myserver-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[myserver-commit] [SCM] GNU MyServer branch, master, updated. 4538ac1853


From: Giuseppe Scrivano
Subject: [myserver-commit] [SCM] GNU MyServer branch, master, updated. 4538ac18536a8cab0791e771100dee0735fbfb24
Date: Fri, 23 Oct 2009 22:50:22 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU MyServer".

The branch, master has been updated
       via  4538ac18536a8cab0791e771100dee0735fbfb24 (commit)
       via  11a566fae186699430a32395749a8b3ef0e7ac2f (commit)
      from  5dbae8c54b5d6038cd0c470265d69b65e0f5ab2f (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------


commit 4538ac18536a8cab0791e771100dee0735fbfb24
Author: Giuseppe Scrivano <address@hidden>
Date:   Sat Oct 24 00:50:11 2009 +0200

    Add a new method `CryptAlgoManager::check' to quickly check if F(x)=result, 
using the specified crypt algorithm.

diff --git a/myserver/configure.ac b/myserver/configure.ac
index 697e8b0..abcf3b0 100644
--- a/myserver/configure.ac
+++ b/myserver/configure.ac
@@ -88,7 +88,7 @@ AC_CHECK_HEADER([sys/sendfile.h], AC_DEFINE(SENDFILE, 1,
 gl_INIT
 
 AC_CHECK_FUNCS(regcomp gettimeofday setgroups localtime_r pipe posix_fallocate 
\
-                      snprintf openat fstatat getpwnam ffsl readdir_r)
+                          openat fstatat getpwnam ffsl readdir_r)
 
 AC_CHECK_LIB(gcrypt, gcry_control, AC_DEFINE(GCRY_CONTROL, 1,
                     [Define if the gcry_control function is present]))
diff --git a/myserver/include/base/crypt/crypt_algo_manager.h 
b/myserver/include/base/crypt/crypt_algo_manager.h
index 1ff7230..501db9e 100644
--- a/myserver/include/base/crypt/crypt_algo_manager.h
+++ b/myserver/include/base/crypt/crypt_algo_manager.h
@@ -32,6 +32,7 @@ public:
   ~CryptAlgoManager ();
   void registerAlgorithm (string &name, builder bld);
   CryptAlgo *make (string &s);
+  bool check (string &value, string &result, string &algo);
 private:
   HashMap<string, builder> algorithms;
 };
diff --git a/myserver/src/base/crypt/crypt_algo_manager.cpp 
b/myserver/src/base/crypt/crypt_algo_manager.cpp
index 3b3afcb..fae94da 100644
--- a/myserver/src/base/crypt/crypt_algo_manager.cpp
+++ b/myserver/src/base/crypt/crypt_algo_manager.cpp
@@ -16,6 +16,11 @@
  */
 
 #include <include/base/crypt/crypt_algo_manager.h>
+#include <memory>
+#include <exception>
+
+using namespace std;
+
 
 /*!
  * C'tor.
@@ -59,3 +64,48 @@ CryptAlgo *CryptAlgoManager::make (string &name)
 
   return NULL;  
 }
+
+/* FIXME: Generalize.  */
+class CryptAlgoManagerException : public exception
+{
+public:
+  virtual const char *what () const throw ()
+  {
+    return message;
+  }
+
+  CryptAlgoManagerException (const char *message)
+  {
+    this->message = message;
+  }
+
+private:
+  const char *message;
+};
+
+/*!
+ * Check if F(value)=result, using the F specified by the algorithm.
+ *
+ * \param value The value to convert.
+ * \param result The final result.
+ * \param algo The name of the algorithm to use.
+ * \return true if F(value)=result.
+ * \throw If the algorithm is not registered, it throws an exception.
+ */
+bool CryptAlgoManager::check (string &value, string &result, string &algo)
+{
+  const size_t buffer_len = 256;
+  char buffer[buffer_len];
+  CryptAlgo *f = make (algo);
+  if (!f)
+    {
+      snprintf (buffer, buffer_len, _("%s is not a registered algorithm"),
+                algo.c_str ());
+      throw CryptAlgoManagerException (buffer);
+    }
+  auto_ptr<CryptAlgo> keeper (f);
+  f->init ();
+  f->update (value.c_str (), value.length ());
+  f->end (buffer);
+  return !result.compare (buffer);
+}
diff --git a/myserver/tests/test_crypt_algo_manager.cpp 
b/myserver/tests/test_crypt_algo_manager.cpp
index f659e6a..575e169 100644
--- a/myserver/tests/test_crypt_algo_manager.cpp
+++ b/myserver/tests/test_crypt_algo_manager.cpp
@@ -31,7 +31,8 @@ using namespace std;
 class TestCryptAlgoManager : public CppUnit::TestFixture
 {
   CPPUNIT_TEST_SUITE ( TestCryptAlgoManager );
-  CPPUNIT_TEST ( testRegister );
+  CPPUNIT_TEST (testRegister);
+  CPPUNIT_TEST (testCheck);
   CPPUNIT_TEST_SUITE_END ();
 
 public:
@@ -65,6 +66,32 @@ public:
     CPPUNIT_ASSERT_EQUAL (cal, (CryptAlgo*) NULL);
   }
 
+  void testCheck ()
+  {
+    string name ("md5");
+    CryptAlgoManager cam;
+    string value ("freedom");
+    string result ("d5aa1729c8c253e5d917a5264855eab8");
+    string wrong  ("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa");
+    Md5::initialize (&cam);
+
+    CPPUNIT_ASSERT (cam.check (value, result, name));
+    CPPUNIT_ASSERT (!cam.check (value, wrong, name));
+    bool raised = false;
+    try
+      {
+        /* Using an algorithm that is not registered causes an
+         * exception.  */
+        cam.check (value, result, wrong);
+      }
+    catch (...)
+      {
+        raised = true;
+      }
+
+    CPPUNIT_ASSERT (raised);
+  }
+
 };
 
 



commit 11a566fae186699430a32395749a8b3ef0e7ac2f
Author: Giuseppe Scrivano <address@hidden>
Date:   Sat Oct 24 00:06:20 2009 +0200

    Use the gnulib snprintf module.

diff --git a/myserver/bootstrap.conf b/myserver/bootstrap.conf
index d646dd0..6ba7214 100644
--- a/myserver/bootstrap.conf
+++ b/myserver/bootstrap.conf
@@ -29,6 +29,7 @@ crypto/md5
 nproc
 regex
 getcwd
+snprintf
 "
 
 gnulib_extra_files="
diff --git a/myserver/src/protocol/control/control_protocol.cpp 
b/myserver/src/protocol/control/control_protocol.cpp
index b38b466..a103c22 100644
--- a/myserver/src/protocol/control/control_protocol.cpp
+++ b/myserver/src/protocol/control/control_protocol.cpp
@@ -29,6 +29,8 @@ along with this program.  If not, see 
<http://www.gnu.org/licenses/>.
 
 extern "C"
 {
+#include <stdio.h>
+
 #ifdef WIN32
 # include <direct.h>
 # include <errno.h>
@@ -535,15 +537,9 @@ int ControlProtocol::addToLog (int retCode, ConnectionPtr 
con, char *buffer,
 {
   string time;
   getRFC822GMTTime (time, 32);
-
-#ifdef HAVE_SNPRINTF
-  snprintf (buffer, bufferSize,
-#else
-  sprintf (buffer,
-#endif
-  "%s [%s] %s:%s:%s - %s - %i", con->getIpAddr (), time.c_str (),
-          header.getCommand (),  header.getVersion (), header.getOptions (),
-          header.getAuthLogin (), retCode);
+  snprintf (buffer, bufferSize, "%s [%s] %s:%s:%s - %s - %i", con->getIpAddr 
(),
+            time.c_str (), header.getCommand (), header.getVersion (),
+            header.getOptions (), header.getAuthLogin (), retCode);
   con->host->accessesLogWrite ("%s", buffer);
   return 0;
 }

-----------------------------------------------------------------------

Summary of changes:
 myserver/bootstrap.conf                            |    1 +
 myserver/configure.ac                              |    2 +-
 myserver/include/base/crypt/crypt_algo_manager.h   |    1 +
 myserver/src/base/crypt/crypt_algo_manager.cpp     |   50 ++++++++++++++++++++
 myserver/src/protocol/control/control_protocol.cpp |   14 ++----
 myserver/tests/test_crypt_algo_manager.cpp         |   29 +++++++++++-
 6 files changed, 86 insertions(+), 11 deletions(-)


hooks/post-receive
-- 
GNU MyServer




reply via email to

[Prev in Thread] Current Thread [Next in Thread]