--- old/usr/src/Targetdirs	2013-09-09 17:55:47.142618986 +0100
+++ new/usr/src/Targetdirs	2013-09-09 17:55:47.149344316 +0100
@@ -24,6 +24,7 @@
 # Copyright 2011 Nexenta Systems, Inc. All rights reserved.
 # Copyright (c) 2012 by Delphix. All rights reserved.
 # Copyright 2012 OmniTI Computer Consulting, Inc.  All rights reserved.
+# Copyright (c) 2013 RackTop Systems.
 #
 
 #
@@ -144,6 +145,7 @@
 	/etc/saf \
 	/etc/sasl	\
 	/etc/sfw \
+	/etc/skel	\
 	/etc/svc \
 	/etc/svc/profile \
 	/etc/svc/profile/site \
--- old/usr/src/cmd/oamuser/group/Makefile	2013-09-09 17:55:47.985293140 +0100
+++ new/usr/src/cmd/oamuser/group/Makefile	2013-09-09 17:55:48.184256869 +0100
@@ -21,6 +21,8 @@
 # Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
 # Use is subject to license terms.
 #
+# Copyright (c) 2013 RackTop Systems.
+#
 # cmd/oamuser/group/Makefile
 #
 
@@ -34,7 +36,7 @@
 
 PROG=		$(SBINPROG)
 
-ADD_OBJ=	groupadd.o    add_group.o   gid.o       messages.o
+ADD_OBJ=	groupadd.o    add_group.o   messages.o
 DEL_OBJ=	groupdel.o    del_group.o   messages.o
 MOD_OBJ=	groupmod.o    mod_group.o   messages.o
 
@@ -50,11 +52,10 @@
 INSSBINPROG=	$(SBINPROG:%=$(ROOTUSRSBIN)/%)
 
 CPPFLAGS=	-I$(HERE) -I$(LOCAL) $(CPPFLAGS.master)
-CERRWARN +=	-_gcc=-Wno-type-limits
 FILEMODE= 	0555
 
 $(GROUPADD) :=	OBJS = $(ADD_OBJ)
-$(GROUPADD) :=	LDLIBS += $(LIBUSRGRP)
+$(GROUPADD) :=	LDLIBS += $(LIBUSRGRP) -lcmdutils
 
 $(GROUPDEL) :=	OBJS = $(DEL_OBJ)
 $(GROUPDEL) :=	LDLIBS += $(LIBUSRGRP)
