LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 03-19-2010, 11:45 AM   #1
ifeatu
Member
 
Registered: Sep 2008
Distribution: Fedora 9
Posts: 68

Rep: Reputation: 15
/BASH script to create Samba users LDAP error


Here is my script :
Code:
#!/bin/bash

#Call the file

processLine(){
#  $SMBPASS = brook123
  line="$@" # get all args
  #  just echo them, but you may need to customize it according to your need
  # for example, F1 will store first field of $line, see readline2 script
  # for more examples
  # F1=$(echo $line | awk '{ print $1 }')
  smbpasswd -e $line -w brook123
  #(echo $SMBPASS; echo $SMBPASS) | smbpasswd -as $line
  #echo -e "$line = $line" >> /etc/samba/smbusers
  echo $line
}

FILE=""

if [ "$1" == "" ]; then
   FILE="/root/scripts/users.txt"
else
   FILE="$1"
   # make sure file exist and readable
   if [ ! -f $FILE ]; then
        echo "$FILE : does not exists"
        exit 1
   elif [ ! -r $FILE ]; then
        echo "$FILE: can not read"
        exit 2
   fi
fi

# Set loop separator to end of line
BAKIFS=$IFS
IFS=$(echo -en "\n\b")
exec 3<&0
exec 0<"$FILE"
while read -r line
do
        # use $line variable to process line in processLine() function
        processLine $line
done
exec 0<&3

# restore $IFS which was used to determine what the field separators are
IFS=$BAKIFS
exit 0
Here is my users.txt file:
Code:
alekich
alice
andra
backuppc
bogus1
colofson
Contreras
dave
domainer
don
dthompson
dthompson_new
elaine
fseto
groberts
inf09$
inf11
I get the following error when it is run:
Code:
ERROR: 'ldap admin dn' not defined! Please check your smb.conf
wbaatin
ERROR: 'ldap admin dn' not defined! Please check your smb.conf
wmadden
...
...
I am NOT using an ldap backend in smb.conf which makes the issue all the more strange
here is my smb.conf
Code:
[global]
workgroup = INMANONE
netbios name = INM_MASTER
passdb backend = tdbsam
hosts allow =  192.168.168. 192.168.1. 127.
cups options = raw
printcap name = cups
add user script = /usr/sbin/useradd -m %u
delete user script = /usr/sbin/userdel -r %u
add group script = /usr/sbin/groupadd %g
delete group script = /usr/sbin/groupdel %g
add user to group script = /usr/sbin/groupmod -A %u %g
delete user from group script = /usr/sbin/groupmod -R %u %g
add machine script = /usr/sbin/useradd -s /bin/false -d /var/lib/nobody %u
# Note: The following specifies the default logon script.
# Per user logon scripts can be specified in the user account using pdbedit
#logon script = scripts\logon.bat
# This sets the default profile path. Set per user paths with pdbedit
logon path = \\%L\Profiles\%U
logon drive = H:
logon home = \\%L\%U
domain logons = Yes
logon script = logon.bat
username map = /etc/samba/smbusers
os level = 65
preferred master = Yes
domain master = Yes
use client driver = yes
admin users = @root
security = user
idmap uid = 15000-20000
idmap gid = 15000-20000
printing = cups

[homes]
path = /home
comment = Home Directories
valid users = %S
read only = No
browseable = yes
create mask = 0600
directory mask = 0700
# Printing auto-share (makes printers available thru CUPS)

[printers]
comment = All Printers
path = /var/spool/samba
printer admin = root, maryo
create mask = 0600
guest ok = Yes
printable = Yes
browseable = No

[print$]
comment = Printer Drivers Share
path = /var/lib/samba/drivers
write list =
printer admin = pmalbrough, root
# Needed to support domain logons

[netlogon]
comment = Network Logon Service
path = /var/lib/samba/netlogon

admin users = pmalbrough, root, administrator
guest ok = Yes
browseable = No
# For profiles to work, create a user directory under the path
# shown. i.e., mkdir -p /var/lib/samba/profiles/maryo

[Profiles]
comment = Network Profiles Share
path = /var/lib/samba/profiles
read only = No
profile acls = Yes
create mask = 0600
directory mask = 0700

[Public]
comment = Public Drive
path = /shares/Public
browseable = yes
read only = no
writeable = yes
create mask = 0777
directory mask = 0755
 
Old 03-19-2010, 12:24 PM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Servers: Debian Squeeze and Wheezy. Desktop: Slackware64 14.0. Netbook: Slackware 13.37
Posts: 8,546
Blog Entries: 28

Rep: Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176Reputation: 1176
I'm not sure I fully understand the script; it has some complex code, apparently to do a simple task. Sorry if I have misunderstood what the script is doing ...

Is the error message coming from smbpasswd -e $line -w brook123? If so it would be very helpful to put an echo in front of it so the actual command generated can be seen: echo smbpasswd -e $line -w brook123

According to the smbpasswd man page the -e option doesn't take a option argument. It may use the modern syntax of accepting non-argument options anywhere on the command line but smbpasswd -e -w brook123 $line would be safer, in case it doesn't.

The only non-option argument that smbpasswd does take is username which must be a single word. The script seems unnecessarily complex regards taking usernames from the users.txt file where they are simply presented, one per line. There is no need for the "exec"ing and IFS setting (and why set the IFS to newline+backspace?!). This simpler code should be all that is required (not tested)
Code:
IFS= while read -r user
do
        processLine "$user"
done < $FILE
and the processLine function (which could more aptly be called processUser) could more simply be
Code:
processLine(){
  smbpasswd -e -w brook123 "$1"
}
 
Old 03-19-2010, 12:34 PM   #3
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,513

Rep: Reputation: 1895Reputation: 1895Reputation: 1895Reputation: 1895Reputation: 1895Reputation: 1895Reputation: 1895Reputation: 1895Reputation: 1895Reputation: 1895Reputation: 1895
Just to tack on the end of the good advice already given, your error would seem to be directly related to the -w option
you are using, see direct quote from man smbpasswd

Quote:
-w password
This parameter is only available if Samba has been compiled with LDAP support. The -w switch is used to specify the password to be used with the ldap admin
dn. Note that the password is stored in the secrets.tdb and is keyed off of the adminīs DN. This means that if the value of ldap admin dn ever changes, the
password will need to be manually updated as well.
 
Old 03-19-2010, 06:55 PM   #4
ifeatu
Member
 
Registered: Sep 2008
Distribution: Fedora 9
Posts: 68

Original Poster
Rep: Reputation: 15
-w option

It was in fact the -w option that was giving me grief...I do plan to use ldap as a back end just not yet/ I'm sure I'll have more questions once that process begins
 
Old 03-21-2010, 04:58 AM   #5
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,513

Rep: Reputation: 1895Reputation: 1895Reputation: 1895Reputation: 1895Reputation: 1895Reputation: 1895Reputation: 1895Reputation: 1895Reputation: 1895Reputation: 1895Reputation: 1895
Don't forget to mark as SOLVED
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do I create linux and samba users with a script? replica88 Linux - General 3 06-07-2011 04:22 PM
Vpopmail ldap to samba ldap users luquee Linux - Software 1 07-23-2008 11:38 AM
Bash Script Help - Trying to create a variable inside script when run. webaccounts Linux - Newbie 1 06-09-2008 02:40 PM
Samba Server w/ LDAP Users haydenyoung Linux - Server 0 09-25-2007 05:39 AM
Samba, LDAP, do I need smbpasswd to create users? yuri_d Linux - Server 2 07-25-2007 07:46 AM


All times are GMT -5. The time now is 05:00 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration