From: Thomas Jarosch Date: Thu, 4 Dec 2008 14:14:35 +0000 (+0000) Subject: libi2ncommon: (tomj) fix i2n::User and i2n::Group usage of uid/gid -1 (-1 is reserved... X-Git-Tag: v2.6~141 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=4c1da7a3d70b734038041a172329aaee6b9a1703;p=libi2ncommon libi2ncommon: (tomj) fix i2n::User and i2n::Group usage of uid/gid -1 (-1 is reserved and ok) --- diff --git a/src/userfunc.cpp b/src/userfunc.cpp index 69ac1f9..9b6196e 100644 --- a/src/userfunc.cpp +++ b/src/userfunc.cpp @@ -82,8 +82,8 @@ bool copy_data ( struct group* from , Group& to) */ User::User() -: Uid (-1) -, Gid (-1) +: Uid ((uid_t)-1) +, Gid ((gid_t)-1) { } // User::User() @@ -127,9 +127,8 @@ void User::clear() { Name.clear(); Password.clear(); - // FIXME: Uid and Gid is unsigned - Uid= -1; - Gid= -1; + Uid= (uid_t)-1; + Gid= (gid_t)-1; Gecos.clear(); Homedir.clear(); Shell.clear(); @@ -145,8 +144,7 @@ void User::clear() */ bool User::is_valid() const { - // FIXME: Uid and Gid is unsigned, so the first expression is always true! - return (Uid >= 0) and (Gid >= 0) + return (Uid != (uid_t)-1) and (Gid != (gid_t)-1) and not Name.empty() ; } // eo User::is_valid() const @@ -158,7 +156,7 @@ bool User::is_valid() const Group::Group() -: Gid (-1) // FIXME: Gid is unsigned +: Gid ((gid_t)-1) { } // eo Group::Group() @@ -201,8 +199,7 @@ void Group::clear() { Name.clear(); Password.clear(); - // FIXME: Gid is unsigned - Gid= -1; + Gid= (gid_t)-1; Members.clear(); } // eo Group::clear() @@ -216,8 +213,7 @@ void Group::clear() */ bool Group::is_valid() const { - // FIXME: Gid is unsigned, so the first expression is always true! - return (Gid >= 0) and not Name.empty(); + return (Gid != (gid_t)-1) and not Name.empty(); } // eo Group::is_valid() const /** diff --git a/test/test_filefunc.cpp b/test/test_filefunc.cpp index 0acdca3..92cc923 100644 --- a/test/test_filefunc.cpp +++ b/test/test_filefunc.cpp @@ -53,6 +53,7 @@ class TestFileFunc : public TestFixture CPPUNIT_TEST(NormalizePath1); CPPUNIT_TEST(NormalizePath2); CPPUNIT_TEST(TestUserAndGroupStuff1); + CPPUNIT_TEST(TestUserAndGroupStuff2); CPPUNIT_TEST(TestFileModes1); CPPUNIT_TEST(TestPidOf1); CPPUNIT_TEST(TestCopyFileSourceFail); @@ -254,7 +255,15 @@ public: } // TestUserAndGroupStuff1() + void TestUserAndGroupStuff2() + { + // Test if is_valid() works correctly + User user_root; + CPPUNIT_ASSERT_EQUAL( false, user_root.is_valid() ); + Group group_root; + CPPUNIT_ASSERT_EQUAL( false, group_root.is_valid() ); + } void TestFileModes1() {