Expand PMF_FN_* macros.
[netbsd-mini2440.git] / crypto / dist / heimdal / lib / 45 / mk_req.c
blob04475bc3902782b21b9875a91ad1794645f90931
1 /*
2 * Copyright (c) 1997 - 2000, 2002 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
34 /* implementation of krb_mk_req that uses 524 protocol */
36 #include "45_locl.h"
38 __RCSID("$Heimdal: mk_req.c 17445 2006-05-05 10:37:46Z lha $"
39 "$NetBSD$");
41 static int lifetime = 255;
43 static void
44 build_request(KTEXT req,
45 const char *name, const char *inst, const char *realm,
46 uint32_t checksum)
48 struct timeval tv;
49 krb5_storage *sp;
50 krb5_data data;
51 sp = krb5_storage_emem();
52 krb5_store_stringz(sp, name);
53 krb5_store_stringz(sp, inst);
54 krb5_store_stringz(sp, realm);
55 krb5_store_int32(sp, checksum);
56 gettimeofday(&tv, NULL);
57 krb5_store_int8(sp, tv.tv_usec / 5000);
58 krb5_store_int32(sp, tv.tv_sec);
59 krb5_storage_to_data(sp, &data);
60 krb5_storage_free(sp);
61 memcpy(req->dat, data.data, data.length);
62 req->length = (data.length + 7) & ~7;
63 krb5_data_free(&data);
66 #ifdef KRB_MK_REQ_CONST
67 int
68 krb_mk_req(KTEXT authent,
69 const char *service, const char *instance, const char *realm,
70 int32_t checksum)
71 #else
72 int
73 krb_mk_req(KTEXT authent,
74 char *service, char *instance, char *realm,
75 int32_t checksum)
77 #endif
79 CREDENTIALS cr;
80 KTEXT_ST req;
81 krb5_storage *sp;
82 int code;
83 /* XXX get user realm */
84 const char *myrealm = realm;
85 krb5_data a;
87 code = krb_get_cred(service, instance, realm, &cr);
88 if(code || time(NULL) > krb_life_to_time(cr.issue_date, cr.lifetime)){
89 code = get_ad_tkt((char *)service,
90 (char *)instance, (char *)realm, lifetime);
91 if(code == KSUCCESS)
92 code = krb_get_cred(service, instance, realm, &cr);
95 if(code)
96 return code;
98 sp = krb5_storage_emem();
100 krb5_store_int8(sp, KRB_PROT_VERSION);
101 krb5_store_int8(sp, AUTH_MSG_APPL_REQUEST);
103 krb5_store_int8(sp, cr.kvno);
104 krb5_store_stringz(sp, realm);
105 krb5_store_int8(sp, cr.ticket_st.length);
107 build_request(&req, cr.pname, cr.pinst, myrealm, checksum);
108 encrypt_ktext(&req, &cr.session, DES_ENCRYPT);
110 krb5_store_int8(sp, req.length);
112 krb5_storage_write(sp, cr.ticket_st.dat, cr.ticket_st.length);
113 krb5_storage_write(sp, req.dat, req.length);
114 krb5_storage_to_data(sp, &a);
115 krb5_storage_free(sp);
116 memcpy(authent->dat, a.data, a.length);
117 authent->length = a.length;
118 krb5_data_free(&a);
120 memset(&cr, 0, sizeof(cr));
121 memset(&req, 0, sizeof(req));
123 return KSUCCESS;
127 * krb_set_lifetime sets the default lifetime for additional tickets
128 * obtained via krb_mk_req().
130 * It returns the previous value of the default lifetime.
134 krb_set_lifetime(int newval)
136 int olife = lifetime;
138 lifetime = newval;
139 return(olife);