DataMuseum.dk

Presents historical artifacts from the history of:

DKUUG/EUUG Conference tapes

This is an automatic "excavation" of a thematic subset of
artifacts from Datamuseum.dk's BitArchive.

See our Wiki for more about DKUUG/EUUG Conference tapes

Excavated with: AutoArchaeologist - Free & Open Source Software.


top - metrics - download
Index: T t

⟦0b5f1afa1⟧ TextFile

    Length: 2683 (0xa7b)
    Types: TextFile
    Names: »tb_getprog.c«

Derivation

└─⟦2d1937cfd⟧ Bits:30007241 EUUGD22: P.P 5.0
    └─⟦dc59850a2⟧ »EurOpenD22/pp5.0/pp-5.tar.Z« 
        └─⟦e5a54fb17⟧ 
            └─⟦this⟧ »pp-5.0/Chans/shell/tb_getprog.c« 

TextFile

/* tb_getprog.c: get prog/shell channel entry */

# ifndef lint
static char Rcsid[] = "@(#)$Header: /cs/research/pp/hubris/pp-beta/Chans/shell/RCS/tb_getprog.c,v 5.0 90/09/20 15:53:42 pp Exp Locker: pp $";
# endif

/*
 * $Header: /cs/research/pp/hubris/pp-beta/Chans/shell/RCS/tb_getprog.c,v 5.0 90/09/20 15:53:42 pp Exp Locker: pp $
 *
 * $Log:	tb_getprog.c,v $
 * Revision 5.0  90/09/20  15:53:42  pp
 * rcsforce : 5.0 public release
 * 
 */



#include	"util.h"
#include	"table.h"
#include	"prog.h"

extern char	*compress();

#define 	DEFAULT_TIMEOUT	5*60	/* 5 mins */

ProgInfo *tb_getprog (key, tbl)
char		*key;
Table		*tbl;

{
	char	buf[BUFSIZ],
		*timeout_value,
		*ix;
	struct passwd *pwd;
	char	*cp;
	ProgInfo *prog;

	PP_DBG(("tb_getprog (%s)", key));

	if (tbl == NULLTBL) {
		PP_LOG(LLOG_FATAL, ("tb_getprog (no table)"));
		return NULLPROG;
	}

	if (tb_k2val (tbl, key, buf) == NOTOK)
		return (NULLPROG);

	/* syntax uid,timeout,cmd line */

	if ((ix = index(buf,',')) == NULLCP) {
		PP_LOG(LLOG_EXCEPTIONS,
		       ("incorrect table syntax for entry '%s' (missing ,)",
			key));
		return NULLPROG;
	}
	*ix++ = '\0';

	prog = (ProgInfo *) smalloc (sizeof *prog);
	bzero ((char *)prog, sizeof *prog);

	/* uid is either a name or a uid/gid pair */
	if (isdigit (*buf) && (cp = index (buf, '/'))) {
		prog -> username = NULLCP;
		*cp ++ = NULL;
		prog -> uid = atoi (buf);
		prog -> gid = atoi (cp);
		prog -> home = strdup ("/tmp");
	}
	else {
		prog->username = strdup(buf);
	
		if ((pwd = getpwnam(prog->username)) == NULL) {
			PP_OPER(NULLCP,
				("tb_getprog no user '%s' with key '%s'",
				 prog->username, key));
			
			prog_free (prog);
			return NULLPROG;
		}
		prog -> uid = pwd -> pw_uid;
		prog -> gid = pwd -> pw_gid;
                prog -> home = strdup (pwd -> pw_dir);
		if (pwd -> pw_shell)
			prog -> shell = strdup (pwd -> pw_shell);
	}
	if (prog -> shell == NULLCP)
		prog -> shell = strdup ("/bin/sh");

	timeout_value  = ix;
	if ((ix = index(timeout_value, ',')) == NULLCP) {
		PP_LOG(LLOG_EXCEPTIONS,
		       ("incorrect table syntax for '%s' entry (missing ,:)",
			key));
		prog_free (prog);
		return NULLPROG;
	}
	*ix++ = '\0';
	(void) compress(timeout_value, timeout_value);
	if (timeout_value[0] == '\0') 
		prog -> timeout_in_secs = DEFAULT_TIMEOUT;
	else
		prog -> timeout_in_secs = atoi(timeout_value);
	prog -> cmd_line = strdup(ix);
	return prog;
}

void prog_free (prog)
ProgInfo *prog;
{
	if (prog == NULLPROG)
		return;
	if (prog -> cmd_line)
		free (prog -> cmd_line);
	if (prog -> username)
		free (prog -> username);
	if (prog -> home)
		free (prog -> home);
	if (prog -> shell)
		free (prog -> shell);
	free ((char *)prog);
}