diff -urp build-tree/heimdal-0.6.3/appl/kf/kfd.c build-tree.new/heimdal-0.6.3/appl/kf/kfd.c
--- build-tree/heimdal-0.6.3/appl/kf/kfd.c	2003-04-16 11:40:24.000000000 -0400
+++ build-tree.new/heimdal-0.6.3/appl/kf/kfd.c	2005-02-02 11:28:13.000000000 -0500
@@ -32,6 +32,12 @@
  */
 
 #include "kf_locl.h"
+#include "xgethostname.h"
+
+#ifndef MAXPATHLEN
+# define MAXPATHLEN 4096
+#endif
+
 RCSID("$Id: kfd.c,v 1.11 2003/04/16 15:40:24 lha Exp $");
 
 krb5_context context;
@@ -128,7 +134,7 @@ proto (int sock, const char *service)
     krb5_ticket *ticket;
     char *name;
     char ret_string[10];
-    char hostname[MAXHOSTNAMELEN];
+    char *hostname;
     krb5_data data;
     krb5_data remotename;
     krb5_data tk_file;
@@ -146,7 +152,7 @@ proto (int sock, const char *service)
     if (status)
 	krb5_err(context, 1, status, "krb5_auth_con_setaddr");
 
-    if(gethostname (hostname, sizeof(hostname)) < 0)
+    if (!(hostname = xgethostname ()))
 	krb5_err(context, 1, errno, "gethostname");
 
     status = krb5_sname_to_principal (context,
@@ -154,6 +160,9 @@ proto (int sock, const char *service)
 				      service,
 				      KRB5_NT_SRV_HST,
 				      &server);
+    if (hostname)
+	free (hostname);
+
     if (status)
 	krb5_err(context, 1, status, "krb5_sname_to_principal");
 
diff -urp build-tree/heimdal-0.6.3/appl/login/login_access.c build-tree.new/heimdal-0.6.3/appl/login/login_access.c
--- build-tree/heimdal-0.6.3/appl/login/login_access.c	2001-06-04 10:09:45.000000000 -0400
+++ build-tree.new/heimdal-0.6.3/appl/login/login_access.c	2005-02-02 11:28:14.000000000 -0500
@@ -24,6 +24,7 @@
   */
 
 #include "login_locl.h"
+#include "xgethostname.h"
 
 RCSID("$Id: login_access.c,v 1.2 2001/06/04 14:09:45 assar Exp $");
 
