A single add, delete, or replace operation to an LdapAttribute. An LdapModification contains information on the type of modification being performed, the name of the attribute to be replaced, and the new value. Multiple modifications are expressed as an array of modifications, i.e., LdapModification[]. An LdapModification or an LdapModification array enable you to modify an attribute of an Ldap entry. The entire array of modifications must be performed by the server as a single atomic operation in the order they are listed. No changes are made to the directory unless all the operations succeed. If all succeed, a success result is returned to the application. It should be noted that if the connection fails during a modification, it is indeterminate whether the modification occurred or not. There are three types of modification operations: Add, Delete, and Replace. Add: Creates the attribute if it doesn't exist, and adds the specified values. This operation must contain at least one value, and all values of the attribute must be unique. Delete: Deletes specified values from the attribute. If no values are specified, or if all existing values of the attribute are specified, the attribute is removed. Mandatory attributes cannot be removed. Replace: Creates the attribute if necessary, and replaces all existing values of the attribute with the specified values. If you wish to keep any existing values of a multi-valued attribute, you must include these values in the replace operation. A replace operation with no value will remove the entire attribute if it exists, and is ignored if the attribute does not exist. Additional information on Ldap modifications is available in section 4.6 of rfc2251.txt
Example #1
0
    public static void doCleanup(LdapConnection conn, System.String userdn, System.String groupdn)
    {
        // since we have modified the user's attributes and failed to
        // modify the group's attribute, we need to delete the modified
        // user's attribute values.

        // modifications for user
        LdapModification[] modUser = new LdapModification[2];

        // Delete the groupdn from the user's attributes
        LdapAttribute membership = new LdapAttribute("groupMembership", groupdn);
        modUser[0] = new LdapModification(LdapModification.DELETE, membership);
        LdapAttribute security = new LdapAttribute("securityEquals", groupdn);
        modUser[1] = new LdapModification(LdapModification.DELETE, security);

        try
        {
            // Modify the user's attributes
            conn.Modify(userdn, modUser);

            System.Console.Out.WriteLine("Deleted the modified user's attribute values.");
        }
        catch (LdapException e)
        {
            System.Console.Out.WriteLine("Could not delete modified user's attributes: " + e.LdapErrorMessage);
        }
        catch(Exception e)
        {
            Console.WriteLine("Error:" + e.Message);
            return;
        }

        return ;
    }
Example #2
0
        static void Main(string[] args)
        {
            if ( args.Length != 5)
            {
            Console.WriteLine("Usage:   mono ModifyEntry <host name> <ldap port>  <login dn>" + " <password> <Modify dn>");
            Console.WriteLine("Example: mono ModifyEntry Acme.com 389"  + " \"cn=admin,o=Acme\"" + " secret \"cn=ksmith,o=Acme\"");
            return;
            }

            string ldapHost = args[0];
            int ldapPort = System.Convert.ToInt32(args[1]);
            String loginDN  = args[2];
            String password = args[3];
            String dn = args[4];

            try
            {
            Console.WriteLine("Connecting to:" + ldapHost);
            LdapConnection conn= new LdapConnection();
            ArrayList modList = new ArrayList();
            String desc = "This object belongs to test user";
            // Add a new value to the description attribute
            LdapAttribute attribute = new LdapAttribute( "description", desc);
            modList.Add( new LdapModification(LdapModification.ADD, attribute));

            String email = "*****@*****.**";
            attribute = new LdapAttribute( "mail", email);
            modList.Add( new LdapModification(LdapModification.REPLACE, attribute));
            LdapModification[] mods = new LdapModification[modList.Count];
            mods = (LdapModification[])modList.ToArray(typeof(LdapModification));

            conn.Connect(ldapHost,ldapPort);
            conn.Bind(loginDN,password);
            conn.Modify(dn,mods);
            Console.WriteLine(" Entry: " + dn + "Modified Successfully");
            conn.Disconnect();

            }
            catch(LdapException e)
            {
            Console.WriteLine("Error:" + e.LdapErrorMessage);
            return;
            }
            catch(Exception e)
            {
            Console.WriteLine("Error:" + e.Message);
            return;
            }
        }
        /// <summary>
        ///     Constructs the modifications associated with this request.
        /// </summary>
        /// <returns>
        ///     an array of LdapModification objects.
        /// </returns>
        public LdapModification[] GetModifications()
        {
            // Get the RFC request object for this request
            var req = (RfcModifyRequest)Asn1Object.GetRequest();

            // get beginning sequenceOf modifications
            var seqof         = req.Modifications;
            var mods          = seqof.ToArray();
            var modifications = new LdapModification[mods.Length];

            // Process each modification
            for (var m = 0; m < mods.Length; m++)
            {
                // Each modification consists of a mod type and a sequence
                // containing the attr name and a set of values
                var opSeq = (Asn1Sequence)mods[m];
                if (opSeq.Size() != 2)
                {
                    throw new Exception("LdapModifyRequest: modification " + m + " is wrong size: " + opSeq.Size());
                }

                // Contains operation and sequence for the attribute
                var opArray = opSeq.ToArray();
                var asn1Op  = (Asn1Enumerated)opArray[0];

                // get the operation
                var op         = asn1Op.IntValue();
                var attrSeq    = (Asn1Sequence)opArray[1];
                var attrArray  = attrSeq.ToArray();
                var aname      = (RfcAttributeDescription)attrArray[0];
                var name       = aname.StringValue();
                var avalue     = (Asn1SetOf)attrArray[1];
                var valueArray = avalue.ToArray();
                var attr       = new LdapAttribute(name);

                for (var v = 0; v < valueArray.Length; v++)
                {
                    var rfcV = (RfcAttributeValue)valueArray[v];
                    attr.AddValue(rfcV.ByteValue());
                }

                modifications[m] = new LdapModification(op, attr);
            }

            return(modifications);
        }
Example #4
0
        static void Main(string[] args)
        {
            if ( args.Length != 5)
            {
            Console.WriteLine("Usage:   mono ModifyPass <host name> <ldap port>  <login dn>" + " <old password> <new password>");
            Console.WriteLine("Example: mono ModifyPass Acme.com 389"  + " \"cn=tjhon,o=Acme\"" + " secret \"newpass\"");
            return;
            }

            string ldapHost = args[0];
            int ldapPort = System.Convert.ToInt32(args[1]);
            String loginDN  = args[2];
            String opassword = args[3];
            String npassword = args[4];

            try
            {
            LdapConnection conn= new LdapConnection();
            Console.WriteLine("Connecting to:" + ldapHost);
            conn.Connect(ldapHost,ldapPort);
            conn.Bind(loginDN,opassword);
            LdapModification[] modifications = new LdapModification[2];
            LdapAttribute deletePassword = new LdapAttribute("userPassword", opassword);
            modifications[0] = new LdapModification(LdapModification.DELETE, deletePassword);
            LdapAttribute addPassword = new LdapAttribute("userPassword", npassword);
            modifications[1] = new LdapModification(LdapModification.ADD, addPassword);

            conn.Modify(loginDN, modifications);

            System.Console.Out.WriteLine("Your password has been modified.");

            conn.Disconnect();
            }
            catch(LdapException e)
            {
            Console.WriteLine("Error:" + e.LdapErrorMessage);
            return;
            }
            catch(Exception e)
            {
            Console.WriteLine("Error:" + e.Message);
            return;
            }
        }
Example #5
0
    public static void Main( String[] args )
    {
        if (args.Length != 6)
        {
            Console.Error.WriteLine("Usage:   mono SimplePassword <host Name> "
                + "<port number> <login dn> <password> <user dn>"
                + " <new user password>");
            Console.Error.WriteLine("\n Example: mono SimplePassword Acme.com 389"
                + " \"cn=Admin,o=Acme\" secret\n"
                + "         \"cn=JSmith,ou=sales,o=Acme\" userPWD");
            Environment.Exit(1);
        }

        int    ldapVersion = LdapConnection.Ldap_V3;
        String ldapHost    = args[0];
        int    ldapPort    = int.Parse(args[1]);
        String loginDN     = args[2];
        String password    = args[3];
        String userDN      = args[4];
        String userPWD     = args[5];

        /* Simple Password control.  There is no value  associated with this control,
         * just an OID and criticality. Setting the criticality to TRUE means the
         * server will return an error if it does not recognize or is unable to
         * perform the control.
         */

        LdapControl cont = new LdapControl(simplePassOID,
            true,
            null);
        LdapConstraints lcons = new LdapConstraints();
        lcons.setControls(cont);

        LdapConnection lc  = new LdapConnection();

        try
        {
            // connect to the server
            lc.Connect( ldapHost, ldapPort );
            // bind to the server
            lc.Bind( ldapVersion, loginDN, password );

            //  Modify the 'userpassword' attribute, with the Simple
            // Password control.
            LdapModification[] modifications = new LdapModification[1];
            LdapAttribute sPassword = new LdapAttribute( "userPassword",userPWD);
            modifications[0] =
                new LdapModification( LdapModification.REPLACE, sPassword);

            lc.Modify( userDN, modifications,lcons);

            Console.WriteLine("Your Simple password has been modified.");

            lc.Disconnect();
        }
        catch( LdapException e )
        {
            Console.Error.WriteLine("SimplePassword example failed");
            Console.Error.WriteLine( "Error: " + e.ToString() );
            Environment.Exit(1);
        }
        catch( Exception e )
        {
            Console.WriteLine( "Error: " + e.ToString() );
        }
        Environment.Exit(0);
    }
        /// <summary> Encode an array of LdapModifications to ASN.1.
        /// 
        /// </summary>
        /// <param name="mods">an array of LdapModification objects
        /// 
        /// </param>
        /// <returns> an Asn1SequenceOf object containing the modifications.
        /// </returns>
        private static Asn1SequenceOf encodeModifications(LdapModification[] mods)
        {
            // Convert Java-API LdapModification[] to RFC2251 SEQUENCE OF SEQUENCE
            Asn1SequenceOf rfcMods = new Asn1SequenceOf(mods.Length);
            for (int i = 0; i < mods.Length; i++)
            {
                LdapAttribute attr = mods[i].Attribute;

                // place modification attribute values in Asn1SetOf
                Asn1SetOf vals = new Asn1SetOf(attr.size());
                if (attr.size() > 0)
                {
                    System.Collections.IEnumerator attrEnum = attr.ByteValues;
                    while (attrEnum.MoveNext())
                    {
                        vals.add(new RfcAttributeValue((sbyte[]) attrEnum.Current));
                    }
                }

                // create SEQUENCE containing mod operation and attr type and vals
                Asn1Sequence rfcMod = new Asn1Sequence(2);
                rfcMod.add(new Asn1Enumerated(mods[i].Op));
                rfcMod.add(new RfcAttributeTypeAndValues(new RfcAttributeDescription(attr.Name), vals));

                // place SEQUENCE into SEQUENCE OF
                rfcMods.add(rfcMod);
            }
            return rfcMods;
        }
