# # 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 2009 Sun Microsystems, Inc. All rights reserved. # Use is subject to license terms. # # Copyright (c) 2018, Joyent, Inc. LIBRARY= lib.a DATEFILE= ugdates DATEFILESRC= ugdates.dat TXT= $(DATEFILESRC) OBJECTS= putgrent.o \ errmsg.o \ file.o \ vgid.o \ vgname.o \ vgroup.o \ vuid.o \ vlogin.o \ vproj.o \ dates.o \ vexpire.o \ putprojent.o \ vprojid.o \ vprojname.o # include library definitions include ../../Makefile.cmd include ../../../lib/Makefile.lib SRCDIR = . FILEMODE= $(LIBFILEMODE) PRODUCT= $(LIBRARY) $(DATEFILE) # Must retain `lib', since default expands to nothing LLINTLIB= llib-l$(LIBRARY:lib%.a=lib).ln CLEANFILES= $(LLINTLIB) CLOBBERFILES= $(DATEFILE) GENERAL= ../inc CPPFLAGS= -I. -I$(GENERAL) $(CPPFLAGS.master) CERRWARN += -Wno-parentheses CERRWARN += -Wno-type-limits CERRWARN += -Wno-unused-variable # not linted SMATCH=off ARFLAGS= cr AROBJS= `$(LORDER) $(OBJS) | $(TSORT)` LINTFLAGS= -u CLOBBERFILES += $(LIBRARY) .KEEP_STATE: all: $(PRODUCT) $(TXT) $(DATEFILE): $(DATEFILESRC) $(GREP) -v "^#ident" $(DATEFILESRC) > $(DATEFILE) install: all lint: $(LLINTLIB) $(LLINTLIB): $(SRCS) $(LINT.c) -o $(LIBRARY:lib%.a=lib) $(SRCS) > $(LINTOUT) 2>&1 include ../../../lib/Makefile.targ /* * 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 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ #include extern int putenv(); static int mask_defined = 0; static char *dmaskpath = "DATEMSK=/etc/datemsk"; /* Parse a date string and return time_t value */ time_t p_getdate( string ) char *string; { struct tm *tmptr, *getdate(); time_t rtime; if ( !mask_defined ) { if ( putenv( dmaskpath ) != 0 ) return( (time_t) 0 ); mask_defined = 1; } if( !(tmptr = getdate( string )) ) return( (time_t) 0 ); if ( (rtime = mktime( tmptr )) < 0) return( (time_t) 0); return( rtime ); } /* * 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 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /*LINTLIBRARY*/ #include #include #include "users.h" extern char *errmsgs[]; extern int lasterrmsg; extern char *cmdname; /* * synopsis: errmsg(msgid, (arg1, ..., argN)) */ void errmsg(int msgid, ...) { va_list args; va_start(args, msgid); if (msgid >= 0 && msgid < lasterrmsg) { (void) fprintf(stderr, "UX: %s: ", cmdname); (void) vfprintf(stderr, errmsgs[ msgid ], args); } va_end(args); } void warningmsg(int what, char *name) { if ((what & WARN_NAME_TOO_LONG) != 0) { (void) fprintf(stderr, "UX: %s: ", cmdname); (void) fprintf(stderr, "%s name too long.\n", name); } if ((what & WARN_BAD_GROUP_NAME) != 0) { (void) fprintf(stderr, "UX: %s: ", cmdname); (void) fprintf(stderr, "%s name should be all lower case" " or numeric.\n", name); } if ((what & WARN_BAD_PROJ_NAME) != 0) { (void) fprintf(stderr, "UX: %s: ", cmdname); (void) fprintf(stderr, "%s name should be all lower case" " or numeric.\n", name); } if ((what & WARN_BAD_LOGNAME_CHAR) != 0) { (void) fprintf(stderr, "UX: %s: ", cmdname); (void) fprintf(stderr, "%s name should be all alphanumeric," " '-', '_', or '.'\n", name); } if ((what & WARN_BAD_LOGNAME_FIRST) != 0) { (void) fprintf(stderr, "UX: %s: ", cmdname); (void) fprintf(stderr, "%s name first character" " should be alphabetic.\n", name); } if ((what & WARN_NO_LOWERCHAR) != 0) { (void) fprintf(stderr, "UX: %s: ", cmdname); (void) fprintf(stderr, "%s name should have at least one " "lower case character.\n", name); } if ((what & WARN_LOGGED_IN) != 0) { (void) fprintf(stderr, "UX: %s: ", cmdname); (void) fprintf(stderr, "%s is currently logged in, some changes" " may not take effect until next login.\n", name); } } /* * 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) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ #ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.3 */ #include #include int check_perm( statbuf, uid, gid, perm ) struct stat statbuf; uid_t uid; gid_t gid; mode_t perm; { int fail = -1; /* assume no permission at onset */ /* Make sure we're dealing with a directory */ if( S_ISDIR( statbuf.st_mode )) { /* * Have a directory, so make sure user has permission * by the various possible methods to this directory. */ if( (statbuf.st_uid == uid) && (statbuf.st_mode & (perm << 6)) == (perm << 6) ) fail = 0; else if( (statbuf.st_gid == gid) && (statbuf.st_mode & (perm << 3)) == (perm << 3) ) fail = 0; else if( (statbuf.st_mode & perm) == perm ) fail = 0; } return( fail ); } /* * 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 2003 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ #include #include #include /* * putgrent() function to write a group structure to a file * supports the use of group names that with + or - */ void putgrent(struct group *grpstr, FILE *to) { char **memptr; /* member vector pointer */ if (grpstr->gr_name[0] == '+' || grpstr->gr_name[0] == '-') { /* * if the groupname starts with either a '+' or '-' then * write out what we can as best as we can * we assume that fgetgrent() set gr_gid to 0 so * write a null entry instead of 0 * This should not break /etc/nsswitch.conf for any of * "group: compat", "group: files", "group: nis" * */ (void) fprintf(to, "%s:%s:", grpstr->gr_name, grpstr->gr_passwd != NULL ? grpstr->gr_passwd : ""); if (grpstr->gr_gid == 0) { (void) fprintf(to, ":"); } else { (void) fprintf(to, "%ld:", grpstr->gr_gid); } memptr = grpstr->gr_mem; while (memptr != NULL && *memptr != NULL) { (void) fprintf(to, "%s", *memptr); memptr++; if (memptr != NULL && *memptr != NULL) (void) fprintf(to, ","); } (void) fprintf(to, "\n"); } else { /* * otherwise write out all the fields in the group structure * */ (void) fprintf(to, "%s:%s:%ld:", grpstr->gr_name, grpstr->gr_passwd, grpstr->gr_gid); memptr = grpstr->gr_mem; while (*memptr != NULL) { (void) fprintf(to, "%s", *memptr); memptr++; if (*memptr != NULL) (void) fprintf(to, ","); } (void) fprintf(to, "\n"); } } /* * 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) 1999-2000 by Sun Microsystems, Inc. * All rights reserved. */ #include #include #include /* * putprojent() function to write a project structure to a file */ void putprojent(struct project *projstr, FILE *to) { char **memptr; /* member vector pointer */ (void) fprintf(to, "%s:%d:%s:", projstr->pj_name, projstr->pj_projid, projstr->pj_comment); /* * do user names first */ memptr = projstr->pj_users; while (*memptr != NULL) { (void) fprintf(to, "%s", *memptr); memptr++; if (*memptr != NULL) (void) fprintf(to, ","); } (void) fprintf(to, ":"); /* * now do groups */ memptr = projstr->pj_groups; while (*memptr != NULL) { (void) fprintf(to, "%s", *memptr); memptr++; if (*memptr != NULL) (void) fprintf(to, ","); } (void) fprintf(to, ":%s\n", projstr->pj_attr); } #ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */ # # 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 # %m/%d/%y %I:%M:%S %p %m/%d/%y %H:%M:%S %m/%d/%y %I:%M %p %m/%d/%y %H:%M %m/%d/%y %I %p %m/%d/%y %H %m/%d/%y %m/%d %b %d, %Y %H:%M:%S %p %b %d, %Y %I:%M:%S %B %d, %Y %H:%M:%S %p %B %d, %Y %I:%M:%S %b %d, %Y %H:%M %p %b %d, %Y %I:%M %B %d, %Y %H:%M %p %B %d, %Y %I:%M %b %d, %Y %H %p %b %d, %Y %I %B %d, %Y %H %p %B %d, %Y %I %b %d, %Y %B %d, %Y %b %d %B %d %b %B %m%d9/25/89M%y %m%d9/25/89M%Y %m%d9/25/89M %m%d%H %m%d %m /* * 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 1997 Sun Microsystems, Inc. All rights reserved. */ /* Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ #include #include #include extern long p_getdate(); /* Validate an expiration date string */ int valid_expire( string, expire ) char *string; time_t *expire; { time_t tmp, now; struct tm *tm; if( !(tmp = (time_t) p_getdate( string ) ) ) return( INVALID ); now = time( (time_t *)0 ); /* Make a time_t for midnight tonight */ tm = localtime( &now ); now -= tm->tm_hour * 60*60 + tm->tm_min * 60 + tm->tm_sec; now += 24 * 60 * 60; if( tmp < now ) return( INVALID ); if( expire ) *expire = now; return( UNIQUE ); } /* * 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) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ #ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.4 */ #include #include #include #include #include #include /* MAXUID should be in param.h; if it isn't, try for UID_MAX in limits.h */ #ifndef MAXUID #include #define MAXUID UID_MAX #endif struct group *getgrgid(); /* validate a GID */ int valid_gid( gid, gptr ) gid_t gid; struct group **gptr; { register struct group *t_gptr; if( gid < 0 ) return( INVALID ); if( gid > MAXUID ) return( TOOBIG ); if( t_gptr = getgrgid( gid ) ) { if( gptr ) *gptr = t_gptr; return( NOTUNIQUE ); } if( gid <= DEFGID ) { if( gptr ) *gptr = getgrgid( gid ); return( RESERVED ); } return( UNIQUE ); } /* * 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, by Sun Microsystems, Inc. * All rights reserved. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /*LINTLIBRARY*/ #include #include #include #include #include /* * validate string given as group name. */ int valid_gname(char *group, struct group **gptr, int *warning) { struct group *t_gptr; char *ptr = group; char c; int len = 0; int badchar = 0; *warning = 0; if (!group || !*group) return (INVALID); for (c = *ptr; c != '\0'; ptr++, c = *ptr) { len++; if (!isprint(c) || (c == ':') || (c == '\n')) return (INVALID); if (!(islower(c) || isdigit(c))) badchar++; } /* * XXX constraints causes some operational/compatibility problem. * This has to be revisited in the future as ARC/standards issue. */ if (len > MAXGLEN - 1) *warning = *warning | WARN_NAME_TOO_LONG; if (badchar != 0) *warning = *warning | WARN_BAD_GROUP_NAME; if ((t_gptr = getgrnam(group)) != NULL) { if (gptr) *gptr = t_gptr; return (NOTUNIQUE); } return (UNIQUE); } /* * 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 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /*LINTLIBRARY*/ #include #include #include #include #include #include #include #include #include extern int valid_gid(gid_t, struct group **); static int isalldigit(char *); /* * validate a group name or number and return the appropriate * group structure for it. */ int valid_group(char *group, struct group **gptr, int *warning) { int r, warn; long l; char *ptr; struct group *grp; *warning = 0; if (!isalldigit(group)) return (valid_gname(group, gptr, warning)); /* * There are only digits in group name. * strtol() doesn't return negative number here. */ errno = 0; l = strtol(group, &ptr, 10); if ((l == LONG_MAX && errno == ERANGE) || l > MAXUID) { r = TOOBIG; } else { if ((r = valid_gid((gid_t)l, &grp)) == NOTUNIQUE) { /* It is a valid existing gid */ if (gptr != NULL) *gptr = grp; return (NOTUNIQUE); } } /* * It's all digit, but not a valid gid nor an existing gid. * There might be an existing group name of all digits. */ if (valid_gname(group, &grp, &warn) == NOTUNIQUE) { /* It does exist */ *warning = warn; if (gptr != NULL) *gptr = grp; return (NOTUNIQUE); } /* * It isn't either existing gid or group name. We return the * error code from valid_gid() assuming that given string * represents an integer GID. */ return (r); } static int isalldigit(char *str) { while (*str != '\0') { if (!isdigit((unsigned char)*str)) return (0); str++; } return (1); } /* * 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) 2013 Gary Mills * * Copyright (c) 1997, by Sun Microsystems, Inc. * All rights reserved. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ /*LINTLIBRARY*/ #include #include #include #include #include #include #include /* Defaults file */ #define DEFAULT_USERADD "/etc/default/useradd" /* * validate string given as login name. */ int valid_login(char *login, struct passwd **pptr, int *warning) { struct passwd *t_pptr; char *ptr = login; int bad1char, badc, clower, len; char c; char action; len = 0; clower = 0; badc = 0; bad1char = 0; *warning = 0; if (!login || !*login) return (INVALID); c = *ptr; if (!isalpha(c)) bad1char++; for (; c != '\0'; ptr++, c = *ptr) { len++; if (!isprint(c) || (c == ':') || (c == '\n')) return (INVALID); if (!isalnum(c) && c != '_' && c != '-' && c != '.') badc++; if (islower(c)) clower++; } action = 'w'; if (defopen(DEFAULT_USERADD) == 0) { char *defptr; if ((defptr = defread("EXCEED_TRAD=")) != NULL) { char let = tolower(*defptr); switch (let) { case 'w': /* warning */ case 'e': /* error */ case 's': /* silent */ action = let; break; } } (void) defopen((char *)NULL); } if (len > LOGNAME_MAX) return (LONGNAME); if (len > LOGNAME_MAX_TRAD) { if (action == 'w') *warning = *warning | WARN_NAME_TOO_LONG; else if (action == 'e') return (LONGNAME); } if (clower == 0) *warning = *warning | WARN_NO_LOWERCHAR; if (badc != 0) *warning = *warning | WARN_BAD_LOGNAME_CHAR; if (bad1char != 0) *warning = *warning | WARN_BAD_LOGNAME_FIRST; if ((t_pptr = getpwnam(login)) != NULL) { if (pptr) *pptr = t_pptr; return (NOTUNIQUE); } return (UNIQUE); } /* * 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 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /*LINTLIBRARY*/ #include #include #include #include #include #include #include extern int valid_projid(projid_t, struct project *, void *, size_t); /* * validate a project name or number and return the appropriate * project structure for it. */ int valid_project(char *project, struct project *pptr, void *buf, size_t len, int *warning) { projid_t projid; char *ptr; *warning = 0; if (isdigit(*project)) { projid = (projid_t)strtol(project, &ptr, (int)10); if (! *ptr) return (valid_projid(projid, pptr, buf, len)); } for (ptr = project; *ptr != '\0'; ptr++) { if (!isprint(*ptr) || (*ptr == ':') || (*ptr == '\n')) return (INVALID); } /* length checking and other warnings are done in valid_projname() */ return (valid_projname(project, pptr, buf, len, warning)); } /* * 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 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ #include #include #include #include #include #include #include #include /* validate a project id */ int valid_projid(projid_t projid, struct project *pptr, void *buf, size_t len) { struct project pbuf; struct project *t_pptr; if (projid < 0) return (INVALID); if (projid > MAXPROJID) return (TOOBIG); if (t_pptr = getprojbyid(projid, pptr, buf, len)) return (NOTUNIQUE); return (UNIQUE); } /* * 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 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /*LINTLIBRARY*/ #include #include #include #include #include #include #include /* * validate string given as project name. */ int valid_projname(char *project, struct project *pptr, void *buf, size_t blen, int *warning) { struct project *t_pptr; char *ptr = project; char c; int len = 0; int badchar = 0; *warning = 0; if (!project || !*project) return (INVALID); for (c = *ptr; c != '\0'; ptr++, c = *ptr) { len++; if (!isprint(c) || (c == ':') || (c == '\n')) return (INVALID); if (!(islower(c) || isdigit(c))) badchar++; } if (len > PROJNAME_MAX) *warning = *warning | WARN_NAME_TOO_LONG; if (badchar != 0) *warning = *warning | WARN_BAD_PROJ_NAME; if ((t_pptr = getprojbyname(project, pptr, buf, blen)) != NULL) return (NOTUNIQUE); return (UNIQUE); } /* * 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) 1984, 1986, 1987, 1988, 1989 AT&T */ /* All Rights Reserved */ #ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.2 */ #include #include #include #include #include #include #ifndef MAXUID #include #define MAXUID UID_MAX #endif struct passwd *getpwuid(); int valid_uid( uid, pptr ) uid_t uid; struct passwd **pptr; { register struct passwd *t_pptr; if( uid <= 0 ) return( INVALID ); if( uid <= DEFRID ) { if( pptr ) *pptr = getpwuid( uid ); return( RESERVED ); } if( uid > MAXUID ) return( TOOBIG ); if( t_pptr = getpwuid( uid ) ) { if( pptr ) *pptr = t_pptr; return( NOTUNIQUE ); } return( UNIQUE ); }