From: Theodore Tso Date: Sat, 22 Apr 1995 00:59:31 +0000 (+0000) Subject: def_realm.c (krb5_get_default_realm): Use the profile code to X-Git-Tag: krb5-1.0-beta5~308 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=37990cb9a9149cbee5851125793deddc3745be30;p=krb5.git def_realm.c (krb5_get_default_realm): Use the profile code to get the default realm from [libdefaults]/default_realm. get_krbhst.c (krb5_get_krbhst): Use the profile code to get the list of Kerberos servers for a particualar realm from [realms]//kdc realm_dom.c (krb5_get_realm_domain): Use the profile code to get the default domain postfix for a realm (used only to convert V4 -> V5 principals) from [realms]//default_domain hst_realm.c (krb5_get_host_realm): Use the profile code to get the default realm given a particular host from [domain_realm]/ init_os_ctx.c (krb5_os_init_context): When the OS context is initialized, also initialize the profile file. This loads in the /etc/krb5.conf file. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@5438 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/krb5/os/ChangeLog b/src/lib/krb5/os/ChangeLog index cfbdb19bc..8fe318fd0 100644 --- a/src/lib/krb5/os/ChangeLog +++ b/src/lib/krb5/os/ChangeLog @@ -1,3 +1,25 @@ +Fri Apr 21 11:38:45 1995 Theodore Y. Ts'o + + * def_realm.c (krb5_get_default_realm): Use the profile code to + get the default realm from [libdefaults]/default_realm. + + * get_krbhst.c (krb5_get_krbhst): Use the profile code to get the + list of Kerberos servers for a particualar realm from + [realms]//kdc + + * realm_dom.c (krb5_get_realm_domain): Use the profile code to + get the default domain postfix for a realm (used only to + convert V4 -> V5 principals) from + [realms]//default_domain + + * hst_realm.c (krb5_get_host_realm): Use the profile code to get + the default realm given a particular host from + [domain_realm]/ + + * init_os_ctx.c (krb5_os_init_context): When the OS context is + initialized, also initialize the profile file. This loads + in the /etc/krb5.conf file. + Wed Apr 19 13:50:19 1995 Ezra Peisach (epeisach@kangaroo.mit.edu) * def_realm.c: (krb5_get_default_realm) - remove global default realm. diff --git a/src/lib/krb5/os/def_realm.c b/src/lib/krb5/os/def_realm.c index 3b3ee8c92..f028c65e4 100644 --- a/src/lib/krb5/os/def_realm.c +++ b/src/lib/krb5/os/def_realm.c @@ -49,8 +49,10 @@ krb5_get_default_realm(context, lrealm) krb5_context context; char **lrealm; { +#ifdef OLD_CONFIG_FILE FILE *config_file; char realmbuf[BUFSIZ]; +#endif char *realm; char *cp; @@ -58,6 +60,7 @@ krb5_get_default_realm(context, lrealm) return KV5M_CONTEXT; if (!context->default_realm) { +#ifdef OLD_CONFIG_FILE krb5_find_config_files(); if (!(config_file = fopen(krb5_config_file, "r"))) /* can't open */ @@ -82,6 +85,18 @@ krb5_get_default_realm(context, lrealm) return ENOMEM; strcpy(context->default_realm, realmbuf); +#else + /* + * XXX should try to figure out a reasonable default based + * on the host's DNS domain. + */ + context->default_realm = 0; + profile_get_string(context->profile, "libdefaults", + "default_realm", 0, 0, + &context->default_realm); + if (context->default_realm == 0) + return(KRB5_CONFIG_BADFORMAT); +#endif } realm = context->default_realm; diff --git a/src/lib/krb5/os/get_krbhst.c b/src/lib/krb5/os/get_krbhst.c index 093af1163..8318d7860 100644 --- a/src/lib/krb5/os/get_krbhst.c +++ b/src/lib/krb5/os/get_krbhst.c @@ -54,6 +54,8 @@ * hostname added to the list returned. */ +#ifdef OLD_CONFIG_FILES + extern char *krb5_config_file; /* extern so can be set at load/runtime */ @@ -155,3 +157,50 @@ krb5_get_krbhst(context, realm, hostlist) return retval; } +#else +krb5_error_code +krb5_get_krbhst(context, realm, hostlist) + krb5_context context; + const krb5_data *realm; + char ***hostlist; +{ + char **values, **cpp, *cp; + const char *realm_kdc_names[4]; + krb5_error_code retval; + + realm_kdc_names[0] = "realms"; + realm_kdc_names[1] = realm->data; + realm_kdc_names[2] = "kdc"; + realm_kdc_names[3] = 0; + + if (context->profile == 0) + return KRB5_CONFIG_CANTOPEN; + + retval = profile_get_values(context->profile, realm_kdc_names, &values); + if (retval == PROF_NO_SECTION) + return KRB5_REALM_UNKNOWN; + if (retval == PROF_NO_RELATION) + return KRB5_CONFIG_BADFORMAT; + if (retval) + return retval; + + /* + * Do cleanup over the list. We allow for some extra field to be + * added to the kdc line later (maybe the port number) + */ + for (cpp = values; *cpp; cpp++) { + cp = strchr(*cpp, ' '); + if (cp) + *cp = 0; + cp = strchr(*cpp, '\t'); + if (cp) + *cp = 0; + cp = strchr(*cpp, ','); + if (cp) + *cp = 0; + } + + *hostlist = values; + return 0; +} +#endif diff --git a/src/lib/krb5/os/hst_realm.c b/src/lib/krb5/os/hst_realm.c index a3193cbbd..1362f4319 100644 --- a/src/lib/krb5/os/hst_realm.c +++ b/src/lib/krb5/os/hst_realm.c @@ -77,6 +77,8 @@ #define MAXHOSTNAMELEN 64 #endif +#ifdef OLD_CONFIG_FILES + #define DEF_REALMNAME_SIZE 256 extern char *krb5_trans_file; @@ -232,5 +234,72 @@ krb5_get_host_realm(context, host, realmsp) return 0; } +#else + +krb5_error_code +krb5_get_host_realm(context, host, realmsp) + krb5_context context; + const char *host; + char ***realmsp; +{ + char **retrealms; + char *domain, *default_realm, *realm, *cp; + krb5_error_code retval; + char local_host[MAXHOSTNAMELEN+1]; + + if (host) + strncpy(local_host, host, MAXHOSTNAMELEN); + else { + if (gethostname(local_host, sizeof(local_host)-1) == -1) + return errno; + } + local_host[sizeof(local_host)-1] = '\0'; + for (cp = local_host; *cp; cp++) { + if (isupper(*cp)) + *cp = tolower(*cp); + } + domain = strchr(local_host, '.'); + + /* prepare default */ + if (domain) { + if (!(default_realm = malloc(strlen(domain+1)+1))) + return ENOMEM; + strcpy(default_realm, domain+1); + /* Upper-case realm */ + for (cp = default_realm; *cp; cp++) + if (islower(*cp)) + *cp = toupper(*cp); + } else { + retval = krb5_get_default_realm(context, &default_realm); + if (retval) { + krb5_xfree(retrealms); + return retval; + } + } + + retval = profile_get_string(context->profile, "domain_realm", local_host, + 0, default_realm, &realm); + free(default_realm); + if (retval) + return retval; + default_realm = realm; + retval = profile_get_string(context->profile, "domain_realm", domain, + 0, default_realm, &realm); + free(default_realm); + if (retval) + return retval; + if (!(retrealms = (char **)calloc(2, sizeof(*retrealms)))) { + free(realm); + return ENOMEM; + } + + retrealms[0] = realm; + retrealms[1] = 0; + + *realmsp = retrealms; + return 0; +} + +#endif diff --git a/src/lib/krb5/os/init_os_ctx.c b/src/lib/krb5/os/init_os_ctx.c index 4c92c6775..d9753ffd3 100644 --- a/src/lib/krb5/os/init_os_ctx.c +++ b/src/lib/krb5/os/init_os_ctx.c @@ -30,6 +30,9 @@ krb5_os_init_context(ctx) krb5_context ctx; { krb5_os_context os_ctx; + krb5_error_code retval; + char *name; + char *filenames[2]; if (ctx->os_context) return 0; @@ -41,6 +44,20 @@ krb5_os_init_context(ctx) os_ctx->magic = KV5M_OS_CONTEXT; ctx->os_context = (void *) os_ctx; + +#ifndef OLD_CONFIG_FILES + /* + * When the profile routines are later enhanced, we will try + * including a config file from user's home directory here. + */ + name = getenv("KRB5_CONFIG"); + filenames[0] == name ? name : DEFAULT_PROFILE_FILENAME; + filenames[1] = 0; + + retval = profile_init(filenames, &ctx->profile); + if (retval) + ctx->profile = 0; +#endif return 0; } @@ -59,4 +76,7 @@ krb5_os_free_context(ctx) os_ctx->magic = 0; free(os_ctx); ctx->os_context = 0; + + if (ctx->profile) + profile_release(ctx->profile); } diff --git a/src/lib/krb5/os/realm_dom.c b/src/lib/krb5/os/realm_dom.c index fcb0b5594..4bc14585f 100644 --- a/src/lib/krb5/os/realm_dom.c +++ b/src/lib/krb5/os/realm_dom.c @@ -42,6 +42,8 @@ #include #include +#ifdef OLD_CONFIG_FILES + /* for old Unixes and friends ... */ #ifndef MAXHOSTNAMELEN #define MAXHOSTNAMELEN 64 @@ -180,3 +182,19 @@ krb5_get_realm_domain(context, realm, domain) } } } + +#else + +krb5_error_code +krb5_get_realm_domain(context, realm, domain) + krb5_context context; + const char *realm; + char **domain; +{ + krb5_error_code retval; + + retval = profile_get_string(context->profile, "realms", realm, + "default_domain", realm, domain); + return retval; +} +#endif