Forum: CFEngine Help
Subject: Re: allclasses facility?
Author: sauer
Link to topic: https://cfengine.com/forum/read.php?3,27436,27524#msg-27524

neilhwatson Wrote:
-------------------------------------------------------
> What other facility is there to get a list of all
> defined classes?

You're probably supposed to parse the allclasses environment variable (which is 
mentioned only once in the reference manual, which isn't clearly an environment 
variable of CFEngine array, and whose format seems to be undocumented either 
way), until that gets inconvenient, at which time I guess you are expected to 
redesign things to make that more convenient. :)


These variables end up in a context which has the same name as the module. When 
the $(allclasses) variable becomes too large to manipulate conveniently, you 
can access the complete list of currently defined classes in the file 
/var/cfengine/state/allclasses. 


Of course, I don't see that variable in CFEngine or in the environment:


sauer@host
$ cat test.cf
bundle agent a{
commands:
  "/usr/bin/pcregrep -oi 'allclass[^[:cntrl:]]+' /proc/self/environ"
    module => "true";
reports:
  cfengine:: "$(allclasses)";
}
sauer@host
$ cf-agent -f ./test.cf -b a -IK
 >> Using command line specified bundlesequence
 -> Executing '/usr/bin/pcregrep -oi 'allclass[^[:cntrl:]]+' 
/proc/self/environ' ...(timeout=-678,owner=-1,group=-1)
 !! Finished command related to promiser "/usr/bin/pcregrep -oi 
'allclass[^[:cntrl:]]+' /proc/self/environ" -- an error occurred (returned 1)
 -> Completed execution of /usr/bin/pcregrep -oi 'allclass[^[:cntrl:]]+' 
/proc/self/environ
R: $(allclasses)


FYI...
On Linux, /proc//environ contains all of 's environment variables, separated by 
null characters, /proc/self is "whatever process is accessing it", and 
"pcregrep or grep -o" prints only the part of the line that matches.  Just in 
case that pcregrep command doesn't make any sense (it really does work, 
though). ;)


sauer@host
$ /usr/bin/pcregrep -oi 'shell[^[:cntrl:]]+' /proc/self/environ
SHELL=/usr/bin/sh


As an aside, "pcregrep -oi '[[:cntrl:]]?[^[:cntrl:]]*ass[^[:cntrl:]]+' 
/proc/*/environ" as root is a fun way to find people who think that they're 
being secure / clever by setting $PASSWORD environment variables instead of 
passing them on the command line.  Yay security!

_______________________________________________
Help-cfengine mailing list
Help-cfengine@cfengine.org
https://cfengine.org/mailman/listinfo/help-cfengine

Reply via email to