--- 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 <sys/types.h>
#include <sys/wait.h>
#include <signal.h>
+#include <pwd.h>
/* 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<uid>] */
+ 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);
|