summaryrefslogtreecommitdiff
path: root/src/lib/libc/net/rcmdsh.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/net/rcmdsh.c')
-rw-r--r--src/lib/libc/net/rcmdsh.c55
1 files changed, 47 insertions, 8 deletions
diff --git a/src/lib/libc/net/rcmdsh.c b/src/lib/libc/net/rcmdsh.c
index a1c7e7d6b8..2a2a5d77fe 100644
--- a/src/lib/libc/net/rcmdsh.c
+++ b/src/lib/libc/net/rcmdsh.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rcmdsh.c,v 1.7 2002/03/12 00:05:44 millert Exp $ */ 1/* $OpenBSD: rcmdsh.c,v 1.8 2003/05/05 22:13:03 millert Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2001, MagniComp 4 * Copyright (c) 2001, MagniComp
@@ -34,7 +34,7 @@
34 */ 34 */
35 35
36#if defined(LIBC_SCCS) && !defined(lint) 36#if defined(LIBC_SCCS) && !defined(lint)
37static char *rcsid = "$OpenBSD: rcmdsh.c,v 1.7 2002/03/12 00:05:44 millert Exp $"; 37static char *rcsid = "$OpenBSD: rcmdsh.c,v 1.8 2003/05/05 22:13:03 millert Exp $";
38#endif /* LIBC_SCCS and not lint */ 38#endif /* LIBC_SCCS and not lint */
39 39
40#include <sys/types.h> 40#include <sys/types.h>
@@ -44,6 +44,7 @@ static char *rcsid = "$OpenBSD: rcmdsh.c,v 1.7 2002/03/12 00:05:44 millert Exp $
44#include <errno.h> 44#include <errno.h>
45#include <netdb.h> 45#include <netdb.h>
46#include <stdio.h> 46#include <stdio.h>
47#include <stdlib.h>
47#include <string.h> 48#include <string.h>
48#include <pwd.h> 49#include <pwd.h>
49#include <paths.h> 50#include <paths.h>
@@ -127,19 +128,57 @@ rcmdsh(ahost, rport, locuser, remuser, cmd, rshprog)
127 * are the same, avoid running remote shell for efficiency. 128 * are the same, avoid running remote shell for efficiency.
128 */ 129 */
129 if (!strcmp(*ahost, "localhost") && !strcmp(locuser, remuser)) { 130 if (!strcmp(*ahost, "localhost") && !strcmp(locuser, remuser)) {
131 char *argv[4];
130 if (pw->pw_shell[0] == '\0') 132 if (pw->pw_shell[0] == '\0')
131 rshprog = _PATH_BSHELL; 133 rshprog = _PATH_BSHELL;
132 else 134 else
133 rshprog = pw->pw_shell; 135 rshprog = pw->pw_shell;
134 p = strrchr(rshprog, '/'); 136 p = strrchr(rshprog, '/');
135 execlp(rshprog, p ? p+1 : rshprog, "-c", cmd, 137 argv[0] = p ? p + 1 : rshprog;
136 (char *) NULL); 138 argv[1] = "-c";
137 } else { 139 argv[2] = (char *)cmd;
140 argv[3] = NULL;
141 execvp(rshprog, argv);
142 } else if ((p = strchr(rshprog, ' ')) == NULL) {
143 /* simple case */
144 char *argv[6];
138 p = strrchr(rshprog, '/'); 145 p = strrchr(rshprog, '/');
139 execlp(rshprog, p ? p+1 : rshprog, *ahost, "-l", 146 argv[0] = p ? p + 1 : rshprog;
140 remuser, cmd, (char *) NULL); 147 argv[1] = "-l";
148 argv[2] = (char *)remuser;
149 argv[3] = *ahost;
150 argv[4] = (char *)cmd;
151 argv[5] = NULL;
152 execvp(rshprog, argv);
153 } else {
154 /* must pull args out of rshprog and dyn alloc argv */
155 char **argv, **ap;
156 int n;
157 for (n = 7; (p = strchr(++p, ' ')) != NULL; n++)
158 continue;
159 rshprog = strdup(rshprog);
160 ap = argv = malloc(sizeof(char *) * n);
161 if (rshprog == NULL || argv == NULL) {
162 perror("rcmdsh");
163 _exit(255);
164 }
165 while ((p = strsep(&rshprog, " ")) != NULL) {
166 if (*p == '\0')
167 continue;
168 *ap++ = p;
169 }
170 if (ap != argv) /* all spaces?!? */
171 rshprog = argv[0];
172 if ((p = strrchr(argv[0], '/')) != NULL)
173 argv[0] = p + 1;
174 *ap++ = "-l";
175 *ap++ = (char *)remuser;
176 *ap++ = *ahost;
177 *ap++ = (char *)cmd;
178 *ap++ = NULL;
179 execvp(rshprog, argv);
141 } 180 }
142 (void) fprintf(stderr, "rcmdsh: execlp %s failed: %s\n", 181 (void) fprintf(stderr, "rcmdsh: execvp %s failed: %s\n",
143 rshprog, strerror(errno)); 182 rshprog, strerror(errno));
144 _exit(255); 183 _exit(255);
145 } else { 184 } else {