Skip to content

Commit

Permalink
Add sesman.ini FuseMountNameColonCharReplacement option
Browse files Browse the repository at this point in the history
  • Loading branch information
Bad-ptr committed Jan 7, 2025
1 parent e3d502c commit 7769021
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 3 deletions.
9 changes: 9 additions & 0 deletions docs/man/sesman.ini.5.in
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,15 @@ the user).
drive. To fix this, consult the docs for your chosen desktop.
.RE

.TP
\fBFuseMountNameColonCharReplacement\fR=\fIstring\fR
Character to replace colon in redirected drive mount point names.
If not specified no colon will not be replaced.
If empty then colon will be replaced by null character.
If longer than one character, only first character used.
Only last colon replaced.
.RE

.TP
\fBFuseDirectIO\fR=\fI[false|true]\fR
Defaults to \fIfalse\fR. Set to \fItrue\fR to disable page caching in
Expand Down
20 changes: 20 additions & 0 deletions sesman/chansrv/chansrv_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#define DEFAULT_RESTRICT_INBOUND_CLIPBOARD 0
#define DEFAULT_ENABLE_FUSE_MOUNT 1
#define DEFAULT_FUSE_MOUNT_NAME "xrdp-client"
#define DEFAULT_FUSE_MOUNT_NAME_COLON_CHAR_REPLACEMENT ':'
#define DEFAULT_FUSE_DIRECT_IO 0
#define DEFAULT_FILE_UMASK 077
#define DEFAULT_USE_NAUTILUS3_FLIST_FORMAT 0
Expand Down Expand Up @@ -220,6 +221,22 @@ read_config_chansrv(log_func_t logmsg,
break;
}
}
else if (g_strcasecmp(name, "FuseMountNameColonCharReplacement") == 0)
{
size_t vallen = g_strlen(value);
if (vallen < 1) {
cfg->fuse_mount_name_colon_char_replacement = '\0';
}
else {
if (vallen > 1) {
logmsg(LOG_LEVEL_WARNING, "FuseMountNameColonCharReplacement "
"must be 1 character length, now it is '%s'."
"Only first char will be used!",
value);
}
cfg->fuse_mount_name_colon_char_replacement = value[0];
}
}
else if (g_strcasecmp(name, "FuseDirectIO") == 0)
{
cfg->fuse_direct_io = g_text2bool(value);
Expand Down Expand Up @@ -299,6 +316,7 @@ new_config(void)
/* Do all the allocations at the beginning, then check them together */
struct config_chansrv *cfg = g_new0(struct config_chansrv, 1);
char *fuse_mount_name = g_strdup(DEFAULT_FUSE_MOUNT_NAME);
char fuse_mount_name_colon_char_replacement = DEFAULT_FUSE_MOUNT_NAME_COLON_CHAR_REPLACEMENT;
char *log_file_path = g_strdup(DEFAULT_LOG_FILE_PATH);
if (cfg == NULL || fuse_mount_name == NULL || log_file_path == NULL)
{
Expand All @@ -315,6 +333,7 @@ new_config(void)
cfg->restrict_outbound_clipboard = DEFAULT_RESTRICT_OUTBOUND_CLIPBOARD;
cfg->restrict_inbound_clipboard = DEFAULT_RESTRICT_INBOUND_CLIPBOARD;
cfg->fuse_mount_name = fuse_mount_name;
cfg->fuse_mount_name_colon_char_replacement = fuse_mount_name_colon_char_replacement;
cfg->fuse_direct_io = DEFAULT_FUSE_DIRECT_IO;
cfg->file_umask = DEFAULT_FILE_UMASK;
cfg->use_nautilus3_flist_format = DEFAULT_USE_NAUTILUS3_FLIST_FORMAT;
Expand Down Expand Up @@ -419,6 +438,7 @@ config_dump(struct config_chansrv *config)
g_writeln(" EnableFuseMount %s",
g_bool2text(config->enable_fuse_mount));
g_writeln(" FuseMountName: %s", config->fuse_mount_name);
g_writeln(" FuseMountNameColonCharReplacement: %c", config->fuse_mount_name_colon_char_replacement);
g_writeln(" FuseDirectIO: %s",
g_bool2text(config->fuse_direct_io));
g_writeln(" FileMask: 0%o", config->file_umask);
Expand Down
2 changes: 2 additions & 0 deletions sesman/chansrv/chansrv_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ struct config_chansrv

/** * FuseMountName from sesman.ini */
char *fuse_mount_name;
/** * FuseMountNameColonCharReplacement from sesman.ini */
char fuse_mount_name_colon_char_replacement;
/** FileUmask from sesman.ini */
mode_t file_umask;

Expand Down
36 changes: 33 additions & 3 deletions sesman/chansrv/chansrv_fuse.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,31 @@ int xfuse_path_in_xfuse_fs(const char *path)
#define XFUSE_ENTRY_TIMEOUT 5.0


extern struct config_chansrv *g_cfg; /* in chansrv.c */


/* Local utility functions */

static inline char* _fuse_mount_name_colon_char_replace(const char *dirname,
size_t dirnamelen)
{
char *newdirname = (char*)dirname;
if (g_cfg->fuse_mount_name_colon_char_replacement != ':' && dirnamelen > 0)
{
newdirname = g_strdup(dirname);
for (size_t i = dirnamelen-1; i >= 0; --i) {
if (':' == newdirname[i]) {
newdirname[i] = g_cfg->fuse_mount_name_colon_char_replacement;
break;
}
}
}
return newdirname;
}

/* End of Local utility functions*/


/* Type of buffer used for fuse_add_direntry() calls */
struct dirbuf1
{
Expand Down Expand Up @@ -343,7 +368,6 @@ struct req_list_item
int size;
};

extern struct config_chansrv *g_cfg; /* in chansrv.c */

static struct list *g_req_list = 0;
static struct xfs_fs *g_xfs; /* an inst of xrdp file system */
Expand Down Expand Up @@ -738,11 +762,17 @@ int xfuse_create_share(tui32 device_id, const char *dirname)
{
int result = -1;
XFS_INODE *xinode;
size_t dirnamelen = strlen(dirname);

if (dirname != NULL && strlen(dirname) > 0 &&
if (dirname != NULL && dirnamelen > 0 &&
xfuse_init_xrdp_fs() == 0)
{
xinode = xfs_add_entry(g_xfs, FUSE_ROOT_ID, dirname, (0777 | S_IFDIR));
char *newdirname = _fuse_mount_name_colon_char_replace(dirname, dirnamelen);
xinode = xfs_add_entry(g_xfs, FUSE_ROOT_ID, newdirname, (0777 | S_IFDIR));
if (newdirname != dirname)
{
g_free(newdirname);
}
if (xinode == NULL)
{
LOG_DEVEL(LOG_LEVEL_DEBUG, "xfs_add_entry() failed");
Expand Down
1 change: 1 addition & 0 deletions sesman/sesman.ini.in
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ param=96
#FuseMountName=/run/user/%u/thinclient_drives
#FuseMountName=/media/thinclient_drives/%U/thinclient_drives
FuseMountName=thinclient_drives
#FuseMountNameColonCharReplacement=
; this value allows only the user to access their own mapped drives.
; Make this more permissive (e.g. 022) if required.
FileUmask=077
Expand Down

0 comments on commit 7769021

Please sign in to comment.