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.

485 lines
15 KiB

  1. /*++
  2. Copyright (c) 2001 Microsoft Corporation
  3. Module Name:
  4. main.cxx
  5. Abstract:
  6. main
  7. Author:
  8. Larry Zhu (LZhu) January 1, 2002 Created
  9. Environment:
  10. User Mode
  11. Revision History:
  12. --*/
  13. #include "precomp.hxx"
  14. #pragma hdrstop
  15. #include "sspi.hxx"
  16. #include "sspicli.hxx"
  17. #include "sspisrv.hxx"
  18. #include "main.hxx"
  19. VOID
  20. Usage(
  21. IN PCSTR pszApp
  22. )
  23. {
  24. DebugPrintf(SSPI_ERROR,
  25. "\n\nUsage: %s [-noserver] [-noclient] [-targetname <target name>] \n"
  26. "[-clientsocketport <client port>] -serversocketport <server port> \n"
  27. "[-clientname <client>] [-clientdomain <client domain>] \n"
  28. "[-clientpassword <client password>] [-servername <server name>] \n"
  29. "[-serverpassword <server password>] [-serverhost <server host>] \n"
  30. "[-serverdomain <server domain>] [-clientprincipal <client principal name>] \n"
  31. "[-serverprincipal <server principal name> [-serverflags <server flag>] \n"
  32. "[-clientflags <client flag>] [-clientpackage <client package>] \n"
  33. "[-clientdatarep <client data rep>] [-serverdatarep <server data rep>] \n"
  34. "[-clientcredlogonidhighpart <client cred logon id highpart>] \n"
  35. "[-clientcredlogonidlowpart <client cred logon id lowpart>] \n"
  36. "[-clientpackagelist <package1,package2,!package3>\n"
  37. "[-serverpackagelist <package1,package2,!package3>\n"
  38. "[-servercredlogonidhighpart <server cred logon id highpart>] \n"
  39. "[-servercredlogonidlowpart <server cred logon id lowpart>] \n"
  40. "[-serverpackage <server package>] [-nomessages] \n"
  41. "[-noimportexport] [-noimportexportmsg] [-noserverqca] \n"
  42. "[-noclientqca] [-nocheckuserdata] [-nocheckusertoken] \n"
  43. "[-noclientpackagecheck] [-noserverpackagecheck] [-application <app>] \n"
  44. "[-s4uclientupn <s4u client upn>] [-s4uclientrealm <s4u client realm>] \n"
  45. "[-s4uflags <s4u2selfflags>] [-processidtokenusedbyclient <process id>] \n"
  46. "[-enabletcbpriv] [-quiet] [-messagelength <length>]\n\n", pszApp);
  47. exit(-1);
  48. }
  49. VOID
  50. checkpoint(
  51. VOID
  52. )
  53. {
  54. DebugPrintf(SSPI_LOG, "checkpoint\n");
  55. ASSERT(FALSE);
  56. }
  57. #if 0
  58. HRESULT
  59. GetAuthdata(
  60. IN OPTIONAL PCSTR pszUserName,
  61. IN OPTIONAL PCSTR pszDomainName,
  62. IN OPTIONAL PCSTR pszPassword,
  63. OUT SEC_WINNT_AUTH_IDENTITY_A* pAuthData
  64. )
  65. {
  66. THResult hRetval = S_OK;
  67. pAuthData->Domain = (UCHAR*)pszDomainName;
  68. pAuthData->DomainLength = pszDomainName ? strlen(pszDomainName) : 0;
  69. pAuthData->Password = (UCHAR*)pszPassword;
  70. pAuthData->PasswordLength = pszPassword ? strlen(pszPassword) : 0;
  71. pAuthData->User = (UCHAR*)pszUserName;
  72. pAuthData->UserLength = pszUserName ? strlen(pszUserName) : 0;
  73. pAuthData->Flags = SEC_WINNT_AUTH_IDENTITY_ANSI;
  74. return hRetval;
  75. }
  76. #endif
  77. VOID __cdecl
  78. main(
  79. IN INT argc,
  80. IN PSTR argv[]
  81. )
  82. {
  83. THResult hRetval = S_OK;
  84. ULONG mark = 1;
  85. BOOL bStartServer = TRUE;
  86. BOOL bStartClient = TRUE;
  87. BOOL bCheckClientPackage = TRUE;
  88. BOOL bCheckServerPackage = TRUE;
  89. TSspiServerMainParam SrvMainParam;
  90. TSspiClientParam CliParam;
  91. BOOLEAN bIsVerberose = TRUE;
  92. SEC_WINNT_AUTH_IDENTITY_EXA ClientAuthData = {0};
  93. SEC_WINNT_AUTH_IDENTITY_EXA ServerAuthData = {0};
  94. PCSTR pszClientName = NULL;
  95. PCSTR pszClientDomain = NULL;
  96. PCSTR pszClientPassword = NULL;
  97. PCSTR pszClientPackageList = NULL;
  98. PCSTR pszServerName = NULL;
  99. PCSTR pszServerDomain = NULL;
  100. PCSTR pszServerPassword = NULL;
  101. PCSTR pszServerPackageList = NULL;
  102. LUID ClientCredLogonId = {0};
  103. LUID ServerCredLogonId = {0};
  104. ULONG ClientTargetDataRep = SECURITY_NATIVE_DREP;
  105. ULONG ServerTargetDataRep = SECURITY_NATIVE_DREP;
  106. USHORT ServerSocketPort = kServerSocketPort;
  107. USHORT ClientSocketPort = kClientSocketPort;
  108. CRITICAL_SECTION DbgPrintCritSection = {0};
  109. BOOLEAN bEnableTcbPriv = FALSE;
  110. TPrivilege* pPriv = NULL;
  111. RtlInitializeCriticalSection(&DbgPrintCritSection);
  112. argc--;
  113. while (argc)
  114. {
  115. if (!strcmp(argv[mark], "-clientsocketport") && argc > 1)
  116. {
  117. argc--; mark++;
  118. ClientSocketPort = (USHORT) strtol(argv[mark], NULL, 0);
  119. argc--; mark++;
  120. }
  121. else if (!strcmp(argv[mark], "-serversocketport") && argc > 1)
  122. {
  123. argc--; mark++;
  124. ServerSocketPort = (USHORT) strtol(argv[mark], NULL, 0);
  125. argc--; mark++;
  126. }
  127. else if (!strcmp(argv[mark], "-clientname") && argc > 1)
  128. {
  129. argc--; mark++;
  130. pszClientName = argv[mark];
  131. argc--; mark++;
  132. }
  133. else if (!strcmp(argv[mark], "-clientdomain") && argc > 1)
  134. {
  135. argc--; mark++;
  136. pszClientDomain = argv[mark];
  137. argc--; mark++;
  138. }
  139. else if (!strcmp(argv[mark], "-clientpassword") && argc > 1)
  140. {
  141. argc--; mark++;
  142. pszClientPassword = argv[mark];
  143. argc--; mark++;
  144. }
  145. else if (!strcmp(argv[mark], "-servername") && argc > 1)
  146. {
  147. argc--; mark++;
  148. pszServerName = argv[mark];
  149. argc--; mark++;
  150. }
  151. else if (!strcmp(argv[mark], "-serverdomain") && argc > 1)
  152. {
  153. argc--; mark++;
  154. pszServerDomain = argv[mark];
  155. argc--; mark++;
  156. }
  157. else if (!strcmp(argv[mark], "-serverpassword") && argc > 1)
  158. {
  159. argc--; mark++;
  160. pszServerPassword = argv[mark];
  161. argc--; mark++;
  162. }
  163. else if (!strcmp(argv[mark], "-serverhost") && argc > 1)
  164. {
  165. argc--; mark++;
  166. bStartServer = FALSE;
  167. CliParam.pszServer = argv[mark];
  168. argc--; mark++;
  169. }
  170. else if (!strcmp(argv[mark], "-clientpackage") && argc > 1)
  171. {
  172. argc--; mark++;
  173. CliParam.pszPackageName = argv[mark];
  174. argc--; mark++;
  175. }
  176. else if (!strcmp(argv[mark], "-serverpackage") && argc > 1)
  177. {
  178. argc--; mark++;
  179. SrvMainParam.pszPackageName = argv[mark];
  180. argc--; mark++;
  181. }
  182. else if (!strcmp(argv[mark], "-processidtokenusedbyclient") && argc > 1)
  183. {
  184. argc--; mark++;
  185. CliParam.ProcessIdTokenUsedByClient = strtol(argv[mark], NULL, 0);
  186. argc--; mark++;
  187. }
  188. else if (!strcmp(argv[mark], "-s4uclientupn") && argc > 1)
  189. {
  190. argc--; mark++;
  191. CliParam.pszS4uClientUpn = argv[mark];
  192. argc--; mark++;
  193. }
  194. else if (!strcmp(argv[mark], "-s4uclientrealm") && argc > 1)
  195. {
  196. argc--; mark++;
  197. CliParam.pszS4uClientRealm = argv[mark];
  198. argc--; mark++;
  199. }
  200. else if (!strcmp(argv[mark], "-clientcredlogonidlowpart") && argc > 1)
  201. {
  202. argc--; mark++;
  203. ClientCredLogonId.LowPart = strtol(argv[mark], NULL, 0);
  204. CliParam.pCredLogonID = &ClientCredLogonId;
  205. argc--; mark++;
  206. }
  207. else if (!strcmp(argv[mark], "-clientcredlogonidhighpart") && argc > 1)
  208. {
  209. argc--; mark++;
  210. ClientCredLogonId.HighPart = strtol(argv[mark], NULL, 0);
  211. CliParam.pCredLogonID = &ClientCredLogonId;
  212. argc--; mark++;
  213. }
  214. else if (!strcmp(argv[mark], "-servercredlogonidhighpart") && argc > 1)
  215. {
  216. argc--; mark++;
  217. ServerCredLogonId.HighPart = strtol(argv[mark], NULL, 0);
  218. SrvMainParam.pCredLogonID = &ClientCredLogonId;
  219. argc--; mark++;
  220. }
  221. else if (!strcmp(argv[mark], "-servercredlogonidlowpart") && argc > 1)
  222. {
  223. argc--; mark++;
  224. ServerCredLogonId.LowPart = strtol(argv[mark], NULL, 0);
  225. SrvMainParam.pCredLogonID = &ServerCredLogonId;
  226. argc--; mark++;
  227. }
  228. else if (!strcmp(argv[mark], "-targetname") && argc > 1)
  229. {
  230. argc--; mark++;
  231. CliParam.pszTargetName = argv[mark];
  232. argc--; mark++;
  233. }
  234. else if (!strcmp(argv[mark], "-clientdatarep") && argc > 1)
  235. {
  236. argc--; mark++;
  237. ClientTargetDataRep = strtol(argv[mark], NULL, 0);
  238. argc--; mark++;
  239. }
  240. else if (!strcmp(argv[mark], "-serverdatarep") && argc > 1)
  241. {
  242. argc--; mark++;
  243. ServerTargetDataRep = strtol(argv[mark], NULL, 0);
  244. argc--; mark++;
  245. }
  246. else if (!strcmp(argv[mark], "-serverflags") && argc > 1)
  247. {
  248. argc--; mark++;
  249. SrvMainParam.ServerFlags = strtol(argv[mark], NULL, 0);
  250. argc--; mark++;
  251. }
  252. else if (!strcmp(argv[mark], "-clientflags") && argc > 1)
  253. {
  254. argc--; mark++;
  255. CliParam.ClientFlags = strtol(argv[mark], NULL, 0);
  256. argc--; mark++;
  257. }
  258. else if (!strcmp(argv[mark], "-s4uflags") && argc > 1)
  259. {
  260. argc--; mark++;
  261. CliParam.S4u2SelfFlags = strtol(argv[mark], NULL, 0);
  262. argc--; mark++;
  263. }
  264. else if (!strcmp(argv[mark], "-clientprincipal") && argc > 1)
  265. {
  266. argc--; mark++;
  267. CliParam.pszPrincipal = argv[mark];
  268. argc--; mark++;
  269. }
  270. else if (!strcmp(argv[mark], "-clientpackagelist") && argc > 1)
  271. {
  272. argc--; mark++;
  273. pszClientPackageList = argv[mark];
  274. argc--; mark++;
  275. }
  276. else if (!strcmp(argv[mark], "-serverpackagelist") && argc > 1)
  277. {
  278. argc--; mark++;
  279. pszServerPackageList = argv[mark];
  280. argc--; mark++;
  281. }
  282. else if (!strcmp(argv[mark], "-serverprincipal") && argc > 1)
  283. {
  284. argc--; mark++;
  285. SrvMainParam.pszPrincipal = argv[mark];
  286. argc--; mark++;
  287. }
  288. else if (!strcmp(argv[mark], "-application") && argc > 1)
  289. {
  290. argc--; mark++;
  291. SrvMainParam.pszApplication = argv[mark];
  292. argc--; mark++;
  293. }
  294. else if (!strcmp(argv[mark], "-messagelength") && argc > 1)
  295. {
  296. argc--; mark++;
  297. g_MsgHeaderLen = strtol(argv[mark], NULL, 0);
  298. argc--; mark++;
  299. }
  300. else if (!strcmp(argv[mark], "-noserver"))
  301. {
  302. argc--; mark++;
  303. bStartServer = FALSE;
  304. }
  305. else if (!strcmp(argv[mark], "-noclient"))
  306. {
  307. argc--; mark++;
  308. bStartClient = FALSE;
  309. }
  310. else if (!strcmp(argv[mark], "-nocheckusertoken"))
  311. {
  312. argc--; mark++;
  313. SrvMainParam.ServerActionFlags |= SSPI_ACTION_NO_CHECK_USER_TOKEN;
  314. }
  315. else if (!strcmp(argv[mark], "-nocheckuserdata"))
  316. {
  317. argc--; mark++;
  318. SrvMainParam.ServerActionFlags |= SSPI_ACTION_NO_CHECK_USER_DATA;
  319. }
  320. else if (!strcmp(argv[mark], "-noserverqca"))
  321. {
  322. argc--; mark++;
  323. SrvMainParam.ServerActionFlags |= SSPI_ACTION_NO_QCA;
  324. }
  325. else if (!strcmp(argv[mark], "-noclientqca"))
  326. {
  327. argc--; mark++;
  328. CliParam.ClientActionFlags |= SSPI_ACTION_NO_QCA;
  329. }
  330. else if (!strcmp(argv[mark], "-nomessages"))
  331. {
  332. argc--; mark++;
  333. CliParam.ClientActionFlags |= SSPI_ACTION_NO_MESSAGES;
  334. }
  335. else if (!strcmp(argv[mark], "-noimportexportmsg"))
  336. {
  337. argc--; mark++;
  338. CliParam.ClientActionFlags |= SSPI_ACTION_NO_IMPORT_EXPORT_MSG;
  339. }
  340. else if (!strcmp(argv[mark], "-noimportexport"))
  341. {
  342. argc--; mark++;
  343. CliParam.ClientActionFlags |= SSPI_ACTION_NO_IMPORT_EXPORT;
  344. }
  345. else if (!strcmp(argv[mark], "-noclientpackagecheck"))
  346. {
  347. argc--; mark++;
  348. bCheckClientPackage = FALSE;
  349. }
  350. else if (!strcmp(argv[mark], "-noserverpackagecheck"))
  351. {
  352. argc--; mark++;
  353. bCheckServerPackage = FALSE;
  354. }
  355. else if (!strcmp(argv[mark], "-quiet"))
  356. {
  357. argc--; mark++;
  358. bIsVerberose = FALSE;
  359. }
  360. else if (!strcmp(argv[mark], "-enabletcbpriv"))
  361. {
  362. argc--; mark++;
  363. bEnableTcbPriv = TRUE;
  364. }
  365. else if (!strcmp(argv[mark], "-h"))
  366. {
  367. argc--; mark++;
  368. Usage(argv[0]);
  369. }
  370. else
  371. {
  372. Usage(argv[0]);
  373. }
  374. }
  375. DebugLogOpenSerialized("sspi.exe",
  376. bIsVerberose ?
  377. SSPI_LOG | SSPI_WARN | SSPI_ERROR | SSPI_MSG
  378. : SSPI_ERROR,
  379. &DbgPrintCritSection);
  380. SrvMainParam.ServerSocketPort = ServerSocketPort;
  381. CliParam.ClientSocketPort = ClientSocketPort;
  382. CliParam.ServerSocketPort = ServerSocketPort;
  383. if (bEnableTcbPriv)
  384. {
  385. pPriv = new TPrivilege(SE_TCB_PRIVILEGE, TRUE);
  386. hRetval DBGCHK = pPriv ? pPriv->Validate() : E_OUTOFMEMORY;
  387. }
  388. if (SUCCEEDED(hRetval) && bStartClient && bCheckClientPackage)
  389. {
  390. hRetval DBGCHK = CheckSecurityPackage(CliParam.pszPackageName);
  391. }
  392. if (SUCCEEDED(hRetval) && bStartServer && bCheckServerPackage
  393. && (!bCheckClientPackage
  394. || (0 != _stricmp(CliParam.pszPackageName, SrvMainParam.pszPackageName))))
  395. {
  396. hRetval DBGCHK = CheckSecurityPackage(SrvMainParam.pszPackageName);
  397. }
  398. if (SUCCEEDED(hRetval) && (pszClientName || pszClientDomain || pszClientPassword || pszClientPackageList))
  399. {
  400. CliParam.pAuthData = &ClientAuthData;
  401. DebugPrintf(SSPI_LOG, "Getting Client AuthData:\n");
  402. (VOID) GetAuthdataExA(
  403. pszClientName,
  404. pszClientDomain,
  405. pszClientPassword,
  406. pszClientPackageList,
  407. &ClientAuthData
  408. );
  409. }
  410. if (SUCCEEDED(hRetval) && (pszServerName || pszServerDomain || pszServerPassword || pszServerPackageList))
  411. {
  412. SrvMainParam.pAuthData = &ServerAuthData;
  413. DebugPrintf(SSPI_LOG, "Getting Server AuthData:\n");
  414. (VOID) GetAuthdataExA(
  415. pszServerName,
  416. pszServerDomain,
  417. pszServerPassword,
  418. pszServerPackageList,
  419. &ServerAuthData
  420. );
  421. }
  422. if (SUCCEEDED(hRetval))
  423. {
  424. hRetval DBGCHK = SspiStartCS(
  425. bStartServer ? &SrvMainParam : NULL,
  426. bStartClient ? &CliParam : NULL
  427. );
  428. }
  429. if (pPriv)
  430. {
  431. delete pPriv;
  432. }
  433. DebugLogClose();
  434. DeleteCriticalSection(&DbgPrintCritSection);
  435. }