OSSP CVS Repository

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

ossp-pkg/rc/rc_proc.c 1.44 -> 1.45

--- rc_proc.c    2003/06/12 14:24:32     1.44
+++ rc_proc.c    2003/06/13 18:33:07     1.45
@@ -45,29 +45,23 @@
 ************************************************/
 rc_proc_t *procNew(void)
 {
+    ex_t Except;
     rc_proc_t *pNewrc = NULL;
 
-    pNewrc = malloc(sizeof(rc_proc_t));
-    pNewrc->m_pAnal = analNew();        /* Construct a configuration analyser */
-    analParse(pNewrc->m_pAnal);         /* Preprocess the anal configuration  */
-    pNewrc->m_pScriptcom = scriptNew(); /* Construct a run-command script     */
-    pNewrc->m_ppLabvec = calloc(pNewrc->m_pAnal->m_nRcs, sizeof(rc_label_t *));
+    ex_try {
+        pNewrc = malloc(sizeof(rc_proc_t));
+        pNewrc->m_pAnal = analNew();        /* Construct a configuration analyser */
+        analRcs (pNewrc->m_pAnal, configGetrcfile()); /* Preprocess analysis      */
+        pNewrc->m_pScriptcom = scriptNew(); /* Construct a run-command script     */
+        pNewrc->m_ppLabvec = calloc(pNewrc->m_pAnal->m_nRcs, sizeof(rc_label_t *));
+    }
+    ex_catch(Except)
+        rethrow;
 
     return(pNewrc);
 }
 
 /************************************************
-* procReadtmp(rc_proc_t *, const char *)        *
-* Open and store a temp file                    *
-************************************************/
-rc_return_t procReadtmp(rc_proc_t *pRc, const char *szTmpname)
-{
-    fprintf(stderr, "%s!!!\n", szTmpname);
-
-    return(RC_THROW(RC_OK));
-}
-
-/************************************************
 * procPopulate(rc_proc_t *)                     *
 * Populate the processor with run commands      *
 ************************************************/
@@ -84,17 +78,18 @@
     rc_section_t *pSec        = NULL;
     char         *szLocex     = NULL;
     rc_script_t  *pTempscript = NULL;
+    short         nTotalsecs  = vectorCount(configGetsecs());
 
     assert(*pRc->m_pAnal->m_pszRcs);
     sBuf = (char *)calloc(1, RC_READ_BUFSIZE);
 
     /* Open the func file if it exists in the configuration */
