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.

171 lines
5.9 KiB

  1. /*---------------------------------------------------------------------------
  2. File: LGTranslator.cpp
  3. Comments: Routines to translate membership of local groups.
  4. Used to update local groups on member servers or in resource domains when
  5. members of the groups have been moved during a domain consolidation.
  6. (c) Copyright 1999, Mission Critical Software, Inc., All Rights Reserved
  7. Proprietary and confidential to Mission Critical Software, Inc.
  8. REVISION LOG ENTRY
  9. Revision By: Christy Boles
  10. Revised on 01/27/99 09:13:18
  11. ---------------------------------------------------------------------------
  12. */
  13. #include "StdAfx.h"
  14. #include "Common.hpp"
  15. #include "Err.hpp"
  16. #include "ErrDct.hpp"
  17. #include "Mcs.h"
  18. #include "STArgs.hpp"
  19. #include "SidCache.hpp"
  20. #include "SDStat.hpp"
  21. #include <lmaccess.h>
  22. #include <lmapibuf.h>
  23. extern TErrorDct err;
  24. // Translates the membership of a local group
  25. DWORD // ret- 0 or error code
  26. TranslateLocalGroup(
  27. WCHAR const * groupName, // in - name of group to translate
  28. WCHAR const * serverName, // in - name of server for local group
  29. SecurityTranslatorArgs * stArgs, // in - translation settings
  30. TSDRidCache * cache, // in - translation table
  31. TSDResolveStats * stat // in - stats on items modified
  32. )
  33. {
  34. API_RET_TYPE rc,
  35. rcEnum;
  36. // Get the members of the local group
  37. LOCALGROUP_MEMBERS_INFO_0 * member,
  38. * memBuf;
  39. DWORD memRead,
  40. memTotal;
  41. // memTotal,
  42. // resume = 0;
  43. DWORD_PTR resume = 0;
  44. TAcctNode * node;
  45. BOOL bUseMapFile = stArgs->UsingMapFile();
  46. // make a list of the group's members
  47. do
  48. {
  49. rcEnum = NetLocalGroupGetMembers( serverName,
  50. groupName,
  51. 0,
  52. (LPBYTE *)&memBuf,
  53. BUFSIZE,
  54. &memRead,
  55. &memTotal,
  56. &resume );
  57. if ( rcEnum != ERROR_SUCCESS && rcEnum != ERROR_MORE_DATA )
  58. break;
  59. for ( member = memBuf; member < memBuf + memRead; member++ )
  60. {
  61. rc = 0;
  62. stat->IncrementExamined(groupmember);
  63. if (!bUseMapFile)
  64. node = cache->Lookup(member->lgrmi0_sid);
  65. else
  66. node = cache->LookupWODomain(member->lgrmi0_sid);
  67. if ( node == (TAcctNode*)-1 )
  68. {
  69. node = NULL;
  70. }
  71. if ( node && node->IsValidOnTgt() )
  72. {
  73. // Found the account in the cache
  74. // remove this member from the group and add the target member
  75. if ( ! stArgs->NoChange() && ( stArgs->TranslationMode() != ADD_SECURITY) )
  76. {
  77. rc = NetLocalGroupDelMembers(serverName,groupName,0,(LPBYTE)member,1);
  78. }
  79. if ( rc )
  80. {
  81. err.SysMsgWrite(ErrE,rc,DCT_MSG_MEMBER_REMOVE_FAILED_SSSD,node->GetAcctName(),groupName,serverName,rc);
  82. stat->IncrementSkipped(groupmember);
  83. }
  84. else
  85. {
  86. node->AddAceChange(groupmember);
  87. stat->IncrementChanged(groupmember);
  88. PSID sid = NULL;
  89. if (!bUseMapFile)
  90. sid = cache->GetTgtSid(node);
  91. else
  92. sid = cache->GetTgtSidWODomain(node);
  93. if ( sid )
  94. {
  95. if ( !stArgs->NoChange() && (stArgs->TranslationMode() != REMOVE_SECURITY) )
  96. {
  97. rc = NetLocalGroupAddMembers(serverName,groupName,0,(LPBYTE)&sid,1);
  98. }
  99. if ( rc )
  100. {
  101. err.SysMsgWrite(ErrE,rc,DCT_MSG_MEMBER_ADD_FAILED_SSSD,node->GetAcctName(),groupName,serverName,rc);
  102. }
  103. free(sid);
  104. }
  105. }
  106. }
  107. }
  108. NetApiBufferFree( memBuf );
  109. } while ( rcEnum == ERROR_MORE_DATA );
  110. if ( rcEnum != ERROR_SUCCESS )
  111. {
  112. err.SysMsgWrite(ErrE,rcEnum,DCT_MSG_GROUP_ENUM_FAILED_SS,groupName,serverName);
  113. }
  114. return rc;
  115. }
  116. DWORD
  117. TranslateLocalGroups(
  118. WCHAR const * serverName, // in - name of server to translate groups on
  119. SecurityTranslatorArgs * stArgs, // in - translation settings
  120. TSDRidCache * cache, // in - translation table
  121. TSDResolveStats * stat // in - stats on items modified
  122. )
  123. {
  124. DWORD rc = 0;
  125. LOCALGROUP_INFO_0 * buf,
  126. * groupInfo;
  127. DWORD numRead,
  128. // numTotal,
  129. // resume=0;
  130. numTotal;
  131. DWORD_PTR resume=0;
  132. WCHAR currName[LEN_Computer + LEN_Group];
  133. // Get a list of all the local groups
  134. do
  135. {
  136. rc = NetLocalGroupEnum(serverName,0,(LPBYTE*)&buf,BUFSIZE,&numRead,&numTotal,&resume);
  137. if ( rc != ERROR_SUCCESS && rc != ERROR_MORE_DATA )
  138. break;
  139. if ( cache->IsCancelled() )
  140. {
  141. err.MsgWrite(0,DCT_MSG_OPERATION_ABORTED);
  142. break;
  143. }
  144. for ( groupInfo = buf ; groupInfo < buf + numRead ; groupInfo++ )
  145. {
  146. swprintf(currName,L"%s\\%s",serverName,groupInfo->lgrpi0_name);
  147. stat->DisplayPath(currName);
  148. TranslateLocalGroup(groupInfo->lgrpi0_name,serverName,stArgs,cache,stat);
  149. }
  150. NetApiBufferFree(buf);
  151. } while ( rc == ERROR_MORE_DATA );
  152. stat->DisplayPath(L"");
  153. return rc;
  154. }