int length = src->length;
if (flags & KRB5_PRINCIPAL_UNPARSE_DISPLAY) {
- memcpy(dest, src->data, src->length);
+ if (src->length > 0)
+ memcpy(dest, src->data, src->length);
return src->length;
}
*q++ = '\\';
*q++ = 'b';
break;
-#if 0
- /* Heimdal escapes spaces in principal names upon unparsing */
- case ' ':
- *q++ = '\\';
- *q++ = ' ';
- break;
-#endif
case '\0':
*q++ = '\\';
*q++ = '0';
int flags, char **name, unsigned int *size)
{
char *q;
- int i;
- krb5_int32 nelem;
+ krb5_int32 i;
unsigned int totalsize = 0;
char *default_realm = NULL;
krb5_error_code ret = 0;
if (ret != 0)
goto cleanup;
- krb5_princ_realm(context, &p)->length = strlen(default_realm);
- krb5_princ_realm(context, &p)->data = default_realm;
+ p.realm = string2data(default_realm);
if (krb5_realm_compare(context, &p, principal))
flags |= KRB5_PRINCIPAL_UNPARSE_NO_REALM;
}
if ((flags & KRB5_PRINCIPAL_UNPARSE_NO_REALM) == 0) {
- totalsize += component_length_quoted(krb5_princ_realm(context,
- principal),
- flags);
+ totalsize += component_length_quoted(&principal->realm, flags);
totalsize++; /* This is for the separator */
}
- nelem = krb5_princ_size(context, principal);
- for (i = 0; i < (int) nelem; i++) {
- totalsize += component_length_quoted(krb5_princ_component(context, principal, i), flags);
+ for (i = 0; i < principal->length; i++) {
+ totalsize += component_length_quoted(&principal->data[i], flags);
totalsize++; /* This is for the separator */
}
- if (nelem == 0)
+ if (principal->length == 0)
totalsize++;
/*
* Allocate space for the ascii string; if space has been
* provided, use it, realloc'ing it if necessary.
*
- * We need only n-1 seperators for n components, but we need
+ * We need only n-1 separators for n components, but we need
* an extra byte for the NUL at the end.
*/
if (size) {
q = *name;
- for (i = 0; i < (int) nelem; i++) {
- q += copy_component_quoting(q,
- krb5_princ_component(context,
- principal,
- i),
- flags);
+ for (i = 0; i < principal->length; i++) {
+ q += copy_component_quoting(q, &principal->data[i], flags);
*q++ = COMPONENT_SEP;
}
q--; /* Back up last component separator */
if ((flags & KRB5_PRINCIPAL_UNPARSE_NO_REALM) == 0) {
*q++ = REALM_SEP;
- q += copy_component_quoting(q, krb5_princ_realm(context, principal), flags);
+ q += copy_component_quoting(q, &principal->realm, flags);
}
*q++ = '\0';
}
krb5_error_code KRB5_CALLCONV
-krb5_unparse_name(krb5_context context, krb5_const_principal principal, register char **name)
+krb5_unparse_name(krb5_context context, krb5_const_principal principal,
+ char **name)
{
if (name != NULL) /* name == NULL will return error from _ext */
*name = NULL;