#!/usr/bin/python3 from impacket.krb5.ccache import CCache from base64 import b64decode import json, os, os.path, sys, stat, subprocess if not os.path.isfile("/media/host/.vminfo.json"): try: subprocess.run(["/usr/bin/mount", "-t", "virtiofs", "VM-Data", "/media/host"], check=True) except subprocess.CalledProcessError: subprocess.run(["/usr/bin/mount", "-t", "virtiofs", "Home_Linux", "/media/host"], check=True) if not os.path.isfile("/media/host/.vminfo.json"): print("/media/host/.vminfo.json not found",file=sys.stderr) exit(1) with open("/media/host/.vminfo.json") as f: data = json.load(f) user = data["User"] krbcred = b64decode(data["krb5"]["cred"]) if os.path.isfile("/tmp/krb5cc_1000"): os.remove("/tmp/krb5cc_1000") if os.path.isfile("/tmp/krb5cc_0"): os.remove("/tmp/krb5cc_0") ccache = CCache() ccache.fromKRBCRED(krbcred) ccache.saveFile("/tmp/krb5cc_1000") ccache.saveFile("/tmp/krb5cc_0") if os.path.isfile("/tmp/krb5cc_1000"): os.chown("/tmp/krb5cc_1000",1000,1000) os.chmod("/tmp/krb5cc_1000",stat.S_IRUSR | stat.S_IWUSR) if os.path.isfile("/tmp/krb5cc_0"): os.chown("/tmp/krb5cc_0",0,0) os.chmod("/tmp/krb5cc_0",stat.S_IRUSR | stat.S_IWUSR) mounts = data["Mounts"] for mount in mounts: directory = f"/lmn/media/{mount['Name']}" if not os.path.exists(directory): os.makedirs(directory) if not os.path.ismount(directory): subprocess.run(["/usr/bin/mount", "-t", "cifs", mount['RemotePath'], directory ,"-o", f"sec=krb5i,username={user},cruid=1000,uid=1000,gid=1000"], check=True) for printer in data["Printers"]: try: subprocess.run(["/usr/sbin/lpadmin", "-p", printer['Name'], "-E", "-v", printer['IppURL'], "-m", "driverless:"+printer['IppURL']], check=True) except subprocess.CalledProcessError: print(f"Error adding printer {{printer['Name']}}")