* libmisc/find_new_gid.c, libmisc/find_new_uid.c: For system

accounts, return the first unused ID, starting from the max value.
	This could be useful later to increase the static IDs range.
This commit is contained in:
nekral-guest
2009-04-11 16:00:45 +00:00
parent 8d136297c4
commit ca1bb50c24
4 changed files with 46 additions and 0 deletions

View File

@@ -110,6 +110,23 @@ int find_new_gid (bool sys_group, gid_t *gid, gid_t const *preferred_gid)
}
}
/* 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]) {
break;
}
}
if ( group_id < gid_min ) {
fprintf (stderr,
_("%s: Can't get unique GID (no more available GIDs)\n"),
Prog);
SYSLOG ((LOG_WARN,
"no more available GID on the system"));
return -1;
}
}
/*
* If a group with GID equal to GID_MAX exists, the above algorithm
* will give us GID_MAX+1 even if not unique. Search for the first