summaryrefslogtreecommitdiffstats
path: root/source3/modules/vfs_virusfilter_utils.h
blob: 69754aa6546e40cbd86639db9c8fed782bb50b82 (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
/*
   Samba-VirusFilter VFS modules
   Copyright (C) 2010-2016 SATOH Fumiyasu @ OSS Technology Corp., Japan

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef _VIRUSFILTER_UTILS_H
#define _VIRUSFILTER_UTILS_H

#include "modules/vfs_virusfilter_common.h"
#include "../lib/util/memcache.h"
#include "../lib/util/strv.h"

/*#define str_eq(s1, s2)		\
	((strcmp((s1), (s2)) == 0) ? true : false)
#define strn_eq(s1, s2, n)	\
	((strncmp((s1), (s2), (n)) == 0) ? true : false) */

/* "* 3" is for %-encoding */
#define VIRUSFILTER_IO_URL_MAX		(PATH_MAX * 3)
#define VIRUSFILTER_IO_BUFFER_SIZE	(VIRUSFILTER_IO_URL_MAX + 128)
#define VIRUSFILTER_IO_EOL_SIZE		1
#define VIRUSFILTER_IO_IOV_MAX		16
#define VIRUSFILTER_CACHE_BUFFER_SIZE	(PATH_MAX + 128)

struct virusfilter_io_handle {
	struct tstream_context *stream;
	int		connect_timeout;	/* msec */
	int		io_timeout;		/* msec */

	/* end-of-line character(s) */
	char		w_eol[VIRUSFILTER_IO_EOL_SIZE];
	int		w_eol_size;

	/* end-of-line character(s) */
	char		r_eol[VIRUSFILTER_IO_EOL_SIZE];
	int		r_eol_size;

	/* buffer */
	char		r_buffer[VIRUSFILTER_IO_BUFFER_SIZE];
	size_t		r_len;
};

struct virusfilter_cache_entry {
	time_t time;
	virusfilter_result result;
	char *report;
};

struct virusfilter_cache {
	struct memcache *cache;
	TALLOC_CTX *ctx;
	time_t time_limit;
};

/* ====================================================================== */

char *virusfilter_string_sub(
	TALLOC_CTX *mem_ctx,
	connection_struct *conn,
	const char *str);
int virusfilter_vfs_next_move(
	vfs_handle_struct *handle,
	const struct smb_filename *smb_fname_src,
	const struct smb_filename *smb_fname_dst);

/* Line-based socket I/O */
struct virusfilter_io_handle *virusfilter_io_new(
	TALLOC_CTX *mem_ctx,
	int connect_timeout,
	int timeout);
int virusfilter_io_set_connect_timeout(
	struct virusfilter_io_handle *io_h,
	int timeout);
int virusfilter_io_set_io_timeout(
	struct virusfilter_io_handle *io_h, int timeout);
void virusfilter_io_set_writel_eol(
	struct virusfilter_io_handle *io_h,
	const char *eol,
	int eol_size);
void virusfilter_io_set_readl_eol(
	struct virusfilter_io_handle *io_h,
	const char *eol,
	int eol_size);
bool virusfilter_io_connect_path(
	struct virusfilter_io_handle *io_h,
	const char *path);
bool virusfilter_io_disconnect(
	struct virusfilter_io_handle *io_h);
bool write_data_iov_timeout(
	struct tstream_context *stream,
	const struct iovec *iov,
	size_t iovcnt,
	int ms_timeout);
bool virusfilter_io_write(
	struct virusfilter_io_handle *io_h,
	const char *data,
	size_t data_size);
bool virusfilter_io_writel(
	struct virusfilter_io_handle *io_h,
	const char *data,
	size_t data_size);
bool virusfilter_io_writefl(
	struct virusfilter_io_handle *io_h,
	const char *data_fmt, ...);
bool virusfilter_io_vwritefl(
	struct virusfilter_io_handle *io_h,
	const char *data_fmt, va_list ap);
bool virusfilter_io_writev(
	struct virusfilter_io_handle *io_h, ...);
bool virusfilter_io_writevl(
	struct virusfilter_io_handle *io_h, ...);
bool virusfilter_io_readl(TALLOC_CTX *ctx,
			struct virusfilter_io_handle *io_h,
			char **read_line);
bool virusfilter_io_writefl_readl(
	struct virusfilter_io_handle *io_h,
	char **read_line,
	const char *fmt, ...);

/* Scan result cache */
struct virusfilter_cache *virusfilter_cache_new(
	TALLOC_CTX *ctx,
	int entry_limit,
	time_t time_limit);
bool virusfilter_cache_entry_add(
	struct virusfilter_cache *cache,
	const char *directory,
	const char *fname,
	virusfilter_result result,
	char *report);
bool virusfilter_cache_entry_rename(
	struct virusfilter_cache *cache,
	const char *directory,
	char *old_fname,
	char *new_fname);
void virusfilter_cache_entry_free(struct virusfilter_cache_entry *cache_e);
struct virusfilter_cache_entry *virusfilter_cache_get(
	struct virusfilter_cache *cache,
	const char *directory,
	const char *fname);
void virusfilter_cache_remove(
	struct virusfilter_cache *cache,
	const char *directory,
	const char *fname);
void virusfilter_cache_purge(struct virusfilter_cache *cache);

/* Shell scripting */
int virusfilter_env_set(
	TALLOC_CTX *mem_ctx,
	char **env_list,
	const char *name,
	const char *value);
int virusfilter_shell_set_conn_env(
	TALLOC_CTX *mem_ctx,
	char **env_list,
	connection_struct *conn);
int virusfilter_shell_run(
	TALLOC_CTX *mem_ctx,
	const char *cmd,
	char **env_list,
	connection_struct *conn,
	bool sanitize);

#endif /* _VIRUSFILTER_UTILS_H */