cmd/oamuser: drop -Wno-implicit-function-declaration
[unleashed.git] / usr / src / cmd / oamuser / user / val_lprj.c
blob669299a44158701163cefceb6874812223974819
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
7 * with the License.
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
20 * CDDL HEADER END
23 * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
28 * Copyright (c) 2013 RackTop Systems.
31 #include <sys/types.h>
32 #include <ctype.h>
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <strings.h>
36 #include <sys/param.h>
37 #include <users.h>
38 #include <userdefs.h>
39 #include <project.h>
40 #include <errno.h>
41 #include "messages.h"
44 static projid_t projlist[NPROJECTS_MAX + 1];
45 static int nproj_max = NPROJECTS_MAX;
47 /* Validate a list of projects */
48 int **
49 valid_lproject(char *list)
51 int n_invalid = 0;
52 int i = 0;
53 int j;
54 char *ptr;
55 struct project projent;
56 int warning;
57 char mybuf[PROJECT_BUFSZ];
59 if (!list || !*list)
60 return ((int **)NULL);
62 while ((ptr = strtok((i || n_invalid) ? NULL : list, ","))) {
64 switch (valid_project(ptr, &projent, mybuf, sizeof (mybuf),
65 &warning)) {
66 case INVALID:
67 errmsg(M_INVALID, ptr, "project id");
68 n_invalid++;
69 break;
70 case TOOBIG:
71 errmsg(M_TOOBIG, "projid", ptr);
72 n_invalid++;
73 break;
74 case UNIQUE:
75 errmsg(M_PROJ_NOTUSED, ptr);
76 n_invalid++;
77 break;
78 case NOTUNIQUE:
79 if (!i)
80 /* ignore respecified primary */
81 projlist[i++] = projent.pj_projid;
82 else {
83 /* Keep out duplicates */
84 for (j = 0; j < i; j++)
85 if (projent.pj_projid == projlist[j])
86 break;
88 if (j == i)
89 /* Not a duplicate */
90 projlist[i++] = projent.pj_projid;
92 break;
94 if (warning)
95 warningmsg(warning, ptr);
97 if (i >= nproj_max) {
98 errmsg(M_MAXPROJECTS, nproj_max);
99 break;
103 /* Terminate the list */
104 projlist[i] = -1;
106 if (n_invalid)
107 exit(EX_BADARG);
109 return ((int **)projlist);