summaryrefslogtreecommitdiffstats
path: root/login-utils
diff options
context:
space:
mode:
authorKarel Zak2006-12-07 00:25:46 +0100
committerKarel Zak2006-12-07 00:25:46 +0100
commitc07ebfa1e02d208ab12430e6791ea147bcfaf9c0 (patch)
treed44a755098286f5d553c7aea1a73d98c2995d6ec /login-utils
parentImported from util-linux-2.10s tarball. (diff)
downloadkernel-qcow2-util-linux-c07ebfa1e02d208ab12430e6791ea147bcfaf9c0.tar.gz
kernel-qcow2-util-linux-c07ebfa1e02d208ab12430e6791ea147bcfaf9c0.tar.xz
kernel-qcow2-util-linux-c07ebfa1e02d208ab12430e6791ea147bcfaf9c0.zip
Imported from util-linux-2.11b tarball.
Diffstat (limited to 'login-utils')
-rw-r--r--login-utils/Makefile20
-rw-r--r--login-utils/agetty.c31
-rw-r--r--login-utils/checktty.c18
-rw-r--r--login-utils/chfn.c6
-rw-r--r--login-utils/chsh.c2
-rw-r--r--login-utils/cryptocard.c2
-rw-r--r--login-utils/islocal.c2
-rw-r--r--login-utils/last.c43
-rw-r--r--login-utils/login.c160
-rw-r--r--login-utils/mesg.c2
-rw-r--r--login-utils/newgrp.c2
-rw-r--r--login-utils/passwd.c6
-rw-r--r--login-utils/setpwnam.h17
-rw-r--r--login-utils/shutdown.c6
-rw-r--r--login-utils/simpleinit.c122
-rw-r--r--login-utils/ttymsg.c2
-rw-r--r--login-utils/vipw.c94
-rw-r--r--login-utils/wall.c10
18 files changed, 277 insertions, 268 deletions
diff --git a/login-utils/Makefile b/login-utils/Makefile
index d986501e1..e6b37b8a1 100644
--- a/login-utils/Makefile
+++ b/login-utils/Makefile
@@ -96,17 +96,17 @@ shutdown.o simpleinit.o: $(LIB)/linux_reboot.h
wall.o: ttymsg.h $(LIB)/carefulputc.h
agetty: agetty.o
-chfn: chfn.o islocal.o setpwnam.o $(LIB)/env.o
+chfn: chfn.o islocal.o setpwnam.o $(LIB)/env.o $(LIB)/xstrncpy.o
$(CC) $(LDFLAGS) -o $@ $^ $(CRYPT) $(PAM)
chsh: chsh.o islocal.o setpwnam.o $(LIB)/env.o
$(CC) $(LDFLAGS) -o $@ $^ $(CRYPT) $(PAM)
last: last.o
ifeq "$(HAVE_PAM)" "yes"
-login: login.o $(LIB)/setproctitle.o
+login: login.o $(LIB)/setproctitle.o $(LIB)/xstrncpy.o
$(CC) $(LDFLAGS) -o $@ $^ $(CRYPT) $(PAM)
else
-login: login.o $(LIB)/setproctitle.o checktty.o
+login: login.o $(LIB)/xstrncpy.o $(LIB)/setproctitle.o checktty.o
$(CC) $(LDFLAGS) -o $@ $^ $(CRYPT)
endif
@@ -115,20 +115,20 @@ mesg: mesg.o $(ERR_O)
newgrp: newgrp.o
$(CC) $(LDFLAGS) -o $@ $^ $(CRYPT) $(PAM)
-shutdown: shutdown.o $(LIB)/my_reboot.o
+shutdown: shutdown.o $(LIB)/my_reboot.o $(LIB)/xstrncpy.o
-simpleinit: simpleinit.o $(LIB)/my_reboot.o
+simpleinit: simpleinit.o $(LIB)/my_reboot.o $(LIB)/xstrncpy.o
$(CC) $(LDFLAGS) -o $@ $^ $(CRYPT)
initctl: initctl.o
$(CC) $(LDFLAGS) -o $@ $^
-vipw: vipw.o
+vipw: vipw.o $(LIB)/xstrncpy.o
newgrp.o: $(LIB)/pathnames.h
$(CC) -c $(CFLAGS) $(PAMFL) newgrp.c
-wall: wall.o ttymsg.o $(LIB)/carefulputc.o
+wall: wall.o ttymsg.o $(LIB)/carefulputc.o $(LIB)/xstrncpy.o
LOGINFLAGS=
ifeq "$(USE_TTY_GROUP)" "yes"
@@ -145,7 +145,7 @@ login.o: login.c $(LIB)/pathnames.h $(LIB)/setproctitle.c $(LIB)/setproctitle.h
mesg.o: mesg.c $(LIB)/errs.h
$(CC) -c $(CFLAGS) $(LOGINFLAGS) mesg.c
-passwd: passwd.o islocal.o setpwnam.o $(LIB)/env.o
+passwd: passwd.o islocal.o setpwnam.o $(LIB)/env.o $(LIB)/xstrncpy.o
$(CC) $(LDFLAGS) -o $@ $^ $(CRYPT)
ifeq "$(REQUIRE_PASSWORD)" "yes"
@@ -214,8 +214,8 @@ ifeq "$(USE_TTY_GROUP)" "yes"
chmod g+s $(USRBINDIR)/wall
endif
-.PHONY: clean
-clean:
+.PHONY: clean distclean
+clean distclean:
-rm -f *.o *~ core $(BIN.PASSWD) $(SBIN.GETTY) $(SBIN.INIT) \
$(USRBIN.MISC) $(USRBIN.PASSWD) $(USRBIN.PUTILS) \
$(USRSBIN.PUTILS) $(BIN.PUTILS)
diff --git a/login-utils/agetty.c b/login-utils/agetty.c
index 63f4adfa6..3a30b16ba 100644
--- a/login-utils/agetty.c
+++ b/login-utils/agetty.c
@@ -5,7 +5,7 @@
-f option added by Eric Rasmussen <ear@usfirst.org> - 12/28/95
- 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org>
+ 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
- added Native Language Support
1999-05-05 Thorsten Kranzkowski <dl8bcu@gmx.net>
@@ -564,7 +564,6 @@ update_utmp(line)
* entry in the utmp file.
*/
-#ifdef __linux__
utmpname(_PATH_UTMP);
setutent();
while ((utp = getutent())
@@ -578,7 +577,6 @@ update_utmp(line)
memset(&ut, 0, sizeof(ut));
strncpy(ut.ut_id, line + 3, sizeof(ut.ut_id));
}
- /*endutent();*/
strncpy(ut.ut_user, "LOGIN", sizeof(ut.ut_user));
strncpy(ut.ut_line, line, sizeof(ut.ut_line));
@@ -593,7 +591,7 @@ update_utmp(line)
endutent();
{
-#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1)
+#ifdef HAVE_updwtmp
updwtmp(_PATH_WTMP, &ut);
#else
int ut_fd;
@@ -610,31 +608,6 @@ update_utmp(line)
}
#endif
}
-#else /* not __linux__ */
- { int ut_fd;
- if ((ut_fd = open(UTMP_FILE, 2)) < 0) {
- error(_("%s: open for update: %m"), UTMP_FILE);
- } else {
- long ut_size = sizeof(ut); /* avoid nonsense */
-
- while (read(ut_fd, (char *) &ut, sizeof(ut)) == sizeof(ut)) {
- if (ut.ut_type == INIT_PROCESS && ut.ut_pid == mypid) {
- ut.ut_type = LOGIN_PROCESS;
- ut.ut_time = time((long *) 0);
- (void) strncpy(ut.ut_name, "LOGIN", sizeof(ut.ut_name));
- (void) strncpy(ut.ut_line, line, sizeof(ut.ut_line));
- if (fakehost)
- (void) strncpy(ut.ut_host, fakehost, sizeof(ut.ut_host));
- (void) lseek(ut_fd, -ut_size, 1);
- (void) write(ut_fd, (char *) &ut, sizeof(ut));
- (void) close(ut_fd);
- return;
- }
- }
- error(_("%s: no utmp entry"), line);
- }
- }
-#endif /* __linux__ */
}
#endif
diff --git a/login-utils/checktty.c b/login-utils/checktty.c
index 6269b6b07..e96647ea6 100644
--- a/login-utils/checktty.c
+++ b/login-utils/checktty.c
@@ -2,7 +2,7 @@
Created 25-Aug-95 by Peter Orbaek <poe@daimi.aau.dk>
Fixed by JDS June 1996 to clear lists and close files
- 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org>
+ 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
- added Native Language Support
*/
@@ -30,6 +30,7 @@
#include "pathnames.h"
#include "login.h"
+#include "xstrncpy.h"
#ifdef TESTING
struct hostent hostaddress;
@@ -107,8 +108,7 @@ new_class(char *class)
tc->next = ttyclasses;
tc->first = NULL;
- strncpy(tc->classname, class, CLASSNAMELEN);
- tc->classname[CLASSNAMELEN-1] = 0;
+ xstrncpy(tc->classname, class, CLASSNAMELEN);
ttyclasses = tc;
return tc;
}
@@ -128,8 +128,7 @@ add_to_class(struct ttyclass *tc, char *tty)
}
ge->next = tc->first;
- strncpy(ge->name, tty, NAMELEN);
- ge->name[NAMELEN-1] = 0;
+ xstrncpy(ge->name, tty, NAMELEN);
tc->first = ge;
}
@@ -267,8 +266,7 @@ in_class(const char *tty, char *class)
if (class[0] == '[') {
if ((p = strchr(class, ']'))) {
*p = 0;
- strncpy(timespec, class+1, sizeof(timespec));
- timespec[sizeof(timespec)-1] = 0;
+ xstrncpy(timespec, class+1, sizeof(timespec));
*p = ']';
if(!timeok(tm, timespec)) return 0;
class = p+1;
@@ -289,8 +287,7 @@ in_class(const char *tty, char *class)
if (n[0] == '[') {
if ((p = strchr(n, ']'))) {
*p = 0;
- strncpy(timespec, n+1, sizeof(timespec));
- timespec[sizeof(timespec)-1] = 0;
+ xstrncpy(timespec, n+1, sizeof(timespec));
*p = ']';
if(!timeok(tm, timespec)) continue;
n = p+1;
@@ -373,8 +370,7 @@ checktty(const char *user, const char *tty, struct passwd *pwd)
if(*ptr == '#') *ptr = 0;
if (buf[0] == '*') {
- strncpy(defaultbuf, buf, 256);
- defaultbuf[255] = 0;
+ xstrncpy(defaultbuf, buf, 256);
continue;
}
diff --git a/login-utils/chfn.c b/login-utils/chfn.c
index de228241b..e25212e88 100644
--- a/login-utils/chfn.c
+++ b/login-utils/chfn.c
@@ -16,7 +16,7 @@
* Hacked by Peter Breitenlohner, peb@mppmu.mpg.de,
* to remove trailing empty fields. Oct 5, 96.
*
- * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org>
+ * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
* - added Native Language Support
*
*
@@ -36,6 +36,7 @@
#include "my_crypt.h"
#include "islocal.h"
#include "setpwnam.h"
+#include "xstrncpy.h"
#include "nls.h"
#include "env.h"
@@ -239,8 +240,7 @@ static boolean parse_argv (argc, argv, pinfo)
info_given = true;
status = 0;
- strncpy (buf, whoami, sizeof(buf)-128);
- buf[sizeof(buf)-128-1] = 0;
+ xstrncpy (buf, whoami, sizeof(buf)-128);
strcat (buf, ": ");
/* now store the argument */
diff --git a/login-utils/chsh.c b/login-utils/chsh.c
index d1a3fa820..fd9b5899e 100644
--- a/login-utils/chsh.c
+++ b/login-utils/chsh.c
@@ -17,7 +17,7 @@
* suggestion from Zefram. Disallowing users with shells not in /etc/shells
* from changing their shell.
*
- * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org>
+ * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
* - added Native Language Support
*
*
diff --git a/login-utils/cryptocard.c b/login-utils/cryptocard.c
index 9e221cbe6..44cfb55d5 100644
--- a/login-utils/cryptocard.c
+++ b/login-utils/cryptocard.c
@@ -17,7 +17,7 @@
ftp://ftp.daimi.aau.dk/pub/linux/poe/poeigl-X.XX.tar.gz
- 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org>
+ 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
- added Native Language Support
*/
diff --git a/login-utils/islocal.c b/login-utils/islocal.c
index 87f8f1cb2..1ee84089f 100644
--- a/login-utils/islocal.c
+++ b/login-utils/islocal.c
@@ -10,7 +10,7 @@
to distinguish user names where one is a prefix of the other,
and to use "pathnames.h". Oct 5, 96.
- 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org>
+ 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
- added Native Language Support
diff --git a/login-utils/last.c b/login-utils/last.c
index 8375f9f07..8d3a8911a 100644
--- a/login-utils/last.c
+++ b/login-utils/last.c
@@ -18,10 +18,14 @@
* WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
- /* 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org>
+ /* 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
* - added Native Language Support
*/
+ /* 2001-02-14 Marek Zelem <marek@fornax.sk>
+ * - using mmap() on Linux - great speed improvement
+ */
+
/*
* last
*/
@@ -29,6 +33,7 @@
#include <sys/stat.h>
#include <sys/file.h>
#include <sys/types.h>
+#include <sys/mman.h>
#include <signal.h>
#include <string.h>
#include <time.h>
@@ -197,8 +202,15 @@ wtmp(void) {
long delta; /* time difference */
char *crmsg = NULL;
char *ct = NULL;
+#if USE_GETUTENT
struct utmp **utmplist = NULL;
int listlen = 0;
+#else
+ int fd;
+ struct utmp *utl;
+ struct stat st;
+ int utl_len;
+#endif
int listnr = 0;
int i;
@@ -208,6 +220,7 @@ wtmp(void) {
(void)signal(SIGINT, onintr);
(void)signal(SIGQUIT, onintr);
+#if USE_GETUTENT
setutent();
while((bp = getutent())) {
if(listnr >= listlen) {
@@ -220,12 +233,31 @@ wtmp(void) {
memcpy(utmplist[listnr++], bp, sizeof(*bp));
}
endutent();
+#else
+ if ((fd = open(file,O_RDONLY)) < 0)
+ exit(1);
+ fstat(fd, &st);
+ utl_len = st.st_size;
+ utl = mmap(NULL, utl_len, PROT_READ|PROT_WRITE,
+ MAP_PRIVATE|MAP_FILE, fd, 0);
+ if (utl == NULL)
+ exit(1);
+ listnr = utl_len/sizeof(struct utmp);
+#endif
if(listnr)
+#if USE_GETUTENT
ct = ctime(&utmplist[0]->ut_time);
+#else
+ ct = ctime(&utl[0].ut_time);
+#endif
for(i = listnr - 1; i >= 0; i--) {
+#if USE_GETUTENT
bp = utmplist[i];
+#else
+ bp = utl+i;
+#endif
/*
* if the terminal line is '~', the machine stopped.
* see utmp(5) for more info.
@@ -245,7 +277,8 @@ wtmp(void) {
}
currentout = -bp->ut_time;
- crmsg = strncmp(bp->ut_name, "shutdown", NMAX) ? "crash" : "down ";
+ crmsg = (strncmp(bp->ut_name, "shutdown", NMAX)
+ ? "crash" : "down ");
if (!bp->ut_name[0])
(void)strcpy(bp->ut_name, "reboot");
if (want(bp, NO)) {
@@ -295,9 +328,15 @@ wtmp(void) {
}
T->logout = bp->ut_time;
utmpbuf.ut_time = bp->ut_time;
+#if USE_GETUTENT
free(bp);
}
if(utmplist) free(utmplist);
+#else
+ }
+ munmap(utl,utl_len);
+ close(fd);
+#endif
if(ct) printf(_("\nwtmp begins %s"), ct); /* ct already ends in \n */
}
diff --git a/login-utils/login.c b/login-utils/login.c
index 3ad3b219c..1cf188fba 100644
--- a/login-utils/login.c
+++ b/login-utils/login.c
@@ -52,7 +52,7 @@
From 1992 till now (1997) this code for Linux has been maintained at
ftp.daimi.aau.dk:/pub/linux/poe/
- 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org>
+ 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
- added Native Language Support
Sun Mar 21 1999 - Arnaldo Carvalho de Melo <acme@conectiva.com.br>
- fixed strerr(errno) in gettext calls
@@ -119,6 +119,7 @@
#include "pathnames.h"
#include "my_crypt.h"
#include "login.h"
+#include "xstrncpy.h"
#include "nls.h"
#ifdef __linux__
@@ -145,8 +146,11 @@
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 { \
+ pam_setcred(pamh, PAM_DELETE_CRED); \
+ retcode = pam_close_session(pamh,0); \
+ pam_end(pamh,retcode); \
+}
#endif
#ifndef __linux__
@@ -190,13 +194,14 @@ struct lastlog
};
#endif
-
+#ifndef USE_PAM
static void getloginname (void);
+static void checknologin (void);
+static int rootterm (char *ttyn);
+#endif
static void timedout (int);
static void sigint (int);
-static int rootterm (char *ttyn);
static void motd (void);
-static void checknologin (void);
static void dolastlog (int quiet);
#ifndef __linux__
@@ -355,8 +360,7 @@ main(int argc, char **argv)
* host to login so that it may be placed in utmp and wtmp
*/
gethostname(tbuf, sizeof(tbuf));
- strncpy(thishost, tbuf, sizeof(thishost)-1);
- thishost[sizeof(thishost)-1] = 0;
+ xstrncpy(thishost, tbuf, sizeof(thishost));
domain = index(tbuf, '.');
username = tty = hostname = NULL;
@@ -590,14 +594,21 @@ main(int argc, char **argv)
First get the username that we are actually using, though.
*/
retcode = pam_get_item(pamh, PAM_USER, (const void **) &username);
- setpwent();
- pwd = getpwnam(username);
+ if (retcode == PAM_SUCCESS && username && *username) {
+ pwd = getpwnam(username);
+ }
+
+ /*
+ * Initialize the supplementary group list.
+ * This should be done before pam_setcred because
+ * the PAM modules might add groups during pam_setcred.
+ */
if (pwd) initgroups(username, pwd->pw_gid);
- retcode = pam_setcred(pamh, PAM_ESTABLISH_CRED);
+ retcode = pam_open_session(pamh, 0);
PAM_FAIL_CHECK;
- retcode = pam_open_session(pamh, 0);
+ retcode = pam_setcred(pamh, PAM_ESTABLISH_CRED);
PAM_FAIL_CHECK;
#else /* ! USE_PAM */
@@ -795,66 +806,6 @@ main(int argc, char **argv)
}
}
-#ifndef __linux__
-# ifdef KERBEROS
- if (notickets && !quietlog)
- printf(_("Warning: no Kerberos tickets issued\n"));
-# endif
-
-# ifndef USE_PAM /* PAM does all of this for us */
-# define TWOWEEKS (14*24*60*60)
- if (pwd->pw_change || pwd->pw_expire) {
- struct timeval tp;
-
- gettimeofday(&tp, (struct timezone *)NULL);
-
- if (pwd->pw_change) {
- if (tp.tv_sec >= pwd->pw_change) {
- printf(_("Sorry -- your password has expired.\n"));
- sleepexit(1);
- }
- else if (tp.tv_sec - pwd->pw_change < TWOWEEKS && !quietlog) {
- struct tm *ttp;
- ttp = localtime(&pwd->pw_change);
- printf(_("Warning: your password expires on %d %s %d.\n"),
- ttp->tm_mday, months[ttp->tm_mon],
- TM_YEAR_BASE + ttp->tm_year);
- }
- }
-
- if (pwd->pw_expire) {
- if (tp.tv_sec >= pwd->pw_expire) {
- printf(_("Sorry -- your account has expired.\n"));
- sleepexit(1);
- }
- else if (tp.tv_sec - pwd->pw_expire < TWOWEEKS && !quietlog) {
- struct tm *ttp;
- ttp = localtime(&pwd->pw_expire);
- printf(_("Warning: your account expires on %d %s %d.\n"),
- ttp->tm_mday, months[ttp->tm_mon],
- TM_YEAR_BASE + ttp->tm_year);
- }
- }
- }
-# endif /* !USE_PAM */
-
- /* nothing else left to fail -- really log in */
- {
- struct utmp utmp;
-
- memset((char *)&utmp, 0, sizeof(utmp));
- time(&utmp.ut_time);
- strncpy(utmp.ut_name, username, sizeof(utmp.ut_name));
- /* ut_name may legally be non-null-terminated */
- if (hostname) {
- strncpy(utmp.ut_host, hostname, sizeof(utmp.ut_host));
- utmp.ut_host[sizeof(utmp.ut_host)-1] = 0;
- }
- strncpy(utmp.ut_line, tty, sizeof(utmp.ut_line));
- utmp.ut_line[sizeof(utmp.ut_line)-1] = 0;
- login(&utmp);
- }
-#else /* __linux__ defined */
/* for linux, write entries in utmp and wtmp */
{
struct utmp ut;
@@ -898,8 +849,7 @@ Michael Riepe <michael@stud.uni-hannover.de>
strncpy(ut.ut_id, ttyn + 8, sizeof(ut.ut_id));
strncpy(ut.ut_user, username, sizeof(ut.ut_user));
- strncpy(ut.ut_line, ttyn + 5, sizeof(ut.ut_line));
- ut.ut_line[sizeof(ut.ut_line)-1] = 0;
+ xstrncpy(ut.ut_line, ttyn + 5, sizeof(ut.ut_line));
#ifdef _HAVE_UT_TV /* in <utmpbits.h> included by <utmp.h> */
gettimeofday(&ut.ut_tv, NULL);
#else
@@ -913,8 +863,7 @@ Michael Riepe <michael@stud.uni-hannover.de>
ut.ut_type = USER_PROCESS;
ut.ut_pid = mypid;
if (hostname) {
- strncpy(ut.ut_host, hostname, sizeof(ut.ut_host));
- ut.ut_host[sizeof(ut.ut_host)-1] = 0;
+ xstrncpy(ut.ut_host, hostname, sizeof(ut.ut_host));
if (hostaddress.h_addr_list)
memcpy(&ut.ut_addr, hostaddress.h_addr_list[0],
sizeof(ut.ut_addr));
@@ -923,7 +872,7 @@ Michael Riepe <michael@stud.uni-hannover.de>
pututline(&ut);
endutent();
-#if __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 1)
+#ifdef HAVE_updwtmp
updwtmp(_PATH_WTMP, &ut);
#else
#if 0
@@ -953,19 +902,11 @@ Michael Riepe <michael@stud.uni-hannover.de>
}
}
#endif
-#endif /* __GLIBC__ */
+#endif
}
-#endif /* __linux__ */
dolastlog(quietlog);
-#ifndef __linux__
- if (!hflag) { /* XXX */
- static struct winsize win = { 0, 0, 0, 0 };
-
- ioctl(0, TIOCSWINSZ, &win);
- }
-#endif
chown(ttyn, pwd->pw_uid,
(gr = getgrnam(TTYGRPNAME)) ? gr->gr_gid : pwd->pw_gid);
chmod(ttyn, TTY_MODE);
@@ -1012,17 +953,6 @@ Michael Riepe <michael@stud.uni-hannover.de>
memset(environ, 0, sizeof(char*));
}
-#ifndef __linux__
- setenv("HOME", pwd->pw_dir, 1);
- setenv("SHELL", pwd->pw_shell, 1);
- if (term[0] == '\0') {
- strncpy(term, stypeof(tty), sizeof(term));
- term[sizeof(term)-1] = 0;
- }
- setenv("TERM", term, 0);
- setenv("USER", pwd->pw_name, 1);
- setenv("PATH", _PATH_DEFPATH, 0);
-#else
setenv("HOME", pwd->pw_dir, 0); /* legal to override */
if(pwd->pw_uid)
setenv("PATH", _PATH_DEFPATH, 1);
@@ -1046,7 +976,6 @@ Michael Riepe <michael@stud.uni-hannover.de>
HP-UX 6.5 does it. We'll not allow modifying it.
*/
setenv("LOGNAME", pwd->pw_name, 1);
-#endif
#ifdef USE_PAM
{
@@ -1108,9 +1037,16 @@ Michael Riepe <michael@stud.uni-hannover.de>
signal(SIGHUP, SIG_DFL);
#ifdef USE_PAM
- /* We must fork before setuid() because we need to call
+ /*
+ * We must fork before setuid() because we need to call
* pam_close_session() as root.
*/
+ /*
+ * Problem: if the user's shell is a shell like ash that doesnt do
+ * setsid() or setpgrp(), then a ctrl-\, sending SIGQUIT to every
+ * process in the pgrp, will kill us.
+ * Solution: use TIOCNOTTY and setsid().
+ */
signal(SIGINT, SIG_IGN);
childPid = fork();
if (childPid < 0) {
@@ -1121,11 +1057,16 @@ Michael Riepe <michael@stud.uni-hannover.de>
exit(0);
} else if (childPid) {
/* parent - wait for child to finish, then cleanup session */
+ signal(SIGHUP, SIG_IGN); /* ignore signal from TIOCNOTTY */
+ ioctl(0, TIOCNOTTY, NULL);
+ signal(SIGHUP, SIG_DFL);
+
wait(NULL);
PAM_END;
exit(0);
}
/* child */
+ setsid();
#endif
signal(SIGINT, SIG_DFL);
@@ -1161,10 +1102,9 @@ Michael Riepe <michael@stud.uni-hannover.de>
childArgv[childArgc++] = buff;
} else {
tbuf[0] = '-';
- strncpy(tbuf + 1, ((p = rindex(pwd->pw_shell, '/')) ?
+ xstrncpy(tbuf + 1, ((p = rindex(pwd->pw_shell, '/')) ?
p + 1 : pwd->pw_shell),
sizeof(tbuf)-1);
- tbuf[sizeof(tbuf)-1] = 0;
childArgv[childArgc++] = pwd->pw_shell;
childArgv[childArgc++] = tbuf;
@@ -1185,7 +1125,8 @@ Michael Riepe <michael@stud.uni-hannover.de>
exit(0);
}
-void
+#ifndef USE_PAM
+static void
getloginname(void) {
int ch, cnt, cnt2;
char *p;
@@ -1229,6 +1170,7 @@ getloginname(void) {
}
}
}
+#endif
void
timedout(int sig) {
@@ -1243,6 +1185,7 @@ timedout(int sig) {
exit(0);
}
+#ifndef USE_PAM
int
rootterm(char * ttyn)
#ifndef __linux__
@@ -1279,7 +1222,8 @@ rootterm(char * ttyn)
}
}
}
-#endif
+#endif /* !__linux__ */
+#endif /* !USE_PAM */
jmp_buf motdinterrupt;
@@ -1342,12 +1286,10 @@ dolastlog(int quiet) {
}
memset((char *)&ll, 0, sizeof(ll));
time(&ll.ll_time);
- strncpy(ll.ll_line, tty, sizeof(ll.ll_line));
- ll.ll_line[sizeof(ll.ll_line)-1] = 0;
- if (hostname) {
- strncpy(ll.ll_host, hostname, sizeof(ll.ll_host));
- ll.ll_host[sizeof(ll.ll_host)-1] = 0;
- }
+ xstrncpy(ll.ll_line, tty, sizeof(ll.ll_line));
+ if (hostname)
+ xstrncpy(ll.ll_host, hostname, sizeof(ll.ll_host));
+
write(fd, (char *)&ll, sizeof(ll));
close(fd);
}
diff --git a/login-utils/mesg.c b/login-utils/mesg.c
index bfa17eb11..2b08d8350 100644
--- a/login-utils/mesg.c
+++ b/login-utils/mesg.c
@@ -39,7 +39,7 @@
* Modified Mon Jul 1 18:14:10 1996, janl@ifi.uio.no, writing to stdout
* as suggested by Michael Meskes <meskes@Informatik.RWTH-Aachen.DE>
*
- * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org>
+ * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
* - added Native Language Support
*
*
diff --git a/login-utils/newgrp.c b/login-utils/newgrp.c
index ade173e53..89db17548 100644
--- a/login-utils/newgrp.c
+++ b/login-utils/newgrp.c
@@ -3,7 +3,7 @@
/* Vesa Roukonen added code for asking password */
/* Currently maintained at ftp://ftp.daimi.aau.dk/pub/linux/poe/ */
-/* 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org>
+/* 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
* - added Native Language Support
*/
diff --git a/login-utils/passwd.c b/login-utils/passwd.c
index 6741ee210..d931d3b88 100644
--- a/login-utils/passwd.c
+++ b/login-utils/passwd.c
@@ -38,7 +38,7 @@
* auth.warning. (Of course, the password itself is not logged.)
*/
- /* 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org>
+ /* 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
* - added Native Language Support
* Sun Mar 21 1999 - Arnaldo Carvalho de Melo <acme@conectiva.com.br>
* - fixed strerr(errno) in gettext calls
@@ -68,6 +68,7 @@
#include "my_crypt.h"
#include "setpwnam.h"
#include "islocal.h"
+#include "xstrncpy.h"
#include "nls.h"
#include "env.h"
@@ -375,8 +376,7 @@ main(int argc, char *argv[]) {
&& !check_passwd(pwdstr, pe->pw_passwd, user, pe->pw_gecos) )
goto redo_it;
- strncpy(pwdstr1, pwdstr, 9);
- pwdstr1[9] = 0;
+ xstrncpy(pwdstr1, pwdstr, sizeof(pwdstr1));
pwdstr = getpass(_("Re-type new password: "));
if(strncmp(pwdstr, pwdstr1, 8)) {
diff --git a/login-utils/setpwnam.h b/login-utils/setpwnam.h
index 84d1c208f..e7f44a94c 100644
--- a/login-utils/setpwnam.h
+++ b/login-utils/setpwnam.h
@@ -22,6 +22,15 @@
#define GROUP_FILE _PATH_GROUP
#define GTMP_FILE _PATH_GTMP
#define GTMPTMP_FILE _PATH_GTMPTMP
+
+#define SHADOW_FILE _PATH_SHADOW_PASSWD
+#define SPTMP_FILE _PATH_SHADOW_PTMP
+#define SPTMPTMP_FILE _PATH_SHADOW_PTMPTMP
+
+#define SGROUP_FILE _PATH_SHADOW_GROUP
+#define SGTMP_FILE _PATH_SHADOW_GTMP
+#define SGTMPTMP_FILE _PATH_SHADOW_GTMPTMP
+
#else
#define PASSWD_FILE "/tmp/passwd"
#define PTMP_FILE "/tmp/ptmp"
@@ -30,6 +39,14 @@
#define GROUP_FILE "/tmp/group"
#define GTMP_FILE "/tmp/gtmp"
#define GTMPTMP_FILE "/tmp/gtmptmp"
+
+#define SHADOW_FILE "/tmp/shadow"
+#define SPTMP_FILE "/tmp/sptmp"
+#define SPTMPTMP_FILE "/tmp/sptmptmp"
+
+#define SGROUP_FILE "/tmp/gshadow"
+#define SGTMP_FILE "/tmp/sgtmp"
+#define SGTMPTMP_FILE "/tmp/sgtmptmp"
#endif
extern int setpwnam (struct passwd *pwd);
diff --git a/login-utils/shutdown.c b/login-utils/shutdown.c
index d1034d5eb..036064aad 100644
--- a/login-utils/shutdown.c
+++ b/login-utils/shutdown.c
@@ -28,7 +28,7 @@
* Changes by Richard Gooch <rgooch@atnf.csiro.au> (butchered by aeb)
* introducing shutdown.conf.
*
- * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org>
+ * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
* - added Native Language Support
*
* 2000-03-02 Richard Gooch <rgooch@atnf.csiro.au>
@@ -71,6 +71,7 @@
#include <sys/utsname.h>
#include "linux_reboot.h"
#include "pathnames.h"
+#include "xstrncpy.h"
#include "nls.h"
static void usage(void), int_handler(int), write_user(struct utmp *);
@@ -249,8 +250,7 @@ main(int argc, char *argv[])
exit(1);
}
} else {
- strncpy(message, argv[c], sizeof(message));
- message[sizeof(message)-1] = '\0';
+ xstrncpy(message, argv[c], sizeof(message));
opt_msgset = 1;
}
}
diff --git a/login-utils/simpleinit.c b/login-utils/simpleinit.c
index 9c4b63a5f..56f10455a 100644
--- a/login-utils/simpleinit.c
+++ b/login-utils/simpleinit.c
@@ -1,8 +1,14 @@
/* simpleinit.c - poe@daimi.aau.dk */
-/* Version 1.21 */
+/* Version 2.0.1 */
-/* 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org>
+/* 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
* - added Native Language Support
+ * 2001-01-25 Richard Gooch <rgooch@atnf.csiro.au>
+ * - fixed bug with failed services so they may be later "reclaimed"
+ * 2001-02-02 Richard Gooch <rgooch@atnf.csiro.au>
+ * - fixed race when reading from pipe and reaping children
+ * 2001-02-18 sam@quux.dropbear.id.au
+ * - fixed bug in <get_path>: multiple INIT_PATH components did not work
*/
#include <sys/types.h>
@@ -31,6 +37,7 @@
#include "my_crypt.h"
#include "pathnames.h"
#include "linux_reboot.h"
+#include "xstrncpy.h"
#include "nls.h"
#include "simpleinit.h"
@@ -77,7 +84,8 @@ static sigjmp_buf jmp_env;
static void do_single (void);
static int do_rc_tty (const char *path);
-static int process_path ( const char *path, int (*func) (const char *path) );
+static int process_path (const char *path, int (*func) (const char *path),
+ int ignore_dangling_symlink);
static int preload_file (const char *path);
static int run_file (const char *path);
static void spawn (int i), read_inittab (void);
@@ -91,7 +99,7 @@ static void sigterm_handler (int sig);
static void set_tz (void);
#endif
static void write_wtmp (void);
-static pid_t mywaitpid (pid_t pid, int *status);
+static pid_t mywait (int *status);
static int run_command (const char *file, const char *name, pid_t pid);
@@ -221,7 +229,7 @@ int main(int argc, char *argv[])
}
for ever {
- pid = mywaitpid (-1, &vec);
+ pid = mywait (&vec);
if (pid < 1) continue;
/* clear utmp entry, and append to wtmp if possible */
@@ -322,7 +330,7 @@ static int do_rc_tty (const char *path)
sigset_t ss;
if (caught_sigint) return 0;
- process_path (path, preload_file);
+ process_path (path, preload_file, 0);
/* Launch off a subprocess to start a new session (required for frobbing
the TTY) and capture control-C */
switch ( child = fork () )
@@ -344,10 +352,10 @@ static int do_rc_tty (const char *path)
break;
}
/* Parent */
- process_path (path, run_file);
+ process_path (path, run_file, 0);
while (1)
{
- if ( ( pid = mywaitpid (-1, &status) ) == child )
+ if ( ( pid = mywait (&status) ) == child )
return (WTERMSIG (status) == SIGINT) ? 0 : 1;
if (pid < 0) break;
}
@@ -356,17 +364,27 @@ static int do_rc_tty (const char *path)
return 0;
} /* End Function do_rc_tty */
-static int process_path ( const char *path, int (*func) (const char *path) )
+static int process_path (const char *path, int (*func) (const char *path),
+ int ignore_dangling_symlink)
{
struct stat statbuf;
DIR *dp;
struct dirent *de;
- if (stat (path, &statbuf) != 0)
+ if (lstat (path, &statbuf) != 0)
{
- err (_ ("stat of path failed\n") );
+ err (_ ("lstat of path failed\n") );
return 1;
}
+ if ( S_ISLNK (statbuf.st_mode) )
+ {
+ if (stat (path, &statbuf) != 0)
+ {
+ if ( (errno == ENOENT) && ignore_dangling_symlink ) return 0;
+ err (_ ("stat of path failed\n") );
+ return 1;
+ }
+ }
if ( !( statbuf.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH) ) ) return 0;
if ( !S_ISDIR (statbuf.st_mode) ) return (*func) (path);
if ( ( dp = opendir (path) ) == NULL )
@@ -382,7 +400,7 @@ static int process_path ( const char *path, int (*func) (const char *path) )
if (de->d_name[0] == '.') continue;
retval = sprintf (newpath, "%s/%s", path, de->d_name);
if (newpath[retval - 1] == '~') continue; /* Common mistake */
- if ( ( retval = process_path (newpath, func) ) ) return retval;
+ if ( ( retval = process_path (newpath, func, 1) ) ) return retval;
}
closedir (dp);
return 0;
@@ -545,11 +563,8 @@ static void read_inittab (void)
(void) strcpy(inittab[i].line, buf);
(void) strtok(inittab[i].line, ":");
- (void) strncpy(inittab[i].tty, inittab[i].line, 10);
- inittab[i].tty[9] = 0;
- (void) strncpy(inittab[i].termcap,
- strtok((char *)0, ":"), 30);
- inittab[i].termcap[29] = 0;
+ xstrncpy(inittab[i].tty, inittab[i].line, 10);
+ xstrncpy(inittab[i].termcap, strtok((char *)0, ":"), 30);
getty = strtok((char *)0, ":");
(void) strtok(getty, " \t\n");
@@ -566,10 +581,8 @@ static void read_inittab (void)
err(_("no TERM or cannot stat tty\n"));
} else {
/* is it a console tty? */
- if(major(stb.st_rdev) == 4 && minor(stb.st_rdev) < 64) {
- strncpy(inittab[i].termcap, termenv, 30);
- inittab[i].termcap[29] = 0;
- }
+ if(major(stb.st_rdev) == 4 && minor(stb.st_rdev) < 64)
+ xstrncpy(inittab[i].termcap, termenv, 30);
}
#endif
@@ -752,40 +765,40 @@ static void show_scripts (FILE *fp, const struct script_struct *script,
static const char *get_path (const char *file);
-static pid_t mywaitpid (pid_t pid, int *status)
+static pid_t mywait (int *status)
/* [RETURNS] The pid for a process to be reaped, 0 if no process is to be
reaped, and less than 0 if the boot scripts appear to have finished.
*/
{
- int ival;
- sigset_t ss_new, ss_old;
+ pid_t pid;
+ sigset_t ss;
long buffer[COMMAND_SIZE / sizeof (long)];
struct command_struct *command = (struct command_struct *) buffer;
- if (initctl_fd < 0) return waitpid (pid, status, 0);
- if (status == NULL) status = &ival;
- if ( ( pid = waitpid (pid, status, WNOHANG) ) > 0 )
- {
- return process_pidstat (pid, *status);
- }
- /* Some magic to avoid races */
+ if (initctl_fd < 0) return wait (status);
+ /* Some magic to avoid races which can result in lost signals */
command->command = -1;
- sigemptyset (&ss_new);
- sigaddset (&ss_new, SIGCHLD);
- sigprocmask (SIG_BLOCK, &ss_new, &ss_old);
- ival = sigsetjmp (jmp_env, 0);
- sigprocmask (SIG_SETMASK, &ss_old, NULL);
- if (ival == 0) do_longjmp = 1;
- else
- {
+ if ( sigsetjmp (jmp_env, 1) )
+ { /* Jump from signal handler */
do_longjmp = 0;
- if (command->command < 0) return 0;
+ process_command (command);
+ return 0;
+ }
+ sigemptyset (&ss); /* Block SIGCHLD so wait status cannot be lost */
+ sigaddset (&ss, SIGCHLD);
+ sigprocmask (SIG_BLOCK, &ss, NULL);
+ if ( ( pid = waitpid (-1, status, WNOHANG) ) > 0 )
+ {
+ sigprocmask (SIG_UNBLOCK, &ss, NULL);
+ return process_pidstat (pid, *status);
}
- if (command->command < 0) read (initctl_fd, buffer, COMMAND_SIZE);
+ do_longjmp = 1; /* After this, SIGCHLD will cause a jump backwards */
+ sigprocmask (SIG_UNBLOCK, &ss, NULL);
+ read (initctl_fd, buffer, COMMAND_SIZE);
do_longjmp = 0;
process_command (command);
return 0;
-} /* End Function mywaitpid */
+} /* End Function mywait */
static pid_t process_pidstat (pid_t pid, int status)
/* [RETURNS] The pid for a process to be reaped, 0 if no process is to be
@@ -978,7 +991,7 @@ static int run_command (const char *file, const char *name, pid_t pid)
script = find_script_byname (name, &starting_list, &service);
if (script == NULL)
service = find_service_in_list (name, unavailable_services);
- if (script == NULL)
+ if (service == NULL)
{
int i;
char txt[1024];
@@ -988,24 +1001,13 @@ static int run_command (const char *file, const char *name, pid_t pid)
if (needer != NULL) free (needer);
return SIG_FAILED;
}
+ service = calloc (1, strlen (name) + sizeof *service);
if (service == NULL)
{
- service = calloc (1, strlen (name) + sizeof *service);
- if (service == NULL)
- {
- free (script);
- return SIG_FAILED;
- }
- strcpy (service->name, name);
- }
- else /* Unhook service from unavailable list */
- {
- if (service->prev == NULL) unavailable_services = service->next;
- else service->prev->next = service->next;
- if (service->next != NULL) service->next->prev = service->prev;
- service->prev = NULL;
- service->next = NULL;
+ free (script);
+ return SIG_FAILED;
}
+ strcpy (service->name, name);
switch ( script->pid = fork () )
{
case 0: /* Child */
@@ -1063,6 +1065,7 @@ static struct script_struct *find_script_byname (const char *name,
return (script);
}
}
+ if (service != NULL) *service = NULL;
return NULL;
} /* End Function find_script_byname */
@@ -1121,6 +1124,7 @@ static void handle_nonworking (struct script_struct *script)
next = service->next;
if (provider == NULL)
{
+ service->prev = NULL;
service->next = unavailable_services;
if (unavailable_services != NULL)
unavailable_services->prev = service;
@@ -1180,7 +1184,7 @@ static const char *get_path (const char *file)
p2 = p1 + strlen (p1);
strncpy (path, p1, p2 - p1);
path[p2 - p1] = '/';
- strcat (path + (p2 - p1) + 1, file);
+ strcpy (path + (p2 - p1) + 1, file);
if (*p2 == ':') ++p2;
if (access (path, X_OK) == 0) return path;
}
diff --git a/login-utils/ttymsg.c b/login-utils/ttymsg.c
index b422abb85..55b26a82a 100644
--- a/login-utils/ttymsg.c
+++ b/login-utils/ttymsg.c
@@ -34,7 +34,7 @@
*
*/
- /* 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org>
+ /* 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
* - added Native Language Support
* Sun Mar 21 1999 - Arnaldo Carvalho de Melo <acme@conectiva.com.br>
* - fixed strerr(errno) in gettext calls
diff --git a/login-utils/vipw.c b/login-utils/vipw.c
index 665d77daa..f6133ac98 100644
--- a/login-utils/vipw.c
+++ b/login-utils/vipw.c
@@ -38,7 +38,7 @@
*
* Martin Schulze's patches adapted to Util-Linux by Nicolai Langfeldt.
*
- * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org>
+ * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
* - added Native Language Support
* Sun Mar 21 1999 - Arnaldo Carvalho de Melo <acme@conectiva.com.br>
* - fixed strerr(errno) in gettext calls
@@ -64,6 +64,7 @@ static char version_string[] = "vipw 1.4";
#include <unistd.h>
#include "setpwnam.h"
+#include "xstrncpy.h"
#include "nls.h"
#define FILENAMELEN 67
@@ -132,13 +133,6 @@ pw_lock(void) {
* that users can't get at the encrypted passwords while editing.
* Open should allow flock'ing the file; see 4.4BSD. XXX
*/
- lockfd = open(orig_file, O_RDONLY, 0);
-
- if (lockfd < 0) {
- (void)fprintf(stderr, "%s: %s: %s\n",
- progname, orig_file, strerror(errno));
- exit(1);
- }
#if 0 /* flock()ing is superfluous here, with the ptmp/ptmptmp system. */
if (flock(lockfd, LOCK_EX|LOCK_NB)) {
(void)fprintf(stderr,
@@ -169,6 +163,16 @@ pw_lock(void) {
}
exit(1);
}
+
+ lockfd = open(orig_file, O_RDONLY, 0);
+
+ if (lockfd < 0) {
+ (void)fprintf(stderr, "%s: %s: %s\n",
+ progname, orig_file, strerror(errno));
+ unlink(tmp_file);
+ exit(1);
+ }
+
copyfile(lockfd, fd);
(void)close(lockfd);
(void)close(fd);
@@ -253,9 +257,28 @@ pw_error(name, err, eval)
exit(eval);
}
+static void
+edit_file(void)
+{
+ struct stat begin, end;
+
+ pw_init();
+ pw_lock();
+
+ if (stat(tmp_file, &begin))
+ pw_error(tmp_file, 1, 1);
+ pw_edit(0);
+ if (stat(tmp_file, &end))
+ pw_error(tmp_file, 1, 1);
+ if (begin.st_mtime == end.st_mtime) {
+ (void)fprintf(stderr, _("%s: no changes made\n"), progname);
+ pw_error((char *)NULL, 0, 0);
+ }
+ pw_unlock();
+}
+
int main(int argc, char *argv[])
{
- struct stat begin, end;
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
@@ -265,15 +288,14 @@ int main(int argc, char *argv[])
progname = (rindex(argv[0], '/')) ? rindex(argv[0], '/') + 1 : argv[0];
if (!strcmp(progname, "vigr")) {
program = VIGR;
- strncpy(orig_file, GROUP_FILE, FILENAMELEN-1);
- strncpy(tmp_file, GTMP_FILE, FILENAMELEN-1);
- strncpy(tmptmp_file, GTMPTMP_FILE, FILENAMELEN-1);
- }
- else {
+ xstrncpy(orig_file, GROUP_FILE, sizeof(orig_file));
+ xstrncpy(tmp_file, GTMP_FILE, sizeof(tmp_file));
+ xstrncpy(tmptmp_file, GTMPTMP_FILE, sizeof(tmptmp_file));
+ } else {
program = VIPW;
- strncpy(orig_file, PASSWD_FILE, FILENAMELEN-1);
- strncpy(tmp_file, PTMP_FILE, FILENAMELEN-1);
- strncpy(tmptmp_file, PTMPTMP_FILE, FILENAMELEN-1);
+ xstrncpy(orig_file, PASSWD_FILE, sizeof(orig_file));
+ xstrncpy(tmp_file, PTMP_FILE, sizeof(tmp_file));
+ xstrncpy(tmptmp_file, PTMPTMP_FILE, sizeof(tmptmp_file));
}
if ((argc > 1) &&
@@ -282,18 +304,32 @@ int main(int argc, char *argv[])
exit(0);
}
- pw_init();
- pw_lock();
-
- if (stat(tmp_file, &begin))
- pw_error(tmp_file, 1, 1);
- pw_edit(0);
- if (stat(tmp_file, &end))
- pw_error(tmp_file, 1, 1);
- if (begin.st_mtime == end.st_mtime) {
- (void)fprintf(stderr, _("%s: no changes made\n"), progname);
- pw_error((char *)NULL, 0, 0);
+ edit_file();
+
+ if (program == VIGR) {
+ strncpy(orig_file, SGROUP_FILE, FILENAMELEN-1);
+ strncpy(tmp_file, SGTMP_FILE, FILENAMELEN-1);
+ strncpy(tmptmp_file, SGTMPTMP_FILE, FILENAMELEN-1);
+ } else {
+ strncpy(orig_file, SHADOW_FILE, FILENAMELEN-1);
+ strncpy(tmp_file, SPTMP_FILE, FILENAMELEN-1);
+ strncpy(tmptmp_file, SPTMPTMP_FILE, FILENAMELEN-1);
}
- pw_unlock();
+
+ if (!access(orig_file, X_OK)) {
+ char response[80];
+
+ printf((program == VIGR)
+ ? _("You are using shadow groups on this system.\n")
+ : _("You are using shadow passwords on this system.\n"));
+ printf(_("Would you like to edit %s now [y/n]? "), orig_file);
+
+ /* EOF means no */
+ if (fgets(response, sizeof(response), stdin)) {
+ if (response[0] == 'y' || response[0] == 'Y')
+ edit_file();
+ }
+ }
+
exit(0);
}
diff --git a/login-utils/wall.c b/login-utils/wall.c
index 6840015d4..3a13fe7ba 100644
--- a/login-utils/wall.c
+++ b/login-utils/wall.c
@@ -37,7 +37,7 @@
* This program is not related to David Wall, whose Stanford Ph.D. thesis
* is entitled "Mechanisms for Broadcast and Selective Broadcast".
*
- * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@misiek.eu.org>
+ * 1999-02-22 Arkadiusz Mi¶kiewicz <misiek@pld.ORG.PL>
* - added Native Language Support
*
*/
@@ -53,10 +53,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <time.h>
#include <unistd.h>
#include <utmp.h>
#include "nls.h"
+#include "xstrncpy.h"
#include "ttymsg.h"
#include "pathnames.h"
#include "carefulputc.h"
@@ -115,14 +117,14 @@ usage:
iov.iov_len = mbufsize;
while((utmpptr = getutent())) {
if (!utmpptr->ut_name[0] ||
- !strncmp(utmpptr->ut_name, IGNOREUSER, sizeof(utmpptr->ut_name)))
+ !strncmp(utmpptr->ut_name, IGNOREUSER,
+ sizeof(utmpptr->ut_name)))
continue;
#ifdef USER_PROCESS
if (utmpptr->ut_type != USER_PROCESS)
continue;
#endif
- strncpy(line, utmpptr->ut_line, sizeof(utmpptr->ut_line));
- line[sizeof(utmpptr->ut_line)-1] = '\0';
+ xstrncpy(line, utmpptr->ut_line, sizeof(utmpptr->ut_line));
if ((p = ttymsg(&iov, 1, line, 60*5)) != NULL)
(void)fprintf(stderr, "%s: %s\n", progname, p);
}