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.

2064 lines
49 KiB

  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <lm.h>
  4. #include "resource.h"
  5. #include <tapi.h>
  6. #if MEMPHIS
  7. #else
  8. #include "ntsecapi.h"
  9. #endif
  10. HINSTANCE ghInstance;
  11. HWND ghWnd;
  12. BOOLEAN gfQuietMode = FALSE;
  13. DWORD gdwNoDSQuery = 0;
  14. DWORD gdwConnectionOrientedOnly = 0;
  15. #if MEMPHIS
  16. #else
  17. const TCHAR gszProductType[] = TEXT("ProductType");
  18. const TCHAR gszProductTypeServer[] = TEXT("ServerNT");
  19. const TCHAR gszProductTypeLanmanNt[] = TEXT("LANMANNT");
  20. const TCHAR gszRegKeyNTServer[] = TEXT("System\\CurrentControlSet\\Control\\ProductOptions");
  21. #endif
  22. const TCHAR gszRegKeyProviders[] = TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Telephony\\Providers");
  23. const TCHAR gszRegKeyTelephony[] = TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Telephony");
  24. const TCHAR gszProviderID[] = TEXT("ProviderID");
  25. const TCHAR gszNumProviders[] = TEXT("NumProviders");
  26. const TCHAR gszNextProviderID[] = TEXT("NextProviderID");
  27. const TCHAR gszProviderFilename[] = TEXT("ProviderFilename");
  28. const TCHAR gszRemoteSP[] = TEXT("RemoteSP.TSP");
  29. const TCHAR gszProvider[] = TEXT("Provider");
  30. const TCHAR gszServer[] = TEXT("Server");
  31. const TCHAR gszNumServers[] = TEXT("NumServers");
  32. const TCHAR gszConnectionOrientedOnly[] = TEXT("ConnectionOrientedOnly");
  33. const TCHAR gszNoDSQuery[] = TEXT("NoDSQuery");
  34. #define MAXERRORTEXTLEN 512
  35. TCHAR gszTapiAdminSetup[MAXERRORTEXTLEN];
  36. LPTSTR glpszFullName = NULL;
  37. LPTSTR glpszPassword= NULL;
  38. LPTSTR glpszMapper = NULL;
  39. LPTSTR glpszDllList = NULL;
  40. LPTSTR glpszRemoteServer = NULL;
  41. BOOL
  42. CALLBACK
  43. DlgProc(
  44. HWND hwndDlg,
  45. UINT uMsg,
  46. WPARAM wParam,
  47. LPARAM lParam
  48. );
  49. #if MEMPHIS
  50. #else
  51. BOOL
  52. IsAdministrator(
  53. );
  54. BOOL
  55. DoServer(
  56. LPTSTR lpszServerLine
  57. );
  58. #endif
  59. BOOL
  60. DoClient(
  61. LPTSTR lpszClientLine
  62. );
  63. //*****************************************************************************
  64. //*****************************************************************************
  65. //*****************************************************************************
  66. UINT TAPIstrlen( const TCHAR *p )
  67. {
  68. UINT nLength = 0;
  69. while ( *p )
  70. {
  71. nLength++;
  72. p++;
  73. }
  74. return nLength;
  75. }
  76. //*****************************************************************************
  77. //*****************************************************************************
  78. //*****************************************************************************
  79. void TAPIstrcat( TCHAR *p1, const TCHAR *p2 )
  80. {
  81. while ( *p1 )
  82. {
  83. p1++;
  84. }
  85. while ( *p2 )
  86. {
  87. *p1 = *p2;
  88. p1++;
  89. p2++;
  90. }
  91. return;
  92. }
  93. //*****************************************************************************
  94. //*****************************************************************************
  95. //*****************************************************************************
  96. void
  97. ErrorStr(
  98. int iMsg
  99. )
  100. {
  101. TCHAR szError[MAXERRORTEXTLEN];
  102. if ( !gfQuietMode )
  103. {
  104. if (LoadString(
  105. ghInstance,
  106. iMsg,
  107. szError,
  108. MAXERRORTEXTLEN
  109. ))
  110. {
  111. MessageBox(
  112. NULL,
  113. szError,
  114. gszTapiAdminSetup,
  115. MB_OK
  116. );
  117. }
  118. }
  119. }
  120. void
  121. ShowHelp()
  122. {
  123. TCHAR szError[MAXERRORTEXTLEN];
  124. LPTSTR szBuffer;
  125. if (gfQuietMode)
  126. {
  127. return;
  128. }
  129. szBuffer = (LPTSTR)GlobalAlloc(
  130. GPTR,
  131. 11 * MAXERRORTEXTLEN * sizeof(TCHAR)
  132. );
  133. if (!szBuffer)
  134. {
  135. return;
  136. }
  137. LoadString(
  138. ghInstance,
  139. iszHelp0,
  140. szBuffer,
  141. MAXERRORTEXTLEN
  142. );
  143. if (LoadString(
  144. ghInstance,
  145. iszHelp1,
  146. szError,
  147. MAXERRORTEXTLEN
  148. ))
  149. {
  150. TAPIstrcat(
  151. szBuffer,
  152. szError
  153. );
  154. }
  155. if (LoadString(
  156. ghInstance,
  157. iszHelp2,
  158. szError,
  159. MAXERRORTEXTLEN
  160. ))
  161. {
  162. TAPIstrcat(
  163. szBuffer,
  164. szError
  165. );
  166. }
  167. if (LoadString(
  168. ghInstance,
  169. iszHelp3,
  170. szError,
  171. MAXERRORTEXTLEN
  172. ))
  173. {
  174. TAPIstrcat(
  175. szBuffer,
  176. szError
  177. );
  178. }
  179. if (LoadString(
  180. ghInstance,
  181. iszHelp4,
  182. szError,
  183. MAXERRORTEXTLEN
  184. ))
  185. {
  186. TAPIstrcat(
  187. szBuffer,
  188. szError
  189. );
  190. }
  191. if (LoadString(
  192. ghInstance,
  193. iszHelp5,
  194. szError,
  195. MAXERRORTEXTLEN
  196. ))
  197. {
  198. TAPIstrcat(
  199. szBuffer,
  200. szError
  201. );
  202. }
  203. if (LoadString(
  204. ghInstance,
  205. iszHelp6,
  206. szError,
  207. MAXERRORTEXTLEN
  208. ))
  209. {
  210. TAPIstrcat(
  211. szBuffer,
  212. szError
  213. );
  214. }
  215. if (LoadString(
  216. ghInstance,
  217. iszHelp7,
  218. szError,
  219. MAXERRORTEXTLEN
  220. ))
  221. {
  222. TAPIstrcat(
  223. szBuffer,
  224. szError
  225. );
  226. }
  227. if (LoadString(
  228. ghInstance,
  229. iszHelp8,
  230. szError,
  231. MAXERRORTEXTLEN
  232. ))
  233. {
  234. TAPIstrcat(
  235. szBuffer,
  236. szError
  237. );
  238. }
  239. if (LoadString(
  240. ghInstance,
  241. iszHelp9,
  242. szError,
  243. MAXERRORTEXTLEN
  244. ))
  245. {
  246. TAPIstrcat(
  247. szBuffer,
  248. szError
  249. );
  250. }
  251. if (LoadString(
  252. ghInstance,
  253. iszHelp10,
  254. szError,
  255. MAXERRORTEXTLEN
  256. ))
  257. {
  258. TAPIstrcat(
  259. szBuffer,
  260. szError
  261. );
  262. }
  263. LoadString(
  264. ghInstance,
  265. iszHelpTitle,
  266. szError,
  267. MAXERRORTEXTLEN
  268. );
  269. MessageBox(
  270. NULL,
  271. szBuffer,
  272. szError,
  273. MB_OK
  274. );
  275. GlobalFree (szBuffer);
  276. }
  277. LPTSTR
  278. GetNextString(
  279. LPTSTR lpszIn
  280. )
  281. {
  282. static LPTSTR lpszLine;
  283. LPTSTR lpszReturn = NULL;
  284. if (lpszIn)
  285. lpszLine = lpszIn;
  286. while (*lpszLine && (*lpszLine == L' ' || *lpszLine == L'\t'))
  287. lpszLine++;
  288. if (!*lpszLine)
  289. return NULL;
  290. lpszReturn = lpszLine;
  291. while (*lpszLine && (*lpszLine != L' ' && *lpszLine != L'\t'))
  292. lpszLine++;
  293. if (*lpszLine)
  294. {
  295. *lpszLine = '\0';
  296. lpszLine++;
  297. }
  298. return lpszReturn;
  299. }
  300. BOOL
  301. ParseCommandLine(
  302. LPTSTR lpszCommandLine
  303. )
  304. {
  305. BOOL bRet = FALSE;
  306. //
  307. // Skip the first segment which is the executable itself
  308. // it is either in double quotes or a string until a white
  309. // space
  310. //
  311. if (*lpszCommandLine == TEXT('\"'))
  312. {
  313. ++lpszCommandLine;
  314. while (*lpszCommandLine &&
  315. *lpszCommandLine != TEXT('\"'))
  316. {
  317. ++lpszCommandLine;
  318. }
  319. if (*lpszCommandLine == TEXT('\"'))
  320. {
  321. ++lpszCommandLine;
  322. }
  323. }
  324. else
  325. {
  326. while (
  327. *lpszCommandLine &&
  328. *lpszCommandLine != TEXT(' ') &&
  329. *lpszCommandLine != TEXT('\t') &&
  330. *lpszCommandLine != 0x0a &&
  331. *lpszCommandLine != 0x0d)
  332. {
  333. ++lpszCommandLine;
  334. }
  335. }
  336. while (*lpszCommandLine)
  337. {
  338. //
  339. // Search for / or - as the start of option
  340. //
  341. while (*lpszCommandLine == TEXT(' ') ||
  342. *lpszCommandLine == TEXT('\t') ||
  343. *lpszCommandLine == 0x0a ||
  344. *lpszCommandLine == 0x0d)
  345. {
  346. lpszCommandLine++;
  347. }
  348. if (*lpszCommandLine != TEXT('/') &&
  349. *lpszCommandLine != TEXT('-'))
  350. {
  351. break;
  352. }
  353. ++lpszCommandLine;
  354. if ( (L'r' == *lpszCommandLine) ||
  355. (L'R' == *lpszCommandLine)
  356. )
  357. {
  358. ++lpszCommandLine;
  359. if (*lpszCommandLine == TEXT(' ') ||
  360. *lpszCommandLine == TEXT('\t') ||
  361. *lpszCommandLine == 0x0a ||
  362. *lpszCommandLine == 0x0d)
  363. {
  364. gdwNoDSQuery = (DWORD) TRUE;
  365. }
  366. else
  367. {
  368. break;
  369. }
  370. }
  371. else if ( (L'q' == *lpszCommandLine) ||
  372. (L'Q' == *lpszCommandLine))
  373. {
  374. ++lpszCommandLine;
  375. if (*lpszCommandLine == TEXT(' ') ||
  376. *lpszCommandLine == TEXT('\t') ||
  377. *lpszCommandLine == 0x0a ||
  378. *lpszCommandLine == 0x0d)
  379. {
  380. gfQuietMode = TRUE;
  381. }
  382. else
  383. {
  384. break;
  385. }
  386. }
  387. else if ((L'x' == *lpszCommandLine) ||
  388. (L'X' == *lpszCommandLine))
  389. {
  390. ++lpszCommandLine;
  391. if (*lpszCommandLine == TEXT(' ') ||
  392. *lpszCommandLine == TEXT('\t') ||
  393. *lpszCommandLine == 0x0a ||
  394. *lpszCommandLine == 0x0d)
  395. {
  396. gdwConnectionOrientedOnly = 1;
  397. }
  398. else
  399. {
  400. break;
  401. }
  402. }
  403. else if ((L'c' == *lpszCommandLine) ||
  404. (L'C' == *lpszCommandLine))
  405. {
  406. ++lpszCommandLine;
  407. if (*lpszCommandLine == TEXT(' ') ||
  408. *lpszCommandLine == TEXT('\t') ||
  409. *lpszCommandLine == 0x0a ||
  410. *lpszCommandLine == 0x0d)
  411. {
  412. bRet = DoClient(++lpszCommandLine);
  413. }
  414. break;
  415. }
  416. else
  417. {
  418. break;
  419. }
  420. }
  421. return bRet;
  422. }
  423. int WINAPI WinMain (HINSTANCE hInstance,
  424. HINSTANCE hPrevInstance,
  425. LPSTR lpszCmdLine,
  426. int nCmdShow)
  427. {
  428. LPTSTR lpszCommandLine;
  429. ghInstance = GetModuleHandle( NULL );
  430. LoadString(
  431. ghInstance,
  432. iszTapiAdminSetup,
  433. gszTapiAdminSetup,
  434. MAXERRORTEXTLEN
  435. );
  436. #if MEMPHIS
  437. #else
  438. if (!IsAdministrator())
  439. {
  440. ErrorStr(iszMustBeAdmin);
  441. return 1;
  442. }
  443. #endif
  444. lpszCommandLine = GetCommandLine();
  445. if (!lpszCommandLine)
  446. {
  447. return 2;
  448. }
  449. if (!(ParseCommandLine(
  450. lpszCommandLine
  451. )))
  452. {
  453. ShowHelp();
  454. }
  455. return 0;
  456. }
  457. #if MEMPHIS
  458. #else
  459. BOOL
  460. IsServer()
  461. {
  462. HKEY hKey;
  463. DWORD dwDataSize;
  464. DWORD dwDataType;
  465. TCHAR szProductType[64];
  466. // check to see if this is running on NT Server
  467. // if so, enable the telephony server stuff
  468. if (ERROR_SUCCESS !=
  469. RegOpenKeyEx(
  470. HKEY_LOCAL_MACHINE,
  471. gszRegKeyNTServer,
  472. 0,
  473. KEY_ALL_ACCESS,
  474. &hKey
  475. ))
  476. {
  477. return FALSE;
  478. }
  479. dwDataSize = 64;
  480. RegQueryValueEx(
  481. hKey,
  482. gszProductType,
  483. 0,
  484. &dwDataType,
  485. (LPBYTE) szProductType,
  486. &dwDataSize
  487. );
  488. RegCloseKey(
  489. hKey
  490. );
  491. if ((!lstrcmpi(
  492. szProductType,
  493. gszProductTypeServer
  494. ))
  495. ||
  496. (!lstrcmpi(
  497. szProductType,
  498. gszProductTypeLanmanNt
  499. )))
  500. {
  501. return TRUE;
  502. }
  503. ErrorStr(iszNotRunningServer);
  504. return FALSE;
  505. }
  506. ////////////////////////////////////////////////////////////////////
  507. //
  508. // Set the disableserver key to true
  509. //
  510. BOOL
  511. DisableServer()
  512. {
  513. HKEY hKeyTelephony, hKey;
  514. DWORD dw;
  515. if ((RegOpenKeyEx(
  516. HKEY_LOCAL_MACHINE,
  517. gszRegKeyTelephony,
  518. 0,
  519. KEY_ALL_ACCESS,
  520. &hKeyTelephony
  521. ) != ERROR_SUCCESS) ||
  522. (RegCreateKeyEx(
  523. hKeyTelephony,
  524. TEXT("Server"),
  525. 0,
  526. NULL,
  527. REG_OPTION_NON_VOLATILE,
  528. KEY_ALL_ACCESS,
  529. NULL,
  530. &hKey,
  531. &dw
  532. ) != ERROR_SUCCESS))
  533. {
  534. return FALSE;
  535. }
  536. dw=1;
  537. if (RegSetValueEx(
  538. hKey,
  539. TEXT("DisableSharing"),
  540. 0,
  541. REG_DWORD,
  542. (LPBYTE)&dw,
  543. sizeof(dw)
  544. ) != ERROR_SUCCESS)
  545. {
  546. return FALSE;
  547. }
  548. RegCloseKey(hKey);
  549. RegCloseKey(hKeyTelephony);
  550. return TRUE;
  551. }
  552. //////////////////////////////////////////////////////////
  553. //
  554. // Determine if the currently logged on person is an admin
  555. //
  556. BOOL
  557. IsAdministrator(
  558. )
  559. {
  560. PSID psidAdministrators;
  561. BOOL bResult = FALSE;
  562. SID_IDENTIFIER_AUTHORITY siaNtAuthority = SECURITY_NT_AUTHORITY;
  563. if (AllocateAndInitializeSid(
  564. &siaNtAuthority,
  565. 2,
  566. SECURITY_BUILTIN_DOMAIN_RID,
  567. DOMAIN_ALIAS_RID_ADMINS,
  568. 0, 0, 0, 0, 0, 0,
  569. &psidAdministrators
  570. ))
  571. {
  572. CheckTokenMembership (NULL, psidAdministrators, &bResult);
  573. FreeSid (psidAdministrators);
  574. }
  575. return bResult;
  576. }
  577. ////////////////////////////////////////////////////////////////////
  578. //
  579. // Determine the name of 'Administrators' group
  580. //
  581. BOOL LookupAdministratorsAlias(
  582. LPWSTR Name,
  583. PDWORD cchName
  584. )
  585. {
  586. SID_IDENTIFIER_AUTHORITY sia = SECURITY_NT_AUTHORITY;
  587. SID_NAME_USE snu;
  588. PSID pSid;
  589. WCHAR DomainName[DNLEN+1];
  590. DWORD cchDomainName = DNLEN;
  591. BOOL bSuccess = FALSE;
  592. //
  593. // Sid is the same regardless of machine, since the well-known
  594. // BUILTIN domain is referenced.
  595. //
  596. if(AllocateAndInitializeSid(
  597. &sia,
  598. 2,
  599. SECURITY_BUILTIN_DOMAIN_RID,
  600. DOMAIN_ALIAS_RID_ADMINS,
  601. 0, 0, 0, 0, 0, 0,
  602. &pSid
  603. ))
  604. {
  605. bSuccess = LookupAccountSidW(
  606. NULL,
  607. pSid,
  608. Name,
  609. cchName,
  610. DomainName,
  611. &cchDomainName,
  612. &snu
  613. );
  614. FreeSid(pSid);
  615. }
  616. return bSuccess;
  617. }
  618. ////////////////////////////////////////////////////////////////////
  619. //
  620. // Determine if the person specified is an administrator
  621. //
  622. BOOL
  623. IsUserAdministrator(
  624. LPTSTR lpszFullName
  625. )
  626. {
  627. DWORD dwRead, dwTotal, x;
  628. NET_API_STATUS nas;
  629. LPLOCALGROUP_USERS_INFO_0 pGroups = NULL;
  630. LPWSTR lpszNewFullName;
  631. #define MAXADMINLEN 256
  632. WCHAR szAdministrators[MAXADMINLEN];
  633. #ifndef UNICODE
  634. DWORD dwSize;
  635. dwSize = (TAPIstrlen( lpszFullName ) + 1) * sizeof( WCHAR );
  636. if (!(lpszNewFullName = (LPWSTR) GlobalAlloc (GPTR, dwSize)))
  637. {
  638. return FALSE;
  639. }
  640. MultiByteToWideChar(
  641. CP_ACP,
  642. MB_PRECOMPOSED,
  643. lpszFullName,
  644. -1,
  645. lpszNewFullName,
  646. dwSize
  647. );
  648. #else
  649. lpszNewFullName = lpszFullName;
  650. #endif
  651. // First, get the name of the 'Administrators' group.
  652. // Normally, this will be Administrators, but the use
  653. // can change it (also, it will be different for foreign
  654. // versions of NT)
  655. dwTotal = sizeof(szAdministrators)/sizeof(WCHAR); // reuse dwTotal
  656. if (!(LookupAdministratorsAlias(
  657. szAdministrators,
  658. &dwTotal
  659. )))
  660. {
  661. return FALSE;
  662. }
  663. // Next, get all the groups the user is part of
  664. // (directly OR indirectly) and see if administrators
  665. // is among them.
  666. #define MAX_PREFERRED_LEN 4096*2 // 2 pages (or 1 on alpha)
  667. nas = NetUserGetLocalGroups (
  668. NULL, // server
  669. lpszNewFullName, // user name
  670. 0, // level
  671. LG_INCLUDE_INDIRECT, // flags
  672. (PBYTE*)&pGroups, // output buffer
  673. MAX_PREFERRED_LEN, // preferred maximum length
  674. &dwRead, // entries read
  675. &dwTotal // total entries
  676. );
  677. if (NERR_Success != nas)
  678. {
  679. return FALSE;
  680. }
  681. for (x = 0; x < dwRead; x++)
  682. {
  683. if (lstrcmpiW(
  684. pGroups[x].lgrui0_name,
  685. szAdministrators
  686. ) == 0)
  687. {
  688. break;
  689. }
  690. }
  691. NetApiBufferFree ((PVOID)pGroups);
  692. if (x < dwRead)
  693. {
  694. return TRUE;
  695. }
  696. ErrorStr(iszUserNotAdmin);
  697. return FALSE;
  698. }
  699. /////////////////////////////////////////////////////////////////////
  700. //
  701. // Write out server registry keys
  702. //
  703. BOOL
  704. WriteRegistryKeys(
  705. LPTSTR lpszMapper,
  706. LPTSTR lpszDlls
  707. )
  708. {
  709. HKEY hKeyTelephony, hKey;
  710. DWORD dw;
  711. if ((RegOpenKeyEx(
  712. HKEY_LOCAL_MACHINE,
  713. TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Telephony"),
  714. 0,
  715. KEY_ALL_ACCESS,
  716. &hKeyTelephony
  717. ) != ERROR_SUCCESS) ||
  718. (RegCreateKeyEx(
  719. hKeyTelephony,
  720. TEXT("Server"),
  721. 0,
  722. NULL,
  723. REG_OPTION_NON_VOLATILE,
  724. KEY_ALL_ACCESS,
  725. NULL,
  726. &hKey,
  727. &dw
  728. ) != ERROR_SUCCESS)
  729. )
  730. {
  731. return FALSE;
  732. }
  733. dw=0;
  734. if ((RegSetValueEx(
  735. hKey,
  736. TEXT("DisableSharing"),
  737. 0,
  738. REG_DWORD,
  739. (LPBYTE)&dw,
  740. sizeof(dw)
  741. ) != ERROR_SUCCESS) ||
  742. (RegSetValueEx(
  743. hKey,
  744. TEXT("MapperDll"),
  745. 0,
  746. REG_SZ,
  747. // (LPBYTE)lpszMapper,
  748. (LPBYTE)TEXT("TSEC.DLL"),
  749. // (TAPIstrlen(lpszMapper)+1)*sizeof(TCHAR)
  750. (TAPIstrlen(TEXT("TSEC.DLL"))+1)*sizeof(TCHAR)
  751. ) != ERROR_SUCCESS))
  752. {
  753. RegCloseKey(hKey);
  754. RegCloseKey(hKeyTelephony);
  755. return FALSE;
  756. }
  757. if (lpszDlls)
  758. {
  759. if (RegSetValueEx(
  760. hKey,
  761. TEXT("ManagementDlls"),
  762. 0,
  763. REG_SZ,
  764. (LPBYTE)lpszDlls,
  765. (TAPIstrlen(lpszDlls)+1)*sizeof(TCHAR)
  766. ) != ERROR_SUCCESS)
  767. {
  768. RegCloseKey(hKey);
  769. RegCloseKey(hKeyTelephony);
  770. return FALSE;
  771. }
  772. }
  773. else
  774. {
  775. RegDeleteValue(
  776. hKey,
  777. TEXT("ManagementDlls")
  778. );
  779. }
  780. RegCloseKey(hKey);
  781. RegCloseKey(hKeyTelephony);
  782. return TRUE;
  783. }
  784. //////////////////////////////////////////////////////////////////
  785. //
  786. // Set server setting for the tapisrv service
  787. //
  788. BOOL
  789. DoServiceStuff(
  790. LPTSTR lpszName,
  791. LPTSTR lpszPassword,
  792. BOOL bServer
  793. )
  794. {
  795. SC_HANDLE sch, sc_tapisrv;
  796. BOOL bReturn = TRUE;
  797. if (!(sch = OpenSCManager(
  798. NULL,
  799. NULL,
  800. SC_MANAGER_ENUMERATE_SERVICE
  801. )))
  802. {
  803. return FALSE;
  804. }
  805. if (!(sc_tapisrv = OpenService(
  806. sch,
  807. TEXT("TAPISRV"),
  808. SERVICE_CHANGE_CONFIG
  809. )))
  810. {
  811. CloseHandle(sch);
  812. ErrorStr(iszOpenServiceFailed);
  813. return FALSE;
  814. }
  815. // this sets tapisrv to start as auto, not manual
  816. // and set the log on as person to be the name/password passed in
  817. if (!(ChangeServiceConfig(
  818. sc_tapisrv,
  819. SERVICE_WIN32_OWN_PROCESS,
  820. bServer?SERVICE_AUTO_START:SERVICE_DEMAND_START,
  821. SERVICE_NO_CHANGE,
  822. NULL,
  823. NULL,
  824. NULL,
  825. NULL,
  826. lpszName,
  827. (lpszPassword ? lpszPassword : TEXT("")),
  828. NULL
  829. )))
  830. {
  831. bReturn = FALSE;
  832. }
  833. CloseServiceHandle(sc_tapisrv);
  834. CloseServiceHandle(sch);
  835. return bReturn;
  836. }
  837. NTSTATUS
  838. OpenPolicy(
  839. LPWSTR ServerName, // machine to open policy on (Unicode)
  840. DWORD DesiredAccess, // desired access to policy
  841. PLSA_HANDLE PolicyHandle // resultant policy handle
  842. );
  843. BOOL
  844. GetAccountSid(
  845. LPTSTR SystemName, // where to lookup account
  846. LPTSTR AccountName, // account of interest
  847. PSID *Sid // resultant buffer containing SID
  848. );
  849. NTSTATUS
  850. SetPrivilegeOnAccount(
  851. LSA_HANDLE PolicyHandle, // open policy handle
  852. PSID AccountSid, // SID to grant privilege to
  853. LPWSTR PrivilegeName, // privilege to grant (Unicode)
  854. BOOL bEnable // enable or disable
  855. );
  856. void
  857. InitLsaString(
  858. PLSA_UNICODE_STRING LsaString, // destination
  859. LPWSTR String // source (Unicode)
  860. );
  861. /////////////////////////////////////////////////////
  862. //
  863. // grant the person the right to Log On As A Service
  864. //
  865. BOOL
  866. DoRight(
  867. LPTSTR AccountName,
  868. LPWSTR Right,
  869. BOOL bEnable
  870. )
  871. {
  872. LSA_HANDLE PolicyHandle;
  873. PSID pSid;
  874. NTSTATUS Status;
  875. BOOL bReturn = FALSE;
  876. WCHAR wComputerName[MAX_COMPUTERNAME_LENGTH+1];
  877. DWORD dwSize = MAX_COMPUTERNAME_LENGTH+1;
  878. GetComputerNameW(
  879. wComputerName,
  880. &dwSize
  881. );
  882. //
  883. // Open the policy on the target machine.
  884. //
  885. if((Status=OpenPolicy(
  886. wComputerName, // target machine
  887. POLICY_CREATE_ACCOUNT | POLICY_LOOKUP_NAMES,
  888. &PolicyHandle // resultant policy handle
  889. )) != ERROR_SUCCESS)
  890. {
  891. ErrorStr(iszOpenPolicyFailed);
  892. return FALSE;
  893. }
  894. //
  895. // Obtain the SID of the user/group.
  896. // Note that we could target a specific machine, but we don't.
  897. // Specifying NULL for target machine searches for the SID in the
  898. // following order: well-known, Built-in and local, primary domain,
  899. // trusted domains.
  900. //
  901. if(GetAccountSid(
  902. NULL, // default lookup logic
  903. AccountName,// account to obtain SID
  904. &pSid // buffer to allocate to contain resultant SID
  905. ))
  906. {
  907. PLSA_UNICODE_STRING rights;
  908. DWORD dwcount = 0;
  909. //
  910. // We only grant the privilege if we succeeded in obtaining the
  911. // SID. We can actually add SIDs which cannot be looked up, but
  912. // looking up the SID is a good sanity check which is suitable for
  913. // most cases.
  914. //
  915. // Grant the SeServiceLogonRight to users represented by pSid.
  916. //
  917. LsaEnumerateAccountRights(
  918. PolicyHandle,
  919. pSid,
  920. &rights,
  921. &dwcount
  922. );
  923. if((Status=SetPrivilegeOnAccount(
  924. PolicyHandle, // policy handle
  925. pSid, // SID to grant privilege
  926. Right,//L"SeServiceLogonRight", // Unicode privilege
  927. bEnable // enable the privilege
  928. )) == ERROR_SUCCESS)
  929. {
  930. bReturn = TRUE;
  931. }
  932. else
  933. {
  934. ErrorStr(iszSetPrivilegeOnAccount);
  935. }
  936. }
  937. //
  938. // Close the policy handle.
  939. //
  940. LsaClose(PolicyHandle);
  941. //
  942. // Free memory allocated for SID.
  943. //
  944. if(pSid != NULL) GlobalFree(pSid);
  945. return bReturn;
  946. }
  947. void
  948. InitLsaString(
  949. PLSA_UNICODE_STRING LsaString,
  950. LPWSTR String
  951. )
  952. {
  953. DWORD StringLength;
  954. if (String == NULL) {
  955. LsaString->Buffer = NULL;
  956. LsaString->Length = 0;
  957. LsaString->MaximumLength = 0;
  958. return;
  959. }
  960. StringLength = TAPIstrlen(String);
  961. LsaString->Buffer = String;
  962. LsaString->Length = (USHORT) StringLength * sizeof(WCHAR);
  963. LsaString->MaximumLength=(USHORT)(StringLength+1) * sizeof(WCHAR);
  964. }
  965. NTSTATUS
  966. OpenPolicy(
  967. LPWSTR ServerName,
  968. DWORD DesiredAccess,
  969. PLSA_HANDLE PolicyHandle
  970. )
  971. {
  972. LSA_OBJECT_ATTRIBUTES ObjectAttributes;
  973. LSA_UNICODE_STRING ServerString;
  974. PLSA_UNICODE_STRING Server = NULL;
  975. //
  976. // Always initialize the object attributes to all zeroes.
  977. //
  978. ZeroMemory(&ObjectAttributes, sizeof(ObjectAttributes));
  979. if (ServerName != NULL)
  980. {
  981. //
  982. // Make a LSA_UNICODE_STRING out of the LPTSTR passed in
  983. //
  984. InitLsaString(&ServerString, ServerName);
  985. Server = &ServerString;
  986. }
  987. //
  988. // Attempt to open the policy.
  989. //
  990. return LsaOpenPolicy(
  991. Server,
  992. &ObjectAttributes,
  993. DesiredAccess,
  994. PolicyHandle
  995. );
  996. }
  997. /*++
  998. This function attempts to obtain a SID representing the supplied
  999. account on the supplied system.
  1000. If the function succeeds, the return value is TRUE. A buffer is
  1001. allocated which contains the SID representing the supplied account.
  1002. This buffer should be freed when it is no longer needed by calling
  1003. HeapFree(GetProcessHeap(), 0, buffer)
  1004. If the function fails, the return value is FALSE. Call GetLastError()
  1005. to obtain extended error information.
  1006. Scott Field (sfield) 12-Jul-95
  1007. --*/
  1008. BOOL
  1009. GetAccountSid(
  1010. LPTSTR SystemName,
  1011. LPTSTR AccountName,
  1012. PSID *Sid
  1013. )
  1014. {
  1015. LPTSTR ReferencedDomain=NULL;
  1016. DWORD cbSid=1000; // initial allocation attempt
  1017. DWORD cbReferencedDomain=256; // initial allocation size
  1018. SID_NAME_USE peUse;
  1019. BOOL bSuccess=TRUE; // assume this function will fail
  1020. //
  1021. // initial memory allocations
  1022. //
  1023. if((*Sid=GlobalAlloc(
  1024. GPTR,
  1025. cbSid
  1026. )) == NULL)
  1027. {
  1028. bSuccess = FALSE;
  1029. goto failure;
  1030. }
  1031. if((ReferencedDomain=GlobalAlloc(
  1032. GPTR,
  1033. cbReferencedDomain
  1034. )) == NULL)
  1035. {
  1036. bSuccess = FALSE;
  1037. goto failure;
  1038. }
  1039. //
  1040. // Obtain the SID of the specified account on the specified system.
  1041. //
  1042. if (!LookupAccountName(
  1043. SystemName, // machine to lookup account on
  1044. AccountName, // account to lookup
  1045. *Sid, // SID of interest
  1046. &cbSid, // size of SID
  1047. ReferencedDomain, // domain account was found on
  1048. &cbReferencedDomain,
  1049. &peUse
  1050. ))
  1051. {
  1052. bSuccess = FALSE;
  1053. goto failure;
  1054. }
  1055. failure:
  1056. if (ReferencedDomain)
  1057. {
  1058. GlobalFree(ReferencedDomain);
  1059. }
  1060. if(!bSuccess)
  1061. {
  1062. if(*Sid != NULL)
  1063. {
  1064. GlobalFree(*Sid);
  1065. *Sid = NULL;
  1066. }
  1067. }
  1068. return bSuccess;
  1069. }
  1070. NTSTATUS
  1071. SetPrivilegeOnAccount(
  1072. LSA_HANDLE PolicyHandle, // open policy handle
  1073. PSID AccountSid, // SID to grant privilege to
  1074. LPWSTR PrivilegeName, // privilege to grant (Unicode)
  1075. BOOL bEnable // enable or disable
  1076. )
  1077. {
  1078. LSA_UNICODE_STRING PrivilegeString;
  1079. //
  1080. // Create a LSA_UNICODE_STRING for the privilege name.
  1081. //
  1082. InitLsaString(&PrivilegeString, PrivilegeName);
  1083. //
  1084. // grant or revoke the privilege, accordingly
  1085. //
  1086. if(bEnable) {
  1087. return LsaAddAccountRights(
  1088. PolicyHandle, // open policy handle
  1089. AccountSid, // target SID
  1090. &PrivilegeString, // privileges
  1091. 1 // privilege count
  1092. );
  1093. }
  1094. else {
  1095. return LsaRemoveAccountRights(
  1096. PolicyHandle, // open policy handle
  1097. AccountSid, // target SID
  1098. FALSE, // do not disable all rights
  1099. &PrivilegeString, // privileges
  1100. 1 // privilege count
  1101. );
  1102. }
  1103. }
  1104. BOOL
  1105. DisableServerStuff()
  1106. {
  1107. HKEY hKeyTelephony;
  1108. if (!IsServer())
  1109. {
  1110. return FALSE;
  1111. }
  1112. if ((RegOpenKeyEx(
  1113. HKEY_LOCAL_MACHINE,
  1114. gszRegKeyTelephony,
  1115. 0,
  1116. KEY_ALL_ACCESS,
  1117. &hKeyTelephony
  1118. ) != ERROR_SUCCESS) ||
  1119. (RegDeleteKey(
  1120. hKeyTelephony,
  1121. TEXT("Server")
  1122. ) != ERROR_SUCCESS)
  1123. )
  1124. {
  1125. return FALSE;
  1126. }
  1127. if (!(DoServiceStuff(
  1128. TEXT("LocalSystem"),
  1129. TEXT(""),
  1130. FALSE
  1131. )))
  1132. {
  1133. return FALSE;
  1134. }
  1135. return TRUE;
  1136. }
  1137. BOOL
  1138. DoServer(
  1139. LPTSTR lpszServerLine
  1140. )
  1141. {
  1142. if (!(glpszFullName = GetNextString(
  1143. lpszServerLine
  1144. )))
  1145. {
  1146. return FALSE;
  1147. }
  1148. if (!(lstrcmpi(
  1149. glpszFullName,
  1150. TEXT("/d")
  1151. )))
  1152. {
  1153. if (!(DisableServerStuff()))
  1154. {
  1155. ErrorStr(iszServerDisabledFailure);
  1156. return FALSE;
  1157. }
  1158. ErrorStr(iszServerDisabled);
  1159. return TRUE;
  1160. }
  1161. // dow we want a password?
  1162. if (!(lstrcmpi(
  1163. glpszFullName,
  1164. TEXT("/n")
  1165. )))
  1166. {
  1167. // NO!
  1168. glpszFullName = GetNextString(
  1169. NULL
  1170. );
  1171. glpszPassword = NULL;
  1172. }
  1173. else
  1174. {
  1175. // yes - get the password
  1176. if (!(glpszPassword = GetNextString(
  1177. NULL
  1178. )))
  1179. {
  1180. ErrorStr(iszNoPasswordSupplied);
  1181. ErrorStr(iszServerSetupFailure);
  1182. return FALSE;
  1183. }
  1184. }
  1185. // if (!(glpszMapper = GetNextString(
  1186. // NULL
  1187. // )))
  1188. // {
  1189. // ErrorStr(iszNoMapperSupplied);
  1190. // ErrorStr(iszServerSetupFailure);
  1191. // return FALSE;
  1192. // }
  1193. // dll list is not mandatory
  1194. glpszDllList = GetNextString(
  1195. NULL
  1196. );
  1197. if (!IsServer())
  1198. {
  1199. return FALSE;
  1200. }
  1201. if (!IsUserAdministrator(
  1202. glpszFullName
  1203. )
  1204. )
  1205. {
  1206. ErrorStr(iszUserNotAnAdmin);
  1207. goto exit_now;
  1208. }
  1209. if (!DoRight(
  1210. glpszFullName,
  1211. L"SeServiceLogonRight",
  1212. TRUE
  1213. ))
  1214. {
  1215. goto exit_now;
  1216. }
  1217. if (!WriteRegistryKeys(
  1218. glpszMapper,
  1219. glpszDllList
  1220. ))
  1221. {
  1222. ErrorStr(iszRegWriteFailed);
  1223. goto exit_now;
  1224. }
  1225. if (!DoServiceStuff(
  1226. glpszFullName,
  1227. glpszPassword,
  1228. TRUE
  1229. ))
  1230. {
  1231. goto exit_now;
  1232. }
  1233. ErrorStr(iszServerSetup);
  1234. return TRUE;
  1235. exit_now:
  1236. ErrorStr(iszServerSetupFailure);
  1237. return FALSE;
  1238. }
  1239. #endif
  1240. #define MAX_KEY_LENGTH 256
  1241. DWORD RegDeleteKeyNT(HKEY hStartKey , LPCTSTR pKeyName )
  1242. {
  1243. DWORD dwRtn, dwSubKeyLength;
  1244. LPTSTR pSubKey = NULL;
  1245. TCHAR szSubKey[MAX_KEY_LENGTH]; // (256) this should be dynamic.
  1246. HKEY hKey;
  1247. // Do not allow NULL or empty key name
  1248. if ( pKeyName && lstrlen(pKeyName))
  1249. {
  1250. if( (dwRtn=RegOpenKeyEx(hStartKey,pKeyName,
  1251. 0, KEY_ENUMERATE_SUB_KEYS | DELETE, &hKey )) == ERROR_SUCCESS)
  1252. {
  1253. while (dwRtn == ERROR_SUCCESS )
  1254. {
  1255. dwSubKeyLength = MAX_KEY_LENGTH;
  1256. dwRtn=RegEnumKeyEx(
  1257. hKey,
  1258. 0, // always index zero
  1259. szSubKey,
  1260. &dwSubKeyLength,
  1261. NULL,
  1262. NULL,
  1263. NULL,
  1264. NULL
  1265. );
  1266. if(dwRtn == ERROR_NO_MORE_ITEMS)
  1267. {
  1268. dwRtn = RegDeleteKey(hStartKey, pKeyName);
  1269. break;
  1270. }
  1271. else if(dwRtn == ERROR_SUCCESS)
  1272. dwRtn=RegDeleteKeyNT(hKey, szSubKey);
  1273. }
  1274. RegCloseKey(hKey);
  1275. // Do not save return code because error
  1276. // has already occurred
  1277. }
  1278. }
  1279. else
  1280. dwRtn = ERROR_BADKEY;
  1281. return dwRtn;
  1282. }
  1283. BOOL
  1284. RemoveRemoteSP()
  1285. {
  1286. HKEY hKeyProviders, hKeyTelephony;
  1287. DWORD dwSize, dwCount, dwID, dwType, dwNumProviders ;
  1288. TCHAR szBuffer[256], szProviderName[256];
  1289. // open providers key
  1290. if (RegOpenKeyEx(
  1291. HKEY_LOCAL_MACHINE,
  1292. gszRegKeyProviders,
  1293. 0,
  1294. KEY_ALL_ACCESS,
  1295. &hKeyProviders
  1296. ) != ERROR_SUCCESS)
  1297. {
  1298. return FALSE;
  1299. }
  1300. // open telephony key
  1301. if (RegOpenKeyEx(
  1302. HKEY_LOCAL_MACHINE,
  1303. gszRegKeyTelephony,
  1304. 0,
  1305. KEY_ALL_ACCESS,
  1306. &hKeyTelephony
  1307. ) != ERROR_SUCCESS)
  1308. {
  1309. return FALSE;
  1310. }
  1311. dwSize = sizeof (DWORD);
  1312. // get current num providers
  1313. if (RegQueryValueEx(
  1314. hKeyProviders,
  1315. gszNumProviders,
  1316. NULL,
  1317. &dwType,
  1318. (LPBYTE)&dwNumProviders,
  1319. &dwSize) != ERROR_SUCCESS)
  1320. {
  1321. RegCloseKey(hKeyProviders);
  1322. return FALSE;
  1323. }
  1324. //check to see if remotesp is already installed
  1325. //loop through all providers and compare filename
  1326. for (dwCount = 0; dwCount < dwNumProviders; dwCount++)
  1327. {
  1328. wsprintf(
  1329. szBuffer,
  1330. TEXT("%s%d"),
  1331. gszProviderFilename,
  1332. dwCount
  1333. );
  1334. dwSize = 256;
  1335. if (RegQueryValueEx(
  1336. hKeyProviders,
  1337. szBuffer,
  1338. NULL,
  1339. &dwType,
  1340. (LPBYTE)szProviderName,
  1341. &dwSize) != ERROR_SUCCESS)
  1342. {
  1343. continue;
  1344. }
  1345. // this is remotesp
  1346. if (!lstrcmpi(
  1347. szProviderName,
  1348. gszRemoteSP
  1349. ))
  1350. {
  1351. wsprintf(
  1352. szBuffer,
  1353. TEXT("%s%d"),
  1354. gszProviderID,
  1355. dwCount
  1356. );
  1357. dwSize = sizeof(DWORD);
  1358. RegQueryValueEx(
  1359. hKeyProviders,
  1360. szBuffer,
  1361. NULL,
  1362. &dwType,
  1363. (LPBYTE)&dwID,
  1364. &dwSize
  1365. );
  1366. return (lineRemoveProvider (dwID, NULL) == S_OK);
  1367. }
  1368. }
  1369. if (dwCount == dwNumProviders)
  1370. {
  1371. return FALSE;
  1372. }
  1373. return TRUE;
  1374. }
  1375. BOOL
  1376. WriteRemoteSPKeys(
  1377. LPTSTR lpszRemoteServer
  1378. )
  1379. {
  1380. HKEY hKeyProviders, hKeyTelephony = NULL, hKey;
  1381. DWORD dwSize, dwType, dwNumProviders, dwNextProviderID,
  1382. dwDisp, dwCount, i;
  1383. TCHAR szBuffer[256], szProviderName[256];
  1384. #ifdef NEVER
  1385. BOOL fAlreadyExists = FALSE;
  1386. #endif
  1387. // open providers key
  1388. if (RegOpenKeyEx(
  1389. HKEY_LOCAL_MACHINE,
  1390. gszRegKeyProviders,
  1391. 0,
  1392. KEY_ALL_ACCESS,
  1393. &hKeyProviders
  1394. ) != ERROR_SUCCESS)
  1395. {
  1396. return FALSE;
  1397. }
  1398. dwSize = sizeof (DWORD);
  1399. // get current num providers
  1400. if (RegQueryValueEx(
  1401. hKeyProviders,
  1402. gszNumProviders,
  1403. NULL,
  1404. &dwType,
  1405. (LPBYTE)&dwNumProviders,
  1406. &dwSize) != ERROR_SUCCESS)
  1407. {
  1408. RegCloseKey(hKeyProviders);
  1409. return FALSE;
  1410. }
  1411. //check to see if remotesp is already installed
  1412. //loop through all providers and compare filename
  1413. for (dwCount = 0; dwCount < dwNumProviders; dwCount++)
  1414. {
  1415. wsprintf(
  1416. szBuffer,
  1417. TEXT("%s%d"),
  1418. gszProviderFilename,
  1419. dwCount
  1420. );
  1421. dwSize = 256;
  1422. if (RegQueryValueEx(
  1423. hKeyProviders,
  1424. szBuffer,
  1425. NULL,
  1426. &dwType,
  1427. (LPBYTE)szProviderName,
  1428. &dwSize) != ERROR_SUCCESS)
  1429. {
  1430. continue;
  1431. }
  1432. if (!lstrcmpi(
  1433. szProviderName,
  1434. gszRemoteSP
  1435. ))
  1436. {
  1437. // if there's a match, return TRUE
  1438. wsprintf(
  1439. szBuffer,
  1440. TEXT("%s%d"),
  1441. gszProviderID,
  1442. dwCount
  1443. );
  1444. dwSize = sizeof(DWORD);
  1445. RegQueryValueEx(
  1446. hKeyProviders,
  1447. szBuffer,
  1448. NULL,
  1449. &dwType,
  1450. (LPBYTE)&dwNextProviderID,
  1451. &dwSize
  1452. );
  1453. // first remove the provider
  1454. if (lineRemoveProvider (dwNextProviderID, NULL))
  1455. {
  1456. RegCloseKey (hKeyProviders);
  1457. return FALSE;
  1458. }
  1459. if (RegOpenKeyEx(
  1460. HKEY_LOCAL_MACHINE,
  1461. gszRegKeyTelephony,
  1462. 0,
  1463. KEY_ALL_ACCESS,
  1464. &hKeyTelephony
  1465. ) != ERROR_SUCCESS)
  1466. {
  1467. return FALSE;
  1468. }
  1469. wsprintf(
  1470. szBuffer,
  1471. TEXT("%s%d"),
  1472. gszProvider,
  1473. dwNextProviderID
  1474. );
  1475. #if MEMPHIS
  1476. RegDeleteKey(
  1477. hKeyTelephony,
  1478. szBuffer
  1479. );
  1480. #else
  1481. RegDeleteKeyNT(
  1482. hKeyTelephony,
  1483. szBuffer
  1484. );
  1485. #endif
  1486. #ifdef NEVER
  1487. wsprintf(
  1488. szBuffer,
  1489. TEXT("%s%d"),
  1490. gszProvider,
  1491. dwNextProviderID
  1492. );
  1493. // open telephony key
  1494. if (RegOpenKeyEx(
  1495. HKEY_LOCAL_MACHINE,
  1496. gszRegKeyTelephony,
  1497. 0,
  1498. KEY_ALL_ACCESS,
  1499. &hKeyTelephony
  1500. ) != ERROR_SUCCESS)
  1501. {
  1502. return FALSE;
  1503. }
  1504. fAlreadyExists = TRUE;
  1505. goto createProviderNKey;
  1506. #endif
  1507. }
  1508. }
  1509. dwSize = sizeof (DWORD);
  1510. // get next provider id
  1511. if (RegQueryValueEx(
  1512. hKeyProviders,
  1513. gszNextProviderID,
  1514. NULL,
  1515. &dwType,
  1516. (LPBYTE)&dwNextProviderID,
  1517. &dwSize) != ERROR_SUCCESS)
  1518. {
  1519. RegCloseKey(hKeyProviders);
  1520. return FALSE;
  1521. }
  1522. #ifdef NEVER
  1523. // make the filename id
  1524. wsprintf(szBuffer, TEXT("%s%d"), gszProviderFilename, dwNumProviders);
  1525. // set the filename
  1526. if (RegSetValueEx(
  1527. hKeyProviders,
  1528. szBuffer,
  1529. 0,
  1530. REG_SZ,
  1531. (LPBYTE)gszRemoteSP,
  1532. (TAPIstrlen(gszRemoteSP)+1) * sizeof(TCHAR)
  1533. ) != ERROR_SUCCESS)
  1534. {
  1535. RegCloseKey(hKeyProviders);
  1536. return FALSE;
  1537. }
  1538. // make the provideid id
  1539. wsprintf(szBuffer, TEXT("%s%d"), gszProviderID, dwNumProviders);
  1540. // set the providerid id
  1541. if (RegSetValueEx(
  1542. hKeyProviders,
  1543. szBuffer,
  1544. 0,
  1545. REG_DWORD,
  1546. (LPBYTE)&dwNextProviderID,
  1547. sizeof(DWORD)
  1548. ) != ERROR_SUCCESS)
  1549. {
  1550. RegCloseKey(hKeyProviders);
  1551. return FALSE;
  1552. }
  1553. // inc next provider id
  1554. dwNextProviderID++;
  1555. // set it
  1556. if (RegSetValueEx(
  1557. hKeyProviders,
  1558. gszNextProviderID,
  1559. 0,
  1560. REG_DWORD,
  1561. (LPBYTE)&dwNextProviderID,
  1562. sizeof(DWORD)
  1563. ) != ERROR_SUCCESS)
  1564. {
  1565. RegCloseKey(hKeyProviders);
  1566. return FALSE;
  1567. }
  1568. // inc num providers
  1569. dwNumProviders++;
  1570. // set it
  1571. if (RegSetValueEx(
  1572. hKeyProviders,
  1573. gszNumProviders,
  1574. 0,
  1575. REG_DWORD,
  1576. (LPBYTE)&dwNumProviders,
  1577. sizeof(DWORD)
  1578. ) != ERROR_SUCCESS)
  1579. {
  1580. RegCloseKey(hKeyProviders);
  1581. return FALSE;
  1582. }
  1583. // close this one
  1584. RegCloseKey(hKeyProviders);
  1585. #endif // NEVER
  1586. // open telephony key
  1587. if ((hKeyTelephony == NULL) && (RegOpenKeyEx(
  1588. HKEY_LOCAL_MACHINE,
  1589. gszRegKeyTelephony,
  1590. 0,
  1591. KEY_ALL_ACCESS,
  1592. &hKeyTelephony
  1593. ) != ERROR_SUCCESS))
  1594. {
  1595. return FALSE;
  1596. }
  1597. // make the provider# key
  1598. wsprintf(szBuffer, TEXT("%s%d"), gszProvider, dwNextProviderID);
  1599. #if NEVER
  1600. createProviderNKey:
  1601. //
  1602. // First nuke the existing key to clear out all the old values,
  1603. // the recreate it & add the new values
  1604. //
  1605. #if MEMPHIS
  1606. RegDeleteKey (hKeyTelephony, szBuffer);
  1607. #else
  1608. RegDeleteKeyNT (hKeyTelephony, szBuffer);
  1609. #endif
  1610. #endif
  1611. if (RegCreateKeyEx(
  1612. hKeyTelephony,
  1613. szBuffer,
  1614. 0,
  1615. NULL,
  1616. REG_OPTION_NON_VOLATILE,
  1617. KEY_ALL_ACCESS,
  1618. NULL,
  1619. &hKey,
  1620. &dwDisp
  1621. ) != ERROR_SUCCESS)
  1622. {
  1623. RegCloseKey(hKeyTelephony);
  1624. return FALSE;
  1625. }
  1626. for (i = 0; lpszRemoteServer; i++)
  1627. {
  1628. wsprintf (szBuffer, TEXT("%s%d"), gszServer, i);
  1629. if (RegSetValueEx(
  1630. hKey,
  1631. szBuffer,
  1632. 0,
  1633. REG_SZ,
  1634. (LPBYTE) lpszRemoteServer,
  1635. (TAPIstrlen (lpszRemoteServer) + 1) * sizeof(TCHAR)
  1636. ) != ERROR_SUCCESS)
  1637. {
  1638. RegCloseKey (hKey);
  1639. RegCloseKey (hKeyProviders);
  1640. return FALSE;
  1641. }
  1642. lpszRemoteServer = GetNextString (NULL);
  1643. }
  1644. if (RegSetValueEx(
  1645. hKey,
  1646. gszNumServers,
  1647. 0,
  1648. REG_DWORD,
  1649. (LPBYTE) &i,
  1650. sizeof (i)
  1651. ) != ERROR_SUCCESS)
  1652. {
  1653. RegCloseKey (hKey);
  1654. RegCloseKey (hKeyProviders);
  1655. return FALSE;
  1656. }
  1657. // set the ConnectionOrientedOnly value appropriately
  1658. if (RegSetValueEx(
  1659. hKey,
  1660. gszConnectionOrientedOnly,
  1661. 0,
  1662. REG_DWORD,
  1663. (LPBYTE) &gdwConnectionOrientedOnly,
  1664. sizeof(DWORD)
  1665. ) != ERROR_SUCCESS)
  1666. {
  1667. RegCloseKey(hKey);
  1668. RegCloseKey(hKeyProviders);
  1669. return FALSE;
  1670. }
  1671. // Set NoDSQuery value appropriately
  1672. if (RegSetValueEx(
  1673. hKey,
  1674. gszNoDSQuery,
  1675. 0,
  1676. REG_DWORD,
  1677. (LPBYTE) &gdwNoDSQuery,
  1678. sizeof(DWORD)
  1679. ) != ERROR_SUCCESS)
  1680. {
  1681. RegCloseKey(hKey);
  1682. RegCloseKey(hKeyProviders);
  1683. return FALSE;
  1684. }
  1685. //
  1686. // Add the new remotesp.tsp
  1687. //
  1688. lineAddProvider (gszRemoteSP, NULL, &dwNextProviderID);
  1689. RegCloseKey (hKey);
  1690. RegCloseKey (hKeyProviders);
  1691. RegCloseKey(hKeyTelephony);
  1692. return TRUE;
  1693. }
  1694. BOOL
  1695. DoClient(
  1696. LPTSTR lpszClientLine
  1697. )
  1698. {
  1699. HANDLE hProvidersMutex = NULL;
  1700. BOOL bRet = FALSE;
  1701. glpszRemoteServer = GetNextString(
  1702. lpszClientLine
  1703. );
  1704. if (!glpszRemoteServer)
  1705. {
  1706. goto ExitHere;
  1707. }
  1708. hProvidersMutex = CreateMutex (
  1709. NULL,
  1710. FALSE,
  1711. TEXT("TapisrvProviderListMutex")
  1712. );
  1713. if (NULL == hProvidersMutex)
  1714. {
  1715. ErrorStr(iszCreateMutexFailed);
  1716. goto ExitHere;
  1717. }
  1718. WaitForSingleObject (hProvidersMutex, INFINITE);
  1719. if (!lstrcmpi(
  1720. glpszRemoteServer,
  1721. TEXT("/d")
  1722. ))
  1723. {
  1724. if (!RemoveRemoteSP())
  1725. {
  1726. ErrorStr(iszClientDisabledFailure);
  1727. goto ExitHere;
  1728. }
  1729. else
  1730. {
  1731. ErrorStr(iszClientDisabled);
  1732. bRet = TRUE;
  1733. goto ExitHere;
  1734. }
  1735. }
  1736. if (!WriteRemoteSPKeys(
  1737. glpszRemoteServer
  1738. ))
  1739. {
  1740. ErrorStr(iszClientSetupFailure);
  1741. goto ExitHere;
  1742. }
  1743. else
  1744. {
  1745. bRet = TRUE;
  1746. }
  1747. ErrorStr(iszClientSetup);
  1748. ExitHere:
  1749. if (hProvidersMutex)
  1750. {
  1751. ReleaseMutex (hProvidersMutex);
  1752. CloseHandle (hProvidersMutex);
  1753. }
  1754. return bRet;
  1755. }