blob: c6332e4f766e1f113f1727290c7726b2c2b801cf [file] [log] [blame]
Andrew Geissler82c905d2020-04-13 13:39:40 -05001From a7d995228491ad5255ad86c1f04ba071f6880897 Mon Sep 17 00:00:00 2001
2From: Chen Qi <Qi.Chen@windriver.com>
3Date: Sat, 16 Nov 2013 15:27:47 +0800
4Subject: [PATCH] Allow for setting password in clear text
5
6Upstream-Status: Inappropriate [OE specific]
7
8Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
9
10---
11 src/Makefile.am | 8 ++++----
12 src/groupadd.c | 20 +++++++++++++++-----
13 src/groupmod.c | 20 +++++++++++++++-----
14 src/useradd.c | 21 +++++++++++++++------
15 src/usermod.c | 20 +++++++++++++++-----
16 5 files changed, 64 insertions(+), 25 deletions(-)
17
18diff --git a/src/Makefile.am b/src/Makefile.am
19index f31fd7a..4a317a3 100644
20--- a/src/Makefile.am
21+++ b/src/Makefile.am
22@@ -103,10 +103,10 @@ chsh_LDADD = $(LDADD) $(LIBPAM) $(LIBAUDIT) $(LIBSELINUX) $(LIBCRYPT_NOPAM)
23 chpasswd_LDADD = $(LDADD) $(LIBPAM) $(LIBAUDIT) $(LIBSELINUX) $(LIBCRYPT) $(LIBECONF)
24 expiry_LDADD = $(LDADD) $(LIBECONF)
25 gpasswd_LDADD = $(LDADD) $(LIBAUDIT) $(LIBSELINUX) $(LIBCRYPT) $(LIBECONF)
26-groupadd_LDADD = $(LDADD) $(LIBPAM_SUID) $(LIBAUDIT) $(LIBSELINUX) $(LIBECONF)
27+groupadd_LDADD = $(LDADD) $(LIBPAM_SUID) $(LIBAUDIT) $(LIBSELINUX) $(LIBECONF) $(LIBCRYPT)
28 groupdel_LDADD = $(LDADD) $(LIBPAM_SUID) $(LIBAUDIT) $(LIBSELINUX) $(LIBECONF)
29 groupmems_LDADD = $(LDADD) $(LIBPAM) $(LIBAUDIT) $(LIBSELINUX) $(LIBECONF)
30-groupmod_LDADD = $(LDADD) $(LIBPAM_SUID) $(LIBAUDIT) $(LIBSELINUX) $(LIBECONF)
31+groupmod_LDADD = $(LDADD) $(LIBPAM_SUID) $(LIBAUDIT) $(LIBSELINUX) $(LIBECONF) $(LIBCRYPT)
32 grpck_LDADD = $(LDADD) $(LIBAUDIT) $(LIBSELINUX) $(LIBECONF)
33 grpconv_LDADD = $(LDADD) $(LIBAUDIT) $(LIBSELINUX) $(LIBECONF)
34 grpunconv_LDADD = $(LDADD) $(LIBAUDIT) $(LIBSELINUX) $(LIBECONF)
35@@ -127,9 +127,9 @@ su_SOURCES = \
36 suauth.c
37 su_LDADD = $(LDADD) $(LIBPAM) $(LIBAUDIT) $(LIBCRYPT_NOPAM) $(LIBSKEY) $(LIBMD) $(LIBECONF)
38 sulogin_LDADD = $(LDADD) $(LIBCRYPT) $(LIBECONF)
39-useradd_LDADD = $(LDADD) $(LIBPAM_SUID) $(LIBAUDIT) $(LIBSELINUX) $(LIBSEMANAGE) $(LIBACL) $(LIBATTR) $(LIBECONF)
40+useradd_LDADD = $(LDADD) $(LIBPAM_SUID) $(LIBAUDIT) $(LIBSELINUX) $(LIBSEMANAGE) $(LIBACL) $(LIBATTR) $(LIBECONF) $(LIBCRYPT)
41 userdel_LDADD = $(LDADD) $(LIBPAM_SUID) $(LIBAUDIT) $(LIBSELINUX) $(LIBSEMANAGE) $(LIBECONF)
42-usermod_LDADD = $(LDADD) $(LIBPAM_SUID) $(LIBAUDIT) $(LIBSELINUX) $(LIBSEMANAGE) $(LIBACL) $(LIBATTR) $(LIBECONF)
43+usermod_LDADD = $(LDADD) $(LIBPAM_SUID) $(LIBAUDIT) $(LIBSELINUX) $(LIBSEMANAGE) $(LIBACL) $(LIBATTR) $(LIBECONF) $(LIBCRYPT)
44 vipw_LDADD = $(LDADD) $(LIBAUDIT) $(LIBSELINUX) $(LIBECONF)
45
46 install-am: all-am
47diff --git a/src/groupadd.c b/src/groupadd.c
48index e9c4bb7..d572c00 100644
49--- a/src/groupadd.c
50+++ b/src/groupadd.c
51@@ -127,9 +127,10 @@ static /*@noreturn@*/void usage (int status)
52 (void) fputs (_(" -o, --non-unique allow to create groups with duplicate\n"
53 " (non-unique) GID\n"), usageout);
54 (void) fputs (_(" -p, --password PASSWORD use this encrypted password for the new group\n"), usageout);
55+ (void) fputs (_(" -P, --clear-password PASSWORD use this clear password for the new group\n"), usageout);
56 (void) fputs (_(" -r, --system create a system account\n"), usageout);
57 (void) fputs (_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout);
58- (void) fputs (_(" -P, --prefix PREFIX_DIR directory prefix\n"), usageout);
59+ (void) fputs (_(" -A, --prefix PREFIX_DIR directory prefix\n"), usageout);
60 (void) fputs ("\n", usageout);
61 exit (status);
62 }
63@@ -391,13 +392,14 @@ static void process_flags (int argc, char **argv)
64 {"key", required_argument, NULL, 'K'},
65 {"non-unique", no_argument, NULL, 'o'},
66 {"password", required_argument, NULL, 'p'},
67+ {"clear-password", required_argument, NULL, 'P'},
68 {"system", no_argument, NULL, 'r'},
69 {"root", required_argument, NULL, 'R'},
70- {"prefix", required_argument, NULL, 'P'},
71+ {"prefix", required_argument, NULL, 'A'},
72 {NULL, 0, NULL, '\0'}
73 };
74
75- while ((c = getopt_long (argc, argv, "fg:hK:op:rR:P:",
76+ while ((c = getopt_long (argc, argv, "fg:hK:op:P:rR:A:",
77 long_options, NULL)) != -1) {
78 switch (c) {
79 case 'f':
80@@ -449,12 +451,20 @@ static void process_flags (int argc, char **argv)
81 pflg = true;
82 group_passwd = optarg;
83 break;
84+ case 'P':
85+ pflg = true;
86+ group_passwd = pw_encrypt (optarg, crypt_make_salt (NULL, NULL));
87+ break;
88 case 'r':
89 rflg = true;
90 break;
91 case 'R': /* no-op, handled in process_root_flag () */
92 break;
93- case 'P': /* no-op, handled in process_prefix_flag () */
94+ case 'A': /* no-op, handled in process_prefix_flag () */
95+ fprintf (stderr,
96+ _("%s: -A is deliberately not supported \n"),
97+ Prog);
98+ exit (E_BAD_ARG);
99 break;
100 default:
101 usage (E_USAGE);
102@@ -588,7 +598,7 @@ int main (int argc, char **argv)
103 (void) textdomain (PACKAGE);
104
105 process_root_flag ("-R", argc, argv);
106- prefix = process_prefix_flag ("-P", argc, argv);
107+ prefix = process_prefix_flag ("-A", argc, argv);
108
109 OPENLOG ("groupadd");
110 #ifdef WITH_AUDIT
111diff --git a/src/groupmod.c b/src/groupmod.c
112index bc14438..25ccb44 100644
113--- a/src/groupmod.c
114+++ b/src/groupmod.c
115@@ -138,8 +138,9 @@ static void usage (int status)
116 (void) fputs (_(" -o, --non-unique allow to use a duplicate (non-unique) GID\n"), usageout);
117 (void) fputs (_(" -p, --password PASSWORD change the password to this (encrypted)\n"
118 " PASSWORD\n"), usageout);
119+ (void) fputs (_(" -P, --clear-password PASSWORD change the password to this clear PASSWORD\n"), usageout);
120 (void) fputs (_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout);
121- (void) fputs (_(" -P, --prefix PREFIX_DIR prefix directory where are located the /etc/* files\n"), usageout);
122+ (void) fputs (_(" -A, --prefix PREFIX_DIR prefix directory where are located the /etc/* files\n"), usageout);
123 (void) fputs ("\n", usageout);
124 exit (status);
125 }
126@@ -387,11 +388,12 @@ static void process_flags (int argc, char **argv)
127 {"new-name", required_argument, NULL, 'n'},
128 {"non-unique", no_argument, NULL, 'o'},
129 {"password", required_argument, NULL, 'p'},
130+ {"clear-password", required_argument, NULL, 'P'},
131 {"root", required_argument, NULL, 'R'},
132- {"prefix", required_argument, NULL, 'P'},
133+ {"prefix", required_argument, NULL, 'A'},
134 {NULL, 0, NULL, '\0'}
135 };
136- while ((c = getopt_long (argc, argv, "g:hn:op:R:P:",
137+ while ((c = getopt_long (argc, argv, "g:hn:op:P:R:A:",
138 long_options, NULL)) != -1) {
139 switch (c) {
140 case 'g':
141@@ -418,9 +420,17 @@ static void process_flags (int argc, char **argv)
142 group_passwd = optarg;
143 pflg = true;
144 break;
145+ case 'P':
146+ group_passwd = pw_encrypt (optarg, crypt_make_salt (NULL, NULL));
147+ pflg = true;
148+ break;
149 case 'R': /* no-op, handled in process_root_flag () */
150 break;
151- case 'P': /* no-op, handled in process_prefix_flag () */
152+ case 'A': /* no-op, handled in process_prefix_flag () */
153+ fprintf (stderr,
154+ _("%s: -A is deliberately not supported \n"),
155+ Prog);
156+ exit (E_BAD_ARG);
157 break;
158 default:
159 usage (E_USAGE);
160@@ -761,7 +771,7 @@ int main (int argc, char **argv)
161 (void) textdomain (PACKAGE);
162
163 process_root_flag ("-R", argc, argv);
164- prefix = process_prefix_flag ("-P", argc, argv);
165+ prefix = process_prefix_flag ("-A", argc, argv);
166
167 OPENLOG ("groupmod");
168 #ifdef WITH_AUDIT
169diff --git a/src/useradd.c b/src/useradd.c
170index 1b7bf06..44f09e2 100644
171--- a/src/useradd.c
172+++ b/src/useradd.c
173@@ -853,9 +853,10 @@ static void usage (int status)
174 (void) fputs (_(" -o, --non-unique allow to create users with duplicate\n"
175 " (non-unique) UID\n"), usageout);
176 (void) fputs (_(" -p, --password PASSWORD encrypted password of the new account\n"), usageout);
177+ (void) fputs (_(" -P, --clear-password PASSWORD clear password of the new account\n"), usageout);
178 (void) fputs (_(" -r, --system create a system account\n"), usageout);
179 (void) fputs (_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout);
180- (void) fputs (_(" -P, --prefix PREFIX_DIR prefix directory where are located the /etc/* files\n"), usageout);
181+ (void) fputs (_(" -A, --prefix PREFIX_DIR prefix directory where are located the /etc/* files\n"), usageout);
182 (void) fputs (_(" -s, --shell SHELL login shell of the new account\n"), usageout);
183 (void) fputs (_(" -u, --uid UID user ID of the new account\n"), usageout);
184 (void) fputs (_(" -U, --user-group create a group with the same name as the user\n"), usageout);
185@@ -1133,9 +1134,10 @@ static void process_flags (int argc, char **argv)
186 {"no-user-group", no_argument, NULL, 'N'},
187 {"non-unique", no_argument, NULL, 'o'},
188 {"password", required_argument, NULL, 'p'},
189+ {"clear-password", required_argument, NULL, 'P'},
190 {"system", no_argument, NULL, 'r'},
191 {"root", required_argument, NULL, 'R'},
192- {"prefix", required_argument, NULL, 'P'},
193+ {"prefix", required_argument, NULL, 'A'},
194 {"shell", required_argument, NULL, 's'},
195 {"uid", required_argument, NULL, 'u'},
196 {"user-group", no_argument, NULL, 'U'},
197@@ -1146,9 +1148,9 @@ static void process_flags (int argc, char **argv)
198 };
199 while ((c = getopt_long (argc, argv,
200 #ifdef WITH_SELINUX
201- "b:c:d:De:f:g:G:hk:K:lmMNop:rR:P:s:u:UZ:",
202+ "b:c:d:De:f:g:G:hk:K:lmMNop:P:rR:A:s:u:UZ:",
203 #else /* !WITH_SELINUX */
204- "b:c:d:De:f:g:G:hk:K:lmMNop:rR:P:s:u:U",
205+ "b:c:d:De:f:g:G:hk:K:lmMNop:P:rR:A:s:u:U",
206 #endif /* !WITH_SELINUX */
207 long_options, NULL)) != -1) {
208 switch (c) {
209@@ -1320,12 +1322,19 @@ static void process_flags (int argc, char **argv)
210 }
211 user_pass = optarg;
212 break;
213+ case 'P': /* set clear text password */
214+ user_pass = pw_encrypt (optarg, crypt_make_salt (NULL, NULL));
215+ break;
216 case 'r':
217 rflg = true;
218 break;
219 case 'R': /* no-op, handled in process_root_flag () */
220 break;
221- case 'P': /* no-op, handled in process_prefix_flag () */
222+ case 'A': /* no-op, handled in process_prefix_flag () */
223+ fprintf (stderr,
224+ _("%s: -A is deliberately not supported \n"),
225+ Prog);
226+ exit (E_BAD_ARG);
227 break;
228 case 's':
229 if ( ( !VALID (optarg) )
230@@ -2257,7 +2266,7 @@ int main (int argc, char **argv)
231
232 process_root_flag ("-R", argc, argv);
233
234- prefix = process_prefix_flag("-P", argc, argv);
235+ prefix = process_prefix_flag("-A", argc, argv);
236
237 OPENLOG ("useradd");
238 #ifdef WITH_AUDIT
239diff --git a/src/usermod.c b/src/usermod.c
240index 21c6da9..cffdb3e 100644
241--- a/src/usermod.c
242+++ b/src/usermod.c
243@@ -431,8 +431,9 @@ static /*@noreturn@*/void usage (int status)
244 " new location (use only with -d)\n"), usageout);
245 (void) fputs (_(" -o, --non-unique allow using duplicate (non-unique) UID\n"), usageout);
246 (void) fputs (_(" -p, --password PASSWORD use encrypted password for the new password\n"), usageout);
247+ (void) fputs (_(" -P, --clear-password PASSWORD use clear password for the new password\n"), usageout);
248 (void) fputs (_(" -R, --root CHROOT_DIR directory to chroot into\n"), usageout);
249- (void) fputs (_(" -P, --prefix PREFIX_DIR prefix directory where are located the /etc/* files\n"), usageout);
250+ (void) fputs (_(" -A, --prefix PREFIX_DIR prefix directory where are located the /etc/* files\n"), usageout);
251 (void) fputs (_(" -s, --shell SHELL new login shell for the user account\n"), usageout);
252 (void) fputs (_(" -u, --uid UID new UID for the user account\n"), usageout);
253 (void) fputs (_(" -U, --unlock unlock the user account\n"), usageout);
254@@ -1010,8 +1011,9 @@ static void process_flags (int argc, char **argv)
255 {"move-home", no_argument, NULL, 'm'},
256 {"non-unique", no_argument, NULL, 'o'},
257 {"password", required_argument, NULL, 'p'},
258+ {"clear-password", required_argument, NULL, 'P'},
259 {"root", required_argument, NULL, 'R'},
260- {"prefix", required_argument, NULL, 'P'},
261+ {"prefix", required_argument, NULL, 'A'},
262 {"shell", required_argument, NULL, 's'},
263 {"uid", required_argument, NULL, 'u'},
264 {"unlock", no_argument, NULL, 'U'},
265@@ -1027,7 +1029,7 @@ static void process_flags (int argc, char **argv)
266 {NULL, 0, NULL, '\0'}
267 };
268 while ((c = getopt_long (argc, argv,
269- "abc:d:e:f:g:G:hl:Lmop:R:s:u:UP:"
270+ "abc:d:e:f:g:G:hl:Lmop:P:R:s:u:UA:"
271 #ifdef ENABLE_SUBIDS
272 "v:w:V:W:"
273 #endif /* ENABLE_SUBIDS */
274@@ -1130,9 +1132,17 @@ static void process_flags (int argc, char **argv)
275 user_pass = optarg;
276 pflg = true;
277 break;
278+ case 'P':
279+ user_pass = pw_encrypt (optarg, crypt_make_salt (NULL, NULL));
280+ pflg = true;
281+ break;
282 case 'R': /* no-op, handled in process_root_flag () */
283 break;
284- case 'P': /* no-op, handled in process_prefix_flag () */
285+ case 'A': /* no-op, handled in process_prefix_flag () */
286+ fprintf (stderr,
287+ _("%s: -A is deliberately not supported \n"),
288+ Prog);
289+ exit (E_BAD_ARG);
290 break;
291 case 's':
292 if (!VALID (optarg)) {
293@@ -2127,7 +2137,7 @@ int main (int argc, char **argv)
294 (void) textdomain (PACKAGE);
295
296 process_root_flag ("-R", argc, argv);
297- prefix = process_prefix_flag ("-P", argc, argv);
298+ prefix = process_prefix_flag ("-A", argc, argv);
299
300 OPENLOG ("usermod");
301 #ifdef WITH_AUDIT