Example #7
0
		/// <summary> Synchronously makes a set of changes to an existing entry in the
		/// directory, using the specified constraints.
		/// 
		/// For example, this modify method changes attribute values, adds new
		/// attribute values, or removes existing attribute values.
		/// 
		/// Because the server applies all changes in an LdapModification array
		/// atomically, the application can expect that no changes
		/// have been performed if an error is returned.
		/// If the request fails with {@link LdapException.CONNECT_ERROR},
		/// it is indeterminate whether or not the server made the modifications.
		/// 
		/// </summary>
		/// <param name="dn">     The distinguished name of the entry to modify.
		/// 
		/// </param>
		/// <param name="mods">   The changes to be made to the entry.
		/// 
		/// </param>
		/// <param name="cons">   The constraints specific to the operation.
		/// 
		/// </param>
		/// <exception> LdapException A general exception which includes an
		/// error message and an Ldap error code.
		/// </exception>
		public virtual void  Modify(System.String dn, LdapModification[] mods, LdapConstraints cons)
		{
			LdapResponseQueue queue = Modify(dn, mods, null, cons);
			
			// Get a handle to the modify response
			LdapResponse modifyResponse = (LdapResponse) (queue.getResponse());
			
			// Set local copy of responseControls synchronously - if there were any
			lock (responseCtlSemaphore)
			{
				responseCtls = modifyResponse.Controls;
			}
			
			chkResultCode(queue, cons, modifyResponse);
			
			return ;
		}
Example #8
0
		/// <summary> Asynchronously makes a set of changes to an existing entry in the
		/// directory.
		/// 
		/// For example, this modify method can change attribute values, add new
		/// attribute values, or remove existing attribute values.
		/// 
		/// Because the server applies all changes in an LdapModification array
		/// atomically, the application can expect that no changes
		/// have been performed if an error is returned.
		/// If the request fails with {@link LdapException.CONNECT_ERROR},
		/// it is indeterminate whether or not the server made the modifications.
		/// 
		/// </summary>
		/// <param name="dn">        The distinguished name of the entry to modify.
		/// 
		/// </param>
		/// <param name="mods">      The changes to be made to the entry.
		/// 
		/// </param>
		/// <param name="queue">     The queue for messages returned from a server in
		/// response to this request. If it is null, a
		/// queue object is created internally.
		/// 
		/// </param>
		/// <exception> LdapException A general exception which includes an error
		/// message and an Ldap error code.
		/// </exception>
		public virtual LdapResponseQueue Modify(System.String dn, LdapModification[] mods, LdapResponseQueue queue)
		{
			return Modify(dn, mods, queue, defSearchCons);
		}
		/// <summary>
		/// Modifies an entry in the Ldap directory with the input LdapModification
		/// values.
		/// </summary>
		/// <param name="mods">Array consisting of the entry attribute name and the
		/// attribute  values to be modified.</param>
		private void ModEntry(LdapModification[] mods)
		{

			try						{
				conn.Modify(Fdn,mods);
			}
			catch(LdapException le)	{
				throw le;
			}
		}
Example #10
0
		/// <summary> 
		/// Synchronously makes a single change to an existing entry in the
		/// directory, using the specified constraints.
		/// 
		/// For example, this modify method changes the value of an attribute,
		/// adds a new attribute value, or removes an existing attribute value.
		/// 
		/// The LdapModification object specifies both the change to be
		/// made and the LdapAttribute value to be changed.
		/// 
		/// If the request fails with {@link LdapException.CONNECT_ERROR},
		/// it is indeterminate whether or not the server made the modification.
		/// 
		/// </summary>
		/// <param name="dn">      The distinguished name of the entry to modify.
		/// 
		/// </param>
		/// <param name="mod">     A single change to be made to the entry.
		/// 
		/// </param>
		/// <param name="cons">    The constraints specific to the operation.
		/// 
		/// </param>
		/// <exception> LdapException A general exception which includes an error
		/// message and an Ldap error code.
		/// </exception>
		public virtual void  Modify(System.String dn, LdapModification mod, LdapConstraints cons)
		{
			LdapModification[] mods = new LdapModification[1];
			mods[0] = mod;
			Modify(dn, mods, cons);
			return ;
		}
