From 8ae3366268e38f3f61f121d77c6083484408e442 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 3 Jan 2000 03:24:23 +0000 Subject: the bulk of the unexpected packet handling code is in here (This used to be commit 771f610f0d0223fea815771c9efe40d00e4817f4) --- source3/libsmb/unexpected.c | 160 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 160 insertions(+) create mode 100644 source3/libsmb/unexpected.c (limited to 'source3/libsmb/unexpected.c') diff --git a/source3/libsmb/unexpected.c b/source3/libsmb/unexpected.c new file mode 100644 index 0000000000..57fad7c696 --- /dev/null +++ b/source3/libsmb/unexpected.c @@ -0,0 +1,160 @@ +/* + Unix SMB/Netbios implementation. + Version 3.0 + handle unexpected packets + Copyright (C) Andrew Tridgell 2000 + + 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 2 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, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "includes.h" + +extern int DEBUGLEVEL; + +static TDB_CONTEXT *tdb; + +/* the key type used in the unexpeceted packet database */ +struct unexpected_key { + enum packet_type packet_type; + time_t timestamp; + int count; +}; + + + +/**************************************************************************** + all unexpected packets are passed in here, to be stored in a unexpected + packet database. This allows nmblookup and other tools to receive packets + erroneoously sent to the wrong port by broken MS systems + **************************************************************************/ +void unexpected_packet(struct packet_struct *p) +{ + static int count; + TDB_DATA kbuf, dbuf; + struct unexpected_key key; + char buf[1024]; + int len=0; + + if (!tdb) { + tdb = tdb_open(lock_path("unexpected.tdb"), 0, + TDB_CLEAR_IF_FIRST, + O_RDWR | O_CREAT, 0644); + if (!tdb) { + DEBUG(0,("Failed to open unexpected.tdb\n")); + return; + } + } + + memset(buf,'\0',sizeof(buf)); + + len = build_packet(buf, p); + + key.packet_type = p->packet_type; + key.timestamp = p->timestamp; + key.count = count++; + + kbuf.dptr = (char *)&key; + kbuf.dsize = sizeof(key); + dbuf.dptr = buf; + dbuf.dsize = len; + + tdb_store(tdb, kbuf, dbuf, TDB_REPLACE); +} + + +static time_t lastt; + +/**************************************************************************** +delete the record if it is too old + **************************************************************************/ +static int traverse_fn(TDB_CONTEXT *ttdb, TDB_DATA kbuf, TDB_DATA dbuf) +{ + struct unexpected_key key; + + memcpy(&key, kbuf.dptr, sizeof(key)); + + if (lastt - key.timestamp > NMBD_UNEXPECTED_TIMEOUT) { + tdb_delete(ttdb, kbuf); + } + + return 0; +} + + +/**************************************************************************** +delete all old unexpected packets + **************************************************************************/ +void clear_unexpected(time_t t) +{ + if (!tdb) return; + + if ((lastt != 0) && (t < lastt + NMBD_UNEXPECTED_TIMEOUT)) + return; + + lastt = t; + + tdb_traverse(tdb, traverse_fn); +} + + +static struct packet_struct *matched_packet; +static int match_trn_id; + +/**************************************************************************** +tdb traversal fn to find a matching 137 packet + **************************************************************************/ +static int traverse_match_137(TDB_CONTEXT *ttdb, TDB_DATA kbuf, TDB_DATA dbuf) +{ + struct unexpected_key key; + struct packet_struct *p; + + memcpy(&key, kbuf.dptr, sizeof(key)); + + if (key.packet_type != NMB_PACKET) return 0; + + p = parse_packet(dbuf.dptr, dbuf.dsize, NMB_PACKET); + + if (p->packet_type == NMB_PACKET && + p->packet.nmb.header.name_trn_id == match_trn_id) { + matched_packet = p; + return -1; + } + + free_packet(p); + + return 0; +} + + +/**************************************************************************** +check for a particular packet in the unexpected packet queue + **************************************************************************/ +struct packet_struct *receive_unexpected_137(int trn_id) +{ + TDB_CONTEXT *tdb2; + + tdb2 = tdb_open(lock_path("unexpected.tdb"), 0, 0, O_RDONLY, 0); + if (!tdb2) return NULL; + + matched_packet = NULL; + match_trn_id = trn_id; + + tdb_traverse(tdb2, traverse_match_137); + + tdb_close(tdb2); + + return matched_packet; +} -- cgit From 632b4f806eae15e319b8f62caef5d25634cf720c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 3 Jan 2000 06:30:50 +0000 Subject: added suppport for unexpected udp/138 packets I also fixed up the lookup_pdc_name() code so that it now works, even with a NT server that insists on replying to udp/138. The method I used to match packets was to use the mailslot string as a datagram ID. The true dgm_id doesn't work as NT doesn't set it correctly. uggh. PS: Jeremy, I had to change your code quite a bit, are you sure this worked with a Samba PDC?? The code looked broken, it got the offsets wrong in the SMB portion of the packet and filled in the IP incorrectly. (This used to be commit 32f66f4ea63038cb4b3785bdf1762abdde076f5d) --- source3/libsmb/unexpected.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'source3/libsmb/unexpected.c') diff --git a/source3/libsmb/unexpected.c b/source3/libsmb/unexpected.c index 57fad7c696..5106ef60f7 100644 --- a/source3/libsmb/unexpected.c +++ b/source3/libsmb/unexpected.c @@ -111,24 +111,28 @@ void clear_unexpected(time_t t) static struct packet_struct *matched_packet; -static int match_trn_id; +static int match_id; +static enum packet_type match_type; +static char *match_name; /**************************************************************************** tdb traversal fn to find a matching 137 packet **************************************************************************/ -static int traverse_match_137(TDB_CONTEXT *ttdb, TDB_DATA kbuf, TDB_DATA dbuf) +static int traverse_match(TDB_CONTEXT *ttdb, TDB_DATA kbuf, TDB_DATA dbuf) { struct unexpected_key key; struct packet_struct *p; memcpy(&key, kbuf.dptr, sizeof(key)); - if (key.packet_type != NMB_PACKET) return 0; + if (key.packet_type != match_type) return 0; - p = parse_packet(dbuf.dptr, dbuf.dsize, NMB_PACKET); + p = parse_packet(dbuf.dptr, dbuf.dsize, match_type); - if (p->packet_type == NMB_PACKET && - p->packet.nmb.header.name_trn_id == match_trn_id) { + if ((match_type == NMB_PACKET && + p->packet.nmb.header.name_trn_id == match_id) || + (match_type == DGRAM_PACKET && + match_mailslot_name(p, match_name))) { matched_packet = p; return -1; } @@ -142,7 +146,8 @@ static int traverse_match_137(TDB_CONTEXT *ttdb, TDB_DATA kbuf, TDB_DATA dbuf) /**************************************************************************** check for a particular packet in the unexpected packet queue **************************************************************************/ -struct packet_struct *receive_unexpected_137(int trn_id) +struct packet_struct *receive_unexpected(enum packet_type packet_type, int id, + char *mailslot_name) { TDB_CONTEXT *tdb2; @@ -150,9 +155,11 @@ struct packet_struct *receive_unexpected_137(int trn_id) if (!tdb2) return NULL; matched_packet = NULL; - match_trn_id = trn_id; + match_id = id; + match_type = packet_type; + match_name = mailslot_name; - tdb_traverse(tdb2, traverse_match_137); + tdb_traverse(tdb2, traverse_match); tdb_close(tdb2); -- cgit From 437c68b5fe4905f7420c9d1d1173f025b6a9c154 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 5 Jan 2000 01:48:30 +0000 Subject: use a minimal hash size in the unexpected packet database. A large hash is only useful when we fetch by key, not when we use tdb_traverse() (This used to be commit e154f041e8ec8b1097d4a0c727c68d217effba34) --- source3/libsmb/unexpected.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/libsmb/unexpected.c') diff --git a/source3/libsmb/unexpected.c b/source3/libsmb/unexpected.c index 5106ef60f7..b210fb2504 100644 --- a/source3/libsmb/unexpected.c +++ b/source3/libsmb/unexpected.c @@ -49,7 +49,7 @@ void unexpected_packet(struct packet_struct *p) int len=0; if (!tdb) { - tdb = tdb_open(lock_path("unexpected.tdb"), 0, + tdb = tdb_open(lock_path("unexpected.tdb"), 1, TDB_CLEAR_IF_FIRST, O_RDWR | O_CREAT, 0644); if (!tdb) { -- cgit From bbe275e95b86bc7af5a641455cbb379974823f84 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Fri, 4 Feb 2000 04:59:31 +0000 Subject: 1) added void* state argument to tdb_traverse. guess what! there were two places i found where it was appropriate to _use_ that third argument, in locking.c and brlock.c! there was a static traverse_function and i removed the static variable, typecast it to a void*, passed it to tdb_traverse and re-cast it back to the traverse_function inside the tdb_traverse function. this makes the use of tdb_traverse() reentrant, which is never going to happen, i know, i just don't like to see statics lying about when there's no need for them. as i had to do in samba-tng, all uses of tdb_traverse modified to take the new void* state argument. 2) disabled rpcclient: referring people to use SAMBA_TNG rpcclient. i don't know how the other samba team members would react if i deleted rpcclient from cvs main. damn, that code's so old, it's unreal. 20 rpcclient commands, instead of about 70 in SAMBA_TNG. (This used to be commit 49d7f0afbc1c5425d53019e234d54ddf205c8e9a) --- source3/libsmb/unexpected.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'source3/libsmb/unexpected.c') diff --git a/source3/libsmb/unexpected.c b/source3/libsmb/unexpected.c index b210fb2504..6c5dd611a9 100644 --- a/source3/libsmb/unexpected.c +++ b/source3/libsmb/unexpected.c @@ -24,7 +24,7 @@ extern int DEBUGLEVEL; -static TDB_CONTEXT *tdb; +static TDB_CONTEXT *tdbd = NULL; /* the key type used in the unexpeceted packet database */ struct unexpected_key { @@ -48,11 +48,11 @@ void unexpected_packet(struct packet_struct *p) char buf[1024]; int len=0; - if (!tdb) { - tdb = tdb_open(lock_path("unexpected.tdb"), 1, + if (!tdbd) { + tdbd = tdb_open(lock_path("unexpected.tdb"), 1, TDB_CLEAR_IF_FIRST, O_RDWR | O_CREAT, 0644); - if (!tdb) { + if (!tdbd) { DEBUG(0,("Failed to open unexpected.tdb\n")); return; } @@ -71,7 +71,7 @@ void unexpected_packet(struct packet_struct *p) dbuf.dptr = buf; dbuf.dsize = len; - tdb_store(tdb, kbuf, dbuf, TDB_REPLACE); + tdb_store(tdbd, kbuf, dbuf, TDB_REPLACE); } @@ -80,7 +80,7 @@ static time_t lastt; /**************************************************************************** delete the record if it is too old **************************************************************************/ -static int traverse_fn(TDB_CONTEXT *ttdb, TDB_DATA kbuf, TDB_DATA dbuf) +static int traverse_fn(TDB_CONTEXT *ttdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state) { struct unexpected_key key; @@ -99,14 +99,14 @@ delete all old unexpected packets **************************************************************************/ void clear_unexpected(time_t t) { - if (!tdb) return; + if (!tdbd) return; if ((lastt != 0) && (t < lastt + NMBD_UNEXPECTED_TIMEOUT)) return; lastt = t; - tdb_traverse(tdb, traverse_fn); + tdb_traverse(tdbd, traverse_fn, NULL); } @@ -118,7 +118,7 @@ static char *match_name; /**************************************************************************** tdb traversal fn to find a matching 137 packet **************************************************************************/ -static int traverse_match(TDB_CONTEXT *ttdb, TDB_DATA kbuf, TDB_DATA dbuf) +static int traverse_match(TDB_CONTEXT *ttdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state) { struct unexpected_key key; struct packet_struct *p; @@ -159,7 +159,7 @@ struct packet_struct *receive_unexpected(enum packet_type packet_type, int id, match_type = packet_type; match_name = mailslot_name; - tdb_traverse(tdb2, traverse_match); + tdb_traverse(tdb2, traverse_match, NULL); tdb_close(tdb2); -- cgit From 05fc3e578c895f632b351969d09cd00feb7599c7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 4 Jun 2001 05:13:59 +0000 Subject: use LDSHFLAGS not -shared in several places (This used to be commit 8ec9c87b5d1a7dae17d5b1a30f58effaf5e69e4b) --- source3/libsmb/unexpected.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/libsmb/unexpected.c') diff --git a/source3/libsmb/unexpected.c b/source3/libsmb/unexpected.c index 6c5dd611a9..d757551963 100644 --- a/source3/libsmb/unexpected.c +++ b/source3/libsmb/unexpected.c @@ -49,7 +49,7 @@ void unexpected_packet(struct packet_struct *p) int len=0; if (!tdbd) { - tdbd = tdb_open(lock_path("unexpected.tdb"), 1, + tdbd = tdb_open_log(lock_path("unexpected.tdb"), 1, TDB_CLEAR_IF_FIRST, O_RDWR | O_CREAT, 0644); if (!tdbd) { -- cgit From 996719cce26700c68ff0e456e6a25d20085d091f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 30 Jul 2001 22:21:31 +0000 Subject: Added "use mmap" for HPUX. Jeremy. (This used to be commit 840802f10677cb0009cb4df4c37c7d01aa5edacd) --- source3/libsmb/unexpected.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/libsmb/unexpected.c') diff --git a/source3/libsmb/unexpected.c b/source3/libsmb/unexpected.c index d757551963..109e2b454a 100644 --- a/source3/libsmb/unexpected.c +++ b/source3/libsmb/unexpected.c @@ -50,7 +50,7 @@ void unexpected_packet(struct packet_struct *p) if (!tdbd) { tdbd = tdb_open_log(lock_path("unexpected.tdb"), 1, - TDB_CLEAR_IF_FIRST, + TDB_CLEAR_IF_FIRST|USE_TDB_MMAP_FLAG, O_RDWR | O_CREAT, 0644); if (!tdbd) { DEBUG(0,("Failed to open unexpected.tdb\n")); -- cgit From 1772584c35189cba517c26bbde3205447f875952 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 6 Sep 2001 05:45:07 +0000 Subject: actually obey the "use mmap" smb.conf option (This used to be commit b36c98036bcbaa5545c9637cb632361122033cfd) --- source3/libsmb/unexpected.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/libsmb/unexpected.c') diff --git a/source3/libsmb/unexpected.c b/source3/libsmb/unexpected.c index 109e2b454a..41249aba56 100644 --- a/source3/libsmb/unexpected.c +++ b/source3/libsmb/unexpected.c @@ -151,7 +151,7 @@ struct packet_struct *receive_unexpected(enum packet_type packet_type, int id, { TDB_CONTEXT *tdb2; - tdb2 = tdb_open(lock_path("unexpected.tdb"), 0, 0, O_RDONLY, 0); + tdb2 = tdb_open_log(lock_path("unexpected.tdb"), 0, 0, O_RDONLY, 0); if (!tdb2) return NULL; matched_packet = NULL; -- cgit From 9a9ac2739bbdc993ecdfa78298bdd9c059328378 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 6 Sep 2001 22:08:19 +0000 Subject: got rid of USE_TDB_MMAP_FLAG as its not needed any more (This used to be commit c26e0d3f27a05ecc8bd2390f9aab7f9451524e47) --- source3/libsmb/unexpected.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/libsmb/unexpected.c') diff --git a/source3/libsmb/unexpected.c b/source3/libsmb/unexpected.c index 41249aba56..7d221e173e 100644 --- a/source3/libsmb/unexpected.c +++ b/source3/libsmb/unexpected.c @@ -50,7 +50,7 @@ void unexpected_packet(struct packet_struct *p) if (!tdbd) { tdbd = tdb_open_log(lock_path("unexpected.tdb"), 1, - TDB_CLEAR_IF_FIRST|USE_TDB_MMAP_FLAG, + TDB_CLEAR_IF_FIRST|TDB_DEFAULT, O_RDWR | O_CREAT, 0644); if (!tdbd) { DEBUG(0,("Failed to open unexpected.tdb\n")); -- cgit From dc1fc3ee8ec2199bc73bb5d7ec711c6800f61d65 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 2 Oct 2001 04:29:50 +0000 Subject: Removed 'extern int DEBUGLEVEL' as it is now in the smb.h header. (This used to be commit 2d0922b0eabfdc0aaf1d0797482fef47ed7fde8e) --- source3/libsmb/unexpected.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/libsmb/unexpected.c') diff --git a/source3/libsmb/unexpected.c b/source3/libsmb/unexpected.c index 7d221e173e..b77e7490a0 100644 --- a/source3/libsmb/unexpected.c +++ b/source3/libsmb/unexpected.c @@ -22,8 +22,6 @@ #include "includes.h" -extern int DEBUGLEVEL; - static TDB_CONTEXT *tdbd = NULL; /* the key type used in the unexpeceted packet database */ -- cgit From cd68afe31256ad60748b34f7318a180cfc2127cc Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 30 Jan 2002 06:08:46 +0000 Subject: Removed version number from file header. Changed "SMB/Netbios" to "SMB/CIFS" in file header. (This used to be commit 6a58c9bd06d0d7502a24bf5ce5a2faf0a146edfa) --- source3/libsmb/unexpected.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/libsmb/unexpected.c') diff --git a/source3/libsmb/unexpected.c b/source3/libsmb/unexpected.c index b77e7490a0..f74a05f75f 100644 --- a/source3/libsmb/unexpected.c +++ b/source3/libsmb/unexpected.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 3.0 + Unix SMB/CIFS implementation. handle unexpected packets Copyright (C) Andrew Tridgell 2000 -- cgit From e90b65284812aaa5ff9e9935ce9bbad7791cbbcd Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 15 Jul 2002 10:35:28 +0000 Subject: updated the 3.0 branch from the head branch - ready for alpha18 (This used to be commit 03ac082dcb375b6f3ca3d810a6a6367542bc23ce) --- source3/libsmb/unexpected.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/libsmb/unexpected.c') diff --git a/source3/libsmb/unexpected.c b/source3/libsmb/unexpected.c index f74a05f75f..4fc3914481 100644 --- a/source3/libsmb/unexpected.c +++ b/source3/libsmb/unexpected.c @@ -46,7 +46,7 @@ void unexpected_packet(struct packet_struct *p) int len=0; if (!tdbd) { - tdbd = tdb_open_log(lock_path("unexpected.tdb"), 1, + tdbd = tdb_open_log(lock_path("unexpected.tdb"), 0, TDB_CLEAR_IF_FIRST|TDB_DEFAULT, O_RDWR | O_CREAT, 0644); if (!tdbd) { -- cgit From 634c54310c92c48dd4eceec602e230a021bdcfc5 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 3 Jan 2003 08:28:12 +0000 Subject: Merge from HEAD - make Samba compile with -Wwrite-strings without additional warnings. (Adds a lot of const). Andrew Bartlett (This used to be commit 3a7458f9472432ef12c43008414925fd1ce8ea0c) --- source3/libsmb/unexpected.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/libsmb/unexpected.c') diff --git a/source3/libsmb/unexpected.c b/source3/libsmb/unexpected.c index 4fc3914481..97d6071e71 100644 --- a/source3/libsmb/unexpected.c +++ b/source3/libsmb/unexpected.c @@ -110,7 +110,7 @@ void clear_unexpected(time_t t) static struct packet_struct *matched_packet; static int match_id; static enum packet_type match_type; -static char *match_name; +static const char *match_name; /**************************************************************************** tdb traversal fn to find a matching 137 packet @@ -144,7 +144,7 @@ static int traverse_match(TDB_CONTEXT *ttdb, TDB_DATA kbuf, TDB_DATA dbuf, void check for a particular packet in the unexpected packet queue **************************************************************************/ struct packet_struct *receive_unexpected(enum packet_type packet_type, int id, - char *mailslot_name) + const char *mailslot_name) { TDB_CONTEXT *tdb2; -- cgit From bc2b6436d0f5f3e9ffdfaeb7f1b32996a83d5478 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 29 Mar 2007 09:35:51 +0000 Subject: r22009: change TDB_DATA from char * to unsigned char * and fix all compiler warnings in the users metze (This used to be commit 3a28443079c141a6ce8182c65b56ca210e34f37f) --- source3/libsmb/unexpected.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/libsmb/unexpected.c') diff --git a/source3/libsmb/unexpected.c b/source3/libsmb/unexpected.c index 97d6071e71..5aee16e4c6 100644 --- a/source3/libsmb/unexpected.c +++ b/source3/libsmb/unexpected.c @@ -63,9 +63,9 @@ void unexpected_packet(struct packet_struct *p) key.timestamp = p->timestamp; key.count = count++; - kbuf.dptr = (char *)&key; + kbuf.dptr = (uint8_t *)&key; kbuf.dsize = sizeof(key); - dbuf.dptr = buf; + dbuf.dptr = (uint8_t *)buf; dbuf.dsize = len; tdb_store(tdbd, kbuf, dbuf, TDB_REPLACE); @@ -124,7 +124,7 @@ static int traverse_match(TDB_CONTEXT *ttdb, TDB_DATA kbuf, TDB_DATA dbuf, void if (key.packet_type != match_type) return 0; - p = parse_packet(dbuf.dptr, dbuf.dsize, match_type); + p = parse_packet((char *)dbuf.dptr, dbuf.dsize, match_type); if ((match_type == NMB_PACKET && p->packet.nmb.header.name_trn_id == match_id) || -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/libsmb/unexpected.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/libsmb/unexpected.c') diff --git a/source3/libsmb/unexpected.c b/source3/libsmb/unexpected.c index 5aee16e4c6..5e45710d10 100644 --- a/source3/libsmb/unexpected.c +++ b/source3/libsmb/unexpected.c @@ -5,7 +5,7 @@ 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 2 of the License, or + 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, -- cgit From 5e54558c6dea67b56bbfaba5698f3a434d3dffb6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 00:52:41 +0000 Subject: r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text (This used to be commit b0132e94fc5fef936aa766fb99a306b3628e9f07) --- source3/libsmb/unexpected.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/libsmb/unexpected.c') diff --git a/source3/libsmb/unexpected.c b/source3/libsmb/unexpected.c index 5e45710d10..6f85f36a62 100644 --- a/source3/libsmb/unexpected.c +++ b/source3/libsmb/unexpected.c @@ -14,8 +14,7 @@ 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, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ -- cgit From 0d87820380416955a132d565a479b4234f78c113 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 3 Oct 2007 20:43:55 +0000 Subject: r25492: Start adding IPv6 compatible code to lib/util_sock.c and deal with the ripple effects this causes. utmp has to change etc. Remove some global varables and store address/port in the unexpected db. Jeremy. (This used to be commit 18c6a2211d9e25233d01715b3f78977edcd6d869) --- source3/libsmb/unexpected.c | 76 +++++++++++++++++++++++++++++---------------- 1 file changed, 50 insertions(+), 26 deletions(-) (limited to 'source3/libsmb/unexpected.c') diff --git a/source3/libsmb/unexpected.c b/source3/libsmb/unexpected.c index 6f85f36a62..f5837f321c 100644 --- a/source3/libsmb/unexpected.c +++ b/source3/libsmb/unexpected.c @@ -1,21 +1,21 @@ -/* +/* Unix SMB/CIFS implementation. handle unexpected packets Copyright (C) Andrew Tridgell 2000 - + 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 . - + */ #include "includes.h" @@ -29,13 +29,12 @@ struct unexpected_key { int count; }; - - /**************************************************************************** - all unexpected packets are passed in here, to be stored in a unexpected + All unexpected packets are passed in here, to be stored in a unexpected packet database. This allows nmblookup and other tools to receive packets - erroneoously sent to the wrong port by broken MS systems - **************************************************************************/ + erroneoously sent to the wrong port by broken MS systems. +**************************************************************************/ + void unexpected_packet(struct packet_struct *p) { static int count; @@ -43,9 +42,10 @@ void unexpected_packet(struct packet_struct *p) struct unexpected_key key; char buf[1024]; int len=0; + uint32_t enc_ip; if (!tdbd) { - tdbd = tdb_open_log(lock_path("unexpected.tdb"), 0, + tdbd = tdb_open_log(lock_path("unexpected.tdb"), 0, TDB_CLEAR_IF_FIRST|TDB_DEFAULT, O_RDWR | O_CREAT, 0644); if (!tdbd) { @@ -55,8 +55,13 @@ void unexpected_packet(struct packet_struct *p) } memset(buf,'\0',sizeof(buf)); - - len = build_packet(buf, p); + + /* Encode the ip addr and port. */ + enc_ip = ntohl(p->ip.s_addr); + SIVAL(buf,0,enc_ip); + SSVAL(buf,4,p->port); + + len = build_packet(&buf[6], sizeof(buf)-6, p) + 6; key.packet_type = p->packet_type; key.timestamp = p->timestamp; @@ -74,8 +79,9 @@ void unexpected_packet(struct packet_struct *p) static time_t lastt; /**************************************************************************** -delete the record if it is too old - **************************************************************************/ + Delete the record if it is too old. +**************************************************************************/ + static int traverse_fn(TDB_CONTEXT *ttdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state) { struct unexpected_key key; @@ -91,8 +97,9 @@ static int traverse_fn(TDB_CONTEXT *ttdb, TDB_DATA kbuf, TDB_DATA dbuf, void *st /**************************************************************************** -delete all old unexpected packets - **************************************************************************/ + Delete all old unexpected packets. +**************************************************************************/ + void clear_unexpected(time_t t) { if (!tdbd) return; @@ -112,22 +119,39 @@ static enum packet_type match_type; static const char *match_name; /**************************************************************************** -tdb traversal fn to find a matching 137 packet - **************************************************************************/ + tdb traversal fn to find a matching 137 packet. +**************************************************************************/ + static int traverse_match(TDB_CONTEXT *ttdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state) { struct unexpected_key key; + struct in_addr ip; + uint32_t enc_ip; + int port; struct packet_struct *p; memcpy(&key, kbuf.dptr, sizeof(key)); if (key.packet_type != match_type) return 0; - p = parse_packet((char *)dbuf.dptr, dbuf.dsize, match_type); + if (dbuf.dsize < 6) { + return 0; + } + + /* Decode the ip addr and port. */ + enc_ip = IVAL(dbuf.dptr,0); + ip.s_addr = htonl(enc_ip); + port = SVAL(dbuf.dptr,4); + + p = parse_packet((char *)&dbuf.dptr[6], + dbuf.dsize-6, + match_type, + ip, + port); - if ((match_type == NMB_PACKET && + if ((match_type == NMB_PACKET && p->packet.nmb.header.name_trn_id == match_id) || - (match_type == DGRAM_PACKET && + (match_type == DGRAM_PACKET && match_mailslot_name(p, match_name))) { matched_packet = p; return -1; @@ -138,11 +162,11 @@ static int traverse_match(TDB_CONTEXT *ttdb, TDB_DATA kbuf, TDB_DATA dbuf, void return 0; } - /**************************************************************************** -check for a particular packet in the unexpected packet queue - **************************************************************************/ -struct packet_struct *receive_unexpected(enum packet_type packet_type, int id, + Check for a particular packet in the unexpected packet queue. +**************************************************************************/ + +struct packet_struct *receive_unexpected(enum packet_type packet_type, int id, const char *mailslot_name) { TDB_CONTEXT *tdb2; -- cgit From 195d6be38d9d721837a8d44ff918829528059cda Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 24 Nov 2007 15:47:04 +0100 Subject: remove some statics (This used to be commit 97c9a4042d36178a728b5e0f8923091c7069366d) --- source3/libsmb/unexpected.c | 43 ++++++++++++++++++++++++------------------- 1 file changed, 24 insertions(+), 19 deletions(-) (limited to 'source3/libsmb/unexpected.c') diff --git a/source3/libsmb/unexpected.c b/source3/libsmb/unexpected.c index f5837f321c..92a609c42b 100644 --- a/source3/libsmb/unexpected.c +++ b/source3/libsmb/unexpected.c @@ -112,18 +112,22 @@ void clear_unexpected(time_t t) tdb_traverse(tdbd, traverse_fn, NULL); } - -static struct packet_struct *matched_packet; -static int match_id; -static enum packet_type match_type; -static const char *match_name; +struct receive_unexpected_state { + struct packet_struct *matched_packet; + int match_id; + enum packet_type match_type; + const char *match_name; +}; /**************************************************************************** tdb traversal fn to find a matching 137 packet. **************************************************************************/ -static int traverse_match(TDB_CONTEXT *ttdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state) +static int traverse_match(TDB_CONTEXT *ttdb, TDB_DATA kbuf, TDB_DATA dbuf, + void *private_data) { + struct receive_unexpected_state *state = + (struct receive_unexpected_state *)private_data; struct unexpected_key key; struct in_addr ip; uint32_t enc_ip; @@ -132,7 +136,7 @@ static int traverse_match(TDB_CONTEXT *ttdb, TDB_DATA kbuf, TDB_DATA dbuf, void memcpy(&key, kbuf.dptr, sizeof(key)); - if (key.packet_type != match_type) return 0; + if (key.packet_type != state->match_type) return 0; if (dbuf.dsize < 6) { return 0; @@ -145,15 +149,15 @@ static int traverse_match(TDB_CONTEXT *ttdb, TDB_DATA kbuf, TDB_DATA dbuf, void p = parse_packet((char *)&dbuf.dptr[6], dbuf.dsize-6, - match_type, + state->match_type, ip, port); - if ((match_type == NMB_PACKET && - p->packet.nmb.header.name_trn_id == match_id) || - (match_type == DGRAM_PACKET && - match_mailslot_name(p, match_name))) { - matched_packet = p; + if ((state->match_type == NMB_PACKET && + p->packet.nmb.header.name_trn_id == state->match_id) || + (state->match_type == DGRAM_PACKET && + match_mailslot_name(p, state->match_name))) { + state->matched_packet = p; return -1; } @@ -170,18 +174,19 @@ struct packet_struct *receive_unexpected(enum packet_type packet_type, int id, const char *mailslot_name) { TDB_CONTEXT *tdb2; + struct receive_unexpected_state state; tdb2 = tdb_open_log(lock_path("unexpected.tdb"), 0, 0, O_RDONLY, 0); if (!tdb2) return NULL; - matched_packet = NULL; - match_id = id; - match_type = packet_type; - match_name = mailslot_name; + state.matched_packet = NULL; + state.match_id = id; + state.match_type = packet_type; + state.match_name = mailslot_name; - tdb_traverse(tdb2, traverse_match, NULL); + tdb_traverse(tdb2, traverse_match, &state); tdb_close(tdb2); - return matched_packet; + return state.matched_packet; } -- cgit From 2197801ef1d9a942c8f8ec8b8e81b9f25cffc02f Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 19 Dec 2007 16:48:04 +0100 Subject: Zero the tdb key, there might be padding This leads to uninitialized variable warnings if nmbd is run under valgrind. (This used to be commit 9ec4f91f35696e5a00e24fe9ae2dd06119482c80) --- source3/libsmb/unexpected.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/libsmb/unexpected.c') diff --git a/source3/libsmb/unexpected.c b/source3/libsmb/unexpected.c index 92a609c42b..195668c44a 100644 --- a/source3/libsmb/unexpected.c +++ b/source3/libsmb/unexpected.c @@ -63,6 +63,8 @@ void unexpected_packet(struct packet_struct *p) len = build_packet(&buf[6], sizeof(buf)-6, p) + 6; + ZERO_STRUCT(key); /* needed for potential alignment */ + key.packet_type = p->packet_type; key.timestamp = p->timestamp; key.count = count++; -- cgit From 0743d384a634ad9c124673f52b9c2d17aab1ac89 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 19 Dec 2007 16:48:18 +0100 Subject: Some paranoia checks (This used to be commit ff644cfa1b123e9d0f8f4817504e5b209b85dedd) --- source3/libsmb/unexpected.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'source3/libsmb/unexpected.c') diff --git a/source3/libsmb/unexpected.c b/source3/libsmb/unexpected.c index 195668c44a..5fbc33cdf5 100644 --- a/source3/libsmb/unexpected.c +++ b/source3/libsmb/unexpected.c @@ -88,6 +88,10 @@ static int traverse_fn(TDB_CONTEXT *ttdb, TDB_DATA kbuf, TDB_DATA dbuf, void *st { struct unexpected_key key; + if (kbuf.dsize != sizeof(key)) { + tdb_delete(ttdb, kbuf); + } + memcpy(&key, kbuf.dptr, sizeof(key)); if (lastt - key.timestamp > NMBD_UNEXPECTED_TIMEOUT) { @@ -136,6 +140,10 @@ static int traverse_match(TDB_CONTEXT *ttdb, TDB_DATA kbuf, TDB_DATA dbuf, int port; struct packet_struct *p; + if (kbuf.dsize != sizeof(key)) { + return 0; + } + memcpy(&key, kbuf.dptr, sizeof(key)); if (key.packet_type != state->match_type) return 0; -- cgit From 6a2dbea79433465518a47a275f3ed5fbaa887c1e Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 1 Mar 2008 19:54:17 +0100 Subject: Fix some typos (This used to be commit cfa1b838144800c0758969921b8904fd62e46c07) --- source3/libsmb/unexpected.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/libsmb/unexpected.c') diff --git a/source3/libsmb/unexpected.c b/source3/libsmb/unexpected.c index 5fbc33cdf5..df4d2119e2 100644 --- a/source3/libsmb/unexpected.c +++ b/source3/libsmb/unexpected.c @@ -22,7 +22,7 @@ static TDB_CONTEXT *tdbd = NULL; -/* the key type used in the unexpeceted packet database */ +/* the key type used in the unexpected packet database */ struct unexpected_key { enum packet_type packet_type; time_t timestamp; @@ -32,7 +32,7 @@ struct unexpected_key { /**************************************************************************** All unexpected packets are passed in here, to be stored in a unexpected packet database. This allows nmblookup and other tools to receive packets - erroneoously sent to the wrong port by broken MS systems. + erroneously sent to the wrong port by broken MS systems. **************************************************************************/ void unexpected_packet(struct packet_struct *p) -- cgit