From d776cdfbb2a1f43b17fa3d5193e7a8075eecabd9 Mon Sep 17 00:00:00 2001 From: Ken Raeburn Date: Sat, 17 May 2008 01:11:42 +0000 Subject: [PATCH] Force hostname to lowercase before constructing kadmin principal name. Allocate space for the name dynamically. ticket: 5943 git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@20323 dc483132-0cff-0310-8789-dd5450dbe970 --- src/kadmin/dbutil/kadm5_create.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/kadmin/dbutil/kadm5_create.c b/src/kadmin/dbutil/kadm5_create.c index ff0d294c5..3f6f6557f 100644 --- a/src/kadmin/dbutil/kadm5_create.c +++ b/src/kadmin/dbutil/kadm5_create.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -172,7 +173,7 @@ static char *build_name_with_realm(char *name, char *realm) static int add_admin_princs(void *handle, krb5_context context, char *realm) { krb5_error_code ret = 0; - char service_name[MAXHOSTNAMELEN + 8]; + char *service_name = 0, *p; char localname[MAXHOSTNAMELEN]; struct addrinfo *ai, ai_hints; int gai_error; @@ -199,7 +200,26 @@ static int add_admin_princs(void *handle, krb5_context context, char *realm) freeaddrinfo(ai); goto clean_and_exit; } - sprintf(service_name, "kadmin/%s", ai->ai_canonname); + for (p = ai->ai_canonname; *p; p++) { +#ifdef isascii + if (!isascii(*p)) + continue; +#else + if (*p < ' ') + continue; + if (*p > '~') + continue; +#endif + if (!isupper(*p)) + continue; + *p = tolower(*p); + } + if (asprintf(&service_name, "kadmin/%s", ai->ai_canonname) < 0) { + ret = ENOMEM; + fprintf(stderr, "Out of memory\n"); + freeaddrinfo(ai); + goto clean_and_exit; + } freeaddrinfo(ai); if ((ret = add_admin_princ(handle, context, -- 2.26.2