From 22b0263c5b7576fe98ac8e0aa841517d1cc17f06 Mon Sep 17 00:00:00 2001 From: James Lu Date: Fri, 4 Dec 2020 00:58:01 -0800 Subject: [PATCH] atheme2json: flatten channels owned by GroupServ groups to the first group founder --- distrib/atheme/atheme2json.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) mode change 100644 => 100755 distrib/atheme/atheme2json.py diff --git a/distrib/atheme/atheme2json.py b/distrib/atheme/atheme2json.py old mode 100644 new mode 100755 index 869cb055..df386ade --- a/distrib/atheme/atheme2json.py +++ b/distrib/atheme/atheme2json.py @@ -24,12 +24,26 @@ def convert(infile): 'channels': defaultdict(dict), } + # Translate channels owned by groups to being owned by the first founder of that group + # Otherwise the code crashes on networks using atheme's GroupServ + # Note: all group definitions precede channel access entries (token CA) by design, so it + # should be safe to read this in using one pass. + groups_to_user = {} + channel_to_founder = defaultdict(lambda: (None, None)) for line in infile: line = line.rstrip('\r\n') parts = line.split(' ') category = parts[0] + if category == 'GACL': + groupname = parts[1] + user = parts[2] + flags = parts[3] + # Pick the first founder + if groupname not in groups_to_user and 'F' in flags: + groups_to_user[groupname] = user + if category == 'MU': # user account # MU AAAAAAAAB shivaram $1$hcspif$nCm4r3S14Me9ifsOPGuJT. user@example.com 1600134392 1600467343 +sC default @@ -96,6 +110,16 @@ def convert(infile): if 'F' in flags: # there can only be one founder preexisting_founder, preexisting_set_at = channel_to_founder[chname] + # If the username starts with "!", it's actually a GroupServ group. + if username.startswith('!'): + try: + group_founder = groups_to_user[username] + print(f"WARNING: flattening GroupServ group founder {username} on {chname} to first group founder {group_founder}") + except KeyError as e: + raise ValueError(f"Got channel {chname} owned by group {username} that has no founder?") + else: + username = group_founder + if preexisting_founder is None or set_at < preexisting_set_at: chdata['founder'] = username channel_to_founder[chname] = (username, set_at)