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);
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('CGI') ) {
102 croak "Pass a CGI object to cgisuidsetup!";
105 adminsuidsetup($user);
110 Returns the CGI (see L<CGI>) object.
120 Returns the DBI database handle.
130 Returns the DBI data source.
144 croak "suidsetup depriciated";
149 Returns the current Freeside user.
159 Sets and returns the CGI REMOTE_USER. $cgi should be defined as a CGI.pm
160 object. Support for CGI::Base and derived classes is depriciated.
165 if ( $cgi && $cgi->isa('CGI::Base') && defined $cgi->var('REMOTE_USER')) {
166 carp "Use of CGI::Base is depriciated";
167 $user = $cgi->var('REMOTE_USER');
168 } elsif ( $cgi && $cgi->isa('CGI') && defined $cgi->remote_user ) {
169 $user = $cgi->remote_user;
171 die "fatal: Can't get REMOTE_USER!";
178 Returns true if effective UID is that of the freeside user.
183 ( $> == $freeside_uid );
188 Returns true if the real UID is that of the freeside user.
193 ( $< == $freeside_uid );
198 Swaps real and effective UIDs.
206 =item getsecrets [ USER ]
208 Sets the user to USER, if supplied.
209 Sets and returns the DBI datasource, username and password for this user from
210 the `/usr/local/etc/freeside/mapsecrets' file.
215 my($setuser) = shift;
216 $user = $setuser if $setuser;
217 die "No user!" unless $user;
218 my($conf) = new FS::Conf $conf_dir;
219 my($line) = grep /^\s*$user\s/, $conf->config('mapsecrets');
220 die "User not found in mapsecrets!" unless $line;
221 $line =~ /^\s*$user\s+(.*)$/;
223 die "Illegal mapsecrets line for user?!" unless $secrets;
224 ($datasrc, $db_user, $db_pass) = $conf->config($secrets)
225 or die "Can't get secrets: $!";
226 $FS::Conf::default_dir = $conf_dir. "/conf.$datasrc";
227 ($datasrc, $db_user, $db_pass);
234 Warning: this interface is likely to change in future releases.
236 A package can install a callback to be run in adminsuidsetup by putting a
237 coderef into the hash %FS::UID::callback :
239 $coderef = sub { warn "Hi, I'm returning your call!" };
240 $FS::UID::callback{'Package::Name'};
244 $Id: UID.pm,v 1.6 1998-11-15 05:27:48 ivan Exp $
248 Too many package-global variables.
252 No capabilities yet. When mod_perl and Authen::DBI are implemented,
253 cgisuidsetup will go away as well.
255 Goes through contortions to support non-OO syntax with multiple datasrc's.
257 Callbacks are inelegant.
261 L<FS::Record>, L<CGI>, L<DBI>, config.html from the base documentation.
265 ivan@voicenet.com 97-jun-4 - 9
267 untaint otaker ivan@voicenet.com 97-jul-7
269 generalize and auto-get uid (getotaker still needs to be db'ed)
270 ivan@sisd.com 97-nov-10
272 &cgisuidsetup logs into database. other cleaning.
273 ivan@sisd.com 97-nov-22,23
275 &adminsuidsetup logs into database with otaker='freeside' (for
276 automated tasks like billing)
277 ivan@sisd.com 97-dec-13
279 added sub datasrc for fs-setup ivan@sisd.com 98-feb-21
281 datasrc, user and pass now come from conf/secrets ivan@sisd.com 98-jun-28
283 added ChopBlanks to DBI call (see man DBI) ivan@sisd.com 98-aug-16
285 pod, use FS::Conf, implemented cgisuidsetup as adminsuidsetup,
287 ivan@sisd.com 98-sep-12
290 Revision 1.6 1998-11-15 05:27:48 ivan
291 bugfix for new configuration layout
293 Revision 1.5 1998/11/15 00:51:51 ivan
294 eliminated some warnings on certain fatal errors (well, it is less confusing)
296 Revision 1.4 1998/11/13 09:56:52 ivan
297 change configuration file layout to support multiple distinct databases (with
298 own set of config files, export, etc.)
300 Revision 1.3 1998/11/08 10:45:42 ivan
301 got sub cgi for FS::CGI
303 Revision 1.2 1998/11/08 09:38:43 ivan
304 cgisuidsetup complains if you pass it a isa CGI::Base instead of an isa CGI
305 (first step in migrating from CGI-modules to CGI.pm)