Beispiel #1
0
/* returns boolean */
int DEFAULT_CC
auth_userpass(char *user, char *pass, int *errorcode)
{
    struct k_opts opts;
    struct k5_data k5;
    struct user_info u_info;
    int got_k5;
    int authed_k5;

    g_memset(&opts, 0, sizeof(opts));
    opts.action = INIT_PW;
    g_memset(&k5, 0, sizeof(k5));
    g_memset(&u_info, 0, sizeof(u_info));
    u_info.name = user;
    u_info.pass = pass;
    authed_k5 = 0;
    got_k5 = k5_begin(&opts, &k5, &u_info);

    if (got_k5)
    {
        authed_k5 = k5_kinit(&opts, &k5, &u_info);
        k5_end(&k5);
    }

    return authed_k5;
}
Beispiel #2
0
static int APP_CC
get_display_num_from_display(char *display_text)
{
    int index;
    int mode;
    int host_index;
    int disp_index;
    int scre_index;
    char host[256];
    char disp[256];
    char scre[256];

    g_memset(host, 0, 256);
    g_memset(disp, 0, 256);
    g_memset(scre, 0, 256);

    index = 0;
    host_index = 0;
    disp_index = 0;
    scre_index = 0;
    mode = 0;

    while (display_text[index] != 0)
    {
        if (display_text[index] == ':')
        {
            mode = 1;
        }
        else if (display_text[index] == '.')
        {
            mode = 2;
        }
        else if (mode == 0)
        {
            host[host_index] = display_text[index];
            host_index++;
        }
        else if (mode == 1)
        {
            disp[disp_index] = display_text[index];
            disp_index++;
        }
        else if (mode == 2)
        {
            scre[scre_index] = display_text[index];
            scre_index++;
        }

        index++;
    }

    host[host_index] = 0;
    disp[disp_index] = 0;
    scre[scre_index] = 0;
    g_display_num = g_atoi(disp);
    return 0;
}
Beispiel #3
0
/* returns error
   returns 0 if everything is ok
   returns 1 if problem reading file */
static int APP_CC
l_file_read_sections(int fd, int max_file_size, struct list *names)
{
    struct stream *s;
    char text[FILE_MAX_LINE_BYTES];
    char c;
    int in_it;
    int in_it_index;
    int len;
    int index;
    int rv;

    rv = 0;
    g_file_seek(fd, 0);
    in_it_index = 0;
    in_it = 0;
    g_memset(text, 0, FILE_MAX_LINE_BYTES);
    list_clear(names);
    make_stream(s);
    init_stream(s, max_file_size);
    len = g_file_read(fd, s->data, max_file_size);

    if (len > 0)
    {
        s->end = s->p + len;

        for (index = 0; index < len; index++)
        {
            in_uint8(s, c);

            if (c == '[')
            {
                in_it = 1;
            }
            else if (c == ']')
            {
                list_add_item(names, (tbus)g_strdup(text));
                in_it = 0;
                in_it_index = 0;
                g_memset(text, 0, FILE_MAX_LINE_BYTES);
            }
            else if (in_it)
            {
                text[in_it_index] = c;
                in_it_index++;
            }
        }
    }
    else if (len < 0)
    {
        rv = 1;
    }

    free_stream(s);
    return rv;
}
Beispiel #4
0
int
rdpPrivateInit(void)
{
#if XRDP_PRI == 3
    g_memset(&g_privateKeyRecGC, 0, sizeof(g_privateKeyRecGC));
    g_memset(&g_privateKeyRecWindow, 0, sizeof(g_privateKeyRecWindow));
    g_memset(&g_privateKeyRecPixmap, 0, sizeof(g_privateKeyRecPixmap));
#endif
    return 0;
}
Beispiel #5
0
int g_tcp_select(int sck1, int sck2)
{
	fd_set rfds;
	struct timeval time;
	int max = 0;
	int rv = 0;

	g_memset(&rfds, 0, sizeof(fd_set));
	g_memset(&time, 0, sizeof(struct timeval));

	time.tv_sec = 0;
	time.tv_usec = 0;
	FD_ZERO(&rfds);

	if (sck1 > 0)
	{
		FD_SET(((unsigned int)sck1), &rfds);
	}

	if (sck2 > 0)
	{
		FD_SET(((unsigned int)sck2), &rfds);
	}

	max = sck1;

	if (sck2 > max)
	{
		max = sck2;
	}

	rv = select(max + 1, &rfds, 0, 0, &time);

	if (rv > 0)
	{
		rv = 0;

		if (FD_ISSET(((unsigned int)sck1), &rfds))
		{
			rv = rv | 1;
		}

		if (FD_ISSET(((unsigned int)sck2), &rfds))
		{
			rv = rv | 2;
		}
	} else
	{
		rv = 0;
	}

	return rv;
}
Beispiel #6
0
/* returns error, zero is good */
static int  g_tcp_bind_flags(int sck, const char* port, const char* address, int flags)
{
	int error;
	int status;
	struct addrinfo* res;
	struct addrinfo hints = { 0 };

	status = -1;
	g_memset(&hints, 0, sizeof(struct addrinfo));

	hints.ai_family = AF_UNSPEC;
	hints.ai_flags = flags;
	hints.ai_socktype = SOCK_STREAM;
	hints.ai_protocol = IPPROTO_TCP;
	error = getaddrinfo(NULL, port, &hints, &res);

	if (error == 0)
	{
		while ((res != 0) && (status < 0))
		{
			if (address_match(address, res))
			{
				status = bind(sck, res->ai_addr, res->ai_addrlen);
			}

			res = res->ai_next;
		}
	}

	return status;
}
Beispiel #7
0
/**
 * Creates a string consisting of all parameters that is hosted in the param list
 * @param self
 * @param outstr, allocate this buffer before you use this function
 * @param len the allocated len for outstr
 * @return
 */