--- old/usr/src/cmd/oamuser/group/gid.c	2013-09-09 17:55:48.712765874 +0100
+++ /dev/null	2013-09-09 17:53:37.000000000 +0100
@@ -1,109 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License (the "License").
- * You may not use this file except in compliance with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-/*
- * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
- * Use is subject to license terms.
- */
-/*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
-/*	  All Rights Reserved  	*/
-
-
-#pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.5 */
-
-#include <sys/types.h>
-#include <stdio.h>
-#include <userdefs.h>
-
-#include <sys/param.h>
-#ifndef	MAXUID
-#include <limits.h>
-#ifdef UID_MAX
-#define	MAXUID	UID_MAX
-#else
-#define	MAXUID	60000
-#endif
-#endif
-
-/*
- * Check to see that the gid is not a reserved gid
- * -- nobody, noaccess or nogroup
- */
-static int
-isvalidgid(gid_t gid)
-{
-	return (gid != 60001 && gid != 60002 && gid != 65534);
-}
-
-gid_t
-findnextgid()
-{
-	FILE *fptr;
-	gid_t last, next;
-	gid_t gid;
-
-	/*
-	 * Sort the used GIDs in decreasing order to return MAXUSED + 1
-	 */
-	if ((fptr = popen("exec sh -c "
-	    "\"getent group|cut -f3 -d:|sort -nr|uniq \" 2>/dev/null",
-	    "r")) == NULL)
-		return (-1);
-
-	if (fscanf(fptr, "%u\n", &next) == EOF) {
-		(void) pclose(fptr);
-		return (DEFRID + 1);
-	}
-
-	/*
-	 * 'next' is now the highest allocated gid.
-	 *
-	 * The simplest allocation is where we just add one, and obtain
-	 * a valid gid.  If this fails look for a hole in the gid range ..
-	 */
-
-	last = MAXUID;		/* upper limit */
-	gid = -1;		/* start invalid */
-	do {
-		if (!isvalidgid(next))
-			continue;
-
-		if (next <= DEFRID) {
-			if (last != DEFRID + 1)
-				gid = DEFRID + 1;
-			break;
-		}
-
-		if ((gid = next + 1) != last) {
-			while (!isvalidgid(gid))
-				gid++;
-			if (gid > 0 && gid < last)
-				break;
-		}
-
-		gid = -1;
-		last = next;
-
-	} while (fscanf(fptr, "%u\n", &next) != EOF);
-
-	(void) pclose(fptr);
-
-	return (gid);
-}
--- /dev/null	2013-09-09 17:53:37.000000000 +0100
+++ new/usr/src/lib/libcmdutils/common/gid.c	2013-09-09 17:55:49.010819192 +0100
@@ -0,0 +1,111 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License (the "License").
+ * You may not use this file except in compliance with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
+/*	  All Rights Reserved  	*/
+
+/*
+ * Copyright (c) 2013 RackTop Systems.
+ */
+
+#include <errno.h>
+#include <sys/types.h>
+#include <stdio.h>
+#include <userdefs.h>
+#include <grp.h>
+#include <libcmdutils.h>
+
+static int findunusedgid(gid_t start, gid_t stop, gid_t *ret);
+static boolean_t isreservedgid(gid_t gid);
+
+/*
+ * Find the highest unused uid. If the highest unused gid is "stop",
+ * then attempt to find a hole in the range. Returns 0 on success.
+ */
+int
+findnextgid(gid_t start, gid_t stop, gid_t *ret)
+{
+	gid_t gid = start;
+	struct group *grp;
+	boolean_t overflow = B_FALSE;
+
+	setgrent();
+	for (grp = getgrent(); grp != NULL; grp = getgrent()) {
+		if (isreservedgid(grp->gr_gid))		/* Skip reserved IDs */
+			continue;
+		if (grp->gr_gid >= gid) {
+			if (grp->gr_gid == stop) {	/* Overflow check */
+				overflow = B_TRUE;
+				break;
+			}
+			gid = grp->gr_gid + 1;
+		}
+	}
+	if (grp == NULL && errno != 0) {
+		endgrent();
+		return (-1);
+	}
+	endgrent();
+	if (overflow == B_TRUE)				/* Find a hole */
+		return (findunusedgid(start, stop, ret));
+	while (isreservedgid(gid) && gid < stop)	/* Skip reserved IDs */
+		gid++;
+	*ret = gid;
+	return (0);
+}
+
+/*
+ * Check to see whether the gid is a reserved gid
+ * -- nobody, noaccess or nogroup
+ */
+static boolean_t
+isreservedgid(gid_t gid)
+{
+	return (gid == 60001 || gid == 60002 || gid == 65534);
+}
+
+/*
+ * findunusedgid() attempts to return the next valid usable id between the
+ * supplied upper and lower limits. Returns 0 on success.
+ */
+static int
+findunusedgid(gid_t start, gid_t stop, gid_t *ret)
+{
+	gid_t gid;
+
+	for (gid = start; gid <= stop; gid++) {
+		if (isreservedgid(gid))
+			continue;
+		if (getgrgid(gid) == NULL) {
+			if (errno != 0)
+				return (-1);
+			break;
+		}
+	}
+	if (gid > stop)
+		return (-1);
+	*ret = gid;
+	return (0);
+}
--- old/usr/src/cmd/oamuser/group/groupadd.c	2013-09-09 17:55:49.454790956 +0100
+++ new/usr/src/cmd/oamuser/group/groupadd.c	2013-09-09 17:55:49.460897879 +0100
@@ -27,10 +27,12 @@
 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
 /*	  All Rights Reserved  	*/
 
-
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
+/*
+ * Copyright (c) 2013 RackTop Systems.
+ */
 
 #include	<sys/types.h>
