|
Jakub Jelen |
8c9e97 |
diff --git a/auth-krb5.c b/auth-krb5.c
|
|
Jakub Jelen |
8c9e97 |
index 09ed151..282fcca 100644
|
|
Jakub Jelen |
8c9e97 |
--- a/auth-krb5.c
|
|
Jakub Jelen |
8c9e97 |
+++ b/auth-krb5.c
|
|
Jakub Jelen |
8c9e97 |
@@ -182,7 +182,8 @@ auth_krb5_password(Authctxt *authctxt, const char *password)
|
|
Jakub Jelen |
8c9e97 |
goto out;
|
|
Jakub Jelen |
8c9e97 |
}
|
|
Jakub Jelen |
8c9e97 |
|
|
Jakub Jelen |
8c9e97 |
- problem = ssh_krb5_cc_gen(authctxt->krb5_ctx, &authctxt->krb5_fwd_ccache);
|
|
Jakub Jelen |
8c9e97 |
+ problem = ssh_krb5_cc_gen(authctxt->krb5_ctx,
|
|
Jakub Jelen |
8c9e97 |
+ &authctxt->krb5_fwd_ccache, &authctxt->krb5_set_env);
|
|
Jakub Jelen |
8c9e97 |
if (problem)
|
|
Jakub Jelen |
8c9e97 |
goto out;
|
|
Jakub Jelen |
8c9e97 |
|
|
Jakub Jelen |
8c9e97 |
@@ -192,7 +192,7 @@ auth_krb5_password(Authctxt *authctxt, const char *password)
|
|
Jakub Jelen |
8c9e97 |
|
|
Jakub Jelen |
8c9e97 |
|
|
Jakub Jelen |
8c9e97 |
#ifdef USE_PAM
|
|
Jakub Jelen |
8c9e97 |
- if (options.use_pam)
|
|
Jakub Jelen |
8c9e97 |
+ if (options.use_pam && authctxt->krb5_set_env)
|
|
Jakub Jelen |
8c9e97 |
do_pam_putenv("KRB5CCNAME", authctxt->krb5_ccname);
|
|
Jakub Jelen |
8c9e97 |
#endif
|
|
Jakub Jelen |
8c9e97 |
|
|
Jakub Jelen |
8c9e97 |
@@ -412,7 +413,7 @@ ssh_krb5_get_cctemplate(krb5_context ctx, char **ccname) {
|
|
Jakub Jelen |
8c9e97 |
|
|
Jakub Jelen |
8c9e97 |
#ifndef HEIMDAL
|
|
Jakub Jelen |
8c9e97 |
krb5_error_code
|
|
Jakub Jelen |
8c9e97 |
-ssh_krb5_cc_gen(krb5_context ctx, krb5_ccache *ccache) {
|
|
Jakub Jelen |
8c9e97 |
+ssh_krb5_cc_gen(krb5_context ctx, krb5_ccache *ccache, int *need_environment) {
|
|
Jakub Jelen |
8c9e97 |
int tmpfd, ret, oerrno;
|
|
Jakub Jelen |
8c9e97 |
char *ccname;
|
|
Jakub Jelen |
8c9e97 |
#ifdef USE_CCAPI
|
|
Jakub Jelen |
8c9e97 |
@@ -423,8 +424,10 @@ ssh_krb5_cc_gen(krb5_context ctx, krb5_ccache *ccache) {
|
|
Jakub Jelen |
8c9e97 |
|
|
Jakub Jelen |
8c9e97 |
#endif
|
|
Jakub Jelen |
8c9e97 |
|
|
Jakub Jelen |
8c9e97 |
+ if (need_environment)
|
|
Jakub Jelen |
8c9e97 |
+ *need_environment = 0;
|
|
Jakub Jelen |
8c9e97 |
ret = ssh_krb5_get_cctemplate(ctx, &ccname);
|
|
Jakub Jelen |
8c9e97 |
-
|
|
Jakub Jelen |
8c9e97 |
+ /* fallback to the ccache in /tmp */
|
|
Jakub Jelen |
8c9e97 |
if (ret) {
|
|
Jakub Jelen |
8c9e97 |
ret = asprintf(&ccname, cctemplate, geteuid());
|
|
Jakub Jelen |
8c9e97 |
if (ret == -1)
|
|
Jakub Jelen |
8c9e97 |
@@ -444,6 +447,9 @@ ssh_krb5_cc_gen(krb5_context ctx, krb5_ccache *ccache) {
|
|
Jakub Jelen |
8c9e97 |
close(tmpfd);
|
|
Jakub Jelen |
8c9e97 |
return oerrno;
|
|
Jakub Jelen |
8c9e97 |
}
|
|
Jakub Jelen |
8c9e97 |
+ /* make sure the KRBCCNAME is set for non-standard location */
|
|
Jakub Jelen |
8c9e97 |
+ if (need_environment)
|
|
Jakub Jelen |
8c9e97 |
+ *need_environment = 1;
|
|
Jakub Jelen |
8c9e97 |
close(tmpfd);
|
|
Jakub Jelen |
8c9e97 |
}
|
|
Jakub Jelen |
8c9e97 |
debug("%s: Setting ccname to %s", __func__, ccname);
|
|
Jakub Jelen |
8c9e97 |
diff --git a/auth.h b/auth.h
|
|
Jakub Jelen |
8c9e97 |
index 954a0dd..0819483 100644
|
|
Jakub Jelen |
8c9e97 |
--- a/auth.h
|
|
Jakub Jelen |
8c9e97 |
+++ b/auth.h
|
|
Jakub Jelen |
8c9e97 |
@@ -78,6 +78,7 @@ struct Authctxt {
|
|
Jakub Jelen |
8c9e97 |
krb5_principal krb5_user;
|
|
Jakub Jelen |
8c9e97 |
char *krb5_ticket_file;
|
|
Jakub Jelen |
8c9e97 |
char *krb5_ccname;
|
|
Jakub Jelen |
8c9e97 |
+ int krb5_set_env;
|
|
Jakub Jelen |
8c9e97 |
#endif
|
|
Jakub Jelen |
5b55d0 |
struct sshbuf *loginmsg;
|
|
Jakub Jelen |
5b55d0 |
|
|
Jakub Jelen |
8c9e97 |
@@ -220,7 +221,7 @@ int sys_auth_passwd(Authctxt *, const char *);
|
|
Jakub Jelen |
8c9e97 |
|
|
Jakub Jelen |
8c9e97 |
#if defined(KRB5) && !defined(HEIMDAL)
|
|
Jakub Jelen |
8c9e97 |
#include <krb5.h>
|
|
Jakub Jelen |
8c9e97 |
-krb5_error_code ssh_krb5_cc_gen(krb5_context, krb5_ccache *);
|
|
Jakub Jelen |
8c9e97 |
+krb5_error_code ssh_krb5_cc_gen(krb5_context, krb5_ccache *, int *);
|
|
Jakub Jelen |
8c9e97 |
krb5_error_code ssh_krb5_get_k5login_directory(krb5_context ctx,
|
|
Jakub Jelen |
8c9e97 |
char **k5login_directory);
|
|
Jakub Jelen |
8c9e97 |
#endif
|
|
Jakub Jelen |
8c9e97 |
diff --git a/gss-serv-krb5.c b/gss-serv-krb5.c
|
|
Jakub Jelen |
8c9e97 |
index 0fa3838..4127245 100644
|
|
Jakub Jelen |
8c9e97 |
--- a/gss-serv-krb5.c
|
|
Jakub Jelen |
8c9e97 |
+++ b/gss-serv-krb5.c
|
|
Jakub Jelen |
8c9e97 |
@@ -382,7 +382,7 @@ ssh_gssapi_krb5_cmdok(krb5_principal principal, const char *name,
|
|
Jakub Jelen |
8c9e97 |
/* This writes out any forwarded credentials from the structure populated
|
|
Jakub Jelen |
8c9e97 |
* during userauth. Called after we have setuid to the user */
|
|
Jakub Jelen |
8c9e97 |
|
|
Jakub Jelen |
8c9e97 |
-static void
|
|
Jakub Jelen |
8c9e97 |
+static int
|
|
Jakub Jelen |
8c9e97 |
ssh_gssapi_krb5_storecreds(ssh_gssapi_client *client)
|
|
Jakub Jelen |
8c9e97 |
{
|
|
Jakub Jelen |
8c9e97 |
krb5_ccache ccache;
|
|
Jakub Jelen |
8c9e97 |
@@ -391,14 +391,15 @@ ssh_gssapi_krb5_storecreds(ssh_gssapi_client *client)
|
|
Jakub Jelen |
8c9e97 |
OM_uint32 maj_status, min_status;
|
|
Jakub Jelen |
8c9e97 |
const char *new_ccname, *new_cctype;
|
|
Jakub Jelen |
8c9e97 |
const char *errmsg;
|
|
Jakub Jelen |
8c9e97 |
+ int set_env = 0;
|
|
Jakub Jelen |
8c9e97 |
|
|
Jakub Jelen |
8c9e97 |
if (client->creds == NULL) {
|
|
Jakub Jelen |
8c9e97 |
debug("No credentials stored");
|
|
Jakub Jelen |
8c9e97 |
- return;
|
|
Jakub Jelen |
8c9e97 |
+ return 0;
|
|
Jakub Jelen |
8c9e97 |
}
|
|
Jakub Jelen |
8c9e97 |
|
|
Jakub Jelen |
8c9e97 |
if (ssh_gssapi_krb5_init() == 0)
|
|
Jakub Jelen |
8c9e97 |
- return;
|
|
Jakub Jelen |
8c9e97 |
+ return 0;
|
|
Jakub Jelen |
8c9e97 |
|
|
Jakub Jelen |
8c9e97 |
#ifdef HEIMDAL
|
|
Jakub Jelen |
8c9e97 |
# ifdef HAVE_KRB5_CC_NEW_UNIQUE
|
|
Jakub Jelen |
8c9e97 |
@@ -412,14 +413,14 @@ ssh_gssapi_krb5_storecreds(ssh_gssapi_client *client)
|
|
Jakub Jelen |
8c9e97 |
krb5_get_err_text(krb_context, problem));
|
|
Jakub Jelen |
8c9e97 |
# endif
|
|
Jakub Jelen |
8c9e97 |
krb5_free_error_message(krb_context, errmsg);
|
|
Jakub Jelen |
8c9e97 |
- return;
|
|
Jakub Jelen |
8c9e97 |
+ return 0;
|
|
Jakub Jelen |
8c9e97 |
}
|
|
Jakub Jelen |
8c9e97 |
#else
|
|
Jakub Jelen |
8c9e97 |
- if ((problem = ssh_krb5_cc_gen(krb_context, &ccache))) {
|
|
Jakub Jelen |
8c9e97 |
+ if ((problem = ssh_krb5_cc_gen(krb_context, &ccache, &set_env))) {
|
|
Jakub Jelen |
8c9e97 |
errmsg = krb5_get_error_message(krb_context, problem);
|
|
Jakub Jelen |
8c9e97 |
logit("ssh_krb5_cc_gen(): %.100s", errmsg);
|
|
Jakub Jelen |
8c9e97 |
krb5_free_error_message(krb_context, errmsg);
|
|
Jakub Jelen |
8c9e97 |
- return;
|
|
Jakub Jelen |
8c9e97 |
+ return 0;
|
|
Jakub Jelen |
8c9e97 |
}
|
|
Jakub Jelen |
8c9e97 |
#endif /* #ifdef HEIMDAL */
|
|
Jakub Jelen |
8c9e97 |
|
|
Jakub Jelen |
8c9e97 |
@@ -428,7 +429,7 @@ ssh_gssapi_krb5_storecreds(ssh_gssapi_client *client)
|
|
Jakub Jelen |
8c9e97 |
errmsg = krb5_get_error_message(krb_context, problem);
|
|
Jakub Jelen |
8c9e97 |
logit("krb5_parse_name(): %.100s", errmsg);
|
|
Jakub Jelen |
8c9e97 |
krb5_free_error_message(krb_context, errmsg);
|
|
Jakub Jelen |
8c9e97 |
- return;
|
|
Jakub Jelen |
8c9e97 |
+ return 0;
|
|
Jakub Jelen |
8c9e97 |
}
|
|
Jakub Jelen |
8c9e97 |
|
|
Jakub Jelen |
8c9e97 |
if ((problem = krb5_cc_initialize(krb_context, ccache, princ))) {
|
|
Jakub Jelen |
8c9e97 |
@@ -437,7 +438,7 @@ ssh_gssapi_krb5_storecreds(ssh_gssapi_client *client)
|
|
Jakub Jelen |
8c9e97 |
krb5_free_error_message(krb_context, errmsg);
|
|
Jakub Jelen |
8c9e97 |
krb5_free_principal(krb_context, princ);
|
|
Jakub Jelen |
8c9e97 |
krb5_cc_destroy(krb_context, ccache);
|
|
Jakub Jelen |
8c9e97 |
- return;
|
|
Jakub Jelen |
8c9e97 |
+ return 0;
|
|
Jakub Jelen |
8c9e97 |
}
|
|
Jakub Jelen |
8c9e97 |
|
|
Jakub Jelen |
8c9e97 |
krb5_free_principal(krb_context, princ);
|
|
Jakub Jelen |
8c9e97 |
@@ -446,7 +447,7 @@ ssh_gssapi_krb5_storecreds(ssh_gssapi_client *client)
|
|
Jakub Jelen |
8c9e97 |
client->creds, ccache))) {
|
|
Jakub Jelen |
8c9e97 |
logit("gss_krb5_copy_ccache() failed");
|
|
Jakub Jelen |
8c9e97 |
krb5_cc_destroy(krb_context, ccache);
|
|
Jakub Jelen |
8c9e97 |
- return;
|
|
Jakub Jelen |
8c9e97 |
+ return 0;
|
|
Jakub Jelen |
8c9e97 |
}
|
|
Jakub Jelen |
8c9e97 |
|
|
Jakub Jelen |
8c9e97 |
new_cctype = krb5_cc_get_type(krb_context, ccache);
|
|
Jakub Jelen |
8c9e97 |
@@ -471,7 +478,7 @@ ssh_gssapi_krb5_storecreds(ssh_gssapi_client *client)
|
|
Jakub Jelen |
8c9e97 |
#endif
|
|
Jakub Jelen |
8c9e97 |
|
|
Jakub Jelen |
8c9e97 |
#ifdef USE_PAM
|
|
Jakub Jelen |
8c9e97 |
- if (options.use_pam)
|
|
Jakub Jelen |
8c9e97 |
+ if (options.use_pam && set_env)
|
|
Jakub Jelen |
8c9e97 |
do_pam_putenv(client->store.envvar, client->store.envval);
|
|
Jakub Jelen |
8c9e97 |
#endif
|
|
Jakub Jelen |
8c9e97 |
|
|
Jakub Jelen |
8c9e97 |
@@ -479,7 +486,7 @@ ssh_gssapi_krb5_storecreds(ssh_gssapi_client *client)
|
|
Jakub Jelen |
8c9e97 |
|
|
Jakub Jelen |
8c9e97 |
client->store.data = krb_context;
|
|
Jakub Jelen |
8c9e97 |
|
|
Jakub Jelen |
8c9e97 |
- return;
|
|
Jakub Jelen |
8c9e97 |
+ return set_env;
|
|
Jakub Jelen |
8c9e97 |
}
|
|
Jakub Jelen |
8c9e97 |
|
|
Jakub Jelen |
8c9e97 |
int
|
|
Jakub Jelen |
8c9e97 |
diff --git a/gss-serv.c b/gss-serv.c
|
|
Jakub Jelen |
8c9e97 |
index 681847a..2a02dae 100644
|
|
Jakub Jelen |
8c9e97 |
--- a/gss-serv.c
|
|
Jakub Jelen |
8c9e97 |
+++ b/gss-serv.c
|
|
Jakub Jelen |
8c9e97 |
@@ -404,7 +404,7 @@ ssh_gssapi_cleanup_creds(void)
|
|
Jakub Jelen |
8c9e97 |
debug("%s: krb5_cc_resolve(): %.100s", __func__,
|
|
Jakub Jelen |
8c9e97 |
krb5_get_err_text(gssapi_client.store.data, problem));
|
|
Jakub Jelen |
8c9e97 |
} else if ((problem = krb5_cc_destroy(gssapi_client.store.data, ccache))) {
|
|
Jakub Jelen |
8c9e97 |
- debug("%s: krb5_cc_resolve(): %.100s", __func__,
|
|
Jakub Jelen |
8c9e97 |
+ debug("%s: krb5_cc_destroy(): %.100s", __func__,
|
|
Jakub Jelen |
8c9e97 |
krb5_get_err_text(gssapi_client.store.data, problem));
|
|
Jakub Jelen |
8c9e97 |
} else {
|
|
Jakub Jelen |
8c9e97 |
krb5_free_context(gssapi_client.store.data);
|
|
Jakub Jelen |
8c9e97 |
@@ -414,13 +414,15 @@ ssh_gssapi_cleanup_creds(void)
|
|
Jakub Jelen |
8c9e97 |
}
|
|
Jakub Jelen |
8c9e97 |
|
|
Jakub Jelen |
8c9e97 |
/* As user */
|
|
Jakub Jelen |
8c9e97 |
-void
|
|
Jakub Jelen |
8c9e97 |
+int
|
|
Jakub Jelen |
8c9e97 |
ssh_gssapi_storecreds(void)
|
|
Jakub Jelen |
8c9e97 |
{
|
|
Jakub Jelen |
8c9e97 |
if (gssapi_client.mech && gssapi_client.mech->storecreds) {
|
|
Jakub Jelen |
8c9e97 |
- (*gssapi_client.mech->storecreds)(&gssapi_client);
|
|
Jakub Jelen |
8c9e97 |
+ return (*gssapi_client.mech->storecreds)(&gssapi_client);
|
|
Jakub Jelen |
8c9e97 |
} else
|
|
Jakub Jelen |
8c9e97 |
debug("ssh_gssapi_storecreds: Not a GSSAPI mechanism");
|
|
Jakub Jelen |
8c9e97 |
+
|
|
Jakub Jelen |
8c9e97 |
+ return 0;
|
|
Jakub Jelen |
8c9e97 |
}
|
|
Jakub Jelen |
8c9e97 |
|
|
Jakub Jelen |
8c9e97 |
/* This allows GSSAPI methods to do things to the childs environment based
|
|
Jakub Jelen |
8c9e97 |
diff --git a/session.c b/session.c
|
|
Jakub Jelen |
8c9e97 |
index df4985a..b7a6a57 100644
|
|
Jakub Jelen |
8c9e97 |
--- a/session.c
|
|
Jakub Jelen |
8c9e97 |
+++ b/session.c
|
|
Jakub Jelen |
8c9e97 |
@@ -1084,7 +1084,8 @@ do_setup_env(Session *s, const char *shell)
|
|
Jakub Jelen |
8c9e97 |
/* Allow any GSSAPI methods that we've used to alter
|
|
Jakub Jelen |
8c9e97 |
* the childs environment as they see fit
|
|
Jakub Jelen |
8c9e97 |
*/
|
|
Jakub Jelen |
8c9e97 |
- ssh_gssapi_do_child(&env, &envsize);
|
|
Jakub Jelen |
8c9e97 |
+ if (s->authctxt->krb5_set_env)
|
|
Jakub Jelen |
8c9e97 |
+ ssh_gssapi_do_child(&env, &envsize);
|
|
Jakub Jelen |
8c9e97 |
#endif
|
|
Jakub Jelen |
8c9e97 |
|
|
Jakub Jelen |
8c9e97 |
/* Set basic environment. */
|
|
Jakub Jelen |
8c9e97 |
@@ -1196,7 +1197,7 @@ do_setup_env(Session *s, const char *shell)
|
|
Jakub Jelen |
8c9e97 |
}
|
|
Jakub Jelen |
8c9e97 |
#endif
|
|
Jakub Jelen |
8c9e97 |
#ifdef KRB5
|
|
Jakub Jelen |
8c9e97 |
- if (s->authctxt->krb5_ccname)
|
|
Jakub Jelen |
8c9e97 |
+ if (s->authctxt->krb5_ccname && s->authctxt->krb5_set_env)
|
|
Jakub Jelen |
8c9e97 |
child_set_env(&env, &envsize, "KRB5CCNAME",
|
|
Jakub Jelen |
8c9e97 |
s->authctxt->krb5_ccname);
|
|
Jakub Jelen |
8c9e97 |
#endif
|
|
Jakub Jelen |
8c9e97 |
diff --git a/ssh-gss.h b/ssh-gss.h
|
|
Jakub Jelen |
8c9e97 |
index 6f2b0ac..73ef2c2 100644
|
|
Jakub Jelen |
8c9e97 |
--- a/ssh-gss.h
|
|
Jakub Jelen |
8c9e97 |
+++ b/ssh-gss.h
|
|
Jakub Jelen |
8c9e97 |
@@ -106,7 +106,7 @@ typedef struct ssh_gssapi_mech_struct {
|
|
Jakub Jelen |
8c9e97 |
int (*dochild) (ssh_gssapi_client *);
|
|
Jakub Jelen |
8c9e97 |
int (*userok) (ssh_gssapi_client *, char *);
|
|
Jakub Jelen |
8c9e97 |
int (*localname) (ssh_gssapi_client *, char **);
|
|
Jakub Jelen |
8c9e97 |
- void (*storecreds) (ssh_gssapi_client *);
|
|
Jakub Jelen |
8c9e97 |
+ int (*storecreds) (ssh_gssapi_client *);
|
|
Jakub Jelen |
8c9e97 |
int (*updatecreds) (ssh_gssapi_ccache *, ssh_gssapi_client *);
|
|
Jakub Jelen |
8c9e97 |
} ssh_gssapi_mech;
|
|
Jakub Jelen |
8c9e97 |
|
|
Jakub Jelen |
8c9e97 |
@@ -163,7 +163,7 @@ char* ssh_gssapi_get_displayname(void);
|
|
Jakub Jelen |
8c9e97 |
OM_uint32 ssh_gssapi_checkmic(Gssctxt *, gss_buffer_t, gss_buffer_t);
|
|
Jakub Jelen |
8c9e97 |
void ssh_gssapi_do_child(char ***, u_int *);
|
|
Jakub Jelen |
8c9e97 |
void ssh_gssapi_cleanup_creds(void);
|
|
Jakub Jelen |
8c9e97 |
-void ssh_gssapi_storecreds(void);
|
|
Jakub Jelen |
8c9e97 |
+int ssh_gssapi_storecreds(void);
|
|
Jakub Jelen |
5b55d0 |
const char *ssh_gssapi_displayname(void);
|
|
Jakub Jelen |
8c9e97 |
|
|
Jakub Jelen |
8c9e97 |
char *ssh_gssapi_server_mechanisms(void);
|
|
Jakub Jelen |
8c9e97 |
diff --git a/sshd.c b/sshd.c
|
|
Jakub Jelen |
8c9e97 |
index ce2e374..3c4e13e 100644
|
|
Jakub Jelen |
8c9e97 |
--- a/sshd.c
|
|
Jakub Jelen |
8c9e97 |
+++ b/sshd.c
|
|
Jakub Jelen |
8c9e97 |
@@ -2221,7 +2221,7 @@ main(int ac, char **av)
|
|
Jakub Jelen |
8c9e97 |
#ifdef GSSAPI
|
|
Jakub Jelen |
8c9e97 |
if (options.gss_authentication) {
|
|
Jakub Jelen |
8c9e97 |
temporarily_use_uid(authctxt->pw);
|
|
Jakub Jelen |
8c9e97 |
- ssh_gssapi_storecreds();
|
|
Jakub Jelen |
8c9e97 |
+ authctxt->krb5_set_env = ssh_gssapi_storecreds();
|
|
Jakub Jelen |
8c9e97 |
restore_uid();
|
|
Jakub Jelen |
8c9e97 |
}
|
|
Jakub Jelen |
8c9e97 |
#endif
|
|
Jakub Jelen |
8c9e97 |
|