Example #11
0
        void modifyGroup(LdapEntry groupEntry, LdapModification[] mods)
        {
            if (groupEntry == null)
                return;

            try {

                conn.Data.Modify (groupEntry.DN, mods);

            } catch (Exception e) {

                string errorMsg =
                    Mono.Unix.Catalog.GetString ("Unable to modify group ") + groupEntry.DN;

                errorMsg += "\nError: " + e.Message;

                HIGMessageDialog dialog = new HIGMessageDialog (
                    editUserDialog,
                    0,
                    Gtk.MessageType.Error,
                    Gtk.ButtonsType.Ok,
                    "Error",
                    errorMsg);

                dialog.Run ();
                dialog.Destroy ();
            }
        }
Example #12
0
 /// <summary>
 /// Write list of LdapModifications to eDirectory
 /// </summary>
 private void WriteLdapChanges(LdapModification[] mods, string dn)
 {
     //Modify the entry in the directory
     lc.Modify ( dn, mods );
 }
Example #13
0
        public void OnAddGroupClicked(object o, EventArgs args)
        {
            List<string> tmp = new List<string> ();

            foreach (KeyValuePair<string, LdapEntry> kvp in _allGroups) {
                if (kvp.Key == primaryGroupLabel.Text || _memberOfGroups.ContainsKey (kvp.Key))
                    continue;

                tmp.Add (kvp.Key);
            }

            SelectGroupsDialog sgd = new SelectGroupsDialog (tmp.ToArray ());

            foreach (string name in sgd.SelectedGroupNames) {

                _memberOfStore.AppendValues (name);

                if (!_memberOfGroups.ContainsKey (name))
                    _memberOfGroups.Add (name, "memberUid");

                LdapAttribute attr = new LdapAttribute ("memberUid", conn.Data.GetAttributeValueFromEntry (currentEntry, "uid"));
                LdapModification lm = new LdapModification (LdapModification.ADD, attr);

                _modsGroup.Add (name, lm);

                updateGroupMembership ();

                _modsGroup.Clear ();
            }
        }
Example #14
0
        public void OnRemoveGroupClicked(object o, EventArgs args)
        {
            TreeModel model;
            TreeIter iter;

            TreePath[] tp = memberOfTreeview.Selection.GetSelectedRows (out model);

            for (int i  = tp.Length; i > 0; i--) {

                _memberOfStore.GetIter (out iter, tp[(i - 1)]);

                string name = (string) _memberOfStore.GetValue (iter, 0);

                _memberOfStore.Remove (ref iter);

                if (_memberOfGroups.ContainsKey (name))
                    _memberOfGroups.Remove (name);

                LdapAttribute attr = new LdapAttribute ("memberUid", conn.Data.GetAttributeValueFromEntry (currentEntry, "uid"));
                LdapModification lm = new LdapModification (LdapModification.DELETE, attr);

                _modsGroup.Add (name, lm);

                updateGroupMembership ();

                _modsGroup.Clear ();
            }
        }
Example #15
0
        void RunViewerPlugin(AttributeViewPlugin avp, string attributeName)
        {
            LdapEntry le = conn.Data.GetEntry (currentDN);
            LdapAttribute la = le.getAttribute (attributeName);

            bool existing = false;
            if (la != null)
                existing = true;

            LdapAttribute newla = new LdapAttribute (attributeName);

            switch (avp.DataType) {

            case ViewerDataType.Binary:
                if (existing)
                    avp.OnActivate (attributeName, SupportClass.ToByteArray (la.ByteValue));
                else
                    avp.OnActivate (attributeName, new byte[0]);
                break;

            case ViewerDataType.String:
                if (existing)
                    avp.OnActivate (attributeName, la.StringValue);
                else
                    avp.OnActivate (attributeName, "");
                break;
            }

            if (avp.ByteValue != null)
                newla.addBase64Value (System.Convert.ToBase64String (avp.ByteValue, 0, avp.ByteValue.Length));
            else if (avp.StringValue != null)
                newla.addValue (avp.StringValue);
            else
                return;

            LdapModification lm;
            if (existing)
                lm = new LdapModification (LdapModification.REPLACE, newla);
            else
                lm = new LdapModification (LdapModification.ADD, newla);

            List<LdapModification> modList = new List<LdapModification> ();
            modList.Add (lm);
            Util.ModifyEntry (conn, currentDN, modList.ToArray());

            this.Show (conn, conn.Data.GetEntry (currentDN), displayAll);
        }
