X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=loginutils%2Flogin.c;h=5a75ed2188b8fb6546b03e00da35058877d0b0de;hb=e99a92dc2f7d45904bf7635ccb97895839000729;hp=900a7c0422ecc1008b528ecf89868727e44f09f2;hpb=636a1f85e89432601c59cdc3239fc867b4adf051;p=oweals%2Fbusybox.git diff --git a/loginutils/login.c b/loginutils/login.c index 900a7c042..5a75ed218 100644 --- a/loginutils/login.c +++ b/loginutils/login.c @@ -80,7 +80,7 @@ static void read_or_build_utent(struct utmp *utptr, int picky) * remotely meaningful by skipping "tty"... */ strncpy(utptr->ut_id, short_tty + 3, sizeof(utptr->ut_id)); strncpy(utptr->ut_user, "LOGIN", sizeof(utptr->ut_user)); - utptr->ut_time = time(NULL); + utptr->ut_tv.tv_sec = time(NULL); } if (!picky) /* root login */ memset(utptr->ut_host, 0, sizeof(utptr->ut_host)); @@ -96,7 +96,7 @@ static void write_utent(struct utmp *utptr, const char *username) { utptr->ut_type = USER_PROCESS; strncpy(utptr->ut_user, username, sizeof(utptr->ut_user)); - utptr->ut_time = time(NULL); + utptr->ut_tv.tv_sec = time(NULL); /* other fields already filled in by read_or_build_utent above */ setutent(); pututline(utptr); @@ -122,7 +122,7 @@ static void die_if_nologin(void) if (access("/etc/nologin", F_OK)) return; - fp = fopen("/etc/nologin", "r"); + fp = fopen_for_read("/etc/nologin"); if (fp) { while ((c = getc(fp)) != EOF) bb_putchar((c=='\n') ? '\r' : c); @@ -139,30 +139,20 @@ static ALWAYS_INLINE void die_if_nologin(void) {} #if ENABLE_FEATURE_SECURETTY && !ENABLE_PAM static int check_securetty(void) { - FILE *fp; - int i; - char buf[256]; - - fp = fopen("/etc/securetty", "r"); - if (!fp) { - /* A missing securetty file is not an error. */ - return 1; - } - while (fgets(buf, sizeof(buf)-1, fp)) { - for (i = strlen(buf)-1; i >= 0; --i) { - if (!isspace(buf[i])) + char *buf; + int ret = 1; + parser_t *parser = config_open2("/etc/securetty", fopen_for_read); + /* N.B. A missing securetty file is not an error. */ + if (parser) { + while (config_read(parser, &buf, 1, 1, "# \t", 0)) { + if (strcmp(buf, short_tty) == 0) break; } - buf[++i] = '\0'; - if (!buf[0] || (buf[0] == '#')) - continue; - if (strcmp(buf, short_tty) == 0) { - fclose(fp); - return 1; - } + config_close(parser); + // buf != NULL here iff config file was empty (OK) or buf equals short_tty (OK) + ret = buf != NULL; } - fclose(fp); - return 0; + return ret; } #else static ALWAYS_INLINE int check_securetty(void) { return 1; } @@ -206,7 +196,7 @@ static void motd(void) } } -static void alarm_handler(int sig ATTRIBUTE_UNUSED) +static void alarm_handler(int sig UNUSED_PARAM) { /* This is the escape hatch! Poor serial line users and the like * arrive here when their connection is broken. @@ -221,7 +211,7 @@ static void alarm_handler(int sig ATTRIBUTE_UNUSED) } int login_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; -int login_main(int argc ATTRIBUTE_UNUSED, char **argv) +int login_main(int argc UNUSED_PARAM, char **argv) { enum { LOGIN_OPT_f = (1<<0),