The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Config::Secure - Perl extension for scripts run with PSC

SYNOPSIS

  use Config::Secure qw(get_conf write_conf);
  
  my %conf = get_conf();
  my $pass = $conf{pass};
  print "Last edited ".scalar(localtime($conf{lastedited}))."\n";
  $conf{lastedited} = time; 
  write_conf(\%conf);

DESCRIPTION

Config::Secure is a module for reading config data passed in by Perl Secure Conf (PSC) which can be found at http://psc.sourceforge.net/ It is really not useful unless your script is called through PSC.

PSC is a setuid C program which opens a protected conf file, drops its permissions, and then runs an unprotected perl script. Theoretically that perl script uses this module, and this module then opens the filehandle and parses the data to return it to you in a nice hash (or hashref). If the conf file is writeable by the setuid user, you may also use write_conf to write back to the conf file. For more info on PSC, see its documentation.

This module expects conf files to be in the form of key: value lines beginning with a # are comment lines. I have done my best to maintain conf file comments on writeback. If you want to have comments and write to your conf file, use the form of

# foo: this is a comment on foo foo: bar

that way your comments will stay associated with their proper keys.

You may have more than one value for a certain key, if you do this the value in the hash will automagically change from a scalar value to a hashref containing all the values in the order they were defined in the file. It is up to you to catch this if you put in multiple values for one key.

If you do not wish to use Config::Secure's get and write functions you are free to write your own, though I would suggest you still use Config::Secure to initialize your program. If you wish to do this I have provided the get_fh method. Calling get_fh returns you the filehandle to the file, and a flag as to whether or not you may write to it. Use it as follows:

  my($fh,$writeable) = Config::Secure::get_fh();

You may then do whatever you want with the file.

Config::Secure does a neat little trick for you, it sets $0 to contain the path to the psc link that was called to invoke the script. This makes it easier to replace any existing scripts that may rely on $0. Keep in mind, though, that FindBin will point to the actual script, not the same as the PSC link.

METHODS

  get_conf() - returns hash ref in scalar context, list in
               list context (for assigning to hashes)
               returns nothing on failure

  write_conf() - take a hash or hash ref as argument. Will
                 write what it understands to conf file.
                 returns 1 on success

  get_fh() - returns filehandle and writeable flag on success,
             nothing on failure

EXPORT

None by default.

Exportable methods are get_conf, write_conf and get_fh

AUTHOR

Anthony Ball <ant_psc@suave.net>

SEE ALSO

perl.