]> 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 9c1985c924bc253a5a2af06e918a9a3f352258eb..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,7 +30,9 @@ 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") {
@@ -49,6 +52,22 @@ sub Server () {
                Type => SOCK_STREAM,
        ) 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;
 }