+#include	<sys/param.h>
 #include	<stdio.h>
 #include	<stdlib.h>
 #include	<ctype.h>
@@ -38,10 +40,10 @@
 #include	<userdefs.h>
 #include	<users.h>
 #include	<errno.h>
+#include	<libcmdutils.h>
 #include	"messages.h"
 
 extern int errmsg();
-extern gid_t findnextgid();
 extern int valid_gid(), add_group();
 
 /*
@@ -136,7 +138,7 @@
 
 	} else {
 
-		if ((gid = findnextgid()) < 0) {
+		if (findnextgid(DEFRID+1, MAXUID, &gid) != 0) {
 			errmsg(M_GID_INVALID, "default id");
 			exit(EX_ID_EXISTS);
 		}
--- old/usr/src/cmd/oamuser/user/Makefile	2013-09-09 17:55:50.080940809 +0100
+++ new/usr/src/cmd/oamuser/user/Makefile	2013-09-09 17:55:50.090406635 +0100
@@ -20,6 +20,7 @@
 #
 #
 # Copyright (c) 1990, 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2013 RackTop Systems.
 #
 # cmd/oamuser/user/Makefile
 #
@@ -42,17 +43,17 @@
 PROG=		$(SBINPROG)
 PRODUCT=	$(PROG)
 
-ADD_OBJ=	useradd.o     uid.o        homedir.o \
-		groups.o      call_pass.o      userdefs.o   messages.o \
-		val_lgrp.o    funcs.o	       val_lprj.o   proj.o
+ADD_OBJ=	useradd.o     homedir.o        groups.o     call_pass.o \
+		userdefs.o    messages.o       val_lgrp.o   funcs.o \
+		val_lprj.o    proj.o
 
 DEL_OBJ=	userdel.o     call_pass.o      rmfiles.o    isbusy.o \
 		groups.o      messages.o       funcs.o      proj.o
 
-MOD_OBJ=	usermod.o     uid.o            movedir.o    groups.o \
-		rmfiles.o     call_pass.o      isbusy.o     homedir.o \
-		userdefs.o    messages.o       val_lgrp.o   funcs.o \
-		val_lprj.o    proj.o
+MOD_OBJ=	usermod.o     movedir.o        groups.o     rmfiles.o \
+		call_pass.o   isbusy.o         homedir.o    userdefs.o \
+		messages.o    val_lgrp.o       funcs.o      val_lprj.o \
+		proj.o
 
 OBJECTS=	$(ADD_OBJ)     $(DEL_OBJ)    $(MOD_OBJ)
 
@@ -71,9 +72,6 @@
 
 CPPFLAGS=	-I$(HERE) -I$(LOCAL) $(CPPFLAGS.master)
 CERRWARN +=	-_gcc=-Wno-implicit-function-declaration
-CERRWARN +=	-_gcc=-Wno-type-limits
-CERRWARN +=	-_gcc=-Wno-uninitialized
-CERRWARN +=	-_gcc=-Wno-parentheses
 
 $(INSSBINPROG)  := FILEMODE = 0555
 $(INSSYSADMPROG):= FILEMODE = 0500
@@ -81,6 +79,7 @@
 
 $(USERADD) :=	OBJS = $(ADD_OBJ)
 $(USERADD) :=	LIBS = $(LIBUSRGRP)
+$(USERADD) :=	LDLIBS += -lcmdutils
 
 $(USERDEL) :=	OBJS = $(DEL_OBJ)
 $(USERDEL) :=	LIBS = $(LIBUSRGRP)
--- old/usr/src/cmd/oamuser/user/funcs.c	2013-09-09 17:55:50.419235493 +0100
+++ new/usr/src/cmd/oamuser/user/funcs.c	2013-09-09 17:55:50.425809125 +0100
@@ -20,6 +20,7 @@
  */
 /*
  * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013 RackTop Systems.
  */
 
 #include <stdio.h>
@@ -180,11 +181,12 @@
 	int i;
 
 	for (i = 0; i < NKEYS; i++)
