shithub: ext4srv

Download patch

ref: 75bb5100f6544967d9559d41befd52366dce4e0d
parent: 3669b3e2e684a40b20c5a22bf4f6ee898e616447
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Thu Nov 12 08:28:19 EST 2020

add -g (for custom group file) and -R (to mount as root) options

--- a/common.h
+++ b/common.h
@@ -7,8 +7,10 @@
 #pragma varargck type "M" Part*
 
 struct Opts {
+	char *group;
 	int cachewb;
 	int linkmode;
+	int asroot;
 };
 
 struct Part {
--- a/ext4srv.c
+++ b/ext4srv.c
@@ -150,8 +150,8 @@
 		rerrstr(err, sizeof(err));
 		respond(r, err);
 	}else{
-		if(findgroup(&a->p->groups, r->ifcall.uname, &a->uid) == nil)
-			a->uid = Root; /* FIXME need external mapping */
+		if(opts.asroot || findgroup(&a->p->groups, r->ifcall.uname, &a->uid) == nil)
+			a->uid = Root;
 
 		incref(a->p);
 		a->type = Adir;
@@ -634,7 +634,7 @@
 static void
 usage(void)
 {
-	fprint(2, "usage: %s [-C] [-l hide] [-s srvname]\n", argv0);
+	fprint(2, "usage: %s [-C] [-R] [-g GROUPFILE] [-l hide] [-s SRVNAME]\n", argv0);
 	threadexitsall("usage");
 }
 
@@ -651,7 +651,9 @@
 void
 threadmain(int argc, char **argv)
 {
-	char *srv;
+	char *srv, *gr;
+	vlong sz;
+	int f;
 
 	srv = "ext4";
 	ARGBEGIN{
@@ -666,6 +668,23 @@
 		break;
 	case 's':
 		srv = EARGF(usage());
+		break;
+	case 'g':
+		gr = EARGF(usage());
+		if((f = open(gr, OREAD)) < 0)
+			sysfatal("%r");
+		if((sz = seek(f, 0, 2)) < 0)
+			sysfatal("%s: invalid group file", gr);
+		if((opts.group = malloc(sz+1)) == nil)
+			sysfatal("memory");
+		seek(f, 0, 0);
+		if(readn(f, opts.group, sz) != sz)
+			sysfatal("%s: read failed", gr);
+		close(f);
+		opts.group[sz] = 0;
+		break;
+	case 'R':
+		opts.asroot = 1;
 		break;
 	}ARGEND
 
--- a/part.c
+++ b/part.c
@@ -257,13 +257,15 @@
 		goto error;
 	}
 
-	if((gr = readfile(p, "/etc/group", &sz)) != nil){
+	if(opts->group != nil){
+		r = loadgroups(&p->groups, opts->group);
+	}else if((gr = readfile(p, "/etc/group", &sz)) != nil){
 		gr[sz] = 0;
 		r = loadgroups(&p->groups, gr);
 		free(gr);
-		if(r != 0)
-			goto error;
 	}
+	if(r != 0)
+		goto error;
 
 	return 0;
 error: