summaryrefslogtreecommitdiffstats
path: root/src/lib/krb5/krb/rd_req_sim.c
blob: 6336343a1fbcbfa3c6765bc7fd24bf15223a9f39 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
 * $Source$
 * $Author$
 *
 * Copyright 1990 by the Massachusetts Institute of Technology.
 *
 * For copying and distribution information, please see the file
 * <krb5/mit-copyright.h>.
 *
 * krb5_rd_req_simple()
 */

#if !defined(lint) && !defined(SABER)
static char rd_req_sim_c[] =
"$Id$";
#endif	/* !lint & !SABER */

#include <krb5/copyright.h>
#include <krb5/krb5.h>
#include <krb5/asn1.h>
#include <krb5/ext-proto.h>

/*
 Parses a KRB_AP_REQ message, returning its contents.

 server specifies the expected server's name for the ticket.

 sender_addr specifies the address(es) expected to be present in the
 ticket.

 A replay cache name derived from the first component of the service name
 is used.

 The default key store is consulted to find the service key.

 authdat->ticket and authdat->authenticator are set to allocated storage
 structures; the caller should free them when finished.

 returns system errors, encryption errors, replay errors
 */

krb5_error_code
krb5_rd_req_simple(inbuf, server, sender_addr, authdat)
const krb5_data *inbuf;
const krb5_principal server;
const krb5_address *sender_addr;
krb5_tkt_authent *authdat;
{
    krb5_error_code retval;
    krb5_ap_req *request;
    krb5_rcache rcache;

    if (!krb5_is_ap_req(inbuf))
	return KRB5KRB_AP_ERR_MSG_TYPE;
    if (retval = decode_krb5_ap_req(inbuf, &request)) {
    	switch (retval) {
	case ISODE_50_LOCAL_ERR_BADMSGTYPE:
	    return KRB5KRB_AP_ERR_BADVERSION; /* XXX ? */
	default:
	    return(retval);
	}
    }
    if (rcache = (krb5_rcache) malloc(sizeof(*rcache))) {
	if (!(retval = krb5_rc_resolve_type(&rcache, "dfl"))) {
	    char *cachename;
	    extern krb5_deltat krb5_clockskew;

	    if (cachename = malloc(server[1]->length+1+3)) {
		strcpy(cachename, "rc_");
		strncat(cachename, server[1]->data, server[1]->length);
		cachename[server[1]->length+3] = '\0';

		if (!(retval = krb5_rc_resolve(rcache, cachename))) {
		    if (!((retval = krb5_rc_recover(rcache)) &&
			  (retval = krb5_rc_initialize(rcache,
						       krb5_clockskew)))) {
			retval = krb5_rd_req_decoded(request, server,
						     sender_addr, 0,
						     0, 0, rcache, authdat);
			krb5_rc_close(rcache);
		    }
		}
		free(cachename);
	    } else
		retval = ENOMEM;
	}
	xfree(rcache);
    } else
	retval = ENOMEM;
    krb5_free_ap_req(request);

    return retval;
}