Comparison

plugins/mod_admin_shell.lua @ 12672:c8f59ce7d3cf

mod_admin_shell: Ensure account has role before it is usable By creating the account first without a password it can't be used until the role has set. This is most important for restricted accounts, as a failure to set the role would lead to the account having more privileges than indented.
author Kim Alvefur <zash@zash.se>
date Thu, 18 Aug 2022 19:00:01 +0200
parent 12670:4a00c8811ea8
child 12675:db8c795ca81a
comparison
equal deleted inserted replaced
12671:32881d0c359f 12672:c8f59ce7d3cf
1388 if not prosody.hosts[host] then 1388 if not prosody.hosts[host] then
1389 return nil, "No such host: "..host; 1389 return nil, "No such host: "..host;
1390 elseif um.user_exists(username, host) then 1390 elseif um.user_exists(username, host) then
1391 return nil, "User exists"; 1391 return nil, "User exists";
1392 end 1392 end
1393 local ok, err = um.create_user(username, password, host); 1393 local ok, err = um.create_user(username, nil, host);
1394 if ok then 1394 if not ok then
1395 if ok and role then
1396 local role_ok, rerr = um.set_user_role(jid, host, role);
1397 if not role_ok then return nil, "User created, but could not set role: " .. tostring(rerr); end
1398 end
1399 return true, "User created";
1400 else
1401 return nil, "Could not create user: "..err; 1395 return nil, "Could not create user: "..err;
1402 end 1396 end
1397
1398 if role then
1399 local role_ok, rerr = um.set_user_role(jid, host, role);
1400 if not role_ok then
1401 return nil, "Could not set role: " .. tostring(rerr);
1402 end
1403 end
1404
1405 local ok, err = um.set_password(username, password, host, nil);
1406 if not ok then
1407 return nil, "Could not set password for user: "..err;
1408 end
1409
1410 return true, "User created";
1403 end 1411 end
1404 1412
1405 function def_env.user:delete(jid) 1413 function def_env.user:delete(jid)
1406 local username, host = jid_split(jid); 1414 local username, host = jid_split(jid);
1407 if not prosody.hosts[host] then 1415 if not prosody.hosts[host] then