2 * Copyright (c) 1997 - 2000, 2002 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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
34 /* implementation of krb_mk_req that uses 524 protocol */
38 __RCSID("$Heimdal: mk_req.c 17445 2006-05-05 10:37:46Z lha $"
41 static int lifetime
= 255;
44 build_request(KTEXT req
,
45 const char *name
, const char *inst
, const char *realm
,
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
68 krb_mk_req(KTEXT authent
,
69 const char *service
, const char *instance
, const char *realm
,
73 krb_mk_req(KTEXT authent
,
74 char *service
, char *instance
, char *realm
,
83 /* XXX get user realm */
84 const char *myrealm
= realm
;
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
);
92 code
= krb_get_cred(service
, instance
, realm
, &cr
);
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
;
120 memset(&cr
, 0, sizeof(cr
));
121 memset(&req
, 0, sizeof(req
));
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
;