From 5c3b3b95259a2b73e7dbabcbda6996ded56b64d3 Mon Sep 17 00:00:00 2001 From: Chris Provenzano Date: Wed, 26 Apr 1995 03:04:19 +0000 Subject: [PATCH] * Makefile.in : Added source files mk_faddr.c and genaddrs.c. * mk_faddr.c (krb5_mk_fulladdr()): Makes a full address from a struct sockaddr_in. * genaddrs.c (krb5_auth_con_genaddrs()) : Generate a full address from the active file descriptor and place it in the auth_context for the calls mk_safe(), mk_priv(), mk_safe(), rd_cred(), rd_priv(), and rd_safe(). * gen_rname.c (krb5_gen_replay_name()) : Fixed to take any type of krb5_address and generate a rcache name. * os-proto.h (krb5_make_full_ipaddr()) : Removed prototype. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@5490 dc483132-0cff-0310-8789-dd5450dbe970 --- src/lib/krb5/os/ChangeLog | 14 ++++++ src/lib/krb5/os/Makefile.in | 4 ++ src/lib/krb5/os/gen_rname.c | 38 ++++++--------- src/lib/krb5/os/genaddrs.c | 95 +++++++++++++++++++++++++++++++++++++ src/lib/krb5/os/mk_faddr.c | 90 +++++++++++++++++++++++++++++++++++ src/lib/krb5/os/os-proto.h | 8 ---- 6 files changed, 217 insertions(+), 32 deletions(-) create mode 100644 src/lib/krb5/os/genaddrs.c create mode 100644 src/lib/krb5/os/mk_faddr.c diff --git a/src/lib/krb5/os/ChangeLog b/src/lib/krb5/os/ChangeLog index 270a1e578..15e16ca7a 100644 --- a/src/lib/krb5/os/ChangeLog +++ b/src/lib/krb5/os/ChangeLog @@ -1,3 +1,17 @@ + +Tue Apr 25 21:58:23 1995 Chris Procenzano (proven@mit.edu) + + * Makefile.in : Added source files mk_faddr.c and genaddrs.c. + * mk_faddr.c (krb5_mk_fulladdr()): Makes a full address from + a struct sockaddr_in. + * genaddrs.c (krb5_auth_con_genaddrs()) : Generate a full address + from the active file descriptor and place it in the + auth_context for the calls mk_safe(), mk_priv(), mk_safe(), + rd_cred(), rd_priv(), and rd_safe(). + * gen_rname.c (krb5_gen_replay_name()) : Fixed to take any type of + krb5_address and generate a rcache name. + * os-proto.h (krb5_make_full_ipaddr()) : Removed prototype. + Tue Apr 25 04:50:13 1995 Chris Procenzano (proven@mit.edu) * locate_kdc.c (krb5_locate_kdc()): Pass a NUL terminated realm diff --git a/src/lib/krb5/os/Makefile.in b/src/lib/krb5/os/Makefile.in index 98a84689a..d974833be 100644 --- a/src/lib/krb5/os/Makefile.in +++ b/src/lib/krb5/os/Makefile.in @@ -14,6 +14,7 @@ OBJS= \ full_ipadr.$(OBJEXT) \ get_krbhst.$(OBJEXT) \ gen_port.$(OBJEXT) \ + genaddrs.$(OBJEXT) \ gen_rname.$(OBJEXT) \ gmt_mktime.$(OBJEXT) \ hst_realm.$(OBJEXT) \ @@ -21,6 +22,7 @@ OBJS= \ krbfileio.$(OBJEXT) \ ktdefname.$(OBJEXT) \ kuserok.$(OBJEXT) \ + mk_faddr.$(OBJEXT) \ localaddr.$(OBJEXT) \ locate_kdc.$(OBJEXT) \ lock_file.$(OBJEXT) \ @@ -49,6 +51,7 @@ SRCS= \ $(srcdir)/full_ipadr.c \ $(srcdir)/get_krbhst.c \ $(srcdir)/gen_port.c \ + $(srcdir)/genaddrs.c \ $(srcdir)/gen_rname.c \ $(srcdir)/gmt_mktime.c \ $(srcdir)/hst_realm.c \ @@ -56,6 +59,7 @@ SRCS= \ $(srcdir)/krbfileio.c \ $(srcdir)/ktdefname.c \ $(srcdir)/kuserok.c \ + $(srcdir)/mk_faddr.c \ $(srcdir)/localaddr.c \ $(srcdir)/locate_kdc.c \ $(srcdir)/lock_file.c \ diff --git a/src/lib/krb5/os/gen_rname.c b/src/lib/krb5/os/gen_rname.c index 50c17242c..8605d1728 100644 --- a/src/lib/krb5/os/gen_rname.c +++ b/src/lib/krb5/os/gen_rname.c @@ -31,32 +31,22 @@ krb5_error_code krb5_gen_replay_name(context, address, uniq, string) - krb5_context context; - const krb5_address *address; - const char *uniq; - char **string; + krb5_context context; + const krb5_address * address; + const char * uniq; + char ** string; { -#ifdef KRB5_USE_INET - krb5_int16 port; - krb5_int32 addr; - register krb5_error_code retval; - register char *tmp, *tmp2; - struct in_addr inaddr; + char * tmp; + int i; - if (retval = krb5_unpack_full_ipaddr(context, address, &addr, &port)) - return retval; - inaddr.s_addr = addr; - - tmp = inet_ntoa(inaddr); - tmp2 = malloc(strlen(uniq)+strlen(tmp)+1+1+5); /* 1 for NUL, - 1 for ,, - 5 for digits (65535 is max) */ - if (!tmp2) + if ((*string = malloc(strlen(uniq) + (address->length * 2) + 1)) == NULL) return ENOMEM; - (void) sprintf(tmp2, "%s%s,%u",uniq,tmp,ntohs(port)); - *string = tmp2; + + sprintf(*string, "%s", uniq); + tmp = (*string) + strlen(uniq); + for (i = 0; i < address->length; i++) { + sprintf(tmp, "%.2x", address->contents[i] & 0xff); + tmp += 2; + } return 0; -#else - return KRB5_PROG_ATYPE_NOSUPP; -#endif } diff --git a/src/lib/krb5/os/genaddrs.c b/src/lib/krb5/os/genaddrs.c new file mode 100644 index 000000000..1ca9dee01 --- /dev/null +++ b/src/lib/krb5/os/genaddrs.c @@ -0,0 +1,95 @@ +/* + * lib/krb5/os/genaddrs.c + * + * Copyright 1995 by the Massachusetts Institute of Technology. + * All Rights Reserved. + * + * Export of this software from the United States of America may + * require a specific license from the United States Government. + * It is the responsibility of any person or organization contemplating + * export to obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + * + * + * Take an IP addr & port and generate a full IP address. + */ + +#define NEED_SOCKETS +#include "k5-int.h" +#include "os-proto.h" + +#ifndef _WINSOCKAPI_ +#include +#endif + +krb5_error_code INTERFACE +krb5_auth_con_genaddrs(context, auth_context, fd, flags) + krb5_context context; + krb5_auth_context * auth_context; + int fd, flags; +{ + krb5_error_code retval; + krb5_address * laddr; + krb5_address * raddr; + +#ifdef KRB5_USE_INET + struct sockaddr_in saddr; + krb5_address lcaddr; + krb5_address rcaddr; + int ssize; + + ssize = sizeof(struct sockaddr); + if ((flags & KRB5_AUTH_CONTEXT_GENERATE_LOCAL_FULL_ADDR) || + (flags & KRB5_AUTH_CONTEXT_GENERATE_LOCAL_ADDR)) { + if (retval = getsockname(fd, &saddr, &ssize)) + return retval; + + if (flags & KRB5_AUTH_CONTEXT_GENERATE_LOCAL_FULL_ADDR) { + if (retval = krb5_make_fulladdr(context, &saddr, &lcaddr)) + return retval; + } else { + lcaddr.contents = (krb5_octet *)&saddr.sin_addr; + lcaddr.length = sizeof(saddr.sin_addr); + lcaddr.addrtype = ADDRTYPE_INET; + } + laddr = &lcaddr; + } else { + laddr = NULL; + } + + if ((flags & KRB5_AUTH_CONTEXT_GENERATE_REMOTE_FULL_ADDR) || + (flags & KRB5_AUTH_CONTEXT_GENERATE_REMOTE_ADDR)) { + if (retval = getpeername(fd, &saddr, &ssize)) + return retval; + + if (flags & KRB5_AUTH_CONTEXT_GENERATE_REMOTE_FULL_ADDR) { + if (retval = krb5_make_fulladdr(context, &saddr, &rcaddr)) { + if (flags & KRB5_AUTH_CONTEXT_GENERATE_LOCAL_FULL_ADDR) + krb5_xfree(laddr->contents); + return retval; + } + } else { + rcaddr.contents = (krb5_octet *)&saddr.sin_addr; + rcaddr.length = sizeof(saddr.sin_addr); + rcaddr.addrtype = ADDRTYPE_INET; + } + raddr = &rcaddr; + } else { + raddr = NULL; + } + + return (krb5_auth_con_setaddrs(context, auth_context, laddr, raddr)); +#else + return KRB5_PROG_ATYPE_NOSUPP; +#endif +} diff --git a/src/lib/krb5/os/mk_faddr.c b/src/lib/krb5/os/mk_faddr.c new file mode 100644 index 000000000..3d090edd8 --- /dev/null +++ b/src/lib/krb5/os/mk_faddr.c @@ -0,0 +1,90 @@ +/* + * lib/krb5/os/full_ipadr.c + * + * Copyright 1995 by the Massachusetts Institute of Technology. + * All Rights Reserved. + * + * Export of this software from the United States of America may + * require a specific license from the United States Government. + * It is the responsibility of any person or organization contemplating + * export to obtain such a license before exporting. + * + * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and + * distribute this software and its documentation for any purpose and + * without fee is hereby granted, provided that the above copyright + * notice appear in all copies and that both that copyright notice and + * this permission notice appear in supporting documentation, and that + * the name of M.I.T. not be used in advertising or publicity pertaining + * to distribution of the software without specific, written prior + * permission. M.I.T. makes no representations about the suitability of + * this software for any purpose. It is provided "as is" without express + * or implied warranty. + * + * + * Take an IP addr & port and generate a full IP address. + */ + +#define NEED_SOCKETS +#include "k5-int.h" + +#ifdef KRB5_USE_INET + +#include "os-proto.h" +#ifndef _WINSOCKAPI_ +#include +#endif + +krb5_error_code INTERFACE +krb5_make_fulladdr(context, saddr, kaddr) + krb5_context context; + struct sockaddr_in * saddr; + krb5_address * kaddr; +{ + krb5_int32 smushaddr = (krb5_int32)saddr->sin_addr.s_addr; /* net order */ + krb5_int16 smushport = (krb5_int16)saddr->sin_port; /* ditto */ + register krb5_octet * marshal; + krb5_int32 tmp32; + krb5_int16 tmp16; + + kaddr->addrtype = ADDRTYPE_ADDRPORT; + kaddr->length = sizeof(saddr->sin_addr) + sizeof(saddr->sin_port) + + (4 * sizeof(krb5_int32)); + + if (!(kaddr->contents = (krb5_octet *)malloc(kaddr->length))) + return ENOMEM; + + marshal = kaddr->contents; + + tmp16 = ADDRTYPE_INET; + *marshal++ = 0x00; + *marshal++ = 0x00; + *marshal++ = tmp16 & 0xff; + *marshal++ = (tmp16 >> 8) & 0xff; + + tmp32 = sizeof(smushaddr); + *marshal++ = tmp32 & 0xff; + *marshal++ = (tmp32 >> 8) & 0xff; + *marshal++ = (tmp32 >> 16) & 0xff; + *marshal++ = (tmp32 >> 24) & 0xff; + + (void) memcpy((char *)marshal, (char *)&smushaddr, sizeof(smushaddr)); + marshal += sizeof(smushaddr); + + tmp16 = ADDRTYPE_IPPORT; + *marshal++ = 0x00; + *marshal++ = 0x00; + *marshal++ = tmp16 & 0xff; + *marshal++ = (tmp16 >> 8) & 0xff; + + tmp32 = sizeof(smushport); + *marshal++ = tmp32 & 0xff; + *marshal++ = (tmp32 >> 8) & 0xff; + *marshal++ = (tmp32 >> 16) & 0xff; + *marshal++ = (tmp32 >> 24) & 0xff; + + (void) memcpy((char *)marshal, (char *)&smushport, sizeof(smushport)); + marshal += sizeof(smushport); + + return 0; +} +#endif diff --git a/src/lib/krb5/os/os-proto.h b/src/lib/krb5/os/os-proto.h index f23bb6646..e73610d5f 100644 --- a/src/lib/krb5/os/os-proto.h +++ b/src/lib/krb5/os/os-proto.h @@ -42,20 +42,12 @@ krb5_error_code krb5_unpack_full_ipaddr krb5_int32 *, krb5_int16 *)); -#ifdef NARROW_PROTOTYPES -krb5_error_code krb5_make_full_ipaddr - PROTOTYPE((krb5_context, - krb5_int32, - krb5_int16, - krb5_address **)); -#else krb5_error_code krb5_make_full_ipaddr PROTOTYPE((krb5_context, krb5_int32, int, /* unsigned short promotes to signed int */ krb5_address **)); -#endif /* NARROW_PROTOTYPES */ #endif /* KRB5_USE_INET */ #endif /* KRB5_LIBOS_INT_PROTO__ */ -- 2.26.2