home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / programs / comms_networking / users / Utilities / c / adduser next >
Encoding:
Text File  |  1998-01-01  |  1.2 KB  |  69 lines

  1. /* adduser.c
  2.  * (c) Chris Rutter 1997
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <stdlib.h>
  8. #include "user.h"
  9.  
  10. #define UID_START 500
  11. #define GID_DEFAULT 100
  12.  
  13. int firstUid(void);
  14.  
  15. int main (int argc, char *argv[])
  16. {
  17.     char tmp[32];
  18.     user u;
  19.     int uid,gid=GID_DEFAULT;
  20.  
  21.     printf ("User name: ");
  22.     user_scanf (u.username, 32, 1);
  23.  
  24.     if (user_get_info (u.username))
  25.     {
  26.         fprintf (stderr, "User %s already exists.\n", u.username);
  27.         exit (1);
  28.     }
  29.  
  30.     printf ("Password: ");
  31.     user_scanf (u.password, 32, 0);
  32.     strcpy (u.password, user_crypt (u.password));
  33.  
  34.     printf ("Real name: ");
  35.     user_scanf (u.realName, 128, 1);
  36.  
  37.     printf ("UID [");
  38.     uid=firstUid();
  39.     printf ("%d]: ", uid);
  40.     user_scanf (tmp, 32, 1);
  41.     if (tmp[0]) u.uid=atoi(tmp);
  42.     else u.uid=uid;
  43.  
  44.     printf ("GID [%d]: ", gid);
  45.     user_scanf (tmp, 32, 1);
  46.     if (tmp[0]) u.gid=atoi(tmp);
  47.     else u.gid=gid;
  48.  
  49.     printf ("Home directory [blank for none]: ");
  50.     user_scanf (u.homeDir, 256, 1);
  51.  
  52.     if (!user_write_line (&u))
  53.     {
  54.         fprintf (stderr, "Failed to add user.\n");
  55.     }
  56.     else
  57.     {
  58.         printf ("Added user `%s' successfully.\n", u.username);
  59.     }
  60. }
  61.  
  62. int firstUid ()
  63. {
  64.     user *u;
  65.     int h=UID_START-1;
  66.     while ((u=user_enumerate())!=0) if (u->uid > h) h=u->uid;
  67.     return h+1;
  68. }
  69.