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.

575 lines
13 KiB

  1. /*++
  2. Copyright (c) 1991-1992 Microsoft Corporation
  3. Module Name:
  4. SrvSvcP.h
  5. Abstract:
  6. This is the header file for the NT server service.
  7. Author:
  8. David Treadwell (davidtr) 10-Jan-1991
  9. Revision History:
  10. --*/
  11. #ifndef _SRVSVCP_
  12. #define _SRVSVCP_
  13. #include <nt.h>
  14. #include <ntrtl.h>
  15. #include <nturtl.h>
  16. #include <windows.h>
  17. #include <rpc.h>
  18. #include <lmcons.h>
  19. #include <secobj.h>
  20. #include <ntlsapi.h>
  21. #include <srvfsctl.h>
  22. #include <srvsvc.h>
  23. #include <svcs.h>
  24. #include <winreg.h>
  25. //
  26. // Include Safe String Functions, but still use depreciated ones in
  27. // unmodified code
  28. //
  29. #define STRSAFE_NO_DEPRECATE
  30. #include <strsafe.h>
  31. #include "ssdebug.h"
  32. #include "sssec.h"
  33. //
  34. // String constants.
  35. //
  36. #define IPC_SHARE_NAME TEXT("IPC$")
  37. #define ADMIN_SHARE_NAME TEXT("ADMIN$")
  38. #define SRVSVC_MAX_NUMBER_OF_DISKS 26
  39. //
  40. // Internationalizable strings
  41. //
  42. extern LPWSTR SsAdminShareRemark ;
  43. extern LPWSTR SsIPCShareRemark ;
  44. extern LPWSTR SsDiskAdminShareRemark ;
  45. //
  46. // Bits of server type (in announcement messages) that can only be set
  47. // by the server itself -- not by services via the internal API
  48. // I_NetServerSetServiceBits.
  49. //
  50. // SV_TYPE_TIME_SOURCE is a pseudo internal bit. It can be set internally or
  51. // it can be set by the w32time service.
  52. //
  53. #define SERVER_TYPE_INTERNAL_BITS (SV_TYPE_SERVER | \
  54. SV_TYPE_PRINTQ_SERVER | \
  55. SV_TYPE_NT | \
  56. SV_TYPE_DFS)
  57. //
  58. // INITIAL_BUFFER_SIZE is the buffer size that GetInfo and Enum requests
  59. // first try to fill. If this buffer isn't large enough, they allocate
  60. // a buffer large enough to hold all the information plus a fudge factor,
  61. // EXTRA_ALLOCATION.
  62. //
  63. #define INITIAL_BUFFER_SIZE (ULONG)8192
  64. #define EXTRA_ALLOCATION 1024
  65. //
  66. // ServerProductName in SERVER_SERVICE_DATA is the name passed to the
  67. // Licensing DLL as the name of this service. MAXPRODNAME is the max
  68. // number of characters in the service name.
  69. #define SERVER_PRODUCT_NAME L"SMBServer"
  70. // szVersionNumber in SERVER_SERVICE_DATA is the version string passed
  71. // to the Licensing DLL as the vesion of this service. MAXVERSIONSZ
  72. // is the max number of characters for the version string
  73. #define MAXVERSIONSZ 10
  74. //
  75. // Structures used to hold transport specific server type bits
  76. //
  77. typedef struct _TRANSPORT_LIST_ENTRY {
  78. struct _TRANSPORT_LIST_ENTRY *Next;
  79. LPWSTR TransportName; // device name for xport
  80. DWORD ServiceBits; // SV... announce bits
  81. } TRANSPORT_LIST_ENTRY, *PTRANSPORT_LIST_ENTRY;
  82. typedef struct _NAME_LIST_ENTRY {
  83. struct _NAME_LIST_ENTRY *Next;
  84. CHAR TransportAddress[ MAX_PATH ]; // address of this server
  85. ULONG TransportAddressLength;
  86. LPWSTR DomainName; // name of the domain
  87. DWORD ServiceBits; // SV... announce bits
  88. struct {
  89. ULONG PrimaryName: 1; // Is this the server's primary name?
  90. };
  91. PTRANSPORT_LIST_ENTRY Transports;
  92. } NAME_LIST_ENTRY, *PNAME_LIST_ENTRY;
  93. //
  94. // Structure for server service global data.
  95. //
  96. typedef struct _SERVER_SERVICE_DATA {
  97. SERVER_INFO_102 ServerInfo102;
  98. SERVER_INFO_599 ServerInfo599;
  99. SERVER_INFO_598 ServerInfo598;
  100. //
  101. // Handle for accessing the server.
  102. //
  103. HANDLE SsServerDeviceHandle;
  104. //
  105. // Pointer to global data made available by SVCS main image.
  106. //
  107. PSVCHOST_GLOBAL_DATA SsLmsvcsGlobalData;
  108. //
  109. // Resource for synchronizing access to server info.
  110. //
  111. RTL_RESOURCE SsServerInfoResource;
  112. BOOL SsServerInfoResourceInitialized;
  113. //
  114. // Boolean indicating whether the server service is initialized.
  115. //
  116. BOOL SsInitialized;
  117. //
  118. // Boolean indicating whether the kernel-mode server FSP has been
  119. // started.
  120. //
  121. BOOL SsServerFspStarted;
  122. //
  123. // Event used for synchronizing server service termination.
  124. //
  125. HANDLE SsTerminationEvent;
  126. //
  127. // Event used for forcing the server to announce itself on the network from
  128. // remote clients.
  129. //
  130. HANDLE SsAnnouncementEvent;
  131. //
  132. // Event used for forcing the server to announce itself on the network from
  133. // inside the server service.
  134. //
  135. HANDLE SsStatusChangedEvent;
  136. //
  137. // Event used to detect domain name changes
  138. //
  139. HANDLE SsDomainNameChangeEvent;
  140. //
  141. // Name of this computer in OEM format.
  142. //
  143. CHAR SsServerTransportAddress[ MAX_PATH ];
  144. ULONG SsServerTransportAddressLength;
  145. //
  146. // List containing transport specific service names and bits
  147. //
  148. PNAME_LIST_ENTRY SsServerNameList;
  149. //
  150. // If we are asked to set some service bits before we've bound to
  151. // any transports, we need to save those bits here and use them later
  152. // when we finally do bind to transports.
  153. //
  154. DWORD ServiceBits;
  155. BOOLEAN IsDfsRoot; // TRUE if we are the root of a DFS tree
  156. UNICODE_STRING ServerAnnounceName;
  157. LONG NumberOfPrintShares;
  158. WCHAR ServerNameBuffer[MAX_PATH];
  159. WCHAR AnnounceNameBuffer[MAX_PATH];
  160. WCHAR ServerCommentBuffer[MAXCOMMENTSZ+1];
  161. WCHAR UserPathBuffer[MAX_PATH+1];
  162. WCHAR DomainNameBuffer[MAX_PATH];
  163. WCHAR ServerProductName[ sizeof( SERVER_PRODUCT_NAME ) ];
  164. WCHAR szVersionNumber[ MAXVERSIONSZ+1 ];
  165. //
  166. // Number of XACTSRV worker threads.
  167. //
  168. LONG XsThreads;
  169. //
  170. // This is the number of Xs threads blocked waiting for an LPC request.
  171. // When it drops to zero, all threads are active and another thread is
  172. // created.
  173. //
  174. LONG XsWaitingApiThreads;
  175. //
  176. // Event signalled when the last XACTSRV worker thread terminates.
  177. //
  178. HANDLE XsAllThreadsTerminatedEvent;
  179. //
  180. // Boolean indicating whether XACTSRV is active or terminating.
  181. //
  182. BOOL XsTerminating;
  183. //
  184. // Handle for the LPC port used for communication between the file server
  185. // and XACTSRV.
  186. //
  187. HANDLE XsConnectionPortHandle;
  188. HANDLE XsCommunicationPortHandle;
  189. //
  190. // Handle to the NTLSAPI.DLL library
  191. //
  192. HMODULE XsLicenseLibrary;
  193. //
  194. // Entry point for obtaining a client license
  195. //
  196. PNT_LICENSE_REQUEST_W SsLicenseRequest;
  197. //
  198. // Entry point for freeing a client license
  199. //
  200. PNT_LS_FREE_HANDLE SsFreeLicense;
  201. //
  202. // Handle to the XACT library
  203. //
  204. HMODULE XsXactsrvLibrary;
  205. BOOL ApiThreadsStarted;
  206. //
  207. // This resource is used to ensure that more than one thread aren't trying
  208. // to load the xactsrv library at the same time.
  209. //
  210. BOOL LibraryResourceInitialized;
  211. RTL_RESOURCE LibraryResource;
  212. } SERVER_SERVICE_DATA, *PSERVER_SERVICE_DATA;
  213. extern SERVER_SERVICE_DATA SsData;
  214. //
  215. // Structure type used for generalized switch matching.
  216. //
  217. typedef struct _FIELD_DESCRIPTOR {
  218. LPWCH FieldName;
  219. ULONG FieldType;
  220. ULONG FieldOffset;
  221. ULONG Level;
  222. DWORD ParameterNumber;
  223. ULONG Settable;
  224. DWORD_PTR DefaultValue;
  225. DWORD MinimumValue;
  226. DWORD MaximumValue;
  227. } FIELD_DESCRIPTOR, *PFIELD_DESCRIPTOR;
  228. //
  229. // Used by NetrShareEnumSticky to get share information from the registry.
  230. //
  231. typedef struct _SRVSVC_SHARE_ENUM_INFO {
  232. ULONG Level;
  233. ULONG ResumeHandle;
  234. ULONG EntriesRead;
  235. ULONG TotalEntries;
  236. ULONG TotalBytesNeeded;
  237. PVOID OutputBuffer;
  238. ULONG OutputBufferLength;
  239. //
  240. // Scratch fields used by SsEnumerateStickyShares
  241. //
  242. ULONG ShareEnumIndex;
  243. PCHAR StartOfFixedData;
  244. PCHAR EndOfVariableData;
  245. } SRVSVC_SHARE_ENUM_INFO, *PSRVSVC_SHARE_ENUM_INFO;
  246. //
  247. // Internal structure used for two-step delete of share's
  248. //
  249. typedef struct _SHARE_DEL_CONTEXT {
  250. struct _SHARE_DEL_CONTEXT* Next;
  251. SERVER_REQUEST_PACKET Srp;
  252. BOOL IsPrintShare;
  253. BOOL IsSpecial;
  254. //WCHAR NetName[];
  255. } SHARE_DEL_CONTEXT, *PSHARE_DEL_CONTEXT;
  256. //
  257. // Manifests that determine field type.
  258. //
  259. #define BOOLEAN_FIELD 0
  260. #define DWORD_FIELD 1
  261. #define LPSTR_FIELD 2
  262. //
  263. // Manifests that determine when a field may be set.
  264. //
  265. #define NOT_SETTABLE 0
  266. #define SET_ON_STARTUP 1
  267. #define ALWAYS_SETTABLE 2
  268. //
  269. // Data for all server info fields.
  270. //
  271. extern FIELD_DESCRIPTOR SsServerInfoFields[];
  272. extern VOID SsInitializeServerInfoFields( VOID );
  273. //
  274. // Macros.
  275. //
  276. #define POINTER_TO_OFFSET(val,start) \
  277. (val) = (val) == NULL ? NULL : (PVOID)( (PCHAR)(val) - (ULONG_PTR)(start) )
  278. #define OFFSET_TO_POINTER(val,start) \
  279. (val) = (val) == NULL ? NULL : (PVOID)( (PCHAR)(val) + (ULONG_PTR)(start) )
  280. #define FIXED_SIZE_OF_SHARE(level) \
  281. ( (level) == 0 ? sizeof(SHARE_INFO_0) : \
  282. (level) == 1 ? sizeof(SHARE_INFO_1) : \
  283. (level) == 2 ? sizeof(SHARE_INFO_2) : \
  284. sizeof(SHARE_INFO_502) )
  285. #define SIZE_WSTR( Str ) \
  286. ( ( Str ) == NULL ? 0 : ((wcslen( Str ) + 1) * sizeof(WCHAR)) )
  287. //
  288. // Internal routine prototypes.
  289. //
  290. PSERVER_REQUEST_PACKET
  291. SsAllocateSrp (
  292. VOID
  293. );
  294. NET_API_STATUS
  295. SsCheckAccess (
  296. IN PSRVSVC_SECURITY_OBJECT SecurityObject,
  297. IN ACCESS_MASK DesiredAccess
  298. );
  299. VOID
  300. SsCloseServer (
  301. VOID
  302. );
  303. VOID
  304. SsControlCHandler (
  305. IN ULONG CtrlType
  306. );
  307. NET_API_STATUS
  308. SsCreateSecurityObjects (
  309. VOID
  310. );
  311. VOID
  312. SsDeleteSecurityObjects (
  313. VOID
  314. );
  315. VOID
  316. SsFreeSrp (
  317. IN PSERVER_REQUEST_PACKET Srp
  318. );
  319. NET_API_STATUS
  320. SsInitialize (
  321. IN DWORD argc,
  322. IN LPTSTR argv[]
  323. );
  324. VOID
  325. SsLogEvent(
  326. IN DWORD MessageId,
  327. IN DWORD NumberOfSubStrings,
  328. IN LPWSTR *SubStrings,
  329. IN DWORD ErrorCode
  330. );
  331. NET_API_STATUS
  332. SsOpenServer ( void );
  333. NET_API_STATUS
  334. SsParseCommandLine (
  335. IN DWORD argc,
  336. IN LPTSTR argv[],
  337. IN BOOLEAN Starting
  338. );
  339. DWORD
  340. SsScavengerThread (
  341. IN LPVOID lpThreadParameter
  342. );
  343. NET_API_STATUS
  344. SsServerFsControlGetInfo (
  345. IN ULONG ServerControlCode,
  346. IN PSERVER_REQUEST_PACKET Srp,
  347. IN OUT PVOID *OutputBuffer,
  348. IN OUT ULONG OutputBufferLength
  349. );
  350. NET_API_STATUS
  351. SsServerFsControl (
  352. IN ULONG ServerControlCode,
  353. IN PSERVER_REQUEST_PACKET Srp,
  354. IN PVOID Buffer OPTIONAL,
  355. IN ULONG BufferLength
  356. );
  357. DWORD
  358. SsGetServerType (
  359. VOID
  360. );
  361. VOID
  362. SsSetExportedServerType (
  363. IN PNAME_LIST_ENTRY Service OPTIONAL,
  364. IN BOOL ExternalBitsAlreadyChanged,
  365. IN BOOL UpdateImmediately
  366. );
  367. NET_API_STATUS
  368. SsSetField (
  369. IN PFIELD_DESCRIPTOR Field,
  370. IN PVOID Value,
  371. IN BOOLEAN WriteToRegistry,
  372. OUT BOOLEAN *AnnouncementInformationChanged OPTIONAL
  373. );
  374. UINT
  375. SsGetDriveType (
  376. IN LPWSTR path
  377. );
  378. NET_API_STATUS
  379. SsTerminate (
  380. VOID
  381. );
  382. DWORD
  383. SsAtol (
  384. IN LPTSTR Input
  385. );
  386. VOID
  387. SsNotifyRdrOfGuid(
  388. LPGUID Guid
  389. );
  390. VOID
  391. AnnounceServiceStatus (
  392. DWORD increment
  393. );
  394. VOID
  395. BindToTransport (
  396. IN PVOID TransportName
  397. );
  398. VOID
  399. BindOptionalNames (
  400. IN PWSTR TransportName
  401. );
  402. NET_API_STATUS NET_API_FUNCTION
  403. I_NetrServerTransportAddEx (
  404. IN DWORD Level,
  405. IN LPTRANSPORT_INFO Buffer
  406. );
  407. VOID
  408. I_NetServerTransportDel(
  409. IN PUNICODE_STRING TransportName
  410. );
  411. NET_API_STATUS
  412. StartPnpNotifications (
  413. VOID
  414. );
  415. NET_API_STATUS NET_API_FUNCTION
  416. I_NetrShareDelStart (
  417. IN LPWSTR ServerName,
  418. IN LPWSTR NetName,
  419. IN DWORD Reserved,
  420. IN PSHARE_DEL_HANDLE ContextHandle,
  421. IN BOOLEAN CheckAccess
  422. );
  423. NET_API_STATUS NET_API_FUNCTION
  424. I_NetrShareAdd (
  425. IN LPWSTR ServerName,
  426. IN DWORD Level,
  427. IN LPSHARE_INFO Buffer,
  428. OUT LPDWORD ErrorParameter,
  429. IN BOOLEAN BypassSecurity
  430. );
  431. //
  432. // XACTSRV functions.
  433. //
  434. DWORD
  435. XsStartXactsrv (
  436. VOID
  437. );
  438. VOID
  439. XsStopXactsrv (
  440. VOID
  441. );
  442. NET_API_STATUS
  443. ShareEnumCommon (
  444. IN DWORD Level,
  445. OUT LPBYTE *Buffer,
  446. IN DWORD PreferredMaximumLength,
  447. OUT LPDWORD EntriesRead,
  448. OUT LPDWORD TotalEntries,
  449. IN OUT LPDWORD ResumeHandle OPTIONAL,
  450. IN LPWSTR NetName OPTIONAL
  451. );
  452. NET_API_STATUS
  453. ConvertStringToTransportAddress (
  454. IN PUNICODE_STRING InputName,
  455. OUT CHAR TransportAddress[MAX_PATH],
  456. OUT PULONG TransportAddressLength
  457. );
  458. VOID
  459. SsSetDfsRoot();
  460. VOID
  461. SsSetDomainName (
  462. VOID
  463. );
  464. #endif // ndef _SRVSVCP_