]> andersk Git - gssapi-openssh.git/blobdiff - setup/setup-openssh.pl
o Set the LD_LIBRARY_PATH variable before we start running any programs.
[gssapi-openssh.git] / setup / setup-openssh.pl
index 8331aa841412e8e573d51cf31066dc2c3468fabd..4e65d179cd84e99c13f1713a81684d0c3e4c01d3 100644 (file)
@@ -29,6 +29,18 @@ if (!defined($gpath))
     die "GLOBUS_LOCATION needs to be set before running this script"
 }
 
+#
+# modify the ld library path for when we call ssh executables
+#
+
+$oldldpath = $ENV{LD_LIBRARY_PATH};
+$newldpath = "$gpath/lib";
+if (length($oldldpath) > 0)
+{
+    $newldpath .= ":$oldldpath";
+}
+$ENV{LD_LIBRARY_PATH} = "$newldpath";
+
 #
 # i'm including this because other perl scripts in the gpt setup directories
 # do so
@@ -64,36 +76,27 @@ my $keyfiles = {
                  "rsa1" => "ssh_host_key",
                };
 
-#
-# Check that we are running as root
-#
-
-$uid = $>;
-
-if ($uid != 0)
-{
-    print "--> NOTE: You must be root to run this script! <--\n";
-    exit 0;
-}
-
 sub copyKeyFiles
 {
     my($copylist) = @_;
     my($regex, $basename);
 
-    print "Copying ssh host keys...\n";
-
-    for my $f (@$copylist)
+    if (@$copylist)
     {
-        $f =~ s:/+:/:g;
+        print "Copying ssh host keys...\n";
 
-        if (length($f) > 0)
+        for my $f (@$copylist)
         {
-            $keyfile = "$f";
-            $pubkeyfile = "$f.pub";
+            $f =~ s:/+:/:g;
+
+            if (length($f) > 0)
+            {
+                $keyfile = "$f";
+                $pubkeyfile = "$f.pub";
 
-            action("cp $localsshdir/$keyfile $sysconfdir/$keyfile");
-            action("cp $localsshdir/$pubkeyfile $sysconfdir/$pubkeyfile");
+                action("cp $localsshdir/$keyfile $sysconfdir/$keyfile");
+                action("cp $localsshdir/$pubkeyfile $sysconfdir/$pubkeyfile");
+            }
         }
     }
 }
@@ -112,40 +115,79 @@ sub isReadable
     }
 }
 
+sub isPresent
+{
+    my($file) = @_;
+
+    if ( -e $file )
+    {
+        return 1;
+    }
+    else
+    {
+        return 0;
+    }
+}
+
 sub determineKeys
 {
     my($keyhash, $keylist);
     my($count);
 
+    #
+    # initialize our variables
+    #
+
     $count = 0;
 
     $keyhash = {};
     $keyhash->{gen} = [];   # a list of keytypes to generate
     $keyhash->{copy} = [];  # a list of files to copy from the 
+
     $genlist = $keyhash->{gen};
     $copylist = $keyhash->{copy};
 
+    #
+    # loop over our keytypes and determine what we need to do for each of them
+    #
+
     for my $keytype (keys %$keyfiles)
     {
         $basekeyfile = $keyfiles->{$keytype};
-        $keyfile = "$localsshdir/$basekeyfile";
-        $pubkeyfile = "$keyfile.pub";
 
-        if ( !isReadable($keyfile) || !isReadable($pubkeyfile) )
+        #
+        # if the key's are already present, we don't need to bother with this rigamarole
+        #
+
+        $gkeyfile = "$sysconfdir/$basekeyfile";
+        $gpubkeyfile = "$sysconfdir/$basekeyfile.pub";
+
+        if ( isPresent($gkeyfile) && isPresent($gpubkeyfile) )
         {
-            push(@$genlist, $keytype);
-            $count++;
+            next;
         }
-    }
 
-    for my $keytype (keys %$keyfiles)
-    {
-        if ( !grep(/^$keytype$/, @$genlist) )
+        #
+        # if we can find a copy of the keys in /etc/ssh, we'll copy them to the user's
+        # globus location
+        #
+
+        $mainkeyfile = "$localsshdir/$basekeyfile";
+        $mainpubkeyfile = "$localsshdir/$basekeyfile.pub";
+
+        if ( isReadable($mainkeyfile) && isReadable($mainpubkeyfile) )
         {
-            $keyfile = $keyfiles->{$keytype};
-            push(@$copylist, $keyfile);
+            push(@$copylist, $basekeyfile);
             $count++;
+            next;
         }
+
+        #
+        # otherwise, we need to generate the key
+        #
+
+        push(@$genlist, $keytype);
+        $count++;
     }
 
     if ($count > 0)
@@ -164,14 +206,17 @@ sub runKeyGen
 {
     my($gen_keys) = @_;
 
-    print "Generating ssh host keys...\n";
-
-    for my $k (@$gen_keys)
+    if (@$gen_keys)
     {
-        $keyfile = $keyfiles->{$k};
+        print "Generating ssh host keys...\n";
 
-        # if $sysconfdir/$keyfile doesn't exist..
-        action("$bindir/ssh-keygen -t $k -f $sysconfdir/$keyfile -N \"\"");
+        for my $k (@$gen_keys)
+        {
+            $keyfile = $keyfiles->{$k};
+
+            # if $sysconfdir/$keyfile doesn't exist..
+            action("$bindir/ssh-keygen -t $k -f $sysconfdir/$keyfile -N \"\"");
+        }
     }
 
     return 0;
@@ -382,7 +427,7 @@ sub action
 
     printf "$command\n";
 
-    my $result = system("$command 2>&1");
+    my $result = system("LD_LIBRARY_PATH=\"$gpath/lib:\$LD_LIBRARY_PATH\"; $command 2>&1");
 
     if (($result or $?) and $command !~ m!patch!)
     {
This page took 0.095635 seconds and 4 git commands to generate.