Exemple #1
0
        public void Modify(LdapModifyEntry entry)
        {
            ThrowIfNotBound();

            if (string.IsNullOrWhiteSpace(entry.Dn))
            {
                throw new ArgumentNullException(nameof(entry.Dn));
            }

            if (entry.Attributes == null)
            {
                entry.Attributes = new List <LdapModifyAttribute>();
            }

            var attrs = entry.Attributes.Select(ToLdapMod).ToList();

            var ptr = Marshal.AllocHGlobal(IntPtr.Size * (attrs.Count + 1)); // alloc memory for list with last element null

            MarshalUtils.StructureArrayToPtr(attrs, ptr, true);

            try
            {
                ThrowIfError(_ld, ldap_modify_ext_s(_ld,
                                                    entry.Dn,
                                                    ptr,
                                                    IntPtr.Zero,
                                                    IntPtr.Zero
                                                    ), nameof(ldap_modify_ext_s));
            }
            finally
            {
                Marshal.FreeHGlobal(ptr);
                attrs.ForEach(_ => { Marshal.FreeHGlobal(_.mod_vals_u.modv_strvals); });
            }
        }
 public ModifyRequest(LdapModifyEntry ldapModifyEntry)
 {
     LdapEntry = ldapModifyEntry;
 }