Exemple #1
0
        static public void TestSAMStoreKeys()
        {
            string mach1  = "machine1";
            string mach1a = "machine1";
            string mach2  = "machine2";

            byte[] sid1a = new byte[] { 0x1, 0x2, 0x3 };
            byte[] sid1b = new byte[] { 0x1, 0x2, 0x3 };
            byte[] sid2  = new byte[] { 0x10, 0x20, 0x30 };

            SAMStoreKey key1a = new SAMStoreKey(mach1, sid1a);
            SAMStoreKey key1b = new SAMStoreKey(mach1, sid1a);
            SAMStoreKey key1c = new SAMStoreKey(mach1a, sid1b);
            SAMStoreKey key2  = new SAMStoreKey(mach2, sid2);
            SAMStoreKey key3  = new SAMStoreKey(mach1, sid2);

            Debug.Assert(key1a.Equals(key1b));
            Debug.Assert(key1a.Equals(key1c));

            Debug.Assert(!key1a.Equals(key2));
            Debug.Assert(!key1a.Equals(key3));

            Debug.Assert(key1a.GetHashCode() != key2.GetHashCode());

            // Shouldn't matter, since SAMStoreKey should make a copy of the byte[] sid
            sid1b[1] = 0xf;
            Debug.Assert(key1a.Equals(key1b));
            Debug.Assert(key1a.Equals(key1c));
        }
Exemple #2
0
        public override bool Equals(object o)
        {
            if (!(o is SAMStoreKey))
            {
                return(false);
            }

            SAMStoreKey that = (SAMStoreKey)o;

            if (!string.Equals(_machineName, that._machineName, StringComparison.OrdinalIgnoreCase))
            {
                return(false);
            }

            return(Utils.AreBytesEqual(_sid, that._sid));
        }
        //
        // CRUD
        //

        // Used to perform the specified operation on the Principal.  They also make any needed security subsystem
        // calls to obtain digitial signatures.
        //
        // Insert() and Update() must check to make sure no properties not supported by this StoreCtx
        // have been set, prior to persisting the Principal.
        internal override void Insert(Principal p)
        {
            Debug.Assert(p.unpersisted == true);
            Debug.Assert(p.fakePrincipal == false);

            try
            {
                // Insert the principal into the store
                SDSUtils.InsertPrincipal(
                    p,
                    this,
                    new SDSUtils.GroupMembershipUpdater(UpdateGroupMembership),
                    _credentials,
                    _authTypes,
                    false               // handled in PushChangesToNative
                    );

                // Load in all the initial values from the store
                ((DirectoryEntry)p.UnderlyingObject).RefreshCache();

                // Load in the StoreKey
                Debug.Assert(p.Key == null);              // since it was previously unpersisted

                Debug.Assert(p.UnderlyingObject != null); // since we just persisted it
                Debug.Assert(p.UnderlyingObject is DirectoryEntry);
                DirectoryEntry de = (DirectoryEntry)p.UnderlyingObject;

                // We just created a principal, so it should have an objectSid
                Debug.Assert((de.Properties["objectSid"] != null) && (de.Properties["objectSid"].Count == 1));

                SAMStoreKey key = new SAMStoreKey(
                    this.MachineFlatName,
                    (byte[])de.Properties["objectSid"].Value
                    );
                p.Key = key;

                // Reset the change tracking
                p.ResetAllChangeStatus();

                GlobalDebug.WriteLineIf(GlobalDebug.Info, "SAMStoreCtx", "Insert: new SID is ", Utils.ByteArrayToString((byte[])de.Properties["objectSid"].Value));
            }
            catch (System.Runtime.InteropServices.COMException e)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(e);
            }
        }
