示例#1
0
static void send_alive(struct sockaddr *from, int fromlen, int length, int fd)
{
    CARD32 sessionID;
    CARD16 displayNumber;
    struct display *d;
    XdmcpHeader header;
    CARD8 sendRunning;
    CARD32 sendSessionID;

    Debug("send <alive>\n");
    if(XdmcpReadCARD16(&buffer, &displayNumber) && XdmcpReadCARD32(&buffer, &sessionID))
    {
        if(length == 6)
        {
            if(!(d = FindDisplayBySessionID(sessionID)))
                d = FindDisplayByAddress((XdmcpNetaddr)from, fromlen, displayNumber);
            sendRunning = 0;
            sendSessionID = 0;
            if(d && d->status == running)
            {
                if(d->sessionID == sessionID)
                    sendRunning = 1;
                sendSessionID = d->sessionID;
            }
            header.version = XDM_PROTOCOL_VERSION;
            header.opcode = (CARD16)ALIVE;
            header.length = 5;
            Debug("<alive>: %d %ld\n", sendRunning, (long)sendSessionID);
            XdmcpWriteHeader(&buffer, &header);
            XdmcpWriteCARD8(&buffer, sendRunning);
            XdmcpWriteCARD32(&buffer, sendSessionID);
            XdmcpFlush(fd, &buffer, (XdmcpNetaddr)from, fromlen);
        }
    }
}
示例#2
0
static void send_refuse(struct sockaddr *from, int fromlen, CARD32 sessionID, int fd)
{
    XdmcpHeader header;

    Debug("send <refuse> %ld\n", (long)sessionID);
    header.version = XDM_PROTOCOL_VERSION;
    header.opcode = (CARD16)REFUSE;
    header.length = 4;
    XdmcpWriteHeader(&buffer, &header);
    XdmcpWriteCARD32(&buffer, sessionID);
    XdmcpFlush(fd, &buffer, (XdmcpNetaddr)from, fromlen);
}
示例#3
0
static void send_unwilling(struct sockaddr *from, int fromlen, ARRAY8Ptr authenticationName, ARRAY8Ptr status, int fd)
{
    XdmcpHeader header;

    Debug("send <unwilling> %.*s %.*s\n", authenticationName->length, authenticationName->data, status->length, status->data);
    header.version = XDM_PROTOCOL_VERSION;
    header.opcode = (CARD16)UNWILLING;
    header.length = 4 + Hostname.length + status->length;
    XdmcpWriteHeader(&buffer, &header);
    XdmcpWriteARRAY8(&buffer, &Hostname);
    XdmcpWriteARRAY8(&buffer, status);
    XdmcpFlush(fd, &buffer, (XdmcpNetaddr)from, fromlen);
}
示例#4
0
static void indirect_respond(struct sockaddr *from, int fromlen, int length, int fd)
{
    ARRAYofARRAY8 queryAuthenticationNames;
    ARRAY8 clientAddress;
    ARRAY8 clientPort;
    CARD16 connectionType;
    int expectedLen;
    int i;
    XdmcpHeader header;
    int localHostAsWell;

    Debug("<indirect> respond %d\n", length);
    if(!XdmcpReadARRAYofARRAY8(&buffer, &queryAuthenticationNames))
        return;
    expectedLen = 1;
    for(i = 0; i < (int)queryAuthenticationNames.length; i++)
        expectedLen += 2 + queryAuthenticationNames.data[i].length;
    if(length == expectedLen)
    {
        ClientAddress(from, &clientAddress, &clientPort, &connectionType);
        /*
         * set up the forward query packet
         */
        header.version = XDM_PROTOCOL_VERSION;
        header.opcode = (CARD16)FORWARD_QUERY;
        header.length = 0;
        header.length += 2 + clientAddress.length;
        header.length += 2 + clientPort.length;
        header.length += 1;
        for(i = 0; i < (int)queryAuthenticationNames.length; i++)
            header.length += 2 + queryAuthenticationNames.data[i].length;
        XdmcpWriteHeader(&buffer, &header);
        XdmcpWriteARRAY8(&buffer, &clientAddress);
        XdmcpWriteARRAY8(&buffer, &clientPort);
        XdmcpWriteARRAYofARRAY8(&buffer, &queryAuthenticationNames);

        localHostAsWell = ForEachMatchingIndirectHost(&clientAddress, connectionType, sendForward, (char *)fd);

        XdmcpDisposeARRAY8(&clientAddress);
        XdmcpDisposeARRAY8(&clientPort);
        if(localHostAsWell)
            all_query_respond(from, fromlen, &queryAuthenticationNames, INDIRECT_QUERY, fd);
    }
    else
        Debug("<indirect> length error got %d expect %d\n", length, expectedLen);
    XdmcpDisposeARRAYofARRAY8(&queryAuthenticationNames);
}
示例#5
0
static void send_decline(struct sockaddr *to, int tolen, ARRAY8Ptr authenticationName, ARRAY8Ptr authenticationData, ARRAY8Ptr status, int fd)
{
    XdmcpHeader header;

    Debug("<decline> %.*s\n", status->length, status->data);
    header.version = XDM_PROTOCOL_VERSION;
    header.opcode = (CARD16)DECLINE;
    header.length = 0;
    header.length += 2 + status->length;
    header.length += 2 + authenticationName->length;
    header.length += 2 + authenticationData->length;
    XdmcpWriteHeader(&buffer, &header);
    XdmcpWriteARRAY8(&buffer, status);
    XdmcpWriteARRAY8(&buffer, authenticationName);
    XdmcpWriteARRAY8(&buffer, authenticationData);
    XdmcpFlush(fd, &buffer, (XdmcpNetaddr)to, tolen);
}
示例#6
0
static void send_failed(struct sockaddr *from, int fromlen, const char *name, CARD32 sessionID, const char *reason, int fd)
{
    char buf[360];
    XdmcpHeader header;
    ARRAY8 status;

    sprintf(buf, "Session %ld failed for display %.260s: %s", (long)sessionID, name, reason);
    Debug("send_failed(%\"s)\n", buf);
    status.length = strlen(buf);
    status.data = (CARD8Ptr)buf;
    header.version = XDM_PROTOCOL_VERSION;
    header.opcode = (CARD16)FAILED;
    header.length = 6 + status.length;
    XdmcpWriteHeader(&buffer, &header);
    XdmcpWriteCARD32(&buffer, sessionID);
    XdmcpWriteARRAY8(&buffer, &status);
    XdmcpFlush(fd, &buffer, (XdmcpNetaddr)from, fromlen);
}
示例#7
0
文件: xdmcp.c 项目: halfline/xserver
static void
send_keepalive_msg(void)
{
    XdmcpHeader header;
    int socketfd = xdmcpSocket;

    header.version = XDM_PROTOCOL_VERSION;
    header.opcode = (CARD16) KEEPALIVE;
    header.length = 6;

    XdmcpWriteHeader(&buffer, &header);
    XdmcpWriteCARD16(&buffer, DisplayNumber);
    XdmcpWriteCARD32(&buffer, SessionID);

    state = XDM_AWAIT_ALIVE_RESPONSE;
#if defined(IPv6) && defined(AF_INET6)
    if (SOCKADDR_FAMILY(req_sockaddr) == AF_INET6)
        socketfd = xdmcpSocket6;
#endif
    XdmcpFlush(socketfd, &buffer, (XdmcpNetaddr) &req_sockaddr, req_socklen);
}
示例#8
0
static void send_accept(struct sockaddr *to, int tolen, CARD32 sessionID, ARRAY8Ptr authenticationName, ARRAY8Ptr authenticationData,
                        ARRAY8Ptr authorizationName, ARRAY8Ptr authorizationData, int fd)
{
    XdmcpHeader header;

    Debug("<accept> session ID %ld\n", (long)sessionID);
    header.version = XDM_PROTOCOL_VERSION;
    header.opcode = (CARD16)ACCEPT;
    header.length = 4; /* session ID */
    header.length += 2 + authenticationName->length;
    header.length += 2 + authenticationData->length;
    header.length += 2 + authorizationName->length;
    header.length += 2 + authorizationData->length;
    XdmcpWriteHeader(&buffer, &header);
    XdmcpWriteCARD32(&buffer, sessionID);
    XdmcpWriteARRAY8(&buffer, authenticationName);
    XdmcpWriteARRAY8(&buffer, authenticationData);
    XdmcpWriteARRAY8(&buffer, authorizationName);
    XdmcpWriteARRAY8(&buffer, authorizationData);
    XdmcpFlush(fd, &buffer, (XdmcpNetaddr)to, tolen);
}
示例#9
0
文件: xdmcp.c 项目: halfline/xserver
static void
send_manage_msg(void)
{
    XdmcpHeader header;
    int socketfd = xdmcpSocket;

    header.version = XDM_PROTOCOL_VERSION;
    header.opcode = (CARD16) MANAGE;
    header.length = 8 + DisplayClass.length;

    if (!XdmcpWriteHeader(&buffer, &header))
        return;
    XdmcpWriteCARD32(&buffer, SessionID);
    XdmcpWriteCARD16(&buffer, DisplayNumber);
    XdmcpWriteARRAY8(&buffer, &DisplayClass);
    state = XDM_AWAIT_MANAGE_RESPONSE;
#if defined(IPv6) && defined(AF_INET6)
    if (SOCKADDR_FAMILY(req_sockaddr) == AF_INET6)
        socketfd = xdmcpSocket6;
#endif
    XdmcpFlush(socketfd, &buffer, (XdmcpNetaddr) &req_sockaddr, req_socklen);
}
示例#10
0
文件: xdmcp.c 项目: halfline/xserver
static void
send_request_msg(void)
{
    XdmcpHeader header;
    int length;
    int i;
    CARD16 XdmcpConnectionType;
    ARRAY8 authenticationData;
    int socketfd = xdmcpSocket;

    switch (SOCKADDR_FAMILY(ManagerAddress)) {
    case AF_INET:
        XdmcpConnectionType = FamilyInternet;
        break;
#if defined(IPv6) && defined(AF_INET6)
    case AF_INET6:
        XdmcpConnectionType = FamilyInternet6;
        break;
#endif
    default:
        XdmcpConnectionType = 0xffff;
        break;
    }

    header.version = XDM_PROTOCOL_VERSION;
    header.opcode = (CARD16) REQUEST;

    length = 2;                 /* display number */
    length += 1 + 2 * ConnectionTypes.length;   /* connection types */
    length += 1;                /* connection addresses */
    for (i = 0; i < ConnectionAddresses.length; i++)
        length += 2 + ConnectionAddresses.data[i].length;
    authenticationData.length = 0;
    authenticationData.data = 0;
    if (AuthenticationFuncs) {
        (*AuthenticationFuncs->Generator) (AuthenticationData,
                                           &authenticationData, REQUEST);
    }
    length += 2 + AuthenticationName->length;   /* authentication name */
    length += 2 + authenticationData.length;    /* authentication data */
    length += 1;                /* authorization names */
    for (i = 0; i < AuthorizationNames.length; i++)
        length += 2 + AuthorizationNames.data[i].length;
    length += 2 + ManufacturerDisplayID.length; /* display ID */
    header.length = length;

    if (!XdmcpWriteHeader(&buffer, &header)) {
        XdmcpDisposeARRAY8(&authenticationData);
        return;
    }
    XdmcpWriteCARD16(&buffer, DisplayNumber);
    XdmcpWriteCARD8(&buffer, ConnectionTypes.length);

    /* The connection array is send reordered, so that connections of   */
    /* the same address type as the XDMCP manager connection are send   */
    /* first. This works around a bug in xdm. [email protected]          */
    for (i = 0; i < (int) ConnectionTypes.length; i++)
        if (ConnectionTypes.data[i] == XdmcpConnectionType)
            XdmcpWriteCARD16(&buffer, ConnectionTypes.data[i]);
    for (i = 0; i < (int) ConnectionTypes.length; i++)
        if (ConnectionTypes.data[i] != XdmcpConnectionType)
            XdmcpWriteCARD16(&buffer, ConnectionTypes.data[i]);

    XdmcpWriteCARD8(&buffer, ConnectionAddresses.length);
    for (i = 0; i < (int) ConnectionAddresses.length; i++)
        if ((i < ConnectionTypes.length) &&
            (ConnectionTypes.data[i] == XdmcpConnectionType))
            XdmcpWriteARRAY8(&buffer, &ConnectionAddresses.data[i]);
    for (i = 0; i < (int) ConnectionAddresses.length; i++)
        if ((i >= ConnectionTypes.length) ||
            (ConnectionTypes.data[i] != XdmcpConnectionType))
            XdmcpWriteARRAY8(&buffer, &ConnectionAddresses.data[i]);

    XdmcpWriteARRAY8(&buffer, AuthenticationName);
    XdmcpWriteARRAY8(&buffer, &authenticationData);
    XdmcpDisposeARRAY8(&authenticationData);
    XdmcpWriteARRAYofARRAY8(&buffer, &AuthorizationNames);
    XdmcpWriteARRAY8(&buffer, &ManufacturerDisplayID);
#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;
}
示例#11
0
文件: xdmcp.c 项目: halfline/xserver
static void
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) {
    case XDM_QUERY:
        header.opcode = (CARD16) QUERY;
        state = XDM_COLLECT_QUERY;
        break;
    case XDM_BROADCAST:
        header.opcode = (CARD16) BROADCAST_QUERY;
        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;
        break;
    default:
        break;
    }
    header.length = 1;
    for (i = 0; i < AuthenticationNames.length; i++)
        header.length += 2 + AuthenticationNames.data[i].length;

    XdmcpWriteHeader(&buffer, &header);
    XdmcpWriteARRAYofARRAY8(&buffer, &AuthenticationNames);
    if (broadcast) {
        for (i = 0; i < NumBroadcastAddresses; i++)
            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 {
#if defined(IPv6) && defined(AF_INET6)
        if (SOCKADDR_FAMILY(ManagerAddress) == AF_INET6)
            socketfd = xdmcpSocket6;
#endif
        XdmcpFlush(socketfd, &buffer, (XdmcpNetaddr) &ManagerAddress,
                   ManagerAddressLen);
    }
}