2 * Copyright (c) 1999-2005 Todd C. Miller <Todd.Miller@courtesan.com>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 * Sponsored in part by the Defense Advanced Research Projects
17 * Agency (DARPA) and Air Force Research Laboratory, Air Force
18 * Materiel Command, USAF, under agreement number F39502-99-1-0512.
23 #include <sys/types.h>
24 #include <sys/param.h>
33 #endif /* STDC_HEADERS */
37 # ifdef HAVE_STRINGS_H
40 #endif /* HAVE_STRING_H */
43 #endif /* HAVE_UNISTD_H */
48 #include "sudo_auth.h"
51 __unused static const char rcsid[] = "$Sudo: kerb4.c,v 1.11.2.2 2007/06/12 01:28:42 millert Exp $";
55 kerb4_init(pw, promptp, auth)
60 static char realm[REALM_SZ];
62 /* Don't try to verify root */
66 /* Get the local realm, or retrun failure (no krb.conf) */
67 if (krb_get_lrealm(realm, 1) != KSUCCESS)
70 /* Stash a pointer to the realm (used in kerb4_verify) */
71 auth->data = (VOID *) realm;
77 kerb4_verify(pw, pass, auth)
82 char tkfile[sizeof(_PATH_SUDO_TIMEDIR) + 4 + MAX_UID_T_LEN];
83 char *realm = (char *) auth->data;
87 * Set the ticket file to be in sudo sudo timedir so we don't
88 * wipe out other (real) kerberos tickets.
90 (void) snprintf(tkfile, sizeof(tkfile), "%s/tkt%lu",
91 _PATH_SUDO_TIMEDIR, (unsigned long) pw->pw_uid);
92 (void) krb_set_tkt_string(tkfile);
94 /* Convert the password to a ticket given. */
95 error = krb_get_pw_in_tkt(pw->pw_name, "", realm, "krbtgt", realm,
96 DEFAULT_TKT_LIFE, pass);
100 dest_tkt(); /* we are done with the temp ticket */
101 return(AUTH_SUCCESS);
107 (void) fprintf(stderr, "Warning: Kerberos error: %s\n",
111 return(AUTH_FAILURE);