RE: Re: svn commit: r1611169 - in /httpd/httpd/trunk: CHANGES server/mpm/winnt/service.c
- Original Message - Subject: Re: svn commit: r1611169 - in /httpd/httpd/trunk: CHANGES server/mpm/winnt/service.c From: Mike Rumph mike.ru...@oracle.com Date: 1/14/15 12:24 pm To: dev@httpd.apache.org Hello Bill, Sorry to respond to this so late, but I see that this is up for a vote against httpd 2.4. We love any code review, early, late, post-release, whatever! Thanks for looking... I noticed a possible problem in the code. I have a question inserted below. + SC_HANDLE schService; + +#if APR_HAS_UNICODE_FS + IF_WIN_OS_IS_UNICODE + { + schService = OpenServiceW(schSCManager, + (LPCWSTR)mpm_service_name_w, + SERVICE_CHANGE_CONFIG); + } +#endif /* APR_HAS_UNICODE_FS */ +#if APR_HAS_ANSI_FS + ELSE_WIN_OS_IS_ANSI + { + schService = OpenService(schSCManager, mpm_service_name, + SERVICE_CHANGE_CONFIG); + } +#endif if (schService) { If neither of these defines are set, then schService appears to be uninitialized. Is this a problem? No, it cannot be an issue, nor are they mutually exclusive. One or both are always defined. I trust you didn't trip over this during compilation; good eyes though :) See also os/win32/ap_regkey.c for much more code that follows this pattern. This is the pattern behind all APR (and httpd) portability from win98 API to winNT (Unicode). For example, the internal representation of an apr_dir_t; #if APR_HAS_UNICODE_FS struct { WIN32_FIND_DATAW *entry; } w; #endif #if APR_HAS_ANSI_FS struct { WIN32_FIND_DATAA *entry; } n; #endif We have no members, w, or n, and therefore no directory entries, if one of these defines has not been set. apr_arch_misc.h contains these two macros. The pattern exists because it was possible to use the same binary on either OS. IF_WIN_OS_IS_UNICODE and ELSE_WIN_OS_IS_ANSI handled the dynamic behavior, if only one is set, those macros are a no-op. If both are set, those macros become if-else cases (against the version of Windows in use). With Win9x dead, it is past time to prune these, at least on trunk and apr-2.0. I'm not sure whether users are building the 'ANSI-only' flavor for use on modern Windows OS (as all 8bit chars devolve to the OEM code page of the installed version of Windows). So I left well enough alone for now (no harm to users moving from 2.4.10 - 2.4.11), and would plan to follow whatever decisions are made on dev@apr with respect to dropping 8-bit OEM code page logic, altogether, from trunk. Bill
Re: svn commit: r1611169 - in /httpd/httpd/trunk: CHANGES server/mpm/winnt/service.c
Hello Bill, Sorry to respond to this so late, but I see that this is up for a vote against httpd 2.4. I noticed a possible problem in the code. I have a question inserted below. Thanks, Mike Rumph On 7/16/2014 1:15 PM, wr...@apache.org wrote: Author: wrowe Date: Wed Jul 16 20:15:49 2014 New Revision: 1611169 URL: http://svn.apache.org/r1611169 Log: mpm_winnt: Accept utf-8 (Unicode) service names and descriptions for internationalization. Modified: httpd/httpd/trunk/CHANGES httpd/httpd/trunk/server/mpm/winnt/service.c Modified: httpd/httpd/trunk/CHANGES URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/CHANGES?rev=1611169r1=1611168r2=1611169view=diff == --- httpd/httpd/trunk/CHANGES [utf-8] (original) +++ httpd/httpd/trunk/CHANGES [utf-8] Wed Jul 16 20:15:49 2014 @@ -1,6 +1,12 @@ -*- coding: utf-8 -*- Changes with Apache 2.5.0 + *) mpm_winnt: Accept utf-8 (Unicode) service names and descriptions for + internationalization. [William Rowe] + + *) mpm_winnt: Normalize the error and status messages emitted by service.c, + the service control interface for Windows. [William Rowe] + *) SECURITY: CVE-2013-5704 (cve.mitre.org) core: HTTP trailers could be used to replace HTTP headers late during request processing, potentially undoing or Modified: httpd/httpd/trunk/server/mpm/winnt/service.c URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/server/mpm/winnt/service.c?rev=1611169r1=1611168r2=1611169view=diff == --- httpd/httpd/trunk/server/mpm/winnt/service.c (original) +++ httpd/httpd/trunk/server/mpm/winnt/service.c Wed Jul 16 20:15:49 2014 @@ -21,11 +21,18 @@ #define _WINUSER_ +#include apr.h +#include apr_strings.h +#include apr_lib.h +#if APR_HAS_UNICODE_FS +#include arch/win32/apr_arch_utf8.h +#include arch/win32/apr_arch_misc.h +#include wchar.h +#endif + #include httpd.h #include http_log.h #include mpm_winnt.h -#include apr_strings.h -#include apr_lib.h #include ap_regkey.h #ifdef NOUSER @@ -41,6 +48,10 @@ APLOG_USE_MODULE(mpm_winnt); static char *mpm_service_name = NULL; static char *mpm_display_name = NULL; +#if APR_HAS_UNICODE_FS +static apr_wchar_t *mpm_service_name_w; +#endif + typedef struct nt_service_ctx_t { HANDLE mpm_thread; /* primary thread handle of the apache server */ @@ -57,6 +68,32 @@ static nt_service_ctx_t globdat; static int ReportStatusToSCMgr(int currentState, int waitHint, nt_service_ctx_t *ctx); +/* Rather than repeat this logic throughout, create an either-or wide or narrow + * implementation because we don't actually pass strings to OpenSCManager. + * This election is based on build time defines and runtime os version test. + */ +#undef OpenSCManager +typedef SC_HANDLE (WINAPI *fpt_OpenSCManager)(const void *lpMachine, + const void *lpDatabase, + DWORD dwAccess); +static fpt_OpenSCManager pfn_OpenSCManager = NULL; +static APR_INLINE SC_HANDLE OpenSCManager(const void *lpMachine, + const void *lpDatabase, + DWORD dwAccess) +{ +if (!pfn_OpenSCManager) { +#if APR_HAS_UNICODE_FS +IF_WIN_OS_IS_UNICODE +pfn_OpenSCManager = (fpt_OpenSCManager)OpenSCManagerW; +#endif +#if APR_HAS_ANSI_FS +ELSE_WIN_OS_IS_ANSI +pfn_OpenSCManager = (fpt_OpenSCManager)OpenSCManagerA; +#endif +} +return (*(pfn_OpenSCManager))(lpMachine, lpDatabase, dwAccess); +} + /* exit() for Win32 is macro mapped (horrible, we agree) that allows us * to catch the non-zero conditions and inform the console process that * the application died, and hang on to the console a bit longer. @@ -245,16 +282,54 @@ static void set_service_description(void if ((ChangeServiceConfig2) (schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT))) { -SC_HANDLE schService = OpenService(schSCManager, mpm_service_name, - SERVICE_CHANGE_CONFIG); +SC_HANDLE schService; + +#if APR_HAS_UNICODE_FS +IF_WIN_OS_IS_UNICODE +{ +schService = OpenServiceW(schSCManager, + (LPCWSTR)mpm_service_name_w, + SERVICE_CHANGE_CONFIG); +} +#endif /* APR_HAS_UNICODE_FS */ +#if APR_HAS_ANSI_FS +ELSE_WIN_OS_IS_ANSI +{ +schService = OpenService(schSCManager, mpm_service_name, + SERVICE_CHANGE_CONFIG); +} +#endif if (schService) { If neither of these defines are set, then schService appears to be uninitialized. Is
Re: svn commit: r1611169 - in /httpd/httpd/trunk: CHANGES server/mpm/winnt/service.c
On Wed, Jul 16, 2014 at 10:15 PM, wr...@apache.org wrote: Author: wrowe Date: Wed Jul 16 20:15:49 2014 New Revision: 1611169 URL: http://svn.apache.org/r1611169 Log: mpm_winnt: Accept utf-8 (Unicode) service names and descriptions for internationalization. Modified: httpd/httpd/trunk/CHANGES httpd/httpd/trunk/server/mpm/winnt/service.c Modified: httpd/httpd/trunk/CHANGES URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/CHANGES?rev=1611169r1=1611168r2=1611169view=diff == --- httpd/httpd/trunk/server/mpm/winnt/service.c (original) +++ httpd/httpd/trunk/server/mpm/winnt/service.c Wed Jul 16 20:15:49 2014 [...] @@ -354,21 +445,99 @@ static void __stdcall service_nt_main_fn [...] + static DWORD WINAPI service_nt_dispatch_thread(LPVOID nada) + { +#if APR_HAS_UNICODE_FS +SERVICE_TABLE_ENTRYW dispatchTable_w[] = +{ +{ L, service_nt_main_fn_w }, { NULL, NULL } }; - -/* ###: utf-ize */ -if (!StartServiceCtrlDispatcher(dispatchTable)) +#endif /* APR_HAS_UNICODE_FS */ +#if APR_HAS_ANSI_FS +SERVICE_TABLE_ENTRYA dispatchTable[] = { +{ , service_nt_main_fn }, +{ NULL, NULL } +}; +#endif +apr_status_t rv; + +#if APR_HAS_UNICODE_FS +IF_WIN_OS_IS_UNICODE +rv = StartServiceCtrlDispatcherW(dispatchTable_w); +#endif +#if APR_HAS_ANSI_FS +ELSE_WIN_OS_IS_ANSI + rv = StartServiceCtrlDispatcherA(dispatchTable); +#endif +if (rv) { +apr_status_t rv = APR_SUCCESS; +} Shouldn't apr_status_t be removed here (and maybe rv initialized to APR_SUCCESS above)? +else { /* This is a genuine failure of the SCM. */ rv = apr_get_os_error(); ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, rv, NULL, Regards, Yann.
Re: svn commit: r1611169 - in /httpd/httpd/trunk: CHANGES server/mpm/winnt/service.c
On Thu, Jul 17, 2014 at 12:44 AM, Yann Ylavic ylavic@gmail.com wrote: (and maybe rv initialized to APR_SUCCESS above)? I meant APR_ENOTIMPL (or any error).