Example #16
0
    public static bool _AddUserToGroup(LdapConnection conn, System.String userdn, System.String groupdn)
    {
        // modifications for group and user
        LdapModification[] modGroup = new LdapModification[2];
        LdapModification[] modUser = new LdapModification[2];

        // Add modifications to modUser
        LdapAttribute membership = new LdapAttribute("groupMembership", groupdn);
        modUser[0] = new LdapModification(LdapModification.ADD, membership);
        LdapAttribute security = new LdapAttribute("securityEquals", groupdn);
        modUser[1] = new LdapModification(LdapModification.ADD, security);

        // Add modifications to modGroup
        LdapAttribute member = new LdapAttribute("uniqueMember", userdn);
        modGroup[0] = new LdapModification(LdapModification.ADD, member);
        LdapAttribute equivalent = new LdapAttribute("equivalentToMe", userdn);
        modGroup[1] = new LdapModification(LdapModification.ADD, equivalent);

        try
        {
            // Modify the user's attributes
            conn.Modify(userdn, modUser);
            System.Console.Out.WriteLine("Modified the user's attribute.");
        }
        catch (LdapException e)
        {
            System.Console.Out.WriteLine("Failed to modify user's attributes: " + e.LdapErrorMessage);
            return false;
        }

        try
        {
            // Modify the group's attributes
            conn.Modify(groupdn, modGroup);
            System.Console.Out.WriteLine("Modified the group's attribute.");
        }
        catch (LdapException e)
        {
            System.Console.Out.WriteLine("Failed to modify group's attributes: " + e.LdapErrorMessage);
            doCleanup(conn, userdn, groupdn);
            return false;
        }
        catch(Exception e)
        {
            Console.WriteLine("Error:" + e.Message);
            return false;
        }
        return true;
    }
Example #17
0
 /// <summary>Modifies the specified entry
 /// </summary>
 /// <param name="dn">Distinguished name of entry to modify</param>
 /// <param name="mods">Array of LdapModification objects</param>
 public void Modify(string dn, LdapModification[] mods)
 {
     conn.Modify (dn, mods);
 }
 /// <summary> Constructs an Ldap Modify request.
 /// 
 /// </summary>
 /// <param name="dn">        The distinguished name of the entry to modify.
 /// 
 /// </param>
 /// <param name="mods">      The changes to be made to the entry.
 /// 
 /// </param>
 /// <param name="cont">       Any controls that apply to the modify request,
 /// or null if none.
 /// </param>
 public LdapModifyRequest(System.String dn, LdapModification[] mods, LdapControl[] cont)
     : base(LdapMessage.MODIFY_REQUEST, new RfcModifyRequest(new RfcLdapDN(dn), encodeModifications(mods)), cont)
 {
     return ;
 }
Example #19
0
        void updateGroupMembership()
        {
            Log.Debug ("START updateGroupMembership ()");

            LdapEntry groupEntry = null;
            LdapModification[] mods = new LdapModification [_modsGroup.Count];

            int count = 0;

            foreach (string key in _modsGroup.Keys) {

                Log.Debug ("group: {0}", key);

                LdapModification lm = (LdapModification) _modsGroup[key];
                groupEntry = (LdapEntry) _allGroups [key];

                mods[count] = lm;

                count++;
            }

            modifyGroup (groupEntry, mods);

            Log.Debug ("END updateGroupMembership ()");
        }
Example #20
0
 /// <summary>
 /// Saves changes made to an existing ZFD 7 Application object
 /// </summary>
 /// <param name="app">
 /// A <see cref="LDAPZFDApp"/>
 /// </param>
 public void modifyZFDApp(LDAPZFDApp app)
 {
     ArrayList modList;
     LDAPZFDApp existingApp = getZFDApp(app.getDN());
     modList = ZFDAppUtils.BuildZFDAppModifications(app, existingApp);
     LdapModification[] mods = new LdapModification[modList.Count];
     Type mtype=Type.GetType("Novell.Directory.LdapModification");
     mods = (LdapModification[])modList.ToArray(typeof(LdapModification));
 }
