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.

282 lines
5.9 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // Copyright (C) 1995, Microsoft Corporation
  4. //
  5. // File: dfssetup.cxx
  6. //
  7. // Contents: Code to setup Dfs on a machine.
  8. //
  9. // Note that this code can be built as an exe or as a DLL. To
  10. // switch between the two, simply edit the following fields in
  11. // the sources file:
  12. // TARGETTYPE=[PROGRAM | DYNLINK]
  13. // UMTYPE=[console | windows]
  14. // Delete the following two lines from sources to build an exe.
  15. // DLLDEF=obj\*\dfssetup.def
  16. // DLLENTRY=_DllMainCRTStartup
  17. // DLLBASE=@$(BASEDIR)\PUBLIC\SDK\LIB\coffbase.txt,dfssetup
  18. //
  19. // Classes: None
  20. //
  21. // Functions:
  22. //
  23. // History: 12-28-95 Milans Created
  24. //
  25. //-----------------------------------------------------------------------------
  26. extern "C" {
  27. #include <nt.h>
  28. #include <ntrtl.h>
  29. #include <nturtl.h>
  30. #include <stdlib.h>
  31. }
  32. #include <windows.h>
  33. #include <rpc.h> // For UuidCreate
  34. #include <winldap.h>
  35. #include <dsgetdc.h>
  36. #include <lm.h>
  37. #include "registry.hxx" // Helper functions...
  38. #include "setupsvc.hxx"
  39. #include "config.hxx" // Config UI functions
  40. //
  41. // Until we get the schema right in the DS, we have to set our own SD on
  42. // certain objects
  43. //
  44. #include <aclapi.h>
  45. #include <permit.h>
  46. HINSTANCE g_hInstance;
  47. extern "C" BOOL
  48. DllMain(
  49. HINSTANCE hDll,
  50. DWORD dwReason,
  51. LPVOID lpReserved)
  52. {
  53. switch(dwReason)
  54. {
  55. case DLL_PROCESS_ATTACH:
  56. g_hInstance = hDll;
  57. DisableThreadLibraryCalls(hDll);
  58. break;
  59. case DLL_PROCESS_DETACH:
  60. break;
  61. }
  62. return TRUE;
  63. }
  64. #define dprintf(x)
  65. #define MAX_NETBIOS_NAME_LEN 16+1
  66. extern DWORD
  67. RemoveDfs(void);
  68. BOOLEAN
  69. DfsCheckForOldDfsService();
  70. DWORD
  71. GetSharePath(
  72. IN LPWSTR wszShareName,
  73. OUT LPWSTR wszSharePath);
  74. //+----------------------------------------------------------------------------
  75. //
  76. // Function: main
  77. //
  78. // Synopsis: Entry point in case you want to build this as an exe.
  79. // Configures all Dfs components on a machine.
  80. //
  81. // Arguments: [argc] --
  82. // [argv] --
  83. //
  84. // Returns: Nothing
  85. //
  86. //-----------------------------------------------------------------------------
  87. void _cdecl
  88. main(int argc, char *argv[])
  89. {
  90. DWORD dwErr = ERROR_SUCCESS;
  91. DWORD cbRootLen;
  92. BOOL fRootSetup = FALSE;
  93. BOOLEAN OldDfsService = FALSE;
  94. WCHAR wszDfsRootShare[ MAX_PATH ];
  95. //
  96. // Figure out the type of machine we are installing on - client or root
  97. //
  98. if (argc != 1) {
  99. return;
  100. }
  101. //
  102. // Configure the Dfs Driver
  103. //
  104. if (dwErr == ERROR_SUCCESS) {
  105. dwErr = ConfigDfs();
  106. if (dwErr == ERROR_SUCCESS) {
  107. dwErr = ConfigDfsService();
  108. if (dwErr != ERROR_SUCCESS) {
  109. dprintf((
  110. DEB_ERROR, "Win32 error configuring Dfs Service %d\n",
  111. dwErr));
  112. (void)RemoveDfs();
  113. } else {
  114. dprintf((DEB_ERROR,"Successfully configured Dfs...\n") );
  115. }
  116. } else {
  117. dprintf((DEB_ERROR,"Error %d configuring Dfs driver!\n", dwErr));
  118. }
  119. }
  120. }
  121. //+----------------------------------------------------------------------------
  122. //
  123. // Function: DfsSetupDfs
  124. //
  125. // Synopsis: Entry point in case you want to build this as a DLL. This
  126. // function is suitable for being called from a setup .inf
  127. // file.
  128. //
  129. // Arguments: [cArgs] -- Count of args
  130. // [lpszArgs] -- Array of args
  131. // [lpszTextOut] -- On return, points to a global buffer
  132. // containing the null string. This is required by the
  133. // .inf file
  134. //
  135. // Returns: TRUE.
  136. //
  137. //-----------------------------------------------------------------------------
  138. LPSTR szReturn = "";
  139. extern "C" BOOL
  140. DfsSetupDfs(
  141. DWORD cArgs,
  142. LPSTR lpszArgs[],
  143. LPSTR *lpszTextOut)
  144. {
  145. int argc;
  146. LPSTR *argv;
  147. argv = (LPSTR *) malloc( (cArgs+1) * sizeof(LPSTR) );
  148. if (argv == NULL) {
  149. return( FALSE );
  150. }
  151. argv[0] = "DfsSetup";
  152. for (argc = 1; argc <= (int) cArgs; argc++) {
  153. argv[ argc ] = lpszArgs[ argc-1 ];
  154. }
  155. main( argc, argv );
  156. free( argv );
  157. *lpszTextOut = szReturn;
  158. return( TRUE );
  159. }
  160. //+------------------------------------------------------------------
  161. //
  162. // Function: CheckForOldDfsService
  163. //
  164. // Synopsis:
  165. //
  166. // Effects: -none-
  167. //
  168. // Arguments: -none-
  169. //
  170. // Returns: TRUE if the old (pre -ds build) dfs service is installed
  171. //
  172. //
  173. // History: 10-09-96 JimMcN Created
  174. //
  175. // Notes:
  176. //
  177. //
  178. //-------------------------------------------------------------------
  179. BOOLEAN DfsCheckForOldDfsService( )
  180. {
  181. DWORD dwErr = 0;
  182. DWORD DfsVersion;
  183. // Open Service Controller
  184. CService cSvc;
  185. if (!(dwErr = cSvc.Init()))
  186. {
  187. dwErr = cSvc._OpenService(L"Dfs", SERVICE_QUERY_STATUS);
  188. cSvc._CloseService();
  189. if (dwErr != 0) {
  190. return(FALSE);
  191. }
  192. CRegKey cregDfsService( HKEY_LOCAL_MACHINE,
  193. &dwErr,
  194. L"System\\CurrentControlSet\\Services\\Dfs"
  195. );
  196. if (dwErr == ERROR_SUCCESS) {
  197. CRegDWORD DfsNewService((const CRegKey &)cregDfsService,
  198. L"DfsVersion", &DfsVersion);
  199. dwErr = DfsNewService.QueryErrorStatus();
  200. if (dwErr != 0) {
  201. dprintf((DEB_ERROR,"CheckForOldDfsService Failed Newserv\n"));
  202. return(TRUE);
  203. }
  204. if (DfsVersion < DFS_VERSION_NUMBER) {
  205. return(TRUE);
  206. }
  207. return(FALSE);
  208. }
  209. return(FALSE);
  210. }
  211. return FALSE ;
  212. }