コード例 #1
0
        private void btnOK_Click(object sender, EventArgs e)
        {
            string errorMessage = null;

            if (Hostinfo.ValidatePassword(_sNewPassword, _sConfirmPassword, out errorMessage))
            {
                uint result = (uint)LUGAPI.WinError.ERROR_SUCCESS;

                try
                {
                    result = LUGAPI.NetChangePassword(
                        _sHostName, _sUserName, _sNewPassword);
                }
                catch (Exception)
                {
                    result = (uint)LUGAPI.WinError.ERROR_EXCEPTION_IN_SERVICE;
                }

                if (result == (uint)LUGAPI.WinError.ERROR_SUCCESS)
                {
                    this.DialogResult = DialogResult.OK;
                    Close();
                    return;
                }

                errorMessage  = "Win32 Error: ";
                errorMessage += Convert.ToString(Enum.Parse(typeof(LUGAPI.WinError), result.ToString()));
            }

            Logger.ShowUserError(errorMessage);
        }
コード例 #2
0
ファイル: NewGroupDlg.cs プロジェクト: vmware/likewise-open
        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);
        }
コード例 #3
0
        private void enumLUGCallback(LUGAPI.LUGEnumStatus enumStatus)
        {
            Hostinfo hn = ctx as Hostinfo;

            if (enumStatus.entries != null && enumStatus.entries.Count > 0)
            {
                lvArr = new ListViewItem[Convert.ToInt32(enumStatus.entries.Count)];

                for (int i = 0; i < enumStatus.entries.Count; i++)
                {
                    lvArr[i] = new ListViewItem(enumStatus.entries[i]);
                    if (enumStatus.entries[i][1] == LUGAPI.Disabled)
                    {
                        lvArr[i].ImageIndex = (int)imageLUGDisabled;
                    }
                    else
                    {
                        lvArr[i].ImageIndex = (int)imageLUG;
                    }
                }

                this.lvLUGBETA.Items.AddRange(lvArr);

                this.AutoResizePage();

                if (enumStatus.moreEntries)
                {
                    try
                    {
                        if (enumStatus.type == LUGAPI.LUGType.User)
                        {
                            LUGAPI.NetEnumUsers(
                                hn.hostName,
                                enumStatus.resumeHandle,
                                out enumStatus);
                            enumLUGCallback(enumStatus);
                        }
                        else if (enumStatus.type == LUGAPI.LUGType.Group)
                        {
                            LUGAPI.NetEnumGroups(
                                hn.hostName,
                                enumStatus.resumeHandle,
                                out enumStatus);
                            enumLUGCallback(enumStatus);
                        }
                    }
                    catch (Exception ex)
                    {
                        Logger.Log(ex.StackTrace);
                    }
                    //container.SetCursor(Cursors.Default);
                }
                else
                {
                    //container.SetCursor(Cursors.Default);
                }
            }
        }
コード例 #4
0
        public string[] GetUserList()
        {
            string[] members;

            if (LUGAPI.NetGetGroupMembers(_servername, _group, out members) == 0)
            {
                return(members);
            }

            return(null);
        }
コード例 #5
0
        public string GetGroupDescription()
        {
            string description;

            if (LUGAPI.NetGetGroupInfo(_servername, _group, out description) == 0)
            {
                return(description);
            }

            return("");
        }
コード例 #6
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);
        }
コード例 #7
0
        private bool SelectComputer(bool bConnect)
        {
            Logger.Log(String.Format(
                           "LUGPlugin.SelectComputer: hn: {0}",
                           _hn));

            SelectComputerDialog selectDlg = new SelectComputerDialog(
                _hn.hostName,
                _hn.creds.UserName);

            if (selectDlg.ShowDialog() == DialogResult.OK)
            {
                int result = (int)LUGAPI.WinError.ERROR_SUCCESS;

                _hn.hostName       = selectDlg.GetHostname();
                _hn.creds.UserName = selectDlg.GetUsername();
                _hn.creds.Password = selectDlg.GetPassword();

                if (!selectDlg.UseDefaultUserCreds() || bConnect)
                {
                    // Only add a connection if we are not using default creds.
                    result = (int)LUGAPI.NetAddConnection(
                        _hn.hostName,
                        _hn.creds.UserName,
                        _hn.creds.Password);

                    if (Configurations.currentPlatform != LikewiseTargetPlatform.Windows &&
                        result == (int)LUGAPI.WinError.ERROR_FILE_NOT_FOUND)
                    {
                        result = (int)LUGAPI.WinError.ERROR_SUCCESS;
                    }

                    if (result != (int)LUGAPI.WinError.ERROR_SUCCESS)
                    {
                        MessageBox.Show(
                            "Unable to connect to system:\n" + ErrorCodes.WIN32String(result),
                            "Likewise Administrative Console",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Exclamation);

                        return(false);
                    }
                }

                return(true);
            }

            return(false);
        }
