System: Introduce function to write just write the auth file

pull/4/head
Darksider3 5 years ago
parent 96097e26b1
commit 7786df3761

@ -80,11 +80,7 @@ class System:
raise lib.UserExceptions.SSHDirUncreatable(f"Could not create {ssh_dir}: Exception: {e}")
try:
with open(ssh_dir + "authorized_keys", "w") as f:
print(pubkey, file=f)
f.close()
os.chmod(ssh_dir + "authorized_keys", 0o700) # directory is already 777?
os.chmod(ssh_dir, 0o700) # directory is already 777?
self.write_ssh(pubkey, ssh_dir)
except OSError as e:
raise lib.UserExceptions.ModifyFilesystem(
f"Could not write and/or chmod 0700 {ssh_dir} or {ssh_dir}/authorized_keys, Exception: {e}")
@ -99,6 +95,12 @@ class System:
raise lib.UserExceptions.General(f"PWD can't find {username}: {e}")
return True
def write_ssh(self, key: str, ssh_dir: str):
with open(ssh_dir + "authorized_keys", "w") as f:
print(key, file=f)
f.close()
os.chmod(ssh_dir + "authorized_keys", 0o700) # we dont care about the directory here
def lock_user_pw(self, username: str, cc: tuple = tuple(["usermod", "--lock"])) -> bool:
"""Lock a users password so it stays empty

Loading…
Cancel
Save