5 @ISA @EXPORT_OK $cgi $dbh $freeside_uid $conf $datasrc $db_user $db_pass
13 @EXPORT_OK = qw(checkeuid checkruid swapuid cgisuidsetup
14 adminsuidsetup getotaker dbh datasrc);
16 $freeside_uid = scalar(getpwnam('freeside'));
18 my $conf = new FS::Conf;
19 ($datasrc, $db_user, $db_pass) = $conf->config('secrets')
20 or die "Can't get secrets: $!";
24 FS::UID - Subroutines for database login and assorted other stuff
28 use FS::UID qw(adminsuidsetup cgisuidsetup dbh datasrc getotaker
29 checkeuid checkruid swapuid);
34 $dbh = cgisuidsetup($cgi);
42 Provides a hodgepodge of subroutines.
50 Cleans the environment.
51 Make sure the script is running as freeside, or setuid freeside.
52 Opens a connection to the database.
53 Swaps real and effective UIDs.
54 Returns the DBI database handle (usually you don't need this).
60 $ENV{'PATH'} ='/usr/local/bin:/usr/bin:/usr/ucb:/bin';
61 $ENV{'SHELL'} = '/bin/sh';
62 $ENV{'IFS'} = " \t\n";
65 $ENV{'BASH_ENV'} = '';
67 croak "Not running uid freeside!" unless checkeuid();
68 $dbh = DBI->connect($datasrc,$db_user,$db_pass, {
70 # my($user)=getotaker();
71 # $dbh = DBI->connect("$datasrc:$user",$db_user,$db_pass, {
72 'AutoCommit' => 'true',
73 'ChopBlanks' => 'true',
74 } ) or die "DBI->connect error: $DBI::errstr\n";;
76 swapuid(); #go to non-privledged user if running setuid freeside
81 =item cgisuidsetup CGI_object
83 Stores the CGI (see L<CGI>) object for later use. (CGI::Base is depriciated)
90 if ( $cgi->isa('CGI::Base') ) {
91 carp "Use of CGI::Base is depriciated";
92 } elsif ( ! $cgi->isa('CGI') ) {
93 croak "Pass a CGI object to cgisuidsetup!";
100 Returns the DBI database handle.
110 Returns the DBI data source.
124 croak "suidsetup depriciated";
129 Returns the current Freeside user. Currently that means the CGI REMOTE_USER,
135 if ( $cgi && $cgi->can('var') && defined $cgi->var('REMOTE_USER')) {
136 carp "Use of CGI::Base is depriciated";
137 return $cgi->var('REMOTE_USER'); #for now
138 } elsif ( $cgi && $cgi->can('remote_user') && defined $cgi->remote_user ) {
139 return $cgi->remote_user;
147 Returns true if effective UID is that of the freeside user.
152 ( $> == $freeside_uid );
157 Returns true if the real UID is that of the freeside user.
162 ( $< == $freeside_uid );
167 Swaps real and effective UIDs.
181 No capabilities yet. When mod_perl and Authen::DBI are implemented,
182 cgisuidsetup will go away as well.
186 L<FS::Record>, L<CGI>, L<DBI>
190 ivan@voicenet.com 97-jun-4 - 9
192 untaint otaker ivan@voicenet.com 97-jul-7
194 generalize and auto-get uid (getotaker still needs to be db'ed)
195 ivan@sisd.com 97-nov-10
197 &cgisuidsetup logs into database. other cleaning.
198 ivan@sisd.com 97-nov-22,23
200 &adminsuidsetup logs into database with otaker='freeside' (for
201 automated tasks like billing)
202 ivan@sisd.com 97-dec-13
204 added sub datasrc for fs-setup ivan@sisd.com 98-feb-21
206 datasrc, user and pass now come from conf/secrets ivan@sisd.com 98-jun-28
208 added ChopBlanks to DBI call (see man DBI) ivan@sisd.com 98-aug-16
210 pod, use FS::Conf, implemented cgisuidsetup as adminsuidsetup,
212 ivan@sisd.com 98-sep-12
215 Revision 1.2 1998-11-08 09:38:43 ivan
216 cgisuidsetup complains if you pass it a isa CGI::Base instead of an isa CGI
217 (first step in migrating from CGI-modules to CGI.pm)