[295] in Kerberos-V5-bugs

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

new-sn2princ.patch

daemon@ATHENA.MIT.EDU (Marc Horowitz)
Fri Feb 26 17:55:17 1993

To: krb5-bugs@MIT.EDU
Date: Fri, 26 Feb 1993 17:51:43 -0500
From: Marc Horowitz <marc@Aktis.COM>

** replacement for krb5_sname_to_principal

./lib/error_tables/krb5_err.et
./lib/os/sn2princ.c
./include/krb5/los-proto.h
	changes for rewrite of krb5_sname_to_principal


*** ./lib/error_tables/krb5_err.et.old	1992/12/03 17:16:28
--- ./lib/error_tables/krb5_err.et	1992/12/09 15:13:28
***************
*** 283,287 ****
--- 283,288 ----
  error_code KRB5_RC_REQUIRED,	"Message replay detection requires rcache parameter"
  error_code KRB5_ERR_BAD_HOSTNAME,	"Hostname cannot be canonicalized"
  error_code KRB5_ERR_HOST_REALM_UNKNOWN,	"Cannot determine realm for host"
+ error_code KRB5_ERR_BAD_NAMETYPE,	"Conversion to principal undefined for name type"
  
  end

*** ./include/krb5/los-proto.h.old	1992/12/07 15:13:32
--- ./include/krb5/los-proto.h	1992/12/07 15:15:19
***************
*** 106,112 ****
  krb5_error_code krb5_sname_to_principal
      PROTOTYPE((const char *,
  	       const char *,
! 	       krb5_boolean,
  	       krb5_principal *));
  #include <krb5/narrow.h>
  
--- 106,112 ----
  krb5_error_code krb5_sname_to_principal
      PROTOTYPE((const char *,
  	       const char *,
! 	       krb5_int32,
  	       krb5_principal *));
  #include <krb5/narrow.h>
  

*** ./lib/os/sn2princ.c.old	1992/12/03 16:55:53
--- ./lib/os/sn2princ.c	1992/12/09 15:24:44
***************
*** 36,50 ****
  #include <krb5/los-proto.h>
  #include <netdb.h>
  #include <ctype.h>
  
  krb5_error_code
  krb5_sname_to_principal(DECLARG(const char *,hostname),
  			DECLARG(const char *,sname),
! 			DECLARG(krb5_boolean,canonicalize),
  			DECLARG(krb5_principal *,ret_princ))
  OLDDECLARG(const char *,hostname)
  OLDDECLARG(const char *,sname)
! OLDDECLARG(krb5_boolean,canonicalize)
  OLDDECLARG(krb5_principal *,ret_princ)
  {
      struct hostent *hp;
--- 36,51 ----
  #include <krb5/los-proto.h>
  #include <netdb.h>
  #include <ctype.h>
+ #include <sys/param.h>
  
  krb5_error_code
  krb5_sname_to_principal(DECLARG(const char *,hostname),
  			DECLARG(const char *,sname),
! 			DECLARG(krb5_int32,type),
  			DECLARG(krb5_principal *,ret_princ))
  OLDDECLARG(const char *,hostname)
  OLDDECLARG(const char *,sname)
! OLDDECLARG(krb5_int32,type)
  OLDDECLARG(krb5_principal *,ret_princ)
  {
      struct hostent *hp;
***************
*** 51,90 ****
      char **hrealms, *remote_host;
      krb5_error_code retval;
      register char *cp;
  
!     /* copy the hostname into non-volatile storage */
  
!     if (canonicalize) {
! 	if (!(hp = gethostbyname(hostname)))
! 	    return KRB5_ERR_BAD_HOSTNAME;
! 	remote_host = strdup(hp->h_name);
!     } else {
! 	remote_host = strdup(hostname);
!     }
!     if (!remote_host)
! 	return ENOMEM;
  
!     for (cp = remote_host; *cp; cp++)
! 	if (isupper(*cp))
! 	    *cp = tolower(*cp);
  
-     if (retval = krb5_get_host_realm(remote_host, &hrealms)) {
  	free(remote_host);
  	return retval;
!     }
!     if (!hrealms[0]) {
! 	free(remote_host);
! 	xfree(hrealms);
! 	return KRB5_ERR_HOST_REALM_UNKNOWN;
      }
- 
-     retval = krb5_build_principal(ret_princ, strlen(hrealms[0]), hrealms[0],
- 				  sname, remote_host, (char *)0);
- 
-     krb5_princ_type(*ret_princ) = KRB5_NT_SRV_HST;
- 
-     free(remote_host);
-     krb5_free_host_realm(hrealms);
-     return retval;
  }
  
--- 52,114 ----
      char **hrealms, *remote_host;
      krb5_error_code retval;
      register char *cp;
+     char localname[MAXHOSTNAMELEN];
  
!     if ((type == KRB5_NT_UNKNOWN) ||
! 	(type == KRB5_NT_SRV_HST)) {
  
! 	/* convenience hack:  if hostname is NULL, use gethostbyname() */
! 
! 	if (! hostname) {
! 	    if (gethostname(localname, MAXHOSTNAMELEN))
! 		return errno;
! 	    hostname = localname;
! 	}
! 
! 	/* if sname is NULL, use "host" */
! 
! 	if (! sname) {
! 	    sname = "host";
! 	}
! 
! 	/* copy the hostname into non-volatile storage */
! 
! 	if (type == KRB5_NT_SRV_HST) {
! 	    if (!(hp = gethostbyname(hostname)))
! 		return KRB5_ERR_BAD_HOSTNAME;
! 	    remote_host = strdup(hp->h_name);
! 	} else /* type == KRB5_NT_UNKNOWN */ {
! 	    remote_host = strdup(hostname);
! 	}
! 	if (!remote_host)
! 	    return ENOMEM;
! 
! 	if (type == KRB5_NT_SRV_HST)
! 	    for (cp = remote_host; *cp; cp++)
! 		if (isupper(*cp))
! 		    *cp = tolower(*cp);
! 
! 	if (retval = krb5_get_host_realm(remote_host, &hrealms)) {
! 	    free(remote_host);
! 	    return retval;
! 	}
! 	if (!hrealms[0]) {
! 	    free(remote_host);
! 	    xfree(hrealms);
! 	    return KRB5_ERR_HOST_REALM_UNKNOWN;
! 	}
! 
! 	retval = krb5_build_principal(ret_princ, strlen(hrealms[0]),
! 				      hrealms[0], sname, remote_host,
! 				      (char *)0);
  
! 	krb5_princ_type(*ret_princ) = type;
  
  	free(remote_host);
+ 	krb5_free_host_realm(hrealms);
  	return retval;
!     } else {
! 	return KRB5_ERR_BAD_NAMETYPE;
      }
  }
  


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