summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralanh <alanh>2003-09-12 11:32:26 +0000
committeralanh <alanh>2003-09-12 11:32:26 +0000
commit85280df5273b9aa87da5426497d0e91875b97fa0 (patch)
tree5d9374c0d42136bac43314eb6fbfb5ce18809517
parent9e0e5383a6f83fdc5ace5ef6b39114e2fb135883 (diff)
resolve merge conflicts
-rw-r--r--xc/programs/Xserver/Xserver.man55
-rw-r--r--xc/programs/Xserver/include/opaque.h5
-rw-r--r--xc/programs/Xserver/os/Imakefile26
-rw-r--r--xc/programs/Xserver/os/utils.c396
-rw-r--r--xc/programs/Xserver/os/xdmcp.c605
5 files changed, 687 insertions, 400 deletions
diff --git a/xc/programs/Xserver/Xserver.man b/xc/programs/Xserver/Xserver.man
index d57fde80e..972280ba0 100644
--- a/xc/programs/Xserver/Xserver.man
+++ b/xc/programs/Xserver/Xserver.man
@@ -22,7 +22,9 @@
.\" not be used in advertising or otherwise to promote the sale, use or
.\" other dealings in this Software without prior written authorization
.\" from The Open Group.
-.\" $XFree86: xc/programs/Xserver/Xserver.man,v 3.21 2002/11/19 23:18:09 dawes Exp $
+.\" $XFree86: xc/programs/Xserver/Xserver.man,v 3.29 2003/09/08 14:25:26 eich Exp $
+.\" shorthand for double quote that works everywhere.
+.ds q \N'34'
.TH XSERVER 1 __xorgversion__
.SH NAME
Xserver \- X Window System display server
@@ -60,7 +62,10 @@ Many X servers have device-specific command line options. See the manual
pages for the individual servers for more details; a list of
server-specific manual pages is provided in the SEE ALSO section below.
.PP
-All of the X servers accept the following command line options:
+All of the X servers accept the command line options described below.
+Some X servers may have alternative ways of providing the parameters
+described here, but the values provided via the command line options
+should override values specified via other mechanisms.
.TP 8
.B :\fIdisplaynumber\fP
The X server runs as the given \fIdisplaynumber\fP, which by default is 0.
@@ -118,7 +123,7 @@ Not obeyed by all servers.
.TP 8
.B \-co \fIfilename\fP
sets name of RGB color database. The default is
-\fI__projectroot__/lib/X11/rgb\fP.
+.IR __projectroot__/lib/X11/rgb .
.ig
.TP 8
.B \-config \fIfilename\fP
@@ -135,8 +140,9 @@ different from the user's real uid.
causes the server to generate a core dump on fatal errors.
.TP 8
.B \-dpi \fIresolution\fP
-sets the resolution of the screen, in dots per inch.
-To be used when the server cannot determine the screen size from the hardware.
+sets the resolution for all screens, in dots per inch.
+To be used when the server cannot determine the screen size(s) from the
+hardware.
.TP 8
.B \-deferglyphs \fIwhichfonts\fP
specifies the types of fonts for which the server should attempt to use
@@ -166,6 +172,8 @@ causes all remaining command line arguments to be ignored.
disables a transport type. For example, TCP/IP connections can be disabled
with
.BR "\-nolisten tcp" .
+This option may be issued multiple times to disable listening to different
+transport types.
.TP 8
.B \-noreset
prevents a server reset when the last client connection is closed. This
@@ -261,6 +269,25 @@ There is currently no way to change this from a client.
.B nologo
turns off the X Window System logo display in the screen-saver.
There is currently no way to change this from a client.
+.TP 8
+.B \-render
+.BR default | mono | gray | color
+sets the color allocation policy that will be used by the render extension.
+.RS 8
+.TP 8
+.I default
+selects the default policy defined for the display depth of the X
+server.
+.TP 8
+.I mono
+don't use any color cell.
+.TP 8
+.I gray
+use a gray map of 13 color cells for the X render extension.
+.TP 8
+.I color
+use a color cube of at most 4*4*4 colors (that is 64 color cells).
+.RE
.SH XDMCP OPTIONS
X servers that support XDMCP have the following options.
See the \fIX Display Manager Control Protocol\fP specification for more
@@ -273,6 +300,15 @@ enables XDMCP and sends Query packets to the specified
.B \-broadcast
enable XDMCP and broadcasts BroadcastQuery packets to the network. The
first responding display manager will be chosen for the session.
+.B \-multicast [\fIaddress\fP [\fIhop count\fP]]
+Enable XDMCP and multicast BroadcastQuery packets to the network.
+The first responding display manager is chosen for the session. If an
+address is specified, the multicast is sent to that address. If no
+address is specified, the multicast is sent to the default XDMCP IPv6
+multicast group. If a hop count is specified, it is used as the maximum
+hop count for the multicast. If no hop count is specified, the multicast
+is set to a maximum of 1 hop, to prevent the multicast from being routed
+beyond the local network.
.TP 8
.B \-indirect \fIhostname\fP
enables XDMCP and send IndirectQuery packets to the specified
@@ -307,7 +343,7 @@ data (not that it is very private, being on the command line!).
Yet another XDMCP specific value, this one allows the display manager to
identify each display so that it can locate the shared key.
.SH XKEYBOARD OPTIONS
-X servers that support the XKEYBOARD (a.k.a. \(oqXKB\(cq) extension accept the
+X servers that support the XKEYBOARD (a.k.a. \*qXKB\*q) extension accept the
following options:
.TP 8
.B [+-]kb
@@ -435,7 +471,7 @@ null-terminated strings. If any of the strings match <string/rv>, the
rule applies.
.PP
The definition of string matching is simple case-sensitive string
-comparison with one elaboration: the occurence of the character '*' in
+comparison with one elaboration: the occurrence of the character '*' in
<string/rv> is a wildcard meaning "any string." A <string/rv> can
contain multiple wildcards anywhere in the string. For example, "x*"
matches strings that begin with x, "*x" matches strings that end with
@@ -673,9 +709,6 @@ Bitmap font directories
.TP 30
.IR __projectroot__/lib/X11/fonts/Speedo , __projectroot__/lib/X11/fonts/Type1
Outline font directories
-.\" .TP 30
-.\" __projectroot__/lib/X11/fonts/PEX
-.\" PEX font directories
.TP 30
.I __projectroot__/lib/X11/rgb.txt
Color database
@@ -700,7 +733,7 @@ Protocols:
.I "X Display Manager Control Protocol"
.PP
Fonts: \fIbdftopcf\fP(1), \fImkfontdir\fP(1), \fIxfs\fP(1),
-\FIxlsfonts\fP(1), \fIxfontsel\fP(1), \fIxfd\fP(1),
+\fIxlsfonts\fP(1), \fIxfontsel\fP(1), \fIxfd\fP(1),
.I "X Logical Font Description Conventions"
.PP
Security: \fIXsecurity\fP(__miscmansuffix__), \fIxauth\fP(1), \fIXau\fP(1),
diff --git a/xc/programs/Xserver/include/opaque.h b/xc/programs/Xserver/include/opaque.h
index 1834202ae..b5a55a60b 100644
--- a/xc/programs/Xserver/include/opaque.h
+++ b/xc/programs/Xserver/include/opaque.h
@@ -26,7 +26,7 @@ other dealings in this Software without prior written authorization
from The Open Group.
*/
-/* $XFree86: xc/programs/Xserver/include/opaque.h,v 1.11 2002/10/08 23:55:22 dawes Exp $ */
+/* $XFree86: xc/programs/Xserver/include/opaque.h,v 1.14 2003/09/09 03:20:41 dawes Exp $ */
#ifndef OPAQUE_H
#define OPAQUE_H
@@ -74,9 +74,10 @@ extern int limitNoFile;
#endif
extern Bool permitOldBugs;
extern Bool defeatAccessControl;
-extern char* protNoListen;
+extern long maxBigRequestSize;
extern Bool blackRoot;
+extern Bool CoreDump;
#endif /* OPAQUE_H */
diff --git a/xc/programs/Xserver/os/Imakefile b/xc/programs/Xserver/os/Imakefile
index 8a41f5b9c..6090535ee 100644
--- a/xc/programs/Xserver/os/Imakefile
+++ b/xc/programs/Xserver/os/Imakefile
@@ -3,7 +3,7 @@ XCOMM $Xorg: Imakefile,v 1.3 2000/08/17 19:53:40 cpqbld Exp $
-XCOMM $XFree86: xc/programs/Xserver/os/Imakefile,v 3.38 2002/11/14 21:01:21 tsi Exp $
+XCOMM $XFree86: xc/programs/Xserver/os/Imakefile,v 3.40 2003/09/09 03:20:41 dawes Exp $
#include <Server.tmpl>
@@ -79,19 +79,24 @@ MALLOC_SRCS=xalloc.c
MALLOC_OBJS=xalloc.o
#endif
+#if !HasSnprintf
+SNPRINTF_SRCS = snprintf.c
+SNPRINTF_OBJS = snprintf.o
+#endif
+
#if HasGetpeereid
GETPEEREID_DEFINES = -DHAS_GETPEEREID
#endif
BOOTSTRAPCFLAGS =
SRCS = WaitFor.c access.c connection.c io.c $(COLOR_SRCS) \
- osinit.c utils.c auth.c mitauth.c secauth.c $(XDMAUTHSRCS) \
- $(RPCSRCS) $(KRB5SRCS) xdmcp.c decompress.c OtherSources \
- transport.c $(MALLOC_SRCS) $(LBX_SRCS)
+ osinit.c utils.c log.c auth.c mitauth.c secauth.c \
+ $(XDMAUTHSRCS) $(RPCSRCS) $(KRB5SRCS) xdmcp.c OtherSources \
+ transport.c $(SNPRINTF_SRCS) $(MALLOC_SRCS) $(LBX_SRCS)
OBJS = WaitFor.o access.o connection.o io.o $(COLOR_OBJS) \
- osinit.o utils.o auth.o mitauth.o secauth.o $(XDMAUTHOBJS) \
- $(RPCOBJS) $(KRB5OBJS) xdmcp.o decompress.o OtherObjects \
- transport.o $(MALLOC_OBJS) $(LBX_OBJS)
+ osinit.o utils.o log.o auth.o mitauth.o secauth.o \
+ $(XDMAUTHOBJS) $(RPCOBJS) $(KRB5OBJS) xdmcp.o OtherObjects \
+ transport.o $(SNPRINTF_OBJS) $(MALLOC_OBJS) $(LBX_OBJS)
#if SpecialMalloc
MEM_DEFINES = -DSPECIAL_MALLOC
@@ -170,12 +175,13 @@ SpecialCObjectRule(oscolor,$(ICONFIGFILES),$(DBM_DEFINES))
LinkSourceFile(k5encode.c,$(XAUTHSRC))
#endif
-#if DoLoadableServer
-AllTarget(libcwrapper.o)
-ObjectFromSpecialSource(libcwrapper,$(XF86OSSRC)/shared/libc_wrapper,-DSELF_CONTAINED_WRAPPER)
#if !HasSnprintf
LinkSourceFile(snprintf.c,$(LIBSRC)/misc)
#endif
+
+#if DoLoadableServer
+AllTarget(libcwrapper.o)
+ObjectFromSpecialSource(libcwrapper,$(XF86OSSRC)/shared/libc_wrapper,-DSELF_CONTAINED_WRAPPER)
#endif
DependTarget()
diff --git a/xc/programs/Xserver/os/utils.c b/xc/programs/Xserver/os/utils.c
index 4bbe9eb8c..ac2a21480 100644
--- a/xc/programs/Xserver/os/utils.c
+++ b/xc/programs/Xserver/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.92 2003/09/09 03:20:41 dawes 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;
@@ -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("-dumpSched 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 (hnameptr == ai->ai_canonname) {
+ 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/xc/programs/Xserver/os/xdmcp.c b/xc/programs/Xserver/os/xdmcp.c
index b6a5db35f..27ba492d7 100644
--- a/xc/programs/Xserver/os/xdmcp.c
+++ b/xc/programs/Xserver/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.26 2003/09/10 01:04:41 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"
@@ -74,7 +75,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 +95,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 +230,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 +248,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 +258,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 +277,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 +331,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 +462,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 +675,9 @@ XdmcpBlockHandler(
if (state == XDM_OFF)
return;
FD_SET(xdmcpSocket, LastSelectMask);
+#if defined(IPv6) && defined(AF_INET6)
+ FD_SET(xdmcpSocket6, LastSelectMask);
+#endif
if (timeOutTime == 0)
return;
millisToGo = timeOutTime - GetTimeInMillis();
@@ -695,9 +708,16 @@ XdmcpWakeupHandler(
{
if (FD_ISSET(xdmcpSocket, LastSelectMask))
{
- receive_packet();
+ receive_packet(xdmcpSocket);
FD_CLR(xdmcpSocket, LastSelectMask);
}
+#if defined(IPv6) && defined(AF_INET6)
+ if (FD_ISSET(xdmcpSocket6, LastSelectMask))
+ {
+ receive_packet(xdmcpSocket6);
+ FD_CLR(xdmcpSocket6, LastSelectMask);
+ }
+#endif
XFD_ANDSET(&devicesReadable, LastSelectMask, &EnabledDevices);
if (XFD_ANYSET(&devicesReadable))
{
@@ -728,10 +748,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 +776,7 @@ XdmcpSelectHost(
/*ARGSUSED*/
static void
XdmcpAddHost(
- struct sockaddr_in *from,
+ struct sockaddr *from,
int fromlen,
ARRAY8Ptr AuthenticationName,
ARRAY8Ptr hostname,
@@ -765,14 +793,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 +818,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 +853,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 +908,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 +943,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 +1049,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 +1061,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 +1075,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 +1092,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 +1120,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 +1185,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 +1208,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 +1248,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 +1337,7 @@ static void
send_manage_msg(void)
{
XdmcpHeader header;
+ int socketfd = xdmcpSocket;
header.version = XDM_PROTOCOL_VERSION;
header.opcode = (CARD16) MANAGE;
@@ -1231,7 +1349,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 +1400,7 @@ static void
send_keepalive_msg(void)
{
XdmcpHeader header;
+ int socketfd = xdmcpSocket;
header.version = XDM_PROTOCOL_VERSION;
header.opcode = (CARD16) KEEPALIVE;
@@ -1288,7 +1411,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 +1467,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)
- {
- ErrorF("Xserver: missing host name in command line\n");
- exit(1);
- }
- if (!(hep = _XGethostbyname(argv[i], hparams)))
+ if (!(hep = _XGethostbyname(namestr, 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 */