/// <summary>
        /// Get User Access, returns user access level and maximum User Ids allowed on BMC
        /// </summary>
        private GetUserAccessResponse GetUserAccess(byte userId, byte channel)
        {
            GetUserAccessResponse UserAccessResponse = (GetUserAccessResponse)this.IpmiSendReceive(
                new GetUserAccessRequest(channel, userId),
                typeof(GetUserAccessResponse));

            return(UserAccessResponse);
        }
        /// <summary>
        /// Get Users. Returns dictionary of User Ids and corresponding User names
        /// </summary>
        public virtual Dictionary <int, string> GetUsers()
        {
            // create return object
            Dictionary <int, string> results = new Dictionary <int, string>();

            // set the default maximum users
            int maxUsers = 15;

            GetUserAccessResponse userAccess = GetUserAccess(defaultUser, defaultChannel);

            if (userAccess.CompletionCode == 0)
            {
                // get maximum user Ids allowed on BMC
                maxUsers = Convert.ToInt32(userAccess.MaxUsers);
            }
            else
            {
                // Surpress IpmiResponseException.  Most bmc types will not throw exceptions
                // HP iLO firmware 1.87, which throws exceptions as the does not implement userId's in accordance
                // with the ipmi specification.
            }

            // loop through all User Id slots on BMC
            // start for loop at defaultUser(1)
            // Ipmi userId 1 is always null, except on HP firmware 1.87
            for (int i = defaultUser; i <= maxUsers; i++)
            {
                byte userByte = Convert.ToByte(i);

                // Get User Name assigned to User Id
                GetUserNameResponse UserNameResponse = (GetUserNameResponse)this.IpmiSendReceive(
                    new GetUserNameRequest(userByte),
                    typeof(GetUserNameResponse));

                if (UserNameResponse != null)
                {
                    if (UserNameResponse.CompletionCode == 0)
                    {
                        string userNameStr = System.Text.ASCIIEncoding.ASCII.GetString(UserNameResponse.UserName).TrimEnd('\0');

                        if (!results.ContainsKey(i))
                        {
                            results.Add(i, userNameStr);
                        }
                    }
                }
                else
                {
                    // Surpress IpmiResponseException.  Most bmc types will not throw exceptions
                    // HP MACH1+ throw exceptions as the does not implement userId's in accordance
                    // with the ipmi specification
                }

                UserNameResponse = null;
            }

            return(results);
        }
        /// <summary>
        /// Get user privilege level
        /// </summary>
        public virtual UserPrivilege GetUserPrivlige(byte userId, byte channel)
        {
            GetUserAccessResponse accessResp = GetUserAccess(userId, channel);

            UserPrivilege privilege = new UserPrivilege(accessResp.CompletionCode);

            if (accessResp.CompletionCode == 0)
            {
                privilege.SetParamaters(new byte[1] {
                    accessResp.AccessLevel
                });
            }

            return(privilege);
        }
Пример #4
0
        /// <summary>
        /// Get Users. Returns dictionary of User Ids and corresponding User names
        /// </summary>
        public virtual Dictionary <int, string> GetUsers()
        {
            // create return object
            Dictionary <int, string> results = new Dictionary <int, string>();

            // maximum users
            int maxUsers = 0;

            GetUserAccessResponse userAccess = GetUserAccess(defaultUser, defaultChannel);

            if (userAccess.CompletionCode == 0)
            {
                // get maximum user Ids allowed on BMC
                maxUsers = Convert.ToInt32(userAccess.MaxUsers);
            }

            // loop through all User Id slots on BMC
            // start for loop at defaultUser(1)
            for (int i = defaultUser; i <= maxUsers; i++)
            {
                byte userByte = Convert.ToByte(i);

                // Get User Name assigned to User Id
                GetUserNameResponse UserNameResponse = (GetUserNameResponse)this.IpmiSendReceive(
                    new GetUserNameRequest(userByte),
                    typeof(GetUserNameResponse));

                if (UserNameResponse != null)
                {
                    if (UserNameResponse.CompletionCode == 0)
                    {
                        string userNameStr = System.Text.ASCIIEncoding.ASCII.GetString(UserNameResponse.UserName).TrimEnd('\0');

                        if (!results.ContainsKey(i))
                        {
                            results.Add(i, userNameStr);
                        }
                    }
                }

                UserNameResponse = null;
            }

            return(results);
        }