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