void Molecule::read(std::string file) { InputFile fp(file); std::vector<std::string> lines; std::vector<std::string> pieces; fp.readFile(lines); std::string line, dat, units; unsigned int pos, nrat; double un; /* grab basisset from first line 1 */ line = strtrim(lines[0]); pos = strpos(line,"="); dat = substr(line,pos+1); basisset = strtrim(dat); basis.setType(basisset); //std::cout << basisset << std::endl; /* grab charge from line 2 */ line = strtrim(lines[1]); pos = strpos(line,"="); dat = substr(line,pos+1); charge = atoi(strtrim(dat).c_str() ); //std::cout << charge << std::endl; /* grab number of atoms from line 3 */ line = strtrim(lines[2]); pos = strpos(line,"="); dat = substr(line,pos+1); nrat = atoi(strtrim(dat).c_str() ); //std::cout << nrat << std::endl; /* grab length unit from first line 4 */ line = strtrim(lines[3]); pos = strpos(line,"="); dat = substr(line,pos+1); units = strtrim(dat); if(units.compare("bohr")==0) { un = 1; } if(units.compare("angstrom")==0) { un = 1.0 / 0.52917721092; } //std::cout << units << std::endl; double x, y, z; std::string element; for(unsigned int i=0; i<nrat; i++) { line = strtrim(lines[4+i]); pieces = explode(" ",line); element = strtrim(pieces[0]); x = atof(pieces[1].c_str() ) * un; y = atof(pieces[2].c_str() ) * un; z = atof(pieces[3].c_str() ) * un; addAtom(element, x, y, z); } }
BOOL CSWindow::itemPassedFilter(ListItem< StatusItem >* li) { wchar_t filter[MAX_PATH]; GetDlgItemText(m_handle, IDC_FILTER_FIELD, filter, _countof(filter)); if (mir_wstrlen(filter)) { wchar_t title[EXTRASTATUS_TITLE_LIMIT], message[EXTRASTATUS_MESSAGE_LIMIT]; mir_wstrcpy(title, li->m_item->m_tszTitle); mir_wstrcpy(message, li->m_item->m_tszMessage); if (strpos(wcslwr(title), wcslwr(filter)) == -1) if (strpos(wcslwr(message), wcslwr(filter)) == -1) return FALSE; } return TRUE; }
int8_t normal_to_fat12(const char* _n, char* _b){ static char bn[8]; static char be[3]; int16_t posdot, cntdot, i, i2; memset(bn, 0, 8); memset(be, 0, 8); memset(_b, ' ', 11); posdot = strpos(_n, '.'); cntdot = strcnt(_n, '.'); if(cntdot != 1) return DISK_MORE_DOTS; if(posdot == -1) return DISK_NOT_DOT; if(posdot == 0) return DISK_DOT_FIRST; if(posdot > 7) return DISK_DOT_PLUS_EIGHT; memcpy( bn, _n, posdot); memcpy( be, _n + posdot +1, 3); if(strcnt(bn, ' ')) return DISK_SPACE_IN_FILENAME; if(strcnt(be, ' ')) return DISK_SPACE_IN_EXT; if(strlen(be) != 3) return DISK_EXT_NOT_THREE; i2 = 0; for(i=0;i<8;++i) _b[i] = bn[i]; for(i=0;i<8;++i) if(_b[i] == 0) _b[i] = ' '; for(i=8;i<11;++i)_b[i] = be[i2++]; _b[11] = 0; return DISK_OP_OK; }
inline string xml_element::parse() const { string data; unsigned offset = 0; const char *source = content; while(*source) { if(*source == '&') { if(strbegin(source, "<")) { data[offset++] = '<'; source += 4; continue; } if(strbegin(source, ">")) { data[offset++] = '>'; source += 4; continue; } if(strbegin(source, "&")) { data[offset++] = '&'; source += 5; continue; } if(strbegin(source, "'")) { data[offset++] = '\''; source += 6; continue; } if(strbegin(source, """)) { data[offset++] = '"'; source += 6; continue; } } if(strbegin(source, "<!--")) { if(optional<unsigned> pos = strpos(source, "-->")) { source += pos() + 3; continue; } else { return ""; } } if(strbegin(source, "<![CDATA[")) { if(optional<unsigned> pos = strpos(source, "]]>")) { string cdata = substr(source, 9, pos() - 9); data << cdata; offset += strlen(cdata); source += offset + 3; continue; } else { return ""; } } //reject illegal characters if(*source == '&') return ""; if(*source == '<') return ""; if(*source == '>') return ""; data[offset++] = *source++; } data[offset] = 0; return data; }
void read_font_to_list( char* file ) { char linebuf[512]; char*pch,*bk; FILE*fp; int n; n = 0; fp = NULL; fp = fopen(file,"r"); if(fp == NULL) { printf("read file error\n"); return; } while(!feof(fp)) { fgets(linebuf,512,fp); if(strpos(linebuf,"ENCODING") == 0) { pch = strtok_r(linebuf," ", &bk); pch = strtok_r(NULL," ", &bk); // printf("= %s\n", pch); n = atoi(pch); while(!feof(fp)) { fgets(linebuf,512,fp); if(strpos(linebuf,"ENDCHAR") == 0) { strcat(wqy_font_list[n],linebuf); break; }else { strcat(wqy_font_list[n], linebuf); } } //printf("%s\n",wqy_font_list[n]); //fclose(fp); break; } } fclose(fp); }
DLLEXPORT int stripCRLFarr(char tempf[]) { /* old method char *tmp = (char*)malloc(strlen(tempf+1)); sprintf(tmp,"%s",tempf); tmp = stripCRLF(tmp); sprintf(tempf,"%s",tmp); //return tempf; */ /*new method*/ int n = strpos("\n", tempf); int r = strpos("\r", tempf); //printf("[n:%d/r:%d]\n", n, r); if ((n > 0) && (r > 0)) { if (n < r) { //strncpy(tempf,tempf,n-1); tempf[n-1] = '\0'; return 1; } else if (r < n) { //strncpy(tempf,tempf,r-1); tempf[r-1] = '\0'; return 1; } } else if ((n > 0) && (r < 0)) { tempf[n-1] = '\0'; return 1; } else if ((r > 0) && (n < 0)) { tempf[r-1] = '\0'; return 1; } else { return 0; } }
/* -------------------------------------------------------------------- */ static void sendRequest(void) { cPrintf(" Sending room request file."); doccr(); wxsnd(cfg.temppath, roomreqout, (char)strpos((char)tolower(node.ndprotocol[0]), extrncmd)); unlink(roomreqout); }
void main(void) { char x[35]; char c; strcpy(x, "Daniel Ferreira Bruno"); printf("\nO comprimento de '%s' eh: %u\n", x, strlen(x)); c = 'a'; printf("O primeiro indice de '%c' em '%s' eh: %d\n", c, x, strpos(x, c)); c = 'l'; printf("O primeiro indice de '%c' em '%s' eh: %d\n", c, x, strpos(x, c)); c = 'F'; printf("O primeiro indice de '%c' em '%s' eh: %d\n", c, x, strpos(x, c)); c = 'x'; printf("O primeiro indice de '%c' em '%s' eh: %d\n", c, x, strpos(x, c)); strcpy(x, "12%"); c = '%'; printf("O primeiro indice de '%c' em '%s' eh: %d\n", c, x, strpos(x, c)); c = '2'; printf("O primeiro indice de '%c' em '%s' eh: %d\n", c, x, strpos(x, c)); c = 'F'; printf("O primeiro indice de '%c' em '%s' eh: %d\n", c, x, strpos(x, c)); printf("\nO comprimento de '%s' eh: %u\n", x, strlen(x)); strcpy(x, "Daniel Silva"); c = 'S'; printf("O primeiro indice de '%c' em '%s' eh: %d\n", c, x, strpos(x, c)); printf("\nO comprimento de '%s' eh: %u\n", x, strlen(x)); printf("Pressione algo para sair"); getch(); }
/* -------------------------------------------------------------------- */ static void sendFiles(void) { cPrintf(" Sending mail and rooms."); doccr(); wxsnd(cfg.temppath, roomdataout, (char)strpos((char)tolower(node.ndprotocol[0]), extrncmd)); unlink(roomdataout); }
int GetOperatorToken( char cCharacter, char *pcToken) /* OPERATOR_TOKEN :== '=' */ /* :== '=' '=' */ /* :== '<' */ /* :== '>' */ /* :== '<' '=' */ /* :== '>' '=' */ /* :== '<' '>' */ /* :== '+' */ /* :== '-' */ /* :== '*' */ /* :== '/' */ /* :== '<' '<' */ /* :== '>' '>' */ /* :== '&' */ /* :== '|' */ /* :== '[' ']' */ /* The following two tokens are read as OPERATOR_TOKEN, but are translated */ /* to LEFT_ARROW_TOKEN or RIGHT_ARROW_TOKEN before leaving the scanner. */ /* :== '-' '>' */ /* :== '<' '-' */ { char *pcCompleteToken; pcCompleteToken = pcToken; /* store pointer to first token char */ *(pcToken++) = cCharacter; /* assign first character to token */ if (chrpos(cCharacter, "-=<>[/.") != NULL) /* if second character possible */ { cCharacter = GetChar(); /* read second character */ if (chrpos(cCharacter, "-=<>]/.") != NULL) /* if valid second character */ { *pcToken = cCharacter; /* add character */ pcToken[1] = 0; /* and make it zero terminated */ /* now a 2 byte operator is read. Check if this is a valid two byte */ /* operator. If not, put back the second character in the input stream. */ if (strpos(pcCompleteToken, "== <= >= <> << >> [] -> <- // ..") == NULL) { UngetChar(); } else { pcToken++; } } else { UngetChar(); /* else put second character back */ } } *pcToken = 0; /* terminate token */ return OPERATOR_TOKEN; }
str* get_domain(pdt_tree_t *pt, str *sp, int *plen) { int l, len; pdt_node_t *itn; str *domain; if(pt==NULL || sp==NULL || sp->s==NULL) { LM_ERR("bad parameters\n"); return NULL; } l = len = 0; itn = pt->head; domain = NULL; while(itn!=NULL && l < sp->len && l < PDT_MAX_DEPTH) { /* check validity */ if(strpos(pdt_char_list.s,sp->s[l]) < 0) { LM_ERR("invalid char at %d in [%.*s]\n", l, sp->len, sp->s); return NULL; } if(itn[strpos(pdt_char_list.s,sp->s[l])%PDT_NODE_SIZE].domain.s!=NULL) { domain = &itn[strpos(pdt_char_list.s,sp->s[l])%PDT_NODE_SIZE].domain; len = l+1; } itn = itn[strpos(pdt_char_list.s,sp->s[l])%PDT_NODE_SIZE].child; l++; } if(plen!=NULL) *plen = len; return domain; }
static uint16_t decode(const char *name) { string s(name); if(!strbegin(name, "KB")) return 0; ltrim(s, "KB"); unsigned id = strunsigned(s); auto pos = strpos(s, "::"); if(!pos) return 0; s = substr(s, pos() + 2); for(unsigned i = 0; i < Limit; i++) { if(s == KeyboardScancodeName[i]) return Base + Size * id + i; } return 0; }
static uint16_t decode(const char *name) { string s(name); if(!strbegin(name, "JP")) return 0; ltrim(s, "JP"); unsigned id = strunsigned(s); int pos = strpos(s, "::"); if(pos < 0) return 0; s = substr(s, pos + 2); for(unsigned i = 0; i < Limit; i++) { if(s == JoypadScancodeName[i]) return Base + Size * id + i; } return 0; }
/* -------------------------------------------------------------------- */ static void reciveRequest(void) { cPrintf(" Receiving room request file."); doccr(); wxrcv(cfg.temppath, roomreqin, (char)strpos((char)tolower(node.ndprotocol[0]), extrncmd)); if (!filexists(roomreqin)) { drop_dtr(); netFailed = TRUE; } }
/* -------------------------------------------------------------------- */ static void reciveFiles(void) { cPrintf(" Receiving mail and rooms."); doccr(); wxrcv(cfg.temppath, roomdatain, (char)strpos((char)tolower(node.ndprotocol[0]), extrncmd)); if (!filexists(roomdatain)) { drop_dtr(); netFailed = TRUE; } }
string operator[](const char *input) { for(unsigned i = 0; i < index_input.size(); i++) { if(index_input[i] == input) return index_output[i]; } //no match, use input; remove input identifier, if one exists if(strbegin(input, "{{")) { if(optional<unsigned> pos = strpos(input, "}}")) { string temp = substr(input, pos() + 2); return temp; } } return input; }
void DiskBrowser::updateFilter() { QString currentText = filter->currentText(); if(currentText.length() == 0) { model->setNameFilters(QStringList() << "*"); } else { string filters = currentText.toUtf8().constData(); filters = substr(filters, strpos(filters, "(")); ltrim(filters, "("); rtrim(filters, ")"); lstring filterPart; filterPart.split(" ", filters); QStringList filterList; for(unsigned i = 0; i < filterPart.size(); i++) filterList << (const char*)filterPart[i]; model->setNameFilters(filterList); } }
int ambigUnlink(const char *filename, const char *directory) { int count = 0; if (directory && !changedir(directory)) { return (0); } // keep going till it errors, which is end of directory FindFileC FF; if (FF.FindFirst(starstar)) { do { if (FF.IsNormalFile()) { // + 1 for strcat() call below #ifdef WINCIT char Name[MAX_PATH + 1]; #else char Name[_MAX_PATH + 1]; #endif CopyStringToBuffer(Name, FF.GetFullName()); if (!strpos('.', Name)) { strcat(Name, getmsg(433)); } // filename match wildcard? if (u_match(Name, filename)) { if (!unlink(Name)) { count++; } } } } while (FF.FindNext()); } return (count); }
/* REQUEST_get_cgi_name( const char* http_local_path ) @http_local_path - URI przekazane w ��daniu - zwraca ci�g znak�w b�d�cy nazw� skryptu. */ char* REQUEST_get_cgi_name( HTTP_SESSION *http_session ) { static char result[ MAX_PATH_LENGTH ]; int len = strlen( http_session->http_info.http_local_path ); /* Metody GET i HEAD */ if( http_session->http_info.method_name != POST ) { memset( result, '\0', MAX_PATH_LENGTH ); strncpy( result, http_session->http_info.http_local_path, len ); /* Usuni�cie reszty znak�w po znaku "?" */ if( strstr( result, "?" ) ) { result[ strpos( result, "?" ) ] = '\0'; } return ( ( char* )&result ); } else { /* Metoda POST */ return http_session->http_info.http_local_path; } }
colog_explode_t explode(char delimiter, char* str) { colog_explode_t exploded; int pos, end; exploded.list = NULL; exploded.length = 0; do { pos = strpos(delimiter, str); end = (pos == -1 ? strlen(str) - 2 : pos - 1); exploded.list = xrealloc(exploded.list, (exploded.length + 1) * sizeof(char *)); exploded.list[exploded.length] = xalloc((end + 2) * sizeof(char)); strncpy(exploded.list[exploded.length], str, end + 1); exploded.list[exploded.length][end + 1] = '\0'; exploded.length++; str += end + 2; } while (pos != -1); return exploded; }
int strsplit(const char *str, char *left, int lmaxlen, char *right, int rmaxlen) { int sp = strpos(str, ' '); int len = strlen(str); int lmax = low((sp > 0) ? sp : len, lmaxlen); strncpy(left, str, lmax); left[lmax] = '\0'; if(sp > 0 && len > sp) { int rmax = low((len - sp - 1), rmaxlen); strncpy(right, str + sp + 1, rmax); right[rmax] = '\0'; return 1; } return 0; }
/* replaces all occurences of what in dest with format */ static void stringreplace(char *dest, const char *what, const char *format, ... ) { char tmp[MAX_LABELSIZE]; int offset=0; va_list va; va_start(va, format); vsnprintf(tmp, MAX_LABELSIZE, format, va); va_end(va); /* no search string == replace the entire string */ if(!what) { memcpy(dest, tmp, strlen(tmp)); dest[strlen(tmp)] = 0; return; } while((offset = strpos(dest, what)) != -1) { memmove(dest + offset + strlen(tmp), dest + offset + strlen(what), strlen(dest + offset + strlen(what)) + 1); memcpy(dest + offset, tmp, strlen(tmp)); } }
static bool parse_reply_string(struct request *req) { int pos; ulong len; len = strtoul(req->buf+1, NULL, 10); if(len < 1) { lua_pushboolean(req->vm, false); return true; } pos = strpos(req->buf, "\r\n"); pos += 2; if(sdslen(req->buf) < (len+pos)) return false; req->buf = sdsrange(req->buf, pos, pos+len); lua_pushlstring(req->vm, req->buf, len); return true; }
int read_file(char *file, char buf[][MAX_CHAR]){ FILE *fp; char tmp[MAX_CHAR]; char str[100]; int n,pos; strcpy(str,home); strcat(str,file); fp = fopen(str, "r" ); if( fp == NULL ){ printf( "%sFile open failed.\n", file ); return -1; } n=0; while( fgets( tmp, MAX_CHAR, fp ) != NULL ){ if ( (pos = strpos( tmp, "#" )) !=0 ) { Trim(tmp); // printf("%s\n",tmp); strcpy(buf[n++],tmp); } } fclose(fp); return n; }
/* int analyze_server_response(int socket) return 0 or 1 when the cond regex is matched return -1 if no response from server */ int analyze_server_response(int s) { int runs = 0; while ((buf = hydra_receive_line(s)) != NULL) { runs++; //check for http redirection if (strstr(buf, "HTTP/1.1 3") != NULL || strstr(buf, "HTTP/1.0 3") != NULL || strstr(buf, "Status: 3") != NULL) { redirected_flag = 1; } else if (strstr(buf, "HTTP/1.1 401") != NULL || strstr(buf, "HTTP/1.0 401") != NULL) { auth_flag = 1; } else if ((strstr(buf, "HTTP/1.1 403") != NULL) || (strstr(buf, "HTTP/1.1 404") != NULL) || (strstr(buf, "HTTP/1.0 403") != NULL) || (strstr(buf, "HTTP/1.0 404") != NULL)) { return 0; } if (hydra_strcasestr(buf, "Location: ") != NULL) { char *startloc, *endloc; char str[2048]; startloc = hydra_strcasestr(buf, "Location: ") + strlen("Location: "); strncpy(str, startloc, sizeof(str) - 1); str[sizeof(str) - 1] = 0; endloc = strchr(str, '\n'); if (endloc != NULL) *endloc = 0; endloc = strchr(str, '\r'); if (endloc != NULL) *endloc = 0; strcpy(redirected_url_buff, str); } //there can be multiple cookies if (hydra_strcasestr(buf, "Set-Cookie: ") != NULL) { char *cookiebuf = buf; do { char *startcookie, *endcookie1, *endcookie2; char str[1024], tmpcookie[4096] = "", tmpname[128] = "", *ptr, *ptr2; memset(str, 0, sizeof(str)); startcookie = hydra_strcasestr(cookiebuf, "Set-Cookie: ") + strlen("Set-Cookie: "); strncpy(str, startcookie, sizeof(str) - 1); str[sizeof(str) - 1] = 0; endcookie1 = strchr(str, '\n'); endcookie2 = strchr(str, ';'); //terminate string after cookie data if (endcookie1 != NULL && endcookie1 < endcookie2) *endcookie1 = 0; else if (endcookie2 != NULL) *endcookie2 = 0; // is the cookie already there? if yes, remove it! if (index(startcookie, '=') != NULL && (ptr = index(startcookie, '=')) - startcookie + 1 <= sizeof(tmpname)) { strncpy(tmpname, startcookie, sizeof(tmpname) - 2); tmpname[sizeof(tmpname) - 2] = 0; ptr = index(tmpname, '='); *(++ptr) = 0; // is the cookie already in the cookiejar? (so, does it have to be replaced?) if ((ptr = hydra_strcasestr(cookie, tmpname)) != NULL) { // yes it is. // if the cookie is not in the beginning of the cookiejar, copy the ones before if (ptr != cookie && *(ptr - 1) == ' ') { strncpy(tmpcookie, cookie, ptr - cookie - 2); tmpcookie[ptr - cookie - 2] = 0; } ptr += strlen(tmpname); // if there are any cookies after this one in the cookiejar, copy them over if ((ptr2 = strstr(ptr, "; ")) != NULL) { ptr2 += 2; strncat(tmpcookie, ptr2, sizeof(tmpcookie) - strlen(tmpcookie) - 1); } if (debug) printf("[DEBUG] removing cookie %s in jar\n before: %s\n after: %s\n", tmpname, cookie, tmpcookie); strcpy(cookie, tmpcookie); } } ptr = index(str, '='); // only copy the cookie if it has a value (otherwise the server wants to delete the cookie if (ptr != NULL && *(ptr + 1) != ';' && *(ptr + 1) != 0 && *(ptr + 1) != '\n' && *(ptr + 1) != '\r') { if (strlen(cookie) > 0) strncat(cookie, "; ", sizeof(cookie) - strlen(cookie) - 1); strncat(cookie, str, sizeof(cookie) - strlen(cookie) - 1); } cookiebuf = startcookie; } while (hydra_strcasestr(cookiebuf, "Set-Cookie: ") != NULL); } #ifdef HAVE_PCRE if (hydra_string_match(buf, cond) == 1) { #else if (strstr(buf, cond) != NULL) { #endif free(buf); // printf("DEBUG: STRING %s FOUND!!:\n%s\n", cond, buf); return 1; } // else printf("DEBUG: STRING %s NOT FOUND:\n%s\n", cond, buf); free(buf); } if (runs == 0) { if (debug) hydra_report(stderr, "DEBUG: no response from server\n"); return -1; } return 0; } void hydra_reconnect(int s, char *ip, int port, unsigned char options) { if (s >= 0) s = hydra_disconnect(s); if ((options & OPTION_SSL) == 0) { s = hydra_connect_tcp(ip, port); } else { s = hydra_connect_ssl(ip, port); } } int start_http_form(int s, char *ip, int port, unsigned char options, char *miscptr, FILE * fp, char *type) { char *empty = ""; char *login, *pass, buffer[9000]; char header[8096], *upd3variables; int found = !success_cond, i, j; memset(header, 0, sizeof(header)); cookie[0] = 0; // reset cookies from potential previous attempt if (strlen(login = hydra_get_next_login()) == 0) login = empty; if (strlen(pass = hydra_get_next_password()) == 0) pass = empty; upd3variables = strrep(variables, "^PASS^", pass); upd3variables = strrep(upd3variables, "^USER^", login); /* again: no snprintf to be portable. dont worry, buffer cant overflow */ if (use_proxy == 1 && proxy_authentication != NULL) { // proxy with authentication if (getcookie) { //doing a GET to save cookies sprintf(buffer, "GET http://%s:%d%.600s HTTP/1.0\r\nHost: %s\r\nProxy-Authorization: Basic %s\r\nUser-Agent: Mozilla 5.0 (Hydra Proxy Auth)\r\n%s%s\r\n", webtarget, webport, cookieurl, webtarget, proxy_authentication, header, userheader); if (hydra_send(s, buffer, strlen(buffer), 0) < 0) { return 1; } i = analyze_server_response(s); // return value ignored if (strlen(cookie) > 0) { sprintf(header, "Cookie: %s\r\n", cookie); } hydra_reconnect(s, ip, port, options); } if (strcmp(type, "POST") == 0) { sprintf(buffer, "POST http://%s:%d%.600s HTTP/1.0\r\nHost: %s\r\nProxy-Authorization: Basic %s\r\nUser-Agent: Mozilla/5.0 (Hydra Proxy Auth)\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: %d\r\n%s%s\r\n%s", webtarget, webport, url, webtarget, proxy_authentication, (int) strlen(upd3variables), header, userheader, upd3variables); if (hydra_send(s, buffer, strlen(buffer), 0) < 0) { return 1; } } else { sprintf(buffer, "GET http://%s:%d%.600s?%s HTTP/1.0\r\nHost: %s\r\nProxy-Authorization: Basic %s\r\nUser-Agent: Mozilla/5.0 (Hydra Proxy Auth)\r\n%s%s\r\n", webtarget, webport, url, upd3variables, webtarget, proxy_authentication, header, userheader); if (hydra_send(s, buffer, strlen(buffer), 0) < 0) { return 1; } } } else { if (use_proxy == 1) { // proxy without authentication if (getcookie) { //doing a GET to get cookies sprintf(buffer, "GET http://%s:%d%.600s HTTP/1.0\r\nHost: %s\r\nUser-Agent: Mozilla/5.0 (Hydra Proxy)\r\n%s%s\r\n", webtarget, webport, cookieurl, webtarget, header, userheader); if (hydra_send(s, buffer, strlen(buffer), 0) < 0) { return 1; } i = analyze_server_response(s); // ignore result if (strlen(cookie) > 0) { sprintf(header, "Cookie: %s\r\n", cookie); } hydra_reconnect(s, ip, port, options); } if (strcmp(type, "POST") == 0) { sprintf(buffer, "POST http://%s:%d%.600s HTTP/1.0\r\nHost: %s\r\nUser-Agent: Mozilla/5.0 (Hydra)\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: %d\r\n%s%s\r\n%s", webtarget, webport, url, webtarget, (int) strlen(upd3variables), header, userheader, upd3variables); if (hydra_send(s, buffer, strlen(buffer), 0) < 0) { return 1; } } else { sprintf(buffer, "GET http://%s:%d%.600s?%s HTTP/1.0\r\nHost: %s\r\nUser-Agent: Mozilla/5.0 (Hydra)\r\n%s%s\r\n", webtarget, webport, url, upd3variables, webtarget, header, userheader); if (hydra_send(s, buffer, strlen(buffer), 0) < 0) { return 1; } } } else { // direct web server, no proxy if (getcookie) { //doing a GET to save cookies sprintf(buffer, "GET %.600s HTTP/1.0\r\nHost: %s\r\nUser-Agent: Mozilla/5.0 (Hydra)\r\n%s\r\n", cookieurl, webtarget, userheader); if (hydra_send(s, buffer, strlen(buffer), 0) < 0) { return 1; } i = analyze_server_response(s); // ignore result if (strlen(cookie) > 0) { sprintf(header, "Cookie: %s\r\n", cookie); } hydra_reconnect(s, ip, port, options); } if (strcmp(type, "POST") == 0) { sprintf(buffer, "POST %.600s HTTP/1.0\r\nHost: %s\r\nUser-Agent: Mozilla/5.0 (Hydra)\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: %d\r\n%s%s\r\n%s", url, webtarget, (int) strlen(upd3variables), header, userheader, upd3variables); if (hydra_send(s, buffer, strlen(buffer), 0) < 0) { return 1; } } else { sprintf(buffer, "GET %.600s?%s HTTP/1.0\r\nHost: %s\r\nUser-Agent: Mozilla/5.0 (Hydra)\r\n%s%s\r\n", url, upd3variables, webtarget, header, userheader); if (hydra_send(s, buffer, strlen(buffer), 0) < 0) { return 1; } } } } found = analyze_server_response(s); if (auth_flag) { // we received a 401 error - user using wrong module hydra_report(stderr, "[ERROR] the target is using HTTP auth, not a web form, received HTTP error code 401. Use module \"http%s-get\" instead.\n", (options & OPTION_SSL) > 0 ? "s" : ""); return 4; } if (strlen(cookie) > 0) { sprintf(header, "Cookie: %.1000s\r\n", cookie); } //if page was redirected, follow the location header redirected_cpt = MAX_REDIRECT; if (debug) printf("[DEBUG] attempt result: found %d, redirect %d, location: %s\n", found, redirected_flag, redirected_url_buff); while (found == 0 && redirected_flag && (redirected_url_buff[0] != 0) && (redirected_cpt > 0)) { //we have to split the location char *startloc, *endloc; char str[2048]; char str2[2048]; char str3[2048]; redirected_cpt--; redirected_flag = 0; //check if the redirect page contains the fail/success condition #ifdef HAVE_PCRE if (hydra_string_match(redirected_url_buff, cond) == 1) { #else if (strstr(redirected_url_buff, cond) != NULL) { #endif found = success_cond; } else { //location could be either absolute http(s):// or / something //or relative startloc = strstr(redirected_url_buff, "://"); if (startloc != NULL) { startloc += strlen("://"); if ((endloc=strchr(startloc, '\r')) != NULL) { startloc[endloc - startloc] = 0; } if ((endloc=strchr(startloc, '\n')) != NULL) { startloc[endloc - startloc] = 0; } strcpy(str, startloc); endloc = strchr(str, '/'); if (endloc != NULL) { strncpy(str2, str, endloc - str); str2[endloc - str] = 0; } else strncpy(str2, str, sizeof(str)); if (strlen(str) - strlen(str2) == 0) { strcpy(str3, "/"); } else { strncpy(str3, str + strlen(str2), strlen(str) - strlen(str2) - 1); str3[strlen(str) - strlen(str2) - 1] = 0; } } else { strncpy(str2, webtarget, sizeof(str2)); if (redirected_url_buff[0] != '/') { //it's a relative path, so we have to concatenate it //with the path from the first url given char *urlpath; char urlpath_extracted[2048]; memset(urlpath_extracted, 0, sizeof(urlpath_extracted)); urlpath=strrchr(url, '/'); if (urlpath != NULL) { strncpy(urlpath_extracted, url, urlpath-url); sprintf(str3, "%.1000s/%.1000s", urlpath_extracted, redirected_url_buff); } else { sprintf(str3, "%.1000s/%.1000s", url, redirected_url_buff); } } else strncpy(str3, redirected_url_buff, sizeof(str3)); if (debug) hydra_report(stderr, "[DEBUG] host=%s redirect=%s origin=%s\n", str2, str3,url); } if (str3[0] != '/') { j = strlen(str3); str3[j + 1] = 0; for (i = j; i > 0; i--) str3[i] = str3[i - 1]; str3[0] = '/'; } if (verbose) hydra_report(stderr, "[VERBOSE] Page redirected to http://%s%s\n", str2, str3); //re-use the code above to check for proxy use if (use_proxy == 1 && proxy_authentication != NULL) { // proxy with authentication sprintf(buffer, "GET http://%s:%d%.600s HTTP/1.0\r\nHost: %s\r\nProxy-Authorization: Basic %s\r\nUser-Agent: Mozilla/4.0 (Hydra)\r\n%s\r\n", webtarget, webport, str3, str2, proxy_authentication, header); } else { if (use_proxy == 1) { // proxy without authentication sprintf(buffer, "GET http://%s:%d%.600s HTTP/1.0\r\nHost: %s\r\nUser-Agent: Mozilla/4.0 (Hydra)\r\n%s\r\n", webtarget, webport, str3, str2, header); } else { //direct web server, no proxy sprintf(buffer, "GET %.600s HTTP/1.0\r\nHost: %s\r\nUser-Agent: Mozilla/4.0 (Hydra)\r\n%s\r\n", str3, str2, header); } } hydra_reconnect(s, ip, port, options); if (hydra_send(s, buffer, strlen(buffer), 0) < 0) { return 1; } found = analyze_server_response(s); if (strlen(cookie) > 0) { sprintf(header, "Cookie: %s\r\n", cookie); } } } //if the last status is still 3xx, set it as a false if (found != -1 && found == success_cond && redirected_flag == 0 && redirected_cpt >= 0) { hydra_report_found_host(port, ip, "www-form", fp); hydra_completed_pair_found(); } else { hydra_completed_pair(); } return 1; } void service_http_form(char *ip, int sp, unsigned char options, char *miscptr, FILE * fp, int port, char *type) { int run = 1, next_run = 1, sock = -1; int myport = PORT_HTTP, mysslport = PORT_HTTP_SSL; char *ptr, *ptr2; hydra_register_socket(sp); if (webtarget != NULL && (webtarget = strstr(miscptr, "://")) != NULL) { webtarget += strlen("://"); if ((ptr2 = index(webtarget, ':')) != NULL) { /* step over port if present */ *ptr2 = 0; ptr2++; ptr = ptr2; if (*ptr == '/' || (ptr = index(ptr2, '/')) != NULL) miscptr = ptr; else miscptr = slash; /* to make things easier to user */ } else if ((ptr2 = index(webtarget, '/')) != NULL) { if (freemischttpform == 0) { freemischttpform = 1; miscptr = malloc(strlen(ptr2) + 1); strcpy(miscptr, ptr2); *ptr2 = 0; } } else webtarget = NULL; } if (cmdlinetarget != NULL && webtarget == NULL) webtarget = cmdlinetarget; else if (webtarget == NULL && cmdlinetarget == NULL) webtarget = hydra_address2string(ip); if (port != 0) webport = port; else if ((options & OPTION_SSL) == 0) webport = myport; else webport = mysslport; sprintf(bufferurl, "%.1000s", miscptr); url = strtok(bufferurl, ":"); variables = strtok(NULL, ":"); cond = strtok(NULL, ":"); sprintf(cookieurl, "%.1000s", url); //condition now have to contain F or S to set the fail or success condition if (cond && (strpos(cond, "F=") == 0)) { success_cond = 0; cond += 2; } else if (cond && (strpos(cond, "S=") == 0)) { success_cond = 1; cond += 2; } else { //by default condition is a fail success_cond = 0; } while ((optional1 = strtok(NULL, ":")) != NULL) { switch(optional1[0]) { case 'c': // fall through case 'C': sprintf(cookieurl, "%.1000s", optional1 + 2); break; case 'h': // fall through case 'H': if (sizeof(userheader) - strlen(userheader) > 4) { strncat(userheader, optional1 + 2, sizeof(userheader) - strlen(userheader) - 4); strcat(userheader, ":"); optional1 = strtok(NULL, ":"); strncat(userheader, optional1, sizeof(userheader) - strlen(userheader) - 3); strcat(userheader, "\r\n"); } break; // no default } } while (1) { if (run == 2) { if (memcmp(hydra_get_next_pair(), &HYDRA_EXIT, sizeof(HYDRA_EXIT)) == 0) { if (freemischttpform) free(miscptr); freemischttpform = 0; hydra_child_exit(1); } } switch (run) { case 1: /* connect and service init function */ { if (sock >= 0) sock = hydra_disconnect(sock); if ((options & OPTION_SSL) == 0) { if (port != 0) myport = port; sock = hydra_connect_tcp(ip, myport); port = myport; } else { if (port != 0) mysslport = port; sock = hydra_connect_ssl(ip, mysslport); port = mysslport; } if (sock < 0) { hydra_report(stderr, "[ERROR] Child with pid %d terminating, can not connect\n", (int) getpid()); if (freemischttpform) free(miscptr); freemischttpform = 0; hydra_child_exit(1); } next_run = 2; break; } case 2: /* run the cracking function */ next_run = start_http_form(sock, ip, port, options, miscptr, fp, type); break; case 3: /* clean exit */ if (sock >= 0) sock = hydra_disconnect(sock); if (freemischttpform) free(miscptr); freemischttpform = 0; hydra_child_exit(0); break; case 4: /* silent error exit */ if (sock >= 0) sock = hydra_disconnect(sock); if (freemischttpform) free(miscptr); freemischttpform = 0; hydra_child_exit(1); break; default: if (freemischttpform) free(miscptr); freemischttpform = 0; hydra_report(stderr, "[ERROR] Caught unknown return code, exiting!\n"); hydra_child_exit(0); } run = next_run; } if (freemischttpform) free(miscptr); }
/** * \fn int VFS_MkNod(char *Path, Uint Flags) * \brief Create a new node in a directory * \param Path Path of new node * \param Flags Flags to apply to the node */ int VFS_MkNod(const char *Path, Uint Flags) { tVFS_Mount *mountpt; char *absPath, *name; int pos = 0, oldpos = 0; int next = 0; tVFS_Node *parent; tVFS_Node *ret; ENTER("sPath xFlags", Path, Flags); absPath = VFS_GetAbsPath(Path); LOG("absPath = '%s'", absPath); while( (next = strpos(&absPath[pos+1], '/')) != -1 ) { LOG("next = %i", next); pos += next+1; LOG("pos = %i", pos); oldpos = pos; } absPath[oldpos] = '\0'; // Mutilate path name = &absPath[oldpos+1]; LOG("absPath = '%s', name = '%s'", absPath, name); // Check for root if(absPath[0] == '\0') parent = VFS_ParsePath("/", NULL, &mountpt); else parent = VFS_ParsePath(absPath, NULL, &mountpt); LOG("parent = %p", parent); if(!parent) { errno = ENOENT; goto _error; } // Permissions Check if( !VFS_CheckACL(parent, VFS_PERM_EXECUTE|VFS_PERM_WRITE) ) { errno = EACCES; goto _error; } LOG("parent = %p", parent); if(!parent->Type || !parent->Type->MkNod) { Log_Warning("VFS", "VFS_MkNod - Directory has no MkNod method"); errno = ENOTDIR; goto _error; } // Create node ret = parent->Type->MkNod(parent, name, Flags); _CloseNode(ret); // Free allocated string free(absPath); // Free Parent ASSERT(mountpt->OpenHandleCount>0); mountpt->OpenHandleCount --; _CloseNode(parent); // Return whatever the driver said LEAVE('i', ret==NULL); return ret==NULL; _error: if( parent ) { _CloseNode(parent); ASSERT(mountpt->OpenHandleCount>0); mountpt->OpenHandleCount --; } free(absPath); LEAVE('i', -1); return -1; }
int cdecl TERMWINDOWMEMBER GetOneKey(const char *prompt, const char *keys, const char dfault, BlurbFiles HelpBlurb, ...) { assert(strchr(keys, dfault)); const char *FullNames[36]; // A-Z0-9 better be enough... va_list ap; int KeyCount = strlen(keys); if (KeyCount > 36) { KeyCount = 36; } va_start(ap, HelpBlurb); for (int n = 0; n < KeyCount; ++n) { FullNames[n] = va_arg(ap, const char *); } va_end(ap); Bool ShowFull = !CurrentUser->IsExpert(); int RetVal; dowhattype oldDowhat = DoWhat; SetDoWhat(PROMPT); Bool DoAgain; do { doCR(); OC.SetOutFlag(IMPERVIOUS); sprintf(gprompt, getmsg(52), prompt); if (ShowFull) { for (int i = 0; i < KeyCount; i++) { strcat(gprompt, FullNames[i]); strcat(gprompt, getmsg(138)); } gprompt[strlen(gprompt) - 1] = 0; strcat(gprompt, getmsg(148)); strcat(gprompt, FullNames[strpos(dfault, keys) - 1]); } else { // This whole bit is quite gross. cope. label Temp; Temp[1] = '/'; Temp[2] = 0; for (int i = 0; i < KeyCount; i++) { Temp[0] = keys[i]; strcat(gprompt, Temp); } gprompt[strlen(gprompt) - 1] = 0; Temp[0] = ')'; Temp[1] = '['; Temp[2] = dfault; Temp[3] = 0; strcat(gprompt, Temp); } strcat(gprompt, getmsg(189)); mPrintf(pcts, gprompt); int errors = 0; do { DoAgain = FALSE; int c = toupper(iCharNE()); if ((c == '\n') || (c == '\r')) { c = dfault; } else if (c == ESC || (!c && !HaveConnectionToUser())) { doCR(); RetVal = CERROR; break; } if (!c && HaveConnectionToUser()) { continue; } if (strchr(keys, c)) { RetVal = strpos((char) c, keys) - 1; mPrintfCR(pcts, FullNames[RetVal]); break; } else { if (c == '?') { DoAgain = TRUE; if (ShowFull) { if (HelpBlurb == MAXBLBS) { CRmPrintfCR(getmsg(103)); } else { doCR(); dispBlb(HelpBlurb); } } else { ShowFull = TRUE; doCR(); } break; } else { errors++; if (errors > cfg.maxerror && !onConsole) { CITWINDOW *w = ScreenSaver.IsOn() ? NULL : CitWindowsMsg(NULL, getmsg(685), getmsg(79)); Hangup(); if (w) { destroyCitWindow(w, FALSE); } } } } } while (HaveConnectionToUser()); } while (HaveConnectionToUser() && DoAgain); // This HaveConnectionToUser() is probably redundant, but safe OC.SetOutFlag(OUTOK); SetDoWhat(oldDowhat); if (!HaveConnectionToUser()) { return (strpos(dfault, keys) - 1); } return (RetVal); }
optional<unsigned> string::position(const char *key) const { return strpos(data, key); }
ptr_header_node initialize(char *ip, unsigned char options, char *miscptr) { ptr_header_node ptr_head = NULL; char *ptr, *ptr2, *proxy_string; if (webtarget != NULL && (webtarget = strstr(miscptr, "://")) != NULL) { webtarget += strlen("://"); if ((ptr2 = index(webtarget, ':')) != NULL) { /* step over port if present */ *ptr2 = 0; ptr2++; ptr = ptr2; if (*ptr == '/' || (ptr = index(ptr2, '/')) != NULL) miscptr = ptr; else miscptr = slash; /* to make things easier to user */ } else if ((ptr2 = index(webtarget, '/')) != NULL) { if (freemischttpform == 0) { if ((miscptr = malloc(strlen(ptr2) + 1)) != NULL) { freemischttpform = 1; strcpy(miscptr, ptr2); *ptr2 = 0; } } } else webtarget = NULL; } if (cmdlinetarget != NULL && webtarget == NULL) webtarget = cmdlinetarget; else if (webtarget == NULL && cmdlinetarget == NULL) webtarget = hydra_address2string(ip); if (port != 0) webport = port; else if ((options & OPTION_SSL) == 0) webport = PORT_HTTP; else webport = PORT_HTTP_SSL; sprintf(bufferurl, "%.1000s", miscptr); url = bufferurl; ptr = url; while (*ptr != 0 && (*ptr != ':' || *(ptr - 1) == '\\')) ptr++; if (*ptr != 0) *ptr++ = 0; variables = ptr; while (*ptr != 0 && (*ptr != ':' || *(ptr - 1) == '\\')) ptr++; if (*ptr != 0) *ptr++ = 0; cond = ptr; while (*ptr != 0 && (*ptr != ':' || *(ptr - 1) == '\\')) ptr++; if (*ptr != 0) *ptr++ = 0; optional1 = ptr; if (strstr(url, "\\:") != NULL) { if ((ptr = malloc(strlen(url))) != NULL) { strcpy(ptr, hydra_strrep(url, "\\:", ":")); url = ptr; } } if (strstr(variables, "\\:") != NULL) { if ((ptr = malloc(strlen(variables))) != NULL) { strcpy(ptr, hydra_strrep(variables, "\\:", ":")); variables = ptr; } } if (strstr(cond, "\\:") != NULL) { if ((ptr = malloc(strlen(cond))) != NULL) { strcpy(ptr, hydra_strrep(cond, "\\:", ":")); cond = ptr; } } if (url == NULL || variables == NULL || cond == NULL /*|| optional1 == NULL */ ) hydra_child_exit(2); if (*cond == 0) { fprintf(stderr, "[ERROR] invalid number of parameters in module option\n"); return NULL; } sprintf(cookieurl, "%.1000s", url); //conditions now have to contain F or S to set the fail or success condition if (*cond != 0 && (strpos(cond, "F=") == 0)) { success_cond = 0; cond += 2; } else if (*cond != 0 && (strpos(cond, "S=") == 0)) { success_cond = 1; cond += 2; } else { //by default condition is a fail success_cond = 0; } /* * Parse the user-supplied options. * Beware of the backslashes (\)! */ while (*optional1 != 0) { switch (optional1[0]) { case 'c': // fall through case 'C': ptr = optional1 + 2; while (*ptr != 0 && (*ptr != ':' || *(ptr - 1) == '\\')) ptr++; if (*ptr != 0) *ptr++ = 0; sprintf(cookieurl, "%.1000s", hydra_strrep(optional1 + 2, "\\:", ":")); optional1 = ptr; break; case 'h': // add a new header at the end ptr = optional1 + 2; while (*ptr != 0 && *ptr != ':') ptr++; if (*(ptr - 1) == '\\') *(ptr - 1) = 0; if (*ptr != 0){ *ptr = 0; ptr += 2; } ptr2 = ptr; while (*ptr2 != 0 && (*ptr2 != ':' || *(ptr2 - 1) == '\\')) ptr2++; if (*ptr2 != 0) *ptr2++ = 0; /* * At this point: * - (optional1 + 2) contains the header's name * - ptr contains the header's value */ if (add_header(&ptr_head, optional1 + 2, hydra_strrep(ptr, "\\:", ":"), HEADER_TYPE_USERHEADER)) { // Success: break the switch and go ahead optional1 = ptr2; break; } // Error: abort execution hydra_report(stderr, "[ERROR] Out of memory for HTTP headers."); return NULL; case 'H': // add a new header, or replace an existing one's value ptr = optional1 + 2; while (*ptr != 0 && *ptr != ':') ptr++; if (*(ptr - 1) == '\\') *(ptr - 1) = 0; if (*ptr != 0){ *ptr = 0; ptr += 2; } ptr2 = ptr; while (*ptr2 != 0 && (*ptr2 != ':' || *(ptr2 - 1) == '\\')) ptr2++; if (*ptr2 != 0) *ptr2++ = 0; /* * At this point: * - (optional1 + 2) contains the header's name * - ptr contains the header's value */ if (add_header(&ptr_head, optional1 + 2, hydra_strrep(ptr, "\\:", ":"), HEADER_TYPE_USERHEADER_REPL)) { // Success: break the switch and go ahead optional1 = ptr2; break; } // Error: abort execution hydra_report(stderr, "[ERROR] Out of memory for HTTP headers."); return NULL; // no default } } /* again: no snprintf to be portable. dont worry, buffer cant overflow */ if (use_proxy == 1 && proxy_authentication != NULL) { // proxy with authentication add_header(&ptr_head, "Host", webtarget, HEADER_TYPE_DEFAULT); add_header(&ptr_head, "User-Agent", "Mozilla 5.0 (Hydra Proxy Auth)", HEADER_TYPE_DEFAULT); proxy_string = (char *) malloc(strlen(proxy_authentication) + 6); if (proxy_string) { strcpy(proxy_string, "Basic "); strncat(proxy_string, proxy_authentication, strlen(proxy_authentication) - 6); add_header(&ptr_head, "Proxy-Authorization", proxy_string, HEADER_TYPE_DEFAULT); } else { hydra_report(stderr, "Out of memory for \"Proxy-Authorization\" header."); return NULL; } if (getcookie) { //doing a GET to save cookies cookie_request = stringify_headers(&ptr_head); } normal_request = stringify_headers(&ptr_head); } else { if (use_proxy == 1) { // proxy without authentication add_header(&ptr_head, "Host", webtarget, HEADER_TYPE_DEFAULT); add_header(&ptr_head, "User-Agent", "Mozilla/5.0 (Hydra Proxy)", HEADER_TYPE_DEFAULT); if (getcookie) { //doing a GET to get cookies cookie_request = stringify_headers(&ptr_head); } normal_request = stringify_headers(&ptr_head); } else { // direct web server, no proxy add_header(&ptr_head, "Host", webtarget, HEADER_TYPE_DEFAULT); add_header(&ptr_head, "User-Agent", "Mozilla/5.0 (Hydra)", HEADER_TYPE_DEFAULT); if (getcookie) { //doing a GET to save cookies cookie_request = stringify_headers(&ptr_head); } normal_request = stringify_headers(&ptr_head); } } return ptr_head; }
void irc_getuser(char *buf, char u[]) { sscanf(buf,":%s!",u); int n=strpos("!",u); if (n>0) u[n-1]=0; }