14 // User options represent user specifications in a config file.
16 // They can be either a literal username, or a number.
17 type UserOption struct {
24 var EmptyUserSet = os.NewError("No value set")
26 func NewUserOption(defaultValue string) ConfigNode {
27 opt := new(UserOption)
29 opt.defaultvalue = defaultValue
35 func (opt *UserOption) String() string {
39 func (opt *UserOption) Parse(newValue string) os.Error {
40 nvs := strings.TrimSpace(newValue)
42 // validate the input.
43 _, err := strconv.Atoi(nvs)
46 case *strconv.NumError:
47 // not a number. do a lookup.
48 _, err = user.Lookup(nvs)
63 func (opt *UserOption) IsDefault() bool {
67 func (opt *UserOption) Reset() {
68 opt.Value = opt.defaultvalue
72 func (opt *UserOption) User() (userinfo *user.User, err os.Error) {
73 nvs := strings.TrimSpace(opt.Value)
75 // special case: empty string is the current euid.
76 return nil, EmptyUserSet
78 // attempt to map this as a number first, in case a numeric UID
80 val, err := strconv.Atoi(nvs)
83 case *strconv.NumError:
84 // not a number. do a user table lookup.
85 userinfo, err = user.Lookup(nvs)
94 userinfo, err = user.LookupId(val)