diff options
author | millert <> | 2003-05-05 22:13:03 +0000 |
---|---|---|
committer | millert <> | 2003-05-05 22:13:03 +0000 |
commit | 3512822e2f5923ed1823cf94b42172157fddd7e3 (patch) | |
tree | 01c46819bd1f7d24cbd5d7c9e53edc734792ecc0 /src | |
parent | 085895ca2bb9375ce5be725e0f30556bb90b0276 (diff) | |
download | openbsd-3512822e2f5923ed1823cf94b42172157fddd7e3.tar.gz openbsd-3512822e2f5923ed1823cf94b42172157fddd7e3.tar.bz2 openbsd-3512822e2f5923ed1823cf94b42172157fddd7e3.zip |
Add support for command line args in rshprog, e.g. "ssh -C".
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libc/net/rcmdsh.3 | 9 | ||||
-rw-r--r-- | src/lib/libc/net/rcmdsh.c | 55 |
2 files changed, 53 insertions, 11 deletions
diff --git a/src/lib/libc/net/rcmdsh.3 b/src/lib/libc/net/rcmdsh.3 index e0c59efb85..e993d2c9d5 100644 --- a/src/lib/libc/net/rcmdsh.3 +++ b/src/lib/libc/net/rcmdsh.3 | |||
@@ -1,4 +1,4 @@ | |||
1 | .\" $OpenBSD: rcmdsh.3,v 1.8 2000/12/24 00:30:56 aaron Exp $ | 1 | .\" $OpenBSD: rcmdsh.3,v 1.9 2003/05/05 22:13:03 millert Exp $ |
2 | .\" | 2 | .\" |
3 | .\" Copyright (c) 1983, 1991, 1993 | 3 | .\" Copyright (c) 1983, 1991, 1993 |
4 | .\" The Regents of the University of California. All rights reserved. | 4 | .\" The Regents of the University of California. All rights reserved. |
@@ -31,7 +31,7 @@ | |||
31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 31 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
32 | .\" SUCH DAMAGE. | 32 | .\" SUCH DAMAGE. |
33 | .\" | 33 | .\" |
34 | .Dd September 1, 1996 | 34 | .Dd May 5, 2003 |
35 | .Dt RCMDSH 3 | 35 | .Dt RCMDSH 3 |
36 | .Os | 36 | .Os |
37 | .Sh NAME | 37 | .Sh NAME |
@@ -46,10 +46,13 @@ The | |||
46 | .Fn rcmdsh | 46 | .Fn rcmdsh |
47 | function is used by normal users to execute a command on a remote machine | 47 | function is used by normal users to execute a command on a remote machine |
48 | using an authentication scheme based on reserved port numbers using | 48 | using an authentication scheme based on reserved port numbers using |
49 | .Xr rshd 8 | 49 | .Xr rsh 1 |
50 | or the value of | 50 | or the value of |
51 | .Fa rshprog | 51 | .Fa rshprog |
52 | (if non-null). | 52 | (if non-null). |
53 | .Fa rshprog | ||
54 | may be a fully-qualified path, a non-qualified command, or a command containing | ||
55 | space-separated command line arguments. | ||
53 | .Pp | 56 | .Pp |
54 | The | 57 | The |
55 | .Fn rcmdsh | 58 | .Fn rcmdsh |
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) |
37 | static char *rcsid = "$OpenBSD: rcmdsh.c,v 1.7 2002/03/12 00:05:44 millert Exp $"; | 37 | static 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 { |