84 lines
3.1 KiB
Perl
Executable File
84 lines
3.1 KiB
Perl
Executable File
#!/usr/bin/perl
|
|
|
|
use esmith::AccountsDB;
|
|
use esmith::ConfigDB;
|
|
|
|
# get username and current PC name from arguments
|
|
my $username=$ARGV[0];
|
|
my $currentpc=$ARGV[1];
|
|
my $arch=$ARGV[2];
|
|
my $ip_address=$ARGV[3];
|
|
|
|
# open accounts and config DBs
|
|
my $db = esmith::ConfigDB->open_ro();
|
|
my $adb = esmith::AccountsDB->open_ro();
|
|
|
|
|
|
# get samba server name
|
|
my $smb = $db->get("smb");
|
|
my $server_name = $smb->prop("ServerName");
|
|
|
|
#get current date and time
|
|
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
|
|
$month = ('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec')[$mon];
|
|
|
|
my $netlogon_root = "/home/e-smith/files/samba/netlogon";
|
|
|
|
|
|
open LOG, ">>/var/log/netlogon.log";
|
|
print LOG "$month $mday $hour:$min:$sec\t$username logged into $currentpc ($arch) - $ip_address\n";
|
|
|
|
# get groups user belongs to
|
|
setgrent();
|
|
while (@grline=getgrent()) {
|
|
(@users)=split(' ',$grline[3]);
|
|
if (grep(/^$username$/,@users)) {
|
|
push(@groups,$grline[0]);
|
|
}
|
|
}
|
|
|
|
# create drive mapping files for users
|
|
my $logonscriptdb = $db->get("twlogonscript");
|
|
my $mount_point_path = $logonscriptdb->prop("MountPointsPath");
|
|
my $user_home_mount_point_name = $logonscriptdb->prop("UserHomeMountPointName");
|
|
open LOGON, ">$netlogon_root/users/$username.bat";
|
|
mkdir "$netlogon_root/users/$username";
|
|
open PAMCONF, ">$netlogon_root/users/$username/.pam_mount.conf.xml";
|
|
print PAMCONF "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
|
|
print PAMCONF "<!DOCTYPE pam_mount SYSTEM \"pam_mount.conf.xml.dtd\">\n";
|
|
print PAMCONF "<pam_mount>\n";
|
|
print PAMCONF "<volume user=\"*\" fstype=\"cifs\" server=\"$server_name\" path=\"%(DOMAIN_USER)\" mountpoint=\"$mount_point_path/$user_home_mount_point_name\" options=\"nodev,nosuid\"></volume>\n";
|
|
|
|
foreach my $ibay ($adb->ibays)
|
|
{
|
|
$ibay_name = $ibay->key;
|
|
$ibay_group = $ibay->prop('Group');
|
|
$ibay_useraccess = $ibay->prop('UserAccess');
|
|
$ibay_drive_letter = $ibay->prop('DriveLetter') || "NONE";
|
|
if ($ibay_drive_letter ne "NONE") {
|
|
if (grep(/^$ibay_group$/,@groups) || ($ibay_useraccess eq "wr-group-rd-everyone")){
|
|
print LOGON "NET USE $ibay_drive_letter: \\\\$server_name\\".$ibay_name."\r\n";
|
|
print PAMCONF "<volume user=\"*\" fstype=\"cifs\" server=\"$server_name\" path=\"$ibay_name\" mountpoint=\"$mount_point_path/$ibay_name\" options=\"nodev,nosuid\"></volume>\n";
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
print LOGON "rem Custom group and user related scripts\r\n";
|
|
foreach my $group (@groups)
|
|
{
|
|
if (-e "$netlogon_root/custom/$group.bat"){
|
|
print LOGON "CALL \\\\$server_name\\netlogon\\custom\\$group.bat\r\n";
|
|
}
|
|
|
|
}
|
|
if (-e "$netlogon_root/custom/$username.bat"){
|
|
print LOGON "CALL \\\\$server_name\\netlogon\\custom\\$username.bat\r\n";
|
|
}
|
|
|
|
print PAMCONF "</pam_mount>\n";
|
|
close PAMCONF;
|
|
close LOGON;
|
|
chmod(0755, "$netlogon_root/users/$username.bat");
|
|
close LOG;
|