Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

using Unix::PasswdFile to change either the password or the shell of a user

by HeatSeekerCannibal (Beadle)
on Jul 29, 2006 at 21:08 UTC ( #564560=perlquestion: print w/ replies, xml ) Need Help??
HeatSeekerCannibal has asked for the wisdom of the Perl Monks concerning the following question:

Greetings, wise monks...
Has anybody used Unix::PasswdFile to change either the password or the shell of a user? According to the documentation it can do both, and in my system (Perl 5.6/Solaris 9/Sparc) doesnt complain at all when executing the following example:
use Unix::PasswdFile; $pw = new Unix::PasswdFile "/etc/passwd"; $pw->passwd("johndoe", $pw->encpass("newpass")); $pw->commit(); undef $pw;
...but it just doesnt change the password.
Where can i look for clues? When i run it through the debugger it doesnt show anything unusual.
Any log i can peruse? Any alternatives?
Thanks in advance,
Heatseeker Cannibal

2006-07-31 Retitled by planetscape, as per Monastery guidelines

( keep:0 edit:11 reap:0 )

Original title: 'PasswdFile'

Comment on using Unix::PasswdFile to change either the password or the shell of a user
Download Code
Re: using Unix::PasswdFile to change either the password or the shell of a user
by liverpole (Monsignor) on Jul 29, 2006 at 22:28 UTC
    Hi HeatSeekerCannibal,

    I haven't used the module myself, sorry.  And looking at the documention doesn't give any obvious clues.

    That said, here are a couple of things I'd look for first:

    1. Are you running this as root (which I'm sure you need to be).
    2. See whether there's any change to the "/etc/passwd" file itself, either in terms of its date/time, or the actual line for "johndoe" (specifically the encrypted password).  Maybe even try it with a different "newpass" to see if that helps.
    3. Try editing the password file by hand, and changing only the password for "johndoe".  Can you do that successfully?

    Do any of those things help?


    s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
Re: using Unix::PasswdFile to change either the password or the shell of a user
by rodion (Chaplain) on Jul 29, 2006 at 22:29 UTC
    The password file used to be a single file which had the scrambled passwords directly in it. Although you sometimes still see this, most of the systems I've delt with keep the actual passwords elsewhere, in a file that's not as widely available as the /etc/passwd file (which needs to be available as a source of user info).

    I took a look at the documentation and the source for Unix::PasswdFile and for Unix::ConfigFile, which does the reading and writing for it. I may have missed it, but I didn't see any handling of the shadow file, so that may be the problem.

Re: using Unix::PasswdFile to change either the password or the shell of a user
by eXile (Priest) on Jul 29, 2006 at 23:17 UTC
    Hi,

    since unix-flavors tend to use different password databases and /etc/password is mostly a relic from the past that is kept for backward compatibility issues (i think), your best bet for changing a password is using a platforms native password changing utility, for most (all?) platforms that would be the passwd utility. What I'd do is write a script that uses Expect to interact with the native password changing utility.

Re: using Unix::PasswdFile to change either the password or the shell of a user
by Zaxo (Archbishop) on Jul 30, 2006 at 02:02 UTC

    The builtins setpwent, setgrent, and friends know about shadow files and can deal with them. No module is needed.

    After Compline,
    Zaxo

      Are you sure? That's not what the documentation says they do:
      setpwent: These routines perform the same functions as their counterparts in the system library.
      And getpwent(3) says:
      The setpwent() function rewinds the file pointer to the beginning of the /etc/passwd file.
Re: using Unix::PasswdFile to change either the password or the shell of a user
by Skeeve (Vicar) on Jul 30, 2006 at 20:14 UTC
    Solaris uses /etc/shadow for passwwords.

    s$$([},&%#}/&/]+}%&{})*;#$&&s&&$^X.($'^"%]=\&(|?*{%
    +.+=%;.#_}\&"^"-+%*).}%:##%}={~=~:.")&e&&s""`$''`"e
      Right if the change the line $pw = new Unix::PasswdFile "/etc/passwd"; to $pw = new Unix::PasswdFile "/etc/shadow"; it should work.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://564560]
Approved by Hue-Bond
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (9)
As of 2014-09-01 21:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (17 votes), past polls