Example #1
0
enum SCP_SERVER_STATES_E
scp_v1s_deny_connection(struct SCP_CONNECTION* c, char* reason)
{
  int rlen;

  init_stream(c->out_s,c->out_s->size);

  /* forcing message not to exceed 64k */
  rlen = g_strlen(reason);
  if (rlen > 65535)
  {
    rlen = 65535;
  }

  out_uint32_be(c->out_s, 1);
  /* packet size: 4 + 4 + 2 + 2 + 2 + strlen(reason)*/
  /* version + size + cmdset + cmd + msglen + msg */
  out_uint32_be(c->out_s, rlen+14);
  out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT);
  out_uint16_be(c->out_s, 2);
  out_uint16_be(c->out_s, rlen);
  out_uint8p(c->out_s, reason, rlen);

  if (0!=scp_tcp_force_send(c->in_sck, c->out_s->data, rlen+14))
  {
    log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: network error", __LINE__);
    return SCP_SERVER_STATE_NETWORK_ERR;
  }

  return SCP_SERVER_STATE_END;
}
Example #2
0
/* 046 was: 031 struct SCP_DISCONNECTED_SESSION* ds, */
enum SCP_SERVER_STATES_E
scp_v1s_reconnect_session(struct SCP_CONNECTION* c, SCP_DISPLAY d)
{
  tui32 version = 1;
  tui32 size = 14;
  tui16 cmd = 46;

  /* ok, we send session data and display */
  init_stream(c->out_s, c->out_s->size);

  /* header */
  out_uint32_be(c->out_s, version);
  out_uint32_be(c->out_s, size);
  out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT);
  out_uint16_be(c->out_s, cmd);

  /* session data */
  out_uint16_be(c->out_s, d); /* session display */
  /*out_uint8(c->out_s, ds->type);
  out_uint16_be(c->out_s, ds->height);
  out_uint16_be(c->out_s, ds->width);
  out_uint8(c->out_s, ds->bpp);
  out_uint8(c->out_s, ds->idle_days);
  out_uint8(c->out_s, ds->idle_hours);
  out_uint8(c->out_s, ds->idle_minutes);*/
  /* these last three are not really needed... */

  if (0!=scp_tcp_force_send(c->in_sck, c->out_s->data, size))
  {
    log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: network error", __LINE__);
    return SCP_SERVER_STATE_NETWORK_ERR;
  }

  return SCP_SERVER_STATE_OK;
}
Example #3
0
/* 030 */
enum SCP_SERVER_STATES_E
scp_v1s_connect_new_session(struct SCP_CONNECTION* c, SCP_DISPLAY d)
{
  /* send password request */
  tui32 version=1;
  tui32 size=14;
  tui16 cmd=30;

  init_stream(c->out_s, c->out_s->size);

  out_uint32_be(c->out_s, version);                 /* version */
  out_uint32_be(c->out_s, size);                    /* size    */
  out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT); /* cmdset  */
  out_uint16_be(c->out_s, cmd);                     /* cmd     */

  out_uint16_be(c->out_s, d);                       /* display */

  if (0!=scp_tcp_force_send(c->in_sck, c->out_s->data, 14))
  {
    log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: network error", __LINE__);
    return SCP_SERVER_STATE_NETWORK_ERR;
  }

  return SCP_SERVER_STATE_OK;
}
Example #4
0
/* 003 */
enum SCP_SERVER_STATES_E
scp_v1s_mng_deny_connection(struct SCP_CONNECTION *c, char *reason)
{
    int rlen;

    init_stream(c->out_s, c->out_s->size);

    /* forcing message not to exceed 64k */
    rlen = g_strlen(reason);

    if (rlen > 65535)
    {
        rlen = 65535;
    }

    out_uint32_be(c->out_s, 1);
    /* packet size: 4 + 4 + 2 + 2 + 2 + strlen(reason)*/
    /* version + size + cmdset + cmd + msglen + msg */
    out_uint32_be(c->out_s, rlen + 14);
    out_uint16_be(c->out_s, SCP_COMMAND_SET_MANAGE);
    out_uint16_be(c->out_s, SCP_CMD_MNG_LOGIN_DENY);
    out_uint16_be(c->out_s, rlen);
    out_uint8p(c->out_s, reason, rlen);

    if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, rlen + 14))
    {
        return SCP_SERVER_STATE_NETWORK_ERR;
    }

    return SCP_SERVER_STATE_END;
}
Example #5
0
/* 004 */
enum SCP_CLIENT_STATES_E
scp_v1c_resend_credentials(struct SCP_CONNECTION *c, struct SCP_SESSION *s)
{
    tui8 sz;
    tui32 size;

    init_stream(c->out_s, c->out_s->size);
    init_stream(c->in_s, c->in_s->size);

    size = 12 + 2 + g_strlen(s->username) + g_strlen(s->password);

    /* sending request */
    /* header */
    out_uint32_be(c->out_s, 1); /* version */
    out_uint32_be(c->out_s, size);
    out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT);
    out_uint16_be(c->out_s, 4);

    /* body */
    sz = g_strlen(s->username);
    out_uint8(c->out_s, sz);
    out_uint8p(c->out_s, s->username, sz);
    sz = g_strlen(s->password);
    out_uint8(c->out_s, sz);
    out_uint8p(c->out_s, s->password, sz);

    if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, size))
    {
        return SCP_CLIENT_STATE_NETWORK_ERR;
    }

    /* wait for response */
    return _scp_v1c_check_response(c, s);
}
Example #6
0
static int APP_CC
rdp_iso_send_msg(struct rdp_iso *self, struct stream *s, int code)
{
    if (rdp_tcp_init(self->tcp_layer, s) != 0)
    {
        return 1;
    }

    out_uint8(s, 3);
    out_uint8(s, 0);
    out_uint16_be(s, 11); /* length */
    out_uint8(s, 6);
    out_uint8(s, code);
    out_uint16_le(s, 0);
    out_uint16_le(s, 0);
    out_uint8(s, 0);
    s_mark_end(s);

    if (rdp_tcp_send(self->tcp_layer, s) != 0)
    {
        return 1;
    }

    return 0;
}
Example #7
0
static BOOL
iso_send_connection_request(RDPCLIENT * This, char *cookie)
{
	STREAM s;
	int cookielen = (int)strlen(cookie);
	int length = 11 + cookielen;

	s = tcp_init(This, length);

	if(s == NULL)
		return False;

	out_uint8(s, 3);	/* version */
	out_uint8(s, 0);	/* reserved */
	out_uint16_be(s, length);	/* length */

	out_uint8(s, length - 5);	/* hdrlen */
	out_uint8(s, ISO_PDU_CR);
	out_uint16(s, 0);	/* dst_ref */
	out_uint16(s, 0);	/* src_ref */
	out_uint8(s, 0);	/* class */

	out_uint8p(s, cookie, cookielen);

	s_mark_end(s);
	return tcp_send(This, s);
}
Example #8
0
/* Output TPKT header for length length.
 * Length should include the TPKT header (4 bytes) */
