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.

388 lines
15 KiB

  1. /*++
  2. Copyright (c) 1991-1992 Microsoft Corporation
  3. Module Name:
  4. AudCpVar.c
  5. Abstract:
  6. This file contains RxpConvertAuditEntryVariableData.
  7. Author:
  8. John Rogers (JohnRo) 07-Nov-1991
  9. Environment:
  10. Portable to any flat, 32-bit environment. (Uses Win32 typedefs.)
  11. Requires ANSI C extensions: slash-slash comments, long external names.
  12. Notes:
  13. This code depends on the numeric values which are assigned to the
  14. AE_ equates in <lmaudit.h>.
  15. Revision History:
  16. 07-Nov-1991 JohnRo
  17. Created.
  18. 18-Nov-1991 JohnRo
  19. Fixed bug setting StringLocation for RapConvertSingleEntry.
  20. Fixed bug computing OutputStringOffset in macro.
  21. Added assertion checking.
  22. Made changes suggested by PC-LINT.
  23. 27-Jan-1992 JohnRo
  24. Fixed bug where *OutputVariableSizePtr was often not set.
  25. Use <winerror.h> and NO_ERROR where possible.
  26. 04-Feb-1992 JohnRo
  27. Oops, output variable size should include string sizes!
  28. 14-Jun-1992 JohnRo
  29. RAID 12410: NetAuditRead may trash memory.
  30. Fixed a bug where AE_NETLOGON records were being truncated.
  31. 07-Jul-1992 JohnRo
  32. RAID 9933: ALIGN_WORST should be 8 for x86 builds.
  33. 27-Oct-1992 JohnRo
  34. RAID 10218: Added AE_LOCKOUT support. Fixed AE_SRVSTATUS and
  35. AE_GENERIC.
  36. --*/
  37. // These must be included first:
  38. #include <windef.h> // IN, DWORD, etc.
  39. #include <lmcons.h> // DEVLEN, NET_API_STATUS, etc.
  40. #include <lmaudit.h> // Needed by rxaudit.h; AE_ equates.
  41. // These may be included in any order:
  42. #include <align.h> // ALIGN_ and related equates.
  43. #include <netdebug.h> // DBGSTATIC.
  44. #include <rap.h> // RapConvertSingleEntry(), etc.
  45. #include <remdef.h> // REM16_, REM32_ descriptors.
  46. #include <rxaudit.h> // My prototype.
  47. #include <smbgtpt.h> // SmbGet macros.
  48. #include <string.h> // strlen().
  49. #include <tstring.h> // MEMCPY(), NetpCopyStrToTStr().
  50. #include <winerror.h> // NO_ERROR.
  51. typedef struct {
  52. LPDESC Desc16;
  53. LPDESC Desc32;
  54. } AUDIT_CONV_DATA, *LPAUDIT_CONV_DATA;
  55. //
  56. // Conversion array, indexed by AE_ value (in ae_type field in fixed portion):
  57. //
  58. DBGSTATIC AUDIT_CONV_DATA DescriptorTable[] = {
  59. { REM16_audit_entry_srvstatus, REM32_audit_entry_srvstatus }, // 0
  60. { REM16_audit_entry_sesslogon, REM32_audit_entry_sesslogon }, // 1
  61. { REM16_audit_entry_sesslogoff, REM32_audit_entry_sesslogoff }, // 2
  62. { REM16_audit_entry_sesspwerr, REM32_audit_entry_sesspwerr }, // 3
  63. { REM16_audit_entry_connstart, REM32_audit_entry_connstart }, // 4
  64. { REM16_audit_entry_connstop, REM32_audit_entry_connstop }, // 5
  65. { REM16_audit_entry_connrej, REM32_audit_entry_connrej }, // 6
  66. // Note: 16-bit ae_resaccess and ae_resaccess2 both get converted to
  67. // the same structure (32-bit ae_resaccess).
  68. { REM16_audit_entry_resaccess, REM32_audit_entry_resaccess }, // 7
  69. { REM16_audit_entry_resaccessrej, REM32_audit_entry_resaccessrej }, // 8
  70. { REM16_audit_entry_closefile, REM32_audit_entry_closefile }, // 9
  71. { NULL, NULL }, // 10 reserved
  72. { REM16_audit_entry_servicestat, REM32_audit_entry_servicestat }, // 11
  73. { REM16_audit_entry_aclmod, REM32_audit_entry_aclmod }, // 12
  74. { REM16_audit_entry_uasmod, REM32_audit_entry_uasmod }, // 13
  75. { REM16_audit_entry_netlogon, REM32_audit_entry_netlogon }, // 14
  76. { REM16_audit_entry_netlogoff, REM32_audit_entry_netlogoff }, // 15
  77. { NULL, NULL }, // 16 AE_NETLOGDENIED not supported in LanMan 2.0
  78. { REM16_audit_entry_acclim, REM32_audit_entry_acclim }, // 17
  79. // Note: 16-bit ae_resaccess and ae_resaccess2 both get converted to
  80. // 32-bit ae_resaccess.
  81. { REM16_audit_entry_resaccess2, REM32_audit_entry_resaccess }, // 18
  82. { REM16_audit_entry_aclmod, REM32_audit_entry_aclmod }, // 19
  83. { REM16_audit_entry_lockout, REM32_audit_entry_lockout }, // 20
  84. { NULL, NULL } // 21 AE_GENERIC_TYPE
  85. // Add new entries here. Indexes must match AE_ equates in <lmaudit.h>.
  86. // Change AE_MAX_KNOWN below at same time.
  87. };
  88. // Max table entry:
  89. #define AE_MAX_KNOWN 21
  90. VOID
  91. RxpConvertAuditEntryVariableData(
  92. IN DWORD EntryType,
  93. IN LPVOID InputVariablePtr,
  94. OUT LPVOID OutputVariablePtr,
  95. IN DWORD InputVariableSize,
  96. OUT LPDWORD OutputVariableSizePtr
  97. )
  98. {
  99. BOOL DoByteCopy;
  100. NetpAssert( InputVariablePtr != NULL );
  101. NetpAssert( OutputVariablePtr != NULL );
  102. NetpAssert( POINTER_IS_ALIGNED( OutputVariablePtr, ALIGN_WORST ) );
  103. NetpAssert( InputVariablePtr != NULL );
  104. if (InputVariableSize == 0) {
  105. DoByteCopy = FALSE;
  106. *OutputVariableSizePtr = 0;
  107. } else if (EntryType > AE_MAX_KNOWN) {
  108. // Can't convert if there isn't even a table entry.
  109. DoByteCopy = TRUE;
  110. } else {
  111. LPAUDIT_CONV_DATA TableEntryPtr;
  112. TableEntryPtr = & DescriptorTable[EntryType];
  113. NetpAssert( TableEntryPtr != NULL );
  114. if (TableEntryPtr->Desc16 == NULL) {
  115. NetpAssert( TableEntryPtr->Desc32 == NULL );
  116. DoByteCopy = TRUE; // Table entry but no descriptors.
  117. } else {
  118. DWORD NonStringSize;
  119. DWORD OutputVariableSize; // (updated by CopyAndFixupString())
  120. LPTSTR StringLocation; // string in output entry (ditto)
  121. NET_API_STATUS Status;
  122. NetpAssert( TableEntryPtr->Desc32 != NULL );
  123. // No bytes yet (RapConvertSingleEntry will update).
  124. NonStringSize = 0;
  125. DoByteCopy = FALSE; // Assume intelligent conversion.
  126. // RapConvertSingleEntry should not do any strings, but expects
  127. // a "valid" StringLocation.
  128. StringLocation = (LPTSTR) ( ( (LPBYTE) OutputVariablePtr )
  129. + RapStructureSize(
  130. TableEntryPtr->Desc32,
  131. Both, // transmission mode
  132. TRUE) ); // want native size.
  133. //
  134. // Use RapConvertSingleEntry() to convert the DWORDS, etc.
  135. // These structures have 16-bit offsets to strings, which
  136. // we'll have to handle ourselves.
  137. //
  138. Status = RapConvertSingleEntry(
  139. InputVariablePtr, // in struct
  140. TableEntryPtr->Desc16, // in struct desc
  141. FALSE, // no meaningless input ptrs
  142. OutputVariablePtr, // out struct start
  143. OutputVariablePtr, // out struct
  144. TableEntryPtr->Desc32, // out struc desc
  145. FALSE, // we want ptrs, not offsets.
  146. (LPBYTE *) (LPVOID *) & StringLocation, // str area
  147. & NonStringSize, // bytes required (will be updated)
  148. Both, // transmission mode
  149. RapToNative); // conversion mode
  150. NetpAssert( Status == NO_ERROR );
  151. NetpAssert( NonStringSize > 0 );
  152. //
  153. // Set up for doing our own string copying.
  154. //
  155. StringLocation =
  156. (LPTSTR) ( (LPBYTE) OutputVariablePtr + NonStringSize );
  157. //
  158. // Macro to copy, convert, and update size to reflect a string.
  159. // OutputVariableSize must be set to the size of the fixed portion *BEFORE*
  160. // calling this macro.
  161. //
  162. #define CopyAndFixupString( OldFieldOffset, StructPtrType, NewFieldName ) \
  163. { \
  164. LPWORD InputFieldPtr = (LPWORD) \
  165. (((LPBYTE) InputVariablePtr) + (OldFieldOffset)); \
  166. DWORD InputStringOffset = (WORD) SmbGetUshort( InputFieldPtr ); \
  167. StructPtrType NewStruct = (LPVOID) OutputVariablePtr; \
  168. if (InputStringOffset != 0) { \
  169. LPSTR OldStringPtr \
  170. = ((LPSTR) InputVariablePtr) + InputStringOffset; \
  171. DWORD OldStringLen = (DWORD) strlen( OldStringPtr ); \
  172. DWORD OutputStringOffset; \
  173. DWORD OutputStringSize = (OldStringLen+1) * sizeof(TCHAR); \
  174. NetpCopyStrToTStr( \
  175. StringLocation, /* dest */ \
  176. OldStringPtr); /* src */ \
  177. OutputStringOffset = (DWORD) (((LPBYTE) StringLocation) \
  178. - (LPBYTE) OutputVariablePtr ); \
  179. NetpAssert( !RapValueWouldBeTruncated( OutputStringOffset ) ); \
  180. NewStruct->NewFieldName = OutputStringOffset; \
  181. OutputVariableSize += OutputStringSize; \
  182. StringLocation = (LPVOID) \
  183. ( ((LPBYTE)StringLocation) + OutputStringSize ); \
  184. } else { \
  185. NewStruct->NewFieldName = 0; \
  186. } \
  187. }
  188. switch (EntryType) {
  189. case AE_SRVSTATUS :
  190. OutputVariableSize = sizeof(struct _AE_SRVSTATUS);
  191. break;
  192. case AE_SESSLOGON :
  193. OutputVariableSize = sizeof(struct _AE_SESSLOGON);
  194. CopyAndFixupString( 0, LPAE_SESSLOGON, ae_so_compname );
  195. CopyAndFixupString( 2, LPAE_SESSLOGON, ae_so_username );
  196. break;
  197. case AE_SESSLOGOFF :
  198. OutputVariableSize = sizeof(struct _AE_SESSLOGOFF);
  199. CopyAndFixupString( 0, LPAE_SESSLOGOFF, ae_sf_compname );
  200. CopyAndFixupString( 2, LPAE_SESSLOGOFF, ae_sf_username );
  201. break;
  202. case AE_SESSPWERR :
  203. OutputVariableSize = sizeof(struct _AE_SESSPWERR);
  204. CopyAndFixupString( 0, LPAE_SESSPWERR, ae_sp_compname );
  205. CopyAndFixupString( 2, LPAE_SESSPWERR, ae_sp_username );
  206. break;
  207. case AE_CONNSTART :
  208. OutputVariableSize = sizeof(struct _AE_CONNSTART);
  209. CopyAndFixupString( 0, LPAE_CONNSTART, ae_ct_compname );
  210. CopyAndFixupString( 2, LPAE_CONNSTART, ae_ct_username );
  211. CopyAndFixupString( 4, LPAE_CONNSTART, ae_ct_netname );
  212. break;
  213. case AE_CONNSTOP :
  214. OutputVariableSize = sizeof(struct _AE_CONNSTOP);
  215. CopyAndFixupString( 0, LPAE_CONNSTOP, ae_cp_compname );
  216. CopyAndFixupString( 2, LPAE_CONNSTOP, ae_cp_username );
  217. CopyAndFixupString( 4, LPAE_CONNSTOP, ae_cp_netname );
  218. break;
  219. case AE_CONNREJ :
  220. OutputVariableSize = sizeof(struct _AE_CONNREJ);
  221. CopyAndFixupString( 0, LPAE_CONNREJ, ae_cr_compname );
  222. CopyAndFixupString( 2, LPAE_CONNREJ, ae_cr_username );
  223. CopyAndFixupString( 4, LPAE_CONNREJ, ae_cr_netname );
  224. break;
  225. case AE_RESACCESS : /* FALLTHROUGH */
  226. case AE_RESACCESS2 : // AE_RESACCESS is subset of AE_RESACCESS2
  227. // Note: 16-bit ae_resaccess and ae_resaccess2 both get
  228. // converted to the same 32-bit ae_resaccess structure.
  229. OutputVariableSize = sizeof(struct _AE_RESACCESS);
  230. CopyAndFixupString( 0, LPAE_RESACCESS, ae_ra_compname );
  231. CopyAndFixupString( 2, LPAE_RESACCESS, ae_ra_username );
  232. CopyAndFixupString( 4, LPAE_RESACCESS, ae_ra_resname );
  233. break;
  234. case AE_RESACCESSREJ :
  235. OutputVariableSize = sizeof(struct _AE_RESACCESSREJ);
  236. CopyAndFixupString( 0, LPAE_RESACCESSREJ, ae_rr_compname );
  237. CopyAndFixupString( 2, LPAE_RESACCESSREJ, ae_rr_username );
  238. CopyAndFixupString( 4, LPAE_RESACCESSREJ, ae_rr_resname );
  239. break;
  240. case AE_CLOSEFILE :
  241. OutputVariableSize = sizeof(struct _AE_CLOSEFILE);
  242. CopyAndFixupString( 0, LPAE_CLOSEFILE, ae_cf_compname );
  243. CopyAndFixupString( 2, LPAE_CLOSEFILE, ae_cf_username );
  244. CopyAndFixupString( 4, LPAE_CLOSEFILE, ae_cf_resname );
  245. break;
  246. case AE_SERVICESTAT :
  247. OutputVariableSize = sizeof(struct _AE_SERVICESTAT);
  248. CopyAndFixupString( 0, LPAE_SERVICESTAT, ae_ss_compname );
  249. CopyAndFixupString( 2, LPAE_SERVICESTAT, ae_ss_username );
  250. CopyAndFixupString( 4, LPAE_SERVICESTAT, ae_ss_svcname );
  251. CopyAndFixupString( 12, LPAE_SERVICESTAT, ae_ss_text );
  252. break;
  253. case AE_ACLMOD : /*FALLTHROUGH*/
  254. case AE_ACLMODFAIL :
  255. OutputVariableSize = sizeof(struct _AE_ACLMOD);
  256. CopyAndFixupString( 0, LPAE_ACLMOD, ae_am_compname );
  257. CopyAndFixupString( 2, LPAE_ACLMOD, ae_am_username );
  258. CopyAndFixupString( 4, LPAE_ACLMOD, ae_am_resname );
  259. break;
  260. case AE_UASMOD :
  261. OutputVariableSize = sizeof(struct _AE_UASMOD);
  262. CopyAndFixupString( 0, LPAE_UASMOD, ae_um_compname );
  263. CopyAndFixupString( 2, LPAE_UASMOD, ae_um_username );
  264. CopyAndFixupString( 4, LPAE_UASMOD, ae_um_resname );
  265. break;
  266. case AE_NETLOGON :
  267. OutputVariableSize = sizeof(struct _AE_NETLOGON);
  268. CopyAndFixupString( 0, LPAE_NETLOGON, ae_no_compname );
  269. CopyAndFixupString( 2, LPAE_NETLOGON, ae_no_username );
  270. break;
  271. case AE_NETLOGOFF :
  272. OutputVariableSize = sizeof(struct _AE_NETLOGOFF);
  273. CopyAndFixupString( 0, LPAE_NETLOGOFF, ae_nf_compname );
  274. CopyAndFixupString( 2, LPAE_NETLOGOFF, ae_nf_username );
  275. break;
  276. case AE_ACCLIMITEXCD :
  277. OutputVariableSize = sizeof(struct _AE_ACCLIM);
  278. CopyAndFixupString( 0, LPAE_ACCLIM, ae_al_compname );
  279. CopyAndFixupString( 2, LPAE_ACCLIM, ae_al_username );
  280. CopyAndFixupString( 4, LPAE_ACCLIM, ae_al_resname );
  281. break;
  282. case AE_LOCKOUT :
  283. OutputVariableSize = sizeof(struct _AE_LOCKOUT);
  284. CopyAndFixupString( 0, LPAE_LOCKOUT, ae_lk_compname );
  285. CopyAndFixupString( 2, LPAE_LOCKOUT, ae_lk_username );
  286. break;
  287. case AE_GENERIC_TYPE :
  288. OutputVariableSize = sizeof(struct _AE_GENERIC);
  289. break;
  290. default :
  291. // We don't know about this type.
  292. // AE_NETLOGDENIED (16) falls into this category.
  293. DoByteCopy = TRUE;
  294. OutputVariableSize = InputVariableSize;
  295. break;
  296. }
  297. *OutputVariableSizePtr = OutputVariableSize;
  298. }
  299. }
  300. if (DoByteCopy == TRUE) {
  301. (void) MEMCPY(
  302. OutputVariablePtr, // dest
  303. InputVariablePtr, // src
  304. InputVariableSize ); // byte count
  305. *OutputVariableSizePtr = InputVariableSize;
  306. }
  307. }