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.

173 lines
3.9 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1998
  5. //
  6. // File: Catalog.cxx
  7. //
  8. // Contents: Used to manage catalog(s) state
  9. //
  10. // History: 27-Nov-1996 KyleP Created
  11. //
  12. //--------------------------------------------------------------------------
  13. #include <pch.cxx>
  14. #pragma hdrstop
  15. #include <catalog.hxx>
  16. #include <catadmin.hxx>
  17. extern "C"
  18. {
  19. #include <lmcons.h>
  20. }
  21. #include <cisecret.hxx>
  22. //
  23. // Global data
  24. //
  25. SScopeColumn coldefScope[] = { { CScope::GetPath, MSG_COL_ROOT },
  26. { CScope::GetAlias, MSG_COL_ALIAS },
  27. { CScope::GetInclude, MSG_COL_EXCLUDE }
  28. };
  29. BOOL CScope::_fFirstTime = TRUE;
  30. CScope::CScope( CCatalog & cat,
  31. WCHAR const * pwcsPath,
  32. WCHAR const * pwcsAlias,
  33. BOOL fExclude,
  34. BOOL fVirtual,
  35. BOOL fShadowAlias )
  36. : _pwcsPath( 0 ),
  37. _pwcsAlias( 0 ),
  38. _fExclude( fExclude ),
  39. _fVirtual( fVirtual ),
  40. _fShadowAlias( fShadowAlias ),
  41. _fZombie( FALSE ),
  42. _cat( cat )
  43. {
  44. TRY
  45. {
  46. Set( pwcsPath, _pwcsPath );
  47. Set( pwcsAlias, _pwcsAlias );
  48. }
  49. CATCH( CException, e )
  50. {
  51. delete [] _pwcsPath;
  52. delete [] _pwcsAlias;
  53. RETHROW();
  54. }
  55. END_CATCH
  56. }
  57. CScope::~CScope()
  58. {
  59. delete [] _pwcsPath;
  60. delete [] _pwcsAlias;
  61. }
  62. void CScope::Modify(WCHAR const * pwcsPath,
  63. WCHAR const * pwcsAlias,
  64. BOOL fExclude)
  65. {
  66. Win4Assert( !IsZombie() );
  67. Reset( pwcsPath, _pwcsPath );
  68. Reset( pwcsAlias, _pwcsAlias );
  69. _fExclude = fExclude;
  70. }
  71. void CScope::InitHeader( CListViewHeader & Header )
  72. {
  73. //
  74. // Initialize header
  75. //
  76. for ( unsigned i = 0; i < sizeof(coldefScope)/sizeof(coldefScope[0]); i++ )
  77. {
  78. if ( _fFirstTime )
  79. coldefScope[i].srTitle.Init( ghInstance );
  80. Header.Add( i, STRINGRESOURCE(coldefScope[i].srTitle), LVCFMT_LEFT, MMCLV_AUTO );
  81. }
  82. _fFirstTime = FALSE;
  83. }
  84. void CScope::Set( WCHAR const * pwcsSrc, WCHAR * & pwcsDst )
  85. {
  86. if ( 0 == pwcsSrc )
  87. {
  88. pwcsDst = new WCHAR[1];
  89. RtlCopyMemory( pwcsDst, L"", sizeof(WCHAR) );
  90. }
  91. else
  92. {
  93. unsigned cc = wcslen( pwcsSrc ) + 1;
  94. pwcsDst = new WCHAR [cc];
  95. RtlCopyMemory( pwcsDst, pwcsSrc, cc * sizeof(WCHAR) );
  96. }
  97. }
  98. void CScope::Reset( WCHAR const * pwcsSrc, WCHAR * & pwcsDst )
  99. {
  100. delete pwcsDst;
  101. Set(pwcsSrc, pwcsDst);
  102. }
  103. void CScope::Rescan( BOOL fFull )
  104. {
  105. _cat.RescanScope( _pwcsPath, fFull );
  106. }
  107. // The username and password are not stored locally. They will
  108. // be retrieved on demand from the catadmin object.
  109. SCODE CScope::GetUsername(WCHAR *pwszLogon)
  110. {
  111. SCODE sc = S_OK;
  112. TRY
  113. {
  114. //
  115. // First, remove from CI.
  116. //
  117. CMachineAdmin MachineAdmin( _cat.GetMachine() );
  118. XPtr<CCatalogAdmin> xCatalogAdmin( MachineAdmin.QueryCatalogAdmin( _cat.GetCat(TRUE) ) );
  119. XPtr<CScopeAdmin> xScopeAdmin( xCatalogAdmin->QueryScopeAdmin(_pwcsPath) );
  120. if ( !xScopeAdmin.IsNull() )
  121. wcscpy(pwszLogon, xScopeAdmin->GetLogon());
  122. }
  123. CATCH (CException, e)
  124. {
  125. sc = e.GetErrorCode();
  126. }
  127. END_CATCH
  128. return sc;
  129. }
  130. SCODE CScope::GetPassword(WCHAR *pwszPassword)
  131. {
  132. WCHAR szLogon[UNLEN + 1];
  133. szLogon[0] = 0;
  134. GetUsername(szLogon);
  135. *pwszPassword = 0;
  136. BOOL fOK = TRUE;
  137. // don't attempt to get pwd of a NULL logon name!
  138. if (0 != szLogon[0])
  139. CiGetPassword(_cat.GetCat(TRUE), szLogon, pwszPassword);
  140. return fOK ? S_OK:S_FALSE;
  141. }