OSSP CVS Repository

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

Check-in Number: 3356
Date: 2003-May-21 14:49:20 (local)
2003-May-21 12:49:20 (UTC)
User:ms
Branch:
Comment: Implement eval mode.
Tickets:
Inspections:
Files:
ossp-pkg/rc/00TODO      1.40 -> 1.41     1 inserted, 0 deleted
ossp-pkg/rc/rc.h      1.45 -> 1.46     3 inserted, 0 deleted
ossp-pkg/rc/rc.pod      1.30 -> 1.31     4 inserted, 4 deleted
ossp-pkg/rc/rc_const.h      1.14 -> 1.15     5 inserted, 0 deleted
ossp-pkg/rc/rc_private.h      1.27 -> 1.28     5 inserted, 4 deleted
ossp-pkg/rc/rc_proc.c      1.28 -> 1.29     61 inserted, 21 deleted
ossp-pkg/rc/rc_script.c      1.18 -> 1.19     38 inserted, 0 deleted
ossp-pkg/rc/rc_sect.c      1.8 -> 1.9     21 inserted, 0 deleted

ossp-pkg/rc/00TODO 1.40 -> 1.41

--- 00TODO       2003/05/19 19:04:45     1.40
+++ 00TODO       2003/05/21 12:49:20     1.41
@@ -28,6 +28,7 @@
 Document
   Refs, pri, user, group, ci, go only in normal (not special) sections.
   Section definition regular expressions need to follow a format ()\2.
+  Changed from OpenPKG: temp files no longer have pids in their file names
 
 Questions
   Should location regex specify a directory and prefix separately, or files*?


ossp-pkg/rc/rc.h 1.45 -> 1.46

--- rc.h 2003/05/20 15:06:41     1.45
+++ rc.h 2003/05/21 12:49:20     1.46
@@ -111,9 +111,11 @@
 
 /* Script function prototypes */
 rc_script_t *scriptNew(void);
+rc_script_t *scriptCopy(rc_script_t *);
 rc_return_t scriptAppend(rc_script_t *, const char *, size_t);
 rc_section_t *scriptSection(rc_script_t *, const char *);
 rc_return_t scriptDump(rc_script_t *);
+rc_return_t scriptWrite(rc_script_t *, const char *);
 const char *scriptTostring(rc_script_t *);
 rc_return_t scriptDelete(rc_script_t *);
 
@@ -136,6 +138,7 @@
 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 *);
+rc_return_t sectionWrite(rc_section_t *, const char *);
 rc_return_t sectionDelete(rc_section_t *);
 
 /* Processor function prototypes */


ossp-pkg/rc/rc.pod 1.30 -> 1.31

--- rc.pod       2002/04/11 16:52:45     1.30
+++ rc.pod       2003/05/21 12:49:20     1.31
@@ -326,8 +326,8 @@
 =head1 SEE ALSO
 
 OSSP rc integrates concepts taken from other run-command architectures. For
-more information, inspect the /etc/rc structures provided by the FreeBSD,
-Solaris, and Red Hat distributions.
+more information, inspect the /etc/rc structures provided by the NetBSD,
+FreeBSD, Solaris, and Red Hat distributions.
 
 rc-sample(5).
 
@@ -343,7 +343,7 @@
 in OpenPKG (http://www.openpkg.org/). The prototype was a slow and less robust
 Bourne shell script. B<OSSP rc> is comparitively faster, more robust, and more
 flexible. This flexibility allows for wider range of use, and B<OSSP rc> can
-therefore be used in a variety of situations. It is no longer exclusive to the
-OpenPKG project.
+therefore be used in a larger variety of situations. It is no longer exclusive
+to the OpenPKG project.
 
 =cut


ossp-pkg/rc/rc_const.h 1.14 -> 1.15

--- rc_const.h   2003/05/16 12:37:10     1.14
+++ rc_const.h   2003/05/21 12:49:21     1.15
@@ -130,4 +130,9 @@
 #define RC_DEF_PRG    "-p"                      /* Section priority string */
 #define RC_DEF_PRI    200                       /* Section priority value */
 
+/* Handling temporary and output during evaluation mode */
+#define RC_EVL_TMP    "rc.XXXX"                              /* Temporary file template */
+#define RC_EVL_SUF    ".tmp"                                 /* Temporary file suffix   */
+#define RC_EVL_OUT    ". %s; rm -f %s 2>/dev/null || true\n" /* Command line output     */
+
 #endif /* __OSSPRC_CONST_H__ */


ossp-pkg/rc/rc_private.h 1.27 -> 1.28

--- rc_private.h 2003/05/20 15:06:42     1.27
+++ rc_private.h 2003/05/21 12:49:21     1.28
@@ -49,10 +49,11 @@
 /* FIXME Tie to shtool generation */
 #define RC_VERSION   "77.77"
 
-#define RC_SEC_SUB         1
-#define RC_GOOD_MEASURE    8
-#define RC_EXEC_MAXARGS    8
-#define RC_READ_BUFSIZE 1024
+#define RC_SEC_SUB          1
+#define RC_GOOD_MEASURE     8
+#define RC_EXEC_MAXARGS     8
+#define RC_READ_BUFSIZE  1024
+#define RC_WRITE_BUFSIZE 1024
 #define RC_STR_ID  "OSSP rc"                        /* APPID for OSSP rc */
 #define RC_UID_ID 0xf8a1845c55e6449481176f6e9cea34b /* UUID for OSSP rc  */
 


ossp-pkg/rc/rc_proc.c 1.28 -> 1.29

--- rc_proc.c    2003/05/20 17:14:17     1.28
+++ rc_proc.c    2003/05/21 12:49:21     1.29
@@ -91,7 +91,7 @@
 
     /* 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)) == -1) {
+        if ((nFdfunc = open(pRc->m_pAnal->m_szFuncs, O_RDONLY)) < 0) {
             RC_THROW(RC_ERR_FNC);
         }
     }
@@ -99,17 +99,13 @@
     /* Stick on the starting shell id line */
     scriptAppend(pRc->m_pScriptcom, "#! /bin/sh\n", strlen("#! /bin/sh\n"));
 
-    /* Read the func file if it was opened successfully */
-    /* We unfortunately make the assumption that 0 is an invalid filedesc */
-    if (nFdfunc) {
-        /* Read data from the func file */
-        while ((nRet = read(nFdfunc, sBuf, RC_READ_BUFSIZE)) > 0) {
-            scriptAppend(pRc->m_pScriptcom, sBuf, nRet);
-        }
-        scriptAppend(pRc->m_pScriptcom, "\n", sizeof(char));
-        if (nRet == -1) /* Handle read errors */
-            RC_THROW(RC_ERR_IO);
+    /* Read data from the func file */
+    while ((nRet = read(nFdfunc, sBuf, RC_READ_BUFSIZE)) > 0) {
+        scriptAppend(pRc->m_pScriptcom, sBuf, nRet);
     }
+    scriptAppend(pRc->m_pScriptcom, "\n", sizeof(char));
+    if (nRet == -1) /* Handle read errors */
+        RC_THROW(RC_ERR_IO);
 
     /* Iteratively read possibly globbed rc files */
     for (nRc = 0; nRc < pRc->m_pAnal->m_nRcs; nRc++)
@@ -194,13 +190,16 @@
 ************************************************/
 rc_return_t procRun(rc_proc_t *pRc)
 {
-    int   nTmp   = 0;               /* Generic index */
-    int   nRcs   = 0;               /* Rc index      */
-    int   nSecs  = 0;               /* Section index */
-    char *szTmp  = NULL;            /* Generic temporary string      */
-    char *szExec = NULL;            /* Used only during exec mode    */
-    char *pszVec[RC_EXEC_MAXARGS];  /* For passing in to execv(3)    */
-    rc_section_t **ppSectmp = NULL; /* Used with priority scheduling */
+    int   nTmp      = 0;              /* Generic index       */
+    int   nTmpname  = 0;              /* Temp file name size */
+    int   nRcs      = 0;              /* Rc index            */
+    int   nSecs     = 0;              /* Section index       */
+    char *szTmpfile = NULL;           /* Path of temporary file          */
+    char *szTmp     = NULL;           /* Generic temporary string        */
+    char *szExec    = NULL;           /* Used only during exec mode      */
+    char *pszVec[RC_EXEC_MAXARGS];    /* For passing in to execv(3)      */
+    rc_script_t   *pFatscript = NULL; /* To build a comprehensive script */
+    rc_section_t **ppSectmp   = NULL; /* Used with priority scheduling   */
 
     /****************************************************/
     /* This will execute, evaluate, or print the script */
@@ -208,10 +207,51 @@
     /* Eval  - Print machine evaluatable format         */
     /* Print - Print human readable format              */
     /****************************************************/
-    if (configGetval(RC_EVL_VAL))                               /* Evaluate */
-        fprintf(stderr, "Error: Evaluate is not implemented yet.\n"); /* FIX */
+    if (configGetval(RC_EVL_VAL)) {                             /* Evaluate */
+        /* Allocate a block of section pointers to use temporarily */
+        ppSectmp = calloc(pRc->m_pAnal->m_nRcs, sizeof(rc_section_t *));
+        /* Allocate the command chain string to execute with execv(3) */
+        pFatscript = scriptCopy(pRc->m_pScriptcom);
+        for (nSecs = 0; nSecs < pRc->m_pAnal->m_nSecs; 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]))
+                    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]) {
+                szTmp = (char *)sectionGetdata(ppSectmp[nTmp]);
+                scriptAppend(pFatscript, szTmp, strlen(szTmp) + 1);
+                nTmp++;
+            }
+        }
+        free(ppSectmp);
+        ppSectmp = NULL;
+
+        szTmpfile = (char *)configGetval(RC_TMP_VAL);
+        nTmpname = (strlen(szTmpfile) + strlen(RC_EVL_TMP) + \
+                    strlen(RC_EVL_SUF) + 1) * sizeof(char);
+        szTmpfile = malloc(nTmpname);
+        strcpy(szTmpfile, configGetval(RC_TMP_VAL));
+        strcat(szTmpfile, RC_EVL_TMP);
+        mktemp(szTmpfile);
+        strcat(szTmpfile, RC_EVL_SUF);
+        scriptWrite(pFatscript, szTmpfile); /* Write the whole script out */
+        fprintf(stdout, RC_EVL_OUT, szTmpfile, szTmpfile);
+        free(szTmpfile);
+        szTmpfile = NULL;
+        scriptDelete(pFatscript);
+        pFatscript = NULL;
+    }
     else if (configGetval(RC_EXC_VAL)) {                        /* Execute  */
-        /* Allocate a block of section pointers to use as a temporary */
+        /* Allocate a block of section pointers to use temporarily */
         ppSectmp = calloc(pRc->m_pAnal->m_nRcs, sizeof(rc_section_t *));
         /* Allocate the command chain string to execute with execv(3) */
         szTmp = (char *)scriptTostring(pRc->m_pScriptcom);


ossp-pkg/rc/rc_script.c 1.18 -> 1.19

--- rc_script.c  2003/05/20 15:06:42     1.18
+++ rc_script.c  2003/05/21 12:49:21     1.19
@@ -28,6 +28,9 @@
 */
 
 #include <string.h>
+#include <stdlib.h>
+#include <unistd.h>     /* For mkstemp(3)             */
+#include <fcntl.h>      /* For open(2)                */
 #include <ctype.h>      /* For isspace(3)             */
 #include <pwd.h>        /* For getlogin(2)            */
 
@@ -38,6 +41,21 @@
 
 
 /************************************************
+* 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));
+    *pNew = malloc((strlen(scriptTostring(pOrig)) + 1) * sizeof(char));
+    strcpy(*pNew, scriptTostring(pOrig));
+
+    return(pNew);
+}
+
+/************************************************
 * scriptNew(void)                               *
 * Construct a script                            *
 ************************************************/
@@ -284,6 +302,26 @@
         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 = fdopen(nFdtmp, "w");
+
+    /* Don't remove this! It encapsulates the script object, */
+    /*                    which might not be a simple string */
+    if (pScript && pStream) {
+        fprintf(pStream, "%s", *pScript);
+        fclose(pStream);
+        return(RC_THROW(RC_OK));
+    }
+    else
         return(RC_THROW(RC_ERR_USE));
 }
 


