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.

422 lines
14 KiB

  1. /**********************************************************************/
  2. /** Microsoft LAN Manager **/
  3. /** Copyright(c) Microsoft Corp., 1990 **/
  4. /**********************************************************************/
  5. /*
  6. * History
  7. * chuckc 12/7/90 Created
  8. * rustanl 1/24/91 Moved lmodev enumerations here from
  9. * lmodev.hxx.
  10. * chuckc 3/1/91 coderev changes from 2/28/91
  11. * (chuckc, rustanl, johnl, annmc, jonshu)
  12. * jonn 7/26/91 Created NEW_LM_OBJ
  13. * jonn 8/06/91 Updated to latest NEW_LM_OBJ spec
  14. * jonn 8/12/91 Code review changes
  15. * rustanl 21-Aug-1991 Changed BufferQuery[...] methods to
  16. * QueryBuffer[...], and BufferResize to
  17. * ResizeBuffer.
  18. * rustanl 8/26/91 Changed [W_]CloneFrom parameter from * to &
  19. * jonn 8/29/91 Added ChangeToNew()
  20. * jonn 9/05/91 Added IsOKState() and IsConstructedState()
  21. * terryk 9/09/91 Added QueryDomain() to LOC_LM_OBJ
  22. * jonn 9/17/91 Moved CHECK_OK / CHECK_VALID strings to static
  23. * terryk 9/19/91 Added SetLoc() to LOC_LM_OBJ
  24. * terryk 10/07/91 Type changes for NT
  25. * terryk 10/17/91 Remove Buffer object and add
  26. * SetBufferPtr and SetBufferPtrSize
  27. * terryk 10/21/91 Type changes for NT
  28. * KeithMo 10/23/91 Added forward references.
  29. * jonn 10/31/91 Use MNET memory primitives
  30. * jonn 05/08/92 Added ClearBuffer()
  31. * jonn 05/19/92 Added LMO_DEV_ALLDEVICES
  32. * KeithMo 07/17/92 Added QueryDisplayName() to LOC_LM_OBJ.
  33. * Yi-HsinS08/21/92 Added _fValidate, IsValidationOn,
  34. * and SetValidation to LM_OBJ_BASE
  35. */
  36. #ifndef _LMOBJ_HXX_
  37. #define _LMOBJ_HXX_
  38. #include "base.hxx"
  39. #include "uibuffer.hxx"
  40. #include "lmoloc.hxx"
  41. /*
  42. * possible states for an object to be in
  43. */
  44. enum LMO_STATE
  45. {
  46. LMOBJ_UNCONSTRUCTED,
  47. LMOBJ_CONSTRUCTED,
  48. LMOBJ_VALID,
  49. LMOBJ_INVALID,
  50. LMOBJ_NEW
  51. };
  52. // Some enumerations used in lmodev and also in the DEVICE_COMBO class
  53. // in BLT.
  54. enum LMO_DEVICE
  55. {
  56. LMO_DEV_ERROR,
  57. LMO_DEV_DISK,
  58. LMO_DEV_PRINT,
  59. LMO_DEV_COMM,
  60. LMO_DEV_ANY
  61. }; // enum lMO_DEVICE
  62. enum LMO_DEV_USAGE
  63. {
  64. LMO_DEV_CANCONNECT,
  65. LMO_DEV_CANDISCONNECT,
  66. LMO_DEV_ISCONNECTED,
  67. LMO_DEV_ALLDEVICES,
  68. LMO_DEV_ALLDEVICES_DEFZ // used by DEVICE_COMBO to set default
  69. // entry to the last in list. Gets
  70. // mapped to LMO_DEV_ALLDEVICES when
  71. // passed into DEVICE class.
  72. };
  73. //
  74. // Forward references.
  75. //
  76. DLL_CLASS LM_OBJ_BASE;
  77. DLL_CLASS LM_OBJ;
  78. DLL_CLASS NEW_LM_OBJ;
  79. DLL_CLASS LOC_LM_OBJ;
  80. /**********************************************************\
  81. NAME: LM_OBJ_BASE
  82. SYNOPSIS: LM_OBJ_BASE provides the base accessors shared by the
  83. LM_OBJ and NEW_LM_OBJ lan manager object hierarchies.
  84. INTERFACE:
  85. Accessors to test current state:
  86. IsUnconstructed()
  87. IsConstructed()
  88. IsValid()
  89. IsInvalid()
  90. Accessors to change current state:
  91. MakeUnconstructed()
  92. MakeConstructed()
  93. MakeValid()
  94. MakeInvalid()
  95. PARENT:
  96. CAVEATS: Do not instantiate LM_OBJ_BASE, use LM_OBJ or
  97. NEW_LM_OBJ instead.
  98. NOTES: Note that the NEW state is only accessible
  99. from NEW_LM_OBJ and its derived classes
  100. HISTORY:
  101. chuckc 12/7/90 Created
  102. jonn 7/24/91 NEW_LM_OBJ
  103. \**********************************************************/
  104. DLL_CLASS LM_OBJ_BASE : virtual public ALLOC_BASE
  105. {
  106. friend class LM_OBJ;
  107. friend class NEW_LM_OBJ;
  108. private:
  109. enum LMO_STATE _usState ;
  110. BOOL _fValidate;
  111. BOOL IsUnconstructed() const {return(_usState==LMOBJ_UNCONSTRUCTED);}
  112. BOOL IsConstructed() const {return(_usState==LMOBJ_CONSTRUCTED);}
  113. BOOL IsValid() const {return(_usState==LMOBJ_VALID);}
  114. BOOL IsInvalid() const {return(_usState==LMOBJ_INVALID);}
  115. VOID MakeUnconstructed() {_usState=LMOBJ_UNCONSTRUCTED;}
  116. VOID MakeConstructed() {_usState=LMOBJ_CONSTRUCTED;}
  117. VOID MakeValid() {_usState=LMOBJ_VALID;}
  118. VOID MakeInvalid() {_usState=LMOBJ_INVALID;}
  119. protected:
  120. LM_OBJ_BASE( BOOL fValidate = TRUE )
  121. { MakeConstructed(); _fValidate = fValidate; }
  122. public:
  123. BOOL IsValidationOn( VOID )
  124. { return _fValidate; }
  125. VOID SetValidation( BOOL fValidate = TRUE )
  126. { _fValidate = fValidate; }
  127. };
  128. /**********************************************************\
  129. NAME: LM_OBJ
  130. SYNOPSIS: old-style lan manager object class
  131. INTERFACE:
  132. QueryName() - returns a name whose type depends on the
  133. subclass, e.g. a user name, a server name, etc.
  134. GetInfo() - pure virtual function
  135. WriteInfo() - pure virtual function
  136. PARENT: LM_OBJ_BASE
  137. CAVEATS: LM_OBJ is a pure virtual class, and only derived classes
  138. can be instantiated.
  139. HISTORY:
  140. chuckc 12/7/90 Created
  141. jonn 7/24/91 NEW_LM_OBJ
  142. \**********************************************************/
  143. DLL_CLASS LM_OBJ : public LM_OBJ_BASE
  144. {
  145. protected:
  146. virtual APIERR ValidateName() {return(NERR_Success);}
  147. BOOL IsUnconstructed() const {return LM_OBJ_BASE::IsUnconstructed();}
  148. BOOL IsConstructed() const {return LM_OBJ_BASE::IsConstructed();}
  149. BOOL IsValid() const {return LM_OBJ_BASE::IsValid();}
  150. BOOL IsInvalid() const {return LM_OBJ_BASE::IsInvalid();}
  151. VOID MakeUnconstructed() {LM_OBJ_BASE::MakeUnconstructed();}
  152. VOID MakeConstructed() {LM_OBJ_BASE::MakeConstructed();}
  153. VOID MakeValid() {LM_OBJ_BASE::MakeValid();}
  154. VOID MakeInvalid() {LM_OBJ_BASE::MakeInvalid();}
  155. public:
  156. /* inherited from LM_OBJ_BASE */
  157. virtual const TCHAR * QueryName() const = 0 ;
  158. virtual APIERR GetInfo() = 0 ;
  159. virtual APIERR WriteInfo() = 0 ;
  160. } ;
  161. /**********************************************************\
  162. NAME: NEW_LM_OBJ
  163. SYNOPSIS: revised lan manager object class
  164. INTERFACE:
  165. Accessors to test current state:
  166. IsOKState() -- public method which returns whether
  167. the object is in a state acceptable for
  168. accessors. Currently VALID and NEW are
  169. acceptable.
  170. IsNew() -- private method
  171. Accessors to change current state:
  172. MakeNew() -- private method
  173. QueryName() - returns a name whose type depends on the
  174. subclass, e.g. a user name, a server name, etc.
  175. Do not use unless redefined.
  176. Do not use these methods unless the corresponding
  177. I_ methods have been redefined
  178. GetInfo() - Get information on the object
  179. WriteInfo() - Write information on existing object
  180. CreateNew() - Set up default new object
  181. WriteNew() - Create new object
  182. Write() - Either writes information on existing object
  183. or creates new object, depending on whether the
  184. object is believed to already exist.
  185. Delete() - Delete exising object. See the specific
  186. subclass for the interpretation of usForce.
  187. ChangeToNew() - Transforms an existing object from state
  188. VALID to state NEW.
  189. Redefine these protected methods to make the
  190. corresponding public methods available
  191. I_GetInfo() - Get information on the object
  192. I_WriteInfo() - Write information on existing object
  193. I_CreateNew() - Set up default new object
  194. I_WriteNew() - Create new object
  195. I_Delete() - Delete exising object. See the specific
  196. subclass for the interpretation of usForce.
  197. I_ChangeToNew() - Transforms an existing object from state
  198. VALID to state NEW.
  199. Internal protected methods
  200. W_CloneFrom() - worker function for CloneFrom()
  201. W_CreateNew() - worker function for I_CreateNew()
  202. W_ChangeToNew() - worker function for I_ChangeToNew()
  203. FixupPointer() - Helper routine to translate pointers
  204. embedded in copied API buffers.
  205. QueryName() - Do not use unless redefined
  206. PARENT: LM_OBJ_BASE
  207. USES: BUFFER
  208. HISTORY:
  209. jonn 7/24/91 NEW_LM_OBJ
  210. jonn 8/06/91 Revised to NEW_LM_OBJ spec
  211. jonn 10/31/91 Use MNET memory primitives
  212. jonn 05/08/92 Added ClearBuffer()
  213. \**********************************************************/
  214. DLL_CLASS NEW_LM_OBJ : public BASE, public LM_OBJ_BASE
  215. {
  216. private:
  217. //
  218. // This buffer stores the API buffer for all subclasses
  219. //
  220. BYTE *_pBuf;
  221. BOOL IsNew() const {return(_usState==LMOBJ_NEW);}
  222. VOID MakeNew() {_usState=LMOBJ_NEW;}
  223. protected:
  224. virtual APIERR I_GetInfo();
  225. virtual APIERR I_WriteInfo();
  226. virtual APIERR I_CreateNew();
  227. virtual APIERR I_WriteNew();
  228. virtual APIERR I_Delete( UINT usForce );
  229. virtual APIERR I_ChangeToNew();
  230. APIERR W_CloneFrom( const NEW_LM_OBJ & lmobj );
  231. virtual APIERR W_CreateNew();
  232. virtual APIERR W_ChangeToNew();
  233. VOID FixupPointer( TCHAR ** ppchar,
  234. const NEW_LM_OBJ * plmobjOld
  235. );
  236. VOID ReportError( APIERR err )
  237. {
  238. BASE::ReportError( err );
  239. MakeUnconstructed();
  240. }
  241. BYTE * QueryBufferPtr() const
  242. {
  243. return _pBuf;
  244. }
  245. UINT QueryBufferSize() const;
  246. VOID SetBufferPtr( BYTE * pBuffer );
  247. APIERR ResizeBuffer( UINT cbNewRequestedSize );
  248. APIERR ClearBuffer();
  249. inline BOOL IsOKState() const
  250. {
  251. return ( IsValid() || IsNew() );
  252. }
  253. public:
  254. NEW_LM_OBJ( BOOL fValidate = TRUE );
  255. ~NEW_LM_OBJ();
  256. virtual const TCHAR * QueryName() const;
  257. APIERR GetInfo();
  258. APIERR WriteInfo();
  259. APIERR CreateNew();
  260. APIERR WriteNew();
  261. APIERR Write();
  262. APIERR Delete( UINT usForce = 0 );
  263. APIERR ChangeToNew();
  264. } ;
  265. /**********************************************************\
  266. NAME: LOC_LM_OBJ
  267. SYNOPSIS: revised lan manager object class with implicit LOCATION
  268. PARENT: NEW_LM_OBJ
  269. USES: LOCATION
  270. HISTORY:
  271. jonn 7/26/91 Created
  272. \**********************************************************/
  273. DLL_CLASS LOC_LM_OBJ : public NEW_LM_OBJ
  274. {
  275. private:
  276. void CtAux( void ); // constructor helper routine
  277. //
  278. // This buffer stores the object location
  279. //
  280. LOCATION _loc;
  281. protected:
  282. APIERR W_CloneFrom( const LOC_LM_OBJ & lmobj );
  283. const TCHAR * QueryServer() const
  284. { return _loc.QueryServer(); }
  285. const TCHAR * QueryDomain() const
  286. { return _loc.QueryDomain(); }
  287. APIERR SetLoc( const TCHAR * pszLocation )
  288. { return _loc.Set( pszLocation ); }
  289. APIERR QueryDisplayName( NLS_STR * pnls ) const
  290. { return _loc.QueryDisplayName( pnls ); }
  291. public:
  292. // _loc must construct successfully
  293. LOC_LM_OBJ( const TCHAR * pszLocation = NULL, BOOL fValidate = TRUE );
  294. LOC_LM_OBJ( enum LOCATION_TYPE loctype, BOOL fValidate = TRUE );
  295. LOC_LM_OBJ( const LOCATION & loc, BOOL fValidate = TRUE );
  296. ~LOC_LM_OBJ() {}
  297. } ;
  298. // Macro used in the implementation of the various LMOBJ classes
  299. // This should only be used in the old LM_OBJ hierarchy
  300. #define CHECK_VALID( default_ret_val ) \
  301. { \
  302. if ( !IsValid() ) \
  303. { \
  304. UIASSERT( FALSE ); \
  305. return default_ret_val; \
  306. } \
  307. }
  308. // This should only be used in the NEW_LM_OBJ hierarchy
  309. #define CHECK_OK( default_ret_val ) \
  310. { \
  311. if ( !IsOKState() ) \
  312. { \
  313. UIASSERT( FALSE ); \
  314. return default_ret_val; \
  315. } \
  316. }
  317. #endif // _LMOBJ_HXX_