Beispiel #1
0
func getfacl(p string, recursive, header bool) error {
	a, err := acl.GetFileAccess(p)
	if err != nil {
		return fmt.Errorf("Failed to get ACL from %s (%s)", p, err)
	}

	uid, gid, err := os2.Owner(p)
	if err != nil {
		return fmt.Errorf("Failed to lookup owner and group (%s)", err)
	}
	user, err := user.LookupId(strconv.Itoa(int(uid)))
	if err != nil {
		return fmt.Errorf("Failed to lookup user (%s)", err)
	}
	group, err := group.LookupId(strconv.Itoa(int(gid)))
	if err != nil {
		return fmt.Errorf("Failed to lookup group (%s)", err)
	}

	if header {
		fmt.Printf("# file: %s\n# user: %s\n# group: %s\n", p, user.Username, group.Name)
	}
	fmt.Println(a)

	// Free ACL before recursing
	a.Free()

	if recursive {
		if err := recurse(p, header); err != nil {
			return err
		}
	}
	return nil
}
Beispiel #2
0
func HasDirDiff(path, username, groupname string, mode os.FileMode) (bool, error) {
	fi, err := os.Stat(path)
	if err != nil {
		if os.IsNotExist(err) {
			return true, nil
		}
		return false, err
	}
	if !fi.IsDir() {
		return false, errors.New("not a directory")
	}
	if (fi.Mode() - os.ModeDir) != mode {
		return true, nil
	}

	uid := fi.Sys().(*syscall.Stat_t).Uid
	gid := fi.Sys().(*syscall.Stat_t).Gid
	u, err := user.LookupId(fmt.Sprint(uid))
	if err != nil {
		return false, err
	}
	g, err := group.LookupId(fmt.Sprint(gid))
	if err != nil {
		return false, err
	}
	if u.Username != username {
		return true, nil
	}
	if g.Name != groupname {
		return true, nil
	}
	return false, nil
}