Changeset View
Changeset View
Standalone View
Standalone View
usr.sbin/pw/pw_user.c
| Show First 20 Lines • Show All 80 Lines • ▼ Show 20 Lines | |||||
| static char *shell_path(char const * path, char *shells[], char *sh); | static char *shell_path(char const * path, char *shells[], char *sh); | ||||
| static void rmat(uid_t uid); | static void rmat(uid_t uid); | ||||
| static void | static void | ||||
| mkdir_home_parents(int dfd, const char *dir) | mkdir_home_parents(int dfd, const char *dir) | ||||
| { | { | ||||
| struct stat st; | struct stat st; | ||||
| char *dirs, *tmp; | char *dirs, *tmp; | ||||
| mode_t pumask; | |||||
| pumask = umask(0); | |||||
| umask(pumask); | |||||
| if (*dir != '/') | if (*dir != '/') | ||||
| errx(EX_DATAERR, "invalid base directory for home '%s'", dir); | errx(EX_DATAERR, "invalid base directory for home '%s'", dir); | ||||
| dir++; | dir++; | ||||
| if (fstatat(dfd, dir, &st, 0) != -1) { | if (fstatat(dfd, dir, &st, 0) != -1) { | ||||
| if (S_ISDIR(st.st_mode)) | if (S_ISDIR(st.st_mode)) | ||||
| return; | return; | ||||
| errx(EX_OSFILE, "root home `/%s' is not a directory", dir); | errx(EX_OSFILE, "root home `/%s' is not a directory", dir); | ||||
| } | } | ||||
| Show All 14 Lines | while ((tmp = strchr(tmp + 1, '/')) != NULL) { | ||||
| *tmp = '\0'; | *tmp = '\0'; | ||||
| if (fstatat(dfd, dirs, &st, 0) == -1) { | if (fstatat(dfd, dirs, &st, 0) == -1) { | ||||
| if (mkdirat(dfd, dirs, _DEF_DIRMODE) == -1) | if (mkdirat(dfd, dirs, _DEF_DIRMODE) == -1) | ||||
| err(EX_OSFILE, | err(EX_OSFILE, | ||||
| "'%s' (home parent) is not a directory", | "'%s' (home parent) is not a directory", | ||||
| dirs); | dirs); | ||||
| if (fchownat(dfd, dirs, 0, 0, 0) != 0) | if (fchownat(dfd, dirs, 0, 0, 0) != 0) | ||||
| warn("chown(%s)", dirs); | warn("chown(%s)", dirs); | ||||
| metalog_emit(dir, | |||||
| (_DEF_DIRMODE | S_IFDIR) & ~pumask, 0, 0, | |||||
| 0); | |||||
| } | } | ||||
| *tmp = '/'; | *tmp = '/'; | ||||
| } | } | ||||
| } | } | ||||
| if (fstatat(dfd, dirs, &st, 0) == -1) { | if (fstatat(dfd, dirs, &st, 0) == -1) { | ||||
| if (mkdirat(dfd, dirs, _DEF_DIRMODE) == -1) | if (mkdirat(dfd, dirs, _DEF_DIRMODE) == -1) | ||||
| err(EX_OSFILE, "'%s' (home parent) is not a directory", dirs); | err(EX_OSFILE, "'%s' (home parent) is not a directory", dirs); | ||||
| if (fchownat(dfd, dirs, 0, 0, 0) != 0) | if (fchownat(dfd, dirs, 0, 0, 0) != 0) | ||||
| warn("chown(%s)", dirs); | warn("chown(%s)", dirs); | ||||
| metalog_emit(dirs, (_DEF_DIRMODE | S_IFDIR) & ~pumask, 0, 0, 0); | |||||
| } | } | ||||
| free(dirs); | free(dirs); | ||||
| } | } | ||||
| static void | static void | ||||
| create_and_populate_homedir(struct userconf *cnf, struct passwd *pwd, | create_and_populate_homedir(struct userconf *cnf, struct passwd *pwd, | ||||
| const char *skeldir, mode_t homemode, bool update) | const char *skeldir, mode_t homemode, bool update) | ||||
| ▲ Show 20 Lines • Show All 1,719 Lines • Show Last 20 Lines | |||||