#!/usr/bin/perl
$|++;
use strict;
use warnings;
use Net::LDAP;
require "cliebow.pm";
use vars qw($sid $rootpw $rootdn $ip $ldapserver $dn $attr @allusers @newstudents %mysmb $lastuid $ldap $gecos $username $mesg $year $uid $firstname $lastname $pw $user);
#parse smb.conf and make a hash of it
	%mysmb=&read_conf();
	$dn=$mysmb{"ldap suffix"};
	$rootdn="cn=root,$dn";#dc=ehs.dc=ellsworthschools.dc=org";
	$ip="localhost";
	$ldapserver="localhost";
	$attr="cn";
#get the pw from ldap.secret
	&getldap_pw;

#get the sid
	&getsid;
#get next usable uid number
	&lastuid;
#reads newusers from a file into @newstudents
	&readfile("/var/www/admin/students");
#Lets split on commas
	foreach my $yoyo (@newstudents){
		my @users=split(",","$yoyo");
	 $firstname=$users[0];
	 $lastname=$users[1];
	 $gecos=join(" ",$firstname,$lastname);
	$year=$users[2];
	$pw=$users[3];
	$username=$users[4];	
print "$gecos\n"
}
my $groupsid=join("-",$sid,$lastuid);
chomp $groupsid;	
	print "$groupsid\n";
	print "$username\n";
	print "$dn\n";
	print "$year\n";
	print "$rootdn\n";
	print "$rootpw\n";
	print "$pw\n";
	print "$lastuid\n";
	$user="cn=$username,ou=$year,ou=Students,ou=People,$dn";
	print "user-->$user\n";
#Wait here before going on#####################################
	my $waitasec=readline(*STDIN);

#bind to ldap as root
	$ldap = Net::LDAP->new("$ldapserver") or die "$@";
	$ldap->bind("$rootdn",password=>"$rootpw");
	$mesg = $ldap->add($user,attrs=> 
	['sambaLMPassword'=>'1461E145A27938EDAAD3B435B51404EE',	
	'sambaPrimaryGroupSID'=>"$groupsid",
	'displayName'=>"$gecos",
	'givenName'=>"$firstname",
	'objectClass'=>['top','inetOrgPerson','posixAccount','sambaSamAccount'],
	'cn'=>"$username",
	'userPassword'=>'{SHA}rj6QQrUzqVP1AnjSPSwN+wuRWWM=',
	'sambaLogonTime'=>'0',
	'sambaHomeDrive'=>'P:',
	'uid'=>"$username",
	'mail'=>"$username\@ellsworthschools.org",
	'uidNumber'=>"$lastuid",
	'sambaLogoffTime'=>'2147483647',
	'sambaPwdLastSet'=>'1128449072',
	'loginShell'=>'/bin/bash',
	'sambaAcctFlags'=>'[UX]',
	'sambaProfilePath'=>"\\\\puffin\\profiles\\$username",
	'gidNumber'=>"$year",
	'sambaPwdMustChange'=>'0',
	'sambaNTPassword'=>"4B08AE009324CE883AD7C42735F8CE2C",
	'sambaPwdCanChange'=>'1128449072',
	'gecos'=>"$gecos",
	'sambaSID'=>"$groupsid",
	'description'=>"$gecos",
	'homeDirectory'=>"/home/$year/$username",
	'sambaKickoffTime'=>"2147483647",
	'sn'=>"$lastname",
	'sambaHomePath'=>'\\\\puffin\\homes',
	]
	);	
	$mesg = $ldap->unbind;
#increment uid
#reset uid in sambaDomainNames



