# modUserProf.pl modifies user profiles containing AXPA. # Calls the following external commands: NET USER. # Written 28-Jan-1998 by fhb. # Usage: modUserProf username | filename # # filename file must contain a list of usernames. # Lines beginning with a '!' are ignored as comments. # $bDebug = 1; $sTempFile = "t.t"; $nTotal = 0; MAIN: $sAppName = "modUserProf"; $sVersion = "0.1"; print "$sAppName $sVersion\n"; $sFile = $ARGV[0]; if (!$sFile) { die "No username or filename supplied.\n"; } if (open(FDATA,$sFile)) { while () { if (!/^\!/) { # skip comments chop; s/\s(.*)//; # remove whitespace $sUser = $_; &ModProfilePath(); } } } else { # arg not a file, so try single user: $sUser = $ARGV[0]; &ModProfilePath(); } if ($nTotal > 1) { print "$sAppName: modified profile for $nTotal users.\n"; } if ($nTotal == 1) { print "$sAppName: modified profile path for $sUser.\n"; } if ($nTotal < 1) { print "$sAppName: no modifications made.\n"; } ##### We all live in a yellow subroutine... ##### sub ModProfilePath { # Capture NET USER output in temp file to get profile path: $sCmd = sprintf("NET USER %s /dom >%s",$sUser,$sTempFile); if ($bDebug) { print "dbg> $sCmd\n"; } system($sCmd); open(FTEMP,$sTempFile) || print "Can't open file $sTempFile: $!\n"; while () { chop $_; # if ($bDebug) { print "dbg> line=$_\n"; } if (/^User profile (.*)/) { $sProPath = substr($_,18); last; } } close(FTEMP); if ($bDebug == 0) { unlink $sTempFile; } if ($sProPath eq "") { die "Can't find profile for $sUser!\n"; } $_ = $sProPath; if (!/axpa/ && !/AXPA/) { return; } # no servername in profile # replace hardcoded server with environment var in $_: s/\\\\axpa/\%LOGONSERVER\%/; s/\\\\AXPA/\%LOGONSERVER\%/; s/^\s+//; # remove whitespace $sCmd = sprintf("net user %s /profilepath:%s /dom",$sUser,$_); if ($bDebug) { print "dbg> $sCmd\n"; } else { print "changing profile for $sUser...\n"; system($sCmd); } ++$nTotal; }