Example #1
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);
    }
}
Example #2
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;
}
Example #3
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;
}
Example #4
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;
}
Example #5
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;
}
Example #6
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;
}
Example #7
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;
}
Example #8
0
THREAD_RV THREAD_CC
channel_thread_loop(void *in_val)
{
    tbus objs[32];
    int num_objs;
    int timeout;
    int error;
    THREAD_RV rv;

    LOGM((LOG_LEVEL_INFO, "channel_thread_loop: thread start"));
    rv = 0;
    setup_api_listen();
    error = setup_listen();

    if (error == 0)
    {
        timeout = -1;
        num_objs = 0;
        objs[num_objs] = g_term_event;
        num_objs++;
        trans_get_wait_objs(g_lis_trans, objs, &num_objs);
        trans_get_wait_objs(g_api_lis_trans, objs, &num_objs);

        while (g_obj_wait(objs, num_objs, 0, 0, timeout) == 0)
        {
            if (g_is_wait_obj_set(g_term_event))
            {
                LOGM((LOG_LEVEL_INFO, "channel_thread_loop: g_term_event set"));
                clipboard_deinit();
                sound_deinit();
                dev_redir_deinit();
                rail_deinit();
                break;
            }

            if (g_lis_trans != 0)
            {
                if (trans_check_wait_objs(g_lis_trans) != 0)
                {
                    LOGM((LOG_LEVEL_INFO, "channel_thread_loop: "
                          "trans_check_wait_objs error"));
                }
            }

            if (g_con_trans != 0)
            {
                if (trans_check_wait_objs(g_con_trans) != 0)
                {
                    LOGM((LOG_LEVEL_INFO, "channel_thread_loop: "
                          "trans_check_wait_objs error resetting"));
                    clipboard_deinit();
                    sound_deinit();
                    dev_redir_deinit();
                    rail_deinit();
                    /* delete g_con_trans */
                    trans_delete(g_con_trans);
                    g_con_trans = 0;
                    /* create new listener */
                    error = setup_listen();

                    if (error != 0)
                    {
                        break;
                    }
                }
            }

            if (g_api_lis_trans != 0)
            {
                if (trans_check_wait_objs(g_api_lis_trans) != 0)
                {
                    LOG(0, ("channel_thread_loop: trans_check_wait_objs failed"));
                }
            }

            LOG(10, ("0 %p", g_api_con_trans));

            if (g_api_con_trans != 0)
            {
                LOG(10, ("1 %p %d", g_api_con_trans, g_tcp_can_recv(g_api_con_trans->sck, 0)));

                if (trans_check_wait_objs(g_api_con_trans) != 0)
                {
                    LOG(10, ("channel_thread_loop: trans_check_wait_objs failed, "
                             "or disconnected"));
                    g_free(g_api_con_trans->callback_data);
                    trans_delete(g_api_con_trans);
                    g_api_con_trans = 0;
                }
            }

            xcommon_check_wait_objs();
            sound_check_wait_objs();
            dev_redir_check_wait_objs();
            fuse_check_wait_objs();
            timeout = -1;
            num_objs = 0;
            objs[num_objs] = g_term_event;
            num_objs++;
            trans_get_wait_objs(g_lis_trans, objs, &num_objs);
            trans_get_wait_objs(g_con_trans, objs, &num_objs);
            trans_get_wait_objs(g_api_lis_trans, objs, &num_objs);
            trans_get_wait_objs(g_api_con_trans, objs, &num_objs);
            xcommon_get_wait_objs(objs, &num_objs, &timeout);
            sound_get_wait_objs(objs, &num_objs, &timeout);
            dev_redir_get_wait_objs(objs, &num_objs, &timeout);
            fuse_get_wait_objs(objs, &num_objs, &timeout);
        }
    }

    trans_delete(g_lis_trans);
    g_lis_trans = 0;
    trans_delete(g_con_trans);
    g_con_trans = 0;
    trans_delete(g_api_lis_trans);
    g_api_lis_trans = 0;
    trans_delete(g_api_con_trans);
    g_api_con_trans = 0;
    LOGM((LOG_LEVEL_INFO, "channel_thread_loop: thread stop"));
    g_set_wait_obj(g_thread_done_event);
    return rv;
}