public bool OnApply()
        {
            Description = this.txtDescription.Text.Trim();

            List <LDAPMod> attrlist = new List <LDAPMod>();
            //the following portion of code uses openldap "ldap_Modify_s"
            string           basedn     = dirnode.DistinguishedName;
            DirectoryContext dirContext = dirnode.LdapContext;

            string[] objectClass_values = null;

            if (!String.IsNullOrEmpty(Description))
            {
                objectClass_values = new string[] { Description, null };
            }
            else
            {
                objectClass_values = new string[] { null };
            }

            LDAPMod attr =
                new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "description",
                            objectClass_values);

            attrlist.Add(attr);

            LDAPMod[] attrArry = attrlist.ToArray();
            int       ret      = -1;

            if (attrArry != null && attrArry.Length != 0)
            {
                ret = dirContext.ModifySynchronous(basedn, attrArry);
            }
            else
            {
                return(true);
            }
            if (ret != 0)
            {
                string sMsg = ErrorCodes.LDAPString(ret);
                container.ShowError(sMsg);
                return(false);
            }
            this.ParentContainer.DataChanged      = false;
            this.ParentContainer.btnApply.Enabled = false;
            return(true);
        }
예제 #2
0
        //when adding a user to a new group, we need modify the group's "member" attribute to include this user,
        // we cannot modify the user's "memberof" attribute
        public bool OnApply()
        {
            bool retVal = true;

            if (IsPrimaryGroupChanged)
            {
                List <LDAPMod> attrlist = new List <LDAPMod>();
                //the following portion of code uses openldap "ldap_Modify_s"
                string           basedn             = _dirnode.DistinguishedName;
                DirectoryContext dirContext         = _dirnode.LdapContext;
                string[]         objectClass_values = null;

                //first obtain the current primaryGroupID value
                DirectoryEntry de = new DirectoryEntry(string.Format("LDAP://{0}/{1}", dirContext.DomainName, ChangedPrimaryGroup));;
                if (de.Properties["primaryGroupToken"].Value != null)
                {
                    int iPrimaryGroupToken = Convert.ToInt32(de.Properties["primaryGroupToken"].Value.ToString());

                    objectClass_values = new string[] { iPrimaryGroupToken.ToString(), null };
                    LDAPMod attr_info =
                        new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "primaryGroupID",
                                    objectClass_values);

                    LDAPMod[] attrinfo = new LDAPMod[] { attr_info };
                    int       ret      = dirContext.ModifySynchronous(basedn, attrinfo);
                    Logger.Log("Modify primaryGroupID returns " + ret);
                    if (ret == 0)
                    {
                        string[] Items = UserGroupUtils.splitDn(ChangedPrimaryGroup);
                        if (!string.IsNullOrEmpty(Items[0]))
                        {
                            DomainUserlabel.Text = Items[0];
                        }
                    }
                    else
                    {
                        retVal = false;
                    }
                }
            }

            retVal = MemOfPages.OnApply_helper(MemofDnList, AddedGroups, RemovedGroups, _dirnode, this);

            return(retVal);
        }
        /// <summary>
        /// Modifies the specified attributes for the selected AD Object either "user" to AD Schema template
        /// </summary>
        /// <returns></returns>
        public bool OnApply()
        {
            if (checkBox.Checked)
            {
                List <LDAPMod> ldapAttrlist = new List <LDAPMod>();
                List <LDAPMod> attrlist     = new List <LDAPMod>();
                //the following portion of code uses openldap "ldap_Modify_s"
                DirectoryContext dirContext         = dirnode.LdapContext;
                string[]         objectClass_values = null;

                objectClass_values = txtDescription.Text.Trim() == string.Empty ? new string[] { null } : new string[] { txtDescription.Text.Trim(), null };
                LDAPMod attr =
                    new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "description",
                                objectClass_values);
                attrlist.Add(attr);

                LDAPMod[] attrArry = attrlist.ToArray();
                int       ret      = -1;
                if (attrArry != null && attrArry.Length != 0)
                {
                    foreach (ADUCDirectoryNode dn in this.parentDlg.ObjectCounts)
                    {
                        if (dn != null)
                        {
                            ret = dirContext.ModifySynchronous(dn.DistinguishedName, attrArry);
                        }
                        if (ret != 0)
                        {
                            string sMsg = ErrorCodes.LDAPString(ret);
                            container.ShowError(sMsg);
                            return(false);
                        }
                    }
                }
                else
                {
                    return(true);
                }

                checkBox.Checked = false;
            }
            return(true);
        }
