Skip to content

Instantly share code, notes, and snippets.

Created Dec 20, 2020
What would you like to do?
BIND external grant authenticator
use strict;
use IO::Socket::UNIX;
my $path = '/tmp/auth.sock';
my $server = IO::Socket::UNIX->new(Local => $path, Type => SOCK_STREAM, Listen => 8) or
die "unable to create socket $path";
chmod 0777, $path;
while (my $client = $server->accept()) {
$client->recv(my $buf, 8, 0);
my ($version, $req_len) = unpack('N N', $buf);
if ($version != 1 || $req_len < 17) {
printf("Badly formatted request\n");
$client->send(pack('N', 2));
$client->recv(my $buf, $req_len - 8, 0);
my ($signer,
$key_data) = unpack('Z* Z* Z* Z* Z* N/a', $buf);
if ($req_len != length($buf)+8) {
printf("Length mismatch %u %u\n", $req_len, length($buf)+8);
$client->send(pack('N', 2));
printf("Update by %s key=%s for name=%s, type=%s at address %s\n",
$signer, $key, $name, $type, $addr);
# look up $name and decide whether to grant or deny
my $result = 1; # grant
my $reply = pack('N', $result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment