OSDN Git Service

Add support for linux-ftpd (untested).
[ffftp/ffftp.git] / registry.c
1 /*=============================================================================\r
2 *                                                               レジストリ関係\r
3 *\r
4 *\r
5 ===============================================================================\r
6 / Copyright (C) 1997-2007 Sota. All rights reserved.\r
7 /\r
8 / Redistribution and use in source and binary forms, with or without \r
9 / modification, are permitted provided that the following conditions \r
10 / are met:\r
11 /\r
12 /  1. Redistributions of source code must retain the above copyright \r
13 /     notice, this list of conditions and the following disclaimer.\r
14 /  2. Redistributions in binary form must reproduce the above copyright \r
15 /     notice, this list of conditions and the following disclaimer in the \r
16 /     documentation and/or other materials provided with the distribution.\r
17 /\r
18 / THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR \r
19 / IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES \r
20 / OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. \r
21 / IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, \r
22 / INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, \r
23 / BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF \r
24 / USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON \r
25 / ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
26 / (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF \r
27 / THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
28 /============================================================================*/\r
29 \r
30 // VC 8.0(2005)以上でのみ rand_s を利用可能\r
31 #if 1400 <= _MSC_VER\r
32 //#define _CRT_RAND_S\r
33 #endif\r
34 \r
35 #define STRICT\r
36 // IPv6対応\r
37 #include <winsock2.h>\r
38 #include <windows.h>\r
39 #include <stdio.h>\r
40 #include <stdlib.h>\r
41 #include <time.h>\r
42 #include <string.h>\r
43 #include <windowsx.h>\r
44 #include <process.h>\r
45 \r
46 \r
47 #include "common.h"\r
48 #include "resource.h"\r
49 #include "sample.h"\r
50 #include "sha.h"\r
51 #include "aes.h"\r
52 \r
53 \r
54 /*===== プロトタイプ =====*/\r
55 \r
56 static void SaveStr(HKEY hKey, char *Key, char *Str, char *DefaultStr);\r
57 static void SaveIntNum(HKEY hKey, char *Key, int Num, int DefaultNum);\r
58 static void MakeFontData(LOGFONT Font, HFONT hFont, char *Buf);\r
59 static int RestoreFontData(char *Str, LOGFONT *Font);\r
60 \r
61 static void EncodePassword(char *Str, char *Buf);\r
62 static void EncodePasswordOriginal(char *Str, char *Buf);\r
63 static void EncodePassword2(char *Str, char *Buf, const char *Key);\r
64 static void EncodePassword3(char *Str, char *Buf, const char *Key);\r
65 \r
66 static void DecodePassword(char *Str, char *Buf);\r
67 static void DecodePasswordOriginal(char *Str, char *Buf);\r
68 static void DecodePassword2(char *Str, char *Buf, const char *Key);\r
69 static void DecodePassword3(char *Str, char *Buf, const char *Key);\r
70 static int CreateAesKey(unsigned char *AesKey, const char* Key);\r
71 \r
72 static void SetRegType(int Type);\r
73 static int OpenReg(char *Name, void **Handle);\r
74 static int CreateReg(char *Name, void **Handle);\r
75 static int CloseReg(void *Handle);\r
76 static int OpenSubKey(void *Parent, char *Name, void **Handle);\r
77 static int CreateSubKey(void *Parent, char *Name, void **Handle);\r
78 static int CloseSubKey(void *Handle);\r
79 static int DeleteSubKey(void *Handle, char *Name);\r
80 static int DeleteValue(void *Handle, char *Name);\r
81 static int ReadIntValueFromReg(void *Handle, char *Name, int *Value);\r
82 static int WriteIntValueToReg(void *Handle, char *Name, int Value);\r
83 static int ReadStringFromReg(void *Handle, char *Name, char *Str, DWORD Size);\r
84 static int WriteStringToReg(void *Handle, char *Name, char *Str);\r
85 static int ReadMultiStringFromReg(void *Handle, char *Name, char *Str, DWORD Size);\r
86 static int WriteMultiStringToReg(void *Handle, char *Name, char *Str);\r
87 static int ReadBinaryFromReg(void *Handle, char *Name, void *Bin, DWORD Size);\r
88 static int WriteBinaryToReg(void *Handle, char *Name, void *Bin, int Len);\r
89 // 暗号化通信対応\r
90 static int StrCatOut(char *Src, int Len, char *Dst);\r
91 static int StrReadIn(char *Src, int Max, char *Dst);\r
92 \r
93 int CheckPasswordValidity( char* Password, int length, const char* HashStr );\r
94 void CreatePasswordHash( char* Password, int length, char* HashStr );\r
95 void SetHashSalt( DWORD salt );\r
96 \r
97 DWORD GetRandamDWRODValue(void);\r
98 \r
99 /* 2010.01.30 genta 追加 */\r
100 static char SecretKey[FMAX_PATH+1];\r
101 static int SecretKeyLength;\r
102 static int IsMasterPasswordError = PASSWORD_OK;\r
103 \r
104 static int IsRndSourceInit = 0;\r
105 static ulong RndSource[9];\r
106 \r
107 // UTF-8対応\r
108 static int IniKanjiCode = KANJI_NOCNV;\r
109 \r
110 /*===== 外部参照 =====*/\r
111 \r
112 /* 設定値 */\r
113 extern int WinPosX;\r
114 extern int WinPosY;\r
115 extern int WinWidth;\r
116 extern int WinHeight;\r
117 extern int LocalWidth;\r
118 extern int TaskHeight;\r
119 extern int LocalTabWidth[4];\r
120 extern int RemoteTabWidth[6];\r
121 extern char UserMailAdrs[USER_MAIL_LEN+1];\r
122 extern char ViewerName[VIEWERS][FMAX_PATH+1];\r
123 extern HFONT ListFont;\r
124 extern LOGFONT ListLogFont;\r
125 extern int LocalFileSort;\r
126 extern int LocalDirSort;\r
127 extern int RemoteFileSort;\r
128 extern int RemoteDirSort;\r
129 extern int TransMode;\r
130 extern int ConnectOnStart;\r
131 extern int DebugConsole;\r
132 extern int SaveWinPos;\r
133 extern char AsciiExt[ASCII_EXT_LEN+1];\r
134 extern int RecvMode;\r
135 extern int SendMode;\r
136 extern int MoveMode;\r
137 extern int ListType;\r
138 extern int CacheEntry;\r
139 extern int CacheSave;\r
140 extern char DefaultLocalPath[FMAX_PATH+1];\r
141 extern int SaveTimeStamp;\r
142 extern int FindMode;\r
143 extern int DotFile;\r
144 extern int DclickOpen;\r
145 extern SOUNDFILE Sound[SOUND_TYPES];\r
146 extern int FnameCnv;\r
147 extern int ConnectAndSet;\r
148 extern int TimeOut;\r
149 extern int RmEOF;\r
150 extern int RegType;\r
151 extern char FwallHost[HOST_ADRS_LEN+1];\r
152 extern char FwallUser[USER_NAME_LEN+1];\r
153 extern char FwallPass[PASSWORD_LEN+1];\r
154 extern int FwallPort;\r
155 extern int FwallType;\r
156 extern int FwallDefault;\r
157 extern int FwallSecurity;\r
158 extern int FwallResolv;\r
159 extern int FwallLower;\r
160 extern int FwallDelimiter;\r
161 extern int PasvDefault;\r
162 extern char MirrorNoTrn[MIRROR_LEN+1];\r
163 extern char MirrorNoDel[MIRROR_LEN+1];\r
164 extern int MirrorFnameCnv;\r
165 //extern int MirrorFolderCnv;\r
166 extern int RasClose;\r
167 extern int RasCloseNotify;\r
168 extern int FileHist;\r
169 extern char DefAttrList[DEFATTRLIST_LEN+1];\r
170 extern SIZE HostDlgSize;\r
171 extern SIZE BmarkDlgSize;\r
172 extern SIZE MirrorDlgSize;\r
173 extern int Sizing;\r
174 extern int SortSave;\r
175 extern char TmpPath[FMAX_PATH+1];\r
176 extern int QuickAnonymous;\r
177 extern int PassToHist;\r
178 extern int VaxSemicolon;\r
179 extern int SendQuit;\r
180 extern int NoRasControl;\r
181 extern int SuppressSave;\r
182 \r
183 extern int UpExistMode;\r
184 extern int ExistMode;\r
185 extern int DispIgnoreHide;\r
186 extern int DispDrives;\r
187 extern int MirUpDelNotify;\r
188 extern int MirDownDelNotify;\r
189 \r
190 extern int FolderAttr;\r
191 extern int FolderAttrNum;\r
192 \r
193 // 暗号化通信対応\r
194 extern BYTE CertificateCacheHash[MAX_CERT_CACHE_HASH][20];\r
195 extern BYTE SSLRootCAFileHash[20];\r
196 \r
197 /*----- マスタパスワードの設定 ----------------------------------------------\r
198 *\r
199 *       Parameter\r
200 *               const char* Password : マスターパスワード\r
201 *\r
202 *       Return Value\r
203 *               なし\r
204 *----------------------------------------------------------------------------*/\r
205 void SetMasterPassword( const char* Password )\r
206 {\r
207         ZeroMemory( SecretKey, MAX_PASSWORD_LEN + 12 );\r
208         if( Password != NULL ){\r
209                 strncpy( SecretKey, Password, MAX_PASSWORD_LEN );\r
210         }\r
211         else {\r
212                 strcpy( SecretKey, DEFAULT_PASSWORD );\r
213         }\r
214         SecretKeyLength = strlen( SecretKey );\r
215         \r
216         /* 未検証なので,初期状態はOKにする (強制再設定→保存にを可能にする)*/\r
217         IsMasterPasswordError = PASSWORD_OK;\r
218 }\r
219 \r
220 /*----- マスタパスワードの状態取得 ----------------------------------------------\r
221 *\r
222 *       Parameter\r
223 *               なし\r
224 *\r
225 *       Return Value\r
226 *               PASSWORD_OK : OK\r
227 *               PASSWORD_UNMATCH : パスワード不一致\r
228 *               BAD_PASSWORD_HASH : パスワード確認失敗\r
229 *----------------------------------------------------------------------------*/\r
230 int GetMasterPasswordStatus(void)\r
231 {\r
232         return IsMasterPasswordError;\r
233 }\r
234 \r
235 /*----- レジストリ/INIファイルのマスターパスワードの検証を行う ------------\r
236 *\r
237 *       Parameter\r
238 *               なし\r
239 *\r
240 *       Return Value\r
241 *               \r
242 *----------------------------------------------------------------------------*/\r
243 \r
244 int ValidateMasterPassword(void)\r
245 {\r
246         void *hKey3;\r
247         int i;\r
248 \r
249         SetRegType(REGTYPE_INI);\r
250         if((i = OpenReg("FFFTP", &hKey3)) != FFFTP_SUCCESS)\r
251         {\r
252                 if(AskForceIni() == NO)\r
253                 {\r
254                         SetRegType(REGTYPE_REG);\r
255                         i = OpenReg("FFFTP", &hKey3);\r
256                 }\r
257         }\r
258         if(i == FFFTP_SUCCESS){\r
259                 char checkbuf[48];\r
260                 int salt = 0;\r
261 \r
262                 if( ReadIntValueFromReg(hKey3, "CredentialSalt", &salt)){\r
263                         SetHashSalt( salt );\r
264                 }\r
265                 if( ReadStringFromReg(hKey3, "CredentialCheck", checkbuf, sizeof( checkbuf )) == FFFTP_SUCCESS ){\r
266                         switch( CheckPasswordValidity( SecretKey, SecretKeyLength, checkbuf ) ){\r
267                         case 0: /* not match */\r
268                                 IsMasterPasswordError = PASSWORD_UNMATCH;\r
269                                 break;\r
270                         case 1: /* match */\r
271                                 IsMasterPasswordError = PASSWORD_OK;\r
272                                 break;\r
273                         case 2: /* invalid hash */\r
274                         default:\r
275                                 IsMasterPasswordError = BAD_PASSWORD_HASH;\r
276                                 break;\r
277                         }\r
278                 }\r
279                 CloseReg(hKey3);\r
280                 return YES;\r
281         }\r
282         return NO;\r
283 }\r
284 \r
285 /*----- レジストリ/INIファイルに設定値を保存 ---------------------------------\r
286 *\r
287 *       Parameter\r
288 *               なし\r
289 *\r
290 *       Return Value\r
291 *               なし\r
292 *----------------------------------------------------------------------------*/\r
293 \r
294 void SaveRegistory(void)\r
295 {\r
296         void *hKey3;\r
297         void *hKey4;\r
298         void *hKey5;\r
299         // 暗号化通信対応\r
300 //      char Str[FMAX_PATH+1];\r
301         char Str[PRIVATE_KEY_LEN*4+1];\r
302         char Buf[FMAX_PATH+1];\r
303         int i;\r
304         int n;\r
305         HOSTDATA DefaultHost;\r
306         HOSTDATA Host;\r
307         HISTORYDATA Hist;\r
308         HISTORYDATA DefaultHist;\r
309         \r
310         if( GetMasterPasswordStatus() == PASSWORD_UNMATCH ){\r
311                 /* 2010.01.30 genta: マスターパスワードが不一致の場合は不用意に上書きしない */\r
312                 return;\r
313         }\r
314 \r
315         SetRegType(RegType);\r
316         if(CreateReg("FFFTP", &hKey3) == FFFTP_SUCCESS)\r
317         {\r
318                 char buf[48];\r
319                 int salt = GetTickCount();\r
320         \r
321                 WriteIntValueToReg(hKey3, "Version", VER_NUM);\r
322                 WriteIntValueToReg(hKey3, "CredentialSalt", salt);\r
323                 \r
324                 SetHashSalt( salt );\r
325                 /* save password hash */\r
326                 CreatePasswordHash( SecretKey, SecretKeyLength, buf );\r
327                 WriteStringToReg(hKey3, "CredentialCheck", buf);\r
328 \r
329                 if(CreateSubKey(hKey3, "Options", &hKey4) == FFFTP_SUCCESS)\r
330                 {\r
331                         WriteIntValueToReg(hKey4, "NoSave", SuppressSave);\r
332 \r
333                         if(SuppressSave != YES)\r
334                         {\r
335                                 WriteIntValueToReg(hKey4, "WinPosX", WinPosX);\r
336                                 WriteIntValueToReg(hKey4, "WinPosY", WinPosY);\r
337                                 WriteIntValueToReg(hKey4, "WinWidth", WinWidth);\r
338                                 WriteIntValueToReg(hKey4, "WinHeight", WinHeight);\r
339                                 WriteIntValueToReg(hKey4, "LocalWidth", LocalWidth);\r
340                                 WriteIntValueToReg(hKey4, "TaskHeight", TaskHeight);\r
341                                 WriteBinaryToReg(hKey4, "LocalColm", LocalTabWidth, sizeof(LocalTabWidth));\r
342                                 WriteBinaryToReg(hKey4, "RemoteColm", RemoteTabWidth, sizeof(RemoteTabWidth));\r
343                                 WriteIntValueToReg(hKey4, "SwCmd", Sizing);\r
344 \r
345                                 WriteStringToReg(hKey4, "UserMail", UserMailAdrs);\r
346                                 WriteStringToReg(hKey4, "Viewer", ViewerName[0]);\r
347                                 WriteStringToReg(hKey4, "Viewer2", ViewerName[1]);\r
348                                 WriteStringToReg(hKey4, "Viewer3", ViewerName[2]);\r
349 \r
350                                 WriteIntValueToReg(hKey4, "TrType", TransMode);\r
351                                 WriteIntValueToReg(hKey4, "Recv", RecvMode);\r
352                                 WriteIntValueToReg(hKey4, "Send", SendMode);\r
353                                 WriteIntValueToReg(hKey4, "Move", MoveMode);\r
354                                 WriteStringToReg(hKey4, "Path", DefaultLocalPath);\r
355                                 WriteIntValueToReg(hKey4, "Time", SaveTimeStamp);\r
356                                 WriteIntValueToReg(hKey4, "EOF", RmEOF);\r
357                                 WriteIntValueToReg(hKey4, "Scolon", VaxSemicolon);\r
358 \r
359                                 WriteIntValueToReg(hKey4, "RecvEx", ExistMode);\r
360                                 WriteIntValueToReg(hKey4, "SendEx", UpExistMode);\r
361 \r
362                                 WriteIntValueToReg(hKey4, "LFsort", LocalFileSort);\r
363                                 WriteIntValueToReg(hKey4, "LDsort", LocalDirSort);\r
364                                 WriteIntValueToReg(hKey4, "RFsort", RemoteFileSort);\r
365                                 WriteIntValueToReg(hKey4, "RDsort", RemoteDirSort);\r
366                                 WriteIntValueToReg(hKey4, "SortSave", SortSave);\r
367 \r
368                                 WriteIntValueToReg(hKey4, "ListType", ListType);\r
369                                 WriteIntValueToReg(hKey4, "Cache", CacheEntry);\r
370                                 WriteIntValueToReg(hKey4, "CacheSave", CacheSave);\r
371                                 WriteIntValueToReg(hKey4, "DotFile", DotFile);\r
372                                 WriteIntValueToReg(hKey4, "Dclick", DclickOpen);\r
373 \r
374                                 WriteIntValueToReg(hKey4, "ConS", ConnectOnStart);\r
375                                 WriteIntValueToReg(hKey4, "OldDlg", ConnectAndSet);\r
376                                 WriteIntValueToReg(hKey4, "RasClose", RasClose);\r
377                                 WriteIntValueToReg(hKey4, "RasNotify", RasCloseNotify);\r
378                                 WriteIntValueToReg(hKey4, "Qanony", QuickAnonymous);\r
379                                 WriteIntValueToReg(hKey4, "PassHist", PassToHist);\r
380                                 WriteIntValueToReg(hKey4, "SendQuit", SendQuit);\r
381                                 WriteIntValueToReg(hKey4, "NoRas", NoRasControl);\r
382 \r
383                                 WriteIntValueToReg(hKey4, "Debug", DebugConsole);\r
384                                 WriteIntValueToReg(hKey4, "WinPos", SaveWinPos);\r
385                                 WriteIntValueToReg(hKey4, "RegExp", FindMode);\r
386                                 WriteIntValueToReg(hKey4, "Reg", RegType);\r
387 \r
388                                 WriteMultiStringToReg(hKey4, "AsciiFile", AsciiExt);\r
389                                 WriteIntValueToReg(hKey4, "LowUp", FnameCnv);\r
390                                 WriteIntValueToReg(hKey4, "Tout", TimeOut);\r
391 \r
392                                 WriteMultiStringToReg(hKey4, "NoTrn", MirrorNoTrn);\r
393                                 WriteMultiStringToReg(hKey4, "NoDel", MirrorNoDel);\r
394                                 WriteIntValueToReg(hKey4, "MirFile", MirrorFnameCnv);\r
395                                 WriteIntValueToReg(hKey4, "MirUNot", MirUpDelNotify);\r
396                                 WriteIntValueToReg(hKey4, "MirDNot", MirDownDelNotify);\r
397 \r
398                                 MakeFontData(ListLogFont, ListFont, Str);\r
399                                 WriteStringToReg(hKey4, "ListFont", Str);\r
400                                 WriteIntValueToReg(hKey4, "ListHide", DispIgnoreHide);\r
401                                 WriteIntValueToReg(hKey4, "ListDrv", DispDrives);\r
402 \r
403                                 WriteStringToReg(hKey4, "FwallHost", FwallHost);\r
404                                 WriteStringToReg(hKey4, "FwallUser", FwallUser);\r
405                                 EncodePassword(FwallPass, Str);\r
406                                 WriteStringToReg(hKey4, "FwallPass", Str);\r
407                                 WriteIntValueToReg(hKey4, "FwallPort", FwallPort);\r
408                                 WriteIntValueToReg(hKey4, "FwallType", FwallType);\r
409                                 WriteIntValueToReg(hKey4, "FwallDef", FwallDefault);\r
410                                 WriteIntValueToReg(hKey4, "FwallSec", FwallSecurity);\r
411                                 WriteIntValueToReg(hKey4, "PasvDef", PasvDefault);\r
412                                 WriteIntValueToReg(hKey4, "FwallRes", FwallResolv);\r
413                                 WriteIntValueToReg(hKey4, "FwallLow", FwallLower);\r
414                                 WriteIntValueToReg(hKey4, "FwallDel", FwallDelimiter);\r
415 \r
416                                 WriteIntValueToReg(hKey4, "SndConSw", Sound[SND_CONNECT].On);\r
417                                 WriteIntValueToReg(hKey4, "SndTrnSw", Sound[SND_TRANS].On);\r
418                                 WriteIntValueToReg(hKey4, "SndErrSw", Sound[SND_ERROR].On);\r
419                                 WriteStringToReg(hKey4, "SndCon", Sound[SND_CONNECT].Fname);\r
420                                 WriteStringToReg(hKey4, "SndTrn", Sound[SND_TRANS].Fname);\r
421                                 WriteStringToReg(hKey4, "SndErr", Sound[SND_ERROR].Fname);\r
422 \r
423                                 WriteMultiStringToReg(hKey4, "DefAttr", DefAttrList);\r
424 \r
425                                 // 環境依存の不具合対策\r
426 //                              GetTempPath(FMAX_PATH, Str);\r
427                                 GetAppTempPath(Str);\r
428                                 SetYenTail(Str);\r
429                                 SaveStr(hKey4, "Tmp", TmpPath, Str);\r
430 \r
431                                 WriteBinaryToReg(hKey4, "Hdlg", &HostDlgSize, sizeof(SIZE));\r
432                                 WriteBinaryToReg(hKey4, "Bdlg", &BmarkDlgSize, sizeof(SIZE));\r
433                                 WriteBinaryToReg(hKey4, "Mdlg", &MirrorDlgSize, sizeof(SIZE));\r
434 \r
435                                 WriteIntValueToReg(hKey4, "FAttrSw", FolderAttr);\r
436                                 WriteIntValueToReg(hKey4, "FAttr", FolderAttrNum);\r
437 \r
438                                 WriteIntValueToReg(hKey4, "HistNum", FileHist);\r
439 \r
440                                 /* Ver1.54a以前の形式のヒストリデータは削除 */\r
441                                 DeleteValue(hKey4, "Hist");\r
442 \r
443                                 /* ヒストリの設定を保存 */\r
444                                 CopyDefaultHistory(&DefaultHist);\r
445                                 n = 0;\r
446                                 for(i = AskHistoryNum(); i > 0; i--)\r
447                                 {\r
448                                         if(GetHistoryByNum(i-1, &Hist) == FFFTP_SUCCESS)\r
449                                         {\r
450                                                 sprintf(Str, "History%d", n);\r
451                                                 if(CreateSubKey(hKey4, Str, &hKey5) == FFFTP_SUCCESS)\r
452                                                 {\r
453                                                         SaveStr(hKey5, "HostAdrs", Hist.HostAdrs, DefaultHist.HostAdrs);\r
454                                                         SaveStr(hKey5, "UserName", Hist.UserName, DefaultHist.UserName);\r
455                                                         SaveStr(hKey5, "Account", Hist.Account, DefaultHist.Account);\r
456                                                         SaveStr(hKey5, "LocalDir", Hist.LocalInitDir, NULL);\r
457                                                         SaveStr(hKey5, "RemoteDir", Hist.RemoteInitDir, DefaultHist.RemoteInitDir);\r
458                                                         SaveStr(hKey5, "Chmod", Hist.ChmodCmd, DefaultHist.ChmodCmd);\r
459                                                         SaveStr(hKey5, "Nlst", Hist.LsName, DefaultHist.LsName);\r
460                                                         SaveStr(hKey5, "Init", Hist.InitCmd, DefaultHist.InitCmd);\r
461                                                         EncodePassword(Hist.PassWord, Str);\r
462                                                         SaveStr(hKey5, "Password", Str, DefaultHist.PassWord);\r
463                                                         SaveIntNum(hKey5, "Port", Hist.Port, DefaultHist.Port);\r
464                                                         SaveIntNum(hKey5, "Kanji", Hist.KanjiCode, DefaultHist.KanjiCode);\r
465                                                         SaveIntNum(hKey5, "KanaCnv", Hist.KanaCnv, DefaultHist.KanaCnv);\r
466                                                         SaveIntNum(hKey5, "NameKanji", Hist.NameKanjiCode, DefaultHist.NameKanjiCode);\r
467                                                         SaveIntNum(hKey5, "NameKana", Hist.NameKanaCnv, DefaultHist.NameKanaCnv);\r
468                                                         SaveIntNum(hKey5, "Pasv", Hist.Pasv, DefaultHist.Pasv);\r
469                                                         SaveIntNum(hKey5, "Fwall", Hist.FireWall, DefaultHist.FireWall);\r
470                                                         SaveIntNum(hKey5, "List", Hist.ListCmdOnly, DefaultHist.ListCmdOnly);\r
471                                                         SaveIntNum(hKey5, "NLST-R", Hist.UseNLST_R, DefaultHist.UseNLST_R);\r
472                                                         SaveIntNum(hKey5, "Tzone", Hist.TimeZone, DefaultHist.TimeZone);\r
473                                                         SaveIntNum(hKey5, "Type", Hist.HostType, DefaultHist.HostType);\r
474                                                         SaveIntNum(hKey5, "Sync", Hist.SyncMove, DefaultHist.SyncMove);\r
475                                                         SaveIntNum(hKey5, "Fpath", Hist.NoFullPath, DefaultHist.NoFullPath);\r
476                                                         WriteBinaryToReg(hKey5, "Sort", &Hist.Sort, sizeof(Hist.Sort));\r
477                                                         SaveIntNum(hKey5, "Secu", Hist.Security, DefaultHist.Security);\r
478                                                         WriteIntValueToReg(hKey5, "TrType", Hist.Type);\r
479                                                         SaveIntNum(hKey5, "Dial", Hist.Dialup, DefaultHist.Dialup);\r
480                                                         SaveIntNum(hKey5, "UseIt", Hist.DialupAlways, DefaultHist.DialupAlways);\r
481                                                         SaveIntNum(hKey5, "Notify", Hist.DialupNotify, DefaultHist.DialupNotify);\r
482                                                         SaveStr(hKey5, "DialTo", Hist.DialEntry, DefaultHist.DialEntry);\r
483                                                         // 暗号化通信対応\r
484                                                         SaveIntNum(hKey5, "NoEncryption", Hist.UseNoEncryption, DefaultHist.UseNoEncryption);\r
485                                                         SaveIntNum(hKey5, "FTPES", Hist.UseFTPES, DefaultHist.UseFTPES);\r
486                                                         SaveIntNum(hKey5, "FTPIS", Hist.UseFTPIS, DefaultHist.UseFTPIS);\r
487                                                         SaveIntNum(hKey5, "SFTP", Hist.UseSFTP, DefaultHist.UseSFTP);\r
488                                                         EncodePassword(Hist.PrivateKey, Str);\r
489                                                         SaveStr(hKey5, "PKey", Str, DefaultHist.PrivateKey);\r
490                                                         // 同時接続対応\r
491                                                         SaveIntNum(hKey5, "ThreadCount", Hist.MaxThreadCount, DefaultHist.MaxThreadCount);\r
492                                                         SaveIntNum(hKey5, "ReuseCmdSkt", Hist.ReuseCmdSkt, DefaultHist.ReuseCmdSkt);\r
493                                                         // MLSD対応\r
494                                                         SaveIntNum(hKey5, "MLSD", Hist.UseMLSD, DefaultHist.UseMLSD);\r
495                                                         // IPv6対応\r
496                                                         SaveIntNum(hKey5, "NetType", Hist.NetType, DefaultHist.NetType);\r
497                                                         // 自動切断対策\r
498                                                         SaveIntNum(hKey5, "Noop", Hist.NoopInterval, DefaultHist.NoopInterval);\r
499                                                         // 再転送対応\r
500                                                         SaveIntNum(hKey5, "ErrMode", Hist.TransferErrorMode, DefaultHist.TransferErrorMode);\r
501                                                         SaveIntNum(hKey5, "ErrNotify", Hist.TransferErrorNotify, DefaultHist.TransferErrorNotify);\r
502 \r
503                                                         CloseSubKey(hKey5);\r
504                                                         n++;\r
505                                                 }\r
506                                         }\r
507                                 }\r
508                                 WriteIntValueToReg(hKey4, "SavedHist", n);\r
509 \r
510                                 /* 余分なヒストリがあったら削除 */\r
511                                 for(; n < 999; n++)\r
512                                 {\r
513                                         sprintf(Str, "History%d", n);\r
514                                         if(DeleteSubKey(hKey4, Str) != FFFTP_SUCCESS)\r
515                                                 break;\r
516                                 }\r
517 \r
518                                 /* ホストの設定を保存 */\r
519                                 CopyDefaultHost(&DefaultHost);\r
520                                 i = 0;\r
521                                 while(CopyHostFromList(i, &Host) == FFFTP_SUCCESS)\r
522                                 {\r
523                                         sprintf(Str, "Host%d", i);\r
524                                         if(CreateSubKey(hKey4, Str, &hKey5) == FFFTP_SUCCESS)\r
525                                         {\r
526 //                                              SaveIntNum(hKey5, "Set", Host.Level, DefaultHost.Level);\r
527                                                 WriteIntValueToReg(hKey5, "Set", Host.Level);\r
528                                                 SaveStr(hKey5, "HostName", Host.HostName, DefaultHost.HostName);\r
529                                                 if((Host.Level & SET_LEVEL_GROUP) == 0)\r
530                                                 {\r
531                                                         SaveStr(hKey5, "HostAdrs", Host.HostAdrs, DefaultHost.HostAdrs);\r
532                                                         SaveStr(hKey5, "UserName", Host.UserName, DefaultHost.UserName);\r
533                                                         SaveStr(hKey5, "Account", Host.Account, DefaultHost.Account);\r
534                                                         SaveStr(hKey5, "LocalDir", Host.LocalInitDir, NULL);\r
535                                                         SaveStr(hKey5, "RemoteDir", Host.RemoteInitDir, DefaultHost.RemoteInitDir);\r
536                                                         SaveStr(hKey5, "Chmod", Host.ChmodCmd, DefaultHost.ChmodCmd);\r
537                                                         SaveStr(hKey5, "Nlst", Host.LsName, DefaultHost.LsName);\r
538                                                         SaveStr(hKey5, "Init", Host.InitCmd, DefaultHost.InitCmd);\r
539 \r
540                                                         if(Host.Anonymous == NO)\r
541                                                                 EncodePassword(Host.PassWord, Str);\r
542                                                         else\r
543                                                                 strcpy(Str, DefaultHost.PassWord);\r
544                                                         SaveStr(hKey5, "Password", Str, DefaultHost.PassWord);\r
545 \r
546                                                         SaveIntNum(hKey5, "Port", Host.Port, DefaultHost.Port);\r
547                                                         SaveIntNum(hKey5, "Anonymous", Host.Anonymous, DefaultHost.Anonymous);\r
548                                                         SaveIntNum(hKey5, "Kanji", Host.KanjiCode, DefaultHost.KanjiCode);\r
549                                                         SaveIntNum(hKey5, "KanaCnv", Host.KanaCnv, DefaultHost.KanaCnv);\r
550                                                         SaveIntNum(hKey5, "NameKanji", Host.NameKanjiCode, DefaultHost.NameKanjiCode);\r
551                                                         SaveIntNum(hKey5, "NameKana", Host.NameKanaCnv, DefaultHost.NameKanaCnv);\r
552                                                         SaveIntNum(hKey5, "Pasv", Host.Pasv, DefaultHost.Pasv);\r
553                                                         SaveIntNum(hKey5, "Fwall", Host.FireWall, DefaultHost.FireWall);\r
554                                                         SaveIntNum(hKey5, "List", Host.ListCmdOnly, DefaultHost.ListCmdOnly);\r
555                                                         SaveIntNum(hKey5, "NLST-R", Host.UseNLST_R, DefaultHost.UseNLST_R);\r
556                                                         SaveIntNum(hKey5, "Last", Host.LastDir, DefaultHost.LastDir);\r
557                                                         SaveIntNum(hKey5, "Tzone", Host.TimeZone, DefaultHost.TimeZone);\r
558                                                         SaveIntNum(hKey5, "Type", Host.HostType, DefaultHost.HostType);\r
559                                                         SaveIntNum(hKey5, "Sync", Host.SyncMove, DefaultHost.SyncMove);\r
560                                                         SaveIntNum(hKey5, "Fpath", Host.NoFullPath, DefaultHost.NoFullPath);\r
561                                                         WriteBinaryToReg(hKey5, "Sort", &Host.Sort, sizeof(Host.Sort));\r
562                                                         SaveIntNum(hKey5, "Secu", Host.Security, DefaultHost.Security);\r
563 \r
564                                                         WriteMultiStringToReg(hKey5, "Bmarks", Host.BookMark);\r
565 \r
566                                                         SaveIntNum(hKey5, "Dial", Host.Dialup, DefaultHost.Dialup);\r
567                                                         SaveIntNum(hKey5, "UseIt", Host.DialupAlways, DefaultHost.DialupAlways);\r
568                                                         SaveIntNum(hKey5, "Notify", Host.DialupNotify, DefaultHost.DialupNotify);\r
569                                                         SaveStr(hKey5, "DialTo", Host.DialEntry, DefaultHost.DialEntry);\r
570                                                         // 暗号化通信対応\r
571                                                         SaveIntNum(hKey5, "NoEncryption", Host.UseNoEncryption, DefaultHost.UseNoEncryption);\r
572                                                         SaveIntNum(hKey5, "FTPES", Host.UseFTPES, DefaultHost.UseFTPES);\r
573                                                         SaveIntNum(hKey5, "FTPIS", Host.UseFTPIS, DefaultHost.UseFTPIS);\r
574                                                         SaveIntNum(hKey5, "SFTP", Host.UseSFTP, DefaultHost.UseSFTP);\r
575                                                         EncodePassword(Host.PrivateKey, Str);\r
576                                                         SaveStr(hKey5, "PKey", Str, DefaultHost.PrivateKey);\r
577                                                         // 同時接続対応\r
578                                                         SaveIntNum(hKey5, "ThreadCount", Host.MaxThreadCount, DefaultHost.MaxThreadCount);\r
579                                                         SaveIntNum(hKey5, "ReuseCmdSkt", Host.ReuseCmdSkt, DefaultHost.ReuseCmdSkt);\r
580                                                         // MLSD対応\r
581                                                         SaveIntNum(hKey5, "MLSD", Host.UseMLSD, DefaultHost.UseMLSD);\r
582                                                         // IPv6対応\r
583                                                         SaveIntNum(hKey5, "NetType", Host.NetType, DefaultHost.NetType);\r
584                                                         // 自動切断対策\r
585                                                         SaveIntNum(hKey5, "Noop", Host.NoopInterval, DefaultHost.NoopInterval);\r
586                                                         // 再転送対応\r
587                                                         SaveIntNum(hKey5, "ErrMode", Host.TransferErrorMode, DefaultHost.TransferErrorMode);\r
588                                                         SaveIntNum(hKey5, "ErrNotify", Host.TransferErrorNotify, DefaultHost.TransferErrorNotify);\r
589                                                 }\r
590                                                 CloseSubKey(hKey5);\r
591                                         }\r
592                                         i++;\r
593                                 }\r
594                                 WriteIntValueToReg(hKey4, "SetNum", i);\r
595 \r
596                                 /* 余分なホストの設定があったら削除 */\r
597                                 for(; i < 998; i++)\r
598                                 {\r
599                                         sprintf(Str, "Host%d", i);\r
600                                         if(DeleteSubKey(hKey4, Str) != FFFTP_SUCCESS)\r
601                                                 break;\r
602                                 }\r
603 \r
604                                 if((i = AskCurrentHost()) == HOSTNUM_NOENTRY)\r
605                                         i = 0;\r
606                                 WriteIntValueToReg(hKey4, "CurSet", i);\r
607 \r
608                                 // 暗号化通信対応\r
609                                 WriteBinaryToReg(hKey4, "CertCacheHash", &CertificateCacheHash, sizeof(CertificateCacheHash));\r
610                                 strcpy(Buf, "");\r
611                                 StrCatOut((char*)&SSLRootCAFileHash, sizeof(SSLRootCAFileHash), Buf);\r
612                                 EncodePassword(Buf, Str);\r
613                                 WriteStringToReg(hKey4, "RootCertHash", Str);\r
614                         }\r
615                         CloseSubKey(hKey4);\r
616                 }\r
617                 CloseReg(hKey3);\r
618         }\r
619         return;\r
620 }\r
621 \r
622 /*----- レジストリ/INIファイルから設定値を呼び出す ---------------------------\r
623 *\r
624 *       この関数を複数回呼び出すと,ホスト設定が追加される.\r
625 *\r
626 *       Parameter\r
627 *               なし\r
628 *\r
629 *       Return Value\r
630 *               YES: 読み出し成功\r
631 *               NO:  読み出し失敗(設定無し)\r
632 *----------------------------------------------------------------------------*/\r
633 \r
634 int LoadRegistory(void)\r
635 {\r
636         void *hKey3;\r
637         void *hKey4;\r
638         void *hKey5;\r
639         int i;\r
640         int Sets;\r
641         // 暗号化通信対応\r
642 //      char Str[256];  /* ASCII_EXT_LENより大きい事 */\r
643         char Str[PRIVATE_KEY_LEN*4+1];\r
644         char Buf[FMAX_PATH+1];\r
645         char *Pos;\r
646         char *Pos2;\r
647         HOSTDATA Host;\r
648         HISTORYDATA Hist;\r
649         int Sts;\r
650         int Version;\r
651 \r
652         Sts = NO;\r
653 \r
654         SetRegType(REGTYPE_INI);\r
655         if((i = OpenReg("FFFTP", &hKey3)) != FFFTP_SUCCESS)\r
656         {\r
657                 if(AskForceIni() == NO)\r
658                 {\r
659                         SetRegType(REGTYPE_REG);\r
660                         i = OpenReg("FFFTP", &hKey3);\r
661                 }\r
662         }\r
663 \r
664         if(i == FFFTP_SUCCESS)\r
665         {\r
666 //              char checkbuf[48];\r
667                 int salt = 0;\r
668                 Sts = YES;\r
669 \r
670                 ReadIntValueFromReg(hKey3, "Version", &Version);\r
671                 // UTF-8対応\r
672                 if(Version < 1980)\r
673                         IniKanjiCode = KANJI_SJIS;\r
674 \r
675                 if(OpenSubKey(hKey3, "Options", &hKey4) == FFFTP_SUCCESS)\r
676                 {\r
677                         ReadIntValueFromReg(hKey4, "WinPosX", &WinPosX);\r
678                         ReadIntValueFromReg(hKey4, "WinPosY", &WinPosY);\r
679                         ReadIntValueFromReg(hKey4, "WinWidth", &WinWidth);\r
680                         ReadIntValueFromReg(hKey4, "WinHeight", &WinHeight);\r
681                         ReadIntValueFromReg(hKey4, "LocalWidth", &LocalWidth);\r
682                         /* ↓旧バージョンのバグ対策 */\r
683                         LocalWidth = max1(0, LocalWidth);\r
684                         ReadIntValueFromReg(hKey4, "TaskHeight", &TaskHeight);\r
685                         /* ↓旧バージョンのバグ対策 */\r
686                         TaskHeight = max1(0, TaskHeight);\r
687                         ReadBinaryFromReg(hKey4, "LocalColm", &LocalTabWidth, sizeof(LocalTabWidth));\r
688                         ReadBinaryFromReg(hKey4, "RemoteColm", &RemoteTabWidth, sizeof(RemoteTabWidth));\r
689                         ReadIntValueFromReg(hKey4, "SwCmd", &Sizing);\r
690 \r
691                         ReadStringFromReg(hKey4, "UserMail", UserMailAdrs, USER_MAIL_LEN+1);\r
692                         ReadStringFromReg(hKey4, "Viewer", ViewerName[0], FMAX_PATH+1);\r
693                         ReadStringFromReg(hKey4, "Viewer2", ViewerName[1], FMAX_PATH+1);\r
694                         ReadStringFromReg(hKey4, "Viewer3", ViewerName[2], FMAX_PATH+1);\r
695 \r
696                         ReadIntValueFromReg(hKey4, "TrType", &TransMode);\r
697                         ReadIntValueFromReg(hKey4, "Recv", &RecvMode);\r
698                         ReadIntValueFromReg(hKey4, "Send", &SendMode);\r
699                         ReadIntValueFromReg(hKey4, "Move", &MoveMode);\r
700                         ReadStringFromReg(hKey4, "Path", DefaultLocalPath, FMAX_PATH+1);\r
701                         ReadIntValueFromReg(hKey4, "Time", &SaveTimeStamp);\r
702                         ReadIntValueFromReg(hKey4, "EOF", &RmEOF);\r
703                         ReadIntValueFromReg(hKey4, "Scolon", &VaxSemicolon);\r
704 \r
705                         ReadIntValueFromReg(hKey4, "RecvEx", &ExistMode);\r
706                         ReadIntValueFromReg(hKey4, "SendEx", &UpExistMode);\r
707 \r
708                         ReadIntValueFromReg(hKey4, "LFsort", &LocalFileSort);\r
709                         ReadIntValueFromReg(hKey4, "LDsort", &LocalDirSort);\r
710                         ReadIntValueFromReg(hKey4, "RFsort", &RemoteFileSort);\r
711                         ReadIntValueFromReg(hKey4, "RDsort", &RemoteDirSort);\r
712                         ReadIntValueFromReg(hKey4, "SortSave", &SortSave);\r
713 \r
714                         ReadIntValueFromReg(hKey4, "ListType", &ListType);\r
715                         ReadIntValueFromReg(hKey4, "Cache", &CacheEntry);\r
716                         ReadIntValueFromReg(hKey4, "CacheSave", &CacheSave);\r
717                         ReadIntValueFromReg(hKey4, "DotFile", &DotFile);\r
718                         ReadIntValueFromReg(hKey4, "Dclick", &DclickOpen);\r
719 \r
720                         ReadIntValueFromReg(hKey4, "ConS", &ConnectOnStart);\r
721                         ReadIntValueFromReg(hKey4, "OldDlg", &ConnectAndSet);\r
722                         ReadIntValueFromReg(hKey4, "RasClose", &RasClose);\r
723                         ReadIntValueFromReg(hKey4, "RasNotify", &RasCloseNotify);\r
724                         ReadIntValueFromReg(hKey4, "Qanony", &QuickAnonymous);\r
725                         ReadIntValueFromReg(hKey4, "PassHist", &PassToHist);\r
726                         ReadIntValueFromReg(hKey4, "SendQuit", &SendQuit);\r
727                         ReadIntValueFromReg(hKey4, "NoRas", &NoRasControl);\r
728 \r
729                         ReadIntValueFromReg(hKey4, "Debug", &DebugConsole);\r
730                         ReadIntValueFromReg(hKey4, "WinPos", &SaveWinPos);\r
731                         ReadIntValueFromReg(hKey4, "RegExp", &FindMode);\r
732                         ReadIntValueFromReg(hKey4, "Reg", &RegType);\r
733 \r
734                         if(ReadMultiStringFromReg(hKey4, "AsciiFile", AsciiExt, ASCII_EXT_LEN+1) == FFFTP_FAIL)\r
735                         {\r
736                                 /* 旧ASCIIモードの拡張子の設定を新しいものに変換 */\r
737                                 ReadStringFromReg(hKey4, "Ascii", Str, ASCII_EXT_LEN+1);\r
738                                 memset(AsciiExt, NUL, ASCII_EXT_LEN+1);\r
739                                 Pos = Str;\r
740                                 while(*Pos != NUL)\r
741                                 {\r
742                                         if((Pos2 = strchr(Pos, ';')) == NULL)\r
743                                                 Pos2 = strchr(Pos, NUL);\r
744                                         if((Pos2 - Pos) > 0)\r
745                                         {\r
746                                                 if((StrMultiLen(AsciiExt) + (Pos2 - Pos) + 2) >= ASCII_EXT_LEN)\r
747                                                         break;\r
748                                                 strcpy(AsciiExt + StrMultiLen(AsciiExt), "*.");\r
749                                                 strncpy(AsciiExt + StrMultiLen(AsciiExt) - 1, Pos, (Pos2 - Pos));\r
750                                         }\r
751                                         Pos = Pos2;\r
752                                         if(*Pos == ';')\r
753                                                 Pos++;\r
754                                 }\r
755                         }\r
756 \r
757                         ReadIntValueFromReg(hKey4, "LowUp", &FnameCnv);\r
758                         ReadIntValueFromReg(hKey4, "Tout", &TimeOut);\r
759 \r
760                         ReadMultiStringFromReg(hKey4, "NoTrn", MirrorNoTrn, MIRROR_LEN+1);\r
761                         ReadMultiStringFromReg(hKey4, "NoDel", MirrorNoDel, MIRROR_LEN+1);\r
762                         ReadIntValueFromReg(hKey4, "MirFile", &MirrorFnameCnv);\r
763                         ReadIntValueFromReg(hKey4, "MirUNot", &MirUpDelNotify);\r
764                         ReadIntValueFromReg(hKey4, "MirDNot", &MirDownDelNotify);\r
765 \r
766                         if(ReadStringFromReg(hKey4, "ListFont", Str, 256) == FFFTP_SUCCESS)\r
767                         {\r
768                                 if(RestoreFontData(Str, &ListLogFont) == FFFTP_SUCCESS)\r
769                                         ListFont = CreateFontIndirect(&ListLogFont);\r
770                         }\r
771                         ReadIntValueFromReg(hKey4, "ListHide", &DispIgnoreHide);\r
772                         ReadIntValueFromReg(hKey4, "ListDrv", &DispDrives);\r
773 \r
774                         ReadStringFromReg(hKey4, "FwallHost", FwallHost, HOST_ADRS_LEN+1);\r
775                         ReadStringFromReg(hKey4, "FwallUser", FwallUser, USER_NAME_LEN+1);\r
776                         ReadStringFromReg(hKey4, "FwallPass", Str, 255);\r
777                         DecodePassword(Str, FwallPass);\r
778                         ReadIntValueFromReg(hKey4, "FwallPort", &FwallPort);\r
779                         ReadIntValueFromReg(hKey4, "FwallType", &FwallType);\r
780                         ReadIntValueFromReg(hKey4, "FwallDef", &FwallDefault);\r
781                         ReadIntValueFromReg(hKey4, "FwallSec", &FwallSecurity);\r
782                         ReadIntValueFromReg(hKey4, "PasvDef", &PasvDefault);\r
783                         ReadIntValueFromReg(hKey4, "FwallRes", &FwallResolv);\r
784                         ReadIntValueFromReg(hKey4, "FwallLow", &FwallLower);\r
785                         ReadIntValueFromReg(hKey4, "FwallDel", &FwallDelimiter);\r
786 \r
787                         ReadIntValueFromReg(hKey4, "SndConSw", &Sound[SND_CONNECT].On);\r
788                         ReadIntValueFromReg(hKey4, "SndTrnSw", &Sound[SND_TRANS].On);\r
789                         ReadIntValueFromReg(hKey4, "SndErrSw", &Sound[SND_ERROR].On);\r
790                         ReadStringFromReg(hKey4, "SndCon", Sound[SND_CONNECT].Fname, FMAX_PATH+1);\r
791                         ReadStringFromReg(hKey4, "SndTrn", Sound[SND_TRANS].Fname, FMAX_PATH+1);\r
792                         ReadStringFromReg(hKey4, "SndErr", Sound[SND_ERROR].Fname, FMAX_PATH+1);\r
793 \r
794                         ReadMultiStringFromReg(hKey4, "DefAttr", DefAttrList, DEFATTRLIST_LEN+1);\r
795 \r
796                         ReadStringFromReg(hKey4, "Tmp", TmpPath, FMAX_PATH+1);\r
797 \r
798                         ReadBinaryFromReg(hKey4, "Hdlg", &HostDlgSize, sizeof(SIZE));\r
799                         ReadBinaryFromReg(hKey4, "Bdlg", &BmarkDlgSize, sizeof(SIZE));\r
800                         ReadBinaryFromReg(hKey4, "Mdlg", &MirrorDlgSize, sizeof(SIZE));\r
801 \r
802                         ReadIntValueFromReg(hKey4, "FAttrSw", &FolderAttr);\r
803                         ReadIntValueFromReg(hKey4, "FAttr", &FolderAttrNum);\r
804 \r
805                         ReadIntValueFromReg(hKey4, "NoSave", &SuppressSave);\r
806 \r
807                         ReadIntValueFromReg(hKey4, "HistNum", &FileHist);\r
808 //                      ReadMultiStringFromReg(hKey4, "Hist", Hist, (FMAX_PATH+1)*HISTORY_MAX+1);\r
809 \r
810                         /* ヒストリの設定を読み込む */\r
811                         Sets = 0;\r
812                         ReadIntValueFromReg(hKey4, "SavedHist", &Sets);\r
813 \r
814                         for(i = 0; i < Sets; i++)\r
815                         {\r
816                                 sprintf(Str, "History%d", i);\r
817                                 if(OpenSubKey(hKey4, Str, &hKey5) == FFFTP_SUCCESS)\r
818                                 {\r
819                                         CopyDefaultHistory(&Hist);\r
820 \r
821                                         ReadStringFromReg(hKey5, "HostAdrs", Hist.HostAdrs, HOST_ADRS_LEN+1);\r
822                                         ReadStringFromReg(hKey5, "UserName", Hist.UserName, USER_NAME_LEN+1);\r
823                                         ReadStringFromReg(hKey5, "Account", Hist.Account, ACCOUNT_LEN+1);\r
824                                         ReadStringFromReg(hKey5, "LocalDir", Hist.LocalInitDir, INIT_DIR_LEN+1);\r
825                                         ReadStringFromReg(hKey5, "RemoteDir", Hist.RemoteInitDir, INIT_DIR_LEN+1);\r
826                                         ReadStringFromReg(hKey5, "Chmod", Hist.ChmodCmd, CHMOD_CMD_LEN+1);\r
827                                         ReadStringFromReg(hKey5, "Nlst", Hist.LsName, NLST_NAME_LEN+1);\r
828                                         ReadStringFromReg(hKey5, "Init", Hist.InitCmd, INITCMD_LEN+1);\r
829                                         ReadIntValueFromReg(hKey5, "Port", &Hist.Port);\r
830                                         ReadIntValueFromReg(hKey5, "Kanji", &Hist.KanjiCode);\r
831                                         ReadIntValueFromReg(hKey5, "KanaCnv", &Hist.KanaCnv);\r
832                                         ReadIntValueFromReg(hKey5, "NameKanji", &Hist.NameKanjiCode);\r
833                                         ReadIntValueFromReg(hKey5, "NameKana", &Hist.NameKanaCnv);\r
834                                         ReadIntValueFromReg(hKey5, "Pasv", &Hist.Pasv);\r
835                                         ReadIntValueFromReg(hKey5, "Fwall", &Hist.FireWall);\r
836                                         ReadIntValueFromReg(hKey5, "List", &Hist.ListCmdOnly);\r
837                                         ReadIntValueFromReg(hKey5, "NLST-R", &Hist.UseNLST_R);\r
838                                         ReadIntValueFromReg(hKey5, "Tzone", &Hist.TimeZone);\r
839                                         ReadIntValueFromReg(hKey5, "Type", &Hist.HostType);\r
840                                         ReadIntValueFromReg(hKey5, "Sync", &Hist.SyncMove);\r
841                                         ReadIntValueFromReg(hKey5, "Fpath", &Hist.NoFullPath);\r
842                                         ReadBinaryFromReg(hKey5, "Sort", &Hist.Sort, sizeof(Hist.Sort));\r
843                                         ReadIntValueFromReg(hKey5, "Secu", &Hist.Security);\r
844                                         ReadIntValueFromReg(hKey5, "TrType", &Hist.Type);\r
845                                         strcpy(Str, "");\r
846                                         ReadStringFromReg(hKey5, "Password", Str, 255);\r
847                                         DecodePassword(Str, Hist.PassWord);\r
848                                         ReadIntValueFromReg(hKey5, "Dial", &Hist.Dialup);\r
849                                         ReadIntValueFromReg(hKey5, "UseIt", &Hist.DialupAlways);\r
850                                         ReadIntValueFromReg(hKey5, "Notify", &Hist.DialupNotify);\r
851                                         ReadStringFromReg(hKey5, "DialTo", Hist.DialEntry, RAS_NAME_LEN+1);\r
852                                         // 暗号化通信対応\r
853                                         ReadIntValueFromReg(hKey5, "NoEncryption", &Hist.UseNoEncryption);\r
854                                         ReadIntValueFromReg(hKey5, "FTPES", &Hist.UseFTPES);\r
855                                         ReadIntValueFromReg(hKey5, "FTPIS", &Hist.UseFTPIS);\r
856                                         ReadIntValueFromReg(hKey5, "SFTP", &Hist.UseSFTP);\r
857                                         strcpy(Str, "");\r
858                                         ReadStringFromReg(hKey5, "PKey", Str, PRIVATE_KEY_LEN*4+1);\r
859                                         DecodePassword(Str, Hist.PrivateKey);\r
860                                         // 同時接続対応\r
861                                         ReadIntValueFromReg(hKey5, "ThreadCount", &Hist.MaxThreadCount);\r
862                                         ReadIntValueFromReg(hKey5, "ReuseCmdSkt", &Hist.ReuseCmdSkt);\r
863                                         // MLSD対応\r
864                                         ReadIntValueFromReg(hKey5, "MLSD", &Hist.UseMLSD);\r
865                                         // IPv6対応\r
866                                         ReadIntValueFromReg(hKey5, "NetType", &Hist.NetType);\r
867                                         // 自動切断対策\r
868                                         ReadIntValueFromReg(hKey5, "Noop", &Hist.NoopInterval);\r
869                                         // 再転送対応\r
870                                         ReadIntValueFromReg(hKey5, "ErrMode", &Hist.TransferErrorMode);\r
871                                         ReadIntValueFromReg(hKey5, "ErrNotify", &Hist.TransferErrorNotify);\r
872 \r
873                                         CloseSubKey(hKey5);\r
874                                         AddHistoryToHistory(&Hist);\r
875                                 }\r
876                         }\r
877 \r
878                         /* ホストの設定を読み込む */\r
879                         Sets = 0;\r
880                         ReadIntValueFromReg(hKey4, "SetNum", &Sets);\r
881 \r
882                         for(i = 0; i < Sets; i++)\r
883                         {\r
884                                 sprintf(Str, "Host%d", i);\r
885                                 if(OpenSubKey(hKey4, Str, &hKey5) == FFFTP_SUCCESS)\r
886                                 {\r
887                                         CopyDefaultHost(&Host);\r
888                                         /* 下位互換性のため */\r
889                                         // SourceForge.JPによるフォーク\r
890 //                                      if(Version < VER_NUM)\r
891                                         if(Version < 1921)\r
892                                         {\r
893                                                 Host.Pasv = NO;\r
894                                                 Host.ListCmdOnly = NO;\r
895                                         }\r
896                                         // 1.97b以前はデフォルトでShift_JIS\r
897                                         if(Version < 1980)\r
898                                                 Host.NameKanjiCode = KANJI_SJIS;\r
899                                         ReadIntValueFromReg(hKey5, "Set", &Host.Level);\r
900 \r
901                                         ReadStringFromReg(hKey5, "HostName", Host.HostName, HOST_NAME_LEN+1);\r
902                                         ReadStringFromReg(hKey5, "HostAdrs", Host.HostAdrs, HOST_ADRS_LEN+1);\r
903                                         ReadStringFromReg(hKey5, "UserName", Host.UserName, USER_NAME_LEN+1);\r
904                                         ReadStringFromReg(hKey5, "Account", Host.Account, ACCOUNT_LEN+1);\r
905                                         ReadStringFromReg(hKey5, "LocalDir", Host.LocalInitDir, INIT_DIR_LEN+1);\r
906                                         ReadStringFromReg(hKey5, "RemoteDir", Host.RemoteInitDir, INIT_DIR_LEN+1);\r
907                                         ReadStringFromReg(hKey5, "Chmod", Host.ChmodCmd, CHMOD_CMD_LEN+1);\r
908                                         ReadStringFromReg(hKey5, "Nlst", Host.LsName, NLST_NAME_LEN+1);\r
909                                         ReadStringFromReg(hKey5, "Init", Host.InitCmd, INITCMD_LEN+1);\r
910                                         ReadIntValueFromReg(hKey5, "Port", &Host.Port);\r
911                                         ReadIntValueFromReg(hKey5, "Anonymous", &Host.Anonymous);\r
912                                         ReadIntValueFromReg(hKey5, "Kanji", &Host.KanjiCode);\r
913                                         // 1.98b以前のUTF-8はBOMあり\r
914                                         if(Version < 1983)\r
915                                         {\r
916                                                 if(Host.KanjiCode == KANJI_UTF8N)\r
917                                                         Host.KanjiCode = KANJI_UTF8BOM;\r
918                                         }\r
919                                         ReadIntValueFromReg(hKey5, "KanaCnv", &Host.KanaCnv);\r
920                                         ReadIntValueFromReg(hKey5, "NameKanji", &Host.NameKanjiCode);\r
921                                         ReadIntValueFromReg(hKey5, "NameKana", &Host.NameKanaCnv);\r
922                                         ReadIntValueFromReg(hKey5, "Pasv", &Host.Pasv);\r
923                                         ReadIntValueFromReg(hKey5, "Fwall", &Host.FireWall);\r
924                                         ReadIntValueFromReg(hKey5, "List", &Host.ListCmdOnly);\r
925                                         ReadIntValueFromReg(hKey5, "NLST-R", &Host.UseNLST_R);\r
926                                         ReadIntValueFromReg(hKey5, "Last", &Host.LastDir);\r
927                                         ReadIntValueFromReg(hKey5, "Tzone", &Host.TimeZone);\r
928                                         ReadIntValueFromReg(hKey5, "Type", &Host.HostType);\r
929                                         ReadIntValueFromReg(hKey5, "Sync", &Host.SyncMove);\r
930                                         ReadIntValueFromReg(hKey5, "Fpath", &Host.NoFullPath);\r
931                                         ReadBinaryFromReg(hKey5, "Sort", &Host.Sort, sizeof(Host.Sort));\r
932                                         ReadIntValueFromReg(hKey5, "Secu", &Host.Security);\r
933                                         if(Host.Anonymous != YES)\r
934                                         {\r
935                                                 strcpy(Str, "");\r
936                                                 ReadStringFromReg(hKey5, "Password", Str, 255);\r
937                                                 DecodePassword(Str, Host.PassWord);\r
938                                         }\r
939                                         else\r
940                                                 strcpy(Host.PassWord, UserMailAdrs);\r
941 \r
942                                         ReadMultiStringFromReg(hKey5, "Bmarks", Host.BookMark, BOOKMARK_SIZE);\r
943 \r
944                                         ReadIntValueFromReg(hKey5, "Dial", &Host.Dialup);\r
945                                         ReadIntValueFromReg(hKey5, "UseIt", &Host.DialupAlways);\r
946                                         ReadIntValueFromReg(hKey5, "Notify", &Host.DialupNotify);\r
947                                         ReadStringFromReg(hKey5, "DialTo", Host.DialEntry, RAS_NAME_LEN+1);\r
948                                         // 暗号化通信対応\r
949                                         ReadIntValueFromReg(hKey5, "NoEncryption", &Host.UseNoEncryption);\r
950                                         ReadIntValueFromReg(hKey5, "FTPES", &Host.UseFTPES);\r
951                                         ReadIntValueFromReg(hKey5, "FTPIS", &Host.UseFTPIS);\r
952                                         ReadIntValueFromReg(hKey5, "SFTP", &Host.UseSFTP);\r
953                                         strcpy(Str, "");\r
954                                         ReadStringFromReg(hKey5, "PKey", Str, PRIVATE_KEY_LEN*4+1);\r
955                                         DecodePassword(Str, Host.PrivateKey);\r
956                                         // 同時接続対応\r
957                                         ReadIntValueFromReg(hKey5, "ThreadCount", &Host.MaxThreadCount);\r
958                                         ReadIntValueFromReg(hKey5, "ReuseCmdSkt", &Host.ReuseCmdSkt);\r
959                                         // MLSD対応\r
960                                         ReadIntValueFromReg(hKey5, "MLSD", &Host.UseMLSD);\r
961                                         // IPv6対応\r
962                                         ReadIntValueFromReg(hKey5, "NetType", &Host.NetType);\r
963                                         // 自動切断対策\r
964                                         ReadIntValueFromReg(hKey5, "Noop", &Host.NoopInterval);\r
965                                         // 再転送対応\r
966                                         ReadIntValueFromReg(hKey5, "ErrMode", &Host.TransferErrorMode);\r
967                                         ReadIntValueFromReg(hKey5, "ErrNotify", &Host.TransferErrorNotify);\r
968 \r
969                                         CloseSubKey(hKey5);\r
970 \r
971                                         AddHostToList(&Host, -1, Host.Level);\r
972                                 }\r
973                         }\r
974 \r
975                         ReadIntValueFromReg(hKey4, "CurSet", &Sets);\r
976                         SetCurrentHost(Sets);\r
977 \r
978                         // 暗号化通信対応\r
979                         ReadBinaryFromReg(hKey4, "CertCacheHash", &CertificateCacheHash, sizeof(CertificateCacheHash));\r
980                         ReadStringFromReg(hKey4, "RootCertHash", Str, PRIVATE_KEY_LEN*4+1);\r
981                         DecodePassword(Str, Buf);\r
982                         StrReadIn(Buf, sizeof(SSLRootCAFileHash), (char*)&SSLRootCAFileHash);\r
983 \r
984                         CloseSubKey(hKey4);\r
985                 }\r
986                 CloseReg(hKey3);\r
987         }\r
988         else\r
989         {\r
990                 /*===== 最初の起動時(設定が無い) =====*/\r
991 \r
992 #if 0\r
993                 strcpy(UserMailAdrs, "");\r
994                 strcpy(Str, "");\r
995                 if(InputDialogBox(mailadrs_dlg, HWND_DESKTOP, NULL, Str, USER_MAIL_LEN+1, &i, IDH_HELP_TOPIC_0000001) == YES)\r
996                         strcpy(UserMailAdrs, Str);\r
997 \r
998                 for(i = 0; i < SAMPLE_HOSTS; i++)\r
999                 {\r
1000                         CopyDefaultHost(&Host);\r
1001                         Host.Level = Sample[i].Level;\r
1002                         strcpy(Host.PassWord, UserMailAdrs);\r
1003                         strcpy(Host.HostName, Sample[i].HostName);\r
1004                         strcpy(Host.HostAdrs, Sample[i].HostAdrs);\r
1005                         strcpy(Host.UserName, "anonymous");\r
1006                         AddHostToList(&Host, -1, Host.Level);\r
1007                 }\r
1008 #endif\r
1009         }\r
1010         return(Sts);\r
1011 }\r
1012 \r
1013 \r
1014 /*----- 隠しドライブ情報を取得 ------------------------------------------------\r
1015 *\r
1016 *       Parameter\r
1017 *               なし\r
1018 *\r
1019 *       Return Value\r
1020 *               DWORD \r
1021 *                       YES/NO=設定無し\r
1022 *----------------------------------------------------------------------------*/\r
1023 \r
1024 DWORD LoadHideDriveListRegistory(void)\r
1025 {\r
1026         HKEY hKey1;\r
1027         HKEY hKey2;\r
1028         HKEY hKey3;\r
1029         HKEY hKey4;\r
1030         HKEY hKey5;\r
1031         HKEY hKey6;\r
1032         DWORD Size;\r
1033         DWORD Type;\r
1034         DWORD Ret;\r
1035 \r
1036         Ret = 0;\r
1037         if(RegOpenKeyEx(HKEY_CURRENT_USER, "Software", 0, KEY_READ, &hKey1) == ERROR_SUCCESS)\r
1038         {\r
1039                 if(RegOpenKeyEx(hKey1, "Microsoft", 0, KEY_READ, &hKey2) == ERROR_SUCCESS)\r
1040                 {\r
1041                         if(RegOpenKeyEx(hKey2, "Windows", 0, KEY_READ, &hKey3) == ERROR_SUCCESS)\r
1042                         {\r
1043                                 if(RegOpenKeyEx(hKey3, "CurrentVersion", 0, KEY_READ, &hKey4) == ERROR_SUCCESS)\r
1044                                 {\r
1045                                         if(RegOpenKeyEx(hKey4, "Policies", 0, KEY_READ, &hKey5) == ERROR_SUCCESS)\r
1046                                         {\r
1047                                                 if(RegOpenKeyEx(hKey5, "Explorer", 0, KEY_READ, &hKey6) == ERROR_SUCCESS)\r
1048                                                 {\r
1049                                                         Size = sizeof(DWORD);\r
1050                                                         RegQueryValueEx(hKey6, "NoDrives", NULL, &Type, (BYTE *)&Ret, &Size);\r
1051                                                         RegCloseKey(hKey6);\r
1052                                                 }\r
1053                                                 RegCloseKey(hKey5);\r
1054                                         }\r
1055                                         RegCloseKey(hKey4);\r
1056                                 }\r
1057                                 RegCloseKey(hKey3);\r
1058                         }\r
1059                         RegCloseKey(hKey2);\r
1060                 }\r
1061                 RegCloseKey(hKey1);\r
1062         }\r
1063         return(Ret);\r
1064 }\r
1065 \r
1066 \r
1067 /*----- レジストリの設定値をクリア --------------------------------------------\r
1068 *\r
1069 *       Parameter\r
1070 *               なし\r
1071 *\r
1072 *       Return Value\r
1073 *               なし\r
1074 *----------------------------------------------------------------------------*/\r
1075 \r
1076 void ClearRegistory(void)\r
1077 {\r
1078         HKEY hKey2;\r
1079         HKEY hKey3;\r
1080         HKEY hKey4;\r
1081         DWORD Dispos;\r
1082         char Str[20];\r
1083         int i;\r
1084 \r
1085         if(RegCreateKeyEx(HKEY_CURRENT_USER, "Software\\Sota", 0, "", REG_OPTION_NON_VOLATILE, KEY_CREATE_SUB_KEY, NULL, &hKey2, &Dispos) == ERROR_SUCCESS)\r
1086         {\r
1087                 if(RegCreateKeyEx(hKey2, "FFFTP", 0, "", REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey3, &Dispos) == ERROR_SUCCESS)\r
1088                 {\r
1089                         if(RegCreateKeyEx(hKey3, "Options", 0, "", REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hKey4, &Dispos) == ERROR_SUCCESS)\r
1090                         {\r
1091                                 for(i = 0; ; i++)\r
1092                                 {\r
1093                                         sprintf(Str, "Host%d", i);\r
1094                                         if(RegDeleteKey(hKey4, Str) != ERROR_SUCCESS)\r
1095                                                 break;\r
1096                                 }\r
1097                                 for(i = 0; ; i++)\r
1098                                 {\r
1099                                         sprintf(Str, "History%d", i);\r
1100                                         if(RegDeleteKey(hKey4, Str) != ERROR_SUCCESS)\r
1101                                                 break;\r
1102                                 }\r
1103                                 RegCloseKey(hKey4);\r
1104                         }\r
1105                         RegDeleteKey(hKey3, "Options");\r
1106                         RegCloseKey(hKey3);\r
1107                 }\r
1108                 RegDeleteKey(hKey2, "FFFTP");\r
1109                 RegCloseKey(hKey2);\r
1110         }\r
1111         return;\r
1112 }\r
1113 \r
1114 \r
1115 /*----- 設定をファイルに保存 --------------------------------------------------\r
1116 *\r
1117 *       Parameter\r
1118 *               なし\r
1119 *\r
1120 *       Return Value\r
1121 *               なし\r
1122 *----------------------------------------------------------------------------*/\r
1123 \r
1124 void SaveSettingsToFile(void)\r
1125 {\r
1126         char Tmp[FMAX_PATH*2];\r
1127         char Fname[FMAX_PATH+1];\r
1128         // 任意のコードが実行されるバグ修正\r
1129         char CurDir[FMAX_PATH+1];\r
1130         char SysDir[FMAX_PATH+1];\r
1131 \r
1132         if(RegType == REGTYPE_REG)\r
1133         {\r
1134                 strcpy(Fname, "FFFTP.reg");\r
1135                 if(SelectFile(GetMainHwnd(), Fname, MSGJPN286, MSGJPN287, "reg", OFN_EXTENSIONDIFFERENT | OFN_OVERWRITEPROMPT, 1) == TRUE)\r
1136                 {\r
1137                         sprintf(Tmp, "/e \x22%s\x22 HKEY_CURRENT_USER\\Software\\sota\\FFFTP", Fname);\r
1138                         // 任意のコードが実行されるバグ修正\r
1139 //                      if(ShellExecute(NULL, "open", "regedit", Tmp, ".", SW_SHOW) <= (HINSTANCE)32)\r
1140 //                      {\r
1141 //                              MessageBox(NULL, MSGJPN285, "FFFTP", MB_OK);\r
1142 //                      }\r
1143                         if(GetCurrentDirectory(FMAX_PATH, CurDir) > 0)\r
1144                         {\r
1145                                 if(GetSystemDirectory(SysDir, FMAX_PATH) > 0)\r
1146                                 {\r
1147                                         if(SetCurrentDirectory(SysDir))\r
1148                                         {\r
1149                                                 if(ShellExecute(NULL, "open", "regedit", Tmp, NULL, SW_SHOW) <= (HINSTANCE)32)\r
1150                                                 {\r
1151                                                         MessageBox(NULL, MSGJPN285, "FFFTP", MB_OK);\r
1152                                                 }\r
1153                                                 SetCurrentDirectory(CurDir);\r
1154                                         }\r
1155                                 }\r
1156                         }\r
1157                 }\r
1158         }\r
1159         else\r
1160         {\r
1161                 strcpy(Fname, "FFFTP-Backup.ini");\r
1162                 if(SelectFile(GetMainHwnd(), Fname, MSGJPN286, MSGJPN288, "ini", OFN_EXTENSIONDIFFERENT | OFN_OVERWRITEPROMPT, 1) == TRUE)\r
1163                 {\r
1164                         CopyFile(AskIniFilePath(), Fname, FALSE);\r
1165                 }\r
1166         }\r
1167         return;\r
1168 }\r
1169 \r
1170 \r
1171 /*----- 設定をファイルから復元 ------------------------------------------------\r
1172 *\r
1173 *       Parameter\r
1174 *               なし\r
1175 *\r
1176 *       Return Value\r
1177 *               int     ロードしたかどうか (YES/NO)\r
1178 *----------------------------------------------------------------------------*/\r
1179 \r
1180 int LoadSettingsFromFile(void)\r
1181 {\r
1182         int Ret;\r
1183         char Tmp[FMAX_PATH*2];\r
1184         char Fname[FMAX_PATH+1];\r
1185         // 任意のコードが実行されるバグ修正\r
1186         char CurDir[FMAX_PATH+1];\r
1187         char SysDir[FMAX_PATH+1];\r
1188 \r
1189         Ret = NO;\r
1190         strcpy(Fname, "");\r
1191         if(SelectFile(GetMainHwnd(), Fname, MSGJPN291, MSGJPN290, "", OFN_FILEMUSTEXIST, 0) == TRUE)\r
1192         {\r
1193                 if((strlen(Fname) >= 5) && (_stricmp(&Fname[strlen(Fname)-4], ".reg") == 0))\r
1194                 {\r
1195                         sprintf(Tmp, "\x22%s\x22", Fname);\r
1196                         // 任意のコードが実行されるバグ修正\r
1197 //                      if(ShellExecute(NULL, "open", "regedit", Tmp, ".", SW_SHOW) <= (HINSTANCE)32)\r
1198 //                      {\r
1199 //                              MessageBox(NULL, MSGJPN285, "FFFTP", MB_OK);\r
1200 //                      }\r
1201 //                      else\r
1202 //                      {\r
1203 //                              Ret = YES;\r
1204 //                              /* レジストリエディタが終了するのを待つ */\r
1205 //                              WaitForSingleObject(Info.hProcess, INFINITE);\r
1206 //                      }\r
1207                         if(GetCurrentDirectory(FMAX_PATH, CurDir) > 0)\r
1208                         {\r
1209                                 if(GetSystemDirectory(SysDir, FMAX_PATH) > 0)\r
1210                                 {\r
1211                                         if(SetCurrentDirectory(SysDir))\r
1212                                         {\r
1213                                                 if(ShellExecute(NULL, "open", "regedit", Tmp, NULL, SW_SHOW) <= (HINSTANCE)32)\r
1214                                                 {\r
1215                                                         MessageBox(NULL, MSGJPN285, "FFFTP", MB_OK);\r
1216                                                 }\r
1217                                                 else\r
1218                                                 {\r
1219                                                         Ret = YES;\r
1220                                                         /* レジストリエディタが終了するのを待つ */\r
1221 //                                                      WaitForSingleObject(Info.hProcess, INFINITE);\r
1222                                                 }\r
1223                                                 SetCurrentDirectory(CurDir);\r
1224                                         }\r
1225                                 }\r
1226                         }\r
1227                 }\r
1228                 else if((strlen(Fname) >= 5) && (_stricmp(&Fname[strlen(Fname)-4], ".ini") == 0))\r
1229                 {\r
1230                         CopyFile(Fname, AskIniFilePath(), FALSE);\r
1231                         Ret = YES;\r
1232                 }\r
1233                 else\r
1234                         MessageBox(NULL, MSGJPN293, "FFFTP", MB_OK);\r
1235         }\r
1236         return(Ret);\r
1237 }\r
1238 \r
1239 \r
1240 \r
1241 \r
1242 /*----- レジストリ/INIファイルに文字列をセーブ --------------------------------\r
1243 *\r
1244 *       Parameter\r
1245 *               HKEY hKey : レジストリキー\r
1246 *               char *Key : キー名\r
1247 *               char *Str : セーブする文字列\r
1248 *               char *DefaultStr : デフォルトの文字列\r
1249 *\r
1250 *       Return Value\r
1251 *               なし\r
1252 *\r
1253 *       Note\r
1254 *               文字列がデフォルトの文字列と同じならセーブしない\r
1255 *----------------------------------------------------------------------------*/\r
1256 \r
1257 static void SaveStr(HKEY hKey, char *Key, char *Str, char *DefaultStr)\r
1258 {\r
1259         if((DefaultStr != NULL) && (strcmp(Str, DefaultStr) == 0))\r
1260                 DeleteValue(hKey, Key);\r
1261         else\r
1262                 WriteStringToReg(hKey, Key, Str);\r
1263 \r
1264         return;\r
1265 }\r
1266 \r
1267 \r
1268 /*----- レジストリ/INIファイルに数値(INT)をセーブ -----------------------------\r
1269 *\r
1270 *       Parameter\r
1271 *               HKEY hKey : レジストリキー\r
1272 *               char *Key : キー名\r
1273 *               int Num : セーブする値\r
1274 *               int DefaultNum : デフォルトの値\r
1275 *\r
1276 *       Return Value\r
1277 *               なし\r
1278 *\r
1279 *       Note\r
1280 *               数値がデフォルトの値と同じならセーブしない\r
1281 *----------------------------------------------------------------------------*/\r
1282 \r
1283 static void SaveIntNum(HKEY hKey, char *Key, int Num, int DefaultNum)\r
1284 {\r
1285         if(Num == DefaultNum)\r
1286                 DeleteValue(hKey, Key);\r
1287         else\r
1288                 WriteIntValueToReg(hKey, Key, Num);\r
1289 \r
1290         return;\r
1291 }\r
1292 \r
1293 \r
1294 /*----- LOGFONTデータを文字列に変換する ---------------------------------------\r
1295 *\r
1296 *       Parameter\r
1297 *               LOGFONT Font : フォントデータ\r
1298 *               HFONT hFont : フォントのハンドル\r
1299 *                       NULL = デフォルトのフォント\r
1300 *               char *Buf : バッファ\r
1301 *\r
1302 *       Return Value\r
1303 *               なし\r
1304 *----------------------------------------------------------------------------*/\r
1305 \r
1306 static void MakeFontData(LOGFONT Font, HFONT hFont, char *Buf)\r
1307 {\r
1308         *Buf = NUL;\r
1309         if(hFont != NULL)\r
1310                 sprintf(Buf, "%d %d %d %d %d %d %d %d %d %d %d %d %d %s",\r
1311                         Font.lfHeight, Font.lfWidth, Font.lfEscapement, Font.lfOrientation,\r
1312                         Font.lfWeight, Font.lfItalic, Font.lfUnderline, Font.lfStrikeOut,\r
1313                         Font.lfCharSet, Font.lfOutPrecision, Font.lfClipPrecision,\r
1314                         Font.lfQuality, Font.lfPitchAndFamily, Font.lfFaceName);\r
1315         return;\r
1316 }\r
1317 \r
1318 \r
1319 /*----- 文字列をLOGFONTデータに変換する ---------------------------------------\r
1320 *\r
1321 *       Parameter\r
1322 *               char *Str : 文字列\r
1323 *               LOGFONT *Font : フォントデータ\r
1324 *\r
1325 *       Return Value\r
1326 *               int ステータス\r
1327 *                       FFFTP_SUCCESS/FFFTP_FAIL=変換できない\r
1328 *----------------------------------------------------------------------------*/\r
1329 \r
1330 static int RestoreFontData(char *Str, LOGFONT *Font)\r
1331 {\r
1332         int i;\r
1333         int Sts;\r
1334 \r
1335         Sts = FFFTP_FAIL;\r
1336         if(sscanf(Str, "%d %d %d %d %d %d %d %d %d %d %d %d %d",\r
1337                         &(Font->lfHeight), &(Font->lfWidth), &(Font->lfEscapement), &(Font->lfOrientation),\r
1338                         &(Font->lfWeight), &(Font->lfItalic), &(Font->lfUnderline), &(Font->lfStrikeOut),\r
1339                         &(Font->lfCharSet), &(Font->lfOutPrecision), &(Font->lfClipPrecision),\r
1340                         &(Font->lfQuality), &(Font->lfPitchAndFamily)) == 13)\r
1341         {\r
1342                 for(i = 13; i > 0; i--)\r
1343                 {\r
1344                         if((Str = strchr(Str, ' ')) == NULL)\r
1345                                 break;\r
1346                         Str++;\r
1347                 }\r
1348                 if(i == 0)\r
1349                 {\r
1350                         strcpy(Font->lfFaceName, Str);\r
1351                         Sts = FFFTP_SUCCESS;\r
1352                 }\r
1353         }\r
1354 \r
1355         if(Sts == FFFTP_FAIL)\r
1356                 memset(Font, NUL, sizeof(LOGFONT));\r
1357 \r
1358         return(Sts);\r
1359 }\r
1360 \r
1361 /*----- パスワードを暗号化する ------------------------------------------------\r
1362 *\r
1363 *       Parameter\r
1364 *               char *Str : パスワード\r
1365 *               char *Buf : 暗号化したパスワードを格納するバッファ\r
1366 *\r
1367 *       Return Value\r
1368 *               なし\r
1369 *----------------------------------------------------------------------------*/\r
1370 static void EncodePassword(char *Str, char *Buf)\r
1371 {\r
1372         EncodePassword3( Str, Buf, SecretKey );\r
1373 }\r
1374 \r
1375 /*----- パスワードを暗号化する(オリジナルアルゴリズム)  ------------------\r
1376 *\r
1377 *       Parameter\r
1378 *               char *Str : パスワード\r
1379 *               char *Buf : 暗号化したパスワードを格納するバッファ\r
1380 *\r
1381 *       Return Value\r
1382 *               なし\r
1383 *----------------------------------------------------------------------------*/\r
1384 \r
1385 static void EncodePasswordOriginal(char *Str, char *Buf)\r
1386 {\r
1387         unsigned char *Get;\r
1388         unsigned char *Put;\r
1389         int Rnd;\r
1390         int Ch;\r
1391 \r
1392         srand((unsigned)time(NULL));\r
1393 \r
1394         Get = (unsigned char *)Str;\r
1395         Put = (unsigned char *)Buf;\r
1396         \r
1397         if( *Get == NUL ){\r
1398                 *Put = NUL;\r
1399                 return;\r
1400         }\r
1401 \r
1402         /* 識別子を先頭に置く */\r
1403         Put[0] = '0';\r
1404         Put[1] = 'A';\r
1405         Put += 2;\r
1406 \r
1407         while(*Get != NUL)\r
1408         {\r
1409                 Rnd = rand() % 3;\r
1410                 Ch = ((int)*Get++) << Rnd;\r
1411                 Ch = (unsigned char)Ch | (unsigned char)(Ch >> 8);\r
1412                 *Put++ = 0x40 | ((Rnd & 0x3) << 4) | (Ch & 0xF);\r
1413                 *Put++ = 0x40 | ((Ch >> 4) & 0xF);\r
1414                 if((*(Put-2) & 0x1) != 0)\r
1415                         *Put++ = (rand() % 62) + 0x40;\r
1416         }\r
1417         *Put = NUL;\r
1418         return;\r
1419 }\r
1420 \r
1421 /*----- パスワードを暗号化する(オリジナルアルゴリズム^Key)  ----------------\r
1422 *\r
1423 *       Parameter\r
1424 *               char *Str : パスワード\r
1425 *               char *Buf : 暗号化したパスワードを格納するバッファ\r
1426 *               const char *Key : 暗号化キー\r
1427 *\r
1428 *       Return Value\r
1429 *               なし\r
1430 *----------------------------------------------------------------------------*/\r
1431 \r
1432 static void EncodePassword2(char *Str, char *Buf, const char* Key)\r
1433 {\r
1434         unsigned char *Get;\r
1435         unsigned char *Put;\r
1436         int Rnd;\r
1437         int Ch;\r
1438 \r
1439         /* 2010.01.31 genta Key */\r
1440         unsigned char *KeyHead = (unsigned char *)Key;\r
1441         unsigned char *KeyEnd = KeyHead + strlen(KeyHead);\r
1442         unsigned char *KeyCurrent = KeyHead;\r
1443 \r
1444         srand((unsigned)time(NULL));\r
1445 \r
1446         Get = (unsigned char *)Str;\r
1447         Put = (unsigned char *)Buf;\r
1448         \r
1449         if( *Get == NUL ){\r
1450                 *Put = NUL;\r
1451                 return;\r
1452         }\r
1453 \r
1454         /* 識別子を先頭に置く */\r
1455         Put[0] = '0';\r
1456         Put[1] = 'B';\r
1457         Put += 2;\r
1458 \r
1459         while(*Get != NUL)\r
1460         {\r
1461                 Rnd = rand() % 3;\r
1462                 Ch = ((int)(*Get++ ^ *KeyCurrent)) << Rnd;\r
1463                 Ch = (unsigned char)Ch | (unsigned char)(Ch >> 8);\r
1464                 *Put++ = 0x40 | ((Rnd & 0x3) << 4) | (Ch & 0xF);\r
1465                 *Put++ = 0x40 | ((Ch >> 4) & 0xF);\r
1466                 if((*(Put-2) & 0x1) != 0)\r
1467                         *Put++ = (rand() % 62) + 0x40;\r
1468 \r
1469                 /* 2010.01.31 genta Key */\r
1470                 if( ++KeyCurrent == KeyEnd ){\r
1471                         KeyCurrent = KeyHead;\r
1472                 }\r
1473         }\r
1474         *Put = NUL;\r
1475         return;\r
1476 }\r
1477 \r
1478 /*----- パスワードを暗号化する(AES) ------------------------------------------\r
1479 *\r
1480 *       Parameter\r
1481 *               char *Str : パスワード\r
1482 *               char *Buf : 暗号化したパスワードを格納するバッファ\r
1483 *               const char *Key : 暗号化キー\r
1484 *\r
1485 *       Return Value\r
1486 *               なし\r
1487 *----------------------------------------------------------------------------*/\r
1488 \r
1489 static void EncodePassword3(char *Str, char *Buf, const char *Key)\r
1490 {\r
1491         unsigned char *Put;\r
1492         unsigned char *AesEncBuf;\r
1493         unsigned char *StrPadBuf;\r
1494         size_t StrLen;\r
1495         size_t StrPadLen;\r
1496         size_t StrPadIndex;\r
1497         size_t IvIndex;\r
1498         size_t EncBufIndex;\r
1499         DWORD RandValue;\r
1500         int RandByteCount;\r
1501         unsigned char AesKey[32];\r
1502         unsigned char AesCbcIv[AES_BLOCK_SIZE];\r
1503         aes_encrypt_ctx Ctx;\r
1504 \r
1505         Buf[0] = NUL;\r
1506 \r
1507         Put = (unsigned char *)Buf;\r
1508         StrLen = strlen(Str);\r
1509         StrPadLen = ((StrLen + AES_BLOCK_SIZE - 1) / AES_BLOCK_SIZE) * AES_BLOCK_SIZE;\r
1510 \r
1511         /* 最低長を32文字とする */\r
1512 //      StrPadLen = min1(StrPadLen, AES_BLOCK_SIZE * 2);\r
1513         StrPadLen = max1(StrPadLen, AES_BLOCK_SIZE * 2);\r
1514 \r
1515         if((StrPadBuf = malloc(StrPadLen)) != NULL)\r
1516         {\r
1517                 if((AesEncBuf = malloc(StrPadLen)) != NULL)\r
1518                 {\r
1519                         BOOL PutState;\r
1520 \r
1521                         PutState = FALSE;\r
1522                         strncpy(StrPadBuf, Str, StrPadLen);\r
1523                         \r
1524                         /* PAD部分を乱数で埋める StrPad[StrLen](が有効な場合) は NUL */\r
1525                         for(StrPadIndex = StrLen + 1; StrPadIndex < StrPadLen;)\r
1526                         {\r
1527                                 RandValue = GetRandamDWRODValue();\r
1528                                 for(RandByteCount = 0; RandByteCount < 4; RandByteCount++)\r
1529                                 {\r
1530                                         if(StrPadIndex < StrPadLen)\r
1531                                         {\r
1532                                                 StrPadBuf[StrPadIndex++] = (unsigned char)(RandValue & 0xff);\r
1533                                                 RandValue >>= 8;\r
1534                                         }\r
1535                                 }\r
1536                         }\r
1537                         \r
1538                         // IVの初期化\r
1539                         for(IvIndex = 0; IvIndex < AES_BLOCK_SIZE;)\r
1540                         {\r
1541                                 RandValue = GetRandamDWRODValue();\r
1542                                 for(RandByteCount = 0; RandByteCount < 4; RandByteCount++)\r
1543                                 {\r
1544                                         if(IvIndex < AES_BLOCK_SIZE)\r
1545                                         {\r
1546                                                 AesCbcIv[IvIndex++] = (unsigned char)(RandValue & 0xff);\r
1547                                                 RandValue >>= 8;\r
1548                                         }\r
1549                                 }\r
1550                         }\r
1551                         Put[0] = '0';\r
1552                         Put[1] = 'C';\r
1553                         Put += 2;\r
1554                         for(IvIndex = 0; IvIndex < AES_BLOCK_SIZE; IvIndex++)\r
1555                         {\r
1556                                 sprintf(Put, "%02x", AesCbcIv[IvIndex]);\r
1557                                 Put += 2;\r
1558                         }\r
1559                         *Put++ = ':';\r
1560 \r
1561                         if(CreateAesKey(AesKey, Key) == FFFTP_SUCCESS)\r
1562                         {\r
1563                                 aes_encrypt_key(AesKey, 32, &Ctx);\r
1564 \r
1565                                 if(aes_cbc_encrypt(StrPadBuf, AesEncBuf, StrPadLen, AesCbcIv, &Ctx) == EXIT_SUCCESS)\r
1566                                 {\r
1567                                         for(EncBufIndex = 0; EncBufIndex < StrPadLen; EncBufIndex++)\r
1568                                         {\r
1569                                                 sprintf(Put, "%02x", AesEncBuf[EncBufIndex]);\r
1570                                                 Put += 2;\r
1571                                         }\r
1572                                         *Put = NUL;\r
1573                                         PutState = TRUE;\r
1574                                 }\r
1575                         }\r
1576                         if(FALSE == PutState)\r
1577                         {\r
1578                                 Buf[0] = NUL;\r
1579                         }\r
1580                         free(StrPadBuf);\r
1581                 }\r
1582                 free(AesEncBuf);\r
1583         }\r
1584         return;\r
1585 }\r
1586 \r
1587 \r
1588 /*----- パスワードの暗号化を解く ----------------------------------------------\r
1589 *\r
1590 *       Parameter\r
1591 *               char *Str : 暗号化したパスワード\r
1592 *               char *Buf : パスワードを格納するバッファ\r
1593 *\r
1594 *       Return Value\r
1595 *               なし\r
1596 *----------------------------------------------------------------------------*/\r
1597 \r
1598 static void DecodePassword(char *Str, char *Buf)\r
1599 {\r
1600         unsigned char *Get;\r
1601         unsigned char *Put;\r
1602 \r
1603         Get = (unsigned char *)Str;\r
1604         Put = (unsigned char *)Buf;\r
1605         \r
1606         if( *Get == NUL ){\r
1607                 *Put = NUL;\r
1608         }\r
1609         else if( 0x40 <= *Get && *Get < 0x80 ){\r
1610                 /* Original algorithm */\r
1611                 DecodePasswordOriginal( Str, Buf );\r
1612         }\r
1613         else if( strncmp( Get, "0A", 2 ) == 0 ){\r
1614                 DecodePasswordOriginal( Str + 2, Buf );\r
1615         }\r
1616         else if( strncmp( Get, "0B", 2 ) == 0 ){\r
1617                 DecodePassword2( Str + 2, Buf, SecretKey );\r
1618         }\r
1619         else if( strncmp( Get, "0C", 2 ) == 0 ){\r
1620                 DecodePassword3( Str + 2, Buf, SecretKey );\r
1621         }\r
1622         else {\r
1623                 //      unknown encoding\r
1624                 *Put = NUL;\r
1625                 return;\r
1626         }\r
1627 }\r
1628 \r
1629 /*----- パスワードの暗号化を解く(オリジナルアルゴリズム) -------------------\r
1630 *\r
1631 *       Parameter\r
1632 *               char *Str : 暗号化したパスワード\r
1633 *               char *Buf : パスワードを格納するバッファ\r
1634 *\r
1635 *       Return Value\r
1636 *               なし\r
1637 *----------------------------------------------------------------------------*/\r
1638 static void DecodePasswordOriginal(char *Str, char *Buf)\r
1639 {\r
1640         unsigned char *Get;\r
1641         unsigned char *Put;\r
1642         int Rnd;\r
1643         int Ch;\r
1644 \r
1645         Get = (unsigned char *)Str;\r
1646         Put = (unsigned char *)Buf;\r
1647 \r
1648         while(*Get != NUL)\r
1649         {\r
1650                 Rnd = ((unsigned int)*Get >> 4) & 0x3;\r
1651                 Ch = (*Get & 0xF) | ((*(Get+1) & 0xF) << 4);\r
1652                 Ch <<= 8;\r
1653                 if((*Get & 0x1) != 0)\r
1654                         Get++;\r
1655                 Get += 2;\r
1656                 Ch >>= Rnd;\r
1657                 Ch = (Ch & 0xFF) | ((Ch >> 8) & 0xFF);\r
1658                 *Put++ = Ch;\r
1659         }\r
1660         *Put = NUL;\r
1661         return;\r
1662 }\r
1663 \r
1664 /*----- パスワードの暗号化を解く(オリジナルアルゴリズム^Key) -------------------\r
1665 *\r
1666 *       Parameter\r
1667 *               char *Str : 暗号化したパスワード\r
1668 *               char *Buf : パスワードを格納するバッファ\r
1669 *               const char *Key : 暗号化キー\r
1670 *\r
1671 *       Return Value\r
1672 *               なし\r
1673 *----------------------------------------------------------------------------*/\r
1674 static void DecodePassword2(char *Str, char *Buf, const char* Key)\r
1675 {\r
1676         int Rnd;\r
1677         int Ch;\r
1678         unsigned char *Get = (unsigned char *)Str;\r
1679         unsigned char *Put = (unsigned char *)Buf;\r
1680 \r
1681         /* 2010.01.31 genta Key */\r
1682         unsigned char *KeyHead = (unsigned char *)Key;\r
1683         unsigned char *KeyEnd = KeyHead + strlen(KeyHead);\r
1684         unsigned char *KeyCurrent = KeyHead;\r
1685 \r
1686         while(*Get != NUL)\r
1687         {\r
1688                 Rnd = ((unsigned int)*Get >> 4) & 0x3;\r
1689                 Ch = (*Get & 0xF) | ((*(Get+1) & 0xF) << 4);\r
1690                 Ch <<= 8;\r
1691                 if((*Get & 0x1) != 0)\r
1692                         Get++;\r
1693                 Get += 2;\r
1694                 Ch >>= Rnd;\r
1695                 Ch = (Ch & 0xFF) | ((Ch >> 8) & 0xFF);\r
1696                 *Put++ = Ch ^ *KeyCurrent;\r
1697                 \r
1698                 /* 2010.01.31 genta Key */\r
1699                 if( ++KeyCurrent == KeyEnd ){\r
1700                         KeyCurrent = KeyHead;\r
1701                 }\r
1702         }\r
1703         *Put = NUL;\r
1704         return;\r
1705 }\r
1706 \r
1707 /*----- パスワードの暗号化を解く(AES) ---------------------------------------\r
1708 *\r
1709 *       Parameter\r
1710 *               char *Str : 暗号化したパスワード\r
1711 *               char *Buf : パスワードを格納するバッファ\r
1712 *               const char *Key : 暗号化キー\r
1713 *\r
1714 *       Return Value\r
1715 *               なし\r
1716 *----------------------------------------------------------------------------*/\r
1717 \r
1718 static void DecodePassword3(char *Str, char *Buf, const char *Key)\r
1719 {\r
1720         char *Get;\r
1721         unsigned char *EncBuf;\r
1722         size_t StrLen;\r
1723         size_t IvIndex;\r
1724         size_t EncBufIndex;\r
1725         size_t EncBufLen;\r
1726         unsigned char AesKey[32];\r
1727         unsigned char AesCbcIv[AES_BLOCK_SIZE];\r
1728         aes_decrypt_ctx Ctx;\r
1729 \r
1730         Buf[0] = NUL;\r
1731 \r
1732         Get = Str;\r
1733         StrLen = strlen(Str);\r
1734 \r
1735         if(AES_BLOCK_SIZE * 2 + 1 < StrLen)\r
1736         {\r
1737 \r
1738                 EncBufLen = (StrLen - 1 ) / 2 - AES_BLOCK_SIZE;\r
1739                 if((EncBuf = malloc(EncBufLen)) != NULL)\r
1740                 {\r
1741                         for(IvIndex = 0; IvIndex < AES_BLOCK_SIZE; IvIndex++)\r
1742                         {\r
1743                                 AesCbcIv[IvIndex]  = hex2bin(*Get++) << 4;\r
1744                                 AesCbcIv[IvIndex] |= hex2bin(*Get++);\r
1745                         }\r
1746 \r
1747                         if(*Get++ == ':')\r
1748                         {\r
1749                                 if(CreateAesKey(AesKey, Key) == FFFTP_SUCCESS)\r
1750                                 {\r
1751                                         aes_decrypt_key(AesKey, 32, &Ctx);\r
1752 \r
1753                                         for(EncBufIndex = 0; EncBufIndex < EncBufLen; EncBufIndex++)\r
1754                                         {\r
1755                                                 EncBuf[EncBufIndex]  = hex2bin(*Get++) << 4;\r
1756                                                 EncBuf[EncBufIndex] |= hex2bin(*Get++);\r
1757                                         }\r
1758                                         if(aes_cbc_decrypt(EncBuf, Buf, EncBufLen, AesCbcIv, &Ctx) == EXIT_SUCCESS)\r
1759                                         {\r
1760                                                 Buf[EncBufLen] = NUL;\r
1761                                         }\r
1762                                 }\r
1763                         }\r
1764                         free(EncBuf);\r
1765                 }\r
1766         }\r
1767         return;\r
1768 }\r
1769 \r
1770 /*----- AES用固定長キーを作成 ----------------------------------------------\r
1771 *\r
1772 *       Parameter\r
1773 *               unsigned char *AesKey : AES暗号鍵\r
1774 *               const char *Key : 暗号化キー\r
1775 *\r
1776 *       Return Value\r
1777 *               int ステータス (FFFTP_SUCCESS/FFFTP_FAIL)\r
1778 *       Note\r
1779 *               SHA-1をもちいて32Byte鍵を生成する\r
1780 *----------------------------------------------------------------------------*/\r
1781 \r
1782 static int CreateAesKey(unsigned char *AesKey, const char* Key)\r
1783 {\r
1784         char* HashKey;\r
1785         uint32 HashKeyLen;\r
1786         uint32 results[10];\r
1787         int ByteOffset;\r
1788         int KeyIndex;\r
1789         int ResIndex;\r
1790 \r
1791         HashKeyLen = strlen(Key) + 16;\r
1792         if((HashKey = malloc(HashKeyLen + 1)) == NULL){\r
1793                 return (FFFTP_FAIL);\r
1794         }\r
1795 \r
1796         strcpy(HashKey, Key);\r
1797         strcat(HashKey, ">g^r=@N7=//z<[`:");\r
1798     sha_memory((uchar *)HashKey, HashKeyLen, results);\r
1799 \r
1800         strcpy(HashKey, Key);\r
1801         strcat(HashKey, "VG77dO1#EyC]$|C@");\r
1802     sha_memory((uchar *)HashKey, HashKeyLen, results + 5);\r
1803 \r
1804         KeyIndex = 0;\r
1805         ResIndex = 0;\r
1806         while(ResIndex < 8){\r
1807                 for(ByteOffset = 0; ByteOffset < 4; ByteOffset++){\r
1808                         AesKey[KeyIndex++] = (results[ResIndex] >> ByteOffset * 8) & 0xff;\r
1809                 }\r
1810                 ResIndex++;\r
1811         }\r
1812         free(HashKey);\r
1813 \r
1814         return (FFFTP_SUCCESS);\r
1815 }\r
1816 \r
1817 \r
1818 /*===== レジストリとINIファイルのアクセス処理 ============*/\r
1819 \r
1820 \r
1821 /*===== INIファイル用のレジストリデータ =====*/\r
1822 \r
1823 typedef struct regdatatbl {\r
1824         char KeyName[80+1];                     /* キー名 */\r
1825         char ValTbl[REG_SECT_MAX];      /* 値のテーブル */\r
1826         int ValLen;                                     /* 値データのバイト数 */\r
1827         int Mode;                                       /* キーのモード */\r
1828         struct regdatatbl *Next;\r
1829 } REGDATATBL;\r
1830 \r
1831 /*===== プロトタイプ =====*/\r
1832 \r
1833 static BOOL WriteOutRegToFile(REGDATATBL *Pos);\r
1834 static int ReadInReg(char *Name, REGDATATBL **Handle);\r
1835 // 暗号化通信対応\r
1836 //static int StrCatOut(char *Src, int Len, char *Dst);\r
1837 //static int StrReadIn(char *Src, int Max, char *Dst);\r
1838 static char *ScanValue(void *Handle, char *Name);\r
1839 \r
1840 \r
1841 /*===== ローカルなワーク =====*/\r
1842 \r
1843 static int TmpRegType;\r
1844 \r
1845 \r
1846 \r
1847 /*----- レジストリのタイプを設定する ------------------------------------------\r
1848 *\r
1849 *       Parameter\r
1850 *               int Type : タイプ (REGTYPE_xxx)\r
1851 *\r
1852 *       Return Value\r
1853 *               int ステータス\r
1854 *                       FFFTP_SUCCESS/FFFTP_FAIL\r
1855 *----------------------------------------------------------------------------*/\r
1856 \r
1857 static void SetRegType(int Type)\r
1858 {\r
1859         TmpRegType = Type;\r
1860         return;\r
1861 }\r
1862 \r
1863 \r
1864 /*----- レジストリ/INIファイルをオープンする(読み込み)-----------------------\r
1865 *\r
1866 *       Parameter\r
1867 *               char *Name : レジストリ名\r
1868 *               void **Handle : ハンドルを返すワーク\r
1869 *\r
1870 *       Return Value\r
1871 *               int ステータス\r
1872 *                       FFFTP_SUCCESS/FFFTP_FAIL\r
1873 *----------------------------------------------------------------------------*/\r
1874 \r
1875 static int OpenReg(char *Name, void **Handle)\r
1876 {\r
1877         int Sts;\r
1878         char Tmp[FMAX_PATH+1];\r
1879 \r
1880         Sts = FFFTP_FAIL;\r
1881         if(TmpRegType == REGTYPE_REG)\r
1882         {\r
1883                 strcpy(Tmp, "Software\\Sota\\");\r
1884                 strcat(Tmp, Name);\r
1885                 if(RegOpenKeyEx(HKEY_CURRENT_USER, Tmp, 0, KEY_READ, (HKEY *)Handle) == ERROR_SUCCESS)\r
1886                         Sts = FFFTP_SUCCESS;\r
1887         }\r
1888         else\r
1889         {\r
1890                 if((Sts = ReadInReg(Name, (REGDATATBL **)Handle)) == FFFTP_SUCCESS)\r
1891                         ((REGDATATBL *)(*Handle))->Mode = 0;\r
1892         }\r
1893         return(Sts);\r
1894 }\r
1895 \r
1896 \r
1897 /*----- レジストリ/INIファイルを作成する(書き込み)---------------------------\r
1898 *\r
1899 *       Parameter\r
1900 *               char *Name : レジストリ名\r
1901 *               void **Handle : ハンドルを返すワーク\r
1902 *\r
1903 *       Return Value\r
1904 *               int ステータス\r
1905 *                       FFFTP_SUCCESS/FFFTP_FAIL\r
1906 *----------------------------------------------------------------------------*/\r
1907 \r
1908 static int CreateReg(char *Name, void **Handle)\r
1909 {\r
1910         int Sts;\r
1911         char Tmp[FMAX_PATH+1];\r
1912         DWORD Dispos;\r
1913 \r
1914         Sts = FFFTP_FAIL;\r
1915         if(TmpRegType == REGTYPE_REG)\r
1916         {\r
1917                 strcpy(Tmp, "Software\\Sota\\");\r
1918                 strcat(Tmp, Name);\r
1919                 if(RegCreateKeyEx(HKEY_CURRENT_USER, Tmp, 0, "", REG_OPTION_NON_VOLATILE, KEY_CREATE_SUB_KEY | KEY_SET_VALUE, NULL, (HKEY *)Handle, &Dispos) == ERROR_SUCCESS)\r
1920                         Sts = FFFTP_SUCCESS;\r
1921         }\r
1922         else\r
1923         {\r
1924                 if((*Handle = malloc(sizeof(REGDATATBL))) != NULL)\r
1925                 {\r
1926                         strcpy(((REGDATATBL *)(*Handle))->KeyName, Name);\r
1927                         ((REGDATATBL *)(*Handle))->ValLen = 0;\r
1928                         ((REGDATATBL *)(*Handle))->Next = NULL;\r
1929                         ((REGDATATBL *)(*Handle))->Mode = 1;\r
1930                         Sts = FFFTP_SUCCESS;\r
1931                 }\r
1932         }\r
1933         return(Sts);\r
1934 }\r
1935 \r
1936 \r
1937 /*----- レジストリ/INIファイルをクローズする ----------------------------------\r
1938 *\r
1939 *       Parameter\r
1940 *               void *Handle : ハンドル\r
1941 *\r
1942 *       Return Value\r
1943 *               int ステータス\r
1944 *                       FFFTP_SUCCESS/FFFTP_FAIL\r
1945 *----------------------------------------------------------------------------*/\r
1946 \r
1947 static int CloseReg(void *Handle)\r
1948 {\r
1949         REGDATATBL *Pos;\r
1950         REGDATATBL *Next;\r
1951         FILE *Strm;\r
1952 \r
1953         if(TmpRegType == REGTYPE_REG)\r
1954         {\r
1955                 RegCloseKey(Handle);\r
1956 \r
1957                 /* INIファイルを削除 */\r
1958                 if((Strm = fopen(AskIniFilePath(), "rt")) != NULL)\r
1959                 {\r
1960                         fclose(Strm);\r
1961                         MoveFileToTrashCan(AskIniFilePath());\r
1962                 }\r
1963         }\r
1964         else\r
1965         {\r
1966                 if(((REGDATATBL *)Handle)->Mode == 1)\r
1967                 {\r
1968                         if(WriteOutRegToFile(Handle) == TRUE)\r
1969                         {\r
1970 //                              /* レジストリをクリア */\r
1971 //                              ClearRegistory();\r
1972                         }\r
1973                 }\r
1974                 /* テーブルを削除 */\r
1975                 Pos = Handle;\r
1976                 while(Pos != NULL)\r
1977                 {\r
1978                         Next = Pos->Next;\r
1979                         free(Pos);\r
1980                         Pos = Next;\r
1981                 }\r
1982         }\r
1983         return(FFFTP_SUCCESS);\r
1984 }\r
1985 \r
1986 \r
1987 /*----- レジストリ情報をINIファイルに書き込む ---------------------------------\r
1988 *\r
1989 *       Parameter\r
1990 *               REGDATATBL *Pos : レジストリデータ\r
1991 *\r
1992 *       Return Value\r
1993 *               なし\r
1994 *----------------------------------------------------------------------------*/\r
1995 \r
1996 static BOOL WriteOutRegToFile(REGDATATBL *Pos)\r
1997 {\r
1998         FILE *Strm;\r
1999         char *Disp;\r
2000         BOOL Ret;\r
2001 \r
2002         Ret = FALSE;\r
2003         if((Strm = fopen(AskIniFilePath(), "wt")) != NULL)\r
2004         {\r
2005                 fprintf(Strm, MSGJPN239);\r
2006                 while(Pos != NULL)\r
2007                 {\r
2008                         fprintf(Strm, "\n[%s]\n", Pos->KeyName);\r
2009 \r
2010                         Disp = Pos->ValTbl;\r
2011                         while(Disp < (Pos->ValTbl + Pos->ValLen))\r
2012                         {\r
2013                                 fprintf(Strm, "%s\n", Disp);\r
2014                                 Disp = Disp + strlen(Disp) + 1;\r
2015                         }\r
2016                         Pos = Pos->Next;\r
2017                 }\r
2018                 fclose(Strm);\r
2019                 Ret = TRUE;\r
2020         }\r
2021         else\r
2022                 MessageBox(NULL, MSGJPN240, "FFFTP", MB_OK);\r
2023 \r
2024         return(Ret);\r
2025 }\r
2026 \r
2027 \r
2028 /*----- INIファイルからレジストリ情報を読み込む -------------------------------\r
2029 *\r
2030 *       Parameter\r
2031 *               char *Name : 名前\r
2032 *               void *Handle : ハンドル\r
2033 *\r
2034 *       Return Value\r
2035 *               int ステータス\r
2036 *                       FFFTP_SUCCESS/FFFTP_FAIL\r
2037 *----------------------------------------------------------------------------*/\r
2038 \r
2039 static int ReadInReg(char *Name, REGDATATBL **Handle)\r
2040 {\r
2041         FILE *Strm;\r
2042         char *Buf;\r
2043         char *Tmp;\r
2044         char *Data;\r
2045         REGDATATBL *New;\r
2046         REGDATATBL *Pos;\r
2047         int Sts;\r
2048 \r
2049         Sts = FFFTP_FAIL;\r
2050         *Handle = NULL;\r
2051 \r
2052         if((Strm = fopen(AskIniFilePath(), "rt")) != NULL)\r
2053         {\r
2054                 if((Buf = malloc(REG_SECT_MAX)) != NULL)\r
2055                 {\r
2056                         while(fgets(Buf, REG_SECT_MAX, Strm) != NULL)\r
2057                         {\r
2058                                 if(*Buf != '#')\r
2059                                 {\r
2060                                         if((Tmp = strchr(Buf, '\n')) != NULL)\r
2061                                                 *Tmp = NUL;\r
2062 \r
2063                                         if(*Buf == '[')\r
2064                                         {\r
2065                                                 if((New = malloc(sizeof(REGDATATBL))) != NULL)\r
2066                                                 {\r
2067                                                         if((Tmp = strchr(Buf, ']')) != NULL)\r
2068                                                                 *Tmp = NUL;\r
2069                                                         strcpy(New->KeyName, Buf+1);\r
2070                                                         New->ValLen = 0;\r
2071                                                         New->Next = NULL;\r
2072                                                         Data = New->ValTbl;\r
2073                                                 }\r
2074                                                 if(*Handle == NULL)\r
2075                                                         *Handle = New;\r
2076                                                 else\r
2077                                                 {\r
2078                                                         Pos = *Handle;\r
2079                                                         while(Pos->Next != NULL)\r
2080                                                                 Pos = Pos->Next;\r
2081                                                         Pos->Next = New;\r
2082                                                 }\r
2083                                         }\r
2084                                         else if(strlen(Buf) > 0)\r
2085                                         {\r
2086                                                 strcpy(Data, Buf);\r
2087                                                 Data += strlen(Buf) + 1;\r
2088                                                 New->ValLen += strlen(Buf) + 1;\r
2089                                         }\r
2090                                 }\r
2091                         }\r
2092                         Sts = FFFTP_SUCCESS;\r
2093                         free(Buf);\r
2094                 }\r
2095                 fclose(Strm);\r
2096         }\r
2097         return(Sts);\r
2098 }\r
2099 \r
2100 \r
2101 /*----- サブキーをオープンする ------------------------------------------------\r
2102 *\r
2103 *       Parameter\r
2104 *               void *Parent : 親のハンドル\r
2105 *               char *Name : 名前\r
2106 *               void **Handle : ハンドルを返すワーク\r
2107 *\r
2108 *       Return Value\r
2109 *               int ステータス\r
2110 *                       FFFTP_SUCCESS/FFFTP_FAIL\r
2111 *----------------------------------------------------------------------------*/\r
2112 \r
2113 static int OpenSubKey(void *Parent, char *Name, void **Handle)\r
2114 {\r
2115         int Sts;\r
2116         char Key[80];\r
2117         REGDATATBL *Pos;\r
2118 \r
2119         Sts = FFFTP_FAIL;\r
2120         if(TmpRegType == REGTYPE_REG)\r
2121         {\r
2122                 if(RegOpenKeyEx(Parent, Name, 0, KEY_READ, (HKEY *)Handle) == ERROR_SUCCESS)\r
2123                         Sts = FFFTP_SUCCESS;\r
2124         }\r
2125         else\r
2126         {\r
2127                 strcpy(Key, ((REGDATATBL *)Parent)->KeyName);\r
2128                 strcat(Key, "\\");\r
2129                 strcat(Key, Name);\r
2130                 Pos = Parent;\r
2131                 while(Pos != NULL)\r
2132                 {\r
2133                         if(strcmp(Pos->KeyName, Key) == 0)\r
2134                         {\r
2135                                 *Handle = Pos;\r
2136                                 Sts = FFFTP_SUCCESS;\r
2137                                 break;\r
2138                         }\r
2139                         Pos = Pos->Next;\r
2140                 }\r
2141         }\r
2142         return(Sts);\r
2143 }\r
2144 \r
2145 \r
2146 /*----- サブキーを作成する ----------------------------------------------------\r
2147 *\r
2148 *       Parameter\r
2149 *               void *Parent : 親のハンドル\r
2150 *               char *Name : 名前\r
2151 *               void **Handle : ハンドルを返すワーク\r
2152 *\r
2153 *       Return Value\r
2154 *               int ステータス\r
2155 *                       FFFTP_SUCCESS/FFFTP_FAIL\r
2156 *----------------------------------------------------------------------------*/\r
2157 \r
2158 static int CreateSubKey(void *Parent, char *Name, void **Handle)\r
2159 {\r
2160         int Sts;\r
2161         DWORD Dispos;\r
2162         REGDATATBL *Pos;\r
2163 \r
2164         Sts = FFFTP_FAIL;\r
2165         if(TmpRegType == REGTYPE_REG)\r
2166         {\r
2167                 if(RegCreateKeyEx(Parent, Name, 0, "", REG_OPTION_NON_VOLATILE, KEY_SET_VALUE, NULL, (HKEY *)Handle, &Dispos) == ERROR_SUCCESS)\r
2168                         Sts = FFFTP_SUCCESS;\r
2169         }\r
2170         else\r
2171         {\r
2172                 if((*Handle = malloc(sizeof(REGDATATBL))) != NULL)\r
2173                 {\r
2174                         strcpy(((REGDATATBL *)(*Handle))->KeyName, ((REGDATATBL *)Parent)->KeyName);\r
2175                         strcat(((REGDATATBL *)(*Handle))->KeyName, "\\");\r
2176                         strcat(((REGDATATBL *)(*Handle))->KeyName, Name);\r
2177 \r
2178                         ((REGDATATBL *)(*Handle))->ValLen = 0;\r
2179                         ((REGDATATBL *)(*Handle))->Next = NULL;\r
2180 \r
2181                         Pos = (REGDATATBL *)Parent;\r
2182                         while(Pos->Next != NULL)\r
2183                                 Pos = Pos->Next;\r
2184                         Pos->Next = *Handle;\r
2185                         Sts = FFFTP_SUCCESS;\r
2186                 }\r
2187         }\r
2188         return(Sts);\r
2189 }\r
2190 \r
2191 \r
2192 /*----- サブキーをクローズする ------------------------------------------------\r
2193 *\r
2194 *       Parameter\r
2195 *               void *Handle : ハンドル\r
2196 *\r
2197 *       Return Value\r
2198 *               int ステータス\r
2199 *                       FFFTP_SUCCESS/FFFTP_FAIL\r
2200 *----------------------------------------------------------------------------*/\r
2201 \r
2202 static int CloseSubKey(void *Handle)\r
2203 {\r
2204         if(TmpRegType == REGTYPE_REG)\r
2205                 RegCloseKey(Handle);\r
2206         else\r
2207         {\r
2208                 /* Nothing */\r
2209         }\r
2210         return(FFFTP_SUCCESS);\r
2211 }\r
2212 \r
2213 \r
2214 /*----- サブキーを削除する ----------------------------------------------------\r
2215 *\r
2216 *       Parameter\r
2217 *               void *Handle : ハンドル\r
2218 *               char *Name : 名前\r
2219 *\r
2220 *       Return Value\r
2221 *               int ステータス\r
2222 *                       FFFTP_SUCCESS/FFFTP_FAIL\r
2223 *----------------------------------------------------------------------------*/\r
2224 \r
2225 static int DeleteSubKey(void *Handle, char *Name)\r
2226 {\r
2227         int Sts;\r
2228 \r
2229         Sts = FFFTP_FAIL;\r
2230         if(TmpRegType == REGTYPE_REG)\r
2231         {\r
2232                 if(RegDeleteKey(Handle, Name) == ERROR_SUCCESS)\r
2233                         Sts = FFFTP_SUCCESS;\r
2234         }\r
2235         else\r
2236         {\r
2237                 Sts = FFFTP_FAIL;\r
2238         }\r
2239         return(Sts);\r
2240 }\r
2241 \r
2242 \r
2243 /*----- 値を削除する ----------------------------------------------------------\r
2244 *\r
2245 *       Parameter\r
2246 *               void *Handle : ハンドル\r
2247 *               char *Name : 名前\r
2248 *\r
2249 *       Return Value\r
2250 *               int ステータス\r
2251 *                       FFFTP_SUCCESS/FFFTP_FAIL\r
2252 *----------------------------------------------------------------------------*/\r
2253 \r
2254 static int DeleteValue(void *Handle, char *Name)\r
2255 {\r
2256         int Sts;\r
2257 \r
2258         Sts = FFFTP_FAIL;\r
2259         if(TmpRegType == REGTYPE_REG)\r
2260         {\r
2261                 if(RegDeleteValue(Handle, Name) == ERROR_SUCCESS)\r
2262                         Sts = FFFTP_SUCCESS;\r
2263         }\r
2264         else\r
2265         {\r
2266                 Sts = FFFTP_FAIL;\r
2267         }\r
2268         return(Sts);\r
2269 }\r
2270 \r
2271 \r
2272 /*----- INT値を読み込む -------------------------------------------------------\r
2273 *\r
2274 *       Parameter\r
2275 *               void *Handle : ハンドル\r
2276 *               char *Name : 名前\r
2277 *               int *Value : INT値を返すワーク\r
2278 *\r
2279 *       Return Value\r
2280 *               int ステータス\r
2281 *                       FFFTP_SUCCESS/FFFTP_FAIL\r
2282 *----------------------------------------------------------------------------*/\r
2283 \r
2284 static int ReadIntValueFromReg(void *Handle, char *Name, int *Value)\r
2285 {\r
2286         int Sts;\r
2287         DWORD Size;\r
2288         char *Pos;\r
2289 \r
2290         Sts = FFFTP_FAIL;\r
2291         if(TmpRegType == REGTYPE_REG)\r
2292         {\r
2293                 Size = sizeof(int);\r
2294                 if(RegQueryValueEx(Handle, Name, NULL, NULL, (BYTE *)Value, &Size) == ERROR_SUCCESS)\r
2295                         Sts = FFFTP_SUCCESS;\r
2296         }\r
2297         else\r
2298         {\r
2299                 if((Pos = ScanValue(Handle, Name)) != NULL)\r
2300                 {\r
2301                         *Value = atoi(Pos);\r
2302                         Sts = FFFTP_SUCCESS;\r
2303                 }\r
2304         }\r
2305         return(Sts);\r
2306 }\r
2307 \r
2308 \r
2309 /*----- INT値を書き込む -------------------------------------------------------\r
2310 *\r
2311 *       Parameter\r
2312 *               void *Handle : ハンドル\r
2313 *               char *Name : 名前\r
2314 *               int Value : INT値\r
2315 *\r
2316 *       Return Value\r
2317 *               int ステータス\r
2318 *                       FFFTP_SUCCESS/FFFTP_FAIL\r
2319 *----------------------------------------------------------------------------*/\r
2320 \r
2321 static int WriteIntValueToReg(void *Handle, char *Name, int Value)\r
2322 {\r
2323         REGDATATBL *Pos;\r
2324         char *Data;\r
2325         char Tmp[20];\r
2326 \r
2327         if(TmpRegType == REGTYPE_REG)\r
2328                 RegSetValueEx(Handle, Name, 0, REG_DWORD, (CONST BYTE *)&Value, sizeof(int));\r
2329         else\r
2330         {\r
2331                 Pos = (REGDATATBL *)Handle;\r
2332                 Data = Pos->ValTbl + Pos->ValLen;\r
2333                 strcpy(Data, Name);\r
2334                 strcat(Data, "=");\r
2335                 sprintf(Tmp, "%d", Value);\r
2336                 strcat(Data, Tmp);\r
2337                 Pos->ValLen += strlen(Data) + 1;\r
2338         }\r
2339         return(FFFTP_SUCCESS);\r
2340 }\r
2341 \r
2342 \r
2343 /*----- 文字列を読み込む ------------------------------------------------------\r
2344 *\r
2345 *       Parameter\r
2346 *               void *Handle : ハンドル\r
2347 *               char *Name : 名前\r
2348 *               char *Str : 文字列を返すワーク\r
2349 *               DWORD Size : 最大サイズ\r
2350 *\r
2351 *       Return Value\r
2352 *               int ステータス\r
2353 *                       FFFTP_SUCCESS/FFFTP_FAIL\r
2354 *----------------------------------------------------------------------------*/\r
2355 \r
2356 static int ReadStringFromReg(void *Handle, char *Name, char *Str, DWORD Size)\r
2357 {\r
2358         int Sts;\r
2359         char *Pos;\r
2360         // UTF-8対応\r
2361         DWORD TempSize;\r
2362         char* pa0;\r
2363         wchar_t* pw0;\r
2364 \r
2365         Sts = FFFTP_FAIL;\r
2366         if(TmpRegType == REGTYPE_REG)\r
2367         {\r
2368                 if(RegQueryValueEx(Handle, Name, NULL, NULL, (BYTE *)Str, &Size) == ERROR_SUCCESS)\r
2369                 {\r
2370                         if(*(Str + Size - 1) != NUL)\r
2371                                 *(Str + Size) = NUL;\r
2372                         Sts = FFFTP_SUCCESS;\r
2373                 }\r
2374         }\r
2375         else\r
2376         {\r
2377                 if((Pos = ScanValue(Handle, Name)) != NULL)\r
2378                 {\r
2379                         // UTF-8対応\r
2380 //                      Size = min1(Size-1, strlen(Pos));\r
2381 //                      Size = StrReadIn(Pos, Size, Str);\r
2382 //                      *(Str + Size) = NUL;\r
2383 //                      Sts = FFFTP_SUCCESS;\r
2384                         switch(IniKanjiCode)\r
2385                         {\r
2386                         case KANJI_NOCNV:\r
2387                                 TempSize = min1(Size-1, strlen(Pos));\r
2388                                 TempSize = StrReadIn(Pos, TempSize, Str);\r
2389                                 *(Str + TempSize) = NUL;\r
2390                                 Sts = FFFTP_SUCCESS;\r
2391                                 if(!CheckStringM(Str))\r
2392                                         break;\r
2393                                 // UTF-8ではない可能性がある\r
2394                                 // Shift_JISとみなす\r
2395                         case KANJI_SJIS:\r
2396                                 if(pa0 = AllocateStringA(Size * 4))\r
2397                                 {\r
2398                                         if(pw0 = AllocateStringW(Size * 4 * 4))\r
2399                                         {\r
2400                                                 TempSize = min1((Size * 4) - 1, strlen(Pos));\r
2401                                                 TempSize = StrReadIn(Pos, TempSize, pa0);\r
2402                                                 *(pa0 + TempSize) = NUL;\r
2403                                                 AtoW(pw0, Size * 4 * 4, pa0, -1);\r
2404                                                 WtoM(Str, Size, pw0, -1);\r
2405                                                 TerminateStringM(Str, Size);\r
2406                                                 Sts = FFFTP_SUCCESS;\r
2407                                                 FreeDuplicatedString(pw0);\r
2408                                         }\r
2409                                         FreeDuplicatedString(pa0);\r
2410                                 }\r
2411                                 break;\r
2412                         }\r
2413                 }\r
2414         }\r
2415         return(Sts);\r
2416 }\r
2417 \r
2418 \r
2419 /*----- 文字列を書き込む ------------------------------------------------------\r
2420 *\r
2421 *       Parameter\r
2422 *               void *Handle : ハンドル\r
2423 *               char *Name : 名前\r
2424 *               char *Str :文字列\r
2425 *\r
2426 *       Return Value\r
2427 *               int ステータス\r
2428 *                       FFFTP_SUCCESS/FFFTP_FAIL\r
2429 *----------------------------------------------------------------------------*/\r
2430 \r
2431 static int WriteStringToReg(void *Handle, char *Name, char *Str)\r
2432 {\r
2433         REGDATATBL *Pos;\r
2434         char *Data;\r
2435 \r
2436         if(TmpRegType == REGTYPE_REG)\r
2437                 RegSetValueEx(Handle, Name, 0, REG_SZ, (CONST BYTE *)Str, strlen(Str)+1);\r
2438         else\r
2439         {\r
2440                 Pos = (REGDATATBL *)Handle;\r
2441                 Data = Pos->ValTbl + Pos->ValLen;\r
2442                 strcpy(Data, Name);\r
2443                 strcat(Data, "=");\r
2444                 Pos->ValLen += strlen(Data);\r
2445                 Data = Pos->ValTbl + Pos->ValLen;\r
2446                 Pos->ValLen += StrCatOut(Str, strlen(Str), Data) + 1;\r
2447         }\r
2448         return(FFFTP_SUCCESS);\r
2449 }\r
2450 \r
2451 \r
2452 /*----- マルチ文字列を読み込む ------------------------------------------------\r
2453 *\r
2454 *       Parameter\r
2455 *               void *Handle : ハンドル\r
2456 *               char *Name : 名前\r
2457 *               char *Str : 文字列を返すワーク\r
2458 *               DWORD Size : 最大サイズ\r
2459 *\r
2460 *       Return Value\r
2461 *               int ステータス\r
2462 *                       FFFTP_SUCCESS/FFFTP_FAIL\r
2463 *----------------------------------------------------------------------------*/\r
2464 \r
2465 static int ReadMultiStringFromReg(void *Handle, char *Name, char *Str, DWORD Size)\r
2466 {\r
2467         int Sts;\r
2468         char *Pos;\r
2469         // UTF-8対応\r
2470         DWORD TempSize;\r
2471         char* pa0;\r
2472         wchar_t* pw0;\r
2473 \r
2474         Sts = FFFTP_FAIL;\r
2475         if(TmpRegType == REGTYPE_REG)\r
2476         {\r
2477                 if(RegQueryValueEx(Handle, Name, NULL, NULL, (BYTE *)Str, &Size) == ERROR_SUCCESS)\r
2478                 {\r
2479                         if(*(Str + Size - 1) != NUL)\r
2480                                 *(Str + Size) = NUL;\r
2481                         Sts = FFFTP_SUCCESS;\r
2482                 }\r
2483         }\r
2484         else\r
2485         {\r
2486                 if((Pos = ScanValue(Handle, Name)) != NULL)\r
2487                 {\r
2488                         // UTF-8対応\r
2489 //                      Size = min1(Size-1, strlen(Pos));\r
2490 //                      Size = StrReadIn(Pos, Size, Str);\r
2491 //                      *(Str + Size) = NUL;\r
2492 //                      Sts = FFFTP_SUCCESS;\r
2493                         switch(IniKanjiCode)\r
2494                         {\r
2495                         case KANJI_NOCNV:\r
2496                                 TempSize = min1(Size - 2, strlen(Pos));\r
2497                                 TempSize = StrReadIn(Pos, TempSize, Str);\r
2498                                 *(Str + TempSize) = NUL;\r
2499                                 *(Str + TempSize + 1) = NUL;\r
2500                                 Sts = FFFTP_SUCCESS;\r
2501                                 if(!CheckMultiStringM(Str))\r
2502                                         break;\r
2503                                 // UTF-8ではない可能性がある\r
2504                                 // Shift_JISとみなす\r
2505                         case KANJI_SJIS:\r
2506                                 if(pa0 = AllocateStringA(Size * 4))\r
2507                                 {\r
2508                                         if(pw0 = AllocateStringW(Size * 4 * 4))\r
2509                                         {\r
2510                                                 TempSize = min1((Size * 4) - 2, strlen(Pos));\r
2511                                                 TempSize = StrReadIn(Pos, TempSize, pa0);\r
2512                                                 *(pa0 + TempSize) = NUL;\r
2513                                                 *(pa0 + TempSize + 1) = NUL;\r
2514                                                 AtoWMultiString(pw0, Size * 4 * 4, pa0);\r
2515                                                 WtoMMultiString(Str, Size, pw0);\r
2516                                                 TerminateStringM(Str, Size);\r
2517                                                 TerminateStringM(Str, Size - 1);\r
2518                                                 Sts = FFFTP_SUCCESS;\r
2519                                                 FreeDuplicatedString(pw0);\r
2520                                         }\r
2521                                         FreeDuplicatedString(pa0);\r
2522                                 }\r
2523                                 break;\r
2524                         }\r
2525                 }\r
2526         }\r
2527         return(Sts);\r
2528 }\r
2529 \r
2530 \r
2531 /*----- マルチ文字列を書き込む ------------------------------------------------\r
2532 *\r
2533 *       Parameter\r
2534 *               void *Handle : ハンドル\r
2535 *               char *Name : 名前\r
2536 *               char *Str : 文字列\r
2537 *\r
2538 *       Return Value\r
2539 *               int ステータス\r
2540 *                       FFFTP_SUCCESS/FFFTP_FAIL\r
2541 *----------------------------------------------------------------------------*/\r
2542 \r
2543 static int WriteMultiStringToReg(void *Handle, char *Name, char *Str)\r
2544 {\r
2545         REGDATATBL *Pos;\r
2546         char *Data;\r
2547 \r
2548         if(TmpRegType == REGTYPE_REG)\r
2549                 RegSetValueEx(Handle, Name, 0, REG_MULTI_SZ, (CONST BYTE *)Str, StrMultiLen(Str)+1);\r
2550         else\r
2551         {\r
2552                 Pos = (REGDATATBL *)Handle;\r
2553                 Data = Pos->ValTbl + Pos->ValLen;\r
2554                 strcpy(Data, Name);\r
2555                 strcat(Data, "=");\r
2556                 Pos->ValLen += strlen(Data);\r
2557                 Data = Pos->ValTbl + Pos->ValLen;\r
2558                 Pos->ValLen += StrCatOut(Str, StrMultiLen(Str), Data) + 1;\r
2559         }\r
2560         return(FFFTP_SUCCESS);\r
2561 }\r
2562 \r
2563 \r
2564 /*----- バイナリを読み込む-----------------------------------------------------\r
2565 *\r
2566 *       Parameter\r
2567 *               void *Handle : ハンドル\r
2568 *               char *Name : 名前\r
2569 *               void *Bin : バイナリを返すワーク\r
2570 *               DWORD Size : 最大サイズ\r
2571 *\r
2572 *       Return Value\r
2573 *               int ステータス\r
2574 *                       FFFTP_SUCCESS/FFFTP_FAIL\r
2575 *----------------------------------------------------------------------------*/\r
2576 \r
2577 static int ReadBinaryFromReg(void *Handle, char *Name, void *Bin, DWORD Size)\r
2578 {\r
2579         int Sts;\r
2580         char *Pos;\r
2581 \r
2582         Sts = FFFTP_FAIL;\r
2583         if(TmpRegType == REGTYPE_REG)\r
2584         {\r
2585                 if(RegQueryValueEx(Handle, Name, NULL, NULL, (BYTE *)Bin, &Size) == ERROR_SUCCESS)\r
2586                         Sts = FFFTP_SUCCESS;\r
2587         }\r
2588         else\r
2589         {\r
2590                 if((Pos = ScanValue(Handle, Name)) != NULL)\r
2591                 {\r
2592                         Size = min1(Size, strlen(Pos));\r
2593                         Size = StrReadIn(Pos, Size, Bin);\r
2594                         Sts = FFFTP_SUCCESS;\r
2595                 }\r
2596         }\r
2597         return(Sts);\r
2598 }\r
2599 \r
2600 \r
2601 /*----- バイナリを書き込む ----------------------------------------------------\r
2602 *\r
2603 *       Parameter\r
2604 *               void *Handle : ハンドル\r
2605 *               char *Name : 名前\r
2606 *               void *Bin : バイナリ\r
2607 *               int Len : 長さ\r
2608 *\r
2609 *       Return Value\r
2610 *               int ステータス\r
2611 *                       FFFTP_SUCCESS/FFFTP_FAIL\r
2612 *----------------------------------------------------------------------------*/\r
2613 \r
2614 static int WriteBinaryToReg(void *Handle, char *Name, void *Bin, int Len)\r
2615 {\r
2616         REGDATATBL *Pos;\r
2617         char *Data;\r
2618 \r
2619         if(TmpRegType == REGTYPE_REG)\r
2620                 RegSetValueEx(Handle, Name, 0, REG_BINARY, (CONST BYTE *)Bin, Len);\r
2621         else\r
2622         {\r
2623                 Pos = (REGDATATBL *)Handle;\r
2624                 Data = Pos->ValTbl + Pos->ValLen;\r
2625                 strcpy(Data, Name);\r
2626                 strcat(Data, "=");\r
2627                 Pos->ValLen += strlen(Data);\r
2628                 Data = Pos->ValTbl + Pos->ValLen;\r
2629                 Pos->ValLen += StrCatOut(Bin, Len, Data) + 1;\r
2630         }\r
2631         return(FFFTP_SUCCESS);\r
2632 }\r
2633 \r
2634 \r
2635 /*----- 文字列をバッファに追加書き込みする ------------------------------------\r
2636 *\r
2637 *       Parameter\r
2638 *               char *Src : 文字列\r
2639 *               int len : 文字列の長さ\r
2640 *               char *Dst : 書き込みするバッファ\r
2641 *\r
2642 *       Return Value\r
2643 *               int 追加したバイト数\r
2644 *----------------------------------------------------------------------------*/\r
2645 \r
2646 static int StrCatOut(char *Src, int Len, char *Dst)\r
2647 {\r
2648         int Count;\r
2649 \r
2650         Dst += strlen(Dst);\r
2651         Count = 0;\r
2652         for(; Len > 0; Len--)\r
2653         {\r
2654                 if(*Src == '\\')\r
2655                 {\r
2656                         *Dst++ = '\\';\r
2657                         *Dst++ = '\\';\r
2658                         Count += 2;\r
2659                 }\r
2660                 else if((*Src >= 0x20) && (*Src <= 0x7E))\r
2661                 {\r
2662                         *Dst++ = *Src;\r
2663                         Count++;\r
2664                 }\r
2665                 else\r
2666                 {\r
2667                         sprintf(Dst, "\\%02X", *(unsigned char *)Src);\r
2668                         Dst += 3;\r
2669                         Count += 3;\r
2670                 }\r
2671                 Src++;\r
2672         }\r
2673         *Dst = NUL;\r
2674         return(Count);\r
2675 }\r
2676 \r
2677 \r
2678 /*----- 文字列をバッファに読み込む --------------------------------------------\r
2679 *\r
2680 *       Parameter\r
2681 *               char *Src : 文字列\r
2682 *               int Max : 最大サイズ\r
2683 *               char *Dst : 書き込みするバッファ\r
2684 *\r
2685 *       Return Value\r
2686 *               int 読み込んだバイト数\r
2687 *----------------------------------------------------------------------------*/\r
2688 \r
2689 static int StrReadIn(char *Src, int Max, char *Dst)\r
2690 {\r
2691         int Count;\r
2692         int Tmp;\r
2693 \r
2694         Count = 0;\r
2695         while(*Src != NUL)\r
2696         {\r
2697                 if(Count >= Max)\r
2698                         break;\r
2699 \r
2700                 if(*Src == '\\')\r
2701                 {\r
2702                         Src++;\r
2703                         if(*Src == '\\')\r
2704                                 *Dst = '\\';\r
2705                         else\r
2706                         {\r
2707                                 sscanf(Src, "%02x", &Tmp);\r
2708                                 *Dst = Tmp;\r
2709                                 Src++;\r
2710                         }\r
2711                 }\r
2712                 else\r
2713                         *Dst = *Src;\r
2714 \r
2715                 Count++;\r
2716                 Dst++;\r
2717                 Src++;\r
2718         }\r
2719         return(Count);\r
2720 }\r
2721 \r
2722 \r
2723 /*----- 値を検索する ----------------------------------------------------------\r
2724 *\r
2725 *       Parameter\r
2726 *               char *Handle : ハンドル\r
2727 *               char *Name : 名前\r
2728 *\r
2729 *       Return Value\r
2730 *               char *値データの先頭\r
2731 *                       NULL=指定の名前の値が見つからない\r
2732 *----------------------------------------------------------------------------*/\r
2733 \r
2734 static char *ScanValue(void *Handle, char *Name)\r
2735 {\r
2736         REGDATATBL *Cur;\r
2737         char *Pos;\r
2738         char *Ret;\r
2739 \r
2740         Ret = NULL;\r
2741         Cur = Handle;\r
2742         Pos = Cur->ValTbl;\r
2743         while(Pos < (Cur->ValTbl + Cur->ValLen))\r
2744         {\r
2745                 if((strncmp(Name, Pos, strlen(Name)) == 0) &&\r
2746                    (*(Pos + strlen(Name)) == '='))\r
2747                 {\r
2748                         Ret = Pos + strlen(Name) + 1;\r
2749                         break;\r
2750                 }\r
2751                 Pos += strlen(Pos) + 1;\r
2752         }\r
2753         return(Ret);\r
2754 }\r
2755 \r
2756 \r
2757 /*----------- パスワードの妥当性を確認する ------------------------------------\r
2758 *\r
2759 *       Parameter\r
2760 *               char *Password: パスワード文字列\r
2761 *               char *HashStr: SHA-1ハッシュ文字列\r
2762 *\r
2763 *       Return Value\r
2764 *               int 0 不一致\r
2765 *                       1: 一致\r
2766 *                       2: 異常\r
2767 *----------------------------------------------------------------------------*/\r
2768 int CheckPasswordValidity( char* Password, int length, const char* HashStr )\r
2769 {\r
2770         ulong hash1[5];\r
2771         ulong hash2[5];\r
2772         \r
2773         int i, j;\r
2774         \r
2775         const char* p = HashStr;\r
2776         \r
2777         /* 空文字列は一致したことにする */\r
2778         if( HashStr[0] == NUL ) return 1;\r
2779 \r
2780         /* Hashをチェックするする*/\r
2781         if( strlen(HashStr) != 40 )     return 2;\r
2782 \r
2783         /* Hashをデコードする*/\r
2784         for( i = 0; i < 5; i++ ){\r
2785                 ulong decode = 0;\r
2786                 for( j = 0; j < 8; j++ ){\r
2787                         if( *p < 0x40 || 0x40 + 15 < *p ){\r
2788                                 return 2;\r
2789                         }\r
2790                         decode = (decode << 4 ) + (*p - 0x40);\r
2791                         ++p;\r
2792                 }\r
2793                 hash1[i] = decode;\r
2794         }\r
2795         \r
2796         /* Password をハッシュする */\r
2797         sha_memory( Password, length, hash2 );\r
2798         \r
2799         if( memcmp( (char*)hash1, (char*)hash2, sizeof( hash1 )) == 0 ){\r
2800                 return 1;\r
2801         }\r
2802         return 0;\r
2803 }\r
2804 \r
2805 /*----------- パスワードの妥当性チェックのための文字列を作成する ------------\r
2806 *\r
2807 *       Parameter\r
2808 *               char *Password: パスワード文字列\r
2809 *               char *Str: SHA-1ハッシュ文字列格納場所 (41bytes以上)\r
2810 *\r
2811 *       Return Value\r
2812 *               None\r
2813 *----------------------------------------------------------------------------*/\r
2814 void CreatePasswordHash( char* Password, int length, char* HashStr )\r
2815 {\r
2816         ulong hash[5];\r
2817         int i, j;\r
2818         unsigned char *p = (unsigned char *)HashStr;\r
2819 \r
2820         sha_memory( Password, length, hash );\r
2821 \r
2822         for( i = 0; i < 5; i++ ){\r
2823                 ulong rest = hash[i];\r
2824                 for( j = 0; j < 8; j++ ){\r
2825                         *p++ = (unsigned char)((rest & 0xf0000000) >> 28) + '@';\r
2826                         rest <<= 4;\r
2827                 }\r
2828         }\r
2829         *p = NUL;\r
2830 }\r
2831 \r
2832 void SetHashSalt( DWORD salt )\r
2833 {\r
2834         unsigned char* pos = &SecretKey[strlen(SecretKey) + 1];\r
2835         *pos++ = ( salt >> 24 ) & 0xff;\r
2836         *pos++ = ( salt >> 16 ) & 0xff;\r
2837         *pos++ = ( salt >>  8 ) & 0xff;\r
2838         *pos++ = ( salt       ) & 0xff;\r
2839         \r
2840         SecretKeyLength = strlen( SecretKey ) + 5;\r
2841 }\r
2842 \r
2843 /*----------- 乱数生成をする --------------------------