Example #21
0
        public void Run(LdapEntry lhs, LdapEntry rhs)
        {
            Log.Debug ("Starting LdapEntryAnalyzer");

            if (lhs.CompareTo (rhs) != 0) {
                Log.Debug ("Entry DNs don't match\nlhs: {0}\nrhs: {1}", lhs.DN, rhs.DN);
                return;
            }

            LdapAttributeSet las = lhs.getAttributeSet ();
            foreach (LdapAttribute la in las) {
                LdapAttribute rla = rhs.getAttribute (la.Name);
                if (rla == null){

                    Log.Debug ("Delete attribute {0} from {1}", la.Name, lhs.DN);
                    LdapAttribute a = new LdapAttribute (la.Name);
                    LdapModification m = new LdapModification (LdapModification.DELETE, a);
                    mods.Add (m);

                } else {

                    if (rla.StringValueArray.Length > 1) {

                        Log.Debug ("Replacing attribute {0} with multiple values", la.Name);
                        LdapAttribute a = new LdapAttribute (la.Name, rla.StringValueArray);
                        LdapModification m = new LdapModification (LdapModification.REPLACE, a);
                        mods.Add (m);

                    } else if (la.StringValue != rla.StringValue) {

                        LdapAttribute newattr;
                        LdapModification lm;

                        if (rla.StringValue == "" || rla.StringValue == null) {
                            Log.Debug ("Delete attribute {0} from {1}", la.Name, lhs.DN);
                            newattr = new LdapAttribute (la.Name);
                            lm = new LdapModification (LdapModification.DELETE, newattr);
                        } else {
                            Log.Debug ("Replace attribute {0} value from {1} to {2} ", la.Name, la.StringValue, rla.StringValue);
                            newattr = new LdapAttribute (la.Name, rla.StringValue);
                            lm = new LdapModification (LdapModification.REPLACE, newattr);
                        }

                        mods.Add (lm);
                    }
                }
            }

            LdapAttributeSet rlas = rhs.getAttributeSet ();
            foreach (LdapAttribute la in rlas) {
                LdapAttribute lla = lhs.getAttribute (la.Name);
                if (lla == null && la.StringValue != string.Empty) {
                    Log.Debug ("Add attribute {0} value [{1}] to {2}", la.Name, la.StringValue, lhs.DN);
                    LdapAttribute a = new LdapAttribute (la.Name, la.StringValue);
                    LdapModification m = new LdapModification (LdapModification.ADD, a);
                    mods.Add (m);
                }
            }

            Log.Debug ("End LdapEntryAnalyzer");
        }
		private void CommitEntry()
		{
			PropertyCollection properties = GetProperties(false);
			if(!Nflag)
			{
				System.Collections.ArrayList modList = new System.Collections.ArrayList();
				foreach (string attribute in properties.PropertyNames)
				{
					LdapAttribute attr=null;
					if (properties [attribute].Mbit)
					{
						switch (properties [attribute].Count) {
							case 0:
								attr = new LdapAttribute (attribute, new string [0]);
								modList.Add (new LdapModification (LdapModification.DELETE, attr));
								break;
							case 1:
								string val = (string) properties [attribute].Value;
								attr = new LdapAttribute (attribute, val);
								modList.Add (new LdapModification (LdapModification.REPLACE, attr));
								break;
							default:
								object [] vals = (object [])properties [attribute].Value;
								string [] aStrVals = new string [properties [attribute].Count];
								Array.Copy (vals, 0, aStrVals, 0, properties [attribute].Count);
								attr = new LdapAttribute (attribute, aStrVals);
								modList.Add (new LdapModification (LdapModification.REPLACE, attr));
								break;
						}
						properties [attribute].Mbit=false;
					}
				}
				if (modList.Count > 0) {
					LdapModification[] mods = new LdapModification[modList.Count]; 	
					Type mtype = typeof (LdapModification);
					mods = (LdapModification[])modList.ToArray(mtype);
					ModEntry(mods);
				}
			}
			else
			{
				LdapAttributeSet attributeSet = new LdapAttributeSet();
				foreach (string attribute in properties.PropertyNames)
				{
					if (properties [attribute].Count == 1)
					{
						string val = (string) properties [attribute].Value;
						attributeSet.Add(new LdapAttribute(attribute, val));                
					}
					else
					{
						object[] vals = (object []) properties [attribute].Value;
						string[] aStrVals = new string [properties [attribute].Count];
						Array.Copy (vals,0,aStrVals,0,properties [attribute].Count);
						attributeSet.Add( new LdapAttribute( attribute , aStrVals));
					}
				}
				LdapEntry newEntry = new LdapEntry( Fdn, attributeSet );
				conn.Add( newEntry );
				Nflag = false;
			}
		}
		private void CommitEntry()
		{
			if(!Nflag)
			{
				System.Collections.ArrayList modList = new System.Collections.ArrayList();
				System.Collections.IDictionaryEnumerator id = Properties.GetEnumerator();
				while(id.MoveNext())
				{
					string attribute=(string)id.Key;
					LdapAttribute attr=null;
					if(Properties[attribute].Mbit)
					{
						if(Properties[attribute].Count==1)
						{
							String val = (String)Properties[attribute].Value;
							attr = new LdapAttribute( attribute , val);
						}
						else
						{
							Object[] vals=(Object [])Properties[attribute].Value;
							String[] aStrVals= new String[Properties[attribute].Count];
							Array.Copy(vals,0,aStrVals,0,Properties[attribute].Count);
							attr = new LdapAttribute( attribute , aStrVals);
						}
						modList.Add( new LdapModification(LdapModification.REPLACE, attr));
						Properties[attribute].Mbit=false;
					}
				}
				if (modList.Count > 0) {
					LdapModification[] mods = new LdapModification[modList.Count]; 	
					Type mtype=Type.GetType("System.DirectoryServices.LdapModification");
					mods = (LdapModification[])modList.ToArray(typeof(LdapModification));
					ModEntry(mods);
				}
			}
			else
			{
				LdapAttributeSet attributeSet = new LdapAttributeSet();
				System.Collections.IDictionaryEnumerator id = Properties.GetEnumerator();
				while(id.MoveNext())
				{
					string attribute=(string)id.Key;
					if(Properties[attribute].Count==1)
					{
						String val = (String)Properties[attribute].Value;
						attributeSet.Add(new LdapAttribute(attribute, val));                
					}
					else
					{
						Object[] vals=(Object [])Properties[attribute].Value;
						String[] aStrVals= new String[Properties[attribute].Count];
						Array.Copy(vals,0,aStrVals,0,Properties[attribute].Count);
						attributeSet.Add( new LdapAttribute( attribute , aStrVals));
					}
				}
				LdapEntry newEntry = new LdapEntry( Fdn, attributeSet );
				conn.Add( newEntry );
				Nflag = false;
			}
		}
