s3 swat: Allow getting the user's HTTP auth password
[samba.git] / source3 / web / cgi.c
index 070e80cf91df831c331c8dd3459090dded38796f..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
@@ -451,7 +460,7 @@ static void cgi_download(char *file)
        if (S_ISDIR(st.st_mode))
        {
                snprintf(buf, sizeof(buf), "%s/index.html", file);
-               if (!file_exist(buf, &st) || !S_ISREG(st.st_mode))
+               if (!file_exist_stat(buf, &st) || !S_ISREG(st.st_mode))
                {
                        cgi_setup_error("404 File Not Found","",
                                        "The requested file was not found");
@@ -488,7 +497,8 @@ static void cgi_download(char *file)
                        printf("Content-Type: text/html\r\n");
                }
        }
-       printf("Expires: %s\r\n", http_timestring(time(NULL)+EXPIRY_TIME));
+       printf("Expires: %s\r\n", 
+                  http_timestring(talloc_tos(), time(NULL)+EXPIRY_TIME));
 
        lang = lang_tdb_current();
        if (lang) {
@@ -497,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);
@@ -604,7 +616,7 @@ void cgi_setup(const char *rootdir, int auth_required)
        }
 
        printf("HTTP/1.0 200 OK\r\nConnection: close\r\n");
-       printf("Date: %s\r\n", http_timestring(time(NULL)));
+       printf("Date: %s\r\n", http_timestring(talloc_tos(), time(NULL)));
        baseurl = "";
        pathinfo = url+1;
 }
@@ -654,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");
 }