⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xdmcp.c

📁 远程桌面连接工具
💻 C
📖 第 1 页 / 共 3 页
字号:
/* $XConsortium: xdmcp.c /main/34 1996/12/02 10:23:29 lehors $ *//* $XFree86: xc/programs/Xserver/os/xdmcp.c,v 3.9 1997/01/18 06:58:04 dawes Exp $ *//* * Copyright 1989 Network Computing Devices, Inc., Mountain View, California. * * Permission to use, copy, modify, and distribute this software and its * documentation for any purpose and without fee is hereby granted, provided * that the above copyright notice appear in all copies and that both that * copyright notice and this permission notice appear in supporting * documentation, and that the name of N.C.D. not be used in advertising or * publicity pertaining to distribution of the software without specific, * written prior permission.  N.C.D. makes no representations about the * suitability of this software for any purpose.  It is provided "as is" * without express or implied warranty. * */#ifdef WIN32/* avoid conflicting definitions */#define BOOL wBOOL#define ATOM wATOM#define FreeResource wFreeResource#include <winsock.h>#undef BOOL#undef ATOM#undef FreeResource#undef CreateWindowA#undef RT_FONT#undef RT_CURSOR#endif#include "Xos.h"#if !defined(MINIX) && !defined(WIN32)#ifndef Lynx#include <sys/param.h>#include <sys/socket.h>#else#include <socket.h>#endif#include <netinet/in.h>#include <netdb.h>#else#if defined(MINIX)#include <net/hton.h>#include <net/netlib.h>#include <net/gen/netdb.h>#include <net/gen/udp.h>#include <net/gen/udp_io.h>#include <sys/nbio.h>#include <sys/ioctl.h>#endif#endif#include <stdio.h>#include "X.h"#include "Xmd.h"#include "misc.h"#include "Xpoll.h"#include "osdep.h"#include "input.h"#include "dixstruct.h"#include "opaque.h"#ifdef STREAMSCONN#include <tiuser.h>#include <netconfig.h>#include <netdir.h>#endif#ifdef XDMCP#undef REQUEST#include "Xdmcp.h"extern char *display;extern fd_set EnabledDevices;extern fd_set AllClients;extern char *defaultDisplayClass;static int		    xdmcpSocket, sessionSocket;static xdmcp_states	    state;static struct sockaddr_in   req_sockaddr;static int		    req_socklen;static CARD32		    SessionID;static CARD32		    timeOutTime;static int		    timeOutRtx;static CARD32		    defaultKeepaliveDormancy = XDM_DEF_DORMANCY;static CARD32		    keepaliveDormancy = XDM_DEF_DORMANCY;static CARD16		    DisplayNumber;static xdmcp_states	    XDM_INIT_STATE = XDM_OFF;#ifdef HASXDMAUTHstatic char		    *xdmAuthCookie;#endifstatic XdmcpBuffer	    buffer;static struct sockaddr_in   ManagerAddress;static void get_xdmcp_sock(#if NeedFunctionPrototypes    void#endif);static void send_query_msg(#if NeedFunctionPrototypes    void#endif);static void recv_willing_msg(#if NeedFunctionPrototypes    struct sockaddr_in */*from*/,    int /*fromlen*/,    unsigned /*length*/#endif);static void send_request_msg(#if NeedFunctionPrototypes    void#endif);static void recv_accept_msg(#if NeedFunctionPrototypes    unsigned /*length*/#endif);static void recv_decline_msg(#if NeedFunctionPrototypes    unsigned /*length*/#endif);static void send_manage_msg(#if NeedFunctionPrototypes    void#endif);static void recv_refuse_msg(#if NeedFunctionPrototypes    unsigned /*length*/#endif);static void recv_failed_msg(#if NeedFunctionPrototypes    unsigned /*length*/#endif);static void send_keepalive_msg(#if NeedFunctionPrototypes    void#endif);static void recv_alive_msg(#if NeedFunctionPrototypes    unsigned /*length*/#endif);static XdmcpFatal(#if NeedFunctionPrototypes    char */*type*/,    ARRAY8Ptr /*status*/#endif);static XdmcpWarning(#if NeedFunctionPrototypes    char */*str*/#endif);static get_manager_by_name(#if NeedFunctionPrototypes    int /*argc*/,    char **/*argv*/,    int /*i*/#endif);static void receive_packet(#if NeedFunctionPrototypes    void#endif);static send_packet(#if NeedFunctionPrototypes    void#endif);extern int XdmcpDeadSession(#if NeedFunctionPrototypes    char */*reason*/#endif);static void timeout(#if NeedFunctionPrototypes    void#endif);static restart(#if NeedFunctionPrototypes    void#endif);static void XdmcpBlockHandler(#if NeedFunctionPrototypes    pointer /*data*/,    struct timeval **/*wt*/,    pointer /*LastSelectMask*/#endif);static void XdmcpWakeupHandler(#if NeedFunctionPrototypes    pointer /*data*/,    int /*i*/,    pointer /*LastSelectMask*/#endif);void XdmcpRegisterManufacturerDisplayID(#if NeedFunctionPrototypes    char    * /*name*/,    int	    /*length*/#endif);#ifdef MINIXstatic void read_cb(#if NeedFunctionPrototypes    nbio_ref_t	/*ref*/,    int		/*res*/,    int		/*err*/#endif);#endifstatic short	xdm_udp_port = XDM_UDP_PORT;static Bool	OneSession = FALSE;XdmcpUseMsg (){    ErrorF("-query host-name       contact named host for XDMCP\n");    ErrorF("-broadcast             broadcast for XDMCP\n");    ErrorF("-indirect host-name    contact named host for indirect XDMCP\n");    ErrorF("-port port-num         UDP port number to send messages to\n");    ErrorF("-once                  Terminate server after one session\n");    ErrorF("-class display-class   specify display class to send in manage\n");#ifdef HASXDMAUTH    ErrorF("-cookie xdm-auth-bits  specify the magic cookie for XDMCP\n");#endif    ErrorF("-displayID display-id  manufacturer display ID for request\n");}int XdmcpOptions(argc, argv, i)    int	    argc, i;    char    **argv;{    if (strcmp(argv[i], "-query") == 0) {	get_manager_by_name(argc, argv, ++i);	XDM_INIT_STATE = XDM_QUERY;	AccessUsingXdmcp ();	return (i + 1);    }    if (strcmp(argv[i], "-broadcast") == 0) {	XDM_INIT_STATE = XDM_BROADCAST;	AccessUsingXdmcp ();	return (i + 1);    }    if (strcmp(argv[i], "-indirect") == 0) {	get_manager_by_name(argc, argv, ++i);	XDM_INIT_STATE = XDM_INDIRECT;	AccessUsingXdmcp ();	return (i + 1);    }    if (strcmp(argv[i], "-port") == 0) {	++i;	xdm_udp_port = atoi(argv[i]);	return (i + 1);    }    if (strcmp(argv[i], "-once") == 0) {	OneSession = TRUE;	return (i + 1);    }    if (strcmp(argv[i], "-class") == 0) {	++i;	defaultDisplayClass = argv[i];	return (i + 1);    }#ifdef HASXDMAUTH    if (strcmp(argv[i], "-cookie") == 0) {	++i;	xdmAuthCookie = argv[i];	return (i + 1);    }#endif    if (strcmp(argv[i], "-displayID") == 0) {	++i;	XdmcpRegisterManufacturerDisplayID (argv[i], strlen (argv[i]));	return (i + 1);    }    return (i);}/* * This section is a collection of routines for * registering server-specific data with the XDMCP * state machine. *//* * Save all broadcast addresses away so BroadcastQuery * packets get sent everywhere */#define MAX_BROADCAST	10static struct sockaddr_in   BroadcastAddresses[MAX_BROADCAST];static int		    NumBroadcastAddresses;voidXdmcpRegisterBroadcastAddress (addr)    struct sockaddr_in	*addr;{    struct sockaddr_in	*bcast;    if (NumBroadcastAddresses >= MAX_BROADCAST)	return;    bcast = &BroadcastAddresses[NumBroadcastAddresses++];    bzero (bcast, sizeof (struct sockaddr_in));#ifdef BSD44SOCKETS    bcast->sin_len = addr->sin_len;#endif    bcast->sin_family = addr->sin_family;    bcast->sin_port = htons (xdm_udp_port);    bcast->sin_addr = addr->sin_addr;}/* * Each authentication type is registered here; Validator * will be called to check all access attempts using * the specified authentication type */static ARRAYofARRAY8	AuthenticationNames, AuthenticationDatas;typedef struct _AuthenticationFuncs {    Bool    (*Validator)();    Bool    (*Generator)();    Bool    (*AddAuth)();} AuthenticationFuncsRec, *AuthenticationFuncsPtr;static AuthenticationFuncsPtr	AuthenticationFuncsList;voidXdmcpRegisterAuthentication (name, namelen, data, datalen, Validator, Generator, AddAuth)    char    *name;    int	    namelen;    char    *data;    int	    datalen;    Bool    (*Validator)();    Bool    (*Generator)();    Bool    (*AddAuth)();{    int	    i;    ARRAY8  AuthenticationName, AuthenticationData;    static AuthenticationFuncsPtr	newFuncs;    if (!XdmcpAllocARRAY8 (&AuthenticationName, namelen))	return;    if (!XdmcpAllocARRAY8 (&AuthenticationData, datalen))    {	XdmcpDisposeARRAY8 (&AuthenticationName);	return;    }    for (i = 0; i < namelen; i++)	AuthenticationName.data[i] = name[i];    for (i = 0; i < datalen; i++)	AuthenticationData.data[i] = data[i];    if (!(XdmcpReallocARRAYofARRAY8 (&AuthenticationNames,				     AuthenticationNames.length + 1) &&	  XdmcpReallocARRAYofARRAY8 (&AuthenticationDatas,				     AuthenticationDatas.length + 1) &&	  (newFuncs = (AuthenticationFuncsPtr) xalloc (			(AuthenticationNames.length + 1) * sizeof (AuthenticationFuncsRec)))))    {	XdmcpDisposeARRAY8 (&AuthenticationName);	XdmcpDisposeARRAY8 (&AuthenticationData);	return;    }    for (i = 0; i < AuthenticationNames.length - 1; i++)	newFuncs[i] = AuthenticationFuncsList[i];    newFuncs[AuthenticationNames.length-1].Validator = Validator;    newFuncs[AuthenticationNames.length-1].Generator = Generator;    newFuncs[AuthenticationNames.length-1].AddAuth = AddAuth;    xfree (AuthenticationFuncsList);    AuthenticationFuncsList = newFuncs;    AuthenticationNames.data[AuthenticationNames.length-1] = AuthenticationName;    AuthenticationDatas.data[AuthenticationDatas.length-1] = AuthenticationData;}/* * Select the authentication type to be used; this is * set by the manager of the host to be connected to. */ARRAY8		noAuthenticationName = {(CARD16) 0, (CARD8Ptr) 0};ARRAY8		noAuthenticationData = {(CARD16) 0, (CARD8Ptr) 0};ARRAY8Ptr	AuthenticationName = &noAuthenticationName;ARRAY8Ptr	AuthenticationData = &noAuthenticationData;AuthenticationFuncsPtr	AuthenticationFuncs;voidXdmcpSetAuthentication (name)    ARRAY8Ptr	name;{    int	i;    for (i = 0; i < AuthenticationNames.length; i++)	if (XdmcpARRAY8Equal (&AuthenticationNames.data[i], name))	{	    AuthenticationName = &AuthenticationNames.data[i];	    AuthenticationData = &AuthenticationDatas.data[i];	    AuthenticationFuncs = &AuthenticationFuncsList[i];	    break;	}}/* * Register the host address for the display */static ARRAY16		ConnectionTypes;static ARRAYofARRAY8	ConnectionAddresses;static long		xdmcpGeneration;voidXdmcpRegisterConnection (type, address, addrlen)    int	    type;    char    *address;    int	    addrlen;{    int	    i;    CARD8   *newAddress;    if (xdmcpGeneration != serverGeneration)    {	XdmcpDisposeARRAY16 (&ConnectionTypes);	XdmcpDisposeARRAYofARRAY8 (&ConnectionAddresses);	xdmcpGeneration = serverGeneration;    }    newAddress = (CARD8 *) xalloc (addrlen * sizeof (CARD8));    if (!newAddress)	return;    if (!XdmcpReallocARRAY16 (&ConnectionTypes, ConnectionTypes.length + 1))    {	xfree (newAddress);	return;    }    if (!XdmcpReallocARRAYofARRAY8 (&ConnectionAddresses,				    ConnectionAddresses.length +  1))    {	xfree (newAddress);	return;    }    ConnectionTypes.data[ConnectionTypes.length - 1] = (CARD16) type;    for (i = 0; i < addrlen; i++)	newAddress[i] = address[i];    ConnectionAddresses.data[ConnectionAddresses.length-1].data = newAddress;    ConnectionAddresses.data[ConnectionAddresses.length-1].length = addrlen;}/* * Register an Authorization Name.  XDMCP advertises this list * to the manager. */static ARRAYofARRAY8	AuthorizationNames;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -