From 2cfa3722090c0290284aaef91bdc1963b6aa779a Mon Sep 17 00:00:00 2001 From: John Kohl Date: Mon, 22 Jan 1990 13:29:40 +0000 Subject: [PATCH] *** empty log message *** git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@164 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/os/def_realm.c | 73 +++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 src/lib/krb5/os/def_realm.c diff --git a/src/lib/krb5/os/def_realm.c b/src/lib/krb5/os/def_realm.c new file mode 100644 index 000000000..a4a45e0ee --- /dev/null +++ b/src/lib/krb5/os/def_realm.c @@ -0,0 +1,73 @@ +/* + * $Source$ + * $Author$ + * + * Copyright 1990 by the Massachusetts Institute of Technology. + * + * For copying and distribution information, please see the file + * . + * + * krb5_get_default_realm() function. + */ + +#if !defined(lint) && !defined(SABER) +static char rcsid_def_realm_c[] = +"$Id$"; +#endif /* !lint & !SABER */ + +#include + +#include +#include + +#include +#ifdef __STDC__ +#include +#else +extern char *malloc(), *index(), *calloc(); +#endif /* __STDC__ */ + +/* + Retrieves 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] + + lnsize specifies the maximum length name that is to be filled into + lrealm. + + returns system errors, NOT_ENOUGH_SPACE +*/ + +/* + * Implementation: the default realm is stored in a configuration file, + * named by krb5_config_file; the first token in this file is taken as + * the default local realm name. + */ + +extern char *krb5_config_file; /* extern so can be set at + load/runtime */ +krb5_error_code +krb5_get_default_realm(lnsize, lrealm) +int lnsize; +char *lrealm; +{ + FILE *config_file; + char realmbuf[BUFSIZ]; + krb5_error_code retval; + + if (!(config_file = fopen(krb5_config_file, "r"))) + /* can't open */ + return KRB5_CONFIG_CANTOPEN; + + if (fscanf(config_file, "%s", realmbuf) != 1) + retval = KRB5_CONFIG_BADFORMAT; + else { + strncpy(lrealm, realmbuf, lnsize); + if (lnsize < strlen(realmbuf)) + retval = KRB5_CONFIG_NOTENUFSPACE; + else + retval = 0; + } + (void) fclose(config_file); + return retval; +} -- 2.26.2