Ejemplo n.º 1
0
int APP_CC
xrdp_audit(struct xrdp_process *process, const char*action, const char* message)
{
    // This sends an http 0.9 request, i.e. no headers
    char client_ip[256] = {0,};
    char data[4096] = {0,};
    char username[256] = {0,};
    char device_name[256] = {0,};
    char accesstoken[256] = {0,};
    xrdp_mm_get_value(process->wm->mm, "osirium_account", username, 255);
    xrdp_mm_get_value(process->wm->mm, "device_name", device_name, 255);
    xrdp_mm_get_value(process->wm->mm, "accesstoken", accesstoken, 255);
    xrdp_mm_get_value(process->wm->mm, "client_ip_addr", client_ip, 255);
    if (username[0] == 0)
    {
        g_snprintf(username, 255, "%s", g_getenv("USER"));
    }
    if (device_name[0] == 0)
    {
        g_strcpy(device_name, "unknown");
    }
    if (accesstoken[0] == 0)
    {
        g_strcpy(accesstoken, "unknown");
    }

    g_snprintf(data, sizeof(data)-1, REQUEST_TEMPLATE, 
            username, //process->wm->session->client_info->username,// username
            "rdp",                                      // type
            device_name,    //process->session->client_info->hostname,    // devicename
            action,                                     // action
            accesstoken,                                         // accesstoken
            // process->server_trans->skt
            client_ip //process->session->client_info->hostname // client_ip
            );
    g_writeln(data);
    fflush(stdout);

    // open socket
    int sck = g_tcp_socket();
    fflush(stdout);
    if (g_tcp_connect(sck, AUDIT_ADDRESS, AUDIT_PORT) == 0)
    {
        // left as blocking socket !!
        fflush(stdout);
        // get url
        int sent = g_tcp_send(sck, data, g_strlen(data), 0);
        if ( g_tcp_can_recv(sck, 1000) > 0)  // at most 1 second
        {
            // read response and ignore.
            int rlen = g_tcp_recv(sck, data, sizeof(data)-1, 0);
        }
        else
        {
        }
        fflush(stdout);
        // close socket
        g_tcp_close(sck);
    }
}
Ejemplo n.º 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;
}
Ejemplo n.º 3
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;
}
Ejemplo n.º 4
0
/* does not work in win32 */
int g_getuser_info(const char *username, int *gid, int *uid, char *shell, char *dir, char *gecos)
{
#if defined(_WIN32)
	return 1;
#else
	struct passwd *pwd_1;

	pwd_1 = getpwnam(username);

	if (pwd_1 != 0)
	{
		if (gid != 0)
		{
			*gid = pwd_1->pw_gid;
		}

		if (uid != 0)
		{
			*uid = pwd_1->pw_uid;
		}

		if (dir != 0)
		{
			g_strcpy(dir, pwd_1->pw_dir);
		}

		if (shell != 0)
		{
			g_strcpy(shell, pwd_1->pw_shell);
		}

		if (gecos != 0)
		{
			g_strcpy(gecos, pwd_1->pw_gecos);
		}

		return 0;
	}

	return 1;
#endif
}
Ejemplo n.º 5
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;
}
Ejemplo n.º 6
0
int
dev_redir_begin_io_request(char* job,int device)
{
	struct stream* s;
	int index;
	make_stream(s);
	init_stream(s,1024);

	actions[action_index].device = device;
	actions[action_index].file_id = action_index;
	actions[action_index].last_req = IRP_MJ_CREATE;
	actions[action_index].message_id = 0;
	g_strcpy(actions[action_index].path, job);

	log_message(&log_conf, LOG_LEVEL_DEBUG, "chansrv[dev_redir_send_file]:"
  		"process job[%s]",job);
	out_uint16_le(s, RDPDR_CTYP_CORE);
	out_uint16_le(s, PAKID_CORE_DEVICE_IOREQUEST);
	out_uint32_le(s, actions[action_index].device);
	out_uint32_le(s, actions[action_index].file_id);
	out_uint32_le(s, actions[action_index].file_id);
	out_uint32_le(s, IRP_MJ_CREATE);   	/* major version */
	out_uint32_le(s, 0);								/* minor version */
	index = dev_redir_get_device_index(device);
	switch (device_list[index].device_type) {
		case RDPDR_DTYP_PRINT:
			out_uint32_le(s, 0);								/* desired access(unused) */
			out_uint64_le(s, 0);								/* size (unused) */
			out_uint32_le(s, 0);								/* file attribute (unused) */
			out_uint32_le(s, 0);								/* shared access (unused) */
			out_uint32_le(s, 0);								/* disposition (unused) */
			out_uint32_le(s, 0);								/* create option (unused) */
			out_uint32_le(s, 0);								/* path length (unused) */
			break;
		default:
			log_message(&log_conf, LOG_LEVEL_ERROR, "chansrv[dev_redir_send_file: "
					"the device type %04x is not yet supported",device);
			free_stream(s);
			return 0;
			break;
	}
	s_mark_end(s);
	dev_redir_send(s);
	free_stream(s);
  return 0;
}
Ejemplo n.º 7
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;
}
Ejemplo n.º 8
0
int DEFAULT_CC
xml_get_xpath(xmlDocPtr doc, char* xpath, char* value)
{
	xmlXPathObjectPtr xpathObj;
	xmlXPathContextPtr context;
	xmlNodeSetPtr nodeset;
	xmlChar *keyword;

	context = xmlXPathNewContext(doc);
	if (context == NULL)
	{
		log_message(&(g_cfg->log), LOG_LEVEL_WARNING, "sesman[xml_get_xpath]: "
				"error in xmlXPathNewContext");
		return 1;
	}
	xpathObj = xmlXPathEvalExpression((xmlChar*) xpath, context);
	xmlXPathFreeContext(context);
	nodeset = xpathObj->nodesetval;
	if(xmlXPathNodeSetIsEmpty(nodeset))
	{
		xmlXPathFreeObject(xpathObj);
		log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "sesman[xml_get_xpath]: "
				"no result");
		return 1;
	}
	keyword = xmlNodeListGetString(doc, nodeset->nodeTab[0]->xmlChildrenNode, 1);
	if( keyword == 0)
	{
		xmlXPathFreeObject(xpathObj);
		log_message(&(g_cfg->log), LOG_LEVEL_WARNING, "sesman[xml_get_xpath]: "
				"Unable to get keyword");
		return 1;
	}
	g_strcpy(value, (const char*)keyword);
	xmlXPathFreeObject(xpathObj);
	xmlFree(keyword);
	return 0;
}
Ejemplo n.º 9
0
static int
clipboard_get_file(const char *file, int bytes)
{
    int sindex;
    int pindex;
    int flags;
    char full_fn[256]; /* /etc/xrdp/xrdp.ini */
    char filename[256]; /* xrdp.ini */
    char pathname[256]; /* /etc/xrdp */
    struct cb_file_info *cfi;

    /* x-special/gnome-copied-files */
    if ((g_strncmp(file, "copy", 4) == 0) && (bytes == 4))
    {
        return 0;
    }
    if ((g_strncmp(file, "cut", 3) == 0) && (bytes == 3))
    {
        return 0;
    }
    sindex = 0;
    flags = CB_FILE_ATTRIBUTE_ARCHIVE;
    /* text/uri-list */
    /* x-special/gnome-copied-files */
    if (g_strncmp(file, "file://", 7) == 0)
    {
        sindex = 7;
    }
    pindex = bytes;
    while (pindex > sindex)
    {
        if (file[pindex] == '/')
        {
            break;
        }
        pindex--;
    }
    g_memset(pathname, 0, 256);
    g_memset(filename, 0, 256);
    g_memcpy(pathname, file + sindex, pindex - sindex);
    if (pathname[0] == 0)
    {
        pathname[0] = '/';
    }
    g_memcpy(filename, file + pindex + 1, (bytes - 1) - pindex);
    /* this should replace %20 with space */
    clipboard_check_file(pathname);
    clipboard_check_file(filename);
    g_snprintf(full_fn, 255, "%s/%s", pathname, filename);
    if (g_directory_exist(full_fn))
    {
        log_error("clipboard_get_file: file [%s] is a directory, "
                   "not supported", full_fn);
        flags |= CB_FILE_ATTRIBUTE_DIRECTORY;
        return 1;
    }
    if (!g_file_exist(full_fn))
    {
        log_error("clipboard_get_file: file [%s] does not exist",
                   full_fn);
        return 1;
    }
    else
    {
        cfi = (struct cb_file_info*)g_malloc(sizeof(struct cb_file_info), 1);
        list_add_item(g_files_list, (tintptr)cfi);
        g_strcpy(cfi->filename, filename);
        g_strcpy(cfi->pathname, pathname);
        cfi->size = g_file_get_size(full_fn);
        cfi->flags = flags;
        cfi->time = (g_time1() + CB_EPOCH_DIFF) * 10000000LL;
        log_debug("ok filename [%s] pathname [%s] size [%d]",
                    cfi->filename, cfi->pathname, cfi->size);
    }
    return 0;
}