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))
42 #define BYTEORDER_IS_PACKED(SP) BYTEORDER_IS((SP), KRB5_STORAGE_BYTEORDER_PACKED)
45 * Add the flags on a storage buffer by or-ing in the flags to the buffer.
47 * @param sp the storage buffer to set the flags on
48 * @param flags the flags to set
50 * @ingroup krb5_storage
53 KRB5_LIB_FUNCTION
void KRB5_LIB_CALL
54 krb5_storage_set_flags(krb5_storage
*sp
, krb5_flags flags
)
60 * Clear the flags on a storage buffer
62 * @param sp the storage buffer to clear the flags on
63 * @param flags the flags to clear
65 * @ingroup krb5_storage
68 KRB5_LIB_FUNCTION
void KRB5_LIB_CALL
69 krb5_storage_clear_flags(krb5_storage
*sp
, krb5_flags flags
)
75 * Return true or false depending on if the storage flags is set or
76 * not. NB testing for the flag 0 always return true.
78 * @param sp the storage buffer to check flags on
79 * @param flags The flags to test for
81 * @return true if all the flags are set, false if not.
83 * @ingroup krb5_storage
86 KRB5_LIB_FUNCTION krb5_boolean KRB5_LIB_CALL
87 krb5_storage_is_flags(krb5_storage
*sp
, krb5_flags flags
)
89 return (sp
->flags
& flags
) == flags
;
93 * Set the new byte order of the storage buffer.
95 * @param sp the storage buffer to set the byte order for.
96 * @param byteorder the new byte order.
98 * The byte order are: KRB5_STORAGE_BYTEORDER_BE,
99 * KRB5_STORAGE_BYTEORDER_LE and KRB5_STORAGE_BYTEORDER_HOST.
101 * @ingroup krb5_storage
104 KRB5_LIB_FUNCTION
void KRB5_LIB_CALL
105 krb5_storage_set_byteorder(krb5_storage
*sp
, krb5_flags byteorder
)
107 sp
->flags
&= ~KRB5_STORAGE_BYTEORDER_MASK
;
108 sp
->flags
|= byteorder
;
112 * Return the current byteorder for the buffer. See krb5_storage_set_byteorder() for the list or byte order contants.
114 * @ingroup krb5_storage
117 KRB5_LIB_FUNCTION krb5_flags KRB5_LIB_CALL
118 krb5_storage_get_byteorder(krb5_storage
*sp
)
120 return sp
->flags
& KRB5_STORAGE_BYTEORDER_MASK
;
124 * Set the max alloc value
126 * @param sp the storage buffer set the max allow for
127 * @param size maximum size to allocate, use 0 to remove limit
129 * @ingroup krb5_storage
132 KRB5_LIB_FUNCTION
void KRB5_LIB_CALL
133 krb5_storage_set_max_alloc(krb5_storage
*sp
, size_t size
)
135 sp
->max_alloc
= size
;
138 /* don't allocate unresonable amount of memory */
139 static krb5_error_code
140 size_too_large(krb5_storage
*sp
, size_t size
)
142 if (sp
->max_alloc
&& sp
->max_alloc
< size
)
143 return HEIM_ERR_TOO_BIG
;
147 static krb5_error_code
148 size_too_large_num(krb5_storage
*sp
, size_t count
, size_t size
)
150 if (sp
->max_alloc
== 0 || size
== 0)
152 size
= sp
->max_alloc
/ size
;
154 return HEIM_ERR_TOO_BIG
;
159 * Seek to a new offset.
161 * @param sp the storage buffer to seek in.
162 * @param offset the offset to seek
163 * @param whence relateive searching, SEEK_CUR from the current
164 * position, SEEK_END from the end, SEEK_SET absolute from the start.
166 * @return The new current offset
168 * @ingroup krb5_storage
171 KRB5_LIB_FUNCTION off_t KRB5_LIB_CALL
172 krb5_storage_seek(krb5_storage
*sp
, off_t offset
, int whence
)
174 return (*sp
->seek
)(sp
, offset
, whence
);
178 * Truncate the storage buffer in sp to offset.
180 * @param sp the storage buffer to truncate.
181 * @param offset the offset to truncate to.
183 * @return An Kerberos 5 error code.
185 * @ingroup krb5_storage
188 KRB5_LIB_FUNCTION
int KRB5_LIB_CALL
189 krb5_storage_truncate(krb5_storage
*sp
, off_t offset
)
191 return (*sp
->trunc
)(sp
, offset
);
195 * Sync the storage buffer to its backing store. If there is no
196 * backing store this function will return success.
198 * @param sp the storage buffer to sync
200 * @return A Kerberos 5 error code
202 * @ingroup krb5_storage
205 KRB5_LIB_FUNCTION
int KRB5_LIB_CALL
206 krb5_storage_fsync(krb5_storage
*sp
)
208 if (sp
->fsync
!= NULL
)
209 return sp
->fsync(sp
);
214 * Read to the storage buffer.
216 * @param sp the storage buffer to read from
217 * @param buf the buffer to store the data in
218 * @param len the length to read
220 * @return The length of data read (can be shorter then len), or negative on error.
222 * @ingroup krb5_storage
225 KRB5_LIB_FUNCTION krb5_ssize_t KRB5_LIB_CALL
226 krb5_storage_read(krb5_storage
*sp
, void *buf
, size_t len
)
228 return sp
->fetch(sp
, buf
, len
);
232 * Write to the storage buffer.
234 * @param sp the storage buffer to write to
235 * @param buf the buffer to write to the storage buffer
236 * @param len the length to write
238 * @return The length of data written (can be shorter then len), or negative on error.
240 * @ingroup krb5_storage
243 KRB5_LIB_FUNCTION krb5_ssize_t KRB5_LIB_CALL
244 krb5_storage_write(krb5_storage
*sp
, const void *buf
, size_t len
)
246 return sp
->store(sp
, buf
, len
);
250 * Set the return code that will be used when end of storage is reached.
252 * @param sp the storage
253 * @param code the error code to return on end of storage
255 * @ingroup krb5_storage
258 KRB5_LIB_FUNCTION
void KRB5_LIB_CALL
259 krb5_storage_set_eof_code(krb5_storage
*sp
, int code
)
265 * Get the return code that will be used when end of storage is reached.
267 * @param sp the storage
269 * @return storage error code
271 * @ingroup krb5_storage
274 KRB5_LIB_FUNCTION
int KRB5_LIB_CALL
275 krb5_storage_get_eof_code(krb5_storage
*sp
)
281 * Free a krb5 storage.
283 * @param sp the storage to free.
285 * @return An Kerberos 5 error code.
287 * @ingroup krb5_storage
290 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
291 krb5_storage_free(krb5_storage
*sp
)
303 * Copy the content of storage to a krb5_data.
305 * @param sp the storage to copy to a data
306 * @param data the copied data, free with krb5_data_free()
308 * @return 0 for success, or a Kerberos 5 error code on failure.
310 * @ingroup krb5_storage
313 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
314 krb5_storage_to_data(krb5_storage
*sp
, krb5_data
*data
)
319 pos
= sp
->seek(sp
, 0, SEEK_CUR
);
321 return HEIM_ERR_NOT_SEEKABLE
;
322 size
= sp
->seek(sp
, 0, SEEK_END
);
323 ret
= size_too_large(sp
, size
);
326 ret
= krb5_data_alloc(data
, size
);
328 sp
->seek(sp
, pos
, SEEK_SET
);
334 sp
->seek(sp
, 0, SEEK_SET
);
335 bytes
= sp
->fetch(sp
, data
->data
, data
->length
);
336 sp
->seek(sp
, pos
, SEEK_SET
);
338 /* sp->fetch() really shouldn't fail */
342 /* Maybe the underlying file (or whatever) got truncated? */
343 data
->length
= bytes
;
349 pack_int(uint8_t *p
, uint64_t val
)
367 unpack_int_length(uint8_t *v
)
380 unpack_int(uint8_t *p
, size_t len
, uint64_t *val
, size_t *size
)
403 e
= der_get_unsigned64(p
, v
, &tmp
, &l
);
412 static krb5_error_code
413 krb5_store_int(krb5_storage
*sp
,
418 uint8_t v
[9], *p
= v
;
420 if (len
> sizeof(value
))
423 if (BYTEORDER_IS_PACKED(sp
)) {
424 uint64_t mask
= ~0ULL >> (64 - len
* 8);
427 len
= pack_int(p
, value
);
428 p
= v
+ sizeof(v
) - len
;
430 _krb5_put_int(v
, value
, len
);
431 ret
= sp
->store(sp
, p
, len
);
434 if ((size_t)ret
!= len
)
440 * Store a int32 to storage, byte order is controlled by the settings
441 * on the storage, see krb5_storage_set_byteorder().
443 * @param sp the storage to write to
444 * @param value the value to store
446 * @return 0 for success, or a Kerberos 5 error code on failure.
448 * @ingroup krb5_storage
451 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
452 krb5_store_int32(krb5_storage
*sp
,
455 if(BYTEORDER_IS_HOST(sp
))
456 value
= htonl(value
);
457 else if(BYTEORDER_IS_LE(sp
))
458 value
= bswap32(value
);
459 return krb5_store_int(sp
, value
, 4);
463 * Store a int64 to storage, byte order is controlled by the settings
464 * on the storage, see krb5_storage_set_byteorder().
466 * @param sp the storage to write to
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_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
475 krb5_store_int64(krb5_storage
*sp
,
478 if (BYTEORDER_IS_HOST(sp
))
479 #ifdef WORDS_BIGENDIAN
482 value
= bswap64(value
); /* There's no ntohll() */
484 else if (BYTEORDER_IS_LE(sp
))
485 value
= bswap64(value
);
486 return krb5_store_int(sp
, value
, 8);
490 * Store a uint32 to storage, byte order is controlled by the settings
491 * on the storage, see krb5_storage_set_byteorder().
493 * @param sp the storage to write to
494 * @param value the value to store
496 * @return 0 for success, or a Kerberos 5 error code on failure.
498 * @ingroup krb5_storage
501 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
502 krb5_store_uint32(krb5_storage
*sp
,
505 return krb5_store_int32(sp
, (int32_t)value
);
509 * Store a uint64 to storage, byte order is controlled by the settings
510 * on the storage, see krb5_storage_set_byteorder().
512 * @param sp the storage to write to
513 * @param value the value to store
515 * @return 0 for success, or a Kerberos 5 error code on failure.
517 * @ingroup krb5_storage
520 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
521 krb5_store_uint64(krb5_storage
*sp
,
524 return krb5_store_int64(sp
, (int64_t)value
);
527 static krb5_error_code
528 krb5_ret_int(krb5_storage
*sp
,
535 *value
= 0; /* quiets warnings */
536 if (BYTEORDER_IS_PACKED(sp
)) {
537 ret
= sp
->fetch(sp
, v
, 1);
543 len
= unpack_int_length(v
);
547 ret
= sp
->fetch(sp
, v
+ 1, len
- 1);
553 ret
= unpack_int(v
, len
, &w
, &len
);
559 ret
= sp
->fetch(sp
, v
, len
);
562 if ((size_t)ret
!= len
)
564 _krb5_get_int64(v
, &w
, len
);
570 * Read a int64 from storage, byte order is controlled by the settings
571 * on the storage, see krb5_storage_set_byteorder().
573 * @param sp the storage to write to
574 * @param value the value read from the buffer
576 * @return 0 for success, or a Kerberos 5 error code on failure.
578 * @ingroup krb5_storage
581 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
582 krb5_ret_int64(krb5_storage
*sp
,
585 krb5_error_code ret
= krb5_ret_int(sp
, value
, 8);
588 if(BYTEORDER_IS_HOST(sp
))
589 #ifdef WORDS_BIGENDIAN
592 *value
= bswap64(*value
); /* There's no ntohll() */
594 else if(BYTEORDER_IS_LE(sp
))
595 *value
= bswap64(*value
);
600 * Read a uint64 from storage, byte order is controlled by the settings
601 * on the storage, see krb5_storage_set_byteorder().
603 * @param sp the storage to write to
604 * @param value the value read from the buffer
606 * @return 0 for success, or a Kerberos 5 error code on failure.
608 * @ingroup krb5_storage
611 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
612 krb5_ret_uint64(krb5_storage
*sp
,
618 ret
= krb5_ret_int64(sp
, &v
);
620 *value
= (uint64_t)v
;
626 * Read a int32 from storage, byte order is controlled by the settings
627 * on the storage, see krb5_storage_set_byteorder().
629 * @param sp the storage to write to
630 * @param value the value read from the buffer
632 * @return 0 for success, or a Kerberos 5 error code on failure.
634 * @ingroup krb5_storage
637 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
638 krb5_ret_int32(krb5_storage
*sp
,
643 krb5_error_code ret
= krb5_ret_int(sp
, &v
, 4);
647 if (BYTEORDER_IS_HOST(sp
))
648 *value
= htonl(*value
);
649 else if (BYTEORDER_IS_LE(sp
))
650 *value
= bswap32(*value
);
655 * Read a uint32 from storage, byte order is controlled by the settings
656 * on the storage, see krb5_storage_set_byteorder().
658 * @param sp the storage to write to
659 * @param value the value read from the buffer
661 * @return 0 for success, or a Kerberos 5 error code on failure.
663 * @ingroup krb5_storage
666 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
667 krb5_ret_uint32(krb5_storage
*sp
, uint32_t *value
)
672 ret
= krb5_ret_int32(sp
, &v
);
674 *value
= (uint32_t)v
;
680 * Store a int16 to storage, byte order is controlled by the settings
681 * on the storage, see krb5_storage_set_byteorder().
683 * @param sp the storage to write to
684 * @param value the value to store
686 * @return 0 for success, or a Kerberos 5 error code on failure.
688 * @ingroup krb5_storage
691 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
692 krb5_store_int16(krb5_storage
*sp
,
695 if(BYTEORDER_IS_HOST(sp
))
696 value
= htons(value
);
697 else if(BYTEORDER_IS_LE(sp
))
698 value
= bswap16(value
);
699 return krb5_store_int(sp
, value
, 2);
703 * Store a uint16 to storage, byte order is controlled by the settings
704 * on the storage, see krb5_storage_set_byteorder().
706 * @param sp the storage to write to
707 * @param value the value to store
709 * @return 0 for success, or a Kerberos 5 error code on failure.
711 * @ingroup krb5_storage
714 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
715 krb5_store_uint16(krb5_storage
*sp
,
718 return krb5_store_int16(sp
, (int16_t)value
);
722 * Read a int16 from storage, byte order is controlled by the settings
723 * on the storage, see krb5_storage_set_byteorder().
725 * @param sp the storage to write to
726 * @param value the value read from the buffer
728 * @return 0 for success, or a Kerberos 5 error code on failure.
730 * @ingroup krb5_storage
733 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
734 krb5_ret_int16(krb5_storage
*sp
,
739 ret
= krb5_ret_int(sp
, &v
, 2);
743 if(BYTEORDER_IS_HOST(sp
))
744 *value
= htons(*value
);
745 else if(BYTEORDER_IS_LE(sp
))
746 *value
= bswap16(*value
);
751 * Read a int16 from storage, byte order is controlled by the settings
752 * on the storage, see krb5_storage_set_byteorder().
754 * @param sp the storage to write to
755 * @param value the value read from the buffer
757 * @return 0 for success, or a Kerberos 5 error code on failure.
759 * @ingroup krb5_storage
762 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
763 krb5_ret_uint16(krb5_storage
*sp
,
769 ret
= krb5_ret_int16(sp
, &v
);
771 *value
= (uint16_t)v
;
777 * Store a int8 to storage.
779 * @param sp the storage to write to
780 * @param value the value to store
782 * @return 0 for success, or a Kerberos 5 error code on failure.
784 * @ingroup krb5_storage
787 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
788 krb5_store_int8(krb5_storage
*sp
,
793 ret
= sp
->store(sp
, &value
, sizeof(value
));
794 if (ret
!= sizeof(value
))
795 return (ret
<0)?errno
:sp
->eof_code
;
800 * Store a uint8 to storage.
802 * @param sp the storage to write to
803 * @param value the value to store
805 * @return 0 for success, or a Kerberos 5 error code on failure.
807 * @ingroup krb5_storage
810 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
811 krb5_store_uint8(krb5_storage
*sp
,
814 return krb5_store_int8(sp
, (int8_t)value
);
818 * Read a int8 from storage
820 * @param sp the storage to write to
821 * @param value the value read from the buffer
823 * @return 0 for success, or a Kerberos 5 error code on failure.
825 * @ingroup krb5_storage
828 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
829 krb5_ret_int8(krb5_storage
*sp
,
834 ret
= sp
->fetch(sp
, value
, sizeof(*value
));
835 if (ret
< 0 || (size_t)ret
!= sizeof(*value
))
836 return (ret
<0)?errno
:sp
->eof_code
;
841 * Read a uint8 from storage
843 * @param sp the storage to write to
844 * @param value the value read from the buffer
846 * @return 0 for success, or a Kerberos 5 error code on failure.
848 * @ingroup krb5_storage
851 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
852 krb5_ret_uint8(krb5_storage
*sp
,
858 ret
= krb5_ret_int8(sp
, &v
);
866 * Store a data to the storage. The data is stored with an int32 as
867 * length plus the data (not padded).
869 * @param sp the storage buffer to write to
870 * @param data the buffer to store.
872 * @return 0 on success, a Kerberos 5 error code on failure.
874 * @ingroup krb5_storage
877 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
878 krb5_store_data(krb5_storage
*sp
,
882 ret
= krb5_store_int32(sp
, data
.length
);
885 ret
= sp
->store(sp
, data
.data
, data
.length
);
888 if((size_t)ret
!= data
.length
)
894 * Store a data blob to the storage. The data is stored with an int32 as
895 * length plus the data (not padded). This function only differs from
896 * krb5_store_data() insofar as it takes a void * and a length as parameters.
898 * @param sp the storage buffer to write to
899 * @param s the string to store.
900 * @param len length of the string to be stored.
902 * @return 0 on success, a Kerberos 5 error code on failure.
904 * @ingroup krb5_storage
906 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
907 krb5_store_datalen(krb5_storage
*sp
, const void *d
, size_t len
)
911 data
.data
= (void *)d
;
912 return krb5_store_data(sp
, data
);
916 * Store a data blob to the storage. The data is stored without a length.
918 * @param sp the storage buffer to write to
919 * @param s the string to store.
920 * @param len length of the string to be stored.
922 * @return 0 on success, a Kerberos 5 error code on failure.
924 * @ingroup krb5_storage
926 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
927 krb5_store_bytes(krb5_storage
*sp
, const void *d
, size_t len
)
931 ssize
= krb5_storage_write(sp
, d
, len
);
939 * Parse a data from the storage.
941 * @param sp the storage buffer to read from
942 * @param data the parsed data
944 * @return 0 on success, a Kerberos 5 error code on failure.
946 * @ingroup krb5_storage
949 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
950 krb5_ret_data(krb5_storage
*sp
,
956 ret
= krb5_ret_int32(sp
, &size
);
959 ret
= size_too_large(sp
, size
);
962 ret
= krb5_data_alloc (data
, size
);
968 bytes
= sp
->fetch(sp
, data
->data
, size
);
969 if (bytes
< 0 || bytes
!= size
) {
970 krb5_data_free(data
);
971 return (bytes
< 0)? errno
: sp
->eof_code
;
978 * Store a string to the buffer. The data is formated as an len:uint32
979 * plus the string itself (not padded).
981 * @param sp the storage buffer to write to
982 * @param s the string to store.
984 * @return 0 on success, a Kerberos 5 error code on failure.
986 * @ingroup krb5_storage
989 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
990 krb5_store_string(krb5_storage
*sp
, const char *s
)
997 data
.length
= strlen(s
);
998 data
.data
= rk_UNCONST(s
);
999 return krb5_store_data(sp
, data
);
1003 * Parse a string from the storage.
1005 * @param sp the storage buffer to read from
1006 * @param string the parsed string
1008 * @return 0 on success, a Kerberos 5 error code on failure.
1010 * @ingroup krb5_storage
1014 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1015 krb5_ret_string(krb5_storage
*sp
,
1022 ret
= krb5_ret_data(sp
, &data
);
1025 *string
= realloc(data
.data
, data
.length
+ 1);
1026 if(*string
== NULL
){
1030 (*string
)[data
.length
] = 0;
1035 * Store a zero terminated string to the buffer. The data is stored
1036 * one character at a time until a NUL is stored.
1038 * @param sp the storage buffer to write to
1039 * @param s the string to store.
1041 * @return 0 on success, a Kerberos 5 error code on failure.
1043 * @ingroup krb5_storage
1046 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1047 krb5_store_stringz(krb5_storage
*sp
, const char *s
)
1055 len
= strlen(s
) + 1;
1056 ret
= sp
->store(sp
, s
, len
);
1059 if((size_t)ret
!= len
)
1060 return sp
->eof_code
;
1065 * Parse zero terminated string from the storage.
1067 * @param sp the storage buffer to read from
1068 * @param string the parsed string
1070 * @return 0 on success, a Kerberos 5 error code on failure.
1072 * @ingroup krb5_storage
1075 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1076 krb5_ret_stringz(krb5_storage
*sp
,
1084 while((ret
= sp
->fetch(sp
, &c
, 1)) == 1){
1085 krb5_error_code eret
;
1089 eret
= size_too_large(sp
, len
);
1094 tmp
= realloc (s
, len
);
1107 return sp
->eof_code
;
1114 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1115 krb5_store_stringnl(krb5_storage
*sp
, const char *s
)
1124 ret
= sp
->store(sp
, s
, len
);
1127 if((size_t)ret
!= len
)
1128 return sp
->eof_code
;
1129 ret
= sp
->store(sp
, "\n", 1);
1134 return sp
->eof_code
;
1141 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1142 krb5_ret_stringnl(krb5_storage
*sp
,
1151 while((ret
= sp
->fetch(sp
, &c
, 1)) == 1){
1152 krb5_error_code eret
;
1159 if (expect_nl
&& c
!= '\n') {
1161 return KRB5_BADMSGTYPE
;
1165 eret
= size_too_large(sp
, len
);
1170 tmp
= realloc (s
, len
);
1185 return sp
->eof_code
;
1193 * Write a principal block to storage.
1195 * @param sp the storage buffer to write to
1196 * @param p the principal block to write.
1198 * @return 0 on success, a Kerberos 5 error code on failure.
1200 * @ingroup krb5_storage
1203 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1204 krb5_store_principal(krb5_storage
*sp
,
1205 krb5_const_principal p
)
1210 if(!krb5_storage_is_flags(sp
, KRB5_STORAGE_PRINCIPAL_NO_NAME_TYPE
)) {
1211 ret
= krb5_store_int32(sp
, p
->name
.name_type
);
1214 if(krb5_storage_is_flags(sp
, KRB5_STORAGE_PRINCIPAL_WRONG_NUM_COMPONENTS
))
1215 ret
= krb5_store_int32(sp
, p
->name
.name_string
.len
+ 1);
1217 ret
= krb5_store_int32(sp
, p
->name
.name_string
.len
);
1220 ret
= krb5_store_string(sp
, p
->realm
);
1222 for(i
= 0; i
< p
->name
.name_string
.len
; i
++){
1223 ret
= krb5_store_string(sp
, p
->name
.name_string
.val
[i
]);
1230 * Parse principal from the storage.
1232 * @param sp the storage buffer to read from
1233 * @param princ the parsed principal
1235 * @return 0 on success, a Kerberos 5 error code on failure.
1237 * @ingroup krb5_storage
1240 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1241 krb5_ret_principal(krb5_storage
*sp
,
1242 krb5_principal
*princ
)
1250 p
= calloc(1, sizeof(*p
));
1254 if(krb5_storage_is_flags(sp
, KRB5_STORAGE_PRINCIPAL_NO_NAME_TYPE
))
1255 type
= KRB5_NT_UNKNOWN
;
1256 else if((ret
= krb5_ret_int32(sp
, &type
))){
1260 if((ret
= krb5_ret_int32(sp
, &ncomp
))){
1264 if(krb5_storage_is_flags(sp
, KRB5_STORAGE_PRINCIPAL_WRONG_NUM_COMPONENTS
))
1270 ret
= size_too_large_num(sp
, ncomp
, sizeof(p
->name
.name_string
.val
[0]));
1275 p
->name
.name_type
= type
;
1276 p
->name
.name_string
.len
= ncomp
;
1277 ret
= krb5_ret_string(sp
, &p
->realm
);
1282 p
->name
.name_string
.val
= calloc(ncomp
, sizeof(p
->name
.name_string
.val
[0]));
1283 if(p
->name
.name_string
.val
== NULL
&& ncomp
!= 0){
1288 for(i
= 0; i
< ncomp
; i
++){
1289 ret
= krb5_ret_string(sp
, &p
->name
.name_string
.val
[i
]);
1292 free(p
->name
.name_string
.val
[i
--]);
1303 * Store a keyblock to the storage.
1305 * @param sp the storage buffer to write to
1306 * @param p the keyblock to write
1308 * @return 0 on success, a Kerberos 5 error code on failure.
1310 * @ingroup krb5_storage
1313 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1314 krb5_store_keyblock(krb5_storage
*sp
, krb5_keyblock p
)
1317 ret
= krb5_store_int16(sp
, p
.keytype
);
1320 if(krb5_storage_is_flags(sp
, KRB5_STORAGE_KEYBLOCK_KEYTYPE_TWICE
)){
1321 /* this should really be enctype, but it is the same as
1323 ret
= krb5_store_int16(sp
, p
.keytype
);
1327 ret
= krb5_store_data(sp
, p
.keyvalue
);
1332 * Read a keyblock from the storage.
1334 * @param sp the storage buffer to write to
1335 * @param p the keyblock read from storage, free using krb5_free_keyblock()
1337 * @return 0 on success, a Kerberos 5 error code on failure.
1339 * @ingroup krb5_storage
1342 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1343 krb5_ret_keyblock(krb5_storage
*sp
, krb5_keyblock
*p
)
1348 ret
= krb5_ret_int16(sp
, &tmp
);
1352 if(krb5_storage_is_flags(sp
, KRB5_STORAGE_KEYBLOCK_KEYTYPE_TWICE
)){
1353 ret
= krb5_ret_int16(sp
, &tmp
);
1357 ret
= krb5_ret_data(sp
, &p
->keyvalue
);
1362 * Write a times block to storage.
1364 * @param sp the storage buffer to write to
1365 * @param times the times block to write.
1367 * @return 0 on success, a Kerberos 5 error code on failure.
1369 * @ingroup krb5_storage
1372 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1373 krb5_store_times(krb5_storage
*sp
, krb5_times times
)
1376 ret
= krb5_store_int32(sp
, times
.authtime
);
1378 ret
= krb5_store_int32(sp
, times
.starttime
);
1380 ret
= krb5_store_int32(sp
, times
.endtime
);
1382 ret
= krb5_store_int32(sp
, times
.renew_till
);
1387 * Read a times block from the storage.
1389 * @param sp the storage buffer to write to
1390 * @param times the times block read from storage
1392 * @return 0 on success, a Kerberos 5 error code on failure.
1394 * @ingroup krb5_storage
1397 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1398 krb5_ret_times(krb5_storage
*sp
, krb5_times
*times
)
1403 ret
= krb5_ret_int32(sp
, &tmp
);
1404 if (ret
) return ret
;
1405 times
->authtime
= tmp
;
1406 ret
= krb5_ret_int32(sp
, &tmp
);
1407 if (ret
) return ret
;
1408 times
->starttime
= tmp
;
1409 ret
= krb5_ret_int32(sp
, &tmp
);
1410 if (ret
) return ret
;
1411 times
->endtime
= tmp
;
1412 ret
= krb5_ret_int32(sp
, &tmp
);
1413 if (ret
) return ret
;
1414 times
->renew_till
= tmp
;
1419 * Write a address block to storage.
1421 * @param sp the storage buffer to write to
1422 * @param p the address block to write.
1424 * @return 0 on success, a Kerberos 5 error code on failure.
1426 * @ingroup krb5_storage
1429 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1430 krb5_store_address(krb5_storage
*sp
, krb5_address p
)
1433 ret
= krb5_store_int16(sp
, p
.addr_type
);
1435 ret
= krb5_store_data(sp
, p
.address
);
1440 * Read a address block from the storage.
1442 * @param sp the storage buffer to write to
1443 * @param adr the address block read from storage
1445 * @return 0 on success, a Kerberos 5 error code on failure.
1447 * @ingroup krb5_storage
1450 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1451 krb5_ret_address(krb5_storage
*sp
, krb5_address
*adr
)
1455 ret
= krb5_ret_int16(sp
, &t
);
1458 ret
= krb5_ret_data(sp
, &adr
->address
);
1463 * Write a addresses block to storage.
1465 * @param sp the storage buffer to write to
1466 * @param p the addresses block to write.
1468 * @return 0 on success, a Kerberos 5 error code on failure.
1470 * @ingroup krb5_storage
1473 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1474 krb5_store_addrs(krb5_storage
*sp
, krb5_addresses p
)
1478 ret
= krb5_store_int32(sp
, p
.len
);
1480 for(i
= 0; i
<p
.len
; i
++){
1481 ret
= krb5_store_address(sp
, p
.val
[i
]);
1488 * Read a addresses block from the storage.
1490 * @param sp the storage buffer to write to
1491 * @param adr the addresses block read from storage
1493 * @return 0 on success, a Kerberos 5 error code on failure.
1495 * @ingroup krb5_storage
1498 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1499 krb5_ret_addrs(krb5_storage
*sp
, krb5_addresses
*adr
)
1505 ret
= krb5_ret_int32(sp
, &tmp
);
1507 ret
= size_too_large_num(sp
, tmp
, sizeof(adr
->val
[0]));
1508 if (ret
) return ret
;
1510 ALLOC(adr
->val
, adr
->len
);
1511 if (adr
->val
== NULL
&& adr
->len
!= 0)
1513 for(i
= 0; i
< adr
->len
; i
++){
1514 ret
= krb5_ret_address(sp
, &adr
->val
[i
]);
1521 * Write a auth data block to storage.
1523 * @param sp the storage buffer to write to
1524 * @param auth the auth data block to write.
1526 * @return 0 on success, a Kerberos 5 error code on failure.
1528 * @ingroup krb5_storage
1531 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1532 krb5_store_authdata(krb5_storage
*sp
, krb5_authdata auth
)
1534 krb5_error_code ret
;
1536 ret
= krb5_store_int32(sp
, auth
.len
);
1538 for(i
= 0; i
< auth
.len
; i
++){
1539 ret
= krb5_store_int16(sp
, auth
.val
[i
].ad_type
);
1541 ret
= krb5_store_data(sp
, auth
.val
[i
].ad_data
);
1548 * Read a auth data from the storage.
1550 * @param sp the storage buffer to write to
1551 * @param auth the auth data block read from storage
1553 * @return 0 on success, a Kerberos 5 error code on failure.
1555 * @ingroup krb5_storage
1558 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1559 krb5_ret_authdata(krb5_storage
*sp
, krb5_authdata
*auth
)
1561 krb5_error_code ret
;
1565 ret
= krb5_ret_int32(sp
, &tmp
);
1567 ret
= size_too_large_num(sp
, tmp
, sizeof(auth
->val
[0]));
1568 if (ret
) return ret
;
1569 ALLOC_SEQ(auth
, tmp
);
1570 if (auth
->val
== NULL
&& tmp
!= 0)
1572 for(i
= 0; i
< tmp
; i
++){
1573 ret
= krb5_ret_int16(sp
, &tmp2
);
1575 auth
->val
[i
].ad_type
= tmp2
;
1576 ret
= krb5_ret_data(sp
, &auth
->val
[i
].ad_data
);
1583 bitswap32(int32_t b
)
1587 for (i
= 0; i
< 32; i
++) {
1588 r
= r
<< 1 | (b
& 1);
1595 * Write a credentials block to storage.
1597 * @param sp the storage buffer to write to
1598 * @param creds the creds block to write.
1600 * @return 0 on success, a Kerberos 5 error code on failure.
1602 * @ingroup krb5_storage
1605 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1606 krb5_store_creds(krb5_storage
*sp
, krb5_creds
*creds
)
1610 ret
= krb5_store_principal(sp
, creds
->client
);
1613 ret
= krb5_store_principal(sp
, creds
->server
);
1616 ret
= krb5_store_keyblock(sp
, creds
->session
);
1619 ret
= krb5_store_times(sp
, creds
->times
);
1622 ret
= krb5_store_int8(sp
, creds
->second_ticket
.length
!= 0); /* is_skey */
1625 ret
= krb5_store_int32(sp
, bitswap32(TicketFlags2int(creds
->flags
.b
)));
1628 ret
= krb5_store_addrs(sp
, creds
->addresses
);
1631 ret
= krb5_store_authdata(sp
, creds
->authdata
);
1634 ret
= krb5_store_data(sp
, creds
->ticket
);
1637 ret
= krb5_store_data(sp
, creds
->second_ticket
);
1642 * Read a credentials block from the storage.
1644 * @param sp the storage buffer to write to
1645 * @param creds the credentials block read from storage
1647 * @return 0 on success, a Kerberos 5 error code on failure.
1649 * @ingroup krb5_storage
1652 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1653 krb5_ret_creds(krb5_storage
*sp
, krb5_creds
*creds
)
1655 krb5_error_code ret
;
1659 memset(creds
, 0, sizeof(*creds
));
1660 ret
= krb5_ret_principal (sp
, &creds
->client
);
1661 if(ret
) goto cleanup
;
1662 ret
= krb5_ret_principal (sp
, &creds
->server
);
1663 if(ret
) goto cleanup
;
1664 ret
= krb5_ret_keyblock (sp
, &creds
->session
);
1665 if(ret
) goto cleanup
;
1666 ret
= krb5_ret_times (sp
, &creds
->times
);
1667 if(ret
) goto cleanup
;
1668 ret
= krb5_ret_int8 (sp
, &dummy8
);
1669 if(ret
) goto cleanup
;
1670 ret
= krb5_ret_int32 (sp
, &dummy32
);
1671 if(ret
) goto cleanup
;
1672 creds
->flags
.b
= int2TicketFlags(bitswap32(dummy32
));
1673 ret
= krb5_ret_addrs (sp
, &creds
->addresses
);
1674 if(ret
) goto cleanup
;
1675 ret
= krb5_ret_authdata (sp
, &creds
->authdata
);
1676 if(ret
) goto cleanup
;
1677 ret
= krb5_ret_data (sp
, &creds
->ticket
);
1678 if(ret
) goto cleanup
;
1679 ret
= krb5_ret_data (sp
, &creds
->second_ticket
);
1683 krb5_free_cred_contents(context
, creds
); /* XXX */
1689 #define SC_CLIENT_PRINCIPAL 0x0001
1690 #define SC_SERVER_PRINCIPAL 0x0002
1691 #define SC_SESSION_KEY 0x0004
1692 #define SC_TICKET 0x0008
1693 #define SC_SECOND_TICKET 0x0010
1694 #define SC_AUTHDATA 0x0020
1695 #define SC_ADDRESSES 0x0040
1698 * Write a tagged credentials block to storage.
1700 * @param sp the storage buffer to write to
1701 * @param creds the creds block to write.
1703 * @return 0 on success, a Kerberos 5 error code on failure.
1705 * @ingroup krb5_storage
1708 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1709 krb5_store_creds_tag(krb5_storage
*sp
, krb5_creds
*creds
)
1715 header
|= SC_CLIENT_PRINCIPAL
;
1717 header
|= SC_SERVER_PRINCIPAL
;
1718 if (creds
->session
.keytype
!= ETYPE_NULL
)
1719 header
|= SC_SESSION_KEY
;
1720 if (creds
->ticket
.data
)
1721 header
|= SC_TICKET
;
1722 if (creds
->second_ticket
.length
)
1723 header
|= SC_SECOND_TICKET
;
1724 if (creds
->authdata
.len
)
1725 header
|= SC_AUTHDATA
;
1726 if (creds
->addresses
.len
)
1727 header
|= SC_ADDRESSES
;
1729 ret
= krb5_store_int32(sp
, header
);
1733 if (creds
->client
) {
1734 ret
= krb5_store_principal(sp
, creds
->client
);
1739 if (creds
->server
) {
1740 ret
= krb5_store_principal(sp
, creds
->server
);
1745 if (creds
->session
.keytype
!= ETYPE_NULL
) {
1746 ret
= krb5_store_keyblock(sp
, creds
->session
);
1751 ret
= krb5_store_times(sp
, creds
->times
);
1754 ret
= krb5_store_int8(sp
, creds
->second_ticket
.length
!= 0); /* is_skey */
1758 ret
= krb5_store_int32(sp
, bitswap32(TicketFlags2int(creds
->flags
.b
)));
1762 if (creds
->addresses
.len
) {
1763 ret
= krb5_store_addrs(sp
, creds
->addresses
);
1768 if (creds
->authdata
.len
) {
1769 ret
= krb5_store_authdata(sp
, creds
->authdata
);
1774 if (creds
->ticket
.data
) {
1775 ret
= krb5_store_data(sp
, creds
->ticket
);
1780 if (creds
->second_ticket
.data
) {
1781 ret
= krb5_store_data(sp
, creds
->second_ticket
);
1790 * Read a tagged credentials block from the storage.
1792 * @param sp the storage buffer to write to
1793 * @param creds the credentials block read from storage
1795 * @return 0 on success, a Kerberos 5 error code on failure.
1797 * @ingroup krb5_storage
1800 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1801 krb5_ret_creds_tag(krb5_storage
*sp
,
1804 krb5_error_code ret
;
1806 int32_t dummy32
, header
;
1808 memset(creds
, 0, sizeof(*creds
));
1810 ret
= krb5_ret_int32 (sp
, &header
);
1811 if (ret
) goto cleanup
;
1813 if (header
& SC_CLIENT_PRINCIPAL
) {
1814 ret
= krb5_ret_principal (sp
, &creds
->client
);
1815 if(ret
) goto cleanup
;
1817 if (header
& SC_SERVER_PRINCIPAL
) {
1818 ret
= krb5_ret_principal (sp
, &creds
->server
);
1819 if(ret
) goto cleanup
;
1821 if (header
& SC_SESSION_KEY
) {
1822 ret
= krb5_ret_keyblock (sp
, &creds
->session
);
1823 if(ret
) goto cleanup
;
1825 ret
= krb5_ret_times (sp
, &creds
->times
);
1826 if(ret
) goto cleanup
;
1827 ret
= krb5_ret_int8 (sp
, &dummy8
);
1828 if(ret
) goto cleanup
;
1829 ret
= krb5_ret_int32 (sp
, &dummy32
);
1830 if(ret
) goto cleanup
;
1831 creds
->flags
.b
= int2TicketFlags(bitswap32(dummy32
));
1832 if (header
& SC_ADDRESSES
) {
1833 ret
= krb5_ret_addrs (sp
, &creds
->addresses
);
1834 if(ret
) goto cleanup
;
1836 if (header
& SC_AUTHDATA
) {
1837 ret
= krb5_ret_authdata (sp
, &creds
->authdata
);
1838 if(ret
) goto cleanup
;
1840 if (header
& SC_TICKET
) {
1841 ret
= krb5_ret_data (sp
, &creds
->ticket
);
1842 if(ret
) goto cleanup
;
1844 if (header
& SC_SECOND_TICKET
) {
1845 ret
= krb5_ret_data (sp
, &creds
->second_ticket
);
1846 if(ret
) goto cleanup
;
1852 krb5_free_cred_contents(context
, creds
); /* XXX */
1858 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1859 _krb5_ret_data_at_offset(krb5_storage
*sp
,
1864 krb5_error_code ret
;
1867 krb5_data_zero(data
);
1869 cur
= sp
->seek(sp
, 0, SEEK_CUR
);
1871 return HEIM_ERR_NOT_SEEKABLE
;
1873 size
= sp
->seek(sp
, 0, SEEK_END
);
1874 if (offset
+ length
> size
) {
1879 ret
= krb5_data_alloc(data
, length
);
1884 sp
->seek(sp
, offset
, SEEK_SET
);
1886 size
= sp
->fetch(sp
, data
->data
, length
);
1887 if (size
< 0 || (size_t)size
!= length
)
1888 return sp
->eof_code
;
1892 sp
->seek(sp
, cur
, SEEK_SET
);
1897 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1898 _krb5_ret_utf8_from_ucs2le_at_offset(krb5_storage
*sp
,
1903 krb5_error_code ret
;
1905 size_t ucs2len
= length
/ 2;
1906 uint16_t *ucs2
= NULL
;
1908 unsigned int flags
= WIND_RW_LE
;
1912 krb5_data_zero(&data
);
1914 ret
= _krb5_ret_data_at_offset(sp
, offset
, length
, &data
);
1918 ucs2
= malloc(sizeof(ucs2
[0]) * ucs2len
);
1924 ret
= wind_ucs2read(data
.data
, data
.length
, &flags
, ucs2
, &ucs2len
);
1928 ret
= wind_ucs2utf8_length(ucs2
, ucs2len
, &u8len
);
1932 u8len
+= 1; /* Add space for NUL */
1934 *utf8
= malloc(u8len
);
1935 if (*utf8
== NULL
) {
1940 ret
= wind_ucs2utf8(ucs2
, ucs2len
, *utf8
, &u8len
);
1950 krb5_data_free(&data
);
1955 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
1956 _krb5_store_data_at_offset(krb5_storage
*sp
,
1958 const krb5_data
*data
)
1960 krb5_error_code ret
;
1961 krb5_ssize_t nbytes
;
1964 if (offset
== (size_t)-1) {
1965 if (data
== NULL
|| data
->data
== NULL
) {
1968 pos
= sp
->seek(sp
, 0, SEEK_CUR
);
1969 offset
= sp
->seek(sp
, 0, SEEK_END
);
1970 sp
->seek(sp
, pos
, SEEK_SET
);
1972 if (offset
== (size_t)-1)
1973 return HEIM_ERR_NOT_SEEKABLE
;
1977 if (offset
> 0xFFFF)
1979 else if ((offset
!= 0) != (data
&& data
->data
))
1981 else if (data
&& data
->length
> 0xFFFF)
1984 ret
= krb5_store_uint16(sp
, data
? (uint16_t)data
->length
: 0);
1986 ret
= krb5_store_uint16(sp
, (uint16_t)offset
);
1987 if (ret
== 0 && offset
) {
1988 pos
= sp
->seek(sp
, 0, SEEK_CUR
);
1989 sp
->seek(sp
, offset
, SEEK_SET
);
1990 nbytes
= krb5_storage_write(sp
, data
->data
, data
->length
);
1991 if ((size_t)nbytes
!= data
->length
)
1993 sp
->seek(sp
, pos
, SEEK_SET
);
1999 KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
2000 _krb5_store_utf8_as_ucs2le_at_offset(krb5_storage
*sp
,
2004 krb5_error_code ret
;
2005 size_t ucs2_len
, ucs2le_size
;
2006 uint16_t *ucs2
, *ucs2le
;
2010 ret
= wind_utf8ucs2_length(utf8
, &ucs2_len
);
2014 ucs2
= malloc(sizeof(ucs2
[0]) * ucs2_len
);
2018 ret
= wind_utf8ucs2(utf8
, ucs2
, &ucs2_len
);
2024 ucs2le_size
= (ucs2_len
+ 1) * 2;
2025 ucs2le
= malloc(ucs2le_size
);
2026 if (ucs2le
== NULL
) {
2032 ret
= wind_ucs2write(ucs2
, ucs2_len
, &flags
, ucs2le
, &ucs2le_size
);
2039 ucs2le_size
= ucs2_len
* 2;
2050 data
.length
= ucs2le_size
;
2052 ret
= _krb5_store_data_at_offset(sp
, offset
, &data
);