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