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.

139 lines
6.1 KiB

  1. //#pragma title( "EnumVols.hpp - Volume Enumeration" )
  2. /*
  3. Copyright (c) 1995-1998, Mission Critical Software, Inc. All rights reserved.
  4. ===============================================================================
  5. Module - enumvols.hpp
  6. System - SDResolve
  7. Author - Christy Boles
  8. Created - 97/06/27
  9. Description - Classes used to generate a list of pathnames, given a list of paths and/or
  10. machine names.
  11. Updates -
  12. ===============================================================================
  13. */
  14. #ifndef ENUMVOLS_HEADER
  15. #define ENUMVOLS_HEADER
  16. #define MAXSIZE 30000
  17. #include <lmcons.h>
  18. #include "EaLen.hpp"
  19. #ifndef TNODEINCLUDED
  20. #include "Tnode.hpp"
  21. #define TNODEINCLUDED
  22. #endif
  23. #define VERIFY_EXISTS (0x00000001)
  24. #define VERIFY_BACKUPRESTORE (0x00000002)
  25. #define VERIFY_PERSISTENT_ACLS (0x00000004)
  26. /*******************************************************************************************
  27. class TPathNode is a TNode, containing a UNICODE pathname. A TNode is constructed to
  28. hold each path in the TPathList list
  29. ********************************************************************************************/
  30. class TPathNode:public TNode
  31. {
  32. protected:
  33. bool haswc; // these three fields are set by Verify
  34. bool validalone;
  35. bool iscontainer;
  36. bool isFirstFromServer; // This field is maintained by TPathList
  37. WCHAR path[MAX_PATH + 1]; // the pathname associated with this node
  38. WCHAR server[UNCLEN+1]; // server name for path
  39. public:
  40. TPathNode(const LPWSTR name);
  41. WCHAR * GetPathName() const { return ( LPWSTR ) path; }
  42. WCHAR * GetServerName() const { return (LPWSTR) server; }
  43. void SetServerName(UCHAR const * name);
  44. void Display() const;
  45. bool ContainsWC() { return haswc; }
  46. bool IsValidAlone() { return validalone; }
  47. void ContainsWC(bool val) { haswc = val; }
  48. void IsValidAlone(bool val) {validalone = val; }
  49. void IsContainer(bool val) { iscontainer = val; }
  50. bool IsContainer() { return iscontainer; }
  51. bool IsFirstPathFromMachine() { return isFirstFromServer; }
  52. void IsFirstPathFromMachine(bool val) { isFirstFromServer = val; }
  53. DWORD VerifyExists();
  54. DWORD VerifyBackupRestore();
  55. DWORD VerifyPersistentAcls();
  56. protected:
  57. void LookForWCChars(); // looks for wildcard, and sets value of haswc
  58. void FindServerName(); // looks for the name of the server
  59. };
  60. /*******************************************************************************************
  61. class TPathList
  62. BuildPathList: takes an argument list, and builds a list of paths as follows:
  63. for each path in the arglist, the path is added,
  64. and for each machine-name, a path is added for the root
  65. of each shared, security-enabled volume.
  66. ********************************************************************************************/
  67. class TPathList : public TNodeList
  68. {
  69. protected:
  70. DWORD numServers; // Stats: count the number of complete servers added
  71. DWORD numPaths; // Stats: the number of paths in the list
  72. TNodeListEnum tenum; // used to enumerate the paths in the list (OpenEnum, Next, CloseEnum)
  73. public:
  74. TPathList();
  75. ~TPathList();
  76. int BuildPathList(TCHAR **argl, int argn, bool verbose); // takes cmd line args & builds path list
  77. int AddVolsOnMachine(const LPWSTR mach, bool verbose,bool verify = false); // takes a machine-name and adds all shared
  78. // security-enabled volumes to the list
  79. bool AddPath(const LPWSTR path,DWORD verifyFlags); // adds a single path (from args)
  80. // to the list
  81. void Clear(); // Removes all the paths in the list
  82. void Display() const; // printfs the pathname for each node
  83. DWORD GetNumPaths() const { return numPaths; }
  84. DWORD GetNumServers() const { return numServers; }
  85. void OpenEnum(); // To enumerate nodes in the list
  86. void CloseEnum(); // OpenEnum, GetItem for each node, CloseEnum
  87. LPWSTR Next(); // Returns the next pathname in the enumeration
  88. protected:
  89. void AddPathToList(TPathNode * newNode); // Helper function
  90. };
  91. // TVolumeEnum enumerates the administrative shares on a server
  92. class TVolumeEnum
  93. {
  94. private:
  95. DWORD numread; // number of volnames read this time
  96. DWORD total; // total # vols
  97. DWORD resume_handle;
  98. DWORD curr; // used to iterate through volumes
  99. LPBYTE pbuf;
  100. WCHAR * drivelist;
  101. LPBYTE shareptr;
  102. WCHAR currEntry[MAX_PATH];
  103. BOOL isOpen;
  104. BOOL verbose;
  105. UINT errmode;
  106. WCHAR server[32];
  107. DWORD verifyFlags;
  108. BOOL bLocalOnly;
  109. int nLeft;
  110. public:
  111. TVolumeEnum() { nLeft = 0; bLocalOnly = FALSE; isOpen = FALSE; pbuf = NULL; numread = 0; }
  112. ~TVolumeEnum() { if ( isOpen ) Close(); }
  113. DWORD Open(WCHAR const * server,DWORD verifyFlags,BOOL verbose);
  114. WCHAR * Next();
  115. void Close();
  116. void SetLocalMode(BOOL bLocal) { bLocalOnly = bLocal; }
  117. };
  118. #endif