head 1.37; access; symbols OSSP_RC_0_7_3:1.37 OSSP_RC_0_7_2:1.36 OSSP_RC_0_7_1:1.35 OSSP_RC_ALPHA_06:1.28 OSSP_RC_EXBROKEN:1.21; locks; strict; comment @ * @; 1.37 date 2003.07.11.14.03.53; author ms; state Exp; branches; next 1.36; 1.36 date 2003.07.11.08.49.36; author ms; state Exp; branches; next 1.35; 1.35 date 2003.07.07.13.30.51; author ms; state Exp; branches; next 1.34; 1.34 date 2003.07.07.12.55.42; author ms; state Exp; branches; next 1.33; 1.33 date 2003.06.30.14.43.36; author ms; state Exp; branches; next 1.32; 1.32 date 2003.06.26.18.45.14; author ms; state Exp; branches; next 1.31; 1.31 date 2003.06.18.14.35.29; author ms; state Exp; branches; next 1.30; 1.30 date 2003.06.13.18.33.07; author ms; state Exp; branches; next 1.29; 1.29 date 2003.06.13.10.53.53; author ms; state Exp; branches; next 1.28; 1.28 date 2003.05.28.14.25.56; author ms; state Exp; branches; next 1.27; 1.27 date 2003.05.28.13.31.55; author ms; state Exp; branches; next 1.26; 1.26 date 2003.05.27.15.09.09; author ms; state Exp; branches; next 1.25; 1.25 date 2003.05.27.13.14.08; author ms; state Exp; branches; next 1.24; 1.24 date 2003.05.27.13.00.22; author ms; state Exp; branches; next 1.23; 1.23 date 2003.05.27.11.56.00; author ms; state Exp; branches; next 1.22; 1.22 date 2003.05.26.16.24.08; author ms; state Exp; branches; next 1.21; 1.21 date 2003.05.23.14.14.09; author ms; state Exp; branches; next 1.20; 1.20 date 2003.05.21.15.16.41; author ms; state Exp; branches; next 1.19; 1.19 date 2003.05.21.12.49.21; author ms; state Exp; branches; next 1.18; 1.18 date 2003.05.20.15.06.42; author ms; state Exp; branches; next 1.17; 1.17 date 2003.05.16.18.43.31; author ms; state Exp; branches; next 1.16; 1.16 date 2003.05.16.12.37.10; author ms; state Exp; branches; next 1.15; 1.15 date 2003.05.15.22.22.30; author ms; state Exp; branches; next 1.14; 1.14 date 2003.05.14.16.36.28; author ms; state Exp; branches; next 1.13; 1.13 date 2003.05.12.15.42.45; author ms; state Exp; branches; next 1.12; 1.12 date 2003.04.03.12.05.14; author ms; state Exp; branches; next 1.11; 1.11 date 2002.08.02.20.09.59; author ms; state Exp; branches; next 1.10; 1.10 date 2002.08.01.14.31.38; author ms; state Exp; branches; next 1.9; 1.9 date 2002.08.01.13.25.32; author ms; state Exp; branches; next 1.8; 1.8 date 2002.07.30.16.36.41; author ms; state Exp; branches; next 1.7; 1.7 date 2002.07.10.19.03.58; author ms; state Exp; branches; next 1.6; 1.6 date 2002.07.05.12.54.56; author ms; state Exp; branches; next 1.5; 1.5 date 2002.07.04.16.49.58; author ms; state Exp; branches; next 1.4; 1.4 date 2002.07.02.18.03.17; author ms; state Exp; branches; next 1.3; 1.3 date 2002.06.28.17.43.23; author ms; state Exp; branches; next 1.2; 1.2 date 2002.06.28.14.20.23; author ms; state Exp; branches; next 1.1; 1.1 date 2002.06.26.14.11.16; author ms; state Exp; branches; next ; desc @@ 1.37 log @Back out regex fix, because the changed PCRE PCRE_DOLLAR_ENDONLY flag broke rc file parsing. @ text @/* OSSP rc - Run-Command Processor ** Copyright (c) 2002-2003 Ralf S. Engelschall ** Copyright (c) 2002-2003 Cable & Wireless Deutschland GmbH ** Copyright (c) 2002-2003 The OSSP Project ** ** This file is part of OSSP rc, a portable run-command processor ** which can be found at http://www.ossp.org/pkg/lib/rc/ ** ** Permission to use, copy, modify, and distribute this software for ** any purpose with or without fee is hereby granted, provided that ** the above copyright notice and this permission notice appear in all ** copies. ** ** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED ** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF ** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF ** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ** SUCH DAMAGE. ** ** rc_script.c: Run-Command Processor ISO C source file */ #include #include #include /* For mkstemp(3) */ #include /* For open(2) */ #include /* For isspace(3) */ #include /* For getpwuid(3) */ #include "rc.h" /* Public Rc interface */ #include "rc_pcre.h" /* For section parsing */ #include "rc_config.h" /* For configuration access */ #include "rc_const.h" /* For configuration defaults */ /************************************************ * scriptCopy(rc_script_t *) * * Copy constructor * ************************************************/ rc_script_t *scriptCopy(rc_script_t *pOrig) { rc_script_t *pNew = NULL; pNew = (rc_script_t *)malloc(sizeof(rc_script_t)); if (pNew) { *pNew = malloc((strlen(scriptGetdata(pOrig)) + 1) * sizeof(char)); if (*pNew) strcpy(*pNew, scriptGetdata(pOrig)); else RC_THROW(RC_ERR_MEM); } else RC_THROW(RC_ERR_MEM); return(pNew); } /************************************************ * scriptNew(void) * * Construct a script * ************************************************/ rc_script_t *scriptNew(void) { rc_script_t *pScript = NULL; pScript = (rc_script_t *)malloc(sizeof(rc_script_t)); if (pScript) { *pScript = malloc(sizeof(char)); if (*pScript) **pScript = NULL; else RC_THROW(RC_ERR_MEM); } else RC_THROW(RC_ERR_MEM); return(pScript); } /**************************************************** * scriptAdd(rc_script_t *, rc_script_t *) * * Add one script to another * ****************************************************/ rc_return_t scriptAdd(rc_script_t *pDest, rc_script_t *pSource) { int nResize = 0; void *pvRealloc = NULL; assert(pDest && pSource); /* Parameters must be valid */ /* Add 2 chars to ensure that a \0 precedes any strings */ nResize = strlen(*pDest) + strlen(*pSource) + sizeof (char); /* Don't trust realloc(3) in this case */ if ((pvRealloc = calloc(1, (size_t)nResize)) == NULL) return(RC_THROW(RC_ERR_MEM)); strcpy(pvRealloc, *pDest); strcat(pvRealloc, *pSource); /* Cleanup and deallocate */ if (*pDest) { free(*pDest); *pDest = NULL; } *pDest = pvRealloc; /* Put the new data in */ return(RC_THROW(RC_OK)); } /***************************************************** * scriptnAppend(rc_script_t *, const char *, size_t) * * Append n characters of text to a script * *****************************************************/ rc_return_t scriptnAppend(rc_script_t *pScript, const char *szInbuf, size_t Size) { int nResize = 0; void *pvRealloc = NULL; assert(pScript); /* Script parameter must be valid */ if (!szInbuf) return(RC_THROW(RC_ERR_USE)); /* Short circuit in case of dumb noop call */ if (Size == 0) return(RC_THROW(RC_OK)); /* Add 2 chars to ensure that a \0 precedes any strings */ nResize = strlen(*pScript) + Size + sizeof (char); /* Don't trust realloc(3) in this case */ if ((pvRealloc = calloc(1, (size_t)nResize)) == NULL) return(RC_THROW(RC_ERR_MEM)); /* Coerce strings into one Script again */ if (*pScript) strcpy(pvRealloc, *pScript); strncat(pvRealloc, szInbuf, Size + 1); /* Cleanup and deallocate memory */ if (*pScript) free(*pScript); *pScript = pvRealloc; return(RC_THROW(RC_OK)); } /************************************************ * scriptSection(rc_script_t *, const char *) * * Parse a script for a given section * ************************************************/ rc_section_t *scriptSection(rc_script_t *pScript, const char *kszSecname) { rc_section_t *pSec = NULL; char *piLabstart = NULL; int nLabsize = 0; char *piSubtemp = NULL; /* To find priority and userid in substrings */ char *piBlocend = NULL; /* Misnomer used to control section looping */ char *piStart = NULL; char *piEnd = NULL; char *piSep = NULL; char *szUser = NULL; char *szTemp = NULL; /* Holds temporarily the pri and user strings */ struct passwd *pPwd = NULL; long nPri = 0; long nUid = 0; int nUserbytes = 0; int nTmp = 0; int nOffset = 0; int nFound = 0; int nVecsize = 0; int nSubstrings = 0; int *pnVec = NULL; const char *kszErr = NULL; const int kiRegopt = PCRE_DOTALL | PCRE_MULTILINE; /* const int kiRegopt = PCRE_DOTALL | PCRE_MULTILINE | PCRE_UNGREEDY;*/ pcre *pRegex = NULL; /* Perl Compatible Regular Expression */ pcre_extra *pExtra = NULL; /* Used for studying an expression */ assert(pScript); /* Check for a valid incoming script */ assert(configGetval(RC_DEF_VAL)); if (!kszSecname) /* If we get a NULL section label, then throw up */ RC_THROW(RC_ERR_USE); if ((pRegex = pcre_compile(configGetval(RC_DEF_VAL), kiRegopt, &kszErr, &nOffset, NULL)) == NULL) { RC_THROW(RC_ERR_SYS); } pExtra = pcre_study(pRegex, 0, &kszErr); /* Study the FSM */ if (kszErr) { /* Variable contains a string reference in case of errors */ free(pRegex); RC_THROW(RC_ERR_SYS); } if (pcre_fullinfo(pRegex, pExtra, PCRE_INFO_CAPTURECOUNT, &nSubstrings)) RC_THROW(RC_ERR_SYS); /* Use multiples of six, because PCRE needs 2x multiples of three */ nVecsize = 6 * (nSubstrings > 0 ? nSubstrings : 1); nVecsize *= RC_GOOD_MEASURE; /* Add redundancy factor for error margin */ /* pAwesome += RC_GOOD_VIBRATIONS;*/ /* Add good vibes for super action */ /***********************************************************************/ /* Reminder: PCRE writes vectors to help identify substrings. */ /* That means that in the following code we can */ /* execute a compiled PCRE regex (ab)(\s)(.*)$ */ /* */ /* piBlocend + pnVec[0] = 'start of whole matched string' */ /* piBlocend + pnVec[1] = 'end of whole matched string' */ /* piBlocend + pnVec[2] = 'start of first substring (ab)' */ /* piBlocend + pnVec[3] = 'end of first substring (ab)' */ /* piBlocend + pnVec[4] = 'start of second substring (\s)' */ /* piBlocend + pnVec[5] = 'end of second substring (\s)' */ /* piBlocend + pnVec[6] = 'start of third substring (.*)' */ /* piBlocend + pnVec[7] = 'end of third substring (.*)' */ /***********************************************************************/ /* Filter the rc file for the section label, do it here the first time */ pnVec = calloc(nVecsize, sizeof(int)); /* 2/3 vec 1/3 scrapinfo */ nFound = pcre_exec(pRegex, pExtra, *pScript,\ strlen(*pScript), 0, 0, pnVec, nVecsize); piBlocend = *pScript; /* Start piBlocend pointing to the script object */ while (nFound > 1) { /* Loop as long as we have more sections */ piLabstart = piBlocend + *(pnVec + 2); nLabsize = *(pnVec + 3) - *(pnVec + 2); /* Test the substring. If it matches our label, make a new section */ if (strncmp(piLabstart, kszSecname, nLabsize) == 0 \ && nLabsize == strlen(kszSecname) * sizeof (char)) { /* Handle the section body */ piStart = piBlocend + *(pnVec + 6); piEnd = piBlocend + *(pnVec + 7); pSec = sectionNew(kszSecname); sectionSetndata(pSec, piStart, piEnd - piStart); /* FIXME: Implement --ParseSectionParam for extra gravy */ /* Handle the section priority */ piStart = piBlocend + *(pnVec + 4); piEnd = piBlocend + *(pnVec + 5); szTemp = malloc((piEnd - piStart + 1) * sizeof (char)); strncpy(szTemp, piStart, piEnd - piStart + 1); piSubtemp = strstr(szTemp, RC_DEF_PRG); if (piSubtemp) { /* Priority pattern found */ for (nTmp = (int)piSubtemp + strlen(RC_DEF_PRG); \ isspace(*(char *)nTmp); nTmp += sizeof (char)); /* Strip */ nPri = strtol((char *)nTmp, &piSep, 10); if ((char *)nTmp == piSep) /* No priority number follows */ RC_THROW(RC_ERR_USE); /* 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 = strstr(szTemp, RC_DEF_UIG); if (piSubtemp) { /* Userid pattern found */ for (nTmp = (int)piSubtemp + strlen(RC_DEF_UIG); \ isspace(*(char *)nTmp); nTmp += sizeof (char)); /* Strip */ nUid = strtol((char *)nTmp, &piSep, 10); if ((char *)nTmp == piSep) /* No userid number follows */ { nUserbytes = strspn((strcspn(piSep, " \t\n") * sizeof (char) + piSep), " \t\n"); nUserbytes = (strlen(piSep) - nUserbytes + 1) * 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); /* Cleanup */ free(szTemp); szTemp = NULL; return(pSec); /* Section found, so return the text */ } /* Looks like we didn't find the section yet, so keep trying */ piBlocend += *(pnVec + 1); /* Find end of section block */ nFound = pcre_exec(pRegex, pExtra, piBlocend,\ strlen(piBlocend), 0, 0, pnVec, nVecsize); } /* Under correct conditions, the section subscript was returned in loop */ if (nFound == 1) /* User gave no klammern */ RC_THROW(RC_ERR_USE); /* so complain about it */ else if (nFound < PCRE_ERROR_NOMATCH) /* Generic problem so */ RC_THROW(RC_ERR_SYS); /* return an error */ return(NULL); /* Probably not found */ } /************************************************ * scriptGetdata(rc_script_t *) * * Return the private script data as a string * ************************************************/ const char *scriptGetdata(rc_script_t *pScript) { assert(pScript); /* Don't remove this! It encapsulates the script object, */ /* which might not be a simple string */ return((const char *)*pScript); } /************************************************ * scriptSetdata(rc_script_t *, const char *) * * Set the private script data from a string * ************************************************/ rc_return_t scriptSetdata(rc_script_t *pScript, const char *kszIn) { assert(pScript && kszIn); /* Avoid idiots */ if (*pScript) { free(*pScript); *pScript = NULL; } *pScript = malloc((strlen(kszIn) + 1) * sizeof(char)); strcpy(*pScript, kszIn); return(RC_THROW(RC_OK)); } /************************************************ * scriptDump(rc_script_t *) * * Print a script to standard out * ************************************************/ rc_return_t scriptDump(rc_script_t *pScript) { /* Don't remove this! It encapsulates the script object, */ /* which might not be a simple string */ if (pScript) { fprintf(stdout, "%s", scriptGetdata(pScript)); return(RC_THROW(RC_OK)); } else return(RC_THROW(RC_ERR_USE)); } /************************************************ * scriptWrite(rc_script_t *, const char *) * * Print a script to a file * ************************************************/ rc_return_t scriptWrite(rc_script_t *pScript, const char *szPath) { int nFdtmp = open(szPath, O_WRONLY | O_CREAT, 0600); FILE *pStream = NULL; /* Initial sanity checks */ if (!pScript || nFdtmp < 0) return(RC_THROW(RC_ERR_USE)); else pStream = fdopen(nFdtmp, "w"); /* Don't remove this! It encapsulates the script object, */ /* which might not be a simple string */ if (pStream) { fprintf(pStream, "%s", scriptGetdata(pScript)); fclose(pStream); return(RC_THROW(RC_OK)); } else return(RC_THROW(RC_ERR_USE)); } /************************************************ * scriptDelete(rc_script_t *) * * Destruct a script * ************************************************/ rc_return_t scriptDelete(rc_script_t *pScript) { assert(pScript); /* Check for a valid incoming script */ if (*pScript) { free(*pScript); *pScript = NULL; } else RC_THROW(RC_WRN_NUL); free(pScript); /* Free the script itself */ pScript = NULL; return(RC_THROW(RC_OK)); } @ 1.36 log @Fix embedded newline regex matching bug. @ text @d181 1 a181 1 const int kiRegopt = PCRE_DOTALL | PCRE_DOLLAR_ENDONLY; @ 1.35 log @More header corrections and improvements. @ text @d181 1 a181 1 const int kiRegopt = PCRE_DOTALL | PCRE_MULTILINE; @ 1.34 log @Correct and update copyrights and source headers. @ text @d1 1 a1 1 /* OSSP rc - Run-command processor d6 1 a6 1 ** This file is part of OSSP rc, a portable Run-command processor d27 1 a27 1 ** rc_script.c: Run-command processor ISO C source file @ 1.33 log @Replace references to scriptAppend with scriptAdd, and change name of scriptAppend to scriptnAppend to avoid surprises. Also, debug minimal memory overallocation in scriptnAppend. @ text @d2 3 a4 3 ** Copyright (c) 2002 Ralf S. Engelschall ** Copyright (c) 2002 Cable & Wireless Deutschland GmbH ** Copyright (c) 2002 The OSSP Project @ 1.32 log @Break off before fully implementing common section run ops, but after reorganization of class data, and additional member functions for section and script manipulation. @ text @d99 1 a99 1 nResize = strlen(*pDest) + strlen(*pSource) + sizeof (char) * 2; d117 5 a121 5 /**************************************************** * scriptAppend(rc_script_t *, const char *, size_t) * * Append text to a script * ****************************************************/ rc_return_t scriptAppend(rc_script_t *pScript, const char *szInbuf, size_t Size) d136 1 a136 1 nResize = strlen(*pScript) + Size + sizeof (char) * 2; d144 1 a144 1 strncat(pvRealloc, szInbuf, Size); d333 1 a333 1 return(*pScript); @ 1.31 log @Removed analyzer class, removed label class, implemented list class, implemented file class, cleanup and restructure. @ text @d53 1 a53 1 *pNew = malloc((strlen(scriptTostring(pOrig)) + 1) * sizeof(char)); d55 1 a55 1 strcpy(*pNew, scriptTostring(pOrig)); d88 30 d171 2 a172 2 long nPri = 0; long nUid = 0; d324 1 a324 1 * scriptTostring(rc_script_t *) * d327 1 a327 1 const char *scriptTostring(rc_script_t *pScript) d329 2 d333 18 a350 4 if (pScript && *pScript) return(*pScript); else RC_THROW(RC_ERR_USE); /* Script was never constructed */ d352 1 a352 1 return(NULL); /* Not reached */ d364 1 a364 1 fprintf(stdout, "%s", scriptTostring(pScript)); d389 1 a389 1 fprintf(pStream, "%s", scriptTostring(pScript)); @ 1.30 log @Sweeping cleanups. Reduced the analyzer to almost nothing. Removed unused method prototypes. Added 'parse' mode option that doesn't work yet. Removed procReadtmp. Change the way we build path names from the locations directory. @ text @d357 1 a357 1 assert(pScript); /* Check for a valid incoming script */ d366 1 a366 1 free(pScript); @ 1.29 log @Force scriptNew to always allocate internal data, solving memory handling problems throughout the script class. @ text @d304 3 a306 1 RC_THROW(RC_ERR_USE); /* Script was never constructed */ @ 1.28 log @Bug fix user id parsing on linux, and put strip block back in. @ text @d52 7 a58 3 *pNew = malloc((strlen(scriptTostring(pOrig)) + 1) * sizeof(char)); if (pNew) strcpy(*pNew, scriptTostring(pOrig)); d74 9 a82 1 *pScript = NULL; d98 1 a98 1 if (!szInbuf) { a99 1 } d105 2 a106 2 /* Add 2 to end of nResize to ensure that a \0 precedes any strings */ nResize = (*pScript != NULL ? strlen(*pScript) : 0) + Size + 2; d108 1 a108 1 if ((pvRealloc = calloc(1, (size_t)nResize)) == NULL) { a109 1 } d112 1 a112 1 if (*pScript) { d114 1 a114 4 strncat(pvRealloc, szInbuf, Size); } else strncpy(pvRealloc, szInbuf, Size); d117 1 a117 1 if (*pScript) { a118 2 *pScript = NULL; } d301 1 a301 1 if (pScript) d304 1 a304 1 return(NULL); d316 1 a316 1 fprintf(stdout, "%s", *pScript); d341 1 a341 1 fprintf(pStream, "%s", *pScript); d355 3 a357 1 if (*pScript) d359 3 a361 1 else { d363 1 a363 1 } d365 1 @ 1.27 log @Bug fix section to script extractor, and remove unneeded white space stripper. @ text @d218 2 a219 1 nTmp = (int)piSubtemp + strlen(RC_DEF_PRG); d232 2 a233 1 nTmp = (int)piSubtemp + strlen(RC_DEF_UIG); d237 2 a238 1 nUserbytes = (strcspn(piSep, " \t\n") + sizeof (char)) * sizeof (char); @ 1.26 log @Fix wrong type warning on SVR4. @ text @d218 1 a218 2 for (nTmp = (int)piSubtemp + strlen(RC_DEF_PRG);\ isspace(nTmp); nTmp += sizeof (char)); /* Strip */ d221 1 a221 1 sectionSetpri(pSec, RC_DEF_PRI); /* which is an error */ d231 1 a231 2 for (nTmp = (int)piSubtemp + strlen(RC_DEF_UIG); \ isspace(nTmp); nTmp += sizeof (char)); /* Strip */ @ 1.25 log @Clean up non BSD compiler warnings. @ text @d219 1 a219 1 isspace(*(char *)nTmp); nTmp += sizeof (char)); /* Strip */ d233 1 a233 1 isspace(*(char *)nTmp); nTmp += sizeof (char)); /* Strip */ @ 1.24 log @Bugfix eval mode temp file name creation, and scrap the nonportable BSD call to strnstr(3). @ text @d127 1 a127 1 int nLabsize = NULL; @ 1.23 log @Put throw logic back in where it was previously removed due to longjmp(3) problems. @ text @d128 2 a129 2 char *piSubtemp = NULL; /* To find priority and userid in substrings */ char *piBlocend = NULL; /* Misnomer used to control section looping */ d134 1 d214 3 a216 1 piSubtemp = strnstr(piStart, RC_DEF_PRG, piEnd - piStart); d230 1 a230 1 piSubtemp = strnstr(piStart, RC_DEF_UIG, piEnd - piStart); d264 4 @ 1.22 log @Fix logic to avoid false positives when comparing sections of unequal lengths. @ text @d87 1 a87 2 TRACE("Problem with appendScript"); /* return(RC_THROW(RC_ERR_USE));*/ d98 1 a98 2 TRACE("Problem with appendScript"); /* return(RC_THROW(RC_ERR_MEM));*/ d333 1 a333 2 fprintf(stderr, "FIXME: Replace with a real ex_throw!\n"); /* return(RC_THROW(RC_ERR_USE));*/ d345 1 a345 2 TRACE("Empty script created, unused, then destroyed"); /* RC_THROW(RC_WRN_NUL);*/ @ 1.21 log @Mostly finish setuid(2) work in section parsing of userid, and exec mode. @ text @d203 2 a204 1 if (!strncmp(piLabstart, kszSecname, nLabsize)) { @ 1.20 log @Bug fix recent eval mode addition, and add login name parsing to eval mode. @ text @d35 1 a35 1 #include /* For getlogin(2) */ @ 1.19 log @Implement eval mode. @ text @d53 4 a56 1 strcpy(*pNew, scriptTostring(pOrig)); d230 1 a230 1 for (nTmp = (int)piSubtemp + strlen(RC_DEF_UIG);\ d318 7 a324 1 FILE *pStream = fdopen(nFdtmp, "w"); d328 1 a328 1 if (pScript && pStream) { d334 2 a335 1 return(RC_THROW(RC_ERR_USE)); @ 1.18 log @Implement rc label ordered command printing and execution. @ text @d31 3 d44 15 d302 20 @ 1.17 log @Added section login accessors for user name handling during print op, implemented user id and user name parsing in section and script objects. @ text @d186 1 a186 1 pSec = sectionNew(); @ 1.16 log @Bugfix and cleanup priority scheduling, and add similar userid parameter handling. @ text @a29 1 #include d32 1 d113 3 d118 1 d197 5 a201 2 nPri = strtol((char *)nTmp, (char **)NULL, 10); sectionSetpri(pSec, nPri); d208 1 a208 1 if (piSubtemp) { /* Priority pattern found */ d211 27 a237 2 nUid = strtol((char *)nTmp, (char **)NULL, 10); sectionSetuid(pSec, nUid); @ 1.15 log @Implement priority scheduling with qsort(3) and priCompare(), adhere to naming standard, and bugfix. @ text @d32 1 d115 1 a176 2 /*fprintf(stderr, "Substring we want ist %s!\n", kszSecname); fprintf(stderr, "Compared with ist %s!\n", piLabstart);*/ d185 1 a188 1 /* FIXME: Implement --ParseSectionParam for extra gravy */ d191 3 a193 2 /* FIXME: Remove the 1 in the following line! */ nPri = strtol(piSubtemp + strlen(RC_DEF_PRG), (char **)NULL, 10); d200 11 a210 1 return(pSec); /* Section found, so return the text */ @ 1.14 log @Correctly use section accessors, split script to common and section vector objects, add sectionSetndata (with n length sections), and wrap script dump logic for NULL pointer safety. @ text @d192 1 a192 1 nPri = strtol(piSubtemp + strlen(RC_DEF_PRG) + 1, (char **)NULL, 10); a197 1 /*fprintf(stderr, "nPri ist %d!\n", pSec->nPri);*/ @ 1.13 log @Temporarily remove debugging help, and align whitespace. @ text @d70 1 a70 1 if (Size == 0) { a71 1 } d112 2 d183 1 a183 3 pSec->szData = malloc(piEnd - piStart + sizeof(char)); strncpy(pSec->szData, piStart, piEnd - piStart); *(pSec->szData + (piEnd - piStart)) = NULL; /* Terminate outgoing */ d192 2 a193 1 pSec->nPri = strtol(piSubtemp + strlen(RC_DEF_PRG) + 1, (char **)NULL, 10); d196 1 a196 1 pSec->nPri = RC_DEF_PRI; d240 6 a245 2 fprintf(stdout, "%s", *pScript); return(RC_THROW(RC_OK)); @ 1.12 log @Bring rc back to life, corrected the processor and script object memory problems, and made small changes to test suite. @ text @d174 2 a175 2 fprintf(stderr, "Substring we want ist %s!\n", kszSecname); fprintf(stderr, "Compared with ist %s!\n", piLabstart); d198 1 a198 1 fprintf(stderr, "nPri ist %d!\n", pSec->nPri); d233 1 a233 1 * scriptDump(rc_script_t *) * @ 1.11 log @Intermediate priority implementation flush. Build is broken. @ text @d53 5 a57 5 /************************************************ * scriptAppend(rc_script_t *, char *, size_t) * * Append text to a script * ************************************************/ rc_return_t scriptAppend(rc_script_t *pScript, char *szInbuf, size_t Size) d174 2 @ 1.10 log @Some minor test changes and documentation. @ text @d33 4 a36 3 #include "rc.h" /* Public Rc interface */ #include "rc_pcre.h" /* For section parsing */ #include "rc_config.h" /* For configuration access */ d104 1 a104 1 char *scriptSection(rc_script_t *pScript, const char *kszSecname) d106 1 a106 1 char *szTempout = NULL; d109 1 d150 1 a150 1 /* Reminder: PCRE writes vectors to help identify substrings */ d156 6 a161 6 /* piBlocend + pnVec[2] = 'start of first substring ab' */ /* piBlocend + pnVec[3] = 'end of first substring ab' */ /* piBlocend + pnVec[4] = 'start of second substring \s' */ /* piBlocend + pnVec[5] = 'end of second substring \s' */ /* piBlocend + pnVec[6] = 'start of third substring .*' */ /* piBlocend + pnVec[7] = 'end of third substring .*' */ d174 1 a174 1 /* Test the substring. If it matches our label, generate a subscript */ d176 1 d179 20 a198 4 szTempout = malloc(piEnd - piStart + sizeof(char)); strncpy(szTempout, piStart, piEnd - piStart); *(szTempout + (piEnd - piStart)) = NULL; /* Terminate outgoing */ return(szTempout); /* Section found, so return the text */ d201 1 a202 1 /* Get ready for the next round of matching */ @ 1.9 log @Added generic parsing of section arguments, adjusted defaults and tests. @ text @d147 15 @ 1.8 log @Implemented command execution mode, and now OSSP rc is dangerous to use because it will actually execute code. Test suite is adjusted accordingly. @ text @d159 2 a160 2 piStart = piBlocend + *(pnVec + 4); piEnd = piBlocend + *(pnVec + 5); @ 1.7 log @Correct and generally improve mixing of sections and parsing the labels. @ text @d183 14 @ 1.6 log @Resolve some null pointer and ex_ bugs, and clean up --print output. @ text @d107 2 a108 1 char *piLabend = NULL; a115 1 const int kiRegopt = 0; d117 2 d126 2 a127 2 if (!kszSecname) /* If we get a NULL section label, give a NULL result */ return (NULL); /* This might be useful in some loop constructs */ d145 1 d152 1 a152 1 piLabend = *pScript; /* Start piLabstart pointing to the script object */ d154 2 a155 2 piLabstart = piLabend + *(pnVec + 2 * RC_SEC_SUB); /* Seclabel start */ piLabend += *(pnVec + 1); /* Find end of section label */ d158 3 a160 9 if (!strncmp(piLabstart , kszSecname, sizeof(kszSecname))) { piStart = strstr(piLabend, "\n") + sizeof(char); /* Wrap to start */ /* See if more sections follow or if this is the last one */ if (pcre_exec(pRegex, pExtra, piLabend, strlen(*pScript), 0, 0, pnVec, nVecsize) > 0) piEnd = piLabend + *pnVec; else /* Doch, last section in file */ piEnd = piLabend + strlen(*pScript); d167 1 d169 2 a170 2 nFound = pcre_exec(pRegex, pExtra, piLabend,\ strlen(piLabend), 0, 0, pnVec, nVecsize); @ 1.5 log @Implemented limited pattern matching of section labels. @ text @d190 3 a192 4 fprintf(stdout, "\n**************** Dumpskripte ****************\n"); fprintf(stdout, "%s\n", *pScript); fprintf(stdout, "**************** Dumpskripte ****************\n\n"); @ 1.4 log @Daily dump, start processing sections with regular expressions. @ text @d106 2 a107 1 char *szTmpsec = NULL; d111 4 d116 1 a116 1 const char *szErr = NULL; d127 1 a127 1 if ((pRegex = pcre_compile(configGetval(RC_DEF_VAL), kiRegopt, &szErr, &nOffset, NULL)) == NULL) { d131 4 a134 14 szTmpsec = malloc(strlen(kszSecname) + sizeof(char)); strcpy(szTmpsec, "%"); strcat(szTmpsec, kszSecname); piStart = strstr(*pScript, szTmpsec); /* Find start of section */ if (!piStart) /* Short circuit if the */ return(NULL); /* section was not found */ piStart = strstr(piStart, "\n") + sizeof(char); /* Wrap to next line */ piEnd = strstr(piStart + sizeof(char), "%"); /* FIXME: Remove hardcoded */ if (piEnd) { szTempout = malloc(piEnd - piStart + sizeof(char)); strncpy(szTempout, piStart, piEnd - piStart); *(szTempout + (piEnd - piStart)) = NULL; /* Terminate outgoing string */ a135 2 else /* We are operating on the last section of the file */ szTempout = strdup(piStart); /* FIXME: Can we assume '\0' at EOF? */ d137 45 a181 1 return(szTempout); d213 1 @ 1.3 log @Improved section parsing and added back most error condition logic. All combinations of wildcard globbing, multiple section parsing, and error handling now work (except for a problem relating to or using ex). @ text @d33 3 a35 1 #include "rc.h" d105 20 a124 4 char *szTempout = NULL; char *szTmpsec = NULL; char *piStart = NULL; char *piEnd = NULL; a125 1 assert(pScript); /* Check for a valid incoming script */ @ 1.2 log @Fixed memory bound violation and added section parsing logic. @ text @d101 1 a101 1 const char *scriptSection(rc_script_t *pScript, const char *kszSecname) d108 1 d114 3 d119 7 a125 3 szTempout = malloc(piEnd - piStart + sizeof(char)); strncpy(szTempout, piStart, piEnd - piStart); *(szTempout + (piEnd - piStart)) = NULL; /* Terminate the outgoing string */ @ 1.1 log @Intermediate committal, lots of additions, compiles and works very limited. @ text @d59 2 d87 1 a87 1 /* Coerce strings into one Script again */ d95 25 @