Beispiel #1
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;
}
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 void *DEFAULT_CC
read_raw_audio_data(void *arg)
{
    pa_sample_spec samp_spec;
    pa_simple *simple = NULL;
    uint32_t bytes_read;
    char *cptr;
    int i;
    int error;
    struct trans *strans;
    char path[256];
    struct stream *outs;

    strans = trans_create(TRANS_MODE_UNIX, 8192, 8192);

    if (strans == 0)
    {
        LOG(0, ("read_raw_audio_data: trans_create failed\n"));
        return 0;
    }

    strans->trans_data_in = sttrans_data_in;
    g_snprintf(path, 255, "/tmp/xrdp_chansrv_audio_socket_%d", g_display_num);

    if (trans_connect(strans, "", path, 100) != 0)
    {
        LOG(0, ("read_raw_audio_data: trans_connect failed\n"));
        trans_delete(strans);
        return 0;
    }

    /* setup audio format */
    samp_spec.format = PA_SAMPLE_S16LE;
    samp_spec.rate = 44100;
    samp_spec.channels = 2;

    /* if we are root, then for first 8 seconds connection to pulseaudo server
       fails; if we are non-root, then connection succeeds on first attempt;
       for now we have changed code to be non-root, but this may change in the
       future - so pretend we are root and try connecting to pulseaudio server
       for upto one minute */
    for (i = 0; i < 60; i++)
    {
        simple = pa_simple_new(NULL, "xrdp", PA_STREAM_RECORD, NULL,
                               "record", &samp_spec, NULL, NULL, &error);

        if (simple)
        {
            /* connected to pulseaudio server */
            LOG(0, ("read_raw_audio_data: connected to pulseaudio server\n"));
            break;
        }

        LOG(0, ("read_raw_audio_data: ERROR creating PulseAudio async interface\n"));
        LOG(0, ("read_raw_audio_data: %s\n", pa_strerror(error)));
        g_sleep(1000);
    }

    if (i == 60)
    {
        /* failed to connect to audio server */
        trans_delete(strans);
        return NULL;
    }

    /* insert header just once */
    outs = trans_get_out_s(strans, 8192);
    out_uint32_le(outs, 0);
    out_uint32_le(outs, AUDIO_BUF_SIZE + 8);
    cptr = outs->p;
    out_uint8s(outs, AUDIO_BUF_SIZE);
    s_mark_end(outs);

    while (1)
    {
        /* read a block of raw audio data... */
        g_memset(cptr, 0, 4);
        bytes_read = pa_simple_read(simple, cptr, AUDIO_BUF_SIZE, &error);

        if (bytes_read < 0)
        {
            LOG(0, ("read_raw_audio_data: ERROR reading from pulseaudio stream\n"));
            LOG(0, ("read_raw_audio_data: %s\n", pa_strerror(error)));
            break;
        }

        /* bug workaround:
           even when there is no audio data, pulseaudio is returning without
           errors but the data itself is zero; we use this zero data to
           determine that there is no audio data present */
        if (*cptr == 0 && *(cptr + 1) == 0 && *(cptr + 2) == 0 && *(cptr + 3) == 0)
        {
            g_sleep(10);
            continue;
        }

        if (trans_force_write_s(strans, outs) != 0)
        {
            LOG(0, ("read_raw_audio_data: ERROR writing audio data to server\n"));
            break;
        }
    }

    pa_simple_free(simple);
    trans_delete(strans);
    return NULL;
}