MCPcopy Create free account
hub / github.com/catboost/catboost / SetUserGroups

Function SetUserGroups

util/system/shellcommand.cpp:59–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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) {

Callers 1

ImpersonateUserFunction · 0.85

Calls 3

mallocFunction · 0.50
GetMethod · 0.45
ResetMethod · 0.45

Tested by

no test coverage detected