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 /* 27*911106dfSjm199354 * PRIVATE header file for the icap client vs_icap.c 28*911106dfSjm199354 */ 29*911106dfSjm199354 30*911106dfSjm199354 #ifndef _VS_ICAP_H_ 31*911106dfSjm199354 #define _VS_ICAP_H_ 32*911106dfSjm199354 33*911106dfSjm199354 #pragma ident "%Z%%M% %I% %E% SMI" 34*911106dfSjm199354 35*911106dfSjm199354 #ifdef __cplusplus 36*911106dfSjm199354 extern "C" { 37*911106dfSjm199354 #endif 38*911106dfSjm199354 39*911106dfSjm199354 /* macros */ 40*911106dfSjm199354 #define MATCH(a, b) (!strncasecmp((a), (b), strlen((b)))) 41*911106dfSjm199354 42*911106dfSjm199354 #define VS_ICAP_VER "ICAP/1.0" 43*911106dfSjm199354 44*911106dfSjm199354 /* max sizes for vs_options_t */ 45*911106dfSjm199354 #define VS_DEFN_SZ 32 46*911106dfSjm199354 #define VS_SERVICE_SZ 64 47*911106dfSjm199354 48*911106dfSjm199354 #define VS_BUF_SZ 4096 /* keep this a power-of-two value. */ 49*911106dfSjm199354 #define VS_HDR_SZ 8 /* > length of VS_BUF_SZ in hex + 2 for \r\n */ 50*911106dfSjm199354 #define VS_TAIL_SZ 8 /* > \r\n */ 51*911106dfSjm199354 #define VS_ENCAP_SZ 64 /* space reserved in header for encap offsets */ 52*911106dfSjm199354 #define VS_TERMINATION "0\r\n\r\n" 53*911106dfSjm199354 54*911106dfSjm199354 /* 55*911106dfSjm199354 * The Symantec ICAP server REQUIRES the "avscan" resource name 56*911106dfSjm199354 * after the IP address in the OPTIONS and RESPMOD requests 57*911106dfSjm199354 * This is ignored by the other ICAP servers. 58*911106dfSjm199354 */ 59*911106dfSjm199354 #define VS_SERVICE_NAME "avscan" 60*911106dfSjm199354 61*911106dfSjm199354 /* infection/violation record processing */ 62*911106dfSjm199354 #define VS_VIOLATION_LINES 4 63*911106dfSjm199354 #define VS_INFECTION_FIELDS 3 64*911106dfSjm199354 65*911106dfSjm199354 /* previewing files */ 66*911106dfSjm199354 #define VS_MIN_PREVIEW_LEN 4 67*911106dfSjm199354 68*911106dfSjm199354 /* defines which files types should be previewed */ 69*911106dfSjm199354 typedef enum { 70*911106dfSjm199354 VS_PREVIEW_ALL = 1, /* preview all files */ 71*911106dfSjm199354 VS_PREVIEW_NONE, /* preview no files, transfer all complete */ 72*911106dfSjm199354 VS_PREVIEW_LIST, /* preview only files of listed types */ 73*911106dfSjm199354 VS_PREVIEW_EXCEPT /* preview all files except listed types */ 74*911106dfSjm199354 } vs_preview_t; 75*911106dfSjm199354 76*911106dfSjm199354 /* valid ICAP response codes */ 77*911106dfSjm199354 typedef enum { 78*911106dfSjm199354 VS_RESP_CONTINUE = 100, 79*911106dfSjm199354 VS_RESP_OK = 200, 80*911106dfSjm199354 VS_RESP_CREATED = 201, /* file repaired. */ 81*911106dfSjm199354 VS_RESP_NO_CONT_NEEDED = 204, 82*911106dfSjm199354 VS_RESP_BAD_REQ = 400, 83*911106dfSjm199354 VS_RESP_FORBIDDEN = 403, /* virus found but not repairable */ 84*911106dfSjm199354 VS_RESP_NOT_FOUND = 404, 85*911106dfSjm199354 VS_RESP_NOT_ALLOWED = 405, 86*911106dfSjm199354 VS_RESP_TIMEOUT = 408, 87*911106dfSjm199354 VS_RESP_INTERNAL_ERR = 500, 88*911106dfSjm199354 VS_RESP_NOT_IMPL = 501, 89*911106dfSjm199354 VS_RESP_SERV_UNAVAIL = 503, /* service unavailable or overloaded */ 90*911106dfSjm199354 VS_RESP_ICAP_VER_UNSUPP = 505, 91*911106dfSjm199354 /* Symantec additions - not ICAP standard */ 92*911106dfSjm199354 VS_RESP_SCAN_ERR = 533, 93*911106dfSjm199354 VS_RESP_NO_LICENSE = 539, 94*911106dfSjm199354 VS_RESP_RES_UNAVAIL = 551, 95*911106dfSjm199354 /* all else */ 96*911106dfSjm199354 VS_RESP_UNKNOWN 97*911106dfSjm199354 } vs_icap_resp_t; 98*911106dfSjm199354 99*911106dfSjm199354 100*911106dfSjm199354 /* the ICAP OPTIONS HEADERS used by NAS AVA */ 101*911106dfSjm199354 typedef enum { 102*911106dfSjm199354 VS_OPT_SERVICE = 1, 103*911106dfSjm199354 VS_OPT_ISTAG, 104*911106dfSjm199354 VS_OPT_METHODS, 105*911106dfSjm199354 VS_OPT_ALLOW, 106*911106dfSjm199354 VS_OPT_PREVIEW, 107*911106dfSjm199354 VS_OPT_XFER_PREVIEW, 108*911106dfSjm199354 VS_OPT_XFER_COMPLETE, 109*911106dfSjm199354 VS_OPT_MAX_CONNECTIONS, 110*911106dfSjm199354 VS_OPT_TTL, 111*911106dfSjm199354 VS_OPT_X_DEF_INFO, 112*911106dfSjm199354 VS_OPT_HDR_MAX = VS_OPT_X_DEF_INFO 113*911106dfSjm199354 } vs_option_hdr_t; 114*911106dfSjm199354 115*911106dfSjm199354 116*911106dfSjm199354 /* 117*911106dfSjm199354 * the ICAP RESPMOD RESPONSE HEADERS used by NAS AVA 118*911106dfSjm199354 * 119*911106dfSjm199354 * Do NOT change the order of: 120*911106dfSjm199354 * VS_RESP_X_VIRUS_ID, VS_RESP_X_INFECTION, VS_RESP_X_VIOLATIONS 121*911106dfSjm199354 * Virus data saved from any one of these headers may be replaced 122*911106dfSjm199354 * with data found in a preferable header (one with more info). 123*911106dfSjm199354 * They are listed in order of preference. 124*911106dfSjm199354 */ 125*911106dfSjm199354 typedef enum { 126*911106dfSjm199354 VS_RESP_ENCAPSULATED = 1, 127*911106dfSjm199354 VS_RESP_ISTAG, 128*911106dfSjm199354 VS_RESP_X_VIRUS_ID, 129*911106dfSjm199354 VS_RESP_X_INFECTION, 130*911106dfSjm199354 VS_RESP_X_VIOLATIONS, 131*911106dfSjm199354 VS_RESP_HDR_MAX = VS_RESP_X_VIOLATIONS 132*911106dfSjm199354 } vs_resp_hdr_t; 133*911106dfSjm199354 134*911106dfSjm199354 135*911106dfSjm199354 /* 136*911106dfSjm199354 * vs_options_t 137*911106dfSjm199354 * vs_impl.c manages an array of vs_options_t, one per scan engine. 138*911106dfSjm199354 * vs_options_t is used to store the scan engine configuration info 139*911106dfSjm199354 * returned from the scan engine in the ICAP OPTIONS RESPONSE. 140*911106dfSjm199354 * This information is then used to determine how to communicate with 141*911106dfSjm199354 * the scan engines (eg which files to preview), when to resend the 142*911106dfSjm199354 * ICAP OPTIONS REQUEST, and the istag is used as the scanstamp of 143*911106dfSjm199354 * the file. The istag is also returned in the ICAP RESPMOD RESPONSE 144*911106dfSjm199354 * and is used to update the stored one if it has changed. 145*911106dfSjm199354 */ 146*911106dfSjm199354 typedef struct vs_options { 147*911106dfSjm199354 /* host & port used to detect config changes */ 148*911106dfSjm199354 char vso_host[MAXHOSTNAMELEN]; 149*911106dfSjm199354 int vso_port; 150*911106dfSjm199354 151*911106dfSjm199354 /* configuration options returned from scan engine */ 152*911106dfSjm199354 int vso_preview_len; /* the preview supported */ 153*911106dfSjm199354 int vso_allow; /* allow 204 */ 154*911106dfSjm199354 vs_scanstamp_t vso_scanstamp; /* from istag received */ 155*911106dfSjm199354 char vso_defninfo[VS_DEFN_SZ]; /* virus definition info */ 156*911106dfSjm199354 char vso_service[VS_SERVICE_SZ]; /* name of SE service */ 157*911106dfSjm199354 int vso_respmod; /* set if RESPMOD method supported */ 158*911106dfSjm199354 vs_preview_t vso_xfer_how; /* transfer preview or complete */ 159*911106dfSjm199354 iovec_t *vso_xfer_preview; /* file exts supporting preview */ 160*911106dfSjm199354 iovec_t *vso_xfer_complete; /* file exts to be sent complete */ 161*911106dfSjm199354 long vso_ttl; /* after this expiry, re-get options */ 162*911106dfSjm199354 time_t vso_req_time; /* time when option was last sent */ 163*911106dfSjm199354 } vs_options_t; 164*911106dfSjm199354 165*911106dfSjm199354 166*911106dfSjm199354 /* 167*911106dfSjm199354 * vs_info_t 168*911106dfSjm199354 * 169*911106dfSjm199354 * vs_info_t is part of the context created for each scan engine request. 170*911106dfSjm199354 * It contains send/recv buffers and other temporary storage required 171*911106dfSjm199354 * during the processing of the request/response. 172*911106dfSjm199354 * threat_hdr_t defines from which header the virus information was 173*911106dfSjm199354 * obtained. This is used to determine whether to overwrite existing 174*911106dfSjm199354 * info if a 'better' header is found. 175*911106dfSjm199354 */ 176*911106dfSjm199354 typedef struct vs_info { 177*911106dfSjm199354 char vsi_send_hdr[VS_HDR_SZ]; 178*911106dfSjm199354 char vsi_send_buf[VS_BUF_SZ + VS_TAIL_SZ]; 179*911106dfSjm199354 char vsi_recv_buf[VS_BUF_SZ]; 180*911106dfSjm199354 181*911106dfSjm199354 /* response header information */ 182*911106dfSjm199354 boolean_t vsi_res_hdr; 183*911106dfSjm199354 boolean_t vsi_res_body; 184*911106dfSjm199354 boolean_t vsi_html_content; /* L8R - set, not used */ 185*911106dfSjm199354 int vsi_content_len; /* L8R - set, not used */ 186*911106dfSjm199354 int vsi_icap_rc; 187*911106dfSjm199354 int vsi_http_rc; 188*911106dfSjm199354 int vsi_threat_hdr; 189*911106dfSjm199354 } vs_info_t; 190*911106dfSjm199354 191*911106dfSjm199354 192*911106dfSjm199354 /* 193*911106dfSjm199354 * vs_scan_ctx_t 194*911106dfSjm199354 * 195*911106dfSjm199354 * A vs_scan_ctx_t is created for each scan request. It will contain 196*911106dfSjm199354 * everything that is needed to process the scan request and return 197*911106dfSjm199354 * the response to the caller. 198*911106dfSjm199354 * - engine connection information used to identify which scan engine 199*911106dfSjm199354 * the request is being sent to, 200*911106dfSjm199354 * - information about the file being scanned, 201*911106dfSjm199354 * - a place to store information about the file that will be created 202*911106dfSjm199354 * to hold cleaned data if the scan engine detects an infection 203*911106dfSjm199354 * and returns a cleaned version of the file, 204*911106dfSjm199354 * - a copy of the vs_options_t for the scan engine. This allows the 205*911106dfSjm199354 * NAS AVA scan engine connection parameters to be reconfigured without 206*911106dfSjm199354 * affecting any in-progress requests, 207*911106dfSjm199354 * - a vs_info_t - the temporary storage needed to process the request, 208*911106dfSjm199354 * - a vs_result_t - a place to store the scan result information to be 209*911106dfSjm199354 * returned to the caller. 210*911106dfSjm199354 */ 211*911106dfSjm199354 typedef struct vs_scan_ctx { 212*911106dfSjm199354 /* scan engine idx and connection info */ 213*911106dfSjm199354 int vsc_idx; 214*911106dfSjm199354 char vsc_host[MAXHOSTNAMELEN]; 215*911106dfSjm199354 int vsc_port; 216*911106dfSjm199354 int vsc_sockfd; 217*911106dfSjm199354 218*911106dfSjm199354 /* info about file to be scanned */ 219*911106dfSjm199354 int vsc_fd; 220*911106dfSjm199354 char *vsc_fname; 221*911106dfSjm199354 uint64_t vsc_fsize; 222*911106dfSjm199354 int vsc_flags; 223*911106dfSjm199354 224*911106dfSjm199354 /* file to hold repaired data */ 225*911106dfSjm199354 boolean_t vsc_repair; 226*911106dfSjm199354 int vsc_repair_fd; 227*911106dfSjm199354 char *vsc_repair_fname; 228*911106dfSjm199354 229*911106dfSjm199354 vs_options_t vsc_options; 230*911106dfSjm199354 vs_info_t vsc_info; 231*911106dfSjm199354 vs_result_t *vsc_result; 232*911106dfSjm199354 } vs_scan_ctx_t; 233*911106dfSjm199354 234*911106dfSjm199354 235*911106dfSjm199354 /* 236*911106dfSjm199354 * vs_icap_hdr_t 237*911106dfSjm199354 * 238*911106dfSjm199354 * vs_icap.c defines tables of handlers for each ICAP OPTIONS RESPONSE HEADER 239*911106dfSjm199354 * and each ICAP RESPMOD RESPONSE HEADER which NAS AVA uses. 240*911106dfSjm199354 * Each entry in these tables is an vs_hdr_t. 241*911106dfSjm199354 */ 242*911106dfSjm199354 typedef struct vs_hdr { 243*911106dfSjm199354 int vsh_id; 244*911106dfSjm199354 char *vsh_name; 245*911106dfSjm199354 int (*vsh_func)(vs_scan_ctx_t *, int, char *); 246*911106dfSjm199354 }vs_hdr_t; 247*911106dfSjm199354 248*911106dfSjm199354 249*911106dfSjm199354 /* 250*911106dfSjm199354 * vs_resp_msg_t 251*911106dfSjm199354 * 252*911106dfSjm199354 * vs_icap.c defines a table mapping ICAP response code values to text strings. 253*911106dfSjm199354 * Each entry in this tables is a vs_resp_msg_t. 254*911106dfSjm199354 */ 255*911106dfSjm199354 typedef struct vs_resp_msg { 256*911106dfSjm199354 int vsm_rc; 257*911106dfSjm199354 char *vsm_msg; 258*911106dfSjm199354 } vs_resp_msg_t; 259*911106dfSjm199354 260*911106dfSjm199354 #ifdef __cplusplus 261*911106dfSjm199354 } 262*911106dfSjm199354 #endif 263*911106dfSjm199354 264*911106dfSjm199354 #endif /* _VS_ICAP_H_ */ 265