diff options
author | Andy Stormont <astormont@racktopsystems.com> | 2013-09-09 17:14:48 +0100 |
---|---|---|
committer | Robert Mustacchi <rm@joyent.com> | 2013-09-13 17:04:07 -0700 |
commit | a7fe1d5bb55904d4c79638b8778bc9dd8ed7fd7b (patch) | |
tree | 81fa5ca69f00db5d053c62e908b2c6edbf50d58e /usr/src | |
parent | 41599e9fdccb44cc5f17828ab04b3147cefcc4e0 (diff) | |
download | illumos-joyent-a7fe1d5bb55904d4c79638b8778bc9dd8ed7fd7b.tar.gz |
4078 groupadd execs getent unnecessarily
4127 dmake setup could create /etc/skel
Reviewed by: Rich Lowe <richlowe@richlowe.net>
Reviewed by: Gary Mills <gary_mills@fastmail.fm>
Reviewed by: Milan Jurik <milan.jurik@xylab.cz>
Reviewed by: Gordon Ross <gwr@nexenta.com>
Approved by: Robert Mustacchi <rm@joyent.com>
Diffstat (limited to 'usr/src')
-rw-r--r-- | usr/src/Targetdirs | 2 | ||||
-rw-r--r-- | usr/src/cmd/oamuser/group/Makefile | 7 | ||||
-rw-r--r-- | usr/src/cmd/oamuser/group/gid.c | 109 | ||||
-rw-r--r-- | usr/src/cmd/oamuser/group/groupadd.c | 10 | ||||
-rw-r--r-- | usr/src/cmd/oamuser/user/Makefile | 19 | ||||
-rw-r--r-- | usr/src/cmd/oamuser/user/funcs.c | 6 | ||||
-rw-r--r-- | usr/src/cmd/oamuser/user/useradd.c | 13 | ||||
-rw-r--r-- | usr/src/cmd/oamuser/user/userdefs.c | 7 | ||||
-rw-r--r-- | usr/src/cmd/oamuser/user/usermod.c | 7 | ||||
-rw-r--r-- | usr/src/cmd/oamuser/user/val_lgrp.c | 6 | ||||
-rw-r--r-- | usr/src/cmd/oamuser/user/val_lprj.c | 6 | ||||
-rw-r--r-- | usr/src/lib/libcmdutils/Makefile.com | 3 | ||||
-rw-r--r-- | usr/src/lib/libcmdutils/common/gid.c | 111 | ||||
-rw-r--r-- | usr/src/lib/libcmdutils/common/mapfile-vers | 3 | ||||
-rw-r--r-- | usr/src/lib/libcmdutils/common/uid.c (renamed from usr/src/cmd/oamuser/user/uid.c) | 86 | ||||
-rw-r--r-- | usr/src/lib/libcmdutils/libcmdutils.h | 19 | ||||
-rw-r--r-- | usr/src/lib/smbsrv/libsmb/Makefile.com | 2 | ||||
-rw-r--r-- | usr/src/lib/smbsrv/libsmb/common/smb_lgrp.c | 73 |
18 files changed, 231 insertions, 258 deletions
diff --git a/usr/src/Targetdirs b/usr/src/Targetdirs index 968e76d15f..485ded568b 100644 --- a/usr/src/Targetdirs +++ b/usr/src/Targetdirs @@ -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 @@ DIRS= \ /etc/saf \ /etc/sasl \ /etc/sfw \ + /etc/skel \ /etc/svc \ /etc/svc/profile \ /etc/svc/profile/site \ diff --git a/usr/src/cmd/oamuser/group/Makefile b/usr/src/cmd/oamuser/group/Makefile index 438890f14b..8289dbda77 100644 --- a/usr/src/cmd/oamuser/group/Makefile +++ b/usr/src/cmd/oamuser/group/Makefile @@ -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 @@ SBINPROG= $(GROUPADD) $(GROUPDEL) $(GROUPMOD) 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 @@ LINTFLAGS= -u 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) diff --git a/usr/src/cmd/oamuser/group/gid.c b/usr/src/cmd/oamuser/group/gid.c deleted file mode 100644 index 51f3a67242..0000000000 --- a/usr/src/cmd/oamuser/group/gid.c +++ /dev/null @@ -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); -} diff --git a/usr/src/cmd/oamuser/group/groupadd.c b/usr/src/cmd/oamuser/group/groupadd.c index 8f6b924280..a4084f7c83 100644 --- a/usr/src/cmd/oamuser/group/groupadd.c +++ b/usr/src/cmd/oamuser/group/groupadd.c @@ -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 @@ main(int argc, char *argv[]) } else { - if ((gid = findnextgid()) < 0) { + if (findnextgid(DEFRID+1, MAXUID, &gid) != 0) { errmsg(M_GID_INVALID, "default id"); exit(EX_ID_EXISTS); } diff --git a/usr/src/cmd/oamuser/user/Makefile b/usr/src/cmd/oamuser/user/Makefile index 6d3266c508..9542a967f0 100644 --- a/usr/src/cmd/oamuser/user/Makefile +++ b/usr/src/cmd/oamuser/user/Makefile @@ -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 @@ SBINPROG= $(USERADD) $(USERDEL) $(USERMOD) 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 @@ INSSKELFILE= $(SKELFILE:%=$(ROOTSKEL)/%) 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 @@ $(INSSKELFILE) := FILEMODE = 0644 $(USERADD) := OBJS = $(ADD_OBJ) $(USERADD) := LIBS = $(LIBUSRGRP) +$(USERADD) := LDLIBS += -lcmdutils $(USERDEL) := OBJS = $(DEL_OBJ) $(USERDEL) := LIBS = $(LIBUSRGRP) diff --git a/usr/src/cmd/oamuser/user/funcs.c b/usr/src/cmd/oamuser/user/funcs.c index 12e9000741..93f6b458d5 100644 --- a/usr/src/cmd/oamuser/user/funcs.c +++ b/usr/src/cmd/oamuser/user/funcs.c @@ -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 @@ getsetdefval(const char *key, char *dflt) 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 @@ getusertype(char *cmdname) static char usertype[MAX_TYPE_LENGTH]; char *cmd; - if (cmd = strrchr(cmdname, '/')) + if ((cmd = strrchr(cmdname, '/'))) ++cmd; else cmd = cmdname; diff --git a/usr/src/cmd/oamuser/user/useradd.c b/usr/src/cmd/oamuser/user/useradd.c index 1b42e22a27..afb3b17411 100644 --- a/usr/src/cmd/oamuser/user/useradd.c +++ b/usr/src/cmd/oamuser/user/useradd.c @@ -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 @@ extern void dispusrdef(); 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 @@ main(argc, argv) 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 @@ char *argv[]; } 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 @@ char *argv[]; 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); diff --git a/usr/src/cmd/oamuser/user/userdefs.c b/usr/src/cmd/oamuser/user/userdefs.c index 4487e2f16d..5845179d77 100644 --- a/usr/src/cmd/oamuser/user/userdefs.c +++ b/usr/src/cmd/oamuser/user/userdefs.c @@ -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 *); diff --git a/usr/src/cmd/oamuser/user/usermod.c b/usr/src/cmd/oamuser/user/usermod.c index f1d19acdb1..99f58ca7cd 100644 --- a/usr/src/cmd/oamuser/user/usermod.c +++ b/usr/src/cmd/oamuser/user/usermod.c @@ -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 @@ char **argv; } } - 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) { diff --git a/usr/src/cmd/oamuser/user/val_lgrp.c b/usr/src/cmd/oamuser/user/val_lgrp.c index 2ad9d38efb..160087f32a 100644 --- a/usr/src/cmd/oamuser/user/val_lgrp.c +++ b/usr/src/cmd/oamuser/user/val_lgrp.c @@ -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 @@ valid_lgroup(char *list, gid_t gid) 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: diff --git a/usr/src/cmd/oamuser/user/val_lprj.c b/usr/src/cmd/oamuser/user/val_lprj.c index 95b084e9bc..4463ac7f41 100644 --- a/usr/src/cmd/oamuser/user/val_lprj.c +++ b/usr/src/cmd/oamuser/user/val_lprj.c @@ -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 @@ valid_lproject(char *list) 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)) { diff --git a/usr/src/lib/libcmdutils/Makefile.com b/usr/src/lib/libcmdutils/Makefile.com index 7961146e1a..2f98fe5f25 100644 --- a/usr/src/lib/libcmdutils/Makefile.com +++ b/usr/src/lib/libcmdutils/Makefile.com @@ -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) diff --git a/usr/src/lib/libcmdutils/common/gid.c b/usr/src/lib/libcmdutils/common/gid.c new file mode 100644 index 0000000000..63456810ea --- /dev/null +++ b/usr/src/lib/libcmdutils/common/gid.c @@ -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); +} diff --git a/usr/src/lib/libcmdutils/common/mapfile-vers b/usr/src/lib/libcmdutils/common/mapfile-vers index 74f59e8fdb..e4c5940c31 100644 --- a/usr/src/lib/libcmdutils/common/mapfile-vers +++ b/usr/src/lib/libcmdutils/common/mapfile-vers @@ -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 @@ SYMBOL_VERSION SUNWprivate_1.1 { global: add_tnode; destroy_tree; + findnextgid; + findnextuid; list_create; list_destroy; list_head; diff --git a/usr/src/cmd/oamuser/user/uid.c b/usr/src/lib/libcmdutils/common/uid.c index dea5318fc4..a5ca6c45bd 100644 --- a/usr/src/cmd/oamuser/user/uid.c +++ b/usr/src/lib/libcmdutils/common/uid.c @@ -27,92 +27,86 @@ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ +/* + * Copyright (c) 2013 RackTop Systems. + */ -#pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.5 */ - +#include <errno.h> #include <sys/types.h> #include <stdio.h> #include <userdefs.h> #include <pwd.h> +#include <libcmdutils.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); +static int findunuseduid(uid_t start, uid_t stop, uid_t *ret); +static boolean_t 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. + * 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. */ -uid_t -findnextuid(void) +int +findnextuid(uid_t start, uid_t stop, uid_t *ret) { - uid_t uid = DEFRID + 1; + uid_t uid = start; struct passwd *pwd; - uchar_t overflow = 0; + 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 == MAXUID) { /* Overflow check */ - overflow = 1; + if (pwd->pw_uid == stop) { /* Overflow check */ + overflow = B_TRUE; break; } uid = pwd->pw_uid + 1; - while (isreserveduid(uid) && - uid < MAXUID) { /* Skip reserved IDs */ - uid++; - } } } + if (pwd == NULL && errno != 0) { + endpwent(); + return (-1); + } endpwent(); - if (overflow == 1) /* Find a hole */ - return (getrangeboundid(DEFRID + 1, MAXUID)); - return (uid); + 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 that the uid is a reserved uid + * Check to see whether the uid is a reserved uid * -- nobody, noaccess or nobody4 */ -static int +static boolean_t 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 + * findunuseduid() attempts to return the next valid usable id between the + * supplied upper and lower limits. Returns 0 on success. */ -static uid_t -getrangeboundid(uid_t start, uid_t stop) +static int +findunuseduid(uid_t start, uid_t stop, uid_t *ret) { - uid_t low = (start <= DEFRID) ? DEFRID + 1 : start; - uid_t high = (stop < MAXUID) ? stop : MAXUID; uid_t uid; - for (uid = low; uid <= high; uid++) { + for (uid = start; uid <= stop; uid++) { if (isreserveduid(uid)) continue; - if (getpwuid(uid) == NULL) + if (getpwuid(uid) == NULL) { + if (errno != 0) + return (-1); break; + } } - return ((uid > high) ? -1 : uid); + if (uid > stop) + return (-1); + *ret = uid; + return (0); } diff --git a/usr/src/lib/libcmdutils/libcmdutils.h b/usr/src/lib/libcmdutils/libcmdutils.h index d1c3a0b193..c315e0fbef 100644 --- a/usr/src/lib/libcmdutils/libcmdutils.h +++ b/usr/src/lib/libcmdutils/libcmdutils.h @@ -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. @@ -30,8 +33,6 @@ #ifndef _LIBCMDUTILS_H #define _LIBCMDUTILS_H -#pragma ident "%Z%%M% %I% %E% SMI" - /* * This is a private header file. Applications should not directly include * this file. @@ -125,6 +126,20 @@ extern int add_tnode(avl_tree_t **, dev_t, ino_t); */ 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 diff --git a/usr/src/lib/smbsrv/libsmb/Makefile.com b/usr/src/lib/smbsrv/libsmb/Makefile.com index 4b86caeb95..dbf479e106 100644 --- a/usr/src/lib/smbsrv/libsmb/Makefile.com +++ b/usr/src/lib/smbsrv/libsmb/Makefile.com @@ -73,6 +73,8 @@ include ../../Makefile.lib INCS += -I$(SRC)/common/smbsrv +LINTCHECKFLAGS += -erroff=E_INCONS_ARG_DECL2 + LDLIBS += $(MACH_LDLIBS) LDLIBS += -lscf -lmd -luuid -lnsl -lpkcs11 -lsec -lsocket -lresolv LDLIBS += -lidmap -lreparse -lnvpair -lcmdutils -lavl -lc diff --git a/usr/src/lib/smbsrv/libsmb/common/smb_lgrp.c b/usr/src/lib/smbsrv/libsmb/common/smb_lgrp.c index 406d7c5db0..3cab135341 100644 --- a/usr/src/lib/smbsrv/libsmb/common/smb_lgrp.c +++ b/usr/src/lib/smbsrv/libsmb/common/smb_lgrp.c @@ -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_gname(char *group) } /* - * 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 @@ smb_lgrp_pgrp_add(char *group) { 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 @@ smb_lgrp_pgrp_add(char *group) 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); |