The following guide describes how to install Samba with OpenLDAP support on an Ubuntu server. This guide assumes that OpenLDAP is already installed and is running on the same server as the Samba installation. The Samba installation is an extension of the Installing Secure LDAP (OpenLDAP with SSL) on Ubuntu using a Self-signed Certificate HOWTO.
See Also:
Run the following from the command line:
sudo apt-get install slapd ldap-utils libnss-ldap libpam-ldap samba smbldap-tools smbclient samba-doc
Add a localhost OpenLDAP to /etc/default/slapd:
SLAPD_SERVICES="ldaps://HOSTNAMEHERE/ ldap://localhost"
Copy the samba.schema to be used in the LDAP server:
cp /usr/share/doc/samba-doc/examples/LDAP/samba.schema.gz /etc/ldap/schema/
gzip -d /etc/ldap/schema/samba.schema.gz
Update /etc/ldap/slapd.conf to include the following schemas:
include /etc/ldap/schema/samba.schema
include /etc/ldap/schema/misc.schema
Add indexes to optimize Samba access (optional):
index uid,uidNumber,gidNumber,memberUid eq
index cn,mail,surname,givenname eq,subinitial
index sambaSID eq
index sambaPrimaryGroupSID eq
index sambaDomainName eq
Allow users to change their passwords by updating the line:
access to attribute=userPassword
to:
access to attrs=userPassword,sambaNTPassword,sambaLMPassword
Restart the OpenLDAP server:
/etc/init.d/slapd restart
Copy necessary files for configuration:
cd /usr/share/doc/smbldap-tools/examples/
cp smbldap_bind.conf /etc/smbldap-tools/
cp smbldap.conf.gz /etc/smbldap-tools/
gzip -d /etc/smbldap-tools/smbldap.conf.gz
Determine your SID:
net getlocalsid
Edit the following parameters in the smbldap.conf file:
SID="YOUR_SID_HERE"
slaveLDAP="127.0.0.1"
masterLDAP="127.0.0.1"
ldapTLS="0"
mailDomain="yourdomain.com"
suffix="dc=YOURDOMAIN,dc=COM"
Set the authentication paramters in the smbldap_bind.conf file:
slaveDN="cn=admin,dc=YOURDOMAIN,dc=COM"
slavePw="YOURPASSWORDHERE"
masterDN="cn=admin,dc=YOURDOMAIN,dc=COM"
masterPw="YOURPASSORDHERE"
Set the approprite file permissions:
chmod 0644 /etc/smbldap-tools/smbldap.conf
chmod 0600 /etc/smbldap-tools/smbldap_bind.conf
Populate the OpenLDAP server:
smbldap-populate -u 30000 -g 30000
The -u flag sets the first user uidNumber to allocate. The -g flag sets the first group gidNumber to allocate. Set these to appropriate values as you see fit.
For more options to set in smbldap-populate run:
smbldap-populate -?
Edit /etc/samba/smb.conf and change:
passdb backend = tdbsam guest
to:
passdb backend = ldapsam:ldap://localhost/
All directives listed below must be placed in the [globals] section of /etc/samba/smb.conf.
Add the following:
obey pam restrictions = no
ldap admin dn = cn=admin,dc=HOSTNAME,dc=HERE
ldap suffix = dc=HOSTNAME, dc=HERE
ldap group suffix = ou=Groups
ldap user suffix = ou=Users
ldap machine suffix = ou=Computers
ldap idmap suffix = ou=Users
Allow passwd sync with smbldap-passwd:
; Do ldap passwd sync
ldap passwd sync = Yes
passwd program = /usr/sbin/smbldap-passwd %u
passwd chat = *New*password* %n\n *Retype*new*password* %n\n *all*authentication*tokens*updated*
To administer user and groups from Windows add:
add user script = /usr/sbin/smbldap-useradd -m "%u"
ldap delete dn = Yes
delete user script = /usr/sbin/smbldap-userdel "%u"
add machine script = /usr/sbin/smbldap-useradd -w "%u"
add group script = /usr/sbin/smbldap-groupadd -p "%g"
delete group script = /usr/sbin/smbldap-groupdel "%g"
add user to group script = /usr/sbin/smbldap-groupmod -m "%u" "%g"
delete user from group script = /usr/sbin/smbldap-groupmod -x "%u" "%g"
set primary group script = /usr/sbin/smbldap-usermod -g "%g" "%u"
Enable domain logins by adding the following to the [globals] section:
domain logons = yes
Restart Samba and set the smbldap admin password:
/etc/init.d/samba restart
smbpasswd -w ADMIN_PASSWORD
Update /etc/libnss-ldap.conf and set the following values:
base dc=YOURDOMAIN,dc=HERE
uri ldaps://YOURLDAPSERVER
ldap_version 3
Update /etc/nsswitch.conf as follows:
passwd: files ldap
group: files ldap
shadow: files ldap
udevd[374]: nss_ldap: could not connect to any LDAP server as (null) - Can't contact LDAP server
To solve the nss_ldap: could not connect to any LDAP server as (null) issue create a group called nvram:
sudo addgroup nvram
When attempting to access a Samba share from a Windows/Mac/Linux workstation I was denied access. Repeated attempts with a user/pass combination I knew should work did not work.
When I turned on degugging in the /etc/ldap/slapd.conf file I found the following error message:
bdb_db_init: Initializing BDB database
slapd starting
conn=0 fd=10 ACCEPT from IP=127.0.0.1:45936 (IP=0.0.0.0:389)
conn=0 op=0 BIND dn="" method=128
conn=0 op=0 RESULT tag=97 err=49 text=
conn=0 op=1 UNBIND
conn=0 fd=10 closed
I had placed the Samba ldap parameters (see the Configure Samba section) at the end of the configuration file. The solution was to move the confuration directives into the [global] section of /etc/samba/smb.conf and restart Samba.
After updating /etc/nsswitch.conf (see Configure NSS to work with LDAP) rebooting the server stalled with the following message:
udevd[]: nss_ldap: could not connect to any LDAP server as (null) - Can't contact LDAP server
udevd[]: nss_ldap: failed to bind to LDAP server ldaps://LDAPSERVER.HERE: Can't contact LDAP server
udevd[]: nss_ldap: could not connect to any LDAP server as (null) - Can't contact LDAP server
udevd[]: nss_ldap: failed to bind to LDAP server ldaps://LDAPSERVER.HERE: Can't contact LDAP server
udevd[]: nss_ldap: could not connect to any LDAP server as (null) - Can't contact LDAP server
udevd[]: nss_ldap: failed to bind to LDAP server ldaps://LDAPSERVER.HERE: Can't contact LDAP server
udevd[]: nss_ldap: reconnecting to LDAP server (sleeping 4 seconds)
The sleep interval is doubled each time (4,8,16,32,64 seconds) and takes a very long time to boot up.
A bug report can be found here.
The issue and proposed solution is as follows:
The problem is caused by the usage of the non existing group 'nvram' in /etc/udev/rules.d/40-permissions.rules: KERNEL=="nvram", GROUP="nvram" When udev starts, is looks up 'nvram'. While 'nvram' could not be found in /etc/group NSS tries to connect the ldap server. As result the boot sequence stops. To fix this problem is very easy: Add the local group 'nvram' to /etc/groups
Type in the following:
sudo addgroup nvram
If you are running BIND on the same computer as you are running Samba you may run into an issue when restarting/starting the BIND service. This may be an issue when rebooting however I have not tested that yet.
When restarting the BIND server (/etc/init.d/bind9 restart) the service stalls on start. Determined that the /etc/nsswitch.conf ldap settings were the point of failure. Restoring the nsswitch.conf setting back to using files temporarily fixed the issue.
The following error occured validating the name "DOMAINHERE":
This condition may be caused by a DNS lookup problem. For information about troubleshooting common DNS lookup problems, please see the following Microsoft Web site: http://go.microsoft.com/fwlink/?LinkId=5171
The specified domain either does not exist or could not be contacted.
The Samba log (/var/log/samba/log.nmdb) gave the error message:
Unable to find the Domain Master Browser name DOMAINHERE<1b> for the workgroup DOMAINHERE.
Unable to sync browse lists in this workgroup.
The resolution is to set the domain logons to yes in the /etc/samba/smb.conf configuration file. Be sure to place the following directive in the [global] section of /etc/samba/smb.conf:
domain logons = yes
When attempting to join a domain from a Windows XP computer the following error is displayed:
The following error occurred attempting to join the domain "DOMAINHERE":
The user name could not be found.
The computer log file generated by Samba (/var/log/samba/log.COMPUTERNAME) gave the error message:
Error: modifications require authentication at /usr/share/perl5/smbldap_tools.pm line 1056.
[2007/04/19 11:06:46, 0] rpc_server/srv_samr_nt.c:_samr_create_user(2415)
_samr_create_user: Running the command /usr/sbin/smbldap-useradd -w "COMPUTERNAME$"' gave 127
Refer here for more details.
Refer to the Useful Commands section below.
While debugging the Samba installation I found the following commands useful for testing purposes.
net use * /DELETE
Deletes local connections; useful for testing multiple users.
net status sessions
Useful for showing sessions on the server. You can see what/who/where the connection is originating from.
For adding users, groups, and adding users to groups the following commands create the necessary entries in the openLDAP
server.
Adding users:
sudo smbldap-useradd -a -m -M george.zappa -c "George Zappa" gzappa
To update/set a users password:
sudo smbldap-passwd gzappa
Creating a group:
sudo smbldap-groupadd SOME_GROUP
To add a user to a group:
smbldap-usermod -G SOME_GROUP gzappa
Comments
thanks...
thanks, that helped me a lot!
regards,
chantal
I want to thank dvogels for
I want to thank dvogels for making this guide that's just work. I think you should have included roaming profile and home share settings in your guide though. I'm guessing it's all related to the same issue.
Why use OpenLDAP and Samba?
Hi,
So I know a few things about technology and I have found a few tutorials about setting up opensource domain controllers, a part of which is configuring OpenLDAP and Samba to work together. My question is this: why are you configuring them to work together? I thought LDAP was supposed to hold user and group information (permissions, etc...) but it seems that this tutorial (and others) are saying let Samba hold that information. So what exactly is OpenLDAP's role after that rather than being a very thin part of the application that is essentially the "doorway" to authentication? Why can't OpenLDAP just holds the user/group information and not use SAMBA?
THANKS!!!
-Brennan Wheeler
Post new comment