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.

103 lines
2.6 KiB

  1. #include "AdsiHelpers.h"
  2. //------------------------------------------------------------------------------
  3. // IsUserRid Function
  4. //
  5. // Synopsis
  6. // Verifies that the RID is a user RID and not a reserved or built-in RID.
  7. //
  8. // Arguments
  9. // IN vntSid - SID as an array of bytes (this is the form received from ADSI)
  10. //
  11. // Return
  12. // A true value means that the RID is a user RID. A false value indicates either
  13. // that the SID is invalid or the RID is a built-in RID.
  14. //------------------------------------------------------------------------------
  15. bool __stdcall IsUserRid(const _variant_t& vntSid)
  16. {
  17. bool bUser = false;
  18. if (V_VT(&vntSid) == (VT_ARRAY|VT_UI1))
  19. {
  20. PSID pSid = (PSID)vntSid.parray->pvData;
  21. if (IsValidSid(pSid))
  22. {
  23. PUCHAR puch = GetSidSubAuthorityCount(pSid);
  24. DWORD dwCount = static_cast<DWORD>(*puch);
  25. DWORD dwIndex = dwCount - 1;
  26. PDWORD pdw = GetSidSubAuthority(pSid, dwIndex);
  27. DWORD dwRid = *pdw;
  28. if (dwRid >= MIN_NON_RESERVED_RID)
  29. {
  30. bUser = true;
  31. }
  32. }
  33. }
  34. return bUser;
  35. }
  36. //------------------------------------------------------------------------------
  37. // GetEscapedFilterValue Function
  38. //
  39. // Synopsis
  40. // Generates an escaped name that may be used in an LDAP query. The characters
  41. // ( ) * \ must be escaped when used in an LDAP query per RFC 2254.
  42. //
  43. // Arguments
  44. // IN pszName - the name to be escaped
  45. //
  46. // Return
  47. // Returns the escaped name.
  48. //------------------------------------------------------------------------------
  49. tstring __stdcall GetEscapedFilterValue(PCTSTR pszValue)
  50. {
  51. tstring strEscapedValue;
  52. if (pszValue)
  53. {
  54. //
  55. // Generate escaped name.
  56. //
  57. for (LPCTSTR pch = pszValue; *pch; pch++)
  58. {
  59. switch (*pch)
  60. {
  61. case _T('('):
  62. {
  63. strEscapedValue += _T("\\28");
  64. break;
  65. }
  66. case _T(')'):
  67. {
  68. strEscapedValue += _T("\\29");
  69. break;
  70. }
  71. case _T('*'):
  72. {
  73. strEscapedValue += _T("\\2A");
  74. break;
  75. }
  76. case _T('\\'):
  77. {
  78. strEscapedValue += _T("\\5C");
  79. break;
  80. }
  81. default:
  82. {
  83. strEscapedValue += *pch;
  84. break;
  85. }
  86. }
  87. }
  88. }
  89. return strEscapedValue;
  90. }