[Samba] Multiple Login scripts

Robert Schetterer robert at schetterer.org
Sat Nov 19 15:34:51 GMT 2005


José M. Fandiño schrieb:

>Hello,
>
>  
>
>>>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.
>
>regards,
>
>smb.conf:
>=========
>[global]
>logon script = %U.bat
>
>[netlogon]
>...
>root preexec = " /usr/local/bin/logon.pl %U %G %L"
>
>	/----/
>
>logon.pl:
>=========
>#!/usr/bin/perl
>$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;
>
>  
>
Hi this scripts are very usefull if you want things coming up on demand, 
but for every change this has to be rewritten, ifmember.exe
in an default logon.bat is more flexible as it is only one file in one 
place which has to be edited and it needs no prexec.
After all every win admin can rewrite it too, some of them hat deep 
problems with perl
Regards


More information about the samba mailing list