char *APP_CC
dumpItemsToString(struct list *self, char *outstr, int len)
{
    g_memset(outstr, 0, len);
    int index;
    tbus item;
    int totalLen = 0;

    if (self->count == 0)
    {
        g_writeln("List is empty");
    }

    for (index = 0; index < self->count; index++)
    {
        /* +1 = one space*/
        totalLen = totalLen + g_strlen((char *)list_get_item(self, index)) + 1;

        if (len > totalLen)
        {
            g_strcat(outstr, (char *)list_get_item(self, index));
            g_strcat(outstr, " ");
        }
    }

    return outstr ;
}
Beispiel #8
0
int APP_CC
rect_intersect(struct xrdp_rect* in1, struct xrdp_rect* in2,
               struct xrdp_rect* out)
{
  int rv;
  struct xrdp_rect dumby;

  if (out == 0)
  {
    out = &dumby;
  }
  *out = *in1;
  if (in2->left > in1->left)
  {
    out->left = in2->left;
  }
  if (in2->top > in1->top)
  {
    out->top = in2->top;
  }
  if (in2->right < in1->right)
  {
    out->right = in2->right;
  }
  if (in2->bottom < in1->bottom)
  {
    out->bottom = in2->bottom;
  }
  rv = !ISRECTEMPTY(*out);
  if (!rv)
  {
    g_memset(out, 0, sizeof(struct xrdp_rect));
  }
  return rv;
}
Beispiel #9
0
/* this will replace %20 or any hex with the space or correct char
 * returns error */
