* libmisc/find_new_gid.c: Use booleans instead of char fo

used_gids.
	* libmisc/find_new_gid.c: Use getdef_ulong and cast to git_t to
	get GID values.
	* libmisc/find_new_gid.c: Use UL as a prefix for ulong values.
	* libmisc/find_new_uid.c: Likewise.
This commit is contained in:
nekral-guest 2009-04-23 11:16:38 +00:00
parent cbd90eed74
commit b0db85bc04
3 changed files with 33 additions and 24 deletions

View File

@ -1,3 +1,12 @@
2009-04-22 Nicolas François <nicolas.francois@centraliens.net>
* libmisc/find_new_gid.c: Use booleans instead of char fo
used_gids.
* libmisc/find_new_gid.c: Use getdef_ulong and cast to git_t to
get GID values.
* libmisc/find_new_gid.c: Use UL as a prefix for ulong values.
* libmisc/find_new_uid.c: Likewise.
2009-04-22 Nicolas François <nicolas.francois@centraliens.net>
* libmisc/yesno.c: Ignore the return value of puts.

View File

@ -51,20 +51,20 @@ int find_new_gid (bool sys_group, gid_t *gid, gid_t const *preferred_gid)
{
const struct group *grp;
gid_t gid_min, gid_max, group_id;
char *used_gids;
bool *used_gids;
assert (gid != NULL);
if (!sys_group) {
gid_min = getdef_ulong ("GID_MIN", 1000L);
gid_max = getdef_ulong ("GID_MAX", 60000L);
gid_min = (gid_t) getdef_ulong ("GID_MIN", 1000UL);
gid_max = (gid_t) getdef_ulong ("GID_MAX", 60000UL);
} else {
gid_min = getdef_ulong ("SYS_GID_MIN", 1L);
gid_max = getdef_ulong ("GID_MIN", 1000L) - 1;
gid_max = getdef_ulong ("SYS_GID_MAX", (unsigned long) gid_max);
gid_min = (gid_t) getdef_ulong ("SYS_GID_MIN", 1UL);
gid_max = (gid_t) getdef_ulong ("GID_MIN", 1000UL) - 1;
gid_max = (gid_t) getdef_ulong ("SYS_GID_MAX", (unsigned long) gid_max);
}
used_gids = alloca (sizeof (char) * gid_max +1);
memset (used_gids, 0, sizeof (char) * gid_max + 1);
used_gids = alloca (sizeof (bool) * (gid_max +1));
memset (used_gids, false, sizeof (bool) * (gid_max + 1));
if ( (NULL != preferred_gid)
&& (*preferred_gid >= gid_min)
@ -95,7 +95,7 @@ int find_new_gid (bool sys_group, gid_t *gid, gid_t const *preferred_gid)
}
/* create index of used GIDs */
if (grp->gr_gid <= gid_max) {
used_gids[grp->gr_gid] = 1;
used_gids[grp->gr_gid] = true;
}
}
endgrent ();
@ -106,14 +106,14 @@ int find_new_gid (bool sys_group, gid_t *gid, gid_t const *preferred_gid)
}
/* create index of used GIDs */
if (grp->gr_gid <= gid_max) {
used_gids[grp->gr_gid] = 1;
used_gids[grp->gr_gid] = true;
}
}
/* find free system account in reverse order */
if (sys_group) {
for (group_id = gid_max; group_id >= gid_min; group_id--) {
if (0 == used_gids[group_id]) {
if (false == used_gids[group_id]) {
break;
}
}
@ -134,7 +134,7 @@ int find_new_gid (bool sys_group, gid_t *gid, gid_t const *preferred_gid)
*/
if (group_id == gid_max + 1) {
for (group_id = gid_min; group_id < gid_max; group_id++) {
if (0 == used_gids[group_id]) {
if (false == used_gids[group_id]) {
break;
}
}

View File

@ -51,20 +51,20 @@ int find_new_uid (bool sys_user, uid_t *uid, uid_t const *preferred_uid)
{
const struct passwd *pwd;
uid_t uid_min, uid_max, user_id;
char *used_uids;
bool *used_uids;
assert (uid != NULL);
if (!sys_user) {
uid_min = getdef_ulong ("UID_MIN", 1000L);
uid_max = getdef_ulong ("UID_MAX", 60000L);
uid_min = (uid_t) getdef_ulong ("UID_MIN", 1000UL);
uid_max = (uid_t) getdef_ulong ("UID_MAX", 60000UL);
} else {
uid_min = getdef_ulong ("SYS_UID_MIN", 1L);
uid_max = getdef_ulong ("UID_MIN", 1000L) - 1;
uid_max = getdef_ulong ("SYS_UID_MAX", (unsigned long) uid_max);
uid_min = (uid_t) getdef_ulong ("SYS_UID_MIN", 1UL);
uid_max = (uid_t) getdef_ulong ("UID_MIN", 1000UL) - 1;
uid_max = (uid_t) getdef_ulong ("SYS_UID_MAX", (unsigned long) uid_max);
}
used_uids = alloca (sizeof (char) * uid_max +1);
memset (used_uids, 0, sizeof (char) * uid_max + 1);
used_uids = alloca (sizeof (bool) * (uid_max +1));
memset (used_uids, false, sizeof (bool) * (uid_max + 1));
if ( (NULL != preferred_uid)
&& (*preferred_uid >= uid_min)
@ -96,7 +96,7 @@ int find_new_uid (bool sys_user, uid_t *uid, uid_t const *preferred_uid)
}
/* create index of used UIDs */
if (pwd->pw_uid <= uid_max) {
used_uids[pwd->pw_uid] = 1;
used_uids[pwd->pw_uid] = true;
}
}
endpwent ();
@ -107,14 +107,14 @@ int find_new_uid (bool sys_user, uid_t *uid, uid_t const *preferred_uid)
}
/* create index of used UIDs */
if (pwd->pw_uid <= uid_max) {
used_uids[pwd->pw_uid] = 1;
used_uids[pwd->pw_uid] = true;
}
}
/* find free system account in reverse order */
if (sys_user) {
for (user_id = uid_max; user_id >= uid_min; user_id--) {
if (0 == used_uids[user_id]) {
if (false == used_uids[user_id]) {
break;
}
}
@ -135,7 +135,7 @@ int find_new_uid (bool sys_user, uid_t *uid, uid_t const *preferred_uid)
*/
if (user_id == uid_max + 1) {
for (user_id = uid_min; user_id < uid_max; user_id++) {
if (0 == used_uids[user_id]) {
if (false == used_uids[user_id]) {
break;
}
}