From: William A. Rowe Jr Date: Tue, 2 Jul 2002 19:03:15 +0000 (+0000) Subject: A bit more ap_regkey and apr-ization. Fixes some new bugs where the X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8d4f6c5bb63bde519edfe29d0ebf5009adf16ab5;p=apache A bit more ap_regkey and apr-ization. Fixes some new bugs where the AP_REGKEY_CREATE flag wasn't passed for ap_regkey_open (when the key is expected to not yet exist), and adds the new flags arg to value_set. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@95937 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/server/mpm/winnt/mpm_winnt.c b/server/mpm/winnt/mpm_winnt.c index 5af17f45e4..11a48f4eb5 100644 --- a/server/mpm/winnt/mpm_winnt.c +++ b/server/mpm/winnt/mpm_winnt.c @@ -2157,7 +2157,7 @@ void winnt_rewrite_args(process_rec *process) * without a drive letter. Change to the default root * (path to apache root, above /bin) for safety. */ - SetCurrentDirectory(def_server_root); + apr_filepath_set(def_server_root, process->pool); /* Any other process has a console, so we don't to begin * a Win9x service until the configuration is parsed and diff --git a/server/mpm/winnt/nt_eventlog.c b/server/mpm/winnt/nt_eventlog.c index 24e146109f..65122a95bf 100644 --- a/server/mpm/winnt/nt_eventlog.c +++ b/server/mpm/winnt/nt_eventlog.c @@ -63,6 +63,7 @@ #include "mpm_winnt.h" #include "apr_strings.h" #include "apr_lib.h" +#include "ap_regkey.h" static char *display_name = NULL; static HANDLE stderr_thread = NULL; @@ -76,8 +77,12 @@ static DWORD WINAPI service_stderr_thread(LPVOID hPipe) char *errmsg = errbuf; const char *errarg[9]; DWORD errres; - HKEY hk; + ap_regkey_t *regkey; + apr_status_t rv; + apr_pool_t *p; + apr_pool_sub_make(&p, NULL, NULL); + errarg[0] = "The Apache service named"; errarg[1] = display_name; errarg[2] = "reported the following error:\r\n>>>"; @@ -89,23 +94,26 @@ static DWORD WINAPI service_stderr_thread(LPVOID hPipe) errarg[8] = NULL; /* What are we going to do in here, bail on the user? not. */ - if (!RegCreateKey(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services" - "\\EventLog\\Application\\Apache Service", &hk)) + if ((rv = ap_regkey_open(®key, AP_REGKEY_LOCAL_MACHINE, + "SYSTEM\\CurrentControlSet\\Services\\" + "EventLog\\Application\\Apache Service", + APR_READ | APR_WRITE | APR_CREATE, p)) + == APR_SUCCESS) { - /* The stock message file */ - char *netmsgkey = "%SystemRoot%\\System32\\netmsg.dll"; DWORD dwData = EVENTLOG_ERROR_TYPE | EVENTLOG_WARNING_TYPE | EVENTLOG_INFORMATION_TYPE; - RegSetValueEx(hk, "EventMessageFile", 0, REG_EXPAND_SZ, - (LPBYTE) netmsgkey, strlen(netmsgkey) + 1); + /* The stock message file */ + ap_regkey_value_set(regkey, "EventMessageFile", + "%SystemRoot%\\System32\\netmsg.dll", + AP_REGKEY_EXPAND, p); - RegSetValueEx(hk, "TypesSupported", 0, REG_DWORD, - (LPBYTE) &dwData, sizeof(dwData)); - RegCloseKey(hk); + ap_regkey_value_raw_set(regkey, "TypesSupported", &dwData, + sizeof(dwData), REG_DWORD, p); + ap_regkey_close(regkey); } - hEventSource = RegisterEventSource(NULL, "Apache Service"); + hEventSource = RegisterEventSourceW(NULL, L"Apache Service"); SetEvent(stderr_ready); @@ -145,6 +153,7 @@ static DWORD WINAPI service_stderr_thread(LPVOID hPipe) DeregisterEventSource(hEventSource); CloseHandle(stderr_thread); stderr_thread = NULL; + apr_pool_destroy(p); return 0; } diff --git a/server/mpm/winnt/service.c b/server/mpm/winnt/service.c index 01ec697b16..b0de8fc50c 100644 --- a/server/mpm/winnt/service.c +++ b/server/mpm/winnt/service.c @@ -513,12 +513,12 @@ static void set_service_description(void) "SYSTEM\\CurrentControlSet\\Services\\%s", mpm_service_name); rv = ap_regkey_open(&svckey, AP_REGKEY_LOCAL_MACHINE, szPath, - APR_WRITE, pconf); + APR_READ | APR_WRITE, pconf); if (rv != APR_SUCCESS) { return; } /* Attempt to set the Description value for our service */ - ap_regkey_value_set(svckey, "Description", full_description, pconf); + ap_regkey_value_set(svckey, "Description", full_description, 0, pconf); ap_regkey_close(svckey); } } @@ -933,9 +933,10 @@ apr_status_t mpm_service_install(apr_pool_t *ptemp, int argc, launch_cmd = apr_psprintf(ptemp, "\"%s\" -n %s -k runservice", exe_path, mpm_service_name); rv = ap_regkey_open(&key, AP_REGKEY_LOCAL_MACHINE, SERVICECONFIG9X, - APR_READ, pconf); + APR_READ | APR_WRITE | APR_CREATE, pconf); if (rv == APR_SUCCESS) { - rv = ap_regkey_value_set(key, mpm_service_name, launch_cmd, pconf); + rv = ap_regkey_value_set(key, mpm_service_name, + launch_cmd, 0, pconf); ap_regkey_close(key); } if (rv != APR_SUCCESS) { @@ -947,14 +948,14 @@ apr_status_t mpm_service_install(apr_pool_t *ptemp, int argc, apr_snprintf(key_name, sizeof(key_name), SERVICECONFIG, mpm_service_name); rv = ap_regkey_open(&key, AP_REGKEY_LOCAL_MACHINE, key_name, - APR_READ, pconf); + APR_READ | APR_WRITE | APR_CREATE, pconf); if (rv != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, rv, NULL, "%s: Failed to create the registry service key.", mpm_display_name); return (rv); } - rv = ap_regkey_value_set(key, "ImagePath", launch_cmd, pconf); + rv = ap_regkey_value_set(key, "ImagePath", launch_cmd, 0, pconf); if (rv != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, rv, NULL, "%s: Failed to store ImagePath in the registry.", @@ -962,7 +963,8 @@ apr_status_t mpm_service_install(apr_pool_t *ptemp, int argc, ap_regkey_close(key); return (rv); } - rv = ap_regkey_value_set(key, "DisplayName", mpm_display_name, pconf); + rv = ap_regkey_value_set(key, "DisplayName", + mpm_display_name, 0, pconf); ap_regkey_close(key); if (rv != APR_SUCCESS) { ap_log_error(APLOG_MARK, APLOG_ERR | APLOG_STARTUP, rv, NULL, @@ -978,7 +980,7 @@ apr_status_t mpm_service_install(apr_pool_t *ptemp, int argc, */ apr_snprintf(key_name, sizeof(key_name), SERVICEPARAMS, mpm_service_name); rv = ap_regkey_open(&key, AP_REGKEY_LOCAL_MACHINE, key_name, - APR_READ, pconf); + APR_READ | APR_WRITE | APR_CREATE, pconf); if (rv == APR_SUCCESS) { rv = ap_regkey_value_array_set(key, "ConfigArgs", argc, argv, pconf); ap_regkey_close(key); @@ -1055,7 +1057,7 @@ apr_status_t mpm_service_uninstall(void) /* TODO: assure the service is stopped before continuing */ rv = ap_regkey_open(&key, AP_REGKEY_LOCAL_MACHINE, SERVICECONFIG9X, - APR_WRITE, pconf); + APR_READ | APR_WRITE | APR_CREATE, pconf); if (rv == APR_SUCCESS) { rv = ap_regkey_value_remove(key, mpm_service_name, pconf); ap_regkey_close(key);