From 0849c0bd2b8ada4aaa5ce2cc6d83ef8154ffce86 Mon Sep 17 00:00:00 2001 From: Mike Hiretsky Date: Mon, 18 Oct 2010 09:36:42 +0400 Subject: [PATCH] Fix work lib without py-smbpasswd. Without py-smbpasswd calculate-lib does not support crypt algoritm lm and nt. --- pym/encrypt.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/pym/encrypt.py b/pym/encrypt.py index 5b73f73..e54a874 100644 --- a/pym/encrypt.py +++ b/pym/encrypt.py @@ -23,7 +23,10 @@ import time from random import choice from base64 import encodestring as _b64enc b64encode = lambda x: _b64enc(x).rstrip() -import smbpasswd +try: + from smbpasswd import lmhash,nthash +except ImportError: + lmhash,nthash = None,None from cl_print import color_print # для создания сертификата import pwd @@ -101,14 +104,17 @@ class encrypt(color_print): h.update(salt) hashPwd = "{SSHA}" + b64encode(h.digest() + salt) - elif SecHashAlg == "lm": - hashPwd = smbpasswd.lmhash(password) - - elif SecHashAlg == "nt": - hashPwd = smbpasswd.nthash(password) - + elif SecHashAlg == "lm" and lmhash: + hashPwd = lmhash(password) + elif SecHashAlg == "nt" and nthash: + hashPwd = nthash(password) else: - self.printERROR(_("ERROR") + " getHashPasswd: " +\ + if SecHashAlg in ("lm","nt"): + self.printERROR(_("ERROR") + " getHashPasswd: " +\ + (_("Can not support '%s' crypto algorithm")\ + %SecHashAlg) + " " + _("without py-smbpasswd")) + else: + self.printERROR(_("ERROR") + " getHashPasswd: " +\ _("Can not support '%s' crypto algorithm")\ %SecHashAlg) return False