From: Andreas Eversberg Date: Tue, 27 Oct 2009 06:56:59 +0000 (+0100) Subject: Merge branch 'master' of ssh://jolly@www.mISDN.org/var/git/lcr X-Git-Url: http://git.eversberg.eu/gitweb.cgi?p=lcr.git;a=commitdiff_plain;h=8994874d7bcb1eff9ee833fb22e4910cc365f456;hp=b987a1bbbcabbf183ebe009903778671a1591337 Merge branch 'master' of ssh://jolly@mISDN.org/var/git/lcr Conflicts: README --- diff --git a/README b/README index f423b62..8c0d65a 100644 --- a/README +++ b/README @@ -520,7 +520,7 @@ 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 - Fixed/simplyfied config parser. The last digit of the last line was ignored. - 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); }