summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ipa-admintools/ipa-addgroup34
-rw-r--r--ipa-admintools/ipa-adduser38
-rw-r--r--ipa-admintools/man/ipa-addgroup.16
-rw-r--r--ipa-admintools/man/ipa-adduser.113
4 files changed, 87 insertions, 4 deletions
diff --git a/ipa-admintools/ipa-addgroup b/ipa-admintools/ipa-addgroup
index fea84287c..89f763006 100644
--- a/ipa-admintools/ipa-addgroup
+++ b/ipa-admintools/ipa-addgroup
@@ -43,9 +43,12 @@ error was:
sys.exit(1)
def usage():
- print "ipa-addgroup [-d|--description STRING] [-g|--gid GID] [-v|--verbose] group"
+ print "ipa-addgroup [-d|--description STRING] [-g|--gid GID] [--addattr attribute=value] [--setattr attribute=value] [-v|--verbose] group"
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("-d", "--description", dest="desc",
@@ -54,6 +57,12 @@ def parse_options():
help="The gid to use for this group. If not included one is automatically set.")
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")
parser.add_option("--usage", action="store_true",
help="Program usage")
@@ -107,6 +116,29 @@ def main():
group.setValue('cn', cn)
group.setValue('description', desc)
+ 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
+ group.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 = group.getValue(attr)
+ if cvalue:
+ if isinstance(cvalue,str):
+ cvalue = [cvalue]
+ value = cvalue + [value]
+ group.setValue(attr, value)
+
client = ipaclient.IPAClient(verbose=options.verbose)
client.add_group(group)
print cn + " successfully added"
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)
diff --git a/ipa-admintools/man/ipa-addgroup.1 b/ipa-admintools/man/ipa-addgroup.1
index 5cc417d3d..03fee1bf2 100644
--- a/ipa-admintools/man/ipa-addgroup.1
+++ b/ipa-admintools/man/ipa-addgroup.1
@@ -34,6 +34,12 @@ Set the description of the group to \fIdescription\fR.
Set the gid for this group to \fIgid\fR.
If this option is not present, one is created automatically
by \fBfreeIPA\fR.
+.TP
+\fB\-\-addattr\fR \fIattr=value\fR
+Adds \fIvalue\fR to attribute \fIattr\fR. Attributes set this way are done after other options. If an attribute is listed more than once or already exists in the entry, it is considered a multi\-valued attribute and a list of the values is created.
+.TP
+\fB\-\-setattr\fR \fIattr=value\fR
+Set attribute \fIattr\fR to \fIvalue\fR. Any existing value will be replaced with \fIvalue\fR.
.PP
The group name and description are mandatory fields. If either of these are not included on the command line you will be asked interactively.
diff --git a/ipa-admintools/man/ipa-adduser.1 b/ipa-admintools/man/ipa-adduser.1
index abf1485a4..b08fe701a 100644
--- a/ipa-admintools/man/ipa-adduser.1
+++ b/ipa-admintools/man/ipa-adduser.1
@@ -46,6 +46,9 @@ Set user's last name to \fIfamilyName\fR.
\fB\-p\fR, \fB\-\-password\fR=\fIpassword\fR
Set user's password to \fIpassword\fR.
.TP
+\fB\-P\fR
+Prompt for the user's password.
+.TP
\fB\-s\fR, \fB\-\-shell\fR=\fIshell\fR
Set the user's login shell to \fIshell\fR.
If this option is not present, a default specified by the
@@ -62,8 +65,16 @@ By default the principal is set to \fBuser\fR.
.TP
\fB\-M\fR, \fB\-\-mailAddress\fR=\fImail\fR
Set this user's e\-mail address to \fImail\fR.
+.TP
+\fB\-\-addattr\fR \fIattr=value\fR
+Adds \fIvalue\fR to attribute \fIattr\fR. Attributes set this way are done after other options. If an attribute is listed more than once or already exists in the entry, it is considered a multi\-valued attribute and a list of the values is created.
+.TP
+\fB\-\-setattr\fR \fIattr=value\fR
+Set attribute \fIattr\fR to \fIvalue\fR. Any existing value will be replaced with \fIvalue\fR.
.PP
-The mandatory fields are: user, first name, last name and password. If any of these are not included on the command line you will be asked interactively.
+The mandatory fields are: user, first name and last name. If any of these are not included on the command line you will be asked interactively.
+
+The password is asked interactively if not passed on the command\-line but it isn't mandatory. Leaving both values blank will leave the password unset on the account.
If no options are passed then all questions are asked.
.SH "EXIT STATUS"