2 * lib/krb5/os/def_realm.c
4 * Copyright 1990,1991 by the Massachusetts Institute of Technology.
7 * Export of this software from the United States of America may
8 * require a specific license from the United States Government.
9 * It is the responsibility of any person or organization contemplating
10 * export to obtain such a license before exporting.
12 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13 * distribute this software and its documentation for any purpose and
14 * without fee is hereby granted, provided that the above copyright
15 * notice appear in all copies and that both that copyright notice and
16 * this permission notice appear in supporting documentation, and that
17 * the name of M.I.T. not be used in advertising or publicity pertaining
18 * to distribution of the software without specific, written prior
19 * permission. M.I.T. makes no representations about the suitability of
20 * this software for any purpose. It is provided "as is" without express
21 * or implied warranty.
24 * krb5_get_default_realm() function.
31 * Retrieves the default realm to be used if no user-specified realm is
32 * available. [e.g. to interpret a user-typed principal name with the
33 * realm omitted for convenience]
35 * returns system errors, NOT_ENOUGH_SPACE
39 * Implementation: the default realm is stored in a configuration file,
40 * named by krb5_config_file; the first token in this file is taken as
41 * the default local realm name.
44 extern char *krb5_config_file; /* extern so can be set at
48 * In case the program wants to override this.
50 extern char *krb5_override_default_realm;
52 char *krb5_override_default_realm = 0;
55 krb5_get_default_realm(context, lrealm)
60 char realmbuf[BUFSIZ];
61 static char *saved_realm = 0;
65 if (krb5_override_default_realm)
66 realm = krb5_override_default_realm;
70 if (!(config_file = fopen(krb5_config_file, "r")))
72 return KRB5_CONFIG_CANTOPEN;
74 if (fgets(realmbuf, sizeof(realmbuf), config_file) == NULL) {
76 return(KRB5_CONFIG_BADFORMAT);
80 realmbuf[BUFSIZ-1] = '0';
81 cp = strchr(realmbuf, '\n');
84 cp = strchr(realmbuf, ' ');
88 saved_realm = malloc(strlen (realmbuf) + 1);
92 strcpy(saved_realm, realmbuf);
97 if (!(*lrealm = cp = malloc((unsigned int) strlen(realm) + 1)))