krb5 commit: Simplify bld_princ.c
Greg Hudson
ghudson at MIT.EDU
Thu Jun 21 17:13:24 EDT 2012
https://github.com/krb5/krb5/commit/3fd8ac32acb5616adf0ac5d4bfcaa88cf2d4946e
commit 3fd8ac32acb5616adf0ac5d4bfcaa88cf2d4946e
Author: Greg Hudson <ghudson at mit.edu>
Date: Thu Jun 21 17:12:50 2012 -0400
Simplify bld_princ.c
src/include/k5-int.h | 9 ----
src/lib/krb5/krb/bld_princ.c | 86 ++++++++++--------------------------------
2 files changed, 20 insertions(+), 75 deletions(-)
diff --git a/src/include/k5-int.h b/src/include/k5-int.h
index 28c86f8..b1e535e 100644
--- a/src/include/k5-int.h
+++ b/src/include/k5-int.h
@@ -2471,15 +2471,6 @@ krb5_error_code krb5_use_natural_time(krb5_context);
krb5_error_code krb5_set_time_offsets(krb5_context, krb5_timestamp,
krb5_int32);
-/* Internal principal function used by KIM to avoid code duplication */
-krb5_error_code KRB5_CALLCONV
-krb5int_build_principal_alloc_va(krb5_context context,
- krb5_principal *princ,
- unsigned int rlen,
- const char *realm,
- const char *first,
- va_list ap);
-
/* Some data comparison and conversion functions. */
static inline int
data_eq(krb5_data d1, krb5_data d2)
diff --git a/src/lib/krb5/krb/bld_princ.c b/src/lib/krb5/krb/bld_princ.c
index 8c17ab3..ba411a6 100644
--- a/src/lib/krb5/krb/bld_princ.c
+++ b/src/lib/krb5/krb/bld_princ.c
@@ -27,15 +27,9 @@
#include <stdarg.h>
#include "k5-int.h"
-/* Takes first component as argument for KIM API,
- * which does not allow realms with zero components */
static krb5_error_code
-krb5int_build_principal_va(krb5_context context,
- krb5_principal princ,
- unsigned int rlen,
- const char *realm,
- const char *first,
- va_list ap)
+build_principal_va(krb5_context context, krb5_principal princ,
+ unsigned int rlen, const char *realm, va_list ap)
{
krb5_error_code retval = 0;
char *r = NULL;
@@ -52,33 +46,25 @@ krb5int_build_principal_va(krb5_context context,
if (!r) { retval = ENOMEM; }
}
- if (!retval && first) {
- data[0].length = strlen(first);
- data[0].data = strdup(first);
- if (!data[0].data) { retval = ENOMEM; }
- count++;
-
- /* ap is only valid if first is non-NULL */
- while (!retval && (component = va_arg(ap, char *))) {
- if (count == size) {
- krb5_data *new_data = NULL;
-
- size *= 2;
- new_data = realloc ((char *) data, sizeof(krb5_data) * size);
- if (new_data) {
- data = new_data;
- } else {
- retval = ENOMEM;
- }
- }
+ while (!retval && (component = va_arg(ap, char *))) {
+ if (count == size) {
+ krb5_data *new_data = NULL;
- if (!retval) {
- data[count].length = strlen(component);
- data[count].data = strdup(component);
- if (!data[count].data) { retval = ENOMEM; }
- count++;
+ size *= 2;
+ new_data = realloc(data, size * sizeof(krb5_data));
+ if (new_data) {
+ data = new_data;
+ } else {
+ retval = ENOMEM;
}
}
+
+ if (!retval) {
+ data[count].length = strlen(component);
+ data[count].data = strdup(component);
+ if (!data[count].data) { retval = ENOMEM; }
+ count++;
+ }
}
if (!retval) {
@@ -110,37 +96,7 @@ krb5_build_principal_va(krb5_context context,
const char *realm,
va_list ap)
{
- char *first = va_arg(ap, char *);
-
- return krb5int_build_principal_va(context, princ, rlen, realm, first, ap);
-}
-
-/* Takes first component as argument for KIM API,
- * which does not allow realms with zero components */
-krb5_error_code KRB5_CALLCONV
-krb5int_build_principal_alloc_va(krb5_context context,
- krb5_principal *princ,
- unsigned int rlen,
- const char *realm,
- const char *first,
- va_list ap)
-{
- krb5_error_code retval = 0;
-
- krb5_principal p = malloc(sizeof(krb5_principal_data));
- if (!p) { retval = ENOMEM; }
-
- if (!retval) {
- retval = krb5int_build_principal_va(context, p, rlen, realm, first, ap);
- }
-
- if (!retval) {
- *princ = p;
- } else {
- free(p);
- }
-
- return retval;
+ return build_principal_va(context, princ, rlen, realm, ap);
}
krb5_error_code KRB5_CALLCONV
@@ -152,14 +108,12 @@ krb5_build_principal_alloc_va(krb5_context context,
{
krb5_error_code retval = 0;
krb5_principal p;
- char *first;
p = malloc(sizeof(krb5_principal_data));
if (p == NULL)
return ENOMEM;
- first = va_arg(ap, char *);
- retval = krb5int_build_principal_va(context, p, rlen, realm, first, ap);
+ retval = build_principal_va(context, p, rlen, realm, ap);
if (retval) {
free(p);
return retval;
More information about the cvs-krb5
mailing list