47 lines
1.5 KiB
Python
Executable file
47 lines
1.5 KiB
Python
Executable file
#!/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"])
|
|
except:
|
|
subprocess.run(["/usr/bin/mount", "-t", "virtiofs", "Home_Linux", "/media/host"])
|
|
|
|
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"])
|