Custom adduser function...

Olmy olmy at thistledown.org
Wed May 10 14:48:39 EDT 2000


If you do a man useradd and look at what the -p option does, you'll 
see why it doesn't work.

the -p flag requires the result of running crypt on your desired password.
Not the value of the desired password itself.

For grins, you can crack open the /etc/shadow file and you'll see 
the literal value of what you typed in the passwordval in the password 
field (whereas all other accounts have passwords that are in an 
encrypted format).

I'd guess you could solve this by using python's crypt module:

http://www.python.org/doc/current/lib/module-crypt.html

I've never used it (indeed, I'm new to python myself), so can't speak 
much beyond this.

hope this helps.

jeff



> 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
> > 
> 
> -- 
> http://www.python.org/mailman/listinfo/python-list
> 






More information about the Python-list mailing list