static void
tpkt_output_header(STREAM s, int length)
{
	out_uint8(s, 3);	/* version */
	out_uint8(s, 0);	/* reserved */
	out_uint16_be(s, length);	/* length */
}
Example #9
0
File: iso.c Project: RPG-7/reactos
static void
iso_send_connection_request(char *username)
{
	STREAM s;
	int length = 30 + strlen(username);

	s = tcp_init(length);

	out_uint8(s, 3);	/* version */
	out_uint8(s, 0);	/* reserved */
	out_uint16_be(s, length);	/* length */

	out_uint8(s, length - 5);	/* hdrlen */
	out_uint8(s, ISO_PDU_CR);
	out_uint16(s, 0);	/* dst_ref */
	out_uint16(s, 0);	/* src_ref */
	out_uint8(s, 0);	/* class */

	out_uint8p(s, "Cookie: mstshash=", strlen("Cookie: mstshash="));
	out_uint8p(s, username, strlen(username));

	out_uint8(s, 0x0d);	/* Unknown */
	out_uint8(s, 0x0a);	/* Unknown */

	s_mark_end(s);
	tcp_send(s);
}
Example #10
0
/* Send an fast path data PDU */
void
iso_fp_send(rdpIso * iso, STREAM s, uint32 flags)
{
	int fp_flags;
	int len;
	int index;

	fp_flags = (1 << 2) | 0;	/* one event, fast path */
	if (flags & SEC_ENCRYPT)
	{
		fp_flags |= 2 << 6;	/* FASTPATH_INPUT_ENCRYPTED */
	}
	s_pop_layer(s, iso_hdr);
	len = (int) (s->end - s->p);
	out_uint8(s, fp_flags);
	if (len >= 128)
	{
		out_uint16_be(s, len | 0x8000);
	}
	else
	{
		/* copy the bits up to pack and save 1 byte */
		for (index = 3; index < len; index++)
		{
			s->data[index - 1] = s->data[index];
		}
		len--;
		s->end--;
		out_uint8(s, len);
	}

	tcp_send(iso->tcp, s);
}
Example #11
0
static int APP_CC
xrdp_iso_send_connection_confirm(struct xrdp_iso* self, struct stream* s)
{
  bool send_request_response = self->need_negotiation_response;
  bool client_support_network_detection = self->mcs_layer->sec_layer->rdp_layer->client_info.support_network_detection;
  int x224_len = 6;
  int tpkt_len = 11;

  if (xrdp_tcp_init(self->tcp_layer, s) != 0)
  {
    return 1;
  }

  if (send_request_response && client_support_network_detection)
  {
    x224_len += 8;
    tpkt_len += 8;
  }

  out_uint8(s, 3);             // TPKT version
  out_uint8(s, 0);             // TPKT reserved
  out_uint16_be(s, tpkt_len);  // TPKT length
  out_uint8(s, x224_len);      // X.224 length
  out_uint8(s, ISO_PDU_CC);    // X.224 type
  out_uint16_be(s, 0);         // X.224 dst
  out_uint16_be(s, 0x1234);    // X.224 src (bogus value)
  out_uint8(s, 0);             // X.224 class

  // send Negotiation Response
  if (send_request_response && client_support_network_detection)
  {
    unsigned char flags = 0;
    flags = EXTENDED_CLIENT_DATA_SUPPORTED;

    out_uint8(s, TYPE_RDP_NEG_RSP);                // type
    out_uint8(s, flags);                           // flags
    out_uint16_le(s, RDP_NEG_RSP_LEN);             // length
    out_uint32_le(s, PROTOCOL_RDP);                // protocol
  }

  s_mark_end(s);
  if (xrdp_tcp_send(self->tcp_layer, s) != 0)
  {
    return 1;
  }
  return 0;
}
Example #12
0
enum SCP_SERVER_STATES_E
scp_v0s_allow_connection(struct SCP_CONNECTION *c, SCP_DISPLAY d)
{
    out_uint32_be(c->out_s, 0);  /* version */
    out_uint32_be(c->out_s, 14); /* size */
    out_uint16_be(c->out_s, 3);  /* cmd */
    out_uint16_be(c->out_s, 1);  /* data */
    out_uint16_be(c->out_s, d);  /* data */
    s_mark_end(c->out_s);

    if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, c->out_s->end - c->out_s->data))
    {
        log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__);
        return SCP_SERVER_STATE_NETWORK_ERR;
    }

    LOG_DBG("[v0:%d] connection terminated (allowed)", __LINE__);
    return SCP_SERVER_STATE_OK;
}
Example #13
0
enum SCP_SERVER_STATES_E
scp_v0s_deny_connection(struct SCP_CONNECTION *c)
{
    out_uint32_be(c->out_s, 0);  /* version */
    out_uint32_be(c->out_s, 14); /* size */
    out_uint16_be(c->out_s, 3);  /* cmd */
    out_uint16_be(c->out_s, 0);  /* data = 0 - means NOT ok*/
    out_uint16_be(c->out_s, 0);  /* reserved for display number*/
    s_mark_end(c->out_s);

    if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, c->out_s->end - c->out_s->data))
    {
        log_message(LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__);
        return SCP_SERVER_STATE_NETWORK_ERR;
    }

    LOG_DBG("[v0:%d] connection terminated (denied)", __LINE__);
    return SCP_SERVER_STATE_OK;
}
Example #14
0
/* 002 */
enum SCP_SERVER_STATES_E
scp_v1s_mng_allow_connection(struct SCP_CONNECTION *c, struct SCP_SESSION *s)
{
    init_stream(c->out_s, c->out_s->size);

    out_uint32_be(c->out_s, 1);
    /* packet size: 4 + 4 + 2 + 2 */
    /* version + size + cmdset + cmd */
    out_uint32_be(c->out_s, 12);
    out_uint16_be(c->out_s, SCP_COMMAND_SET_MANAGE);
    out_uint16_be(c->out_s, SCP_CMD_MNG_LOGIN_ALLOW);

    if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, 12))
    {
        return SCP_SERVER_STATE_NETWORK_ERR;
    }

    return _scp_v1s_mng_check_response(c, s);
}
Example #15
0
/* Output an ASN.1 BER header */
void
ber_out_header(STREAM s, int tagval, int length)
{
	if (tagval > 0xff)
	{
		out_uint16_be(s, tagval);
	}
	else
	{
		out_uint8(s, tagval);
	}

	if (length >= 0x80)
	{
		out_uint8(s, 0x82);
		out_uint16_be(s, length);
	}
	else
		out_uint8(s, length);
}
Example #16
0
enum SCP_SERVER_STATES_E
scp_v0s_replyauthentication(struct SCP_CONNECTION *c, unsigned short int value)
{
    out_uint32_be(c->out_s, 0);  /* version */
    out_uint32_be(c->out_s, 14); /* size */
    /* cmd SCP_GW_AUTHENTICATION means authentication reply */
    out_uint16_be(c->out_s, SCP_GW_AUTHENTICATION);
    out_uint16_be(c->out_s, value);  /* reply code  */
    out_uint16_be(c->out_s, 0);  /* dummy data */
    s_mark_end(c->out_s);

    /* g_writeln("Total number of bytes that will be sent %d",c->out_s->end - c->out_s->data);*/
    if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, c->out_s->end - c->out_s->data))
    {
        /* until syslog merge log_message(s_log, LOG_LEVEL_WARNING, "[v0:%d] connection aborted: network error", __LINE__); */
        return SCP_SERVER_STATE_NETWORK_ERR;
    }

    /* until syslog merge LOG_DBG(s_log, "[v0:%d] connection terminated (scp_v0s_deny_authentication)", __LINE__);*/
    return SCP_SERVER_STATE_OK;
}
Example #17
0
/* 032 */
enum SCP_SERVER_STATES_E
scp_v1s_connection_error(struct SCP_CONNECTION* c, char* error)
{
  tui16 len;

  len = g_strlen(error);
  init_stream(c->out_s,c->out_s->size);

  out_uint32_be(c->out_s, 1);
  /* packet size: 4 + 4 + 2 + 2 + len */
  /* version + size + cmdset + cmd */
  out_uint32_be(c->out_s, (12 + len));
  out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT);
  out_uint16_be(c->out_s, SCP_CMD_CONN_ERROR);

  if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, (12 + len)))
  {
    return SCP_SERVER_STATE_NETWORK_ERR;
  }

  return SCP_SERVER_STATE_END;
}
Example #18
0
/* Send an ISO data PDU */
BOOL
iso_send(RDPCLIENT * This, STREAM s)
{
	uint16 length;

	s_pop_layer(s, iso_hdr);
	length = (uint16)(s->end - s->p);

	out_uint8(s, 3);	/* version */
	out_uint8(s, 0);	/* reserved */
	out_uint16_be(s, length);

	out_uint8(s, 2);	/* hdrlen */
	out_uint8(s, ISO_PDU_DT);	/* code */
	out_uint8(s, 0x80);	/* eot */

	return tcp_send(This, s);
}
Example #19
0
File: iso.c Project: RPG-7/reactos
/* Send an ISO data PDU */
void
iso_send(STREAM s)
{
	uint16 length;

	s_pop_layer(s, iso_hdr);
	length = s->end - s->p;

	out_uint8(s, 3);	/* version */
	out_uint8(s, 0);	/* reserved */
	out_uint16_be(s, length);

	out_uint8(s, 2);	/* hdrlen */
	out_uint8(s, ISO_PDU_DT);	/* code */
	out_uint8(s, 0x80);	/* eot */

	tcp_send(s);
}
Example #20
0
/* Send an ISO data PDU */
void
iso_send(rdpIso * iso, STREAM s)
{
	uint16 length;

	s_pop_layer(s, iso_hdr);
	length = s->end - s->p;

	out_uint8(s, 3);		/* version */
	out_uint8(s, 0);		/* reserved */
	out_uint16_be(s, length);

	out_uint8(s, 2);		/* hdrlen */
	out_uint8(s, X224_TPDU_DATA);	/* code */
	out_uint8(s, 0x80);		/* eot */

	tcp_send(iso->tcp, s);
}
Example #21
0
/* returns error */
int APP_CC
rdp_iso_send(struct rdp_iso* self, struct stream* s)
{
  int len;

  s_pop_layer(s, iso_hdr);
  len = s->end - s->p;
  out_uint8(s, 3);
  out_uint8(s, 0);
  out_uint16_be(s, len);
  out_uint8(s, 2);
  out_uint8(s, ISO_PDU_DT);
  out_uint8(s, 0x80);
  if (rdp_tcp_send(self->tcp_layer, s) != 0)
  {
    return 1;
  }
  return 0;
}
Example #22
0
File: iso.c Project: RPG-7/reactos
/* Send a self-contained ISO PDU */
static void
iso_send_msg(uint8 code)
{
	STREAM s;

	s = tcp_init(11);

	out_uint8(s, 3);	/* version */
	out_uint8(s, 0);	/* reserved */
	out_uint16_be(s, 11);	/* length */

	out_uint8(s, 6);	/* hdrlen */
	out_uint8(s, code);
	out_uint16(s, 0);	/* dst_ref */
	out_uint16(s, 0);	/* src_ref */
	out_uint8(s, 0);	/* class */

	s_mark_end(s);
	tcp_send(s);
}
Example #23
0
/* Output bitmap cache v2 capability set */
static void rdp_out_bmpcache2_caps(STREAM s) {
	out_uint16_le(s, RDP_CAPSET_BMPCACHE2);
	out_uint16_le(s, RDP_CAPLEN_BMPCACHE2);

	out_uint16_le(s, g_bitmap_cache_persist_enable ? 2 : 0);
	/* version */

	out_uint16_be(s, 3);
	/* number of caches in this set */

	/* max cell size for cache 0 is 16x16, 1 = 32x32, 2 = 64x64, etc */
	out_uint32_le(s, BMPCACHE2_C0_CELLS);
	out_uint32_le(s, BMPCACHE2_C1_CELLS);
	if (pstcache_init(2)) {
		out_uint32_le(s, BMPCACHE2_NUM_PSTCELLS | BMPCACHE2_FLAG_PERSIST);
	} else {
		out_uint32_le(s, BMPCACHE2_C2_CELLS);
	}out_uint8s(s, 20);
	/* other bitmap caches not used */
}
Example #24
0
static void
iso_send_connection_request(char *username)
{
	STREAM s;
	int length = 30 + strlen(username);

	if (g_rdp_version >= RDP_V5 && g_negotiate_rdp_protocol)
		length += 8;

	s = tcp_init(length);

	out_uint8(s, 3);	/* version */
	out_uint8(s, 0);	/* reserved */
	out_uint16_be(s, length);	/* length */

	out_uint8(s, length - 5);	/* hdrlen */
	out_uint8(s, ISO_PDU_CR);
	out_uint16(s, 0);	/* dst_ref */
	out_uint16(s, 0);	/* src_ref */
	out_uint8(s, 0);	/* class */

	out_uint8p(s, "Cookie: mstshash=", strlen("Cookie: mstshash="));
	out_uint8p(s, username, strlen(username));

	out_uint8(s, 0x0d);	/* cookie termination string: CR+LF */
	out_uint8(s, 0x0a);

	if (g_rdp_version >= RDP_V5 && g_negotiate_rdp_protocol)
	{
		/* optional rdp protocol negotiation request for RDPv5 */
		out_uint8(s, RDP_NEG_REQ);
		out_uint8(s, 0);
		out_uint16(s, 8);
		out_uint32(s, PROTOCOL_SSL);
	}

	s_mark_end(s);
	tcp_send(s);
}
Example #25
0
/* Send a self-contained ISO PDU */
static BOOL
iso_send_msg(RDPCLIENT * This, uint8 code)
{
	STREAM s;

	s = tcp_init(This, 11);

	if(s == NULL)
		return False;

	out_uint8(s, 3);	/* version */
	out_uint8(s, 0);	/* reserved */
	out_uint16_be(s, 11);	/* length */

	out_uint8(s, 6);	/* hdrlen */
	out_uint8(s, code);
	out_uint16(s, 0);	/* dst_ref */
	out_uint16(s, 0);	/* src_ref */
	out_uint8(s, 0);	/* class */

	s_mark_end(s);
	return tcp_send(This, s);
}
Example #26
0
/* Output an ASN.1 BER integer */
void
ber_out_integer(STREAM s, int value)
{
	ber_out_header(s, BER_TAG_INTEGER, 2);
	out_uint16_be(s, value);
}
Example #27
0
static int APP_CC
xrdp_mm_send_login(struct xrdp_mm* self)
{
  struct stream * s = (struct stream *)NULL;
  int rv = 0;
  int index = 0;
  int count = 0;
  char * username = (char *)NULL;
  char * password = (char *)NULL;
  char * name = (char *)NULL;
  char * value = (char *)NULL;

  xrdp_wm_log_msg(self->wm, "sending login info to session manager, "
                            "please wait...");
  username = 0;
  password = 0;
  self->code = 0;
  count = self->login_names->count;
  for (index = 0; index < count; index++)
  {
    name = (char*)list_get_item(self->login_names, index);
    value = (char*)list_get_item(self->login_values, index);
    if (g_strcasecmp(name, "username") == 0)
    {
      username = value;
    }
    else if (g_strcasecmp(name, "password") == 0)
    {
      password = value;
    }
    else if (g_strcasecmp(name, "lib") == 0)
    {
      if ((g_strcasecmp(value, "libxup.so") == 0) ||
          (g_strcasecmp(value, "xup.dll") == 0))
      {
        self->code = 10;
      }
    }
  }
  if ((username == 0) || (password == 0))
  {
    xrdp_wm_log_msg(self->wm, "Error finding username and password");
    return 1;
  }

  s = trans_get_out_s(self->sesman_trans, 8192);
  s_push_layer(s, channel_hdr, 8);
  /* this code is either 0 for Xvnc or 10 for X11rdp */
  out_uint16_be(s, self->code);
  index = g_strlen(username);
  out_uint16_be(s, index);
  out_uint8a(s, username, index);
  index = g_strlen(password);

  out_uint16_be(s, index);
  out_uint8a(s, password, index);
  out_uint16_be(s, self->wm->screen->width);
  out_uint16_be(s, self->wm->screen->height);
  out_uint16_be(s, self->wm->screen->bpp);

  /* send domain */
  index = g_strlen(self->wm->client_info->domain);
  out_uint16_be(s, index);
  out_uint8a(s, self->wm->client_info->domain, index);

  /* send program / shell */
  index = g_strlen(self->wm->client_info->program);
  out_uint16_be(s, index);
  out_uint8a(s, self->wm->client_info->program, index);

  /* send directory */
  index = g_strlen(self->wm->client_info->directory);
  out_uint16_be(s, index);
  out_uint8a(s, self->wm->client_info->directory, index);

  /* send client ip */
  index = g_strlen(self->wm->client_info->client_ip);
  out_uint16_be(s, index);
  out_uint8a(s, self->wm->client_info->client_ip, index);

  s_mark_end(s);

  s_pop_layer(s, channel_hdr);
  out_uint32_be(s, 0); /* version */
  index = (int)(s->end - s->data);
  out_uint32_be(s, index); /* size */

  rv = trans_force_write(self->sesman_trans);

  if (rv != 0) {
    xrdp_wm_log_msg(self->wm, "xrdp_mm_send_login: xrdp_mm_send_login failed");
  }

  return rv;
}
Example #28
0
int APP_CC
xrdp_caps_send_demand_active(struct xrdp_rdp *self)
{
    struct stream *s;
    int caps_count;
    int caps_size;
    int codec_caps_count;
    int codec_caps_size;
    int flags;
    char *caps_count_ptr;
    char *caps_size_ptr;
    char *caps_ptr;
    char *codec_caps_count_ptr;
    char *codec_caps_size_ptr;

    make_stream(s);
    init_stream(s, 8192);

    DEBUG(("in xrdp_caps_send_demand_active"));

    if (xrdp_rdp_init(self, s) != 0)
    {
        free_stream(s);
        return 1;
    }

    caps_count = 0;
    out_uint32_le(s, self->share_id);
    out_uint16_le(s, 4); /* 4 chars for RDP\0 */
    /* 2 bytes size after num caps, set later */
    caps_size_ptr = s->p;
    out_uint8s(s, 2);
    out_uint8a(s, "RDP", 4);
    /* 4 byte num caps, set later */
    caps_count_ptr = s->p;
    out_uint8s(s, 4);
    caps_ptr = s->p;

    /* Output share capability set */
    caps_count++;
    out_uint16_le(s, RDP_CAPSET_SHARE);
    out_uint16_le(s, RDP_CAPLEN_SHARE);
    out_uint16_le(s, self->mcs_channel);
    out_uint16_be(s, 0xb5e2); /* 0x73e1 */

    /* Output general capability set */
    caps_count++;
    out_uint16_le(s, RDP_CAPSET_GENERAL); /* 1 */
    out_uint16_le(s, RDP_CAPLEN_GENERAL); /* 24(0x18) */
    out_uint16_le(s, 1); /* OS major type */
    out_uint16_le(s, 3); /* OS minor type */
    out_uint16_le(s, 0x200); /* Protocol version */
    out_uint16_le(s, 0); /* pad */
    out_uint16_le(s, 0); /* Compression types */
    /* NO_BITMAP_COMPRESSION_HDR 0x0400
       FASTPATH_OUTPUT_SUPPORTED 0x0001 */
    if (self->client_info.use_fast_path & 1)
    {
        out_uint16_le(s, 0x401);
    }
    else
    {
        out_uint16_le(s, 0x400);
    }
    out_uint16_le(s, 0); /* Update capability */
    out_uint16_le(s, 0); /* Remote unshare capability */
    out_uint16_le(s, 0); /* Compression level */
    out_uint16_le(s, 0); /* Pad */

    /* Output bitmap capability set */
    caps_count++;
    out_uint16_le(s, RDP_CAPSET_BITMAP); /* 2 */
    out_uint16_le(s, RDP_CAPLEN_BITMAP); /* 28(0x1c) */
    out_uint16_le(s, self->client_info.bpp); /* Preferred BPP */
    out_uint16_le(s, 1); /* Receive 1 BPP */
    out_uint16_le(s, 1); /* Receive 4 BPP */
    out_uint16_le(s, 1); /* Receive 8 BPP */
    out_uint16_le(s, self->client_info.width); /* width */
    out_uint16_le(s, self->client_info.height); /* height */
    out_uint16_le(s, 0); /* Pad */
    out_uint16_le(s, 1); /* Allow resize */
    out_uint16_le(s, 1); /* bitmap compression */
    out_uint16_le(s, 0); /* unknown */
    out_uint16_le(s, 0); /* unknown */
    out_uint16_le(s, 0); /* pad */

    /* Output font capability set */
    caps_count++;
    out_uint16_le(s, RDP_CAPSET_FONT); /* 14 */
    out_uint16_le(s, RDP_CAPLEN_FONT); /* 4 */

    /* Output order capability set */
    caps_count++;
    out_uint16_le(s, RDP_CAPSET_ORDER); /* 3 */
    out_uint16_le(s, RDP_CAPLEN_ORDER); /* 88(0x58) */
    out_uint8s(s, 16);
    out_uint32_be(s, 0x40420f00);
    out_uint16_le(s, 1); /* Cache X granularity */
    out_uint16_le(s, 20); /* Cache Y granularity */
    out_uint16_le(s, 0); /* Pad */
    out_uint16_le(s, 1); /* Max order level */
    out_uint16_le(s, 0x2f); /* Number of fonts */
    out_uint16_le(s, 0x22); /* Capability flags */
    /* caps */
    out_uint8(s, 1); /* NEG_DSTBLT_INDEX                0x00 0 */
    out_uint8(s, 1); /* NEG_PATBLT_INDEX                0x01 1 */
    out_uint8(s, 1); /* NEG_SCRBLT_INDEX                0x02 2 */
    out_uint8(s, 1); /* NEG_MEMBLT_INDEX                0x03 3 */
    out_uint8(s, 0); /* NEG_MEM3BLT_INDEX               0x04 4 */
    out_uint8(s, 0); /* NEG_ATEXTOUT_INDEX              0x05 5 */
    out_uint8(s, 0); /* NEG_AEXTTEXTOUT_INDEX           0x06 6 */
    out_uint8(s, 0); /* NEG_DRAWNINEGRID_INDEX          0x07 7 */
    out_uint8(s, 1); /* NEG_LINETO_INDEX                0x08 8 */
    out_uint8(s, 0); /* NEG_MULTI_DRAWNINEGRID_INDEX    0x09 9 */
    out_uint8(s, 1); /* NEG_OPAQUE_RECT_INDEX           0x0A 10 */
    out_uint8(s, 0); /* NEG_SAVEBITMAP_INDEX            0x0B 11 */
    out_uint8(s, 0); /* NEG_WTEXTOUT_INDEX              0x0C 12 */
    out_uint8(s, 0); /* NEG_MEMBLT_V2_INDEX             0x0D 13 */
    out_uint8(s, 0); /* NEG_MEM3BLT_V2_INDEX            0x0E 14 */
    out_uint8(s, 0); /* NEG_MULTIDSTBLT_INDEX           0x0F 15 */
    out_uint8(s, 0); /* NEG_MULTIPATBLT_INDEX           0x10 16 */
    out_uint8(s, 0); /* NEG_MULTISCRBLT_INDEX           0x11 17 */
    out_uint8(s, 1); /* NEG_MULTIOPAQUERECT_INDEX       0x12 18 */
    out_uint8(s, 0); /* NEG_FAST_INDEX_INDEX            0x13 19 */
    out_uint8(s, 0); /* NEG_POLYGON_SC_INDEX            0x14 20 */
    out_uint8(s, 0); /* NEG_POLYGON_CB_INDEX            0x15 21 */
    out_uint8(s, 0); /* NEG_POLYLINE_INDEX              0x16 22 */
    out_uint8(s, 0); /* unused                          0x17 23 */
    out_uint8(s, 0); /* NEG_FAST_GLYPH_INDEX            0x18 24 */
    out_uint8(s, 0); /* NEG_ELLIPSE_SC_INDEX            0x19 25 */
    out_uint8(s, 0); /* NEG_ELLIPSE_CB_INDEX            0x1A 26 */
    out_uint8(s, 1); /* NEG_GLYPH_INDEX_INDEX           0x1B 27 */
    out_uint8(s, 0); /* NEG_GLYPH_WEXTTEXTOUT_INDEX     0x1C 28 */
    out_uint8(s, 0); /* NEG_GLYPH_WLONGTEXTOUT_INDEX    0x1D 29 */
    out_uint8(s, 0); /* NEG_GLYPH_WLONGEXTTEXTOUT_INDEX 0x1E 30 */
    out_uint8(s, 0); /* unused                          0x1F 31 */
    out_uint16_le(s, 0x6a1);
    /* declare support of bitmap cache rev3 */
    out_uint16_le(s, XR_ORDERFLAGS_EX_CACHE_BITMAP_REV3_SUPPORT);
    out_uint32_le(s, 0x0f4240); /* desk save */
    out_uint32_le(s, 0x0f4240); /* desk save */
    out_uint32_le(s, 1); /* ? */
    out_uint32_le(s, 0); /* ? */

    /* Output bmpcodecs capability set */
    caps_count++;
    out_uint16_le(s, RDP_CAPSET_BMPCODECS);
    codec_caps_size_ptr = s->p;
    out_uint8s(s, 2); /* cap len set later */
    codec_caps_count = 0;
    codec_caps_count_ptr = s->p;
    out_uint8s(s, 1); /* bitmapCodecCount set later */
    /* nscodec */
    codec_caps_count++;
    out_uint8a(s, XR_CODEC_GUID_NSCODEC, 16);
    out_uint8(s, 1); /* codec id, must be 1 */
    out_uint16_le(s, 3); /* codecPropertiesLength */
    out_uint8(s, 0x01); /* fAllowDynamicFidelity */
    out_uint8(s, 0x01); /* fAllowSubsampling */
    out_uint8(s, 0x03); /* colorLossLevel */
#if defined(XRDP_RFXCODEC) || defined(XRDP_NEUTRINORDP)
    /* remotefx */
    codec_caps_count++;
    out_uint8a(s, XR_CODEC_GUID_REMOTEFX, 16);
    out_uint8(s, 0); /* codec id, client sets */
    out_uint16_le(s, 4); /* codecPropertiesLength */
    out_uint32_le(s, 0); /* reserved */
    /* image remotefx */
    codec_caps_count++;
    out_uint8a(s, XR_CODEC_GUID_IMAGE_REMOTEFX, 16);
    out_uint8(s, 0); /* codec id, client sets */
    out_uint16_le(s, 4); /* codecPropertiesLength */
    out_uint32_le(s, 0); /* reserved */
#endif
    /* jpeg */
    codec_caps_count++;
    out_uint8a(s, XR_CODEC_GUID_JPEG, 16);
    out_uint8(s, 0); /* codec id, client sets */
    out_uint16_le(s, 1); /* codecPropertiesLength */
    out_uint8(s, 75); /* jpeg compression ratio */
    /* calculate and set size and count */
    codec_caps_size = (int)(s->p - codec_caps_size_ptr);
    codec_caps_size += 2; /* 2 bytes for RDP_CAPSET_BMPCODECS above */
    codec_caps_size_ptr[0] = codec_caps_size;
    codec_caps_size_ptr[1] = codec_caps_size >> 8;
    codec_caps_count_ptr[0] = codec_caps_count;

    /* Output color cache capability set */
    caps_count++;
    out_uint16_le(s, RDP_CAPSET_COLCACHE);
    out_uint16_le(s, RDP_CAPLEN_COLCACHE);
    out_uint16_le(s, 6); /* cache size */
    out_uint16_le(s, 0); /* pad */

    /* Output pointer capability set */
    caps_count++;
    out_uint16_le(s, RDP_CAPSET_POINTER);
    out_uint16_le(s, RDP_CAPLEN_POINTER);
    out_uint16_le(s, 1); /* Colour pointer */
    out_uint16_le(s, 0x19); /* Cache size */
    out_uint16_le(s, 0x19); /* Cache size */

    /* Output input capability set */
    caps_count++;
    out_uint16_le(s, RDP_CAPSET_INPUT); /* 13(0xd) */
    out_uint16_le(s, RDP_CAPLEN_INPUT); /* 88(0x58) */

    flags = INPUT_FLAG_SCANCODES | INPUT_FLAG_MOUSEX | INPUT_FLAG_UNICODE;
    if (self->client_info.use_fast_path & 2)
    {
        flags |= INPUT_FLAG_FASTPATH_INPUT | INPUT_FLAG_FASTPATH_INPUT2;
    }
    out_uint16_le(s, flags);
    out_uint8s(s, 82);

    /* Remote Programs Capability Set */
    caps_count++;
    out_uint16_le(s, 0x0017); /* CAPSETTYPE_RAIL */
    out_uint16_le(s, 8);
    out_uint32_le(s, 3); /* TS_RAIL_LEVEL_SUPPORTED
                          TS_RAIL_LEVEL_DOCKED_LANGBAR_SUPPORTED */

    /* Window List Capability Set */
    caps_count++;
    out_uint16_le(s, 0x0018); /* CAPSETTYPE_WINDOW */
    out_uint16_le(s, 11);
    out_uint32_le(s, 2); /* TS_WINDOW_LEVEL_SUPPORTED_EX */
    out_uint8(s, 3); /* NumIconCaches */
    out_uint16_le(s, 12); /* NumIconCacheEntries */

    /* 6 - bitmap cache v3 codecid */
    caps_count++;
    out_uint16_le(s, 0x0006);
    out_uint16_le(s, 5);
    out_uint8(s, 0); /* client sets */

    if (self->client_info.use_fast_path & FASTPATH_OUTPUT_SUPPORTED) /* fastpath output on */
    {
        /* multifragment update */
        caps_count++;
        out_uint16_le(s, RDP_CAPSET_MULTIFRAGMENT); /* 26 CAPSETTYPE_MULTIFRAGMENTUPDATE */
        out_uint16_le(s, RDP_CAPLEN_MULTIFRAGMENT);
        out_uint32_le(s, 3 * 1024 * 1024); /* 3MB */

        /* frame acks */
        caps_count++;
        out_uint16_le(s, RDP_CAPSET_FRAME_ACKNOWLEDGE); /* CAPSETTYPE_FRAME_ACKNOWLEDGE */
        out_uint16_le(s, RDP_CAPLEN_FRAME_ACKNOWLEDGE);
        out_uint32_le(s, 2); /* 2 frames in flight */

        /* surface commands */
        caps_count++;
        out_uint16_le(s, RDP_CAPSET_SURFCMDS); /* CAPSETTYPE_SURFACE_COMMANDS */
        out_uint16_le(s, RDP_CAPLEN_SURFCMDS); /* lengthCapability */
        out_uint32_le(s, (SURFCMDS_SETSURFACEBITS |
                          SURFCMDS_FRAMEMARKER |
                          SURFCMDS_STREAMSUFRACEBITS)); /* cmdFlags */
        out_uint32_le(s, 0); /* reserved */
    }

    out_uint8s(s, 4); /* pad */

    s_mark_end(s);

    caps_size = (int)(s->end - caps_ptr);
    caps_size_ptr[0] = caps_size;
    caps_size_ptr[1] = caps_size >> 8;

    caps_count_ptr[0] = caps_count;
    caps_count_ptr[1] = caps_count >> 8;
    caps_count_ptr[2] = caps_count >> 16;
    caps_count_ptr[3] = caps_count >> 24;

    if (xrdp_rdp_send(self, s, RDP_PDU_DEMAND_ACTIVE) != 0)
    {
        free_stream(s);
        return 1;
    }
    DEBUG(("out (1) xrdp_caps_send_demand_active"));

    /* send Monitor Layout PDU for dual monitor */
    if (self->client_info.monitorCount > 0 &&
        self->client_info.multimon == 1)
    {
        DEBUG(("xrdp_caps_send_demand_active: sending monitor layout pdu"));
        if (xrdp_caps_send_monitorlayout(self) != 0)
        {
          g_writeln("xrdp_caps_send_demand_active: error sending monitor layout pdu");
        }
    }

    free_stream(s);
    return 0;
}
Example #29
0
/* 001 */
enum SCP_CLIENT_STATES_E
scp_v1c_mng_connect(struct SCP_CONNECTION *c, struct SCP_SESSION *s)
{
	tui8 sz;
	tui32 size;

	init_stream(c->out_s, c->out_s->size);
	init_stream(c->in_s, c->in_s->size);

	size = 12 + 4 + g_strlen(s->hostname) + g_strlen(s->username) +
			g_strlen(s->password);

	if (s->addr_type == SCP_ADDRESS_TYPE_IPV4)
	{
		size = size + 4;
	}
	else
	{
		size = size + 16;
	}

	/* sending request */

	/* header */
	out_uint32_be(c->out_s, 1); /* version */
	out_uint32_be(c->out_s, size);
	out_uint16_be(c->out_s, SCP_COMMAND_SET_MANAGE);
	out_uint16_be(c->out_s, SCP_CMD_MNG_LOGIN);

	/* data */
	sz = g_strlen(s->username);
	out_uint8(c->out_s, sz);
	out_uint8p(c->out_s, s->username, sz);
	sz = g_strlen(s->password);
	out_uint8(c->out_s, sz);
	out_uint8p(c->out_s, s->password, sz);

	/* address */
	out_uint8(c->out_s, s->addr_type);

	if (s->addr_type == SCP_ADDRESS_TYPE_IPV4)
	{
		out_uint32_be(c->out_s, s->ipv4addr);
	}
	else
	{
		out_uint8p(c->out_s, s->ipv6addr, 16);
	}

	/* hostname */
	sz = g_strlen(s->hostname);
	out_uint8(c->out_s, sz);
	out_uint8p(c->out_s, s->hostname, sz);

	if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, size))
	{
		log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: network error", __LINE__);
		return SCP_CLIENT_STATE_NETWORK_ERR;
	}

	/* wait for response */
	return _scp_v1c_mng_check_response(c, s);
}
Example #30
0
/* 004 */
enum SCP_CLIENT_STATES_E
scp_v1c_mng_get_session_list(struct SCP_CONNECTION *c, int *scount,
		struct SCP_DISCONNECTED_SESSION **s)
{
	tui32 version = 1;
	tui32 size = 12;
	tui16 cmd = SCP_CMD_MNG_LIST_REQ;       /* request session list */
	tui32 sescnt = 0;    /* total session number */
	tui32 sestmp = 0;    /* additional total session number */
	tui8 pktcnt = 0;     /* packet session count */
	tui32 totalcnt = 0;  /* session counter */
	tui8 continued = 0;  /* continue flag */
	int firstpkt = 1;    /* "first packet" flag */
	int idx;
	struct SCP_DISCONNECTED_SESSION *ds = 0;
	//   tui8 addr[16];