-    if (pRc->m_pAnal->m_szFuncs) {
-        if ((nFdfunc = open(pRc->m_pAnal->m_szFuncs, O_RDONLY)) >= 0) {
+    if (configGetval(RC_FNC_VAL)) {
+/* FIXME: Funcfile data does not belong in config section data! */
+        if ((nFdfunc = open(configGetval(RC_FNC_VAL), O_RDONLY)) >= 0) {
             /* Read data from the func file */
-            while ((nRet = read(nFdfunc, sBuf, RC_READ_BUFSIZE)) > 0) {
+            while ((nRet = read(nFdfunc, sBuf, RC_READ_BUFSIZE)) > 0)
                 scriptAppend(pRc->m_pScriptcom, sBuf, nRet);
-            }
             if (nRet == -1) /* Handle read errors */
                 RC_THROW(RC_ERR_IO);
             scriptAppend(pRc->m_pScriptcom, "\n", sizeof(char));
@@ -107,18 +102,38 @@
     for (nRc = 0; nRc < pRc->m_pAnal->m_nRcs; nRc++)
     {
         assert(*pRc->m_pAnal->m_pszRcs);
-        assert(pRc->m_pAnal->m_szLocs);
 
         /* Construct a new label */
         pRc->m_ppLabvec[nRc] = labelNew(pRc->m_pAnal->m_pszRcs[nRc]);
 
-        /* Build the path name */
-        szLocex = (char *)malloc(strlen(pRc->m_pAnal->m_szLocs) + \
+        /* Build the location path name */
+        if (!configGetval(RC_LOC_VAL)) {
+            szLocex = NULL;
+            szLocex = strdup("./"); /* FIXME: Relocate default val */
+            RC_THROW(RC_ERR_INT);   /* Config should have given a locs default */
+        }
+        else { /* Only enter block with valid string, strdup can't handle NULL */
+            if (*(configGetval(RC_LOC_VAL) + strlen(configGetval(RC_LOC_VAL)) - sizeof (char)) != '/') {
+                szLocex = malloc(strlen(configGetval(RC_LOC_VAL)) + \
+                                 sizeof (char) + \
+                                 strlen("rc.") + \
+                                 strlen(pRc->m_pAnal->m_pszRcs[nRc]) + \
+                                 sizeof (char));
+                strcpy(szLocex, configGetval(RC_LOC_VAL));
+                strcat(szLocex, "/");
+                strcat(szLocex, "rc."); /* FIXME: Make the prefix configurable */
+                strcat(szLocex, pRc->m_pAnal->m_pszRcs[nRc]);
+            }
+            else {
+                szLocex = malloc(strlen(configGetval(RC_LOC_VAL)) + \
+                                 strlen("rc.") + \
                                  strlen(pRc->m_pAnal->m_pszRcs[nRc]) + \
-                                 strlen("rc.") + 1);
-        strcpy(szLocex, pRc->m_pAnal->m_szLocs);
-        strcat(szLocex, "rc."); /* FIXME: Make the prefix configurable */
-        strcat(szLocex, pRc->m_pAnal->m_pszRcs[nRc]);
+                                 sizeof (char));
+                strcpy(szLocex, configGetval(RC_LOC_VAL));
+                strcat(szLocex, "rc."); /* FIXME: Make the prefix configurable */
+                strcat(szLocex, pRc->m_pAnal->m_pszRcs[nRc]);
+            }
+        }
 
         /* Open the rc file unconditionally */
         if ((nFdrc = open(szLocex, O_RDONLY)) == -1)
@@ -133,25 +148,24 @@
             RC_THROW(RC_ERR_IO);
 
         try {
-            /* Append config section if it exists */
+            /* Append common section if it exists */
             pSec = scriptSection(pTempscript, configGetval(RC_NCF_VAL));
             if (pSec) { /* Only operate if the section lookup succeeds */
                 scriptAppend(pRc->m_pScriptcom, sectionGetdata(pSec), strlen(sectionGetdata(pSec)));
-                scriptAppend(pRc->m_pScriptcom, "\n", sizeof(char));
+                scriptAppend(pRc->m_pScriptcom, "\n", strlen ("\n"));
                 sectionDelete(pSec);    /* Cleanup */
                 pSec = NULL;            /* Cleanup */
             }
 
-            for (nSect = 0; nSect < pRc->m_pAnal->m_nSecs; nSect++) { /* Iterate over */
+            for (nSect = 0; nSect < nTotalsecs; nSect++) { /* Iterate over */
                 /* Extract a section from the temp script, and append it */
-                pSec = scriptSection(pTempscript, pRc->m_pAnal->m_pszSecs[nSect]);
+                pSec = scriptSection(pTempscript, configGetsecs()[nSect]);
 
                 if (pSec) /* Only copy if the section lookup succeeds */
                     labelAppendsec(pRc->m_ppLabvec[nRc], pSec);
                 else if (configGetval(RC_DBG_VAL)) /* Only show if debug set */
                     fprintf(stderr, "#Warning: Missing section '%s' in %s!\n",\
-                        pRc->m_pAnal->m_pszSecs[nSect],\
-                        pRc->m_pAnal->m_pszRcs[nRc]);
+                        configGetsecs()[nSect], pRc->m_pAnal->m_pszRcs[nRc]);
 
                 if (pSec) { /* Cleanup iterative section string */
                     sectionDelete(pSec);
@@ -204,6 +218,7 @@
     rc_script_t   *pBangscript = NULL;  /* Common script with the shebang  */
     rc_script_t   *pFatscript  = NULL;  /* To build a comprehensive script */
     rc_section_t **ppSectmp    = NULL;  /* Used with priority scheduling   */
+    short          nTotalsecs  = vectorCount(configGetsecs()); /* Sections */
 
     /****************************************************/
     /* This will execute, evaluate, or print the script */
@@ -226,12 +241,12 @@
         }
         scriptAppend(pFatscript, scriptTostring(pRc->m_pScriptcom), \
             strlen(scriptTostring(pRc->m_pScriptcom)));
-        for (nSecs = 0; nSecs < pRc->m_pAnal->m_nSecs; nSecs++) {
+        for (nSecs = 0; nSecs < nTotalsecs; nSecs++) {
             for (nRcs = 0; nRcs < pRc->m_pAnal->m_nRcs; nRcs++) {
                 nTmp = 0;
                 while (nTmp < pRc->m_ppLabvec[nRcs]->m_nSecs && \
                     strcmp(pRc->m_ppLabvec[nRcs]->m_ppSecvec[nTmp]->m_szName, \
-                                pRc->m_pAnal->m_pszSecs[nSecs]))
+                                configGetsecs()[nSecs]))
                     nTmp++;
                 if (nTmp < pRc->m_ppLabvec[nRcs]->m_nSecs)
                     ppSectmp[nRcs] = pRc->m_ppLabvec[nRcs]->m_ppSecvec[nTmp];
@@ -287,7 +302,7 @@
         /* 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               */
-        for (nSecs = 0; nSecs < pRc->m_pAnal->m_nSecs; nSecs++) {
+        for (nSecs = 0; nSecs < nTotalsecs; nSecs++) {
             for (nTmp = 0; nTmp < pRc->m_pAnal->m_nRcs; nTmp++) {
                 if (pRc->m_ppLabvec[nTmp]->m_ppSecvec && \
                     pRc->m_ppLabvec[nTmp]->m_ppSecvec[nSecs]) {
@@ -304,12 +319,12 @@
         /* 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);
-        for (nSecs = 0; nSecs < pRc->m_pAnal->m_nSecs; nSecs++) {
+        for (nSecs = 0; nSecs < nTotalsecs; nSecs++) {
             for (nRcs = 0; nRcs < pRc->m_pAnal->m_nRcs; nRcs++) {
                 nTmp = 0;
                 while (nTmp < pRc->m_ppLabvec[nRcs]->m_nSecs && \
                     strcmp(pRc->m_ppLabvec[nRcs]->m_ppSecvec[nTmp]->m_szName, \
-                                pRc->m_pAnal->m_pszSecs[nSecs]))
+                                configGetsecs()[nSecs]))
                     nTmp++;
                 if (nTmp < pRc->m_ppLabvec[nRcs]->m_nSecs)
                     ppSectmp[nRcs] = pRc->m_ppLabvec[nRcs]->m_ppSecvec[nTmp];
@@ -429,12 +444,12 @@
         scriptDump(pBangscript);        /* Dump the common script with shebang */
         scriptDump(pRc->m_pScriptcom);  /* Dump the rest of the common script */
         scriptDelete(pBangscript);
-        for (nSecs = 0; nSecs < pRc->m_pAnal->m_nSecs; nSecs++) {
+        for (nSecs = 0; nSecs < nTotalsecs; nSecs++) {
             for (nRcs = 0; nRcs < pRc->m_pAnal->m_nRcs; nRcs++) {
                 nTmp = 0;
                 while (nTmp < pRc->m_ppLabvec[nRcs]->m_nSecs && \
                     strcmp(pRc->m_ppLabvec[nRcs]->m_ppSecvec[nTmp]->m_szName, \
-                                pRc->m_pAnal->m_pszSecs[nSecs]))
+                                configGetsecs()[nSecs]))
                     nTmp++;
                 if (nTmp < pRc->m_ppLabvec[nRcs]->m_nSecs)
                     ppSectmp[nRcs] = pRc->m_ppLabvec[nRcs]->m_ppSecvec[nTmp];
@@ -457,6 +472,33 @@
                 nTmp++;
             }
         }
+        free(ppSectmp);
+        ppSectmp = NULL;
+    }
+    else if (configGetval(RC_PAR_VAL)) {                    /* Parse names */
+        /* Allocate a block of section pointers to use as a temporary */
+        ppSectmp = calloc(pRc->m_pAnal->m_nRcs, sizeof(rc_section_t *));
+        fprintf(stderr, "file %s, section %s\n", pRc->m_ppLabvec[nRcs]->m_szName, RC_CMN_TEXT);
+        for (nSecs = 0; nSecs < nTotalsecs; nSecs++) {
+            for (nRcs = 0; nRcs < pRc->m_pAnal->m_nRcs; nRcs++) {
+                nTmp = 0;
+                while (nTmp < pRc->m_ppLabvec[nRcs]->m_nSecs && \
+                    strcmp(pRc->m_ppLabvec[nRcs]->m_ppSecvec[nTmp]->m_szName, \
+                                configGetsecs()[nSecs])) {
+                    nTmp++;
+                }
+                if (nTmp < pRc->m_ppLabvec[nRcs]->m_nSecs)
+                    ppSectmp[nRcs] = pRc->m_ppLabvec[nRcs]->m_ppSecvec[nTmp];
+                else
+                    ppSectmp[nRcs] = NULL;
+            }
+            qsort((void *)ppSectmp, (size_t)pRc->m_pAnal->m_nRcs, sizeof(rc_section_t *), priCompare);
+            nTmp = 0;
+            while (nTmp < pRc->m_pAnal->m_nRcs && ppSectmp[nTmp]) {
+                fprintf(stderr, "section %s\n", ppSectmp[nTmp]->m_szName);
+                nTmp++;
+            }
+        }
         free(ppSectmp);
         ppSectmp = NULL;
     }

CVSTrac 2.0.1