diff --git a/docker/entrypoint.py b/docker/entrypoint.py index cd4999a..1483579 100755 --- a/docker/entrypoint.py +++ b/docker/entrypoint.py @@ -10,7 +10,7 @@ import subprocess import sys PYTHON3 = '/usr/bin/python3' -dbPath = os.path.join(os.sep, 'home', 'py-kms', 'db', 'pykms_database.db') +dbPath = os.path.join(os.sep, 'home', 'py-kms', 'db') # Do not include the database file name, as we must correct the folder permissions (the db file is recursively reachable) log_level_bootstrap = log_level = os.getenv('LOGLEVEL', 'INFO') if log_level_bootstrap == "MININFO": log_level_bootstrap = "INFO" @@ -33,10 +33,24 @@ def change_uid_grp(): new_uid = int(os.getenv('UID', str(uid))) os.chown("/home/py-kms", new_uid, new_gid) os.chown("/usr/bin/start.py", new_uid, new_gid) - if os.path.isfile(dbPath): + if os.path.isdir(dbPath): + # Corret permissions recursively, as to access the database file, also its parent folder must be accessible + loggersrv.debug(f'Correcting owner permissions on {dbPath}.') os.chown(dbPath, new_uid, new_gid) - loggersrv.debug("%s" %str(subprocess.check_output("ls -al " + dbPath, shell=True))) - + for root, dirs, files in os.walk(dbPath): + for dName in dirs: + dPath = os.path.join(root, dName) + loggersrv.debug(f'Correcting owner permissions on {dPath}.') + os.chown(dPath, new_uid, new_gid) + for fName in files: + fPath = os.path.join(root, fName) + loggersrv.debug(f'Correcting owner permissions on {fPath}.') + os.chown(fPath, new_uid, new_gid) + loggersrv.debug(subprocess.check_output(['ls', '-la', dbPath]).decode()) + if 'LOGFILE' in os.environ and os.path.exists(os.environ['LOGFILE']): + # Oh, the user also wants a custom log file -> make sure start.py can access it by setting the correct permissions (777) + os.chmod(os.environ['LOGFILE'], 777) + loggersrv.error(str(subprocess.check_output(['ls', '-la', os.environ['LOGFILE']]))) loggersrv.info("Setting gid to '%s'." % str(new_gid)) os.setgid(new_gid) diff --git a/docs/Getting Started.md b/docs/Getting Started.md index 7aa157c..2ad3ec8 100644 --- a/docs/Getting Started.md +++ b/docs/Getting Started.md @@ -52,7 +52,6 @@ services: - SQLITE=true - HWID=RANDOM - LOGLEVEL=INFO - - LOGFILE=/dev/stdout restart: always volumes: - ./db:/home/py-kms/db diff --git a/py-kms/pykms_Client.py b/py-kms/pykms_Client.py index bd6d3ec..5a47fb7 100644 --- a/py-kms/pykms_Client.py +++ b/py-kms/pykms_Client.py @@ -156,18 +156,25 @@ def client_check(): def client_update(): kmsdb = kmsDB2Dict() + loggerclt.debug(f'Searching in kms database for machine "{clt_config["mode"]}"...') + appitems = kmsdb[2] for appitem in appitems: kmsitems = appitem['KmsItems'] for kmsitem in kmsitems: - name = re.sub('\(.*\)', '', kmsitem['DisplayName']).replace('2015', '').replace(' ', '') + name = re.sub('\(.*\)', '', kmsitem['DisplayName']) # Remove bracets + name = name.replace('2015', '') # Remove specific years + name = name.replace(' ', '') # Ignore whitespaces + name = name.replace('/11', '', 1) # Cut out Windows 11, as it is basically Windows 10 if name == clt_config['mode']: skuitems = kmsitem['SkuItems'] # Select 'Enterprise' for Windows or 'Professional Plus' for Office. for skuitem in skuitems: - if skuitem['DisplayName'].replace(' ','') == name + 'Enterprise' or \ - skuitem['DisplayName'].replace(' ','') == name[:6] + 'ProfessionalPlus' + name[6:]: - + sName = skuitem['DisplayName'] + sName = sName.replace(' ', '') # Ignore whitespaces + sName = sName.replace('/11', '', 1) # Cut out Windows 11, as it is basically Windows 10 + if sName == name + 'Enterprise' or \ + sName == name[:6] + 'ProfessionalPlus' + name[6:]: clt_config['KMSClientSkuID'] = skuitem['Id'] clt_config['RequiredClientCount'] = int(kmsitem['NCountPolicy']) clt_config['KMSProtocolMajorVersion'] = int(float(kmsitem['DefaultKmsProtocol'])) @@ -175,7 +182,8 @@ def client_update(): clt_config['KMSClientLicenseStatus'] = 2 clt_config['KMSClientAppID'] = appitem['Id'] clt_config['KMSClientKMSCountedID'] = kmsitem['Id'] - break + return + raise RuntimeError(f'Client failed to find machine configuration in kms database - make sure it contains an entry for "{clt_config["mode"]}"') def client_connect(): loggerclt.info("Connecting to %s on port %d" % (clt_config['ip'], clt_config['port'])) diff --git a/py-kms/pykms_Sql.py b/py-kms/pykms_Sql.py index 1e8c47d..6afa889 100644 --- a/py-kms/pykms_Sql.py +++ b/py-kms/pykms_Sql.py @@ -18,6 +18,7 @@ loggersrv = logging.getLogger('logsrv') def sql_initialize(dbName): if not os.path.isfile(dbName): # Initialize the database. + loggersrv.debug(f'Initializing database file "{dbName}"...') con = None try: con = sqlite3.connect(dbName)