	init_stream(c->out_s, c->out_s->size);

	/* we request session list */
	out_uint32_be(c->out_s, version);                 /* version */
	out_uint32_be(c->out_s, size);                    /* size    */
	out_uint16_be(c->out_s, SCP_COMMAND_SET_MANAGE); /* cmdset  */
	out_uint16_be(c->out_s, cmd);                     /* cmd     */

	if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, size))
	{
		log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: network error", __LINE__);
		return SCP_CLIENT_STATE_NETWORK_ERR;
	}

	do
	{
		/* then we wait for server response */
		init_stream(c->in_s, c->in_s->size);

		if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, 8))
		{
			log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: network error", __LINE__);
			return SCP_CLIENT_STATE_NETWORK_ERR;
		}

		in_uint32_be(c->in_s, version);

		if (version != 1)
		{
			log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: version error", __LINE__);
			return SCP_CLIENT_STATE_VERSION_ERR;
		}

		in_uint32_be(c->in_s, size);

		if (size < 12)
		{
			log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: size error", __LINE__);
			return SCP_CLIENT_STATE_SIZE_ERR;
		}

		init_stream(c->in_s, c->in_s->size);

		if (0 != scp_tcp_force_recv(c->in_sck, c->in_s->data, size - 8))
		{
			log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: network error", __LINE__);
			return SCP_CLIENT_STATE_NETWORK_ERR;
		}

		in_uint16_be(c->in_s, cmd);

		if (cmd != SCP_COMMAND_SET_MANAGE)
		{
			log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: sequence error", __LINE__);
			return SCP_CLIENT_STATE_SEQUENCE_ERR;
		}

		in_uint16_be(c->in_s, cmd);

		if (cmd != SCP_CMD_MNG_LIST) /* session list */
		{
			log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: sequence error", __LINE__);
			return SCP_CLIENT_STATE_SEQUENCE_ERR;
		}

		if (firstpkt)
		{
			firstpkt = 0;
			in_uint32_be(c->in_s, sescnt);
			sestmp = sescnt;

			if (0 == sescnt)
			{
				/* return data... */
						(*scount) = sescnt;
						(*s) = NULL;

						LOG_DBG("[v1c_mng] end list - no session on TS");
						return SCP_CLIENT_STATE_LIST_OK;
			}

			ds = g_malloc(sizeof(struct SCP_DISCONNECTED_SESSION) * sescnt, 0);

			if (ds == 0)
			{
				log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: internal error", __LINE__);
				return SCP_CLIENT_STATE_INTERNAL_ERR;
			}
		}
		else
		{
			in_uint32_be(c->in_s, sestmp);
		}

		in_uint8(c->in_s, continued);
		in_uint8(c->in_s, pktcnt);

		for (idx = 0; idx < pktcnt; idx++)
		{
			in_uint32_be(c->in_s, (ds[totalcnt]).SID); /* session id */
			in_uint8(c->in_s, (ds[totalcnt]).type);
			in_uint16_be(c->in_s, (ds[totalcnt]).height);
			in_uint16_be(c->in_s, (ds[totalcnt]).width);
			in_uint8(c->in_s, (ds[totalcnt]).bpp);
			in_uint8(c->in_s, (ds[totalcnt]).idle_days);
			in_uint8(c->in_s, (ds[totalcnt]).idle_hours);
			in_uint8(c->in_s, (ds[totalcnt]).idle_minutes);

			in_uint16_be(c->in_s, (ds[totalcnt]).conn_year);
			in_uint8(c->in_s, (ds[totalcnt]).conn_month);
			in_uint8(c->in_s, (ds[totalcnt]).conn_day);
			in_uint8(c->in_s, (ds[totalcnt]).conn_hour);
			in_uint8(c->in_s, (ds[totalcnt]).conn_minute);
			in_uint8(c->in_s, (ds[totalcnt]).addr_type);

			if ((ds[totalcnt]).addr_type == SCP_ADDRESS_TYPE_IPV4)
			{
				in_uint32_be(c->in_s, (ds[totalcnt]).ipv4addr);
			}

			if ((ds[totalcnt]).addr_type == SCP_ADDRESS_TYPE_IPV6)
			{
				in_uint8a(c->in_s, (ds[totalcnt]).ipv6addr, 16);
			}

			totalcnt++;
		}
	}
	while (continued);

	/* return data... */
	(*scount) = sescnt;
	(*s) = ds;

	LOG_DBG("[v1c_mng] end list");
	return SCP_CLIENT_STATE_LIST_OK;
}