Index: ossp-pkg/lmtp2nntp/lmtp2nntp.c RCS File: /v/ossp/cvs/ossp-pkg/lmtp2nntp/Attic/lmtp2nntp.c,v rcsdiff -q -kk '-r1.83' '-r1.84' -u '/v/ossp/cvs/ossp-pkg/lmtp2nntp/Attic/lmtp2nntp.c,v' 2>/dev/null --- lmtp2nntp.c 2001/10/12 07:43:31 1.83 +++ lmtp2nntp.c 2001/10/12 08:57:50 1.84 @@ -35,6 +35,7 @@ #include #include #include +#include /* third party */ #include "str.h" @@ -151,6 +152,7 @@ unsigned int option_levelmask; char *option_pidfile; int option_killflag; + uid_t option_uid; int option_daemon; int option_aclc; struct acl option_acl[MAXACLS]; @@ -216,6 +218,7 @@ "[-o operationmode] " "[-s size] " "[-t name=sec[,name=sec[,...]] " + "[-u uid] " "[-v] " "newsgroup [newsgroup ...] " "\n", @@ -392,6 +395,7 @@ int nValue; char *cpAddr; char *cpPrefixLen; + struct passwd *sPasswd; /* library version check (run-time) */ if (l2_version.v_hex < L2_VERSION_HEX_REQ) { @@ -424,6 +428,7 @@ ctx->option_levelmask = L2_LEVEL_NONE; ctx->option_pidfile = NULL; ctx->option_killflag = FALSE; + ctx->option_uid = geteuid(); ctx->option_daemon = FALSE; ctx->l2 = NULL; ctx->saaAltio = NULL; @@ -466,7 +471,7 @@ */ /* read in the arguments */ - while ((i = getopt(argc, argv, "DKP:a:b:c:d:g:l:m:n:o:s:t:v")) != -1) { + while ((i = getopt(argc, argv, "DKP:a:b:c:d:g:l:m:n:o:s:t:u:v")) != -1) { switch (i) { case 'D': /*POD [B<-D>] */ ctx->option_daemon = TRUE; @@ -753,6 +758,22 @@ } free(azTimeout); break; + case 'u': /*POD [B<-u> I] */ + if (isdigit((int)optarg[0])) { + if ((sPasswd = getpwuid((uid_t)atoi(optarg))) == NULL) { + fprintf(stderr, "%s:Error: uid \"%s\" not found for -u option.\n", ctx->progname, optarg); + CU(ERR_EXECUTION); + } + } + else { + + if ((sPasswd = getpwnam(optarg)) == NULL) { + fprintf(stderr, "%s:Error: loginname \"%s\" not found for -u option.\n", ctx->progname, optarg); + CU(ERR_EXECUTION); + } + } + ctx->option_uid = sPasswd->pw_uid; + break; case 'v': /*POD [B<-v>] (version)*/ fprintf(stdout, "%s\n", lmtp2nntp_version.v_gnu); CU(0); @@ -819,6 +840,12 @@ } #endif + if (setuid(ctx->option_uid) == -1) { + fprintf(stderr, "%s:Error: Setting UID to %d failed: %s\n", + ctx->progname, ctx->option_uid, strerror(errno)); + CU(ERR_EXECUTION); + } + if ((ctx->l2 = l2_stream_create()) == NULL) { fprintf(stderr, "%s:Error: logging failed to create stream\n", ctx->progname); CU(ERR_EXECUTION); Index: ossp-pkg/lmtp2nntp/lmtp2nntp.pod RCS File: /v/ossp/cvs/ossp-pkg/lmtp2nntp/lmtp2nntp.pod,v rcsdiff -q -kk '-r1.28' '-r1.29' -u '/v/ossp/cvs/ossp-pkg/lmtp2nntp/lmtp2nntp.pod,v' 2>/dev/null --- lmtp2nntp.pod 2001/10/12 07:43:31 1.28 +++ lmtp2nntp.pod 2001/10/12 08:57:51 1.29 @@ -47,6 +47,7 @@ [B<-o> I] [B<-s> I] [B<-t> I=I[,I=I[,...]] +[B<-u> I] [B<-v>] I [I ...] @@ -198,6 +199,10 @@ nntp:read = 60 nntp:write = 60 +=item B<-u> I + +UID or login name to resolve to a UID to be set for program execution. + =item B<-v> Print version information.