Writing a program to add a new user to /etc/passwd in sunos 4.1.3

Writing a program to add a new user to /etc/passwd in sunos 4.1.3

Post by Paul Nguy » Thu, 05 Oct 1995 04:00:00



Hi,

        I would like to find out any information or where I can get some good
source on the net for an adduser module.  I would like to see the routines
that read and encrypt the passwd and write it out to /etc/passwd.  Or is there
a book that can show me how to do this?  Thanks.

-Paul

 
 
 

Writing a program to add a new user to /etc/passwd in sunos 4.1.3

Post by John Rushfo » Thu, 05 Oct 1995 04:00:00



>Hi,

>    I would like to find out any information or where I can get some good
>source on the net for an adduser module.  I would like to see the routines
>that read and encrypt the passwd and write it out to /etc/passwd.  Or is there
>a book that can show me how to do this?  Thanks.

>-Paul

Wow, I just finished writing one for SunOS 4.1.3 last week.  It adds, and
deletes users.  But here is how I read and encrypt the password:

-------------------------------- CUT ---------------------------------------
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/time.h>

main ()
{
    static char * key =
        "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    char          buf1[16],
                  buf2[16],
                  passwd[16],
                  salt[3],
                  * crypt (),
                  * getpass ();
    time_t        ticks;

    /*
     * get the clear text password.
     */
    while (1) {
        strncpy (buf1, getpass ("Password:"), 15);
        if (buf[0] == '\0') {
            printf ("\nYou must enter a password\n\n");
            continue;
        }
        strncpy (buf2, getpass ("Re-enter password:"), 15);
        if (strncmp (buf1, buf2, 15) != 0) {
            printf ("\nThey don't match, try again.\n\n");
            continue;
        }
        /*
         * encrypt clear text password.
         */
        else {
            time (&ticks);
            salt[0] = key[(ticks & 077)];
            salt[1] = key[((ticks > 6) & 077)];
            salt[2] = `\0`;
            strncpy (passwd, crypt (buf1, salt), 15);
            break;
        }
    }

To verify if the user of the program is 'root':

    1) use getpwent() to get root's encrypted password.
       first two characters of the encrypted password is
       the salt[] to use with crypt() in step 3.

    2) use getpass() to prompt the user to input the
       root password.

    3) use crypt, as above, to encrypt the input password from
       step 2.  (salt is first two characters from the password
       obtained using getpwent()).

    4) compare the password obtained using crypt() in step 3
       and password obtained using getpwent() in step 1.  If
       they are the same, he input the correct root password.

Hope this helps.
John

 
 
 

1. scoadmin -> Account Manager -> Users -> Add New Users breaks /etc/password symlink

When ever I add a news user on my SCO OSR5 (.0.2) system, the symlink
from /etc/passwd to /var/opt/K/SCO/Unix/5.0.2Dp/etc/passwd, and
sometimes for /etc/group as well.  If I use the utility in ScoAdmin to
fix the discrepancies, the my password and group files will not have the
proper info, ie the user(s) just added.  Why is the updated file being
written to /etc/passwd instead of the file the link points to?  Or is
this normal behavior?

TIA
--
Connector Distribution Corporation            Edward Hooper
Where connectors come from!                   (Dokhebi!)

Voice: 310-632-2466     Fax: 310-632-1249     Life: still looking

2. how to get around large memory usage

3. Adding users with /etc/passwd

4. ppp.o : unresolved symbol

5. Adding user through adduser or through /etc/passwd?

6. Linux 1.1.59 / Ether Exp 16 / SMC Elite

7. Adding users to /etc/passwd and groups

8. Problem with linux swap

9. Wingz add-ins - how to write

10. Removing entries in /etc/shadow and /etc/passwd via a program

11. Convert NIS passwd back to standard /etc/passwd & /etc/shadow

12. removing users from /etc/passwd, like gopher, operator, halt, shutdown, etc...

13. /etc/passwd & /etc/security/passwd