OSSP CVS Repository

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

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