aboutsummaryrefslogtreecommitdiff
path: root/rpc.cpp
diff options
context:
space:
mode:
authors_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>2010-09-15 22:10:13 +0000
committers_nakamoto <s_nakamoto@1a98c847-1fd6-4fd8-948a-caf3550aa51b>2010-09-15 22:10:13 +0000
commitefae3da41d821b12d1481de8b8e0b2e105d36ae3 (patch)
treea5d236f56a3f2d69d48e9b42297d6653601da057 /rpc.cpp
parent3df62878c3cece15a8921fbbdee7859ee9368768 (diff)
config option -rpcallowip= to accept json-rpc connections from another machine
git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@155 1a98c847-1fd6-4fd8-948a-caf3550aa51b
Diffstat (limited to 'rpc.cpp')
-rw-r--r--rpc.cpp24
1 files changed, 18 insertions, 6 deletions
diff --git a/rpc.cpp b/rpc.cpp
index 0970c87b2d..9a4757390f 100644
--- a/rpc.cpp
+++ b/rpc.cpp
@@ -783,8 +783,9 @@ int ReadHTTPStatus(tcp::iostream& stream)
getline(stream, str);
vector<string> vWords;
boost::split(vWords, str, boost::is_any_of(" "));
- int nStatus = atoi(vWords[1].c_str());
- return nStatus;
+ if (vWords.size() < 2)
+ return 500;
+ return atoi(vWords[1].c_str());
}
int ReadHTTPHeader(tcp::iostream& stream, map<string, string>& mapHeadersRet)
@@ -918,6 +919,17 @@ string JSONRPCReply(const Value& result, const Value& error, const Value& id)
return write_string(Value(reply), false) + "\n";
}
+bool ClientAllowed(const string& strAddress)
+{
+ if (strAddress == asio::ip::address_v4::loopback().to_string())
+ return true;
+ const vector<string>& vAllow = mapMultiArgs["-rpcallowip"];
+ foreach(string strAllow, vAllow)
+ if (WildcardMatch(strAddress, strAllow))
+ return true;
+ return false;
+}
+
@@ -962,7 +974,7 @@ void ThreadRPCServer2(void* parg)
// Bind to loopback 127.0.0.1 so the socket can only be accessed locally
boost::asio::io_service io_service;
- tcp::endpoint endpoint(boost::asio::ip::address_v4::loopback(), 8332);
+ tcp::endpoint endpoint(mapArgs.count("-rpcallowip") ? asio::ip::address_v4::any() : asio::ip::address_v4::loopback(), 8332);
tcp::acceptor acceptor(io_service, endpoint);
loop
@@ -976,8 +988,8 @@ void ThreadRPCServer2(void* parg)
if (fShutdown)
return;
- // Shouldn't be possible for anyone else to connect, but just in case
- if (peer.address().to_string() != "127.0.0.1")
+ // Restrict callers by IP
+ if (!ClientAllowed(peer.address().to_string()))
continue;
// Receive request
@@ -1090,7 +1102,7 @@ Object CallRPC(const string& strMethod, const Array& params)
GetConfigFile().c_str()));
// Connect to localhost
- tcp::iostream stream("127.0.0.1", "8332");
+ tcp::iostream stream(GetArg("-rpcconnect", "127.0.0.1"), "8332");
if (stream.fail())
throw runtime_error("couldn't connect to server");