Change indentation style to modified K&R
The entire source code of timeoutd.c has been passed through GNU indent, in order to amend the inconsistencies, it uses the K&R C style, but modified, so that tabs are replaced with 4 spaces, close to what a lot of the code was already using. (Blasphemy, i know) Also the maximum line length is 100 chars, apart from long strings, which don't get cut as a result.
This commit is contained in:
parent
848c784e7f
commit
1ed5ce8edf
461
timeoutd.c
461
timeoutd.c
|
@ -77,25 +77,22 @@ FILE *utfile = NULL;
|
||||||
#ifdef NEED_UTMP_UTILS
|
#ifdef NEED_UTMP_UTILS
|
||||||
void setutent()
|
void setutent()
|
||||||
{
|
{
|
||||||
if (utfile == NULL)
|
if (utfile == NULL) {
|
||||||
{
|
if ((utfile = fopen("/etc/utmp", "r")) == NULL) {
|
||||||
if ((utfile = fopen("/etc/utmp", "r")) == NULL)
|
|
||||||
{
|
|
||||||
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
||||||
syslog(LOG_ERR, "Could not open /etc/utmp");
|
syslog(LOG_ERR, "Could not open /etc/utmp");
|
||||||
closelog();
|
closelog();
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
}
|
} else
|
||||||
else fseek(utfile, 0L, 0);
|
fseek(utfile, 0L, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct utmp *getutent() /* returns next utmp file entry */
|
struct utmp *getutent()
|
||||||
{
|
{ /* returns next utmp file entry */
|
||||||
static struct utmp uent;
|
static struct utmp uent;
|
||||||
|
|
||||||
while (fread(&uent, sizeof(struct utmp), 1, utfile) == 1)
|
while (fread(&uent, sizeof(struct utmp), 1, utfile) == 1) {
|
||||||
{
|
|
||||||
if (uent.ut_line[0] != 0 && uent.ut_name[0] != 0)
|
if (uent.ut_line[0] != 0 && uent.ut_name[0] != 0)
|
||||||
return &uent;
|
return &uent;
|
||||||
}
|
}
|
||||||
|
@ -207,8 +204,7 @@ char comm[16]; /*seppy; to save the command of a pid*/
|
||||||
#ifdef NEED_STRCASECMP
|
#ifdef NEED_STRCASECMP
|
||||||
int strcasecmp(char *s1, char *s2)
|
int strcasecmp(char *s1, char *s2)
|
||||||
{
|
{
|
||||||
while (*s1 && *s2)
|
while (*s1 && *s2) {
|
||||||
{
|
|
||||||
if (tolower(*s1) < tolower(*s2))
|
if (tolower(*s1) < tolower(*s2))
|
||||||
return -1;
|
return -1;
|
||||||
else if (tolower(*s1) > tolower(*s2))
|
else if (tolower(*s1) > tolower(*s2))
|
||||||
|
@ -232,15 +228,13 @@ char *delim;
|
||||||
char *retp = *stringp;
|
char *retp = *stringp;
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
if (!**stringp) return NULL;
|
if (!**stringp)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
while (**stringp)
|
while (**stringp) {
|
||||||
{
|
|
||||||
p = delim;
|
p = delim;
|
||||||
while (*p)
|
while (*p) {
|
||||||
{
|
if (*p == **stringp) {
|
||||||
if (*p == **stringp)
|
|
||||||
{
|
|
||||||
**stringp = '\0';
|
**stringp = '\0';
|
||||||
(*stringp)++;
|
(*stringp)++;
|
||||||
return retp;
|
return retp;
|
||||||
|
@ -267,8 +261,7 @@ char *argv[];
|
||||||
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
||||||
|
|
||||||
/* The only valid invocations are "timeoutd" or "timeoutd user tty" */
|
/* The only valid invocations are "timeoutd" or "timeoutd user tty" */
|
||||||
if (argc != 1 && argc != 3)
|
if (argc != 1 && argc != 3) {
|
||||||
{
|
|
||||||
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
||||||
syslog(LOG_ERR, "Incorrect invocation of timeoutd (argc=%d) by UID %d.", argc, getuid());
|
syslog(LOG_ERR, "Incorrect invocation of timeoutd (argc=%d) by UID %d.", argc, getuid());
|
||||||
closelog();
|
closelog();
|
||||||
|
@ -282,8 +275,7 @@ char *argv[];
|
||||||
* filesystem from which we were started is unmounted. /dev is convenient as
|
* filesystem from which we were started is unmounted. /dev is convenient as
|
||||||
* ut_line fields are relative to it.
|
* ut_line fields are relative to it.
|
||||||
*/
|
*/
|
||||||
if (chdir("/dev"))
|
if (chdir("/dev")) {
|
||||||
{
|
|
||||||
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
||||||
syslog(LOG_ERR, "Could not change working directory to /dev!");
|
syslog(LOG_ERR, "Could not change working directory to /dev!");
|
||||||
closelog();
|
closelog();
|
||||||
|
@ -292,11 +284,11 @@ char *argv[];
|
||||||
|
|
||||||
/* Handle the "timeoutd user tty" invocation */
|
/* Handle the "timeoutd user tty" invocation */
|
||||||
/* This is a bit of a shameless hack, but, well, it works. */
|
/* This is a bit of a shameless hack, but, well, it works. */
|
||||||
if (argc == 3)
|
if (argc == 3) {
|
||||||
{
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
||||||
syslog(SYSLOG_DEBUG, "Running in user check mode. Checking user %s on %s.", argv[1], argv[2]);
|
syslog(SYSLOG_DEBUG, "Running in user check mode. Checking user %s on %s.", argv[1],
|
||||||
|
argv[2]);
|
||||||
closelog();
|
closelog();
|
||||||
#endif
|
#endif
|
||||||
strncpy(dev, argv[2], sizeof(dev) - 1);
|
strncpy(dev, argv[2], sizeof(dev) - 1);
|
||||||
|
@ -306,8 +298,7 @@ char *argv[];
|
||||||
now_hhmm = now.tm_hour * 100 + now.tm_min;
|
now_hhmm = now.tm_hour * 100 + now.tm_min;
|
||||||
allow_reread = 0;
|
allow_reread = 0;
|
||||||
read_wtmp(); /* Read in today's wtmp entries */
|
read_wtmp(); /* Read in today's wtmp entries */
|
||||||
switch(chk_timeout(argv[1], dev, "", 0, 0))
|
switch (chk_timeout(argv[1], dev, "", 0, 0)) {
|
||||||
{
|
|
||||||
case DAYMAX:
|
case DAYMAX:
|
||||||
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
||||||
syslog(LOG_NOTICE,
|
syslog(LOG_NOTICE,
|
||||||
|
@ -323,8 +314,8 @@ char *argv[];
|
||||||
case NOLOGIN:
|
case NOLOGIN:
|
||||||
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
||||||
syslog(LOG_NOTICE,
|
syslog(LOG_NOTICE,
|
||||||
"User %s not allowed to login on %s at this time. Login check failed.",
|
"User %s not allowed to login on %s at this time. Login check failed.", argv[1],
|
||||||
argv[1], argv[2]);
|
argv[2]);
|
||||||
closelog();
|
closelog();
|
||||||
/*
|
/*
|
||||||
printf("\r\nLogin not permitted at this time. Please try again later.\r\n");
|
printf("\r\nLogin not permitted at this time. Please try again later.\r\n");
|
||||||
|
@ -341,7 +332,8 @@ char *argv[];
|
||||||
exit(0);
|
exit(0);
|
||||||
default:
|
default:
|
||||||
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
||||||
syslog(LOG_ERR, "Internal error checking user %s on %s - unexpected return from chk_timeout",
|
syslog(LOG_ERR,
|
||||||
|
"Internal error checking user %s on %s - unexpected return from chk_timeout",
|
||||||
argv[1], argv[2]);
|
argv[1], argv[2]);
|
||||||
closelog();
|
closelog();
|
||||||
exit(30);
|
exit(30);
|
||||||
|
@ -362,8 +354,7 @@ char *argv[];
|
||||||
closelog();
|
closelog();
|
||||||
|
|
||||||
/* the child processes all utmp file entries: */
|
/* the child processes all utmp file entries: */
|
||||||
while (1)
|
while (1) {
|
||||||
{
|
|
||||||
/* Record time at which we woke up & started checking */
|
/* Record time at which we woke up & started checking */
|
||||||
time_now = time((time_t *) 0); /* get current time */
|
time_now = time((time_t *) 0); /* get current time */
|
||||||
now = *(localtime(&time_now)); /* Break it into bits */
|
now = *(localtime(&time_now)); /* Break it into bits */
|
||||||
|
@ -416,8 +407,7 @@ void read_wtmp()
|
||||||
/* Go to end of file minus one structure */
|
/* Go to end of file minus one structure */
|
||||||
fseek(fp, -1L * sizeof(struct utmp), SEEK_END);
|
fseek(fp, -1L * sizeof(struct utmp), SEEK_END);
|
||||||
|
|
||||||
while (fread(&ut, sizeof(struct utmp), 1, fp) == 1)
|
while (fread(&ut, sizeof(struct utmp), 1, fp) == 1) {
|
||||||
{
|
|
||||||
/* ut.ut_tv.tv_sec is not guaranteed to be time_t and localtime requires a time_t
|
/* ut.ut_tv.tv_sec is not guaranteed to be time_t and localtime requires a time_t
|
||||||
argument, and will break otherwise */
|
argument, and will break otherwise */
|
||||||
time_t tmp_time = ut.ut_tv.tv_sec;
|
time_t tmp_time = ut.ut_tv.tv_sec;
|
||||||
|
@ -427,14 +417,12 @@ void read_wtmp()
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#ifndef SUNOS
|
#ifndef SUNOS
|
||||||
if (ut.ut_type == USER_PROCESS ||
|
if (ut.ut_type == USER_PROCESS || ut.ut_type == DEAD_PROCESS || ut.ut_type == UT_UNKNOWN || /* SA 19940703 */
|
||||||
ut.ut_type == DEAD_PROCESS ||
|
ut.ut_type == LOGIN_PROCESS || ut.ut_type == BOOT_TIME)
|
||||||
ut.ut_type == UT_UNKNOWN || /* SA 19940703 */
|
|
||||||
ut.ut_type == LOGIN_PROCESS ||
|
|
||||||
ut.ut_type == BOOT_TIME)
|
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
if ((ut_list_p = (struct ut_list *) malloc(sizeof(struct ut_list))) == NULL)
|
if ((ut_list_p = (struct ut_list *)
|
||||||
|
malloc(sizeof(struct ut_list))) == NULL)
|
||||||
bailout("Out of memory in read_wtmp.", 1);
|
bailout("Out of memory in read_wtmp.", 1);
|
||||||
ut_list_p->elem = ut;
|
ut_list_p->elem = ut;
|
||||||
ut_list_p->next = wtmplist;
|
ut_list_p->next = wtmplist;
|
||||||
|
@ -442,7 +430,8 @@ void read_wtmp()
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Position the file pointer 2 structures back */
|
/* Position the file pointer 2 structures back */
|
||||||
if (fseek(fp, -2 * sizeof(struct utmp), SEEK_CUR) < 0) break;
|
if (fseek(fp, -2 * sizeof(struct utmp), SEEK_CUR) < 0)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
@ -462,16 +451,15 @@ void free_wtmp()
|
||||||
closelog();
|
closelog();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
while (wtmplist)
|
while (wtmplist) {
|
||||||
{
|
|
||||||
#ifdef DEBUG_WTMP
|
#ifdef DEBUG_WTMP
|
||||||
struct tm *tm;
|
struct tm *tm;
|
||||||
tm = localtime(&(wtmplist->elem.ut_time));
|
tm = localtime(&(wtmplist->elem.ut_time));
|
||||||
printf("%d:%d %s %s %s\n",
|
printf("%d:%d %s %s %s\n", tm->tm_hour, tm->tm_min, wtmplist->elem.ut_line,
|
||||||
tm->tm_hour,tm->tm_min, wtmplist->elem.ut_line,
|
|
||||||
wtmplist->elem.ut_user,
|
wtmplist->elem.ut_user,
|
||||||
#ifndef SUNOS
|
#ifndef SUNOS
|
||||||
wtmplist->elem.ut_type == LOGIN_PROCESS?"login":wtmplist->elem.ut_type == BOOT_TIME?"reboot":"logoff"
|
wtmplist->elem.ut_type ==
|
||||||
|
LOGIN_PROCESS ? "login" : wtmplist->elem.ut_type == BOOT_TIME ? "reboot" : "logoff"
|
||||||
#else
|
#else
|
||||||
""
|
""
|
||||||
#endif
|
#endif
|
||||||
|
@ -507,16 +495,15 @@ char *time_str;
|
||||||
|
|
||||||
p = strtok(time_str, ",");
|
p = strtok(time_str, ",");
|
||||||
/* For each day/timerange set, */
|
/* For each day/timerange set, */
|
||||||
while (p)
|
while (p) {
|
||||||
{
|
|
||||||
/* Store valid days */
|
/* Store valid days */
|
||||||
te->days = 0;
|
te->days = 0;
|
||||||
while (isalpha(*p))
|
while (isalpha(*p)) {
|
||||||
{
|
if (!p[1] || !isalpha(p[1])) {
|
||||||
if (!p[1] || !isalpha(p[1]))
|
|
||||||
{
|
|
||||||
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
||||||
syslog(LOG_ERR, "Malformed day name (%c%c) in time field of config file (%s). Entry ignored.", p[0], p[1], CONFIG);
|
syslog(LOG_ERR,
|
||||||
|
"Malformed day name (%c%c) in time field of config file (%s). Entry ignored.",
|
||||||
|
p[0], p[1], CONFIG);
|
||||||
closelog();
|
closelog();
|
||||||
(*t)->days = 0;
|
(*t)->days = 0;
|
||||||
return;
|
return;
|
||||||
|
@ -525,19 +512,18 @@ char *time_str;
|
||||||
p[1] = toupper(p[1]);
|
p[1] = toupper(p[1]);
|
||||||
|
|
||||||
i = 0;
|
i = 0;
|
||||||
while (daynames[i])
|
while (daynames[i]) {
|
||||||
{
|
if (!strncmp(daynames[i], p, 2)) {
|
||||||
if (!strncmp(daynames[i], p, 2))
|
|
||||||
{
|
|
||||||
te->days |= daynums[i];
|
te->days |= daynums[i];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
if (!daynames[i])
|
if (!daynames[i]) {
|
||||||
{
|
|
||||||
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
||||||
syslog(LOG_ERR, "Malformed day name (%c%c) in time field of config file (%s). Entry ignored.", p[0], p[1], CONFIG);
|
syslog(LOG_ERR,
|
||||||
|
"Malformed day name (%c%c) in time field of config file (%s). Entry ignored.",
|
||||||
|
p[0], p[1], CONFIG);
|
||||||
closelog();
|
closelog();
|
||||||
(*t)->days = 0;
|
(*t)->days = 0;
|
||||||
return;
|
return;
|
||||||
|
@ -546,29 +532,29 @@ char *time_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Store start and end times */
|
/* Store start and end times */
|
||||||
if (*p)
|
if (*p) {
|
||||||
{
|
if (strlen(p) != 9 || p[4] != '-') {
|
||||||
if (strlen(p) != 9 || p[4] != '-')
|
|
||||||
{
|
|
||||||
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
||||||
syslog(LOG_ERR, "Malformed time (%s) in time field of config file (%s). Entry ignored.", p, CONFIG);
|
syslog(LOG_ERR,
|
||||||
|
"Malformed time (%s) in time field of config file (%s). Entry ignored.", p,
|
||||||
|
CONFIG);
|
||||||
closelog();
|
closelog();
|
||||||
(*t)->days = 0;
|
(*t)->days = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
te->starttime = atoi(p);
|
te->starttime = atoi(p);
|
||||||
te->endtime = atoi(p + 5);
|
te->endtime = atoi(p + 5);
|
||||||
if ((te->starttime == 0 && strncmp(p, "0000-", 5)) || (te->endtime == 0 && strcmp(p+5, "0000")))
|
if ((te->starttime == 0 && strncmp(p, "0000-", 5))
|
||||||
{
|
|| (te->endtime == 0 && strcmp(p + 5, "0000"))) {
|
||||||
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
||||||
syslog(LOG_ERR, "Invalid range (%s) in time field of config file (%s). Entry ignored.", p, CONFIG);
|
syslog(LOG_ERR,
|
||||||
|
"Invalid range (%s) in time field of config file (%s). Entry ignored.", p,
|
||||||
|
CONFIG);
|
||||||
closelog();
|
closelog();
|
||||||
(*t)->days = 0;
|
(*t)->days = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
te->starttime = 0;
|
te->starttime = 0;
|
||||||
te->endtime = 2359;
|
te->endtime = 2359;
|
||||||
}
|
}
|
||||||
|
@ -584,7 +570,8 @@ char *b;
|
||||||
{
|
{
|
||||||
if ((*a = (char *) malloc(strlen(b) + 1)) == NULL)
|
if ((*a = (char *) malloc(strlen(b) + 1)) == NULL)
|
||||||
bailout("Out of memory", 1);
|
bailout("Out of memory", 1);
|
||||||
else strcpy(*a, b);
|
else
|
||||||
|
strcpy(*a, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
void read_config()
|
void read_config()
|
||||||
|
@ -603,8 +590,7 @@ void read_config()
|
||||||
if ((config_file = fopen(CONFIG, "r")) == NULL)
|
if ((config_file = fopen(CONFIG, "r")) == NULL)
|
||||||
bailout("Cannot open config file", 1);
|
bailout("Cannot open config file", 1);
|
||||||
|
|
||||||
while (fgets(line, 256, config_file) != NULL)
|
while (fgets(line, 256, config_file) != NULL) {
|
||||||
{
|
|
||||||
linenum++;
|
linenum++;
|
||||||
p = line;
|
p = line;
|
||||||
while (*p && (*p == ' ' || *p == '\t'))
|
while (*p && (*p == ' ' || *p == '\t'))
|
||||||
|
@ -613,11 +599,12 @@ void read_config()
|
||||||
while (*p && *p != '#' && *p != '\n')
|
while (*p && *p != '#' && *p != '\n')
|
||||||
p++;
|
p++;
|
||||||
*p = '\0';
|
*p = '\0';
|
||||||
if (*lstart)
|
if (*lstart) {
|
||||||
{
|
|
||||||
if (i == MAXLINES)
|
if (i == MAXLINES)
|
||||||
bailout("Too many lines in timeouts config file.", 1);
|
bailout("Too many lines in timeouts config file.", 1);
|
||||||
if ((config[i] = (struct config_ent *) malloc(sizeof(struct config_ent))) == NULL)
|
if ((config[i] = (struct config_ent *)
|
||||||
|
malloc(sizeof(struct config_ent)))
|
||||||
|
== NULL)
|
||||||
bailout("Out of memory", 1);
|
bailout("Out of memory", 1);
|
||||||
config[i]->times = NULL;
|
config[i]->times = NULL;
|
||||||
config[i]->ttys = NULL;
|
config[i]->ttys = NULL;
|
||||||
|
@ -632,51 +619,50 @@ void read_config()
|
||||||
config[i]->messages[SESSMSG] = NULL;
|
config[i]->messages[SESSMSG] = NULL;
|
||||||
config[i]->messages[DAYMSG] = NULL;
|
config[i]->messages[DAYMSG] = NULL;
|
||||||
config[i]->messages[NOLOGINMSG] = NULL;
|
config[i]->messages[NOLOGINMSG] = NULL;
|
||||||
if ((tok = strsep(&lstart, ":")) != NULL) store_times(&config[i]->times, tok);
|
if ((tok = strsep(&lstart, ":")) != NULL)
|
||||||
if ((tok = strsep(&lstart, ":")) != NULL) alloc_cp(&config[i]->ttys, tok);
|
store_times(&config[i]->times, tok);
|
||||||
if ((tok = strsep(&lstart, ":")) != NULL) alloc_cp(&config[i]->users, tok);
|
if ((tok = strsep(&lstart, ":")) != NULL)
|
||||||
if ((tok = strsep(&lstart, ":")) != NULL) alloc_cp(&config[i]->groups, tok);
|
alloc_cp(&config[i]->ttys, tok);
|
||||||
|
if ((tok = strsep(&lstart, ":")) != NULL)
|
||||||
|
alloc_cp(&config[i]->users, tok);
|
||||||
|
if ((tok = strsep(&lstart, ":")) != NULL)
|
||||||
|
alloc_cp(&config[i]->groups, tok);
|
||||||
tok = strsep(&lstart, ":");
|
tok = strsep(&lstart, ":");
|
||||||
if (tok != NULL && !strncasecmp(tok, "NOLOGIN", 7))
|
if (tok != NULL && !strncasecmp(tok, "NOLOGIN", 7)) {
|
||||||
{
|
|
||||||
config[i]->login_allowed = 0;
|
config[i]->login_allowed = 0;
|
||||||
if (tok[7] == ';') alloc_cp(&config[i]->messages[NOLOGINMSG], tok+8);
|
if (tok[7] == ';')
|
||||||
else if ((tok = strsep(&lstart, ":")) != NULL) alloc_cp(&config[i]->messages[NOLOGINMSG], tok);
|
alloc_cp(&config[i]->messages[NOLOGINMSG], tok + 8);
|
||||||
}
|
else if ((tok = strsep(&lstart, ":")) != NULL)
|
||||||
else
|
alloc_cp(&config[i]->messages[NOLOGINMSG], tok);
|
||||||
if (tok != NULL && !strcasecmp(tok, "LOGIN")) config[i]->login_allowed=1;
|
} else if (tok != NULL && !strcasecmp(tok, "LOGIN"))
|
||||||
else
|
config[i]->login_allowed = 1;
|
||||||
{
|
else {
|
||||||
if (tok != NULL)
|
if (tok != NULL) {
|
||||||
{
|
|
||||||
config[i]->idlemax = atoi(tok);
|
config[i]->idlemax = atoi(tok);
|
||||||
if ((p = strchr(tok, ';')) != NULL) alloc_cp(&config[i]->messages[IDLEMSG], p+1);
|
if ((p = strchr(tok, ';')) != NULL)
|
||||||
|
alloc_cp(&config[i]->messages[IDLEMSG], p + 1);
|
||||||
}
|
}
|
||||||
if ((tok = strsep(&lstart, ":")) != NULL)
|
if ((tok = strsep(&lstart, ":")) != NULL) {
|
||||||
{
|
|
||||||
config[i]->sessmax = atoi(tok);
|
config[i]->sessmax = atoi(tok);
|
||||||
if ((p = strchr(tok, ';')) != NULL) alloc_cp(&config[i]->messages[SESSMSG], p+1);
|
if ((p = strchr(tok, ';')) != NULL)
|
||||||
|
alloc_cp(&config[i]->messages[SESSMSG], p + 1);
|
||||||
}
|
}
|
||||||
if ((tok = strsep(&lstart, ":")) != NULL)
|
if ((tok = strsep(&lstart, ":")) != NULL) {
|
||||||
{
|
|
||||||
config[i]->daymax = atoi(tok);
|
config[i]->daymax = atoi(tok);
|
||||||
if ((p = strchr(tok, ';')) != NULL) alloc_cp(&config[i]->messages[DAYMSG], p+1);
|
if ((p = strchr(tok, ';')) != NULL)
|
||||||
|
alloc_cp(&config[i]->messages[DAYMSG], p + 1);
|
||||||
}
|
}
|
||||||
if ((tok = strsep(&lstart, ":")) != NULL)
|
if ((tok = strsep(&lstart, ":")) != NULL) {
|
||||||
{
|
|
||||||
config[i]->warntime = atoi(tok);
|
config[i]->warntime = atoi(tok);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!config[i]->times || !config[i]->ttys ||
|
if (!config[i]->times || !config[i]->ttys || !config[i]->users || !config[i]->groups) {
|
||||||
!config[i]->users || !config[i]->groups)
|
|
||||||
{
|
|
||||||
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
||||||
syslog(LOG_ERR,
|
syslog(LOG_ERR, "Error on line %d of config file (%s). Line ignored.", linenum,
|
||||||
"Error on line %d of config file (%s). Line ignored.",
|
CONFIG);
|
||||||
linenum, CONFIG);
|
|
||||||
closelog();
|
closelog();
|
||||||
}
|
} else
|
||||||
else i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
config[i] = NULL;
|
config[i] = NULL;
|
||||||
|
@ -686,27 +672,26 @@ void read_config()
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
i = 0;
|
i = 0;
|
||||||
while (config[i])
|
while (config[i]) {
|
||||||
{
|
|
||||||
printf("line %d: ", i);
|
printf("line %d: ", i);
|
||||||
j = 0;
|
j = 0;
|
||||||
while (config[i]->times[j].days)
|
while (config[i]->times[j].days)
|
||||||
printf("%d(%d-%d):", config[i]->times[j].days,
|
printf("%d(%d-%d):", config[i]->times[j].days,
|
||||||
config[i]->times[j].starttime,
|
config[i]->times[j].starttime, config[i]->times[j].endtime), j++;
|
||||||
config[i]->times[j].endtime),j++;
|
|
||||||
printf("%s:%s:%s:%s:%d;%s:%d;%s:%d;%s:%d\n",
|
printf("%s:%s:%s:%s:%d;%s:%d;%s:%d;%s:%d\n",
|
||||||
config[i]->ttys,
|
config[i]->ttys,
|
||||||
config[i]->users,
|
config[i]->users,
|
||||||
config[i]->groups,
|
config[i]->groups,
|
||||||
config[i]->login_allowed ? "LOGIN" : "NOLOGIN",
|
config[i]->login_allowed ? "LOGIN" : "NOLOGIN",
|
||||||
config[i]->idlemax,
|
config[i]->idlemax,
|
||||||
config[i]->messages[IDLEMSG] == NULL?"builtin":config[i]->messages[IDLEMSG],
|
config[i]->messages[IDLEMSG] ==
|
||||||
|
NULL ? "builtin" : config[i]->messages[IDLEMSG],
|
||||||
config[i]->sessmax,
|
config[i]->sessmax,
|
||||||
config[i]->messages[SESSMSG] == NULL?"builtin":config[i]->messages[SESSMSG],
|
config[i]->messages[SESSMSG] ==
|
||||||
|
NULL ? "builtin" : config[i]->messages[SESSMSG],
|
||||||
config[i]->daymax,
|
config[i]->daymax,
|
||||||
config[i]->messages[DAYMSG] == NULL ? "builtin" : config[i]->messages[DAYMSG],
|
config[i]->messages[DAYMSG] == NULL ? "builtin" : config[i]->messages[DAYMSG],
|
||||||
config[i]->warntime
|
config[i]->warntime), i++;
|
||||||
),i++;
|
|
||||||
}
|
}
|
||||||
printf("End debug output.\n");
|
printf("End debug output.\n");
|
||||||
#endif /* DEBUG */
|
#endif /* DEBUG */
|
||||||
|
@ -715,18 +700,12 @@ printf("End debug output.\n");
|
||||||
char chktimes(te)
|
char chktimes(te)
|
||||||
struct time_ent *te;
|
struct time_ent *te;
|
||||||
{
|
{
|
||||||
while (te->days)
|
while (te->days) {
|
||||||
{
|
|
||||||
if (daynums[now.tm_wday] & te->days && /* Date within range */
|
if (daynums[now.tm_wday] & te->days && /* Date within range */
|
||||||
((te->starttime <= te->endtime && /* Time within range */
|
((te->starttime <= te->endtime && /* Time within range */
|
||||||
now_hhmm >= te->starttime &&
|
now_hhmm >= te->starttime && now_hhmm <= te->endtime)
|
||||||
now_hhmm <= te->endtime)
|
|| (te->starttime > te->endtime
|
||||||
||
|
&& (now_hhmm >= te->starttime || now_hhmm <= te->endtime))))
|
||||||
(te->starttime > te->endtime &&
|
|
||||||
(now_hhmm >= te->starttime ||
|
|
||||||
now_hhmm <= te->endtime))
|
|
||||||
)
|
|
||||||
)
|
|
||||||
return 1;
|
return 1;
|
||||||
te++;
|
te++;
|
||||||
}
|
}
|
||||||
|
@ -740,22 +719,19 @@ char *in_set;
|
||||||
char *t;
|
char *t;
|
||||||
char *set = (char *) malloc(strlen(in_set) + 1);
|
char *set = (char *) malloc(strlen(in_set) + 1);
|
||||||
|
|
||||||
if (set == NULL) bailout("Out of memory", 1);
|
if (set == NULL)
|
||||||
else strcpy(set, in_set);
|
bailout("Out of memory", 1);
|
||||||
|
else
|
||||||
|
strcpy(set, in_set);
|
||||||
|
|
||||||
t = strtok(set, " ,");
|
t = strtok(set, " ,");
|
||||||
while (t)
|
while (t) {
|
||||||
{
|
if (t[strlen(t) - 1] == '*') {
|
||||||
if (t[strlen(t)-1] == '*')
|
if (!strncmp(t, element, strlen(t) - 1)) {
|
||||||
{
|
|
||||||
if (!strncmp(t, element, strlen(t) - 1))
|
|
||||||
{
|
|
||||||
free(set);
|
free(set);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
} else if (!strcmp(t, element)) {
|
||||||
else if (!strcmp(t, element))
|
|
||||||
{
|
|
||||||
free(set);
|
free(set);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -785,20 +761,16 @@ char *user;
|
||||||
#ifndef SUNOS
|
#ifndef SUNOS
|
||||||
login_p->elem.ut_type == USER_PROCESS &&
|
login_p->elem.ut_type == USER_PROCESS &&
|
||||||
#endif
|
#endif
|
||||||
!strncmp(login_p->elem.ut_user, user, 8) &&
|
!strncmp(login_p->elem.ut_user, user, 8)
|
||||||
chkmatch(login_p->elem.ut_line, config[configline]->ttys))
|
&& chkmatch(login_p->elem.ut_line, config[configline]->ttys)) {
|
||||||
{
|
|
||||||
#ifdef DEBUG_WTMP
|
#ifdef DEBUG_WTMP
|
||||||
struct tm *tm;
|
struct tm *tm;
|
||||||
tm = localtime(&(login_p->elem.ut_time));
|
tm = localtime(&(login_p->elem.ut_time));
|
||||||
fprintf(stderr, "%d:%d %s %s %s\n",
|
fprintf(stderr, "%d:%d %s %s %s\n",
|
||||||
tm->tm_hour,tm->tm_min, login_p->elem.ut_line,
|
tm->tm_hour, tm->tm_min, login_p->elem.ut_line, login_p->elem.ut_user, "login");
|
||||||
login_p->elem.ut_user,
|
|
||||||
"login");
|
|
||||||
#endif
|
#endif
|
||||||
prev_p = logout_p = login_p->next;
|
prev_p = logout_p = login_p->next;
|
||||||
while (logout_p)
|
while (logout_p) {
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
* SA19931128
|
* SA19931128
|
||||||
* If there has been a crash, then be reasonably fair and use the
|
* If there has been a crash, then be reasonably fair and use the
|
||||||
|
@ -808,8 +780,7 @@ char *user;
|
||||||
* was down.
|
* was down.
|
||||||
*/
|
*/
|
||||||
#ifndef SUNOS
|
#ifndef SUNOS
|
||||||
if (logout_p->elem.ut_type == BOOT_TIME)
|
if (logout_p->elem.ut_type == BOOT_TIME) {
|
||||||
{
|
|
||||||
logout_p = prev_p;
|
logout_p = prev_p;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -822,13 +793,14 @@ char *user;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef DEBUG_WTMP
|
#ifdef DEBUG_WTMP
|
||||||
if (logout_p)
|
if (logout_p) {
|
||||||
{
|
|
||||||
tm = localtime(&(logout_p->elem.ut_time));
|
tm = localtime(&(logout_p->elem.ut_time));
|
||||||
fprintf(stderr, "%d:%d %s %s %s\n",
|
fprintf(stderr, "%d:%d %s %s %s\n",
|
||||||
tm->tm_hour,tm->tm_min, logout_p->elem.ut_line,
|
tm->tm_hour, tm->tm_min, logout_p->elem.ut_line, logout_p->elem.ut_user,
|
||||||
logout_p->elem.ut_user, "logout");
|
"logout");
|
||||||
fprintf(stderr, "%s %d minutes\n", user, ((logout_p?logout_p->elem.ut_time:time_now) - login_p->elem.ut_time)/60);
|
fprintf(stderr, "%s %d minutes\n", user,
|
||||||
|
((logout_p ? logout_p->elem.ut_time : time_now) -
|
||||||
|
login_p->elem.ut_time) / 60);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
daytime += (logout_p ? logout_p->elem.ut_time : time_now) - login_p->elem.ut_time;
|
daytime += (logout_p ? logout_p->elem.ut_time : time_now) - login_p->elem.ut_time;
|
||||||
|
@ -854,19 +826,24 @@ char *host;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
||||||
syslog(SYSLOG_DEBUG, "Warning %s@%s on %s of pending logoff in %d minutes.",
|
syslog(SYSLOG_DEBUG, "Warning %s@%s on %s of pending logoff in %d minutes.", user, host, tty,
|
||||||
user, host, tty, time_remaining);
|
time_remaining);
|
||||||
closelog();
|
closelog();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (chk_xsession(tty, host)) {
|
if (chk_xsession(tty, host)) {
|
||||||
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
||||||
syslog(SYSLOG_DEBUG, "Warning %s running X on %s for pending logout! (%d min%s left)", user, tty, time_remaining, time_remaining==1?"":"s");
|
syslog(SYSLOG_DEBUG,
|
||||||
|
"Warning %s running X on %s for pending logout! (%d min%s left)",
|
||||||
|
user, tty, time_remaining, time_remaining == 1 ? "" : "s");
|
||||||
closelog();
|
closelog();
|
||||||
|
|
||||||
/* then send the message using xmessage */
|
/* then send the message using xmessage */
|
||||||
/* well, this is not really clean: */
|
/* well, this is not really clean: */
|
||||||
sprintf(cmdbuf, "su %s -c \"xmessage -display %s -center 'WARNING: You will be logged out in %d minute%s when your %s limit expires.'&\"", user, host, time_remaining, time_remaining==1?"":"s", limit_names[limit_type]);
|
sprintf(cmdbuf,
|
||||||
|
"su %s -c \"xmessage -display %s -center 'WARNING: You will be logged out in %d minute%s when your %s limit expires.'&\"",
|
||||||
|
user, host, time_remaining, time_remaining == 1 ? "" : "s",
|
||||||
|
limit_names[limit_type]);
|
||||||
system(cmdbuf);
|
system(cmdbuf);
|
||||||
/*#ifdef DEBUG */
|
/*#ifdef DEBUG */
|
||||||
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
||||||
|
@ -877,15 +854,14 @@ char *host;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((fd = open(tty, O_WRONLY|O_NOCTTY|O_NONBLOCK)) < 0 ||
|
if ((fd = open(tty, O_WRONLY | O_NOCTTY | O_NONBLOCK)) < 0 || (ttyf = fdopen(fd, "w")) == NULL) {
|
||||||
(ttyf = fdopen(fd, "w")) == NULL)
|
|
||||||
{
|
|
||||||
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
||||||
syslog(LOG_ERR, "Could not open %s to warn of impending logoff.\n", tty);
|
syslog(LOG_ERR, "Could not open %s to warn of impending logoff.\n", tty);
|
||||||
closelog();
|
closelog();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fprintf(ttyf, "\r\nWARNING:\r\nYou will be logged out in %d minute%s when your %s limit expires.\r\n",
|
fprintf(ttyf,
|
||||||
|
"\r\nWARNING:\r\nYou will be logged out in %d minute%s when your %s limit expires.\r\n",
|
||||||
time_remaining, time_remaining == 1 ? "" : "s", limit_names[limit_type]);
|
time_remaining, time_remaining == 1 ? "" : "s", limit_names[limit_type]);
|
||||||
fclose(ttyf);
|
fclose(ttyf);
|
||||||
}
|
}
|
||||||
|
@ -911,15 +887,13 @@ int session;
|
||||||
configline = 0;
|
configline = 0;
|
||||||
|
|
||||||
/* Find primary group for specified user */
|
/* Find primary group for specified user */
|
||||||
if ((pw = getpwnam(user)) == NULL)
|
if ((pw = getpwnam(user)) == NULL) {
|
||||||
{
|
|
||||||
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
||||||
syslog(LOG_ERR, "Could not get password entry for %s.", user);
|
syslog(LOG_ERR, "Could not get password entry for %s.", user);
|
||||||
closelog();
|
closelog();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if ((gr = getgrgid(pw->pw_gid)) == NULL)
|
if ((gr = getgrgid(pw->pw_gid)) == NULL) {
|
||||||
{
|
|
||||||
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
||||||
syslog(LOG_ERR, "Could not get group name for %s.", user);
|
syslog(LOG_ERR, "Could not get group name for %s.", user);
|
||||||
closelog();
|
closelog();
|
||||||
|
@ -933,19 +907,16 @@ int session;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Check to see if current user matches any entry based on tty/user/group */
|
/* Check to see if current user matches any entry based on tty/user/group */
|
||||||
while (config[configline])
|
while (config[configline]) {
|
||||||
{
|
|
||||||
timematch = chktimes(config[configline]->times);
|
timematch = chktimes(config[configline]->times);
|
||||||
ttymatch = chkmatch(tty, config[configline]->ttys);
|
ttymatch = chkmatch(tty, config[configline]->ttys);
|
||||||
usermatch = chkmatch(user, config[configline]->users);
|
usermatch = chkmatch(user, config[configline]->users);
|
||||||
groupmatch = chkmatch(gr->gr_name, config[configline]->groups);
|
groupmatch = chkmatch(gr->gr_name, config[configline]->groups);
|
||||||
/* If the primary group doesn't match this entry, check secondaries */
|
/* If the primary group doesn't match this entry, check secondaries */
|
||||||
setgrent();
|
setgrent();
|
||||||
while (!groupmatch && (secgr = getgrent()) != NULL)
|
while (!groupmatch && (secgr = getgrent()) != NULL) {
|
||||||
{
|
|
||||||
p = secgr->gr_mem;
|
p = secgr->gr_mem;
|
||||||
while (*p && !groupmatch)
|
while (*p && !groupmatch) {
|
||||||
{
|
|
||||||
/*
|
/*
|
||||||
printf("Group %s member %s\n", secgr->gr_name, *p);
|
printf("Group %s member %s\n", secgr->gr_name, *p);
|
||||||
*/
|
*/
|
||||||
|
@ -953,21 +924,18 @@ printf("Group %s member %s\n", secgr->gr_name, *p);
|
||||||
groupmatch = chkmatch(secgr->gr_name, config[configline]->groups);
|
groupmatch = chkmatch(secgr->gr_name, config[configline]->groups);
|
||||||
p++;
|
p++;
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
free(gr);
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
endgrent();
|
|
||||||
*/
|
|
||||||
/* If so, then check their idle, daily and session times in turn */
|
/* If so, then check their idle, daily and session times in turn */
|
||||||
if (timematch && ttymatch && usermatch && groupmatch)
|
if (timematch && ttymatch && usermatch && groupmatch) {
|
||||||
{
|
|
||||||
get_day_time(user);
|
get_day_time(user);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
||||||
syslog(SYSLOG_DEBUG, "Matched entry %d", configline);
|
syslog(SYSLOG_DEBUG, "Matched entry %d", configline);
|
||||||
syslog(SYSLOG_DEBUG, "Idle=%d (max=%d) Sess=%d (max=%d) Daily=%d (max=%d) warntime=%d", idle, config[configline]->idlemax, session, config[configline]->sessmax, daytime, config[configline]->daymax, config[configline]->warntime);
|
syslog(SYSLOG_DEBUG,
|
||||||
|
"Idle=%d (max=%d) Sess=%d (max=%d) Daily=%d (max=%d) warntime=%d",
|
||||||
|
idle, config[configline]->idlemax, session,
|
||||||
|
config[configline]->sessmax, daytime, config[configline]->daymax,
|
||||||
|
config[configline]->warntime);
|
||||||
closelog();
|
closelog();
|
||||||
#endif
|
#endif
|
||||||
disc = getdisc(dev, host);
|
disc = getdisc(dev, host);
|
||||||
|
@ -977,7 +945,8 @@ printf("Group %s member %s\n", secgr->gr_name, *p);
|
||||||
return NOLOGIN;
|
return NOLOGIN;
|
||||||
|
|
||||||
limit_type = IDLEMSG;
|
limit_type = IDLEMSG;
|
||||||
if (disc == N_TTY && config[configline]->idlemax > 0 && idle >= config[configline]->idlemax)
|
if (disc == N_TTY && config[configline]->idlemax > 0
|
||||||
|
&& idle >= config[configline]->idlemax)
|
||||||
return IDLEMAX;
|
return IDLEMAX;
|
||||||
|
|
||||||
limit_type = SESSMSG;
|
limit_type = SESSMSG;
|
||||||
|
@ -990,12 +959,13 @@ printf("Group %s member %s\n", secgr->gr_name, *p);
|
||||||
|
|
||||||
/* If none of those have been exceeded, then warn users of upcoming logouts */
|
/* If none of those have been exceeded, then warn users of upcoming logouts */
|
||||||
limit_type = DAYMSG;
|
limit_type = DAYMSG;
|
||||||
if (config[configline]->daymax > 0 && daytime >= config[configline]->daymax - config[configline]->warntime)
|
if (config[configline]->daymax > 0
|
||||||
|
&& daytime >= config[configline]->daymax - config[configline]->warntime)
|
||||||
warnpending(dev, config[configline]->daymax - daytime, user, host);
|
warnpending(dev, config[configline]->daymax - daytime, user, host);
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
limit_type = SESSMSG;
|
limit_type = SESSMSG;
|
||||||
if (config[configline]->sessmax > 0 && session >= config[configline]->sessmax - config[configline]->warntime)
|
if (config[configline]->sessmax > 0
|
||||||
|
&& session >= config[configline]->sessmax - config[configline]->warntime)
|
||||||
warnpending(dev, config[configline]->sessmax - session, user, host);
|
warnpending(dev, config[configline]->sessmax - session, user, host);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1009,8 +979,8 @@ printf("Group %s member %s\n", secgr->gr_name, *p);
|
||||||
return ACTIVE;
|
return ACTIVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void check_idle() /* Check for exceeded time limits & logoff exceeders */
|
void check_idle()
|
||||||
{
|
{ /* Check for exceeded time limits & logoff exceeders */
|
||||||
char user[sizeof(utmpp->ut_user)];
|
char user[sizeof(utmpp->ut_user)];
|
||||||
char host[sizeof(utmpp->ut_host)];
|
char host[sizeof(utmpp->ut_host)];
|
||||||
struct stat status, *pstat;
|
struct stat status, *pstat;
|
||||||
|
@ -1033,7 +1003,8 @@ void check_idle() /* Check for exceeded time limits & logoff exceeders */
|
||||||
if (!config[0])
|
if (!config[0])
|
||||||
return; /* no entries in config */
|
return; /* no entries in config */
|
||||||
while (config[++aktconfigline] && aktconfigline >= 0)
|
while (config[++aktconfigline] && aktconfigline >= 0)
|
||||||
if(strcmp(config[aktconfigline]->users, user) == 0 || config[aktconfigline]->users[0] == '*') {
|
if (strcmp(config[aktconfigline]->users, user) == 0
|
||||||
|
|| config[aktconfigline]->users[0] == '*') {
|
||||||
aktconfigline = -2; /* we found user or * in config, so he/they has/have restrictions */
|
aktconfigline = -2; /* we found user or * in config, so he/they has/have restrictions */
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1041,7 +1012,8 @@ void check_idle() /* Check for exceeded time limits & logoff exceeders */
|
||||||
if (aktconfigline > 0) { /* > 0 if user is not in config */
|
if (aktconfigline > 0) { /* > 0 if user is not in config */
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
||||||
syslog(SYSLOG_DEBUG, "User %s or * not in config -> No restrictions. Not checking %s on %s", user, user, dev);
|
syslog(SYSLOG_DEBUG, "User %s or * not in config -> No restrictions. Not checking %s on %s",
|
||||||
|
user, user, dev);
|
||||||
closelog();
|
closelog();
|
||||||
#endif
|
#endif
|
||||||
return; /* now, we return because the user beeing checked is not in config, so he has no restrictions */
|
return; /* now, we return because the user beeing checked is not in config, so he has no restrictions */
|
||||||
|
@ -1053,11 +1025,9 @@ void check_idle() /* Check for exceeded time limits & logoff exceeders */
|
||||||
strncpy(dev, utmpp->ut_line, sizeof(dev) - 1); /* get device name */
|
strncpy(dev, utmpp->ut_line, sizeof(dev) - 1); /* get device name */
|
||||||
dev[sizeof(dev) - 1] = '\0';
|
dev[sizeof(dev) - 1] = '\0';
|
||||||
sprintf(path, "/dev/%s", dev);
|
sprintf(path, "/dev/%s", dev);
|
||||||
if (stat(path, pstat) && chk_xsession(dev, host) != TIMEOUTD_XSESSION_LOCAL) /* if can't get status for
|
if (stat(path, pstat) && chk_xsession(dev, host) != TIMEOUTD_XSESSION_LOCAL) { /* if can't get status for
|
||||||
port && if it's not a local Xsession */
|
port && if it's not a local Xsession */
|
||||||
{
|
sprintf(errmsg, "Can't get status of user %s's terminal (%s)\n", user, dev);
|
||||||
sprintf(errmsg, "Can't get status of user %s's terminal (%s)\n",
|
|
||||||
user, dev);
|
|
||||||
/* bailout(errmsg, 1); MOH: is there a reason to exit here? */
|
/* bailout(errmsg, 1); MOH: is there a reason to exit here? */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1069,17 +1039,17 @@ void check_idle() /* Check for exceeded time limits & logoff exceeders */
|
||||||
if (chk_xsession(dev, host) && !chk_xterm(dev, host)) { /* check idle for Xsession, but not for xterm */
|
if (chk_xsession(dev, host) && !chk_xterm(dev, host)) { /* check idle for Xsession, but not for xterm */
|
||||||
idle = get_xidle(user, host) / 1000 / 60; /* get_xidle returns millisecs, we need mins */
|
idle = get_xidle(user, host) / 1000 / 60; /* get_xidle returns millisecs, we need mins */
|
||||||
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
||||||
syslog(SYSLOG_DEBUG, "get_xidle(%s,%s) returned %d mins idle for %s.", dev, host, (int)idle, user);
|
syslog(SYSLOG_DEBUG, "get_xidle(%s,%s) returned %d mins idle for %s.", dev, host,
|
||||||
|
(int) idle, user);
|
||||||
closelog();
|
closelog();
|
||||||
}
|
} else if (chk_xterm(dev, host))
|
||||||
else if (chk_xterm(dev, host)) return;
|
return;
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
idle = (time_now - max(pstat->st_atime, pstat->st_mtime)) / 60;
|
idle = (time_now - max(pstat->st_atime, pstat->st_mtime)) / 60;
|
||||||
|
|
||||||
sesstime = (time_now - utmpp->ut_time) / 60;
|
sesstime = (time_now - utmpp->ut_time) / 60;
|
||||||
switch(chk_timeout(user, dev, host, idle, sesstime))
|
switch (chk_timeout(user, dev, host, idle, sesstime)) {
|
||||||
{
|
|
||||||
case ACTIVE:
|
case ACTIVE:
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
||||||
|
@ -1114,7 +1084,8 @@ void check_idle() /* Check for exceeded time limits & logoff exceeders */
|
||||||
case NOLOGIN:
|
case NOLOGIN:
|
||||||
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
syslog(LOG_NOTICE, "NOLOGIN period reached for user %s@%s. (pid %d)", user, host, utmpp->ut_pid);
|
syslog(LOG_NOTICE, "NOLOGIN period reached for user %s@%s. (pid %d)", user, host,
|
||||||
|
utmpp->ut_pid);
|
||||||
#else
|
#else
|
||||||
syslog(LOG_NOTICE, "NOLOGIN period reached for user %s %s", user, host);
|
syslog(LOG_NOTICE, "NOLOGIN period reached for user %s %s", user, host);
|
||||||
#endif
|
#endif
|
||||||
|
@ -1166,18 +1137,18 @@ int tty;
|
||||||
if (config[configline]->messages[limit_type])
|
if (config[configline]->messages[limit_type])
|
||||||
msgfile = fopen(config[configline]->messages[limit_type], "r");
|
msgfile = fopen(config[configline]->messages[limit_type], "r");
|
||||||
|
|
||||||
if (msgfile)
|
if (msgfile) {
|
||||||
{
|
|
||||||
while ((cnt = read(tty, msgbuf, 1024)) > 0)
|
while ((cnt = read(tty, msgbuf, 1024)) > 0)
|
||||||
write(tty, msgbuf, cnt);
|
write(tty, msgbuf, cnt);
|
||||||
fclose(msgfile);
|
fclose(msgfile);
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
if (limit_type == NOLOGINMSG)
|
if (limit_type == NOLOGINMSG)
|
||||||
sprintf(msgbuf, "\r\n\r\nLogins not allowed at this time. Please try again later.\r\n");
|
sprintf(msgbuf,
|
||||||
|
"\r\n\r\nLogins not allowed at this time. Please try again later.\r\n");
|
||||||
else
|
else
|
||||||
sprintf(msgbuf, "\r\n\r\nYou have exceeded your %s time limit. Logging you off now.\r\n\r\n", limit_names[limit_type]);
|
sprintf(msgbuf,
|
||||||
|
"\r\n\r\nYou have exceeded your %s time limit. Logging you off now.\r\n\r\n",
|
||||||
|
limit_names[limit_type]);
|
||||||
write(tty, msgbuf, strlen(msgbuf));
|
write(tty, msgbuf, strlen(msgbuf));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1200,8 +1171,7 @@ char *host;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* Tell user which limit they have exceeded and that they will be logged off */
|
/* Tell user which limit they have exceeded and that they will be logged off */
|
||||||
if ((tty = open(dev, O_WRONLY|O_NOCTTY|O_NONBLOCK)) < 0)
|
if ((tty = open(dev, O_WRONLY | O_NOCTTY | O_NONBLOCK)) < 0) {
|
||||||
{
|
|
||||||
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
||||||
syslog(LOG_ERR, "Could not write logoff message to %s.", dev);
|
syslog(LOG_ERR, "Could not write logoff message to %s.", dev);
|
||||||
closelog();
|
closelog();
|
||||||
|
@ -1215,14 +1185,16 @@ char *host;
|
||||||
cpid = getcpid(pid);
|
cpid = getcpid(pid);
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
||||||
syslog(LOG_NOTICE, "I am at killit() pid=%d user=%s child=%d line %d", pid, user, cpid, __LINE__);
|
syslog(LOG_NOTICE, "I am at killit() pid=%d user=%s child=%d line %d", pid, user, cpid,
|
||||||
|
__LINE__);
|
||||||
closelog();
|
closelog();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (chk_ssh(pid) && chk_ssh(cpid) && !strcmp(getusr(cpid), user)) {
|
if (chk_ssh(pid) && chk_ssh(cpid) && !strcmp(getusr(cpid), user)) {
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
||||||
syslog(LOG_NOTICE, "User %s (pid:%d, cpid:%d) logged in via ssh from %s.", user, pid, cpid, host);
|
syslog(LOG_NOTICE, "User %s (pid:%d, cpid:%d) logged in via ssh from %s.", user, pid, cpid,
|
||||||
|
host);
|
||||||
closelog();
|
closelog();
|
||||||
#endif
|
#endif
|
||||||
pid = cpid;
|
pid = cpid;
|
||||||
|
@ -1245,16 +1217,15 @@ char *host;
|
||||||
/* Wait a little while in case the above message gets lost during logout */
|
/* Wait a little while in case the above message gets lost during logout */
|
||||||
#ifdef SURE_KILL
|
#ifdef SURE_KILL
|
||||||
signal(SIGHUP, SIG_IGN);
|
signal(SIGHUP, SIG_IGN);
|
||||||
if ((pw = getpwnam(user)) == NULL)
|
if ((pw = getpwnam(user)) == NULL) {
|
||||||
{
|
|
||||||
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
||||||
syslog(LOG_ERR, "Could not log user %s off line %s - unable to determine uid.", user, dev);
|
syslog(LOG_ERR, "Could not log user %s off line %s - unable to determine uid.", user, dev);
|
||||||
closelog();
|
closelog();
|
||||||
}
|
}
|
||||||
if (setuid(pw->pw_uid))
|
if (setuid(pw->pw_uid)) {
|
||||||
{
|
|
||||||
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
||||||
syslog(LOG_ERR, "Could not log user %s off line %s - unable to setuid(%d).", user, dev, pw->pw_uid);
|
syslog(LOG_ERR, "Could not log user %s off line %s - unable to setuid(%d).", user, dev,
|
||||||
|
pw->pw_uid);
|
||||||
closelog();
|
closelog();
|
||||||
}
|
}
|
||||||
kill(-1, SIGHUP);
|
kill(-1, SIGHUP);
|
||||||
|
@ -1266,8 +1237,7 @@ char *host;
|
||||||
if (!kill(pid, 0)) { /* SIGHUP might be ignored */
|
if (!kill(pid, 0)) { /* SIGHUP might be ignored */
|
||||||
kill(pid, SIGKILL); /* then send sure "kill" signal */
|
kill(pid, SIGKILL); /* then send sure "kill" signal */
|
||||||
sleep(KWAIT);
|
sleep(KWAIT);
|
||||||
if (!kill(pid, 0))
|
if (!kill(pid, 0)) {
|
||||||
{
|
|
||||||
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
||||||
syslog(LOG_ERR, "Could not log user %s off line %s.", user, dev);
|
syslog(LOG_ERR, "Could not log user %s off line %s.", user, dev);
|
||||||
closelog();
|
closelog();
|
||||||
|
@ -1284,22 +1254,24 @@ int signum;
|
||||||
|
|
||||||
if (!allow_reread)
|
if (!allow_reread)
|
||||||
pending_reread = 1;
|
pending_reread = 1;
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
pending_reread = 0;
|
pending_reread = 0;
|
||||||
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
||||||
syslog(LOG_NOTICE, "Re-reading configuration file.");
|
syslog(LOG_NOTICE, "Re-reading configuration file.");
|
||||||
closelog();
|
closelog();
|
||||||
while (config[i])
|
while (config[i]) {
|
||||||
{
|
|
||||||
free(config[i]->times);
|
free(config[i]->times);
|
||||||
free(config[i]->ttys);
|
free(config[i]->ttys);
|
||||||
free(config[i]->users);
|
free(config[i]->users);
|
||||||
free(config[i]->groups);
|
free(config[i]->groups);
|
||||||
if (config[i]->messages[IDLEMSG]) free(config[i]->messages[IDLEMSG]);
|
if (config[i]->messages[IDLEMSG])
|
||||||
if (config[i]->messages[DAYMSG]) free(config[i]->messages[DAYMSG]);
|
free(config[i]->messages[IDLEMSG]);
|
||||||
if (config[i]->messages[SESSMSG]) free(config[i]->messages[SESSMSG]);
|
if (config[i]->messages[DAYMSG])
|
||||||
if (config[i]->messages[NOLOGINMSG]) free(config[i]->messages[NOLOGINMSG]);
|
free(config[i]->messages[DAYMSG]);
|
||||||
|
if (config[i]->messages[SESSMSG])
|
||||||
|
free(config[i]->messages[SESSMSG]);
|
||||||
|
if (config[i]->messages[NOLOGINMSG])
|
||||||
|
free(config[i]->messages[NOLOGINMSG]);
|
||||||
free(config[i]);
|
free(config[i]);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
@ -1328,19 +1300,19 @@ char *host;
|
||||||
if (chk_xsession(d, host) || chk_xterm(d, host))
|
if (chk_xsession(d, host) || chk_xterm(d, host))
|
||||||
return N_TTY;
|
return N_TTY;
|
||||||
|
|
||||||
if ((fd = open(d, O_RDONLY|O_NONBLOCK|O_NOCTTY)) < 0)
|
if ((fd = open(d, O_RDONLY | O_NONBLOCK | O_NOCTTY)) < 0) {
|
||||||
{
|
|
||||||
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
||||||
syslog(LOG_WARNING, "Could not open %s for checking line discipline - idle limits will be enforced.", d);
|
syslog(LOG_WARNING,
|
||||||
|
"Could not open %s for checking line discipline - idle limits will be enforced.", d);
|
||||||
closelog();
|
closelog();
|
||||||
return N_TTY;
|
return N_TTY;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ioctl(fd, TIOCGETD, &disc) < 0)
|
if (ioctl(fd, TIOCGETD, &disc) < 0) {
|
||||||
{
|
|
||||||
close(fd);
|
close(fd);
|
||||||
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
||||||
syslog(LOG_WARNING, "Could not get line discipline for %s - idle limits will be enforced.", d);
|
syslog(LOG_WARNING, "Could not get line discipline for %s - idle limits will be enforced.",
|
||||||
|
d);
|
||||||
closelog();
|
closelog();
|
||||||
return N_TTY;
|
return N_TTY;
|
||||||
}
|
}
|
||||||
|
@ -1349,7 +1321,9 @@ char *host;
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
||||||
syslog(SYSLOG_DEBUG, "TTY %s: Discipline=%s.",d,disc==N_SLIP?"SLIP":disc==N_TTY?"TTY":disc==N_PPP?"PPP":disc==N_MOUSE?"MOUSE":"UNKNOWN");
|
syslog(SYSLOG_DEBUG, "TTY %s: Discipline=%s.", d,
|
||||||
|
disc == N_SLIP ? "SLIP" : disc == N_TTY ? "TTY" : disc ==
|
||||||
|
N_PPP ? "PPP" : disc == N_MOUSE ? "MOUSE" : "UNKNOWN");
|
||||||
closelog();
|
closelog();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -1382,8 +1356,7 @@ char *dev,*host;
|
||||||
closelog();
|
closelog();
|
||||||
#endif
|
#endif
|
||||||
return TIMEOUTD_XSESSION_LOCAL;
|
return TIMEOUTD_XSESSION_LOCAL;
|
||||||
}
|
} else if (strstr(dev, ":") && strlen(host) > 1 && gethostbyname(host)) {
|
||||||
else if (strstr(dev, ":") && strlen(host) > 1 && gethostbyname(host)) {
|
|
||||||
/* What about remote XDMCP sessions?
|
/* What about remote XDMCP sessions?
|
||||||
* USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
|
* USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
|
||||||
* mark pts/3 mercury Sat11 0.00s 10.99s 0.04s w
|
* mark pts/3 mercury Sat11 0.00s 10.99s 0.04s w
|
||||||
|
@ -1396,8 +1369,7 @@ char *dev,*host;
|
||||||
closelog();
|
closelog();
|
||||||
#endif
|
#endif
|
||||||
return TIMEOUTD_XSESSION_REMOTE;
|
return TIMEOUTD_XSESSION_REMOTE;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
||||||
syslog(LOG_DEBUG, "NO xsession detected. device=%s host=%s", dev, host);
|
syslog(LOG_DEBUG, "NO xsession detected. device=%s host=%s", dev, host);
|
||||||
|
@ -1423,8 +1395,7 @@ char *dev,*host;
|
||||||
closelog();
|
closelog();
|
||||||
#endif
|
#endif
|
||||||
return 1;
|
return 1;
|
||||||
}
|
} else
|
||||||
else
|
|
||||||
return 0;
|
return 0;
|
||||||
} /* chk_xterm(dev,host) */
|
} /* chk_xterm(dev,host) */
|
||||||
|
|
||||||
|
@ -1438,7 +1409,8 @@ char *host, *user;
|
||||||
if (limit_type == NOLOGINMSG) {
|
if (limit_type == NOLOGINMSG) {
|
||||||
sprintf(msgbuf, "Logins not allowed at this time. Please try again later.");
|
sprintf(msgbuf, "Logins not allowed at this time. Please try again later.");
|
||||||
} else {
|
} else {
|
||||||
sprintf(msgbuf, "You have exceeded your %s time limit. Logging you off now.", limit_names[limit_type]);
|
sprintf(msgbuf, "You have exceeded your %s time limit. Logging you off now.",
|
||||||
|
limit_names[limit_type]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* then send the message using xmessage */
|
/* then send the message using xmessage */
|
||||||
|
@ -1460,8 +1432,7 @@ char *host, *user;
|
||||||
if (!kill(pid, 0)) { /* SIGHUP might be ignored */
|
if (!kill(pid, 0)) { /* SIGHUP might be ignored */
|
||||||
kill(pid, SIGKILL); /* then send sure "kill" signal */
|
kill(pid, SIGKILL); /* then send sure "kill" signal */
|
||||||
sleep(KWAIT);
|
sleep(KWAIT);
|
||||||
if (!kill(pid, 0))
|
if (!kill(pid, 0)) {
|
||||||
{
|
|
||||||
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
||||||
syslog(LOG_ERR, "Could not log user %s off line %s. (running X)", user, host);
|
syslog(LOG_ERR, "Could not log user %s off line %s. (running X)", user, host);
|
||||||
closelog();
|
closelog();
|
||||||
|
@ -1483,7 +1454,8 @@ pid_t pid;
|
||||||
proc_file = fopen(path, "r");
|
proc_file = fopen(path, "r");
|
||||||
if (!proc_file) {
|
if (!proc_file) {
|
||||||
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
||||||
syslog(LOG_WARNING, "chk_ssh(): PID %d does not exist. Something went wrong. Ignoring.", pid);
|
syslog(LOG_WARNING, "chk_ssh(): PID %d does not exist. Something went wrong. Ignoring.",
|
||||||
|
pid);
|
||||||
closelog();
|
closelog();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1561,7 +1533,8 @@ char *display;
|
||||||
/* First, check if there is a xserver.. */
|
/* First, check if there is a xserver.. */
|
||||||
if ((dpy = XOpenDisplay(display)) == NULL) { /* = intended */
|
if ((dpy = XOpenDisplay(display)) == NULL) { /* = intended */
|
||||||
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
openlog("timeoutd", OPENLOG_FLAGS, LOG_DAEMON);
|
||||||
syslog(LOG_NOTICE, "Could not connect to %s to query idle-time for %s. Ignoring.", display, user);
|
syslog(LOG_NOTICE, "Could not connect to %s to query idle-time for %s. Ignoring.", display,
|
||||||
|
user);
|
||||||
closelog();
|
closelog();
|
||||||
} else {
|
} else {
|
||||||
if (!mitInfo)
|
if (!mitInfo)
|
||||||
|
|
Loading…
Reference in a new issue