From ac68ec0de9249c60c92099ae37d7d4efd34fefcc Mon Sep 17 00:00:00 2001 From: netblue30 Date: Sat, 12 Mar 2016 12:36:16 -0500 Subject: build fixes --- src/firejail/checkcfg.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 src/firejail/checkcfg.c diff --git a/src/firejail/checkcfg.c b/src/firejail/checkcfg.c new file mode 100644 index 000000000..9313bb1a4 --- /dev/null +++ b/src/firejail/checkcfg.c @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2014-2016 Firejail Authors + * + * This file is part of firejail project + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ +#include "firejail.h" +#include + +#define MAX_READ 8192 // line buffer for profile files + +static int initialized = 0; +static int cfg_val[CFG_MAX]; + +int checkcfg(int val) { + EUID_ASSERT(); + assert(val < CFG_MAX); + int line = 0; + + if (!initialized) { + // initialize defaults + int i; + for (i = 0; i < CFG_MAX; i++) + cfg_val[i] = 1; // most of them are enabled by default + + // open configuration file + char *fname; + if (asprintf(&fname, "%s/firejail.config", SYSCONFDIR) == -1) + errExit("asprintf"); + + FILE *fp = fopen(fname, "r"); + if (!fp) { + fprintf(stderr, "Error: Firejail configuration file %s not found\n", fname); + exit(1); + } + + // read configuration file + char buf[MAX_READ]; + while (fgets(buf,MAX_READ, fp)) { + line++; + if (*buf == '#' || *buf == '\n') + continue; + + // parse line + line_remove_spaces(buf); + if (strncmp(buf, "file-transfer ", 14) == 0) { + if (strcmp(buf + 14, "yes") == 0) + cfg_val[CFG_FILE_TRANSFER] = 1; + else if (strcmp(buf + 14, "no") == 0) + cfg_val[CFG_FILE_TRANSFER] = 0; + else + goto errout; + } + else + goto errout; + } + + fclose(fp); + free(fname); + initialized = 1; + } + + return cfg_val[val]; + +errout: + fprintf(stderr, "Error: invalid line %d in firejail configuration file\n", line ); + exit(1); +} + -- cgit v1.2.3-54-g00ecf