From 4c5125627348083a104b166bb120e07adb5d1a6f Mon Sep 17 00:00:00 2001 From: Serge Date: Fri, 27 May 2022 18:11:42 -0700 Subject: [PATCH] Update cmd/login. --- include/grp.h | 1 + include/unistd.h | 1 + include/utmp.h | 2 ++ src/cmd/login/login.c | 48 ++++++++++++++++++++++------------------ src/libc/string/Makefile | 4 ++-- src/libc/string/stpcpy.c | 41 ++++++++++++++++++++++++++++++++++ 6 files changed, 74 insertions(+), 23 deletions(-) create mode 100644 src/libc/string/stpcpy.c diff --git a/include/grp.h b/include/grp.h index 4a9c999..8c65026 100644 --- a/include/grp.h +++ b/include/grp.h @@ -14,3 +14,4 @@ void setgrent(void); void endgrent(void); int setgroups(size_t size, const gid_t *list); int getgrouplist(char *uname, gid_t agroup, gid_t *groups, int *grpcnt); +int initgroups(char *uname, int agroup); diff --git a/include/unistd.h b/include/unistd.h index 81e7154..66464be 100644 --- a/include/unistd.h +++ b/include/unistd.h @@ -65,6 +65,7 @@ gid_t getegid(); uid_t geteuid(); gid_t getgid(); char *getlogin(); +int setlogin(const char *name); pid_t getpgrp(); pid_t getpid(); pid_t getppid(); diff --git a/include/utmp.h b/include/utmp.h index a7d36f4..d77e5e6 100644 --- a/include/utmp.h +++ b/include/utmp.h @@ -25,3 +25,5 @@ struct utmp { char ut_host[UT_HOSTSIZE]; long ut_time; }; + +void login(struct utmp *ut); diff --git a/src/cmd/login/login.c b/src/cmd/login/login.c index c8a1de4..079843d 100644 --- a/src/cmd/login/login.c +++ b/src/cmd/login/login.c @@ -24,7 +24,6 @@ #include #include #include - #include #include #include @@ -41,6 +40,7 @@ #include #include #include +#include #ifdef KERBEROS #include @@ -73,6 +73,15 @@ char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; +void getloginname(void); +void badlogin(char *name); +void checknologin(void); +int rootterm(char *ttyn); +void sleepexit(int eval); +void dolastlog(int quiet); +char *stypeof(char *ttyid); +void motd(void); + void timedout(sig) int sig; { @@ -80,7 +89,7 @@ void timedout(sig) exit(0); } -main(argc, argv) +int main(argc, argv) int argc; char **argv; { @@ -95,9 +104,6 @@ main(argc, argv) int quietlog, passwd_req, ioctlval; char *domain, *salt, *envinit[1], *ttyn, *pp; char tbuf[MAXPATHLEN + 2], tname[sizeof(_PATH_TTY) + 10]; - char *ctime(), *ttyname(), *stypeof(), *crypt(), *getpass(); - time_t time(); - off_t lseek(); (void)signal(SIGALRM, timedout); (void)alarm((u_int) timeout); @@ -109,7 +115,7 @@ main(argc, argv) #endif /* * -p is used by getty to tell login not to destroy the environment - * -f is used to skip a second login authentication + * -f is used to skip a second login authentication * -h is used by other servers to pass the name of the remote * host to login so that it may be placed in utmp and wtmp */ @@ -171,7 +177,7 @@ main(argc, argv) (void)sprintf(tname, "%s??", _PATH_TTY); ttyn = tname; } - if (tty = rindex(ttyn, '/')) + if ((tty = rindex(ttyn, '/'))) ++tty; else tty = ttyn; @@ -198,7 +204,7 @@ main(argc, argv) failures = 0; } (void)strcpy(tbuf, username); - if (pwd = getpwnam(username)) { + if ((pwd = getpwnam(username))) { salt = pwd->pw_passwd; //printf("getpwnam returned username='%s' password='%s'\n", pwd->pw_name, pwd->pw_passwd); } else { @@ -385,12 +391,13 @@ nouser: if (tty[sizeof("tty")-1] == 'd') syslog(LOG_INFO, "DIALUP %s, %s", tty, pwd->pw_name); - if (pwd->pw_uid == 0) + if (pwd->pw_uid == 0) { if (hostname) syslog(LOG_NOTICE, "ROOT LOGIN ON %s FROM %s", tty, hostname); else syslog(LOG_NOTICE, "ROOT LOGIN ON %s", tty); + } if (!quietlog) { struct stat st; @@ -422,7 +429,7 @@ nouser: exit(0); } -getloginname() +void getloginname() { register int ch; register char *p; @@ -438,7 +445,7 @@ getloginname() if (p < nbuf + UT_NAMESIZE) *p++ = ch; } - if (p > nbuf) + if (p > nbuf) { if (nbuf[0] == '-') (void)fprintf(stderr, "login names may not start with '-'.\n"); @@ -447,10 +454,11 @@ getloginname() username = nbuf; break; } + } } } -rootterm(ttyn) +int rootterm(ttyn) char *ttyn; { struct ttyent *t; @@ -466,7 +474,7 @@ void sigint(sig) longjmp(motdinterrupt, 1); } -motd() +void motd() { register int fd, nchars; sig_t oldint; @@ -482,7 +490,7 @@ motd() (void)close(fd); } -checknologin() +void checknologin() { register int fd, nchars; char tbuf[BUFSIZ]; @@ -494,12 +502,11 @@ checknologin() } } -dolastlog(quiet) +void dolastlog(quiet) int quiet; { struct lastlog ll; int fd; - char *ctime(); if ((fd = open(_PATH_LASTLOG, O_RDWR, 0)) >= 0) { (void)lseek(fd, (off_t)pwd->pw_uid * sizeof(ll), L_SET); @@ -527,7 +534,7 @@ dolastlog(quiet) } } -badlogin(name) +void badlogin(name) char *name; { if (failures == 0) @@ -543,8 +550,7 @@ badlogin(name) #undef UNKNOWN #define UNKNOWN "su" -char * -stypeof(ttyid) +char *stypeof(ttyid) char *ttyid; { struct ttyent *t; @@ -552,7 +558,7 @@ stypeof(ttyid) return(ttyid && (t = getttynam(ttyid)) ? t->ty_type : UNKNOWN); } -getstr(buf, cnt, err) +void getstr(buf, cnt, err) char *buf, *err; int cnt; { @@ -569,7 +575,7 @@ getstr(buf, cnt, err) } while (ch); } -sleepexit(eval) +void sleepexit(eval) int eval; { sleep((u_int)5); diff --git a/src/libc/string/Makefile b/src/libc/string/Makefile index d1fc06b..c18c3f3 100644 --- a/src/libc/string/Makefile +++ b/src/libc/string/Makefile @@ -9,8 +9,8 @@ include $(TOPSRC)/target.mk DEFS = CFLAGS += ${DEFS} -Os -SRCS = strcspn.c strpbrk.c strerror.c strsep.c strspn.c strstr.c strtok.c strtok_r.c -OBJS = strcspn.o strpbrk.o strerror.o strsep.o strspn.o strstr.o strtok.o strtok_r.o +SRCS = strcspn.c strpbrk.c strerror.c strsep.c strspn.c strstr.c strtok.c strtok_r.c stpcpy.c +OBJS = strcspn.o strpbrk.o strerror.o strsep.o strspn.o strstr.o strtok.o strtok_r.o stpcpy.o all: string.a diff --git a/src/libc/string/stpcpy.c b/src/libc/string/stpcpy.c new file mode 100644 index 0000000..6582f09 --- /dev/null +++ b/src/libc/string/stpcpy.c @@ -0,0 +1,41 @@ +/*- + * SPDX-License-Identifier: BSD-3-Clause + * + * Copyright (c) 1999 + * David E. O'Brien + * Copyright (c) 1988, 1993 + * The Regents of the University of California. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ +#include + +char * +stpcpy(char * __restrict to, const char * __restrict from) +{ + + for (; (*to = *from); ++from, ++to); + return(to); +}