Add krb5_storage_from_readonly_mem that is safe to use on
const/readonly buffers (it doesn't support write). git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@18948 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -64,6 +64,12 @@ mem_store(krb5_storage *sp, const void *data, size_t size)
|
||||
return size;
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
mem_no_store(krb5_storage *sp, const void *data, size_t size)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
static off_t
|
||||
mem_seek(krb5_storage *sp, off_t offset, int whence)
|
||||
{
|
||||
@@ -117,3 +123,28 @@ krb5_storage_from_data(krb5_data *data)
|
||||
{
|
||||
return krb5_storage_from_mem(data->data, data->length);
|
||||
}
|
||||
|
||||
krb5_storage * KRB5_LIB_FUNCTION
|
||||
krb5_storage_from_readonly_mem(const void *buf, size_t len)
|
||||
{
|
||||
krb5_storage *sp = malloc(sizeof(krb5_storage));
|
||||
mem_storage *s;
|
||||
if(sp == NULL)
|
||||
return NULL;
|
||||
s = malloc(sizeof(*s));
|
||||
if(s == NULL) {
|
||||
free(sp);
|
||||
return NULL;
|
||||
}
|
||||
sp->data = s;
|
||||
sp->flags = 0;
|
||||
sp->eof_code = HEIM_ERR_EOF;
|
||||
s->base = rk_UNCONST(buf);
|
||||
s->size = len;
|
||||
s->ptr = rk_UNCONST(buf);
|
||||
sp->fetch = mem_fetch;
|
||||
sp->store = mem_no_store;
|
||||
sp->seek = mem_seek;
|
||||
sp->free = NULL;
|
||||
return sp;
|
||||
}
|
||||
|
Reference in New Issue
Block a user