Accepting request 848094 from home:favogt:boo1178296

- Amend patches/useradd-userkeleton.patch to also write into
  existing directories and prefer files from /etc

OBS-URL: https://build.opensuse.org/request/show/848094
OBS-URL: https://build.opensuse.org/package/show/Base:System/shadow?expand=0&rev=98
This commit is contained in:
Dr. Werner Fink 2020-11-12 10:32:46 +00:00 committed by Git OBS Bridge
parent cf082dac01
commit ff3f23e669
2 changed files with 63 additions and 9 deletions

View File

@ -1,3 +1,9 @@
-------------------------------------------------------------------
Wed Nov 11 14:38:13 UTC 2020 - Fabian Vogt <fvogt@suse.com>
- Amend patches/useradd-userkeleton.patch to also write into
existing directories and prefer files from /etc
------------------------------------------------------------------- -------------------------------------------------------------------
Wed Nov 11 11:28:09 UTC 2020 - Dr. Werner Fink <werner@suse.de> Wed Nov 11 11:28:09 UTC 2020 - Dr. Werner Fink <werner@suse.de>

View File

@ -5,16 +5,20 @@ Copy also skeleton files from /usr/etc/skel (boo#1173321)
src/useradd.c | 37 +++++++++++++++++++++++++++++++++++++ src/useradd.c | 37 +++++++++++++++++++++++++++++++++++++
2 files changed, 38 insertions(+) 2 files changed, 38 insertions(+)
--- etc/useradd Index: etc/useradd
+++ etc/useradd 2020-11-11 11:33:32.809513584 +0000 ===================================================================
--- etc/useradd.orig
+++ etc/useradd
@@ -5,4 +5,5 @@ INACTIVE=-1 @@ -5,4 +5,5 @@ INACTIVE=-1
EXPIRE= EXPIRE=
SHELL=/bin/bash SHELL=/bin/bash
SKEL=/etc/skel SKEL=/etc/skel
+USRSKEL=/usr/etc/skel +USRSKEL=/usr/etc/skel
CREATE_MAIL_SPOOL=yes CREATE_MAIL_SPOOL=yes
--- src/useradd.c Index: src/useradd.c
+++ src/useradd.c 2020-11-11 11:15:42.922067931 +0000 ===================================================================
--- src/useradd.c.orig
+++ src/useradd.c
@@ -78,6 +78,9 @@ @@ -78,6 +78,9 @@
#ifndef SKEL_DIR #ifndef SKEL_DIR
#define SKEL_DIR "/etc/skel" #define SKEL_DIR "/etc/skel"
@ -106,12 +110,56 @@ Copy also skeleton files from /usr/etc/skel (boo#1173321)
if (!out_create_mail_spool) if (!out_create_mail_spool)
fprintf (ofp, DCREATE_MAIL_SPOOL "%s\n", def_create_mail_spool); fprintf (ofp, DCREATE_MAIL_SPOOL "%s\n", def_create_mail_spool);
@@ -2505,6 +2540,8 @@ int main (int argc, char **argv) @@ -2507,6 +2542,8 @@ int main (int argc, char **argv)
if (mflg) {
create_home ();
if (home_added) { if (home_added) {
+ copy_tree (def_usrtemplate, prefix_user_home, false, false,
+ (uid_t)-1, user_id, (gid_t)-1, user_gid);
copy_tree (def_template, prefix_user_home, false, false, copy_tree (def_template, prefix_user_home, false, false,
(uid_t)-1, user_id, (gid_t)-1, user_gid); (uid_t)-1, user_id, (gid_t)-1, user_gid);
+ copy_tree (def_usrtemplate, prefix_user_home, false, false,
+ (uid_t)-1, user_id, (gid_t)-1, user_gid);
} else { } else {
fprintf (stderr,
_("%s: warning: the home directory %s already exists.\n"
Index: libmisc/copydir.c
===================================================================
--- libmisc/copydir.c.orig
+++ libmisc/copydir.c
@@ -416,6 +416,14 @@ static int copy_entry (const char *src,
old_uid, new_uid, old_gid, new_gid);
}
+ /*
+ * If the destination already exists do nothing.
+ * This is after the copy_dir above to still iterate into subdirectories.
+ */
+ if (LSTAT (dst, &sb) != -1) {
+ return 0;
+ }
+
#ifdef S_IFLNK
/*
* Copy any symbolic links
@@ -477,6 +485,7 @@ static int copy_dir (const char *src, co
gid_t old_gid, gid_t new_gid)
{
int err = 0;
+ struct stat dst_sb;
/*
* Create a new target directory, make it owned by
@@ -488,6 +497,16 @@ static int copy_dir (const char *src, co
return -1;
}
#endif /* WITH_SELINUX */
+
+ /*
+ * If the destination is already a directory, don't change it
+ * but copy into it (recursively).
+ */
+ if (LSTAT (dst, &dst_sb) == 0 && S_ISDIR(dst_sb.st_mode)) {
+ return (copy_tree (src, dst, false, reset_selinux,
+ old_uid, new_uid, old_gid, new_gid) != 0);
+ }
+
if ( (mkdir (dst, statp->st_mode) != 0)
|| (chown_if_needed (dst, statp,
old_uid, new_uid, old_gid, new_gid) != 0)