[Camps-users] RFC: fix mysql password regeneration issue when calling refresh-camp --db

David Christensen david at endpoint.com
Fri Apr 3 02:32:39 UTC 2009


Campers,

Enclosing this patch for discussion before committing upstream.   
Comments/suggestions appreciated.

Regards,

David
----
commit 2edde0304c5d9425e30b734b0ca034e377397dab
Author: David Christensen <david at endpoint.com>
Date:   Thu Apr 2 21:27:35 2009 -0500

     Fixed mysql password regeneration issue when calling refresh-camp  
--db

     Specificaly, added role_password_cache method to return a list of
     previously-used passwords for all roles.  This returns an empty  
hash
     in the case of pg (i.e., existing behavior), and returns the  
contents
     of an existing mysql.yml's users hashref, if one exists.

diff --git a/lib/Camp/Master.pm b/lib/Camp/Master.pm
index 80cba2a..8f347dd 100644
--- a/lib/Camp/Master.pm
+++ b/lib/Camp/Master.pm
@@ -1906,8 +1906,9 @@ sub role_sql {

  sub parse_roles {
      $roles = {};
+    my $password_cache = role_password_cache();
      my $path = roles_path();
-    opendir(my $DIR, roles_path()) or die "Failed to open roles path  
'$path': $!\n";
+    opendir(my $DIR, $path) or die "Failed to open roles path  
'$path': $!\n";
      local $/;
      for my $role (grep /^\w+$/, readdir($DIR)) {
          open(my $ROLE, '<', File::Spec->catfile($path, $role))
@@ -1916,6 +1917,10 @@ sub parse_roles {
              role    => $role,
              sql     => <$ROLE>,
          };
+
+        if (my $pw = $password_cache->{$role}) {
+            $roles->{$role}->{password} = $pw;
+        }
          close $ROLE or die "Error closing $path: $!\n";
      }
      closedir($DIR);
@@ -1987,6 +1992,25 @@ sub _database_running_check_mysql {
      return 1;
  }

+sub role_password_cache {
+    return _camp_db_type_dispatcher( 'role_password_cache' )->( @_ );
+}
+
+sub role_password_cache_pg {
+    return {};
+}
+
+sub role_password_cache_mysql {
+    my %opt = @_;
+    my $conf = $opt{config} || config_hash();
+    my $path = camp_mysql_settings_file($conf);
+
+    return {} unless -f $path;
+
+    my $settings = parse_yaml( $path );
+    return $settings->{users} || {};
+}
+
  sub camp_mysql_settings_file {
      my $conf = shift;
      return File::Spec->catfile( $conf->{path}, 'mysql.yml' );



More information about the Camps-users mailing list