diff options
Diffstat (limited to 'sshconnect.c')
-rw-r--r-- | sshconnect.c | 38 |
1 files changed, 37 insertions, 1 deletions
diff --git a/sshconnect.c b/sshconnect.c index 2245a8af6..64ffec240 100644 --- a/sshconnect.c +++ b/sshconnect.c | |||
@@ -13,7 +13,7 @@ | |||
13 | */ | 13 | */ |
14 | 14 | ||
15 | #include "includes.h" | 15 | #include "includes.h" |
16 | RCSID("$OpenBSD: sshconnect.c,v 1.170 2005/10/30 08:52:18 djm Exp $"); | 16 | RCSID("$OpenBSD: sshconnect.c,v 1.171 2005/12/06 22:38:27 reyk Exp $"); |
17 | 17 | ||
18 | #include <openssl/bn.h> | 18 | #include <openssl/bn.h> |
19 | 19 | ||
@@ -1034,3 +1034,39 @@ warn_changed_key(Key *host_key) | |||
1034 | 1034 | ||
1035 | xfree(fp); | 1035 | xfree(fp); |
1036 | } | 1036 | } |
1037 | |||
1038 | /* | ||
1039 | * Execute a local command | ||
1040 | */ | ||
1041 | int | ||
1042 | ssh_local_cmd(const char *args) | ||
1043 | { | ||
1044 | char *shell; | ||
1045 | pid_t pid; | ||
1046 | int status; | ||
1047 | |||
1048 | if (!options.permit_local_command || | ||
1049 | args == NULL || !*args) | ||
1050 | return (1); | ||
1051 | |||
1052 | if ((shell = getenv("SHELL")) == NULL) | ||
1053 | shell = _PATH_BSHELL; | ||
1054 | |||
1055 | pid = fork(); | ||
1056 | if (pid == 0) { | ||
1057 | debug3("Executing %s -c \"%s\"", shell, args); | ||
1058 | execl(shell, shell, "-c", args, (char *)NULL); | ||
1059 | error("Couldn't execute %s -c \"%s\": %s", | ||
1060 | shell, args, strerror(errno)); | ||
1061 | _exit(1); | ||
1062 | } else if (pid == -1) | ||
1063 | fatal("fork failed: %.100s", strerror(errno)); | ||
1064 | while (waitpid(pid, &status, 0) == -1) | ||
1065 | if (errno != EINTR) | ||
1066 | fatal("Couldn't wait for child: %s", strerror(errno)); | ||
1067 | |||
1068 | if (!WIFEXITED(status)) | ||
1069 | return (1); | ||
1070 | |||
1071 | return (WEXITSTATUS(status)); | ||
1072 | } | ||