X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=ud-generate;h=943da311577e1c64e25691f8bd95d96c2dea52d7;hb=29816c66079debfbaaa183bd46466698ce4d29fd;hp=29517947a413e1a27e44ca49195704f84e5b9a79;hpb=55e97da44178f34579c61a212dcb493c3100c428;p=mirror%2Fuserdir-ldap.git diff --git a/ud-generate b/ud-generate index 2951794..943da31 100755 --- a/ud-generate +++ b/ud-generate @@ -39,6 +39,10 @@ except ImportError: global Allowed global CurrentHost +if os.getuid() == 0: + sys.stderr.write("You should probably not run ud-generate as root.\n") + sys.exit(1) + PasswdAttrs = None DebianUsers = None DisabledUsers = [] @@ -1072,9 +1076,14 @@ def GenKeyrings(OutDir): # Connect to the ldap server l = connectLDAP() -F = open(PassDir + "/pass-" + pwd.getpwuid(os.getuid())[0], "r") -Pass = F.readline().strip().split(" ") -F.close() +# for testing purposes it's sometimes useful to pass username/password +# via the environment +if 'UD_CREDENTIALS' in os.environ: + Pass = os.environ['UD_CREDENTIALS'].split() +else: + F = open(PassDir + "/pass-" + pwd.getpwuid(os.getuid())[0], "r") + Pass = F.readline().strip().split(" ") + F.close() l.simple_bind_s("uid=" + Pass[0] + "," + BaseDn, Pass[1]) # Fetch all the groups @@ -1119,6 +1128,10 @@ if HostAttrs == None: HostAttrs.sort(lambda x, y: cmp((GetAttr(x, "hostname")).lower(), (GetAttr(y, "hostname")).lower())) +# override globaldir for testing +if 'UD_GENERATEDIR' in os.environ: + GenerateDir = os.environ['UD_GENERATEDIR'] + # Generate global things GlobalDir = GenerateDir + "/" GenDisabledAccounts(GlobalDir + "disabled-accounts")