-		if (strcmp(keys[i].key, key) == 0)
+		if (strcmp(keys[i].key, key) == 0) {
 			if (keys[i].newvalue != NULL)
 				return (keys[i].newvalue);
 			else
 				return (keys[i].newvalue = dflt);
+		}
 	return (NULL);
 }
 
@@ -194,7 +196,7 @@
 	static char usertype[MAX_TYPE_LENGTH];
 	char *cmd;
 
-	if (cmd = strrchr(cmdname, '/'))
+	if ((cmd = strrchr(cmdname, '/')))
 		++cmd;
 	else
 		cmd = cmdname;
--- old/usr/src/cmd/oamuser/user/useradd.c	2013-09-09 17:55:51.281103828 +0100
+++ new/usr/src/cmd/oamuser/user/useradd.c	2013-09-09 17:55:51.289108955 +0100
@@ -26,6 +26,9 @@
 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
 /*	  All Rights Reserved  	*/
 
+/*
+ * Copyright (c) 2013 RackTop Systems.
+ */
 
 #include	<sys/types.h>
 #include	<sys/stat.h>
@@ -40,6 +43,7 @@
 #include	<project.h>
 #include	<unistd.h>
 #include	<user_attr.h>
+#include	<libcmdutils.h>
 #include	"users.h"
 #include	"messages.h"
 #include	"userdisp.h"
@@ -82,7 +86,6 @@
 
 static void cleanup();
 
-extern uid_t findnextuid(void);
 extern int check_perm(), valid_expire();
 extern int putusrdef(), valid_uid();
 extern int call_passmgmt(), edit_group(), create_home();
