1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 #include "apr_strings.h"
18 #include "arch/win32/apr_arch_file_io.h"
19 #include "arch/win32/apr_arch_misc.h"
30 AP_DECLARE(apr_status_t) ap_os_proc_filepath(char **binpath, apr_pool_t *p)
32 apr_wchar_t wbinpath[APR_PATH_MAX];
34 #if APR_HAS_UNICODE_FS
40 if (!GetModuleFileNameW(NULL, wbinpath, sizeof(wbinpath)
41 / sizeof(apr_wchar_t))) {
42 return apr_get_os_error();
44 wbinlen = wcslen(wbinpath) + 1;
45 binlen = (wbinlen - 1) * 3 + 1;
46 *binpath = apr_palloc(p, binlen);
47 rv = apr_conv_ucs2_to_utf8(wbinpath, &wbinlen, *binpath, &binlen);
48 if (rv != APR_SUCCESS)
51 return APR_ENAMETOOLONG;
53 #endif /* APR_HAS_UNICODE_FS */
57 /* share the same scratch buffer */
58 char *pathbuf = (char*) wbinpath;
59 if (!GetModuleFileName(NULL, pathbuf, sizeof(wbinpath))) {
60 return apr_get_os_error();
62 *binpath = apr_pstrdup(p, pathbuf);
69 AP_DECLARE(apr_status_t) ap_os_create_privileged_process(
71 apr_proc_t *newproc, const char *progname,
72 const char * const *args,
73 const char * const *env,
74 apr_procattr_t *attr, apr_pool_t *p)
76 return apr_proc_create(newproc, progname, args, env, attr, p);
80 /* This code is stolen from misc/win32/misc.c and apr_private.h
81 * This helper code resolves late bound entry points
82 * missing from one or more releases of the Win32 API...
83 * but it sure would be nice if we didn't duplicate this code
86 static const char* const lateDllName[DLL_defined] = {
87 "kernel32", "advapi32", "mswsock", "ws2_32" };
88 static HMODULE lateDllHandle[DLL_defined] = {
89 NULL, NULL, NULL, NULL };
92 FARPROC ap_load_dll_func(ap_dlltoken_e fnLib, char* fnName, int ordinal)
94 if (!lateDllHandle[fnLib]) {
95 lateDllHandle[fnLib] = LoadLibrary(lateDllName[fnLib]);
96 if (!lateDllHandle[fnLib])
100 return GetProcAddress(lateDllHandle[fnLib], (char *) ordinal);
102 return GetProcAddress(lateDllHandle[fnLib], fnName);
106 /* To share the semaphores with other processes, we need a NULL ACL
107 * Code from MS KB Q106387
109 PSECURITY_ATTRIBUTES GetNullACL(void)
111 PSECURITY_DESCRIPTOR pSD;
112 PSECURITY_ATTRIBUTES sa;
114 sa = (PSECURITY_ATTRIBUTES) LocalAlloc(LPTR, sizeof(SECURITY_ATTRIBUTES));
115 sa->nLength = sizeof(SECURITY_ATTRIBUTES);
117 pSD = (PSECURITY_DESCRIPTOR) LocalAlloc(LPTR, SECURITY_DESCRIPTOR_MIN_LENGTH);
118 sa->lpSecurityDescriptor = pSD;
120 if (pSD == NULL || sa == NULL) {
124 if (!InitializeSecurityDescriptor(pSD, SECURITY_DESCRIPTOR_REVISION)
125 || apr_get_os_error()) {
130 if (!SetSecurityDescriptorDacl(pSD, TRUE, (PACL) NULL, FALSE)
131 || apr_get_os_error()) {
137 sa->bInheritHandle = FALSE;
142 void CleanNullACL(void *sa)
145 LocalFree(((PSECURITY_ATTRIBUTES)sa)->lpSecurityDescriptor);