make the config directory configurable
[freeside.git] / FS / FS / UID.pm
index 21df944..8dd928e 100644 (file)
@@ -10,7 +10,7 @@ use subs qw(
   getsecrets cgisetotaker
 );
 use Exporter;
-use Carp qw(carp croak cluck);
+use Carp qw(carp croak cluck confess);
 use DBI;
 use FS::Conf;
 use FS::CurrentUser;
@@ -21,7 +21,7 @@ use FS::CurrentUser;
 
 $freeside_uid = scalar(getpwnam('freeside'));
 
-$conf_dir = "/usr/local/etc/freeside/";
+$conf_dir = "%%%FREESIDE_CONF%%%/";
 
 $AutoCommit = 1; #ours, not DBI
 
@@ -72,10 +72,16 @@ sub adminsuidsetup {
 
 sub forksuidsetup {
   $user = shift;
-  croak "fatal: adminsuidsetup called without arguements" unless $user;
+  my $olduser = $user;
 
-  $user =~ /^([\w\-\.]+)$/ or croak "fatal: illegal user $user";
-  $user = $1;
+  if ( $FS::CurrentUser::upgrade_hack ) {
+    $user = 'fs_bootstrap';
+  } else {
+    croak "fatal: adminsuidsetup called without arguements" unless $user;
+
+    $user =~ /^([\w\-\.]+)$/ or croak "fatal: illegal user $user";
+    $user = $1;
+  }
 
   $ENV{'PATH'} ='/usr/local/bin:/usr/bin:/usr/ucb:/bin';
   $ENV{'SHELL'} = '/bin/sh';
@@ -86,10 +92,14 @@ sub forksuidsetup {
 
   croak "Not running uid freeside!" unless checkeuid();
 
-  $dbh = &myconnect;
+  if ( $FS::CurrentUser::upgrade_hack && $olduser ) {
+    $dbh = &myconnect($olduser);
+  } else {
+    $dbh = &myconnect();
+  }
 
   use FS::Schema qw(reload_dbdef);
-  reload_dbdef("/usr/local/etc/freeside/dbdef.$datasrc")
+  reload_dbdef("$conf_dir/dbdef.$datasrc")
     unless $FS::Schema::setup_hack;
 
   FS::CurrentUser->load_user($user);
@@ -105,10 +115,10 @@ sub forksuidsetup {
 }
 
 sub myconnect {
-  DBI->connect( getsecrets, { 'AutoCommit'         => 0,
-                              'ChopBlanks'         => 1,
-                              'ShowErrorStatement' => 1,
-                            }
+  DBI->connect( getsecrets(@_), { 'AutoCommit'         => 0,
+                                  'ChopBlanks'         => 1,
+                                  'ShowErrorStatement' => 1,
+                                }
               )
     or die "DBI->connect error: $DBI::errstr\n";
 }
@@ -265,13 +275,20 @@ the `/usr/local/etc/freeside/mapsecrets' file.
 sub getsecrets {
   my($setuser) = shift;
   $user = $setuser if $setuser;
-  die "No user!" unless $user;
   my($conf) = new FS::Conf $conf_dir;
-  my($line) = grep /^\s*($user|\*)\s/, $conf->config('mapsecrets');
-  die "User $user not found in mapsecrets!" unless $line;
-  $line =~ /^\s*($user|\*)\s+(.*)$/;
-  $secrets = $2;
-  die "Illegal mapsecrets line for user?!" unless $secrets;
+
+  if ( $conf->exists('mapsecrets') ) {
+    die "No user!" unless $user;
+    my($line) = grep /^\s*($user|\*)\s/, $conf->config('mapsecrets');
+    confess "User $user not found in mapsecrets!" unless $line;
+    $line =~ /^\s*($user|\*)\s+(.*)$/;
+    $secrets = $2;
+    die "Illegal mapsecrets line for user?!" unless $secrets;
+  } else {
+    # no mapsecrets file at all, so do the default thing
+    $secrets = 'secrets';
+  }
+
   ($datasrc, $db_user, $db_pass) = $conf->config($secrets)
     or die "Can't get secrets: $secrets: $!\n";
   $FS::Conf::default_dir = $conf_dir. "/conf.$datasrc";