예제 #4
0
        /// <summary>
        /// Modifies the specified attributes for the selected AD Object either "user" to AD Schema template
        /// </summary>
        /// <returns></returns>
        public bool OnApply()
        {
            List <LDAPMod> attrlist = new List <LDAPMod>();
            //the following portion of code uses openldap "ldap_Modify_s"
            string           basedn     = dirnode.DistinguishedName;
            DirectoryContext dirContext = dirnode.LdapContext;

            string[] objectClass_values = null;

            if (_editObject.Description != "" &&
                !(_editObject.Description.Equals(_originalObject.Description)))
            {
                objectClass_values = new string[] { _editObject.Description, null };
                LDAPMod attr =
                    new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "description",
                                objectClass_values);
                attrlist.Add(attr);
            }

            LDAPMod[] attrArry = attrlist.ToArray();
            int       ret      = -1;

            if (attrArry != null && attrArry.Length != 0)
            {
                ret = dirContext.ModifySynchronous(basedn, attrArry);
            }
            else
            {
                return(true);
            }
            if (ret != 0)
            {
                string sMsg = ErrorCodes.LDAPString(ret);
                container.ShowError(sMsg);
                return(false);
            }
            UpdateOriginalData();
            return(true);
        }
예제 #5
0
        /// <summary>
        /// Modifies the specified attributes for the selected AD Object either "user" to AD Schema template
        /// </summary>
        /// <returns></returns>
        public bool OnApply()
        {
            List <LDAPMod> ldapAttrlist = new List <LDAPMod>();
            List <LDAPMod> attrlist     = new List <LDAPMod>();

            if (dirnode == null ||
                String.IsNullOrEmpty(dirnode.DistinguishedName) ||
                dirnode.LdapContext == null)
            {
                return(true);
            }

            if (ListUserOptions.GetItemChecked(0) && ListUserOptions.GetItemChecked(1))
            {
                string Msg = "You cannot select both 'User must change passowrd at next logon' and 'User cannot change password'\nfor the same user";
                MessageBox.Show(this, Msg, CommonResources.GetString("Caption_Console"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                ListUserOptions.SetItemChecked(1, false);
                return(false);
            }

            if (ListUserOptions.GetItemChecked(0) && ListUserOptions.GetItemChecked(2))
            {
                string Msg = "You have selected 'Password never expires'. \nThe user will not be required to change the password at next logon.";
                MessageBox.Show(this, Msg, CommonResources.GetString("Caption_Console"), MessageBoxButtons.OK, MessageBoxIcon.Information);
                ListUserOptions.SetItemChecked(0, false);
                return(false);
            }

            //the following portion of code uses openldap "ldap_Modify_s"
            string           basedn     = dirnode.DistinguishedName;
            DirectoryContext dirContext = dirnode.LdapContext;

            string[] objectClass_values = null;

            if (Logonname != null && !(Logonname.Trim().Equals(txtlogon.Text.Trim())))
            {
                objectClass_values = new string[] { txtlogon.Text.Trim(), null };
                LDAPMod attr =
                    new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "userPrincipalName",
                                objectClass_values);
                attrlist.Add(attr);
            }

            if (txtpreLogonname.Text.Trim().Length > 0 && !(PreLogonname.Trim().Equals(txtpreLogonname.Text.Trim())))
            {
                objectClass_values = new string[] { txtpreLogonname.Text.Trim(), null };
                LDAPMod attr =
                    new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "sAMAccountName",
                                objectClass_values);
                attrlist.Add(attr);
            }
            if (dateTimePicker.Enabled && dateTimePicker.Value != null)
            {
                objectClass_values = new string[] { ConvertToUnixTimestamp(dateTimePicker.Value).ToString(), null };
                LDAPMod attr =
                    new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "accountExpires",
                                objectClass_values);
                attrlist.Add(attr);
            }

            if (!String.IsNullOrEmpty(pwdLastSet))
            {
                objectClass_values = new string[] { pwdLastSet, null };
                LDAPMod attr =
                    new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "pwdLastSet",
                                objectClass_values);
                attrlist.Add(attr);
            }

            //userWorkstations attribute
            if (String.IsNullOrEmpty(sUserWorkStations))
            {
                objectClass_values = new string[] { null }
            }
            ;
            else
            {
                objectClass_values = new string[] { sUserWorkStations, null }
            };
            LDAPMod attri =
                new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "userWorkstations",
                            objectClass_values);

            attrlist.Add(attri);

            if (ListUserOptions.SelectedIndices.Count > 0)
            {
                objectClass_values = new string[] { CalculateUserAccountControl().ToString(), null };
                LDAPMod attr =
                    new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "userAccountControl",
                                objectClass_values);
                attrlist.Add(attr);
            }

            LDAPMod[] attrArry = attrlist.ToArray();
            int       ret      = -1;

            if (attrArry != null && attrArry.Length != 0)
            {
                ret = dirContext.ModifySynchronous(basedn, attrArry);
            }
            else
            {
                return(true);
            }
            if (ret != 0)
            {
                string sMsg = ErrorCodes.LDAPString(ret);
                container.ShowError(sMsg);
                return(false);
            }
            else
            {
                DirectoryEntry de = new DirectoryEntry(dirnode.DistinguishedName);
                de.Properties["pwdLastSet"].Value = pwdLastSet;
                de.CommitChanges();
            }
            return(true);
        }
