throwFromErrno(fmt::format("Cannot do 'getgrnam_r' to obtain gid from group name, specified in the CLICKHOUSE_SETGID environment variable ({})",env_gid),ErrorCodes::SYSTEM_ERROR);
if(!result)
throwException("Group {} specified in the CLICKHOUSE_SETGID environment variable is not found in the system",ErrorCodes::BAD_ARGUMENTS);
gid=entry.gr_gid;
}
if(gid==0)
throwException("Group specified in the CLICKHOUSE_SETGID environment variable has id 0, but dropping privileges to gid 0 does not make sense",ErrorCodes::BAD_ARGUMENTS);
if(0!=setgid(gid))
throwFromErrno(fmt::format("Cannot do 'setgid' to user, specified in the CLICKHOUSE_SETGID environment variable ({})",arg_gid),ErrorCodes::SYSTEM_ERROR);
throwFromErrno(fmt::format("Cannot do 'getpwnam_r' to obtain uid from user name, specified in the CLICKHOUSE_SETUID environment variable ({})",env_uid),ErrorCodes::SYSTEM_ERROR);
if(!result)
throwException("User {} specified in the CLICKHOUSE_SETUID environment variable is not found in the system",ErrorCodes::BAD_ARGUMENTS);
uid=entry.pw_uid;
}
if(uid==0)
throwException("User specified in the CLICKHOUSE_SETUID environment variable has id 0, but dropping privileges to uid 0 does not make sense",ErrorCodes::BAD_ARGUMENTS);
if(0!=setuid(uid))
throwFromErrno(fmt::format("Cannot do 'setuid' to user, specified in the CLICKHOUSE_SETUID environment variable ({})",arg_uid),ErrorCodes::SYSTEM_ERROR);
}
}
}
intmainEntryClickHouseSU(intargc,char**argv)
try
{
usingnamespaceDB;
if(argc<3)
{
std::cout<<"Usage: ./clickhouse su user:group ..."<<std::endl;