|
Lines 18-23
Link Here
|
| 18 |
|
18 |
|
| 19 |
#ifdef KRB5 |
19 |
#ifdef KRB5 |
| 20 |
#include <krb5.h> |
20 |
#include <krb5.h> |
|
|
21 |
#ifndef HEIMDAL |
| 22 |
#define krb5_get_err_text(context,code) error_message(code) |
| 23 |
#endif /* !HEIMDAL */ |
| 21 |
|
24 |
|
| 22 |
extern ServerOptions options; |
25 |
extern ServerOptions options; |
| 23 |
|
26 |
|
|
Lines 70-77
Link Here
|
| 70 |
goto err; |
73 |
goto err; |
| 71 |
|
74 |
|
| 72 |
fd = packet_get_connection_in(); |
75 |
fd = packet_get_connection_in(); |
|
|
76 |
#ifdef HEIMDAL |
| 73 |
problem = krb5_auth_con_setaddrs_from_fd(authctxt->krb5_ctx, |
77 |
problem = krb5_auth_con_setaddrs_from_fd(authctxt->krb5_ctx, |
| 74 |
authctxt->krb5_auth_ctx, &fd); |
78 |
authctxt->krb5_auth_ctx, &fd); |
|
|
79 |
#else |
| 80 |
problem = krb5_auth_con_genaddrs(authctxt->krb5_ctx, |
| 81 |
authctxt->krb5_auth_ctx,fd, |
| 82 |
KRB5_AUTH_CONTEXT_GENERATE_REMOTE_FULL_ADDR | |
| 83 |
KRB5_AUTH_CONTEXT_GENERATE_LOCAL_FULL_ADDR); |
| 84 |
#endif |
| 75 |
if (problem) |
85 |
if (problem) |
| 76 |
goto err; |
86 |
goto err; |
| 77 |
|
87 |
|
|
Lines 85-92
Link Here
|
| 85 |
if (problem) |
95 |
if (problem) |
| 86 |
goto err; |
96 |
goto err; |
| 87 |
|
97 |
|
|
|
98 |
#ifdef HEIMDAL |
| 88 |
problem = krb5_copy_principal(authctxt->krb5_ctx, ticket->client, |
99 |
problem = krb5_copy_principal(authctxt->krb5_ctx, ticket->client, |
| 89 |
&authctxt->krb5_user); |
100 |
&authctxt->krb5_user); |
|
|
101 |
#else |
| 102 |
problem = krb5_copy_principal(authctxt->krb5_ctx, |
| 103 |
ticket->enc_part2->client, |
| 104 |
&authctxt->krb5_user); |
| 105 |
#endif |
| 90 |
if (problem) |
106 |
if (problem) |
| 91 |
goto err; |
107 |
goto err; |
| 92 |
|
108 |
|
|
Lines 137-149
Link Here
|
| 137 |
krb5_error_code problem; |
153 |
krb5_error_code problem; |
| 138 |
krb5_ccache ccache = NULL; |
154 |
krb5_ccache ccache = NULL; |
| 139 |
char *pname; |
155 |
char *pname; |
|
|
156 |
krb5_creds **creds; |
| 140 |
|
157 |
|
| 141 |
if (authctxt->pw == NULL || authctxt->krb5_user == NULL) |
158 |
if (authctxt->pw == NULL || authctxt->krb5_user == NULL) |
| 142 |
return (0); |
159 |
return (0); |
| 143 |
|
160 |
|
| 144 |
temporarily_use_uid(authctxt->pw); |
161 |
temporarily_use_uid(authctxt->pw); |
| 145 |
|
162 |
|
|
|
163 |
#ifdef HEIMDAL |
| 146 |
problem = krb5_cc_gen_new(authctxt->krb5_ctx, &krb5_fcc_ops, &ccache); |
164 |
problem = krb5_cc_gen_new(authctxt->krb5_ctx, &krb5_fcc_ops, &ccache); |
|
|
165 |
#else |
| 166 |
{ |
| 167 |
char ccname[40]; |
| 168 |
int tmpfd; |
| 169 |
|
| 170 |
snprintf(ccname,sizeof(ccname),"FILE:/tmp/krb5cc_%d_XXXXXX",geteuid()); |
| 171 |
|
| 172 |
if ((tmpfd = mkstemp(ccname+strlen("FILE:")))==-1) { |
| 173 |
log("mkstemp(): %.100s", strerror(errno)); |
| 174 |
problem = errno; |
| 175 |
goto fail; |
| 176 |
} |
| 177 |
if (fchmod(tmpfd,S_IRUSR | S_IWUSR) == -1) { |
| 178 |
log("fchmod(): %.100s", strerror(errno)); |
| 179 |
close(tmpfd); |
| 180 |
problem = errno; |
| 181 |
goto fail; |
| 182 |
} |
| 183 |
close(tmpfd); |
| 184 |
problem = krb5_cc_resolve(authctxt->krb5_ctx, ccname, &ccache); |
| 185 |
} |
| 186 |
#endif |
| 147 |
if (problem) |
187 |
if (problem) |
| 148 |
goto fail; |
188 |
goto fail; |
| 149 |
|
189 |
|
|
Lines 152-161
Link Here
|
| 152 |
if (problem) |
192 |
if (problem) |
| 153 |
goto fail; |
193 |
goto fail; |
| 154 |
|
194 |
|
|
|
195 |
#ifdef HEIMDAL |
| 155 |
problem = krb5_rd_cred2(authctxt->krb5_ctx, authctxt->krb5_auth_ctx, |
196 |
problem = krb5_rd_cred2(authctxt->krb5_ctx, authctxt->krb5_auth_ctx, |
| 156 |
ccache, tgt); |
197 |
ccache, tgt); |
| 157 |
if (problem) |
198 |
if (problem) |
| 158 |
goto fail; |
199 |
goto fail; |
|
|
200 |
#else |
| 201 |
problem = krb5_rd_cred(authctxt->krb5_ctx, authctxt->krb5_auth_ctx, |
| 202 |
tgt, &creds, NULL); |
| 203 |
if (problem) |
| 204 |
goto fail; |
| 205 |
problem = krb5_cc_store_cred(authctxt->krb5_ctx, ccache, *creds); |
| 206 |
if (problem) |
| 207 |
goto fail; |
| 208 |
#endif |
| 159 |
|
209 |
|
| 160 |
authctxt->krb5_fwd_ccache = ccache; |
210 |
authctxt->krb5_fwd_ccache = ccache; |
| 161 |
ccache = NULL; |
211 |
ccache = NULL; |
|
Lines 188-193
Link Here
|
| 188 |
int |
238 |
int |
| 189 |
auth_krb5_password(Authctxt *authctxt, const char *password) |
239 |
auth_krb5_password(Authctxt *authctxt, const char *password) |
| 190 |
{ |
240 |
{ |
|
|
241 |
#ifndef HEIMDAL |
| 242 |
krb5_creds creds; |
| 243 |
krb5_principal server; |
| 244 |
char ccname[40]; |
| 245 |
int tmpfd; |
| 246 |
#endif |
| 191 |
krb5_error_code problem; |
247 |
krb5_error_code problem; |
| 192 |
|
248 |
|
| 193 |
if (authctxt->pw == NULL) |
249 |
if (authctxt->pw == NULL) |
|
Lines 204-209
Link Here
|
| 204 |
if (problem) |
260 |
if (problem) |
| 205 |
goto out; |
261 |
goto out; |
| 206 |
|
262 |
|
|
|
263 |
#ifdef HEIMDAL |
| 207 |
problem = krb5_cc_gen_new(authctxt->krb5_ctx, &krb5_mcc_ops, |
264 |
problem = krb5_cc_gen_new(authctxt->krb5_ctx, &krb5_mcc_ops, |
| 208 |
&authctxt->krb5_fwd_ccache); |
265 |
&authctxt->krb5_fwd_ccache); |
| 209 |
if (problem) |
266 |
if (problem) |
|
Lines 222-234
Link Here
|
| 222 |
if (problem) |
279 |
if (problem) |
| 223 |
goto out; |
280 |
goto out; |
| 224 |
|
281 |
|
|
|
282 |
#else |
| 283 |
problem = krb5_get_init_creds_password(authctxt->krb5_ctx, &creds, |
| 284 |
authctxt->krb5_user, (char *)password, NULL, NULL, 0, NULL, NULL); |
| 285 |
if (problem) |
| 286 |
goto out; |
| 287 |
|
| 288 |
problem = krb5_sname_to_principal(authctxt->krb5_ctx, NULL, NULL, |
| 289 |
KRB5_NT_SRV_HST, &server); |
| 290 |
if (problem) |
| 291 |
goto out; |
| 292 |
|
| 293 |
restore_uid(); |
| 294 |
problem = krb5_verify_init_creds(authctxt->krb5_ctx, &creds, server, |
| 295 |
NULL, NULL, NULL); |
| 296 |
krb5_free_principal(authctxt->krb5_ctx, server); |
| 297 |
temporarily_use_uid(authctxt->pw); |
| 298 |
if (problem) |
| 299 |
goto out; |
| 300 |
|
| 301 |
if (!krb5_kuserok(authctxt->krb5_ctx, authctxt->krb5_user, |
| 302 |
authctxt->pw->pw_name)) { |
| 303 |
problem = -1; |
| 304 |
goto out; |
| 305 |
} |
| 306 |
|
| 307 |
snprintf(ccname,sizeof(ccname),"FILE:/tmp/krb5cc_%d_XXXXXX",geteuid()); |
| 308 |
|
| 309 |
if ((tmpfd = mkstemp(ccname+strlen("FILE:")))==-1) { |
| 310 |
log("mkstemp(): %.100s", strerror(errno)); |
| 311 |
problem = errno; |
| 312 |
goto out; |
| 313 |
} |
| 314 |
|
| 315 |
if (fchmod(tmpfd,S_IRUSR | S_IWUSR) == -1) { |
| 316 |
log("fchmod(): %.100s", strerror(errno)); |
| 317 |
close(tmpfd); |
| 318 |
problem = errno; |
| 319 |
goto out; |
| 320 |
} |
| 321 |
close(tmpfd); |
| 322 |
|
| 323 |
problem = krb5_cc_resolve(authctxt->krb5_ctx, ccname, &authctxt->krb5_fwd_ccache); |
| 324 |
if (problem) |
| 325 |
goto out; |
| 326 |
|
| 327 |
problem = krb5_cc_initialize(authctxt->krb5_ctx, authctxt->krb5_fwd_ccache, |
| 328 |
authctxt->krb5_user); |
| 329 |
if (problem) |
| 330 |
goto out; |
| 331 |
|
| 332 |
problem= krb5_cc_store_cred(authctxt->krb5_ctx, authctxt->krb5_fwd_ccache, |
| 333 |
&creds); |
| 334 |
if (problem) |
| 335 |
goto out; |
| 336 |
#endif |
| 337 |
|
| 225 |
authctxt->krb5_ticket_file = (char *)krb5_cc_get_name(authctxt->krb5_ctx, authctxt->krb5_fwd_ccache); |
338 |
authctxt->krb5_ticket_file = (char *)krb5_cc_get_name(authctxt->krb5_ctx, authctxt->krb5_fwd_ccache); |
| 226 |
|
339 |
|
| 227 |
out: |
340 |
out: |
| 228 |
restore_uid(); |
341 |
restore_uid(); |
| 229 |
|
342 |
|
| 230 |
if (problem) { |
343 |
if (problem) { |
| 231 |
if (authctxt->krb5_ctx != NULL) |
344 |
if (authctxt->krb5_ctx != NULL && problem!=-1) |
| 232 |
debug("Kerberos password authentication failed: %s", |
345 |
debug("Kerberos password authentication failed: %s", |
| 233 |
krb5_get_err_text(authctxt->krb5_ctx, problem)); |
346 |
krb5_get_err_text(authctxt->krb5_ctx, problem)); |
| 234 |
else |
347 |
else |