[705] in Zephyr_Bugs

home help back first fref pref prev next nref lref last post

ZExpandRealm() again

daemon@ATHENA.MIT.EDU (Derrick J. Brashear)
Thu Sep 14 09:41:13 1995

Date: Thu, 14 Sep 1995 09:40:58 -0400 (EDT)
From: "Derrick J. Brashear" <shadow@DEMENTIA.ORG>
Reply-To: "Derrick J. Brashear" <shadow@DEMENTIA.ORG>
To: bug-zephyr@MIT.EDU

---2143855796-755253631-811086063=:14990
Content-Type: TEXT/PLAIN; CHARSET=US-ASCII

Hi again,

There's a small patch here so that ZExpandRealm will expand "" to the local
realm.

I'm just sending the entire function again.

-D

---2143855796-755253631-811086063=:14990
Content-Type: TEXT/plain; CHARSET=US-ASCII
Content-Description: ZExpnRlm.c

#ifdef CMU_INTERREALM
#include <internal.h>
#include <sys/param.h>
#include <ctype.h>
#include <netdb.h>

char *
ZExpandRealm(realm)
char *realm;
{
        char *cp1, *cp2;
        static char expand[REALM_SZ];
#ifndef ZEPHYR_USES_KERBEROS
        struct hostent *he;

        he = gethostbyname(realm);

        if (!he || !he->h_name)
                /* just use the raw realm */
                cp2 = realm;
        else
                cp2 = he->h_name;

        cp1 = expand;
        while (*cp2) {
                *cp1++ = toupper(*cp2++);
        }
        *cp1 = '\0';

        return(expand);
#else
	int retval;
	FILE *rlm_file;
	char krb_host[MAXHOSTNAMELEN+1];
        char krb_realm[REALM_SZ+1];
	char linebuf[BUFSIZ];
	char scratch[64];

/* upcase what we got */
	cp2 = realm;
        cp1 = expand;
        while (*cp2) {
                *cp1++ = toupper(*cp2++);
        }
        *cp1 = '\0';

	if ((rlm_file = fopen("/etc/krb.conf", "r")) == (FILE *) 0) {
                return(expand);
        }
	
	if (fgets(linebuf, BUFSIZ, rlm_file) == NULL) {
	  /* error reading */
	  (void) fclose(rlm_file);
	  return(expand);
	}

	if (sscanf(linebuf, "%s", krb_realm) < 1) {
	  /* error reading */
	  (void) fclose(rlm_file);
	  return(expand);
	}

	if (!strncmp(krb_realm, expand, strlen(expand))) {
	  (void) fclose(rlm_file);
	  return(krb_realm);
	}

	while (1) {
	  /* run through the file, looking for admin host */
	  if (fgets(linebuf, BUFSIZ, rlm_file) == NULL) {
            (void) fclose(rlm_file);
            return(expand);
	  }

	  if (sscanf(linebuf, "%s %s admin %s", krb_realm, krb_host, scratch)
	      < 2)
            continue;
	  if (!strncmp(krb_realm, expand, strlen(expand))) {
	    (void) fclose(rlm_file);
	    return(krb_realm);
	  }
	}
#endif /* ZEPHYR_USES_KERBEROS */
}
#endif

---2143855796-755253631-811086063=:14990--

home help back first fref pref prev next nref lref last post