5 * Copyright 1991 by the Massachusetts Institute of Technology.
8 * For copying and distribution information, please see the file
11 * Build a principal from a list of strings
14 #if !defined(lint) && !defined(SABER)
15 static char rcsid_bld_princ_c [] =
17 #endif /* !lint & !SABER */
19 #include <krb5/krb5.h>
20 #include <krb5/ext-proto.h>
30 krb5_build_principal(krb5_principal *princ, int rlen, const char *realm, ...)
32 krb5_build_principal(princ, rlen, realm, va_alist)
33 krb5_principal *princ;
40 krb5_error_code retval;
47 retval = krb5_build_principal_va(princ, realm, ap);
53 krb5_build_principal_va(princ, rlen, realm, ap)
54 krb5_principal *princ;
59 register int i, count = 0;
61 krb5_principal princ_ret;
63 /* guess at an initial sufficent count of 2 pieces */
64 count = 2 + 2; /* plus 2 for realm & null terminator */
66 /* get space for array and realm, and insert realm */
67 princ_ret = (krb5_principal) malloc(sizeof(*princ_ret) * (count));
70 if (!(princ_ret[0] = (krb5_data *) malloc(sizeof(*princ_ret[0])))) {
74 princ_ret[0]->length = rlen;
75 princ_ret[0]->data = malloc(rlen);
76 if (!princ_ret[0]->data) {
81 memcpy(princ_ret[0]->data, realm, rlen);
83 /* process rest of components */
85 for (i = 1, next = va_arg(ap, char *);
87 next = va_arg(ap, char *), i++) {
89 /* not big enough. realloc the array */
91 p_tmp = (krb5_principal) realloc((char *)princ_ret, sizeof(*princ_ret)*(count*2));
98 (krb5_data *) malloc(sizeof(*princ_ret[i])))) {
100 for (i--; i >= 0; i--) {
101 xfree(princ_ret[i]->data);
107 princ_ret[i]->length = strlen(next);
108 princ_ret[i]->data = strdup(next);
109 if (!princ_ret[i]->data) {
114 princ_ret[i] = 0; /* put a null as the last entry */