Exemple #1
0
xmlDocPtr DEFAULT_CC
xml_receive_message(int client)
{
	struct stream* s;
	int data_length;
	int res = 0;
	make_stream(s);
	init_stream(s, 1024);
	xmlDocPtr doc;

	res= g_tcp_recv(client, s->data, sizeof(int), 0);

	if (res != sizeof(int))
	{
		log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "sesman[xml_received_message]: "
				"Unable to read size header with error %s", strerror(g_get_errno()));
		return NULL;
	}
	in_uint32_be(s,data_length);
	log_message(&(g_cfg->log), LOG_LEVEL_DEBUG_PLUS, "sesman[xml_received_message]: "
			"data_length : %i", data_length);
	free_stream(s);
	make_stream(s);
	init_stream(s, data_length + 1);

	g_tcp_recv(client, s->data, data_length, 0);
	s->data[data_length] = 0;
	log_message(&(g_cfg->log), LOG_LEVEL_DEBUG_PLUS, "sesman[xml_received_message]: "
			"data : %s",s->data);
	doc = xmlReadMemory(s->data, data_length, "noname.xml", NULL, 0);
	free_stream(s);
	return doc;
}
Exemple #2
0
int APP_CC
xrdp_audit(struct xrdp_process *process, const char*action, const char* message)
{
    // This sends an http 0.9 request, i.e. no headers
    char client_ip[256] = {0,};
    char data[4096] = {0,};
    char username[256] = {0,};
    char device_name[256] = {0,};
    char accesstoken[256] = {0,};
    xrdp_mm_get_value(process->wm->mm, "osirium_account", username, 255);
    xrdp_mm_get_value(process->wm->mm, "device_name", device_name, 255);
    xrdp_mm_get_value(process->wm->mm, "accesstoken", accesstoken, 255);
    xrdp_mm_get_value(process->wm->mm, "client_ip_addr", client_ip, 255);
    if (username[0] == 0)
    {
        g_snprintf(username, 255, "%s", g_getenv("USER"));
    }
    if (device_name[0] == 0)
    {
        g_strcpy(device_name, "unknown");
    }
    if (accesstoken[0] == 0)
    {
        g_strcpy(accesstoken, "unknown");
    }

    g_snprintf(data, sizeof(data)-1, REQUEST_TEMPLATE, 
            username, //process->wm->session->client_info->username,// username
            "rdp",                                      // type
            device_name,    //process->session->client_info->hostname,    // devicename
            action,                                     // action
            accesstoken,                                         // accesstoken
            // process->server_trans->skt
            client_ip //process->session->client_info->hostname // client_ip
            );
    g_writeln(data);
    fflush(stdout);

    // open socket
    int sck = g_tcp_socket();
    fflush(stdout);
    if (g_tcp_connect(sck, AUDIT_ADDRESS, AUDIT_PORT) == 0)
    {
        // left as blocking socket !!
        fflush(stdout);
        // get url
        int sent = g_tcp_send(sck, data, g_strlen(data), 0);
        if ( g_tcp_can_recv(sck, 1000) > 0)  // at most 1 second
        {
            // read response and ignore.
            int rlen = g_tcp_recv(sck, data, sizeof(data)-1, 0);
        }
        else
        {
        }
        fflush(stdout);
        // close socket
        g_tcp_close(sck);
    }
}
Exemple #3
0
/* returns error */
int APP_CC
xrdp_tcp_recv(struct xrdp_tcp* self, struct stream* s, int len)
{
    int rcvd;
    struct xrdp_session* session;

    if (self->sck_closed)
    {
        DEBUG(("    in xrdp_tcp_recv, sck closed"));
        return 1;
    }
    DEBUG(("    in xrdp_tcp_recv, gota get %d bytes", len));
    session = self->iso_layer->mcs_layer->sec_layer->rdp_layer->session;
    init_stream(s, len);
    while (len > 0)
    {
        rcvd = g_tcp_recv(self->sck, s->end, len, 0);
        if (rcvd == -1)
        {
            if (g_tcp_last_error_would_block(self->sck))
            {
                if (!g_tcp_can_recv(self->sck, 10))
                {
                    if (session->is_term != 0)
                    {
                        if (session->is_term())
                        {
                            DEBUG(("    out xrdp_tcp_recv, terminated"));
                            return 1;
                        }
                    }
                }
            }
            else
            {
                self->sck_closed = 1;
                DEBUG(("    error = -1 in xrdp_tcp_recv socket %d", self->sck));
                return 1;
            }
        }
        else if (rcvd == 0)
        {
            self->sck_closed = 1;
            DEBUG(("    error = 0 in xrdp_tcp_recv socket %d", self->sck));
            return 1;
        }
        else
        {
            s->end += rcvd;
            len -= rcvd;
        }
    }
    DEBUG(("    out xrdp_tcp_recv"));
    return 0;
}
Exemple #4
0
void APP_CC
logd_main_loop()
{
	int client = 0;
	char buffer[1024];
	int count;

	log_fd = open(LOGGING_FILE, O_WRONLY | O_CREAT | O_APPEND | O_SYNC, S_IRUSR | S_IWUSR);
	g_mkdir("/var/spool/xrdp");
	g_chmod_hex("/var/spool/xrdp", 0775);
	if ( g_directory_exist("/var/spool/xrdp") == 0)
	{
		g_writeln("Unable to create the logging socket");
		g_exit(1);
	}
	g_writeln("xrdp logging spool application\n");
	log_socket = g_create_unix_socket(LOGGING_SOCKET);
	g_chmod_hex(LOGGING_SOCKET, 0xFFFF);
	if ( log_socket == 1)
	{
		g_writeln("Unable to create logging socket");
		return ;
	}
	if (log_fd < 0){
		g_writeln("Unable to create logging instance\n");
	}
	running = 1;
	while(running)
	{
		client = g_wait_connection(log_socket);

		count = g_tcp_recv(client, (char*)buffer, 1024, 0);
		while(count > 0)
		{
			g_file_write(log_fd, buffer, count);
			count = g_tcp_recv(client, (char*)buffer, 1024, 0);
		}
		count = 0;
		g_tcp_close(client);
	}

}
Exemple #5
0
/* returns error */
int APP_CC
rdp_tcp_recv(struct rdp_tcp *self, struct stream *s, int len)
{
    int rcvd;

    DEBUG(("    in rdp_tcp_recv gota get %d bytes on sck %d",
           len, self->sck));

    if (self->sck_closed)
    {
        DEBUG(("    out rdp_tcp_recv error sck closed"));
        return 1;
    }

    init_stream(s, len);

    while (len > 0)
    {
        rcvd = g_tcp_recv(self->sck, s->end, len, 0);

        if (rcvd == -1)
        {
            if (g_tcp_last_error_would_block(self->sck))
            {
                g_tcp_can_recv(self->sck, 10);
            }
            else
            {
                self->sck_closed = 1;
                DEBUG(("    out rdp_tcp_recv error unknown"));
                return 1;
            }
        }
        else if (rcvd == 0)
        {
            self->sck_closed = 1;
            DEBUG(("    out rdp_tcp_recv error connection dropped"));
            return 1;
        }
        else
        {
            s->end += rcvd;
            len -= rcvd;
        }
    }

    return 0;
}
Exemple #6
0
/* returns error */
static int
rdpup_recv(char* data, int len)
{
  int rcvd;

  if (g_sck_closed)
  {
    return 1;
  }
  while (len > 0)
  {
    rcvd = g_tcp_recv(g_sck, data, len, 0);
    if (rcvd == -1)
    {
      if (g_tcp_last_error_would_block(g_sck))
      {
        g_sleep(1);
      }
      else
      {
        RemoveEnabledDevice(g_sck);
        g_connected = 0;
        g_tcp_close(g_sck);
        g_sck = 0;
        g_sck_closed = 1;
        return 1;
      }
    }
    else if (rcvd == 0)
    {
      RemoveEnabledDevice(g_sck);
      g_connected = 0;
      g_tcp_close(g_sck);
      g_sck = 0;
      g_sck_closed = 1;
      return 1;
    }
    else
    {
      data += rcvd;
      len -= rcvd;
    }
  }
  return 0;
}
Exemple #7
0
/* returns error */
int DEFAULT_CC
lib_recv(struct mod *mod, char *data, int len)
{
    int rcvd;

    if (mod->sck_closed)
    {
        return 1;
    }

    while (len > 0)
    {
        rcvd = g_tcp_recv(mod->sck, data, len, 0);

        if (rcvd == -1)
        {
            if (g_tcp_last_error_would_block(mod->sck))
            {
                if (mod->server_is_term(mod))
                {
                    return 1;
                }

                g_tcp_can_recv(mod->sck, 10);
            }
            else
            {
                return 1;
            }
        }
        else if (rcvd == 0)
        {
            mod->sck_closed = 1;
            return 1;
        }
        else
        {
            data += rcvd;
            len -= rcvd;
        }
    }

    return 0;
}
Exemple #8
0
int APP_CC
trans_force_read(struct trans* self, int size)
{
  int rv;
  int rcvd;

  if (self->status != 1)
  {
    return 1;
  }
  rv = 0;
  while (size > 0)
  {
    rcvd = g_tcp_recv(self->sck, self->in_s->end, size, 0);
    if (rcvd == -1)
    {
      if (g_tcp_last_error_would_block(self->sck))
      {
        if (!g_tcp_can_recv(self->sck, 10))
        {
          /* check for term here */
        }
      }
      else
      {
        /* error */
        self->status = 0;
        rv = 1;
      }
    }
    else if (rcvd == 0)
    {
      /* error */
      self->status = 0;
      rv = 1;
    }
    else
    {
      self->in_s->end += rcvd;
      size -= rcvd;
    }
  }
  return rv;
}
Exemple #9
0
int APP_CC
trans_force_read_s(struct trans* self, struct stream* in_s, int size)
{
  int rcvd;

  if (self->status != TRANS_STATUS_UP)
  {
    return 1;
  }
  while (size > 0)
  {
    rcvd = g_tcp_recv(self->sck, in_s->end, size, 0);
    if (rcvd == -1)
    {
      if (g_tcp_last_error_would_block(self->sck))
      {
        if (!g_tcp_can_recv(self->sck, 10))
        {
          /* check for term here */
        }
      }
      else
      {
        /* error */
        self->status = TRANS_STATUS_DOWN;
        return 1;
      }
    }
    else if (rcvd == 0)
    {
      /* error */
      self->status = TRANS_STATUS_DOWN;
      return 1;
    }
    else
    {
      in_s->end += rcvd;
      size -= rcvd;
    }
  }
  return 0;
}
Exemple #10
0
int
scp_tcp_force_recv(int sck, char *data, int len)
{
    int rcvd;
    int block;

    LOG_DBG("scp_tcp_force_recv()");
    block = scp_lock_fork_critical_section_start();

    while (len > 0)
    {
        rcvd = g_tcp_recv(sck, data, len, 0);

        if (rcvd == -1)
        {
            if (g_tcp_last_error_would_block(sck))
            {
                g_sleep(1);
            }
            else
            {
                scp_lock_fork_critical_section_end(block);
                return 1;
            }
        }
        else if (rcvd == 0)
        {
            scp_lock_fork_critical_section_end(block);
            return 1;
        }
        else
        {
            data += rcvd;
            len -= rcvd;
        }
    }

    scp_lock_fork_critical_section_end(block);

    return 0;
}
Exemple #11
0
int APP_CC
trans_tcp_recv(struct trans *self, char *ptr, int len)
{
    return g_tcp_recv(self->sck, ptr, len, 0);
}
Exemple #12
0
int APP_CC
trans_check_wait_objs(struct trans* self)
{
  tbus in_sck;
  struct trans* in_trans;
  int read_bytes;
  int to_read;
  int read_so_far;
  int rv;

  if (self == 0)
  {
    return 1;
  }
  if (self->status != 1)
  {
    return 1;
  }
  rv = 0;
  if (self->type1 == 1) /* listening */
  {
    if (g_tcp_can_recv(self->sck, 0))
    {
      in_sck = g_tcp_accept(self->sck);
      if (in_sck == -1)
      {
        if (g_tcp_last_error_would_block(self->sck))
        {
          /* ok, but shouldn't happen */
        }
        else
        {
          /* error */
          self->status = 0;
          rv = 1;
        }
      }
      if (in_sck != -1)
      {
        if (self->trans_conn_in != 0) /* is function assigned */
        {
          in_trans = trans_create(self->mode, self->in_s->size,
                                  self->out_s->size);
          in_trans->sck = in_sck;
          in_trans->type1 = 2;
          in_trans->status = 1;
          if (self->trans_conn_in(self, in_trans) != 0)
          {
            trans_delete(in_trans);
          }
        }
        else
        {
          g_tcp_close(in_sck);
        }
      }
    }
  }
  else /* connected server or client (2 or 3) */
  {
    if (g_tcp_can_recv(self->sck, 0))
    {
      read_so_far = (int)(self->in_s->end - self->in_s->data);
      to_read = self->header_size - read_so_far;
      read_bytes = g_tcp_recv(self->sck, self->in_s->end, to_read, 0);
      if (read_bytes == -1)
      {
        if (g_tcp_last_error_would_block(self->sck))
        {
          /* ok, but shouldn't happen */
        }
        else
        {
          /* error */
          self->status = 0;
          rv = 1;
        }
      }
      else if (read_bytes == 0)
      {
        /* error */
        self->status = 0;
        rv = 1;
      }
      else
      {
        self->in_s->end += read_bytes;
      }
      read_so_far = (int)(self->in_s->end - self->in_s->data);
      if (read_so_far == self->header_size)
      {
        if (self->trans_data_in != 0)
        {
          rv = self->trans_data_in(self);
          init_stream(self->in_s, 0);
        }
      }
    }
  }
  return rv;
}
Exemple #13
0
/*
 * called when WTSVirtualChannelWrite() is invoked in xrdpapi.c
 *
 ******************************************************************************/
