xref: /illumos-gate/usr/src/uts/common/sys/vscan.h (revision b6c3f786)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_VSCAN_H
27 #define	_VSCAN_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 #include <sys/param.h>
36 #include <sys/vnode.h>
37 
38 /*
39  * vscan.h provides definitions for vscan kernel module
40  */
41 
42 #define	VS_DRV_MAX_FILES	1024	/* max concurent file scans */
43 #define	VS_DRV_PATH		"/devices/pseudo/vscan@0:vscan"
44 #define	VS_DRV_IOCTL_ENABLE	0x0001	/* door rendezvous */
45 #define	VS_DRV_IOCTL_DISABLE	0x0002	/* vscand shutting down */
46 #define	VS_DRV_IOCTL_CONFIG	0x0004	/* vscand config data update */
47 
48 /* Scan Result - vsr_result */
49 #define	VS_STATUS_UNDEFINED	0
50 #define	VS_STATUS_NO_SCAN	1 /* scan not required */
51 #define	VS_STATUS_ERROR		2 /* scan failed */
52 #define	VS_STATUS_CLEAN		3 /* scan successful, file clean */
53 #define	VS_STATUS_INFECTED	4 /* scan successful, file infected */
54 
55 #define	VS_TYPES_LEN		4096	/* vs_config_t - types buffer */
56 
57 /*
58  * AV_SCANSTAMP_SZ is the size of the scanstamp stored in the
59  * filesystem. vs_scanstamp_t is 1 character longer to allow
60  * a null terminated string to be used within vscan
61  */
62 typedef char vs_scanstamp_t[AV_SCANSTAMP_SZ + 1];
63 
64 /* used for both request to and response from vscand */
65 typedef struct vs_scan_req {
66 	uint32_t vsr_id;
67 	uint32_t vsr_flags;
68 	uint64_t vsr_size;
69 	uint8_t vsr_modified;
70 	uint8_t vsr_quarantined;
71 	char vsr_path[MAXPATHLEN];
72 	vs_scanstamp_t vsr_scanstamp;
73 	uint32_t vsr_result;
74 } vs_scan_req_t;
75 
76 
77 /* passed in VS_DRV_IOCTL_CONFIG */
78 typedef struct vs_config {
79 	char vsc_types[VS_TYPES_LEN];
80 	uint64_t vsc_types_len;
81 	uint64_t vsc_max_size;	/* files > max size (bytes) not scan */
82 	uint64_t vsc_allow;	/* allow access to file exceeding max_size? */
83 } vs_config_t;
84 
85 
86 #ifdef _KERNEL
87 
88 /*
89  * max no of types in vs_config_t.vsc_types
90  * used as dimention for array of pointers to types
91  */
92 #define	VS_TYPES_MAX		VS_TYPES_LEN / 2
93 
94 /*
95  * seconds to wait for daemon to reconnect before unregistering from VFS
96  * during this time, the kernel will:
97  * - allow access to files that have not been modified since last scanned
98  * - deny access to files which have been modified since last scanned
99  */
100 #define	VS_DAEMON_WAIT_SEC	60
101 
102 /* access derived from scan result (VS_STATUS_XXX) and file attributes */
103 #define	VS_ACCESS_UNDEFINED	0
104 #define	VS_ACCESS_ALLOW		1
105 #define	VS_ACCESS_DENY		2
106 
107 int vscan_svc_init(void);
108 void vscan_svc_fini(void);
109 void vscan_svc_enable(void);
110 void vscan_svc_disable(void);
111 int vscan_svc_configure(vs_config_t *);
112 boolean_t vscan_svc_is_enabled(void);
113 boolean_t vscan_svc_in_use(void);
114 vnode_t *vscan_svc_get_vnode(int);
115 
116 int vscan_door_init(void);
117 void vscan_door_fini(void);
118 int vscan_door_open(int);
119 void vscan_door_close(void);
120 int vscan_door_scan_file(vs_scan_req_t *);
121 
122 boolean_t vscan_drv_create_node(int);
123 
124 #endif /* _KERNEL */
125 
126 #ifdef __cplusplus
127 }
128 #endif
129 
130 
131 #endif /* _VSCAN_H */
132