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.

507 lines
12 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. //=======================
  89. // INLINE FUNCTIONS
  90. //=======================
  91. inline void
  92. PROBE_FOR_WRITE(
  93. LPDWORD pdw
  94. )
  95. // WARNING: This function can throw an exception. It must be called from
  96. // within a try-except block.
  97. {
  98. *(volatile DWORD *)pdw = *(volatile DWORD *)pdw;
  99. }
  100. inline BOOL
  101. IS_BAD_BYTE_BUFFER(
  102. LPVOID lpBuffer,
  103. LPDWORD lpBufferSize // in bytes
  104. )
  105. // WARNING: This function can throw an exception. It must be called from
  106. // within a try-except block.
  107. {
  108. PROBE_FOR_WRITE(lpBufferSize);
  109. return IsBadWritePtr(lpBuffer, *lpBufferSize);
  110. }
  111. inline BOOL
  112. IS_BAD_WCHAR_BUFFER(
  113. LPVOID lpBuffer,
  114. LPDWORD lpBufferSize // in Unicode characters
  115. )
  116. // WARNING: This function can throw an exception. It must be called from
  117. // within a try-except block.
  118. {
  119. PROBE_FOR_WRITE(lpBufferSize);
  120. return IsBadWritePtr(lpBuffer, *lpBufferSize * sizeof(WCHAR));
  121. }
  122. //=======================
  123. // CONSTANTS
  124. //=======================
  125. #define DEFAULT_MAX_PROVIDERS 25
  126. // Bit masks for remembering error codes
  127. #define BAD_NAME 0x00000001
  128. #define NO_NET 0x00000002
  129. #define NOT_CONNECTED 0x00000004
  130. #define NOT_CONTAINER 0x00000008
  131. #define NO_DEVICES 0x00000010
  132. #define OTHER_ERRS 0xFFFFFFFF
  133. #define REDIR_DEVICE 0x00000001
  134. #define REMOTE_NAME 0x00000002
  135. #define LOCAL_NAME REDIR_DEVICE
  136. #define DA_READ 0x00000001
  137. #define DA_WRITE 0x00000002
  138. #define DA_DELETE 0x00000004
  139. //
  140. // Timeout values for restoring connections and notifying
  141. // Credential Managers.
  142. //
  143. #define DEFAULT_WAIT_TIME 60000 // Default timeout if providers don't
  144. // specify.
  145. #define MAX_ALLOWED_WAIT_TIME 300000 // Max timeout a provider can specify
  146. #define RECONNECT_SLEEP_INCREMENT 3000 // number of seconds to sleep
  147. #define PROVIDER_WILL_NOT_START 0x00000000 // The provider will not be starting
  148. #define NO_TIME_ESTIMATE 0xffffffff // The provider cannot predict the
  149. // amount of time it will take to
  150. // start.
  151. #define NET_PROVIDER_KEY TEXT("system\\CurrentControlSet\\Control\\NetworkProvider")
  152. #define RESTORE_WAIT_VALUE TEXT("RestoreTimeout")
  153. #define RESTORE_CONNECTION_VALUE TEXT("RestoreConnection")
  154. #define DEFER_CONNECTION_VALUE TEXT("DeferConnection")
  155. //
  156. // GlobalInitLevels & InitClasses
  157. //
  158. // NOTE: The WN_???_CLASS values are bit masks.
  159. //
  160. // GlobalInitLevel
  161. #define FIRST_LEVEL 0x00000001
  162. #define NETWORK_LEVEL 0x00000002
  163. #define CREDENTIAL_LEVEL 0x00000004
  164. #define NOTIFIEE_LEVEL 0x00000008
  165. //
  166. //
  167. // InitClasses
  168. #define NETWORK_TYPE WN_NETWORK_CLASS
  169. #define CREDENTIAL_TYPE (WN_CREDENTIAL_CLASS | WN_PRIMARY_AUTHENT_CLASS)
  170. // The path in the registry for user's persistent connections is found in
  171. // the following key:
  172. //
  173. // "\HKEY_CURRENT_USER\Network"
  174. //
  175. // Subkeys of the network section listed by local drive names. These
  176. // keys contain the following values:
  177. // RemotePath, Type, ProviderName, UserName
  178. //
  179. // d: RemotePath = \\cyclops\scratch
  180. // Type = RESOURCE_TYPE_DISK
  181. // ProviderName = LanMan
  182. // UserName = Ernie
  183. #define CONNECTION_KEY_NAME TEXT("Network")
  184. #define REMOTE_PATH_NAME TEXT("RemotePath")
  185. #define USER_NAME TEXT("UserName")
  186. #define PROVIDER_NAME TEXT("ProviderName")
  187. #define PROVIDER_TYPE TEXT("ProviderType")
  188. #define PROVIDER_FLAGS TEXT("ProviderFlags")
  189. #define DEFER_FLAGS TEXT("DeferFlags")
  190. #define CONNECTION_TYPE TEXT("ConnectionType")
  191. #define PRINT_CONNECTION_KEY_NAME TEXT("Printers\\RestoredConnections")
  192. //=======================
  193. // Global data
  194. //=======================
  195. extern LPPROVIDER GlobalProviderInfo; // pArray of PROVIDER Structures
  196. extern DWORD GlobalNumProviders;
  197. extern DWORD MprDebugLevel;
  198. extern HANDLE MprLoadLibSemaphore; // used to protect DLL handles
  199. extern volatile DWORD GlobalInitLevel;
  200. extern CRITICAL_SECTION MprErrorRecCritSec;
  201. extern WCHAR g_wszEntireNetwork[40];
  202. //==========================
  203. // Functions from support.c
  204. //==========================
  205. VOID
  206. MprDeleteIndexArray(
  207. VOID
  208. );
  209. DWORD
  210. MprFindCallOrder(
  211. IN LPTSTR NameInfo,
  212. OUT LPDWORD *IndexArrayPtr,
  213. OUT LPDWORD IndexArrayCount,
  214. IN DWORD InitClass
  215. );
  216. DWORD
  217. MprDeviceType(
  218. IN LPCTSTR DeviceName
  219. );
  220. BOOL
  221. MprGetProviderIndex(
  222. IN LPCTSTR ProviderName,
  223. OUT LPDWORD IndexPtr
  224. );
  225. LPPROVIDER
  226. MprFindProviderByName(
  227. IN LPCWSTR ProviderName
  228. );
  229. LPPROVIDER
  230. MprFindProviderByType(
  231. IN DWORD ProviderType
  232. );
  233. DWORD
  234. MprFindProviderForPath(
  235. IN LPWSTR lpPathName,
  236. OUT LPDWORD lpProviderIndex
  237. );
  238. VOID
  239. MprInitIndexArray(
  240. LPDWORD IndexArray,
  241. DWORD NumEntries
  242. );
  243. VOID
  244. MprEndCallOrder(
  245. VOID
  246. );
  247. VOID
  248. MprFreeAllErrorRecords(
  249. VOID
  250. );
  251. BOOL
  252. MprNetIsAvailable(
  253. VOID) ;
  254. //=========================
  255. // Functions from mprreg.c
  256. //=========================
  257. BOOL
  258. MprOpenKey(
  259. HKEY hKey,
  260. LPTSTR lpSubKey,
  261. PHKEY phKeyHandle,
  262. DWORD desiredAccess
  263. );
  264. BOOL
  265. MprGetKeyValue(
  266. HKEY KeyHandle,
  267. LPTSTR ValueName,
  268. LPTSTR *ValueString
  269. );
  270. BOOL
  271. MprGetKeyDwordValue(
  272. IN HKEY KeyHandle,
  273. IN LPCWSTR ValueName,
  274. OUT DWORD * Value
  275. );
  276. LONG
  277. MprGetKeyNumberValue(
  278. IN HKEY KeyHandle,
  279. IN LPCWSTR ValueName,
  280. IN LONG Default
  281. );
  282. DWORD
  283. MprEnumKey(
  284. IN HKEY KeyHandle,
  285. IN DWORD SubKeyIndex,
  286. OUT LPTSTR *SubKeyName,
  287. IN DWORD MaxSubKeyNameLen
  288. );
  289. BOOL
  290. MprGetKeyInfo(
  291. IN HKEY KeyHandle,
  292. OUT LPDWORD TitleIndex OPTIONAL,
  293. OUT LPDWORD NumSubKeys,
  294. OUT LPDWORD MaxSubKeyLen,
  295. OUT LPDWORD NumValues OPTIONAL,
  296. OUT LPDWORD MaxValueLen
  297. );
  298. DWORD MprGetPrintKeyInfo(HKEY KeyHandle,
  299. LPDWORD NumValueNames,
  300. LPDWORD MaxValueNameLength,
  301. LPDWORD MaxValueLen) ;
  302. BOOL
  303. MprFindDriveInRegistry (
  304. IN LPCTSTR DriveName,
  305. OUT LPTSTR *RemoteName
  306. );
  307. DWORD
  308. MprSaveDeferFlags(
  309. IN HKEY RegKey,
  310. IN DWORD DeferFlags
  311. );
  312. DWORD
  313. MprSetRegValue(
  314. IN HKEY KeyHandle,
  315. IN LPTSTR ValueName,
  316. IN LPCTSTR ValueString,
  317. IN DWORD LongValue
  318. );
  319. DWORD
  320. MprCreateRegKey(
  321. IN HKEY BaseKeyHandle,
  322. IN LPCTSTR KeyName,
  323. OUT PHKEY KeyHandlePtr
  324. );
  325. BOOL
  326. MprReadConnectionInfo(
  327. IN HKEY KeyHandle,
  328. IN LPCTSTR DriveName,
  329. IN DWORD Index,
  330. OUT LPDWORD ProviderFlags,
  331. OUT LPDWORD DeferFlags,
  332. OUT LPTSTR *UserNamePtr,
  333. OUT LPNETRESOURCEW NetResource,
  334. OUT HKEY *SubKeyHandleOut,
  335. IN DWORD MaxSubKeyLen
  336. );
  337. VOID
  338. MprForgetRedirConnection(
  339. IN LPCTSTR lpName
  340. );
  341. DWORD
  342. MprForgetPrintConnection(
  343. IN LPTSTR lpName
  344. );
  345. BOOL
  346. MprGetRemoteName(
  347. IN LPTSTR lpLocalName,
  348. IN OUT LPDWORD lpBufferSize,
  349. OUT LPTSTR lpRemoteName,
  350. OUT LPDWORD lpStatus
  351. ) ;
  352. //=========================
  353. // Functions from strbuf.c
  354. //=========================
  355. BOOL
  356. NetpCopyStringToBufferW (
  357. IN LPTSTR String OPTIONAL,
  358. IN DWORD CharacterCount,
  359. IN LPTSTR FixedDataEnd,
  360. IN OUT LPTSTR *EndOfVariableData,
  361. OUT LPTSTR *VariableDataPointer
  362. );
  363. BOOL
  364. NetpCopyStringToBufferA (
  365. IN LPTSTR String OPTIONAL,
  366. IN DWORD CharacterCount,
  367. IN LPBYTE FixedDataEnd,
  368. IN OUT LPTSTR *EndOfVariableData,
  369. OUT LPTSTR *VariableDataPointer
  370. );
  371. #ifdef UNICODE
  372. #define NetpCopyStringToBuffer NetpCopyStringToBufferW
  373. #else
  374. #define NetpCopyStringToBuffer NetpCopyStringToBufferA
  375. #endif
  376. //=========================
  377. // Other functions
  378. //=========================
  379. VOID
  380. MprCheckProviders(
  381. VOID
  382. );
  383. DWORD
  384. MprLevel1Init(
  385. VOID
  386. );
  387. DWORD
  388. MprLevel2Init(
  389. DWORD InitClass
  390. );
  391. DWORD
  392. MprEnterLoadLibCritSect (
  393. VOID
  394. ) ;
  395. DWORD
  396. MprLeaveLoadLibCritSect (
  397. VOID
  398. ) ;
  399. VOID
  400. MprClearString (
  401. LPWSTR lpString
  402. ) ;
  403. DWORD
  404. MprGetConnection (
  405. IN LPCWSTR lpLocalName,
  406. OUT LPWSTR lpRemoteName,
  407. IN OUT LPDWORD lpBufferSize,
  408. OUT LPDWORD lpProviderIndex OPTIONAL
  409. ) ;
  410. DWORD
  411. OutputStringToAnsiInPlace(
  412. IN LPWSTR UnicodeIn
  413. );