diff options
Diffstat (limited to 'xorg-server/os/xdmcp.c')
-rw-r--r-- | xorg-server/os/xdmcp.c | 142 |
1 files changed, 120 insertions, 22 deletions
diff --git a/xorg-server/os/xdmcp.c b/xorg-server/os/xdmcp.c index 99616d94b..bc7dcb3df 100644 --- a/xorg-server/os/xdmcp.c +++ b/xorg-server/os/xdmcp.c @@ -62,6 +62,8 @@ static const char *defaultDisplayClass = COMPILEDDISPLAYCLASS; +extern void match_interface(u_long u_lQuery); + static int xdmcpSocket, sessionSocket; static xdmcp_states state; @@ -200,6 +202,11 @@ static void XdmcpWakeupHandler(void *data, int i, void *LastSelectMask); +#define XSERV_t +#define TRANS_SERVER +#define TRANS_REOPEN +#include <X11/Xtrans/Xtrans.h> + /* * Register the Manufacturer display ID */ @@ -584,6 +591,32 @@ XdmcpInit(void) (void *) 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(); } @@ -654,8 +687,8 @@ XdmcpBlockHandler(void *data, /* unused */ if (timeOutTime == 0) return; millisToGo = timeOutTime - GetTimeInMillis(); - if ((int) millisToGo < 0) - millisToGo = 0; + if ((int) millisToGo <= 0) + millisToGo = 1; AdjustWaitForDelay(wt, millisToGo); } @@ -692,16 +725,6 @@ XdmcpWakeupHandler(void *data, /* unused */ 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(); } } @@ -727,12 +750,71 @@ XdmcpSelectHost(const struct sockaddr *host_sockaddr, * 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(const struct sockaddr *from, int fromlen, ARRAY8Ptr auth_name, ARRAY8Ptr hostname, ARRAY8Ptr status) { - XdmcpSelectHost(from, fromlen, auth_name); +#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=auth_name->length; + g_Hosts[HostIdx].AuthenticationName.data=realloc(g_Hosts[HostIdx].AuthenticationName.data,auth_name->length); + memcpy(g_Hosts[HostIdx].AuthenticationName.data,auth_name->data,auth_name->length); +#else + XdmcpSelectHost(from, fromlen, auth_name); +#endif } /* @@ -1004,12 +1086,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 */ } @@ -1071,18 +1161,18 @@ 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; @@ -1436,6 +1526,10 @@ get_addr_by_name(const char *argtype, char *pport = portstr; int gaierr; +#if defined(WIN32) && defined(TCPCONN) + _XSERVTransWSAStartup(); +#endif + memset(&hints, 0, sizeof(hints)); hints.ai_socktype = socktype; @@ -1479,9 +1573,6 @@ get_addr_by_name(const char *argtype, #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); } @@ -1502,7 +1593,11 @@ static void get_manager_by_name(int argc, char **argv, 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]); } @@ -1512,6 +1607,9 @@ get_manager_by_name(int argc, char **argv, int i) , &mgrAddr, &mgrAddrFirst #endif ); + queryAddr = (PSOCKADDR_IN)&ManagerAddress; + u_lqueryAddr = queryAddr->sin_addr.S_un.S_addr; + match_interface(u_lqueryAddr); } static void |