Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
Update code to work with samba4
Browse files Browse the repository at this point in the history
  • Loading branch information
luke-dixon committed Dec 18, 2014
1 parent c26ad50 commit 84d2f43
Show file tree
Hide file tree
Showing 6 changed files with 172 additions and 51 deletions.
47 changes: 46 additions & 1 deletion INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Requirements
* Samba build environment
* GNU make

Basic build and install procedure
Basic build and install procedure for Samba 3
======================================================================

$ ./configure --with-samba-source=/path/to/samba-3.6.x
Expand All @@ -22,6 +22,51 @@ Basic build and install procedure
# make install
...

Build and install procedure for Samba 4
======================================================================

Place this folder in the samba source directory:

$ cd samba-4.x.x
$ unzip /path/to/download/samba-virusfilter.zip

Add the following line to ./wscript in the samba source directory:

conf.RECURSE('samba-virusfilter')

after the line:

conf.RECURSE('source3')

Add the following line to ./source3/wscript_build:

bld.RECURSE('../samba-virusfilter')

after the line:

bld.RECURSE('../examples/VFS')

Change a line in ./buildtools/wafsamba/stale_files.py:

@@ -88,7 +88,7 @@
link = os.readlink(p)
if link[0:bin_base_len] == bin_base:
p = link
- if f in ['config.h']:
+ if f in ['config.h', 'svf-config.h']:
continue
(froot, fext) = os.path.splitext(f)
if fext not in [ '.c', '.h', '.so', '.o' ]:

Then build samba:

$ ./configure --prefix=/some/install/dir
...
$ make
...
$ sudo make install # or 'su -c "make install"'
...

Usage
======================================================================

Expand Down
17 changes: 12 additions & 5 deletions include/svf-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#ifndef _SVF_COMMON_H
#define _SVF_COMMON_H

#include <stdint.h>
#include <time.h>
/* Samba common include file */
#include "includes.h"

Expand All @@ -29,6 +31,7 @@
#include "auth.h"
#include "passdb.h"
#include "../librpc/gen_ndr/ndr_netlogon.h"
#include "../lib/tsocket/tsocket.h"

#if (SMB_VFS_INTERFACE_VERSION < 28)
#error "Samba 3.6+ required (SMB_VFS_INTERFACE_VERSION >= 28)"
Expand Down Expand Up @@ -73,12 +76,16 @@ typedef enum {
} svf_result;

#define conn_session_info(conn) ((conn)->session_info)
#define conn_socket(conn) ((conn)->sconn->sock)
#define conn_domain_name(conn) ((conn)->session_info->info3->base.domain.string)
#define conn_client_name(conn) ((conn)->sconn->client_id.name)
#define conn_client_addr(conn, addr) ((conn)->sconn->client_id.addr)
#if SAMBA_VERSION_NUMBER >= 40200
# define conn_socket(conn) ((conn)->transport.sock)
#else
# define conn_socket(conn) ((conn)->sconn->sock)
#endif
#define conn_domain_name(conn) ((conn)->session_info->info->domain_name)
#define conn_client_name(conn) ((conn)->sconn->remote_hostname)
#define conn_client_addr(conn) tsocket_address_inet_addr_string((conn)->sconn->remote_address, talloc_tos())

#define conn_server_addr(conn, addr) client_socket_addr(conn_socket(conn), (addr), sizeof(addr));
#define conn_server_addr(conn) tsocket_address_inet_addr_string((conn)->sconn->local_address, talloc_tos())

#endif /* _SVF_COMMON_H */

36 changes: 22 additions & 14 deletions include/svf-vfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "svf-common.h"
#include "svf-utils.h"

#define SVF_MODULE_NAME "svf-" SVF_MODULE_ENGINE
#define SVF_MODULE_NAME "svf_" SVF_MODULE_ENGINE

