[Patch] Using define with shellcommands action breaks allclasses variable

Andy Clayton <[email protected]> Sat, 15 Aug 2009 18:48:25 -0500
Newsgroups gmane.comp.sysutils.cfengine.bugs
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--------------010709050602030800060204
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Currently when using a shellcommand with a define set, trying to use
$(allclasses) in the argument list expands incorrectly to what the
define option is set to.

Example config:

     shellcommands:
         "/var/cfengine/scripts/packages.sh $(allclasses)"
define=script_success

What runs:

     /var/cfengine/scripts/packages.sh script_success

Expected:

     /var/cfengine/scripts/packages.sh CFALLCLASSES=class1:class2:class3:...

This happens because the ALLCLASSBUFFER is currently being used for two
purposes. One is to hold the string representation of the class stack
that replaces $(allclasses), and the other is to temporarily hold the
define option while parsing.

The supplied patch (against 2.2.10) adds a new DEFINECLASSBUFFER (to
match the ELSECLASSBUFFER), and uses that instead for holding the define
option. Note that we need to still zero out the ALLCLASSBUFFER in the
action initialization because $(allclasses) currently cannot be expanded
when first parsed. If it is we run into problems with
Build2DListFromVarstring splitting on the colons in the class string.

Overall the changes are fairly minimal as ALLCLASSBUFFER is not
referenced in tons of places.

Thanks,

Andy Clayton


--------------010709050602030800060204
Content-Type: text/x-patch;
 name="cfengine-2.2.10-allclasses-with-define-2.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="cfengine-2.2.10-allclasses-with-define-2.patch"

diff -U5 src.orig/cf.extern.h src/cf.extern.h
--- src.orig/cf.extern.h	2009-08-13 12:47:19.576272000 -0500
+++ src/cf.extern.h	2009-08-13 12:56:00.275629000 -0500
@@ -196,10 +196,11 @@
 extern char *GROUPBUFF;
 extern char *ACTIONBUFF;
 extern char *CLASSBUFF;
 extern char ALLCLASSBUFFER[4*CF_BUFSIZE];
 extern char CHROOT[CF_BUFSIZE];
+extern char DEFINECLASSBUFFER[CF_BUFSIZE];
 extern char ELSECLASSBUFFER[CF_BUFSIZE];
 extern char FAILOVERBUFFER[CF_BUFSIZE];
 extern char *LINKFROM;
 extern char *LINKTO;
 extern char *ERROR;
diff -U5 src.orig/globals.c src/globals.c
--- src.orig/globals.c	2009-08-13 12:47:20.375121000 -0500
+++ src/globals.c	2009-08-13 12:51:13.439898000 -0500
@@ -125,10 +125,11 @@
 
   PUBLIC char VINPUTFILE[CF_BUFSIZE];
   PUBLIC char VCURRENTFILE[CF_BUFSIZE];
   PUBLIC char VLOGFILE[CF_BUFSIZE];
   PUBLIC char ALLCLASSBUFFER[CF_ALLCLASSSIZE];
+  PUBLIC char DEFINECLASSBUFFER[CF_BUFSIZE];
   PUBLIC char ELSECLASSBUFFER[CF_BUFSIZE];
   PUBLIC char FAILOVERBUFFER[CF_BUFSIZE];
   PUBLIC char CHROOT[CF_BUFSIZE];
   PUBLIC char EDITBUFF[CF_BUFSIZE];
 
diff -U5 src.orig/install.c src/install.c
--- src.orig/install.c	2009-08-13 12:47:19.668071000 -0500
+++ src/install.c	2009-08-13 12:55:38.621735000 -0500
@@ -1975,11 +1975,11 @@
 if (strlen(buffer) > 1)
    { 
    DeleteSlash(buffer);
    }
 
-ExpandVarstring(ALLCLASSBUFFER,buffer2,""); 
+ExpandVarstring(DEFINECLASSBUFFER,buffer2,""); 
  
 if ((ptr = (struct Link *)malloc(sizeof(struct Link))) == NULL)
    {
    FatalError("Memory Allocation failed for InstallListItem() #1");
    }
@@ -2097,11 +2097,11 @@
    Debug1("Not installing linkchildren no match\n");
    return;
    }
 
 ExpandVarstring(from,ebuff,"");
-ExpandVarstring(ALLCLASSBUFFER,buffer,""); 
+ExpandVarstring(DEFINECLASSBUFFER,buffer,""); 
 
 Build2DListFromVarstring(&tp,to,LISTSEPARATOR,false);
 Set2DList(tp);
 
 for (sp = Get2DListEnt(tp); sp != NULL; sp = Get2DListEnt(tp))
@@ -2239,11 +2239,11 @@
    if ((ptr->classes = strdup(CLASSBUFF)) == NULL)
       {
       FatalError("Memory Allocation failed for InstallRequired() #2");
       }
    
-   ExpandVarstring(ALLCLASSBUFFER,buffer,"");
+   ExpandVarstring(DEFINECLASSBUFFER,buffer,"");
    
    if ((ptr->define = strdup(buffer)) == NULL)
       {
       FatalError("Memory Allocation failed for Installrequied() #2");
       }
@@ -3599,11 +3599,11 @@
    ptr->noabspath = NOABSPATH;
    ptr->next = NULL;
    ptr->done = 'n';
    ptr->scope = strdup(CONTEXTID);
 
-   ExpandVarstring(ALLCLASSBUFFER,ebuff,"");
+   ExpandVarstring(DEFINECLASSBUFFER,ebuff,"");
    
    if ((ptr->defines = strdup(ebuff)) == NULL)
       {
       FatalError("Memory Allocation failed for AppendShellcommand() #3");
       }
