add permission "A" (alias of "rwmda."); closes #70

This commit is contained in:
ed 2023-12-31 18:20:24 +00:00
parent bed133d3dd
commit ab40ff5051
4 changed files with 23 additions and 9 deletions

View file

@ -374,6 +374,7 @@ permissions:
* `G` (upget): same as `g` except uploaders get to see their own [filekeys](#filekeys) (see `fk` in examples below) * `G` (upget): same as `g` except uploaders get to see their own [filekeys](#filekeys) (see `fk` in examples below)
* `h` (html): same as `g` except folders return their index.html, and filekeys are not necessary for index.html * `h` (html): same as `g` except folders return their index.html, and filekeys are not necessary for index.html
* `a` (admin): can see upload time, uploader IPs, config-reload * `a` (admin): can see upload time, uploader IPs, config-reload
* 'A' ("all"): same as `rwmda.` (read/write/move/delete/dotfiles)
examples: examples:
* add accounts named u1, u2, u3 with passwords p1, p2, p3: `-a u1:p1 -a u2:p2 -a u3:p3` * add accounts named u1, u2, u3 with passwords p1, p2, p3: `-a u1:p1 -a u2:p2 -a u3:p3`

View file

@ -500,6 +500,7 @@ def get_sects():
"h" (html): "get", but folders return their index.html "h" (html): "get", but folders return their index.html
"." (dots): user can ask to show dotfiles in listings "." (dots): user can ask to show dotfiles in listings
"a" (admin): can see uploader IPs, config-reload "a" (admin): can see uploader IPs, config-reload
"A" ("all"): same as "rwmda." (read/write/move/delete/admin/dotfiles)
too many volflags to list here, see --help-flags too many volflags to list here, see --help-flags

View file

@ -956,7 +956,7 @@ class AuthSrv(object):
try: try:
self._l(ln, 5, "volume access config:") self._l(ln, 5, "volume access config:")
sk, sv = ln.split(":") sk, sv = ln.split(":")
if re.sub("[rwmdgGha.]", "", sk) or not sk: if re.sub("[rwmdgGhaA.]", "", sk) or not sk:
err = "invalid accs permissions list; " err = "invalid accs permissions list; "
raise Exception(err) raise Exception(err)
if " " in re.sub(", *", "", sv).strip(): if " " in re.sub(", *", "", sv).strip():
@ -966,7 +966,7 @@ class AuthSrv(object):
self._read_vol_str(sk, sv.replace(" ", ""), daxs[vp], mflags[vp]) self._read_vol_str(sk, sv.replace(" ", ""), daxs[vp], mflags[vp])
continue continue
except: except:
err += "accs entries must be 'rwmdgGha.: user1, user2, ...'" err += "accs entries must be 'rwmdgGhaA.: user1, user2, ...'"
raise Exception(err + SBADCFG) raise Exception(err + SBADCFG)
if cat == catf: if cat == catf:
@ -1004,7 +1004,7 @@ class AuthSrv(object):
def _read_vol_str( def _read_vol_str(
self, lvl: str, uname: str, axs: AXS, flags: dict[str, Any] self, lvl: str, uname: str, axs: AXS, flags: dict[str, Any]
) -> None: ) -> None:
if lvl.strip("crwmdgGha."): if lvl.strip("crwmdgGhaA."):
t = "%s,%s" % (lvl, uname) if uname else lvl t = "%s,%s" % (lvl, uname) if uname else lvl
raise Exception("invalid config value (volume or volflag): %s" % (t,)) raise Exception("invalid config value (volume or volflag): %s" % (t,))
@ -1028,7 +1028,19 @@ class AuthSrv(object):
if uname == "": if uname == "":
uname = "*" uname = "*"
junkset = set()
for un in uname.replace(",", " ").strip().split(): for un in uname.replace(",", " ").strip().split():
for alias, mapping in [
("h", "gh"),
("G", "gG"),
("A", "rwmda.A"),
]:
expanded = ""
for ch in mapping:
if ch not in lvl:
expanded += ch
lvl = lvl.replace(alias, expanded + alias)
for ch, al in [ for ch, al in [
("r", axs.uread), ("r", axs.uread),
("w", axs.uwrite), ("w", axs.uwrite),
@ -1036,12 +1048,11 @@ class AuthSrv(object):
("d", axs.udel), ("d", axs.udel),
(".", axs.udot), (".", axs.udot),
("a", axs.uadmin), ("a", axs.uadmin),
("h", axs.uhtml), ("A", junkset),
("h", axs.uget),
("g", axs.uget), ("g", axs.uget),
("G", axs.uget),
("G", axs.upget), ("G", axs.upget),
]: # b bb bbb ("h", axs.uhtml),
]:
if ch in lvl: if ch in lvl:
if un == "*": if un == "*":
t = "└─add permission [{0}] for [everyone] -- {2}" t = "└─add permission [{0}] for [everyone] -- {2}"
@ -1113,7 +1124,7 @@ class AuthSrv(object):
if self.args.v: if self.args.v:
# list of src:dst:permset:permset:... # list of src:dst:permset:permset:...
# permset is <rwmdgGha.>[,username][,username] or <c>,<flag>[=args] # permset is <rwmdgGhaA.>[,username][,username] or <c>,<flag>[=args]
for v_str in self.args.v: for v_str in self.args.v:
m = re_vol.match(v_str) m = re_vol.match(v_str)
if not m: if not m:
@ -2189,7 +2200,7 @@ def upgrade_cfg_fmt(
else: else:
sn = sn.replace(",", ", ") sn = sn.replace(",", ", ")
ret.append(" " + sn) ret.append(" " + sn)
elif sn[:1] in "rwmdgGha.": elif sn[:1] in "rwmdgGhaA.":
if cat != catx: if cat != catx:
cat = catx cat = catx
ret.append(cat) ret.append(cat)

View file

@ -104,6 +104,7 @@ permdescs = {
"G": 'upget; same as "g" but can see filekeys of their own uploads', "G": 'upget; same as "g" but can see filekeys of their own uploads',
"h": 'html; same as "g" but folders return their index.html', "h": 'html; same as "g" but folders return their index.html',
"a": "admin; can see uploader IPs, config-reload", "a": "admin; can see uploader IPs, config-reload",
"A": "all; same as 'rwmda.' (read/write/move/delete/dotfiles)",
} }