summaryrefslogtreecommitdiffstats
path: root/ipa-admintools/ipa-adduser
diff options
context:
space:
mode:
authorRob Crittenden <rcritten@redhat.com>2008-05-30 10:19:08 -0400
committerRob Crittenden <rcritten@redhat.com>2008-05-30 11:22:56 -0400
commit8f639ea9248dfdb38982d653e489866f3e33795a (patch)
treec2b41e8dce774c11b85b038eead75ec6879b947d /ipa-admintools/ipa-adduser
parent165d26ce2b5d6fefe26679822cc274843de889dd (diff)
downloadfreeipa-8f639ea9248dfdb38982d653e489866f3e33795a.tar.gz
freeipa-8f639ea9248dfdb38982d653e489866f3e33795a.tar.xz
freeipa-8f639ea9248dfdb38982d653e489866f3e33795a.zip
Add two now options, --addattr and --setattr, to allow arbitrary attributes to be added and set when a new user or group is created.
Make the user password not mandatory and add new option, -P, to prompt for a password interactively. 449006
Diffstat (limited to 'ipa-admintools/ipa-adduser')
-rw-r--r--ipa-admintools/ipa-adduser38
1 files changed, 36 insertions, 2 deletions
diff --git a/ipa-admintools/ipa-adduser b/ipa-admintools/ipa-adduser
index 131c8a778..09f5c758b 100644
--- a/ipa-admintools/ipa-adduser
+++ b/ipa-admintools/ipa-adduser
@@ -44,9 +44,12 @@ error was:
sys.exit(1)
def usage():
- print "ipa-adduser [-c|--gecos STRING] [-d|--directory STRING] [-f|--firstname STRING] [-l|--lastname STRING] [-s|--shell] [-g|--groups] [-k|krb-principal [-M|mailAddress] [-v|--verbose] user"
+ print "ipa-adduser [-c|--gecos STRING] [-d|--directory STRING] [-f|--firstname STRING] [-l|--lastname STRING] [-s|--shell] [-g|--groups] [-k|krb-principal [-M|mailAddress] [--addattr attribute=value] [--setattr attribute=value] [-v|--verbose] user"
sys.exit(1)
+def set_add_usage(which):
+ print "%s option usage: --%s NAME=VALUE" % (which, which)
+
def parse_options():
parser = OptionParser()
parser.add_option("-c", "--gecos", dest="gecos",
@@ -59,6 +62,8 @@ def parse_options():
help="User's last name")
parser.add_option("-p", "--password", dest="password",
help="Set user's password")
+ parser.add_option("-P", dest="password_prompt", action="store_true",
+ help="Prompt on the command-line for the user's password")
parser.add_option("-s", "--shell", dest="shell",
help="Set user's login shell to shell")
parser.add_option("-G", "--groups", dest="groups",
@@ -71,6 +76,12 @@ def parse_options():
help="Program usage")
parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
help="Verbose output of the XML-RPC connection")
+ parser.add_option("--addattr", dest="addattr",
+ help="Adds an attribute or values to that attribute, attr=value",
+ action="append")
+ parser.add_option("--setattr", dest="setattr",
+ help="Set an attribute, dropping any existing values that may exist",
+ action="append")
args = ipa.config.init_config(sys.argv)
options, args = parser.parse_args(args)
@@ -145,7 +156,7 @@ def main():
print "Username is required and may only include letters and numbers"
return 1
- if not options.password:
+ if options.password_prompt:
while (match != True):
password = getpass.getpass(" Password: ")
confirm = getpass.getpass(" Password (again): ")
@@ -221,6 +232,29 @@ def main():
if shell:
user.setValue('loginshell', shell)
+ if options.setattr:
+ for s in options.setattr:
+ s = s.split('=')
+ if len(s) != 2:
+ set_add_usage("set")
+ sys.exit(1)
+ (attr,value) = s
+ user.setValue(attr, value)
+
+ if options.addattr:
+ for a in options.addattr:
+ a = a.split('=')
+ if len(a) != 2:
+ set_add_usage("add")
+ sys.exit(1)
+ (attr,value) = a
+ cvalue = user.getValue(attr)
+ if cvalue:
+ if isinstance(cvalue,str):
+ cvalue = [cvalue]
+ value = cvalue + [value]
+ user.setValue(attr, value)
+
client = ipaclient.IPAClient(verbose=options.verbose)
client.add_user(user)