Patch for bug #8544

Jelmer Vernooij jelmer at samba.org
Tue Oct 25 11:20:53 MDT 2011


On Tue, 2011-10-25 at 17:25 +0200, Gémes Géza wrote:
> 
>            From: 
> Gémes Géza
> <geza at kzsdabas.hu>
>              To: 
> Jelmer Vernooij
> <jelmer at samba.org>
>              Cc: 
> Samba Technical
> <samba-technical at lists.samba.org>
>         Subject: 
> Re: Patch for bug
> #8544
>            Date: 
> Tue, 25 Oct 2011
> 17:25:56 +0200
> (25/10/11
> 08:25:56)
> 
> 
> 2011-10-25 10:08 keltezéssel, Jelmer Vernooij írta:
> > Hi,
> >
> > Thanks for the patch. We already have a password generator available
> in
> > Samba though, see "samba.generate_random_password". Can you use that
> > instead, rather than duplicating it?
> >
> > Cheers,
> >
> > Jelmer
> >
> > On Sun, 2011-10-23 at 08:14 +0200, Gémes Géza wrote:
> >> Hi,
> >>
> >> Today I've submitted bug #8544, together with a patch (the random
> >> password generation routine is based on:
> >> http://en.wikipedia.org/wiki/Random_password_generator ). The patch
> is
> >> also attached to this e-mail. Please review it.
> >>
> >> Thank you!
> >>
> >> Geza
> Hi,
> 
> Thank you for pointing me to the right tool. Attached is a remade
> patch.
> I'll also attach it to the bug report.
> 
> 
> 
> 
> 
> 
> differences
> between files
> attachment
> (samba-tool.diff)
> 
> diff --git a/source4/scripting/python/samba/netcmd/user.py
> b/source4/scripting/python/samba/netcmd/user.py
> index cbac5af..b1018d0 100644
> --- a/source4/scripting/python/samba/netcmd/user.py
> +++ b/source4/scripting/python/samba/netcmd/user.py
> @@ -25,7 +25,7 @@ import sys, ldb
>  from getpass import getpass
>  from samba.auth import system_session
>  from samba.samdb import SamDB
> -from samba import gensec
> +from samba import gensec, _glue
>  from samba.net import Net
>  
>  from samba.netcmd import (
> @@ -35,6 +35,7 @@ from samba.netcmd import (
>      Option,
>      )
>  
> +generate_random_password = _glue.generate_random_password
Please just directly import from the samba module rather than looking at
its internals. E.g.:

"from samba import generate_random_password"

Cheers,

Jelmer
>  
>  class cmd_user_add(Command):
>      """Creates a new user"""
> @@ -47,6 +48,9 @@ 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("--use-username-as-cn",
>                  help="Force use of username as user's CN",
>                  action="store_true"),
> @@ -73,12 +77,15 @@ 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,
>              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:
> +            password = generate_random_password(128, 255)
> +
>          while 1:
>              if password is not None and password is not '':
>                  break
> @@ -248,17 +255,24 @@ 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"),
>          ]
>  
>      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):
>          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:
> +            password = generate_random_password(128, 255)
> +        else
> +            password = newpassword
> +
>          while 1:
>              if password is not None and password is not '':
>                  break
> 
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20111025/b8d6372b/attachment.pgp>


More information about the samba-technical mailing list