blob: fa7eb07aa5119d614bbd8c97b5f9e4dbca368957 [file] [log] [blame]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001Subject: [PATCH] Allow for setting password in clear text
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08003Upstream-Status: Inappropriate [OE specific]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05004
5Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
6---
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08007 src/Makefile.am | 8 ++++----
8 src/groupadd.c | 20 +++++++++++++++-----
9 src/groupmod.c | 20 +++++++++++++++-----
10 src/useradd.c | 21 +++++++++++++++------
11 src/usermod.c | 20 +++++++++++++++-----
12 5 files changed, 64 insertions(+), 25 deletions(-)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050013
14diff --git a/src/Makefile.am b/src/Makefile.am
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080015index 3c98a8d..b8093d5 100644
Patrick Williamsc124f4f2015-09-15 14:41:29 -050016--- a/src/Makefile.am
17+++ b/src/Makefile.am
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080018@@ -93,10 +93,10 @@ chgpasswd_LDADD = $(LDADD) $(LIBPAM_SUID) $(LIBSELINUX) $(LIBCRYPT)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050019 chsh_LDADD = $(LDADD) $(LIBPAM) $(LIBSELINUX) $(LIBCRYPT_NOPAM) $(LIBSKEY) $(LIBMD)
20 chpasswd_LDADD = $(LDADD) $(LIBPAM) $(LIBSELINUX) $(LIBCRYPT)
21 gpasswd_LDADD = $(LDADD) $(LIBAUDIT) $(LIBSELINUX) $(LIBCRYPT)
22-groupadd_LDADD = $(LDADD) $(LIBPAM_SUID) $(LIBAUDIT) $(LIBSELINUX)
23+groupadd_LDADD = $(LDADD) $(LIBPAM_SUID) $(LIBAUDIT) $(LIBSELINUX) $(LIBCRYPT)
24 groupdel_LDADD = $(LDADD) $(LIBPAM_SUID) $(LIBAUDIT) $(LIBSELINUX)
25 groupmems_LDADD = $(LDADD) $(LIBPAM) $(LIBSELINUX)
26-groupmod_LDADD = $(LDADD) $(LIBPAM_SUID) $(LIBAUDIT) $(LIBSELINUX)
27+groupmod_LDADD = $(LDADD) $(LIBPAM_SUID) $(LIBAUDIT) $(LIBSELINUX) $(LIBCRYPT)
28 grpck_LDADD = $(LDADD) $(LIBSELINUX)
29 grpconv_LDADD = $(LDADD) $(LIBSELINUX)
30 grpunconv_LDADD = $(LDADD) $(LIBSELINUX)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080031@@ -117,9 +117,9 @@ su_SOURCES = \
Patrick Williamsc124f4f2015-09-15 14:41:29 -050032 suauth.c
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080033 su_LDADD = $(LDADD) $(LIBPAM) $(LIBAUDIT) $(LIBCRYPT_NOPAM) $(LIBSKEY) $(LIBMD)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050034 sulogin_LDADD = $(LDADD) $(LIBCRYPT)
35-useradd_LDADD = $(LDADD) $(LIBPAM_SUID) $(LIBAUDIT) $(LIBSELINUX) $(LIBSEMANAGE) $(LIBACL) $(LIBATTR)
36+useradd_LDADD = $(LDADD) $(LIBPAM_SUID) $(LIBAUDIT) $(LIBSELINUX) $(LIBSEMANAGE) $(LIBACL) $(LIBATTR) $(LIBCRYPT)
37 userdel_LDADD = $(LDADD) $(LIBPAM_SUID) $(LIBAUDIT) $(LIBSELINUX) $(LIBSEMANAGE)
38-usermod_LDADD = $(LDADD) $(LIBPAM_SUID) $(LIBAUDIT) $(LIBSELINUX) $(LIBSEMANAGE) $(LIBACL) $(LIBATTR)
39+usermod_LDADD = $(LDADD) $(LIBPAM_SUID) $(LIBAUDIT) $(LIBSELINUX) $(LIBSEMANAGE) $(LIBACL) $(LIBATTR) $(LIBCRYPT)
40 vipw_LDADD = $(LDADD) $(LIBSELINUX)
41
42 install-am: all-am
43diff --git a/src/groupadd.c b/src/groupadd.c
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080044index b57006c..63e1c48 100644
Patrick Williamsc124f4f2015-09-15 14:41:29 -050045--- a/src/groupadd.c
46+++ b/src/groupadd.c
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080047@@ -123,9 +123,10 @@ static /*@noreturn@*/void usage (int status)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050048 (void) fputs (_(" -o, --non-unique allow to create groups with duplicate\n"
49 " (non-unique) GID\n"), usageout);
50 (void) fputs (_(" -p, --password PASSWORD use this encrypted password for the new group\n"), usageout);
51+ (void) fputs (_(" -P, --clear-password PASSWORD use this clear password for the new group\n"), usageout);
52 (void) fputs (_(" -r, --system create a system account\n"), usageout);
53 (void) fputs (_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout);
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080054- (void) fputs (_(" -P, --prefix PREFIX_DIR directory prefix\n"), usageout);
55+ (void) fputs (_(" -A, --prefix PREFIX_DIR directory prefix\n"), usageout);
Patrick Williamsc124f4f2015-09-15 14:41:29 -050056 (void) fputs ("\n", usageout);
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080057 exit (status);
58 }
59@@ -387,13 +388,14 @@ static void process_flags (int argc, char **argv)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050060 {"key", required_argument, NULL, 'K'},
61 {"non-unique", no_argument, NULL, 'o'},
62 {"password", required_argument, NULL, 'p'},
63+ {"clear-password", required_argument, NULL, 'P'},
64 {"system", no_argument, NULL, 'r'},
65 {"root", required_argument, NULL, 'R'},
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080066- {"prefix", required_argument, NULL, 'P'},
67+ {"prefix", required_argument, NULL, 'A'},
Patrick Williamsc124f4f2015-09-15 14:41:29 -050068 {NULL, 0, NULL, '\0'}
69 };
70
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080071- while ((c = getopt_long (argc, argv, "fg:hK:op:rR:P:",
72+ while ((c = getopt_long (argc, argv, "fg:hK:op:P:rR:A:",
Patrick Williamsc124f4f2015-09-15 14:41:29 -050073 long_options, NULL)) != -1) {
74 switch (c) {
75 case 'f':
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080076@@ -445,12 +447,20 @@ static void process_flags (int argc, char **argv)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050077 pflg = true;
78 group_passwd = optarg;
79 break;
80+ case 'P':
81+ pflg = true;
82+ group_passwd = pw_encrypt (optarg, crypt_make_salt (NULL, NULL));
83+ break;
84 case 'r':
85 rflg = true;
86 break;
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080087 case 'R': /* no-op, handled in process_root_flag () */
88 break;
89- case 'P': /* no-op, handled in process_prefix_flag () */
90+ case 'A': /* no-op, handled in process_prefix_flag () */
91+ fprintf (stderr,
92+ _("%s: -A is deliberately not supported \n"),
93+ Prog);
94+ exit (E_BAD_ARG);
95 break;
96 default:
97 usage (E_USAGE);
98@@ -584,7 +594,7 @@ int main (int argc, char **argv)
99 (void) textdomain (PACKAGE);
100
101 process_root_flag ("-R", argc, argv);
102- prefix = process_prefix_flag ("-P", argc, argv);
103+ prefix = process_prefix_flag ("-A", argc, argv);
104
105 OPENLOG ("groupadd");
106 #ifdef WITH_AUDIT
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500107diff --git a/src/groupmod.c b/src/groupmod.c
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800108index b293b98..72daf2c 100644
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500109--- a/src/groupmod.c
110+++ b/src/groupmod.c
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800111@@ -134,8 +134,9 @@ static void usage (int status)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500112 (void) fputs (_(" -o, --non-unique allow to use a duplicate (non-unique) GID\n"), usageout);
113 (void) fputs (_(" -p, --password PASSWORD change the password to this (encrypted)\n"
114 " PASSWORD\n"), usageout);
115+ (void) fputs (_(" -P, --clear-password PASSWORD change the password to this clear PASSWORD\n"), usageout);
116 (void) fputs (_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout);
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800117- (void) fputs (_(" -P, --prefix PREFIX_DIR prefix directory where are located the /etc/* files\n"), usageout);
118+ (void) fputs (_(" -A, --prefix PREFIX_DIR prefix directory where are located the /etc/* files\n"), usageout);
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500119 (void) fputs ("\n", usageout);
120 exit (status);
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800121 }
122@@ -383,11 +384,12 @@ static void process_flags (int argc, char **argv)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500123 {"new-name", required_argument, NULL, 'n'},
124 {"non-unique", no_argument, NULL, 'o'},
125 {"password", required_argument, NULL, 'p'},
126+ {"clear-password", required_argument, NULL, 'P'},
127 {"root", required_argument, NULL, 'R'},
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800128- {"prefix", required_argument, NULL, 'P'},
129+ {"prefix", required_argument, NULL, 'A'},
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500130 {NULL, 0, NULL, '\0'}
131 };
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800132- while ((c = getopt_long (argc, argv, "g:hn:op:R:P:",
133+ while ((c = getopt_long (argc, argv, "g:hn:op:P:R:A:",
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500134 long_options, NULL)) != -1) {
135 switch (c) {
136 case 'g':
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800137@@ -414,9 +416,17 @@ static void process_flags (int argc, char **argv)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500138 group_passwd = optarg;
139 pflg = true;
140 break;
141+ case 'P':
142+ group_passwd = pw_encrypt (optarg, crypt_make_salt (NULL, NULL));
143+ pflg = true;
144+ break;
145 case 'R': /* no-op, handled in process_root_flag () */
146 break;
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800147- case 'P': /* no-op, handled in process_prefix_flag () */
148+ case 'A': /* no-op, handled in process_prefix_flag () */
149+ fprintf (stderr,
150+ _("%s: -A is deliberately not supported \n"),
151+ Prog);
152+ exit (E_BAD_ARG);
153 break;
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500154 default:
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800155 usage (E_USAGE);
156@@ -757,7 +767,7 @@ int main (int argc, char **argv)
157 (void) textdomain (PACKAGE);
158
159 process_root_flag ("-R", argc, argv);
160- prefix = process_prefix_flag ("-P", argc, argv);
161+ prefix = process_prefix_flag ("-A", argc, argv);
162
163 OPENLOG ("groupmod");
164 #ifdef WITH_AUDIT
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500165diff --git a/src/useradd.c b/src/useradd.c
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800166index c74e491..7214e72 100644
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500167--- a/src/useradd.c
168+++ b/src/useradd.c
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800169@@ -829,9 +829,10 @@ static void usage (int status)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500170 (void) fputs (_(" -o, --non-unique allow to create users with duplicate\n"
171 " (non-unique) UID\n"), usageout);
172 (void) fputs (_(" -p, --password PASSWORD encrypted password of the new account\n"), usageout);
173+ (void) fputs (_(" -P, --clear-password PASSWORD clear password of the new account\n"), usageout);
174 (void) fputs (_(" -r, --system create a system account\n"), usageout);
175 (void) fputs (_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout);
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800176- (void) fputs (_(" -P, --prefix PREFIX_DIR prefix directory where are located the /etc/* files\n"), usageout);
177+ (void) fputs (_(" -A, --prefix PREFIX_DIR prefix directory where are located the /etc/* files\n"), usageout);
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500178 (void) fputs (_(" -s, --shell SHELL login shell of the new account\n"), usageout);
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800179 (void) fputs (_(" -u, --uid UID user ID of the new account\n"), usageout);
180 (void) fputs (_(" -U, --user-group create a group with the same name as the user\n"), usageout);
181@@ -1104,9 +1105,10 @@ static void process_flags (int argc, char **argv)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500182 {"no-user-group", no_argument, NULL, 'N'},
183 {"non-unique", no_argument, NULL, 'o'},
184 {"password", required_argument, NULL, 'p'},
185+ {"clear-password", required_argument, NULL, 'P'},
186 {"system", no_argument, NULL, 'r'},
187 {"root", required_argument, NULL, 'R'},
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800188- {"prefix", required_argument, NULL, 'P'},
189+ {"prefix", required_argument, NULL, 'A'},
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500190 {"shell", required_argument, NULL, 's'},
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800191 {"uid", required_argument, NULL, 'u'},
192 {"user-group", no_argument, NULL, 'U'},
193@@ -1117,9 +1119,9 @@ static void process_flags (int argc, char **argv)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500194 };
195 while ((c = getopt_long (argc, argv,
196 #ifdef WITH_SELINUX
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800197- "b:c:d:De:f:g:G:hk:K:lmMNop:rR:P:s:u:UZ:",
198+ "b:c:d:De:f:g:G:hk:K:lmMNop:P:rR:A:s:u:UZ:",
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500199 #else /* !WITH_SELINUX */
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800200- "b:c:d:De:f:g:G:hk:K:lmMNop:rR:P:s:u:U",
201+ "b:c:d:De:f:g:G:hk:K:lmMNop:P:rR:A:s:u:U",
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500202 #endif /* !WITH_SELINUX */
203 long_options, NULL)) != -1) {
204 switch (c) {
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800205@@ -1285,12 +1287,19 @@ static void process_flags (int argc, char **argv)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500206 }
207 user_pass = optarg;
208 break;
209+ case 'P': /* set clear text password */
210+ user_pass = pw_encrypt (optarg, crypt_make_salt (NULL, NULL));
211+ break;
212 case 'r':
213 rflg = true;
214 break;
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800215 case 'R': /* no-op, handled in process_root_flag () */
216 break;
217- case 'P': /* no-op, handled in process_prefix_flag () */
218+ case 'A': /* no-op, handled in process_prefix_flag () */
219+ fprintf (stderr,
220+ _("%s: -A is deliberately not supported \n"),
221+ Prog);
222+ exit (E_BAD_ARG);
223 break;
224 case 's':
225 if ( ( !VALID (optarg) )
226@@ -2148,7 +2157,7 @@ int main (int argc, char **argv)
227
228 process_root_flag ("-R", argc, argv);
229
230- prefix = process_prefix_flag("-P", argc, argv);
231+ prefix = process_prefix_flag("-A", argc, argv);
232
233 OPENLOG ("useradd");
234 #ifdef WITH_AUDIT
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500235diff --git a/src/usermod.c b/src/usermod.c
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800236index e571426..ccfbb99 100644
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500237--- a/src/usermod.c
238+++ b/src/usermod.c
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800239@@ -424,8 +424,9 @@ static /*@noreturn@*/void usage (int status)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500240 " new location (use only with -d)\n"), usageout);
241 (void) fputs (_(" -o, --non-unique allow using duplicate (non-unique) UID\n"), usageout);
242 (void) fputs (_(" -p, --password PASSWORD use encrypted password for the new password\n"), usageout);
243+ (void) fputs (_(" -P, --clear-password PASSWORD use clear password for the new password\n"), usageout);
244 (void) fputs (_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout);
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800245- (void) fputs (_(" -P, --prefix PREFIX_DIR prefix directory where are located the /etc/* files\n"), usageout);
246+ (void) fputs (_(" -A, --prefix PREFIX_DIR prefix directory where are located the /etc/* files\n"), usageout);
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500247 (void) fputs (_(" -s, --shell SHELL new login shell for the user account\n"), usageout);
248 (void) fputs (_(" -u, --uid UID new UID for the user account\n"), usageout);
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800249 (void) fputs (_(" -U, --unlock unlock the user account\n"), usageout);
250@@ -1002,8 +1003,9 @@ static void process_flags (int argc, char **argv)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500251 {"move-home", no_argument, NULL, 'm'},
252 {"non-unique", no_argument, NULL, 'o'},
253 {"password", required_argument, NULL, 'p'},
254+ {"clear-password", required_argument, NULL, 'P'},
255 {"root", required_argument, NULL, 'R'},
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800256- {"prefix", required_argument, NULL, 'P'},
257+ {"prefix", required_argument, NULL, 'A'},
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500258 {"shell", required_argument, NULL, 's'},
259 {"uid", required_argument, NULL, 'u'},
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800260 {"unlock", no_argument, NULL, 'U'},
261@@ -1019,7 +1021,7 @@ static void process_flags (int argc, char **argv)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500262 {NULL, 0, NULL, '\0'}
263 };
264 while ((c = getopt_long (argc, argv,
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800265- "ac:d:e:f:g:G:hl:Lmop:R:s:u:UP:"
266+ "ac:d:e:f:g:G:hl:Lmop:P:R:s:u:UA:"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500267 #ifdef ENABLE_SUBIDS
268 "v:w:V:W:"
269 #endif /* ENABLE_SUBIDS */
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800270@@ -1119,9 +1121,17 @@ static void process_flags (int argc, char **argv)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500271 user_pass = optarg;
272 pflg = true;
273 break;
274+ case 'P':
275+ user_pass = pw_encrypt (optarg, crypt_make_salt (NULL, NULL));
276+ pflg = true;
277+ break;
278 case 'R': /* no-op, handled in process_root_flag () */
279 break;
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800280- case 'P': /* no-op, handled in process_prefix_flag () */
281+ case 'A': /* no-op, handled in process_prefix_flag () */
282+ fprintf (stderr,
283+ _("%s: -A is deliberately not supported \n"),
284+ Prog);
285+ exit (E_BAD_ARG);
286 break;
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500287 case 's':
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800288 if (!VALID (optarg)) {
289@@ -2098,7 +2108,7 @@ int main (int argc, char **argv)
290 (void) textdomain (PACKAGE);
291
292 process_root_flag ("-R", argc, argv);
293- prefix = process_prefix_flag ("-P", argc, argv);
294+ prefix = process_prefix_flag ("-A", argc, argv);
295
296 OPENLOG ("usermod");
297 #ifdef WITH_AUDIT
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500298--
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08002992.11.0
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500300