Event *EventAddEx(Module *module, char *name, long every, long howmany, vFP event, void *data) { Event *newevent; if (!name || (every < 0) || (howmany < 0) || !event) { if (module) module->errorcode = MODERR_INVALID; return NULL; } newevent = (Event *) MyMallocEx(sizeof(Event)); newevent->name = strdup(name); newevent->howmany = howmany; newevent->every = every; newevent->event = event; newevent->data = data; /* We don't want a quick execution */ newevent->last = TStime(); newevent->owner = module; AddListItem(newevent,events); if (module) { ModuleObject *eventobj = (ModuleObject *)MyMallocEx(sizeof(ModuleObject)); eventobj->object.event = newevent; eventobj->type = MOBJ_EVENT; AddListItem(eventobj, module->objects); module->errorcode = MODERR_NOERROR; } return newevent; }
/* * Adds a "remove channelmode set by +f" timer. * chptr Channel * mflag Mode flag, eg 'C' * mbit Mode bitflag, eg MODE_NOCTCP * when when it should be removed * NOTES: * - This function takes care of overwriting of any previous timer * for the same modechar. * - The function takes care of chptr->mode.floodprot->timer_flags, * do not modify it yourself. * - chptr->mode.floodprot is asumed to be non-NULL. */ void chanfloodtimer_add(aChannel *chptr, char mflag, long mbit, time_t when) { RemoveFld *e = NULL; unsigned char add=1; if (chptr->mode.floodprot->timer_flags & mbit) { /* Already exists... */ e = chanfloodtimer_find(chptr, mflag); if (e) add = 0; } if (add) e = MyMallocEx(sizeof(RemoveFld)); e->chptr = chptr; e->m = mflag; e->when = when; if (add) AddListItem(e, removefld_list); chptr->mode.floodprot->timer_flags |= mbit; }
Snomask *SnomaskAdd(Module *module, char ch, int (*allowed)(aClient *sptr, int what), long *mode) { short i = 0; short j = 0; short save = -1; while (i < UMODETABLESZ) { if (!Snomask_Table[i].flag && save == -1) save = i; else if (Snomask_Table[i].flag == ch) { if (Snomask_Table[i].unloaded) { save = i; Snomask_Table[i].unloaded = 0; break; } else { if (module) module->errorcode = MODERR_EXISTS; return NULL; } } i++; } i = save; if (i != UMODETABLESZ) { Snomask_Table[i].flag = ch; Snomask_Table[i].allowed = allowed; /* Update usermode table highest */ for (j = 0; j < UMODETABLESZ; j++) if (Snomask_Table[i].flag) if (i > Snomask_highest) Snomask_highest = i; *mode = Snomask_Table[i].mode; Snomask_Table[i].owner = module; if (module) { ModuleObject *snoobj = MyMallocEx(sizeof(ModuleObject)); snoobj->object.snomask = &(Snomask_Table[i]); snoobj->type = MOBJ_SNOMASK; AddListItem(snoobj, module->objects); module->errorcode = MODERR_NOERROR; } return &(Snomask_Table[i]); } else { Debug((DEBUG_DEBUG, "SnomaskAdd failed, no space")); *mode = 0; if (module) module->errorcode = MODERR_NOSPACE; return NULL; } }
void DCCdeny_add(char *filename, char *reason, int type, int type2) { ConfigItem_deny_dcc *deny = NULL; deny = (ConfigItem_deny_dcc *) MyMallocEx(sizeof(ConfigItem_deny_dcc)); deny->filename = strdup(filename); deny->reason = strdup(reason); deny->flag.type = type; deny->flag.type2 = type2; AddListItem(deny, conf_deny_dcc); }
/** Read motd-like file, used for rules/motd/botmotd/opermotd/etc. * Multiplexes to either directly reading the MOTD or downloading it asynchronously. * @param filename Filename of file to read or URL. NULL is accepted and causes the *motd to be free()d. * @param motd Reference to motd pointer (used for freeing if needed and for asynchronous remote MOTD support) */ void read_motd(const char *filename, aMotdFile *themotd) { #ifdef USE_LIBCURL time_t modtime; aMotdDownload *motd_download; #endif /* TODO: if themotd points to a tld's motd, could a rehash disrupt this pointer?*/ #ifdef USE_LIBCURL if(themotd->motd_download) { themotd->motd_download->themotd = NULL; /* * It is not our job to free() motd_download, the * read_motd_asynch_downloaded() function will do that * when it sees that ->themod == NULL. */ themotd->motd_download = NULL; } /* if filename is NULL, do_read_motd will catch it */ if(filename && url_is_valid(filename)) { /* prepare our payload for read_motd_asynch_downloaded() */ motd_download = MyMallocEx(sizeof(aMotdDownload)); if(!motd_download) outofmemory(); motd_download->themotd = themotd; themotd->motd_download = motd_download; #ifdef REMOTEINC_SPECIALCACHE modtime = unreal_getfilemodtime(unreal_mkcache(filename)); #else modtime = 0; #endif download_file_async(filename, modtime, (vFP)read_motd_asynch_downloaded, motd_download); return; } #endif /* USE_LIBCURL */ do_read_motd(filename, themotd); return; }
Extban *ExtbanAdd(Module *module, ExtbanInfo req) { int slot; char tmpbuf[512]; if (findmod_by_bantype(req.flag)) { if (module) module->errorcode = MODERR_EXISTS; return NULL; } /* TODO: perhaps some sanity checking on a-zA-Z0-9? */ for (slot = 0; slot < EXTBANTABLESZ; slot++) if (ExtBan_Table[slot].flag == '\0') break; if (slot == EXTBANTABLESZ - 1) { if (module) module->errorcode = MODERR_NOSPACE; return NULL; } ExtBan_Table[slot].flag = req.flag; ExtBan_Table[slot].is_ok = req.is_ok; ExtBan_Table[slot].conv_param = req.conv_param; ExtBan_Table[slot].is_banned = req.is_banned; ExtBan_Table[slot].owner = module; ExtBan_Table[slot].options = req.options; if (module) { ModuleObject *banobj = MyMallocEx(sizeof(ModuleObject)); banobj->object.extban = &ExtBan_Table[slot]; banobj->type = MOBJ_EXTBAN; AddListItem(banobj, module->objects); module->errorcode = MODERR_NOERROR; } ExtBan_highest = slot; if (loop.ircd_booted) { make_extbanstr(); ircsprintf(tmpbuf, "~,%s", extbanstr); IsupportSetValue(IsupportFind("EXTBAN"), tmpbuf); } return &ExtBan_Table[slot]; }
/* ** zip_init ** Initialize compression structures for a server. ** If failed, zip_free() has to be called. */ int zip_init(aClient *cptr, int compressionlevel) { cptr->zip = (aZdata *) MyMalloc(sizeof(aZdata)); cptr->zip->incount = 0; cptr->zip->outcount = 0; cptr->zip->in = (z_stream *) MyMalloc(sizeof(z_stream)); bzero(cptr->zip->in, sizeof(z_stream)); /* Just to be sure -- Syzop */ cptr->zip->in->total_in = 0; cptr->zip->in->total_out = 0; cptr->zip->in->zalloc = NULL; cptr->zip->in->zfree = NULL; cptr->zip->in->data_type = Z_ASCII; if (inflateInit(cptr->zip->in) != Z_OK) { cptr->zip->out = NULL; return -1; } cptr->zip->out = (z_stream *) MyMalloc(sizeof(z_stream)); bzero(cptr->zip->out, sizeof(z_stream)); /* Just to be sure -- Syzop */ cptr->zip->out->total_in = 0; cptr->zip->out->total_out = 0; cptr->zip->out->zalloc = NULL; cptr->zip->out->zfree = NULL; cptr->zip->out->data_type = Z_ASCII; if (deflateInit(cptr->zip->out, compressionlevel) != Z_OK) return -1; if (!unzipbuf) { unzipbuf = MyMallocEx(UNZIP_BUFFER_SIZE); /* big chunk! */ if (!unzipbuf) { ircd_log(LOG_ERROR, "zip_init(): out of memory (trying to alloc %d bytes)!", UNZIP_BUFFER_SIZE); sendto_realops("zip_init(): out of memory (trying to alloc %d bytes)!", UNZIP_BUFFER_SIZE); return -1; } } return 0; }
DLLFUNC int nopost_config_run(ConfigFile *cf, ConfigEntry *ce, int type) { ConfigEntry *cep, *cep2; DynList *d; if (type != CONFIG_SET) return 0; /* We are only interrested in set::nopost... */ if (!ce || !ce->ce_varname || strcmp(ce->ce_varname, "nopost")) return 0; for (cep = ce->ce_entries; cep; cep = cep->ce_next) { if (!strcmp(cep->ce_varname, "except-hosts")) { for (cep2 = cep->ce_entries; cep2; cep2 = cep2->ce_next) { d = MyMallocEx(sizeof(DynList)); d->entry = strdup(cep2->ce_varname); AddListItem(d, cfg.except_hosts); } } else if (!strcmp(cep->ce_varname, "ban-action")) { cfg.ban_action = banact_stringtoval(cep->ce_vardata); } else if (!strcmp(cep->ce_varname, "ban-reason")) { if (cfg.ban_reason) MyFree(cfg.ban_reason); cfg.ban_reason = strdup(cep->ce_vardata); } else if (!strcmp(cep->ce_varname, "ban-time")) { cfg.ban_time = config_checkval(cep->ce_vardata, CFG_TIME); } } return 1; }
void add_pending_net(aClient *sptr, char *str) { aPendingNet *e = NULL; int num = 1; char *p, *name; if (BadPtr(str) || !sptr) return; /* First, count them */ for (p = str; *p; p++) if (*p == ',') num++; /* Allocate */ e = MyMallocEx(sizeof(aPendingNet) + (sizeof(int) * num)); e->numservers = num; e->sptr = sptr; /* Fill in */ num = 0; for (name = strtoken(&p, str, ","); name; name = strtoken(&p, NULL, ",")) { if (!*name) continue; /* skip any non-digit prefixes, if necessary. Possibly needed in the future. */ while (*name && !isdigit(*name)) name++; e->servers[num++] = atoi(name); } AddListItem(e, pendingnet); }
LRESULT CALLBACK FromFileDLG(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) { HWND hWnd; static FINDREPLACE find; static char findbuf[256]; static unsigned char *file; static HWND hTool, hClip, hStatus; static RECT rOld; CHARFORMAT2 chars; if (message == WM_FINDMSGSTRING) { FINDREPLACE *fr = (FINDREPLACE *)lParam; if (fr->Flags & FR_FINDNEXT) { HWND hRich = GetDlgItem(hDlg, IDC_TEXT); DWORD flags=0; FINDTEXTEX ft; CHARRANGE chrg; if (fr->Flags & FR_DOWN) flags |= FR_DOWN; if (fr->Flags & FR_MATCHCASE) flags |= FR_MATCHCASE; if (fr->Flags & FR_WHOLEWORD) flags |= FR_WHOLEWORD; ft.lpstrText = fr->lpstrFindWhat; SendMessage(hRich, EM_EXGETSEL, 0, (LPARAM)&chrg); if (flags & FR_DOWN) { ft.chrg.cpMin = chrg.cpMax; ft.chrg.cpMax = -1; } else { ft.chrg.cpMin = chrg.cpMin; ft.chrg.cpMax = -1; } if (SendMessage(hRich, EM_FINDTEXTEX, flags, (LPARAM)&ft) == -1) MessageBox(NULL, "UnrealIRCd has finished searching the document", "Find", MB_ICONINFORMATION|MB_OK); else { SendMessage(hRich, EM_EXSETSEL, 0, (LPARAM)&(ft.chrgText)); SendMessage(hRich, EM_SCROLLCARET, 0, 0); SetFocus(hRich); } } return TRUE; } switch (message) { case WM_INITDIALOG: { int fd,len; char *buffer, *string; EDITSTREAM edit; StreamIO *stream = MyMallocEx(sizeof(StreamIO)); unsigned char szText[256]; struct stat sb; HWND hWnd = GetDlgItem(hDlg, IDC_TEXT), hTip; file = (unsigned char *)lParam; if (file) wsprintf(szText, "UnrealIRCd Editor - %s", file); else strcpy(szText, "UnrealIRCd Editor - New File"); SetWindowText(hDlg, szText); lpfnOldWndProc = (FARPROC)SetWindowLong(hWnd, GWL_WNDPROC, (DWORD)RESubClassFunc); hTool = DrawToolbar(hInst, hDlg); hStatus = DrawStatusbar(hInst, hDlg, IDC_STATUS); SendMessage(hWnd, EM_SETEVENTMASK, 0, (LPARAM)ENM_SELCHANGE); chars.cbSize = sizeof(CHARFORMAT2); chars.dwMask = CFM_FACE; strcpy(chars.szFaceName,"Fixedsys"); SendMessage(hWnd, EM_SETCHARFORMAT, (WPARAM)SCF_ALL, (LPARAM)&chars); if ((fd = open(file, _O_RDONLY|_O_BINARY)) != -1) { fstat(fd,&sb); /* Only allocate the amount we need */ buffer = MyMallocEx(sb.st_size+1); len = read(fd, buffer, sb.st_size); buffer[len] = 0; len = CountRTFSize(buffer)+1; string = MyMallocEx(len); IRCToRTF(buffer,string); RTFBuf = string; len--; stream->size = &len; stream->buffer = &RTFBuf; edit.dwCookie = (UINT)stream; edit.pfnCallback = SplitIt; SendMessage(hWnd, EM_EXLIMITTEXT, 0, (LPARAM)0x7FFFFFFF); SendMessage(hWnd, EM_STREAMIN, (WPARAM)SF_RTF|SFF_PLAINRTF, (LPARAM)&edit); SendMessage(hWnd, EM_SETMODIFY, (WPARAM)FALSE, 0); SendMessage(hWnd, EM_EMPTYUNDOBUFFER, 0, 0); close(fd); RTFBuf = NULL; free(buffer); free(string); free(stream); hClip = SetClipboardViewer(hDlg); if (SendMessage(hWnd, EM_CANPASTE, 0, 0)) SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_PASTE, (LPARAM)MAKELONG(TRUE,0)); else SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_PASTE, (LPARAM)MAKELONG(FALSE,0)); SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_UNDO, (LPARAM)MAKELONG(FALSE,0)); wsprintf(szText, "Line: 1"); SetWindowText(hStatus, szText); } return TRUE; } case WM_WINDOWPOSCHANGING: { GetClientRect(hDlg, &rOld); return FALSE; } case WM_SIZE: { DWORD new_width, new_height; HWND hRich; RECT rOldRich; DWORD old_width, old_height; DWORD old_rich_width, old_rich_height; if (hDlg == hFind) return FALSE; new_width = LOWORD(lParam); new_height = HIWORD(lParam); hRich = GetDlgItem(hDlg, IDC_TEXT); SendMessage(hStatus, WM_SIZE, 0, 0); SendMessage(hTool, TB_AUTOSIZE, 0, 0); old_width = rOld.right-rOld.left; old_height = rOld.bottom-rOld.top; new_width = new_width - old_width; new_height = new_height - old_height; GetWindowRect(hRich, &rOldRich); old_rich_width = rOldRich.right-rOldRich.left; old_rich_height = rOldRich.bottom-rOldRich.top; SetWindowPos(hRich, NULL, 0, 0, old_rich_width+new_width, old_rich_height+new_height, SWP_NOMOVE|SWP_NOREPOSITION|SWP_NOZORDER); bzero(&rOld, sizeof(RECT)); return TRUE; } case WM_NOTIFY: switch (((NMHDR *)lParam)->code) { case EN_SELCHANGE: { HWND hWnd = GetDlgItem(hDlg, IDC_TEXT); DWORD start, end, currline; static DWORD prevline = 0; unsigned char buffer[512]; chars.cbSize = sizeof(CHARFORMAT2); SendMessage(hWnd, EM_GETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&chars); if (chars.dwMask & CFM_BOLD && chars.dwEffects & CFE_BOLD) SendMessage(hTool, TB_CHECKBUTTON, (WPARAM)IDC_BOLD, (LPARAM)MAKELONG(TRUE,0)); else SendMessage(hTool, TB_CHECKBUTTON, (WPARAM)IDC_BOLD, (LPARAM)MAKELONG(FALSE,0)); if (chars.dwMask & CFM_UNDERLINE && chars.dwEffects & CFE_UNDERLINE) SendMessage(hTool, TB_CHECKBUTTON, (WPARAM)IDC_UNDERLINE, (LPARAM)MAKELONG(TRUE,0)); else SendMessage(hTool, TB_CHECKBUTTON, (WPARAM)IDC_UNDERLINE, (LPARAM)MAKELONG(FALSE,0)); SendMessage(hWnd, EM_GETSEL,(WPARAM)&start, (LPARAM)&end); if (start == end) { SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_COPY, (LPARAM)MAKELONG(FALSE,0)); SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_CUT, (LPARAM)MAKELONG(FALSE,0)); } else { SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_COPY, (LPARAM)MAKELONG(TRUE,0)); SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_CUT, (LPARAM)MAKELONG(TRUE,0)); } if (SendMessage(hWnd, EM_CANUNDO, 0, 0)) SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_UNDO, (LPARAM)MAKELONG(TRUE,0)); else SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_UNDO, (LPARAM)MAKELONG(FALSE,0)); if (SendMessage(hWnd, EM_CANREDO, 0, 0)) SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_REDO, (LPARAM)MAKELONG(TRUE,0)); else SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_REDO, (LPARAM)MAKELONG(FALSE,0)); currline = SendMessage(hWnd, EM_LINEFROMCHAR, (WPARAM)-1, 0); currline++; if (currline != prevline) { wsprintf(buffer, "Line: %d", currline); SetWindowText(hStatus, buffer); prevline = currline; } return TRUE; } case TTN_GETDISPINFO: { LPTOOLTIPTEXT lpttt = (LPTOOLTIPTEXT) lParam; lpttt->hinst = NULL; switch (lpttt->hdr.idFrom) { case IDM_NEW: strcpy(lpttt->szText, "New"); break; case IDM_SAVE: strcpy(lpttt->szText, "Save"); break; case IDM_CUT: strcpy(lpttt->szText, "Cut"); break; case IDM_COPY: strcpy(lpttt->szText, "Copy"); break; case IDM_PASTE: strcpy(lpttt->szText, "Paste"); break; case IDM_UNDO: strcpy(lpttt->szText, "Undo"); break; case IDM_REDO: strcpy(lpttt->szText, "Redo"); break; case IDC_BOLD: strcpy(lpttt->szText, "Bold"); break; case IDC_UNDERLINE: strcpy(lpttt->szText, "Underline"); break; case IDC_COLOR: strcpy(lpttt->szText, "Text Color"); break; case IDC_BGCOLOR: strcpy(lpttt->szText, "Background Color"); break; case IDC_GOTO: strcpy(lpttt->szText, "Goto"); break; case IDC_FIND: strcpy(lpttt->szText, "Find"); break; } return TRUE; } case NM_DBLCLK: DialogBox(hInst, "GOTO", hDlg, (DLGPROC)GotoDLG); return (TRUE); } return (TRUE); case WM_COMMAND: if (LOWORD(wParam) == IDC_BOLD) { hWnd = GetDlgItem(hDlg, IDC_TEXT); if (SendMessage(hTool, TB_ISBUTTONCHECKED, (WPARAM)IDC_BOLD, (LPARAM)0) != 0) { chars.cbSize = sizeof(CHARFORMAT2); chars.dwMask = CFM_BOLD; chars.dwEffects = CFE_BOLD; SendMessage(hWnd, EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&chars); SendMessage(hWnd, EM_HIDESELECTION, 0, 0); SetFocus(hWnd); } else { chars.cbSize = sizeof(CHARFORMAT2); chars.dwMask = CFM_BOLD; chars.dwEffects = 0; SendMessage(hWnd, EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&chars); SendMessage(hWnd, EM_HIDESELECTION, 0, 0); SetFocus(hWnd); } return TRUE; } else if (LOWORD(wParam) == IDC_UNDERLINE) { hWnd = GetDlgItem(hDlg, IDC_TEXT); if (SendMessage(hTool, TB_ISBUTTONCHECKED, (WPARAM)IDC_UNDERLINE, (LPARAM)0) != 0) { chars.cbSize = sizeof(CHARFORMAT2); chars.dwMask = CFM_UNDERLINETYPE; chars.bUnderlineType = CFU_UNDERLINE; SendMessage(hWnd, EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&chars); SendMessage(hWnd, EM_HIDESELECTION, 0, 0); SetFocus(hWnd); } else { chars.cbSize = sizeof(CHARFORMAT2); chars.dwMask = CFM_UNDERLINETYPE; chars.bUnderlineType = CFU_UNDERLINENONE; SendMessage(hWnd, EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&chars); SendMessage(hWnd, EM_HIDESELECTION, 0, 0); SetFocus(hWnd); } return TRUE; } if (LOWORD(wParam) == IDC_COLOR) { DialogBoxParam(hInst, "Color", hDlg, (DLGPROC)ColorDLG, (LPARAM)WM_USER+10); return 0; } if (LOWORD(wParam) == IDC_BGCOLOR) { DialogBoxParam(hInst, "Color", hDlg, (DLGPROC)ColorDLG, (LPARAM)WM_USER+11); return 0; } if (LOWORD(wParam) == IDC_GOTO) { DialogBox(hInst, "GOTO", hDlg, (DLGPROC)GotoDLG); return 0; } if (LOWORD(wParam) == IDC_FIND) { static FINDREPLACE fr; bzero(&fr, sizeof(FINDREPLACE)); fr.lStructSize = sizeof(FINDREPLACE); fr.hwndOwner = hDlg; fr.lpstrFindWhat = findbuf; fr.wFindWhatLen = 255; hFind = FindText(&fr); return 0; } hWnd = GetDlgItem(hDlg, IDC_TEXT); if (LOWORD(wParam) == IDM_COPY) { SendMessage(hWnd, WM_COPY, 0, 0); return 0; } if (LOWORD(wParam) == IDM_SELECTALL) { SendMessage(hWnd, EM_SETSEL, 0, -1); return 0; } if (LOWORD(wParam) == IDM_PASTE) { SendMessage(hWnd, WM_PASTE, 0, 0); return 0; } if (LOWORD(wParam) == IDM_CUT) { SendMessage(hWnd, WM_CUT, 0, 0); return 0; } if (LOWORD(wParam) == IDM_UNDO) { SendMessage(hWnd, EM_UNDO, 0, 0); return 0; } if (LOWORD(wParam) == IDM_REDO) { SendMessage(hWnd, EM_REDO, 0, 0); return 0; } if (LOWORD(wParam) == IDM_DELETE) { SendMessage(hWnd, WM_CLEAR, 0, 0); return 0; } if (LOWORD(wParam) == IDM_SAVE) { int fd; EDITSTREAM edit; OPENFILENAME lpopen; if (!file) { unsigned char path[MAX_PATH]; path[0] = '\0'; bzero(&lpopen, sizeof(OPENFILENAME)); lpopen.lStructSize = sizeof(OPENFILENAME); lpopen.hwndOwner = hDlg; lpopen.lpstrFilter = NULL; lpopen.lpstrCustomFilter = NULL; lpopen.nFilterIndex = 0; lpopen.lpstrFile = path; lpopen.nMaxFile = MAX_PATH; lpopen.lpstrFileTitle = NULL; lpopen.lpstrInitialDir = CONFDIR; lpopen.lpstrTitle = NULL; lpopen.Flags = (OFN_ENABLESIZING|OFN_NONETWORKBUTTON| OFN_OVERWRITEPROMPT); if (GetSaveFileName(&lpopen)) file = path; else break; } fd = open(file, _O_TRUNC|_O_CREAT|_O_WRONLY|_O_BINARY,_S_IWRITE); edit.dwCookie = 0; edit.pfnCallback = BufferIt; SendMessage(GetDlgItem(hDlg, IDC_TEXT), EM_STREAMOUT, (WPARAM)SF_RTF|SFF_PLAINRTF, (LPARAM)&edit); RTFToIRC(fd, RTFBuf, strlen(RTFBuf)); free(RTFBuf); RTFBuf = NULL; SendMessage(GetDlgItem(hDlg, IDC_TEXT), EM_SETMODIFY, (WPARAM)FALSE, 0); return 0; } if (LOWORD(wParam) == IDM_NEW) { unsigned char text[1024]; BOOL newfile = FALSE; int ans; if (SendMessage(GetDlgItem(hDlg, IDC_TEXT), EM_GETMODIFY, 0, 0) != 0) { sprintf(text, "The text in the %s file has changed.\r\n\r\nDo you want to save the changes?", file ? file : "new"); ans = MessageBox(hDlg, text, "UnrealIRCd", MB_YESNOCANCEL|MB_ICONWARNING); if (ans == IDNO) newfile = TRUE; if (ans == IDCANCEL) return TRUE; if (ans == IDYES) { SendMessage(hDlg, WM_COMMAND, MAKEWPARAM(IDM_SAVE,0), 0); newfile = TRUE; } } else newfile = TRUE; if (newfile == TRUE) { unsigned char szText[256]; file = NULL; strcpy(szText, "UnrealIRCd Editor - New File"); SetWindowText(hDlg, szText); SetWindowText(GetDlgItem(hDlg, IDC_TEXT), NULL); } break; } break; case WM_USER+10: { HWND hWnd = GetDlgItem(hDlg, IDC_TEXT); EndDialog((HWND)lParam, TRUE); chars.cbSize = sizeof(CHARFORMAT2); chars.dwMask = CFM_COLOR; chars.crTextColor = (COLORREF)wParam; SendMessage(hWnd, EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&chars); SendMessage(hWnd, EM_HIDESELECTION, 0, 0); SetFocus(hWnd); break; } case WM_USER+11: { HWND hWnd = GetDlgItem(hDlg, IDC_TEXT); EndDialog((HWND)lParam, TRUE); chars.cbSize = sizeof(CHARFORMAT2); chars.dwMask = CFM_BACKCOLOR; chars.crBackColor = (COLORREF)wParam; SendMessage(hWnd, EM_SETCHARFORMAT, (WPARAM)SCF_SELECTION, (LPARAM)&chars); SendMessage(hWnd, EM_HIDESELECTION, 0, 0); SetFocus(hWnd); break; } case WM_CHANGECBCHAIN: if ((HWND)wParam == hClip) hClip = (HWND)lParam; else SendMessage(hClip, WM_CHANGECBCHAIN, wParam, lParam); break; case WM_DRAWCLIPBOARD: if (SendMessage(GetDlgItem(hDlg, IDC_TEXT), EM_CANPASTE, 0, 0)) SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_PASTE, (LPARAM)MAKELONG(TRUE,0)); else SendMessage(hTool, TB_ENABLEBUTTON, (WPARAM)IDM_PASTE, (LPARAM)MAKELONG(FALSE,0)); SendMessage(hClip, WM_DRAWCLIPBOARD, wParam, lParam); break; case WM_CLOSE: { unsigned char text[256]; int ans; if (SendMessage(GetDlgItem(hDlg, IDC_TEXT), EM_GETMODIFY, 0, 0) != 0) { sprintf(text, "The text in the %s file has changed.\r\n\r\nDo you want to save the changes?", file ? file : "new"); ans = MessageBox(hDlg, text, "UnrealIRCd", MB_YESNOCANCEL|MB_ICONWARNING); if (ans == IDNO) EndDialog(hDlg, TRUE); if (ans == IDCANCEL) return TRUE; if (ans == IDYES) { SendMessage(hDlg, WM_COMMAND, MAKEWPARAM(IDM_SAVE,0), 0); EndDialog(hDlg, TRUE); } } else EndDialog(hDlg, TRUE); break; } case WM_DESTROY: ChangeClipboardChain(hDlg, hClip); break; } return FALSE; }
/* umode_get: * Add a usermode with character 'ch', if global is set to 1 the usermode is global * (sent to other servers) otherwise it's a local usermode */ Umode *UmodeAdd(Module *module, char ch, int global, int (*allowed)(aClient *sptr, int what), long *mode) { short i = 0; short j = 0; short save = -1; while (i < UMODETABLESZ) { if (!Usermode_Table[i].flag && save == -1) save = i; else if (Usermode_Table[i].flag == ch) { if (Usermode_Table[i].unloaded) { save = i; Usermode_Table[i].unloaded = 0; break; } else { if (module) module->errorcode = MODERR_EXISTS; return NULL; } } i++; } i = save; if (i != UMODETABLESZ) { Usermode_Table[i].flag = ch; Usermode_Table[i].allowed = allowed; Debug((DEBUG_DEBUG, "umode_get(%c) returning %04x", ch, Usermode_Table[i].mode)); /* Update usermode table highest */ for (j = 0; j < UMODETABLESZ; j++) if (Usermode_Table[i].flag) if (i > Usermode_highest) Usermode_highest = i; make_umodestr(); AllUmodes |= Usermode_Table[i].mode; if (global) SendUmodes |= Usermode_Table[i].mode; *mode = Usermode_Table[i].mode; Usermode_Table[i].owner = module; if (module) { ModuleObject *umodeobj = MyMallocEx(sizeof(ModuleObject)); umodeobj->object.umode = &(Usermode_Table[i]); umodeobj->type = MOBJ_UMODE; AddListItem(umodeobj, module->objects); module->errorcode = MODERR_NOERROR; } return &(Usermode_Table[i]); } else { Debug((DEBUG_DEBUG, "UmodeAdd failed, no space")); if (module) module->errorcode = MODERR_NOSPACE; return NULL; } }
/* Runs a stack trace * Parameters: * e - The exception information * Returns: * The stack trace with function and line number information */ __inline char *StackTrace(EXCEPTION_POINTERS *e) { static char buffer[5000]; char curmodule[32]; DWORD symOptions, dwDisp, frame; HANDLE hProcess = GetCurrentProcess(); IMAGEHLP_SYMBOL *pSym = MyMallocEx(sizeof(IMAGEHLP_SYMBOL)+500); IMAGEHLP_LINE pLine; IMAGEHLP_MODULE pMod; STACKFRAME Stack; /* Load the stack information */ memset(&Stack, 0, sizeof(Stack)); Stack.AddrPC.Offset = e->ContextRecord->Eip; Stack.AddrPC.Mode = AddrModeFlat; Stack.AddrFrame.Offset = e->ContextRecord->Ebp; Stack.AddrFrame.Mode = AddrModeFlat; Stack.AddrStack.Offset = e->ContextRecord->Esp; Stack.AddrStack.Mode = AddrModeFlat; if (VerInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS) hProcess = (HANDLE)GetCurrentProcessId(); else hProcess = GetCurrentProcess(); /* Initialize symbol retrieval system */ SymInitialize(hProcess, NULL, TRUE); SymSetOptions(SYMOPT_LOAD_LINES|SYMOPT_UNDNAME); bzero(pSym, sizeof(IMAGEHLP_SYMBOL)+500); pSym->SizeOfStruct = sizeof(IMAGEHLP_SYMBOL); pSym->MaxNameLength = 500; bzero(&pLine, sizeof(IMAGEHLP_LINE)); pLine.SizeOfStruct = sizeof(IMAGEHLP_LINE); bzero(&pMod, sizeof(IMAGEHLP_MODULE)); pMod.SizeOfStruct = sizeof(IMAGEHLP_MODULE); /* Retrieve the first module name */ SymGetModuleInfo(hProcess, Stack.AddrPC.Offset, &pMod); strcpy(curmodule, pMod.ModuleName); sprintf(buffer, "\tModule: %s\n", pMod.ModuleName); /* Walk through the stack */ for (frame = 0; ; frame++) { char buf[500]; if (!StackWalk(IMAGE_FILE_MACHINE_I386, GetCurrentProcess(), GetCurrentThread(), &Stack, NULL, NULL, SymFunctionTableAccess, SymGetModuleBase, NULL)) break; SymGetModuleInfo(hProcess, Stack.AddrPC.Offset, &pMod); if (strcmp(curmodule, pMod.ModuleName)) { strcpy(curmodule, pMod.ModuleName); sprintf(buf, "\tModule: %s\n", pMod.ModuleName); strcat(buffer, buf); } SymGetLineFromAddr(hProcess, Stack.AddrPC.Offset, &dwDisp, &pLine); SymGetSymFromAddr(hProcess, Stack.AddrPC.Offset, &dwDisp, pSym); sprintf(buf, "\t\t#%d %s:%d: %s\n", frame, pLine.FileName, pLine.LineNumber, pSym->Name); strcat(buffer, buf); } return buffer; }
DLLFUNC int m_jumpserver(aClient *cptr, aClient *sptr, int parc, char *parv[]) { char *serv, *sslserv=NULL, *reason, *p, *p2; int all=0, port=6667, sslport=6697; char logbuf[512]; if (!IsCoAdmin(sptr) && !IsAdmin(sptr) && !IsNetAdmin(sptr) && !IsSAdmin(sptr)) { sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, parv[0]); return 0; } if ((parc < 2) || BadPtr(parv[1])) { #ifdef USE_SSL if (jss && jss->ssl_server) sendnotice(sptr, "JumpServer is \002ENABLED\002 to %s:%d (SSL: %s:%d) with reason '%s'", jss->server, jss->port, jss->ssl_server, jss->ssl_port, jss->reason); else #endif if (jss) sendnotice(sptr, "JumpServer is \002ENABLED\002 to %s:%d with reason '%s'", jss->server, jss->port, jss->reason); else sendnotice(sptr, "JumpServer is \002DISABLED\002"); return 0; } if ((parc > 1) && (!strcasecmp(parv[1], "OFF") || !strcasecmp(parv[1], "STOP"))) { if (!jss) { sendnotice(sptr, "JUMPSERVER: No redirect active (already OFF)"); return 0; } free_jss(); snprintf(logbuf, sizeof(logbuf), "%s (%s@%s) turned JUMPSERVER OFF", sptr->name, sptr->user->username, sptr->user->realhost); sendto_realops("%s", logbuf); ircd_log(LOG_ERROR, "%s", logbuf); return 0; } if (parc < 4) { /* Waah, pretty verbose usage info ;) */ sendnotice(sptr, "Use: /JUMPSERVER <server>[:port] <NEW|ALL> <reason>"); #ifdef USE_SSL sendnotice(sptr, " Or: /JUMPSERVER <server>[:port]/<sslserver>[:port] <NEW|ALL> <reason>"); #endif sendnotice(sptr, "if 'NEW' is chosen then only new (incoming) connections will be redirected"); sendnotice(sptr, "if 'ALL' is chosen then all clients except opers will be redirected immediately (+incoming connections)"); sendnotice(sptr, "Example: /JUMPSERVER irc2.test.net NEW This server will be upgraded, please use irc2.test.net for now"); sendnotice(sptr, "And then for example 10 minutes later..."); sendnotice(sptr, " /JUMPSERVER irc2.test.net ALL This server will be upgraded, please use irc2.test.net for now"); sendnotice(sptr, "Use: '/JUMPSERVER OFF' to turn off any redirects"); return 0; } /* Parsing code follows... * The parsing of the SSL stuff is still done even on non-SSL, * but it's simply not used/applied :). * Reason for this is to reduce non-SSL/SSL inconsistency issues. */ serv = parv[1]; p = strchr(serv, '/'); if (p) { *p = '\0'; sslserv = p+1; } p = strchr(serv, ':'); if (p) { *p++ = '\0'; port = atoi(p); if ((port < 1) || (port > 65535)) { sendnotice(sptr, "Invalid serverport specified (%d)", port); return 0; } } if (sslserv) { p = strchr(sslserv, ':'); if (p) { *p++ = '\0'; sslport = atoi(p); if ((sslport < 1) || (sslport > 65535)) { sendnotice(sptr, "Invalid SSL serverport specified (%d)", sslport); return 0; } } if (!*sslserv) sslserv = NULL; } if (!strcasecmp(parv[2], "new")) all = 0; else if (!strcasecmp(parv[2], "all")) all = 1; else { sendnotice(sptr, "ERROR: Invalid action '%s', should be 'NEW' or 'ALL' (see /jumpserver help for usage)", parv[2]); return 0; } reason = parv[3]; /* Free any old stuff (needed!) */ if (jss) free_jss(); jss = MyMallocEx(sizeof(JSS)); /* Set it */ jss->server = strdup(serv); jss->port = port; #ifdef USE_SSL if (sslserv) { jss->ssl_server = strdup(sslserv); jss->ssl_port = sslport; } #endif jss->reason = strdup(reason); /* Broadcast/log */ #ifdef USE_SSL if (sslserv) snprintf(logbuf, sizeof(logbuf), "%s (%s@%s) added JUMPSERVER redirect for %s to %s:%d [SSL: %s:%d] with reason '%s'", sptr->name, sptr->user->username, sptr->user->realhost, all ? "ALL CLIENTS" : "all new clients", jss->server, jss->port, jss->ssl_server, jss->ssl_port, jss->reason); else #endif snprintf(logbuf, sizeof(logbuf), "%s (%s@%s) added JUMPSERVER redirect for %s to %s:%d with reason '%s'", sptr->name, sptr->user->username, sptr->user->realhost, all ? "ALL CLIENTS" : "all new clients", jss->server, jss->port, jss->reason); sendto_realops("%s", logbuf); ircd_log(LOG_ERROR, "%s", logbuf); if (all) redirect_all_clients(); return 0; }