OSSP CVS Repository

ossp - Difference in ossp-pkg/rc/rc_proc.c versions 1.32 and 1.33
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [History

ossp-pkg/rc/rc_proc.c 1.32 -> 1.33

--- rc_proc.c    2003/05/22 14:46:33     1.32
+++ rc_proc.c    2003/05/23 14:14:09     1.33
@@ -27,17 +27,16 @@
 **  rc_proc.c: Run-command processor ISO C source file
 */
 
-#include <stdlib.h>     /* Standard system headers  */
-#include <fcntl.h>      /* For reading rc files     */
-#include <unistd.h>     /* For reading rc files     */
-#include <string.h>     /* For string manipulation  */
-
-/* FIXME: Remove */
-#include <sys/stat.h>
-
-#include "rc.h"         /* Public interfaces        */
-#include "rc_const.h"   /* String and value const   */
-#include "rc_config.h"  /* Option definitions       */
+#include <stdlib.h>     /* Standard system headers    */
+#include <fcntl.h>      /* For reading rc files       */
+#include <unistd.h>     /* For reading rc files       */
+#include <string.h>     /* For string manipulation    */
+#include <signal.h>     /* For signal(3)              */
+#include <sys/wait.h>   /* For waitpid(2) and fork(2) */
+
+#include "rc.h"         /* Public interfaces          */
+#include "rc_const.h"   /* String and value const     */
+#include "rc_config.h"  /* Option definitions         */
 
 
 /************************************************
@@ -194,6 +193,9 @@
     int   nTmpname  = 0;              /* Temp file name size */
     int   nRcs      = 0;              /* Rc index            */
     int   nSecs     = 0;              /* Section index       */
+    int   nSectuid  = -1;             /* The section's user id           */
+    int   nRunuid   = -1;             /* The current user id             */
+    pid_t Pidexec   = -1;             /* When spawning before execv(3)   */
     char *szTmpfile = NULL;           /* Path of temporary file          */
     char *szTmp     = NULL;           /* Generic temporary string        */
     char *szCom     = NULL;           /* Stores common script text       */
@@ -262,6 +264,20 @@
         pFatscript = NULL;
     }
     else if (configGetval(RC_EXC_VAL)) {                        /* Execute  */
+        /* FIXME FIXME FIXME FIXME */
+        /* For however many labels */
+            /* For however many sections in this label */
+                /* If the we must setuid(2) */
+                    /* If yes, are we root? */
+                        /* If no, then report error and exit */
+/*        for (nTmp = 0; ; nTmp++) {
+            if ()
+            nRunuid = getuid();
+            if (nRunuid != 0 && nRunuid != nSectuid) {
+                fprintf(stderr, RC_RUT_TEXT);
+                return(RC_THROW(RC_ERR_USE));
+            }
+        }*/
         /* Allocate a block of section pointers to use temporarily */
         ppSectmp = calloc(pRc->m_pAnal->m_nRcs, sizeof(rc_section_t *));
         szCom = (char *)scriptTostring(pRc->m_pScriptcom);
@@ -288,12 +304,24 @@
                                (strlen(szTmp) + 1) * sizeof(char));
                 strcpy(szExec, szCom); /* Start out with just the common script code */
                 strcat(szExec, szTmp); /* And build a section onto the command chain */
-                pszVec[2] = szExec; /* Actually launch the new process image now */
+                pszVec[2] = szExec;    /* Actually launch the new process image now  */
 
-/* FIXME: Put the fork in here! */
-                if (execvp(*pszVec, pszVec) == -1) {                    /* launch */
-                    TRACE("Bad, execvp for common script in child returned -1");
-                    return(RC_THROW(RC_ERR_INT));
+                /* Spawn the section shell code */
+                switch (Pidexec = fork()){
+                    case -1:    /* Broken */
+                        return(RC_THROW(RC_ERR_INT));
+                        break;  /* Huh? */
+                    case 0:     /* Child, runs script code through bourne shell */
+                        nSectuid = sectionGetuid(ppSectmp[nTmp]);
+                        if (nSectuid >= 0 && getuid() != nSectuid)
+                            if (setuid(nSectuid) != 0)
+                                return(RC_THROW(RC_ERR_INT));
+                        if (execvp(*pszVec, pszVec) == -1)
+                            return(RC_THROW(RC_ERR_INT));
+                        break;
+                    default: /* Parent, blocks until child returns */
+                        waitpid(Pidexec, NULL, WUNTRACED);
+                        break;
                 }
 
                 free(szExec); /* Cleanup after exec */

CVSTrac 2.0.1