]> granicus.if.org Git - sudo/commitdiff
Move exec_cmnd to exec.c to fix a compilation issue with sesh.c
authorTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 14 Mar 2013 23:59:07 +0000 (19:59 -0400)
committerTodd C. Miller <Todd.Miller@courtesan.com>
Thu, 14 Mar 2013 23:59:07 +0000 (19:59 -0400)
src/exec.c
src/exec_common.c

index 10199c20d6354ccd6cb8524c3634cd015ce6fa49..ddb5c4bf3c7abe0c283c4986666a7f1231215fa3 100644 (file)
@@ -148,7 +148,55 @@ static int fork_cmnd(struct command_details *details, int sv[2])
 }
 
 /*
- * Execute a command, potentially in a pty with I/O loggging.
+ * Setup the execution environment and execute the command.
+ * If SELinux is enabled, run the command via sesh, otherwise
+ * execute it directly.
+ * If the exec fails, cstat is filled in with the value of errno.
+ */
+void
+exec_cmnd(struct command_details *details, struct command_status *cstat,
+    int *errfd)
+{
+    debug_decl(exec_cmnd, SUDO_DEBUG_EXEC)
+
+    restore_signals();
+    if (exec_setup(details, NULL, -1) == true) {
+       /* headed for execve() */
+       sudo_debug_execve(SUDO_DEBUG_INFO, details->command,
+           details->argv, details->envp);
+       if (details->closefrom >= 0) {
+           int maxfd = details->closefrom;
+           /* Preserve back channel if present. */
+           if (errfd != NULL) {
+               dup2(*errfd, maxfd);
+               (void)fcntl(maxfd, F_SETFD, FD_CLOEXEC);
+               *errfd = maxfd++;
+           }
+           if (sudo_debug_fd_set(maxfd) != -1)
+               maxfd++;
+           closefrom(maxfd);
+       }
+#ifdef HAVE_SELINUX
+       if (ISSET(details->flags, CD_RBAC_ENABLED)) {
+           selinux_execve(details->command, details->argv, details->envp,
+               ISSET(details->flags, CD_NOEXEC));
+       } else
+#endif
+       {
+           sudo_execve(details->command, details->argv, details->envp,
+               ISSET(details->flags, CD_NOEXEC));
+       }
+       cstat->type = CMD_ERRNO;
+       cstat->val = errno;
+       sudo_debug_printf(SUDO_DEBUG_ERROR, "unable to exec %s: %s",
+           details->command, strerror(errno));
+    }
+    debug_return;
+}
+
+/*
+ * Execute a command, potentially in a pty with I/O loggging, and
+ * wait for it to finish.
  * This is a little bit tricky due to how POSIX job control works and
  * we fact that we have two different controlling terminals to deal with.
  */
index e23b628d1aa089b84f97b20a6c2f2f8201c2c888..923a0fe019d0fa0a8268a4955adc751cdf9467a4 100644 (file)
@@ -157,44 +157,3 @@ sudo_execve(const char *path, char *const argv[], char *const envp[], int noexec
     }
     return -1;
 }
-
-void
-exec_cmnd(struct command_details *details, struct command_status *cstat,
-    int *errfd)
-{
-    debug_decl(exec_cmnd, SUDO_DEBUG_EXEC)
-
-    restore_signals();
-    if (exec_setup(details, NULL, -1) == true) {
-       /* headed for execve() */
-       sudo_debug_execve(SUDO_DEBUG_INFO, details->command,
-           details->argv, details->envp);
-       if (details->closefrom >= 0) {
-           int maxfd = details->closefrom;
-           /* Preserve back channel if present. */
-           if (errfd != NULL) {
-               dup2(*errfd, maxfd);
-               (void)fcntl(maxfd, F_SETFD, FD_CLOEXEC);
-               *errfd = maxfd++;
-           }
-           if (sudo_debug_fd_set(maxfd) != -1)
-               maxfd++;
-           closefrom(maxfd);
-       }
-#ifdef HAVE_SELINUX
-       if (ISSET(details->flags, CD_RBAC_ENABLED)) {
-           selinux_execve(details->command, details->argv, details->envp,
-               ISSET(details->flags, CD_NOEXEC));
-       } else
-#endif
-       {
-           sudo_execve(details->command, details->argv, details->envp,
-               ISSET(details->flags, CD_NOEXEC));
-       }
-       cstat->type = CMD_ERRNO;
-       cstat->val = errno;
-       sudo_debug_printf(SUDO_DEBUG_ERROR, "unable to exec %s: %s",
-           details->command, strerror(errno));
-    }
-    debug_return;
-}