Repository :
http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
---------------------------------------------------------------
commit a4dfa43c6bea040d78c3489bf2da2ed5f7eaa432
Author: Peter Hatina <phatina(a)redhat.com>
Date: Tue Feb 19 16:28:16 2013 +0100
introduce simple authentication check
---------------------------------------------------------------
cli-tools/lmishell | 19 ++++++++++++++++++-
1 files changed, 18 insertions(+), 1 deletions(-)
diff --git a/cli-tools/lmishell b/cli-tools/lmishell
index e56a800..aaa5c30 100755
--- a/cli-tools/lmishell
+++ b/cli-tools/lmishell
@@ -17,6 +17,7 @@
import os
import sys
import code
+import pywbem
import readline
import rlcompleter
import __builtin__
@@ -294,7 +295,23 @@ def _connect(hostname, username = "", password =
"", interactive = False):
return None
sys.stdout.write("\n")
readline.remove_history_item(readline.get_current_history_length() - 1)
- return LmiConnection(hostname, username, password, interactive)
+ # Try to get some non-existing class as a login check
+ connection = LmiConnection(hostname, username, password, interactive)
+ use_exceptions = LmiBaseClient._get_use_exceptions()
+ try:
+ LmiBaseClient._set_use_exceptions(True)
+ connection.root.cimv2.NonExistingClass
+ except pywbem.cim_operations.CIMError, e:
+ if e.args[0] == pywbem.cim_constants.CIM_ERR_NOT_FOUND:
+ return connection
+ if use_exceptions:
+ raise
+ return None
+ except pywbem.cim_http.AuthError, e:
+ return None
+ finally:
+ LmiBaseClient._set_use_exceptions(use_exceptions)
+ return connection
def _use_display_sugar(use = True):
sys.displayhook = _lmi_displayhook if use else sys.__displayhook__