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