示例#1
0
        private bool ProcessMembers(CredentialEntry ce, string domain)
        {
            bool retVal = true;
            uint result = (uint)LUGAPI.WinError.ERROR_SUCCESS;

            for (int i = 0; i < lvMembers.Items.Count; i++)
            {
                try
                {
                    result = LUGAPI.NetAddGroupMember(
                        _hn.hostName,
                        this.GroupName,
                        lvMembers.Items[i].Text
                        );

                    if (result != (uint)LUGAPI.WinError.ERROR_SUCCESS)
                    {
                        container.ShowError(String.Format(
                                                "User \"{0}\" could not be added:\n{1}",
                                                lvMembers.Items[i].Text,
                                                ErrorCodes.WIN32String((int)result)));
                    }
                }
                catch (Exception)
                {
                    retVal = false;
                    container.ShowError(
                        String.Format("Failed to add user {0} to group {1}", lvMembers.Items[i].Text, this.GroupName));
                }
            }
            return(retVal);
        }
示例#2
0
        /// <summary>
        /// Modifies the specified attributes for the selected group in AD schema template
        /// </summary>
        /// <returns></returns>
        public bool OnApply()
        {
            bool retVal = true;

            if (!compareLists(ModifiedObjects, OriginalObjects))
            {
                string AdminGroupDN = string.Concat("CN=Administrators,CN=Builtin,", _dirnode.LdapContext.RootDN);
                if (ModifiedObjects.Contains(AdminGroupDN.ToLower()))
                {
                    string         userlogonName = string.Empty;
                    DirectoryEntry de            = new DirectoryEntry(_dirnode.DistinguishedName, _dirnode.LdapContext.UserName, _dirnode.LdapContext.Password);
                    if (de != null && de.Properties["sAMAccountName"].Value != null)
                    {
                        userlogonName = de.Properties["sAMAccountName"].Value as string;
                    }
                    LUGAPI.NetAddGroupMember(_dirnode.LdapContext.DomainControllerName, "Administrators", userlogonName);

                    ModifiedObjects.Remove(AdminGroupDN.ToLower());
                }

                string[] members_values = new string[ModifiedObjects.Count + 1];
                if (ModifiedObjects.Count > 0)
                {
                    ModifiedObjects.CopyTo(members_values);
                }
                members_values[ModifiedObjects.Count] = null;

                LDAPMod memberattr_Info =
                    new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "member",
                                members_values);

                LDAPMod[] attrinfo = new LDAPMod[] { memberattr_Info };

                if (_dirnode != null)
                {
                    int ret = _dirnode.LdapContext.ModifySynchronous(_dirnode.DistinguishedName, attrinfo);

                    if (ret == 0)
                    {
                        container.ShowMessage("Group Memerbers have been modified successfully!");
                        retVal = true;
                    }
                    else
                    {
                        string sMsg = ErrorCodes.LDAPString(ret);
                        container.ShowError(sMsg);
                        retVal = false;
                    }
                }
            }
            return(retVal);
        }
示例#3
0
        public uint AddUserToGroup(string group)
        {
            uint result = (uint)LUGAPI.WinError.ERROR_SUCCESS;

            if (ParentPage == null)
            {
                return(result);
            }

            result = LUGAPI.NetAddGroupMember(
                _servername,
                group,
                _username);

            return(result);
        }
示例#4
0
 public uint AddUserToGroup(string user)
 {
     return(LUGAPI.NetAddGroupMember(_servername, _group, user));
 }
示例#5
0
        /// <summary>
        /// Modifies the "member" attribute for the selected "user" or "group" in AD schema template
        /// </summary>
        /// <param name="changedGroups"></param>
        /// <param name="_dirnode"></param>
        /// <param name="page"></param>
        /// <param name="operation"></param>
        /// <returns></returns>
        private static bool OnApply_inner(List <string> changedGroups, ADUCDirectoryNode _dirnode, MPPage page, int operation)
        {
            bool   retVal       = true;
            int    ret          = -1;
            string AdminGroupDN = string.Concat("CN=Administrators,CN=Builtin,", _dirnode.LdapContext.RootDN);

            if (changedGroups != null && changedGroups.Count > 0)
            {
                foreach (string newGroupname in changedGroups)
                {
                    List <string> members = new List <string>();
                    members = GetMemberAttrofGroup(newGroupname.Trim(), _dirnode);

                    bool existingMember = false;

                    //if we want to add, we need check whether it is already a member of the group
                    if (operation == ADDING)
                    {
                        foreach (string str in members)
                        {
                            if (str.Equals(_dirnode.DistinguishedName, StringComparison.InvariantCultureIgnoreCase))
                            {
                                existingMember = true;
                                break;
                            }
                        }
                    }

                    if (!existingMember)
                    {
                        if (operation == ADDING)
                        {
                            members.Add(_dirnode.DistinguishedName);
                        }
                        if (operation == REMOVING)
                        {
                            members.Remove(_dirnode.DistinguishedName);
                        }

                        if (newGroupname.Trim().ToLower().Equals(AdminGroupDN.Trim().ToLower()))
                        {
                            string userlogonName = OnApply_GetObjectRealmName(_dirnode);
                            LUGAPI.NetAddGroupMember(_dirnode.LdapContext.DomainControllerName, "Administrators", userlogonName);
                        }
                        else
                        {
                            string[] members_values = new string[members.Count + 1];
                            members.CopyTo(members_values);
                            members_values[members.Count] = null;

                            LDAPMod memberattr_Info =
                                new LDAPMod((int)LDAPMod.mod_ops.LDAP_MOD_REPLACE, "member",
                                            members_values);

                            LDAPMod[] attrinfo = new LDAPMod[] { memberattr_Info };

                            if (_dirnode != null)
                            {
                                ret = _dirnode.LdapContext.ModifySynchronous(newGroupname.Trim(), attrinfo);

                                if (ret == 0)
                                {
                                    retVal = true;
                                }
                                else
                                {
                                    string sMsg = ErrorCodes.LDAPString(ret);
                                    MessageBox.Show(page, sMsg, "Likewise Management Console",
                                                    MessageBoxButtons.OK);
                                    retVal = false;
                                }
                            }
                        }
                    }
                }
                if (ret == 0)
                {
                    if (operation == ADDING)
                    {
                        MessageBox.Show(
                            page,
                            "User/Computer/Group list is added to new groups!",
                            CommonResources.GetString("Caption_Console"),
                            MessageBoxButtons.OK);
                    }
                    if (operation == REMOVING)
                    {
                        MessageBox.Show(
                            page,
                            "User/Computer/Group list is removed from chose groups!",
                            CommonResources.GetString("Caption_Console"),
                            MessageBoxButtons.OK);
                    }
                }
            }
            return(retVal);
        }