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.

136 lines
3.0 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1998, Microsoft Corp. All rights reserved.
  4. //
  5. // FILE
  6. //
  7. // NTGroups.cpp
  8. //
  9. // SYNOPSIS
  10. //
  11. // This file declares the class NTGroups.
  12. //
  13. // MODIFICATION HISTORY
  14. //
  15. // 02/04/1998 Original version.
  16. // 04/06/1998 Check the enabled flag.
  17. //
  18. ///////////////////////////////////////////////////////////////////////////////
  19. #include <ias.h>
  20. #include <iastlutl.h>
  21. #include <sdoias.h>
  22. #include <ntgroups.h>
  23. #include <parser.h>
  24. #include <textsid.h>
  25. //////////
  26. // We'll allow a broad range of delimiters.
  27. //////////
  28. const WCHAR DELIMITERS[] = L" ,;\t\n|";
  29. STDMETHODIMP NTGroups::IsTrue(IRequest* pRequest, VARIANT_BOOL *pVal)
  30. {
  31. _ASSERT(pRequest != NULL);
  32. _ASSERT(pVal != NULL);
  33. CComQIPtr<IAttributesRaw, &__uuidof(IAttributesRaw)> attrsRaw(pRequest);
  34. _ASSERT(attrsRaw != NULL);
  35. *pVal = VARIANT_FALSE;
  36. //////////
  37. // Get the NT-Token-Groups attribute.
  38. //////////
  39. PIASATTRIBUTE attr = IASPeekAttribute(attrsRaw,
  40. IAS_ATTRIBUTE_TOKEN_GROUPS,
  41. IASTYPE_OCTET_STRING);
  42. if (attr)
  43. {
  44. //////////
  45. // See if the user belongs to one of the allowed groups.
  46. //////////
  47. PTOKEN_GROUPS tokenGroups;
  48. tokenGroups = (PTOKEN_GROUPS)attr->Value.OctetString.lpValue;
  49. for (DWORD dw = 0; dw < tokenGroups->GroupCount; ++dw)
  50. {
  51. if (groups.contains(tokenGroups->Groups[dw].Sid) &&
  52. (tokenGroups->Groups[dw].Attributes & SE_GROUP_ENABLED))
  53. {
  54. *pVal = VARIANT_TRUE;
  55. break;
  56. }
  57. }
  58. }
  59. return S_OK;
  60. }
  61. STDMETHODIMP NTGroups::put_ConditionText(BSTR newVal)
  62. {
  63. if (newVal == NULL) { return E_INVALIDARG; }
  64. //////////
  65. // Make a local copy so we can modify it.
  66. //////////
  67. size_t len = sizeof(WCHAR) * (wcslen(newVal) + 1);
  68. Parser p((PWSTR)memcpy(_alloca(len), newVal, len));
  69. //////////
  70. // Parse the input text and create SIDs.
  71. //////////
  72. SidSet temp;
  73. try
  74. {
  75. //////////
  76. // Iterate through the individual SID tokens.
  77. //////////
  78. PCWSTR token;
  79. while ((token = p.seekToken(DELIMITERS)) != NULL)
  80. {
  81. PSID sid;
  82. // Try to convert.
  83. DWORD status = IASSidFromTextW(token, &sid);
  84. if (status == NO_ERROR)
  85. {
  86. temp.insert(sid);
  87. }
  88. else
  89. {
  90. return E_INVALIDARG;
  91. }
  92. // We're done with the token.
  93. p.releaseToken();
  94. }
  95. }
  96. catch (std::bad_alloc)
  97. {
  98. return E_OUTOFMEMORY;
  99. }
  100. // Try to save the condition next.
  101. HRESULT hr = Condition::put_ConditionText(newVal);
  102. if (SUCCEEDED(hr))
  103. {
  104. // All went well so save the new set of groups.
  105. groups.swap(temp);
  106. }
  107. return hr;
  108. }