Skip to content

Commit

Permalink
Refactor.
Browse files Browse the repository at this point in the history
Signed-off-by: RileyW <wrllrwwrllrw@gmail.com>
  • Loading branch information
RileyWen committed Nov 21, 2024
1 parent 4a0b61e commit cc88d3a
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions src/Misc/Pam/PamUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@ bool GrpcMigrateSshProcToCgroupAndSetEnv(pam_handle_t *pamh, pid_t pid,
using grpc::ClientContext;
using grpc::Status;

Status status;

std::string craned_unix_socket_address =
fmt::format("unix://{}", g_pam_config.CranedUnixSockPath);

Expand All @@ -377,7 +379,6 @@ bool GrpcMigrateSshProcToCgroupAndSetEnv(pam_handle_t *pamh, pid_t pid,
crane::grpc::MigrateSshProcToCgroupRequest request;
crane::grpc::MigrateSshProcToCgroupReply reply;
ClientContext context;
Status status;

request.set_pid(pid);
request.set_task_id(task_id);
Expand Down Expand Up @@ -405,7 +406,6 @@ bool GrpcMigrateSshProcToCgroupAndSetEnv(pam_handle_t *pamh, pid_t pid,
crane::grpc::QueryTaskEnvVariablesForwardRequest request;
crane::grpc::QueryTaskEnvVariablesForwardReply reply;
ClientContext context;
Status status;

request.set_task_id(task_id);

Expand All @@ -418,21 +418,21 @@ bool GrpcMigrateSshProcToCgroupAndSetEnv(pam_handle_t *pamh, pid_t pid,
return false;
}

if (reply.ok()) {
pam_syslog(pamh, LOG_ERR,
"[Crane] QueryTaskEnvVariablesForward succeeded.");
for (const auto &[name, value] : reply.env_map())
if (pam_putenv(
pamh, fmt::format("{}={}", name, value).c_str()) !=
PAM_SUCCESS) {
pam_syslog(pamh, LOG_ERR, "[Crane] Set env %s=%s failed",
name.c_str(), value.c_str());
return false;
}
return true;
} else {
if (!reply.ok()) {
pam_syslog(pamh, LOG_ERR, "[Crane] QueryTaskEnvVariablesForward failed.");
return false;
}

pam_syslog(pamh, LOG_ERR,
"[Crane] QueryTaskEnvVariablesForward succeeded.");
for (const auto &[name, value] : reply.env_map()) {
int ret = pam_putenv(pamh, fmt::format("{}={}", name, value).c_str());
if (ret != PAM_SUCCESS) {
pam_syslog(pamh, LOG_ERR, "[Crane] Set env %s=%s failed", name.c_str(),
value.c_str());
return false;
}
}
return true;
}
}

0 comments on commit cc88d3a

Please sign in to comment.