diff options
author | Kaleb Keithley <kaleb@freedesktop.org> | 2003-11-25 19:29:03 +0000 |
---|---|---|
committer | Kaleb Keithley <kaleb@freedesktop.org> | 2003-11-25 19:29:03 +0000 |
commit | 09cf02b0457f774bd10574c0facf1df29fb83b53 (patch) | |
tree | 4114125647494b42fe91521f69cdaf0ee055d93a | |
parent | d013d0b3ecb18ae2f1c162c6a1db89c6b4f063d3 (diff) |
XFree86 4.3.99.16 Bring the tree up to date for the Cygwin folksxf86-4_3_99_16
-rw-r--r-- | gethost.c | 146 | ||||
-rw-r--r-- | parsedpy.c | 12 | ||||
-rw-r--r-- | process.c | 180 | ||||
-rw-r--r-- | xauth.c | 6 | ||||
-rw-r--r-- | xauth.h | 13 | ||||
-rw-r--r-- | xauth.man | 9 |
6 files changed, 253 insertions, 113 deletions
@@ -1,6 +1,5 @@ /* * $Xorg: gethost.c,v 1.5 2001/02/09 02:05:38 xorgcvs Exp $ - * * Copyright 1989, 1998 The Open Group @@ -27,7 +26,7 @@ in this Software without prior written authorization from The Open Group. * Author: Jim Fulton, MIT X Consortium */ -/* $XFree86: xc/programs/xauth/gethost.c,v 3.16 2001/12/14 20:01:14 dawes Exp $ */ +/* $XFree86: xc/programs/xauth/gethost.c,v 3.21 2003/08/02 15:30:10 herrb Exp $ */ /* sorry, streams support does not really work yet */ #if defined(STREAMSCONN) && defined(SVR4) @@ -59,9 +58,9 @@ in this Software without prior written authorization from The Open Group. #include <arpa/inet.h> #ifdef SYSV #ifdef i386 -#ifndef sco +#if !defined(sco) && !defined(sun) #include <net/errno.h> -#endif /* !sco */ +#endif /* !sco && !sun */ #endif /* i386 */ #endif /* SYSV */ #endif /* !STREAMSCONN */ @@ -74,8 +73,12 @@ in this Software without prior written authorization from The Open Group. #include <netdnet/dnetdb.h> #endif +#ifndef WIN32 +#include <arpa/inet.h> +#endif + #ifdef SIGALRM -Bool nameserver_timedout = False; +static volatile Bool nameserver_timedout = False; /* @@ -106,16 +109,30 @@ char * get_hostname (auth) Xauth *auth; { - static struct hostent *hp = NULL; + static struct hostent *hp; + int af; #ifdef DNETCONN struct nodeent *np; static char nodeaddr[4 + 2 * DN_MAXADDL]; #endif /* DNETCONN */ + hp = NULL; if (auth->address_length == 0) return "Illegal Address"; #ifdef TCPCONN - if (auth->family == FamilyInternet) { + if (auth->family == FamilyInternet +#if defined(IPv6) && defined(AF_INET6) + || auth->family == FamilyInternet6 +#endif + ) + { +#if defined(IPv6) && defined(AF_INET6) + if (auth->family == FamilyInternet6) + af = AF_INET6; + else +#endif + af = AF_INET; + if (no_name_lookups == False) { #ifdef SIGALRM /* gethostbyaddr can take a LONG time if the host does not exist. Assume that if it does not respond in NAMESERVER_TIMEOUT seconds @@ -128,22 +145,39 @@ get_hostname (auth) alarm (4); if (setjmp(env) == 0) { #endif - hp = gethostbyaddr (auth->address, auth->address_length, AF_INET); + hp = gethostbyaddr (auth->address, auth->address_length, af); #ifdef SIGALRM } alarm (0); #endif + } if (hp) return (hp->h_name); - else +#if defined(IPv6) && defined(AF_INET6) + else if (af == AF_INET6) { + static char addr[INET6_ADDRSTRLEN+2]; + /* Add [] for clarity to distinguish between address & display, + like RFC 2732 for URL's. Not required, since X display syntax + always ends in :<display>, but makes it easier for people to read + and less confusing to those who expect the RFC 2732 style. */ + addr[0] = '['; + if (inet_ntop(af, auth->address, addr + 1, INET6_ADDRSTRLEN) == NULL) + return NULL; + strcat(addr, "]"); + return addr; + } +#endif + else { return (inet_ntoa(*((struct in_addr *)(auth->address)))); + } } #endif #ifdef DNETCONN if (auth->family == FamilyDECnet) { struct dn_naddr *addr_ptr = (struct dn_naddr *) auth->address; - if (np = getnodebyaddr(addr_ptr->a_addr, addr_ptr->a_len, AF_DECnet)) { + if ((no_name_lookups == False) && + (np = getnodebyaddr(addr_ptr->a_addr, addr_ptr->a_len, AF_DECnet))) { sprintf(nodeaddr, "%s:", np->n_name); } else { sprintf(nodeaddr, "%s:", dnet_htoa(auth->address)); @@ -155,7 +189,7 @@ get_hostname (auth) return (NULL); } -#ifdef TCPCONN +#if defined(TCPCONN) && (!defined(IPv6) || !defined(AF_INET6)) /* * cribbed from lib/X/XConnDis.c */ @@ -211,19 +245,25 @@ static Bool get_dnet_address (name, resultp) } #endif -char *get_address_info (family, fulldpyname, prefix, host, lenp) - int family; - char *fulldpyname; - int prefix; - char *host; - int *lenp; +struct addrlist *get_address_info ( + int family, + char *fulldpyname, + int prefix, + char *host) { - char *retval = NULL; + struct addrlist *retval = NULL; int len = 0; - char *src = NULL; + void *src = NULL; #ifdef TCPCONN +#if defined(IPv6) && defined(AF_INET6) + struct addrlist *lastrv = NULL; + struct addrinfo *firstai = NULL; + struct addrinfo *ai = NULL; + struct addrinfo hints; +#else unsigned int hostinetaddr; #endif +#endif #ifdef DNETCONN struct dn_naddr dnaddr; #endif @@ -252,10 +292,58 @@ char *get_address_info (family, fulldpyname, prefix, host, lenp) break; case FamilyInternet: /* host:0 */ #ifdef TCPCONN +#if defined(IPv6) && defined(AF_INET6) + case FamilyInternet6: + memset(&hints, 0, sizeof(hints)); + hints.ai_family = PF_UNSPEC; /* IPv4 or IPv6 */ + hints.ai_socktype = SOCK_STREAM; /* only interested in TCP */ + hints.ai_protocol = 0; + if (getaddrinfo(host,NULL,&hints,&firstai) !=0) return NULL; + for (ai = firstai; ai != NULL; ai = ai->ai_next) { + if (ai->ai_family == AF_INET) { + struct sockaddr_in *sin = (struct sockaddr_in *)ai->ai_addr; + src = &(sin->sin_addr); + len = sizeof(sin->sin_addr); + family = FamilyInternet; + } else if (ai->ai_family == AF_INET6) { + struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)ai->ai_addr; + src = &(sin6->sin6_addr); + len = sizeof(sin6->sin6_addr); + family = FamilyInternet6; + } + + if (len > 0 && src != NULL) { + struct addrlist *newrv = malloc (sizeof(struct addrlist)); + if (newrv) { + newrv->address = malloc (len); + if (newrv->address) { + memcpy(newrv->address, src, len); + newrv->next = NULL; + newrv->family = family; + newrv->len = len; + if (retval == NULL) { + lastrv = retval = newrv; + } else { + lastrv->next = newrv; + lastrv = newrv; + } + } else { + free(newrv); + } + } + } + /* reset to avoid copying into list twice */ + len = 0; + src = NULL; + } + freeaddrinfo(firstai); + break; +#else if (!get_inet_address (host, &hostinetaddr)) return NULL; src = (char *) &hostinetaddr; len = 4; /* sizeof inaddr.sin_addr, would fail on Cray */ break; +#endif /* IPv6 */ #else return NULL; #endif @@ -276,12 +364,20 @@ char *get_address_info (family, fulldpyname, prefix, host, lenp) /* * if source was provided, allocate space and copy it */ - if (len == 0 || !src) return NULL; - - retval = malloc (len); - if (retval) { - memmove( retval, src, len); - *lenp = len; + if (len > 0 && src != NULL) { + retval = malloc (sizeof(struct addrlist)); + if (retval) { + retval->address = malloc (len); + if (retval->address) { + memcpy(retval->address, src, len); + retval->next = NULL; + retval->family = family; + retval->len = len; + } else { + free(retval); + retval = NULL; + } + } } return retval; } @@ -29,7 +29,7 @@ in this Software without prior written authorization from The Open Group. * Author: Jim Fulton, MIT X Consortium */ -/* $XFree86: xc/programs/xauth/parsedpy.c,v 3.6 2001/12/14 20:01:15 dawes Exp $ */ +/* $XFree86: xc/programs/xauth/parsedpy.c,v 3.8 2003/07/18 15:53:28 tsi Exp $ */ #include <stdio.h> /* for NULL */ #include <ctype.h> /* for isascii() and isdigit() */ @@ -111,10 +111,10 @@ parse_displayname (char *displayname, if (!displayname || !displayname[0]) return False; /* must have at least :number */ - ptr = strchr(displayname, ':'); + ptr = strrchr(displayname, ':'); if (!ptr || !ptr[1]) return False; - if (ptr[1] == ':') { - if (ptr[2] == '\0') return False; + if ((ptr != displayname) && (*(ptr - 1) == ':')) { + ptr--; dnet = True; } @@ -137,6 +137,10 @@ parse_displayname (char *displayname, family = FamilyInternet; } #endif + } else if (!dnet && (*displayname == '[') && (*(ptr - 1) == ']')) { + /* Allow RFC2732-like [<IPv6NumericAddress>]:display syntax */ + family = FamilyInternet6; + host = copystring (displayname + 1, len - 2); } else { host = copystring (displayname, len); if (dnet) { @@ -26,7 +26,7 @@ other dealings in this Software without prior written authorization from The Open Group. */ -/* $XFree86: xc/programs/xauth/process.c,v 3.18 2003/02/13 02:50:22 dawes Exp $ */ +/* $XFree86: xc/programs/xauth/process.c,v 3.22 2003/07/18 15:53:28 tsi Exp $ */ /* * Author: Jim Fulton, MIT X Consortium @@ -36,6 +36,7 @@ from The Open Group. #include <ctype.h> #include <errno.h> #include <sys/stat.h> +#include <sys/socket.h> #include <signal.h> #include <X11/X.h> /* for Family constants */ @@ -43,8 +44,6 @@ from The Open Group. #include <X11/Xlib.h> #include <X11/extensions/security.h> -extern Bool nameserver_timedout; - #ifndef DEFAULT_PROTOCOL_ABBREV /* to make add command easier */ #define DEFAULT_PROTOCOL_ABBREV "." #endif @@ -462,16 +461,17 @@ read_auth_entries(FILE *fp, Bool numeric, AuthList **headp, AuthList **tailp) } static Bool -get_displayname_auth(char *displayname, Xauth *auth) +get_displayname_auth(char *displayname, AuthList **authl) { int family; char *host = NULL, *rest = NULL; int dpynum, scrnum; char *cp; - int len; - Xauth proto; int prelen = 0; + struct addrlist *addrlist_head, *addrlist_cur; + AuthList *authl_cur = NULL; + *authl = NULL; /* * check to see if the display name is of the form "host/unix:" * which is how the list routine prints out local connections @@ -485,36 +485,53 @@ get_displayname_auth(char *displayname, Xauth *auth) return False; } - proto.family = family; - proto.address = get_address_info (family, displayname, prelen, host, &len); - if (proto.address) { + addrlist_head = get_address_info(family, displayname, prelen, host); + if (addrlist_head) { char buf[40]; /* want to hold largest display num */ + unsigned short dpylen; - proto.address_length = len; buf[0] = '\0'; sprintf (buf, "%d", dpynum); - proto.number_length = strlen (buf); - if (proto.number_length <= 0) { - free (proto.address); - proto.address = NULL; - } else { - proto.number = copystring (buf, proto.number_length); + dpylen = strlen (buf); + if (dpylen > 0) { + for (addrlist_cur = addrlist_head; addrlist_cur != NULL; + addrlist_cur = addrlist_cur->next) { + AuthList *newal = malloc(sizeof(AuthList)); + Xauth *auth = malloc(sizeof(Xauth)); + + if ((newal == NULL) || (auth == NULL)) { + if (newal != NULL) free(newal); + if (auth != NULL) free(auth); + break; + } + + if (authl_cur == NULL) { + *authl = authl_cur = newal; + } else { + authl_cur->next = newal; + authl_cur = newal; + } + + newal->next = NULL; + newal->auth = auth; + + auth->family = addrlist_cur->family; + auth->address = addrlist_cur->address; + auth->address_length = addrlist_cur->len; + auth->number = copystring(buf, dpylen); + auth->number_length = dpylen; + auth->name = NULL; + auth->name_length = 0; + auth->data = NULL; + auth->data_length = 0; + } } } if (host) free (host); if (rest) free (rest); - if (proto.address) { - auth->family = proto.family; - auth->address = proto.address; - auth->address_length = proto.address_length; - auth->number = proto.number; - auth->number_length = proto.number_length; - auth->name = NULL; - auth->name_length = 0; - auth->data = NULL; - auth->data_length = 0; + if (*authl != NULL) { return True; } else { return False; @@ -606,7 +623,7 @@ static Bool xauth_modified = False; /* if added, removed, or merged */ static Bool xauth_allowed = True; /* if allowed to write auth file */ static Bool xauth_locked = False; /* if has been locked */ static char *xauth_filename = NULL; -static Bool dieing = False; +static volatile Bool dieing = False; #ifdef SIGNALRETURNSINT #define _signal_t int @@ -941,7 +958,7 @@ fprintfhex(register FILE *fp, int len, char *cp) free(hex); } -int +static int dump_numeric(register FILE *fp, register Xauth *auth) { fprintf (fp, "%04x", auth->family); /* unsigned short */ @@ -975,6 +992,9 @@ dump_entry(char *inputfilename, int lineno, Xauth *auth, char *data) fprintf (fp, "/unix"); break; case FamilyInternet: +#if defined(IPv6) && defined(AF_INET6) + case FamilyInternet6: +#endif case FamilyDECnet: dpyname = get_hostname (auth); if (dpyname) { @@ -1124,7 +1144,7 @@ iterdpy (char *inputfilename, int lineno, int start, int i; int status; int errors = 0; - Xauth proto; + AuthList *proto_head, *proto; AuthList *l, *next; /* @@ -1132,8 +1152,7 @@ iterdpy (char *inputfilename, int lineno, int start, */ for (i = start; i < argc; i++) { char *displayname = argv[i]; - proto.address = proto.number = NULL; - if (!get_displayname_auth (displayname, &proto)) { + if (!get_displayname_auth (displayname, &proto_head)) { prefix (inputfilename, lineno); baddisplayname (displayname, argv[0]); errors++; @@ -1141,23 +1160,34 @@ iterdpy (char *inputfilename, int lineno, int start, } status = 0; for (l = xauth_head; l; l = next) { + Bool matched = False; + next = l->next; - if (match_auth_dpy (&proto, l->auth)) { - if (yfunc) { - status = (*yfunc) (inputfilename, lineno, - l->auth, data); - if (status < 0) break; + for (proto = proto_head; proto; proto = proto->next) { + if (match_auth_dpy (proto->auth, l->auth)) { + matched = True; + if (yfunc) { + status = (*yfunc) (inputfilename, lineno, + l->auth, data); + if (status < 0) break; + } } - } else { + } + if (matched == False) { if (nfunc) { status = (*nfunc) (inputfilename, lineno, l->auth, data); - if (status < 0) break; } } + if (status < 0) break; + } + for (proto = proto_head; proto ; proto = next) { + next = proto->next; + if (proto->auth->address) free (proto->auth->address); + if (proto->auth->number) free (proto->auth->number); + free (proto->auth); + free (proto); } - if (proto.address) free (proto.address); - if (proto.number) free (proto.number); if (status < 0) { errors -= status; /* since status is negative */ break; @@ -1427,8 +1457,7 @@ do_add(char *inputfilename, int lineno, int argc, char **argv) char *protoname; char *hexkey; char *key; - Xauth *auth; - AuthList *list; + AuthList *list, *list_cur, *list_next; if (argc != 4 || !argv[1] || !argv[2] || !argv[3]) { prefix (inputfilename, lineno); @@ -1459,19 +1488,9 @@ do_add(char *inputfilename, int lineno, int argc, char **argv) } } - auth = (Xauth *) malloc (sizeof (Xauth)); - if (!auth) { - prefix (inputfilename, lineno); - fprintf (stderr, "unable to allocate %ld bytes for Xauth structure\n", - (unsigned long)sizeof (Xauth)); - free (key); - return 1; - } - - if (!get_displayname_auth (dpyname, auth)) { + if (!get_displayname_auth (dpyname, &list)) { prefix (inputfilename, lineno); baddisplayname (dpyname, argv[0]); - free (auth); free (key); return 1; } @@ -1483,33 +1502,38 @@ do_add(char *inputfilename, int lineno, int argc, char **argv) protoname = DEFAULT_PROTOCOL; } - auth->name_length = strlen (protoname); - auth->name = copystring (protoname, auth->name_length); - if (!auth->name) { - prefix (inputfilename, lineno); - fprintf (stderr, "unable to allocate %d character protocol name\n", - auth->name_length); - free (auth); - free (key); - return 1; - } - auth->data_length = len; - auth->data = key; + for (list_cur = list; list_cur != NULL; list_cur = list_cur->next) { + Xauth *auth = list_cur->auth; - list = (AuthList *) malloc (sizeof (AuthList)); - if (!list) { - prefix (inputfilename, lineno); - fprintf (stderr, "unable to allocate %ld bytes for auth list\n", - (unsigned long)sizeof (AuthList)); - free (auth); - free (key); - free (auth->name); - return 1; + auth->name_length = strlen (protoname); + auth->name = copystring (protoname, auth->name_length); + if (!auth->name) { + prefix (inputfilename, lineno); + fprintf (stderr, "unable to allocate %d character protocol name\n", + auth->name_length); + for (list_cur = list; list_cur != NULL; list_cur = list_next) { + list_next = list_cur->next; + XauDisposeAuth(list_cur->auth); + free(list_cur); + } + free (key); + return 1; + } + auth->data_length = len; + auth->data = copystring(key, len); + if (!auth->data) { + prefix(inputfilename, lineno); + fprintf(stderr, "unable to allocate %d bytes for key\n", len); + for (list_cur = list; list_cur != NULL; list_cur = list_next) { + list_next = list_cur->next; + XauDisposeAuth(list_cur->auth); + free(list_cur); + } + free(key); + return 1; + } } - - list->next = NULL; - list->auth = auth; - + free(key); /* * merge it in; note that merge will deal with allocation */ @@ -28,7 +28,7 @@ in this Software without prior written authorization from The Open Group. * * * Author: Jim Fulton, MIT X Consortium */ -/* $XFree86: xc/programs/xauth/xauth.c,v 1.5 2001/12/14 20:01:15 dawes Exp $ */ +/* $XFree86: xc/programs/xauth/xauth.c,v 1.6 2003/07/09 15:27:37 tsi Exp $ */ #include "xauth.h" @@ -40,6 +40,7 @@ char *ProgramName; /* argv[0], set at top of main() */ int verbose = -1; /* print certain messages */ Bool ignore_locks = False; /* for error recovery */ Bool break_locks = False; /* for error recovery */ +Bool no_name_lookups = False; /* show addresses instead of names */ /* * local data @@ -127,6 +128,9 @@ main(int argc, char *argv[]) case 'i': /* -i */ ignore_locks = True; continue; + case 'n': /* -n */ + no_name_lookups = True; + continue; default: usage (); } @@ -26,7 +26,7 @@ in this Software without prior written authorization from The Open Group. * * * Author: Jim Fulton, MIT X Consortium */ -/* $XFree86: xc/programs/xauth/xauth.h,v 1.6 2001/12/14 20:01:15 dawes Exp $ */ +/* $XFree86: xc/programs/xauth/xauth.h,v 1.7 2003/07/09 15:27:37 tsi Exp $ */ #include <stdio.h> #include <X11/Xos.h> @@ -43,16 +43,23 @@ extern char *ProgramName; #include <stdlib.h> +struct addrlist { + struct addrlist *next; + char *address; + int len; + int family; +}; + extern char *get_hostname ( Xauth *auth ); -extern char *get_address_info ( int family, char *fulldpyname, int prefix, char *host, int *lenp ); +extern struct addrlist *get_address_info ( int family, char *fulldpyname, int prefix, char *host); extern char *copystring ( char *src, int len ); extern char *get_local_hostname ( char *buf, int maxlen ); extern Bool parse_displayname ( char *displayname, int *familyp, char **hostp, int *dpynump, int *scrnump, char **restp ); extern int auth_initialize ( char *authfilename ); extern int auth_finalize ( void ); extern int process_command ( char *inputfilename, int lineno, int argc, char **argv ); -extern int dump_numeric ( FILE *fp, Xauth *auth ); extern int print_help ( FILE *fp, char *cmd, char *prefix ); extern int verbose; extern Bool ignore_locks; extern Bool break_locks; +extern Bool no_name_lookups; @@ -23,14 +23,14 @@ .\" other dealings in this Software without prior written authorization .\" from The Open Group. .\" -.\" $XFree86: xc/programs/xauth/xauth.man,v 1.7 2001/12/14 20:01:15 dawes Exp $ +.\" $XFree86: xc/programs/xauth/xauth.man,v 1.9 2003/07/09 15:27:37 tsi Exp $ .\" .TH XAUTH 1 __xorgversion__ .SH NAME xauth \- X authority file utility .SH SYNOPSIS .B xauth -[ \fB\-f\fP \fIauthfile\fP ] [ \fB\-vqib\fP ] [ \fIcommand arg ...\fP ] +[ \fB\-f\fP \fIauthfile\fP ] [ \fB\-vqibn\fP ] [ \fIcommand arg ...\fP ] .SH DESCRIPTION .PP The \fIxauth\fP program is used to edit and display the authorization @@ -73,6 +73,11 @@ that have been locked by other programs (usually \fIxdm\fP or another .B \-b This option indicates that \fIxauth\fP should attempt to break any authority file locks before proceeding. Use this option only to clean up stale locks. +.TP 8 +.B \-n +This option indicates that \fIxauth\fP should not attempt to resolve any +hostnames, but should simply always print the host address as stored in +the authority file. .SH COMMANDS The following commands may be used to manipulate authority files: .TP 8 |