int DEFAULT_CC
my_api_trans_data_in(struct trans *trans)
{
    struct stream        *s;
    int                   bytes_read;
    int                   i32;
    struct xrdp_api_data *ad;

    //g_writeln("my_api_trans_data_in:");

    LOG(10, ("my_api_trans_data_in:"));

    if (trans == 0)
    {
        return 0;
    }

    if (trans != g_api_con_trans)
    {
        return 1;
    }

    LOGM((LOG_LEVEL_DEBUG, "my_api_trans_data_in:"));

    s = trans_get_in_s(trans);
    bytes_read = g_tcp_recv(trans->sck, s->data, 16, 0);
    if (bytes_read == 16)
    {
        if (g_memcmp(s->data, g_xrdpapi_magic, 12) == 0)
        {
            in_uint8s(s, 12);
            in_uint32_le(s, bytes_read);
            init_stream(s, bytes_read);
            trans_force_read(trans, bytes_read);
        }
        else if (g_tcp_select(trans->sck, 0) & 1)
        {
            i32 = bytes_read;
            bytes_read = g_tcp_recv(trans->sck, s->data + bytes_read,
                                    8192 * 4 - bytes_read, 0);
            if (bytes_read > 0)
            {
                bytes_read += i32;
            }
        }
    }

    //g_writeln("bytes_read %d", bytes_read);

    if (bytes_read > 0)
    {
        LOG(10, ("my_api_trans_data_in: got data %d", bytes_read));
        ad = (struct xrdp_api_data *) trans->callback_data;

        if (ad->dvc_chan_id < 0)
        {
            /* writing data to a static virtual channel */
            if (send_channel_data(ad->chan_id, s->data, bytes_read) != 0)
            {
                LOG(0, ("my_api_trans_data_in: send_channel_data failed"));
            }
        }
        else
        {
            /* writing data to a dynamic virtual channel */
            drdynvc_write_data(ad->dvc_chan_id, s->data, bytes_read);
        }
    }
    else
    {
        ad = (struct xrdp_api_data *) (trans->callback_data);
        if ((ad != NULL) && (ad->dvc_chan_id > 0))
        {
            /* WTSVirtualChannelClose() was invoked, or connection dropped */
            LOG(10, ("my_api_trans_data_in: g_tcp_recv failed or disconnected for DVC"));
            ad->transp = NULL;
            ad->is_connected = 0;
            remove_struct_with_chan_id(ad->dvc_chan_id);
        }
        else
        {
            LOG(10, ("my_api_trans_data_in: g_tcp_recv failed or disconnected for SVC"));
        }
        return 1;
    }

    return 0;
}