Exit if no GnuPG key has been entered
[mirror/userdir-ldap.git] / ud-useradd
index 009bdd3..829d707 100755 (executable)
@@ -40,19 +40,28 @@ for (switch, val) in options:
       userdir_gpg.GPGKeyRings = OldGPGKeyRings;
 
 print "Accessing LDAP directory as '" + AdminUser + "'";
-Password = getpass(AdminUser + "'s password: ");
+while (1):
+   Password = getpass(AdminUser + "'s password: ");
+
+   if len(Password) == 0:
+      sys.exit(0)
 
-# Connect to the ldap server
-l = ldap.open(LDAPServer);
-UserDn = "uid=" + AdminUser + "," + BaseDn;
-l.simple_bind_s(UserDn,Password);
+   l = ldap.open(LDAPServer);
+   UserDn = "uid=" + AdminUser + "," + BaseDn;
+
+   # Connect to the ldap server
+   try:
+      l.simple_bind_s(UserDn,Password);
+   except ldap.INVALID_CREDENTIALS:
+      continue
+   break
 
 # Locate the key of the user we are adding
-GPGBasicOptions[0] = "--batch"           # Permit loading of the config file
+SetKeyrings(["/org/keyring.debian.org/keyrings/debian-keyring.gpg"])
 while (1):
    Foo = raw_input("Who are you going to add (for a GPG search)? ");
    if Foo == "":
-      continue;
+      sys.exit(0);
 
    Keys = GPGKeySearch(Foo);