Skip to content

Commit

Permalink
scubainit: Don't create home directory if it already exists
Browse files Browse the repository at this point in the history
The mkdir_p is harmless, but the chmod/chown might actually affect the
invoking user's home directory if .scuba.yml exists there.

Note that the chown is probably harmless because it would be chowning to
the same user. But it's better to not mess with anything.
  • Loading branch information
JonathonReinhart committed Mar 5, 2020
1 parent 3cdca42 commit 6dee24d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions scubainit/scubainit.c
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,19 @@ mkdir_p(const char *path)
static int
make_homedir(const char *path, unsigned int uid, unsigned int gid)
{
struct stat st;

/* See if the home directory already exists */
if (stat(path, &st) == 0) {
verbose("Homedir %s already exists\n", path);
return 0;
}
else if (errno != ENOENT) {
errmsg("Failed to stat %s: %m\n", path);
return -1;
}

/* Create the home directory */
if (mkdir_p(path) != 0) {
errmsg("Failed to create %s: %m\n", path);
return -1;
Expand All @@ -377,6 +390,8 @@ make_homedir(const char *path, unsigned int uid, unsigned int gid)
errmsg("Failed to chown %s: %m\n", path);
return -1;
}

verbose("Created homedir %s\n", path);
return 0;
}

Expand Down

0 comments on commit 6dee24d

Please sign in to comment.