Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2381 lines
72 KiB

  1. /*
  2. +-------------------------------------------------------------------------+
  3. | Netware to Windows NT Transfer Loop |
  4. +-------------------------------------------------------------------------+
  5. | (c) Copyright 1993-1994 |
  6. | Microsoft Corp. |
  7. | All rights reserved |
  8. | |
  9. | Program : [Transfer.c] |
  10. | Programmer : Arthur Hanson |
  11. | Original Program Date : [Jul 27, 1993] |
  12. | Last Update : [Jun 16, 1994] |
  13. | |
  14. | Version: 1.00 |
  15. | |
  16. | Description: |
  17. | |
  18. | History: |
  19. | arth June 16, 1994 1.00 Original Version. |
  20. | |
  21. +-------------------------------------------------------------------------+
  22. */
  23. #include "globals.h"
  24. #include <stdio.h>
  25. #include <stdarg.h>
  26. #include <limits.h>
  27. #include <time.h>
  28. #include "nwconv.h"
  29. #include "convapi.h"
  30. #include "ntnetapi.h"
  31. #include "nwnetapi.h"
  32. #include "userdlg.h"
  33. #include "statbox.h"
  34. #include "filedlg.h"
  35. #include "map.h"
  36. #define NWC_ERR_IGNORE 1
  37. #define NWC_ERR_NAMELONG 2
  38. #define NWC_ERR_DUPLICATE 3
  39. #define NWC_ERR_NAMEINVALID 4
  40. #define ILLEGAL_CHARS TEXT("\"\\/[]:;=,+*?<>")
  41. // define for routines in fcopy.c
  42. void ConvertFiles(HWND hDlg, BOOL TConversion, USER_LIST *Users, GROUP_LIST *Groups);
  43. void ConvertFilesInit(HWND hDlg);
  44. void VSharesCreate(DEST_SERVER_BUFFER *DServ, BOOL TConversion);
  45. // Cache of user and group lists
  46. typedef struct _LIST_CACHE {
  47. struct _LIST_CACHE *next;
  48. ULONG Count;
  49. void *ul;
  50. } LIST_CACHE;
  51. static LIST_CACHE *UserCacheHead = NULL;
  52. static LIST_CACHE *GroupCacheHead = NULL;
  53. // Misc string holders
  54. static LPTSTR LocalName = NULL;
  55. static LPTSTR SourceServer, DestServer;
  56. TCHAR UserServerName[MAX_SERVER_NAME_LEN + 3];
  57. static TCHAR tmpStr[80];
  58. static TCHAR tmpStr2[60];
  59. static TCHAR ErrorText[256];
  60. static TCHAR NewName[256];
  61. static TCHAR pLine[256];
  62. static CONVERT_OPTIONS *ConvOpt = NULL;
  63. static FILE_OPTIONS *FileOptions = NULL;
  64. static BOOL TConversion;
  65. static BOOL WarningDlgForNTFS;
  66. // Totals for stat box
  67. static UINT TotErrors;
  68. static UINT TotGroups;
  69. static UINT TotUsers;
  70. static UINT TotConversions;
  71. UINT TotFiles;
  72. time_t StartTime;
  73. time_t CurrTime;
  74. // User and Group list pointers
  75. static USER_LIST *Users = NULL;
  76. static USER_LIST *NTUsers = NULL;
  77. static GROUP_LIST *Groups = NULL;
  78. static GROUP_LIST *NTGroups = NULL;
  79. static DWORD UserCount, NTUserCount;
  80. static DWORD GroupCount, NTGroupCount;
  81. static BOOL TransferCancel = FALSE;
  82. static MAP_FILE *hMap;
  83. // All of this is used for transfer lists in the conversion
  84. #define USER_SERVER 0
  85. #define USER_SERVER_PDC 1
  86. #define USER_SERVER_TRUSTED 2
  87. typedef struct _TRANSFER_BUFFER {
  88. LPTSTR ServerName;
  89. UINT UserServerType;
  90. CONVERT_LIST *ConvertList;
  91. } TRANSFER_BUFFER;
  92. typedef struct _TRANSFER_LIST {
  93. ULONG Count;
  94. TRANSFER_BUFFER TList[];
  95. } TRANSFER_LIST;
  96. /*+-------------------------------------------------------------------------+
  97. | ErrorIt()
  98. |
  99. +-------------------------------------------------------------------------+*/
  100. void ErrorIt(LPTSTR szFormat, ...) {
  101. static TCHAR tmpStr[1024];
  102. va_list marker;
  103. va_start(marker, szFormat);
  104. wvsprintf(tmpStr, szFormat, marker);
  105. #ifdef DEBUG
  106. dprintf(TEXT("Errorit: %s\n"), tmpStr);
  107. #endif
  108. TotErrors++;
  109. Status_TotErrors(TotErrors);
  110. LogWriteErr(TEXT("%s"),tmpStr);
  111. va_end(marker);
  112. } // ErrorIt
  113. /*+-------------------------------------------------------------------------+
  114. | NTFS Check Routines |
  115. +-------------------------------------------------------------------------+*/
  116. /*+-------------------------------------------------------------------------+
  117. | ShareListNTFSCheck()
  118. |
  119. +-------------------------------------------------------------------------+*/
  120. BOOL ShareListNTFSCheck() {
  121. CONVERT_LIST *ConvList;
  122. DEST_SERVER_BUFFER *DServ;
  123. SOURCE_SERVER_BUFFER *SServ;
  124. SHARE_LIST *ShareList;
  125. SHARE_BUFFER *SList;
  126. VIRTUAL_SHARE_BUFFER *VShare;
  127. DRIVE_BUFFER *Drive;
  128. ULONG i;
  129. FILE_OPTIONS *FileOptions;
  130. // Go through the convert list checking for any shares to non NTFS drives
  131. ConvList = ConvertListStart;
  132. while (ConvList != NULL) {
  133. DServ = ConvList->FileServ;
  134. SServ = ConvList->SourceServ;
  135. FileOptions = (FILE_OPTIONS *) ConvList->FileOptions;
  136. if (FileOptions->TransferFileInfo) {
  137. ShareList = SServ->ShareList;
  138. if (ShareList != NULL) {
  139. SList = ShareList->SList;
  140. for (i = 0; i < ShareList->Count; i++) {
  141. // if not flagged as okay for going to fat, then must check
  142. if (SList[i].Convert && !SList[i].ToFat)
  143. if (SList[i].DestShare != NULL)
  144. if (SList[i].Virtual) {
  145. VShare = (VIRTUAL_SHARE_BUFFER *) SList[i].DestShare;
  146. Drive = VShare->Drive;
  147. if ((Drive == NULL) || (Drive->Type != DRIVE_TYPE_NTFS))
  148. return FALSE;
  149. } else {
  150. Drive = SList[i].DestShare->Drive;
  151. if ((Drive == NULL) || (Drive->Type != DRIVE_TYPE_NTFS))
  152. return FALSE;
  153. }
  154. } // for loop through shares
  155. }
  156. } // if FileOptions
  157. ConvList = ConvList->next;
  158. }
  159. return TRUE;
  160. } // ShareListNTFSCheck
  161. /*+-------------------------------------------------------------------------+
  162. | ShareListNTFSListboxFill()
  163. |
  164. +-------------------------------------------------------------------------+*/
  165. void ShareListNTFSListboxFill(HWND hDlg) {
  166. TCHAR AddLine[256];
  167. CONVERT_LIST *ConvList;
  168. DEST_SERVER_BUFFER *DServ;
  169. SOURCE_SERVER_BUFFER *SServ;
  170. SHARE_LIST *ShareList;
  171. SHARE_BUFFER *SList;
  172. VIRTUAL_SHARE_BUFFER *VShare;
  173. DRIVE_BUFFER *Drive;
  174. ULONG i;
  175. HWND hCtrl;
  176. FILE_OPTIONS *FileOptions;
  177. // Go through the convert list checking for any shares to non NTFS drives
  178. ConvList = ConvertListStart;
  179. hCtrl = GetDlgItem(hDlg, IDC_LIST1);
  180. while (ConvList != NULL) {
  181. DServ = ConvList->FileServ;
  182. SServ = ConvList->SourceServ;
  183. FileOptions = (FILE_OPTIONS *) ConvList->FileOptions;
  184. if (FileOptions->TransferFileInfo) {
  185. ShareList = SServ->ShareList;
  186. if (ShareList != NULL) {
  187. SList = ShareList->SList;
  188. for (i = 0; i < ShareList->Count; i++) {
  189. // if not flagged as okay for going to fat, then must check
  190. if (SList[i].Convert && !SList[i].ToFat)
  191. if (SList[i].DestShare != NULL)
  192. if (SList[i].Virtual) {
  193. VShare = (VIRTUAL_SHARE_BUFFER *) SList[i].DestShare;
  194. Drive = VShare->Drive;
  195. if ((Drive == NULL) || (Drive->Type != DRIVE_TYPE_NTFS)) {
  196. wsprintf(AddLine, TEXT("%s\\%s: -> \\\\%s\\%s"), SServ->Name, SList[i].Name, DServ->Name, VShare->Name);
  197. SendMessage(hCtrl, LB_ADDSTRING, (WPARAM) 0, (LPARAM) AddLine);
  198. }
  199. } else {
  200. Drive = SList[i].DestShare->Drive;
  201. if ((Drive == NULL) || (Drive->Type != DRIVE_TYPE_NTFS)) {
  202. wsprintf(AddLine, TEXT("%s\\%s: -> \\\\%s\\%s"), SServ->Name, SList[i].Name, DServ->Name, SList[i].DestShare->Name);
  203. SendMessage(hCtrl, LB_ADDSTRING, (WPARAM) 0, (LPARAM) AddLine);
  204. }
  205. }
  206. } // for loop through shares
  207. }
  208. } // if FileOptions
  209. ConvList = ConvList->next;
  210. }
  211. } // ShareListNTFSListboxFill
  212. /*+-------------------------------------------------------------------------+
  213. | ShareListFATOK()
  214. |
  215. +-------------------------------------------------------------------------+*/
  216. void ShareListFATOK() {
  217. CONVERT_LIST *ConvList;
  218. DEST_SERVER_BUFFER *DServ;
  219. SOURCE_SERVER_BUFFER *SServ;
  220. SHARE_LIST *ShareList;
  221. SHARE_BUFFER *SList;
  222. ULONG i;
  223. FILE_OPTIONS *FileOptions;
  224. // Go through the convert list checking for any shares to non NTFS drives
  225. ConvList = ConvertListStart;
  226. while (ConvList != NULL) {
  227. DServ = ConvList->FileServ;
  228. SServ = ConvList->SourceServ;
  229. FileOptions = (FILE_OPTIONS *) ConvList->FileOptions;
  230. if (FileOptions->TransferFileInfo) {
  231. ShareList = SServ->ShareList;
  232. if (ShareList != NULL) {
  233. SList = ShareList->SList;
  234. for (i = 0; i < ShareList->Count; i++) {
  235. if (SList[i].Convert)
  236. SList[i].ToFat = TRUE;
  237. }
  238. }
  239. } // if FileOptions
  240. ConvList = ConvList->next;
  241. }
  242. } // ShareListFATOK
  243. /*+-------------------------------------------------------------------------+
  244. | Space Check Routines |
  245. +-------------------------------------------------------------------------+*/
  246. /*+-------------------------------------------------------------------------+
  247. | ShareListSpaceCheck()
  248. |
  249. +-------------------------------------------------------------------------+*/
  250. BOOL ShareListSpaceCheck() {
  251. CONVERT_LIST *ConvList;
  252. DEST_SERVER_BUFFER *DServ;
  253. SOURCE_SERVER_BUFFER *SServ;
  254. SHARE_LIST *ShareList;
  255. SHARE_BUFFER *SList;
  256. VIRTUAL_SHARE_BUFFER *VShare;
  257. DRIVE_BUFFER *Drive;
  258. ULONG i;
  259. FILE_OPTIONS *FileOptions;
  260. // Go through the convert list checking for any shares to non NTFS drives
  261. ConvList = ConvertListStart;
  262. while (ConvList != NULL) {
  263. DServ = ConvList->FileServ;
  264. SServ = ConvList->SourceServ;
  265. FileOptions = (FILE_OPTIONS *) ConvList->FileOptions;
  266. if (FileOptions->TransferFileInfo) {
  267. ShareList = SServ->ShareList;
  268. if (ShareList != NULL) {
  269. SList = ShareList->SList;
  270. for (i = 0; i < ShareList->Count; i++) {
  271. if (SList[i].Convert && (SList[i].DestShare != NULL))
  272. if (SList[i].Virtual) {
  273. VShare = (VIRTUAL_SHARE_BUFFER *) SList[i].DestShare;
  274. Drive = VShare->Drive;
  275. if ((Drive == NULL) || (Drive->AllocSpace > Drive->FreeSpace))
  276. return FALSE;
  277. } else {
  278. Drive = SList[i].DestShare->Drive;
  279. if ((Drive == NULL) || (Drive->AllocSpace > Drive->FreeSpace))
  280. return FALSE;
  281. }
  282. } // for loop through shares
  283. }
  284. } // if FileOptions
  285. ConvList = ConvList->next;
  286. }
  287. return TRUE;
  288. } // ShareListSpaceCheck
  289. /*+-------------------------------------------------------------------------+
  290. | ShareListSpaceListboxFill()
  291. |
  292. +-------------------------------------------------------------------------+*/
  293. void ShareListSpaceListboxFill(HWND hDlg) {
  294. TCHAR AddLine[256];
  295. TCHAR Free[25];
  296. CONVERT_LIST *ConvList;
  297. DEST_SERVER_BUFFER *DServ;
  298. SOURCE_SERVER_BUFFER *SServ;
  299. SHARE_LIST *ShareList;
  300. SHARE_BUFFER *SList;
  301. VIRTUAL_SHARE_BUFFER *VShare;
  302. DRIVE_BUFFER *Drive;
  303. ULONG i;
  304. HWND hCtrl;
  305. FILE_OPTIONS *FileOptions;
  306. // Go through the convert list checking for any shares to non NTFS drives
  307. ConvList = ConvertListStart;
  308. hCtrl = GetDlgItem(hDlg, IDC_LIST1);
  309. while (ConvList != NULL) {
  310. DServ = ConvList->FileServ;
  311. SServ = ConvList->SourceServ;
  312. FileOptions = (FILE_OPTIONS *) ConvList->FileOptions;
  313. if (FileOptions->TransferFileInfo) {
  314. ShareList = SServ->ShareList;
  315. if (ShareList != NULL) {
  316. SList = ShareList->SList;
  317. for (i = 0; i < ShareList->Count; i++) {
  318. if (SList[i].Convert && (SList[i].DestShare != NULL))
  319. if (SList[i].Virtual) {
  320. VShare = (VIRTUAL_SHARE_BUFFER *) SList[i].DestShare;
  321. Drive = VShare->Drive;
  322. if (Drive != NULL) {
  323. if (Drive->AllocSpace > Drive->FreeSpace) {
  324. // List shares then space
  325. wsprintf(AddLine, TEXT("%s\\%s: -> \\\\%s\\%s"), SServ->Name, SList[i].Name, DServ->Name, VShare->Name);
  326. SendMessage(hCtrl, LB_ADDSTRING, (WPARAM) 0, (LPARAM) AddLine);
  327. lstrcpy(Free, lToStr(Drive->FreeSpace));
  328. wsprintf(AddLine, Lids(IDS_D_13), Free, lToStr(Drive->AllocSpace));
  329. SendMessage(hCtrl, LB_ADDSTRING, (WPARAM) 0, (LPARAM) AddLine);
  330. }
  331. } else {
  332. wsprintf(AddLine, TEXT("%s\\%s: -> \\\\%s\\%s"), SServ->Name, SList[i].Name, DServ->Name, VShare->Name);
  333. SendMessage(hCtrl, LB_ADDSTRING, (WPARAM) 0, (LPARAM) AddLine);
  334. wsprintf(AddLine, Lids(IDS_D_14));
  335. SendMessage(hCtrl, LB_ADDSTRING, (WPARAM) 0, (LPARAM) AddLine);
  336. }
  337. } else {
  338. Drive = SList[i].DestShare->Drive;
  339. if (Drive != NULL) {
  340. if (Drive->AllocSpace > Drive->FreeSpace) {
  341. // List shares then space
  342. wsprintf(AddLine, TEXT("%s\\%s: -> \\\\%s\\%s"), SServ->Name, SList[i].Name, DServ->Name, SList[i].DestShare->Name);
  343. SendMessage(hCtrl, LB_ADDSTRING, (WPARAM) 0, (LPARAM) AddLine);
  344. lstrcpy(Free, lToStr(Drive->FreeSpace));
  345. wsprintf(AddLine, Lids(IDS_D_13), Free, lToStr(Drive->AllocSpace));
  346. SendMessage(hCtrl, LB_ADDSTRING, (WPARAM) 0, (LPARAM) AddLine);
  347. }
  348. } else {
  349. wsprintf(AddLine, TEXT("%s\\%s: -> \\\\%s\\%s"), SServ->Name, SList[i].Name, DServ->Name, SList[i].DestShare->Name);
  350. SendMessage(hCtrl, LB_ADDSTRING, (WPARAM) 0, (LPARAM) AddLine);
  351. wsprintf(AddLine, Lids(IDS_D_14));
  352. SendMessage(hCtrl, LB_ADDSTRING, (WPARAM) 0, (LPARAM) AddLine);
  353. }
  354. } // if Virtual
  355. } // for loop through shares
  356. }
  357. } // if FileOptions
  358. ConvList = ConvList->next;
  359. }
  360. } // ShareListSpaceListboxFill
  361. /*+-------------------------------------------------------------------------+
  362. | Conversion Warning Dialog |
  363. +-------------------------------------------------------------------------+*/
  364. /*+-------------------------------------------------------------------------+
  365. | DlgConversionWarning()
  366. |
  367. +-------------------------------------------------------------------------+*/
  368. LRESULT CALLBACK DlgConversionWarning(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {
  369. int wmId, wmEvent;
  370. switch (message) {
  371. case WM_INITDIALOG:
  372. // Center the dialog over the application window
  373. CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
  374. if (WarningDlgForNTFS) {
  375. SendDlgItemMessage(hDlg, IDC_PANEL1, WM_SETTEXT, 0, (LPARAM) Lids(IDS_D_15));
  376. ShareListNTFSListboxFill(hDlg);
  377. } else {
  378. SendDlgItemMessage(hDlg, IDC_PANEL1, WM_SETTEXT, 0, (LPARAM) Lids(IDS_D_16));
  379. ShareListSpaceListboxFill(hDlg);
  380. }
  381. return (TRUE);
  382. case WM_COMMAND:
  383. wmId = LOWORD(wParam);
  384. wmEvent = HIWORD(wParam);
  385. switch (wmId) {
  386. case IDYES:
  387. if (WarningDlgForNTFS)
  388. ShareListFATOK();
  389. EndDialog(hDlg, 0);
  390. return (TRUE);
  391. break;
  392. case IDNO:
  393. TransferCancel = TRUE;
  394. EndDialog(hDlg, 0);
  395. return (TRUE);
  396. break;
  397. }
  398. break;
  399. }
  400. return (FALSE); // Didn't process the message
  401. lParam;
  402. } // DlgConversionWarning
  403. /*+-------------------------------------------------------------------------+
  404. | ConversionWarningDlg_Do()
  405. |
  406. +-------------------------------------------------------------------------+*/
  407. void ConversionWarningDlg_Do(HWND hDlg) {
  408. DLGPROC lpfnDlg;
  409. lpfnDlg = MakeProcInstance((DLGPROC) DlgConversionWarning, hInst);
  410. DialogBox(hInst, TEXT("AlertSel"), hDlg, lpfnDlg) ;
  411. FreeProcInstance(lpfnDlg);
  412. } // ConversionWarningDlg_Do
  413. /*+-------------------------------------------------------------------------+
  414. | NTFSCheck()
  415. |
  416. +-------------------------------------------------------------------------+*/
  417. void NTFSCheck(HWND hDlg) {
  418. WarningDlgForNTFS = TRUE;
  419. if (!ShareListNTFSCheck())
  420. ConversionWarningDlg_Do(hDlg);
  421. } // NTFSCheck
  422. /*+-------------------------------------------------------------------------+
  423. | SpaceCheck()
  424. |
  425. +-------------------------------------------------------------------------+*/
  426. void SpaceCheck(HWND hDlg) {
  427. WarningDlgForNTFS = FALSE;
  428. if (!ShareListSpaceCheck())
  429. ConversionWarningDlg_Do(hDlg);
  430. } // SpaceCheck
  431. /*+-------------------------------------------------------------------------+
  432. | End of Conversion Dialog |
  433. +-------------------------------------------------------------------------+*/
  434. /*+-------------------------------------------------------------------------+
  435. | DlgConversionEnd()
  436. |
  437. +-------------------------------------------------------------------------+*/
  438. LRESULT CALLBACK DlgConversionEnd(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {
  439. HANDLE hFile;
  440. int wmId, wmEvent;
  441. static char CmdLine[256];
  442. HWND hCtrl;
  443. switch (message) {
  444. case WM_INITDIALOG:
  445. // Center the dialog over the application window
  446. CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
  447. hCtrl = GetDlgItem(hDlg, IDC_VIEWLOG);
  448. // check if logfile exists, if it does allow log file viewing...
  449. hFile = CreateFileA( "LogFile.LOG", GENERIC_READ, 0, NULL, OPEN_EXISTING,
  450. FILE_ATTRIBUTE_NORMAL, NULL);
  451. if (hFile != (HANDLE) INVALID_HANDLE_VALUE)
  452. CloseHandle( hFile );
  453. else
  454. EnableWindow(hCtrl, FALSE);
  455. SendDlgItemMessage(hDlg, IDC_S_TOT_COMP, WM_SETTEXT, 0, (LPARAM) lToStr(TotConversions));
  456. SendDlgItemMessage(hDlg, IDC_S_TOT_GROUPS, WM_SETTEXT, 0, (LPARAM) lToStr(TotGroups));
  457. SendDlgItemMessage(hDlg, IDC_S_TOT_USERS, WM_SETTEXT, 0, (LPARAM) lToStr(TotUsers));
  458. SendDlgItemMessage(hDlg, IDC_S_TOT_FILES, WM_SETTEXT, 0, (LPARAM) lToStr(TotFiles));
  459. SendDlgItemMessage(hDlg, IDC_S_TOT_ERRORS, WM_SETTEXT, 0, (LPARAM) lToStr(TotErrors));
  460. if (TransferCancel)
  461. SendMessage(hDlg, WM_SETTEXT, (WPARAM) 0, (LPARAM) Lids(IDS_D_17));
  462. return (TRUE);
  463. case WM_COMMAND:
  464. wmId = LOWORD(wParam);
  465. wmEvent = HIWORD(wParam);
  466. switch (wmId) {
  467. case IDOK:
  468. case IDCANCEL:
  469. EndDialog(hDlg, 0);
  470. return (TRUE);
  471. break;
  472. case IDC_VIEWLOG:
  473. lstrcpyA(CmdLine, "LogView ");
  474. lstrcatA(CmdLine, "Error.LOG Summary.LOG LogFile.LOG");
  475. WinExec(CmdLine, SW_SHOW);
  476. return (TRUE);
  477. break;
  478. }
  479. break;
  480. }
  481. return (FALSE); // Didn't process the message
  482. lParam;
  483. } // DlgConversionEnd
  484. /*+-------------------------------------------------------------------------+
  485. | ConversionEndDlg_Do()
  486. |
  487. +-------------------------------------------------------------------------+*/
  488. void ConversionEndDlg_Do(HWND hDlg) {
  489. DLGPROC lpfnDlg;
  490. lpfnDlg = MakeProcInstance((DLGPROC) DlgConversionEnd, hInst);
  491. DialogBox(hInst, TEXT("ConversionEnd"), hDlg, lpfnDlg) ;
  492. FreeProcInstance(lpfnDlg);
  493. } // ConversionEndDlg_Do
  494. /*+-------------------------------------------------------------------------+
  495. | User / Group lists and Cache routines |
  496. +-------------------------------------------------------------------------+*/
  497. /*+-------------------------------------------------------------------------+
  498. | FindUserMatch()
  499. |
  500. | Searches through the user list using a binary search. Returns a
  501. | pointer to the found user record or NULL if no match.
  502. |
  503. +-------------------------------------------------------------------------+*/
  504. USER_BUFFER *FindUserMatch(LPTSTR Name, USER_LIST *UserList, BOOL NewName) {
  505. LONG begin = 0;
  506. LONG end;
  507. LONG cur;
  508. int match;
  509. USER_BUFFER *UserBuffer;
  510. if (UserList == NULL)
  511. return NULL;
  512. UserBuffer = UserList->UserBuffer;
  513. end = UserList->Count - 1;
  514. while (end >= begin) {
  515. // go halfway in-between
  516. cur = (begin + end) / 2;
  517. // compare the two result into match
  518. if (NewName)
  519. match = lstrcmpi(Name, UserBuffer[cur].NewName);
  520. else
  521. match = lstrcmpi(Name, UserBuffer[cur].Name);
  522. if (match < 0)
  523. // move new begin
  524. end = cur - 1;
  525. else
  526. begin = cur + 1;
  527. if (match == 0)
  528. return &UserBuffer[cur];
  529. }
  530. return NULL;
  531. } // FindUserMatch
  532. /*+-------------------------------------------------------------------------+
  533. | FindGroupMatch()
  534. |
  535. | Searches through the group list using a binary search. Returns a
  536. | pointer to the found group record or NULL if no match.
  537. |
  538. +-------------------------------------------------------------------------+*/
  539. GROUP_BUFFER *FindGroupMatch(LPTSTR Name, GROUP_LIST *GroupList, BOOL NewName) {
  540. LONG begin = 0;
  541. LONG end;
  542. LONG cur;
  543. int match;
  544. GROUP_BUFFER *GroupBuffer;
  545. if (GroupList == NULL)
  546. return NULL;
  547. GroupBuffer = GroupList->GroupBuffer;
  548. end = GroupList->Count - 1;
  549. while (end >= begin) {
  550. // go halfway in-between
  551. cur = (begin + end) / 2;
  552. // compare the two result into match
  553. if (NewName)
  554. match = lstrcmpi(Name, GroupBuffer[cur].NewName);
  555. else
  556. match = lstrcmpi(Name, GroupBuffer[cur].Name);
  557. if (match < 0)
  558. // move new begin
  559. end = cur - 1;
  560. else
  561. begin = cur + 1;
  562. if (match == 0)
  563. return &GroupBuffer[cur];
  564. }
  565. return NULL;
  566. } // FindGroupMatch
  567. /*+-------------------------------------------------------------------------+
  568. | The List Cache's are a linked list of previously converted user and
  569. | group lists. This is mostly for when running trial conversions you can
  570. | check if a previously transferred name conflicts with a new name (since
  571. | the name won't actually be out on the destination server).
  572. |
  573. | The Cache is kept around while working with the same destination server
  574. | or domain. Once a new domain/server is selected the cache and all lists
  575. | should be freed.
  576. +-------------------------------------------------------------------------+*/
  577. /*+-------------------------------------------------------------------------+
  578. | ListCachePut()
  579. |
  580. +-------------------------------------------------------------------------+*/
  581. BOOL ListCachePut(LIST_CACHE **CacheHead, void *ul, ULONG Count) {
  582. LIST_CACHE *cc;
  583. LIST_CACHE *pc;
  584. cc = (LIST_CACHE *) AllocMemory(sizeof(LIST_CACHE));
  585. if (cc == NULL)
  586. return FALSE;
  587. // Init the cache entry
  588. cc->next = NULL;
  589. cc->Count = Count;
  590. cc->ul = ul;
  591. // Now put it at the end of the chain
  592. if (*CacheHead == NULL) {
  593. *CacheHead = cc;
  594. return TRUE;
  595. }
  596. pc = *CacheHead;
  597. while (pc->next)
  598. pc = pc->next;
  599. pc->next = cc;
  600. return TRUE;
  601. } // ListCachePut
  602. /*+-------------------------------------------------------------------------+
  603. | ListCacheFree()
  604. |
  605. +-------------------------------------------------------------------------+*/
  606. void ListCacheFree(LIST_CACHE **CacheHead) {
  607. LIST_CACHE *cc;
  608. LIST_CACHE *pc;
  609. cc = *CacheHead;
  610. while (cc) {
  611. // Free the user list attached to this cache entry
  612. FreeMemory(cc->ul);
  613. // Save next cache entry
  614. pc = cc->next;
  615. // Free up the cache entry and loop
  616. FreeMemory(cc);
  617. cc = pc;
  618. }
  619. *CacheHead = NULL;
  620. } // ListCacheFree
  621. /*+-------------------------------------------------------------------------+
  622. | UserCacheMatch()
  623. |
  624. +-------------------------------------------------------------------------+*/
  625. BOOL UserCacheMatch(LPTSTR UserName) {
  626. LIST_CACHE *cc;
  627. BOOL match = FALSE;
  628. cc = UserCacheHead;
  629. // loop through the cache entries and try to match with each user list
  630. while (cc && !match) {
  631. if (FindUserMatch(UserName, (USER_LIST *) cc->ul, TRUE))
  632. match = TRUE;
  633. else
  634. cc = cc->next;
  635. }
  636. return match;
  637. } // UserCacheMatch
  638. /*+-------------------------------------------------------------------------+
  639. | GroupCacheMatch()
  640. |
  641. +-------------------------------------------------------------------------+*/
  642. BOOL GroupCacheMatch(LPTSTR GroupName) {
  643. LIST_CACHE *cc;
  644. BOOL match = FALSE;
  645. cc = GroupCacheHead;
  646. // loop through the cache entries and try to match with each user list
  647. while (cc && !match) {
  648. if (FindGroupMatch(GroupName, (GROUP_LIST *) cc->ul, TRUE))
  649. match = TRUE;
  650. else
  651. cc = cc->next;
  652. }
  653. return match;
  654. } // GroupCacheMatch
  655. /*+-------------------------------------------------------------------------+
  656. | Logging Garbage |
  657. +-------------------------------------------------------------------------+*/
  658. /*+-------------------------------------------------------------------------+
  659. | ConvertOptionsLog()
  660. |
  661. | Writes all the admin selected conversion options to the log file.
  662. |
  663. +-------------------------------------------------------------------------+*/
  664. void ConvertOptionsLog() {
  665. LogWriteLog(0, Lids(IDS_L_136));
  666. if (ConvOpt->TransferUserInfo)
  667. LogWriteLog(1, Lids(IDS_L_137), Lids(IDS_YES));
  668. else
  669. LogWriteLog(1, Lids(IDS_L_137), Lids(IDS_NO));
  670. LogWriteLog(0, Lids(IDS_CRLF));
  671. if (ConvOpt->TransferUserInfo) {
  672. LogWriteLog(1, Lids(IDS_L_140));
  673. if (ConvOpt->UseMappingFile) {
  674. LogWriteLog(2, Lids(IDS_L_138), Lids(IDS_YES));
  675. LogWriteLog(3, Lids(IDS_L_139), ConvOpt->MappingFile);
  676. } else {
  677. LogWriteLog(2, Lids(IDS_L_138), Lids(IDS_NO));
  678. // Password Options
  679. LogWriteLog(2, Lids(IDS_L_141));
  680. switch (ConvOpt->PasswordOption) {
  681. case 0: // Use NULL
  682. LogWriteLog(0, Lids(IDS_L_142));
  683. break;
  684. case 1: // Password is username
  685. LogWriteLog(0, Lids(IDS_L_143));
  686. break;
  687. case 2: // Use constant
  688. LogWriteLog(0, Lids(IDS_L_144), ConvOpt->PasswordConstant);
  689. break;
  690. }
  691. }
  692. if (ConvOpt->ForcePasswordChange)
  693. LogWriteLog(3, Lids(IDS_L_145), Lids(IDS_YES));
  694. else
  695. LogWriteLog(3, Lids(IDS_L_145), Lids(IDS_NO));
  696. if (!ConvOpt->UseMappingFile) {
  697. // User Names Options
  698. LogWriteLog(2, Lids(IDS_L_146));
  699. switch (ConvOpt->UserNameOption) {
  700. case 0: // Don't transfer - log failures
  701. LogWriteLog(0, Lids(IDS_L_148));
  702. break;
  703. case 1: // Ignore
  704. LogWriteLog(0, Lids(IDS_L_149));
  705. break;
  706. case 2: // Overwrite with new info
  707. LogWriteLog(0, Lids(IDS_L_151));
  708. break;
  709. case 3: // Pre-Pend constant
  710. LogWriteLog(0, Lids(IDS_L_150), ConvOpt->UserConstant);
  711. break;
  712. }
  713. LogWriteLog(0, Lids(IDS_CRLF));
  714. // Group Names Options
  715. LogWriteLog(2, Lids(IDS_L_147));
  716. switch (ConvOpt->GroupNameOption) {
  717. case 0: // Don't transfer - log failures
  718. LogWriteLog(0, Lids(IDS_L_148));
  719. break;
  720. case 1: // Overwrite with new info
  721. LogWriteLog(0, Lids(IDS_L_149));
  722. break;
  723. case 2: // Pre-Pend constant
  724. LogWriteLog(0, Lids(IDS_L_150), ConvOpt->GroupConstant);
  725. break;
  726. }
  727. LogWriteLog(0, Lids(IDS_CRLF));
  728. }
  729. if (ConvOpt->SupervisorDefaults)
  730. LogWriteLog(2, Lids(IDS_L_152), Lids(IDS_YES));
  731. else
  732. LogWriteLog(2, Lids(IDS_L_152), Lids(IDS_NO));
  733. if (ConvOpt->AdminAccounts)
  734. LogWriteLog(2, Lids(IDS_L_153), Lids(IDS_YES));
  735. else
  736. LogWriteLog(2, Lids(IDS_L_153), Lids(IDS_NO));
  737. if (ConvOpt->UseTrustedDomain && (ConvOpt->TrustedDomain != NULL))
  738. LogWriteLog(2, Lids(IDS_L_154), ConvOpt->TrustedDomain->Name);
  739. LogWriteLog(0, Lids(IDS_CRLF));
  740. }
  741. LogWriteLog(0, Lids(IDS_CRLF));
  742. } // ConvertOptionsLog
  743. /*+-------------------------------------------------------------------------+
  744. | OptionsFileLog()
  745. |
  746. +-------------------------------------------------------------------------+*/
  747. void OptionsFileLog() {
  748. LogWriteLog(0, Lids(IDS_L_155));
  749. if (FileOptions->TransferFileInfo)
  750. LogWriteLog(1, Lids(IDS_L_156), Lids(IDS_YES));
  751. else
  752. LogWriteLog(1, Lids(IDS_L_156), Lids(IDS_NO));
  753. LogWriteLog(0, Lids(IDS_CRLF));
  754. } // OptionsFileLog
  755. /*+-------------------------------------------------------------------------+
  756. | ConvertPairLog()
  757. |
  758. +-------------------------------------------------------------------------+*/
  759. void ConvertPairLog() {
  760. LogWriteLog(0, Lids(IDS_LINE));
  761. wsprintf(tmpStr, Lids(IDS_L_157), SourceServer);
  762. LogWriteLog(0, Lids(IDS_BRACE), tmpStr);
  763. wsprintf(tmpStr, Lids(IDS_L_158), DestServer);
  764. LogWriteLog(0, Lids(IDS_BRACE), tmpStr);
  765. LogWriteLog(0, Lids(IDS_LINE));
  766. GetTime(tmpStr2);
  767. wsprintf(tmpStr, Lids(IDS_L_159), tmpStr2);
  768. LogWriteLog(0, Lids(IDS_BRACE), tmpStr);
  769. LogWriteLog(0, Lids(IDS_LINE));
  770. LogWriteLog(0, Lids(IDS_CRLF));
  771. LogWriteSummary(0, Lids(IDS_CRLF));
  772. LogWriteSummary(0, TEXT("[%s -> %s]\r\n"), SourceServer, DestServer);
  773. ErrorContextSet(TEXT("[%s -> %s]\r\n"), SourceServer, DestServer);
  774. } // ConvertPairLog
  775. /*+-------------------------------------------------------------------------+
  776. | UsersLogNames()
  777. |
  778. +-------------------------------------------------------------------------+*/
  779. void UsersLogNames(USER_LIST *Users) {
  780. ULONG i;
  781. DWORD UserCount;
  782. USER_BUFFER *UserBuffer;
  783. if (Users == NULL)
  784. return;
  785. UserCount = Users->Count;
  786. UserBuffer = Users->UserBuffer;
  787. if (UserCount) {
  788. LogWriteLog(1, Lids(IDS_L_160));
  789. LogWriteLog(1, Lids(IDS_L_161));
  790. // Check Mapping File
  791. for (i = 0; i < UserCount; i++) {
  792. if (UserBuffer[i].IsNewName)
  793. wsprintf(pLine, TEXT("%s -> %s"), UserBuffer[i].Name, UserBuffer[i].NewName);
  794. else
  795. wsprintf(pLine, TEXT("%s"), UserBuffer[i].NewName);
  796. LogWriteLog(1, TEXT(" %-50s"), pLine);
  797. if (UserBuffer[i].err) {
  798. if (UserBuffer[i].err == NWC_ERR_NAMELONG)
  799. LogWriteLog(0, Lids(IDS_L_162));
  800. if (UserBuffer[i].err == NWC_ERR_DUPLICATE)
  801. LogWriteLog(0, Lids(IDS_L_163));
  802. if (UserBuffer[i].err == NWC_ERR_NAMEINVALID)
  803. LogWriteLog(0, Lids(IDS_L_164));
  804. }
  805. // Need to check this seperatly - as it's not an error
  806. if (UserBuffer[i].Overwrite)
  807. LogWriteLog(0, Lids(IDS_L_163));
  808. LogWriteLog(0, Lids(IDS_CRLF));
  809. }
  810. LogWriteLog(0, Lids(IDS_CRLF));
  811. }
  812. } // UsersLogNames
  813. /*+-------------------------------------------------------------------------+
  814. | UserNewName_Check()
  815. |
  816. +-------------------------------------------------------------------------+*/
  817. void UserNewName_Check(USER_BUFFER *Users) {
  818. // We have done any mappings that need to be done, now check for
  819. // name validity if there is a new name...
  820. if (Users->IsNewName)
  821. if (UserCacheMatch(Users->NewName)) {
  822. Users->err = NWC_ERR_DUPLICATE;
  823. }
  824. if (lstrlen(Users->NewName) > MAX_NT_USER_NAME_LEN) {
  825. // Name is too long
  826. Users->err = NWC_ERR_NAMELONG;
  827. }
  828. // Check if a valid name (no illegal characters)...
  829. if ((int) wcscspn(Users->NewName, ILLEGAL_CHARS) < (int) lstrlen(Users->NewName))
  830. Users->err = NWC_ERR_NAMEINVALID;
  831. } // UserNewName_Check
  832. /*+-------------------------------------------------------------------------+
  833. | UserNames_Resolve()
  834. |
  835. +-------------------------------------------------------------------------+*/
  836. void UserNames_Resolve(USER_BUFFER *Users) {
  837. LPTSTR TheName;
  838. LPTSTR ErrorText;
  839. ULONG RetType;
  840. // Figure out which name to use
  841. if (Users->IsNewName)
  842. TheName = Users->Name;
  843. else
  844. TheName = Users->NewName;
  845. // If using mapping file then map the name appropriatly
  846. if (ConvOpt->UseMappingFile) {
  847. if (UserCacheMatch(TheName))
  848. Users->err = NWC_ERR_DUPLICATE;
  849. } else {
  850. // check if the user name is in the destination list (duplicate)
  851. if (UserCacheMatch(TheName)) {
  852. // There was - so figure out based on conversion options what
  853. // to do with it...
  854. switch (ConvOpt->UserNameOption) {
  855. case 0: // Log Errors
  856. Users->err = NWC_ERR_DUPLICATE;
  857. break;
  858. case 1: // ignore
  859. Users->err = NWC_ERR_IGNORE;
  860. break;
  861. case 2: // Overwrite
  862. Users->Overwrite = TRUE;
  863. break;
  864. case 3: // Pre-Pend constant
  865. lstrcpy(NewName, ConvOpt->UserConstant);
  866. lstrcat(NewName, Users->Name);
  867. lstrcpy(Users->NewName, NewName);
  868. Users->IsNewName = TRUE;
  869. break;
  870. } // switch
  871. }
  872. }
  873. do {
  874. RetType = IDIGNORE;
  875. UserNewName_Check(Users);
  876. if (Users->err && (Users->err != NWC_ERR_IGNORE) && PopupOnError()) {
  877. switch(Users->err) {
  878. case NWC_ERR_NAMELONG:
  879. ErrorText = Lids(IDS_L_165);
  880. break;
  881. case NWC_ERR_DUPLICATE:
  882. ErrorText = Lids(IDS_L_166);
  883. break;
  884. case NWC_ERR_NAMEINVALID:
  885. ErrorText = Lids(IDS_L_167);
  886. break;
  887. }
  888. RetType = UserNameErrorDlg_Do(Lids(IDS_L_168), ErrorText, Users);
  889. }
  890. } while (RetType == IDRETRY);
  891. if (RetType == IDABORT)
  892. TransferCancel = TRUE;
  893. } // UserNames_Resolve
  894. /*+-------------------------------------------------------------------------+
  895. | UserSave()
  896. |
  897. | Given a user-name, moves their account information from the source
  898. | to the destination server.
  899. |
  900. +-------------------------------------------------------------------------+*/
  901. BOOL UserSave(BOOL *NWInfo, LPTSTR origUserName, LPTSTR newUserName, NT_USER_INFO *NTInfo, void **OldInfo, BOOL Replace) {
  902. NET_API_STATUS ret = 0;
  903. void *NWUInfo;
  904. FPNW_INFO fpnw;
  905. static TCHAR ServerName[MAX_SERVER_NAME_LEN+3]; // +3 for leading slashes and ending NULL
  906. *NWInfo = FALSE;
  907. // Overlay NetWare info into record
  908. NWUserInfoGet(origUserName, OldInfo);
  909. NWUInfo = *OldInfo;
  910. if (NWUInfo == NULL)
  911. return FALSE;
  912. *NWInfo = TRUE;
  913. NWNetUserMapInfo(origUserName, NWUInfo, NTInfo);
  914. // Force user to change password if required
  915. if (ConvOpt->ForcePasswordChange)
  916. NTInfo->password_expired = (DWORD) (-1L);
  917. // Now get/map special FPNW info
  918. if (ConvOpt->NetWareInfo) {
  919. NWFPNWMapInfo(NWUInfo, &fpnw);
  920. }
  921. if (!TConversion)
  922. if (Replace)
  923. if (ConvOpt->NetWareInfo)
  924. ret = NTUserInfoSet(NTInfo, &fpnw);
  925. else
  926. ret = NTUserInfoSet(NTInfo, NULL);
  927. else
  928. if (ConvOpt->NetWareInfo)
  929. ret = NTUserInfoSave(NTInfo, &fpnw);
  930. else
  931. ret = NTUserInfoSave(NTInfo, NULL);
  932. if (ret)
  933. return FALSE;
  934. else {
  935. // now save out FPNW Info
  936. if (ConvOpt->NetWareInfo)
  937. NTSAMParmsSet(newUserName, fpnw, NTInfo->password, ConvOpt->ForcePasswordChange);
  938. return TRUE;
  939. }
  940. } // UserSave
  941. /*+-------------------------------------------------------------------------+
  942. | UsersConvert()
  943. |
  944. +-------------------------------------------------------------------------+*/
  945. void UsersConvert() {
  946. static TCHAR Password[MAX_PW_LEN + 1];
  947. USER_BUFFER *UserBuffer = NULL;
  948. BOOL NWInfo;
  949. DWORD status = 0;
  950. DWORD i;
  951. void *NW_UInfo;
  952. static NT_USER_INFO NT_UInfo;
  953. ULONG TotConv = 0;
  954. Status_ConvTxt(Lids(IDS_D_18));
  955. Status_ItemLabel(Lids(IDS_D_19));
  956. Status_CurTot((UINT) UserCount);
  957. LogWriteLog(0, Lids(IDS_L_169));
  958. LogWriteLog(1, Lids(IDS_L_170), UserCount);
  959. ErrorCategorySet(Lids(IDS_L_171));
  960. if (Users == NULL)
  961. return;
  962. UserBuffer = Users->UserBuffer;
  963. // This will update the status pane - but we will reset it afterwards
  964. for (i = 0; i < UserCount; i++) {
  965. // Don't update totals yet, but update item ref incase this takes
  966. // awhile
  967. Status_CurNum((UINT) i + 1);
  968. Status_Item(UserBuffer[i].Name);
  969. UserNames_Resolve(&UserBuffer[i]);
  970. if (TransferCancel)
  971. return;
  972. }
  973. UsersLogNames(Users);
  974. i = 0;
  975. while (i < UserCount) {
  976. Status_CurNum((UINT) i + 1);
  977. Status_Item(UserBuffer[i].Name);
  978. lstrcpy(pLine, UserBuffer[i].Name);
  979. if (UserBuffer[i].IsNewName)
  980. wsprintf(pLine, TEXT("[%s -> %s]"), UserBuffer[i].Name, UserBuffer[i].NewName);
  981. else
  982. wsprintf(pLine, TEXT("[%s]"), UserBuffer[i].NewName);
  983. LogWriteLog(1, TEXT("%-50s"), pLine);
  984. ErrorItemSet(TEXT("%s\r\n"), pLine);
  985. // If duplicate or other type error just do logging - don't try to save
  986. if (UserBuffer[i].err) {
  987. if (UserBuffer[i].err == NWC_ERR_DUPLICATE) {
  988. LogWriteLog(0, Lids(IDS_L_172));
  989. ErrorIt(Lids(IDS_L_173));
  990. }
  991. if (UserBuffer[i].err == NWC_ERR_NAMELONG) {
  992. LogWriteLog(0, Lids(IDS_L_174));
  993. ErrorIt(Lids(IDS_L_175));
  994. }
  995. if (UserBuffer[i].err == NWC_ERR_NAMEINVALID) {
  996. LogWriteLog(0, Lids(IDS_L_176));
  997. ErrorIt(Lids(IDS_L_177));
  998. }
  999. } else {
  1000. // Init the user record
  1001. NTUserRecInit(UserBuffer[i].NewName, &NT_UInfo);
  1002. // +-------------------------------------------------------------+
  1003. // | User name figured out - now map password |
  1004. // +-------------------------------------------------------------+
  1005. memset(Password, 0, sizeof(Password));
  1006. if (ConvOpt->UseMappingFile)
  1007. // If using map file, password is already set
  1008. lstrcpy(Password, UserBuffer[i].Password);
  1009. else
  1010. if (lstrlen(Password) == 0) {
  1011. // Didn't map password - so find what to use
  1012. switch (ConvOpt->PasswordOption) {
  1013. case 0: // No Password
  1014. // Don't need to do anything
  1015. break;
  1016. case 1: // Username
  1017. // BUGBUG: Name can be longer then password!!!
  1018. lstrcpy(Password, UserBuffer[i].NewName);
  1019. break;
  1020. case 2: // Constant
  1021. lstrcpy(Password, ConvOpt->PasswordConstant);
  1022. break;
  1023. } // switch
  1024. }
  1025. NT_UInfo.password = Password;
  1026. #ifdef DEBUG
  1027. dprintf(TEXT("User: %s\n"), UserBuffer[i].Name);
  1028. #endif
  1029. if (!UserSave(&NWInfo, UserBuffer[i].Name, UserBuffer[i].NewName, &NT_UInfo, &NW_UInfo, UserBuffer[i].Overwrite )) {
  1030. LogWriteLog(0, Lids(IDS_L_178));
  1031. ErrorIt(Lids(IDS_L_179));
  1032. } else {
  1033. // only increment total if actually converted...
  1034. TotUsers++;
  1035. TotConv++;
  1036. Status_TotUsers(TotUsers);
  1037. LogWriteLog(0, Lids(IDS_L_180));
  1038. LogWriteLog(0, Lids(IDS_CRLF));
  1039. // Converted - now need to save info to logs...
  1040. if (NWInfo) {
  1041. if (VerboseUserLogging())
  1042. NWUserInfoLog(UserBuffer[i].Name, NW_UInfo);
  1043. if (VerboseUserLogging())
  1044. NTUserRecLog(NT_UInfo);
  1045. }
  1046. }
  1047. LogWriteLog(0, Lids(IDS_CRLF));
  1048. }
  1049. i++;
  1050. }
  1051. LogWriteLog(0, Lids(IDS_CRLF));
  1052. LogWriteSummary(1, Lids(IDS_L_181), lToStr(TotConv));
  1053. } // UsersConvert
  1054. /*+-------------------------------------------------------------------------+
  1055. | GroupSave()
  1056. |
  1057. +-------------------------------------------------------------------------+*/
  1058. BOOL GroupSave(LPTSTR Name, DWORD *Status) {
  1059. *Status = 0;
  1060. if (!TConversion)
  1061. if ((*Status = NTGroupSave(Name)))
  1062. return FALSE;
  1063. return TRUE;
  1064. } // GroupSave
  1065. /*+-------------------------------------------------------------------------+
  1066. | GroupNewName_Check()
  1067. |
  1068. +-------------------------------------------------------------------------+*/
  1069. void GroupNewName_Check(GROUP_BUFFER *Groups) {
  1070. // We have done any mappings that need to be done, now check for
  1071. // name validity if there is a new name...
  1072. if (Groups->IsNewName)
  1073. if (GroupCacheMatch(Groups->NewName)) {
  1074. Groups->err = NWC_ERR_DUPLICATE;
  1075. }
  1076. // make sure not too long
  1077. if (lstrlen(Groups->NewName) > MAX_NT_GROUP_NAME_LEN) {
  1078. // Name is too long
  1079. Groups->err = NWC_ERR_NAMELONG;
  1080. }
  1081. // Check if a valid name (no illegal characters)...
  1082. if ((int) wcscspn(Groups->NewName, ILLEGAL_CHARS) < (int) lstrlen(Groups->NewName))
  1083. Groups->err = NWC_ERR_NAMEINVALID;
  1084. } // GroupNewName_Check
  1085. /*+-------------------------------------------------------------------------+
  1086. | GroupNames_Resolve()
  1087. |
  1088. +-------------------------------------------------------------------------+*/
  1089. void GroupNames_Resolve(GROUP_BUFFER *Groups) {
  1090. LPTSTR TheName;
  1091. LPTSTR ErrorText;
  1092. ULONG RetType;
  1093. // Figure out which name to use
  1094. if (Groups->IsNewName)
  1095. TheName = Groups->Name;
  1096. else
  1097. TheName = Groups->NewName;
  1098. // If using mapping file then map the name appropriatly
  1099. if (ConvOpt->UseMappingFile) {
  1100. if (GroupCacheMatch(TheName))
  1101. Groups->err = NWC_ERR_DUPLICATE;
  1102. } else {
  1103. // check if the user name is in the destination list (duplicate)
  1104. if (GroupCacheMatch(TheName)) {
  1105. // There was - so figure out based on conversion options what
  1106. // to do with it...
  1107. switch (ConvOpt->GroupNameOption) {
  1108. case 0: // Log Errors
  1109. Groups->err = NWC_ERR_DUPLICATE;
  1110. break;
  1111. case 1: // ignore
  1112. Groups->err = NWC_ERR_IGNORE;
  1113. break;
  1114. case 2: // Pre-Pend constant
  1115. lstrcpy(NewName, ConvOpt->GroupConstant);
  1116. lstrcat(NewName, Groups->Name);
  1117. lstrcpy(Groups->NewName, NewName);
  1118. Groups->IsNewName = TRUE;
  1119. break;
  1120. } // switch
  1121. }
  1122. }
  1123. do {
  1124. RetType = IDIGNORE;
  1125. GroupNewName_Check(Groups);
  1126. if (Groups->err && (Groups->err != NWC_ERR_IGNORE) && PopupOnError()) {
  1127. switch(Groups->err) {
  1128. case NWC_ERR_NAMELONG:
  1129. ErrorText = Lids(IDS_L_182);
  1130. break;
  1131. case NWC_ERR_DUPLICATE:
  1132. ErrorText = Lids(IDS_L_183);
  1133. break;
  1134. case NWC_ERR_NAMEINVALID:
  1135. ErrorText = Lids(IDS_L_184);
  1136. break;
  1137. }
  1138. RetType = GroupNameErrorDlg_Do(Lids(IDS_L_185), ErrorText, Groups);
  1139. }
  1140. } while (RetType == IDRETRY);
  1141. if (RetType == IDABORT)
  1142. TransferCancel = TRUE;
  1143. } // GroupNames_Resolve
  1144. /*+-------------------------------------------------------------------------+
  1145. | GroupsConvert()
  1146. |
  1147. +-------------------------------------------------------------------------+*/
  1148. void GroupsConvert() {
  1149. USER_LIST *GUsers = NULL;
  1150. USER_BUFFER *GUserBuffer;
  1151. USER_BUFFER *pUser;
  1152. GROUP_BUFFER *pGroup;
  1153. GROUP_BUFFER *GroupBuffer = NULL;
  1154. DWORD GUserCount;
  1155. DWORD status = 0;
  1156. ULONG Count, i;
  1157. ULONG TotConv = 0;
  1158. LPTSTR NewName;
  1159. BOOL SecEquivTitle = FALSE;
  1160. BOOL SecEquivUser = FALSE;
  1161. TCHAR GroupTitle[TMP_STR_LEN_256];
  1162. // update status pane
  1163. Status_ConvTxt(Lids(IDS_D_20));
  1164. Status_ItemLabel(Lids(IDS_D_21));
  1165. ErrorCategorySet(Lids(IDS_L_186));
  1166. Status_CurTot((UINT) GroupCount);
  1167. LogWriteLog(0, Lids(IDS_L_187));
  1168. LogWriteLog(1, Lids(IDS_L_188), GroupCount);
  1169. if (Groups == NULL)
  1170. return;
  1171. GroupBuffer = Groups->GroupBuffer;
  1172. for (i = 0; i < GroupCount; i++) {
  1173. // Don't update totals yet, but update item ref incase this takes
  1174. // awhile
  1175. Status_CurNum((UINT) i + 1);
  1176. Status_Item(GroupBuffer[i].Name);
  1177. GroupNames_Resolve(&GroupBuffer[i]);
  1178. if (TransferCancel)
  1179. return;
  1180. }
  1181. i = 0;
  1182. while (i < GroupCount) {
  1183. // update status pane for this group
  1184. Status_CurNum((UINT) i + 1);
  1185. Status_Item(GroupBuffer[i].Name);
  1186. lstrcpy(pLine, GroupBuffer[i].Name);
  1187. #ifdef DEBUG
  1188. dprintf(TEXT("Working on Group: %s\r\n"), GroupBuffer[i].Name);
  1189. #endif
  1190. if (GroupBuffer[i].IsNewName)
  1191. wsprintf(pLine, TEXT("%s -> %s"), GroupBuffer[i].Name, GroupBuffer[i].NewName);
  1192. else
  1193. wsprintf(pLine, TEXT("%s"), GroupBuffer[i].NewName);
  1194. LogWriteLog(1, TEXT("%-50s"), pLine);
  1195. ErrorItemSet(TEXT("[%s]\r\n"), pLine);
  1196. // If duplicate or other type error just do logging - don't try
  1197. // to save...
  1198. if (GroupBuffer[i].err) {
  1199. if (GroupBuffer[i].err == NWC_ERR_DUPLICATE) {
  1200. LogWriteLog(0, Lids(IDS_L_163));
  1201. ErrorIt(Lids(IDS_L_189));
  1202. }
  1203. if (GroupBuffer[i].err == NWC_ERR_NAMELONG) {
  1204. LogWriteLog(0, Lids(IDS_L_162));
  1205. ErrorIt(Lids(IDS_L_190));
  1206. }
  1207. if (GroupBuffer[i].err == NWC_ERR_NAMEINVALID) {
  1208. LogWriteLog(0, Lids(IDS_L_164));
  1209. ErrorIt(Lids(IDS_L_191));
  1210. }
  1211. } else {
  1212. // Try to save it and get any errors...
  1213. if (!GroupSave(GroupBuffer[i].NewName, &status)) {
  1214. LogWriteLog(0, Lids(IDS_L_192));
  1215. ErrorIt(Lids(IDS_L_193));
  1216. } else {
  1217. // only increment total if actually converted...
  1218. TotGroups++;
  1219. TotConv++;
  1220. Status_TotGroups(TotGroups);
  1221. LogWriteLog(0, Lids(IDS_L_180));
  1222. }
  1223. }
  1224. LogWriteLog(0, Lids(IDS_CRLF));
  1225. i++;
  1226. }
  1227. LogWriteLog(0, Lids(IDS_CRLF));
  1228. ErrorCategorySet(Lids(IDS_L_194));
  1229. // +-------------------------------------------------------------+
  1230. // | Go through and add users to the groups |
  1231. // +-------------------------------------------------------------+
  1232. for (Count = 0; Count < GroupCount; Count++) {
  1233. GUserCount = 0;
  1234. if (!(status = NWGroupUsersEnum(GroupBuffer[Count].Name, &GUsers)) && (GUsers != NULL)) {
  1235. GUserCount = GUsers->Count;
  1236. GUserBuffer = GUsers->UserBuffer;
  1237. if (GUserCount > 0) {
  1238. wsprintf(GroupTitle, Lids(IDS_S_46), GroupBuffer[Count].NewName);
  1239. EscapeFormattingChars(GroupTitle,
  1240. sizeof(GroupTitle)/sizeof(GroupTitle[0])) ;
  1241. Status_ItemLabel(GroupTitle);
  1242. LogWriteLog(1, TEXT("[%s]\r\n"), GroupBuffer[Count].NewName);
  1243. }
  1244. for (i = 0; i < GUserCount; i++) {
  1245. pUser = FindUserMatch(GUserBuffer[i].Name, Users, FALSE);
  1246. if (pUser == NULL)
  1247. NewName = NWSpecialNamesMap(GUserBuffer[i].Name);
  1248. else
  1249. NewName = pUser->NewName;
  1250. LogWriteLog(2, TEXT("%-20s"), NewName);
  1251. Status_Item(NewName);
  1252. #ifdef DEBUG
  1253. dprintf(TEXT("Adding User [%s] to Group: %s\n"), NewName, GroupBuffer[Count].NewName );
  1254. #endif
  1255. if (!TConversion)
  1256. if (NTGroupUserAdd(GroupBuffer[Count].NewName, NewName, FALSE)) {
  1257. LogWriteLog(0, Lids(IDS_L_196));
  1258. ErrorIt(Lids(IDS_L_195), NewName, GroupBuffer[Count].NewName);
  1259. }
  1260. LogWriteLog(0, Lids(IDS_CRLF));
  1261. }
  1262. LogWriteLog(0, Lids(IDS_CRLF));
  1263. FreeMemory((LPBYTE) GUsers);
  1264. } else {
  1265. LogWriteLog(1, Lids(IDS_L_197), GroupBuffer[Count].Name);
  1266. ErrorIt(Lids(IDS_L_197), GroupBuffer[Count].Name);
  1267. }
  1268. } // loop adding users to groups
  1269. ErrorCategorySet(Lids(IDS_L_198));
  1270. // +-------------------------------------------------------------+
  1271. // | Convert Security Equivalences to Group Names |
  1272. // +-------------------------------------------------------------+
  1273. SecEquivTitle = FALSE;
  1274. for (Count = 0; Count < UserCount; Count++) {
  1275. GUserCount = 0;
  1276. SecEquivUser = FALSE;
  1277. if (!(status = NWUserEquivalenceEnum(Users->UserBuffer[Count].Name, &GUsers)) && (GUsers != NULL)) {
  1278. GUserCount = GUsers->Count;
  1279. GUserBuffer = GUsers->UserBuffer;
  1280. if (GUserCount > 0) {
  1281. for (i = 0; i < GUserCount; i++) {
  1282. pGroup = FindGroupMatch(GUserBuffer[i].Name, Groups, FALSE);
  1283. if (pGroup != NULL) {
  1284. if ((pGroup->err != NWC_ERR_NAMELONG) && (pGroup->err != NWC_ERR_NAMEINVALID))
  1285. if (!SecEquivTitle) {
  1286. SecEquivTitle = TRUE;
  1287. LogWriteLog(0, Lids(IDS_CRLF));
  1288. LogWriteLog(0, Lids(IDS_L_199));
  1289. }
  1290. if (!SecEquivUser) {
  1291. SecEquivUser = TRUE;
  1292. wsprintf(GroupTitle, Lids(IDS_S_47), Users->UserBuffer[Count].NewName);
  1293. EscapeFormattingChars(GroupTitle,
  1294. sizeof(GroupTitle)/sizeof(GroupTitle[0])) ;
  1295. Status_ItemLabel(GroupTitle);
  1296. LogWriteLog(1, TEXT("[%s]\r\n"), Users->UserBuffer[Count].NewName);
  1297. }
  1298. LogWriteLog(2, TEXT("%-20s"), pGroup->NewName);
  1299. Status_Item(pGroup->NewName);
  1300. #ifdef DEBUG
  1301. dprintf(TEXT("User [%s] Security Equivalence: %s\n"), Users->UserBuffer[Count].NewName, pGroup->NewName );
  1302. #endif
  1303. if (!TConversion)
  1304. if (NTGroupUserAdd(pGroup->NewName, Users->UserBuffer[Count].NewName, FALSE)) {
  1305. LogWriteLog(0, Lids(IDS_L_196));
  1306. ErrorIt(Lids(IDS_L_195), Users->UserBuffer[Count].NewName, pGroup->NewName);
  1307. }
  1308. LogWriteLog(0, Lids(IDS_CRLF));
  1309. } else {
  1310. // There was not a group match - check if this is supervisor
  1311. // equivalence
  1312. if (!lstrcmpi(GUserBuffer[i].Name, Lids(IDS_S_28))) {
  1313. // Check if we should add them
  1314. if (ConvOpt->AdminAccounts) {
  1315. if (!SecEquivTitle) {
  1316. SecEquivTitle = TRUE;
  1317. LogWriteLog(0, Lids(IDS_CRLF));
  1318. LogWriteLog(0, Lids(IDS_L_199));
  1319. }
  1320. if (!SecEquivUser) {
  1321. SecEquivUser = TRUE;
  1322. LogWriteLog(1, TEXT("[%s]\r\n"), Users->UserBuffer[Count].NewName);
  1323. }
  1324. LogWriteLog(2, TEXT("%-20s"), Lids(IDS_S_42));
  1325. if (!TConversion)
  1326. if (NTGroupUserAdd(Lids(IDS_S_42), Users->UserBuffer[Count].NewName, FALSE)) {
  1327. LogWriteLog(0, Lids(IDS_L_196));
  1328. ErrorIt(Lids(IDS_L_195), Users->UserBuffer[Count].NewName, Lids(IDS_S_42));
  1329. }
  1330. LogWriteLog(0, Lids(IDS_CRLF));
  1331. }
  1332. }
  1333. }
  1334. }
  1335. // Only put blank line if we logged this user
  1336. if (SecEquivUser)
  1337. LogWriteLog(0, Lids(IDS_CRLF));
  1338. }
  1339. FreeMemory((LPBYTE) GUsers);
  1340. }
  1341. } // Loop converting security equivalences
  1342. // Synchronize the domain - we need to synch as Print Operators are a
  1343. // local group
  1344. NTDomainSynch(CurrentConvertList->FileServ);
  1345. // Now set server to appropriate dest server (local group - so must
  1346. // be on dest server and not PDC or trusted domain)...
  1347. if ((status = NTServerSet(CurrentConvertList->FileServ->Name))) {
  1348. // Failed to set server so log it and loop to next server
  1349. LogWriteLog(0, Lids(IDS_L_209), CurrentConvertList->FileServ->Name);
  1350. ErrorIt(Lids(IDS_L_209), CurrentConvertList->FileServ->Name);
  1351. return;
  1352. }
  1353. ErrorCategorySet(Lids(IDS_L_200));
  1354. // +-------------------------------------------------------------+
  1355. // | Do Print Operators |
  1356. // +-------------------------------------------------------------+
  1357. SecEquivTitle = FALSE;
  1358. if (!(status = NWPrintOpsEnum(&GUsers)) && (GUsers != NULL)) {
  1359. GUserCount = GUsers->Count;
  1360. GUserBuffer = GUsers->UserBuffer;
  1361. if (GUserCount > 0) {
  1362. for (i = 0; i < GUserCount; i++) {
  1363. if (!SecEquivTitle) {
  1364. SecEquivTitle = TRUE;
  1365. LogWriteLog(0, Lids(IDS_CRLF));
  1366. LogWriteLog(0, Lids(IDS_L_201));
  1367. }
  1368. pUser = FindUserMatch(GUserBuffer[i].Name, Users, FALSE);
  1369. if ((pUser == NULL) || ((pUser->err != NWC_ERR_NAMELONG) && (pUser->err != NWC_ERR_NAMEINVALID))) {
  1370. if (pUser == NULL)
  1371. NewName = NWSpecialNamesMap(GUserBuffer[i].Name);
  1372. else
  1373. NewName = pUser->NewName;
  1374. LogWriteLog(2, TEXT("%-20s"), NewName);
  1375. #ifdef DEBUG
  1376. dprintf(TEXT("Adding User [%s] to Group: %s\n"), NewName, Lids(IDS_S_43) );
  1377. #endif
  1378. if (!TConversion)
  1379. if (NTGroupUserAdd(Lids(IDS_S_43), NewName, TRUE)) {
  1380. LogWriteLog(0, Lids(IDS_L_196));
  1381. ErrorIt(Lids(IDS_L_195), NewName, Lids(IDS_S_43));
  1382. }
  1383. LogWriteLog(0, Lids(IDS_CRLF));
  1384. }
  1385. }
  1386. }
  1387. }
  1388. LogWriteSummary(1, Lids(IDS_L_202), lToStr(TotConv));
  1389. } // GroupsConvert
  1390. /*+-------------------------------------------------------------------------+
  1391. | SupervisorDefaultsConvert()
  1392. |
  1393. +-------------------------------------------------------------------------+*/
  1394. void SupervisorDefaultsConvert(TRANSFER_LIST *tl) {
  1395. ULONG i;
  1396. void *Defaults;
  1397. BOOL ConvertDefaults = FALSE;
  1398. NT_DEFAULTS *NTDefaults = NULL;
  1399. NT_DEFAULTS CDefaults;
  1400. DEST_SERVER_BUFFER *oDServ = NULL;
  1401. TRANSFER_BUFFER *TList;
  1402. CONVERT_OPTIONS *ConvOpt;
  1403. if (tl == NULL)
  1404. return;
  1405. TList = tl->TList;
  1406. memset(&CDefaults, 0, sizeof(CDefaults));
  1407. LogWriteLog(0, Lids(IDS_LINE));
  1408. LogWriteLog(0, Lids(IDS_BRACE), Lids(IDS_L_203));
  1409. LogWriteLog(0, Lids(IDS_LINE));
  1410. // Loop through the server pairs for conversion - this is sorted in order of
  1411. // destination users servers.
  1412. for (i = 0; i < tl->Count; i++) {
  1413. CurrentConvertList = TList[i].ConvertList;
  1414. ConvOpt = (CONVERT_OPTIONS *) CurrentConvertList->ConvertOptions;
  1415. if (CurrentConvertList->FileServ != oDServ) {
  1416. // if this is not the first time through the loop, then we need to save
  1417. // off the converted defaults
  1418. if (ConvertDefaults && (oDServ != NULL)) {
  1419. ConvertDefaults = FALSE;
  1420. LogWriteLog(0, Lids(IDS_L_204), oDServ->Name);
  1421. if (NTDefaults != NULL) {
  1422. NTUserDefaultsLog(*NTDefaults);
  1423. if (!TConversion)
  1424. NTUserDefaultsSet(*NTDefaults);
  1425. }
  1426. }
  1427. oDServ = CurrentConvertList->FileServ;
  1428. // Point to dest server and get defaults
  1429. NTServerSet(CurrentConvertList->FileServ->Name);
  1430. NTUserDefaultsGet(&NTDefaults);
  1431. memset(&CDefaults, 0, sizeof(CDefaults));
  1432. if (NTDefaults != NULL)
  1433. memcpy(&CDefaults, NTDefaults, sizeof(CDefaults));
  1434. }
  1435. // Supervisor defaults
  1436. if (ConvOpt->SupervisorDefaults) {
  1437. // if not flagged for this dest server, then flag and write out original
  1438. // values
  1439. if (!ConvertDefaults) {
  1440. ConvertDefaults = TRUE;
  1441. if (NTDefaults != NULL) {
  1442. LogWriteLog(0, Lids(IDS_L_205), CurrentConvertList->FileServ->Name);
  1443. NTUserDefaultsLog(*NTDefaults);
  1444. }
  1445. }
  1446. NWServerSet(CurrentConvertList->SourceServ->Name);
  1447. NWUserDefaultsGet(&Defaults);
  1448. if (Defaults != NULL) {
  1449. LogWriteLog(0, Lids(IDS_L_206), CurrentConvertList->SourceServ->Name);
  1450. NWUserDefaultsLog(Defaults);
  1451. NWUserDefaultsMap(Defaults, &CDefaults);
  1452. // Now map in least restrictive values to the NT one
  1453. if (NTDefaults != NULL) {
  1454. if (CDefaults.min_passwd_len < NTDefaults->min_passwd_len)
  1455. NTDefaults->min_passwd_len = CDefaults.min_passwd_len;
  1456. if (CDefaults.max_passwd_age < NTDefaults->max_passwd_age)
  1457. NTDefaults->max_passwd_age = CDefaults.max_passwd_age;
  1458. if (CDefaults.force_logoff < NTDefaults->force_logoff)
  1459. NTDefaults->force_logoff = CDefaults.force_logoff;
  1460. }
  1461. FreeMemory(Defaults);
  1462. Defaults = NULL;
  1463. }
  1464. }
  1465. }
  1466. // Need to catch the last one through the loop
  1467. if (ConvertDefaults && (oDServ != NULL)) {
  1468. ConvertDefaults = FALSE;
  1469. LogWriteLog(0, Lids(IDS_L_204), oDServ->Name);
  1470. if (NTDefaults != NULL) {
  1471. NTUserDefaultsLog(*NTDefaults);
  1472. if (!TConversion)
  1473. NTUserDefaultsSet(*NTDefaults);
  1474. }
  1475. }
  1476. } // SupervisorDefaultsConvert
  1477. /*+-------------------------------------------------------------------------+
  1478. | TransferListCompare()
  1479. |
  1480. +-------------------------------------------------------------------------+*/
  1481. int __cdecl TransferListCompare(const void *arg1, const void *arg2) {
  1482. TRANSFER_BUFFER *TBarg1, *TBarg2;
  1483. TBarg1 = (TRANSFER_BUFFER *) arg1;
  1484. TBarg2 = (TRANSFER_BUFFER *) arg2;
  1485. return lstrcmpi( TBarg1->ServerName, TBarg2->ServerName);
  1486. } // TransferListCompare
  1487. /*+-------------------------------------------------------------------------+
  1488. | TransferListCreate()
  1489. |
  1490. +-------------------------------------------------------------------------+*/
  1491. TRANSFER_LIST *TransferListCreate() {
  1492. CONVERT_OPTIONS *ConvOpt;
  1493. static TRANSFER_LIST *tl;
  1494. TRANSFER_BUFFER *TList;
  1495. CONVERT_LIST *CList;
  1496. ULONG Count = 0;
  1497. tl = NULL;
  1498. CList = ConvertListStart;
  1499. while (CList != NULL) {
  1500. Count++;
  1501. CList = CList->next;
  1502. }
  1503. if (Count == 0)
  1504. return NULL;
  1505. tl = AllocMemory(sizeof(TRANSFER_LIST) + (sizeof(TRANSFER_BUFFER) * Count));
  1506. if (tl == NULL)
  1507. return NULL;
  1508. tl->Count = Count;
  1509. TList = tl->TList;
  1510. // init it all to NULL
  1511. memset(TList, 0, sizeof(TRANSFER_BUFFER) * Count);
  1512. Count = 0;
  1513. CList = ConvertListStart;
  1514. while (CList != NULL) {
  1515. TList[Count].ConvertList = CList;
  1516. // If going to a trusted domain then point to it's PDC for user transfers
  1517. ConvOpt = (CONVERT_OPTIONS *) CList->ConvertOptions;
  1518. if (ConvOpt->UseTrustedDomain && (ConvOpt->TrustedDomain != NULL) && (ConvOpt->TrustedDomain->PDCName != NULL)) {
  1519. TList[Count].UserServerType = USER_SERVER_TRUSTED;
  1520. TList[Count].ServerName = ConvOpt->TrustedDomain->PDCName;
  1521. } else
  1522. // If in a domain then point to the PDC for user transfers
  1523. if (CList->FileServ->InDomain && CList->FileServ->Domain) {
  1524. TList[Count].UserServerType = USER_SERVER_PDC;
  1525. TList[Count].ServerName = CList->FileServ->Domain->PDCName;
  1526. } else {
  1527. TList[Count].UserServerType = USER_SERVER;
  1528. TList[Count].ServerName = CList->FileServ->Name;
  1529. }
  1530. Count++;
  1531. CList = CList->next;
  1532. }
  1533. // Have setup the main transfer list - now need to sort it in order of the
  1534. // server names that users are being transfered to.
  1535. qsort((void *) TList, (size_t) tl->Count, sizeof(TRANSFER_BUFFER), TransferListCompare);
  1536. #ifdef DEBUG
  1537. dprintf(TEXT("\nTransfer List:\n"));
  1538. for (Count = 0; Count < tl->Count; Count++) {
  1539. dprintf(TEXT(" Name: %s "), TList[Count].ServerName);
  1540. switch (TList[Count].UserServerType) {
  1541. case USER_SERVER:
  1542. dprintf(TEXT("(Normal)\n"));
  1543. break;
  1544. case USER_SERVER_PDC:
  1545. dprintf(TEXT("(PDC)\n"));
  1546. break;
  1547. case USER_SERVER_TRUSTED:
  1548. dprintf(TEXT("(TRUSTED)\n"));
  1549. break;
  1550. }
  1551. }
  1552. dprintf(TEXT("\n"));
  1553. #endif
  1554. return tl;
  1555. } // TransferListCreate
  1556. /*+-------------------------------------------------------------------------+
  1557. | DoConversion()
  1558. |
  1559. | Main program that does the actuall conversion. Loops through the
  1560. | convert list and transfer the information.
  1561. |
  1562. +-------------------------------------------------------------------------+*/
  1563. void DoConversion(HWND hDlg, BOOL TrialConversion) {
  1564. TRANSFER_LIST *tl = NULL;
  1565. TRANSFER_BUFFER *TList;
  1566. LPTSTR oDServ = NULL;
  1567. DWORD status = 0;
  1568. UINT i;
  1569. BOOL GotUserList;
  1570. TCHAR sztime[40];
  1571. LPTSTR DomainName;
  1572. time(&StartTime);
  1573. TransferCancel = FALSE;
  1574. TConversion = TrialConversion;
  1575. // Check if going to non NTFS drives - if so, let user abort
  1576. NTFSCheck(hDlg);
  1577. if (TransferCancel)
  1578. return;
  1579. CursorHourGlass();
  1580. PanelDlg_Do(hDlg, Lids(IDS_D_22));
  1581. ConvertFilesInit(hDlg);
  1582. if (Panel_Cancel()) {
  1583. PanelDlgKill();
  1584. TransferCancel = TRUE;
  1585. CursorNormal();
  1586. return;
  1587. }
  1588. PanelDlgKill();
  1589. // Check if enough space on destination drives, if not allow user to abort
  1590. CursorNormal();
  1591. SpaceCheck(hDlg);
  1592. if (TransferCancel)
  1593. return;
  1594. CursorHourGlass();
  1595. tl = TransferListCreate();
  1596. TList = tl->TList;
  1597. DoStatusDlg(hDlg);
  1598. Status_TotConv((UINT) NumServerPairs);
  1599. Users = NULL;
  1600. NTUsers = NULL;
  1601. Groups = NULL;
  1602. NTGroups = NULL;
  1603. UserCount = 0;
  1604. NTUserCount = 0;
  1605. GroupCount = 0;
  1606. NTGroupCount= 0;
  1607. // Initialize global statistics
  1608. TotErrors = 0;
  1609. TotGroups = 0;
  1610. TotUsers = 0;
  1611. TotFiles = 0;
  1612. // Update statistics window
  1613. Status_TotComplete(0);
  1614. Status_TotGroups(TotGroups);
  1615. Status_TotUsers(TotUsers);
  1616. Status_TotFiles(TotFiles);
  1617. Status_TotErrors(TotErrors);
  1618. // Set up logs and do all the header stuff
  1619. LogInit();
  1620. if (TrialConversion) {
  1621. LogWriteLog(0, Lids(IDS_L_207));
  1622. } else {
  1623. LogWriteLog(0, Lids(IDS_L_208));
  1624. }
  1625. LogWriteSummary(0, Lids(IDS_CRLF));
  1626. LogWriteErr(Lids(IDS_CRLF));
  1627. LogWriteLog(0, Lids(IDS_CRLF));
  1628. // Log the list of servers to be converted
  1629. ErrorResetAll();
  1630. ConvertListLog();
  1631. // Loop through source servers and conglomerate defaults into dest servers
  1632. // and log the results
  1633. SupervisorDefaultsConvert(tl);
  1634. // +---------------------------------------------------------------------+
  1635. // | Done with init - loop through server pairs and do conversion |
  1636. // +---------------------------------------------------------------------+
  1637. // Get Local computer name
  1638. GetLocalName(&LocalName);
  1639. // Loop through the server pairs for conversion
  1640. for (i = 0; ((i < tl->Count) && !TransferCancel); i++) {
  1641. CurrentConvertList = TList[i].ConvertList;
  1642. // Get source and destination server - update logs and status window
  1643. Status_CurConv(i + 1);
  1644. SourceServer = CurrentConvertList->SourceServ->Name;
  1645. DestServer = CurrentConvertList->FileServ->Name;
  1646. Status_SrcServ(SourceServer);
  1647. Status_DestServ(DestServer);
  1648. // Log this server pair - section heading
  1649. ConvertPairLog();
  1650. // SetConvert options and log them out.
  1651. ConvOpt = (CONVERT_OPTIONS *) CurrentConvertList->ConvertOptions;
  1652. FileOptions = (FILE_OPTIONS *) CurrentConvertList->FileOptions;
  1653. ConvertOptionsLog();
  1654. OptionsFileLog();
  1655. // If our destination server has changed then update the caches
  1656. if (TList[i].ServerName != oDServ) {
  1657. oDServ = TList[i].ServerName;
  1658. GotUserList = TRUE;
  1659. ListCacheFree(&UserCacheHead);
  1660. ListCacheFree(&GroupCacheHead);
  1661. if ((status = NTServerSet(DestServer))) {
  1662. // Failed to set server so log it and loop to next server
  1663. LogWriteLog(0, Lids(IDS_L_209), DestServer);
  1664. ErrorIt(Lids(IDS_L_209), DestServer);
  1665. goto ConvDo_Loop;
  1666. }
  1667. // Put VShares here so it doesn't get lost in user info
  1668. if (FileOptions->TransferFileInfo)
  1669. VSharesCreate(CurrentConvertList->FileServ, TConversion);
  1670. // Get users on NT server and put in cache
  1671. if (status = NTUsersEnum(&NTUsers)) {
  1672. // Failed - make sure we don't try to convert users and log err
  1673. NTUsers = NULL;
  1674. NTUserCount = 0;
  1675. LogWriteLog(0, Lids(IDS_L_210), DestServer);
  1676. ErrorIt(Lids(IDS_L_210), DestServer);
  1677. GotUserList = FALSE;
  1678. } else
  1679. NTUserCount = NTUsers->Count;
  1680. if (!ListCachePut(&UserCacheHead, (void *) NTUsers, NTUserCount)) {
  1681. // Failed - but clean up NT List first
  1682. GotUserList = FALSE;
  1683. FreeMemory(NTUsers);
  1684. } else {
  1685. // Now get Groups (if users succeded) and put in group cache
  1686. if (status = NTGroupsEnum(&NTGroups)) {
  1687. // Failed - make sure we don't try to convert users and log err
  1688. NTGroupCount = 0;
  1689. NTGroups = NULL;
  1690. LogWriteLog(0, Lids(IDS_L_211), DestServer);
  1691. ErrorIt(Lids(IDS_L_211), DestServer);
  1692. FreeMemory(NTUsers);
  1693. GotUserList = FALSE;
  1694. } else
  1695. NTGroupCount = NTGroups->Count;
  1696. if (!ListCachePut(&GroupCacheHead, (void *) NTGroups, NTGroupCount)) {
  1697. // Failed - but clean up NT List first
  1698. GotUserList = FALSE;
  1699. FreeMemory(NTUsers);
  1700. FreeMemory(NTGroups);
  1701. }
  1702. }
  1703. }
  1704. wsprintf(UserServerName, TEXT("\\\\%s"), TList[i].ServerName);
  1705. if ((status = NTServerSet(TList[i].ServerName))) {
  1706. // Failed to set server so log it and loop to next server
  1707. LogWriteLog(0, Lids(IDS_L_209), TList[i].ServerName);
  1708. ErrorIt(Lids(IDS_L_209), TList[i].ServerName);
  1709. goto ConvDo_Loop;
  1710. }
  1711. if (ConvOpt->NetWareInfo) {
  1712. NTSAMClose();
  1713. if (ConvOpt->UseTrustedDomain && (ConvOpt->TrustedDomain != NULL))
  1714. DomainName = ConvOpt->TrustedDomain->Name;
  1715. else
  1716. if ((CurrentConvertList->FileServ->InDomain) && (CurrentConvertList->FileServ->Domain != NULL))
  1717. DomainName = CurrentConvertList->FileServ->Domain->Name;
  1718. else
  1719. DomainName = TEXT("");
  1720. if ((status = NTSAMConnect(TList[i].ServerName, DomainName))) {
  1721. // Failed to set server so log it and loop to next server
  1722. LogWriteLog(0, Lids(IDS_L_209), TList[i].ServerName);
  1723. ErrorIt(Lids(IDS_L_209), TList[i].ServerName);
  1724. goto ConvDo_Loop;
  1725. }
  1726. }
  1727. if ((status = NWServerSet(SourceServer))) {
  1728. // Failed to set server so log it and loop to next server
  1729. LogWriteLog(0, Lids(IDS_L_209), SourceServer);
  1730. ErrorIt(Lids(IDS_L_209), SourceServer);
  1731. goto ConvDo_Loop;
  1732. }
  1733. //
  1734. // If we are using mapping file then don't enum users and groups off
  1735. // the server. Get them from the mapping file instead.
  1736. //
  1737. hMap = NULL;
  1738. if (ConvOpt->UseMappingFile) {
  1739. //
  1740. // This is mapping file stuff
  1741. //
  1742. hMap = map_Open(ConvOpt->MappingFile);
  1743. if (hMap == NULL) {
  1744. ErrorIt(Lids(IDS_L_217), ConvOpt->MappingFile);
  1745. goto ConvDo_Loop;
  1746. }
  1747. if ((status = map_GroupsEnum(hMap, &Groups))) {
  1748. // Failed - make sure we don't try to convert users and log err
  1749. Groups = NULL;
  1750. GroupCount = 0;
  1751. LogWriteLog(0, Lids(IDS_L_219), ConvOpt->MappingFile);
  1752. ErrorIt(Lids(IDS_L_219), ConvOpt->MappingFile);
  1753. GotUserList = FALSE;
  1754. } else
  1755. GroupCount = Groups->Count;
  1756. if ((status = map_UsersEnum(hMap, &Users))) {
  1757. // Failed - make sure we don't try to convert users and log err
  1758. Users = NULL;
  1759. UserCount = 0;
  1760. LogWriteLog(0, Lids(IDS_L_218), ConvOpt->MappingFile);
  1761. ErrorIt(Lids(IDS_L_218), ConvOpt->MappingFile);
  1762. GotUserList = FALSE;
  1763. } else
  1764. UserCount = Users->Count;
  1765. } else {
  1766. //
  1767. // Enuming users and groups from NetWare Server instead of map file
  1768. //
  1769. if ((status = NWGroupsEnum(&Groups, TRUE))) {
  1770. // Failed - make sure we don't try to convert users and log err
  1771. Groups = NULL;
  1772. GroupCount = 0;
  1773. LogWriteLog(0, Lids(IDS_L_211), SourceServer);
  1774. ErrorIt(Lids(IDS_L_211), SourceServer);
  1775. GotUserList = FALSE;
  1776. } else
  1777. GroupCount = Groups->Count;
  1778. if ((status = NWUsersEnum(&Users, TRUE))) {
  1779. // Failed - make sure we don't try to convert users and log err
  1780. Users = NULL;
  1781. UserCount = 0;
  1782. LogWriteLog(0, Lids(IDS_L_210), SourceServer);
  1783. ErrorIt(Lids(IDS_L_210), SourceServer);
  1784. GotUserList = FALSE;
  1785. } else
  1786. UserCount = Users->Count;
  1787. }
  1788. if (GotUserList) {
  1789. // User and Groups
  1790. if (ConvOpt->TransferUserInfo) {
  1791. UsersConvert();
  1792. if (!TransferCancel)
  1793. GroupsConvert();
  1794. }
  1795. }
  1796. // Note GroupsConvert switches servers for Print Operators to the
  1797. // destination server (and not the PDC).
  1798. // Files
  1799. if (!(TransferCancel) && FileOptions->TransferFileInfo) {
  1800. ErrorCategorySet(Lids(IDS_L_212));
  1801. // Now set server to appropriate file dest server
  1802. if ((status = NTServerSet(CurrentConvertList->FileServ->Name))) {
  1803. // Failed to set server so log it and loop to next server
  1804. LogWriteLog(0, Lids(IDS_L_209), CurrentConvertList->FileServ->Name);
  1805. ErrorIt(Lids(IDS_L_209), CurrentConvertList->FileServ->Name);
  1806. goto ConvDo_Loop;
  1807. }
  1808. Status_BytesTxt(Lids(IDS_L_213));
  1809. Status_Bytes(TEXT("0"));
  1810. Status_TotBytes(TEXT("0"));
  1811. Status_BytesSep(Lids(IDS_L_214));
  1812. ConvertFiles(hDlg, TConversion, Users, Groups);
  1813. Status_BytesTxt(TEXT(""));
  1814. Status_Bytes(TEXT(""));
  1815. Status_TotBytes(TEXT(""));
  1816. Status_BytesSep(TEXT(""));
  1817. }
  1818. NWServerFree();
  1819. ConvDo_Loop:
  1820. Status_TotComplete(i);
  1821. if (Users) {
  1822. FreeMemory(Users);
  1823. UserCount = 0;
  1824. }
  1825. if (Groups) {
  1826. FreeMemory(Groups);
  1827. GroupCount = 0;
  1828. }
  1829. if (hMap != NULL)
  1830. map_Close(hMap);
  1831. } // for loop through transfer list
  1832. // Free up our caches
  1833. ListCacheFree(&UserCacheHead);
  1834. ListCacheFree(&GroupCacheHead);
  1835. // Log out the finish time
  1836. LogWriteSummary(0, Lids(IDS_CRLF));
  1837. LogWriteSummary(0, Lids(IDS_CRLF));
  1838. LogWriteLog(0, Lids(IDS_CRLF));
  1839. LogWriteLog(0, Lids(IDS_CRLF));
  1840. GetTime(sztime);
  1841. if (TransferCancel) {
  1842. LogWriteLog(0, Lids(IDS_L_215), sztime);
  1843. LogWriteSummary(0, Lids(IDS_L_215), sztime);
  1844. } else {
  1845. LogWriteLog(0, Lids(IDS_L_216), sztime);
  1846. LogWriteSummary(0, Lids(IDS_L_216), sztime);
  1847. }
  1848. if (tl != NULL)
  1849. FreeMemory(tl);
  1850. NTSAMClose();
  1851. StatusDlgKill();
  1852. CursorNormal();
  1853. TotConversions = i;
  1854. ConversionEndDlg_Do(hDlg);
  1855. } // DoConversion
  1856. /*+-------------------------------------------------------------------------+
  1857. | ConversionSuccessful()
  1858. |
  1859. +-------------------------------------------------------------------------+*/
  1860. BOOL ConversionSuccessful() {
  1861. if (TotErrors || TransferCancel)
  1862. return FALSE;
  1863. else
  1864. return TRUE;
  1865. } // ConversionSuccesful