2 * Copyright (c) 1997-2008 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"
35 #include "store-int.h"
37 #define BYTEORDER_IS(SP, V) (((SP)->flags & KRB5_STORAGE_BYTEORDER_MASK) == (V))
38 #define BYTEORDER_IS_LE(SP) BYTEORDER_IS((SP), KRB5_STORAGE_BYTEORDER_LE)
39 #define BYTEORDER_IS_BE(SP) BYTEORDER_IS((SP), KRB5_STORAGE_BYTEORDER_BE)
40 #define BYTEORDER_IS_HOST(SP) (BYTEORDER_IS((SP), KRB5_STORAGE_BYTEORDER_HOST) || \
41 krb5_storage_is_flags((SP), KRB5_STORAGE_HOST_BYTEORDER))
43 void KRB5_LIB_FUNCTION
44 krb5_storage_set_flags(krb5_storage
*sp
, krb5_flags flags
)
49 void KRB5_LIB_FUNCTION
50 krb5_storage_clear_flags(krb5_storage
*sp
, krb5_flags flags
)
56 * Return true or false depending on if the storage flags is set or
57 * not. NB testing for the flag 0 always return true.
59 * @param sp the storage buffer to check flags on
60 * @param flags The flags to test for
62 * @return true if all the flags are set, false if not.
64 * @ingroup krb5_storage
67 krb5_boolean KRB5_LIB_FUNCTION
68 krb5_storage_is_flags(krb5_storage
*sp
, krb5_flags flags
)
70 return (sp
->flags
& flags
) == flags
;
74 * Set the new byte order of the storage buffer.
76 * @param sp the storage buffer to set the byte order for.
77 * @param byteorder the new byte order.
79 * The byte order are: KRB5_STORAGE_BYTEORDER_BE,
80 * KRB5_STORAGE_BYTEORDER_LE and KRB5_STORAGE_BYTEORDER_HOST.
82 * @ingroup krb5_storage
85 void KRB5_LIB_FUNCTION
86 krb5_storage_set_byteorder(krb5_storage
*sp
, krb5_flags byteorder
)
88 sp
->flags
&= ~KRB5_STORAGE_BYTEORDER_MASK
;
89 sp
->flags
|= byteorder
;
93 * Return the current byteorder for the buffer. See krb5_storage_set_byteorder() for the list or byte order contants.
95 * @ingroup krb5_storage
98 krb5_flags KRB5_LIB_FUNCTION
99 krb5_storage_get_byteorder(krb5_storage
*sp
)
101 return sp
->flags
& KRB5_STORAGE_BYTEORDER_MASK
;
105 * Seek to a new offset.
107 * @param sp the storage buffer to seek in.
108 * @param offset the offset to seek
109 * @param whence relateive searching, SEEK_CUR from the current
110 * position, SEEK_END from the end, SEEK_SET absolute from the start.
112 * @return The new current offset
114 * @ingroup krb5_storage
117 off_t KRB5_LIB_FUNCTION
118 krb5_storage_seek(krb5_storage
*sp
, off_t offset
, int whence
)
120 return (*sp
->seek
)(sp
, offset
, whence
);
124 * Truncate the storage buffer in sp to offset.
126 * @param sp the storage buffer to truncate.
127 * @param offset the offset to truncate too.
129 * @return An Kerberos 5 error code.
131 * @ingroup krb5_storage
134 int KRB5_LIB_FUNCTION
135 krb5_storage_truncate(krb5_storage
*sp
, off_t offset
)
137 return (*sp
->trunc
)(sp
, offset
);
141 * Read to the storage buffer.
143 * @param sp the storage buffer to read from
144 * @param buf the buffer to store the data in
145 * @param len the length to read
147 * @return The length of data read (can be shorter then len), or negative on error.
149 * @ingroup krb5_storage
152 krb5_ssize_t KRB5_LIB_FUNCTION
153 krb5_storage_read(krb5_storage
*sp
, void *buf
, size_t len
)
155 return sp
->fetch(sp
, buf
, len
);
159 * Write to the storage buffer.
161 * @param sp the storage buffer to write to
162 * @param buf the buffer to write to the storage buffer
163 * @param len the length to write
165 * @return The length of data written (can be shorter then len), or negative on error.
167 * @ingroup krb5_storage
170 krb5_ssize_t KRB5_LIB_FUNCTION
171 krb5_storage_write(krb5_storage
*sp
, const void *buf
, size_t len
)
173 return sp
->store(sp
, buf
, len
);
177 * Set the return code that will be used when end of storage is reached.
179 * @param sp the storage
180 * @param code the error code to return on end of storage
182 * @ingroup krb5_storage
185 void KRB5_LIB_FUNCTION
186 krb5_storage_set_eof_code(krb5_storage
*sp
, int code
)
192 * Get the return code that will be used when end of storage is reached.
194 * @param sp the storage
196 * @return storage error code
198 * @ingroup krb5_storage
201 int KRB5_LIB_FUNCTION
202 krb5_storage_get_eof_code(krb5_storage
*sp
)
207 krb5_ssize_t KRB5_LIB_FUNCTION
208 _krb5_put_int(void *buffer
, unsigned long value
, size_t size
)
210 unsigned char *p
= buffer
;
212 for (i
= size
- 1; i
>= 0; i
--) {
219 krb5_ssize_t KRB5_LIB_FUNCTION
220 _krb5_get_int(void *buffer
, unsigned long *value
, size_t size
)
222 unsigned char *p
= buffer
;
225 for (i
= 0; i
< size
; i
++)
232 * Free a krb5 storage.
234 * @param sp the storage to free.
236 * @return An Kerberos 5 error code.
238 * @ingroup krb5_storage
241 krb5_error_code KRB5_LIB_FUNCTION
242 krb5_storage_free(krb5_storage
*sp
)
252 * Copy the contnent of storage
254 * @param sp the storage to copy to a data
255 * @param data the copied data, free with krb5_data_free()
257 * @return 0 for success, or a Kerberos 5 error code on failure.
259 * @ingroup krb5_storage
262 krb5_error_code KRB5_LIB_FUNCTION
263 krb5_storage_to_data(krb5_storage
*sp
, krb5_data
*data
)
268 pos
= sp
->seek(sp
, 0, SEEK_CUR
);
270 return HEIM_ERR_NOT_SEEKABLE
;
271 size
= (size_t)sp
->seek(sp
, 0, SEEK_END
);
272 if (size
> (size_t)-1)
273 return HEIM_ERR_TOO_BIG
;
274 ret
= krb5_data_alloc (data
, size
);
276 sp
->seek(sp
, pos
, SEEK_SET
);
280 sp
->seek(sp
, 0, SEEK_SET
);
281 sp
->fetch(sp
, data
->data
, data
->length
);
282 sp
->seek(sp
, pos
, SEEK_SET
);
287 static krb5_error_code
288 krb5_store_int(krb5_storage
*sp
,
297 _krb5_put_int(v
, value
, len
);
298 ret
= sp
->store(sp
, v
, len
);
300 return (ret
<0)?errno
:sp
->eof_code
;
305 * Store a int32 to storage, byte order is controlled by the settings
306 * on the storage, see krb5_storage_set_byteorder().
308 * @param sp the storage to write too
309 * @param value the value to store
311 * @return 0 for success, or a Kerberos 5 error code on failure.
313 * @ingroup krb5_storage
316 krb5_error_code KRB5_LIB_FUNCTION
317 krb5_store_int32(krb5_storage
*sp
,
320 if(BYTEORDER_IS_HOST(sp
))
321 value
= htonl(value
);
322 else if(BYTEORDER_IS_LE(sp
))
323 value
= bswap32(value
);
324 return krb5_store_int(sp
, value
, 4);
328 * Store a uint32 to storage, byte order is controlled by the settings
329 * on the storage, see krb5_storage_set_byteorder().
331 * @param sp the storage to write too
332 * @param value the value to store
334 * @return 0 for success, or a Kerberos 5 error code on failure.
336 * @ingroup krb5_storage
339 krb5_error_code KRB5_LIB_FUNCTION
340 krb5_store_uint32(krb5_storage
*sp
,
343 return krb5_store_int32(sp
, (int32_t)value
);
346 static krb5_error_code
347 krb5_ret_int(krb5_storage
*sp
,
354 ret
= sp
->fetch(sp
, v
, len
);
356 return (ret
<0)?errno
:sp
->eof_code
;
357 _krb5_get_int(v
, &w
, len
);
362 krb5_error_code KRB5_LIB_FUNCTION
363 krb5_ret_int32(krb5_storage
*sp
,
366 krb5_error_code ret
= krb5_ret_int(sp
, value
, 4);
369 if(BYTEORDER_IS_HOST(sp
))
370 *value
= htonl(*value
);
371 else if(BYTEORDER_IS_LE(sp
))
372 *value
= bswap32(*value
);
376 krb5_error_code KRB5_LIB_FUNCTION
377 krb5_ret_uint32(krb5_storage
*sp
,
383 ret
= krb5_ret_int32(sp
, &v
);
385 *value
= (uint32_t)v
;
391 * Store a int16 to storage, byte order is controlled by the settings
392 * on the storage, see krb5_storage_set_byteorder().
394 * @param sp the storage to write too
395 * @param value the value to store
397 * @return 0 for success, or a Kerberos 5 error code on failure.
399 * @ingroup krb5_storage
402 krb5_error_code KRB5_LIB_FUNCTION
403 krb5_store_int16(krb5_storage
*sp
,
406 if(BYTEORDER_IS_HOST(sp
))
407 value
= htons(value
);
408 else if(BYTEORDER_IS_LE(sp
))
409 value
= bswap16(value
);
410 return krb5_store_int(sp
, value
, 2);
414 * Store a uint16 to storage, byte order is controlled by the settings
415 * on the storage, see krb5_storage_set_byteorder().
417 * @param sp the storage to write too
418 * @param value the value to store
420 * @return 0 for success, or a Kerberos 5 error code on failure.
422 * @ingroup krb5_storage
425 krb5_error_code KRB5_LIB_FUNCTION
426 krb5_store_uint16(krb5_storage
*sp
,
429 return krb5_store_int16(sp
, (int16_t)value
);
432 krb5_error_code KRB5_LIB_FUNCTION
433 krb5_ret_int16(krb5_storage
*sp
,
438 ret
= krb5_ret_int(sp
, &v
, 2);
442 if(BYTEORDER_IS_HOST(sp
))
443 *value
= htons(*value
);
444 else if(BYTEORDER_IS_LE(sp
))
445 *value
= bswap16(*value
);
449 krb5_error_code KRB5_LIB_FUNCTION
450 krb5_ret_uint16(krb5_storage
*sp
,
456 ret
= krb5_ret_int16(sp
, &v
);
458 *value
= (uint16_t)v
;
464 * Store a int8 to storage.
466 * @param sp the storage to write too
467 * @param value the value to store
469 * @return 0 for success, or a Kerberos 5 error code on failure.
471 * @ingroup krb5_storage
474 krb5_error_code KRB5_LIB_FUNCTION
475 krb5_store_int8(krb5_storage
*sp
,
480 ret
= sp
->store(sp
, &value
, sizeof(value
));
481 if (ret
!= sizeof(value
))
482 return (ret
<0)?errno
:sp
->eof_code
;
487 * Store a uint8 to storage.
489 * @param sp the storage to write too
490 * @param value the value to store
492 * @return 0 for success, or a Kerberos 5 error code on failure.
494 * @ingroup krb5_storage
497 krb5_error_code KRB5_LIB_FUNCTION
498 krb5_store_uint8(krb5_storage
*sp
,
501 return krb5_store_int8(sp
, (int8_t)value
);
504 krb5_error_code KRB5_LIB_FUNCTION
505 krb5_ret_int8(krb5_storage
*sp
,
510 ret
= sp
->fetch(sp
, value
, sizeof(*value
));
511 if (ret
!= sizeof(*value
))
512 return (ret
<0)?errno
:sp
->eof_code
;
516 krb5_error_code KRB5_LIB_FUNCTION
517 krb5_ret_uint8(krb5_storage
*sp
,
523 ret
= krb5_ret_int8(sp
, &v
);
531 * Store a data to the storage.
533 * @param sp the storage buffer to write to
534 * @param data the buffer to store.
536 * @return 0 on success, a Kerberos 5 error code on failure.
538 * @ingroup krb5_storage
541 krb5_error_code KRB5_LIB_FUNCTION
542 krb5_store_data(krb5_storage
*sp
,
546 ret
= krb5_store_int32(sp
, data
.length
);
549 ret
= sp
->store(sp
, data
.data
, data
.length
);
550 if(ret
!= data
.length
){
559 * Parse a data from the storage.
561 * @param sp the storage buffer to read from
562 * @param data the parsed data
564 * @return 0 on success, a Kerberos 5 error code on failure.
566 * @ingroup krb5_storage
569 krb5_error_code KRB5_LIB_FUNCTION
570 krb5_ret_data(krb5_storage
*sp
,
576 ret
= krb5_ret_int32(sp
, &size
);
579 ret
= krb5_data_alloc (data
, size
);
583 ret
= sp
->fetch(sp
, data
->data
, size
);
585 return (ret
< 0)? errno
: sp
->eof_code
;
590 krb5_error_code KRB5_LIB_FUNCTION
591 krb5_store_string(krb5_storage
*sp
, const char *s
)
594 data
.length
= strlen(s
);
595 data
.data
= rk_UNCONST(s
);
596 return krb5_store_data(sp
, data
);
599 krb5_error_code KRB5_LIB_FUNCTION
600 krb5_ret_string(krb5_storage
*sp
,
605 ret
= krb5_ret_data(sp
, &data
);
608 *string
= realloc(data
.data
, data
.length
+ 1);
613 (*string
)[data
.length
] = 0;
617 krb5_error_code KRB5_LIB_FUNCTION
618 krb5_store_stringz(krb5_storage
*sp
, const char *s
)
620 size_t len
= strlen(s
) + 1;
623 ret
= sp
->store(sp
, s
, len
);
633 krb5_error_code KRB5_LIB_FUNCTION
634 krb5_ret_stringz(krb5_storage
*sp
,
642 while((ret
= sp
->fetch(sp
, &c
, 1)) == 1){
646 tmp
= realloc (s
, len
);
666 krb5_error_code KRB5_LIB_FUNCTION
667 krb5_store_stringnl(krb5_storage
*sp
, const char *s
)
669 size_t len
= strlen(s
);
672 ret
= sp
->store(sp
, s
, len
);
679 ret
= sp
->store(sp
, "\n", 1);
691 krb5_error_code KRB5_LIB_FUNCTION
692 krb5_ret_stringnl(krb5_storage
*sp
,
701 while((ret
= sp
->fetch(sp
, &c
, 1)) == 1){
708 if (expect_nl
&& c
!= '\n') {
710 return KRB5_BADMSGTYPE
;
714 tmp
= realloc (s
, len
);
737 krb5_error_code KRB5_LIB_FUNCTION
738 krb5_store_principal(krb5_storage
*sp
,
739 krb5_const_principal p
)
744 if(!krb5_storage_is_flags(sp
, KRB5_STORAGE_PRINCIPAL_NO_NAME_TYPE
)) {
745 ret
= krb5_store_int32(sp
, p
->name
.name_type
);
748 if(krb5_storage_is_flags(sp
, KRB5_STORAGE_PRINCIPAL_WRONG_NUM_COMPONENTS
))
749 ret
= krb5_store_int32(sp
, p
->name
.name_string
.len
+ 1);
751 ret
= krb5_store_int32(sp
, p
->name
.name_string
.len
);
754 ret
= krb5_store_string(sp
, p
->realm
);
756 for(i
= 0; i
< p
->name
.name_string
.len
; i
++){
757 ret
= krb5_store_string(sp
, p
->name
.name_string
.val
[i
]);
763 krb5_error_code KRB5_LIB_FUNCTION
764 krb5_ret_principal(krb5_storage
*sp
,
765 krb5_principal
*princ
)
773 p
= calloc(1, sizeof(*p
));
777 if(krb5_storage_is_flags(sp
, KRB5_STORAGE_PRINCIPAL_NO_NAME_TYPE
))
778 type
= KRB5_NT_UNKNOWN
;
779 else if((ret
= krb5_ret_int32(sp
, &type
))){
783 if((ret
= krb5_ret_int32(sp
, &ncomp
))){
787 if(krb5_storage_is_flags(sp
, KRB5_STORAGE_PRINCIPAL_WRONG_NUM_COMPONENTS
))
793 p
->name
.name_type
= type
;
794 p
->name
.name_string
.len
= ncomp
;
795 ret
= krb5_ret_string(sp
, &p
->realm
);
800 p
->name
.name_string
.val
= calloc(ncomp
, sizeof(*p
->name
.name_string
.val
));
801 if(p
->name
.name_string
.val
== NULL
&& ncomp
!= 0){
806 for(i
= 0; i
< ncomp
; i
++){
807 ret
= krb5_ret_string(sp
, &p
->name
.name_string
.val
[i
]);
810 free(p
->name
.name_string
.val
[i
--]);
821 * Store a keyblock to the storage.
823 * @param sp the storage buffer to write to
824 * @param p the keyblock to write
826 * @return 0 on success, a Kerberos 5 error code on failure.
828 * @ingroup krb5_storage
831 krb5_error_code KRB5_LIB_FUNCTION
832 krb5_store_keyblock(krb5_storage
*sp
, krb5_keyblock p
)
835 ret
= krb5_store_int16(sp
, p
.keytype
);
838 if(krb5_storage_is_flags(sp
, KRB5_STORAGE_KEYBLOCK_KEYTYPE_TWICE
)){
839 /* this should really be enctype, but it is the same as
841 ret
= krb5_store_int16(sp
, p
.keytype
);
845 ret
= krb5_store_data(sp
, p
.keyvalue
);
850 * Read a keyblock from the storage.
852 * @param sp the storage buffer to write to
853 * @param p the keyblock read from storage, free using krb5_free_keyblock()
855 * @return 0 on success, a Kerberos 5 error code on failure.
857 * @ingroup krb5_storage
860 krb5_error_code KRB5_LIB_FUNCTION
861 krb5_ret_keyblock(krb5_storage
*sp
, krb5_keyblock
*p
)
866 ret
= krb5_ret_int16(sp
, &tmp
);
870 if(krb5_storage_is_flags(sp
, KRB5_STORAGE_KEYBLOCK_KEYTYPE_TWICE
)){
871 ret
= krb5_ret_int16(sp
, &tmp
);
875 ret
= krb5_ret_data(sp
, &p
->keyvalue
);
880 * Write a times block to storage.
882 * @param sp the storage buffer to write to
883 * @param times the times block to write.
885 * @return 0 on success, a Kerberos 5 error code on failure.
887 * @ingroup krb5_storage
890 krb5_error_code KRB5_LIB_FUNCTION
891 krb5_store_times(krb5_storage
*sp
, krb5_times times
)
894 ret
= krb5_store_int32(sp
, times
.authtime
);
896 ret
= krb5_store_int32(sp
, times
.starttime
);
898 ret
= krb5_store_int32(sp
, times
.endtime
);
900 ret
= krb5_store_int32(sp
, times
.renew_till
);
905 * Read a times block from the storage.
907 * @param sp the storage buffer to write to
908 * @param times the times block read from storage
910 * @return 0 on success, a Kerberos 5 error code on failure.
912 * @ingroup krb5_storage
915 krb5_error_code KRB5_LIB_FUNCTION
916 krb5_ret_times(krb5_storage
*sp
, krb5_times
*times
)
920 ret
= krb5_ret_int32(sp
, &tmp
);
921 times
->authtime
= tmp
;
923 ret
= krb5_ret_int32(sp
, &tmp
);
924 times
->starttime
= tmp
;
926 ret
= krb5_ret_int32(sp
, &tmp
);
927 times
->endtime
= tmp
;
929 ret
= krb5_ret_int32(sp
, &tmp
);
930 times
->renew_till
= tmp
;
934 krb5_error_code KRB5_LIB_FUNCTION
935 krb5_store_address(krb5_storage
*sp
, krb5_address p
)
938 ret
= krb5_store_int16(sp
, p
.addr_type
);
940 ret
= krb5_store_data(sp
, p
.address
);
944 krb5_error_code KRB5_LIB_FUNCTION
945 krb5_ret_address(krb5_storage
*sp
, krb5_address
*adr
)
949 ret
= krb5_ret_int16(sp
, &t
);
952 ret
= krb5_ret_data(sp
, &adr
->address
);
956 krb5_error_code KRB5_LIB_FUNCTION
957 krb5_store_addrs(krb5_storage
*sp
, krb5_addresses p
)
961 ret
= krb5_store_int32(sp
, p
.len
);
963 for(i
= 0; i
<p
.len
; i
++){
964 ret
= krb5_store_address(sp
, p
.val
[i
]);
970 krb5_error_code KRB5_LIB_FUNCTION
971 krb5_ret_addrs(krb5_storage
*sp
, krb5_addresses
*adr
)
977 ret
= krb5_ret_int32(sp
, &tmp
);
980 ALLOC(adr
->val
, adr
->len
);
981 if (adr
->val
== NULL
&& adr
->len
!= 0)
983 for(i
= 0; i
< adr
->len
; i
++){
984 ret
= krb5_ret_address(sp
, &adr
->val
[i
]);
990 krb5_error_code KRB5_LIB_FUNCTION
991 krb5_store_authdata(krb5_storage
*sp
, krb5_authdata auth
)
995 ret
= krb5_store_int32(sp
, auth
.len
);
997 for(i
= 0; i
< auth
.len
; i
++){
998 ret
= krb5_store_int16(sp
, auth
.val
[i
].ad_type
);
1000 ret
= krb5_store_data(sp
, auth
.val
[i
].ad_data
);
1006 krb5_error_code KRB5_LIB_FUNCTION
1007 krb5_ret_authdata(krb5_storage
*sp
, krb5_authdata
*auth
)
1009 krb5_error_code ret
;
1013 ret
= krb5_ret_int32(sp
, &tmp
);
1015 ALLOC_SEQ(auth
, tmp
);
1016 if (auth
->val
== NULL
&& tmp
!= 0)
1018 for(i
= 0; i
< tmp
; i
++){
1019 ret
= krb5_ret_int16(sp
, &tmp2
);
1021 auth
->val
[i
].ad_type
= tmp2
;
1022 ret
= krb5_ret_data(sp
, &auth
->val
[i
].ad_data
);
1029 bitswap32(int32_t b
)
1033 for (i
= 0; i
< 32; i
++) {
1034 r
= r
<< 1 | (b
& 1);
1045 krb5_error_code KRB5_LIB_FUNCTION
1046 krb5_store_creds(krb5_storage
*sp
, krb5_creds
*creds
)
1050 ret
= krb5_store_principal(sp
, creds
->client
);
1053 ret
= krb5_store_principal(sp
, creds
->server
);
1056 ret
= krb5_store_keyblock(sp
, creds
->session
);
1059 ret
= krb5_store_times(sp
, creds
->times
);
1062 ret
= krb5_store_int8(sp
, creds
->second_ticket
.length
!= 0); /* is_skey */
1066 if(krb5_storage_is_flags(sp
, KRB5_STORAGE_CREDS_FLAGS_WRONG_BITORDER
))
1067 ret
= krb5_store_int32(sp
, creds
->flags
.i
);
1069 ret
= krb5_store_int32(sp
, bitswap32(TicketFlags2int(creds
->flags
.b
)));
1073 ret
= krb5_store_addrs(sp
, creds
->addresses
);
1076 ret
= krb5_store_authdata(sp
, creds
->authdata
);
1079 ret
= krb5_store_data(sp
, creds
->ticket
);
1082 ret
= krb5_store_data(sp
, creds
->second_ticket
);
1086 krb5_error_code KRB5_LIB_FUNCTION
1087 krb5_ret_creds(krb5_storage
*sp
, krb5_creds
*creds
)
1089 krb5_error_code ret
;
1093 memset(creds
, 0, sizeof(*creds
));
1094 ret
= krb5_ret_principal (sp
, &creds
->client
);
1095 if(ret
) goto cleanup
;
1096 ret
= krb5_ret_principal (sp
, &creds
->server
);
1097 if(ret
) goto cleanup
;
1098 ret
= krb5_ret_keyblock (sp
, &creds
->session
);
1099 if(ret
) goto cleanup
;
1100 ret
= krb5_ret_times (sp
, &creds
->times
);
1101 if(ret
) goto cleanup
;
1102 ret
= krb5_ret_int8 (sp
, &dummy8
);
1103 if(ret
) goto cleanup
;
1104 ret
= krb5_ret_int32 (sp
, &dummy32
);
1105 if(ret
) goto cleanup
;
1107 * Runtime detect the what is the higher bits of the bitfield. If
1108 * any of the higher bits are set in the input data, it's either a
1109 * new ticket flag (and this code need to be removed), or it's a
1110 * MIT cache (or new Heimdal cache), lets change it to our current
1114 uint32_t mask
= 0xffff0000;
1116 creds
->flags
.b
.anonymous
= 1;
1117 if (creds
->flags
.i
& mask
)
1120 dummy32
= bitswap32(dummy32
);
1122 creds
->flags
.i
= dummy32
;
1123 ret
= krb5_ret_addrs (sp
, &creds
->addresses
);
1124 if(ret
) goto cleanup
;
1125 ret
= krb5_ret_authdata (sp
, &creds
->authdata
);
1126 if(ret
) goto cleanup
;
1127 ret
= krb5_ret_data (sp
, &creds
->ticket
);
1128 if(ret
) goto cleanup
;
1129 ret
= krb5_ret_data (sp
, &creds
->second_ticket
);
1133 krb5_free_cred_contents(context
, creds
); /* XXX */
1139 #define SC_CLIENT_PRINCIPAL 0x0001
1140 #define SC_SERVER_PRINCIPAL 0x0002
1141 #define SC_SESSION_KEY 0x0004
1142 #define SC_TICKET 0x0008
1143 #define SC_SECOND_TICKET 0x0010
1144 #define SC_AUTHDATA 0x0020
1145 #define SC_ADDRESSES 0x0040
1151 krb5_error_code KRB5_LIB_FUNCTION
1152 krb5_store_creds_tag(krb5_storage
*sp
, krb5_creds
*creds
)
1158 header
|= SC_CLIENT_PRINCIPAL
;
1160 header
|= SC_SERVER_PRINCIPAL
;
1161 if (creds
->session
.keytype
!= ETYPE_NULL
)
1162 header
|= SC_SESSION_KEY
;
1163 if (creds
->ticket
.data
)
1164 header
|= SC_TICKET
;
1165 if (creds
->second_ticket
.length
)
1166 header
|= SC_SECOND_TICKET
;
1167 if (creds
->authdata
.len
)
1168 header
|= SC_AUTHDATA
;
1169 if (creds
->addresses
.len
)
1170 header
|= SC_ADDRESSES
;
1172 ret
= krb5_store_int32(sp
, header
);
1176 if (creds
->client
) {
1177 ret
= krb5_store_principal(sp
, creds
->client
);
1182 if (creds
->server
) {
1183 ret
= krb5_store_principal(sp
, creds
->server
);
1188 if (creds
->session
.keytype
!= ETYPE_NULL
) {
1189 ret
= krb5_store_keyblock(sp
, creds
->session
);
1194 ret
= krb5_store_times(sp
, creds
->times
);
1197 ret
= krb5_store_int8(sp
, creds
->second_ticket
.length
!= 0); /* is_skey */
1201 ret
= krb5_store_int32(sp
, bitswap32(TicketFlags2int(creds
->flags
.b
)));
1205 if (creds
->addresses
.len
) {
1206 ret
= krb5_store_addrs(sp
, creds
->addresses
);
1211 if (creds
->authdata
.len
) {
1212 ret
= krb5_store_authdata(sp
, creds
->authdata
);
1217 if (creds
->ticket
.data
) {
1218 ret
= krb5_store_data(sp
, creds
->ticket
);
1223 if (creds
->second_ticket
.data
) {
1224 ret
= krb5_store_data(sp
, creds
->second_ticket
);
1232 krb5_error_code KRB5_LIB_FUNCTION
1233 krb5_ret_creds_tag(krb5_storage
*sp
,
1236 krb5_error_code ret
;
1238 int32_t dummy32
, header
;
1240 memset(creds
, 0, sizeof(*creds
));
1242 ret
= krb5_ret_int32 (sp
, &header
);
1243 if (ret
) goto cleanup
;
1245 if (header
& SC_CLIENT_PRINCIPAL
) {
1246 ret
= krb5_ret_principal (sp
, &creds
->client
);
1247 if(ret
) goto cleanup
;
1249 if (header
& SC_SERVER_PRINCIPAL
) {
1250 ret
= krb5_ret_principal (sp
, &creds
->server
);
1251 if(ret
) goto cleanup
;
1253 if (header
& SC_SESSION_KEY
) {
1254 ret
= krb5_ret_keyblock (sp
, &creds
->session
);
1255 if(ret
) goto cleanup
;
1257 ret
= krb5_ret_times (sp
, &creds
->times
);
1258 if(ret
) goto cleanup
;
1259 ret
= krb5_ret_int8 (sp
, &dummy8
);
1260 if(ret
) goto cleanup
;
1261 ret
= krb5_ret_int32 (sp
, &dummy32
);
1262 if(ret
) goto cleanup
;
1264 * Runtime detect the what is the higher bits of the bitfield. If
1265 * any of the higher bits are set in the input data, it's either a
1266 * new ticket flag (and this code need to be removed), or it's a
1267 * MIT cache (or new Heimdal cache), lets change it to our current
1271 uint32_t mask
= 0xffff0000;
1273 creds
->flags
.b
.anonymous
= 1;
1274 if (creds
->flags
.i
& mask
)
1277 dummy32
= bitswap32(dummy32
);
1279 creds
->flags
.i
= dummy32
;
1280 if (header
& SC_ADDRESSES
) {
1281 ret
= krb5_ret_addrs (sp
, &creds
->addresses
);
1282 if(ret
) goto cleanup
;
1284 if (header
& SC_AUTHDATA
) {
1285 ret
= krb5_ret_authdata (sp
, &creds
->authdata
);
1286 if(ret
) goto cleanup
;
1288 if (header
& SC_TICKET
) {
1289 ret
= krb5_ret_data (sp
, &creds
->ticket
);
1290 if(ret
) goto cleanup
;
1292 if (header
& SC_SECOND_TICKET
) {
1293 ret
= krb5_ret_data (sp
, &creds
->second_ticket
);
1294 if(ret
) goto cleanup
;
1300 krb5_free_cred_contents(context
, creds
); /* XXX */