s3 swat: Allow getting the user's HTTP auth password
[samba.git] / source3 / web / cgi.c
index ce36bd93101b4823f9975f46304fba8b1e726d2f..8eef0b3b501151059c2081222bc5b83f2a04fa32 100644 (file)
@@ -42,6 +42,7 @@ static char *query_string;
 static const char *baseurl;
 static char *pathinfo;
 static char *C_user;
+static char *C_pass;
 static bool inetd_server;
 static bool got_request;
 
@@ -314,7 +315,7 @@ static void cgi_web_auth(void)
                exit(0);
        }
 
-       pwd = getpwnam_alloc(NULL, user);
+       pwd = getpwnam_alloc(talloc_autofree_context(), user);
        if (!pwd) {
                printf("%sCannot find user %s<br>%s\n", head, user, tail);
                exit(0);
@@ -367,7 +368,7 @@ static bool cgi_handle_authorization(char *line)
         * Try and get the user from the UNIX password file.
         */
        
-       pass = getpwnam_alloc(NULL, user);
+       pass = getpwnam_alloc(talloc_autofree_context(), user);
        
        /*
         * Validate the password they have given.
@@ -388,6 +389,7 @@ static bool cgi_handle_authorization(char *line)
                        
                        /* Save the users name */
                        C_user = SMB_STRDUP(user);
+                       C_pass = SMB_STRDUP(user_pass);
                        TALLOC_FREE(pass);
                        return True;
                }
@@ -422,6 +424,13 @@ char *cgi_user_name(void)
         return(C_user);
 }
 
+/***************************************************************************
+return a ptr to the users password
+  ***************************************************************************/
+char *cgi_user_pass(void)
+{
+        return(C_pass);
+}
 
 /***************************************************************************
 handle a file download
@@ -498,7 +507,9 @@ static void cgi_download(char *file)
 
        printf("Content-Length: %d\r\n\r\n", (int)st.st_size);
        while ((l=read(fd,buf,sizeof(buf)))>0) {
-               fwrite(buf, 1, l, stdout);
+               if (fwrite(buf, 1, l, stdout) != l) {
+                       break;
+               }
        }
        close(fd);
        exit(0);
@@ -655,7 +666,8 @@ const char *cgi_remote_addr(void)
 {
        if (inetd_server) {
                char addr[INET6_ADDRSTRLEN];
-               return get_peer_addr(1,addr,sizeof(addr));
+               get_peer_addr(1,addr,sizeof(addr));
+               return talloc_strdup(talloc_tos(), addr);
        }
        return getenv("REMOTE_ADDR");
 }