Replace contents with keyvalue. Prepare for use of asn1-types.

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@1890 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Johan Danielsson
1997-06-10 14:25:15 +00:00
parent b03ed317ba
commit de43cd185b
11 changed files with 342 additions and 75 deletions

View File

@@ -65,10 +65,10 @@ krb5_kt_read_service_key(krb5_context context,
return r;
*key = malloc(sizeof(**key));
(*key)->keytype = entry.keyblock.keytype;
(*key)->contents.length = 0;
(*key)->contents.data = NULL;
krb5_data_copy(&(*key)->contents, entry.keyblock.contents.data,
entry.keyblock.contents.length);
(*key)->keyvalue.length = 0;
(*key)->keyvalue.data = NULL;
krb5_data_copy(&(*key)->keyvalue, entry.keyblock.keyvalue.data,
entry.keyblock.keyvalue.length);
krb5_kt_close (context, keytab);
return r;
@@ -172,6 +172,22 @@ krb5_kt_ret_data(krb5_storage *sp,
return 0;
}
static krb5_error_code
krb5_kt_ret_string(krb5_storage *sp,
general_string *data)
{
int ret;
int16_t size;
ret = krb5_ret_int16(sp, &size);
if(ret)
return ret;
*data = malloc(size + 1);
ret = sp->fetch(sp, *data, size);
if(ret != size)
return (ret < 0)? errno : KRB5_CC_END;
return 0;
}
static krb5_error_code
krb5_kt_ret_principal(krb5_storage *sp,
krb5_principal *princ)
@@ -186,12 +202,27 @@ krb5_kt_ret_principal(krb5_storage *sp,
return ENOMEM;
p->type = KRB5_NT_SRV_HST;
ret = krb5_ret_int16(sp, &tmp);
if(ret) return ret;
p->ncomp = tmp;
ret = krb5_kt_ret_data(sp, &p->realm);
#ifdef USE_ASN1_PRINCIPAL
p->name.name_type = KRB5_NT_SRV_HST;
p->name.name_string.len = tmp;
ret = krb5_kt_ret_string(sp, &p->realm);
if(ret) return ret;
p->name.name_string.val = calloc(p->name.name_string.len,
sizeof(*p->name.name_string.val));
if(p->name.name_string.val == NULL)
return ENOMEM;
for(i = 0; i < p->name.name_string.len; i++){
ret = krb5_kt_ret_string(sp, p->name.name_string.val + i);
if(ret) return ret;
}
#else
p->type = KRB5_NT_SRV_HST;
p->ncomp = tmp;
ret = krb5_kt_ret_data(sp, &realm);
if(ret) return ret;
p->realm = realm;
p->comp = ALLOC(p->ncomp, krb5_data);
if(p->comp == NULL){
return ENOMEM;
@@ -200,6 +231,7 @@ krb5_kt_ret_principal(krb5_storage *sp,
ret = krb5_kt_ret_data(sp, &p->comp[i]);
if(ret) return ret;
}
#endif
*princ = p;
return 0;
}
@@ -213,7 +245,7 @@ krb5_kt_ret_keyblock(krb5_storage *sp, krb5_keyblock *p)
ret = krb5_ret_int16(sp, &tmp); /* keytype + etype */
if(ret) return ret;
p->keytype = tmp;
ret = krb5_kt_ret_data(sp, &p->contents);
ret = krb5_kt_ret_data(sp, &p->keyvalue);
return ret;
}
@@ -234,6 +266,24 @@ krb5_kt_store_data(krb5_storage *sp,
return 0;
}
static krb5_error_code
krb5_kt_store_string(krb5_storage *sp,
general_string data)
{
int ret;
size_t len = strlen(data);
ret = krb5_store_int16(sp, len);
if(ret < 0)
return ret;
ret = sp->store(sp, data, len);
if(ret != len){
if(ret < 0)
return errno;
return KRB5_CC_END;
}
return 0;
}
static krb5_error_code
krb5_kt_store_keyblock(krb5_storage *sp,
krb5_keyblock *p)
@@ -242,7 +292,7 @@ krb5_kt_store_keyblock(krb5_storage *sp,
ret = krb5_store_int16(sp, p->keytype); /* keytype + etype */
if(ret) return ret;
ret = krb5_kt_store_data(sp, p->contents);
ret = krb5_kt_store_data(sp, p->keyvalue);
return ret;
}
@@ -255,14 +305,25 @@ krb5_kt_store_principal(krb5_storage *sp,
int ret;
int16_t tmp;
#ifdef USE_ASN1_PRINCIPAL
ret = krb5_store_int16(sp, p->name.name_string.len);
if(ret) return ret;
ret = krb5_kt_store_string(sp, p->realm);
if(ret) return ret;
for(i = 0; i < p->name.name_string.len; i++){
ret = krb5_kt_store_string(sp, p->name.name_string.val[i]);
if(ret) return ret;
}
#else
ret = krb5_store_int16(sp, p->ncomp);
if(ret) return ret;
ret = krb5_kt_store_data(sp, p->realm);
ret = krb5_kt_store_string(sp, p->realm);
if(ret) return ret;
for(i = 0; i < p->ncomp; i++){
ret = krb5_kt_store_data(sp, p->comp[i]);
if(ret) return ret;
}
#endif
return 0;
}
@@ -292,7 +353,11 @@ krb5_kt_add_entry(krb5_context context,
if (ret) return ret;
ret = krb5_kt_store_principal (sp, entry->principal);
if (ret) return ret;
#ifdef USE_ASN1_PRINCIPAL
ret = krb5_store_int32 (sp, entry->principal->name.name_type);
#else
ret = krb5_store_int32 (sp, entry->principal->type);
#endif
if (ret) return ret;
ret = krb5_store_int32 (sp, time(NULL));
if (ret) return ret;
@@ -322,7 +387,11 @@ krb5_kt_next_entry(krb5_context context,
ret = krb5_kt_ret_principal (cursor->sp, &entry->principal);
if (ret)
return ret;
#ifdef USE_ASN1_PRINCIPAL
ret = krb5_ret_int32(cursor->sp, &entry->principal->name.name_type);
#else
ret = krb5_ret_int32(cursor->sp, &entry->principal->type);
#endif
if (ret)
return ret;
ret = krb5_ret_int32(cursor->sp, &timestamp);