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.

490 lines
13 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. mprdata.h
  5. Abstract:
  6. Contains data structures and function prototypes that are internal to
  7. MPR.
  8. Author:
  9. Dan Lafferty (danl) 07-Sept-1991
  10. Environment:
  11. User Mode -Win32
  12. Revision History:
  13. 05-May-1999 jschwart
  14. Make provider addition/removal dynamic
  15. 01-Mar-1994 Danl
  16. Created a separate location for the Credential Managers GetCaps()
  17. function. This way if a provider has both a credential manager
  18. dll and a network dll, we will be able to direct calls to the
  19. correct GetCaps() function.
  20. 07-Jan-1993 Danl
  21. Add NPLogonNotify and NPPasswordChangeNotify and AuthentDllName
  22. to PROVIDER structure. Also added CREDENTIAL_TYPE InitClass.
  23. 04-Aug-1992 chuckc
  24. added MprEnterLoadLibCritSect, MprLeaveLoadLibCritSect.
  25. 07-Sept-1991 danl
  26. created
  27. --*/
  28. //
  29. // Includes
  30. //
  31. //=======================
  32. // Data Structures
  33. //=======================
  34. typedef struct _PROVIDER {
  35. NETRESOURCE Resource;
  36. DWORD Type; // WNNC_NET_MSNet, WNNC_NET_LanMan, WNNC_NET_NetWare
  37. HMODULE Handle; // Handle to the provider DLL.
  38. LPTSTR DllName; // set to NULL after loaded.
  39. HMODULE AuthentHandle; // Handle to authenticator DLL.
  40. LPTSTR AuthentDllName; // Authenticator Dll.
  41. DWORD InitClass; // Network or Authentication provider.
  42. DWORD ConnectCaps; // Cached result of GetCaps(WNNC_CONNECTION)
  43. DWORD ConnectFlagCaps;// Cached result of GetCaps(WNNC_CONNECTION_FLAGS)
  44. PF_NPAddConnection AddConnection;
  45. PF_NPAddConnection3 AddConnection3;
  46. PF_NPGetReconnectFlags GetReconnectFlags;
  47. PF_NPCancelConnection CancelConnection;
  48. PF_NPGetConnection GetConnection;
  49. PF_NPGetConnection3 GetConnection3;
  50. PF_NPGetUser GetUser;
  51. PF_NPOpenEnum OpenEnum;
  52. PF_NPEnumResource EnumResource;
  53. PF_NPCloseEnum CloseEnum;
  54. PF_NPGetCaps GetCaps;
  55. PF_NPGetDirectoryType GetDirectoryType;
  56. PF_NPDirectoryNotify DirectoryNotify;
  57. PF_NPPropertyDialog PropertyDialog;
  58. PF_NPGetPropertyText GetPropertyText;
  59. PF_NPSearchDialog SearchDialog;
  60. PF_NPFormatNetworkName FormatNetworkName;
  61. PF_NPLogonNotify LogonNotify;
  62. PF_NPPasswordChangeNotify PasswordChangeNotify;
  63. PF_NPGetCaps GetAuthentCaps;
  64. PF_NPFMXGetPermCaps FMXGetPermCaps;
  65. PF_NPFMXEditPerm FMXEditPerm;
  66. PF_NPFMXGetPermHelp FMXGetPermHelp;
  67. PF_NPGetUniversalName GetUniversalName;
  68. PF_NPGetResourceParent GetResourceParent;
  69. PF_NPGetResourceInformation GetResourceInformation;
  70. PF_NPGetConnectionPerformance GetConnectionPerformance;
  71. }PROVIDER, *LPPROVIDER;
  72. //=======================
  73. // MACROS
  74. //=======================
  75. #define IS_EMPTY_STRING(pch) ( !pch || !*(pch) )
  76. #define LENGTH(array) (sizeof(array)/sizeof((array)[0]))
  77. #define INIT_IF_NECESSARY(level,status) ASSERT(MPRProviderLock.Have()); \
  78. if(!(GlobalInitLevel & level)) { \
  79. status = MprLevel2Init(level); \
  80. if (status != WN_SUCCESS) { \
  81. SetLastError(status); \
  82. return(status); \
  83. } \
  84. }
  85. #define MPR_IS_INITIALIZED(level) (GlobalInitLevel & level ## _LEVEL)
  86. #define ASSERT_INITIALIZED(level) ASSERT(MPR_IS_INITIALIZED(level) && \
  87. MPRProviderLock.Have());
  88. #define MPR_EXCEPTION_FILTER (GetExceptionCode() == STATUS_POSSIBLE_DEADLOCK ? \
  89. EXCEPTION_CONTINUE_SEARCH : EXCEPTION_EXECUTE_HANDLER)
  90. //=======================
  91. // INLINE FUNCTIONS
  92. //=======================
  93. inline void
  94. PROBE_FOR_WRITE(
  95. LPDWORD pdw
  96. )
  97. // WARNING: This function can throw an exception. It must be called from
  98. // within a try-except block.
  99. {
  100. *(volatile DWORD *)pdw = *(volatile DWORD *)pdw;
  101. }
  102. inline BOOL
  103. IS_BAD_BYTE_BUFFER(
  104. LPVOID lpBuffer,
  105. LPDWORD lpBufferSize // in bytes
  106. )
  107. // WARNING: This function can throw an exception. It must be called from
  108. // within a try-except block.
  109. {
  110. PROBE_FOR_WRITE(lpBufferSize);
  111. return IsBadWritePtr(lpBuffer, *lpBufferSize);
  112. }
  113. inline BOOL
  114. IS_BAD_WCHAR_BUFFER(
  115. LPVOID lpBuffer,
  116. LPDWORD lpBufferSize // in Unicode characters
  117. )
  118. // WARNING: This function can throw an exception. It must be called from
  119. // within a try-except block.
  120. {
  121. PROBE_FOR_WRITE(lpBufferSize);
  122. return IsBadWritePtr(lpBuffer, *lpBufferSize * sizeof(WCHAR));
  123. }
  124. //=======================
  125. // CONSTANTS
  126. //=======================
  127. #define DEFAULT_MAX_PROVIDERS 25
  128. // Bit masks for remembering error codes
  129. #define BAD_NAME 0x00000001
  130. #define NO_NET 0x00000002
  131. #define NOT_CONNECTED 0x00000004
  132. #define NOT_CONTAINER 0x00000008
  133. #define NO_DEVICES 0x00000010
  134. #define OTHER_ERRS 0xFFFFFFFF
  135. #define REDIR_DEVICE 0x00000001
  136. #define REMOTE_NAME 0x00000002
  137. #define LOCAL_NAME REDIR_DEVICE
  138. #define DA_READ 0x00000001
  139. #define DA_WRITE 0x00000002
  140. #define DA_DELETE 0x00000004
  141. //
  142. // Timeout values for restoring connections and notifying
  143. // Credential Managers.
  144. //
  145. #define DEFAULT_WAIT_TIME 60000 // Default timeout if providers don't
  146. // specify.
  147. #define MAX_ALLOWED_WAIT_TIME 300000 // Max timeout a provider can specify
  148. #define RECONNECT_SLEEP_INCREMENT 3000 // number of seconds to sleep
  149. #define PROVIDER_WILL_NOT_START 0x00000000 // The provider will not be starting
  150. #define NO_TIME_ESTIMATE 0xffffffff // The provider cannot predict the
  151. // amount of time it will take to
  152. // start.
  153. #define NET_PROVIDER_KEY TEXT("system\\CurrentControlSet\\Control\\NetworkProvider")
  154. #define RESTORE_WAIT_VALUE TEXT("RestoreTimeout")
  155. #define RESTORE_CONNECTION_VALUE TEXT("RestoreConnection")
  156. #define DEFER_CONNECTION_VALUE TEXT("DeferConnection")
  157. //
  158. // GlobalInitLevels & InitClasses
  159. //
  160. // NOTE: The WN_???_CLASS values are bit masks.
  161. //
  162. // GlobalInitLevel
  163. #define FIRST_LEVEL 0x00000001
  164. #define NETWORK_LEVEL 0x00000002
  165. #define CREDENTIAL_LEVEL 0x00000004
  166. #define NOTIFIEE_LEVEL 0x00000008
  167. //
  168. //
  169. // InitClasses
  170. #define NETWORK_TYPE WN_NETWORK_CLASS
  171. #define CREDENTIAL_TYPE (WN_CREDENTIAL_CLASS | WN_PRIMARY_AUTHENT_CLASS)
  172. // The path in the registry for user's persistent connections is found in
  173. // the following key:
  174. //
  175. // "\HKEY_CURRENT_USER\Network"
  176. //
  177. // Subkeys of the network section listed by local drive names. These
  178. // keys contain the following values:
  179. // RemotePath, Type, ProviderName, UserName
  180. //
  181. // d: RemotePath = \\cyclops\scratch
  182. // Type = RESOURCE_TYPE_DISK
  183. // ProviderName = LanMan
  184. // UserName = Ernie
  185. #define CONNECTION_KEY_NAME TEXT("Network")
  186. #define REMOTE_PATH_NAME TEXT("RemotePath")
  187. #define USER_NAME TEXT("UserName")
  188. #define PROVIDER_NAME TEXT("ProviderName")
  189. #define PROVIDER_TYPE TEXT("ProviderType")
  190. #define PROVIDER_FLAGS TEXT("ProviderFlags")
  191. #define DEFER_FLAGS TEXT("DeferFlags")
  192. #define CONNECTION_TYPE TEXT("ConnectionType")
  193. #define PRINT_CONNECTION_KEY_NAME TEXT("Printers\\RestoredConnections")
  194. //=======================
  195. // Global data
  196. //=======================
  197. extern LPPROVIDER GlobalProviderInfo; // pArray of PROVIDER Structures
  198. extern DWORD GlobalNumProviders;
  199. extern DWORD MprDebugLevel;
  200. extern HANDLE MprLoadLibSemaphore; // used to protect DLL handles
  201. extern volatile DWORD GlobalInitLevel;
  202. extern CRITICAL_SECTION MprErrorRecCritSec;
  203. extern WCHAR g_wszEntireNetwork[40];
  204. //==========================
  205. // Functions from support.c
  206. //==========================
  207. VOID
  208. MprDeleteIndexArray(
  209. VOID
  210. );
  211. DWORD
  212. MprFindCallOrder(
  213. IN LPTSTR NameInfo,
  214. OUT LPDWORD *IndexArrayPtr,
  215. OUT LPDWORD IndexArrayCount,
  216. IN DWORD InitClass
  217. );
  218. DWORD
  219. MprDeviceType(
  220. IN LPCTSTR DeviceName
  221. );
  222. BOOL
  223. MprGetProviderIndex(
  224. IN LPCTSTR ProviderName,
  225. OUT LPDWORD IndexPtr
  226. );
  227. LPPROVIDER
  228. MprFindProviderByName(
  229. IN LPCWSTR ProviderName
  230. );
  231. LPPROVIDER
  232. MprFindProviderByType(
  233. IN DWORD ProviderType
  234. );
  235. DWORD
  236. MprFindProviderForPath(
  237. IN LPWSTR lpPathName,
  238. OUT LPDWORD lpProviderIndex
  239. );
  240. VOID
  241. MprInitIndexArray(
  242. LPDWORD IndexArray,
  243. DWORD NumEntries
  244. );
  245. VOID
  246. MprEndCallOrder(
  247. VOID
  248. );
  249. VOID
  250. MprFreeAllErrorRecords(
  251. VOID
  252. );
  253. BOOL
  254. MprNetIsAvailable(
  255. VOID) ;
  256. //=========================
  257. // Functions from mprreg.c
  258. //=========================
  259. BOOL
  260. MprOpenKey(
  261. HKEY hKey,
  262. LPTSTR lpSubKey,
  263. PHKEY phKeyHandle,
  264. DWORD desiredAccess
  265. );
  266. BOOL
  267. MprGetKeyValue(
  268. HKEY KeyHandle,
  269. LPTSTR ValueName,
  270. LPTSTR *ValueString
  271. );
  272. BOOL
  273. MprGetKeyDwordValue(
  274. IN HKEY KeyHandle,
  275. IN LPCWSTR ValueName,
  276. OUT DWORD * Value
  277. );
  278. LONG
  279. MprGetKeyNumberValue(
  280. IN HKEY KeyHandle,
  281. IN LPCWSTR ValueName,
  282. IN LONG Default
  283. );
  284. DWORD
  285. MprEnumKey(
  286. IN HKEY KeyHandle,
  287. IN DWORD SubKeyIndex,
  288. OUT LPTSTR *SubKeyName,
  289. IN DWORD MaxSubKeyNameLen
  290. );
  291. BOOL
  292. MprGetKeyInfo(
  293. IN HKEY KeyHandle,
  294. OUT LPDWORD TitleIndex OPTIONAL,
  295. OUT LPDWORD NumSubKeys,
  296. OUT LPDWORD MaxSubKeyLen,
  297. OUT LPDWORD NumValues OPTIONAL,
  298. OUT LPDWORD MaxValueLen
  299. );
  300. DWORD MprGetPrintKeyInfo(HKEY KeyHandle,
  301. LPDWORD NumValueNames,
  302. LPDWORD MaxValueNameLength,
  303. LPDWORD MaxValueLen) ;
  304. BOOL
  305. MprFindDriveInRegistry (
  306. IN LPCTSTR DriveName,
  307. OUT LPTSTR *RemoteName
  308. );
  309. DWORD
  310. MprSaveDeferFlags(
  311. IN HKEY RegKey,
  312. IN DWORD DeferFlags
  313. );
  314. DWORD
  315. MprSetRegValue(
  316. IN HKEY KeyHandle,
  317. IN LPTSTR ValueName,
  318. IN LPCTSTR ValueString,
  319. IN DWORD LongValue
  320. );
  321. DWORD
  322. MprCreateRegKey(
  323. IN HKEY BaseKeyHandle,
  324. IN LPCTSTR KeyName,
  325. OUT PHKEY KeyHandlePtr
  326. );
  327. BOOL
  328. MprReadConnectionInfo(
  329. IN HKEY KeyHandle,
  330. IN LPCTSTR DriveName,
  331. IN DWORD Index,
  332. OUT LPDWORD ProviderFlags,
  333. OUT LPDWORD DeferFlags,
  334. OUT LPTSTR *UserNamePtr,
  335. OUT LPNETRESOURCEW NetResource,
  336. OUT HKEY *SubKeyHandleOut,
  337. IN DWORD MaxSubKeyLen
  338. );
  339. VOID
  340. MprForgetRedirConnection(
  341. IN LPCTSTR lpName
  342. );
  343. DWORD
  344. MprForgetPrintConnection(
  345. IN LPTSTR lpName
  346. );
  347. BOOL
  348. MprGetRemoteName(
  349. IN LPTSTR lpLocalName,
  350. IN OUT LPDWORD lpBufferSize,
  351. OUT LPTSTR lpRemoteName,
  352. OUT LPDWORD lpStatus
  353. ) ;
  354. //=========================
  355. // Functions from strbuf.c
  356. //=========================
  357. BOOL
  358. NetpCopyStringToBuffer (
  359. IN LPWSTR String OPTIONAL,
  360. IN DWORD CharacterCount,
  361. IN LPWSTR FixedDataEnd,
  362. IN OUT LPWSTR *EndOfVariableData,
  363. OUT LPWSTR *VariableDataPointer
  364. );
  365. //=========================
  366. // Other functions
  367. //=========================
  368. VOID
  369. MprCheckProviders(
  370. VOID
  371. );
  372. DWORD
  373. MprLevel1Init(
  374. VOID
  375. );
  376. DWORD
  377. MprLevel2Init(
  378. DWORD InitClass
  379. );
  380. DWORD
  381. MprEnterLoadLibCritSect (
  382. VOID
  383. ) ;
  384. DWORD
  385. MprLeaveLoadLibCritSect (
  386. VOID
  387. ) ;
  388. VOID
  389. MprClearString (
  390. LPWSTR lpString
  391. ) ;
  392. DWORD
  393. MprGetConnection (
  394. IN LPCWSTR lpLocalName,
  395. OUT LPWSTR lpRemoteName,
  396. IN OUT LPDWORD lpBufferSize,
  397. OUT LPDWORD lpProviderIndex OPTIONAL
  398. ) ;
  399. DWORD
  400. OutputStringToAnsiInPlace(
  401. IN LPWSTR UnicodeIn
  402. );