X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FUID.pm;h=065db61c1e076d43b98c05fde98dd455fa75de34;hb=eb4ff7f73c5d4bdf74a3472448b5a195598ff4cd;hp=1f51ca69c28309771754753a5c44951d1ae16c17;hpb=9bc0e873966642f415795525f8a2a57381afb080;p=freeside.git diff --git a/FS/FS/UID.pm b/FS/FS/UID.pm index 1f51ca69c..065db61c1 100644 --- a/FS/FS/UID.pm +++ b/FS/FS/UID.pm @@ -4,26 +4,29 @@ use strict; use vars qw( @ISA @EXPORT_OK $cgi $dbh $freeside_uid $user $conf_dir $secrets $datasrc $db_user $db_pass %callback @callback - $driver_name $AutoCommit + $driver_name $AutoCommit $callback_hack $use_confcompat ); 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 IO::File; use FS::CurrentUser; @ISA = qw(Exporter); @EXPORT_OK = qw(checkeuid checkruid cgisuidsetup adminsuidsetup forksuidsetup - getotaker dbh datasrc getsecrets driver_name myconnect ); + getotaker dbh datasrc getsecrets driver_name myconnect + use_confcompat); $freeside_uid = scalar(getpwnam('freeside')); -$conf_dir = "/usr/local/etc/freeside/"; +$conf_dir = "%%%FREESIDE_CONF%%%"; $AutoCommit = 1; #ours, not DBI +$use_confcompat = 1; +$callback_hack = 0; =head1 NAME @@ -72,9 +75,10 @@ sub adminsuidsetup { sub forksuidsetup { $user = shift; + my $olduser = $user; if ( $FS::CurrentUser::upgrade_hack ) { - $user = ''; + $user = 'fs_bootstrap'; } else { croak "fatal: adminsuidsetup called without arguements" unless $user; @@ -91,29 +95,47 @@ 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); - foreach ( keys %callback ) { - &{$callback{$_}}; - # breaks multi-database installs # delete $callback{$_}; #run once + if ($dbh && ! $callback_hack) { + my $sth = $dbh->prepare("SELECT COUNT(*) FROM conf") or die $dbh->errstr; + $sth->execute or die $sth->errstr; + my $confcount = $sth->fetchrow_arrayref->[0]; + + if ($confcount) { + $use_confcompat = 0; + }else{ + warn "NO CONFIGURATION RECORDS FOUND"; + } } - &{$_} foreach @callback; + unless($callback_hack) { + foreach ( keys %callback ) { + &{$callback{$_}}; + # breaks multi-database installs # delete $callback{$_}; #run once + } + + &{$_} foreach @callback; + } $dbh; } 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"; } @@ -270,12 +292,12 @@ the `/usr/local/etc/freeside/mapsecrets' file. sub getsecrets { my($setuser) = shift; $user = $setuser if $setuser; - my($conf) = new FS::Conf $conf_dir; - if ( $conf->exists('mapsecrets') ) { + if ( -e "$conf_dir/mapsecrets" ) { die "No user!" unless $user; - my($line) = grep /^\s*($user|\*)\s/, $conf->config('mapsecrets'); - die "User $user not found in mapsecrets!" unless $line; + my($line) = grep /^\s*($user|\*)\s/, + map { /^(.*)$/; $1 } readline(new IO::File "$conf_dir/mapsecrets"); + confess "User $user not found in mapsecrets!" unless $line; $line =~ /^\s*($user|\*)\s+(.*)$/; $secrets = $2; die "Illegal mapsecrets line for user?!" unless $secrets; @@ -284,13 +306,23 @@ sub getsecrets { $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"; + ($datasrc, $db_user, $db_pass) = + map { /^(.*)$/; $1 } readline(new IO::File "$conf_dir/$secrets") + or die "Can't get secrets: $conf_dir/$secrets: $!\n"; undef $driver_name; ($datasrc, $db_user, $db_pass); } +=item use_confcompat + +Returns true whenever we should use 1.7 configuration compatibility. + +=cut + +sub use_confcompat { + $use_confcompat; +} + =back =head1 CALLBACKS