Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
--- upgrade.py.orig 2014-03-19 13:41:09.000000000 -0700
+++ upgrade.py 2014-04-17 13:40:31.129417325 -0700
@@ -93,9 +93,10 @@
except ldb.LdbError, e:
logger.warn("Could not set account policy, (%s)", str(e))
-
+# Modified to support importing LDAP attributes -- JTY
def add_posix_attrs(logger, samdb, sid, name, nisdomain, xid_type, home=None,
- shell=None, pgid=None):
+ shell=None, pgid=None, gname=None, sname=None, title=None, room=None,
+ pobox=None, mail=None, phone=None, fax=None):
"""Add posix attributes for the user/group
:param samdb: Samba4 sam.ldb database
@@ -106,6 +107,15 @@
:param home: user homedir (Unix homepath)
:param shell: user shell
:param pgid: users primary group id
+ # Added to support importing LDAP attributes -- JTY
+ :param gname: users given name
+ :param sname: users surname
+ :param title: users title
+ :param room: users office number
+ :param pobox: users mailbox
+ :param mail: users email address
+ :param phone: users phone number
+ :param fax: users fax number
"""
try:
@@ -118,6 +128,31 @@
str(shell), ldb.FLAG_MOD_REPLACE, 'loginShell')
m['gidNumber'] = ldb.MessageElement(
str(pgid), ldb.FLAG_MOD_REPLACE, 'gidNumber')
+ # Added to support importing LDAP attributes -- JTY
+ if gname != '':
+ m['givenName'] = ldb.MessageElement(
+ str(gname), ldb.FLAG_MOD_ADD, 'givenName')
+ if sname != '':
+ m['sn'] = ldb.MessageElement(
+ str(sname), ldb.FLAG_MOD_ADD, 'sn')
+ if title != '':
+ m['title'] = ldb.MessageElement(
+ str(title), ldb.FLAG_MOD_ADD, 'title')
+ if room != '':
+ m['physicalDeliveryOfficeName'] = ldb.MessageElement(
+ str(room), ldb.FLAG_MOD_ADD, 'physicalDeliveryOfficeName')
+ if pobox != '':
+ m['postOfficeBox'] = ldb.MessageElement(
+ str(pobox), ldb.FLAG_MOD_ADD, 'postOfficeBox')
+ if mail != '':
+ m['mail'] = ldb.MessageElement(
+ str(mail), ldb.FLAG_MOD_ADD, 'mail')
+ if phone != '':
+ m['telephoneNumber'] = ldb.MessageElement(
+ str(phone), ldb.FLAG_MOD_ADD, 'telephoneNumber')
+ if fax != '':
+ m['facsimileTelephoneNumber'] = ldb.MessageElement(
+ str(fax), ldb.FLAG_MOD_ADD, 'facsimileTelephoneNumber')
m['msSFU30NisDomain'] = ldb.MessageElement(
str(nisdomain), ldb.FLAG_MOD_REPLACE, 'msSFU30NisDomain')
@@ -788,6 +823,16 @@
homes = {}
shells = {}
pgids = {}
+ # Added to support importing LDAP attributes -- JTY
+ gnames = {}
+ faxnumbers = {}
+ mails = {}
+ poboxes = {}
+ rooms = {}
+ snames = {}
+ phonenumbers = {}
+ titles = {}
+
if ldap:
creds = Credentials()
creds.guess(samba3.lp)
@@ -835,6 +880,70 @@
pass
except IndexError:
pass
+ # Added to support importing LDAP attributes -- JTY
+ try:
+ if ldap:
+ gnames[username] = get_posix_attr_from_ldap_backend(logger, ldb_object, base_dn, username, "givenName")
+ except KeyError:
+ pass
+ except IndexError:
+ pass
+
+ try:
+ if ldap:
+ faxnumbers[username] = get_posix_attr_from_ldap_backend(logger, ldb_object, base_dn, username, "facsimileTelephoneNumber")
+ except KeyError:
+ pass
+ except IndexError:
+ pass
+
+ try:
+ if ldap:
+ mails[username] = get_posix_attr_from_ldap_backend(logger, ldb_object, base_dn, username, "mail")
+ except KeyError:
+ pass
+ except IndexError:
+ pass
+
+ try:
+ if ldap:
+ poboxes[username] = get_posix_attr_from_ldap_backend(logger, ldb_object, base_dn, username, "postOfficeBox")
+ except KeyError:
+ pass
+ except IndexError:
+ pass
+
+ try:
+ if ldap:
+ rooms[username] = get_posix_attr_from_ldap_backend(logger, ldb_object, base_dn, username, "roomNumber")
+ except KeyError:
+ pass
+ except IndexError:
+ pass
+
+ try:
+ if ldap:
+ snames[username] = get_posix_attr_from_ldap_backend(logger, ldb_object, base_dn, username, "sn")
+ except KeyError:
+ pass
+ except IndexError:
+ pass
+
+ try:
+ if ldap:
+ phonenumbers[username] = get_posix_attr_from_ldap_backend(logger, ldb_object, base_dn, username, "telephoneNumber")
+ except KeyError:
+ pass
+ except IndexError:
+ pass
+
+ try:
+ if ldap:
+ titles[username] = get_posix_attr_from_ldap_backend(logger, ldb_object, base_dn, username, "title")
+ except KeyError:
+ pass
+ except IndexError:
+ pass
logger.info("Reading WINS database")
samba3_winsdb = None
@@ -936,7 +1045,8 @@
if (username in homes) and (homes[username] is not None) and \
(username in shells) and (shells[username] is not None) and \
(username in pgids) and (pgids[username] is not None):
- add_posix_attrs(samdb=result.samdb, sid=userdata[username].user_sid, name=username, nisdomain=domainname.lower(), xid_type="ID_TYPE_UID", home=homes[username], shell=shells[username], pgid=pgids[username], logger=logger)
+ # Modified to support importing LDAP attributes -- JTY
+ add_posix_attrs(samdb=result.samdb, sid=userdata[username].user_sid, name=username, nisdomain=domainname.lower(), xid_type="ID_TYPE_UID", home=homes[username], shell=shells[username], pgid=pgids[username], logger=logger, gname=gnames.get(username,''), sname=snames.get(username,''), title=titles.get(username,''), room=rooms.get(username,''), pobox=poboxes.get(username,''), mail=mails.get(username,''), phone=phonenumbers.get(username,''), fax=faxnumbers.get(username,''))
except:
# We need this, so that we do not give even more errors due to not cancelling the transaction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment