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.

2565 lines
63 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. ftpconf.cxx
  5. Abstract:
  6. This module contains functions for FTP Server configuration
  7. class (FTP_SERVER_CONFIG).
  8. Author:
  9. Murali R. Krishnan (MuraliK) 21-March-1995
  10. Project:
  11. FTP Server DLL
  12. Functions Exported:
  13. FTP_SERVER_CONFIG::FTP_SERVER_CONFIG()
  14. FTP_SERVER_CONFIG::~FTP_SERVER_CONFIG()
  15. FTP_SERVER_CONFIG::InitFromRegistry()
  16. FTP_SERVER_CONFIG::GetConfigInformation()
  17. FTP_SERVER_CONFIG::SetConfigInformation()
  18. FTP_SERVER_CONFIG::AllocNewConnection()
  19. FTP_SERVER_CONFIG::RemoveConnection()
  20. FTP_SERVER_CONFIG::DisconnectAllConnections()
  21. FTP_SERVER_CONFIG::Print()
  22. Revisions:
  23. MuraliK 26-July-1995 Added Allocation caching of client conns.
  24. --*/
  25. # include "ftpdp.hxx"
  26. #include <ole2.h>
  27. #include <imd.h>
  28. #include <iiscnfgp.h>
  29. #include <mb.hxx>
  30. #include <mbstring.h>
  31. # include <tchar.h>
  32. #include <timer.h>
  33. extern "C"
  34. {
  35. #include "ntlsa.h"
  36. } // extern "C"
  37. /************************************************************
  38. * Symbolic Constants
  39. ************************************************************/
  40. #define DEFAULT_ALLOW_ANONYMOUS TRUE
  41. #define DEFAULT_ALLOW_GUEST_ACCESS TRUE
  42. #define DEFAULT_ANONYMOUS_ONLY FALSE
  43. #define DEFAULT_READ_ACCESS_MASK 0
  44. #define DEFAULT_WRITE_ACCESS_MASK 0
  45. #define DEFAULT_MSDOS_DIR_OUTPUT TRUE
  46. #define DEFAULT_USE_SUBAUTH TRUE
  47. #define DEFAULT_LOGON_METHOD LOGON32_LOGON_INTERACTIVE
  48. #define DEFAULT_ANONYMOUS_PWD ""
  49. const TCHAR DEFAULT_EXIT_MESSAGE[] = TEXT("Goodbye.");
  50. # define CCH_DEFAULT_EXIT_MESSAGE (lstrlen( DEFAULT_EXIT_MESSAGE) + 1)
  51. const TCHAR DEFAULT_MAX_CLIENTS_MSG[] =
  52. TEXT("Maximum clients reached, service unavailable.");
  53. # define CCH_DEFAULT_MAX_CLIENTS_MSG (lstrlen( DEFAULT_MAX_CLIENTS_MSG) + 1)
  54. // this should be a double null terminated null terminated sequence.
  55. const TCHAR DEFAULT_GREETING_MESSAGE[2] = { '\0', '\0' };
  56. # define CCH_DEFAULT_GREETING_MESSAGE ( 2)
  57. // this should be a double null terminated null terminated sequence.
  58. const TCHAR DEFAULT_BANNER_MESSAGE[2] = { '\0', '\0' };
  59. # define CCH_DEFAULT_BANNER_MESSAGE ( 2)
  60. #define DEFAULT_ANNOTATE_DIRS FALSE
  61. #define DEFAULT_LOWERCASE_FILES FALSE
  62. #define DEFAULT_LISTEN_BACKLOG 1 /* reduce listen backlog */
  63. #define DEFAULT_ENABLE_LICENSING FALSE
  64. #define DEFAULT_DEFAULT_LOGON_DOMAIN NULL // NULL == use primary domain
  65. #define DEFAULT_ENABLE_PORT_ATTACK FALSE
  66. #define DEFAULT_ENABLE_PASV_THEFT FALSE
  67. #define DEFAULT_ALLOW_REPLACE_ON_RENAME FALSE
  68. #define DEFAULT_SHOW_4_DIGIT_YEAR FALSE
  69. #define DEFAULT_USER_ISOLATION NoIsolation
  70. #define DEFAULT_LOG_IN_UTF_8 FALSE
  71. # define SC_NOTIFY_INTERVAL 3000 // milliseconds
  72. # define CLEANUP_POLL_INTERVAL 2000 // milliseconds
  73. # define CLEANUP_RETRY_COUNT 12 // iterations
  74. //
  75. // Private Prototypes
  76. //
  77. APIERR
  78. GetDefaultDomainName(
  79. CHAR * pszDomainName,
  80. DWORD cchDomainName
  81. );
  82. BOOL
  83. FtpdReadRegString(
  84. IN HKEY hkey,
  85. OUT TCHAR * * ppchstr,
  86. IN LPCTSTR pchValue,
  87. IN LPCTSTR pchDefault,
  88. IN DWORD cchDefault
  89. );
  90. BOOL
  91. GenMessageWithLineFeed(IN LPSTR pszzMessage,
  92. IN LPSTR * ppszMessageWithLineFeed);
  93. #if DBG
  94. static CHAR * p_AccessTypes[] = { "read",
  95. "write",
  96. "create",
  97. "delete" };
  98. #endif // DBG
  99. /************************************************************
  100. * Member Functions of FTP_SERVER_INSTANCE
  101. ************************************************************/
  102. FTP_SERVER_INSTANCE::FTP_SERVER_INSTANCE(
  103. IN PFTP_IIS_SERVICE pService,
  104. IN DWORD dwInstanceId,
  105. IN USHORT sPort,
  106. IN LPCSTR lpszRegParamKey,
  107. IN LPWSTR lpwszAnonPasswordSecretName,
  108. IN LPWSTR lpwszRootPasswordSecretName,
  109. IN BOOL fMigrateVroots
  110. )
  111. /*++
  112. Description:
  113. Constructor Function for Ftp server Configuration object
  114. ( Initializes all members to be NULL)
  115. The valid flag may be initialized to TRUE only after reading values
  116. from registry.
  117. --*/
  118. : IIS_SERVER_INSTANCE(
  119. pService,
  120. dwInstanceId,
  121. sPort,
  122. lpszRegParamKey,
  123. lpwszAnonPasswordSecretName,
  124. lpwszRootPasswordSecretName,
  125. fMigrateVroots
  126. ),
  127. m_cCurrentConnections ( 0),
  128. m_cMaxCurrentConnections ( 0),
  129. m_fValid ( FALSE),
  130. m_fAllowAnonymous ( TRUE),
  131. m_fAnonymousOnly ( FALSE),
  132. m_fAllowGuestAccess ( TRUE),
  133. m_fAnnotateDirectories ( FALSE),
  134. m_fLowercaseFiles ( FALSE),
  135. m_fMsdosDirOutput ( FALSE),
  136. m_fFourDigitYear ( FALSE),
  137. m_fEnableLicensing ( FALSE),
  138. m_fEnablePortAttack ( FALSE),
  139. m_fEnablePasvTheft ( FALSE),
  140. m_pszGreetingMessageWithLineFeed( NULL),
  141. m_pszBannerMessageWithLineFeed( NULL),
  142. m_pszLocalHostName ( NULL),
  143. m_dwUserFlags ( 0),
  144. m_ListenBacklog ( DEFAULT_LISTEN_BACKLOG),
  145. m_pFTPStats ( NULL),
  146. m_UserIsolationMode ( DEFAULT_USER_ISOLATION),
  147. m_fLogInUtf8 ( DEFAULT_LOG_IN_UTF_8)
  148. {
  149. InitializeListHead( &m_ActiveConnectionsList);
  150. INITIALIZE_CRITICAL_SECTION( &m_csLock);
  151. InitializeListHead( &m_FreeConnectionsList);
  152. INITIALIZE_CRITICAL_SECTION( &m_csConnectionsList);
  153. if( QueryServerState() == MD_SERVER_STATE_INVALID ) {
  154. return;
  155. }
  156. m_pFTPStats = new FTP_SERVER_STATISTICS;
  157. if ( m_pFTPStats == NULL )
  158. {
  159. SetServerState( MD_SERVER_STATE_INVALID, ERROR_NOT_ENOUGH_MEMORY );
  160. SetLastError( ERROR_NOT_ENOUGH_MEMORY );
  161. }
  162. return;
  163. } // FTP_SERVER_INSTANCE::FTP_SERVER_INSTANCE()
  164. FTP_SERVER_INSTANCE::~FTP_SERVER_INSTANCE( VOID)
  165. /*++
  166. Description:
  167. Destructor function for server config object.
  168. ( Frees all dynamically allocated storage space)
  169. --*/
  170. {
  171. HRESULT hRes;
  172. //
  173. // delete statistics object
  174. //
  175. if( m_pFTPStats != NULL )
  176. {
  177. delete m_pFTPStats;
  178. m_pFTPStats = NULL;
  179. }
  180. //
  181. // The strings are automatically freed by a call to destructor
  182. //
  183. if ( m_pszLocalHostName != NULL) {
  184. delete [] ( m_pszLocalHostName);
  185. }
  186. if ( m_pszGreetingMessageWithLineFeed != NULL) {
  187. TCP_FREE( m_pszGreetingMessageWithLineFeed);
  188. m_pszGreetingMessageWithLineFeed = NULL;
  189. }
  190. if ( m_pszBannerMessageWithLineFeed != NULL) {
  191. TCP_FREE( m_pszBannerMessageWithLineFeed);
  192. m_pszBannerMessageWithLineFeed = NULL;
  193. }
  194. m_rfAccessCheck.Reset( (IMDCOM*)m_Service->QueryMDObject() );
  195. DBG_ASSERT( m_cCurrentConnections == 0);
  196. DBG_ASSERT( IsListEmpty( &m_ActiveConnectionsList));
  197. LockConnectionsList();
  198. DBG_REQUIRE(FreeAllocCachedClientConn());
  199. UnlockConnectionsList();
  200. DBG_ASSERT( IsListEmpty( &m_FreeConnectionsList));
  201. //
  202. // Delete the critical section object
  203. //
  204. DeleteCriticalSection( &m_csLock);
  205. DeleteCriticalSection( &m_csConnectionsList);
  206. } /* FTP_SERVER_INSTANCE::~FTP_SERVER_INSTANCE() */
  207. DWORD
  208. FTP_SERVER_INSTANCE::StartInstance()
  209. {
  210. IF_DEBUG(INSTANCE) {
  211. DBGPRINTF((
  212. DBG_CONTEXT,
  213. "FTP_SERVER_INSTANCE::StartInstance called for %p. Current state %d\n",
  214. this,
  215. QueryServerState()
  216. ));
  217. }
  218. DBG_ASSERT(m_pFTPStats);
  219. m_pFTPStats->UpdateStopTime();
  220. DWORD dwError = IIS_SERVER_INSTANCE::StartInstance();
  221. if ( dwError)
  222. {
  223. IF_DEBUG(INSTANCE) {
  224. DBGPRINTF((
  225. DBG_CONTEXT,
  226. "FTO_SERVER_INSTANCE - IIS_SERVER_INSTANCE Failed. StartInstance returned 0x%x",
  227. dwError
  228. ));
  229. }
  230. return dwError;
  231. }
  232. dwError = InitFromRegistry( FC_FTP_ALL );
  233. if( dwError == NO_ERROR ) {
  234. dwError = ReadAuthentInfo();
  235. }
  236. if (dwError == NO_ERROR)
  237. {
  238. m_pFTPStats->UpdateStartTime();
  239. }
  240. return dwError;
  241. }
  242. DWORD
  243. FTP_SERVER_INSTANCE::StopInstance()
  244. {
  245. DBG_ASSERT(m_pFTPStats);
  246. m_pFTPStats->UpdateStopTime();
  247. return IIS_SERVER_INSTANCE::StopInstance();
  248. }
  249. DWORD
  250. FTP_SERVER_INSTANCE::SetLocalHostName(IN LPCSTR pszHost)
  251. /*++
  252. This function copies the host name specified in the given string to
  253. configuration object.
  254. Arguments:
  255. pszHost pointer to string containing the local host name.
  256. Returns:
  257. NO_ERROR on success and ERROR_NOT_ENOUGH_MEMORY when no memory.
  258. ERROR_ALREADY_ASSIGNED if value is already present.
  259. --*/
  260. {
  261. //
  262. // if already a host name exists, return error.
  263. // otherwise allocate memory and copy the local host name.
  264. //
  265. if ( m_pszLocalHostName != NULL) {
  266. return (ERROR_ALREADY_ASSIGNED);
  267. } else {
  268. m_pszLocalHostName = new CHAR[lstrlenA(pszHost) + 1];
  269. if ( m_pszLocalHostName == NULL) {
  270. return (ERROR_NOT_ENOUGH_MEMORY);
  271. }
  272. lstrcpyA( m_pszLocalHostName, pszHost);
  273. }
  274. return (NO_ERROR);
  275. } // FTP_SERVER_INSTANCE::SetLocalHostName()
  276. DWORD
  277. FTP_SERVER_INSTANCE::InitFromRegistry(
  278. IN FIELD_CONTROL FieldsToRead)
  279. /*++
  280. Description:
  281. Initializes server configuration data from registry.
  282. Some values are also initialized with constants.
  283. If invalid registry key or load data from registry fails,
  284. then use default values.
  285. Arguments:
  286. hkeyReg handle to registry key
  287. FieldsToRead
  288. bitmask indicating the fields to read from the registry.
  289. This is useful when we try to read the new values after
  290. modifying the registry information as a result of
  291. SetAdminInfo call from the Admin UI
  292. Returns:
  293. NO_ERROR if there are no errors.
  294. Win32 error codes otherwise
  295. Limitations:
  296. No validity check is performed on the data present in registry.
  297. --*/
  298. {
  299. BOOL fSuccess = TRUE;
  300. DWORD err = NO_ERROR;
  301. IMDCOM* pMBCom;
  302. METADATA_HANDLE hMB;
  303. HRESULT hRes;
  304. METADATA_RECORD mdRecord;
  305. DWORD dwRequiredLen;
  306. BOOL fMustRel;
  307. HKEY hkeyReg = NULL;
  308. MB mb( (IMDCOM*)g_pInetSvc->QueryMDObject() );
  309. DWORD tmp;
  310. err = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  311. QueryRegParamKey(),
  312. 0,
  313. KEY_ALL_ACCESS,
  314. &hkeyReg );
  315. if ( hkeyReg == INVALID_HANDLE_VALUE ||
  316. hkeyReg == NULL) {
  317. //
  318. // Invalid Registry handle given
  319. //
  320. SetLastError( ERROR_INVALID_PARAMETER);
  321. return ( FALSE);
  322. }
  323. LockConfig();
  324. //
  325. // Read metabase data.
  326. //
  327. if( !mb.Open( QueryMDPath() ) ) {
  328. RegCloseKey( hkeyReg );
  329. UnLockConfig();
  330. return FALSE;
  331. }
  332. if( IsFieldSet( FieldsToRead, FC_FTP_EXIT_MESSAGE ) ) {
  333. if( !mb.GetStr( "",
  334. MD_EXIT_MESSAGE,
  335. IIS_MD_UT_SERVER,
  336. &m_ExitMessage,
  337. METADATA_INHERIT,
  338. DEFAULT_EXIT_MESSAGE ) ) {
  339. fSuccess = FALSE;
  340. err = GetLastError();
  341. }
  342. }
  343. if( fSuccess && IsFieldSet( FieldsToRead, FC_FTP_GREETING_MESSAGE ) ) {
  344. if( !mb.GetMultisz( "",
  345. MD_GREETING_MESSAGE,
  346. IIS_MD_UT_SERVER,
  347. &m_GreetingMessage ) ) {
  348. if( !m_GreetingMessage.Copy(
  349. DEFAULT_GREETING_MESSAGE,
  350. CCH_DEFAULT_GREETING_MESSAGE
  351. ) ) {
  352. fSuccess = FALSE;
  353. err = GetLastError();
  354. }
  355. }
  356. //
  357. // The m_pszGreetingMessage as read is a double null terminated
  358. // seq of strings (with one string per line)
  359. // A local copy of the string in the form suited for RPC Admin
  360. // should be generated.
  361. //
  362. if( fSuccess ) {
  363. fSuccess = GenMessageWithLineFeed( m_GreetingMessage.QueryStr(),
  364. &m_pszGreetingMessageWithLineFeed);
  365. if( !fSuccess ) {
  366. err = GetLastError();
  367. }
  368. }
  369. }
  370. if( fSuccess && IsFieldSet( FieldsToRead, FC_FTP_BANNER_MESSAGE ) ) {
  371. if( !mb.GetMultisz( "",
  372. MD_BANNER_MESSAGE,
  373. IIS_MD_UT_SERVER,
  374. &m_BannerMessage ) ) {
  375. if( !m_BannerMessage.Copy(
  376. DEFAULT_BANNER_MESSAGE,
  377. CCH_DEFAULT_BANNER_MESSAGE
  378. ) ) {
  379. fSuccess = FALSE;
  380. err = GetLastError();
  381. }
  382. }
  383. //
  384. // The m_pszBannerMessage as read is a double null terminated
  385. // seq of strings (with one string per line)
  386. // A local copy of the string in the form suited for RPC Admin
  387. // should be generated.
  388. //
  389. if( fSuccess ) {
  390. fSuccess = GenMessageWithLineFeed( m_BannerMessage.QueryStr(),
  391. &m_pszBannerMessageWithLineFeed);
  392. if( !fSuccess ) {
  393. err = GetLastError();
  394. }
  395. }
  396. }
  397. if( fSuccess && IsFieldSet( FieldsToRead, FC_FTP_MAX_CLIENTS_MESSAGE ) ) {
  398. if( !mb.GetStr( "",
  399. MD_MAX_CLIENTS_MESSAGE,
  400. IIS_MD_UT_SERVER,
  401. &m_MaxClientsMessage,
  402. METADATA_INHERIT,
  403. DEFAULT_MAX_CLIENTS_MSG ) ) {
  404. fSuccess = FALSE;
  405. err = GetLastError();
  406. }
  407. }
  408. if( IsFieldSet( FieldsToRead, FC_FTP_MSDOS_DIR_OUTPUT ) ) {
  409. if( !mb.GetDword( "",
  410. MD_MSDOS_DIR_OUTPUT,
  411. IIS_MD_UT_SERVER,
  412. &tmp ) ) {
  413. tmp = DEFAULT_MSDOS_DIR_OUTPUT;
  414. }
  415. m_fMsdosDirOutput = !!tmp;
  416. // clear and then set the MSDOS_DIR_OUTPUT in user flags
  417. m_dwUserFlags &= ~UF_MSDOS_DIR_OUTPUT;
  418. m_dwUserFlags |= (m_fMsdosDirOutput) ? UF_MSDOS_DIR_OUTPUT : 0;
  419. }
  420. if( IsFieldSet( FieldsToRead, FC_FTP_SHOW_4_DIGIT_YEAR) ) {
  421. if( !mb.GetDword( "",
  422. MD_SHOW_4_DIGIT_YEAR,
  423. IIS_MD_UT_SERVER,
  424. &tmp ) ) {
  425. tmp = DEFAULT_SHOW_4_DIGIT_YEAR;
  426. }
  427. m_fFourDigitYear = !!tmp;
  428. // clear and then set the 4_DIGIT_YEAR in user flags
  429. m_dwUserFlags &= ~UF_4_DIGIT_YEAR;
  430. m_dwUserFlags |= (m_fFourDigitYear) ? UF_4_DIGIT_YEAR : 0;
  431. }
  432. if( IsFieldSet( FieldsToRead, FC_FTP_ALLOW_ANONYMOUS ) ) {
  433. if( !mb.GetDword( "",
  434. MD_ALLOW_ANONYMOUS,
  435. IIS_MD_UT_SERVER,
  436. &tmp ) ) {
  437. tmp = DEFAULT_ALLOW_ANONYMOUS;
  438. }
  439. m_fAllowAnonymous = !!tmp;
  440. }
  441. if( IsFieldSet( FieldsToRead, FC_FTP_ANONYMOUS_ONLY ) ) {
  442. if( !mb.GetDword( "",
  443. MD_ANONYMOUS_ONLY,
  444. IIS_MD_UT_SERVER,
  445. &tmp ) ) {
  446. tmp = DEFAULT_ANONYMOUS_ONLY;
  447. }
  448. m_fAnonymousOnly = !!tmp;
  449. }
  450. if( IsFieldSet( FieldsToRead, FC_FTP_ALLOW_REPLACE_ON_RENAME ) ) {
  451. if( !mb.GetDword( "",
  452. MD_ALLOW_REPLACE_ON_RENAME,
  453. IIS_MD_UT_SERVER,
  454. &tmp ) ) {
  455. tmp = DEFAULT_ALLOW_REPLACE_ON_RENAME;
  456. }
  457. m_fAllowReplaceOnRename = !!tmp;
  458. }
  459. if( IsFieldSet( FieldsToRead, FC_FTP_USER_ISOLATION ) ) {
  460. if( !mb.GetDword( "",
  461. MD_USER_ISOLATION,
  462. IIS_MD_UT_SERVER,
  463. &tmp ) ) {
  464. tmp = DEFAULT_USER_ISOLATION;
  465. }
  466. m_UserIsolationMode = (ISOLATION_MODE)tmp;
  467. if (m_UserIsolationMode >= IsolationModeOverflow) {
  468. m_UserIsolationMode = DEFAULT_USER_ISOLATION;
  469. }
  470. }
  471. if( IsFieldSet( FieldsToRead, FC_FTP_LOG_IN_UTF_8 ) ) {
  472. if( !mb.GetDword( "",
  473. MD_FTP_LOG_IN_UTF_8,
  474. IIS_MD_UT_SERVER,
  475. &tmp ) ) {
  476. tmp = DEFAULT_LOG_IN_UTF_8;
  477. }
  478. m_fLogInUtf8 = !!tmp;
  479. }
  480. //
  481. // Read registry data.
  482. //
  483. if( IsFieldSet( FieldsToRead, FC_FTP_LISTEN_BACKLOG ) )
  484. {
  485. m_ListenBacklog = ReadRegistryDword( hkeyReg,
  486. FTPD_LISTEN_BACKLOG,
  487. DEFAULT_LISTEN_BACKLOG );
  488. }
  489. if( IsFieldSet( FieldsToRead, FC_FTP_ALLOW_GUEST_ACCESS ) ) {
  490. m_fAllowGuestAccess = !!ReadRegistryDword( hkeyReg,
  491. FTPD_ALLOW_GUEST_ACCESS,
  492. DEFAULT_ALLOW_GUEST_ACCESS );
  493. }
  494. if( IsFieldSet( FieldsToRead, FC_FTP_ANNOTATE_DIRECTORIES ) ) {
  495. m_fAnnotateDirectories = !!ReadRegistryDword( hkeyReg,
  496. FTPD_ANNOTATE_DIRS,
  497. DEFAULT_ANNOTATE_DIRS );
  498. // clear and then set the ANNOTATE_DIRS in user flags
  499. m_dwUserFlags &= ~UF_ANNOTATE_DIRS;
  500. m_dwUserFlags |= (m_fAnnotateDirectories) ? UF_ANNOTATE_DIRS : 0;
  501. }
  502. if( IsFieldSet( FieldsToRead, FC_FTP_LOWERCASE_FILES ) ) {
  503. m_fLowercaseFiles = !!ReadRegistryDword( hkeyReg,
  504. FTPD_LOWERCASE_FILES,
  505. DEFAULT_LOWERCASE_FILES );
  506. }
  507. // fEnablePortAttack is not controlled by RPC yet.
  508. m_fEnablePortAttack = !!ReadRegistryDword(hkeyReg,
  509. FTPD_ENABLE_PORT_ATTACK,
  510. DEFAULT_ENABLE_PORT_ATTACK);
  511. // fEnablePasvTheft is not controlled by RPC yet.
  512. m_fEnablePasvTheft = !!ReadRegistryDword(hkeyReg,
  513. FTPD_ENABLE_PASV_THEFT,
  514. DEFAULT_ENABLE_PASV_THEFT);
  515. if( fSuccess ) {
  516. //
  517. // The following field is not supported in the admin API.
  518. //
  519. m_fEnableLicensing = !!ReadRegistryDword( hkeyReg,
  520. FTPD_ENABLE_LICENSING,
  521. DEFAULT_ENABLE_LICENSING );
  522. }
  523. if ( fSuccess )
  524. {
  525. m_rfAccessCheck.Reset( (IMDCOM*)m_Service->QueryMDObject() );
  526. pMBCom = (IMDCOM*)m_Service->QueryMDObject();
  527. hRes = pMBCom->ComMDOpenMetaObject( METADATA_MASTER_ROOT_HANDLE,
  528. (BYTE *) QueryMDVRPath(),
  529. METADATA_PERMISSION_READ,
  530. 5000,
  531. &hMB );
  532. if ( SUCCEEDED( hRes ) )
  533. {
  534. mdRecord.dwMDIdentifier = MD_IP_SEC;
  535. mdRecord.dwMDAttributes = METADATA_INHERIT | METADATA_REFERENCE;
  536. mdRecord.dwMDUserType = IIS_MD_UT_FILE;
  537. mdRecord.dwMDDataType = BINARY_METADATA;
  538. mdRecord.dwMDDataLen = 0;
  539. mdRecord.pbMDData = (PBYTE)NULL;
  540. hRes = pMBCom->ComMDGetMetaData( hMB,
  541. (LPBYTE)"",
  542. &mdRecord,
  543. &dwRequiredLen );
  544. if ( SUCCEEDED( hRes ) && mdRecord.dwMDDataTag )
  545. {
  546. m_rfAccessCheck.Set( mdRecord.pbMDData,
  547. mdRecord.dwMDDataLen,
  548. mdRecord.dwMDDataTag );
  549. }
  550. DBG_REQUIRE( SUCCEEDED(pMBCom->ComMDCloseMetaObject( hMB )) );
  551. }
  552. else
  553. if( HRESULTTOWIN32( hRes ) != ERROR_PATH_NOT_FOUND )
  554. {
  555. fSuccess = FALSE;
  556. err = HRESULTTOWIN32( hRes );
  557. }
  558. }
  559. UnLockConfig();
  560. IF_DEBUG( CONFIG) {
  561. Print();
  562. }
  563. m_fValid = TRUE;
  564. RegCloseKey( hkeyReg );
  565. return ( err);
  566. } // FTP_SERVER_INSTANCE::InitFromRegistry()
  567. static BOOL
  568. RemoveInvalidsInPath( IN OUT TCHAR * pszPath)
  569. /*++
  570. Eliminate path components consisting of '.' and '..'
  571. to prevent security from being overridden
  572. Arguments:
  573. pszPath pointer to string containing path
  574. Returns:
  575. TRUE on success and
  576. FALSE if there is any failure
  577. --*/
  578. {
  579. int idest;
  580. TCHAR * pszScan;
  581. //
  582. // Check and eliminate the invalid path components
  583. //
  584. for( pszScan = pszPath; *pszScan != TEXT( '\0'); pszScan++) {
  585. if ( *pszScan == TEXT( '/')) {
  586. //
  587. // Check and kill invalid path components before next "\"
  588. //
  589. if ( *(pszScan + 1) == TEXT( '.')) {
  590. if ( *(pszScan +2) == TEXT('/')) {
  591. pszScan += 2; // skip the /./ pattern
  592. } else
  593. if ( *(pszScan +2) == TEXT('.') &&
  594. *(pszScan +3) == TEXT('/')) {
  595. //
  596. // We found the pattern /../, elimiate it
  597. //
  598. pszScan += 3;
  599. }
  600. *pszPath++ = *pszScan;
  601. continue;
  602. } // found a single /.
  603. }
  604. *pszPath++ = *pszScan;
  605. } // for
  606. *pszPath = TEXT( '\0');
  607. return ( TRUE);
  608. } // RemoveInvalidsInPath()
  609. VOID
  610. FTP_SERVER_INSTANCE::Print( VOID) const
  611. /*++
  612. Description:
  613. Prints the configuration information for this server.
  614. To be used in debugging mode for verification.
  615. Returns:
  616. None.
  617. --*/
  618. {
  619. DBGPRINTF(( DBG_CONTEXT,
  620. "FTP Server Configuration ( %08x).\n", this ));
  621. #if 0
  622. READ_LOCK_INST();
  623. DBGPRINTF(( DBG_CONTEXT,
  624. " AnonymousUser = %s\n",
  625. g_pInetSvc->QueryAnonUserName() ));
  626. UNLOCK_INST();
  627. DBGPRINTF(( DBG_CONTEXT,
  628. " %s = %d\n"
  629. " %s = %d\n"
  630. " %s = %u\n"
  631. " %s = %u\n"
  632. " %s = %u\n"
  633. " %s = %u\n"
  634. " %s = %u\n",
  635. FTPD_ALLOW_ANONYMOUS,
  636. m_fAllowAnonymous,
  637. FTPD_ALLOW_GUEST_ACCESS,
  638. m_fAllowGuestAccess,
  639. FTPD_ANONYMOUS_ONLY,
  640. m_fAnonymousOnly,
  641. FTPD_ENABLE_PORT_ATTACK,
  642. m_fEnablePortAttack,
  643. FTPD_ENABLE_PASV_THEFT,
  644. m_fEnablePasvTheft,
  645. "LogAnonymous",
  646. g_pInetSvc->QueryLogAnonymous(),
  647. "LogNonAnonymous",
  648. g_pInetSvc->QueryLogNonAnonymous()
  649. ));
  650. DBGPRINTF(( DBG_CONTEXT,
  651. " %s = %d\n",
  652. FTPD_ENABLE_LICENSING,
  653. m_fEnableLicensing ));
  654. DBGPRINTF(( DBG_CONTEXT,
  655. " MaxConnections = %lu\n",
  656. g_pInetSvc->QueryMaxConnections() ));
  657. DBGPRINTF(( DBG_CONTEXT,
  658. " ConnectionTimeout = %lu\n",
  659. g_pInetSvc->QueryConnectionTimeout() ));
  660. DBGPRINTF(( DBG_CONTEXT,
  661. " %s = %d\n",
  662. FTPD_MSDOS_DIR_OUTPUT,
  663. m_fMsdosDirOutput ));
  664. DBGPRINTF(( DBG_CONTEXT,
  665. " %s = %d\n",
  666. FTPD_4_DIGIT_YEAR,
  667. m_f4DigitYear ));
  668. DBGPRINTF(( DBG_CONTEXT,
  669. " %s = %d\n",
  670. FTPD_ANNOTATE_DIRS,
  671. m_fAnnotateDirectories ));
  672. DBGPRINTF(( DBG_CONTEXT,
  673. " %s = %08lX\n",
  674. FTPD_DEBUG_FLAGS,
  675. GET_DEBUG_FLAGS()));
  676. READ_LOCK_INST();
  677. DBGPRINTF(( DBG_CONTEXT,
  678. " LogFileDirectory = %s\n",
  679. g_pInetSvc->QueryLogFileDirectory() ));
  680. UNLOCK_INST();
  681. DBGPRINTF(( DBG_CONTEXT,
  682. " LogFileAccess = %lu\n",
  683. g_pInetSvc->QueryLogFileType() ));
  684. DBGPRINTF(( DBG_CONTEXT,
  685. " %s = %u\n",
  686. FTPD_LISTEN_BACKLOG,
  687. m_ListenBacklog ));
  688. DBGPRINTF(( DBG_CONTEXT,
  689. " DefaultLogonDomain = %s\n",
  690. m_DefaultLogonDomain ));
  691. DBGPRINTF(( DBG_CONTEXT,
  692. " %s = %u\n",
  693. FTPD_USER_ISOLATION,
  694. m_UserIsolation ));
  695. DBGPRINTF(( DBG_CONTEXT,
  696. " %s = %u\n",
  697. FTPD_LOG_IN_UTF_8,
  698. m_fLogInUtf8 ));
  699. #endif
  700. return;
  701. } // FTP_SERVER_INSTANCE::Print()
  702. PICLIENT_CONNECTION
  703. FTP_SERVER_INSTANCE::AllocNewConnection()
  704. /*++
  705. This function first checks that there is room for more connections
  706. as per the configured max connections.
  707. If there is no more connections allowed, it returns NULL
  708. with *pfMaxExceeded = TRUE
  709. Otherwise:
  710. This function creates a new CLIENT_CONNECTION (USER_DATA) object.
  711. The creation maybe fresh from heap or from cached free list.
  712. It increments the counter of currnet connections and returns
  713. the allocated object (if non NULL).
  714. We enter a critical section to avoid race condition
  715. among different threads. (this can be improved NYI).
  716. Returns:
  717. TRUE on success and
  718. FALSE if there is max Connections exceeded.
  719. --*/
  720. {
  721. PICLIENT_CONNECTION pConn = NULL;
  722. LockConnectionsList();
  723. //
  724. // We can add this new connection
  725. //
  726. pConn = AllocClientConnFromAllocCache();
  727. if ( pConn != NULL) {
  728. //
  729. // Increment the count of connected users
  730. //
  731. m_cCurrentConnections++;
  732. IF_DEBUG( CLIENT) {
  733. DBGPRINTF((DBG_CONTEXT, " CurrentConnections = %u\n",
  734. m_cCurrentConnections));
  735. }
  736. //
  737. // Update the current maximum connections
  738. //
  739. if ( m_cCurrentConnections > m_cMaxCurrentConnections) {
  740. m_cMaxCurrentConnections = m_cCurrentConnections;
  741. }
  742. //
  743. // Insert into the list of connected users.
  744. //
  745. InsertTailList( &m_ActiveConnectionsList, &pConn->QueryListEntry());
  746. }
  747. UnlockConnectionsList();
  748. return ( pConn);
  749. } // FTP_SERVER_INSTANCE::AllocNewConnection()
  750. VOID
  751. FTP_SERVER_INSTANCE::RemoveConnection(
  752. IN OUT PICLIENT_CONNECTION pcc
  753. )
  754. /*++
  755. --*/
  756. {
  757. LockConnectionsList();
  758. //
  759. // Remove from list of connections
  760. //
  761. RemoveEntryList( &pcc->QueryListEntry());
  762. //
  763. // Decrement count of current users
  764. //
  765. m_cCurrentConnections--;
  766. IF_DEBUG( CLIENT) {
  767. DBGPRINTF((DBG_CONTEXT, " CurrentConnections = %u\n",
  768. m_cCurrentConnections));
  769. }
  770. //
  771. // move the free connection to free list
  772. //
  773. FreeClientConnToAllocCache( pcc);
  774. UnlockConnectionsList();
  775. } // FTP_SERVER_INSTANCE::RemoveConnection()
  776. VOID
  777. FTP_SERVER_INSTANCE::DisconnectAllConnections( VOID)
  778. /*++
  779. Disconnects all user connections.
  780. Arguments:
  781. Instance - If NULL, then all users are disconnected. If !NULL, then
  782. only those users associated with the specified instance are
  783. disconnected.
  784. --*/
  785. {
  786. #ifdef CHECK_DBG
  787. CHAR rgchBuffer[90];
  788. #endif // CHECK_DBG
  789. DWORD dwLastTick = GetTickCount();
  790. DWORD dwCurrentTick;
  791. PLIST_ENTRY pEntry;
  792. PLIST_ENTRY pEntryNext;
  793. DBGPRINTF( ( DBG_CONTEXT,
  794. "Entering FTP_SERVER_INSTANCE::DisconnectAllConnections()\n"));
  795. //
  796. // Let's empty the connection list immediately while in the lock to avoid a
  797. // shutdown deadlock
  798. //
  799. LockConnectionsList();
  800. pEntry = m_ActiveConnectionsList.Flink;
  801. InitializeListHead( &m_ActiveConnectionsList);
  802. UnlockConnectionsList();
  803. //
  804. // close down all the active sockets.
  805. //
  806. for( pEntryNext = pEntry->Flink;
  807. pEntry != &m_ActiveConnectionsList;
  808. pEntry = pEntryNext) {
  809. PICLIENT_CONNECTION pConn =
  810. GET_USER_DATA_FROM_LIST_ENTRY( pEntry);
  811. pEntryNext = pEntry->Flink; // cache next entry since pConn may die
  812. ASSERT( pConn != NULL);
  813. # ifdef CHECK_DBG
  814. wsprintfA( rgchBuffer, "Kill UID=%u. Ref=%u\n",
  815. pConn->QueryId(), pConn->QueryReference());
  816. OutputDebugString( rgchBuffer);
  817. # endif // CHECK_DBG
  818. dwCurrentTick = GetTickCount();
  819. if ( (dwCurrentTick - dwLastTick) >= ( SC_NOTIFY_INTERVAL)) {
  820. //
  821. // We seem to take longer time for cleaning up than
  822. // expected. Let us ask service controller to wait for us.
  823. //
  824. g_pInetSvc->
  825. DelayCurrentServiceCtrlOperation(SC_NOTIFY_INTERVAL * 2);
  826. dwLastTick = dwCurrentTick;
  827. }
  828. pConn->Reference();
  829. pConn->DisconnectUserWithError( ERROR_SERVER_DISABLED, TRUE);
  830. DBG_REQUIRE( pConn->DeReference() > 0 ); // remove ref added above
  831. if( pConn->RemoveActiveReference() ) {
  832. //
  833. // This connection is due for deletion. Kill it.
  834. //
  835. // Remove from list of connections
  836. //
  837. pConn->Cleanup();
  838. RemoveEntryList( &pConn->QueryListEntry());
  839. //
  840. // Decrement count of current users
  841. //
  842. m_cCurrentConnections--;
  843. // move the connection to free list
  844. FreeClientConnToAllocCache( pConn);
  845. }
  846. } // for
  847. //
  848. // Wait for the users to die.
  849. // The connection objects should be automatically freed because the
  850. // socket has been closed. Subsequent requests will fail
  851. // and cause a blowaway of the connection objects.
  852. //
  853. //
  854. // Wait for the users to die.
  855. //
  856. for( int i = 0 ;
  857. ( i < CLEANUP_RETRY_COUNT ) && ( m_cCurrentConnections > 0);
  858. i++ )
  859. {
  860. DBGPRINTF(( DBG_CONTEXT, "Sleep Iteration %d; Time=%u millisecs."
  861. " CurrentConn=%d.\n",
  862. i, CLEANUP_POLL_INTERVAL, m_cCurrentConnections));
  863. g_pInetSvc->
  864. DelayCurrentServiceCtrlOperation( CLEANUP_POLL_INTERVAL * 2);
  865. Sleep( CLEANUP_POLL_INTERVAL );
  866. }
  867. return;
  868. } // FTP_SERVER_INSTANCE::DisconnectAllConnections()
  869. BOOL
  870. FTP_SERVER_INSTANCE::EnumerateConnection(
  871. IN PFN_CLIENT_CONNECTION_ENUM pfnConnEnum,
  872. IN LPVOID pContext,
  873. IN DWORD dwConnectionId)
  874. /*++
  875. This function iterates through all the connections in the current connected
  876. users list and enumerates each of them. If the connectionId matches then
  877. given callback function is called. If the ConnectionId is 0, then the
  878. callback is called for each and every connection active currently.
  879. During such a call the reference count of the connection is bumped up.
  880. Call this function after obtaining the ConnectionsList Lock.
  881. Arguments:
  882. pfnConnEnum pointer to function to be called when a match is found.
  883. pContext pointer to context information to be passed in
  884. for callback
  885. dwConnectionId DWORD containing the Connection Id. IF 0 match all the
  886. connections.
  887. Returns:
  888. FALSE if no match is found
  889. TRUE if atleast one match is found.
  890. --*/
  891. {
  892. BOOL fReturn = FALSE;
  893. BOOL fFoundOne = FALSE;
  894. PLIST_ENTRY pEntry;
  895. PLIST_ENTRY pEntryNext;
  896. DBG_ASSERT( pfnConnEnum != NULL);
  897. //
  898. // Loop through the list of connections and call the callback
  899. // for each connection that matches condition
  900. //
  901. for ( pEntry = m_ActiveConnectionsList.Flink,
  902. pEntryNext = &m_ActiveConnectionsList;
  903. pEntry != &m_ActiveConnectionsList;
  904. pEntry = pEntryNext
  905. ) {
  906. PICLIENT_CONNECTION pConn =
  907. GET_USER_DATA_FROM_LIST_ENTRY( pEntry);
  908. pEntryNext = pEntry->Flink; // cache next entry since pConn may die
  909. if ( dwConnectionId == 0 || dwConnectionId == pConn->QueryId()) {
  910. pConn->Reference();
  911. fReturn = ( pfnConnEnum)( pConn, pContext);
  912. if ( !pConn->DeReference()) {
  913. // Blowaway the connection and update the count of entries.
  914. //
  915. // Remove from list of connections
  916. //
  917. pConn->Cleanup();
  918. RemoveEntryList( &pConn->QueryListEntry());
  919. //
  920. // Decrement count of current users
  921. //
  922. m_cCurrentConnections--;
  923. IF_DEBUG( CLIENT) {
  924. DBGPRINTF((DBG_CONTEXT, " CurrentConnections = %u\n",
  925. m_cCurrentConnections));
  926. }
  927. }
  928. if (!fReturn) {
  929. break;
  930. }
  931. fFoundOne = TRUE;
  932. }
  933. } // for
  934. //
  935. // If we didn't find any, assume that there was no match.
  936. //
  937. if ( !fFoundOne ) {
  938. SetLastError( ERROR_NO_MORE_ITEMS );
  939. fReturn = FALSE;
  940. }
  941. return ( fReturn);
  942. } // FTP_SERVER_INSTANCE::EnumerateConnection()
  943. DWORD
  944. FTP_SERVER_INSTANCE::GetConfigInformation(OUT LPFTP_CONFIG_INFO pConfig)
  945. /*++
  946. This function copies the ftp server configuration into the given
  947. structure (pointed to).
  948. Arguments:
  949. pConfig -- pointer to FTP_CONFIG_INFO which on success will contain
  950. the ftp server configuration
  951. Returns:
  952. Win32 error code. NO_ERROR on success.
  953. --*/
  954. {
  955. DWORD dwError = NO_ERROR;
  956. memset( pConfig, 0, sizeof(*pConfig) );
  957. pConfig->FieldControl = FC_FTP_ALL;
  958. LockConfig();
  959. pConfig->fAllowAnonymous = m_fAllowAnonymous;
  960. pConfig->fAllowGuestAccess = m_fAllowGuestAccess;
  961. pConfig->fAnnotateDirectories = m_fAnnotateDirectories;
  962. pConfig->fAnonymousOnly = m_fAnonymousOnly;
  963. pConfig->dwListenBacklog = m_ListenBacklog;
  964. pConfig->fLowercaseFiles = m_fLowercaseFiles;
  965. pConfig->fMsdosDirOutput = m_fMsdosDirOutput;
  966. pConfig->dwUserIsolationMode = m_UserIsolationMode;
  967. pConfig->fLogInUtf8 = m_fLogInUtf8;
  968. if( !ConvertStringToRpc( &pConfig->lpszExitMessage,
  969. QueryExitMsg() ) ||
  970. !ConvertStringToRpc( &pConfig->lpszGreetingMessage,
  971. m_pszGreetingMessageWithLineFeed ) ||
  972. !ConvertStringToRpc( &pConfig->lpszBannerMessage,
  973. m_pszBannerMessageWithLineFeed ) ||
  974. !ConvertStringToRpc( &pConfig->lpszMaxClientsMessage,
  975. QueryMaxClientsMsg() ) )
  976. {
  977. dwError = GetLastError();
  978. }
  979. UnLockConfig();
  980. if ( dwError == NO_ERROR) {
  981. pConfig->lpszHomeDirectory = NULL; // use query virtual roots.
  982. }
  983. if ( dwError != NO_ERROR) {
  984. FreeRpcString( pConfig->lpszExitMessage );
  985. FreeRpcString( pConfig->lpszGreetingMessage );
  986. FreeRpcString( pConfig->lpszBannerMessage );
  987. FreeRpcString( pConfig->lpszHomeDirectory );
  988. FreeRpcString( pConfig->lpszMaxClientsMessage );
  989. }
  990. return (dwError);
  991. } // FTP_SERVER_INSTANCE::GetConfigurationInformation()
  992. // Private Functions ...
  993. BOOL
  994. FTP_SERVER_INSTANCE::FreeAllocCachedClientConn( VOID)
  995. /*++
  996. This function frees all the alloc cached client connections
  997. It walks through the list of alloc cached entries and frees them.
  998. This function should be called when Server module is terminated and when
  999. no other thread can interfere in processing a shared object.
  1000. Arguments:
  1001. NONE
  1002. Returns:
  1003. TRUE on success and FALSE on failure.
  1004. --*/
  1005. {
  1006. register PLIST_ENTRY pEntry;
  1007. register PLIST_ENTRY pEntryNext;
  1008. register PICLIENT_CONNECTION pConn;
  1009. for( pEntry = m_FreeConnectionsList.Flink;
  1010. pEntry != &m_FreeConnectionsList; ) {
  1011. PICLIENT_CONNECTION pConn =
  1012. GET_USER_DATA_FROM_LIST_ENTRY( pEntry);
  1013. pEntryNext = pEntry->Flink; // cache next entry since pConn may die
  1014. DBG_ASSERT( pConn->QueryReference() == 0);
  1015. RemoveEntryList( pEntry ); // Remove this context from list
  1016. // delete the object itself
  1017. delete pConn;
  1018. pEntry = pEntryNext;
  1019. } // for
  1020. return (TRUE);
  1021. } // USER_DATA::FreeAllocCachedClientConn()
  1022. PICLIENT_CONNECTION
  1023. FTP_SERVER_INSTANCE::AllocClientConnFromAllocCache(
  1024. VOID
  1025. )
  1026. /*++
  1027. This function attempts to allocate a client connection object from
  1028. the allocation cache, using the free list of connections available.
  1029. If none is available, then a new object is allocated using new ()
  1030. and returned to the caller.
  1031. Eventually the object will enter free list and will be available
  1032. for free use.
  1033. Arguments:
  1034. None
  1035. Returns:
  1036. On success a valid pointer to client connection object.
  1037. Issues:
  1038. This function should be called while holding the ConnectionsLock.
  1039. --*/
  1040. {
  1041. PLIST_ENTRY pEntry = m_FreeConnectionsList.Flink;
  1042. PICLIENT_CONNECTION pConn;
  1043. if ( pEntry != &m_FreeConnectionsList) {
  1044. pConn = GET_USER_DATA_FROM_LIST_ENTRY( pEntry);
  1045. DBG_ASSERT( pConn != NULL);
  1046. RemoveEntryList( pEntry); // remove entry from free list
  1047. DBG_ASSERT( pConn->QueryInstance() == NULL );
  1048. pConn->SetInstance( this );
  1049. } else {
  1050. //
  1051. // create a new object, since allocation cache is empty
  1052. //
  1053. pConn = new USER_DATA( this );
  1054. }
  1055. return (pConn);
  1056. } // FTP_SERVER_INSTANCE::AllocClientConnFromAllocCache()
  1057. VOID
  1058. FTP_SERVER_INSTANCE::FreeClientConnToAllocCache(
  1059. IN PICLIENT_CONNECTION pClient
  1060. )
  1061. /*++
  1062. This function releases the given Client connection to the allocation cache.
  1063. It adds the given object to allocation cache.
  1064. Arguments:
  1065. pClient pointer to client connection object which needs to be freed.
  1066. Returns:
  1067. None
  1068. Issues:
  1069. This function should be called after holding the ConnectionsList
  1070. critical section.
  1071. Should we limit the number of items that can be on free list and
  1072. to release the remaining to global pool? NYI (depends on # CPUs)
  1073. --*/
  1074. {
  1075. PLIST_ENTRY pEntry = &pClient->QueryListEntry();
  1076. //
  1077. // empty out instance pointer
  1078. //
  1079. pClient->QueryInstance()->DecrementCurrentConnections();
  1080. pClient->QueryInstance()->Dereference( );
  1081. pClient->SetInstance( NULL );
  1082. InsertHeadList( &m_FreeConnectionsList, pEntry);
  1083. return;
  1084. } // FTP_SERVER_INSTANCE::FreeClientConnToAllocCache()
  1085. /*******************************************************************
  1086. NAME: GetDefaultDomainName
  1087. SYNOPSIS: Fills in the given array with the name of the default
  1088. domain to use for logon validation.
  1089. ENTRY: pszDomainName - Pointer to a buffer that will receive
  1090. the default domain name.
  1091. cchDomainName - The size (in charactesr) of the domain
  1092. name buffer.
  1093. RETURNS: APIERR - 0 if successful, !0 if not.
  1094. HISTORY:
  1095. KeithMo 05-Dec-1994 Created.
  1096. ********************************************************************/
  1097. APIERR
  1098. GetDefaultDomainName(
  1099. STR * pstrDomainName
  1100. )
  1101. {
  1102. OBJECT_ATTRIBUTES ObjectAttributes;
  1103. NTSTATUS NtStatus;
  1104. INT Result;
  1105. APIERR err = 0;
  1106. LSA_HANDLE LsaPolicyHandle = NULL;
  1107. PPOLICY_ACCOUNT_DOMAIN_INFO DomainInfo = NULL;
  1108. //
  1109. // Open a handle to the local machine's LSA policy object.
  1110. //
  1111. InitializeObjectAttributes( &ObjectAttributes, // object attributes
  1112. NULL, // name
  1113. 0L, // attributes
  1114. NULL, // root directory
  1115. NULL ); // security descriptor
  1116. NtStatus = LsaOpenPolicy( NULL, // system name
  1117. &ObjectAttributes, // object attributes
  1118. POLICY_EXECUTE, // access mask
  1119. &LsaPolicyHandle ); // policy handle
  1120. if( !NT_SUCCESS( NtStatus ) )
  1121. {
  1122. DBGPRINTF(( DBG_CONTEXT,
  1123. "cannot open lsa policy, error %08lX\n",
  1124. NtStatus ));
  1125. err = LsaNtStatusToWinError( NtStatus );
  1126. goto Cleanup;
  1127. }
  1128. //
  1129. // Query the domain information from the policy object.
  1130. //
  1131. NtStatus = LsaQueryInformationPolicy( LsaPolicyHandle,
  1132. PolicyAccountDomainInformation,
  1133. (PVOID *)&DomainInfo );
  1134. if( !NT_SUCCESS( NtStatus ) )
  1135. {
  1136. DBGPRINTF(( DBG_CONTEXT,
  1137. "cannot query lsa policy info, error %08lX\n",
  1138. NtStatus ));
  1139. err = LsaNtStatusToWinError( NtStatus );
  1140. goto Cleanup;
  1141. }
  1142. //
  1143. // Compute the required length of the ANSI name.
  1144. //
  1145. Result = WideCharToMultiByte( CP_ACP,
  1146. 0, // dwFlags
  1147. (LPCWSTR)DomainInfo->DomainName.Buffer,
  1148. DomainInfo->DomainName.Length /sizeof(WCHAR),
  1149. NULL, // lpMultiByteStr
  1150. 0, // cchMultiByte
  1151. NULL, // lpDefaultChar
  1152. NULL // lpUsedDefaultChar
  1153. );
  1154. if( Result <= 0 )
  1155. {
  1156. err = GetLastError();
  1157. goto Cleanup;
  1158. }
  1159. //
  1160. // Resize the output string as appropriate, including room for the
  1161. // terminating '\0'.
  1162. //
  1163. if( !pstrDomainName->Resize( (UINT)Result + 1 ) )
  1164. {
  1165. err = GetLastError();
  1166. goto Cleanup;
  1167. }
  1168. //
  1169. // Convert the name from UNICODE to ANSI.
  1170. //
  1171. Result = WideCharToMultiByte( CP_ACP,
  1172. 0, // flags
  1173. (LPCWSTR)DomainInfo->DomainName.Buffer,
  1174. DomainInfo->DomainName.Length /sizeof(WCHAR),
  1175. pstrDomainName->QueryStr(),
  1176. pstrDomainName->QuerySize() - 1, // for '\0'
  1177. NULL,
  1178. NULL
  1179. );
  1180. if( Result <= 0 )
  1181. {
  1182. err = GetLastError();
  1183. DBGPRINTF(( DBG_CONTEXT,
  1184. "cannot convert domain name to ANSI, error %d\n",
  1185. err ));
  1186. goto Cleanup;
  1187. }
  1188. //
  1189. // Ensure the ANSI string is zero terminated.
  1190. //
  1191. DBG_ASSERT( (DWORD)Result < pstrDomainName->QuerySize() );
  1192. pstrDomainName->QueryStr()[Result] = '\0';
  1193. //
  1194. // Success!
  1195. //
  1196. DBG_ASSERT( err == 0 );
  1197. IF_DEBUG( CONFIG )
  1198. {
  1199. DBGPRINTF(( DBG_CONTEXT,
  1200. "GetDefaultDomainName: default domain = %s\n",
  1201. pstrDomainName->QueryStr() ));
  1202. }
  1203. Cleanup:
  1204. if( DomainInfo != NULL )
  1205. {
  1206. LsaFreeMemory( (PVOID)DomainInfo );
  1207. }
  1208. if( LsaPolicyHandle != NULL )
  1209. {
  1210. LsaClose( LsaPolicyHandle );
  1211. }
  1212. return err;
  1213. } // GetDefaultDomainName()
  1214. BOOL
  1215. GenMessageWithLineFeed(IN LPTSTR pszzMessage,
  1216. IN LPTSTR * ppszMessageWithLineFeed)
  1217. {
  1218. DWORD cchLen = 0;
  1219. DWORD cchLen2;
  1220. DWORD nLines = 0;
  1221. LPCTSTR pszNext = pszzMessage;
  1222. LPTSTR pszDst = NULL;
  1223. DBG_ASSERT( ppszMessageWithLineFeed != NULL);
  1224. //
  1225. // 1. Find the length of the the complete message
  1226. //
  1227. for ( cchLen = _tcslen( pszzMessage), nLines = 0;
  1228. *(pszzMessage + cchLen + 1) != TEXT('\0');
  1229. cchLen += 1+_tcslen( pszzMessage + cchLen + 1), nLines++
  1230. )
  1231. ;
  1232. //
  1233. // 2. Allocate sufficient space to hold the data
  1234. //
  1235. if ( *ppszMessageWithLineFeed != NULL) {
  1236. TCP_FREE( *ppszMessageWithLineFeed);
  1237. }
  1238. *ppszMessageWithLineFeed = (TCHAR *) TCP_ALLOC((cchLen + nLines + 3)
  1239. * sizeof(TCHAR));
  1240. if ( *ppszMessageWithLineFeed == NULL) {
  1241. SetLastError( ERROR_NOT_ENOUGH_MEMORY);
  1242. return (FALSE);
  1243. }
  1244. //
  1245. // 3.
  1246. // Copy the message from double null terminated string to the
  1247. // new string, taking care to replace the nulls with \n for linefeed
  1248. //
  1249. pszDst = * ppszMessageWithLineFeed;
  1250. _tcscpy( pszDst, pszzMessage);
  1251. cchLen2 = _tcslen( pszzMessage) + 1;
  1252. *(pszDst+cchLen2 - 1) = TEXT('\n'); // replacing the '\0' with '\n'
  1253. for( pszNext = pszzMessage + cchLen2;
  1254. *pszNext != '\0';
  1255. pszNext = pszzMessage + cchLen2
  1256. ) {
  1257. _tcscpy( pszDst + cchLen2, pszNext);
  1258. cchLen2 += _tcslen(pszNext) + 1;
  1259. *(pszDst + cchLen2 - 1) = TCHAR('\n'); // replacing the '\0' with '\n'
  1260. } // for
  1261. //
  1262. // Reset the last line feed.
  1263. //
  1264. *(pszDst + cchLen2 - 1) = TCHAR('\0');
  1265. // if following assertion is not true, we are writing into heap!!!
  1266. if ( cchLen + nLines + 3 <= cchLen2) {
  1267. return ( FALSE);
  1268. }
  1269. DBG_ASSERT( cchLen + nLines + 3 >= cchLen2);
  1270. return ( TRUE);
  1271. } // GenMessageWithLineFeed()
  1272. TCHAR *
  1273. FtpdReadRegistryString(IN HKEY hkey,
  1274. IN LPCTSTR pszValueName,
  1275. IN LPCTSTR pchDefaultValue,
  1276. IN DWORD cbDefaultValue)
  1277. /*++
  1278. This function reads a string (REG_SZ/REG_MULTI_SZ/REG_EXPAND_SZ) without
  1279. expanding the same. It allocates memory for reading the data from registry.
  1280. Arguments:
  1281. hkey handle for the registry key.
  1282. pszValueName pointer to string containing the name of value to be read.
  1283. pchDefaultValue pointer to default value to be used for reading the string
  1284. this may be double null terminated sequence of string for
  1285. REG_MULTI_SZ strings
  1286. cchDefaultValue count of characters in default value string,
  1287. including double null characters.
  1288. Return:
  1289. pointer to newly allocated string containing the data read from registry
  1290. or the default string.
  1291. --*/
  1292. {
  1293. TCHAR * pszBuffer1 = NULL;
  1294. DWORD err;
  1295. if( hkey == NULL ) {
  1296. //
  1297. // Pretend the key wasn't found.
  1298. //
  1299. err = ERROR_FILE_NOT_FOUND;
  1300. } else {
  1301. DWORD cbBuffer = 0;
  1302. DWORD dwType;
  1303. //
  1304. // Determine the buffer size.
  1305. //
  1306. err = RegQueryValueEx( hkey,
  1307. pszValueName,
  1308. NULL,
  1309. &dwType,
  1310. NULL,
  1311. &cbBuffer );
  1312. if( ( err == NO_ERROR ) || ( err == ERROR_MORE_DATA ) ) {
  1313. if(( dwType != REG_SZ ) &&
  1314. ( dwType != REG_MULTI_SZ ) &&
  1315. ( dwType != REG_EXPAND_SZ )
  1316. ) {
  1317. //
  1318. // Type mismatch, registry data NOT a string.
  1319. // Use default.
  1320. //
  1321. err = ERROR_FILE_NOT_FOUND;
  1322. } else {
  1323. //
  1324. // Item found, allocate a buffer.
  1325. //
  1326. pszBuffer1 = (TCHAR *) TCP_ALLOC( cbBuffer+sizeof(TCHAR) );
  1327. if( pszBuffer1 == NULL ) {
  1328. err = GetLastError();
  1329. } else {
  1330. //
  1331. // Now read the value into the buffer.
  1332. //
  1333. err = RegQueryValueEx( hkey,
  1334. pszValueName,
  1335. NULL,
  1336. NULL,
  1337. (LPBYTE)pszBuffer1,
  1338. &cbBuffer );
  1339. }
  1340. }
  1341. }
  1342. }
  1343. if( err == ERROR_FILE_NOT_FOUND ) {
  1344. //
  1345. // Item not found, use default value.
  1346. //
  1347. err = NO_ERROR;
  1348. if( pchDefaultValue != NULL ) {
  1349. if ( pszBuffer1 != NULL) {
  1350. TCP_FREE( pszBuffer1);
  1351. }
  1352. pszBuffer1 = (TCHAR *)TCP_ALLOC((cbDefaultValue) *
  1353. sizeof(TCHAR));
  1354. if( pszBuffer1 == NULL ) {
  1355. err = GetLastError();
  1356. } else {
  1357. memcpy(pszBuffer1, pchDefaultValue,
  1358. cbDefaultValue*sizeof(TCHAR) );
  1359. }
  1360. }
  1361. }
  1362. if( err != NO_ERROR ) {
  1363. //
  1364. // Something tragic happend; free any allocated buffers
  1365. // and return NULL to the caller, indicating failure.
  1366. //
  1367. if( pszBuffer1 != NULL ) {
  1368. TCP_FREE( pszBuffer1 );
  1369. pszBuffer1 = NULL;
  1370. }
  1371. SetLastError( err);
  1372. }
  1373. return pszBuffer1;
  1374. } // FtpdReadRegistryString()
  1375. BOOL
  1376. FtpdReadRegString(
  1377. IN HKEY hkey,
  1378. OUT TCHAR * * ppchstr,
  1379. IN LPCTSTR pchValue,
  1380. IN LPCTSTR pchDefault,
  1381. IN DWORD cchDefault
  1382. )
  1383. /*++
  1384. Description
  1385. Gets the specified string from the registry. If *ppchstr is not NULL,
  1386. then the value is freed. If the registry call fails, *ppchstr is
  1387. restored to its previous value.
  1388. Arguments:
  1389. hkey - Handle to open key
  1390. ppchstr - Receives pointer of allocated memory of the new value of the
  1391. string
  1392. pchValue - Which registry value to retrieve
  1393. pchDefault - Default string if value isn't found
  1394. cchDefault - count of characters in default value
  1395. Note:
  1396. --*/
  1397. {
  1398. CHAR * pch = *ppchstr;
  1399. *ppchstr = FtpdReadRegistryString(hkey,
  1400. pchValue,
  1401. pchDefault,
  1402. cchDefault);
  1403. if ( !*ppchstr )
  1404. {
  1405. *ppchstr = pch;
  1406. return FALSE;
  1407. }
  1408. if ( pch ) {
  1409. //
  1410. // use TCP_FREE since FtpdReadRegistryString() uses TCP_ALLOC
  1411. // to allocate the chunk of memory
  1412. //
  1413. TCP_FREE( pch );
  1414. }
  1415. return TRUE;
  1416. } // FtpdReadRegString()
  1417. BOOL
  1418. FTP_IIS_SERVICE::AddInstanceInfo(
  1419. IN DWORD dwInstance,
  1420. IN BOOL fMigrateRoots
  1421. )
  1422. {
  1423. PFTP_SERVER_INSTANCE pInstance;
  1424. CHAR szHost[MAXGETHOSTSTRUCT];
  1425. IF_DEBUG(SERVICE_CTRL) {
  1426. DBGPRINTF(( DBG_CONTEXT,
  1427. "AddInstanceInfo: instance %d reg %s\n", dwInstance, QueryRegParamKey() ));
  1428. }
  1429. // Guard against startup race where another thread might be adding
  1430. // instances before the MSFTPSVC thread is finished with initializing
  1431. // the g_pInetSvc pointer.
  1432. if ( g_pInetSvc == NULL )
  1433. {
  1434. SetLastError( ERROR_NOT_SUPPORTED );
  1435. return FALSE;
  1436. }
  1437. //
  1438. // Get the current host name.
  1439. //
  1440. if( gethostname( szHost, sizeof(szHost) ) < 0 ) {
  1441. return FALSE;
  1442. }
  1443. //
  1444. // Create the new instance
  1445. //
  1446. pInstance = new FTP_SERVER_INSTANCE(
  1447. this,
  1448. dwInstance,
  1449. IPPORT_FTP,
  1450. QueryRegParamKey(),
  1451. FTPD_ANONYMOUS_SECRET_W,
  1452. FTPD_ROOT_SECRET_W,
  1453. fMigrateRoots
  1454. );
  1455. if (pInstance == NULL) {
  1456. SetLastError( E_OUTOFMEMORY );
  1457. return FALSE;
  1458. }
  1459. if( !AddInstanceInfoHelper( pInstance ) ) {
  1460. return FALSE;
  1461. }
  1462. if( pInstance->SetLocalHostName( szHost ) != NO_ERROR ) {
  1463. RemoveServerInstance( pInstance );
  1464. return FALSE;
  1465. }
  1466. return TRUE;
  1467. } // FTP_IIS_SERVICE::AddInstanceInfo
  1468. DWORD
  1469. FTP_IIS_SERVICE::DisconnectUsersByInstance(
  1470. IN IIS_SERVER_INSTANCE * pInstance
  1471. )
  1472. /*++
  1473. Virtual callback invoked by IIS_SERVER_INSTANCE::StopInstance() to
  1474. disconnect all users associated with the given instance.
  1475. Arguments:
  1476. pInstance - All users associated with this instance will be
  1477. forcibly disconnected.
  1478. --*/
  1479. {
  1480. ((FTP_SERVER_INSTANCE *)pInstance)->DisconnectAllConnections();
  1481. return NO_ERROR;
  1482. } // FTP_IIS_SERVICE::DisconnectUsersByInstance
  1483. VOID
  1484. FTP_SERVER_INSTANCE::MDChangeNotify(
  1485. MD_CHANGE_OBJECT * pco
  1486. )
  1487. /*++
  1488. Handles metabase change notifications.
  1489. Arguments:
  1490. pco - Path and ID that changed.
  1491. --*/
  1492. {
  1493. FIELD_CONTROL control = 0;
  1494. DWORD i;
  1495. DWORD err;
  1496. DWORD id;
  1497. PCSTR pszURL;
  1498. DWORD dwURLLength;
  1499. //
  1500. // Let the parent deal with it.
  1501. //
  1502. IIS_SERVER_INSTANCE::MDChangeNotify( pco );
  1503. //
  1504. // Now flush the metacache and relevant file handle cache entries.
  1505. //
  1506. TsFlushMetaCache(METACACHE_FTP_SERVER_ID, FALSE);
  1507. if ( !_mbsnbicmp((PUCHAR)pco->pszMDPath, (PUCHAR)QueryMDVRPath(),
  1508. _mbslen( (PUCHAR)QueryMDVRPath() )) )
  1509. {
  1510. pszURL = (CHAR *)pco->pszMDPath + QueryMDVRPathLen() - 1;
  1511. //
  1512. // Figure out the length of the URL. Unless this is the root,
  1513. // we want to strip the trailing slash.
  1514. if (memcmp(pszURL, "/", sizeof("/")) != 0)
  1515. {
  1516. dwURLLength = strlen(pszURL) - 1;
  1517. }
  1518. else
  1519. {
  1520. dwURLLength = sizeof("/") - 1;
  1521. }
  1522. }
  1523. else
  1524. {
  1525. //
  1526. // Presumably this is for a change above the root URL level, i.e. a
  1527. // change of a property at the service level. Since this affects
  1528. // everything, flush starting at the root.
  1529. //
  1530. pszURL = "/";
  1531. dwURLLength = sizeof("/") - 1;
  1532. }
  1533. DBG_ASSERT(pszURL != NULL);
  1534. DBG_ASSERT(*pszURL != '\0');
  1535. TsFlushURL(GetTsvcCache(), pszURL, dwURLLength, RESERVED_DEMUX_URI_INFO);
  1536. //
  1537. // Interpret the changes.
  1538. //
  1539. for( i = 0 ; i < pco->dwMDNumDataIDs ; i++ ) {
  1540. id = pco->pdwMDDataIDs[i];
  1541. switch( id ) {
  1542. case MD_EXIT_MESSAGE :
  1543. control |= FC_FTP_EXIT_MESSAGE;
  1544. break;
  1545. case MD_GREETING_MESSAGE :
  1546. control |= FC_FTP_GREETING_MESSAGE;
  1547. break;
  1548. case MD_BANNER_MESSAGE :
  1549. control |= FC_FTP_BANNER_MESSAGE;
  1550. break;
  1551. case MD_MAX_CLIENTS_MESSAGE :
  1552. control |= FC_FTP_MAX_CLIENTS_MESSAGE;
  1553. break;
  1554. case MD_MSDOS_DIR_OUTPUT :
  1555. control |= FC_FTP_MSDOS_DIR_OUTPUT;
  1556. break;
  1557. case MD_ALLOW_ANONYMOUS :
  1558. control |= FC_FTP_ALLOW_ANONYMOUS;
  1559. break;
  1560. case MD_ANONYMOUS_ONLY :
  1561. control |= FC_FTP_ANONYMOUS_ONLY;
  1562. break;
  1563. case MD_ALLOW_REPLACE_ON_RENAME :
  1564. control |= FC_FTP_ALLOW_REPLACE_ON_RENAME;
  1565. break;
  1566. case MD_SHOW_4_DIGIT_YEAR :
  1567. control |= FC_FTP_SHOW_4_DIGIT_YEAR;
  1568. break;
  1569. case MD_USER_ISOLATION :
  1570. control |= FC_FTP_USER_ISOLATION;
  1571. break;
  1572. case MD_FTP_LOG_IN_UTF_8 :
  1573. control |= FC_FTP_LOG_IN_UTF_8;
  1574. break;
  1575. case MD_ANONYMOUS_USER_NAME :
  1576. case MD_ANONYMOUS_PWD :
  1577. case MD_ANONYMOUS_USE_SUBAUTH :
  1578. case MD_DEFAULT_LOGON_DOMAIN :
  1579. case MD_LOGON_METHOD :
  1580. err = ReadAuthentInfo( FALSE, id );
  1581. if( err != NO_ERROR ) {
  1582. DBGPRINTF((
  1583. DBG_CONTEXT,
  1584. "FTP_SERVER_INSTANCE::MDChangeNotify() cannot read authentication info, error %d\n",
  1585. err
  1586. ));
  1587. }
  1588. break;
  1589. }
  1590. }
  1591. if( control != 0 ) {
  1592. err = InitFromRegistry( control );
  1593. if( err != NO_ERROR ) {
  1594. DBGPRINTF((
  1595. DBG_CONTEXT,
  1596. "FTP_SERVER_INSTANCE::MDChangeNotify() cannot read config, error %lx\n",
  1597. err
  1598. ));
  1599. }
  1600. }
  1601. } // FTP_SERVER_INSTANCE::MDChangeNotify
  1602. DWORD
  1603. FTP_SERVER_INSTANCE::ReadAuthentInfo(
  1604. IN BOOL ReadAll,
  1605. IN DWORD SingleItemToRead
  1606. )
  1607. /*++
  1608. Reads per-instance authentication info from the metabase.
  1609. Arguments:
  1610. ReadAll - If TRUE, then all authentication related items are
  1611. read from the metabase. If FALSE, then only a single item
  1612. is read.
  1613. SingleItemToRead - The single authentication item to read if
  1614. ReadAll is FALSE. Ignored if ReadAll is TRUE.
  1615. Returns:
  1616. DWORD - 0 if successful, !0 otherwise.
  1617. --*/
  1618. {
  1619. DWORD tmp;
  1620. DWORD err = NO_ERROR;
  1621. BOOL rebuildAcctDesc = FALSE;
  1622. MB mb( (IMDCOM*)g_pInetSvc->QueryMDObject() );
  1623. //
  1624. // Lock our configuration (since we'll presumably be making changes)
  1625. // and open the metabase.
  1626. //
  1627. LockConfig();
  1628. if( !mb.Open( QueryMDPath() ) ) {
  1629. err = GetLastError();
  1630. DBGPRINTF((
  1631. DBG_CONTEXT,
  1632. "ReadAuthentInfo: cannot open metabase, error %lx\n",
  1633. err
  1634. ));
  1635. }
  1636. //
  1637. // Read the anonymous username if necessary. Note this is a REQUIRED
  1638. // property. If it is missing from the metabase, bail.
  1639. //
  1640. if( err == NO_ERROR &&
  1641. ( ReadAll || SingleItemToRead == MD_ANONYMOUS_USER_NAME ) ) {
  1642. if( mb.GetStr(
  1643. "",
  1644. MD_ANONYMOUS_USER_NAME,
  1645. IIS_MD_UT_SERVER,
  1646. &m_TcpAuthentInfo.strAnonUserName
  1647. ) ) {
  1648. rebuildAcctDesc = TRUE;
  1649. } else {
  1650. err = GetLastError();
  1651. DBGPRINTF((
  1652. DBG_CONTEXT,
  1653. "ReadAuthentInfo: cannot read MD_ANONYMOUS_USER_NAME, error %lx\n",
  1654. err
  1655. ));
  1656. }
  1657. }
  1658. //
  1659. // Read the "use subauthenticator" flag if necessary. This is an
  1660. // optional property.
  1661. //
  1662. if( err == NO_ERROR &&
  1663. ( ReadAll || SingleItemToRead == MD_ANONYMOUS_USE_SUBAUTH ) ) {
  1664. if( !mb.GetDword(
  1665. "",
  1666. MD_ANONYMOUS_USE_SUBAUTH,
  1667. IIS_MD_UT_SERVER,
  1668. &tmp
  1669. ) ) {
  1670. tmp = DEFAULT_USE_SUBAUTH;
  1671. }
  1672. m_TcpAuthentInfo.fDontUseAnonSubAuth = !tmp;
  1673. }
  1674. //
  1675. // Read the anonymous password if necessary. This is an optional
  1676. // property.
  1677. //
  1678. if( err == NO_ERROR &&
  1679. ( ReadAll || SingleItemToRead == MD_ANONYMOUS_PWD ) ) {
  1680. if( mb.GetStr(
  1681. "",
  1682. MD_ANONYMOUS_PWD,
  1683. IIS_MD_UT_SERVER,
  1684. &m_TcpAuthentInfo.strAnonUserPassword,
  1685. METADATA_INHERIT,
  1686. DEFAULT_ANONYMOUS_PWD
  1687. ) ) {
  1688. rebuildAcctDesc = TRUE;
  1689. } else {
  1690. //
  1691. // Since we provided a default value to mb.GetStr(), it should
  1692. // only fail if something catastrophic occurred, such as an
  1693. // out of memory condition.
  1694. //
  1695. err = GetLastError();
  1696. DBGPRINTF((
  1697. DBG_CONTEXT,
  1698. "ReadAuthentInfo: cannot read MD_ANONYMOUS_PWD, error %lx\n",
  1699. err
  1700. ));
  1701. }
  1702. }
  1703. //
  1704. // Read the default logon domain if necessary. This is an optional
  1705. // property.
  1706. //
  1707. if( err == NO_ERROR &&
  1708. ( ReadAll || SingleItemToRead == MD_DEFAULT_LOGON_DOMAIN ) ) {
  1709. if( !mb.GetStr(
  1710. "",
  1711. MD_DEFAULT_LOGON_DOMAIN,
  1712. IIS_MD_UT_SERVER,
  1713. &m_TcpAuthentInfo.strDefaultLogonDomain
  1714. ) ) {
  1715. //
  1716. // Generate a default domain name.
  1717. //
  1718. err = GetDefaultDomainName( &m_TcpAuthentInfo.strDefaultLogonDomain );
  1719. if( err != NO_ERROR ) {
  1720. DBGPRINTF((
  1721. DBG_CONTEXT,
  1722. "ReadAuthentInfo: cannot get default domain name, error %d\n",
  1723. err
  1724. ));
  1725. }
  1726. }
  1727. }
  1728. //
  1729. // Read the logon method if necessary. This is an optional property.
  1730. //
  1731. if( err == NO_ERROR &&
  1732. ( ReadAll || SingleItemToRead == MD_LOGON_METHOD ) ) {
  1733. if( !mb.GetDword(
  1734. "",
  1735. MD_LOGON_METHOD,
  1736. IIS_MD_UT_SERVER,
  1737. &tmp
  1738. ) ) {
  1739. tmp = DEFAULT_LOGON_METHOD;
  1740. }
  1741. m_TcpAuthentInfo.dwLogonMethod = tmp;
  1742. }
  1743. //
  1744. // If anything changed that could affect the anonymous account
  1745. // descriptor, then rebuild the descriptor.
  1746. //
  1747. if( err == NO_ERROR && rebuildAcctDesc ) {
  1748. if( !BuildAnonymousAcctDesc( &m_TcpAuthentInfo ) ) {
  1749. DBGPRINTF((
  1750. DBG_CONTEXT,
  1751. "ReadAuthentInfo: BuildAnonymousAcctDesc() failed\n"
  1752. ));
  1753. err = ERROR_NOT_ENOUGH_MEMORY; // SWAG
  1754. }
  1755. }
  1756. UnLockConfig();
  1757. return err;
  1758. } // FTP_SERVER_INSTANCE::ReadAuthentInfo
  1759. BOOL
  1760. FTP_IIS_SERVICE::GetGlobalStatistics(
  1761. IN DWORD dwLevel,
  1762. OUT PCHAR *pBuffer
  1763. )
  1764. {
  1765. APIERR err = NO_ERROR;
  1766. switch( dwLevel ) {
  1767. case 0 : {
  1768. LPFTP_STATISTICS_0 pstats0;
  1769. pstats0 = (LPFTP_STATISTICS_0)
  1770. MIDL_user_allocate(sizeof(FTP_STATISTICS_0));
  1771. if( pstats0 == NULL ) {
  1772. err = ERROR_NOT_ENOUGH_MEMORY;
  1773. } else {
  1774. ATQ_STATISTICS atqStat;
  1775. ZeroMemory( pstats0, sizeof( FTP_STATISTICS_0 ) );
  1776. g_pFTPStats->CopyToStatsBuffer( pstats0 );
  1777. *pBuffer = (PCHAR)pstats0;
  1778. }
  1779. }
  1780. break;
  1781. default :
  1782. err = ERROR_INVALID_LEVEL;
  1783. break;
  1784. }
  1785. SetLastError(err);
  1786. return(err == NO_ERROR);
  1787. } // FTP_IIS_SERVICE::GetGlobalStatistics
  1788. BOOL
  1789. FTP_IIS_SERVICE::AggregateStatistics(
  1790. IN PCHAR pDestination,
  1791. IN PCHAR pSource
  1792. )
  1793. {
  1794. LPFTP_STATISTICS_0 pStatDest = (LPFTP_STATISTICS_0) pDestination;
  1795. LPFTP_STATISTICS_0 pStatSrc = (LPFTP_STATISTICS_0) pSource;
  1796. if ((NULL == pDestination) || (NULL == pSource))
  1797. {
  1798. return FALSE;
  1799. }
  1800. pStatDest->TotalBytesSent.QuadPart += pStatSrc->TotalBytesSent.QuadPart;
  1801. pStatDest->TotalBytesReceived.QuadPart += pStatSrc->TotalBytesReceived.QuadPart;
  1802. pStatDest->TotalFilesSent += pStatSrc->TotalFilesSent;
  1803. pStatDest->TotalFilesReceived += pStatSrc->TotalFilesReceived;
  1804. pStatDest->CurrentAnonymousUsers += pStatSrc->CurrentAnonymousUsers;
  1805. pStatDest->CurrentNonAnonymousUsers += pStatSrc->CurrentNonAnonymousUsers;
  1806. pStatDest->TotalAnonymousUsers += pStatSrc->TotalAnonymousUsers;
  1807. pStatDest->MaxAnonymousUsers += pStatSrc->MaxAnonymousUsers;
  1808. pStatDest->MaxNonAnonymousUsers += pStatSrc->MaxNonAnonymousUsers;
  1809. pStatDest->CurrentConnections += pStatSrc->CurrentConnections;
  1810. pStatDest->MaxConnections += pStatSrc->MaxConnections;
  1811. pStatDest->ConnectionAttempts += pStatSrc->ConnectionAttempts;
  1812. pStatDest->LogonAttempts += pStatSrc->LogonAttempts;
  1813. pStatDest->ServiceUptime = pStatSrc->ServiceUptime;
  1814. // bandwidth throttling info. Not relevant for FTP
  1815. /*
  1816. pStatDest->CurrentBlockedRequests += pStatSrc->CurrentBlockedRequests;
  1817. pStatDest->TotalBlockedRequests += pStatSrc->TotalBlockedRequests;
  1818. pStatDest->TotalAllowedRequests += pStatSrc->TotalAllowedRequests;
  1819. pStatDest->TotalRejectedRequests += pStatSrc->TotalRejectedRequests;
  1820. pStatDest->MeasuredBandwidth += pStatSrc->MeasuredBandwidth;
  1821. */
  1822. return TRUE;
  1823. }