private void Init(VicType initRegion, BorderType borderType, SidType sidType, TapeDriveType tapeDriveType, DiskDriveType diskDriveType) { // Force certain drive types to be available depending on ROM type switch (_inputFileInfo.Extension.ToUpper()) { case @".D64": case @".G64": if (diskDriveType == DiskDriveType.None) { diskDriveType = DiskDriveType.Commodore1541; } break; case @".TAP": if (tapeDriveType == TapeDriveType.None) { tapeDriveType = TapeDriveType.Commodore1530; } break; } _board = new Motherboard(this, initRegion, borderType, sidType, tapeDriveType, diskDriveType); InitRoms(diskDriveType); _board.Init(); InitMedia(); // configure video CoreComm.VsyncDen = _board.Vic.CyclesPerFrame; CoreComm.VsyncNum = _board.Vic.CyclesPerSecond; }
private void TranslateForeignMembers() { List <byte[]> numArrays = new List <byte[]>(this.foreignMembersCurrentGroup.Count); foreach (DirectoryEntry directoryEntry in this.foreignMembersCurrentGroup) { if (directoryEntry.Properties["objectSid"].Count != 0) { byte[] value = (byte[])directoryEntry.Properties["objectSid"].Value; SidType sidType = Utils.ClassifySID(value); if (sidType != SidType.FakeObject) { numArrays.Add(value); directoryEntry.Dispose(); } else { this.fakePrincipalMembers.Add(directoryEntry); } } else { throw new PrincipalOperationException(StringResources.ADStoreCtxCantRetrieveObjectSidForCrossStore); } } this.foreignMembersToReturn = new SidList(numArrays, this.storeCtx.DnsHostName, this.storeCtx.Credentials); this.foreignMembersCurrentGroup.Clear(); }
private bool IsLocalMember(byte[] sid) { string str = null; string str1 = null; SidType sidType = Utils.ClassifySID(sid); if (sidType != SidType.RealObjectFakeDomain) { bool flag = false; int num = 0; int num1 = Utils.LookupSid(this.storeCtx.MachineUserSuppliedName, this.storeCtx.Credentials, sid, out str, out str1, out num); if (num1 == 0) { if (string.Compare(this.storeCtx.MachineFlatName, str1, StringComparison.OrdinalIgnoreCase) == 0) { flag = true; } return(flag); } else { object[] objArray = new object[1]; objArray[0] = num1; throw new PrincipalOperationException(string.Format(CultureInfo.CurrentCulture, StringResources.SAMStoreCtxErrorEnumeratingGroup, objArray)); } } else { return(true); } }
private bool IsLocalMember(byte[] sid) { // BUILTIN SIDs are local, but we can't determine that by looking at domainName SidType sidType = Utils.ClassifySID(sid); Debug.Assert(sidType != SidType.FakeObject); if (sidType == SidType.RealObjectFakeDomain) { GlobalDebug.WriteLineIf(GlobalDebug.Info, "SAMMembersSet", "IsLocalMember: fake domain, SID={0}", Utils.ByteArrayToString(sid)); return(true); } bool isLocal = false; // Ask the OS to resolve the SID to its target. int accountUsage = 0; string name; string domainName; int err = Utils.LookupSid( _storeCtx.MachineUserSuppliedName, _storeCtx.Credentials, sid, out name, out domainName, out accountUsage); if (err != 0) { GlobalDebug.WriteLineIf(GlobalDebug.Error, "SAMMembersSet", "IsLocalMember: LookupSid failed, sid={0}, server={1}, err={2}", Utils.ByteArrayToString(sid), _storeCtx.MachineUserSuppliedName, err); throw new PrincipalOperationException( SR.Format(SR.SAMStoreCtxErrorEnumeratingGroup, err)); } if (string.Equals(_storeCtx.MachineFlatName, domainName, StringComparison.OrdinalIgnoreCase)) { isLocal = true; } GlobalDebug.WriteLineIf(GlobalDebug.Info, "SAMMembersSet", "IsLocalMember: sid={0}, isLocal={1}, domainName={2}", Utils.ByteArrayToString(sid), isLocal, domainName); return(isLocal); }
internal static extern bool LookupAccountSidW( /* _In_opt_ LPCTSTR */ [In] string lpSystemName, /* _In_ PSID */ [In] IntPtr lpSid, /* _Out_opt_ LPTSTR */ [In][Out] StringBuilder lpName, /* _Inout_ LPDWORD */ [In][Out] ref uint cchName, /* _Out_opt_ LPTSTR */ [In][Out] StringBuilder lpReferencedDomainName, /* _Inout_ LPDWORD */ [In][Out] ref uint cchReferencedDomainName, /* _Out_ PSID_NAME_USE */ [In][Out] ref SidType peUse );
private void Init(VicType initRegion, BorderType borderType, SidType sidType, TapeDriveType tapeDriveType, DiskDriveType diskDriveType) { // Force certain drive types to be available depending on ROM type foreach (var rom in Roms) { switch (C64FormatFinder.GetFormat(rom)) { case C64Format.D64: case C64Format.G64: case C64Format.X64: if (diskDriveType == DiskDriveType.None) { diskDriveType = DiskDriveType.Commodore1541; } break; case C64Format.T64: case C64Format.TAP: if (tapeDriveType == TapeDriveType.None) { tapeDriveType = TapeDriveType.Commodore1530; } break; case C64Format.CRT: // Nothing required. break; case C64Format.Unknown: if (rom.Length >= 0xFE00) { throw new Exception("The image format is not known, and too large to be used as a PRG."); } if (diskDriveType == DiskDriveType.None) { diskDriveType = DiskDriveType.Commodore1541; } break; default: throw new Exception("The image format is not yet supported by the Commodore 64 core."); } } _board = new Motherboard(this, initRegion, borderType, sidType, tapeDriveType, diskDriveType); InitRoms(diskDriveType); _board.Init(); // configure video CoreComm.VsyncDen = _board.Vic.CyclesPerFrame; CoreComm.VsyncNum = _board.Vic.CyclesPerSecond; }
#pragma warning disable CA1810 // Initialize reference type static fields inline; by-design, as value will differ depending on TSid Type. /// <summary> /// Static initializer. /// </summary> static ReferenceDataSidList() #pragma warning restore CA1810 { if (typeof(TSid) == typeof(string)) { _sidType = SidType.String; } else if (typeof(TSid) == typeof(int)) { _sidType = SidType.Int32; } else if (typeof(TSid) == typeof(Guid)) { _sidType = SidType.Guid; } }
internal static bool IsSamUser() { bool flag; bool flag1; IntPtr zero = IntPtr.Zero; IntPtr machineDomainSid = IntPtr.Zero; try { zero = Utils.GetCurrentUserSid(); SidType sidType = Utils.ClassifySID(zero); if (sidType != SidType.RealObject) { flag = true; } else { machineDomainSid = Utils.GetMachineDomainSid(); bool flag2 = false; UnsafeNativeMethods.EqualDomainSid(zero, machineDomainSid, ref flag2); if (flag2) { flag1 = !Utils.IsMachineDC(null); } else { flag1 = false; } flag = flag1; } } finally { if (zero != IntPtr.Zero) { Marshal.FreeHGlobal(zero); } if (machineDomainSid != IntPtr.Zero) { Marshal.FreeHGlobal(machineDomainSid); } } return(flag); }
/// <summary> /// Static initializer. /// </summary> static ReferenceDataSidList() { if (typeof(TSid) == typeof(string)) { _sidType = SidType.String; } else if (typeof(TSid) == typeof(int)) { _sidType = SidType.Int32; } else if (typeof(TSid) == typeof(long)) { _sidType = SidType.Int64; } else if (typeof(TSid) == typeof(Guid)) { _sidType = SidType.Guid; } }
/// <summary> /// Static initializer. /// </summary> static ReferenceDataSidList() { if (typeof(TSid) == typeof(string)) { _sidType = SidType.String; } else if (typeof(TSid) == typeof(int)) { _sidType = SidType.Int32; } else if (typeof(TSid) == typeof(Guid)) { _sidType = SidType.Guid; } if (_sidType == SidType.Unknown) { throw new InvalidOperationException("Unsupported SID Type; must be String, Int32 or Guid."); } }
internal static bool IsSamUser() { // // Basic algorithm // // Get SID of current user (via OpenThreadToken/GetTokenInformation/CloseHandle for TokenUser) // // Is the user SID of the form S-1-5-21-... (does GetSidIdentityAuthority(u) == 5 and GetSidSubauthority(u, 0) == 21)? // If NO ---> is local user // If YES ---> // Get machine domain SID (via LsaOpenPolicy/LsaQueryInformationPolicy for PolicyAccountDomainInformation/LsaClose) // Does EqualDomainSid indicate the current user SID and the machine domain SID have the same domain? // If YES --> // IS the local machine a DC // If NO --> is local user // If YES --> is _not_ local user // If NO --> is _not_ local user // IntPtr pCopyOfUserSid = IntPtr.Zero; IntPtr pMachineDomainSid = IntPtr.Zero; try { // Get the user's SID pCopyOfUserSid = GetCurrentUserSid(); // Is it of S-1-5-21 form: Is the issuing authority NT_AUTHORITY and the RID NT_NOT_UNIQUE? SidType sidType = ClassifySID(pCopyOfUserSid); if (sidType == SidType.RealObject) { // It's a domain SID. Now, is the domain portion for the local machine, or something else? // Get the machine domain SID pMachineDomainSid = GetMachineDomainSid(); // Does the user SID have the same domain as the machine SID? bool sameDomain = false; bool success = UnsafeNativeMethods.EqualDomainSid(pCopyOfUserSid, pMachineDomainSid, ref sameDomain); // Since both pCopyOfUserSid and pMachineDomainSid should always be account SIDs Debug.Assert(success == true); // If user SID is the same domain as the machine domain, and the machine is not a DC then the user is a local (machine) user return(sameDomain ? !IsMachineDC(null) : false); } else { // It's not a domain SID, must be local (e.g., NT AUTHORITY\foo, or BUILTIN\foo) return(true); } } finally { if (pCopyOfUserSid != IntPtr.Zero) { Marshal.FreeHGlobal(pCopyOfUserSid); } if (pMachineDomainSid != IntPtr.Zero) { Marshal.FreeHGlobal(pMachineDomainSid); } } }
private void Init(VicType initRegion, BorderType borderType, SidType sidType, TapeDriveType tapeDriveType, DiskDriveType diskDriveType) { // Force certain drive types to be available depending on ROM type foreach (var rom in Roms) { switch (C64FormatFinder.GetFormat(rom)) { case C64Format.D64: case C64Format.G64: case C64Format.X64: if (diskDriveType == DiskDriveType.None) diskDriveType = DiskDriveType.Commodore1541; break; case C64Format.T64: case C64Format.TAP: if (tapeDriveType == TapeDriveType.None) { tapeDriveType = TapeDriveType.Commodore1530; } break; case C64Format.CRT: // Nothing required. break; case C64Format.Unknown: if (rom.Length >= 0xFE00) { throw new Exception("The image format is not known, and too large to be used as a PRG."); } if (diskDriveType == DiskDriveType.None) diskDriveType = DiskDriveType.Commodore1541; break; default: throw new Exception("The image format is not yet supported by the Commodore 64 core."); } } _board = new Motherboard(this, initRegion, borderType, sidType, tapeDriveType, diskDriveType); InitRoms(diskDriveType); _board.Init(); // configure video CoreComm.VsyncDen = _board.Vic.CyclesPerFrame; CoreComm.VsyncNum = _board.Vic.CyclesPerSecond; }
private bool MoveNextLocal() { bool needToRetry; do { needToRetry = false; bool f = _membersEnumerator.MoveNext(); if (f) // got a value { GlobalDebug.WriteLineIf(GlobalDebug.Info, "SAMMembersSet", "MoveNextLocal: got a value from the enumerator"); UnsafeNativeMethods.IADs nativeMember = (UnsafeNativeMethods.IADs)_membersEnumerator.Current; // If we encountered a group member corresponding to a fake principal such as // NT AUTHORITY/NETWORK SERVICE, construct and prepare to return the fake principal. byte[] sid = (byte[])nativeMember.Get("objectSid"); SidType sidType = Utils.ClassifySID(sid); if (sidType == SidType.FakeObject) { GlobalDebug.WriteLineIf(GlobalDebug.Info, "SAMMembersSet", "MoveNextLocal: fake principal, sid={0}", Utils.ByteArrayToString(sid)); _currentFakePrincipal = _storeCtx.ConstructFakePrincipalFromSID(sid); _current = null; _currentForeign = null; if (_foreignResultSet != null) { _foreignResultSet.Dispose(); } _foreignResultSet = null; return(true); } // We do this, rather than using the DirectoryEntry constructor that takes a native IADs object, // is so the credentials get transferred to the new DirectoryEntry. If we just use the native // object constructor, the native object will have the right credentials, but the DirectoryEntry // will have default (null) credentials, which it'll use anytime it needs to use credentials. DirectoryEntry de = SDSUtils.BuildDirectoryEntry( _storeCtx.Credentials, _storeCtx.AuthTypes); if (sidType == SidType.RealObjectFakeDomain) { // Transform the "WinNT://BUILTIN/foo" path to "WinNT://machineName/foo" string builtinADsPath = nativeMember.ADsPath; UnsafeNativeMethods.Pathname pathCracker = new UnsafeNativeMethods.Pathname(); UnsafeNativeMethods.IADsPathname pathName = (UnsafeNativeMethods.IADsPathname)pathCracker; pathName.Set(builtinADsPath, 1 /* ADS_SETTYPE_FULL */); // Build the "WinNT://" portion of the new path StringBuilder adsPath = new StringBuilder(); adsPath.Append("WinNT://"); //adsPath.Append(pathName.Retrieve(9 /*ADS_FORMAT_SERVER */)); // Build the "WinNT://machineName/" portion of the new path adsPath.Append(_storeCtx.MachineUserSuppliedName); adsPath.Append('/'); // Build the "WinNT://machineName/foo" portion of the new path int cElements = pathName.GetNumElements(); Debug.Assert(cElements >= 2); // "WinNT://BUILTIN/foo" == 2 elements // Note that the ADSI WinNT provider indexes them backwards, e.g., in // "WinNT://BUILTIN/A/B", BUILTIN == 2, A == 1, B == 0. for (int i = cElements - 2; i >= 0; i--) { adsPath.Append(pathName.GetElement(i)); adsPath.Append('/'); } adsPath.Remove(adsPath.Length - 1, 1); // remove the trailing "/" de.Path = adsPath.ToString(); GlobalDebug.WriteLineIf(GlobalDebug.Info, "SAMMembersSet", "MoveNextLocal: fake domain: {0} --> {1}", builtinADsPath, adsPath); } else { Debug.Assert(sidType == SidType.RealObject); de.Path = nativeMember.ADsPath; GlobalDebug.WriteLineIf(GlobalDebug.Info, "SAMMembersSet", "MoveNextLocal: real domain {0}", de.Path); } // Debug.Assert(Utils.AreBytesEqual(sid, (byte[]) de.Properties["objectSid"].Value)); if (IsLocalMember(sid)) { // If we're processing recursively, and the member is a group, // we don't return it but instead treat it as something to recursively // visit (expand) later. if (!_recursive || !SAMUtils.IsOfObjectClass(de, "Group")) { GlobalDebug.WriteLineIf(GlobalDebug.Info, "SAMMembersSet", "MoveNextLocal: setting current to {0}", de.Path); // Not recursive, or not a group. Return the principal. _current = de; _currentFakePrincipal = null; _currentForeign = null; if (_foreignResultSet != null) { _foreignResultSet.Dispose(); } _foreignResultSet = null; return(true); } else { GlobalDebug.WriteLineIf(GlobalDebug.Info, "SAMMembersSet", "MoveNextLocal: adding {0} to groupsToVisit", de.Path); // Save off for later, if we haven't done so already. if (!_groupsVisited.Contains(de.Path) && !_groupsToVisit.Contains(de.Path)) { _groupsToVisit.Add(de.Path); } needToRetry = true; continue; } } else { // It's a foreign principal (e..g, an AD user or group). // Save it off for later. GlobalDebug.WriteLineIf(GlobalDebug.Info, "SAMMembersSet", "MoveNextLocal: adding {0} to foreignMembers", de.Path); _foreignMembers.Add(de); needToRetry = true; continue; } } else { // We reached the end of this group's membership. // If we're supposed to be recursively expanding, we need to expand // any remaining non-foreign groups we earlier visited. if (_recursive) { GlobalDebug.WriteLineIf(GlobalDebug.Info, "SAMMembersSet", "MoveNextLocal: recursive processing, groupsToVisit={0}", _groupsToVisit.Count); if (_groupsToVisit.Count > 0) { // Pull off the next group to visit string groupPath = _groupsToVisit[0]; GlobalDebug.WriteLineIf(GlobalDebug.Info, "SAMMembersSet", "MoveNextLocal: recursively processing {0}", groupPath); _groupsToVisit.RemoveAt(0); _groupsVisited.Add(groupPath); // Set up for the next round of enumeration DirectoryEntry de = SDSUtils.BuildDirectoryEntry( groupPath, _storeCtx.Credentials, _storeCtx.AuthTypes); _group = (UnsafeNativeMethods.IADsGroup)de.NativeObject; UnsafeNativeMethods.IADsMembers iADsMembers = _group.Members(); _membersEnumerator = ((IEnumerable)iADsMembers).GetEnumerator(); // and go on to the first member of this new group needToRetry = true; continue; } } } }while (needToRetry); return(false); }
private bool MoveNextForeign(ref bool outerNeedToRetry) { bool flag; Principal principal; StoreCtx queryCtx; bool hasValue; outerNeedToRetry = false; do { flag = false; if (this.foreignMembersCurrentGroup.Count > 0) { this.TranslateForeignMembers(); } if (this.fakePrincipalMembers.Count <= 0) { if (this.foreignMembersToReturn == null || this.foreignMembersToReturn.Length <= 0) { if (this.foreignGroups.Count <= 0) { return(false); } else { outerNeedToRetry = true; if (this.foreignGroups[0].Context.ServerInformation.OsVersion != DomainControllerMode.Win2k) { GroupScope?groupScope = this.foreignGroups[0].GroupScope; if (groupScope.GetValueOrDefault() != GroupScope.Global) { hasValue = true; } else { hasValue = !groupScope.HasValue; } if (!hasValue) { this.expansionMode = ExpansionMode.ASQ; return(this.ExpandForeignGroupSearcher()); } } this.expansionMode = ExpansionMode.Enum; return(this.ExpandForeignGroupEnumerator()); } } else { SidListEntry item = this.foreignMembersToReturn[0]; SidType sidType = Utils.ClassifySID(item.pSid); if (sidType != SidType.RealObjectFakeDomain) { ContextOptions aDDefaultContextOption = DefaultContextOptions.ADDefaultContextOption; PrincipalContext context = SDSCache.Domain.GetContext(item.sidIssuerName, this.storeCtx.Credentials, aDDefaultContextOption); queryCtx = context.QueryCtx; } else { queryCtx = this.storeCtx; } principal = queryCtx.FindPrincipalByIdentRef(typeof(Principal), "ms-sid", (new SecurityIdentifier(Utils.ConvertNativeSidToByteArray(this.foreignMembersToReturn[0].pSid), 0)).ToString(), DateTime.UtcNow); if (principal != null) { this.foreignMembersToReturn.RemoveAt(0); } else { throw new PrincipalOperationException(StringResources.ADStoreCtxFailedFindCrossStoreTarget); } } } else { principal = this.storeCtx.ConstructFakePrincipalFromSID((byte[])this.fakePrincipalMembers[0].Properties["objectSid"].Value); this.fakePrincipalMembers[0].Dispose(); this.fakePrincipalMembers.RemoveAt(0); } if (principal as GroupPrincipal == null) { DirectoryEntry underlyingObject = (DirectoryEntry)principal.GetUnderlyingObject(); this.storeCtx.LoadDirectoryEntryAttributes(underlyingObject); if (this.usersVisited.ContainsKey(underlyingObject.Properties["distinguishedName"][0].ToString())) { principal.Dispose(); flag = true; } else { this.usersVisited.Add(underlyingObject.Properties["distinguishedName"][0].ToString(), true); this.current = null; this.currentForeignDE = null; this.currentForeignPrincipal = principal; return(true); } } else { if (!principal.fakePrincipal) { string value = (string)((DirectoryEntry)principal.UnderlyingObject).Properties["distinguishedName"].Value; if (this.groupsVisited.Contains(value) || this.groupsToVisit.Contains(value)) { principal.Dispose(); } else { this.foreignGroups.Add((GroupPrincipal)principal); } } flag = true; } }while (flag); return(false); }
private bool MoveNextLocal() { bool flag; do { flag = false; bool flag1 = this.membersEnumerator.MoveNext(); if (!flag1) { if (!this.recursive || this.groupsToVisit.Count <= 0) { continue; } string item = this.groupsToVisit[0]; this.groupsToVisit.RemoveAt(0); this.groupsVisited.Add(item); DirectoryEntry directoryEntry = SDSUtils.BuildDirectoryEntry(item, this.storeCtx.Credentials, this.storeCtx.AuthTypes); this.@group = (UnsafeNativeMethods.IADsGroup)directoryEntry.NativeObject; UnsafeNativeMethods.IADsMembers aDsMember = [email protected](); this.membersEnumerator = ((IEnumerable)aDsMember).GetEnumerator(); flag = true; } else { UnsafeNativeMethods.IADs current = (UnsafeNativeMethods.IADs) this.membersEnumerator.Current; byte[] numArray = (byte[])current.Get("objectSid"); SidType sidType = Utils.ClassifySID(numArray); if (sidType != SidType.FakeObject) { DirectoryEntry aDsPath = SDSUtils.BuildDirectoryEntry(this.storeCtx.Credentials, this.storeCtx.AuthTypes); if (sidType != SidType.RealObjectFakeDomain) { aDsPath.Path = current.ADsPath; } else { string str = current.ADsPath; UnsafeNativeMethods.Pathname pathname = new UnsafeNativeMethods.Pathname(); UnsafeNativeMethods.IADsPathname aDsPathname = (UnsafeNativeMethods.IADsPathname)pathname; aDsPathname.Set(str, 1); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.Append("WinNT://"); stringBuilder.Append(this.storeCtx.MachineUserSuppliedName); stringBuilder.Append("/"); int numElements = aDsPathname.GetNumElements(); for (int i = numElements - 2; i >= 0; i--) { stringBuilder.Append(aDsPathname.GetElement(i)); stringBuilder.Append("/"); } stringBuilder.Remove(stringBuilder.Length - 1, 1); aDsPath.Path = stringBuilder.ToString(); } if (!this.IsLocalMember(numArray)) { this.foreignMembers.Add(aDsPath); flag = true; } else { if (!this.recursive || !SAMUtils.IsOfObjectClass(aDsPath, "Group")) { this.current = aDsPath; this.currentFakePrincipal = null; this.currentForeign = null; if (this.foreignResultSet != null) { this.foreignResultSet.Dispose(); } this.foreignResultSet = null; return(true); } else { if (!this.groupsVisited.Contains(aDsPath.Path) && !this.groupsToVisit.Contains(aDsPath.Path)) { this.groupsToVisit.Add(aDsPath.Path); } flag = true; } } } else { this.currentFakePrincipal = this.storeCtx.ConstructFakePrincipalFromSID(numArray); this.current = null; this.currentForeign = null; if (this.foreignResultSet != null) { this.foreignResultSet.Dispose(); } this.foreignResultSet = null; return(true); } } }while (flag); return(false); }
private void Init(VicType initRegion, BorderType borderType, SidType sidType, TapeDriveType tapeDriveType, DiskDriveType diskDriveType) { // Force certain drive types to be available depending on ROM type switch (_inputFileInfo.Extension.ToUpper()) { case @".D64": case @".G64": if (diskDriveType == DiskDriveType.None) { diskDriveType = DiskDriveType.Commodore1541; } break; case @".TAP": if (tapeDriveType == TapeDriveType.None) { tapeDriveType = TapeDriveType.Commodore1530; } break; } _board = new Motherboard(this, initRegion, borderType, sidType, tapeDriveType, diskDriveType); InitRoms(diskDriveType); _board.Init(); InitMedia(); // configure video CoreComm.VsyncDen = _board.Vic.CyclesPerFrame; CoreComm.VsyncNum = _board.Vic.CyclesPerSecond; }