From 320159175adced71da64efa80e9334f7bcab96c8 Mon Sep 17 00:00:00 2001 From: Peter Schlaile Date: Thu, 8 Oct 2009 10:36:06 +0200 Subject: [PATCH] added owner / group options to options.conf makes the usual setup LCR running as "root" and asterisk running as "asterisk" easier to configure. --- README | 2 +- default/options.conf | 8 ++++++++ options.c | 28 ++++++++++++++++++++++++++++ options.h | 3 ++- socket_server.c | 6 +++++- 5 files changed, 44 insertions(+), 3 deletions(-) diff --git a/README b/README index 85e8d96..c7cac53 100644 --- 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 diff --git a/default/options.conf b/default/options.conf index 4875773..f63bd33 100644 --- a/default/options.conf +++ b/default/options.conf @@ -96,6 +96,14 @@ # 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 - diff --git a/options.c b/options.c index 6f74533..f58d7f9 100644 --- a/options.c +++ b/options.c @@ -17,6 +17,8 @@ #include "macro.h" #include "extension.h" #include "options.h" +#include +#include 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 diff --git a/options.h b/options.h index ec8f1c1..ecf8244 100644 --- 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 */ }; diff --git a/socket_server.c b/socket_server.c index 7a08680..a33f626 100644 --- a/socket_server.c +++ b/socket_server.c @@ -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); } -- 2.13.6