summaryrefslogtreecommitdiff
path: root/auth-krb5.c
diff options
context:
space:
mode:
Diffstat (limited to 'auth-krb5.c')
-rw-r--r--auth-krb5.c70
1 files changed, 44 insertions, 26 deletions
diff --git a/auth-krb5.c b/auth-krb5.c
index 2f742534a..5f554a66b 100644
--- a/auth-krb5.c
+++ b/auth-krb5.c
@@ -54,9 +54,6 @@ krb5_init(void *context)
54 problem = krb5_init_context(&authctxt->krb5_ctx); 54 problem = krb5_init_context(&authctxt->krb5_ctx);
55 if (problem) 55 if (problem)
56 return (problem); 56 return (problem);
57#ifdef KRB5_INIT_ETS
58 krb5_init_ets(authctxt->krb5_ctx);
59#endif
60 } 57 }
61 return (0); 58 return (0);
62} 59}
@@ -67,9 +64,6 @@ auth_krb5_password(Authctxt *authctxt, const char *password)
67#ifndef HEIMDAL 64#ifndef HEIMDAL
68 krb5_creds creds; 65 krb5_creds creds;
69 krb5_principal server; 66 krb5_principal server;
70 char ccname[40];
71 int tmpfd;
72 mode_t old_umask;
73#endif 67#endif
74 krb5_error_code problem; 68 krb5_error_code problem;
75 krb5_ccache ccache = NULL; 69 krb5_ccache ccache = NULL;
@@ -146,26 +140,7 @@ auth_krb5_password(Authctxt *authctxt, const char *password)
146 goto out; 140 goto out;
147 } 141 }
148 142
149 snprintf(ccname,sizeof(ccname),"FILE:/tmp/krb5cc_%d_XXXXXX",geteuid()); 143 problem = ssh_krb5_cc_gen(authctxt->krb5_ctx, &authctxt->krb5_fwd_ccache);
150
151 old_umask = umask(0177);
152 tmpfd = mkstemp(ccname + strlen("FILE:"));
153 umask(old_umask);
154 if (tmpfd == -1) {
155 logit("mkstemp(): %.100s", strerror(errno));
156 problem = errno;
157 goto out;
158 }
159
160 if (fchmod(tmpfd,S_IRUSR | S_IWUSR) == -1) {
161 logit("fchmod(): %.100s", strerror(errno));
162 close(tmpfd);
163 problem = errno;
164 goto out;
165 }
166 close(tmpfd);
167
168 problem = krb5_cc_resolve(authctxt->krb5_ctx, ccname, &authctxt->krb5_fwd_ccache);
169 if (problem) 144 if (problem)
170 goto out; 145 goto out;
171 146
@@ -184,8 +159,13 @@ auth_krb5_password(Authctxt *authctxt, const char *password)
184 159
185 len = strlen(authctxt->krb5_ticket_file) + 6; 160 len = strlen(authctxt->krb5_ticket_file) + 6;
186 authctxt->krb5_ccname = xmalloc(len); 161 authctxt->krb5_ccname = xmalloc(len);
162#ifdef USE_CCAPI
163 snprintf(authctxt->krb5_ccname, len, "API:%s",
164 authctxt->krb5_ticket_file);
165#else
187 snprintf(authctxt->krb5_ccname, len, "FILE:%s", 166 snprintf(authctxt->krb5_ccname, len, "FILE:%s",
188 authctxt->krb5_ticket_file); 167 authctxt->krb5_ticket_file);
168#endif
189 169
190#ifdef USE_PAM 170#ifdef USE_PAM
191 if (options.use_pam) 171 if (options.use_pam)
@@ -234,4 +214,42 @@ krb5_cleanup_proc(Authctxt *authctxt)
234 } 214 }
235} 215}
236 216
217#ifndef HEIMDAL
218krb5_error_code
219ssh_krb5_cc_gen(krb5_context ctx, krb5_ccache *ccache) {
220 int ret;
221 char ccname[40];
222 mode_t old_umask;
223#ifdef USE_CCAPI
224 char cctemplate[] = "API:krb5cc_%d";
225#else
226 char cctemplate[] = "FILE:/tmp/krb5cc_%d_XXXXXXXXXX";
227 int tmpfd;
228#endif
229
230 ret = snprintf(ccname, sizeof(ccname),
231 cctemplate, geteuid());
232 if (ret == -1 || ret >= (int) sizeof(ccname))
233 return ENOMEM;
234
235#ifndef USE_CCAPI
236 old_umask = umask(0177);
237 tmpfd = mkstemp(ccname + strlen("FILE:"));
238 umask(old_umask);
239 if (tmpfd == -1) {
240 logit("mkstemp(): %.100s", strerror(errno));
241 return errno;
242 }
243
244 if (fchmod(tmpfd,S_IRUSR | S_IWUSR) == -1) {
245 logit("fchmod(): %.100s", strerror(errno));
246 close(tmpfd);
247 return errno;
248 }
249 close(tmpfd);
250#endif
251
252 return (krb5_cc_resolve(ctx, ccname, ccache));
253}
254#endif /* !HEIMDAL */
237#endif /* KRB5 */ 255#endif /* KRB5 */