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.

361 lines
11 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1994 - 1996.
  5. //
  6. // File: lmshare.cxx
  7. //
  8. // Contents: local functions
  9. //
  10. // History: 8/94 davemont Created
  11. //
  12. //----------------------------------------------------------------------------
  13. #include <aclpch.hxx>
  14. #pragma hdrstop
  15. #include <lmerr.h>
  16. #include <lmcons.h>
  17. //+---------------------------------------------------------------------------
  18. //
  19. // Function: PingLmShare
  20. //
  21. // Synopsis: Determines whether the given share is a Lanman share or not...
  22. //
  23. // Arguments: [IN pwszShare] -- The name of the share to ping
  24. //
  25. // Returns: ERROR_SUCCESS -- The share is lanman
  26. // ERROR_INVALID_NAME -- The format of the name is unrecognized
  27. //
  28. // Notes:
  29. //
  30. //----------------------------------------------------------------------------
  31. DWORD
  32. PingLmShare( IN LPCWSTR pwszShareName)
  33. {
  34. acDebugOut((DEB_TRACE, "in PingLmShare\n"));
  35. DWORD dwErr;
  36. dwErr = LoadDLLFuncTable();
  37. if(dwErr != NO_ERROR)
  38. {
  39. return(dwErr);
  40. }
  41. if(pwszShareName != NULL)
  42. {
  43. //
  44. // save the object since we must crack it to go to remote machines
  45. //
  46. WCHAR wszUseName[RMLEN + 1];
  47. LPWSTR pwszUseName;
  48. dwErr = AccGetBufferOfSizeW((PWSTR)pwszShareName,
  49. wszUseName,
  50. &pwszUseName);
  51. if(dwErr == ERROR_SUCCESS)
  52. {
  53. PWSTR pwszShare, pwszMachine;
  54. //
  55. // get the machinename from the full name
  56. //
  57. dwErr = ParseName(pwszUseName,
  58. &pwszMachine,
  59. &pwszShare);
  60. if(dwErr == ERROR_SUCCESS)
  61. {
  62. PSHARE_INFO_0 pSI0;
  63. //
  64. // get share infolevel 0
  65. //
  66. dwErr = (*DLLFuncs.PNetShareGetInfo)(pwszMachine,
  67. pwszShare,
  68. 0,
  69. (PBYTE *)&pSI0);
  70. if(dwErr == ERROR_SUCCESS)
  71. {
  72. (*DLLFuncs.PNetApiBufferFree)(pSI0);
  73. }
  74. else
  75. {
  76. if(dwErr == NERR_NetNameNotFound)
  77. {
  78. dwErr = ERROR_PATH_NOT_FOUND;
  79. }
  80. //
  81. // Any other error will be returned to the calling
  82. // API
  83. //
  84. }
  85. }
  86. AccFreeBufferOfSizeW(wszUseName,
  87. pwszUseName);
  88. }
  89. }
  90. else
  91. {
  92. dwErr = ERROR_INVALID_NAME;
  93. }
  94. acDebugOut((DEB_TRACE, "Out PingLmShare(%d)\n", dwErr));
  95. return(dwErr);
  96. }
  97. //+---------------------------------------------------------------------------
  98. //
  99. // Function: ReadSharePropertyRights
  100. //
  101. // Synopsis: Gets the specified security info for the specified net share
  102. // object
  103. //
  104. // Arguments: [IN pwszShare] -- The share to get the rights
  105. // for
  106. // [IN pRightsList] -- SecurityInfo to read based
  107. // on properties
  108. // [IN cRights] -- Number of items in rights list
  109. // [IN AccessList] -- Access List to fill in
  110. //
  111. // Returns: ERROR_SUCCESS -- Success
  112. // ERROR_INVALID_PARAMETER -- A bad property was encountered
  113. // ERROR_NOT_ENOUGH_MEMORY -- A memory allocation failed
  114. //
  115. //----------------------------------------------------------------------------
  116. DWORD
  117. ReadSharePropertyRights(IN LPWSTR pwszShare,
  118. IN PACTRL_RIGHTS_INFO pRightsList,
  119. IN ULONG cRights,
  120. IN CAccessList& AccessList)
  121. {
  122. acDebugOut((DEB_TRACE, "in ReadSharePropertyRights\n"));
  123. DWORD dwErr;
  124. PSHARE_INFO_502 pSI502;
  125. dwErr = LoadDLLFuncTable();
  126. if(dwErr != ERROR_SUCCESS)
  127. {
  128. return(dwErr);
  129. }
  130. //
  131. // For the moment, there is only the share itself...
  132. //
  133. ASSERT(cRights == 1 && pRightsList[0].pwszProperty == NULL);
  134. if(cRights != 1 || pRightsList[0].pwszProperty != NULL)
  135. {
  136. return(ERROR_INVALID_PARAMETER);
  137. }
  138. if(pwszShare != NULL)
  139. {
  140. WCHAR wszName[MAX_PATH + 1];
  141. PWSTR pwszName;
  142. //
  143. // save the object since we must crack it to go to remote machines
  144. //
  145. dwErr = AccGetBufferOfSizeW(pwszShare,
  146. wszName,
  147. &pwszName);
  148. if(dwErr == ERROR_SUCCESS)
  149. {
  150. PWSTR pwszShr, pwszMachine;
  151. //
  152. // Separate the names
  153. //
  154. dwErr = ParseName(pwszName,
  155. &pwszMachine,
  156. &pwszShr);
  157. if(dwErr == ERROR_SUCCESS)
  158. {
  159. //
  160. // get share infolevel 502 (a bunch of stuff) since
  161. // level 1501 seems to be write only
  162. //
  163. PSHARE_INFO_0 pSI0;
  164. dwErr = (*DLLFuncs.PNetShareGetInfo)(pwszMachine,
  165. pwszShr,
  166. 502,
  167. (PBYTE *)&pSI502);
  168. if(dwErr == ERROR_SUCCESS &&
  169. pSI502->shi502_security_descriptor != NULL)
  170. {
  171. //
  172. // Add it
  173. //
  174. dwErr = AccessList.AddSD(
  175. pSI502->shi502_security_descriptor,
  176. pRightsList->SeInfo,
  177. pRightsList->pwszProperty);
  178. (*DLLFuncs.PNetApiBufferFree)(pSI502);
  179. }
  180. }
  181. AccFreeBufferOfSizeW(wszName, pwszName);
  182. }
  183. else
  184. {
  185. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  186. }
  187. }
  188. else
  189. {
  190. dwErr = ERROR_INVALID_PARAMETER;
  191. }
  192. acDebugOut((DEB_TRACE, "Out ReadSharePropertyRights: %lu\n", dwErr));
  193. return(dwErr);
  194. }
  195. //+---------------------------------------------------------------------------
  196. //
  197. // Function: GetShareParentRights
  198. //
  199. // Synopsis: Determines who the parent is, and gets the access rights
  200. // for it. It is used to aid in determining what the approriate
  201. // inheritance bits are.
  202. //
  203. // This operation does not make sense for share objects
  204. //
  205. // Arguments: [IN pwszShare] -- The share to get the parent
  206. // for
  207. // [IN pRightsList] -- The properties to get the
  208. // rights for
  209. // [IN cRights] -- Number of items in rights list
  210. // [OUT ppDAcl] -- Where the DACL is returned
  211. // [OUT ppSAcl] -- Where the SACL is returned
  212. // [OUT ppSD] -- Where the Security Descriptor
  213. // is returned
  214. //
  215. // Returns: ERROR_INVALID_FUNCTION -- Call doesn't make sense here
  216. //
  217. //----------------------------------------------------------------------------
  218. DWORD
  219. GetShareParentRights(IN LPWSTR pwszShare,
  220. IN PACTRL_RIGHTS_INFO pRightsList,
  221. IN ULONG cRights,
  222. OUT PACL *ppDAcl,
  223. OUT PACL *ppSAcl,
  224. OUT PSECURITY_DESCRIPTOR *ppSD)
  225. {
  226. //
  227. // This doesn't currently make sense for share objects, so simply
  228. // return an error
  229. //
  230. return(ERROR_INVALID_FUNCTION);
  231. }
  232. //+---------------------------------------------------------------------------
  233. //
  234. // Function: SetShareSecurityInfo
  235. //
  236. // Synopsis: Sets the specified security info on the specified share
  237. // object
  238. //
  239. // Arguments: [IN pwszShare] -- Share to set it on
  240. // [IN SeInfo] -- Flag indicating what security
  241. // info to set
  242. // [IN pwszProperty] -- The property on the object to
  243. // set
  244. // For kernel objects, this MBZ
  245. // [IN pSD] -- The security descriptor to set
  246. //
  247. // Returns: ERROR_SUCCESS -- Success
  248. // ERROR_INVALID_PARAMETER -- A bad property was given
  249. //
  250. //----------------------------------------------------------------------------
  251. DWORD
  252. SetShareSecurityInfo(IN PWSTR pwszShare,
  253. IN SECURITY_INFORMATION SeInfo,
  254. IN PWSTR pwszProperty,
  255. IN PSECURITY_DESCRIPTOR pSD)
  256. {
  257. acDebugOut((DEB_TRACE, "in SetShareSecurityInfo \n"));
  258. DWORD dwErr = ERROR_SUCCESS;
  259. SHARE_INFO_1501 SI1501;
  260. //
  261. // Net shares don't have properties
  262. //
  263. if(pwszProperty != NULL)
  264. {
  265. dwErr = ERROR_INVALID_PARAMETER;
  266. }
  267. else
  268. {
  269. dwErr = LoadDLLFuncTable();
  270. if(dwErr != ERROR_SUCCESS)
  271. {
  272. return(dwErr);
  273. }
  274. if(pwszShare != NULL)
  275. {
  276. WCHAR wszName[MAX_PATH + 1];
  277. PWSTR pwszName;
  278. //
  279. // save the object since we must crack it to go to remote machines
  280. //
  281. dwErr = AccGetBufferOfSizeW(pwszShare,
  282. wszName,
  283. &pwszName);
  284. if(dwErr == ERROR_SUCCESS)
  285. {
  286. PWSTR pwszShr, pwszMachine;
  287. //
  288. // Separate the names
  289. //
  290. dwErr = ParseName(pwszName,
  291. &pwszMachine,
  292. &pwszShr);
  293. if(dwErr == ERROR_SUCCESS)
  294. {
  295. SI1501.shi1501_reserved = 0;
  296. SI1501.shi1501_security_descriptor = pSD;
  297. //
  298. // set the security descriptor
  299. //
  300. dwErr = (*DLLFuncs.PNetShareSetInfo)(pwszMachine,
  301. pwszShr,
  302. 1501,
  303. (PBYTE)&SI1501,
  304. NULL);
  305. }
  306. AccFreeBufferOfSizeW(wszName, pwszName);
  307. }
  308. else
  309. {
  310. dwErr = ERROR_NOT_ENOUGH_MEMORY;
  311. }
  312. }
  313. else
  314. {
  315. dwErr = ERROR_INVALID_PARAMETER;
  316. }
  317. }
  318. acDebugOut((DEB_TRACE, "Out SetShareSecurityInfo: %lu\n", dwErr));
  319. return(dwErr);
  320. }