5 @ISA @EXPORT_OK $cgi $dbh $freeside_uid $user
6 $conf_dir $secrets $datasrc $db_user $db_pass %callback $driver_name
10 getsecrets cgisetotaker
13 use Carp qw(carp croak cluck);
18 @EXPORT_OK = qw(checkeuid checkruid cgisuidsetup adminsuidsetup forksuidsetup
19 getotaker dbh datasrc getsecrets driver_name );
21 $freeside_uid = scalar(getpwnam('freeside'));
23 $conf_dir = "/usr/local/etc/freeside/";
25 $AutoCommit = 1; #ours, not DBI
29 FS::UID - Subroutines for database login and assorted other stuff
33 use FS::UID qw(adminsuidsetup cgisuidsetup dbh datasrc getotaker
39 $dbh = cgisuidsetup($cgi);
45 $driver_name = driver_name;
49 Provides a hodgepodge of subroutines.
55 =item adminsuidsetup USER
57 Sets the user to USER (see config.html from the base documentation).
58 Cleans the environment.
59 Make sure the script is running as freeside, or setuid freeside.
60 Opens a connection to the database.
61 Swaps real and effective UIDs.
62 Runs any defined callbacks (see below).
63 Returns the DBI database handle (usually you don't need this).
68 $dbh->disconnect if $dbh;
74 croak "fatal: adminsuidsetup called without arguements" unless $user;
76 $user =~ /^([\w\-\.]+)$/ or croak "fatal: illegal user $user";
79 $ENV{'PATH'} ='/usr/local/bin:/usr/bin:/usr/ucb:/bin';
80 $ENV{'SHELL'} = '/bin/sh';
81 $ENV{'IFS'} = " \t\n";
84 $ENV{'BASH_ENV'} = '';
86 croak "Not running uid freeside!" unless checkeuid();
88 $dbh = DBI->connect($datasrc,$db_user,$db_pass, {
91 } ) or die "DBI->connect error: $DBI::errstr\n";
93 foreach ( keys %callback ) {
100 =item cgisuidsetup CGI_object
102 Takes a single argument, which is a CGI (see L<CGI>) or Apache (see L<Apache>)
103 object (CGI::Base is depriciated). Runs cgisetotaker and then adminsuidsetup.
109 if ( $cgi->isa('CGI::Base') ) {
110 carp "Use of CGI::Base is depriciated";
111 } elsif ( $cgi->isa('Apache') ) {
113 } elsif ( ! $cgi->isa('CGI') ) {
114 croak "fatal: unrecognized object $cgi";
117 adminsuidsetup($user);
122 Returns the CGI (see L<CGI>) object.
127 carp "warning: \$FS::UID::cgi isa Apache" if $cgi->isa('Apache');
133 Returns the DBI database handle.
143 Returns the DBI data source.
153 Returns just the driver name portion of the DBI data source.
158 return $driver_name if defined $driver_name;
159 $driver_name = ( split(':', $datasrc) )[1];
163 croak "suidsetup depriciated";
168 Returns the current Freeside user.
178 Sets and returns the CGI REMOTE_USER. $cgi should be defined as a CGI.pm
179 object (see L<CGI>) or an Apache object (see L<Apache>). Support for CGI::Base
180 and derived classes is depriciated.
185 if ( $cgi && $cgi->isa('CGI::Base') && defined $cgi->var('REMOTE_USER')) {
186 carp "Use of CGI::Base is depriciated";
187 $user = lc ( $cgi->var('REMOTE_USER') );
188 } elsif ( $cgi && $cgi->isa('CGI') && defined $cgi->remote_user ) {
189 $user = lc ( $cgi->remote_user );
190 } elsif ( $cgi && $cgi->isa('Apache') ) {
191 $user = lc ( $cgi->connection->user );
193 die "fatal: Can't get REMOTE_USER! for cgi $cgi - you need to setup ".
194 "Apache user authentication as documented in httemplate/docs/install.html";
201 Returns true if effective UID is that of the freeside user.
206 ( $> == $freeside_uid );
211 Returns true if the real UID is that of the freeside user.
216 ( $< == $freeside_uid );
219 =item getsecrets [ USER ]
221 Sets the user to USER, if supplied.
222 Sets and returns the DBI datasource, username and password for this user from
223 the `/usr/local/etc/freeside/mapsecrets' file.
228 my($setuser) = shift;
229 $user = $setuser if $setuser;
230 die "No user!" unless $user;
231 my($conf) = new FS::Conf $conf_dir;
232 my($line) = grep /^\s*$user\s/, $conf->config('mapsecrets');
233 die "User $user not found in mapsecrets!" unless $line;
234 $line =~ /^\s*$user\s+(.*)$/;
236 die "Illegal mapsecrets line for user?!" unless $secrets;
237 ($datasrc, $db_user, $db_pass) = $conf->config($secrets)
238 or die "Can't get secrets: $!";
239 $FS::Conf::default_dir = $conf_dir. "/conf.$datasrc";
241 ($datasrc, $db_user, $db_pass);
248 Warning: this interface is likely to change in future releases.
250 A package can install a callback to be run in adminsuidsetup by putting a
251 coderef into the hash %FS::UID::callback :
253 $coderef = sub { warn "Hi, I'm returning your call!" };
254 $FS::UID::callback{'Package::Name'};
258 $Id: UID.pm,v 1.14 2002-02-23 07:00:21 ivan Exp $
262 Too many package-global variables.
266 No capabilities yet. When mod_perl and Authen::DBI are implemented,
267 cgisuidsetup will go away as well.
269 Goes through contortions to support non-OO syntax with multiple datasrc's.
271 Callbacks are inelegant.
275 L<FS::Record>, L<CGI>, L<DBI>, config.html from the base documentation.