Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow overriding configuration file #47

Merged
merged 3 commits into from
Jul 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 55 additions & 53 deletions gui-daemon/guid.conf
Original file line number Diff line number Diff line change
@@ -1,57 +1,59 @@
# Default configuration file for Qubes GUI daemon
# For syntax go http://www.hyperrealm.com/libconfig/libconfig_manual.html
# (For syntax go http://www.hyperrealm.com/libconfig/libconfig_manual.html)

# EDITING THIS FILE WILL NOT HAVE ANY EFFECT! It is not read by the GUI daemon
# anymore, and is left here for reference only. To configure the GUI daemon,
# use qvm-features (see 'man qvm-features' for details).

global: {
# default values
#allow_fullscreen = false;
#override_redirect_protection = true;
#allow_utf8_titles = false;
# Change the lines below to change the secure copy and paste keyboard shortcuts
# Before changing secure_(copy|paste)_sequence below because you need
# Ctrl-Shift-(c|v) for normal terminal copy&paste, please note that you
# can also use Ctrl-Ins and Shift-Ins for that (thus: no need to change).
# If you still want to change, here is a list of valid modifier key names:
# "Ctrl", "Shift", "Mod4" (Windows key)
#secure_copy_sequence = "Ctrl-Shift-c";
#secure_paste_sequence = "Ctrl-Shift-v";
#windows_count_limit = 500;
#audio_low_latency = true;
# Change the line below to set how tray icons are handled
# see `man qubes-guid` for options
#trayicon_mode = "border1";
#startup_timeout = 45;
};

# most of setting can be set per-VM basis

VM: {
# Example of a VM with UTF-8 title characters allowed
#example-work-vm: {
# allow_utf8_titles = true;
#};
# Example of a VM with full screen access
# see https://www.qubes-os.org/doc/full-screen-mode/
# for discussion of risks and alternatives
#example-media-vm: {
# allow_fullscreen = true;
#};
# Example of a VM that may create very large windows that
# have the override_redirect flag set. This flag allows a
# window to unconditionally cover all other windows and
# causes the window manager to make it impossible to
# minimize or hide the window in question.
#
# Qubes OS will prevent a window having the override_redirect
# flag set from covering more than 90% of the screen as a
# protection measure. The protection measure unsets this
# flag and lets the window manager (and hence the user)
# control the window.
#
# If this causes issues with a VM's or an application's usage,
# please adapt this example to disable this protection for
# a specific VM.
#example-vm-with-large-unusual-windows: {
# override_redirect_protection = false;
#}
};
# Allow full-screen access
#
# See https://www.qubes-os.org/doc/full-screen-mode/
# for discussion of risks and alternatives.
#
# allow_fullscreen = false;

# override_redirect protection
#
# You might disable this for of a VM that may create very large windows that
# have the override_redirect flag set. This flag allows a window to
# unconditionally cover all other windows and causes the window manager to
# make it impossible to minimize or hide the window in question.
#
# Qubes OS will prevent a window having the override_redirect flag set from
# covering more than 90% of the screen as a protection measure. The
# protection measure unsets this flag and lets the window manager (and hence
# the user) control the window.
#
# If this causes issues with a VM's or an application's usage, you can
# disable this protection for a specific VM.
#
# override_redirect_protection = true;

# Allow UTF-8 title characters
#
# allow_utf8_titles = false;

# Secure copy and paste keyboard shortcuts
#
# Before changing secure_(copy|paste)_sequence below because you need
# Ctrl-Shift-(c|v) for normal terminal copy&paste, please note that you can
# also use Ctrl-Ins and Shift-Ins for that (thus: no need to change). If you
# still want to change, here is a list of valid modifier key names: "Ctrl",
# "Shift", "Mod4" (Windows key)
#
# secure_copy_sequence = "Ctrl-Shift-c";
# secure_paste_sequence = "Ctrl-Shift-v";

# Limit number of windows
#
# windows_count_limit = 500;

# Set how tray icons are handled. See `man qubes-guid` for options.
#
# trayicon_mode = "border1";

# Timeout when waiting for qubes-gui-agent
#
# startup_timeout = 45;
}
46 changes: 24 additions & 22 deletions gui-daemon/xside.c
Original file line number Diff line number Diff line change
Expand Up @@ -2943,6 +2943,7 @@ enum {
};

