shithub: ext4srv

Download patch

ref: 07c47f43a906863c080f15022d3201b6b1c9516b
parent: e05602598c19ed2708d56e4536a654d3998b2087
author: Sigrid Solveig Haflínudóttir <[email protected]>
date: Sun Nov 15 08:16:56 EST 2020

hide symbolic links by default

--- a/common.h
+++ b/common.h
@@ -32,7 +32,8 @@
 };
 
 enum {
-	Lhide = 1,
+	Lhide,
+	Lresolve = 1,
 };
 
 Part *openpart(char *dev, Opts *opts);
--- a/ext4srv.c
+++ b/ext4srv.c
@@ -31,7 +31,12 @@
 	Root = 0,
 };
 
-static Opts opts;
+static Opts opts = {
+	.group = nil,
+	.cachewb = 0,
+	.asroot = 0,
+	.linkmode = Lhide,
+};
 static u8int zero[65536];
 static char Eperm[] = "permission denied";
 
@@ -40,18 +45,15 @@
 {
 	char *q, buf[4096+1];
 	uvlong sz;
+	int res;
 
-	if(ext4_readlink(s, buf, sizeof(buf), &sz) == 0){
+	res = 0;
+	if(opts.linkmode == Lresolve && (res = ext4_readlink(s, buf, sizeof(buf), &sz)) == 0){
 		if(sz == sizeof(buf)){
 			werrstr("readlink: %s: path too long", s);
 			free(s);
 			return nil;
 		}
-		if(opts.linkmode == Lhide){
-			werrstr("linkresolve: %s: links are hidden", s);
-			free(s);
-			return nil;
-		}
 
 		buf[sz] = 0;
 		if(value != nil)
@@ -65,11 +67,14 @@
 			*q = 0;
 			q = s;
 			s = smprint("%s/%s", q, buf);
-			cleanname(s);
 			free(q);
+			cleanname(strchr(s+1, '/')+1);
 		}
-	}else if(value != nil){
-		*value = nil;
+	}else{
+		if(res != 0)
+			werrstr("readlink: %s: %s", s, errno2s(res));
+		if(value != nil)
+			*value = nil;
 	}
 
 	return s;
@@ -400,11 +405,16 @@
 		return -1;
 	}
 
+	t = ext4_inode_type(a->p->sb, &inode);
+	if(opts.linkmode == Lhide && (t & EXT4_INODE_MODE_SOFTLINK) != 0){
+		free(s);
+		return -1;
+	}
+
 	dir->mode = ext4_inode_get_mode(a->p->sb, &inode) & 0x1ff;
 	dir->qid.path = a->p->qidmask.path | ino;
 	dir->qid.vers = ext4_inode_get_generation(&inode);
 	dir->qid.type = 0;
-	t = ext4_inode_type(a->p->sb, &inode);
 	if(t & EXT4_INODE_MODE_DIRECTORY){
 		dir->qid.type |= QTDIR;
 		dir->mode |= DMDIR;
@@ -455,9 +465,6 @@
 
 		if(dirfill(dir, a, (char*)e->name) == 0)
 			return 0;
-		else{
-			fprint(2, "dirfill failed on %s: %r\n", (char*)e->name);
-		}
 	}
 }
 
@@ -865,7 +872,7 @@
 static void
 usage(void)
 {
-	fprint(2, "usage: %s [-C] [-R] [-g GROUPFILE] [-l hide] [-s SRVNAME]\n", argv0);
+	fprint(2, "usage: %s [-C] [-R] [-g GROUPFILE] [-l resolve] [-s SRVNAME]\n", argv0);
 	threadexitsall("usage");
 }
 
@@ -872,8 +879,8 @@
 static int
 linkmode(char *m)
 {
-	if(strcmp(m, "hide") == 0)
-		return Lhide;
+	if(strcmp(m, "resolve") == 0)
+		return Lresolve;
 
 	usage();
 	return -1;