|
Lines 42-47
Link Here
|
| 42 |
#ifdef KRB5 |
42 |
#ifdef KRB5 |
| 43 |
#include <krb5.h> |
43 |
#include <krb5.h> |
| 44 |
|
44 |
|
|
|
45 |
#ifdef HEIMDAL |
| 46 |
#define KRB5KDC_ERR_KEY_EXP KRB5KDC_ERR_KEY_EXPIRED |
| 47 |
#endif |
| 48 |
|
| 45 |
extern ServerOptions options; |
49 |
extern ServerOptions options; |
| 46 |
|
50 |
|
| 47 |
static int |
51 |
static int |
|
Lines 59-64
Link Here
|
| 59 |
return (0); |
63 |
return (0); |
| 60 |
} |
64 |
} |
| 61 |
|
65 |
|
|
|
66 |
static int |
| 67 |
try_get_cpw_ticket(Authctxt *authctxt, const char *password) |
| 68 |
{ |
| 69 |
char *realm; |
| 70 |
size_t cpwprinclen; |
| 71 |
char *cpwprinc; |
| 72 |
krb5_error_code problem; |
| 73 |
krb5_creds creds; |
| 74 |
memset(&creds, 0, sizeof(creds)); |
| 75 |
problem = krb5_get_default_realm(authctxt->krb5_ctx, &realm); |
| 76 |
if (problem) |
| 77 |
return (problem); |
| 78 |
cpwprinclen = strlen("kadmin/changepw") + 1 + strlen(realm) + 1; |
| 79 |
cpwprinc = (char *)xmalloc(cpwprinclen); |
| 80 |
strlcpy(cpwprinc, "kadmin/changepw", cpwprinclen); |
| 81 |
strlcat(cpwprinc, "@", cpwprinclen); |
| 82 |
strlcat(cpwprinc, realm, cpwprinclen); |
| 83 |
problem = krb5_get_init_creds_password(authctxt->krb5_ctx, &creds, |
| 84 |
authctxt->krb5_user, |
| 85 |
(char *)password, |
| 86 |
NULL, NULL, 0, cpwprinc, NULL); |
| 87 |
free(cpwprinc); |
| 88 |
free(realm); |
| 89 |
if (problem) { |
| 90 |
return (problem); |
| 91 |
} |
| 92 |
krb5_free_cred_contents(authctxt->krb5_ctx, &creds); |
| 93 |
disable_forwarding(); |
| 94 |
authctxt->force_pwchange = 1; |
| 95 |
authctxt->krb5_force_pwchange = 1; |
| 96 |
return (0); |
| 97 |
} |
| 98 |
|
| 62 |
int |
99 |
int |
| 63 |
auth_krb5_password(Authctxt *authctxt, const char *password) |
100 |
auth_krb5_password(Authctxt *authctxt, const char *password) |
| 64 |
{ |
101 |
{ |
|
Lines 102-107
Link Here
|
| 102 |
|
139 |
|
| 103 |
temporarily_use_uid(authctxt->pw); |
140 |
temporarily_use_uid(authctxt->pw); |
| 104 |
|
141 |
|
|
|
142 |
#ifdef _PATH_KPASSWD_PROG |
| 143 |
if (problem == KRB5KDC_ERR_KEY_EXP) { |
| 144 |
} |
| 145 |
else { |
| 146 |
krb5_creds creds; |
| 147 |
int kret = krb5_get_init_creds_password(authctxt->krb5_ctx, |
| 148 |
&creds, |
| 149 |
authctxt->krb5_user, |
| 150 |
(char *)password, |
| 151 |
NULL, NULL, 0, |
| 152 |
NULL, NULL); |
| 153 |
if (!kret) { /* ?!?!!? */ |
| 154 |
krb5_free_cred_contents(authctxt->krb5_ctx, &creds); |
| 155 |
goto not_expired; |
| 156 |
} |
| 157 |
else if (kret != KRB5KDC_ERR_KEY_EXP) |
| 158 |
goto not_expired; |
| 159 |
} |
| 160 |
|
| 161 |
problem = try_get_cpw_ticket(authctxt, password); |
| 162 |
/* if that worked, flag for special handling below */ |
| 163 |
if (!problem) |
| 164 |
problem = KRB5KDC_ERR_KEY_EXP; |
| 165 |
|
| 166 |
not_expired: |
| 167 |
#endif /* _PATH_KPASSWD_PROG */ |
| 168 |
|
| 105 |
if (problem) |
169 |
if (problem) |
| 106 |
goto out; |
170 |
goto out; |
| 107 |
|
171 |
|
|
Lines 120-125
Link Here
|
| 120 |
#else |
184 |
#else |
| 121 |
problem = krb5_get_init_creds_password(authctxt->krb5_ctx, &creds, |
185 |
problem = krb5_get_init_creds_password(authctxt->krb5_ctx, &creds, |
| 122 |
authctxt->krb5_user, (char *)password, NULL, NULL, 0, NULL, NULL); |
186 |
authctxt->krb5_user, (char *)password, NULL, NULL, 0, NULL, NULL); |
|
|
187 |
#ifdef _PATH_KPASSWD_PROG |
| 188 |
if (problem == KRB5KDC_ERR_KEY_EXP) { |
| 189 |
problem = try_get_cpw_ticket(authctxt, password); |
| 190 |
/* if that worked, flag for special handling below */ |
| 191 |
if (!problem) |
| 192 |
problem = KRB5KDC_ERR_KEY_EXP; |
| 193 |
} |
| 194 |
#endif /* _PATH_KPASSWD_PROG */ |
| 123 |
if (problem) |
195 |
if (problem) |
| 124 |
goto out; |
196 |
goto out; |
| 125 |
|
197 |
|
|
Lines 191-197
Link Here
|
| 191 |
|
263 |
|
| 192 |
krb5_cleanup_proc(authctxt); |
264 |
krb5_cleanup_proc(authctxt); |
| 193 |
|
265 |
|
|
|
266 |
if (problem == KRB5KDC_ERR_KEY_EXP) |
| 267 |
/* return with authctxt->force_pwchange set, so we |
| 268 |
* drop straight into kpasswd */ |
| 269 |
return (1); |
| 194 |
if (options.kerberos_or_local_passwd) |
270 |
if (options.kerberos_or_local_passwd) |
|
|
271 |
|
| 195 |
return (-1); |
272 |
return (-1); |
| 196 |
else |
273 |
else |
| 197 |
return (0); |
274 |
return (0); |