home *** CD-ROM | disk | FTP | other *** search
- /* adduser.c
- * (c) Chris Rutter 1997
- */
-
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include "user.h"
-
- #define UID_START 500
- #define GID_DEFAULT 100
-
- int firstUid(void);
-
- int main (int argc, char *argv[])
- {
- char tmp[32];
- user u;
- int uid,gid=GID_DEFAULT;
-
- printf ("User name: ");
- user_scanf (u.username, 32, 1);
-
- if (user_get_info (u.username))
- {
- fprintf (stderr, "User %s already exists.\n", u.username);
- exit (1);
- }
-
- printf ("Password: ");
- user_scanf (u.password, 32, 0);
- strcpy (u.password, user_crypt (u.password));
-
- printf ("Real name: ");
- user_scanf (u.realName, 128, 1);
-
- printf ("UID [");
- uid=firstUid();
- printf ("%d]: ", uid);
- user_scanf (tmp, 32, 1);
- if (tmp[0]) u.uid=atoi(tmp);
- else u.uid=uid;
-
- printf ("GID [%d]: ", gid);
- user_scanf (tmp, 32, 1);
- if (tmp[0]) u.gid=atoi(tmp);
- else u.gid=gid;
-
- printf ("Home directory [blank for none]: ");
- user_scanf (u.homeDir, 256, 1);
-
- if (!user_write_line (&u))
- {
- fprintf (stderr, "Failed to add user.\n");
- }
- else
- {
- printf ("Added user `%s' successfully.\n", u.username);
- }
- }
-
- int firstUid ()
- {
- user *u;
- int h=UID_START-1;
- while ((u=user_enumerate())!=0) if (u->uid > h) h=u->uid;
- return h+1;
- }
-