xref: /titanic_44/usr/src/lib/libvscan/common/libvscan.h (revision db8b037b5616a366b7dfdc01ef9552f02f9adfdd)
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 2008 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 #define	VS_STATS_DOOR_MAGIC		0x56535354	/* VSST - VScanStats */
103 
104 /* scan statistics door request type */
105 typedef enum {
106 	VS_STATS_GET,
107 	VS_STATS_RESET
108 } vs_stats_req_type_t;
109 
110 typedef struct vs_stats_req {
111 	uint32_t vsr_magic;
112 	vs_stats_req_type_t vsr_id;
113 } vs_stats_req_t;
114 
115 typedef struct vs_stats {
116 	uint64_t vss_scanned;
117 	uint64_t vss_infected;
118 	uint64_t vss_cleaned;
119 	uint64_t vss_failed;
120 	struct {
121 		char vss_engid[VS_SE_NAME_LEN];
122 		uint64_t vss_errors;
123 	} vss_eng[VS_SE_MAX];
124 } vs_stats_t;
125 
126 typedef struct vs_stats_rsp {
127 	uint32_t vsr_magic;
128 	vs_stats_t vsr_stats;
129 } vs_stats_rsp_t;
130 
131 
132 
133 /*
134  *  General service configuration properties
135  */
136 typedef struct vs_props {
137 	char vp_maxsize[VS_VAL_MAXSIZE_LEN];
138 	boolean_t vp_maxsize_action;
139 	char vp_types[VS_VAL_TYPES_LEN];
140 	char vp_vlog[MAXPATHLEN];
141 } vs_props_t;
142 
143 /*
144  *  Scan engine configuration properties.  These are defined
145  *  per-engine.
146  */
147 typedef struct vs_props_se {
148 	char vep_engid[VS_SE_NAME_LEN];
149 	boolean_t vep_enable;
150 	char vep_host[MAXHOSTNAMELEN];
151 	uint16_t vep_port;
152 	uint64_t vep_maxconn;
153 } vs_props_se_t;
154 
155 typedef struct vs_props_all {
156 	vs_props_t va_props;
157 	vs_props_se_t va_se[VS_SE_MAX];
158 } vs_props_all_t;
159 
160 
161 /*
162  * General service configuration properties API
163  * These functions return VS_ERR_XXX error codes.
164  */
165 int vs_props_get_all(vs_props_all_t *);
166 int vs_props_set(const vs_props_t *, uint64_t);
167 int vs_props_get(vs_props_t *, uint64_t);
168 int vs_props_validate(const vs_props_t *, uint64_t);
169 
170 
171 /*
172  * Scan engine configuration properties API
173  * These functions return VS_ERR_XXX error codes.
174  */
175 int vs_props_se_create(char *, const vs_props_se_t *, uint64_t);
176 int vs_props_se_set(char *, const vs_props_se_t *, uint64_t);
177 int vs_props_se_get(char *, vs_props_se_t *, uint64_t);
178 int vs_props_se_validate(const vs_props_se_t *, uint64_t);
179 int vs_props_se_delete(const char *);
180 
181 
182 /* Get error string for error code */
183 const char *vs_strerror(int);
184 
185 /* Functions to access/reset scan statistics in service daemon */
186 int vs_statistics(vs_stats_t *);
187 int vs_statistics_reset(void);
188 
189 
190 /*  Utility functions */
191 
192 /*
193  * Replace comma separators with '\0'.
194  *
195  * Types contains comma separated rules each beginning with +|-
196  *   - embedded commas are escaped by backslash
197  *   - backslash is escaped by backslash
198  *   - a single backslash not followed by comma is illegal
199  *
200  * On entry to the function len must contain the length of
201  * the buffer. On sucecssful exit len will contain the length
202  * of the parsed data within the buffer.
203  *
204  * Returns 0 on success, -1 on failure
205  */
206 int vs_parse_types(const char *, char *, uint32_t *);
207 
208 
209 /*
210  * Converts a size string in the format into an integer.
211  *
212  * A size string is a numeric value followed by an optional unit
213  * specifier which is used as a multiplier to calculate a raw
214  * number.
215  * The size string format is:  N[.N][KMGTP][B]
216  *
217  * The numeric value can contain a decimal portion. Unit specifiers
218  * are either a one-character or two-character string; i.e. "K" or
219  * "KB" for kilobytes. Unit specifiers must follow the numeric portion
220  * immediately, and are not case-sensitive.
221  *
222  * If either "B" is specified, or there is no unit specifier portion
223  * in the string, the numeric value is calculated with no multiplier
224  * (assumes a basic unit of "bytes").
225  *
226  * Returns: -1: Failure; errno set to specify the error.
227  *           0: Success.
228  */
229 int vs_strtonum(const char *, uint64_t *);
230 
231 #ifdef __cplusplus
232 }
233 #endif
234 
235 #endif /* __LIBVS_H__ */
236