コード例 #8
0
        private bool SelectComputer()
        {
            Logger.Log(String.Format(
                           "LUGPlugin.SelectComputer: hn: {0}",
                           _hn));

            SelectComputerDialog selectDlg = new SelectComputerDialog(
                _hn.hostName,
                _hn.creds.UserName);

            if (selectDlg.ShowDialog() == DialogResult.OK)
            {
                int result = (int)ErrorCodes.WIN32Enum.ERROR_SUCCESS;

                _hn.hostName = selectDlg.GetHostname();

                if (!selectDlg.UseDefaultUserCreds())
                {
                    _hn.creds.UserName = selectDlg.GetUsername();
                    _hn.creds.Password = selectDlg.GetPassword();

                    // Only add a connection if we are not using default creds.
                    result = (int)LUGAPI.NetAddConnection(
                        _hn.hostName,
                        _hn.creds.UserName,
                        _hn.creds.Password);

                    if (result != (int)ErrorCodes.WIN32Enum.ERROR_SUCCESS)
                    {
                        MessageBox.Show(
                            "Unable to connect to system:\n" + ErrorCodes.WIN32String(result),
                            "Likewise Administrative Console",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Exclamation);

                        return(false);
                    }
                }

                // This function is going to set _hn.IsConnectionSuccess... return
                // that value for this selection.
                ConnectToDomain();

                return(_hn.IsConnectionSuccess);
            }

            return(false);
        }
コード例 #9
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);
        }
コード例 #10
0
        private void PopulateListView(LUGAPI.LUGEnumStatus enumStatus)
        {
            if (enumStatus.entries != null && enumStatus.entries.Count > 0)
            {
                ListViewItem [] lvArr = new ListViewItem[Convert.ToInt32(enumStatus.entries.Count)];

                for (int i = 0; i < enumStatus.entries.Count; i++)
                {
                    if (enumStatus.type == LUGAPI.LUGType.User)
                    {
                        lvArr[i] = new ListViewItem(enumStatus.entries[i][2]);
                    }
                    else
                    {
                        lvArr[i] = new ListViewItem(enumStatus.entries[i][1]);
                    }
                }

                this.lvMembers.Items.AddRange(lvArr);

                if (enumStatus.moreEntries)
                {
                    try
                    {
                        if (enumStatus.type == LUGAPI.LUGType.User)
                        {
                            LUGAPI.NetEnumUsers(
                                _hostName,
                                enumStatus.resumeHandle,
                                out enumStatus);
                            PopulateListView(enumStatus);
                        }
                        else if (enumStatus.type == LUGAPI.LUGType.Group)
                        {
                            LUGAPI.NetEnumGroups(
                                _hostName,
                                enumStatus.resumeHandle,
                                out enumStatus);
                            PopulateListView(enumStatus);
                        }
                    }
                    catch (Exception)
                    {
                    }
                }
            }
        }
コード例 #11
0
        public bool DeleteUserFromGroup(string group)
        {
            if (ParentPage == null)
            {
                return(false);
            }

            uint result = LUGAPI.NetDeleteUserFromGroup(
                _servername,
                group,
                _username);

            if (result == (uint)LUGAPI.WinError.ERROR_SUCCESS)
            {
                return(true);
            }

            return(false);
        }
コード例 #12
0
        public string[] GetGroupList()
        {
            if (ParentPage == null)
            {
                return(null);
            }

            string [] groups;

            uint result = LUGAPI.NetGetGroups(
                _servername,
                _username,
                out groups);

            if (result == (uint)LUGAPI.WinError.ERROR_SUCCESS)
            {
                return(groups);
            }

            return(null);
        }
コード例 #13
0
ファイル: EditUserPage.cs プロジェクト: vmware/likewise-open
        public void SetData(CredentialEntry ce, string servername, string username)
        {
            _servername = servername;
            _username   = username;

            this.lbUser.Text = String.Format(this.lbUser.Text, username);

            try
            {
                LUGAPI.LUGInfo userInfo;

                if (LUGAPI.NetGetUserInfo(_servername, _username, out userInfo) == 0)
                {
                    GetUserInfoDelegate(userInfo);
                }
            }
            catch (Exception e)
            {
                Logger.LogException("EditUserPage.SetData", e);
            }
        }
