Simple rename of get_socket_addr to get_peer_addr and get_socket_name to
[samba.git] / source3 / web / cgi.c
index 35f32662833fb28c204105a489a7f699b48d301c..49a8fa92de4a937da3f44e6bfc344d54856c13c4 100644 (file)
@@ -114,7 +114,7 @@ void cgi_load_variables(void)
        if (len > 0 && 
            (request_post ||
             ((s=getenv("REQUEST_METHOD")) && 
-             strcasecmp(s,"POST")==0))) {
+             strequal(s,"POST")))) {
                while (len && (line=grab_line(f, &len))) {
                        p = strchr_m(line,'=');
                        if (!p) continue;
@@ -224,9 +224,9 @@ static void cgi_setup_error(const char *err, const char *header, const char *inf
                /* damn browsers don't like getting cut off before they give a request */
                char line[1024];
                while (fgets(line, sizeof(line)-1, stdin)) {
-                       if (strncasecmp(line,"GET ", 4)==0 || 
-                           strncasecmp(line,"POST ", 5)==0 ||
-                           strncasecmp(line,"PUT ", 4)==0) {
+                       if (strnequal(line,"GET ", 4) || 
+                           strnequal(line,"POST ", 5) ||
+                           strnequal(line,"PUT ", 4)) {
                                break;
                        }
                }
@@ -297,15 +297,16 @@ handle a http authentication line
   ***************************************************************************/
 static BOOL cgi_handle_authorization(char *line)
 {
-       char *p, *user, *user_pass;
+       char *p;
+       fstring user, user_pass;
        struct passwd *pass = NULL;
 
-       if (strncasecmp(line,"Basic ", 6)) {
+       if (!strnequal(line,"Basic ", 6)) {
                goto err;
        }
        line += 6;
        while (line[0] == ' ') line++;
-       base64_decode(line);
+       base64_decode_inplace(line);
        if (!(p=strchr_m(line,':'))) {
                /*
                 * Always give the same error so a cracker
@@ -314,9 +315,15 @@ static BOOL cgi_handle_authorization(char *line)
                goto err;
        }
        *p = 0;
-       user = line;
-       user_pass = p+1;
-       
+
+       convert_string(CH_DISPLAY, CH_UNIX, 
+                      line, -1, 
+                      user, sizeof(user));
+
+       convert_string(CH_DISPLAY, CH_UNIX, 
+                      p+1, -1, 
+                      user_pass, sizeof(user_pass));
+
        /*
         * Try and get the user from the UNIX password file.
         */
@@ -335,6 +342,9 @@ static BOOL cgi_handle_authorization(char *line)
                         * Password was ok.
                         */
                        
+                       if ( initgroups(pass->pw_name, pass->pw_gid) != 0 )
+                               goto err;
+
                        become_user_permanently(pass->pw_uid, pass->pw_gid);
                        
                        /* Save the users name */
@@ -448,11 +458,11 @@ void cgi_setup(const char *rootdir, int auth_required)
        char *lang;
 
        if (chdir(rootdir)) {
-               cgi_setup_error("400 Server Error", "",
+               cgi_setup_error("500 Server Error", "",
                                "chdir failed - the server is not configured correctly");
        }
 
-       /* Handle the possability we might be running as non-root */
+       /* Handle the possibility we might be running as non-root */
        sec_init();
 
        if ((lang=getenv("HTTP_ACCEPT_LANGUAGE"))) {
@@ -471,7 +481,7 @@ void cgi_setup(const char *rootdir, int auth_required)
        inetd_server = True;
 
        if (!check_access(1, lp_hostsallow(-1), lp_hostsdeny(-1))) {
-               cgi_setup_error("400 Server Error", "",
+               cgi_setup_error("403 Forbidden", "",
                                "Samba is configured to deny access from this client\n<br>Check your \"hosts allow\" and \"hosts deny\" options in smb.conf ");
        }
 
@@ -479,22 +489,22 @@ void cgi_setup(const char *rootdir, int auth_required)
           and handle authentication etc */
        while (fgets(line, sizeof(line)-1, stdin)) {
                if (line[0] == '\r' || line[0] == '\n') break;
-               if (strncasecmp(line,"GET ", 4)==0) {
+               if (strnequal(line,"GET ", 4)) {
                        got_request = True;
                        url = strdup(&line[4]);
-               } else if (strncasecmp(line,"POST ", 5)==0) {
+               } else if (strnequal(line,"POST ", 5)) {
                        got_request = True;
                        request_post = 1;
                        url = strdup(&line[5]);
-               } else if (strncasecmp(line,"PUT ", 4)==0) {
+               } else if (strnequal(line,"PUT ", 4)) {
                        got_request = True;
                        cgi_setup_error("400 Bad Request", "",
                                        "This server does not accept PUT requests");
-               } else if (strncasecmp(line,"Authorization: ", 15)==0) {
+               } else if (strnequal(line,"Authorization: ", 15)) {
                        authenticated = cgi_handle_authorization(&line[15]);
-               } else if (strncasecmp(line,"Content-Length: ", 16)==0) {
+               } else if (strnequal(line,"Content-Length: ", 16)) {
                        content_length = atoi(&line[16]);
-               } else if (strncasecmp(line,"Accept-Language: ", 17)==0) {
+               } else if (strnequal(line,"Accept-Language: ", 17)) {
                        web_set_lang(&line[17]);
                }
                /* ignore all other requests! */
@@ -568,7 +578,7 @@ return the hostname of the client
 char *cgi_remote_host(void)
 {
        if (inetd_server) {
-               return get_socket_name(1,False);
+               return get_peer_name(1,False);
        }
        return getenv("REMOTE_HOST");
 }
@@ -579,7 +589,7 @@ return the hostname of the client
 char *cgi_remote_addr(void)
 {
        if (inetd_server) {
-               return get_socket_addr(1);
+               return get_peer_addr(1);
        }
        return getenv("REMOTE_ADDR");
 }