summaryrefslogtreecommitdiffstats
path: root/source/utils/smbfilter.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/utils/smbfilter.c')
-rw-r--r--source/utils/smbfilter.c61
1 files changed, 23 insertions, 38 deletions
diff --git a/source/utils/smbfilter.c b/source/utils/smbfilter.c
index 5a2d394706b..6be0860c928 100644
--- a/source/utils/smbfilter.c
+++ b/source/utils/smbfilter.c
@@ -1,5 +1,6 @@
/*
- Unix SMB/CIFS implementation.
+ Unix SMB/Netbios implementation.
+ Version 2
SMB filter/socket plugin
Copyright (C) Andrew Tridgell 1999
@@ -25,7 +26,7 @@
#define SECURITY_SET 0
/* this forces non-unicode */
-#define CAPABILITY_MASK 0
+#define CAPABILITY_MASK (CAP_NT_SMBS | CAP_RPC_REMOTE_APIS)
#define CAPABILITY_SET 0
/* and non-unicode for the client too */
@@ -35,22 +36,6 @@
static char *netbiosname;
static char packet[BUFFER_SIZE];
-static void save_file(const char *fname, void *packet, size_t length)
-{
- int fd;
- fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, 0644);
- if (fd == -1) {
- perror(fname);
- return;
- }
- if (write(fd, packet, length) != length) {
- fprintf(stderr,"Failed to write %s\n", fname);
- return;
- }
- close(fd);
- printf("Wrote %d bytes to %s\n", length, fname);
-}
-
static void filter_reply(char *buf)
{
int msg_type = CVAL(buf,0);
@@ -90,8 +75,8 @@ static void filter_request(char *buf)
/* session request */
name_extract(buf,4,name1);
name_extract(buf,4 + name_len(buf + 4),name2);
- d_printf("sesion_request: %s -> %s\n",
- name1, name2);
+ DEBUG(0,("sesion_request: %s -> %s\n",
+ name1, name2));
if (netbiosname) {
/* replace the destination netbios name */
name_mangle(netbiosname, buf+4, 0x20);
@@ -105,10 +90,6 @@ static void filter_request(char *buf)
case SMBsesssetupX:
/* force the client capabilities */
x = IVAL(buf,smb_vwv11);
- d_printf("SMBsesssetupX cap=0x%08x\n", x);
- d_printf("pwlen=%d/%d\n", SVAL(buf, smb_vwv7), SVAL(buf, smb_vwv8));
- system("mv sessionsetup.dat sessionsetup1.dat");
- save_file("sessionsetup.dat", smb_buf(buf), SVAL(buf, smb_vwv7));
x = (x | CLI_CAPABILITY_SET) & ~CLI_CAPABILITY_MASK;
SIVAL(buf, smb_vwv11, x);
break;
@@ -122,10 +103,10 @@ static void filter_child(int c, struct in_addr dest_ip)
int s;
/* we have a connection from a new client, now connect to the server */
- s = open_socket_out(SOCK_STREAM, &dest_ip, 445, LONG_CONNECT_TIMEOUT);
+ s = open_socket_out(SOCK_STREAM, &dest_ip, 139, LONG_CONNECT_TIMEOUT);
if (s == -1) {
- d_printf("Unable to connect to %s\n", inet_ntoa(dest_ip));
+ DEBUG(0,("Unable to connect to %s\n", inet_ntoa(dest_ip)));
exit(1);
}
@@ -142,28 +123,28 @@ static void filter_child(int c, struct in_addr dest_ip)
if (c != -1 && FD_ISSET(c, &fds)) {
if (!receive_smb(c, packet, 0)) {
- d_printf("client closed connection\n");
+ DEBUG(0,("client closed connection\n"));
exit(0);
}
filter_request(packet);
if (!send_smb(s, packet)) {
- d_printf("server is dead\n");
+ DEBUG(0,("server is dead\n"));
exit(1);
}
}
if (s != -1 && FD_ISSET(s, &fds)) {
if (!receive_smb(s, packet, 0)) {
- d_printf("server closed connection\n");
+ DEBUG(0,("server closed connection\n"));
exit(0);
}
filter_reply(packet);
if (!send_smb(c, packet)) {
- d_printf("client is dead\n");
+ DEBUG(0,("client is dead\n"));
exit(1);
}
}
}
- d_printf("Connection closed\n");
+ DEBUG(0,("Connection closed\n"));
exit(0);
}
@@ -175,20 +156,20 @@ static void start_filter(char *desthost)
CatchChild();
- /* start listening on port 445 locally */
- s = open_socket_in(SOCK_STREAM, 445, 0, 0, True);
+ /* start listening on port 139 locally */
+ s = open_socket_in(SOCK_STREAM, 139, 0, 0, True);
if (s == -1) {
- d_printf("bind failed\n");
+ DEBUG(0,("bind failed\n"));
exit(1);
}
if (listen(s, 5) == -1) {
- d_printf("listen failed\n");
+ DEBUG(0,("listen failed\n"));
}
if (!resolve_name(desthost, &dest_ip, 0x20)) {
- d_printf("Unable to resolve host %s\n", desthost);
+ DEBUG(0,("Unable to resolve host %s\n", desthost));
exit(1);
}
@@ -223,9 +204,13 @@ int main(int argc, char *argv[])
char *desthost;
pstring configfile;
+ TimeInit();
+
setup_logging(argv[0],True);
- pstrcpy(configfile,dyn_CONFIGFILE);
+ charset_initialise();
+
+ pstrcpy(configfile,CONFIGFILE);
if (argc < 2) {
fprintf(stderr,"smbfilter <desthost> <netbiosname>\n");
@@ -238,7 +223,7 @@ int main(int argc, char *argv[])
}
if (!lp_load(configfile,True,False,False)) {
- d_printf("Unable to load config file\n");
+ DEBUG(0,("Unable to load config file\n"));
}
start_filter(desthost);