X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=plugins%2Fspecialaccounts.py;h=23bd4ae27df1f3ee31bb59408d0374e040b5793a;hb=3b869bb6f51790344bb1927d827ecd2b9a3dace1;hp=ad4c2cf804ee70ea342951a621055d060aee57ce;hpb=134ea0feb7ea9145b6136225b1105e0622ae41ed;p=nodemanager.git diff --git a/plugins/specialaccounts.py b/plugins/specialaccounts.py index ad4c2cf..23bd4ae 100644 --- a/plugins/specialaccounts.py +++ b/plugins/specialaccounts.py @@ -34,20 +34,25 @@ def GetSlivers(plc, data, conf): pw_dir = pw_info[5] # populate account's .ssh/authorized_keys file - dot_ssh = pw_dir + '/.ssh' + dot_ssh = os.path.join(pw_dir,'.ssh') if not os.access(dot_ssh, os.F_OK): os.mkdir(dot_ssh) - auth_keys = dot_ssh + '/authorized_keys' + auth_keys = os.path.join(dot_ssh,'authorized_keys') logger.log("new keys = %s" % auth_keys) - auth_file = file(auth_keys,"w") + + fd, fname = tempfile.mkstemp('','authorized_keys',dot_ssh) for key in new_keys: - auth_file.write(key) - auth_file.write("\n") - auth_file.close() + os.write(fd,key) + os.write(fd,'\n') + + os.close(fd) + if os.path.exists(auth_keys): + os.unlink(auth_keys) + os.rename(fname,auth_keys) # set permissions properly os.chmod(dot_ssh, 0700) - os.chmod(auth_keys, 0600) os.chown(dot_ssh, uid,gid) + os.chmod(auth_keys, 0600) os.chown(auth_keys, uid,gid) logger.log('specialacounts: installed ssh keys for %s' % name)