convert all POST variables from display to unix charset
authorAndrew Tridgell <tridge@samba.org>
Mon, 24 Sep 2001 04:49:14 +0000 (04:49 +0000)
committerAndrew Tridgell <tridge@samba.org>
Mon, 24 Sep 2001 04:49:14 +0000 (04:49 +0000)
(This used to be commit cd6478ad9890949d0ef34a7078ec5518debe4a3c)

source3/web/cgi.c
source3/web/swat.c

index a8af9b27221468ded93616bd5a04576811adcd03..0227cd07a62dd020da3840d68dc4bf7649f24db8 100644 (file)
@@ -127,12 +127,12 @@ static char *grab_line(FILE *f, int *cl)
   with the same name and the same or different values. Takes a file parameter
   for simulating CGI invocation eg loading saved preferences.
   ***************************************************************************/
-void cgi_load_variables(FILE *f1)
+void cgi_load_variables(void)
 {
-       FILE *f = f1;
        static char *line;
        char *p, *s, *tok;
-       int len;
+       int len, i;
+       FILE *f = stdin;
 
 #ifdef DEBUG_COMMENTS
        char dummy[100]="";
@@ -140,23 +140,16 @@ void cgi_load_variables(FILE *f1)
        printf("<!== Start dump in cgi_load_variables() %s ==>\n",__FILE__);
 #endif
 
-       if (!f1) {
-               f = stdin;
-               if (!content_length) {
-                       p = getenv("CONTENT_LENGTH");
-                       len = p?atoi(p):0;
-               } else {
-                       len = content_length;
-               }
+       if (!content_length) {
+               p = getenv("CONTENT_LENGTH");
+               len = p?atoi(p):0;
        } else {
-               struct stat st;
-               fstat(fileno(f), &st);
-               len = st.st_size;
+               len = content_length;
        }
 
 
        if (len > 0 && 
-           (f1 || request_post ||
+           (request_post ||
             ((s=getenv("REQUEST_METHOD")) && 
              strcasecmp(s,"POST")==0))) {
                while (len && (line=grab_line(f, &len))) {
@@ -188,13 +181,6 @@ void cgi_load_variables(FILE *f1)
                }
        }
 
-       if (f1) {
-#ifdef DEBUG_COMMENTS
-               printf("<!== End dump in cgi_load_variables() ==>\n"); 
-#endif
-               return;
-       }
-
        fclose(stdin);
        open("/dev/null", O_RDWR);
 
@@ -228,6 +214,26 @@ void cgi_load_variables(FILE *f1)
 #ifdef DEBUG_COMMENTS
         printf("<!== End dump in cgi_load_variables() ==>\n");   
 #endif
+
+       /* variables from the client are in display charset - convert them
+          to our internal charset before use */
+       for (i=0;i<num_variables;i++) {
+               pstring dest;
+
+               convert_string(CH_DISPLAY, CH_UNIX, 
+                              variables[i].name, -1, 
+                              dest, sizeof(dest));
+               free(variables[i].name);
+               variables[i].name = strdup(dest);
+
+               convert_string(CH_DISPLAY, CH_UNIX, 
+                              variables[i].value, -1, 
+                              dest, sizeof(dest));
+               free(variables[i].value);
+               variables[i].value = strdup(dest);
+       }
+
+
 }
 
 
index 56ce321f8d82fbc3cc4c8e789f7e5e10f34357eb..9a7658e94f5c4d524ef52f9f299acb4e5492fb2c 100644 (file)
@@ -1042,7 +1042,7 @@ static void printers_page(void)
 
        print_header();
        
-       cgi_load_variables(NULL);
+       cgi_load_variables();
 
        if (!file_exist(servicesf, NULL)) {
                have_read_access = True;