adduser,addgroup: introduce and use CONFIG_LAST_ID
Changes adduser.c, addgroup.c and Config.src to set and use CONFIG_LAST_ID. function old new delta adduser_main 841 865 +24 addgroup_main 407 425 +18 Signed-off-by: Tito Ragusa <farmatito@tiscali.it> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
2e66daca65
commit
891b98c9bc
@ -118,10 +118,17 @@ config FEATURE_CHECK_NAMES
|
|||||||
For compatibility with Samba machine accounts "$" is also supported
|
For compatibility with Samba machine accounts "$" is also supported
|
||||||
at the end of the user or group name.
|
at the end of the user or group name.
|
||||||
|
|
||||||
|
config LAST_ID
|
||||||
|
int "Last valid uid or gid for adduser and addgroup"
|
||||||
|
depends on ADDUSER || ADDGROUP
|
||||||
|
default 60000
|
||||||
|
help
|
||||||
|
Last valid uid or gid for adduser and addgroup
|
||||||
|
|
||||||
config FIRST_SYSTEM_ID
|
config FIRST_SYSTEM_ID
|
||||||
int "First valid system uid or gid for adduser and addgroup"
|
int "First valid system uid or gid for adduser and addgroup"
|
||||||
depends on ADDUSER || ADDGROUP
|
depends on ADDUSER || ADDGROUP
|
||||||
range 0 64900
|
range 0 LAST_ID
|
||||||
default 100
|
default 100
|
||||||
help
|
help
|
||||||
First valid system uid or gid for adduser and addgroup
|
First valid system uid or gid for adduser and addgroup
|
||||||
@ -129,7 +136,7 @@ config FIRST_SYSTEM_ID
|
|||||||
config LAST_SYSTEM_ID
|
config LAST_SYSTEM_ID
|
||||||
int "Last valid system uid or gid for adduser and addgroup"
|
int "Last valid system uid or gid for adduser and addgroup"
|
||||||
depends on ADDUSER || ADDGROUP
|
depends on ADDUSER || ADDGROUP
|
||||||
range 0 64900
|
range FIRST_SYSTEM_ID LAST_ID
|
||||||
default 999
|
default 999
|
||||||
help
|
help
|
||||||
Last valid system uid or gid for adduser and addgroup
|
Last valid system uid or gid for adduser and addgroup
|
||||||
|
@ -22,14 +22,16 @@
|
|||||||
#if CONFIG_LAST_SYSTEM_ID < CONFIG_FIRST_SYSTEM_ID
|
#if CONFIG_LAST_SYSTEM_ID < CONFIG_FIRST_SYSTEM_ID
|
||||||
#error Bad LAST_SYSTEM_ID or FIRST_SYSTEM_ID in .config
|
#error Bad LAST_SYSTEM_ID or FIRST_SYSTEM_ID in .config
|
||||||
#endif
|
#endif
|
||||||
|
#if CONFIG_LAST_ID < CONFIG_LAST_SYSTEM_ID
|
||||||
|
#error Bad LAST_ID or LAST_SYSTEM_ID in .config
|
||||||
|
#endif
|
||||||
|
|
||||||
#define OPT_GID (1 << 0)
|
#define OPT_GID (1 << 0)
|
||||||
#define OPT_SYSTEM_ACCOUNT (1 << 1)
|
#define OPT_SYSTEM_ACCOUNT (1 << 1)
|
||||||
|
|
||||||
/* We assume GID_T_MAX == INT_MAX */
|
|
||||||
static void xgroup_study(struct group *g)
|
static void xgroup_study(struct group *g)
|
||||||
{
|
{
|
||||||
unsigned max = INT_MAX;
|
unsigned max = CONFIG_LAST_ID;
|
||||||
|
|
||||||
/* Make sure gr_name is unused */
|
/* Make sure gr_name is unused */
|
||||||
if (getgrnam(g->gr_name)) {
|
if (getgrnam(g->gr_name)) {
|
||||||
@ -46,7 +48,6 @@ static void xgroup_study(struct group *g)
|
|||||||
max = CONFIG_LAST_SYSTEM_ID;
|
max = CONFIG_LAST_SYSTEM_ID;
|
||||||
} else {
|
} else {
|
||||||
g->gr_gid = CONFIG_LAST_SYSTEM_ID + 1;
|
g->gr_gid = CONFIG_LAST_SYSTEM_ID + 1;
|
||||||
max = 64999;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* Check if the desired gid is free
|
/* Check if the desired gid is free
|
||||||
@ -125,7 +126,7 @@ int addgroup_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
|||||||
int addgroup_main(int argc UNUSED_PARAM, char **argv)
|
int addgroup_main(int argc UNUSED_PARAM, char **argv)
|
||||||
{
|
{
|
||||||
unsigned opts;
|
unsigned opts;
|
||||||
unsigned gid = 0;
|
const char *gid = "0";
|
||||||
|
|
||||||
/* need to be root */
|
/* need to be root */
|
||||||
if (geteuid()) {
|
if (geteuid()) {
|
||||||
@ -139,7 +140,7 @@ int addgroup_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
* addgroup -g num group
|
* addgroup -g num group
|
||||||
* addgroup user group
|
* addgroup user group
|
||||||
* Check for min, max and missing args */
|
* Check for min, max and missing args */
|
||||||
opt_complementary = "-1:?2:g+";
|
opt_complementary = "-1:?2";
|
||||||
opts = getopt32(argv, "g:S", &gid);
|
opts = getopt32(argv, "g:S", &gid);
|
||||||
/* move past the commandline options */
|
/* move past the commandline options */
|
||||||
argv += optind;
|
argv += optind;
|
||||||
@ -175,7 +176,7 @@ int addgroup_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
#endif /* ENABLE_FEATURE_ADDUSER_TO_GROUP */
|
#endif /* ENABLE_FEATURE_ADDUSER_TO_GROUP */
|
||||||
{
|
{
|
||||||
die_if_bad_username(argv[0]);
|
die_if_bad_username(argv[0]);
|
||||||
new_group(argv[0], gid);
|
new_group(argv[0], xatou_range(gid, 0, CONFIG_LAST_ID));
|
||||||
}
|
}
|
||||||
/* Reached only on success */
|
/* Reached only on success */
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
@ -26,6 +26,10 @@
|
|||||||
#if CONFIG_LAST_SYSTEM_ID < CONFIG_FIRST_SYSTEM_ID
|
#if CONFIG_LAST_SYSTEM_ID < CONFIG_FIRST_SYSTEM_ID
|
||||||
#error Bad LAST_SYSTEM_ID or FIRST_SYSTEM_ID in .config
|
#error Bad LAST_SYSTEM_ID or FIRST_SYSTEM_ID in .config
|
||||||
#endif
|
#endif
|
||||||
|
#if CONFIG_LAST_ID < CONFIG_LAST_SYSTEM_ID
|
||||||
|
#error Bad LAST_ID or LAST_SYSTEM_ID in .config
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* #define OPT_HOME (1 << 0) */ /* unused */
|
/* #define OPT_HOME (1 << 0) */ /* unused */
|
||||||
/* #define OPT_GECOS (1 << 1) */ /* unused */
|
/* #define OPT_GECOS (1 << 1) */ /* unused */
|
||||||
@ -36,12 +40,11 @@
|
|||||||
#define OPT_DONT_MAKE_HOME (1 << 6)
|
#define OPT_DONT_MAKE_HOME (1 << 6)
|
||||||
#define OPT_UID (1 << 7)
|
#define OPT_UID (1 << 7)
|
||||||
|
|
||||||
/* We assume UID_T_MAX == INT_MAX */
|
|
||||||
/* remix */
|
/* remix */
|
||||||
/* recoded such that the uid may be passed in *p */
|
/* recoded such that the uid may be passed in *p */
|
||||||
static void passwd_study(struct passwd *p)
|
static void passwd_study(struct passwd *p)
|
||||||
{
|
{
|
||||||
int max = UINT_MAX;
|
int max = CONFIG_LAST_ID;
|
||||||
|
|
||||||
if (getpwnam(p->pw_name)) {
|
if (getpwnam(p->pw_name)) {
|
||||||
bb_error_msg_and_die("%s '%s' in use", "user", p->pw_name);
|
bb_error_msg_and_die("%s '%s' in use", "user", p->pw_name);
|
||||||
@ -54,7 +57,6 @@ static void passwd_study(struct passwd *p)
|
|||||||
max = CONFIG_LAST_SYSTEM_ID;
|
max = CONFIG_LAST_SYSTEM_ID;
|
||||||
} else {
|
} else {
|
||||||
p->pw_uid = CONFIG_LAST_SYSTEM_ID + 1;
|
p->pw_uid = CONFIG_LAST_SYSTEM_ID + 1;
|
||||||
max = 64999;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/* check for a free uid (and maybe gid) */
|
/* check for a free uid (and maybe gid) */
|
||||||
@ -147,6 +149,7 @@ int adduser_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
const char *usegroup = NULL;
|
const char *usegroup = NULL;
|
||||||
char *p;
|
char *p;
|
||||||
unsigned opts;
|
unsigned opts;
|
||||||
|
char *uid;
|
||||||
|
|
||||||
#if ENABLE_FEATURE_ADDUSER_LONG_OPTIONS
|
#if ENABLE_FEATURE_ADDUSER_LONG_OPTIONS
|
||||||
applet_long_options = adduser_longopts;
|
applet_long_options = adduser_longopts;
|
||||||
@ -164,16 +167,11 @@ int adduser_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
|
|
||||||
/* at least one and at most two non-option args */
|
/* at least one and at most two non-option args */
|
||||||
/* disable interactive passwd for system accounts */
|
/* disable interactive passwd for system accounts */
|
||||||
opt_complementary = "-1:?2:SD:u+";
|
opt_complementary = "-1:?2:SD";
|
||||||
if (sizeof(pw.pw_uid) == sizeof(int)) {
|
|
||||||
opts = getopt32(argv, "h:g:s:G:DSHu:", &pw.pw_dir, &pw.pw_gecos, &pw.pw_shell, &usegroup, &pw.pw_uid);
|
|
||||||
} else {
|
|
||||||
unsigned uid;
|
|
||||||
opts = getopt32(argv, "h:g:s:G:DSHu:", &pw.pw_dir, &pw.pw_gecos, &pw.pw_shell, &usegroup, &uid);
|
opts = getopt32(argv, "h:g:s:G:DSHu:", &pw.pw_dir, &pw.pw_gecos, &pw.pw_shell, &usegroup, &uid);
|
||||||
if (opts & OPT_UID) {
|
if (opts & OPT_UID)
|
||||||
pw.pw_uid = uid;
|
pw.pw_uid = xatou_range(uid, 0, CONFIG_LAST_ID);
|
||||||
}
|
|
||||||
}
|
|
||||||
argv += optind;
|
argv += optind;
|
||||||
pw.pw_name = argv[0];
|
pw.pw_name = argv[0];
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user