From: John Kohl Date: Mon, 22 Jan 1990 13:02:40 +0000 (+0000) Subject: *** empty log message *** X-Git-Tag: krb5-1.0-alpha2~1220 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=cc1c8c43b25c226d63a43d49e12eebb75dd8d4d4;p=krb5.git *** empty log message *** git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@163 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/krb5/krb/unparse.c b/src/lib/krb5/krb/unparse.c new file mode 100644 index 000000000..fa4d8281e --- /dev/null +++ b/src/lib/krb5/krb/unparse.c @@ -0,0 +1,87 @@ +/* + * $Source$ + * $Author$ + * + * Copyright 1990 by the Massachusetts Institute of Technology. + * + * For copying and distribution information, please see the file + * . + * + * krb5_unparse_name() routine + */ + +#if !defined(lint) && !defined(SABER) +static char rcsid_unparse_c[] = +"$Id$"; +#endif /* !lint & !SABER */ + +#include + +#include +#include +#ifdef __STDC__ +#include +#else +extern char *malloc(), *index(), *calloc(); +#endif /* __STDC__ */ + +#include + +/* + converts the multi-part + principal format used in the protocols to a single-string representation + of the name. + + the name returned is in allocated storage and should be freed by the caller + when finished. + + Conventions: / is used to separate components; @ is used to separate + the realm from the rest of the name. If any component besides the realm has + a / or @ in it, an error is returned. + + returns system errors XXX + */ + +#define REALM_SEP '@' +#define COMPONENT_SEP '/' +#define REALM_SEP_STRING "@" +#define COMPONENT_SEP_STRING "/" + +krb5_error_code +krb5_unparse_name(principal, name) +krb5_principal principal; +register char **name; +{ + register char *cp; + register int i; + int totalsize = 0; + + /* check for invalid elements of components; don't need to check + realm, which is first component */ + for (i = 1; principal[i]; i++) { + for (cp = principal[i]->data; + cp < principal[i]->data + principal[i]->length; cp++) + if (*cp == REALM_SEP || *cp == COMPONENT_SEP) + return KRB5_PARSE_ILLCHAR; + totalsize += principal[i]->length + 1; /* + 1 for separator */ + } + totalsize += principal[0]->length; /* no +1 since we need only n-1 seps + for n components */ + + *name = malloc(totalsize+1); /* room for null */ + if (!*name) + return ENOMEM; + + (void) bzero(*name, totalsize+1); + + for (i = 1; principal[i]; i++) { + strncat(*name, principal[i]->data, principal[i]->length); + if (principal[i+1]) /* don't append sep to last elt */ + strcat(*name, COMPONENT_SEP_STRING); + } + + strcat(*name, REALM_SEP_STRING); + strncat(*name, principal[0]->data, principal[0]->length); + + return 0; +}