Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 302570
Collapse All | Expand All

(-)busybox-1.15.3.old/include/applets.h (-2 / +2 lines)
Lines 70-77 Link Here
70
IF_TEST(APPLET_NOFORK([,  test, _BB_DIR_USR_BIN, _BB_SUID_DROP, test))
70
IF_TEST(APPLET_NOFORK([,  test, _BB_DIR_USR_BIN, _BB_SUID_DROP, test))
71
IF_TEST(APPLET_NOFORK([[, test, _BB_DIR_USR_BIN, _BB_SUID_DROP, test))
71
IF_TEST(APPLET_NOFORK([[, test, _BB_DIR_USR_BIN, _BB_SUID_DROP, test))
72
IF_ACPID(APPLET(acpid, _BB_DIR_SBIN, _BB_SUID_DROP))
72
IF_ACPID(APPLET(acpid, _BB_DIR_SBIN, _BB_SUID_DROP))
73
IF_ADDGROUP(APPLET(addgroup, _BB_DIR_BIN, _BB_SUID_DROP))
74
IF_ADDUSER(APPLET(adduser, _BB_DIR_BIN, _BB_SUID_DROP))
75
IF_ADJTIMEX(APPLET(adjtimex, _BB_DIR_SBIN, _BB_SUID_DROP))
73
IF_ADJTIMEX(APPLET(adjtimex, _BB_DIR_SBIN, _BB_SUID_DROP))
76
IF_AR(APPLET(ar, _BB_DIR_USR_BIN, _BB_SUID_DROP))
74
IF_AR(APPLET(ar, _BB_DIR_USR_BIN, _BB_SUID_DROP))
77
IF_ARP(APPLET(arp, _BB_DIR_SBIN, _BB_SUID_DROP))
75
IF_ARP(APPLET(arp, _BB_DIR_SBIN, _BB_SUID_DROP))
Lines 177-182 Link Here
177
IF_GETSEBOOL(APPLET(getsebool, _BB_DIR_USR_SBIN, _BB_SUID_DROP))
175
IF_GETSEBOOL(APPLET(getsebool, _BB_DIR_USR_SBIN, _BB_SUID_DROP))
178
IF_GETTY(APPLET(getty, _BB_DIR_SBIN, _BB_SUID_DROP))
176
IF_GETTY(APPLET(getty, _BB_DIR_SBIN, _BB_SUID_DROP))
179
IF_GREP(APPLET(grep, _BB_DIR_BIN, _BB_SUID_DROP))
177
IF_GREP(APPLET(grep, _BB_DIR_BIN, _BB_SUID_DROP))
178
IF_ADDGROUP(APPLET_ODDNAME(groupadd, addgroup, _BB_DIR_BIN, _BB_SUID_DROP, addgroup))
180
IF_GUNZIP(APPLET(gunzip, _BB_DIR_BIN, _BB_SUID_DROP))
179
IF_GUNZIP(APPLET(gunzip, _BB_DIR_BIN, _BB_SUID_DROP))
181
IF_GZIP(APPLET(gzip, _BB_DIR_BIN, _BB_SUID_DROP))
180
IF_GZIP(APPLET(gzip, _BB_DIR_BIN, _BB_SUID_DROP))
182
IF_HALT(APPLET(halt, _BB_DIR_SBIN, _BB_SUID_DROP))
181
IF_HALT(APPLET(halt, _BB_DIR_SBIN, _BB_SUID_DROP))
Lines 410-415 Link Here
410
IF_LZOP(APPLET_ODDNAME(unlzop, lzop, _BB_DIR_USR_BIN, _BB_SUID_DROP, unlzop))
409
IF_LZOP(APPLET_ODDNAME(unlzop, lzop, _BB_DIR_USR_BIN, _BB_SUID_DROP, unlzop))
411
IF_UNZIP(APPLET(unzip, _BB_DIR_USR_BIN, _BB_SUID_DROP))
410
IF_UNZIP(APPLET(unzip, _BB_DIR_USR_BIN, _BB_SUID_DROP))
412
IF_UPTIME(APPLET(uptime, _BB_DIR_USR_BIN, _BB_SUID_DROP))
411
IF_UPTIME(APPLET(uptime, _BB_DIR_USR_BIN, _BB_SUID_DROP))
412
IF_ADDUSER(APPLET_ODDNAME(useradd, adduser, _BB_DIR_BIN, _BB_SUID_DROP, adduser))
413
IF_USLEEP(APPLET_NOFORK(usleep, usleep, _BB_DIR_BIN, _BB_SUID_DROP, usleep))
413
IF_USLEEP(APPLET_NOFORK(usleep, usleep, _BB_DIR_BIN, _BB_SUID_DROP, usleep))
414
IF_UUDECODE(APPLET(uudecode, _BB_DIR_USR_BIN, _BB_SUID_DROP))
414
IF_UUDECODE(APPLET(uudecode, _BB_DIR_USR_BIN, _BB_SUID_DROP))
415
IF_UUENCODE(APPLET(uuencode, _BB_DIR_USR_BIN, _BB_SUID_DROP))
415
IF_UUENCODE(APPLET(uuencode, _BB_DIR_USR_BIN, _BB_SUID_DROP))
(-)busybox-1.15.3.old/include/libbb.h (+2 lines)
Lines 334-339 Link Here
334
334
335
char *xmalloc_follow_symlinks(const char *path) FAST_FUNC;
335
char *xmalloc_follow_symlinks(const char *path) FAST_FUNC;
336
336
337
const char *cross_path(const char *path);
338
337
339
338
enum {
340
enum {
339
	/* bb_signals(BB_FATAL_SIGS, handler) catches all signals which
341
	/* bb_signals(BB_FATAL_SIGS, handler) catches all signals which
(-)busybox-1.15.3.old/include/usage.h (-7 / +8 lines)
Lines 38-57 Link Here
38
       "Add a group " IF_FEATURE_ADDUSER_TO_GROUP("or add a user to a group") "\n" \
38
       "Add a group " IF_FEATURE_ADDUSER_TO_GROUP("or add a user to a group") "\n" \
39
     "\nOptions:" \
39
     "\nOptions:" \
40
     "\n	-g GID	Group id" \
40
     "\n	-g GID	Group id" \
41
     "\n	-S	Create a system group" \
41
     "\n	-r	Create a system group" \
42
42
43
#define adduser_trivial_usage \
43
#define adduser_trivial_usage \
44
       "[OPTIONS] user_name"
44
       "[OPTIONS] user_name"
45
#define adduser_full_usage "\n\n" \
45
#define adduser_full_usage "\n\n" \
46
       "Add a user\n" \
46
       "Add a user\n" \
47
     "\nOptions:" \
47
     "\nOptions:" \
48
     "\n	-h DIR		Home directory" \
48
     "\n	-d DIR		Home directory" \
49
     "\n	-g GECOS	GECOS field" \
49
     "\n	-c COMMENT	Comment field" \
50
     "\n	-s SHELL	Login shell" \
50
     "\n	-s SHELL	Login shell" \
51
     "\n	-G GROUP	Add user to existing group" \
51
     "\n	-g GROUP	Add user to primary group" \
52
     "\n	-S		Create a system user" \
52
     "\n	-G GROUPS	Add user to supplementary groups" \
53
     "\n	-D		Do not assign a password" \
53
     "\n	-r		Create a system user" \
54
     "\n	-H		Do not create home directory" \
54
     "\n	-P		Assign a password" \
55
     "\n	-m		Create home directory" \
55
     "\n	-u UID		User id" \
56
     "\n	-u UID		User id" \
56
57
57
#define adjtimex_trivial_usage \
58
#define adjtimex_trivial_usage \
(-)busybox-1.15.3.old/libbb/appletlib.c (-1 / +6 lines)
Lines 746-752 Link Here
746
	int applet = find_applet_by_name(name);
746
	int applet = find_applet_by_name(name);
747
	if (applet >= 0)
747
	if (applet >= 0)
748
		run_applet_no_and_exit(applet, argv);
748
		run_applet_no_and_exit(applet, argv);
749
	if (!strncmp(name, "busybox", 7))
749
	if (!strncmp(name, "busybox", 7) || !strncmp(name, basename(bb_busybox_exec_path), strlen(basename(bb_busybox_exec_path))))
750
		exit(busybox_main(argv));
750
		exit(busybox_main(argv));
751
}
751
}
752
752
Lines 760-765 Link Here
760
int main(int argc UNUSED_PARAM, char **argv)
760
int main(int argc UNUSED_PARAM, char **argv)
761
#endif
761
#endif
762
{
762
{
763
	if (!getenv("ROOT") || !strcmp(getenv("ROOT"), "/")) {
764
		full_write2_str("ROOT environment variable must exist\n");
765
		full_write2_str("and should not point to '/'.\n");
766
		xfunc_die();
767
	}
763
#if defined(SINGLE_APPLET_MAIN)
768
#if defined(SINGLE_APPLET_MAIN)
764
	/* Only one applet is selected by the user! */
769
	/* Only one applet is selected by the user! */
765
	/* applet_names in this case is just "applet\0\0" */
770
	/* applet_names in this case is just "applet\0\0" */
(-)busybox-1.15.3.old/libbb/messages.c (+13 lines)
Lines 71-73 Link Here
71
 * Since gcc insists on aligning struct global's members, it would be a pity
71
 * Since gcc insists on aligning struct global's members, it would be a pity
72
 * (and an alignment fault on some CPUs) to mess it up. */
72
 * (and an alignment fault on some CPUs) to mess it up. */
73
char bb_common_bufsiz1[COMMON_BUFSIZE] ALIGNED(sizeof(long long));
73
char bb_common_bufsiz1[COMMON_BUFSIZE] ALIGNED(sizeof(long long));
74
75
const char *cross_path(const char *path) {
76
	static const char *tc_path = NULL;
77
	static char *cpath = NULL;
78
	if (cpath != NULL)
79
		free(cpath);
80
	if (tc_path == NULL)
81
		tc_path = (const char *) getenv("ROOT");
82
	cpath = (char *) calloc(strlen(path) + strlen(tc_path) + 1, sizeof(char));
83
	strcpy(cpath, tc_path);
84
	strcat(cpath, path);
85
	return (const char *) cpath;
86
}
(-)busybox-1.15.3.old/libbb/update_passwd.c (-2 / +2 lines)
Lines 180-186 Link Here
180
		if (member) {
180
		if (member) {
181
			/* It's actually /etc/group+, not /etc/passwd+ */
181
			/* It's actually /etc/group+, not /etc/passwd+ */
182
			if (ENABLE_FEATURE_ADDUSER_TO_GROUP
182
			if (ENABLE_FEATURE_ADDUSER_TO_GROUP
183
			 && applet_name[0] == 'a'
183
			 && applet_name[6] == 'd'
184
			) {
184
			) {
185
				/* Add user to group */
185
				/* Add user to group */
186
				fprintf(new_fp, "%s%s%s\n", line,
186
				fprintf(new_fp, "%s%s%s\n", line,
Lines 245-251 Link Here
245
			bb_error_msg("can't find %s in %s", member, filename);
245
			bb_error_msg("can't find %s in %s", member, filename);
246
#endif
246
#endif
247
		if ((ENABLE_ADDUSER || ENABLE_ADDGROUP)
247
		if ((ENABLE_ADDUSER || ENABLE_ADDGROUP)
248
		 && applet_name[0] == 'a' && !member
248
		 && applet_name[6] == 'd' && !member
249
		) {
249
		) {
250
			/* add user or group */
250
			/* add user or group */
251
			fprintf(new_fp, "%s%s\n", name, new_passwd);
251
			fprintf(new_fp, "%s%s\n", name, new_passwd);
(-)busybox-1.15.3.old/libpwdgrp/pwd_grp.c (-10 / +9 lines)
Lines 51-57 Link Here
51
#if ENABLE_USE_BB_SHADOW
51
#if ENABLE_USE_BB_SHADOW
52
static int bb__parsespent(void *sp, char *line);
52
static int bb__parsespent(void *sp, char *line);
53
#endif
53
#endif
54
55
/**********************************************************************/
54
/**********************************************************************/
56
/* We avoid having big global data. */
55
/* We avoid having big global data. */
57
56
Lines 259-265 Link Here
259
#define GETXXKEY_R_ENTTYPE      struct passwd
258
#define GETXXKEY_R_ENTTYPE      struct passwd
260
#define GETXXKEY_R_TEST(ENT)    (!strcmp((ENT)->pw_name, key))
259
#define GETXXKEY_R_TEST(ENT)    (!strcmp((ENT)->pw_name, key))
261
#define GETXXKEY_R_KEYTYPE      const char *__restrict
260
#define GETXXKEY_R_KEYTYPE      const char *__restrict
262
#define GETXXKEY_R_PATHNAME     _PATH_PASSWD
261
#define GETXXKEY_R_PATHNAME     cross_path(_PATH_PASSWD)
263
#include "pwd_grp_internal.c"
262
#include "pwd_grp_internal.c"
264
263
265
#define GETXXKEY_R_FUNC         getgrnam_r
264
#define GETXXKEY_R_FUNC         getgrnam_r
Lines 267-273 Link Here
267
#define GETXXKEY_R_ENTTYPE      struct group
266
#define GETXXKEY_R_ENTTYPE      struct group
268
#define GETXXKEY_R_TEST(ENT)    (!strcmp((ENT)->gr_name, key))
267
#define GETXXKEY_R_TEST(ENT)    (!strcmp((ENT)->gr_name, key))
269
#define GETXXKEY_R_KEYTYPE      const char *__restrict
268
#define GETXXKEY_R_KEYTYPE      const char *__restrict
270
#define GETXXKEY_R_PATHNAME     _PATH_GROUP
269
#define GETXXKEY_R_PATHNAME     cross_path(_PATH_GROUP)
271
#include "pwd_grp_internal.c"
270
#include "pwd_grp_internal.c"
272
271
273
#if ENABLE_USE_BB_SHADOW
272
#if ENABLE_USE_BB_SHADOW
Lines 276-282 Link Here
276
#define GETXXKEY_R_ENTTYPE      struct spwd
275
#define GETXXKEY_R_ENTTYPE      struct spwd
277
#define GETXXKEY_R_TEST(ENT)    (!strcmp((ENT)->sp_namp, key))
276
#define GETXXKEY_R_TEST(ENT)    (!strcmp((ENT)->sp_namp, key))
278
#define GETXXKEY_R_KEYTYPE      const char *__restrict
277
#define GETXXKEY_R_KEYTYPE      const char *__restrict
279
#define GETXXKEY_R_PATHNAME     _PATH_SHADOW
278
#define GETXXKEY_R_PATHNAME     cross_path(_PATH_SHADOW)
280
#include "pwd_grp_internal.c"
279
#include "pwd_grp_internal.c"
281
#endif
280
#endif
282
281
Lines 285-291 Link Here
285
#define GETXXKEY_R_ENTTYPE      struct passwd
284
#define GETXXKEY_R_ENTTYPE      struct passwd
286
#define GETXXKEY_R_TEST(ENT)    ((ENT)->pw_uid == key)
285
#define GETXXKEY_R_TEST(ENT)    ((ENT)->pw_uid == key)
287
#define GETXXKEY_R_KEYTYPE      uid_t
286
#define GETXXKEY_R_KEYTYPE      uid_t
288
#define GETXXKEY_R_PATHNAME     _PATH_PASSWD
287
#define GETXXKEY_R_PATHNAME     cross_path(_PATH_PASSWD)
289
#include "pwd_grp_internal.c"
288
#include "pwd_grp_internal.c"
290
289
291
#define GETXXKEY_R_FUNC         getgrgid_r
290
#define GETXXKEY_R_FUNC         getgrgid_r
Lines 293-299 Link Here
293
#define GETXXKEY_R_ENTTYPE      struct group
292
#define GETXXKEY_R_ENTTYPE      struct group
294
#define GETXXKEY_R_TEST(ENT)    ((ENT)->gr_gid == key)
293
#define GETXXKEY_R_TEST(ENT)    ((ENT)->gr_gid == key)
295
#define GETXXKEY_R_KEYTYPE      gid_t
294
#define GETXXKEY_R_KEYTYPE      gid_t
296
#define GETXXKEY_R_PATHNAME     _PATH_GROUP
295
#define GETXXKEY_R_PATHNAME     cross_path(_PATH_GROUP)
297
#include "pwd_grp_internal.c"
296
#include "pwd_grp_internal.c"
298
297
299
/**********************************************************************/
298
/**********************************************************************/
Lines 466-472 Link Here
466
	*result = NULL;				/* In case of error... */
465
	*result = NULL;				/* In case of error... */
467
466
468
	if (!pwf) {
467
	if (!pwf) {
469
		pwf = fopen_for_read(_PATH_PASSWD);
468
		pwf = fopen_for_read(cross_path(_PATH_PASSWD));
470
		if (!pwf) {
469
		if (!pwf) {
471
			rv = errno;
470
			rv = errno;
472
			goto ERR;
471
			goto ERR;
Lines 513-519 Link Here
513
	*result = NULL;				/* In case of error... */
512
	*result = NULL;				/* In case of error... */
514
513
515
	if (!grf) {
514
	if (!grf) {
516
		grf = fopen_for_read(_PATH_GROUP);
515
		grf = fopen_for_read(cross_path(_PATH_GROUP));
517
		if (!grf) {
516
		if (!grf) {
518
			rv = errno;
517
			rv = errno;
519
			goto ERR;
518
			goto ERR;
Lines 560-566 Link Here
560
	*result = NULL;				/* In case of error... */
559
	*result = NULL;				/* In case of error... */
561
560
562
	if (!spf) {
561
	if (!spf) {
563
		spf = fopen_for_read(_PATH_SHADOW);
562
		spf = fopen_for_read(cross_path(_PATH_SHADOW));
564
		if (!spf) {
563
		if (!spf) {
565
			rv = errno;
564
			rv = errno;
566
			goto ERR;
565
			goto ERR;
Lines 635-641 Link Here
635
	group_list[0] = gid;
634
	group_list[0] = gid;
636
	ngroups = 1;
635
	ngroups = 1;
637
636
638
	grfile = fopen_for_read(_PATH_GROUP);
637
	grfile = fopen_for_read(cross_path(_PATH_GROUP));
639
	if (grfile) {
638
	if (grfile) {
640
		while (!bb__pgsreader(bb__parsegrent, &group, buff, sizeof(buff), grfile)) {
639
		while (!bb__pgsreader(bb__parsegrent, &group, buff, sizeof(buff), grfile)) {
641
			char **m;
640
			char **m;
(-)busybox-1.15.3.old/loginutils/addgroup.c (-6 / +6 lines)
Lines 74-80 Link Here
74
74
75
	/* add entry to group */
75
	/* add entry to group */
76
	p = xasprintf("x:%u:", (unsigned) gr.gr_gid);
76
	p = xasprintf("x:%u:", (unsigned) gr.gr_gid);
77
	if (update_passwd(bb_path_group_file, group, p, NULL) < 0)
77
	if (update_passwd(cross_path(bb_path_group_file), group, p, NULL) < 0)
78
		exit(EXIT_FAILURE);
78
		exit(EXIT_FAILURE);
79
	if (ENABLE_FEATURE_CLEAN_UP)
79
	if (ENABLE_FEATURE_CLEAN_UP)
80
		free(p);
80
		free(p);
Lines 95-108 Link Here
95
	 * 4. Group members (comma delimited list).
95
	 * 4. Group members (comma delimited list).
96
	 */
96
	 */
97
	/* Ignore errors: if file is missing we assume admin doesn't want it */
97
	/* Ignore errors: if file is missing we assume admin doesn't want it */
98
	update_passwd(bb_path_gshadow_file, group, "!::", NULL);
98
	update_passwd(cross_path(bb_path_gshadow_file), group, "!::", NULL);
99
#endif
99
#endif
100
}
100
}
101
101
102
#if ENABLE_FEATURE_ADDGROUP_LONG_OPTIONS
102
#if ENABLE_FEATURE_ADDGROUP_LONG_OPTIONS
103
static const char addgroup_longopts[] ALIGN1 =
103
static const char addgroup_longopts[] ALIGN1 =
104
		"gid\0"                 Required_argument "g"
104
		"gid\0"                 Required_argument "g"
105
		"system\0"              No_argument       "S"
105
		"system\0"              No_argument       "r"
106
		;
106
		;
107
#endif
107
#endif
108
108
Lines 132-138 Link Here
132
	 *  addgroup user group
132
	 *  addgroup user group
133
	 * Check for min, max and missing args */
133
	 * Check for min, max and missing args */
134
	opt_complementary = "-1:?2:g+";
134
	opt_complementary = "-1:?2:g+";
135
	opts = getopt32(argv, "g:S", &gid);
135
	opts = getopt32(argv, "g:r", &gid);
136
	/* move past the commandline options */
136
	/* move past the commandline options */
137
	argv += optind;
137
	argv += optind;
138
	//argc -= optind;
138
	//argc -= optind;
Lines 157-167 Link Here
157
				return EXIT_SUCCESS;
157
				return EXIT_SUCCESS;
158
			}
158
			}
159
		}
159
		}
160
		if (update_passwd(bb_path_group_file, argv[1], NULL, argv[0]) < 0) {
160
		if (update_passwd(cross_path(bb_path_group_file), argv[1], NULL, argv[0]) < 0) {
161
			return EXIT_FAILURE;
161
			return EXIT_FAILURE;
162
		}
162
		}
163
# if ENABLE_FEATURE_SHADOWPASSWDS
163
# if ENABLE_FEATURE_SHADOWPASSWDS
164
		update_passwd(bb_path_gshadow_file, argv[1], NULL, argv[0]);
164
		update_passwd(cross_path(bb_path_gshadow_file), argv[1], NULL, argv[0]);
165
# endif
165
# endif
166
	} else
166
	} else
167
#endif /* ENABLE_FEATURE_ADDUSER_TO_GROUP */
167
#endif /* ENABLE_FEATURE_ADDUSER_TO_GROUP */
(-)busybox-1.15.3.old/loginutils/adduser.c (-21 / +76 lines)
Lines 17-26 Link Here
17
/* #define OPT_GECOS          (1 << 1) */ /* unused */
17
/* #define OPT_GECOS          (1 << 1) */ /* unused */
18
#define OPT_SHELL          (1 << 2)
18
#define OPT_SHELL          (1 << 2)
19
#define OPT_GID            (1 << 3)
19
#define OPT_GID            (1 << 3)
20
#define OPT_DONT_SET_PASS  (1 << 4)
20
/* #define OPT_GROUPS         (1 << 4) */ /* unused */
21
#define OPT_SYSTEM_ACCOUNT (1 << 5)
21
#define OPT_SET_PASS  (1 << 5)
22
#define OPT_DONT_MAKE_HOME (1 << 6)
22
#define OPT_SYSTEM_ACCOUNT (1 << 6)
23
#define OPT_UID            (1 << 7)
23
#define OPT_MAKE_HOME (1 << 7)
24
#define OPT_UID            (1 << 8)
24
25
25
/* We assume UID_T_MAX == INT_MAX */
26
/* We assume UID_T_MAX == INT_MAX */
26
/* remix */
27
/* remix */
Lines 69-75 Link Here
69
{
70
{
70
	char *cmd;
71
	char *cmd;
71
72
72
	cmd = xasprintf("addgroup -g %u '%s'", (unsigned)p->pw_gid, p->pw_name);
73
	cmd = xasprintf("'%s' groupadd -g %u '%s'", bb_busybox_exec_path, (unsigned)p->pw_gid, p->pw_name);
74
	system(cmd);
75
	free(cmd);
76
}
77
78
static void addgroup_wrapper2(char * name, char * grp)
79
{
80
	char *cmd;
81
82
	cmd = xasprintf("'%s' groupadd '%s' '%s'", bb_busybox_exec_path, name, grp);
73
	system(cmd);
83
	system(cmd);
74
	free(cmd);
84
	free(cmd);
75
}
85
}
Lines 86-99 Link Here
86
96
87
#if ENABLE_FEATURE_ADDUSER_LONG_OPTIONS
97
#if ENABLE_FEATURE_ADDUSER_LONG_OPTIONS
88
static const char adduser_longopts[] ALIGN1 =
98
static const char adduser_longopts[] ALIGN1 =
89
		"home\0"                Required_argument "h"
99
		"home-dir\0"            Required_argument "d"
90
		"gecos\0"               Required_argument "g"
100
		"comment\0"             Required_argument "c"
91
		"shell\0"               Required_argument "s"
101
		"shell\0"               Required_argument "s"
92
		"ingroup\0"             Required_argument "G"
102
		"gid\0"                 Required_argument "g"
93
		"disabled-password\0"   No_argument       "D"
103
		"groups\0"              Required_argument "G"
94
		"empty-password\0"      No_argument       "D"
104
		"enable-password\0"     No_argument       "P"
95
		"system\0"              No_argument       "S"
105
		"system\0"              No_argument       "r"
96
		"no-create-home\0"      No_argument       "H"
106
		"create-home\0"         No_argument       "m"
97
		"uid\0"                 Required_argument "u"
107
		"uid\0"                 Required_argument "u"
98
		;
108
		;
99
#endif
109
#endif
Lines 108-115 Link Here
108
{
118
{
109
	struct passwd pw;
119
	struct passwd pw;
110
	const char *usegroup = NULL;
120
	const char *usegroup = NULL;
121
	const char *groups = NULL;
111
	char *p;
122
	char *p;
112
	unsigned opts;
123
	unsigned opts;
124
	char *groupsbuf = NULL;
125
	char **sup_grp = NULL;
126
	char *tmp_grp = NULL;
127
	int sup_num = 0;
113
128
114
#if ENABLE_FEATURE_ADDUSER_LONG_OPTIONS
129
#if ENABLE_FEATURE_ADDUSER_LONG_OPTIONS
115
	applet_long_options = adduser_longopts;
130
	applet_long_options = adduser_longopts;
Lines 120-137 Link Here
120
		bb_error_msg_and_die(bb_msg_perm_denied_are_you_root);
135
		bb_error_msg_and_die(bb_msg_perm_denied_are_you_root);
121
	}
136
	}
122
137
123
	pw.pw_gecos = (char *)"Linux User,,,";
138
	pw.pw_gecos = NULL;
124
	pw.pw_shell = (char *)DEFAULT_SHELL;
139
	pw.pw_shell = (char *)DEFAULT_SHELL;
125
	pw.pw_dir = NULL;
140
	pw.pw_dir = NULL;
126
141
127
	/* exactly one non-option arg */
142
	/* exactly one non-option arg */
128
	/* disable interactive passwd for system accounts */
143
	/* disable interactive passwd for system accounts */
129
	opt_complementary = "=1:SD:u+";
144
	opt_complementary = "=1:r-P:u+";
130
	if (sizeof(pw.pw_uid) == sizeof(int)) {
145
	if (sizeof(pw.pw_uid) == sizeof(int)) {
131
		opts = getopt32(argv, "h:g:s:G:DSHu:", &pw.pw_dir, &pw.pw_gecos, &pw.pw_shell, &usegroup, &pw.pw_uid);
146
		opts = getopt32(argv, "d:c:s:g:G:Prmu:", &pw.pw_dir, &pw.pw_gecos, &pw.pw_shell, &usegroup, &groups, &pw.pw_uid);
132
	} else {
147
	} else {
133
		unsigned uid;
148
		unsigned uid;
134
		opts = getopt32(argv, "h:g:s:G:DSHu:", &pw.pw_dir, &pw.pw_gecos, &pw.pw_shell, &usegroup, &uid);
149
		opts = getopt32(argv, "d:c:s:g:G:Prmu:", &pw.pw_dir, &pw.pw_gecos, &pw.pw_shell, &usegroup, &groups, &uid);
135
		if (opts & OPT_UID) {
150
		if (opts & OPT_UID) {
136
			pw.pw_uid = uid;
151
			pw.pw_uid = uid;
137
		}
152
		}
Lines 141-159 Link Here
141
	/* fill in the passwd struct */
155
	/* fill in the passwd struct */
142
	pw.pw_name = argv[0];
156
	pw.pw_name = argv[0];
143
	die_if_bad_username(pw.pw_name);
157
	die_if_bad_username(pw.pw_name);
158
	if (!pw.pw_gecos) {
159
		pw.pw_gecos = pw.pw_name;
160
	}
144
	if (!pw.pw_dir) {
161
	if (!pw.pw_dir) {
145
		/* create string for $HOME if not specified already */
162
		/* create string for $HOME if not specified already */
146
		pw.pw_dir = xasprintf("/home/%s", argv[0]);
163
		pw.pw_dir = xasprintf("/home/%s", argv[0]);
147
	}
164
	}
148
	pw.pw_passwd = (char *)"x";
165
	pw.pw_passwd = (char *)"x";
149
	if (opts & OPT_SYSTEM_ACCOUNT) {
166
	if (opts & OPT_SYSTEM_ACCOUNT) {
150
		if (!usegroup) {
167
		if (!usegroup && !groups) {
151
			usegroup = "nogroup";
168
			usegroup = "nogroup";
152
		}
169
		}
153
		if (!(opts & OPT_SHELL)) {
170
		if (!(opts & OPT_SHELL)) {
154
			pw.pw_shell = (char *) "/bin/false";
171
			pw.pw_shell = (char *) "/bin/false";
155
		}
172
		}
156
	}
173
	}
174
175
	if (groups) {
176
		groupsbuf = (char *) calloc(strlen(groups) + 1, sizeof(char));
177
		strcpy(groupsbuf, groups);
178
		for (tmp_grp = groupsbuf; (tmp_grp = strchr(&tmp_grp[1], ',')) != NULL; sup_num++);
179
		if (sup_num || usegroup) {
180
			if (usegroup)
181
				sup_num++;
182
			sup_grp = (char **) malloc(sizeof(char *) * sup_num);
183
			sup_num = 0;
184
			strtok((char * restrict) groupsbuf, ",");
185
			if (usegroup) {
186
				sup_grp[sup_num] = (const char *) groupsbuf;
187
				sup_num++;
188
			} else {
189
				usegroup = (const char *) groupsbuf;
190
			}
191
			while ((tmp_grp = (char *) strtok(NULL, ",")) != NULL) {
192
				sup_grp[sup_num] = (const char *) calloc(strlen(tmp_grp) + 1, sizeof(char));
193
				strcpy(sup_grp[sup_num], tmp_grp);
194
				sup_num++;
195
			}
196
		} else {
197
			usegroup = groups;
198
			groups = NULL;
199
			}
200
	}
201
	
157
	pw.pw_gid = usegroup ? xgroup2gid(usegroup) : -1; /* exits on failure */
202
	pw.pw_gid = usegroup ? xgroup2gid(usegroup) : -1; /* exits on failure */
158
203
159
	/* make sure everything is kosher and setup uid && maybe gid */
204
	/* make sure everything is kosher and setup uid && maybe gid */
Lines 162-168 Link Here
162
	p = xasprintf("x:%u:%u:%s:%s:%s",
208
	p = xasprintf("x:%u:%u:%s:%s:%s",
163
			(unsigned) pw.pw_uid, (unsigned) pw.pw_gid,
209
			(unsigned) pw.pw_uid, (unsigned) pw.pw_gid,
164
			pw.pw_gecos, pw.pw_dir, pw.pw_shell);
210
			pw.pw_gecos, pw.pw_dir, pw.pw_shell);
165
	if (update_passwd(bb_path_passwd_file, pw.pw_name, p, NULL) < 0) {
211
		if (update_passwd(cross_path(bb_path_passwd_file), pw.pw_name, p, NULL) < 0) {
166
		return EXIT_FAILURE;
212
		return EXIT_FAILURE;
167
	}
213
	}
168
	if (ENABLE_FEATURE_CLEAN_UP)
214
	if (ENABLE_FEATURE_CLEAN_UP)
Lines 182-188 Link Here
182
	/* fields:     2 3  4 5     6 78 */
228
	/* fields:     2 3  4 5     6 78 */
183
	p = xasprintf("!:%u:0:99999:7:::", (unsigned)(time(NULL)) / (24*60*60));
229
	p = xasprintf("!:%u:0:99999:7:::", (unsigned)(time(NULL)) / (24*60*60));
184
	/* ignore errors: if file is missing we suppose admin doesn't want it */
230
	/* ignore errors: if file is missing we suppose admin doesn't want it */
185
	update_passwd(bb_path_shadow_file, pw.pw_name, p, NULL);
231
	update_passwd(cross_path(bb_path_shadow_file), pw.pw_name, p, NULL);
186
	if (ENABLE_FEATURE_CLEAN_UP)
232
	if (ENABLE_FEATURE_CLEAN_UP)
187
		free(p);
233
		free(p);
188
#endif
234
#endif
Lines 192-202 Link Here
192
	/* if using a pre-existing group, don't create one */
238
	/* if using a pre-existing group, don't create one */
193
	if (!usegroup)
239
	if (!usegroup)
194
		addgroup_wrapper(&pw);
240
		addgroup_wrapper(&pw);
241
	
242
	if (groups) {
243
		do {
244
			sup_num--;
245
			addgroup_wrapper2(pw.pw_name, sup_grp[sup_num]);
246
			free(sup_grp[sup_num]);
247
		} while (sup_num > 0);
248
		free(sup_grp);
249
	}
195
250
196
	/* clear the umask for this process so it doesn't
251
	/* clear the umask for this process so it doesn't
197
	 * screw up the permissions on the mkdir and chown. */
252
	 * screw up the permissions on the mkdir and chown. */
198
	umask(0);
253
	umask(0);
199
	if (!(opts & OPT_DONT_MAKE_HOME)) {
254
	if (opts & OPT_MAKE_HOME) {
200
		/* set the owner and group so it is owned by the new user,
255
		/* set the owner and group so it is owned by the new user,
201
		 * then fix up the permissions to 2755. Can't do it before
256
		 * then fix up the permissions to 2755. Can't do it before
202
		 * since chown will clear the setgid bit */
257
		 * since chown will clear the setgid bit */
Lines 208-214 Link Here
208
		}
263
		}
209
	}
264
	}
210
265
211
	if (!(opts & OPT_DONT_SET_PASS)) {
266
	if (opts & OPT_SET_PASS) {
212
		/* interactively set passwd */
267
		/* interactively set passwd */
213
		passwd_wrapper(pw.pw_name);
268
		passwd_wrapper(pw.pw_name);
214
	}
269
	}
(-)busybox-1.15.3.old/loginutils/deluser.c (-4 / +4 lines)
Lines 39-56 Link Here
39
		if (ENABLE_DELUSER
39
		if (ENABLE_DELUSER
40
		 && (!ENABLE_DELGROUP || applet_name[3] == 'u')
40
		 && (!ENABLE_DELGROUP || applet_name[3] == 'u')
41
		) {
41
		) {
42
			if (del_line_matching(argv, bb_path_passwd_file) < 0)
42
			if (del_line_matching(argv, cross_path(bb_path_passwd_file)) < 0)
43
				return EXIT_FAILURE;
43
				return EXIT_FAILURE;
44
			if (ENABLE_FEATURE_SHADOWPASSWDS) {
44
			if (ENABLE_FEATURE_SHADOWPASSWDS) {
45
				del_line_matching(argv, bb_path_shadow_file);
45
				del_line_matching(argv, cross_path(bb_path_shadow_file));
46
			}
46
			}
47
		} else if (ENABLE_DESKTOP && ENABLE_DELGROUP && getpwnam(argv[1]))
47
		} else if (ENABLE_DESKTOP && ENABLE_DELGROUP && getpwnam(argv[1]))
48
			bb_error_msg_and_die("can't remove primary group of user %s", argv[1]);
48
			bb_error_msg_and_die("can't remove primary group of user %s", argv[1]);
49
	}
49
	}
50
	if (del_line_matching(argv, bb_path_group_file) < 0)
50
	if (del_line_matching(argv, cross_path(bb_path_group_file)) < 0)
51
		return EXIT_FAILURE;
51
		return EXIT_FAILURE;
52
	if (ENABLE_FEATURE_SHADOWPASSWDS) {
52
	if (ENABLE_FEATURE_SHADOWPASSWDS) {
53
		del_line_matching(argv, bb_path_gshadow_file);
53
		del_line_matching(argv, cross_path(bb_path_gshadow_file));
54
	}
54
	}
55
	return EXIT_SUCCESS;
55
	return EXIT_SUCCESS;
56
}
56
}
(-)busybox-1.15.3.old/loginutils/passwd.c (-6 / +6 lines)
Lines 132-139 Link Here
132
		 || !result || strcmp(result->sp_namp, pw->pw_name) != 0) {
132
		 || !result || strcmp(result->sp_namp, pw->pw_name) != 0) {
133
			/* LOGMODE_BOTH */
133
			/* LOGMODE_BOTH */
134
			bb_error_msg("no record of %s in %s, using %s",
134
			bb_error_msg("no record of %s in %s, using %s",
135
					name, bb_path_shadow_file,
135
					name, cross_path(bb_path_shadow_file),
136
					bb_path_passwd_file);
136
					cross_path(bb_path_passwd_file));
137
		} else {
137
		} else {
138
			pw->pw_passwd = result->sp_pwdp;
138
			pw->pw_passwd = result->sp_pwdp;
139
		}
139
		}
Lines 179-191 Link Here
179
	xsetuid(0);
179
	xsetuid(0);
180
180
181
#if ENABLE_FEATURE_SHADOWPASSWDS
181
#if ENABLE_FEATURE_SHADOWPASSWDS
182
	filename = bb_path_shadow_file;
182
	filename = cross_path(bb_path_shadow_file);
183
	rc = update_passwd(bb_path_shadow_file, name, newp, NULL);
183
	rc = update_passwd(cross_path(bb_path_shadow_file), name, newp, NULL);
184
	if (rc == 0) /* no lines updated, no errors detected */
184
	if (rc == 0) /* no lines updated, no errors detected */
185
#endif
185
#endif
186
	{
186
	{
187
		filename = bb_path_passwd_file;
187
		filename = cross_path(bb_path_passwd_file);
188
		rc = update_passwd(bb_path_passwd_file, name, newp, NULL);
188
		rc = update_passwd(cross_path(bb_path_passwd_file), name, newp, NULL);
189
	}
189
	}
190
	/* LOGMODE_BOTH */
190
	/* LOGMODE_BOTH */
191
	if (rc < 0)
191
	if (rc < 0)

Return to bug 302570