home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 4 / CDPD_IV.bin / networking / uucp / amigauucpsrc / lib / getpwnam.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-06-29  |  2.0 KB  |  114 lines

  1.  
  2. /*
  3.  *  GETPWNAM.C
  4.  *
  5.  *  (C) Copyright 1989-1990 by Matthew Dillon,  All Rights Reserved.
  6.  *
  7.  *  (UUCP source support)
  8.  */
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <pwd.h>
  13. #include "config.h"
  14.  
  15. Prototype struct passwd *getpwnam(const char *);
  16.  
  17. Local char *Breakout(char **);
  18.  
  19. char *PasswdFile;
  20.  
  21. struct passwd *
  22. getpwnam(name)
  23. const char *name;
  24. {
  25.     FILE *fi;
  26.     char *buf = malloc(256);
  27.     static char User[32];
  28.     static char Passwd[32];
  29.     static char Dir[128];
  30.     static char Shell[256];
  31.     static struct passwd Pas = { User, Passwd, 0, 0, 0, "", "", Dir, Shell };
  32.  
  33.     if (PasswdFile)
  34.     fi = fopen(PasswdFile, "r");
  35.     else
  36.     fi = fopen(MakeConfigPath(UULIB, "Passwd"), "r");
  37.  
  38.     if (fi == NULL) {
  39.     free(buf);
  40.     return(NULL);
  41.     }
  42.  
  43.     while (fgets(buf, 256, fi)) {
  44.     char *ptr = buf;
  45.     char *arg;
  46.  
  47.     arg = Breakout(&ptr);
  48.     if (strcmp(name, arg) != 0)
  49.         continue;
  50.     strcpy(Pas.pw_name, arg);
  51.     strcpy(Pas.pw_passwd, Breakout(&ptr));
  52.     Pas.pw_uid = atoi(Breakout(&ptr));
  53.     Pas.pw_gid = atoi(Breakout(&ptr));
  54.     Breakout(&ptr);     /*  finger info */
  55.     strcpy(Pas.pw_dir, Breakout(&ptr));
  56.     strcpy(Pas.pw_shell, Breakout(&ptr));
  57.  
  58.     {
  59.         short i = strlen(Pas.pw_dir) - 1;
  60.         if (i >= 0 && Pas.pw_dir[i] != ':' && Pas.pw_dir[i] != '/') {
  61.         Pas.pw_dir[++i] = '/';
  62.         Pas.pw_dir[++i] = 0;
  63.         }
  64.     }
  65.  
  66.     {
  67.         char *str;
  68.  
  69.         Pas.pw_shell_arg0 = Pas.pw_shell;
  70.         for (str = Pas.pw_shell; *str && *str != ' ' && *str != 9; ++str);
  71.         if (*str) {
  72.         *str = 0;
  73.         ++str;
  74.         while (*str == ' ' || *str == 9)
  75.             ++str;
  76.         Pas.pw_shell_argn = str;
  77.         } else {
  78.         Pas.pw_shell_argn = str;
  79.         }
  80.     }
  81.  
  82.  
  83.     fclose(fi);
  84.     free(buf);
  85.     return(&Pas);
  86.     }
  87.     free(buf);
  88.     fclose(fi);
  89.     return(NULL);
  90. }
  91.  
  92. static
  93. char *
  94. Breakout(pptr)
  95. char **pptr;
  96. {
  97.     char *base;
  98.     char *ptr;
  99.  
  100.     base = *pptr;
  101.     if (base == NULL)
  102.     return("");
  103.     for (ptr = base; *ptr && *ptr != '\n' && *ptr != ','; ++ptr);
  104.     if (*ptr == ',') {
  105.     *pptr = ptr + 1;
  106.     *ptr = 0;
  107.     } else {
  108.     *pptr = NULL;
  109.     *ptr = 0;
  110.     }
  111.     return(base);
  112. }
  113.  
  114.