1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
|
package ipmi
import "context"
// 22.30 Set User Password Command
type SetUserPasswordRequest struct {
// [5:0] - User ID. 000000b = reserved. (User ID 1 is permanently associated with User 1, the null user name).
UserID uint8
// The BMC shall maintain an internal tag that indicates whether
// the password was set as a 16-byte or as a 20-byte password.
Stored20 bool
Operation PasswordOperation
Password string
}
type PasswordOperation uint8
const (
PasswordOperationDisableUser PasswordOperation = 0x00
PasswordOperationEnableUser PasswordOperation = 0x01
PasswordOperationSetPassword PasswordOperation = 0x02
PasswordOperationTestPassword PasswordOperation = 0x03
)
type SetUserPasswordResponse struct {
// empty
}
func (req *SetUserPasswordRequest) Command() Command {
return CommandSetUserPassword
}
func (req *SetUserPasswordRequest) Pack() []byte {
out := make([]byte, 2)
b := req.UserID & 0x3f
if req.Stored20 {
b = setBit7(b)
}
packUint8(b, out, 0)
packUint8(uint8(req.Operation)&0x03, out, 1)
if req.Operation == PasswordOperationSetPassword || req.Operation == PasswordOperationTestPassword {
var passwordStored []byte
if req.Stored20 {
passwordStored = padBytes(req.Password, 20, 0x00)
} else {
passwordStored = padBytes(req.Password, 16, 0x00)
}
out = append(out, passwordStored...)
}
return out
}
func (res *SetUserPasswordResponse) CompletionCodes() map[uint8]string {
return map[uint8]string{}
}
func (res *SetUserPasswordResponse) Unpack(msg []byte) error {
return nil
}
func (res *SetUserPasswordResponse) Format() string {
return ""
}
func (c *Client) SetUserPassword(ctx context.Context, userID uint8, password string, stored20 bool) (response *SetUserPasswordResponse, err error) {
request := &SetUserPasswordRequest{
UserID: userID,
Stored20: stored20,
Operation: PasswordOperationSetPassword,
Password: password,
}
response = &SetUserPasswordResponse{}
err = c.Exchange(ctx, request, response)
return
}
func (c *Client) TestUserPassword(ctx context.Context, userID uint8, password string, stored20 bool) (response *SetUserPasswordResponse, err error) {
request := &SetUserPasswordRequest{
UserID: userID,
Stored20: stored20,
Operation: PasswordOperationTestPassword,
Password: password,
}
response = &SetUserPasswordResponse{}
err = c.Exchange(ctx, request, response)
return
}
func (c *Client) DisableUser(ctx context.Context, userID uint8) (err error) {
request := &SetUserPasswordRequest{
UserID: userID,
Operation: PasswordOperationDisableUser,
}
response := &SetUserPasswordResponse{}
err = c.Exchange(ctx, request, response)
return err
}
func (c *Client) EnableUser(ctx context.Context, userID uint8) (err error) {
request := &SetUserPasswordRequest{
UserID: userID,
Operation: PasswordOperationEnableUser,
}
response := &SetUserPasswordResponse{}
err = c.Exchange(ctx, request, response)
return err
}
|