1911106dfSjm199354 /* 2911106dfSjm199354 * CDDL HEADER START 3911106dfSjm199354 * 4911106dfSjm199354 * The contents of this file are subject to the terms of the 5911106dfSjm199354 * Common Development and Distribution License (the "License"). 6911106dfSjm199354 * You may not use this file except in compliance with the License. 7911106dfSjm199354 * 8911106dfSjm199354 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9911106dfSjm199354 * or http://www.opensolaris.org/os/licensing. 10911106dfSjm199354 * See the License for the specific language governing permissions 11911106dfSjm199354 * and limitations under the License. 12911106dfSjm199354 * 13911106dfSjm199354 * When distributing Covered Code, include this CDDL HEADER in each 14911106dfSjm199354 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15911106dfSjm199354 * If applicable, add the following below this CDDL HEADER, with the 16911106dfSjm199354 * fields enclosed by brackets "[]" replaced with your own identifying 17911106dfSjm199354 * information: Portions Copyright [yyyy] [name of copyright owner] 18911106dfSjm199354 * 19911106dfSjm199354 * CDDL HEADER END 20911106dfSjm199354 */ 21911106dfSjm199354 /* 22*bfc848c6Sjm199354 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 23911106dfSjm199354 * Use is subject to license terms. 24911106dfSjm199354 */ 25911106dfSjm199354 26911106dfSjm199354 #pragma ident "%Z%%M% %I% %E% SMI" 27911106dfSjm199354 28911106dfSjm199354 #ifndef __LIBVS_H__ 29911106dfSjm199354 #define __LIBVS_H__ 30911106dfSjm199354 31911106dfSjm199354 #include <netdb.h> 32911106dfSjm199354 #include <netinet/in.h> 33911106dfSjm199354 34911106dfSjm199354 #ifdef __cplusplus 35911106dfSjm199354 extern "C" { 36911106dfSjm199354 #endif 37911106dfSjm199354 38911106dfSjm199354 /* Property IDs - general property group */ 39911106dfSjm199354 #define VS_PROPID_MAXSIZE 0x01LL 40911106dfSjm199354 #define VS_PROPID_MAXSIZE_ACTION 0x02LL 41911106dfSjm199354 #define VS_PROPID_TYPES 0x04LL 42911106dfSjm199354 #define VS_PROPID_VLOG 0x08LL 43911106dfSjm199354 44911106dfSjm199354 #define VS_PROPID_GEN_ALL (VS_PROPID_MAXSIZE | \ 45911106dfSjm199354 VS_PROPID_MAXSIZE_ACTION | VS_PROPID_TYPES | VS_PROPID_VLOG) 46911106dfSjm199354 47911106dfSjm199354 #define VS_PROPID_VALUE_AUTH 0x010LL 48911106dfSjm199354 49911106dfSjm199354 /* Property IDs - scan engine property groups */ 50911106dfSjm199354 #define VS_PROPID_SE_ENABLE 0x100LL 51911106dfSjm199354 #define VS_PROPID_SE_HOST 0x200LL 52911106dfSjm199354 #define VS_PROPID_SE_PORT 0x400LL 53911106dfSjm199354 #define VS_PROPID_SE_MAXCONN 0x800LL 54911106dfSjm199354 55911106dfSjm199354 #define VS_PROPID_SE_ALL (VS_PROPID_SE_ENABLE | \ 56911106dfSjm199354 VS_PROPID_SE_HOST | VS_PROPID_SE_PORT | VS_PROPID_SE_MAXCONN) 57911106dfSjm199354 58911106dfSjm199354 /* Check for whether a property id is a scan engine id */ 59911106dfSjm199354 #define VS_PROPID_IS_SE(id) ((id & VS_PROPID_SE_ALL) ? 1 : 0) 60911106dfSjm199354 61911106dfSjm199354 /* The maximum property id value - across all property groups */ 62911106dfSjm199354 #define VS_PROPID_MAX VS_PROPID_SE_MAXCONN 63911106dfSjm199354 64911106dfSjm199354 /* The number of properties in the largest property group */ 65911106dfSjm199354 #define VS_NUM_PROPIDS 5 66911106dfSjm199354 67911106dfSjm199354 /* Range of scan engine IDs and max number of scan engines supported */ 68911106dfSjm199354 #define VS_SE_MAX 16 69911106dfSjm199354 #define VS_SE_NAME_LEN 64 70911106dfSjm199354 71911106dfSjm199354 /* Min & Max scan engine connections per engine */ 72911106dfSjm199354 #define VS_VAL_SE_MAXCONN_MIN 1 73911106dfSjm199354 #define VS_VAL_SE_MAXCONN_MAX 512 74911106dfSjm199354 75911106dfSjm199354 /* Can accommodate a string-ified ULONG_MAX plus unit specifier */ 76911106dfSjm199354 #define VS_VAL_MAXSIZE_LEN 32 77911106dfSjm199354 78911106dfSjm199354 #define VS_VAL_TYPES_LEN 4096 79911106dfSjm199354 #define VS_VAL_TYPES_INVALID_CHARS "." 80911106dfSjm199354 81911106dfSjm199354 /* libvscan error codes */ 82911106dfSjm199354 #define VS_ERR_NONE 0 83911106dfSjm199354 #define VS_ERR_INVALID_PROPERTY 1 84911106dfSjm199354 #define VS_ERR_INVALID_VALUE 2 85911106dfSjm199354 #define VS_ERR_INVALID_HOST 3 86911106dfSjm199354 #define VS_ERR_INVALID_SE 4 87911106dfSjm199354 #define VS_ERR_MAX_SE 5 88911106dfSjm199354 #define VS_ERR_AUTH 6 89911106dfSjm199354 #define VS_ERR_DAEMON_COMM 10 90911106dfSjm199354 #define VS_ERR_SCF 20 91911106dfSjm199354 #define VS_ERR_SYS 30 92911106dfSjm199354 93911106dfSjm199354 94911106dfSjm199354 /* RBAC authorizations */ 95911106dfSjm199354 #define VS_VALUE_AUTH "solaris.smf.value.vscan" 96911106dfSjm199354 #define VS_ACTION_AUTH "solaris.smf.manage.vscan" 97911106dfSjm199354 #define VS_MODIFY_AUTH "solaris.smf.modify.application" 98911106dfSjm199354 99911106dfSjm199354 /* statistics door interface */ 100911106dfSjm199354 #define VS_STATS_DOOR_NAME "/var/run/vscan_stats_door" 101911106dfSjm199354 #define VS_STATS_DOOR_VERSION 1 102*bfc848c6Sjm199354 #define VS_STATS_DOOR_MAGIC 0x56535354 /* VSST - VScanStats */ 103911106dfSjm199354 104911106dfSjm199354 /* scan statistics door request type */ 105911106dfSjm199354 typedef enum { 106911106dfSjm199354 VS_STATS_GET, 107911106dfSjm199354 VS_STATS_RESET 108*bfc848c6Sjm199354 } vs_stats_req_type_t; 109*bfc848c6Sjm199354 110*bfc848c6Sjm199354 typedef struct vs_stats_req { 111*bfc848c6Sjm199354 uint32_t vsr_magic; 112*bfc848c6Sjm199354 vs_stats_req_type_t vsr_id; 113911106dfSjm199354 } vs_stats_req_t; 114911106dfSjm199354 115911106dfSjm199354 typedef struct vs_stats { 116911106dfSjm199354 uint64_t vss_scanned; 117911106dfSjm199354 uint64_t vss_infected; 118911106dfSjm199354 uint64_t vss_cleaned; 119911106dfSjm199354 uint64_t vss_failed; 120911106dfSjm199354 struct { 121911106dfSjm199354 char vss_engid[VS_SE_NAME_LEN]; 122911106dfSjm199354 uint64_t vss_errors; 123911106dfSjm199354 } vss_eng[VS_SE_MAX]; 124911106dfSjm199354 } vs_stats_t; 125911106dfSjm199354 126*bfc848c6Sjm199354 typedef struct vs_stats_rsp { 127*bfc848c6Sjm199354 uint32_t vsr_magic; 128*bfc848c6Sjm199354 vs_stats_t vsr_stats; 129*bfc848c6Sjm199354 } vs_stats_rsp_t; 130*bfc848c6Sjm199354 131*bfc848c6Sjm199354 132*bfc848c6Sjm199354 133911106dfSjm199354 /* 134911106dfSjm199354 * General service configuration properties 135911106dfSjm199354 */ 136911106dfSjm199354 typedef struct vs_props { 137911106dfSjm199354 char vp_maxsize[VS_VAL_MAXSIZE_LEN]; 138911106dfSjm199354 boolean_t vp_maxsize_action; 139911106dfSjm199354 char vp_types[VS_VAL_TYPES_LEN]; 140911106dfSjm199354 char vp_vlog[MAXPATHLEN]; 141911106dfSjm199354 } vs_props_t; 142911106dfSjm199354 143911106dfSjm199354 /* 144911106dfSjm199354 * Scan engine configuration properties. These are defined 145911106dfSjm199354 * per-engine. 146911106dfSjm199354 */ 147911106dfSjm199354 typedef struct vs_props_se { 148911106dfSjm199354 char vep_engid[VS_SE_NAME_LEN]; 149911106dfSjm199354 boolean_t vep_enable; 150911106dfSjm199354 char vep_host[MAXHOSTNAMELEN]; 151911106dfSjm199354 uint16_t vep_port; 152911106dfSjm199354 uint64_t vep_maxconn; 153911106dfSjm199354 } vs_props_se_t; 154911106dfSjm199354 155911106dfSjm199354 typedef struct vs_props_all { 156911106dfSjm199354 vs_props_t va_props; 157911106dfSjm199354 vs_props_se_t va_se[VS_SE_MAX]; 158911106dfSjm199354 } vs_props_all_t; 159911106dfSjm199354 160911106dfSjm199354 161911106dfSjm199354 /* 162911106dfSjm199354 * General service configuration properties API 163911106dfSjm199354 * These functions return VS_ERR_XXX error codes. 164911106dfSjm199354 */ 165911106dfSjm199354 int vs_props_get_all(vs_props_all_t *); 166911106dfSjm199354 int vs_props_set(const vs_props_t *, uint64_t); 167911106dfSjm199354 int vs_props_get(vs_props_t *, uint64_t); 168911106dfSjm199354 int vs_props_validate(const vs_props_t *, uint64_t); 169911106dfSjm199354 170911106dfSjm199354 171911106dfSjm199354 /* 172911106dfSjm199354 * Scan engine configuration properties API 173911106dfSjm199354 * These functions return VS_ERR_XXX error codes. 174911106dfSjm199354 */ 175911106dfSjm199354 int vs_props_se_create(char *, const vs_props_se_t *, uint64_t); 176911106dfSjm199354 int vs_props_se_set(char *, const vs_props_se_t *, uint64_t); 177911106dfSjm199354 int vs_props_se_get(char *, vs_props_se_t *, uint64_t); 178911106dfSjm199354 int vs_props_se_validate(const vs_props_se_t *, uint64_t); 179911106dfSjm199354 int vs_props_se_delete(const char *); 180911106dfSjm199354 181911106dfSjm199354 182911106dfSjm199354 /* Get error string for error code */ 183911106dfSjm199354 const char *vs_strerror(int); 184911106dfSjm199354 185911106dfSjm199354 /* Functions to access/reset scan statistics in service daemon */ 186911106dfSjm199354 int vs_statistics(vs_stats_t *); 187911106dfSjm199354 int vs_statistics_reset(void); 188911106dfSjm199354 189911106dfSjm199354 190911106dfSjm199354 /* Utility functions */ 191911106dfSjm199354 192911106dfSjm199354 /* 193911106dfSjm199354 * Replace comma separators with '\0'. 194911106dfSjm199354 * 195911106dfSjm199354 * Types contains comma separated rules each beginning with +|- 196911106dfSjm199354 * - embedded commas are escaped by backslash 197911106dfSjm199354 * - backslash is escaped by backslash 198911106dfSjm199354 * - a single backslash not followed by comma is illegal 199911106dfSjm199354 * 200911106dfSjm199354 * On entry to the function len must contain the length of 201911106dfSjm199354 * the buffer. On sucecssful exit len will contain the length 202911106dfSjm199354 * of the parsed data within the buffer. 203911106dfSjm199354 * 204911106dfSjm199354 * Returns 0 on success, -1 on failure 205911106dfSjm199354 */ 206911106dfSjm199354 int vs_parse_types(const char *, char *, uint32_t *); 207911106dfSjm199354 208911106dfSjm199354 209911106dfSjm199354 /* 210911106dfSjm199354 * Converts a size string in the format into an integer. 211911106dfSjm199354 * 212911106dfSjm199354 * A size string is a numeric value followed by an optional unit 213911106dfSjm199354 * specifier which is used as a multiplier to calculate a raw 214911106dfSjm199354 * number. 215911106dfSjm199354 * The size string format is: N[.N][KMGTP][B] 216911106dfSjm199354 * 217911106dfSjm199354 * The numeric value can contain a decimal portion. Unit specifiers 218911106dfSjm199354 * are either a one-character or two-character string; i.e. "K" or 219911106dfSjm199354 * "KB" for kilobytes. Unit specifiers must follow the numeric portion 220911106dfSjm199354 * immediately, and are not case-sensitive. 221911106dfSjm199354 * 222911106dfSjm199354 * If either "B" is specified, or there is no unit specifier portion 223911106dfSjm199354 * in the string, the numeric value is calculated with no multiplier 224911106dfSjm199354 * (assumes a basic unit of "bytes"). 225911106dfSjm199354 * 226911106dfSjm199354 * Returns: -1: Failure; errno set to specify the error. 227911106dfSjm199354 * 0: Success. 228911106dfSjm199354 */ 229911106dfSjm199354 int vs_strtonum(const char *, uint64_t *); 230911106dfSjm199354 231911106dfSjm199354 #ifdef __cplusplus 232911106dfSjm199354 } 233911106dfSjm199354 #endif 234911106dfSjm199354 235911106dfSjm199354 #endif /* __LIBVS_H__ */ 236