@@ -132,8 +135,8 @@
 int argc;
 char *argv[];
 {
-	int ch, ret, mflag = 0, oflag = 0, Dflag = 0, **gidlist;
-	projid_t **projlist;
+	int ch, ret, mflag = 0, oflag = 0, Dflag = 0, **gidlist = NULL;
+	projid_t **projlist = NULL;
 	char *ptr;			/* loc in a str, may be set by strtol */
 	struct group *g_ptr;
 	struct project p_ptr;
@@ -425,7 +428,7 @@
 
 	} else {
 
-		if ((uid = findnextuid()) < 0) {
+		if (findnextuid(DEFRID+1, MAXUID, &uid) != 0) {
 			errmsg(M_INVALID, "default id", "user id");
 			exit(EX_ID_EXISTS);
 		}
@@ -634,7 +637,7 @@
 				errmsg(M_UID_USED, uid);
 				exit(EX_ID_EXISTS);
 			} else {
-				if ((uid = findnextuid()) < 0) {
+				if (findnextuid(DEFRID+1, MAXUID, &uid) != 0) {
 					errmsg(M_INVALID, "default id",
 					    "user id");
 					exit(EX_ID_EXISTS);
--- old/usr/src/cmd/oamuser/user/userdefs.c	2013-09-09 17:55:52.085777245 +0100
+++ new/usr/src/cmd/oamuser/user/userdefs.c	2013-09-09 17:55:52.092242476 +0100
@@ -28,8 +28,9 @@
 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
 /*	  All Rights Reserved  	*/
 
-
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
+/*
+ * Copyright (c) 2013 RackTop Systems.
+ */
 
 /*LINTLIBRARY*/
 
@@ -54,7 +55,7 @@
 		(void) fprintf(fptr, "\n"); \
 	}
 
-#define	SKIPWS(ptr)	while (*ptr && *ptr == ' ' || *ptr == '\t') ptr++
+#define	SKIPWS(ptr)	while (*ptr && (*ptr == ' ' || *ptr == '\t')) ptr++
 
 static char *dup_to_nl(char *);
 
--- old/usr/src/cmd/oamuser/user/usermod.c	2013-09-09 17:55:52.807600610 +0100
+++ new/usr/src/cmd/oamuser/user/usermod.c	2013-09-09 17:55:52.814151883 +0100
@@ -26,7 +26,9 @@
 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
 /*	  All Rights Reserved  	*/
 
-
+/*
+ * Copyright (c) 2013 RackTop Systems.
+ */
 
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -510,12 +512,13 @@
 		}
 	}
 
-	if (comment)
+	if (comment) {
 		/* ignore comment if comment is not changed */
 		if (strcmp(pstruct->pw_comment, comment))
 			call_pass = 1;
 		else
 			comment = NULL;
+	}
 
 	/* inactive string is a positive integer */
 	if (inactstr) {
--- old/usr/src/cmd/oamuser/user/val_lgrp.c	2013-09-09 17:55:53.438119099 +0100
+++ new/usr/src/cmd/oamuser/user/val_lgrp.c	2013-09-09 17:55:53.444576718 +0100
@@ -26,6 +26,10 @@
 /*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
 /*	  All Rights Reserved  	*/
 
+/*
+ * Copyright (c) 2013 RackTop Systems.
+ */
+
 
 #include	<sys/types.h>
 #include	<stdio.h>
@@ -60,7 +64,7 @@
 		grplist = malloc((ngroups_max + 1) * sizeof (gid_t));
 	}
 
-	while (ptr = strtok(((i || n_invalid || dup_prim)? NULL: list), ",")) {
+	while ((ptr = strtok((i || n_invalid || dup_prim)? NULL: list, ","))) {
 
 		switch (valid_group(ptr, &g_ptr, &warning)) {
 		case INVALID:
--- old/usr/src/cmd/oamuser/user/val_lprj.c	2013-09-09 17:55:54.193308771 +0100
+++ new/usr/src/cmd/oamuser/user/val_lprj.c	2013-09-09 17:55:54.199732976 +0100
@@ -24,7 +24,9 @@
  * Use is subject to license terms.
  */
 
-#pragma ident	"%Z%%M%	%I%	%E% SMI"
+/*
+ * Copyright (c) 2013 RackTop Systems.
+ */
 
 #include	<sys/types.h>
 #include	<stdio.h>
@@ -55,7 +57,7 @@
 	if (!list || !*list)
 		return ((int **)NULL);
 
-	while (ptr = strtok(((i || n_invalid) ? NULL : list), ",")) {
+	while ((ptr = strtok((i || n_invalid) ? NULL : list, ","))) {
 
 		switch (valid_project(ptr, &projent, mybuf, sizeof (mybuf),
 		    &warning)) {
--- old/usr/src/lib/libcmdutils/Makefile.com	2013-09-09 17:55:55.026245198 +0100
+++ new/usr/src/lib/libcmdutils/Makefile.com	2013-09-09 17:55:55.293207762 +0100
@@ -20,11 +20,12 @@
 #
 #
 # Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2013 RackTop Systems.
 #
 
 LIBRARY=	libcmdutils.a
 VERS=		.1
-CMD_OBJS=	avltree.o sysattrs.o writefile.o process_xattrs.o
+CMD_OBJS=	avltree.o sysattrs.o writefile.o process_xattrs.o uid.o gid.o
 COM_OBJS=	list.o
 OBJECTS=	$(CMD_OBJS) $(COM_OBJS)
 
--- old/usr/src/lib/libcmdutils/common/mapfile-vers	2013-09-09 17:55:56.292239730 +0100
+++ new/usr/src/lib/libcmdutils/common/mapfile-vers	2013-09-09 17:55:56.300667995 +0100
@@ -20,6 +20,7 @@
 #
 #
 # Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved.
+# Copyright (c) 2013 RackTop Systems.
 #
 
 #
@@ -42,6 +43,8 @@
     global:
 	add_tnode;
 	destroy_tree;
+	findnextgid;
+	findnextuid;
 	list_create;
 	list_destroy;
 	list_head;
--- old/usr/src/cmd/oamuser/user/uid.c	2013-09-09 17:55:56.892221477 +0100
+++ /dev/null	2013-09-09 17:53:37.000000000 +0100
@@ -1,118 +0,0 @@
-/*
- * CDDL HEADER START
- *
- * The contents of this file are subject to the terms of the
- * Common Development and Distribution License, Version 1.0 only
- * (the "License").  You may not use this file except in compliance
- * with the License.
- *
- * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
- * or http://www.opensolaris.org/os/licensing.
- * See the License for the specific language governing permissions
- * and limitations under the License.
- *
- * When distributing Covered Code, include this CDDL HEADER in each
- * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
- * If applicable, add the following below this CDDL HEADER, with the
- * fields enclosed by brackets "[]" replaced with your own identifying
- * information: Portions Copyright [yyyy] [name of copyright owner]
- *
- * CDDL HEADER END
- */
-/*
- * Copyright (c) 1997-2001 by Sun Microsystems, Inc.
- * All rights reserved.
- */
-
-/*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
-/*	  All Rights Reserved  	*/
-
-
-#pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 1.5 */
-
-#include <sys/types.h>
-#include <stdio.h>
-#include <userdefs.h>
-#include <pwd.h>
-
-#include <sys/param.h>
-#ifndef	MAXUID
-#include <limits.h>
-#ifdef UID_MAX
-#define	MAXUID	UID_MAX
-#else
-#define	MAXUID	60000
-#endif
-#endif
-
-static uid_t getrangeboundid(uid_t start, uid_t stop);
-static int isreserveduid(uid_t uid);
-
-/*
- * Find the highest uid currently in use and return it. If the highest unused
- * uid is MAXUID, then attempt to find a hole in the range. If there are no
- * more unused uids, then return -1.
- */
-uid_t
-findnextuid(void)
-{
-	uid_t uid = DEFRID + 1;
-	struct passwd *pwd;
-	uchar_t overflow = 0;
-
-	setpwent();
-	for (pwd = getpwent(); pwd != NULL; pwd = getpwent()) {
-		if (isreserveduid(pwd->pw_uid))		/* Skip reserved IDs */
-			continue;
-		if (pwd->pw_uid >= uid) {
-			if (pwd->pw_uid == MAXUID) {	/* Overflow check */
-				overflow = 1;
-				break;
-			}
-			uid = pwd->pw_uid + 1;
-			while (isreserveduid(uid) &&
-			    uid < MAXUID) {		/* Skip reserved IDs */
-				uid++;
-			}
-		}
-	}
-	endpwent();
-	if (overflow == 1)				/* Find a hole */
-		return (getrangeboundid(DEFRID + 1, MAXUID));
-	return (uid);
-}
-
-/*
- * Check to see that the uid is a reserved uid
- * -- nobody, noaccess or nobody4
- */
-static int
-isreserveduid(uid_t uid)
-{
-	return (uid == 60001 || uid == 60002 || uid == 65534);
-}
-
-
-/*
- * getrangeboundid() attempts to return the next valid usable id between the
- * supplied upper and lower limits. If these limits exceed the system
- * boundaries of DEFRID +1 and MAXUID (lower and upper bound respectively),
- * then they are ignored and DEFRID + 1 and MAXUID are used.
- *
- * Returns a valid uid_t between DEFRID +1 and MAXUID, -1 is returned on fail
- */
-static uid_t
-getrangeboundid(uid_t start, uid_t stop)
-{
-	uid_t low = (start <= DEFRID) ? DEFRID + 1 : start;
-	uid_t high = (stop < MAXUID) ? stop : MAXUID;
-	uid_t uid;
-
-	for (uid = low; uid <= high; uid++) {
-		if (isreserveduid(uid))
-			continue;
-		if (getpwuid(uid) == NULL)
-			break;
-	}
-	return ((uid > high) ? -1 : uid);
-}
--- /dev/null	2013-09-09 17:53:37.000000000 +0100
+++ new/usr/src/lib/libcmdutils/common/uid.c	2013-09-09 17:55:56.913178469 +0100
@@ -0,0 +1,112 @@
+/*
+ * CDDL HEADER START
+ *
+ * The contents of this file are subject to the terms of the
+ * Common Development and Distribution License, Version 1.0 only
+ * (the "License").  You may not use this file except in compliance
+ * with the License.
+ *
+ * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
+ * or http://www.opensolaris.org/os/licensing.
+ * See the License for the specific language governing permissions
+ * and limitations under the License.
+ *
+ * When distributing Covered Code, include this CDDL HEADER in each
+ * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
+ * If applicable, add the following below this CDDL HEADER, with the
+ * fields enclosed by brackets "[]" replaced with your own identifying
+ * information: Portions Copyright [yyyy] [name of copyright owner]
+ *
+ * CDDL HEADER END
+ */
+/*
+ * Copyright (c) 1997-2001 by Sun Microsystems, Inc.
+ * All rights reserved.
+ */
+
+/*	Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T	*/
+/*	  All Rights Reserved  	*/
+
+/*
+ * Copyright (c) 2013 RackTop Systems.
+ */
+
+#include <errno.h>
+#include <sys/types.h>
+#include <stdio.h>
+#include <userdefs.h>
+#include <pwd.h>
+#include <libcmdutils.h>
+
+static int findunuseduid(uid_t start, uid_t stop, uid_t *ret);
+static boolean_t isreserveduid(uid_t uid);
+
+/*
+ * Find the highest unused uid. If the highest unused uid is "stop",
+ * then attempt to find a hole in the range. Returns 0 on success.
+ */
+int
+findnextuid(uid_t start, uid_t stop, uid_t *ret)
+{
+	uid_t uid = start;
+	struct passwd *pwd;
+	boolean_t overflow = B_FALSE;
+
+	setpwent();
+	for (pwd = getpwent(); pwd != NULL; pwd = getpwent()) {
+		if (isreserveduid(pwd->pw_uid))		/* Skip reserved IDs */
+			continue;
+		if (pwd->pw_uid >= uid) {
+			if (pwd->pw_uid == stop) {	/* Overflow check */
+				overflow = B_TRUE;
+				break;
+			}
+			uid = pwd->pw_uid + 1;
+		}
+	}
+	if (pwd == NULL && errno != 0) {
+		endpwent();
+		return (-1);
+	}
+	endpwent();
+	if (overflow == B_TRUE)				/* Find a hole */
+		return (findunuseduid(start, stop, ret));
+	while (isreserveduid(uid) && uid < stop)	/* Skip reserved IDs */
+		uid++;
+	*ret = uid;
+	return (0);
+}
+
+/*
+ * Check to see whether the uid is a reserved uid
+ * -- nobody, noaccess or nobody4
+ */
+static boolean_t
+isreserveduid(uid_t uid)
+{
+	return (uid == 60001 || uid == 60002 || uid == 65534);
+}
+
+/*
+ * findunuseduid() attempts to return the next valid usable id between the
+ * supplied upper and lower limits. Returns 0 on success.
+ */
+static int
+findunuseduid(uid_t start, uid_t stop, uid_t *ret)
+{
+	uid_t uid;
+
+	for (uid = start; uid <= stop; uid++) {
+		if (isreserveduid(uid))
+			continue;
+		if (getpwuid(uid) == NULL) {
+			if (errno != 0)
+				return (-1);
+			break;
+		}
+	}
+	if (uid > stop)
+		return (-1);
+	*ret = uid;
+	return (0);
+}
--- old/usr/src/lib/libcmdutils/libcmdutils.h	2013-09-09 17:55:58.167036173 +0100
+++ new/usr/src/lib/libcmdutils/libcmdutils.h	2013-09-09 17:55:58.173204778 +0100
@@ -22,6 +22,9 @@
  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
  * Use is subject to license terms.
  */
+/*
+ * Copyright (c) 2013 RackTop Systems.
+ */
 
 /*
  * Declarations for the functions in libcmdutils.
@@ -125,6 +128,20 @@
  */
 extern void destroy_tree(avl_tree_t *);
 
+
+
+		/* user/group id helpers */
+
+/*
+ * Used to get the next available user id in given range.
+ */
+extern int findnextuid(uid_t, uid_t, uid_t *);
+
+/*
+ * Used to get the next available group id in given range.
+ */
+extern int findnextgid(gid_t, gid_t, gid_t *);
+
 #ifdef	__cplusplus
 }
 #endif
--- old/usr/src/lib/smbsrv/libsmb/common/smb_lgrp.c	2013-09-09 17:55:58.904139960 +0100
+++ new/usr/src/lib/smbsrv/libsmb/common/smb_lgrp.c	2013-09-09 17:55:58.912843047 +0100
@@ -22,6 +22,7 @@
 /*
  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
  * Copyright (c) 2008, 2010, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013 RackTop Systems.
  */
 
 #include <stdlib.h>
@@ -38,6 +39,7 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/param.h>
+#include <libcmdutils.h>
 
 /*
  * Local domain SID (aka machine SID) is not stored in the domain table
@@ -123,7 +125,7 @@
 #define	SMB_LGRP_PGRP_GRPBUFSIZ	5120
 #define	SMB_LGRP_PGRP_GROUP	"/etc/group"
 #define	SMB_LGRP_PGRP_MAXGLEN	9	/* max length of group name */
-#define	SMB_LGRP_PGRP_DEFRID	99	/* max reserved id */
+#define	SMB_LGRP_PGRP_DEFRID	1000	/* lowest cifs created gid */
 
 #define	SMB_LGRP_PGRP_NOTUNIQUE	0
 #define	SMB_LGRP_PGRP_RESERVED	1
@@ -2545,70 +2547,6 @@
 }
 
 /*
- * smb_lgrp_pgrp_valid_gid
- *
- * Check to see that the gid is not a reserved gid
- * -- nobody (60001), noaccess (60002) or nogroup (65534)
- */
-static int
-smb_lgrp_pgrp_valid_gid(gid_t gid)
-{
-	return (gid != 60001 && gid != 60002 && gid != 65534);
-}
-
-/*
- * smb_lgrp_pgrp_findnextgid(void)
- *
- * This method finds the next valid GID.
- * It sorts the used GIDs in decreasing order to return MAXUSED + 1.
- * It then adds one to obtain the next valid GID.
- * On failure, -1 is returned. On success, a valid GID is returned.
- */
-static int
-smb_lgrp_pgrp_findnextgid(void)
-{
-	FILE *fptr;
-	gid_t last, next;
-	int gid;
-
-	if ((fptr = popen("exec sh -c "
-	    "\"getent group|cut -f3 -d:|sort -nr|uniq \" 2>/dev/null",
-	    "r")) == NULL)
-		return (-1);
-
-	if (fscanf(fptr, "%u\n", &next) == EOF) {
-		(void) pclose(fptr);
-		return (SMB_LGRP_PGRP_DEFRID + 1);
-	}
-
-	last = MAXUID;
-	gid = -1;
-	do {
-		if (!smb_lgrp_pgrp_valid_gid(next))
-			continue;
-
-		if (next <= SMB_LGRP_PGRP_DEFRID) {
-			if (last != SMB_LGRP_PGRP_DEFRID + 1)
-				gid = SMB_LGRP_PGRP_DEFRID + 1;
-			break;
-		}
-
-		if ((gid = next + 1) != last) {
-			while (!smb_lgrp_pgrp_valid_gid((gid_t)gid))
-				gid++;
-			if (gid > 0 && gid < last)
-				break;
-		}
-
-		gid = -1;
-		last = next;
-	} while (fscanf(fptr, "%u\n", &next) != EOF);
-
-	(void) pclose(fptr);
-	return (gid);
-}
-
-/*
  * smb_lgrp_pgrp_add
  *
  * Create a posix group with the given name.
@@ -2619,7 +2557,7 @@
 {
 	FILE *etcgrp;
 	FILE *etctmp;
-	int o_mask, gret;
+	int o_mask;
 	int newdone = 0;
 	struct stat sb;
 	char buf[SMB_LGRP_PGRP_GRPBUFSIZ];
@@ -2630,9 +2568,8 @@
 	if ((rc == SMB_LGRP_PGRP_INVALID) || (rc == SMB_LGRP_PGRP_NOTUNIQUE))
 		return (-1);
 
-	if ((gret = smb_lgrp_pgrp_findnextgid()) < 0)
+	if ((findnextgid(SMB_LGRP_PGRP_DEFRID, MAXUID, &gid)) != 0)
 		return (-1);
-	gid = gret;
 
 	if ((etcgrp = fopen(SMB_LGRP_PGRP_GROUP, "r")) == NULL)
 		return (-1);
