LCOV - code coverage report
Current view: top level - libcli/nbt - nbtsocket.c (source / functions) Hit Total Coverage
Test: coverage report for abartlet/fix-coverage dd10fb34 Lines: 202 247 81.8 %
Date: 2021-09-23 10:06:22 Functions: 13 13 100.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             : 
       4             :    low level socket handling for nbt requests
       5             : 
       6             :    Copyright (C) Andrew Tridgell 2005
       7             : 
       8             :    This program is free software; you can redistribute it and/or modify
       9             :    it under the terms of the GNU General Public License as published by
      10             :    the Free Software Foundation; either version 3 of the License, or
      11             :    (at your option) any later version.
      12             : 
      13             :    This program is distributed in the hope that it will be useful,
      14             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      16             :    GNU General Public License for more details.
      17             : 
      18             :    You should have received a copy of the GNU General Public License
      19             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      20             : */
      21             : 
      22             : #include "includes.h"
      23             : #include "lib/events/events.h"
      24             : #include "../lib/util/dlinklist.h"
      25             : #include "../libcli/nbt/libnbt.h"
      26             : #include "../libcli/nbt/nbt_proto.h"
      27             : #include "lib/socket/socket.h"
      28             : #include "librpc/gen_ndr/ndr_nbt.h"
      29             : #include "param/param.h"
      30             : 
      31             : #define NBT_MAX_REPLIES 1000
      32             : 
      33             : /*
      34             :   destroy a pending request
      35             : */
      36       21833 : static int nbt_name_request_destructor(struct nbt_name_request *req)
      37             : {
      38       21833 :         if (req->state == NBT_REQUEST_SEND) {
      39        7652 :                 DLIST_REMOVE(req->nbtsock->send_queue, req);
      40             :         }
      41       21833 :         if (req->state == NBT_REQUEST_WAIT) {
      42        4209 :                 req->nbtsock->num_pending--;
      43             :         }
      44       21833 :         if (req->name_trn_id != 0 && !req->is_reply) {
      45       10066 :                 idr_remove(req->nbtsock->idr, req->name_trn_id);
      46       10066 :                 req->name_trn_id = 0;
      47             :         }
      48       21833 :         TALLOC_FREE(req->te);
      49       21833 :         if (req->nbtsock->send_queue == NULL) {
      50       20777 :                 TEVENT_FD_NOT_WRITEABLE(req->nbtsock->fde);
      51             :         }
      52       36711 :         if (req->nbtsock->num_pending == 0 &&
      53       17132 :             req->nbtsock->incoming.handler == NULL) {
      54       17054 :                 TEVENT_FD_NOT_READABLE(req->nbtsock->fde);
      55             :         }
      56       21833 :         return 0;
      57             : }
      58             : 
      59             : 
      60             : /*
      61             :   handle send events on a nbt name socket
      62             : */
      63       11711 : static void nbt_name_socket_send(struct nbt_name_socket *nbtsock)
      64             : {
      65             :         struct nbt_name_request *req;
      66       11711 :         TALLOC_CTX *tmp_ctx = talloc_new(nbtsock);
      67             :         NTSTATUS status;
      68             : 
      69       26507 :         while ((req = nbtsock->send_queue)) {
      70             :                 size_t len;
      71             : 
      72       12771 :                 len = req->encoded.length;
      73       12771 :                 status = socket_sendto(nbtsock->sock, &req->encoded, &len,
      74       12771 :                                        req->dest);
      75       12771 :                 if (NT_STATUS_IS_ERR(status)) goto failed;
      76             : 
      77        5123 :                 if (!NT_STATUS_IS_OK(status)) {
      78           0 :                         talloc_free(tmp_ctx);
      79           0 :                         return;
      80             :                 }
      81             : 
      82        5123 :                 DLIST_REMOVE(nbtsock->send_queue, req);
      83        5123 :                 req->state = NBT_REQUEST_WAIT;
      84        5123 :                 if (req->is_reply) {
      85        1775 :                         talloc_free(req);
      86             :                 } else {
      87        3348 :                         TEVENT_FD_READABLE(nbtsock->fde);
      88        3348 :                         nbtsock->num_pending++;
      89             :                 }
      90             :         }
      91             : 
      92        4063 :         TEVENT_FD_NOT_WRITEABLE(nbtsock->fde);
      93        4063 :         talloc_free(tmp_ctx);
      94        4063 :         return;
      95             : 
      96        7648 : failed:
      97        7664 :         DLIST_REMOVE(nbtsock->send_queue, req);
      98        7648 :         nbt_name_request_destructor(req);
      99        7648 :         req->status = status;
     100        7648 :         req->state = NBT_REQUEST_ERROR;
     101        7648 :         talloc_free(tmp_ctx);
     102        7648 :         if (req->async.fn) {
     103        7565 :                 req->async.fn(req);
     104          83 :         } else if (req->is_reply) {
     105          16 :                 talloc_free(req);
     106             :         }
     107        7632 :         return;
     108             : }
     109             : 
     110             : 
     111             : /*
     112             :   handle a request timeout
     113             : */
     114        1772 : static void nbt_name_socket_timeout(struct tevent_context *ev, struct tevent_timer *te,
     115             :                                     struct timeval t, void *private_data)
     116             : {
     117        1772 :         struct nbt_name_request *req = talloc_get_type(private_data,
     118             :                                                        struct nbt_name_request);
     119             : 
     120        1772 :         if (req->num_retries != 0) {
     121         958 :                 req->num_retries--;
     122         958 :                 req->te = tevent_add_timer(req->nbtsock->event_ctx, req,
     123             :                                            timeval_add(&t, req->timeout, 0),
     124             :                                            nbt_name_socket_timeout, req);
     125         958 :                 if (req->state != NBT_REQUEST_SEND) {
     126         909 :                         req->state = NBT_REQUEST_SEND;
     127         909 :                         DLIST_ADD_END(req->nbtsock->send_queue, req);
     128             :                 }
     129         958 :                 TEVENT_FD_WRITEABLE(req->nbtsock->fde);
     130         958 :                 return;
     131             :         }
     132             : 
     133         814 :         nbt_name_request_destructor(req);
     134         814 :         if (req->num_replies == 0) {
     135         814 :                 req->state = NBT_REQUEST_TIMEOUT;
     136         814 :                 req->status = NT_STATUS_IO_TIMEOUT;
     137             :         } else {
     138           0 :                 req->state = NBT_REQUEST_DONE;
     139           0 :                 req->status = NT_STATUS_OK;
     140             :         }
     141         814 :         if (req->async.fn) {
     142         747 :                 req->async.fn(req);
     143          67 :         } else if (req->is_reply) {
     144           0 :                 talloc_free(req);
     145             :         }
     146             : }
     147             : 
     148             : 
     149             : 
     150             : /**
     151             :   handle recv events on a nbt name socket
     152             : */
     153       13225 : static void nbt_name_socket_recv(struct nbt_name_socket *nbtsock)
     154             : {
     155       13225 :         TALLOC_CTX *tmp_ctx = talloc_new(nbtsock);
     156             :         NTSTATUS status;
     157             :         enum ndr_err_code ndr_err;
     158             :         struct socket_address *src;
     159             :         DATA_BLOB blob;
     160             :         size_t nread, dsize;
     161             :         struct nbt_name_packet *packet;
     162             :         struct nbt_name_request *req;
     163             : 
     164       13225 :         status = socket_pending(nbtsock->sock, &dsize);
     165       13225 :         if (!NT_STATUS_IS_OK(status)) {
     166           0 :                 talloc_free(tmp_ctx);
     167        2575 :                 return;
     168             :         }
     169             : 
     170             :         /*
     171             :          * Given a zero length, data_blob_talloc() returns the
     172             :          * NULL blob {NULL, 0}.
     173             :          *
     174             :          * We only want to error return here on a real out of memory condition
     175             :          * (i.e. dsize != 0, so the UDP packet has data, but the return of the
     176             :          * allocation failed, so blob.data==NULL).
     177             :          *
     178             :          * Given an actual zero length UDP packet having blob.data == NULL
     179             :          * isn't an out of memory error condition, that's the defined semantics
     180             :          * of data_blob_talloc() when asked for zero bytes.
     181             :          *
     182             :          * We still need to continue to do the zero-length socket_recvfrom()
     183             :          * read in order to clear the "read pending" condition on the socket.
     184             :          */
     185       13225 :         blob = data_blob_talloc(tmp_ctx, NULL, dsize);
     186       13225 :         if (blob.data == NULL && dsize != 0) {
     187           0 :                 talloc_free(tmp_ctx);
     188           0 :                 return;
     189             :         }
     190             : 
     191       13225 :         status = socket_recvfrom(nbtsock->sock, blob.data, blob.length, &nread,
     192             :                                  tmp_ctx, &src);
     193       13225 :         if (!NT_STATUS_IS_OK(status)) {
     194           2 :                 talloc_free(tmp_ctx);
     195           2 :                 return;
     196             :         }
     197             : 
     198       13223 :         packet = talloc(tmp_ctx, struct nbt_name_packet);
     199       13223 :         if (packet == NULL) {
     200           0 :                 talloc_free(tmp_ctx);
     201           0 :                 return;
     202             :         }
     203             : 
     204             :         /* parse the request */
     205       13223 :         ndr_err = ndr_pull_struct_blob(&blob, packet, packet,
     206             :                                        (ndr_pull_flags_fn_t)ndr_pull_nbt_name_packet);
     207       13223 :         if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     208           0 :                 status = ndr_map_error2ntstatus(ndr_err);
     209           0 :                 DEBUG(2,("Failed to parse incoming NBT name packet - %s\n",
     210             :                          nt_errstr(status)));
     211           0 :                 talloc_free(tmp_ctx);
     212           0 :                 return;
     213             :         }
     214             : 
     215       13223 :         if (DEBUGLVL(10)) {
     216           0 :                 DEBUG(10,("Received nbt packet of length %d from %s:%d\n",
     217             :                           (int)blob.length, src->addr, src->port));
     218           0 :                 NDR_PRINT_DEBUG(nbt_name_packet, packet);
     219             :         }
     220             : 
     221             :         /* if its not a reply then pass it off to the incoming request
     222             :            handler, if any */
     223       13223 :         if (!(packet->operation & NBT_FLAG_REPLY)) {
     224       11689 :                 if (nbtsock->incoming.handler) {
     225       11689 :                         nbtsock->incoming.handler(nbtsock, packet, src);
     226             :                 }
     227       11689 :                 talloc_free(tmp_ctx);
     228       11689 :                 return;
     229             :         }
     230             : 
     231             :         /* find the matching request */
     232        1534 :         req = (struct nbt_name_request *)idr_find(nbtsock->idr,
     233        1534 :                                                   packet->name_trn_id);
     234        1534 :         if (req == NULL) {
     235           6 :                 if (nbtsock->unexpected.handler) {
     236           1 :                         nbtsock->unexpected.handler(nbtsock, packet, src);
     237             :                 } else {
     238           5 :                         DEBUG(10,("Failed to match request for incoming name packet id 0x%04x on %p\n",
     239             :                                  packet->name_trn_id, nbtsock));
     240             :                 }
     241           6 :                 talloc_free(tmp_ctx);
     242           6 :                 return;
     243             :         }
     244             : 
     245        1528 :         talloc_steal(req, packet);
     246        1528 :         talloc_steal(req, src);
     247        1528 :         talloc_free(tmp_ctx);
     248        1528 :         nbt_name_socket_handle_response_packet(req, packet, src);
     249             : }
     250             : 
     251        1528 : void nbt_name_socket_handle_response_packet(struct nbt_name_request *req,
     252             :                                             struct nbt_name_packet *packet,
     253             :                                             struct socket_address *src)
     254             : {
     255             :         /* if this is a WACK response, this we need to go back to waiting,
     256             :            but perhaps increase the timeout */
     257        1528 :         if ((packet->operation & NBT_OPCODE) == NBT_OPCODE_WACK) {
     258             :                 uint32_t ttl;
     259          18 :                 if (req->received_wack || packet->ancount < 1) {
     260           0 :                         nbt_name_request_destructor(req);
     261           0 :                         req->status = NT_STATUS_INVALID_NETWORK_RESPONSE;
     262           0 :                         req->state  = NBT_REQUEST_ERROR;
     263           0 :                         goto done;
     264             :                 }
     265          18 :                 talloc_free(req->te);
     266             :                 /* we know we won't need any more retries - the server
     267             :                    has received our request */
     268          18 :                 req->num_retries   = 0;
     269          18 :                 req->received_wack = true;
     270             :                 /*
     271             :                  * there is a timeout in the packet,
     272             :                  * it is 5 + 4 * num_old_addresses
     273             :                  *
     274             :                  * although w2k3 screws it up
     275             :                  * and uses num_old_addresses = 0
     276             :                  *
     277             :                  * so we better fallback to the maximum
     278             :                  * of num_old_addresses = 25 if we got
     279             :                  * a timeout of less than 9s (5 + 4*1)
     280             :                  * or more than 105s (5 + 4*25).
     281             :                  */
     282          18 :                 ttl = packet->answers[0].ttl;
     283          18 :                 if ((ttl < (5 + 4*1)) || (ttl > (5 + 4*25))) {
     284           0 :                         ttl = 5 + 4*25;
     285             :                 }
     286          18 :                 req->timeout = ttl;
     287          18 :                 req->te = tevent_add_timer(req->nbtsock->event_ctx, req,
     288             :                                            timeval_current_ofs(req->timeout, 0),
     289             :                                            nbt_name_socket_timeout, req);
     290          18 :                 return;
     291             :         }
     292             : 
     293             : 
     294        1510 :         req->replies = talloc_realloc(req, req->replies, struct nbt_name_reply, req->num_replies+1);
     295        1510 :         if (req->replies == NULL) {
     296           0 :                 nbt_name_request_destructor(req);
     297           0 :                 req->state  = NBT_REQUEST_ERROR;
     298           0 :                 req->status = NT_STATUS_NO_MEMORY;
     299           0 :                 goto done;
     300             :         }
     301             : 
     302        1510 :         talloc_steal(req, src);
     303        1510 :         req->replies[req->num_replies].dest   = src;
     304        1510 :         talloc_steal(req, packet);
     305        1510 :         req->replies[req->num_replies].packet = packet;
     306        1510 :         req->num_replies++;
     307             : 
     308             :         /* if we don't want multiple replies then we are done */
     309        1510 :         if (req->allow_multiple_replies &&
     310           0 :             req->num_replies < NBT_MAX_REPLIES) {
     311           0 :                 return;
     312             :         }
     313             : 
     314        1510 :         nbt_name_request_destructor(req);
     315        1510 :         req->state  = NBT_REQUEST_DONE;
     316        1510 :         req->status = NT_STATUS_OK;
     317             : 
     318        1510 : done:
     319        1510 :         if (req->async.fn) {
     320         313 :                 req->async.fn(req);
     321             :         }
     322             : }
     323             : 
     324             : /*
     325             :   handle fd events on a nbt_name_socket
     326             : */
     327       24515 : static void nbt_name_socket_handler(struct tevent_context *ev, struct tevent_fd *fde,
     328             :                                     uint16_t flags, void *private_data)
     329             : {
     330       24515 :         struct nbt_name_socket *nbtsock = talloc_get_type(private_data,
     331             :                                                           struct nbt_name_socket);
     332       24515 :         if (flags & TEVENT_FD_WRITE) {
     333       11711 :                 nbt_name_socket_send(nbtsock);
     334             :         }
     335       24515 :         if (flags & TEVENT_FD_READ) {
     336       13225 :                 nbt_name_socket_recv(nbtsock);
     337             :         }
     338       24515 : }
     339             : 
     340             : 
     341             : /*
     342             :   initialise a nbt_name_socket. The event_ctx is optional, if provided
     343             :   then operations will use that event context
     344             : */
     345        8440 : _PUBLIC_ struct nbt_name_socket *nbt_name_socket_init(TALLOC_CTX *mem_ctx,
     346             :                                              struct tevent_context *event_ctx)
     347             : {
     348             :         struct nbt_name_socket *nbtsock;
     349             :         NTSTATUS status;
     350             : 
     351        8440 :         nbtsock = talloc(mem_ctx, struct nbt_name_socket);
     352        8440 :         if (nbtsock == NULL) goto failed;
     353             : 
     354        8440 :         nbtsock->event_ctx = event_ctx;
     355        8440 :         if (nbtsock->event_ctx == NULL) goto failed;
     356             : 
     357        8440 :         status = socket_create(nbtsock, "ip", SOCKET_TYPE_DGRAM,
     358             :                                &nbtsock->sock, 0);
     359        8440 :         if (!NT_STATUS_IS_OK(status)) goto failed;
     360             : 
     361        8440 :         socket_set_option(nbtsock->sock, "SO_BROADCAST", "1");
     362             : 
     363        8440 :         nbtsock->idr = idr_init(nbtsock);
     364        8440 :         if (nbtsock->idr == NULL) goto failed;
     365             : 
     366        8440 :         nbtsock->send_queue = NULL;
     367        8440 :         nbtsock->num_pending = 0;
     368        8440 :         nbtsock->incoming.handler = NULL;
     369        8440 :         nbtsock->unexpected.handler = NULL;
     370             : 
     371        8440 :         nbtsock->fde = tevent_add_fd(nbtsock->event_ctx, nbtsock,
     372             :                                      socket_get_fd(nbtsock->sock), 0,
     373             :                                      nbt_name_socket_handler, nbtsock);
     374             : 
     375        8440 :         return nbtsock;
     376             : 
     377           0 : failed:
     378           0 :         talloc_free(nbtsock);
     379           0 :         return NULL;
     380             : }
     381             : 
     382             : /*
     383             :   send off a nbt name request
     384             : */
     385       10066 : struct nbt_name_request *nbt_name_request_send(TALLOC_CTX *mem_ctx,
     386             :                                                struct nbt_name_socket *nbtsock,
     387             :                                                struct socket_address *dest,
     388             :                                                struct nbt_name_packet *request,
     389             :                                                int timeout, int retries,
     390             :                                                bool allow_multiple_replies)
     391             : {
     392             :         struct nbt_name_request *req;
     393             :         int id;
     394             :         enum ndr_err_code ndr_err;
     395             : 
     396       10066 :         req = talloc_zero(mem_ctx, struct nbt_name_request);
     397       10066 :         if (req == NULL) goto failed;
     398             : 
     399       10066 :         req->nbtsock                = nbtsock;
     400       10066 :         req->allow_multiple_replies = allow_multiple_replies;
     401       10066 :         req->state                  = NBT_REQUEST_SEND;
     402       10066 :         req->is_reply               = false;
     403       10066 :         req->timeout                = timeout;
     404       10066 :         req->num_retries            = retries;
     405       10066 :         req->dest                   = socket_address_copy(req, dest);
     406       10066 :         if (req->dest == NULL) goto failed;
     407             : 
     408             :         /* we select a random transaction id unless the user supplied one */
     409       10066 :         if (request->name_trn_id == 0) {
     410       10066 :                 id = idr_get_new_random(req->nbtsock->idr, req, UINT16_MAX);
     411             :         } else {
     412           0 :                 if (idr_find(req->nbtsock->idr, request->name_trn_id)) goto failed;
     413           0 :                 id = idr_get_new_above(req->nbtsock->idr, req, request->name_trn_id,
     414             :                                        UINT16_MAX);
     415             :         }
     416       10066 :         if (id == -1) goto failed;
     417             : 
     418       10066 :         request->name_trn_id = id;
     419       10066 :         req->name_trn_id     = id;
     420             : 
     421       10066 :         req->te = tevent_add_timer(nbtsock->event_ctx, req,
     422             :                                    timeval_current_ofs(req->timeout, 0),
     423             :                                    nbt_name_socket_timeout, req);
     424             : 
     425       10066 :         talloc_set_destructor(req, nbt_name_request_destructor);
     426             : 
     427       10066 :         ndr_err = ndr_push_struct_blob(&req->encoded, req,
     428             :                                        request,
     429             :                                        (ndr_push_flags_fn_t)ndr_push_nbt_name_packet);
     430       10066 :         if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) goto failed;
     431             : 
     432       10066 :         DLIST_ADD_END(nbtsock->send_queue, req);
     433             : 
     434       10066 :         if (DEBUGLVL(10)) {
     435           0 :                 DEBUG(10,("Queueing nbt packet to %s:%d\n",
     436             :                           req->dest->addr, req->dest->port));
     437           0 :                 NDR_PRINT_DEBUG(nbt_name_packet, request);
     438             :         }
     439             : 
     440       10066 :         TEVENT_FD_WRITEABLE(nbtsock->fde);
     441             : 
     442       10066 :         return req;
     443             : 
     444           0 : failed:
     445           0 :         talloc_free(req);
     446           0 :         return NULL;
     447             : }
     448             : 
     449             : 
     450             : /*
     451             :   send off a nbt name reply
     452             : */
     453        1795 : _PUBLIC_ NTSTATUS nbt_name_reply_send(struct nbt_name_socket *nbtsock,
     454             :                              struct socket_address *dest,
     455             :                              struct nbt_name_packet *request)
     456             : {
     457             :         struct nbt_name_request *req;
     458             :         enum ndr_err_code ndr_err;
     459             : 
     460        1795 :         req = talloc_zero(nbtsock, struct nbt_name_request);
     461        1795 :         NT_STATUS_HAVE_NO_MEMORY(req);
     462             : 
     463        1795 :         req->nbtsock   = nbtsock;
     464        1795 :         req->dest = socket_address_copy(req, dest);
     465        1795 :         if (req->dest == NULL) goto failed;
     466        1795 :         req->state     = NBT_REQUEST_SEND;
     467        1795 :         req->is_reply = true;
     468             : 
     469        1795 :         talloc_set_destructor(req, nbt_name_request_destructor);
     470             : 
     471        1795 :         if (DEBUGLVL(10)) {
     472           0 :                 NDR_PRINT_DEBUG(nbt_name_packet, request);
     473             :         }
     474             : 
     475        1795 :         ndr_err = ndr_push_struct_blob(&req->encoded, req,
     476             :                                        request,
     477             :                                        (ndr_push_flags_fn_t)ndr_push_nbt_name_packet);
     478        1795 :         if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     479           4 :                 talloc_free(req);
     480           4 :                 return ndr_map_error2ntstatus(ndr_err);
     481             :         }
     482             : 
     483        1791 :         DLIST_ADD_END(nbtsock->send_queue, req);
     484             : 
     485        1791 :         TEVENT_FD_WRITEABLE(nbtsock->fde);
     486             : 
     487        1791 :         return NT_STATUS_OK;
     488             : 
     489           0 : failed:
     490           0 :         talloc_free(req);
     491           0 :         return NT_STATUS_NO_MEMORY;
     492             : }
     493             : 
     494             : /*
     495             :   wait for a nbt request to complete
     496             : */
     497        9956 : NTSTATUS nbt_name_request_recv(struct nbt_name_request *req)
     498             : {
     499        9956 :         if (!req) return NT_STATUS_NO_MEMORY;
     500             : 
     501       21194 :         while (req->state < NBT_REQUEST_DONE) {
     502        2863 :                 if (tevent_loop_once(req->nbtsock->event_ctx) != 0) {
     503           0 :                         req->state = NBT_REQUEST_ERROR;
     504           0 :                         req->status = NT_STATUS_UNEXPECTED_NETWORK_ERROR;
     505           0 :                         break;
     506             :                 }
     507             :         }
     508        9956 :         return req->status;
     509             : }
     510             : 
     511             : 
     512             : /*
     513             :   setup a handler for incoming requests
     514             : */
     515         545 : _PUBLIC_ NTSTATUS nbt_set_incoming_handler(struct nbt_name_socket *nbtsock,
     516             :                                   void (*handler)(struct nbt_name_socket *, struct nbt_name_packet *,
     517             :                                                   struct socket_address *),
     518             :                                   void *private_data)
     519             : {
     520         545 :         nbtsock->incoming.handler = handler;
     521         545 :         nbtsock->incoming.private_data = private_data;
     522         545 :         TEVENT_FD_READABLE(nbtsock->fde);
     523         545 :         return NT_STATUS_OK;
     524             : }
     525             : 
     526             : /*
     527             :   setup a handler for unexpected requests
     528             : */
     529         126 : NTSTATUS nbt_set_unexpected_handler(struct nbt_name_socket *nbtsock,
     530             :                                     void (*handler)(struct nbt_name_socket *, struct nbt_name_packet *,
     531             :                                                     struct socket_address *),
     532             :                                     void *private_data)
     533             : {
     534         126 :         nbtsock->unexpected.handler = handler;
     535         126 :         nbtsock->unexpected.private_data = private_data;
     536         126 :         TEVENT_FD_READABLE(nbtsock->fde);
     537         126 :         return NT_STATUS_OK;
     538             : }
     539             : 
     540             : /*
     541             :   turn a NBT rcode into a NTSTATUS
     542             : */
     543          30 : _PUBLIC_ NTSTATUS nbt_rcode_to_ntstatus(uint8_t rcode)
     544             : {
     545             :         size_t i;
     546             :         struct {
     547             :                 enum nbt_rcode rcode;
     548             :                 NTSTATUS status;
     549          30 :         } map[] = {
     550             :                 { NBT_RCODE_FMT, NT_STATUS_INVALID_PARAMETER },
     551             :                 { NBT_RCODE_SVR, NT_STATUS_SERVER_DISABLED },
     552             :                 { NBT_RCODE_NAM, NT_STATUS_OBJECT_NAME_NOT_FOUND },
     553             :                 { NBT_RCODE_IMP, NT_STATUS_NOT_SUPPORTED },
     554             :                 { NBT_RCODE_RFS, NT_STATUS_ACCESS_DENIED },
     555             :                 { NBT_RCODE_ACT, NT_STATUS_ADDRESS_ALREADY_EXISTS },
     556             :                 { NBT_RCODE_CFT, NT_STATUS_CONFLICTING_ADDRESSES }
     557             :         };
     558          90 :         for (i=0;i<ARRAY_SIZE(map);i++) {
     559          90 :                 if (map[i].rcode == rcode) {
     560          30 :                         return map[i].status;
     561             :                 }
     562             :         }
     563           0 :         return NT_STATUS_UNSUCCESSFUL;
     564             : }

Generated by: LCOV version 1.13