[LON-CAPA-cvs] cvs: loncom / Lond.pm lond /lonnet/perl lonnet.pm
raeburn
raeburn at source.lon-capa.org
Mon Feb 8 09:50:53 EST 2021
raeburn Mon Feb 8 14:50:53 2021 EDT
Modified files:
/loncom lond Lond.pm
/loncom/lonnet/perl lonnet.pm
Log:
- Bug 6585
get_domain_handler() and encrypted_get_domain_handler() in lond now use
get_dom() routine in Lond.pm
Index: loncom/lond
diff -u loncom/lond:1.564 loncom/lond:1.565
--- loncom/lond:1.564 Thu Oct 22 19:23:22 2020
+++ loncom/lond Mon Feb 8 14:50:53 2021
@@ -2,7 +2,7 @@
# The LearningOnline Network
# lond "LON Daemon" Server (port "LOND" 5663)
#
-# $Id: lond,v 1.564 2020/10/22 19:23:22 raeburn Exp $
+# $Id: lond,v 1.565 2021/02/08 14:50:53 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -65,7 +65,7 @@
my $status='';
my $lastlog='';
-my $VERSION='$Revision: 1.564 $'; #' stupid emacs
+my $VERSION='$Revision: 1.565 $'; #' stupid emacs
my $remoteVERSION;
my $currenthostid="default";
my $currentdomainid;
@@ -5077,7 +5077,7 @@
# domain directory.
#
# Parameters:
-# $cmd - Command request keyword (get).
+# $cmd - Command request keyword (getdom).
# $tail - Tail of the command. This is a colon separated list
# consisting of the domain and the 'namespace'
# which selects the gdbm file to do the lookup in,
@@ -5094,31 +5094,17 @@
sub get_domain_handler {
my ($cmd, $tail, $client) = @_;
-
my $userinput = "$cmd:$tail";
my ($udom,$namespace,$what)=split(/:/,$tail,3);
- chomp($what);
if ($namespace =~ /^enc/) {
&Failure( $client, "refused\n", $userinput);
} else {
- my @queries=split(/\&/,$what);
- my $qresult='';
- my $hashref = &tie_domain_hash($udom, "$namespace", &GDBM_READER());
- if ($hashref) {
- for (my $i=0;$i<=$#queries;$i++) {
- $qresult.="$hashref->{$queries[$i]}&";
- }
- if (&untie_domain_hash($hashref)) {
- $qresult=~s/\&$//;
- &Reply($client, \$qresult, $userinput);
- } else {
- &Failure( $client, "error: ".($!+0)." untie(GDBM) Failed ".
- "while attempting getdom\n",$userinput);
- }
+ my $res = LONCAPA::Lond::get_dom($userinput);
+ if ($res =~ /^error:/) {
+ &Failure($client, \$res, $userinput);
} else {
- &Failure($client, "error: ".($!+0)." tie(GDBM) Failed ".
- "while attempting getdom\n",$userinput);
+ &Reply($client, \$res, $userinput);
}
}
@@ -5131,38 +5117,24 @@
my $userinput = "$cmd:$tail";
- my ($udom,$namespace,$what)=split(/:/,$tail,3);
- chomp($what);
- my @queries=split(/\&/,$what);
- my $qresult='';
- my $hashref = &tie_domain_hash($udom, "$namespace", &GDBM_READER());
- if ($hashref) {
- for (my $i=0;$i<=$#queries;$i++) {
- $qresult.="$hashref->{$queries[$i]}&";
- }
- if (&untie_domain_hash($hashref)) {
- $qresult=~s/\&$//;
- if ($cipher) {
- my $cmdlength=length($qresult);
- $qresult.=" ";
- my $encqresult='';
- for (my $encidx=0;$encidx<=$cmdlength;$encidx+=8) {
- $encqresult.= unpack("H16",
- $cipher->encrypt(substr($qresult,
- $encidx,
- 8)));
- }
- &Reply( $client, "enc:$cmdlength:$encqresult\n", $userinput);
- } else {
- &Failure( $client, "error:no_key\n", $userinput);
+ my $res = LONCAPA::Lond::get_dom($userinput);
+ if ($res =~ /^error:/) {
+ &Failure($client, \$res, $userinput);
+ } else {
+ if ($cipher) {
+ my $cmdlength=length($res);
+ $res.=" ";
+ my $encres='';
+ for (my $encidx=0;$encidx<=$cmdlength;$encidx+=8) {
+ $encres.= unpack("H16",
+ $cipher->encrypt(substr($res,
+ $encidx,
+ 8)));
}
+ &Reply( $client,"enc:$cmdlength:$encres\n",$userinput);
} else {
- &Failure( $client, "error: ".($!+0)." untie(GDBM) Failed ".
- "while attempting egetdom\n",$userinput);
+ &Failure( $client, "error:no_key\n",$userinput);
}
- } else {
- &Failure($client, "error: ".($!+0)." tie(GDBM) Failed ".
- "while attempting egetdom\n",$userinput);
}
return 1;
}
Index: loncom/Lond.pm
diff -u loncom/Lond.pm:1.15 loncom/Lond.pm:1.16
--- loncom/Lond.pm:1.15 Thu Jul 11 18:12:01 2019
+++ loncom/Lond.pm Mon Feb 8 14:50:53 2021
@@ -1,6 +1,6 @@
# The LearningOnline Network
#
-# $Id: Lond.pm,v 1.15 2019/07/11 18:12:01 raeburn Exp $
+# $Id: Lond.pm,v 1.16 2021/02/08 14:50:53 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -1024,6 +1024,25 @@
return $result;
}
+sub get_dom {
+ my ($userinput) = @_;
+ my ($cmd,$udom,$namespace,$what) =split(/:/,$userinput,4);
+ my $hashref = &tie_domain_hash($udom,$namespace,&GDBM_READER()) or
+ return "error: ".($!+0)." tie(GDBM) Failed while attempting $cmd";
+ my $qresult='';
+ if (ref($hashref)) {
+ chomp($what);
+ my @queries=split(/\&/,$what);
+ for (my $i=0;$i<=$#queries;$i++) {
+ $qresult.="$hashref->{$queries[$i]}&";
+ }
+ $qresult=~s/\&$//;
+ }
+ &untie_user_hash($hashref) or
+ return "error: ".($!+0)." untie(GDBM) Failed while attempting $cmd";
+ return $qresult;
+}
+
1;
__END__
@@ -1146,7 +1165,18 @@
The contents of the inner hash, for that single item in the outer hash
are returned (and cached in memcache for 10 minutes).
+=item get_dom ( $userinput )
+get_dom() will retrieve domain configuration information from a GDBM file
+in /home/httpd/lonUsers/$dom on the primary library server in a domain.
+The single argument passed is the string: $cmd:$udom:$namespace:$what
+where $cmd is the command historically passed to lond - i.e., getdom
+or egetdom, $udom is the domain, $namespace is the name of the GDBM file
+(encconfig or configuration), and $what is a string containing names of
+items to retrieve from the db file (each item name is escaped and separated
+from the next item name with an ampersand). The return value is either:
+error: followed by an error message, or a string containing the value (escaped)
+for each item, again separated from the next item with an ampersand.
=back
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1441 loncom/lonnet/perl/lonnet.pm:1.1442
--- loncom/lonnet/perl/lonnet.pm:1.1441 Mon Feb 8 14:10:17 2021
+++ loncom/lonnet/perl/lonnet.pm Mon Feb 8 14:50:53 2021
@@ -1,7 +1,7 @@
# The LearningOnline Network
# TCP networking package
#
-# $Id: lonnet.pm,v 1.1441 2021/02/08 14:10:17 raeburn Exp $
+# $Id: lonnet.pm,v 1.1442 2021/02/08 14:50:53 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -2164,10 +2164,19 @@
}
if ($udom && $uhome && ($uhome ne 'no_host')) {
my $rep;
- if ($namespace =~ /^enc/) {
- $rep=&reply("encrypt:egetdom:$udom:$namespace:$items",$uhome);
+ if (grep { $_ eq $uhome } ¤t_machine_ids()) {
+ # domain information is hosted on this machine
+ my $cmd = 'getdom';
+ if ($namespace =~ /^enc/) {
+ $cmd = 'egetdom';
+ }
+ $rep = &LONCAPA::Lond::get_dom("$cmd:$udom:$namespace:$items");
} else {
- $rep=&reply("getdom:$udom:$namespace:$items",$uhome);
+ if ($namespace =~ /^enc/) {
+ $rep=&reply("encrypt:egetdom:$udom:$namespace:$items",$uhome);
+ } else {
+ $rep=&reply("getdom:$udom:$namespace:$items",$uhome);
+ }
}
my %returnhash;
if ($rep eq '' || $rep =~ /^error: 2 /) {
More information about the LON-CAPA-cvs
mailing list