Cross Reference: uu_ident.c
xref
: /
osnet-11
/
usr
/
src
/
lib
/
libuutil
/
common
/
uu_ident.c
Home
History
Annotate
Line#
Navigate
Download
Search
only in
./
2
N/A
/*
2
N/A
* CDDL HEADER START
2
N/A
*
2
N/A
* The contents of this file are subject to the terms of the
2
N/A
* Common Development and Distribution License, Version 1.0 only
2
N/A
* (the "License"). You may not use this file except in compliance
2
N/A
* with the License.
2
N/A
*
2
N/A
* You can obtain a copy of the license at
usr
/
src
/
OPENSOLARIS.LICENSE
2
N/A
* or
http://www.opensolaris.org/os/licensing
.
2
N/A
* See the License for the specific language governing permissions
2
N/A
* and limitations under the License.
2
N/A
*
2
N/A
* When distributing Covered Code, include this CDDL HEADER in each
2
N/A
* file and include the License file at
usr
/
src
/
OPENSOLARIS.LICENSE
.
2
N/A
* If applicable, add the following below this CDDL HEADER, with the
2
N/A
* fields enclosed by brackets "[]" replaced with your own identifying
2
N/A
* information: Portions Copyright [yyyy] [name of copyright owner]
2
N/A
*
2
N/A
* CDDL HEADER END
2
N/A
*/
2
N/A
/*
2
N/A
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
2
N/A
* Use is subject to license terms.
2
N/A
*/
2
N/A
2
N/A
#
pragma
ident
"%Z%%M% %I% %E% SMI"
2
N/A
2
N/A
#
include
"
libuutil_common.h
"
2
N/A
2
N/A
#
include
<
string.h
>
2
N/A
2
N/A
/*
2
N/A
* We require names of the form:
2
N/A
* [provider,]identifier[/[provider,]identifier]...
2
N/A
*
2
N/A
* Where provider is either a stock symbol (SUNW) or a java-style reversed
2
N/A
* domain name (
com.s
un).
2
N/A
*
2
N/A
* Both providers and identifiers must start with a letter, and may
2
N/A
* only contain alphanumerics, dashes, and underlines. Providers
2
N/A
* may also contain periods.
2
N/A
*
2
N/A
* Note that we do _not_ use the macros in <
ctype.h
>, since they are affected
2
N/A
* by the current locale settings.
2
N/A
*/
2
N/A
2
N/A
#
define
IS_ALPHA
(c) \
2
N/A
(((c) >=
'a'
&& (c) <=
'z'
) || ((c) >=
'A'
&& (c) <=
'Z'
))
2
N/A
2
N/A
#
define
IS_DIGIT
(c) \
2
N/A
((c) >=
'0'
&& (c) <=
'9'
)
2
N/A
2
N/A
static
int
2
N/A
is_valid_ident
(
const
char
*s,
const
char
*e,
int
allowdot
)
2
N/A
{
2
N/A
char
c;
2
N/A
2
N/A
if
(s >= e)
2
N/A
return
(0);
/* name is empty */
2
N/A
2
N/A
c = *s++;
2
N/A
if
(!
IS_ALPHA
(c))
2
N/A
return
(0);
/* does not start with letter */
2
N/A
2
N/A
while
(s < e && (c = *s++) != 0) {
2
N/A
if
(
IS_ALPHA
(c) ||
IS_DIGIT
(c) || c ==
'-'
|| c ==
'_'
||
2
N/A
(
allowdot
&& c ==
'.'
))
2
N/A
continue
;
2
N/A
return
(0);
/* invalid character */
2
N/A
}
2
N/A
return
(
1
);
2
N/A
}
2
N/A
2
N/A
static
int
2
N/A
is_valid_component
(
const
char
*b,
const
char
*e,
uint_t
flags
)
2
N/A
{
2
N/A
char
*
sp
;
2
N/A
2
N/A
if
(
flags
&
UU_NAME_DOMAIN
) {
2
N/A
sp
=
strchr
(b,
','
);
2
N/A
if
(
sp
!=
NULL
&&
sp
< e) {
2
N/A
if
(!
is_valid_ident
(b,
sp
,
1
))
2
N/A
return
(0);
2
N/A
b =
sp
+
1
;
2
N/A
}
2
N/A
}
2
N/A
2
N/A
return
(
is_valid_ident
(b, e, 0));
2
N/A
}
2
N/A
2
N/A
int
2
N/A
uu_check_name
(
const
char
*
name
,
uint_t
flags
)
2
N/A
{
2
N/A
const
char
*
end
=
name
+
strlen
(
name
);
2
N/A
const
char
*p;
2
N/A
2
N/A
if
(
flags
& ~(
UU_NAME_DOMAIN
|
UU_NAME_PATH
)) {
2
N/A
uu_set_error
(
UU_ERROR_UNKNOWN_FLAG
);
2
N/A
return
(-
1
);
2
N/A
}
2
N/A
2
N/A
if
(!(
flags
&
UU_NAME_PATH
)) {
2
N/A
if
(!
is_valid_component
(
name
,
end
,
flags
))
2
N/A
goto
bad
;
2
N/A
return
(0);
2
N/A
}
2
N/A
2
N/A
while
((p =
strchr
(
name
,
'/'
)) !=
NULL
) {
2
N/A
if
(!
is_valid_component
(
name
, p -
1
,
flags
))
2
N/A
goto
bad
;
2
N/A
name
= p +
1
;
2
N/A
}
2
N/A
if
(!
is_valid_component
(
name
,
end
,
flags
))
2
N/A
goto
bad
;
2
N/A
2
N/A
return
(0);
2
N/A
2
N/A
bad
:
2
N/A
uu_set_error
(
UU_ERROR_INVALID_ARGUMENT
);
2
N/A
return
(-
1
);
2
N/A
}