Changeset

814:f12b1ddd458d

Merge from waqas
author Matthew Wild <mwild1@gmail.com>
date Mon, 16 Feb 2009 15:44:54 +0000
parents 806:655293df3d7e (diff) 813:ebfb904640d8 (current diff)
children 815:cf8392613f46 817:e3e3919b6c7e 859:43f7e342135d
files
diffstat 6 files changed, 138 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/configure	Mon Feb 16 20:24:31 2009 +0500
+++ b/configure	Mon Feb 16 15:44:54 2009 +0000
@@ -12,8 +12,10 @@
 LUA_LIBDIR="/usr/lib"
 IDN_LIB=idn
 OPENSSL_LIB=crypto
+CC=gcc
+LD=gcc
 
-CFLAGS="-fPIC"
+CFLAGS="-fPIC -Wall"
 LFLAGS="-shared"
 
 # Help
@@ -45,6 +47,12 @@
                             Default is $OPENSSL_LIB
 --cflags=FLAGS              Flags to pass to the compiler
                             Default is $CFLAGS
+--lflags=FLAGS              Flags to pass to the linker
+                            Default is $LFLAGS
+--c-compiler=CC             The C compiler to use when building modules.
+                            Default is $CC
+--linker=CC                 The linker to use when building modules.
+                            Default is $LD
 --require-config            Will cause Prosody to refuse to run when
                             it fails to find a configuration file
 EOF
@@ -105,6 +113,12 @@
    --cflags=*)
       CFLAGS="$value"
       ;;      
+   --c-compiler=*)
+      CC="$value"
+      ;;      
+   --linker=*)
+      LD="$value"
+      ;;      
    *)
       echo "Error: Unknown flag: $1"
       exit 1
@@ -126,7 +140,7 @@
 	LUA_INCDIR_SET=yes	
 	LUA_LIBDIR=/usr/local/lib
 	LUA_LIBDIR_SET=yes
-	CFLAGS=""
+	CFLAGS="-Wall"
 	LFLAGS="-bundle -undefined dynamic_lookup"
 	fi	
 fi
@@ -279,6 +293,8 @@
 OPENSSL_LIB=$OPENSSL_LIB
 CFLAGS=$CFLAGS
 LFLAGS=$LFLAGS
+CC=$CC
+LD=$LD
 
 EOF
 
--- a/plugins/mod_saslauth.lua	Mon Feb 16 20:24:31 2009 +0500
+++ b/plugins/mod_saslauth.lua	Mon Feb 16 15:44:54 2009 +0000
@@ -106,6 +106,7 @@
 				-- TODO: Provide PLAIN only if TLS is active, this is a SHOULD from the introduction of RFC 4616. This behavior could be overridden via configuration but will issuing a warning or so.
 					features:tag("mechanism"):text("PLAIN"):up();
 					features:tag("mechanism"):text("DIGEST-MD5"):up();
+					features:tag("mechanism"):text("ANONYMOUS"):up();
 				features:up();
 			else
 				features:tag("bind", bind_attr):tag("required"):up():up();
--- a/plugins/mod_version.lua	Mon Feb 16 20:24:31 2009 +0500
+++ b/plugins/mod_version.lua	Mon Feb 16 15:44:54 2009 +0000
@@ -14,11 +14,28 @@
 
 module:add_feature(xmlns_version);
 
+local version = "the best operating system ever!";
+
+if not require "core.configmanager".get("*", "core", "hide_os_type") then
+	if os.getenv("WINDIR") then
+		version = "Windows";
+	else
+		local uname = io.popen("uname");
+		if uname then
+			version = uname:read("*a");
+		else
+			version = "an OS";
+		end
+	end
+end
+
+version = version:match("^%s*(.-)%s*$") or version;
+
 module:add_iq_handler({"c2s", "s2sin"}, xmlns_version, function(session, stanza)
 	if stanza.attr.type == "get" then
 		session.send(st.reply(stanza):query(xmlns_version)
 			:tag("name"):text("Prosody"):up()
 			:tag("version"):text("0.3"):up()
-			:tag("os"):text("the best operating system ever!"));
+			:tag("os"):text(version));
 	end
 end);
--- a/util-src/Makefile	Mon Feb 16 20:24:31 2009 +0500
+++ b/util-src/Makefile	Mon Feb 16 15:44:54 2009 +0000
@@ -6,7 +6,8 @@
 LUA_LIB?=lua$(LUA_SUFFIX)
 IDN_LIB?=idn
 OPENSSL_LIB?=crypto
-
+CC?=gcc
+LD?=gcc
 
 
 all: encodings.so hashes.so pposix.so
