OSSP CVS Repository

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

Check-in Number: 3344
Date: 2003-May-16 20:43:30 (local)
2003-May-16 18:43:30 (UTC)
User:ms
Branch:
Comment: Added section login accessors for user name handling during print op, implemented user id and user name parsing in section and script objects.
Tickets:
Inspections:
Files:
ossp-pkg/rc/rc.h      1.42 -> 1.43     2 inserted, 0 deleted
ossp-pkg/rc/rc_private.h      1.24 -> 1.25     1 inserted, 0 deleted
ossp-pkg/rc/rc_proc.c      1.23 -> 1.24     0 inserted, 1 deleted
ossp-pkg/rc/rc_script.c      1.16 -> 1.17     38 inserted, 6 deleted
ossp-pkg/rc/rc_sect.c      1.5 -> 1.6     37 inserted, 5 deleted

ossp-pkg/rc/rc.h 1.42 -> 1.43

--- rc.h 2003/05/15 22:22:30     1.42
+++ rc.h 2003/05/16 18:43:30     1.43
@@ -122,10 +122,12 @@
 rc_section_t *sectionCopy(rc_section_t *);
 const int sectionGetpri(rc_section_t *);
 const int sectionGetuid(rc_section_t *);
+const char *sectionGetlogin(rc_section_t *);
 const char *sectionGetdata(rc_section_t *);
 size_t sectionGetlen(rc_section_t *);
 rc_return_t sectionSetpri(rc_section_t *, long);
 rc_return_t sectionSetuid(rc_section_t *, long);
+rc_return_t sectionSetlogin(rc_section_t *, const char *);
 rc_return_t sectionSetdata(rc_section_t *, const char *);
 rc_return_t sectionSetndata(rc_section_t *, const char *, size_t);
 rc_return_t sectionDump(rc_section_t *);


ossp-pkg/rc/rc_private.h 1.24 -> 1.25

--- rc_private.h 2003/05/15 22:22:30     1.24
+++ rc_private.h 2003/05/16 18:43:30     1.25
@@ -90,6 +90,7 @@
 typedef struct {
     int m_nPri;
     int m_nUid;
+    char *m_szLogin;
     char *m_szData;
     size_t m_Bytes;
 } rc_section_t;


ossp-pkg/rc/rc_proc.c 1.23 -> 1.24

--- rc_proc.c    2003/05/15 22:22:30     1.23
+++ rc_proc.c    2003/05/16 18:43:30     1.24
@@ -149,7 +149,6 @@
                 pSec = NULL;            /* Cleanup */
             }
 
