diff options
author | Randolph Tan <randolph@10gen.com> | 2012-07-11 14:07:15 -0400 |
---|---|---|
committer | Randolph Tan <randolph@10gen.com> | 2012-07-13 14:08:15 -0400 |
commit | 5a55760e7dfa3d637c547d5d8f04719503674e7d (patch) | |
tree | d5990068497ab114996134f14f7c745fb3e54805 /src/mongo/scripting/sm_db.cpp | |
parent | 479b5b9d963b4899c57a9754f824f3614a8dd941 (diff) | |
download | mongo-5a55760e7dfa3d637c547d5d8f04719503674e7d.tar.gz |
SERVER-6334 ReplSet connections magically gets reauthenticated after logging out
Make sure DBClientReplicaSet clears it's auth table entries whenever user logs out.
Diffstat (limited to 'src/mongo/scripting/sm_db.cpp')
-rw-r--r-- | src/mongo/scripting/sm_db.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/src/mongo/scripting/sm_db.cpp b/src/mongo/scripting/sm_db.cpp index 9d37feeec0c..e7b547b8df8 100644 --- a/src/mongo/scripting/sm_db.cpp +++ b/src/mongo/scripting/sm_db.cpp @@ -351,6 +351,42 @@ namespace mongo { return JS_TRUE; } + JSBool mongo_logout(JSContext *context, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { + try { + smuassert(context, "mongo_logout needs 1 arg" , argc == 1); + shared_ptr<DBClientWithCommands>* connHolder = + reinterpret_cast<shared_ptr<DBClientWithCommands>*>( + JS_GetPrivate(context , obj)); + smuassert(context, "no connection!", connHolder && connHolder->get()); + DBClientWithCommands *conn = connHolder->get(); + + Convertor convertor(context); + string db = convertor.toString(argv[0]); + + BSONObj ret; + conn->logout(db, ret); + *rval = convertor.toval(&ret); + } + catch (const AssertionException& e) { + if (!JS_IsExceptionPending(context)) { + JS_ReportError(context, e.what()); + } + return JS_FALSE; + } + catch (const SocketException& e) { + if (!JS_IsExceptionPending(context)) { + JS_ReportError(context, e.toString().c_str()); + } + return JS_FALSE; + } + catch (const std::exception& e) { + log() << "unhandled exception: " << e.what() << ", throwing Fatal Assertion" << endl; + fassertFailed(16396); + } + + return JS_TRUE; + } + JSBool mongo_find(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval) { try { smuassert( cx , "mongo_find needs 7 args" , argc == 7 ); @@ -546,6 +582,7 @@ namespace mongo { JSFunctionSpec mongo_functions[] = { { "auth" , mongo_auth , 0 , JSPROP_READONLY | JSPROP_PERMANENT, 0 } , + { "logout", mongo_logout, 0, JSPROP_READONLY | JSPROP_PERMANENT, 0 }, { "find" , mongo_find , 0 , JSPROP_READONLY | JSPROP_PERMANENT, 0 } , { "update" , mongo_update , 0 , JSPROP_READONLY | JSPROP_PERMANENT, 0 } , { "insert" , mongo_insert , 0 , JSPROP_READONLY | JSPROP_PERMANENT, 0 } , |