4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright (c) 2017 Peter Tribble.
27 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
31 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
32 /* All Rights Reserved */
39 #include <sys/types.h>
41 #include "pkglibmsgs.h"
42 #include "pkglocale.h"
47 static int proc_name(char *param
, char *value
);
48 static int proc_arch(char *param
, char *value
);
49 static int proc_version(char *param
, char *value
);
50 static int proc_category(char *param
, char *value
);
51 static int bad_first_char(char *param
, char *value
);
52 static int not_alnum(char *param
, char *pt
);
53 static int not_ascii(char *param
, char *pt
);
54 static int too_long(char *param
, char *pt
, int len
);
55 static int isnull(char *param
, char *pt
);
58 ckparam(char *param
, char *val
)
60 char *value
= strdup(val
);
61 int ret_val
= 0; /* return value */
63 if (strcmp(param
, "NAME") == 0)
64 ret_val
= proc_name(param
, value
);
66 else if (strcmp(param
, "ARCH") == 0)
67 ret_val
= proc_arch(param
, value
);
69 else if (strcmp(param
, "VERSION") == 0)
70 ret_val
= proc_version(param
, value
);
72 else if (strcmp(param
, "CATEGORY") == 0)
73 ret_val
= proc_category(param
, value
);
75 /* param does not match existing parameters */
81 proc_name(char *param
, char *value
)
85 if (!(ret_val
= isnull(param
, value
))) {
86 ret_val
+= too_long(param
, value
, MAXLEN
);
87 ret_val
+= not_ascii(param
, value
);
94 proc_arch(char *param
, char *value
)
99 if (!(ret_val
= isnull(param
, value
))) {
100 token
= strtok(value
, ", ");
103 ret_val
+= too_long(param
, token
, TOKLEN
);
104 ret_val
+= not_ascii(param
, token
);
105 token
= strtok(NULL
, ", ");
113 proc_version(char *param
, char *value
)
117 if (!(ret_val
= isnull(param
, value
))) {
118 ret_val
+= bad_first_char(param
, value
);
119 ret_val
+= too_long(param
, value
, MAXLEN
);
120 ret_val
+= not_ascii(param
, value
);
127 proc_category(char *param
, char *value
)
132 if (!(ret_val
= isnull(param
, value
))) {
133 token
= strtok(value
, ", ");
136 ret_val
+= too_long(param
, token
, TOKLEN
);
137 ret_val
+= not_alnum(param
, token
);
138 token
= strtok(NULL
, ", ");
146 bad_first_char(char *param
, char *value
)
149 progerr(pkg_gt(ERR_CHAR
), param
);
157 isnull(char *param
, char *pt
)
159 if (!pt
|| *pt
== '\0') {
160 progerr(pkg_gt(ERR_UNDEF
), param
);
167 too_long(char *param
, char *pt
, int len
)
169 if (strlen(pt
) > (size_t)len
) {
170 progerr(pkg_gt(ERR_LEN
), param
);
177 not_ascii(char *param
, char *pt
)
180 if (!(isascii(*pt
))) {
181 progerr(pkg_gt(ERR_ASCII
), param
);
190 not_alnum(char *param
, char *pt
)
193 if (!(isalnum(*pt
))) {
194 progerr(pkg_gt(ERR_ALNUM
), param
);