From: Tom Yu Date: Fri, 6 Dec 2002 03:22:41 +0000 (+0000) Subject: * kname_parse.c (kname_unparse): Add new function ported from X-Git-Tag: krb5-1.3-alpha1~244 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=346f6846d7bfd873da865bbc2e9e5cbe8768df42;p=krb5.git * kname_parse.c (kname_unparse): Add new function ported from KfM, including support functions. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@15030 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/krb4/ChangeLog b/src/lib/krb4/ChangeLog index 59e71c9be..95c9d3fd8 100644 --- a/src/lib/krb4/ChangeLog +++ b/src/lib/krb4/ChangeLog @@ -1,5 +1,8 @@ 2002-12-05 Tom Yu + * kname_parse.c (kname_unparse): Add new function ported from + KfM, including support functions. + * decomp_tkt.c (decomp_ticket): Add KRB5_CALLCONV. 2002-12-04 Tom Yu diff --git a/src/lib/krb4/kname_parse.c b/src/lib/krb4/kname_parse.c index 13f844511..db3a1cf0b 100644 --- a/src/lib/krb4/kname_parse.c +++ b/src/lib/krb4/kname_parse.c @@ -28,6 +28,10 @@ #include "krb.h" #include +static int k_isname_unparsed(const char *s); +static int k_isinst_unparsed(const char *s); +static int k_isrealm_unparsed(const char *s); + /* * max size of full name * @@ -271,3 +275,137 @@ k_isrealm(s) } return 1; } + +int KRB5_CALLCONV +kname_unparse( + char *outFullName, + const char *inName, + const char *inInstance, + const char *inRealm) +{ + const char *read; + char *write = outFullName; + + if (inName == NULL) + return KFAILURE; + + if (outFullName == NULL) + return KFAILURE; + + if (!k_isname_unparsed(inName) || + ((inInstance != NULL) && !k_isinst_unparsed(inInstance)) || + ((inRealm != NULL) && !k_isrealm_unparsed(inRealm))) { + + return KFAILURE; + } + + for (read = inName; *read != '\0'; read++, write++) { + if ((*read == '.') || (*read == '@')) { + *write = '\\'; + write++; + } + *write = *read; + } + + if ((inInstance != NULL) && (inInstance[0] != '\0')) { + *write = '.'; + write++; + for (read = inInstance; *read != '\0'; read++, write++) { + if (*read == '@') { + *write = '\\'; + write++; + } + *write = *read; + } + } + + if ((inRealm != NULL) && (inRealm[0] != '\0')) { + *write = '@'; + write++; + for (read = inRealm; *read != '\0'; read++, write++) { + if (*read == '@') { + *write = '\\'; + write++; + } + *write = *read; + } + } + + *write = '\0'; + return KSUCCESS; +} + +/* + * k_isname, k_isrealm, k_isinst expect an unparsed realm -- i.e., one where all + * components have special characters escaped with \. However, + * for kname_unparse, we need to be able to sanity-check components without \. + * That's what k_is*_unparsed are for. + */ + +static int +k_isname_unparsed(const char *s) +{ + int len = strlen(s); + const char* c; + /* Has to be non-empty and has to fit in ANAME_SZ when escaped with \ */ + + if (!*s) + return 0; + + for (c = s; *c != '\0'; c++) { + switch (*c) { + case '.': + case '@': + len++; + break; + } + } + + if (len > ANAME_SZ - 1) + return 0; + return 1; +} + +static int +k_isinst_unparsed(const char *s) +{ + int len = strlen(s); + const char* c; + /* Has to fit in INST_SZ when escaped with \ */ + + for (c = s; *c != '\0'; c++) { + switch (*c) { + case '.': + case '@': + len++; + break; + } + } + + if (len > INST_SZ - 1) + return 0; + return 1; +} + +static int +k_isrealm_unparsed(const char *s) +{ + int len = strlen(s); + const char* c; + /* Has to be non-empty and has to fit in REALM_SZ when escaped with \ */ + + if (!*s) + return 0; + + for (c = s; *c != '\0'; c++) { + switch (*c) { + case '@': + len++; + break; + } + } + + if (len > REALM_SZ - 1) + return 0; + return 1; +}