Changeset

4976:0875c9208580

Merge Zash with Zash for Zash
author Matthew Wild <mwild1@gmail.com>
date Sun, 22 Jul 2012 18:46:49 +0100
parents 4975:6f689c155186 (diff) 4972:1777271a1ec0 (current diff)
children 4977:7006ccbf22a9
files
diffstat 5 files changed, 75 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/adhoc/adhoc.lib.lua	Sat Jul 07 23:22:15 2012 +0200
+++ b/plugins/adhoc/adhoc.lib.lua	Sun Jul 22 18:46:49 2012 +0100
@@ -12,7 +12,7 @@
 
 local _M = {};
 
-function _cmdtag(desc, status, sessionid, action)
+local function _cmdtag(desc, status, sessionid, action)
 	local cmd = st.stanza("command", { xmlns = xmlns_cmd, node = desc.node, status = status });
 	if sessionid then cmd.attr.sessionid = sessionid; end
 	if action then cmd.attr.action = action; end
@@ -35,6 +35,7 @@
 	local data, state = command:handler(dataIn, states[sessionid]);
 	states[sessionid] = state;
 	local stanza = st.reply(stanza);
+	local cmdtag;
 	if data.status == "completed" then
 		states[sessionid] = nil;
 		cmdtag = command:cmdtag("completed", sessionid);
--- a/plugins/mod_admin_telnet.lua	Sat Jul 07 23:22:15 2012 +0200
+++ b/plugins/mod_admin_telnet.lua	Sun Jul 22 18:46:49 2012 +0100
@@ -187,6 +187,7 @@
 		print [[s2s - Commands to manage sessions between this server and others]]
 		print [[module - Commands to load/reload/unload modules/plugins]]
 		print [[host - Commands to activate, deactivate and list virtual hosts]]
+		print [[user - Commands to create and delete users, and change their passwords]]
 		print [[server - Uptime, version, shutting down, etc.]]
 		print [[config - Reloading the configuration, etc.]]
 		print [[console - Help regarding the console itself]]
@@ -207,6 +208,10 @@
 		print [[host:activate(hostname) - Activates the specified host]]
 		print [[host:deactivate(hostname) - Disconnects all clients on this host and deactivates]]
 		print [[host:list() - List the currently-activated hosts]]
+	elseif section == "user" then
+		print [[user:create(jid, password) - Create the specified user account]]
+		print [[user:password(jid, password) - Set the password for the specified user account]]
+		print [[user:delete(jid, password) - Permanently remove the specified user account]]
 	elseif section == "server" then
 		print [[server:version() - Show the server's version number]]
 		print [[server:uptime() - Show how long the server has been running]]
@@ -856,6 +861,37 @@
 	return setmetatable({ room = room_obj }, console_room_mt);
 end
 
+def_env.user = {};
+function def_env.user:create(jid, password)
+	local username, host = jid_split(jid);
+	local ok, err = um.create_user(username, password, host);
+	if ok then
+		return true, "User created";
+	else
+		return nil, "Could not create user: "..err;
+	end
+end
+
+function def_env.user:delete(jid)
+	local username, host = jid_split(jid);
+	local ok, err = um.delete_user(username, host);
+	if ok then
+		return true, "User deleted";
+	else
+		return nil, "Could not delete user: "..err;
+	end
+end
+
+function def_env.user:passwd(jid, password)
+	local username, host = jid_split(jid);
+	local ok, err = um.set_password(username, password, host);
+	if ok then
+		return true, "User created";
+	else
+		return nil, "Could not change password for user: "..err;
+	end
+end
+
 -------------
 
 function printbanner(session)
--- a/plugins/mod_auth_anonymous.lua	Sat Jul 07 23:22:15 2012 +0200
+++ b/plugins/mod_auth_anonymous.lua	Sun Jul 22 18:46:49 2012 +0100
@@ -32,10 +32,9 @@
 		return nil, "Account creation/modification not supported.";
 	end
 
-	function provider.get_sasl_handler(session)
+	function provider.get_sasl_handler()
 		local anonymous_authentication_profile = {
 			anonymous = function(sasl, username, realm)
-				session.roster = {}; -- so that the null storage backend doesn't upset rostermanager
 				return true; -- for normal usage you should always return true here
 			end
 		};
--- a/util-src/pposix.c	Sat Jul 07 23:22:15 2012 +0200
+++ b/util-src/pposix.c	Sun Jul 22 18:46:49 2012 +0100
@@ -34,6 +34,11 @@
 #include "lua.h"
 #include "lauxlib.h"
 
+#if (defined(_SVID_SOURCE) && !defined(WITHOUT_MALLINFO))
+	#include <malloc.h>
+	#define WITH_MALLINFO
+#endif
+
 /* Daemonization support */
 
 static int lc_daemonize(lua_State *L)
@@ -612,6 +617,31 @@
 	return 1;
 }
 
+#ifdef WITH_MALLINFO
+int lc_meminfo(lua_State* L)
+{
+	struct mallinfo info = mallinfo();
+	lua_newtable(L);
+	/* This is the total size of memory allocated with sbrk by malloc, in bytes. */
+	lua_pushinteger(L, info.arena);
+	lua_setfield(L, -2, "allocated");
+	/* This is the total size of memory allocated with mmap, in bytes. */
+	lua_pushinteger(L, info.hblkhd);
+	lua_setfield(L, -2, "allocated_mmap");
+	/* This is the total size of memory occupied by chunks handed out by malloc. */
+	lua_pushinteger(L, info.uordblks);
+	lua_setfield(L, -2, "used");
+	/* This is the total size of memory occupied by free (not in use) chunks. */
+	lua_pushinteger(L, info.fordblks);
+	lua_setfield(L, -2, "unused");
+	/* This is the size of the top-most releasable chunk that normally borders the
+	   end of the heap (i.e., the high end of the virtual address space's data segment). */
+	lua_pushinteger(L, info.keepcost);
+	lua_setfield(L, -2, "returnable");
+	return 1;
+}
+#endif
+
 /* Register functions */
 
 int luaopen_util_pposix(lua_State *L)
@@ -645,6 +675,10 @@
 
 		{ "setenv", lc_setenv },
 
+#ifdef WITH_MALLINFO
+		{ "meminfo", lc_meminfo },
+#endif
+
 		{ NULL, NULL }
 	};
 
--- a/util/throttle.lua	Sat Jul 07 23:22:15 2012 +0200
+++ b/util/throttle.lua	Sun Jul 22 18:46:49 2012 +0100
@@ -1,6 +1,7 @@
 
 local gettime = require "socket".gettime;
 local setmetatable = setmetatable;
+local floor = math.floor;
 
 module "throttle"
 
@@ -11,7 +12,7 @@
 	local newt = gettime();
 	local elapsed = newt - self.t;
 	self.t = newt;
-	local balance = self.rate * elapsed + self.balance;
+	local balance = floor(self.rate * elapsed) + self.balance;
 	if balance > self.max then
 		self.balance = self.max;
 	else