예제 #6
0
        /// <summary>
        /// Modifies the specified attributes for the selected AD Object either "user" to AD Schema template
        /// </summary>
        /// <returns></returns>
        public bool OnApply()
        {
            if (txtPrewinGroup.Text.Equals(string.Empty))
            {
                string sMsg =
                    "This object must have a pre-Windows 2000 name." +
                    "Enter a pre-Windows 2000 name, and then try again";
                container.ShowError(sMsg);
                return(false);
            }
            List <LDAPMod> attrlist = new List <LDAPMod>();
            //the following portion of code uses openldap "ldap_Modify_s"
            string           basedn     = dirnode.DistinguishedName;
            DirectoryContext dirContext = dirnode.LdapContext;

            string[] objectClass_values = null;

            if (_editObject.Name != "" &&
                !(_editObject.Name.Equals(_originalObject.Name)))
            {
                objectClass_values = new string[] { _editObject.Name, null };
                LDAPMod attr =
                    new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "sAMAccountName",
                                objectClass_values);
                attrlist.Add(attr);
            }
            if (_editObject.Description != "" &&
                !(_editObject.Description.Equals(_originalObject.Description)))
            {
                objectClass_values = new string[] { _editObject.Description, null };
                LDAPMod attr =
                    new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "description",
                                objectClass_values);
                attrlist.Add(attr);
            }
            if (_editObject.Email != "" &&
                !(_editObject.Email.Equals(_originalObject.Email)))
            {
                objectClass_values = new string[] { _editObject.Email, null };
                LDAPMod attr =
                    new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "mail",
                                objectClass_values);
                attrlist.Add(attr);
            }
            if (_editObject.Notes != "" &&
                !(_editObject.Notes.Equals(_originalObject.Notes)))
            {
                objectClass_values = new string[] { _editObject.Notes, null };
                LDAPMod attr =
                    new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "info",
                                objectClass_values);
                attrlist.Add(attr);
            }
            if (_editObject.GroupType != "" &&
                !(_editObject.GroupType.Equals(_originalObject.GroupType)))
            {
                if (_originalObject.GroupType.Equals("-2147483643"))
                {
                    return(false);
                }
                else
                {
                    objectClass_values = new string[] { _editObject.GroupType, null };
                    LDAPMod attr =
                        new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "groupType",
                                    objectClass_values);
                    attrlist.Add(attr);
                }
            }

            LDAPMod[] attrArry = attrlist.ToArray();
            int       ret      = -1;

            if (attrArry != null && attrArry.Length != 0)
            {
                ret = dirContext.ModifySynchronous(basedn, attrArry);
            }
            else
            {
                return(true);
            }
            if (ret != 0)
            {
                string sMsg = ErrorCodes.LDAPString(ret);
                container.ShowError(sMsg);
                return(false);
            }
            UpdateOriginalData();
            return(true);
        }
