summaryrefslogtreecommitdiff
path: root/usr/src/cmd/vscan/vscand/vs_icap.h
blob: d6549388132b4c955d5050b8f00b2795ac4a2c8e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */
/*
 * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 */

/*
 * PRIVATE header file for the icap client vs_icap.c
 */

#ifndef _VS_ICAP_H_
#define	_VS_ICAP_H_

#pragma ident	"%Z%%M%	%I%	%E% SMI"

#ifdef __cplusplus
extern "C" {
#endif

/* macros */
#define	MATCH(a, b)	(!strncasecmp((a), (b), strlen((b))))

#define	VS_ICAP_VER	"ICAP/1.0"

/* max sizes for vs_options_t */
#define	VS_DEFN_SZ	32
#define	VS_SERVICE_SZ	64

#define	VS_BUF_SZ	4096	/* keep this a power-of-two value. */
#define	VS_HDR_SZ	8	/* > length of VS_BUF_SZ in hex + 2 for \r\n */
#define	VS_TAIL_SZ	8	/* > \r\n */
#define	VS_ENCAP_SZ	64	/* space reserved in header for encap offsets */
#define	VS_TERMINATION	"0\r\n\r\n"

/*
 * The Symantec ICAP server REQUIRES the "avscan" resource name
 * after the IP address in the OPTIONS and  RESPMOD requests
 * This is ignored by the other ICAP servers.
 */
#define	VS_SERVICE_NAME "avscan"

/* infection/violation record processing */
#define	VS_VIOLATION_LINES   4
#define	VS_INFECTION_FIELDS  3

/* previewing files */
#define	VS_MIN_PREVIEW_LEN	4

/* defines which files types should be previewed */
typedef enum {
	VS_PREVIEW_ALL = 1,	/* preview all files */
	VS_PREVIEW_NONE,	/* preview no files, transfer all complete */
	VS_PREVIEW_LIST,	/* preview only files of listed types */
	VS_PREVIEW_EXCEPT	/* preview all files except listed types */
} vs_preview_t;

/* valid ICAP response codes */
typedef enum {
	VS_RESP_CONTINUE	= 100,
	VS_RESP_OK		= 200,
	VS_RESP_CREATED		= 201, /* file repaired. */
	VS_RESP_NO_CONT_NEEDED	= 204,
	VS_RESP_BAD_REQ		= 400,
	VS_RESP_FORBIDDEN	= 403, /* virus found but not repairable */
	VS_RESP_NOT_FOUND	= 404,
	VS_RESP_NOT_ALLOWED	= 405,
	VS_RESP_TIMEOUT		= 408,
	VS_RESP_INTERNAL_ERR	= 500,
	VS_RESP_NOT_IMPL	= 501,
	VS_RESP_SERV_UNAVAIL	= 503,  /* service unavailable or overloaded */
	VS_RESP_ICAP_VER_UNSUPP	= 505,
	/* Symantec additions - not ICAP standard */
	VS_RESP_SCAN_ERR	= 533,
	VS_RESP_NO_LICENSE	= 539,
	VS_RESP_RES_UNAVAIL	= 551,
	/* all else */
	VS_RESP_UNKNOWN
} vs_icap_resp_t;


/* the ICAP OPTIONS HEADERS used by NAS AVA */
typedef enum {
	VS_OPT_SERVICE = 1,
	VS_OPT_ISTAG,
	VS_OPT_METHODS,
	VS_OPT_ALLOW,
	VS_OPT_PREVIEW,
	VS_OPT_XFER_PREVIEW,
	VS_OPT_XFER_COMPLETE,
	VS_OPT_MAX_CONNECTIONS,
	VS_OPT_TTL,
	VS_OPT_X_DEF_INFO,
	VS_OPT_HDR_MAX = VS_OPT_X_DEF_INFO
} vs_option_hdr_t;


/*
 * the ICAP RESPMOD RESPONSE HEADERS used by NAS AVA
 *
 * Do NOT change the order of:
 * VS_RESP_X_VIRUS_ID, VS_RESP_X_INFECTION, VS_RESP_X_VIOLATIONS
 * Virus data saved from any one of these headers may be replaced
 * with data found in a preferable header (one with more info).
 * They are listed in order of preference.
 */
typedef enum {
	VS_RESP_ENCAPSULATED = 1,
	VS_RESP_ISTAG,
	VS_RESP_X_VIRUS_ID,
	VS_RESP_X_INFECTION,
	VS_RESP_X_VIOLATIONS,
	VS_RESP_HDR_MAX = VS_RESP_X_VIOLATIONS
} vs_resp_hdr_t;


/*
 * vs_options_t
 * vs_impl.c manages an array of vs_options_t, one per scan engine.
 * vs_options_t is used to store the scan engine configuration info
 * returned from the scan engine in the ICAP OPTIONS RESPONSE.
 * This information is then used to determine how to communicate with
 * the scan engines (eg which files to preview), when to resend the
 * ICAP OPTIONS REQUEST, and the istag is used as the scanstamp of
 * the file. The istag is also returned in the ICAP RESPMOD RESPONSE
 * and is used to update the stored one if it has changed.
 */
typedef struct vs_options {
	/* host & port used to detect config changes */
	char vso_host[MAXHOSTNAMELEN];
	int vso_port;

	/* configuration options returned from scan engine */
	int vso_preview_len;		/* the preview supported */
	int vso_allow;			/* allow 204 */
	vs_scanstamp_t vso_scanstamp;	/* from istag received */
	char vso_defninfo[VS_DEFN_SZ];	/* virus definition info */
	char vso_service[VS_SERVICE_SZ]; /* name of SE service */
	int vso_respmod;		/* set if RESPMOD method supported */
	vs_preview_t vso_xfer_how;	/* transfer preview or complete */
	iovec_t *vso_xfer_preview;	/* file exts supporting preview */
	iovec_t *vso_xfer_complete;	/* file exts to be sent complete */
	long vso_ttl;			/* after this expiry, re-get options */
	time_t vso_req_time;		/* time when option was last sent */
} vs_options_t;


/*
 * vs_info_t
 *
 * vs_info_t is part of the context created for each scan engine request.
 * It contains send/recv buffers and other temporary storage required
 * during the processing of the request/response.
 * threat_hdr_t defines from which header the virus information was
 * obtained. This is used to determine whether to overwrite existing
 * info if a 'better' header is found.
 */
typedef struct vs_info {
	char vsi_send_hdr[VS_HDR_SZ];
	char vsi_send_buf[VS_BUF_SZ + VS_TAIL_SZ];
	char vsi_recv_buf[VS_BUF_SZ];

	/*  response header information */
	boolean_t vsi_res_hdr;
	boolean_t vsi_res_body;
	boolean_t vsi_html_content;	/* L8R - set, not used */
	int	vsi_content_len;	/* L8R - set, not used */
	int	vsi_icap_rc;
	int	vsi_http_rc;
	int	vsi_threat_hdr;
} vs_info_t;


/*
 * vs_scan_ctx_t
 *
 * A vs_scan_ctx_t is created for each scan request. It will contain
 * everything that is needed to process the scan request and return
 * the response to the caller.
 * - engine connection information used to identify which scan engine
 *   the request is being sent to,
 * - information about the file being scanned,
 * - a place to store information about the file that will be created
 *   to hold cleaned data if the scan engine detects an infection
 *   and returns a cleaned version of the file,
 * - a copy of the vs_options_t for the scan engine. This allows the
 *   NAS AVA scan engine connection parameters to be reconfigured without
 *   affecting any in-progress requests,
 * - a vs_info_t - the temporary storage needed to process the request,
 * - a vs_result_t - a place to store the  scan result information to be
 *   returned to the caller.
 */
typedef struct vs_scan_ctx {
	/* scan engine idx and connection info */
	int vsc_idx;
	char vsc_host[MAXHOSTNAMELEN];
	int vsc_port;
	int vsc_sockfd;

	/* info about file to be scanned */
	int vsc_fd;
	char *vsc_fname;
	uint64_t vsc_fsize;
	int vsc_flags;

	/* file to hold repaired data */
	boolean_t vsc_repair;
	int vsc_repair_fd;
	char *vsc_repair_fname;

	vs_options_t vsc_options;
	vs_info_t vsc_info;
	vs_result_t *vsc_result;
} vs_scan_ctx_t;


/*
 * vs_icap_hdr_t
 *
 * vs_icap.c defines tables of handlers for each ICAP OPTIONS RESPONSE HEADER
 * and each ICAP RESPMOD RESPONSE HEADER which NAS AVA uses.
 * Each entry in these tables is an vs_hdr_t.
 */
typedef struct vs_hdr {
	int  vsh_id;
	char *vsh_name;
	int  (*vsh_func)(vs_scan_ctx_t *, int, char *);
}vs_hdr_t;


/*
 * vs_resp_msg_t
 *
 * vs_icap.c defines a table mapping ICAP response code values to text strings.
 * Each entry in this tables is a vs_resp_msg_t.
 */
typedef struct vs_resp_msg {
	int vsm_rc;
	char *vsm_msg;
} vs_resp_msg_t;

#ifdef __cplusplus
}
#endif

#endif /* _VS_ICAP_H_ */