Changeset 155 for trunk/dns.cgi


Ignore:
Timestamp:
10/26/11 18:10:09 (13 years ago)
Author:
Kris Deugau
Message:

/trunk

Tweak DNSDB::isParent slightly; treat all groups as being their own parent
Remove stale $offset fiddling in page -> bulkdomain
Add error-reporting TMPL_IF on record data page
Continued scope-checking changes:

  • rearrange group-changing check a little to allow propagating the error message without hardcoding it twice
  • handle the special case of group-change while on the default record list page
  • new sub, check_scope, to do the real checking
  • use new sub checking access to individual records (both record and parent domain/group)
  • check target for bulk domain move, as well as source domains in bulkchange
  • check AXFR target group
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/dns.cgi

    r154 r155  
    207207
    208208    # security check - does the user have permission to view this entity?
     209    my $errmsg;
    209210    if (!(grep /^$webvar{group}$/, @viewablegroups)) {
    210211      # hmm.  Reset the current group to the login group?  Yes.  Prevents confusing behaviour elsewhere.
     
    212213      $webvar{group} = $logingroup;
    213214      $curgroup = $logingroup;
    214       $page->param(errmsg => "You are not permitted to view or make changes in the requested group");
     215      $errmsg = "You are not permitted to view or make changes in the requested group";
     216      $page->param(errmsg => $errmsg);
    215217    }
    216218
    217219    $session->param('curgroup', $webvar{group});
    218220    $curgroup = ($webvar{group} ? $webvar{group} : $session->param('curgroup'));
     221
     222    # I hate special cases.
     223    if ($webvar{page} eq 'reclist' && $webvar{defrec} eq 'y') {
     224      my %args = (page => $webvar{page}, id => $curgroup, defrec => $webvar{defrec});
     225      $args{errmsg} = $errmsg if $errmsg;
     226      changepage(%args);
     227    }
     228
    219229  }
    220230} # handle global webvar{action}s
     
    390400
    391401} elsif ($webvar{page} eq 'record') {
     402
     403  # security check - does the user have permission to access this entity?
     404  if (!check_scope($webvar{id}, ($webvar{defrec} eq 'y' ? 'defrec' : 'record'))) {
     405    $page->param(perm_err => "You are not permitted to add or edit the requested record");
     406    goto DONEREC;
     407  }
     408  # round 2, check the parent.
     409  if (!check_scope($webvar{parentid}, ($webvar{defrec} eq 'y' ? 'group' : 'domain'))) {
     410    my $msg = ($webvar{defrec} eq 'y' ?
     411        "You are not permitted to add or edit default records in the requested group" :
     412        "You are not permitted to add or edit records in the requested domain");
     413    $page->param(perm_err => $msg);
     414    goto DONEREC;
     415  }
     416
    392417
    393418  if ($webvar{recact} eq 'new') {
     
    519544    $page->param(dohere => domainName($dbh,$webvar{parentid}));
    520545  }
     546
     547  # Yes, this is a GOTO target.  PTBHTTT.
     548  DONEREC: ;
    521549
    522550} elsif ($webvar{page} eq 'delrec') {
     
    750778  fill_pgcount($count,'domains',groupName($dbh,$curgroup));
    751779  fill_fpnla($count);
    752   $page->param(offset => $offset);      # since apparently this isn't set explicitly elsewhere.  Who knew?
    753780  $page->param(perpage => $perpage);
    754781
     
    777804} elsif ($webvar{page} eq 'bulkchange') {
    778805
     806  # security check - does the user have permission to access this entity?
     807  if (!check_scope($webvar{destgroup}, 'group')) {
     808    $page->param(errmsg => "You are not permitted to make bulk changes in the requested group");
     809    goto DONEBULK;
     810  }
     811
    779812  if ($webvar{action} eq 'move') {
    780813    changepage(page => "domlist", errmsg => "You are not permitted to bulk-move domains")
     
    789822      my %row;
    790823      next unless $_ =~ /^dom_\d+$/;
     824      # second security check - does the user have permission to meddle with this domain?
     825      if (!check_scope($webvar{$_}, 'domain')) {
     826        $row{domerr} = "You are not permitted to make changes to the requested domain";
     827        $row{domain} = $webvar{$_};
     828        push @bulkresults, \%row;
     829        next;
     830      }
    791831      $row{domain} = domainName($dbh,$webvar{$_});
    792832      my ($code, $msg) = changeGroup($dbh, 'domain', $webvar{$_}, $webvar{destgroup});
     
    812852      my %row;
    813853      next unless $_ =~ /^dom_\d+$/;
     854      # second security check - does the user have permission to meddle with this domain?
     855      if (!check_scope($webvar{$_}, 'domain')) {
     856        $row{domerr} = "You are not permitted to make changes to the requested domain";
     857        $row{domain} = $webvar{$_};
     858        push @bulkresults, \%row;
     859        next;
     860      }
    814861      $row{domain} = domainName($dbh,$webvar{$_});
    815862##fixme:  error handling on status change
     
    832879      my %row;
    833880      next unless $_ =~ /^dom_\d+$/;
     881      # second security check - does the user have permission to meddle with this domain?
     882      if (!check_scope($webvar{$_}, 'domain')) {
     883        $row{domerr} = "You are not permitted to make changes to the requested domain";
     884        $row{domain} = $webvar{$_};
     885        push @bulkresults, \%row;
     886        next;
     887      }
    834888      $row{domain} = domainName($dbh,$webvar{$_});
    835889      my $pargroup = parentID($webvar{$_}, 'dom', 'group');
     
    851905  # not going to handle the unknown $webvar{action} else;  it should not be possible in normal
    852906  # operations, and anyone who meddles with the URL gets what they deserve.
     907
     908  # Yes, this is a GOTO target.  PTHBTTT.
     909  DONEBULK: ;
    853910
    854911} elsif ($webvar{page} eq 'useradmin') {
     
    11721229  $webvar{doit} = '' if !defined($webvar{doit});
    11731230
     1231  # security check - does the user have permission to access this entity?
     1232  if (!check_scope($webvar{group}, 'group')) {
     1233    $page->param(errmsg => "You are not permitted to import domains into the requested group");
     1234    goto DONEAXFR;
     1235  }
     1236
    11741237  if ($webvar{doit} eq 'y' && !$webvar{ifrom}) {
    11751238    $page->param(errmsg => "Need to set host to import from");
     
    12001263    $page->param(axfrresults => \@results);
    12011264  }
     1265
     1266  # Yes, this is a GOTO target.  PTBHTTT.
     1267  DONEAXFR: ;
    12021268
    12031269} elsif ($webvar{page} eq 'whoisq') {
     
    19722038  }
    19732039}
     2040
     2041# so simple when defined as a sub instead of inline.  O_o
     2042sub check_scope {
     2043  my $entity = shift;
     2044  my $entype = shift;
     2045
     2046  if ($entype eq 'group') {
     2047    return 1 if grep /^$entity$/, @viewablegroups;
     2048  } else {
     2049    foreach (@viewablegroups) {
     2050      return 1 if isParent($dbh, $_, 'group', $entity, $entype);
     2051    }
     2052  }
     2053}
Note: See TracChangeset for help on using the changeset viewer.