OSSP CVS Repository

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

Check-in Number: 3475
Date: 2003-Jun-30 17:27:38 (local)
2003-Jun-30 15:27:38 (UTC)
User:ms
Branch:
Comment: Add RC_ERR_ROOT error, and improve error handling during forked child op failures.
Tickets:
Inspections:
Files:
ossp-pkg/rc/rc.h      1.54 -> 1.55     16 inserted, 15 deleted
ossp-pkg/rc/rc_error.c      1.3 -> 1.4     4 inserted, 1 deleted
ossp-pkg/rc/rc_proc.c      1.52 -> 1.53     11 inserted, 5 deleted

ossp-pkg/rc/rc.h 1.54 -> 1.55

--- rc.h 2003/06/30 15:09:46     1.54
+++ rc.h 2003/06/30 15:27:38     1.55
@@ -52,21 +52,22 @@
 
 /* Rc return codes */
 typedef enum {
-    RC_OK      = 0,  /* Success                  */
-    RC_ERR_0   = 1,  /* Error base               */
-    RC_ERR_USE = 2,  /* Usage error              */
-    RC_ERR_MEM = 3,  /* Memory error             */
-    RC_ERR_SYS = 4,  /* System error (see errno) */
-    RC_ERR_IO  = 5,  /* Input/output error       */
-    RC_ERR_INT = 6,  /* Internal error           */
-    RC_ERR_FNC = 7,  /* Func file not found      */
-    RC_ERR_DIR = 8,  /* Location dir not found   */
-    RC_ERR_RCF = 9,  /* Rc file not found        */
-    RC_ERR_TRM = 10, /* Request to terminate app */
-    RC_ERR_CFG = 11, /* Config or option failure */
-    RC_WRN_0   = 12, /* Warning base             */
-    RC_WRN_OWR = 13, /* Overwrite warning        */
-    RC_WRN_NUL = 14  /* NULL pointer warning     */
+    RC_OK      = 0,   /* Success                  */
+    RC_ERR_0   = 1,   /* Error base               */
+    RC_ERR_USE = 2,   /* Usage error              */
+    RC_ERR_MEM = 3,   /* Memory error             */
+    RC_ERR_SYS = 4,   /* System error (see errno) */
+    RC_ERR_IO  = 5,   /* Input/output error       */
+    RC_ERR_INT = 6,   /* Internal error           */
+    RC_ERR_FNC = 7,   /* Func file not found      */
+    RC_ERR_DIR = 8,   /* Location dir not found   */
+    RC_ERR_RCF = 9,   /* Rc file not found        */
+    RC_ERR_TRM = 10,  /* Request to terminate app */
+    RC_ERR_CFG = 11,  /* Config or option failure */
+    RC_ERR_ROOT = 12, /* Process must run as root */
+    RC_WRN_0   = 13,  /* Warning base             */
+    RC_WRN_OWR = 14,  /* Overwrite warning        */
+    RC_WRN_NUL = 15   /* NULL pointer warning     */
 } rc_return_t;
 
 /* Config function prototypes */


ossp-pkg/rc/rc_error.c 1.3 -> 1.4

--- rc_error.c   2003/06/24 09:35:39     1.3
+++ rc_error.c   2003/06/30 15:27:38     1.4
@@ -67,9 +67,12 @@
         else if ((rc_return_t)Localerr.ex_value == RC_ERR_CFG)
             fprintf(stderr, "    Error condition, configuration and options failure in %s:%s():%d.\n", \
                 Localerr.ex_file, Localerr.ex_func, Localerr.ex_line);
+        else if ((rc_return_t)Localerr.ex_value == RC_ERR_ROOT)
+            fprintf(stderr, "    Error condition, in %s:%s():%d. You must be root to run these commands\n", \
+                Localerr.ex_file, Localerr.ex_func, Localerr.ex_line);
         else
             fprintf(stderr, "    Error condition of class '%s',\n    exception %d in %s:%s():%d.\n", (char *)Localerr.ex_class, (int)Localerr.ex_value, Localerr.ex_file, Localerr.ex_func, Localerr.ex_line);
-        exit(1); /* Return failure */
+        exit((int)Localerr.ex_value); /* Return failure */
     }
 #ifdef DEBUG
     else        /* Warning condition */


ossp-pkg/rc/rc_proc.c 1.52 -> 1.53

--- rc_proc.c    2003/06/30 15:09:46     1.52
+++ rc_proc.c    2003/06/30 15:27:38     1.53
@@ -276,6 +276,8 @@
         pFatscript = NULL;
     }
     else if (configGetval(RC_EXC_VAL)) {                        /* Execute  */
+        int nStat; /* Used for reporting status on return of a forked child */
+
         /* This block does nothing more than implement the feature,         */
         /* that allows rc to run unprivileged (as long as no privileged     */
         /* code is used in the script sections to be executed               */
@@ -392,7 +394,7 @@
                     szVerbose = NULL;
 
                     /* Spawn the section shell code */
-                    switch (Pidexec = fork()){
+                    switch (Pidexec = fork()) {
                         case -1:    /* Broken */
                             return(RC_THROW(RC_ERR_INT));
                             break;  /* Huh? */
@@ -400,12 +402,14 @@
                             nSectuid = sectionGetuid(ppSectmp[nTmp]);
                             if (nSectuid >= 0 && getuid() != nSectuid)
                                 if (setuid(nSectuid) != 0)
-                                    return(RC_THROW(RC_ERR_INT));
+                                    return(RC_THROW(RC_ERR_ROOT));
                             if (execvp(*pszVec, pszVec) == -1)
                                 return(RC_THROW(RC_ERR_INT));
                             break;
                         default: /* Parent, blocks until child returns */
-                            waitpid(Pidexec, NULL, WUNTRACED);
+                            waitpid(Pidexec, &nStat, WUNTRACED);
+                            if ((nStat = WEXITSTATUS(nStat)) != 0)
+                                return(nStat);
                             break;
                     }
                     if (szExec) {
@@ -443,12 +447,14 @@
                             nSectuid = sectionGetuid(ppSectmp[nTmp]);
                             if (nSectuid >= 0 && getuid() != nSectuid)
                                 if (setuid(nSectuid) != 0)
-                                    return(RC_THROW(RC_ERR_INT));
+                                    return(RC_THROW(RC_ERR_ROOT));
                             if (execvp(*pszVec, pszVec) == -1)
                                 return(RC_THROW(RC_ERR_INT));
                             break;
                         default: /* Parent, blocks until child returns */
-                            waitpid(Pidexec, NULL, WUNTRACED);
+                            waitpid(Pidexec, &nStat, WUNTRACED);
+                            if ((nStat = WEXITSTATUS(nStat)) != 0)
+                                return(nStat);
                             break;
                     }
                     free(szExec); /* Cleanup after exec */

CVSTrac 2.0.1