OSSP CVS Repository

ossp - Check-in [1165]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 1165
Date: 2001-Oct-12 10:57:50 (local)
2001-Oct-12 08:57:50 (UTC)
User:thl
Branch:
Comment: added -u uid option
Tickets:
Inspections:
Files:
ossp-pkg/lmtp2nntp/lmtp2nntp.c      1.83 -> 1.84     28 inserted, 1 deleted
ossp-pkg/lmtp2nntp/lmtp2nntp.pod      1.28 -> 1.29     5 inserted, 0 deleted

ossp-pkg/lmtp2nntp/lmtp2nntp.c 1.83 -> 1.84

--- 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);


ossp-pkg/lmtp2nntp/lmtp2nntp.pod 1.28 -> 1.29

--- 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<operationmode>]
 [B<-s> I<size>]
 [B<-t> I<name>=I<sec>[,I<name>=I<sec>[,...]]
+[B<-u> I<uid>]
 [B<-v>]
 I<newsgroup> [I<newsgroup> ...]
 
@@ -198,6 +199,10 @@
     nntp:read    = 60
     nntp:write   = 60
 
+=item B<-u> I<uid>
+
+UID or login name to resolve to a UID to be set for program execution.
+
 =item B<-v>
 
 Print version information.

CVSTrac 2.0.1