r12608: Remove some unused #include lines.
[abartlet/samba.git/.git] / source4 / libcli / dgram / netlogon.c
index 1f3a3d6c62581b5e5b5176e1fc95643befd24123..dffeae2007ba92727b4246e37325b2a39870cc1e 100644 (file)
 */
 
 #include "includes.h"
-#include "lib/events/events.h"
-#include "dlinklist.h"
-#include "libcli/nbt/libnbt.h"
 #include "libcli/dgram/libdgram.h"
-#include "lib/socket/socket.h"
-#include "librpc/gen_ndr/ndr_nbt.h"
 
 /* 
    send a netlogon mailslot request 
 */
 NTSTATUS dgram_mailslot_netlogon_send(struct nbt_dgram_socket *dgmsock,
                                      struct nbt_name *dest_name,
-                                     const char *dest_address,
+                                     const struct nbt_peer_socket *dest,
                                      struct nbt_name *src_name,
                                      struct nbt_netlogon_packet *request)
 {
@@ -50,9 +45,68 @@ NTSTATUS dgram_mailslot_netlogon_send(struct nbt_dgram_socket *dgmsock,
 
 
        status = dgram_mailslot_send(dgmsock, DGRAM_DIRECT_UNIQUE, 
-                                    "\\MAILSLOT\\NET\\NETLOGON",
-                                    dest_name, dest_address, src_name, &blob);
+                                    NBT_MAILSLOT_NETLOGON,
+                                    dest_name, dest, 
+                                    src_name, &blob);
        talloc_free(tmp_ctx);
        return status;
 }
 
+
+/* 
+   send a netlogon mailslot reply
+*/
+NTSTATUS dgram_mailslot_netlogon_reply(struct nbt_dgram_socket *dgmsock,
+                                      struct nbt_dgram_packet *request,
+                                      const char *mailslot_name,
+                                      struct nbt_netlogon_packet *reply)
+{
+       NTSTATUS status;
+       DATA_BLOB blob;
+       TALLOC_CTX *tmp_ctx = talloc_new(dgmsock);
+       struct nbt_name myname;
+       struct nbt_peer_socket dest;
+
+       status = ndr_push_struct_blob(&blob, tmp_ctx, reply, 
+                                     (ndr_push_flags_fn_t)ndr_push_nbt_netlogon_packet);
+       if (!NT_STATUS_IS_OK(status)) {
+               talloc_free(tmp_ctx);
+               return status;
+       }
+
+       make_nbt_name_client(&myname, lp_netbios_name());
+
+       dest.port = request->src_port;
+       dest.addr = request->src_addr;
+       status = dgram_mailslot_send(dgmsock, DGRAM_DIRECT_UNIQUE, 
+                                    mailslot_name,
+                                    &request->data.msg.source_name,
+                                    &dest,
+                                    &myname, &blob);
+       talloc_free(tmp_ctx);
+       return status;
+}
+
+
+/*
+  parse a netlogon response. The packet must be a valid mailslot packet
+*/
+NTSTATUS dgram_mailslot_netlogon_parse(struct dgram_mailslot_handler *dgmslot,
+                                      TALLOC_CTX *mem_ctx,
+                                      struct nbt_dgram_packet *dgram,
+                                      struct nbt_netlogon_packet *netlogon)
+{
+       DATA_BLOB data = dgram_mailslot_data(dgram);
+       NTSTATUS status;
+
+       status = ndr_pull_struct_blob(&data, mem_ctx, netlogon, 
+                                     (ndr_pull_flags_fn_t)ndr_pull_nbt_netlogon_packet);
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(0,("Failed to parse netlogon packet of length %d\n", 
+                        (int)data.length));
+               if (DEBUGLVL(10)) {
+                       file_save("netlogon.dat", data.data, data.length);
+               }
+       }
+       return status;
+}