commit c24026e7c2949ede4fc292335df1a08c3f6575fe Author: Steve Dickson Date: Fri Apr 20 13:10:58 2007 -0400 Allow the uid that rpcbind runs as to be set during compile time with the --with-rpcuser configuration flag. The given uid will only be used if the -s flag is not given on the command. Signed-off-by: Steve Dickson diff --git a/configure.in b/configure.in index 0e2f163..dfe5907 100644 --- a/configure.in +++ b/configure.in @@ -37,6 +37,12 @@ if test "$warmstarts" = "true" ; then AC_SUBST(statedir) AC_DEFINE_UNQUOTED(RPCBIND_STATEDIR, "$statedir", [This defines the location where the state files will be kept for warm starts]) fi +AC_ARG_WITH(rpcuser, + [ --with-rpcuser=user uid to use [root]], + rpcuser=$withval, + rpcuser=root) + AC_SUBST(rpcuser) +AC_DEFINE_UNQUOTED(RPCBIND_USER, "$rpcuser", [This defines the uid to run as]) AC_CHECK_HEADERS([arpa/inet.h fcntl.h netdb.h \ netinet/in.h stdlib.h string.h \ diff --git a/src/rpcbind.c b/src/rpcbind.c index 55bbd8d..2a900d9 100644 --- a/src/rpcbind.c +++ b/src/rpcbind.c @@ -68,6 +68,7 @@ #include #include #include +#include "config.h" #include "rpcbind.h" /*#define RPCBIND_DEBUG*/ @@ -79,6 +80,11 @@ int doabort = 0; /* When debugging, do an abort on errors */ rpcblist_ptr list_rbl; /* A list of version 3/4 rpcbind services */ +#ifdef RPCBIND_USER +char *rpcbinduser = RPCBIND_USER; +#else +char *rpcbinduser = NULL; +#endif /* who to suid to if -s is given */ #define RUN_AS "daemon" @@ -206,15 +212,16 @@ main(int argc, char *argv[]) err(1, "fork failed"); } - if (runasdaemon) { + if (runasdaemon || rpcbinduser) { struct passwd *p; + char *id = runasdaemon ? RUN_AS : rpcbinduser; - if((p = getpwnam(RUN_AS)) == NULL) { - syslog(LOG_ERR, "cannot get uid of daemon: %m"); + if((p = getpwnam(id)) == NULL) { + syslog(LOG_ERR, "cannot get uid of '%s': %m", id); exit(1); } if (setuid(p->pw_uid) == -1) { - syslog(LOG_ERR, "setuid to daemon failed: %m"); + syslog(LOG_ERR, "setuid to '%s' failed: %m", id); exit(1); } }