-/* $OpenBSD: gss-serv-krb5.c,v 1.1 2003/08/22 10:56:09 markus Exp $ */
+/* $OpenBSD: gss-serv-krb5.c,v 1.6 2006/07/02 18:36:47 stevesk Exp $ */
/*
* Copyright (c) 2001-2003 Simon Wilkinson. All rights reserved.
#ifdef GSSAPI
#ifdef KRB5
+#include <string.h>
+
#include "auth.h"
#include "xmalloc.h"
#include "log.h"
extern ServerOptions options;
#ifdef HEIMDAL
-#include <krb5.h>
+# include <krb5.h>
#else
-#include <gssapi_krb5.h>
+# ifdef HAVE_GSSAPI_KRB5_H
+# include <gssapi_krb5.h>
+# elif HAVE_GSSAPI_GSSAPI_KRB5_H
+# include <gssapi/gssapi_krb5.h>
+# endif
#endif
static krb5_context krb_context = NULL;
/* Initialise the krb5 library, for the stuff that GSSAPI won't do */
-static int
-ssh_gssapi_krb5_init()
+static int
+ssh_gssapi_krb5_init(void)
{
krb5_error_code problem;
logit("Cannot initialize krb5 context");
return 0;
}
- krb5_init_ets(krb_context);
return 1;
}
krb5_error_code problem;
krb5_principal princ;
OM_uint32 maj_status, min_status;
+ int len;
if (client->creds == NULL) {
debug("No credentials stored");
return;
}
#else
- {
- int tmpfd;
- char ccname[40];
-
- snprintf(ccname, sizeof(ccname),
- "FILE:/tmp/krb5cc_%d_XXXXXX", geteuid());
-
- if ((tmpfd = mkstemp(ccname + strlen("FILE:"))) == -1) {
- logit("mkstemp(): %.100s", strerror(errno));
- problem = errno;
- return;
- }
- if (fchmod(tmpfd, S_IRUSR | S_IWUSR) == -1) {
- logit("fchmod(): %.100s", strerror(errno));
- close(tmpfd);
- problem = errno;
- return;
- }
- close(tmpfd);
- if ((problem = krb5_cc_resolve(krb_context, ccname, &ccache))) {
- logit("krb5_cc_resolve(): %.100s",
- krb5_get_err_text(krb_context, problem));
- return;
- }
+ if ((problem = ssh_krb5_cc_gen(krb_context, &ccache))) {
+ logit("ssh_krb5_cc_gen(): %.100s",
+ krb5_get_err_text(krb_context, problem));
+ return;
}
#endif /* #ifdef HEIMDAL */
- if ((problem = krb5_parse_name(krb_context,
+ if ((problem = krb5_parse_name(krb_context,
client->exportedname.value, &princ))) {
logit("krb5_parse_name(): %.100s",
krb5_get_err_text(krb_context, problem));
krb5_free_principal(krb_context, princ);
- if ((maj_status = gss_krb5_copy_ccache(&min_status,
+ if ((maj_status = gss_krb5_copy_ccache(&min_status,
client->creds, ccache))) {
logit("gss_krb5_copy_ccache() failed");
krb5_cc_destroy(krb_context, ccache);
client->store.filename = xstrdup(krb5_cc_get_name(krb_context, ccache));
client->store.envvar = "KRB5CCNAME";
- client->store.envval = xstrdup(client->store.filename);
+ len = strlen(client->store.filename) + 6;
+ client->store.envval = xmalloc(len);
+ snprintf(client->store.envval, len, "FILE:%s", client->store.filename);
#ifdef USE_PAM
if (options.use_pam)
- do_pam_putenv(client->store.envvar,client->store.envval);
+ do_pam_putenv(client->store.envvar, client->store.envval);
#endif
krb5_cc_close(krb_context, ccache);