Пример #1
0
/* 004 */
enum SCP_CLIENT_STATES_E
scp_v1c_resend_credentials(struct SCP_CONNECTION *c, struct SCP_SESSION *s)
{
    tui8 sz;
    tui32 size;

    init_stream(c->out_s, c->out_s->size);
    init_stream(c->in_s, c->in_s->size);

    size = 12 + 2 + g_strlen(s->username) + g_strlen(s->password);

    /* sending request */
    /* header */
    out_uint32_be(c->out_s, 1); /* version */
    out_uint32_be(c->out_s, size);
    out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT);
    out_uint16_be(c->out_s, 4);

    /* body */
    sz = g_strlen(s->username);
    out_uint8(c->out_s, sz);
    out_uint8p(c->out_s, s->username, sz);
    sz = g_strlen(s->password);
    out_uint8(c->out_s, sz);
    out_uint8p(c->out_s, s->password, sz);

    if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, size))
    {
        return SCP_CLIENT_STATE_NETWORK_ERR;
    }

    /* wait for response */
    return _scp_v1c_check_response(c, s);
}
Пример #2
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;
}
Пример #3
0
/* return exit status of the mount command*/
void disk_umount (t_disk * pdisk, char* umount_command)
{
	if (pdisk != NULL)
	{
		char * cmd ;
		char *a;
		char *b;
char *str = g_strdup(umount_command);
if (!g_strchr(str,'$')) {
		g_free(str);
		cmd = g_strconcat ("bash -c '", umount_command, " ", 
		                   pdisk->mount_point, "'", NULL);
} else {
int i;
i = g_strlen(str) - g_strlen(g_strchr(str,'$'));

str[i]='\0';
a=g_strdup(str);
str[i]='$';
b=g_strdup(g_strchr(str,'$')+1);
g_free(str);
		cmd = g_strconcat ("bash -c '", a, pdisk->mount_point, b, "'", NULL);
g_free(a); g_free(b);
}


/*      #ifdef DEBUG
         g_printf("umount command: %s \n", umount_command);
      #endif */

		/* changed from pdisk->device to pdisk->mount_point */
/*		cmd = g_strconcat (umount_command, " ", pdisk->mount_point, NULL); */
		
		/*bresult = g_spawn_command_line_sync(cmd,&standard_output,&standard_error,&exit_status,&error);
		if (bresult)
		{
			if (exit_status) 
			{
				mount_info_free(&(pdisk->mount_info));
			}
			
			return exit_status ;
		}
		*/
/*		exec_cmd_silent (cmd, FALSE, FALSE);
*/
/*		ERR("exec-um-cmd %s \n", cmd);*/
		g_spawn_command_line_async(cmd, NULL);
		g_free(cmd);
	}
	//return -1 ;
}
Пример #4
0
static int g_strcmp(char *stra, char *strb)
{
int ia; int ib; int i;
if ((stra == NULL) || (strb == NULL)) return -1;
ia = g_strlen(stra);
ib = g_strlen(strb);
if (ia != ib) return -1;
	for(i=0;i < ia;i++)
	{
		if (stra[i] != strb[i]) return -1;
	}
	return 1;
}
Пример #5
0
mEResult mCFileStream::Read( mCString & a_strDest )
{
    // Note: m_arrBuffer (a mCCharArray) is guaranteed to be 0-terminated.
    if ( !( m_enuOpenMode & mEFileOpenMode_Read ) )
    {
        MI_ERROR( mCStreamError, EFileNotOpen, "File is not open for reading operations." );
        return mEResult_False;
    }
    if ( Tell() == GetSize() )
    {
        MI_ERROR( mCStreamError, ESizeExceeded, "File size exceeded when reading binary data." );
        return mEResult_False;
    }
    MILPCChar const pcText = m_arrBuffer.GetBuffer() + m_uOffset;
    MIUInt const uSize = static_cast< MIUInt >( g_strlen( pcText ) );
    a_strDest.SetText( pcText, uSize );
    m_uOffset += uSize;
    if ( m_uOffset == m_arrBuffer.GetCount() )
    {
        if ( Tell() == GetSize() )
            return mEResult_Ok;
        Buffer( Tell() );
        mCString strTemp;
        Read( strTemp );
        a_strDest.Append( strTemp );
    }
    else
    {
        m_uOffset += 1;
    }
    return mEResult_Ok;
}
Пример #6
0
/* --------------- disks_refresh ----------------------*/
void procinf(GPtrArray * pdisks)
{
  FILE *partitions;
  char dev[256];
  char bdev[256];
  char *s; char *w; char *z; char *r; char *b;
  int i; int j; int ia = pdisks->len;
	t_disk * pdisk;
	t_disk * ddisk;
  r = g_strno(rtdisk(pdisks));
  b = g_strno(rbdisk(pdisks)); 
  partitions = fopen ("/proc/partitions", "r");
  if (partitions == NULL) {return;}
  while (getc (partitions) != '\n');    /* skip header */
  while (fscanf (partitions, "%s%s%s%s\n", dev, dev, bdev, dev) != EOF)
    { 
          s = g_strdup(dev);
          w = g_strdup(bdev);
          z = g_strconcat("/dev/", s, NULL);
if ((g_strlen(w) == 1) && ((g_strchr(w, '1') != NULL) || (g_strchr(w, '0') != NULL))) continue;
          pdisk = disk_new(z, s);
          pdisk->is_new = TRUE;
          g_ptr_array_add( pdisks , pdisk );
    }

  fclose (partitions);

	for(i=ia;i < pdisks->len;i++)
	{
		pdisk = g_ptr_array_index(pdisks,i);
		
		if (g_strcmp(g_strno(pdisk->device), r) == 1){
			pdisk->is_hide = TRUE;
		}
		if (g_strcmp(g_strno(pdisk->device), b) == 1){
			pdisk->is_hide = TRUE;
		}
		for(j=ia;j < pdisks->len;j++)
		{
			if (i == j) continue;
			ddisk = g_ptr_array_index(pdisks, j);
			if (g_strcmp(g_strno(pdisk->device), ddisk->device) == 1){
				ddisk->mount_point = NULL;
				ddisk->is_hide = TRUE;
//				g_print("found! %s %s\n", ddisk->device ,ddisk->mount_point);
			}
		}
		for(j=0;j < ia;j++)
		{
			if (i == j) continue;
			ddisk = g_ptr_array_index(pdisks, j);
			if (g_strcmp(pdisk->device, ddisk->device) == 1){
				pdisk->mount_point = NULL;
				pdisk->is_hide = TRUE;
//				g_print("found! %s %s\n", pdisk->device ,pdisk->mount_point);
			}
		}
	}

}
Пример #7
0
/* returns error */
static int
xrdp_orders_send_as_unicode(struct stream *s, const char *text)
{
    int str_chars;
    int index;
    int i32;
    int len;
    twchar *wdst;

    len = g_strlen(text) + 1;

    wdst = (twchar *) g_malloc(sizeof(twchar) * len, 1);
    if (wdst == 0)
    {
        return 1;
    }
    str_chars = g_mbstowcs(wdst, text, len);
    if (str_chars > 0)
    {
        i32 = str_chars * 2;
        out_uint16_le(s, i32);
        for (index = 0; index < str_chars; index++)
        {
            i32 = wdst[index];
            out_uint16_le(s, i32);
        }
    }
    else
    {
        out_uint16_le(s, 0);
    }
    g_free(wdst);
    return 0;
}
Пример #8
0
enum SCP_SERVER_STATES_E
scp_v1s_deny_connection(struct SCP_CONNECTION* c, char* reason)
{
  int rlen;

  init_stream(c->out_s,c->out_s->size);

  /* forcing message not to exceed 64k */
  rlen = g_strlen(reason);
  if (rlen > 65535)
  {
    rlen = 65535;
  }

  out_uint32_be(c->out_s, 1);
  /* packet size: 4 + 4 + 2 + 2 + 2 + strlen(reason)*/
  /* version + size + cmdset + cmd + msglen + msg */
  out_uint32_be(c->out_s, rlen+14);
  out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT);
  out_uint16_be(c->out_s, 2);
  out_uint16_be(c->out_s, rlen);
  out_uint8p(c->out_s, reason, rlen);

  if (0!=scp_tcp_force_send(c->in_sck, c->out_s->data, rlen+14))
  {
    log_message(LOG_LEVEL_WARNING, "[v1s:%d] connection aborted: network error", __LINE__);
    return SCP_SERVER_STATE_NETWORK_ERR;
  }

  return SCP_SERVER_STATE_END;
}
Пример #9
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);
    }
}
Пример #10
0
static char*
share_convert_path(char* path)
{
	char* buffer = NULL;
	int i = 0;
	int buffer_len = 0;
	int path_len = 0;
	unsigned char c = 0;
	char* t = 0;

	path_len = g_strlen(path);
	buffer_len = path_len * 3 + 1;
	buffer = g_malloc(buffer_len, 1);

	t = buffer;

	/* copy the path component name */
	for (i = 0 ; i< path_len ; i++)
	{
		c = path[i];
		if (!ACCEPTABLE_URI_CHAR (c) && (c != '\n'))
		{
			*t++ = '%';
			*t++ = HEX_CHARS[c >> 4];
			*t++ = HEX_CHARS[c & 15];
		}
		else
		{
Пример #11
0
/* 003 */
enum SCP_SERVER_STATES_E
scp_v1s_mng_deny_connection(struct SCP_CONNECTION *c, char *reason)
{
    int rlen;

    init_stream(c->out_s, c->out_s->size);

    /* forcing message not to exceed 64k */
    rlen = g_strlen(reason);

    if (rlen > 65535)
    {
        rlen = 65535;
    }

    out_uint32_be(c->out_s, 1);
    /* packet size: 4 + 4 + 2 + 2 + 2 + strlen(reason)*/
    /* version + size + cmdset + cmd + msglen + msg */
    out_uint32_be(c->out_s, rlen + 14);
    out_uint16_be(c->out_s, SCP_COMMAND_SET_MANAGE);
    out_uint16_be(c->out_s, SCP_CMD_MNG_LOGIN_DENY);
    out_uint16_be(c->out_s, rlen);
    out_uint8p(c->out_s, reason, rlen);

    if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, rlen + 14))
    {
        return SCP_SERVER_STATE_NETWORK_ERR;
    }

    return SCP_SERVER_STATE_END;
}
Пример #12
0
int APP_CC
dev_redir_client_name(struct stream* s)
{
  log_message(&log_conf, LOG_LEVEL_DEBUG, "rdpdr channel[dev_redir_data_in]: new message: PAKID_CORE_CLIENT_NAME");
  int hostname_size;
  in_uint32_le(s, use_unicode);
  in_uint32_le(s, hostname_size);   /* flag not use */
  in_uint32_le(s, hostname_size);
  if (hostname_size < 1)
  {
    log_message(&log_conf, LOG_LEVEL_ERROR, "rdpdr channel[dev_redir_data_in]: no hostname specified");
    return 1;
  }
  if (use_unicode == 1)
  {
    log_message(&log_conf, LOG_LEVEL_DEBUG, "rdpdr channel[dev_redir_data_in]: unicode is used");
    in_unistr(s, hostname, sizeof(hostname), hostname_size);
  }
  else
  {
    in_uint8a(s, hostname, hostname_size);
  }
  log_message(&log_conf, LOG_LEVEL_DEBUG, "rdpdr channel[dev_redir_data_in]: hostname : '%s'",hostname);
  if (g_strlen(hostname) >0)
  {
    dev_redir_confirm_clientID_request();
  }
  return 0;
}
Пример #13
0
/* if in = 0, return 0 else return newly alloced copy of input string
 * if the input string is larger than maxlen the returned string will be
 * truncated. All strings returned will include null termination*/
char* g_strndup(const char *in, const unsigned int maxlen)
{
	int len;
	char *p;

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

	len = g_strlen(in);

	if (len > maxlen)
	{
		len = maxlen - 1;
	}

	p = (char *) g_malloc(len + 2, 0);

	if (p != NULL)
	{
		g_strncpy(p, in, len + 1);
	}

	return p;
}
Пример #14
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 ;
}
Пример #15
0
/* return exit status of the mount command*/
void disk_mount (t_disk * pdisk, char* mount_command)
{
	if (pdisk != NULL)
	{
		char * cmd ;
		char *a;
		char *b;
char *str = g_strdup(mount_command);
if (!g_strchr(str,'$')) {
		g_free(str);
		cmd = g_strconcat ("bash -c '", mount_command, " ", 
		                   pdisk->mount_point, "'", NULL);
} else {
int i;
i = g_strlen(str) - g_strlen(g_strchr(str,'$'));

str[i]='\0';
a=g_strdup(str);
str[i]='$';
b=g_strdup(g_strchr(str,'$')+1);
g_free(str);
		cmd = g_strconcat ("bash -c '", a, pdisk->mount_point, b, "'", NULL);
g_free(a); g_free(b);
}

/*		cmd = g_strconcat ("bash -c '", mount_command, " ", 
		                   pdisk->mount_point, NULL);
		                   
		if (on_mount_cmd != NULL)
			cmd = g_strconcat(cmd," && ",on_mount_cmd," ", pdisk->mount_point, " ' ", NULL);
		else
			cmd = g_strconcat(cmd," ' ",NULL);
			
		DBG("cmd :%s",cmd); */
		
/*		exec_cmd_silent(cmd,FALSE,FALSE);
*/
/*		ERR("exec-mo-cmd %s \n", cmd); */
		g_spawn_command_line_async(cmd, NULL);
		g_free(cmd);
	}
}
Пример #16
0
char * rtdisk(GPtrArray * pdisks){
	int i;t_disk * pdisk;
	for(i=0;i < pdisks->len;i++)
	{
		pdisk = g_ptr_array_index(pdisks,i);
if ((g_strlen(pdisk->mount_point) == 1) && (g_strchr(pdisk->mount_point, '/') != NULL)) {// || (g_strcmp(pdisk->mount_point, "/boot")))) {
//g_print("lol %s \n", pdisk->mount_point);
	pdisk->is_hide = TRUE;
	return pdisk->device;
  }
  }
	return NULL;
}
Пример #17
0
/* if in = 0, return 0 else return newly alloced copy of in */
char* APP_CC
g_strdup(const char* in)
{
    int len;
    char* p;

    if (in == 0)
    {
        return 0;
    }
    len = g_strlen(in);
    p = (char*)g_malloc(len + 1, 0);
    g_strcpy(p, in);
    return p;
}
Пример #18
0
Файл: env.c Проект: 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;
}
Пример #19
0
/* if in = 0, return 0 else return newly alloced copy of in */
char* g_strdup(const char *in)
{
	int len;
	char *p;

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

	len = g_strlen(in);
	p = (char *) g_malloc(len + 1, 0);

	if (p != NULL)
	{
		g_strcpy(p, in);
	}

	return p;
}
Пример #20
0
/* returns error */
static int APP_CC
file_split_name_value(char* text, char* name, char* value)
{
  int len;
  int i;
  int value_index;
  int name_index;
  int on_to;

  value_index = 0;
  name_index = 0;
  on_to = 0;
  name[0] = 0;
  value[0] = 0;
  len = g_strlen(text);
  for (i = 0; i < len; i++)
  {
    if (text[i] == '=' && on_to == 0)
    {
      on_to = 1;
    }
    else if (on_to)
    {
    	if(text[i] != '"')
    	{
				value[value_index] = text[i];
				value_index++;
				value[value_index] = 0;
    	}
    }
    else
    {
      name[name_index] = text[i];
      name_index++;
      name[name_index] = 0;
    }
  }
  g_strtrim(name, 3); /* trim both right and left */
  g_strtrim(value, 3); /* trim both right and left */
  return 0;
}
Пример #21
0
static int APP_CC
rail_process_exec(struct stream *s, int size)
{
    int flags;
    int ExeOrFileLength;
    int WorkingDirLength;
    int ArgumentsLen;
    char *ExeOrFile;
    char *WorkingDir;
    char *Arguments;

    LOG(0, ("chansrv::rail_process_exec:"));
    in_uint16_le(s, flags);
    in_uint16_le(s, ExeOrFileLength);
    in_uint16_le(s, WorkingDirLength);
    in_uint16_le(s, ArgumentsLen);
    ExeOrFile = read_uni(s, ExeOrFileLength);
    WorkingDir = read_uni(s, WorkingDirLength);
    Arguments = read_uni(s, ArgumentsLen);
    LOG(10, ("  flags 0x%8.8x ExeOrFileLength %d WorkingDirLength %d "
             "ArgumentsLen %d ExeOrFile [%s] WorkingDir [%s] "
             "Arguments [%s]", flags, ExeOrFileLength, WorkingDirLength,
             ArgumentsLen, ExeOrFile, WorkingDir, Arguments));

    if (g_strlen(ExeOrFile) > 0)
    {
        LOG(10, ("rail_process_exec: pre"));
        /* ask main thread to fork */
        tc_mutex_lock(g_exec_mutex);
        g_exec_name = ExeOrFile;
        g_set_wait_obj(g_exec_event);
        tc_sem_dec(g_exec_sem);
        tc_mutex_unlock(g_exec_mutex);
        LOG(10, ("rail_process_exec: post"));
    }

    g_free(ExeOrFile);
    g_free(WorkingDir);
    g_free(Arguments);
    return 0;
}
Пример #22
0
/* 032 */
enum SCP_SERVER_STATES_E
scp_v1s_connection_error(struct SCP_CONNECTION* c, char* error)
{
  tui16 len;

  len = g_strlen(error);
  init_stream(c->out_s,c->out_s->size);

  out_uint32_be(c->out_s, 1);
  /* packet size: 4 + 4 + 2 + 2 + len */
  /* version + size + cmdset + cmd */
  out_uint32_be(c->out_s, (12 + len));
  out_uint16_be(c->out_s, SCP_COMMAND_SET_DEFAULT);
  out_uint16_be(c->out_s, SCP_CMD_CONN_ERROR);

  if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, (12 + len)))
  {
    return SCP_SERVER_STATE_NETWORK_ERR;
  }

  return SCP_SERVER_STATE_END;
}
Пример #23
0
/* 001 */
enum SCP_CLIENT_STATES_E
scp_v1c_mng_connect(struct SCP_CONNECTION *c, struct SCP_SESSION *s)
{
	tui8 sz;
	tui32 size;

	init_stream(c->out_s, c->out_s->size);
	init_stream(c->in_s, c->in_s->size);

	size = 12 + 4 + g_strlen(s->hostname) + g_strlen(s->username) +
			g_strlen(s->password);

	if (s->addr_type == SCP_ADDRESS_TYPE_IPV4)
	{
		size = size + 4;
	}
	else
	{
		size = size + 16;
	}

	/* sending request */

	/* header */
	out_uint32_be(c->out_s, 1); /* version */
	out_uint32_be(c->out_s, size);
	out_uint16_be(c->out_s, SCP_COMMAND_SET_MANAGE);
	out_uint16_be(c->out_s, SCP_CMD_MNG_LOGIN);

	/* data */
	sz = g_strlen(s->username);
	out_uint8(c->out_s, sz);
	out_uint8p(c->out_s, s->username, sz);
	sz = g_strlen(s->password);
	out_uint8(c->out_s, sz);
	out_uint8p(c->out_s, s->password, sz);

	/* address */
	out_uint8(c->out_s, s->addr_type);

	if (s->addr_type == SCP_ADDRESS_TYPE_IPV4)
	{
		out_uint32_be(c->out_s, s->ipv4addr);
	}
	else
	{
		out_uint8p(c->out_s, s->ipv6addr, 16);
	}

	/* hostname */
	sz = g_strlen(s->hostname);
	out_uint8(c->out_s, sz);
	out_uint8p(c->out_s, s->hostname, sz);

	if (0 != scp_tcp_force_send(c->in_sck, c->out_s->data, size))
	{
		log_message(LOG_LEVEL_WARNING, "[v1c_mng:%d] connection aborted: network error", __LINE__);
		return SCP_CLIENT_STATE_NETWORK_ERR;
	}

	/* wait for response */
	return _scp_v1c_mng_check_response(c, s);
}
Пример #24
0
int
cliprdr_init()
{
  char filename[256];
  struct list* names;
  struct list* values;
  char* name;
  char* value;
  int index;
  int display_num;

  display_num = g_get_display_num_from_display(g_strdup(g_getenv("DISPLAY")));
	if(display_num == 0)
	{
		g_printf("cliprdr[cliprdr_init]: Display must be different of 0\n");
		return ERROR;
	}
	l_config = g_malloc(sizeof(struct log_config), 1);
	l_config->program_name = "cliprdr";
	l_config->log_file = 0;
	l_config->fd = 0;
	l_config->log_level = LOG_LEVEL_DEBUG;
	l_config->enable_syslog = 0;
	l_config->syslog_level = LOG_LEVEL_DEBUG;

  names = list_create();
  names->auto_free = 1;
  values = list_create();
  values->auto_free = 1;
  g_snprintf(filename, 255, "%s/cliprdr.conf", XRDP_CFG_PATH);
  if (file_by_name_read_section(filename, CLIPRDR_CFG_GLOBAL, 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 (0 == g_strcasecmp(name, CLIPRDR_CFG_NAME))
      {
        if( g_strlen(value) > 1)
        {
        	l_config->program_name = (char*)g_strdup(value);
        }
      }
    }
  }
  if (file_by_name_read_section(filename, CLIPRDR_CFG_LOGGING, 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 (0 == g_strcasecmp(name, CLIPRDR_CFG_LOG_LEVEL))
      {
      	l_config->log_level = log_text2level(value);
      }
    }
  }
  list_delete(names);
  list_delete(values);

	if(log_start(l_config) != LOG_STARTUP_OK)
	{
		g_printf("vchannel[vchannel_init]: Unable to start log system\n");
		return ERROR;
	}
  else
  {
  	return LOG_STARTUP_OK;
  }
  return 0;
}
Пример #25
0
static int
xrdp_rdp_read_config(struct xrdp_client_info *client_info)
{
    int index = 0;
    struct list *items = (struct list *)NULL;
    struct list *values = (struct list *)NULL;
    char *item = NULL;
    char *value = NULL;
    char cfg_file[256];
    int pos;
    char *tmp = NULL;
    int tmp_length = 0;

    /* initialize (zero out) local variables: */
    g_memset(cfg_file, 0, sizeof(char) * 256);

    items = list_create();
    items->auto_free = 1;
    values = list_create();
    values->auto_free = 1;
    g_snprintf(cfg_file, 255, "%s/xrdp.ini", XRDP_CFG_PATH);
    DEBUG(("cfg_file %s", cfg_file));
    file_by_name_read_section(cfg_file, "globals", items, values);

    for (index = 0; index < items->count; index++)
    {
        item = (char *)list_get_item(items, index);
        value = (char *)list_get_item(values, index);
        DEBUG(("item %s value %s", item, value));

        if (g_strcasecmp(item, "bitmap_cache") == 0)
        {
            client_info->use_bitmap_cache = g_text2bool(value);
        }
        else if (g_strcasecmp(item, "bitmap_compression") == 0)
        {
            client_info->use_bitmap_comp = g_text2bool(value);
        }
        else if (g_strcasecmp(item, "bulk_compression") == 0)
        {
            client_info->use_bulk_comp = g_text2bool(value);
        }
        else if (g_strcasecmp(item, "crypt_level") == 0)
        {
            if (g_strcasecmp(value, "none") == 0)
            {
                client_info->crypt_level = 0;
            }
            else if (g_strcasecmp(value, "low") == 0)
            {
                client_info->crypt_level = 1;
            }
            else if (g_strcasecmp(value, "medium") == 0)
            {
                client_info->crypt_level = 2;
            }
            else if (g_strcasecmp(value, "high") == 0)
            {
                client_info->crypt_level = 3;
            }
            else if (g_strcasecmp(value, "fips") == 0)
            {
                client_info->crypt_level = 4;
            }
            else
            {
                log_message(LOG_LEVEL_ALWAYS,"Warning: Your configured crypt level is "
                          "undefined, 'high' will be used");
                client_info->crypt_level = 3;
            }
        }
        else if (g_strcasecmp(item, "allow_channels") == 0)
        {
            client_info->channels_allowed = g_text2bool(value);
            if (client_info->channels_allowed == 0)
            {
                log_message(LOG_LEVEL_DEBUG,"Info - All channels are disabled");
            }
        }
        else if (g_strcasecmp(item, "allow_multimon") == 0)
                {
                    client_info->multimon = g_text2bool(value);
                    if (client_info->multimon == 0)
                    {
                        log_message(LOG_LEVEL_DEBUG,"Info - Multi monitor server support disabled");
                    }
                }
        else if (g_strcasecmp(item, "max_bpp") == 0)
        {
            client_info->max_bpp = g_atoi(value);
        }
        else if (g_strcasecmp(item, "rfx_min_pixel") == 0)
        {
            client_info->rfx_min_pixel = g_atoi(value);
        }
        else if (g_strcasecmp(item, "new_cursors") == 0)
        {
            client_info->pointer_flags = g_text2bool(value) == 0 ? 2 : 0;
        }
        else if (g_strcasecmp(item, "require_credentials") == 0)
        {
            client_info->require_credentials = g_text2bool(value);
        }
        else if (g_strcasecmp(item, "use_fastpath") == 0)
        {
            if (g_strcasecmp(value, "output") == 0)
            {
                client_info->use_fast_path = 1;
            }
            else if (g_strcasecmp(value, "input") == 0)
            {
                client_info->use_fast_path = 2;
            }
            else if (g_strcasecmp(value, "both") == 0)
            {
                client_info->use_fast_path = 3;
            }
            else if (g_strcasecmp(value, "none") == 0)
            {
                client_info->use_fast_path = 0;
            }
            else
            {
                log_message(LOG_LEVEL_ALWAYS,"Warning: Your configured fastpath level is "
                          "undefined, fastpath will not be used");
                client_info->use_fast_path = 0;
            }
        }
        else if (g_strcasecmp(item, "ssl_protocols") == 0)
        {
            /* put leading/trailing comma to properly detect "TLSv1" without regex */
            tmp_length = g_strlen(value) + 3;
            tmp = g_new(char, tmp_length);
            g_snprintf(tmp, tmp_length, "%s%s%s", ",", value, ",");
            /* replace all spaces with comma */
            /* to accept space after comma */
            while ((pos = g_pos(tmp, " ")) != -1)
            {
                tmp[pos] = ',';
            }
            ssl_get_protocols_from_string(tmp, &(client_info->ssl_protocols));
            g_free(tmp);
        }
        else if (g_strcasecmp(item, "tls_ciphers") == 0)
Пример #26
0
/* return error */
static int l_file_read_section(int fd, int max_file_size, const char *section, xrdpList *names, xrdpList *values)
{
	struct stream *s;
	char text[512];
	char name[512];
	char value[512];
	char *lvalue;
	char c;
	int in_it;
	int in_it_index;
	int len;
	int index;
	int file_size;

	file_size = 32 * 1024; /* 32 K file size limit */
	g_file_seek(fd, 0);
	in_it_index = 0;
	in_it = 0;
	g_memset(text, 0, 512);
	list_clear(names);
	list_clear(values);
	make_stream(s);
	init_stream(s, file_size);
	len = g_file_read(fd, s->data, file_size);

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

		for (index = 0; index < len; index++)
		{
			if (!s_check_rem(s, 1))
			{
				break;
			}

			in_uint8(s, c);

			if ((c == '#') || (c == ';'))
			{
				file_read_line(s, text);
				in_it = 0;
				in_it_index = 0;
				g_memset(text, 0, 512);
				continue;
			}

			if (c == '[')
			{
				in_it = 1;
			}
			else if (c == ']')
			{
				if (g_strcasecmp(section, text) == 0)
				{
					file_read_line(s, text);

					while (file_read_line(s, text) == 0)
					{
						if (g_strlen(text) > 0)
						{
							file_split_name_value(text, name, value);
							list_add_item(names, (tbus) g_strdup(name));

							if (value[0] == '$')
							{
								lvalue = g_getenv(value + 1);

								if (lvalue != 0)
								{
									list_add_item(values, (tbus) g_strdup(lvalue));
								}
								else
								{
									list_add_item(values, (tbus) g_strdup(""));
								}
							}
							else
							{
								list_add_item(values, (tbus) g_strdup(value));
							}
						}
					}

					free_stream(s);
					return 0;
				}

				in_it = 0;
				in_it_index = 0;
				g_memset(text, 0, 512);
			}
			else if (in_it)
			{
				text[in_it_index] = c;
				in_it_index++;
			}
		}
	}

	free_stream(s);
	return 1;
}
Пример #27
0
static int APP_CC
xrdp_mm_setup_mod2(struct xrdp_mm* self)
{
  char text[256];
  char* name = (char *)NULL;
  char* value = (char *)NULL;
  int i = 0;
  int rv = 0;
  int key_flags = 0;
  int device_flags = 0;

  g_memset(text,0,sizeof(char) * 256);
  rv = 1;
  text[0] = 0;
  if (!g_is_wait_obj_set(self->wm->pro_layer->self_term_event))
  {
    if (self->mod->mod_start(self->mod, self->wm->screen->width,
                             self->wm->screen->height,
                             self->wm->screen->bpp) != 0)
    {
      g_set_wait_obj(self->wm->pro_layer->self_term_event); /* kill session */
    }
  }
  if (!g_is_wait_obj_set(self->wm->pro_layer->self_term_event))
  {
    if (self->display > 0)
    {
      if (self->code == 0) /* Xvnc */
      {
        g_snprintf(text, 255, "%d", 5900 + self->display);
      }
      else if (self->code == 10) /* X11rdp */
      {
        g_snprintf(text, 255, "%d", 6200 + self->display);
      }
      else
      {
        g_set_wait_obj(self->wm->pro_layer->self_term_event); /* kill session */
      }
    }
  }
  if (!g_is_wait_obj_set(self->wm->pro_layer->self_term_event))
  {
    /* this adds the port to the end of the list, it will already be in
       the list as -1
       the module should use the last one */
    if (g_strlen(text) > 0)
    {
      list_add_item(self->login_names, (long)g_strdup("port"));
      list_add_item(self->login_values, (long)g_strdup(text));
    }
    /* always set these */
    name = self->wm->session->client_info->hostname;
    self->mod->mod_set_param(self->mod, "hostname", name);
    g_snprintf(text, 255, "%d", self->wm->session->client_info->keylayout);
    self->mod->mod_set_param(self->mod, "keylayout", text);
    for (i = 0; i < self->login_names->count; i++)
    {
      name = (char*)list_get_item(self->login_names, i);
      value = (char*)list_get_item(self->login_values, i);
      self->mod->mod_set_param(self->mod, name, value);
    }
    /* connect */
    if (self->mod->mod_connect(self->mod) == 0)
    {
      rv = 0;
    }
    else
    {
// AUDIT connected Failed
      AUDIT_FAILED_OPEN( self->wm->pro_layer, "" );
    }
  }
  if (rv == 0)
  {
// AUDIT connected Ok
    AUDIT_OPEN( self->wm->pro_layer, "" );
    /* sync modifiers */
    key_flags = 0;
    device_flags = 0;
    if (self->wm->scroll_lock)
    {
      key_flags |= 1;
    }
    if (self->wm->num_lock)
    {
      key_flags |= 2;
    }
    if (self->wm->caps_lock)
    {
      key_flags |= 4;
    }
    if (self->mod != 0)
    {
      if (self->mod->mod_event != 0)
      {
        self->mod->mod_event(self->mod, 17, key_flags, device_flags,
                             key_flags, device_flags);
      }
    }
  }
  return rv;
}
Пример #28
0
static int APP_CC
xrdp_mm_send_login(struct xrdp_mm* self)
{
  struct stream * s = (struct stream *)NULL;
  int rv = 0;
  int index = 0;
  int count = 0;
  char * username = (char *)NULL;
  char * password = (char *)NULL;
  char * name = (char *)NULL;
  char * value = (char *)NULL;

  xrdp_wm_log_msg(self->wm, "sending login info to session manager, "
                            "please wait...");
  username = 0;
  password = 0;
  self->code = 0;
  count = self->login_names->count;
  for (index = 0; index < count; index++)
  {
    name = (char*)list_get_item(self->login_names, index);
    value = (char*)list_get_item(self->login_values, index);
    if (g_strcasecmp(name, "username") == 0)
    {
      username = value;
    }
    else if (g_strcasecmp(name, "password") == 0)
    {
      password = value;
    }
    else if (g_strcasecmp(name, "lib") == 0)
    {
      if ((g_strcasecmp(value, "libxup.so") == 0) ||
          (g_strcasecmp(value, "xup.dll") == 0))
      {
        self->code = 10;
      }
    }
  }
  if ((username == 0) || (password == 0))
  {
    xrdp_wm_log_msg(self->wm, "Error finding username and password");
    return 1;
  }

  s = trans_get_out_s(self->sesman_trans, 8192);
  s_push_layer(s, channel_hdr, 8);
  /* this code is either 0 for Xvnc or 10 for X11rdp */
  out_uint16_be(s, self->code);
  index = g_strlen(username);
  out_uint16_be(s, index);
  out_uint8a(s, username, index);
  index = g_strlen(password);

  out_uint16_be(s, index);
  out_uint8a(s, password, index);
  out_uint16_be(s, self->wm->screen->width);
  out_uint16_be(s, self->wm->screen->height);
  out_uint16_be(s, self->wm->screen->bpp);

  /* send domain */
  index = g_strlen(self->wm->client_info->domain);
  out_uint16_be(s, index);
  out_uint8a(s, self->wm->client_info->domain, index);

  /* send program / shell */
  index = g_strlen(self->wm->client_info->program);
  out_uint16_be(s, index);
  out_uint8a(s, self->wm->client_info->program, index);

  /* send directory */
  index = g_strlen(self->wm->client_info->directory);
  out_uint16_be(s, index);
  out_uint8a(s, self->wm->client_info->directory, index);

  /* send client ip */
  index = g_strlen(self->wm->client_info->client_ip);
  out_uint16_be(s, index);
  out_uint8a(s, self->wm->client_info->client_ip, index);

  s_mark_end(s);

  s_pop_layer(s, channel_hdr);
  out_uint32_be(s, 0); /* version */
  index = (int)(s->end - s->data);
  out_uint32_be(s, index); /* size */

  rv = trans_force_write(self->sesman_trans);

  if (rv != 0) {
    xrdp_wm_log_msg(self->wm, "xrdp_mm_send_login: xrdp_mm_send_login failed");
  }

  return rv;
}
Пример #29
0
int DEFAULT_CC
main(int argc, char **argv)
{
    int test;
    int host_be;
#if defined(_WIN32)
    WSADATA w;
    SC_HANDLE sc_man;
    SC_HANDLE sc_ser;
    int run_as_service;
    SERVICE_TABLE_ENTRY te[2];
#else
    int pid;
    int fd;
    int no_daemon;
    char text[256];
    char pid_file[256];
#endif

    g_init();
    ssl_init();
    /* check compiled endian with actual endian */
    test = 1;
    host_be = !((int)(*(unsigned char *)(&test)));
#if defined(B_ENDIAN)

    if (!host_be)
#endif
#if defined(L_ENDIAN)
        if (host_be)
#endif
        {
            g_writeln("endian wrong, edit arch.h");
            return 0;
        }

    /* check long, int and void* sizes */
    if (sizeof(int) != 4)
    {
        g_writeln("unusable int size, must be 4");
        return 0;
    }

    if (sizeof(long) != sizeof(void *))
    {
        g_writeln("long size must match void* size");
        return 0;
    }

    if (sizeof(long) != 4 && sizeof(long) != 8)
    {
        g_writeln("unusable long size, must be 4 or 8");
        return 0;
    }

    if (sizeof(tui64) != 8)
    {
        g_writeln("unusable tui64 size, must be 8");
        return 0;
    }

#if defined(_WIN32)
    run_as_service = 1;

    if (argc == 2)
    {
        if (g_strncasecmp(argv[1], "-help", 255) == 0 ||
                g_strncasecmp(argv[1], "--help", 255) == 0 ||
                g_strncasecmp(argv[1], "-h", 255) == 0)
        {
            g_writeln("");
            g_writeln("xrdp: A Remote Desktop Protocol server.");
            g_writeln("Copyright (C) Jay Sorg 2004-2011");
            g_writeln("See http://xrdp.sourceforge.net for more information.");
            g_writeln("");
            g_writeln("Usage: xrdp [options]");
            g_writeln("   -h: show help");
            g_writeln("   -install: install service");
            g_writeln("   -remove: remove service");
            g_writeln("");
            g_exit(0);
        }
        else if (g_strncasecmp(argv[1], "-install", 255) == 0 ||
                 g_strncasecmp(argv[1], "--install", 255) == 0 ||
                 g_strncasecmp(argv[1], "-i", 255) == 0)
        {
            /* open service manager */
            sc_man = OpenSCManager(0, 0, GENERIC_WRITE);

            if (sc_man == 0)
            {
                g_writeln("error OpenSCManager, do you have rights?");
                g_exit(0);
            }

            /* check if service is allready installed */
            sc_ser = OpenService(sc_man, "xrdp", SERVICE_ALL_ACCESS);

            if (sc_ser == 0)
            {
                /* install service */
                CreateService(sc_man, "xrdp", "xrdp", SERVICE_ALL_ACCESS,
                              SERVICE_WIN32_OWN_PROCESS, SERVICE_DEMAND_START,
                              SERVICE_ERROR_IGNORE, "c:\\temp\\xrdp\\xrdp.exe",
                              0, 0, 0, 0, 0);

            }
            else
            {
                g_writeln("error service is allready installed");
                CloseServiceHandle(sc_ser);
                CloseServiceHandle(sc_man);
                g_exit(0);
            }

            CloseServiceHandle(sc_man);
            g_exit(0);
        }
        else if (g_strncasecmp(argv[1], "-remove", 255) == 0 ||
                 g_strncasecmp(argv[1], "--remove", 255) == 0 ||
                 g_strncasecmp(argv[1], "-r", 255) == 0)
        {
            /* open service manager */
            sc_man = OpenSCManager(0, 0, GENERIC_WRITE);

            if (sc_man == 0)
            {
                g_writeln("error OpenSCManager, do you have rights?");
                g_exit(0);
            }

            /* check if service is allready installed */
            sc_ser = OpenService(sc_man, "xrdp", SERVICE_ALL_ACCESS);

            if (sc_ser == 0)
            {
                g_writeln("error service is not installed");
                CloseServiceHandle(sc_man);
                g_exit(0);
            }

            DeleteService(sc_ser);
            CloseServiceHandle(sc_man);
            g_exit(0);
        }
        else
        {
            g_writeln("Unknown Parameter");
            g_writeln("xrdp -h for help");
            g_writeln("");
            g_exit(0);
        }
    }
    else if (argc > 1)
    {
        g_writeln("Unknown Parameter");
        g_writeln("xrdp -h for help");
        g_writeln("");
        g_exit(0);
    }

    if (run_as_service)
    {
        g_memset(&te, 0, sizeof(te));
        te[0].lpServiceName = "xrdp";
        te[0].lpServiceProc = MyServiceMain;
        StartServiceCtrlDispatcher(&te);
        g_exit(0);
    }

    WSAStartup(2, &w);
#else /* _WIN32 */
    g_snprintf(pid_file, 255, "%s/xrdp.pid", XRDP_PID_PATH);
    no_daemon = 0;

    if (argc == 2)
    {
        if ((g_strncasecmp(argv[1], "-kill", 255) == 0) ||
                (g_strncasecmp(argv[1], "--kill", 255) == 0) ||
                (g_strncasecmp(argv[1], "-k", 255) == 0))
        {
            g_writeln("stopping xrdp");
            /* read the xrdp.pid file */
            fd = -1;

            if (g_file_exist(pid_file)) /* xrdp.pid */
            {
                fd = g_file_open(pid_file); /* xrdp.pid */
            }

            if (fd == -1)
            {
                g_writeln("problem opening to xrdp.pid");
                g_writeln("maybe its not running");
            }
            else
            {
                g_memset(text, 0, 32);
                g_file_read(fd, text, 31);
                pid = g_atoi(text);
                g_writeln("stopping process id %d", pid);

                if (pid > 0)
                {
                    g_sigterm(pid);
                }

                g_file_close(fd);
            }

            g_exit(0);
        }
        else if (g_strncasecmp(argv[1], "-nodaemon", 255) == 0 ||
                 g_strncasecmp(argv[1], "--nodaemon", 255) == 0 ||
                 g_strncasecmp(argv[1], "-nd", 255) == 0 ||
                 g_strncasecmp(argv[1], "--nd", 255) == 0 ||
                 g_strncasecmp(argv[1], "-ns", 255) == 0 ||
                 g_strncasecmp(argv[1], "--ns", 255) == 0)
        {
            no_daemon = 1;
        }
        else if (g_strncasecmp(argv[1], "-help", 255) == 0 ||
                 g_strncasecmp(argv[1], "--help", 255) == 0 ||
                 g_strncasecmp(argv[1], "-h", 255) == 0)
        {
            g_writeln("");
            g_writeln("xrdp: A Remote Desktop Protocol server.");
            g_writeln("Copyright (C) Jay Sorg 2004-2011");
            g_writeln("See http://xrdp.sourceforge.net for more information.");
            g_writeln("");
            g_writeln("Usage: xrdp [options]");
            g_writeln("   -h: show help");
            g_writeln("   -nodaemon: don't fork into background");
            g_writeln("   -kill: shut down xrdp");
            g_writeln("");
            g_exit(0);
        }
        else if ((g_strncasecmp(argv[1], "-v", 255) == 0) ||
                 (g_strncasecmp(argv[1], "--version", 255) == 0))
        {
            g_writeln("");
            g_writeln("xrdp: A Remote Desktop Protocol server.");
            g_writeln("Copyright (C) Jay Sorg 2004-2011");
            g_writeln("See http://xrdp.sourceforge.net for more information.");
            g_writeln("Version %s", PACKAGE_VERSION);
            g_writeln("");
            g_exit(0);
        }
        else
        {
            g_writeln("Unknown Parameter");
            g_writeln("xrdp -h for help");
            g_writeln("");
            g_exit(0);
        }
    }
    else if (argc > 1)
    {
        g_writeln("Unknown Parameter");
        g_writeln("xrdp -h for help");
        g_writeln("");
        g_exit(0);
    }

    if (g_file_exist(pid_file)) /* xrdp.pid */
    {
        g_writeln("It looks like xrdp is allready running,");
        g_writeln("if not delete the xrdp.pid file and try again");
        g_exit(0);
    }

    if (!no_daemon)
    {
        /* make sure we can write to pid file */
        fd = g_file_open(pid_file); /* xrdp.pid */

        if (fd == -1)
        {
            g_writeln("running in daemon mode with no access to pid files, quitting");
            g_exit(0);
        }

        if (g_file_write(fd, "0", 1) == -1)
        {
            g_writeln("running in daemon mode with no access to pid files, quitting");
            g_exit(0);
        }

        g_file_close(fd);
        g_file_delete(pid_file);
    }

    if (!no_daemon)
    {
        /* start of daemonizing code */
        pid = g_fork();

        if (pid == -1)
        {
            g_writeln("problem forking");
            g_exit(1);
        }

        if (0 != pid)
        {
            g_writeln("process %d started ok", pid);
            /* exit, this is the main process */
            g_exit(0);
        }

        g_sleep(1000);
        g_file_close(0);
        g_file_close(1);
        g_file_close(2);
        g_file_open("/dev/null");
        g_file_open("/dev/null");
        g_file_open("/dev/null");
        /* end of daemonizing code */
    }

    if (!no_daemon)
    {
        /* write the pid to file */
        pid = g_getpid();
        fd = g_file_open(pid_file); /* xrdp.pid */

        if (fd == -1)
        {
            g_writeln("trying to write process id to xrdp.pid");
            g_writeln("problem opening xrdp.pid");
            g_writeln("maybe no rights");
        }
        else
        {
            g_sprintf(text, "%d", pid);
            g_file_write(fd, text, g_strlen(text));
            g_file_close(fd);
        }
    }

#endif
    g_threadid = tc_get_threadid();
    g_listen = xrdp_listen_create();
    g_signal_user_interrupt(xrdp_shutdown); /* SIGINT */
    g_signal_kill(xrdp_shutdown); /* SIGKILL */
    g_signal_pipe(pipe_sig); /* SIGPIPE */
    g_signal_terminate(xrdp_shutdown); /* SIGTERM */
    g_sync_mutex = tc_mutex_create();
    g_sync1_mutex = tc_mutex_create();
    pid = g_getpid();
    g_snprintf(text, 255, "xrdp_%8.8x_main_term", pid);
    g_term_event = g_create_wait_obj(text);
    g_snprintf(text, 255, "xrdp_%8.8x_main_sync", pid);
    g_sync_event = g_create_wait_obj(text);

    if (g_term_event == 0)
    {
        g_writeln("error creating g_term_event");
    }

    xrdp_listen_main_loop(g_listen);
    xrdp_listen_delete(g_listen);
    tc_mutex_delete(g_sync_mutex);
    tc_mutex_delete(g_sync1_mutex);
    g_delete_wait_obj(g_term_event);
    g_delete_wait_obj(g_sync_event);
#if defined(_WIN32)
    /* I don't think it ever gets here */
    /* when running in win32 app mode, control c exits right away */
    WSACleanup();
#else
    /* delete the xrdp.pid file */
    g_file_delete(pid_file);
#endif
    return 0;
}
Пример #30
0
/* return error */
static int APP_CC
l_file_read_section(int fd, int max_file_size, const char *section,
                    struct list *names, struct list *values)
{
    struct stream *s;
    char *data;
    char *text;
    char *name;
    char *value;
    char *lvalue;
    char c;
    int in_it;
    int in_it_index;
    int len;
    int index;
    int file_size;

    data = (char *) g_malloc(FILE_MAX_LINE_BYTES * 3, 0);
    text = data;
    name = text + FILE_MAX_LINE_BYTES;
    value = name + FILE_MAX_LINE_BYTES;

    file_size = 32 * 1024; /* 32 K file size limit */
    g_file_seek(fd, 0);
    in_it_index = 0;
    in_it = 0;
    g_memset(text, 0, FILE_MAX_LINE_BYTES);
    list_clear(names);
    list_clear(values);
    make_stream(s);
    init_stream(s, file_size);
    len = g_file_read(fd, s->data, file_size);

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

        for (index = 0; index < len; index++)
        {
            if (!s_check_rem(s, 1))
            {
                break;
            }
            in_uint8(s, c);
            if ((c == '#') || (c == ';'))
            {
                if (file_read_line(s, text, FILE_MAX_LINE_BYTES) != 0)
                {
                    break;
                }
                in_it = 0;
                in_it_index = 0;
                g_memset(text, 0, FILE_MAX_LINE_BYTES);
                continue;
            }
            if (c == '[')
            {
                in_it = 1;
            }
            else if (c == ']')
            {
                if (g_strcasecmp(section, text) == 0)
                {
                    file_read_line(s, text, FILE_MAX_LINE_BYTES);
                    while (file_read_line(s, text, FILE_MAX_LINE_BYTES) == 0)
                    {
                        if (g_strlen(text) > 0)
                        {
                            file_split_name_value(text, name, value);
                            list_add_item(names, (tbus)g_strdup(name));

                            if (value[0] == '$')
                            {
                                lvalue = g_getenv(value + 1);

                                if (lvalue != 0)
                                {
                                    list_add_item(values, (tbus)g_strdup(lvalue));
                                }
                                else
                                {
                                    list_add_item(values, (tbus)g_strdup(""));
                                }
                            }
                            else
                            {
                                list_add_item(values, (tbus)g_strdup(value));
                            }
                        }
                    }

                    free_stream(s);
                    g_free(data);
                    return 0;
                }

                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++;
                if (in_it_index >= FILE_MAX_LINE_BYTES)
                {
                    break;
                }
            }
        }
    }
    free_stream(s);
    g_free(data);
    return 1;
}