예제 #7
0
        /// <summary>
        /// Modifies the specified attributes for the selected AD Object either "user" to AD Schema template
        /// </summary>
        /// <returns></returns>
        public bool OnApply()
        {
            List <LDAPMod> attrlist = new List <LDAPMod>();
            //the following portion of code uses openldap "ldap_Modify_s"
            string           basedn     = dirnode.DistinguishedName;
            DirectoryContext dirContext = dirnode.LdapContext;

            string[] objectClass_values = null;

            if (!(_editObject.Description.Equals(_originalObject.Description)))
            {
                if (String.IsNullOrEmpty(_editObject.Description))
                {
                    objectClass_values = new string[] { null }
                }
                ;
                else
                {
                    objectClass_values = new string[] { _editObject.Description, null }
                };

                LDAPMod attr =
                    new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "description",
                                objectClass_values);
                attrlist.Add(attr);
            }

            if (!_editObject.DelegateTrust.Equals(_originalObject.DelegateTrust))
            {
                int userCtrlBinStr = _editObject.UserCtrlBinStr;

                if (_editObject.DelegateTrust)
                {
                    userCtrlBinStr += 524288;
                }
                else
                {
                    userCtrlBinStr -= 524288;
                }

                string[] userControl_values = { userCtrlBinStr.ToString(), null };
                LDAPMod  userControl_Info   =
                    new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "userAccountControl", userControl_values);

                attrlist.Add(userControl_Info);
            }

            LDAPMod[] attrArry = attrlist.ToArray();
            int       ret      = -1;

            if (attrArry != null && attrArry.Length != 0)
            {
                ret = dirContext.ModifySynchronous(basedn, attrArry);
            }
            else
            {
                return(true);
            }
            if (ret != 0)
            {
                string sMsg = ErrorCodes.LDAPString(ret);
                container.ShowMessage(sMsg);
                return(false);
            }
            UpdateOriginalData();
            return(true);
        }
