Comparison

plugins/mod_admin_telnet.lua @ 5598:3bb8aefd8ce0

mod_admin_telnet: Verify that the host exists in user commands (Thanks SkyBlue)
author Kim Alvefur <zash@zash.se>
date Sat, 18 May 2013 13:19:31 +0200
parent 5596:73fea1a87afd
child 5599:34e9f237b915
child 5630:5f3c0b11aa88
comparison
equal deleted inserted replaced
5597:6fe09707c73b 5598:3bb8aefd8ce0
937 local um = require"core.usermanager"; 937 local um = require"core.usermanager";
938 938
939 def_env.user = {}; 939 def_env.user = {};
940 function def_env.user:create(jid, password) 940 function def_env.user:create(jid, password)
941 local username, host = jid_split(jid); 941 local username, host = jid_split(jid);
942 if um.user_exists(username, host) then 942 if not hosts[host] then
943 return nil, "No such host: "..host;
944 elseif um.user_exists(username, host) then
943 return nil, "User exists"; 945 return nil, "User exists";
944 end 946 end
945 local ok, err = um.create_user(username, password, host); 947 local ok, err = um.create_user(username, password, host);
946 if ok then 948 if ok then
947 return true, "User created"; 949 return true, "User created";
950 end 952 end
951 end 953 end
952 954
953 function def_env.user:delete(jid) 955 function def_env.user:delete(jid)
954 local username, host = jid_split(jid); 956 local username, host = jid_split(jid);
955 if not um.user_exists(username, host) then 957 if not hosts[host] then
958 return nil, "No such host: "..host;
959 elseif um.user_exists(username, host) then
956 return nil, "No such user"; 960 return nil, "No such user";
957 end 961 end
958 local ok, err = um.delete_user(username, host); 962 local ok, err = um.delete_user(username, host);
959 if ok then 963 if ok then
960 return true, "User deleted"; 964 return true, "User deleted";
963 end 967 end
964 end 968 end
965 969
966 function def_env.user:password(jid, password) 970 function def_env.user:password(jid, password)
967 local username, host = jid_split(jid); 971 local username, host = jid_split(jid);
968 if not um.user_exists(username, host) then 972 if not hosts[host] then
973 return nil, "No such host: "..host;
974 elseif um.user_exists(username, host) then
969 return nil, "No such user"; 975 return nil, "No such user";
970 end 976 end
971 local ok, err = um.set_password(username, password, host); 977 local ok, err = um.set_password(username, password, host);
972 if ok then 978 if ok then
973 return true, "User password changed"; 979 return true, "User password changed";