summaryrefslogtreecommitdiff
path: root/cpp/src
diff options
context:
space:
mode:
Diffstat (limited to 'cpp/src')
-rw-r--r--cpp/src/Ice/PropertyNames.cpp13
-rw-r--r--cpp/src/Ice/PropertyNames.h3
-rw-r--r--cpp/src/IceGrid/Client.cpp234
-rw-r--r--cpp/src/IceGrid/Parser.cpp11
-rw-r--r--cpp/src/IceGrid/Parser.h5
5 files changed, 242 insertions, 24 deletions
diff --git a/cpp/src/Ice/PropertyNames.cpp b/cpp/src/Ice/PropertyNames.cpp
index f1dfb0d6dd7..9e95ee13ad1 100644
--- a/cpp/src/Ice/PropertyNames.cpp
+++ b/cpp/src/Ice/PropertyNames.cpp
@@ -7,7 +7,7 @@
//
// **********************************************************************
-// Generated by makeprops.py from file `../config/PropertyNames.def', Mon Aug 21 16:37:24 2006
+// Generated by makeprops.py from file `../../config/PropertyNames.def', Mon Aug 28 09:10:05 2006
// IMPORTANT: Do not edit this file -- any edits made here will be lost!
@@ -95,6 +95,15 @@ const char* IceInternal::PropertyNames::IceBoxProps[] =
0
};
+const char* IceInternal::PropertyNames::IceGridAdminProps[] =
+{
+ "IceGridAdmin.UseSecureAuthentication",
+ "IceGridAdmin.Routed",
+ "IceGridAdmin.Username",
+ "IceGridAdmin.Password",
+ 0
+};
+
const char* IceInternal::PropertyNames::IceGridProps[] =
{
"IceGrid.AdminGUI.Endpoints",
@@ -353,6 +362,7 @@ const char* const* IceInternal::PropertyNames::validProps[] =
{
IcePatch2Props,
IceStormProps,
+ IceGridAdminProps,
IceSSLProps,
IceProps,
FreezeProps,
@@ -366,6 +376,7 @@ const char* IceInternal::PropertyNames::clPropNames[] =
{
"Ice",
"IceBox",
+ "IceGridAdmin",
"IceGrid",
"IcePatch2",
"IceSSL",
diff --git a/cpp/src/Ice/PropertyNames.h b/cpp/src/Ice/PropertyNames.h
index 7ea2a4eeeef..138e64763eb 100644
--- a/cpp/src/Ice/PropertyNames.h
+++ b/cpp/src/Ice/PropertyNames.h
@@ -7,7 +7,7 @@
//
// **********************************************************************
-// Generated by makeprops.py from file `../config/PropertyNames.def', Mon Aug 21 16:37:24 2006
+// Generated by makeprops.py from file `../../config/PropertyNames.def', Mon Aug 28 09:10:05 2006
// IMPORTANT: Do not edit this file -- any edits made here will be lost!
@@ -24,6 +24,7 @@ public:
static const char* IceProps[];
static const char* IceBoxProps[];
+ static const char* IceGridAdminProps[];
static const char* IceGridProps[];
static const char* IcePatch2Props[];
static const char* IceSSLProps[];
diff --git a/cpp/src/IceGrid/Client.cpp b/cpp/src/IceGrid/Client.cpp
index c0762890158..d2d3dfb55d2 100644
--- a/cpp/src/IceGrid/Client.cpp
+++ b/cpp/src/IceGrid/Client.cpp
@@ -13,18 +13,71 @@
#include <Ice/SliceChecksums.h>
#include <IceGrid/Parser.h>
#include <IceGrid/FileParserI.h>
+#include <IceGrid/Registry.h>
+#include <Glacier2/Router.h>
#include <fstream>
using namespace std;
using namespace Ice;
using namespace IceGrid;
+class SessionKeepAliveThread : public IceUtil::Thread, public IceUtil::Monitor<IceUtil::Mutex>
+{
+public:
+
+ SessionKeepAliveThread(const IceGrid::AdminSessionPrx& session, long timeout) :
+ _session(session),
+ _timeout(IceUtil::Time::seconds(timeout)),
+ _destroy(false)
+ {
+ }
+
+ virtual void
+ run()
+ {
+ Lock sync(*this);
+ while(!_destroy)
+ {
+ timedWait(_timeout);
+ if(_destroy)
+ {
+ break;
+ }
+ try
+ {
+ _session->keepAlive();
+ }
+ catch(const Ice::Exception&)
+ {
+ break;
+ }
+ }
+ }
+
+ void
+ destroy()
+ {
+ Lock sync(*this);
+ _destroy = true;
+ notify();
+ }
+
+private:
+
+ IceGrid::AdminSessionPrx _session;
+ const IceUtil::Time _timeout;
+ bool _destroy;
+};
+typedef IceUtil::Handle<SessionKeepAliveThread> SessionKeepAliveThreadPtr;
+
class Client : public Application
{
public:
void usage();
virtual int run(int, char*[]);
+
+ string trim(const string&);
};
int
@@ -49,6 +102,10 @@ Client::usage()
"-e COMMANDS Execute COMMANDS.\n"
"-d, --debug Print debug messages.\n"
"-s, --server Start icegridadmin as a server (to parse XML files).\n"
+ "-u, --username Login with the given username.\n"
+ "-p, --password Login with the given password.\n"
+ "-s, --ssl Authenticate through SSL.\n"
+ "-r, --routed Login through a Glacier2 router.\n"
;
}
@@ -66,6 +123,10 @@ Client::run(int argc, char* argv[])
opts.addOpt("U", "", IceUtil::Options::NeedArg, "", IceUtil::Options::Repeat);
opts.addOpt("I", "", IceUtil::Options::NeedArg, "", IceUtil::Options::Repeat);
opts.addOpt("e", "", IceUtil::Options::NeedArg, "", IceUtil::Options::Repeat);
+ opts.addOpt("u", "username", IceUtil::Options::NeedArg, "", IceUtil::Options::NoRepeat);
+ opts.addOpt("p", "password", IceUtil::Options::NeedArg, "", IceUtil::Options::NoRepeat);
+ opts.addOpt("S", "ssl");
+ opts.addOpt("r", "routed");
opts.addOpt("d", "debug");
opts.addOpt("s", "server");
@@ -144,29 +205,140 @@ Client::run(int argc, char* argv[])
usage();
return EXIT_FAILURE;
}
-
- if(!communicator()->getDefaultLocator())
+
+ string instanceName;
+ if(communicator()->getDefaultLocator())
{
- cerr << appName() << "property `Ice.Default.Locator' is not set" << endl;
- return EXIT_FAILURE;
+ instanceName = communicator()->getDefaultLocator()->ice_getIdentity().category;
+ }
+ else
+ {
+ instanceName = communicator()->getProperties()->getPropertyWithDefault("IceGrid.InstanceName", "IceGrid");
}
- string instanceName = communicator()->getDefaultLocator()->ice_getIdentity().category;
+ int timeout;
+ IceGrid::AdminSessionPrx session;
+ bool ssl = communicator()->getProperties()->getPropertyAsInt("IceGridAdmin.UseSecureAuthentication");
+ if(opts.isSet("ssl"))
+ {
+ ssl = true;
+ }
- AdminPrx admin = AdminPrx::checkedCast(communicator()->stringToProxy(instanceName + "/Admin"));
- if(!admin)
+ string id = communicator()->getProperties()->getProperty("IceGridAdmin.Username");
+ if(!opts.optArg("username").empty())
{
- cerr << appName() << ": no valid administrative interface" << endl;
- return EXIT_FAILURE;
+ id = opts.optArg("username");
}
+ string password = communicator()->getProperties()->getProperty("IceGridAdmin.Password");
+ if(!opts.optArg("password").empty())
+ {
+ password = opts.optArg("password");
+ }
+ bool routed = communicator()->getProperties()->getPropertyAsInt("IceGridAdmin.Routed");
+ if(opts.isSet("routed"))
+ {
+ routed = true;
+ }
+
+ try
+ {
+ if(routed)
+ {
+ Glacier2::RouterPrx router = Glacier2::RouterPrx::checkedCast(communicator()->getDefaultRouter());
+ if(!router)
+ {
+ cerr << argv[0] << ": configured router is not a Glacier2 router" << endl;
+ return EXIT_FAILURE;
+ }
+
+ // Use SSL if available.
+ try
+ {
+ router = Glacier2::RouterPrx::checkedCast(router->ice_secure(true));
+ }
+ catch(const Ice::NoEndpointException&)
+ {
+ }
+
+ if(ssl)
+ {
+ session = IceGrid::AdminSessionPrx::uncheckedCast(router->createSessionFromSecureConnection());
+ }
+ else
+ {
+ while(id.empty())
+ {
+ cout << "user id: " << flush;
+ getline(cin, id);
+ id = trim(id);
+ }
+
+ if(password.empty())
+ {
+ cout << "password: " << flush;
+ getline(cin, password);
+ password = trim(password);
+ }
+
+ session = IceGrid::AdminSessionPrx::uncheckedCast(router->createSession(id, password));
+ }
+ timeout = router->getSessionTimeout();
+ }
+ else
+ {
+ IceGrid::RegistryPrx registry = IceGrid::RegistryPrx::checkedCast(
+ communicator()->stringToProxy(instanceName + "/Registry"));
+ if(!registry)
+ {
+ cerr << argv[0] << ": could not contact registry" << endl;
+ return EXIT_FAILURE;
+ }
- QueryPrx query = QueryPrx::checkedCast(communicator()->stringToProxy(instanceName + "/Query"));
- if(!query)
+ // Use SSL if available.
+ try
+ {
+ registry = IceGrid::RegistryPrx::checkedCast(registry->ice_secure(true));
+ }
+ catch(const Ice::NoEndpointException&)
+ {
+ }
+
+ if(ssl)
+ {
+ session = registry->createAdminSessionFromSecureConnection();
+ }
+ else
+ {
+ while(id.empty())
+ {
+ cout << "user id: " << flush;
+ getline(cin, id);
+ id = trim(id);
+ }
+
+ if(password.empty())
+ {
+ cout << "password: " << flush;
+ getline(cin, password);
+ password = trim(password);
+ }
+
+ session = registry->createAdminSession(id, password);
+ }
+ timeout = registry->getSessionTimeout();
+ }
+ }
+ catch(const IceGrid::PermissionDeniedException& ex)
{
- cerr << appName() << ": no valid query interface" << endl;
+ cout << "permission denied:\n" << ex.reason << endl;
return EXIT_FAILURE;
}
+ SessionKeepAliveThreadPtr keepAlive = new SessionKeepAliveThread(session, timeout / 2);
+ keepAlive->start();
+
+ AdminPrx admin = session->getAdmin();
+
Ice::SliceChecksumDict serverChecksums = admin->getSliceChecksums();
Ice::SliceChecksumDict localChecksums = Ice::sliceChecksums();
@@ -189,7 +361,8 @@ Client::run(int argc, char* argv[])
}
}
- ParserPtr p = Parser::createParser(communicator(), admin, query);
+ ParserPtr p = Parser::createParser(communicator(), admin);
+ session->startUpdate();
int status = EXIT_SUCCESS;
@@ -253,5 +426,40 @@ Client::run(int argc, char* argv[])
}
}
+ try
+ {
+ session->finishUpdate();
+ }
+ catch(const Ice::Exception&)
+ {
+ // Ignore. If the registry has been shutdown this will cause
+ // an exception.
+ }
+
+ keepAlive->destroy();
+ keepAlive->getThreadControl().join();
+
+ try
+ {
+ session->destroy();
+ }
+ catch(const Ice::Exception&)
+ {
+ // Ignore. If the registry has been shutdown this will cause
+ // an exception.
+ }
+
return status;
}
+
+string
+Client::trim(const string& s)
+{
+ static const string delims = "\t\r\n ";
+ string::size_type last = s.find_last_not_of(delims);
+ if(last != string::npos)
+ {
+ return s.substr(s.find_first_not_of(delims), last+1);
+ }
+ return s;
+}
diff --git a/cpp/src/IceGrid/Parser.cpp b/cpp/src/IceGrid/Parser.cpp
index a755e60f49d..f2aec2882c6 100644
--- a/cpp/src/IceGrid/Parser.cpp
+++ b/cpp/src/IceGrid/Parser.cpp
@@ -41,9 +41,9 @@ Parser* parser;
}
ParserPtr
-Parser::createParser(const CommunicatorPtr& communicator, const AdminPrx& admin, const QueryPrx& query)
+Parser::createParser(const CommunicatorPtr& communicator, const AdminPrx& admin)
{
- return new Parser(communicator, admin, query);
+ return new Parser(communicator, admin);
}
void
@@ -1494,10 +1494,9 @@ Parser::parse(const std::string& commands, bool debug)
return status;
}
-Parser::Parser(const CommunicatorPtr& communicator, const AdminPrx& admin, const QueryPrx& query) :
+Parser::Parser(const CommunicatorPtr& communicator, const AdminPrx& admin) :
_communicator(communicator),
- _admin(admin),
- _query(query)
+ _admin(admin)
{
}
@@ -1563,7 +1562,7 @@ Parser::exception(const Ice::Exception& ex)
}
catch(const AccessDeniedException& ex)
{
- error("couldn't update the registry, the session from + `" + ex.lockUserId + "' is updating the registry");
+ error("couldn't update the registry, the session from `" + ex.lockUserId + "' is updating the registry");
}
catch(const IceXML::ParserException& ex)
{
diff --git a/cpp/src/IceGrid/Parser.h b/cpp/src/IceGrid/Parser.h
index c793e540d5a..23c5d4d3f51 100644
--- a/cpp/src/IceGrid/Parser.h
+++ b/cpp/src/IceGrid/Parser.h
@@ -66,7 +66,7 @@ class Parser : public ::IceUtil::SimpleShared
{
public:
- static ParserPtr createParser(const Ice::CommunicatorPtr&, const IceGrid::AdminPrx&, const IceGrid::QueryPrx&);
+ static ParserPtr createParser(const Ice::CommunicatorPtr&, const IceGrid::AdminPrx&);
void usage();
@@ -137,13 +137,12 @@ public:
private:
- Parser(const Ice::CommunicatorPtr&, const IceGrid::AdminPrx&, const IceGrid::QueryPrx&);
+ Parser(const Ice::CommunicatorPtr&, const IceGrid::AdminPrx&);
void exception(const Ice::Exception&);
std::string _commands;
Ice::CommunicatorPtr _communicator;
IceGrid::AdminPrx _admin;
- IceGrid::QueryPrx _query;
bool _continue;
int _errors;
int _currentLine;