예제 #8
0
        /// <summary>
        /// Modifies the specified attributes for the selected AD Object either "user" to AD Schema template
        /// </summary>
        /// <returns></returns>
        public bool OnApply()
        {
            if (rbConnect.Checked)
            {
                string Connect = txtConnect.Text.Trim();
                bool   IsValid = true;
                if (String.IsNullOrEmpty(Connect) ||
                    Connect.Length < 3)
                {
                    IsValid = false;
                }
                else if (Connect.Length == 3 && Connect.IndexOf(@"\\") == 0)
                {
                    MessageBox.Show(this, "The home folder could not be created because: The filename, directory name, or valume" +
                                    "label syntax is incorrect",
                                    CommonResources.GetString("Caption_Console"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(false);
                }
                else
                {
                    string[] Slashsplits = Connect.Substring(2).Split('\\');
                    if (String.IsNullOrEmpty(Connect) ||
                        Slashsplits.Length != 2 ||
                        txtConnect.Text.Trim().IndexOf(@"\\") != 0 ||
                        Connect.EndsWith(@"\"))
                    {
                        IsValid = false;
                    }
                }
                if (!IsValid)
                {
                    MessageBox.Show(this, "The specified path is not valid. Enter a valid network server path using the form:\n\\\\server\\share\\folder",
                                    CommonResources.GetString("Caption_Console"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return(false);
                }
            }

            List <LDAPMod> ldapAttrlist = new List <LDAPMod>();
            List <LDAPMod> attrlist     = new List <LDAPMod>();

            if (dirnode == null ||
                String.IsNullOrEmpty(dirnode.DistinguishedName) ||
                dirnode.LdapContext == null)
            {
                return(true);
            }

            //the following portion of code uses openldap "ldap_Modify_s"
            string           basedn     = dirnode.DistinguishedName;
            DirectoryContext dirContext = dirnode.LdapContext;

            string[] objectClass_values = null;

            if (txtProfilePath.Text.Trim().Length > 0)
            {
                objectClass_values = new string[] { txtProfilePath.Text.Trim(), null };
                LDAPMod attr =
                    new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "profilePath",
                                objectClass_values);
                attrlist.Add(attr);
            }
            if (txtLogonScript.Text.Trim().Length > 0)
            {
                objectClass_values = new string[] { txtLogonScript.Text.Trim(), null };
                LDAPMod attr =
                    new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "scriptPath",
                                objectClass_values);
                attrlist.Add(attr);
            }
            if (rbConnect.Checked)
            {
                if (txtConnect.Text.Trim().Length > 0)
                {
                    objectClass_values = new string[] { txtConnect.Text.Trim(), null };
                    LDAPMod attr =
                        new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "homeDirectory",
                                    objectClass_values);
                    attrlist.Add(attr);
                }
                if (cbDrive.SelectedItem != null)
                {
                    objectClass_values = new string[] { cbDrive.SelectedItem.ToString(), null };
                    LDAPMod attr =
                        new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "homeDrive",
                                    objectClass_values);
                    attrlist.Add(attr);
                }
            }
            else
            {
                if (txtLocalPath.Text.Trim().Length > 0)
                {
                    objectClass_values = new string[] { txtLocalPath.Text.Trim(), null };
                    LDAPMod attr =
                        new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "homeDirectory",
                                    objectClass_values);
                    attrlist.Add(attr);
                }
            }

            LDAPMod[] attrArry = attrlist.ToArray();
            int       ret      = -1;

            if (attrArry != null && attrArry.Length != 0)
            {
                ret = dirContext.ModifySynchronous(basedn, attrArry);
            }
            else
            {
                return(true);
            }
            if (ret != 0)
            {
                string sMsg = ErrorCodes.LDAPString(ret);
                container.ShowError(sMsg);
                return(false);
            }
            else
            {
                if (rbConnect.Checked)
                {
                    string sMsg = string.Empty;
                    if (!bIsOpened)
                    {
                        sMsg = string.Format("The {0} home folder was not created because the path was not found. This could be caused by listing\n" +
                                             "non-existent intermediate folders or by not finding the server or share. The user account has been updated" +
                                             "with the new home folder value but you must create the folder manually", txtConnect.Text.Trim());
                        bIsOpened = true;
                    }
                    else
                    {
                        sMsg = "The home folder could not be created becuase: The network location cannot be reached." +
                               "\nFor information about network troubleshooting, see the google map";
                    }

                    MessageBox.Show(this, sMsg,
                                    CommonResources.GetString("Caption_Console"), MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }

            return(true);
        }
예제 #9
0
        public bool OnApply()
        {
            List <LDAPMod>   attrlist   = new List <LDAPMod>();
            LDAPMod          attr       = null;
            DirectoryContext dirContext = dirnode.LdapContext;

            string[] objectClass_values = null;

            string street = txtStreet.Text.Trim();

            if (street.Contains("\n"))
            {
                street = street.Replace("\n", "\r\n");
            }

            objectClass_values = street == string.Empty ? new string[] { null } : new string[] { street, null };
            attr =
                new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "streetAddress",
                            objectClass_values);
            if (bMultiUserSelected && chkStreet.Checked)
            {
                attrlist.Add(attr);
            }
            else if (!bMultiUserSelected && !String.IsNullOrEmpty(txtStreet.Text.Trim()))
            {
                attrlist.Add(attr);
            }

            objectClass_values = txtPOBox.Text.Trim() == string.Empty ? new string[] { null } : new string[] { txtPOBox.Text.Trim(), null };
            attr =
                new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "postOfficeBox",
                            objectClass_values);
            if (bMultiUserSelected && chkPO.Checked)
            {
                attrlist.Add(attr);
            }
            else if (!bMultiUserSelected && !String.IsNullOrEmpty(txtPOBox.Text.Trim()))
            {
                attrlist.Add(attr);
            }

            objectClass_values = txtCity.Text.Trim() == string.Empty ? new string[] { null } : new string[] { txtCity.Text.Trim(), null };
            attr =
                new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "l",
                            objectClass_values);
            if (bMultiUserSelected && chkCity.Checked)
            {
                attrlist.Add(attr);
            }
            else if (!bMultiUserSelected && !String.IsNullOrEmpty(txtCity.Text.Trim()))
            {
                attrlist.Add(attr);
            }

            objectClass_values = txtState.Text.Trim() == string.Empty ? new string[] { null } : new string[] { txtState.Text.Trim(), null };
            attr =
                new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "st",
                            objectClass_values);
            if (bMultiUserSelected && chkState.Checked)
            {
                attrlist.Add(attr);
            }
            else if (!bMultiUserSelected && !String.IsNullOrEmpty(txtState.Text.Trim()))
            {
                attrlist.Add(attr);
            }

            objectClass_values = txtZip.Text.Trim() == string.Empty ? new string[] { null } : new string[] { txtZip.Text.Trim(), null };
            attr =
                new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "postalCode",
                            objectClass_values);
            if (bMultiUserSelected && chkZip.Checked)
            {
                attrlist.Add(attr);
            }
            else if (!bMultiUserSelected && !String.IsNullOrEmpty(txtZip.Text.Trim()))
            {
                attrlist.Add(attr);
            }

            objectClass_values = cbCountry.Text.Trim() == string.Empty ? new string[] { null } : new string[] { cbCountry.Text.Trim(), null };
            attr =
                new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "co",
                            objectClass_values);
            if (bMultiUserSelected && chkCountry.Checked)
            {
                attrlist.Add(attr);
            }
            else if (!bMultiUserSelected && !String.IsNullOrEmpty(cbCountry.Text.Trim()))
            {
                attrlist.Add(attr);
            }

            SetControlStatus();

            LDAPMod[] attrArry = attrlist.ToArray();
            int       ret      = -1;

            if (attrArry != null && attrArry.Length != 0)
            {
                List <object> dirnodes = new List <object>();
                if (parentDlg is MultiItemPropertiesDlg)
                {
                    MPContainer _MultiItemPropertiesDlg = parentDlg as MPContainer;
                    dirnodes = _MultiItemPropertiesDlg.ObjectCounts;
                }
                else
                {
                    MPContainer _ADUserPropertiesDlg = parentDlg as MPContainer;
                    dirnodes = _ADUserPropertiesDlg.ObjectCounts;
                }
                foreach (ADUCDirectoryNode dn in dirnodes)
                {
                    if (dn != null)
                    {
                        ret = dirContext.ModifySynchronous(dn.DistinguishedName, attrArry);
                    }
                    if (ret != 0)
                    {
                        string sMsg = ErrorCodes.LDAPString(ret);
                        container.ShowError(sMsg);
                        return(false);
                    }
                }
            }

            return(true);
        }
