forked from pool/shadow
118 lines
3.5 KiB
Diff
118 lines
3.5 KiB
Diff
|
Copy also skeleton files from /usr/etc/skel (boo#1173321)
|
||
|
|
||
|
---
|
||
|
etc/useradd | 1 +
|
||
|
src/useradd.c | 37 +++++++++++++++++++++++++++++++++++++
|
||
|
2 files changed, 38 insertions(+)
|
||
|
|
||
|
--- etc/useradd
|
||
|
+++ etc/useradd 2020-11-11 11:33:32.809513584 +0000
|
||
|
@@ -5,4 +5,5 @@ INACTIVE=-1
|
||
|
EXPIRE=
|
||
|
SHELL=/bin/bash
|
||
|
SKEL=/etc/skel
|
||
|
+USRSKEL=/usr/etc/skel
|
||
|
CREATE_MAIL_SPOOL=yes
|
||
|
--- src/useradd.c
|
||
|
+++ src/useradd.c 2020-11-11 11:15:42.922067931 +0000
|
||
|
@@ -78,6 +78,9 @@
|
||
|
#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"
|
||
|
@@ -101,6 +104,7 @@ static const char *def_gname = "other";
|
||
|
static const char *def_home = "/home";
|
||
|
static const char *def_shell = "";
|
||
|
static const char *def_template = SKEL_DIR;
|
||
|
+static const char *def_usrtemplate = USRSKELDIR;
|
||
|
static const char *def_create_mail_spool = "no";
|
||
|
|
||
|
static long def_inactive = -1;
|
||
|
@@ -202,6 +206,7 @@ static bool home_added = false;
|
||
|
#define DINACT "INACTIVE="
|
||
|
#define DEXPIRE "EXPIRE="
|
||
|
#define DSKEL "SKEL="
|
||
|
+#define DUSRSKEL "USRSKEL="
|
||
|
#define DCREATE_MAIL_SPOOL "CREATE_MAIL_SPOOL="
|
||
|
|
||
|
/* local function prototypes */
|
||
|
@@ -469,6 +474,29 @@ static void get_defaults (void)
|
||
|
}
|
||
|
|
||
|
/*
|
||
|
+ * Default Usr Skeleton information
|
||
|
+ */
|
||
|
+ else if (MATCH (buf, DUSRSKEL)) {
|
||
|
+ if ('\0' == *cp) {
|
||
|
+ cp = USRSKELDIR; /* XXX warning: const */
|
||
|
+ }
|
||
|
+
|
||
|
+ 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)) {
|
||
|
@@ -500,6 +528,7 @@ static void show_defaults (void)
|
||
|
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);
|
||
|
}
|
||
|
|
||
|
@@ -526,6 +555,7 @@ static int set_defaults (void)
|
||
|
bool out_expire = false;
|
||
|
bool out_shell = false;
|
||
|
bool out_skel = false;
|
||
|
+ bool out_usrskel = false;
|
||
|
bool out_create_mail_spool = false;
|
||
|
size_t len;
|
||
|
int ret = -1;
|
||
|
@@ -620,6 +650,9 @@ static int set_defaults (void)
|
||
|
} 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,
|
||
|
@@ -649,6 +682,8 @@ static int set_defaults (void)
|
||
|
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);
|
||
|
@@ -2505,6 +2540,8 @@ int main (int argc, char **argv)
|
||
|
if (mflg) {
|
||
|
create_home ();
|
||
|
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,
|
||
|
(uid_t)-1, user_id, (gid_t)-1, user_gid);
|
||
|
} else {
|