From 926f4d9125fa76d54e9abeba372ee78e9545182b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 11 Sep 1997 02:17:16 +0000 Subject: cgi.c is a simple set of CGI manipulation routines wsmbconf.c is a rudimentary web based smb.conf editor. Its really there just to demonstrate how such an editor can hook into loadparm.c, I don't expect anyone to actually use it as is. wsmbstatus.c is a simple web based smbstatus. Its probably broken. (This used to be commit ced5205f72ba58d677f3cfa480fddc58ec9faa27) --- source3/web/cgi.c | 163 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 163 insertions(+) create mode 100644 source3/web/cgi.c (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c new file mode 100644 index 0000000000..56c293985d --- /dev/null +++ b/source3/web/cgi.c @@ -0,0 +1,163 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + some simple CGI helper routines + Copyright (C) Andrew Tridgell 1997 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + + +#include "includes.h" + +#define MAX_VARIABLES 512 + +struct var { + char *name; + char *value; +}; + +static struct var variables[MAX_VARIABLES]; +static int num_variables; + + +static int grab_line(int *cl, char *line, int maxsize) +{ + int i = 0; + + while ((*cl)) { + int c = fgetc(stdin); + (*cl)--; + + if (c == EOF) { + (*cl) = 0; + break; + } + + if (c == '+') { + c = ' '; + } + + if (c == '\r') continue; + + if (strchr("\n&", c)) break; + + if (c == '%' && (*cl) >= 2) { + int c1, c2; + c1 = fgetc(stdin); + c2 = fgetc(stdin); + (*cl) -= 2; + if (c1 == EOF || c2 == EOF) break; + if (c1 >= '0' && c1 <= '9') + c1 = c1 - '0'; + else if (c1 >= 'A' && c1 <= 'F') + c1 = 10 + c1 - 'A'; + else if (c1 >= 'a' && c1 <= 'f') + c1 = 10 + c1 - 'a'; + else break; + + if (c2 >= '0' && c2 <= '9') + c2 = c2 - '0'; + else if (c2 >= 'A' && c2 <= 'F') + c2 = 10 + c2 - 'A'; + else if (c2 >= 'a' && c2 <= 'f') + c2 = 10 + c2 - 'a'; + else break; + + c = (c1<<4) | c2; + } + + line[i++] = c; + + if (i == maxsize) break; + } + + /* now unescape the line */ + + + line[i] = 0; + return 1; +} + + +/*************************************************************************** + load all the variables passed to the CGI program + ***************************************************************************/ +void cgi_load_variables(void) +{ + static pstring line; + char *p; + int len; + + if (!(p=getenv("CONTENT_LENGTH"))) return; + + len = atoi(p); + + if (len <= 0) return; + + + + while (len && grab_line(&len, line, sizeof(line)-1)) { + p = strchr(line,'='); + if (!p) continue; + + *p = 0; + + variables[num_variables].name = strdup(line); + variables[num_variables].value = strdup(p+1); + + if (!variables[num_variables].name || + !variables[num_variables].value) + continue; + +#if 0 + printf("%s=%s
\n", + variables[num_variables].name, + variables[num_variables].value); +#endif + + num_variables++; + if (num_variables == MAX_VARIABLES) break; + } + + fclose(stdin); +} + + +/*************************************************************************** + find a variable passed via CGI + ***************************************************************************/ +char *cgi_variable(char *name) +{ + int i; + + for (i=0;i Date: Sat, 22 Nov 1997 07:51:23 +0000 Subject: this new cgi code includes the ability to act as a mini web server, allowing people to use web configuration of Samba without installing a web server (This used to be commit b4e05c360e77cbf27a95920b613bfe6bc874ea1b) --- source3/web/cgi.c | 577 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 510 insertions(+), 67 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 56c293985d..3739d712d3 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -1,6 +1,4 @@ /* - Unix SMB/Netbios implementation. - Version 1.9. some simple CGI helper routines Copyright (C) Andrew Tridgell 1997 @@ -20,9 +18,19 @@ */ -#include "includes.h" +#include +#include +#include +#include +#include +#include +#include -#define MAX_VARIABLES 512 +#define MAX_VARIABLES 10000 + +#ifdef DEBUG_COMMENTS +extern void print_title(char *fmt, ...); +#endif struct var { char *name; @@ -31,14 +39,60 @@ struct var { static struct var variables[MAX_VARIABLES]; static int num_variables; +static int content_length; +static int request_post; +static int request_get; +static char *query_string; + +static void unescape(char *buf) +{ + char *p=buf; + + while ((p=strchr(p,'+'))) + *p = ' '; + + p = buf; + + while (p && *p && (p=strchr(p,'%'))) { + int c1 = p[1]; + int c2 = p[2]; + + if (c1 >= '0' && c1 <= '9') + c1 = c1 - '0'; + else if (c1 >= 'A' && c1 <= 'F') + c1 = 10 + c1 - 'A'; + else if (c1 >= 'a' && c1 <= 'f') + c1 = 10 + c1 - 'a'; + else {p++; continue;} + + if (c2 >= '0' && c2 <= '9') + c2 = c2 - '0'; + else if (c2 >= 'A' && c2 <= 'F') + c2 = 10 + c2 - 'A'; + else if (c2 >= 'a' && c2 <= 'f') + c2 = 10 + c2 - 'a'; + else {p++; continue;} + + *p = (c1<<4) | c2; + + memcpy(p+1, p+3, strlen(p+3)+1); + p++; + } +} -static int grab_line(int *cl, char *line, int maxsize) +static char *grab_line(FILE *f, int *cl) { + char *ret; int i = 0; + int len = 1024; + + ret = (char *)malloc(len); + if (!ret) return NULL; + while ((*cl)) { - int c = fgetc(stdin); + int c = fgetc(f); (*cl)--; if (c == EOF) { @@ -46,98 +100,140 @@ static int grab_line(int *cl, char *line, int maxsize) break; } - if (c == '+') { - c = ' '; - } - if (c == '\r') continue; if (strchr("\n&", c)) break; - if (c == '%' && (*cl) >= 2) { - int c1, c2; - c1 = fgetc(stdin); - c2 = fgetc(stdin); - (*cl) -= 2; - if (c1 == EOF || c2 == EOF) break; - if (c1 >= '0' && c1 <= '9') - c1 = c1 - '0'; - else if (c1 >= 'A' && c1 <= 'F') - c1 = 10 + c1 - 'A'; - else if (c1 >= 'a' && c1 <= 'f') - c1 = 10 + c1 - 'a'; - else break; - - if (c2 >= '0' && c2 <= '9') - c2 = c2 - '0'; - else if (c2 >= 'A' && c2 <= 'F') - c2 = 10 + c2 - 'A'; - else if (c2 >= 'a' && c2 <= 'f') - c2 = 10 + c2 - 'a'; - else break; - - c = (c1<<4) | c2; - } - - line[i++] = c; + ret[i++] = c; - if (i == maxsize) break; + if (i == len-1) { + char *ret2; + ret2 = (char *)realloc(ret, len*2); + if (!ret2) return ret; + len *= 2; + ret = ret2; + } } - - /* now unescape the line */ - line[i] = 0; - return 1; + ret[i] = 0; + return ret; } - /*************************************************************************** - load all the variables passed to the CGI program + load all the variables passed to the CGI program. May have multiple variables + 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(void) +void cgi_load_variables(FILE *f1) { - static pstring line; - char *p; + FILE *f = f1; + static char *line; + char *p, *s, *tok; int len; - if (!(p=getenv("CONTENT_LENGTH"))) return; +#ifdef DEBUG_COMMENTS + char dummy[100]=""; + print_title(dummy); + printf("\n",__FILE__); +#endif - len = atoi(p); + if (!f1) { + f = stdin; + if (!content_length) { + p = getenv("CONTENT_LENGTH"); + len = p?atoi(p):0; + } else { + len = content_length; + } + } else { + fseek(f, 0, SEEK_END); + len = ftell(f); + fseek(f, 0, SEEK_SET); + } - if (len <= 0) return; - + if (len > 0 && + (f1 || request_post || + ((s=getenv("REQUEST_METHOD")) && + strcasecmp(s,"POST")==0))) { + while (len && (line=grab_line(f, &len))) { + p = strchr(line,'='); + if (!p) continue; + + *p = 0; + + variables[num_variables].name = strdup(line); + variables[num_variables].value = strdup(p+1); - while (len && grab_line(&len, line, sizeof(line)-1)) { - p = strchr(line,'='); - if (!p) continue; + free(line); + + if (!variables[num_variables].name || + !variables[num_variables].value) + continue; - *p = 0; + unescape(variables[num_variables].value); + unescape(variables[num_variables].name); - variables[num_variables].name = strdup(line); - variables[num_variables].value = strdup(p+1); - - if (!variables[num_variables].name || - !variables[num_variables].value) - continue; - -#if 0 - printf("%s=%s
\n", - variables[num_variables].name, - variables[num_variables].value); +#ifdef DEBUG_COMMENTS + printf("\n", + variables[num_variables].name, + variables[num_variables].value); #endif + + num_variables++; + if (num_variables == MAX_VARIABLES) break; + } + } - num_variables++; - if (num_variables == MAX_VARIABLES) break; + if (f1) { +#ifdef DEBUG_COMMENTS + printf("\n"); +#endif + return; } fclose(stdin); + + if ((s=query_string) || (s=getenv("QUERY_STRING"))) { + for (tok=strtok(s,"&;");tok;tok=strtok(NULL,"&;")) { + p = strchr(tok,'='); + if (!p) continue; + + *p = 0; + + variables[num_variables].name = strdup(tok); + variables[num_variables].value = strdup(p+1); + + if (!variables[num_variables].name || + !variables[num_variables].value) + continue; + + unescape(variables[num_variables].value); + unescape(variables[num_variables].name); + +#ifdef DEBUG_COMMENTS + printf("\n", + variables[num_variables].name, + variables[num_variables].value); +#endif + num_variables++; + if (num_variables == MAX_VARIABLES) break; + } + + } +#ifdef DEBUG_COMMENTS + printf("\n"); +#endif } /*************************************************************************** find a variable passed via CGI + Doesn't quite do what you think in the case of POST text variables, because + if they exist they might have a value of "" or even " ", depending on the + browser. Also doesn't allow for variables[] containing multiple variables + with the same name and the same or different values. ***************************************************************************/ char *cgi_variable(char *name) { @@ -149,6 +245,15 @@ char *cgi_variable(char *name) return NULL; } +/*************************************************************************** +return a particular cgi variable + ***************************************************************************/ +char *cgi_vnum(int i, char **name) +{ + if (i < 0 || i >= num_variables) return NULL; + *name = variables[i].name; + return variables[i].value; +} /*************************************************************************** return the value of a CGI boolean variable. @@ -161,3 +266,341 @@ int cgi_boolean(char *name, int def) return strcmp(p, "1") == 0; } + +/*************************************************************************** +like strdup() but quotes < > and & + ***************************************************************************/ +char *quotedup(char *s) +{ + int i, n=0; + int len; + char *ret; + char *d; + + if (!s) return strdup(""); + + len = strlen(s); + + for (i=0;i' || s[i] == '&') + n++; + + ret = malloc(len + n*6 + 1); + + if (!ret) return NULL; + + d = ret; + + for (i=0;i': + strcpy(d, ">"); + d += 4; + break; + + case '&': + strcpy(d, "&"); + d += 5; + break; + + default: + *d++ = s[i]; + } + } + + *d = 0; + + return ret; +} + + +/*************************************************************************** +like strdup() but quotes a wide range of characters + ***************************************************************************/ +char *urlquote(char *s) +{ + int i, n=0; + int len; + char *ret; + char *d; + char *qlist = "\"\n\r'&<> \t+;"; + + if (!s) return strdup(""); + + len = strlen(s); + + for (i=0;i%s

%s

%s

\r\n", err, header, err, err, info); + exit(0); +} + + +/*************************************************************************** +decode a base64 string in-place - simple and slow algorithm + ***************************************************************************/ +static void base64_decode(char *s) +{ + char *b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + int bit_offset, byte_offset, idx, i; + unsigned char *d = (unsigned char *)s; + char *p; + + i=0; + + while (*s && (p=strchr(b64,*s))) { + idx = (int)(p - b64); + byte_offset = (i*6)/8; + bit_offset = (i*6)%8; + d[byte_offset] &= ~((1<<(8-bit_offset))-1); + if (bit_offset < 3) { + d[byte_offset] |= (idx << (2-bit_offset)); + } else { + d[byte_offset] |= (idx >> (bit_offset-2)); + d[byte_offset+1] = 0; + d[byte_offset+1] |= (idx << (8-(bit_offset-2))) & 0xFF; + } + s++; i++; + } +} + + +/*************************************************************************** +handle a http authentication line + ***************************************************************************/ +static int cgi_handle_authorization(char *line) +{ + char *p, *user, *pass; + struct passwd *pwd; + int ret=0; + + if (strncasecmp(line,"Basic ", 6)) { + cgi_setup_error("401 Bad Authorization", "", + "Only basic authorization is understood"); + } + line += 6; + while (line[0] == ' ') line++; + base64_decode(line); + if (!(p=strchr(line,':'))) { + cgi_setup_error("401 Bad Authorization", "", + "username/password must be supplied"); + } + *p = 0; + user = line; + pass = p+1; + + /* currently only allow connections as root */ + if (strcasecmp(user,"root")) { + cgi_setup_error("401 Bad Authorization", "", + "incorrect username/password"); + } + + pwd = getpwnam(user); + + if (!strcmp((char *)crypt(pass, pwd->pw_passwd),pwd->pw_passwd)) { + ret = 1; + } + + memset(pass, 0, strlen(pass)); + + return ret; +} + + +/*************************************************************************** +handle a file download + ***************************************************************************/ +static void cgi_download(char *file) +{ + struct stat st; + char buf[1024]; + int fd, l; + char *p; + + if (!file_exist(file, &st)) { + cgi_setup_error("404 File Not Found","", + "The requested file was not found"); + } + fd = open(file,O_RDONLY); + if (fd == -1) { + cgi_setup_error("404 File Not Found","", + "The requested file was not found"); + } + printf("HTTP/1.1 200 OK\r\n"); + if ((p=strrchr(file,'.'))) { + if (strcmp(p,".gif")==0 || strcmp(p,".jpg")==0) { + printf("Content-Type: image/gif\r\n"); + } else { + printf("Content-Type: text/html\r\n"); + } + } + 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); + } + close(fd); + exit(0); +} + + +/*************************************************************************** +setup the cgi framework, handling the possability that this program is either +run as a true cgi program by a web browser or is itself a mini web server + ***************************************************************************/ +void cgi_setup(char *rootdir) +{ + int authenticated = 0; + char line[1024]; + char *url=NULL; + char *p; + + if (chdir(rootdir)) { + cgi_setup_error("400 Server Error", "", + "chdir failed - the server is not configured correctly"); + } + + if (getenv("CONTENT_LENGTH") || getenv("REQUEST_METHOD")) { + /* assume we are running under a real web server */ + return; + } + + /* we are a mini-web server. We need to read the request from stdin + 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) { + request_get = 1; + url = strdup(&line[4]); + } else if (strncasecmp(line,"POST ", 5)==0) { + request_post = 1; + url = strdup(&line[5]); + } else if (strncasecmp(line,"PUT ", 4)==0) { + cgi_setup_error("400 Bad Request", "", + "This server does not accept PUT requests"); + } else if (strncasecmp(line,"Authorization: ", 15)==0) { + authenticated = cgi_handle_authorization(&line[15]); + } else if (strncasecmp(line,"Content-Length: ", 16)==0) { + content_length = atoi(&line[16]); + } + /* ignore all other requests! */ + } + + if (!authenticated) { + cgi_setup_error("401 Authorization Required", + "WWW-Authenticate: Basic realm=\"samba\"\r\n", + "You must be authenticated to use this service"); + } + + if (!url) { + cgi_setup_error("400 Bad Request", "", + "You must specify a GET or POST request"); + } + + /* trim the URL */ + if ((p = strchr(url,' ')) || (p=strchr(url,'\t'))) { + *p = 0; + } + while (*url && strchr("\r\n",url[strlen(url)-1])) { + url[strlen(url)-1] = 0; + } + + /* anything following a ? in the URL is part of the query string */ + if ((p=strchr(url,'?'))) { + query_string = p+1; + *p = 0; + } + + if (strcmp(url,"/")) { + cgi_download(url+1); + } + + printf("HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Type: text/html\r\n\r\n"); + +} -- cgit From 74f06e4062634fa4f8cb46915280dedf73d58c6f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 23 Nov 1997 02:42:22 +0000 Subject: minor wsmbconf and cgi changes (This used to be commit bca9c49e6f24c2ee79cbb9b6ebf69d6647146fc1) --- source3/web/cgi.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 3739d712d3..f165c56110 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -501,9 +501,22 @@ static void cgi_download(char *file) { struct stat st; char buf[1024]; - int fd, l; + int fd, l, i; char *p; + /* sanitise the filename */ + for (i=0;file[i];i++) { + if (!isalnum(file[i]) && !strchr("/.-_", file[i])) { + cgi_setup_error("404 File Not Found","", + "Illegal character in filename"); + } + } + + if (strstr(file,"..")) { + cgi_setup_error("404 File Not Found","", + "Relative paths not allowed"); + } + if (!file_exist(file, &st)) { cgi_setup_error("404 File Not Found","", "The requested file was not found"); @@ -574,7 +587,7 @@ void cgi_setup(char *rootdir) if (!authenticated) { cgi_setup_error("401 Authorization Required", - "WWW-Authenticate: Basic realm=\"samba\"\r\n", + "WWW-Authenticate: Basic realm=\"root\"\r\n", "You must be authenticated to use this service"); } @@ -604,3 +617,5 @@ void cgi_setup(char *rootdir) printf("HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Type: text/html\r\n\r\n"); } + + -- cgit From 96eed00608226370ca4177fd9c8a4ae54d17517d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 12 Jan 1998 00:32:27 +0000 Subject: propogate my cgi changes to the main branch (This used to be commit 215c97e83ac74757cffb4f64176c80ddb845d65f) --- source3/web/cgi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index f165c56110..e697f5537a 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -614,7 +614,7 @@ void cgi_setup(char *rootdir) cgi_download(url+1); } - printf("HTTP/1.1 200 OK\r\nConnection: close\r\nContent-Type: text/html\r\n\r\n"); + printf("HTTP/1.1 200 OK\r\nConnection: close\r\n"); } -- cgit From 55f400bd84f26027f5ec9b7fa06b22895de7557c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 22 Jan 1998 13:27:43 +0000 Subject: This is *not* a big change (although it looks like one). This is merely updating the Copyright statements from 1997 to 1998. It's a once a year thing :-). NO OTHER CHANGES WERE MADE. Jeremy. (This used to be commit b9c16977231efb274e08856f7f3f4408dad6d96c) --- source3/web/cgi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index e697f5537a..ae60d72b7b 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -1,6 +1,6 @@ /* some simple CGI helper routines - Copyright (C) Andrew Tridgell 1997 + Copyright (C) Andrew Tridgell 1997-1998 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by -- cgit From 35d67dd80aa3ba72b75683cb1f35c81066e21223 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 8 Mar 1998 14:14:49 +0000 Subject: Jeremy is going to hate me ... These are some hacks on SWAT. Maybe users will actually be able to work out how to use it now. Unfortunately these changes required some editing in loadparm.c and smb.h which will make Jeremys merge job harder. Sorry! (This used to be commit 674c88a6bf4c8009769a482c53f105efdc54bbc8) --- source3/web/cgi.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index ae60d72b7b..7c84f47ada 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -43,6 +43,7 @@ static int content_length; static int request_post; static int request_get; static char *query_string; +static char *baseurl; static void unescape(char *buf) { @@ -610,12 +611,20 @@ void cgi_setup(char *rootdir) *p = 0; } - if (strcmp(url,"/")) { + if (strstr(url+1,"..")==0 && file_exist(url+1)) { cgi_download(url+1); } printf("HTTP/1.1 200 OK\r\nConnection: close\r\n"); - + + baseurl = url+1; } +/*************************************************************************** +return the current pages URL + ***************************************************************************/ +char *cgi_baseurl(void) +{ + return baseurl; +} -- cgit From 6a37b245e3894c5a3a62bf38d4eef27be5f209e8 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 8 Mar 1998 14:31:50 +0000 Subject: allow for non-authenticated SWAT for demo purposes (This used to be commit 6e1237568b559c006ee5429308ac47e97cc4a1c4) --- source3/web/cgi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 7c84f47ada..83158fc1a5 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -548,7 +548,7 @@ static void cgi_download(char *file) setup the cgi framework, handling the possability that this program is either run as a true cgi program by a web browser or is itself a mini web server ***************************************************************************/ -void cgi_setup(char *rootdir) +void cgi_setup(char *rootdir, int auth_required) { int authenticated = 0; char line[1024]; @@ -586,7 +586,7 @@ void cgi_setup(char *rootdir) /* ignore all other requests! */ } - if (!authenticated) { + if (auth_required && !authenticated) { cgi_setup_error("401 Authorization Required", "WWW-Authenticate: Basic realm=\"root\"\r\n", "You must be authenticated to use this service"); -- cgit From c03c56b2e29fd773b19b01d22be4ce347be9f05b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 8 Mar 1998 14:52:45 +0000 Subject: - remove redundent strstr() - don't show printers in shares page (This used to be commit 2b4204a7769a974a74a7658e787274f6251b1d69) --- source3/web/cgi.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 83158fc1a5..9ce8c4d91e 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -513,11 +513,6 @@ static void cgi_download(char *file) } } - if (strstr(file,"..")) { - cgi_setup_error("404 File Not Found","", - "Relative paths not allowed"); - } - if (!file_exist(file, &st)) { cgi_setup_error("404 File Not Found","", "The requested file was not found"); -- cgit From 49a5dd09b9aaba81fa217c9d41fce5e1f90c054b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Mar 1998 04:56:58 +0000 Subject: added Date and Expires headers in the mini web server so clients know what they can cache. (This used to be commit b6055e40bb91775a29b756640d95910a6f19814f) --- source3/web/cgi.c | 35 +++++++++++++++++++++++++---------- 1 file changed, 25 insertions(+), 10 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 9ce8c4d91e..2008f9a8d3 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -18,16 +18,16 @@ */ -#include -#include -#include -#include -#include -#include -#include +#include "includes.h" +#include "smb.h" #define MAX_VARIABLES 10000 +/* set the expiry on fixed pages */ +#define EXPIRY_TIME (60*60*24*7) + +#define CGI_LOGGING 0 + #ifdef DEBUG_COMMENTS extern void print_title(char *fmt, ...); #endif @@ -524,12 +524,16 @@ static void cgi_download(char *file) } printf("HTTP/1.1 200 OK\r\n"); if ((p=strrchr(file,'.'))) { - if (strcmp(p,".gif")==0 || strcmp(p,".jpg")==0) { + if (strcmp(p,".gif")==0) { printf("Content-Type: image/gif\r\n"); + } else if (strcmp(p,".jpg")==0) { + printf("Content-Type: image/jpeg\r\n"); } else { printf("Content-Type: text/html\r\n"); } } + printf("Expires: %s\r\n", http_timestring(time(NULL)+EXPIRY_TIME)); + 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); @@ -549,6 +553,11 @@ void cgi_setup(char *rootdir, int auth_required) char line[1024]; char *url=NULL; char *p; +#if CGI_LOGGING + FILE *f = fopen("/tmp/cgi.log", "a"); + + fprintf(f,"\n[Date: %s]\n", http_timestring(time(NULL))); +#endif if (chdir(rootdir)) { cgi_setup_error("400 Server Error", "", @@ -563,6 +572,9 @@ void cgi_setup(char *rootdir, int auth_required) /* we are a mini-web server. We need to read the request from stdin and handle authentication etc */ while (fgets(line, sizeof(line)-1, stdin)) { +#if CGI_LOGGING + fputs(line, f); +#endif if (line[0] == '\r' || line[0] == '\n') break; if (strncasecmp(line,"GET ", 4)==0) { request_get = 1; @@ -580,6 +592,9 @@ void cgi_setup(char *rootdir, int auth_required) } /* ignore all other requests! */ } +#if CGI_LOGGING + fclose(f); +#endif if (auth_required && !authenticated) { cgi_setup_error("401 Authorization Required", @@ -606,12 +621,12 @@ void cgi_setup(char *rootdir, int auth_required) *p = 0; } - if (strstr(url+1,"..")==0 && file_exist(url+1)) { + if (strstr(url+1,"..")==0 && file_exist(url+1, NULL)) { cgi_download(url+1); } printf("HTTP/1.1 200 OK\r\nConnection: close\r\n"); - + printf("Date: %s\r\n", http_timestring(time(NULL))); baseurl = url+1; } -- cgit From e1f131bab840f23b1ba5ae4ba36a4054857afc94 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 12 Mar 1998 02:42:39 +0000 Subject: use password_ok() instead of calling crypt() (This used to be commit 53dc8ea5e315abf9ee8d38ffdb8a3057df0235be) --- source3/web/cgi.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 2008f9a8d3..6468c92917 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -459,8 +459,6 @@ handle a http authentication line static int cgi_handle_authorization(char *line) { char *p, *user, *pass; - struct passwd *pwd; - int ret=0; if (strncasecmp(line,"Basic ", 6)) { cgi_setup_error("401 Bad Authorization", "", @@ -478,20 +476,13 @@ static int cgi_handle_authorization(char *line) pass = p+1; /* currently only allow connections as root */ - if (strcasecmp(user,"root")) { + if (strcmp(user,"root")) { cgi_setup_error("401 Bad Authorization", "", "incorrect username/password"); } - - pwd = getpwnam(user); - - if (!strcmp((char *)crypt(pass, pwd->pw_passwd),pwd->pw_passwd)) { - ret = 1; - } - memset(pass, 0, strlen(pass)); - return ret; + return password_ok(user, pass, strlen(pass), NULL); } -- cgit From d5c1af5d9fb33e42e24dc3f1c0ea235eb1fb904a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 14 Mar 1998 04:13:24 +0000 Subject: fixed support for running swat via cgi-bin (This used to be commit 9dbfb16990954ee3518ce3bc73e067c82b653930) --- source3/web/cgi.c | 50 +++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 43 insertions(+), 7 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 6468c92917..46654b1303 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -44,6 +44,7 @@ static int request_post; static int request_get; static char *query_string; static char *baseurl; +static char *pathinfo; static void unescape(char *buf) { @@ -545,9 +546,7 @@ void cgi_setup(char *rootdir, int auth_required) char *url=NULL; char *p; #if CGI_LOGGING - FILE *f = fopen("/tmp/cgi.log", "a"); - - fprintf(f,"\n[Date: %s]\n", http_timestring(time(NULL))); + FILE *f; #endif if (chdir(rootdir)) { @@ -560,11 +559,16 @@ void cgi_setup(char *rootdir, int auth_required) return; } +#if CGI_LOGGING + f = fopen("/tmp/cgi.log", "a"); + if (f) fprintf(f,"\n[Date: %s]\n", http_timestring(time(NULL))); +#endif + /* we are a mini-web server. We need to read the request from stdin and handle authentication etc */ while (fgets(line, sizeof(line)-1, stdin)) { #if CGI_LOGGING - fputs(line, f); + if (f) fputs(line, f); #endif if (line[0] == '\r' || line[0] == '\n') break; if (strncasecmp(line,"GET ", 4)==0) { @@ -584,7 +588,7 @@ void cgi_setup(char *rootdir, int auth_required) /* ignore all other requests! */ } #if CGI_LOGGING - fclose(f); + if (f) fclose(f); #endif if (auth_required && !authenticated) { @@ -618,7 +622,8 @@ void cgi_setup(char *rootdir, int auth_required) printf("HTTP/1.1 200 OK\r\nConnection: close\r\n"); printf("Date: %s\r\n", http_timestring(time(NULL))); - baseurl = url+1; + baseurl = ""; + pathinfo = url+1; } @@ -627,5 +632,36 @@ return the current pages URL ***************************************************************************/ char *cgi_baseurl(void) { - return baseurl; + if (baseurl) { + return baseurl; + } + return getenv("SCRIPT_NAME"); } + +/*************************************************************************** +return the root URL for images etc + ***************************************************************************/ +char *cgi_rooturl(void) +{ + if (baseurl) { + return "/"; + } + return "/swat/"; +} + + +/*************************************************************************** +return the current pages path info + ***************************************************************************/ +char *cgi_pathinfo(void) +{ + char *r; + if (pathinfo) { + return pathinfo; + } + r = getenv("PATH_INFO"); + if (!r) return ""; + if (*r == '/') r++; + return r; +} + -- cgit From f996885676f041437430bfd5843a3000611b0923 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 17 Mar 1998 12:31:43 +0000 Subject: this isn't a big commit, it just looks like it :-) I needed the client_name() and client_addr() functions in swat so I could tell who was connecting from where. The problem was that these functions didn't take a file descriptor parameter they just used the global "Client". So I needed to change all calls to pass a parameter ... lots of files. (This used to be commit a776058900a727591bd7b69debdaa25c0e31d693) --- source3/web/cgi.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 46654b1303..9931ca1468 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -665,3 +665,24 @@ char *cgi_pathinfo(void) return r; } +/*************************************************************************** +return the hostname of the client + ***************************************************************************/ +char *cgi_remote_host(void) +{ + if (baseurl) { + return client_name(1); + } + return getenv("REMOTE_HOST"); +} + +/*************************************************************************** +return the hostname of the client + ***************************************************************************/ +char *cgi_remote_addr(void) +{ + if (baseurl) { + return client_addr(1); + } + return getenv("REMOTE_ADDR"); +} -- cgit From d56fc8d169b0b29136b18c764ddb5d2fdfadbd76 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 17 Mar 1998 12:37:06 +0000 Subject: when CGI_LOGGING is on log the host name and IP this is just so I can snoop on who is looking at the demo :-) (This used to be commit 78abb9fec3aac235ad26d0192351dc81ade6c584) --- source3/web/cgi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 9931ca1468..c5b2ac55f1 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -561,7 +561,9 @@ void cgi_setup(char *rootdir, int auth_required) #if CGI_LOGGING f = fopen("/tmp/cgi.log", "a"); - if (f) fprintf(f,"\n[Date: %s]\n", http_timestring(time(NULL))); + if (f) fprintf(f,"\n[Date: %s %s (%s)]\n", + http_timestring(time(NULL)), + client_name(1), client_addr(1)); #endif /* we are a mini-web server. We need to read the request from stdin -- cgit From c8c61ac6a643d1c51c1546a6e346c566bb34f3b2 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 18 Mar 1998 07:33:11 +0000 Subject: changed the method used for auto-reload on the status page to use JavaScript. This avoids the nasty inetd problem. (This used to be commit 9d9b13880963a0e3cf5213ce2a24c52f4a11a472) --- source3/web/cgi.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index c5b2ac55f1..065c524cb8 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -26,7 +26,7 @@ /* set the expiry on fixed pages */ #define EXPIRY_TIME (60*60*24*7) -#define CGI_LOGGING 0 +#define CGI_LOGGING 1 #ifdef DEBUG_COMMENTS extern void print_title(char *fmt, ...); @@ -688,3 +688,15 @@ char *cgi_remote_addr(void) } return getenv("REMOTE_ADDR"); } + + +/*************************************************************************** +return True if the request was a POST + ***************************************************************************/ +BOOL cgi_waspost(void) +{ + if (baseurl) { + return request_post; + } + return strequal(getenv("REQUEST_METHOD"), "POST"); +} -- cgit From bee4067bd4771ee7883ab6365e91df86a1230618 Mon Sep 17 00:00:00 2001 From: John Terpstra Date: Sat, 21 Mar 1998 03:03:59 +0000 Subject: Getting ready for first Red Hat Linux RPMs for 1.9.19 pre-alpha release (This used to be commit 4e424d0ba652bf9c5dfd3c44216b6145538cf821) --- source3/web/cgi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 065c524cb8..a1aa4d753d 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -26,7 +26,7 @@ /* set the expiry on fixed pages */ #define EXPIRY_TIME (60*60*24*7) -#define CGI_LOGGING 1 +#define CGI_LOGGING 0 #ifdef DEBUG_COMMENTS extern void print_title(char *fmt, ...); -- cgit From f888868f46a5418bac9ab528497136c152895305 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 12 May 1998 00:55:32 +0000 Subject: This is a security audit change of the main source. It removed all ocurrences of the following functions : sprintf strcpy strcat The replacements are slprintf, safe_strcpy and safe_strcat. It should not be possible to use code in Samba that uses sprintf, strcpy or strcat, only the safe_equivalents. Once Andrew has fixed the slprintf implementation then this code will be moved back to the 1.9.18 code stream. Jeremy. (This used to be commit 2d774454005f0b54e5684cf618da7060594dfcbb) --- source3/web/cgi.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index a1aa4d753d..5958b0a419 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -296,17 +296,17 @@ char *quotedup(char *s) for (i=0;i': - strcpy(d, ">"); + safe_strcpy(d, ">", len + n*6 - (d - ret)); d += 4; break; case '&': - strcpy(d, "&"); + safe_strcpy(d, "&", len + n*6 - (d - ret)); d += 5; break; @@ -347,7 +347,7 @@ char *urlquote(char *s) for (i=0;i Date: Mon, 10 Aug 1998 07:04:53 +0000 Subject: split the system password checking routines out of smbd/password.c and into passdb/pass_check.c. This means SWAT no longer needs to link to smbd/password.c (This used to be commit 90d93889d722670cbb517017531264630af759bf) --- source3/web/cgi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 5958b0a419..1a9d34d004 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -483,7 +483,7 @@ static int cgi_handle_authorization(char *line) } - return password_ok(user, pass, strlen(pass), NULL); + return pass_check(user, pass, strlen(pass), NULL, NULL); } -- cgit From e13aeea928dd89373cfaf3916c96f853c1227884 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 15 Aug 1998 01:19:26 +0000 Subject: configure: Changes for extra headers. configure.in: Source for header changes. client/clitar.c: Fixed isXXX macros & debugs for gcc pedantic compile. include/config.h.in: Added MEMSET, BZERO, MEMORY, RPCSVC_YPCLNT, STRINGS headers. include/includes.h: Headers for the above. include/smb.h: Made SIGNAL_CAST POSIX by default void (*)(int). lib/access.c: Fixed isXXX macros & debugs for gcc pedantic compile. lib/charset.c: Fixed isXXX macros & debugs for gcc pedantic compile. lib/debug.c: Fixed signal functs. lib/kanji.c: Fixed isXXX macros & debugs for gcc pedantic compile. lib/smbrun.c: Fixed isXXX macros & debugs for gcc pedantic compile. lib/util.c: Fixed isXXX macros & debugs for gcc pedantic compile. libsmb/namequery.c: Fixed isXXX macros & debugs for gcc pedantic compile. locking/shmem.c: Fixed isXXX macros & debugs for gcc pedantic compile. locking/shmem_sysv.c: Fixed error messages in sysV stuff. nmbd/asyncdns.c: Fixed signal functs. nmbd/nmbd.c: Fixed isXXX macros & debugs for gcc pedantic compile. passdb/passdb.c: Fixed isXXX macros & debugs for gcc pedantic compile. passdb/smbpassfile.c: Fixed isXXX macros & debugs for gcc pedantic compile. smbd/chgpasswd.c: Fixed isXXX macros & debugs for gcc pedantic compile. smbd/ipc.c: Fixed isXXX macros & debugs for gcc pedantic compile. smbd/nttrans.c: Fixed fsp code path. smbd/password.c: fixed HAVE_YP_GET_DEFAULT_DOMAIN problem. smbd/printing.c: Fixed isXXX macros & debugs for gcc pedantic compile. smbd/reply.c: Fixed isXXX macros & debugs for gcc pedantic compile. smbd/server.c: Fixed isXXX macros & debugs for gcc pedantic compile. smbd/trans2.c: Fixed core dump bug. smbd/uid.c: Fixed isXXX macros & debugs for gcc pedantic compile. Jeremy. (This used to be commit 1b9cbcd02e575dc0a95fa589f720df30a4acc46b) --- source3/web/cgi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 1a9d34d004..20337e0459 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -499,7 +499,7 @@ static void cgi_download(char *file) /* sanitise the filename */ for (i=0;file[i];i++) { - if (!isalnum(file[i]) && !strchr("/.-_", file[i])) { + if (!isalnum((int)file[i]) && !strchr("/.-_", file[i])) { cgi_setup_error("404 File Not Found","", "Illegal character in filename"); } -- cgit From 296038d49800c8657e7cf718f308541630748e7f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 1 Sep 1998 06:01:19 +0000 Subject: fixed a bug in the base64 hanlding that led to auth failures for some passwords with SWAT (This used to be commit edcde70108ab643a29f3e0e0cc97609287da6e87) --- source3/web/cgi.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 20337e0459..ce1038231b 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -431,11 +431,11 @@ decode a base64 string in-place - simple and slow algorithm static void base64_decode(char *s) { char *b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - int bit_offset, byte_offset, idx, i; + int bit_offset, byte_offset, idx, i, n; unsigned char *d = (unsigned char *)s; char *p; - i=0; + n=i=0; while (*s && (p=strchr(b64,*s))) { idx = (int)(p - b64); @@ -444,13 +444,17 @@ static void base64_decode(char *s) d[byte_offset] &= ~((1<<(8-bit_offset))-1); if (bit_offset < 3) { d[byte_offset] |= (idx << (2-bit_offset)); + n = byte_offset+1; } else { d[byte_offset] |= (idx >> (bit_offset-2)); d[byte_offset+1] = 0; d[byte_offset+1] |= (idx << (8-(bit_offset-2))) & 0xFF; + n = byte_offset+2; } s++; i++; } + /* null terminate */ + d[n] = 0; } -- cgit From 18556274139cc5a00593471bd745354d98a35303 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 1 Sep 1998 20:11:54 +0000 Subject: More abstraction of file system data types, to move to a 64 bit file interface for the NT SMB's. Created a new define, SMB_STRUCT_STAT that currently is defined to be struct stat - this wil change to a user defined type containing 64 bit info when the correct wrappers are written for 64 bit stat(), fstat() and lstat() calls. Also changed all sys_xxxx() calls that were previously just wrappers to the same call prefixed by a dos_to_unix() call into dos_xxxx() calls. This makes it explicit when a pathname translation is being done, and when it is not. Now, all sys_xxx() calls are meant to be wrappers to mask OS differences, and not silently converting filenames on the fly. Jeremy. (This used to be commit 28aa182dbffaa4ffd86047e608400de4b26e80eb) --- source3/web/cgi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index ce1038231b..9804f93adf 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -496,7 +496,7 @@ handle a file download ***************************************************************************/ static void cgi_download(char *file) { - struct stat st; + SMB_STRUCT_STAT st; char buf[1024]; int fd, l, i; char *p; -- cgit From b68d65d4bc5de98356863d640ebb3d0985066064 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 2 Sep 1998 02:02:30 +0000 Subject: use /swat/ prefix in both inetd and cgi modes, to enable a static header.html (This used to be commit ddb788c24d043b18506138a7759b8128df1673aa) --- source3/web/cgi.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 9804f93adf..97dac86668 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -622,8 +622,10 @@ void cgi_setup(char *rootdir, int auth_required) *p = 0; } - if (strstr(url+1,"..")==0 && file_exist(url+1, NULL)) { - cgi_download(url+1); + string_sub(url, "/swat/", ""); + + if (strstr(url,"..")==0 && file_exist(url, NULL)) { + cgi_download(url); } printf("HTTP/1.1 200 OK\r\nConnection: close\r\n"); @@ -644,18 +646,6 @@ char *cgi_baseurl(void) return getenv("SCRIPT_NAME"); } -/*************************************************************************** -return the root URL for images etc - ***************************************************************************/ -char *cgi_rooturl(void) -{ - if (baseurl) { - return "/"; - } - return "/swat/"; -} - - /*************************************************************************** return the current pages path info ***************************************************************************/ -- cgit From e9ea36e4d2270bd7d32da12ef6d6e2299641582d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 5 Sep 1998 05:07:05 +0000 Subject: tridge the destroyer returns! prompted by the interpret_security() dead code that Jean-Francois pointed out I added a make target "finddead" that finds potentially dead (ie. unused) code. It spat out 304 function names ... I went through these are deleted many of them, making others static (finddead also reports functions that are used only in the local file). in doing this I have almost certainly deleted some useful code. I may have even prevented compilation with some compile options. I apologise. I decided it was better to get rid of this code now and add back the one or two functions that are needed than to keep all this baggage. So, if I have done a bit too much "destroying" then let me know. Keep the swearing to a minimum :) One bit I didn't do is the ubibt code. Chris, can you look at that? Heaps of unused functions there. Can they be made static? (This used to be commit 2204475c87f3024ea8fd1fbd7385b2def617a46f) --- source3/web/cgi.c | 168 ------------------------------------------------------ 1 file changed, 168 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 97dac86668..874447359b 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -247,174 +247,6 @@ char *cgi_variable(char *name) return NULL; } -/*************************************************************************** -return a particular cgi variable - ***************************************************************************/ -char *cgi_vnum(int i, char **name) -{ - if (i < 0 || i >= num_variables) return NULL; - *name = variables[i].name; - return variables[i].value; -} - -/*************************************************************************** - return the value of a CGI boolean variable. - ***************************************************************************/ -int cgi_boolean(char *name, int def) -{ - char *p = cgi_variable(name); - - if (!p) return def; - - return strcmp(p, "1") == 0; -} - -/*************************************************************************** -like strdup() but quotes < > and & - ***************************************************************************/ -char *quotedup(char *s) -{ - int i, n=0; - int len; - char *ret; - char *d; - - if (!s) return strdup(""); - - len = strlen(s); - - for (i=0;i' || s[i] == '&') - n++; - - ret = malloc(len + n*6 + 1); - - if (!ret) return NULL; - - d = ret; - - for (i=0;i': - safe_strcpy(d, ">", len + n*6 - (d - ret)); - d += 4; - break; - - case '&': - safe_strcpy(d, "&", len + n*6 - (d - ret)); - d += 5; - break; - - default: - *d++ = s[i]; - } - } - - *d = 0; - - return ret; -} - - -/*************************************************************************** -like strdup() but quotes a wide range of characters - ***************************************************************************/ -char *urlquote(char *s) -{ - int i, n=0; - int len; - char *ret; - char *d; - char *qlist = "\"\n\r'&<> \t+;"; - - if (!s) return strdup(""); - - len = strlen(s); - - for (i=0;i Date: Mon, 28 Sep 1998 21:43:48 +0000 Subject: Changes to test in configure if capabilities are enabled on a system. Changes to get Samba to compile cleanly with the IRIX compiler with the options : -fullwarn -woff 1209,1174 (the -woff options are to turn off warnings about unused function parameters and controlling loop expressions being constants). Split prototype generation as we hit a limit in IRIX nawk. Removed "." code in smbd/filename.c (yet again :-). Jeremy. (This used to be commit e0567433bd72aec17bf5a54cc292701095d25f09) --- source3/web/cgi.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 874447359b..bf99a67a04 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -41,7 +41,6 @@ static struct var variables[MAX_VARIABLES]; static int num_variables; static int content_length; static int request_post; -static int request_get; static char *query_string; static char *baseurl; static char *pathinfo; @@ -410,7 +409,6 @@ void cgi_setup(char *rootdir, int auth_required) #endif if (line[0] == '\r' || line[0] == '\n') break; if (strncasecmp(line,"GET ", 4)==0) { - request_get = 1; url = strdup(&line[4]); } else if (strncasecmp(line,"POST ", 5)==0) { request_post = 1; -- cgit From 46fcd85b2dbe32c0f78a9382f8c3e2db92416391 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 26 Oct 1998 10:55:29 +0000 Subject: report ourselves as HTTP/1.0 not HTTP/1.1 (This used to be commit b2210614e810c8e84c9a14a8e32e05f95d92479b) --- source3/web/cgi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index bf99a67a04..38be0de3c6 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -251,7 +251,7 @@ tell a browser about a fatal error in the http processing ***************************************************************************/ static void cgi_setup_error(char *err, char *header, char *info) { - printf("HTTP/1.1 %s\r\n%sConnection: close\r\nContent-Type: text/html\r\n\r\n%s

%s

%s

\r\n", err, header, err, err, info); + printf("HTTP/1.0 %s\r\n%sConnection: close\r\nContent-Type: text/html\r\n\r\n%s

%s

%s

\r\n", err, header, err, err, info); exit(0); } @@ -349,7 +349,7 @@ static void cgi_download(char *file) cgi_setup_error("404 File Not Found","", "The requested file was not found"); } - printf("HTTP/1.1 200 OK\r\n"); + printf("HTTP/1.0 200 OK\r\n"); if ((p=strrchr(file,'.'))) { if (strcmp(p,".gif")==0) { printf("Content-Type: image/gif\r\n"); @@ -458,7 +458,7 @@ void cgi_setup(char *rootdir, int auth_required) cgi_download(url); } - printf("HTTP/1.1 200 OK\r\nConnection: close\r\n"); + printf("HTTP/1.0 200 OK\r\nConnection: close\r\n"); printf("Date: %s\r\n", http_timestring(time(NULL))); baseurl = ""; pathinfo = url+1; -- cgit From 6559aa10d55dd7a71e3b7c7cdee1ff3c7a58ac37 Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Wed, 11 Nov 1998 21:37:44 +0000 Subject: added password change functionality to swat (This used to be commit 06d4026cf1521766b52766193774f1fd8dd70c81) --- source3/web/cgi.c | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 38be0de3c6..a11abe074e 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -44,6 +44,7 @@ static int request_post; static char *query_string; static char *baseurl; static char *pathinfo; +static char *C_user; static void unescape(char *buf) { @@ -311,16 +312,32 @@ static int cgi_handle_authorization(char *line) user = line; pass = p+1; - /* currently only allow connections as root */ - if (strcmp(user,"root")) { - cgi_setup_error("401 Bad Authorization", "", - "incorrect username/password"); - } - + /* Save the users name */ + C_user = strdup(user); return pass_check(user, pass, strlen(pass), NULL, NULL); } +/*************************************************************************** +is this root? + ***************************************************************************/ +BOOL is_root() +{ + if ((C_user) && (strcmp(C_user,"root") == 0)) { + return( True); + } else { + return( False); + } +} + +/*************************************************************************** +return a ptr to the users name + ***************************************************************************/ +char * get_user_name() +{ + return(C_user); +} + /*************************************************************************** handle a file download @@ -390,6 +407,16 @@ void cgi_setup(char *rootdir, int auth_required) } if (getenv("CONTENT_LENGTH") || getenv("REQUEST_METHOD")) { + + char *x; + + /* Save the users name if available */ + if (x = getenv("REMOTE_USER")) { + C_user = strdup(x); + } else { + C_user = ""; + } + /* assume we are running under a real web server */ return; } -- cgit From f49b994aeb987ac87c3c49f35ae1e05a7004f75d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 11 Nov 1998 23:25:51 +0000 Subject: rpc_server/srv_netlog.c: Fixed crash bug with ACB_PWNOTREQ. script/makeyodldocs.sh: Added code to make text docs for non-man page YODL docs. web/cgi.c web/swat.c: SGI compiler warnings fixed. Jeremy. (This used to be commit 80e0f7e1071f032c5004aecb01a91d1397e6a161) --- source3/web/cgi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index a11abe074e..86366d1083 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -321,7 +321,7 @@ static int cgi_handle_authorization(char *line) /*************************************************************************** is this root? ***************************************************************************/ -BOOL is_root() +BOOL is_root(void) { if ((C_user) && (strcmp(C_user,"root") == 0)) { return( True); @@ -333,7 +333,7 @@ BOOL is_root() /*************************************************************************** return a ptr to the users name ***************************************************************************/ -char * get_user_name() +char *get_user_name(void) { return(C_user); } -- cgit From f9584f93be33ee69912708e6402809f47703a5d5 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 11 Nov 1998 23:31:37 +0000 Subject: J.F.'s latest printer fixes plus his gcc -picky fix for web/cgi.c Jeremy. (This used to be commit bd4e2972f50cafd932a5c915cdeeef7eedda07cc) --- source3/web/cgi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 86366d1083..41d099bac9 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -411,7 +411,7 @@ void cgi_setup(char *rootdir, int auth_required) char *x; /* Save the users name if available */ - if (x = getenv("REMOTE_USER")) { + if ((x = getenv("REMOTE_USER"))!=NULL) { C_user = strdup(x); } else { C_user = ""; -- cgit From 01ceb5e2d7b7b4492ed3f2bd1e95fe9b4d68ad47 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 11 Nov 1998 23:47:03 +0000 Subject: changed is_root() to am_root() to prevent clash with variable names. (This used to be commit 52f47b8d2ef5ee64e2f8dcfeb6840071e57904d1) --- source3/web/cgi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 41d099bac9..5415abf6b3 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -321,7 +321,7 @@ static int cgi_handle_authorization(char *line) /*************************************************************************** is this root? ***************************************************************************/ -BOOL is_root(void) +BOOL am_root(void) { if ((C_user) && (strcmp(C_user,"root") == 0)) { return( True); @@ -411,7 +411,7 @@ void cgi_setup(char *rootdir, int auth_required) char *x; /* Save the users name if available */ - if ((x = getenv("REMOTE_USER"))!=NULL) { + if ((x = getenv("REMOTE_USER"))) { C_user = strdup(x); } else { C_user = ""; -- cgit From b0a2e2e77896aeeddbebcd748517dcf4a1230e50 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 12 Nov 1998 03:06:00 +0000 Subject: Added the security changes suggested by Andrew - become the user that authenticated to swat permanently (if not root). Jeremy. (This used to be commit 7d55bf379177a4a448e39577ae0af603d5e958f6) --- source3/web/cgi.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 62 insertions(+), 8 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 5415abf6b3..9b5cf2158c 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -293,29 +293,83 @@ static void base64_decode(char *s) /*************************************************************************** handle a http authentication line ***************************************************************************/ -static int cgi_handle_authorization(char *line) +static BOOL cgi_handle_authorization(char *line) { - char *p, *user, *pass; + char *p, *user, *user_pass; + struct passwd *pass = NULL; + int ret = False; if (strncasecmp(line,"Basic ", 6)) { cgi_setup_error("401 Bad Authorization", "", "Only basic authorization is understood"); + return False; } line += 6; while (line[0] == ' ') line++; base64_decode(line); if (!(p=strchr(line,':'))) { + /* + * Always give the same error so a cracker + * cannot tell why we fail. + */ cgi_setup_error("401 Bad Authorization", "", "username/password must be supplied"); + return False; } *p = 0; user = line; - pass = p+1; + user_pass = p+1; + + /* + * Try and get the user from the UNIX password file. + */ + + if(!(pass = Get_Pwnam(user,False))) { + /* + * Always give the same error so a cracker + * cannot tell why we fail. + */ + cgi_setup_error("401 Bad Authorization", "", + "username/password must be supplied"); + return False; + } + + /* + * Validate the password they have given. + */ + + if((ret = pass_check(user, user_pass, strlen(user_pass), NULL, NULL)) == True) { + + /* + * Password was ok. + */ + + if(pass->pw_uid != 0) { + /* + * We have not authenticated as root, + * become the user *permanently*. + */ + if(!become_user_permanently(pass->pw_uid, pass->pw_gid)) { + /* + * Always give the same error so a cracker + * cannot tell why we fail. + */ + cgi_setup_error("401 Bad Authorization", "", + "username/password must be supplied"); + return False; + } + + /* + * On exit from here we are the authenticated + * user - no way back. + */ + } - /* Save the users name */ - C_user = strdup(user); + /* Save the users name */ + C_user = strdup(user); + } - return pass_check(user, pass, strlen(pass), NULL, NULL); + return ret; } /*************************************************************************** @@ -323,7 +377,7 @@ is this root? ***************************************************************************/ BOOL am_root(void) { - if ((C_user) && (strcmp(C_user,"root") == 0)) { + if (geteuid() == 0) { return( True); } else { return( False); @@ -393,7 +447,7 @@ run as a true cgi program by a web browser or is itself a mini web server ***************************************************************************/ void cgi_setup(char *rootdir, int auth_required) { - int authenticated = 0; + BOOL authenticated = False; char line[1024]; char *url=NULL; char *p; -- cgit From 5be7ae453d588bf520a71723115e5edbd5584d07 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 14 Nov 1998 02:10:55 +0000 Subject: remove code that allows installation via cgi swat will now give an error message if run via cgi (This used to be commit 55377e3cdd5d8428e89b40946f0535b8cf5247ae) --- source3/web/cgi.c | 55 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 35 insertions(+), 20 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 9b5cf2158c..db2cfb4555 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -45,6 +45,7 @@ static char *query_string; static char *baseurl; static char *pathinfo; static char *C_user; +static BOOL inetd_server; static void unescape(char *buf) { @@ -257,6 +258,27 @@ static void cgi_setup_error(char *err, char *header, char *info) } +/*************************************************************************** +tell a browser about a fatal authentication error + ***************************************************************************/ +static void cgi_auth_error(void) +{ + if (inetd_server) { + cgi_setup_error("401 Authorization Required", + "WWW-Authenticate: Basic realm=\"SWAT\"\r\n", + "You must be authenticated to use this service"); + } else { + printf("Content-Type: text/html\r\n"); + + printf("\r\nSWAT\n"); + printf("

Installation Error

\n"); + printf("SWAT must be installed via inetd. It cannot be run as a CGI script

\n"); + printf("\r\n"); + } + exit(0); +} + + /*************************************************************************** decode a base64 string in-place - simple and slow algorithm ***************************************************************************/ @@ -297,7 +319,7 @@ static BOOL cgi_handle_authorization(char *line) { char *p, *user, *user_pass; struct passwd *pass = NULL; - int ret = False; + BOOL ret = False; if (strncasecmp(line,"Basic ", 6)) { cgi_setup_error("401 Bad Authorization", "", @@ -387,7 +409,7 @@ BOOL am_root(void) /*************************************************************************** return a ptr to the users name ***************************************************************************/ -char *get_user_name(void) +char *cgi_user_name(void) { return(C_user); } @@ -460,21 +482,16 @@ void cgi_setup(char *rootdir, int auth_required) "chdir failed - the server is not configured correctly"); } + /* maybe we are running under a web server */ if (getenv("CONTENT_LENGTH") || getenv("REQUEST_METHOD")) { - - char *x; - - /* Save the users name if available */ - if ((x = getenv("REMOTE_USER"))) { - C_user = strdup(x); - } else { - C_user = ""; + if (auth_required) { + cgi_auth_error(); } - - /* assume we are running under a real web server */ return; } + inetd_server = True; + #if CGI_LOGGING f = fopen("/tmp/cgi.log", "a"); if (f) fprintf(f,"\n[Date: %s %s (%s)]\n", @@ -509,9 +526,7 @@ void cgi_setup(char *rootdir, int auth_required) #endif if (auth_required && !authenticated) { - cgi_setup_error("401 Authorization Required", - "WWW-Authenticate: Basic realm=\"root\"\r\n", - "You must be authenticated to use this service"); + cgi_auth_error(); } if (!url) { @@ -551,7 +566,7 @@ return the current pages URL ***************************************************************************/ char *cgi_baseurl(void) { - if (baseurl) { + if (inetd_server) { return baseurl; } return getenv("SCRIPT_NAME"); @@ -563,7 +578,7 @@ return the current pages path info char *cgi_pathinfo(void) { char *r; - if (pathinfo) { + if (inetd_server) { return pathinfo; } r = getenv("PATH_INFO"); @@ -577,7 +592,7 @@ return the hostname of the client ***************************************************************************/ char *cgi_remote_host(void) { - if (baseurl) { + if (inetd_server) { return client_name(1); } return getenv("REMOTE_HOST"); @@ -588,7 +603,7 @@ return the hostname of the client ***************************************************************************/ char *cgi_remote_addr(void) { - if (baseurl) { + if (inetd_server) { return client_addr(1); } return getenv("REMOTE_ADDR"); @@ -600,7 +615,7 @@ return True if the request was a POST ***************************************************************************/ BOOL cgi_waspost(void) { - if (baseurl) { + if (inetd_server) { return request_post; } return strequal(getenv("REQUEST_METHOD"), "POST"); -- cgit From 768761820e8d7481c586c4e0ab4ac7cb36d18c4b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 17 Nov 1998 20:50:07 +0000 Subject: Added the same open()/fopen()/creat()/mmap() -> sys_XXX calls. Tidied up some of the mess (no other word for it). Still doesn't compile cleanly. There are calls with incorrect parameters that don't seem to be doing the right thing. This code still needs surgery :-(. Jeremy. (This used to be commit 18ff93a9abbf68ee8c59c0af3e57c63e4a015dac) --- source3/web/cgi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index db2cfb4555..009244e595 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -437,7 +437,7 @@ static void cgi_download(char *file) cgi_setup_error("404 File Not Found","", "The requested file was not found"); } - fd = open(file,O_RDONLY); + fd = sys_open(file,O_RDONLY,0); if (fd == -1) { cgi_setup_error("404 File Not Found","", "The requested file was not found"); @@ -493,7 +493,7 @@ void cgi_setup(char *rootdir, int auth_required) inetd_server = True; #if CGI_LOGGING - f = fopen("/tmp/cgi.log", "a"); + f = sys_fopen("/tmp/cgi.log", "a"); if (f) fprintf(f,"\n[Date: %s %s (%s)]\n", http_timestring(time(NULL)), client_name(1), client_addr(1)); -- cgit From 42e96160d373885007c4f9cc6e6b5b69e04a998b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 21 Nov 1998 01:41:14 +0000 Subject: make SWAT obey the global "hosts allow" and "hosts deny" settings. any attempt to run swat from a host that is disallowed will give an error. (This used to be commit fe4ef4bbef01aed75807c884249ca8efa5de4140) --- source3/web/cgi.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 009244e595..275bf8999f 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -46,6 +46,7 @@ static char *baseurl; static char *pathinfo; static char *C_user; static BOOL inetd_server; +static BOOL got_request; static void unescape(char *buf) { @@ -253,7 +254,21 @@ tell a browser about a fatal error in the http processing ***************************************************************************/ static void cgi_setup_error(char *err, char *header, char *info) { - printf("HTTP/1.0 %s\r\n%sConnection: close\r\nContent-Type: text/html\r\n\r\n%s

%s

%s

\r\n", err, header, err, err, info); + if (!got_request) { + /* 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) { + break; + } + } + } + + printf("HTTP/1.0 %s\r\n%sConnection: close\r\nContent-Type: text/html\r\n\r\n%s

%s

%s

\r\n\r\n", err, header, err, err, info); + fclose(stdin); + fclose(stdout); exit(0); } @@ -492,6 +507,11 @@ void cgi_setup(char *rootdir, int auth_required) inetd_server = True; + if (!check_access(1, lp_hostsallow(-1), lp_hostsdeny(-1))) { + cgi_setup_error("400 Server Error", "", + "Samba is configured to deny access from this client\n
Check your \"hosts allow\" and \"hosts deny\" options in smb.conf "); + } + #if CGI_LOGGING f = sys_fopen("/tmp/cgi.log", "a"); if (f) fprintf(f,"\n[Date: %s %s (%s)]\n", @@ -507,11 +527,14 @@ void cgi_setup(char *rootdir, int auth_required) #endif if (line[0] == '\r' || line[0] == '\n') break; if (strncasecmp(line,"GET ", 4)==0) { + got_request = True; url = strdup(&line[4]); } else if (strncasecmp(line,"POST ", 5)==0) { + got_request = True; request_post = 1; url = strdup(&line[5]); } else if (strncasecmp(line,"PUT ", 4)==0) { + got_request = True; cgi_setup_error("400 Bad Request", "", "This server does not accept PUT requests"); } else if (strncasecmp(line,"Authorization: ", 15)==0) { -- cgit From 731c7f2ecfe17651506ba05b88358360e4654a37 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sun, 13 Jun 1999 04:14:24 +0000 Subject: Moved code that changes the pw_passwd entry (i.e shadow password and weird unixware stuff) into _Get_Pwnam() to fix a memory allocation bug. Note that the Get_Pwnam() function now returns a const struct passwd * as a hint to other developers not to change entries in the struct passwd. (This used to be commit 36d7cb4ccc42268e8e6a7b783c945d1853624958) --- source3/web/cgi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 275bf8999f..305c173a5d 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -333,7 +333,7 @@ handle a http authentication line static BOOL cgi_handle_authorization(char *line) { char *p, *user, *user_pass; - struct passwd *pass = NULL; + const struct passwd *pass = NULL; BOOL ret = False; if (strncasecmp(line,"Basic ", 6)) { -- cgit From 3db52feb1f3b2c07ce0b06ad4a7099fa6efe3fc7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 13 Dec 1999 13:27:58 +0000 Subject: first pass at updating head branch to be to be the same as the SAMBA_2_0 branch (This used to be commit 453a822a76780063dff23526c35408866d0c0154) --- source3/web/cgi.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 305c173a5d..62a5e71e05 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -333,7 +333,7 @@ handle a http authentication line static BOOL cgi_handle_authorization(char *line) { char *p, *user, *user_pass; - const struct passwd *pass = NULL; + struct passwd *pass = NULL; BOOL ret = False; if (strncasecmp(line,"Basic ", 6)) { @@ -386,20 +386,7 @@ static BOOL cgi_handle_authorization(char *line) * We have not authenticated as root, * become the user *permanently*. */ - if(!become_user_permanently(pass->pw_uid, pass->pw_gid)) { - /* - * Always give the same error so a cracker - * cannot tell why we fail. - */ - cgi_setup_error("401 Bad Authorization", "", - "username/password must be supplied"); - return False; - } - - /* - * On exit from here we are the authenticated - * user - no way back. - */ + become_user_permanently(pass->pw_uid, pass->pw_gid); } /* Save the users name */ @@ -571,9 +558,9 @@ void cgi_setup(char *rootdir, int auth_required) *p = 0; } - string_sub(url, "/swat/", ""); + string_sub(url, "/swat/", "", 0); - if (strstr(url,"..")==0 && file_exist(url, NULL)) { + if (url[0] != '/' && strstr(url,"..")==0 && file_exist(url, NULL)) { cgi_download(url); } -- cgit From cdf223083fed0f35549071d141f6257c4a660ca2 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 11 Apr 2000 07:14:12 +0000 Subject: two minor bugfixes for SCO UnixWare. The first is to catch SIGPIPE so that putmsg() inside their send() doesn't kill swat and the scond is to open /dev/null to replace stdin after we close that (This used to be commit d35bbe56bc9e3e5896b2ebdf33ff6468a0432e1f) --- source3/web/cgi.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 62a5e71e05..b33feb30c2 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -198,6 +198,7 @@ void cgi_load_variables(FILE *f1) } fclose(stdin); + open("/dev/null", O_RDWR); if ((s=query_string) || (s=getenv("QUERY_STRING"))) { for (tok=strtok(s,"&;");tok;tok=strtok(NULL,"&;")) { -- cgit From 2fa922611bf7160e2c1ce80c11b50006448bf98d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 11 Apr 2000 13:55:53 +0000 Subject: finally got sick of the "extern int Client" code and the stupid assumption that we have one socket everywhere while doing so I discovered a few bugs! 1) the clientgen session retarget code if used from smbd or nmbd would cause a crash as it called close_sockets() which closed our main socket! fixed by removing close_sockets() completely - it is unnecessary 2) the caching in client_addr() and client_name() was bogus - it could easily get fooled and give the wrong result. fixed. 3) the retarget could could recurse, allowing an easy denial of service attack on nmbd. fixed. (This used to be commit 5937ab14d222696e40a3fc6f0e6a536f2d7305d3) --- source3/web/cgi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index b33feb30c2..ea73a0f1a7 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -504,7 +504,7 @@ void cgi_setup(char *rootdir, int auth_required) f = sys_fopen("/tmp/cgi.log", "a"); if (f) fprintf(f,"\n[Date: %s %s (%s)]\n", http_timestring(time(NULL)), - client_name(1), client_addr(1)); + get_socket_name(1), get_socket_addr(1)); #endif /* we are a mini-web server. We need to read the request from stdin @@ -604,7 +604,7 @@ return the hostname of the client char *cgi_remote_host(void) { if (inetd_server) { - return client_name(1); + return get_socket_name(1); } return getenv("REMOTE_HOST"); } @@ -615,7 +615,7 @@ return the hostname of the client char *cgi_remote_addr(void) { if (inetd_server) { - return client_addr(1); + return get_socket_addr(1); } return getenv("REMOTE_ADDR"); } -- cgit From e5e43b553ee12af1add965804dc32d63f5fa2f1e Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 1 Sep 2000 02:06:20 +0000 Subject: Fix for swat to return correct MIME type for text files. From "Ron Alexander" (This used to be commit 061e5e50523913a26bc86bd816c4e26a37a832c7) --- source3/web/cgi.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index ea73a0f1a7..4f44d10afc 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -451,6 +451,8 @@ static void cgi_download(char *file) printf("Content-Type: image/gif\r\n"); } else if (strcmp(p,".jpg")==0) { printf("Content-Type: image/jpeg\r\n"); + } else if (strcmp(p,".txt")==0) { + printf("Content-Type: text/plain\r\n"); } else { printf("Content-Type: text/html\r\n"); } -- cgit From 9e70ba71af8253b7b9995b55d9851b73bb58bf78 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 1 Nov 2000 19:43:53 +0000 Subject: Remove CGI logging code. Make username/password lookups take the same time. Jeremy. (This used to be commit 9698f746858f0f2b37ec6494fca990e958d97cb7) --- source3/web/cgi.c | 57 +++++++++++++++++++++++++++---------------------------- 1 file changed, 28 insertions(+), 29 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 4f44d10afc..a99b9d3c5d 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -26,8 +26,6 @@ /* set the expiry on fixed pages */ #define EXPIRY_TIME (60*60*24*7) -#define CGI_LOGGING 0 - #ifdef DEBUG_COMMENTS extern void print_title(char *fmt, ...); #endif @@ -327,7 +325,6 @@ static void base64_decode(char *s) d[n] = 0; } - /*************************************************************************** handle a http authentication line ***************************************************************************/ @@ -336,11 +333,17 @@ static BOOL cgi_handle_authorization(char *line) char *p, *user, *user_pass; struct passwd *pass = NULL; BOOL ret = False; + BOOL got_name = False; + BOOL tested_pass = False; + fstring default_user_lookup; + fstring default_user_pass; + + /* Dummy user lookup to take the same time as a valid user. */ + fstrcpy(default_user_lookup, "zzzz bibble"); + fstrcpy(default_user_pass, "123456789"); if (strncasecmp(line,"Basic ", 6)) { - cgi_setup_error("401 Bad Authorization", "", - "Only basic authorization is understood"); - return False; + goto err; } line += 6; while (line[0] == ' ') line++; @@ -350,9 +353,7 @@ static BOOL cgi_handle_authorization(char *line) * Always give the same error so a cracker * cannot tell why we fail. */ - cgi_setup_error("401 Bad Authorization", "", - "username/password must be supplied"); - return False; + goto err; } *p = 0; user = line; @@ -367,15 +368,16 @@ static BOOL cgi_handle_authorization(char *line) * Always give the same error so a cracker * cannot tell why we fail. */ - cgi_setup_error("401 Bad Authorization", "", - "username/password must be supplied"); - return False; + got_name = True; + goto err; } /* * Validate the password they have given. */ + tested_pass = True; + if((ret = pass_check(user, user_pass, strlen(user_pass), NULL, NULL)) == True) { /* @@ -394,7 +396,20 @@ static BOOL cgi_handle_authorization(char *line) C_user = strdup(user); } - return ret; + err: + + /* Always take the same time. */ + if (!got_name) + Get_Pwnam(default_user_lookup,False); + + if (!tested_pass) + pass_check(default_user_lookup, default_user_pass, + strlen(default_user_pass), NULL, NULL); + + cgi_setup_error("401 Bad Authorization", "", + "username or password incorrect"); + + return False; } /*************************************************************************** @@ -478,9 +493,6 @@ void cgi_setup(char *rootdir, int auth_required) char line[1024]; char *url=NULL; char *p; -#if CGI_LOGGING - FILE *f; -#endif if (chdir(rootdir)) { cgi_setup_error("400 Server Error", "", @@ -502,19 +514,9 @@ void cgi_setup(char *rootdir, int auth_required) "Samba is configured to deny access from this client\n
Check your \"hosts allow\" and \"hosts deny\" options in smb.conf "); } -#if CGI_LOGGING - f = sys_fopen("/tmp/cgi.log", "a"); - if (f) fprintf(f,"\n[Date: %s %s (%s)]\n", - http_timestring(time(NULL)), - get_socket_name(1), get_socket_addr(1)); -#endif - /* we are a mini-web server. We need to read the request from stdin and handle authentication etc */ while (fgets(line, sizeof(line)-1, stdin)) { -#if CGI_LOGGING - if (f) fputs(line, f); -#endif if (line[0] == '\r' || line[0] == '\n') break; if (strncasecmp(line,"GET ", 4)==0) { got_request = True; @@ -534,9 +536,6 @@ void cgi_setup(char *rootdir, int auth_required) } /* ignore all other requests! */ } -#if CGI_LOGGING - if (f) fclose(f); -#endif if (auth_required && !authenticated) { cgi_auth_error(); -- cgit From 0042bf32cc8eddfc0b89799f19bf6cfa05311f99 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 6 Nov 2000 23:08:00 +0000 Subject: Fix to the "known/unknown user" difference patch from "Ron Alexander" . Jeremy. (This used to be commit 7a698c1f23ea8740755c544f631789848a360e42) --- source3/web/cgi.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index a99b9d3c5d..f85ba7bebd 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -394,6 +394,7 @@ static BOOL cgi_handle_authorization(char *line) /* Save the users name */ C_user = strdup(user); + return True; } err: -- cgit From da3053048c3d224a20d6383ac6682d31059cd46c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sun, 11 Mar 2001 00:32:10 +0000 Subject: Merge of new 2.2 code into HEAD (Gerald I hate you :-) :-). Allows new SAMR RPC code to merge with new passdb code. Currently rpcclient doesn't compile. I'm working on it... Jeremy. (This used to be commit 0be41d5158ea4e645e93e8cd30617c038416e549) --- source3/web/cgi.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index f85ba7bebd..e4fda2d99c 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -332,7 +332,6 @@ static BOOL cgi_handle_authorization(char *line) { char *p, *user, *user_pass; struct passwd *pass = NULL; - BOOL ret = False; BOOL got_name = False; BOOL tested_pass = False; fstring default_user_lookup; @@ -378,7 +377,7 @@ static BOOL cgi_handle_authorization(char *line) tested_pass = True; - if((ret = pass_check(user, user_pass, strlen(user_pass), NULL, NULL)) == True) { + if(pass_check(user, user_pass, strlen(user_pass), NULL, NULL) == True) { /* * Password was ok. -- cgit From ed585b91eb2be5bff000c715ff11447d3aaa0cb0 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 17 May 2001 11:45:58 +0000 Subject: - added ability for swat to run under CGI. This needs to be setup very carefully for it not to be a security hole - reran configure (This used to be commit cf4e439a1e0f3fadbe08c474e5b201827866d7f5) --- source3/web/cgi.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index e4fda2d99c..07f84b2a61 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -292,6 +292,36 @@ static void cgi_auth_error(void) exit(0); } +/*************************************************************************** +authenticate when we are running as a CGI + ***************************************************************************/ +static void cgi_web_auth(void) +{ + char *user = getenv("REMOTE_USER"); + struct passwd *pwd; + char *head = "Content-Type: text/html\r\n\r\n

SWAT installation Error

\n"; + char *tail = "\r\n"; + + if (!user) { + printf("%sREMOTE_USER not set. Not authenticated by web server.
%s\n", + head, tail); + exit(0); + } + + pwd = getpwnam(user); + if (!pwd) { + printf("%sCannot find user %s
%s\n", head, user, tail); + exit(0); + } + + setuid(0); + setuid(pwd->pw_uid); + if (geteuid() != pwd->pw_uid || getuid() != pwd->pw_uid) { + printf("%sFailed to become user %s - uid=%d/%d
%s\n", + head, user, (int)geteuid(), (int)getuid(), tail); + exit(0); + } +} /*************************************************************************** decode a base64 string in-place - simple and slow algorithm @@ -483,6 +513,8 @@ static void cgi_download(char *file) } + + /*************************************************************************** setup the cgi framework, handling the possability that this program is either run as a true cgi program by a web browser or is itself a mini web server @@ -502,7 +534,7 @@ void cgi_setup(char *rootdir, int auth_required) /* maybe we are running under a web server */ if (getenv("CONTENT_LENGTH") || getenv("REQUEST_METHOD")) { if (auth_required) { - cgi_auth_error(); + cgi_web_auth(); } return; } -- cgit From 527e824293ee934ca5da0ef5424efe5ab7757248 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 4 Jul 2001 07:36:09 +0000 Subject: strchr and strrchr are macros when compiling with optimisation in gcc, so we can't redefine them. damn. (This used to be commit c41fc06376d1a2b83690612304e85010b5e5f3cf) --- source3/web/cgi.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 07f84b2a61..af9d2ea8f6 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -50,12 +50,12 @@ static void unescape(char *buf) { char *p=buf; - while ((p=strchr(p,'+'))) + while ((p=strchr_m(p,'+'))) *p = ' '; p = buf; - while (p && *p && (p=strchr(p,'%'))) { + while (p && *p && (p=strchr_m(p,'%'))) { int c1 = p[1]; int c2 = p[2]; @@ -104,7 +104,7 @@ static char *grab_line(FILE *f, int *cl) if (c == '\r') continue; - if (strchr("\n&", c)) break; + if (strchr_m("\n&", c)) break; ret[i++] = c; @@ -160,7 +160,7 @@ void cgi_load_variables(FILE *f1) ((s=getenv("REQUEST_METHOD")) && strcasecmp(s,"POST")==0))) { while (len && (line=grab_line(f, &len))) { - p = strchr(line,'='); + p = strchr_m(line,'='); if (!p) continue; *p = 0; @@ -200,7 +200,7 @@ void cgi_load_variables(FILE *f1) if ((s=query_string) || (s=getenv("QUERY_STRING"))) { for (tok=strtok(s,"&;");tok;tok=strtok(NULL,"&;")) { - p = strchr(tok,'='); + p = strchr_m(tok,'='); if (!p) continue; *p = 0; @@ -335,7 +335,7 @@ static void base64_decode(char *s) n=i=0; - while (*s && (p=strchr(b64,*s))) { + while (*s && (p=strchr_m(b64,*s))) { idx = (int)(p - b64); byte_offset = (i*6)/8; bit_offset = (i*6)%8; @@ -377,7 +377,7 @@ static BOOL cgi_handle_authorization(char *line) line += 6; while (line[0] == ' ') line++; base64_decode(line); - if (!(p=strchr(line,':'))) { + if (!(p=strchr_m(line,':'))) { /* * Always give the same error so a cracker * cannot tell why we fail. @@ -475,7 +475,7 @@ static void cgi_download(char *file) /* sanitise the filename */ for (i=0;file[i];i++) { - if (!isalnum((int)file[i]) && !strchr("/.-_", file[i])) { + if (!isalnum((int)file[i]) && !strchr_m("/.-_", file[i])) { cgi_setup_error("404 File Not Found","", "Illegal character in filename"); } @@ -491,7 +491,7 @@ static void cgi_download(char *file) "The requested file was not found"); } printf("HTTP/1.0 200 OK\r\n"); - if ((p=strrchr(file,'.'))) { + if ((p=strrchr_m(file,'.'))) { if (strcmp(p,".gif")==0) { printf("Content-Type: image/gif\r\n"); } else if (strcmp(p,".jpg")==0) { @@ -579,15 +579,15 @@ void cgi_setup(char *rootdir, int auth_required) } /* trim the URL */ - if ((p = strchr(url,' ')) || (p=strchr(url,'\t'))) { + if ((p = strchr_m(url,' ')) || (p=strchr_m(url,'\t'))) { *p = 0; } - while (*url && strchr("\r\n",url[strlen(url)-1])) { + while (*url && strchr_m("\r\n",url[strlen(url)-1])) { url[strlen(url)-1] = 0; } /* anything following a ? in the URL is part of the query string */ - if ((p=strchr(url,'?'))) { + if ((p=strchr_m(url,'?'))) { query_string = p+1; *p = 0; } -- cgit From 5b8d230e39cedda6117cf8528065cbab45bdd835 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sun, 8 Jul 2001 14:10:30 +0000 Subject: This removes unused paramaters from various authtication functions, and should not change behaviour. This should make my later diffs smaller, where I actualy start cleaning up this mess... Andrew Bartlett (This used to be commit 04f090c224bb7ac3b53c430a591fce1fc939a81c) --- source3/web/cgi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index af9d2ea8f6..e47514904b 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -407,7 +407,7 @@ static BOOL cgi_handle_authorization(char *line) tested_pass = True; - if(pass_check(user, user_pass, strlen(user_pass), NULL, NULL) == True) { + if(pass_check(user, user_pass, strlen(user_pass), NULL) == True) { /* * Password was ok. @@ -434,7 +434,7 @@ static BOOL cgi_handle_authorization(char *line) if (!tested_pass) pass_check(default_user_lookup, default_user_pass, - strlen(default_user_pass), NULL, NULL); + strlen(default_user_pass), NULL); cgi_setup_error("401 Bad Authorization", "", "username or password incorrect"); -- cgit From 2f844bf447a98b802daa4b8d552ea4530e7f6108 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 8 Aug 2001 16:54:16 +0000 Subject: Change all realloc() statements to Realloc() (ecxept for tdb.c) changed some code to exploit the fact that Realloc(NULL, size) == malloc(size) fixed some possible mem leaks, or seg faults. thanks to andreas moroder (mallocs not checked in client/client.c, client/smbumount.c) (This used to be commit 7f33c01688b825ab2fa9bbb2730bff4f2fa352be) --- source3/web/cgi.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index e47514904b..74e9969ff4 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -85,16 +85,23 @@ static void unescape(char *buf) static char *grab_line(FILE *f, int *cl) { - char *ret; + char *ret = NULL; int i = 0; int len = 1024; - ret = (char *)malloc(len); - if (!ret) return NULL; - - while ((*cl)) { - int c = fgetc(f); + int c; + + if (i == len) { + char *ret2; + if (len == 0) len = 1024; + else len *= 2; + ret2 = (char *)Realloc(ret, len*2); + if (!ret2) return ret; + ret = ret2; + } + + c = fgetc(f); (*cl)--; if (c == EOF) { @@ -108,13 +115,6 @@ static char *grab_line(FILE *f, int *cl) ret[i++] = c; - if (i == len-1) { - char *ret2; - ret2 = (char *)realloc(ret, len*2); - if (!ret2) return ret; - len *= 2; - ret = ret2; - } } -- cgit From 9644bf74bd90ef5b9c016434408be1acaa311978 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 12 Aug 2001 09:18:31 +0000 Subject: it was half committed last time, thanks to Hasch@t-online.de (Juergen Hasch) for spotting that. (This used to be commit a2a4d4e6286c2127b6f8e32fc97b96dabd7cdb40) --- source3/web/cgi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 74e9969ff4..651cd3d8c3 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -87,7 +87,7 @@ static char *grab_line(FILE *f, int *cl) { char *ret = NULL; int i = 0; - int len = 1024; + int len = 0; while ((*cl)) { int c; @@ -96,7 +96,7 @@ static char *grab_line(FILE *f, int *cl) char *ret2; if (len == 0) len = 1024; else len *= 2; - ret2 = (char *)Realloc(ret, len*2); + ret2 = (char *)Realloc(ret, len); if (!ret2) return ret; ret = ret2; } -- cgit From b30e75692d68233448b3ad3d7ddd4b4ac423d3ab Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 10 Sep 2001 11:08:57 +0000 Subject: replaced stdio in many parts of samba with a XFILE. XFILE is a cut-down replacemnt of stdio that doesn't suffer from the 8-bit filedescriptor limit that we hit with nasty consequences on some systems I would eventually prefer us to have a configure test to see if we need to replace stdio, but for now this code needs to be tested widely so I'm enabling it by default. (This used to be commit 1af8bf34f1caa3e7ec312d8109c07d32a945a448) --- source3/web/cgi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 651cd3d8c3..88f4d3f36f 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -149,9 +149,9 @@ void cgi_load_variables(FILE *f1) len = content_length; } } else { - fseek(f, 0, SEEK_END); - len = ftell(f); - fseek(f, 0, SEEK_SET); + struct stat st; + fstat(fileno(f), &st); + len = st.st_size; } -- cgit From c0ef0e113e8d3117891b4b137f660ca3c4c6b1f0 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 17 Sep 2001 11:48:29 +0000 Subject: move to SAFE_FREE() (This used to be commit 67db8f03c5c9e81e11b5f3276b50ee23e09a2659) --- source3/web/cgi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 88f4d3f36f..3547379084 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -168,7 +168,7 @@ void cgi_load_variables(FILE *f1) variables[num_variables].name = strdup(line); variables[num_variables].value = strdup(p+1); - free(line); + SAFE_FREE(line); if (!variables[num_variables].name || !variables[num_variables].value) -- cgit From 6adafe50d4a9a75a6fe1f666232e0af1ac717513 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 19 Sep 2001 05:26:11 +0000 Subject: Remove the ugly hacks to get around the Get_Pwnam() calls in pass_check.c by simply not doing Get_Pwnam() calls in pass_check.c We now make *one* sys_getpnam() call in cgi.c and we always call PAM no matter what it returns. We also no longer run the password cracker for these logins. The truly parinod will note the slight difference in call paths, in that we only call crypt for valid password structs (if not --with-pam). The truly parinoid don't run SWAT either, so I don't think this is an issue. Andrew Bartlett (This used to be commit 9020d884935243f28c19cedc88f076f0709e12cb) --- source3/web/cgi.c | 71 +++++++++++++++++++------------------------------------ 1 file changed, 24 insertions(+), 47 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 3547379084..b4356af46e 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -362,14 +362,6 @@ static BOOL cgi_handle_authorization(char *line) { char *p, *user, *user_pass; struct passwd *pass = NULL; - BOOL got_name = False; - BOOL tested_pass = False; - fstring default_user_lookup; - fstring default_user_pass; - - /* Dummy user lookup to take the same time as a valid user. */ - fstrcpy(default_user_lookup, "zzzz bibble"); - fstrcpy(default_user_pass, "123456789"); if (strncasecmp(line,"Basic ", 6)) { goto err; @@ -387,55 +379,40 @@ static BOOL cgi_handle_authorization(char *line) *p = 0; user = line; user_pass = p+1; - + /* * Try and get the user from the UNIX password file. */ - - if(!(pass = Get_Pwnam(user,False))) { - /* - * Always give the same error so a cracker - * cannot tell why we fail. - */ - got_name = True; - goto err; - } - + + pass = sys_getpwnam(user); + /* * Validate the password they have given. */ - - tested_pass = True; - - if(pass_check(user, user_pass, strlen(user_pass), NULL) == True) { - - /* - * Password was ok. - */ - - if(pass->pw_uid != 0) { + + if (pass_check(pass, user, user_pass, + strlen(user_pass), NULL, False)) { + + if (pass) { /* - * We have not authenticated as root, - * become the user *permanently*. + * Password was ok. */ - become_user_permanently(pass->pw_uid, pass->pw_gid); + + if(pass->pw_uid != 0) { + /* + * We have not authenticated as root, + * become the user *permanently*. + */ + become_user_permanently(pass->pw_uid, pass->pw_gid); + } + + /* Save the users name */ + C_user = strdup(user); + return True; } - - /* Save the users name */ - C_user = strdup(user); - return True; } - - err: - - /* Always take the same time. */ - if (!got_name) - Get_Pwnam(default_user_lookup,False); - - if (!tested_pass) - pass_check(default_user_lookup, default_user_pass, - strlen(default_user_pass), NULL); - + +err: cgi_setup_error("401 Bad Authorization", "", "username or password incorrect"); -- cgit From fa6713bf8b121a45e59235786eec3cee29e92e67 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 20 Sep 2001 13:15:35 +0000 Subject: Move pass_check.c over to NTSTATUS, allowing full NTSTATUS from PAM to wire! Add the ability for swat to run in non-root-mode (ie non-root from inetd). - we still need some of the am_root() calls fixed however. (This used to be commit 2c2317c56ee13abdbdbc866363c3b52dab826e3c) --- source3/web/cgi.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index b4356af46e..a8af9b2722 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -390,7 +390,7 @@ static BOOL cgi_handle_authorization(char *line) * Validate the password they have given. */ - if (pass_check(pass, user, user_pass, + if NT_STATUS_IS_OK(pass_check(pass, user, user_pass, strlen(user_pass), NULL, False)) { if (pass) { @@ -398,13 +398,7 @@ static BOOL cgi_handle_authorization(char *line) * Password was ok. */ - if(pass->pw_uid != 0) { - /* - * We have not authenticated as root, - * become the user *permanently*. - */ - become_user_permanently(pass->pw_uid, pass->pw_gid); - } + become_user_permanently(pass->pw_uid, pass->pw_gid); /* Save the users name */ C_user = strdup(user); @@ -508,6 +502,9 @@ void cgi_setup(char *rootdir, int auth_required) "chdir failed - the server is not configured correctly"); } + /* Handle the possability we might be running as non-root */ + sec_init(); + /* maybe we are running under a web server */ if (getenv("CONTENT_LENGTH") || getenv("REQUEST_METHOD")) { if (auth_required) { -- cgit From 1fcc9e1f6d2a6ee3f170055692cbfbe7432cf7ee Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 24 Sep 2001 04:49:14 +0000 Subject: convert all POST variables from display to unix charset (This used to be commit cd6478ad9890949d0ef34a7078ec5518debe4a3c) --- source3/web/cgi.c | 50 ++++++++++++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 22 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index a8af9b2722..0227cd07a6 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -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("\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("\n"); -#endif - return; - } - fclose(stdin); open("/dev/null", O_RDWR); @@ -228,6 +214,26 @@ void cgi_load_variables(FILE *f1) #ifdef DEBUG_COMMENTS printf("\n"); #endif + + /* variables from the client are in display charset - convert them + to our internal charset before use */ + for (i=0;i Date: Mon, 24 Sep 2001 06:02:31 +0000 Subject: fixed bug in POST var handling (This used to be commit 73f10d3ef6de2dbcb23f93ef93eb9e7053ebf26b) --- source3/web/cgi.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 0227cd07a6..7b12bf5748 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -221,19 +221,17 @@ void cgi_load_variables(void) pstring dest; convert_string(CH_DISPLAY, CH_UNIX, - variables[i].name, -1, + variables[i].name, strlen(variables[i].name), dest, sizeof(dest)); free(variables[i].name); variables[i].name = strdup(dest); convert_string(CH_DISPLAY, CH_UNIX, - variables[i].value, -1, + variables[i].value, strlen(variables[i].name), dest, sizeof(dest)); free(variables[i].value); variables[i].value = strdup(dest); } - - } -- cgit From 79b5b1aebf9f59e4de19c9b52f473cfd06d1fd0c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 24 Sep 2001 06:24:14 +0000 Subject: fixed a silly off by 1 bug (This used to be commit e558ab6ac8930e3393291fe12289ad43175b8a1d) --- source3/web/cgi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 7b12bf5748..939b8f94cd 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -221,13 +221,13 @@ void cgi_load_variables(void) pstring dest; convert_string(CH_DISPLAY, CH_UNIX, - variables[i].name, strlen(variables[i].name), + 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, strlen(variables[i].name), + variables[i].value, -1, dest, sizeof(dest)); free(variables[i].value); variables[i].value = strdup(dest); -- cgit From 96db4b1ba3a48f50b80b2cfbf0b940e073b7843c Mon Sep 17 00:00:00 2001 From: Motonobu Takahashi Date: Mon, 24 Sep 2001 15:55:09 +0000 Subject: Added SWAT i18n feature: TO enable configure with --with-i18n-swat to support this gettext is integrated and a new directories name "po" and "intl" are created. now these languages are supported: en - English (default) ja - Japanese po - Polish tr - Turkish To add your language, to create ${your_language}.po by translating source/po/en.po into your language is needed. some of html and image files of various language version are not included yet, though message catalogue files are installed. you need to copy files manually under ${swatdir}/lang/$ln/{help,images,included,using_samba} And also added a option to intall manual pages: of various lang version To enable configure with --with-manlangs but manual pages themself are not included yet. (This used to be commit 486b79a6fc4ba20a751aab544bd0f7ccff2b3d19) --- source3/web/cgi.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 939b8f94cd..d2b30c49e9 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -20,6 +20,7 @@ #include "includes.h" #include "smb.h" +#include "webintl.h" #define MAX_VARIABLES 10000 @@ -447,6 +448,7 @@ static void cgi_download(char *file) char buf[1024]; int fd, l, i; char *p; + int nLangDesc; /* sanitise the filename */ for (i=0;file[i];i++) { @@ -460,7 +462,11 @@ static void cgi_download(char *file) cgi_setup_error("404 File Not Found","", "The requested file was not found"); } +#if I18N_SWAT + fd = sys_open(ln_get_pref_file(file, &st, &nLangDesc),O_RDONLY,0); +#else fd = sys_open(file,O_RDONLY,0); +#endif if (fd == -1) { cgi_setup_error("404 File Not Found","", "The requested file was not found"); @@ -478,7 +484,10 @@ static void cgi_download(char *file) } } printf("Expires: %s\r\n", http_timestring(time(NULL)+EXPIRY_TIME)); - +#if I18N_SWAT + if(ln_get_lang(nLangDesc)) + printf("Content-Language: %s\r\n", ln_get_lang(nLangDesc)); +#endif 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); @@ -509,6 +518,11 @@ void cgi_setup(char *rootdir, int auth_required) /* Handle the possability we might be running as non-root */ sec_init(); +#if I18N_SWAT + if(getenv("HTTP_ACCEPT_LANGUAGE")) /* if running as a cgi program */ + ln_negotiate_language(getenv("HTTP_ACCEPT_LANGUAGE")); +#endif + /* maybe we are running under a web server */ if (getenv("CONTENT_LENGTH") || getenv("REQUEST_METHOD")) { if (auth_required) { @@ -543,6 +557,10 @@ void cgi_setup(char *rootdir, int auth_required) authenticated = cgi_handle_authorization(&line[15]); } else if (strncasecmp(line,"Content-Length: ", 16)==0) { content_length = atoi(&line[16]); +#if I18N_SWAT + } else if (strncasecmp(line,"Accept-Language: ", 17)==0) { + ln_negotiate_language(&line[17]); +#endif } /* ignore all other requests! */ } -- cgit From 6ddcd8a3bcef32694d9d753ff91cced71f5ca3a8 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 25 Sep 2001 20:21:21 +0000 Subject: Fixup passdb stuff to add new nisplus and ldap backends. Jeremy. (This used to be commit 611bf806d569b70edabbc04a2f5408142370a550) --- source3/web/cgi.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index d2b30c49e9..caba28396f 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -448,7 +448,9 @@ static void cgi_download(char *file) char buf[1024]; int fd, l, i; char *p; +#if I18N_SWAT int nLangDesc; +#endif /* sanitise the filename */ for (i=0;file[i];i++) { -- cgit From a689b24db14436ab1faa2f2f79b9f27b777b1fdb Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 14 Oct 2001 12:10:29 +0000 Subject: the next step in the intl changeover. This should get us compiling agian, and also completes the switch to lang_tdb.c. SWAT should now work with a po file in the lib/ directory also removed useless SYSLOG defines in many files (This used to be commit 5296b20ad85d7519c870768455cb4d8df048c55a) --- source3/web/cgi.c | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index caba28396f..e1b26d99b4 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -20,7 +20,6 @@ #include "includes.h" #include "smb.h" -#include "webintl.h" #define MAX_VARIABLES 10000 @@ -138,7 +137,7 @@ void cgi_load_variables(void) #ifdef DEBUG_COMMENTS char dummy[100]=""; print_title(dummy); - printf("\n",__FILE__); + d_printf("\n",__FILE__); #endif if (!content_length) { @@ -270,7 +269,7 @@ static void cgi_setup_error(char *err, char *header, char *info) } } - printf("HTTP/1.0 %s\r\n%sConnection: close\r\nContent-Type: text/html\r\n\r\n%s

%s

%s

\r\n\r\n", err, header, err, err, info); + d_printf("HTTP/1.0 %s\r\n%sConnection: close\r\nContent-Type: text/html\r\n\r\n%s

%s

%s

\r\n\r\n", err, header, err, err, info); fclose(stdin); fclose(stdout); exit(0); @@ -448,9 +447,7 @@ static void cgi_download(char *file) char buf[1024]; int fd, l, i; char *p; -#if I18N_SWAT - int nLangDesc; -#endif + char *lang; /* sanitise the filename */ for (i=0;file[i];i++) { @@ -464,11 +461,8 @@ static void cgi_download(char *file) cgi_setup_error("404 File Not Found","", "The requested file was not found"); } -#if I18N_SWAT - fd = sys_open(ln_get_pref_file(file, &st, &nLangDesc),O_RDONLY,0); -#else - fd = sys_open(file,O_RDONLY,0); -#endif + + fd = web_open(file,O_RDONLY,0); if (fd == -1) { cgi_setup_error("404 File Not Found","", "The requested file was not found"); @@ -486,10 +480,12 @@ static void cgi_download(char *file) } } printf("Expires: %s\r\n", http_timestring(time(NULL)+EXPIRY_TIME)); -#if I18N_SWAT - if(ln_get_lang(nLangDesc)) - printf("Content-Language: %s\r\n", ln_get_lang(nLangDesc)); -#endif + + lang = lang_tdb_current(); + if (lang) { + printf("Content-Language: %s\r\n", lang); + } + 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); @@ -511,6 +507,7 @@ void cgi_setup(char *rootdir, int auth_required) char line[1024]; char *url=NULL; char *p; + char *lang; if (chdir(rootdir)) { cgi_setup_error("400 Server Error", "", @@ -520,10 +517,10 @@ void cgi_setup(char *rootdir, int auth_required) /* Handle the possability we might be running as non-root */ sec_init(); -#if I18N_SWAT - if(getenv("HTTP_ACCEPT_LANGUAGE")) /* if running as a cgi program */ - ln_negotiate_language(getenv("HTTP_ACCEPT_LANGUAGE")); -#endif + if ((lang=getenv("HTTP_ACCEPT_LANGUAGE"))) { + /* if running as a cgi program */ + web_set_lang(lang); + } /* maybe we are running under a web server */ if (getenv("CONTENT_LENGTH") || getenv("REQUEST_METHOD")) { @@ -559,10 +556,8 @@ void cgi_setup(char *rootdir, int auth_required) authenticated = cgi_handle_authorization(&line[15]); } else if (strncasecmp(line,"Content-Length: ", 16)==0) { content_length = atoi(&line[16]); -#if I18N_SWAT } else if (strncasecmp(line,"Accept-Language: ", 17)==0) { - ln_negotiate_language(&line[17]); -#endif + web_set_lang(&line[17]); } /* ignore all other requests! */ } -- cgit From a1b9de0b9872b91574e75bb360d49b887a072389 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Mon, 19 Nov 2001 02:48:23 +0000 Subject: Fix const warning. Doxyfy comment. (This used to be commit 91e07a7fdc47b2baf42fc06e77d1e1d883111668) --- source3/web/cgi.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index e1b26d99b4..9a029684ce 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -497,11 +497,14 @@ static void cgi_download(char *file) -/*************************************************************************** -setup the cgi framework, handling the possability that this program is either -run as a true cgi program by a web browser or is itself a mini web server - ***************************************************************************/ -void cgi_setup(char *rootdir, int auth_required) +/** + * @brief Setup the CGI framework. + * + * Setup the cgi framework, handling the possibility that this program + * is either run as a true CGI program with a gateway to a web server, or + * is itself a mini web server. + **/ +void cgi_setup(const char *rootdir, int auth_required) { BOOL authenticated = False; char line[1024]; -- cgit From c311d24ce32d2a8aa244f126bcec67ec03549727 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 17 Jan 2002 08:45:58 +0000 Subject: A nice *big* change to the fundemental way we do things. Samba (ab)uses the returns from getpwnam() a lot - in particular it keeps them around for a long time - often past the next call... This adds a getpwnam_alloc and a getpwuid_alloc to the collection. These function as expected, returning a malloced structure that can be free()ed with passwd_free(&passwd). This patch also cuts down on the number of calls to getpwnam - mostly by taking advantage of the fact that the passdb interface is already case-insensiteve. With this patch most of the recursive cases have been removed (that I know of) and the problems are reduced further by not using the sys_ interface in the new code. This means that pointers to the cache won't be affected. (This is a tempoary HACK, I intend to kill the password cache entirly). The only change I'm a little worried about is the change to rpc_server/srv_samr_nt.c for private groups. In this case we are getting groups from the new group mapping DB. Do we still need to check for private groups? I've toned down the check to a case sensitve match with the new code, but we might be able to kill it entirly. I've also added a make_modifyable_passwd() function, that copies a passwd struct into the form that the old sys_getpw* code provided. As far as I can tell this is only actually used in the pass_check.c crazies, where I moved the final 'special case' for shadow passwords (out of _Get_Pwnam()). The matching case for getpwent() is dealt with already, in lib/util_getent.c Also included in here is a small change to register the [homes] share at vuid creation rather than just in one varient of the session setup. (This picks up the SPNEGO cases). The home directory is now stored on the vuid, and I am hoping this might provide a saner way to do %H substitions. TODO: Kill off remaining Get_Pwnam_Modify calls (they are not needed), change the remaining sys_getpwnam() callers to use getpwnam_alloc() and move Get_Pwnam to return an allocated struct. Andrew Bartlett (This used to be commit 1d86c7f94230bc53daebd4d2cd829da6292e05da) --- source3/web/cgi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 9a029684ce..a8cb543dfb 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -388,7 +388,7 @@ static BOOL cgi_handle_authorization(char *line) * Try and get the user from the UNIX password file. */ - pass = sys_getpwnam(user); + pass = getpwnam_alloc(user); /* * Validate the password they have given. @@ -406,6 +406,7 @@ static BOOL cgi_handle_authorization(char *line) /* Save the users name */ C_user = strdup(user); + passwd_free(&pass); return True; } } @@ -414,6 +415,7 @@ err: cgi_setup_error("401 Bad Authorization", "", "username or password incorrect"); + passwd_free(&pass); return False; } -- cgit From e1793bde612c499d08c6ecb9fdecb630a9cdf04d Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 21 Jan 2002 00:47:02 +0000 Subject: getpwnam -> getpwnam_alloc (This used to be commit f8208458b3ac05743932d96e4d0a919adc0d9e55) --- source3/web/cgi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index a8cb543dfb..e785ce92d8 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -312,7 +312,7 @@ static void cgi_web_auth(void) exit(0); } - pwd = getpwnam(user); + pwd = getpwnam_alloc(user); if (!pwd) { printf("%sCannot find user %s
%s\n", head, user, tail); exit(0); @@ -325,6 +325,7 @@ static void cgi_web_auth(void) head, user, (int)geteuid(), (int)getuid(), tail); exit(0); } + passwd_free(&pwd); } /*************************************************************************** -- cgit From e90b65284812aaa5ff9e9935ce9bbad7791cbbcd Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 15 Jul 2002 10:35:28 +0000 Subject: updated the 3.0 branch from the head branch - ready for alpha18 (This used to be commit 03ac082dcb375b6f3ca3d810a6a6367542bc23ce) --- source3/web/cgi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index e785ce92d8..7415fbe3f1 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -19,7 +19,7 @@ #include "includes.h" -#include "smb.h" +#include "../web/swat_proto.h" #define MAX_VARIABLES 10000 -- cgit From 8c2a62c55566337a5cbb963ccef59e279a43af7d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 9 Oct 2002 19:47:04 +0000 Subject: Use memmove when copies can overlap. Spotted by SUGIOKA Toshinobu . Jeremy. (This used to be commit 0ab08186f419a09e15f1ab7db621d429b1a3f994) --- source3/web/cgi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 7415fbe3f1..684086f61e 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -77,7 +77,7 @@ static void unescape(char *buf) *p = (c1<<4) | c2; - memcpy(p+1, p+3, strlen(p+3)+1); + memmove(p+1, p+3, strlen(p+3)+1); p++; } } -- cgit From 35ac9d287f000c27dc864789b341bebe7acb4c74 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 26 Oct 2002 02:20:59 +0000 Subject: Try to catch up on the code I've put into HEAD that should be in 3.0: - vorlan's hosts allow with DNS names patch - use x_fileno() in debug.c, not the struct directly. - check for server timeout on password change (was reporting success) - better error/status loggin in both the pam_winbind client and winbindd_pam server code. - (pdb_ldap) don't set the ldap version twice - we do it on every bind anyway. (This used to be commit 9fa1863d8e7788eda83911ca2610754486b33069) --- source3/web/cgi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 684086f61e..c9cb78f6f1 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -636,7 +636,7 @@ return the hostname of the client char *cgi_remote_host(void) { if (inetd_server) { - return get_socket_name(1); + return get_socket_name(1,False); } return getenv("REMOTE_HOST"); } -- cgit From 634c54310c92c48dd4eceec602e230a021bdcfc5 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 3 Jan 2003 08:28:12 +0000 Subject: Merge from HEAD - make Samba compile with -Wwrite-strings without additional warnings. (Adds a lot of const). Andrew Bartlett (This used to be commit 3a7458f9472432ef12c43008414925fd1ce8ea0c) --- source3/web/cgi.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index c9cb78f6f1..1cec580c67 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -40,7 +40,7 @@ static int num_variables; static int content_length; static int request_post; static char *query_string; -static char *baseurl; +static const char *baseurl; static char *pathinfo; static char *C_user; static BOOL inetd_server; @@ -242,7 +242,7 @@ void cgi_load_variables(void) browser. Also doesn't allow for variables[] containing multiple variables with the same name and the same or different values. ***************************************************************************/ -char *cgi_variable(char *name) +const char *cgi_variable(const char *name) { int i; @@ -255,7 +255,7 @@ char *cgi_variable(char *name) /*************************************************************************** tell a browser about a fatal error in the http processing ***************************************************************************/ -static void cgi_setup_error(char *err, char *header, char *info) +static void cgi_setup_error(const char *err, const char *header, const char *info) { if (!got_request) { /* damn browsers don't like getting cut off before they give a request */ @@ -301,10 +301,10 @@ authenticate when we are running as a CGI ***************************************************************************/ static void cgi_web_auth(void) { - char *user = getenv("REMOTE_USER"); + const char *user = getenv("REMOTE_USER"); struct passwd *pwd; - char *head = "Content-Type: text/html\r\n\r\n

SWAT installation Error

\n"; - char *tail = "\r\n"; + const char *head = "Content-Type: text/html\r\n\r\n

SWAT installation Error

\n"; + const char *tail = "\r\n"; if (!user) { printf("%sREMOTE_USER not set. Not authenticated by web server.
%s\n", @@ -333,7 +333,7 @@ decode a base64 string in-place - simple and slow algorithm ***************************************************************************/ static void base64_decode(char *s) { - char *b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + const char *b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; int bit_offset, byte_offset, idx, i, n; unsigned char *d = (unsigned char *)s; char *p; @@ -607,7 +607,7 @@ void cgi_setup(const char *rootdir, int auth_required) /*************************************************************************** return the current pages URL ***************************************************************************/ -char *cgi_baseurl(void) +const char *cgi_baseurl(void) { if (inetd_server) { return baseurl; @@ -618,7 +618,7 @@ char *cgi_baseurl(void) /*************************************************************************** return the current pages path info ***************************************************************************/ -char *cgi_pathinfo(void) +const char *cgi_pathinfo(void) { char *r; if (inetd_server) { -- cgit From 99cdb462083381c88689a4e698ca48b6ed4cf5ac Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 15 Jan 2003 18:57:41 +0000 Subject: *lots of small merges form HEAD *sync up configure.in *don't build torture tools in make all *make sure to remove torture tools as part of make clean (This used to be commit 0fb724b3216eeeb97e61ff12755ca3a31bcad6ef) --- source3/web/cgi.c | 45 ++++----------------------------------------- 1 file changed, 4 insertions(+), 41 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 1cec580c67..018dd3602f 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -46,43 +46,6 @@ static char *C_user; static BOOL inetd_server; static BOOL got_request; -static void unescape(char *buf) -{ - char *p=buf; - - while ((p=strchr_m(p,'+'))) - *p = ' '; - - p = buf; - - while (p && *p && (p=strchr_m(p,'%'))) { - int c1 = p[1]; - int c2 = p[2]; - - if (c1 >= '0' && c1 <= '9') - c1 = c1 - '0'; - else if (c1 >= 'A' && c1 <= 'F') - c1 = 10 + c1 - 'A'; - else if (c1 >= 'a' && c1 <= 'f') - c1 = 10 + c1 - 'a'; - else {p++; continue;} - - if (c2 >= '0' && c2 <= '9') - c2 = c2 - '0'; - else if (c2 >= 'A' && c2 <= 'F') - c2 = 10 + c2 - 'A'; - else if (c2 >= 'a' && c2 <= 'f') - c2 = 10 + c2 - 'a'; - else {p++; continue;} - - *p = (c1<<4) | c2; - - memmove(p+1, p+3, strlen(p+3)+1); - p++; - } -} - - static char *grab_line(FILE *f, int *cl) { char *ret = NULL; @@ -167,8 +130,8 @@ void cgi_load_variables(void) !variables[num_variables].value) continue; - unescape(variables[num_variables].value); - unescape(variables[num_variables].name); + rfc1738_unescape(variables[num_variables].value); + rfc1738_unescape(variables[num_variables].name); #ifdef DEBUG_COMMENTS printf("\n", @@ -198,8 +161,8 @@ void cgi_load_variables(void) !variables[num_variables].value) continue; - unescape(variables[num_variables].value); - unescape(variables[num_variables].name); + rfc1738_unescape(variables[num_variables].value); + rfc1738_unescape(variables[num_variables].name); #ifdef DEBUG_COMMENTS printf("\n", -- cgit From 1cba0a757970ffd8b81d61c88965010968ab3eff Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 28 Jan 2003 12:07:02 +0000 Subject: Merge from HEAD: - NTLMSSP over SPENGO (sesssion-setup-and-x) cleanup and code refactor. - also consequential changes to the NTLMSSP and SPNEGO parsing functions - and the client code that uses the same functions - Add ntlm_auth, a NTLMSSP authentication interface for use by applications like Squid and Apache. - also consquential changes to use common code for base64 encode/decode. - Winbind changes to support ntlm_auth (I don't want this program to need to read smb.conf, instead getting all it's details over the pipe). - nmbd changes for fstrcat() instead of fstrcpy(). Andrew Bartlett (This used to be commit fbb46da79cf322570a7e3318100c304bbf33409e) --- source3/web/cgi.c | 31 ------------------------------- 1 file changed, 31 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 018dd3602f..35f3266283 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -291,37 +291,6 @@ static void cgi_web_auth(void) passwd_free(&pwd); } -/*************************************************************************** -decode a base64 string in-place - simple and slow algorithm - ***************************************************************************/ -static void base64_decode(char *s) -{ - const char *b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - int bit_offset, byte_offset, idx, i, n; - unsigned char *d = (unsigned char *)s; - char *p; - - n=i=0; - - while (*s && (p=strchr_m(b64,*s))) { - idx = (int)(p - b64); - byte_offset = (i*6)/8; - bit_offset = (i*6)%8; - d[byte_offset] &= ~((1<<(8-bit_offset))-1); - if (bit_offset < 3) { - d[byte_offset] |= (idx << (2-bit_offset)); - n = byte_offset+1; - } else { - d[byte_offset] |= (idx >> (bit_offset-2)); - d[byte_offset+1] = 0; - d[byte_offset+1] |= (idx << (8-(bit_offset-2))) & 0xFF; - n = byte_offset+2; - } - s++; i++; - } - /* null terminate */ - d[n] = 0; -} /*************************************************************************** handle a http authentication line -- cgit From 9c858c3188bf26a754936fff5f1a1a0c263ba7cd Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 1 Feb 2003 07:27:01 +0000 Subject: Merge from HEAD - convert username/password to unix before checking them in SWAT. (This used to be commit 8485c51bc47f45a6263bda83a0bc3ba15abcd250) --- source3/web/cgi.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 35f3266283..46f33789bf 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -297,7 +297,8 @@ 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)) { @@ -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. */ -- cgit From 17ec9642cdf29257297b56a202966863c9dac56f Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Tue, 18 Feb 2003 23:17:59 +0000 Subject: base64_decode() with heimdal libs, so I've renamed it base64_decode_inplace(). (This used to be commit d510ff85fb0dafddf3dea9412a09eeee6e70f0cb) --- source3/web/cgi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 46f33789bf..8abc2f0bd5 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -306,7 +306,7 @@ static BOOL cgi_handle_authorization(char *line) } 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 -- cgit From 938f37afc2b47184e5802324db31fbb357a4b6cc Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 28 Feb 2003 08:48:26 +0000 Subject: Fix HTTP error codes (patch by Vance Lankhaar) (This used to be commit e660b0b8d034c6cb9771601c64b952380d136ca1) --- source3/web/cgi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 8abc2f0bd5..212c2884b6 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -455,11 +455,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"))) { @@ -478,7 +478,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
Check your \"hosts allow\" and \"hosts deny\" options in smb.conf "); } -- cgit From da8048b4fa8b60ec3cb3033d19d4a451f259befb Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 21 Oct 2003 14:19:32 +0000 Subject: call initgroups before becomming the user; patch from Fabio Cecchi (This used to be commit 5a8dbccd66911642fabb6b8b38fff4477b76c3a1) --- source3/web/cgi.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 212c2884b6..8e739cd224 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -342,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 */ -- cgit From bb0598faf58679a7ad26a1caab8eadb154a07ae2 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 22 Oct 2003 23:38:20 +0000 Subject: Put strcasecmp/strncasecmp on the banned list (except for needed calls in iconv.c and nsswitch/). Using them means you're not thinking about multibyte at all and I really want to discourage that. Jeremy. (This used to be commit d7e35dfb9283d560d0ed2ab231f36ed92767dace) --- source3/web/cgi.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 8e739cd224..6778e59656 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -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; } } @@ -301,7 +301,7 @@ static BOOL cgi_handle_authorization(char *line) fstring user, user_pass; struct passwd *pass = NULL; - if (strncasecmp(line,"Basic ", 6)) { + if (!strnequal(line,"Basic ", 6)) { goto err; } line += 6; @@ -489,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! */ -- cgit From d5573ccde3b5c39eb9a4637d5a9d7a95b66d86e3 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 7 Nov 2003 09:03:02 +0000 Subject: Simple rename of get_socket_addr to get_peer_addr and get_socket_name to get_peer_name. This is to get closer to the getsockname/getpeername system functions. Next step will be the %i macro for the local IP address. I still want to play %L-games in times of port 445. Volker (This used to be commit d7162122eaf5d897e5de51604e431bfbaa20e905) --- source3/web/cgi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 6778e59656..49a8fa92de 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -578,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"); } @@ -589,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"); } -- cgit From 7d9fb45339687de1cbc8a0749353c8dd7c13d870 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Sat, 22 Nov 2003 06:16:01 +0000 Subject: include WWW-Authenticate field in 401 response for bad auth attempt; bug 629 (This used to be commit 879d0f15ea260d61c56c5b841065ecb2f5ec26ca) --- source3/web/cgi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 49a8fa92de..07e3ee38fb 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -355,7 +355,8 @@ static BOOL cgi_handle_authorization(char *line) } err: - cgi_setup_error("401 Bad Authorization", "", + cgi_setup_error("401 Bad Authorization", + "WWW-Authenticate: Basic realm=\"SWAT\"\r\n", "username or password incorrect"); passwd_free(&pass); -- cgit From 3b386064911dce7c02e40b5cc7a971f2d4b28185 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 25 Dec 2003 09:37:41 +0000 Subject: Fix bug 916 - do not perform a + -> space substitution for squid URL encoded strings, only form input in SWAT. Andrew Bartlett (This used to be commit 8d54f5fe0c5689660f37788916b37014754ce23e) --- source3/web/cgi.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 07e3ee38fb..8a103fa57f 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -85,6 +85,20 @@ static char *grab_line(FILE *f, int *cl) return ret; } +/** + URL encoded strings can have a '+', which should be replaced with a space + + (This was in rfc1738_unescape(), but that broke the squid helper) +**/ + +void plus_to_space_unescape(char *buf) +{ + char *p=buf; + + while ((p=strchr_m(p,'+'))) + *p = ' '; +} + /*************************************************************************** load all the variables passed to the CGI program. May have multiple variables with the same name and the same or different values. Takes a file parameter @@ -130,7 +144,9 @@ void cgi_load_variables(void) !variables[num_variables].value) continue; + plus_to_space_unescape(variables[num_variables].value); rfc1738_unescape(variables[num_variables].value); + plus_to_space_unescape(variables[num_variables].name); rfc1738_unescape(variables[num_variables].name); #ifdef DEBUG_COMMENTS @@ -161,7 +177,9 @@ void cgi_load_variables(void) !variables[num_variables].value) continue; + plus_to_space_unescape(variables[num_variables].value); rfc1738_unescape(variables[num_variables].value); + plus_to_space_unescape(variables[num_variables].name); rfc1738_unescape(variables[num_variables].name); #ifdef DEBUG_COMMENTS -- cgit From d198c5587774808823aa09e997ff492826738c51 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sun, 8 Feb 2004 08:38:42 +0000 Subject: Make more functions static, and remove duplication in the use of functions in lib/smbpasswd.c that were exact duplicates of functions in passdb/passdb.c (These should perhaps be pulled back out to smbpasswd.c, but that can occour later). Andrew Bartlett (This used to be commit fcdc5efb1e245c8fa95cd031f67ec56093b9056e) --- source3/web/cgi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 8a103fa57f..aac009893c 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -91,7 +91,7 @@ static char *grab_line(FILE *f, int *cl) (This was in rfc1738_unescape(), but that broke the squid helper) **/ -void plus_to_space_unescape(char *buf) +static void plus_to_space_unescape(char *buf) { char *p=buf; -- cgit From e3f5b542707e2328030b9d5eff0836a904eccde5 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 11 Mar 2004 22:48:24 +0000 Subject: Restore the contract on all convert_stringXX() interfaces. Add a "allow_bad_conv" boolean parameter that allows broken iconv conversions to work. Gets rid of the nasty errno checks in mangle_hash2 and check_path_syntax and allows correct return code checking. Jeremy. (This used to be commit 7b96765c23637613f079d37566d95d5edd511f05) --- source3/web/cgi.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index aac009893c..07b9f52ff7 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -203,13 +203,13 @@ void cgi_load_variables(void) convert_string(CH_DISPLAY, CH_UNIX, variables[i].name, -1, - dest, sizeof(dest)); + dest, sizeof(dest), True); free(variables[i].name); variables[i].name = strdup(dest); convert_string(CH_DISPLAY, CH_UNIX, variables[i].value, -1, - dest, sizeof(dest)); + dest, sizeof(dest), True); free(variables[i].value); variables[i].value = strdup(dest); } @@ -336,11 +336,11 @@ static BOOL cgi_handle_authorization(char *line) convert_string(CH_DISPLAY, CH_UNIX, line, -1, - user, sizeof(user)); + user, sizeof(user), True); convert_string(CH_DISPLAY, CH_UNIX, p+1, -1, - user_pass, sizeof(user_pass)); + user_pass, sizeof(user_pass), True); /* * Try and get the user from the UNIX password file. -- cgit From db1ff9b348a16d769f007362fa57ab89f56d101c Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 16 Aug 2004 15:25:57 +0000 Subject: r1833: patch from James Peach to get swat to look for index.html by default when given a trailing directory/ (This used to be commit 980740da784ce00ad1b388872297b82d4d368044) --- source3/web/cgi.c | 28 ++++++++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 07b9f52ff7..b1aa8ae754 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -421,18 +421,38 @@ static void cgi_download(char *file) } } - if (!file_exist(file, &st)) { + if (sys_stat(file, &st) != 0) + { cgi_setup_error("404 File Not Found","", "The requested file was not found"); } - fd = web_open(file,O_RDONLY,0); + if (S_ISDIR(st.st_mode)) + { + snprintf(buf, sizeof(buf), "%s/index.html", file); + if (!file_exist(buf, &st) || !S_ISREG(st.st_mode)) + { + cgi_setup_error("404 File Not Found","", + "The requested file was not found"); + } + } + else if (S_ISREG(st.st_mode)) + { + snprintf(buf, sizeof(buf), "%s", file); + } + else + { + cgi_setup_error("404 File Not Found","", + "The requested file was not found"); + } + + fd = web_open(buf,O_RDONLY,0); if (fd == -1) { cgi_setup_error("404 File Not Found","", "The requested file was not found"); } printf("HTTP/1.0 200 OK\r\n"); - if ((p=strrchr_m(file,'.'))) { + if ((p=strrchr_m(buf, '.'))) { if (strcmp(p,".gif")==0) { printf("Content-Type: image/gif\r\n"); } else if (strcmp(p,".jpg")==0) { @@ -554,7 +574,7 @@ void cgi_setup(const char *rootdir, int auth_required) string_sub(url, "/swat/", "", 0); - if (url[0] != '/' && strstr(url,"..")==0 && file_exist(url, NULL)) { + if (url[0] != '/' && strstr(url,"..")==0) { cgi_download(url); } -- cgit From b2dc329d437603e525609b101ecced7f0c5b19cd Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Fri, 1 Oct 2004 22:24:44 +0000 Subject: r2771: Second (and last) part of Swat-i18n-Patch from Björn Jacke MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit "Do not use display charset for swat output. In HTML we do not care about the "locale charmap" because HTML code is UTF-8 only now. Additionally take care that we convert files from statuspage from unix charset to UTF-8. Thus we have correct HTML output under all circumstances. We now also convert the share names correctly from unix encoding to web encoding and vice vera. " Guenther (This used to be commit 6d9f77c2bb95db4939b8ef375e22b188168b70ab) --- source3/web/cgi.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index b1aa8ae754..93731d1d3f 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -196,18 +196,18 @@ void cgi_load_variables(void) printf("\n"); #endif - /* variables from the client are in display charset - convert them - to our internal charset before use */ + /* variables from the client are in UTF-8 - convert them + to our internal unix charset before use */ for (i=0;i Date: Thu, 7 Oct 2004 04:01:18 +0000 Subject: r2835: Since we always have -I. and -I$(srcdir) in CFLAGS, we can get rid of '..' from all #include preprocessor commands. This fixes bugzilla #1880 where OpenVMS gets confused about the '.' characters. (This used to be commit 7f161702fa4916979602cc0295919b541912acd6) --- source3/web/cgi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 93731d1d3f..cf309c364e 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -19,7 +19,7 @@ #include "includes.h" -#include "../web/swat_proto.h" +#include "web/swat_proto.h" #define MAX_VARIABLES 10000 -- cgit From acf9d61421faa6c0055d57fdee7db300dc5431aa Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 7 Dec 2004 18:25:53 +0000 Subject: r4088: Get medieval on our ass about malloc.... :-). Take control of all our allocation functions so we can funnel through some well known functions. Should help greatly with malloc checking. HEAD patch to follow. Jeremy. (This used to be commit 620f2e608f70ba92f032720c031283d295c5c06a) --- source3/web/cgi.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index cf309c364e..937e603f8c 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -59,7 +59,7 @@ static char *grab_line(FILE *f, int *cl) char *ret2; if (len == 0) len = 1024; else len *= 2; - ret2 = (char *)Realloc(ret, len); + ret2 = (char *)SMB_REALLOC(ret, len); if (!ret2) return ret; ret = ret2; } @@ -135,8 +135,8 @@ void cgi_load_variables(void) *p = 0; - variables[num_variables].name = strdup(line); - variables[num_variables].value = strdup(p+1); + variables[num_variables].name = SMB_STRDUP(line); + variables[num_variables].value = SMB_STRDUP(p+1); SAFE_FREE(line); @@ -170,8 +170,8 @@ void cgi_load_variables(void) *p = 0; - variables[num_variables].name = strdup(tok); - variables[num_variables].value = strdup(p+1); + variables[num_variables].name = SMB_STRDUP(tok); + variables[num_variables].value = SMB_STRDUP(p+1); if (!variables[num_variables].name || !variables[num_variables].value) @@ -205,13 +205,13 @@ void cgi_load_variables(void) variables[i].name, -1, dest, sizeof(dest), True); free(variables[i].name); - variables[i].name = strdup(dest); + variables[i].name = SMB_STRDUP(dest); convert_string(CH_UTF8, CH_UNIX, variables[i].value, -1, dest, sizeof(dest), True); free(variables[i].value); - variables[i].value = strdup(dest); + variables[i].value = SMB_STRDUP(dest); } } @@ -366,7 +366,7 @@ static BOOL cgi_handle_authorization(char *line) become_user_permanently(pass->pw_uid, pass->pw_gid); /* Save the users name */ - C_user = strdup(user); + C_user = SMB_STRDUP(user); passwd_free(&pass); return True; } @@ -530,11 +530,11 @@ void cgi_setup(const char *rootdir, int auth_required) if (line[0] == '\r' || line[0] == '\n') break; if (strnequal(line,"GET ", 4)) { got_request = True; - url = strdup(&line[4]); + url = SMB_STRDUP(&line[4]); } else if (strnequal(line,"POST ", 5)) { got_request = True; request_post = 1; - url = strdup(&line[5]); + url = SMB_STRDUP(&line[5]); } else if (strnequal(line,"PUT ", 4)) { got_request = True; cgi_setup_error("400 Bad Request", "", -- cgit From 23c143dc4190ea2e15d340cebd1a5ecc12ebeedd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 6 Jan 2005 19:32:39 +0000 Subject: r4577: Fix from William Jojo for AIX 5.3 compile. Jeremy. (This used to be commit 80e7c6c312eb0bdb93fe381e7ce3a24a21dd9cf0) --- source3/web/cgi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 937e603f8c..5d52ad6279 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -30,12 +30,12 @@ extern void print_title(char *fmt, ...); #endif -struct var { +struct cgi_var { char *name; char *value; }; -static struct var variables[MAX_VARIABLES]; +static struct cgi_var variables[MAX_VARIABLES]; static int num_variables; static int content_length; static int request_post; -- cgit From af8a691db11a5072865f8b03fd1cbd3aab5cb6d7 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 8 Jul 2005 04:51:27 +0000 Subject: r8219: Merge the new open code from HEAD to 3.0. Haven't yet run the torture tests on this as it's very late NY time (just wanted to get this work into the tree). I'll test this over the weekend.... Jerry - in looking at the difference between the two trees there seem to be some printing/ntprinting.c and registry changes we might want to examine to try keep in sync. Jeremy. (This used to be commit c7fe18761e2c753afbffd3a78abff46472a9b8eb) --- source3/web/cgi.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 5d52ad6279..6c9cfce13c 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -457,6 +457,10 @@ static void cgi_download(char *file) printf("Content-Type: image/gif\r\n"); } else if (strcmp(p,".jpg")==0) { printf("Content-Type: image/jpeg\r\n"); + } else if (strcmp(p,".png")==0) { + printf("Content-Type: image/png\r\n"); + } else if (strcmp(p,".css")==0) { + printf("Content-Type: text/css\r\n"); } else if (strcmp(p,".txt")==0) { printf("Content-Type: text/plain\r\n"); } else { -- cgit From 0af1500fc0bafe61019f1b2ab1d9e1d369221240 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 3 Feb 2006 22:19:41 +0000 Subject: r13316: Let the carnage begin.... Sync with trunk as off r13315 (This used to be commit 17e63ac4ed8325c0d44fe62b2442449f3298559f) --- source3/web/cgi.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 6c9cfce13c..700fb7fa08 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -293,7 +293,7 @@ static void cgi_web_auth(void) exit(0); } - pwd = getpwnam_alloc(user); + pwd = getpwnam_alloc(NULL, user); if (!pwd) { printf("%sCannot find user %s
%s\n", head, user, tail); exit(0); @@ -306,7 +306,7 @@ static void cgi_web_auth(void) head, user, (int)geteuid(), (int)getuid(), tail); exit(0); } - passwd_free(&pwd); + talloc_free(pwd); } @@ -346,7 +346,7 @@ static BOOL cgi_handle_authorization(char *line) * Try and get the user from the UNIX password file. */ - pass = getpwnam_alloc(user); + pass = getpwnam_alloc(NULL, user); /* * Validate the password they have given. @@ -367,7 +367,7 @@ static BOOL cgi_handle_authorization(char *line) /* Save the users name */ C_user = SMB_STRDUP(user); - passwd_free(&pass); + talloc_free(pass); return True; } } @@ -377,7 +377,7 @@ err: "WWW-Authenticate: Basic realm=\"SWAT\"\r\n", "username or password incorrect"); - passwd_free(&pass); + talloc_free(pass); return False; } -- cgit From fb5362c069b5b6548478b2217a0519c56d856705 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 20 Feb 2006 17:59:58 +0000 Subject: r13571: Replace all calls to talloc_free() with thye TALLOC_FREE() macro which sets the freed pointer to NULL. (This used to be commit b65be8874a2efe5a4b167448960a4fcf6bd995e2) --- source3/web/cgi.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 700fb7fa08..d1cd38eb51 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -306,7 +306,7 @@ static void cgi_web_auth(void) head, user, (int)geteuid(), (int)getuid(), tail); exit(0); } - talloc_free(pwd); + TALLOC_FREE(pwd); } @@ -367,7 +367,7 @@ static BOOL cgi_handle_authorization(char *line) /* Save the users name */ C_user = SMB_STRDUP(user); - talloc_free(pass); + TALLOC_FREE(pass); return True; } } @@ -377,7 +377,7 @@ err: "WWW-Authenticate: Basic realm=\"SWAT\"\r\n", "username or password incorrect"); - talloc_free(pass); + TALLOC_FREE(pass); return False; } -- cgit From 894358a8f3e338b339b6c37233edef794b312087 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 7 Mar 2006 06:31:04 +0000 Subject: r13915: Fixed a very interesting class of realloc() bugs found by Coverity. realloc can return NULL in one of two cases - (1) the realloc failed, (2) realloc succeeded but the new size requested was zero, in which case this is identical to a free() call. The error paths dealing with these two cases should be different, but mostly weren't. Secondly the standard idiom for dealing with realloc when you know the new size is non-zero is the following : tmp = realloc(p, size); if (!tmp) { SAFE_FREE(p); return error; } else { p = tmp; } However, there were *many* *many* places in Samba where we were using the old (broken) idiom of : p = realloc(p, size) if (!p) { return error; } which will leak the memory pointed to by p on realloc fail. This commit (hopefully) fixes all these cases by moving to a standard idiom of : p = SMB_REALLOC(p, size) if (!p) { return error; } Where if the realloc returns null due to the realloc failing or size == 0 we *guarentee* that the storage pointed to by p has been freed. This allows me to remove a lot of code that was dealing with the standard (more verbose) method that required a tmp pointer. This is almost always what you want. When a realloc fails you never usually want the old memory, you want to free it and get into your error processing asap. For the 11 remaining cases where we really do need to keep the old pointer I have invented the new macro SMB_REALLOC_KEEP_OLD_ON_ERROR, which can be used as follows : tmp = SMB_REALLOC_KEEP_OLD_ON_ERROR(p, size); if (!tmp) { SAFE_FREE(p); return error; } else { p = tmp; } SMB_REALLOC_KEEP_OLD_ON_ERROR guarentees never to free the pointer p, even on size == 0 or realloc fail. All this is done by a hidden extra argument to Realloc(), BOOL free_old_on_error which is set appropriately by the SMB_REALLOC and SMB_REALLOC_KEEP_OLD_ON_ERROR macros (and their array counterparts). It remains to be seen what this will do to our Coverity bug count :-). Jeremy. (This used to be commit 1d710d06a214f3f1740e80e0bffd6aab44aac2b0) --- source3/web/cgi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index d1cd38eb51..b764b6d628 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -59,7 +59,7 @@ static char *grab_line(FILE *f, int *cl) char *ret2; if (len == 0) len = 1024; else len *= 2; - ret2 = (char *)SMB_REALLOC(ret, len); + ret2 = (char *)SMB_REALLOC_KEEP_OLD_ON_ERROR(ret, len); if (!ret2) return ret; ret = ret2; } -- cgit From 4340b7cea74203799f7cd5d2457cbe062b42425c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 20 Jun 2006 19:21:14 +0000 Subject: r16426: Klocwork #1544, #1545, #1546, #1549, #1550, #1552, #1553, #1554 Jeremy. (This used to be commit e71cc6647a2eaba0eac95b6abb40745e45db72a4) --- source3/web/cgi.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index b764b6d628..d289613b4b 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -223,6 +223,7 @@ void cgi_load_variables(void) browser. Also doesn't allow for variables[] containing multiple variables with the same name and the same or different values. ***************************************************************************/ + const char *cgi_variable(const char *name) { int i; @@ -233,6 +234,20 @@ const char *cgi_variable(const char *name) return NULL; } +/*************************************************************************** + Version of the above that can't return a NULL pointer. +***************************************************************************/ + +const char *cgi_variable_nonull(const char *name) +{ + const char *var = cgi_variable(name); + if (var) { + return var; + } else { + return ""; + } +} + /*************************************************************************** tell a browser about a fatal error in the http processing ***************************************************************************/ -- cgit From 981588d57905674b1b13dc9830abf3e318d19ab3 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 28 Aug 2006 04:55:05 +0000 Subject: r17873: Fix possible null deref found by Stanford checker. Jeremy. (This used to be commit 1adb3b2432187e9a19b78cfa5762c3e05a357392) --- source3/web/cgi.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index d289613b4b..046dd3bee6 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -80,8 +80,9 @@ static char *grab_line(FILE *f, int *cl) } - - ret[i] = 0; + if (ret) { + ret[i] = 0; + } return ret; } -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/web/cgi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 046dd3bee6..a6adbda5d6 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -4,7 +4,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, -- cgit From 5e54558c6dea67b56bbfaba5698f3a434d3dffb6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 00:52:41 +0000 Subject: r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text (This used to be commit b0132e94fc5fef936aa766fb99a306b3628e9f07) --- source3/web/cgi.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index a6adbda5d6..9af4337a21 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -13,8 +13,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ -- cgit From cb5436bcc3b55e0c221fb6b3fa3133f149a64384 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 11 Oct 2007 15:36:13 -0700 Subject: Add const to the get_peer_addr() and get_socket_addr() calls. Use the IPv6 varient for get_peer_addr(). Jeremy. (This used to be commit baf1f52e34ae2465a7a34be1065da29ed97e7bea) --- source3/web/cgi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 9af4337a21..0e362ea245 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -633,7 +633,7 @@ const char *cgi_pathinfo(void) /*************************************************************************** return the hostname of the client ***************************************************************************/ -char *cgi_remote_host(void) +const char *cgi_remote_host(void) { if (inetd_server) { return get_peer_name(1,False); @@ -644,7 +644,7 @@ char *cgi_remote_host(void) /*************************************************************************** return the hostname of the client ***************************************************************************/ -char *cgi_remote_addr(void) +const char *cgi_remote_addr(void) { if (inetd_server) { return get_peer_addr(1); -- cgit From 30191d1a5704ad2b158386b511558972d539ce47 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 18 Oct 2007 17:40:25 -0700 Subject: RIP BOOL. Convert BOOL -> bool. I found a few interesting bugs in various places whilst doing this (places that assumed BOOL == int). I also need to fix the Samba4 pidl generation (next checkin). Jeremy. (This used to be commit f35a266b3cbb3e5fa6a86be60f34fe340a3ca71f) --- source3/web/cgi.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 0e362ea245..6a8688b637 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -42,8 +42,8 @@ static char *query_string; static const char *baseurl; static char *pathinfo; static char *C_user; -static BOOL inetd_server; -static BOOL got_request; +static bool inetd_server; +static bool got_request; static char *grab_line(FILE *f, int *cl) { @@ -328,7 +328,7 @@ static void cgi_web_auth(void) /*************************************************************************** handle a http authentication line ***************************************************************************/ -static BOOL cgi_handle_authorization(char *line) +static bool cgi_handle_authorization(char *line) { char *p; fstring user, user_pass; @@ -399,7 +399,7 @@ err: /*************************************************************************** is this root? ***************************************************************************/ -BOOL am_root(void) +bool am_root(void) { if (geteuid() == 0) { return( True); @@ -509,7 +509,7 @@ static void cgi_download(char *file) **/ void cgi_setup(const char *rootdir, int auth_required) { - BOOL authenticated = False; + bool authenticated = False; char line[1024]; char *url=NULL; char *p; @@ -656,7 +656,7 @@ const char *cgi_remote_addr(void) /*************************************************************************** return True if the request was a POST ***************************************************************************/ -BOOL cgi_waspost(void) +bool cgi_waspost(void) { if (inetd_server) { return request_post; -- cgit From 6658165d5e9cd186fea74e1581091233e8990e9b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 3 Nov 2007 18:15:45 -0700 Subject: Stop get_peer_addr() and client_addr() from using global statics. Part of my library cleanups. Jeremy. (This used to be commit e848506c858bd16706c1d7f6b4b032005512b8ac) --- source3/web/cgi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 6a8688b637..71328459f0 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -647,7 +647,8 @@ return the hostname of the client const char *cgi_remote_addr(void) { if (inetd_server) { - return get_peer_addr(1); + char addr[INET6_ADDRSTRLEN]; + return get_peer_addr(1,addr); } return getenv("REMOTE_ADDR"); } -- cgit From 25074433f412c4dd2531fd268d51be8753ddc11b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 3 Nov 2007 18:41:26 -0700 Subject: I can't get away without a 'length' arg. :-). Jeremy. (This used to be commit 95d01279a5def709d0a5d5ae7224d6286006d120) --- source3/web/cgi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 71328459f0..41ac29be5d 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -648,7 +648,7 @@ const char *cgi_remote_addr(void) { if (inetd_server) { char addr[INET6_ADDRSTRLEN]; - return get_peer_addr(1,addr); + return get_peer_addr(1,addr,sizeof(addr)); } return getenv("REMOTE_ADDR"); } -- cgit From 6f46f75dfc2c80b99a6a5fb277bab456a5fd247b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 3 Dec 2007 17:17:05 -0800 Subject: Make strhex_to_str clear on string limits. Remove pstring from web/*.c Jeremy. (This used to be commit f9c8d62389f8cb47837e5360209936176537df13) --- source3/web/cgi.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 41ac29be5d..07a6fbcf54 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -173,7 +173,7 @@ void cgi_load_variables(void) variables[num_variables].name = SMB_STRDUP(tok); variables[num_variables].value = SMB_STRDUP(p+1); - if (!variables[num_variables].name || + if (!variables[num_variables].name || !variables[num_variables].value) continue; @@ -186,32 +186,36 @@ void cgi_load_variables(void) printf("\n", variables[num_variables].name, variables[num_variables].value); -#endif +#endif num_variables++; if (num_variables == MAX_VARIABLES) break; } } #ifdef DEBUG_COMMENTS - printf("\n"); + printf("\n"); #endif /* variables from the client are in UTF-8 - convert them to our internal unix charset before use */ for (i=0;i Date: Wed, 23 Jan 2008 11:04:10 +0100 Subject: strtok -> strtok_r (This used to be commit fd34ce437057bb34cdc37f4b066e424000d36789) --- source3/web/cgi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 07a6fbcf54..c6233b0869 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -164,7 +164,9 @@ void cgi_load_variables(void) open("/dev/null", O_RDWR); if ((s=query_string) || (s=getenv("QUERY_STRING"))) { - for (tok=strtok(s,"&;");tok;tok=strtok(NULL,"&;")) { + char *saveptr; + for (tok=strtok_r(s, "&;", &saveptr); tok; + tok=strtok_r(NULL, "&;", &saveptr)) { p = strchr_m(tok,'='); if (!p) continue; -- cgit From bb869741ddc3d82da02c96bef592dab6074ff142 Mon Sep 17 00:00:00 2001 From: Tim Prouty Date: Mon, 3 Mar 2008 13:32:54 -0800 Subject: Cleanup size_t return values in convert_string_allocate This patch is the first iteration of an inside-out conversion to cleanup functions in charcnv.c returning size_t == -1 to indicate failure. (This used to be commit 59124382d2894a1b194b48dd82bc5f956959eb48) --- source3/web/cgi.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index c6233b0869..28f64f89ad 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -202,19 +202,19 @@ void cgi_load_variables(void) to our internal unix charset before use */ for (i=0;i Date: Tue, 3 Jun 2008 15:05:50 +0200 Subject: Fix saving of the config file in SWAT; [#5516]. The strlen of the source string passed to convert_string_allocate was too short :) Signed-off-by: Stefan Metzmacher (This used to be commit ac3597ef8b7781499ab55f1039670ec82202e32c) --- source3/web/cgi.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/web/cgi.c') diff --git a/source3/web/cgi.c b/source3/web/cgi.c index 28f64f89ad..070e80cf91 100644 --- a/source3/web/cgi.c +++ b/source3/web/cgi.c @@ -206,14 +206,14 @@ void cgi_load_variables(void) size_t dest_len; convert_string_allocate(frame, CH_UTF8, CH_UNIX, - variables[i].name, -1, + variables[i].name, strlen(variables[i].name), &dest, &dest_len, True); SAFE_FREE(variables[i].name); variables[i].name = SMB_STRDUP(dest ? dest : ""); dest = NULL; convert_string_allocate(frame, CH_UTF8, CH_UNIX, - variables[i].value, -1, + variables[i].value, strlen(variables[i].value), &dest, &dest_len, True); SAFE_FREE(variables[i].value); variables[i].value = SMB_STRDUP(dest ? dest : ""); -- cgit