> ich would like to use the Samba-Server as an PDC for a school.
> Because of the high numbers of students it is not possible for us to add
> ervery student by hand an think about a pw.
> Has anyone designed a script which read the users from an ASCII-file and
> add's them to the samba?
>
> Regards,
>
> Michael Lechner
I have for the same purpose created two little perl-scripts which read
from standard in. The first creates accounts for pupils, the other for
teacher.
I create 40 accounts per class:
#! /usr/bin/perl
open( PASSWD, "./passwdGen.sh| " );
$lastUID = 7976;
@usersPre = <STDIN>;
$lastUID++;
foreach $userMark ( @usersPre ) {
chop( $userMark );
for( $i=1; $i <= 40; $i++ ) {
print "dn: cn=$userMark-$i,dc=my-org,dc=schule\n";
#print "dn: cn=$userMark-03-$i,dc=my-org,dc=schule\n";
print "objectclass: posixAccount\n";
print "objectclass: account\n";
print "objectclass: mailRecipient\n";
print "cn: $userMark-$i\n";
#print "cn: $userMark-03-$i\n";
print "uid: $userMark-$i\n";
#print "uid: $userMark-03-$i\n";
print "uidNumber: $lastUID\n";
print "gidNumber: 500\n";
print "homeDirectory: /home/schueler/$userMark-$i\n";
print "loginShell: /bin/false\n";
print "mail: $userMark-$i\@my-domain.de\n";
print "mailLocalAddress:
$userMark-$i\@fileserver.my-org.schule\n";
print "mailDeliveryOption: accept\n";
print "description: schueler\n";
print "\n";
$lastUID++;
}
}
Creating the teacher-accounts is nearly the same, except for the gid and
the for-loop.
It creates the ldif, so I can just have a quick look at it, befor I
ldapadd it.
After the entries are added, I add the sambaSamAccount:
#! /usr/bin/perl
open( PASSWD, "/root/createUser/passwdGen.sh| " );
@usersPre = <STDIN>;
foreach $userMark ( @usersPre ) {
chop( $userMark );
for( $i=1; $i <= 40; $i++ ) {
open( PASSWD, "./passwdGen.sh| " );
$pass = <PASSWD>;
chop( $pass );
print "#\n";
print "#$userMark-03-$i \t \t $pass \n";
print "#--------------------------------\n";
system( "ldappasswd -D cn=root,dc=my-org,dc=schule -x -w
\"insecure-way!\" -s \"$pass\"
cn=$userMark-03-$i,dc=my-org,dc=schule" ) && die
"unexpected ldappasswd error";
system( "/opt/samba3/bin/smbpasswd -a $userMark-03-$i
\"$pass\"" ) && die "unexpected smbpasswd
error";
system( "/usr/local/samba/bin/pdbedit -u $userMark-03-$i
-d P:") && die "unexpected pdbedit homedrive error";
system( "/usr/local/samba/bin/pdbedit -u $userMark-03-$i
-h \\\\fileserver\\$userMark-03-$i" ) && die "unexpected
pdbedit homedir error";
system( "mkdir /home/schueler/$userMark-03-$i" )
&& die
"unexpected mkdir error";
system( "chown $userMark-03-$i
/home/schueler/$userMark-03-$i" )
&& die "unexpected chown error";
system( "chgrp lehrer /home/schueler/$userMark-03-$i"
) &&
die "unexpected chgrp error";
system( "chmod 770 /home/schueler/$userMark-03-$i" )
&&
die "unexpected chmod error";
}
}
The passwdgen.sh is simply:
#!/bin/bash
/root/bin/apg -a 0 -M cn -E 0O1lI -n 1 -m 8 -x 8
which uses apg (Advanced Password Generator) to create somewhat secure
passwords which are readable and easy to remember (I don't let the users
change their passwords).
Have fun,
Malte M?ller
BBS1 Emden