Hi, I have managed to get dillo.cc to use the 'save_dir' preference to set which download path is unveiled. This was done by moving the unveil call to a point after which prefs are initialized and dillorc is parsed. Here is what the patch looks like: --- dillo.cc Sat Jun 29 16:33:08 2024 +++ dillo.cc Tue Jul 30 14:18:28 2024 @@ -23,6 +23,7 @@ #include <stdio.h> #include <unistd.h> +#include <err.h> #include <stdlib.h> #include <time.h> #include <sys/types.h> @@ -463,6 +464,58 @@ int main(int argc, char **argv) } dLib_show_messages(prefs.show_msg); + // Use unveil on OpenBSD + #ifdef __OpenBSD__ + if (unveil("/usr/local/share/fonts", "r") == -1) { + err(1, "unveil failed"); + } + if (unveil("/usr/local/share/icons", "r") == -1) { + err(1, "unveil failed"); + } + if (unveil("/usr/X11R6/share/X11/locale", "r") == -1) { + err(1, "unveil failed"); + } + if (unveil("/usr/X11R6/lib/X11/fonts", "r") == -1) { + err(1, "unveil failed"); + } + if (unveil("/usr/local/etc/dillo", "r") == -1) { + err(1, "unveil failed"); + } + if (unveil("/tmp", "rwc") == -1) { + err(1, "unveil failed"); + } + if (unveil("/usr/local/bin/dpid", "x") == -1) { + err(1, "unveil failed"); + } + if (unveil("/etc/fonts", "r") == -1) { + err(1, "unveil failed"); + } + if (unveil("/etc/resolv.conf", "r") == -1) { + err(1, "unveil failed"); + } + if (unveil("/etc/ssl/cert.pem", "r") == -1) { + err(1, "unveil failed"); + } + if (unveil(prefs.save_dir, "rwc") == -1) { + err(1, "unveil failed"); + } + char *dil_loc = dStrconcat(dGethomedir(), "/.dillo", NULL); + if (unveil(dil_loc, "rwc") == -1) { + err(1, "unveil failed"); + } + dFree(dil_loc); + char *icons_loc = dStrconcat(dGethomedir(), "/.icons", NULL); + if (unveil(icons_loc, "r") == -1) { + err(1, "unveil failed"); + } + dFree(icons_loc); + char *xauth_loc = dStrconcat(dGethomedir(), "/.Xauthority", NULL); + if (unveil(xauth_loc, "r") == -1) { + err(1, "unveil failed"); + } + dFree(xauth_loc); + #endif + // initialize internal modules a_Dpi_init(); a_Dns_init(); I have tried to do the same for downloads.cc, but haven't quite got it yet. Since prefs are not initialized in downloads.cc, I tried to copy that from dillo.cc, but am getting some linker errors when compliling. I probably missed something obvious. Any ideas? ld: error: undefined symbol: a_Prefs_init
referenced by downloads.cc downloads_dpi-downloads.o:(main) mv -f .deps/vsource.Tpo .deps/vsource.Po
ld: error: undefined symbol: Paths::init()
referenced by downloads.cc downloads_dpi-downloads.o:(main)
ld: error: undefined symbol: Paths::getPrefsFP(char const*)
referenced by downloads.cc downloads_dpi-downloads.o:(main)
ld: error: undefined symbol: PrefsParser::parse(__sFILE*)
referenced by downloads.cc downloads_dpi-downloads.o:(main)
ld: error: undefined symbol: prefs
referenced by downloads.cc downloads_dpi-downloads.o:(main) c++: error: linker command failed with exit code 1 (use -v to see invocation)
Here is what I tried: --- downloads.cc Sat Jun 29 16:33:08 2024 +++ downloads.cc Tue Jul 30 15:07:04 2024 @@ -18,6 +18,7 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> +#include <err.h> #include <errno.h> #include <fcntl.h> #include <ctype.h> @@ -42,6 +43,9 @@ #include <FL/Fl_Box.H> #include <FL/Fl_Button.H> +#include "../src/paths.hh" +#include "../src/prefs.h" +#include "../src/prefsparser.hh" #include "config.h" #include "dpiutil.h" #include "../dpip/dpip.h" @@ -1104,6 +1108,48 @@ static void custLabelMeasure(const Fl_Label* o, int& W int main() { int ww = 420, wh = 85; + FILE *fp; + + // set the default values for the preferences + a_Prefs_init(); + + // create ~/.dillo if not present + Paths::init(); + + // parse dillorc + if ((fp = Paths::getPrefsFP(PATHS_RC_PREFS))) { + PrefsParser::parse(fp); + } + + /* Use unveil on OpenBSD */ + #ifdef __OpenBSD__ + if (unveil("/tmp", "rwc") == -1) { + err(1, "unveil failed"); + } + if (unveil("/etc/fonts", "r") == -1) { + err(1, "unveil failed"); + } + if (unveil("/usr/local/bin/wget", "x") == -1) { + err(1, "unveil failed"); + } + char *xauth_loc = dStrconcat(dGethomedir(), "/.Xauthority", NULL); + if (unveil(xauth_loc, "r") == -1) { + err(1, "unveil failed"); + } + dFree(xauth_loc); + if (unveil("/usr/local/share/fonts", "r") == -1) { + err(1, "unveil failed"); + } + char *dil_loc = dStrconcat(dGethomedir(), "/.dillo", NULL); + if (unveil(dil_loc, "rwc") == -1) { + err(1, "unveil failed"); + } + dFree(dil_loc); + if (unveil(prefs.save_dir, "rwc") == -1) { + err(1, "unveil failed"); + } + unveil(NULL, NULL); + #endif Fl::lock(); Finally, I tried to also get ftp.c to use the 'save_dir' preference, but had less luck. I think the issue comes from the fact that this is a C program, and the others are C++. I'm wondering, is this whole unveil idea realistic at this point? Maybe I'm just too inexperienced to be doing this work. I am quite willing to keep going, but it will probably involve many more messages to the list with problems similar to the ones above. I don't want to overwhelm the list and devs with my beginner programming mistakes, it feels like I'm placing an unfair burden on you. Regards, Alex
participants (1)
-
a1ex@dismail.de