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.

522 lines
9.4 KiB

  1. /********************************************************************/
  2. /** Copyright(c) 1989 Microsoft Corporation. **/
  3. /********************************************************************/
  4. //***
  5. //
  6. // Filename: afpsvcp.h
  7. //
  8. // Description: This is the main header file for the AFP Server Service.
  9. //
  10. // History:
  11. // May 11,1992. NarenG Created original version.
  12. //
  13. #ifndef _AFPSVCP_
  14. #define _AFPSVCP_
  15. #include <nt.h>
  16. #include <ntrtl.h>
  17. #include <ntseapi.h>
  18. #include <ntlsa.h>
  19. #include <ntsam.h>
  20. #include <ntsamp.h>
  21. #include <nturtl.h> // needed for winbase.h
  22. #include <ntmsv1_0.h>
  23. #include <samrpc.h>
  24. #include <align.h>
  25. #include <windows.h> // Win32 base API's
  26. #include <winuser.h> // Needed for LoadString
  27. #include <winsvc.h> // Win32 service control stuff
  28. #include <winreg.h> // Win32 registry API's
  29. #include <lm.h>
  30. #include <srvann.h>
  31. #include <rpc.h> // RPC api's
  32. #include <devioctl.h> // FILE_DEVICE_NETWORK, METHOD_BUFFERD constants
  33. #include <stdlib.h>
  34. #include <string.h>
  35. #include <ctype.h>
  36. #include <wchar.h>
  37. #include <search.h>
  38. #if DBG
  39. #define DEBUG TRUE
  40. #endif
  41. #include <afpsvc.h> // Generated by MIDL
  42. #include <admin.h>
  43. #include <macfile.h>
  44. #include <afpcomn.h>
  45. #include "events.h"
  46. #include "ioctl.h"
  47. #include "rasfmsub.h"
  48. #include "debug.h"
  49. #define LOGON_PROCESS_NAME "SFM_SERVICE"
  50. #define AFPSTATE_RPC_STARTED 0x1
  51. #define AFPSTATE_FSD_LOADED 0x2
  52. #define AFPSTATE_BLOCKED_ON_DOMINFO 0x4
  53. // Id's of the various data structures
  54. //
  55. typedef enum _AFP_STRUCTURE_TYPE {
  56. AFP_EXTENSION_STRUCT,
  57. AFP_TYPECREATOR_STRUCT,
  58. AFP_ICON_STRUCT,
  59. AFP_VOLUME_STRUCT,
  60. AFP_SERVER_STRUCT,
  61. AFP_DIRECTORY_STRUCT,
  62. AFP_SESSION_STRUCT,
  63. AFP_CONNECTION_STRUCT,
  64. AFP_MESSAGE_STRUCT,
  65. AFP_FILE_STRUCT,
  66. AFP_FINDER_STRUCT
  67. } AFP_STRUCTURE_TYPE;
  68. // The approximate times (in milliseconds) taken to respond to various
  69. // service control requests.
  70. //
  71. #define AFP_SERVICE_INSTALL_TIME 15*60000 // 15 minutes
  72. #define AFP_SERVICE_STOP_TIME 5*60000 // 5 minutes
  73. #define AFP_SERVICE_CONTINUE_TIME 5000
  74. #define AFP_SERVICE_PAUSE_TIME 1000
  75. // Macro to calculate the byte offset of a field in a structure of type type.
  76. //
  77. #define AFP_FIELD_OFFSET(type, field) ((LONG)((LONG_PTR)&(((type *)0)->field)))
  78. // Macro to calculate the size of a given field within a structure.
  79. //
  80. #define AFP_FIELD_SIZE(type, field) sizeof(((type *)0)->field)
  81. // Access mask values
  82. //
  83. #define AFPSVC_ALL_ACCESS 0x0001
  84. // All global variables are packaged within this structure.
  85. //
  86. typedef struct _AFP_GLOBALS {
  87. // Handle to the key that contains the server parameters
  88. //
  89. HKEY hkeyServerParams;
  90. // Handle to the key that contains the volumes list.
  91. //
  92. HKEY hkeyVolumesList;
  93. // Handle to the key that contains the list of Type/Creator/Comment tupples
  94. //
  95. HKEY hkeyTypeCreators;
  96. // Handle to the key that contains the list mapped extensions.
  97. //
  98. HKEY hkeyExtensions;
  99. // Handle to the key that contains the icon list.
  100. //
  101. HKEY hkeyIcons;
  102. // Service parameters
  103. //
  104. WCHAR wchServerName[AFP_SERVERNAME_LEN+1];
  105. DWORD dwServerOptions;
  106. DWORD dwMaxSessions;
  107. WCHAR wchLoginMsg[AFP_MESSAGE_LEN+1];
  108. DWORD dwMaxPagedMem;
  109. DWORD dwMaxNonPagedMem;
  110. WCHAR wchCodePagePath[MAX_PATH];
  111. // Localizable strings
  112. //
  113. WCHAR wchInvalid[100];
  114. WCHAR wchDeleted[100];
  115. WCHAR wchUnknown[100];
  116. WCHAR wchDefTCComment[AFP_ETC_COMMENT_LEN+1];
  117. // Contains information about what components were initialized
  118. // successfully
  119. //
  120. DWORD dwServerState;
  121. // Handle to the AFP Server FSD
  122. //
  123. HANDLE hFSD;
  124. // Handle used to announce the service status
  125. //
  126. SERVICE_STATUS_HANDLE hServiceStatus;
  127. SERVICE_STATUS ServiceStatus;
  128. // This is a cache of ext/type/creator mappings
  129. //
  130. AFP_ETCMAP_INFO AfpETCMapInfo;
  131. // Will contain the Id of the next type/creator that will be added to the
  132. // registry via the AfpAdminAddETCMap API.
  133. //
  134. DWORD dwCurrentTCId;
  135. // Mutex handle for mutual exclusion around volume SetInfo/ Add/ Delete
  136. // ETC mappings registry and cache operations.
  137. //
  138. HANDLE hmutexETCMap;
  139. // Mutex handle for mutual exclusion around volume SetInfo/ Add/ Delete
  140. // volume registry operations.
  141. //
  142. HANDLE hmutexVolume;
  143. // This will be used by the server helper thread to inicate its
  144. // success or failure while initializing itself. The parent thread
  145. // can then take appropriate action.
  146. //
  147. HANDLE heventSrvrHlprThread;
  148. // This is used by the server helper thread(s) to indicate that they have terminated
  149. //
  150. HANDLE heventSrvrHlprThreadTerminate;
  151. // This is used in special case: if we have to terminate the helper thread when
  152. // it's blocked trying to get domain info
  153. HANDLE heventSrvrHlprSpecial;
  154. DWORD nThreadCount;
  155. DWORD dwSrvrHlprCode;
  156. DWORD dwSrvrHlprCount;
  157. NT_PRODUCT_TYPE NtProductType;
  158. PSID pSidNone;
  159. } AFP_GLOBALS, *PAFP_GLOBALS;
  160. #ifdef DEFINE_AFP_GLOBALS
  161. AFP_GLOBALS AfpGlobals;
  162. HANDLE SfmLsaHandle;
  163. DWORD SfmAuthPkgId;
  164. #else
  165. extern AFP_GLOBALS AfpGlobals;
  166. extern HANDLE SfmLsaHandle;
  167. extern DWORD SfmAuthPkgId;
  168. #endif
  169. // prototypes of functions used across modules
  170. //
  171. VOID
  172. AfpAnnounceServiceStatus(
  173. VOID
  174. );
  175. DWORD
  176. AfpInitialize(
  177. VOID
  178. );
  179. VOID
  180. AfpTerminate(
  181. VOID
  182. );
  183. DWORD
  184. AfpRegGetKeyInfo(
  185. IN HKEY hKey,
  186. OUT LPDWORD lpdwMaxValNameLen, // Longest valuename in this key
  187. OUT LPDWORD lpdwNumValues, // Number of values in this key
  188. OUT LPDWORD lpdwMaxValueDataSize // Max. size of value data.
  189. );
  190. DWORD
  191. AfpRegOpen(
  192. VOID
  193. );
  194. VOID
  195. AfpRegClose(
  196. VOID
  197. );
  198. DWORD
  199. AfpRegVolumeAdd(
  200. IN PAFP_VOLUME_INFO pVolumeInfo
  201. );
  202. DWORD
  203. AfpRegVolumeDelete(
  204. IN LPWSTR lpwsVolumeName
  205. );
  206. DWORD
  207. AfpRegVolumeSetInfo(
  208. IN PAFP_VOLUME_INFO pVolumeInfo
  209. );
  210. DWORD
  211. AfpRegExtensionEnum(
  212. VOID
  213. );
  214. DWORD
  215. AfpRegTypeCreatorEnum(
  216. VOID
  217. );
  218. DWORD
  219. AfpRegExtensionAdd(
  220. IN PAFP_EXTENSION pAfpExtension
  221. );
  222. DWORD
  223. AfpRegExtensionSetInfo(
  224. IN PAFP_EXTENSION pAfpExtension
  225. );
  226. DWORD
  227. AfpRegExtensionDelete(
  228. IN PAFP_EXTENSION pAfpExtension
  229. );
  230. DWORD
  231. AfpRegTypeCreatorSetInfo(
  232. IN PAFP_TYPE_CREATOR pAfpTypeCreator
  233. );
  234. DWORD
  235. AfpRegTypeCreatorAdd(
  236. IN PAFP_TYPE_CREATOR pAfpTypeCreator
  237. );
  238. DWORD
  239. AfpRegTypeCreatorDelete(
  240. IN PAFP_TYPE_CREATOR pAfpTypeCreator
  241. );
  242. DWORD
  243. AfpRegServerGetInfo(
  244. VOID
  245. );
  246. DWORD
  247. AfpRegServerSetInfo(
  248. IN PAFP_SERVER_INFO pServerInfo,
  249. IN DWORD dwParmnum
  250. );
  251. DWORD
  252. AfpRegServerGetCodePagePath(
  253. VOID
  254. );
  255. DWORD
  256. AfpSecObjCreate(
  257. VOID
  258. );
  259. DWORD
  260. AfpSecObjDelete(
  261. VOID
  262. );
  263. DWORD
  264. AfpSecObjAccessCheck(
  265. IN DWORD DesiredAccess,
  266. OUT LPDWORD pfAccessStatus
  267. );
  268. DWORD
  269. AfpBufMakeFSDRequest(
  270. IN LPBYTE pBuffer,
  271. IN DWORD cbReqPktSize,
  272. IN AFP_STRUCTURE_TYPE dwStructureId,
  273. OUT LPBYTE *ppSelfRelativeBuf,
  274. OUT LPDWORD lpdwSelfRelativeBufSize
  275. );
  276. DWORD
  277. AfpBufMakeFSDETCMappings(
  278. OUT PSRVETCPKT *ppSrvSetEtc,
  279. OUT LPDWORD lpdwSrvSetEtcBufSize
  280. );
  281. VOID
  282. AfpBufOffsetToPointer(
  283. IN OUT LPBYTE pBuffer,
  284. IN DWORD dwNumEntries,
  285. IN AFP_STRUCTURE_TYPE dwStructureType
  286. );
  287. VOID
  288. AfpBufCopyFSDETCMapInfo(
  289. IN PAFP_TYPE_CREATOR pAfpTypeCreator,
  290. IN PAFP_EXTENSION pAfpExtension,
  291. OUT PETCMAPINFO2 pFSDETCMapInfo
  292. );
  293. VOID
  294. AfpBufMakeFSDIcon(
  295. IN PAFP_ICON_INFO pIconInfo,
  296. OUT LPBYTE lpbFSDIcon,
  297. OUT LPDWORD lpcbFSDIconSize
  298. );
  299. DWORD
  300. AfpBufMakeMultiSz(
  301. IN AFP_STRUCTURE_TYPE dwStructureId,
  302. IN LPBYTE pbStructure,
  303. OUT LPBYTE* ppbMultiSz,
  304. OUT LPDWORD lpdwMultiSzSize
  305. );
  306. DWORD
  307. AfpBufParseMultiSz(
  308. IN AFP_STRUCTURE_TYPE dwStructureId,
  309. IN LPBYTE pbMultiSz,
  310. OUT LPBYTE pbStructure
  311. );
  312. DWORD
  313. AfpBufStructureSize(
  314. IN AFP_STRUCTURE_TYPE dwStructureId,
  315. IN LPBYTE lpbStructure
  316. );
  317. DWORD
  318. AfpBufUnicodeToNibble(
  319. IN OUT LPWSTR lpwsData
  320. );
  321. void *
  322. AfpBinarySearch(
  323. IN const void * pKey,
  324. IN const void * pBase,
  325. IN size_t num,
  326. IN size_t width,
  327. IN int (_cdecl *compare)(const void * pElem1, const void * pElem2 )
  328. );
  329. int
  330. _cdecl
  331. AfpBCompareTypeCreator(
  332. IN const void * pAfpTypeCreator1,
  333. IN const void * pAfpTypeCreatro2
  334. );
  335. int
  336. _cdecl
  337. AfpLCompareTypeCreator(
  338. IN const void * pAfpTypeCreator1,
  339. IN const void * pAfpTypeCreatro2
  340. );
  341. int
  342. _cdecl
  343. AfpBCompareExtension(
  344. IN const void * pAfpExtension1,
  345. IN const void * pAfpExtension2
  346. );
  347. int
  348. _cdecl
  349. AfpLCompareExtension(
  350. IN const void * pAfpExtension1,
  351. IN const void * pAfpExtension2
  352. );
  353. DWORD
  354. AfpFSDOpen(
  355. OUT PHANDLE pFSD
  356. );
  357. DWORD
  358. AfpFSDClose(
  359. IN HANDLE hFSD
  360. );
  361. DWORD
  362. AfpFSDUnload(
  363. VOID
  364. );
  365. DWORD
  366. AfpFSDLoad(
  367. VOID
  368. );
  369. DWORD
  370. AfpFSDIOControl(
  371. IN HANDLE hFSD,
  372. IN DWORD dwOpCode,
  373. IN PVOID pInbuf OPTIONAL,
  374. IN DWORD cbInbufLen,
  375. OUT PVOID pOutbuf OPTIONAL,
  376. IN DWORD cbOutbuflen,
  377. OUT LPDWORD cbBytesTransferred
  378. );
  379. DWORD
  380. AfpCreateServerHelperThread(
  381. BOOL fIsFirstThread
  382. );
  383. VOID
  384. AfpTerminateCurrentThread(
  385. VOID
  386. );
  387. DWORD
  388. AfpInitServerHelper(
  389. VOID
  390. );
  391. DWORD
  392. AfpServerHelper(
  393. IN LPVOID Parameter
  394. );
  395. VOID
  396. AfpLogEvent(
  397. IN DWORD dwMessageId,
  398. IN WORD cNumberOfSubStrings,
  399. IN LPWSTR* plpwsSubStrings,
  400. IN DWORD dwErrorCode,
  401. IN WORD wSeverity
  402. );
  403. VOID
  404. AfpLogServerEvent(
  405. IN PAFP_FSD_CMD_PKT pAfpFsdCmd
  406. );
  407. VOID
  408. AfpAddInvalidVolume(
  409. IN LPWSTR lpwsName,
  410. IN LPWSTR lpwsPath
  411. );
  412. VOID
  413. AfpDeleteInvalidVolume(
  414. IN LPWSTR lpwsVolumeName
  415. );
  416. DWORD
  417. I_DirectorySetInfo(
  418. IN PAFP_DIRECTORY_INFO pAfpDirectoryInfo,
  419. IN DWORD dwParmNum
  420. );
  421. DWORD
  422. I_DirectoryGetInfo(
  423. IN LPWSTR lpwsPath,
  424. OUT PAFP_DIRECTORY_INFO * ppAfpDirectoryInfo
  425. );
  426. #endif // _AFPSVCP_
  427. 
  428.