Beispiel #1
0
// RoleToID converts username/groupname to their numeric id representations: uid/gid
// Returns error if the role is not supported, usernamd/groupname have not been found
func RoleToID(role string, name string) (uint64, error) {
	var id string
	switch strings.ToLower(role) {
	case "user":
		user, err := user.Lookup(name)
		if err != nil {
			return 0, err
		}
		id = user.Uid
	case "group":
		group, err := group.Lookup(name)
		if err != nil {
			return 0, err
		}
		id = group.Gid
	default:
		return 0, fmt.Errorf("Unsupported role: %s", role)
	}
	// Parse uid/gid
	numID, err := strconv.ParseUint(id, 10, 32)
	if err != nil {
		return 0, err
	}

	return numID, nil
}
Beispiel #2
0
func Test_DefaultProvider_LookupGroup(t *testing.T) {
	current := getCurrentUser(t)
	uip := GetDefaultProvider()

	g1, err := group.LookupID(current.Gid)
	if err != nil {
		t.Fatalf("Can't look up current group by ID directly: %s", err.Error())
	}

	g1b, err := group.Lookup(g1.Name)
	if err != nil {
		t.Fatalf("Can't look up current group by name directly: %s", err.Error())
	}

	g2, err := uip.LookupGroup(g1.Name)
	if err != nil {
		t.Fatalf("Can't look up current user via provider: %s", err.Error())
	}

	assert.Equal(t, g1.Name, g1b.Name, "group module failure")
	assert.Equal(t, g1b.Name, g2.Name, "shim failure")
}
Beispiel #3
0
func (p defaultProvider) LookupGroup(groupname string) (*group.Group, error) {
	return group.Lookup(groupname)
}