[LON-CAPA-cvs] cvs: loncom /debugging_tools move_construction_spaces.pl
raeburn
raeburn at source.lon-capa.org
Fri Jun 8 09:08:13 EDT 2012
raeburn Fri Jun 8 13:08:13 2012 EDT
Modified files:
/loncom/debugging_tools move_construction_spaces.pl
Log:
- Undo of authoring spaces migration.
- Detect case where user has a UNIX account and authentication in LON-CAPA
is filesystem auth (i.e., unix:).
- Set permissions/ownership in /home/<user> accordingly and add www to
user's group, if not currently included.
Index: loncom/debugging_tools/move_construction_spaces.pl
diff -u loncom/debugging_tools/move_construction_spaces.pl:1.8 loncom/debugging_tools/move_construction_spaces.pl:1.9
--- loncom/debugging_tools/move_construction_spaces.pl:1.8 Fri Jun 8 13:04:08 2012
+++ loncom/debugging_tools/move_construction_spaces.pl Fri Jun 8 13:08:13 2012
@@ -5,7 +5,7 @@
# Move Construction Spaces from /home/$user/public_html
# to /home/httpd/html/priv/$domain/$user and vice versa
#
-# $Id: move_construction_spaces.pl,v 1.8 2012/06/08 13:04:08 raeburn Exp $
+# $Id: move_construction_spaces.pl,v 1.9 2012/06/08 13:08:13 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -819,11 +819,22 @@
if ($uname =~ /^$match_username$/ && $domain =~ /^$match_domain$/) {
my $source_path="$londocroot/priv/$domain/$uname";
my $target_path="/home/$uname/public_html";
+ my $userpath = &LONCAPA::propath($domain,$uname);
+ my ($authtype,$userid,$groupid);
+ if (-e "$userpath/passwd") {
+ if (open(my $fh, "<$userpath/passwd")) {
+ ($authtype) = split(/:/,<$fh>);
+ close($fh);
+ }
+ }
if (!-e "/home/$uname") {
- my (undef,undef,$userid,$groupid) = getpwnam($uname);
+ (undef,undef,$userid,$groupid) = getpwnam($uname);
if (mkdir("/home/$uname",0711)) {
- if ($userid ne '' && $groupid ne '') {
+ if ($authtype eq 'unix' && $userid ne '' && $groupid ne '') {
chown($userid,$groupid,"/home/$uname");
+ if (&www_in_group($uname)) {
+ chmod(0710,"/home/$uname");
+ }
}
} else {
$output = &mt('Failed to create directory [_1] -- not moving [_2].',
@@ -835,6 +846,11 @@
if (!-e $target_path) {
move($source_path,$target_path);
chown($uid,$gid,$target_path);
+ if ($authtype eq 'unix' && $userid ne '' && $groupid ne '') {
+ if (&www_in_group($uname)) {
+ chown($userid,$groupid,$target_path);
+ }
+ }
chmod(02770,$target_path);
if (-e $target_path && !-e $source_path) {
$output = &mt('Moved [_1] to [_2].',"'$source_path'","'$target_path'")."\n";
@@ -850,6 +866,30 @@
return $output;
}
+sub www_in_group {
+ my ($uname) = @_;
+ my $hasuser;
+ if (open(PIPE,"/usr/bin/groups www|")) {
+ my $memberlist = <PIPE>;
+ close(PIPE);
+ chomp($memberlist);
+ my ($safegroups)=($memberlist=~/:\s*([\s\w]+)$/);
+ if ($safegroups =~ /\S/) {
+ my @members = split(/\s+/,$safegroups);
+ if (grep(/^\Q$uname\E$/, at members)) {
+ $hasuser = 1;
+ } else {
+ my @ugrouplist=grep(!/www|$uname/, at members);
+ my $gl=join(',',(@ugrouplist,$uname));
+ if (system('/usr/sbin/usermod','-G',$gl,'www') == 0) {
+ $hasuser = 1;
+ }
+ }
+ }
+ }
+ return $hasuser;
+}
+
sub get_user_selection {
my ($defaultrun) = @_;
my $do_action = 0;
More information about the LON-CAPA-cvs
mailing list