static int
clipboard_check_file(char *filename)
{
    char lfilename[256];
    char jchr[8];
    int lindex;
    int index;

    g_memset(lfilename, 0, 256);
    lindex = 0;
    index = 0;
    while (filename[index] != 0)
    {
        if (filename[index] == '%')
        {
            jchr[0] = filename[index + 1];
            jchr[1] = filename[index + 2];
            jchr[2] = 0;
            index += 3;
            lfilename[lindex] = g_htoi(jchr);
            lindex++;
        }
        else
        {
            lfilename[lindex] = filename[index];
            lindex++;
            index++;
        }
    }
    log_debug("[%s] [%s]", filename, lfilename);
    g_strcpy(filename, lfilename);
    return 0;
}
Beispiel #10
0
int APP_CC
xcommon_check_wait_objs(void)
{
    XEvent xevent;
    int clip_rv;
    int rail_rv;

    if ((!g_clip_up) && (!g_rail_up))
    {
        return 0;
    }
    while (XPending(g_display) > 0)
    {
        g_memset(&xevent, 0, sizeof(xevent));
        XNextEvent(g_display, &xevent);
        clip_rv = clipboard_xevent(&xevent);
        rail_rv = rail_xevent(&xevent);
        if ((clip_rv == 1) && (rail_rv == 1))
        {
            LOG(10, ("xcommon_check_wait_objs unknown xevent type %d",
                     xevent.type));
        }
    }
    return 0;
}
Beispiel #11
0
static void DEFAULT_CC
k5_end(struct k5_data *k5)
{
    if (k5->name)
    {
        krb5_free_unparsed_name(k5->ctx, k5->name);
    }

    if (k5->me)
    {
        krb5_free_principal(k5->ctx, k5->me);
    }

    if (k5->cc)
    {
        krb5_cc_close(k5->ctx, k5->cc);
    }

    if (k5->ctx)
    {
        krb5_free_context(k5->ctx);
    }

    g_memset(k5, 0, sizeof(struct k5_data));
}
Beispiel #12
0
int APP_CC
g_tcp_connect(int sck, const char* address, const char* port)
{
    struct sockaddr_in s;
    struct hostent* h;

    g_memset(&s, 0, sizeof(struct sockaddr_in));
    s.sin_family = AF_INET;
    s.sin_port = htons(atoi(port));
    s.sin_addr.s_addr = inet_addr(address);
    if (s.sin_addr.s_addr == INADDR_NONE)
    {
        h = gethostbyname(address);
        if (h != 0)
        {
            if (h->h_name != 0)
            {
                if (h->h_addr_list != 0)
                {
                    if ((*(h->h_addr_list)) != 0)
                    {
                        s.sin_addr.s_addr = *((int*)(*(h->h_addr_list)));
                    }
                }
            }
        }
    }
    return connect(sck, (struct sockaddr*)&s, sizeof(struct sockaddr_in));
}
Beispiel #13
0
/* returns error */
int APP_CC
xrdp_cache_remove_os_bitmap(struct xrdp_cache *self, int rdpindex)
{
    struct xrdp_os_bitmap_item *bi;
    int index;

    if ((rdpindex < 0) || (rdpindex >= 2000))
    {
        return 1;
    }

    bi = self->os_bitmap_items + rdpindex;

    if (bi->bitmap->tab_stop)
    {
        index = list_index_of(self->xrdp_os_del_list, rdpindex);

        if (index == -1)
        {
            list_add_item(self->xrdp_os_del_list, rdpindex);
        }
    }

    xrdp_bitmap_delete(bi->bitmap);
    g_memset(bi, 0, sizeof(struct xrdp_os_bitmap_item));
    return 0;
}
Beispiel #14
0
int 
clipboard_c2s_in_files(struct stream *s, char *file_list)
{
    int cItems;
    int lindex;
    int str_len;
    struct clip_file_desc *cfd;
    char *ptr;

    if (!s_check_rem(s, 4))
    {
        LLOGLN(0, ("clipboard_c2s_in_files: parse error"));
        return 1;
    }
    in_uint32_le(s, cItems);
    if (cItems > 64 * 1024) /* sanity check */
    {
        LLOGLN(0, ("clipboard_c2s_in_files: error cItems %d too big", cItems));
        return 1;
    }
    xfuse_clear_clip_dir();
    LLOGLN(10, ("clipboard_c2s_in_files: cItems %d", cItems));
    cfd = (struct clip_file_desc *)
          g_malloc(sizeof(struct clip_file_desc), 0);
    ptr = file_list;
    for (lindex = 0; lindex < cItems; lindex++)
    {
        g_memset(cfd, 0, sizeof(struct clip_file_desc));
        clipboard_c2s_in_file_info(s, cfd);
        if ((g_pos(cfd->cFileName, "\\") >= 0) ||
            (cfd->fileAttributes & CB_FILE_ATTRIBUTE_DIRECTORY))
        {
            LLOGLN(0, ("clipboard_c2s_in_files: skipping directory not "
                       "supported [%s]", cfd->cFileName));
            continue;
        }
        xfuse_add_clip_dir_item(cfd->cFileName, 0, cfd->fileSizeLow, lindex);

        g_strcpy(ptr, "file://");
        ptr += 7;

        str_len = g_strlen(g_fuse_clipboard_path);
        g_strcpy(ptr, g_fuse_clipboard_path);
        ptr += str_len;

        *ptr = '/';
        ptr++;

        str_len = g_strlen(cfd->cFileName);
        g_strcpy(ptr, cfd->cFileName);
        ptr += str_len;

        *ptr = '\n';
        ptr++;
    }
    *ptr = 0;
    g_free(cfd);
    return 0;
}
Beispiel #15
0
Datei: env.c Projekt: PKRoma/xrdp
int
env_check_password_file(const char *filename, const char *passwd)
{
    char encryptedPasswd[16];
    char key[24];
    char passwd_hash[20];
    char passwd_hash_text[40];
    int fd;
    int passwd_bytes;
    void *des;
    void *sha1;

    /* create password hash from password */
    passwd_bytes = g_strlen(passwd);
    sha1 = ssl_sha1_info_create();
    ssl_sha1_transform(sha1, "xrdp_vnc", 8);
    ssl_sha1_transform(sha1, passwd, passwd_bytes);
    ssl_sha1_transform(sha1, passwd, passwd_bytes);
    ssl_sha1_complete(sha1, passwd_hash);
    ssl_sha1_info_delete(sha1);
    g_snprintf(passwd_hash_text, 39, "%2.2x%2.2x%2.2x%2.2x",
               (tui8)passwd_hash[0], (tui8)passwd_hash[1],
               (tui8)passwd_hash[2], (tui8)passwd_hash[3]);
    passwd_hash_text[39] = 0;
    passwd = passwd_hash_text;

    /* create file from password */
    g_memset(encryptedPasswd, 0, sizeof(encryptedPasswd));
    g_strncpy(encryptedPasswd, passwd, 8);
    g_memset(key, 0, sizeof(key));
    g_mirror_memcpy(key, g_fixedkey, 8);
    des = ssl_des3_encrypt_info_create(key, 0);
    ssl_des3_encrypt(des, 8, encryptedPasswd, encryptedPasswd);
    ssl_des3_info_delete(des);
    fd = g_file_open_ex(filename, 0, 1, 1, 1);
    if (fd == -1)
    {
        log_message(LOG_LEVEL_WARNING,
                    "Cannot write VNC password hash to file %s: %s",
                    filename, g_get_strerror());
        return 1;
    }
    g_file_write(fd, encryptedPasswd, 8);
    g_file_close(fd);
    return 0;
}
Beispiel #16
0
/* returns the number of milliseconds since the machine was
 started. */
