[padb-devel] [padb] r280 committed - Add a --create-secret-file option to automatically generate a secret f...

codesite-noreply at google.com codesite-noreply at google.com
Thu Oct 8 11:49:20 BST 2009


Revision: 280
Author: apittman
Date: Thu Oct  8 03:48:22 2009
Log: Add a --create-secret-file option to automatically generate a secret  
file.

Also change the code to read them to accept digits and full stops
as well as just letters (replace \w+ with [\w\d\.]+).

http://code.google.com/p/padb/source/detail?r=280

Modified:
  /trunk/src/padb

=======================================
--- /trunk/src/padb	Wed Oct  7 12:59:15 2009
+++ /trunk/src/padb	Thu Oct  8 03:48:22 2009
@@ -695,6 +695,7 @@
  my $full_report;
  my $core_stack;
  my $list_rmgrs;
+my $create_secret;
  my $watch;
  my $local_stats;
  my $show_jobs;
@@ -821,6 +822,7 @@
          'norc'                => \$norc,
          'config-file=s'       => \$configfile,
          'debug=s'             => \$debugflag,
+        'create-secret-file'  => \$create_secret,
      );

      # The primary modes, one of these only must be set.
@@ -4352,6 +4354,24 @@

      return 0;
  }
+
+sub create_padb_secret {
+    my $filename = "$ENV{HOME}/.padb-secret";
+    my $FD;
+    if ( not open $FD, '>', $filename ) {
+        printf("Failed to create secret file: $!\n");
+        return;
+    }
+    if ( chmod( 0600, $FD ) != 1 ) {
+        printf("Failed to chmod secret file: $!\n");
+        return;
+    }
+    my $s = rand;
+    print {$FD} "secret=$s\n";
+    close $FD;
+    print("Sucessfully created secret file ($filename)\n");
+    return;
+}

  sub find_padb_secret {

@@ -4375,9 +4395,11 @@
      if ( $#l != 0 ) {
          return;
      }
-    if ( $l[0] =~ m{\Asecret=(\w+)\Z}x ) {
+    if ( $l[0] =~ m{\Asecret=([\w\d\.]+)\Z}x ) {
          return $1;
      }
+    print "Failed to load secret from file ($file)\n";
+    exit 1;
  }

  sub go_job {
@@ -4394,6 +4416,7 @@

          if ( not defined $secret ) {
              print "Error: Could not load secret file on this node\n";
+            print "Use --create-secret-file to create one\n";
              exit 1;
          }

@@ -4659,6 +4682,11 @@

      debug_log( 'config', \%conf, 'Finished setting configuration options'  
);

+    if ($create_secret) {
+        create_padb_secret();
+        exit 0;
+    }
+
      if ($list_rmgrs) {
          foreach my $res ( sort keys %rmgr ) {
              my $working = 'yes';




More information about the padb-devel mailing list