help-cfengine
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bug (and patch) in functions.c: FileExists doesn't work if passed variab


From: Chip Seraphine
Subject: Bug (and patch) in functions.c: FileExists doesn't work if passed variable
Date: Mon, 24 Oct 2005 17:17:53 -0500
User-agent: Mozilla Thunderbird 1.0.5 (X11/20050711)

In 2.1.16, the FileExists() function does not work properly if passed a string with a variable in it. This is because the HandleStatInfo function passes an unexpanded string (which can contain a $(variable)) to lstat.

I was able to make it work by passing lstat(2) the expanded values generated by FunctionArgs() rather than the raw args value. This change causes FileExists to work correctly with variables in its argument list. (See attached patch, which is against current snashot from the website).

Note that HandleStatInfo did not change between .15 and .16; the change appears to be in what is set by FunctionArgs() (which was largely rewritten). A proper bug fix should probably be in FunctionArgs(), not what I have below-- this patch is a demonstration. But since my C coding is mediocre at best, I'll leave an analysis of FunctionArgs to the smart people.... :)

--

As an example of what I am talking about, the code below did not work in 2.1.16 without this patch:


#File cf.file1
control:
   path= ( /etc )
   actionsequence= ( shellcommands )

shellcommands:
   "/bin/echo here I am"
import:
     cf.file2



#File cf.file2
groups:
   passwdfile_exists= ( FileExists(${path}/passwd) )

control:
alerts:
   foo|!foo::
      "path is ${path}"

   passwdfile_exists::  "Found it"
   !passwdfile_exists:: "Did not find it"


--

After applying the attached patch, it worked fine.


--- functions.c.orig    2005-10-24 16:57:58.861241789 -0500
+++ functions.c 2005-10-24 16:58:05.352295945 -0500
@@ -313,7 +313,7 @@
 
 FunctionArgs(args,argv,1);
 
-if (lstat(args,&statbuf) == -1)
+if (lstat(argv,&statbuf) == -1)
    {
    strcpy(value,CF_NOCLASS);
    return;

reply via email to

[Prev in Thread] Current Thread [Next in Thread]