/* Default configuration values
* ====================================================================== */
Expand Down Expand Up @@ -164,15 +164,15 @@ static int svf_vfs_connect(
{
int snum = SNUM(vfs_h->conn);
svf_handle *svf_h;
char *exclude_files;
const char *exclude_files;
#ifdef SVF_DEFAULT_SOCKET_PATH
int connect_timeout, io_timeout;
#endif


svf_h = TALLOC_ZERO_P(vfs_h, svf_handle);
svf_h = talloc_zero(vfs_h, svf_handle);
if (!svf_h) {
DEBUG(0, ("TALLOC_ZERO_P failed\n"));
DEBUG(0, ("talloc_zero failed\n"));
return -1;
}

Expand Down Expand Up @@ -227,13 +227,12 @@ static int svf_vfs_connect(
"min file size",
SVF_DEFAULT_MIN_FILE_SIZE);

exclude_files = lp_parm_talloc_string(
exclude_files = lp_parm_const_string(
snum, SVF_MODULE_NAME,
"exclude files",
SVF_DEFAULT_EXCLUDE_FILES);
if (exclude_files) {
set_namearray(&svf_h->exclude_files, exclude_files);
TALLOC_FREE(exclude_files);
}

svf_h->cache_entry_limit = lp_parm_int(
Expand Down Expand Up @@ -377,7 +376,6 @@ static svf_action svf_do_infected_file_action(
char *q_prefix;
char *q_filepath;
int q_fd;
NTSTATUS status;

switch (svf_h->infected_file_action) {
case SVF_ACTION_QUARANTINE:
Expand Down Expand Up @@ -408,28 +406,34 @@ static svf_action svf_do_infected_file_action(
if (q_fd == -1) {
unbecome_root();
DEBUG(0,("Quarantine failed: %s/%s: "
"Cannot open destination: %s: %s",
"Cannot open destination: %s: %s\n",
conn->connectpath,
smb_fname->base_name,
q_filepath, strerror(errno)));
return SVF_ACTION_DO_NOTHING;
}
close(q_fd);

#if SAMBA_VERSION_NUMBER >= 40100
q_smb_fname = synthetic_smb_fname(mem_ctx, q_filepath, smb_fname->stream_name, NULL);
if (q_smb_fname == NULL) {
#else
NTSTATUS status;
status = create_synthetic_smb_fname(mem_ctx,
q_filepath,
smb_fname->stream_name,
NULL,
&q_smb_fname);
if (!NT_STATUS_IS_OK(status)) {
#endif
unlink(q_filepath);
unbecome_root();
return SVF_ACTION_DO_NOTHING;
}

if (svf_vfs_next_move(vfs_h, smb_fname, q_smb_fname) == -1) {
unbecome_root();
DEBUG(0,("Quarantine failed: %s/%s: Rename failed: %s",
DEBUG(0,("Quarantine failed: %s/%s: Rename failed: %s\n",
conn->connectpath,
smb_fname->base_name,
strerror(errno)));
Expand All @@ -445,7 +449,7 @@ static svf_action svf_do_infected_file_action(
become_root();
if (SMB_VFS_NEXT_UNLINK(vfs_h, smb_fname) == -1) {
unbecome_root();
DEBUG(0,("Delete failed: %s/%s: Unlink failed: %s",
DEBUG(0,("Delete failed: %s/%s: Unlink failed: %s\n",
conn->connectpath,
smb_fname->base_name,
strerror(errno)));
Expand Down Expand Up @@ -821,25 +825,29 @@ static int svf_vfs_close(
if (fsp->is_directory) {
DEBUG(5, ("Not scanned: Directory: %s/%s\n",
conn->connectpath, fname));
TALLOC_FREE(mem_ctx);
return close_result;
}

if (!svf_h->scan_on_close) {
DEBUG(5, ("Not scanned: scan on close is disabled: %s/%s\n",
conn->connectpath, fname));
TALLOC_FREE(mem_ctx);
return close_result;
}

if (!fsp->modified) {
DEBUG(3, ("Not scanned: File not modified: %s/%s\n",
conn->connectpath, fname));

TALLOC_FREE(mem_ctx);
return close_result;
}

if (svf_h->exclude_files && is_in_path(fname, svf_h->exclude_files, false)) {
DEBUG(5, ("Not scanned: exclude files: %s/%s\n",
conn->connectpath, fname));
TALLOC_FREE(mem_ctx);
return close_result;
}

Expand Down Expand Up @@ -951,14 +959,14 @@ static int svf_vfs_rename(
/* VFS operations */
static struct vfs_fn_pointers vfs_svf_fns = {
.connect_fn = svf_vfs_connect,
.disconnect = svf_vfs_disconnect,
.disconnect_fn =svf_vfs_disconnect,
.open_fn = svf_vfs_open,
.close_fn = svf_vfs_close,
.unlink = svf_vfs_unlink,
.rename = svf_vfs_rename,
.unlink_fn = svf_vfs_unlink,
.rename_fn = svf_vfs_rename,
};

NTSTATUS init_samba_module(void)
NTSTATUS samba_init_module(void)
{
NTSTATUS ret;

Expand Down
Loading

0 comments on commit 84d2f43

Please sign in to comment.