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
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or https://opensource.org/licenses/CDDL-1.0.
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]
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
29 #include "libuutil_common.h"
34 * We require names of the form:
35 * [provider,]identifier[/[provider,]identifier]...
37 * Where provider is either a stock symbol (SUNW) or a java-style reversed
38 * domain name (com.sun).
40 * Both providers and identifiers must start with a letter, and may
41 * only contain alphanumerics, dashes, and underlines. Providers
42 * may also contain periods.
44 * Note that we do _not_ use the macros in <ctype.h>, since they are affected
45 * by the current locale settings.
49 (((c) >= 'a' && (c) <= 'z') || ((c) >= 'A' && (c) <= 'Z'))
52 ((c) >= '0' && (c) <= '9')
55 is_valid_ident(const char *s
, const char *e
, int allowdot
)
60 return (0); /* name is empty */
64 return (0); /* does not start with letter */
66 while (s
< e
&& (c
= *s
++) != 0) {
67 if (IS_ALPHA(c
) || IS_DIGIT(c
) || c
== '-' || c
== '_' ||
68 (allowdot
&& c
== '.'))
70 return (0); /* invalid character */
76 is_valid_component(const char *b
, const char *e
, uint_t flags
)
80 if (flags
& UU_NAME_DOMAIN
) {
82 if (sp
!= NULL
&& sp
< e
) {
83 if (!is_valid_ident(b
, sp
, 1))
89 return (is_valid_ident(b
, e
, 0));
93 uu_check_name(const char *name
, uint_t flags
)
95 const char *end
= name
+ strlen(name
);
98 if (flags
& ~(UU_NAME_DOMAIN
| UU_NAME_PATH
)) {
99 uu_set_error(UU_ERROR_UNKNOWN_FLAG
);
103 if (!(flags
& UU_NAME_PATH
)) {
104 if (!is_valid_component(name
, end
, flags
))
109 while ((p
= strchr(name
, '/')) != NULL
) {
110 if (!is_valid_component(name
, p
- 1, flags
))
114 if (!is_valid_component(name
, end
, flags
))
120 uu_set_error(UU_ERROR_INVALID_ARGUMENT
);