struct option longopts[] = {
{ "config", required_argument, NULL, 'C' },
{ "domid", required_argument, NULL, 'd' },
{ "name", required_argument, NULL, 'N' },
{ "target-domid", required_argument, NULL, 't' },
Expand All @@ -2962,14 +2963,15 @@ struct option longopts[] = {
{ "help", no_argument, NULL, 'h' },
{ 0, 0, 0, 0 },
};
static const char optstring[] = "d:t:N:c:l:i:K:vqQnafIp:Th";
static const char optstring[] = "C:d:t:N:c:l:i:K:vqQnafIp:Th";

static void usage(FILE *stream)
{
fprintf(stream,
"Usage: qubes-guid -d domain_id -N domain_name [options]\n");
fprintf(stream, "\n");
fprintf(stream, "Options:\n");
fprintf(stream, " --config=PATH, -C PATH\tpath to configuration file\n");
fprintf(stream, " --verbose, -v\tincrease log verbosity\n");
fprintf(stream, " --quiet, -q\tdecrease log verbosity\n");
fprintf(stream, " --domid=ID, -d ID\tdomain ID running GUI agent\n");
Expand Down Expand Up @@ -3006,18 +3008,17 @@ static void usage(FILE *stream)
fprintf(stream, "\n");
}

static void parse_cmdline_vmname(Ghandles * g, int argc, char **argv)
static void parse_cmdline_config_path(Ghandles * g, int argc, char **argv)
{
int opt;
optind = 1;
g->vmname[0] = '\0';

while ((opt = getopt_long(argc, argv, optstring, longopts, NULL)) != -1) {
if (opt == 'N') {
strncpy(g->vmname, optarg, sizeof(g->vmname));
g->vmname[sizeof(g->vmname) - 1] = '\0';
if (strcmp(g->vmname, optarg)) {
fprintf(stderr, "domain name too long");
if (opt == 'C') {
strncpy(g->config_path, optarg, sizeof(g->config_path));
g->config_path[sizeof(g->config_path) - 1] = '\0';
if (strcmp(g->config_path, optarg)) {
fprintf(stderr, "config path too long");
exit(1);
}
} else if (opt == 'h') {
Expand Down Expand Up @@ -3149,14 +3150,22 @@ static void parse_cmdline(Ghandles * g, int argc, char **argv)

while ((opt = getopt_long(argc, argv, optstring, longopts, NULL)) != -1) {
switch (opt) {
case 'C':
/* already handled in parse_cmdline_config_path */
break;
case 'd':
g->domid = atoi(optarg);
break;
case 't':
g->target_domid = atoi(optarg);
break;
case 'N':
/* already handled in parse_cmdline_vmname */
strncpy(g->vmname, optarg, sizeof(g->vmname));
g->vmname[sizeof(g->vmname) - 1] = '\0';
if (strcmp(g->vmname, optarg)) {
fprintf(stderr, "domain name too long");
exit(1);
}
break;
case 'c':
g->cmdline_color = optarg;
Expand Down Expand Up @@ -3232,7 +3241,7 @@ static void parse_cmdline(Ghandles * g, int argc, char **argv)

static void load_default_config_values(Ghandles * g)
{

strcpy(g->config_path, GUID_CONFIG_FILE);
g->allow_utf8_titles = 0;
g->copy_seq_mask = ControlMask | ShiftMask;
g->copy_seq_key = XK_c;
Expand Down Expand Up @@ -3343,14 +3352,13 @@ static void parse_config(Ghandles * g)
{
config_t config;
config_setting_t *setting;
char buf[128];

config_init(&config);
#if (((LIBCONFIG_VER_MAJOR == 1) && (LIBCONFIG_VER_MINOR > 5)) \
|| (LIBCONFIG_VER_MAJOR > 1))
config_set_include_dir(&config, GUID_CONFIG_DIR);
#endif
if (config_read_file(&config, GUID_CONFIG_FILE) == CONFIG_FALSE) {
if (config_read_file(&config, g->config_path) == CONFIG_FALSE) {
#if (((LIBCONFIG_VER_MAJOR == 1) && (LIBCONFIG_VER_MINOR >= 4)) \
|| (LIBCONFIG_VER_MAJOR > 1))
if (config_error_type(&config) == CONFIG_ERR_FILE_IO) {
Expand All @@ -3360,7 +3368,7 @@ static void parse_config(Ghandles * g)
#endif
fprintf(stderr,
"Warning: cannot read config file (%s): %s\n",
GUID_CONFIG_FILE,
g->config_path,
config_error_text(&config));
} else {
fprintf(stderr,
Expand All @@ -3369,22 +3377,16 @@ static void parse_config(Ghandles * g)
|| (LIBCONFIG_VER_MAJOR > 1))
config_error_file(&config),
#else
GUID_CONFIG_FILE,
g->config_path,
#endif
config_error_line(&config),
config_error_text(&config));
exit(1);
}
}
// first load global settings
if ((setting = config_lookup(&config, "global"))) {
parse_vm_config(g, setting);
}
// then try to load per-VM settings
snprintf(buf, sizeof(buf), "VM/%s", g->vmname);
if ((setting = config_lookup(&config, buf))) {
parse_vm_config(g, setting);
}
}

/* helper to get a file flag path */
Expand Down Expand Up @@ -3476,8 +3478,8 @@ int main(int argc, char **argv)
int display_num;

load_default_config_values(&ghandles);
/* get the VM name to read the right section in config file */
parse_cmdline_vmname(&ghandles, argc, argv);
/* get the config file path first */
parse_cmdline_config_path(&ghandles, argc, argv);
/* load config file */
parse_config(&ghandles);
/* parse cmdline, possibly overriding values from config */
Expand Down
1 change: 1 addition & 0 deletions gui-daemon/xside.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ struct _global_handles {
int volatile reload_requested;
pid_t pulseaudio_pid;
/* configuration */
char config_path[64]; /* configuration file path (initialized to default) */
int log_level; /* log level */
int startup_timeout;
int nofork; /* do not fork into background - used during guid restart */
Expand Down