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.
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.
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]
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #pragma ident "%Z%%M% %I% %E% SMI"
31 #include <sys/param.h>
33 #include <netinet/in.h>
39 /* Property IDs - general property group */
40 #define VS_PROPID_MAXSIZE 0x01LL
41 #define VS_PROPID_MAXSIZE_ACTION 0x02LL
42 #define VS_PROPID_TYPES 0x04LL
43 #define VS_PROPID_VLOG 0x08LL
45 #define VS_PROPID_GEN_ALL (VS_PROPID_MAXSIZE | \
46 VS_PROPID_MAXSIZE_ACTION | VS_PROPID_TYPES | VS_PROPID_VLOG)
48 #define VS_PROPID_VALUE_AUTH 0x010LL
50 /* Property IDs - scan engine property groups */
51 #define VS_PROPID_SE_ENABLE 0x100LL
52 #define VS_PROPID_SE_HOST 0x200LL
53 #define VS_PROPID_SE_PORT 0x400LL
54 #define VS_PROPID_SE_MAXCONN 0x800LL
56 #define VS_PROPID_SE_ALL (VS_PROPID_SE_ENABLE | \
57 VS_PROPID_SE_HOST | VS_PROPID_SE_PORT | VS_PROPID_SE_MAXCONN)
59 /* Check for whether a property id is a scan engine id */
60 #define VS_PROPID_IS_SE(id) ((id & VS_PROPID_SE_ALL) ? 1 : 0)
62 /* The maximum property id value - across all property groups */
63 #define VS_PROPID_MAX VS_PROPID_SE_MAXCONN
65 /* The number of properties in the largest property group */
66 #define VS_NUM_PROPIDS 5
68 /* Range of scan engine IDs and max number of scan engines supported */
70 #define VS_SE_NAME_LEN 64
72 /* Min & Max scan engine connections per engine */
73 #define VS_VAL_SE_MAXCONN_MIN 1
74 #define VS_VAL_SE_MAXCONN_MAX 512
76 /* Can accommodate a string-ified ULONG_MAX plus unit specifier */
77 #define VS_VAL_MAXSIZE_LEN 32
79 #define VS_VAL_TYPES_LEN 4096
80 #define VS_VAL_TYPES_INVALID_CHARS "."
82 /* libvscan error codes */
84 #define VS_ERR_INVALID_PROPERTY 1
85 #define VS_ERR_INVALID_VALUE 2
86 #define VS_ERR_INVALID_HOST 3
87 #define VS_ERR_INVALID_SE 4
88 #define VS_ERR_MAX_SE 5
90 #define VS_ERR_DAEMON_COMM 10
95 /* RBAC authorizations */
96 #define VS_VALUE_AUTH "solaris.smf.value.vscan"
97 #define VS_ACTION_AUTH "solaris.smf.manage.vscan"
98 #define VS_MODIFY_AUTH "solaris.smf.modify.application"
100 /* statistics door interface */
101 #define VS_STATS_DOOR_NAME "/var/run/vscan_stats_door"
102 #define VS_STATS_DOOR_VERSION 1
103 #define VS_STATS_DOOR_MAGIC 0x56535354 /* VSST - VScanStats */
105 /* scan statistics door request type */
109 } vs_stats_req_type_t
;
111 typedef struct vs_stats_req
{
113 vs_stats_req_type_t vsr_id
;
116 typedef struct vs_stats
{
117 uint64_t vss_scanned
;
118 uint64_t vss_infected
;
119 uint64_t vss_cleaned
;
122 char vss_engid
[VS_SE_NAME_LEN
];
124 } vss_eng
[VS_SE_MAX
];
127 typedef struct vs_stats_rsp
{
129 vs_stats_t vsr_stats
;
135 * General service configuration properties
137 typedef struct vs_props
{
138 char vp_maxsize
[VS_VAL_MAXSIZE_LEN
];
139 boolean_t vp_maxsize_action
;
140 char vp_types
[VS_VAL_TYPES_LEN
];
141 char vp_vlog
[MAXPATHLEN
];
145 * Scan engine configuration properties. These are defined
148 typedef struct vs_props_se
{
149 char vep_engid
[VS_SE_NAME_LEN
];
150 boolean_t vep_enable
;
151 char vep_host
[MAXHOSTNAMELEN
];
153 uint64_t vep_maxconn
;
156 typedef struct vs_props_all
{
158 vs_props_se_t va_se
[VS_SE_MAX
];
163 * General service configuration properties API
164 * These functions return VS_ERR_XXX error codes.
166 int vs_props_get_all(vs_props_all_t
*);
167 int vs_props_set(const vs_props_t
*, uint64_t);
168 int vs_props_get(vs_props_t
*, uint64_t);
169 int vs_props_validate(const vs_props_t
*, uint64_t);
173 * Scan engine configuration properties API
174 * These functions return VS_ERR_XXX error codes.
176 int vs_props_se_create(char *, const vs_props_se_t
*, uint64_t);
177 int vs_props_se_set(char *, const vs_props_se_t
*, uint64_t);
178 int vs_props_se_get(char *, vs_props_se_t
*, uint64_t);
179 int vs_props_se_validate(const vs_props_se_t
*, uint64_t);
180 int vs_props_se_delete(const char *);
183 /* Get error string for error code */
184 const char *vs_strerror(int);
186 /* Functions to access/reset scan statistics in service daemon */
187 int vs_statistics(vs_stats_t
*);
188 int vs_statistics_reset(void);
191 /* Utility functions */
194 * Replace comma separators with '\0'.
196 * Types contains comma separated rules each beginning with +|-
197 * - embedded commas are escaped by backslash
198 * - backslash is escaped by backslash
199 * - a single backslash not followed by comma is illegal
201 * On entry to the function len must contain the length of
202 * the buffer. On sucecssful exit len will contain the length
203 * of the parsed data within the buffer.
205 * Returns 0 on success, -1 on failure
207 int vs_parse_types(const char *, char *, uint32_t *);
211 * Converts a size string in the format into an integer.
213 * A size string is a numeric value followed by an optional unit
214 * specifier which is used as a multiplier to calculate a raw
216 * The size string format is: N[.N][KMGTP][B]
218 * The numeric value can contain a decimal portion. Unit specifiers
219 * are either a one-character or two-character string; i.e. "K" or
220 * "KB" for kilobytes. Unit specifiers must follow the numeric portion
221 * immediately, and are not case-sensitive.
223 * If either "B" is specified, or there is no unit specifier portion
224 * in the string, the numeric value is calculated with no multiplier
225 * (assumes a basic unit of "bytes").
227 * Returns: -1: Failure; errno set to specify the error.
230 int vs_strtonum(const char *, uint64_t *);
236 #endif /* __LIBVS_H__ */