xref: /titanic_52/usr/src/lib/libtsnet/common/libtsnet.h (revision 45916cd2fec6e79bca5dee0421bd39e3c2910d1e)
1*45916cd2Sjpk /*
2*45916cd2Sjpk  * CDDL HEADER START
3*45916cd2Sjpk  *
4*45916cd2Sjpk  * The contents of this file are subject to the terms of the
5*45916cd2Sjpk  * Common Development and Distribution License (the "License").
6*45916cd2Sjpk  * You may not use this file except in compliance with the License.
7*45916cd2Sjpk  *
8*45916cd2Sjpk  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*45916cd2Sjpk  * or http://www.opensolaris.org/os/licensing.
10*45916cd2Sjpk  * See the License for the specific language governing permissions
11*45916cd2Sjpk  * and limitations under the License.
12*45916cd2Sjpk  *
13*45916cd2Sjpk  * When distributing Covered Code, include this CDDL HEADER in each
14*45916cd2Sjpk  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*45916cd2Sjpk  * If applicable, add the following below this CDDL HEADER, with the
16*45916cd2Sjpk  * fields enclosed by brackets "[]" replaced with your own identifying
17*45916cd2Sjpk  * information: Portions Copyright [yyyy] [name of copyright owner]
18*45916cd2Sjpk  *
19*45916cd2Sjpk  * CDDL HEADER END
20*45916cd2Sjpk  */
21*45916cd2Sjpk /*
22*45916cd2Sjpk  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23*45916cd2Sjpk  * Use is subject to license terms.
24*45916cd2Sjpk  *
25*45916cd2Sjpk  * All symbols and functions in this header file and library are private to Sun
26*45916cd2Sjpk  * Microsystems.  The only guarantee that is made is that if your application
27*45916cd2Sjpk  * uses them, it will break on upgrade.
28*45916cd2Sjpk  */
29*45916cd2Sjpk 
30*45916cd2Sjpk #ifndef	_LIBTSNET_H
31*45916cd2Sjpk #define	_LIBTSNET_H
32*45916cd2Sjpk 
33*45916cd2Sjpk #pragma ident	"%Z%%M%	%I%	%E% SMI"
34*45916cd2Sjpk 
35*45916cd2Sjpk #include <stdio.h>
36*45916cd2Sjpk #include <sys/tsol/tndb.h>
37*45916cd2Sjpk 
38*45916cd2Sjpk #ifdef	__cplusplus
39*45916cd2Sjpk extern "C" {
40*45916cd2Sjpk #endif
41*45916cd2Sjpk 
42*45916cd2Sjpk #define	TNRHTP_PATH	"/etc/security/tsol/tnrhtp"
43*45916cd2Sjpk #define	TNRHDB_PATH	"/etc/security/tsol/tnrhdb"
44*45916cd2Sjpk #define	TNZONECFG_PATH	"/etc/security/tsol/tnzonecfg"
45*45916cd2Sjpk 
46*45916cd2Sjpk #define	TNDB_COMMA	", \t"
47*45916cd2Sjpk 
48*45916cd2Sjpk /*
49*45916cd2Sjpk  * String parsing routines
50*45916cd2Sjpk  *
51*45916cd2Sjpk  * These functions are in four logical groups: one for template (tnrhtp)
52*45916cd2Sjpk  * entries, one for remote host (tnrhdb) entries, one for zone configuration
53*45916cd2Sjpk  * (tnzonecfg) entries, and a fourth for routing attributes.
54*45916cd2Sjpk  *
55*45916cd2Sjpk  * In each group, there are functions that parse from a string or database, and
56*45916cd2Sjpk  * a function to free returned entries.  The parsing functions all take a
57*45916cd2Sjpk  * pointer to an integer and a pointer to a character pointer for returning
58*45916cd2Sjpk  * errors.  On error, the returned entry pointer is NULL, the integer is set to
59*45916cd2Sjpk  * one of the LTSNET_* errors below, and the character pointer points to the
60*45916cd2Sjpk  * location of the error.  (For the functions that iterate on a database, this
61*45916cd2Sjpk  * points into static storage in the library.  This storage is associated with
62*45916cd2Sjpk  * the iterator.)
63*45916cd2Sjpk  *
64*45916cd2Sjpk  * The functions that do look-ups based on a value (name or address) do not
65*45916cd2Sjpk  * return errors other than "not found," which is signaled by a return value of
66*45916cd2Sjpk  * NULL.
67*45916cd2Sjpk  */
68*45916cd2Sjpk 
69*45916cd2Sjpk /* Template entry parsing */
70*45916cd2Sjpk extern tsol_tpent_t *tsol_gettpbyname(const char *);
71*45916cd2Sjpk extern tsol_tpent_t *tsol_gettpent(void);
72*45916cd2Sjpk extern tsol_tpent_t *tsol_fgettpent(FILE *);
73*45916cd2Sjpk extern void tsol_freetpent(tsol_tpent_t *);
74*45916cd2Sjpk extern void tsol_settpent(int);
75*45916cd2Sjpk extern void tsol_endtpent(void);
76*45916cd2Sjpk extern int str_to_tpstr(const char *, int, void *, char *, int);
77*45916cd2Sjpk extern tsol_tpent_t *tpstr_to_ent(tsol_tpstr_t *, int *, char **);
78*45916cd2Sjpk 
79*45916cd2Sjpk /* Remote host entry parsing */
80*45916cd2Sjpk extern tsol_rhent_t *tsol_getrhbyaddr(const void *, size_t, int);
81*45916cd2Sjpk extern tsol_rhent_t *tsol_getrhent(void);
82*45916cd2Sjpk extern tsol_rhent_t *tsol_fgetrhent(FILE *);
83*45916cd2Sjpk extern void tsol_freerhent(tsol_rhent_t *);
84*45916cd2Sjpk extern void tsol_setrhent(int);
85*45916cd2Sjpk extern void tsol_endrhent(void);
86*45916cd2Sjpk extern int str_to_rhstr(const char *, int, void *, char *, int);
87*45916cd2Sjpk extern tsol_rhent_t *rhstr_to_ent(tsol_rhstr_t *, int *, char **);
88*45916cd2Sjpk extern tsol_host_type_t tsol_getrhtype(char *);
89*45916cd2Sjpk 
90*45916cd2Sjpk 
91*45916cd2Sjpk /* Zone configuration parsing */
92*45916cd2Sjpk extern tsol_zcent_t *tsol_sgetzcent(const char *, int *, char **);
93*45916cd2Sjpk extern void tsol_freezcent(tsol_zcent_t *);
94*45916cd2Sjpk 
95*45916cd2Sjpk /* Routing attribute parsing */
96*45916cd2Sjpk extern const char *sl_to_str(const bslabel_t *);
97*45916cd2Sjpk struct rtsa_s;
98*45916cd2Sjpk extern const char *rtsa_to_str(const struct rtsa_s *, char *, size_t);
99*45916cd2Sjpk extern boolean_t rtsa_keyword(const char *, struct rtsa_s *, int *, char **);
100*45916cd2Sjpk extern const char *parse_entry(char *, size_t, const char *, const char *);
101*45916cd2Sjpk 
102*45916cd2Sjpk /* Convert LTSNET_* to a printable string */
103*45916cd2Sjpk extern const char *tsol_strerror(int, int);
104*45916cd2Sjpk 
105*45916cd2Sjpk /* System calls; these return -1 on error and set errno */
106*45916cd2Sjpk extern int tnrhtp(int, tsol_tpent_t *);
107*45916cd2Sjpk extern int tnrh(int, tsol_rhent_t *);
108*45916cd2Sjpk extern int tnmlp(int, tsol_mlpent_t *);
109*45916cd2Sjpk 
110*45916cd2Sjpk /*
111*45916cd2Sjpk  * Errors that can occur in the parsing routines.  Note that not all errors are
112*45916cd2Sjpk  * possible with every routine.  Must be kept in sync with list in misc.c.
113*45916cd2Sjpk  */
114*45916cd2Sjpk #define	LTSNET_NONE		0	/* No error */
115*45916cd2Sjpk #define	LTSNET_SYSERR		1	/* System error; see errno */
116*45916cd2Sjpk #define	LTSNET_EMPTY		2	/* Empty string or end of list */
117*45916cd2Sjpk #define	LTSNET_ILL_ENTRY	3	/* Entry is malformed */
118*45916cd2Sjpk #define	LTSNET_NO_NAME		4	/* Missing name */
119*45916cd2Sjpk #define	LTSNET_NO_ATTRS		5	/* Missing template attributes */
120*45916cd2Sjpk #define	LTSNET_ILL_NAME		6	/* Illegal name */
121*45916cd2Sjpk #define	LTSNET_ILL_KEYDELIM	7	/* Illegal keyword delimiter */
122*45916cd2Sjpk #define	LTSNET_ILL_KEY		8	/* Unknown keyword */
123*45916cd2Sjpk #define	LTSNET_DUP_KEY		9	/* Duplicate keyword */
124*45916cd2Sjpk #define	LTSNET_ILL_VALDELIM	10	/* Illegal value delimiter */
125*45916cd2Sjpk #define	LTSNET_NO_HOSTTYPE	11	/* Missing host type */
126*45916cd2Sjpk #define	LTSNET_ILL_HOSTTYPE	12	/* Illegal host type */
127*45916cd2Sjpk #define	LTSNET_NO_LABEL		13	/* Missing label */
128*45916cd2Sjpk #define	LTSNET_ILL_LABEL	14	/* Illegal label */
129*45916cd2Sjpk #define	LTSNET_NO_RANGE		15	/* Missing label range */
130*45916cd2Sjpk #define	LTSNET_ILL_RANGE	16	/* Illegal label range */
131*45916cd2Sjpk #define	LTSNET_NO_LOWERBOUND	17	/* No lower bound in range */
132*45916cd2Sjpk #define	LTSNET_ILL_LOWERBOUND	18	/* Illegal lower bound in range */
133*45916cd2Sjpk #define	LTSNET_NO_UPPERBOUND	19	/* No upper bound in range */
134*45916cd2Sjpk #define	LTSNET_ILL_UPPERBOUND	20	/* Illegal upper bound in range */
135*45916cd2Sjpk #define	LTSNET_NO_DOI		21	/* Missing DOI */
136*45916cd2Sjpk #define	LTSNET_ILL_DOI		22	/* Illegal DOI */
137*45916cd2Sjpk #define	LTSNET_SET_TOO_BIG	23	/* Too many entries in set */
138*45916cd2Sjpk #define	LTSNET_NO_ADDR		24	/* Missing address/network */
139*45916cd2Sjpk #define	LTSNET_ILL_ADDR		25	/* Illegal address/network */
140*45916cd2Sjpk #define	LTSNET_ILL_FLAG		26	/* Illegal flag */
141*45916cd2Sjpk #define	LTSNET_ILL_MLP		27	/* Illegal MLP specification */
142*45916cd2Sjpk #define	LTSNET_BAD_TYPE		28	/* Unacceptable keyword for type */
143*45916cd2Sjpk 
144*45916cd2Sjpk #ifdef	__cplusplus
145*45916cd2Sjpk }
146*45916cd2Sjpk #endif
147*45916cd2Sjpk 
148*45916cd2Sjpk #endif	/* _LIBTSNET_H */
149