Example #24
0
File: Util.cs Project: MrJoe/lat
        public static bool ModifyEntry(Connection conn, string dn, LdapModification[] modList)
        {
            if (modList.Length == 0) {
                Log.Debug ("No modifications to make to entry {0}", dn);
                return false;
            }

            try {

                conn.Data.Modify (dn, modList);
                Log.Debug ("Successfully modified entry {0}", dn);

                return true;

            } catch (Exception e) {

                string errorMsg =
                    Mono.Unix.Catalog.GetString ("Unable to modify entry ") + dn;

                errorMsg += "\nError: " + e.Message;

                HIGMessageDialog dialog = new HIGMessageDialog (
                    null,
                    0,
                    Gtk.MessageType.Error,
                    Gtk.ButtonsType.Ok,
                    "Modify entry",
                    errorMsg);

                dialog.Run ();
                dialog.Destroy ();

                return false;
            }
        }
Example #25
0
        void OnApplyClicked(object o, EventArgs args)
        {
            List<LdapModification> modList = new List<LdapModification> ();
            NameValueCollection newAttributes = new NameValueCollection ();

            foreach (object[] row in this.store) {

                string newValue = row[1].ToString();

                if (newValue == "" || newValue == null)
                    continue;

                newAttributes.Add (row[0].ToString(), newValue);
            }

            foreach (string key in newAttributes.AllKeys) {

                string[] newValues = newAttributes.GetValues(key);
                string[] oldValues = currentAttributes.GetValues (key);
                LdapAttribute la = new LdapAttribute (key, newValues);

                if (oldValues == null) {
                    LdapModification lm = new LdapModification (LdapModification.ADD, la);
                    modList.Add (lm);
                } else {

                    foreach (string nv in newValues) {

                        bool foundMatch = false;
                        foreach (string ov in oldValues)
                            if (ov == nv)
                                foundMatch = true;

                        if (!foundMatch) {
                            LdapModification lm = new LdapModification (LdapModification.REPLACE, la);
                            modList.Add (lm);
                        }
                    }
                }
            }

            foreach (string key in currentAttributes.AllKeys) {
                string[] newValues = newAttributes.GetValues (key);

                if (newValues == null) {
                    string[] oldValues = currentAttributes.GetValues (key);
                    LdapAttribute la = new LdapAttribute (key, oldValues);
                    LdapModification lm = new LdapModification (LdapModification.DELETE, la);
                    modList.Add (lm);
                } else {
                    LdapAttribute la = new LdapAttribute (key, newValues);
                    LdapModification lm = new LdapModification (LdapModification.REPLACE, la);
                    modList.Add (lm);
                }
            }

            Util.ModifyEntry (conn, currentDN, modList.ToArray());
        }
Example #26
0
		/// <summary> 
		/// Synchronously makes a set of changes to an existing entry in the
		/// directory.
		/// 
		/// For example, this modify method changes attribute values, adds
		/// new attribute values, or removes existing attribute values.
		/// 
		/// Because the server applies all changes in an LdapModification array
		/// atomically, the application can expect that no changes
		/// have been performed if an error is returned.
		/// If the request fails with {@link LdapException.CONNECT_ERROR},
		/// it is indeterminate whether or not the server made the modifications.
		/// 
		/// </summary>
		/// <param name="dn">    Distinguished name of the entry to modify.
		/// 
		/// </param>
		/// <param name="mods">  The changes to be made to the entry.
		/// 
		/// </param>
		/// <exception> LdapException A general exception which includes an error
		/// message and an Ldap error code.
		/// </exception>
		public virtual void  Modify(System.String dn, LdapModification[] mods)
		{
			Modify(dn, mods, defSearchCons);
			return ;
		}
