summaryrefslogtreecommitdiff
path: root/source3/libsmb/namequery.c
diff options
context:
space:
mode:
authorJeremy Allison <jra@samba.org>2010-11-13 20:32:36 -0800
committerJeremy Allison <jra@samba.org>2010-11-14 05:22:45 +0000
commit52f252064817b4be4d45d9fdbb0ad07748a0f317 (patch)
treecebc18dd44724ff5ff1e03da4a3736f89ec32f06 /source3/libsmb/namequery.c
parent781c4aabb87e63df77c76a360b6ed5f6a20e6d58 (diff)
downloadsamba-52f252064817b4be4d45d9fdbb0ad07748a0f317.tar.gz
samba-52f252064817b4be4d45d9fdbb0ad07748a0f317.tar.bz2
samba-52f252064817b4be4d45d9fdbb0ad07748a0f317.zip
Fix the unexpected.tdb database problem. Change nmbd to store the
transaction id of packets it was requested to send via a client, and only store replies that match these ids. On the client side change clients to always attempt to ask nmbd first for name_query and node_status calls, and then fall back to doing socket calls if we can't talk to nmbd (either nmbd is not running, or we're not root and cannot open the messaging tdb's). Fix readers of unexpected.tdb to delete packets they've successfully read. This should fix a long standing problem of unexpected.tdb growing out of control in noisy NetBIOS envioronments with lots of bradcasts, yet still allow unprivileged client apps to work mostly as well as they already did (nmblookup for example) in an environment when nmbd isn't running. Jeremy. Autobuild-User: Jeremy Allison <jra@samba.org> Autobuild-Date: Sun Nov 14 05:22:45 UTC 2010 on sn-devel-104
Diffstat (limited to 'source3/libsmb/namequery.c')
-rw-r--r--source3/libsmb/namequery.c35
1 files changed, 30 insertions, 5 deletions
diff --git a/source3/libsmb/namequery.c b/source3/libsmb/namequery.c
index d1fb5ab817..6ff5f7112a 100644
--- a/source3/libsmb/namequery.c
+++ b/source3/libsmb/namequery.c
@@ -22,6 +22,7 @@
#include "libads/sitename_cache.h"
#include "libads/dns.h"
#include "../libcli/netlogon.h"
+#include "librpc/gen_ndr/messaging.h"
/* nmbd.c sets this to True. */
bool global_in_nmbd = False;
@@ -246,6 +247,31 @@ static NODE_STATUS_STRUCT *parse_node_status(char *p,
return ret;
}
+/****************************************************************************
+ Try and send a request to nmbd to send a packet_struct packet first.
+ If this fails, use send_packet().
+**************************************************************************/
+
+static bool send_packet_request(struct packet_struct *p)
+{
+ struct messaging_context *msg_ctx = server_messaging_context();
+ if (msg_ctx) {
+ pid_t nmbd_pid = pidfile_pid("nmbd");
+
+ if (nmbd_pid) {
+ /* Try nmbd. */
+ if (NT_STATUS_IS_OK(messaging_send_buf(msg_ctx,
+ pid_to_procid(nmbd_pid),
+ MSG_SEND_PACKET,
+ (uint8_t *)p,
+ sizeof(struct packet_struct)))) {
+ return true;
+ }
+ }
+ }
+
+ return send_packet(p);
+}
/****************************************************************************
Do a NBT node status query on an open socket and return an array of
@@ -299,7 +325,7 @@ NODE_STATUS_STRUCT *node_status_query(int fd,
clock_gettime_mono(&tp);
- if (!send_packet(&p))
+ if (!send_packet_request(&p))
return NULL;
retries--;
@@ -310,7 +336,7 @@ NODE_STATUS_STRUCT *node_status_query(int fd,
if (nsec_time_diff(&tp2,&tp)/1000000 > retry_time) {
if (!retries)
break;
- if (!found && !send_packet(&p))
+ if (!found && !send_packet_request(&p))
return NULL;
clock_gettime_mono(&tp);
retries--;
@@ -707,7 +733,7 @@ struct sockaddr_storage *name_query(int fd,
clock_gettime_mono(&tp);
- if (!send_packet(&p))
+ if (!send_packet_request(&p))
return NULL;
retries--;
@@ -719,12 +745,11 @@ struct sockaddr_storage *name_query(int fd,
if (nsec_time_diff(&tp2,&tp)/1000000 > retry_time) {
if (!retries)
break;
- if (!found && !send_packet(&p))
+ if (!found && !send_packet_request(&p))
return NULL;
clock_gettime_mono(&tp);
retries--;
}
-
if ((p2=receive_nmb_packet(fd,90,nmb->header.name_trn_id))) {
struct nmb_packet *nmb2 = &p2->packet.nmb;
debug_nmb_packet(p2);