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"
29 AP_DECLARE(apr_status_t
) ap_os_proc_filepath(char **binpath
, apr_pool_t
*p
)
31 apr_wchar_t wbinpath
[APR_PATH_MAX
];
33 #if APR_HAS_UNICODE_FS
39 if (!GetModuleFileNameW(NULL
, wbinpath
, sizeof(wbinpath
)
40 / sizeof(apr_wchar_t
))) {
41 return apr_get_os_error();
43 wbinlen
= wcslen(wbinpath
) + 1;
44 binlen
= (wbinlen
- 1) * 3 + 1;
45 *binpath
= apr_palloc(p
, binlen
);
46 rv
= apr_conv_ucs2_to_utf8(wbinpath
, &wbinlen
, *binpath
, &binlen
);
47 if (rv
!= APR_SUCCESS
)
50 return APR_ENAMETOOLONG
;
52 #endif /* APR_HAS_UNICODE_FS */
56 /* share the same scratch buffer */
57 char *pathbuf
= (char*) wbinpath
;
58 if (!GetModuleFileName(NULL
, pathbuf
, sizeof(wbinpath
))) {
59 return apr_get_os_error();
61 *binpath
= apr_pstrdup(p
, pathbuf
);
68 AP_DECLARE(apr_status_t
) ap_os_create_privileged_process(
70 apr_proc_t
*newproc
, const char *progname
,
71 const char * const *args
,
72 const char * const *env
,
73 apr_procattr_t
*attr
, apr_pool_t
*p
)
75 return apr_proc_create(newproc
, progname
, args
, env
, attr
, p
);
79 /* This code is stolen from misc/win32/misc.c and apr_private.h
80 * This helper code resolves late bound entry points
81 * missing from one or more releases of the Win32 API...
82 * but it sure would be nice if we didn't duplicate this code
85 static const char* const lateDllName
[DLL_defined
] = {
86 "kernel32", "advapi32", "mswsock", "ws2_32" };
87 static HMODULE lateDllHandle
[DLL_defined
] = {
88 NULL
, NULL
, NULL
, NULL
};
91 FARPROC
ap_load_dll_func(ap_dlltoken_e fnLib
, char* fnName
, int ordinal
)
93 if (!lateDllHandle
[fnLib
]) {
94 lateDllHandle
[fnLib
] = LoadLibrary(lateDllName
[fnLib
]);
95 if (!lateDllHandle
[fnLib
])
99 return GetProcAddress(lateDllHandle
[fnLib
], (char *) ordinal
);
101 return GetProcAddress(lateDllHandle
[fnLib
], fnName
);
105 /* To share the semaphores with other processes, we need a NULL ACL
106 * Code from MS KB Q106387
108 PSECURITY_ATTRIBUTES
GetNullACL()
110 PSECURITY_DESCRIPTOR pSD
;
111 PSECURITY_ATTRIBUTES sa
;
113 sa
= (PSECURITY_ATTRIBUTES
) LocalAlloc(LPTR
, sizeof(SECURITY_ATTRIBUTES
));
114 sa
->nLength
= sizeof(sizeof(SECURITY_ATTRIBUTES
));
116 pSD
= (PSECURITY_DESCRIPTOR
) LocalAlloc(LPTR
, SECURITY_DESCRIPTOR_MIN_LENGTH
);
117 sa
->lpSecurityDescriptor
= pSD
;
119 if (pSD
== NULL
|| sa
== NULL
) {
123 if (!InitializeSecurityDescriptor(pSD
, SECURITY_DESCRIPTOR_REVISION
)
124 || apr_get_os_error()) {
129 if (!SetSecurityDescriptorDacl(pSD
, TRUE
, (PACL
) NULL
, FALSE
)
130 || apr_get_os_error()) {
136 sa
->bInheritHandle
= FALSE
;
141 void CleanNullACL(void *sa
)
144 LocalFree(((PSECURITY_ATTRIBUTES
)sa
)->lpSecurityDescriptor
);