Add SIGINFO support for kinit cmd
Use SIGUSR1 if there's no SIGINFO, so the code isn't dead.
This commit is contained in:
@@ -43,6 +43,10 @@
|
|||||||
#include "heimntlm.h"
|
#include "heimntlm.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef SIGINFO
|
||||||
|
#define SIGINFO SIGUSR1
|
||||||
|
#endif
|
||||||
|
|
||||||
int forwardable_flag = -1;
|
int forwardable_flag = -1;
|
||||||
int proxiable_flag = -1;
|
int proxiable_flag = -1;
|
||||||
int renewable_flag = -1;
|
int renewable_flag = -1;
|
||||||
@@ -813,6 +817,53 @@ ticket_lifetime(krb5_context context, krb5_ccache cache, krb5_principal client,
|
|||||||
return timeout;
|
return timeout;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static time_t expire;
|
||||||
|
|
||||||
|
static char siginfo_msg[1024] = "No credentials\n";
|
||||||
|
|
||||||
|
static void
|
||||||
|
update_siginfo_msg(time_t exp, const char *srv)
|
||||||
|
{
|
||||||
|
/* Note that exp is relative time */
|
||||||
|
memset(siginfo_msg, 0, sizeof(siginfo_msg));
|
||||||
|
memcpy(&siginfo_msg, "Updating...\n", sizeof("Updating...\n"));
|
||||||
|
if (exp) {
|
||||||
|
if (srv == NULL) {
|
||||||
|
snprintf(siginfo_msg, sizeof(siginfo_msg),
|
||||||
|
N_("kinit: TGT expires in %llu seconds\n", ""),
|
||||||
|
(unsigned long long)expire);
|
||||||
|
} else {
|
||||||
|
snprintf(siginfo_msg, sizeof(siginfo_msg),
|
||||||
|
N_("kinit: Ticket for %s expired\n", ""), srv);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Expired creds */
|
||||||
|
if (srv == NULL) {
|
||||||
|
snprintf(siginfo_msg, sizeof(siginfo_msg),
|
||||||
|
N_("kinit: TGT expired\n", ""));
|
||||||
|
} else {
|
||||||
|
snprintf(siginfo_msg, sizeof(siginfo_msg),
|
||||||
|
N_("kinit: Ticket for %s expired\n", ""), srv);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_SIGACTION
|
||||||
|
static void
|
||||||
|
handle_siginfo(int sig)
|
||||||
|
{
|
||||||
|
struct iovec iov[2];
|
||||||
|
|
||||||
|
iov[0].iov_base = rk_UNCONST(siginfo_msg);
|
||||||
|
iov[0].iov_len = strlen(siginfo_msg);
|
||||||
|
iov[1].iov_base = "\n";
|
||||||
|
iov[1].iov_len = 1;
|
||||||
|
|
||||||
|
writev(2, iov, sizeof(iov)/sizeof(iov[0]));
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
struct renew_ctx {
|
struct renew_ctx {
|
||||||
krb5_context context;
|
krb5_context context;
|
||||||
krb5_ccache ccache;
|
krb5_ccache ccache;
|
||||||
@@ -825,7 +876,6 @@ renew_func(void *ptr)
|
|||||||
{
|
{
|
||||||
krb5_error_code ret;
|
krb5_error_code ret;
|
||||||
struct renew_ctx *ctx = ptr;
|
struct renew_ctx *ctx = ptr;
|
||||||
time_t expire;
|
|
||||||
time_t renew_expire;
|
time_t renew_expire;
|
||||||
static time_t exp_delay = 1;
|
static time_t exp_delay = 1;
|
||||||
|
|
||||||
@@ -859,6 +909,8 @@ renew_func(void *ptr)
|
|||||||
krb5_afslog(ctx->context, ctx->ccache, NULL, NULL);
|
krb5_afslog(ctx->context, ctx->ccache, NULL, NULL);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
update_siginfo_msg(expire, server_str);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If our tickets have expired and we been able to either renew them
|
* If our tickets have expired and we been able to either renew them
|
||||||
* or obtain new tickets, then we still call this function but we use
|
* or obtain new tickets, then we still call this function but we use
|
||||||
@@ -1086,6 +1138,9 @@ main(int argc, char **argv)
|
|||||||
krb5_principal principal = NULL;
|
krb5_principal principal = NULL;
|
||||||
int optidx = 0;
|
int optidx = 0;
|
||||||
krb5_deltat ticket_life = 0;
|
krb5_deltat ticket_life = 0;
|
||||||
|
#ifdef HAVE_SIGACTION
|
||||||
|
struct sigaction sa;
|
||||||
|
#endif
|
||||||
|
|
||||||
setprogname(argv[0]);
|
setprogname(argv[0]);
|
||||||
|
|
||||||
@@ -1265,6 +1320,14 @@ main(int argc, char **argv)
|
|||||||
ctx.principal = principal;
|
ctx.principal = principal;
|
||||||
ctx.ticket_life = ticket_life;
|
ctx.ticket_life = ticket_life;
|
||||||
|
|
||||||
|
#ifdef HAVE_SIGACTION
|
||||||
|
memset(&sa, 0, sizeof(sa));
|
||||||
|
sigemptyset(&sa.sa_mask);
|
||||||
|
sa.sa_handler = handle_siginfo;
|
||||||
|
|
||||||
|
sigaction(SIGINFO, &sa, NULL);
|
||||||
|
#endif
|
||||||
|
|
||||||
ret = simple_execvp_timed(argv[1], argv+1,
|
ret = simple_execvp_timed(argv[1], argv+1,
|
||||||
renew_func, &ctx, timeout);
|
renew_func, &ctx, timeout);
|
||||||
#define EX_NOEXEC 126
|
#define EX_NOEXEC 126
|
||||||
|
Reference in New Issue
Block a user