int g_time2(void)
{
#if defined(_WIN32)
	return (int)GetTickCount();
#else
	struct tms tm;
	clock_t num_ticks = 0;
	g_memset(&tm, 0, sizeof(struct tms));
	num_ticks = times(&tm);
	return (int) (num_ticks * 10);
#endif
}
Beispiel #17
0
/* returns error, zero is good */
int g_tcp_connect(int sck, const char *address, const char *port)
{
	int res = 0;
	struct addrinfo p;
	struct addrinfo *h = (struct addrinfo *) NULL;
	struct addrinfo *rp = (struct addrinfo *) NULL;

	/* initialize (zero out) local variables: */
	g_memset(&p, 0, sizeof(struct addrinfo));

	/* in IPv6-enabled environments, set the AI_V4MAPPED
	 * flag in ai_flags and specify ai_family=AF_INET6 in
	 * order to ensure that getaddrinfo() returns any
	 * available IPv4-mapped addresses in case the target
	 * host does not have a true IPv6 address:
	 */
	p.ai_socktype = SOCK_STREAM;
	p.ai_protocol = IPPROTO_TCP;
#if !defined(NO_ARPA_INET_H_IP6)
	p.ai_flags = AI_ADDRCONFIG | AI_V4MAPPED;
	p.ai_family = AF_INET6;
	if (g_strcmp(address, "127.0.0.1") == 0)
	{
		res = getaddrinfo("::1", port, &p, &h);
	} else
	{
		res = getaddrinfo(address, port, &p, &h);
	}
#else
	p.ai_flags = AI_ADDRCONFIG;
	p.ai_family = AF_INET;
	res = getaddrinfo(address, port, &p, &h);
#endif
	if (res > -1)
	{
		if (h != NULL)
		{
			for (rp = h; rp != NULL; rp = rp->ai_next)
			{
				rp = h;
				res = connect(sck, (struct sockaddr *) (rp->ai_addr), rp->ai_addrlen);
				if (res != -1)
				{
					break; /* Success */
				}
			}
		}
	}
	return res;
}
Beispiel #18
0
static int
xrdp_mm_get_sesman_port(char* port, int port_bytes)
{
  int fd = -1;
  int error = 0;
  int index = 0;
  char* val = 0;
  char cfg_file[256];
  struct list* names = (struct list *)NULL;
  struct list* values = (struct list *)NULL;

  g_memset(cfg_file,0,sizeof(char) * 256);
  /* default to port 3350 */
  g_strncpy(port, "3350", port_bytes - 1);
  /* see if port is in xrdp.ini file */
  file_config_name("sesman.ini", cfg_file, 255);
  fd = g_file_open(cfg_file);
  if (fd > 0)
  {
    names = list_create();
    names->auto_free = 1;
    values = list_create();
    values->auto_free = 1;
    if (file_read_section(fd, "Globals", names, values) == 0)
    {
      for (index = 0; index < names->count; index++)
      {
        val = (char*)list_get_item(names, index);
        if (val != 0)
        {
          if (g_strcasecmp(val, "ListenPort") == 0)
          {
            val = (char*)list_get_item(values, index);
            error = g_atoi(val);
            if ((error > 0) && (error < 65000))
            {
              g_strncpy(port, val, port_bytes - 1);
            }
            break;
          }
        }
      }
    }
    list_delete(names);
    list_delete(values);
    g_file_close(fd);
  }

  return 0;
}
Beispiel #19
0
int APP_CC
xrdp_cache_reset(struct xrdp_cache *self,
                 struct xrdp_client_info *client_info)
{
    struct xrdp_wm *wm;
    struct xrdp_session *session;
    int i;
    int j;

    /* free all the cached bitmaps */
    for (i = 0; i < XRDP_MAX_BITMAP_CACHE_ID; i++)
    {
        for (j = 0; j < XRDP_MAX_BITMAP_CACHE_IDX; j++)
        {
            xrdp_bitmap_delete(self->bitmap_items[i][j].bitmap);
        }
    }

    /* free all the cached font items */
    for (i = 0; i < 12; i++)
    {
        for (j = 0; j < 256; j++)
        {
            g_free(self->char_items[i][j].font_item.data);
        }
    }

    /* save these */
    wm = self->wm;
    session = self->session;
    /* set whole struct to zero */
    g_memset(self, 0, sizeof(struct xrdp_cache));
    /* set some stuff back */
    self->wm = wm;
    self->session = session;
    self->use_bitmap_comp = client_info->use_bitmap_comp;
    self->cache1_entries = client_info->cache1_entries;
    self->cache1_size = client_info->cache1_size;
    self->cache2_entries = client_info->cache2_entries;
    self->cache2_size = client_info->cache2_size;
    self->cache3_entries = client_info->cache3_entries;
    self->cache3_size = client_info->cache3_size;
    self->bitmap_cache_persist_enable = client_info->bitmap_cache_persist_enable;
    self->bitmap_cache_version = client_info->bitmap_cache_version;
    self->pointer_cache_entries = client_info->pointer_cache_entries;
    xrdp_cache_reset_lru(self);
    xrdp_cache_reset_crc(self);
    return 0;
}
Beispiel #20
0
/* return error */
static int APP_CC
process_server_window_show(struct mod* mod, struct stream* s)
{
    int window_id;
    int rv;
    int flags;
    struct rail_window_state_order rwso;

    g_memset(&rwso, 0, sizeof(rwso));
    in_uint32_le(s, window_id);
    in_uint32_le(s, flags);
    in_uint32_le(s, rwso.show_state);
    mod->server_window_new_update(mod, window_id, &rwso, flags);
    rv = 0;
    return rv;
}
Beispiel #21
0
static int APP_CC
rail_close_window(int window_id)
{
    XEvent ce;

    LOG(0, ("chansrv::rail_close_window:"));
    g_memset(&ce, 0, sizeof(ce));
    ce.xclient.type = ClientMessage;
    ce.xclient.message_type = g_wm_protocols_atom;
    ce.xclient.display = g_display;
    ce.xclient.window = window_id;
    ce.xclient.format = 32;
    ce.xclient.data.l[0] = g_wm_delete_window_atom;
    ce.xclient.data.l[1] = CurrentTime;
    XSendEvent(g_display, window_id, False, NoEventMask, &ce);
    return 0;
}
Beispiel #22
0
int APP_CC
tc_thread_create(void * (* start_routine)(void *), void *arg)
{
    int rv = 0;
    pthread_t thread = (pthread_t)0;

    g_memset(&thread, 0x00, sizeof(pthread_t));

    /* pthread_create returns error */
    rv = pthread_create(&thread, 0, start_routine, arg);

    if (!rv)
    {
        rv = pthread_detach(thread);
    }

    return rv;
}
Beispiel #23
0
/* returns error
   send a list of channels to the channel handler */
