Re: [Samba] Samba4 Patch: newuseradv and newgroupadv scripts for net cmd utlity

2010-05-27 Thread Michael Wood
Hi

On 27 May 2010 00:06, Lukasz Zalewski lu...@dcs.qmul.ac.uk wrote:
 Hi all,
 As per Jelmer's request - in response to bug #7455 attached diff file.
 Please let me know what you think and if any modificationes need to be
 performed


 Regards

 Luk

I think samba-technical is a better place to post this.

-- 
Michael Wood esiot...@gmail.com
--- samba/netcmd/__init__.py.org2010-05-25 17:28:00.0 +0100
+++ samba/netcmd/__init__.py2010-05-26 11:43:16.0 +0100
@@ -160,3 +160,7 @@
 commands[vampire] = cmd_vampire()
 from samba.netcmd.machinepw import cmd_machinepw
 commands[machinepw] = cmd_machinepw()
+from samba.netcmd.newuseradv import cmd_newuseradv
+commands[newuseradv] = cmd_newuseradv()
+from samba.netcmd.newgroupadv import cmd_newgroupadv
+commands[newgroupadv] = cmd_newgroupadv()
--- samba/samdb.py.org  2010-05-25 13:12:16.0 +0100
+++ samba/samdb.py  2010-05-26 21:34:11.0 +0100
@@ -140,6 +140,158 @@
 else:
 self.transaction_commit()
 
+def newgroupadv(self, groupname, groupou=None, grouptype=None,
+description=None, mailaddress=None, notes=None):
+Adds a new group with additional parameters
+
+:param groupname: Name of the new group
+:param grouptype: Type of the new group
+:param description: Description of the new group
+:param mailaddress: Email address of the new group
+:param notes: Notes of the new group
+
+
+self.transaction_start()
+try:
+group_dn = CN=%s,%s,%s % (groupname, (groupou or CN=Users), 
self.domain_dn())
+
+# The new user record. Note the reliance on the SAMLDB module which
+# fills in the default informations
+   ldbmessage = {dn: group_dn,
+sAMAccountName: groupname,
+objectClass: group}
+   
+   if grouptype is not None:
+ldbmessage[groupType] = %d % ((grouptype)-2**32)
+
+if description is not None:
+ldbmessage[description] = description
+
+if mailaddress is not None:
+ldbmessage[mail] = mailaddress
+
+if notes is not None:
+ldbmessage[info] = notes
+
+self.add(ldbmessage)
+
+except:
+self.transaction_cancel()
+raise
+else:
+self.transaction_commit()
+
+def newuseradv(self, username, password,
+force_password_change_at_next_login_req=False,
+   userou=None, surname=None, givenname=None, initials=None,
+   profilepath=None, scriptpath=None, homedrive=None, 
homedirectory=None,
+   jobtitle=None, department=None, company=None, description=None,
+   mailaddress=None, internetaddress=None, telephonenumber=None,
+   physicaldeliveryoffice=None):
+Adds a new user with additional parameters
+
+:param username: Name of the new user
+:param password: Password for the new user
+:param force_password_change_at_next_login_req: Force password change
+:param userou: Object container (without domainDN postfix) for new user
+:param surname: Surname of the new user
+:param givenname: First name of the new user
+:param initials: Initials of the new user
+:param profilepath: Profile path of the new user
+:param scriptpath: Logon script path of the new user
+:param homedrive: Home drive of the new user
+:param homedirectory: Home directory of the new user
+:param jobtitle: Job title of the new user
+:param department: Department of the new user
+:param company: Company of the new user
+:param description: of the new user
+:param mailaddress: Email address of the new user
+:param internetaddress: Home page of the new user
+:param telephonenumber: Phone number of the new user
+:param physicaldeliveryoffice: Office location of the new user
+   
+
+displayName = ;
+if givenname is not None:
+displayName += givenname
+
+if initials is not None:
+displayName += ' %s.' % initials
+
+if surname is not None:
+displayName += ' %s' % surname
+
+self.transaction_start()
+try:
+user_dn = CN=%s,%s,%s % (username, (userou or CN=Users), 
self.domain_dn())
+
+# The new user record. Note the reliance on the SAMLDB module which
+# fills in the default informations
+   ldbmessage = {dn: user_dn,
+sAMAccountName: username,
+objectClass: user}
+   
+   if surname is not None:
+ldbmessage[sn] = surname
+
+   if givenname is not None:
+ldbmessage[givenName] = givenname
+
+   if displayName is not :
+ldbmessage[displayName] = 

