ref: 71bee3deb73e04c314ed968533f4c04d497e8c2f
parent: e71d9c74dcf1525101694b132328c6071aaaf01f
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Sun Aug 4 14:05:52 EDT 2024
9pex: add -a (anonimized user/group) option and use pledge+unveil on OpenBSD (thanks cgnarne)
--- a/9pex.c
+++ b/9pex.c
@@ -109,7 +109,7 @@
static int in, out, eof;
static C9ctx ctx;
-static int debug, rootescape;
+static int debug, rootescape, anon;
static Fid **fids;
static int numfids;
static Tag **tags;
@@ -584,9 +584,9 @@
if(fmt == S_IFCHR || fmt == S_IFCHR || fmt == S_IFSOCK || fmt == S_IFIFO)
stout->mode |= C9stappend;
stout->mode |= st->st_mode & 0x1ff;
- if((stout->uid = uid2str(st->st_uid, err)) == NULL)
+ if((stout->uid = anon ? "tuttle" : uid2str(st->st_uid, err)) == NULL)
return -1;
- if((stout->gid = gid2str(st->st_gid, err)) == NULL)
+ if((stout->gid = anon ? "tuttle" : gid2str(st->st_gid, err)) == NULL)
return -1;
return 0;
@@ -963,7 +963,7 @@
debug = 0;
dir = NULL;
- while((c = parg_getopt(&ps, argc, argv, "deh")) >= 0){
+ while((c = parg_getopt(&ps, argc, argv, "adeh")) >= 0){
switch(c){
case 1:
if(dir != NULL){
@@ -972,6 +972,9 @@
}
dir = ps.optarg;
break;
+ case 'a':
+ anon++;
+ break;
case 'e':
rootescape++;
break;
@@ -1039,6 +1042,12 @@
sa.sa_flags = SA_RESTART;
sigfillset(&sa.sa_mask);
sigaction(SIGUSR1, &sa, NULL);
+
+#ifdef __OpenBSD__
+ unveil(rootpath, "r");
+ unveil(NULL, NULL);
+ pledge("stdio rpath getpw", NULL);
+#endif
err = NULL;
rdonly = block = 1; /* at first we wait until the client sends in data */
--
⑨