Merge pull request #1703 from matt335672/issue1048-2

Allow FuseMountName for chansrv to be absolute path (#1048)
Move string funcs from os_calls.h to string_calls.h
This commit is contained in:
matt335672 2020-12-22 12:10:43 +00:00 committed by GitHub
commit aa5c5daf7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
58 changed files with 967 additions and 574 deletions

View File

@ -54,11 +54,12 @@ libcommon_la_SOURCES = \
log.h \
os_calls.c \
os_calls.h \
os_calls.h \
parse.h \
rail.h \
ssl_calls.c \
ssl_calls.h \
string_calls.c \
string_calls.h \
thread_calls.c \
thread_calls.h \
trans.c \

View File

@ -22,7 +22,7 @@
#include <config_ac.h>
#endif
#include "os_calls.h"
#include "string_calls.h"
#include <openssl/bio.h>
#include <openssl/evp.h>

View File

@ -24,6 +24,7 @@
#include "arch.h"
#include "os_calls.h"
#include "string_calls.h"
#include "list.h"
#include "file.h"
#include "parse.h"

View File

@ -24,6 +24,7 @@
#include "arch.h"
#include "os_calls.h"
#include "string_calls.h"
#include "list.h"
/*****************************************************************************/

View File

@ -31,6 +31,7 @@
#include "file.h"
#include "os_calls.h"
#include "thread_calls.h"
#include "string_calls.h"
/* Add a define here so that the log.h will hold more information
* when compiled from this C file.

View File

@ -76,7 +76,7 @@
#endif
#include "os_calls.h"
#include "arch.h"
#include "string_calls.h"
#include "log.h"
/* for clearenv() */
@ -2509,518 +2509,6 @@ g_file_get_size(const char *filename)
#endif
}
/*****************************************************************************/
/* returns length of text */
int
g_strlen(const char *text)
{
if (text == NULL)
{
return 0;
}
return strlen(text);
}
/*****************************************************************************/
/* locates char in text */
const char *
g_strchr(const char* text, int c)
{
if (text == NULL)
{
return 0;
}
return strchr(text,c);
}
/*****************************************************************************/
/* returns dest */
char *
g_strcpy(char *dest, const char *src)
{
if (src == 0 && dest != 0)
{
dest[0] = 0;
return dest;
}
if (dest == 0 || src == 0)
{
return 0;
}
return strcpy(dest, src);
}
/*****************************************************************************/
/* returns dest */
char *
g_strncpy(char *dest, const char *src, int len)
{
char *rv;
if (src == 0 && dest != 0)
{
dest[0] = 0;
return dest;
}
if (dest == 0 || src == 0)
{
return 0;
}
rv = strncpy(dest, src, len);
dest[len] = 0;
return rv;
}
/*****************************************************************************/
/* returns dest */
char *
g_strcat(char *dest, const char *src)
{
if (dest == 0 || src == 0)
{
return dest;
}
return strcat(dest, src);
}
/*****************************************************************************/
/* returns dest */
char *
g_strncat(char *dest, const char *src, int len)
{
if (dest == 0 || src == 0)
{
return dest;
}
return strncat(dest, src, len);
}
/*****************************************************************************/
/* 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;
}
/*****************************************************************************/
/* 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)
{
unsigned 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;
}
/*****************************************************************************/
int
g_strcmp(const char *c1, const char *c2)
{
return strcmp(c1, c2);
}
/*****************************************************************************/
int
g_strncmp(const char *c1, const char *c2, int len)
{
return strncmp(c1, c2, len);
}
/*****************************************************************************/
/* compare up to delim */
int
g_strncmp_d(const char *s1, const char *s2, const char delim, int n)
{
char c1;
char c2;
c1 = 0;
c2 = 0;
while (n > 0)
{
c1 = *(s1++);
c2 = *(s2++);
if ((c1 == 0) || (c1 != c2) || (c1 == delim) || (c2 == delim))
{
return c1 - c2;
}
n--;
}
return c1 - c2;
}
/*****************************************************************************/
int
g_strcasecmp(const char *c1, const char *c2)
{
#if defined(_WIN32)
return stricmp(c1, c2);
#else
return strcasecmp(c1, c2);
#endif
}
/*****************************************************************************/
int
g_strncasecmp(const char *c1, const char *c2, int len)
{
#if defined(_WIN32)
return strnicmp(c1, c2, len);
#else
return strncasecmp(c1, c2, len);
#endif
}
/*****************************************************************************/
int
g_atoi(const char *str)
{
if (str == 0)
{
return 0;
}
return atoi(str);
}
/*****************************************************************************/
int
g_htoi(char *str)
{
int len;
int index;
int rv;
int val;
int shift;
rv = 0;
len = strlen(str);
index = len - 1;
shift = 0;
while (index >= 0)
{
val = 0;
switch (str[index])
{
case '1':
val = 1;
break;
case '2':
val = 2;
break;
case '3':
val = 3;
break;
case '4':
val = 4;
break;
case '5':
val = 5;
break;
case '6':
val = 6;
break;
case '7':
val = 7;
break;
case '8':
val = 8;
break;
case '9':
val = 9;
break;
case 'a':
case 'A':
val = 10;
break;
case 'b':
case 'B':
val = 11;
break;
case 'c':
case 'C':
val = 12;
break;
case 'd':
case 'D':
val = 13;
break;
case 'e':
case 'E':
val = 14;
break;
case 'f':
case 'F':
val = 15;
break;
}
rv = rv | (val << shift);
index--;
shift += 4;
}
return rv;
}
/*****************************************************************************/
/* returns number of bytes copied into out_str */
int
g_bytes_to_hexstr(const void *bytes, int num_bytes, char *out_str,
int bytes_out_str)
{
int rv;
int index;
char *lout_str;
const tui8 *lbytes;
rv = 0;
lbytes = (const tui8 *) bytes;
lout_str = out_str;
for (index = 0; index < num_bytes; index++)
{
if (bytes_out_str < 3)
{
break;
}
g_snprintf(lout_str, bytes_out_str, "%2.2x", lbytes[index]);
lout_str += 2;
bytes_out_str -= 2;
rv += 2;
}
return rv;
}
/*****************************************************************************/
int
g_pos(const char *str, const char *to_find)
{
const char *pp;
pp = strstr(str, to_find);
if (pp == 0)
{
return -1;
}
return (pp - str);
}
/*****************************************************************************/
int
g_mbstowcs(twchar *dest, const char *src, int n)
{
wchar_t *ldest;
int rv;
ldest = (wchar_t *)dest;
rv = mbstowcs(ldest, src, n);
return rv;
}
/*****************************************************************************/
int
g_wcstombs(char *dest, const twchar *src, int n)
{
const wchar_t *lsrc;
int rv;
lsrc = (const wchar_t *)src;
rv = wcstombs(dest, lsrc, n);
return rv;
}
/*****************************************************************************/
/* returns error */
/* trim spaces and tabs, anything <= space */
/* trim_flags 1 trim left, 2 trim right, 3 trim both, 4 trim through */
/* this will always shorten the string or not change it */
int
g_strtrim(char *str, int trim_flags)
{
int index;
int len;
int text1_index;
int got_char;
wchar_t *text;
wchar_t *text1;
len = mbstowcs(0, str, 0);
if (len < 1)
{
return 0;
}
if ((trim_flags < 1) || (trim_flags > 4))
{
return 1;
}
text = (wchar_t *)malloc(len * sizeof(wchar_t) + 8);
text1 = (wchar_t *)malloc(len * sizeof(wchar_t) + 8);
if (text == NULL || text1 == NULL)
{
free(text);
free(text1);
return 1;
}
text1_index = 0;
mbstowcs(text, str, len + 1);
switch (trim_flags)
{
case 4: /* trim through */
for (index = 0; index < len; index++)
{
if (text[index] > 32)
{
text1[text1_index] = text[index];
text1_index++;
}
}
text1[text1_index] = 0;
break;
case 3: /* trim both */
got_char = 0;
for (index = 0; index < len; index++)
{
if (got_char)
{
text1[text1_index] = text[index];
text1_index++;
}
else
{
if (text[index] > 32)
{
text1[text1_index] = text[index];
text1_index++;
got_char = 1;
}
}
}
text1[text1_index] = 0;
len = text1_index;
/* trim right */
for (index = len - 1; index >= 0; index--)
{
if (text1[index] > 32)
{
break;
}
}
text1_index = index + 1;
text1[text1_index] = 0;
break;
case 2: /* trim right */
/* copy it */
for (index = 0; index < len; index++)
{
text1[text1_index] = text[index];
text1_index++;
}
/* trim right */
for (index = len - 1; index >= 0; index--)
{
if (text1[index] > 32)
{
break;
}
}
text1_index = index + 1;
text1[text1_index] = 0;
break;
case 1: /* trim left */
got_char = 0;
for (index = 0; index < len; index++)
{
if (got_char)
{
text1[text1_index] = text[index];
text1_index++;
}
else
{
if (text[index] > 32)
{
text1[text1_index] = text[index];
text1_index++;
got_char = 1;
}
}
}
text1[text1_index] = 0;
break;
}
wcstombs(str, text1, text1_index + 1);
free(text);
free(text1);
return 0;
}
/*****************************************************************************/
long
g_load_library(char *in)
@ -3307,6 +2795,17 @@ g_setsid(void)
#endif
}
/*****************************************************************************/
int
g_getlogin(char *name, unsigned int len)
{
#if defined(_WIN32)
return -1;
#else
return getlogin_r(name, len);
#endif
}
/*****************************************************************************/
int
g_setlogin(const char *name)
@ -3760,21 +3259,6 @@ g_save_to_bmp(const char* filename, char* data, int stride_bytes,
return 0;
}
/*****************************************************************************/
/* returns boolean */
int
g_text2bool(const char *s)
{
if ( (g_atoi(s) != 0) ||
(0 == g_strcasecmp(s, "true")) ||
(0 == g_strcasecmp(s, "on")) ||
(0 == g_strcasecmp(s, "yes")))
{
return 1;
}
return 0;
}
/*****************************************************************************/
/* returns pointer or nil on error */
void *

