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.

281 lines
6.2 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. HINSTANCE g_hInstance;
  46. extern "C" BOOL
  47. DllMain(
  48. HINSTANCE hDll,
  49. DWORD dwReason,
  50. LPVOID lpReserved)
  51. {
  52. switch(dwReason)
  53. {
  54. case DLL_PROCESS_ATTACH:
  55. g_hInstance = hDll;
  56. DisableThreadLibraryCalls(hDll);
  57. break;
  58. case DLL_PROCESS_DETACH:
  59. break;
  60. }
  61. return TRUE;
  62. }
  63. #define dprintf(x)
  64. #define MAX_NETBIOS_NAME_LEN 16+1
  65. extern DWORD
  66. RemoveDfs(void);
  67. BOOLEAN
  68. DfsCheckForOldDfsService();
  69. DWORD
  70. GetSharePath(
  71. IN LPWSTR wszShareName,
  72. OUT LPWSTR wszSharePath);
  73. //+----------------------------------------------------------------------------
  74. //
  75. // Function: main
  76. //
  77. // Synopsis: Entry point in case you want to build this as an exe.
  78. // Configures all Dfs components on a machine.
  79. //
  80. // Arguments: [argc] --
  81. // [argv] --
  82. //
  83. // Returns: Nothing
  84. //
  85. //-----------------------------------------------------------------------------
  86. void _cdecl
  87. main(int argc, char *argv[])
  88. {
  89. DWORD dwErr = ERROR_SUCCESS;
  90. DWORD cbRootLen;
  91. BOOL fRootSetup = FALSE;
  92. BOOLEAN OldDfsService = FALSE;
  93. WCHAR wszDfsRootShare[ MAX_PATH ];
  94. //
  95. // Figure out the type of machine we are installing on - client or root
  96. //
  97. if (argc != 1) {
  98. return;
  99. }
  100. //
  101. // Configure the Dfs Driver
  102. //
  103. if (dwErr == ERROR_SUCCESS) {
  104. dwErr = ConfigDfs();
  105. if (dwErr == ERROR_SUCCESS) {
  106. dwErr = ConfigDfsService();
  107. if (dwErr != ERROR_SUCCESS) {
  108. dprintf((
  109. DEB_ERROR, "Win32 error configuring Dfs Service %d\n",
  110. dwErr));
  111. (void)RemoveDfs();
  112. } else {
  113. dprintf((DEB_ERROR,"Successfully configured Dfs...\n") );
  114. }
  115. } else {
  116. dprintf((DEB_ERROR,"Error %d configuring Dfs driver!\n", dwErr));
  117. }
  118. }
  119. }
  120. //+----------------------------------------------------------------------------
  121. //
  122. // Function: DfsSetupDfs
  123. //
  124. // Synopsis: Entry point in case you want to build this as a DLL. This
  125. // function is suitable for being called from a setup .inf
  126. // file.
  127. //
  128. // Arguments: [cArgs] -- Count of args
  129. // [lpszArgs] -- Array of args
  130. // [lpszTextOut] -- On return, points to a global buffer
  131. // containing the null string. This is required by the
  132. // .inf file
  133. //
  134. // Returns: TRUE.
  135. //
  136. //-----------------------------------------------------------------------------
  137. LPSTR szReturn = "";
  138. extern "C" BOOL
  139. DfsSetupDfs(
  140. DWORD cArgs,
  141. LPSTR lpszArgs[],
  142. LPSTR *lpszTextOut)
  143. {
  144. int argc;
  145. LPSTR *argv;
  146. argv = (LPSTR *) malloc( (cArgs+1) * sizeof(LPSTR) );
  147. if (argv == NULL) {
  148. return( FALSE );
  149. }
  150. argv[0] = "DfsSetup";
  151. for (argc = 1; argc <= (int) cArgs; argc++) {
  152. argv[ argc ] = lpszArgs[ argc-1 ];
  153. }
  154. main( argc, argv );
  155. free( argv );
  156. *lpszTextOut = szReturn;
  157. return( TRUE );
  158. }
  159. //+------------------------------------------------------------------
  160. //
  161. // Function: CheckForOldDfsService
  162. //
  163. // Synopsis:
  164. //
  165. // Effects: -none-
  166. //
  167. // Arguments: -none-
  168. //
  169. // Returns: TRUE if the old (pre -ds build) dfs service is installed
  170. //
  171. //
  172. // History: 10-09-96 JimMcN Created
  173. //
  174. // Notes:
  175. //
  176. //
  177. //-------------------------------------------------------------------
  178. BOOLEAN DfsCheckForOldDfsService( )
  179. {
  180. DWORD dwErr = 0;
  181. DWORD DfsVersion;
  182. // Open Service Controller
  183. CService cSvc;
  184. if (!(dwErr = cSvc.Init()))
  185. {
  186. dwErr = cSvc._OpenService(L"Dfs", SERVICE_QUERY_STATUS);
  187. cSvc._CloseService();
  188. if (dwErr != 0) {
  189. return(FALSE);
  190. }
  191. CRegKey cregDfsService( HKEY_LOCAL_MACHINE,
  192. &dwErr,
  193. L"System\\CurrentControlSet\\Services\\Dfs"
  194. );
  195. if (dwErr == ERROR_SUCCESS) {
  196. CRegDWORD DfsNewService((const CRegKey &)cregDfsService,
  197. L"DfsVersion", &DfsVersion);
  198. dwErr = DfsNewService.QueryErrorStatus();
  199. if (dwErr != 0) {
  200. dprintf((DEB_ERROR,"CheckForOldDfsService Failed Newserv\n"));
  201. return(TRUE);
  202. }
  203. if (DfsVersion < DFS_VERSION_NUMBER) {
  204. return(TRUE);
  205. }
  206. return(FALSE);
  207. }
  208. return(FALSE);
  209. }
  210. return FALSE ;
  211. }