tru64-unix-managers (formerly alpha-osf-managers) (1994-2012)
 help / color / mirror / Atom feed
From: haymanR () icefog ! uacn ! alaska ! edu
To: tru64-unix-managers
Subject: SUMMARY: putpwent() Question
Date: Fri, 10 Mar 1995 16:33:16 +0000	[thread overview]
Message-ID: <96075318306499.tru64-unix-managers.marc@archive.invalid> (raw)

My original post:

------- Forwarded Message
Greetings - 

While this may not be specific to Alpha OSF/1, it may be due to our running
Enhanced Security also, and there may be some interrelations I don't know 
about...

I have a routine which is intending to modify information in /etc/passwd for
an account.  The problem is that after I call putpwent, I end up with two
entries for the account in question (only in /etc/passwd).  Below is a code 
fragment.  What am I missing?   BTW, I have no problems with the tcb database 
modifications.

thanks.  Summary pending responses.

Randy M. Hayman
haymanr@icefog.alaska.edu


...
#define PWD_FILE "/etc/passwd"
FILE    *pw_fil;

...
        pw_fil = fopen(PWD_FILE, "r+");
        setpwent();
...

/*--------------------username exist?-----------------------------------*/
        if (NULL == (upr = getpwnam(name)) )            /* /etc/passwd  */
        {
                fprintf(stderr, "Error getting entry for %s. User likely doesn't 
exist (passwd).\n", name);
                exit(1);
        }

        if (NULL == (pr = getprpwnam(name)) )           /* tcb database */
        {
                fprintf(stderr, "Error getting entry for %s. User likely doesn't 
exist (tcb).\n", name);
                exit(1);
        }

...
/*--------------------get user data and change it-----------------------*/

        upr = getpwnam(name);           /* /etc/passwd structure        */
        pr = getprpwnam(name);          /* tcb database structure       */

        strcpy(old_home, upr->pw_dir);
        old_uid = upr->pw_uid;
        if (old_uid != pr->ufld.fd_uid)
        {
                fprintf(stderr, "/etc/passwd uid field %u does not match tcb uid 
field %u\n", old_uid, pr->ufld.fd_uid);
                exit(1);
        }

...
/*--------------------write it out now----------------------------------*/
/*--------------------to both /etc/passwd and tcb database--------------*/

        if (0 == putprpwnam(name, pr))
        {
                fprintf(stdout, "\n\t***Failure to Update Account (tcb)***");
                exit(1);
        }
        else
        {
                fprintf(stdout, "\ntcb Account: %s   Old UID: %u   New UID: 
%u\n", name, old_uid, new_uid);
        }


        if (NULL != putpwent(upr, pw_fil))
        {
                fprintf(stdout, "\n\t***Failure to Update Account 
(passwd)***\n");
                exit(1);
        }
        else
        {
                endpwent();
                fprintf(stdout, "\npasswd Account: %s   Old UID: %u   New UID: 
%u   \n\tOld Home: %s   New Home: %s\n",
                        name, old_uid, new_uid, old_home, new_home);
        }

...

------- End of Forwarded Message

I received but a single response from Knut.Hellebo@nho.hydro.com, inquiring 
if the hashed passwd databases are fooling me.  No, unfortunately not.  


The work-around (haven't yet determined if putpwent() is doing what it is
designed to) which I now use is as follows:

while getpwent from /etc/passwd !NULL
  if (user I'm looking for)
    modify
  putpwent to tmp_passwd

mv tmp_passwd /etc/passwd
mkpasswd


Randy M. Hayman
haymanr@icefog.alaska.edu

                 reply	other threads:[~1995-03-10 16:33 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox