diff options
Diffstat (limited to 'os')
-rw-r--r-- | os/WaitFor.c | 343 | ||||
-rw-r--r-- | os/access.c | 325 | ||||
-rw-r--r-- | os/auth.c | 26 | ||||
-rw-r--r-- | os/connection.c | 242 | ||||
-rw-r--r-- | os/io.c | 96 | ||||
-rw-r--r-- | os/lbxio.c | 80 | ||||
-rw-r--r-- | os/oscolor.c | 39 | ||||
-rw-r--r-- | os/osdep.h | 4 | ||||
-rw-r--r-- | os/osinit.c | 16 | ||||
-rw-r--r-- | os/rpcauth.c | 31 | ||||
-rw-r--r-- | os/utils.c | 398 | ||||
-rw-r--r-- | os/xalloc.c | 8 | ||||
-rw-r--r-- | os/xdmauth.c | 81 | ||||
-rw-r--r-- | os/xdmcp.c | 611 |
14 files changed, 1318 insertions, 982 deletions
diff --git a/os/WaitFor.c b/os/WaitFor.c index 76fa67327..221296d11 100644 --- a/os/WaitFor.c +++ b/os/WaitFor.c @@ -1,4 +1,4 @@ -/* $XFree86: xc/programs/Xserver/os/WaitFor.c,v 3.38 2002/05/31 18:46:05 dawes Exp $ */ +/* $XFree86: xc/programs/Xserver/os/WaitFor.c,v 3.43 2003/10/29 04:17:22 dawes Exp $ */ /*********************************************************** Copyright 1987, 1998 The Open Group @@ -112,7 +112,7 @@ struct _OsTimerRec { }; static void DoTimer(OsTimerPtr timer, CARD32 now, OsTimerPtr *prev); -static OsTimerPtr timers; +static OsTimerPtr timers = NULL; /***************** * WaitForSomething: @@ -131,18 +131,12 @@ static OsTimerPtr timers; * pClientsReady is an array to store ready client->index values into. *****************/ -static INT32 timeTilFrob = 0; /* while screen saving */ - int -WaitForSomething(pClientsReady) - int *pClientsReady; +WaitForSomething(int *pClientsReady) { int i; struct timeval waittime, *wt; INT32 timeout = 0; -#ifdef DPMSExtension - INT32 standbyTimeout = 0, suspendTimeout = 0, offTimeout = 0; -#endif fd_set clientsReadable; fd_set clientsWritable; int curclient; @@ -189,138 +183,17 @@ WaitForSomething(pClientsReady) else { #endif -#ifdef DPMSExtension - if (ScreenSaverTime > 0 || DPMSEnabled || timers) -#else - if (ScreenSaverTime > 0 || timers) -#endif - now = GetTimeInMillis(); - wt = NULL; + wt = NULL; if (timers) - { - while (timers && (int) (timers->expires - now) <= 0) - DoTimer(timers, now, &timers); - if (timers) - { - timeout = timers->expires - now; - waittime.tv_sec = timeout / MILLI_PER_SECOND; - waittime.tv_usec = (timeout % MILLI_PER_SECOND) * - (1000000 / MILLI_PER_SECOND); - wt = &waittime; - } - } - if (ScreenSaverTime > 0 -#ifdef DPMSExtension - || (DPMSEnabled && - (DPMSStandbyTime > 0 || DPMSSuspendTime > 0 || DPMSOffTime > 0)) -#endif - ) { -#ifdef DPMSExtension - if (ScreenSaverTime > 0) -#endif - timeout = (ScreenSaverTime - - (now - lastDeviceEventTime.milliseconds)); -#ifdef DPMSExtension - if (DPMSStandbyTime > 0) - standbyTimeout = (DPMSStandbyTime - - (now - lastDeviceEventTime.milliseconds)); - if (DPMSSuspendTime > 0) - suspendTimeout = (DPMSSuspendTime - - (now - lastDeviceEventTime.milliseconds)); - if (DPMSOffTime > 0) - offTimeout = (DPMSOffTime - - (now - lastDeviceEventTime.milliseconds)); -#endif /* DPMSExtension */ - - if ( - timeout <= 0 -#ifdef DPMSExtension - && ScreenSaverTime > 0 -#endif /* DPMSExtension */ - ) { - INT32 timeSinceSave; - - timeSinceSave = -timeout; - if (timeSinceSave >= timeTilFrob && timeTilFrob >= 0) - { - ResetOsBuffers(); /* not ideal, but better than nothing */ - SaveScreens(SCREEN_SAVER_ON, ScreenSaverActive); -#ifdef DPMSExtension - if (ScreenSaverInterval > 0 && - DPMSPowerLevel == DPMSModeOn) -#else - if (ScreenSaverInterval) -#endif /* DPMSExtension */ - /* round up to the next ScreenSaverInterval */ - timeTilFrob = ScreenSaverInterval * - ((timeSinceSave + ScreenSaverInterval) / - ScreenSaverInterval); - else - timeTilFrob = -1; - } - timeout = timeTilFrob - timeSinceSave; - } - else - { - if (ScreenSaverTime > 0 && timeout > ScreenSaverTime) - timeout = ScreenSaverTime; - timeTilFrob = 0; - } -#ifdef DPMSExtension - if (DPMSEnabled) - { - if (standbyTimeout > 0 - && (timeout <= 0 || timeout > standbyTimeout)) - timeout = standbyTimeout; - if (suspendTimeout > 0 - && (timeout <= 0 || timeout > suspendTimeout)) - timeout = suspendTimeout; - if (offTimeout > 0 - && (timeout <= 0 || timeout > offTimeout)) - timeout = offTimeout; - } -#endif - if (timeout > 0 && (!wt || timeout < (int) (timers->expires - now))) - { - waittime.tv_sec = timeout / MILLI_PER_SECOND; - waittime.tv_usec = (timeout % MILLI_PER_SECOND) * - (1000000 / MILLI_PER_SECOND); - wt = &waittime; - } -#ifdef DPMSExtension - /* don't bother unless it's switched on */ - if (DPMSEnabled) { - /* - * If this mode's enabled, and if the time's come - * and if we're still at a lesser mode, do it now. - */ - if (DPMSStandbyTime > 0) { - if (standbyTimeout <= 0) { - if (DPMSPowerLevel < DPMSModeStandby) { - DPMSSet(DPMSModeStandby); - } - } - } - /* - * and ditto. Note that since these modes can have the - * same timeouts, they can happen at the same time. - */ - if (DPMSSuspendTime > 0) { - if (suspendTimeout <= 0) { - if (DPMSPowerLevel < DPMSModeSuspend) { - DPMSSet(DPMSModeSuspend); - } - } - } - if (DPMSOffTime > 0) { - if (offTimeout <= 0) { - if (DPMSPowerLevel < DPMSModeOff) { - DPMSSet(DPMSModeOff); - } - } - } - } -#endif + { + now = GetTimeInMillis(); + timeout = timers->expires - now; + if (timeout < 0) + timeout = 0; + waittime.tv_sec = timeout / MILLI_PER_SECOND; + waittime.tv_usec = (timeout % MILLI_PER_SECOND) * + (1000000 / MILLI_PER_SECOND); + wt = &waittime; } XFD_COPYSET(&AllSockets, &LastSelectMask); #ifdef SMART_SCHEDULE @@ -399,18 +272,42 @@ WaitForSomething(pClientsReady) break; } #endif + if (*checkForInput[0] != *checkForInput[1]) + return 0; + if (timers) { + int expired = 0; now = GetTimeInMillis(); + if ((int) (timers->expires - now) <= 0) + expired = 1; + while (timers && (int) (timers->expires - now) <= 0) DoTimer(timers, now, &timers); + + if (expired) + return 0; } - if (*checkForInput[0] != *checkForInput[1]) - return 0; } else { fd_set tmp_set; + + if (*checkForInput[0] == *checkForInput[1]) { + if (timers) + { + int expired = 0; + now = GetTimeInMillis(); + if ((int) (timers->expires - now) <= 0) + expired = 1; + + while (timers && (int) (timers->expires - now) <= 0) + DoTimer(timers, now, &timers); + + if (expired) + return 0; + } + } #ifdef SMART_SCHEDULE if (someReady) XFD_ORSET(&LastSelectMask, &ClientsWithInput, &LastSelectMask); @@ -511,8 +408,7 @@ WaitForSomething(pClientsReady) /* * This is not always a macro. */ -ANYSET(src) - FdMask *src; +ANYSET(FdMask *src) { int i; @@ -537,12 +433,8 @@ DoTimer(OsTimerPtr timer, CARD32 now, OsTimerPtr *prev) } OsTimerPtr -TimerSet(timer, flags, millis, func, arg) - register OsTimerPtr timer; - int flags; - CARD32 millis; - OsTimerCallback func; - pointer arg; +TimerSet(OsTimerPtr timer, int flags, CARD32 millis, + OsTimerCallback func, pointer arg) { register OsTimerPtr *prev; CARD32 now = GetTimeInMillis(); @@ -573,7 +465,7 @@ TimerSet(timer, flags, millis, func, arg) timer->expires = millis; timer->callback = func; timer->arg = arg; - if (millis <= now) + if ((int) (millis - now) <= 0) { timer->next = NULL; millis = (*timer->callback)(timer, now, timer->arg); @@ -590,10 +482,9 @@ TimerSet(timer, flags, millis, func, arg) } Bool -TimerForce(timer) - register OsTimerPtr timer; +TimerForce(OsTimerPtr timer) { - register OsTimerPtr *prev; + OsTimerPtr *prev; for (prev = &timers; *prev; prev = &(*prev)->next) { @@ -608,10 +499,9 @@ TimerForce(timer) void -TimerCancel(timer) - register OsTimerPtr timer; +TimerCancel(OsTimerPtr timer) { - register OsTimerPtr *prev; + OsTimerPtr *prev; if (!timer) return; @@ -626,8 +516,7 @@ TimerCancel(timer) } void -TimerFree(timer) - register OsTimerPtr timer; +TimerFree(OsTimerPtr timer) { if (!timer) return; @@ -636,16 +525,16 @@ TimerFree(timer) } void -TimerCheck() +TimerCheck(void) { - register CARD32 now = GetTimeInMillis(); + CARD32 now = GetTimeInMillis(); while (timers && (int) (timers->expires - now) <= 0) DoTimer(timers, now, &timers); } void -TimerInit() +TimerInit(void) { OsTimerPtr timer; @@ -655,3 +544,133 @@ TimerInit() xfree(timer); } } + +static CARD32 +ScreenSaverTimeoutExpire(OsTimerPtr timer,CARD32 now,pointer arg) +{ + INT32 timeout = now - lastDeviceEventTime.milliseconds; + + if (timeout < ScreenSaverTime) { + return ScreenSaverTime - timeout; + } + + ResetOsBuffers(); /* not ideal, but better than nothing */ + SaveScreens(SCREEN_SAVER_ON, ScreenSaverActive); + +#ifdef DPMSExtension + if (ScreenSaverInterval > 0 && DPMSPowerLevel == DPMSModeOn) +#else + if (ScreenSaverInterval > 0) +#endif /* DPMSExtension */ + return ScreenSaverInterval; + + return 0; +} + +static OsTimerPtr ScreenSaverTimer = NULL; + +void +FreeScreenSaverTimer(void) +{ + if (ScreenSaverTimer) { + TimerFree(ScreenSaverTimer); + ScreenSaverTimer = NULL; + } +} + +void +SetScreenSaverTimer(void) +{ + if (ScreenSaverTime > 0) { + ScreenSaverTimer = TimerSet(ScreenSaverTimer, 0, ScreenSaverTime, + ScreenSaverTimeoutExpire, NULL); + } else if (ScreenSaverTimer) { + FreeScreenSaverTimer(); + } +} + +#ifdef DPMSExtension + +static OsTimerPtr DPMSStandbyTimer = NULL; +static OsTimerPtr DPMSSuspendTimer = NULL; +static OsTimerPtr DPMSOffTimer = NULL; + +static CARD32 +DPMSStandbyTimerExpire(OsTimerPtr timer,CARD32 now,pointer arg) +{ + INT32 timeout = now - lastDeviceEventTime.milliseconds; + + if (timeout < DPMSStandbyTime) { + return DPMSStandbyTime - timeout; + } + if (DPMSPowerLevel < DPMSModeStandby) { + DPMSSet(DPMSModeStandby); + } + return DPMSStandbyTime; +} + +static CARD32 +DPMSSuspendTimerExpire(OsTimerPtr timer,CARD32 now,pointer arg) +{ + INT32 timeout = now - lastDeviceEventTime.milliseconds; + + if (timeout < DPMSSuspendTime) { + return DPMSSuspendTime - timeout; + } + if (DPMSPowerLevel < DPMSModeSuspend) { + DPMSSet(DPMSModeSuspend); + } + return DPMSSuspendTime; +} + +static CARD32 +DPMSOffTimerExpire(OsTimerPtr timer,CARD32 now,pointer arg) +{ + INT32 timeout = now - lastDeviceEventTime.milliseconds; + + if (timeout < DPMSOffTime) { + return DPMSOffTime - timeout; + } + if (DPMSPowerLevel < DPMSModeOff) { + DPMSSet(DPMSModeOff); + } + return DPMSOffTime; +} + +void +FreeDPMSTimers(void) +{ + if (DPMSStandbyTimer) { + TimerFree(DPMSStandbyTimer); + DPMSStandbyTimer = NULL; + } + if (DPMSSuspendTimer) { + TimerFree(DPMSSuspendTimer); + DPMSSuspendTimer = NULL; + } + if (DPMSOffTimer) { + TimerFree(DPMSOffTimer); + DPMSOffTimer = NULL; + } +} + +void +SetDPMSTimers(void) +{ + if (!DPMSEnabled) + return; + + if (DPMSStandbyTime > 0) { + DPMSStandbyTimer = TimerSet(DPMSStandbyTimer, 0, DPMSStandbyTime, + DPMSStandbyTimerExpire, NULL); + } + if (DPMSSuspendTime > 0) { + DPMSSuspendTimer = TimerSet(DPMSSuspendTimer, 0, DPMSSuspendTime, + DPMSSuspendTimerExpire, NULL); + } + if (DPMSOffTime > 0) { + DPMSOffTimer = TimerSet(DPMSOffTimer, 0, DPMSOffTime, + DPMSOffTimerExpire, NULL); + } +} +#endif diff --git a/os/access.c b/os/access.c index f12c5c081..77dcebe20 100644 --- a/os/access.c +++ b/os/access.c @@ -45,13 +45,14 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ -/* $XFree86: xc/programs/Xserver/os/access.c,v 3.42 2002/07/07 20:11:52 herrb Exp $ */ +/* $XFree86: xc/programs/Xserver/os/access.c,v 3.50 2003/11/03 05:12:00 tsi Exp $ */ #ifdef WIN32 #include <X11/Xwinsock.h> #endif #include <stdio.h> +#include <stdlib.h> #include <X11/Xtrans.h> #include <X11/Xauth.h> #include <X.h> @@ -142,6 +143,19 @@ SOFTWARE. #include <ifaddrs.h> #endif +/* Solaris provides an extended interface SIOCGLIFCONF. Other systems + * may have this as well, but the code has only been tested on Solaris + * so far, so we only enable it there. Other platforms may be added as + * needed. + * + * Test for Solaris commented out -- TSI @ UQV 2003.06.13 + */ +#ifdef SIOCGLIFCONF +/* #if defined(sun) */ +#define USE_SIOCGLIFCONF +/* #endif */ +#endif + #endif /* WIN32 */ #ifndef PATH_MAX @@ -170,6 +184,14 @@ SOFTWARE. #include "extensions/security.h" #endif +#ifndef PATH_MAX +#ifdef MAXPATHLEN +#define PATH_MAX MAXPATHLEN +#else +#define PATH_MAX 1024 +#endif +#endif + Bool defeatAccessControl = FALSE; #define acmp(a1, a2, len) memcmp((char *)(a1), (char *)(a2), len) @@ -189,23 +211,35 @@ static int CheckAddr(int /*family*/, static Bool NewHost(int /*family*/, pointer /*addr*/, - int /*len*/); + int /*len*/, + int /* addingLocalHosts */); + +/* XFree86 bug #156: To keep track of which hosts were explicitly requested in + /etc/X<display>.hosts, we've added a requested field to the HOST struct, + and a LocalHostRequested variable. These default to FALSE, but are set + to TRUE in ResetHosts when reading in /etc/X<display>.hosts. They are + checked in DisableLocalHost(), which is called to disable the default + local host entries when stronger authentication is turned on. */ typedef struct _host { short family; short len; unsigned char *addr; struct _host *next; + int requested; } HOST; #define MakeHost(h,l) (h)=(HOST *) xalloc(sizeof *(h)+(l));\ - if((h))\ - (h)->addr=(unsigned char *) ((h) + 1); + if (h) { \ + (h)->addr=(unsigned char *) ((h) + 1);\ + (h)->requested = FALSE; \ + } #define FreeHost(h) xfree(h) static HOST *selfhosts = NULL; static HOST *validhosts = NULL; static int AccessEnabled = DEFAULT_ACCESS_CONTROL; static int LocalHostEnabled = FALSE; +static int LocalHostRequested = FALSE; static int UsingXdmcp = FALSE; @@ -232,9 +266,12 @@ DisableLocalHost (void) { HOST *self; - LocalHostEnabled = FALSE; - for (self = selfhosts; self; self = self->next) + if (!LocalHostRequested) /* Fix for XFree86 bug #156 */ + LocalHostEnabled = FALSE; + for (self = selfhosts; self; self = self->next) { + if (!self->requested) /* Fix for XFree86 bug #156 */ (void) RemoveHost ((ClientPtr)NULL, self->family, self->len, (pointer)self->addr); + } } /* @@ -250,7 +287,7 @@ AccessUsingXdmcp (void) } -#if ((defined(SVR4) && !defined(DGUX) && !defined(SCO325) && !defined(sun) && !defined(NCR)) || defined(ISC)) && defined(SIOCGIFCONF) +#if ((defined(SVR4) && !defined(DGUX) && !defined(SCO325) && !defined(sun) && !defined(NCR)) || defined(ISC)) && defined(SIOCGIFCONF) && !defined(USE_SIOCGLIFCONF) /* Deal with different SIOCGIFCONF ioctl semantics on these OSs */ @@ -465,9 +502,13 @@ DefineSelf (int fd) union { struct sockaddr sa; struct sockaddr_in in; +#if defined(IPv6) && defined(AF_INET6) + struct sockaddr_in6 in6; +#endif } saddr; struct sockaddr_in *inetaddr; + struct sockaddr_in6 *inet6addr; struct sockaddr_in broad_addr; #ifdef XTHREADS_NEEDS_BYNAMEPARAMS _Xgethostbynameparams hparams; @@ -492,9 +533,22 @@ DefineSelf (int fd) if (hp != NULL) { saddr.sa.sa_family = hp->h_addrtype; - inetaddr = (struct sockaddr_in *) (&(saddr.sa)); - acopy ( hp->h_addr, &(inetaddr->sin_addr), hp->h_length); - len = sizeof(saddr.sa); + switch (hp->h_addrtype) { + case AF_INET: + inetaddr = (struct sockaddr_in *) (&(saddr.sa)); + acopy ( hp->h_addr, &(inetaddr->sin_addr), hp->h_length); + len = sizeof(saddr.sa); + break; +#if defined(IPv6) && defined(AF_INET6) + case AF_INET6: + inet6addr = (struct sockaddr_in6 *) (&(saddr.sa)); + acopy ( hp->h_addr, &(inet6addr->sin6_addr), hp->h_length); + len = sizeof(saddr.in6); + break; +#endif + default: + goto DefineLocalHost; + } family = ConvertAddr ( &(saddr.sa), &len, (pointer *)&addr); if ( family != -1 && family != FamilyLocal ) { @@ -530,6 +584,14 @@ DefineSelf (int fd) XdmcpRegisterBroadcastAddress ((struct sockaddr_in *) &broad_addr); } +#if defined(IPv6) && defined(AF_INET6) + else if (family == FamilyInternet6 && + !(IN6_IS_ADDR_LOOPBACK((struct in6_addr *)addr))) + { + XdmcpRegisterConnection (family, (char *)addr, len); + } +#endif + #endif /* XDMCP */ } } @@ -537,6 +599,7 @@ DefineSelf (int fd) /* * now add a host of family FamilyLocalHost... */ +DefineLocalHost: for (host = selfhosts; host && !addrEqual(FamilyLocalHost, "", 0, host); host = host->next); @@ -557,6 +620,12 @@ DefineSelf (int fd) #else +#ifdef USE_SIOCGLIFCONF +#define ifr_type struct lifreq +#else +#define ifr_type struct ifreq +#endif + #ifdef VARIABLE_IFREQ #define ifr_size(p) (sizeof (struct ifreq) + \ (p->ifr_addr.sa_len > sizeof (p->ifr_addr) ? \ @@ -567,7 +636,7 @@ DefineSelf (int fd) #define ifr_size(p) (p->ifr_addr.sa_len + IFNAMSIZ) #define ifraddr_size(a) (a.sa_len) #else -#define ifr_size(p) (sizeof (struct ifreq)) +#define ifr_size(p) (sizeof (ifr_type)) #define ifraddr_size(a) (sizeof (a)) #endif #endif @@ -581,8 +650,17 @@ DefineSelf (int fd) { #ifndef HAS_GETIFADDRS char buf[2048], *cp, *cplim; + void * bufptr = buf; +#ifdef USE_SIOCGLIFCONF + struct lifconf ifc; + register struct lifreq *ifr; +#ifdef SIOCGLIFNUM + struct lifnum ifn; +#endif +#else struct ifconf ifc; register struct ifreq *ifr; +#endif #else struct ifaddrs * ifap, *ifr; #endif @@ -621,37 +699,80 @@ DefineSelf (int fd) } #endif /* DNETCONN */ #ifndef HAS_GETIFADDRS - ifc.ifc_len = sizeof (buf); - ifc.ifc_buf = buf; - if (ifioctl (fd, SIOCGIFCONF, (pointer) &ifc) < 0) - Error ("Getting interface configuration (4)"); + len = sizeof(buf); + +#ifdef USE_SIOCGLIFCONF + +#ifdef SIOCGLIFNUM + ifn.lifn_family = AF_UNSPEC; + ifn.lifn_flags = 0; + if (ioctl (fd, SIOCGLIFNUM, (char *) &ifn) < 0) + Error ("Getting interface count"); + if (len < (ifn.lifn_count * sizeof(struct lifreq))) { + len = ifn.lifn_count * sizeof(struct lifreq); + bufptr = xalloc(len); + } +#endif + + ifc.lifc_family = AF_UNSPEC; + ifc.lifc_flags = 0; + ifc.lifc_len = len; + ifc.lifc_buf = bufptr; + +#define IFC_IOCTL_REQ SIOCGLIFCONF +#define IFC_IFC_REQ ifc.lifc_req +#define IFC_IFC_LEN ifc.lifc_len +#define IFR_IFR_ADDR ifr->lifr_addr +#define IFR_IFR_NAME ifr->lifr_name + +#else /* Use SIOCGIFCONF */ + ifc.ifc_len = len; + ifc.ifc_buf = bufptr; + +#define IFC_IOCTL_REQ SIOCGIFCONF #ifdef ISC #define IFC_IFC_REQ (struct ifreq *) ifc.ifc_buf #else #define IFC_IFC_REQ ifc.ifc_req #endif /* ISC */ +#define IFC_IFC_LEN ifc.ifc_len +#define IFR_IFR_ADDR ifr->ifr_addr +#define IFR_IFR_NAME ifr->ifr_name +#endif + + if (ifioctl (fd, IFC_IOCTL_REQ, (pointer) &ifc) < 0) + Error ("Getting interface configuration (4)"); - cplim = (char *) IFC_IFC_REQ + ifc.ifc_len; + cplim = (char *) IFC_IFC_REQ + IFC_IFC_LEN; for (cp = (char *) IFC_IFC_REQ; cp < cplim; cp += ifr_size (ifr)) { - ifr = (struct ifreq *) cp; - len = ifraddr_size (ifr->ifr_addr); + ifr = (ifr_type *) cp; + len = ifraddr_size (IFR_IFR_ADDR); + family = ConvertAddr ((struct sockaddr *) &IFR_IFR_ADDR, + &len, (pointer *)&addr); #ifdef DNETCONN /* * DECnet was handled up above. */ - if (ifr->ifr_addr.sa_family == AF_DECnet) + if (family == AF_DECnet) continue; #endif /* DNETCONN */ - family = ConvertAddr (&ifr->ifr_addr, &len, (pointer *)&addr); if (family == -1 || family == FamilyLocal) continue; #ifdef DEF_SELF_DEBUG if (family == FamilyInternet) ErrorF("Xserver: DefineSelf(): ifname = %s, addr = %d.%d.%d.%d\n", - ifr->ifr_name, addr[0], addr[1], addr[2], addr[3]); + IFR_IFR_NAME, addr[0], addr[1], addr[2], addr[3]); +#if defined(IPv6) && defined(AF_INET6) + else if (family == FamilyInternet6) { + char cp[INET6_ADDRSTRLEN] = ""; + inet_ntop(AF_INET6, addr, cp, sizeof(cp)); + ErrorF("Xserver: DefineSelf(): ifname = %s, addr = %s\n", + IFR_IFR_NAME, cp); + } +#endif #endif /* DEF_SELF_DEBUG */ for (host = selfhosts; host && !addrEqual (family, addr, len, host); @@ -670,39 +791,80 @@ DefineSelf (int fd) } #ifdef XDMCP { +#ifdef USE_SIOCGLIFCONF + struct sockaddr_storage broad_addr; +#else struct sockaddr broad_addr; +#endif /* * If this isn't an Internet Address, don't register it. */ - if (family != FamilyInternet) + if (family != FamilyInternet +#if defined(IPv6) && defined(AF_INET6) + && family != FamilyInternet6 +#endif + ) continue; /* * ignore 'localhost' entries as they're not useful * on the other end of the wire */ - if (len == 4 && + if (family == FamilyInternet && addr[0] == 127 && addr[1] == 0 && addr[2] == 0 && addr[3] == 1) continue; +#if defined(IPv6) && defined(AF_INET6) + else if (family == FamilyInternet6 && + IN6_IS_ADDR_LOOPBACK((struct in6_addr *)addr)) + continue; +#endif XdmcpRegisterConnection (family, (char *)addr, len); - broad_addr = ifr->ifr_addr; + +#if defined(IPv6) && defined(AF_INET6) + /* IPv6 doesn't support broadcasting, so we drop out here */ + if (family == FamilyInternet6) + continue; +#endif + + broad_addr = IFR_IFR_ADDR; + ((struct sockaddr_in *) &broad_addr)->sin_addr.s_addr = htonl (INADDR_BROADCAST); -#ifdef SIOCGIFBRDADDR +#if defined(USE_SIOCGLIFCONF) && defined(SIOCGLIFBRDADDR) + { + struct lifreq broad_req; + + broad_req = *ifr; + if (ioctl (fd, SIOCGLIFFLAGS, (char *) &broad_req) != -1 && + (broad_req.lifr_flags & IFF_BROADCAST) && + (broad_req.lifr_flags & IFF_UP) + ) + { + broad_req = *ifr; + if (ioctl (fd, SIOCGLIFBRDADDR, &broad_req) != -1) + broad_addr = broad_req.lifr_broadaddr; + else + continue; + } + else + continue; + } + +#elif defined(SIOCGIFBRDADDR) { struct ifreq broad_req; broad_req = *ifr; - if (ifioctl (fd, SIOCGIFFLAGS, (char *) &broad_req) != -1 && + if (ifioctl (fd, SIOCGIFFLAGS, (pointer) &broad_req) != -1 && (broad_req.ifr_flags & IFF_BROADCAST) && (broad_req.ifr_flags & IFF_UP) ) { broad_req = *ifr; - if (ifioctl (fd, SIOCGIFBRDADDR, &broad_req) != -1) + if (ifioctl (fd, SIOCGIFBRDADDR, (pointer) &broad_req) != -1) broad_addr = broad_req.ifr_addr; else continue; @@ -713,13 +875,15 @@ DefineSelf (int fd) #endif /* SIOCGIFBRDADDR */ #ifdef DEF_SELF_DEBUG ErrorF("Xserver: DefineSelf(): ifname = %s, baddr = %s\n", - ifr->ifr_name, + IFR_IFR_NAME, inet_ntoa(((struct sockaddr_in *) &broad_addr)->sin_addr)); #endif /* DEF_SELF_DEBUG */ XdmcpRegisterBroadcastAddress ((struct sockaddr_in *) &broad_addr); } #endif /* XDMCP */ } + if (bufptr != buf) + free(bufptr); #else /* HAS_GETIFADDRS */ if (getifaddrs(&ifap) < 0) { ErrorF("Warning: getifaddrs returns %s\n", strerror(errno)); @@ -730,6 +894,7 @@ DefineSelf (int fd) if (ifr->ifa_addr.sa_family == AF_DECnet) continue; #endif /* DNETCONN */ + len = sizeof(*(ifr->ifa_addr)); family = ConvertAddr(ifr->ifa_addr, &len, (pointer *)&addr); if (family == -1 || family == FamilyLocal) continue; @@ -843,7 +1008,11 @@ AddLocalHosts (void) HOST *self; for (self = selfhosts; self; self = self->next) - (void) NewHost (self->family, self->addr, self->len); + /* Fix for XFree86 bug #156: pass addingLocal = TRUE to + * NewHost to tell that we are adding the default local + * host entries and not to flag the entries as being + * explicitely requested */ + (void) NewHost (self->family, self->addr, self->len, TRUE); } /* Reset access control list to initial hosts */ @@ -858,15 +1027,18 @@ ResetHosts (char *display) FILE *fd; char *ptr; int i, hostlen; +#if ((defined(TCPCONN) || defined(STREAMSCONN) || defined(MNX_TCPCONN)) && \ + (!defined(IPv6) || !defined(AF_INET6))) || defined(DNETCONN) union { struct sockaddr sa; #if defined(TCPCONN) || defined(STREAMSCONN) || defined(MNX_TCPCONN) - struct sockaddr_in in; + struct sockaddr_in in; #endif /* TCPCONN || STREAMSCONN */ #ifdef DNETCONN - struct sockaddr_dn dn; + struct sockaddr_dn dn; +#endif + } saddr; #endif - } saddr; #ifdef DNETCONN struct nodeent *np; struct dn_naddr dnaddr, *dnaddrp, *dnet_addr(); @@ -878,7 +1050,6 @@ ResetHosts (char *display) int family = 0; pointer addr; int len; - register struct hostent *hp; AccessEnabled = defeatAccessControl ? FALSE : DEFAULT_ACCESS_CONTROL; LocalHostEnabled = FALSE; @@ -902,6 +1073,7 @@ ResetHosts (char *display) { while (fgets (ohostname, sizeof (ohostname), fd)) { + family = FamilyWild; if (*ohostname == '#') continue; if ((ptr = strchr(ohostname, '\n')) != 0) @@ -917,7 +1089,8 @@ ResetHosts (char *display) if (!strncmp("local:", lhostname, 6)) { family = FamilyLocalHost; - NewHost(family, "", 0); + NewHost(family, "", 0, FALSE); + LocalHostRequested = TRUE; /* Fix for XFree86 bug #156 */ } #if defined(TCPCONN) || defined(STREAMSCONN) || defined(MNX_TCPCONN) else if (!strncmp("inet:", lhostname, 5)) @@ -925,6 +1098,13 @@ ResetHosts (char *display) family = FamilyInternet; hostname = ohostname + 5; } +#if defined(IPv6) && defined(AF_INET6) + else if (!strncmp("inet6:", lhostname, 6)) + { + family = FamilyInternet6; + hostname = ohostname + 6; + } +#endif #endif #ifdef DNETCONN else if (!strncmp("dnet:", lhostname, 5)) @@ -969,7 +1149,7 @@ ResetHosts (char *display) } if (dnaddrp) (void) NewHost(FamilyDECnet, (pointer)dnaddrp, - (int)(dnaddrp->a_len + sizeof(dnaddrp->a_len))); + (int)(dnaddrp->a_len + sizeof(dnaddrp->a_len)), FALSE); } else #endif /* DNETCONN */ @@ -978,7 +1158,7 @@ ResetHosts (char *display) { krb5_parse_name(hostname, &princ); XauKrb5Encode(princ, &kbuf); - (void) NewHost(FamilyKrb5Principal, kbuf.data, kbuf.length); + (void) NewHost(FamilyKrb5Principal, kbuf.data, kbuf.length, FALSE); krb5_free_principal(princ); } else @@ -987,15 +1167,37 @@ ResetHosts (char *display) if ((family == FamilyNetname) || (strchr(hostname, '@'))) { SecureRPCInit (); - (void) NewHost (FamilyNetname, hostname, strlen (hostname)); + (void) NewHost (FamilyNetname, hostname, strlen (hostname), FALSE); } else #endif /* SECURE_RPC */ #if defined(TCPCONN) || defined(STREAMSCONN) || defined(MNX_TCPCONN) { +#if defined(IPv6) && defined(AF_INET6) + if ( (family == FamilyInternet) || (family == FamilyInternet6) || + (family == FamilyWild) ) + { + struct addrinfo *addresses; + struct addrinfo *a; + int f; + + if (getaddrinfo(hostname, NULL, NULL, &addresses) == 0) { + for (a = addresses ; a != NULL ; a = a->ai_next) { + len = a->ai_addrlen; + f = ConvertAddr(a->ai_addr,&len,(pointer *)&addr); + if ( (family == f) || + ((family == FamilyWild) && (f != -1)) ) { + NewHost(f, addr, len, FALSE); + } + } + freeaddrinfo(addresses); + } + } +#else #ifdef XTHREADS_NEEDS_BYNAMEPARAMS _Xgethostbynameparams hparams; #endif + register struct hostent *hp; /* host name */ if ((family == FamilyInternet && @@ -1011,12 +1213,13 @@ ResetHosts (char *display) /* iterate over the addresses */ for (list = hp->h_addr_list; *list; list++) - (void) NewHost (family, (pointer)*list, len); + (void) NewHost (family, (pointer)*list, len, FALSE); #else - (void) NewHost (family, (pointer)hp->h_addr, len); + (void) NewHost (family, (pointer)hp->h_addr, len, FALSE); #endif } } +#endif /* IPv6 */ } #endif /* TCPCONN || STREAMSCONN */ family = FamilyWild; @@ -1080,6 +1283,7 @@ Bool LocalClient(ClientPtr client) int LocalClientCred(ClientPtr client, int *pUid, int *pGid) { +#if defined(HAS_GETPEEREID) || defined(SO_PEERCRED) int fd; XtransConnInfo ci; #ifdef HAS_GETPEEREID @@ -1114,6 +1318,7 @@ LocalClientCred(ClientPtr client, int *pUid, int *pGid) if (pGid != NULL) *pGid = peercred.gid; return 0; +#endif #else /* No system call available to get the credentials of the peer */ return -1; @@ -1158,6 +1363,9 @@ AddHost (ClientPtr client, break; #endif case FamilyInternet: +#if defined(IPv6) && defined(AF_INET6) + case FamilyInternet6: +#endif case FamilyDECnet: case FamilyChaos: if ((len = CheckAddr (family, pAddr, length)) < 0) @@ -1171,7 +1379,7 @@ AddHost (ClientPtr client, client->errorValue = family; return (BadValue); } - if (NewHost (family, pAddr, len)) + if (NewHost (family, pAddr, len, FALSE)) return Success; return BadAlloc; } @@ -1197,7 +1405,8 @@ ForEachHostInFamily (int family, static Bool NewHost (int family, pointer addr, - int len) + int len, + int addingLocalHosts) { register HOST *host; @@ -1206,6 +1415,14 @@ NewHost (int family, if (addrEqual (family, addr, len, host)) return TRUE; } + if (!addingLocalHosts) { /* Fix for XFree86 bug #156 */ + for (host = selfhosts; host; host = host->next) { + if (addrEqual (family, addr, len, host)) { + host->requested = TRUE; + break; + } + } + } MakeHost(host,len) if (!host) return FALSE; @@ -1247,6 +1464,9 @@ RemoveHost ( break; #endif case FamilyInternet: +#if defined(IPv6) && defined(AF_INET6) + case FamilyInternet6: +#endif case FamilyDECnet: case FamilyChaos: if ((len = CheckAddr (family, pAddr, length)) < 0) @@ -1336,6 +1556,14 @@ CheckAddr ( else len = -1; break; +#if defined(IPv6) && defined(AF_INET6) + case FamilyInternet6: + if (length == sizeof (struct in6_addr)) + len = length; + else + len = -1; + break; +#endif #endif #ifdef DNETCONN case FamilyDECnet: @@ -1424,6 +1652,21 @@ ConvertAddr ( *len = sizeof (struct in_addr); *addr = (pointer) &(((struct sockaddr_in *) saddr)->sin_addr); return FamilyInternet; +#if defined(IPv6) && defined(AF_INET6) + case AF_INET6: + { + struct sockaddr_in6 *saddr6 = (struct sockaddr_in6 *) saddr; + if (IN6_IS_ADDR_V4MAPPED(&(saddr6->sin6_addr))) { + *len = sizeof (struct in_addr); + *addr = (pointer) &(saddr6->sin6_addr.s6_addr[12]); + return FamilyInternet; + } else { + *len = sizeof (struct in6_addr); + *addr = (pointer) &(saddr6->sin6_addr); + return FamilyInternet6; + } + } +#endif #endif #ifdef DNETCONN case AF_DECnet: @@ -26,7 +26,7 @@ other dealings in this Software without prior written authorization from The Open Group. */ -/* $XFree86: xc/programs/Xserver/os/auth.c,v 1.12 2002/12/09 02:56:03 dawes Exp $ */ +/* $XFree86: xc/programs/Xserver/os/auth.c,v 1.14 2003/08/27 19:57:21 herrb Exp $ */ /* * authorization hooks for the server @@ -128,30 +128,19 @@ InitAuthorization (char *file_name) authorization_file = file_name; } -int +static int LoadAuthorization (void) { FILE *f; Xauth *auth; int i; int count = 0; -#if !defined(WIN32) && !defined(__UNIXOS2__) - char *buf; -#endif ShouldLoadAuth = FALSE; if (!authorization_file) return 0; -#if !defined(WIN32) && !defined(__UNIXOS2__) - buf = xalloc (strlen(authorization_file) + 5); - if (!buf) - return -1; - sprintf (buf, "cat %s", authorization_file); - f = Popen (buf, "r"); - xfree (buf); -#else - f = fopen (authorization_file, "r"); -#endif + + f = Fopen (authorization_file, "r"); if (!f) return -1; @@ -169,12 +158,7 @@ LoadAuthorization (void) XauDisposeAuth (auth); } -#if !defined(WIN32) && !defined(__UNIXOS2__) - if (Pclose (f) != 0) - return -1; -#else - fclose (f); -#endif + Fclose (f); return count; } diff --git a/os/connection.c b/os/connection.c index 46cfd4dfb..7465e7eff 100644 --- a/os/connection.c +++ b/os/connection.c @@ -45,7 +45,7 @@ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ -/* $XFree86: xc/programs/Xserver/os/connection.c,v 3.56 2002/05/31 18:46:05 dawes Exp $ */ +/* $XFree86: xc/programs/Xserver/os/connection.c,v 3.65 2003/10/30 21:21:10 herrb Exp $ */ /***************************************************************** * Stuff to create connections --- OS dependent * @@ -72,6 +72,7 @@ SOFTWARE. #include <errno.h> #include <signal.h> #include <stdio.h> +#include <stdlib.h> #ifndef WIN32 #if defined(Lynx) @@ -123,6 +124,7 @@ extern __const__ int _nfiles; # endif # endif # endif +# include <arpa/inet.h> #endif #ifdef AMTCPCONN @@ -155,6 +157,7 @@ extern __const__ int _nfiles; #include "colormapst.h" #include "propertyst.h" #include "lbxserve.h" +#include "osdep.h" #endif #ifdef X_NOT_POSIX @@ -183,8 +186,10 @@ Bool AnyClientsWriteBlocked; /* true if some client blocked on write */ Bool RunFromSmartParent; /* send SIGUSR1 to parent process */ Bool PartialNetwork; /* continue even if unable to bind all addrs */ -char *protNoListen; /* don't listen on this protocol */ static Pid_t ParentProcess; +#ifdef __UNIXOS2__ +Pid_t GetPPID(Pid_t pid); +#endif static Bool debug_conns = FALSE; @@ -210,32 +215,18 @@ XtransConnInfo *ListenTransConns = NULL; int *ListenTransFds = NULL; int ListenTransCount; -static void ErrorConnMax( -#if NeedFunctionPrototypes -XtransConnInfo /* trans_conn */ -#endif -); +static void ErrorConnMax(XtransConnInfo /* trans_conn */); #ifndef LBX static -#endif void CloseDownFileDescriptor( -#if NeedFunctionPrototypes -#ifdef LBX - ClientPtr client -#else - register OsCommPtr /*oc*/ -#endif -#endif + OsCommPtr /*oc*/ ); +#endif -#ifdef LBX -extern int LbxFlushClient(); -#endif /* LBX */ static XtransConnInfo -lookup_trans_conn (fd) - int fd; +lookup_trans_conn (int fd) { if (ListenTransFds) { @@ -251,7 +242,7 @@ lookup_trans_conn (fd) /* Set MaxClients and lastfdesc, and allocate ConnectionTranslation */ void -InitConnectionLimits() +InitConnectionLimits(void) { lastfdesc = -1; @@ -312,11 +303,12 @@ InitConnectionLimits() *****************/ void -CreateWellKnownSockets() +CreateWellKnownSockets(void) { int i; int partial; char port[20]; + OsSigHandlerPtr handler; FD_ZERO(&AllSockets); FD_ZERO(&AllClients); @@ -333,12 +325,6 @@ CreateWellKnownSockets() sprintf (port, "%d", atoi (display)); - if (protNoListen) - if (_XSERVTransNoListen(protNoListen)) - { - FatalError ("Failed to disable listen for %s", protNoListen); - } - if ((_XSERVTransMakeAllCOTSServerListeners (port, &partial, &ListenTransCount, &ListenTransConns) >= 0) && (ListenTransCount >= 1)) @@ -392,9 +378,20 @@ CreateWellKnownSockets() * useful */ #if !defined(WIN32) - if (OsSignal (SIGUSR1, SIG_IGN) == SIG_IGN) + handler = OsSignal (SIGUSR1, SIG_IGN); + if ( handler == SIG_IGN) RunFromSmartParent = TRUE; + OsSignal(SIGUSR1, handler); ParentProcess = getppid (); +#ifdef __UNIXOS2__ + /* + * fg030505: under OS/2, xinit is not the parent process but + * the "grant parent" process of the server because execvpe() + * presents us an additional process number; + * GetPPID(pid) is part of libemxfix + */ + ParentProcess = GetPPID (ParentProcess); +#endif /* __UNIXOS2__ */ if (RunFromSmartParent) { if (ParentProcess > 1) { kill (ParentProcess, SIGUSR1); @@ -407,7 +404,7 @@ CreateWellKnownSockets() } void -ResetWellKnownSockets () +ResetWellKnownSockets (void) { int i; @@ -468,7 +465,7 @@ ResetWellKnownSockets () } void -CloseWellKnownConnections() +CloseWellKnownConnections(void) { int i; @@ -477,14 +474,9 @@ CloseWellKnownConnections() } static void -AuthAudit (client, letin, saddr, len, proto_n, auth_proto, auth_id) - ClientPtr client; - Bool letin; - struct sockaddr *saddr; - int len; - unsigned short proto_n; - char *auth_proto; - int auth_id; +AuthAudit (ClientPtr client, Bool letin, + struct sockaddr *saddr, int len, + unsigned int proto_n, char *auth_proto, int auth_id) { char addr[128]; char *out = addr; @@ -506,11 +498,19 @@ AuthAudit (client, letin, saddr, len, proto_n, auth_proto, auth_id) break; #if defined(TCPCONN) || defined(STREAMSCONN) || defined(MNX_TCPCONN) case AF_INET: - sprintf(out, "IP %s port %d", - inet_ntoa(((struct sockaddr_in *) saddr)->sin_addr), - ntohs(((struct sockaddr_in *) saddr)->sin_port)); + sprintf(out, "IP %s", + inet_ntoa(((struct sockaddr_in *) saddr)->sin_addr)); + break; +#if defined(IPv6) && defined(AF_INET6) + case AF_INET6: { + char ipaddr[INET6_ADDRSTRLEN]; + inet_ntop(AF_INET6, &((struct sockaddr_in6 *) saddr)->sin6_addr, + ipaddr, sizeof(ipaddr)); + sprintf(out, "IP %s", ipaddr); + } break; #endif +#endif #ifdef DNETCONN case AF_DECnet: sprintf(out, "DN %s", @@ -530,17 +530,18 @@ AuthAudit (client, letin, saddr, len, proto_n, auth_proto, auth_id) default: strcpy(out, "unknown address"); } - if (letin) - AuditF("client %d connected from %s\n", client->index, addr); - else - AuditF("client %d rejected from %s\n", client->index, addr); + if (proto_n) - AuditF(" Auth name: %.*s ID: %d\n", proto_n, auth_proto, auth_id); + AuditF("client %d %s from %s\n Auth name: %.*s ID: %d\n", + client->index, letin ? "connected" : "rejected", addr, + (int)proto_n, auth_proto, auth_id); + else + AuditF("client %d %s from %s\n", + client->index, letin ? "connected" : "rejected", addr); } XID -AuthorizationIDOfClient(client) - ClientPtr client; +AuthorizationIDOfClient(ClientPtr client) { if (client->osPrivate) return ((OsCommPtr)client->osPrivate)->auth_id; @@ -569,12 +570,11 @@ AuthorizationIDOfClient(client) *****************************************************************/ char * -ClientAuthorized(client, proto_n, auth_proto, string_n, auth_string) - ClientPtr client; - char *auth_proto, *auth_string; - unsigned int proto_n, string_n; +ClientAuthorized(ClientPtr client, + unsigned int proto_n, char *auth_proto, + unsigned int string_n, char *auth_string) { - register OsCommPtr priv; + OsCommPtr priv; Xtransaddr *from = NULL; int family; int fromlen; @@ -729,17 +729,15 @@ ClientAuthorized(client, proto_n, auth_proto, string_n, auth_string) static ClientPtr #ifdef LBX -AllocNewConnection (trans_conn, fd, conn_time, Flush, Close, proxy) +AllocNewConnection (XtransConnInfo trans_conn, int fd, CARD32 conn_time, + int (*Flush)( + ClientPtr /*who*/, OsCommPtr /*oc*/, + char */*extraBuf*/, int /*extraCount*/), + void (*Close)( + ClientPtr /*client*/), + LbxProxyPtr proxy) #else -AllocNewConnection (trans_conn, fd, conn_time) -#endif - XtransConnInfo trans_conn; - int fd; - CARD32 conn_time; -#ifdef LBX - int (*Flush)(); - void (*Close)(); - LbxProxyPtr proxy; +AllocNewConnection (XtransConnInfo trans_conn, int fd, CARD32 conn_time) #endif { OsCommPtr oc; @@ -804,8 +802,7 @@ AllocNewConnection (trans_conn, fd, conn_time) #ifdef LBX int -ClientConnectionNumber (client) - ClientPtr client; +ClientConnectionNumber (ClientPtr client) { OsCommPtr oc = (OsCommPtr) client->osPrivate; @@ -813,9 +810,7 @@ ClientConnectionNumber (client) } ClientPtr -AllocLbxClientConnection (client, proxy) - ClientPtr client; - LbxProxyPtr proxy; +AllocLbxClientConnection (ClientPtr client, LbxProxyPtr proxy) { OsCommPtr oc = (OsCommPtr) client->osPrivate; @@ -824,9 +819,7 @@ AllocLbxClientConnection (client, proxy) } void -LbxProxyConnection (client, proxy) - ClientPtr client; - LbxProxyPtr proxy; +LbxProxyConnection (ClientPtr client, LbxProxyPtr proxy) { OsCommPtr oc = (OsCommPtr) client->osPrivate; @@ -848,9 +841,7 @@ LbxProxyConnection (client, proxy) /*ARGSUSED*/ Bool -EstablishNewConnections(clientUnused, closure) - ClientPtr clientUnused; - pointer closure; +EstablishNewConnections(ClientPtr clientUnused, pointer closure) { fd_set readyconnections; /* set of listeners that are ready */ int curconn; /* fd of listener that's ready */ @@ -940,10 +931,9 @@ EstablishNewConnections(clientUnused, closure) ************/ static void -ErrorConnMax(trans_conn) -XtransConnInfo trans_conn; +ErrorConnMax(XtransConnInfo trans_conn) { - register int fd = _XSERVTransGetConnectionNumber (trans_conn); + int fd = _XSERVTransGetConnectionNumber (trans_conn); xConnSetupPrefix csp; char pad[3]; struct iovec iov[3]; @@ -992,16 +982,14 @@ XtransConnInfo trans_conn; #ifdef LBX void -CloseDownFileDescriptor(client) - ClientPtr client; +CloseDownFileDescriptor(ClientPtr client) #else static void -CloseDownFileDescriptor(oc) - register OsCommPtr oc; +CloseDownFileDescriptor(OsCommPtr oc) #endif { #ifdef LBX - register OsCommPtr oc = (OsCommPtr) client->osPrivate; + OsCommPtr oc = (OsCommPtr) client->osPrivate; #endif int connection = oc->fd; @@ -1040,13 +1028,13 @@ CloseDownFileDescriptor(oc) *****************/ void -CheckConnections() +CheckConnections(void) { #ifndef WIN32 fd_mask mask; #endif fd_set tmask; - register int curclient, curoff; + int curclient, curoff; int i; struct timeval notime; int r; @@ -1094,8 +1082,7 @@ CheckConnections() *****************/ void -CloseDownConnection(client) - ClientPtr client; +CloseDownConnection(ClientPtr client) { OsCommPtr oc = (OsCommPtr)client->osPrivate; @@ -1117,8 +1104,7 @@ CloseDownConnection(client) } void -AddEnabledDevice(fd) - int fd; +AddEnabledDevice(int fd) { FD_SET(fd, &EnabledDevices); FD_SET(fd, &AllSockets); @@ -1127,8 +1113,7 @@ AddEnabledDevice(fd) } void -RemoveEnabledDevice(fd) - int fd; +RemoveEnabledDevice(int fd) { FD_CLR(fd, &EnabledDevices); FD_CLR(fd, &AllSockets); @@ -1147,8 +1132,7 @@ RemoveEnabledDevice(fd) *****************/ void -OnlyListenToOneClient(client) - ClientPtr client; +OnlyListenToOneClient(ClientPtr client) { OsCommPtr oc = (OsCommPtr)client->osPrivate; int connection = oc->fd; @@ -1180,7 +1164,7 @@ OnlyListenToOneClient(client) ****************/ void -ListenToAllClients() +ListenToAllClients(void) { if (GrabInProgress) { @@ -1198,8 +1182,7 @@ ListenToAllClients() ****************/ void -IgnoreClient (client) - ClientPtr client; +IgnoreClient (ClientPtr client) { OsCommPtr oc = (OsCommPtr)client->osPrivate; int connection = oc->fd; @@ -1243,8 +1226,7 @@ IgnoreClient (client) ****************/ void -AttendClient (client) - ClientPtr client; +AttendClient (ClientPtr client) { OsCommPtr oc = (OsCommPtr)client->osPrivate; int connection = oc->fd; @@ -1277,8 +1259,7 @@ AttendClient (client) /* make client impervious to grabs; assume only executing client calls this */ void -MakeClientGrabImpervious(client) - ClientPtr client; +MakeClientGrabImpervious(ClientPtr client) { OsCommPtr oc = (OsCommPtr)client->osPrivate; int connection = oc->fd; @@ -1297,8 +1278,7 @@ MakeClientGrabImpervious(client) /* make client pervious to grabs; assume only executing client calls this */ void -MakeClientGrabPervious(client) - ClientPtr client; +MakeClientGrabPervious(ClientPtr client) { OsCommPtr oc = (OsCommPtr)client->osPrivate; int connection = oc->fd; @@ -1325,61 +1305,3 @@ MakeClientGrabPervious(client) } } -#ifdef AIXV3 - -static fd_set pendingActiveClients; -static BOOL reallyGrabbed; - -/**************** -* DontListenToAnybody: -* Don't listen to requests from any clients. Continue to handle new -* connections, but don't take any protocol requests from anybody. -* We have to take care if there is already a grab in progress, though. -* Undone by PayAttentionToClientsAgain. We also have to be careful -* not to accept any more input from the currently dispatched client. -* we do this be telling dispatch it is time to yield. - -* We call this when the server loses access to the glass -* (user hot-keys away). This looks like a grab by the -* server itself, but gets a little tricky if there is already -* a grab in progress. -******************/ - -void -DontListenToAnybody() -{ - if (!GrabInProgress) - { - XFD_COPYSET(&ClientsWithInput, &SavedClientsWithInput); - XFD_COPYSET(&AllSockets, &SavedAllSockets); - XFD_COPYSET(&AllClients, &SavedAllClients); - GrabInProgress = TRUE; - reallyGrabbed = FALSE; - } - else - { - XFD_COPYSET(&AllClients, &pendingActiveClients); - reallyGrabbed = TRUE; - } - FD_ZERO(&ClientsWithInput); - XFD_UNSET(&AllSockets, &AllClients); - FD_ZERO(&AllClients); - isItTimeToYield = TRUE; -} - -void -PayAttentionToClientsAgain() -{ - if (reallyGrabbed) - { - XFD_ORSET(&AllSockets, &AllSockets, &pendingActiveClients); - XFD_ORSET(&AllClients, &AllClients, &pendingActiveClients); - } - else - { - ListenToAllClients(); - } - reallyGrabbed = FALSE; -} - -#endif @@ -53,7 +53,7 @@ SOFTWARE. * InsertFakeRequest, ResetCurrentRequest * *****************************************************************/ -/* $XFree86: xc/programs/Xserver/os/io.c,v 3.34 2002/05/31 18:46:05 dawes Exp $ */ +/* $XFree86: xc/programs/Xserver/os/io.c,v 3.35 2003/04/27 21:31:08 herrb Exp $ */ #if 0 #define DEBUG_COMMUNICATION @@ -200,25 +200,22 @@ OsCommPtr AvailableInput = (OsCommPtr)NULL; #ifdef LBX_NEED_OLD_SYMBOL_FOR_LOADABLES #undef ReadRequestFromClient int -ReadRequestFromClient(client) - ClientPtr client; +ReadRequestFromClient(ClientPtr client) { return (*client->readRequest)(client); } #endif int -StandardReadRequestFromClient(client) - ClientPtr client; +StandardReadRequestFromClient(ClientPtr client) #else int -ReadRequestFromClient(client) - ClientPtr client; +ReadRequestFromClient(ClientPtr client) #endif { OsCommPtr oc = (OsCommPtr)client->osPrivate; - register ConnectionInputPtr oci = oc->input; + ConnectionInputPtr oci = oc->input; int fd = oc->fd; - register unsigned int gotnow, needed; + unsigned int gotnow, needed; int result; register xReq *request; Bool need_header; @@ -524,21 +521,18 @@ ReadRequestFromClient(client) **********************/ Bool -InsertFakeRequest(client, data, count) - ClientPtr client; - char *data; - int count; +InsertFakeRequest(ClientPtr client, char *data, int count) { OsCommPtr oc = (OsCommPtr)client->osPrivate; - register ConnectionInputPtr oci = oc->input; + ConnectionInputPtr oci = oc->input; int fd = oc->fd; - register int gotnow, moveup; + int gotnow, moveup; if (AvailableInput) { if (AvailableInput != oc) { - register ConnectionInputPtr aci = AvailableInput->input; + ConnectionInputPtr aci = AvailableInput->input; if (aci->size > BUFWATERMARK) { xfree(aci->buffer); @@ -601,8 +595,7 @@ InsertFakeRequest(client, data, count) **********************/ void -ResetCurrentRequest(client) - ClientPtr client; +ResetCurrentRequest(ClientPtr client) { OsCommPtr oc = (OsCommPtr)client->osPrivate; register ConnectionInputPtr oci = oc->input; @@ -685,10 +678,10 @@ ResetCurrentRequest(client) **********************/ xReqPtr -PeekNextRequest(req, client, readmore) - xReqPtr req; /* request we're starting from */ - ClientPtr client; /* client whose requests we're skipping */ - Bool readmore; /* attempt to read more if next request isn't there? */ +PeekNextRequest( + xReqPtr req, /* request we're starting from */ + ClientPtr client, /* client whose requests we're skipping */ + Bool readmore) /* attempt to read more if next request isn't there? */ { register ConnectionInputPtr oci = ((OsCommPtr)client->osPrivate)->input; xReqPtr pnextreq; @@ -747,10 +740,10 @@ PeekNextRequest(req, client, readmore) CallbackListPtr SkippedRequestsCallback = NULL; void -SkipRequests(req, client, numskipped) - xReqPtr req; /* last request being skipped */ - ClientPtr client; /* client whose requests we're skipping */ - int numskipped; /* how many requests we're skipping */ +SkipRequests( + xReqPtr req, /* last request being skipped */ + ClientPtr client, /* client whose requests we're skipping */ + int numskipped) /* how many requests we're skipping */ { OsCommPtr oc = (OsCommPtr)client->osPrivate; register ConnectionInputPtr oci = oc->input; @@ -809,7 +802,7 @@ static int padlength[4] = {0, 3, 2, 1}; **********************/ void -FlushAllOutput() +FlushAllOutput(void) { register int index, base; register fd_mask mask; /* raphael */ @@ -890,14 +883,14 @@ FlushAllOutput() } void -FlushIfCriticalOutputPending() +FlushIfCriticalOutputPending(void) { if (CriticalOutputPending) FlushAllOutput(); } void -SetCriticalOutputPending() +SetCriticalOutputPending(void) { CriticalOutputPending = TRUE; } @@ -914,13 +907,10 @@ SetCriticalOutputPending() *****************/ int -WriteToClient (who, count, buf) - ClientPtr who; - char *buf; - int count; +WriteToClient (ClientPtr who, int count, char *buf) { OsCommPtr oc = (OsCommPtr)who->osPrivate; - register ConnectionOutputPtr oco = oc->output; + ConnectionOutputPtr oco = oc->output; int padBytes; #ifdef DEBUG_COMMUNICATION Bool multicount = FALSE; @@ -1061,27 +1051,20 @@ WriteToClient (who, count, buf) #ifdef LBX_NEED_OLD_SYMBOL_FOR_LOADABLES #undef FlushClient int -FlushClient(who, oc, extraBuf, extraCount) - ClientPtr who; - OsCommPtr oc; - char *extraBuf; - int extraCount; +FlushClient(ClientPtr who, OsCommPtr oc, char *extraBuf, int extraCount) { return (*oc->Flush)(who, oc, extraBuf, extraCount); } #endif int -StandardFlushClient(who, oc, extraBuf, extraCount) +StandardFlushClient(ClientPtr who, OsCommPtr oc, + char *extraBuf, int extraCount) #else int -FlushClient(who, oc, extraBuf, extraCount) +FlushClient(ClientPtr who, OsCommPtr oc, char *extraBuf, int extraCount) #endif - ClientPtr who; - OsCommPtr oc; - char *extraBuf; - int extraCount; /* do not modify... returned below */ { - register ConnectionOutputPtr oco = oc->output; + ConnectionOutputPtr oco = oc->output; int connection = oc->fd; XtransConnInfo trans_conn = oc->trans_conn; struct iovec iov[3]; @@ -1247,9 +1230,9 @@ FlushClient(who, oc, extraBuf, extraCount) } ConnectionInputPtr -AllocateInputBuffer() +AllocateInputBuffer(void) { - register ConnectionInputPtr oci; + ConnectionInputPtr oci; oci = (ConnectionInputPtr)xalloc(sizeof(ConnectionInput)); if (!oci) @@ -1268,9 +1251,9 @@ AllocateInputBuffer() } ConnectionOutputPtr -AllocateOutputBuffer() +AllocateOutputBuffer(void) { - register ConnectionOutputPtr oco; + ConnectionOutputPtr oco; oco = (ConnectionOutputPtr)xalloc(sizeof(ConnectionOutput)); if (!oco) @@ -1290,11 +1273,10 @@ AllocateOutputBuffer() } void -FreeOsBuffers(oc) - OsCommPtr oc; +FreeOsBuffers(OsCommPtr oc) { - register ConnectionInputPtr oci; - register ConnectionOutputPtr oco; + ConnectionInputPtr oci; + ConnectionOutputPtr oco; if (AvailableInput == oc) AvailableInput = (OsCommPtr)NULL; @@ -1337,10 +1319,10 @@ FreeOsBuffers(oc) } void -ResetOsBuffers() +ResetOsBuffers(void) { - register ConnectionInputPtr oci; - register ConnectionOutputPtr oco; + ConnectionInputPtr oci; + ConnectionOutputPtr oco; while ((oci = FreeInputs)) { diff --git a/os/lbxio.c b/os/lbxio.c index 2991681de..ae4d4355f 100644 --- a/os/lbxio.c +++ b/os/lbxio.c @@ -1,4 +1,4 @@ -/* $XFree86: xc/programs/Xserver/os/lbxio.c,v 3.17 2002/05/31 18:46:06 dawes Exp $ */ +/* $XFree86: xc/programs/Xserver/os/lbxio.c,v 3.18 2003/04/27 21:31:09 herrb Exp $ */ /* Copyright 1996, 1998 The Open Group @@ -97,9 +97,7 @@ SOFTWARE. FD_CLR(fd, &ClientsWithInput); } void -SwitchClientInput (client, pending) - ClientPtr client; - Bool pending; +SwitchClientInput (ClientPtr client, Bool pending) { OsCommPtr oc = (OsCommPtr)client->osPrivate; @@ -111,9 +109,7 @@ SwitchClientInput (client, pending) } void -LbxPrimeInput(client, proxy) - ClientPtr client; - LbxProxyPtr proxy; +LbxPrimeInput(ClientPtr client, LbxProxyPtr proxy) { OsCommPtr oc = (OsCommPtr)client->osPrivate; ConnectionInputPtr oci = oc->input; @@ -131,8 +127,7 @@ LbxPrimeInput(client, proxy) } void -AvailableClientInput (client) - ClientPtr client; +AvailableClientInput (ClientPtr client) { OsCommPtr oc = (OsCommPtr)client->osPrivate; @@ -147,15 +142,12 @@ AvailableClientInput (client) **********************/ Bool -AppendFakeRequest (client, data, count) - ClientPtr client; - char *data; - int count; +AppendFakeRequest (ClientPtr client, char *data, int count) { OsCommPtr oc = (OsCommPtr)client->osPrivate; - register ConnectionInputPtr oci = oc->input; + ConnectionInputPtr oci = oc->input; int fd = oc->fd; - register int gotnow; + int gotnow; if (!oci) { @@ -198,11 +190,8 @@ AppendFakeRequest (client, data, count) } static int -LbxWrite(trans_conn, proxy, buf, len) - XtransConnInfo trans_conn; - LbxProxyPtr proxy; - char *buf; - int len; +LbxWrite(XtransConnInfo trans_conn, LbxProxyPtr proxy, + char *buf, int len) { struct iovec iov; int n; @@ -242,10 +231,7 @@ LbxWrite(trans_conn, proxy, buf, len) } static Bool -LbxAppendOutput(proxy, client, oco) - LbxProxyPtr proxy; - ClientPtr client; - ConnectionOutputPtr oco; +LbxAppendOutput(LbxProxyPtr proxy, ClientPtr client, ConnectionOutputPtr oco) { ConnectionOutputPtr noco = proxy->olast; LbxClientPtr lbxClient = LbxClient(client); @@ -317,12 +303,8 @@ LbxAppendOutput(proxy, client, oco) } static int -LbxClientOutput(client, oc, extraBuf, extraCount, nocompress) - ClientPtr client; - OsCommPtr oc; - char *extraBuf; - int extraCount; - Bool nocompress; +LbxClientOutput(ClientPtr client, OsCommPtr oc, + char *extraBuf, int extraCount, Bool nocompress) { ConnectionOutputPtr oco; int len; @@ -367,8 +349,7 @@ LbxClientOutput(client, oc, extraBuf, extraCount, nocompress) } void -LbxForceOutput(proxy) - LbxProxyPtr proxy; +LbxForceOutput(LbxProxyPtr proxy) { int i; LbxClientPtr lbxClient; @@ -388,11 +369,8 @@ LbxForceOutput(proxy) } int -LbxFlushClient(who, oc, extraBuf, extraCount) - ClientPtr who; - OsCommPtr oc; - char *extraBuf; - int extraCount; +LbxFlushClient(ClientPtr who, OsCommPtr oc, + char *extraBuf, int extraCount) { LbxProxyPtr proxy; ConnectionOutputPtr oco; @@ -459,17 +437,13 @@ LbxFlushClient(who, oc, extraBuf, extraCount) } int -UncompressedWriteToClient (who, count, buf) - ClientPtr who; - char *buf; - int count; +UncompressedWriteToClient (ClientPtr who, int count, char *buf) { return LbxClientOutput(who, (OsCommPtr)who->osPrivate, buf, count, TRUE); } void -LbxFreeOsBuffers(proxy) - LbxProxyPtr proxy; +LbxFreeOsBuffers(LbxProxyPtr proxy) { ConnectionOutputPtr oco; @@ -481,12 +455,10 @@ LbxFreeOsBuffers(proxy) } Bool -AllocateLargeReqBuffer(client, size) - ClientPtr client; - int size; +AllocateLargeReqBuffer(ClientPtr client, int size) { OsCommPtr oc = (OsCommPtr)client->osPrivate; - register ConnectionInputPtr oci; + ConnectionInputPtr oci; if (!(oci = oc->largereq)) { if ((oci = FreeInputs)) @@ -522,13 +494,10 @@ AllocateLargeReqBuffer(client, size) } Bool -AddToLargeReqBuffer(client, data, size) - ClientPtr client; - char *data; - int size; +AddToLargeReqBuffer(ClientPtr client, char *data, int size) { OsCommPtr oc = (OsCommPtr)client->osPrivate; - register ConnectionInputPtr oci = oc->largereq; + ConnectionInputPtr oci = oc->largereq; if (!oci || (oci->bufcnt + size > oci->lenLastReq)) return FALSE; @@ -540,11 +509,10 @@ AddToLargeReqBuffer(client, data, size) static OsCommRec lbxAvailableInput; int -PrepareLargeReqBuffer(client) - ClientPtr client; +PrepareLargeReqBuffer(ClientPtr client) { OsCommPtr oc = (OsCommPtr)client->osPrivate; - register ConnectionInputPtr oci = oc->largereq; + ConnectionInputPtr oci = oc->largereq; if (!oci) return client->req_len << 2; @@ -560,7 +528,7 @@ PrepareLargeReqBuffer(client) oci->lenLastReq = 0; if (AvailableInput) { - register ConnectionInputPtr aci = AvailableInput->input; + ConnectionInputPtr aci = AvailableInput->input; if (aci->size > BUFWATERMARK) { xfree(aci->buffer); diff --git a/os/oscolor.c b/os/oscolor.c index 62676f84b..f6e941fb8 100644 --- a/os/oscolor.c +++ b/os/oscolor.c @@ -1,4 +1,4 @@ -/* $XFree86: xc/programs/Xserver/os/oscolor.c,v 3.8 2002/05/31 18:46:06 dawes Exp $ */ +/* $XFree86: xc/programs/Xserver/os/oscolor.c,v 3.11 2003/09/24 02:43:36 dawes Exp $ */ /*********************************************************** Copyright 1987, 1998 The Open Group @@ -70,10 +70,13 @@ DBM *rgb_dbm = (DBM *)NULL; int rgb_dbm = 0; #endif -extern void CopyISOLatin1Lowered(); +extern void CopyISOLatin1Lowered( + unsigned char * /*dest*/, + unsigned char * /*source*/, + int /*length*/); int -OsInitColors() +OsInitColors(void) { if (!rgb_dbm) { @@ -93,12 +96,8 @@ OsInitColors() /*ARGSUSED*/ int -OsLookupColor(screen, name, len, pred, pgreen, pblue) - int screen; - char *name; - unsigned len; - unsigned short *pred, *pgreen, *pblue; - +OsLookupColor(int screen, char *name, unsigned int len, + unsigned short *pred, unsigned short *pgreen, unsigned short *pblue) { datum dbent; RGB rgb; @@ -164,23 +163,23 @@ typedef struct _dbEntry { } dbEntry; -extern void CopyISOLatin1Lowered(); +extern void CopyISOLatin1Lowered( + unsigned char * /*dest*/, + unsigned char * /*source*/, + int /*length*/); static dbEntryPtr hashTab[HASHSIZE]; static dbEntryPtr -lookup(name, len, create) - char *name; - int len; - Bool create; +lookup(char *name, int len, Bool create) { unsigned int h = 0, g; dbEntryPtr entry, *prev = NULL; char *str = name; if (!(name = (char*)ALLOCATE_LOCAL(len +1))) return NULL; - CopyISOLatin1Lowered(name, str, len); + CopyISOLatin1Lowered((unsigned char *)name, (unsigned char *)str, len); name[len] = '\0'; for(str = name; *str; str++) { @@ -212,7 +211,7 @@ lookup(name, len, create) Bool -OsInitColors() +OsInitColors(void) { FILE *rgb; char *path; @@ -281,12 +280,8 @@ OsInitColors() Bool -OsLookupColor(screen, name, len, pred, pgreen, pblue) - int screen; - char *name; - unsigned len; - unsigned short *pred, *pgreen, *pblue; - +OsLookupColor(int screen, char *name, unsigned int len, + unsigned short *pred, unsigned short *pgreen, unsigned short *pblue) { dbEntryPtr entry; diff --git a/os/osdep.h b/os/osdep.h index a1fe2bfed..a5392ffc3 100644 --- a/os/osdep.h +++ b/os/osdep.h @@ -1,4 +1,4 @@ -/* $XFree86: xc/programs/Xserver/os/osdep.h,v 3.17 2002/05/31 18:46:06 dawes Exp $ */ +/* $XFree86: xc/programs/Xserver/os/osdep.h,v 3.18 2003/04/27 21:31:09 herrb Exp $ */ /*********************************************************** Copyright 1987, 1998 The Open Group @@ -215,6 +215,8 @@ extern int StandardFlushClient( char* /*extraBuf*/, int /*extraCount*/ ); +extern int LbxFlushClient(ClientPtr /*who*/, OsCommPtr /*oc*/, + char */*extraBuf*/, int /*extraCount*/); #else extern int FlushClient( ClientPtr /*who*/, diff --git a/os/osinit.c b/os/osinit.c index 9d9fcda4e..1c56d0af7 100644 --- a/os/osinit.c +++ b/os/osinit.c @@ -1,4 +1,4 @@ -/* $XFree86: xc/programs/Xserver/os/osinit.c,v 3.27 2002/06/17 08:04:18 alanh Exp $ */ +/* $XFree86: xc/programs/Xserver/os/osinit.c,v 3.30 2003/10/29 04:17:22 dawes Exp $ */ /*********************************************************** Copyright 1987, 1998 The Open Group @@ -95,7 +95,7 @@ extern void xf86WrapperInit(void); #endif void -OsInit() +OsInit(void) { static Bool been_here = FALSE; static char* admpath = ADMPATH; @@ -216,6 +216,11 @@ OsInit() #ifdef DDXOSINIT OsVendorInit(); #endif + /* + * No log file by default. OsVendorInit() should call LogInit() with the + * log file name if logging to a file is desired. + */ + LogInit(NULL, NULL); #ifdef SMART_SCHEDULE if (!SmartScheduleDisable) if (!SmartScheduleInit ()) @@ -226,9 +231,12 @@ OsInit() } void -OsCleanup() +OsCleanup(Bool terminating) { #ifdef SERVER_LOCK - UnlockServer(); + if (terminating) + { + UnlockServer(); + } #endif } diff --git a/os/rpcauth.c b/os/rpcauth.c index 7ee53b52d..512b3ecb5 100644 --- a/os/rpcauth.c +++ b/os/rpcauth.c @@ -26,7 +26,7 @@ other dealings in this Software without prior written authorization from The Open Group. */ -/* $XFree86: xc/programs/Xserver/os/rpcauth.c,v 3.7 2001/12/14 20:00:35 dawes Exp $ */ +/* $XFree86: xc/programs/Xserver/os/rpcauth.c,v 3.8 2003/04/27 21:31:09 herrb Exp $ */ /* * SUN-DES-1 authentication mechanism @@ -62,9 +62,7 @@ extern bool_t xdr_opaque_auth(XDR *, struct opaque_auth *); static enum auth_stat why; static char * -authdes_ezdecode(inmsg, len) -char *inmsg; -int len; +authdes_ezdecode(char *inmsg, int len) { struct rpc_msg msg; char cred_area[MAX_AUTH_BYTES]; @@ -136,11 +134,8 @@ CheckNetName ( static char rpc_error[MAXNETNAMELEN+50]; XID -SecureRPCCheck (data_length, data, client, reason) - register unsigned short data_length; - char *data; - ClientPtr client; - char **reason; +SecureRPCCheck (unsigned short data_length, char *data, + ClientPtr client, char **reason) { char *fullname; @@ -170,10 +165,7 @@ SecureRPCInit (void) } int -SecureRPCAdd (data_length, data, id) -unsigned short data_length; -char *data; -XID id; +SecureRPCAdd (unsigned short data_length, char *data, XID id) { if (data_length) AddHost ((pointer) 0, FamilyNetname, data_length, data); @@ -189,26 +181,19 @@ SecureRPCReset (void) } XID -SecureRPCToID (data_length, data) - unsigned short data_length; - char *data; +SecureRPCToID (unsigned short data_length, char *data) { return rpc_id; } int -SecureRPCFromID (id, data_lenp, datap) - XID id; - unsigned short *data_lenp; - char **datap; +SecureRPCFromID (XID id, unsigned short *data_lenp, char **datap) { return 0; } int -SecureRPCRemove (data_length, data) - unsigned short data_length; - char *data; +SecureRPCRemove (unsigned short data_length, char *data) { return 0; } diff --git a/os/utils.c b/os/utils.c index 4bbe9eb8c..e01793604 100644 --- a/os/utils.c +++ b/os/utils.c @@ -49,7 +49,7 @@ OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $XFree86: xc/programs/Xserver/os/utils.c,v 3.85 2002/12/24 17:43:00 tsi Exp $ */ +/* $XFree86: xc/programs/Xserver/os/utils.c,v 3.95 2003/10/01 18:36:38 alanh Exp $ */ #ifdef __CYGWIN__ #include <stdlib.h> @@ -63,6 +63,7 @@ OR PERFORMANCE OF THIS SOFTWARE. #include <stdio.h> #include "misc.h" #include "X.h" +#include <X11/Xtrans.h> #include "input.h" #include "dixfont.h" #include "osdep.h" @@ -135,10 +136,6 @@ Bool PanoramiXWindowExposureSent = FALSE; Bool PanoramiXOneExposeRequest = FALSE; #endif -#ifdef DDXOSVERRORF -void (*OsVendorVErrorFProc)(const char *, va_list args) = NULL; -#endif - int auditTrailLevel = 1; Bool Must_have_memory = FALSE; @@ -154,6 +151,10 @@ extern int SelectWaitTime; #endif #endif +#if defined(SVR4) || defined(__linux__) || defined(CSRG_BASED) +#define HAS_SAVED_IDS_AND_SETEUID +#endif + #ifdef MEMBUG #define MEM_FAIL_SCALE 100000 long Memory_fail = 0; @@ -166,6 +167,8 @@ int userdefinedfontpath = 0; char *dev_tty_from_init = NULL; /* since we need to parse it anyway */ +extern int dispatchExceptionAtReset; + OsSigHandlerPtr OsSignal(sig, handler) int sig; @@ -235,7 +238,7 @@ static Bool nolock = FALSE; * the lock file containing the PID. */ void -LockServer() +LockServer(void) { char tmp[PATH_MAX], pid_str[12]; int lfd, i, haslock, l_pid, t; @@ -259,7 +262,7 @@ LockServer() strlen(LOCK_TMP_PREFIX); len += strlen(tmppath) + strlen(display) + strlen(LOCK_SUFFIX) + 1; if (len > sizeof(LockFile)) - FatalError("Display name `%s' is too long\n"); + FatalError("Display name `%s' is too long\n", display); (void)sprintf(tmp, "%s" LOCK_TMP_PREFIX "%s" LOCK_SUFFIX, tmppath, display); (void)sprintf(LockFile, "%s" LOCK_PREFIX "%s" LOCK_SUFFIX, tmppath, display); @@ -372,7 +375,7 @@ LockServer() * Remove the server lock file. */ void -UnlockServer() +UnlockServer(void) { if (nolock) return; @@ -390,8 +393,7 @@ UnlockServer() /*ARGSUSED*/ SIGVAL -AutoResetServer (sig) - int sig; +AutoResetServer (int sig) { int olderrno = errno; @@ -411,8 +413,7 @@ AutoResetServer (sig) /*ARGSUSED*/ SIGVAL -GiveUp(sig) - int sig; +GiveUp(int sig) { int olderrno = errno; @@ -425,31 +426,9 @@ GiveUp(sig) errno = olderrno; } -#ifdef __GNUC__ -static void AbortServer() __attribute__((noreturn)); -#endif - -static void -AbortServer() -{ - OsCleanup(); - AbortDDX(); - fflush(stderr); - if (CoreDump) - abort(); - exit (1); -} - -void -Error(str) - char *str; -{ - perror(str); -} - #ifndef DDXTIME CARD32 -GetTimeInMillis() +GetTimeInMillis(void) { struct timeval tp; @@ -459,9 +438,7 @@ GetTimeInMillis() #endif void -AdjustWaitForDelay (waitTime, newdelay) - pointer waitTime; - unsigned long newdelay; +AdjustWaitForDelay (pointer waitTime, unsigned long newdelay) { static struct timeval delay_val; struct timeval **wt = (struct timeval **) waitTime; @@ -484,7 +461,7 @@ AdjustWaitForDelay (waitTime, newdelay) } } -void UseMsg() +void UseMsg(void) { #if !defined(AIXrt) && !defined(AIX386) ErrorF("use: X [:<display>] [option]\n"); @@ -558,10 +535,15 @@ void UseMsg() ErrorF("-v screen-saver without video blanking\n"); ErrorF("-wm WhenMapped default backing-store\n"); ErrorF("-x string loads named extension at init time \n"); + ErrorF("-maxbigreqsize set maximal bigrequest size \n"); #ifdef PANORAMIX ErrorF("+xinerama Enable XINERAMA extension\n"); ErrorF("-xinerama Disable XINERAMA extension\n"); #endif +#ifdef SMART_SCHEDULE + ErrorF("-dumbSched Disable smart scheduling, enable old behavior\n"); + ErrorF("-schedInterval int Set scheduler interval in msec\n"); +#endif #ifdef XDMCP XdmcpUseMsg(); #endif @@ -579,8 +561,8 @@ void UseMsg() * not contain a "/" and not start with a "-". * --kvajk */ -int VerifyDisplayName( d ) -char *d; +static int +VerifyDisplayName(const char *d) { if ( d == (char *)0 ) return( 0 ); /* null */ if ( *d == '\0' ) return( 0 ); /* empty */ @@ -596,10 +578,7 @@ char *d; * argc or any of the strings pointed to by argv. */ void -ProcessCommandLine ( argc, argv ) -int argc; -char *argv[]; - +ProcessCommandLine(int argc, char *argv[]) { int i, skip; @@ -817,15 +796,15 @@ char *argv[]; #endif else if ( strcmp( argv[i], "-nolisten") == 0) { - if(++i < argc) - protNoListen = argv[i]; - else + if(++i < argc) { + if (_XSERVTransNoListen(argv[i])) + FatalError ("Failed to disable listen for %s transport", + argv[i]); + } else UseMsg(); } else if ( strcmp( argv[i], "-noreset") == 0) { - extern char dispatchExceptionAtReset; - dispatchExceptionAtReset = 0; } else if ( strcmp( argv[i], "-p") == 0) @@ -863,8 +842,6 @@ char *argv[]; } else if ( strcmp( argv[i], "-terminate") == 0) { - extern char dispatchExceptionAtReset; - dispatchExceptionAtReset = DE_TERMINATE; } else if ( strcmp( argv[i], "-to") == 0) @@ -884,6 +861,24 @@ char *argv[]; defaultScreenSaverBlanking = DontPreferBlanking; else if ( strcmp( argv[i], "-wm") == 0) defaultBackingStore = WhenMapped; + else if ( strcmp( argv[i], "-maxbigreqsize") == 0) { + if(++i < argc) { + int reqSizeArg = atoi(argv[i]); + + /* Request size > 128MB does not make much sense... */ + if( reqSizeArg > 0 && reqSizeArg < 128 ) { + maxBigRequestSize = (reqSizeArg * 1048576) - 1; + } + else + { + UseMsg(); + } + } + else + { + UseMsg(); + } + } #ifdef PANORAMIX else if ( strcmp( argv[i], "+xinerama") == 0){ noPanoramiXExtension = FALSE; @@ -993,15 +988,11 @@ char *argv[]; #ifdef COMMANDLINE_CHALLENGED_OPERATING_SYSTEMS static void -InsertFileIntoCommandLine(resargc, resargv, prefix_argc, prefix_argv, - filename, suffix_argc, suffix_argv) - int *resargc; - char ***resargv; - int prefix_argc; - char **prefix_argv; - char *filename; - int suffix_argc; - char **suffix_argv; +InsertFileIntoCommandLine( + int *resargc, char ***resargv, + int prefix_argc, char **prefix_argv, + char *filename, + int suffix_argc, char **suffix_argv) { struct stat st; FILE *f; @@ -1084,9 +1075,7 @@ InsertFileIntoCommandLine(resargc, resargv, prefix_argc, prefix_argv, void -ExpandCommandLine(pargc, pargv) - int *pargc; - char ***pargv; +ExpandCommandLine(int *pargc, char ***pargv) { int i; @@ -1112,42 +1101,61 @@ ExpandCommandLine(pargc, pargv) /* Implement a simple-minded font authorization scheme. The authorization name is "hp-hostname-1", the contents are simply the host name. */ int -set_font_authorizations(authorizations, authlen, client) -char **authorizations; -int *authlen; -pointer client; +set_font_authorizations(char **authorizations, int *authlen, pointer client) { #define AUTHORIZATION_NAME "hp-hostname-1" #if defined(TCPCONN) || defined(STREAMSCONN) - static char result[1024]; + static char *result = NULL; static char *p = NULL; if (p == NULL) { char hname[1024], *hnameptr; + unsigned int len; +#if defined(IPv6) && defined(AF_INET6) + struct addrinfo hints, *ai = NULL; +#else struct hostent *host; - int len; #ifdef XTHREADS_NEEDS_BYNAMEPARAMS _Xgethostbynameparams hparams; #endif +#endif gethostname(hname, 1024); +#if defined(IPv6) && defined(AF_INET6) + bzero(&hints, sizeof(hints)); + hints.ai_flags = AI_CANONNAME; + if (getaddrinfo(hname, NULL, &hints, &ai) == 0) { + hnameptr = ai->ai_canonname; + } else { + hnameptr = hname; + } +#else host = _XGethostbyname(hname, hparams); if (host == NULL) hnameptr = hname; else hnameptr = host->h_name; +#endif + + len = strlen(hnameptr) + 1; + result = xalloc(len + sizeof(AUTHORIZATION_NAME) + 4); p = result; *p++ = sizeof(AUTHORIZATION_NAME) >> 8; *p++ = sizeof(AUTHORIZATION_NAME) & 0xff; - *p++ = (len = strlen(hnameptr) + 1) >> 8; + *p++ = (len) >> 8; *p++ = (len & 0xff); memmove(p, AUTHORIZATION_NAME, sizeof(AUTHORIZATION_NAME)); p += sizeof(AUTHORIZATION_NAME); memmove(p, hnameptr, len); p += len; +#if defined(IPv6) && defined(AF_INET6) + if (ai) { + freeaddrinfo(ai); + } +#endif } *authlen = p - result; *authorizations = result; @@ -1172,8 +1180,7 @@ pointer client; #ifndef INTERNAL_MALLOC void * -Xalloc (amount) - unsigned long amount; +Xalloc(unsigned long amount) { register pointer ptr; @@ -1201,8 +1208,7 @@ Xalloc (amount) *****************/ void * -XNFalloc (amount) - unsigned long amount; +XNFalloc(unsigned long amount) { register pointer ptr; @@ -1225,8 +1231,7 @@ XNFalloc (amount) *****************/ void * -Xcalloc (amount) - unsigned long amount; +Xcalloc(unsigned long amount) { unsigned long *ret; @@ -1241,8 +1246,7 @@ Xcalloc (amount) *****************/ void * -XNFcalloc (amount) - unsigned long amount; +XNFcalloc(unsigned long amount) { unsigned long *ret; @@ -1259,9 +1263,7 @@ XNFcalloc (amount) *****************/ void * -Xrealloc (ptr, amount) - register pointer ptr; - unsigned long amount; +Xrealloc(pointer ptr, unsigned long amount) { #ifdef MEMBUG if (!Must_have_memory && Memory_fail && @@ -1292,9 +1294,7 @@ Xrealloc (ptr, amount) *****************/ void * -XNFrealloc (ptr, amount) - register pointer ptr; - unsigned long amount; +XNFrealloc(pointer ptr, unsigned long amount) { if (( ptr = (pointer)Xrealloc( ptr, amount ) ) == NULL) { @@ -1310,15 +1310,14 @@ XNFrealloc (ptr, amount) *****************/ void -Xfree(ptr) - register pointer ptr; +Xfree(pointer ptr) { if (ptr) free((char *)ptr); } void -OsInitAllocator () +OsInitAllocator (void) { #ifdef MEMBUG static int been_here; @@ -1361,110 +1360,6 @@ XNFstrdup(const char *s) return sd; } - -void -AuditPrefix(f) - const char *f; -{ - time_t tm; - char *autime, *s; - if (*f != ' ') - { - time(&tm); - autime = ctime(&tm); - if ((s = strchr(autime, '\n'))) - *s = '\0'; - if ((s = strrchr(argvGlobal[0], '/'))) - s++; - else - s = argvGlobal[0]; - ErrorF("AUDIT: %s: %d %s: ", autime, getpid(), s); - } -} - -void -AuditF(const char * f, ...) -{ - va_list args; - - AuditPrefix(f); - - va_start(args, f); - VErrorF(f, args); - va_end(args); -} - -void -FatalError(const char *f, ...) -{ - va_list args; - static Bool beenhere = FALSE; - - if (beenhere) - ErrorF("\nFatalError re-entered, aborting\n"); - else - ErrorF("\nFatal server error:\n"); - - va_start(args, f); - VErrorF(f, args); - va_end(args); - ErrorF("\n"); -#ifdef DDXOSFATALERROR - if (!beenhere) - OsVendorFatalError(); -#endif -#ifdef ABORTONFATALERROR - abort(); -#endif - if (!beenhere) { - beenhere = TRUE; - AbortServer(); - } else - abort(); - /*NOTREACHED*/ -} - -void -VErrorF(f, args) - const char *f; - va_list args; -{ -#ifdef AIXV3 - if (SyncOn) - sync(); -#else -#ifdef DDXOSVERRORF - if (OsVendorVErrorFProc) - OsVendorVErrorFProc(f, args); - else - vfprintf(stderr, f, args); -#else - vfprintf(stderr, f, args); -#endif -#endif /* AIXV3 */ -} - -void -VFatalError(const char *msg, va_list args) -{ - VErrorF(msg, args); - ErrorF("\n"); -#ifdef DDXOSFATALERROR - OsVendorFatalError(); -#endif - AbortServer(); - /*NOTREACHED*/ -} - -void -ErrorF(const char * f, ...) -{ - va_list args; - va_start(args, f); - VErrorF(f, args); - va_end(args); -} - #ifdef SMART_SCHEDULE unsigned long SmartScheduleIdleCount; @@ -1480,7 +1375,7 @@ Bool SmartScheduleTimerStopped; #define SMART_SCHEDULE_TIMER ITIMER_REAL #endif -void +static void SmartScheduleStopTimer (void) { #ifdef SMART_SCHEDULE_POSSIBLE @@ -1512,7 +1407,7 @@ SmartScheduleStartTimer (void) } #ifdef SMART_SCHEDULE_POSSIBLE -void +static void SmartScheduleTimer (int sig) { int olderrno = errno; @@ -1624,8 +1519,7 @@ OsReleaseSignals (void) */ int -System(command) - char *command; +System(char *command) { int pid, p; #ifdef SIGCHLD @@ -1673,9 +1567,7 @@ static struct pid { } *pidlist; pointer -Popen(command, type) - char *command; - char *type; +Popen(char *command, char *type) { struct pid *cur; FILE *iop; @@ -1747,9 +1639,100 @@ Popen(command, type) return iop; } +/* fopen that drops privileges */ +pointer +Fopen(char *file, char *type) +{ + FILE *iop; +#ifndef HAS_SAVED_IDS_AND_SETEUID + struct pid *cur; + int pdes[2], pid; + + if (file == NULL || type == NULL) + return NULL; + + if ((*type != 'r' && *type != 'w') || type[1]) + return NULL; + + if ((cur = (struct pid *)xalloc(sizeof(struct pid))) == NULL) + return NULL; + + if (pipe(pdes) < 0) { + xfree(cur); + return NULL; + } + + switch (pid = fork()) { + case -1: /* error */ + close(pdes[0]); + close(pdes[1]); + xfree(cur); + return NULL; + case 0: /* child */ + setgid(getgid()); + setuid(getuid()); + if (*type == 'r') { + if (pdes[1] != 1) { + /* stdout */ + dup2(pdes[1], 1); + close(pdes[1]); + } + close(pdes[0]); + } else { + if (pdes[0] != 0) { + /* stdin */ + dup2(pdes[0], 0); + close(pdes[0]); + } + close(pdes[1]); + } + execl("/bin/cat", "cat", file, (char *)NULL); + _exit(127); + } + + /* Avoid EINTR during stdio calls */ + OsBlockSignals (); + + /* parent */ + if (*type == 'r') { + iop = fdopen(pdes[0], type); + close(pdes[1]); + } else { + iop = fdopen(pdes[1], type); + close(pdes[0]); + } + + cur->fp = iop; + cur->pid = pid; + cur->next = pidlist; + pidlist = cur; + +#ifdef DEBUG + ErrorF("Popen: `%s', fp = %p\n", command, iop); +#endif + + return iop; +#else + int ruid, euid; + + ruid = getuid(); + euid = geteuid(); + + if (seteuid(ruid) == -1) { + return NULL; + } + iop = fopen(file, type); + + if (seteuid(euid) == -1) { + fclose(iop); + return NULL; + } + return iop; +#endif /* HAS_SAVED_IDS_AND_SETEUID */ +} + int -Pclose(iop) - pointer iop; +Pclose(pointer iop) { struct pid *cur, *last; int pstat; @@ -1782,6 +1765,17 @@ Pclose(iop) return pid == -1 ? -1 : pstat; } + +int +Fclose(pointer iop) +{ +#ifdef HAS_SAVED_IDS_AND_SETEUID + return fclose(iop); +#else + return Pclose(iop); +#endif +} + #endif /* !WIN32 && !__UNIXOS2__ */ @@ -2007,7 +2001,7 @@ CheckUserParameters(int argc, char **argv, char **envp) #endif /* USE_PAM */ void -CheckUserAuthorization() +CheckUserAuthorization(void) { #ifdef USE_PAM static struct pam_conv conv = { diff --git a/os/xalloc.c b/os/xalloc.c index b42d91cd2..8bb46e2c9 100644 --- a/os/xalloc.c +++ b/os/xalloc.c @@ -26,7 +26,7 @@ dealings in this Software without prior written authorization from Pascal Haible. */ -/* $XFree86: xc/programs/Xserver/os/xalloc.c,v 3.33 2002/04/04 14:05:57 eich Exp $ */ +/* $XFree86: xc/programs/Xserver/os/xalloc.c,v 3.36 2003/11/03 05:12:00 tsi Exp $ */ /* Only used if INTERNAL_MALLOC is defined * - otherwise xalloc() in utils.c is used @@ -179,11 +179,13 @@ extern Bool Must_have_memory; #define TAIL_SIZE 0 #endif -#if defined(__alpha__) || defined(__alpha) || \ +#if defined (_LP64) || \ + defined(__alpha__) || defined(__alpha) || \ defined(__ia64__) || defined(ia64) || \ defined(__sparc64__) || \ defined(__s390x__) || \ - defined(__x86_64__) || defined(x86_64) + defined(__AMD64__) || defined(AMD64) || \ + (defined(sgi) && _MIPS_SZLONG == 64)) #define MAGIC 0x1404196414071968 #define MAGIC_FREE 0x1506196615061966 #define MAGIC2 0x2515207525182079 diff --git a/os/xdmauth.c b/os/xdmauth.c index eb1385408..13695c13c 100644 --- a/os/xdmauth.c +++ b/os/xdmauth.c @@ -26,7 +26,7 @@ other dealings in this Software without prior written authorization from The Open Group. */ -/* $XFree86: xc/programs/Xserver/os/xdmauth.c,v 1.7 2002/11/05 05:50:34 keithp Exp $ */ +/* $XFree86: xc/programs/Xserver/os/xdmauth.c,v 1.9 2003/06/24 15:44:48 eich Exp $ */ /* * XDM-AUTHENTICATION-1 (XDMCP authentication) and @@ -58,9 +58,9 @@ static char XdmAuthenticationName[] = "XDM-AUTHENTICATION-1"; #define XdmAuthenticationNameLen (sizeof XdmAuthenticationName - 1) static XdmAuthKeyRec rho; -static Bool XdmAuthenticationValidator (privateData, incomingData, packet_type) - ARRAY8Ptr privateData, incomingData; - xdmOpCode packet_type; +static Bool +XdmAuthenticationValidator (ARRAY8Ptr privateData, ARRAY8Ptr incomingData, + xdmOpCode packet_type) { XdmAuthKeyPtr incoming; @@ -79,9 +79,8 @@ static Bool XdmAuthenticationValidator (privateData, incomingData, packet_type) } static Bool -XdmAuthenticationGenerator (privateData, outgoingData, packet_type) - ARRAY8Ptr privateData, outgoingData; - xdmOpCode packet_type; +XdmAuthenticationGenerator (ARRAY8Ptr privateData, ARRAY8Ptr outgoingData, + xdmOpCode packet_type) { outgoingData->length = 0; outgoingData->data = 0; @@ -95,12 +94,11 @@ XdmAuthenticationGenerator (privateData, outgoingData, packet_type) } static Bool -XdmAuthenticationAddAuth (name_len, name, data_len, data) - int name_len, data_len; - char *name, *data; +XdmAuthenticationAddAuth (int name_len, char *name, + int data_len, char *data) { Bool ret; - XdmcpUnwrap (data, &privateKey, data, data_len); + XdmcpUnwrap (data, (unsigned char *)&privateKey, data, data_len); authFromXDMCP = TRUE; ret = AddAuthorization (name_len, name, data_len, data); authFromXDMCP = FALSE; @@ -113,9 +111,7 @@ XdmAuthenticationAddAuth (name_len, name, data_len, data) 'A' <= c && c <= 'F' ? c - 'A' + 10 : -1) static int -HexToBinary (in, out, len) - char *out, *in; - int len; +HexToBinary (char *in, char *out, int len) { int top, bottom; @@ -138,9 +134,7 @@ HexToBinary (in, out, len) } void -XdmAuthenticationInit (cookie, cookie_len) - char *cookie; - int cookie_len; +XdmAuthenticationInit (char *cookie, int cookie_len) { bzero (privateKey.data, 8); if (!strncmp (cookie, "0x", 2) || !strncmp (cookie, "0X", 2)) @@ -157,7 +151,7 @@ XdmAuthenticationInit (cookie, cookie_len) } XdmcpGenerateKey (&rho); XdmcpRegisterAuthentication (XdmAuthenticationName, XdmAuthenticationNameLen, - &rho, + (unsigned char *)&rho, sizeof (rho), XdmAuthenticationValidator, XdmAuthenticationGenerator, @@ -191,8 +185,7 @@ static Bool gotClock; #define TwentyFiveMinutes (25 * 60) static Bool -XdmClientAuthCompare (a, b) - XdmClientAuthPtr a, b; +XdmClientAuthCompare (XdmClientAuthPtr a, XdmClientAuthPtr b) { int i; @@ -205,9 +198,7 @@ XdmClientAuthCompare (a, b) } static void -XdmClientAuthDecode (plain, auth) - unsigned char *plain; - XdmClientAuthPtr auth; +XdmClientAuthDecode (unsigned char *plain, XdmClientAuthPtr auth) { int i, j; @@ -231,8 +222,7 @@ XdmClientAuthDecode (plain, auth) } static void -XdmClientAuthTimeout (now) - long now; +XdmClientAuthTimeout (long now) { XdmClientAuthPtr client, next, prev; @@ -254,12 +244,8 @@ XdmClientAuthTimeout (now) } static XdmClientAuthPtr -XdmAuthorizationValidate (plain, length, rho, xclient, reason) - unsigned char *plain; - int length; - XdmAuthKeyPtr rho; - ClientPtr xclient; - char **reason; +XdmAuthorizationValidate (unsigned char *plain, int length, + XdmAuthKeyPtr rho, ClientPtr xclient, char **reason) { XdmClientAuthPtr client, existing; long now; @@ -338,10 +324,7 @@ XdmAuthorizationValidate (plain, length, rho, xclient, reason) } int -XdmAddCookie (data_length, data, id) -unsigned short data_length; -char *data; -XID id; +XdmAddCookie (unsigned short data_length, char *data, XID id) { XdmAuthorizationPtr new; unsigned char *rho_bits, *key_bits; @@ -389,11 +372,8 @@ XID id; } XID -XdmCheckCookie (cookie_length, cookie, xclient, reason) - unsigned short cookie_length; - char *cookie; - ClientPtr xclient; - char **reason; +XdmCheckCookie (unsigned short cookie_length, char *cookie, + ClientPtr xclient, char **reason) { XdmAuthorizationPtr auth; XdmClientAuthPtr client; @@ -406,8 +386,8 @@ XdmCheckCookie (cookie_length, cookie, xclient, reason) if (!plain) return (XID) -1; for (auth = xdmAuth; auth; auth=auth->next) { - XdmcpUnwrap (cookie, &auth->key, plain, cookie_length); - if (client = XdmAuthorizationValidate (plain, cookie_length, &auth->rho, xclient, reason)) + XdmcpUnwrap (cookie, (unsigned char *)&auth->key, plain, cookie_length); + if ((client = XdmAuthorizationValidate (plain, cookie_length, &auth->rho, xclient, reason)) != NULL) { client->next = xdmClients; xdmClients = client; @@ -441,9 +421,7 @@ XdmResetCookie (void) } XID -XdmToID (cookie_length, cookie) -unsigned short cookie_length; -char *cookie; +XdmToID (unsigned short cookie_length, char *cookie) { XdmAuthorizationPtr auth; XdmClientAuthPtr client; @@ -453,8 +431,8 @@ char *cookie; if (!plain) return (XID) -1; for (auth = xdmAuth; auth; auth=auth->next) { - XdmcpUnwrap (cookie, &auth->key, plain, cookie_length); - if (client = XdmAuthorizationValidate (plain, cookie_length, &auth->rho, NULL, NULL)) + XdmcpUnwrap (cookie, (unsigned char *)&auth->key, plain, cookie_length); + if ((client = XdmAuthorizationValidate (plain, cookie_length, &auth->rho, NULL, NULL)) != NULL) { xfree (client); xfree (cookie); @@ -466,10 +444,7 @@ char *cookie; } int -XdmFromID (id, data_lenp, datap) -XID id; -unsigned short *data_lenp; -char **datap; +XdmFromID (XID id, unsigned short *data_lenp, char **datap) { XdmAuthorizationPtr auth; @@ -484,9 +459,7 @@ char **datap; } int -XdmRemoveCookie (data_length, data) -unsigned short data_length; -char *data; +XdmRemoveCookie (unsigned short data_length, char *data) { XdmAuthorizationPtr auth, prev; XdmAuthKeyPtr key_bits, rho_bits; diff --git a/os/xdmcp.c b/os/xdmcp.c index b6a5db35f..43af268e4 100644 --- a/os/xdmcp.c +++ b/os/xdmcp.c @@ -13,7 +13,7 @@ * without express or implied warranty. * */ -/* $XFree86: xc/programs/Xserver/os/xdmcp.c,v 3.21 2002/03/11 16:22:28 keithp Exp $ */ +/* $XFree86: xc/programs/Xserver/os/xdmcp.c,v 3.28 2003/11/11 00:27:14 dawes Exp $ */ #ifdef WIN32 /* avoid conflicting definitions */ @@ -43,6 +43,7 @@ #endif #include <stdio.h> +#include <stdlib.h> #include "X.h" #include "Xmd.h" #include "misc.h" @@ -65,6 +66,11 @@ #ifdef XDMCP #undef REQUEST + +#ifdef XDMCP_NO_IPV6 +#undef IPv6 +#endif + #include <X11/Xdmcp.h> #define X_INCLUDE_NETDB_H @@ -74,7 +80,12 @@ extern char *defaultDisplayClass; static int xdmcpSocket, sessionSocket; static xdmcp_states state; +#if defined(IPv6) && defined(AF_INET6) +static int xdmcpSocket6; +static struct sockaddr_storage req_sockaddr; +#else static struct sockaddr_in req_sockaddr; +#endif static int req_socklen; static CARD32 SessionID; static CARD32 timeOutTime; @@ -89,167 +100,133 @@ static char *xdmAuthCookie; static XdmcpBuffer buffer; -static struct sockaddr_in ManagerAddress; -static struct sockaddr_in FromAddress; +#if defined(IPv6) && defined(AF_INET6) + +static struct addrinfo *mgrAddr; +static struct addrinfo *mgrAddrFirst; + +#define SOCKADDR_TYPE struct sockaddr_storage +#define SOCKADDR_FAMILY(s) ((struct sockaddr *)&(s))->sa_family + +#ifdef BSD44SOCKETS +#define SOCKLEN_FIELD(s) ((struct sockaddr *)&(s))->sa_len +#define SOCKLEN_TYPE unsigned char +#else +#define SOCKLEN_TYPE unsigned int +#endif + +#else + +#define SOCKADDR_TYPE struct sockaddr_in +#define SOCKADDR_FAMILY(s) (s).sin_family + +#ifdef BSD44SOCKETS +#define SOCKLEN_FIELD(s) (s).sin_len +#define SOCKLEN_TYPE unsigned char +#else +#define SOCKLEN_TYPE size_t +#endif + +#endif + +static SOCKADDR_TYPE ManagerAddress; +static SOCKADDR_TYPE FromAddress; + +#ifdef SOCKLEN_FIELD +#define ManagerAddressLen SOCKLEN_FIELD(ManagerAddress) +#define FromAddressLen SOCKLEN_FIELD(FromAddress) +#else +static SOCKLEN_TYPE ManagerAddressLen, FromAddressLen; +#endif + +#if defined(IPv6) && defined(AF_INET6) +static struct multicastinfo { + struct multicastinfo *next; + struct addrinfo *ai; + int hops; +} *mcastlist; +#endif static void XdmcpAddHost( - struct sockaddr_in *from, + struct sockaddr *from, int fromlen, ARRAY8Ptr AuthenticationName, ARRAY8Ptr hostname, ARRAY8Ptr status); static void XdmcpSelectHost( - struct sockaddr_in *host_sockaddr, + struct sockaddr *host_sockaddr, int host_len, ARRAY8Ptr AuthenticationName); -static void get_xdmcp_sock( -#if NeedFunctionPrototypes - void -#endif -); +static void get_xdmcp_sock(void); -static void send_query_msg( -#if NeedFunctionPrototypes - void -#endif -); +static void send_query_msg(void); static void recv_willing_msg( -#if NeedFunctionPrototypes - struct sockaddr_in */*from*/, + struct sockaddr */*from*/, int /*fromlen*/, - unsigned /*length*/ -#endif -); + unsigned /*length*/); -static void send_request_msg( -#if NeedFunctionPrototypes - void -#endif -); +static void send_request_msg(void); -static void recv_accept_msg( -#if NeedFunctionPrototypes - unsigned /*length*/ -#endif -); +static void recv_accept_msg(unsigned /*length*/); -static void recv_decline_msg( -#if NeedFunctionPrototypes - unsigned /*length*/ -#endif -); +static void recv_decline_msg(unsigned /*length*/); -static void send_manage_msg( -#if NeedFunctionPrototypes - void -#endif -); +static void send_manage_msg(void); -static void recv_refuse_msg( -#if NeedFunctionPrototypes - unsigned /*length*/ -#endif -); +static void recv_refuse_msg(unsigned /*length*/); -static void recv_failed_msg( -#if NeedFunctionPrototypes - unsigned /*length*/ -#endif -); +static void recv_failed_msg(unsigned /*length*/); -static void send_keepalive_msg( -#if NeedFunctionPrototypes - void -#endif -); +static void send_keepalive_msg(void); -static void recv_alive_msg( -#if NeedFunctionPrototypes - unsigned /*length*/ -#endif -); +static void recv_alive_msg(unsigned /*length*/); static void XdmcpFatal( -#if NeedFunctionPrototypes char */*type*/, - ARRAY8Ptr /*status*/ -#endif -); - -static void XdmcpWarning( -#if NeedFunctionPrototypes - char */*str*/ -#endif -); + ARRAY8Ptr /*status*/); + +static void XdmcpWarning(char */*str*/); static void get_manager_by_name( -#if NeedFunctionPrototypes int /*argc*/, char **/*argv*/, - int /*i*/ -#endif -); + int /*i*/); static void get_fromaddr_by_name(int /*argc*/, char **/*argv*/, int /*i*/); -static void receive_packet( -#if NeedFunctionPrototypes - void +#if defined(IPv6) && defined(AF_INET6) +static int get_mcast_options(int /*argc*/, char **/*argv*/, int /*i*/); #endif -); -static void send_packet( -#if NeedFunctionPrototypes - void -#endif -); +static void receive_packet(int /*socketfd*/); -extern void XdmcpDeadSession( -#if NeedFunctionPrototypes - char */*reason*/ -#endif -); +static void send_packet(void); -static void timeout( -#if NeedFunctionPrototypes - void -#endif -); +extern void XdmcpDeadSession(char */*reason*/); -static void restart( -#if NeedFunctionPrototypes - void -#endif -); +static void timeout(void); + +static void restart(void); static void XdmcpBlockHandler( -#if NeedFunctionPrototypes pointer /*data*/, struct timeval **/*wt*/, - pointer /*LastSelectMask*/ -#endif -); + pointer /*LastSelectMask*/); static void XdmcpWakeupHandler( -#if NeedFunctionPrototypes pointer /*data*/, int /*i*/, - pointer /*LastSelectMask*/ -#endif -); + pointer /*LastSelectMask*/); void XdmcpRegisterManufacturerDisplayID( -#if NeedFunctionPrototypes char * /*name*/, - int /*length*/ -#endif -); + int /*length*/); -static short xdm_udp_port = XDM_UDP_PORT; +static unsigned short xdm_udp_port = XDM_UDP_PORT; static Bool OneSession = FALSE; static const char *xdm_from = NULL; @@ -258,6 +235,9 @@ XdmcpUseMsg (void) { ErrorF("-query host-name contact named host for XDMCP\n"); ErrorF("-broadcast broadcast for XDMCP\n"); +#if defined(IPv6) && defined(AF_INET6) + ErrorF("-multicast [addr [hops]] IPv6 multicast for XDMCP\n"); +#endif ErrorF("-indirect host-name contact named host for indirect XDMCP\n"); ErrorF("-port port-num UDP port number to send messages to\n"); ErrorF("-from local-address specify the local address to connect from\n"); @@ -273,7 +253,7 @@ int XdmcpOptions(int argc, char **argv, int i) { if (strcmp(argv[i], "-query") == 0) { - get_manager_by_name(argc, argv, ++i); + get_manager_by_name(argc, argv, i++); XDM_INIT_STATE = XDM_QUERY; AccessUsingXdmcp (); return (i + 1); @@ -283,8 +263,16 @@ XdmcpOptions(int argc, char **argv, int i) AccessUsingXdmcp (); return (i + 1); } +#if defined(IPv6) && defined(AF_INET6) + if (strcmp(argv[i], "-multicast") == 0) { + i = get_mcast_options(argc, argv, ++i); + XDM_INIT_STATE = XDM_MULTICAST; + AccessUsingXdmcp (); + return (i + 1); + } +#endif if (strcmp(argv[i], "-indirect") == 0) { - get_manager_by_name(argc, argv, ++i); + get_manager_by_name(argc, argv, i++); XDM_INIT_STATE = XDM_INDIRECT; AccessUsingXdmcp (); return (i + 1); @@ -294,7 +282,7 @@ XdmcpOptions(int argc, char **argv, int i) ErrorF("Xserver: missing port number in command line\n"); exit(1); } - xdm_udp_port = atoi(argv[i]); + xdm_udp_port = (unsigned short) atoi(argv[i]); return (i + 1); } if (strcmp(argv[i], "-from") == 0) { @@ -348,6 +336,7 @@ XdmcpOptions(int argc, char **argv, int i) #define MAX_BROADCAST 10 +/* This stays sockaddr_in since IPv6 doesn't support broadcast */ static struct sockaddr_in BroadcastAddresses[MAX_BROADCAST]; static int NumBroadcastAddresses; @@ -478,10 +467,36 @@ XdmcpRegisterConnection ( XdmcpDisposeARRAYofARRAY8 (&ConnectionAddresses); xdmcpGeneration = serverGeneration; } - if (addrlen == sizeof(struct in_addr) && xdm_from != NULL) - { - /* Only register the requested address */ - if (memcmp(address, &FromAddress.sin_addr, addrlen) != 0) { + if (xdm_from != NULL) { /* Only register the requested address */ + const void *regAddr = address; + const void *fromAddr = NULL; + int regAddrlen = addrlen; + + if (addrlen == sizeof(struct in_addr)) { + if (SOCKADDR_FAMILY(FromAddress) == AF_INET) { + fromAddr = &((struct sockaddr_in *)&FromAddress)->sin_addr; + } +#if defined(IPv6) && defined(AF_INET6) + else if ((SOCKADDR_FAMILY(FromAddress) == AF_INET6) && + IN6_IS_ADDR_V4MAPPED( + &((struct sockaddr_in6 *)&FromAddress)->sin6_addr)) { + fromAddr = &((struct sockaddr_in6 *)&FromAddress)->sin6_addr.s6_addr[12]; + } +#endif + } +#if defined(IPv6) && defined(AF_INET6) + else if (addrlen == sizeof(struct in6_addr)) { + if (SOCKADDR_FAMILY(FromAddress) == AF_INET6) { + fromAddr = &((struct sockaddr_in6 *)&FromAddress)->sin6_addr; + } else if ((SOCKADDR_FAMILY(FromAddress) == AF_INET) && + IN6_IS_ADDR_V4MAPPED((struct in6_addr *) address)) { + fromAddr = &((struct sockaddr_in *)&FromAddress)->sin_addr; + regAddr = &((struct sockaddr_in6 *)&address)->sin6_addr.s6_addr[12]; + regAddrlen = sizeof(struct in_addr); + } + } +#endif + if (fromAddr && memcmp(regAddr, fromAddr, regAddrlen) != 0) { return; } } @@ -665,6 +680,10 @@ XdmcpBlockHandler( if (state == XDM_OFF) return; FD_SET(xdmcpSocket, LastSelectMask); +#if defined(IPv6) && defined(AF_INET6) + if (xdmcpSocket6 >= 0) + FD_SET(xdmcpSocket6, LastSelectMask); +#endif if (timeOutTime == 0) return; millisToGo = timeOutTime - GetTimeInMillis(); @@ -695,9 +714,16 @@ XdmcpWakeupHandler( { if (FD_ISSET(xdmcpSocket, LastSelectMask)) { - receive_packet(); + receive_packet(xdmcpSocket); FD_CLR(xdmcpSocket, LastSelectMask); } +#if defined(IPv6) && defined(AF_INET6) + if (xdmcpSocket6 >= 0 && FD_ISSET(xdmcpSocket6, LastSelectMask)) + { + receive_packet(xdmcpSocket6); + FD_CLR(xdmcpSocket6, LastSelectMask); + } +#endif XFD_ANDSET(&devicesReadable, LastSelectMask, &EnabledDevices); if (XFD_ANYSET(&devicesReadable)) { @@ -728,10 +754,18 @@ XdmcpWakeupHandler( static void XdmcpSelectHost( - struct sockaddr_in *host_sockaddr, + struct sockaddr *host_sockaddr, int host_len, ARRAY8Ptr AuthenticationName) { +#if defined(IPv6) && defined(AF_INET6) + /* Don't need list of addresses for host anymore */ + if (mgrAddrFirst != NULL) { + freeaddrinfo(mgrAddrFirst); + mgrAddrFirst = NULL; + mgrAddr = NULL; + } +#endif state = XDM_START_CONNECTION; memmove(&req_sockaddr, host_sockaddr, host_len); req_socklen = host_len; @@ -748,7 +782,7 @@ XdmcpSelectHost( /*ARGSUSED*/ static void XdmcpAddHost( - struct sockaddr_in *from, + struct sockaddr *from, int fromlen, ARRAY8Ptr AuthenticationName, ARRAY8Ptr hostname, @@ -765,14 +799,18 @@ XdmcpAddHost( ARRAY8 UnwillingMessage = { (CARD8) 14, (CARD8 *) "Host unwilling" }; static void -receive_packet(void) +receive_packet(int socketfd) { +#if defined(IPv6) && defined(AF_INET6) + struct sockaddr_storage from; +#else struct sockaddr_in from; - int fromlen = sizeof(struct sockaddr_in); +#endif + int fromlen = sizeof(from); XdmcpHeader header; /* read message off socket */ - if (!XdmcpFill (xdmcpSocket, &buffer, (XdmcpNetaddr) &from, &fromlen)) + if (!XdmcpFill (socketfd, &buffer, (XdmcpNetaddr) &from, &fromlen)) return; /* reset retransmission backoff */ @@ -786,7 +824,7 @@ receive_packet(void) switch (header.opcode) { case WILLING: - recv_willing_msg(&from, fromlen, header.length); + recv_willing_msg((struct sockaddr *) &from, fromlen, header.length); break; case UNWILLING: XdmcpFatal("Manager unwilling", &UnwillingMessage); @@ -821,6 +859,9 @@ send_packet(void) case XDM_QUERY: case XDM_BROADCAST: case XDM_INDIRECT: +#if defined(IPv6) && defined(AF_INET6) + case XDM_MULTICAST: +#endif send_query_msg(); break; case XDM_START_CONNECTION: @@ -873,13 +914,34 @@ timeout(void) } else if (timeOutRtx >= XDM_RTX_LIMIT) { - ErrorF("XDM: too many retransmissions\n"); - state = XDM_AWAIT_USER_INPUT; - timeOutTime = 0; - timeOutRtx = 0; + /* Quit if "-once" specified, otherwise reset and try again. */ + if (OneSession) { + dispatchException |= DE_TERMINATE; + ErrorF("XDM: too many retransmissions\n"); + } else { + XdmcpDeadSession("too many retransmissions"); + } return; } +#if defined(IPv6) && defined(AF_INET6) + if (state == XDM_COLLECT_QUERY || state == XDM_COLLECT_INDIRECT_QUERY) { + /* Try next address */ + for (mgrAddr = mgrAddr->ai_next; ; mgrAddr = mgrAddr->ai_next) { + if (mgrAddr == NULL) { + mgrAddr = mgrAddrFirst; + } + if (mgrAddr->ai_family == AF_INET + || mgrAddr->ai_family == AF_INET6) + break; + } +#ifndef SIN6_LEN + ManagerAddressLen = mgrAddr->ai_addrlen; +#endif + memcpy(&ManagerAddress, mgrAddr->ai_addr, mgrAddr->ai_addrlen); + } +#endif + switch (state) { case XDM_COLLECT_QUERY: state = XDM_QUERY; @@ -887,6 +949,11 @@ timeout(void) case XDM_COLLECT_BROADCAST_QUERY: state = XDM_BROADCAST; break; +#if defined(IPv6) && defined(AF_INET6) + case XDM_COLLECT_MULTICAST_QUERY: + state = XDM_MULTICAST; + break; +#endif case XDM_COLLECT_INDIRECT_QUERY: state = XDM_INDIRECT; break; @@ -988,6 +1055,10 @@ get_xdmcp_sock(void) #else int soopts = 1; +#if defined(IPv6) && defined(AF_INET6) + if ((xdmcpSocket6 = socket(AF_INET6, SOCK_DGRAM, 0)) < 0) + XdmcpWarning("INET6 UDP socket creation failed"); +#endif if ((xdmcpSocket = socket(AF_INET, SOCK_DGRAM, 0)) < 0) XdmcpWarning("UDP socket creation failed"); #ifdef SO_BROADCAST @@ -996,8 +1067,8 @@ get_xdmcp_sock(void) XdmcpWarning("UDP set broadcast socket-option failed"); #endif /* SO_BROADCAST */ if (xdmcpSocket >= 0 && xdm_from != NULL) { - if (bind(xdmcpSocket, (struct sockaddr *)&FromAddress, - sizeof(FromAddress)) < 0) { + if (bind(xdmcpSocket, (struct sockaddr *)&FromAddress, + FromAddressLen) < 0) { ErrorF("Xserver: failed to bind to -from address: %s\n", xdm_from); exit(1); } @@ -1010,7 +1081,11 @@ send_query_msg(void) { XdmcpHeader header; Bool broadcast = FALSE; +#if defined(IPv6) && defined(AF_INET6) + Bool multicast = FALSE; +#endif int i; + int socketfd = xdmcpSocket; header.version = XDM_PROTOCOL_VERSION; switch(state){ @@ -1023,6 +1098,13 @@ send_query_msg(void) state = XDM_COLLECT_BROADCAST_QUERY; broadcast = TRUE; break; +#if defined(IPv6) && defined(AF_INET6) + case XDM_MULTICAST: + header.opcode = (CARD16) BROADCAST_QUERY; + state = XDM_COLLECT_MULTICAST_QUERY; + multicast = TRUE; + break; +#endif case XDM_INDIRECT: header.opcode = (CARD16) INDIRECT_QUERY; state = XDM_COLLECT_INDIRECT_QUERY; @@ -1044,16 +1126,48 @@ send_query_msg(void) XdmcpFlush (xdmcpSocket, &buffer, (XdmcpNetaddr) &BroadcastAddresses[i], sizeof (struct sockaddr_in)); } +#if defined(IPv6) && defined(AF_INET6) + else if (multicast) + { + struct multicastinfo *mcl; + struct addrinfo *ai; + + for (mcl = mcastlist; mcl != NULL; mcl = mcl->next) { + for (ai = mcl->ai ; ai != NULL; ai = ai->ai_next) { + if (ai->ai_family == AF_INET) { + unsigned char hopflag = (unsigned char) mcl->hops; + socketfd = xdmcpSocket; + setsockopt(socketfd, IPPROTO_IP, IP_MULTICAST_TTL, + &hopflag, sizeof(hopflag)); + } else if (ai->ai_family == AF_INET6) { + int hopflag6 = mcl->hops; + socketfd = xdmcpSocket6; + setsockopt(socketfd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, + &hopflag6, sizeof(hopflag6)); + } else { + continue; + } + XdmcpFlush (socketfd, &buffer, + (XdmcpNetaddr) ai->ai_addr, ai->ai_addrlen); + break; + } + } + } +#endif else { - XdmcpFlush (xdmcpSocket, &buffer, (XdmcpNetaddr) &ManagerAddress, +#if defined(IPv6) && defined(AF_INET6) + if (SOCKADDR_FAMILY(ManagerAddress) == AF_INET6) + socketfd = xdmcpSocket6; +#endif + XdmcpFlush (socketfd, &buffer, (XdmcpNetaddr) &ManagerAddress, sizeof (ManagerAddress)); } } static void recv_willing_msg( - struct sockaddr_in *from, + struct sockaddr *from, int fromlen, unsigned length) { @@ -1077,6 +1191,9 @@ recv_willing_msg( XdmcpSelectHost(from, fromlen, &authenticationName); break; case XDM_COLLECT_BROADCAST_QUERY: +#if defined(IPv6) && defined(AF_INET6) + case XDM_COLLECT_MULTICAST_QUERY: +#endif case XDM_COLLECT_INDIRECT_QUERY: XdmcpAddHost(from, fromlen, &authenticationName, &hostname, &status); break; @@ -1097,6 +1214,7 @@ send_request_msg(void) int length; int i; ARRAY8 authenticationData; + int socketfd = xdmcpSocket; header.version = XDM_PROTOCOL_VERSION; header.opcode = (CARD16) REQUEST; @@ -1136,7 +1254,12 @@ send_request_msg(void) XdmcpDisposeARRAY8 (&authenticationData); XdmcpWriteARRAYofARRAY8 (&buffer, &AuthorizationNames); XdmcpWriteARRAY8 (&buffer, &ManufacturerDisplayID); - if (XdmcpFlush (xdmcpSocket, &buffer, (XdmcpNetaddr) &req_sockaddr, req_socklen)) +#if defined(IPv6) && defined(AF_INET6) + if (SOCKADDR_FAMILY(req_sockaddr) == AF_INET6) + socketfd = xdmcpSocket6; +#endif + if (XdmcpFlush (socketfd, &buffer, + (XdmcpNetaddr) &req_sockaddr, req_socklen)) state = XDM_AWAIT_REQUEST_RESPONSE; } @@ -1220,6 +1343,7 @@ static void send_manage_msg(void) { XdmcpHeader header; + int socketfd = xdmcpSocket; header.version = XDM_PROTOCOL_VERSION; header.opcode = (CARD16) MANAGE; @@ -1231,7 +1355,11 @@ send_manage_msg(void) XdmcpWriteCARD16 (&buffer, DisplayNumber); XdmcpWriteARRAY8 (&buffer, &DisplayClass); state = XDM_AWAIT_MANAGE_RESPONSE; - XdmcpFlush (xdmcpSocket, &buffer, (XdmcpNetaddr) &req_sockaddr, req_socklen); +#if defined(IPv6) && defined(AF_INET6) + if (SOCKADDR_FAMILY(req_sockaddr) == AF_INET6) + socketfd = xdmcpSocket6; +#endif + XdmcpFlush (socketfd, &buffer, (XdmcpNetaddr) &req_sockaddr, req_socklen); } static void @@ -1278,6 +1406,7 @@ static void send_keepalive_msg(void) { XdmcpHeader header; + int socketfd = xdmcpSocket; header.version = XDM_PROTOCOL_VERSION; header.opcode = (CARD16) KEEPALIVE; @@ -1288,7 +1417,11 @@ send_keepalive_msg(void) XdmcpWriteCARD32 (&buffer, SessionID); state = XDM_AWAIT_ALIVE_RESPONSE; - XdmcpFlush (xdmcpSocket, &buffer, (XdmcpNetaddr) &req_sockaddr, req_socklen); +#if defined(IPv6) && defined(AF_INET6) + if (SOCKADDR_FAMILY(req_sockaddr) == AF_INET6) + socketfd = xdmcpSocket6; +#endif + XdmcpFlush (socketfd, &buffer, (XdmcpNetaddr) &req_sockaddr, req_socklen); } static void @@ -1340,80 +1473,206 @@ XdmcpWarning(char *str) } static void -get_manager_by_name( - int argc, - char **argv, - int i) +get_addr_by_name( + char * argtype, + char * namestr, + int port, + int socktype, + SOCKADDR_TYPE *addr, + SOCKLEN_TYPE *addrlen +#if defined(IPv6) && defined(AF_INET6) + , + struct addrinfo **aip, + struct addrinfo **aifirstp +#endif + ) { +#if defined(IPv6) && defined(AF_INET6) + struct addrinfo *ai; + struct addrinfo hints; + char portstr[6]; + char *pport = portstr; + int gaierr; + + bzero(&hints, sizeof(hints)); + hints.ai_socktype = socktype; + + if (port == 0) { + pport = NULL; + } else if (port > 0 && port < 65535) { + sprintf(portstr, "%d", port); + } else { + ErrorF("Xserver: port out of range: %d\n", port); + exit(1); + } + + if (*aifirstp != NULL) { + freeaddrinfo(*aifirstp); + *aifirstp = NULL; + } + + if ((gaierr = getaddrinfo(namestr, pport, &hints, aifirstp)) == 0) { + for (ai = *aifirstp; ai != NULL; ai = ai->ai_next) { + if (ai->ai_family == AF_INET || ai->ai_family == AF_INET6) + break; + } + if ((ai == NULL) || (ai->ai_addrlen > sizeof(SOCKADDR_TYPE))) { + ErrorF ("Xserver: %s host %s not on supported network type\n", + argtype, namestr); + exit (1); + } else { + *aip = ai; + *addrlen = ai->ai_addrlen; + memcpy(addr, ai->ai_addr, ai->ai_addrlen); + } + } else { + ErrorF("Xserver: %s: %s %s\n", gai_strerror(gaierr), argtype, namestr); + exit(1); + } +#else struct hostent *hep; #ifdef XTHREADS_NEEDS_BYNAMEPARAMS _Xgethostbynameparams hparams; #endif - if (i == argc) + if (!(hep = _XGethostbyname(namestr, hparams))) { - ErrorF("Xserver: missing host name in command line\n"); - exit(1); - } - if (!(hep = _XGethostbyname(argv[i], hparams))) - { - ErrorF("Xserver: unknown host: %s\n", argv[i]); + ErrorF("Xserver: %s unknown host: %s\n", argtype, namestr); exit(1); } if (hep->h_length == sizeof (struct in_addr)) { - memmove(&ManagerAddress.sin_addr, hep->h_addr, hep->h_length); -#ifdef BSD44SOCKETS - ManagerAddress.sin_len = sizeof(ManagerAddress); -#endif - ManagerAddress.sin_family = AF_INET; - ManagerAddress.sin_port = htons (xdm_udp_port); + memmove(&addr->sin_addr, hep->h_addr, hep->h_length); + *addrlen = sizeof(struct sockaddr_in); + addr->sin_family = AF_INET; + addr->sin_port = htons (xdm_udp_port); } else { - ErrorF ("Xserver: host on strange network %s\n", argv[i]); + ErrorF ("Xserver: %s host on strange network %s\n", argtype, namestr); exit (1); } +#endif } static void -get_fromaddr_by_name( +get_manager_by_name( int argc, char **argv, int i) { - struct hostent *hep; -#ifdef XTHREADS_NEEDS_BYNAMEPARAMS - _Xgethostbynameparams hparams; -#endif - if (i == argc) + if ((i + 1) == argc) { - ErrorF("Xserver: missing -from host name in command line\n"); + ErrorF("Xserver: missing %s host name in command line\n", argv[i]); exit(1); } - if (!(hep = _XGethostbyname(argv[i], hparams))) + + get_addr_by_name(argv[i], argv[i+1], xdm_udp_port, SOCK_DGRAM, + &ManagerAddress, &ManagerAddressLen +#if defined(IPv6) && defined(AF_INET6) + , &mgrAddr, &mgrAddrFirst +#endif + ); +} + + +static void +get_fromaddr_by_name( + int argc, + char **argv, + int i) +{ +#if defined(IPv6) && defined(AF_INET6) + struct addrinfo *ai = NULL; + struct addrinfo *aifirst = NULL; +#endif + if (i == argc) { - ErrorF("Xserver: unknown host: %s\n", argv[i]); + ErrorF("Xserver: missing -from host name in command line\n"); exit(1); } - if (hep->h_length == sizeof (struct in_addr)) - { - memset(&FromAddress, 0, sizeof(FromAddress)); - memmove(&FromAddress.sin_addr, hep->h_addr, hep->h_length); -#ifdef BSD44SOCKETS - FromAddress.sin_len = sizeof(FromAddress); + get_addr_by_name("-from", argv[i], 0, 0, &FromAddress, &FromAddressLen +#if defined(IPv6) && defined(AF_INET6) + , &ai, &aifirst #endif - FromAddress.sin_family = AF_INET; - FromAddress.sin_port = 0; + ); + xdm_from = argv[i]; +} + + +#if defined(IPv6) && defined(AF_INET6) +static int +get_mcast_options(argc, argv, i) + int argc, i; + char **argv; +{ + char *address = "ff02::1"; /* Default address until IANA assigns one */ + int hopcount = 1; + struct addrinfo hints; + char portstr[6]; + int gaierr; + struct addrinfo *ai, *firstai; + + if ((i < argc) && (argv[i][0] != '-') && (argv[i][0] != '+')) { + address = argv[i++]; + if ((i < argc) && (argv[i][0] != '-') && (argv[i][0] != '+')) { + hopcount = strtol(argv[i++], NULL, 10); + if ((hopcount < 1) || (hopcount > 255)) { + ErrorF("Xserver: multicast hop count out of range: %d\n", + hopcount); + exit(1); + } + } } - else - { - ErrorF ("Xserver: -from host on strange network %s\n", argv[i]); - exit (1); + + if (xdm_udp_port > 0 && xdm_udp_port < 65535) { + sprintf(portstr, "%d", xdm_udp_port); + } else { + ErrorF("Xserver: port out of range: %d\n", xdm_udp_port); + exit(1); } - xdm_from = argv[i]; + bzero(&hints, sizeof(hints)); + hints.ai_socktype = SOCK_DGRAM; + + if ((gaierr = getaddrinfo(address, portstr, &hints, &firstai)) == 0) { + for (ai = firstai; ai != NULL; ai = ai->ai_next) { + if (((ai->ai_family == AF_INET) && + IN_MULTICAST(((struct sockaddr_in *) ai->ai_addr) + ->sin_addr.s_addr)) + || ((ai->ai_family == AF_INET6) && + IN6_IS_ADDR_MULTICAST(&((struct sockaddr_in6 *) ai->ai_addr) + ->sin6_addr))) + break; + } + if (ai == NULL) { + ErrorF ("Xserver: address not supported multicast type %s\n", + address); + exit (1); + } else { + struct multicastinfo *mcastinfo, *mcl; + + mcastinfo = malloc(sizeof(struct multicastinfo)); + mcastinfo->next = NULL; + mcastinfo->ai = firstai; + mcastinfo->hops = hopcount; + + if (mcastlist == NULL) { + mcastlist = mcastinfo; + } else { + for (mcl = mcastlist; mcl->next != NULL; mcl = mcl->next) { + /* Do nothing - just find end of list */ + } + mcl->next = mcastinfo; + } + } + } else { + ErrorF("Xserver: %s: %s\n", gai_strerror(gaierr), address); + exit(1); + } + return i; } +#endif #else static int xdmcp_non_empty; /* avoid complaint by ranlib */ |