Example #27
0
        public void OnOkClicked(object o, EventArgs args)
        {
            Connection conn = GetCurrentConnection ();

            LdapEntry[] sr = conn.Data.Search (conn.DirectoryRoot, searchEntry.Text);

            foreach (object[] row in modListStore) {

                string _action = (string) row[0];
                string _name = (string) row[1];
                string _value = (string) row[2];

                LdapAttribute a = new LdapAttribute (_name, _value);
                LdapModification m = null;

                switch (_action.ToLower()) {

                case "add":
                    m = new LdapModification (LdapModification.ADD, a);
                    break;

                case "delete":
                    m = new LdapModification (LdapModification.DELETE, a);
                    break;

                case "replace":
                    m = new LdapModification (LdapModification.REPLACE, a);
                    break;

                default:
                    break;
                }

                if (m != null)
                    _modList.Add (m);
            }

            foreach (LdapEntry e in sr) {
                Util.ModifyEntry (conn, e.DN, _modList.ToArray());
            }

            massEditDialog.HideAll ();
        }
Example #28
0
		/// <summary> Asynchronously makes a single change to an existing entry in the
		/// directory, using the specified constraints and queue.
		/// 
		/// For example, this modify method can change the value of an attribute,
		/// add a new attribute value, or remove an existing attribute value.
		/// 
		/// The LdapModification object specifies both the change to be made
		/// and the LdapAttribute value to be changed.
		/// 
		/// If the request fails with {@link LdapException.CONNECT_ERROR},
		/// it is indeterminate whether or not the server made the modification.
		/// 
		/// </summary>
		/// <param name="dn">         Distinguished name of the entry to modify.
		/// 
		/// </param>
		/// <param name="mod">        A single change to be made to the entry.
		/// 
		/// </param>
		/// <param name="queue">      Handler for messages returned from a server in
		/// response to this request. If it is null, a
		/// queue object is created internally.
		/// 
		/// </param>
		/// <param name="cons">       Constraints specific to the operation.
		/// 
		/// </param>
		/// <exception> LdapException A general exception which includes an error
		/// message and an Ldap error code.
		/// </exception>
		public virtual LdapResponseQueue Modify(System.String dn, LdapModification mod, LdapResponseQueue queue, LdapConstraints cons)
		{
			LdapModification[] mods = new LdapModification[1];
			mods[0] = mod;
			return Modify(dn, mods, queue, cons);
		}
Example #29
0
        void ChangePassword(LdapEntry entry, PasswordDialog pd)
        {
            List<LdapModification> mods = new List<LdapModification> ();

            LdapAttribute la;
            LdapModification lm;

            la = new LdapAttribute ("userPassword", pd.UnixPassword);
            lm = new LdapModification (LdapModification.REPLACE, la);
            mods.Add (lm);

            if (Util.CheckSamba (entry)) {
                la = new LdapAttribute ("sambaLMPassword", pd.LMPassword);
                lm = new LdapModification (LdapModification.REPLACE, la);
                mods.Add (lm);

                la = new LdapAttribute ("sambaNTPassword", pd.NTPassword);
                lm = new LdapModification (LdapModification.REPLACE, la);
                mods.Add (lm);
            }

            Util.ModifyEntry (conn, entry.DN, mods.ToArray());
        }
Example #30
0
		/// <summary> Asynchronously makes a set of changes to an existing entry in the
		/// directory, using the specified constraints and queue.
		/// 
		/// For example, this modify method can change attribute values, add new
		/// attribute values, or remove existing attribute values.
		/// 
		/// Because the server applies all changes in an LdapModification array
		/// atomically, the application can expect that no changes
		/// have been performed if an error is returned.
		/// If the request fails with {@link LdapException.CONNECT_ERROR},
		/// it is indeterminate whether or not the server made the modifications.
		/// 
		/// </summary>
		/// <param name="dn">        The distinguished name of the entry to modify.
		/// 
		/// </param>
		/// <param name="mods">      The changes to be made to the entry.
		/// 
		/// </param>
		/// <param name="queue">     The queue for messages returned from a server in
		/// response to this request. If it is null, a
		/// queue object is created internally.
		/// 
		/// </param>
		/// <param name="cons">      Constraints specific to the operation.
		/// 
		/// </param>
		/// <exception> LdapException A general exception which includes an error
		/// message and an Ldap error code.
		/// </exception>
		public virtual LdapResponseQueue Modify(System.String dn, LdapModification[] mods, LdapResponseQueue queue, LdapConstraints cons)
		{
			if ((System.Object) dn == null)
			{
				// Invalid DN parameter
				throw new System.ArgumentException(ExceptionMessages.DN_PARAM_ERROR);
			}
			
			if (cons == null)
				cons = defSearchCons;
			
			LdapMessage msg = new LdapModifyRequest(dn, mods, cons.getControls());
			
			return SendRequestToServer(msg, cons.TimeLimit, queue, null);
		}
Example #31
0
 /// <summary>Modifies the specified entry
 /// </summary>
 /// <param name="dn">Distinguished name of entry to modify</param>
 /// <param name="mods">Array of LdapModification objects</param>
 public void Modify(string dn, LdapModification[] mods)
 {
     server.Modify (dn, mods);
 }