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.

1682 lines
48 KiB

  1. /*
  2. +-------------------------------------------------------------------------+
  3. | User Options Dialog |
  4. +-------------------------------------------------------------------------+
  5. | (c) Copyright 1993-1994 |
  6. | Microsoft Corp. |
  7. | All rights reserved |
  8. | |
  9. | Program : [MAP.c] |
  10. | Programmer : Arthur Hanson |
  11. | Original Program Date : [Sep 28, 1994] |
  12. | Last Update : [Sep 28, 1994] |
  13. | |
  14. | Version: 1.00 |
  15. | |
  16. | Description: |
  17. | |
  18. | History: |
  19. | arth Sep 28, 1994 1.00 Original Version. |
  20. | |
  21. +-------------------------------------------------------------------------+
  22. */
  23. #include "globals.h"
  24. #include "convapi.h"
  25. #include "ntnetapi.h"
  26. #include "nwnetapi.h"
  27. #include "map.h"
  28. #include "nwlog.h"
  29. #include "nwconv.h"
  30. // from userdlg.c
  31. DWORD UserFileGet(HWND hwnd, LPTSTR FilePath);
  32. // The map file is kept as a doubly-linked list of sections, each of which has
  33. // a doubly-linked list of lines in that section. A header is used to point to
  34. // the first section, and also contains a pointer to any lines that appear
  35. // before the first section (usually only comment lines) - it also keeps the
  36. // current line and section pointer.
  37. //
  38. // All the linked lists have a dummy header and tail, with the tail pointing
  39. // back on itself (this simplifies the logic for list manipulation)...
  40. //
  41. // +-------------+ +----------------+
  42. // | Dummy | | Dummy |
  43. // | head node v v tail node |
  44. // | +-----------+ +-----------+ +-----------+ |
  45. // | | Node 1 |-->| Node 2 |-->| Node 3 |----+
  46. // +--| (not used)|<--| (data) |<--| (not used)|
  47. // +-----------+ +-----------+ +-----------+
  48. //
  49. // The dummy head/tail nodes make it easy to keep track of the start and
  50. // end of the list (we never have to worry about updating the head and tail
  51. // pointers in the owning data structures, since they never change). It does,
  52. // however, make for some obtuse cases in the add/delete node code.
  53. typedef struct _LINKED_LIST {
  54. struct _LINKED_LIST *prev;
  55. struct _LINKED_LIST *next;
  56. } LINKED_LIST;
  57. typedef struct _LINK_HEAD {
  58. LINKED_LIST *Head;
  59. LINKED_LIST *Tail;
  60. LINKED_LIST *Current;
  61. ULONG Count;
  62. TCHAR Name[];
  63. } LINK_HEAD;
  64. static TCHAR MappingFile[MAX_PATH + 1];
  65. static TCHAR PasswordConstant[MAX_PW_LEN + 1];
  66. static BOOL DoUsers = TRUE;
  67. static BOOL DoGroups = TRUE;
  68. static UINT PasswordOption = 0;
  69. static LPTSTR SourceServ;
  70. /*+-------------------------------------------------------------------------+
  71. | Common Linked List Routines
  72. +-------------------------------------------------------------------------+*/
  73. /*+-------------------------------------------------------------------------+
  74. | ll_Init()
  75. |
  76. +-------------------------------------------------------------------------+*/
  77. LINKED_LIST *ll_Init(ULONG Size) {
  78. LINKED_LIST *llHead;
  79. LINKED_LIST *llTail;
  80. llHead = (LINKED_LIST *) AllocMemory(Size);
  81. if (llHead == NULL)
  82. return NULL;
  83. llTail = (LINKED_LIST *) AllocMemory(Size);
  84. if (llTail == NULL) {
  85. FreeMemory(llHead);
  86. return NULL;
  87. }
  88. llHead->prev = llHead;
  89. llHead->next = llTail;
  90. llTail->next = llTail;
  91. llTail->prev = llHead;
  92. return llHead;
  93. } // ll_Init
  94. /*+-------------------------------------------------------------------------+
  95. | ll_Next()
  96. |
  97. +-------------------------------------------------------------------------+*/
  98. LINKED_LIST *ll_Next(void *vllCurrent) {
  99. LINKED_LIST *llCurrent;
  100. llCurrent = (LINKED_LIST *) vllCurrent;
  101. if ((llCurrent == NULL) || (llCurrent->next == NULL) || (llCurrent->prev == NULL))
  102. return NULL;
  103. llCurrent = llCurrent->next;
  104. if (llCurrent->next == llCurrent)
  105. return NULL;
  106. else
  107. return llCurrent;
  108. } // ll_Next
  109. /*+-------------------------------------------------------------------------+
  110. | ll_Prev()
  111. |
  112. +-------------------------------------------------------------------------+*/
  113. LINKED_LIST *ll_Prev(void *vllCurrent) {
  114. LINKED_LIST *llCurrent;
  115. llCurrent = (LINKED_LIST *) vllCurrent;
  116. if ((llCurrent == NULL) || (llCurrent->next == NULL) || (llCurrent->prev == NULL))
  117. return NULL;
  118. llCurrent = llCurrent->prev;
  119. if (llCurrent->prev == llCurrent)
  120. return NULL;
  121. else
  122. return llCurrent;
  123. } // ll_Prev
  124. /*+-------------------------------------------------------------------------+
  125. | ll_InsertAfter()
  126. |
  127. +-------------------------------------------------------------------------+*/
  128. LINKED_LIST *ll_InsertAfter(void *vllCurrent, void *vllNew) {
  129. LINKED_LIST *llCurrent;
  130. LINKED_LIST *llNew;
  131. llCurrent = (LINKED_LIST *) vllCurrent;
  132. llNew = (LINKED_LIST *) vllNew;
  133. if ((vllCurrent == NULL) || (llNew == NULL))
  134. return NULL;
  135. // change pointers to insert it into the list
  136. llNew->next = llCurrent->next;
  137. // check if at end of list
  138. if (llCurrent->next == llCurrent)
  139. llNew->prev = llCurrent->prev;
  140. else
  141. llNew->prev = llCurrent;
  142. llNew->prev->next = llNew;
  143. llNew->next->prev = llNew;
  144. return llNew;
  145. } // ll_InsertAfter
  146. /*+-------------------------------------------------------------------------+
  147. | ll_InsertBefore()
  148. |
  149. +-------------------------------------------------------------------------+*/
  150. LINKED_LIST *ll_InsertBefore(void *vllCurrent, void *vllNew) {
  151. LINKED_LIST *llCurrent;
  152. LINKED_LIST *llNew;
  153. llCurrent = (LINKED_LIST *) vllCurrent;
  154. llNew = (LINKED_LIST *) vllNew;
  155. if ((vllCurrent == NULL) || (llNew == NULL))
  156. return NULL;
  157. // change pointers to insert it into the list
  158. llNew->prev = llCurrent->prev;
  159. // check if at start of list
  160. if (llCurrent->prev = llCurrent)
  161. llNew->next = llCurrent->next;
  162. else
  163. llNew->next = llCurrent;
  164. llNew->prev->next = llNew;
  165. llNew->next->prev = llNew;
  166. return llNew;
  167. } // ll_InsertBefore
  168. /*+-------------------------------------------------------------------------+
  169. | ll_Delete()
  170. |
  171. +-------------------------------------------------------------------------+*/
  172. LINKED_LIST *ll_Delete(void *vllCurrent) {
  173. LINKED_LIST *llCurrent;
  174. llCurrent = (LINKED_LIST *) vllCurrent;
  175. if ((llCurrent == NULL) || (llCurrent->next == NULL) || (llCurrent->prev == NULL))
  176. return NULL;
  177. // make sure not on one of the dummy end headers
  178. if ((llCurrent->next == llCurrent) || (llCurrent->prev == llCurrent))
  179. return NULL;
  180. // changed pointers to remove it from list
  181. llCurrent->prev->next = llCurrent->next;
  182. llCurrent->next->prev = llCurrent->prev;
  183. // Get which one to return as new current record - we generally want to
  184. // go to the previous record - unless we deleted the first record, in
  185. // which case get the next record. If there are no records, then return
  186. // the list head
  187. llCurrent = llCurrent->prev;
  188. // check if at start of list
  189. if (llCurrent->prev == llCurrent)
  190. llCurrent = llCurrent->next;
  191. // make sure not at end of list (may have moved here if empty list) - if
  192. // so we want to return the starting node
  193. if (llCurrent->next == llCurrent)
  194. llCurrent = llCurrent->prev;
  195. return llCurrent;
  196. } // ll_Delete
  197. /*+-------------------------------------------------------------------------+
  198. | ll_Home()
  199. |
  200. +-------------------------------------------------------------------------+*/
  201. LINKED_LIST *ll_Home(void *vllCurrent) {
  202. LINKED_LIST *llCurrent;
  203. llCurrent = (LINKED_LIST *) vllCurrent;
  204. if (llCurrent == NULL)
  205. return (LINKED_LIST *) NULL;
  206. // make sure at start of list
  207. while (llCurrent->prev != llCurrent)
  208. llCurrent = llCurrent->prev;
  209. return llCurrent;
  210. } // ll_Home
  211. /*+-------------------------------------------------------------------------+
  212. | ll_End()
  213. |
  214. +-------------------------------------------------------------------------+*/
  215. LINKED_LIST *ll_End(void *vllCurrent) {
  216. LINKED_LIST *llCurrent;
  217. llCurrent = (LINKED_LIST *) vllCurrent;
  218. if (llCurrent == NULL)
  219. return (LINKED_LIST *) NULL;
  220. // make sure at end of list
  221. while (llCurrent->next != llCurrent)
  222. llCurrent = llCurrent->next;
  223. return llCurrent;
  224. } // ll_End
  225. /*+-------------------------------------------------------------------------+
  226. | ll_ListFree()
  227. |
  228. +-------------------------------------------------------------------------+*/
  229. void ll_ListFree(void *vllHead) {
  230. LINKED_LIST *llCurrent;
  231. LINKED_LIST *llNext;
  232. llCurrent = (LINKED_LIST *) vllHead;
  233. if (llCurrent == NULL)
  234. return;
  235. // make sure at start of list
  236. while (llCurrent->prev != llCurrent)
  237. llCurrent = llCurrent->prev;
  238. // walk the chain - freeing it
  239. while ((llCurrent != NULL) && (llCurrent->next != llCurrent)) {
  240. llNext = llCurrent->next;
  241. FreeMemory(llCurrent);
  242. llCurrent = llNext;
  243. }
  244. // at the ending node - kill it as well
  245. FreeMemory(llCurrent);
  246. } // ll_ListFree
  247. /*+-------------------------------------------------------------------------+
  248. | List Routines
  249. +-------------------------------------------------------------------------+*/
  250. /*+-------------------------------------------------------------------------+
  251. | map_LineListInit()
  252. |
  253. +-------------------------------------------------------------------------+*/
  254. MAP_LINE *map_LineListInit() {
  255. MAP_LINE *NewHead;
  256. MAP_LINE *NewTail;
  257. // Create our linked list
  258. NewHead = (MAP_LINE *) ll_Init(sizeof(MAP_LINE));
  259. if (NewHead == NULL)
  260. return (MAP_LINE *) NULL;
  261. NewTail = NewHead->next;
  262. // Now init them as appropriate
  263. NewHead->Line = NULL;
  264. NewTail->Line = NULL;
  265. return NewHead;
  266. } // map_LineListInit
  267. /*+-------------------------------------------------------------------------+
  268. | map_SectionListInit()
  269. |
  270. +-------------------------------------------------------------------------+*/
  271. MAP_SECTION *map_SectionListInit() {
  272. MAP_SECTION *NewHead;
  273. MAP_SECTION *NewTail;
  274. // Create our linked list
  275. NewHead = (MAP_SECTION *) ll_Init(sizeof(MAP_SECTION));
  276. if (NewHead == NULL)
  277. return (MAP_SECTION *) NULL;
  278. NewTail = NewHead->next;
  279. // Now init them as appropriate
  280. NewHead->Name = NULL;
  281. NewTail->Name = NULL;
  282. NewHead->FirstLine = NewHead->LastLine = NewTail->FirstLine = NewTail->LastLine = NULL;
  283. NewHead->LineCount = NewTail->LineCount = 0;
  284. return NewHead;
  285. } // map_SectionListInit
  286. /*+-------------------------------------------------------------------------+
  287. | map_LineListFree()
  288. |
  289. +-------------------------------------------------------------------------+*/
  290. void map_LineListFree(MAP_LINE *CurrentLine) {
  291. MAP_LINE *NextLine;
  292. if (CurrentLine == NULL)
  293. return;
  294. // make sure at start of list
  295. while (CurrentLine->prev != CurrentLine)
  296. CurrentLine = CurrentLine->prev;
  297. // walk the chain - freeing it
  298. while ((CurrentLine != NULL) && (CurrentLine->next != CurrentLine)) {
  299. NextLine = CurrentLine->next;
  300. if (CurrentLine->Line != NULL)
  301. FreeMemory(CurrentLine->Line);
  302. FreeMemory(CurrentLine);
  303. CurrentLine = NextLine;
  304. }
  305. // at the ending node - kill it as well
  306. FreeMemory(CurrentLine);
  307. } // map_LineListFree
  308. /*+-------------------------------------------------------------------------+
  309. | map_SectionListFree()
  310. |
  311. +-------------------------------------------------------------------------+*/
  312. void map_SectionListFree(MAP_SECTION *CurrentSection) {
  313. MAP_SECTION *NextSection;
  314. if (CurrentSection == NULL)
  315. return;
  316. // make sure at start of list
  317. while (CurrentSection->prev != CurrentSection)
  318. CurrentSection = CurrentSection->prev;
  319. // walk the chain - freeing it
  320. while ((CurrentSection != NULL) && (CurrentSection->next != CurrentSection)) {
  321. NextSection = CurrentSection->next;
  322. map_LineListFree(CurrentSection->FirstLine);
  323. if (CurrentSection->Name != NULL)
  324. FreeMemory(CurrentSection->Name);
  325. FreeMemory(CurrentSection);
  326. CurrentSection = NextSection;
  327. }
  328. // at the ending node - kill it as well
  329. FreeMemory(CurrentSection);
  330. } // map_SectionListFree
  331. /*+-------------------------------------------------------------------------+
  332. | Section Routines
  333. +-------------------------------------------------------------------------+*/
  334. /*+-------------------------------------------------------------------------+
  335. | map_SectionInit()
  336. |
  337. +-------------------------------------------------------------------------+*/
  338. MAP_SECTION *map_SectionInit(LPTSTR Section) {
  339. MAP_SECTION *NewSection;
  340. MAP_LINE *FirstLine;
  341. NewSection = (MAP_SECTION *) AllocMemory(sizeof(MAP_SECTION));
  342. if (NewSection == NULL)
  343. return (MAP_SECTION *) NULL;
  344. // Init the section name
  345. NewSection->Name = (LPTSTR) AllocMemory((lstrlen(Section) + 1) * sizeof(TCHAR));
  346. if (NewSection->Name == NULL) {
  347. FreeMemory(NewSection);
  348. return (MAP_SECTION *) NULL;
  349. }
  350. // Now create the line list
  351. FirstLine = map_LineListInit();
  352. if (FirstLine == NULL) {
  353. FreeMemory(NewSection->Name);
  354. FreeMemory(NewSection);
  355. return (MAP_SECTION *) NULL;
  356. }
  357. lstrcpy(NewSection->Name, Section);
  358. NewSection->LineCount = 0;
  359. NewSection->FirstLine = FirstLine;
  360. NewSection->LastLine = FirstLine->next;
  361. return NewSection;
  362. } // map_SectionInit
  363. /*+-------------------------------------------------------------------------+
  364. | map_SectionAdd()
  365. |
  366. +-------------------------------------------------------------------------+*/
  367. void map_SectionAdd(MAP_FILE *hMap, LPTSTR Section) {
  368. MAP_SECTION *NewSection;
  369. NewSection = map_SectionInit(Section);
  370. if (NewSection == NULL)
  371. return;
  372. // Add it to the section list
  373. ll_InsertBefore((void *) hMap->LastSection, (void *) NewSection);
  374. // Init it so the added section is currently selected
  375. hMap->CurrentSection = NewSection;
  376. hMap->CurrentLine = hMap->CurrentSection->FirstLine;
  377. } // map_SectionAdd
  378. /*+-------------------------------------------------------------------------+
  379. | map_SectionDelete()
  380. |
  381. +-------------------------------------------------------------------------+*/
  382. void map_SectionDelete(MAP_FILE *hMap) {
  383. MAP_SECTION *CurrentSection;
  384. MAP_SECTION *NewSection;
  385. // if no section is currently selected then get out
  386. CurrentSection = hMap->CurrentSection;
  387. if (CurrentSection == NULL)
  388. return;
  389. // Remove this from the chain
  390. NewSection = (MAP_SECTION *) ll_Delete((void *) CurrentSection);
  391. // walk the lines and remove them...
  392. map_LineListFree(CurrentSection->FirstLine);
  393. // All lines have been removed, so remove section header itself
  394. FreeMemory(CurrentSection->Name);
  395. FreeMemory(CurrentSection);
  396. // Update Section count
  397. if (hMap->SectionCount > 0)
  398. hMap->SectionCount--;
  399. } // map_SectionDelete
  400. /*+-------------------------------------------------------------------------+
  401. | map_SectionInsertBefore()
  402. |
  403. +-------------------------------------------------------------------------+*/
  404. void map_SectionInsertBefore(MAP_FILE *hMap, LPTSTR Section) {
  405. MAP_SECTION *CurrentSection;
  406. if (hMap->CurrentSection == NULL)
  407. return;
  408. CurrentSection = map_SectionInit(Section);
  409. if (CurrentSection == NULL)
  410. return;
  411. ll_InsertBefore((void *) hMap->CurrentSection, (void *) CurrentSection);
  412. } // map_SectionInsertBefore
  413. /*+-------------------------------------------------------------------------+
  414. | map_SectionInsertAfter()
  415. |
  416. +-------------------------------------------------------------------------+*/
  417. void map_SectionInsertAfter(MAP_FILE *hMap, LPTSTR Section) {
  418. MAP_SECTION *CurrentSection;
  419. if (hMap->CurrentSection == NULL)
  420. return;
  421. CurrentSection = map_SectionInit(Section);
  422. if (CurrentSection == NULL)
  423. return;
  424. ll_InsertAfter((void *) hMap->CurrentSection, (void *) CurrentSection);
  425. } // map_SectionInsertAfter
  426. /*+-------------------------------------------------------------------------+
  427. | map_SectionNext()
  428. |
  429. +-------------------------------------------------------------------------+*/
  430. MAP_SECTION *map_SectionNext(MAP_FILE *hMap) {
  431. MAP_SECTION *CurrentSection;
  432. if (hMap->CurrentSection == NULL)
  433. return NULL;
  434. CurrentSection = (MAP_SECTION *) ll_Next((void *) hMap->CurrentSection);
  435. if (CurrentSection != NULL)
  436. hMap->CurrentSection = CurrentSection;
  437. return CurrentSection;
  438. } // map_SectionNext
  439. /*+-------------------------------------------------------------------------+
  440. | map_SectionPrev()
  441. |
  442. +-------------------------------------------------------------------------+*/
  443. MAP_SECTION *map_SectionPrev(MAP_FILE *hMap) {
  444. MAP_SECTION *CurrentSection;
  445. if (hMap->CurrentSection == NULL)
  446. return NULL;
  447. CurrentSection = (MAP_SECTION *) ll_Prev((void *) hMap->CurrentSection);
  448. if (CurrentSection != NULL)
  449. hMap->CurrentSection = CurrentSection;
  450. return CurrentSection;
  451. } // map_SectionPrev
  452. /*+-------------------------------------------------------------------------+
  453. | map_SectionFind()
  454. |
  455. +-------------------------------------------------------------------------+*/
  456. MAP_SECTION *map_SectionFind(MAP_FILE *hMap, LPTSTR Section) {
  457. MAP_SECTION *CurrentSection;
  458. CurrentSection = hMap->FirstSection;
  459. while (CurrentSection && lstrcmpi(CurrentSection->Name, Section))
  460. CurrentSection = (MAP_SECTION *) ll_Next((void *) CurrentSection);
  461. if (CurrentSection != NULL) {
  462. hMap->CurrentSection = CurrentSection;
  463. hMap->CurrentLine = hMap->CurrentSection->FirstLine;
  464. }
  465. return CurrentSection;
  466. } // map_SectionFind
  467. /*+-------------------------------------------------------------------------+
  468. | map_SectionHome()
  469. |
  470. +-------------------------------------------------------------------------+*/
  471. void map_SectionHome(MAP_FILE *hMap) {
  472. hMap->CurrentSection = hMap->FirstSection;
  473. hMap->CurrentLine = hMap->CurrentSection->FirstLine;
  474. } // map_SectionHome
  475. /*+-------------------------------------------------------------------------+
  476. | map_SectionEnd()
  477. |
  478. +-------------------------------------------------------------------------+*/
  479. void map_SectionEnd(MAP_FILE *hMap) {
  480. MAP_SECTION *CurrentSection;
  481. CurrentSection = hMap->FirstSection;
  482. while (CurrentSection && (CurrentSection->next != NULL))
  483. CurrentSection = CurrentSection->next;
  484. hMap->CurrentSection = CurrentSection;
  485. hMap->CurrentLine = CurrentSection->FirstLine;
  486. } // map_SectionEnd
  487. /*+-------------------------------------------------------------------------+
  488. | Line Routines
  489. +-------------------------------------------------------------------------+*/
  490. /*+-------------------------------------------------------------------------+
  491. | map_LineInit()
  492. |
  493. +-------------------------------------------------------------------------+*/
  494. MAP_LINE *map_LineInit(LPTSTR Line) {
  495. MAP_LINE *NewLine;
  496. NewLine = (MAP_LINE *) AllocMemory(sizeof(MAP_LINE));
  497. if (NewLine == NULL)
  498. return (MAP_LINE *) NULL;
  499. NewLine->Line = (LPTSTR) AllocMemory((lstrlen(Line) + 1) * sizeof(TCHAR));
  500. if (NewLine->Line == NULL) {
  501. FreeMemory(NewLine);
  502. return (MAP_LINE *) NULL;
  503. }
  504. lstrcpy(NewLine->Line, Line);
  505. return NewLine;
  506. } // map_LineInit
  507. /*+-------------------------------------------------------------------------+
  508. | map_LineAdd()
  509. |
  510. +-------------------------------------------------------------------------+*/
  511. MAP_LINE *map_LineAdd(MAP_FILE *hMap, LPTSTR Line) {
  512. MAP_LINE *NewLine;
  513. // make sure there is something to add it to
  514. if ((hMap->CurrentSection == NULL) || (hMap->CurrentSection->LastLine == NULL))
  515. return (MAP_LINE *) NULL;
  516. // Create the new line
  517. NewLine = map_LineInit(Line);
  518. if (NewLine->Line == NULL)
  519. return (MAP_LINE *) NULL;
  520. // ...and add it to our list
  521. ll_InsertBefore((void *) hMap->CurrentSection->LastLine, (void *) NewLine);
  522. // Init it so the added line is currently selected
  523. hMap->CurrentLine = NewLine;
  524. hMap->CurrentSection->LineCount++;
  525. return NewLine;
  526. } // map_LineAdd
  527. /*+-------------------------------------------------------------------------+
  528. | map_LineDelete()
  529. |
  530. +-------------------------------------------------------------------------+*/
  531. void map_LineDelete(MAP_FILE *hMap) {
  532. MAP_LINE *CurrentLine;
  533. MAP_LINE *NewLine;
  534. // if no section is currently selected then get out
  535. if ((hMap->CurrentSection == NULL) || (hMap->CurrentLine == NULL))
  536. return;
  537. CurrentLine = hMap->CurrentLine;
  538. NewLine = (MAP_LINE *) ll_Delete((void *) CurrentLine);
  539. // All lines have been removed, so remove section header itself
  540. FreeMemory(CurrentLine->Line);
  541. FreeMemory(CurrentLine);
  542. // update hMap
  543. if (NewLine != NULL)
  544. hMap->CurrentLine = NewLine;
  545. else
  546. hMap->CurrentLine = hMap->CurrentSection->FirstLine;
  547. if (hMap->CurrentSection->LineCount > 0)
  548. hMap->CurrentSection->LineCount--;
  549. } // map_LineDelete
  550. /*+-------------------------------------------------------------------------+
  551. | map_LineInsertBefore()
  552. |
  553. +-------------------------------------------------------------------------+*/
  554. void map_LineInsertBefore(MAP_FILE *hMap, LPTSTR Line) {
  555. MAP_LINE *NewLine;
  556. if ((hMap->CurrentSection == NULL) || (hMap->CurrentLine == NULL))
  557. return;
  558. NewLine = map_LineInit(Line);
  559. if (NewLine == NULL)
  560. return;
  561. ll_InsertBefore((void *) hMap->CurrentLine, (void *) NewLine);
  562. } // map_LineInsertBefore
  563. /*+-------------------------------------------------------------------------+
  564. | map_LineInsertAfter()
  565. |
  566. +-------------------------------------------------------------------------+*/
  567. void map_LineInsertAfter(MAP_FILE *hMap, LPTSTR Line) {
  568. MAP_LINE *NewLine;
  569. if ((hMap->CurrentSection == NULL) || (hMap->CurrentLine == NULL))
  570. return;
  571. NewLine = map_LineInit(Line);
  572. if (NewLine == NULL)
  573. return;
  574. ll_InsertAfter((void *) hMap->CurrentLine, (void *) NewLine);
  575. } // map_LineInsertAfter
  576. /*+-------------------------------------------------------------------------+
  577. | map_LineNext()
  578. |
  579. +-------------------------------------------------------------------------+*/
  580. MAP_LINE *map_LineNext(MAP_FILE *hMap) {
  581. MAP_LINE *CurrentLine;
  582. if ((hMap->CurrentSection == NULL) || (hMap->CurrentLine == NULL))
  583. return NULL;
  584. CurrentLine = (MAP_LINE *) ll_Next((void *) hMap->CurrentLine);
  585. if (CurrentLine != NULL)
  586. hMap->CurrentLine = CurrentLine;
  587. return CurrentLine;
  588. } // map_LineNext
  589. /*+-------------------------------------------------------------------------+
  590. | map_LinePrev()
  591. |
  592. +-------------------------------------------------------------------------+*/
  593. MAP_LINE *map_LinePrev(MAP_FILE *hMap) {
  594. MAP_LINE *CurrentLine;
  595. if ((hMap->CurrentSection == NULL) || (hMap->CurrentLine == NULL))
  596. return NULL;
  597. CurrentLine = (MAP_LINE *) ll_Prev((void *) hMap->CurrentLine);
  598. if (CurrentLine != NULL)
  599. hMap->CurrentLine = CurrentLine;
  600. return CurrentLine;
  601. } // map_LinePrev
  602. /*+-------------------------------------------------------------------------+
  603. | map_LineHome()
  604. |
  605. +-------------------------------------------------------------------------+*/
  606. void map_LineHome(MAP_FILE *hMap) {
  607. if ((hMap->CurrentSection == NULL) || (hMap->CurrentLine == NULL))
  608. return;
  609. hMap->CurrentLine = (MAP_LINE *) ll_Home((void *) hMap->CurrentLine);
  610. } // map_LineHome
  611. /*+-------------------------------------------------------------------------+
  612. | map_LineEnd()
  613. |
  614. +-------------------------------------------------------------------------+*/
  615. void map_LineEnd(MAP_FILE *hMap) {
  616. if ((hMap->CurrentSection == NULL) || (hMap->CurrentLine == NULL))
  617. return;
  618. hMap->CurrentLine = (MAP_LINE *) ll_End((void *) hMap->CurrentLine);
  619. } // map_LineEnd
  620. /*+-------------------------------------------------------------------------+
  621. | Map File Routines
  622. +-------------------------------------------------------------------------+*/
  623. /*+-------------------------------------------------------------------------+
  624. | map_Home()
  625. |
  626. +-------------------------------------------------------------------------+*/
  627. void map_Home(MAP_FILE *hMap) {
  628. hMap->CurrentSection = hMap->FirstSection;
  629. } // map_Home
  630. /*+-------------------------------------------------------------------------+
  631. | map_End()
  632. |
  633. +-------------------------------------------------------------------------+*/
  634. void map_End(MAP_FILE *hMap) {
  635. MAP_SECTION *CurrentSection;
  636. MAP_LINE *CurrentLine = NULL;
  637. CurrentSection = hMap->FirstSection;
  638. while (CurrentSection->next != NULL)
  639. CurrentSection = CurrentSection->next;
  640. CurrentLine = CurrentSection->FirstLine;
  641. if (CurrentLine != NULL)
  642. while (CurrentLine->next != NULL)
  643. CurrentLine = CurrentLine->next;
  644. hMap->CurrentSection = CurrentSection;
  645. hMap->CurrentLine = CurrentLine;
  646. } // map_End
  647. /*+-------------------------------------------------------------------------+
  648. | map_Open()
  649. |
  650. +-------------------------------------------------------------------------+*/
  651. MAP_FILE *map_Open(TCHAR *FileName) {
  652. MAP_FILE *hMap = NULL;
  653. HANDLE hFile = NULL;
  654. char *FileCache = NULL;
  655. char *chA;
  656. char *pchA;
  657. DWORD wrote;
  658. char lpszA[MAX_LINE_LEN + 1];
  659. TCHAR lpsz[MAX_LINE_LEN + 1];
  660. TCHAR tmpStr[MAX_LINE_LEN + 1];
  661. char FileNameA[MAX_PATH + 1];
  662. ULONG Size;
  663. TCHAR *ch;
  664. TCHAR *pch;
  665. TCHAR *lch;
  666. DWORD FSize;
  667. MAP_SECTION *CurrentSection = NULL;
  668. MAP_LINE *CurrentLine = NULL;
  669. WideCharToMultiByte(CP_ACP, 0, FileName, -1, FileNameA, sizeof(FileNameA), NULL, NULL);
  670. hFile = CreateFileA( FileNameA, GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING,
  671. FILE_ATTRIBUTE_NORMAL, NULL);
  672. if (hFile == (HANDLE) INVALID_HANDLE_VALUE)
  673. return hMap;
  674. FSize = GetFileSize(hFile, NULL);
  675. FileCache = (char *) AllocMemory(FSize + 1);
  676. if (FileCache == NULL)
  677. goto map_OpenExit;
  678. hMap = (MAP_FILE *) AllocMemory(sizeof(MAP_FILE) + ((lstrlen(FileName) + 1) * sizeof(TCHAR)));
  679. if (hMap == NULL)
  680. goto map_OpenExit;
  681. // Init the section list
  682. CurrentSection = map_SectionListInit();
  683. if (CurrentSection == NULL) {
  684. FreeMemory(hMap);
  685. hMap = NULL;
  686. goto map_OpenExit;
  687. }
  688. hMap->FirstSection = CurrentSection;
  689. hMap->CurrentSection = CurrentSection;
  690. hMap->LastSection = CurrentSection->next;
  691. // Init the header info
  692. if (hMap != NULL) {
  693. hMap->hf = hFile;
  694. hMap->Modified = FALSE;
  695. hMap->CurrentLine = NULL;
  696. hMap->SectionCount = 0;
  697. lstrcpy(hMap->Name, FileName);
  698. }
  699. memset(FileCache, 0, FSize + 1);
  700. // Read in the whole file then parse it - it shouldn't be that large, a
  701. // very full NW server generated ~20K map file
  702. if (!ReadFile(hFile, FileCache, FSize, &wrote, NULL))
  703. goto map_OpenExit;
  704. // Now walk and parse the buffer - remember it's in ASCII
  705. chA = FileCache;
  706. while (*chA) {
  707. // Get past any white space junk at beginning of line
  708. while(*chA && ((*chA == ' ') || (*chA == '\t')))
  709. chA++;
  710. // transfer a line of text
  711. Size = 0;
  712. pchA = lpszA;
  713. while (*chA && (*chA != '\n') && (*chA != '\r') && (Size < MAX_LINE_LEN))
  714. *pchA++ = *chA++;
  715. *pchA = '\0';
  716. if (*chA == '\r')
  717. chA++;
  718. if (*chA == '\n')
  719. chA++;
  720. // ...convert line to Unicode
  721. MultiByteToWideChar(CP_ACP, 0, lpszA, -1, lpsz, sizeof(lpsz) );
  722. //
  723. // Now have a line of text - figure out what it is and update data
  724. // structures
  725. //
  726. // ...Check for section header
  727. ch = lpsz;
  728. lch = pch = tmpStr;
  729. if (*ch == TEXT(SECTION_BEGIN_CHAR)) {
  730. // Find end section brace - keeping track of last non-white space char
  731. // anything after end-section-brace is discarded. Any trailing/
  732. // leading whitespace in section header is removed
  733. ch++; // get past section-begin
  734. // remove any leading whitespace
  735. while(*ch && ((*ch == TEXT(' ')) || (*ch == TEXT('\t'))))
  736. ch++;
  737. // transfer it to tmpStr (via pch pointer)
  738. while (*ch && (*ch != TEXT(SECTION_END_CHAR))) {
  739. // keep track of last non-whitespace
  740. if ((*ch != TEXT(' ')) && (*ch != TEXT('\t'))) {
  741. lch = pch;
  742. lch++;
  743. }
  744. *pch++ = *ch++;
  745. }
  746. // NULL terminate before last section of whitespace
  747. *lch = TEXT('\0');
  748. // Allocate a new section-header block and init
  749. map_SectionAdd(hMap, tmpStr);
  750. } else {
  751. // Not section header, so normal line - copy to tmpStr via pch pointer
  752. while (*ch) {
  753. // keep track of last non-whitespace
  754. if ((*ch != TEXT(' ')) && (*ch != TEXT('\t'))) {
  755. lch = pch;
  756. lch++;
  757. }
  758. *pch++ = *ch++;
  759. }
  760. // NULL terminate before last section of whitespace
  761. *lch = TEXT('\0');
  762. // ...add it to the list
  763. map_LineAdd(hMap, tmpStr);
  764. }
  765. // Done with the line of text, so just loop back up to parse next
  766. // line
  767. }
  768. map_OpenExit:
  769. FreeMemory(FileCache);
  770. return hMap;
  771. } // map_Open
  772. /*+-------------------------------------------------------------------------+
  773. | map_Close()
  774. |
  775. +-------------------------------------------------------------------------+*/
  776. void map_Close(MAP_FILE *hMap) {
  777. // If file modified then re-write file.
  778. if ( hMap->Modified )
  779. ;
  780. // Write out cache of file, close it and clean up all the data structures
  781. CloseHandle( hMap->hf );
  782. hMap = NULL;
  783. } // map_Close
  784. /*+-------------------------------------------------------------------------+
  785. | ParseWord()
  786. |
  787. +-------------------------------------------------------------------------+*/
  788. void ParseWord(TCHAR **lpch, LPTSTR tmpStr) {
  789. TCHAR *ch;
  790. TCHAR *lch;
  791. TCHAR *pch;
  792. ch = *lpch;
  793. lch = pch = tmpStr;
  794. // remove any leading whitespace
  795. while(*ch && ((*ch == TEXT(' ')) || (*ch == TEXT('\t'))))
  796. ch++;
  797. // transfer it to tmpStr (via pch pointer)
  798. while (*ch && (*ch != TEXT(WORD_DELIMITER))) {
  799. // keep track of last non-whitespace
  800. if ((*ch != TEXT(' ')) && (*ch != TEXT('\t'))) {
  801. lch = pch;
  802. lch++;
  803. }
  804. *pch++ = *ch++;
  805. }
  806. if (*ch == TEXT(WORD_DELIMITER))
  807. ch++;
  808. // NULL terminate before last section of whitespace
  809. *lch = TEXT('\0');
  810. *lpch = ch;
  811. } // ParseWord
  812. /*+-------------------------------------------------------------------------+
  813. | map_ParseUser()
  814. |
  815. +-------------------------------------------------------------------------+*/
  816. void map_ParseUser(LPTSTR Line, LPTSTR Name, LPTSTR NewName, LPTSTR Password) {
  817. TCHAR *pch = Line;
  818. lstrcpy(Name, TEXT(""));
  819. lstrcpy(NewName, TEXT(""));
  820. lstrcpy(Password, TEXT(""));
  821. if (Line == NULL)
  822. return;
  823. ParseWord(&pch, Name);
  824. if (lstrlen(Name) >= MAX_USER_NAME_LEN)
  825. lstrcpy(Name, TEXT(""));
  826. ParseWord(&pch, NewName);
  827. if (lstrlen(NewName) >= MAX_USER_NAME_LEN)
  828. lstrcpy(NewName, TEXT(""));
  829. ParseWord(&pch, Password);
  830. if (lstrlen(Password) > MAX_PW_LEN)
  831. lstrcpy(Password, TEXT(""));
  832. } // map_ParseUser
  833. /*+-------------------------------------------------------------------------+
  834. | map_ParseGroup()
  835. |
  836. +-------------------------------------------------------------------------+*/
  837. void map_ParseGroup(LPTSTR Line, LPTSTR Name, LPTSTR NewName) {
  838. TCHAR *pch = Line;
  839. lstrcpy(Name, TEXT(""));
  840. lstrcpy(NewName, TEXT(""));
  841. if (Line == NULL)
  842. return;
  843. ParseWord(&pch, Name);
  844. if (lstrlen(Name) >= MAX_GROUP_NAME_LEN)
  845. lstrcpy(Name, TEXT(""));
  846. ParseWord(&pch, NewName);
  847. if (lstrlen(NewName) >= MAX_GROUP_NAME_LEN)
  848. lstrcpy(NewName, TEXT(""));
  849. } // map_ParseGroup
  850. /*+-------------------------------------------------------------------------+
  851. | map_UsersEnum()
  852. |
  853. +-------------------------------------------------------------------------+*/
  854. DWORD map_UsersEnum(MAP_FILE *hMap, USER_LIST **lpUsers) {
  855. DWORD ret = 0;
  856. USER_LIST *UserList = NULL;
  857. USER_BUFFER *UserBuffer = NULL;
  858. MAP_SECTION *CurrentSection = NULL;
  859. MAP_LINE *CurrentLine = NULL;
  860. ULONG Entries = 0;
  861. ULONG ActualEntries = 0;
  862. TCHAR Name[MAX_LINE_LEN + 1];
  863. TCHAR NewName[MAX_LINE_LEN + 1];
  864. TCHAR Password[MAX_LINE_LEN + 1];
  865. ULONG i;
  866. CurrentSection = map_SectionFind(hMap, Lids(IDS_M_7));
  867. if (CurrentSection != NULL)
  868. Entries = CurrentSection->LineCount;
  869. UserList = AllocMemory(sizeof(USER_LIST) + (sizeof(USER_BUFFER) * Entries));
  870. if (!UserList) {
  871. ret = ERROR_NOT_ENOUGH_MEMORY;
  872. } else {
  873. UserBuffer = UserList->UserBuffer;
  874. for (i = 0; i < Entries; i++) {
  875. CurrentLine = map_LineNext(hMap);
  876. if (CurrentLine != NULL) {
  877. map_ParseUser(CurrentLine->Line, Name, NewName, Password);
  878. if (lstrlen(Name)) {
  879. lstrcpy(UserBuffer[ActualEntries].Name, Name);
  880. lstrcpy(UserBuffer[ActualEntries].NewName, NewName);
  881. lstrcpy(UserBuffer[ActualEntries].Password, Password);
  882. if (lstrcmpi(Name, NewName))
  883. UserBuffer[ActualEntries].IsNewName = TRUE;
  884. ActualEntries++;
  885. }
  886. }
  887. }
  888. if (ActualEntries != Entries)
  889. UserList = (USER_LIST *) ReallocMemory((HGLOBAL) UserList, sizeof(USER_LIST) + (sizeof(USER_BUFFER)* ActualEntries));
  890. if (UserList == NULL)
  891. ret = ERROR_NOT_ENOUGH_MEMORY;
  892. else {
  893. // Sort the server list before putting it in the dialog
  894. UserBuffer = UserList->UserBuffer;
  895. qsort((void *) UserBuffer, (size_t) ActualEntries, sizeof(USER_BUFFER), UserListCompare);
  896. UserList->Count = ActualEntries;
  897. }
  898. *lpUsers = UserList;
  899. }
  900. return ret;
  901. } // map_UsersEnum
  902. /*+-------------------------------------------------------------------------+
  903. | map_GroupsEnum()
  904. |
  905. +-------------------------------------------------------------------------+*/
  906. DWORD map_GroupsEnum(MAP_FILE *hMap, GROUP_LIST **lpGroups) {
  907. DWORD ret = 0;
  908. GROUP_LIST *GroupList = NULL;
  909. GROUP_BUFFER *GroupBuffer = NULL;
  910. MAP_SECTION *CurrentSection = NULL;
  911. MAP_LINE *CurrentLine = NULL;
  912. ULONG Entries = 0;
  913. ULONG ActualEntries = 0;
  914. TCHAR Name[MAX_LINE_LEN + 1];
  915. TCHAR NewName[MAX_LINE_LEN + 1];
  916. ULONG i;
  917. CurrentSection = map_SectionFind(hMap, Lids(IDS_M_8));
  918. if (CurrentSection != NULL)
  919. Entries = CurrentSection->LineCount;
  920. GroupList = AllocMemory(sizeof(GROUP_LIST) + (sizeof(GROUP_BUFFER) * Entries));
  921. if (!GroupList) {
  922. ret = ERROR_NOT_ENOUGH_MEMORY;
  923. } else {
  924. GroupBuffer = GroupList->GroupBuffer;
  925. for (i = 0; i < Entries; i++) {
  926. CurrentLine = map_LineNext(hMap);
  927. if (CurrentLine != NULL) {
  928. map_ParseGroup(CurrentLine->Line, Name, NewName);
  929. if (lstrlen(Name)) {
  930. lstrcpy(GroupBuffer[ActualEntries].Name, Name);
  931. lstrcpy(GroupBuffer[ActualEntries].NewName, NewName);
  932. if (lstrcmpi(Name, NewName))
  933. GroupBuffer[ActualEntries].IsNewName = TRUE;
  934. ActualEntries++;
  935. }
  936. }
  937. }
  938. if (ActualEntries != Entries)
  939. GroupList = (GROUP_LIST *) ReallocMemory((HGLOBAL) GroupList, sizeof(GROUP_LIST) + (sizeof(GROUP_BUFFER)* ActualEntries));
  940. if (GroupList == NULL)
  941. ret = ERROR_NOT_ENOUGH_MEMORY;
  942. else
  943. GroupList->Count = ActualEntries;
  944. *lpGroups = GroupList;
  945. }
  946. return ret;
  947. } // map_GroupsEnum
  948. /*+-------------------------------------------------------------------------+
  949. | MapFileWrite()
  950. |
  951. +-------------------------------------------------------------------------+*/
  952. BOOL MapFileWrite(HANDLE hFile, LPTSTR String) {
  953. DWORD wrote;
  954. static char tmpStr[MAX_LINE_LEN + 1];
  955. WideCharToMultiByte(CP_ACP, 0, String, -1, tmpStr, sizeof(tmpStr), NULL, NULL);
  956. if (!WriteFile(hFile, tmpStr, strlen(tmpStr), &wrote, NULL))
  957. return FALSE;
  958. return TRUE;
  959. } // MapFileWrite
  960. /*+-------------------------------------------------------------------------+
  961. | MapFileOpen()
  962. |
  963. +-------------------------------------------------------------------------+*/
  964. HANDLE MapFileOpen(LPTSTR FileNameW) {
  965. int ret;
  966. HANDLE hFile = NULL;
  967. char FileName[MAX_PATH + 1];
  968. WideCharToMultiByte(CP_ACP, 0, FileNameW, -1, FileName, sizeof(FileName), NULL, NULL);
  969. DeleteFile(FileNameW);
  970. // Now do the actual creation with error handling...
  971. do {
  972. ret = IDOK;
  973. hFile = CreateFileA( FileName, GENERIC_WRITE, 0, NULL, CREATE_NEW,
  974. FILE_ATTRIBUTE_NORMAL, NULL );
  975. if (hFile == INVALID_HANDLE_VALUE)
  976. ret = ErrorBoxRetry(Lids(IDS_MAPCREATEFAIL));
  977. } while(ret == IDRETRY);
  978. return(hFile);
  979. } // MapFileOpen
  980. /*+-------------------------------------------------------------------------+
  981. | MappingFileCreate()
  982. |
  983. | Creates a mapping file. This allows the admin to specify for each
  984. | user a new username and password.
  985. |
  986. +-------------------------------------------------------------------------+*/
  987. BOOL MappingFileCreate(LPTSTR FileName, LPTSTR Server) {
  988. BOOL status = FALSE;
  989. DWORD ret = 0;
  990. USER_LIST *Users;
  991. DWORD UserCount;
  992. GROUP_LIST *Groups;
  993. GROUP_BUFFER *GroupBuffer;
  994. USER_BUFFER *UserBuffer;
  995. DWORD GroupCount;
  996. int Count;
  997. HANDLE hFile = NULL;
  998. static TCHAR tmpStr[MAX_LINE_LEN + 1];
  999. static TCHAR tmpStr2[MAX_LINE_LEN + 1];
  1000. // Create Empty map file
  1001. hFile = MapFileOpen(FileName);
  1002. if (hFile == INVALID_HANDLE_VALUE)
  1003. return FALSE;
  1004. CursorHourGlass();
  1005. // Now write out header gunk
  1006. status = MapFileWrite(hFile, Lids(IDS_LINE));
  1007. wsprintf(tmpStr, Lids(IDS_M_1), Server);
  1008. wsprintf(tmpStr2, Lids(IDS_BRACE), tmpStr);
  1009. if (status)
  1010. status = MapFileWrite(hFile, tmpStr2);
  1011. wsprintf(tmpStr, Lids(IDS_BRACE), Lids(IDS_M_2));
  1012. if (status)
  1013. status = MapFileWrite(hFile, tmpStr);
  1014. wsprintf(tmpStr, Lids(IDS_BRACE), TEXT(""));
  1015. if (status)
  1016. status = MapFileWrite(hFile, tmpStr);
  1017. wsprintf(tmpStr, Lids(IDS_BRACE), Lids(IDS_M_3));
  1018. if (status)
  1019. status = MapFileWrite(hFile, tmpStr);
  1020. wsprintf(tmpStr, Lids(IDS_BRACE), Lids(IDS_M_4));
  1021. if (status)
  1022. status = MapFileWrite(hFile, tmpStr);
  1023. wsprintf(tmpStr, Lids(IDS_BRACE), TEXT(""));
  1024. if (status)
  1025. status = MapFileWrite(hFile, tmpStr);
  1026. if (status)
  1027. status = MapFileWrite(hFile, Lids(IDS_LINE));
  1028. // [USERS] section header
  1029. if (DoUsers && status)
  1030. status = MapFileWrite(hFile, Lids(IDS_M_5));
  1031. // If anything went wrong with writing header, get out
  1032. if (!status) {
  1033. CursorNormal();
  1034. return FALSE;
  1035. }
  1036. // Header is all done - now lets do the actual users and such
  1037. if (!(ret = NWServerSet(Server))) {
  1038. //
  1039. // If users were selected then put them into the map file
  1040. //
  1041. if (DoUsers) {
  1042. if (!NWUsersEnum(&Users, FALSE) && (Users != NULL)) {
  1043. UserCount = Users->Count;
  1044. UserBuffer = Users->UserBuffer;
  1045. for (Count = 0; Count < (int) UserCount; Count++) {
  1046. if (status) {
  1047. switch(PasswordOption) {
  1048. case 0: // No password
  1049. wsprintf(tmpStr, TEXT("%s, %s,\r\n"), UserBuffer[Count].Name, UserBuffer[Count].Name);
  1050. break;
  1051. case 1: // Password is username
  1052. wsprintf(tmpStr, TEXT("%s, %s, %s\r\n"), UserBuffer[Count].Name, UserBuffer[Count].Name, UserBuffer[Count].Name);
  1053. break;
  1054. case 2: // Password is constant
  1055. wsprintf(tmpStr, TEXT("%s, %s, %s\r\n"), UserBuffer[Count].Name, UserBuffer[Count].Name, PasswordConstant);
  1056. break;
  1057. }
  1058. status = MapFileWrite(hFile, tmpStr);
  1059. }
  1060. }
  1061. FreeMemory((LPBYTE) Users);
  1062. }
  1063. }
  1064. //
  1065. // If groups were selected then put them in map file
  1066. //
  1067. if (DoGroups) {
  1068. // [GROUPS] section header
  1069. if (status)
  1070. status = MapFileWrite(hFile, Lids(IDS_M_6));
  1071. if (!NWGroupsEnum(&Groups, FALSE) && (Groups != NULL)) {
  1072. GroupCount = Groups->Count;
  1073. GroupBuffer = Groups->GroupBuffer;
  1074. for (Count = 0; Count < (int) GroupCount; Count++) {
  1075. if (status) {
  1076. wsprintf(tmpStr, TEXT("%s, %s\r\n"), GroupBuffer[Count].Name, GroupBuffer[Count].Name);
  1077. status = MapFileWrite(hFile, tmpStr);
  1078. }
  1079. }
  1080. FreeMemory((LPBYTE) Groups);
  1081. }
  1082. }
  1083. NWServerFree();
  1084. }
  1085. CloseHandle( hFile );
  1086. CursorNormal();
  1087. return status;
  1088. } // MappingFileCreate
  1089. /*+-------------------------------------------------------------------------+
  1090. | MappingFileNameResolve()
  1091. |
  1092. +-------------------------------------------------------------------------+*/
  1093. BOOL MappingFileNameResolve(HWND hDlg) {
  1094. HWND hCtrl;
  1095. static char FileNameA[MAX_PATH + 1];
  1096. static char CmdLine[MAX_PATH + 1 + 12]; // Editor + file
  1097. TCHAR drive[MAX_DRIVE + 1];
  1098. TCHAR dir[MAX_PATH + 1];
  1099. TCHAR fname[MAX_PATH + 1];
  1100. TCHAR ext[_MAX_EXT + 1];
  1101. UINT uReturn;
  1102. BOOL ret = TRUE;
  1103. // First check filename
  1104. hCtrl = GetDlgItem(hDlg, IDC_MAPPINGFILE);
  1105. * (WORD *)MappingFile = sizeof(MappingFile);
  1106. SendMessage(hCtrl, EM_GETLINE, 0, (LPARAM) MappingFile);
  1107. lsplitpath(MappingFile, drive, dir, fname, ext);
  1108. // remake path so it is fully qualified
  1109. if ((drive[0] == TEXT('\0')) && (dir[0] == TEXT('\0')))
  1110. lstrcpy(dir, ProgPath);
  1111. if (ext[0] == TEXT('\0'))
  1112. lstrcpy(ext, Lids(IDS_S_36));
  1113. lmakepath(MappingFile, drive, dir, fname, ext);
  1114. if (MappingFileCreate(MappingFile, SourceServ)) {
  1115. if (MessageBox(hDlg, Lids(IDS_MAPCREATED), Lids(IDS_APPNAME), MB_YESNO | MB_ICONQUESTION) == IDYES) {
  1116. WideCharToMultiByte(CP_ACP, 0, MappingFile, -1, FileNameA, sizeof(FileNameA), NULL, NULL);
  1117. wsprintfA(CmdLine, "Notepad %s", FileNameA);
  1118. uReturn = WinExec(CmdLine, SW_SHOW);
  1119. }
  1120. } else {
  1121. MessageBox(hDlg, Lids(IDS_MAPCREATEFAIL), Lids(IDS_TXTWARNING), MB_OK);
  1122. ret = FALSE;
  1123. }
  1124. return ret;
  1125. } // MappingFileNameResolve
  1126. /*+-------------------------------------------------------------------------+
  1127. | MapCreate()
  1128. |
  1129. +-------------------------------------------------------------------------+*/
  1130. LRESULT CALLBACK MapCreateProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam) {
  1131. HWND hCtrl;
  1132. int wmId, wmEvent;
  1133. static short UserNameTab, GroupNameTab, PasswordsTab, DefaultsTab;
  1134. switch (message) {
  1135. case WM_INITDIALOG:
  1136. // Center the dialog over the application window
  1137. CenterWindow (hDlg, GetWindow (hDlg, GW_OWNER));
  1138. // limit edit field lengths
  1139. hCtrl = GetDlgItem(hDlg, IDC_MAPPINGFILE);
  1140. PostMessage(hCtrl, EM_LIMITTEXT, (WPARAM) MAX_PATH, 0);
  1141. hCtrl = GetDlgItem(hDlg, IDC_PWCONST);
  1142. PostMessage(hCtrl, EM_LIMITTEXT, (WPARAM) MAX_PW_LEN, 0);
  1143. // set mapping file name and init OK button appropriatly
  1144. hCtrl = GetDlgItem(hDlg, IDC_MAPPINGFILE);
  1145. SendMessage(hCtrl, WM_SETTEXT, 0, (LPARAM) MappingFile);
  1146. hCtrl = GetDlgItem(hDlg, IDC_MAPPINGFILE);
  1147. if (SendMessage(hCtrl, EM_LINELENGTH, 0, 0)) {
  1148. hCtrl = GetDlgItem(hDlg, IDOK);
  1149. EnableWindow(hCtrl, TRUE);
  1150. } else {
  1151. hCtrl = GetDlgItem(hDlg, IDOK);
  1152. EnableWindow(hCtrl, FALSE);
  1153. }
  1154. // check Users and Groups checkbox's
  1155. hCtrl = GetDlgItem(hDlg, IDC_USERS);
  1156. SendMessage(hCtrl, BM_SETCHECK, 1, 0);
  1157. hCtrl = GetDlgItem(hDlg, IDC_GROUPS);
  1158. SendMessage(hCtrl, BM_SETCHECK, 1, 0);
  1159. CheckRadioButton(hDlg, IDC_RADIO1, IDC_RADIO3, IDC_RADIO1);
  1160. return (TRUE);
  1161. case WM_COMMAND:
  1162. wmId = LOWORD(wParam);
  1163. wmEvent = HIWORD(wParam);
  1164. switch (wmId) {
  1165. // [OK] button
  1166. case IDOK:
  1167. // Figure out what password option is checked...
  1168. hCtrl = GetDlgItem(hDlg, IDC_RADIO1);
  1169. if (SendMessage(hCtrl, BM_GETCHECK, 0, 0) == 1)
  1170. PasswordOption = 0;
  1171. hCtrl = GetDlgItem(hDlg, IDC_RADIO2);
  1172. if (SendMessage(hCtrl, BM_GETCHECK, 0, 0) == 1)
  1173. PasswordOption = 1;
  1174. hCtrl = GetDlgItem(hDlg, IDC_RADIO3);
  1175. if (SendMessage(hCtrl, BM_GETCHECK, 0, 0) == 1)
  1176. PasswordOption = 2;
  1177. hCtrl = GetDlgItem(hDlg, IDC_PWCONST);
  1178. * (WORD *)PasswordConstant = sizeof(PasswordConstant);
  1179. SendMessage(hCtrl, EM_GETLINE, 0, (LPARAM) PasswordConstant);
  1180. EnableWindow(hDlg, FALSE);
  1181. MappingFileNameResolve(hDlg);
  1182. EnableWindow(hDlg, TRUE);
  1183. EndDialog(hDlg, 0);
  1184. return (TRUE);
  1185. break;
  1186. // [CANCEL] button
  1187. case IDCANCEL:
  1188. EndDialog(hDlg, 0);
  1189. return (TRUE);
  1190. break;
  1191. // [HELP] button
  1192. case IDHELP:
  1193. WinHelp(hDlg, HELP_FILE, HELP_CONTEXT, (DWORD) IDC_HELP_CMAP);
  1194. return (TRUE);
  1195. break;
  1196. // Checkbox for Users
  1197. case IDC_USERS:
  1198. DoUsers = !DoUsers;
  1199. hCtrl = GetDlgItem(hDlg, IDC_RADIO1);
  1200. EnableWindow(hCtrl, DoUsers);
  1201. hCtrl = GetDlgItem(hDlg, IDC_RADIO2);
  1202. EnableWindow(hCtrl, DoUsers);
  1203. hCtrl = GetDlgItem(hDlg, IDC_RADIO3);
  1204. EnableWindow(hCtrl, DoUsers);
  1205. hCtrl = GetDlgItem(hDlg, IDC_PWCONST);
  1206. EnableWindow(hCtrl, DoUsers);
  1207. return (TRUE);
  1208. break;
  1209. // Checkbox for Groups
  1210. case IDC_GROUPS:
  1211. DoGroups = !DoGroups;
  1212. return (TRUE);
  1213. break;
  1214. // Edit field for password constant
  1215. case IDC_PWCONST:
  1216. if (wmEvent == EN_CHANGE)
  1217. CheckRadioButton(hDlg, IDC_RADIO1, IDC_RADIO3, IDC_RADIO3);
  1218. break;
  1219. // Edit field for password constant
  1220. case IDC_MAPPINGFILE:
  1221. if (wmEvent == EN_CHANGE) {
  1222. hCtrl = GetDlgItem(hDlg, IDC_MAPPINGFILE);
  1223. if (SendMessage(hCtrl, EM_LINELENGTH, 0, 0)) {
  1224. hCtrl = GetDlgItem(hDlg, IDOK);
  1225. EnableWindow(hCtrl, TRUE);
  1226. } else {
  1227. hCtrl = GetDlgItem(hDlg, IDOK);
  1228. EnableWindow(hCtrl, FALSE);
  1229. }
  1230. }
  1231. break;
  1232. // [...] button for mapping file
  1233. case IDC_BTNMAPPINGFILE:
  1234. // Let the user browse for a file
  1235. if (!UserFileGet(hDlg, MappingFile)) {
  1236. hCtrl = GetDlgItem(hDlg, IDC_MAPPINGFILE);
  1237. SendMessage(hCtrl, WM_SETTEXT, 0, (LPARAM) MappingFile);
  1238. SetFocus(hCtrl);
  1239. }
  1240. return (TRUE);
  1241. break;
  1242. }
  1243. break;
  1244. }
  1245. return (FALSE); // Didn't process the message
  1246. lParam;
  1247. } // MapCreateProc
  1248. /*+-------------------------------------------------------------------------+
  1249. | MapFileCreate()
  1250. |
  1251. +-------------------------------------------------------------------------+*/
  1252. BOOL MapFileCreate(HWND hDlg, LPTSTR FileName, LPTSTR Server) {
  1253. DLGPROC lpfnDlg;
  1254. DoUsers = TRUE;
  1255. DoGroups = TRUE;
  1256. PasswordOption = 0;
  1257. lstrcpy(MappingFile, FileName);
  1258. lstrcpy(PasswordConstant, TEXT(""));
  1259. SourceServ = Server;
  1260. lpfnDlg = MakeProcInstance((DLGPROC)MapCreateProc, hInst);
  1261. DialogBox(hInst, TEXT("MAPCreate"), hDlg, lpfnDlg) ;
  1262. FreeProcInstance(lpfnDlg);
  1263. lstrcpy(FileName, MappingFile);
  1264. return TRUE;
  1265. } // MapFileCreate