View File

@ -119,27 +119,6 @@ int g_create_path(const char* path);
int g_remove_dir(const char* dirname);
int g_file_delete(const char* filename);
int g_file_get_size(const char* filename);
int g_strlen(const char* text);
const char *g_strchr(const char *text, int c);
char* g_strcpy(char* dest, const char* src);
char* g_strncpy(char* dest, const char* src, int len);
char* g_strcat(char* dest, const char* src);
char* g_strncat(char* dest, const char* src, int len);
char* g_strdup(const char* in);
char* g_strndup(const char* in, const unsigned int maxlen);
int g_strcmp(const char* c1, const char* c2);
int g_strncmp(const char* c1, const char* c2, int len);
int g_strncmp_d(const char* c1, const char* c2, const char delim, int len);
int g_strcasecmp(const char* c1, const char* c2);
int g_strncasecmp(const char* c1, const char* c2, int len);
int g_atoi(const char* str);
int g_htoi(char* str);
int g_bytes_to_hexstr(const void *bytes, int num_bytes, char *out_str,
int bytes_out_str);
int g_pos(const char* str, const char* to_find);
int g_mbstowcs(twchar* dest, const char* src, int n);
int g_wcstombs(char* dest, const twchar* src, int n);
int g_strtrim(char* str, int trim_flags);
long g_load_library(char* in);
int g_free_library(long lib);
void* g_get_proc_address(long lib, const char* name);
@ -162,6 +141,7 @@ int g_getuid(void);
int g_getgid(void);
int g_setuid(int pid);
int g_setsid(void);
int g_getlogin(char *name, unsigned int len);
int g_setlogin(const char *name);
int g_waitchild(void);
int g_waitpid(int pid);
@ -180,7 +160,6 @@ int g_time2(void);
int g_time3(void);
int g_save_to_bmp(const char* filename, char* data, int stride_bytes,
int width, int height, int depth, int bits_per_pixel);
int g_text2bool(const char *s);
void * g_shmat(int shmid);
int g_shmdt(const void *shmaddr);
int g_gethostname(char *name, int len);