Exemple #4
0
 public override bool Equals(object o)
 {
     if (o as SAMStoreKey != null)
     {
         SAMStoreKey sAMStoreKey = (SAMStoreKey)o;
         if (string.Compare(this.machineName, sAMStoreKey.machineName, StringComparison.OrdinalIgnoreCase) == 0)
         {
             return(Utils.AreBytesEqual(this.sid, sAMStoreKey.sid));
         }
         else
         {
             return(false);
         }
     }
     else
     {
         return(false);
     }
 }
        //
        // Construct a fake Principal to represent a well-known SID like
        // "\Everyone" or "NT AUTHORITY\NETWORK SERVICE"
        //
        internal override Principal ConstructFakePrincipalFromSID(byte[] sid)
        {
            GlobalDebug.WriteLineIf(GlobalDebug.Info,
                                    "SAMStoreCtx",
                                    "ConstructFakePrincipalFromSID: sid={0}, machine={1}",
                                    Utils.ByteArrayToString(sid),
                                    this.MachineFlatName);

            Principal p = Utils.ConstructFakePrincipalFromSID(
                sid,
                this.OwningContext,
                this.MachineUserSuppliedName,
                _credentials,
                this.MachineUserSuppliedName);

            // Assign it a StoreKey
            SAMStoreKey key = new SAMStoreKey(this.MachineFlatName, sid);

            p.Key = key;

            return(p);
        }
        // Given a underlying store object (e.g., DirectoryEntry), further narrowed down a discriminant
        // (if applicable for the StoreCtx type), returns a fresh instance of a Principal 
        // object based on it.  The WinFX Principal API follows ADSI-style semantics, where you get multiple
        // in-memory objects all referring to the same store pricipal, rather than WinFS semantics, where
        // multiple searches all return references to the same in-memory object.
        // Used to implement the reverse wormhole.  Also, used internally by FindResultEnumerator
        // to construct Principals from the store objects returned by a store query.
        //
        // The Principal object produced by this method does not have all the properties
        // loaded.  The Principal object will call the Load method on demand to load its properties
        // from its Principal.UnderlyingObject.
        //
        //
        // This method works for native objects from the store corresponding to _this_ StoreCtx.
        // Each StoreCtx will also have its own internal algorithms used for dealing with cross-store objects, e.g., 
        // for use when iterating over group membership.  These routines are exposed as 
        // ResolveCrossStoreRefToPrincipal, and will be called by the StoreCtx's associated ResultSet
        // classes when iterating over a representation of a "foreign" principal.
        internal override Principal GetAsPrincipal(object storeObject, object discriminant)
        {
            // SAM doesn't use discriminant, should always be null.
            Debug.Assert(discriminant == null);

            Debug.Assert(storeObject != null);
            Debug.Assert(storeObject is DirectoryEntry);

            DirectoryEntry de = (DirectoryEntry)storeObject;

            GlobalDebug.WriteLineIf(GlobalDebug.Info, "SAMStoreCtx", "GetAsPrincipal: using path={0}", de.Path);

            // Construct a appropriate Principal object.
            Principal p = SDSUtils.DirectoryEntryToPrincipal(de, this.OwningContext, null);
            Debug.Assert(p != null);

            // Assign a SAMStoreKey to the newly-constructed Principal.

            // If it doesn't have an objectSid, it's not a principal and we shouldn't be here.
            Debug.Assert((de.Properties["objectSid"] != null) && (de.Properties["objectSid"].Count == 1));

            SAMStoreKey key = new SAMStoreKey(this.MachineFlatName, (byte[])de.Properties["objectSid"].Value);
            p.Key = key;

            return p;
        }
Exemple #7
0
        //
        // Construct a fake Principal to represent a well-known SID like
        // "\Everyone" or "NT AUTHORITY\NETWORK SERVICE"
        //
        internal override Principal ConstructFakePrincipalFromSID(byte[] sid)
        {
            GlobalDebug.WriteLineIf(GlobalDebug.Info,
                                    "SAMStoreCtx",
                                    "ConstructFakePrincipalFromSID: sid={0}, machine={1}",
                                    Utils.ByteArrayToString(sid),
                                    this.MachineFlatName);

            Principal p = Utils.ConstructFakePrincipalFromSID(
                                                        sid,
                                                        this.OwningContext,
                                                        this.MachineUserSuppliedName,
                                                        _credentials,
                                                        this.MachineUserSuppliedName);

            // Assign it a StoreKey
            SAMStoreKey key = new SAMStoreKey(this.MachineFlatName, sid);
            p.Key = key;

            return p;
        }
