[702] in Zephyr_Bugs

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

interrealm zephyr code piece and comments

daemon@ATHENA.MIT.EDU (Derrick J. Brashear)
Wed Sep 13 09:54:57 1995

Date: Wed, 13 Sep 1995 09:54:39 -0400 (EDT)
From: "Derrick J. Brashear" <shadow@DEMENTIA.ORG>
Reply-To: "Derrick J. Brashear" <shadow@DEMENTIA.ORG>
To: bug-zephyr@MIT.EDU

---2143855796-2078917053-811000485=:14990
Content-Type: TEXT/PLAIN; CHARSET=US-ASCII

Hello,

I've included ZExpandRealm(), code which expands a short realm specification
into a full realm name. So, shadow@cs would become shadow@CS.CMU.EDU.

If you're using Kerberos it searches for the first realm name that matches the
string you gave it, which it first upcases. Otherwise, it uses gethostbyname. 

Also, as an incidental:
While I wouldn't suggest you use the server code for the CMU Interrealm zephyr,
I might note that the current suite of clients in the 2.0.2 distribution will
work unmodifed with the CMU interrealm servers, and even work correctly! I'm
currently making minor patches to add what had become the expected handling of
some things locally, but in general the clients work with the servers.
Hopefully, that's what you're shooting for, and hopefully, I can contribute
something to your effort. If/when you're ready to start on the interrealm code,
can you let me know what your plans are?

Thanks
-D

---2143855796-2078917053-811000485=: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 (!strchr(linebuf, '\n')) {
	  /* didn't all fit into buffer, punt */
          (void) fclose(rlm_file);
          return(expand);
	}

	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-2078917053-811000485=:14990--

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