3
0
mirror of https://github.com/ergochat/ergo.git synced 2024-12-23 03:02:48 +01:00

Merge pull request #1444 from slingamn/issue1439_confusable_import

fix #1439, give all atheme group founders +q
This commit is contained in:
Shivaram Lingamneni 2020-12-07 16:06:46 -08:00 committed by GitHub
commit 85c39f3ea0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 26 deletions

View File

@ -27,11 +27,7 @@ def convert(infile):
'channels': defaultdict(dict), 'channels': defaultdict(dict),
} }
# Translate channels owned by groups to being owned by the first founder of that group group_to_founders = defaultdict(list)
# 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)) channel_to_founder = defaultdict(lambda: (None, None))
@ -39,15 +35,16 @@ def convert(infile):
line = line.rstrip('\r\n') line = line.rstrip('\r\n')
parts = line.split(' ') parts = line.split(' ')
category = parts[0] category = parts[0]
if category == 'GACL': if category == 'GACL':
# Note: all group definitions precede channel access entries (token CA) by design, so it
# should be safe to read this in using one pass.
groupname = parts[1] groupname = parts[1]
user = parts[2] user = parts[2]
flags = parts[3] flags = parts[3]
# Pick the first founder if 'F' in flags:
if groupname not in groups_to_user and 'F' in flags: group_to_founders[groupname].append(user)
groups_to_user[groupname] = user elif category == 'MU':
if category == 'MU':
# user account # user account
# MU AAAAAAAAB shivaram $1$hcspif$nCm4r3S14Me9ifsOPGuJT. user@example.com 1600134392 1600467343 +sC default # MU AAAAAAAAB shivaram $1$hcspif$nCm4r3S14Me9ifsOPGuJT. user@example.com 1600134392 1600467343 +sC default
name = parts[2] name = parts[2]
@ -60,9 +57,7 @@ def convert(infile):
username, groupednick = parts[1], parts[2] username, groupednick = parts[1], parts[2]
if username != groupednick: if username != groupednick:
user = out['users'][username] user = out['users'][username]
if 'additionalNicks' not in user: user.setdefault('additionalnicks', []).append(groupednick)
user['additionalNicks'] = []
user['additionalNicks'].append(groupednick)
elif category == 'MDU': elif category == 'MDU':
if parts[2] == 'private:usercloak': if parts[2] == 'private:usercloak':
username = parts[1] username = parts[1]
@ -111,18 +106,19 @@ def convert(infile):
chdata['amode'] = {} chdata['amode'] = {}
# see libathemecore/flags.c: +o is op, +O is autoop, etc. # see libathemecore/flags.c: +o is op, +O is autoop, etc.
if 'F' in flags: 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 the username starts with "!", it's actually a GroupServ group.
if username.startswith('!'): if username.startswith('!'):
try: group_founders = group_to_founders.get(username)
group_founder = groups_to_user[username] if not group_founders:
print(f"WARNING: flattening GroupServ group founder {username} on {chname} to first group founder {group_founder}") # skip this and warn about it later
except KeyError: continue
raise ValueError(f"Got channel {chname} owned by group {username} that has no founder?") # attempt to promote the first group founder to channel founder
else: username = group_founders[0]
username = group_founder # but everyone gets the +q flag
for founder in group_founders:
chdata['amode'][founder] = 'q'
# there can only be one founder
preexisting_founder, preexisting_set_at = channel_to_founder[chname]
if preexisting_founder is None or set_at < preexisting_set_at: if preexisting_founder is None or set_at < preexisting_set_at:
chdata['founder'] = username chdata['founder'] = username
channel_to_founder[chname] = (username, set_at) channel_to_founder[chname] = (username, set_at)

View File

@ -80,13 +80,24 @@ func doImportDBGeneric(config *Config, dbImport databaseImport, credsType Creden
tx.Set(keyCloakSecret, utils.GenerateSecretKey(), nil) tx.Set(keyCloakSecret, utils.GenerateSecretKey(), nil)
cfUsernames := make(utils.StringSet) cfUsernames := make(utils.StringSet)
skeletonToUsername := make(map[string]string)
warnSkeletons := false
for username, userInfo := range dbImport.Users { for username, userInfo := range dbImport.Users {
cfUsername, err := CasefoldName(username) cfUsername, err := CasefoldName(username)
if err != nil { skeleton, skErr := Skeleton(username)
log.Printf("invalid username %s: %v", username, err) if err != nil || skErr != nil {
log.Printf("invalid username %s: %v\n", username, err)
continue continue
} }
if existingSkelUser, ok := skeletonToUsername[skeleton]; ok {
log.Printf("Users %s and %s have confusable nicknames; this may render one or both accounts unusable\n", username, existingSkelUser)
warnSkeletons = true
} else {
skeletonToUsername[skeleton] = username
}
var certfps []string var certfps []string
for _, certfp := range userInfo.Certfps { for _, certfp := range userInfo.Certfps {
normalizedCertfp, err := utils.NormalizeCertfp(certfp) normalizedCertfp, err := utils.NormalizeCertfp(certfp)
@ -103,7 +114,7 @@ func doImportDBGeneric(config *Config, dbImport databaseImport, credsType Creden
} }
marshaledCredentials, err := json.Marshal(&credentials) marshaledCredentials, err := json.Marshal(&credentials)
if err != nil { if err != nil {
log.Printf("invalid credentials for %s: %v", username, err) log.Printf("invalid credentials for %s: %v\n", username, err)
continue continue
} }
tx.Set(fmt.Sprintf(keyAccountExists, cfUsername), "1", nil) tx.Set(fmt.Sprintf(keyAccountExists, cfUsername), "1", nil)
@ -178,6 +189,11 @@ func doImportDBGeneric(config *Config, dbImport databaseImport, credsType Creden
} }
} }
if warnSkeletons {
log.Printf("NOTE: you may be able to avoid confusability issues by changing the server casemapping setting to `ascii`\n")
log.Printf("However, this will prevent the use of non-ASCII Unicode characters in nicknames\n")
}
return nil return nil
} }