line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Gantry::Control; |
2
|
3
|
|
|
3
|
|
17
|
use strict; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
116
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
require Exporter; |
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
1222
|
use Gantry::Utils::DB; |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
329
|
|
7
|
3
|
|
|
3
|
|
1619
|
use Gantry::Utils::SQL; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
104
|
|
8
|
3
|
|
|
3
|
|
1148
|
use Gantry::Utils::Validate; |
|
3
|
|
|
|
|
10
|
|
|
3
|
|
|
|
|
97
|
|
9
|
|
|
|
|
|
|
|
10
|
3
|
|
|
3
|
|
18
|
use vars qw( @ISA @EXPORT ); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
2297
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
############################################################ |
13
|
|
|
|
|
|
|
# Variables # |
14
|
|
|
|
|
|
|
############################################################ |
15
|
|
|
|
|
|
|
@ISA = qw( Exporter ); |
16
|
|
|
|
|
|
|
@EXPORT = qw( dec2bin |
17
|
|
|
|
|
|
|
encrypt |
18
|
|
|
|
|
|
|
get_grnam |
19
|
|
|
|
|
|
|
get_grgid |
20
|
|
|
|
|
|
|
get_pwnam |
21
|
|
|
|
|
|
|
get_pwuid |
22
|
|
|
|
|
|
|
get_usrgrp ); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
############################################################ |
25
|
|
|
|
|
|
|
# Functions # |
26
|
|
|
|
|
|
|
############################################################ |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
#------------------------------------------------- |
29
|
|
|
|
|
|
|
# dec2bin( $bits ) |
30
|
|
|
|
|
|
|
#------------------------------------------------- |
31
|
|
|
|
|
|
|
sub dec2bin { |
32
|
0
|
|
|
0
|
1
|
|
my $bits = shift; |
33
|
|
|
|
|
|
|
|
34
|
0
|
0
|
|
|
|
|
return( 0, 0, 0 ) if ( ! $bits ); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# Is there a nicer way to do this ? |
37
|
0
|
|
|
|
|
|
return( ( split( '', unpack( 'B32', pack( 'N', $bits ) ) ) )[-3..-1] ); |
38
|
|
|
|
|
|
|
} # END dec2bin |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
#------------------------------------------------- |
41
|
|
|
|
|
|
|
# encrypt( $string ) |
42
|
|
|
|
|
|
|
#------------------------------------------------- |
43
|
|
|
|
|
|
|
sub encrypt { |
44
|
0
|
|
|
0
|
1
|
|
my $str = shift; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# Emulates unix crypt(3) |
47
|
0
|
|
|
|
|
|
my @chars = ( '.', '/', 0..9, 'A'..'Z', 'a'..'z' )[ rand 64, rand 64 ]; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
return( crypt( $str, join( '', @chars ) ) ); |
50
|
|
|
|
|
|
|
} # END encrypt |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
#------------------------------------------------- |
53
|
|
|
|
|
|
|
# get_grnam( $dbh, $group_name ) |
54
|
|
|
|
|
|
|
#------------------------------------------------- |
55
|
|
|
|
|
|
|
sub get_grnam { |
56
|
0
|
|
|
0
|
1
|
|
my ( $dbh, $name ) = @_; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# act like C's getgrnam |
59
|
0
|
|
|
|
|
|
my $sth = db_query( $dbh, 'get a groups id', |
60
|
|
|
|
|
|
|
'SELECT id FROM auth_groups WHERE name = ', |
61
|
|
|
|
|
|
|
sql_str( $name ) ); |
62
|
|
|
|
|
|
|
|
63
|
0
|
|
|
|
|
|
my $gid = db_next( $sth ); |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
db_finish( $sth ); |
66
|
|
|
|
|
|
|
|
67
|
0
|
0
|
|
|
|
|
$gid = 0 if ( ! $gid ); |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
return( $gid ); |
70
|
|
|
|
|
|
|
} # END get_grnam |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
#------------------------------------------------- |
73
|
|
|
|
|
|
|
# get_grgid( $dbh, $gid ) |
74
|
|
|
|
|
|
|
#------------------------------------------------- |
75
|
|
|
|
|
|
|
sub get_grgid { |
76
|
0
|
|
|
0
|
1
|
|
my ( $dbh, $gid ) = @_; |
77
|
|
|
|
|
|
|
|
78
|
0
|
0
|
|
|
|
|
$gid = 0 if ( ! $gid ); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# act like C's getgrgid |
81
|
0
|
|
|
|
|
|
my $sth = db_query( $dbh, 'get a groups name', |
82
|
|
|
|
|
|
|
'SELECT name FROM auth_groups WHERE id = ', |
83
|
|
|
|
|
|
|
sql_num( $gid ) ); |
84
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
my $gname = db_next( $sth ); |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
db_finish( $sth ); |
88
|
|
|
|
|
|
|
|
89
|
0
|
0
|
|
|
|
|
$gname = '' if ( ! $gname ); |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
return( $gid ); |
92
|
|
|
|
|
|
|
} # END get_grgid |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
#------------------------------------------------- |
95
|
|
|
|
|
|
|
# get_pwnam( $dbh, $name ) |
96
|
|
|
|
|
|
|
#------------------------------------------------- |
97
|
|
|
|
|
|
|
sub get_pwnam { |
98
|
0
|
|
|
0
|
1
|
|
my ( $dbh, $name ) = @_; |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
my $sth = db_query( $dbh, 'Get users info', |
101
|
|
|
|
|
|
|
'SELECT id, password, first_name, last_name, email, ', |
102
|
|
|
|
|
|
|
'active FROM auth_users WHERE user_name = ', |
103
|
|
|
|
|
|
|
sql_str( $name ) ); |
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
my ( $id, $passwd, $first, $last, $email, $active ) = db_next( $sth ); |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
db_finish( $sth ); |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
# act like C's getpwuid |
110
|
0
|
|
0
|
|
|
|
return( $id || 0, $active || 0, $passwd || '', $first || '', |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
111
|
|
|
|
|
|
|
$last || '', $email || '' ); |
112
|
|
|
|
|
|
|
} # END get_pwnam |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
#------------------------------------------------- |
115
|
|
|
|
|
|
|
# get_pwuid( $dbh, $uid ) |
116
|
|
|
|
|
|
|
#------------------------------------------------- |
117
|
|
|
|
|
|
|
sub get_pwuid { |
118
|
0
|
|
|
0
|
1
|
|
my ( $dbh, $uid ) = @_; |
119
|
|
|
|
|
|
|
|
120
|
0
|
0
|
|
|
|
|
$uid = 0 if ( ! $uid ); |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
my $sth = db_query( $dbh, 'Get users info', |
123
|
|
|
|
|
|
|
'SELECT user_name, password, first_name, last_name, ', |
124
|
|
|
|
|
|
|
'email, active FROM auth_users WHERE id = ', |
125
|
|
|
|
|
|
|
sql_num( $uid ) ); |
126
|
|
|
|
|
|
|
|
127
|
0
|
|
|
|
|
|
my ( $uname, $passwd, $first, $last, $email, $active ) = db_next( $sth ); |
128
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
db_finish( $sth ); |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# act like C's getpwuid |
132
|
0
|
|
0
|
|
|
|
return( $uname || '', $active || 0, $passwd || '', $first || '', |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
133
|
|
|
|
|
|
|
$last || '', $email || '' ); |
134
|
|
|
|
|
|
|
} # END get_pwuid |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
#------------------------------------------------- |
137
|
|
|
|
|
|
|
# get_usrgrp( $dbh, $uid ) |
138
|
|
|
|
|
|
|
#------------------------------------------------- |
139
|
|
|
|
|
|
|
sub get_usrgrp { |
140
|
0
|
|
|
0
|
1
|
|
my ( $dbh, $uid ) = @_; |
141
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
my %grp; |
143
|
|
|
|
|
|
|
|
144
|
0
|
0
|
|
|
|
|
$uid = 0 if ( ! $uid ); |
145
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
my $sth = db_query( $dbh, 'get groups user is in', |
147
|
|
|
|
|
|
|
'SELECT auth_groups.id, auth_groups.name FROM ', |
148
|
|
|
|
|
|
|
'auth_groups, auth_group_members WHERE ', |
149
|
|
|
|
|
|
|
'auth_groups.id = auth_group_members.group_id AND ', |
150
|
|
|
|
|
|
|
'auth_group_members.user_id = ', sql_num( $uid ) ); |
151
|
|
|
|
|
|
|
|
152
|
0
|
|
|
|
|
|
while ( my ( $gid, $gname ) = db_next( $sth ) ) { |
153
|
0
|
|
|
|
|
|
$grp{$gid} = $gname; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
0
|
|
|
|
|
|
db_finish( $sth ); |
157
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
|
return( \%grp ); # Gets all of a users groups as a hash reference. |
159
|
|
|
|
|
|
|
} # END get_usrgrp |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
# EOF |
162
|
|
|
|
|
|
|
1; |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
__END__ |