10 #define STD_INTERVAL (3600 * 8)
12 volatile int died = 0;
14 int execmode = 0, failsafe = 0;
15 int verbose = 0, quiet = 0;
16 krb5_context context = NULL;
17 krb5_ccache ccache = NULL;
19 void cleanup_krb5(void)
22 krb5_cc_close(context, ccache);
24 krb5_free_context(context);
27 void sighandler(int sig)
44 int main(int argc, char **argv)
48 time_t interval, last, now;
52 interval = STD_INTERVAL;
53 while((c = getopt(argc, argv, "+hi:vqf")) != -1) {
65 p = optarg + strlen(optarg) - 1;
66 if((*p >= 'a') || (*p <= 'z')) {
79 interval *= atoi(optarg);
85 fprintf(stderr, "usage: krb5-agent [-hvqf] [-i interval] [program args...]\n");
91 if((ret = krb5_init_context(&context)) != 0) {
93 fprintf(stderr, "could not initialize Kerberos context: %s\n", error_message(ret));
98 if((ret = krb5_cc_default(context, &ccache)) != 0) {
100 fprintf(stderr, "could not initialize Kerberos context: %s\n", error_message(ret));
108 signal(SIGCHLD, sighandler);
109 if((child = fork()) < 0) {
115 snprintf(buf, 80, "KRB5_AGENT_PID=%i", getpid());
117 execvp(argv[optind], argv + optind);
118 perror(argv[optind]);
122 now = last = time(NULL);
125 wpid = waitpid(-1, &status, WNOHANG);
128 } else if(execmode && (wpid == child)) {
129 /* Try to preserve exit status as best as we can... */
130 if(WIFEXITED(status)) {
131 exit(WEXITSTATUS(status));
133 signal(WTERMSIG(status), SIG_DFL);
134 kill(getpid(), WTERMSIG(status));
140 sleep((last + interval) - now);
142 if(now >= last + interval)
149 * compile-command: "gcc -Wall -g -o krb5-agent krb5-agent.c -lkrb5"