View File

@ -36,6 +36,7 @@
#include <openssl/crypto.h>
#include "os_calls.h"
#include "string_calls.h"
#include "arch.h"
#include "ssl_calls.h"
#include "trans.h"

653
common/string_calls.c Normal file
View File

@ -0,0 +1,653 @@
/**
* xrdp: A Remote Desktop Protocol server.
*
* Copyright (C) Jay Sorg 2004-2020
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* generic string handling calls
*/
#if defined(HAVE_CONFIG_H)
#include "config_ac.h"
#endif
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include "string_calls.h"
#include "os_calls.h"
unsigned int
g_format_info_string(char *dest, unsigned int len,
const char *format,
const struct info_string_tag map[])
{
unsigned int result = 0;
const char *copy_from; /* Data to add to output */
unsigned int copy_len; /* Length of above */
unsigned int skip; /* Date to skip over in format string */
const char *p;
const struct info_string_tag *m;
for ( ; *format != '\0'; format += skip)
{
if (*format == '%')
{
char ch = *(format + 1);
if (ch == '%')
{
/* '%%' in format - replace with single '%' */
copy_from = format;
copy_len = 1;
skip = 2;
}
else if (ch == '\0')
{
/* Percent at end of string - ignore */
copy_from = NULL;
copy_len = 0;
skip = 1;
}
else
{
/* Look up the character in the map, assuming failure */
copy_from = NULL;
copy_len = 0;
skip = 2;
for (m = map ; m->ch != '\0' ; ++m)
{
if (ch == m->ch)
{
copy_from = m->val;
copy_len = strlen(copy_from);
break;
}
}
}
}
else if ((p = strchr(format, '%')) != NULL)
{
/* Copy up to the next '%' */
copy_from = format;
copy_len = p - format;
skip = copy_len;
}
else
{
/* Copy the rest of the format string */
copy_from = format;
copy_len = strlen(format);
skip = copy_len;
}
/* Update the result before any truncation */
result += copy_len;
/* Do we have room in the output buffer for any more data? We
* must always write a terminator if possible */
if (len > 1)
{
if (copy_len > (len - 1))
{
copy_len = len - 1;
}
memcpy(dest, copy_from, copy_len);
dest += copy_len;
len -= copy_len;
}
}
/* Room for a terminator? */
if (len > 0)
{
*dest = '\0';
}
return result;
}
/******************************************************************************/
const char *
g_bool2text(int value)
{
return value ? "true" : "false";
}
/*****************************************************************************/
int
g_text2bool(const char *s)
{
if ( (g_atoi(s) != 0) ||
(0 == g_strcasecmp(s, "true")) ||
(0 == g_strcasecmp(s, "on")) ||
(0 == g_strcasecmp(s, "yes")))
{
return 1;
}
return 0;
}
/*****************************************************************************/
/* returns length of text */
int
g_strlen(const char *text)
{
if (text == NULL)
{
return 0;
}
return strlen(text);
}
/*****************************************************************************/
/* locates char in text */
const char *
g_strchr(const char *text, int c)
{
if (text == NULL)
{
return 0;
}
return strchr(text, c);
}
/*****************************************************************************/
/* returns dest */
char *
g_strcpy(char *dest, const char *src)
{
if (src == 0 && dest != 0)
{
dest[0] = 0;
return dest;
}
if (dest == 0 || src == 0)
{
return 0;
}
return strcpy(dest, src);
}
/*****************************************************************************/
/* returns dest */
char *
g_strncpy(char *dest, const char *src, int len)
{
char *rv;
if (src == 0 && dest != 0)
{
dest[0] = 0;
return dest;
}
if (dest == 0 || src == 0)
{
return 0;
}
rv = strncpy(dest, src, len);
dest[len] = 0;
return rv;
}
/*****************************************************************************/
/* returns dest */
char *
g_strcat(char *dest, const char *src)
{
if (dest == 0 || src == 0)
{
return dest;
}
return strcat(dest, src);
}
/*****************************************************************************/
/* returns dest */
char *
g_strncat(char *dest, const char *src, int len)
{
if (dest == 0 || src == 0)
{
return dest;
}
return strncat(dest, src, len);
}
/*****************************************************************************/
/* 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;
}
/*****************************************************************************/
/* 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)
{
unsigned 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;
}
/*****************************************************************************/
int
g_strcmp(const char *c1, const char *c2)
{
return strcmp(c1, c2);
}
/*****************************************************************************/
int
g_strncmp(const char *c1, const char *c2, int len)
{
return strncmp(c1, c2, len);
}
/*****************************************************************************/
/* compare up to delim */
int
g_strncmp_d(const char *s1, const char *s2, const char delim, int n)
{
char c1;
char c2;
c1 = 0;
c2 = 0;
while (n > 0)
{
c1 = *(s1++);
c2 = *(s2++);
if ((c1 == 0) || (c1 != c2) || (c1 == delim) || (c2 == delim))
{
return c1 - c2;
}
n--;
}
return c1 - c2;
}
/*****************************************************************************/
int
g_strcasecmp(const char *c1, const char *c2)
{
#if defined(_WIN32)
return stricmp(c1, c2);
#else
return strcasecmp(c1, c2);
#endif
}
/*****************************************************************************/
int
g_strncasecmp(const char *c1, const char *c2, int len)
{
#if defined(_WIN32)
return strnicmp(c1, c2, len);
#else
return strncasecmp(c1, c2, len);
#endif
}
/*****************************************************************************/
int
g_atoi(const char *str)
{
if (str == 0)
{
return 0;
}
return atoi(str);
}
/*****************************************************************************/
int
g_htoi(char *str)
{
int len;
int index;
int rv;
int val;
int shift;
rv = 0;
len = strlen(str);
index = len - 1;
shift = 0;
while (index >= 0)
{
val = 0;
switch (str[index])
{
case '1':
val = 1;
break;
case '2':
val = 2;
break;
case '3':
val = 3;
break;
case '4':
val = 4;
break;
case '5':
val = 5;
break;
case '6':
val = 6;
break;
case '7':
val = 7;
break;
case '8':
val = 8;
break;
case '9':
val = 9;
break;
case 'a':
case 'A':
val = 10;
break;
case 'b':
case 'B':
val = 11;
break;
case 'c':
case 'C':
val = 12;
break;
case 'd':
case 'D':
val = 13;
break;
case 'e':
case 'E':
val = 14;
break;
case 'f':
case 'F':
val = 15;
break;
}
rv = rv | (val << shift);
index--;
shift += 4;
}
return rv;
}
/*****************************************************************************/
/* returns number of bytes copied into out_str */
int
g_bytes_to_hexstr(const void *bytes, int num_bytes, char *out_str,
int bytes_out_str)
{
int rv;
int index;
char *lout_str;
const tui8 *lbytes;
rv = 0;
lbytes = (const tui8 *) bytes;
lout_str = out_str;
for (index = 0; index < num_bytes; index++)
{
if (bytes_out_str < 3)
{
break;
}
g_snprintf(lout_str, bytes_out_str, "%2.2x", lbytes[index]);
lout_str += 2;
bytes_out_str -= 2;
rv += 2;
}
return rv;
}
/*****************************************************************************/
int
g_pos(const char *str, const char *to_find)
{
const char *pp;
pp = strstr(str, to_find);
if (pp == 0)
{
return -1;
}
return (pp - str);
}
/*****************************************************************************/
int
g_mbstowcs(twchar *dest, const char *src, int n)
{
wchar_t *ldest;
int rv;
ldest = (wchar_t *)dest;
rv = mbstowcs(ldest, src, n);
return rv;
}
/*****************************************************************************/
int
g_wcstombs(char *dest, const twchar *src, int n)
{
const wchar_t *lsrc;
int rv;
lsrc = (const wchar_t *)src;
rv = wcstombs(dest, lsrc, n);
return rv;
}
/*****************************************************************************/
/* returns error */
/* trim spaces and tabs, anything <= space */
/* trim_flags 1 trim left, 2 trim right, 3 trim both, 4 trim through */
/* this will always shorten the string or not change it */
int
g_strtrim(char *str, int trim_flags)
{
int index;
int len;
int text1_index;
int got_char;
wchar_t *text;
wchar_t *text1;
len = mbstowcs(0, str, 0);
if (len < 1)
{
return 0;
}
if ((trim_flags < 1) || (trim_flags > 4))
{
return 1;
}
text = (wchar_t *)malloc(len * sizeof(wchar_t) + 8);
text1 = (wchar_t *)malloc(len * sizeof(wchar_t) + 8);
if (text == NULL || text1 == NULL)
{
free(text);
free(text1);
return 1;
}
text1_index = 0;
mbstowcs(text, str, len + 1);
switch (trim_flags)
{
case 4: /* trim through */
for (index = 0; index < len; index++)
{
if (text[index] > 32)
{
text1[text1_index] = text[index];
text1_index++;
}
}
text1[text1_index] = 0;
break;
case 3: /* trim both */
got_char = 0;
for (index = 0; index < len; index++)
{
if (got_char)
{
text1[text1_index] = text[index];
text1_index++;
}
else
{
if (text[index] > 32)
{
text1[text1_index] = text[index];
text1_index++;
got_char = 1;
}
}
}
text1[text1_index] = 0;
len = text1_index;
/* trim right */
for (index = len - 1; index >= 0; index--)
{
if (text1[index] > 32)
{
break;
}
}
text1_index = index + 1;
text1[text1_index] = 0;
break;
case 2: /* trim right */
/* copy it */
for (index = 0; index < len; index++)
{
text1[text1_index] = text[index];
text1_index++;
}
/* trim right */
for (index = len - 1; index >= 0; index--)
{
if (text1[index] > 32)
{
break;
}
}
text1_index = index + 1;
text1[text1_index] = 0;
break;
case 1: /* trim left */
got_char = 0;
for (index = 0; index < len; index++)
{
if (got_char)
{
text1[text1_index] = text[index];
text1_index++;
}
else
{
if (text[index] > 32)
{
text1[text1_index] = text[index];
text1_index++;
got_char = 1;
}
}
}
text1[text1_index] = 0;
break;
}
wcstombs(str, text1, text1_index + 1);
free(text);
free(text1);
return 0;
}

