/*************************************************************************/ /** **/ /** getcgivars.c-- routine to read CGI input variables into an **/ /** array of strings. **/ /** **/ /** The x2c() and unescape_url() routines were lifted directly **/ /** from NCSA's sample program util.c, packaged with their HTTPD. **/ /** **/ /*************************************************************************/ #include "../common/config.h" #include #include #include "getcgi.h" /* Remove potentially harmful characters from CGI input (Ethan Galstad) */ void sanitize(char **cgivars){ char *strptr; int x,y,i; for(strptr=cgivars[i=0];strptr!=NULL;strptr=cgivars[++i]){ for(x=0,y=0;strptr[x]!='\x0';x++){ if(strptr[x]==';'||strptr[x]=='|'||strptr[x]=='&'||strptr[x]=='<'||strptr[x]=='>'); else{ strptr[y]=strptr[x]; y++; } } strptr[y]='\x0'; } return; } /** Convert a two-char hex string into the char it represents **/ char x2c(char *what){ register char digit; digit = (what[0] >= 'A' ? ((what[0] & 0xdf) - 'A')+10 : (what[0] - '0')); digit *= 16; digit += (what[1] >= 'A' ? ((what[1] & 0xdf) - 'A')+10 : (what[1] - '0')); return(digit); } /** Reduce any %xx escape sequences to the characters they represent **/ void unescape_url(char *url){ register int i,j; if(url==NULL) return; for(i=0,j=0;url[j]!='\x0' && j '%s'\n",request_method); printf("\n"); printf("I'm guessing you're trying to execute the CGI from a command line.\n"); printf("In order to do that, you need to set the REQUEST_METHOD environment\n"); printf("variable to either \"GET\", \"HEAD\", or \"POST\". When using the\n"); printf("GET and HEAD methods, arguments can be passed to the CGI\n"); printf("by setting the \"QUERY_STRING\" environment variable. If you're\n"); printf("using the POST method, data is read from standard input. Also of\n"); printf("note: if you've enabled authentication in the CGIs, you must set the\n"); printf("\"REMOTE_USER\" environment variable to be the name of the user you're\n"); printf("\"authenticated\" as. Now you know the secret. Just don't tell anyone...\n"); printf("\n"); printf(" - Ethan Galstad (netsaint@netsaint.org)\n"); exit(1); } /** Change all plusses back to spaces **/ for(i=0;cgiinput[i];i++){ if(cgiinput[i]=='+') cgiinput[i]=' '; } /** First, split on "&" to extract the name-value pairs into pairlist **/ pairlist=(char **)malloc(256*sizeof(char **)); paircount=0; nvpair=strtok(cgiinput,"&"); while(nvpair){ pairlist[paircount++]=strdup(nvpair); if(!(paircount%256)) pairlist=(char **)realloc(pairlist,(paircount+256)*sizeof(char **)); nvpair=strtok(NULL,"&"); } pairlist[paircount]=0; /* terminate the list with NULL */ /** Then, from the list of pairs, extract the names and values **/ cgivars=(char **)malloc((paircount*2+1)*sizeof(char **)); for(i=0;i