mirror of
https://gitlab.isc.org/isc-projects/kea
synced 2025-08-30 13:37:55 +00:00
Merge branch 'work/sockets'
This commit is contained in:
@@ -712,6 +712,7 @@ AC_OUTPUT([doc/version.ent
|
||||
src/bin/xfrout/xfrout.py
|
||||
src/bin/xfrout/xfrout.spec.pre
|
||||
src/bin/xfrout/tests/xfrout_test
|
||||
src/bin/xfrout/tests/xfrout_test.py
|
||||
src/bin/xfrout/run_b10-xfrout.sh
|
||||
src/bin/resolver/resolver.spec.pre
|
||||
src/bin/resolver/spec_config.h.pre
|
||||
|
@@ -41,7 +41,7 @@ b10_auth_SOURCES += auth_srv.cc auth_srv.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
|
||||
b10_auth_SOURCES += common.h common.cc
|
||||
b10_auth_SOURCES += statistics.cc statistics.h
|
||||
b10_auth_SOURCES += main.cc
|
||||
b10_auth_LDADD = $(top_builddir)/src/lib/datasrc/libdatasrc.la
|
||||
|
36
src/bin/auth/common.cc
Normal file
36
src/bin/auth/common.cc
Normal file
@@ -0,0 +1,36 @@
|
||||
// Copyright (C) 2009-2011 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 <auth/common.h>
|
||||
#include <auth/spec_config.h>
|
||||
#include <cstdlib>
|
||||
|
||||
using std::string;
|
||||
|
||||
string getXfroutSocketPath() {
|
||||
if (getenv("B10_FROM_BUILD") != NULL) {
|
||||
if (getenv("B10_FROM_SOURCE_LOCALSTATEDIR")) {
|
||||
return (string(getenv("B10_FROM_SOURCE_LOCALSTATEDIR")) +
|
||||
"/auth_xfrout_conn");
|
||||
} else {
|
||||
return (string(getenv("B10_FROM_BUILD")) + "/auth_xfrout_conn");
|
||||
}
|
||||
} else {
|
||||
if (getenv("BIND10_XFROUT_SOCKET_FILE")) {
|
||||
return (getenv("BIND10_XFROUT_SOCKET_FILE"));
|
||||
} else {
|
||||
return (UNIX_SOCKET_FILE);
|
||||
}
|
||||
}
|
||||
}
|
@@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2009 Internet Systems Consortium, Inc. ("ISC")
|
||||
// Copyright (C) 2009-2011 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
|
||||
@@ -29,6 +29,15 @@ public:
|
||||
{}
|
||||
};
|
||||
|
||||
/// \short Get the path of socket to talk to xfrout
|
||||
///
|
||||
/// It takes some environment variables into account (B10_FROM_BUILD,
|
||||
/// B10_FROM_SOURCE_LOCALSTATEDIR and BIND10_XFROUT_SOCKET_FILE). It
|
||||
/// also considers the installation prefix.
|
||||
///
|
||||
/// The logic should be the same as in b10-xfrout, so they find each other.
|
||||
std::string getXfroutSocketPath();
|
||||
|
||||
#endif // __COMMON_H
|
||||
|
||||
// Local Variables:
|
||||
|
@@ -1,4 +1,4 @@
|
||||
// Copyright (C) 2009 Internet Systems Consortium, Inc. ("ISC")
|
||||
// Copyright (C) 2009-2011 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
|
||||
@@ -122,19 +122,7 @@ main(int argc, char* argv[]) {
|
||||
bool xfrin_session_established = false; // XXX (see Trac #287)
|
||||
bool statistics_session_established = false; // XXX (see Trac #287)
|
||||
ModuleCCSession* config_session = NULL;
|
||||
string xfrout_socket_path;
|
||||
if (getenv("B10_FROM_BUILD") != NULL) {
|
||||
if (getenv("B10_FROM_SOURCE_LOCALSTATEDIR")) {
|
||||
xfrout_socket_path = string("B10_FROM_SOURCE_LOCALSTATEDIR") +
|
||||
"/auth_xfrout_conn";
|
||||
} else {
|
||||
xfrout_socket_path = string(getenv("B10_FROM_BUILD")) +
|
||||
"/auth_xfrout_conn";
|
||||
}
|
||||
} else {
|
||||
xfrout_socket_path = UNIX_SOCKET_FILE;
|
||||
}
|
||||
XfroutClient xfrout_client(xfrout_socket_path);
|
||||
XfroutClient xfrout_client(getXfroutSocketPath());
|
||||
try {
|
||||
string specfile;
|
||||
if (getenv("B10_FROM_BUILD")) {
|
||||
|
@@ -24,10 +24,12 @@ 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
|
||||
run_unittests_SOURCES += ../statistics.h ../statistics.cc
|
||||
run_unittests_SOURCES += auth_srv_unittest.cc
|
||||
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
|
||||
|
96
src/bin/auth/tests/common_unittest.cc
Normal file
96
src/bin/auth/tests/common_unittest.cc
Normal file
@@ -0,0 +1,96 @@
|
||||
// Copyright (C) 2011 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 <gtest/gtest.h>
|
||||
#include <auth/common.h>
|
||||
#include <auth/spec_config.h>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <cstdio>
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
using std::pair;
|
||||
using std::vector;
|
||||
using std::string;
|
||||
|
||||
namespace {
|
||||
|
||||
class Paths : public ::testing::Test {
|
||||
private:
|
||||
typedef pair<string, string*> Environ;
|
||||
vector<Environ> restoreEnviron;
|
||||
public:
|
||||
void TearDown() {
|
||||
// Restore the original environment
|
||||
BOOST_FOREACH(const Environ &env, restoreEnviron) {
|
||||
if (env.second == NULL) {
|
||||
EXPECT_EQ(0, unsetenv(env.first.c_str())) <<
|
||||
"Couldn't restore environment, results of other tests"
|
||||
"are uncertain";
|
||||
} else {
|
||||
EXPECT_EQ(0, setenv(env.first.c_str(), env.second->c_str(),
|
||||
1)) << "Couldn't restore environment, "
|
||||
"results of other tests are uncertain";
|
||||
}
|
||||
}
|
||||
}
|
||||
protected:
|
||||
// Sets a temporary value into environment. If value is empty, it deletes
|
||||
// the variable from environment (just for simplicity).
|
||||
void setEnv(const string& name, const string& value) {
|
||||
// Backup the original environment
|
||||
char* env(getenv(name.c_str()));
|
||||
restoreEnviron.push_back(Environ(name, env == NULL ? NULL :
|
||||
new string(env)));
|
||||
// Set the new value
|
||||
if (value.empty()) {
|
||||
EXPECT_EQ(0, unsetenv(name.c_str()));
|
||||
} else {
|
||||
EXPECT_EQ(0, setenv(name.c_str(), value.c_str(), 1));
|
||||
}
|
||||
}
|
||||
// Test getXfroutSocketPath under given environment
|
||||
void testXfrout(const string& fromBuild, const string& localStateDir,
|
||||
const string& socketFile, const string& expected)
|
||||
{
|
||||
setEnv("B10_FROM_BUILD", fromBuild);
|
||||
setEnv("B10_FROM_SOURCE_LOCALSTATEDIR", localStateDir);
|
||||
setEnv("BIND10_XFROUT_SOCKET_FILE", socketFile);
|
||||
EXPECT_EQ(expected, getXfroutSocketPath());
|
||||
}
|
||||
};
|
||||
|
||||
// Test that when we have no special environment, we get the default from prefix
|
||||
TEST_F(Paths, xfroutNoEnv) {
|
||||
testXfrout("", "", "", UNIX_SOCKET_FILE);
|
||||
}
|
||||
|
||||
// Override by B10_FROM_BUILD
|
||||
TEST_F(Paths, xfroutFromBuild) {
|
||||
testXfrout("/from/build", "", "/wrong/path",
|
||||
"/from/build/auth_xfrout_conn");
|
||||
}
|
||||
|
||||
// Override by B10_FROM_SOURCE_LOCALSTATEDIR
|
||||
TEST_F(Paths, xfroutLocalStatedir) {
|
||||
testXfrout("/wrong/path", "/state/dir", "/wrong/path",
|
||||
"/state/dir/auth_xfrout_conn");
|
||||
}
|
||||
|
||||
// Override by BIND10_XFROUT_SOCKET_FILE explicitly
|
||||
TEST_F(Paths, xfroutFromEnv) {
|
||||
testXfrout("", "", "/the/path/to/file", "/the/path/to/file");
|
||||
}
|
||||
|
||||
}
|
@@ -21,6 +21,7 @@ import os
|
||||
from isc.cc.session import *
|
||||
from pydnspp import *
|
||||
from xfrout import *
|
||||
import xfrout
|
||||
|
||||
# our fake socket, where we can read and insert messages
|
||||
class MySocket():
|
||||
@@ -433,5 +434,36 @@ class TestUnixSockServer(unittest.TestCase):
|
||||
sys.stdout = old_stdout
|
||||
os.rmdir(dir_name)
|
||||
|
||||
class TestInitialization(unittest.TestCase):
|
||||
def setEnv(self, name, value):
|
||||
if value is None:
|
||||
if name in os.environ:
|
||||
del os.environ[name]
|
||||
else:
|
||||
os.environ[name] = value
|
||||
|
||||
def setUp(self):
|
||||
self._oldSocket = os.getenv("BIND10_XFROUT_SOCKET_FILE")
|
||||
self._oldFromBuild = os.getenv("B10_FROM_BUILD")
|
||||
|
||||
def tearDown(self):
|
||||
self.setEnv("B10_FROM_BUILD", self._oldFromBuild)
|
||||
self.setEnv("BIND10_XFROUT_SOCKET_FILE", self._oldSocket)
|
||||
# Make sure even the computed values are back
|
||||
xfrout.init_paths()
|
||||
|
||||
def testNoEnv(self):
|
||||
self.setEnv("B10_FROM_BUILD", None)
|
||||
self.setEnv("BIND10_XFROUT_SOCKET_FILE", None)
|
||||
xfrout.init_paths()
|
||||
self.assertEqual(xfrout.UNIX_SOCKET_FILE,
|
||||
"@@LOCALSTATEDIR@@/auth_xfrout_conn")
|
||||
|
||||
def testProvidedSocket(self):
|
||||
self.setEnv("B10_FROM_BUILD", None)
|
||||
self.setEnv("BIND10_XFROUT_SOCKET_FILE", "The/Socket/File")
|
||||
xfrout.init_paths()
|
||||
self.assertEqual(xfrout.UNIX_SOCKET_FILE, "The/Socket/File")
|
||||
|
||||
if __name__== "__main__":
|
||||
unittest.main()
|
@@ -46,7 +46,11 @@ except ImportError as e:
|
||||
|
||||
isc.util.process.rename()
|
||||
|
||||
if "B10_FROM_BUILD" in os.environ:
|
||||
def init_paths():
|
||||
global SPECFILE_PATH
|
||||
global AUTH_SPECFILE_PATH
|
||||
global UNIX_SOCKET_FILE
|
||||
if "B10_FROM_BUILD" in os.environ:
|
||||
SPECFILE_PATH = os.environ["B10_FROM_BUILD"] + "/src/bin/xfrout"
|
||||
AUTH_SPECFILE_PATH = os.environ["B10_FROM_BUILD"] + "/src/bin/auth"
|
||||
if "B10_FROM_SOURCE_LOCALSTATEDIR" in os.environ:
|
||||
@@ -54,13 +58,18 @@ if "B10_FROM_BUILD" in os.environ:
|
||||
"/auth_xfrout_conn"
|
||||
else:
|
||||
UNIX_SOCKET_FILE = os.environ["B10_FROM_BUILD"] + "/auth_xfrout_conn"
|
||||
else:
|
||||
else:
|
||||
PREFIX = "@prefix@"
|
||||
DATAROOTDIR = "@datarootdir@"
|
||||
SPECFILE_PATH = "@datadir@/@PACKAGE@".replace("${datarootdir}", DATAROOTDIR).replace("${prefix}", PREFIX)
|
||||
AUTH_SPECFILE_PATH = SPECFILE_PATH
|
||||
if "BIND10_XFROUT_SOCKET_FILE" in os.environ:
|
||||
UNIX_SOCKET_FILE = os.environ["BIND10_XFROUT_SOCKET_FILE"]
|
||||
else:
|
||||
UNIX_SOCKET_FILE = "@@LOCALSTATEDIR@@/auth_xfrout_conn"
|
||||
|
||||
init_paths()
|
||||
|
||||
SPECFILE_LOCATION = SPECFILE_PATH + "/xfrout.spec"
|
||||
AUTH_SPECFILE_LOCATION = AUTH_SPECFILE_PATH + os.sep + "auth.spec"
|
||||
MAX_TRANSFERS_OUT = 10
|
||||
|
Reference in New Issue
Block a user