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