104
common/string_calls.h Normal file
View File

@ -0,0 +1,104 @@
/**
* xrdp: A Remote Desktop Protocol server.
*
* Copyright (C) Jay Sorg 2004-2020
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* generic string handling calls
*/
#if !defined(STRING_CALLS_H)
#define STRING_CALLS_H
#include "arch.h"
/**
* Map a character to a string value
*
* This structure is used by g_format_info_string() to specify the
* string which chould be output for %'ch', where ch is a character
*/
struct info_string_tag
{
char ch;
const char *val;
};
#define INFO_STRING_END_OF_LIST { '\0', NULL }
/**
* Processes a format string for general info
*
* @param[out] dest Destination buffer
* @param[in] len Length of buffer, including space for a terminator
* @param[in] format Format string to process
* @param[in] map Array of struct info_string_tag.
*
* Where a '%<ch>' is encountered in the format string, the map is scanned
* and the corresponding string is copied instead of '%<ch>'.
*
* '%%' is always replaced with a single '%' in the output. %<ch> strings
* not present in the map are ignored.
*
* The map is terminated with INFO_STRING_END_OF_LIST
*
* Caller can check for buffer truncation by comparing the result with
* the buffer length (as in snprintf())
*/
unsigned int
g_format_info_string(char *dest, unsigned int len,
const char *format,
const struct info_string_tag map[]);
/**
* Converts a boolean to a string for output
*
* @param[in] value Value to convert
* @return String representation
*/
const char *
g_bool2text(int value);
/**
* Converts a string to a boolean value
*
* @param[in] s String to convert
* @return machine representation
*/
int
g_text2bool(const char *s);
int g_strlen(const char *text);
const char *g_strchr(const char *text, int c);
char *g_strcpy(char *dest, const char *src);
char *g_strncpy(char *dest, const char *src, int len);
char *g_strcat(char *dest, const char *src);
char *g_strncat(char *dest, const char *src, int len);
char *g_strdup(const char *in);
char *g_strndup(const char *in, const unsigned int maxlen);
int g_strcmp(const char *c1, const char *c2);
int g_strncmp(const char *c1, const char *c2, int len);
int g_strncmp_d(const char *c1, const char *c2, const char delim, int len);
int g_strcasecmp(const char *c1, const char *c2);
int g_strncasecmp(const char *c1, const char *c2, int len);
int g_atoi(const char *str);
int g_htoi(char *str);
int g_bytes_to_hexstr(const void *bytes, int num_bytes, char *out_str,
int bytes_out_str);
int g_pos(const char *str, const char *to_find);
int g_mbstowcs(twchar *dest, const char *src, int n);
int g_wcstombs(char *dest, const twchar *src, int n);
int g_strtrim(char *str, int trim_flags);
#endif

