Lines Matching +full:write +full:- +full:data
2 * Copyright (c) 1997-2008 Kungliga Tekniska Högskolan
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 #include "store-int.h"
37 #define BYTEORDER_IS(SP, V) (((SP)->flags & KRB5_STORAGE_BYTEORDER_MASK) == (V))
44 * Add the flags on a storage buffer by or-ing in the flags to the buffer.
55 sp->flags |= flags; in krb5_storage_set_flags()
70 sp->flags &= ~flags; in krb5_storage_clear_flags()
88 return (sp->flags & flags) == flags; in krb5_storage_is_flags()
106 sp->flags &= ~KRB5_STORAGE_BYTEORDER_MASK; in krb5_storage_set_byteorder()
107 sp->flags |= byteorder; in krb5_storage_set_byteorder()
119 return sp->flags & KRB5_STORAGE_BYTEORDER_MASK; in krb5_storage_get_byteorder()
134 sp->max_alloc = size; in krb5_storage_set_max_alloc()
141 if (sp->max_alloc && sp->max_alloc < size) in size_too_large()
149 if (sp->max_alloc == 0 || size == 0) in size_too_large_num()
151 size = sp->max_alloc / size; in size_too_large_num()
173 return (*sp->seek)(sp, offset, whence); in krb5_storage_seek()
190 return (*sp->trunc)(sp, offset); in krb5_storage_truncate()
197 * @param buf the buffer to store the data in
200 * @return The length of data read (can be shorter then len), or negative on error.
208 return sp->fetch(sp, buf, len); in krb5_storage_read()
212 * Write to the storage buffer.
214 * @param sp the storage buffer to write to
215 * @param buf the buffer to write to the storage buffer
216 * @param len the length to write
218 * @return The length of data written (can be shorter then len), or negative on error.
226 return sp->store(sp, buf, len); in krb5_storage_write()
241 sp->eof_code = code; in krb5_storage_set_eof_code()
257 return sp->eof_code; in krb5_storage_get_eof_code()
273 if(sp->free) in krb5_storage_free()
274 (*sp->free)(sp); in krb5_storage_free()
275 free(sp->data); in krb5_storage_free()
283 * @param sp the storage to copy to a data
284 * @param data the copied data, free with krb5_data_free()
292 krb5_storage_to_data(krb5_storage *sp, krb5_data *data) in krb5_storage_to_data() argument
297 pos = sp->seek(sp, 0, SEEK_CUR); in krb5_storage_to_data()
300 size = sp->seek(sp, 0, SEEK_END); in krb5_storage_to_data()
304 ret = krb5_data_alloc(data, size); in krb5_storage_to_data()
306 sp->seek(sp, pos, SEEK_SET); in krb5_storage_to_data()
310 sp->seek(sp, 0, SEEK_SET); in krb5_storage_to_data()
311 sp->fetch(sp, data->data, data->length); in krb5_storage_to_data()
312 sp->seek(sp, pos, SEEK_SET); in krb5_storage_to_data()
328 ret = sp->store(sp, v, len); in krb5_store_int()
332 return sp->eof_code; in krb5_store_int()
340 * @param sp the storage to write too
363 * @param sp the storage to write too
386 ret = sp->fetch(sp, v, len); in krb5_ret_int()
390 return sp->eof_code; in krb5_ret_int()
400 * @param sp the storage to write too
426 * @param sp the storage to write too
452 * @param sp the storage to write too
475 * @param sp the storage to write too
494 * @param sp the storage to write too
523 * @param sp the storage to write too
548 * @param sp the storage to write too
562 ret = sp->store(sp, &value, sizeof(value)); in krb5_store_int8()
564 return (ret<0)?errno:sp->eof_code; in krb5_store_int8()
571 * @param sp the storage to write too
589 * @param sp the storage to write too
603 ret = sp->fetch(sp, value, sizeof(*value)); in krb5_ret_int8()
605 return (ret<0)?errno:sp->eof_code; in krb5_ret_int8()
612 * @param sp the storage to write too
635 * Store a data to the storage. The data is stored with an int32 as
636 * lenght plus the data (not padded).
638 * @param sp the storage buffer to write to
639 * @param data the buffer to store.
648 krb5_data data) in krb5_store_data() argument
651 ret = krb5_store_int32(sp, data.length); in krb5_store_data()
654 ret = sp->store(sp, data.data, data.length); in krb5_store_data()
657 if((size_t)ret != data.length) in krb5_store_data()
658 return sp->eof_code; in krb5_store_data()
663 * Parse a data from the storage.
666 * @param data the parsed data
675 krb5_data *data) in krb5_ret_data() argument
686 ret = krb5_data_alloc (data, size); in krb5_ret_data()
690 ret = sp->fetch(sp, data->data, size); in krb5_ret_data()
692 return (ret < 0)? errno : sp->eof_code; in krb5_ret_data()
698 * Store a string to the buffer. The data is formated as an len:uint32
701 * @param sp the storage buffer to write to
712 krb5_data data; in krb5_store_string() local
713 data.length = strlen(s); in krb5_store_string()
714 data.data = rk_UNCONST(s); in krb5_store_string()
715 return krb5_store_data(sp, data); in krb5_store_string()
735 krb5_data data; in krb5_ret_string() local
736 ret = krb5_ret_data(sp, &data); in krb5_ret_string()
739 *string = realloc(data.data, data.length + 1); in krb5_ret_string()
741 free(data.data); in krb5_ret_string()
744 (*string)[data.length] = 0; in krb5_ret_string()
749 * Store a zero terminated string to the buffer. The data is stored
752 * @param sp the storage buffer to write to
766 ret = sp->store(sp, s, len); in krb5_store_stringz()
770 return sp->eof_code; in krb5_store_stringz()
794 while((ret = sp->fetch(sp, &c, 1)) == 1){ in krb5_ret_stringz()
807 s[len - 1] = c; in krb5_ret_stringz()
814 return sp->eof_code; in krb5_ret_stringz()
827 ret = sp->store(sp, s, len); in krb5_store_stringnl()
831 return sp->eof_code; in krb5_store_stringnl()
832 ret = sp->store(sp, "\n", 1); in krb5_store_stringnl()
837 return sp->eof_code; in krb5_store_stringnl()
854 while((ret = sp->fetch(sp, &c, 1)) == 1){ in krb5_ret_stringnl()
877 s[len - 1] = '\0'; in krb5_ret_stringnl()
880 s[len - 1] = c; in krb5_ret_stringnl()
885 return sp->eof_code; in krb5_ret_stringnl()
893 * Write a principal block to storage.
895 * @param sp the storage buffer to write to
896 * @param p the principal block to write.
911 ret = krb5_store_int32(sp, p->name.name_type); in krb5_store_principal()
915 ret = krb5_store_int32(sp, p->name.name_string.len + 1); in krb5_store_principal()
917 ret = krb5_store_int32(sp, p->name.name_string.len); in krb5_store_principal()
920 ret = krb5_store_string(sp, p->realm); in krb5_store_principal()
922 for(i = 0; i < p->name.name_string.len; i++){ in krb5_store_principal()
923 ret = krb5_store_string(sp, p->name.name_string.val[i]); in krb5_store_principal()
965 ncomp--; in krb5_ret_principal()
970 ret = size_too_large_num(sp, ncomp, sizeof(p->name.name_string.val[0])); in krb5_ret_principal()
975 p->name.name_type = type; in krb5_ret_principal()
976 p->name.name_string.len = ncomp; in krb5_ret_principal()
977 ret = krb5_ret_string(sp, &p->realm); in krb5_ret_principal()
982 p->name.name_string.val = calloc(ncomp, sizeof(p->name.name_string.val[0])); in krb5_ret_principal()
983 if(p->name.name_string.val == NULL && ncomp != 0){ in krb5_ret_principal()
984 free(p->realm); in krb5_ret_principal()
989 ret = krb5_ret_string(sp, &p->name.name_string.val[i]); in krb5_ret_principal()
992 free(p->name.name_string.val[i--]); in krb5_ret_principal()
993 free(p->realm); in krb5_ret_principal()
1005 * @param sp the storage buffer to write to
1006 * @param p the keyblock to write
1034 * @param sp the storage buffer to write to
1050 p->keytype = tmp; in krb5_ret_keyblock()
1057 ret = krb5_ret_data(sp, &p->keyvalue); in krb5_ret_keyblock()
1062 * Write a times block to storage.
1064 * @param sp the storage buffer to write to
1065 * @param times the times block to write.
1089 * @param sp the storage buffer to write to
1103 times->authtime = tmp; in krb5_ret_times()
1106 times->starttime = tmp; in krb5_ret_times()
1109 times->endtime = tmp; in krb5_ret_times()
1112 times->renew_till = tmp; in krb5_ret_times()
1117 * Write a address block to storage.
1119 * @param sp the storage buffer to write to
1120 * @param p the address block to write.
1140 * @param sp the storage buffer to write to
1155 adr->addr_type = t; in krb5_ret_address()
1156 ret = krb5_ret_data(sp, &adr->address); in krb5_ret_address()
1161 * Write a addresses block to storage.
1163 * @param sp the storage buffer to write to
1164 * @param p the addresses block to write.
1188 * @param sp the storage buffer to write to
1205 ret = size_too_large_num(sp, tmp, sizeof(adr->val[0])); in krb5_ret_addrs()
1207 adr->len = tmp; in krb5_ret_addrs()
1208 ALLOC(adr->val, adr->len); in krb5_ret_addrs()
1209 if (adr->val == NULL && adr->len != 0) in krb5_ret_addrs()
1211 for(i = 0; i < adr->len; i++){ in krb5_ret_addrs()
1212 ret = krb5_ret_address(sp, &adr->val[i]); in krb5_ret_addrs()
1219 * Write a auth data block to storage.
1221 * @param sp the storage buffer to write to
1222 * @param auth the auth data block to write.
1246 * Read a auth data from the storage.
1248 * @param sp the storage buffer to write to
1249 * @param auth the auth data block read from storage
1265 ret = size_too_large_num(sp, tmp, sizeof(auth->val[0])); in krb5_ret_authdata()
1268 if (auth->val == NULL && tmp != 0) in krb5_ret_authdata()
1273 auth->val[i].ad_type = tmp2; in krb5_ret_authdata()
1274 ret = krb5_ret_data(sp, &auth->val[i].ad_data); in krb5_ret_authdata()
1293 * Write a credentials block to storage.
1295 * @param sp the storage buffer to write to
1296 * @param creds the creds block to write.
1308 ret = krb5_store_principal(sp, creds->client); in krb5_store_creds()
1311 ret = krb5_store_principal(sp, creds->server); in krb5_store_creds()
1314 ret = krb5_store_keyblock(sp, creds->session); in krb5_store_creds()
1317 ret = krb5_store_times(sp, creds->times); in krb5_store_creds()
1320 ret = krb5_store_int8(sp, creds->second_ticket.length != 0); /* is_skey */ in krb5_store_creds()
1325 ret = krb5_store_int32(sp, creds->flags.i); in krb5_store_creds()
1327 ret = krb5_store_int32(sp, bitswap32(TicketFlags2int(creds->flags.b))); in krb5_store_creds()
1331 ret = krb5_store_addrs(sp, creds->addresses); in krb5_store_creds()
1334 ret = krb5_store_authdata(sp, creds->authdata); in krb5_store_creds()
1337 ret = krb5_store_data(sp, creds->ticket); in krb5_store_creds()
1340 ret = krb5_store_data(sp, creds->second_ticket); in krb5_store_creds()
1347 * @param sp the storage buffer to write to
1363 ret = krb5_ret_principal (sp, &creds->client); in krb5_ret_creds()
1365 ret = krb5_ret_principal (sp, &creds->server); in krb5_ret_creds()
1367 ret = krb5_ret_keyblock (sp, &creds->session); in krb5_ret_creds()
1369 ret = krb5_ret_times (sp, &creds->times); in krb5_ret_creds()
1377 * any of the higher bits are set in the input data, it's either a in krb5_ret_creds()
1384 creds->flags.i = 0; in krb5_ret_creds()
1385 creds->flags.b.anonymous = 1; in krb5_ret_creds()
1386 if (creds->flags.i & mask) in krb5_ret_creds()
1391 creds->flags.i = dummy32; in krb5_ret_creds()
1392 ret = krb5_ret_addrs (sp, &creds->addresses); in krb5_ret_creds()
1394 ret = krb5_ret_authdata (sp, &creds->authdata); in krb5_ret_creds()
1396 ret = krb5_ret_data (sp, &creds->ticket); in krb5_ret_creds()
1398 ret = krb5_ret_data (sp, &creds->second_ticket); in krb5_ret_creds()
1417 * Write a tagged credentials block to storage.
1419 * @param sp the storage buffer to write to
1420 * @param creds the creds block to write.
1433 if (creds->client) in krb5_store_creds_tag()
1435 if (creds->server) in krb5_store_creds_tag()
1437 if (creds->session.keytype != ETYPE_NULL) in krb5_store_creds_tag()
1439 if (creds->ticket.data) in krb5_store_creds_tag()
1441 if (creds->second_ticket.length) in krb5_store_creds_tag()
1443 if (creds->authdata.len) in krb5_store_creds_tag()
1445 if (creds->addresses.len) in krb5_store_creds_tag()
1452 if (creds->client) { in krb5_store_creds_tag()
1453 ret = krb5_store_principal(sp, creds->client); in krb5_store_creds_tag()
1458 if (creds->server) { in krb5_store_creds_tag()
1459 ret = krb5_store_principal(sp, creds->server); in krb5_store_creds_tag()
1464 if (creds->session.keytype != ETYPE_NULL) { in krb5_store_creds_tag()
1465 ret = krb5_store_keyblock(sp, creds->session); in krb5_store_creds_tag()
1470 ret = krb5_store_times(sp, creds->times); in krb5_store_creds_tag()
1473 ret = krb5_store_int8(sp, creds->second_ticket.length != 0); /* is_skey */ in krb5_store_creds_tag()
1477 ret = krb5_store_int32(sp, bitswap32(TicketFlags2int(creds->flags.b))); in krb5_store_creds_tag()
1481 if (creds->addresses.len) { in krb5_store_creds_tag()
1482 ret = krb5_store_addrs(sp, creds->addresses); in krb5_store_creds_tag()
1487 if (creds->authdata.len) { in krb5_store_creds_tag()
1488 ret = krb5_store_authdata(sp, creds->authdata); in krb5_store_creds_tag()
1493 if (creds->ticket.data) { in krb5_store_creds_tag()
1494 ret = krb5_store_data(sp, creds->ticket); in krb5_store_creds_tag()
1499 if (creds->second_ticket.data) { in krb5_store_creds_tag()
1500 ret = krb5_store_data(sp, creds->second_ticket); in krb5_store_creds_tag()
1511 * @param sp the storage buffer to write to
1533 ret = krb5_ret_principal (sp, &creds->client); in krb5_ret_creds_tag()
1537 ret = krb5_ret_principal (sp, &creds->server); in krb5_ret_creds_tag()
1541 ret = krb5_ret_keyblock (sp, &creds->session); in krb5_ret_creds_tag()
1544 ret = krb5_ret_times (sp, &creds->times); in krb5_ret_creds_tag()
1552 * any of the higher bits are set in the input data, it's either a in krb5_ret_creds_tag()
1559 creds->flags.i = 0; in krb5_ret_creds_tag()
1560 creds->flags.b.anonymous = 1; in krb5_ret_creds_tag()
1561 if (creds->flags.i & mask) in krb5_ret_creds_tag()
1566 creds->flags.i = dummy32; in krb5_ret_creds_tag()
1568 ret = krb5_ret_addrs (sp, &creds->addresses); in krb5_ret_creds_tag()
1572 ret = krb5_ret_authdata (sp, &creds->authdata); in krb5_ret_creds_tag()
1576 ret = krb5_ret_data (sp, &creds->ticket); in krb5_ret_creds_tag()
1580 ret = krb5_ret_data (sp, &creds->second_ticket); in krb5_ret_creds_tag()