5 @ISA @EXPORT_OK $cgi $dbh $freeside_uid $user
6 $conf_dir $secrets $datasrc $db_user $db_pass %callback
9 getsecrets cgisetotaker
17 @EXPORT_OK = qw(checkeuid checkruid swapuid cgisuidsetup
18 adminsuidsetup getotaker dbh datasrc getsecrets );
20 $freeside_uid = scalar(getpwnam('freeside'));
22 $conf_dir = "/usr/local/etc/freeside/";
26 FS::UID - Subroutines for database login and assorted other stuff
30 use FS::UID qw(adminsuidsetup cgisuidsetup dbh datasrc getotaker
31 checkeuid checkruid swapuid);
36 $dbh = cgisuidsetup($cgi);
44 Provides a hodgepodge of subroutines.
50 =item adminsuidsetup USER
52 Sets the user to USER (see config.html from the base documentation).
53 Cleans the environment.
54 Make sure the script is running as freeside, or setuid freeside.
55 Opens a connection to the database.
56 Swaps real and effective UIDs.
57 Runs any defined callbacks (see below).
58 Returns the DBI database handle (usually you don't need this).
65 croak "fatal: adminsuidsetup called without arguements" unless $user;
67 $ENV{'PATH'} ='/usr/local/bin:/usr/bin:/usr/ucb:/bin';
68 $ENV{'SHELL'} = '/bin/sh';
69 $ENV{'IFS'} = " \t\n";
72 $ENV{'BASH_ENV'} = '';
74 croak "Not running uid freeside!" unless checkeuid();
76 $dbh = DBI->connect($datasrc,$db_user,$db_pass, {
77 'AutoCommit' => 'true',
78 'ChopBlanks' => 'true',
79 } ) or die "DBI->connect error: $DBI::errstr\n";
81 swapuid(); #go to non-privledged user if running setuid freeside
83 foreach ( keys %callback ) {
90 =item cgisuidsetup CGI_object
92 Stores the CGI (see L<CGI>) object for later use. (CGI::Base is depriciated)
99 if ( $cgi->isa('CGI::Base') ) {
100 carp "Use of CGI::Base is depriciated";
101 } elsif ( $cgi->isa('Apache') ) {
103 } elsif ( ! $cgi->isa('CGI') ) {
104 croak "fatal: unrecognized object $cgi";
107 adminsuidsetup($user);
112 Returns the CGI (see L<CGI>) object.
117 carp "warning: \$FS::UID::cgi isa Apache" if $cgi->isa('Apache');
123 Returns the DBI database handle.
133 Returns the DBI data source.
147 croak "suidsetup depriciated";
152 Returns the current Freeside user.
162 Sets and returns the CGI REMOTE_USER. $cgi should be defined as a CGI.pm
163 object. Support for CGI::Base and derived classes is depriciated.
168 if ( $cgi && $cgi->isa('CGI::Base') && defined $cgi->var('REMOTE_USER')) {
169 carp "Use of CGI::Base is depriciated";
170 $user = lc ( $cgi->var('REMOTE_USER') );
171 } elsif ( $cgi && $cgi->isa('CGI') && defined $cgi->remote_user ) {
172 $user = lc ( $cgi->remote_user );
173 } elsif ( $cgi && $cgi->isa('Apache') ) {
174 $user = lc ( $cgi->connection->user );
176 die "fatal: Can't get REMOTE_USER! for cgi $cgi";
183 Returns true if effective UID is that of the freeside user.
188 ( $> == $freeside_uid );
193 Returns true if the real UID is that of the freeside user.
198 ( $< == $freeside_uid );
203 Swaps real and effective UIDs.
208 ($<,$>) = ($>,$<) if $< != $>;
211 =item getsecrets [ USER ]
213 Sets the user to USER, if supplied.
214 Sets and returns the DBI datasource, username and password for this user from
215 the `/usr/local/etc/freeside/mapsecrets' file.
220 my($setuser) = shift;
221 $user = $setuser if $setuser;
222 die "No user!" unless $user;
223 my($conf) = new FS::Conf $conf_dir;
224 my($line) = grep /^\s*$user\s/, $conf->config('mapsecrets');
225 die "User not found in mapsecrets!" unless $line;
226 $line =~ /^\s*$user\s+(.*)$/;
228 die "Illegal mapsecrets line for user?!" unless $secrets;
229 ($datasrc, $db_user, $db_pass) = $conf->config($secrets)
230 or die "Can't get secrets: $!";
231 $FS::Conf::default_dir = $conf_dir. "/conf.$datasrc";
232 ($datasrc, $db_user, $db_pass);
239 Warning: this interface is likely to change in future releases.
241 A package can install a callback to be run in adminsuidsetup by putting a
242 coderef into the hash %FS::UID::callback :
244 $coderef = sub { warn "Hi, I'm returning your call!" };
245 $FS::UID::callback{'Package::Name'};
249 $Id: UID.pm,v 1.2 2000-05-13 21:50:12 ivan Exp $
253 Too many package-global variables.
257 No capabilities yet. When mod_perl and Authen::DBI are implemented,
258 cgisuidsetup will go away as well.
260 Goes through contortions to support non-OO syntax with multiple datasrc's.
262 Callbacks are inelegant.
266 L<FS::Record>, L<CGI>, L<DBI>, config.html from the base documentation.