krb5_error_code
krb5int_copy_data_contents (krb5_context, const krb5_data *, krb5_data *);
+krb5_error_code
+krb5int_copy_data_contents_add0 (krb5_context, const krb5_data *, krb5_data *);
+
krb5_error_code
krb5int_copy_creds_contents (krb5_context, const krb5_creds *, krb5_creds *);
/*
* lib/kdb/kdb_cpw.c
*
- * Copyright 1995 by the Massachusetts Institute of Technology.
+ * Copyright 1995, 2009 by the Massachusetts Institute of Technology.
* All Rights Reserved.
*
* Export of this software from the United States of America may
key_salt.data.length = 0;
key_salt.data.data = 0;
break;
- case KRB5_KDB_SALTTYPE_AFS3: {
-#if 0
- krb5_data * saltdata;
- if (retval = krb5_copy_data(context, krb5_princ_realm(context,
- db_entry->princ), &saltdata))
- return(retval);
-
- key_salt.data = *saltdata;
+ case KRB5_KDB_SALTTYPE_AFS3:
+ /* The afs_mit_string_to_key needs to use strlen, and the
+ realm field is not (necessarily) NULL terminated. */
+ retval = krb5int_copy_data_contents_add0(context,
+ krb5_princ_realm(context,
+ db_entry->princ),
+ &key_salt.data);
+ if (retval)
+ return retval;
key_salt.data.length = SALT_TYPE_AFS_LENGTH; /*length actually used below...*/
- free(saltdata);
-#else
- /* Why do we do this? Well, the afs_mit_string_to_key needs to
- use strlen, and the realm is not NULL terminated.... */
- unsigned int slen =
- (*krb5_princ_realm(context,db_entry->princ)).length;
- if(!(key_salt.data.data = (char *) malloc(slen+1)))
- return ENOMEM;
- key_salt.data.data[slen] = 0;
- memcpy(key_salt.data.data,
- (*krb5_princ_realm(context,db_entry->princ)).data,
- slen);
- key_salt.data.length = SALT_TYPE_AFS_LENGTH; /*length actually used below...*/
-#endif
-
- }
- break;
+ break;
default:
return(KRB5_KDB_BAD_SALTTYPE);
}
/*
* lib/krb5/krb/bld_pr_ext.c
*
- * Copyright 1991, 2008 by the Massachusetts Institute of Technology.
+ * Copyright 1991, 2008, 2009 by the Massachusetts Institute of Technology.
* All Rights Reserved.
*
* Export of this software from the United States of America may
unsigned int rlen, const char * realm, ...)
{
va_list ap;
- register int i, count = 0;
- register unsigned int size;
- register char *next;
- char *tmpdata = 0;
+ int i, count = 0;
krb5_data *princ_data;
krb5_principal princ_ret;
+ krb5_data tmpdata;
va_start(ap, realm);
/* count up */
}
princ_ret->data = princ_data;
princ_ret->length = count;
- tmpdata = malloc(rlen+1);
- if (!tmpdata) {
+ tmpdata.length = rlen;
+ tmpdata.data = (char *) realm;
+ if (krb5int_copy_data_contents_add0(context, &tmpdata, &princ_ret->realm) != 0) {
free(princ_data);
free(princ_ret);
return ENOMEM;
}
- krb5_princ_set_realm_length(context, princ_ret, rlen);
- krb5_princ_set_realm_data(context, princ_ret, tmpdata);
- memcpy(tmpdata, realm, rlen);
- tmpdata[rlen] = 0;
/* process rest of components */
va_start(ap, realm);
for (i = 0; i < count; i++) {
- size = va_arg(ap, unsigned int);
- next = va_arg(ap, char *);
- princ_data[i].length = size;
- princ_data[i].data = malloc(size+1);
- if (!princ_data[i].data)
+ tmpdata.length = va_arg(ap, unsigned int);
+ tmpdata.data = va_arg(ap, char *);
+ if (krb5int_copy_data_contents_add0(context, &tmpdata,
+ &princ_data[i]) != 0)
goto free_out;
- memcpy(princ_data[i].data, next, size);
- princ_data[i].data[size] = 0;
}
va_end(ap);
*princ = princ_ret;
while (--i >= 0)
free(princ_data[i].data);
free(princ_data);
+ free(princ_ret->realm.data);
free(princ_ret);
- free(tmpdata);
va_end(ap);
return ENOMEM;
}
/*
* lib/krb5/krb/copy_data.c
*
- * Copyright 1990,1991 by the Massachusetts Institute of Technology.
+ * Copyright 1990,1991,2009 by the Massachusetts Institute of Technology.
* All Rights Reserved.
*
* Export of this software from the United States of America may
return 0;
}
+
+/* As above, but add an (uncounted) extra byte at the end to
+ null-terminate the data so it can be used as a standard C
+ string. */
+krb5_error_code
+krb5int_copy_data_contents_add0(krb5_context context, const krb5_data *indata, krb5_data *outdata)
+{
+ if (!indata)
+ return EINVAL;
+ outdata->length = indata->length;
+ if (!(outdata->data = malloc(outdata->length + 1)))
+ return ENOMEM;
+ if (outdata->length)
+ memcpy(outdata->data, indata->data, outdata->length);
+ outdata->data[outdata->length] = 0;
+ outdata->magic = KV5M_DATA;
+
+ return 0;
+}
/*
* lib/krb5/krb/copy_princ.c
*
- * Copyright 1990 by the Massachusetts Institute of Technology.
+ * Copyright 1990, 2009 by the Massachusetts Institute of Technology.
* All Rights Reserved.
*
* Export of this software from the United States of America may
}
for (i = 0; i < nelems; i++) {
- unsigned int len = krb5_princ_component(context, inprinc, i)->length;
- krb5_princ_component(context, tempprinc, i)->length = len;
- if (len) {
- if (((krb5_princ_component(context, tempprinc, i)->data =
- malloc(len)) == 0)) {
- while (--i >= 0)
- free(krb5_princ_component(context, tempprinc, i)->data);
- free (tempprinc->data);
- free (tempprinc);
- return ENOMEM;
- }
- memcpy(krb5_princ_component(context, tempprinc, i)->data,
- krb5_princ_component(context, inprinc, i)->data, len);
- } else
- krb5_princ_component(context, tempprinc, i)->data = 0;
+ if (krb5int_copy_data_contents(context,
+ krb5_princ_component(context, inprinc, i),
+ krb5_princ_component(context, tempprinc, i)) != 0) {
+ while (--i >= 0)
+ free(krb5_princ_component(context, tempprinc, i)->data);
+ free (tempprinc->data);
+ free (tempprinc);
+ return ENOMEM;
+ }
}
- tempprinc->realm.data =
- malloc((tempprinc->realm.length = inprinc->realm.length) + 1);
- if (!tempprinc->realm.data) {
+ if (krb5int_copy_data_contents_add0(context, &inprinc->realm,
+ &tempprinc->realm) != 0) {
for (i = 0; i < nelems; i++)
free(krb5_princ_component(context, tempprinc, i)->data);
free(tempprinc->data);
free(tempprinc);
return ENOMEM;
}
- memcpy(tempprinc->realm.data, inprinc->realm.data,
- inprinc->realm.length);
- tempprinc->realm.data[tempprinc->realm.length] = 0;
*outprinc = tempprinc;
return 0;
krb5int_cc_default
krb5int_cleanup_library
krb5int_cm_call_select
+krb5int_copy_data_contents_add0
krb5int_foreach_localaddr
krb5int_free_addrlist
krb5int_init_context_kdc