Skip to content

Commit

Permalink
krb5: Move soft_terminate_krb5_child to static
Browse files Browse the repository at this point in the history
  • Loading branch information
justin-stephenson committed Apr 29, 2024
1 parent 54179a0 commit 27b2a23
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 55 deletions.
54 changes: 54 additions & 0 deletions src/providers/krb5/krb5_auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "util/crypto/sss_crypto.h"
#include "util/find_uid.h"
#include "util/auth_utils.h"
#include "util/sss_ptr_hash.h"
#include "db/sysdb.h"
#include "util/sss_utf8.h"
#include "util/child_common.h"
Expand Down Expand Up @@ -427,6 +428,59 @@ static bool is_otp_enabled(struct ldb_message *user_msg)
return false;
}

/* Closes the write end of waiting krb5_child */
static errno_t soft_terminate_krb5_child(TALLOC_CTX *mem_ctx,
struct pam_data *pd,
struct krb5_ctx *krb5_ctx)
{
char *io_key;
struct child_io_fds *io;
TALLOC_CTX *tmp_ctx;
int ret;

tmp_ctx = talloc_new(NULL);
if (tmp_ctx == NULL) {
return ENOMEM;
}

if (pd->child_pid == 0) {
DEBUG(SSSDBG_CRIT_FAILURE,
"Expected waiting krb5_child.\n");
ret = EINVAL;
goto done;
}

io_key = talloc_asprintf(tmp_ctx, "%d", pd->child_pid);
if (io_key == NULL) {
ret = ENOMEM;
goto done;
}

io = sss_ptr_hash_lookup(krb5_ctx->io_table, io_key,
struct child_io_fds);
if (io == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE,
"PTR hash lookup failed.\n");
ret = ENOMEM;
goto done;
}

if (io->write_to_child_fd != -1) {
ret = close(io->write_to_child_fd);
io->write_to_child_fd = -1;
if (ret != EOK) {
ret = errno;
DEBUG(SSSDBG_CRIT_FAILURE,
"close failed [%d][%s].\n", ret, strerror(ret));
}
}

ret = EOK;
done:
talloc_free(tmp_ctx);
return ret;
}

/* krb5_auth request */

struct krb5_auth_state {
Expand Down
3 changes: 0 additions & 3 deletions src/providers/krb5/krb5_auth.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,6 @@ errno_t init_renew_tgt(struct krb5_ctx *krb5_ctx, struct be_ctx *be_ctx,
errno_t add_tgt_to_renew_table(struct krb5_ctx *krb5_ctx, const char *ccfile,
struct tgt_times *tgtt, struct pam_data *pd,
const char *upn);
errno_t soft_terminate_krb5_child(TALLOC_CTX *mem_ctx,
struct pam_data *pd,
struct krb5_ctx *krb5_ctx);

/* krb5_access.c */
struct tevent_req *krb5_access_send(TALLOC_CTX *mem_ctx,
Expand Down
52 changes: 0 additions & 52 deletions src/providers/krb5/krb5_child_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -1021,55 +1021,3 @@ parse_krb5_child_response(TALLOC_CTX *mem_ctx, uint8_t *buf, ssize_t len,
return EOK;
}

/* Closes the write end of waiting krb5_child */
errno_t soft_terminate_krb5_child(TALLOC_CTX *mem_ctx,
struct pam_data *pd,
struct krb5_ctx *krb5_ctx)
{
char *io_key;
struct child_io_fds *io;
TALLOC_CTX *tmp_ctx;
int ret;

tmp_ctx = talloc_new(NULL);
if (tmp_ctx == NULL) {
return ENOMEM;
}

if (pd->child_pid == 0) {
DEBUG(SSSDBG_CRIT_FAILURE,
"Expected waiting krb5_child.\n");
ret = EINVAL;
goto done;
}

io_key = talloc_asprintf(tmp_ctx, "%d", pd->child_pid);
if (io_key == NULL) {
ret = ENOMEM;
goto done;
}

io = sss_ptr_hash_lookup(krb5_ctx->io_table, io_key,
struct child_io_fds);
if (io == NULL) {
DEBUG(SSSDBG_CRIT_FAILURE,
"PTR hash lookup failed.\n");
ret = ENOMEM;
goto done;
}

if (io->write_to_child_fd != -1) {
ret = close(io->write_to_child_fd);
io->write_to_child_fd = -1;
if (ret != EOK) {
ret = errno;
DEBUG(SSSDBG_CRIT_FAILURE,
"close failed [%d][%s].\n", ret, strerror(ret));
}
}

ret = EOK;
done:
talloc_free(tmp_ctx);
return ret;
}

0 comments on commit 27b2a23

Please sign in to comment.