samba-tool: add --smartcard-required option to 'samba-tool user create'
authorStefan Metzmacher <metze@samba.org>
Thu, 2 Jun 2016 12:19:37 +0000 (14:19 +0200)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 30 Jun 2016 01:30:24 +0000 (03:30 +0200)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=11441

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
python/samba/netcmd/user.py

index 7391af582fc6e4aa2d4fa5fb4741918f4643400f..2a93a30197e5f7bfda6e54e2c741ff63e5041c93 100644 (file)
@@ -90,6 +90,9 @@ Example5 shows how to create an RFC2307/NIS domain enabled user account. If
         Option("--random-password",
                 help="Generate random password",
                 action="store_true"),
+        Option("--smartcard-required",
+                help="Require a smartcard for interactive logons",
+                action="store_true"),
         Option("--use-username-as-cn",
                 help="Force use of username as user's CN",
                 action="store_true"),
@@ -141,12 +144,25 @@ Example5 shows how to create an RFC2307/NIS domain enabled user account. If
             mail_address=None, internet_address=None, telephone_number=None,
             physical_delivery_office=None, rfc2307_from_nss=False,
             nis_domain=None, unix_home=None, uid=None, uid_number=None,
-            gid_number=None, gecos=None, login_shell=None):
+            gid_number=None, gecos=None, login_shell=None,
+            smartcard_required=False):
 
-        if random_password:
+        if smartcard_required:
+            if password is not None and password is not '':
+                raise CommandError('It is not allowed to specifiy '
+                                   '--newpassword '
+                                   'together with --smartcard-required.')
+            if must_change_at_next_login:
+                raise CommandError('It is not allowed to specifiy '
+                                   '--must-change-at-next-login '
+                                   'together with --smartcard-required.')
+
+        if random_password and not smartcard_required:
             password = generate_random_password(128, 255)
 
         while True:
+            if smartcard_required:
+                break
             if password is not None and password is not '':
                 break
             password = getpass("New Password: ")
@@ -194,7 +210,8 @@ Example5 shows how to create an RFC2307/NIS domain enabled user account. If
                           telephonenumber=telephone_number, physicaldeliveryoffice=physical_delivery_office,
                           nisdomain=nis_domain, unixhome=unix_home, uid=uid,
                           uidnumber=uid_number, gidnumber=gid_number,
-                          gecos=gecos, loginshell=login_shell)
+                          gecos=gecos, loginshell=login_shell,
+                          smartcard_required=smartcard_required)
         except Exception, e:
             raise CommandError("Failed to add user '%s': " % username, e)