Script for capturing variables

Joel Hammer jhammer2 at
Thu Sep 13 19:00:02 GMT 2001

I spent some tedious time writing a preexec and a script for capturing all
those variables which samba has when a user logs in. I thought I would pass
them along, just in case someone else finds them useful.
The smb.conf preexec isn't very pretty. I can't be sure it will work in its
present form, since in my smb.conf file it was all one long line, but when I
cut and pasted it into this email vi automatically put in returns. I put in
\ at the end of each line so things might work just fine as it is.
The preexec close = yes makes samba deny the connection if the preexec
script returns an error code. Very handy. I call this a preexec script, but
SWAT calls them exec scripts and removes the pre, but it is the same thing.
Maybe SWAT removes those carriage returns, too. Not sure.

        comment = Root directory
        path = /
        read only = No
        create mask = 0766
        guest ok = Yes
        preexec close = yes
        exec = rm /tmp/Hello;echo \"m %m \" \"G %G \" \"I %I \" \"L %L \" \
\"M %M \" \"N %N \" \"R %R \"  \"T %T \" \"U %U \" \
\"a %a \" \"d %d \" \"h %h \" \"p %p \" \"v %v \" \
\"H %H \" \"P %P \" \"S %S \" \"g %g \" \"u %u \"  | xargs -n1 /usr/local/samba/bin/Hello;

To make things confusing, I called the data file Hello and the script
Hello, but, since they are in different directories, that shouldn't be a

This is the script Hello:

 i=`echo "$1" | tr -s " "`
 index=`echo "$i" | cut -d" " -f1`
 value=`echo "$i" | sed 's/^. //'`
 case $index in
   m )  message="client machine NetBios name = $value";;

   M )  message="Internet DNS of client= $value";;

   I )  message="IP address of client = $value";;

   a )  message="Architecture of remote machine= $value";;

   U )  message="Session user name (one the client wanted)= $value";;

   L )  message="Netbios name of server = $value";;

   h )  message="Internet DNS hostname of server= $value";;

   R )  message="Protocal level = $value";;

   v )  message="Samba version= $value";;

   T )  message="Current time and date= $value";;

   G )  message="Primary goup name of u = $value";;

   N )  message="NIS home directory= $value";;

   d )  message="Process ID of current server= $value";;

   p )  message="Path of services home directory from NIS= $value";;

   H )  message="Home directory of user in u= $value";;                        

   P )  message="Root directory of current service = $value";;

   S )  message="Name of current service = $value";;

   g )  message="Primary group name of u in share = $value";;

   u )  message="User name of current service = $value";;
echo $message \(\%$index\) >> /tmp/Hello

More information about the samba mailing list