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. 0_9_2-6-ga


From: Giuseppe Scrivano
Subject: [myserver-commit] [SCM] GNU MyServer branch, master, updated. 0_9_2-6-gaf784c2
Date: Thu, 18 Feb 2010 10:43:41 +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  af784c22995cd1d92e25ff53b21c68c8bb6ed14f (commit)
      from  257530993ef3c84242e56ce0edf76302b31f15ff (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 af784c22995cd1d92e25ff53b21c68c8bb6ed14f
Author: Giuseppe Scrivano <address@hidden>
Date:   Thu Feb 18 11:41:03 2010 +0100

    Refactor HomeDir::getHomeDir return codes.
    
    Now HomeDir::getHomeDir includes checks done previously by the
    TestHomeDir::testGetAdmin test.

diff --git a/myserver/src/base/home_dir/home_dir.cpp 
b/myserver/src/base/home_dir/home_dir.cpp
index 1870572..90b346c 100644
--- a/myserver/src/base/home_dir/home_dir.cpp
+++ b/myserver/src/base/home_dir/home_dir.cpp
@@ -228,6 +228,8 @@ int HomeDir::loadImpl ()
  * \param userName The user name.
  * \param out The buffer where write.
  * \return 0 on success.
+ * \return < 0 on error.
+ * \return > 0 if the user home directory does not exist.
  */
 int HomeDir::getHomeDir (string& userName, string& out)
 {
@@ -235,6 +237,7 @@ int HomeDir::getHomeDir (string& userName, string& out)
   out.assign (data);
   out.append ("/");
   out.append (userName);
+  return FilesUtility::fileExists (out.c_str ()) ? 0 : 1;
 #elif HAVE_GETPWNAM
   struct passwd *p;
   int ret = 0;
@@ -249,13 +252,18 @@ int HomeDir::getHomeDir (string& userName, string& out)
 
   loadMutex.unlock ();
 
-  return ret;
+  /* The user was not found.  */
+  if (p == NULL && (errno == ENOENT || errno == ESRCH || errno == EBADF
+                    || errno == EPERM))
+    return 1;
+
+  return p ? 0 : -1;
 #else
   static u_long lastCheckTime = 0;
   string *res = 0;
 
   if (!loaded)
-    return 1;
+    return -1;
 
   if (getTicks () - lastCheckTime > MYSERVER_SEC (1))
     {
@@ -265,9 +273,13 @@ int HomeDir::getHomeDir (string& userName, string& out)
     }
   res = data.get (userName);
   if (res)
+    {
       out.assign (*res);
+      return 0;
+    }
   else
-    out.assign ("");
+    return 1;
 #endif
-  return 0;
+
+  return -1;
 }
diff --git a/myserver/tests/test_homedir.cpp b/myserver/tests/test_homedir.cpp
index 3e0b959..ce8f295 100644
--- a/myserver/tests/test_homedir.cpp
+++ b/myserver/tests/test_homedir.cpp
@@ -17,14 +17,11 @@
 
 #include "myserver.h"
 #include <include/base/home_dir/home_dir.h>
-#include <include/base/file/files_utility.h>
 #include <cppunit/CompilerOutputter.h>
 #include <cppunit/extensions/TestFactoryRegistry.h>
 #include <cppunit/ui/text/TestRunner.h>
 #include <cppunit/extensions/HelperMacros.h>
 
-#include <errno.h>
-
 class TestHomeDir : public CppUnit::TestFixture
 {
   CPPUNIT_TEST_SUITE ( TestHomeDir );
@@ -62,28 +59,14 @@ public:
     username.assign ("root");
 #endif
     string dir;
-
-#if !WIN32
-    errno = 0;
-#endif
-
     int ret = homeDir->getHomeDir (username, dir);
 
-    /* FIXME: handle this case in homeDir::getHomeDir.  */
-#if HAVE_GETPWNAM
     /* If the user could not be found, silently return.  */
-    if (ret && (errno == ENOENT || errno == ESRCH || errno == EBADF
-                || errno == EPERM))
+    if (ret > 0)
       return;
-#elif !WIN32
-    if (! FilesUtility::fileExists ("/etc/passwd") || !dir.length ())
-      return;
-#endif
 
     CPPUNIT_ASSERT_EQUAL (ret, 0);
-
     CPPUNIT_ASSERT (dir.length ());
-
     homeDir->clear ();
   }
 

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

Summary of changes:
 myserver/src/base/home_dir/home_dir.cpp |   20 ++++++++++++++++----
 myserver/tests/test_homedir.cpp         |   19 +------------------
 2 files changed, 17 insertions(+), 22 deletions(-)


hooks/post-receive
-- 
GNU MyServer




reply via email to

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