@@ -21,18 +22,18 @@
 	rm -f ../util/*.so
 
 encodings.o: encodings.c
-	gcc $(CFLAGS) -I$(LUA_INCDIR) -c -o encodings.o encodings.c
+	$(CC) $(CFLAGS) -I$(LUA_INCDIR) -c -o encodings.o encodings.c
 encodings.so: encodings.o
-	export MACOSX_DEPLOYMENT_TARGET="10.3"; gcc $(LFLAGS) -o encodings.so encodings.o -L/usr/local/lib -llua$(LUA_SUFFIX) -lidn
+	export MACOSX_DEPLOYMENT_TARGET="10.3"; $(LD) $(LFLAGS) -o encodings.so encodings.o -L$(LUA_LIBDIR) -llua$(LUA_SUFFIX) -lidn
 	
 
 hashes.o: hashes.c
-	gcc $(CFLAGS) -I$(LUA_INCDIR) -c -o hashes.o hashes.c
+	$(CC) $(CFLAGS) -I$(LUA_INCDIR) -c -o hashes.o hashes.c
 hashes.so: hashes.o
-	export MACOSX_DEPLOYMENT_TARGET="10.3"; gcc $(LFLAGS) -o hashes.so hashes.o -L/usr/local/lib -llua$(LUA_SUFFIX) -lcrypto
+	export MACOSX_DEPLOYMENT_TARGET="10.3"; $(LD) $(LFLAGS) -o hashes.so hashes.o -L$(LUA_LIBDIR) -llua$(LUA_SUFFIX) -lcrypto
 
 pposix.o: pposix.c
-	gcc $(CFLAGS) -I$(LUA_INCDIR) -c -o pposix.o pposix.c
+	$(CC) $(CFLAGS) -I$(LUA_INCDIR) -c -o pposix.o pposix.c
 pposix.so: pposix.o
-	export MACOSX_DEPLOYMENT_TARGET="10.3"; gcc $(LFLAGS) -o pposix.so pposix.o -L/usr/local/lib -llua$(LUA_SUFFIX)
+	export MACOSX_DEPLOYMENT_TARGET="10.3"; $(LD) $(LFLAGS) -o pposix.so pposix.o -L$(LUA_LIBDIR) -llua$(LUA_SUFFIX)
 	
--- a/util-src/pposix.c	Mon Feb 16 20:24:31 2009 +0500
+++ b/util-src/pposix.c	Mon Feb 16 15:44:54 2009 +0000
@@ -22,9 +22,10 @@
 #include <fcntl.h>
 
 #include <syslog.h>
+#include <pwd.h>
 
 #include <string.h>
-
+#include <errno.h>
 #include "lua.h"
 #include "lauxlib.h"
 
@@ -216,6 +217,78 @@
 	return 1;
 }
 
+/* UID/GID functions */
+
+int lc_getuid(lua_State* L)
+{
+	lua_pushinteger(L, getuid());
+	return 1;
+}
+
+int lc_getgid(lua_State* L)
+{
+	lua_pushinteger(L, getgid());
+	return 1;
+}
+
+int lc_setuid(lua_State* L)
+{
+	int uid = -1;
+	if(lua_gettop(L) < 1)
+		return 0;
+	if(!lua_isnumber(L, 1) && lua_tostring(L, 1))
+	{
+		/* Passed UID is actually a string, so look up the UID */
+		struct passwd *p;
+		p = getpwnam(lua_tostring(L, 1));
+		if(!p)
+		{
+			lua_pushboolean(L, 0);
+			lua_pushstring(L, "no-such-user");
+			return 2;
+		}
+		uid = p->pw_uid;
+	}
+	else
+	{
+		uid = lua_tonumber(L, 1);
+	}
+	
+	if(uid>-1)
+	{
+		/* Ok, attempt setuid */
+		errno = 0;
+		if(setuid(uid))
+		{
+			/* Fail */
+			lua_pushboolean(L, 0);
+			switch(errno)
+			{
+			case EINVAL:
+				lua_pushstring(L, "invalid-uid");
+				break;
+			case EPERM:
+				lua_pushstring(L, "permission-denied");
+				break;
+			default:
+				lua_pushstring(L, "unknown-error");
+			}
+			return 2;
+		}
+		else
+		{
+			/* Success! */
+			lua_pushboolean(L, 1);
+			return 1;
+		}
+	}
+	
+	/* Seems we couldn't find a valid UID to switch to */
+	lua_pushboolean(L, 0);
+	lua_pushstring(L, "invalid-uid");
+	return 2;
+}
+
 /* Register functions */
 
 int luaopen_util_pposix(lua_State *L)
@@ -240,6 +313,12 @@
 	lua_pushcfunction(L, lc_getpid);
 	lua_setfield(L, -2, "getpid");
 
+	lua_pushcfunction(L, lc_getuid);
+	lua_setfield(L, -2, "getuid");
+
+	lua_pushcfunction(L, lc_setuid);
+	lua_setfield(L, -2, "setuid");
+
 	lua_pushliteral(L, "pposix");
 	lua_setfield(L, -2, "_NAME");
 
--- a/util/sasl.lua	Mon Feb 16 20:24:31 2009 +0500
+++ b/util/sasl.lua	Mon Feb 16 15:44:54 2009 +0000
@@ -1,4 +1,4 @@
--- sasl.lua v0.2
+-- sasl.lua v0.3
 -- Copyright (C) 2008-2009 Tobias Markmann
 -- 
 --    All rights reserved.
@@ -235,10 +235,22 @@
 	return object
 end
 
+local function new_anonymous(realm, password_handler)
+	local object = { mechanism = "ANONYMOUS", realm = realm, password_handler = password_handler}
+		function object.feed(self, message)
+			return "success"
+		end
+	--TODO: From XEP-0175 "It is RECOMMENDED for the node identifier to be a UUID as specified in RFC 4122 [5]." So util.uuid() should (or have an option to) behave as specified in RFC 4122.
+	object["username"] = generate_uuid()
+	return object
+end
+
+
 function new(mechanism, realm, password_handler)
 	local object
 	if mechanism == "PLAIN" then object = new_plain(realm, password_handler)
 	elseif mechanism == "DIGEST-MD5" then object = new_digest_md5(realm, password_handler)
+	elseif mechanism == "ANONYMOUS" then object = new_anonymous(realm, password_handler)
 	else
 		log("debug", "Unsupported SASL mechanism: "..tostring(mechanism));
 		return nil