Leaked source code of windows server 2003
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.

2041 lines
51 KiB

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