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.

398 lines
12 KiB

  1. /**********************************************************************/
  2. /** Microsoft NT Windows **/
  3. /** Copyright(c) Microsoft Corp., 1991 **/
  4. /**********************************************************************/
  5. /*
  6. * lmoshare.hxx
  7. *
  8. * This file contains the definitions for the share class objects.
  9. *
  10. * History
  11. * t-yis 8/9/91 Created
  12. * rustanl 8/27/91 Changed CloneFrom param from * to &
  13. * terryk 10/07/91 type changes for NT
  14. * terryk 10/21/91 type changes for NT
  15. * Yi-HsinS 1/21/92 QueryPath return NULL
  16. * when its contents is empty.
  17. * Yi-HsinS 11/30/92 Added flag to SetWriteBuffer
  18. */
  19. #ifndef _LMOSHARE_HXX_
  20. #define _LMOSHARE_HXX_
  21. #include "lmobj.hxx"
  22. /*************************************************************************
  23. NAME: SHARE
  24. SYNOPSIS: Superclass for manipulation of share object
  25. INTERFACE: PUBLIC:
  26. QueryName
  27. Returns the share name e.g. PUBLIC
  28. QueryServer
  29. Returns the name of the server the share is on
  30. e.g. \\FOOBAR
  31. Delete - defined as public in NEW_LM_OBJ
  32. The interface to delete the share
  33. PROTECTED:
  34. I_Delete - redefined as protected in SHARE class
  35. and will be called by Delete.
  36. Do the actual work in deleting the share
  37. SetName -
  38. Set the share name
  39. PARENT: LOC_LM_OBJ
  40. USES: NLS_STR
  41. CAVEATS:
  42. NOTES: SetName() is protected in SHARE class and redefined
  43. as public in SHARE_2 class so that only SHARE_2 objects
  44. can set the share name for use when creating a new share.
  45. HISTORY:
  46. t-yis 8/9/91 Created
  47. **************************************************************************/
  48. DLL_CLASS SHARE : public LOC_LM_OBJ
  49. {
  50. private:
  51. NLS_STR _nlsShareName;
  52. protected:
  53. APIERR W_CloneFrom( const SHARE & share );
  54. APIERR W_CreateNew( VOID );
  55. APIERR I_Delete( UINT usForce = 0 );
  56. APIERR SetName( const TCHAR *pszShareName );
  57. public:
  58. SHARE( const TCHAR *pszShareName,
  59. const TCHAR *pszServerName = NULL,
  60. BOOL fValidate = TRUE );
  61. ~SHARE();
  62. // Need to add macro to check if the share object is in valid state
  63. // before querying the data members
  64. const TCHAR *QueryName( VOID ) const
  65. { return _nlsShareName.QueryPch(); }
  66. // QueryServer() defined in LOC_LM_OBJ is protected,
  67. // make it public here so that we can use it.
  68. const TCHAR *QueryServer( VOID ) const
  69. { return LOC_LM_OBJ::QueryServer(); }
  70. };
  71. /*************************************************************************
  72. NAME: SHARE_1
  73. SYNOPSIS: SHARE_1 does not support WriteNew since
  74. the API does not support level 1 NetShareAdd.
  75. INTERFACE: In addition to the interface of SHARE, SHARE_1 also support
  76. the following:
  77. PUBLIC:
  78. GetInfo
  79. Retrieves info about the share, returns a standard
  80. error code.
  81. WriteInfo
  82. Writes the current state of the object to the
  83. API. This write is atomic, either all
  84. parameters are set or none are set.
  85. CloneFrom
  86. Makes this SHARE_1 instance an exact copy of the
  87. parameter SHARE_1 instance. All fields including
  88. name and state will be copied. If this operation
  89. fails, the object will be invalid. The parameter
  90. must be a SHARE_1 and not a subclass of SHARE_1.
  91. QueryResourceType
  92. Returns the type of the shared resource,
  93. disk, printer queue ...
  94. QueryComment
  95. Returns the comment set for the share
  96. IsAdminOnly
  97. TRUE is the share can be access only by administrator
  98. or server operator
  99. IsDiskDirectory
  100. TRUE if the share is a disk directory
  101. IsPrinterQueue
  102. TRUE if the share is a printer queue
  103. IsCommDevice
  104. TRUE if the share is a communication device
  105. IsIPC
  106. TRUE if the share is a interprocess communication
  107. SetComment
  108. Set the comment of the share
  109. PROTECTED:
  110. I_GetInfo
  111. Actual function to get the information about the
  112. share. Called by GetInfo defined in NEW_LM_OBJ.
  113. I_WriteInfo
  114. Actual function to write the information about the
  115. share. Called by WriteInfo defined in NEW_LM_OBJ.
  116. SetResourceType
  117. Set the resource type of the share
  118. PARENT: SHARE
  119. USES: NLS_STR
  120. CAVEATS: (internal) The fields with appear as both data members
  121. and in the API buffer should be accessed only through
  122. the access methods. The API buffer is not updated until
  123. WriteInfo/WriteNew. This allows subclasses to use the
  124. same accessors.
  125. NOTES: SetResourceType() is protected since only SHARE_2 object
  126. can be used in creating a new share.
  127. HISTORY:
  128. t-yis 8/9/91 Created
  129. **************************************************************************/
  130. DLL_CLASS SHARE_1 : public SHARE
  131. {
  132. private:
  133. UINT _uResourceType;
  134. BOOL _fAdminOnly;
  135. NLS_STR _nlsComment;
  136. protected:
  137. APIERR W_CloneFrom( const SHARE_1 & share1 );
  138. APIERR W_CreateNew( VOID );
  139. virtual APIERR I_GetInfo( VOID );
  140. virtual APIERR I_WriteInfo( VOID );
  141. APIERR SetResourceType( UINT uResourceType );
  142. VOID SetAdminOnly( BOOL fAdminOnly )
  143. { _fAdminOnly = fAdminOnly; }
  144. public:
  145. SHARE_1( const TCHAR *pszShareName,
  146. const TCHAR *pszServerName = NULL,
  147. BOOL fValidate = TRUE );
  148. ~SHARE_1();
  149. APIERR CloneFrom( const SHARE_1 & share1 );
  150. // Need to add macro to check if the share object is in valid state
  151. // before querying the data members
  152. UINT QueryResourceType( VOID ) const
  153. { return _uResourceType; }
  154. const TCHAR *QueryComment( VOID ) const
  155. { return _nlsComment.QueryPch(); }
  156. BOOL IsAdminOnly( VOID ) const
  157. { return _fAdminOnly; }
  158. BOOL IsDiskDirectory( VOID ) const
  159. { return (QueryResourceType() == STYPE_DISKTREE); }
  160. BOOL IsPrinterQueue( VOID ) const
  161. { return (QueryResourceType() == STYPE_PRINTQ); }
  162. BOOL IsCommDevice( VOID ) const
  163. { return (QueryResourceType() == STYPE_DEVICE); }
  164. BOOL IsIPC( VOID ) const
  165. { return (QueryResourceType() == STYPE_IPC); }
  166. APIERR SetComment( const TCHAR *pszComment );
  167. };
  168. /*************************************************************************
  169. NAME: SHARE_2
  170. SYNOPSIS: SHARE_2 must be used whenever the user wants to use
  171. WriteNew.
  172. INTERFACE: In addition to the interface of SHARE_1, SHARE_2 also
  173. supports the following:
  174. GetInfo
  175. Retrieves info about the share, returns a standard
  176. error code.
  177. WriteInfo
  178. Writes the current state of the object to the
  179. API.
  180. CreateNew
  181. Sets up the SHARE_2 object with default values in
  182. preparation for a call to WriteNew
  183. WriteNew
  184. Adds a new share
  185. CloneFrom
  186. Makes this SHARE_2 instance an exact copy of the
  187. parameter SHARE_2 instance. All fields including
  188. name and state will be copied. If this operation
  189. fails, the object will be invalid. The parameter
  190. must be a SHARE_2 and not a subclass of SHARE_2.
  191. QueryPermissions
  192. Returns the permissions to the share. This value
  193. is ignored when the server has user-level security.
  194. QueryMaxUses
  195. Returns the maximum number of concurrent connections
  196. that the share can accommodate.
  197. QueryCurrentUses
  198. Returns the number of connections to the share.
  199. QueryPath
  200. Returns the local pathname for the share.
  201. QueryPassword
  202. Returns the share's password. This value is ignored
  203. when the server has user-level security.
  204. IsPermReadOnly
  205. Returns true if the share has RX permissions
  206. IsPermModify
  207. Returns true if the share has RWXCDA permissions
  208. SetPermissions
  209. Set the permissions of the share. This value is ignored
  210. when the server is running user-level security.
  211. SetMaxUses
  212. Set the maximum number of concurrent connections allowed
  213. for the share.
  214. SetPath
  215. Set the actual local path for the share.
  216. SetPassword
  217. Set the password for the share. This value is ignored
  218. when the server is running share-level security.
  219. SetResourceType ( inherited from SHARE_1 )
  220. Set the type of the share, disk dir, printer queue...
  221. SetName ( inherited from SHARE )
  222. Set the share name for use in creating a new share
  223. PROTECTED:
  224. I_GetInfo
  225. Actual function for getting the information about
  226. the share. Called by GetInfo.
  227. I_WriteInfo
  228. Actual function for writing the information about
  229. the share. Called by WriteInfo.
  230. I_CreateNew
  231. Actual function for defining a new share object.
  232. Called by CreateNew.
  233. I_WriteNew
  234. Actual function for actually creating a new share.
  235. Called by WriteNew.
  236. SetCurrentUses
  237. Set the current number of connections. Defined because
  238. of parallelism with QueryCurrentUses. It is protected
  239. so only member functions can use it. This value is
  240. ignored when WriteNew/WriteInfo.
  241. PARENT: SHARE_1
  242. USES: NLS_STR
  243. HISTORY:
  244. t-yis 8/9/91 Created
  245. **************************************************************************/
  246. DLL_CLASS SHARE_2: public SHARE_1
  247. {
  248. private:
  249. UINT _fs2lPermissions;
  250. UINT _uMaxUses;
  251. UINT _uCurrentUses;
  252. NLS_STR _nlsPath;
  253. NLS_STR _nlsPassword;
  254. protected:
  255. APIERR W_CloneFrom( const SHARE_2 & share2 );
  256. APIERR W_CreateNew( VOID );
  257. virtual APIERR I_GetInfo( VOID );
  258. virtual APIERR I_WriteInfo( VOID );
  259. virtual APIERR I_CreateNew( VOID );
  260. virtual APIERR I_WriteNew( VOID );
  261. APIERR SetWriteBuffer( BOOL fNew ); // helper for I_WriteInfo and I_WriteNew
  262. APIERR SetCurrentUses( UINT uCurrentUses );
  263. public:
  264. SHARE_2( const TCHAR *pszShareName,
  265. const TCHAR *pszServerName = NULL,
  266. BOOL fValidate = TRUE );
  267. ~SHARE_2();
  268. APIERR CloneFrom( const SHARE_2 & share2 );
  269. UINT QueryPermissions( VOID ) const
  270. { return _fs2lPermissions; }
  271. UINT QueryMaxUses( VOID ) const
  272. { return _uMaxUses; }
  273. UINT QueryCurrentUses( VOID ) const
  274. { return _uCurrentUses; }
  275. const TCHAR *QueryPath( VOID ) const
  276. { return ( (_nlsPath.QueryTextLength() == 0 )
  277. ? NULL : _nlsPath.QueryPch());
  278. }
  279. const TCHAR *QueryPassword( VOID ) const
  280. { return _nlsPassword.QueryPch(); }
  281. BOOL IsPermReadOnly( VOID ) const
  282. { return ( (QueryPermissions() & ACCESS_ALL) ==
  283. (ACCESS_READ | ACCESS_EXEC)); }
  284. BOOL IsPermModify( VOID ) const
  285. { return ( (QueryPermissions() & ACCESS_ALL) ==
  286. (ACCESS_ALL | ~ACCESS_PERM)); }
  287. inline APIERR SetName( const TCHAR *pszShareName )
  288. { return SHARE::SetName( pszShareName ); }
  289. inline APIERR SetResourceType( UINT uResourceType )
  290. { return SHARE_1::SetResourceType( uResourceType ); }
  291. APIERR SetPermissions( UINT fs2lPermissions );
  292. APIERR SetMaxUses( UINT uMaxUses );
  293. APIERR SetPath( const TCHAR *pszPath );
  294. APIERR SetPassword( const TCHAR *pszPassword );
  295. };
  296. #endif