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

Function ImpersonateUser

util/system/shellcommand.cpp:73–87  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

71 }
72
73 void ImpersonateUser(const TShellCommandOptions::TUserOptions& userOpts) {
74 if (GetUsername() == userOpts.Name) {
75 return;
76 }
77 const passwd* newUser = getpwnam(userOpts.Name.c_str());
78 if (!newUser) {
79 ythrow TSystemError(errno) << "getpwnam failed";
80 }
81 if (userOpts.UseUserGroups) {
82 SetUserGroups(newUser);
83 }
84 if (setuid(newUser->pw_uid)) {
85 ythrow TSystemError(errno) << "setuid failed";
86 }
87 }
88#elif defined(_win_)
89 constexpr static size_t MAX_COMMAND_LINE = 32 * 1024;
90

Callers 1

OnForkMethod · 0.85

Calls 3

GetUsernameFunction · 0.85
SetUserGroupsFunction · 0.85
c_strMethod · 0.45

Tested by

no test coverage detected