예제 #10
0
        public bool OnApply()
        {
            List <LDAPMod>   attrlist   = new List <LDAPMod>();
            LDAPMod          attr       = null;
            DirectoryContext dirContext = dirnode.LdapContext;

            string[] objectClass_values = null;

            if (chkDescription.Checked)
            {
                objectClass_values = txtDescription.Text.Trim() == string.Empty ? new string[] { null } : new string[] { txtDescription.Text.Trim(), null };
                attr =
                    new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "description",
                                objectClass_values);
                attrlist.Add(attr);
            }

            if (chkEmail.Checked)
            {
                objectClass_values = txtEmail.Text.Trim() == string.Empty ? new string[] { null } : new string[] { txtEmail.Text.Trim(), null };
                attr =
                    new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "mail",
                                objectClass_values);
                attrlist.Add(attr);
            }
            if (chkOffice.Checked)
            {
                objectClass_values = txtOffice.Text.Trim() == string.Empty ? new string[] { null } : new string[] { txtOffice.Text.Trim(), null };
                attr =
                    new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "physicalDeliveryOfficeName",
                                objectClass_values);
                attrlist.Add(attr);
            }
            if (chkTelephone.Checked)
            {
                objectClass_values = txtTelephone.Text.Trim() == string.Empty ? new string[] { null } : new string[] { txtTelephone.Text.Trim(), null };
                attr =
                    new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "telephoneNumber",
                                objectClass_values);
                attrlist.Add(attr);
            }

            if (chkWebpage.Checked)
            {
                objectClass_values = txtWebpage.Text.Trim() == string.Empty ? new string[] { null } : new string[] { txtWebpage.Text.Trim(), null };
                attr =
                    new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "wWWHomePage",
                                objectClass_values);
                attrlist.Add(attr);
            }
            SetControlStatus();
            LDAPMod[] attrArry = attrlist.ToArray();
            int       ret      = -1;

            if (attrArry != null && attrArry.Length != 0)
            {
                foreach (ADUCDirectoryNode dn in this.parentDlg.ObjectCounts)
                {
                    if (dn != null)
                    {
                        ret = dirContext.ModifySynchronous(dn.DistinguishedName, attrArry);
                    }
                    if (ret != 0)
                    {
                        string sMsg = ErrorCodes.LDAPString(ret);
                        container.ShowError(sMsg);
                        return(false);
                    }
                }
            }
            else
            {
                return(true);
            }

            return(true);
        }
