2007-10-07 17:14:02 +05:30
|
|
|
/*
|
2021-12-05 21:05:27 +05:30
|
|
|
* SPDX-FileCopyrightText: 1989 - 1994, Julianne Frances Haugh
|
|
|
|
* SPDX-FileCopyrightText: 1996 - 1997, Marek Michałkiewicz
|
|
|
|
* SPDX-FileCopyrightText: 2005 , Tomasz Kłoczko
|
|
|
|
* SPDX-FileCopyrightText: 2008 , Nicolas François
|
2007-10-07 17:14:02 +05:30
|
|
|
*
|
2021-12-05 21:05:27 +05:30
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
|
2007-11-11 05:16:11 +05:30
|
|
|
#ident "$Id$"
|
2007-10-07 17:17:01 +05:30
|
|
|
|
2007-10-07 17:14:02 +05:30
|
|
|
#include <stdio.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include "defines.h"
|
2008-01-05 18:53:22 +05:30
|
|
|
#include "prototypes.h"
|
2007-10-07 17:14:02 +05:30
|
|
|
#include "port.h"
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
static FILE *ports;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* portcmp - compare the name of a port to a /etc/porttime entry
|
|
|
|
*
|
|
|
|
* portcmp works like strcmp, except that if the last character
|
|
|
|
* in a failing match is a '*', the match is considered to have
|
|
|
|
* passed. The "*" match is suppressed whenever the port is "SU",
|
|
|
|
* which is the token the "su" command uses to validate access.
|
|
|
|
* A match returns 0, failure returns non-zero.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
static int portcmp (const char *pattern, const char *port)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
|
|
|
const char *orig = port;
|
|
|
|
|
2008-05-26 06:35:04 +05:30
|
|
|
while (('\0' != *pattern) && (*pattern == *port)) {
|
|
|
|
pattern++;
|
|
|
|
port++;
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-05-26 06:35:04 +05:30
|
|
|
if (('\0' == *pattern) && ('\0' == *port)) {
|
2007-10-07 17:14:02 +05:30
|
|
|
return 0;
|
2008-05-26 06:35:04 +05:30
|
|
|
}
|
2008-06-11 01:29:26 +05:30
|
|
|
if (('S' == orig[0]) && ('U' == orig[1]) && ('\0' == orig[2])) {
|
2007-10-07 17:14:02 +05:30
|
|
|
return 1;
|
2008-05-26 06:35:04 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-05-26 06:35:04 +05:30
|
|
|
return (*pattern == '*') ? 0 : 1;
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* setportent - open /etc/porttime file or rewind
|
|
|
|
*
|
|
|
|
* the /etc/porttime file is rewound if already open, or
|
|
|
|
* opened for reading.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
static void setportent (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2008-05-26 06:35:04 +05:30
|
|
|
if (NULL != ports) {
|
2007-10-07 17:14:02 +05:30
|
|
|
rewind (ports);
|
2008-05-26 06:35:04 +05:30
|
|
|
} else {
|
2007-10-07 17:14:02 +05:30
|
|
|
ports = fopen (PORTS, "r");
|
2008-05-26 06:35:04 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* endportent - close the /etc/porttime file
|
|
|
|
*
|
|
|
|
* the /etc/porttime file is closed and the ports variable set
|
|
|
|
* to NULL to indicate that the /etc/porttime file is no longer
|
|
|
|
* open.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
static void endportent (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2008-05-26 06:35:04 +05:30
|
|
|
if (NULL != ports) {
|
2008-06-11 01:29:26 +05:30
|
|
|
(void) fclose (ports);
|
2008-05-26 06:35:04 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2023-02-01 07:20:14 +05:30
|
|
|
ports = NULL;
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* getportent - read a single entry from /etc/porttime
|
|
|
|
*
|
|
|
|
* the next line in /etc/porttime is converted to a (struct port)
|
|
|
|
* and a pointer to a static (struct port) is returned to the
|
|
|
|
* invoker. NULL is returned on either EOF or error. errno is
|
|
|
|
* set to EINVAL on error to distinguish the two conditions.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
static struct port *getportent (void)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
static struct port port; /* static struct to point to */
|
|
|
|
static char buf[BUFSIZ]; /* some space for stuff */
|
|
|
|
static char *ttys[PORT_TTY + 1]; /* some pointers to tty names */
|
|
|
|
static char *users[PORT_IDS + 1]; /* some pointers to user ids */
|
|
|
|
static struct pt_time ptimes[PORT_TIMES + 1]; /* time ranges */
|
|
|
|
char *cp; /* pointer into line */
|
|
|
|
int dtime; /* scratch time of day */
|
|
|
|
int i, j;
|
|
|
|
int saveerr = errno; /* errno value on entry */
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* If the ports file is not open, open the file. Do not rewind
|
|
|
|
* since we want to search from the beginning each time.
|
|
|
|
*/
|
|
|
|
|
2008-05-26 06:35:04 +05:30
|
|
|
if (NULL == ports) {
|
2007-10-07 17:14:02 +05:30
|
|
|
setportent ();
|
2008-05-26 06:35:04 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-05-26 06:35:04 +05:30
|
|
|
if (NULL == ports) {
|
2007-10-07 17:14:02 +05:30
|
|
|
errno = saveerr;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Common point for beginning a new line -
|
|
|
|
*
|
2007-10-07 17:16:07 +05:30
|
|
|
* - read a line, and NUL terminate
|
|
|
|
* - skip lines which begin with '#'
|
|
|
|
* - parse off the tty names
|
|
|
|
* - parse off a list of user names
|
|
|
|
* - parse off a list of days and times
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
again:
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
2023-01-30 17:23:47 +05:30
|
|
|
* Get the next line and remove optional trailing '\n'.
|
|
|
|
* Lines which begin with '#' are all ignored.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
* libmisc/console.c, libmisc/hushed.c, libmisc/yesno.c,
libmisc/loginprompt.c, libmisc/ttytype.c, libmisc/tz.c,
src/login_nopam.c, src/chpasswd.c, src/chgpasswd.c, lib/port.c:
The size argument of fgets is an int, not a size_t.
* libmisc/loginprompt.c: Ignore the return value from signal()
when the signal handlers are restored.
* src/chpasswd.c: Cast the return value of time() to a long
integer.
* src/chpasswd.c: Use the SCALE macro instead of (24L * 3600L)
for the values to be set in /etc/shadow.
2008-06-13 23:41:09 +05:30
|
|
|
if (fgets (buf, (int) sizeof buf, ports) == 0) {
|
2007-10-07 17:14:02 +05:30
|
|
|
errno = saveerr;
|
|
|
|
return 0;
|
|
|
|
}
|
2008-06-11 01:29:26 +05:30
|
|
|
if ('#' == buf[0]) {
|
2007-10-07 17:14:02 +05:30
|
|
|
goto again;
|
2008-05-26 06:35:04 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the name of the TTY device. It is the first colon
|
|
|
|
* separated field, and is the name of the TTY with no
|
|
|
|
* leading "/dev". The entry '*' is used to specify all
|
|
|
|
* TTY devices.
|
|
|
|
*/
|
|
|
|
|
2023-01-30 17:23:47 +05:30
|
|
|
buf[strcspn (buf, "\n")] = 0;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
port.pt_names = ttys;
|
2007-10-07 17:16:07 +05:30
|
|
|
for (cp = buf, j = 0; j < PORT_TTY; j++) {
|
2007-10-07 17:14:02 +05:30
|
|
|
port.pt_names[j] = cp;
|
2008-06-11 01:29:26 +05:30
|
|
|
while (('\0' != *cp) && (':' != *cp) && (',' != *cp)) {
|
2007-10-07 17:14:02 +05:30
|
|
|
cp++;
|
2008-05-26 06:35:04 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-05-26 06:35:04 +05:30
|
|
|
if ('\0' == *cp) {
|
2007-10-07 17:14:02 +05:30
|
|
|
goto again; /* line format error */
|
2008-05-26 06:35:04 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-06-11 01:29:26 +05:30
|
|
|
if (':' == *cp) { /* end of tty name list */
|
2007-10-07 17:14:02 +05:30
|
|
|
break;
|
2008-06-11 01:29:26 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-06-11 01:29:26 +05:30
|
|
|
if (',' == *cp) { /* end of current tty name */
|
2007-10-07 17:14:02 +05:30
|
|
|
*cp++ = '\0';
|
2008-06-11 01:29:26 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2008-06-11 01:29:26 +05:30
|
|
|
*cp = '\0';
|
|
|
|
cp++;
|
2023-02-01 07:20:14 +05:30
|
|
|
port.pt_names[j + 1] = NULL;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the list of user names. It is the second colon
|
|
|
|
* separated field, and is a comma separated list of user
|
|
|
|
* names. The entry '*' is used to specify all usernames.
|
2023-02-01 07:20:14 +05:30
|
|
|
* The last entry in the list is a NULL pointer.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
2008-06-11 01:29:26 +05:30
|
|
|
if (':' != *cp) {
|
2007-10-07 17:14:02 +05:30
|
|
|
port.pt_users = users;
|
|
|
|
port.pt_users[0] = cp;
|
|
|
|
|
2008-06-11 01:29:26 +05:30
|
|
|
for (j = 1; ':' != *cp; cp++) {
|
|
|
|
if ((',' == *cp) && (j < PORT_IDS)) {
|
|
|
|
*cp = '\0';
|
|
|
|
cp++;
|
|
|
|
port.pt_users[j] = cp;
|
|
|
|
j++;
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
port.pt_users[j] = 0;
|
2008-06-11 01:29:26 +05:30
|
|
|
} else {
|
2007-10-07 17:14:02 +05:30
|
|
|
port.pt_users = 0;
|
2008-06-11 01:29:26 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-06-11 01:29:26 +05:30
|
|
|
if (':' != *cp) {
|
2007-10-07 17:14:02 +05:30
|
|
|
goto again;
|
2008-06-11 01:29:26 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-06-11 01:29:26 +05:30
|
|
|
*cp = '\0';
|
|
|
|
cp++;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the list of valid times. The times field is the third
|
|
|
|
* colon separated field and is a list of days of the week and
|
|
|
|
* times during which this port may be used by this user. The
|
|
|
|
* valid days are 'Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', and 'Sa'.
|
|
|
|
*
|
|
|
|
* In addition, the value 'Al' represents all 7 days, and 'Wk'
|
|
|
|
* represents the 5 weekdays.
|
|
|
|
*
|
|
|
|
* Times are given as HHMM-HHMM. The ending time may be before
|
|
|
|
* the starting time. Days are presumed to wrap at 0000.
|
|
|
|
*/
|
|
|
|
|
2008-06-11 01:29:26 +05:30
|
|
|
if ('\0' == *cp) {
|
2007-10-07 17:14:02 +05:30
|
|
|
port.pt_times = 0;
|
|
|
|
return &port;
|
|
|
|
}
|
|
|
|
|
|
|
|
port.pt_times = ptimes;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get the next comma separated entry
|
|
|
|
*/
|
|
|
|
|
2008-05-26 06:35:04 +05:30
|
|
|
for (j = 0; ('\0' != *cp) && (j < PORT_TIMES); j++) {
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Start off with no days of the week
|
|
|
|
*/
|
|
|
|
|
|
|
|
port.pt_times[j].t_days = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check each two letter sequence to see if it is
|
|
|
|
* one of the abbreviations for the days of the
|
|
|
|
* week or the other two values.
|
|
|
|
*/
|
|
|
|
|
2008-05-26 06:35:04 +05:30
|
|
|
for (i = 0;
|
|
|
|
('\0' != cp[i]) && ('\0' != cp[i + 1]) && isalpha (cp[i]);
|
|
|
|
i += 2) {
|
2007-10-07 17:14:02 +05:30
|
|
|
switch ((cp[i] << 8) | (cp[i + 1])) {
|
2007-10-07 17:16:07 +05:30
|
|
|
case ('S' << 8) | 'u':
|
|
|
|
port.pt_times[j].t_days |= 01;
|
|
|
|
break;
|
|
|
|
case ('M' << 8) | 'o':
|
|
|
|
port.pt_times[j].t_days |= 02;
|
|
|
|
break;
|
|
|
|
case ('T' << 8) | 'u':
|
|
|
|
port.pt_times[j].t_days |= 04;
|
|
|
|
break;
|
|
|
|
case ('W' << 8) | 'e':
|
|
|
|
port.pt_times[j].t_days |= 010;
|
|
|
|
break;
|
|
|
|
case ('T' << 8) | 'h':
|
|
|
|
port.pt_times[j].t_days |= 020;
|
|
|
|
break;
|
|
|
|
case ('F' << 8) | 'r':
|
|
|
|
port.pt_times[j].t_days |= 040;
|
|
|
|
break;
|
|
|
|
case ('S' << 8) | 'a':
|
|
|
|
port.pt_times[j].t_days |= 0100;
|
|
|
|
break;
|
|
|
|
case ('W' << 8) | 'k':
|
|
|
|
port.pt_times[j].t_days |= 076;
|
|
|
|
break;
|
|
|
|
case ('A' << 8) | 'l':
|
|
|
|
port.pt_times[j].t_days |= 0177;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
errno = EINVAL;
|
|
|
|
return 0;
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The default is 'Al' if no days were seen.
|
|
|
|
*/
|
|
|
|
|
2008-06-11 01:29:26 +05:30
|
|
|
if (0 == i) {
|
2007-10-07 17:14:02 +05:30
|
|
|
port.pt_times[j].t_days = 0177;
|
2008-06-11 01:29:26 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* The start and end times are separated from each
|
|
|
|
* other by a '-'. The times are four digit numbers
|
|
|
|
* representing the times of day.
|
|
|
|
*/
|
|
|
|
|
2008-05-26 06:35:04 +05:30
|
|
|
for (dtime = 0; ('\0' != cp[i]) && isdigit (cp[i]); i++) {
|
2007-10-07 17:14:02 +05:30
|
|
|
dtime = dtime * 10 + cp[i] - '0';
|
2008-05-26 06:35:04 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-06-11 01:29:26 +05:30
|
|
|
if (('-' != cp[i]) || (dtime > 2400) || ((dtime % 100) > 59)) {
|
2007-10-07 17:14:02 +05:30
|
|
|
goto again;
|
2008-05-26 06:35:04 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
port.pt_times[j].t_start = dtime;
|
|
|
|
cp = cp + i + 1;
|
|
|
|
|
2008-06-11 01:29:26 +05:30
|
|
|
for (dtime = 0, i = 0;
|
|
|
|
('\0' != cp[i]) && isdigit (cp[i]);
|
|
|
|
i++) {
|
2007-10-07 17:14:02 +05:30
|
|
|
dtime = dtime * 10 + cp[i] - '0';
|
2008-05-26 06:35:04 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-06-11 01:29:26 +05:30
|
|
|
if ( ((',' != cp[i]) && ('\0' != cp[i]))
|
|
|
|
|| (dtime > 2400)
|
|
|
|
|| ((dtime % 100) > 59)) {
|
2007-10-07 17:14:02 +05:30
|
|
|
goto again;
|
2008-05-26 06:35:04 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
port.pt_times[j].t_end = dtime;
|
|
|
|
cp = cp + i + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The end of the list is indicated by a pair of -1's for the
|
|
|
|
* start and end times.
|
|
|
|
*/
|
|
|
|
|
|
|
|
port.pt_times[j].t_start = port.pt_times[j].t_end = -1;
|
|
|
|
|
|
|
|
return &port;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* getttyuser - get ports information for user and tty
|
|
|
|
*
|
|
|
|
* getttyuser() searches the ports file for an entry with a TTY
|
|
|
|
* and user field both of which match the supplied TTY and
|
|
|
|
* user name. The file is searched from the beginning, so the
|
|
|
|
* entries are treated as an ordered list.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
static struct port *getttyuser (const char *tty, const char *user)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
int i, j;
|
|
|
|
struct port *port;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
setportent ();
|
|
|
|
|
2008-05-26 06:35:04 +05:30
|
|
|
while ((port = getportent ()) != NULL) {
|
2008-06-11 01:29:26 +05:30
|
|
|
if ( (0 == port->pt_names)
|
|
|
|
|| (0 == port->pt_users)) {
|
2007-10-07 17:14:02 +05:30
|
|
|
continue;
|
2008-06-11 01:29:26 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-05-26 06:35:04 +05:30
|
|
|
for (i = 0; NULL != port->pt_names[i]; i++) {
|
|
|
|
if (portcmp (port->pt_names[i], tty) == 0) {
|
2007-10-07 17:14:02 +05:30
|
|
|
break;
|
2008-05-26 06:35:04 +05:30
|
|
|
}
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-06-11 01:29:26 +05:30
|
|
|
if (port->pt_names[i] == 0) {
|
2007-10-07 17:14:02 +05:30
|
|
|
continue;
|
2008-06-11 01:29:26 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-05-26 06:35:04 +05:30
|
|
|
for (j = 0; NULL != port->pt_users[j]; j++) {
|
2008-06-11 01:29:26 +05:30
|
|
|
if ( (strcmp (user, port->pt_users[j]) == 0)
|
|
|
|
|| (strcmp (port->pt_users[j], "*") == 0)) {
|
2007-10-07 17:14:02 +05:30
|
|
|
break;
|
2008-05-26 06:35:04 +05:30
|
|
|
}
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
2008-05-26 06:35:04 +05:30
|
|
|
if (port->pt_users[j] != 0) {
|
2007-10-07 17:14:02 +05:30
|
|
|
break;
|
2008-05-26 06:35:04 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
endportent ();
|
|
|
|
return port;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* isttytime - tell if a given user may login at a particular time
|
|
|
|
*
|
|
|
|
* isttytime searches the ports file for an entry which matches
|
|
|
|
* the user name and TTY given.
|
|
|
|
*/
|
|
|
|
|
2008-06-11 01:29:26 +05:30
|
|
|
bool isttytime (const char *id, const char *port, time_t when)
|
2007-10-07 17:14:02 +05:30
|
|
|
{
|
2007-10-07 17:16:07 +05:30
|
|
|
int i;
|
|
|
|
int dtime;
|
|
|
|
struct port *pp;
|
|
|
|
struct tm *tm;
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* Try to find a matching entry for this user. Default to
|
2008-06-11 01:29:26 +05:30
|
|
|
* letting the user in - there are plenty of ways to have an
|
2007-10-07 17:14:02 +05:30
|
|
|
* entry to match all users.
|
|
|
|
*/
|
|
|
|
|
2008-05-26 06:35:04 +05:30
|
|
|
pp = getttyuser (port, id);
|
|
|
|
if (NULL == pp) {
|
2008-06-11 01:29:26 +05:30
|
|
|
return true;
|
2008-05-26 06:35:04 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* The entry is there, but has no time entries - don't
|
|
|
|
* ever let them login.
|
|
|
|
*/
|
|
|
|
|
2008-06-11 01:29:26 +05:30
|
|
|
if (0 == pp->pt_times) {
|
|
|
|
return false;
|
2008-05-26 06:35:04 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
/*
|
|
|
|
* The current time is converted to HHMM format for
|
2008-05-26 06:35:04 +05:30
|
|
|
* comparison against the time values in the TTY entry.
|
2007-10-07 17:14:02 +05:30
|
|
|
*/
|
|
|
|
|
|
|
|
tm = localtime (&when);
|
|
|
|
dtime = tm->tm_hour * 100 + tm->tm_min;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Each time entry is compared against the current
|
|
|
|
* time. For entries with the start after the end time,
|
2008-05-26 06:35:04 +05:30
|
|
|
* the comparison is made so that the time is between
|
2007-10-07 17:14:02 +05:30
|
|
|
* midnight and either the start or end time.
|
|
|
|
*/
|
|
|
|
|
2007-10-07 17:16:07 +05:30
|
|
|
for (i = 0; pp->pt_times[i].t_start != -1; i++) {
|
2008-06-11 01:29:26 +05:30
|
|
|
if (!(pp->pt_times[i].t_days & PORT_DAY (tm->tm_wday))) {
|
2007-10-07 17:14:02 +05:30
|
|
|
continue;
|
2008-06-11 01:29:26 +05:30
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
|
|
|
|
if (pp->pt_times[i].t_start <= pp->pt_times[i].t_end) {
|
2008-06-11 01:29:26 +05:30
|
|
|
if ( (dtime >= pp->pt_times[i].t_start)
|
|
|
|
&& (dtime <= pp->pt_times[i].t_end)) {
|
|
|
|
return true;
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
} else {
|
2008-06-11 01:29:26 +05:30
|
|
|
if ( (dtime >= pp->pt_times[i].t_start)
|
|
|
|
|| (dtime <= pp->pt_times[i].t_end)) {
|
|
|
|
return true;
|
|
|
|
}
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* No matching time entry was found, user shouldn't
|
|
|
|
* be let in right now.
|
|
|
|
*/
|
|
|
|
|
2008-06-11 01:29:26 +05:30
|
|
|
return false;
|
2007-10-07 17:14:02 +05:30
|
|
|
}
|
2008-05-26 06:35:04 +05:30
|
|
|
|