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.

2743 lines
74 KiB

  1. /*++
  2. Copyright (c) 1989 Microsoft Corporation
  3. Module Name:
  4. ea.c
  5. Abstract:
  6. This module implements the mini redirector call down routines pertaining to query/set ea/security.
  7. Author:
  8. joelinn [joelinn] 12-jul-95
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. #pragma hdrstop
  13. //
  14. // Forward declarations.
  15. //
  16. #if defined(REMOTE_BOOT)
  17. VOID
  18. MRxSmbInitializeExtraAceArray(
  19. VOID
  20. );
  21. BOOLEAN
  22. MRxSmbAclHasExtraAces(
  23. IN PACL Acl
  24. );
  25. NTSTATUS
  26. MRxSmbRemoveExtraAcesFromSelfRelativeSD(
  27. IN PSECURITY_DESCRIPTOR OriginalSecurityDescriptor,
  28. OUT PSECURITY_DESCRIPTOR * NewSecurityDescriptor,
  29. OUT PBOOLEAN WereRemoved
  30. );
  31. NTSTATUS
  32. MRxSmbAddExtraAcesToSelfRelativeSD(
  33. IN PSECURITY_DESCRIPTOR OriginalSecurityDescriptor,
  34. IN BOOLEAN InheritableAces,
  35. OUT PSECURITY_DESCRIPTOR * NewSecurityDescriptor
  36. );
  37. NTSTATUS
  38. MRxSmbCreateExtraAcesSelfRelativeSD(
  39. IN BOOLEAN InheritableAces,
  40. OUT PSECURITY_DESCRIPTOR * NewSecurityDescriptor
  41. );
  42. NTSTATUS
  43. MRxSmbSelfRelativeToAbsoluteSD(
  44. IN PSECURITY_DESCRIPTOR SelfRelativeSecurityDescriptor,
  45. OUT PSECURITY_DESCRIPTOR * AbsoluteSecurityDescriptor,
  46. OUT PACL * Dacl,
  47. OUT PACL * Sacl,
  48. OUT PSID * Owner,
  49. OUT PSID * Group
  50. );
  51. NTSTATUS
  52. MRxSmbAbsoluteToSelfRelativeSD(
  53. PSECURITY_DESCRIPTOR AbsoluteSecurityDescriptor,
  54. PSECURITY_DESCRIPTOR * SelfRelativeSecurityDescriptor
  55. );
  56. //
  57. // Definitions from ntrtl.h
  58. //
  59. NTSYSAPI
  60. NTSTATUS
  61. NTAPI
  62. RtlAbsoluteToSelfRelativeSD(
  63. PSECURITY_DESCRIPTOR AbsoluteSecurityDescriptor,
  64. PSECURITY_DESCRIPTOR SelfRelativeSecurityDescriptor,
  65. PULONG BufferLength
  66. );
  67. NTSYSAPI
  68. NTSTATUS
  69. NTAPI
  70. RtlSelfRelativeToAbsoluteSD(
  71. PSECURITY_DESCRIPTOR SelfRelativeSecurityDescriptor,
  72. PSECURITY_DESCRIPTOR AbsoluteSecurityDescriptor,
  73. PULONG AbsoluteSecurityDescriptorSize,
  74. PACL Dacl,
  75. PULONG DaclSize,
  76. PACL Sacl,
  77. PULONG SaclSize,
  78. PSID Owner,
  79. PULONG OwnerSize,
  80. PSID PrimaryGroup,
  81. PULONG PrimaryGroupSize
  82. );
  83. NTSYSAPI
  84. NTSTATUS
  85. NTAPI
  86. RtlAddAce (
  87. PACL Acl,
  88. ULONG AceRevision,
  89. ULONG StartingAceIndex,
  90. PVOID AceList,
  91. ULONG AceListLength
  92. );
  93. NTSYSAPI
  94. NTSTATUS
  95. NTAPI
  96. RtlDeleteAce (
  97. PACL Acl,
  98. ULONG AceIndex
  99. );
  100. NTSYSAPI
  101. NTSTATUS
  102. NTAPI
  103. RtlGetAce (
  104. PACL Acl,
  105. ULONG AceIndex,
  106. PVOID *Ace
  107. );
  108. #endif // defined(REMOTE_BOOT)
  109. #ifdef ALLOC_PRAGMA
  110. #pragma alloc_text(PAGE, MRxSmbQueryEaInformation)
  111. #pragma alloc_text(PAGE, MRxSmbSetEaInformation)
  112. #if defined(REMOTE_BOOT)
  113. #pragma alloc_text(PAGE, MRxSmbInitializeExtraAceArray)
  114. #pragma alloc_text(PAGE, MRxSmbAclHasExtraAces)
  115. #pragma alloc_text(PAGE, MRxSmbRemoveExtraAcesFromSelfRelativeSD)
  116. #pragma alloc_text(PAGE, MRxSmbAddExtraAcesToSelfRelativeSD)
  117. #pragma alloc_text(PAGE, MRxSmbSelfRelativeToAbsoluteSD)
  118. #pragma alloc_text(PAGE, MRxSmbAbsoluteToSelfRelativeSD)
  119. #endif // defined(REMOTE_BOOT)
  120. #pragma alloc_text(PAGE, MRxSmbQuerySecurityInformation)
  121. #pragma alloc_text(PAGE, MRxSmbSetSecurityInformation)
  122. #pragma alloc_text(PAGE, MRxSmbLoadEaList)
  123. #pragma alloc_text(PAGE, MRxSmbNtGeaListToOs2)
  124. #pragma alloc_text(PAGE, MRxSmbNtGetEaToOs2)
  125. #pragma alloc_text(PAGE, MRxSmbQueryEasFromServer)
  126. #pragma alloc_text(PAGE, MRxSmbNtFullEaSizeToOs2)
  127. #pragma alloc_text(PAGE, MRxSmbNtFullListToOs2)
  128. #pragma alloc_text(PAGE, MRxSmbNtFullEaToOs2)
  129. #pragma alloc_text(PAGE, MRxSmbSetEaList)
  130. #endif
  131. ////
  132. //// The Bug check file id for this module
  133. ////
  134. //
  135. //#define BugCheckFileId (RDBSS_BUG_CHECK_LOCAL_CREATE)
  136. //
  137. // The local debug trace level
  138. //
  139. #define Dbg (DEBUG_TRACE_EA)
  140. //this is the largest EAs that could ever be returned! oh my god!
  141. //this is used to simulate the nt resumable queryEA using the downlevel call
  142. //sigh!
  143. #define EA_QUERY_SIZE 0x0000ffff
  144. #if defined(REMOTE_BOOT)
  145. //
  146. // ACEs that are added to the front of server ACLs. The array is
  147. // initialized by MRxSmbInitializeExtraAceArray.
  148. //
  149. typedef struct _EXTRA_ACE_INFO {
  150. UCHAR AceType;
  151. UCHAR AceFlags;
  152. USHORT AceSize;
  153. ACCESS_MASK Mask;
  154. PVOID Sid;
  155. } EXTRA_ACE_INFO, *PEXTRA_ACE_INFO;
  156. #define EXTRA_ACE_INFO_COUNT 4
  157. EXTRA_ACE_INFO ExtraAceInfo[EXTRA_ACE_INFO_COUNT];
  158. ULONG ExtraAceInfoCount;
  159. #endif // defined(REMOTE_BOOT)
  160. //for QueryEA
  161. NTSTATUS
  162. MRxSmbLoadEaList(
  163. IN PRX_CONTEXT RxContext,
  164. IN PUCHAR UserEaList,
  165. IN ULONG UserEaListLength,
  166. OUT PFEALIST *ServerEaList
  167. );
  168. NTSTATUS
  169. MRxSmbQueryEasFromServer(
  170. IN PRX_CONTEXT RxContext,
  171. IN PFEALIST ServerEaList,
  172. IN PVOID Buffer,
  173. IN OUT PULONG BufferLengthRemaining,
  174. IN BOOLEAN ReturnSingleEntry,
  175. IN BOOLEAN UserEaListSupplied
  176. );
  177. //for SetEA
  178. NTSTATUS
  179. MRxSmbSetEaList(
  180. // IN PICB Icb,
  181. // IN PIRP Irp,
  182. IN PRX_CONTEXT RxContext,
  183. IN PFEALIST ServerEaList
  184. );
  185. VOID MRxSmbExtraEaRoutine(LONG i){
  186. RxDbgTrace( 0, Dbg, ("MRxSmbExtraEaRoutine i=%08lx\n", i ));
  187. }
  188. NTSTATUS
  189. MRxSmbQueryEaInformation (
  190. IN OUT PRX_CONTEXT RxContext
  191. )
  192. {
  193. NTSTATUS Status;
  194. RxCaptureFcb;
  195. RxCaptureFobx;
  196. PSMBCEDB_SERVER_ENTRY pServerEntry;
  197. PVOID Buffer = RxContext->Info.Buffer;
  198. PLONG pLengthRemaining = &RxContext->Info.LengthRemaining;
  199. PUCHAR UserEaList = RxContext->QueryEa.UserEaList;
  200. ULONG UserEaListLength = RxContext->QueryEa.UserEaListLength;
  201. ULONG UserEaIndex = RxContext->QueryEa.UserEaIndex;
  202. BOOLEAN RestartScan = RxContext->QueryEa.RestartScan;
  203. BOOLEAN ReturnSingleEntry = RxContext->QueryEa.ReturnSingleEntry;
  204. BOOLEAN IndexSpecified = RxContext->QueryEa.IndexSpecified;
  205. PFEALIST ServerEaList = NULL;
  206. PAGED_CODE();
  207. RxDbgTrace(+1, Dbg, ("MRxSmbQueryEaInformation\n"));
  208. pServerEntry = SmbCeGetAssociatedServerEntry(capFcb->pNetRoot->pSrvCall);
  209. //get rid of nonEA guys right now
  210. if (!FlagOn(pServerEntry->Server.DialectFlags,DF_SUPPORTEA)) {
  211. RxDbgTrace(-1, Dbg, ("EAs w/o EA support!\n"));
  212. return((STATUS_NOT_SUPPORTED));
  213. }
  214. if (MRxSmbIsThisADisconnectedOpen(capFobx->pSrvOpen)) {
  215. return STATUS_ONLY_IF_CONNECTED;
  216. }
  217. Status = MRxSmbDeferredCreate(RxContext);
  218. if (Status!=STATUS_SUCCESS) {
  219. goto FINALLY;
  220. }
  221. Status = MRxSmbLoadEaList( RxContext, UserEaList, UserEaListLength, &ServerEaList );
  222. if (( !NT_SUCCESS( Status ) )||
  223. ( ServerEaList == NULL )) {
  224. goto FINALLY;
  225. }
  226. if (IndexSpecified) {
  227. //CODE.IMPROVEMENT this name is poor....it owes back to the fastfat heritage and is not so meaningful
  228. // for a rdr
  229. capFobx->OffsetOfNextEaToReturn = UserEaIndex;
  230. Status = MRxSmbQueryEasFromServer(
  231. RxContext,
  232. ServerEaList,
  233. Buffer,
  234. pLengthRemaining,
  235. ReturnSingleEntry,
  236. (BOOLEAN)(UserEaList != NULL) );
  237. //
  238. // if there are no Ea's on the file, and the user supplied an EA
  239. // index, we want to map the error to STATUS_NONEXISTANT_EA_ENTRY.
  240. //
  241. if ( Status == STATUS_NO_EAS_ON_FILE ) {
  242. Status = STATUS_NONEXISTENT_EA_ENTRY;
  243. }
  244. } else {
  245. if ( ( RestartScan == TRUE ) || (UserEaList != NULL) ){
  246. //
  247. // Ea Indices start at 1, not 0....
  248. //
  249. capFobx->OffsetOfNextEaToReturn = 1;
  250. }
  251. Status = MRxSmbQueryEasFromServer( //it is offensive to have two identical calls but oh, well.....
  252. RxContext,
  253. ServerEaList,
  254. Buffer,
  255. pLengthRemaining,
  256. ReturnSingleEntry,
  257. (BOOLEAN)(UserEaList != NULL) );
  258. }
  259. FINALLY:
  260. if ( ServerEaList != NULL) {
  261. RxFreePool(ServerEaList);
  262. }
  263. RxDbgTrace(-1, Dbg, ("MRxSmbQueryEaInformation st=%08lx\n",Status));
  264. return Status;
  265. }
  266. NTSTATUS
  267. MRxSmbSetEaInformation (
  268. IN OUT struct _RX_CONTEXT * RxContext
  269. )
  270. {
  271. NTSTATUS Status;
  272. RxCaptureFcb; RxCaptureFobx;
  273. PSMBCEDB_SERVER_ENTRY pServerEntry;
  274. PVOID Buffer = RxContext->Info.Buffer;
  275. ULONG Length = RxContext->Info.Length;
  276. PFEALIST ServerEaList = NULL;
  277. ULONG Size;
  278. PAGED_CODE();
  279. RxDbgTrace(+1, Dbg, ("MRxSmbSetEaInformation\n"));
  280. pServerEntry = SmbCeGetAssociatedServerEntry(capFcb->pNetRoot->pSrvCall);
  281. //get rid of nonEA guys right now
  282. if (!FlagOn(pServerEntry->Server.DialectFlags,DF_SUPPORTEA)) {
  283. RxDbgTrace(-1, Dbg, ("EAs w/o EA support!\n"));
  284. return((STATUS_NOT_SUPPORTED));
  285. }
  286. if (MRxSmbIsThisADisconnectedOpen(capFobx->pSrvOpen)) {
  287. return STATUS_ONLY_IF_CONNECTED;
  288. }
  289. Status = MRxSmbDeferredCreate(RxContext);
  290. if (Status!=STATUS_SUCCESS) {
  291. goto FINALLY;
  292. }
  293. //
  294. // Convert Nt format FEALIST to OS/2 format
  295. //
  296. Size = MRxSmbNtFullEaSizeToOs2 ( Buffer );
  297. if ( Size > 0x0000ffff ) {
  298. Status = STATUS_EA_TOO_LARGE;
  299. goto FINALLY;
  300. }
  301. //CODE.IMPROVEMENT since |os2eas|<=|nteas| we really don't need a maximum buffer
  302. ServerEaList = RxAllocatePool ( PagedPool, EA_QUERY_SIZE );
  303. if ( ServerEaList == NULL ) {
  304. Status = STATUS_INSUFFICIENT_RESOURCES;
  305. goto FINALLY;
  306. }
  307. MRxSmbNtFullListToOs2 ( Buffer, ServerEaList );
  308. //
  309. // Set EAs on the file/directory; if the error is EA_ERROR then SetEaList
  310. // sets iostatus.information to the offset of the offender
  311. //
  312. Status = MRxSmbSetEaList( RxContext, ServerEaList);
  313. FINALLY:
  314. if ( ServerEaList != NULL) {
  315. RxFreePool(ServerEaList);
  316. }
  317. if (Status == STATUS_SUCCESS) {
  318. // invalidate the name based file info cache since the attributes of the file on
  319. // the server have been changed
  320. MRxSmbInvalidateFileInfoCache(RxContext);
  321. }
  322. RxDbgTrace(-1, Dbg, ("MRxSmbSetEaInformation st=%08lx\n",Status));
  323. return Status;
  324. }
  325. #if DBG
  326. VOID
  327. MRxSmbDumpSecurityDescriptor(
  328. IN PSECURITY_DESCRIPTOR SecurityDescriptor
  329. )
  330. {
  331. PISECURITY_DESCRIPTOR sd = (PISECURITY_DESCRIPTOR)SecurityDescriptor;
  332. ULONG sdLength = RtlLengthSecurityDescriptor(sd);
  333. PACL dacl;
  334. PACCESS_ALLOWED_ACE ace;
  335. ULONG i, j;
  336. PUCHAR p;
  337. PISID sid;
  338. BOOLEAN selfRelative;
  339. selfRelative = (BOOLEAN)((sd->Control & SE_SELF_RELATIVE) != 0);
  340. DbgPrint( " SD:\n" );
  341. DbgPrint( " Revision = %x, Control = %x\n", sd->Revision, sd->Control );
  342. DbgPrint( " Owner = %x, Group = %x\n", sd->Owner, sd->Group );
  343. DbgPrint( " Sacl = %x, Dacl = %x\n", sd->Sacl, sd->Dacl );
  344. if ( (sd->Control & SE_DACL_PRESENT) != 0 ) {
  345. dacl = sd->Dacl;
  346. if ( selfRelative ) {
  347. dacl = (PACL)((PUCHAR)sd + (ULONG_PTR)dacl);
  348. }
  349. DbgPrint( " DACL:\n" );
  350. DbgPrint( " AclRevision = %x, AclSize = %x, AceCount = %x\n",
  351. dacl->AclRevision, dacl->AclSize, dacl->AceCount );
  352. ace = (PACCESS_ALLOWED_ACE)(dacl + 1);
  353. for ( i = 0; i < dacl->AceCount; i++ ) {
  354. DbgPrint( " ACE %d:\n", i );
  355. DbgPrint( " AceType = %x, AceFlags = %x, AceSize = %x\n",
  356. ace->Header.AceType, ace->Header.AceFlags, ace->Header.AceSize );
  357. if ( ace->Header.AceType < ACCESS_MAX_MS_V2_ACE_TYPE ) {
  358. DbgPrint(" Mask = %08x, Sid = ", ace->Mask );
  359. for ( j = FIELD_OFFSET(ACCESS_ALLOWED_ACE,SidStart), p = (PUCHAR)&ace->SidStart;
  360. j < ace->Header.AceSize;
  361. j++, p++ ) {
  362. DbgPrint( "%02x ", *p );
  363. }
  364. DbgPrint( "\n" );
  365. }
  366. ace = (PACCESS_ALLOWED_ACE)((PUCHAR)ace + ace->Header.AceSize );
  367. }
  368. }
  369. if ( sd->Owner != 0 ) {
  370. sid = sd->Owner;
  371. if ( selfRelative ) {
  372. sid = (PISID)((PUCHAR)sd + (ULONG_PTR)sid);
  373. }
  374. DbgPrint( " Owner SID:\n" );
  375. DbgPrint( " Revision = %x, SubAuthorityCount = %x\n",
  376. sid->Revision, sid->SubAuthorityCount );
  377. DbgPrint( " IdentifierAuthority = " );
  378. for ( j = 0; j < 6; j++ ) {
  379. DbgPrint( "%02x ", sid->IdentifierAuthority.Value[j] );
  380. }
  381. DbgPrint( "\n" );
  382. for ( i = 0; i < sid->SubAuthorityCount; i++ ) {
  383. DbgPrint(" SubAuthority %d = ", i );
  384. for ( j = 0, p = (PUCHAR)&sid->SubAuthority[i]; j < 4; j++, p++ ) {
  385. DbgPrint( "%02x ", *p );
  386. }
  387. DbgPrint( "\n" );
  388. }
  389. }
  390. }
  391. #endif
  392. #if defined(REMOTE_BOOT)
  393. VOID
  394. MRxSmbInitializeExtraAceArray(
  395. VOID
  396. )
  397. /*++
  398. Routine Description:
  399. This routine initializes the array of extra ACEs that we add to
  400. the front of ACLs for files on the server. It must be called
  401. *after* SeEnableAccessToExports has been called.
  402. Arguments:
  403. None.
  404. Return Value:
  405. None.
  406. --*/
  407. {
  408. ULONG i;
  409. PAGED_CODE();
  410. //
  411. // Our code assumes the ACEs we use have the same structure.
  412. //
  413. ASSERT(FIELD_OFFSET(ACCESS_ALLOWED_ACE, SidStart) ==
  414. FIELD_OFFSET(ACCESS_DENIED_ACE, SidStart));
  415. ASSERT((sizeof(ExtraAceInfo) / sizeof(EXTRA_ACE_INFO)) == EXTRA_ACE_INFO_COUNT);
  416. ExtraAceInfoCount = EXTRA_ACE_INFO_COUNT;
  417. ExtraAceInfo[0].AceType = ACCESS_ALLOWED_ACE_TYPE;
  418. ExtraAceInfo[0].AceFlags = 0;
  419. ExtraAceInfo[0].Mask = FILE_ALL_ACCESS;
  420. ExtraAceInfo[0].Sid = MRxSmbRemoteBootMachineSid;
  421. ExtraAceInfo[1].AceType = ACCESS_ALLOWED_ACE_TYPE;
  422. ExtraAceInfo[1].AceFlags = 0;
  423. ExtraAceInfo[1].Mask = FILE_ALL_ACCESS;
  424. ExtraAceInfo[1].Sid = SeExports->SeLocalSystemSid;
  425. ExtraAceInfo[2].AceType = ACCESS_ALLOWED_ACE_TYPE;
  426. ExtraAceInfo[2].AceFlags = 0;
  427. ExtraAceInfo[2].Mask = FILE_ALL_ACCESS;
  428. ExtraAceInfo[2].Sid = SeExports->SeAliasAdminsSid;
  429. ExtraAceInfo[3].AceType = ACCESS_DENIED_ACE_TYPE;
  430. ExtraAceInfo[3].AceFlags = 0;
  431. ExtraAceInfo[3].Mask = FILE_ALL_ACCESS;
  432. ExtraAceInfo[3].Sid = SeExports->SeWorldSid;
  433. for (i = 0; i < ExtraAceInfoCount; i++) {
  434. ExtraAceInfo[i].AceSize = (USHORT)(FIELD_OFFSET(ACCESS_ALLOWED_ACE, SidStart) +
  435. RtlLengthSid((PSID)(ExtraAceInfo[i].Sid)));
  436. }
  437. }
  438. BOOLEAN
  439. MRxSmbAclHasExtraAces(
  440. IN PACL Acl
  441. )
  442. /*++
  443. Routine Description:
  444. This routine determines if an ACL has the special ACEs that we
  445. put on the front for remote boot server files.
  446. Arguments:
  447. Acl - The ACL to check.
  448. Return Value:
  449. TRUE if the ACEs are there, FALSE otherwise (including if there
  450. are any errors while checking).
  451. --*/
  452. {
  453. PACCESS_ALLOWED_ACE Ace;
  454. ULONG KnownSidLength;
  455. ULONG i;
  456. NTSTATUS Status;
  457. PAGED_CODE();
  458. //
  459. // Make sure the first n ACEs in this ACL match those in our
  460. // array.
  461. //
  462. for (i = 0; i < ExtraAceInfoCount; i++) {
  463. Status = RtlGetAce(Acl, i, &Ace);
  464. if (!NT_SUCCESS(Status)) {
  465. return FALSE;
  466. }
  467. KnownSidLength = ExtraAceInfo[i].AceSize - FIELD_OFFSET(ACCESS_ALLOWED_ACE, SidStart);
  468. //
  469. // Don't compare the flags to avoid worrying about inherited
  470. // flags.
  471. //
  472. if ((Ace->Header.AceType != ExtraAceInfo[i].AceType) ||
  473. // TMP: my server doesn't store 0x200 bit // (Ace->Mask != ExtraAceInfo[i].Mask) ||
  474. (RtlLengthSid((PSID)(&Ace->SidStart)) != KnownSidLength) ||
  475. (memcmp(&Ace->SidStart, ExtraAceInfo[i].Sid, KnownSidLength) != 0)) {
  476. return FALSE;
  477. }
  478. }
  479. //
  480. // Everything matched, so it does have the extra ACEs.
  481. //
  482. return TRUE;
  483. }
  484. NTSTATUS
  485. MRxSmbSelfRelativeToAbsoluteSD(
  486. IN PSECURITY_DESCRIPTOR SelfRelativeSecurityDescriptor,
  487. OUT PSECURITY_DESCRIPTOR * AbsoluteSecurityDescriptor,
  488. OUT PACL * Dacl,
  489. OUT PACL * Sacl,
  490. OUT PSID * Owner,
  491. OUT PSID * Group
  492. )
  493. /*++
  494. Routine Description:
  495. This routine converts a self-relative security descriptor to
  496. absolute form, allocating all the entries needed.
  497. Arguments:
  498. Return Value:
  499. Status - Result of the operation.
  500. --*/
  501. {
  502. NTSTATUS Status;
  503. ULONG AbsoluteSecurityDescriptorSize = 0;
  504. ULONG GroupSize = 0;
  505. ULONG OwnerSize = 0;
  506. ULONG SaclSize = 0;
  507. ULONG DaclSize = 0;
  508. PUCHAR AllocatedBuffer;
  509. ULONG AllocatedBufferSize;
  510. PAGED_CODE();
  511. *AbsoluteSecurityDescriptor = NULL;
  512. *Owner = NULL;
  513. *Group = NULL;
  514. *Dacl = NULL;
  515. *Sacl = NULL;
  516. //
  517. // First determine how much storage is needed by the SD.
  518. //
  519. Status = RtlSelfRelativeToAbsoluteSD(
  520. SelfRelativeSecurityDescriptor,
  521. NULL,
  522. &AbsoluteSecurityDescriptorSize,
  523. NULL,
  524. &DaclSize,
  525. NULL,
  526. &SaclSize,
  527. NULL,
  528. &OwnerSize,
  529. NULL,
  530. &GroupSize);
  531. //
  532. // We expect to get this error since at least the core of the SD
  533. // has some non-zero size.
  534. //
  535. if (Status == STATUS_BUFFER_TOO_SMALL) {
  536. AllocatedBufferSize =
  537. AbsoluteSecurityDescriptorSize +
  538. OwnerSize +
  539. GroupSize +
  540. SaclSize +
  541. DaclSize;
  542. ASSERT(AllocatedBufferSize > 0);
  543. AllocatedBuffer = RxAllocatePoolWithTag(PagedPool, AllocatedBufferSize, MRXSMB_REMOTEBOOT_POOLTAG);
  544. if (AllocatedBuffer == NULL) {
  545. return STATUS_INSUFFICIENT_RESOURCES;
  546. }
  547. //
  548. // Walk through each piece of memory we need and take a chunk
  549. // of AllocatedBuffer. The caller assumes that AbsoluteSecurityDescriptor
  550. // will be the address of the buffer they need to free, so we always
  551. // set that even if the size needed is 0 (which should never happen!).
  552. // For the others we set them if the size needed is not NULL.
  553. //
  554. ASSERT(AbsoluteSecurityDescriptorSize > 0);
  555. *AbsoluteSecurityDescriptor = (PSECURITY_DESCRIPTOR)AllocatedBuffer;
  556. AllocatedBuffer += AbsoluteSecurityDescriptorSize;
  557. if (OwnerSize > 0) {
  558. *Owner = (PSID)AllocatedBuffer;
  559. AllocatedBuffer += OwnerSize;
  560. }
  561. if (GroupSize > 0) {
  562. *Group = (PSID)AllocatedBuffer;
  563. AllocatedBuffer += GroupSize;
  564. }
  565. if (SaclSize > 0) {
  566. *Sacl = (PACL)AllocatedBuffer;
  567. AllocatedBuffer += SaclSize;
  568. }
  569. if (DaclSize > 0) {
  570. *Dacl = (PACL)AllocatedBuffer;
  571. }
  572. //
  573. // Now make the call again to really do the conversion.
  574. //
  575. Status = RtlSelfRelativeToAbsoluteSD(
  576. SelfRelativeSecurityDescriptor,
  577. *AbsoluteSecurityDescriptor,
  578. &AbsoluteSecurityDescriptorSize,
  579. *Dacl,
  580. &DaclSize,
  581. *Sacl,
  582. &SaclSize,
  583. *Owner,
  584. &OwnerSize,
  585. *Group,
  586. &GroupSize);
  587. } else {
  588. Status = STATUS_INVALID_PARAMETER;
  589. }
  590. if (!NT_SUCCESS(Status) && (*AbsoluteSecurityDescriptor != NULL)) {
  591. RxFreePool(*AbsoluteSecurityDescriptor);
  592. *AbsoluteSecurityDescriptor = NULL;
  593. }
  594. return Status;
  595. }
  596. NTSTATUS
  597. MRxSmbAbsoluteToSelfRelativeSD(
  598. PSECURITY_DESCRIPTOR AbsoluteSecurityDescriptor,
  599. PSECURITY_DESCRIPTOR * SelfRelativeSecurityDescriptor
  600. )
  601. /*++
  602. Routine Description:
  603. This routine converts an absolute security descriptor to
  604. self-relative form, allocating all the entries needed.
  605. Arguments:
  606. Return Value:
  607. Status - Result of the operation.
  608. --*/
  609. {
  610. NTSTATUS Status;
  611. ULONG SelfRelativeSdSize = 0;
  612. PAGED_CODE();
  613. *SelfRelativeSecurityDescriptor = NULL;
  614. Status = RtlAbsoluteToSelfRelativeSD(
  615. AbsoluteSecurityDescriptor,
  616. NULL,
  617. &SelfRelativeSdSize);
  618. ASSERT(Status == STATUS_BUFFER_TOO_SMALL);
  619. *SelfRelativeSecurityDescriptor = RxAllocatePoolWithTag(NonPagedPool, SelfRelativeSdSize, MRXSMB_REMOTEBOOT_POOLTAG);
  620. if (*SelfRelativeSecurityDescriptor == NULL) {
  621. return STATUS_INSUFFICIENT_RESOURCES;
  622. }
  623. //
  624. // Now do the real conversion.
  625. //
  626. Status = RtlAbsoluteToSelfRelativeSD(
  627. AbsoluteSecurityDescriptor,
  628. *SelfRelativeSecurityDescriptor,
  629. &SelfRelativeSdSize);
  630. if (!NT_SUCCESS(Status) && (*SelfRelativeSecurityDescriptor != NULL)) {
  631. RxFreePool(*SelfRelativeSecurityDescriptor);
  632. *SelfRelativeSecurityDescriptor = NULL;
  633. }
  634. return Status;
  635. }
  636. NTSTATUS
  637. MRxSmbRemoveExtraAcesFromSelfRelativeSD(
  638. IN PSECURITY_DESCRIPTOR OriginalSecurityDescriptor,
  639. OUT PSECURITY_DESCRIPTOR * NewSecurityDescriptor,
  640. OUT PBOOLEAN WereRemoved
  641. )
  642. /*++
  643. Routine Description:
  644. This routine takes an existing self-relative security descriptor
  645. and produces a new self-relative security descriptor with our
  646. extra ACEs removed. It returns S_FALSE if they did not need to
  647. be removed.
  648. Arguments:
  649. Return Value:
  650. Status - Result of the operation.
  651. --*/
  652. {
  653. NTSTATUS Status;
  654. PSECURITY_DESCRIPTOR AbsoluteSd = NULL;
  655. PSID Owner;
  656. PSID Group;
  657. PACL Dacl;
  658. PACL Sacl;
  659. PACL NewDacl = NULL;
  660. ULONG NewDaclSize;
  661. BOOLEAN DaclPresent, DaclDefaulted;
  662. *NewSecurityDescriptor = NULL;
  663. *WereRemoved = FALSE;
  664. //
  665. // Check if we need to strip off any ACEs in the DACL
  666. // that SetSecurityInformation may have added.
  667. //
  668. Status = RtlGetDaclSecurityDescriptor(
  669. OriginalSecurityDescriptor,
  670. &DaclPresent,
  671. &Dacl,
  672. &DaclDefaulted);
  673. if (!NT_SUCCESS(Status)) {
  674. goto CLEANUP;
  675. }
  676. if (DaclPresent &&
  677. (Dacl != NULL) &&
  678. MRxSmbAclHasExtraAces(Dacl)) {
  679. ULONG i;
  680. //
  681. // Need to strip the extra ACEs off.
  682. //
  683. // First convert the SD to absolute.
  684. //
  685. Status = MRxSmbSelfRelativeToAbsoluteSD(
  686. OriginalSecurityDescriptor,
  687. &AbsoluteSd,
  688. &Dacl,
  689. &Sacl,
  690. &Owner,
  691. &Group);
  692. if (!NT_SUCCESS(Status)) {
  693. goto CLEANUP;
  694. }
  695. //
  696. // Now modify the DACL. Each delete moves
  697. // the other ACEs down, so we just delete
  698. // ACE 0 as many times as needed.
  699. //
  700. for (i = 0; i < ExtraAceInfoCount; i++) {
  701. Status = RtlDeleteAce(
  702. Dacl,
  703. 0);
  704. if (!NT_SUCCESS(Status)) {
  705. goto CLEANUP;
  706. }
  707. }
  708. //
  709. // If the resulting Dacl has no ACEs, then remove it
  710. // since a DACL with no ACEs implies no access.
  711. //
  712. if (Dacl->AceCount == 0) {
  713. Status = RtlSetDaclSecurityDescriptor(
  714. AbsoluteSd,
  715. FALSE,
  716. NULL,
  717. FALSE);
  718. }
  719. //
  720. // Allocate and convert back to self-relative.
  721. //
  722. Status = MRxSmbAbsoluteToSelfRelativeSD(
  723. AbsoluteSd,
  724. NewSecurityDescriptor);
  725. if (!NT_SUCCESS(Status)) {
  726. goto CLEANUP;
  727. }
  728. *WereRemoved = TRUE;
  729. }
  730. CLEANUP:
  731. if (AbsoluteSd != NULL) {
  732. RxFreePool(AbsoluteSd);
  733. }
  734. if (!NT_SUCCESS(Status) && (*NewSecurityDescriptor != NULL)) {
  735. RxFreePool(*NewSecurityDescriptor);
  736. *NewSecurityDescriptor = NULL;
  737. }
  738. return Status;
  739. }
  740. NTSTATUS
  741. MRxSmbAddExtraAcesToSelfRelativeSD(
  742. IN PSECURITY_DESCRIPTOR OriginalSecurityDescriptor,
  743. IN BOOLEAN InheritableAces,
  744. OUT PSECURITY_DESCRIPTOR * NewSecurityDescriptor
  745. )
  746. /*++
  747. Routine Description:
  748. This routine takes an existing self-relative security descriptor
  749. and produces a new self-relative security descriptor with our
  750. extra ACEs added.
  751. Arguments:
  752. Return Value:
  753. Status - Result of the operation.
  754. --*/
  755. {
  756. NTSTATUS Status;
  757. PSECURITY_DESCRIPTOR AbsoluteSd = NULL;
  758. PSID Owner;
  759. PSID Group;
  760. PACL Dacl;
  761. PACL Sacl;
  762. PUCHAR NewAceList = NULL;
  763. PACL NewDacl = NULL;
  764. ULONG NewAceListSize;
  765. ULONG NewDaclSize;
  766. PACCESS_ALLOWED_ACE CurrentAce;
  767. ULONG i;
  768. *NewSecurityDescriptor = NULL;
  769. //
  770. // Allocate and convert the SD to absolute.
  771. //
  772. Status = MRxSmbSelfRelativeToAbsoluteSD(
  773. OriginalSecurityDescriptor,
  774. &AbsoluteSd,
  775. &Dacl,
  776. &Sacl,
  777. &Owner,
  778. &Group);
  779. //
  780. // If the SD is already absolute this call will have returned
  781. // STATUS_BAD_DESCRIPTOR_FORMAT -- we don't expect that.
  782. //
  783. if (!NT_SUCCESS(Status)) {
  784. goto CLEANUP;
  785. }
  786. //
  787. // The server requires that the SD we pass to it has an owner -- so
  788. // set one if there isn't one.
  789. //
  790. if (Owner == NULL) {
  791. Status = RtlSetOwnerSecurityDescriptor(
  792. AbsoluteSd,
  793. MRxSmbRemoteBootMachineSid,
  794. FALSE);
  795. if (!NT_SUCCESS(Status)) {
  796. goto CLEANUP;
  797. }
  798. }
  799. //
  800. // AbsoluteSd is now an absolute version of the passed-in
  801. // security descriptor. We replace the DACL with our
  802. // modified one.
  803. //
  804. //
  805. // First create the ACEs we want to add to the ACL.
  806. //
  807. NewAceListSize = 0;
  808. for (i = 0; i < ExtraAceInfoCount; i++) {
  809. NewAceListSize += ExtraAceInfo[i].AceSize;
  810. }
  811. NewAceList = RxAllocatePoolWithTag(PagedPool, NewAceListSize, MRXSMB_REMOTEBOOT_POOLTAG);
  812. if (NewAceList == NULL) {
  813. Status = STATUS_INSUFFICIENT_RESOURCES;
  814. goto CLEANUP;
  815. }
  816. CurrentAce = (PACCESS_ALLOWED_ACE)NewAceList;
  817. for (i = 0; i < ExtraAceInfoCount; i++) {
  818. CurrentAce->Header.AceType = ExtraAceInfo[i].AceType;
  819. CurrentAce->Header.AceFlags = ExtraAceInfo[i].AceFlags;
  820. if (InheritableAces) {
  821. CurrentAce->Header.AceFlags |= (OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE);
  822. }
  823. CurrentAce->Header.AceSize = ExtraAceInfo[i].AceSize;
  824. CurrentAce->Mask = ExtraAceInfo[i].Mask;
  825. RtlCopyMemory(&CurrentAce->SidStart,
  826. ExtraAceInfo[i].Sid,
  827. ExtraAceInfo[i].AceSize - FIELD_OFFSET(ACCESS_ALLOWED_ACE, SidStart));
  828. CurrentAce = (PACCESS_ALLOWED_ACE)(((PUCHAR)CurrentAce) + ExtraAceInfo[i].AceSize);
  829. }
  830. //
  831. // Allocate the new DACL.
  832. //
  833. if (Dacl != NULL) {
  834. NewDaclSize = Dacl->AclSize + NewAceListSize;
  835. } else {
  836. NewDaclSize = sizeof(ACL) + NewAceListSize;
  837. }
  838. NewDacl = RxAllocatePoolWithTag(NonPagedPool, NewDaclSize, MRXSMB_REMOTEBOOT_POOLTAG);
  839. if (NewDacl == NULL) {
  840. Status = STATUS_INSUFFICIENT_RESOURCES;
  841. goto CLEANUP;
  842. }
  843. if (Dacl != NULL) {
  844. RtlCopyMemory(NewDacl, Dacl, Dacl->AclSize);
  845. NewDacl->AclSize = (USHORT)NewDaclSize;
  846. } else {
  847. Status = RtlCreateAcl(NewDacl, NewDaclSize, ACL_REVISION);
  848. if (!NT_SUCCESS(Status)) {
  849. goto CLEANUP;
  850. }
  851. }
  852. //
  853. // Put our ACEs in the front.
  854. //
  855. Status = RtlAddAce(
  856. NewDacl,
  857. ACL_REVISION,
  858. 0, // StartingAceIndex
  859. NewAceList,
  860. NewAceListSize);
  861. if (!NT_SUCCESS(Status)) {
  862. goto CLEANUP;
  863. }
  864. //
  865. // Replace the existing DACL with ours.
  866. //
  867. Status = RtlSetDaclSecurityDescriptor(
  868. AbsoluteSd,
  869. TRUE,
  870. NewDacl,
  871. FALSE);
  872. if (!NT_SUCCESS(Status)) {
  873. goto CLEANUP;
  874. }
  875. //
  876. // Allocate and convert back to self-relative.
  877. //
  878. Status = MRxSmbAbsoluteToSelfRelativeSD(
  879. AbsoluteSd,
  880. NewSecurityDescriptor);
  881. if (!NT_SUCCESS(Status)) {
  882. goto CLEANUP;
  883. }
  884. CLEANUP:
  885. //
  886. // Free the temporary things we allocated.
  887. //
  888. if (AbsoluteSd != NULL) {
  889. RxFreePool(AbsoluteSd);
  890. }
  891. if (NewAceList != NULL) {
  892. RxFreePool(NewAceList);
  893. }
  894. if (NewDacl != NULL) {
  895. RxFreePool(NewDacl);
  896. }
  897. if (!NT_SUCCESS(Status) && (*NewSecurityDescriptor != NULL)) {
  898. RxFreePool(*NewSecurityDescriptor);
  899. *NewSecurityDescriptor = NULL;
  900. }
  901. return Status;
  902. }
  903. NTSTATUS
  904. MRxSmbCreateExtraAcesSelfRelativeSD(
  905. IN BOOLEAN InheritableAces,
  906. OUT PSECURITY_DESCRIPTOR * NewSecurityDescriptor
  907. )
  908. /*++
  909. Routine Description:
  910. This routine takes an existing self-relative security descriptor
  911. and produces a new self-relative security descriptor with our
  912. extra ACEs added.
  913. Arguments:
  914. Return Value:
  915. Status - Result of the operation.
  916. --*/
  917. {
  918. NTSTATUS Status;
  919. PSECURITY_DESCRIPTOR AbsoluteSd = NULL;
  920. PUCHAR NewAceList = NULL;
  921. PACL NewDacl = NULL;
  922. ULONG NewAceListSize;
  923. ULONG NewDaclSize;
  924. PACCESS_ALLOWED_ACE CurrentAce;
  925. ULONG i;
  926. AbsoluteSd = RxAllocatePoolWithTag(PagedPool, SECURITY_DESCRIPTOR_MIN_LENGTH, MRXSMB_REMOTEBOOT_POOLTAG);
  927. if (AbsoluteSd == NULL) {
  928. Status = STATUS_INSUFFICIENT_RESOURCES;
  929. goto CLEANUP;
  930. }
  931. Status = RtlCreateSecurityDescriptor(
  932. AbsoluteSd,
  933. SECURITY_DESCRIPTOR_REVISION);
  934. if (!NT_SUCCESS(Status)) {
  935. goto CLEANUP;
  936. }
  937. //
  938. // First create the ACEs we want to add to the ACL.
  939. //
  940. NewAceListSize = 0;
  941. for (i = 0; i < ExtraAceInfoCount; i++) {
  942. NewAceListSize += ExtraAceInfo[i].AceSize;
  943. }
  944. NewAceList = RxAllocatePoolWithTag(PagedPool, NewAceListSize, MRXSMB_REMOTEBOOT_POOLTAG);
  945. if (NewAceList == NULL) {
  946. Status = STATUS_INSUFFICIENT_RESOURCES;
  947. goto CLEANUP;
  948. }
  949. CurrentAce = (PACCESS_ALLOWED_ACE)NewAceList;
  950. for (i = 0; i < ExtraAceInfoCount; i++) {
  951. CurrentAce->Header.AceType = ExtraAceInfo[i].AceType;
  952. CurrentAce->Header.AceFlags = ExtraAceInfo[i].AceFlags;
  953. if (InheritableAces) {
  954. CurrentAce->Header.AceFlags |= (OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE);
  955. }
  956. CurrentAce->Header.AceSize = ExtraAceInfo[i].AceSize;
  957. CurrentAce->Mask = ExtraAceInfo[i].Mask;
  958. RtlCopyMemory(&CurrentAce->SidStart,
  959. ExtraAceInfo[i].Sid,
  960. ExtraAceInfo[i].AceSize - FIELD_OFFSET(ACCESS_ALLOWED_ACE, SidStart));
  961. CurrentAce = (PACCESS_ALLOWED_ACE)(((PUCHAR)CurrentAce) + ExtraAceInfo[i].AceSize);
  962. }
  963. //
  964. // Allocate the new DACL.
  965. //
  966. NewDaclSize = sizeof(ACL) + NewAceListSize;
  967. NewDacl = RxAllocatePoolWithTag(NonPagedPool, NewDaclSize, MRXSMB_REMOTEBOOT_POOLTAG);
  968. if (NewDacl == NULL) {
  969. Status = STATUS_INSUFFICIENT_RESOURCES;
  970. goto CLEANUP;
  971. }
  972. RtlCreateAcl(NewDacl, NewDaclSize, ACL_REVISION);
  973. //
  974. // Put our ACEs in the front.
  975. //
  976. Status = RtlAddAce(
  977. NewDacl,
  978. ACL_REVISION,
  979. 0, // StartingAceIndex
  980. NewAceList,
  981. NewAceListSize);
  982. if (!NT_SUCCESS(Status)) {
  983. goto CLEANUP;
  984. }
  985. //
  986. // Set the DACL on the SD.
  987. //
  988. Status = RtlSetDaclSecurityDescriptor(
  989. AbsoluteSd,
  990. TRUE,
  991. NewDacl,
  992. FALSE);
  993. if (!NT_SUCCESS(Status)) {
  994. goto CLEANUP;
  995. }
  996. //
  997. // Set the owner on the SD.
  998. //
  999. Status = RtlSetOwnerSecurityDescriptor(
  1000. AbsoluteSd,
  1001. MRxSmbRemoteBootMachineSid,
  1002. FALSE);
  1003. if (!NT_SUCCESS(Status)) {
  1004. goto CLEANUP;
  1005. }
  1006. //
  1007. // Allocate and convert back to self-relative.
  1008. //
  1009. Status = MRxSmbAbsoluteToSelfRelativeSD(
  1010. AbsoluteSd,
  1011. NewSecurityDescriptor);
  1012. if (!NT_SUCCESS(Status)) {
  1013. goto CLEANUP;
  1014. }
  1015. CLEANUP:
  1016. if (AbsoluteSd != NULL) {
  1017. RxFreePool(AbsoluteSd);
  1018. }
  1019. if (NewAceList != NULL) {
  1020. RxFreePool(NewAceList);
  1021. }
  1022. if (NewDacl != NULL) {
  1023. RxFreePool(NewDacl);
  1024. }
  1025. if (!NT_SUCCESS(Status) && (*NewSecurityDescriptor != NULL)) {
  1026. RxFreePool(*NewSecurityDescriptor);
  1027. *NewSecurityDescriptor = NULL;
  1028. }
  1029. return Status;
  1030. }
  1031. #endif // defined(REMOTE_BOOT)
  1032. NTSTATUS
  1033. MRxSmbQuerySecurityInformation (
  1034. IN OUT PRX_CONTEXT RxContext
  1035. )
  1036. /*++
  1037. Routine Description:
  1038. This routine implements the NtQuerySecurityFile api.
  1039. Arguments:
  1040. Return Value:
  1041. Status - Result of the operation.
  1042. --*/
  1043. {
  1044. RxCaptureFcb;
  1045. RxCaptureFobx;
  1046. PVOID Buffer = RxContext->Info.Buffer;
  1047. PLONG pLengthRemaining = &RxContext->Info.LengthRemaining;
  1048. PMRX_SMB_SRV_OPEN smbSrvOpen;
  1049. PSMBCEDB_SERVER_ENTRY pServerEntry;
  1050. #if defined(REMOTE_BOOT)
  1051. PSECURITY_DESCRIPTOR SelfRelativeSd;
  1052. BOOLEAN ConvertedAcl = FALSE;
  1053. #endif // defined(REMOTE_BOOT)
  1054. NTSTATUS Status;
  1055. REQ_QUERY_SECURITY_DESCRIPTOR QuerySecurityRequest;
  1056. RESP_QUERY_SECURITY_DESCRIPTOR QuerySecurityResponse;
  1057. PBYTE pInputParamBuffer = NULL;
  1058. PBYTE pOutputParamBuffer = NULL;
  1059. PBYTE pInputDataBuffer = NULL;
  1060. PBYTE pOutputDataBuffer = NULL;
  1061. ULONG InputParamBufferLength = 0;
  1062. ULONG OutputParamBufferLength = 0;
  1063. ULONG InputDataBufferLength = 0;
  1064. ULONG OutputDataBufferLength = 0;
  1065. PAGED_CODE();
  1066. RxDbgTrace(+1, Dbg, ("MRxSmbQuerySecurityInformation...\n"));
  1067. // Turn away this call from those servers which do not support the NT SMBs
  1068. pServerEntry = SmbCeGetAssociatedServerEntry(capFcb->pNetRoot->pSrvCall);
  1069. if (!FlagOn(pServerEntry->Server.DialectFlags,DF_NT_SMBS)) {
  1070. RxDbgTrace(-1, Dbg, ("QuerySecurityDescriptor not supported!\n"));
  1071. return((STATUS_NOT_SUPPORTED));
  1072. }
  1073. if (MRxSmbIsThisADisconnectedOpen(capFobx->pSrvOpen)) {
  1074. return STATUS_ONLY_IF_CONNECTED;
  1075. }
  1076. Status = MRxSmbDeferredCreate(RxContext);
  1077. if (Status!=STATUS_SUCCESS) {
  1078. goto FINALLY;
  1079. }
  1080. Status = STATUS_MORE_PROCESSING_REQUIRED;
  1081. smbSrvOpen = MRxSmbGetSrvOpenExtension(capFobx->pSrvOpen);
  1082. if (Status == STATUS_MORE_PROCESSING_REQUIRED) {
  1083. SMB_TRANSACTION_OPTIONS TransactionOptions = RxDefaultTransactionOptions;
  1084. SMB_TRANSACTION_RESUMPTION_CONTEXT ResumptionContext;
  1085. //BOOLEAN printflag;
  1086. TransactionOptions.NtTransactFunction = NT_TRANSACT_QUERY_SECURITY_DESC;
  1087. //TransactionOptions.Flags |= SMB_XACT_FLAGS_COPY_ON_ERROR;
  1088. QuerySecurityRequest.Fid = smbSrvOpen->Fid;
  1089. QuerySecurityRequest.Reserved = 0;
  1090. QuerySecurityRequest.SecurityInformation = RxContext->QuerySecurity.SecurityInformation;
  1091. QuerySecurityResponse.LengthNeeded = 0xbaadbaad;
  1092. //printflag = RxDbgTraceDisableGlobally();//this is debug code anyway!
  1093. //RxDbgTraceEnableGlobally(FALSE);
  1094. Status = SmbCeTransact(
  1095. RxContext, // the RXContext for the transaction
  1096. &TransactionOptions, // transaction options
  1097. NULL, // the setup buffer
  1098. 0, // input setup buffer length
  1099. NULL, // output setup buffer
  1100. 0, // output setup buffer length
  1101. &QuerySecurityRequest, // Input Param Buffer
  1102. sizeof(QuerySecurityRequest), // Input param buffer length
  1103. &QuerySecurityResponse, // Output param buffer
  1104. sizeof(QuerySecurityResponse),// output param buffer length
  1105. NULL, // Input data buffer
  1106. 0, // Input data buffer length
  1107. Buffer, // output data buffer
  1108. *pLengthRemaining, // output data buffer length
  1109. &ResumptionContext // the resumption context
  1110. );
  1111. //DbgPrint("QSR.len=%x\n", QuerySecurityResponse.LengthNeeded);
  1112. if (NT_SUCCESS(Status) || (Status == STATUS_BUFFER_TOO_SMALL)) {
  1113. ULONG ReturnedDataCount = ResumptionContext.DataBytesReceived;
  1114. RxContext->InformationToReturn = QuerySecurityResponse.LengthNeeded;
  1115. RxDbgTrace(0, Dbg, ("MRxSmbQuerySecurityInformation...ReturnedDataCount=%08lx\n",ReturnedDataCount));
  1116. ASSERT(ResumptionContext.ParameterBytesReceived == sizeof(RESP_QUERY_SECURITY_DESCRIPTOR));
  1117. if (((LONG)(QuerySecurityResponse.LengthNeeded)) > *pLengthRemaining) {
  1118. Status = STATUS_BUFFER_OVERFLOW;
  1119. }
  1120. #if defined(REMOTE_BOOT)
  1121. if (MRxSmbBootedRemotely &&
  1122. MRxSmbRemoteBootDoMachineLogon) {
  1123. PSMBCE_SESSION pSession;
  1124. pSession = &SmbCeGetAssociatedVNetRootContext(
  1125. capFobx->pSrvOpen->pVNetRoot)->pSessionEntry->Session;
  1126. if (FlagOn(pSession->Flags,SMBCE_SESSION_FLAGS_REMOTE_BOOT_SESSION)) {
  1127. //
  1128. // if the user supplied a zero-length buffer, I.e. they were querying
  1129. // to see how big a buffer was needed, they will wind up with less
  1130. // data than expected because on the subsequent call with a real buffer,
  1131. // we may remove the extra ACEs.
  1132. //
  1133. if (NT_SUCCESS(Status) && (Buffer != NULL) && (ReturnedDataCount > 0)) {
  1134. BOOLEAN DaclPresent, DaclDefaulted;
  1135. // DbgPrint( ">>> Querying SD on %wZ\n", &capFcb->AlreadyPrefixedName);
  1136. //
  1137. // Remove any any ACEs in the DACL
  1138. // that SetSecurityInformation may have added.
  1139. //
  1140. Status = MRxSmbRemoveExtraAcesFromSelfRelativeSD(
  1141. (PSECURITY_DESCRIPTOR)Buffer,
  1142. &SelfRelativeSd,
  1143. &ConvertedAcl);
  1144. if (!NT_SUCCESS(Status)) {
  1145. goto FINALLY;
  1146. }
  1147. if (ConvertedAcl) {
  1148. //
  1149. // Copy the new security descriptor and
  1150. // modify the data length.
  1151. //
  1152. RtlCopyMemory(
  1153. Buffer,
  1154. SelfRelativeSd,
  1155. RtlLengthSecurityDescriptor(SelfRelativeSd));
  1156. }
  1157. }
  1158. }
  1159. }
  1160. #endif // defined(REMOTE_BOOT)
  1161. }
  1162. //RxDbgTraceEnableGlobally(printflag);
  1163. }
  1164. FINALLY:
  1165. #if defined(REMOTE_BOOT)
  1166. //
  1167. // If we modified the security descriptor for a remote boot server,
  1168. // clean it up.
  1169. //
  1170. if (ConvertedAcl) {
  1171. //
  1172. // Free the self-relative SD that was allocated.
  1173. //
  1174. if (SelfRelativeSd != NULL) {
  1175. RxFreePool(SelfRelativeSd);
  1176. }
  1177. }
  1178. #endif // defined(REMOTE_BOOT)
  1179. RxDbgTrace(-1, Dbg, ("MRxSmbQuerySecurityInformation...exit, st=%08lx,info=%08lx\n",
  1180. Status, RxContext->InformationToReturn));
  1181. return Status;
  1182. }
  1183. NTSTATUS
  1184. MRxSmbSetSecurityInformation (
  1185. IN OUT struct _RX_CONTEXT * RxContext
  1186. )
  1187. {
  1188. RxCaptureFcb;
  1189. RxCaptureFobx;
  1190. PMRX_SMB_SRV_OPEN smbSrvOpen;
  1191. PSMBCEDB_SERVER_ENTRY pServerEntry;
  1192. NTSTATUS Status;
  1193. REQ_SET_SECURITY_DESCRIPTOR SetSecurityRequest;
  1194. #if defined(REMOTE_BOOT)
  1195. PSECURITY_DESCRIPTOR OriginalSd;
  1196. PSECURITY_DESCRIPTOR SelfRelativeSd;
  1197. BOOLEAN DidRemoteBootProcessing = FALSE;
  1198. #endif // defined(REMOTE_BOOT)
  1199. PAGED_CODE();
  1200. RxDbgTrace(+1, Dbg, ("MRxSmbSetSecurityInformation...\n"));
  1201. pServerEntry = SmbCeGetAssociatedServerEntry(capFcb->pNetRoot->pSrvCall);
  1202. if (!FlagOn(pServerEntry->Server.DialectFlags,DF_NT_SMBS)) {
  1203. RxDbgTrace(-1, Dbg, ("Set Security Descriptor not supported!\n"));
  1204. return((STATUS_NOT_SUPPORTED));
  1205. } else if (MRxSmbIsThisADisconnectedOpen(capFobx->pSrvOpen)) {
  1206. return STATUS_ONLY_IF_CONNECTED;
  1207. #if defined(REMOTE_BOOT)
  1208. } else if (MRxSmbBootedRemotely) {
  1209. PSMBCE_SESSION pSession;
  1210. pSession = &SmbCeGetAssociatedVNetRootContext(
  1211. capFobx->pSrvOpen->pVNetRoot)->pSessionEntry->Session;
  1212. if (FlagOn(pSession->Flags,SMBCE_SESSION_FLAGS_REMOTE_BOOT_SESSION)) {
  1213. TYPE_OF_OPEN TypeOfOpen = NodeType(capFcb);
  1214. //
  1215. // Set this so we know to call the CSC epilogue, and can clean
  1216. // up correctly.
  1217. //
  1218. DidRemoteBootProcessing = TRUE;
  1219. SelfRelativeSd = NULL;
  1220. // DbgPrint( ">>> setting SD on %wZ\n", &capFcb->AlreadyPrefixedName);
  1221. //
  1222. // First we need to set the security descriptor on the CSC
  1223. // version of the file, if one exists.
  1224. //
  1225. Status = MRxSmbCscSetSecurityPrologue(RxContext);
  1226. if (Status != STATUS_SUCCESS) {
  1227. goto FINALLY;
  1228. }
  1229. if (MRxSmbRemoteBootDoMachineLogon) {
  1230. //
  1231. // Add our ACEs to the security descriptor. This returns the
  1232. // new security descriptor in SelfRelativeSd. If this is a
  1233. // directory we add inheritable ACEs.
  1234. //
  1235. Status = MRxSmbAddExtraAcesToSelfRelativeSD(
  1236. RxContext->SetSecurity.SecurityDescriptor,
  1237. (BOOLEAN)(TypeOfOpen == RDBSS_NTC_STORAGE_TYPE_DIRECTORY),
  1238. &SelfRelativeSd);
  1239. if (!NT_SUCCESS(Status)) {
  1240. goto FINALLY;
  1241. }
  1242. //
  1243. // Now replace the original SD with the new one.
  1244. //
  1245. OriginalSd = RxContext->SetSecurity.SecurityDescriptor;
  1246. RxContext->SetSecurity.SecurityDescriptor = SelfRelativeSd;
  1247. } else {
  1248. //
  1249. // If we logged on using the NULL session, then don't set ACLs
  1250. // on the server file. Jump to the end so that the CSC epilogue
  1251. // is called.
  1252. //
  1253. Status = STATUS_SUCCESS;
  1254. goto FINALLY;
  1255. }
  1256. }
  1257. #endif // defined(REMOTE_BOOT)
  1258. }
  1259. Status = MRxSmbDeferredCreate(RxContext);
  1260. if (Status!=STATUS_SUCCESS) {
  1261. goto FINALLY;
  1262. }
  1263. Status = STATUS_MORE_PROCESSING_REQUIRED;
  1264. smbSrvOpen = MRxSmbGetSrvOpenExtension(capFobx->pSrvOpen);
  1265. if (Status == STATUS_MORE_PROCESSING_REQUIRED) {
  1266. SMB_TRANSACTION_OPTIONS TransactionOptions = RxDefaultTransactionOptions;
  1267. SMB_TRANSACTION_RESUMPTION_CONTEXT ResumptionContext;
  1268. ULONG SdLength = RtlLengthSecurityDescriptor(RxContext->SetSecurity.SecurityDescriptor);
  1269. TransactionOptions.NtTransactFunction = NT_TRANSACT_SET_SECURITY_DESC;
  1270. SetSecurityRequest.Fid = smbSrvOpen->Fid;
  1271. SetSecurityRequest.Reserved = 0;
  1272. SetSecurityRequest.SecurityInformation = RxContext->SetSecurity.SecurityInformation;
  1273. Status = SmbCeTransact(
  1274. RxContext, // the RXContext for the transaction
  1275. &TransactionOptions, // transaction options
  1276. NULL, // the input setup buffer
  1277. 0, // input setup buffer length
  1278. NULL, // the output setup buffer
  1279. 0, // output setup buffer length
  1280. &SetSecurityRequest, // Input Param Buffer
  1281. sizeof(SetSecurityRequest), // Input param buffer length
  1282. NULL, // Output param buffer
  1283. 0, // output param buffer length
  1284. RxContext->SetSecurity.SecurityDescriptor, // Input data buffer
  1285. SdLength, // Input data buffer length
  1286. NULL, // output data buffer
  1287. 0, // output data buffer length
  1288. &ResumptionContext // the resumption context
  1289. );
  1290. //the old rdr doesn't return any info...................
  1291. //RxContext->InformationToReturn = SetSecurityResponse.LengthNeeded;
  1292. if ( NT_SUCCESS(Status) ) {
  1293. ULONG ReturnedDataCount = ResumptionContext.DataBytesReceived;
  1294. RxDbgTrace(0, Dbg, ("MRxSmbSetSecurityInformation...ReturnedDataCount=%08lx\n",ReturnedDataCount));
  1295. ASSERT(ResumptionContext.ParameterBytesReceived == 0);
  1296. ASSERT(ResumptionContext.SetupBytesReceived == 0);
  1297. ASSERT(ResumptionContext.DataBytesReceived == 0);
  1298. }
  1299. }
  1300. FINALLY:
  1301. #if defined(REMOTE_BOOT)
  1302. //
  1303. // If we modified the security descriptor for a remote boot server,
  1304. // clean it up.
  1305. //
  1306. if (DidRemoteBootProcessing) {
  1307. if (SelfRelativeSd != NULL) {
  1308. RxFreePool(SelfRelativeSd);
  1309. //
  1310. // If we successfully allocated SelfRelativeSd then we
  1311. // also replaced the original passed-in SD, so we need
  1312. // to put the old SD back.
  1313. //
  1314. RxContext->SetSecurity.SecurityDescriptor = OriginalSd;
  1315. }
  1316. MRxSmbCscSetSecurityEpilogue(RxContext, &Status);
  1317. }
  1318. #endif // defined(REMOTE_BOOT)
  1319. RxDbgTrace(-1, Dbg, ("MRxSmbSetSecurityInformation...exit, st=%08lx,info=%08lx\n",
  1320. Status, RxContext->InformationToReturn));
  1321. return Status;
  1322. }
  1323. NTSTATUS
  1324. MRxSmbLoadEaList(
  1325. IN PRX_CONTEXT RxContext,
  1326. IN PUCHAR UserEaList,
  1327. IN ULONG UserEaListLength,
  1328. OUT PFEALIST *ServerEaList
  1329. )
  1330. /*++
  1331. Routine Description:
  1332. This routine implements the NtQueryEaFile api.
  1333. It returns the following information:
  1334. Arguments:
  1335. IN PUCHAR UserEaList; - Supplies the Ea names required.
  1336. IN ULONG UserEaListLength;
  1337. OUT PFEALIST *ServerEaList - Eas returned by the server. Caller is responsible for
  1338. freeing memory.
  1339. Return Value:
  1340. Status - Result of the operation.
  1341. --*/
  1342. {
  1343. RxCaptureFobx;
  1344. PMRX_SMB_SRV_OPEN smbSrvOpen;
  1345. NTSTATUS Status;
  1346. USHORT Setup = TRANS2_QUERY_FILE_INFORMATION;
  1347. REQ_QUERY_FILE_INFORMATION QueryFileInfoRequest;
  1348. RESP_QUERY_FILE_INFORMATION QueryFileInfoResponse;
  1349. PBYTE pInputParamBuffer = NULL;
  1350. PBYTE pOutputParamBuffer = NULL;
  1351. PBYTE pInputDataBuffer = NULL;
  1352. PBYTE pOutputDataBuffer = NULL;
  1353. ULONG InputParamBufferLength = 0;
  1354. ULONG OutputParamBufferLength = 0;
  1355. ULONG InputDataBufferLength = 0;
  1356. ULONG OutputDataBufferLength = 0;
  1357. CLONG OutDataCount = EA_QUERY_SIZE;
  1358. CLONG OutSetupCount = 0;
  1359. PFEALIST Buffer;
  1360. PGEALIST ServerQueryEaList = NULL;
  1361. CLONG InDataCount;
  1362. PAGED_CODE();
  1363. RxDbgTrace(+1, Dbg, ("MRxSmbLoadEaList...\n"));
  1364. Status = STATUS_MORE_PROCESSING_REQUIRED;
  1365. smbSrvOpen = MRxSmbGetSrvOpenExtension(capFobx->pSrvOpen);
  1366. //
  1367. // Convert the supplied UserEaList to a GEALIST. The server will return just the Eas
  1368. // requested by the application.
  1369. //
  1370. //
  1371. // If the application specified a subset of EaNames then convert to OS/2 1.2 format and
  1372. // pass that to the server. ie. Use the server to filter out the names.
  1373. //
  1374. //CODE.IMPROVEMENT if write-cacheing is enabled, then we could find out the size once and save it. in
  1375. // this way we would at least avoid this everytime. the best way would be an NT-->NT api that
  1376. // implements this in a reasonable fashion. (we can only do the above optimization if it's a full
  1377. // query instead of a ealist!=NULL query.
  1378. Buffer = RxAllocatePool ( PagedPool, OutDataCount );
  1379. if ( Buffer == NULL ) {
  1380. Status = STATUS_INSUFFICIENT_RESOURCES;
  1381. goto FINALLY;
  1382. }
  1383. if ( UserEaList != NULL) {
  1384. //
  1385. // OS/2 format is always a little less than or equal to the NT UserEaList size.
  1386. // This code relies on the I/O system verifying the EaList is valid.
  1387. //
  1388. ServerQueryEaList = RxAllocatePool ( PagedPool, UserEaListLength );
  1389. if ( ServerQueryEaList == NULL ) {
  1390. Status = STATUS_INSUFFICIENT_RESOURCES;
  1391. goto FINALLY;
  1392. };
  1393. MRxSmbNtGeaListToOs2((PFILE_GET_EA_INFORMATION )UserEaList, UserEaListLength, ServerQueryEaList );
  1394. InDataCount = (CLONG)ServerQueryEaList->cbList;
  1395. } else {
  1396. InDataCount = 0;
  1397. }
  1398. if (Status == STATUS_MORE_PROCESSING_REQUIRED) {
  1399. PSMB_TRANSACTION_OPTIONS pTransactionOptions = &RxDefaultTransactionOptions;
  1400. SMB_TRANSACTION_RESUMPTION_CONTEXT ResumptionContext;
  1401. QueryFileInfoRequest.Fid = smbSrvOpen->Fid;
  1402. if ( UserEaList != NULL) {
  1403. QueryFileInfoRequest.InformationLevel = SMB_INFO_QUERY_EAS_FROM_LIST;
  1404. } else {
  1405. QueryFileInfoRequest.InformationLevel = SMB_INFO_QUERY_ALL_EAS;
  1406. }
  1407. // CODE.IMPROVEMENT it is unfortunate that this is defined so that a paramMDL cannot be passed
  1408. // perhaps it should be passed in the options!
  1409. Status = SmbCeTransact(
  1410. RxContext, // the RXContext for the transaction
  1411. pTransactionOptions, // transaction options
  1412. &Setup, // the setup buffer
  1413. sizeof(Setup), // setup buffer length
  1414. NULL, // the output setup buffer
  1415. 0, // output setup buffer length
  1416. &QueryFileInfoRequest, // Input Param Buffer
  1417. sizeof(QueryFileInfoRequest), // Input param buffer length
  1418. &QueryFileInfoResponse, // Output param buffer
  1419. sizeof(QueryFileInfoResponse),// output param buffer length
  1420. ServerQueryEaList, // Input data buffer
  1421. InDataCount, // Input data buffer length
  1422. Buffer, // output data buffer
  1423. OutDataCount, // output data buffer length
  1424. &ResumptionContext // the resumption context
  1425. );
  1426. if ( NT_SUCCESS(Status) ) {
  1427. ULONG ReturnedDataCount = ResumptionContext.DataBytesReceived;
  1428. RxDbgTrace(0, Dbg, ("MRxSmbLoadEaList...ReturnedDataCount=%08lx\n",ReturnedDataCount));
  1429. ASSERT(ResumptionContext.ParameterBytesReceived == sizeof(RESP_QUERY_FILE_INFORMATION));
  1430. if ( SmbGetUlong( &((PFEALIST)Buffer)->cbList) != ReturnedDataCount ){
  1431. Status = STATUS_EA_CORRUPT_ERROR;
  1432. }
  1433. if ( ReturnedDataCount == 0 ) {
  1434. Status = STATUS_NO_EAS_ON_FILE;
  1435. }
  1436. }
  1437. }
  1438. FINALLY:
  1439. if ( NT_SUCCESS(Status) ) {
  1440. *ServerEaList = Buffer;
  1441. } else {
  1442. if (Buffer != NULL) {
  1443. RxFreePool(Buffer);
  1444. }
  1445. }
  1446. if ( ServerQueryEaList != NULL) {
  1447. RxFreePool(ServerQueryEaList);
  1448. }
  1449. RxDbgTrace(-1, Dbg, ("MRxSmbLoadEaList...exit, st=%08lx\n",Status));
  1450. return Status;
  1451. }
  1452. VOID
  1453. MRxSmbNtGeaListToOs2 (
  1454. IN PFILE_GET_EA_INFORMATION NtGetEaList,
  1455. IN ULONG GeaListLength,
  1456. IN PGEALIST GeaList
  1457. )
  1458. /*++
  1459. Routine Description:
  1460. Converts a single NT GET EA list to OS/2 GEALIST style. The GEALIST
  1461. need not have any particular alignment.
  1462. Arguments:
  1463. NtGetEaList - An NT style get EA list to be converted to OS/2 format.
  1464. GeaListLength - the maximum possible length of the GeaList.
  1465. GeaList - Where to place the OS/2 1.2 style GEALIST.
  1466. Return Value:
  1467. none.
  1468. --*/
  1469. {
  1470. PGEA gea = GeaList->list;
  1471. PFILE_GET_EA_INFORMATION ntGetEa = NtGetEaList;
  1472. PAGED_CODE();
  1473. //
  1474. // Copy the Eas up until the last one
  1475. //
  1476. while ( ntGetEa->NextEntryOffset != 0 ) {
  1477. //
  1478. // Copy the NT format EA to OS/2 1.2 format and set the gea
  1479. // pointer for the next iteration.
  1480. //
  1481. gea = MRxSmbNtGetEaToOs2( gea, ntGetEa );
  1482. ASSERT( (ULONG_PTR)gea <= (ULONG_PTR)GeaList + GeaListLength );
  1483. ntGetEa = (PFILE_GET_EA_INFORMATION)((PCHAR)ntGetEa + ntGetEa->NextEntryOffset);
  1484. }
  1485. // Now copy the last entry.
  1486. gea = MRxSmbNtGetEaToOs2( gea, ntGetEa );
  1487. ASSERT( (ULONG_PTR)gea <= (ULONG_PTR)GeaList + GeaListLength );
  1488. //
  1489. // Set the number of bytes in the GEALIST.
  1490. //
  1491. SmbPutUlong(
  1492. &GeaList->cbList,
  1493. (ULONG)((PCHAR)gea - (PCHAR)GeaList)
  1494. );
  1495. UNREFERENCED_PARAMETER( GeaListLength );
  1496. }
  1497. PGEA
  1498. MRxSmbNtGetEaToOs2 (
  1499. OUT PGEA Gea,
  1500. IN PFILE_GET_EA_INFORMATION NtGetEa
  1501. )
  1502. /*++
  1503. Routine Description:
  1504. Converts a single NT Get EA entry to OS/2 GEA style. The GEA need not have
  1505. any particular alignment. This routine makes no checks on buffer
  1506. overrunning--this is the responsibility of the calling routine.
  1507. Arguments:
  1508. Gea - a pointer to the location where the OS/2 GEA is to be written.
  1509. NtGetEa - a pointer to the NT Get EA.
  1510. Return Value:
  1511. A pointer to the location after the last byte written.
  1512. --*/
  1513. {
  1514. PCHAR ptr;
  1515. PAGED_CODE();
  1516. Gea->cbName = NtGetEa->EaNameLength;
  1517. ptr = (PCHAR)(Gea) + 1;
  1518. RtlCopyMemory( ptr, NtGetEa->EaName, NtGetEa->EaNameLength );
  1519. ptr += NtGetEa->EaNameLength;
  1520. *ptr++ = '\0';
  1521. return ( (PGEA)ptr );
  1522. }
  1523. NTSTATUS
  1524. MRxSmbQueryEasFromServer(
  1525. IN PRX_CONTEXT RxContext,
  1526. IN PFEALIST ServerEaList,
  1527. IN PVOID Buffer,
  1528. IN OUT PULONG BufferLengthRemaining,
  1529. IN BOOLEAN ReturnSingleEntry,
  1530. IN BOOLEAN UserEaListSupplied
  1531. )
  1532. /*++
  1533. Routine Description:
  1534. This routine copies the required number of Eas from the ServerEaList
  1535. starting from the offset indicated in the Icb. The Icb is also updated
  1536. to show the last Ea returned.
  1537. Arguments:
  1538. IN PFEALIST ServerEaList - Supplies the Ea List in OS/2 format.
  1539. IN PVOID Buffer - Supplies where to put the NT format EAs
  1540. IN OUT PULONG BufferLengthRemaining - Supplies the user buffer space.
  1541. IN BOOLEAN ReturnSingleEntry
  1542. IN BOOLEAN UserEaListSupplied - ServerEaList is a subset of the Eas
  1543. Return Value:
  1544. NTSTATUS - The status for the Irp.
  1545. --*/
  1546. {
  1547. RxCaptureFobx;
  1548. ULONG EaIndex = capFobx->OffsetOfNextEaToReturn;
  1549. ULONG Index = 1;
  1550. ULONG Size;
  1551. ULONG OriginalLengthRemaining = *BufferLengthRemaining;
  1552. BOOLEAN Overflow = FALSE;
  1553. PFEA LastFeaStartLocation;
  1554. PFEA Fea = NULL;
  1555. PFEA LastFea = NULL;
  1556. PFILE_FULL_EA_INFORMATION NtFullEa = Buffer;
  1557. PFILE_FULL_EA_INFORMATION LastNtFullEa = Buffer;
  1558. PAGED_CODE();
  1559. RxDbgTrace(0, Dbg, ("MRxSmbQueryEasFromServer...EaIndex/Buffer/Remaining=%08lx/%08lx/%08lx\n",
  1560. EaIndex,Buffer,((BufferLengthRemaining)?*BufferLengthRemaining:0xbadbad)
  1561. ));
  1562. //
  1563. // If there are no Ea's present in the list, return the appropriate
  1564. // error.
  1565. //
  1566. // Os/2 servers indicate that a list is null if cbList==4.
  1567. //
  1568. if ( SmbGetUlong(&ServerEaList->cbList) == FIELD_OFFSET(FEALIST, list) ) {
  1569. return STATUS_NO_EAS_ON_FILE;
  1570. }
  1571. //
  1572. // Find the last location at which an FEA can start.
  1573. //
  1574. LastFeaStartLocation = (PFEA)( (PCHAR)ServerEaList +
  1575. SmbGetUlong( &ServerEaList->cbList ) -
  1576. sizeof(FEA) - 1 );
  1577. //
  1578. // Go through the ServerEaList until we find the entry corresponding to EaIndex
  1579. //
  1580. for ( Fea = ServerEaList->list;
  1581. (Fea <= LastFeaStartLocation) && (Index < EaIndex);
  1582. Index+= 1,
  1583. Fea = (PFEA)( (PCHAR)Fea + sizeof(FEA) +
  1584. Fea->cbName + 1 + SmbGetUshort( &Fea->cbValue ) ) ) {
  1585. NOTHING;
  1586. }
  1587. if ( Index != EaIndex ) {
  1588. if ( Index == EaIndex+1 ) {
  1589. return STATUS_NO_MORE_EAS;
  1590. }
  1591. //
  1592. // No such index
  1593. //
  1594. return STATUS_NONEXISTENT_EA_ENTRY;
  1595. }
  1596. //
  1597. // Go through the rest of the FEA list, converting from OS/2 1.2 format to NT
  1598. // until we pass the last possible location in which an FEA can start.
  1599. //
  1600. for ( ;
  1601. Fea <= LastFeaStartLocation;
  1602. Fea = (PFEA)( (PCHAR)Fea + sizeof(FEA) +
  1603. Fea->cbName + 1 + SmbGetUshort( &Fea->cbValue ) ) ) {
  1604. PCHAR ptr;
  1605. //
  1606. // Calculate the size of this Fea when converted to an NT EA structure.
  1607. //
  1608. // The last field shouldn't be padded.
  1609. //
  1610. if ((PFEA)((PCHAR)Fea+sizeof(FEA)+Fea->cbName+1+SmbGetUshort(&Fea->cbValue)) < LastFeaStartLocation) {
  1611. Size = SmbGetNtSizeOfFea( Fea );
  1612. } else {
  1613. Size = FIELD_OFFSET(FILE_FULL_EA_INFORMATION, EaName[0]) +
  1614. Fea->cbName + 1 + SmbGetUshort(&Fea->cbValue);
  1615. }
  1616. //
  1617. // Will the next Ea fit?
  1618. //
  1619. if ( *BufferLengthRemaining < Size ) {
  1620. if ( LastNtFullEa != NtFullEa ) {
  1621. if ( UserEaListSupplied == TRUE ) {
  1622. *BufferLengthRemaining = OriginalLengthRemaining;
  1623. return STATUS_BUFFER_OVERFLOW;
  1624. }
  1625. Overflow = TRUE;
  1626. break;
  1627. } else {
  1628. // Not even room for a single EA!
  1629. return STATUS_BUFFER_OVERFLOW;
  1630. }
  1631. } else {
  1632. *BufferLengthRemaining -= Size;
  1633. }
  1634. //
  1635. // We are comitted to copy the Os2 Fea to Nt format in the users buffer
  1636. //
  1637. LastNtFullEa = NtFullEa;
  1638. LastFea = Fea;
  1639. EaIndex++;
  1640. // Create new Nt Ea
  1641. NtFullEa->Flags = Fea->fEA;
  1642. NtFullEa->EaNameLength = Fea->cbName;
  1643. NtFullEa->EaValueLength = SmbGetUshort( &Fea->cbValue );
  1644. ptr = NtFullEa->EaName;
  1645. RtlCopyMemory( ptr, (PCHAR)(Fea+1), Fea->cbName );
  1646. ptr += NtFullEa->EaNameLength;
  1647. *ptr++ = '\0';
  1648. //
  1649. // Copy the EA value to the NT full EA.
  1650. //
  1651. RtlCopyMemory(
  1652. ptr,
  1653. (PCHAR)(Fea+1) + NtFullEa->EaNameLength + 1,
  1654. NtFullEa->EaValueLength
  1655. );
  1656. ptr += NtFullEa->EaValueLength;
  1657. //
  1658. // Longword-align ptr to determine the offset to the next location
  1659. // for an NT full EA.
  1660. //
  1661. ptr = (PCHAR)( ((ULONG_PTR)ptr + 3) & ~3 );
  1662. NtFullEa->NextEntryOffset = (ULONG)( ptr - (PCHAR)NtFullEa );
  1663. NtFullEa = (PFILE_FULL_EA_INFORMATION)ptr;
  1664. if ( ReturnSingleEntry == TRUE ) {
  1665. break;
  1666. }
  1667. }
  1668. //
  1669. // Set the NextEntryOffset field of the last full EA to 0 to indicate
  1670. // the end of the list.
  1671. //
  1672. LastNtFullEa->NextEntryOffset = 0;
  1673. //
  1674. // Record position the default start position for the next query
  1675. //
  1676. capFobx->OffsetOfNextEaToReturn = EaIndex;
  1677. if ( Overflow == FALSE ) {
  1678. return STATUS_SUCCESS;
  1679. } else {
  1680. return STATUS_BUFFER_OVERFLOW;
  1681. }
  1682. }
  1683. ULONG
  1684. MRxSmbNtFullEaSizeToOs2 (
  1685. IN PFILE_FULL_EA_INFORMATION NtFullEa
  1686. )
  1687. /*++
  1688. Routine Description:
  1689. Get the number of bytes that would be required to represent the
  1690. NT full EA list in OS/2 1.2 style. This routine assumes that
  1691. at least one EA is present in the buffer.
  1692. Arguments:
  1693. NtFullEa - a pointer to the list of NT EAs.
  1694. Return Value:
  1695. ULONG - number of bytes required to hold the EAs in OS/2 1.2 format.
  1696. --*/
  1697. {
  1698. ULONG size;
  1699. PAGED_CODE();
  1700. //
  1701. // Walk through the EAs, adding up the total size required to
  1702. // hold them in OS/2 format.
  1703. //
  1704. for ( size = FIELD_OFFSET(FEALIST, list[0]);
  1705. NtFullEa->NextEntryOffset != 0;
  1706. NtFullEa = (PFILE_FULL_EA_INFORMATION)(
  1707. (PCHAR)NtFullEa + NtFullEa->NextEntryOffset ) ) {
  1708. size += SmbGetOs2SizeOfNtFullEa( NtFullEa );
  1709. }
  1710. size += SmbGetOs2SizeOfNtFullEa( NtFullEa );
  1711. return size;
  1712. }
  1713. VOID
  1714. MRxSmbNtFullListToOs2 (
  1715. IN PFILE_FULL_EA_INFORMATION NtEaList,
  1716. IN PFEALIST FeaList
  1717. )
  1718. /*++
  1719. Routine Description:
  1720. Converts a single NT FULL EA list to OS/2 FEALIST style. The FEALIST
  1721. need not have any particular alignment.
  1722. It is the callers responsibility to ensure that FeaList is large enough.
  1723. Arguments:
  1724. NtEaList - An NT style get EA list to be converted to OS/2 format.
  1725. FeaList - Where to place the OS/2 1.2 style FEALIST.
  1726. Return Value:
  1727. none.
  1728. --*/
  1729. {
  1730. PFEA fea = FeaList->list;
  1731. PFILE_FULL_EA_INFORMATION ntFullEa = NtEaList;
  1732. PAGED_CODE();
  1733. //
  1734. // Copy the Eas up until the last one
  1735. //
  1736. while ( ntFullEa->NextEntryOffset != 0 ) {
  1737. //
  1738. // Copy the NT format EA to OS/2 1.2 format and set the fea
  1739. // pointer for the next iteration.
  1740. //
  1741. fea = MRxSmbNtFullEaToOs2( fea, ntFullEa );
  1742. ntFullEa = (PFILE_FULL_EA_INFORMATION)((PCHAR)ntFullEa + ntFullEa->NextEntryOffset);
  1743. }
  1744. // Now copy the last entry.
  1745. fea = MRxSmbNtFullEaToOs2( fea, ntFullEa );
  1746. //
  1747. // Set the number of bytes in the FEALIST.
  1748. //
  1749. SmbPutUlong(
  1750. &FeaList->cbList,
  1751. (ULONG)((PCHAR)fea - (PCHAR)FeaList)
  1752. );
  1753. }
  1754. PVOID
  1755. MRxSmbNtFullEaToOs2 (
  1756. OUT PFEA Fea,
  1757. IN PFILE_FULL_EA_INFORMATION NtFullEa
  1758. )
  1759. /*++
  1760. Routine Description:
  1761. Converts a single NT full EA to OS/2 FEA style. The FEA need not have
  1762. any particular alignment. This routine makes no checks on buffer
  1763. overrunning--this is the responsibility of the calling routine.
  1764. Arguments:
  1765. Fea - a pointer to the location where the OS/2 FEA is to be written.
  1766. NtFullEa - a pointer to the NT full EA.
  1767. Return Value:
  1768. A pointer to the location after the last byte written.
  1769. --*/
  1770. {
  1771. PCHAR ptr;
  1772. PAGED_CODE();
  1773. Fea->fEA = (UCHAR)NtFullEa->Flags;
  1774. Fea->cbName = NtFullEa->EaNameLength;
  1775. SmbPutUshort( &Fea->cbValue, NtFullEa->EaValueLength );
  1776. ptr = (PCHAR)(Fea + 1);
  1777. RtlCopyMemory( ptr, NtFullEa->EaName, NtFullEa->EaNameLength );
  1778. ptr += NtFullEa->EaNameLength;
  1779. *ptr++ = '\0';
  1780. RtlCopyMemory(
  1781. ptr,
  1782. NtFullEa->EaName + NtFullEa->EaNameLength + 1,
  1783. NtFullEa->EaValueLength
  1784. );
  1785. return (ptr + NtFullEa->EaValueLength);
  1786. }
  1787. NTSTATUS
  1788. MRxSmbSetEaList(
  1789. IN PRX_CONTEXT RxContext,
  1790. IN PFEALIST ServerEaList
  1791. )
  1792. /*++
  1793. Routine Description:
  1794. This routine implements the NtQueryEaFile api.
  1795. It returns the following information:
  1796. Arguments:
  1797. IN PFEALIST ServerEaList - Eas to be sent to the server.
  1798. Return Value:
  1799. Status - Result of the operation.
  1800. --*/
  1801. {
  1802. RxCaptureFobx;
  1803. PMRX_SMB_SRV_OPEN smbSrvOpen;
  1804. NTSTATUS Status;
  1805. USHORT Setup = TRANS2_SET_FILE_INFORMATION;
  1806. REQ_SET_FILE_INFORMATION SetFileInfoRequest;
  1807. RESP_SET_FILE_INFORMATION SetFileInfoResponse;
  1808. PBYTE pInputParamBuffer = NULL;
  1809. PBYTE pOutputParamBuffer = NULL;
  1810. PBYTE pInputDataBuffer = NULL;
  1811. PBYTE pOutputDataBuffer = NULL;
  1812. ULONG InputParamBufferLength = 0;
  1813. ULONG OutputParamBufferLength = 0;
  1814. ULONG InputDataBufferLength = 0;
  1815. ULONG OutputDataBufferLength = 0;
  1816. PAGED_CODE();
  1817. RxDbgTrace(+1, Dbg, ("MRxSmbSetEaList...\n"));
  1818. Status = STATUS_MORE_PROCESSING_REQUIRED;
  1819. SetFileInfoResponse.EaErrorOffset = 0;
  1820. smbSrvOpen = MRxSmbGetSrvOpenExtension(capFobx->pSrvOpen);
  1821. if (Status == STATUS_MORE_PROCESSING_REQUIRED) {
  1822. PSMB_TRANSACTION_OPTIONS pTransactionOptions = &RxDefaultTransactionOptions;
  1823. SMB_TRANSACTION_RESUMPTION_CONTEXT ResumptionContext;
  1824. //RxDbgTrace( 0, Dbg, ("MRxSmbNamedPipeFsControl: TransactionName %ws Length %ld\n",
  1825. // TransactionName.Buffer,TransactionName.Length));
  1826. SetFileInfoRequest.Fid = smbSrvOpen->Fid;
  1827. SetFileInfoRequest.InformationLevel = SMB_INFO_SET_EAS;
  1828. SetFileInfoRequest.Flags = 0;
  1829. // CODE.IMPROVEMENT it is unfortunate that this is defined so that a dataMDL cannot be passed
  1830. // perhaps it should be passed in the options!
  1831. Status = SmbCeTransact(
  1832. RxContext, // the RXContext for the transaction
  1833. pTransactionOptions, // transaction options
  1834. &Setup, // the setup buffer
  1835. sizeof(Setup), // setup buffer length
  1836. NULL, // the output setup buffer
  1837. 0, // output setup buffer length
  1838. &SetFileInfoRequest, // Input Param Buffer
  1839. sizeof(SetFileInfoRequest), // Input param buffer length
  1840. &SetFileInfoResponse, // Output param buffer
  1841. sizeof(SetFileInfoResponse), // output param buffer length
  1842. ServerEaList, // Input data buffer
  1843. SmbGetUlong(&ServerEaList->cbList), // Input data buffer length
  1844. NULL, // output data buffer
  1845. 0, // output data buffer length
  1846. &ResumptionContext // the resumption context
  1847. );
  1848. }
  1849. if (!NT_SUCCESS(Status)) {
  1850. USHORT EaErrorOffset = SetFileInfoResponse.EaErrorOffset;
  1851. RxDbgTrace( 0, Dbg, ("MRxSmbSetEaList: Failed .. returning %lx/%lx\n",Status,EaErrorOffset));
  1852. RxContext->InformationToReturn = (EaErrorOffset);
  1853. }
  1854. else
  1855. {
  1856. // succeeded in setting EAs, reset this flag so that when this
  1857. // srvopen is used again for getting the EAs we will succeed
  1858. smbSrvOpen->FileStatusFlags &= ~SMB_FSF_NO_EAS;
  1859. }
  1860. RxDbgTrace(-1, Dbg, ("MRxSmbSetEaList...exit\n"));
  1861. return Status;
  1862. }
  1863. NTSTATUS
  1864. MRxSmbQueryQuotaInformation(
  1865. IN OUT PRX_CONTEXT RxContext)
  1866. {
  1867. RxCaptureFobx;
  1868. PMRX_SMB_SRV_OPEN smbSrvOpen;
  1869. NTSTATUS Status;
  1870. USHORT Setup = NT_TRANSACT_QUERY_QUOTA;
  1871. PSID StartSid;
  1872. ULONG StartSidLength;
  1873. REQ_NT_QUERY_FS_QUOTA_INFO QueryQuotaInfoRequest;
  1874. RESP_NT_QUERY_FS_QUOTA_INFO QueryQuotaInfoResponse;
  1875. PBYTE pInputParamBuffer = NULL;
  1876. PBYTE pOutputParamBuffer = NULL;
  1877. PBYTE pInputDataBuffer = NULL;
  1878. PBYTE pOutputDataBuffer = NULL;
  1879. ULONG InputParamBufferLength = 0;
  1880. ULONG OutputParamBufferLength = 0;
  1881. ULONG InputDataBufferLength = 0;
  1882. ULONG OutputDataBufferLength = 0;
  1883. PAGED_CODE();
  1884. RxDbgTrace(+1, Dbg, ("MRxSmbQueryQuotaInformation...\n"));
  1885. Status = STATUS_MORE_PROCESSING_REQUIRED;
  1886. if (capFobx != NULL) {
  1887. smbSrvOpen = MRxSmbGetSrvOpenExtension(capFobx->pSrvOpen);
  1888. }
  1889. if ((capFobx == NULL) ||
  1890. (smbSrvOpen == NULL)) {
  1891. Status = STATUS_INVALID_PARAMETER;
  1892. }
  1893. if (Status == STATUS_MORE_PROCESSING_REQUIRED) {
  1894. StartSid = RxContext->QueryQuota.StartSid;
  1895. if (StartSid != NULL) {
  1896. StartSidLength = RtlLengthRequiredSid(((PISID)StartSid)->SubAuthorityCount);
  1897. } else {
  1898. StartSidLength = 0;
  1899. }
  1900. QueryQuotaInfoRequest.Fid = smbSrvOpen->Fid;
  1901. QueryQuotaInfoRequest.ReturnSingleEntry = RxContext->QueryQuota.ReturnSingleEntry;
  1902. QueryQuotaInfoRequest.RestartScan = RxContext->QueryQuota.RestartScan;
  1903. QueryQuotaInfoRequest.SidListLength = RxContext->QueryQuota.SidListLength;
  1904. QueryQuotaInfoRequest.StartSidOffset = ROUND_UP_COUNT(
  1905. RxContext->QueryQuota.SidListLength,
  1906. sizeof(ULONG));
  1907. QueryQuotaInfoRequest.StartSidLength = StartSidLength;
  1908. // The input data buffer to be supplied to the server consists of two pieces
  1909. // of information the start sid and the sid list. Currently the I/O
  1910. // subsystem allocates them in contigous memory. In such cases we avoid
  1911. // another allocation by reusing the same buffer. If this condition is
  1912. // not satisfied we allocate a buffer large enough for both the
  1913. // components and copy them over.
  1914. InputDataBufferLength = ROUND_UP_COUNT(
  1915. RxContext->QueryQuota.SidListLength,
  1916. sizeof(ULONG)) +
  1917. StartSidLength;
  1918. QueryQuotaInfoRequest.StartSidLength = StartSidLength;
  1919. if (((PBYTE)RxContext->QueryQuota.SidList +
  1920. ROUND_UP_COUNT(RxContext->QueryQuota.SidListLength,sizeof(ULONG))) !=
  1921. RxContext->QueryQuota.StartSid) {
  1922. pInputDataBuffer = RxAllocatePoolWithTag(
  1923. PagedPool,
  1924. InputDataBufferLength,
  1925. MRXSMB_MISC_POOLTAG);
  1926. if (pInputDataBuffer != NULL) {
  1927. RtlCopyMemory(
  1928. pInputDataBuffer ,
  1929. RxContext->QueryQuota.SidList,
  1930. RxContext->QueryQuota.SidListLength);
  1931. RtlCopyMemory(
  1932. pInputDataBuffer + QueryQuotaInfoRequest.StartSidOffset,
  1933. StartSid,
  1934. StartSidLength);
  1935. } else {
  1936. Status = STATUS_INSUFFICIENT_RESOURCES;
  1937. }
  1938. } else {
  1939. pInputDataBuffer = (PBYTE)RxContext->QueryQuota.SidList;
  1940. }
  1941. if (Status == STATUS_MORE_PROCESSING_REQUIRED) {
  1942. SMB_TRANSACTION_OPTIONS TransactionOptions = RxDefaultTransactionOptions;
  1943. SMB_TRANSACTION_RESUMPTION_CONTEXT ResumptionContext;
  1944. TransactionOptions.NtTransactFunction = NT_TRANSACT_QUERY_QUOTA;
  1945. pOutputDataBuffer = RxContext->Info.Buffer;
  1946. OutputDataBufferLength = RxContext->Info.LengthRemaining;
  1947. Status = SmbCeTransact(
  1948. RxContext, // the RXContext for the transaction
  1949. &TransactionOptions, // transaction options
  1950. &Setup, // the setup buffer
  1951. sizeof(Setup), // setup buffer length
  1952. NULL, // the output setup buffer
  1953. 0, // output setup buffer length
  1954. &QueryQuotaInfoRequest, // Input Param Buffer
  1955. sizeof(QueryQuotaInfoRequest), // Input param buffer length
  1956. &QueryQuotaInfoResponse, // Output param buffer
  1957. sizeof(QueryQuotaInfoResponse), // output param buffer length
  1958. pInputDataBuffer, // Input data buffer
  1959. InputDataBufferLength, // Input data buffer length
  1960. pOutputDataBuffer, // output data buffer
  1961. OutputDataBufferLength, // output data buffer length
  1962. &ResumptionContext // the resumption context
  1963. );
  1964. }
  1965. if ((pInputDataBuffer != NULL) &&
  1966. (pInputDataBuffer != (PBYTE)RxContext->QueryQuota.SidList)) {
  1967. RxFreePool(pInputDataBuffer);
  1968. }
  1969. }
  1970. if (!NT_SUCCESS(Status)) {
  1971. RxContext->InformationToReturn = 0;
  1972. } else {
  1973. RxContext->InformationToReturn = QueryQuotaInfoResponse.Length;
  1974. }
  1975. RxDbgTrace(-1, Dbg, ("MRxSmbQueryQuotaInformation...exit\n"));
  1976. return Status;
  1977. }
  1978. NTSTATUS
  1979. MRxSmbSetQuotaInformation(
  1980. IN OUT PRX_CONTEXT RxContext)
  1981. {
  1982. RxCaptureFobx;
  1983. PMRX_SMB_SRV_OPEN smbSrvOpen;
  1984. NTSTATUS Status;
  1985. USHORT Setup = NT_TRANSACT_SET_QUOTA;
  1986. REQ_NT_SET_FS_QUOTA_INFO SetQuotaInfoRequest;
  1987. PBYTE pInputParamBuffer = NULL;
  1988. PBYTE pOutputParamBuffer = NULL;
  1989. PBYTE pInputDataBuffer = NULL;
  1990. PBYTE pOutputDataBuffer = NULL;
  1991. ULONG InputParamBufferLength = 0;
  1992. ULONG OutputParamBufferLength = 0;
  1993. ULONG InputDataBufferLength = 0;
  1994. ULONG OutputDataBufferLength = 0;
  1995. PAGED_CODE();
  1996. RxDbgTrace(+1, Dbg, ("MRxSmbSetQuotaInformation...\n"));
  1997. Status = STATUS_MORE_PROCESSING_REQUIRED;
  1998. if (capFobx != NULL) {
  1999. smbSrvOpen = MRxSmbGetSrvOpenExtension(capFobx->pSrvOpen);
  2000. }
  2001. if ((capFobx == NULL) ||
  2002. (smbSrvOpen == NULL)) {
  2003. Status = STATUS_INVALID_PARAMETER;
  2004. }
  2005. if (Status == STATUS_MORE_PROCESSING_REQUIRED) {
  2006. SMB_TRANSACTION_OPTIONS TransactionOptions = RxDefaultTransactionOptions;
  2007. SMB_TRANSACTION_RESUMPTION_CONTEXT ResumptionContext;
  2008. TransactionOptions.NtTransactFunction = NT_TRANSACT_SET_QUOTA;
  2009. SetQuotaInfoRequest.Fid = smbSrvOpen->Fid;
  2010. pInputDataBuffer = RxContext->Info.Buffer;
  2011. InputDataBufferLength = RxContext->Info.LengthRemaining;
  2012. Status = SmbCeTransact(
  2013. RxContext, // the RXContext for the transaction
  2014. &TransactionOptions, // transaction options
  2015. &Setup, // the setup buffer
  2016. sizeof(Setup), // setup buffer length
  2017. NULL, // the output setup buffer
  2018. 0, // output setup buffer length
  2019. &SetQuotaInfoRequest, // Input Param Buffer
  2020. sizeof(SetQuotaInfoRequest), // Input param buffer length
  2021. pOutputParamBuffer, // Output param buffer
  2022. OutputParamBufferLength, // output param buffer length
  2023. pInputDataBuffer, // Input data buffer
  2024. InputDataBufferLength, // Input data buffer length
  2025. pOutputDataBuffer, // output data buffer
  2026. OutputDataBufferLength, // output data buffer length
  2027. &ResumptionContext // the resumption context
  2028. );
  2029. }
  2030. RxDbgTrace(-1, Dbg, ("MRxSmbSetQuotaInformation...exit\n"));
  2031. return Status;
  2032. }