added owner / group options to options.conf
authorPeter Schlaile <peter@schlaile.de>
Thu, 8 Oct 2009 08:36:06 +0000 (10:36 +0200)
committerroot <peter@schlaile.de>
Thu, 8 Oct 2009 08:36:06 +0000 (10:36 +0200)
makes the usual setup LCR running as "root" and asterisk running as "asterisk"
easier to configure.

README
default/options.conf
options.c
options.h
socket_server.c

diff --git a/README b/README
index 85e8d96..c7cac53 100644 (file)
--- a/README
+++ b/README
@@ -520,6 +520,6 @@ Changes after Version 1.6
  -> Just add 'extern' right below your external interface definition, or give
     external interface name in routing.conf: ": extern interfaces=XXXXX"
 - Added experimental CCITT No. 5 signalling system. (for educational purpose)
-
+- Added socket owner/group options to options.conf
 
 
index 4875773..f63bd33 100644 (file)
 # Rights must have 0 in front, if octal values above are used.
 #socketrights 0700
 
+# Change user of LCR socket, where lcradmin or chan_lcr connects to.
+# So: change to asterisk, if you have asterisk run as user "asterisk" e.g.
+#socketuser asterisk
+
+# Change group of LCR socket, where lcradmin or chan_lcr connects to.
+# So: change to asterisk, if you have asterisk run in group "asterisk" e.g.
+#socketgroup asterisk
+
 # Enable GSM network capability.
 # This option turns LCR into a GSM network. Additional options are specified
 # in 'gsm.conf'. You also need openbsc at compile time and of yourse -
index 6f74533..f58d7f9 100644 (file)
--- a/options.c
+++ b/options.c
@@ -17,6 +17,8 @@
 #include "macro.h"
 #include "extension.h"
 #include "options.h"
+#include <grp.h>
+#include <pwd.h>
 
 struct options options = {
        "/usr/local/lcr/log",           /* log file */
@@ -31,6 +33,8 @@ struct options options = {
        "lcr@your.machine",             /* source mail adress */
        "/var/tmp",                     /* path of lock files */
        0700,                           /* rights of lcr admin socket */
+       -1,                             /* socket user (-1= no change) */
+       -1,                             /* socket group (-1= no change) */
        0                               /* enable gsm */
 };
 
@@ -202,6 +206,30 @@ int read_options(void)
                        SCPY(options.lock, param);
 
                } else
+               if (!strcmp(option,"socketuser")) {
+                       char * endptr = NULL;
+                       options.socketuser = strtol(param, &endptr, 10);
+                       if (*endptr != '\0') {
+                               struct passwd * pwd = getpwnam(param);
+                               if (pwd == NULL) {
+                                       SPRINT(options_error, "Error in %s (line %d): no such user: %s.\n",filename,line,param);
+                                       goto error;
+                               }
+                               options.socketuser = pwd->pw_uid;
+                       }
+               } else
+               if (!strcmp(option,"socketgroup")) {
+                       char * endptr = NULL;
+                       options.socketgroup = strtol(param, &endptr, 10);
+                       if (*endptr != '\0') {
+                               struct group * grp = getgrnam(param);
+                               if (grp == NULL) {
+                                       SPRINT(options_error, "Error in %s (line %d): no such group: %s.\n",filename,line,param);
+                                       goto error;
+                               }
+                               options.socketgroup = grp->gr_gid;
+                       }
+               } else
                if (!strcmp(option,"socketrights")) {
                        options.socketrights = strtol(param, NULL, 0);
                } else
index ec8f1c1..ecf8244 100644 (file)
--- a/options.h
+++ b/options.h
@@ -27,7 +27,8 @@ struct options {
        char    email[128];             /* source email address */
        char    lock[128];              /* path of lock files */
        int     socketrights;           /* rights of lcr admin socket */
-
+       int     socketuser;             /* socket chown to this user */
+       int     socketgroup;            /* socket chgrp to this group */
        int     gsm;                    /* enable gsm support */
 };     
 
index 7a08680..a33f626 100644 (file)
@@ -64,8 +64,12 @@ int admin_init(void)
                return(-1);
        }
        if (chmod(socket_name, options.socketrights) < 0) {
-               PERROR("Failed to change socket rigts to %d. (errno=%d)\n", options.socketrights, errno);
+               PERROR("Failed to change socket rights to %d. (errno=%d)\n", options.socketrights, errno);
        }
+       if (chown(socket_name, options.socketuser, options.socketgroup) < 0) {
+               PERROR("Failed to change socket user/group to %d/%d. (errno=%d)\n", options.socketuser, options.socketgroup, errno);
+       }
+
        return(0);
 }