version 1.23.2.3, 2002/06/02 22:56:09 |
version 1.24, 2001/06/26 16:15:22 |
|
|
const char *tkt_root = TKT_ROOT; |
const char *tkt_root = TKT_ROOT; |
struct stat st; |
struct stat st; |
int fd; |
int fd; |
|
|
if (!authctxt->krb4_ticket_file) { |
if (!authctxt->krb4_ticket_file) { |
/* Set unique ticket string manually since we're still root. */ |
/* Set unique ticket string manually since we're still root. */ |
authctxt->krb4_ticket_file = xmalloc(MAXPATHLEN); |
authctxt->krb4_ticket_file = xmalloc(MAXPATHLEN); |
|
|
} |
} |
/* Failure - cancel cleanup function, leaving ticket for inspection. */ |
/* Failure - cancel cleanup function, leaving ticket for inspection. */ |
log("WARNING: bad ticket file %s", authctxt->krb4_ticket_file); |
log("WARNING: bad ticket file %s", authctxt->krb4_ticket_file); |
|
|
fatal_remove_cleanup(krb4_cleanup_proc, authctxt); |
fatal_remove_cleanup(krb4_cleanup_proc, authctxt); |
cleanup_registered = 0; |
cleanup_registered = 0; |
|
|
xfree(authctxt->krb4_ticket_file); |
xfree(authctxt->krb4_ticket_file); |
authctxt->krb4_ticket_file = NULL; |
authctxt->krb4_ticket_file = NULL; |
|
|
return (0); |
return (0); |
} |
} |
|
|
|
|
char localhost[MAXHOSTNAMELEN], phost[INST_SZ], realm[REALM_SZ]; |
char localhost[MAXHOSTNAMELEN], phost[INST_SZ], realm[REALM_SZ]; |
u_int32_t faddr; |
u_int32_t faddr; |
int r; |
int r; |
|
|
if ((pw = authctxt->pw) == NULL) |
if ((pw = authctxt->pw) == NULL) |
return (0); |
return (0); |
|
|
/* |
/* |
* Try Kerberos password authentication only for non-root |
* Try Kerberos password authentication only for non-root |
* users and only if Kerberos is installed. |
* users and only if Kerberos is installed. |
|
|
} |
} |
/* Successful authentication. */ |
/* Successful authentication. */ |
chown(tkt_string(), pw->pw_uid, pw->pw_gid); |
chown(tkt_string(), pw->pw_uid, pw->pw_gid); |
|
|
/* |
/* |
* Now that we have a TGT, try to get a local |
* Now that we have a TGT, try to get a local |
* "rcmd" ticket to ensure that we are not talking |
* "rcmd" ticket to ensure that we are not talking |
|
|
strlcpy(phost, (char *)krb_get_phost(localhost), |
strlcpy(phost, (char *)krb_get_phost(localhost), |
sizeof(phost)); |
sizeof(phost)); |
r = krb_mk_req(&tkt, KRB4_SERVICE_NAME, phost, realm, 33); |
r = krb_mk_req(&tkt, KRB4_SERVICE_NAME, phost, realm, 33); |
|
|
if (r == KSUCCESS) { |
if (r == KSUCCESS) { |
if ((hp = gethostbyname(localhost)) == NULL) { |
if ((hp = gethostbyname(localhost)) == NULL) { |
log("Couldn't get local host address!"); |
log("Couldn't get local host address!"); |
|
|
} |
} |
memmove((void *)&faddr, (void *)hp->h_addr, |
memmove((void *)&faddr, (void *)hp->h_addr, |
sizeof(faddr)); |
sizeof(faddr)); |
|
|
/* Verify our "rcmd" ticket. */ |
/* Verify our "rcmd" ticket. */ |
r = krb_rd_req(&tkt, KRB4_SERVICE_NAME, phost, |
r = krb_rd_req(&tkt, KRB4_SERVICE_NAME, phost, |
faddr, &adata, ""); |
faddr, &adata, ""); |
|
|
} else |
} else |
/* Logging in as root or no local Kerberos realm. */ |
/* Logging in as root or no local Kerberos realm. */ |
debug("Unable to authenticate to Kerberos."); |
debug("Unable to authenticate to Kerberos."); |
|
|
failure: |
failure: |
krb4_cleanup_proc(authctxt); |
krb4_cleanup_proc(authctxt); |
|
|
if (!options.kerberos_or_local_passwd) |
if (!options.kerberos_or_local_passwd) |
return (0); |
return (0); |
|
|
/* Fall back to ordinary passwd authentication. */ |
/* Fall back to ordinary passwd authentication. */ |
return (-1); |
return (-1); |
} |
} |
|
|
socklen_t slen; |
socklen_t slen; |
u_int cksum; |
u_int cksum; |
int r, s; |
int r, s; |
|
|
s = packet_get_connection_in(); |
s = packet_get_connection_in(); |
|
|
slen = sizeof(local); |
slen = sizeof(local); |
memset(&local, 0, sizeof(local)); |
memset(&local, 0, sizeof(local)); |
if (getsockname(s, (struct sockaddr *) & local, &slen) < 0) |
if (getsockname(s, (struct sockaddr *) & local, &slen) < 0) |
|
|
} |
} |
instance[0] = '*'; |
instance[0] = '*'; |
instance[1] = 0; |
instance[1] = 0; |
|
|
/* Get the encrypted request, challenge, and session key. */ |
/* Get the encrypted request, challenge, and session key. */ |
if ((r = krb_rd_req(auth, KRB4_SERVICE_NAME, instance, |
if ((r = krb_rd_req(auth, KRB4_SERVICE_NAME, instance, |
0, &adat, ""))) { |
0, &adat, ""))) { |
|
|
return (0); |
return (0); |
} |
} |
des_key_sched((des_cblock *) adat.session, schedule); |
des_key_sched((des_cblock *) adat.session, schedule); |
|
|
*client = xmalloc(MAX_K_NAME_SZ); |
*client = xmalloc(MAX_K_NAME_SZ); |
(void) snprintf(*client, MAX_K_NAME_SZ, "%s%s%s@%s", adat.pname, |
(void) snprintf(*client, MAX_K_NAME_SZ, "%s%s%s@%s", adat.pname, |
*adat.pinst ? "." : "", adat.pinst, adat.prealm); |
*adat.pinst ? "." : "", adat.pinst, adat.prealm); |
|
|
/* Check ~/.klogin authorization now. */ |
/* Check ~/.klogin authorization now. */ |
if (kuserok(&adat, authctxt->user) != KSUCCESS) { |
if (kuserok(&adat, authctxt->user) != KSUCCESS) { |
log("Kerberos v4 .klogin authorization failed for %s to " |
log("Kerberos v4 .klogin authorization failed for %s to " |
"account %s", *client, authctxt->user); |
"account %s", *client, authctxt->user); |
xfree(*client); |
xfree(*client); |
*client = NULL; |
|
return (0); |
return (0); |
} |
} |
/* Increment the checksum, and return it encrypted with the |
/* Increment the checksum, and return it encrypted with the |
session key. */ |
session key. */ |
cksum = adat.checksum + 1; |
cksum = adat.checksum + 1; |
cksum = htonl(cksum); |
cksum = htonl(cksum); |
|
|
/* If we can't successfully encrypt the checksum, we send back an |
/* If we can't successfully encrypt the checksum, we send back an |
empty message, admitting our failure. */ |
empty message, admitting our failure. */ |
if ((r = krb_mk_priv((u_char *) & cksum, reply.dat, sizeof(cksum) + 1, |
if ((r = krb_mk_priv((u_char *) & cksum, reply.dat, sizeof(cksum) + 1, |
|
|
reply.length = 0; |
reply.length = 0; |
} else |
} else |
reply.length = r; |
reply.length = r; |
|
|
/* Clear session key. */ |
/* Clear session key. */ |
memset(&adat.session, 0, sizeof(&adat.session)); |
memset(&adat.session, 0, sizeof(&adat.session)); |
|
|
packet_start(SSH_SMSG_AUTH_KERBEROS_RESPONSE); |
packet_start(SSH_SMSG_AUTH_KERBEROS_RESPONSE); |
packet_put_string((char *) reply.dat, reply.length); |
packet_put_string((char *) reply.dat, reply.length); |
packet_send(); |
packet_send(); |
|
|
{ |
{ |
CREDENTIALS creds; |
CREDENTIALS creds; |
struct passwd *pw; |
struct passwd *pw; |
|
|
if ((pw = authctxt->pw) == NULL) |
if ((pw = authctxt->pw) == NULL) |
goto failure; |
goto failure; |
|
|
temporarily_use_uid(pw); |
temporarily_use_uid(pw); |
|
|
if (!radix_to_creds(string, &creds)) { |
if (!radix_to_creds(string, &creds)) { |
log("Protocol error decoding Kerberos v4 TGT"); |
log("Protocol error decoding Kerberos v4 TGT"); |
goto failure; |
goto failure; |
} |
} |
if (strncmp(creds.service, "", 1) == 0) /* backward compatibility */ |
if (strncmp(creds.service, "", 1) == 0) /* backward compatibility */ |
strlcpy(creds.service, "krbtgt", sizeof creds.service); |
strlcpy(creds.service, "krbtgt", sizeof creds.service); |
|
|
if (strcmp(creds.service, "krbtgt")) { |
if (strcmp(creds.service, "krbtgt")) { |
log("Kerberos v4 TGT (%s%s%s@%s) rejected for %s", |
log("Kerberos v4 TGT (%s%s%s@%s) rejected for %s", |
creds.pname, creds.pinst[0] ? "." : "", creds.pinst, |
creds.pname, creds.pinst[0] ? "." : "", creds.pinst, |
|
|
} |
} |
if (!krb4_init(authctxt)) |
if (!krb4_init(authctxt)) |
goto failure; |
goto failure; |
|
|
if (in_tkt(creds.pname, creds.pinst) != KSUCCESS) |
if (in_tkt(creds.pname, creds.pinst) != KSUCCESS) |
goto failure; |
goto failure; |
|
|
if (save_credentials(creds.service, creds.instance, creds.realm, |
if (save_credentials(creds.service, creds.instance, creds.realm, |
creds.session, creds.lifetime, creds.kvno, &creds.ticket_st, |
creds.session, creds.lifetime, creds.kvno, &creds.ticket_st, |
creds.issue_date) != KSUCCESS) { |
creds.issue_date) != KSUCCESS) { |
|
|
} |
} |
/* Successful authentication, passed all checks. */ |
/* Successful authentication, passed all checks. */ |
chown(tkt_string(), pw->pw_uid, pw->pw_gid); |
chown(tkt_string(), pw->pw_uid, pw->pw_gid); |
|
|
debug("Kerberos v4 TGT accepted (%s%s%s@%s)", |
debug("Kerberos v4 TGT accepted (%s%s%s@%s)", |
creds.pname, creds.pinst[0] ? "." : "", creds.pinst, creds.realm); |
creds.pname, creds.pinst[0] ? "." : "", creds.pinst, creds.realm); |
memset(&creds, 0, sizeof(creds)); |
memset(&creds, 0, sizeof(creds)); |
|
|
restore_uid(); |
restore_uid(); |
|
|
return (1); |
return (1); |
|
|
failure: |
failure: |
krb4_cleanup_proc(authctxt); |
krb4_cleanup_proc(authctxt); |
memset(&creds, 0, sizeof(creds)); |
memset(&creds, 0, sizeof(creds)); |
restore_uid(); |
restore_uid(); |
|
|
return (0); |
return (0); |
} |
} |
|
|
|
|
CREDENTIALS creds; |
CREDENTIALS creds; |
struct passwd *pw; |
struct passwd *pw; |
uid_t uid; |
uid_t uid; |
|
|
if ((pw = authctxt->pw) == NULL) |
if ((pw = authctxt->pw) == NULL) |
return (0); |
return (0); |
|
|
if (!radix_to_creds(token_string, &creds)) { |
if (!radix_to_creds(token_string, &creds)) { |
log("Protocol error decoding AFS token"); |
log("Protocol error decoding AFS token"); |
return (0); |
return (0); |
} |
} |
if (strncmp(creds.service, "", 1) == 0) /* backward compatibility */ |
if (strncmp(creds.service, "", 1) == 0) /* backward compatibility */ |
strlcpy(creds.service, "afs", sizeof creds.service); |
strlcpy(creds.service, "afs", sizeof creds.service); |
|
|
if (strncmp(creds.pname, "AFS ID ", 7) == 0) |
if (strncmp(creds.pname, "AFS ID ", 7) == 0) |
uid = atoi(creds.pname + 7); |
uid = atoi(creds.pname + 7); |
else |
else |
uid = pw->pw_uid; |
uid = pw->pw_uid; |
|
|
if (kafs_settoken(creds.realm, uid, &creds)) { |
if (kafs_settoken(creds.realm, uid, &creds)) { |
log("AFS token (%s@%s) rejected for %s", |
log("AFS token (%s@%s) rejected for %s", |
creds.pname, creds.realm, pw->pw_name); |
creds.pname, creds.realm, pw->pw_name); |
|
|
} |
} |
debug("AFS token accepted (%s@%s)", creds.pname, creds.realm); |
debug("AFS token accepted (%s@%s)", creds.pname, creds.realm); |
memset(&creds, 0, sizeof(creds)); |
memset(&creds, 0, sizeof(creds)); |
|
|
return (1); |
return (1); |
} |
} |
#endif /* AFS */ |
#endif /* AFS */ |