static int APP_CC
xrdp_mm_trans_send_channel_setup(struct xrdp_mm* self, struct trans* trans)
{
  int index = 0;
  int chan_id = 0;
  int chan_flags = 0;
  int size = 0;
  struct stream* s = (struct stream *)NULL;
  char chan_name[256];

  g_memset(chan_name,0,sizeof(char) * 256);

  s = trans_get_out_s(trans, 8192);
  if (s == 0)
  {
    return 1;
  }
  s_push_layer(s, iso_hdr, 8);
  s_push_layer(s, mcs_hdr, 8);
  s_push_layer(s, sec_hdr, 2);
  index = 0;
  while (libxrdp_query_channel(self->wm->session, index, chan_name,
                               &chan_flags) == 0)
  {
    chan_id = libxrdp_get_channel_id(self->wm->session, chan_name);
    out_uint8a(s, chan_name, 8);
    out_uint16_le(s, chan_id);
    out_uint16_le(s, chan_flags);
    index++;
  }
  s_mark_end(s);
  s_pop_layer(s, sec_hdr);
  out_uint16_le(s, index);
  s_pop_layer(s, mcs_hdr);
  size = (int)(s->end - s->p);
  out_uint32_le(s, 3); /* msg id */
  out_uint32_le(s, size); /* msg size */
  s_pop_layer(s, iso_hdr);
  size = (int)(s->end - s->p);
  out_uint32_le(s, 0); /* version */
  out_uint32_le(s, size); /* block size */
  return trans_force_write(trans);
}
Beispiel #24
0
MIBool mCCooking::WriteCookedMesh( mCIOStreamBinary & a_streamDest, mCMesh a_meshSource, MIBool a_bConvex )
{
    if ( !s_pCooking || !s_pPhysicsSDK )
        return MIFalse;
    mTArray< MIU16 > arrMatIDs( 1, a_meshSource.GetNumFaces() );
    NxTriangleMeshDesc_Dummy Desc;
    g_memset( &Desc, 0, sizeof( Desc ) );
    Desc.numTriangles = a_meshSource.GetNumFaces();
    Desc.numVertices = a_meshSource.GetNumVerts();
    Desc.points = a_meshSource.GetVerts();
    Desc.pointStrideBytes = sizeof( *a_meshSource.GetVerts() );
    Desc.triangles = a_meshSource.GetFaces();
    Desc.triangleStrideBytes = sizeof( *a_meshSource.GetFaces() );
    Desc.materialIndices = arrMatIDs.GetBuffer();
    Desc.materialIndexStride = sizeof( arrMatIDs[ 0 ] );
    Desc.flags = a_bConvex ? 1 << 2 : 0;  // NX_CF_COMPUTE_CONVEX
    Desc.heightFieldVerticalAxis = 0xFF;  // NX_NOT_HEIGHTFIELD
    Desc.convexEdgeThreshold = 0.001f;
    CPhysicsStream streamDest( a_streamDest );
    return a_bConvex ? s_pCooking->NxCookConvexMesh( Desc, streamDest ) : s_pCooking->NxCookTriangleMesh( Desc, streamDest );
}
Beispiel #25
0
static int APP_CC
read_ini(void)
{
    char filename[256];
    struct list *names;
    struct list *values;
    char *name;
    char *value;
    int index;

    g_memset(filename, 0, (sizeof(char) * 256));
    names = list_create();
    names->auto_free = 1;
    values = list_create();
    values->auto_free = 1;
    g_use_unix_socket = 0;
    g_snprintf(filename, 255, "%s/sesman.ini", XRDP_CFG_PATH);

    if (file_by_name_read_section(filename, "Globals", names, values) == 0)
    {
        for (index = 0; index < names->count; index++)
        {
            name = (char *)list_get_item(names, index);
            value = (char *)list_get_item(values, index);

            if (g_strcasecmp(name, "ListenAddress") == 0)
            {
                if (g_strcasecmp(value, "127.0.0.1") == 0)
                {
                    g_use_unix_socket = 1;
                }
            }
        }
    }

    list_delete(names);
    list_delete(values);
    return 0;
}
Beispiel #26
0
Datei: env.c Projekt: cuzz/xrdp
int DEFAULT_CC
env_check_password_file(char* filename, char* password)
{
  char encryptedPasswd[16];
  int fd;

  g_memset(encryptedPasswd, 0, 16);
  g_strncpy(encryptedPasswd, password, 8);
  rfbDesKey(g_fixedkey, 0);
  rfbDes((unsigned char*)encryptedPasswd, (unsigned char*)encryptedPasswd);
  fd = g_file_open(filename);
  if (fd == -1)
  {
    log_message(&(g_cfg->log), LOG_LEVEL_WARNING,
                "can't read vnc password file - %s",
                filename);
    return 1;
  }
  g_file_write(fd, encryptedPasswd, 8);
  g_file_close(fd);
  return 0;
}
Beispiel #27
0
void APP_CC
scard_device_announce(tui32 device_id)
{
    IRP *irp;

    log_debug("entered: device_id=%d", device_id);

    if (!g_smartcards_inited)
    {
        g_memset(&smartcards, 0, sizeof(smartcards));
        g_smartcards_inited = 1;
    }

    if ((irp = devredir_irp_new()) == NULL)
    {
        log_error("system out of memory");
        return;
    }

    irp->scard_index = scard_add_new_device(device_id);
    if (irp->scard_index < 0)
    {
        log_debug("NOT adding smartcard with DeviceId=%d to list", device_id);
        devredir_irp_delete(irp);
        return;
    }

    log_debug("added smartcard with DeviceId=%d to list", device_id);

    irp->CompletionId = g_completion_id++;
    irp->DeviceId = device_id;
    irp->callback = scard_handle_EstablishContext_Return;

    scard_send_EstablishContext(irp);
    log_debug("leaving");
}
Beispiel #28
0
/* returns 0, event handled, 1 unhandled */
int APP_CC
rail_xevent(void *xevent)
{
    XEvent *lxevent;
    XWindowChanges xwc;
    int rv;

    LOG(10, ("chansrv::rail_xevent:"));

    if (!g_rail_up)
    {
        return 1;
    }

    rv = 1;
    lxevent = (XEvent *)xevent;

    switch (lxevent->type)
    {
        case ConfigureRequest:
            LOG(10, ("  got ConfigureRequest window_id 0x%8.8x", lxevent->xconfigurerequest.window));
            g_memset(&xwc, 0, sizeof(xwc));
            xwc.x = lxevent->xconfigurerequest.x;
            xwc.y = lxevent->xconfigurerequest.y;
            xwc.width = lxevent->xconfigurerequest.width;
            xwc.height = lxevent->xconfigurerequest.height;
            xwc.border_width = lxevent->xconfigurerequest.border_width;
            xwc.sibling = lxevent->xconfigurerequest.above;
            xwc.stack_mode = lxevent->xconfigurerequest.detail;
            XConfigureWindow(g_display,
                             lxevent->xconfigurerequest.window,
                             lxevent->xconfigurerequest.value_mask,
                             &xwc);
            rv = 0;
            break;

        case MapRequest:
            LOG(10, ("  got MapRequest"));
            XMapWindow(g_display, lxevent->xmaprequest.window);
            rv = 0;
            break;

        case MapNotify:
            LOG(10, ("  got MapNotify"));
            break;

        case UnmapNotify:
            LOG(10, ("  got UnmapNotify"));
            break;

        case ConfigureNotify:
            LOG(10, ("  got ConfigureNotify"));
            break;

        case FocusIn:
            LOG(10, ("  got FocusIn"));
            break;

        case ButtonPress:
            LOG(10, ("  got ButtonPress"));
            break;

        case EnterNotify:
            LOG(10, ("  got EnterNotify"));
            break;

        case LeaveNotify:
            LOG(10, ("  got LeaveNotify"));
            break;

    }

    return rv;
}
Beispiel #29
0
static void DEFAULT_CC
session_start_sessvc(int xpid, int wmpid, long data, char *username, int display)
{
    struct list *sessvc_params = (struct list *)NULL;
    char wmpid_str[25];
    char xpid_str[25];
    char exe_path[262];
    int i = 0;

    /* initialize (zero out) local variables: */
    g_memset(wmpid_str, 0, sizeof(char) * 25);
    g_memset(xpid_str, 0, sizeof(char) * 25);
    g_memset(exe_path, 0, sizeof(char) * 262);

    /* new style waiting for clients */
    g_sprintf(wmpid_str, "%d", wmpid);
    g_sprintf(xpid_str, "%d",  xpid);
    log_message(LOG_LEVEL_INFO,
                "starting xrdp-sessvc - xpid=%s - wmpid=%s",
                xpid_str, wmpid_str);

    sessvc_params = list_create();
    sessvc_params->auto_free = 1;

    /* building parameters */
    g_snprintf(exe_path, 261, "%s/xrdp-sessvc", XRDP_SBIN_PATH);

    list_add_item(sessvc_params, (long)g_strdup(exe_path));
    list_add_item(sessvc_params, (long)g_strdup(xpid_str));
    list_add_item(sessvc_params, (long)g_strdup(wmpid_str));
    list_add_item(sessvc_params, 0); /* mandatory */

    env_set_user(username, 0, display);

    /* executing sessvc */
    g_execvp(exe_path, ((char **)sessvc_params->items));

    /* should not get here */
    log_message(LOG_LEVEL_ALWAYS,
                "error starting xrdp-sessvc - pid %d - xpid=%s - wmpid=%s",
                g_getpid(), xpid_str, wmpid_str);

    /* logging parameters */
    /* no problem calling strerror for thread safety: other threads
       are blocked */
    log_message(LOG_LEVEL_DEBUG, "errno: %d, description: %s",
                errno, g_get_strerror());
    log_message(LOG_LEVEL_DEBUG, "execve parameter list:");

    for (i = 0; i < (sessvc_params->count); i++)
    {
        log_message(LOG_LEVEL_DEBUG, "        argv[%d] = %s", i,
                    (char *)list_get_item(sessvc_params, i));
    }

    list_delete(sessvc_params);

    /* keep the old waitpid if some error occurs during execlp */
    g_waitpid(wmpid);
    g_sigterm(xpid);
    g_sigterm(wmpid);
    g_sleep(1000);
    auth_end(data);
    g_exit(0);
}
Beispiel #30
0
/* called with the main thread */
static int APP_CC
session_start_fork(int width, int height, int bpp, char *username,
                   char *password, tbus data, tui8 type, char *domain,
                   char *program, char *directory, char *client_ip)
{
    int display = 0;
    int pid = 0;
    int wmpid = 0;
    int xpid = 0;
    int i = 0;
    char geometry[32];
    char depth[32];
    char screen[32];
    char text[256];
    char passwd_file[256];
    char **pp1 = (char **)NULL;
    struct session_chain *temp = (struct session_chain *)NULL;
    struct list *xserver_params = (struct list *)NULL;
    time_t ltime;
    struct tm stime;
    char execvpparams[2048];

    /* initialize (zero out) local variables: */
    g_memset(&ltime, 0, sizeof(time_t));
    g_memset(&stime, 0, sizeof(struct tm));
    g_memset(geometry, 0, sizeof(char) * 32);
    g_memset(depth, 0, sizeof(char) * 32);
    g_memset(screen, 0, sizeof(char) * 32);
    g_memset(text, 0, sizeof(char) * 256);
    g_memset(passwd_file, 0, sizeof(char) * 256);

    /* check to limit concurrent sessions */
    if (g_session_count >= g_cfg->sess.max_sessions)
    {
        log_message(LOG_LEVEL_INFO, "max concurrent session limit "
                    "exceeded. login for user %s denied", username);
        return 0;
    }

    temp = (struct session_chain *)g_malloc(sizeof(struct session_chain), 0);

    if (temp == 0)
    {
        log_message(LOG_LEVEL_ERROR, "cannot create new chain "
                    "element - user %s", username);
        return 0;
    }

    temp->item = (struct session_item *)g_malloc(sizeof(struct session_item), 0);

    if (temp->item == 0)
    {
        g_free(temp);
        log_message(LOG_LEVEL_ERROR, "cannot create new session "
                    "item - user %s", username);
        return 0;
    }

    display = session_get_aval_display_from_chain();

    if (display == 0)
    {
        g_free(temp->item);
        g_free(temp);
        return 0;
    }

    pid = g_fork();

    if (pid == -1)
    {
    }
    else if (pid == 0) /* child sesman */
    {
        g_tcp_close(g_sck);
        g_tcp_close(g_thread_sck);
        auth_start_session(data, display);
        g_sprintf(geometry, "%dx%d", width, height);
        g_sprintf(depth, "%d", bpp);
        g_sprintf(screen, ":%d", display);
        wmpid = g_fork();

        if (wmpid == -1)
        {
        }
        else if (wmpid == 0) /* child (child sesman) xserver */
        {
            wait_for_xserver(display);
            env_set_user(username, 0, display);

            if (x_server_running(display))
            {
                auth_set_env(data);

                if (directory != 0)
                {
                    if (directory[0] != 0)
                    {
                        g_set_current_dir(directory);
                    }
                }

                if (program != 0)
                {
                    if (program[0] != 0)
                    {
                        g_execlp3(program, program, 0);
                        log_message(LOG_LEVEL_ALWAYS,
                                    "error starting program %s for user %s - pid %d",
                                    program, username, g_getpid());
                    }
                }

                /* try to execute user window manager if enabled */
                if (g_cfg->enable_user_wm)
                {
                    g_sprintf(text, "%s/%s", g_getenv("HOME"), g_cfg->user_wm);

                    if (g_file_exist(text))
                    {
                        g_execlp3(text, g_cfg->user_wm, 0);
                        log_message(LOG_LEVEL_ALWAYS, "error starting user "
                                    "wm for user %s - pid %d", username, g_getpid());
                        /* logging parameters */
                        log_message(LOG_LEVEL_DEBUG, "errno: %d, "
                                    "description: %s", errno, g_get_strerror());
                        log_message(LOG_LEVEL_DEBUG, "execlp3 parameter "
                                    "list:");
                        log_message(LOG_LEVEL_DEBUG, "        argv[0] = %s",
                                    text);
                        log_message(LOG_LEVEL_DEBUG, "        argv[1] = %s",
                                    g_cfg->user_wm);
                    }
                }

                /* if we're here something happened to g_execlp3
                   so we try running the default window manager */
                g_sprintf(text, "%s/%s", XRDP_CFG_PATH, g_cfg->default_wm);
                g_execlp3(text, g_cfg->default_wm, 0);

                log_message( LOG_LEVEL_ALWAYS, "error starting default "
                             "wm for user %s - pid %d", username, g_getpid());
                /* logging parameters */
                log_message( LOG_LEVEL_DEBUG, "errno: %d, description: "
                             "%s", errno, g_get_strerror());
                log_message(LOG_LEVEL_DEBUG, "execlp3 parameter list:");
                log_message(LOG_LEVEL_DEBUG, "        argv[0] = %s",
                            text);
                log_message(LOG_LEVEL_DEBUG, "        argv[1] = %s",
                            g_cfg->default_wm);

                /* still a problem starting window manager just start xterm */
                g_execlp3("xterm", "xterm", 0);

                /* should not get here */
                log_message(LOG_LEVEL_ALWAYS, "error starting xterm "
                            "for user %s - pid %d", username, g_getpid());
                /* logging parameters */
                log_message(LOG_LEVEL_DEBUG, "errno: %d, description: "
                            "%s", errno, g_get_strerror());
            }
            else
            {
                log_message(LOG_LEVEL_ERROR, "another Xserver might "
                            "already be active on display %d - see log", display);
            }

            log_message(LOG_LEVEL_DEBUG, "aborting connection...");
            g_exit(0);
        }
        else /* parent (child sesman) */
        {
            xpid = g_fork();

            if (xpid == -1)
            {
            }
            else if (xpid == 0) /* child */
            {
                env_set_user(username, passwd_file, display);
                env_check_password_file(passwd_file, password);

                if (type == SESMAN_SESSION_TYPE_XVNC)
                {
                    xserver_params = list_create();
                    xserver_params->auto_free = 1;
                    /* these are the must have parameters */
                    list_add_item(xserver_params, (long)g_strdup("Xvnc"));
                    list_add_item(xserver_params, (long)g_strdup(screen));
                    list_add_item(xserver_params, (long)g_strdup("-geometry"));
                    list_add_item(xserver_params, (long)g_strdup(geometry));
                    list_add_item(xserver_params, (long)g_strdup("-depth"));
                    list_add_item(xserver_params, (long)g_strdup(depth));
                    list_add_item(xserver_params, (long)g_strdup("-rfbauth"));
                    list_add_item(xserver_params, (long)g_strdup(passwd_file));

                    /* additional parameters from sesman.ini file */
                    //config_read_xserver_params(SESMAN_SESSION_TYPE_XVNC,
                    //                           xserver_params);
                    list_append_list_strdup(g_cfg->vnc_params, xserver_params, 0);

                    /* make sure it ends with a zero */
                    list_add_item(xserver_params, 0);
                    pp1 = (char **)xserver_params->items;
                    log_message(LOG_LEVEL_INFO, "Xvnc start:%s", dumpItemsToString(xserver_params, execvpparams, 2048));
                    g_execvp("Xvnc", pp1);
                }
                else if (type == SESMAN_SESSION_TYPE_XRDP)
                {
                    xserver_params = list_create();
                    xserver_params->auto_free = 1;
                    /* these are the must have parameters */
                    list_add_item(xserver_params, (long)g_strdup("X11rdp"));
                    list_add_item(xserver_params, (long)g_strdup(screen));
                    list_add_item(xserver_params, (long)g_strdup("-geometry"));
                    list_add_item(xserver_params, (long)g_strdup(geometry));
                    list_add_item(xserver_params, (long)g_strdup("-depth"));
                    list_add_item(xserver_params, (long)g_strdup(depth));

                    /* additional parameters from sesman.ini file */
                    //config_read_xserver_params(SESMAN_SESSION_TYPE_XRDP,
                    //                           xserver_params);
                    list_append_list_strdup(g_cfg->rdp_params, xserver_params, 0);

                    /* make sure it ends with a zero */
                    list_add_item(xserver_params, 0);
                    pp1 = (char **)xserver_params->items;
                    log_message(LOG_LEVEL_INFO, "X11rdp start:%s", dumpItemsToString(xserver_params, execvpparams, 2048));
                    g_execvp("X11rdp", pp1);
                }
                else
                {
                    log_message(LOG_LEVEL_ALWAYS, "bad session type - "
                                "user %s - pid %d", username, g_getpid());
                    g_exit(1);
                }

                /* should not get here */
                log_message(LOG_LEVEL_ALWAYS, "error starting X server "
                            "- user %s - pid %d", username, g_getpid());

                /* logging parameters */
                log_message(LOG_LEVEL_DEBUG, "errno: %d, description: "
                            "%s", errno, g_get_strerror());
                log_message(LOG_LEVEL_DEBUG, "execve parameter list size: "
                            "%d", (xserver_params)->count);

                for (i = 0; i < (xserver_params->count); i++)
                {
                    log_message(LOG_LEVEL_DEBUG, "        argv[%d] = %s",
                                i, (char *)list_get_item(xserver_params, i));
                }

                list_delete(xserver_params);
                g_exit(1);
            }
            else /* parent (child sesman)*/
            {
                wait_for_xserver(display);
                g_snprintf(text, 255, "%d", display);
                g_setenv("XRDP_SESSVC_DISPLAY", text, 1);
                g_snprintf(text, 255, ":%d.0", display);
                g_setenv("DISPLAY", text, 1);
                /* new style waiting for clients */
                session_start_sessvc(xpid, wmpid, data, username, display);
            }
        }
    }
    else /* parent sesman process */
    {
        temp->item->pid = pid;
        temp->item->display = display;
        temp->item->width = width;
        temp->item->height = height;
        temp->item->bpp = bpp;
        temp->item->data = data;
        g_strncpy(temp->item->client_ip, client_ip, 255);   /* store client ip data */
        g_strncpy(temp->item->name, username, 255);

        ltime = g_time1();
        localtime_r(&ltime, &stime);
        temp->item->connect_time.year = (tui16)(stime.tm_year + 1900);
        temp->item->connect_time.month = (tui8)stime.tm_mon;
        temp->item->connect_time.day = (tui8)stime.tm_mday;
        temp->item->connect_time.hour = (tui8)stime.tm_hour;
        temp->item->connect_time.minute = (tui8)stime.tm_min;
        zero_time(&(temp->item->disconnect_time));
        zero_time(&(temp->item->idle_time));

        temp->item->type = type;
        temp->item->status = SESMAN_SESSION_STATUS_ACTIVE;

        temp->next = g_sessions;
        g_sessions = temp;
        g_session_count++;
    }

    return display;
}