Skip to content

Commit 173aedd

Browse files
committed
Update the way machine codes are generated on Linux that does not require sudo
1 parent 65b25da commit 173aedd

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

licensing/internal.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,34 @@ def start_process(command):
5858
(output, err) = process.communicate()
5959
exit_code = process.wait()
6060
return output.decode("utf-8")
61+
62+
@staticmethod
63+
def get_dbus_machine_id():
64+
try:
65+
with open("/etc/machine-id") as f:
66+
return f.read().strip()
67+
except:
68+
pass
69+
try:
70+
with open("/var/lib/dbus/machine-id") as f:
71+
return f.read().strip()
72+
except:
73+
pass
74+
return ""
75+
76+
@staticmethod
77+
def get_inodes():
78+
import os
79+
files = ["/bin", "/etc", "/lib", "/root", "/sbin", "/usr", "/var"]
80+
inodes = []
81+
for file in files:
82+
try:
83+
inodes.append(os.stat(file).st_ino)
84+
except:
85+
pass
86+
return "".join([str(x) for x in inodes])
87+
88+
@staticmethod
89+
def compute_machine_code():
90+
return get_dbus_machine_id() + get_inodes()
6191

licensing/methods.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ def GetMachineCode():
134134
res = HelperMethods.start_process(["system_profiler","SPHardwareDataType"]).decode('utf-8')
135135
HelperMethods.get_SHA256(res[res.index("UUID"):].strip())
136136
elif "Linux" in platform.platform():
137-
return HelperMethods.get_SHA256(HelperMethods.start_process(["dmidecode", "-s", "system-uuid"]))
137+
return HelperMethods.get_SHA256(HelperMethods.compute_machine_code())
138138
else:
139-
return HelperMethods.get_SHA256(HelperMethods.start_process(["dmidecode", "-s", "system-uuid"]).decode('utf-8'))
139+
return HelperMethods.get_SHA256(HelperMethods.compute_machine_code())
140140

141141
def IsOnRightMachine(license_key, is_floating_license = False, allow_overdraft=False):
142142

0 commit comments

Comments
 (0)