summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTom Yu <tlyu@mit.edu>2002-12-06 03:22:41 +0000
committerTom Yu <tlyu@mit.edu>2002-12-06 03:22:41 +0000
commit346f6846d7bfd873da865bbc2e9e5cbe8768df42 (patch)
treec6c88fa5a75786c49e91bb241fb18d4eb86ced34 /src
parent17d65bfa2e5d0e4f942430e236c2ffd595f92cc7 (diff)
downloadkrb5-346f6846d7bfd873da865bbc2e9e5cbe8768df42.tar.gz
krb5-346f6846d7bfd873da865bbc2e9e5cbe8768df42.tar.xz
krb5-346f6846d7bfd873da865bbc2e9e5cbe8768df42.zip
* 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
Diffstat (limited to 'src')
-rw-r--r--src/lib/krb4/ChangeLog3
-rw-r--r--src/lib/krb4/kname_parse.c138
2 files changed, 141 insertions, 0 deletions
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 <tlyu@mit.edu>
+ * 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 <tlyu@mit.edu>
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 <string.h>
+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;
+}