예제 #11
0
        /// <summary>
        /// Modifies the specified attributes for the selected AD Object either "user" to AD Schema template
        /// </summary>
        /// <returns></returns>
        public bool OnApply()
        {
            List <LDAPMod> ldapAttrlist = new List <LDAPMod>();
            List <LDAPMod> attrlist     = new List <LDAPMod>();

            if (dirnode == null ||
                String.IsNullOrEmpty(dirnode.DistinguishedName) ||
                dirnode.LdapContext == null)
            {
                return(true);
            }

            //the following portion of code uses openldap "ldap_Modify_s"
            string           basedn     = dirnode.DistinguishedName;
            DirectoryContext dirContext = dirnode.LdapContext;

            string[] objectClass_values = null;

            if (_editObject.FirstName != "" &&
                !(_editObject.FirstName.Equals(_originalObject.FirstName)))
            {
                objectClass_values = new string[] { _editObject.FirstName, null };
                LDAPMod attr =
                    new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "givenName",
                                objectClass_values);
                attrlist.Add(attr);
            }
            if (_editObject.Initails != "" &&
                !(_editObject.Initails.Equals(_originalObject.Initails)))
            {
                objectClass_values = new string[] { _editObject.Initails, null };
                LDAPMod attr =
                    new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "initials",
                                objectClass_values);
                attrlist.Add(attr);
            }
            if (_editObject.LastName != "" &&
                !(_editObject.LastName.Equals(_originalObject.LastName)))
            {
                objectClass_values = new string[] { _editObject.LastName, null };
                LDAPMod attr =
                    new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "sn",
                                objectClass_values);
                attrlist.Add(attr);
            }
            if (_editObject.Description != "" &&
                !(_editObject.Description.Equals(_originalObject.Description)))
            {
                objectClass_values = new string[] { _editObject.Description, null };
                LDAPMod attr =
                    new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "description",
                                objectClass_values);
                attrlist.Add(attr);
            }
            if (_editObject.DisplayName != "" &&
                !(_editObject.DisplayName.Equals(_originalObject.DisplayName)))
            {
                objectClass_values = new string[] { _editObject.DisplayName, null };
                LDAPMod attr =
                    new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "displayName",
                                objectClass_values);
                attrlist.Add(attr);
            }
            if (_editObject.Office != "" &&
                !(_editObject.Office.Equals(_originalObject.Office)))
            {
                objectClass_values = new string[] { _editObject.Office, null };
                LDAPMod attr =
                    new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "physicalDeliveryOfficeName",
                                objectClass_values);
                attrlist.Add(attr);
            }
            if (_editObject.Email != "" &&
                !(_editObject.Email.Equals(_originalObject.Email)))
            {
                objectClass_values = new string[] { _editObject.Email, null };
                LDAPMod attr =
                    new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "mail",
                                objectClass_values);
                attrlist.Add(attr);
            }
            if (_editObject.WebPage != "" &&
                !(_editObject.WebPage.Equals(_originalObject.WebPage)))
            {
                objectClass_values = new string[] { _editObject.WebPage, null };
                LDAPMod attr =
                    new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "wWWHomePage",
                                objectClass_values);
                attrlist.Add(attr);
            }
            if (_editObject.TelephoneNumber != "" &&
                !(_editObject.TelephoneNumber.Equals(_originalObject.TelephoneNumber)))
            {
                objectClass_values = new string[] { _editObject.TelephoneNumber, null };
                LDAPMod attr =
                    new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "telephoneNumber",
                                objectClass_values);
                attrlist.Add(attr);
            }
            if (_editObject.TelephoneNumberOther != "" &&
                !(_editObject.TelephoneNumberOther.Equals(_originalObject.TelephoneNumberOther)))
            {
                _editObject.TelephoneNumberOther += ";";
                string[] split = _editObject.TelephoneNumberOther.Split(';');
                split[split.Length - 1] = null;

                objectClass_values = split;

                LDAPMod TelephoneNumberOther =
                    new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "otherTelephone", objectClass_values);
                ldapAttrlist.Add(TelephoneNumberOther);

                attrlist.Add(TelephoneNumberOther);
            }

            if (_editObject.WebPageOther != "" &&
                !(_editObject.WebPageOther.Equals(_originalObject.WebPageOther)))
            {
                objectClass_values = new string[] { _editObject.WebPageOther, null };
                LDAPMod attr =
                    new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "url",
                                objectClass_values);
                attrlist.Add(attr);
            }

            LDAPMod[] attrArry = attrlist.ToArray();
            int       ret      = -1;

            if (attrArry != null && attrArry.Length != 0)
            {
                ret = dirContext.ModifySynchronous(basedn, attrArry);
            }
            else
            {
                return(true);
            }
            if (ret != 0)
            {
                string sMsg = ErrorCodes.LDAPString(ret);
                container.ShowError(sMsg);
                return(false);
            }
            UpdateOriginalData();

            return(true);
        }