|
|
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 c
Length: 8150 (0x1fd6)
Types: TextFile
Names: »cf.c«
└─⟦9ae75bfbd⟧ Bits:30007242 EUUGD3: Starter Kit
└─⟦653021b30⟧ »EurOpenD3/utils/downtime.tar.Z«
└─⟦946c717da⟧
└─⟦this⟧ »cf.c«
/*
* Copyright (c) 1988 Michael A. Cooper, University of Southern California.
* This program may be used, copied, modified, and redistributed freely
* for noncommercial purposes, so long as this notice remains intact.
*/
#ifndef lint
static char *RCSid = "$Header: cf.c,v 4.2 88/07/05 15:58:47 mcooper Exp $";
#endif
/*
*------------------------------------------------------------------
*
* $Source: /usr/skat3/src/common/usc/etc/downtime/RCS/cf.c,v $
* $Revision: 4.2 $
* $Date: 88/07/05 15:58:47 $
* $State: Exp $
*
*------------------------------------------------------------------
*
* Michael A. Cooper
* Research and Development Group
* University Computing Services
* University of Southern California
* (mcooper@oberon.USC.EDU)
*
*------------------------------------------------------------------
*
* $Log: cf.c,v $
* Revision 4.2 88/07/05 15:58:47 mcooper
* Added copyright notice.
*
* Revision 4.1 88/06/08 12:38:42 mcooper
* Don't blow chow if we encounter
* an unknown group in _group().
*
* Revision 4.0 88/04/20 15:41:43 mcooper
* Version 4.
*
* Revision 3.4 88/04/14 18:49:23 mcooper
* Added ability to set certain booleans
* via cfset().
*
* Revision 3.3 88/03/02 16:09:45 mcooper
* Cleanup time.
*
* Revision 3.2 88/03/01 15:48:05 mcooper
* Cleaned up header files.
*
* Revision 3.1 87/09/21 16:16:53 mcooper
* Fixed major security hole that gave
* anyone permission to run downtime.
* Problem was that group "wheel" is
* group 0 and the getgr* routines make
* entries in the gidset table 0 for
* "empties".
*
* Revision 3.0 87/07/24 14:15:00 mcooper
* Version 3.
*
*------------------------------------------------------------------
*/
#define NO_CCMD /* So ccmd.h doesn't hurt us */
#include "defs.h"
#include <pwd.h>
#include <grp.h>
int warntime = WARNTIME; /* default warntime */
int motdtime = MOTDTIME; /* default motdtime */
char datafile[BUFSIZ]; /* default data file */
char helpfile[BUFSIZ]; /* default help file */
char motdfile[BUFSIZ]; /* default motd file */
int okayuser = FALSE; /* Is this user authorized? */
char *username = NULL; /* The user's name */
char host[MAXHOSTNAMELEN]; /* His host name */
struct passwd *pwd;
int _user(), _group(), gettime(), getfile(), cfset();
struct keytable {
char *key;
int valint;
} words[] = {
{ "user", (int) _user },
{ "usr", (int) _user },
{ "group", (int) _group },
{ "grp", (int) _group },
{ "set", (int) cfset },
{ "warntime", (int) gettime },
{ "datafile", (int) getfile },
{ "helpfile", (int) getfile },
{ "motdfile", (int) getfile },
{ "motdtime", (int) gettime },
{ NULL, 0 },
};
/*
* config - Parse the configuration file.
*/
config(file)
char *file;
{
FILE *fd, *fopen();
char buf[BUFSIZ], word[BUFSIZ];
int did = FALSE;
int line = 0;
register int x;
strcpy(datafile, DATAFILE); /* default data file */
strcpy(helpfile, HELPFILE); /* default help file */
strcpy(motdfile, MOTD); /* default motd file */
gethostname(host, sizeof(host));
strcpy(buf, "");
if (getuid() == ROOT) {
username = "root";
okayuser = TRUE;
}
if ((fd = fopen(file, "r")) == NULL) {
if (getuid() != ROOT) {
perror(file);
return(-1);
} else
return(0);
}
if ((pwd = (struct passwd *) getpwuid(getuid())) == NULL) {
perror("getpwuid()");
return(-1);
}
username = pwd->pw_name;
while (fgets(buf, sizeof(buf), fd) != NULL) {
++line;
if (buf[strlen(buf)-1] == '\n')
buf[strlen(buf)-1] = NULL;
if (buf[0] == COMMENT || strlen(buf) == 0 || buf[0] == ' ' ||
buf[0] == '\011')
continue;
strcpy(word, "");
sscanf(buf, "%s ", word);
lowerstr(word);
did = FALSE;
for (x = 0;words[x].key != NULL;++x) {
if (strncmp(word, words[x].key, strlen(word)) == 0) {
if ((* (procptr) words[x].valint)(buf) < 0) {
if (getuid() != ROOT) /* if we're root, just continue */
return(-1);
}
did = TRUE;
}
}
if (did == FALSE) {
fprintf(stderr, "Warning: *** Line %d of %s: %s: No such keyword.\n",
line, file, word);
}
}
return(0);
}
/*
* _user - Is the user specifically enabled?
*/
_user(str)
char *str;
{
char usr[100];
if (okayuser)
return(0);
if (username == (char *) NULL) {
if ((pwd = (struct passwd *) getpwuid(getuid())) == NULL) {
perror("getpwuid()");
return(-1);
}
username = pwd->pw_name;
}
strcpy(usr, "");
sscanf(str, "%*s %s", usr);
if (strncmp(username, usr, strlen(username)) == 0) {
okayuser = TRUE;
}
return(0);
}
/*
* _group - Is the user a member of the right group?
*/
_group(str)
char *str;
{
register int x;
static int gidset[NGROUPS];
static int ngrps = 0;
char group[100];
struct group *grp;
if (okayuser)
return(0);
if (ngrps == 0) {
ngrps = getgroups(NGROUPS, gidset);
}
strcpy(group, "");
sscanf(str, "%*s %s", group);
if (strlen(group) == 0) {
fprintf(stderr, "group: No group name specified.\n");
return(-1);
}
/*
* If we can't find the group, just ignore.
*/
if ((grp = (struct group *) getgrnam(group)) == NULL) {
return(0);
}
for (x = 0; x < ngrps; x++) {
if (grp->gr_gid == gidset[x]) {
okayuser = TRUE;
return(0);
}
}
return(0);
}
/*
* gettime - Parse and set time.
*/
gettime(str)
char *str;
{
char whoami[200];
int time = -1;
char scale = NULL;
int t;
time = -1;
scale = NULL;
sscanf(str, "%s %d%c", whoami, &time, &scale);
lowerstr(whoami);
if (time <= 0) {
fprintf(stderr, "%s: Bad time value.\n", whoami);
return(-1);
}
if (scale == NULL)
scale = 'h';
switch(scale) {
case 'S':
case 's':
t = time SECONDS;
break;
case 'M':
case 'm':
t = time MINUTES;
break;
case 'H':
case 'h':
t = time HOURS;
break;
case 'D':
case 'd':
t = time DAYS;
break;
default:
fprintf(stderr, "%c: Bad scale value for `%d'.\n", scale, time);
return(-1);
}
if (strncmp(whoami, "warntime", 8) == 0)
warntime = t;
else if (strncmp(whoami, "motdtime", 8) == 0)
motdtime = t;
else {
fprintf(stderr, "time: Unknown keyword `%s'.\n", whoami);
return(-1);
}
return(0);
}
/*
* getfile - Set file names.
*/
getfile(str)
char *str;
{
char whoami[BUFSIZ];
char buf[BUFSIZ];
strcpy(buf, "");
strcpy(whoami, "");
sscanf(str, "%s %s", whoami, buf);
lowerstr(whoami);
if (strlen(buf) < 1) {
fprintf(stderr, "No file specified for keyword `%s'.\n", whoami);
return(-1);
}
if (strncmp(whoami, "datafile", 8) == 0)
strcpy(datafile, buf);
else if (strncmp(whoami, "motdfile", 8) == 0)
strcpy(motdfile, buf);
else if (strncmp(whoami, "helpfile", 8) == 0)
strcpy(helpfile, buf);
else {
fprintf(stderr, "Unknown keyword in getfile `%s'.\n", whoami);
return(-1);
}
return(0);
}
struct keytable cfsettab[] = {
{ "shortmessage", (int) &shortshutmsg },
{ "quiet", (int) &quiet },
{ "force", (int) &force },
{ NULL, 0 },
};
cfset(str)
char *str;
{
register int x;
int *iptr;
char word[100], val[100];
strcpy(word, "");
strcpy(val, "");
sscanf(str, "%*s %s %s", word, val);
lowerstr(word);
lowerstr(val);
for (x = 0;cfsettab[x].key != NULL;++x) {
if (strncmp(word, cfsettab[x].key, strlen(word)) == 0) {
iptr = (int *) cfsettab[x].valint;
if (strlen(val) == 0) {
*iptr = !(*iptr);
} else if (strcmp(val, "true") == 0) {
*iptr = TRUE;
} else if (strcmp(val, "false") == 0) {
*iptr = FALSE;
} else {
fprintf(stderr, "%s: Unknown set value.\n", val);
return(-1);
}
return(0);
}
}
fprintf(stderr, "%s: Unknown set keyword.\n", word);
return(-1);
}