xref: /titanic_44/usr/src/lib/libvscan/common/libvscan.h (revision 5b3e1433c6213363bcb6387e66fc84ee9ff21a5d)
1 /*
2  * CDDL HEADER START
3  *
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.
7  *
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.
12  *
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]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 #ifndef __LIBVS_H__
29 #define	__LIBVS_H__
30 
31 #include <netdb.h>
32 #include <netinet/in.h>
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 /* Property IDs - general property group */
39 #define	VS_PROPID_MAXSIZE	0x01LL
40 #define	VS_PROPID_MAXSIZE_ACTION	0x02LL
41 #define	VS_PROPID_TYPES		0x04LL
42 #define	VS_PROPID_VLOG		0x08LL
43 
44 #define	VS_PROPID_GEN_ALL		(VS_PROPID_MAXSIZE | \
45     VS_PROPID_MAXSIZE_ACTION | VS_PROPID_TYPES | VS_PROPID_VLOG)
46 
47 #define	VS_PROPID_VALUE_AUTH	0x010LL
48 
49 /* Property IDs - scan engine property groups */
50 #define	VS_PROPID_SE_ENABLE	0x100LL
51 #define	VS_PROPID_SE_HOST	0x200LL
52 #define	VS_PROPID_SE_PORT	0x400LL
53 #define	VS_PROPID_SE_MAXCONN	0x800LL
54 
55 #define	VS_PROPID_SE_ALL	(VS_PROPID_SE_ENABLE | \
56     VS_PROPID_SE_HOST | VS_PROPID_SE_PORT | VS_PROPID_SE_MAXCONN)
57 
58 /* Check for whether a property id is a scan engine id */
59 #define	VS_PROPID_IS_SE(id)	((id & VS_PROPID_SE_ALL) ? 1 : 0)
60 
61 /* The maximum property id value - across all property groups */
62 #define	VS_PROPID_MAX		VS_PROPID_SE_MAXCONN
63 
64 /* The number of properties in the largest property group */
65 #define	VS_NUM_PROPIDS		5
66 
67 /* Range of scan engine IDs and max number of scan engines supported */
68 #define	VS_SE_MAX		16
69 #define	VS_SE_NAME_LEN		64
70 
71 /* Min & Max scan engine connections per engine */
72 #define	VS_VAL_SE_MAXCONN_MIN	1
73 #define	VS_VAL_SE_MAXCONN_MAX	512
74 
75 /* Can accommodate a string-ified ULONG_MAX plus unit specifier */
76 #define	VS_VAL_MAXSIZE_LEN	32
77 
78 #define	VS_VAL_TYPES_LEN	4096
79 #define	VS_VAL_TYPES_INVALID_CHARS	"."
80 
81 /* libvscan error codes */
82 #define	VS_ERR_NONE			0
83 #define	VS_ERR_INVALID_PROPERTY		1
84 #define	VS_ERR_INVALID_VALUE		2
85 #define	VS_ERR_INVALID_HOST		3
86 #define	VS_ERR_INVALID_SE		4
87 #define	VS_ERR_MAX_SE			5
88 #define	VS_ERR_AUTH			6
89 #define	VS_ERR_DAEMON_COMM		10
90 #define	VS_ERR_SCF			20
91 #define	VS_ERR_SYS			30
92 
93 
94 /* RBAC authorizations */
95 #define	VS_VALUE_AUTH		"solaris.smf.value.vscan"
96 #define	VS_ACTION_AUTH		"solaris.smf.manage.vscan"
97 #define	VS_MODIFY_AUTH		"solaris.smf.modify.application"
98 
99 /* statistics door interface */
100 #define	VS_STATS_DOOR_NAME	"/var/run/vscan_stats_door"
101 #define	VS_STATS_DOOR_VERSION	1
102 
103 /* scan statistics door request type */
104 typedef enum {
105 	VS_STATS_GET,
106 	VS_STATS_RESET
107 } vs_stats_req_t;
108 
109 typedef struct vs_stats {
110 	uint64_t vss_scanned;
111 	uint64_t vss_infected;
112 	uint64_t vss_cleaned;
113 	uint64_t vss_failed;
114 	struct {
115 		char vss_engid[VS_SE_NAME_LEN];
116 		uint64_t vss_errors;
117 	} vss_eng[VS_SE_MAX];
118 } vs_stats_t;
119 
120 /*
121  *  General service configuration properties
122  */
123 typedef struct vs_props {
124 	char vp_maxsize[VS_VAL_MAXSIZE_LEN];
125 	boolean_t vp_maxsize_action;
126 	char vp_types[VS_VAL_TYPES_LEN];
127 	char vp_vlog[MAXPATHLEN];
128 } vs_props_t;
129 
130 /*
131  *  Scan engine configuration properties.  These are defined
132  *  per-engine.
133  */
134 typedef struct vs_props_se {
135 	char vep_engid[VS_SE_NAME_LEN];
136 	boolean_t vep_enable;
137 	char vep_host[MAXHOSTNAMELEN];
138 	uint16_t vep_port;
139 	uint64_t vep_maxconn;
140 } vs_props_se_t;
141 
142 typedef struct vs_props_all {
143 	vs_props_t va_props;
144 	vs_props_se_t va_se[VS_SE_MAX];
145 } vs_props_all_t;
146 
147 
148 /*
149  * General service configuration properties API
150  * These functions return VS_ERR_XXX error codes.
151  */
152 int vs_props_get_all(vs_props_all_t *);
153 int vs_props_set(const vs_props_t *, uint64_t);
154 int vs_props_get(vs_props_t *, uint64_t);
155 int vs_props_validate(const vs_props_t *, uint64_t);
156 
157 
158 /*
159  * Scan engine configuration properties API
160  * These functions return VS_ERR_XXX error codes.
161  */
162 int vs_props_se_create(char *, const vs_props_se_t *, uint64_t);
163 int vs_props_se_set(char *, const vs_props_se_t *, uint64_t);
164 int vs_props_se_get(char *, vs_props_se_t *, uint64_t);
165 int vs_props_se_validate(const vs_props_se_t *, uint64_t);
166 int vs_props_se_delete(const char *);
167 
168 
169 /* Get error string for error code */
170 const char *vs_strerror(int);
171 
172 /* Functions to access/reset scan statistics in service daemon */
173 int vs_statistics(vs_stats_t *);
174 int vs_statistics_reset(void);
175 
176 
177 /*  Utility functions */
178 
179 /*
180  * Replace comma separators with '\0'.
181  *
182  * Types contains comma separated rules each beginning with +|-
183  *   - embedded commas are escaped by backslash
184  *   - backslash is escaped by backslash
185  *   - a single backslash not followed by comma is illegal
186  *
187  * On entry to the function len must contain the length of
188  * the buffer. On sucecssful exit len will contain the length
189  * of the parsed data within the buffer.
190  *
191  * Returns 0 on success, -1 on failure
192  */
193 int vs_parse_types(const char *, char *, uint32_t *);
194 
195 
196 /*
197  * Converts a size string in the format into an integer.
198  *
199  * A size string is a numeric value followed by an optional unit
200  * specifier which is used as a multiplier to calculate a raw
201  * number.
202  * The size string format is:  N[.N][KMGTP][B]
203  *
204  * The numeric value can contain a decimal portion. Unit specifiers
205  * are either a one-character or two-character string; i.e. "K" or
206  * "KB" for kilobytes. Unit specifiers must follow the numeric portion
207  * immediately, and are not case-sensitive.
208  *
209  * If either "B" is specified, or there is no unit specifier portion
210  * in the string, the numeric value is calculated with no multiplier
211  * (assumes a basic unit of "bytes").
212  *
213  * Returns: -1: Failure; errno set to specify the error.
214  *           0: Success.
215  */
216 int vs_strtonum(const char *, uint64_t *);
217 
218 #ifdef __cplusplus
219 }
220 #endif
221 
222 #endif /* __LIBVS_H__ */
223