Custom adduser function...
Channel21 Python Team
python at channel21.com
Wed May 10 14:57:00 EDT 2000
for some reason, the -p option does not actually set the password to what we
think it is. I.E., if you run "/usr/sbin/useradd -p passwordval usernameval"
it doesn't actually set the password to passwordval...
try it on your machine, then go to log in as the user - you'll see what I
mean...
what do you think to do?
> ----------
> From: Jeff Bauer[SMTP:jbauer at rubic.com]
> Sent: Wednesday, May 10, 2000 1:59 PM
> To: Channel21 Python Team
> Cc: python-list at python.org
> Subject: Re: Custom adduser function...
>
> Channel21 Python Team wrote:
> > ok - RedHat 6.2
> > need to have a function w/ 2 args (username,password)
> > which will create a system account w/ the username
> > and passwd passed in... any ideas?
>
> The easiest way is to probably pass the arguments
> to /usr/sbin/useradd via os.command(). Sample code
> below.
>
> I would probably add keyword arguments to support
> the other account options (i.e. uid, group, shell,
> home, comment, expire, etc.)
>
> Best regards,
>
> Jeff Bauer
> Rubicon Research
>
> ---
>
> #!/usr/bin/python
> import os, sys
>
> def adduser(username, password):
> cmd = "/usr/sbin/useradd -p %s %s" % (password, username)
> os.system(cmd)
>
> if __name__ == '__main__':
> usage = "usage: %s username [password]" % \
> os.path.basename(sys.argv[0])
> if len(sys.argv) < 2:
> print usage
> sys.exit(1)
> username = sys.argv[1]
> if len(sys.argv) > 2:
> password = sys.argv[2]
> else:
> from getpass import getpass
> password = None
> while password is None:
> p1 = getpass("Password for user '%s':" % username)
> p2 = getpass("Re-enter user '%s' password:" % username)
> if p1 == p2:
> password = p1
> else:
> print "Passwords don't match."
> adduser(username, password)
>
> --
> http://www.python.org/mailman/listinfo/python-list
>
More information about the Python-list
mailing list