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.

634 lines
11 KiB

  1. /*++
  2. Copyright (c) 1992-1999 Microsoft Corporation
  3. Module Name:
  4. dumpnt.c
  5. Abstract:
  6. Dump routines for various native defined types.
  7. The original/maintained version of this code lives @
  8. \\brillig\ntct!slm\src\security\util\dumpnt.c
  9. Author:
  10. TimF 12-Jun-92 created
  11. Revision History:
  12. JinHuang 13-Feb-98 modified
  13. */
  14. #include <stdio.h>
  15. #include <nt.h>
  16. #include <ntrtl.h>
  17. #include <nturtl.h>
  18. #include <windows.h>
  19. #include <ntlsa.h>
  20. #include <ntsam.h>
  21. #include "dumpnt.h"
  22. /*
  23. * Generic header:
  24. *
  25. * Dump<TYPE_FOO>
  26. *
  27. * Takes a pointer to an object of TYPE_FOO, and dumps the contents of that
  28. * structure to wherever output is being sent these days (as best it can).
  29. *
  30. * Pointers and regions pointed are expected to be valid, and accessible.
  31. *
  32. * No return value is defined.
  33. */
  34. VOID
  35. DumpGUID(
  36. IN GUID *g
  37. )
  38. {
  39. if (!g) {
  40. printf("<NULL>\n");
  41. } else {
  42. try {
  43. printf("0x%08lx-%04x-%04x-%02x%02x%02x%02x%02x%02x%02x%02x\n",
  44. g -> Data1,
  45. g -> Data2,
  46. g -> Data3,
  47. g -> Data4[0],
  48. g -> Data4[1],
  49. g -> Data4[2],
  50. g -> Data4[3],
  51. g -> Data4[4],
  52. g -> Data4[5],
  53. g -> Data4[6],
  54. g -> Data4[7]);
  55. } except (EXCEPTION_EXECUTE_HANDLER) {
  56. printf("DumpGUID: invalid pointer (0x%p)\n",
  57. g);
  58. }
  59. }
  60. }
  61. VOID
  62. DumpSID(
  63. IN PSID s
  64. )
  65. {
  66. static char b[128];
  67. SID_IDENTIFIER_AUTHORITY *a;
  68. ULONG id = 0, i;
  69. try {
  70. b[0] = '\0';
  71. a = RtlIdentifierAuthoritySid(s);
  72. sprintf(b, "s-0x1-%02x%02x%02x%02x%02x%02x", a -> Value[0],
  73. a -> Value[1], a -> Value[2], a -> Value[3], a ->
  74. Value[4], a -> Value[5]);
  75. for (i = 0; i < *RtlSubAuthorityCountSid(s); i++) {
  76. sprintf(b, "%s-%lx", b, *RtlSubAuthoritySid(s, i));
  77. }
  78. printf("%s", b);
  79. } except (EXCEPTION_EXECUTE_HANDLER) {
  80. printf("%s<invalid pointer: 0x%p>\t", b, s);
  81. }
  82. }
  83. /*
  84. * DumpSIDNAME() attempts to unravel the Sid into a Display Name
  85. */
  86. VOID
  87. DumpSIDNAME(
  88. IN PSID s
  89. )
  90. {
  91. NTSTATUS Status;
  92. LSA_HANDLE Policy;
  93. OBJECT_ATTRIBUTES ObjAttr;
  94. SECURITY_QUALITY_OF_SERVICE SQoS;
  95. PLSA_REFERENCED_DOMAIN_LIST RefDomains = NULL;
  96. PLSA_TRANSLATED_NAME XNames = NULL;
  97. try {
  98. /*
  99. * Open the policy with POLICY_LOOKUP_NAMES and lookup this
  100. * Sid.
  101. */
  102. InitializeObjectAttributes(&ObjAttr,
  103. NULL,
  104. 0L,
  105. NULL,
  106. NULL);
  107. /*
  108. * init the sqos struct
  109. */
  110. SQoS.Length = sizeof(SECURITY_QUALITY_OF_SERVICE);
  111. SQoS.ContextTrackingMode = SECURITY_DYNAMIC_TRACKING;
  112. SQoS.ImpersonationLevel = SecurityIdentification;
  113. SQoS.EffectiveOnly = TRUE;
  114. ObjAttr.SecurityQualityOfService = &SQoS;
  115. /*
  116. * make the actual call
  117. */
  118. Status = LsaOpenPolicy(NULL,
  119. &ObjAttr,
  120. POLICY_LOOKUP_NAMES,
  121. &Policy);
  122. if (!NT_SUCCESS(Status)) {
  123. printf("DumpSIDNAMES: can't open Lsa, (0x%lx)\n",
  124. Status);
  125. return;
  126. }
  127. Status = LsaLookupSids(Policy,
  128. 1L,
  129. &s,
  130. &RefDomains,
  131. &XNames);
  132. if (Status == STATUS_NONE_MAPPED) {
  133. printf("Unknown\n");
  134. } else if (!NT_SUCCESS(Status)) {
  135. printf("DumpSIDNAMES: can't Lookup Sids, (0x%lx)\n",
  136. Status);
  137. } else {
  138. printf("'%wZ' (%s)\n",
  139. &(XNames->Name),
  140. (XNames->Use == SidTypeUser ? "User" :
  141. XNames->Use == SidTypeGroup ? "Group" :
  142. XNames->Use == SidTypeDomain ? "Domain" :
  143. XNames->Use == SidTypeAlias ? "Alias" :
  144. XNames->Use == SidTypeWellKnownGroup ? "WellKnownGroup" :
  145. XNames->Use == SidTypeDeletedAccount ? "Deleted" :
  146. XNames->Use == SidTypeInvalid ? "Invalid" :
  147. XNames->Use == SidTypeUnknown ? "Unknown" :
  148. "ERROR!"));
  149. }
  150. } except (EXCEPTION_EXECUTE_HANDLER) {
  151. printf("DumpSIDNAME: invalid pointer (0x%p)\n", s);
  152. }
  153. if (RefDomains) {
  154. LsaFreeMemory(RefDomains);
  155. }
  156. if (XNames) {
  157. LsaFreeMemory(XNames);
  158. }
  159. LsaClose(Policy);
  160. }
  161. VOID
  162. DumpACL(
  163. IN ACL *a
  164. )
  165. {
  166. ACE_HEADER *Ace;
  167. USHORT i;
  168. try {
  169. printf("Acl -> AclRevision = 0x%x\n", a -> AclRevision);
  170. printf("Acl -> Sbz1 = 0x%x\n", a -> Sbz1);
  171. printf("Acl -> AclSize = 0x%x\n", a -> AclSize);
  172. printf("Acl -> AceCount = 0x%x\n", a -> AceCount);
  173. printf("Acl -> Sbz2 = 0x%x\n\n", a -> Sbz2);
  174. for (i = 0; i < a -> AceCount; i++) {
  175. if (NT_SUCCESS(RtlGetAce(a, i, (PVOID *)&Ace))) {
  176. DumpACE(Ace);
  177. } else {
  178. printf("(Can't RtlGetAce[%d])\n", i);
  179. }
  180. printf("\n");
  181. }
  182. } except (EXCEPTION_EXECUTE_HANDLER) {
  183. printf("DumpACL: invalid pointer (0x%p)\n", a);
  184. }
  185. }
  186. VOID
  187. DumpACE(
  188. IN ACE_HEADER *a
  189. )
  190. {
  191. ACCESS_ALLOWED_ACE *Ace = (ACCESS_ALLOWED_ACE *)a;
  192. try {
  193. printf("Ace -> AceType = ");
  194. Dump_ACE_TYPE(a -> AceType);
  195. printf("Ace -> AceSize = 0x%x\n", a -> AceSize);
  196. printf("Ace -> AceFlags = ");
  197. Dump_ACE_FLAGS(a -> AceFlags);
  198. switch (a -> AceType) {
  199. case ACCESS_ALLOWED_ACE_TYPE:
  200. case ACCESS_DENIED_ACE_TYPE:
  201. case SYSTEM_AUDIT_ACE_TYPE:
  202. case SYSTEM_ALARM_ACE_TYPE:
  203. printf("Ace -> Mask = 0x%lx\n",
  204. Ace -> Mask);
  205. printf("Ace -> Sid = ");
  206. DumpSID(&(Ace -> SidStart));
  207. printf("\t");
  208. DumpSIDNAME(&(Ace -> SidStart));
  209. break;
  210. case ACCESS_ALLOWED_OBJECT_ACE_TYPE:
  211. case ACCESS_DENIED_OBJECT_ACE_TYPE:
  212. case SYSTEM_AUDIT_OBJECT_ACE_TYPE:
  213. case SYSTEM_ALARM_OBJECT_ACE_TYPE: {
  214. ACCESS_ALLOWED_OBJECT_ACE *Ace;
  215. ULONG_PTR Offset;
  216. Ace = (ACCESS_ALLOWED_OBJECT_ACE *)a;
  217. printf("Ace -> Mask = 0x%lx\n",
  218. Ace -> Mask);
  219. if (!Ace -> Flags) {
  220. printf("Ace -> Flags = 0\n");
  221. } else {
  222. printf("Ace -> Flags = ");
  223. if (Ace -> Flags & ACE_INHERITED_OBJECT_TYPE_PRESENT) {
  224. printf("ACE_INHERITED_OBJECT_TYPE_PRESENT ");
  225. }
  226. if (Ace -> Flags & ACE_OBJECT_TYPE_PRESENT) {
  227. printf("ACE_OBJECT_TYPE_PRESENT");
  228. }
  229. printf("\n");
  230. }
  231. Offset = (ULONG_PTR)&(Ace -> ObjectType);
  232. if (Ace -> Flags & ACE_OBJECT_TYPE_PRESENT) {
  233. printf("Ace -> ObjectType = ");
  234. DumpGUID((GUID *)Offset);
  235. Offset += sizeof (GUID);
  236. }
  237. if (Ace -> Flags & ACE_INHERITED_OBJECT_TYPE_PRESENT) {
  238. printf("Ace -> InheritedObjectType = ");
  239. DumpGUID((GUID *)Offset);
  240. Offset += sizeof (GUID);
  241. }
  242. printf("Ace -> Sid = ");
  243. DumpSID((SID *)Offset);
  244. printf("\t");
  245. DumpSIDNAME((SID *)Offset);
  246. break;
  247. }
  248. default:
  249. printf("(Unknown ACE type)\n");
  250. break;
  251. }
  252. } except (EXCEPTION_EXECUTE_HANDLER) {
  253. printf("DumpACE: invalid pointer (0x%p)\n",
  254. a);
  255. }
  256. }
  257. VOID
  258. DumpSECURITY_DESCRIPTOR_CONTROL(
  259. SECURITY_DESCRIPTOR_CONTROL Control
  260. )
  261. {
  262. printf("SecurityDescriptor -> Control = ");
  263. if (!Control) {
  264. printf("<no flags set>");
  265. }
  266. if (Control & SE_OWNER_DEFAULTED) {
  267. printf("SE_OWNER_DEFAULTED ");
  268. }
  269. if (Control & SE_GROUP_DEFAULTED) {
  270. printf("SE_GROUP_DEFAULTED ");
  271. }
  272. if (Control & SE_DACL_PRESENT) {
  273. printf("SE_DACL_PRESENT ");
  274. }
  275. if (Control & SE_DACL_DEFAULTED) {
  276. printf("SE_DACL_DEFAULTED ");
  277. }
  278. if (Control & SE_SACL_PRESENT) {
  279. printf("SE_SACL_PRESENT ");
  280. }
  281. if (Control & SE_SACL_DEFAULTED) {
  282. printf("SE_SACL_DEFAULTED ");
  283. }
  284. if (Control & SE_DACL_UNTRUSTED) {
  285. printf("SE_DACL_UNTRUSTED ");
  286. }
  287. if (Control & SE_SERVER_SECURITY) {
  288. printf("SE_SERVER_SECURITY ");
  289. }
  290. if (Control & SE_DACL_AUTO_INHERIT_REQ) {
  291. printf("SE_DACL_AUTO_INHERIT_REQ ");
  292. }
  293. if (Control & SE_SACL_AUTO_INHERIT_REQ) {
  294. printf("SE_SACL_AUTO_INHERIT_REQ ");
  295. }
  296. if (Control & SE_DACL_AUTO_INHERITED) {
  297. printf("SE_DACL_AUTO_INHERITED ");
  298. }
  299. if (Control & SE_SACL_AUTO_INHERITED) {
  300. printf("SE_SACL_AUTO_INHERITED ");
  301. }
  302. if (Control & SE_DACL_PROTECTED) {
  303. printf("SE_DACL_PROTECTED ");
  304. }
  305. if (Control & SE_SACL_PROTECTED) {
  306. printf("SE_SACL_PROTECTED ");
  307. }
  308. if (Control & SE_SELF_RELATIVE) {
  309. printf("SE_SELF_RELATIVE");
  310. }
  311. printf("\n");
  312. }
  313. VOID
  314. DumpSECURITY_DESCRIPTOR(
  315. IN PSECURITY_DESCRIPTOR s
  316. )
  317. {
  318. BOOLEAN Defaulted, Present;
  319. PACL Acl;
  320. PSID Sid;
  321. SECURITY_DESCRIPTOR_CONTROL Control;
  322. ULONG Rev;
  323. try {
  324. printf("\nSecurityDescriptor -> Length = 0x%lx\n",
  325. RtlLengthSecurityDescriptor(s));
  326. RtlGetControlSecurityDescriptor(s,
  327. &Control,
  328. &Rev);
  329. DumpSECURITY_DESCRIPTOR_CONTROL(Control);
  330. printf("SecurityDescriptor -> Revision = 0x%lx\n",
  331. Rev);
  332. RtlGetOwnerSecurityDescriptor(s,
  333. &Sid,
  334. &Defaulted);
  335. printf("SecurityDescriptor -> Owner = ");
  336. if (Sid) {
  337. DumpSID(Sid);
  338. printf("\t");
  339. DumpSIDNAME(Sid);
  340. } else {
  341. printf("<NULL>\n");
  342. }
  343. RtlGetGroupSecurityDescriptor(s,
  344. &Sid,
  345. &Defaulted);
  346. printf("SecurityDescriptor -> Group = ");
  347. if (Sid) {
  348. DumpSID(Sid);
  349. printf("\t");
  350. DumpSIDNAME(Sid);
  351. } else {
  352. printf("<NULL>\n");
  353. }
  354. RtlGetDaclSecurityDescriptor(s,
  355. &Present,
  356. &Acl,
  357. &Defaulted);
  358. if (Present && Acl) {
  359. printf("SecurityDescriptor -> Dacl = \n");
  360. DumpACL(Acl);
  361. } else {
  362. printf("SecurityDescriptor -> Dacl = <not present>\n");
  363. }
  364. RtlGetSaclSecurityDescriptor(s,
  365. &Present,
  366. &Acl,
  367. &Defaulted);
  368. if (Present && Acl) {
  369. printf("SecurityDescriptor -> Sacl = \n");
  370. DumpACL(Acl);
  371. } else {
  372. printf("SecurityDescriptor -> Sacl = <not present>\n");
  373. }
  374. } except (EXCEPTION_EXECUTE_HANDLER) {
  375. printf("DumpSECURITY_DESCRIPTOR: invalid pointer (0x%p)\n",
  376. s);
  377. }
  378. }
  379. VOID
  380. DumpUNICODE_STRING(
  381. IN UNICODE_STRING *s
  382. )
  383. {
  384. ANSI_STRING a;
  385. try {
  386. printf("UnicodeString -> Length = 0x%x\n", s -> Length);
  387. printf("UnicodeString -> MaximumLength = 0x%x\n",
  388. s -> MaximumLength);
  389. RtlUnicodeStringToAnsiString(&a,
  390. s,
  391. TRUE);
  392. printf("UnicodeString -> Buffer (a la ansi) = \"%s\"\n",
  393. a.Buffer);
  394. RtlFreeAnsiString(&a);
  395. } except (EXCEPTION_EXECUTE_HANDLER) {
  396. printf("DumpUNICODE_STRING: invalid pointer (0x%p)\n", s);
  397. }
  398. }
  399. VOID
  400. Dump_ACE_TYPE(
  401. IN UCHAR t
  402. )
  403. {
  404. switch (t) {
  405. case ACCESS_ALLOWED_ACE_TYPE:
  406. printf("ACCESS_ALLOWED_ACE_TYPE\n");
  407. break;
  408. case ACCESS_DENIED_ACE_TYPE:
  409. printf("ACCESS_DENIED_ACE_TYPE\n");
  410. break;
  411. case SYSTEM_AUDIT_ACE_TYPE:
  412. printf("SYSTEM_AUDIT_ACE_TYPE\n");
  413. break;
  414. case SYSTEM_ALARM_ACE_TYPE:
  415. printf("SYSTEM_ALARM_ACE_TYPE\n");
  416. break;
  417. case ACCESS_ALLOWED_COMPOUND_ACE_TYPE:
  418. printf("ACCESS_ALLOWED_COMPOUND_ACE_TYPE\n");
  419. break;
  420. case ACCESS_ALLOWED_OBJECT_ACE_TYPE:
  421. printf("ACCESS_ALLOWED_OBJECT_ACE_TYPE\n");
  422. break;
  423. case ACCESS_DENIED_OBJECT_ACE_TYPE:
  424. printf("ACCESS_DENIED_OBJECT_ACE_TYPE\n");
  425. break;
  426. case SYSTEM_AUDIT_OBJECT_ACE_TYPE:
  427. printf("SYSTEM_AUDIT_OBJECT_ACE_TYPE\n");
  428. break;
  429. case SYSTEM_ALARM_OBJECT_ACE_TYPE:
  430. printf("SYSTEM_ALARM_OBJECT_ACE_TYPE\n");
  431. break;
  432. default:
  433. printf("(unknown ace type)\n");
  434. break;
  435. }
  436. }
  437. VOID
  438. Dump_ACE_FLAGS(
  439. IN UCHAR f
  440. )
  441. {
  442. if (f & INHERIT_ONLY_ACE) {
  443. printf("INHERIT_ONLY_ACE ");
  444. }
  445. if (f & NO_PROPAGATE_INHERIT_ACE) {
  446. printf("NO_PROPAGATE_INHERIT_ACE ");
  447. }
  448. if (f & CONTAINER_INHERIT_ACE) {
  449. printf("CONTAINER_INHERIT_ACE ");
  450. }
  451. if (f & OBJECT_INHERIT_ACE) {
  452. printf("OBJECT_INHERIT_ACE ");
  453. }
  454. if (f & INHERITED_ACE) {
  455. printf("INHERITED_ACE ");
  456. }
  457. if (f & SUCCESSFUL_ACCESS_ACE_FLAG) {
  458. printf("SUCCESSFUL_ACCESS_ACE_FLAG ");
  459. }
  460. if (f & FAILED_ACCESS_ACE_FLAG) {
  461. printf("FAILED_ACCESS_ACE_FLAG");
  462. }
  463. printf("\n");
  464. }
  465. VOID
  466. DumpSTRING(
  467. IN STRING *s
  468. )
  469. {
  470. try {
  471. printf("String -> Length = 0x%x\n", s -> Length);
  472. printf("String -> MaximumLength = 0x%x\n", s ->
  473. MaximumLength);
  474. printf("String -> Buffer = \"%s\"\n", s -> Buffer);
  475. } except (EXCEPTION_EXECUTE_HANDLER) {
  476. printf("DumpUNICODE_STRING: invalid pointer (0x%p)\n", s);
  477. }
  478. }