]> git.ipfire.org Git - people/stevee/guardian.git/blobdiff - modules/Socket.pm
Add ability to reload the ignore list.
[people/stevee/guardian.git] / modules / Socket.pm
index 5e5a9982e86cfff87603117591588713e7e12dd1..d4c9a3051ab9b16ec6d72de39ce81268868b7247 100644 (file)
@@ -19,6 +19,7 @@ my %supported_commands = (
        'unblock' => 'unblock',
        'flush' => 'flush',
        'reload' => 'reload',
+       'reload-ignore-list' => 'reload-ignore-list',
        'logrotate' => 'logrotate',
 );
 
@@ -29,17 +30,19 @@ my %supported_commands = (
 ## mechanism for guardian.  The server function creates an UNIX
 ## socket.
 #
-sub Server () {
+sub Server ($) {
+       my $socket_owner = shift;
+
        # If the path for the socketfile does not exist, try to
        # create it.
        unless (-d "$socketpath") {
-               mkdir("$socketpath") or die "Could not create $socketpath: $!\n";
+               mkdir("$socketpath") or die "Could not create $socketpath: $!";
        }
 
        # Delete an existing socket file.
        if (-e "$socketfile") {
                unlink $socketfile
-               or die "Could not release existing socket file: $!\n";
+               or die "Could not release existing socket file: $!";
        }
 
        # Create a new UNIX socket.
@@ -47,7 +50,23 @@ sub Server () {
                Local => $socketfile,
                Listen => SOMAXCONN,
                Type => SOCK_STREAM,
-       ) or die "Could not create socket: $!\n";
+       ) or die "Could not create socket: $!";
+
+       
+       # Translate the given user/group name into ID values.
+       if (defined ($socket_owner)) {
+               # Splitt provided user/group into single arguments.
+               my ($username, $groupname) = split(/:/, $socket_owner);
+
+               # Get the ID for the given user name.
+               my $uid = getpwnam($username) or die "Could not get an UID for $username: $!";
+
+               # Get the ID for given group name.
+               my $gid = getgrnam($groupname) or die "Could not get a GID for $groupname: $!";
+
+               # Set new ownership for the socket file.
+               chown($uid, $gid, "$socketfile") or die "Could not change ownership to ($uid:$gid) for $socketfile: $!";
+       }
 
        # Return the server object.
        return $server;
@@ -102,7 +121,7 @@ sub Message_Parser ($) {
                if ($optarg) {
                        # The message is valid, return the event and
                        # the optional argument.
-                       return "$supported_commands{$command} $optarg";
+                       return "$supported_commands{$command} $optarg Socket User-requested action.";
                } else {
                        # Only return the event for the recieved command.
                        return "$supported_commands{$command}";