From: Marc 'HE' Brockschmidt Date: Tue, 25 Dec 2007 17:32:43 +0000 (+0100) Subject: Really apply HE's changes. X-Git-Tag: userdir-ldap-0.3.16~20^2~4 X-Git-Url: https://git.adam-barratt.org.uk/?p=mirror%2Fuserdir-ldap.git;a=commitdiff_plain;h=9f96588735e6d2c3ff733a4de3920399585a3b2e;hp=d30df594d92c8a503be5bdc7e9f9b1d18226f726 Really apply HE's changes. --- diff --git a/ud-host b/ud-host index 4ba0571..ebcaa05 100755 --- a/ud-host +++ b/ud-host @@ -50,8 +50,10 @@ AttrInfo = {"description": ["Machine Descr.", 1], "machine": ["Machine Hardware", 10], "memory": ["Memory", 11], "disk": ["Disk", 12], + "physicalHost": ["Physical Host", 13], "sshRSAHostKey": ["SSH Host Keys", 14], - "bandwidth": ["Bandwidth", 15]}; + "bandwidth": ["Bandwidth", 15], + "purpose": ["Purposes", 16],}; AttrPrompt = {"description": ["Purpose of the machine"], "hostname": ["The hostnames for the box (ipv4/ipv6)"], @@ -65,8 +67,10 @@ AttrPrompt = {"description": ["Purpose of the machine"], "machine": ["Hardware description"], "memory": ["Installed RAM"], "disk": ["Disk Space, RAID levels, etc"], + "physicalHost": ["The box hosting this virtual server"], "sshRSAHostKey": ["A copy of /etc/ssh/ssh_*host_key.pub"], - "bandwidth": ["Available outbound"]}; + "bandwidth": ["Available outbound"], + "purpose": ["The purposes of this host"],}; # Create a map of IDs to desc,value,attr OrderedIndex = {}; @@ -128,7 +132,7 @@ def Overview(Attrs): # Change a single attribute def ChangeAttr(Attrs,Attr): - if (Attr == "sponsor" or Attr == "sshRSAHostKey"): + if (Attr in ["sponsor", "sshRSAHostKey", "purpose"]): return MultiChangeAttr(Attrs,Attr); print "Old value: '%s'" % (GetAttr(Attrs,Attr,"")); @@ -242,10 +246,8 @@ else: l = ldap.open(LDAPServer); l.simple_bind_s("","") -HBaseDn = HostBaseDn - if ListMode == 1: - Attrs = l.search_s(HBaseDn,ldap.SCOPE_ONELEVEL,"host=*") + Attrs = l.search_s(HostBaseDn,ldap.SCOPE_ONELEVEL,"host=*") hosts = [] for hAttrs in Attrs: hosts.append(hAttrs[1]['host'][0]) @@ -260,9 +262,9 @@ if ListMode == 1: sys.exit(0) elif FingerPrints == 1: if Host is not None: - Attrs = l.search_s(HBaseDn,ldap.SCOPE_ONELEVEL,"host=" + Host) + Attrs = l.search_s(HostBaseDn,ldap.SCOPE_ONELEVEL,"host=" + Host) else: - Attrs = l.search_s(HBaseDn,ldap.SCOPE_ONELEVEL,"host=*") + Attrs = l.search_s(HostBaseDn,ldap.SCOPE_ONELEVEL,"host=*") hosts = [] for hAttrs in Attrs: hosts.append(hAttrs[1]['host'][0]) @@ -285,10 +287,10 @@ elif FingerPrints == 1: os.unlink(tmpfile) sys.exit(0) -HostDn = "host=" + Host + "," + HBaseDn; +HostDn = "host=" + Host + "," + HostBaseDn; # Query the server for all of the attributes -Attrs = l.search_s(HBaseDn,ldap.SCOPE_ONELEVEL,"host=" + Host); +Attrs = l.search_s(HostBaseDn,ldap.SCOPE_ONELEVEL,"host=" + Host); if len(Attrs) == 0: print "Host",Host,"was not found."; sys.exit(0); @@ -317,13 +319,13 @@ while(1): NewHost = raw_input("Host? "); if NewHost == "": continue; - NAttrs = l.search_s(HBaseDn,ldap.SCOPE_ONELEVEL,"host=" + NewHost); + NAttrs = l.search_s(HostBaseDn,ldap.SCOPE_ONELEVEL,"host=" + NewHost); if len(NAttrs) == 0: print "Host",NewHost,"was not found."; continue; Attrs = NAttrs; Host = NewHost; - HostDn = "host=" + Host + "," + HBaseDn; + HostDn = "host=" + Host + "," + HostBaseDn; OrderedIndex = copy.deepcopy(OrigOrderedIndex); continue; @@ -332,26 +334,26 @@ while(1): NewHost = raw_input("Host? "); if NewHost == "": continue; - NAttrs = l.search_s(HBaseDn,ldap.SCOPE_ONELEVEL,"host=" + NewHost); + NAttrs = l.search_s(HostBaseDn,ldap.SCOPE_ONELEVEL,"host=" + NewHost); if len(NAttrs) != 0: print "Host",NewHost,"already exists."; continue; NewHostName = raw_input("Hostname? "); if NewHost == "": continue; - Dn = "host=" + NewHost + "," + HBaseDn; + Dn = "host=" + NewHost + "," + HostBaseDn; l.add_s(Dn,[("host", NewHost), ("hostname", NewHostName), ("objectClass", ("top", "debianServer"))]); # Switch - NAttrs = l.search_s(HBaseDn,ldap.SCOPE_ONELEVEL,"host=" + NewHost); + NAttrs = l.search_s(HostBaseDn,ldap.SCOPE_ONELEVEL,"host=" + NewHost); if len(NAttrs) == 0: print "Host",NewHost,"was not found."; continue; Attrs = NAttrs; Host = NewHost; - HostDn = "host=" + Host + "," + HBaseDn; + HostDn = "host=" + Host + "," + HostBaseDn; OrderedIndex = copy.deepcopy(OrigOrderedIndex); continue; diff --git a/ud-useradd b/ud-useradd index 419ae6a..98cf8cb 100755 --- a/ud-useradd +++ b/ud-useradd @@ -33,22 +33,30 @@ from userdir_gpg import *; # search through all UIDs. def GetFreeID(l): Attrs = l.search_s(BaseDn,ldap.SCOPE_ONELEVEL, - "uidNumber=*",["uidNumber"]); + "uidNumber=*",["uidNumber", "gidNumber"]); HighestUID = 0; + gids = []; for I in Attrs: ID = int(GetAttr(I,"uidNumber","0")); + gids.append(int(GetAttr(I, "gidNumber","0"))) if ID > HighestUID: HighestUID = ID; - return HighestUID + 1; + + resGID = HighestUID + 1; + while resGID in gids: + resGID += 1 + + return (HighestUID + 1, resGID); # Main starts here AdminUser = pwd.getpwuid(os.getuid())[0]; # Process options ForceMail = 0; +NoAutomaticIDs = 0; OldGPGKeyRings = GPGKeyRings; userdir_gpg.GPGKeyRings = []; -(options, arguments) = getopt.getopt(sys.argv[1:], "u:ma") +(options, arguments) = getopt.getopt(sys.argv[1:], "u:man") for (switch, val) in options: if (switch == '-u'): AdminUser = val; @@ -56,6 +64,8 @@ for (switch, val) in options: ForceMail = 1; elif (switch == '-a'): userdir_gpg.GPGKeyRings = OldGPGKeyRings; + elif (switch == '-n'): + NoAutomaticIDs = 1; l = passwdAccessLDAP(LDAPServer, BaseDn, AdminUser) @@ -91,7 +101,7 @@ email = Addr[1] + '@' + Addr[2]; account = Addr[1]; privsub = email; -gidNumber = str(DefaultGID); +gidNumber = 0; uidNumber = 0; # Decide if we should use IDEA encryption @@ -157,14 +167,28 @@ Res = raw_input("Subscribe to debian-private (space is none) [" + privsub + "]? if Res != "": privsub = Res; -# GID -Res = raw_input("Group ID Number [" + gidNumber + "]? "); -if Res != "": - gidNumber = Group2GID(l, Res); +(uidNumber, generatedGID) = GetFreeID(l, RoleAccount) +if not gidNumber: + gidNumber = DefaultGID +UserGroup = 0 -# UID -if uidNumber == 0: - uidNumber = GetFreeID(l); +if NoAutomaticIDs: + # UID + if not Update: + Res = raw_input("User ID Number [%s]? " % (uidNumber)); + if Res != "": + uidNumber = Res; + + # GID + Res = raw_input("Group ID Number (default group is %s, new usergroup %s) [%s]" % (DefaultGID, generatedGID, gidNumber)); + if Res != "": + if Res.isdigit(): + gidNumber = Res; + else: + gidNumber = Group2GID(l, Res); + + if gidNumber == generatedGID: + UserGroup = 1 # Generate a random password if Update == 0 or ForceMail == 1: @@ -243,6 +267,12 @@ if Update == 0: Details.append(("mn",mn)); if privsub != " ": Details.append(("privateSub",privsub)) + + #Add user group if needed, then the actual user: + if UserGroup == 1: + Dn = "gid=" + account + "," + BaseDn; + l.add_s(Dn,[("gid",account), ("gidNumber",str(gidNumber)), ("objectClass",("top", "debianGroup"))]); + l.add_s(Dn,Details); else: # Modification diff --git a/userdir-ldap.schema b/userdir-ldap.schema index 32e679f..d089f0b 100644 --- a/userdir-ldap.schema +++ b/userdir-ldap.schema @@ -1,7 +1,8 @@ # Revision history: # -# XXX [PP] -# - Now version controlled in db.d.o bzr repository - 2007-12-25 +# XXX +# - [PP] Now version controlled in db.d.o bzr repository - 2007-12-25 +# - [HE] Add 'purpose', 'physicalHost' to debianServer - 2007-12-25 # # 0.7 [RM] # - Add 'gender' and 'birthDate' to debianDeveloper @@ -93,6 +94,8 @@ # .30 - gender # .31 - birthdate # .32 - mailDisableMessage +# .33 - purpose +# .34 - physicalHost # # .3 - experimental LDAP objectClasses # .1 - debianDeveloper @@ -332,6 +335,21 @@ attributetype ( 1.3.6.1.4.1.9586.100.4.2.32 SUBSTR caseIgnoreIA5SubstringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.26 SINGLE-VALUE ) +attributetype ( 1.3.6.1.4.1.9586.100.4.2.33 + NAME 'purpose' + DESC 'purposes of this server' + EQUALITY caseIgnoreMatch + SUBSTR caseIgnoreSubstringsMatch + SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 ) + +attributetype ( 1.3.6.1.4.1.9586.100.4.2.34 + NAME 'physicalHost' + DESC 'FQDN of the physical host of this virtual server' + EQUALITY caseIgnoreIA5Match + SUBSTR caseIgnoreIA5SubstringsMatch + SINGLE-VALUE + SYNTAX 1.3.6.1.4.1.1466.115.121.1.26{256} ) + # Public object classes objectclass ( 1.3.6.1.4.1.9586.100.4.1.1 @@ -457,7 +475,7 @@ objectclass ( 1.3.6.1.4.1.9586.100.4.3.2 MUST ( host $ hostname ) MAY ( c $ access $ admin $ architecture $ bandwidth $ description $ disk $ distribution $ l $ machine $ memory $ sponsor $ - sponsor-admin $ sshRSAHostKey $ status + sponsor-admin $ sshRSAHostKey $ status $ purpose $ physicalHost ) ) objectclass ( 1.3.6.1.4.1.9586.100.4.3.3