[Samba] HomeDir with machinenname

kissg mail.gery at gmail.com
Wed Jun 18 16:05:23 GMT 2008


Dear Marc,

it's always a good idea to read man pages (this is from the smb.conf man
page):

"%m
          the NetBIOS name of the client machine (very useful).

          This parameter is not available when Samba listens on port  445,
as
          clients no longer send this information. If you use this macro in
an
          include statement on a domain that has a Samba domain controller
be
          sure to set in the [global] section smb ports = 139. This will
cause
          Samba to not listen on port 445 and will permit include
functional$B!>(B
          ity to function as it did with Samba 2.x."

So, according to this, you should add an entry to the [global] section of
your smb.conf file:

smb ports = 139

Another thing to note, is that you have to write a script, that creates the
machine's directory, if it doesn't exist yet and instruct Samba to run the
script, when a user logs in.

To do this, add the following to the [netlogon] share in smb.conf:

root preexec = /usr/local/sbin/createmachinedir.sh %m %u

This script will test if the username is "general" and create a directory
with the name of the machine where the user has logged in from.

Create a file in the directory /usr/local/sbin, named "createmachinedir.sh"
and copy the followings to it:

######### Script start #########

#!/bin/sh

SHAREPATH="/shares/Public/general"

if [ ! -e "$SHAREPATH/$1" -a "$2" = "general"]
then
   mkdir "$SHAREPATH/$1"
   # Set permissions with chown and chmod:
   # "general" will be the owner of this directory:
   chown general:users "$SHAREPATH/$1"
   # We give access only to "general" for this machine directory
   # (correct this if you want to grant permissions to other users, too)
   chmod 0700 "$SHAREPATH/$1"
fi
exit 0

######### End of script #########

Save the script and set the executable bit:

chmod a+x /usr/local/sbin/createmachinedir.sh

The next step is, to map the correct directory when the user logs in. This
can be achieved by adding the following command to the user's logon script:

net use Z: %LOGONSERVER%\Public\general\%COMPUTERNAME%

You can use any drive letter instead of Z:, just make sure, it is not
already taken.

I think, this could provide a perfect solution to your problem. By the way,
I use a similar script to create home directories for domain users, when
they log in for the first time.

Please tell me whether this method works for you or not.

Best regards:
Gergely Kiss

2008/6/18 Marc Muehlfeld <Marc.Muehlfeld at medizinische-genetik.de>:

> No one any idea how I can get this working?
>
>
> Marc Muehlfeld schrieb:
>
>> Hello.
>>
>> I have a Folder /shares/Public/ which is shared. The Account "general"
>> should have a separate HomeDir below /shares/Public/general depending on the
>> machine name. So I set the attribute homeDirectory in LDAP to
>> /shares/Public/general/%m (i also tried %M).
>>
>> But when I log on at PC01, the HomeDir is not mounted, because %m/%M was
>> not resolved to the machinename:
>>
>>  > /shares/Public/general/10.1.0.17' does not exist or permission denied
>> when
>>  > connecting to [general] Error was No such file or directory
>>
>> I use %m for the logfile name too, where it is mapped to the machine name
>> (not the IP).
>>
>> Any idea what could went wrong and how else I can get the needed setup?
>> Currently we use 3.0.22 and can't upgrade because of different problems with
>> trusted domains in our setup.
>>
>> Regards
>> Marc Muehlfeld
>>
>>
> --
> Marc Muehlfeld (Leitung IT)
> Zentrum fuer Humangenetik und Laboratoriumsmedizin Dr. Klein und Dr. Rost
> Lochhamer Str. 29 - D-82152 Martinsried
> Telefon: +49(0)89/895578-0 - Fax: +49(0)89/895578-78
> http://www.medizinische-genetik.de
>
> --
> To unsubscribe from this list go to the following URL and read the
> instructions:  https://lists.samba.org/mailman/listinfo/samba
>


More information about the samba mailing list