Commit 0dfafe6c authored by Sebastian Ramacher's avatar Sebastian Ramacher

Store sandbox mode

parent 753ca0f3
......@@ -280,14 +280,10 @@ cmd_print(girara_session_t* session, girara_list_t* UNUSED(argument_list))
return false;
}
char* sandbox = NULL;
girara_setting_get(zathura->ui.session, "sandbox", &sandbox);
if (g_strcmp0(sandbox, "strict") == 0) {
if (zathura->global.sandbox == ZATHURA_SANDBOX_STRICT) {
girara_notify(zathura->ui.session, GIRARA_ERROR, _("Printing is not permitted in strict sandbox mode"));
g_free(sandbox);
return false;
}
g_free(sandbox);
print(zathura);
......
......@@ -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);
}
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
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);
bool_value = true;
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) \
girara_shortcut_add(gsession, 0, GDK_KEY_a, NULL, sc_adjust_window, (mode), ZATHURA_ADJUST_BESTFIT, NULL); \
......
......@@ -135,10 +135,6 @@ zathura_link_evaluate(zathura_t* zathura, zathura_link_t* link)
bool link_zoom = true;
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) {
case ZATHURA_LINK_GOTO_DEST:
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);
break;
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"));
} else {
if (girara_xdg_open(link->target.value) == false) {
......@@ -221,7 +217,6 @@ zathura_link_evaluate(zathura_t* zathura, zathura_link_t* link)
default:
break;
}
g_free(sandbox);
}
void
......
......@@ -87,6 +87,7 @@ zathura_create(void)
/* global settings */
zathura->global.search_direction = FORWARD;
zathura->global.sandbox = ZATHURA_SANDBOX_NORMAL;
/* plugins */
zathura->plugins.manager = zathura_plugin_manager_new();
......
......@@ -82,6 +82,12 @@ enum {
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 */
typedef struct _ZathuraDatabase zathura_database_t;
......@@ -138,6 +144,7 @@ struct zathura_s
int search_direction; /**< Current search direction (FORWARD or BACKWARD) */
girara_list_t* marks; /**< Marker */
char** arguments; /**> Arguments that were passed at startup */
zathura_sandbox_t sandbox; /**< Sandbox mode */
} global;
struct
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment