[Samba] Multiple Login scripts

José M. Fandiño samba at fadesa.es
Thu Nov 17 12:20:50 GMT 2005


> >Just a quick question about login scripts for a large number of users who
> >change rooms a lot.
> >
> >I have several rooms each with a printer, and nearly a thousand users divided
> >into two main groups - pupils and teachers who change rooms on a routine
> >basis. Is it possible to set up multiple login scripts that would be executed
> >in sequence i.e. run by user is %u, and machine is %m is it possible to say
> >run %u to set up shares followed by %m  to set up the right printers for the
> >room their in?

I have been using a lightly modified version of the perl logon
script in the samba contrib directory. Perhaps it can help you
with that.

The advantage of this script is that the secondary unix groups 
are automatically mapped to windows units (M:, J:, ...) based 
in their membership to those unix groups.

For you case simply add %m to the list of netlogon parameters
and write the desired configuration.


logon script = %U.bat

root preexec = " /usr/local/bin/logon.pl %U %G %L"


$usuario = $ARGV[0] ;
$grupoPrimario = $ARGV[1] ;
$servidor = $ARGV[2] ;

# log login activity
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
open LOG, ">>/var/log/samba/netlogon.log";
print LOG "$year/$mon/$mday $hour:$min:$sec";
print LOG " - User $ARGV[0] logged into $ARGV[1]\n";
close LOG;

# check the presence of a home directory
$idnum = (getpwnam ($usuario))[2];
$gidnum = (getpwnam ($usuario))[3];
$homedir = (getpwnam ($usuario))[7];
if ( ! -d $homedir) {
    mkdir(${homedir},0700) || die "No pude crear $homedir: $!";
    chown($idnum , $gidnum , ${homedir} );

# Start generating logon script
open LOGON, ">/var/lib/samba/netlogon/${usuario.bat}";
print LOGON "\@ECHO OFF\r\n";

# generic stuff.
print LOGON "NET USE /persistent:no\r\n";
print LOGON "NET TIME \\\\$servidor /set /yes \r\n";
print LOGON "NET USE U: /HOME \r\n";
print LOGON "NET USE F: \\\\$servidor\\publico   \r\n";

# specific user maps
if ($usuario eq "jefazo")
        print LOGON "NET USE z: \\\\$servidor\\CEO\r\n";

# primary group maps
if ($grupoPrimario eq "informatic") {
     print LOGON "NET USE H: \\\\$servidor\\$grupoPrimario  \r\n";

# secondary group maps
while (($grupoSecundario, $passwd, $gid, $members) = getgrent) {
    if ( grep /\b$ARGV[0]\b/, $members )
        if ( $grupoSecundario eq "telefonia" ) {
            print LOGON "NET USE N: \\\\$servidor\\$grupoSecundario  \r\n";
close LOGON;

Version: 3.1
GCS/IT d- s+:+() a31 C+++ UBL+++$ P+ L+++ E--- W++ N+ o++ K- w---
O+ M+ V- PS+ PE+ Y++ PGP+>+++ t+ 5 X+$ R- tv-- b+++ DI D++>+++
G++ e- h+(++) !r !z

More information about the samba mailing list