You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by st...@locus.apache.org on 2000/04/15 19:48:17 UTC

cvs commit: apache-2.0/src/os/win32 registry.c registry.h service.c service.h

stoddard    00/04/15 10:48:17

  Modified:    src      CHANGES
               src/lib/apr aprlib.def
               src/lib/apr/include apr_lib.h
               src/lib/apr/lib apr_cpystrn.c
               src/os/win32 registry.c registry.h service.c service.h
  Log:
  Win32:
  1. Move the space stripping of physical service names
  fix up from Apache 1.3.
  2. #include'ing "ap_mpm.h" fixes up an unresolved symbol.
  3. Add dependency checking to the CreateService call to ensure TCPIP and
  AFP (winsock) is started before Apache.
  
  Submitted by:	William Rowe
  Reviewed by:	Bill Stoddard
  
  Revision  Changes    Path
  1.65      +7 -0      apache-2.0/src/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/CHANGES,v
  retrieving revision 1.64
  retrieving revision 1.65
  diff -u -r1.64 -r1.65
  --- CHANGES	2000/04/13 14:59:46	1.64
  +++ CHANGES	2000/04/15 17:48:15	1.65
  @@ -1,4 +1,11 @@
   Changes with Apache 2.0a3-dev
  +  *) Win32: Move the space stripping of physical service names
  +     fix up from Apache 1.3. #include'ing "ap_mpm.h" fixes up an
  +     unresolved symbol. Add dependency checking to the
  +     CreateService call to ensure TCPIP and AFP (winsock) is started
  +     before Apache.
  +     [William Rowe <wr...@lnd.com>]
  +
     *) Win32: Add code to perform latebinding on functions that may
        not exist on all levels of Windows where Apache runs. This
        is needed to allow Apache to start-up on Win95/98. All calls
  
  
  
  1.20      +1 -0      apache-2.0/src/lib/apr/aprlib.def
  
  Index: aprlib.def
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/aprlib.def,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- aprlib.def	2000/04/14 16:50:24	1.19
  +++ aprlib.def	2000/04/15 17:48:15	1.20
  @@ -241,3 +241,4 @@
           ap_dso_unload @220
           ap_dso_sym @221
           ap_dso_init @222
  +        ap_collapse_spaces @223
  \ No newline at end of file
  
  
  
  1.26      +2 -0      apache-2.0/src/lib/apr/include/apr_lib.h
  
  Index: apr_lib.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/include/apr_lib.h,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- apr_lib.h	2000/04/14 15:58:25	1.25
  +++ apr_lib.h	2000/04/15 17:48:16	1.26
  @@ -130,6 +130,8 @@
   API_EXPORT(int) ap_tokenize_to_argv(ap_pool_t *token_context,
                                       char *arg_str, char ***argv_out);
   API_EXPORT(const char *) ap_filename_of_pathname(const char *pathname);
  +API_EXPORT(char *) ap_collapse_spaces(char *dest, const char *src);
  +
   /*API_EXPORT(ap_mutex_t *) ap_create_mutex(void *m);*/
   API_EXPORT(int) ap_slack(int l, int h);
   API_EXPORT_NONSTD(ap_status_t) ap_execle(const char *c, const char *a, ...);
  
  
  
  1.14      +26 -4     apache-2.0/src/lib/apr/lib/apr_cpystrn.c
  
  Index: apr_cpystrn.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/lib/apr/lib/apr_cpystrn.c,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -r1.13 -r1.14
  --- apr_cpystrn.c	2000/04/14 15:58:28	1.13
  +++ apr_cpystrn.c	2000/04/15 17:48:16	1.14
  @@ -200,17 +200,39 @@
    *   "/foo/bar/gum/" -> ""
    *   "gum" -> "gum"
    *   "wi\\n32\\stuff" -> "stuff
  + *
  + * Corrected Win32 to accept "a/b\\stuff", "a:stuff"
    */
   
   const char *ap_filename_of_pathname(const char *pathname)
   {
  -#ifdef WIN32
  -    const char path_separator = '\\';
  -#else
       const char path_separator = '/';
  -#endif
       const char *s = strrchr(pathname, path_separator);
   
  +#ifdef WIN32
  +    const char path_separator_win = '\\';
  +    const char drive_separator_win = ':';
  +    const char *s2 = strrchr(pathname, path_separator_win);
  +
  +    if (s2 > s) s = s2;
  +
  +    if (!s) s = strrchr(pathname, drive_separator_win);
  +#endif
  +
       return s ? ++s : pathname;
   }
   
  +/* length of dest assumed >= length of src
  + * collapse in place (src == dest) is legal.
  + * returns terminating null ptr to dest string.
  + */
  +API_EXPORT(char *) ap_collapse_spaces(char *dest, const char *src)
  +{
  +    while (*src) {
  +        if (!ap_isspace(*src)) 
  +            *dest++ = *src;
  +        ++src;
  +    }
  +    *dest = 0;
  +    return (dest);
  +}
  
  
  
  1.15      +13 -11    apache-2.0/src/os/win32/registry.c
  
  Index: registry.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/os/win32/registry.c,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- registry.c	2000/04/15 01:16:44	1.14
  +++ registry.c	2000/04/15 17:48:16	1.15
  @@ -280,21 +280,23 @@
       return (rv < -1) ? -1 : 0;
   }
   #endif
  -char *ap_get_service_key(char *service_name)
  +char *ap_get_service_key(char *display_name)
   {
  -    char *key = malloc(strlen(SERVICEKEYPRE) +
  -                       strlen(service_name) +
  -                       strlen(SERVICEKEYPOST) + 1);
  -
  -    sprintf(key,"%s%s%s", SERVICEKEYPRE, service_name, SERVICEKEYPOST);
  -
  +    size_t keylen = strlen(display_name);
  +    char *key2, *key = malloc(sizeof(SERVICEKEYPRE) + keylen
  +                            + sizeof(SERVICEKEYPOST) + 1);
  +
  +    key2 = ap_cpystrn(key, SERVICEKEYPRE, sizeof(SERVICEKEYPRE) + 1);
  +    key2 = ap_collapse_spaces(key2, display_name);
  +    key2 = ap_cpystrn(key2, SERVICEKEYPOST, sizeof(SERVICEKEYPOST) + 1);
  +    
       return(key);
   }
   #if 0
  -int ap_registry_get_service_conf(ap_pool_t *p, char *dir, int size, char *service_name)
  +int ap_registry_get_service_conf(ap_pool_t *p, char *dir, int size, char *display_name)
   {
       int rv;
  -    char *key = ap_get_service_key(service_name);
  +    char *key = ap_get_service_key(display_name);
   
       rv = ap_registry_get_key_int(p, key, "ConfPath", dir, size, NULL);
       if (rv < 0) {
  @@ -527,10 +529,10 @@
    * logged via aplog_error().
    */
   
  -int ap_registry_set_service_conf(char *conf, char *service_name)
  +int ap_registry_set_service_conf(char *conf, char *display_name)
   {
       int rv;
  -    char *key = ap_get_service_key(service_name);
  +    char *key = ap_get_service_key(display_name);
       
       rv = ap_registry_store_key_int(key, "ConfPath", REG_SZ, conf, strlen(conf)+1);
       free(key);
  
  
  
  1.7       +2 -2      apache-2.0/src/os/win32/registry.h
  
  Index: registry.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/os/win32/registry.h,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- registry.h	2000/04/14 15:59:18	1.6
  +++ registry.h	2000/04/15 17:48:16	1.7
  @@ -62,5 +62,5 @@
   
   extern int ap_registry_get_server_root(ap_pool_t *p, char **buf);
   extern int ap_registry_set_server_root(char *dir);
  -extern int ap_registry_get_service_conf(ap_pool_t *p, char **buf, char *service_name);
  -extern int ap_registry_set_service_conf(char *dir, char *service_name);
  +extern int ap_registry_get_service_conf(ap_pool_t *p, char **buf, char *display_name);
  +extern int ap_registry_set_service_conf(char *dir, char *display_name);
  
  
  
  1.7       +41 -16    apache-2.0/src/os/win32/service.c
  
  Index: service.c
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/os/win32/service.c,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- service.c	2000/04/14 15:59:18	1.6
  +++ service.c	2000/04/15 17:48:16	1.7
  @@ -69,6 +69,7 @@
   #include "http_main.h"
   #include "service.h"
   #include "registry.h"
  +#include "ap_mpm.h"
   
   static struct
   {
  @@ -278,15 +279,16 @@
       return(1);
   }
   
  -void InstallService(char *service_name, char *conf)
  +void InstallService(char *display_name, char *conf)
   {
       SC_HANDLE   schService;
       SC_HANDLE   schSCManager;
   
       TCHAR szPath[512];
       TCHAR szQuotedPath[512];
  +    char service_name[256];
   
  -    printf("Installing the %s service to use %s\n", service_name, conf);
  +    printf("Installing the %s service to use %s\n", display_name, conf);
   
       if (GetModuleFileName( NULL, szPath, 512 ) == 0)
       {
  @@ -295,6 +297,9 @@
           return;
       }
   
  +    /* Remove spaces from display name to create service name */
  +    ap_collapse_spaces(service_name, display_name);
  +
       ap_snprintf(szQuotedPath, 512, "\"%s\"", szPath);
   
       schSCManager = OpenSCManager(
  @@ -307,18 +312,26 @@
                       "OpenSCManager failed");
       }
       else {
  +    /* Added dependencies for the following: TCPIP, AFD
  +     * AFD is the winsock handler, TCPIP is self evident
  +     *
  +     * RPCSS is the Remote Procedure Call (RPC) Locator
  +     * required for DCOM communication.  I am far from
  +     * convinced we should toggle this, but be warned that
  +     * future apache modules or ISAPI dll's may depend on it.
  +     */
           schService = CreateService(
               schSCManager,               // SCManager database
               service_name,               // name of service
  -            service_name,               // name to display
  +            display_name,               // name to display
               SERVICE_ALL_ACCESS,         // desired access
               SERVICE_WIN32_OWN_PROCESS,  // service type
  -            SERVICE_AUTO_START,       // start type
  +            SERVICE_AUTO_START,         // start type
               SERVICE_ERROR_NORMAL,       // error control type
               szQuotedPath,               // service's binary
               NULL,                       // no load ordering group
               NULL,                       // no tag identifier
  -            NULL,       // dependencies
  +            "Tcpip\0Afd\0",             // dependencies
               NULL,                       // LocalSystem account
               NULL);                      // no password
   
  @@ -327,7 +340,7 @@
   
               /* Now store the server_root in the registry */
               if(!ap_registry_set_service_conf(conf, service_name))
  -                printf("The %s service has been installed successfully.\n", service_name );
  +                printf("The %s service has been installed successfully.\n", display_name);
           }
           else {
               ap_log_error(APLOG_MARK, APLOG_ERR, GetLastError(), NULL, 
  @@ -339,12 +352,16 @@
   }
   
   
  -void RemoveService(char *service_name)
  +void RemoveService(char *display_name)
   {
       SC_HANDLE   schService;
       SC_HANDLE   schSCManager;
  +    char service_name[256];
  +
  +    printf("Removing the %s service\n", display_name);
   
  -    printf("Removing the %s service\n", service_name);
  +    /* Remove spaces from display name to create service name */
  +    ap_collapse_spaces(service_name, display_name);
   
       schSCManager = OpenSCManager(
                           NULL,                   // machine (NULL == local)
  @@ -372,7 +389,7 @@
   		ap_log_error(APLOG_MARK, APLOG_ERR, GetLastError(), NULL,
                                "DeleteService failed");
               else
  -                printf("The %s service has been removed successfully.\n", service_name );
  +                printf("The %s service has been removed successfully.\n", display_name);
               CloseServiceHandle(schService);
           }
           /* SCM removes registry parameters  */
  @@ -395,10 +412,14 @@
   /* Determine is service_name is a valid service
    */
   
  -BOOL isValidService(char *service_name) {
  +BOOL isValidService(char *display_name) {
       SC_HANDLE schSCM, schSVC;
  +    char service_name[256];
       int Err;
   
  +    /* Remove spaces from display name to create service name */
  +    ap_collapse_spaces(service_name, display_name);
  +
       if (!(schSCM = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS))) {
           ap_log_error(APLOG_MARK, APLOG_ERR, GetLastError(), NULL,
                        "OpenSCManager failed");
  @@ -419,9 +440,10 @@
       return FALSE;
   }
   
  -int send_signal_to_service(char *service_name, char *sig) {
  +int send_signal_to_service(char *display_name, char *sig) {
       SC_HANDLE   schService;
       SC_HANDLE   schSCManager;
  +    char service_name[256];
       int success = FALSE;
   
       enum                        { start,      restart,      stop, unknown } action;
  @@ -438,6 +460,9 @@
           return FALSE;
       }
   
  +    /* Remove spaces from display name to create service name */
  +    ap_collapse_spaces(service_name, display_name);
  +
       schSCManager = OpenSCManager(
                           NULL,                   // machine (NULL == local)
                           NULL,                   // database (NULL == default)
  @@ -461,11 +486,11 @@
                                "QueryService failed");
               else {
                   if (globdat.ssStatus.dwCurrentState == SERVICE_STOPPED && action == stop)
  -                    printf("The %s service is not started.\n", service_name);
  +                    printf("The %s service is not started.\n", display_name);
                   else if (globdat.ssStatus.dwCurrentState == SERVICE_RUNNING && action == start)
  -                    printf("The %s service has already been started.\n", service_name);
  +                    printf("The %s service has already been started.\n", display_name);
                   else {
  -                    printf("The %s service is %s.\n", service_name, participle[action]);
  +                    printf("The %s service is %s.\n", display_name, participle[action]);
   
                       if (action == stop || action == restart)
                           success = ap_stop_service(schService);
  @@ -473,9 +498,9 @@
                           success = ap_start_service(schService);
                   
                       if( success )
  -                        printf("The %s service has %s.\n", service_name, past[action]);
  +                        printf("The %s service has %s.\n", display_name, past[action]);
                       else
  -                        printf("Failed to %s the %s service.\n", sig, service_name );
  +                        printf("Failed to %s the %s service.\n", sig, display_name);
                   }
   
                   CloseServiceHandle(schService);
  
  
  
  1.3       +4 -4      apache-2.0/src/os/win32/service.h
  
  Index: service.h
  ===================================================================
  RCS file: /home/cvs/apache-2.0/src/os/win32/service.h,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- service.h	2000/03/31 09:17:18	1.2
  +++ service.h	2000/04/15 17:48:16	1.3
  @@ -64,11 +64,11 @@
   void service_set_status(int status);
   void service_cd();
   BOOL isProcessService();
  -BOOL isValidService(char *service_name);
  -void InstallService(char *service_name, char *conf);
  -void RemoveService(char *service_name);
  +BOOL isValidService(char *display_name);
  +void InstallService(char *display_name, char *conf);
  +void RemoveService(char *display_name);
   int service_init();
  -int send_signal_to_service(char *service_name, char *sig);
  +int send_signal_to_service(char *display_name, char *sig);
   #endif /* WIN32 */
   
   #endif /* SERVICE_H */