From: Ryan Bloom Date: Fri, 31 Dec 1999 01:27:43 +0000 (+0000) Subject: Get rid of ap_call_exec. It has been #if 0'ed out for a long time, and we X-Git-Tag: 1.3.10~41 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6786681590be62f0cc27a40b8811de608acad326;p=apache Get rid of ap_call_exec. It has been #if 0'ed out for a long time, and we never call it, so I'm taking it out all together now. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@84377 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/include/util_script.h b/include/util_script.h index 36c1067b05..d438c63fdb 100644 --- a/include/util_script.h +++ b/include/util_script.h @@ -81,8 +81,6 @@ API_EXPORT(int) ap_scan_script_header_err_core(request_rec *r, char *buffer, int (*getsfunc) (char *, int, void *), void *getsfunc_data); API_EXPORT(void) ap_send_size(ap_ssize_t size, request_rec *r); -API_EXPORT(int) ap_call_exec(request_rec *r, ap_child_info_t *pinfo, char *argv0, char **env, - int shellcmd); #ifdef __cplusplus } diff --git a/server/util_script.c b/server/util_script.c index 5de8b74a12..3997644cf8 100644 --- a/server/util_script.c +++ b/server/util_script.c @@ -682,414 +682,3 @@ static char **create_argv_cmd(ap_context_t *p, char *av0, const char *args, char } #endif -#if 0 -API_EXPORT(int) ap_call_exec(request_rec *r, ap_child_info_t *pinfo, char *argv0, - char **env, int shellcmd) -{ - int pid = 0; - int errfileno = STDERR_FILENO; - -#if !defined(WIN32) && !defined(OS2) - /* the fd on r->server->error_log is closed, but we need somewhere to - * put the error messages from the log_* functions. So, we use stderr, - * since that is better than allowing errors to go unnoticed. Don't do - * this on Win32, though, since we haven't fork()'d. - */ - ap_put_os_file(&r->server->error_log, &errfileno, r->pool); -#endif - - /* TODO: all that RLimit stuff should become part of the spawning API, - * and not something in the core_dir_config... define a special rlimit - * structure and pass it in here. - */ - -#ifdef OS2 - { - /* Additions by Alec Kloss, to allow exec'ing of scripts under OS/2 */ - int is_script = 0; - char interpreter[2048]; /* hope it's enough for the interpreter path */ - char error_object[260]; - FILE *program; - char *cmdline = r->filename, *cmdline_pos; - int cmdlen; - char *args = "", *args_end; - ULONG rc; - RESULTCODES rescodes; - int env_len, e; - char *env_block, *env_block_pos; - - if (r->args && r->args[0] && !strchr(r->args, '=')) - args = r->args; - - program = fopen(r->filename, "rt"); - - if (!program) { - ap_log_rerror(APLOG_MARK, APLOG_ERR, r, "fopen(%s) failed", - r->filename); - return (pid); - } - - fgets(interpreter, sizeof(interpreter), program); - fclose(program); - - if (!strncmp(interpreter, "#!", 2)) { - is_script = 1; - interpreter[strlen(interpreter) - 1] = '\0'; - if (interpreter[2] != '/' && interpreter[2] != '\\' && interpreter[3] != ':') { - char buffer[300]; - if (DosSearchPath(SEARCH_ENVIRONMENT, "PATH", interpreter+2, buffer, sizeof(buffer)) == 0) { - strcpy(interpreter+2, buffer); - } else { - strcat(interpreter, ".exe"); - if (DosSearchPath(SEARCH_ENVIRONMENT, "PATH", interpreter+2, buffer, sizeof(buffer)) == 0) { - strcpy(interpreter+2, buffer); - } - } - } - } - - if (is_script) { - cmdline = ap_pstrcat(r->pool, interpreter+2, " ", r->filename, NULL); - } - else if (strstr(strupr(r->filename), ".CMD") > 0) { - /* Special case to allow use of REXX commands as scripts. */ - os2pathname(r->filename); - cmdline = ap_pstrcat(r->pool, SHELL_PATH, " /C ", r->filename, NULL); - } - else { - cmdline = r->filename; - } - - args = ap_pstrdup(r->pool, args); - ap_unescape_url(args); - args = ap_double_quotes(r->pool, args); - args_end = args + strlen(args); - - if (args_end - args > 4000) { /* cmd.exe won't handle lines longer than 4k */ - args_end = args + 4000; - *args_end = 0; - } - - /* +4 = 1 space between progname and args, 2 for double null at end, 2 for possible quote on first arg */ - cmdlen = strlen(cmdline) + strlen(args) + 4; - cmdline_pos = cmdline; - - while (*cmdline_pos) { - cmdlen += 2 * (*cmdline_pos == '+'); /* Allow space for each arg to be quoted */ - cmdline_pos++; - } - - cmdline = ap_pstrndup(r->pool, cmdline, cmdlen); - cmdline_pos = cmdline + strlen(cmdline); - - while (args < args_end) { - char *arg; - - arg = ap_getword_nc(r->pool, &args, '+'); - - if (strpbrk(arg, "&|<> ")) - arg = ap_pstrcat(r->pool, "\"", arg, "\"", NULL); - - *(cmdline_pos++) = ' '; - strcpy(cmdline_pos, arg); - cmdline_pos += strlen(cmdline_pos); - } - - *(++cmdline_pos) = 0; /* Add required second terminator */ - args = strchr(cmdline, ' '); - - if (args) { - *args = 0; - args++; - } - - /* Create environment block from list of envariables */ - for (env_len=1, e=0; env[e]; e++) - env_len += strlen(env[e]) + 1; - - env_block = ap_palloc(r->pool, env_len); - env_block_pos = env_block; - - for (e=0; env[e]; e++) { - strcpy(env_block_pos, env[e]); - env_block_pos += strlen(env_block_pos) + 1; - } - - *env_block_pos = 0; /* environment block is terminated by a double null */ - - rc = DosExecPgm(error_object, sizeof(error_object), EXEC_ASYNC, cmdline, env_block, &rescodes, cmdline); - - if (rc) { - ap_log_rerror(APLOG_MARK, APLOG_ERR, r, "DosExecPgm(%s %s) failed, %s - %s", - cmdline, args ? args : "", ap_os_error_message(rc), error_object ); - return -1; - } - - return rescodes.codeTerminate; - } -#elif defined(WIN32) - { - /* Adapted from Alec Kloss' work for OS/2 */ - char *interpreter = NULL; - char *arguments = NULL; - char *ext = NULL; - char *exename = NULL; - char *s = NULL; - char *quoted_filename; - char *pCommand; - char *pEnvBlock, *pNext; - - int i; - int iEnvBlockLen; - - file_type_e fileType; - - STARTUPINFO si; - PROCESS_INFORMATION pi; - - memset(&si, 0, sizeof(si)); - memset(&pi, 0, sizeof(pi)); - - pid = -1; - - if (!shellcmd) { - - fileType = ap_get_win32_interpreter(r, &interpreter); - - if (fileType == eFileTypeUNKNOWN) { - ap_log_rerror(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, r, - "%s is not executable; ensure interpreted scripts have " - "\"#!\" first line", - r->filename); - return (pid); - } - - /* - * Look at the arguments... - */ - arguments = ""; - if ((r->args) && (r->args[0]) && !strchr(r->args, '=')) { - /* If we are in this leg, there are some other arguments - * that we must include in the execution of the CGI. - * Because CreateProcess is the way it is, we have to - * create a command line like format for the execution - * of the CGI. This means we need to create on long - * string with the executable and arguments. - * - * The arguments string comes in the request structure, - * and each argument is separated by a '+'. We'll replace - * these pluses with spaces. - */ - - int iStringSize = 0; - int x; - - /* - * Duplicate the request structure string so we don't change it. - */ - arguments = ap_pstrdup(r->pool, r->args); - - /* - * Change the '+' to ' ' - */ - for (x=0; arguments[x]; x++) { - if ('+' == arguments[x]) { - arguments[x] = ' '; - } - } - - /* - * We need to unescape any characters that are - * in the arguments list. - */ - ap_unescape_url(arguments); - arguments = ap_escape_shell_cmd(r->pool, arguments); - } - - /* - * We have the interpreter (if there is one) and we have - * the arguments (if there are any). - * Build the command string to pass to CreateProcess. - */ - quoted_filename = ap_pstrcat(r->pool, "\"", r->filename, "\"", NULL); - if (interpreter && *interpreter) { - pCommand = ap_pstrcat(r->pool, interpreter, " ", - quoted_filename, " ", arguments, NULL); - } - else { - pCommand = ap_pstrcat(r->pool, quoted_filename, " ", arguments, NULL); - } - - } else { - - char *shell_cmd = "CMD.EXE /C "; - OSVERSIONINFO osver; - osver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); - - /* - * Use CMD.EXE for NT, COMMAND.COM for WIN95 - */ - if (GetVersionEx(&osver)) { - if (osver.dwPlatformId != VER_PLATFORM_WIN32_NT) { - shell_cmd = "COMMAND.COM /C "; - } - } - pCommand = ap_pstrcat(r->pool, shell_cmd, argv0, NULL); - } - - /* - * Make child process use hPipeOutputWrite as standard out, - * and make sure it does not show on screen. - */ - si.cb = sizeof(si); - si.dwFlags = STARTF_USESHOWWINDOW | STARTF_USESTDHANDLES; - si.wShowWindow = SW_HIDE; - si.hStdInput = pinfo->hPipeInputRead; - si.hStdOutput = pinfo->hPipeOutputWrite; - si.hStdError = pinfo->hPipeErrorWrite; - - /* - * Win32's CreateProcess call requires that the environment - * be passed in an environment block, a null terminated block of - * null terminated strings. - */ - i = 0; - iEnvBlockLen = 1; - while (env[i]) { - iEnvBlockLen += strlen(env[i]) + 1; - i++; - } - - pEnvBlock = (char *)ap_pcalloc(r->pool,iEnvBlockLen); - - i = 0; - pNext = pEnvBlock; - while (env[i]) { - strcpy(pNext, env[i]); - pNext = pNext + strlen(pNext) + 1; - i++; - } - - if (CreateProcess(NULL, pCommand, NULL, NULL, TRUE, DETACHED_PROCESS, pEnvBlock, - ap_make_dirstr_parent(r->pool, r->filename), - &si, &pi)) { - if (fileType == eFileTypeEXE16) { - /* Hack to get 16-bit CGI's working. It works for all the - * standard modules shipped with Apache. pi.dwProcessId is 0 - * for 16-bit CGIs and all the Unix specific code that calls - * ap_call_exec interprets this as a failure case. And we can't - * use -1 either because it is mapped to 0 by the caller. - */ - pid = -2; - } - else { - pid = pi.dwProcessId; - /* - * We must close the handles to the new process and its main thread - * to prevent handle and memory leaks. - */ - CloseHandle(pi.hProcess); - CloseHandle(pi.hThread); - } - } - return (pid); - } - -#else - /* TODO: reimplement suexec */ -#if 0 - if (ap_suexec_enabled - && ((r->server->server_uid != ap_user_id) - || (r->server->server_gid != ap_group_id) - || (!strncmp("/~", r->uri, 2)))) { - - char *execuser, *grpname; - struct passwd *pw; - struct group *gr; - - if (!strncmp("/~", r->uri, 2)) { - gid_t user_gid; - char *username = ap_pstrdup(r->pool, r->uri + 2); - char *pos = strchr(username, '/'); - - if (pos) { - *pos = '\0'; - } - - if ((pw = getpwnam(username)) == NULL) { - ap_log_rerror(APLOG_MARK, APLOG_ERR, r, - "getpwnam: invalid username %s", username); - return (pid); - } - execuser = ap_pstrcat(r->pool, "~", pw->pw_name, NULL); - user_gid = pw->pw_gid; - - if ((gr = getgrgid(user_gid)) == NULL) { - if ((grpname = ap_palloc(r->pool, 16)) == NULL) { - return (pid); - } - else { - ap_snprintf(grpname, 16, "%ld", (long) user_gid); - } - } - else { - grpname = gr->gr_name; - } - } - else { - if ((pw = getpwuid(r->server->server_uid)) == NULL) { - ap_log_rerror(APLOG_MARK, APLOG_ERR, r, - "getpwuid: invalid userid %ld", - (long) r->server->server_uid); - return (pid); - } - execuser = ap_pstrdup(r->pool, pw->pw_name); - - if ((gr = getgrgid(r->server->server_gid)) == NULL) { - ap_log_rerror(APLOG_MARK, APLOG_ERR, r, - "getgrgid: invalid groupid %ld", - (long) r->server->server_gid); - return (pid); - } - grpname = gr->gr_name; - } - - if (shellcmd) { - execle(SUEXEC_BIN, SUEXEC_BIN, execuser, grpname, argv0, - NULL, env); - } - - else if ((!r->args) || (!r->args[0]) || strchr(r->args, '=')) { - execle(SUEXEC_BIN, SUEXEC_BIN, execuser, grpname, argv0, - NULL, env); - } - - else { - execve(SUEXEC_BIN, - create_argv(r->pool, SUEXEC_BIN, execuser, grpname, - argv0, r->args), - env); - } - } - else { -#endif - if (shellcmd) { - execle(SHELL_PATH, SHELL_PATH, "-c", argv0, NULL, env); - } - - else if ((!r->args) || (!r->args[0]) || strchr(r->args, '=')) { - execle(r->filename, argv0, NULL, env); - } - - else { - execve(r->filename, - create_argv(r->pool, NULL, NULL, NULL, argv0, r->args), - env); - } -#if 0 - } -#endif - return (pid); -#endif -} -#endif