15440Sjm199354 /* 25440Sjm199354 * CDDL HEADER START 35440Sjm199354 * 45440Sjm199354 * The contents of this file are subject to the terms of the 55440Sjm199354 * Common Development and Distribution License (the "License"). 65440Sjm199354 * You may not use this file except in compliance with the License. 75440Sjm199354 * 85440Sjm199354 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 95440Sjm199354 * or http://www.opensolaris.org/os/licensing. 105440Sjm199354 * See the License for the specific language governing permissions 115440Sjm199354 * and limitations under the License. 125440Sjm199354 * 135440Sjm199354 * When distributing Covered Code, include this CDDL HEADER in each 145440Sjm199354 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 155440Sjm199354 * If applicable, add the following below this CDDL HEADER, with the 165440Sjm199354 * fields enclosed by brackets "[]" replaced with your own identifying 175440Sjm199354 * information: Portions Copyright [yyyy] [name of copyright owner] 185440Sjm199354 * 195440Sjm199354 * CDDL HEADER END 205440Sjm199354 */ 215440Sjm199354 /* 22*6407Sjm199354 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 235440Sjm199354 * Use is subject to license terms. 245440Sjm199354 */ 255440Sjm199354 265440Sjm199354 #pragma ident "%Z%%M% %I% %E% SMI" 275440Sjm199354 285440Sjm199354 #ifndef __LIBVS_H__ 295440Sjm199354 #define __LIBVS_H__ 305440Sjm199354 315440Sjm199354 #include <netdb.h> 325440Sjm199354 #include <netinet/in.h> 335440Sjm199354 345440Sjm199354 #ifdef __cplusplus 355440Sjm199354 extern "C" { 365440Sjm199354 #endif 375440Sjm199354 385440Sjm199354 /* Property IDs - general property group */ 395440Sjm199354 #define VS_PROPID_MAXSIZE 0x01LL 405440Sjm199354 #define VS_PROPID_MAXSIZE_ACTION 0x02LL 415440Sjm199354 #define VS_PROPID_TYPES 0x04LL 425440Sjm199354 #define VS_PROPID_VLOG 0x08LL 435440Sjm199354 445440Sjm199354 #define VS_PROPID_GEN_ALL (VS_PROPID_MAXSIZE | \ 455440Sjm199354 VS_PROPID_MAXSIZE_ACTION | VS_PROPID_TYPES | VS_PROPID_VLOG) 465440Sjm199354 475440Sjm199354 #define VS_PROPID_VALUE_AUTH 0x010LL 485440Sjm199354 495440Sjm199354 /* Property IDs - scan engine property groups */ 505440Sjm199354 #define VS_PROPID_SE_ENABLE 0x100LL 515440Sjm199354 #define VS_PROPID_SE_HOST 0x200LL 525440Sjm199354 #define VS_PROPID_SE_PORT 0x400LL 535440Sjm199354 #define VS_PROPID_SE_MAXCONN 0x800LL 545440Sjm199354 555440Sjm199354 #define VS_PROPID_SE_ALL (VS_PROPID_SE_ENABLE | \ 565440Sjm199354 VS_PROPID_SE_HOST | VS_PROPID_SE_PORT | VS_PROPID_SE_MAXCONN) 575440Sjm199354 585440Sjm199354 /* Check for whether a property id is a scan engine id */ 595440Sjm199354 #define VS_PROPID_IS_SE(id) ((id & VS_PROPID_SE_ALL) ? 1 : 0) 605440Sjm199354 615440Sjm199354 /* The maximum property id value - across all property groups */ 625440Sjm199354 #define VS_PROPID_MAX VS_PROPID_SE_MAXCONN 635440Sjm199354 645440Sjm199354 /* The number of properties in the largest property group */ 655440Sjm199354 #define VS_NUM_PROPIDS 5 665440Sjm199354 675440Sjm199354 /* Range of scan engine IDs and max number of scan engines supported */ 685440Sjm199354 #define VS_SE_MAX 16 695440Sjm199354 #define VS_SE_NAME_LEN 64 705440Sjm199354 715440Sjm199354 /* Min & Max scan engine connections per engine */ 725440Sjm199354 #define VS_VAL_SE_MAXCONN_MIN 1 735440Sjm199354 #define VS_VAL_SE_MAXCONN_MAX 512 745440Sjm199354 755440Sjm199354 /* Can accommodate a string-ified ULONG_MAX plus unit specifier */ 765440Sjm199354 #define VS_VAL_MAXSIZE_LEN 32 775440Sjm199354 785440Sjm199354 #define VS_VAL_TYPES_LEN 4096 795440Sjm199354 #define VS_VAL_TYPES_INVALID_CHARS "." 805440Sjm199354 815440Sjm199354 /* libvscan error codes */ 825440Sjm199354 #define VS_ERR_NONE 0 835440Sjm199354 #define VS_ERR_INVALID_PROPERTY 1 845440Sjm199354 #define VS_ERR_INVALID_VALUE 2 855440Sjm199354 #define VS_ERR_INVALID_HOST 3 865440Sjm199354 #define VS_ERR_INVALID_SE 4 875440Sjm199354 #define VS_ERR_MAX_SE 5 885440Sjm199354 #define VS_ERR_AUTH 6 895440Sjm199354 #define VS_ERR_DAEMON_COMM 10 905440Sjm199354 #define VS_ERR_SCF 20 915440Sjm199354 #define VS_ERR_SYS 30 925440Sjm199354 935440Sjm199354 945440Sjm199354 /* RBAC authorizations */ 955440Sjm199354 #define VS_VALUE_AUTH "solaris.smf.value.vscan" 965440Sjm199354 #define VS_ACTION_AUTH "solaris.smf.manage.vscan" 975440Sjm199354 #define VS_MODIFY_AUTH "solaris.smf.modify.application" 985440Sjm199354 995440Sjm199354 /* statistics door interface */ 1005440Sjm199354 #define VS_STATS_DOOR_NAME "/var/run/vscan_stats_door" 1015440Sjm199354 #define VS_STATS_DOOR_VERSION 1 102*6407Sjm199354 #define VS_STATS_DOOR_MAGIC 0x56535354 /* VSST - VScanStats */ 1035440Sjm199354 1045440Sjm199354 /* scan statistics door request type */ 1055440Sjm199354 typedef enum { 1065440Sjm199354 VS_STATS_GET, 1075440Sjm199354 VS_STATS_RESET 108*6407Sjm199354 } vs_stats_req_type_t; 109*6407Sjm199354 110*6407Sjm199354 typedef struct vs_stats_req { 111*6407Sjm199354 uint32_t vsr_magic; 112*6407Sjm199354 vs_stats_req_type_t vsr_id; 1135440Sjm199354 } vs_stats_req_t; 1145440Sjm199354 1155440Sjm199354 typedef struct vs_stats { 1165440Sjm199354 uint64_t vss_scanned; 1175440Sjm199354 uint64_t vss_infected; 1185440Sjm199354 uint64_t vss_cleaned; 1195440Sjm199354 uint64_t vss_failed; 1205440Sjm199354 struct { 1215440Sjm199354 char vss_engid[VS_SE_NAME_LEN]; 1225440Sjm199354 uint64_t vss_errors; 1235440Sjm199354 } vss_eng[VS_SE_MAX]; 1245440Sjm199354 } vs_stats_t; 1255440Sjm199354 126*6407Sjm199354 typedef struct vs_stats_rsp { 127*6407Sjm199354 uint32_t vsr_magic; 128*6407Sjm199354 vs_stats_t vsr_stats; 129*6407Sjm199354 } vs_stats_rsp_t; 130*6407Sjm199354 131*6407Sjm199354 132*6407Sjm199354 1335440Sjm199354 /* 1345440Sjm199354 * General service configuration properties 1355440Sjm199354 */ 1365440Sjm199354 typedef struct vs_props { 1375440Sjm199354 char vp_maxsize[VS_VAL_MAXSIZE_LEN]; 1385440Sjm199354 boolean_t vp_maxsize_action; 1395440Sjm199354 char vp_types[VS_VAL_TYPES_LEN]; 1405440Sjm199354 char vp_vlog[MAXPATHLEN]; 1415440Sjm199354 } vs_props_t; 1425440Sjm199354 1435440Sjm199354 /* 1445440Sjm199354 * Scan engine configuration properties. These are defined 1455440Sjm199354 * per-engine. 1465440Sjm199354 */ 1475440Sjm199354 typedef struct vs_props_se { 1485440Sjm199354 char vep_engid[VS_SE_NAME_LEN]; 1495440Sjm199354 boolean_t vep_enable; 1505440Sjm199354 char vep_host[MAXHOSTNAMELEN]; 1515440Sjm199354 uint16_t vep_port; 1525440Sjm199354 uint64_t vep_maxconn; 1535440Sjm199354 } vs_props_se_t; 1545440Sjm199354 1555440Sjm199354 typedef struct vs_props_all { 1565440Sjm199354 vs_props_t va_props; 1575440Sjm199354 vs_props_se_t va_se[VS_SE_MAX]; 1585440Sjm199354 } vs_props_all_t; 1595440Sjm199354 1605440Sjm199354 1615440Sjm199354 /* 1625440Sjm199354 * General service configuration properties API 1635440Sjm199354 * These functions return VS_ERR_XXX error codes. 1645440Sjm199354 */ 1655440Sjm199354 int vs_props_get_all(vs_props_all_t *); 1665440Sjm199354 int vs_props_set(const vs_props_t *, uint64_t); 1675440Sjm199354 int vs_props_get(vs_props_t *, uint64_t); 1685440Sjm199354 int vs_props_validate(const vs_props_t *, uint64_t); 1695440Sjm199354 1705440Sjm199354 1715440Sjm199354 /* 1725440Sjm199354 * Scan engine configuration properties API 1735440Sjm199354 * These functions return VS_ERR_XXX error codes. 1745440Sjm199354 */ 1755440Sjm199354 int vs_props_se_create(char *, const vs_props_se_t *, uint64_t); 1765440Sjm199354 int vs_props_se_set(char *, const vs_props_se_t *, uint64_t); 1775440Sjm199354 int vs_props_se_get(char *, vs_props_se_t *, uint64_t); 1785440Sjm199354 int vs_props_se_validate(const vs_props_se_t *, uint64_t); 1795440Sjm199354 int vs_props_se_delete(const char *); 1805440Sjm199354 1815440Sjm199354 1825440Sjm199354 /* Get error string for error code */ 1835440Sjm199354 const char *vs_strerror(int); 1845440Sjm199354 1855440Sjm199354 /* Functions to access/reset scan statistics in service daemon */ 1865440Sjm199354 int vs_statistics(vs_stats_t *); 1875440Sjm199354 int vs_statistics_reset(void); 1885440Sjm199354 1895440Sjm199354 1905440Sjm199354 /* Utility functions */ 1915440Sjm199354 1925440Sjm199354 /* 1935440Sjm199354 * Replace comma separators with '\0'. 1945440Sjm199354 * 1955440Sjm199354 * Types contains comma separated rules each beginning with +|- 1965440Sjm199354 * - embedded commas are escaped by backslash 1975440Sjm199354 * - backslash is escaped by backslash 1985440Sjm199354 * - a single backslash not followed by comma is illegal 1995440Sjm199354 * 2005440Sjm199354 * On entry to the function len must contain the length of 2015440Sjm199354 * the buffer. On sucecssful exit len will contain the length 2025440Sjm199354 * of the parsed data within the buffer. 2035440Sjm199354 * 2045440Sjm199354 * Returns 0 on success, -1 on failure 2055440Sjm199354 */ 2065440Sjm199354 int vs_parse_types(const char *, char *, uint32_t *); 2075440Sjm199354 2085440Sjm199354 2095440Sjm199354 /* 2105440Sjm199354 * Converts a size string in the format into an integer. 2115440Sjm199354 * 2125440Sjm199354 * A size string is a numeric value followed by an optional unit 2135440Sjm199354 * specifier which is used as a multiplier to calculate a raw 2145440Sjm199354 * number. 2155440Sjm199354 * The size string format is: N[.N][KMGTP][B] 2165440Sjm199354 * 2175440Sjm199354 * The numeric value can contain a decimal portion. Unit specifiers 2185440Sjm199354 * are either a one-character or two-character string; i.e. "K" or 2195440Sjm199354 * "KB" for kilobytes. Unit specifiers must follow the numeric portion 2205440Sjm199354 * immediately, and are not case-sensitive. 2215440Sjm199354 * 2225440Sjm199354 * If either "B" is specified, or there is no unit specifier portion 2235440Sjm199354 * in the string, the numeric value is calculated with no multiplier 2245440Sjm199354 * (assumes a basic unit of "bytes"). 2255440Sjm199354 * 2265440Sjm199354 * Returns: -1: Failure; errno set to specify the error. 2275440Sjm199354 * 0: Success. 2285440Sjm199354 */ 2295440Sjm199354 int vs_strtonum(const char *, uint64_t *); 2305440Sjm199354 2315440Sjm199354 #ifdef __cplusplus 2325440Sjm199354 } 2335440Sjm199354 #endif 2345440Sjm199354 2355440Sjm199354 #endif /* __LIBVS_H__ */ 236