Re: Easy way to programatically change /etc/passwd

From: Jan-Frode Myklebust (janfrode@PARALLAB.UIB.NO)
Date: Tue Mar 18 2003 - 02:58:51 EST


On Mon, Mar 17, 2003 at 07:10:54PM -0800, pSeries AIX Geek wrote:
> Anyone have an easy way to programatically change the
> "!" entry in /etc/passwd to a "*"?
>

Run this one as a normal user (if you run it as root, it will spit out
the shadowed passwords instead of '*'):

% cat passwordentry.c
#include <stdio.h>
#include <pwd.h>
#include <sys/types.h>
#include <errno.h> /* for perror() */
int main ()
{
        struct passwd *p_entry;
        int errno=0;
        while (p_entry = getpwent()) {/* get a password entry */
        if ( p_entry == NULL ) { /* have we reached the the end? */
                if (errno!=0) { /* is it an error? */
                perror("getpwent");
                exit(-1);
                }
        }
        printf("%s:%s:%i:%i:%s:%s:%s\n",
                p_entry->pw_name, p_entry->pw_passwd, p_entry->pw_uid, p_entry->pw_gid, p_entry->pw_gecos, p_entry->pw_dir, p_entry->pw_shell);
        }
        exit(0);
}
% cc -o passwordentry passwordentry.c
% ./passwordentry

  -jf



This archive was generated by hypermail 2.1.7 : Wed Apr 09 2008 - 22:16:40 EDT