From: Michal 'vorner' Vaner Date: Wed, 28 Dec 2011 12:15:19 +0000 (+0100) Subject: [1510] Remove the -u flag from auth X-Git-Tag: trac2351_base~300^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=dcfd99e26c1cf8040d58a77a689ad7939cc24884;p=thirdparty%2Fkea.git [1510] Remove the -u flag from auth --- diff --git a/src/bin/auth/Makefile.am b/src/bin/auth/Makefile.am index 3d604321dd..66abbe2db6 100644 --- a/src/bin/auth/Makefile.am +++ b/src/bin/auth/Makefile.am @@ -44,7 +44,6 @@ pkglibexec_PROGRAMS = b10-auth b10_auth_SOURCES = query.cc query.h b10_auth_SOURCES += auth_srv.cc auth_srv.h b10_auth_SOURCES += auth_log.cc auth_log.h -b10_auth_SOURCES += change_user.cc change_user.h b10_auth_SOURCES += auth_config.cc auth_config.h b10_auth_SOURCES += command.cc command.h b10_auth_SOURCES += common.h common.cc diff --git a/src/bin/auth/b10-auth.xml b/src/bin/auth/b10-auth.xml index 636f437993..f2f185a8f6 100644 --- a/src/bin/auth/b10-auth.xml +++ b/src/bin/auth/b10-auth.xml @@ -45,7 +45,6 @@ b10-auth - @@ -92,20 +91,6 @@ - - - - - The user name of the b10-auth daemon. - If specified, the daemon changes the process owner to the - specified user. - The username must be either a - valid numeric user ID or a valid user name. - By default the daemon runs as the user who invokes it. - - - - diff --git a/src/bin/auth/change_user.cc b/src/bin/auth/change_user.cc deleted file mode 100644 index 253b8fbe2b..0000000000 --- a/src/bin/auth/change_user.cc +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC") -// -// Permission to use, copy, modify, and/or distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice appear in all copies. -// -// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH -// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, -// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE -// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -// PERFORMANCE OF THIS SOFTWARE. - -#include -#include -#include -#include - -#include - -#include - -#include - -using namespace boost; -using namespace std; - -void -changeUser(const char* const username) { - const struct passwd *runas_pw = NULL; - - runas_pw = getpwnam(username); - endpwent(); - if (runas_pw == NULL) { - try { - runas_pw = getpwuid(lexical_cast(username)); - endpwent(); - } catch (const bad_lexical_cast&) { - ; // fall through to isc_throw below. - } - } - if (runas_pw == NULL) { - throw FatalError("Unknown user name or UID:" + string(username)); - } - - if (setgid(runas_pw->pw_gid) < 0) { - throw FatalError("setgid() failed: " + string(strerror(errno))); - } - - if (setuid(runas_pw->pw_uid) < 0) { - throw FatalError("setuid() failed: " + string(strerror(errno))); - } -} diff --git a/src/bin/auth/change_user.h b/src/bin/auth/change_user.h deleted file mode 100644 index e4fc5ee5a2..0000000000 --- a/src/bin/auth/change_user.h +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC") -// -// Permission to use, copy, modify, and/or distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice appear in all copies. -// -// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH -// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, -// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE -// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -// PERFORMANCE OF THIS SOFTWARE. - -#ifndef __CHANGE_USER_H -#define __CHANGE_USER_H 1 - -/// \brief Change the run time user. -/// -/// This function changes the user and its group of the authoritative server -/// process. -/// -/// On success the user ID of the process is changed to the specified user, -/// and the group is changed to that of the new user. -/// -/// This is considered a short term workaround until we develop clearer -/// privilege separation, where the server won't even have to open privileged -/// ports and can be started by a non privileged user from the beginning. -/// This function therefore ignores some corner case problems (see below) -/// which we would address otherwise. -/// -/// \c username can be either a textual user name or its numeric ID. -/// If the specified user name (or ID) doesn't specify a local user ID -/// or the user originally starting the process doesn't have a permission -/// of changing the user to \c username, this function throws an exception -/// of class \c FatalError. -/// -/// This function internally uses system libraries that do not guarantee -/// reentrancy. In fact, it doesn't even expect to be called more than once. -/// The behavior is undefined if this function is called from multiple threads -/// simultaneously or more generally called multiple times. -/// -/// This function only offers the basic exception guarantee, that is, if -/// an exception is thrown from this function, it's possible that an exception -/// is thrown after changing the group ID. This function doesn't recover -/// from that situation. In practice, the process is expected to consider -/// this event a fatal error and will immediately exit, and shouldn't cause -/// a real trouble. -/// -/// \param username User name or ID of the new effective user. -void changeUser(const char* const username); - -#endif // __CHANGE_USER_H - -// Local Variables: -// mode: c++ -// End: diff --git a/src/bin/auth/main.cc b/src/bin/auth/main.cc index c8f6762aad..caf4a9170d 100644 --- a/src/bin/auth/main.cc +++ b/src/bin/auth/main.cc @@ -42,7 +42,6 @@ #include #include #include -#include #include #include #include @@ -85,7 +84,6 @@ usage() { cerr << "Usage: b10-auth [-u user] [-nv]" << endl; cerr << "\t-n: do not cache answers in memory" << endl; - cerr << "\t-u: change process UID to the specified user" << endl; cerr << "\t-v: verbose output" << endl; exit(1); } @@ -95,7 +93,6 @@ usage() { int main(int argc, char* argv[]) { int ch; - const char* uid = NULL; bool cache = true; bool verbose = false; @@ -104,9 +101,6 @@ main(int argc, char* argv[]) { case 'n': cache = false; break; - case 'u': - uid = optarg; - break; case 'v': verbose = true; break; @@ -198,10 +192,6 @@ main(int argc, char* argv[]) { LOG_ERROR(auth_logger, AUTH_CONFIG_LOAD_FAIL).arg(ex.what()); } - if (uid != NULL) { - changeUser(uid); - } - LOG_DEBUG(auth_logger, DBG_AUTH_START, AUTH_LOAD_TSIG); isc::server_common::initKeyring(*config_session); auth_server->setTSIGKeyRing(&isc::server_common::keyring); diff --git a/src/bin/auth/tests/Makefile.am b/src/bin/auth/tests/Makefile.am index b5b96d7b24..d24ba89957 100644 --- a/src/bin/auth/tests/Makefile.am +++ b/src/bin/auth/tests/Makefile.am @@ -24,7 +24,6 @@ run_unittests_SOURCES += $(top_srcdir)/src/lib/dns/tests/unittest_util.cc run_unittests_SOURCES += ../auth_srv.h ../auth_srv.cc run_unittests_SOURCES += ../auth_log.h ../auth_log.cc run_unittests_SOURCES += ../query.h ../query.cc -run_unittests_SOURCES += ../change_user.h ../change_user.cc run_unittests_SOURCES += ../auth_config.h ../auth_config.cc run_unittests_SOURCES += ../command.h ../command.cc run_unittests_SOURCES += ../common.h ../common.cc @@ -34,7 +33,6 @@ run_unittests_SOURCES += config_unittest.cc run_unittests_SOURCES += command_unittest.cc run_unittests_SOURCES += common_unittest.cc run_unittests_SOURCES += query_unittest.cc -run_unittests_SOURCES += change_user_unittest.cc run_unittests_SOURCES += statistics_unittest.cc run_unittests_SOURCES += run_unittests.cc # This is a temporary workaround for #1206, where the InMemoryClient has been diff --git a/src/bin/auth/tests/change_user_unittest.cc b/src/bin/auth/tests/change_user_unittest.cc deleted file mode 100644 index 33897b6850..0000000000 --- a/src/bin/auth/tests/change_user_unittest.cc +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (C) 2010 Internet Systems Consortium, Inc. ("ISC") -// -// Permission to use, copy, modify, and/or distribute this software for any -// purpose with or without fee is hereby granted, provided that the above -// copyright notice and this permission notice appear in all copies. -// -// THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH -// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -// AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, -// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE -// OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -// PERFORMANCE OF THIS SOFTWARE. - -#include -#include // for getuid - -#include - -#include - -#include - -#include -#include - -using namespace std; - -namespace { -TEST(ChangeUserTest, changeToTheSameUser) { - const char* const my_username = getenv("USER"); - - // normally the USER environment variable should be set to the name - // of the local user running this test, but it's not always the case. - if (my_username == NULL) { - cerr << "Environment variable USER is undefined, skipping the test" - << endl; - return; - } - - // changing to the run time user should succeed. - EXPECT_NO_THROW(changeUser(my_username)); -} - -TEST(ChangeUserTest, changeToTheSameUserId) { - // same as above, but using numeric user ID - EXPECT_NO_THROW(changeUser( - (boost::lexical_cast(getuid())).c_str())); -} - -TEST(ChangeUserTest, badUID) { - // -1 should be an invalid numeric UID, and (hopefully) shouldn't be - // a valid textual username. - EXPECT_THROW(changeUser("-1"), FatalError); -} - -TEST(ChangeUserTest, promotionAttempt) { - // change to root should fail unless the running user is a super user. - if (getuid() == 0) { - cerr << "Already a super user, skipping the test" << endl; - return; - } - EXPECT_THROW(changeUser("root"), FatalError); -} -}