home *** CD-ROM | disk | FTP | other *** search
- /*
- * GETPWNAM.C
- *
- * (C) Copyright 1989-1990 by Matthew Dillon, All Rights Reserved.
- *
- * (UUCP source support)
- */
-
- #include <string.h>
- #include <stdio.h>
- #include <stdlib.h>
- #include <pwd.h>
- #include "config.h"
-
- Prototype struct passwd *getpwnam (const char *);
-
- static char *Breakout (char **);
-
- char
- *PasswdFile = NULL;
-
- struct passwd *
- getpwnam (const char *name)
- {
- FILE
- *fi;
- char
- *buf = malloc (256);
- static char
- User [32],
- Passwd [32],
- RealName [64],
- Dir [128],
- Shell [256];
- static struct passwd
- Pas = { User, Passwd, 0, 0, 0, "", "", Dir, Shell, NULL, NULL, RealName};
-
- if (!buf)
- return NULL;
-
- if (PasswdFile)
- fi = fopen (PasswdFile, "r");
- else
- fi = fopen (MakeConfigPath (UULIB, "Passwd"), "r");
-
- if (fi == NULL) {
- free (buf);
- return NULL;
- }
-
- while (fgets (buf, 256, fi)) {
- int
- i;
- char
- *str,
- *ptr = buf,
- *arg;
-
- arg = Breakout (&ptr);
- if (strcmp (name, arg) != 0)
- continue;
- strcpy (Pas.pw_name, arg);
- strcpy (Pas.pw_passwd, Breakout (&ptr));
- Pas.pw_uid = atoi (Breakout (&ptr));
- Pas.pw_gid = atoi (Breakout (&ptr));
- strcpy (Pas.pw_real_name, Breakout (&ptr)); /* finger info */
- strcpy (Pas.pw_dir, Breakout (&ptr));
- strcpy (Pas.pw_shell, Breakout (&ptr));
-
- i = strlen (Pas.pw_dir) - 1;
- if (i >= 0 && Pas.pw_dir [i] != ':' && Pas.pw_dir [i] != '/') {
- Pas.pw_dir [++i] = '/';
- Pas.pw_dir [++i] = 0;
- }
-
- Pas.pw_shell_arg0 = Pas.pw_shell;
- for (str = Pas.pw_shell; *str && *str != ' ' && *str != '\t'; ++str)
- ;
- if (*str) {
- *str = 0;
- ++str;
- while (*str == ' ' || *str == '\t')
- ++str;
- Pas.pw_shell_argn = str;
- }
- else {
- Pas.pw_shell_argn = str;
- }
-
-
- fclose (fi);
- free (buf);
- return &Pas;
- }
-
- fclose (fi);
- free (buf);
- return NULL;
- }
-
- static char *
- Breakout (char **pptr)
- {
- char
- *base,
- *ptr;
-
- base = *pptr;
- if (base == NULL)
- return "";
-
- for (ptr = base; *ptr && *ptr != '\n' && *ptr != ','; ++ptr)
- ;
-
- if (*ptr == ',') {
- *pptr = ptr + 1;
- *ptr = 0;
- }
- else {
- *pptr = NULL;
- *ptr = 0;
- }
-
- return base;
- }
-