[1190] in Kerberos-V5-bugs
krb5_set_default_realm
daemon@ATHENA.MIT.EDU (epeisach@MIT.EDU)
Fri Mar 17 23:47:36 1995
From: epeisach@MIT.EDU
Date: Fri, 17 Mar 1995 23:47:31 -0500
To: krb5-bugs@MIT.EDU
This allows one to change the default realm for an application such that
functions that call krb5_get_default_realm will return what you want.
(i.e. krb5_parse... will do this transparaently). Why might this be
good? Well, say I want to setup a new kerberos realm - which is not the
default realm of the machine I am - for testing purposes, in kdb5_edit
you specify the realm on the command line, but add_new_key will use the
machine default realm if the user does not specify one...
Implementation note: Ted and I discussed this briefly. He wanted to but
the realm into the context structure and do away with the gross hack for
a global override variable that existed currently. This has been done.
One could argue that the code could test for a real context which is
initialized, but I could not find such a macro or anything on the system
currently. (and an error message).
I also include the API change... Well, the api docs are really in bad
shape and need a context for all of the routines, but I figured this
should be included (w/o context for compatibility :-)) so it will not be
forgotten.
The changes are:
src/
include/krb5.h
Add the default_realm to the context
include/krb5/los-proto.h
Add prototype
lib/krb5/krb/init_ctx.c:
Initialize and free the default realm
lib/krb5/os/def_realm.c
Do the realm work
admin/edit/kdb5_edit.c:
Use krb5_set_default_realm
doc/api/libos.tex:
Add a broken definition...
===================================================================
RCS file: /mit/krb5/.cvsroot/src/include/krb5.h,v
retrieving revision 1.5
diff -c -r1.5 krb5.h
*** krb5.h 1995/03/18 03:15:49 1.5
--- src/include/krb5.h 1995/03/18 03:53:41
***************
*** 37,42 ****
--- 37,43 ----
krb5_enctype * etypes;
int etype_count;
void * os_context;
+ char * default_realm;
} * krb5_context;
struct _krb5_auth_context;
===================================================================
RCS file: /mit/krb5/.cvsroot/src/include/krb5/los-proto.h,v
retrieving revision 5.38
diff -c -r5.38 los-proto.h
*** los-proto.h 1995/03/15 19:55:31 5.38
--- src/include/krb5/los-proto.h 1995/03/18 02:34:43
***************
*** 84,89 ****
--- 84,92 ----
krb5_error_code INTERFACE krb5_get_default_realm
PROTOTYPE((krb5_context,
char ** ));
+ krb5_error_code INTERFACE krb5_set_default_realm
+ PROTOTYPE((krb5_context,
+ const char * ));
krb5_error_code INTERFACE krb5_get_host_realm
PROTOTYPE((krb5_context,
const char *,
===================================================================
RCS file: /mit/krb5/.cvsroot/src/lib/krb5/krb/init_ctx.c,v
retrieving revision 5.6
diff -c -r5.6 init_ctx.c
*** init_ctx.c 1995/03/02 04:22:12 5.6
--- src/lib/krb5/krb/init_ctx.c 1995/03/18 04:12:09
***************
*** 47,52 ****
--- 47,55 ----
if (krb5_os_init_context(ctx))
goto cleanup;
+
+ ctx->default_realm = 0;
+
*context = ctx;
return 0;
***************
*** 63,68 ****
--- 66,74 ----
if (ctx->etypes);
free(ctx->etypes);
+
+ if (ctx->default_realm)
+ free(ctx->default_realm);
ctx->magic = 0;
free(ctx);
===================================================================
RCS file: /mit/krb5/.cvsroot/src/lib/krb5/os/def_realm.c,v
retrieving revision 5.14
diff -c -r5.14 def_realm.c
*** def_realm.c 1995/03/07 23:12:27 5.14
--- src/lib/krb5/os/def_realm.c 1995/03/18 04:21:24
***************
*** 44,56 ****
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;
--- 44,49 ----
***************
*** 58,71 ****
{
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 (!(config_file = fopen(krb5_config_file, "r")))
/* can't open */
--- 51,61 ----
{
FILE *config_file;
char realmbuf[BUFSIZ];
char *realm;
char *cp;
! if (context->default_realm)
! realm = context->default_realm;
else {
if (!(config_file = fopen(krb5_config_file, "r")))
/* can't open */
***************
*** 85,101 ****
if (cp)
*cp = '\0';
! saved_realm = malloc(strlen (realmbuf) + 1);
! if (!saved_realm)
return ENOMEM;
! strcpy(saved_realm, realmbuf);
! realm = saved_realm;
}
if (!(*lrealm = cp = malloc((unsigned int) strlen(realm) + 1)))
return ENOMEM;
strcpy(cp, realm);
return(0);
}
--- 75,112 ----
if (cp)
*cp = '\0';
! context->default_realm = malloc(strlen (realmbuf) + 1);
! if (!context->default_realm)
return ENOMEM;
! 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 (!lrealm) return ENOMEM;
+
+ if (context->default_realm) {
+ free(context->default_realm);
+ }
+
+ context->default_realm = malloc(strlen (lrealm) + 1);
+
+ if (!context->default_realm)
+ return ENOMEM;
+
+ strcpy(context->default_realm, lrealm);
+ return(0);
+
}
===================================================================
RCS file: /mit/krb5/.cvsroot/src/admin/edit/kdb5_edit.c,v
retrieving revision 5.52
diff -c -r5.52 kdb5_edit.c
*** kdb5_edit.c 1995/02/28 10:09:40 5.52
--- src/admin/edit/kdb5_edit.c 1995/03/18 04:26:03
***************
*** 205,211 ****
exit(1);
}
krb5_use_cstype(edit_context, &master_encblock, etype);
! if (!cur_realm) {
if (retval = krb5_get_default_realm(edit_context, &defrealm)) {
com_err(progname, retval, "while retrieving default realm name");
exit(1);
--- 205,217 ----
exit(1);
}
krb5_use_cstype(edit_context, &master_encblock, etype);
!
! if (cur_realm) {
! if (retval = krb5_set_default_realm(edit_context, cur_realm)) {
! com_err(progname, retval, "while setting default realm name");
! exit(1);
! }
! } else {
if (retval = krb5_get_default_realm(edit_context, &defrealm)) {
com_err(progname, retval, "while retrieving default realm name");
exit(1);
***************
*** 217,222 ****
--- 223,229 ----
}
(void) strcpy(cur_realm, defrealm);
}
+
(void) set_dbname_help(progname, dbname);
exit_status = 0; /* It's OK if we get errors in set_dbname_help */
return request;
===================================================================
RCS file: /mit/krb5/.cvsroot/doc/api/libos.tex,v
retrieving revision 5.11
diff -c -r5.11 libos.tex
*** libos.tex 1994/06/14 19:04:50 5.11
--- doc/api/libos.tex 1995/03/18 04:30:41
***************
*** 257,262 ****
--- 257,273 ----
Returns system errors.
+ \begin{funcdecl}{krb5_set_default_realm}{krb5_error_code}
+ \funcout
+ \funcarg{char *}{realm}
+ \end{funcdecl}
+
+ Sets the default realm to be used if no user-specified realm is
+ available (e.g. to interpret a user-typed principal name with the
+ realm omitted for convenience). (c.f. krb5_get_default_realm)
+
+ Returns system errors.
+
\begin{funcdecl}{krb5_get_host_realm}{krb5_error_code}{\funcin}
\funcarg{const char *}{host}
\funcout