Changeset 244 for trunk/DNSDB.pm


Ignore:
Timestamp:
02/24/12 17:59:45 (12 years ago)
Author:
Kris Deugau
Message:

/trunk

Scope check cleanup for rdns, should be complete. Some checks
seem to have been wrong (eg default record delete) and may be
candidates for backporting to a stable release. See #26.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/DNSDB.pm

    r243 r244  
    21182118
    21192119  # Reference hashes.
    2120   my %par_tbl = (
     2120my %par_tbl = (
    21212121                group   => 'groups',
    21222122                user    => 'users',
    21232123                defrec  => 'default_records',
     2124                defrevrec       => 'default_rev_records',
    21242125                domain  => 'domains',
     2126                revzone => 'revzones',
    21252127                record  => 'records'
    21262128        );
    2127   my %id_col = (
     2129my %id_col = (
    21282130                group   => 'group_id',
    21292131                user    => 'user_id',
    21302132                defrec  => 'record_id',
     2133                defrevrec       => 'record_id',
    21312134                domain  => 'domain_id',
     2135                revzone => 'rdns_id',
    21322136                record  => 'record_id'
    21332137        );
    2134   my %par_col = (
     2138my %par_col = (
    21352139                group   => 'parent_group_id',
    21362140                user    => 'group_id',
    21372141                defrec  => 'group_id',
     2142                defrevrec       => 'group_id',
    21382143                domain  => 'group_id',
     2144                revzone => 'group_id',
    21392145                record  => 'domain_id'
    21402146        );
    2141   my %par_type = (
     2147my %par_type = (
    21422148                group   => 'group',
    21432149                user    => 'group',
    21442150                defrec  => 'group',
     2151                defrevrec       => 'group',
    21452152                domain  => 'group',
     2153                revzone => 'group',
    21462154                record  => 'domain'
    21472155        );
     
    22312239
    22322240  # Return false on invalid types
    2233   return 0 if !grep /^$type1$/, ('record','defrec','user','domain','group');
    2234   return 0 if !grep /^$type2$/, ('record','defrec','user','domain','group');
     2241  return 0 if !grep /^$type1$/, ('record','defrec','defrevrec','user','domain','revzone','group');
     2242  return 0 if !grep /^$type2$/, ('record','defrec','defrevrec','user','domain','revzone','group');
    22352243
    22362244  # Return false on impossible relations
    22372245  return 0 if $type1 eq 'record';       # nothing may be a child of a record
    22382246  return 0 if $type1 eq 'defrec';       # nothing may be a child of a record
     2247  return 0 if $type1 eq 'defrevrec';    # nothing may be a child of a record
    22392248  return 0 if $type1 eq 'user';         # nothing may be child of a user
    22402249  return 0 if $type1 eq 'domain' && $type2 ne 'record'; # domain may not be a parent of anything other than a record
     2250  return 0 if $type1 eq 'revzone' && $type2 ne 'record';# reverse zone may not be a parent of anything other than a record
    22412251
    22422252  # ennnhhhh....  if we're passed an id of 0, it will never be found.  usual
    22432253  # case would be the UI creating a new <thing>, and so we don't have an ID for
    22442254  # <thing> to look up yet.  in that case the UI should check the parent as well.
    2245   # argument for returning 1 is
    22462255  return 0 if $id1 == 0;        # nothing can have a parent id of 0
    22472256  return 1 if $id2 == 0;        # anything could have a child id of 0 (or "unknown")
     
    22532262  return 1 if $type1 eq 'group' && $type2 eq 'group' && $id1 == $id2;
    22542263
    2255 # almost the same loop as getParents() above
    22562264  my $id = $id2;
    22572265  my $type = $type2;
    22582266  my $foundparent = 0;
    22592267
     2268  # Records are the only entity with two possible parents.  We need to split the parent checks on
     2269  # domain/rdns.
     2270  if ($type eq 'record') {
     2271    my ($dom,$rdns) = $dbh->selectrow_array("SELECT domain_id,rdns_id FROM records WHERE record_id=?",
     2272        undef, ($id));
     2273    # check immediate parent against request
     2274    return 1 if $type1 eq 'domain' && $id1 == $dom;
     2275    return 1 if $type1 eq 'revzone' && $id1 == $rdns;
     2276    # if request is group, check *both* parents.  Only check if the parent is nonzero though.
     2277    return 1 if $dom && isParent($dbh, $id1, $type1, $dom, 'domain');
     2278    return 1 if $rdns && isParent($dbh, $id1, $type1, $rdns, 'revzone');
     2279    # exit here since we've executed the loop below by proxy in the above recursive calls.
     2280    return 0;
     2281  }
     2282
     2283# almost the same loop as getParents() above
    22602284  my $limiter = 0;
    22612285  while (1) {
     
    22652289    if (!$result) {
    22662290      $limiter++;
    2267 ##fixme:  how often will this happen on a live site?
     2291##fixme:  how often will this happen on a live site?  fail at max limiter <n>?
    22682292      warn "no results looking for $sql with id $id (depth $limiter)\n";
    22692293      last;
     
    22742298    } else {
    22752299##fixme: do we care about trying to return a "no such record/domain/user/group" error?
     2300# should be impossible to create an inconsistent DB just with API calls.
    22762301      warn $dbh->errstr." $sql, $id" if $dbh->errstr;
    22772302    }
Note: See TracChangeset for help on using the changeset viewer.