diff options
author | davidn <davidn@FreeBSD.org> | 1997-05-10 18:55:38 +0000 |
---|---|---|
committer | davidn <davidn@FreeBSD.org> | 1997-05-10 18:55:38 +0000 |
commit | 1ad6ccc98afd1c55203d6b83b4d8e79fa7b3847a (patch) | |
tree | fc47fb17dbeaaa8cc7d7360dc539739166e4102e /lib/libutil/login_times.c | |
parent | d0fcfa02e614f5fbab7f793c6a1e1b161a71315e (diff) | |
download | FreeBSD-src-1ad6ccc98afd1c55203d6b83b4d8e79fa7b3847a.zip FreeBSD-src-1ad6ccc98afd1c55203d6b83b4d8e79fa7b3847a.tar.gz |
Summary of login.conf support changes:
o Incorporated BSDI code and enhancements, better logging for error
checking (which has been shown to be a problem, and is therefore
justified, imho); also some minor things we were missing, including
better quad_t math, which checks for under/overflows.
o setusercontext() now allows user resource limit overrides, but
does this AFTER dropping root privs, to restrict the user to
droping hard limits and set soft limits within the kernel's
allowed user limits.
o umask() only set once, and only if requested.
o add _secure_path(), and use in login.conf to guard against
symlinks etc. and non-root owned or non-user owned files being
used. Derived from BSDI contributed code.
o revamped authentication code to BSDI's latest api, which
includes deleting authenticate() and adding auth_check()
and a few other functions. This is still marked as depecated
in BSDI, but is included for completeness. No other source
in the tree uses this anyway, so it is now bracketed with
#ifdef LOGIN_CAP_AUTH which is by default not defined. Only
auth_checknologin() and auth_cat() are actually used in
module login_auth.c.
o AUTH_NONE definition removed (collided with other includes
in the tree). [bde]
o BSDI's login_getclass() now accepts a char *classname
parameter rather than struct passwd *pwd. We now do likewise,
but added login_getpwclass() for (sort of) backwards
compatiblity, namely because we handle root as a special
case for the default class. This will require quite a few
changes elsewhere in the source tree.
o We no longer pretend to support rlim_t as a long type.
o Revised code formatting to be more bsd-ish style.
Diffstat (limited to 'lib/libutil/login_times.c')
-rw-r--r-- | lib/libutil/login_times.c | 179 |
1 files changed, 87 insertions, 92 deletions
diff --git a/lib/libutil/login_times.c b/lib/libutil/login_times.c index c21524c..598592b 100644 --- a/lib/libutil/login_times.c +++ b/lib/libutil/login_times.c @@ -20,7 +20,7 @@ * * Login period parsing and comparison functions. * - * $Id$ + * $Id: login_times.c,v 1.4 1997/02/22 15:08:27 peter Exp $ */ #include <stdio.h> @@ -34,134 +34,129 @@ static struct { - const char * dw; - u_char cn; - u_char fl; + const char *dw; + u_char cn; + u_char fl; } dws[] = { - { "su", 2, LTM_SUN }, { "mo", 2, LTM_MON }, { "tu", 2, LTM_TUE }, - { "we", 2, LTM_WED }, { "th", 2, LTM_THU }, { "fr", 2, LTM_FRI }, - { "sa", 2, LTM_SAT }, { "any",3, LTM_ANY }, { "all",3, LTM_ANY }, - { "wk", 2, LTM_WK }, { "wd", 2, LTM_WD }, { NULL, 0, 0 } + { "su", 2, LTM_SUN }, { "mo", 2, LTM_MON }, { "tu", 2, LTM_TUE }, + { "we", 2, LTM_WED }, { "th", 2, LTM_THU }, { "fr", 2, LTM_FRI }, + { "sa", 2, LTM_SAT }, { "any",3, LTM_ANY }, { "all",3, LTM_ANY }, + { "wk", 2, LTM_WK }, { "wd", 2, LTM_WD }, { NULL, 0, 0 } }; static char * parse_time(char * ptr, u_short * t) { - u_short val; + u_short val; - for (val = 0; *ptr && isdigit(*ptr); ptr++) - val = (u_short)(val * 10 + (*ptr - '0')); + for (val = 0; *ptr && isdigit(*ptr); ptr++) + val = (u_short)(val * 10 + (*ptr - '0')); - *t = (u_short)((val / 100) * 60 + (val % 100)); - return ptr; + *t = (u_short)((val / 100) * 60 + (val % 100)); + + return ptr; } + login_time_t parse_lt(const char * str) { - login_time_t t; - - memset(&t, 0, sizeof t); - t.lt_dow = LTM_NONE; - if (str && *str && strcmp(str, "Never") != 0 && strcmp(str, "None") != 0) - { - int i; - login_time_t m = t; - char * p; - char buf[64]; - - /* Make local copy and force lowercase to simplify parsing - */ - p = strncpy(buf, str, sizeof buf); - buf[sizeof buf - 1] = '\0'; - for (i = 0; buf[i]; i++) - buf[i] = (char)tolower(buf[i]); - - while (isalpha(*p)) - { - for (i = 0; dws[i].dw && strncmp(p, dws[i].dw, dws[i].cn) != 0 ; i++) - ; - if (dws[i].dw == NULL) - break; - m.lt_dow |= dws[i].fl; - p += dws[i].cn; - } + login_time_t t; + + memset(&t, 0, sizeof t); + t.lt_dow = LTM_NONE; + if (str && *str && strcmp(str, "Never") != 0 && strcmp(str, "None") != 0) { + int i; + login_time_t m = t; + char *p; + char buf[64]; + + /* Make local copy and force lowercase to simplify parsing */ + p = strncpy(buf, str, sizeof buf); + buf[sizeof buf - 1] = '\0'; + for (i = 0; buf[i]; i++) + buf[i] = (char)tolower(buf[i]); + + while (isalpha(*p)) { + + i = 0; + while (dws[i].dw && strncmp(p, dws[i].dw, dws[i].cn) != 0) + i++; + if (dws[i].dw == NULL) + break; + m.lt_dow |= dws[i].fl; + p += dws[i].cn; + } + + if (m.lt_dow == LTM_NONE) /* No (valid) prefix, assume any */ + m.lt_dow |= LTM_ANY; - if (m.lt_dow == LTM_NONE) /* No (valid) prefix, assume any */ - m.lt_dow |= LTM_ANY; - - if (isdigit(*p)) - p = parse_time(p, &m.lt_start); - else - m.lt_start = 0; - if (*p == '-') - p = parse_time(++p, &m.lt_end); - else - m.lt_end = 1440; - - t = m; - } - return t; + if (isdigit(*p)) + p = parse_time(p, &m.lt_start); + else + m.lt_start = 0; + if (*p == '-') + p = parse_time(++p, &m.lt_end); + else + m.lt_end = 1440; + + t = m; + } + return t; } int in_ltm(const login_time_t * ltm, struct tm * tt, time_t * ends) { - int rc = 0; - - if (tt != NULL) - { - /* First, examine the day of the week - */ - if ((u_char)(0x01 << tt->tm_wday) & ltm->lt_dow) - { - /* Convert `current' time to minute of the day - */ - u_short now = (u_short)((tt->tm_hour * 60) + tt->tm_min); - if (tt->tm_sec > 30) - ++now; - if (now >= ltm->lt_start && now < ltm->lt_end) - { - rc = 2; - if (ends != NULL) - { - /* If requested, return ending time for this period - */ - tt->tm_hour = (int)(ltm->lt_end / 60); - tt->tm_min = (int)(ltm->lt_end % 60); - *ends = mktime(tt); + int rc = 0; + + if (tt != NULL) { + /* First, examine the day of the week */ + if ((u_char)(0x01 << tt->tm_wday) & ltm->lt_dow) { + /* Convert `current' time to minute of the day */ + u_short now = (u_short)((tt->tm_hour * 60) + tt->tm_min); + + if (tt->tm_sec > 30) + ++now; + if (now >= ltm->lt_start && now < ltm->lt_end) { + rc = 2; + if (ends != NULL) { + /* If requested, return ending time for this period */ + tt->tm_hour = (int)(ltm->lt_end / 60); + tt->tm_min = (int)(ltm->lt_end % 60); + *ends = mktime(tt); + } + } } - } } - } - return rc; + return rc; } + int in_lt(const login_time_t * ltm, time_t * t) { - return in_ltm(ltm, localtime(t), t); + return in_ltm(ltm, localtime(t), t); } int in_ltms(const login_time_t * ltm, struct tm * tm, time_t * t) { - int i = 0; - - while (i < LC_MAXTIMES && ltm[i].lt_dow != LTM_NONE) - { - if (in_ltm(ltm + i, tm, t)) - return i; - i++; - } - return -1; + int i = 0; + + while (i < LC_MAXTIMES && ltm[i].lt_dow != LTM_NONE) { + if (in_ltm(ltm + i, tm, t)) + return i; + i++; + } + return -1; } int in_lts(const login_time_t * ltm, time_t * t) { - return in_ltms(ltm, localtime(t), t); + return in_ltms(ltm, localtime(t), t); } |