2020-11-11 12:39:56 +01:00
|
|
|
Copy also skeleton files from /usr/etc/skel (boo#1173321)
|
|
|
|
|
|
|
|
---
|
|
|
|
etc/useradd | 1 +
|
|
|
|
src/useradd.c | 37 +++++++++++++++++++++++++++++++++++++
|
|
|
|
2 files changed, 38 insertions(+)
|
|
|
|
|
2020-11-12 11:32:46 +01:00
|
|
|
Index: src/useradd.c
|
|
|
|
===================================================================
|
|
|
|
--- src/useradd.c.orig
|
|
|
|
+++ src/useradd.c
|
2022-01-03 13:19:45 +01:00
|
|
|
@@ -61,6 +61,9 @@
|
2020-11-11 12:39:56 +01:00
|
|
|
#ifndef SKEL_DIR
|
|
|
|
#define SKEL_DIR "/etc/skel"
|
|
|
|
#endif
|
|
|
|
+#ifndef USRSKELDIR
|
|
|
|
+#define USRSKELDIR "/usr/etc/skel"
|
|
|
|
+#endif
|
|
|
|
#ifndef USER_DEFAULTS_FILE
|
|
|
|
#define USER_DEFAULTS_FILE "/etc/default/useradd"
|
|
|
|
#define NEW_USER_FILE "/etc/default/nuaddXXXXXX"
|
2022-01-03 13:19:45 +01:00
|
|
|
@@ -84,6 +87,7 @@ static const char *def_gname = "other";
|
2020-11-11 12:39:56 +01:00
|
|
|
static const char *def_home = "/home";
|
2021-08-18 16:25:29 +02:00
|
|
|
static const char *def_shell = "/bin/bash";
|
2020-11-11 12:39:56 +01:00
|
|
|
static const char *def_template = SKEL_DIR;
|
|
|
|
+static const char *def_usrtemplate = USRSKELDIR;
|
2021-08-18 16:25:29 +02:00
|
|
|
static const char *def_create_mail_spool = "yes";
|
2022-01-03 13:19:45 +01:00
|
|
|
static const char *def_log_init = "yes";
|
2020-11-11 12:39:56 +01:00
|
|
|
|
2022-08-22 16:01:13 +02:00
|
|
|
@@ -188,6 +192,7 @@ static bool home_added = false;
|
2020-11-11 12:39:56 +01:00
|
|
|
#define DINACT "INACTIVE="
|
|
|
|
#define DEXPIRE "EXPIRE="
|
|
|
|
#define DSKEL "SKEL="
|
|
|
|
+#define DUSRSKEL "USRSKEL="
|
|
|
|
#define DCREATE_MAIL_SPOOL "CREATE_MAIL_SPOOL="
|
2022-01-03 13:19:45 +01:00
|
|
|
#define DLOG_INIT "LOG_INIT="
|
2020-11-11 12:39:56 +01:00
|
|
|
|
2022-08-22 16:01:13 +02:00
|
|
|
@@ -461,6 +466,29 @@ static void get_defaults (void)
|
2020-11-11 12:39:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
+ * Default Usr Skeleton information
|
|
|
|
+ */
|
|
|
|
+ else if (MATCH (buf, DUSRSKEL)) {
|
|
|
|
+ if ('\0' == *cp) {
|
|
|
|
+ cp = USRSKELDIR; /* XXX warning: const */
|
|
|
|
+ }
|
2022-08-22 16:01:13 +02:00
|
|
|
+
|
2020-11-11 12:39:56 +01:00
|
|
|
+ if(prefix[0]) {
|
|
|
|
+ size_t len;
|
|
|
|
+ int wlen;
|
|
|
|
+ char* _def_usrtemplate; /* avoid const warning */
|
|
|
|
+
|
|
|
|
+ len = strlen(prefix) + strlen(cp) + 2;
|
|
|
|
+ _def_usrtemplate = xmalloc(len);
|
|
|
|
+ wlen = snprintf(_def_usrtemplate, len, "%s/%s", prefix, cp);
|
|
|
|
+ assert (wlen == (int) len -1);
|
|
|
|
+ def_usrtemplate = _def_usrtemplate;
|
|
|
|
+ }
|
|
|
|
+ else {
|
|
|
|
+ def_usrtemplate = xstrdup (cp);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ /*
|
|
|
|
* Create by default user mail spool or not ?
|
|
|
|
*/
|
|
|
|
else if (MATCH (buf, DCREATE_MAIL_SPOOL)) {
|
2022-08-22 16:01:13 +02:00
|
|
|
@@ -502,6 +530,7 @@ static void show_defaults (void)
|
2020-11-11 12:39:56 +01:00
|
|
|
printf ("EXPIRE=%s\n", def_expire);
|
|
|
|
printf ("SHELL=%s\n", def_shell);
|
|
|
|
printf ("SKEL=%s\n", def_template);
|
|
|
|
+ printf ("USRSKEL=%s\n", def_usrtemplate);
|
|
|
|
printf ("CREATE_MAIL_SPOOL=%s\n", def_create_mail_spool);
|
2022-01-03 13:19:45 +01:00
|
|
|
printf ("LOG_INIT=%s\n", def_log_init);
|
2020-11-11 12:39:56 +01:00
|
|
|
}
|
2022-08-22 16:01:13 +02:00
|
|
|
@@ -530,6 +559,7 @@ static int set_defaults (void)
|
2020-11-11 12:39:56 +01:00
|
|
|
bool out_expire = false;
|
|
|
|
bool out_shell = false;
|
|
|
|
bool out_skel = false;
|
|
|
|
+ bool out_usrskel = false;
|
|
|
|
bool out_create_mail_spool = false;
|
2022-01-03 13:19:45 +01:00
|
|
|
bool out_log_init = false;
|
2020-11-11 12:39:56 +01:00
|
|
|
size_t len;
|
2022-08-22 16:01:13 +02:00
|
|
|
@@ -643,6 +673,9 @@ static int set_defaults (void)
|
2020-11-11 12:39:56 +01:00
|
|
|
} else if (!out_skel && MATCH (buf, DSKEL)) {
|
|
|
|
fprintf (ofp, DSKEL "%s\n", def_template);
|
|
|
|
out_skel = true;
|
|
|
|
+ } else if (!out_usrskel && MATCH (buf, DUSRSKEL)) {
|
|
|
|
+ fprintf (ofp, DUSRSKEL "%s\n", def_usrtemplate);
|
|
|
|
+ out_usrskel = true;
|
|
|
|
} else if (!out_create_mail_spool
|
|
|
|
&& MATCH (buf, DCREATE_MAIL_SPOOL)) {
|
|
|
|
fprintf (ofp,
|
2022-08-22 16:01:13 +02:00
|
|
|
@@ -678,6 +711,8 @@ static int set_defaults (void)
|
2020-11-11 12:39:56 +01:00
|
|
|
fprintf (ofp, DSHELL "%s\n", def_shell);
|
|
|
|
if (!out_skel)
|
|
|
|
fprintf (ofp, DSKEL "%s\n", def_template);
|
|
|
|
+ if (!out_usrskel)
|
|
|
|
+ fprintf (ofp, DUSRSKEL "%s\n", def_usrtemplate);
|
|
|
|
|
|
|
|
if (!out_create_mail_spool)
|
|
|
|
fprintf (ofp, DCREATE_MAIL_SPOOL "%s\n", def_create_mail_spool);
|
2022-11-09 14:35:08 +01:00
|
|
|
@@ -2758,6 +2793,8 @@ int main (int argc, char **argv)
|
2020-11-11 12:39:56 +01:00
|
|
|
if (home_added) {
|
2022-01-03 13:19:45 +01:00
|
|
|
copy_tree (def_template, prefix_user_home, false, true,
|
2020-11-11 12:39:56 +01:00
|
|
|
(uid_t)-1, user_id, (gid_t)-1, user_gid);
|
2020-11-12 11:32:46 +01:00
|
|
|
+ copy_tree (def_usrtemplate, prefix_user_home, false, false,
|
|
|
|
+ (uid_t)-1, user_id, (gid_t)-1, user_gid);
|
2020-11-11 12:39:56 +01:00
|
|
|
} else {
|
2020-11-12 11:32:46 +01:00
|
|
|
fprintf (stderr,
|
|
|
|
_("%s: warning: the home directory %s already exists.\n"
|
|
|
|
Index: libmisc/copydir.c
|
|
|
|
===================================================================
|
|
|
|
--- libmisc/copydir.c.orig
|
|
|
|
+++ libmisc/copydir.c
|
2022-11-09 14:35:08 +01:00
|
|
|
@@ -449,6 +449,14 @@ static int copy_entry (const struct path
|
2020-11-12 11:32:46 +01:00
|
|
|
}
|
|
|
|
|
2022-08-22 16:01:13 +02:00
|
|
|
/*
|
2020-11-12 11:32:46 +01:00
|
|
|
+ * If the destination already exists do nothing.
|
|
|
|
+ * This is after the copy_dir above to still iterate into subdirectories.
|
|
|
|
+ */
|
2022-08-24 16:58:41 +02:00
|
|
|
+ if (fstatat(dst->dirfd, dst->name, &sb, AT_SYMLINK_NOFOLLOW) != -1) {
|
2020-11-12 11:32:46 +01:00
|
|
|
+ return 0;
|
|
|
|
+ }
|
|
|
|
+
|
2022-08-22 16:01:13 +02:00
|
|
|
+ /*
|
2020-11-12 11:32:46 +01:00
|
|
|
* Copy any symbolic links
|
2022-08-22 16:01:13 +02:00
|
|
|
*/
|
|
|
|
|
2022-11-09 14:35:08 +01:00
|
|
|
@@ -507,6 +515,7 @@ static int copy_dir (const struct path_i
|
2020-11-12 11:32:46 +01:00
|
|
|
gid_t old_gid, gid_t new_gid)
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
+ struct stat dst_sb;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a new target directory, make it owned by
|
2022-11-09 14:35:08 +01:00
|
|
|
@@ -518,6 +527,15 @@ static int copy_dir (const struct path_i
|
2020-11-12 11:32:46 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
#endif /* WITH_SELINUX */
|
2022-08-22 16:01:13 +02:00
|
|
|
+ /*
|
|
|
|
+ * If the destination is already a directory, don't change it
|
|
|
|
+ * but copy into it (recursively).
|
|
|
|
+ */
|
|
|
|
+ if (fstatat(dst->dirfd, dst->name, &dst_sb, AT_SYMLINK_NOFOLLOW) == 0 && S_ISDIR(dst_sb.st_mode)) {
|
|
|
|
+ return (copy_tree (src, dst, false, reset_selinux,
|
|
|
|
+ old_uid, new_uid, old_gid, new_gid) != 0);
|
|
|
|
+ }
|
2020-11-12 11:32:46 +01:00
|
|
|
+
|
2022-11-09 14:35:08 +01:00
|
|
|
if ( (mkdirat (dst->dirfd, dst->name, 0700) != 0)
|
2022-08-22 16:01:13 +02:00
|
|
|
|| (chownat_if_needed (dst, statp,
|
2020-11-12 11:32:46 +01:00
|
|
|
old_uid, new_uid, old_gid, new_gid) != 0)
|