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.

391 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. SetPermissions
  207. Set the permissions of the share. This value is ignored
  208. when the server is running user-level security.
  209. SetMaxUses
  210. Set the maximum number of concurrent connections allowed
  211. for the share.
  212. SetPath
  213. Set the actual local path for the share.
  214. SetPassword
  215. Set the password for the share. This value is ignored
  216. when the server is running share-level security.
  217. SetResourceType ( inherited from SHARE_1 )
  218. Set the type of the share, disk dir, printer queue...
  219. SetName ( inherited from SHARE )
  220. Set the share name for use in creating a new share
  221. PROTECTED:
  222. I_GetInfo
  223. Actual function for getting the information about
  224. the share. Called by GetInfo.
  225. I_WriteInfo
  226. Actual function for writing the information about
  227. the share. Called by WriteInfo.
  228. I_CreateNew
  229. Actual function for defining a new share object.
  230. Called by CreateNew.
  231. I_WriteNew
  232. Actual function for actually creating a new share.
  233. Called by WriteNew.
  234. SetCurrentUses
  235. Set the current number of connections. Defined because
  236. of parallelism with QueryCurrentUses. It is protected
  237. so only member functions can use it. This value is
  238. ignored when WriteNew/WriteInfo.
  239. PARENT: SHARE_1
  240. USES: NLS_STR
  241. HISTORY:
  242. t-yis 8/9/91 Created
  243. **************************************************************************/
  244. DLL_CLASS SHARE_2: public SHARE_1
  245. {
  246. private:
  247. UINT _fs2lPermissions;
  248. UINT _uMaxUses;
  249. UINT _uCurrentUses;
  250. NLS_STR _nlsPath;
  251. NLS_STR _nlsPassword;
  252. protected:
  253. APIERR W_CloneFrom( const SHARE_2 & share2 );
  254. APIERR W_CreateNew( VOID );
  255. virtual APIERR I_GetInfo( VOID );
  256. virtual APIERR I_WriteInfo( VOID );
  257. virtual APIERR I_CreateNew( VOID );
  258. virtual APIERR I_WriteNew( VOID );
  259. APIERR SetWriteBuffer( BOOL fNew ); // helper for I_WriteInfo and I_WriteNew
  260. APIERR SetCurrentUses( UINT uCurrentUses );
  261. public:
  262. SHARE_2( const TCHAR *pszShareName,
  263. const TCHAR *pszServerName = NULL,
  264. BOOL fValidate = TRUE );
  265. ~SHARE_2();
  266. APIERR CloneFrom( const SHARE_2 & share2 );
  267. UINT QueryPermissions( VOID ) const
  268. { return _fs2lPermissions; }
  269. UINT QueryMaxUses( VOID ) const
  270. { return _uMaxUses; }
  271. UINT QueryCurrentUses( VOID ) const
  272. { return _uCurrentUses; }
  273. const TCHAR *QueryPath( VOID ) const
  274. { return ( (_nlsPath.QueryTextLength() == 0 )
  275. ? NULL : _nlsPath.QueryPch());
  276. }
  277. const TCHAR *QueryPassword( VOID ) const
  278. { return _nlsPassword.QueryPch(); }
  279. BOOL IsPermReadOnly( VOID ) const
  280. { return ( (QueryPermissions() & ACCESS_ALL) ==
  281. (ACCESS_READ | ACCESS_EXEC)); }
  282. inline APIERR SetName( const TCHAR *pszShareName )
  283. { return SHARE::SetName( pszShareName ); }
  284. inline APIERR SetResourceType( UINT uResourceType )
  285. { return SHARE_1::SetResourceType( uResourceType ); }
  286. APIERR SetPermissions( UINT fs2lPermissions );
  287. APIERR SetMaxUses( UINT uMaxUses );
  288. APIERR SetPath( const TCHAR *pszPath );
  289. APIERR SetPassword( const TCHAR *pszPassword );
  290. };
  291. #endif