View File

@ -23,6 +23,7 @@
#endif
#include "os_calls.h"
#include "string_calls.h"
#include "trans.h"
#include "arch.h"
#include "parse.h"

View File

@ -246,8 +246,27 @@ Following parameters can be used in the \fB[Chansrv]\fR section.
.TP
\fBFuseMountName\fR=\fIstring\fR
Directory for drive redirection, relative to the user home directory.
Directory for drive redirection.
Created if it doesn't exist. If not specified, defaults to \fIxrdp_client\fR.
If first character is not a '/', this is relative to $HOME.
.P
.RS
If first character is a '/' this is an absolute path. The following
substitutions are made in this string:-
%U - Username
%u - Numeric UID
%% - Percent character
.P
If this format is used:-
.HP 3
1) The directory path permissions MUST be configured correctly by
the system administrator or the system itself - xrdp-chansrv will not
do this for you (although it will create the final directories owned by
the user).
.HP 3
2) The desktop may not automatically display a link for the redirected
drive. To fix this, consult the docs for your chosen desktop.
.RE
.TP
\fBFileUmask\fR=\fImode\fR
@ -257,6 +276,21 @@ files on your redirected drives. This may not be approprate for all
environents, and so you can change this value to allow other users to
access your remote files if required.
.TP
\fBEnableFuseMount\fR=\fI[true|false]\fR
Defaults to \fItrue\fR.
Set to \fIfalse\fR to disable xrdp-chansrv's use of the FUSE system
feature, even if it has been built with this feature enabled.
.P
.RS
Setting this value to \fIfalse\fR will disable the following application
features:-
.P
- drive redirection
.P
- copying-and-pasting of files
.RE
.SH "SESSIONS VARIABLES"
All entries in the \fB[SessionVariables]\fR section are set as
environment variables in the user's session.

View File

@ -30,6 +30,7 @@
#endif
#include "os_calls.h"
#include "string_calls.h"
#include "ssl_calls.h"
#include "arch.h"
#include "list.h"

View File

@ -23,6 +23,7 @@
#endif
#include "libxrdp.h"
#include "string_calls.h"
#include "xrdp_orders_rail.h"
#include "ms-rdpbcgr.h"

View File

@ -23,6 +23,7 @@
#endif
#include "libxrdp.h"
#include "string_calls.h"
/* todo, move these to constants.h */
//#define CHANNEL_CHUNK_LENGTH 1600 /* todo, why is this so small? */

View File

