LCOV - code coverage report
Current view: top level - source4/libcli/dgram - browse.c (source / functions) Hit Total Coverage
Test: coverage report for master 70ed9daf Lines: 5 43 11.6 %
Date: 2024-01-11 09:59:51 Functions: 1 3 33.3 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             : 
       4             :    handling for browsing dgram requests
       5             : 
       6             :    Copyright (C) Jelmer Vernooij 2005
       7             :         Heavily based on ntlogon.c
       8             : 
       9             :    This program is free software; you can redistribute it and/or modify
      10             :    it under the terms of the GNU General Public License as published by
      11             :    the Free Software Foundation; either version 3 of the License, or
      12             :    (at your option) any later version.
      13             : 
      14             :    This program is distributed in the hope that it will be useful,
      15             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      16             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      17             :    GNU General Public License for more details.
      18             : 
      19             :    You should have received a copy of the GNU General Public License
      20             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      21             : */
      22             : 
      23             : #include "includes.h"
      24             : #include "libcli/dgram/libdgram.h"
      25             : #include "lib/socket/socket.h"
      26             : #include "libcli/resolve/resolve.h"
      27             : #include "librpc/gen_ndr/ndr_nbt.h"
      28             : #include "param/param.h"
      29             : 
      30           0 : NTSTATUS dgram_mailslot_browse_send(struct nbt_dgram_socket *dgmsock,
      31             :                                     struct nbt_name *dest_name,
      32             :                                     struct socket_address *dest,
      33             :                                     struct nbt_name *src_name,
      34             :                                     struct nbt_browse_packet *request)
      35             : {
      36           0 :         NTSTATUS status;
      37           0 :         enum ndr_err_code ndr_err;
      38           0 :         DATA_BLOB blob;
      39           0 :         TALLOC_CTX *tmp_ctx = talloc_new(dgmsock);
      40             : 
      41           0 :         ndr_err = ndr_push_struct_blob(&blob, tmp_ctx, request,
      42             :                                       (ndr_push_flags_fn_t)ndr_push_nbt_browse_packet);
      43           0 :         if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
      44           0 :                 talloc_free(tmp_ctx);
      45           0 :                 return ndr_map_error2ntstatus(ndr_err);
      46             :         }
      47             : 
      48           0 :         status = dgram_mailslot_send(dgmsock, DGRAM_DIRECT_UNIQUE,
      49             :                                      NBT_MAILSLOT_BROWSE,
      50             :                                      dest_name, dest,
      51             :                                      src_name, &blob);
      52           0 :         talloc_free(tmp_ctx);
      53           0 :         return status;
      54             : }
      55             : 
      56           0 : NTSTATUS dgram_mailslot_browse_reply(struct nbt_dgram_socket *dgmsock,
      57             :                                      struct nbt_dgram_packet *request,
      58             :                                      const char *mailslot_name,
      59             :                                      const char *my_netbios_name,
      60             :                                      struct nbt_browse_packet *reply)
      61             : {
      62           0 :         NTSTATUS status;
      63           0 :         enum ndr_err_code ndr_err;
      64           0 :         DATA_BLOB blob;
      65           0 :         TALLOC_CTX *tmp_ctx = talloc_new(dgmsock);
      66           0 :         struct nbt_name myname;
      67           0 :         struct socket_address *dest;
      68             : 
      69           0 :         ndr_err = ndr_push_struct_blob(&blob, tmp_ctx, reply,
      70             :                                       (ndr_push_flags_fn_t)ndr_push_nbt_browse_packet);
      71           0 :         if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
      72           0 :                 talloc_free(tmp_ctx);
      73           0 :                 return ndr_map_error2ntstatus(ndr_err);
      74             :         }
      75             : 
      76           0 :         make_nbt_name_client(&myname, my_netbios_name);
      77             : 
      78           0 :         dest = socket_address_from_strings(tmp_ctx, dgmsock->sock->backend_name,
      79           0 :                                            request->src_addr, request->src_port);
      80           0 :         if (!dest) {
      81           0 :                 talloc_free(tmp_ctx);
      82           0 :                 return NT_STATUS_NO_MEMORY;
      83             :         }
      84             : 
      85           0 :         status = dgram_mailslot_send(dgmsock, DGRAM_DIRECT_UNIQUE,
      86             :                                      mailslot_name,
      87             :                                      &request->data.msg.source_name,
      88             :                                      dest,
      89             :                                      &myname, &blob);
      90           0 :         talloc_free(tmp_ctx);
      91           0 :         return status;
      92             : }
      93             : 
      94         710 : NTSTATUS dgram_mailslot_browse_parse(struct dgram_mailslot_handler *dgmslot,
      95             :                                      TALLOC_CTX *mem_ctx,
      96             :                                      struct nbt_dgram_packet *dgram,
      97             :                                      struct nbt_browse_packet *pkt)
      98             : {
      99         710 :         DATA_BLOB data = dgram_mailslot_data(dgram);
     100           0 :         enum ndr_err_code ndr_err;
     101             : 
     102         710 :         ndr_err = ndr_pull_struct_blob(&data, mem_ctx, pkt,
     103             :                                       (ndr_pull_flags_fn_t)ndr_pull_nbt_browse_packet);
     104         710 :         if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     105           0 :                 NTSTATUS status = ndr_map_error2ntstatus(ndr_err);
     106           0 :                 DEBUG(0,("Failed to parse browse packet of length %d: %s\n",
     107             :                          (int)data.length, nt_errstr(status)));
     108           0 :                 if (DEBUGLVL(10)) {
     109           0 :                         (void)file_save("browse.dat", data.data, data.length);
     110             :                 }
     111           0 :                 return status;
     112             :         }
     113         710 :         return NT_STATUS_OK;
     114             : }

Generated by: LCOV version 1.14