Changeset 65 for trunk/DNSDB.pm
- Timestamp:
- 11/25/10 16:26:08 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/DNSDB.pm
r62 r65 16 16 use DBI; 17 17 use Net::DNS; 18 use Crypt::PasswdMD5; 18 19 #use Net::SMTP; 19 20 #use NetAddr::IP qw( Compact ); … … 24 25 @ISA = qw(Exporter); 25 26 @EXPORT_OK = qw( 26 &initGlobals &connectDB &finish 27 &initGlobals &initPermissions &getPermissions 28 &connectDB &finish 27 29 &addDomain &delDomain &domainName 28 30 &addGroup &delGroup &getChildren &groupName … … 32 34 &domStatus &importAXFR 33 35 %typemap %reverse_typemap 36 %permissions 34 37 ); 35 38 36 39 @EXPORT = (); # Export nothing by default. 37 40 %EXPORT_TAGS = ( ALL => [qw( 38 &initGlobals &connectDB &finish 41 &initGlobals &initPermissions &getPermissions 42 &connectDB &finish 39 43 &addDomain &delDomain &domainName 40 44 &addGroup &delGroup &getChildren &groupName … … 44 48 &domStatus &importAXFR 45 49 %typemap %reverse_typemap 50 %permissions 46 51 )] 47 52 ); … … 67 72 our %reverse_typemap; 68 73 74 our %permissions; 69 75 70 76 ## … … 156 162 } 157 163 } # end initGlobals 164 165 166 ## DNSDB::initPermissions() 167 # Set up permissions global 168 # Takes database handle and UID 169 sub initPermissions { 170 my $dbh = shift; 171 my $uid = shift; 172 173 # %permissions = $(getPermissions($dbh,'user',$uid)); 174 getPermissions($dbh, 'user', $uid, \%permissions); 175 176 } # end initPermissions() 177 178 179 ## DNSDB::getPermissions() 180 # Get permissions from DB 181 # Requires DB handle, group or user flag, ID, and hashref. 182 sub getPermissions { 183 my $dbh = shift; 184 my $type = shift; 185 my $id = shift; 186 my $hash = shift; 187 188 my $sql = qq( 189 SELECT 190 p.admin,p.self_edit, 191 p.group_create,p.group_edit,p.group_delete, 192 p.user_create,p.user_edit,p.user_delete, 193 p.domain_create,p.domain_edit,p.domain_delete, 194 p.record_create,p.record_edit,p.record_delete 195 FROM permissions p 196 ); 197 if ($type eq 'group') { 198 $sql .= qq( 199 JOIN groups g ON g.permission_id=p.permission_id 200 WHERE g.group_id=? 201 ); 202 } else { 203 $sql .= qq( 204 JOIN users u ON u.permission_id=p.permission_id 205 WHERE u.user_id=? 206 ); 207 } 208 209 my $sth = $dbh->prepare($sql); 210 211 $sth->execute($id) or die "argh: ".$sth->errstr; 212 213 # my $permref = $sth->fetchrow_hashref; 214 # return $permref; 215 # $hash = $permref; 216 # Eww. Need to learn how to forcibly drop a hashref onto an existing hash. 217 ($hash->{admin},$hash->{self_edit}, 218 $hash->{group_create},$hash->{group_edit},$hash->{group_delete}, 219 $hash->{user_create},$hash->{user_edit},$hash->{user_delete}, 220 $hash->{domain_create},$hash->{domain_edit},$hash->{domain_delete}, 221 $hash->{record_create},$hash->{record_edit},$hash->{record_delete}) 222 = $sth->fetchrow_array; 223 224 } # end getPermissions() 225 226 227 ## DNSDB::changePermissions() 228 # Update an ACL entry 229 # Takes a db handle, type, owner-id, and hashref for the changed permissions. 230 ##fixme: Must handle case of changing object's permissions from inherited to custom 231 sub changePermissions { 232 my $dbh = shift; 233 my $type = shift; 234 my $id = shift; 235 my $newperms = shift; 236 237 # see if we're switching from inherited to custom 238 my $sth = $dbh->prepare("SELECT (u.permission_id=g.permission_id) AS was_inherited". 239 " FROM ".($type eq 'user' ? 'users' : 'groups')." u ". 240 " JOIN groups g ON u.group_id=g.group_id ". 241 " WHERE u.".($type eq 'user' ? 'user' : 'group')."_id=?"); 242 $sth->execute($id); 243 244 } # end changePermissions() 158 245 159 246 … … 507 594 508 595 ##fixme: add another table to hold name/email for log table? 596 die "dying horribly\n"; 509 597 510 598 # once we get here, we should have suceeded.
Note:
See TracChangeset
for help on using the changeset viewer.