2 * Copyright (c) 2006 - 2007 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 #include "krb5_locl.h"
39 struct PAC_INFO_BUFFER
{
49 struct PAC_INFO_BUFFER buffers
[1];
52 struct krb5_pac_data
{
55 struct PAC_INFO_BUFFER
*server_checksum
;
56 struct PAC_INFO_BUFFER
*privsvr_checksum
;
57 struct PAC_INFO_BUFFER
*logon_name
;
60 #define PAC_ALIGNMENT 8
62 #define PACTYPE_SIZE 8
63 #define PAC_INFO_BUFFER_SIZE 16
65 #define PAC_SERVER_CHECKSUM 6
66 #define PAC_PRIVSVR_CHECKSUM 7
67 #define PAC_LOGON_NAME 10
68 #define PAC_CONSTRAINED_DELEGATION 11
70 #define CHECK(r,f,l) \
72 if (((r) = f ) != 0) { \
73 krb5_clear_error_string(context); \
78 static const char zeros
[PAC_ALIGNMENT
] = { 0 };
85 krb5_pac_parse(krb5_context context
, const void *ptr
, size_t len
,
90 krb5_storage
*sp
= NULL
;
91 uint32_t i
, tmp
, tmp2
, header_end
;
93 p
= calloc(1, sizeof(*p
));
96 krb5_set_error_string(context
, "out of memory");
100 sp
= krb5_storage_from_readonly_mem(ptr
, len
);
103 krb5_set_error_string(context
, "out of memory");
106 krb5_storage_set_flags(sp
, KRB5_STORAGE_BYTEORDER_LE
);
108 CHECK(ret
, krb5_ret_uint32(sp
, &tmp
), out
);
109 CHECK(ret
, krb5_ret_uint32(sp
, &tmp2
), out
);
111 krb5_set_error_string(context
, "PAC have too few buffer");
112 ret
= EINVAL
; /* Too few buffers */
116 krb5_set_error_string(context
, "PAC have wrong version");
117 ret
= EINVAL
; /* Wrong version */
122 sizeof(*p
->pac
) + (sizeof(p
->pac
->buffers
[0]) * (tmp
- 1)));
123 if (p
->pac
== NULL
) {
124 krb5_set_error_string(context
, "out of memory");
129 p
->pac
->numbuffers
= tmp
;
130 p
->pac
->version
= tmp2
;
132 header_end
= PACTYPE_SIZE
+ (PAC_INFO_BUFFER_SIZE
* p
->pac
->numbuffers
);
133 if (header_end
> len
) {
138 for (i
= 0; i
< p
->pac
->numbuffers
; i
++) {
139 CHECK(ret
, krb5_ret_uint32(sp
, &p
->pac
->buffers
[i
].type
), out
);
140 CHECK(ret
, krb5_ret_uint32(sp
, &p
->pac
->buffers
[i
].buffersize
), out
);
141 CHECK(ret
, krb5_ret_uint32(sp
, &p
->pac
->buffers
[i
].offset_lo
), out
);
142 CHECK(ret
, krb5_ret_uint32(sp
, &p
->pac
->buffers
[i
].offset_hi
), out
);
144 /* consistency checks */
145 if (p
->pac
->buffers
[i
].offset_lo
& (PAC_ALIGNMENT
- 1)) {
146 krb5_set_error_string(context
, "PAC out of allignment");
150 if (p
->pac
->buffers
[i
].offset_hi
) {
151 krb5_set_error_string(context
, "PAC high offset set");
155 if (p
->pac
->buffers
[i
].offset_lo
> len
) {
156 krb5_set_error_string(context
, "PAC offset off end");
160 if (p
->pac
->buffers
[i
].offset_lo
< header_end
) {
161 krb5_set_error_string(context
, "PAC offset inside header: %d %d",
162 p
->pac
->buffers
[i
].offset_lo
, header_end
);
166 if (p
->pac
->buffers
[i
].buffersize
> len
- p
->pac
->buffers
[i
].offset_lo
){
167 krb5_set_error_string(context
, "PAC length off end");
172 /* let save pointer to data we need later */
173 if (p
->pac
->buffers
[i
].type
== PAC_SERVER_CHECKSUM
) {
174 if (p
->server_checksum
) {
175 krb5_set_error_string(context
, "PAC have two server checksums");
179 p
->server_checksum
= &p
->pac
->buffers
[i
];
180 } else if (p
->pac
->buffers
[i
].type
== PAC_PRIVSVR_CHECKSUM
) {
181 if (p
->privsvr_checksum
) {
182 krb5_set_error_string(context
, "PAC have two KDC checksums");
186 p
->privsvr_checksum
= &p
->pac
->buffers
[i
];
187 } else if (p
->pac
->buffers
[i
].type
== PAC_LOGON_NAME
) {
189 krb5_set_error_string(context
, "PAC have two logon names");
193 p
->logon_name
= &p
->pac
->buffers
[i
];
197 ret
= krb5_data_copy(&p
->data
, ptr
, len
);
201 krb5_storage_free(sp
);
208 krb5_storage_free(sp
);
220 krb5_pac_init(krb5_context context
, krb5_pac
*pac
)
225 p
= calloc(1, sizeof(*p
));
227 krb5_set_error_string(context
, "out of memory");
231 p
->pac
= calloc(1, sizeof(*p
->pac
));
232 if (p
->pac
== NULL
) {
234 krb5_set_error_string(context
, "out of memory");
238 ret
= krb5_data_alloc(&p
->data
, PACTYPE_SIZE
);
242 krb5_set_error_string(context
, "out of memory");
252 krb5_pac_add_buffer(krb5_context context
, krb5_pac p
,
253 uint32_t type
, const krb5_data
*data
)
257 size_t len
, offset
, header_end
, old_end
;
260 len
= p
->pac
->numbuffers
;
262 ptr
= realloc(p
->pac
,
263 sizeof(*p
->pac
) + (sizeof(p
->pac
->buffers
[0]) * len
));
265 krb5_set_error_string(context
, "out of memory");
270 for (i
= 0; i
< len
; i
++)
271 p
->pac
->buffers
[i
].offset_lo
+= PAC_INFO_BUFFER_SIZE
;
273 offset
= p
->data
.length
+ PAC_INFO_BUFFER_SIZE
;
275 p
->pac
->buffers
[len
].type
= type
;
276 p
->pac
->buffers
[len
].buffersize
= data
->length
;
277 p
->pac
->buffers
[len
].offset_lo
= offset
;
278 p
->pac
->buffers
[len
].offset_hi
= 0;
280 old_end
= p
->data
.length
;
281 len
= p
->data
.length
+ data
->length
+ PAC_INFO_BUFFER_SIZE
;
282 if (len
< p
->data
.length
) {
283 krb5_set_error_string(context
, "integer overrun");
287 /* align to PAC_ALIGNMENT */
288 len
= ((len
+ PAC_ALIGNMENT
- 1) / PAC_ALIGNMENT
) * PAC_ALIGNMENT
;
290 ret
= krb5_data_realloc(&p
->data
, len
);
292 krb5_set_error_string(context
, "out of memory");
297 * make place for new PAC INFO BUFFER header
299 header_end
= PACTYPE_SIZE
+ (PAC_INFO_BUFFER_SIZE
* p
->pac
->numbuffers
);
300 memmove((unsigned char *)p
->data
.data
+ header_end
+ PAC_INFO_BUFFER_SIZE
,
301 (unsigned char *)p
->data
.data
+ header_end
,
302 old_end
- header_end
);
303 memset((unsigned char *)p
->data
.data
+ header_end
, 0, PAC_INFO_BUFFER_SIZE
);
306 * copy in new data part
309 memcpy((unsigned char *)p
->data
.data
+ offset
,
310 data
->data
, data
->length
);
311 memset((unsigned char *)p
->data
.data
+ offset
+ data
->length
,
312 0, p
->data
.length
- offset
- data
->length
);
314 p
->pac
->numbuffers
+= 1;
320 krb5_pac_get_buffer(krb5_context context
, krb5_pac p
,
321 uint32_t type
, krb5_data
*data
)
327 * Hide the checksums from external consumers
330 if (type
== PAC_PRIVSVR_CHECKSUM
|| type
== PAC_SERVER_CHECKSUM
) {
331 ret
= krb5_data_alloc(data
, 16);
333 krb5_set_error_string(context
, "out of memory");
336 memset(data
->data
, 0, data
->length
);
340 for (i
= 0; i
< p
->pac
->numbuffers
; i
++) {
341 size_t len
= p
->pac
->buffers
[i
].buffersize
;
342 size_t offset
= p
->pac
->buffers
[i
].offset_lo
;
344 if (p
->pac
->buffers
[i
].type
!= type
)
347 ret
= krb5_data_copy(data
, (unsigned char *)p
->data
.data
+ offset
, len
);
349 krb5_set_error_string(context
, "Out of memory");
354 krb5_set_error_string(context
, "No PAC buffer of type %lu was found",
355 (unsigned long)type
);
364 krb5_pac_get_types(krb5_context context
,
371 *types
= calloc(p
->pac
->numbuffers
, sizeof(*types
));
372 if (*types
== NULL
) {
374 krb5_set_error_string(context
, "out of memory");
377 for (i
= 0; i
< p
->pac
->numbuffers
; i
++)
378 (*types
)[i
] = p
->pac
->buffers
[i
].type
;
379 *len
= p
->pac
->numbuffers
;
389 krb5_pac_free(krb5_context context
, krb5_pac pac
)
391 krb5_data_free(&pac
->data
);
400 static krb5_error_code
401 verify_checksum(krb5_context context
,
402 const struct PAC_INFO_BUFFER
*sig
,
403 const krb5_data
*data
,
404 void *ptr
, size_t len
,
405 const krb5_keyblock
*key
)
407 krb5_crypto crypto
= NULL
;
408 krb5_storage
*sp
= NULL
;
413 memset(&cksum
, 0, sizeof(cksum
));
415 sp
= krb5_storage_from_mem((char *)data
->data
+ sig
->offset_lo
,
418 krb5_set_error_string(context
, "out of memory");
421 krb5_storage_set_flags(sp
, KRB5_STORAGE_BYTEORDER_LE
);
423 CHECK(ret
, krb5_ret_uint32(sp
, &type
), out
);
424 cksum
.cksumtype
= type
;
425 cksum
.checksum
.length
=
426 sig
->buffersize
- krb5_storage_seek(sp
, 0, SEEK_CUR
);
427 cksum
.checksum
.data
= malloc(cksum
.checksum
.length
);
428 if (cksum
.checksum
.data
== NULL
) {
429 krb5_set_error_string(context
, "out of memory");
433 ret
= krb5_storage_read(sp
, cksum
.checksum
.data
, cksum
.checksum
.length
);
434 if (ret
!= cksum
.checksum
.length
) {
435 krb5_set_error_string(context
, "PAC checksum missing checksum");
440 if (!krb5_checksum_is_keyed(context
, cksum
.cksumtype
)) {
441 krb5_set_error_string (context
, "Checksum type %d not keyed",
447 ret
= krb5_crypto_init(context
, key
, 0, &crypto
);
451 ret
= krb5_verify_checksum(context
, crypto
, KRB5_KU_OTHER_CKSUM
,
453 free(cksum
.checksum
.data
);
454 krb5_crypto_destroy(context
, crypto
);
455 krb5_storage_free(sp
);
460 if (cksum
.checksum
.data
)
461 free(cksum
.checksum
.data
);
463 krb5_storage_free(sp
);
465 krb5_crypto_destroy(context
, crypto
);
469 static krb5_error_code
470 create_checksum(krb5_context context
,
471 const krb5_keyblock
*key
,
472 void *data
, size_t datalen
,
473 void *sig
, size_t siglen
)
475 krb5_crypto crypto
= NULL
;
479 ret
= krb5_crypto_init(context
, key
, 0, &crypto
);
483 ret
= krb5_create_checksum(context
, crypto
, KRB5_KU_OTHER_CKSUM
, 0,
484 data
, datalen
, &cksum
);
485 krb5_crypto_destroy(context
, crypto
);
489 if (cksum
.checksum
.length
!= siglen
) {
490 krb5_set_error_string(context
, "pac checksum wrong length");
491 free_Checksum(&cksum
);
495 memcpy(sig
, cksum
.checksum
.data
, siglen
);
496 free_Checksum(&cksum
);
506 #define NTTIME_EPOCH 0x019DB1DED53E8000LL
509 unix2nttime(time_t unix_time
)
512 wt
= unix_time
* (uint64_t)10000000 + (uint64_t)NTTIME_EPOCH
;
516 static krb5_error_code
517 verify_logonname(krb5_context context
,
518 const struct PAC_INFO_BUFFER
*logon_name
,
519 const krb5_data
*data
,
521 krb5_const_principal principal
)
525 uint32_t time1
, time2
;
530 sp
= krb5_storage_from_readonly_mem((const char *)data
->data
+ logon_name
->offset_lo
,
531 logon_name
->buffersize
);
533 krb5_set_error_string(context
, "Out of memory");
537 krb5_storage_set_flags(sp
, KRB5_STORAGE_BYTEORDER_LE
);
539 CHECK(ret
, krb5_ret_uint32(sp
, &time1
), out
);
540 CHECK(ret
, krb5_ret_uint32(sp
, &time2
), out
);
544 t1
= unix2nttime(authtime
);
545 t2
= ((uint64_t)time2
<< 32) | time1
;
547 krb5_storage_free(sp
);
548 krb5_set_error_string(context
, "PAC timestamp mismatch");
552 CHECK(ret
, krb5_ret_uint16(sp
, &len
), out
);
554 krb5_storage_free(sp
);
555 krb5_set_error_string(context
, "PAC logon name length missing");
561 krb5_storage_free(sp
);
562 krb5_set_error_string(context
, "Out of memory");
565 ret
= krb5_storage_read(sp
, s
, len
);
567 krb5_storage_free(sp
);
568 krb5_set_error_string(context
, "Failed to read PAC logon name");
571 krb5_storage_free(sp
);
573 size_t ucs2len
= len
/ 2;
576 unsigned int flags
= WIND_RW_LE
;
578 ucs2
= malloc(sizeof(ucs2
[0]) * ucs2len
);
580 krb5_set_error_string(context
, "malloc: out of memory");
583 ret
= wind_ucs2read(s
, len
, &flags
, ucs2
, &ucs2len
);
587 krb5_set_error_string(context
, "Failed to convert string to UCS-2");
590 ret
= wind_ucs2utf8_length(ucs2
, ucs2len
, &u8len
);
593 krb5_set_error_string(context
, "Failed to count length of UCS-2 string");
596 u8len
+= 1; /* Add space for NUL */
600 krb5_set_error_string(context
, "malloc: out of memory");
603 ret
= wind_ucs2utf8(ucs2
, ucs2len
, s
, &u8len
);
606 krb5_set_error_string(context
, "Failed to convert to UTF-8");
610 ret
= krb5_parse_name_flags(context
, s
, KRB5_PRINCIPAL_PARSE_NO_REALM
, &p2
);
615 if (krb5_principal_compare_any_realm(context
, principal
, p2
) != TRUE
) {
616 krb5_set_error_string(context
, "PAC logon name mismatch");
619 krb5_free_principal(context
, p2
);
629 static krb5_error_code
630 build_logon_name(krb5_context context
,
632 krb5_const_principal principal
,
641 t
= unix2nttime(authtime
);
643 krb5_data_zero(logon
);
645 sp
= krb5_storage_emem();
647 krb5_set_error_string(context
, "out of memory");
650 krb5_storage_set_flags(sp
, KRB5_STORAGE_BYTEORDER_LE
);
652 CHECK(ret
, krb5_store_uint32(sp
, t
& 0xffffffff), out
);
653 CHECK(ret
, krb5_store_uint32(sp
, t
>> 32), out
);
655 ret
= krb5_unparse_name_flags(context
, principal
,
656 KRB5_PRINCIPAL_UNPARSE_NO_REALM
, &s
);
662 CHECK(ret
, krb5_store_uint16(sp
, len
* 2), out
);
664 #if 1 /* cheat for now */
665 s2
= malloc(len
* 2);
671 for (i
= 0; i
< len
; i
++) {
677 /* write libwind code here */
680 ret
= krb5_storage_write(sp
, s2
, len
* 2);
682 if (ret
!= len
* 2) {
686 ret
= krb5_storage_to_data(sp
, logon
);
689 krb5_storage_free(sp
);
693 krb5_storage_free(sp
);
703 krb5_pac_verify(krb5_context context
,
706 krb5_const_principal principal
,
707 const krb5_keyblock
*server
,
708 const krb5_keyblock
*privsvr
)
712 if (pac
->server_checksum
== NULL
) {
713 krb5_set_error_string(context
, "PAC missing server checksum");
716 if (pac
->privsvr_checksum
== NULL
) {
717 krb5_set_error_string(context
, "PAC missing kdc checksum");
720 if (pac
->logon_name
== NULL
) {
721 krb5_set_error_string(context
, "PAC missing logon name");
725 ret
= verify_logonname(context
,
734 * in the service case, clean out data option of the privsvr and
735 * server checksum before checking the checksum.
740 ret
= krb5_copy_data(context
, &pac
->data
, ©
);
744 if (pac
->server_checksum
->buffersize
< 4)
746 if (pac
->privsvr_checksum
->buffersize
< 4)
749 memset((char *)copy
->data
+ pac
->server_checksum
->offset_lo
+ 4,
751 pac
->server_checksum
->buffersize
- 4);
753 memset((char *)copy
->data
+ pac
->privsvr_checksum
->offset_lo
+ 4,
755 pac
->privsvr_checksum
->buffersize
- 4);
757 ret
= verify_checksum(context
,
758 pac
->server_checksum
,
763 krb5_free_data(context
, copy
);
768 ret
= verify_checksum(context
,
769 pac
->privsvr_checksum
,
771 (char *)pac
->data
.data
772 + pac
->server_checksum
->offset_lo
+ 4,
773 pac
->server_checksum
->buffersize
- 4,
786 static krb5_error_code
787 fill_zeros(krb5_context context
, krb5_storage
*sp
, size_t len
)
794 if (l
> sizeof(zeros
))
796 sret
= krb5_storage_write(sp
, zeros
, l
);
798 krb5_set_error_string(context
, "out of memory");
806 static krb5_error_code
807 pac_checksum(krb5_context context
,
808 const krb5_keyblock
*key
,
812 krb5_cksumtype cktype
;
814 krb5_crypto crypto
= NULL
;
816 ret
= krb5_crypto_init(context
, key
, 0, &crypto
);
820 ret
= krb5_crypto_get_checksum_type(context
, crypto
, &cktype
);
821 ret
= krb5_crypto_destroy(context
, crypto
);
825 if (krb5_checksum_is_keyed(context
, cktype
) == FALSE
) {
826 krb5_set_error_string(context
, "PAC checksum type is not keyed");
830 ret
= krb5_checksumsize(context
, cktype
, cksumsize
);
834 *cksumtype
= (uint32_t)cktype
;
840 _krb5_pac_sign(krb5_context context
,
843 krb5_principal principal
,
844 const krb5_keyblock
*server_key
,
845 const krb5_keyblock
*priv_key
,
849 krb5_storage
*sp
= NULL
, *spdata
= NULL
;
851 size_t server_size
, priv_size
;
852 uint32_t server_offset
= 0, priv_offset
= 0;
853 uint32_t server_cksumtype
= 0, priv_cksumtype
= 0;
857 krb5_data_zero(&logon
);
859 if (p
->logon_name
== NULL
)
861 if (p
->server_checksum
== NULL
)
863 if (p
->privsvr_checksum
== NULL
)
869 ptr
= realloc(p
->pac
, sizeof(*p
->pac
) + (sizeof(p
->pac
->buffers
[0]) * (p
->pac
->numbuffers
+ num
- 1)));
871 krb5_set_error_string(context
, "out of memory");
876 if (p
->logon_name
== NULL
) {
877 p
->logon_name
= &p
->pac
->buffers
[p
->pac
->numbuffers
++];
878 memset(p
->logon_name
, 0, sizeof(*p
->logon_name
));
879 p
->logon_name
->type
= PAC_LOGON_NAME
;
881 if (p
->server_checksum
== NULL
) {
882 p
->server_checksum
= &p
->pac
->buffers
[p
->pac
->numbuffers
++];
883 memset(p
->server_checksum
, 0, sizeof(*p
->server_checksum
));
884 p
->server_checksum
->type
= PAC_SERVER_CHECKSUM
;
886 if (p
->privsvr_checksum
== NULL
) {
887 p
->privsvr_checksum
= &p
->pac
->buffers
[p
->pac
->numbuffers
++];
888 memset(p
->privsvr_checksum
, 0, sizeof(*p
->privsvr_checksum
));
889 p
->privsvr_checksum
->type
= PAC_PRIVSVR_CHECKSUM
;
893 /* Calculate LOGON NAME */
894 ret
= build_logon_name(context
, authtime
, principal
, &logon
);
898 /* Set lengths for checksum */
899 ret
= pac_checksum(context
, server_key
, &server_cksumtype
, &server_size
);
902 ret
= pac_checksum(context
, priv_key
, &priv_cksumtype
, &priv_size
);
907 sp
= krb5_storage_emem();
909 krb5_set_error_string(context
, "out of memory");
912 krb5_storage_set_flags(sp
, KRB5_STORAGE_BYTEORDER_LE
);
914 spdata
= krb5_storage_emem();
915 if (spdata
== NULL
) {
916 krb5_storage_free(sp
);
917 krb5_set_error_string(context
, "out of memory");
920 krb5_storage_set_flags(spdata
, KRB5_STORAGE_BYTEORDER_LE
);
922 CHECK(ret
, krb5_store_uint32(sp
, p
->pac
->numbuffers
), out
);
923 CHECK(ret
, krb5_store_uint32(sp
, p
->pac
->version
), out
);
925 end
= PACTYPE_SIZE
+ (PAC_INFO_BUFFER_SIZE
* p
->pac
->numbuffers
);
927 for (i
= 0; i
< p
->pac
->numbuffers
; i
++) {
934 if (p
->pac
->buffers
[i
].type
== PAC_SERVER_CHECKSUM
) {
935 len
= server_size
+ 4;
936 server_offset
= end
+ 4;
937 CHECK(ret
, krb5_store_uint32(spdata
, server_cksumtype
), out
);
938 CHECK(ret
, fill_zeros(context
, spdata
, server_size
), out
);
939 } else if (p
->pac
->buffers
[i
].type
== PAC_PRIVSVR_CHECKSUM
) {
941 priv_offset
= end
+ 4;
942 CHECK(ret
, krb5_store_uint32(spdata
, priv_cksumtype
), out
);
943 CHECK(ret
, fill_zeros(context
, spdata
, priv_size
), out
);
944 } else if (p
->pac
->buffers
[i
].type
== PAC_LOGON_NAME
) {
945 len
= krb5_storage_write(spdata
, logon
.data
, logon
.length
);
946 if (logon
.length
!= len
) {
951 len
= p
->pac
->buffers
[i
].buffersize
;
952 ptr
= (char *)p
->data
.data
+ p
->pac
->buffers
[i
].offset_lo
;
954 sret
= krb5_storage_write(spdata
, ptr
, len
);
956 krb5_set_error_string(context
, "out of memory");
960 /* XXX if not aligned, fill_zeros */
964 CHECK(ret
, krb5_store_uint32(sp
, p
->pac
->buffers
[i
].type
), out
);
965 CHECK(ret
, krb5_store_uint32(sp
, len
), out
);
966 CHECK(ret
, krb5_store_uint32(sp
, end
), out
);
967 CHECK(ret
, krb5_store_uint32(sp
, 0), out
);
969 /* advance data endpointer and align */
974 e
= ((end
+ PAC_ALIGNMENT
- 1) / PAC_ALIGNMENT
) * PAC_ALIGNMENT
;
976 CHECK(ret
, fill_zeros(context
, spdata
, e
- end
), out
);
983 /* assert (server_offset != 0 && priv_offset != 0); */
986 ret
= krb5_storage_to_data(spdata
, &d
);
988 krb5_set_error_string(context
, "out of memory");
991 ret
= krb5_storage_write(sp
, d
.data
, d
.length
);
992 if (ret
!= d
.length
) {
994 krb5_set_error_string(context
, "out of memory");
1000 ret
= krb5_storage_to_data(sp
, &d
);
1002 krb5_set_error_string(context
, "out of memory");
1008 ret
= create_checksum(context
, server_key
,
1010 (char *)d
.data
+ server_offset
, server_size
);
1016 ret
= create_checksum(context
, priv_key
,
1017 (char *)d
.data
+ server_offset
, server_size
,
1018 (char *)d
.data
+ priv_offset
, priv_size
);
1027 krb5_data_free(&logon
);
1028 krb5_storage_free(sp
);
1029 krb5_storage_free(spdata
);
1033 krb5_data_free(&logon
);
1035 krb5_storage_free(sp
);
1037 krb5_storage_free(spdata
);