Exemple #8
0
        //
        // CRUD
        //

        // Used to perform the specified operation on the Principal.  They also make any needed security subsystem
        // calls to obtain digitial signatures.
        //
        // Insert() and Update() must check to make sure no properties not supported by this StoreCtx
        // have been set, prior to persisting the Principal.
        internal override void Insert(Principal p)
        {
            Debug.Assert(p.unpersisted == true);
            Debug.Assert(p.fakePrincipal == false);

            try
            {
                // Insert the principal into the store
                SDSUtils.InsertPrincipal(
                                p,
                                this,
                                new SDSUtils.GroupMembershipUpdater(UpdateGroupMembership),
                                _credentials,
                                _authTypes,
                                false   // handled in PushChangesToNative
                                );

                // Load in all the initial values from the store
                ((DirectoryEntry)p.UnderlyingObject).RefreshCache();

                // Load in the StoreKey
                Debug.Assert(p.Key == null); // since it was previously unpersisted

                Debug.Assert(p.UnderlyingObject != null); // since we just persisted it
                Debug.Assert(p.UnderlyingObject is DirectoryEntry);
                DirectoryEntry de = (DirectoryEntry)p.UnderlyingObject;

                // We just created a principal, so it should have an objectSid
                Debug.Assert((de.Properties["objectSid"] != null) && (de.Properties["objectSid"].Count == 1));

                SAMStoreKey key = new SAMStoreKey(
                                            this.MachineFlatName,
                                            (byte[])de.Properties["objectSid"].Value
                                            );
                p.Key = key;

                // Reset the change tracking
                p.ResetAllChangeStatus();

                GlobalDebug.WriteLineIf(GlobalDebug.Info, "SAMStoreCtx", "Insert: new SID is ", Utils.ByteArrayToString((byte[])de.Properties["objectSid"].Value));
            }
            catch (System.Runtime.InteropServices.COMException e)
            {
                throw ExceptionHelper.GetExceptionFromCOMException(e);
            }
        }
Exemple #9
0
		internal override Principal GetAsPrincipal(object storeObject, object discriminant)
		{
			DirectoryEntry directoryEntry = (DirectoryEntry)storeObject;
			Principal principal = SDSUtils.DirectoryEntryToPrincipal(directoryEntry, base.OwningContext, null);
			SAMStoreKey sAMStoreKey = new SAMStoreKey(this.MachineFlatName, (byte[])directoryEntry.Properties["objectSid"].Value);
			principal.Key = sAMStoreKey;
			return principal;
		}
Exemple #10
0
		internal override Principal ConstructFakePrincipalFromSID(byte[] sid)
		{
			Principal principal = Utils.ConstructFakePrincipalFromSID(sid, base.OwningContext, this.MachineUserSuppliedName, this.credentials, this.MachineUserSuppliedName);
			SAMStoreKey sAMStoreKey = new SAMStoreKey(this.MachineFlatName, sid);
			principal.Key = sAMStoreKey;
			return principal;
		}
Exemple #11
0
		internal override void Insert(Principal p)
		{
			try
			{
				SDSUtils.InsertPrincipal(p, this, new SDSUtils.GroupMembershipUpdater(SAMStoreCtx.UpdateGroupMembership), this.credentials, this.authTypes, false);
				((DirectoryEntry)p.UnderlyingObject).RefreshCache();
				DirectoryEntry underlyingObject = (DirectoryEntry)p.UnderlyingObject;
				SAMStoreKey sAMStoreKey = new SAMStoreKey(this.MachineFlatName, (byte[])underlyingObject.Properties["objectSid"].Value);
				p.Key = sAMStoreKey;
				p.ResetAllChangeStatus();
			}
			catch (COMException cOMException1)
			{
				COMException cOMException = cOMException1;
				throw ExceptionHelper.GetExceptionFromCOMException(cOMException);
			}
		}