From b9a420cb3c760ab8385ff9a92b52d9bc83707c9f Mon Sep 17 00:00:00 2001 From: Ezra Peisach Date: Wed, 19 Apr 1995 17:59:06 +0000 Subject: [PATCH] Added storing of default realm in context. Global default realm variable removed. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@5378 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/os/ChangeLog | 5 ++++ src/lib/krb5/os/def_realm.c | 56 ++++++++++++++++++++++++------------- 2 files changed, 42 insertions(+), 19 deletions(-) diff --git a/src/lib/krb5/os/ChangeLog b/src/lib/krb5/os/ChangeLog index c4e2df84e..cfbdb19bc 100644 --- a/src/lib/krb5/os/ChangeLog +++ b/src/lib/krb5/os/ChangeLog @@ -1,3 +1,8 @@ +Wed Apr 19 13:50:19 1995 Ezra Peisach (epeisach@kangaroo.mit.edu) + + * def_realm.c: (krb5_get_default_realm) - remove global default realm. + Moved into the context. (krb5_set_default_realm) added. + Fri Apr 14 22:15:00 1995 Theodore Y. Ts'o * an_to_ln.c (dbm_an_to_ln): Don't compile dbm_an_to_ln() if diff --git a/src/lib/krb5/os/def_realm.c b/src/lib/krb5/os/def_realm.c index a7634376f..3b3ee8c92 100644 --- a/src/lib/krb5/os/def_realm.c +++ b/src/lib/krb5/os/def_realm.c @@ -32,7 +32,7 @@ * available. [e.g. to interpret a user-typed principal name with the * realm omitted for convenience] * - * returns system errors, NOT_ENOUGH_SPACE + * returns system errors, NOT_ENOUGH_SPACE, KV5M_CONTEXT */ /* @@ -44,13 +44,6 @@ extern char *krb5_config_file; /* extern so can be set at load/runtime */ -/* - * In case the program wants to override this. - */ -extern char *krb5_override_default_realm; - -char *krb5_override_default_realm = 0; - krb5_error_code INTERFACE krb5_get_default_realm(context, lrealm) krb5_context context; @@ -58,15 +51,13 @@ krb5_get_default_realm(context, lrealm) { FILE *config_file; char realmbuf[BUFSIZ]; - static char *saved_realm = 0; char *realm; char *cp; - if (krb5_override_default_realm) - realm = krb5_override_default_realm; - else if (saved_realm) - realm = saved_realm; - else { + if (!context || (context->magic != KV5M_CONTEXT)) + return KV5M_CONTEXT; + + if (!context->default_realm) { krb5_find_config_files(); if (!(config_file = fopen(krb5_config_file, "r"))) /* can't open */ @@ -86,17 +77,44 @@ krb5_get_default_realm(context, lrealm) if (cp) *cp = '\0'; - saved_realm = malloc(strlen (realmbuf) + 1); - if (!saved_realm) + context->default_realm = malloc(strlen (realmbuf) + 1); + if (!context->default_realm) return ENOMEM; - strcpy(saved_realm, realmbuf); - - realm = saved_realm; + strcpy(context->default_realm, realmbuf); } + realm = context->default_realm; + if (!(*lrealm = cp = malloc((unsigned int) strlen(realm) + 1))) return ENOMEM; strcpy(cp, realm); return(0); } + +krb5_error_code INTERFACE +krb5_set_default_realm(context, lrealm) + krb5_context context; + const char *lrealm; +{ + if (!context || (context->magic != KV5M_CONTEXT)) + return KV5M_CONTEXT; + + if (context->default_realm) { + free(context->default_realm); + context->default_realm = 0; + } + + /* Allow the user to clear the default realm setting by passing in + NULL */ + if (!lrealm) return 0; + + context->default_realm = malloc(strlen (lrealm) + 1); + + if (!context->default_realm) + return ENOMEM; + + strcpy(context->default_realm, lrealm); + return(0); + +} -- 2.26.2