Beispiel #1
0
int APP_CC
process_preamble_packet(struct xrdp_wm *self)
{
    char* line_end;
    char* t;
    char* q;
    char* r;
    DEBUG(("Preamble %s", self->session->client_info->osirium_preamble_buffer))
    line_end = g_strchr(self->session->client_info->osirium_preamble_buffer, '\n');
    while (line_end != 0)
    {
        q = line_end+1;
        // locate start of name
        while ( isspace(*q) )
        {
            q++;
        }
        DEBUG(("Preamble still needing processing %s", q));
        // locate separator
        t = r = g_strchr(q,'=');
        if ( r == 0 ) break;  // handle broken preamble by assuming at end of pre
        *r = 0; // ensure name terminated

        // strip possible trailing spaces from name
        while ( isspace(*--t) )
        {
            *t = 0; // nulls to terminate name
        };
        // locate start of value
        while ( isspace(*++r) )
        {
          // pre increment
        }

        line_end = g_strchr(r, '\n'); //locate end of value
        if (line_end)   // may be last value in preamble and have no LF at end.
        {
            *line_end = 0; // null terminate value
        }
        DEBUG(("Name '%s' Value '%s'", q, r));
        list_add_item(self->mm->login_names, (long)g_strdup(q));
        list_add_item(self->mm->login_values, (long)g_strdup(r));
    }
    g_free(self->session->client_info->osirium_preamble_buffer);
    self->session->client_info->osirium_preamble_buffer = 0;
    xrdp_wm_set_login_mode(self, 2);
}
Beispiel #2
0
int APP_CC
xrdp_mm_connect(struct xrdp_mm* self)
{
  struct list* names = (struct list *)NULL;
  struct list* values = (struct list *)NULL;
  int index = 0;
  int count = 0;
  int use_sesman = 0;
  int error = 0;
  int ok = 0;
  int rv = 0;
  char* name = (char *)NULL;
  char* value = (char *)NULL;
  char ip[256];
  char errstr[256];
  char text[256];
  char port[8];

  g_memset(ip,0,sizeof(char) * 256);
  g_memset(errstr,0,sizeof(char) * 256);
  g_memset(text,0,sizeof(char) * 256);
  g_memset(port,0,sizeof(char) * 8);
  rv = 0;
  use_sesman = 0;
  names = self->login_names;
  values = self->login_values;
  count = names->count;
  for (index = 0; index < count; index++)
  {
    name = (char*)list_get_item(names, index);
    value = (char*)list_get_item(values, index);
    if (g_strcasecmp(name, "ip") == 0)
    {
      g_strncpy(ip, value, 255);
    }
    else if (g_strcasecmp(name, "port") == 0)
    {
      if (g_strcasecmp(value, "-1") == 0)
      {
        use_sesman = 1;
      }
    }
  }
  if (use_sesman)
  {
    ok = 0;
    errstr[0] = 0;
    trans_delete(self->sesman_trans);
    self->sesman_trans = trans_create(TRANS_MODE_TCP, 8192, 8192);
    xrdp_mm_get_sesman_port(port, sizeof(port));
    g_snprintf(text, 255, "connecting to sesman ip %s port %s", ip, port);
    xrdp_wm_log_msg(self->wm, text);

    self->sesman_trans->trans_data_in = xrdp_mm_sesman_data_in;
    self->sesman_trans->header_size = 8;
    self->sesman_trans->callback_data = self;
    /* try to connect up to 4 times */
    for (index = 0; index < 4; index++)
    {
      if (trans_connect(self->sesman_trans, ip, port, 3000) == 0)
      {
        self->sesman_trans_up = 1;
        ok = 1;
        break;
      }
      g_sleep(1000);
      g_writeln("xrdp_mm_connect: connect failed "
                "trying again...");
    }
    if (ok)
    {
      /* fully connect */
      xrdp_wm_log_msg(self->wm, "sesman connect ok");
      self->connected_state = 1;
      rv = xrdp_mm_send_login(self);
    }
    else
    {
      xrdp_wm_log_msg(self->wm, errstr);
      trans_delete(self->sesman_trans);
      self->sesman_trans = 0;
      self->sesman_trans_up = 0;
      rv = 1;
    }
  }
  else /* no sesman */
  {
    if (xrdp_mm_setup_mod1(self) == 0)
    {
      if (xrdp_mm_setup_mod2(self) == 0)
      {
        xrdp_wm_set_login_mode(self->wm, 10);
      }
    }
    if (self->wm->login_mode != 10)
    {
      xrdp_wm_set_login_mode(self->wm, 11);
      xrdp_mm_module_cleanup(self);
    }
  }
  self->sesman_controlled = use_sesman;

  return rv;
}
Beispiel #3
0
static int APP_CC
xrdp_mm_process_login_response(struct xrdp_mm* self, struct stream* s)
{
  int ok = 0;
  int display = 0;
  int rv = 0;
  int index = 0;
  char text[256];
  char ip[256];
  char port[256];

  g_memset(text,0,sizeof(char) * 256);
  g_memset(ip,0,sizeof(char) * 256);
  g_memset(port,0,sizeof(char) * 256);
  rv = 0;
  in_uint16_be(s, ok);
  in_uint16_be(s, display);
  if (ok)
  {
    self->display = display;
    g_snprintf(text, 255, "xrdp_mm_process_login_response: login successful "
                          "for display %d", display);
    xrdp_wm_log_msg(self->wm, text);
    if (xrdp_mm_setup_mod1(self) == 0)
    {
      if (xrdp_mm_setup_mod2(self) == 0)
      {
        xrdp_mm_get_value(self, "ip", ip, 255);
        xrdp_wm_set_login_mode(self->wm, 10);
        self->wm->dragging = 0;
        /* connect channel redir */
        if (strcmp(ip, "127.0.0.1") == 0)
        {
          /* unix socket */
          self->chan_trans = trans_create(TRANS_MODE_UNIX, 8192, 8192);
          g_snprintf(port, 255, "/tmp/xrdp_chansrv_socket_%d", 7200 + display);
        }
        else
        {
          /* tcp */
          self->chan_trans = trans_create(TRANS_MODE_TCP, 8192, 8192);
          g_snprintf(port, 255, "%d", 7200 + display);
        }
        self->chan_trans->trans_data_in = xrdp_mm_chan_data_in;
        self->chan_trans->header_size = 8;
        self->chan_trans->callback_data = self;
        /* try to connect up to 4 times */
        for (index = 0; index < 4; index++)
        {
          if (trans_connect(self->chan_trans, ip, port, 3000) == 0)
          {
            self->chan_trans_up = 1;
            break;
          }
          g_sleep(1000);
          g_writeln("xrdp_mm_process_login_response: connect failed "
                    "trying again...");
        }
        if (!(self->chan_trans_up))
        {
          g_writeln("xrdp_mm_process_login_response: error in trans_connect "
                    "chan");
        }
        if (self->chan_trans_up)
        {
          if (xrdp_mm_chan_send_init(self) != 0)
          {
            g_writeln("xrdp_mm_process_login_response: error in "
                      "xrdp_mm_chan_send_init");
          }
        }
      }
    }
  }
  else
  {
    xrdp_wm_log_msg(self->wm, "xrdp_mm_process_login_response: "
                              "login failed");
  }
  self->delete_sesman_trans = 1;
  self->connected_state = 0;
  if (self->wm->login_mode != 10)
  {
    xrdp_wm_set_login_mode(self->wm, 11);
    xrdp_mm_module_cleanup(self);
  }

  return rv;
}