10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
50Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
60Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
70Sstevel@tonic-gate * with the License.
80Sstevel@tonic-gate *
90Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
100Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
110Sstevel@tonic-gate * See the License for the specific language governing permissions
120Sstevel@tonic-gate * and limitations under the License.
130Sstevel@tonic-gate *
140Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
150Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
160Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
170Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
180Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
190Sstevel@tonic-gate *
200Sstevel@tonic-gate * CDDL HEADER END
210Sstevel@tonic-gate */
220Sstevel@tonic-gate /*
230Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
240Sstevel@tonic-gate * Use is subject to license terms.
250Sstevel@tonic-gate */
260Sstevel@tonic-gate
270Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
280Sstevel@tonic-gate
290Sstevel@tonic-gate #include <sys/types.h>
300Sstevel@tonic-gate #include <stdio.h>
310Sstevel@tonic-gate #include <strings.h>
320Sstevel@tonic-gate #include <sys/param.h>
330Sstevel@tonic-gate #include <users.h>
340Sstevel@tonic-gate #include <userdefs.h>
350Sstevel@tonic-gate #include <project.h>
360Sstevel@tonic-gate #include <errno.h>
370Sstevel@tonic-gate #include "messages.h"
380Sstevel@tonic-gate
390Sstevel@tonic-gate
400Sstevel@tonic-gate static projid_t projlist[NPROJECTS_MAX + 1];
41*108Sbasabi static int nproj_max = NPROJECTS_MAX;
420Sstevel@tonic-gate
430Sstevel@tonic-gate /* Validate a list of projects */
440Sstevel@tonic-gate int **
valid_lproject(char * list)450Sstevel@tonic-gate valid_lproject(char *list)
460Sstevel@tonic-gate {
470Sstevel@tonic-gate int n_invalid = 0;
480Sstevel@tonic-gate int i = 0;
490Sstevel@tonic-gate int j;
500Sstevel@tonic-gate char *ptr;
510Sstevel@tonic-gate struct project projent;
520Sstevel@tonic-gate int warning;
530Sstevel@tonic-gate char mybuf[PROJECT_BUFSZ];
540Sstevel@tonic-gate
550Sstevel@tonic-gate if (!list || !*list)
560Sstevel@tonic-gate return ((int **)NULL);
570Sstevel@tonic-gate
580Sstevel@tonic-gate while (ptr = strtok(((i || n_invalid) ? NULL : list), ",")) {
590Sstevel@tonic-gate
600Sstevel@tonic-gate switch (valid_project(ptr, &projent, mybuf, sizeof (mybuf),
610Sstevel@tonic-gate &warning)) {
620Sstevel@tonic-gate case INVALID:
630Sstevel@tonic-gate errmsg(M_INVALID, ptr, "project id");
640Sstevel@tonic-gate n_invalid++;
650Sstevel@tonic-gate break;
660Sstevel@tonic-gate case TOOBIG:
670Sstevel@tonic-gate errmsg(M_TOOBIG, "projid", ptr);
680Sstevel@tonic-gate n_invalid++;
690Sstevel@tonic-gate break;
700Sstevel@tonic-gate case UNIQUE:
710Sstevel@tonic-gate errmsg(M_PROJ_NOTUSED, ptr);
720Sstevel@tonic-gate n_invalid++;
730Sstevel@tonic-gate break;
740Sstevel@tonic-gate case NOTUNIQUE:
750Sstevel@tonic-gate if (!i)
760Sstevel@tonic-gate /* ignore respecified primary */
770Sstevel@tonic-gate projlist[i++] = projent.pj_projid;
780Sstevel@tonic-gate else {
790Sstevel@tonic-gate /* Keep out duplicates */
800Sstevel@tonic-gate for (j = 0; j < i; j++)
810Sstevel@tonic-gate if (projent.pj_projid == projlist[j])
820Sstevel@tonic-gate break;
830Sstevel@tonic-gate
840Sstevel@tonic-gate if (j == i)
850Sstevel@tonic-gate /* Not a duplicate */
860Sstevel@tonic-gate projlist[i++] = projent.pj_projid;
870Sstevel@tonic-gate }
880Sstevel@tonic-gate break;
890Sstevel@tonic-gate }
900Sstevel@tonic-gate if (warning)
910Sstevel@tonic-gate warningmsg(warning, ptr);
920Sstevel@tonic-gate
930Sstevel@tonic-gate if (i >= nproj_max) {
940Sstevel@tonic-gate errmsg(M_MAXPROJECTS, nproj_max);
950Sstevel@tonic-gate break;
960Sstevel@tonic-gate }
970Sstevel@tonic-gate }
980Sstevel@tonic-gate
990Sstevel@tonic-gate /* Terminate the list */
1000Sstevel@tonic-gate projlist[i] = -1;
1010Sstevel@tonic-gate
1020Sstevel@tonic-gate if (n_invalid)
1030Sstevel@tonic-gate exit(EX_BADARG);
1040Sstevel@tonic-gate
1050Sstevel@tonic-gate return ((int **)projlist);
1060Sstevel@tonic-gate }
107