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.

207 lines
6.4 KiB

  1. ///+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (c) Microsoft Corporation, 1996 - 2000.
  5. //
  6. // File: regscp.hxx
  7. //
  8. // Contents: Class for parsing scopes to be indexed as listed in the
  9. // registry.
  10. //
  11. // Classes: CParseRegistryScope
  12. //
  13. // History: 29-Oct-96 dlee Created.
  14. //
  15. //----------------------------------------------------------------------------
  16. #pragma once
  17. #include <lmcons.h>
  18. #include <cisecret.hxx>
  19. //+---------------------------------------------------------------------------
  20. //
  21. // Class: CParseRegistryScope
  22. //
  23. // Purpose: Parses a registry scope entry
  24. //
  25. // History: 29-Oct-96 dlee Created.
  26. //
  27. //----------------------------------------------------------------------------
  28. class CParseRegistryScope
  29. {
  30. public:
  31. CParseRegistryScope( WCHAR const *pValueName, ULONG uValueType,
  32. VOID const *pValueData, ULONG uValueLength )
  33. : _pwcScope( pValueName ),
  34. _fIsIndexed( TRUE ),
  35. _fIsPhysical( TRUE ),
  36. _fIsVirtual( FALSE ),
  37. _fIsShadowAlias( FALSE )
  38. {
  39. //
  40. // Is this a duplicate scope (e.g. one with '<#>' at then end)?
  41. //
  42. unsigned cwc = wcslen( pValueName );
  43. if ( pValueName[cwc-1] == L'>' )
  44. {
  45. //
  46. // Find the other bracket.
  47. //
  48. cwc--;
  49. while ( cwc > 0 && pValueName[cwc] != L'<' )
  50. cwc--;
  51. if ( cwc > 0 )
  52. {
  53. _xScope.Init( cwc + 1 );
  54. _pwcScope = _xScope.Get();
  55. RtlCopyMemory( _xScope.Get(), pValueName, cwc * sizeof(WCHAR) );
  56. _xScope[cwc] = 0;
  57. }
  58. }
  59. // Format is fixup,username,indexed
  60. // Fields are optional.
  61. // If indexed is "0", indexing is turned off.
  62. if ( REG_SZ != uValueType )
  63. return;
  64. WCHAR *pwcValue = (WCHAR *) pValueData;
  65. cwc = 1 + wcslen( pwcValue );
  66. XArray<WCHAR> xValue( cwc );
  67. RtlCopyMemory( xValue.Get(), pwcValue, xValue.SizeOf() );
  68. WCHAR *pwcUser = wcschr( xValue.Get(), L',' );
  69. if ( 0 != pwcUser )
  70. {
  71. *pwcUser = 0;
  72. if ( pwcUser != xValue.Get() )
  73. {
  74. _xFixup.Init( 1 + (UINT)(pwcUser - xValue.Get()) );
  75. RtlCopyMemory( _xFixup.Get(), xValue.Get(), _xFixup.SizeOf() );
  76. }
  77. pwcUser++;
  78. WCHAR *pwcIndexed = wcschr( pwcUser, L',' );
  79. if ( 0 != pwcIndexed )
  80. {
  81. *pwcIndexed = 0;
  82. if ( pwcIndexed != pwcUser )
  83. {
  84. _xUsername.Init( 1 + (UINT)(pwcIndexed - pwcUser) );
  85. RtlCopyMemory( _xUsername.Get(), pwcUser, _xUsername.SizeOf() );
  86. }
  87. pwcIndexed++;
  88. if ( ( isxdigit(pwcIndexed[0]) ) &&
  89. ( 0 == pwcIndexed[1] || (isxdigit(pwcIndexed[1]) && 0 == pwcIndexed[2]) ) )
  90. {
  91. unsigned flag = wcstol( pwcIndexed, 0, 16 );
  92. if ( 0 == (flag & 0x1) )
  93. _fIsIndexed = FALSE;
  94. if ( flag & 0x2 )
  95. {
  96. _fIsVirtual = TRUE;
  97. _fIsPhysical = FALSE;
  98. }
  99. if ( flag & 0x40 )
  100. _fIsShadowAlias = TRUE;
  101. if ( flag & 0x4 )
  102. _fIsPhysical = TRUE;
  103. }
  104. }
  105. else
  106. {
  107. unsigned cwcUser = 1 + wcslen( pwcUser );
  108. _xUsername.Init( cwcUser );
  109. RtlCopyMemory( _xUsername.Get(), pwcUser, _xUsername.SizeOf() );
  110. }
  111. }
  112. else
  113. {
  114. _xFixup.Set( cwc, xValue.Acquire() );
  115. }
  116. }
  117. ~CParseRegistryScope()
  118. {
  119. if ( 0 != _xPassword.Get() )
  120. SecureZeroMemory( _xPassword.Get(), _xPassword.SizeOf() );
  121. }
  122. WCHAR const * GetScope() { return _pwcScope; }
  123. void GetScope( WCHAR * pwcScope )
  124. {
  125. if ( _pwcScope != pwcScope )
  126. wcscpy( pwcScope, _pwcScope );
  127. }
  128. WCHAR const * GetFixup() { return _xFixup.Get(); }
  129. WCHAR * AcqFixup() { return _xFixup.Acquire(); }
  130. WCHAR const * GetUsername() { return _xUsername.Get(); }
  131. WCHAR * AcqUsername() { return _xUsername.Acquire(); }
  132. BOOL IsIndexed() { return _fIsIndexed; }
  133. BOOL IsVirtualPlaceholder() { return _fIsVirtual; }
  134. BOOL IsPhysical() { return _fIsPhysical; }
  135. BOOL IsShadowAlias() { return _fIsShadowAlias; }
  136. WCHAR * GetPassword( WCHAR const * pwcCatalogName )
  137. {
  138. // For security reasons, the password isn't stored in the registry.
  139. // It's in the lsa database under a key that includes the catalog
  140. // name and username.
  141. if ( ( 0 == _xPassword.Get() ) &&
  142. ( 0 != _xUsername.Get() ) )
  143. {
  144. // Look it up in the lsa database.
  145. // This object is short-lived, so leave it in memory unencrypted.
  146. WCHAR awc[ PWLEN+1 ];
  147. if ( CiGetPassword( pwcCatalogName,
  148. _xUsername.Get(),
  149. awc ) )
  150. {
  151. unsigned cwc = 1 + wcslen( awc );
  152. _xPassword.Init( cwc );
  153. RtlCopyMemory( _xPassword.Get(), awc, _xPassword.SizeOf() );
  154. }
  155. }
  156. return _xPassword.Get();
  157. }
  158. private:
  159. WCHAR const * _pwcScope; // scope to be filtered or excluded
  160. BOOL _fIsIndexed; // TRUE if the scope should be filtered
  161. BOOL _fIsVirtual; // TRUE if scope exists (partly) because of IIS / NNTP
  162. BOOL _fIsPhysical; // TRUE if scope exists independent of IIS / NNTP
  163. BOOL _fIsShadowAlias; // TRUE if the scope was added to shadow a net share
  164. XArray<WCHAR> _xFixup; // optional fix for remote use of local scopes
  165. XArray<WCHAR> _xUsername; // optional username to use for scope
  166. XArray<WCHAR> _xPassword; // optional password to use for scope
  167. XArray<WCHAR> _xScope; // Used for duplicate scopes
  168. };