BOOL ShowSelectHomeDlg(LPSTR path) { int i; OPENFILENAME ofn; ofn.lpstrFile = GetEnvValue("GNUPGHOME"); if ( ofn.lpstrFile && existsPath(ofn.lpstrFile) ) { strcpy(path, ofn.lpstrFile); return TRUE; } ofn.lpstrFile = GetRegValue(HKEY_CURRENT_USER,"Software\\GNU\\GnuPG","HomeDir"); if ( ofn.lpstrFile && existsPath(ofn.lpstrFile) ) { strcpy(path, ofn.lpstrFile); return TRUE; } ofn.lpstrFile = GetEnvValue("APPDATA"); if ( ofn.lpstrFile ) { strcat(ofn.lpstrFile,"\\gnupg"); if ( existsPath(ofn.lpstrFile) ) { strcpy(path, ofn.lpstrFile); return TRUE; } } ofn.lStructSize = sizeof(ofn); ofn.nMaxFile = MAX_PATH; ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_NONETWORKBUTTON; ofn.lpstrFile = path; ofn.lpstrFilter = "Public key rings (pubring.gpg)\0pubring.gpg\0All files (*.*)\0*.*\0"; ofn.lpstrTitle = "Open Public Keyring"; if (!GetOpenFileName(&ofn)) return FALSE; for(i=strlen(path);i && path[i]!='\\';i--); path[i] = 0; return TRUE; }
cgiEnvT::cgiEnvT(int argc, char *argv[], char *envp[]) { int errcd = 0; long size = 0; int i = 0, j, offset; char *p = envp[i], *ContentLength;; ArgSize = argc; ArgVars = argv; cgiOut = stdout; cgiError = stderr; cgiDebug = stderr; cgiLog = stderr; EnvSize = 0; while(p != NULL) p = envp[++EnvSize]; EnvVars = (struct STRTUPLE *) malloc(sizeof(struct STRTUPLE) * EnvSize); for (i = 0; envp[i] != NULL; i++) { p = envp[i]; EnvVars[i].name = (char *) malloc(sizeof(char) * length(p,'=') + 1); for(offset = j = 0; j < (int) strlen(p) && p[j] != '=' && j-offset < STRMAX;j++) EnvVars[i].name[j-offset] = p[j]; EnvVars[i].name[j-offset] = '\0'; //<<ensure string termination EnvVars[i].value = (char *) malloc(sizeof(char) * length(p+j+1,'\n') + 1); for(offset = ++j; j < (int) strlen(p) && p[j] != '\n' && j-offset < STRMAX;j++) EnvVars[i].value[j-offset] = p[j]; EnvVars[i].value[j-offset] = '\0'; size++; } if ((ArgSize > 1) && (strcmp((NULL == GetNthArgValue(1))?GetNthArgValue(0):GetNthArgValue(1),"-f") == 0)) //look at arg[1] for a -f, if it is, then arg[2] is a filename to readfrom { if (GetNthArgValue(2) != NULL) { if ((cgiIn = fopen(GetNthArgValue(2),"r")) == NULL) { ReportError("%s Failed to open %s for input. File Not Accessable.\n",GetNthArgValue(0),GetNthArgValue(2)); errcd = 1; } else { //now that we have it open we need to set CONTENT_LENGTH to the file size if (atol(((ContentLength = GetEnvValue("CONTENT_LENGTH")) != NULL)?ContentLength:"0") == 0) { EnvVars = (struct STRTUPLE *) realloc(EnvVars,sizeof(struct STRTUPLE) * ++EnvSize); EnvVars[EnvSize-1].name = (char *) malloc(sizeof(char) * 15); strcpy(EnvVars[EnvSize-1].name,"CONTENT_LENGTH"); EnvVars[EnvSize-1].value = (char *) malloc(sizeof(char) * 5); sprintf(EnvVars[EnvSize-1].value,"%d",STRMAX); } } } else ReportError("%s Failed to open file. File Name wasn't Provided.\n",GetNthArgValue(0)); } else cgiIn = stdin; //if successfull if (errcd == 0) { //must determine where data comes from here! DataSize = LoadData(); CgiOut("Content-type: text/html\n\n"); } else { CgiOut("Content Type: text/html\n\n<html><title>CGI Error</title>\n<body>\n<h1>CGI Error</h1>\nAn error occured while creating a response.\n</body></html>"); ReportError("Error Code %d occured while creating a response.\n",errcd); } return; };
int cgiEnvT::LoadData() { // if method is GET or HEAD, data is going to be in QUERY_STRING // if method is POST, data is going to be on cgiIn (a.k.a. STDIN) // if method is not in the ENV or == "" then use QUERY_STRING and the Command Line long ict = 0, i, j, k = 0, offset, errcd = 0; char *p, *q = (char *) malloc(sizeof(char) * STRMAX), *ContentLength, *input, *CgiMethod, *tmpstr; if (atol(((ContentLength = GetEnvValue("CONTENT_LENGTH")) != NULL)?ContentLength:"0") > 0) { CgiMethod = ((tmpstr = GetEnvValue("REQUEST_METHOD")) != NULL)?tmpstr:(char *)"NO_POST_METHOD"; if ((strcmp(CgiMethod,"POST") == 0) || (strcmp((NULL == GetNthArgValue(1))?GetNthArgValue(0):GetNthArgValue(1),"-f") == 0)) { char *xtra = (char *) malloc(sizeof(char) * MAXCGIINPUTLENGTH); input = (char *) malloc(sizeof(char) * MAXCGIINPUTLENGTH); fgets(input,MAXCGIINPUTLENGTH,cgiIn); while(!feof(cgiIn)) { fgets(xtra,MAXCGIINPUTLENGTH,cgiIn); strcat(input,xtra); } free(xtra); } else { input = (char *) malloc(sizeof(char) * STRMAX); if ((strcmp(CgiMethod,"GET") == 0) || (strcmp(CgiMethod,"HEAD") == 0)) input = GetEnvValue("QUERY_STRING"); else { input = GetEnvValue("QUERY_STRING"); //add all of argv here for ( i = 0; i < ArgSize; i++) { input = (char *) realloc(input, sizeof(char) * ((int) strlen(ArgVars[i])+1)); strcat(input,"&"); strcat(input,ArgVars[i]); //are the command line argv's in the form name=value? } } } } else { //prompt user for input here, if appropriate if (strcmp((NULL == GetNthArgValue(1))?GetNthArgValue(0):GetNthArgValue(1),"-f") != 0) //look at arg[1] for a -f, if its there, we read from an alternate file { fprintf(stdout,"Enter Your Input to %s:\n",GetNthArgValue(0)); input = (char *) malloc(sizeof(char) * MAXCGIINPUTLENGTH); fgets(input,MAXCGIINPUTLENGTH,stdin); } else errcd = 32; //same as ReportError("%s Failed to open file. File Name wasn't Provided.\n",GetNthArgValue(0)); } if (errcd == 0) { ict = ((int) strlen(input) > 0)?1:0; for(k = 0; k < (int) strlen(input); ict += (input[k++] == '&')?1:0); if ((ict != 0) && (q != NULL)) { DataVars = (struct STRTUPLE *) malloc(sizeof(struct STRTUPLE) * ict); strcpy(q,input); p = q; for(i = 0; i < ict; i++) { DataVars[i].name = (char *) malloc(sizeof(char) * length(p,'=') + 1); for(offset = j = 0; j < (int) strlen(p) && p[j] != '=' && j-offset < STRMAX; j++) DataVars[i].name[j-offset] = p[j]; DataVars[i].name[j-offset] = '\0'; DataVars[i].value = (char *) malloc(sizeof(char) * length(p+j+1,'&') + 1); for(offset = ++j; j < (int) strlen(p) && p[j] != '&' && j-offset < STRMAX; j++) DataVars[i].value[j-offset] = p[j]; DataVars[i].value[j-offset] = '\0'; p += ++j; } } free(input); } free(q); return (ict); }