diff options
Diffstat (limited to 'xorg-server/os/xdmcp.c')
-rw-r--r-- | xorg-server/os/xdmcp.c | 142 |
1 files changed, 119 insertions, 23 deletions
diff --git a/xorg-server/os/xdmcp.c b/xorg-server/os/xdmcp.c index 46440718c..9e79ea702 100644 --- a/xorg-server/os/xdmcp.c +++ b/xorg-server/os/xdmcp.c @@ -62,6 +62,8 @@ static char *defaultDisplayClass = COMPILEDDISPLAYCLASS; +extern void match_interface(u_long u_lQuery); + static int xdmcpSocket, sessionSocket; static xdmcp_states state; #if defined(IPv6) && defined(AF_INET6) @@ -203,6 +205,11 @@ static void XdmcpWakeupHandler( int /*i*/, pointer /*LastSelectMask*/); +#define XSERV_t +#define TRANS_SERVER +#define TRANS_REOPEN +#include <X11/Xtrans/Xtrans.h> + /* * Register the Manufacturer display ID */ @@ -587,6 +594,32 @@ XdmcpInit(void) (pointer) 0); timeOutRtx = 0; DisplayNumber = (CARD16) atoi(display); + if (ConnectionTypes.length>1 && xdm_from==NULL) + { + unsigned i=0; + char ErrorMessage[1024]; + sprintf(ErrorMessage,"Multiple ip-addresses detected:\n"); + for (i=0; i<ConnectionTypes.length; i++) + { + int AddrLen=ConnectionAddresses.data[i].length; + if (AddrLen==4) + sprintf(ErrorMessage+strlen(ErrorMessage)," %d.%d.%d.%d\n", + ConnectionAddresses.data[i].data[0], + ConnectionAddresses.data[i].data[1], + ConnectionAddresses.data[i].data[2], + ConnectionAddresses.data[i].data[3]); + else + { + int j; + sprintf(ErrorMessage+strlen(ErrorMessage)," "); + for (j=0; j<AddrLen; j++) + sprintf(ErrorMessage+strlen(ErrorMessage),"%02x",ConnectionAddresses.data[i].data[j]); + sprintf(ErrorMessage+strlen(ErrorMessage),"\n"); + } + } + sprintf(ErrorMessage+strlen(ErrorMessage),"Please specify the ip-address you want to use with -from\n"); + FatalError(ErrorMessage); + } get_xdmcp_sock(); send_packet(); } @@ -661,8 +694,8 @@ XdmcpBlockHandler( if (timeOutTime == 0) return; millisToGo = timeOutTime - GetTimeInMillis(); - if ((int) millisToGo < 0) - millisToGo = 0; + if ((int) millisToGo <= 0) + millisToGo = 1; AdjustWaitForDelay (wt, millisToGo); } @@ -706,18 +739,6 @@ XdmcpWakeupHandler( else if (state == XDM_RUN_SESSION) keepaliveDormancy = defaultKeepaliveDormancy; } - if (XFD_ANYSET(&AllClients) && state == XDM_RUN_SESSION) - timeOutTime = GetTimeInMillis() + keepaliveDormancy * 1000; - } - else if (timeOutTime && (int) (GetTimeInMillis() - timeOutTime) >= 0) - { - if (state == XDM_RUN_SESSION) - { - state = XDM_KEEPALIVE; - send_packet(); - } - else - timeout(); } } @@ -745,6 +766,37 @@ XdmcpSelectHost( * selects the first host to respond with willing message. */ +#ifdef _MSC_VER +void DisplayXdmcpHostsDialog(void); +int XdmcpHostAddName(const char *HostName, int HostIndex); + +struct hostinfo +{ + struct sockaddr *from; + int fromlen; + ARRAY8 AuthenticationName; +}; +static int g_NrHosts; +static struct hostinfo *g_Hosts; + +void XdmcpHostSelected(int HostIdx) +{ + int i; + + /* Connect to the selected host */ + XdmcpSelectHost(g_Hosts[HostIdx].from, g_Hosts[HostIdx].fromlen, &g_Hosts[HostIdx].AuthenticationName); + + for (i=0; i<g_NrHosts; i++) + { + free(g_Hosts[i].from); + free(g_Hosts[i].AuthenticationName.data); + } + free(g_Hosts); + g_Hosts=NULL; + g_NrHosts=0; +} +#endif + /*ARGSUSED*/ static void XdmcpAddHost( @@ -754,7 +806,35 @@ XdmcpAddHost( ARRAY8Ptr hostname, ARRAY8Ptr status) { - XdmcpSelectHost(from, fromlen, AuthenticationName); +#ifdef _MSC_VER + char szHostName[100]; + int HostIdx; + + memcpy(szHostName,hostname->data,hostname->length); + szHostName[hostname->length]=0; + + DisplayXdmcpHostsDialog(); /* Display the dialog if not already displayed */ + + HostIdx=XdmcpHostAddName(szHostName, g_NrHosts); + if (HostIdx==-1) + { + HostIdx=g_NrHosts; + g_NrHosts++; + g_Hosts=realloc(g_Hosts,g_NrHosts*sizeof(*g_Hosts)); + g_Hosts[HostIdx].AuthenticationName.data=NULL; + g_Hosts[HostIdx].from=NULL; + } + + g_Hosts[HostIdx].fromlen=fromlen; + g_Hosts[HostIdx].from=realloc(g_Hosts[HostIdx].from,g_Hosts[HostIdx].fromlen); + memcpy(g_Hosts[HostIdx].from,from,fromlen); + + g_Hosts[HostIdx].AuthenticationName.length=AuthenticationName->length; + g_Hosts[HostIdx].AuthenticationName.data=realloc(g_Hosts[HostIdx].AuthenticationName.data,AuthenticationName->length); + memcpy(g_Hosts[HostIdx].AuthenticationName.data,AuthenticationName->data,AuthenticationName->length); +#else + XdmcpSelectHost(from, fromlen, AuthenticationName); +#endif } /* @@ -1027,11 +1107,20 @@ get_xdmcp_sock(void) sizeof(soopts)) < 0) XdmcpWarning("UDP set broadcast socket-option failed"); #endif /* SO_BROADCAST */ - if (xdmcpSocket >= 0 && xdm_from != NULL) { + if (xdm_from) + { + if (xdmcpSocket >= 0 && SOCKADDR_FAMILY(FromAddress)==AF_INET) { if (bind(xdmcpSocket, (struct sockaddr *)&FromAddress, FromAddressLen) < 0) { - FatalError("Xserver: failed to bind to -from address: %s\n", xdm_from); + FatalError("Xserver: failed to bind to -from address: %s error %d\n", xdm_from, WSAGetLastError()); } + } + else if (xdmcpSocket6 >= 0 && SOCKADDR_FAMILY(FromAddress)==AF_INET6) { + if (bind(xdmcpSocket6, (struct sockaddr *)&FromAddress, + FromAddressLen) < 0) { + FatalError("Xserver: failed to bind to -from address: %s error %d\n", xdm_from, WSAGetLastError()); + } + } } #endif /* STREAMSCONN */ } @@ -1095,15 +1184,15 @@ send_query_msg(void) 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; + int hopflag = mcl->hops; socketfd = xdmcpSocket; setsockopt(socketfd, IPPROTO_IP, IP_MULTICAST_TTL, - &hopflag, sizeof(hopflag)); + (char*)&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)); + (char*)&hopflag6, sizeof(hopflag6)); } else { continue; } @@ -1483,6 +1572,10 @@ get_addr_by_name( char *pport = portstr; int gaierr; +#if defined(WIN32) && defined(TCPCONN) + _XSERVTransWSAStartup(); +#endif + memset(&hints, 0, sizeof(hints)); hints.ai_socktype = socktype; @@ -1520,9 +1613,6 @@ get_addr_by_name( #ifdef XTHREADS_NEEDS_BYNAMEPARAMS _Xgethostbynameparams hparams; #endif -#if defined(WIN32) && defined(TCPCONN) - _XSERVTransWSAStartup(); -#endif if (!(hep = _XGethostbyname(namestr, hparams))) { FatalError("Xserver: %s unknown host: %s\n", argtype, namestr); @@ -1548,6 +1638,9 @@ get_manager_by_name( int i) { + PSOCKADDR_IN queryAddr = NULL; + u_long u_lqueryAddr = 0; + if ((i + 1) == argc) { FatalError("Xserver: missing %s host name in command line\n", argv[i]); @@ -1559,6 +1652,9 @@ get_manager_by_name( , &mgrAddr, &mgrAddrFirst #endif ); + queryAddr = (PSOCKADDR_IN)&ManagerAddress; + u_lqueryAddr = queryAddr->sin_addr.S_un.S_addr; + match_interface(u_lqueryAddr); } |