From 2b6fc908bc368b540845a313c3b8a867c5ad9a42 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 7 Dec 2006 00:25:35 +0100 Subject: Imported from util-linux-2.8 tarball. --- login-utils/agetty.8 | 6 +-- login-utils/agetty.c | 9 +--- login-utils/checktty.c | 7 +-- login-utils/chfn.c | 10 ++-- login-utils/chsh.c | 10 ++-- login-utils/cryptocard.c | 7 ++- login-utils/last.c | 10 ---- login-utils/login.c | 129 +++++++++++++++++++---------------------------- login-utils/mesg.c | 10 ---- login-utils/my_crypt.h | 3 ++ login-utils/newgrp.c | 2 +- login-utils/passwd.1 | 4 ++ login-utils/passwd.c | 11 ++-- login-utils/ttymsg.c | 37 +++++++++----- login-utils/vipw.c | 24 ++++----- login-utils/wall.c | 34 ++++++------- 16 files changed, 134 insertions(+), 179 deletions(-) create mode 100644 login-utils/my_crypt.h (limited to 'login-utils') diff --git a/login-utils/agetty.8 b/login-utils/agetty.8 index ebbc27588..57c9b6b46 100644 --- a/login-utils/agetty.8 +++ b/login-utils/agetty.8 @@ -158,9 +158,9 @@ linefeed character before sending the \fI/etc/issue\fP (or other) file and the login prompt. Very useful in connection with the \-I option. .PP .SH EXAMPLES -.na -.nf -This section shows sample command entries for the \fI/etc/inittab\fP file. +This section shows examples for the process field of an entry in the +\fI/etc/inittab\fP file. You'll have to prepend appropriate values +for the other fields. See \fIinittab(5)\fP for more details. For a hard-wired line or a console tty: .ti +5 diff --git a/login-utils/agetty.c b/login-utils/agetty.c index ba28336b6..039589591 100644 --- a/login-utils/agetty.c +++ b/login-utils/agetty.c @@ -6,13 +6,10 @@ -f option added by Eric Rasmussen - 12/28/95 */ -#ifndef lint -char sccsid[] = "@(#) agetty.c 1.29 9/1/91 23:22:00"; -#endif - #include #include #include +#include #include #include #include @@ -510,7 +507,6 @@ update_utmp(line) int mypid = getpid(); long time(); long lseek(); - char *strncpy(); struct utmp *utp; /* @@ -1162,9 +1158,6 @@ error(va_alist) char buf[BUFSIZ]; char *bp; - char *strcpy(); - char *strcat(); - /* * If the diagnostic is reported via syslog(3), the process name is * automatically prepended to the message. If we write directly to diff --git a/login-utils/checktty.c b/login-utils/checktty.c index e5d03815a..f01d0ee82 100644 --- a/login-utils/checktty.c +++ b/login-utils/checktty.c @@ -3,8 +3,6 @@ Fixed by JDS June 1996 to clear lists and close files */ -#define _GNU_SOURCE /* for snprintf */ - #include #include @@ -143,7 +141,10 @@ isapty(const char *tty) char devname[100]; struct stat stb; - snprintf(devname, sizeof(devname), "/dev/%s", tty); + /* avoid snprintf - old systems do not have it */ + if (strlen(tty) + 6 > sizeof(devname)) + return 0; + sprintf(devname, "/dev/%s", tty); #if defined(__linux__) && defined(PTY_SLAVE_MAJOR) /* this is for linux 1.3 and newer */ diff --git a/login-utils/chfn.c b/login-utils/chfn.c index e81c5c18b..8e962db05 100644 --- a/login-utils/chfn.c +++ b/login-utils/chfn.c @@ -7,8 +7,8 @@ * there is no warranty. * * $Author: aebr $ - * $Revision: 1.15 $ - * $Date: 1997/07/06 23:10:41 $ + * $Revision: 1.18 $ + * $Date: 1998/06/11 22:30:11 $ * * Updated Thu Oct 12 09:19:26 1995 by faith@cs.unc.edu with security * patches from Zefram @@ -21,9 +21,6 @@ * */ -static char rcsId[] = "$Version: $Id: chfn.c,v 1.15 1997/07/06 23:10:41 aebr Exp $ $"; - -#define _XOPEN_SOURCE /* for crypt() */ #define _BSD_SOURCE /* for strcasecmp() */ #include @@ -35,6 +32,7 @@ static char rcsId[] = "$Version: $Id: chfn.c,v 1.15 1997/07/06 23:10:41 aebr Exp #include #include #include +#include "my_crypt.h" #include "../version.h" #if REQUIRE_PASSWORD && USE_PAM @@ -161,7 +159,7 @@ int main (argc, argv) exit(1); } retcode = pam_acct_mgmt(pamh, 0); - if (retcode == PAM_AUTHTOKEN_REQD) { + if (retcode == PAM_NEW_AUTHTOK_REQD) { retcode = pam_chauthtok(pamh, PAM_CHANGE_EXPIRED_AUTHTOK); } else if (retcode) { puts("Password error."); diff --git a/login-utils/chsh.c b/login-utils/chsh.c index 3cafc966b..f64cd0b78 100644 --- a/login-utils/chsh.c +++ b/login-utils/chsh.c @@ -7,8 +7,8 @@ * there is no warranty. * * $Author: aebr $ - * $Revision: 1.16 $ - * $Date: 1997/07/06 00:12:08 $ + * $Revision: 1.19 $ + * $Date: 1998/06/11 22:30:14 $ * * Updated Thu Oct 12 09:33:15 1995 by faith@cs.unc.edu with security * patches from Zefram @@ -24,9 +24,6 @@ * */ -static char rcsId[] = "$Version: $Id: chsh.c,v 1.16 1997/07/06 00:12:08 aebr Exp $ $"; - -#define _XOPEN_SOURCE /* to get definition of crypt() */ #if 0 #define _POSIX_SOURCE 1 #endif @@ -40,6 +37,7 @@ static char rcsId[] = "$Version: $Id: chsh.c,v 1.16 1997/07/06 00:12:08 aebr Exp #include #include #include +#include "my_crypt.h" #include "../version.h" #if REQUIRE_PASSWORD && USE_PAM @@ -156,7 +154,7 @@ int main (argc, argv) exit(1); } retcode = pam_acct_mgmt(pamh, 0); - if (retcode == PAM_AUTHTOKEN_REQD) { + if (retcode == PAM_NEW_AUTHTOK_REQD) { retcode = pam_chauthtok(pamh, PAM_CHANGE_EXPIRED_AUTHTOK); } else if (retcode) { puts("Password error."); diff --git a/login-utils/cryptocard.c b/login-utils/cryptocard.c index e735c7273..b3edc6fd4 100644 --- a/login-utils/cryptocard.c +++ b/login-utils/cryptocard.c @@ -85,7 +85,9 @@ get_key() int rfd; struct stat statbuf; - snprintf(keyfile, sizeof(keyfile), "%s/.cryptocard", pwd->pw_dir); + if (strlen(pwd->pw_dir) + 13 > sizeof(keyfile)) + goto bail_out; + sprintf(keyfile, "%s/.cryptocard", pwd->pw_dir); if ((rfd = open(keyfile, O_RDONLY)) < 0) { syslog(LOG_NOTICE, "can't open %s for reading", keyfile); @@ -182,7 +184,8 @@ cryptocard(void) challenge = generate_challenge(); if (challenge == NULL) return 0; - snprintf(prompt, sizeof(prompt), "%s Password: ", challenge); + if (strlen(challenge) + 13 > sizeof(prompt)) return 0; + sprintf(prompt, "%s Password: ", challenge); alarm((unsigned int)timeout); /* give user time to fiddle with card */ response = getpass(prompt); /* presents challenge and gets response */ diff --git a/login-utils/last.c b/login-utils/last.c index fa9f8f837..98ffef38f 100644 --- a/login-utils/last.c +++ b/login-utils/last.c @@ -18,16 +18,6 @@ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ -#ifndef lint -char copyright[] = -"@(#) Copyright (c) 1987 Regents of the University of California.\n\ - All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -static char sccsid[] = "@(#)last.c 5.11 (Berkeley) 6/29/88"; -#endif /* not lint */ - /* * last */ diff --git a/login-utils/login.c b/login-utils/login.c index c1626183e..ebb0a22da 100644 --- a/login-utils/login.c +++ b/login-utils/login.c @@ -70,24 +70,12 @@ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ -#ifndef lint -char copyright[] = - "@(#) Copyright (c) 1980, 1987, 1988 The Regents of the University of California.\n\ - All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -static char sccsid[] = "@(#)login.c 5.40 (Berkeley) 5/9/89"; -#endif /* not lint */ - /* * login [ name ] * login -h hostname (for telnetd, etc.) * login -f name (for pre-authenticated login: datakit, xterm, etc.) */ -#define _GNU_SOURCE /* to get definition of snprintf */ - /* #define TESTING */ #ifdef TESTING @@ -123,6 +111,7 @@ static char sccsid[] = "@(#)login.c 5.40 (Berkeley) 5/9/89"; #include #include #include +#include "my_crypt.h" #ifdef __linux__ # include @@ -144,15 +133,12 @@ static char sccsid[] = "@(#)login.c 5.40 (Berkeley) 5/9/89"; # include # define PAM_MAX_LOGIN_TRIES 3 # define PAM_FAIL_CHECK if (retcode != PAM_SUCCESS) { \ - fprintf(stderr,"\n%s\n",pam_strerror(retcode)); \ - syslog(LOG_ERR,"%s",pam_strerror(retcode)); \ + fprintf(stderr,"\n%s\n",pam_strerror(pamh, retcode)); \ + syslog(LOG_ERR,"%s",pam_strerror(pamh, retcode)); \ pam_end(pamh, retcode); exit(1); \ } # define PAM_END { retcode = pam_close_session(pamh,0); \ pam_end(pamh,retcode); } -# define PAM_END { \ - retcode = pam_close_session(pamh,0); pam_end(pamh,retcode); \ -} #endif #ifndef __linux__ @@ -295,23 +281,14 @@ main(argc, argv) char * childArgv[10]; char * buff; int childArgc = 0; - int error = 0; #ifdef USE_PAM int retcode; pam_handle_t *pamh = NULL; struct pam_conv conv = { misc_conv, NULL }; pid_t childPid; int childStatus; - void * oldSigHandler; #endif - -#ifdef __linux__ - char tmp[100]; - /* Just as arbitrary as mountain time: */ - /* (void)setenv("TZ", "MET-1DST",0); */ -#endif - signal(SIGALRM, timedout); alarm((unsigned int)timeout); signal(SIGQUIT, SIG_IGN); @@ -407,7 +384,8 @@ main(argc, argv) ttyn = ttyname(0); if (ttyn == NULL || *ttyn == '\0') { - snprintf(tname, sizeof(tname), "%s??", _PATH_TTY); + /* no snprintf required - see definition of tname */ + sprintf(tname, "%s??", _PATH_TTY); ttyn = tname; } @@ -461,8 +439,8 @@ main(argc, argv) retcode = pam_start("login",username, &conv, &pamh); if(retcode != PAM_SUCCESS) { fprintf(stderr,"login: PAM Failure, aborting: %s\n", - pam_strerror(retcode)); - syslog(LOG_ERR,"Couldn't initialize PAM: %s", pam_strerror(retcode)); + pam_strerror(pamh, retcode)); + syslog(LOG_ERR,"Couldn't initialize PAM: %s", pam_strerror(pamh, retcode)); exit(99); } /* hostname & tty are either set to NULL or their correct values, @@ -494,7 +472,7 @@ main(argc, argv) (retcode == PAM_AUTHINFO_UNAVAIL))) { pam_get_item(pamh, PAM_USER, (const void **) &username); syslog(LOG_NOTICE,"FAILED LOGIN %d FROM %s FOR %s, %s", - failcount, hostname,username,pam_strerror(retcode)); + failcount, hostname,username,pam_strerror(pamh, retcode)); fprintf(stderr,"Login incorrect\n\n"); pam_set_item(pamh,PAM_USER,NULL); retcode = pam_authenticate(pamh, 0); @@ -506,10 +484,10 @@ main(argc, argv) if (retcode == PAM_MAXTRIES) syslog(LOG_NOTICE,"TOO MANY LOGIN TRIES (%d) FROM %s FOR " "%s, %s", failcount, hostname, username, - pam_strerror(retcode)); + pam_strerror(pamh, retcode)); else syslog(LOG_NOTICE,"FAILED LOGIN SESSION FROM %s FOR %s, %s", - hostname, username, pam_strerror(retcode)); + hostname, username, pam_strerror(pamh, retcode)); fprintf(stderr,"\nLogin incorrect\n"); pam_end(pamh, retcode); @@ -518,7 +496,7 @@ main(argc, argv) retcode = pam_acct_mgmt(pamh, 0); - if(retcode == PAM_AUTHTOKEN_REQD) { + if(retcode == PAM_NEW_AUTHTOK_REQD) { retcode = pam_chauthtok(pamh, PAM_CHANGE_EXPIRED_AUTHTOK); } @@ -533,7 +511,7 @@ main(argc, argv) pwd = getpwnam(username); if (pwd) initgroups(username, pwd->pw_gid); - retcode = pam_setcred(pamh, PAM_CRED_ESTABLISH); + retcode = pam_setcred(pamh, PAM_ESTABLISH_CRED); PAM_FAIL_CHECK; retcode = pam_open_session(pamh, 0); @@ -717,16 +695,20 @@ main(argc, argv) char tmpstr[MAXPATHLEN]; uid_t ruid = getuid(); gid_t egid = getegid(); - - snprintf(tmpstr, sizeof(tmpstr), - "%s/%s", pwd->pw_dir, _PATH_HUSHLOGIN); - - setregid(-1, pwd->pw_gid); - setreuid(0, pwd->pw_uid); - quietlog = (access(tmpstr, R_OK) == 0); - setuid(0); /* setreuid doesn't do it alone! */ - setreuid(ruid, 0); - setregid(-1, egid); + + /* avoid snprintf - old systems do not have it, or worse, + have a libc in which snprintf is the same as sprintf */ + if (strlen(pwd->pw_dir) + sizeof(_PATH_HUSHLOGIN) + 2 > MAXPATHLEN) + quietlog = 0; + else { + sprintf(tmpstr, "%s/%s", pwd->pw_dir, _PATH_HUSHLOGIN); + setregid(-1, pwd->pw_gid); + setreuid(0, pwd->pw_uid); + quietlog = (access(tmpstr, R_OK) == 0); + setuid(0); /* setreuid doesn't do it alone! */ + setreuid(ruid, 0); + setregid(-1, egid); + } } #ifndef __linux__ @@ -921,8 +903,13 @@ main(argc, argv) setenv("TERM", termenv, 1); /* mailx will give a funny error msg if you forget this one */ - snprintf(tmp, sizeof(tmp), "%s/%s", _PATH_MAILDIR, pwd->pw_name); - setenv("MAIL",tmp,0); + { char tmp[MAXPATHLEN]; + /* avoid snprintf */ + if (sizeof(_PATH_MAILDIR) + strlen(pwd->pw_name) + 1 < MAXPATHLEN) { + sprintf(tmp, "%s/%s", _PATH_MAILDIR, pwd->pw_name); + setenv("MAIL",tmp,0); + } + } /* LOGNAME is not documented in login(1) but HP-UX 6.5 does it. We'll not allow modifying it. @@ -971,11 +958,13 @@ main(argc, argv) struct stat st; motd(); - snprintf(tbuf, sizeof(tbuf), - "%s/%s", _PATH_MAILDIR, pwd->pw_name); - if (stat(tbuf, &st) == 0 && st.st_size != 0) - printf("You have %smail.\n", - (st.st_mtime > st.st_atime) ? "new " : ""); + /* avoid snprintf */ + if (sizeof(_PATH_MAILDIR) + strlen(pwd->pw_name) + 1 < sizeof(tbuf)) { + sprintf(tbuf, "%s/%s", _PATH_MAILDIR, pwd->pw_name); + if (stat(tbuf, &st) == 0 && st.st_size != 0) + printf("You have %smail.\n", + (st.st_mtime > st.st_atime) ? "new " : ""); + } } signal(SIGALRM, SIG_DFL); @@ -1034,38 +1023,22 @@ main(argc, argv) childArgv[childArgc++] = NULL; -#ifndef USE_PAM - execvp(childArgv[0], childArgv + 1); - error = 1; -#else /* USE_PAM */ - oldSigHandler = signal(SIGINT, SIG_IGN); - childPid = fork(); - if (childPid < 0) { - /* error in fork() */ - fprintf(stderr,"login: failure forking: %s", strerror(errno)); - PAM_END; - exit(0); - } else if (childPid) { - /* parent */ - wait(&childStatus); - signal(SIGINT, oldSigHandler); - PAM_END; - - if (!WIFEXITED(&childStatus)) error = 1; - } else { - /* child */ - execvp(childArgv[0], childArgv + 1); - exit(1); - } +#ifdef USE_PAM + /* There was some junk with fork()/exec()/signal()/wait() here + that was incorrect, and util-linux-2.7-11.src.rpm contains + a patch that makes the fork entirely useless. + If you introduce one again, please document in the source + what its purpose is. - aeb */ + PAM_END; #endif /* USE_PAM */ - if (error) { - if (!strcmp(childArgv[0], "/bin/sh")) + execvp(childArgv[0], childArgv + 1); + + if (!strcmp(childArgv[0], "/bin/sh")) fprintf(stderr, "login: couldn't exec shell script: %s.\n", strerror(errno)); - else + else fprintf(stderr, "login: no shell: %s.\n", strerror(errno)); - } exit(0); } diff --git a/login-utils/mesg.c b/login-utils/mesg.c index 4e4916357..d05d333c9 100644 --- a/login-utils/mesg.c +++ b/login-utils/mesg.c @@ -41,16 +41,6 @@ * */ -#ifndef lint -static char copyright[] = -"@(#) Copyright (c) 1987, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -static char sccsid[] = "@(#)mesg.c 8.2 (Berkeley) 1/21/94"; -#endif /* not lint */ - #include #include diff --git a/login-utils/my_crypt.h b/login-utils/my_crypt.h new file mode 100644 index 000000000..efb1a66fd --- /dev/null +++ b/login-utils/my_crypt.h @@ -0,0 +1,3 @@ +#if defined (__GNU_LIBRARY__) && __GNU_LIBRARY__ > 1 +#include +#endif diff --git a/login-utils/newgrp.c b/login-utils/newgrp.c index 65dd00d95..5c26a4a0e 100644 --- a/login-utils/newgrp.c +++ b/login-utils/newgrp.c @@ -3,7 +3,6 @@ /* Vesa Roukonen added code for asking password */ /* Currently maintained at ftp://ftp.daimi.aau.dk/pub/linux/poe/ */ -#define _XOPEN_SOURCE /* for crypt() */ #include #include #include @@ -11,6 +10,7 @@ #include #include #include "pathnames.h" +#include "my_crypt.h" #ifndef TRUE # define TRUE 1 diff --git a/login-utils/passwd.1 b/login-utils/passwd.1 index c696c53d3..db44aa8e9 100644 --- a/login-utils/passwd.1 +++ b/login-utils/passwd.1 @@ -92,6 +92,10 @@ o must not match neither the username nor any word of the realname, neither in normal nor in reverse order, neither at the beginning nor at the end. +.SH BUGS +If you change your mind there is no escaping from this program. +It will insist on a new password until killed from another terminal. +(This is caused by a bug in getpass(3): it ignores signals.) .SH FILES .TP .I /etc/passwd diff --git a/login-utils/passwd.c b/login-utils/passwd.c index f707c0521..4ed1b74d7 100644 --- a/login-utils/passwd.c +++ b/login-utils/passwd.c @@ -19,8 +19,12 @@ /* * Sun Oct 15 13:18:34 1995 Martin Schulze * - * I have completely rewritten the whole argument handlig (what?) + * I have completely rewritten the whole argument handling (what?) * to support two things. First I wanted "passwd $user $pw" to + + (a very bad idea; command lines are visible to people doing ps + or running a background job that just collects all command lines) + * work and second I wanted simplicity checks to be done for * root, too. Only root can turn this of using the -f * switch. Okay, I started with this to support -V version @@ -59,10 +63,7 @@ #include #include #include - -#if defined (__GNU_LIBRARY__) && __GNU_LIBRARY__ > 1 -#include -#endif +#include "my_crypt.h" #if 0 # include "../version.h" diff --git a/login-utils/ttymsg.c b/login-utils/ttymsg.c index 1f5fd1f5d..7caf35be3 100644 --- a/login-utils/ttymsg.c +++ b/login-utils/ttymsg.c @@ -34,10 +34,6 @@ * */ -#ifndef lint -static char sccsid[] = "@(#)ttymsg.c 8.2 (Berkeley) 11/16/93"; -#endif /* not lint */ - #include #include #include @@ -69,7 +65,7 @@ ttymsg(iov, iovcnt, line, tmout) int tmout; { static char device[MAXNAMLEN]; - static char errbuf[1024]; + static char errbuf[MAXNAMLEN+1024]; register int cnt, fd, left, wret; struct iovec localiov[6]; int forked = 0; @@ -79,11 +75,15 @@ ttymsg(iov, iovcnt, line, tmout) if (strchr(line, '/')) { /* A slash is an attempt to break security... */ - (void) snprintf(errbuf, sizeof(errbuf), "'/' in \"%s\"", - device); + (void) sprintf(errbuf, "'/' in \"%s\"", device); + errbuf[1024] = 0; /* protect caller */ + return (errbuf); + } + if (strlen(line) + sizeof(_PATH_DEV) + 1 > sizeof(device)) { + (void) sprintf(errbuf, "excessively long line arg"); return (errbuf); } - (void) snprintf(device, sizeof(device), "%s%s", _PATH_DEV, line); + (void) sprintf(device, "%s%s", _PATH_DEV, line); /* * open will fail on slip lines or exclusive-use lines @@ -92,8 +92,10 @@ ttymsg(iov, iovcnt, line, tmout) if ((fd = open(device, O_WRONLY|O_NONBLOCK, 0)) < 0) { if (errno == EBUSY || errno == EACCES) return (NULL); - (void) snprintf(errbuf, sizeof(errbuf), - "%s: %s", device, strerror(errno)); + if (strlen(strerror(errno)) > 1000) + return (NULL); + (void) sprintf(errbuf, "%s: %s", device, strerror(errno)); + errbuf[1024] = 0; return (errbuf); } @@ -131,8 +133,11 @@ ttymsg(iov, iovcnt, line, tmout) } cpid = fork(); if (cpid < 0) { - (void) snprintf(errbuf, sizeof(errbuf), - "fork: %s", strerror(errno)); + if (strlen(strerror(errno)) > 1000) + (void) sprintf(errbuf, "cannot fork"); + else + (void) sprintf(errbuf, + "fork: %s", strerror(errno)); (void) close(fd); return (errbuf); } @@ -158,8 +163,12 @@ ttymsg(iov, iovcnt, line, tmout) (void) close(fd); if (forked) _exit(1); - (void) snprintf(errbuf, sizeof(errbuf), - "%s: %s", device, strerror(errno)); + if (strlen(strerror(errno)) > 1000) + (void) sprintf(errbuf, "%s: BAD ERROR", device); + else + (void) sprintf(errbuf, "%s: %s", device, + strerror(errno)); + errbuf[1024] = 0; return (errbuf); } diff --git a/login-utils/vipw.c b/login-utils/vipw.c index 6eff4f3b3..a5763b105 100644 --- a/login-utils/vipw.c +++ b/login-utils/vipw.c @@ -39,17 +39,6 @@ * Martin Schulze's patches adapted to Util-Linux by Nicolai Langfeldt. */ -#ifndef lint -char copyright[] = -"@(#) Copyright (c) 1987 Regents of the University of California.\n\ - All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -/*static char sccsid[] = "from: @(#)vipw.c 5.16 (Berkeley) 3/3/91";*/ -static char rcsid[] = "$Id: vipw.c,v 1.6 1997/07/06 00:12:23 aebr Exp $"; -#endif /* not lint */ - static char version_string[] = "vipw 1.4"; #include @@ -167,8 +156,10 @@ pw_lock() if (ret == -1) { if (errno == EEXIST) (void)fprintf(stderr, - "%s: the %s file is busy\n", progname, - program == VIPW ? "password" : "group" ); + "%s: the %s file is busy (%s present)\n", + progname, + program == VIPW ? "password" : "group", + tmp_file); else (void)fprintf(stderr, "%s: can't link %s: %s\n", progname, tmp_file, strerror(errno)); @@ -213,7 +204,12 @@ pw_edit(notsetuid) else p = editor; - if (!(pid = vfork())) { + pid = fork(); + if (pid < 0) { + (void)fprintf(stderr, "%s: Cannot fork\n", progname); + exit(1); + } + if (!pid) { if (notsetuid) { (void)setgid(getgid()); (void)setuid(getuid()); diff --git a/login-utils/wall.c b/login-utils/wall.c index 7957ae299..eda7e611d 100644 --- a/login-utils/wall.c +++ b/login-utils/wall.c @@ -33,16 +33,6 @@ * Modified Sun Mar 12 10:34:34 1995, faith@cs.unc.edu, for Linux */ -#ifndef lint -static char copyright[] = -"@(#) Copyright (c) 1988, 1990, 1993\n\ - The Regents of the University of California. All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -static char sccsid[] = "@(#)wall.c 8.2 (Berkeley) 11/16/93"; -#endif /* not lint */ - /* * This program is not related to David Wall, whose Stanford Ph.D. thesis * is entitled "Mechanisms for Broadcast and Selective Broadcast". @@ -145,11 +135,12 @@ makemsg(fname) time_t now, time(); FILE *fp; int fd; - char *p, *whom, hostname[MAXHOSTNAMELEN], lbuf[100], tmpname[64]; + char *p, *whom, *where, hostname[MAXHOSTNAMELEN], + lbuf[MAXHOSTNAMELEN + 320], + tmpname[sizeof(_PATH_TMP) + 20]; char *getlogin(), *strcpy(), *ttyname(); - (void)snprintf(tmpname, sizeof(tmpname), - "%s/wall.XXXXXX", _PATH_TMP); + (void)sprintf(tmpname, "%s/wall.XXXXXX", _PATH_TMP); if (!(fd = mkstemp(tmpname)) || !(fp = fdopen(fd, "r+"))) { (void)fprintf(stderr, "wall: can't open temporary file.\n"); exit(1); @@ -159,6 +150,11 @@ makemsg(fname) if (!nobanner) { if (!(whom = getlogin())) whom = (pw = getpwuid(getuid())) ? pw->pw_name : "???"; + if (!whom || strlen(whom) > 100) + whom = "someone"; + where = ttyname(2); + if (!where || strlen(where) > 100) + where = "somewhere"; (void)gethostname(hostname, sizeof(hostname)); (void)time(&now); lt = localtime(&now); @@ -170,14 +166,14 @@ makemsg(fname) * Which means that we may leave a non-blank character * in column 80, but that can't be helped. */ + /* snprintf is not always available, but the sprintf's here + will not overflow as long as %d takes at most 100 chars */ (void)fprintf(fp, "\r%79s\r\n", " "); - (void)snprintf(lbuf, sizeof(lbuf), - "Broadcast Message from %s@%s", - whom, hostname); + (void)sprintf(lbuf, "Broadcast Message from %s@%s", + whom, hostname); (void)fprintf(fp, "%-79.79s\007\007\r\n", lbuf); - (void)snprintf(lbuf, sizeof(lbuf), - " (%s) at %d:%02d ...", ttyname(2), - lt->tm_hour, lt->tm_min); + (void)sprintf(lbuf, " (%s) at %d:%02d ...", + where, lt->tm_hour, lt->tm_min); (void)fprintf(fp, "%-79.79s\r\n", lbuf); } (void)fprintf(fp, "%79s\r\n", " "); -- cgit v1.2.3-55-g7522