http://qs321.pair.com?node_id=564560

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

Replies are listed 'Best First'.
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 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 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 Skeeve (Parson) 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.