コード例 #14
0
        public void PopulatePage(string hostName, bool bListUsers)
        {
            LUGAPI.LUGEnumStatus enumStatus;
            _hostName = hostName;

            if (bListUsers)
            {
                LUGAPI.NetEnumUsers(_hostName, 0, out enumStatus);
            }
            else
            {
                LUGAPI.NetEnumGroups(_hostName, 0, out enumStatus);
            }

            lvMembers.Clear();

            lvMembers.Columns.Add("", 20, HorizontalAlignment.Left);

            PopulateListView(enumStatus);

            lvMembers.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
        }
コード例 #15
0
ファイル: RenameDlg.cs プロジェクト: vmware/likewise-open
        private void btnOK_Click(object sender, EventArgs e)
        {
            uint result = (uint)LUGAPI.WinError.ERROR_SUCCESS;

            if (_isUser)
            {
                result = LUGAPI.NetRenameUser(_hostName, _oldName, _newName);
            }
            else
            {
                result = LUGAPI.NetRenameGroup(_hostName, _oldName, _newName);
            }

            if (result == (uint)LUGAPI.WinError.ERROR_SUCCESS)
            {
                this.DialogResult = DialogResult.OK;
                Close();
                return;
            }

            Logger.ShowUserError(ErrorCodes.WIN32String((int)result));
        }
コード例 #16
0
        public void SetContext(IContext ctx)
        {
            Hostinfo hn = ctx as Hostinfo;

            Logger.Log(String.Format("LUGPlugin.SetHost(hn: {0})",
                                     hn == null ? "null" : hn.hostName), Logger.manageLogLevel);

            _hn = hn;

            if (_hn == null)
            {
                _hn = new Hostinfo();
            }

            if (_pluginNode != null &&
                (!String.IsNullOrEmpty(hn.hostName)))
            {
                uint result = LUGAPI.NetAddConnection(
                    _hn.hostName,
                    _hn.creds.UserName,
                    _hn.creds.Password);

                if (Configurations.currentPlatform != LikewiseTargetPlatform.Windows &&
                    result == (uint)LUGAPI.WinError.ERROR_FILE_NOT_FOUND)
                {
                    result = (uint)LUGAPI.WinError.ERROR_SUCCESS;
                }

                hn.IsConnectionSuccess = false;
                if (result == (uint)LUGAPI.WinError.ERROR_SUCCESS)
                {
                    hn.IsConnectionSuccess = true;
                }

                _pluginNode.SetContext(_hn);
            }
        }
コード例 #17
0
ファイル: MemOfPages.cs プロジェクト: vmware/likewise-open
        /// <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);
        }
コード例 #18
0
        public bool EditLUG(object o)
        {
            bool retValue = false;

            try
            {
                if (memberType == LUGAPI.LUGType.User)
                {
                    UserProperties up = ((UserPropertiesDlg)o).userProperties;
                    Hostinfo       hn = ctx as Hostinfo;

                    uint flags = 0;

                    LUGAPI.LUGInfo userInfo;
                    LUGAPI.NetGetUserInfo(hn.hostName, up.userName, out userInfo);

                    flags = userInfo.flags;

                    uint old_flags = userInfo.flags;

                    Logger.Log(String.Format("LUGPage.EditLUG(user): flags: expired:{0}, cant_change:{1}, never_expires:{2}, disabled:{3}, lockout:{4}, old_flags: {5}",
                                             up.mustChange,
                                             up.cannotChange,
                                             up.neverExpires,
                                             up.isDisabled,
                                             up.isLocked,
                                             LUGAPI.flagDescription(flags)), Logger.netAPILogLevel);

                    // Clear flags we are interested in...
                    flags &= ~(LUGAPI.UF_PASSWORD_EXPIRED);
                    flags &= ~(LUGAPI.UF_PASSWD_CANT_CHANGE);
                    flags &= ~(LUGAPI.UF_DONT_EXPIRE_PASSWD);
                    flags &= ~(LUGAPI.UF_ACCOUNTDISABLE);
                    flags &= ~(LUGAPI.UF_LOCKOUT);

                    // Set flags per user request...
                    flags |= up.mustChange ? LUGAPI.UF_PASSWORD_EXPIRED : 0;
                    flags |= up.cannotChange ? LUGAPI.UF_PASSWD_CANT_CHANGE : 0;
                    flags |= up.isDisabled ? LUGAPI.UF_ACCOUNTDISABLE : 0;
                    flags |= up.neverExpires ? LUGAPI.UF_DONT_EXPIRE_PASSWD : 0;
                    flags |= up.isLocked ? LUGAPI.UF_LOCKOUT : 0;

                    Logger.Log(String.Format("LUGPage.EditLUG(user) new_flags: {0}",
                                             LUGAPI.flagDescription(flags)), Logger.netAPILogLevel);

                    if (userInfo.fullname != up.fullName)
                    {
                        LUGAPI.NetEditUserFullName(hn.hostName, up.userName, up.fullName);
                    }

                    if (userInfo.description != up.description)
                    {
                        LUGAPI.NetEditUserDescription(hn.hostName, up.userName, up.description);
                    }

                    if (old_flags != flags)
                    {
                        LUGAPI.NetEditUserFlags(hn.hostName, up.userName, flags);
                    }

                    retValue = true;


                    Refresh();
                }
                else if (memberType == LUGAPI.LUGType.Group)
                {
                    GroupPropertiesDlg gpDlg = (GroupPropertiesDlg)o;
                    Hostinfo           hn    = ctx as Hostinfo;

                    if (gpDlg != null)
                    {
                        string description;

                        LUGAPI.NetGetGroupInfo(
                            hn.hostName,
                            gpDlg.GroupName,
                            out description
                            );

                        if (description == null || description != gpDlg.Description)
                        {
                            LUGAPI.NetEditGroupDescription(hn.hostName, gpDlg.GroupName, gpDlg.Description);
                            Refresh();
                        }
                    }
                }
            }
            catch (Exception e)
            {
                retValue = false;
                Logger.LogException("EditLUG", e);
            }

            return(retValue);
        }
