[Reconnoiter-devel] [reconnoiter commit] r898 - trunk/src/modules

svn-commit at lists.omniti.com svn-commit at lists.omniti.com
Tue Sep 29 01:22:39 EDT 2009


Author: jesus
Date: 2009-09-29 01:22:39 -0400 (Tue, 29 Sep 2009)
New Revision: 898

Modified:
   trunk/src/modules/lua_noit.c
Log:
need this for digest auth, refs #186

Modified: trunk/src/modules/lua_noit.c
===================================================================
--- trunk/src/modules/lua_noit.c	2009-09-29 02:55:59 UTC (rev 897)
+++ trunk/src/modules/lua_noit.c	2009-09-29 05:22:39 UTC (rev 898)
@@ -45,6 +45,7 @@
 #include <libxml/parser.h>
 #include <libxml/xpath.h>
 #include <libxml/tree.h>
+#include <openssl/md5.h>
 
 #include "noit_conf.h"
 #include "noit_module.h"
@@ -724,7 +725,31 @@
   lua_pushlstring(L, (char *)encoded, encoded_len);
   return 1;
 }
+static const char _hexchars[16] =
+  {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
 static int
+nl_md5_hex(lua_State *L) {
+  int i;
+  MD5_CTX ctx;
+  size_t inlen;
+  const char *in;
+  unsigned char md5[MD5_DIGEST_LENGTH];
+  char md5_hex[MD5_DIGEST_LENGTH * 2 + 1];
+
+  if(lua_gettop(L) != 1) luaL_error(L, "bad call to noit.md5_hex");
+  MD5_Init(&ctx);
+  in = lua_tolstring(L, 1, &inlen);
+  MD5_Update(&ctx, (const void *)in, (unsigned long)inlen);
+  MD5_Final(md5, &ctx);
+  for(i=0;i<MD5_DIGEST_LENGTH;i++) {
+    md5_hex[i*2] = _hexchars[(md5[i] >> 4) & 0xf];
+    md5_hex[i*2+1] = _hexchars[md5[i] & 0xf];
+  }
+  md5_hex[i*2] = '\0';
+  lua_pushstring(L, md5_hex);
+  return 1;
+}
+static int
 nl_gettimeofday(lua_State *L) {
   struct timeval now;
   gettimeofday(&now, NULL);
@@ -1228,6 +1253,7 @@
   { "log", nl_log },
   { "base64_decode", nl_base64_decode },
   { "base64_encode", nl_base64_encode },
+  { "md5_hex", nl_md5_hex },
   { "pcre", nl_pcre },
   { "socket_ipv6", nl_socket_ipv6 },
   { "gunzip", nl_gunzip },



More information about the Reconnoiter-devel mailing list