2 * lib/krb5/krb/bld_princ.c
4 * Copyright 1991 by the Massachusetts Institute of Technology.
7 * Export of this software from the United States of America may
8 * require a specific license from the United States Government.
9 * It is the responsibility of any person or organization contemplating
10 * export to obtain such a license before exporting.
12 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13 * distribute this software and its documentation for any purpose and
14 * without fee is hereby granted, provided that the above copyright
15 * notice appear in all copies and that both that copyright notice and
16 * this permission notice appear in supporting documentation, and that
17 * the name of M.I.T. not be used in advertising or publicity pertaining
18 * to distribution of the software without specific, written prior
19 * permission. M.I.T. makes no representations about the suitability of
20 * this software for any purpose. It is provided "as is" without express
21 * or implied warranty.
24 * Build a principal from a list of strings
27 /* Need <krb5/k5-config.h> for HAVE_STDARG_H */
36 krb5_error_code INTERFACE_C
37 krb5_build_principal_va(context, princ, rlen, realm, ap)
44 register int i, count = 0;
49 /* guess at an initial sufficent count of 2 pieces */
52 /* get space for array and realm, and insert realm */
53 data = (krb5_data *) malloc(sizeof(krb5_data) * count);
56 krb5_princ_set_realm_length(context, princ, rlen);
57 tmpdata = malloc(rlen);
62 krb5_princ_set_realm_data(context, princ, tmpdata);
63 memcpy(tmpdata, realm, rlen);
65 /* process rest of components */
67 for (i = 0, next = va_arg(ap, char *);
69 next = va_arg(ap, char *), i++) {
71 /* not big enough. realloc the array */
73 p_tmp = (krb5_data *) realloc((char *)data,
74 sizeof(krb5_data)*(count*2));
78 krb5_xfree(data[i].data);
87 data[i].length = strlen(next);
88 data[i].data = strdup(next);
94 princ->type = KRB5_NT_UNKNOWN;
95 princ->magic = KV5M_PRINCIPAL;
99 krb5_error_code INTERFACE_C
101 krb5_build_principal(krb5_context context, krb5_principal * princ, int rlen,
102 const char * realm, ...)
104 krb5_build_principal(context, princ, rlen, realm, va_alist)
105 krb5_context context;
106 krb5_principal *princ;
113 krb5_error_code retval;
114 krb5_principal pr_ret = (krb5_principal)malloc(sizeof(krb5_principal_data));
124 retval = krb5_build_principal_va(context, pr_ret, rlen, realm, ap);