@ -23,6 +23,7 @@
#include "libxrdp.h"
#include "ms-rdpegdi.h"
#include "xrdp_rail.h"
#include "string_calls.h"
/* [MS-RDPERP]: Remote Desktop Protocol:
Remote Programs Virtual Channel Extension

View File

@ -26,6 +26,7 @@
#include "ms-rdpbcgr.h"
#include "log.h"
#include "ssl_calls.h"
#include "string_calls.h"
#if defined(XRDP_NEUTRINORDP)
#include <freerdp/codec/rfx.h>

View File

@ -25,6 +25,7 @@
#include "libxrdp.h"
#include "ms-rdpbcgr.h"
#include "log.h"
#include "string_calls.h"
#define LOG_LEVEL 1
#define LLOG(_level, _args) \

View File

@ -26,6 +26,7 @@
#include "xrdp_rail.h"
#include "trans.h"
#include "log.h"
#include "string_calls.h"
#include <freerdp/settings.h>
#if defined(VERSION_STRUCT_RDP_FREERDP)

View File

@ -29,6 +29,7 @@
#endif
#include "sesman.h"
#include "string_calls.h"
extern struct config_sesman *g_cfg; /* in sesman.c */

View File

@ -23,6 +23,7 @@
#include "arch.h"
#include "os_calls.h"
#include "string_calls.h"
#include "thread_calls.h"
#include "trans.h"
#include "chansrv.h"

View File

