ENH Educated guess of NSS loading based on bitness

If Python's bitness doesn't match that of the NSS.dll found,
loading will fail. This restricts directories on a 64bit Windows system.
A better solution would check the bitness of the lib as well - refs #41
This commit is contained in:
Renato Alves
2019-01-18 17:32:36 +01:00
parent 6a0c69b00b
commit 2bd3ffbd96
2 changed files with 48 additions and 21 deletions

View File

@@ -7,6 +7,7 @@
- Using `--pass-prefix=''` prevents creation of a prefix: `web/address/...` becomes `address/...` - Using `--pass-prefix=''` prevents creation of a prefix: `web/address/...` becomes `address/...`
- Fix an encoding bug due to non-ASCII characters leading to a user's profile path - Fix an encoding bug due to non-ASCII characters leading to a user's profile path
- Drop support for Python 2 on Windows. Python 3 works fine. - Drop support for Python 2 on Windows. Python 3 works fine.
- Explicitly target 32/64bit Mozilla folders depending on Python bitness
##### 0.7.0 ##### 0.7.0
- Fix PK11 slot memory leak - Fix PK11 slot memory leak

View File

@@ -54,6 +54,7 @@ except ImportError:
PY3 = sys.version_info.major > 2 PY3 = sys.version_info.major > 2
LOG = None LOG = None
VERBOSE = False VERBOSE = False
SYS64 = sys.maxsize > 2**32
if not PY3 and os.name == "nt": if not PY3 and os.name == "nt":
sys.stderr.write("WARNING: You are using Python 2 on Windows. If your " sys.stderr.write("WARNING: You are using Python 2 on Windows. If your "
@@ -342,13 +343,24 @@ class NSSDecoder(object):
""" """
if os.name == "nt": if os.name == "nt":
nssname = "nss3.dll" nssname = "nss3.dll"
locations = ( if SYS64:
"", # Current directory or system lib finder locations = (
r"C:\Program Files (x86)\Mozilla Firefox", "", # Current directory or system lib finder
r"C:\Program Files\Mozilla Firefox", r"C:\Program Files\Mozilla Firefox",
r"C:\Program Files (x86)\Nightly", r"C:\Program Files\Mozilla Thunderbird",
r"C:\Program Files\Nightly", r"C:\Program Files\Nightly",
) )
else:
locations = (
"", # Current directory or system lib finder
r"C:\Program Files (x86)\Mozilla Firefox",
r"C:\Program Files (x86)\Mozilla Thunderbird",
r"C:\Program Files (x86)\Nightly",
# On windows 32bit these folders can also be 32bit
r"C:\Program Files\Mozilla Firefox",
r"C:\Program Files\Mozilla Thunderbird",
r"C:\Program Files\Nightly",
)
# FIXME this was present in the past adding the location where NSS was found to PATH # FIXME this was present in the past adding the location where NSS was found to PATH
# I'm not sure why this would be necessary. We don't need to run Firefox... # I'm not sure why this would be necessary. We don't need to run Firefox...
@@ -371,20 +383,34 @@ class NSSDecoder(object):
else: else:
nssname = "libnss3.so" nssname = "libnss3.so"
locations = ( if SYS64:
"", # Current directory or system lib finder locations = (
"/usr/lib", "", # Current directory or system lib finder
"/usr/lib32", "/usr/lib64",
"/usr/lib64", "/usr/lib64/nss",
"/usr/lib/nss", "/usr/lib",
"/usr/lib32/nss", "/usr/lib/nss",
"/usr/lib64/nss", "/usr/local/lib",
"/usr/local/lib", "/usr/local/lib/nss",
"/usr/local/lib/nss", "/opt/local/lib",
"/opt/local/lib", "/opt/local/lib/nss",
"/opt/local/lib/nss", os.path.expanduser("~/.nix-profile/lib"),
os.path.expanduser("~/.nix-profile/lib"), )
) else:
locations = (
"", # Current directory or system lib finder
"/usr/lib",
"/usr/lib/nss",
"/usr/lib32",
"/usr/lib32/nss",
"/usr/lib64",
"/usr/lib64/nss",
"/usr/local/lib",
"/usr/local/lib/nss",
"/opt/local/lib",
"/opt/local/lib/nss",
os.path.expanduser("~/.nix-profile/lib"),
)
# If this succeeds libnss was loaded # If this succeeds libnss was loaded
self.NSS = self.find_nss(locations, nssname) self.NSS = self.find_nss(locations, nssname)