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.

641 lines
14 KiB

  1. /*
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. fsp_dtp.c
  5. Abstract:
  6. This module contains the entry points for the AFP desktop APIs queued to
  7. the FSP. These are all callable from FSP Only.
  8. Author:
  9. Jameel Hyder (microsoft!jameelh)
  10. Revision History:
  11. 25 Apr 1992 Initial Version
  12. Notes: Tab stop: 4
  13. --*/
  14. #define FILENUM FILE_FSP_DTP
  15. #include <afp.h>
  16. #include <gendisp.h>
  17. #include <fdparm.h>
  18. #include <pathmap.h>
  19. #include <client.h>
  20. #ifdef ALLOC_PRAGMA
  21. #pragma alloc_text( PAGE, AfpFspDispAddIcon)
  22. #pragma alloc_text( PAGE, AfpFspDispGetIcon)
  23. #pragma alloc_text( PAGE, AfpFspDispGetIconInfo)
  24. #pragma alloc_text( PAGE, AfpFspDispAddAppl)
  25. #pragma alloc_text( PAGE, AfpFspDispGetAppl)
  26. #pragma alloc_text( PAGE, AfpFspDispRemoveAppl)
  27. #pragma alloc_text( PAGE, AfpFspDispAddComment)
  28. #pragma alloc_text( PAGE, AfpFspDispGetComment)
  29. #pragma alloc_text( PAGE, AfpFspDispRemoveComment)
  30. #endif
  31. /*** AfpFspDispAddIcon
  32. *
  33. * This is the worker routine for the AfpAddIcon API.
  34. *
  35. * The request packet is represented below
  36. *
  37. * sda_ReqBlock PCONNDESC pConnDesc
  38. * sda_ReqBlock DWORD Creator
  39. * sda_ReqBlock DWORD Type
  40. * sda_ReqBlock DWORD IconType
  41. * sda_ReqBlock DWORD IconTag
  42. * sda_ReqBlock LONG BitmapSize
  43. * sda_ReplyBuf BYTE[] IconBuffer
  44. */
  45. AFPSTATUS FASTCALL
  46. AfpFspDispAddIcon(
  47. IN PSDA pSda
  48. )
  49. {
  50. AFPSTATUS Status = AFP_ERR_PARAM;
  51. struct _RequestPacket
  52. {
  53. PCONNDESC _pConnDesc;
  54. DWORD _Creator;
  55. DWORD _Type;
  56. DWORD _IconType;
  57. DWORD _IconTag;
  58. LONG _Size;
  59. };
  60. PAGED_CODE( );
  61. DBGPRINT(DBG_COMP_AFPAPI_DTP, DBG_LEVEL_INFO,
  62. ("AfpFspDispAddIcon: Entered\n"));
  63. ASSERT(VALID_CONNDESC(pReqPkt->_pConnDesc) &&
  64. VALID_VOLDESC(pReqPkt->_pConnDesc->cds_pVolDesc));
  65. ASSERT(VALID_CONNDESC(pReqPkt->_pConnDesc));
  66. ASSERT(VALID_VOLDESC(pReqPkt->_pConnDesc->cds_pVolDesc));
  67. if (pSda->sda_IOSize > 0)
  68. {
  69. ASSERT(pSda->sda_IOBuf != NULL);
  70. Status = AfpAddIcon(pReqPkt->_pConnDesc->cds_pVolDesc,
  71. pReqPkt->_Creator,
  72. pReqPkt->_Type,
  73. pReqPkt->_IconTag,
  74. pReqPkt->_Size,
  75. pReqPkt->_IconType,
  76. pSda->sda_IOBuf);
  77. AfpFreeIOBuffer(pSda);
  78. }
  79. return Status;
  80. }
  81. /*** AfpFspDispGetIcon
  82. *
  83. * This is the worker routine for the AfpGetIcon API.
  84. *
  85. * The request packet is represented below
  86. *
  87. * sda_ReqBlock PCONNDESC pConnDesc
  88. * sda_ReqBlock DWORD Creator
  89. * sda_ReqBlock DWORD Type
  90. * sda_ReqBlock DWORD IconType
  91. * sda_ReqBlock LONG Length of buffer
  92. */
  93. AFPSTATUS FASTCALL
  94. AfpFspDispGetIcon(
  95. IN PSDA pSda
  96. )
  97. {
  98. AFPSTATUS Status = AFP_ERR_PARAM;
  99. LONG ActualLength;
  100. struct _RequestPacket
  101. {
  102. PCONNDESC _pConnDesc;
  103. DWORD _Creator;
  104. DWORD _Type;
  105. DWORD _IconType;
  106. LONG _Length;
  107. };
  108. PAGED_CODE( );
  109. DBGPRINT(DBG_COMP_AFPAPI_DTP, DBG_LEVEL_INFO,
  110. ("AfpFspDispGetIcon: Entered\n"));
  111. ASSERT(VALID_CONNDESC(pReqPkt->_pConnDesc) &&
  112. VALID_VOLDESC(pReqPkt->_pConnDesc->cds_pVolDesc));
  113. if (pReqPkt->_Length >= 0)
  114. {
  115. pSda->sda_ReplySize = (USHORT)pReqPkt->_Length;
  116. if (pReqPkt->_Length > (LONG)pSda->sda_MaxWriteSize)
  117. pSda->sda_ReplySize = (USHORT)pSda->sda_MaxWriteSize;
  118. if ((pSda->sda_ReplySize == 0) ||
  119. ((pSda->sda_ReplySize > 0) &&
  120. (Status = AfpAllocReplyBuf(pSda)) == AFP_ERR_NONE))
  121. {
  122. if ((Status = AfpLookupIcon(pReqPkt->_pConnDesc->cds_pVolDesc,
  123. pReqPkt->_Creator,
  124. pReqPkt->_Type,
  125. pReqPkt->_Length,
  126. pReqPkt->_IconType,
  127. &ActualLength,
  128. pSda->sda_ReplyBuf)) != AFP_ERR_NONE)
  129. {
  130. Status = AFP_ERR_ITEM_NOT_FOUND;
  131. }
  132. else
  133. {
  134. pSda->sda_ReplySize = (USHORT)ActualLength;
  135. }
  136. }
  137. }
  138. return Status;
  139. }
  140. /*** AfpFspDispGetIconInfo
  141. *
  142. * This is the worker routine for the AfpGetIconInfo API.
  143. *
  144. * The request packet is represented below
  145. *
  146. * sda_ReqBlock PCONNDESC pConnDesc
  147. * sda_ReqBlock DWORD Creator
  148. * sda_ReqBlock LONG Icon index
  149. */
  150. AFPSTATUS FASTCALL
  151. AfpFspDispGetIconInfo(
  152. IN PSDA pSda
  153. )
  154. {
  155. LONG Size;
  156. DWORD Type,
  157. Tag;
  158. DWORD IconType;
  159. AFPSTATUS Status = AFP_ERR_PARAM;
  160. struct _RequestPacket
  161. {
  162. PCONNDESC _pConnDesc;
  163. DWORD _Creator;
  164. DWORD _Index;
  165. };
  166. struct _ResponsePacket
  167. {
  168. BYTE __IconTag[4];
  169. BYTE __Type[4];
  170. BYTE __IconType;
  171. BYTE __Pad;
  172. BYTE __Size[2];
  173. };
  174. PAGED_CODE( );
  175. DBGPRINT(DBG_COMP_AFPAPI_DTP, DBG_LEVEL_INFO,
  176. ("AfpFspDispGetIconInfo: Entered\n"));
  177. ASSERT(VALID_CONNDESC(pReqPkt->_pConnDesc) &&
  178. VALID_VOLDESC(pReqPkt->_pConnDesc->cds_pVolDesc));
  179. if ((Status = AfpLookupIconInfo(pReqPkt->_pConnDesc->cds_pVolDesc,
  180. pReqPkt->_Creator,
  181. pReqPkt->_Index,
  182. &Type,
  183. &IconType,
  184. &Tag,
  185. &Size)) == AFP_ERR_NONE)
  186. {
  187. pSda->sda_ReplySize = SIZE_RESPPKT;
  188. if ((Status = AfpAllocReplyBuf(pSda)) == AFP_ERR_NONE)
  189. {
  190. PUTDWORD2DWORD(&pRspPkt->__IconTag, Tag);
  191. RtlCopyMemory(&pRspPkt->__Type, (PBYTE)&Type, sizeof(DWORD));
  192. PUTSHORT2BYTE(&pRspPkt->__IconType, IconType);
  193. PUTDWORD2SHORT(&pRspPkt->__Size, Size);
  194. }
  195. }
  196. return Status;
  197. }
  198. /*** AfpFspDispAddAppl
  199. *
  200. * This is the worker routine for the AfpAddAppl API.
  201. *
  202. * The request packet is represented below
  203. *
  204. * sda_ReqBlock PCONNDESC pConnDesc
  205. * sda_ReqBlock DWORD Directory Id
  206. * sda_ReqBlock DWORD Creator
  207. * sda_ReqBlock DWORD APPL Tag
  208. * sda_Name1 ANSI_STRING PathName
  209. */
  210. AFPSTATUS FASTCALL
  211. AfpFspDispAddAppl(
  212. IN PSDA pSda
  213. )
  214. {
  215. FILEDIRPARM FDParm;
  216. PATHMAPENTITY PME;
  217. AFPSTATUS Status = AFP_ERR_PARAM;
  218. struct _RequestPacket
  219. {
  220. PCONNDESC _pConnDesc;
  221. DWORD _DirId;
  222. DWORD _Creator;
  223. DWORD _ApplTag;
  224. };
  225. PAGED_CODE( );
  226. DBGPRINT(DBG_COMP_AFPAPI_DTP, DBG_LEVEL_INFO,
  227. ("AfpFspDispAddAppl: Entered\n"));
  228. ASSERT(VALID_CONNDESC(pReqPkt->_pConnDesc) &&
  229. VALID_VOLDESC(pReqPkt->_pConnDesc->cds_pVolDesc));
  230. AfpInitializePME(&PME, 0, NULL);
  231. if ((Status = AfpMapAfpPathForLookup(pReqPkt->_pConnDesc,
  232. pReqPkt->_DirId,
  233. &pSda->sda_Name1,
  234. pSda->sda_PathType,
  235. DFE_FILE,
  236. FILE_BITMAP_FILENUM |
  237. FD_INTERNAL_BITMAP_OPENACCESS_WRITE,
  238. &PME,
  239. &FDParm)) == AFP_ERR_NONE)
  240. {
  241. AfpIoClose(&PME.pme_Handle); // only needed to check for RW access
  242. Status = AfpAddAppl(pReqPkt->_pConnDesc->cds_pVolDesc,
  243. pReqPkt->_Creator,
  244. pReqPkt->_ApplTag,
  245. FDParm._fdp_AfpId,
  246. False,
  247. FDParm._fdp_ParentId);
  248. }
  249. return Status;
  250. }
  251. /*** AfpFspDispGetAPPL
  252. *
  253. * This is the worker routine for the AfpGetAppl API.
  254. *
  255. * The request packet is represented below
  256. *
  257. * sda_ReqBlock PCONNDESC pConnDesc
  258. * sda_ReqBlock DWORD Creator
  259. * sda_ReqBlock DWORD APPL Index
  260. * sda_ReqBlock DWORD Bitmap
  261. */
  262. AFPSTATUS FASTCALL
  263. AfpFspDispGetAppl(
  264. IN PSDA pSda
  265. )
  266. {
  267. DWORD ApplTag;
  268. DWORD Bitmap, // Need to copy this as it goes into the resp
  269. FileNum, ParentID;
  270. AFPSTATUS Status = AFP_ERR_PARAM;
  271. FILEDIRPARM FDParm;
  272. PATHMAPENTITY PME;
  273. struct _RequestPacket
  274. {
  275. PCONNDESC _pConnDesc;
  276. DWORD _Creator;
  277. DWORD _Index;
  278. DWORD _Bitmap;
  279. };
  280. struct _ResponsePacket
  281. {
  282. BYTE __Bitmap[2];
  283. BYTE __ApplTag[4];
  284. // Followed by the File Parameters. These cannot be represented as a
  285. // structure since it depends on the bitmap
  286. };
  287. PAGED_CODE( );
  288. DBGPRINT(DBG_COMP_AFPAPI_DTP, DBG_LEVEL_INFO,
  289. ("AfpFspDispGetAppl: Entered\n"));
  290. ASSERT(VALID_CONNDESC(pReqPkt->_pConnDesc) &&
  291. VALID_VOLDESC(pReqPkt->_pConnDesc->cds_pVolDesc));
  292. Bitmap = pReqPkt->_Bitmap;
  293. AfpInitializePME(&PME, 0, NULL);
  294. do
  295. {
  296. if ((Status = AfpLookupAppl(pReqPkt->_pConnDesc->cds_pVolDesc,
  297. pReqPkt->_Creator,
  298. pReqPkt->_Index,
  299. &ApplTag, &FileNum, &ParentID)) != AFP_ERR_NONE)
  300. break;
  301. AfpInitializeFDParms(&FDParm);
  302. // Call AfpMapAfpPathForLookup on the parent ID first to make sure
  303. // its files are cached in.
  304. if (ParentID != 0)
  305. {
  306. ANSI_STRING nullname = {0, 0, NULL};
  307. if ((Status = AfpMapAfpPathForLookup(pReqPkt->_pConnDesc,
  308. ParentID,
  309. &nullname,
  310. AFP_LONGNAME,
  311. DFE_DIR,
  312. 0, // Bitmap
  313. NULL,
  314. NULL)) != AFP_ERR_NONE)
  315. {
  316. break;
  317. }
  318. }
  319. if ((Status = AfpMapAfpIdForLookup(pReqPkt->_pConnDesc,
  320. FileNum,
  321. DFE_FILE,
  322. Bitmap | FD_INTERNAL_BITMAP_OPENACCESS_READ,
  323. &PME, // open a handle to check access
  324. &FDParm)) != AFP_ERR_NONE)
  325. break;
  326. pSda->sda_ReplySize = SIZE_RESPPKT +
  327. EVENALIGN(AfpGetFileDirParmsReplyLength(&FDParm, Bitmap));
  328. if ((Status = AfpAllocReplyBuf(pSda)) == AFP_ERR_NONE)
  329. {
  330. AfpPackFileDirParms(&FDParm, Bitmap,
  331. pSda->sda_ReplyBuf + SIZE_RESPPKT);
  332. PUTDWORD2SHORT(pRspPkt->__Bitmap, Bitmap);
  333. PUTDWORD2DWORD(pRspPkt->__ApplTag, ApplTag);
  334. }
  335. } while (False);
  336. if (PME.pme_Handle.fsh_FileHandle != NULL)
  337. AfpIoClose(&PME.pme_Handle);
  338. return Status;
  339. }
  340. /*** AfpFspDispRemoveAppl
  341. *
  342. * This is the worker routine for the AfpRemoveAppl API.
  343. *
  344. * The request packet is represented below
  345. *
  346. * sda_ReqBlock PCONNDESC pConnDesc
  347. * sda_ReqBlock DWORD Directory Id
  348. * sda_ReqBlock DWORD Creator
  349. * sda_Name1 ANSI_STRING PathName
  350. */
  351. AFPSTATUS FASTCALL
  352. AfpFspDispRemoveAppl(
  353. IN PSDA pSda
  354. )
  355. {
  356. FILEDIRPARM FDParm;
  357. PATHMAPENTITY PME;
  358. AFPSTATUS Status = AFP_ERR_PARAM;
  359. struct _RequestPacket
  360. {
  361. PCONNDESC _pConnDesc;
  362. DWORD _DirId;
  363. DWORD _Creator;
  364. };
  365. PAGED_CODE( );
  366. DBGPRINT(DBG_COMP_AFPAPI_DTP, DBG_LEVEL_INFO,
  367. ("AfpFspDispRemoveAppl: Entered\n"));
  368. ASSERT(VALID_CONNDESC(pReqPkt->_pConnDesc) &&
  369. VALID_VOLDESC(pReqPkt->_pConnDesc->cds_pVolDesc));
  370. AfpInitializePME(&PME, 0, NULL);
  371. if ((Status = AfpMapAfpPathForLookup(pReqPkt->_pConnDesc,
  372. pReqPkt->_DirId,
  373. &pSda->sda_Name1,
  374. pSda->sda_PathType,
  375. DFE_FILE,
  376. FILE_BITMAP_FILENUM |
  377. FD_INTERNAL_BITMAP_OPENACCESS_READWRITE,
  378. &PME,
  379. &FDParm)) == AFP_ERR_NONE)
  380. {
  381. AfpIoClose(&PME.pme_Handle); // only needed to check access
  382. Status = AfpRemoveAppl(pReqPkt->_pConnDesc->cds_pVolDesc,
  383. pReqPkt->_Creator,
  384. FDParm._fdp_AfpId);
  385. }
  386. return Status;
  387. }
  388. /*** AfpFspDispAddComment
  389. *
  390. * This is the worker routine for the AfpAddComment API.
  391. *
  392. * The request packet is represented below
  393. *
  394. * sda_ReqBlock PCONNDESC pConnDesc
  395. * sda_ReqBlock DWORD Directory Id
  396. * sda_Name1 ANSI_STRING PathName
  397. * sda_Name2 ANSI_STRING Comment
  398. */
  399. AFPSTATUS FASTCALL
  400. AfpFspDispAddComment(
  401. IN PSDA pSda
  402. )
  403. {
  404. PATHMAPENTITY PME;
  405. FILEDIRPARM FDParm;
  406. AFPSTATUS Status;
  407. struct _RequestPacket
  408. {
  409. PCONNDESC _pConnDesc;
  410. DWORD _DirId;
  411. };
  412. PAGED_CODE( );
  413. DBGPRINT(DBG_COMP_AFPAPI_DTP, DBG_LEVEL_INFO,
  414. ("AfpFspDispAddComment: Entered\n"));
  415. ASSERT(VALID_CONNDESC(pReqPkt->_pConnDesc) &&
  416. VALID_VOLDESC(pReqPkt->_pConnDesc->cds_pVolDesc));
  417. AfpInitializePME(&PME, 0, NULL);
  418. if ((Status = AfpMapAfpPathForLookup(pReqPkt->_pConnDesc,
  419. pReqPkt->_DirId,
  420. &pSda->sda_Name1,
  421. pSda->sda_PathType,
  422. DFE_ANY,
  423. 0,
  424. &PME,
  425. &FDParm)) == AFP_ERR_NONE)
  426. {
  427. Status = AFP_ERR_VOLUME_LOCKED;
  428. if (IS_CONN_NTFS(pReqPkt->_pConnDesc))
  429. Status = AfpAddComment(pSda,
  430. pReqPkt->_pConnDesc->cds_pVolDesc,
  431. &pSda->sda_Name2,
  432. &PME,
  433. IsDir(&FDParm),
  434. FDParm._fdp_AfpId);
  435. AfpIoClose(&PME.pme_Handle);
  436. }
  437. return Status;
  438. }
  439. /*** AfpFspDispGetComment
  440. *
  441. * This is the worker routine for the AfpGetComment API.
  442. *
  443. * The request packet is represented below
  444. *
  445. * sda_ReqBlock PCONNDESC pConnDesc
  446. * sda_ReqBlock DWORD Directory Id
  447. * sda_Name1 ANSI_STRING PathName
  448. */
  449. AFPSTATUS FASTCALL
  450. AfpFspDispGetComment(
  451. IN PSDA pSda
  452. )
  453. {
  454. PATHMAPENTITY PME;
  455. FILEDIRPARM FDParm;
  456. AFPSTATUS Status;
  457. struct _RequestPacket
  458. {
  459. PCONNDESC _pConnDesc;
  460. DWORD _DirId;
  461. };
  462. PAGED_CODE( );
  463. DBGPRINT(DBG_COMP_AFPAPI_DTP, DBG_LEVEL_INFO,
  464. ("AfpFspDispGetComment: Entered\n"));
  465. ASSERT(VALID_CONNDESC(pReqPkt->_pConnDesc) &&
  466. VALID_VOLDESC(pReqPkt->_pConnDesc->cds_pVolDesc));
  467. AfpInitializePME(&PME, 0, NULL);
  468. if ((Status = AfpMapAfpPathForLookup(pReqPkt->_pConnDesc,
  469. pReqPkt->_DirId,
  470. &pSda->sda_Name1,
  471. pSda->sda_PathType,
  472. DFE_ANY,
  473. 0,
  474. &PME,
  475. &FDParm)) == AFP_ERR_NONE)
  476. {
  477. // Assume no comment to start with
  478. Status = AFP_ERR_ITEM_NOT_FOUND;
  479. if (IS_CONN_NTFS(pReqPkt->_pConnDesc) &&
  480. (FDParm._fdp_Flags & DFE_FLAGS_HAS_COMMENT))
  481. {
  482. pSda->sda_ReplySize = AFP_MAXCOMMENTSIZE + 1;
  483. if ((Status = AfpAllocReplyBuf(pSda)) == AFP_ERR_NONE)
  484. {
  485. if ((Status = AfpGetComment(pSda,
  486. pReqPkt->_pConnDesc->cds_pVolDesc,
  487. &PME,
  488. IsDir(&FDParm))) != AFP_ERR_NONE)
  489. {
  490. AfpFreeReplyBuf(pSda, FALSE);
  491. }
  492. }
  493. }
  494. AfpIoClose(&PME.pme_Handle);
  495. }
  496. return Status;
  497. }
  498. /*** AfpFspDispRemoveComment
  499. *
  500. * This is the worker routine for the AfpRemoveComment API.
  501. *
  502. * The request packet is represented below
  503. *
  504. * sda_ReqBlock PCONNDESC pConnDesc
  505. * sda_ReqBlock DWORD Directory Id
  506. * sda_Name1 ANSI_STRING PathName
  507. */
  508. AFPSTATUS FASTCALL
  509. AfpFspDispRemoveComment(
  510. IN PSDA pSda
  511. )
  512. {
  513. PATHMAPENTITY PME;
  514. FILEDIRPARM FDParm;
  515. AFPSTATUS Status = AFP_ERR_ITEM_NOT_FOUND;
  516. struct _RequestPacket
  517. {
  518. PCONNDESC _pConnDesc;
  519. DWORD _DirId;
  520. };
  521. PAGED_CODE( );
  522. DBGPRINT(DBG_COMP_AFPAPI_DTP, DBG_LEVEL_INFO,
  523. ("AfpFspDispRemoveComment: Entered\n"));
  524. ASSERT(VALID_CONNDESC(pReqPkt->_pConnDesc) &&
  525. VALID_VOLDESC(pReqPkt->_pConnDesc->cds_pVolDesc));
  526. AfpInitializePME(&PME, 0, NULL);
  527. if (IS_CONN_NTFS(pReqPkt->_pConnDesc) &&
  528. (Status = AfpMapAfpPathForLookup(pReqPkt->_pConnDesc,
  529. pReqPkt->_DirId,
  530. &pSda->sda_Name1,
  531. pSda->sda_PathType,
  532. DFE_ANY,
  533. 0,
  534. &PME,
  535. &FDParm)) == AFP_ERR_NONE)
  536. {
  537. Status = AFP_ERR_ITEM_NOT_FOUND;
  538. if (IS_CONN_NTFS(pReqPkt->_pConnDesc) &&
  539. (FDParm._fdp_Flags & DFE_FLAGS_HAS_COMMENT))
  540. Status = AfpRemoveComment(pSda,
  541. pReqPkt->_pConnDesc->cds_pVolDesc,
  542. &PME,
  543. IsDir(&FDParm),
  544. FDParm._fdp_AfpId);
  545. AfpIoClose(&PME.pme_Handle);
  546. }
  547. return Status;
  548. }
  549.