Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-1-4]: src/lib/libutil Pull up revision 1.19 (requested by mjl):
details: https://anonhg.NetBSD.org/src/rev/47e744d6f9da
branches: netbsd-1-4
changeset: 469850:47e744d6f9da
user: he <he%NetBSD.org@localhost>
date: Sat Dec 04 20:00:55 1999 +0000
description:
Pull up revision 1.19 (requested by mjl):
Correct handling of more complex EDITOR environment variable
settings by using /bin/sh. Fixes PR#8935.
diffstat:
lib/libutil/passwd.c | 69 ++++++++++++++++++---------------------------------
1 files changed, 24 insertions(+), 45 deletions(-)
diffs (121 lines):
diff -r 2c1f9a3e6a95 -r 47e744d6f9da lib/libutil/passwd.c
--- a/lib/libutil/passwd.c Sat Dec 04 19:57:23 1999 +0000
+++ b/lib/libutil/passwd.c Sat Dec 04 20:00:55 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: passwd.c,v 1.15 1998/12/09 14:35:03 christos Exp $ */
+/* $NetBSD: passwd.c,v 1.15.2.1 1999/12/04 20:00:55 he Exp $ */
/*
* Copyright (c) 1987, 1993, 1994, 1995
@@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: passwd.c,v 1.15 1998/12/09 14:35:03 christos Exp $");
+__RCSID("$NetBSD: passwd.c,v 1.15.2.1 1999/12/04 20:00:55 he Exp $");
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@@ -90,6 +90,9 @@
pid_t pid;
pid = vfork();
+ if (pid == -1)
+ return (-1);
+
if (pid == 0) {
execl(_PATH_PWD_MKDB, "pwd_mkdb", "-p",
_PATH_MASTERPASSWD_LOCK, NULL);
@@ -154,64 +157,42 @@
int notsetuid;
const char *filename;
{
- int i, xargc, pstat;
+ int pstat;
char *p, *editor;
- char **xargv;
+ char *argp[] = { "sh", "-c", NULL, NULL };
+
#ifdef __GNUC__
(void) &editor;
#endif
if (filename == NULL)
filename = _PATH_MASTERPASSWD_LOCK;
+
if ((editor = getenv("EDITOR")) == NULL)
- editor = strdup(_PATH_VI);
- else
- editor = strdup(editor);
- if ((p = strrchr(editor, '/')) != NULL)
- ++p;
- else
- p = editor;
+ editor = _PATH_VI;
- /* Scan editor string, count spaces, allocate arg vector. */
- for (i = 0, xargc = 0; p[i] != '\0'; i++) {
- if (isspace(p[i])) {
- while (isspace(p[i++]))
- /* skip white space */ ;
- if (p[i] == '\0')
- break;
- xargc++;
- }
- }
+ p = malloc(strlen(editor) + 1 + strlen(filename) + 1);
+ if (p == NULL)
+ return;
- /* argv[0] + <xargc args> + filename + NULL */
- xargv = (char **)malloc(sizeof(char *) * (xargc + 3));
- if (xargv == NULL)
- pw_error("malloc failed", 1, 1);
+ sprintf(p, "%s %s", editor, filename);
+ argp[2] = p;
- i = 0;
- xargv[i++] = p;
- for (; *p != '\0'; p++) {
- if (isspace(*p)) {
- while(isspace(*p))
- *p++ = '\0'; /* blast whitespace */
- if (*p == '\0')
- break;
- xargv[i++] = p;
- }
- }
-
- /*LINTED*/
- xargv[i++] = (char *)filename;
- xargv[i] = NULL;
-
- if (!(editpid = vfork())) {
+ switch(editpid = vfork()) {
+ case -1:
+ free(p);
+ return;
+ case 0:
if (notsetuid) {
setgid(getgid());
setuid(getuid());
}
- execvp(editor, xargv);
+ execvp(_PATH_BSHELL, argp);
_exit(1);
}
+
+ free(p);
+
for (;;) {
editpid = waitpid(editpid, (int *)&pstat, WUNTRACED);
if (editpid == -1)
@@ -224,8 +205,6 @@
pw_error(editor, 1, 1);
}
editpid = -1;
- free(editor);
- free(xargv);
}
void
Home |
Main Index |
Thread Index |
Old Index