[Samba] Samba4 Patch: newuseradv and newgroupadv scripts for net cmd utlity

2010-05-26 Thread Lukasz Zalewski

Hi all,
As per Jelmer's request - in response to bug #7455 attached diff file. 
Please let me know what you think and if any modificationes need to be 
performed



Regards

Luk
--- samba/netcmd/__init__.py.org2010-05-25 17:28:00.0 +0100
+++ samba/netcmd/__init__.py2010-05-26 11:43:16.0 +0100
@@ -160,3 +160,7 @@
 commands[vampire] = cmd_vampire()
 from samba.netcmd.machinepw import cmd_machinepw
 commands[machinepw] = cmd_machinepw()
+from samba.netcmd.newuseradv import cmd_newuseradv
+commands[newuseradv] = cmd_newuseradv()
+from samba.netcmd.newgroupadv import cmd_newgroupadv
+commands[newgroupadv] = cmd_newgroupadv()
--- samba/samdb.py.org  2010-05-25 13:12:16.0 +0100
+++ samba/samdb.py  2010-05-26 21:34:11.0 +0100
@@ -140,6 +140,158 @@
 else:
 self.transaction_commit()
 
+def newgroupadv(self, groupname, groupou=None, grouptype=None,
+description=None, mailaddress=None, notes=None):
+Adds a new group with additional parameters
+
+:param groupname: Name of the new group
+:param grouptype: Type of the new group
+:param description: Description of the new group
+:param mailaddress: Email address of the new group
+:param notes: Notes of the new group
+
+
+self.transaction_start()
+try:
+group_dn = CN=%s,%s,%s % (groupname, (groupou or CN=Users), 
self.domain_dn())
+
+# The new user record. Note the reliance on the SAMLDB module which
+# fills in the default informations
+   ldbmessage = {dn: group_dn,
+sAMAccountName: groupname,
+objectClass: group}
+   
+   if grouptype is not None:
+ldbmessage[groupType] = %d % ((grouptype)-2**32)
+
+if description is not None:
+ldbmessage[description] = description
+
+if mailaddress is not None:
+ldbmessage[mail] = mailaddress
+
+if notes is not None:
+ldbmessage[info] = notes
+
+self.add(ldbmessage)
+
+except:
+self.transaction_cancel()
+raise
+else:
+self.transaction_commit()
+
+def newuseradv(self, username, password,
+force_password_change_at_next_login_req=False,
+   userou=None, surname=None, givenname=None, initials=None,
+   profilepath=None, scriptpath=None, homedrive=None, 
homedirectory=None,
+   jobtitle=None, department=None, company=None, description=None,
+   mailaddress=None, internetaddress=None, telephonenumber=None,
+   physicaldeliveryoffice=None):
+Adds a new user with additional parameters
+
+:param username: Name of the new user
+:param password: Password for the new user
+:param force_password_change_at_next_login_req: Force password change
+:param userou: Object container (without domainDN postfix) for new user
+:param surname: Surname of the new user
+:param givenname: First name of the new user
+:param initials: Initials of the new user
+:param profilepath: Profile path of the new user
+:param scriptpath: Logon script path of the new user
+:param homedrive: Home drive of the new user
+:param homedirectory: Home directory of the new user
+:param jobtitle: Job title of the new user
+:param department: Department of the new user
+:param company: Company of the new user
+:param description: of the new user
+:param mailaddress: Email address of the new user
+:param internetaddress: Home page of the new user
+:param telephonenumber: Phone number of the new user
+:param physicaldeliveryoffice: Office location of the new user
+   
+
+displayName = ;
+if givenname is not None:
+displayName += givenname
+
+if initials is not None:
+displayName += ' %s.' % initials
+
+if surname is not None:
+displayName += ' %s' % surname
+
+self.transaction_start()
+try:
+user_dn = CN=%s,%s,%s % (username, (userou or CN=Users), 
self.domain_dn())
+
+# The new user record. Note the reliance on the SAMLDB module which
+# fills in the default informations
+   ldbmessage = {dn: user_dn,
+sAMAccountName: username,
+objectClass: user}
+   
+   if surname is not None:
+ldbmessage[sn] = surname
+
+   if givenname is not None:
+ldbmessage[givenName] = givenname
+
+   if displayName is not :
+ldbmessage[displayName] = displayName
+ldbmessage[name] = displayName
+
+   if initials is not None:
+ldbmessage[initials] = '%s.' % initials
+
+   if