@@ -3774,11 +3774,11 @@
    ptr->noabspath = NOABSPATH;
    ptr->next = NULL;
    ptr->done = 'n';
    ptr->scope = strdup(CONTEXTID);
 
-   ExpandVarstring(ALLCLASSBUFFER,ebuff,"");
+   ExpandVarstring(DEFINECLASSBUFFER,ebuff,"");
    
    if ((ptr->defines = strdup(ebuff)) == NULL)
       {
       FatalError("Memory Allocation failed for AppendSCLI() #3");
       }
@@ -3835,11 +3835,11 @@
    if ((ptr->name = strdup(sp)) == NULL)
       {
       FatalError("Memory Allocation failed for AppendDisable() #2");
       }
    
-   ExpandVarstring(ALLCLASSBUFFER,ebuff,"");
+   ExpandVarstring(DEFINECLASSBUFFER,ebuff,"");
 
    if ((ptr->defines = strdup(ebuff)) == NULL)
       {
       FatalError("Memory Allocation failed for AppendDisable() #3");
       }
@@ -4311,11 +4311,11 @@
    if ((ptr->classes = strdup(CLASSBUFF)) == NULL)
       {
       FatalError("Memory Allocation failed for InstallMakepath() #3");
       }
    
-   ExpandVarstring(ALLCLASSBUFFER,buffer,""); 
+   ExpandVarstring(DEFINECLASSBUFFER,buffer,""); 
    
    if ((ptr->defines = strdup(buffer)) == NULL)
       {
       FatalError("Memory Allocation failed for InstallMakepath() #3a");
       }
@@ -4799,11 +4799,11 @@
    if ((ptr->classes = strdup(CLASSBUFF)) == NULL)
       {
       FatalError("Memory Allocation failed for InstallFileListItem() #3");
       }
 
-   ExpandVarstring(ALLCLASSBUFFER,ebuff,""); 
+   ExpandVarstring(DEFINECLASSBUFFER,ebuff,""); 
 
    if ((ptr->defines = strdup(ebuff)) == NULL)
       {
       FatalError("Memory Allocation failed for InstallFileListItem() #3");
       }
@@ -4928,11 +4928,11 @@
 if ((ptr->restart = strdup(ebuff)) == NULL)
    {
    FatalError("Memory Allocation failed for InstallProcItem() #3");
    }
 
-ExpandVarstring(ALLCLASSBUFFER,ebuff,""); 
+ExpandVarstring(DEFINECLASSBUFFER,ebuff,""); 
  
 if ((ptr->defines = strdup(ebuff)) == NULL)
    {
    FatalError("Memory Allocation failed for InstallProcItem() #4");
    }
@@ -5112,11 +5112,11 @@
 if ((ptr->classes = strdup(CLASSBUFF)) == NULL)
    {
    FatalError("Memory Allocation failed for InstallPackageItem() #4");
    }
 
-ExpandVarstring(ALLCLASSBUFFER,buffer,"");
+ExpandVarstring(DEFINECLASSBUFFER,buffer,"");
 
 if ((ptr->defines = strdup(buffer)) == NULL)
    {
    FatalError("Memory Allocation failed for InstallPackageItem() #4a");
    }
@@ -5319,11 +5319,11 @@
       if ((ptr->action = strdup(action)) == NULL)
          {
          FatalError("Memory Allocation failed for InstallImageItem() #6");
          }
       
-      ExpandVarstring(ALLCLASSBUFFER,buf4,"");
+      ExpandVarstring(DEFINECLASSBUFFER,buf4,"");
       
       if ((ptr->defines = strdup(buf4)) == NULL)
          {
          FatalError("Memory Allocation failed for InstallImageItem() #7");
          }
@@ -6048,11 +6048,11 @@
    {
    snprintf(OUTPUT,CF_BUFSIZE*2,"Undeclared installable define=%s (see AddInstallable)",value);
    yyerror(OUTPUT);
    }
 */
-strcpy(ALLCLASSBUFFER,value);
+strcpy(DEFINECLASSBUFFER,value);
 
 for (sp = value; *sp != '\0'; sp++)
    {
    if (*sp == ':' || *sp == ',' || *sp == '.')
       {
@@ -6770,11 +6770,11 @@
 if ((sp = strdup(wild)) == NULL)
    {
    FatalError("Memory Allocation failed for PrependTidy() #2");
    }
 
-ExpandVarstring(ALLCLASSBUFFER,buffer,""); 
+ExpandVarstring(DEFINECLASSBUFFER,buffer,""); 
 
 if ((tp->defines = strdup(buffer)) == NULL)
    {
    FatalError("Memory Allocation failed for PrependTidy() #2a");
    }
diff -U5 src.orig/parse.c src/parse.c
--- src.orig/parse.c	2009-08-13 12:47:19.857529000 -0500
+++ src/parse.c	2009-08-13 15:04:16.475832000 -0500
@@ -1277,10 +1277,11 @@
  PKGVER[0] = '\0';
 
  STRATEGYNAME[0] = '\0';
  FILTERNAME[0] = '\0';
  memset(ALLCLASSBUFFER,0,CF_BUFSIZE);
+ memset(DEFINECLASSBUFFER,0,CF_BUFSIZE);
  memset(ELSECLASSBUFFER,0,CF_BUFSIZE);
  
  strcpy(CFSERVER,"localhost");
  
  IMGCOMP = DISCOMP='>';


--------------010709050602030800060204
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Bug-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/bug-cfengine

--------------010709050602030800060204--