void SetLogMsgUser(Cfg *cfg, HostSub *hostSub, THosts *hosts, LogMsg *logmsg) { Host *host = hostSub->addr.IsEnabled() ? hosts->GetHostByAddr(hostSub) : hosts->GetHostByName(hostSub); LogHost log_host; log_host.uid = hostSub->u.userName; log_host.addr = hostSub->addr.S(); log_host.host = hostSub->u.hostName; if (host && IsSameHost(hostSub, &host->hostSub) || GetUserNameDigestField(hostSub->u.userName) && (host = cfg->priorityHosts.GetHostByName(hostSub))) { log_host.gname = host->groupName; log_host.nick = host->nickName; if (!hostSub->addr.IsEnabled()) { log_host.addr = host->hostSub.addr.S(); } } if (!log_host.nick) { log_host.nick = hostSub->u.userName; } logmsg->host.push_back(log_host); }
/* ログ記録/ウィンドウ表示用の HostEntry表示文字列 */ void MakeListString(Cfg *cfg, HostSub *hostSub, THosts *hosts, char *buf, BOOL is_log) { Host *host; if ((host = hosts->GetHostByAddr(hostSub)) && IsSameHost(hostSub, &host->hostSub) || GetUserNameDigestField(hostSub->userName) && (host = cfg->priorityHosts.GetHostByName(hostSub))) MakeListString(cfg, host, buf, is_log); else { Host host; memset(&host, 0, sizeof(host)); host.hostSub = *hostSub; MakeListString(cfg, &host, buf, is_log); } }
/* 1: success 0: verify_error -1: no_digest_user */ int VerifyUserNameDigest(const char *user, const BYTE *key) { BYTE val1[8]; BYTE val2[8]; int len = 0; const char *p; if (!(p = GetUserNameDigestField(user)) || !hexstr2bin(p+2, val1, 8, &len) || len != 8) { return -1; } if (!GenUserNameDigestVal(key, val2)) { return -1; } return memcmp(val1, val2, 8) == 0 ? 1 : 0; }
BOOL Cfg::WriteRegistry(int ctl_flg) { char buf[MAX_LISTBUF], val[MAX_LISTBUF]; int i; GetRegName(buf, nicAddr, portNo); TRegistry reg(HS_TOOLS, buf); if (ctl_flg & CFG_GENERAL) { reg.SetStr(NULL, GetVersionStr()); reg.SetInt(LCID_KEY, lcid); reg.SetInt(NOBEEP_STR, NoBeep); reg.SetInt(NOTCP_STR, NoTcp); reg.SetInt(LISTGET_STR, ListGet); reg.SetInt(LISTGETMSEC_STR, (int)ListGetMSec); reg.SetInt(RETRYMSEC_STR, (int)RetryMSec); reg.SetInt(RETRYMAX_STR, (int)RetryMax); reg.SetInt(IsWinNT() ? RECVMAXNT_STR : RECVMAX95_STR, (int)RecvMax); reg.SetInt(NOERASE_STR, NoErase); // reg.SetInt(DEBUG_STR, Debug); reg.SetInt(NOPOPUPCHECK_STR, NoPopupCheck); reg.SetInt(OPENCHECK_STR, OpenCheck); reg.SetInt(ALLOWSENDLIST_STR, AllowSendList); reg.SetInt(FILETRANSOPT_STR, fileTransOpt); reg.SetInt(RESOLVEOPT_STR, ResolveOpt); // reg.SetInt(LETTERKEY_STR, LetterKey); // reg.SetInt(REMOTEGRACE_STR, RemoteGraceSec); reg.SetStr(REBOOT_STR, RemoteReboot); reg.SetInt(REBOOTMODE_STR, RemoteRebootMode); reg.SetStr(EXIT_STR, RemoteExit); reg.SetInt(EXITMODE_STR, RemoteExitMode); reg.SetInt(CLIPMODE_STR, ClipMode); // reg.SetInt(CLIPMAX_STR, ClipMax); // reg.SetInt(CAPTUREDELAY_STR, CaptureDelay); // reg.SetInt(CAPTUREDELAYEX_STR, CaptureDelayEx); reg.SetInt(CAPTUREMINIMIZE_STR, CaptureMinimize); reg.SetInt(CAPTURECLIP_STR, CaptureClip); reg.SetInt(CAPTURESAVE_STR, CaptureSave); reg.SetInt(OPENMSGTIME_STR, OpenMsgTime); reg.SetInt(RECVMSGTIME_STR, RecvMsgTime); reg.SetInt(BALLOONNOINFO_STR, BalloonNoInfo); // reg.SetInt(TASKBARUI_STR, TaskbarUI); // reg.SetInt(MARKERTHICK_STR, MarkerThick); if (IsWinVista()) reg.SetInt(IPV6MODE_STR, IPv6ModeNext); // if (IsWinVista()) reg.SetStr(IPV6MULITCAST, IPv6Multicast); // reg.SetInt(VIEWMAX_STR, ViewMax); // reg.SetInt(TRANSMAX_STR, TransMax); // reg.SetInt(TCPBUFMAX_STR, TcpbufMax); // reg.SetInt(IOBUFMAX_STR, IoBufMax); reg.SetInt(LUMPCHECK_STR, LumpCheck); reg.SetInt(ENCTRANSCHECK_STR, EncTransCheck); } if (ctl_flg & CFG_ABSENCE) { reg.SetInt(ABSENCESAVE_STR, AbsenceSave); reg.SetInt(ABSENCECHECK_STR, AbsenceCheck); reg.SetInt(ABSENCEMAX_STR, AbsenceMax); if (reg.CreateKey(ABSENCESTR_STR)) { for (i=0; i < AbsenceMax; i++) { char key[MAX_PATH_U8]; sprintf(key, "%s%d", ABSENCESTR_STR, i); reg.SetStr(key, AbsenceStr[i]); sprintf(key, "%s%d", ABSENCEHEAD_STR, i); reg.SetStr(key, AbsenceHead[i]); } } reg.CloseKey(); } if (ctl_flg & CFG_GENERAL) { reg.SetStr(PASSWORD_STR, PasswordStr); reg.SetInt(PASSWDLOGCHECK_STR, PasswdLogCheck); reg.SetInt(DELAYTIME_STR, DelayTime); reg.SetInt(QUOTECHECK_STR, QuoteCheck); reg.SetInt(SECRETCHECK_STR, SecretCheck); reg.SetInt(LOGONLOG_STR, LogonLog); reg.SetInt(RECVLOGONDISP_STR, RecvLogonDisp); reg.SetInt(IPADDRCHECK_STR, IPAddrCheck); reg.SetInt(RECVIPADDRCHECK_STR, RecvIPAddr); reg.SetInt(ONECLICKPOPUP_STR, OneClickPopup); reg.SetInt(BALLOONNOTIFY_STR, BalloonNotify); reg.SetInt(TRAYICON_STR, TrayIcon); reg.SetInt(ABNORMALBTN_STR, AbnormalButton); reg.SetInt(DIALUPCHECK_STR, DialUpCheck); reg.SetInt(ABSENCENONPOPUP_STR, AbsenceNonPopup); reg.SetStr(NICKNAMESTR_STR, NickNameStr); reg.SetStr(GROUPNAMESTR_STR, GroupNameStr); reg.SetLong(SORT_STR, Sort); reg.SetInt(UPDATETIME_STR, UpdateTime); reg.SetInt(KEEPHOSTTIME_STR, KeepHostTime); reg.SetInt(EXTENDENTRY_STR, ExtendEntry); reg.SetInt(EXTENDBROADCAST_STR, ExtendBroadcast); reg.SetInt(MULTICASTMODE_STR, MulticastMode); reg.SetInt(CONTROLIME_STR, ControlIME); reg.SetInt(GRIDLINE_STR, GridLineCheck); reg.SetInt(COLUMNITEMS_STR, ColumnItems); reg.SetStr(QUOTESTR_STR, QuoteStr); if (reg.CreateKey(HOTKEY_STR)) { reg.SetInt(HOTKEYCHECK_STR, HotKeyCheck); reg.SetInt(HOTKEYMODIFY_STR, HotKeyModify); reg.SetInt(HOTKEYSEND_STR, HotKeySend); reg.SetInt(HOTKEYRECV_STR, HotKeyRecv); reg.SetInt(HOTKEYMISC_STR, HotKeyMisc); reg.CloseKey(); } reg.SetInt(LOGCHECK_STR, LogCheck); reg.SetInt(LOGUTF8_STR, LogUTF8); reg.SetStr(LOGFILE_STR, LogFile); reg.SetStr(SOUNDFILE_STR, SoundFile); reg.SetStr(ICON_STR, IconFile); reg.SetStr(REVICON_STR, RevIconFile); reg.SetStr(LASTOPEN_STR, lastOpenDir); reg.SetStr(LASTSAVE_STR, lastSaveDir); reg.SetInt(LRUUSERMAX_STR, lruUserMax); reg.SetStr(AUTOSAVEDIR_STR, autoSaveDir); reg.SetInt(AUTOSAVETOUT_STR, autoSaveTout); reg.SetInt(AUTOSAVEMAX_STR, autoSaveMax); reg.SetInt(AUTOSAVELEVEL_STR, autoSaveLevel); reg.SetInt(AUTOSAVEFLAGS_STR, autoSaveFlags); } if ((ctl_flg & CFG_WINSIZE) && reg.CreateKey(WINSIZE_STR)) { reg.SetInt(SENDNICKNAME_STR, SendWidth[SW_NICKNAME]); reg.SetInt(SENDUSERNAME_STR, SendWidth[SW_USER]); reg.SetInt(SENDABSENCE_STR, SendWidth[SW_ABSENCE]); reg.SetInt(SENDPRIORITY_STR, SendWidth[SW_PRIORITY]); reg.SetInt(SENDGROUPNAME_STR, SendWidth[SW_GROUP]); reg.SetInt(SENDHOSTNAME_STR, SendWidth[SW_HOST]); reg.SetInt(SENDIPADDR_STR, SendWidth[SW_IPADDR]); if (reg.CreateKey(SENDORDER_STR)) { for (i=0; i < MAX_SENDWIDTH; i++) { sprintf(buf, "%d", i); reg.SetInt(buf, SendOrder[i]); } reg.CloseKey(); } reg.SetInt(SENDXDIFF_STR, SendXdiff); reg.SetInt(SENDYDIFF_STR, SendYdiff); reg.SetInt(SENDMIDYDIFF_STR, SendMidYdiff); reg.SetInt(SENDSAVEPOS_STR, SendSavePos); reg.SetInt(SENDXPOS_STR, SendXpos); reg.SetInt(SENDYPOS_STR, SendYpos); reg.SetInt(RECVXDIFF_STR, RecvXdiff); reg.SetInt(RECVYDIFF_STR, RecvYdiff); reg.SetInt(RECVSAVEPOS_STR, RecvSavePos); reg.SetInt(RECVXPOS_STR, RecvXpos); reg.SetInt(RECVYPOS_STR, RecvYpos); reg.SetInt(HISTXDIFF_STR, HistXdiff); reg.SetInt(HISTYDIFF_STR, HistYdiff); reg.SetInt(HISTUSER_STR, HistWidth[HW_USER]); reg.SetInt(HISTODATE_STR, HistWidth[HW_ODATE]); reg.SetInt(HISTSDATE_STR, HistWidth[HW_SDATE]); reg.SetInt(HISTID_STR, HistWidth[HW_ID]); reg.CloseKey(); } if ((ctl_flg & CFG_FONT) && reg.CreateKey(FONT_STR)) { WriteFontRegistry(®, SENDEDITFONT_STR, &SendEditFont); WriteFontRegistry(®, SENDLISTFONT_STR, &SendListFont); WriteFontRegistry(®, RECVHEADFONT_STR, &RecvHeadFont); WriteFontRegistry(®, RECVEDITFONT_STR, &RecvEditFont); WriteFontRegistry(®, LOGVIEWFONT_STR, &LogViewFont); reg.CloseKey(); } if ((ctl_flg & CFG_BROADCAST) && reg.CreateKey(BROADCAST_STR)) { i = 0; for (TBrObj *obj=brList.TopObj(); obj; obj=brList.NextObj(obj)) { sprintf(buf, "%d", i++); reg.SetStr(buf, obj->Host()); } while (1) { sprintf(buf, "%d", i++); if (!reg.GetStr(buf, val, sizeof(val))) break; if (!reg.DeleteValue(buf)) break; } reg.CloseKey(); } if (ctl_flg & CFG_CLICKURL) { reg.SetInt(DEFAULTURL_STR, DefaultUrl); reg.SetInt(SHELLEXEC_STR, ShellExec); if (reg.CreateKey(CLICKABLEURL_STR)) { for (UrlObj *obj = urlList.TopObj(); obj; obj = urlList.NextObj(obj)) reg.SetStr(obj->protocol, obj->program); reg.CloseKey(); } } if ((ctl_flg & CFG_PRIORITY) && reg.CreateKey(PRIORITY_STR)) { reg.SetInt(PRIORITYMAX_STR, PriorityMax); reg.SetInt(PRIORITYREJECT_STR, PriorityReject); #if 0 for (i=0; i < PriorityMax; i++) { sprintf(buf, "%d", i); if (reg.CreateKey(buf)) { reg.SetStr(PRIORITYSOUND_STR, PrioritySound[i] ? PrioritySound[i] : ""); reg.CloseKey(); } } #endif reg.CloseKey(); } if ((ctl_flg & CFG_HOSTINFO) && reg.CreateKey(HOSTINFO_STR)) { Time_t now_time = Time(); BYTE pubkey[MAX_BUF]; int pubkeySize; if (ctl_flg & CFG_DELHOST) reg.DeleteChildTree(); for (i=0; i < priorityHosts.HostCnt(); i++) { Host *host = priorityHosts.GetHost(i); int to_store_size = 2048 / 8; // 2048bits RSA key sprintf(buf, "%s:%s", host->hostSub.userName, host->hostSub.hostName); if (host->updateTime + KeepHostTime < now_time || (host->pubKey.KeyLen() < to_store_size && host->priority == DEFAULT_PRIORITY)) { if (ctl_flg & CFG_DELCHLDHOST) reg.DeleteChildTree(buf); } else if (reg.CreateKey(buf)) { reg.SetStr(USERNAME_STR, host->hostSub.userName); reg.SetStr(HOSTNAME_STR, host->hostSub.hostName); reg.SetLong(IPADDR_STR, host->hostSub.addr.V4Addr()); reg.SetInt(PORTNO_STR, host->hostSub.portNo); reg.SetStr(NICKNAME_STR, host->nickName); reg.SetStr(GROUPNAME_STR, host->groupName); if (*host->alterName) reg.SetStr(ALTERNAME_STR, host->alterName); reg.SetInt(PRIORITY_STR, host->priority); reg.SetLong(UPDATETIME_STR, (long)host->updateTime); if (host->pubKey.KeyLen() >= to_store_size) { char *p = (char *)GetUserNameDigestField(host->hostSub.userName); if (p && (pubkeySize = host->pubKey.Serialize(pubkey, sizeof(pubkey))) > 0) { reg.SetByte(PUBLICKEY_STR, pubkey, pubkeySize); } } reg.CloseKey(); } } reg.CloseKey(); } if ((ctl_flg & CFG_FINDHIST) && reg.CreateKey(FINDSTR_STR)) { reg.SetInt(FINDMAX_STR, FindMax); reg.SetInt(FINDALL_STR, FindAll); for (i=0; i < FindMax; i++) { char key[MAX_PATH_U8]; sprintf(key, "%d", i); reg.SetStr(key, FindStr[i]); } reg.CloseKey(); } if (ctl_flg & CFG_LRUUSER) { reg.DeleteChildTree(LRUUSERKEY_STR); if (reg.CreateKey(LRUUSERKEY_STR)) { UsersObj *obj=lruUserList.TopObj(); for (i=0; obj; i++) { sprintf(buf, "%d", i); if (!reg.CreateKey(buf)) break; UserObj *u = obj->users.TopObj(); for (int j=0; u; j++) { sprintf(buf, "%d", j); if (!reg.CreateKey(buf)) break; reg.SetStr(USERNAME_STR, u->hostSub.userName); reg.SetStr(HOSTNAME_STR, u->hostSub.hostName); reg.CloseKey(); u = obj->users.NextObj(u); } reg.CloseKey(); obj = lruUserList.NextObj(obj); } reg.CloseKey(); } } // private/public key if (ctl_flg & CFG_CRYPT) { for (int i=KEY_1024; i <= KEY_2048; i++) { const char *key = (i == KEY_1024) ? CRYPT_STR : CRYPT2_STR; if (reg.CreateKey(key) && priv[i].blob) { reg.SetByte(PRIVBLOB_STR, priv[i].blob, priv[i].blobLen); if (priv[i].encryptSeed) reg.SetByte(PRIVSEED_STR, priv[i].encryptSeed, priv[i].encryptSeedLen); reg.SetInt(PRIVTYPE_STR, priv[i].encryptType); reg.CloseKey(); } } } return TRUE; }
BOOL VerifyUserNameExtension(Cfg *cfg, MsgBuf *msg) { return !IsUserNameExt(cfg) || !GetUserNameDigestField(msg->hostSub.userName) || (msg->command & IPMSG_ENCRYPTOPT) ? TRUE : FALSE; }