|
|
DataMuseum.dkPresents historical artifacts from the history of: DKUUG/EUUG Conference tapes |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about DKUUG/EUUG Conference tapes Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - downloadIndex: T t
Length: 2570 (0xa0a)
Types: TextFile
Names: »tb_getlocal.c«
└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0
└─⟦dc59850a2⟧ »EurOpenD22/pp5.0/pp-5.tar.Z«
└─⟦e5a54fb17⟧
└─⟦this⟧ »pp-5.0/Lib/table/tb_getlocal.c«
/* tb_getlocal.c: convert address to user reference */
# ifndef lint
static char Rcsid[] = "@(#)$Header: /cs/research/pp/hubris/pp-beta/Lib/table/RCS/tb_getlocal.c,v 5.0 90/09/20 16:15:32 pp Exp Locker: pp $";
# endif
/*
* $Header: /cs/research/pp/hubris/pp-beta/Lib/table/RCS/tb_getlocal.c,v 5.0 90/09/20 16:15:32 pp Exp Locker: pp $
*
* $Log: tb_getlocal.c,v $
* Revision 5.0 90/09/20 16:15:32 pp
* rcsforce : 5.0 public release
*
*/
#include "util.h"
#include "chan.h"
#include "loc_user.h"
#include <ctype.h>
#include <pwd.h>
#define MAX_USER_ARGS 5
extern char *mboxname;
/* --------------------- Begin Routines -------------------------------- */
LocUser *tb_getlocal (key, channel)
char *key;
CHAN *channel;
{
LocUser *loc;
char *cp;
int argc;
char *argv [MAX_USER_ARGS],
buf [BUFSIZ];
PP_DBG (("Lib/tb_getlocal (%s, %s)", key, channel -> ch_name));
if (channel -> ch_table == NULL) {
PP_LOG (LLOG_EXCEPTIONS,
("Channel %s (%s) doesn't have a table",
channel -> ch_name, channel -> ch_show));
return NULL;
}
if (tb_k2val (channel -> ch_table, key, buf) == NOTOK)
return (NULL);
if ((argc = sstr2arg (buf, MAX_USER_ARGS, argv, " ")) == NOTOK)
return (NULL);
loc = (LocUser *) smalloc (sizeof *loc);
bzero ((char *)loc, sizeof *loc);
if (argc > 1)
loc -> directory = strdup (argv[1]);
if (argc > 2)
loc -> mailbox = strdup (argv[2]);
if (isdigit (*argv[0]) && (cp = index (argv[0], '/'))) {
if (loc -> directory == NULLCP) {
PP_LOG (LLOG_EXCEPTIONS,
("No directory specified for %s", key));
free_loc_user (loc);
return NULL;
}
*cp ++ = NULL;
loc -> uid = atoi (argv[0]);
loc -> gid = atoi (cp);
}
else {
struct passwd *pwd;
if ((pwd = getpwnam (argv[0])) == NULL) {
PP_LOG (LLOG_EXCEPTIONS,
("No such local user %s", argv[0]));
free_loc_user (loc);
return NULL;
}
loc -> uid = pwd -> pw_uid;
loc -> gid = pwd -> pw_gid;
loc -> username = strdup (argv[0]);
loc -> home = strdup (pwd -> pw_dir);
loc -> shell = strdup (pwd -> pw_shell);
if (loc -> directory == NULLCP)
loc -> directory = strdup (pwd -> pw_dir);
}
if (loc -> mailbox == NULLCP)
loc -> mailbox = strdup (mboxname);
return (loc);
}
void free_loc_user (loc)
LocUser *loc;
{
if (loc -> username)
free (loc->username);
if (loc -> directory)
free (loc -> directory);
if (loc -> mailbox)
free (loc -> mailbox);
if (loc -> shell)
free (loc -> shell);
if (loc -> home)
free (loc -> home);
free ((char *) loc);
}