iFix the way system files are handled at surf startup. - surf - Surf web browser. Err gopher.r-36.net 70 i Err gopher.r-36.net 70 1Log /scm/surf//log.gph gopher.r-36.net 70 1Files /scm/surf//files.gph gopher.r-36.net 70 1Refs /scm/surf//refs.gph gopher.r-36.net 70 1README /scm/surf//file/README.gph gopher.r-36.net 70 1LICENSE /scm/surf//file/LICENSE.gph gopher.r-36.net 70 i--- Err gopher.r-36.net 70 1commit 8a898ec4dfc7068656681ec94a04f8ed3ebe3b2d /scm/surf//commit/8a898ec4dfc7068656681ec94a04f8ed3ebe3b2d.gph gopher.r-36.net 70 1parent 1554354f1689c2205a809e23d29c9e21d38e0be5 /scm/surf//commit/1554354f1689c2205a809e23d29c9e21d38e0be5.gph gopher.r-36.net 70 hAuthor: Quentin Rameau URL:mailto:quinq@fifth.space gopher.r-36.net 70 iDate: Tue, 13 Oct 2015 21:39:01 +0200 Err gopher.r-36.net 70 i Err gopher.r-36.net 70 iFix the way system files are handled at surf startup. Err gopher.r-36.net 70 i Err gopher.r-36.net 70 i1. Do not chmod existing directories. Err gopher.r-36.net 70 i2. Fix the handling of tilde expansion in paths, don't expand ~foo to Err gopher.r-36.net 70 i $HOME/foo but to foo's home directory. Err gopher.r-36.net 70 i3. Separate the creation of files and directories. We don't have to Err gopher.r-36.net 70 i worry anymore about pathnames having to end with a '/' to be correctly Err gopher.r-36.net 70 i handled. Err gopher.r-36.net 70 i Err gopher.r-36.net 70 iSigned-off-by: Christoph Lohmann <20h@r-36.net> Err gopher.r-36.net 70 i Err gopher.r-36.net 70 iDiffstat: Err gopher.r-36.net 70 i surf.c | 83 +++++++++++++++++++++---------- Err gopher.r-36.net 70 i Err gopher.r-36.net 70 i1 file changed, 56 insertions(+), 27 deletions(-) Err gopher.r-36.net 70 i--- Err gopher.r-36.net 70 1diff --git a/surf.c b/surf.c /scm/surf//file/surf.c.gph gopher.r-36.net 70 i@@ -24,6 +24,8 @@ Err gopher.r-36.net 70 i #include Err gopher.r-36.net 70 i #include Err gopher.r-36.net 70 i #include Err gopher.r-36.net 70 i+#include Err gopher.r-36.net 70 i+#include Err gopher.r-36.net 70 i Err gopher.r-36.net 70 i #include "arg.h" Err gopher.r-36.net 70 i Err gopher.r-36.net 70 i@@ -113,6 +115,7 @@ static void addaccelgroup(Client *c); Err gopher.r-36.net 70 i static void beforerequest(WebKitWebView *w, WebKitWebFrame *f, Err gopher.r-36.net 70 i WebKitWebResource *r, WebKitNetworkRequest *req, Err gopher.r-36.net 70 i WebKitNetworkResponse *resp, Client *c); Err gopher.r-36.net 70 i+static char *buildfile(const char *path); Err gopher.r-36.net 70 i static char *buildpath(const char *path); Err gopher.r-36.net 70 i static gboolean buttonrelease(WebKitWebView *web, GdkEventButton *e, Client *c); Err gopher.r-36.net 70 i static void cleanup(void); Err gopher.r-36.net 70 i@@ -257,37 +260,63 @@ beforerequest(WebKitWebView *w, WebKitWebFrame *f, WebKitWebResource *r, Err gopher.r-36.net 70 i } Err gopher.r-36.net 70 i Err gopher.r-36.net 70 i static char * Err gopher.r-36.net 70 i-buildpath(const char *path) { Err gopher.r-36.net 70 i- char *apath, *p; Err gopher.r-36.net 70 i+buildfile(const char *path) { Err gopher.r-36.net 70 i+ char *dname, *bname, *bpath, *fpath; Err gopher.r-36.net 70 i FILE *f; Err gopher.r-36.net 70 i Err gopher.r-36.net 70 i- /* creating directory */ Err gopher.r-36.net 70 i- if(path[0] == '/') { Err gopher.r-36.net 70 i- apath = g_strdup(path); Err gopher.r-36.net 70 i- } else if(path[0] == '~') { Err gopher.r-36.net 70 i- if(path[1] == '/') { Err gopher.r-36.net 70 i- apath = g_strconcat(g_get_home_dir(), &path[1], NULL); Err gopher.r-36.net 70 i+ dname = g_path_get_dirname(path); Err gopher.r-36.net 70 i+ bname = g_path_get_basename(path); Err gopher.r-36.net 70 i+ Err gopher.r-36.net 70 i+ bpath = buildpath(dname); Err gopher.r-36.net 70 i+ g_free(dname); Err gopher.r-36.net 70 i+ Err gopher.r-36.net 70 i+ fpath = g_build_filename(bpath, bname, NULL); Err gopher.r-36.net 70 i+ g_free(bname); Err gopher.r-36.net 70 i+ Err gopher.r-36.net 70 i+ Err gopher.r-36.net 70 i+ if(!(f = fopen(fpath, "a"))) Err gopher.r-36.net 70 i+ die("Could not open file: %s\n", fpath); Err gopher.r-36.net 70 i+ Err gopher.r-36.net 70 i+ g_chmod(fpath, 0600); /* always */ Err gopher.r-36.net 70 i+ fclose(f); Err gopher.r-36.net 70 i+ Err gopher.r-36.net 70 i+ return fpath; Err gopher.r-36.net 70 i+} Err gopher.r-36.net 70 i+ Err gopher.r-36.net 70 i+static char * Err gopher.r-36.net 70 i+buildpath(const char *path) { Err gopher.r-36.net 70 i+ struct passwd *pw; Err gopher.r-36.net 70 i+ char *apath, *name, *p, *fpath; Err gopher.r-36.net 70 i+ Err gopher.r-36.net 70 i+ if(path[0] == '~') { Err gopher.r-36.net 70 i+ if(path[1] == '/' || path[1] == '\0') { Err gopher.r-36.net 70 i+ p = (char *)&path[1]; Err gopher.r-36.net 70 i+ pw = getpwuid(getuid()); Err gopher.r-36.net 70 i } else { Err gopher.r-36.net 70 i- apath = g_strconcat(g_get_home_dir(), "/", Err gopher.r-36.net 70 i- &path[1], NULL); Err gopher.r-36.net 70 i+ if((p = strchr(path, '/'))) Err gopher.r-36.net 70 i+ name = g_strndup(&path[1], --p - path); Err gopher.r-36.net 70 i+ else Err gopher.r-36.net 70 i+ name = g_strdup(&path[1]); Err gopher.r-36.net 70 i+ Err gopher.r-36.net 70 i+ if(!(pw = getpwnam(name))) { Err gopher.r-36.net 70 i+ die("Can't get user %s home directory: %s.\n", Err gopher.r-36.net 70 i+ name, path); Err gopher.r-36.net 70 i+ } Err gopher.r-36.net 70 i+ g_free(name); Err gopher.r-36.net 70 i } Err gopher.r-36.net 70 i+ apath = g_build_filename(pw->pw_dir, p, NULL); Err gopher.r-36.net 70 i } else { Err gopher.r-36.net 70 i- apath = g_strconcat(g_get_current_dir(), "/", path, NULL); Err gopher.r-36.net 70 i+ apath = g_strdup(path); Err gopher.r-36.net 70 i } Err gopher.r-36.net 70 i Err gopher.r-36.net 70 i- if((p = strrchr(apath, '/'))) { Err gopher.r-36.net 70 i- *p = '\0'; Err gopher.r-36.net 70 i- g_mkdir_with_parents(apath, 0700); Err gopher.r-36.net 70 i- g_chmod(apath, 0700); /* in case it existed */ Err gopher.r-36.net 70 i- *p = '/'; Err gopher.r-36.net 70 i- } Err gopher.r-36.net 70 i- /* creating file (gives error when apath ends with "/") */ Err gopher.r-36.net 70 i- if((f = fopen(apath, "a"))) { Err gopher.r-36.net 70 i- g_chmod(apath, 0600); /* always */ Err gopher.r-36.net 70 i- fclose(f); Err gopher.r-36.net 70 i- } Err gopher.r-36.net 70 i+ /* creating directory */ Err gopher.r-36.net 70 i+ if (g_mkdir_with_parents(apath, 0700) < 0) Err gopher.r-36.net 70 i+ die("Could not access directory: %s\n", apath); Err gopher.r-36.net 70 i+ Err gopher.r-36.net 70 i+ fpath = realpath(apath, NULL); Err gopher.r-36.net 70 i+ g_free(apath); Err gopher.r-36.net 70 i Err gopher.r-36.net 70 i- return apath; Err gopher.r-36.net 70 i+ return fpath; Err gopher.r-36.net 70 i } Err gopher.r-36.net 70 i Err gopher.r-36.net 70 i static gboolean Err gopher.r-36.net 70 i@@ -1221,8 +1250,8 @@ setup(void) { Err gopher.r-36.net 70 i atoms[AtomUri] = XInternAtom(dpy, "_SURF_URI", False); Err gopher.r-36.net 70 i Err gopher.r-36.net 70 i /* dirs and files */ Err gopher.r-36.net 70 i- cookiefile = buildpath(cookiefile); Err gopher.r-36.net 70 i- scriptfile = buildpath(scriptfile); Err gopher.r-36.net 70 i+ cookiefile = buildfile(cookiefile); Err gopher.r-36.net 70 i+ scriptfile = buildfile(scriptfile); Err gopher.r-36.net 70 i cachefolder = buildpath(cachefolder); Err gopher.r-36.net 70 i styledir = buildpath(styledir); Err gopher.r-36.net 70 i if(stylefile == NULL) { Err gopher.r-36.net 70 i@@ -1234,12 +1263,12 @@ setup(void) { Err gopher.r-36.net 70 i styles[i].regex); Err gopher.r-36.net 70 i styles[i].regex = NULL; Err gopher.r-36.net 70 i } Err gopher.r-36.net 70 i- styles[i].style = buildpath( Err gopher.r-36.net 70 i+ styles[i].style = buildfile( Err gopher.r-36.net 70 i g_strconcat(styledir, Err gopher.r-36.net 70 i styles[i].style, NULL)); Err gopher.r-36.net 70 i } Err gopher.r-36.net 70 i } else { Err gopher.r-36.net 70 i- stylefile = buildpath(stylefile); Err gopher.r-36.net 70 i+ stylefile = buildfile(stylefile); Err gopher.r-36.net 70 i } Err gopher.r-36.net 70 i Err gopher.r-36.net 70 i /* request handler */ Err gopher.r-36.net 70 .