--- loncom/debugging_tools/move_construction_spaces.pl 2012/06/08 13:04:08 1.8 +++ loncom/debugging_tools/move_construction_spaces.pl 2012/06/08 13:08:13 1.9 @@ -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 @@ sub move_priv_to_home { 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 @@ sub move_priv_to_home { 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 @@ sub move_priv_to_home { return $output; } +sub www_in_group { + my ($uname) = @_; + my $hasuser; + if (open(PIPE,"/usr/bin/groups www|")) { + my $memberlist = ; + close(PIPE); + chomp($memberlist); + my ($safegroups)=($memberlist=~/:\s*([\s\w]+)$/); + if ($safegroups =~ /\S/) { + my @members = split(/\s+/,$safegroups); + if (grep(/^\Q$uname\E$/,@members)) { + $hasuser = 1; + } else { + my @ugrouplist=grep(!/www|$uname/,@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;