// Takes care of dropping privileges to the desired user func changeUser(u string) { if u == "" { return } userent, err := utils.UserLookup(u) if err != nil { log.Fatalf("Unable to find user %v: %v", u, err) } uid, err := strconv.Atoi(userent.Uid) if err != nil { log.Fatalf("Invalid uid: %v", userent.Uid) } gid, err := strconv.Atoi(userent.Gid) if err != nil { log.Fatalf("Invalid gid: %v", userent.Gid) } if err := syscall.Setgid(gid); err != nil { log.Fatalf("setgid failed: %v", err) } if err := syscall.Setuid(uid); err != nil { log.Fatalf("setuid failed: %v", err) } }
// Takes care of dropping privileges to the desired user func changeUser(args *DockerInitArgs) error { if args.user == "" { return nil } userent, err := utils.UserLookup(args.user) if err != nil { return fmt.Errorf("Unable to find user %v: %v", args.user, err) } uid, err := strconv.Atoi(userent.Uid) if err != nil { return fmt.Errorf("Invalid uid: %v", userent.Uid) } gid, err := strconv.Atoi(userent.Gid) if err != nil { return fmt.Errorf("Invalid gid: %v", userent.Gid) } if err := syscall.Setgid(gid); err != nil { return fmt.Errorf("setgid failed: %v", err) } if err := syscall.Setuid(uid); err != nil { return fmt.Errorf("setuid failed: %v", err) } return nil }