| 
									
										
										
										
											2020-11-02 15:56:45 +00:00
										 |  |  | ---
 | 
					
						
							|  |  |  |  etc/login.defs |    7 +++++++ | 
					
						
							|  |  |  |  lib/getdef.c   |    1 + | 
					
						
							|  |  |  |  src/useradd.c  |   41 ++++++++++++++++++++++++++++++++++++++++- | 
					
						
							|  |  |  |  3 files changed, 48 insertions(+), 1 deletion(-) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | --- etc/login.defs
 | 
					
						
							|  |  |  | +++ etc/login.defs	2020-10-30 12:54:38.117849829 +0000
 | 
					
						
							|  |  |  | @@ -242,6 +242,13 @@ CHFN_RESTRICT		rwh
 | 
					
						
							| 
									
										
										
										
											2019-05-06 07:58:15 +00:00
										 |  |  |  DEFAULT_HOME	yes | 
					
						
							|  |  |  |   | 
					
						
							|  |  |  |  # | 
					
						
							|  |  |  | +# If defined, this command is run when adding a user.
 | 
					
						
							|  |  |  | +# It should rebuild any NIS database etc. to add the
 | 
					
						
							|  |  |  | +# new created account.
 | 
					
						
							|  |  |  | +#
 | 
					
						
							|  |  |  | +USERADD_CMD             /usr/sbin/useradd.local
 | 
					
						
							|  |  |  | +
 | 
					
						
							|  |  |  | +#
 | 
					
						
							|  |  |  |  # If defined, this command is run when removing a user. | 
					
						
							|  |  |  |  # It should remove any at/cron/print jobs etc. owned by | 
					
						
							|  |  |  |  # the user to be removed (passed as the first argument). | 
					
						
							| 
									
										
										
										
											2020-11-02 15:56:45 +00:00
										 |  |  | --- lib/getdef.c
 | 
					
						
							|  |  |  | +++ lib/getdef.c	2020-10-30 12:54:38.117849829 +0000
 | 
					
						
							|  |  |  | @@ -134,6 +134,7 @@ static struct itemdef def_table[] = {
 | 
					
						
							| 
									
										
										
										
											2019-05-06 07:58:15 +00:00
										 |  |  |  	{"UID_MAX", NULL}, | 
					
						
							|  |  |  |  	{"UID_MIN", NULL}, | 
					
						
							|  |  |  |  	{"UMASK", NULL}, | 
					
						
							|  |  |  | +	{"USERADD_CMD", NULL},
 | 
					
						
							|  |  |  |  	{"USERDEL_CMD", NULL}, | 
					
						
							|  |  |  |  	{"USERDEL_PRECMD", NULL}, | 
					
						
							|  |  |  |  	{"USERDEL_POSTCMD", NULL}, | 
					
						
							| 
									
										
										
										
											2020-11-02 15:56:45 +00:00
										 |  |  | --- src/useradd.c
 | 
					
						
							|  |  |  | +++ src/useradd.c	2020-10-30 13:08:17.378336989 +0000
 | 
					
						
							|  |  |  | @@ -2238,6 +2238,44 @@ static void create_mail (void)
 | 
					
						
							| 
									
										
										
										
											2012-10-29 15:15:23 +00:00
										 |  |  |  } | 
					
						
							|  |  |  |   | 
					
						
							|  |  |  |  /* | 
					
						
							|  |  |  | + * call_script - call a script to do some work
 | 
					
						
							|  |  |  | + *
 | 
					
						
							|  |  |  | + *      call_script calls a script for additional changes to the
 | 
					
						
							|  |  |  | + *      account.
 | 
					
						
							|  |  |  | + */
 | 
					
						
							|  |  |  | +
 | 
					
						
							| 
									
										
										
										
											2020-11-02 15:56:45 +00:00
										 |  |  | +static void call_script (const char *user, const uid_t uid, const gid_t gid, const char *home)
 | 
					
						
							| 
									
										
										
										
											2012-10-29 15:15:23 +00:00
										 |  |  | +{
 | 
					
						
							|  |  |  | +        const char *cmd;
 | 
					
						
							| 
									
										
										
										
											2020-11-02 15:56:45 +00:00
										 |  |  | +        const char *argv[6];
 | 
					
						
							|  |  |  | +        char *strgid, *struid;
 | 
					
						
							| 
									
										
										
										
											2012-10-29 15:15:23 +00:00
										 |  |  | +        int status;
 | 
					
						
							|  |  |  | +
 | 
					
						
							|  |  |  | +        cmd = getdef_str ("USERADD_CMD");
 | 
					
						
							|  |  |  | +        if (NULL == cmd) {
 | 
					
						
							|  |  |  | +                return;
 | 
					
						
							|  |  |  | +        }
 | 
					
						
							| 
									
										
										
										
											2020-11-02 15:56:45 +00:00
										 |  |  | +        if (asprintf(&struid, "%lu", (long unsigned)uid) < 0) {
 | 
					
						
							|  |  |  | +                (void) fprintf (stderr, _("%s: out of memory\n"), Prog);
 | 
					
						
							|  |  |  | +                exit(1);
 | 
					
						
							|  |  |  | +        }
 | 
					
						
							|  |  |  | +        if (asprintf(&strgid, "%lu", (long unsigned)gid) < 0) {
 | 
					
						
							|  |  |  | +                (void) fprintf (stderr, _("%s: out of memory\n"), Prog);
 | 
					
						
							|  |  |  | +                exit(1);
 | 
					
						
							|  |  |  | +        }
 | 
					
						
							| 
									
										
										
										
											2012-10-29 15:15:23 +00:00
										 |  |  | +        argv[0] = cmd;
 | 
					
						
							|  |  |  | +        argv[1] = user;
 | 
					
						
							| 
									
										
										
										
											2020-11-02 15:56:45 +00:00
										 |  |  | +        argv[2] = struid;
 | 
					
						
							|  |  |  | +        argv[3] = strgid;
 | 
					
						
							|  |  |  | +        argv[4] = home;
 | 
					
						
							|  |  |  | +        argv[5] = (char *)0;
 | 
					
						
							| 
									
										
										
										
											2012-10-29 15:15:23 +00:00
										 |  |  | +        (void) run_command (cmd, argv, NULL, &status);
 | 
					
						
							| 
									
										
										
										
											2020-11-02 15:56:45 +00:00
										 |  |  | +        free(strgid);
 | 
					
						
							|  |  |  | +        free(struid);
 | 
					
						
							| 
									
										
										
										
											2012-10-29 15:15:23 +00:00
										 |  |  | +}
 | 
					
						
							|  |  |  | +
 | 
					
						
							|  |  |  | +
 | 
					
						
							|  |  |  | +/*
 | 
					
						
							|  |  |  |   * main - useradd command | 
					
						
							|  |  |  |   */ | 
					
						
							|  |  |  |  int main (int argc, char **argv) | 
					
						
							| 
									
										
										
										
											2020-11-02 15:56:45 +00:00
										 |  |  | @@ -2514,6 +2552,7 @@ int main (int argc, char **argv)
 | 
					
						
							| 
									
										
										
										
											2012-10-29 15:15:23 +00:00
										 |  |  |  	nscd_flush_cache ("group"); | 
					
						
							| 
									
										
										
										
											2019-06-14 07:41:25 +00:00
										 |  |  |  	sssd_flush_cache (SSSD_DB_PASSWD | SSSD_DB_GROUP); | 
					
						
							| 
									
										
										
										
											2012-10-29 15:15:23 +00:00
										 |  |  |   | 
					
						
							| 
									
										
										
										
											2020-11-02 15:56:45 +00:00
										 |  |  | +	call_script (user_name, user_id, user_gid, user_home);
 | 
					
						
							| 
									
										
										
										
											2012-10-29 15:15:23 +00:00
										 |  |  | +
 | 
					
						
							|  |  |  |  	return E_SUCCESS; | 
					
						
							|  |  |  |  } | 
					
						
							|  |  |  | -
 |