Revision 70d9e3d8 lib/ssh.py

b/lib/ssh.py
55 55
  ]
56 56

  
57 57

  
58
def GetUserFiles(user, mkdir=False):
59
  """Return the paths of a user's ssh files.
60

  
61
  The function will return a triplet (priv_key_path, pub_key_path,
62
  auth_key_path) that are used for ssh authentication. Currently, the
63
  keys used are DSA keys, so this function will return:
64
  (~user/.ssh/id_dsa, ~user/.ssh/id_dsa.pub,
65
  ~user/.ssh/authorized_keys).
66

  
67
  If the optional parameter mkdir is True, the ssh directory will be
68
  created if it doesn't exist.
69

  
70
  Regardless of the mkdir parameters, the script will raise an error
71
  if ~user/.ssh is not a directory.
72

  
73
  """
74
  user_dir = utils.GetHomeDir(user)
75
  if not user_dir:
76
    raise errors.OpExecError("Cannot resolve home of user %s" % user)
77

  
78
  ssh_dir = os.path.join(user_dir, ".ssh")
79
  if not os.path.lexists(ssh_dir):
80
    if mkdir:
81
      try:
82
        os.mkdir(ssh_dir, 0700)
83
      except EnvironmentError, err:
84
        raise errors.OpExecError("Can't create .ssh dir for user %s: %s" %
85
                                 (user, str(err)))
86
  elif not os.path.isdir(ssh_dir):
87
    raise errors.OpExecError("path ~%s/.ssh is not a directory" % user)
88

  
89
  return [os.path.join(ssh_dir, base)
90
          for base in ["id_dsa", "id_dsa.pub", "authorized_keys"]]
91

  
92

  
58 93
def BuildSSHCmd(hostname, user, command, batch=True, ask_key=False):
59 94
  """Build an ssh string to execute a command on a remote node.
60 95

  

Also available in: Unified diff