httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wr...@apache.org
Subject cvs commit: apache-1.3/src/main http_main.c
Date Wed, 03 Oct 2001 20:56:01 GMT
wrowe       01/10/03 13:56:01

  Modified:    src      CHANGES
               src/os/win32 service.c service.h registry.c
               src/main http_main.c
  Log:
    Accept service names modified by the user in the Win/2000 Service Control
    Panel applet.  Allow the admin to specify -W dependency, where the given
    service will become a dependency for Apache when configured with the
    -k install and config options.  Finally, document -w and -W.
  
  Revision  Changes    Path
  1.1720    +8 -0      apache-1.3/src/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apache-1.3/src/CHANGES,v
  retrieving revision 1.1719
  retrieving revision 1.1720
  diff -u -r1.1719 -r1.1720
  --- CHANGES	2001/10/02 21:54:32	1.1719
  +++ CHANGES	2001/10/03 20:56:00	1.1720
  @@ -1,5 +1,13 @@
   Changes with Apache 1.3.21
   
  +  *) Handle user modification of WinNT/2K service display names.  Prior
  +     versions of Apache only accepted identical internal and display names
  +     (where internal service names were space-stripped.)  [William Rowe]
  +
  +  *) Introduce Win32 -W option for -k install/config to set up service
  +     dependencies on the workstation, snmp and other services that given
  +     modules or configurations might depend upon.  [William Rowe]
  +
     *) Update the mime.types file to map video/vnd.mpegurl to mxu
        and add commonly used audio/x-mpegurl for m3u extensions.
        [Heiko Recktenwald <uzs106@uni-bonn.de>, Lars Eilebrecht]
  
  
  
  1.55      +104 -32   apache-1.3/src/os/win32/service.c
  
  Index: service.c
  ===================================================================
  RCS file: /home/cvs/apache-1.3/src/os/win32/service.c,v
  retrieving revision 1.54
  retrieving revision 1.55
  diff -u -r1.54 -r1.55
  --- service.c	2001/09/24 21:44:48	1.54
  +++ service.c	2001/10/03 20:56:00	1.55
  @@ -668,7 +668,6 @@
       globdat.exit_status = globdat.main_fn( argc, argv );
   }
   
  -
   /* Set the service description regardless of platform.
    * We revert to set_service_description_string on NT/9x, the
    * very long way so any Apache management program can grab the
  @@ -696,6 +695,55 @@
   }
   
   
  +char *get_service_name(char *display_name)
  +{
  +    /* Get the service's true name from the SCM on NT/2000, since it
  +     * can be changed by the user on 2000, especially, from the
  +     * service control panel.  We can't trust the service name to 
  +     * match a space-collapsed display name.
  +     */
  +    char service_name[MAX_PATH];
  +    if (isWindowsNT())
  +    {
  +        SC_HANDLE scm = OpenSCManager(NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE);
  +        DWORD namelen = sizeof(service_name);
  +        if (scm) {
  +            BOOL ok = GetServiceKeyName(scm, display_name, service_name, 
  +                                        &namelen);
  +            CloseServiceHandle(scm);
  +            if (ok)
  +                return strdup(service_name);
  +        }
  +    }
  +    ap_remove_spaces(service_name, display_name);
  +    return strdup(service_name);
  +}
  +
  +
  +char *get_display_name(char *service_name)
  +{
  +    /* Get the service's display name from the SCM on NT/2000, since it
  +     * can be changed by the user on 2000, especially, from the
  +     * service control panel.  We can't trust the service name as
  +     * provided by the user.
  +     */
  +    if (isWindowsNT())
  +    {
  +        char display_name[MAX_PATH];
  +        SC_HANDLE scm = OpenSCManager(NULL, NULL, SC_MANAGER_ENUMERATE_SERVICE);
  +        DWORD namelen = sizeof(display_name);
  +        if (scm) {
  +            BOOL ok = GetServiceDisplayName(scm, service_name, display_name,
  +                                            &namelen);
  +            CloseServiceHandle(scm);
  +            if (ok)
  +                return strdup(display_name);
  +        }
  +    }
  +    return service_name;
  +}
  +
  +
   /* ChangeServiceConfig2() prototype:
    */
   typedef WINADVAPI BOOL (WINAPI *CSD_T)(SC_HANDLE, DWORD, LPCVOID);
  @@ -854,7 +902,11 @@
       TCHAR szQuotedPath[512];
       char *service_name;
       int regargc = 0;
  -    char **regargv = malloc((argc + 4) * sizeof(char*)), **newelem = regargv;
  +    char default_depends[] = "Tcpip\0Afd\0";
  +    char *depends = default_depends;
  +    size_t depends_len = sizeof(default_depends);
  +    char **regargv = malloc((argc + 4) * sizeof(char*));
  +    char **newelem = regargv;
   
       regargc += 4;
       *(newelem++) = "-d";
  @@ -865,10 +917,28 @@
       while (++argv, --argc) {
           if ((**argv == '-') && strchr("kndf", argv[0][1]))
               --argc, ++argv; /* Skip already handled -k -n -d -f options */
  +        else if ((**argv == '-') && (argv[0][1] == 'W')) 
  +        {
  +            /* Catch this service -W dependency 
  +             * the depends list is null seperated, double-null terminated
  +             */
  +            char *service = get_service_name(*(argv + 1));
  +            size_t add_len = strlen(service) + 1;
  +            char *more_depends = malloc(depends_len + add_len);
  +            memcpy (more_depends, depends, depends_len - 1);
  +            memcpy (more_depends + depends_len - 1, service, add_len);
  +            depends_len += add_len;
  +            depends = more_depends;
  +            depends[depends_len - 1] = '\0';
  +            ++argv, --argc;
  +        }
           else if ((**argv != '-') || !strchr("iuw", argv[0][1]))
               *(newelem++) = *argv, ++regargc;  /* Ignoring -i -u -w options */
       }
   
  +    /* Remove spaces from display name to create service name */
  +    service_name = get_service_name(display_name);
  +    
       printf(reconfig ? "Reconfiguring the %s service\n"
                       : "Installing the %s service\n", 
              display_name);
  @@ -880,10 +950,6 @@
           return;
       }
   
  -    /* Remove spaces from display name to create service name */
  -    service_name = strdup(display_name);
  -    ap_remove_spaces(service_name, display_name);
  -
       if (isWindowsNT())
       {
           SC_HANDLE schService;
  @@ -909,6 +975,12 @@
            * 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.
  +         * Also UNC share users may need the networking service 
  +         * started (usually "LanmanWorkstation").  "ProtectedStorage" 
  +         * may be needed depending on how files and registry keys are 
  +         * stored.  And W3SVC may be needed to wait until IIS has
  +         * glommed and released 0.0.0.0:80 if the admin allocates 
  +         * two different IP's to Apache and IIS on the same port.
            */
           if (reconfig) 
           {
  @@ -925,7 +997,7 @@
                           szQuotedPath,               // service's binary
                           NULL,                       // no load ordering group
                           NULL,                       // no tag identifier
  -                        "Tcpip\0Afd\0",             // dependencies
  +                        depends,                    // dependencies
                           NULL,                       // user account
                           NULL,                       // account password
                           display_name)) {            // service display name
  @@ -949,7 +1021,7 @@
                           szQuotedPath,               // service's binary
                           NULL,                       // no load ordering group
                           NULL,                       // no tag identifier
  -                        "Tcpip\0Afd\0",             // dependencies
  +                        depends,                    // dependencies
                           NULL,                       // user account
                           NULL);                      // account password
               if (!schService)
  @@ -1056,9 +1128,8 @@
       printf("Removing the %s service\n", display_name);
   
       /* Remove spaces from display name to create service name */
  -    service_name = strdup(display_name);
  -    ap_remove_spaces(service_name, display_name);
  -
  +    service_name = get_service_name(display_name);
  +    
       if (isWindowsNT())
       {
           SC_HANDLE   schService;
  @@ -1172,6 +1243,25 @@
                  display_name);
   }
   
  +
  +BOOL isWindowsNT(void)
  +{
  +    static BOOL once = FALSE;
  +    static BOOL isNT = FALSE;
  +    
  +    if (!once)
  +    {
  +        OSVERSIONINFO osver;
  +        osver.dwOSVersionInfoSize = sizeof(osver);
  +        if (GetVersionEx(&osver))
  +            if (osver.dwPlatformId == VER_PLATFORM_WIN32_NT)
  +                isNT = TRUE;
  +        once = TRUE;
  +    }
  +    return isNT;
  +}
  +
  +
   /*
    * A hack to determine if we're running as a service without waiting for
    * the SCM to fail.
  @@ -1202,8 +1292,8 @@
       
       /* Remove spaces from display name to create service name */
       strcpy(service_key, "System\\CurrentControlSet\\Services\\");
  -    service_name = strchr(service_key, '\0');
  -    ap_remove_spaces(service_name, display_name);
  +    service_name = get_service_name(display_name);
  +    strcat(service_key, service_name);
   
       if (RegOpenKey(HKEY_LOCAL_MACHINE, service_key, &hkey) != ERROR_SUCCESS) {
           return FALSE;
  @@ -1212,22 +1302,6 @@
       return TRUE;
   }
   
  -BOOL isWindowsNT(void)
  -{
  -    static BOOL once = FALSE;
  -    static BOOL isNT = FALSE;
  -    
  -    if (!once)
  -    {
  -        OSVERSIONINFO osver;
  -        osver.dwOSVersionInfoSize = sizeof(osver);
  -        if (GetVersionEx(&osver))
  -            if (osver.dwPlatformId == VER_PLATFORM_WIN32_NT)
  -                isNT = TRUE;
  -        once = TRUE;
  -    }
  -    return isNT;
  -}
   
   int send_signal_to_service(char *display_name, char *sig, 
                              int argc, char **argv)
  @@ -1253,9 +1327,7 @@
           return FALSE;
       }
   
  -    /* Remove spaces from display name to create service name */
  -    service_name = strdup(display_name);
  -    ap_remove_spaces(service_name, display_name);
  +    service_name = get_service_name(display_name);
   
       if (isWindowsNT()) 
       {
  
  
  
  1.19      +2 -0      apache-1.3/src/os/win32/service.h
  
  Index: service.h
  ===================================================================
  RCS file: /home/cvs/apache-1.3/src/os/win32/service.h,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- service.h	2001/02/14 14:22:11	1.18
  +++ service.h	2001/10/03 20:56:00	1.19
  @@ -79,6 +79,8 @@
   		   char *display_name);
   void service_set_status(int status);
   void service_cd();
  +char *get_service_name(char *display_name);
  +char *get_display_name(char *service_name);
   BOOL isProcessService();
   BOOL isValidService(char *display_name);
   void InstallService(pool *p, char *display_name, int argc, char **argv, int reconfig);
  
  
  
  1.37      +3 -3      apache-1.3/src/os/win32/registry.c
  
  Index: registry.c
  ===================================================================
  RCS file: /home/cvs/apache-1.3/src/os/win32/registry.c,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -r1.36 -r1.37
  --- registry.c	2001/02/14 14:22:10	1.36
  +++ registry.c	2001/10/03 20:56:00	1.37
  @@ -89,6 +89,7 @@
   
   #include "httpd.h"
   #include "http_log.h"
  +#include "service.h"
   
   /* Define where the Apache values are stored in the registry. In general
    * VERSION will be the same across all beta releases for a particular
  @@ -279,9 +280,8 @@
       if (display_name == NULL)
           return strdup("");
   
  -    service_name = strdup(display_name);
  -    ap_remove_spaces(service_name, display_name);
  -
  +    service_name = get_service_name(display_name);
  +    
       key = malloc(strlen(SERVICEKEYPRE) +
                    strlen(service_name) +
                    strlen(SERVICEKEYPOST) + 1);
  
  
  
  1.552     +20 -3     apache-1.3/src/main/http_main.c
  
  Index: http_main.c
  ===================================================================
  RCS file: /home/cvs/apache-1.3/src/main/http_main.c,v
  retrieving revision 1.551
  retrieving revision 1.552
  diff -u -r1.551 -r1.552
  --- http_main.c	2001/09/27 18:12:04	1.551
  +++ http_main.c	2001/10/03 20:56:00	1.552
  @@ -1310,6 +1310,8 @@
       fprintf(stderr, "  -k install   | -i: install an Apache service\n");
       fprintf(stderr, "  -k config        : reconfigure an installed Apache service\n");
       fprintf(stderr, "  -k uninstall | -u: uninstall an Apache service\n");
  +    fprintf(stderr, "  -W service       : after -k config|install; Apache starts after
'service'\n");
  +    fprintf(stderr, "  -w               : holds the window open for 30 seconds for fatal
errors.\n");
   #endif
   
   #if defined(NETWARE)
  @@ -7059,7 +7061,7 @@
           reparsed = 1;
       }
   
  -    while ((c = getopt(argc, argv, "D:C:c:Xd:f:vVlLz:Z:wiuStThk:n:")) != -1) {
  +    while ((c = getopt(argc, argv, "D:C:c:Xd:f:vVlLz:Z:wiuStThk:n:W:")) != -1) {
   #else /* !WIN32 */
       while ((c = getopt(argc, argv, "D:C:c:Xd:f:vVlLsStTh")) != -1) {
   #endif
  @@ -7125,6 +7127,19 @@
               else
                   signal_to_send = optarg;
   	    break;
  +        case 'W':
  +            /* -With a dependent service */
  +            if (install < 1) {
  +	        fprintf(stderr, "%s: invalid option: -W %s ignored\n"
  +                        "\t-W only modifies -k install or -k config\n",
  +                        argv[0], optarg);
  +            }
  +            else if (!isWindowsNT()) {
  +                fprintf(stderr, "%s: invalid option: -W %s ignored\n"
  +                        "\t-W is only supported for Windows NT/2000\n",
  +                        argv[0], optarg);
  +            }
  +            break;
   #endif /* WIN32 */
   #ifdef NETWARE
           case 's':
  @@ -7225,6 +7240,10 @@
           service_name = DEFAULTSERVICENAME;
       }
   
  +    if (service_name) {
  +        service_name = get_display_name(service_name);
  +    }
  +
       if (service_name && isValidService(service_name)) 
       {
           if (install == 2) {
  @@ -7314,8 +7333,6 @@
       }
   
       if (install) {
  -        if (!service_name)
  -            service_name = ap_pstrdup(pconf, DEFAULTSERVICENAME);
           if (install > 0) 
               InstallService(pconf, service_name, argc, argv, install == 1);
           else
  
  
  

Mime
View raw message