[704] in Kerberos-V5-bugs
enhancement: try "kerberos.REALM" if "REALM" isn't in /etc/krb.conf
daemon@ATHENA.MIT.EDU (Jonathan I. Kamens)
Sun Sep 4 22:00:43 1994
Date: Sun, 4 Sep 1994 22:01:46 -0400
From: "Jonathan I. Kamens" <jik@cam.ov.com>
To: krb5-bugs@MIT.EDU
If /etc/krb.conf doesn't exist, or if the desired realm can't be found
in it, then krb5_get_krbhost should check to see if a host named
"kerberos.REALM" exists, and if so, use that as the kerberos server
for the realm.
The patch below adds this enhancement. In addition it fixes a minor
bug: before, if something inside the search loop set retval, the end
of the function didn't notice and always set it to REALM_UNKNOWN.
--- /afs/gza.com/development/krb5.beta4/src/lib/krb5/os/get_krbhst.c Fri Oct 15 12:52:03 1993
+++ get_krbhst.c Sun Sep 4 21:59:24 1994
@@ -34,7 +34,12 @@
#include <krb5/ext-proto.h>
#include <stdio.h>
#include <ctype.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netdb.h>
+#define DEF_KDC_HOSTNAME "kerberos."
+
/*
Figures out the Kerberos server names for the given realm, filling in a
pointer to an argv[] style list of names, terminated with a null pointer.
@@ -81,9 +86,33 @@
* case.
*/
- if (!(config_file = fopen(krb5_config_file, "r")))
- /* can't open */
- return KRB5_CONFIG_CANTOPEN;
+ if (!(config_file = fopen(krb5_config_file, "r"))) {
+ char *host_ptr;
+
+ retval = KRB5_CONFIG_CANTOPEN;
+
+try_default_hostname:
+ /* Can't open the config file. See if there's a host named
+ "kerberos.realm", and if so, use that as the single
+ kerberos server. */
+
+ if (host_ptr = malloc(realm->length + strlen(DEF_KDC_HOSTNAME) + 1)) {
+ struct hostent *hent;
+
+ (void) sprintf(host_ptr, "%s%*s", DEF_KDC_HOSTNAME,
+ realm->length, realm->data);
+ if ((hent = gethostbyname(host_ptr)) &&
+ (rethlist = (char **) calloc(hlsize, sizeof(*rethlist)))) {
+ rethlist[0] = host_ptr;
+ *hostlist = rethlist;
+ return 0;
+ }
+ krb5_xfree(host_ptr);
+ }
+
+ *hostlist = 0;
+ return retval;
+ }
if (fgets(filebuf, sizeof(filebuf), config_file) == NULL)
retval = KRB5_CONFIG_BADFORMAT;
@@ -149,7 +178,10 @@
if (hlindex == 0) {
krb5_xfree(rethlist);
rethlist = 0;
- retval = KRB5_REALM_UNKNOWN;
+ if (! retval) {
+ retval = KRB5_REALM_UNKNOWN;
+ goto try_default_hostname;
+ }
}
*hostlist = rethlist;