The Samba-Bugzilla – Attachment 7022 Details for
Bug 8544
samba-tool user subcommands (add and setpassword) doesn't support random passwords
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
The patch adds random password capability to the relevant samba-tool user subcommands
samba-tool.diff (text/plain), 4.01 KB, created by
Geza Gemes (dead mail address)
on 2011-10-23 06:10:09 UTC
(
hide
)
Description:
The patch adds random password capability to the relevant samba-tool user subcommands
Filename:
MIME Type:
Creator:
Geza Gemes (dead mail address)
Created:
2011-10-23 06:10:09 UTC
Size:
4.01 KB
patch
obsolete
>diff --git a/samba/source4/scripting/python/samba/netcmd/user.py b/samba/source4/scripting/python/samba/netcmd/user.py >index cbac5af..e0b531b 100644 >--- a/samba/source4/scripting/python/samba/netcmd/user.py >+++ b/samba/source4/scripting/python/samba/netcmd/user.py >@@ -20,6 +20,9 @@ > # along with this program. If not, see <http://www.gnu.org/licenses/>. > # > >+import random >+import string >+ > import samba.getopt as options > import sys, ldb > from getpass import getpass >@@ -35,6 +38,14 @@ from samba.netcmd import ( > Option, > ) > >+class randomstring(object): >+ """Generates a random string usable as a password""" >+ def __init__(self,length = 180): >+ __myrg = random.SystemRandom() >+ # If you want non-English characters, remove the [0:52] >+ alphabet = string.letters[0:52] + string.digits >+ #alphabet = string.letters[0:52] + string.digits + string.punctuation >+ self.rndstr = str().join(__myrg.choice(alphabet) for _ in range(length)) > > class cmd_user_add(Command): > """Creates a new user""" >@@ -47,6 +58,12 @@ class cmd_user_add(Command): > Option("--must-change-at-next-login", > help="Force password to be changed on next login", > action="store_true"), >+ Option("--random-password", >+ help="Generate random password", >+ action="store_true"), >+ Option("--password-length", type=int, >+ help="The length of the password to be generated (defaults to 180 chars)", >+ dest="pass_length"), > Option("--use-username-as-cn", > help="Force use of username as user's CN", > action="store_true"), >@@ -73,12 +90,19 @@ class cmd_user_add(Command): > takes_args = ["username", "password?"] > > def run(self, username, password=None, credopts=None, sambaopts=None, >- versionopts=None, H=None, must_change_at_next_login=None, >+ versionopts=None, H=None, must_change_at_next_login=None, random_password=None, pass_length=None, > use_username_as_cn=None, userou=None, surname=None, given_name=None, initials=None, > profile_path=None, script_path=None, home_drive=None, home_directory=None, > job_title=None, department=None, company=None, description=None, > mail_address=None, internet_address=None, telephone_number=None, physical_delivery_office=None): > >+ if random_password is not None: >+ if pass_length is not None: >+ pw = randomstring(pass_length) >+ else: >+ pw = randomstring() >+ password = pw.rndstr >+ > while 1: > if password is not None and password is not '': > break >@@ -248,17 +272,31 @@ class cmd_user_setpassword(Command): > Option("--must-change-at-next-login", > help="Force password to be changed on next login", > action="store_true"), >+ Option("--random-password", >+ help="Generate random password", >+ action="store_true"), >+ Option("--password-length", type=int, >+ help="The length of the password to be generated (defaults to 180 chars)", >+ dest="pass_length"), > ] > > takes_args = ["username?"] > > def run(self, username=None, filter=None, credopts=None, sambaopts=None, > versionopts=None, H=None, newpassword=None, >- must_change_at_next_login=None): >+ must_change_at_next_login=None, random_password=None, pass_length=None): > if filter is None and username is None: > raise CommandError("Either the username or '--filter' must be specified!") > >- password = newpassword >+ if random_password is not None: >+ if pass_length is not None: >+ pw = randomstring(pass_length) >+ else: >+ pw = randomstring() >+ password = pw.rndstr >+ else: >+ password = newpassword >+ > while 1: > if password is not None and password is not '': > break
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 8544
:
7022
|
7023
|
7030
|
7031
|
7033
|
7044