-/* FIXME: Swap nested rcfile/section logic loops for section/rcfile ordering */
             for (i = 0; pRc->m_pAnal->m_pszSecs[i]; i++) { /* Iterate over */
                 /* Extract a section from the temp script, and append it */
                 pSec = scriptSection(pTempscript, pRc->m_pAnal->m_pszSecs[i]);


ossp-pkg/rc/rc_script.c 1.16 -> 1.17

--- rc_script.c  2003/05/16 12:37:10     1.16
+++ rc_script.c  2003/05/16 18:43:31     1.17
@@ -27,9 +27,9 @@
 **  rc_script.c: Run-command processor ISO C source file
 */
 
-#include <stdlib.h>
 #include <string.h>
 #include <ctype.h>      /* For isspace(3)             */
+#include <pwd.h>        /* For getlogin(2)            */
 
 #include "rc.h"         /* Public Rc interface        */
 #include "rc_pcre.h"    /* For section parsing        */
@@ -110,8 +110,12 @@
     char *piBlocend    = NULL; /* Misnomer used to control section looping */
     char *piStart      = NULL;
     char *piEnd        = NULL;
+    char *piSep        = NULL;
+    char *szUser       = NULL;
+    struct passwd *pPwd = NULL;
     long  nPri         = 0;
     long  nUid         = 0;
+    int nUserbytes     = 0;
     int nTmp           = 0;
     int nOffset        = 0;
     int nFound         = 0;
@@ -190,19 +194,47 @@
             if (piSubtemp) { /* Priority pattern found */
                 for (nTmp = (int)piSubtemp + strlen(RC_DEF_PRG);\
                     isspace(*(char *)nTmp); nTmp += sizeof (char)); /* Strip */
-                nPri = strtol((char *)nTmp, (char **)NULL, 10);
-                sectionSetpri(pSec, nPri);
+                nPri = strtol((char *)nTmp, &piSep, 10);
+                if ((char *)nTmp == piSep)  /* No priority number follows */
+                    sectionSetpri(pSec, RC_DEF_PRI); /* which is an error */
+                else
+                    sectionSetpri(pSec, nPri);  /* Found a priority value */
             }
             else /* Fallback to default value */
                 sectionSetpri(pSec, RC_DEF_PRI);
 
             /* Handle the section userid   */
             piSubtemp = strnstr(piStart, RC_DEF_UIG, piEnd - piStart);
-            if (piSubtemp) { /* Priority pattern found */
+            if (piSubtemp) { /* Userid pattern found */
                 for (nTmp = (int)piSubtemp + strlen(RC_DEF_UIG);\
                     isspace(*(char *)nTmp); nTmp += sizeof (char)); /* Strip */
-                nUid = strtol((char *)nTmp, (char **)NULL, 10);
-                sectionSetuid(pSec, nUid);
+                nUid = strtol((char *)nTmp, &piSep, 10);
+                if ((char *)nTmp == piSep)      /* No userid number follows */
+                {
+                    nUserbytes = (strcspn(piSep, " \t\n") + sizeof (char)) * sizeof (char);
+                    szUser = malloc(nUserbytes);
+                    if (!szUser)
+                        RC_THROW(RC_ERR_MEM);
+                    strncpy(szUser, (const char *)nTmp, nUserbytes);
+                    strtok(szUser, " \t\n");
+                    pPwd = getpwnam(szUser);
+                    if (pPwd) {
+                        sectionSetuid(pSec, pPwd->pw_uid);  /* Set to given   */
+                        sectionSetlogin(pSec, szUser);      /* uid and login  */
+                    }
+                    else
+                        sectionSetuid(pSec, RC_DEF_UID);    /* Set to default */
+                    free(szUser);
+                }
+                else {
+                    pPwd = getpwuid(nUid);
+                    if (pPwd) {
+                        sectionSetuid(pSec, nUid);              /* Found a value */
+                        sectionSetlogin(pSec, pPwd->pw_name);   /* uid and login  */
+                    }
+                    else
+                        sectionSetuid(pSec, RC_DEF_UID);        /* Set to default */
+                }
             }
             else /* Fallback to default value */
                 sectionSetuid(pSec, RC_DEF_UID);


ossp-pkg/rc/rc_sect.c 1.5 -> 1.6

--- rc_sect.c    2003/05/15 22:22:30     1.5
+++ rc_sect.c    2003/05/16 18:43:31     1.6
@@ -61,10 +61,18 @@
 
     /* Today is a rain and no coffee day */
     pSec = (rc_section_t *)malloc(sizeof(rc_section_t));
-    pSec->m_nPri   = pOrigsec->m_nPri;
-    pSec->m_nUid   = pOrigsec->m_nUid;
-    pSec->m_Bytes  = pOrigsec->m_Bytes;
-    pSec->m_szData = malloc(strlen(pOrigsec->m_szData) * sizeof(char) + 1);
+    pSec->m_nPri    = pOrigsec->m_nPri;
+    pSec->m_nUid    = pOrigsec->m_nUid;
+    pSec->m_Bytes   = pOrigsec->m_Bytes;
+
+    /* Deep copy of user name */
+    pSec->m_szLogin = malloc((strlen(pOrigsec->m_szLogin) + sizeof(char))\
+        * sizeof(char));
+    strcpy(pSec->m_szLogin, pOrigsec->m_szLogin);
+
+    /* Deep copy of section text */
+    pSec->m_szData  = malloc((strlen(pOrigsec->m_szData) + sizeof(char))\
+        * sizeof(char));
     strcpy(pSec->m_szData, pOrigsec->m_szData);
 
     if (!pSec)
@@ -97,6 +105,16 @@
     return(0); /* Not reached */
 }
 
+const char *sectionGetlogin(rc_section_t *pSec)
+{ /* User name of section, used for display during print */
+    if (pSec)
+        return(pSec->m_szLogin);
+    else
+        RC_THROW(RC_ERR_USE);
+
+    return(0); /* Not reached */
+}
+
 const char *sectionGetdata(rc_section_t *pSec)
 { /* Data of section, this is the script body of the particular section */
     if (pSec && pSec->m_szData)
@@ -141,10 +159,21 @@
     return(RC_THROW(RC_ERR_USE));
 }
 
+rc_return_t sectionSetlogin(rc_section_t *pSec, const char *szLogin)
+{ /* User name of section, used for display during print */
+    if (pSec) {
+        pSec->m_szLogin = malloc((strlen(szLogin) + 1) * sizeof (char));
+        strcpy(pSec->m_szLogin, szLogin);
+        return(RC_THROW(RC_OK));
+    }
+
+    return(RC_THROW(RC_ERR_USE));
+}
+
 rc_return_t sectionSetdata(rc_section_t *pSec, const char *kszScript)
 { /* Data of section, this is the script body of the particular section */
     if (pSec) {
-        pSec->m_Bytes = strlen(kszScript) * sizeof(char) + sizeof(char);
+        pSec->m_Bytes = (strlen(kszScript) + sizeof(char)) * sizeof(char);
         if (pSec->m_szData) { /* The section data is already in use */
             free(pSec->m_szData);
             pSec->m_szData = malloc(pSec->m_Bytes);
@@ -188,6 +217,7 @@
 rc_return_t sectionDump(rc_section_t *pSec)
 {
     if (pSec) {
+        fprintf(stdout, "#su %s\n", sectionGetlogin(pSec));
         fprintf(stdout, "%s", sectionGetdata(pSec));
         return(RC_THROW(RC_OK));
     }
@@ -205,6 +235,8 @@
     if (pSec) {
         if (pSec->m_szData)
             free(pSec->m_szData);
+        if (pSec->m_szLogin)
+            free(pSec->m_szLogin);
         free(pSec);
     }
     else    /* Dumbass passed an empty section object */

CVSTrac 2.0.1