From c9b0e00b236fc4154d7ae88794e1de97a78cc8e8 Mon Sep 17 00:00:00 2001 From: oetiker Date: Tue, 21 Dec 2010 16:06:32 +0000 Subject: [PATCH] rrdcached: Fix permissions of the default socket. If neither the "-l" nor the "-P" options have been given, a UNIX domain socket at a default location is created. However, due to a missing initialization in this case, the "permissions" field will be left at zero (no command allowed). This patch fixes this problem by allowing all commands on the default socket if no "-P" option is given. -- Florian Forster git-svn-id: svn://svn.oetiker.ch/rrdtool/trunk@2152 a5681a0c-68f1-0310-ab6d-d61299d08faa --- program/src/rrd_daemon.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/program/src/rrd_daemon.c b/program/src/rrd_daemon.c index 0586a8de..1a20974d 100644 --- a/program/src/rrd_daemon.c +++ b/program/src/rrd_daemon.c @@ -2168,6 +2168,15 @@ static void socket_permission_copy (listen_socket_t *dest, /* {{{ */ dest->permissions = src->permissions; } /* }}} socket_permission_copy */ +static void socket_permission_set_all (listen_socket_t *sock) /* {{{ */ +{ + size_t i; + + sock->permissions = 0; + for (i = 0; i < list_of_commands_len; i++) + sock->permissions |= (1 << i); +} /* }}} void socket_permission_set_all */ + /* check whether commands are received in the expected context */ static int command_check_context(listen_socket_t *sock, command_t *cmd) { @@ -3131,6 +3140,10 @@ static int daemonize (void) /* {{{ */ strncpy(default_socket.addr, RRDCACHED_DEFAULT_ADDRESS, sizeof(default_socket.addr) - 1); default_socket.addr[sizeof(default_socket.addr) - 1] = '\0'; + + if (default_socket.permissions == 0) + socket_permission_set_all (&default_socket); + open_listen_socket (&default_socket); } @@ -3275,18 +3288,7 @@ static int read_options (int argc, char **argv) /* {{{ */ else /* if (default_socket.permissions == 0) */ { /* Add permission for ALL commands to the socket. */ - size_t i; - for (i = 0; i < list_of_commands_len; i++) - { - status = socket_permission_add (new, list_of_commands[i].cmd); - if (status != 0) - { - fprintf (stderr, "read_options: Adding permission \"%s\" to " - "socket failed. This should never happen, ever! Sorry.\n", - list_of_commands[i].cmd); - status = 4; - } - } + socket_permission_set_all (new); } /* }}} Done adding permissions. */ @@ -3573,6 +3575,7 @@ static int read_options (int argc, char **argv) /* {{{ */ "\n" "Valid options are:\n" " -l
Socket address to listen to.\n" + " Default: "RRDCACHED_DEFAULT_ADDRESS"\n" " -P Sets the permissions to assign to all following " "sockets\n" " -w Interval in which to write data.\n" -- 2.30.2