1*9781SMoriah.Waterland@Sun.COM /*
2*9781SMoriah.Waterland@Sun.COM * CDDL HEADER START
3*9781SMoriah.Waterland@Sun.COM *
4*9781SMoriah.Waterland@Sun.COM * The contents of this file are subject to the terms of the
5*9781SMoriah.Waterland@Sun.COM * Common Development and Distribution License (the "License").
6*9781SMoriah.Waterland@Sun.COM * You may not use this file except in compliance with the License.
7*9781SMoriah.Waterland@Sun.COM *
8*9781SMoriah.Waterland@Sun.COM * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*9781SMoriah.Waterland@Sun.COM * or http://www.opensolaris.org/os/licensing.
10*9781SMoriah.Waterland@Sun.COM * See the License for the specific language governing permissions
11*9781SMoriah.Waterland@Sun.COM * and limitations under the License.
12*9781SMoriah.Waterland@Sun.COM *
13*9781SMoriah.Waterland@Sun.COM * When distributing Covered Code, include this CDDL HEADER in each
14*9781SMoriah.Waterland@Sun.COM * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*9781SMoriah.Waterland@Sun.COM * If applicable, add the following below this CDDL HEADER, with the
16*9781SMoriah.Waterland@Sun.COM * fields enclosed by brackets "[]" replaced with your own identifying
17*9781SMoriah.Waterland@Sun.COM * information: Portions Copyright [yyyy] [name of copyright owner]
18*9781SMoriah.Waterland@Sun.COM *
19*9781SMoriah.Waterland@Sun.COM * CDDL HEADER END
20*9781SMoriah.Waterland@Sun.COM */
21*9781SMoriah.Waterland@Sun.COM
22*9781SMoriah.Waterland@Sun.COM /*
23*9781SMoriah.Waterland@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24*9781SMoriah.Waterland@Sun.COM * Use is subject to license terms.
25*9781SMoriah.Waterland@Sun.COM */
26*9781SMoriah.Waterland@Sun.COM
27*9781SMoriah.Waterland@Sun.COM /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28*9781SMoriah.Waterland@Sun.COM /* All Rights Reserved */
29*9781SMoriah.Waterland@Sun.COM
30*9781SMoriah.Waterland@Sun.COM
31*9781SMoriah.Waterland@Sun.COM
32*9781SMoriah.Waterland@Sun.COM #include <ctype.h>
33*9781SMoriah.Waterland@Sun.COM #include <string.h>
34*9781SMoriah.Waterland@Sun.COM #include <sys/types.h>
35*9781SMoriah.Waterland@Sun.COM #include "pkglib.h"
36*9781SMoriah.Waterland@Sun.COM #include "pkglibmsgs.h"
37*9781SMoriah.Waterland@Sun.COM #include "pkglocale.h"
38*9781SMoriah.Waterland@Sun.COM
39*9781SMoriah.Waterland@Sun.COM #define MAXLEN 256
40*9781SMoriah.Waterland@Sun.COM #define TOKLEN 16
41*9781SMoriah.Waterland@Sun.COM
42*9781SMoriah.Waterland@Sun.COM static int proc_name(char *param, char *value);
43*9781SMoriah.Waterland@Sun.COM static int proc_arch(char *param, char *value);
44*9781SMoriah.Waterland@Sun.COM static int proc_version(char *param, char *value);
45*9781SMoriah.Waterland@Sun.COM static int proc_category(char *param, char *value);
46*9781SMoriah.Waterland@Sun.COM static int bad_first_char(char *param, char *value);
47*9781SMoriah.Waterland@Sun.COM static int not_alnum(char *param, char *pt);
48*9781SMoriah.Waterland@Sun.COM static int not_ascii(char *param, char *pt);
49*9781SMoriah.Waterland@Sun.COM static int too_long(char *param, char *pt, int len);
50*9781SMoriah.Waterland@Sun.COM static int isnull(char *param, char *pt);
51*9781SMoriah.Waterland@Sun.COM
52*9781SMoriah.Waterland@Sun.COM int
ckparam(char * param,char * val)53*9781SMoriah.Waterland@Sun.COM ckparam(char *param, char *val)
54*9781SMoriah.Waterland@Sun.COM {
55*9781SMoriah.Waterland@Sun.COM char *value = strdup(val);
56*9781SMoriah.Waterland@Sun.COM int ret_val = 0; /* return value */
57*9781SMoriah.Waterland@Sun.COM
58*9781SMoriah.Waterland@Sun.COM if (strcmp(param, "NAME") == 0)
59*9781SMoriah.Waterland@Sun.COM ret_val = proc_name(param, value);
60*9781SMoriah.Waterland@Sun.COM
61*9781SMoriah.Waterland@Sun.COM else if (strcmp(param, "ARCH") == 0)
62*9781SMoriah.Waterland@Sun.COM ret_val = proc_arch(param, value);
63*9781SMoriah.Waterland@Sun.COM
64*9781SMoriah.Waterland@Sun.COM else if (strcmp(param, "VERSION") == 0)
65*9781SMoriah.Waterland@Sun.COM ret_val = proc_version(param, value);
66*9781SMoriah.Waterland@Sun.COM
67*9781SMoriah.Waterland@Sun.COM else if (strcmp(param, "CATEGORY") == 0)
68*9781SMoriah.Waterland@Sun.COM ret_val = proc_category(param, value);
69*9781SMoriah.Waterland@Sun.COM
70*9781SMoriah.Waterland@Sun.COM /* param does not match existing parameters */
71*9781SMoriah.Waterland@Sun.COM free(value);
72*9781SMoriah.Waterland@Sun.COM return (ret_val);
73*9781SMoriah.Waterland@Sun.COM }
74*9781SMoriah.Waterland@Sun.COM
75*9781SMoriah.Waterland@Sun.COM static int
proc_name(char * param,char * value)76*9781SMoriah.Waterland@Sun.COM proc_name(char *param, char *value)
77*9781SMoriah.Waterland@Sun.COM {
78*9781SMoriah.Waterland@Sun.COM int ret_val;
79*9781SMoriah.Waterland@Sun.COM
80*9781SMoriah.Waterland@Sun.COM if (!(ret_val = isnull(param, value))) {
81*9781SMoriah.Waterland@Sun.COM ret_val += too_long(param, value, MAXLEN);
82*9781SMoriah.Waterland@Sun.COM ret_val += not_ascii(param, value);
83*9781SMoriah.Waterland@Sun.COM }
84*9781SMoriah.Waterland@Sun.COM
85*9781SMoriah.Waterland@Sun.COM return (ret_val);
86*9781SMoriah.Waterland@Sun.COM }
87*9781SMoriah.Waterland@Sun.COM
88*9781SMoriah.Waterland@Sun.COM static int
proc_arch(char * param,char * value)89*9781SMoriah.Waterland@Sun.COM proc_arch(char *param, char *value)
90*9781SMoriah.Waterland@Sun.COM {
91*9781SMoriah.Waterland@Sun.COM int ret_val;
92*9781SMoriah.Waterland@Sun.COM char *token;
93*9781SMoriah.Waterland@Sun.COM
94*9781SMoriah.Waterland@Sun.COM if (!(ret_val = isnull(param, value))) {
95*9781SMoriah.Waterland@Sun.COM token = strtok(value, ", ");
96*9781SMoriah.Waterland@Sun.COM
97*9781SMoriah.Waterland@Sun.COM while (token) {
98*9781SMoriah.Waterland@Sun.COM ret_val += too_long(param, token, TOKLEN);
99*9781SMoriah.Waterland@Sun.COM ret_val += not_ascii(param, token);
100*9781SMoriah.Waterland@Sun.COM token = strtok(NULL, ", ");
101*9781SMoriah.Waterland@Sun.COM }
102*9781SMoriah.Waterland@Sun.COM }
103*9781SMoriah.Waterland@Sun.COM
104*9781SMoriah.Waterland@Sun.COM return (ret_val);
105*9781SMoriah.Waterland@Sun.COM }
106*9781SMoriah.Waterland@Sun.COM
107*9781SMoriah.Waterland@Sun.COM static int
proc_version(char * param,char * value)108*9781SMoriah.Waterland@Sun.COM proc_version(char *param, char *value)
109*9781SMoriah.Waterland@Sun.COM {
110*9781SMoriah.Waterland@Sun.COM int ret_val;
111*9781SMoriah.Waterland@Sun.COM
112*9781SMoriah.Waterland@Sun.COM if (!(ret_val = isnull(param, value))) {
113*9781SMoriah.Waterland@Sun.COM ret_val += bad_first_char(param, value);
114*9781SMoriah.Waterland@Sun.COM ret_val += too_long(param, value, MAXLEN);
115*9781SMoriah.Waterland@Sun.COM ret_val += not_ascii(param, value);
116*9781SMoriah.Waterland@Sun.COM }
117*9781SMoriah.Waterland@Sun.COM
118*9781SMoriah.Waterland@Sun.COM return (ret_val);
119*9781SMoriah.Waterland@Sun.COM }
120*9781SMoriah.Waterland@Sun.COM
121*9781SMoriah.Waterland@Sun.COM static int
proc_category(char * param,char * value)122*9781SMoriah.Waterland@Sun.COM proc_category(char *param, char *value)
123*9781SMoriah.Waterland@Sun.COM {
124*9781SMoriah.Waterland@Sun.COM int ret_val;
125*9781SMoriah.Waterland@Sun.COM char *token;
126*9781SMoriah.Waterland@Sun.COM
127*9781SMoriah.Waterland@Sun.COM if (!(ret_val = isnull(param, value))) {
128*9781SMoriah.Waterland@Sun.COM token = strtok(value, ", ");
129*9781SMoriah.Waterland@Sun.COM
130*9781SMoriah.Waterland@Sun.COM while (token) {
131*9781SMoriah.Waterland@Sun.COM ret_val += too_long(param, token, TOKLEN);
132*9781SMoriah.Waterland@Sun.COM ret_val += not_alnum(param, token);
133*9781SMoriah.Waterland@Sun.COM token = strtok(NULL, ", ");
134*9781SMoriah.Waterland@Sun.COM }
135*9781SMoriah.Waterland@Sun.COM }
136*9781SMoriah.Waterland@Sun.COM
137*9781SMoriah.Waterland@Sun.COM return (ret_val);
138*9781SMoriah.Waterland@Sun.COM }
139*9781SMoriah.Waterland@Sun.COM
140*9781SMoriah.Waterland@Sun.COM static int
bad_first_char(char * param,char * value)141*9781SMoriah.Waterland@Sun.COM bad_first_char(char *param, char *value)
142*9781SMoriah.Waterland@Sun.COM {
143*9781SMoriah.Waterland@Sun.COM if (*value == '(') {
144*9781SMoriah.Waterland@Sun.COM progerr(pkg_gt(ERR_CHAR), param);
145*9781SMoriah.Waterland@Sun.COM return (1);
146*9781SMoriah.Waterland@Sun.COM }
147*9781SMoriah.Waterland@Sun.COM
148*9781SMoriah.Waterland@Sun.COM return (0);
149*9781SMoriah.Waterland@Sun.COM }
150*9781SMoriah.Waterland@Sun.COM
151*9781SMoriah.Waterland@Sun.COM static int
isnull(char * param,char * pt)152*9781SMoriah.Waterland@Sun.COM isnull(char *param, char *pt)
153*9781SMoriah.Waterland@Sun.COM {
154*9781SMoriah.Waterland@Sun.COM if (!pt || *pt == '\0') {
155*9781SMoriah.Waterland@Sun.COM progerr(pkg_gt(ERR_UNDEF), param);
156*9781SMoriah.Waterland@Sun.COM return (1);
157*9781SMoriah.Waterland@Sun.COM }
158*9781SMoriah.Waterland@Sun.COM return (0);
159*9781SMoriah.Waterland@Sun.COM }
160*9781SMoriah.Waterland@Sun.COM
161*9781SMoriah.Waterland@Sun.COM static int
too_long(char * param,char * pt,int len)162*9781SMoriah.Waterland@Sun.COM too_long(char *param, char *pt, int len)
163*9781SMoriah.Waterland@Sun.COM {
164*9781SMoriah.Waterland@Sun.COM if (strlen(pt) > (size_t)len) {
165*9781SMoriah.Waterland@Sun.COM progerr(pkg_gt(ERR_LEN), pt);
166*9781SMoriah.Waterland@Sun.COM return (1);
167*9781SMoriah.Waterland@Sun.COM }
168*9781SMoriah.Waterland@Sun.COM return (0);
169*9781SMoriah.Waterland@Sun.COM }
170*9781SMoriah.Waterland@Sun.COM
171*9781SMoriah.Waterland@Sun.COM static int
not_ascii(char * param,char * pt)172*9781SMoriah.Waterland@Sun.COM not_ascii(char *param, char *pt)
173*9781SMoriah.Waterland@Sun.COM {
174*9781SMoriah.Waterland@Sun.COM while (*pt) {
175*9781SMoriah.Waterland@Sun.COM if (!(isascii(*pt))) {
176*9781SMoriah.Waterland@Sun.COM progerr(pkg_gt(ERR_ASCII), param);
177*9781SMoriah.Waterland@Sun.COM return (1);
178*9781SMoriah.Waterland@Sun.COM }
179*9781SMoriah.Waterland@Sun.COM pt++;
180*9781SMoriah.Waterland@Sun.COM }
181*9781SMoriah.Waterland@Sun.COM return (0);
182*9781SMoriah.Waterland@Sun.COM }
183*9781SMoriah.Waterland@Sun.COM
184*9781SMoriah.Waterland@Sun.COM static int
not_alnum(char * param,char * pt)185*9781SMoriah.Waterland@Sun.COM not_alnum(char *param, char *pt)
186*9781SMoriah.Waterland@Sun.COM {
187*9781SMoriah.Waterland@Sun.COM while (*pt) {
188*9781SMoriah.Waterland@Sun.COM if (!(isalnum(*pt))) {
189*9781SMoriah.Waterland@Sun.COM progerr(pkg_gt(ERR_ALNUM), param);
190*9781SMoriah.Waterland@Sun.COM return (1);
191*9781SMoriah.Waterland@Sun.COM }
192*9781SMoriah.Waterland@Sun.COM pt++;
193*9781SMoriah.Waterland@Sun.COM }
194*9781SMoriah.Waterland@Sun.COM
195*9781SMoriah.Waterland@Sun.COM return (0);
196*9781SMoriah.Waterland@Sun.COM }
197