ossp-pkg/rc/rc_sect.c 1.8 -> 1.9

--- rc_sect.c    2003/05/20 15:06:42     1.8
+++ rc_sect.c    2003/05/21 12:49:21     1.9
@@ -29,6 +29,8 @@
 
 #include <string.h> /* For string copy and such data ops */
 #include <stdlib.h> /* For memory ops */
+#include <unistd.h> /* For mktemp(3)  */
+#include <fcntl.h>  /* For open(2)    */
 
 #include "rc.h"     /* Public Rc interface */
 
@@ -230,6 +232,25 @@
         return(RC_THROW(RC_OK));
     }
     else
+        return(RC_THROW(RC_ERR_USE));
+}
+
+/************************************************
+* sectionWrite(rc_section_t *, const char *)    *
+* Print a section to a file                     *
+************************************************/
+rc_return_t sectionWrite(rc_section_t *pSec, const char *szPath)
+{
+    int nFdtmp = open(szPath, O_WRONLY | O_CREAT, 0600);
+    FILE *pStream = fdopen(nFdtmp, "w");
+
+    if (pSec && pStream) {
+        fprintf(pStream, "#su %s\n", sectionGetlogin(pSec));
+        fprintf(pStream, "%s", sectionGetdata(pSec));
+        fclose(pStream);
+        return(RC_THROW(RC_OK));
+    }
+    else
         return(RC_THROW(RC_ERR_USE));
 }
 

CVSTrac 2.0.1