Store sandbox mode

This commit is contained in:
Sebastian Ramacher 2018-05-22 17:45:22 +02:00
parent 753ca0f315
commit 0dfafe6cfb
5 changed files with 31 additions and 12 deletions

View file

@ -280,14 +280,10 @@ cmd_print(girara_session_t* session, girara_list_t* UNUSED(argument_list))
return false; return false;
} }
char* sandbox = NULL; if (zathura->global.sandbox == ZATHURA_SANDBOX_STRICT) {
girara_setting_get(zathura->ui.session, "sandbox", &sandbox);
if (g_strcmp0(sandbox, "strict") == 0) {
girara_notify(zathura->ui.session, GIRARA_ERROR, _("Printing is not permitted in strict sandbox mode")); girara_notify(zathura->ui.session, GIRARA_ERROR, _("Printing is not permitted in strict sandbox mode"));
g_free(sandbox);
return false; return false;
} }
g_free(sandbox);
print(zathura); print(zathura);

View file

@ -103,6 +103,26 @@ cb_incsearch_changed(girara_session_t* session, const char* UNUSED(name),
girara_special_command_add(session, '?', cmd_search, inc_search, BACKWARD, NULL); girara_special_command_add(session, '?', cmd_search, inc_search, BACKWARD, NULL);
} }
static void
cb_sandbox_changed(girara_session_t* session, const char* UNUSED(name),
girara_setting_type_t UNUSED(type), void* value, void* UNUSED(data))
{
g_return_if_fail(value != NULL);
g_return_if_fail(session != NULL);
g_return_if_fail(session->global.data != NULL);
zathura_t* zathura = session->global.data;
const char* sandbox = value;
if (g_strcmp0(sandbox, "none") == 0) {
zathura->global.sandbox = ZATHURA_SANDBOX_NONE;
} else if (g_strcmp0(sandbox, "normal") == 0) {
zathura->global.sandbox = ZATHURA_SANDBOX_NORMAL;
} else if (g_strcmp0(sandbox, "strict") == 0) {
zathura->global.sandbox = ZATHURA_SANDBOX_STRICT;
} else {
girara_error("Invalid sandbox option");
}
}
void void
config_load_default(zathura_t* zathura) config_load_default(zathura_t* zathura)
@ -249,7 +269,7 @@ config_load_default(zathura_t* zathura)
girara_setting_add(gsession, "selection-clipboard", string_value, STRING, false, _("The clipboard into which mouse-selected data will be written"), NULL, NULL); girara_setting_add(gsession, "selection-clipboard", string_value, STRING, false, _("The clipboard into which mouse-selected data will be written"), NULL, NULL);
bool_value = true; bool_value = true;
girara_setting_add(gsession, "selection-notification", &bool_value, BOOLEAN, false, _("Enable notification after selecting text"), NULL, NULL); girara_setting_add(gsession, "selection-notification", &bool_value, BOOLEAN, false, _("Enable notification after selecting text"), NULL, NULL);
girara_setting_add(gsession, "sandbox", "normal", STRING, true, _("Sandbox level"), NULL, NULL); girara_setting_add(gsession, "sandbox", "normal", STRING, true, _("Sandbox level"), cb_sandbox_changed, NULL);
#define DEFAULT_SHORTCUTS(mode) \ #define DEFAULT_SHORTCUTS(mode) \
girara_shortcut_add(gsession, 0, GDK_KEY_a, NULL, sc_adjust_window, (mode), ZATHURA_ADJUST_BESTFIT, NULL); \ girara_shortcut_add(gsession, 0, GDK_KEY_a, NULL, sc_adjust_window, (mode), ZATHURA_ADJUST_BESTFIT, NULL); \

View file

@ -135,10 +135,6 @@ zathura_link_evaluate(zathura_t* zathura, zathura_link_t* link)
bool link_zoom = true; bool link_zoom = true;
girara_setting_get(zathura->ui.session, "link-zoom", &link_zoom); girara_setting_get(zathura->ui.session, "link-zoom", &link_zoom);
/* required below to prevent opening hyperlinks in strict sandbox mode */
char* sandbox = NULL;
girara_setting_get(zathura->ui.session, "sandbox", &sandbox);
switch (link->type) { switch (link->type) {
case ZATHURA_LINK_GOTO_DEST: case ZATHURA_LINK_GOTO_DEST:
if (link->target.destination_type != ZATHURA_LINK_DESTINATION_UNKNOWN) { if (link->target.destination_type != ZATHURA_LINK_DESTINATION_UNKNOWN) {
@ -207,7 +203,7 @@ zathura_link_evaluate(zathura_t* zathura, zathura_link_t* link)
link_remote(zathura, link->target.value); link_remote(zathura, link->target.value);
break; break;
case ZATHURA_LINK_URI: case ZATHURA_LINK_URI:
if (g_strcmp0(sandbox, "strict") == 0) { if (zathura->global.sandbox == ZATHURA_SANDBOX_STRICT) {
girara_notify(zathura->ui.session, GIRARA_ERROR, _("Opening external applications in strict sandbox mode is not permitted")); girara_notify(zathura->ui.session, GIRARA_ERROR, _("Opening external applications in strict sandbox mode is not permitted"));
} else { } else {
if (girara_xdg_open(link->target.value) == false) { if (girara_xdg_open(link->target.value) == false) {
@ -221,7 +217,6 @@ zathura_link_evaluate(zathura_t* zathura, zathura_link_t* link)
default: default:
break; break;
} }
g_free(sandbox);
} }
void void

View file

@ -87,6 +87,7 @@ zathura_create(void)
/* global settings */ /* global settings */
zathura->global.search_direction = FORWARD; zathura->global.search_direction = FORWARD;
zathura->global.sandbox = ZATHURA_SANDBOX_NORMAL;
/* plugins */ /* plugins */
zathura->plugins.manager = zathura_plugin_manager_new(); zathura->plugins.manager = zathura_plugin_manager_new();

View file

@ -82,6 +82,12 @@ enum {
ZATHURA_PAGE_THUMBNAIL_DEFAULT_SIZE = 4*1024*1024 ZATHURA_PAGE_THUMBNAIL_DEFAULT_SIZE = 4*1024*1024
}; };
typedef enum {
ZATHURA_SANDBOX_NONE,
ZATHURA_SANDBOX_NORMAL,
ZATHURA_SANDBOX_STRICT
} zathura_sandbox_t;
/* forward declaration for types from database.h */ /* forward declaration for types from database.h */
typedef struct _ZathuraDatabase zathura_database_t; typedef struct _ZathuraDatabase zathura_database_t;
@ -138,6 +144,7 @@ struct zathura_s
int search_direction; /**< Current search direction (FORWARD or BACKWARD) */ int search_direction; /**< Current search direction (FORWARD or BACKWARD) */
girara_list_t* marks; /**< Marker */ girara_list_t* marks; /**< Marker */
char** arguments; /**> Arguments that were passed at startup */ char** arguments; /**> Arguments that were passed at startup */
zathura_sandbox_t sandbox; /**< Sandbox mode */
} global; } global;
struct struct