/* DoParsePart (static) * * Private function used to pipe the output of 1847 parsing into a file. */ static int DoParsePart(BufTypePtr pInBuf, FILE *fOut, emsMIMEtypeP *mimePtr, int bDeMime, PartParseStatePtr pState) { if (!pInBuf) // Input buf NULL indicates 'cleanup' { if (!pState->bFoundHeader) return (FALSE); else return (TRUE); } if (!pState->bFoundHeader) { resetpos_buf(pState->pSearchBuf); if (pState->nPrevEndMatch > 0) { /* Check for completion of span */ // If doesn't continue match, returns zero // otherwise returns number of chars of pSearchBuf that have been matched unsigned int nNewMatched = completecount_buf(pInBuf, pState->pSearchBuf, pState->nPrevEndMatch); if (nNewMatched == buflen_buf(pState->pSearchBuf)) /* complete match made */ { pState->bFoundHeader = TRUE; pState->nPrevEndMatch = 0; bufncat_buf(pState->pBuf, pInBuf, (buflen_buf(pState->pSearchBuf) - (pState->nPrevEndMatch))); } else if (nNewMatched != 0) /* Continued to match, but not completed yet -- the input buffer is smaller than the pSearchBuf */ { bufncat_buf(pState->pBuf, pInBuf, poslen_buf(pInBuf)); pState->nPrevEndMatch = nNewMatched; return (TRUE); } else /* No match continuation */ { pState->nPrevEndMatch = 0; } } resetpos_buf(pState->pSearchBuf); // Still not found -- no span if (!pState->bFoundHeader) { // Find match of pSearchBuf, either complete or end-spanning // return number of chars to skip before match unsigned int nSkip = skipcount_buf(pInBuf, pState->pSearchBuf); unsigned int nRemain = poslen_buf(pInBuf) - nSkip; if (nRemain == 0) // Not found { bufncat_buf(pState->pBuf, pInBuf, poslen_buf(pInBuf)); return (TRUE); } else if (nRemain > buflen_buf(pState->pSearchBuf)) /* Found 'complete' */ { pState->bFoundHeader = TRUE; bufncat_buf(pState->pBuf, pInBuf, (nSkip + buflen_buf(pState->pSearchBuf)) ); } else // Partial possible { pState->nPrevEndMatch = nRemain; bufncat_buf(pState->pBuf, pInBuf, poslen_buf(pInBuf)); return (TRUE); } } // ---------- Now we know it is found ---------- unsigned int nLen = buflen_buf(pState->pBuf); char *pHeader = (char *) malloc(nLen + 1); strncpy(pHeader, getbuf_buf(pState->pBuf), nLen); { char *pCT = rfc822_extract_header(pHeader, "Content-Type:"); if (mimePtr) { if (pCT) { *mimePtr = parse_make_mime_type(pCT); } else { *mimePtr = make_mime_type("text", "plain", "1.0"); } } safefree(pCT); } if (bDeMime) { { char *pCTE = rfc822_extract_cte(pHeader); if (pCTE) pState->cte = rfc822_parse_cte(pCTE); else pState->cte = CTE_NONE; /* No CTE header, so no encoding */ safefree(pCTE); } switch (pState->cte) { // BASE64 case CTE_Base64: { // BASE64 expands about 1/3 unsigned int preEncBufLen = ((kBufferSize * 10) / 6); pState->preEncBuffer = (char *) malloc(preEncBufLen); pState->d64state = (Dec64Ptr) malloc(sizeof(Dec64)); // Used by Decode64() pState->d64state->decoderState = 0; pState->d64state->invalCount = 0; pState->d64state->padCount = 0; pState->d64state->partial = 0; pState->d64state->wasCR = FALSE; } break; // QUOTED-PRINTABLE case CTE_QP: { // QP expands max of 3 times unsigned int preEncBufLen = (kBufferSize * 4); pState->preEncBuffer = (char *) malloc(preEncBufLen); pState->dQPstate = (DecQPPtr) malloc(sizeof(EncQP)); pState->dQPstate->CurState = qpNormal; pState->dQPstate->cLastChar = 0; } break; // Otherwise, no encoding default: break; } } else { fwrite(getbuf_buf(pState->pBuf), sizeof(char), nLen, fOut); } safefree(pHeader) free_buf(pState->pBuf); } // ---------- Now we know it is found and header is init'd ---------- long errorcnt; switch (pState->cte) { case CTE_Base64: { unsigned int nReadLen = Decode64(getpos_buf(pInBuf), poslen_buf(pInBuf), pState->preEncBuffer, pState->d64state, &errorcnt); fwrite(pState->preEncBuffer, sizeof(char), nReadLen, fOut); } break; case CTE_QP: { unsigned int nReadLen = DecodeQP(getpos_buf(pInBuf), poslen_buf(pInBuf), pState->preEncBuffer, pState->dQPstate, &errorcnt); fwrite(pState->preEncBuffer, sizeof(char), nReadLen, fOut); } break; default: /* 7bit, 8bit, binary, none */ { fwrite(getpos_buf(pInBuf), sizeof(char), poslen_buf(pInBuf), fOut); } break; } return (TRUE); }
bool SmbAuthenticate(char* name, char* password, char* domainname, char* groupname, UINT timeout, UCHAR* challenge8, UCHAR* MsChapV2_ClientResponse, UCHAR* nt_pw_hash_hash) { bool auth = false; int fds[2]; FILE* out, *in; PID pid; char buffer[255]; char ntlm_timeout[32]; char* proc_parameter[6]; if (name == NULL || password == NULL || domainname == NULL || groupname == NULL) { Debug("Sam.c - SmbAuthenticate - wrong password parameter\n"); return false; } if (password[0] == '\0' && (challenge8 == NULL || MsChapV2_ClientResponse == NULL || nt_pw_hash_hash == NULL)) { Debug("Sam.c - SmbAuthenticate - wrong MsCHAPv2 parameter\n"); return false; } Zero(buffer, sizeof(buffer)); // Truncate string if unsafe char EnSafeStr(domainname, '\0'); if (strlen(domainname) > 255) { // there is no domainname longer then 255 chars! // http://tools.ietf.org/html/rfc1035 section 2.3.4 domainname[255] = '\0'; } // set timeout to 15 minutes even if timeout is disabled, to prevent ntlm_auth from hung up if (timeout <= 0 || timeout > 900) { timeout = 999; } snprintf(ntlm_timeout, sizeof(ntlm_timeout), "%is", timeout); Debug("Sam.c - timeout for ntlm_auth %s\n", ntlm_timeout); proc_parameter[0] = "timeout"; proc_parameter[1] = ntlm_timeout; proc_parameter[2] = "ntlm_auth"; proc_parameter[3] = "--helper-protocol=ntlm-server-1"; proc_parameter[4] = 0; if (strlen(groupname) > 1) { // DNS Name 255 chars + OU names are limited to 64 characters + cmdline 32 + 1 char requiremember[352]; // Truncate string if unsafe char EnSafeStr(groupname, '\0'); snprintf(requiremember, sizeof(requiremember), "--require-membership-of=%s\\%s", domainname, groupname); proc_parameter[4] = requiremember; proc_parameter[5] = 0; } pid = OpenChildProcess("timeout", proc_parameter, fds); if (pid < 0) { Debug("Sam.c - SmbCheckLogon - error fork child process (ntlm_auth)\n"); return false; } out = fdopen(fds[1], "w"); if (out == 0) { CloseChildProcess(pid, fds); Debug("Sam.c - cant open out pipe (ntlm_auth)\n"); return false; } in = fdopen(fds[0], "r"); if (in == 0) { fclose(out); CloseChildProcess(pid, fds); Debug("Sam.c - cant open in pipe (ntlm_auth)\n"); return false; } if (base64_enc_len(strlen(name)) < sizeof(buffer)-1 && base64_enc_len(strlen(password)) < sizeof(buffer)-1 && base64_enc_len(strlen(domainname)) < sizeof(buffer)-1) { char answer[300]; unsigned int end = B64_Encode(buffer, name, strlen(name)); buffer[end] = '\0'; fputs("Username:: ", out); fputs(buffer, out); fputs("\n", out); Debug("Username: %s\n", buffer); buffer[0] = 0; end = B64_Encode(buffer, domainname, strlen(domainname)); buffer[end] = '\0'; fputs("NT-Domain:: ", out); fputs(buffer, out); fputs("\n", out); Debug("NT-Domain: %s\n", buffer); buffer[0] = 0; if (password[0] != '\0') { Debug("Password authentication\n"); end = B64_Encode(buffer, password, strlen(password)); buffer[end] = '\0'; fputs("Password:: ", out); fputs(buffer, out); fputs("\n", out); Debug("Password: %s\n", buffer); buffer[0] = 0; } else { char* mschapv2_client_response; char* base64_challenge8; Debug("MsChapV2 authentication\n"); mschapv2_client_response = CopyBinToStr(MsChapV2_ClientResponse, 24); end = B64_Encode(buffer, mschapv2_client_response, 48); buffer[end] = '\0'; fputs("NT-Response:: ", out); fputs(buffer, out); fputs("\n", out); Debug("NT-Response:: %s\n", buffer); buffer[0] = 0; Free(mschapv2_client_response); base64_challenge8 = CopyBinToStr(challenge8, 8); end = B64_Encode(buffer, base64_challenge8 , 16); buffer[end] = '\0'; fputs("LANMAN-Challenge:: ", out); fputs(buffer, out); fputs("\n", out); Debug("LANMAN-Challenge:: %s\n", buffer); buffer[0] = 0; Free(base64_challenge8); fputs("Request-User-Session-Key: Yes\n", out); } // Start authentication fputs( ".\n", out ); fflush (out); // Request send! Zero(answer, sizeof(answer)); while (fgets(answer, sizeof(answer)-1, in)) { char* response_parameter; if (strncmp(answer, ".\n", sizeof(answer)-1 ) == 0) { break; } /* Indicates a base64 encoded structure */ response_parameter = strstr(answer, ":: "); if (!response_parameter) { char* newline; response_parameter = strstr(answer, ": "); if (!response_parameter) { continue; } response_parameter[0] ='\0'; response_parameter++; response_parameter[0] ='\0'; response_parameter++; newline = strstr(response_parameter, "\n"); if( newline ) newline[0] = '\0'; } else { response_parameter[0] ='\0'; response_parameter++; response_parameter[0] ='\0'; response_parameter++; response_parameter[0] ='\0'; response_parameter++; end = Decode64(response_parameter, response_parameter); response_parameter[end] = '\0'; } if (strncmp(answer, "Authenticated", sizeof(answer)-1 ) == 0) { if (strcmp(response_parameter, "Yes") == 0) { Debug("Authenticated!\n"); auth = true; } else if (strcmp(response_parameter, "No") == 0) { Debug("Authentication failed!\n"); auth = false; } } else if (strncmp(answer, "User-Session-Key", sizeof(answer)-1 ) == 0) { if (nt_pw_hash_hash != NULL) { BUF* Buf = StrToBin(response_parameter); Copy(nt_pw_hash_hash, Buf->Buf, 16); FreeBuf(Buf); } } } } fclose(in); fclose(out); CloseChildProcess(pid, fds); return auth; }
void PropertiesWindow::Generate(FormObject* pI, int index) { if (!pI) return; _Properties.Clear(); _Options.Clear(); _Item = pI; _Index = index; String type = pI->Get("Type"); if (type.IsEmpty()) return; Property("Variable", t_("Variable:"), "EditField", Array<String>() << pI->Get("Variable")); if (_Headers.GetRowCount() != 1) { _Headers.Clear(); _Headers.AddRow(t_("Type:"), type); } Property("Font.Height", t_("Font height:"), "EditInt", Array<String>() << AsString(pI->GetNumber("Font.Height", 0, 0, 500))); if (type == "EditField") { Property("Style", t_("Style:"), "DropList", Array<String>() << pI->Get("Style") << "Text Field" << "Password"); Property("TextAlign", t_("Text align:"), "DropList", Array<String>() << pI->Get("TextAlign") << "Left" << "Right"); Property("Tip", t_("Tip:"), "EditField", Array<String>() << pI->Get("Tip")); Property("NotNull", t_("Not null:"), "Option", Array<String>() << pI->Get("NotNull", "0")); } if (type == "EditInt") { Property("Min", t_("Min:"), "EditInt", Array<String>() << pI->Get("Min")); Property("Max", t_("Max:"), "EditInt", Array<String>() << pI->Get("Max")); Property("Tip", t_("Tip:"), "EditField", Array<String>() << pI->Get("Tip")); Property("NotNull", t_("Not null:"), "Option", Array<String>() << pI->Get("NotNull", "0")); } if (type == "Label") { Color src = DefaultInk(); LoadFromString( src, Decode64(pI->Get("Font.Color", Encode64(StoreAsString(src)))) ); Property("Label", t_("Label:"), "EditField", Array<String>() << pI->Get("Label")); Property("Text.Align", t_("Text align:"), "DropList", Array<String>() << pI->Get("Text.Align") << "Left" << "Center" << "Right"); Property("Font.Color", t_("Font color:"), "EditColor", src); } if (type == "Button") { Property("Label", t_("Label:"), "EditField", Array<String>() << pI->Get("Label")); Property("Action", t_("Action:"), "EditField", Array<String>() << pI->Get("Action")); Property("Tip", t_("Tip:"), "EditField", Array<String>() << pI->Get("Tip")); } if (type == "Form") { Property("Form.PathType", t_("Type of path:"), "DropList", Array<String>() << pI->Get("Form.PathType") << "Relative" << "Absolute"); Property("Form.Path", t_("Path:"), "EditField", Array<String>() << pI->Get("Form.Path")); Property("Form.Layout", t_("Layout:"), "EditField", Array<String>() << pI->Get("Form.Layout")); } if (type == "TabCtrl") { Property("Tab.Content", t_("Tabs:"), "EditTabs", Array<String>() << pI->Get("Tab.Content", "[Tabs];")); } if (type == "GridCtrl") { Property("Grid.Columns", t_("Columns:"), "EditColumns", Array<String>() << pI->Get("Grid.Columns", "[Columns];")); } Property("Frame", t_("Frame:"), "DropList", Array<String>() << pI->Get("Frame") << "Default frame" << "Null frame" << "Top separator frame" << "Left separator frame" << "Right separator frame" << "Bottom separator frame" << "Field frame" << "Inset frame" << "Outset frame" << "Thin inset frame" << "Thin outset frame" << "Black frame" << "Button frame"); _Options.HideRow(0); _Headers.SetCursor(0); _Headers.StartEdit(); _Options.SetCursor(0); }
void FormEdit::UpdateChildCount(int count) { for (int i = 0; i < _Ctrls.GetCount(); ++i) _CtrlContainer.RemoveChild(&_Ctrls[i]); _Ctrls.Clear(); _ItemList.Clear(); _Temporaries.Clear(); if (!_View.IsLayout()) { UpdateItemList(); return; } // if (_ViewMode == VIEW_MODE_WIREFRAME) // return; for (int i = 0; i < count; ++i) { if (!_View.GetObject(i)) continue; String type = (*_View.GetObjects())[i].Get("Type"); Font font = _View.GetFont(); int h = _View.ZoomY((*_View.GetObjects())[i].GetNumber("Font.Height")); if (h != 0) font.Height(h); if (font.GetHeight() == 0) font.Height(StdFont().GetHeight()); _ItemList.AddRow(type, (*_View.GetObjects())[i].Get("Variable")); if ((*_View.GetObjects())[i].GetBool("OutlineDraw", false) && _ViewMode != VIEW_MODE_AS_IS) { if (_ViewMode != VIEW_MODE_WIREFRAME) _CtrlContainer.Add( _Ctrls.Create<StaticRect>() ); } else if (type == "Button") { Button* b = &_Ctrls.Create<Button>(); b->SetFont(font); if (_ViewMode == VIEW_MODE_AS_IS) b->SetLabel((*_View.GetObjects())[i].Get("Label")); if (_ViewMode != VIEW_MODE_WIREFRAME) _CtrlContainer.Add( b->NoWantFocus() ); } else if (type == "DropDate") { DropDate *b = &_Ctrls.Create<DropDate>(); b->SetFont(font); if (_ViewMode != VIEW_MODE_WIREFRAME) _CtrlContainer.Add( b->NoWantFocus() ); } else if (type == "GridCtrl") { GridCtrl *b = &_Ctrls.Create<GridCtrl>(); // b->SetFont(font); TODO #ifdef PLATFORM_WIN32 b->Chameleon(); #endif String src = (*_View.GetObjects())[i].Get("Grid.Columns"); ReplaceString(src, ";", "\r\n"); StringStream s; s.Open(src); IniFile f; f.Load(s); Vector<String> names = f.EnumNames("Columns"); for (int j = 0; j < names.GetCount(); ++j) { int n = ScanInt(names[j]); Vector<String> values = f.GetArray("Columns", names[j]); if (values.GetCount() != 3) continue; if (values[1] == "Left") b->AddColumn(values[0]).HeaderAlignCenterLeft(); else if (values[1] == "Right") b->AddColumn(values[0]).HeaderAlignCenterRight(); else b->AddColumn(values[0]).HeaderAlignCenter(); } if (_ViewMode != VIEW_MODE_WIREFRAME) _CtrlContainer.Add( b->NoWantFocus() ); } else if (type == "EditField") { EditField *b = &_Ctrls.Create<EditField>(); b->SetFont(font); if (_ViewMode == VIEW_MODE_AS_IS) b->SetText((*_View.GetObjects())[i].Get("DefaultData")); if (_ViewMode != VIEW_MODE_WIREFRAME) _CtrlContainer.Add( b->NoWantFocus() ); } else if (type == "EditInt") { EditInt *b = &_Ctrls.Create<EditInt>(); b->SetFont(font); if (_ViewMode == VIEW_MODE_AS_IS) b->SetText((*_View.GetObjects())[i].Get("DefaultData")); if (_ViewMode != VIEW_MODE_WIREFRAME) _CtrlContainer.Add( b->NoWantFocus() ); } else if (type == "ProgressBar") { ProgressIndicator *b = &_Ctrls.Create<ProgressIndicator>(); b->Set(0, 100); if (_ViewMode != VIEW_MODE_WIREFRAME) _CtrlContainer.Add( b->NoWantFocus() ); } else if (type == "TabCtrl") { TabCtrl* e = &_Ctrls.Create<TabCtrl>(); TabCtrl::Style& style = e->StyleDefault().Write(); style.font = font; style.tabheight = font.GetHeight() + VertLayoutZoom(10); e->SetStyle(style); String src = (*_View.GetObjects())[i].Get("Tab.Content"); ReplaceString(src, ";", "\r\n"); StringStream s; s.Open(src); IniFile f; f.Load(s); Vector<String> names = f.EnumNames("Tabs"); VectorMap<int, Vector<String> > cache; int tabCount = 0; for (int j = 0; j < names.GetCount(); ++j) { int n = ScanInt(names[j]); if (AsString(n) != names[j]) continue; Vector<String> values = f.GetArray("Tabs", names[j]); if (values.GetCount() != 3) continue; Container *cont = &_Temporaries.Create<Container>(); Form *f = &_Temporaries.Create<Form>(); if (values[0] != t_("Current form")) { if (!f->Load(GetFileDirectory(_File) + "\\" + values[0])) continue; } else { int lay = _View.HasLayout(values[1]); if (lay < 0) continue; f->GetLayouts().Add() <<= _View.GetLayouts()[lay]; } if (!f->Layout(values[1], font)) continue; cont->Set(*f, f->GetSize()); cont->SizePos(); e->Add(*cont, values[2]); tabCount++; } int activeTab = -1; if (tabCount) { activeTab = (*_View.GetObjects())[i].GetNumber("Tab.Active", 0, 0); if (activeTab >= tabCount) { activeTab = tabCount - 1; e->Set(activeTab); } e->Set(activeTab); } (*_View.GetObjects())[i].SetNumber("Tab.Active", activeTab); (*_View.GetObjects())[i].SetNumber("Tab.Count", tabCount); if (_ViewMode != VIEW_MODE_WIREFRAME) _CtrlContainer.Add( e->NoWantFocus() ); } else if (type == "Form") { Form f; String path = (*_View.GetObjects())[i].Get("Form.Path"); (*_View.GetObjects())[i].Get("Form.PathType") == "Relative" ? f.Load(::GetFileDirectory(_File) + "\\" + path) : f.Load(path); f.Layout((*_View.GetObjects())[i].Get("Form.Layout"), font); ImageDraw w(f.GetSize()); f.DrawCtrl(w); ImageBuffer buf(w); StaticImage *s = &_Ctrls.Create<StaticImage>(); s->SetImage(buf); if (_ViewMode != VIEW_MODE_WIREFRAME) _CtrlContainer.AddChild( s ); } else { Label *b = &_Ctrls.Create<Label>(); b->SetFont(font); Color fontColor = DefaultInk(); LoadFromString(fontColor, Decode64((*_View.GetObjects())[i].Get("Font.Color", StoreAsString(fontColor)))); b->SetInk(fontColor); String align = (*_View.GetObjects())[i].Get("Text.Align"); if (align == "Center") b->SetAlign(ALIGN_CENTER); if (align == "Right") b->SetAlign(ALIGN_RIGHT); if (align == "Left") b->SetAlign(ALIGN_LEFT); if (_ViewMode == VIEW_MODE_AS_IS) b->SetLabel((*_View.GetObjects())[i].Get("Label")); if (_ViewMode != VIEW_MODE_WIREFRAME) _CtrlContainer.Add( b->NoWantFocus() ); } String frame = (*_View.GetObjects())[i].Get("Frame"); Ctrl* c = NULL; if (_Ctrls.GetCount()) c = &_Ctrls[_Ctrls.GetCount() - 1]; if (c) { if (frame == "Null frame") c->SetFrame(NullFrame()); if (frame == "Field frame") c->SetFrame(FieldFrame()); if (frame == "Inset frame") c->SetFrame(InsetFrame()); if (frame == "Outset frame") c->SetFrame(OutsetFrame()); if (frame == "Thin inset frame") c->SetFrame(ThinInsetFrame()); if (frame == "Thin outset frame") c->SetFrame(ThinOutsetFrame()); if (frame == "Black frame") c->SetFrame(BlackFrame()); if (frame == "Button frame") c->SetFrame(ButtonFrame()); if (frame == "Top separator frame") c->SetFrame(TopSeparatorFrame()); if (frame == "Left separator frame") c->SetFrame(LeftSeparatorFrame()); if (frame == "Right separator frame") c->SetFrame(RightSeparatorFrame()); if (frame == "Bottom separator frame") c->SetFrame(BottomSeparatorFrame()); } } UpdateItemList(); UpdateChildAllPos(); }