]> granicus.if.org Git - php/commitdiff
Provide basic auth info to scripts.
authorSascha Schumann <sas@php.net>
Wed, 11 Oct 2000 19:40:56 +0000 (19:40 +0000)
committerSascha Schumann <sas@php.net>
Wed, 11 Oct 2000 19:40:56 +0000 (19:40 +0000)
Protect shutdown handler from being called multiple times.

sapi/thttpd/thttpd.c

index 1dc2b11b2f54872c23c68965c1bcdd7069671752..47eed6767f42f6509bd6becbdc0c4f8025771173 100644 (file)
@@ -241,6 +241,23 @@ static void thttpd_request_ctor(TLS_D SLS_DC)
        SG(request_info).auth_user = NULL;
        SG(request_info).auth_password = NULL;
 
+       if (TG(hc)->authorization[0] != '\0' 
+                       && strncmp(TG(hc)->authorization, "Basic ", 6) == 0) {
+               char *pass;
+               char *user;
+
+               user = php_base64_decode(TG(hc)->authorization + 6, strlen(TG(hc)->authorization) - 6, NULL);
+               if (user) {
+                       pass = strchr(user, ':');
+                       if (pass) {
+                               *pass++ = '\0';
+                               SG(request_info).auth_user = user;
+                               SG(request_info).auth_password = estrdup(pass);
+                       } else
+                               efree(user);
+               }
+       }
+
        TG(post_off) = TG(hc)->read_idx - TG(hc)->checked_idx;
 
        /* avoid feeding \r\n from POST data to SAPI */
@@ -283,6 +300,8 @@ void thttpd_php_init(void)
 
 void thttpd_php_shutdown(void)
 {
-       sapi_module.shutdown(&sapi_module);
-       sapi_shutdown();
+       if (SG(server_context) != NULL) {
+               sapi_module.shutdown(&sapi_module);
+               sapi_shutdown();
+       }
 }