@ -31,10 +31,12 @@
#include "os_calls.h"
#include "chansrv_config.h"
#include "string_calls.h"
/* Default settings */
#define DEFAULT_USE_UNIX_SOCKET 0
#define DEFAULT_RESTRICT_OUTBOUND_CLIPBOARD 0
#define DEFAULT_ENABLE_FUSE_MOUNT 1
#define DEFAULT_FUSE_MOUNT_NAME "xrdp-client"
#define DEFAULT_FILE_UMASK 077
@ -155,6 +157,10 @@ read_config_chansrv(log_func_t logmsg,
const char *name = (const char *)list_get_item(names, index);
const char *value = (const char *)list_get_item(values, index);
if (g_strcasecmp(name, "EnableFuseMount") == 0)
{
cfg->enable_fuse_mount = g_text2bool(value);
}
if (g_strcasecmp(name, "FuseMountName") == 0)
{
g_free(cfg->fuse_mount_name);
@ -196,6 +202,7 @@ new_config(void)
else
{
cfg->use_unix_socket = DEFAULT_USE_UNIX_SOCKET;
cfg->enable_fuse_mount = DEFAULT_ENABLE_FUSE_MOUNT;
cfg->restrict_outbound_clipboard = DEFAULT_RESTRICT_OUTBOUND_CLIPBOARD;
cfg->fuse_mount_name = fuse_mount_name;
cfg->file_umask = DEFAULT_FILE_UMASK;
@ -271,13 +278,16 @@ void
config_dump(struct config_chansrv *config)
{
g_writeln("Global configuration:");
g_writeln(" UseUnixSocket (derived): %d", config->use_unix_socket);
g_writeln(" UseUnixSocket (derived): %s",
g_bool2text(config->use_unix_socket));
g_writeln("\nSecurity configuration:");
g_writeln(" RestrictOutboundClipboard: %d",
config->restrict_outbound_clipboard);
g_writeln(" RestrictOutboundClipboard: %s",
g_bool2text(config->restrict_outbound_clipboard));
g_writeln("\nChansrv configuration:");
g_writeln(" EnableFuseMount %s",
g_bool2text(config->enable_fuse_mount));
g_writeln(" FuseMountName: %s", config->fuse_mount_name);
g_writeln(" FileMask: 0%o", config->file_umask);
}

View File

@ -26,6 +26,9 @@ struct config_chansrv
/** Whether to use a UNIX socket for chansrv */
int use_unix_socket;
/** Whether the FUSE mount is enabled or not */
int enable_fuse_mount;
/** RestrictOutboundClipboard setting from sesman.ini */
int restrict_outbound_clipboard;

View File

@ -144,6 +144,7 @@ void xfuse_devredir_cb_file_close(struct state_close *fip)
#include "arch.h"
#include "os_calls.h"
#include "string_calls.h"
#include "clipboard_file.h"
#include "chansrv_fuse.h"
#include "chansrv_xfs.h"
@ -392,6 +393,8 @@ static const char *filename_on_device(const char *full_path);
static void update_inode_file_attributes(const struct file_attr *fattr,
tui32 change_mask, XFS_INODE *xinode);
static char *get_name_for_entry_in_parent(fuse_ino_t parent, const char *name);
static unsigned int format_user_info(char *dest, unsigned int len,
const char *format);
/*****************************************************************************/
int
@ -446,7 +449,7 @@ xfuse_handle_from_fuse_handle(uint64_t handle)
/**
* Initialize FUSE subsystem
*
* @return 0 on success, -1 on failure
* @return 0 on success, -1 on failure, 1 for feature disabled
*****************************************************************************/
int
@ -458,6 +461,21 @@ xfuse_init(void)
if (g_xfuse_inited)
{
LOG_DEVEL(LOG_LEVEL_DEBUG, "already inited");
return 0;
}
/* This feature may be disabled */
if (!g_cfg->enable_fuse_mount)
{
/*
* Only log the 'disabled mounts' message one time
*/
static int disabled_mounts_msg_shown = 0;
if (!disabled_mounts_msg_shown)
{
LOG(LOG_LEVEL_INFO, "FUSE mounts are disabled by config");
disabled_mounts_msg_shown = 1;
}
return 1;
}
@ -469,13 +487,27 @@ xfuse_init(void)
load_fuse_config();
/* define FUSE mount point to ~/xrdp_client, ~/thinclient_drives */
g_snprintf(g_fuse_root_path, 255, "%s/%s", g_getenv("HOME"), g_cfg->fuse_mount_name);
/* define FUSE mount point */
if (g_cfg->fuse_mount_name[0] == '/')
{
/* String is an absolute path to the mount point containing
* %u or %U characters */
format_user_info(g_fuse_root_path, sizeof(g_fuse_root_path),
g_cfg->fuse_mount_name);
}
else
{
/* mount_name is relative to $HOME, e.g. ~/xrdp_client,
* or ~/thinclient_drives */
g_snprintf(g_fuse_root_path, sizeof(g_fuse_root_path), "%s/%s",
g_getenv("HOME"), g_cfg->fuse_mount_name);
}
g_snprintf(g_fuse_clipboard_path, 255, "%s/.clipboard", g_fuse_root_path);
/* if FUSE mount point does not exist, create it */
if (!g_directory_exist(g_fuse_root_path))
{
(void)g_create_path(g_fuse_root_path);
if (!g_create_dir(g_fuse_root_path))
{
LOG_DEVEL(LOG_LEVEL_ERROR, "mkdir %s failed. If %s is already mounted, you must "
@ -748,23 +780,38 @@ xfuse_file_contents_range(int stream_id, const char *data, int data_bytes)
int
xfuse_add_clip_dir_item(const char *filename, int flags, int size, int lindex)
{
LOG_DEVEL(LOG_LEVEL_DEBUG, "entered: filename=%s flags=%d size=%d lindex=%d",
LOG_DEVEL(LOG_LEVEL_DEBUG,
"entered: filename=%s flags=%d size=%d lindex=%d",
filename, flags, size, lindex);
/* add entry to xrdp_fs */
XFS_INODE *xinode = xfs_add_entry( g_xfs,
g_clipboard_inum, /* parent inode */
filename,
(0666 | S_IFREG));
if (xinode == NULL)
{
LOG_DEVEL(LOG_LEVEL_DEBUG, "failed to create file in xrdp filesystem");
return -1;
}
xinode->size = size;
xinode->lindex = lindex;
int result = -1;
return 0;
if (g_xfs == NULL)
{
LOG_DEVEL(LOG_LEVEL_ERROR,
"xfuse_add_clip_dir_item() called with no filesystem")
}
else
{
/* add entry to xrdp_fs */
XFS_INODE *xinode = xfs_add_entry( g_xfs,
g_clipboard_inum, /* parent inode */
filename,
(0666 | S_IFREG));
if (xinode == NULL)
{
LOG(LOG_LEVEL_INFO,
"failed to create file %s in xrdp filesystem", filename);
}
else
{
xinode->size = size;
xinode->lindex = lindex;
result = 0;
}
}
return result;
}
/**
@ -2609,4 +2656,30 @@ static char *get_name_for_entry_in_parent(fuse_ino_t parent, const char *name)
return result;
}
/*
* Scans a user-provided string substituting %u/%U for UID/username
*/
static unsigned int format_user_info(char *dest, unsigned int len,
const char *format)
{
char uidstr[64];
char username[64];
const struct info_string_tag map[] =
{
{'u', uidstr},
{'U', username},
INFO_STRING_END_OF_LIST
};
int uid = g_getuid();
g_snprintf(uidstr, sizeof(uidstr), "%d", uid);
if (g_getlogin(username, sizeof(username)) != 0)
{
/* Fall back to UID */
g_strncpy(username, uidstr, sizeof(username) - 1);
}
return g_format_info_string(dest, len, format, map);
}
#endif /* end else #ifndef XRDP_FUSE */

View File

@ -169,6 +169,7 @@ x-special/gnome-copied-files
#include "arch.h"
#include "parse.h"
#include "os_calls.h"
#include "string_calls.h"
#include "chansrv.h"
#include "chansrv_config.h"
#include "clipboard.h"

View File

@ -33,6 +33,7 @@
#include "arch.h"
#include "parse.h"
#include "os_calls.h"
#include "string_calls.h"
#include "list.h"
#include "chansrv.h"
#include "clipboard.h"

View File

@ -49,6 +49,7 @@
#include "arch.h"
#include "parse.h"
#include "os_calls.h"
#include "string_calls.h"
#include "log.h"
#include "chansrv.h"
#include "chansrv_fuse.h"

View File

@ -28,6 +28,7 @@
#include "chansrv.h"
#include "parse.h"
#include "os_calls.h"
#include "string_calls.h"
#include "irp.h"
IRP *g_irp_head = NULL;

View File

@ -39,6 +39,7 @@
#include "xcommon.h"
#include "log.h"
#include "os_calls.h"
#include "string_calls.h"
#include "thread_calls.h"
#include "list.h"

View File

@ -28,6 +28,7 @@
#include <string.h>
#include "os_calls.h"
#include "string_calls.h"
#include "smartcard.h"
#include "log.h"
#include "irp.h"

View File

@ -33,6 +33,7 @@
#define PCSC_STANDIN 1
#include "os_calls.h"
#include "string_calls.h"
#include "smartcard.h"
#include "log.h"
#include "irp.h"

View File

@ -33,6 +33,7 @@
#include "file.h"
#include "sesman.h"
#include "log.h"
#include "string_calls.h"
/***************************************************************************//**
*

View File

@ -34,6 +34,7 @@
#include "list.h"
#include "sesman.h"
#include "ssl_calls.h"
#include "string_calls.h"
extern unsigned char g_fixedkey[8]; /* in sesman.c */
extern struct config_sesman *g_cfg; /* in sesman.c */

View File

@ -29,6 +29,7 @@
#endif
#include "libscp_session.h"
#include "string_calls.h"
#include <sys/types.h>
#include <sys/socket.h>

View File

@ -31,6 +31,7 @@
#include "libscp_v0.h"
#include "os_calls.h"
#include "string_calls.h"
extern struct log_config *s_log;

View File

@ -29,6 +29,7 @@
#endif
#include "libscp_v1c.h"
#include "string_calls.h"
#include <stdlib.h>
#include <stdio.h>

View File

@ -29,6 +29,7 @@
#endif
#include "libscp_v1c_mng.h"
#include "string_calls.h"
#include <stdlib.h>
#include <stdio.h>

View File

@ -32,6 +32,7 @@
#define LIBSCP_V1S_C
#include "libscp_v1s.h"
#include "string_calls.h"
//extern struct log_config* s_log;

View File

@ -32,6 +32,7 @@
#define LIBSCP_V1S_MNG_C
#include "libscp_v1s_mng.h"
#include "string_calls.h"
//extern struct log_config* s_log;

View File

@ -32,6 +32,7 @@
#include "sesman.h"
#include "xrdp_configure_options.h"
#include "string_calls.h"
struct sesman_startup_params
{

View File

@ -114,11 +114,16 @@ param=-dpi
param=96
[Chansrv]
; drive redirection, defaults to xrdp_client if not set
; drive redirection
; See sesman.ini(5) for the format of this parameter
#FuseMountName=/run/user/%u/thinclient_drives
#FuseMountName=/media/thinclient_drives/%U/thinclient_drives
FuseMountName=thinclient_drives
; this value allows only the user to acess their own mapped drives.
; Make this more permissive (e.g. 022) if required.
FileUmask=077
; Can be used to disable FUSE functionality - see sesman.ini(5)
#EnableFuseMount=false
[ChansrvLogging]
; Note: one log file is created per display and the LogFile config value

View File

@ -41,6 +41,7 @@
#include "libscp_types.h"
#include "xauth.h"
#include "xrdp_sockets.h"
#include "string_calls.h"
#ifndef PR_SET_NO_NEW_PRIVS
#define PR_SET_NO_NEW_PRIVS 38

View File

@ -27,6 +27,7 @@
#include "parse.h"
#include "log.h"
#include "libscp.h"
#include "string_calls.h"
#include <stdio.h>
#include <unistd.h>

View File

@ -37,6 +37,7 @@
#include "config.h"
#include "log.h"
#include "tcp.h"
#include "string_calls.h"
#if !defined(PACKAGE_VERSION)
#define PACKAGE_VERSION "???"

View File

@ -26,6 +26,7 @@
#include "libscp.h"
#include "parse.h"
#include "log.h"
#include "string_calls.h"
#include <stdio.h>

View File

@ -30,6 +30,7 @@
#include "arch.h"
#include "os_calls.h"
#include "string_calls.h"
#include <stdio.h>
#include <security/pam_appl.h>

View File

@ -30,6 +30,7 @@
#include <stdio.h>
#include "log.h"
#include "os_calls.h"
#include "string_calls.h"
/******************************************************************************/

View File

@ -34,6 +34,7 @@
#include "log.h"
#include "trans.h"
#include "ssl_calls.h"
#include "string_calls.h"
#include "xrdp_client_info.h"
#define LLOG_LEVEL 1

View File

@ -23,6 +23,7 @@
#endif
#include "xrdp.h"
#include "string_calls.h"
/*****************************************************************************/
/* returns boolean */

View File

@ -26,6 +26,7 @@
#include "xrdp.h"
#include "ms-rdpbcgr.h"
#include "log.h"
#include "string_calls.h"
/* map for rdp to x11 scancodes
code1 is regular scancode, code2 is extended scancode */

View File

@ -27,6 +27,7 @@
#include "xrdp.h"
#include "log.h"
#include "xrdp_configure_options.h"
#include "string_calls.h"
#if !defined(PACKAGE_VERSION)
#define PACKAGE_VERSION "???"

View File

@ -29,6 +29,7 @@
#include "xrdp.h"
#include "log.h"
#include "string_calls.h"
#define LLOG_LEVEL 1
#define LLOGLN(_level, _args) \

View File

@ -24,6 +24,7 @@
#include "xrdp.h"
#include "log.h"
#include "string_calls.h"
/* 'g_process' is protected by the semaphore 'g_process_sem'. One thread sets
g_process and waits for the other to process it */

View File

@ -25,6 +25,7 @@
#include "base64.h"
#include "xrdp.h"
#include "log.h"
#include "string_calls.h"
#define ASK "ask"
#define ASK_LEN g_strlen(ASK)

View File

@ -23,6 +23,7 @@
#endif
#include "xrdp.h"
#include "log.h"
#include "string_calls.h"
#ifndef USE_NOPAM
#if defined(HAVE__PAM_TYPES_H)

View File

@ -23,6 +23,7 @@
#endif
#include "xrdp.h"
#include "string_calls.h"
#if defined(XRDP_PAINTER)
#include <painter.h> /* libpainter */

View File

@ -27,6 +27,7 @@
#include "xrdp.h"
#include "ms-rdpbcgr.h"
#include "log.h"
#include "string_calls.h"
#define LLOG_LEVEL 1
#define LLOGLN(_level, _args) \

View File

@ -25,6 +25,7 @@
#include "xup.h"
#include "log.h"
#include "trans.h"
#include "string_calls.h"
#define LOG_LEVEL 1
#define LLOG(_level, _args) \