Index: ossp-pkg/rc/rc.h RCS File: /v/ossp/cvs/ossp-pkg/rc/rc.h,v rcsdiff -q -kk '-r1.42' '-r1.43' -u '/v/ossp/cvs/ossp-pkg/rc/rc.h,v' 2>/dev/null --- 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 *); Index: ossp-pkg/rc/rc_private.h RCS File: /v/ossp/cvs/ossp-pkg/rc/rc_private.h,v rcsdiff -q -kk '-r1.24' '-r1.25' -u '/v/ossp/cvs/ossp-pkg/rc/rc_private.h,v' 2>/dev/null --- 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; Index: ossp-pkg/rc/rc_proc.c RCS File: /v/ossp/cvs/ossp-pkg/rc/rc_proc.c,v rcsdiff -q -kk '-r1.23' '-r1.24' -u '/v/ossp/cvs/ossp-pkg/rc/rc_proc.c,v' 2>/dev/null --- 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]); Index: ossp-pkg/rc/rc_script.c RCS File: /v/ossp/cvs/ossp-pkg/rc/rc_script.c,v rcsdiff -q -kk '-r1.16' '-r1.17' -u '/v/ossp/cvs/ossp-pkg/rc/rc_script.c,v' 2>/dev/null --- 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 #include #include /* For isspace(3) */ +#include /* 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); Index: ossp-pkg/rc/rc_sect.c RCS File: /v/ossp/cvs/ossp-pkg/rc/rc_sect.c,v rcsdiff -q -kk '-r1.5' '-r1.6' -u '/v/ossp/cvs/ossp-pkg/rc/rc_sect.c,v' 2>/dev/null --- 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 */