| 57 | |
| 58 | #if defined(_unix_) |
| 59 | void SetUserGroups(const passwd* pw) { |
| 60 | int ngroups = 1; |
| 61 | THolder<gid_t, TFree> groups = THolder<gid_t, TFree>(static_cast<gid_t*>(malloc(ngroups * sizeof(gid_t)))); |
| 62 | if (getgrouplist(pw->pw_name, pw->pw_gid, reinterpret_cast<TGetGroupListGid*>(groups.Get()), &ngroups) == -1) { |
| 63 | groups.Reset(static_cast<gid_t*>(malloc(ngroups * sizeof(gid_t)))); |
| 64 | if (getgrouplist(pw->pw_name, pw->pw_gid, reinterpret_cast<TGetGroupListGid*>(groups.Get()), &ngroups) == -1) { |
| 65 | ythrow TSystemError() << "getgrouplist failed: user " << pw->pw_name << " (" << pw->pw_uid << ")"; |
| 66 | } |
| 67 | } |
| 68 | if (setgroups(ngroups, groups.Get()) == -1) { |
| 69 | ythrow TSystemError(errno) << "Unable to set groups for user " << pw->pw_name << Endl; |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | void ImpersonateUser(const TShellCommandOptions::TUserOptions& userOpts) { |
| 74 | if (GetUsername() == userOpts.Name) { |
no test coverage detected