@@ -163,11 +164,10 @@ list_match(char *list,
 
 static char *myhostname(void)
 {
-    static char name[MAXHOSTNAMELEN + 1] = "";
+    static char *name = "";
 
     if (name[0] == 0) {
-	gethostname(name, sizeof(name));
-	name[MAXHOSTNAMELEN] = 0;
+      name = xgethostname(); 
     }
     return (name);
 }

diff -urp build-tree/heimdal-0.6.3/appl/test/tcp_server.c build-tree.new/heimdal-0.6.3/appl/test/tcp_server.c
--- build-tree/heimdal-0.6.3/appl/test/tcp_server.c	1999-12-16 05:31:08.000000000 -0500
+++ build-tree.new/heimdal-0.6.3/appl/test/tcp_server.c	2005-02-02 11:28:16.000000000 -0500
@@ -32,6 +32,8 @@
  */
 
 #include "test_locl.h"
+#include "xgethostname.h"
+
 RCSID("$Id: tcp_server.c,v 1.16 1999/12/16 10:31:08 assar Exp $");
 
 krb5_context context;
@@ -44,7 +46,7 @@ proto (int sock, const char *service)
     krb5_principal server;
     krb5_ticket *ticket;
     char *name;
-    char hostname[MAXHOSTNAMELEN];
+    char *hostname;
     krb5_data packet;
     krb5_data data;
     u_int32_t len, net_len;
@@ -61,7 +63,7 @@ proto (int sock, const char *service)
     if (status)
 	krb5_err (context, 1, status, "krb5_auth_con_setaddrs_from_fd");
 
-    if(gethostname (hostname, sizeof(hostname)) < 0)
+    if( !(hostname = xgethostname ()))
 	krb5_err (context, 1, errno, "gethostname");
 
     status = krb5_sname_to_principal (context,

diff -urp build-tree/heimdal-0.6.3/lib/gssapi/import_name.c build-tree.new/heimdal-0.6.3/lib/gssapi/import_name.c
--- build-tree/heimdal-0.6.3/lib/gssapi/import_name.c	2003-03-16 12:33:31.000000000 -0500
+++ build-tree.new/heimdal-0.6.3/lib/gssapi/import_name.c	2005-02-02 11:29:05.000000000 -0500
@@ -90,7 +90,6 @@ import_hostbased_name (OM_uint32 *minor_
     char *tmp;
     char *p;
     char *host;
-    char local_hostname[MAXHOSTNAMELEN];
 
     *output_name = NULL;
 
@@ -109,12 +108,11 @@ import_hostbased_name (OM_uint32 *minor_
 	*p = '\0';
 	host = p + 1;
     } else {
-	if (gethostname(local_hostname, sizeof(local_hostname)) < 0) {
+	if ( !(host = xgethostname()) ) {
 	    *minor_status = errno;
 	    free (tmp);
 	    return GSS_S_FAILURE;
 	}
-	host = local_hostname;
     }
 
     kerr = krb5_sname_to_principal (gssapi_krb5_context,

diff -urp build-tree/heimdal-0.6.3/lib/kafs/afssys.c build-tree.new/heimdal-0.6.3/lib/kafs/afssys.c
--- build-tree/heimdal-0.6.3/lib/kafs/afssys.c	2004-06-22 10:29:48.000000000 -0400
+++ build-tree.new/heimdal-0.6.3/lib/kafs/afssys.c	2005-02-02 11:30:33.000000000 -0500
@@ -42,8 +42,12 @@ struct procdata {
     unsigned long param1;
     unsigned long syscall;
 };
-#define VIOC_SYSCALL _IOW('C', 1, void *)
 
+#if defined __GNU__
+#define VIOC_SYSCALL 0
+#else
+#define VIOC_SYSCALL _IOW('C', 1, void *)
+#endif
 
 int _kafs_debug; /* this should be done in a better way */
 

diff -urp build-tree/heimdal-0.6.3/lib/kafs/kafs.h build-tree.new/heimdal-0.6.3/lib/kafs/kafs.h
--- build-tree/heimdal-0.6.3/lib/kafs/kafs.h	2003-04-23 14:03:21.000000000 -0400
+++ build-tree.new/heimdal-0.6.3/lib/kafs/kafs.h	2005-02-02 11:30:33.000000000 -0500
@@ -49,6 +49,11 @@
 #define _VICEIOCTL(id)  ((unsigned int ) _IOW('V', id, struct ViceIoctl))
 #endif /* _VICEIOCTL */
 
+#ifdef __GNU__
+#define _IOT_ViceIoctl \
+    _IOT (_IOTS (caddr_t), 2, _IOTS (short), 2, 0, 0)
+#endif
+
 #define VIOCSETAL		_VICEIOCTL(1)
 #define VIOCGETAL		_VICEIOCTL(2)
 #define VIOCSETTOK		_VICEIOCTL(3)

diff -urp build-tree/heimdal-0.6.3/lib/krb5/Makefile.am build-tree.new/heimdal-0.6.3/lib/krb5/Makefile.am
--- build-tree/heimdal-0.6.3/lib/krb5/Makefile.am	2005-02-02 11:23:41.000000000 -0500
+++ build-tree.new/heimdal-0.6.3/lib/krb5/Makefile.am	2005-02-02 11:29:42.000000000 -0500
@@ -130,6 +130,7 @@ libkrb5_la_SOURCES =				\
 	version.c				\
 	warn.c					\
 	write_message.c				\
+	xgethostname.c				\
 	$(ERR_FILES)
 
 libkrb5_la_LDFLAGS = -version-info 20:0:3 -symbol-version KRB5_17_HEIMDAL
@@ -181,7 +182,7 @@ man_MANS =					\
 	krb5_warn.3				\
 	verify_krb5_conf.8
 
-include_HEADERS = krb5.h krb5-protos.h krb5-private.h krb5_err.h heim_err.h k524_err.h
+include_HEADERS = krb5.h krb5-protos.h krb5-private.h krb5_err.h heim_err.h k524_err.h xgethostname.h
 
 CLEANFILES = krb5_err.c krb5_err.h heim_err.c heim_err.h k524_err.c k524_err.h
 
diff -urp build-tree/heimdal-0.6.3/lib/krb5/Makefile.in build-tree.new/heimdal-0.6.3/lib/krb5/Makefile.in
--- build-tree/heimdal-0.6.3/lib/krb5/Makefile.in	2005-02-02 11:23:41.000000000 -0500
+++ build-tree.new/heimdal-0.6.3/lib/krb5/Makefile.in	2005-02-02 11:29:42.000000000 -0500
@@ -440,6 +440,7 @@ libkrb5_la_SOURCES = \
 	version.c				\
 	warn.c					\
 	write_message.c				\
+	xgethostname.c				\
 	$(ERR_FILES)
 
 
@@ -485,7 +486,7 @@ man_MANS = \
 	verify_krb5_conf.8
 
 
-include_HEADERS = krb5.h krb5-protos.h krb5-private.h krb5_err.h heim_err.h k524_err.h
+include_HEADERS = krb5.h krb5-protos.h krb5-private.h krb5_err.h heim_err.h k524_err.h xgethostname.h
 
 CLEANFILES = krb5_err.c krb5_err.h heim_err.c heim_err.h k524_err.c k524_err.h
 subdir = lib/krb5
@@ -496,7 +497,7 @@ CONFIG_CLEAN_FILES =
 LTLIBRARIES = $(lib_LTLIBRARIES)
 
 libkrb5_la_DEPENDENCIES = $(top_builddir)/lib/asn1/libasn1.la
-am__objects_1 = krb5_err.lo heim_err.lo k524_err.lo
+am__objects_1 = krb5_err.lo heim_err.lo k524_err.lo xgethostname.lo
 am_libkrb5_la_OBJECTS = acl.lo add_et_list.lo addr_families.lo \
 	aname_to_localname.lo appdefault.lo asn1_glue.lo \
 	auth_context.lo build_ap_req.lo build_auth.lo cache.lo \

diff -urp build-tree/heimdal-0.6.3/lib/krb5/get_addrs.c build-tree.new/heimdal-0.6.3/lib/krb5/get_addrs.c
--- build-tree/heimdal-0.6.3/lib/krb5/get_addrs.c	2003-01-25 10:19:49.000000000 -0500
+++ build-tree.new/heimdal-0.6.3/lib/krb5/get_addrs.c	2005-02-02 11:29:45.000000000 -0500
@@ -32,6 +32,7 @@
  */
 
 #include "krb5_locl.h"
+#include "xgethostname.h"
 
 RCSID("$Id: get_addrs.c,v 1.45 2003/01/25 15:19:49 lha Exp $");
 
@@ -49,10 +50,10 @@ static krb5_error_code
 gethostname_fallback (krb5_context context, krb5_addresses *res)
 {
     krb5_error_code ret;
-    char hostname[MAXHOSTNAMELEN];
+    char *hostname;
     struct hostent *hostent;
 
-    if (gethostname (hostname, sizeof(hostname))) {
+    if ( !(hostname = xgethostname ())) {
 	ret = errno;
 	krb5_set_error_string (context, "gethostname: %s", strerror(ret));
 	return ret;

diff -urp build-tree/heimdal-0.6.3/lib/krb5/get_host_realm.c build-tree.new/heimdal-0.6.3/lib/krb5/get_host_realm.c
--- build-tree/heimdal-0.6.3/lib/krb5/get_host_realm.c	2002-08-28 09:36:57.000000000 -0400
+++ build-tree.new/heimdal-0.6.3/lib/krb5/get_host_realm.c	2005-02-02 11:29:45.000000000 -0500
@@ -32,6 +32,7 @@
  */
 
 #include "krb5_locl.h"
+#include "xgethostname.h"
 #include <resolve.h>
 
 RCSID("$Id: get_host_realm.c,v 1.29 2002/08/28 13:36:57 nectar Exp $");
@@ -95,7 +96,7 @@ dns_find_realm(krb5_context context,
 	       krb5_realm **realms)
 {
     static char *default_labels[] = { "_kerberos", NULL };
-    char dom[MAXHOSTNAMELEN];
+    char *dom;
     struct dns_reply *r;
     char **labels;
     int i, ret;
@@ -106,11 +107,20 @@ dns_find_realm(krb5_context context,
 	labels = default_labels;
     if(*domain == '.')
 	domain++;
+
+    dom = (char *)malloc (strlen (domain) + 2 + strlen (domain));
+    if (!dom)
+        fprintf (stderr, "No memory available");
+
     for (i = 0; labels[i] != NULL; i++) {
 	if(snprintf(dom, sizeof(dom), "%s.%s.", labels[i], domain) >=
 	    sizeof(dom))
 	    return -1;
     	r = dns_lookup(dom, "TXT");
+
+	if (dom)
+	    free (dom);
+
     	if(r != NULL) {
 	    ret = copy_txt_to_realms (r->head, realms);
 	    dns_free_data(r);
@@ -208,12 +218,9 @@ krb5_get_host_realm(krb5_context context
 		    const char *host,
 		    krb5_realm **realms)
 {
-    char hostname[MAXHOSTNAMELEN];
-
     if (host == NULL) {
-	if (gethostname (hostname, sizeof(hostname)))
+	if ( !(host = xgethostname ()))
 	    return errno;
-	host = hostname;
     }
 
     return krb5_get_host_realm_int (context, host, 1, realms);

diff -urp build-tree/heimdal-0.6.3/lib/krb5/krb5_krbhst_init.3 build-tree.new/heimdal-0.6.3/lib/krb5/krb5_krbhst_init.3
--- build-tree/heimdal-0.6.3/lib/krb5/krb5_krbhst_init.3	2003-04-16 09:58:16.000000000 -0400
+++ build-tree.new/heimdal-0.6.3/lib/krb5/krb5_krbhst_init.3	2005-02-02 11:29:45.000000000 -0500
@@ -137,7 +137,7 @@ The following code will print the KDCs o
 .Dq MY.REALM .
 .Bd -literal -offset indent
 krb5_krbhst_handle handle;
-char host[MAXHOSTNAMELEN];
+char *host = NULL;
 krb5_krbhst_init(context, "MY.REALM", KRB5_KRBHST_KDC, &handle);
 while(krb5_krbhst_next_as_string(context, handle,
 				 host, sizeof(host)) == 0)
Only in build-tree.new/heimdal-0.6.3/lib/krb5: krbhst-test
diff -urp build-tree/heimdal-0.6.3/lib/krb5/krbhst-test.c build-tree.new/heimdal-0.6.3/lib/krb5/krbhst-test.c
--- build-tree/heimdal-0.6.3/lib/krb5/krbhst-test.c	2002-08-22 23:43:18.000000000 -0400
+++ build-tree.new/heimdal-0.6.3/lib/krb5/krbhst-test.c	2005-02-02 11:29:46.000000000 -0500
@@ -87,7 +87,7 @@ main(int argc, char **argv)
     krb5_init_context (&context);
     for(i = 0; i < argc; i++) {
 	krb5_krbhst_handle handle;
-	char host[MAXHOSTNAMELEN];
+	char *host=NULL;
 
 	for (j = 0; j < sizeof(types)/sizeof(*types); ++j) {
 	    printf ("%s for %s:\n", type_str[j], argv[i]);
Only in build-tree.new/heimdal-0.6.3/lib/krb5: krbhst-test.o
diff -urp build-tree/heimdal-0.6.3/lib/krb5/krbhst.c build-tree.new/heimdal-0.6.3/lib/krb5/krbhst.c
--- build-tree/heimdal-0.6.3/lib/krb5/krbhst.c	2003-04-22 11:00:38.000000000 -0400
+++ build-tree.new/heimdal-0.6.3/lib/krb5/krbhst.c	2005-02-02 11:29:46.000000000 -0500
@@ -267,6 +267,10 @@ krb5_krbhst_format_string(krb5_context c
 	proto = "http://";
     if(host->port != host->def_port)
 	snprintf(portstr, sizeof(portstr), ":%d", host->port);
+    if(hostname) free(hostname); 
+    hostname = (char*)malloc(strlen(proto) + strlen(host->hostname) + 
+			     strlen(portstr) + 1 ); 
+    if (!hostname) fprintf(stderr,"No memory available"); 
     snprintf(hostname, hostlen, "%s%s%s", proto, host->hostname, portstr);
     return 0;
 }
@@ -725,7 +729,7 @@ gethostlist(krb5_context context, const 
     krb5_error_code ret;
     int nhost = 0;
     krb5_krbhst_handle handle;
-    char host[MAXHOSTNAMELEN];
+    char *host = NULL;
     krb5_krbhst_info *hostinfo;
 
     ret = krb5_krbhst_init(context, realm, type, &handle);

diff -urp build-tree/heimdal-0.6.3/lib/krb5/principal.c build-tree.new/heimdal-0.6.3/lib/krb5/principal.c
--- build-tree/heimdal-0.6.3/lib/krb5/principal.c	2003-08-15 10:30:07.000000000 -0400
+++ build-tree.new/heimdal-0.6.3/lib/krb5/principal.c	2005-02-02 11:29:46.000000000 -0500
@@ -698,8 +698,8 @@ krb5_425_conv_principal_ext(krb5_context
     const char *p;
     krb5_error_code ret;
     krb5_principal pr;
-    char host[MAXHOSTNAMELEN];
-    char local_hostname[MAXHOSTNAMELEN];
+    char *host;
+    char *local_hostname;
 
     /* do the following: if the name is found in the
        `v4_name_convert:host' part, is is assumed to be a `host' type
@@ -806,9 +806,11 @@ krb5_425_conv_principal_ext(krb5_context
      */
 
     if (func == NULL && 
-        gethostname (local_hostname, sizeof(local_hostname)) == 0 &&
+        !(local_hostname = xgethostname ()) &&
         strncmp(instance, local_hostname, strlen(instance)) == 0 && 
 	local_hostname[strlen(instance)] == '.') {
+      host = (char*)malloc(strlen(local_hostname) + 1); 
+      if (!host) fprintf(stderr,"No memory available for host"); 
 	strlcpy(host, local_hostname, sizeof(host));
 	goto local_host;
     }
@@ -818,6 +820,10 @@ krb5_425_conv_principal_ext(krb5_context
 	domains = krb5_config_get_strings(context, NULL, "realms", realm,
 					  "v4_domains", NULL);
 	for(d = domains; d && *d; d++){
+	  if (host) free(host);
+	  host = (char*)malloc(strlen(instance) + strlen(*d) + 2);
+	  if (!host) fprintf(stderr,"No memory available"); 
+
 	    snprintf(host, sizeof(host), "%s.%s", instance, *d);
 	    ret = krb5_make_principal(context, &pr, realm, name, host, NULL);
 	    if(func == NULL || (*func)(context, pr)){
@@ -841,6 +847,12 @@ krb5_425_conv_principal_ext(krb5_context
 	
     if (*p == '.')
 	++p;
+    if ( (strlen(instance) + strlen(p) + 2) > sizeof(host) ) {
+      free(host); 
+      host = (char*)malloc(strlen(instance) + strlen(p) + 2);
+      if (!host) fprintf(stderr,"No memory available"); 
+    }
+
     snprintf(host, sizeof(host), "%s.%s", instance, p);
 local_host:
     ret = krb5_make_principal(context, &pr, realm, name, host, NULL);
@@ -1051,7 +1063,6 @@ krb5_sname_to_principal (krb5_context co
 			 krb5_principal *ret_princ)
 {
     krb5_error_code ret;
-    char localhost[MAXHOSTNAMELEN];
     char **realms, *host = NULL;
 	
     if(type != KRB5_NT_SRV_HST && type != KRB5_NT_UNKNOWN) {
@@ -1060,8 +1071,7 @@ krb5_sname_to_principal (krb5_context co
 	return KRB5_SNAME_UNSUPP_NAMETYPE;
     }
     if(hostname == NULL) {
-	gethostname(localhost, sizeof(localhost));
-	hostname = localhost;
+	hostname = xgethostname();
     }
     if(sname == NULL)
 	sname = "host";

diff -urp build-tree/heimdal-0.6.3/lib/krb5/verify_init.c build-tree.new/heimdal-0.6.3/lib/krb5/verify_init.c
--- build-tree/heimdal-0.6.3/lib/krb5/verify_init.c	2002-08-20 10:47:59.000000000 -0400
+++ build-tree.new/heimdal-0.6.3/lib/krb5/verify_init.c	2005-02-02 11:29:46.000000000 -0500
@@ -32,6 +32,7 @@
  */
 
 #include "krb5_locl.h"
+#include "xgethostname.h"
 
 RCSID("$Id: verify_init.c,v 1.17 2002/08/20 14:47:59 joda Exp $");
 
@@ -90,9 +91,9 @@ krb5_verify_init_creds(krb5_context cont
     memset (&entry, 0, sizeof(entry));
 
     if (ap_req_server == NULL) {
-	char local_hostname[MAXHOSTNAMELEN];
+	char *local_hostname;
 
-	if (gethostname (local_hostname, sizeof(local_hostname)) < 0) {
+	if ( !(local_hostname = xgethostname () ) ) {
 	    ret = errno;
 	    krb5_set_error_string (context, "gethostname: %s",
 				   strerror(ret));

diff -urp build-tree/heimdal-0.6.3/lib/roken/getaddrinfo_hostspec.c build-tree.new/heimdal-0.6.3/lib/roken/getaddrinfo_hostspec.c
--- build-tree/heimdal-0.6.3/lib/roken/getaddrinfo_hostspec.c	2000-07-15 08:50:32.000000000 -0400
+++ build-tree.new/heimdal-0.6.3/lib/roken/getaddrinfo_hostspec.c	2005-02-02 11:30:28.000000000 -0500
@@ -48,7 +48,7 @@ roken_getaddrinfo_hostspec2(const char *
 {
     const char *p;
     char portstr[NI_MAXSERV];
-    char host[MAXHOSTNAMELEN];
+    char *host;
     struct addrinfo hints;
     int hostspec_len;
 
@@ -91,6 +91,8 @@ roken_getaddrinfo_hostspec2(const char *
     }
     snprintf (portstr, sizeof(portstr), "%u", port);
     
+    host = (char*)malloc(hostspec_len + 1);
+    if (!host) fprintf(stderr,"No memory available for host"); 
     snprintf (host, sizeof(host), "%.*s", hostspec_len, hostspec);
     return getaddrinfo (host, portstr, &hints, ai);
 }
@@ -102,3 +104,5 @@ roken_getaddrinfo_hostspec(const char *h
 {
     return roken_getaddrinfo_hostspec2(hostspec, 0, port, ai);
 }
+
+
diff -urp build-tree/heimdal-0.6.3/lib/roken/glob.c build-tree.new/heimdal-0.6.3/lib/roken/glob.c
--- build-tree/heimdal-0.6.3/lib/roken/glob.c	2005-02-02 11:23:30.000000000 -0500
+++ build-tree.new/heimdal-0.6.3/lib/roken/glob.c	2005-02-02 11:30:28.000000000 -0500
@@ -685,7 +685,11 @@ globextend(const Char *path, glob_t *pgl
 	}
 	pathv[pglob->gl_offs + pglob->gl_pathc] = NULL;
 
-	if ((pglob->gl_flags & GLOB_LIMIT) && (newsize + *limit) >= ARG_MAX) {
+	if ((pglob->gl_flags & GLOB_LIMIT)
+#ifdef ARG_MAX
+	    && (newsize + *limit) >= ARG_MAX
+#endif
+	    ) {
 		errno = 0;
 		return(GLOB_NOSPACE);
 	}
diff -urp build-tree/heimdal-0.6.3/lib/roken/roken_gethostby.c build-tree.new/heimdal-0.6.3/lib/roken/roken_gethostby.c
--- build-tree/heimdal-0.6.3/lib/roken/roken_gethostby.c	1999-12-05 08:16:44.000000000 -0500
+++ build-tree.new/heimdal-0.6.3/lib/roken/roken_gethostby.c	2005-02-02 11:30:29.000000000 -0500
@@ -250,7 +250,7 @@ int
 main(int argc, char **argv)
 {
     char *query = getenv("QUERY_STRING");
-    char host[MAXHOSTNAMELEN];
+    char *host;
     int i;
     struct hostent *he;
     
@@ -258,6 +258,8 @@ main(int argc, char **argv)
     if(query == NULL)
 	exit(0);
     he = gethostbyname(query);
+    host = (char*)malloc(strlen(he->h_name)+1);
+    if (!host) exit(1); 
     strncpy(host, he->h_name, sizeof(host));
     host[sizeof(host) - 1] = '\0';
     he = gethostbyaddr(he->h_addr, he->h_length, AF_INET);

