va_list ap;
register int i, count = 0, size;
register char *next;
+ char *tmpdata;
+ krb5_data *princ_data;
krb5_principal princ_ret;
#if __STDC__ || defined(STDARG_PROTOTYPES)
#endif
/* count up */
while (va_arg(ap, int) != 0) {
- va_arg(ap, char *); /* pass one up */
+ (void)va_arg(ap, char *); /* pass one up */
count++;
}
va_end(ap);
/* we do a 2-pass to avoid the need to guess on allocation needs
cf. bld_princ.c */
- /* get space for array and realm, and insert realm */
- princ_ret = (krb5_principal) malloc(sizeof(*princ_ret) * (count + 2));
- if (!princ_ret)
+ /* get space for array */
+ princ_data = (krb5_data *) malloc(sizeof(krb5_data) * count);
+ if (!princ_data)
return ENOMEM;
- if (!(princ_ret[0] = (krb5_data *) malloc(sizeof(*princ_ret[0])))) {
- xfree(princ_ret);
+ princ_ret = (krb5_principal) malloc(sizeof(krb5_principal_data));
+ if (!princ_ret) {
+ xfree(princ_data);
return ENOMEM;
}
- princ_ret[0]->length = rlen;
- princ_ret[0]->data = malloc(rlen);
- if (!princ_ret[0]->data) {
- xfree(princ_ret[0]);
+ princ_ret->data = princ_data;
+ princ_ret->length = count;
+ tmpdata = malloc(rlen);
+ if (!tmpdata) {
+ xfree(princ_data);
xfree(princ_ret);
return ENOMEM;
}
- memcpy(princ_ret[0]->data, realm, rlen);
+ krb5_princ_set_realm_length(princ_ret, rlen);
+ krb5_princ_set_realm_data(princ_ret, tmpdata);
+ memcpy(tmpdata, realm, rlen);
/* process rest of components */
#if __STDC__ || defined(STDARG_PROTOTYPES)
#else
va_start(ap);
#endif
- for (i = 1; i <= count; i++) {
- if (!(princ_ret[i] =
- (krb5_data *) malloc(sizeof(*princ_ret[i])))) {
- free_out:
- for (i--; i >= 0; i--) {
- xfree(princ_ret[i]->data);
- xfree(princ_ret[i]);
- }
- xfree(princ_ret);
- va_end(ap);
- return (ENOMEM);
- }
+ for (i = 0; i < count; i++) {
size = va_arg(ap, int);
next = va_arg(ap, char *);
- princ_ret[i]->length = size;
- princ_ret[i]->data = malloc(size);
- if (!princ_ret[i]->data) {
- xfree(princ_ret[i]);
+ princ_data[i].length = size;
+ princ_data[i].data = malloc(size);
+ if (!princ_data[i].data)
goto free_out;
- }
- memcpy(princ_ret[i]->data, next, size);
+ memcpy(princ_data[i].data, next, size);
}
- princ_ret[count+1] = 0;
va_end(ap);
*princ = princ_ret;
return 0;
+
+free_out:
+ while (i-- >= 0)
+ xfree(princ_data[i].data);
+ xfree(princ_data);
+ xfree(princ_ret);
+ va_end(ap);
+ return ENOMEM;
}
krb5_error_code
krb5_build_principal_va(princ, rlen, realm, ap)
-krb5_principal *princ;
+krb5_principal princ;
int rlen;
const char *realm;
va_list ap;
{
register int i, count = 0;
register char *next;
- krb5_principal princ_ret;
+ char *tmpdata;
+ krb5_data *data;
/* guess at an initial sufficent count of 2 pieces */
- count = 2 + 2; /* plus 2 for realm & null terminator */
+ count = 2;
/* get space for array and realm, and insert realm */
- princ_ret = (krb5_principal) malloc(sizeof(*princ_ret) * (count));
- if (!princ_ret)
- return ENOMEM;
- if (!(princ_ret[0] = (krb5_data *) malloc(sizeof(*princ_ret[0])))) {
- xfree(princ_ret);
+ data = (krb5_data *) malloc(sizeof(krb5_data) * count);
+ if (data == 0)
return ENOMEM;
- }
- princ_ret[0]->length = rlen;
- princ_ret[0]->data = malloc(rlen);
- if (!princ_ret[0]->data) {
- xfree(princ_ret[0]);
- xfree(princ_ret);
+ krb5_princ_set_realm_length(princ, rlen);
+ tmpdata = malloc(rlen);
+ if (!tmpdata) {
+ free (data);
return ENOMEM;
}
- memcpy(princ_ret[0]->data, realm, rlen);
+ krb5_princ_set_realm_data(princ, tmpdata);
+ memcpy(tmpdata, realm, rlen);
/* process rest of components */
- for (i = 1, next = va_arg(ap, char *);
+ for (i = 0, next = va_arg(ap, char *);
next;
next = va_arg(ap, char *), i++) {
- if (i == count-1) {
+ if (i == count) {
/* not big enough. realloc the array */
- krb5_principal p_tmp;
- p_tmp = (krb5_principal) realloc((char *)princ_ret, sizeof(*princ_ret)*(count*2));
- if (!p_tmp)
- goto free_out;
- princ_ret = p_tmp;
- count *= 2;
- }
- if (!(princ_ret[i] =
- (krb5_data *) malloc(sizeof(*princ_ret[i])))) {
- free_out:
- for (i--; i >= 0; i--) {
- xfree(princ_ret[i]->data);
- xfree(princ_ret[i]);
+ krb5_data *p_tmp;
+ p_tmp = (krb5_data *) realloc((char *)data,
+ sizeof(krb5_data)*(count*2));
+ if (!p_tmp) {
+ free_out:
+ while (i-- >= 0)
+ xfree(data[i].data);
+ xfree(data);
+ xfree(tmpdata);
+ return (ENOMEM);
}
- xfree(princ_ret);
- return (ENOMEM);
+ count *= 2;
+ data = p_tmp;
}
- princ_ret[i]->length = strlen(next);
- princ_ret[i]->data = strdup(next);
- if (!princ_ret[i]->data) {
- xfree(princ_ret[i]);
+
+ data[i].length = strlen(next);
+ data[i].data = strdup(next);
+ if (!data[i].data)
goto free_out;
- }
}
- princ_ret[i] = 0; /* put a null as the last entry */
- *princ = princ_ret;
+ princ->data = data;
+ princ->length = i;
+ /* Set princ->type */
return 0;
}
{
va_list ap;
krb5_error_code retval;
+ krb5_principal pr_ret = (krb5_principal)malloc(sizeof(krb5_principal_data));
+
+ if (!pr_ret)
+ return ENOMEM;
#if __STDC__ || defined(STDARG_PROTOTYPES)
va_start(ap, realm);
#else
va_start(ap);
#endif
- retval = krb5_build_principal_va(princ, rlen, realm, ap);
+ retval = krb5_build_principal_va(pr_ret, rlen, realm, ap);
va_end(ap);
+ if (retval == 0)
+ *princ = pr_ret;
return retval;
}
krb5_error_code
krb5_principal2salt(pr, ret)
-krb5_const_principal pr;
+register krb5_const_principal pr;
krb5_data *ret;
{
int size, offset;
- krb5_data * const * prp;
-
+ int nelem;
+ register int i;
if (pr == 0) {
- ret->length = 0;
- ret->data = 0;
- } else {
- for (size = 0, prp = pr; *prp; prp++)
- size += (*prp)->length;
+ ret->length = 0;
+ ret->data = 0;
+ return 0;
+ }
+
+ nelem = krb5_princ_size(pr);
+
+ size = krb5_princ_realm(pr)->length;
+
+ for (i = 0; i < nelem; i++)
+ size += krb5_princ_component(pr, i)->length;
+
+ ret->length = size;
+ if (!(ret->data = malloc (size)))
+ return ENOMEM;
- ret->length = size;
- if (!(ret->data = malloc (size+1)))
- return ENOMEM;
+ offset = krb5_princ_realm(pr)->length;
+ memcpy(ret->data, krb5_princ_realm(pr)->data, offset);
- for (offset=0, prp=pr; *prp; prp++)
- {
- memcpy(&ret->data[offset],(*prp)->data, (*prp)->length);
- offset += (*prp)->length;
- }
+ for (i = 0; i < nelem; i++) {
+ memcpy(&ret->data[offset], krb5_princ_component(pr, i)->data,
+ krb5_princ_component(pr, i)->length);
+ offset += krb5_princ_component(pr, i)->length;
}
return 0;
}
#include <krb5/krb5.h>
#include <krb5/ext-proto.h>
-#ifndef min
-#define min(a,b) ((a) < (b) ? (a) : (b))
-#endif /* min */
-
krb5_boolean
krb5_principal_compare(princ1, princ2)
krb5_const_principal princ1;
krb5_const_principal princ2;
{
- register krb5_data * const *p1, * const *p2;
+ register int i, nelem;
- for (p1 = princ1, p2 = princ2; *p1 && *p2; p1++, p2++) {
- if ((*p1)->length != (*p2)->length)
- return FALSE;
- if (memcmp((*p1)->data, (*p2)->data, (*p1)->length))
-
+ nelem = krb5_princ_size(princ1);
+ if (nelem != krb5_princ_size(princ2))
+ return FALSE;
+
+ if (krb5_princ_realm(princ1)->length != krb5_princ_realm(princ2)->length ||
+ memcmp (krb5_princ_realm(princ1)->data, krb5_princ_realm(princ2)->data,
+ krb5_princ_realm(princ2)->length))
+ return FALSE;
+
+ for (i = 0; i < nelem; i++) {
+ register const krb5_data *p1 = krb5_princ_component(princ1, i);
+ register const krb5_data *p2 = krb5_princ_component(princ2, i);
+ if (p1->length != p2->length ||
+ memcmp(p1->data, p2->data, p1->length))
return FALSE;
}
- if (*p1 || *p2) /* didn't both run out of components
- at once */
- return FALSE;
return TRUE;
}
return(retval);
}
}
- if (!(retval = krb5_get_server_rcache(server[1], &rcache))) {
+ if (!(retval = krb5_get_server_rcache(krb5_princ_component(server, 1),
+ &rcache))) {
retval = krb5_rd_req_decoded(request, server,
sender_addr, 0,
0, 0, rcache, authdat);
krb5_data outbuf;
krb5_rcache rcache;
krb5_octet response;
+ krb5_data *server_name;
char *cachename;
extern krb5_deltat krb5_clockskew;
static char *rc_base = "rc_";
problem = krb5_rc_resolve_type(&rcache,
rc_type ? rc_type : "dfl");
cachename = NULL;
- if (!problem && !(cachename = malloc(server[1]->length+1+
- strlen(rc_base))))
+ server_name = krb5_princ_component(server, 0);
+ if (!problem && !(cachename = malloc(server_name->length+1+strlen(rc_base))))
problem = ENOMEM;
if (!problem) {
strcpy(cachename, rc_base ? rc_base : "rc_");
- strncat(cachename, server[1]->data, server[1]->length);
- cachename[server[1]->length+strlen(rc_base)] = '\0';
+ strncat(cachename, server_name->data, server_name->length);
+ cachename[server_name->length+strlen(rc_base)] = '\0';
problem = krb5_rc_resolve(rcache, cachename);
}
if (!problem) {
{
register char *cp, *q;
register int i,j;
- register int totalsize = 0;
- int length;
+ int length, nelem;
+ register int totalsize = krb5_princ_realm(principal)->length + 1;
- if (!principal[0] || !principal[1])
- return KRB5_PARSE_MALFORMED;
- for (i = 0; principal[i]; i++) {
- cp = principal[i]->data;
- length = principal[i]->length;
+ for (cp = krb5_princ_realm(principal)->data; *cp; cp++)
+ if (*cp == REALM_SEP || *cp == COMPONENT_SEP ||
+ *cp == '\\' || *cp == '\t')
+ totalsize++;
+
+ nelem = krb5_princ_size(principal);
+ for (i = 0; i < nelem; i++) {
+ cp = krb5_princ_component(principal, i)->data;
+ length = krb5_princ_component(principal, i)->length;
+ totalsize += length;
for (j=0; j < length; j++,cp++)
if (*cp == REALM_SEP || *cp == COMPONENT_SEP ||
*cp == '\0' || *cp == '\\' || *cp == '\t')
- totalsize += 2;
- else
totalsize++;
totalsize++; /* This is for the separator */
}
q = *name;
- for (i = 1; principal[i]; i++) {
- cp = principal[i]->data;
- length = principal[i]->length;
+ for (i = 0; i < nelem; i++) {
+ cp = krb5_princ_component(principal, i)->data;
+ length = krb5_princ_component(principal, i)->length;
for (j=0; j < length; j++,cp++) {
switch (*cp) {
case COMPONENT_SEP:
q--; /* Back up last component separator */
*q++ = REALM_SEP;
- cp = principal[0]->data;
- length = principal[0]->length;
+ cp = krb5_princ_realm(principal)->data;
+ length = krb5_princ_realm(principal)->length;
for (j=0; j < length; j++,cp++) {
switch (*cp) {
case COMPONENT_SEP: