a7fe1d5bb55904d4c79638b8778bc9dd8ed7fd7bAndy Stormont * CDDL HEADER START
a7fe1d5bb55904d4c79638b8778bc9dd8ed7fd7bAndy Stormont * The contents of this file are subject to the terms of the
a7fe1d5bb55904d4c79638b8778bc9dd8ed7fd7bAndy Stormont * Common Development and Distribution License (the "License").
a7fe1d5bb55904d4c79638b8778bc9dd8ed7fd7bAndy Stormont * You may not use this file except in compliance with the License.
a7fe1d5bb55904d4c79638b8778bc9dd8ed7fd7bAndy Stormont * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
a7fe1d5bb55904d4c79638b8778bc9dd8ed7fd7bAndy Stormont * See the License for the specific language governing permissions
a7fe1d5bb55904d4c79638b8778bc9dd8ed7fd7bAndy Stormont * and limitations under the License.
a7fe1d5bb55904d4c79638b8778bc9dd8ed7fd7bAndy Stormont * When distributing Covered Code, include this CDDL HEADER in each
a7fe1d5bb55904d4c79638b8778bc9dd8ed7fd7bAndy Stormont * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
a7fe1d5bb55904d4c79638b8778bc9dd8ed7fd7bAndy Stormont * If applicable, add the following below this CDDL HEADER, with the
a7fe1d5bb55904d4c79638b8778bc9dd8ed7fd7bAndy Stormont * fields enclosed by brackets "[]" replaced with your own identifying
a7fe1d5bb55904d4c79638b8778bc9dd8ed7fd7bAndy Stormont * information: Portions Copyright [yyyy] [name of copyright owner]
a7fe1d5bb55904d4c79638b8778bc9dd8ed7fd7bAndy Stormont * CDDL HEADER END
a7fe1d5bb55904d4c79638b8778bc9dd8ed7fd7bAndy Stormont * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
a7fe1d5bb55904d4c79638b8778bc9dd8ed7fd7bAndy Stormont * Use is subject to license terms.
a7fe1d5bb55904d4c79638b8778bc9dd8ed7fd7bAndy Stormont/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
a7fe1d5bb55904d4c79638b8778bc9dd8ed7fd7bAndy Stormont/* All Rights Reserved */
a7fe1d5bb55904d4c79638b8778bc9dd8ed7fd7bAndy Stormont * Copyright (c) 2013 RackTop Systems.
a7fe1d5bb55904d4c79638b8778bc9dd8ed7fd7bAndy Stormontstatic int findunusedgid(gid_t start, gid_t stop, gid_t *ret);
a7fe1d5bb55904d4c79638b8778bc9dd8ed7fd7bAndy Stormont * Find the highest unused uid. If the highest unused gid is "stop",
a7fe1d5bb55904d4c79638b8778bc9dd8ed7fd7bAndy Stormont * then attempt to find a hole in the range. Returns 0 on success.
a7fe1d5bb55904d4c79638b8778bc9dd8ed7fd7bAndy Stormontfindnextgid(gid_t start, gid_t stop, gid_t *ret)
a7fe1d5bb55904d4c79638b8778bc9dd8ed7fd7bAndy Stormont for (grp = getgrent(); grp != NULL; grp = getgrent()) {
a7fe1d5bb55904d4c79638b8778bc9dd8ed7fd7bAndy Stormont if (isreservedgid(grp->gr_gid)) /* Skip reserved IDs */
a7fe1d5bb55904d4c79638b8778bc9dd8ed7fd7bAndy Stormont if (grp->gr_gid == stop) { /* Overflow check */
a7fe1d5bb55904d4c79638b8778bc9dd8ed7fd7bAndy Stormont while (isreservedgid(gid) && gid < stop) /* Skip reserved IDs */
a7fe1d5bb55904d4c79638b8778bc9dd8ed7fd7bAndy Stormont * Check to see whether the gid is a reserved gid
a7fe1d5bb55904d4c79638b8778bc9dd8ed7fd7bAndy Stormont * -- nobody, noaccess or nogroup
a7fe1d5bb55904d4c79638b8778bc9dd8ed7fd7bAndy Stormont return (gid == 60001 || gid == 60002 || gid == 65534);
a7fe1d5bb55904d4c79638b8778bc9dd8ed7fd7bAndy Stormont * findunusedgid() attempts to return the next valid usable id between the
a7fe1d5bb55904d4c79638b8778bc9dd8ed7fd7bAndy Stormont * supplied upper and lower limits. Returns 0 on success.