+ #
+ # read in the PATH environmental variable and prepend a set of 'safe'
+ # directories from which to test PRNG commands.
+ #
+
+ $path = $ENV{PATH};
+ $path = "/bin:/usr/bin:/sbin:/usr/sbin:/etc:" . $path;
+ @dirs = split(/:/, $path);
+
+ #
+ # sanitize each directory listed in the array.
+ #
+
+ @dirs = map {
+ $tmp = $_;
+ $tmp =~ s:/+:/:g;
+ $tmp =~ s:^\s+|\s+$::g;
+ $tmp;
+ } @dirs;
+
+ return \@dirs;
+}
+
+### addPRNGCommand( $prng_name, $exec_name )
+#
+# given a PRNG name and a corresponding executable name, add it to our list of
+# PRNG commands for which to find on the system.
+#
+
+sub addPRNGCommand
+{
+ my($prng_name, $exec_name) = @_;
+
+ prngAddNode($prng_name, $exec_name);
+}
+
+### copyPRNGFile( )
+#
+# read in ssh_prng_cmds.in, translate the program listings to the paths we have
+# found on the local system, and then write the output to ssh_prng_cmds.
+#
+
+sub copyPRNGFile
+{
+ my($fileInput, $fileOutput);
+ my($mode, $uid, $gid);
+ my($data);
+
+ if ( isPresent("$sysconfdir/ssh_prng_cmds") && !isForced() )
+ {
+ debug1("ssh_prng_cmds found and not forced. Not installing ssh_prng_cmds...\n");
+ return;
+ }
+
+ initPRNGHash();
+
+ debug1("Fixing paths in ssh_prng_cmds...\n");
+
+ $fileInput = "$setupdir/ssh_prng_cmds.in";
+ $fileOutput = "$sysconfdir/ssh_prng_cmds";
+
+ #
+ # verify that we are prepared to work with $fileInput
+ #
+
+ if ( !isReadable($fileInput) )
+ {
+ debug1("Cannot read $fileInput... skipping.\n");
+ return;
+ }
+
+ #
+ # verify that we are prepared to work with $fileOuput
+ #
+
+ if ( !prepareFileWrite($fileOutput) )
+ {
+ return;
+ }
+
+ #
+ # Grab the current mode/uid/gid for use later
+ #
+
+ $mode = (stat($fileInput))[2];
+ $uid = (stat($fileInput))[4];
+ $gid = (stat($fileInput))[5];
+
+ #
+ # Open the files for reading and writing, and loop over the input's contents
+ #
+
+ $data = readFile($fileInput);
+ for my $k (keys %$prngcmds)
+ {
+ $sub = prngGetExecPath($k);
+ $data =~ s:$k:$sub:g;
+ }
+ writeFile($fileOutput, $data);
+
+ #
+ # An attempt to revert the new file back to the original file's
+ # mode/uid/gid
+ #
+
+ chmod($mode, $fileOutput);
+ chown($uid, $gid, $fileOutput);
+
+ return 0;
+}
+
+### determinePRNGPaths( )
+#
+# for every entry in the PRNG hash, seek out and find the path for the
+# corresponding executable name.
+#
+
+sub determinePRNGPaths
+{
+ my(@paths, @dirs);
+ my($exec_name, $exec_path);
+
+ $dirs = getDirectoryPaths();
+
+ for my $k (keys %$prngcmds)
+ {
+ $exec_name = prngGetExecName($k);
+ $exec_path = findExecutable($exec_name, $dirs);
+ prngSetExecPath($k, $exec_path);
+ }
+
+ return;
+}
+
+### prngAddNode( $prng_name, $exec_name )
+#
+# add a new node to the PRNG hash
+#
+
+sub prngAddNode
+{
+ my($prng_name, $exec_name) = @_;
+ my($node);
+
+ if (!defined($prngcmds))
+ {
+ $prngcmds = {};
+ }
+
+ $node = {};
+ $node->{prng} = $prng_name;
+ $node->{exec} = $exec_name;
+
+ $prngcmds->{$prng_name} = $node;
+}
+
+### prngGetExecName( $key )
+#
+# get the executable name from the prng commands hash named by $key
+#
+
+sub prngGetExecName
+{
+ my($key) = @_;
+
+ return $prngcmds->{$key}->{exec};
+}
+
+### prngGetExecPath( $key )
+#
+# get the executable path from the prng commands hash named by $key
+#
+
+sub prngGetExecPath
+{
+ my($key) = @_;
+
+ return $prngcmds->{$key}->{exec_path};
+}
+
+### prngGetNode( $key )
+#
+# return a reference to the node named by $key
+#
+
+sub prngGetNode
+{
+ my($key) = @_;
+
+ return ${$prngcmds}{$key};
+}
+
+### prngSetExecPath( $key, $path )
+#
+# given a key, set the executable path in that node to $path
+#
+
+sub prngSetExecPath
+{
+ my($key, $path) = @_;
+
+ $prngcmds->{$key}->{exec_path} = $path;
+}
+
+### findExecutable( $exec_name, $dirs )
+#
+# given an executable name, test each possible path in $dirs to see if such
+# an executable exists.
+#
+
+sub findExecutable
+{
+ my($exec_name, $dirs) = @_;
+
+ for my $d (@$dirs)
+ {
+ $test = "$d/$exec_name";
+
+ if ( isExecutable($test) )
+ {
+ return $test;
+ }
+ }
+
+ return "undef";
+}
+
+### linkKeyFiles( $linklist )
+#
+# given an array of keys to link, link both the key and its public variant into
+# the gsi-openssh configuration directory.
+#
+
+sub linkKeyFiles
+{
+ my($linklist) = @_;