コード例 #19
0
        public uint AddLUG(object o)
        {
            uint result = (uint)LUGAPI.WinError.ERROR_SUCCESS;

            try
            {
                if (memberType == LUGAPI.LUGType.User)
                {
                    NewUserDlg nu = (NewUserDlg)o;
                    if (nu != null)
                    {
                        Logger.Log(String.Format("LUGPage.AddLUG mustChange={0}, cannotChange={1}, isDisabled={2}, neverExpires={3}",
                                                 nu.MustChange, nu.CannotChange, nu.IsDisabled, nu.NeverExpires));

                        uint     flags = LUGAPI.UF_SCRIPT;
                        Hostinfo hn    = ctx as Hostinfo;

                        flags |= nu.MustChange ? LUGAPI.UF_PASSWORD_EXPIRED : 0;

                        flags |= nu.CannotChange ? LUGAPI.UF_PASSWD_CANT_CHANGE : 0;

                        flags |= nu.IsDisabled ? LUGAPI.UF_ACCOUNTDISABLE : 0;

                        flags |= nu.NeverExpires ? LUGAPI.UF_DONT_EXPIRE_PASSWD : 0;

                        result = LUGAPI.NetAddUser(
                            hn.hostName,
                            nu.User,
                            nu.Password,
                            nu.FullName,
                            nu.Description,
                            flags);

                        if (result == (uint)LUGAPI.WinError.ERROR_SUCCESS)
                        {
                            string[] row = new string[] { "", nu.IsDisabled ? "Disabled" : "", nu.User, nu.FullName, nu.Description };
                            InsertLUGToListView(row);
                            return(result);
                        }
                    }
                }
                else if (memberType == LUGAPI.LUGType.Group)
                {
                    NewGroupDlg ng = (NewGroupDlg)o;
                    Hostinfo    hn = ctx as Hostinfo;
                    if (ng != null)
                    {
                        result = LUGAPI.NetAddGroup(
                            hn.hostName,
                            ng.GroupName,
                            ng.Description);

                        if (result == (uint)LUGAPI.WinError.ERROR_SUCCESS)
                        {
                            string[] row = new string[] { "", ng.GroupName, ng.Description };
                            InsertLUGToListView(row);
                            return(result);
                        }
                    }
                }
            }
            catch (Exception)
            {
                result = (uint)LUGAPI.WinError.ERROR_EXCEPTION_IN_SERVICE;
            }
            return(result);
        }
コード例 #20
0
 public bool DeleteUserFromGroup(string user)
 {
     return(!Convert.ToBoolean(LUGAPI.NetDeleteUserFromGroup(_servername, _group, user)));
 }
コード例 #21
0
 public uint AddUserToGroup(string user)
 {
     return(LUGAPI.NetAddGroupMember(_servername, _group, user));
 }