[LON-CAPA-cvs] cvs: loncom /lonnet/perl lonnet.pm
raeburn
lon-capa-cvs@mail.lon-capa.org
Wed, 10 Nov 2004 19:03:05 -0000
raeburn Wed Nov 10 14:03:05 2004 EDT
Modified files:
/loncom/lonnet/perl lonnet.pm
Log:
Extract some of the functionality of rolesinit() into separate subroutines to allow calling of subsets of rolesinit functionality. Also some compaction of code intended to keep the style police content.
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.566 loncom/lonnet/perl/lonnet.pm:1.567
--- loncom/lonnet/perl/lonnet.pm:1.566 Wed Nov 10 01:02:11 2004
+++ loncom/lonnet/perl/lonnet.pm Wed Nov 10 14:03:04 2004
@@ -1,7 +1,7 @@
# The LearningOnline Network
# TCP networking package
#
-# $Id: lonnet.pm,v 1.566 2004/11/10 06:02:11 banghart Exp $
+# $Id: lonnet.pm,v 1.567 2004/11/10 19:03:04 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -2387,10 +2387,8 @@
my $rolesdump=reply("dump:$domain:$username:roles",$authhost);
if (($rolesdump eq 'con_lost') || ($rolesdump eq '')) { return ''; }
my %allroles=();
- my %thesepriv=();
my $now=time;
my $userroles="user.login.time=$now\n";
- my $thesestr;
if ($rolesdump ne '') {
foreach (split(/&/,$rolesdump)) {
@@ -2398,94 +2396,21 @@
my ($area,$role)=split(/=/,$_);
$area=~s/\_\w\w$//;
my ($trole,$tend,$tstart)=split(/_/,$role);
- $userroles.='user.role.'.$trole.'.'.$area.'='.
- $tstart.'.'.$tend."\n";
-# log the associated role with the area
- &userrolelog($trole,$username,$domain,$area,$tstart,$tend);
- if ($tend!=0) {
- if ($tend<$now) {
- $trole='';
- }
- }
- if ($tstart!=0) {
- if ($tstart>$now) {
- $trole='';
- }
- }
+ $userroles.=&set_arearole($trole,$area,$tstart,$tend);
+ if (($tend!=0) && ($tend<$now)) { $trole=''; }
+ if (($tstart!=0) && ($tstart>$now)) { $trole=''; }
if (($area ne '') && ($trole ne '')) {
my $spec=$trole.'.'.$area;
my ($tdummy,$tdomain,$trest)=split(/\//,$area);
if ($trole =~ /^cr\//) {
- my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$trole);
- my $homsvr=homeserver($rauthor,$rdomain);
- if ($hostname{$homsvr} ne '') {
- my ($rdummy,$roledef)=
- &get('roles',["rolesdef_$rrole"],$rdomain,$rauthor);
-
- if (($rdummy ne 'con_lost') && ($roledef ne '')) {
- my ($syspriv,$dompriv,$coursepriv)=
- split(/\_/,$roledef);
- if (defined($syspriv)) {
- $allroles{'cm./'}.=':'.$syspriv;
- $allroles{$spec.'./'}.=':'.$syspriv;
- }
- if ($tdomain ne '') {
- if (defined($dompriv)) {
- $allroles{'cm./'.$tdomain.'/'}.=':'.$dompriv;
- $allroles{$spec.'./'.$tdomain.'/'}.=':'.$dompriv;
- }
- if ($trest ne '') {
- if (defined($coursepriv)) {
- $allroles{'cm.'.$area}.=':'.$coursepriv;
- $allroles{$spec.'.'.$area}.=':'.$coursepriv;
- }
- }
- }
- }
- }
+ &custom_roleprivs(\%allroles,$trole,$tdomain,$trest,$spec,$area);
} else {
- if (defined($pr{$trole.':s'})) {
- $allroles{'cm./'}.=':'.$pr{$trole.':s'};
- $allroles{$spec.'./'}.=':'.$pr{$trole.':s'};
- }
- if ($tdomain ne '') {
- if (defined($pr{$trole.':d'})) {
- $allroles{'cm./'.$tdomain.'/'}.=':'.$pr{$trole.':d'};
- $allroles{$spec.'./'.$tdomain.'/'}.=':'.$pr{$trole.':d'};
- }
- if ($trest ne '') {
- if (defined($pr{$trole.':c'})) {
- $allroles{'cm.'.$area}.=':'.$pr{$trole.':c'};
- $allroles{$spec.'.'.$area}.=':'.$pr{$trole.':c'};
- }
- }
- }
+ &standard_roleprivs(\%allroles,$trole,$tdomain,$spec,$trest,$area);
}
}
}
}
- my $adv=0;
- my $author=0;
- foreach (keys %allroles) {
- %thesepriv=();
- if (($_=~/^au/) || ($_=~/^ca/)) { $author=1; }
- foreach (split(/:/,$allroles{$_})) {
- if ($_ ne '') {
- my ($privilege,$restrictions)=split(/&/,$_);
- if ($restrictions eq '') {
- $thesepriv{$privilege}='F';
- } else {
- if ($thesepriv{$privilege} ne 'F') {
- $thesepriv{$privilege}.=$restrictions;
- }
- }
- if ($thesepriv{'adv'} eq 'F') { $adv=1; }
- }
- }
- $thesestr='';
- foreach (keys %thesepriv) { $thesestr.=':'.$_.'&'.$thesepriv{$_}; }
- $userroles.='user.priv.'.$_.'='.$thesestr."\n";
- }
+ my ($author,$adv) = &set_userprivs(\$userroles,\%allroles);
$userroles.='user.adv='.$adv."\n".
'user.author='.$author."\n";
$ENV{'user.adv'}=$adv;
@@ -2493,6 +2418,84 @@
return $userroles;
}
+sub set_arearole {
+ my ($trole,$area,$tstart,$tend,$domain,$username) = @_;
+# log the associated role with the area
+ &userrolelog($trole,$username,$domain,$area,$tstart,$tend);
+ return 'user.role.'.$trole.'.'.$area.'='.$tstart.'.'.$tend."\n";
+}
+
+sub custom_roleprivs {
+ my ($allroles,$trole,$tdomain,$trest,$spec,$area) = @_;
+ my ($rdummy,$rdomain,$rauthor,$rrole)=split(/\//,$trole);
+ my $homsvr=homeserver($rauthor,$rdomain);
+ if ($hostname{$homsvr} ne '') {
+ my ($rdummy,$roledef)=
+ &get('roles',["rolesdef_$rrole"],$rdomain,$rauthor);
+ if (($rdummy ne 'con_lost') && ($roledef ne '')) {
+ my ($syspriv,$dompriv,$coursepriv)=split(/\_/,$roledef);
+ if (defined($syspriv)) {
+ $$allroles{'cm./'}.=':'.$syspriv;
+ $$allroles{$spec.'./'}.=':'.$syspriv;
+ }
+ if ($tdomain ne '') {
+ if (defined($dompriv)) {
+ $$allroles{'cm./'.$tdomain.'/'}.=':'.$dompriv;
+ $$allroles{$spec.'./'.$tdomain.'/'}.=':'.$dompriv;
+ }
+ if (($trest ne '') && (defined($coursepriv))) {
+ $$allroles{'cm.'.$area}.=':'.$coursepriv;
+ $$allroles{$spec.'.'.$area}.=':'.$coursepriv;
+ }
+ }
+ }
+ }
+}
+
+
+sub standard_roleprivs {
+ my ($allroles,$trole,$tdomain,$spec,$trest,$area) = @_;
+ if (defined($pr{$trole.':s'})) {
+ $$allroles{'cm./'}.=':'.$pr{$trole.':s'};
+ $$allroles{$spec.'./'}.=':'.$pr{$trole.':s'};
+ }
+ if ($tdomain ne '') {
+ if (defined($pr{$trole.':d'})) {
+ $$allroles{'cm./'.$tdomain.'/'}.=':'.$pr{$trole.':d'};
+ $$allroles{$spec.'./'.$tdomain.'/'}.=':'.$pr{$trole.':d'};
+ }
+ if (($trest ne '') && (defined($pr{$trole.':c'}))) {
+ $$allroles{'cm.'.$area}.=':'.$pr{$trole.':c'};
+ $$allroles{$spec.'.'.$area}.=':'.$pr{$trole.':c'};
+ }
+ }
+}
+
+sub set_userprivs {
+ my ($userroles,$allroles) = @_;
+ my $author=0;
+ my $adv=0;
+ foreach (keys %{$allroles}) {
+ my %thesepriv=();
+ if (($_=~/^au/) || ($_=~/^ca/)) { $author=1; }
+ foreach (split(/:/,$$allroles{$_})) {
+ if ($_ ne '') {
+ my ($privilege,$restrictions)=split(/&/,$_);
+ if ($restrictions eq '') {
+ $thesepriv{$privilege}='F';
+ } elsif ($thesepriv{$privilege} ne 'F') {
+ $thesepriv{$privilege}.=$restrictions;
+ }
+ if ($thesepriv{'adv'} eq 'F') { $adv=1; }
+ }
+ }
+ my $thesestr='';
+ foreach (keys %thesepriv) { $thesestr.=':'.$_.'&'.$thesepriv{$_}; }
+ $$userroles.='user.priv.'.$_.'='.$thesestr."\n";
+ }
+ return ($author,$adv);
+}
+
# --------------------------------------------------------------- get interface
sub get {