Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
1 deleted
11 edited
2 copied

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/libcli/nbt/libnbt.h

    r414 r745  
    9696        struct socket_context *sock;
    9797        struct tevent_context *event_ctx;
    98         struct smb_iconv_convenience *iconv_convenience;
    9998
    10099        /* a queue of requests pending to be sent */
     
    276275
    277276struct nbt_name_socket *nbt_name_socket_init(TALLOC_CTX *mem_ctx,
    278                                              struct tevent_context *event_ctx,
    279                                              struct smb_iconv_convenience *iconv_convenience);
     277                                             struct tevent_context *event_ctx);
    280278void nbt_name_socket_handle_response_packet(struct nbt_name_request *req,
    281279                                            struct nbt_name_packet *packet,
     
    295293
    296294NTSTATUS nbt_name_dup(TALLOC_CTX *mem_ctx, struct nbt_name *name, struct nbt_name *newname);
    297 NTSTATUS nbt_name_to_blob(TALLOC_CTX *mem_ctx, struct smb_iconv_convenience *iconv_convenience, DATA_BLOB *blob, struct nbt_name *name);
     295NTSTATUS nbt_name_to_blob(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, struct nbt_name *name);
    298296NTSTATUS nbt_name_from_blob(TALLOC_CTX *mem_ctx, const DATA_BLOB *blob, struct nbt_name *name);
    299297void nbt_choose_called_name(TALLOC_CTX *mem_ctx, struct nbt_name *n, const char *name, int type);
     
    342340NTSTATUS nbt_rcode_to_ntstatus(uint8_t rcode);
    343341
    344 struct composite_context;
    345 struct composite_context *nbt_name_register_bcast_send(struct nbt_name_socket *nbtsock,
    346                                                        struct nbt_name_register_bcast *io);
    347 NTSTATUS nbt_name_register_bcast_recv(struct composite_context *c);
    348 struct composite_context *nbt_name_register_wins_send(struct nbt_name_socket *nbtsock,
    349                                                       struct nbt_name_register_wins *io);
    350 NTSTATUS nbt_name_refresh_wins_recv(struct composite_context *c, TALLOC_CTX *mem_ctx,
    351                                      struct nbt_name_refresh_wins *io);
    352 struct composite_context *nbt_name_refresh_wins_send(struct nbt_name_socket *nbtsock,
    353                                                       struct nbt_name_refresh_wins *io);
    354 NTSTATUS nbt_name_register_wins_recv(struct composite_context *c, TALLOC_CTX *mem_ctx,
     342struct tevent_context;
     343struct tevent_req;
     344struct tevent_req *nbt_name_register_bcast_send(TALLOC_CTX *mem_ctx,
     345                                        struct tevent_context *ev,
     346                                        struct nbt_name_socket *nbtsock,
     347                                        struct nbt_name_register_bcast *io);
     348NTSTATUS nbt_name_register_bcast_recv(struct tevent_req *req);
     349struct tevent_req *nbt_name_register_wins_send(TALLOC_CTX *mem_ctx,
     350                                               struct tevent_context *ev,
     351                                               struct nbt_name_socket *nbtsock,
     352                                               struct nbt_name_register_wins *io);
     353NTSTATUS nbt_name_register_wins_recv(struct tevent_req *req,
     354                                     TALLOC_CTX *mem_ctx,
    355355                                     struct nbt_name_register_wins *io);
    356 
     356struct tevent_req *nbt_name_refresh_wins_send(TALLOC_CTX *mem_ctx,
     357                                              struct tevent_context *ev,
     358                                              struct nbt_name_socket *nbtsock,
     359                                              struct nbt_name_refresh_wins *io);
     360NTSTATUS nbt_name_refresh_wins_recv(struct tevent_req *req,
     361                                    TALLOC_CTX *mem_ctx,
     362                                    struct nbt_name_refresh_wins *io);
    357363
    358364XFILE *startlmhosts(const char *fname);
     
    361367void endlmhosts(XFILE *fp);
    362368
     369NTSTATUS resolve_lmhosts_file_as_sockaddr(const char *lmhosts_file,
     370                                          const char *name, int name_type,
     371                                          TALLOC_CTX *mem_ctx,
     372                                          struct sockaddr_storage **return_iplist,
     373                                          int *return_count);
     374
     375NTSTATUS resolve_dns_hosts_file_as_sockaddr(const char *dns_hosts_file,
     376                                            const char *name, bool srv_lookup,
     377                                            TALLOC_CTX *mem_ctx,
     378                                            struct sockaddr_storage **return_iplist,
     379                                            int *return_count);
     380
    363381#endif /* __LIBNBT_H__ */
  • trunk/server/libcli/nbt/lmhosts.c

    r414 r745  
    2727#include "system/filesys.h"
    2828#include "system/network.h"
     29#include "../libcli/nbt/libnbt.h"
    2930
    3031/********************************************************
     
    156157}
    157158
     159/********************************************************
     160 Resolve via "lmhosts" method.
     161*********************************************************/
     162
     163NTSTATUS resolve_lmhosts_file_as_sockaddr(const char *lmhosts_file,
     164                                          const char *name, int name_type,
     165                                          TALLOC_CTX *mem_ctx,
     166                                          struct sockaddr_storage **return_iplist,
     167                                          int *return_count)
     168{
     169        /*
     170         * "lmhosts" means parse the local lmhosts file.
     171         */
     172
     173        XFILE *fp;
     174        char *lmhost_name = NULL;
     175        int name_type2;
     176        struct sockaddr_storage return_ss;
     177        NTSTATUS status = NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND;
     178        TALLOC_CTX *ctx = NULL;
     179
     180        *return_iplist = NULL;
     181        *return_count = 0;
     182
     183        DEBUG(3,("resolve_lmhosts: "
     184                "Attempting lmhosts lookup for name %s<0x%x>\n",
     185                name, name_type));
     186
     187        fp = startlmhosts(lmhosts_file);
     188
     189        if ( fp == NULL )
     190                return NT_STATUS_NO_SUCH_FILE;
     191
     192        ctx = talloc_new(mem_ctx);
     193        if (!ctx) {
     194                endlmhosts(fp);
     195                return NT_STATUS_NO_MEMORY;
     196        }
     197
     198        while (getlmhostsent(ctx, fp, &lmhost_name, &name_type2, &return_ss)) {
     199
     200                if (!strequal(name, lmhost_name)) {
     201                        TALLOC_FREE(lmhost_name);
     202                        continue;
     203                }
     204
     205                if ((name_type2 != -1) && (name_type != name_type2)) {
     206                        TALLOC_FREE(lmhost_name);
     207                        continue;
     208                }
     209               
     210                *return_iplist = talloc_realloc(ctx, (*return_iplist),
     211                                                struct sockaddr_storage,
     212                                                (*return_count)+1);
     213
     214                if ((*return_iplist) == NULL) {
     215                        TALLOC_FREE(ctx);
     216                        endlmhosts(fp);
     217                        DEBUG(3,("resolve_lmhosts: talloc_realloc fail !\n"));
     218                        return NT_STATUS_NO_MEMORY;
     219                }
     220
     221                (*return_iplist)[*return_count] = return_ss;
     222                *return_count += 1;
     223
     224                /* we found something */
     225                status = NT_STATUS_OK;
     226
     227                /* Multiple names only for DC lookup */
     228                if (name_type != 0x1c)
     229                        break;
     230        }
     231
     232        talloc_steal(mem_ctx, *return_iplist);
     233        TALLOC_FREE(ctx);
     234        endlmhosts(fp);
     235        return status;
     236}
     237
  • trunk/server/libcli/nbt/man/nmblookup.1.xml

    r414 r745  
    11<?xml version="1.0" encoding="iso-8859-1"?>
    2 <!DOCTYPE refentry PUBLIC "-//Samba-Team//DTD DocBook V4.2-Based Variant V1.0//EN" "http://www.samba.org/samba/DTD/samba-doc">
     2<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN" "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">
    33<refentry id="nmblookup">
    44
     
    107107                </varlistentry>
    108108
    109 
    110 
    111                 &popt.common.connection;
    112                 &stdarg.help;
    113 
    114109                <varlistentry>
    115110                <term>-B &lt;broadcast address&gt;</term>
     
    124119                </varlistentry>
    125120
    126 
    127 
    128121                <varlistentry>
    129122                <term>-U &lt;unicast address&gt;</term>
     
    133126                query a WINS server.</para></listitem>
    134127                </varlistentry>
    135                
    136                 &stdarg.server.debug;   
    137                 &popt.common.samba;
    138128
    139129                <varlistentry>
  • trunk/server/libcli/nbt/namerefresh.c

    r414 r745  
    2121
    2222#include "includes.h"
     23#include <tevent.h>
    2324#include "../libcli/nbt/libnbt.h"
    2425#include "../libcli/nbt/nbt_proto.h"
    25 #include "libcli/composite/composite.h"
    2626#include "lib/socket/socket.h"
     27#include "lib/util/tevent_ntstatus.h"
    2728
    2829/*
     
    143144  reply for each address
    144145*/
    145 struct refresh_wins_state {
     146struct nbt_name_refresh_wins_state {
    146147        struct nbt_name_socket *nbtsock;
    147148        struct nbt_name_refresh *io;
    148         const char **wins_servers;
     149        char **wins_servers;
    149150        uint16_t wins_port;
    150         const char **addresses;
     151        char **addresses;
    151152        int address_idx;
    152         struct nbt_name_request *req;
    153153};
    154154
    155 
    156 /**
    157   state handler for WINS multi-homed multi-server name refresh
    158 */
    159 static void name_refresh_wins_handler(struct nbt_name_request *req)
    160 {
    161         struct composite_context *c = talloc_get_type(req->async.private_data,
    162                                                       struct composite_context);
    163         struct refresh_wins_state *state = talloc_get_type(c->private_data,
    164                                                             struct refresh_wins_state);
    165         NTSTATUS status;
    166 
    167         status = nbt_name_refresh_recv(state->req, state, state->io);
    168         if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
    169                 /* the refresh timed out - try the next WINS server */
    170                 state->wins_servers++;
    171                 state->address_idx = 0;
    172                 if (state->wins_servers[0] == NULL) {
    173                         c->state = COMPOSITE_STATE_ERROR;
    174                         c->status = status;
    175                         goto done;
    176                 }
    177                 state->io->in.dest_addr = state->wins_servers[0];
    178                 state->io->in.dest_port = state->wins_port;
    179                 state->io->in.address   = state->addresses[0];
    180                 state->req = nbt_name_refresh_send(state->nbtsock, state->io);
    181                 if (state->req == NULL) {
    182                         c->state = COMPOSITE_STATE_ERROR;
    183                         c->status = NT_STATUS_NO_MEMORY;
    184                 } else {
    185                         state->req->async.fn      = name_refresh_wins_handler;
    186                         state->req->async.private_data = c;
    187                 }
    188         } else if (!NT_STATUS_IS_OK(status)) {
    189                 c->state = COMPOSITE_STATE_ERROR;
    190                 c->status = status;
    191         } else {
    192                 if (state->io->out.rcode == 0 &&
    193                     state->addresses[state->address_idx+1] != NULL) {
    194                         /* refresh our next address */
    195                         state->io->in.address = state->addresses[++(state->address_idx)];
    196                         state->req = nbt_name_refresh_send(state->nbtsock, state->io);
    197                         if (state->req == NULL) {
    198                                 c->state = COMPOSITE_STATE_ERROR;
    199                                 c->status = NT_STATUS_NO_MEMORY;
    200                         } else {
    201                                 state->req->async.fn      = name_refresh_wins_handler;
    202                                 state->req->async.private_data = c;
    203                         }
    204                 } else {
    205                         c->state = COMPOSITE_STATE_DONE;
    206                         c->status = NT_STATUS_OK;
    207                 }
    208         }
    209 
    210 done:
    211         if (c->state >= COMPOSITE_STATE_DONE &&
    212             c->async.fn) {
    213                 c->async.fn(c);
    214         }
    215 }
     155static void nbt_name_refresh_wins_handler(struct nbt_name_request *subreq);
    216156
    217157/**
    218158  the async send call for a multi-server WINS refresh
    219159*/
    220 _PUBLIC_ struct composite_context *nbt_name_refresh_wins_send(struct nbt_name_socket *nbtsock,
    221                                                       struct nbt_name_refresh_wins *io)
    222 {
    223         struct composite_context *c;
    224         struct refresh_wins_state *state;
    225 
    226         c = talloc_zero(nbtsock, struct composite_context);
    227         if (c == NULL) goto failed;
    228 
    229         state = talloc(c, struct refresh_wins_state);
    230         if (state == NULL) goto failed;
     160_PUBLIC_ struct tevent_req *nbt_name_refresh_wins_send(TALLOC_CTX *mem_ctx,
     161                                                struct tevent_context *ev,
     162                                                struct nbt_name_socket *nbtsock,
     163                                                struct nbt_name_refresh_wins *io)
     164{
     165        struct tevent_req *req;
     166        struct nbt_name_refresh_wins_state *state;
     167        struct nbt_name_request *subreq;
     168
     169        req = tevent_req_create(mem_ctx, &state,
     170                                struct nbt_name_refresh_wins_state);
     171        if (req == NULL) {
     172                return NULL;
     173        }
    231174
    232175        state->io = talloc(state, struct nbt_name_refresh);
    233         if (state->io == NULL) goto failed;
     176        if (tevent_req_nomem(state->io, req)) {
     177                return tevent_req_post(req, ev);
     178        }
     179
     180        if (io->in.wins_servers == NULL) {
     181                tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
     182                return tevent_req_post(req, ev);
     183        }
     184
     185        if (io->in.wins_servers[0] == NULL) {
     186                tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
     187                return tevent_req_post(req, ev);
     188        }
     189
     190        if (io->in.addresses == NULL) {
     191                tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
     192                return tevent_req_post(req, ev);
     193        }
     194
     195        if (io->in.addresses[0] == NULL) {
     196                tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
     197                return tevent_req_post(req, ev);
     198        }
    234199
    235200        state->wins_port = io->in.wins_port;
    236         state->wins_servers = (const char **)str_list_copy(state, io->in.wins_servers);
    237         if (state->wins_servers == NULL ||
    238             state->wins_servers[0] == NULL) goto failed;
    239 
    240         state->addresses = (const char **)str_list_copy(state, io->in.addresses);
    241         if (state->addresses == NULL ||
    242             state->addresses[0] == NULL) goto failed;
     201        state->wins_servers = str_list_copy(state, io->in.wins_servers);
     202        if (tevent_req_nomem(state->wins_servers, req)) {
     203                return tevent_req_post(req, ev);
     204        }
     205
     206        state->addresses = str_list_copy(state, io->in.addresses);
     207        if (tevent_req_nomem(state->addresses, req)) {
     208                return tevent_req_post(req, ev);
     209        }
    243210
    244211        state->io->in.name            = io->in.name;
     
    255222        state->address_idx = 0;
    256223
    257         state->req = nbt_name_refresh_send(nbtsock, state->io);
    258         if (state->req == NULL) goto failed;
    259 
    260         state->req->async.fn      = name_refresh_wins_handler;
    261         state->req->async.private_data = c;
    262 
    263         c->private_data = state;
    264         c->state        = COMPOSITE_STATE_IN_PROGRESS;
    265         c->event_ctx    = nbtsock->event_ctx;
    266 
    267         return c;
    268 
    269 failed:
    270         talloc_free(c);
    271         return NULL;
     224        subreq = nbt_name_refresh_send(nbtsock, state->io);
     225        if (tevent_req_nomem(subreq, req)) {
     226                return tevent_req_post(req, ev);
     227        }
     228
     229        subreq->async.fn = nbt_name_refresh_wins_handler;
     230        subreq->async.private_data = req;
     231
     232        return req;
     233}
     234
     235static void nbt_name_refresh_wins_handler(struct nbt_name_request *subreq)
     236{
     237        struct tevent_req *req =
     238                talloc_get_type_abort(subreq->async.private_data,
     239                struct tevent_req);
     240        struct nbt_name_refresh_wins_state *state =
     241                tevent_req_data(req,
     242                struct nbt_name_refresh_wins_state);
     243        NTSTATUS status;
     244
     245        status = nbt_name_refresh_recv(subreq, state, state->io);
     246        if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
     247                /* the refresh timed out - try the next WINS server */
     248                state->wins_servers++;
     249                if (state->wins_servers[0] == NULL) {
     250                        tevent_req_nterror(req, status);
     251                        return;
     252                }
     253
     254                state->address_idx = 0;
     255                state->io->in.dest_addr = state->wins_servers[0];
     256                state->io->in.dest_port = state->wins_port;
     257                state->io->in.address   = state->addresses[0];
     258
     259                subreq = nbt_name_refresh_send(state->nbtsock, state->io);
     260                if (tevent_req_nomem(subreq, req)) {
     261                        return;
     262                }
     263                subreq->async.fn = nbt_name_refresh_wins_handler;
     264                subreq->async.private_data = req;
     265        } else if (!NT_STATUS_IS_OK(status)) {
     266                tevent_req_nterror(req, status);
     267                return;
     268        }
     269
     270        if (state->io->out.rcode == 0 &&
     271            state->addresses[state->address_idx+1] != NULL) {
     272                /* refresh our next address */
     273                state->io->in.address = state->addresses[++(state->address_idx)];
     274                subreq = nbt_name_refresh_send(state->nbtsock, state->io);
     275                if (tevent_req_nomem(subreq, req)) {
     276                        return;
     277                }
     278                subreq->async.fn = nbt_name_refresh_wins_handler;
     279                subreq->async.private_data = req;
     280                return;
     281        }
     282
     283        tevent_req_done(req);
    272284}
    273285
     
    275287  multi-homed WINS name refresh - recv side
    276288*/
    277 _PUBLIC_ NTSTATUS nbt_name_refresh_wins_recv(struct composite_context *c, TALLOC_CTX *mem_ctx,
    278                                      struct nbt_name_refresh_wins *io)
    279 {
     289_PUBLIC_ NTSTATUS nbt_name_refresh_wins_recv(struct tevent_req *req,
     290                                             TALLOC_CTX *mem_ctx,
     291                                             struct nbt_name_refresh_wins *io)
     292{
     293        struct nbt_name_refresh_wins_state *state =
     294                tevent_req_data(req,
     295                struct nbt_name_refresh_wins_state);
    280296        NTSTATUS status;
    281         status = composite_wait(c);
    282         if (NT_STATUS_IS_OK(status)) {
    283                 struct refresh_wins_state *state =
    284                         talloc_get_type(c->private_data, struct refresh_wins_state);
    285                 io->out.wins_server = talloc_steal(mem_ctx, state->wins_servers[0]);
    286                 io->out.rcode = state->io->out.rcode;
    287         }
    288         talloc_free(c);
    289         return status;
     297
     298        if (tevent_req_is_nterror(req, &status)) {
     299                tevent_req_received(req);
     300                return status;
     301        }
     302
     303        io->out.wins_server = talloc_move(mem_ctx, &state->wins_servers[0]);
     304        io->out.rcode = state->io->out.rcode;
     305
     306        tevent_req_received(req);
     307        return NT_STATUS_OK;
    290308}
    291309
     
    294312*/
    295313_PUBLIC_ NTSTATUS nbt_name_refresh_wins(struct nbt_name_socket *nbtsock,
    296                                 TALLOC_CTX *mem_ctx,
    297                                 struct nbt_name_refresh_wins *io)
    298 {
    299         struct composite_context *c = nbt_name_refresh_wins_send(nbtsock, io);
    300         return nbt_name_refresh_wins_recv(c, mem_ctx, io);
    301 }
     314                                        TALLOC_CTX *mem_ctx,
     315                                        struct nbt_name_refresh_wins *io)
     316{
     317        TALLOC_CTX *frame = talloc_stackframe();
     318        struct tevent_context *ev;
     319        struct tevent_req *subreq;
     320        NTSTATUS status;
     321
     322        /*
     323         * TODO: create a temporary event context
     324         */
     325        ev = nbtsock->event_ctx;
     326
     327        subreq = nbt_name_refresh_wins_send(frame, ev, nbtsock, io);
     328        if (subreq == NULL) {
     329                talloc_free(frame);
     330                return NT_STATUS_NO_MEMORY;
     331        }
     332
     333        if (!tevent_req_poll(subreq, ev)) {
     334                status = map_nt_error_from_unix(errno);
     335                talloc_free(frame);
     336                return status;
     337        }
     338
     339        status = nbt_name_refresh_wins_recv(subreq, mem_ctx, io);
     340        if (!NT_STATUS_IS_OK(status)) {
     341                talloc_free(frame);
     342                return status;
     343        }
     344
     345        TALLOC_FREE(frame);
     346        return NT_STATUS_OK;
     347}
  • trunk/server/libcli/nbt/nameregister.c

    r414 r745  
    2121
    2222#include "includes.h"
     23#include <tevent.h>
    2324#include "../libcli/nbt/libnbt.h"
    2425#include "../libcli/nbt/nbt_proto.h"
    25 #include "libcli/composite/composite.h"
    2626#include "lib/socket/socket.h"
    2727#include "librpc/gen_ndr/ndr_nbt.h"
     28#include "../lib/util/tevent_ntstatus.h"
    2829
    2930/*
     
    149150  a name registration demand
    150151*/
    151 struct register_bcast_state {
     152struct nbt_name_register_bcast_state {
    152153        struct nbt_name_socket *nbtsock;
    153         struct nbt_name_register *io;
    154         struct nbt_name_request *req;
     154        struct nbt_name_register io;
    155155};
    156156
    157 
    158 /*
    159   state handler for 4 stage name registration
    160 */
    161 static void name_register_bcast_handler(struct nbt_name_request *req)
    162 {
    163         struct composite_context *c = talloc_get_type(req->async.private_data, struct composite_context);
    164         struct register_bcast_state *state = talloc_get_type(c->private_data, struct register_bcast_state);
    165         NTSTATUS status;
    166 
    167         status = nbt_name_register_recv(state->req, state, state->io);
     157static void nbt_name_register_bcast_handler(struct nbt_name_request *subreq);
     158
     159/*
     160  the async send call for a 4 stage name registration
     161*/
     162_PUBLIC_ struct tevent_req *nbt_name_register_bcast_send(TALLOC_CTX *mem_ctx,
     163                                        struct tevent_context *ev,
     164                                        struct nbt_name_socket *nbtsock,
     165                                        struct nbt_name_register_bcast *io)
     166{
     167        struct tevent_req *req;
     168        struct nbt_name_register_bcast_state *state;
     169        struct nbt_name_request *subreq;
     170
     171        req = tevent_req_create(mem_ctx, &state,
     172                                struct nbt_name_register_bcast_state);
     173        if (req == NULL) {
     174                return NULL;
     175        }
     176
     177        state->io.in.name            = io->in.name;
     178        state->io.in.dest_addr       = io->in.dest_addr;
     179        state->io.in.dest_port       = io->in.dest_port;
     180        state->io.in.address         = io->in.address;
     181        state->io.in.nb_flags        = io->in.nb_flags;
     182        state->io.in.register_demand = false;
     183        state->io.in.broadcast       = true;
     184        state->io.in.multi_homed     = false;
     185        state->io.in.ttl             = io->in.ttl;
     186        state->io.in.timeout         = 1;
     187        state->io.in.retries         = 2;
     188
     189        state->nbtsock = nbtsock;
     190
     191        subreq = nbt_name_register_send(nbtsock, &state->io);
     192        if (tevent_req_nomem(subreq, req)) {
     193                return tevent_req_post(req, ev);
     194        }
     195
     196        subreq->async.fn = nbt_name_register_bcast_handler;
     197        subreq->async.private_data = req;
     198
     199        return req;
     200}
     201
     202static void nbt_name_register_bcast_handler(struct nbt_name_request *subreq)
     203{
     204        struct tevent_req *req =
     205                talloc_get_type_abort(subreq->async.private_data,
     206                struct tevent_req);
     207        struct nbt_name_register_bcast_state *state =
     208                tevent_req_data(req,
     209                struct nbt_name_register_bcast_state);
     210        NTSTATUS status;
     211
     212        status = nbt_name_register_recv(subreq, state, &state->io);
    168213        if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
    169                 if (state->io->in.register_demand == true) {
    170                         /* all done */
    171                         c->state = COMPOSITE_STATE_DONE;
    172                         c->status = NT_STATUS_OK;
    173                         goto done;
     214                if (state->io.in.register_demand == true) {
     215                        tevent_req_done(req);
     216                        return;
    174217                }
    175218
    176219                /* the registration timed out - good, send the demand */
    177                 state->io->in.register_demand = true;
    178                 state->io->in.retries         = 0;
    179                 state->req = nbt_name_register_send(state->nbtsock, state->io);
    180                 if (state->req == NULL) {
    181                         c->state = COMPOSITE_STATE_ERROR;
    182                         c->status = NT_STATUS_NO_MEMORY;
    183                 } else {
    184                         state->req->async.fn      = name_register_bcast_handler;
    185                         state->req->async.private_data = c;
     220                state->io.in.register_demand = true;
     221                state->io.in.retries         = 0;
     222
     223                subreq = nbt_name_register_send(state->nbtsock, &state->io);
     224                if (tevent_req_nomem(subreq, req)) {
     225                        return;
    186226                }
    187         } else if (!NT_STATUS_IS_OK(status)) {
    188                 c->state = COMPOSITE_STATE_ERROR;
    189                 c->status = status;
    190         } else {
    191                 c->state = COMPOSITE_STATE_ERROR;
    192                 c->status = NT_STATUS_CONFLICTING_ADDRESSES;
    193                 DEBUG(3,("Name registration conflict from %s for %s with ip %s - rcode %d\n",
    194                          state->io->out.reply_from,
    195                          nbt_name_string(state, &state->io->out.name),
    196                          state->io->out.reply_addr,
    197                          state->io->out.rcode));
    198         }
    199 
    200 done:
    201         if (c->state >= COMPOSITE_STATE_DONE &&
    202             c->async.fn) {
    203                 c->async.fn(c);
    204         }
    205 }
    206 
    207 /*
    208   the async send call for a 4 stage name registration
    209 */
    210 _PUBLIC_ struct composite_context *nbt_name_register_bcast_send(struct nbt_name_socket *nbtsock,
    211                                                        struct nbt_name_register_bcast *io)
    212 {
    213         struct composite_context *c;
    214         struct register_bcast_state *state;
    215 
    216         c = talloc_zero(nbtsock, struct composite_context);
    217         if (c == NULL) goto failed;
    218 
    219         state = talloc(c, struct register_bcast_state);
    220         if (state == NULL) goto failed;
    221 
    222         state->io = talloc(state, struct nbt_name_register);
    223         if (state->io == NULL) goto failed;
    224 
    225         state->io->in.name            = io->in.name;
    226         state->io->in.dest_addr       = io->in.dest_addr;
    227         state->io->in.dest_port       = io->in.dest_port;
    228         state->io->in.address         = io->in.address;
    229         state->io->in.nb_flags        = io->in.nb_flags;
    230         state->io->in.register_demand = false;
    231         state->io->in.broadcast       = true;
    232         state->io->in.multi_homed     = false;
    233         state->io->in.ttl             = io->in.ttl;
    234         state->io->in.timeout         = 1;
    235         state->io->in.retries         = 2;
    236 
    237         state->nbtsock = nbtsock;
    238 
    239         state->req = nbt_name_register_send(nbtsock, state->io);
    240         if (state->req == NULL) goto failed;
    241 
    242         state->req->async.fn      = name_register_bcast_handler;
    243         state->req->async.private_data = c;
    244 
    245         c->private_data = state;
    246         c->state        = COMPOSITE_STATE_IN_PROGRESS;
    247         c->event_ctx    = nbtsock->event_ctx;
    248 
    249         return c;
    250 
    251 failed:
    252         talloc_free(c);
    253         return NULL;
     227
     228                subreq->async.fn = nbt_name_register_bcast_handler;
     229                subreq->async.private_data = req;
     230                return;
     231        }
     232
     233        if (!NT_STATUS_IS_OK(status)) {
     234                tevent_req_nterror(req, status);
     235                return;
     236        }
     237
     238        DEBUG(3,("Name registration conflict from %s for %s with ip %s - rcode %d\n",
     239                 state->io.out.reply_from,
     240                 nbt_name_string(state, &state->io.out.name),
     241                 state->io.out.reply_addr,
     242                 state->io.out.rcode));
     243
     244        tevent_req_nterror(req, NT_STATUS_CONFLICTING_ADDRESSES);
    254245}
    255246
     
    257248  broadcast 4 part name register - recv
    258249*/
    259 _PUBLIC_ NTSTATUS nbt_name_register_bcast_recv(struct composite_context *c)
    260 {
    261         NTSTATUS status;
    262         status = composite_wait(c);
    263         talloc_free(c);
    264         return status;
     250_PUBLIC_ NTSTATUS nbt_name_register_bcast_recv(struct tevent_req *req)
     251{
     252        NTSTATUS status;
     253
     254        if (tevent_req_is_nterror(req, &status)) {
     255                tevent_req_received(req);
     256                return status;
     257        }
     258
     259        tevent_req_received(req);
     260        return NT_STATUS_OK;
    265261}
    266262
     
    271267                                 struct nbt_name_register_bcast *io)
    272268{
    273         struct composite_context *c = nbt_name_register_bcast_send(nbtsock, io);
    274         return nbt_name_register_bcast_recv(c);
     269        TALLOC_CTX *frame = talloc_stackframe();
     270        struct tevent_context *ev;
     271        struct tevent_req *subreq;
     272        NTSTATUS status;
     273
     274        /*
     275         * TODO: create a temporary event context
     276         */
     277        ev = nbtsock->event_ctx;
     278
     279        subreq = nbt_name_register_bcast_send(frame, ev, nbtsock, io);
     280        if (subreq == NULL) {
     281                talloc_free(frame);
     282                return NT_STATUS_NO_MEMORY;
     283        }
     284
     285        if (!tevent_req_poll(subreq, ev)) {
     286                status = map_nt_error_from_unix(errno);
     287                talloc_free(frame);
     288                return status;
     289        }
     290
     291        status = nbt_name_register_bcast_recv(subreq);
     292        if (!NT_STATUS_IS_OK(status)) {
     293                talloc_free(frame);
     294                return status;
     295        }
     296
     297        TALLOC_FREE(frame);
     298        return NT_STATUS_OK;
    275299}
    276300
     
    281305  reply for each address
    282306*/
    283 struct register_wins_state {
     307struct nbt_name_register_wins_state {
    284308        struct nbt_name_socket *nbtsock;
    285         struct nbt_name_register *io;
    286         const char **wins_servers;
     309        struct nbt_name_register io;
     310        char **wins_servers;
    287311        uint16_t wins_port;
    288         const char **addresses;
    289         int address_idx;
    290         struct nbt_name_request *req;
     312        char **addresses;
     313        uint32_t address_idx;
    291314};
    292315
     316static void nbt_name_register_wins_handler(struct nbt_name_request *subreq);
     317
     318/*
     319  the async send call for a multi-server WINS register
     320*/
     321_PUBLIC_ struct tevent_req *nbt_name_register_wins_send(TALLOC_CTX *mem_ctx,
     322                                                struct tevent_context *ev,
     323                                                struct nbt_name_socket *nbtsock,
     324                                                struct nbt_name_register_wins *io)
     325{
     326        struct tevent_req *req;
     327        struct nbt_name_register_wins_state *state;
     328        struct nbt_name_request *subreq;
     329
     330        req = tevent_req_create(mem_ctx, &state,
     331                                struct nbt_name_register_wins_state);
     332        if (req == NULL) {
     333                return NULL;
     334        }
     335
     336        if (io->in.wins_servers == NULL) {
     337                tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
     338                return tevent_req_post(req, ev);
     339        }
     340
     341        if (io->in.wins_servers[0] == NULL) {
     342                tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
     343                return tevent_req_post(req, ev);
     344        }
     345
     346        if (io->in.addresses == NULL) {
     347                tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
     348                return tevent_req_post(req, ev);
     349        }
     350
     351        if (io->in.addresses[0] == NULL) {
     352                tevent_req_nterror(req, NT_STATUS_INVALID_PARAMETER);
     353                return tevent_req_post(req, ev);
     354        }
     355
     356        state->wins_port = io->in.wins_port;
     357        state->wins_servers = str_list_copy(state, io->in.wins_servers);
     358        if (tevent_req_nomem(state->wins_servers, req)) {
     359                return tevent_req_post(req, ev);
     360        }
     361
     362        state->addresses = str_list_copy(state, io->in.addresses);
     363        if (tevent_req_nomem(state->addresses, req)) {
     364                return tevent_req_post(req, ev);
     365        }
     366
     367        state->io.in.name            = io->in.name;
     368        state->io.in.dest_addr       = state->wins_servers[0];
     369        state->io.in.dest_port       = state->wins_port;
     370        state->io.in.address         = io->in.addresses[0];
     371        state->io.in.nb_flags        = io->in.nb_flags;
     372        state->io.in.broadcast       = false;
     373        state->io.in.register_demand = false;
     374        state->io.in.multi_homed     = (io->in.nb_flags & NBT_NM_GROUP)?false:true;
     375        state->io.in.ttl             = io->in.ttl;
     376        state->io.in.timeout         = 3;
     377        state->io.in.retries         = 2;
     378
     379        state->nbtsock     = nbtsock;
     380        state->address_idx = 0;
     381
     382        subreq = nbt_name_register_send(nbtsock, &state->io);
     383        if (tevent_req_nomem(subreq, req)) {
     384                return tevent_req_post(req, ev);
     385        }
     386
     387        subreq->async.fn = nbt_name_register_wins_handler;
     388        subreq->async.private_data = req;
     389
     390        return req;
     391}
    293392
    294393/*
    295394  state handler for WINS multi-homed multi-server name register
    296395*/
    297 static void name_register_wins_handler(struct nbt_name_request *req)
    298 {
    299         struct composite_context *c = talloc_get_type(req->async.private_data,
    300                                                       struct composite_context);
    301         struct register_wins_state *state = talloc_get_type(c->private_data,
    302                                                             struct register_wins_state);
    303         NTSTATUS status;
    304 
    305         status = nbt_name_register_recv(state->req, state, state->io);
     396static void nbt_name_register_wins_handler(struct nbt_name_request *subreq)
     397{
     398        struct tevent_req *req =
     399                talloc_get_type_abort(subreq->async.private_data,
     400                struct tevent_req);
     401        struct nbt_name_register_wins_state *state =
     402                tevent_req_data(req,
     403                struct nbt_name_register_wins_state);
     404        NTSTATUS status;
     405
     406        status = nbt_name_register_recv(subreq, state, &state->io);
    306407        if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
    307408                /* the register timed out - try the next WINS server */
    308409                state->wins_servers++;
     410                if (state->wins_servers[0] == NULL) {
     411                        tevent_req_nterror(req, status);
     412                        return;
     413                }
     414
    309415                state->address_idx = 0;
    310                 if (state->wins_servers[0] == NULL) {
    311                         c->state = COMPOSITE_STATE_ERROR;
    312                         c->status = status;
    313                         goto done;
     416                state->io.in.dest_addr = state->wins_servers[0];
     417                state->io.in.dest_port = state->wins_port;
     418                state->io.in.address   = state->addresses[0];
     419
     420                subreq = nbt_name_register_send(state->nbtsock, &state->io);
     421                if (tevent_req_nomem(subreq, req)) {
     422                        return;
    314423                }
    315                 state->io->in.dest_addr = state->wins_servers[0];
    316                 state->io->in.dest_port = state->wins_port;
    317                 state->io->in.address   = state->addresses[0];
    318                 state->req = nbt_name_register_send(state->nbtsock, state->io);
    319                 if (state->req == NULL) {
    320                         c->state = COMPOSITE_STATE_ERROR;
    321                         c->status = NT_STATUS_NO_MEMORY;
    322                 } else {
    323                         state->req->async.fn      = name_register_wins_handler;
    324                         state->req->async.private_data = c;
     424
     425                subreq->async.fn = nbt_name_register_wins_handler;
     426                subreq->async.private_data = req;
     427                return;
     428        }
     429
     430        if (!NT_STATUS_IS_OK(status)) {
     431                tevent_req_nterror(req, status);
     432                return;
     433        }
     434
     435        if (state->io.out.rcode == 0 &&
     436            state->addresses[state->address_idx+1] != NULL) {
     437                /* register our next address */
     438                state->io.in.address = state->addresses[++(state->address_idx)];
     439
     440                subreq = nbt_name_register_send(state->nbtsock, &state->io);
     441                if (tevent_req_nomem(subreq, req)) {
     442                        return;
    325443                }
    326         } else if (!NT_STATUS_IS_OK(status)) {
    327                 c->state = COMPOSITE_STATE_ERROR;
    328                 c->status = status;
    329         } else {
    330                 if (state->io->out.rcode == 0 &&
    331                     state->addresses[state->address_idx+1] != NULL) {
    332                         /* register our next address */
    333                         state->io->in.address = state->addresses[++(state->address_idx)];
    334                         state->req = nbt_name_register_send(state->nbtsock, state->io);
    335                         if (state->req == NULL) {
    336                                 c->state = COMPOSITE_STATE_ERROR;
    337                                 c->status = NT_STATUS_NO_MEMORY;
    338                         } else {
    339                                 state->req->async.fn      = name_register_wins_handler;
    340                                 state->req->async.private_data = c;
    341                         }
    342                 } else {
    343                         c->state = COMPOSITE_STATE_DONE;
    344                         c->status = NT_STATUS_OK;
    345                 }
    346         }
    347 
    348 done:
    349         if (c->state >= COMPOSITE_STATE_DONE &&
    350             c->async.fn) {
    351                 c->async.fn(c);
    352         }
    353 }
    354 
    355 /*
    356   the async send call for a multi-server WINS register
    357 */
    358 _PUBLIC_ struct composite_context *nbt_name_register_wins_send(struct nbt_name_socket *nbtsock,
    359                                                       struct nbt_name_register_wins *io)
    360 {
    361         struct composite_context *c;
    362         struct register_wins_state *state;
    363 
    364         c = talloc_zero(nbtsock, struct composite_context);
    365         if (c == NULL) goto failed;
    366 
    367         state = talloc(c, struct register_wins_state);
    368         if (state == NULL) goto failed;
    369 
    370         state->io = talloc(state, struct nbt_name_register);
    371         if (state->io == NULL) goto failed;
    372 
    373         state->wins_port = io->in.wins_port;
    374         state->wins_servers = (const char **)str_list_copy(state, io->in.wins_servers);
    375         if (state->wins_servers == NULL ||
    376             state->wins_servers[0] == NULL) goto failed;
    377 
    378         state->addresses = (const char **)str_list_copy(state, io->in.addresses);
    379         if (state->addresses == NULL ||
    380             state->addresses[0] == NULL) goto failed;
    381 
    382         state->io->in.name            = io->in.name;
    383         state->io->in.dest_addr       = state->wins_servers[0];
    384         state->io->in.dest_port       = state->wins_port;
    385         state->io->in.address         = io->in.addresses[0];
    386         state->io->in.nb_flags        = io->in.nb_flags;
    387         state->io->in.broadcast       = false;
    388         state->io->in.register_demand = false;
    389         state->io->in.multi_homed     = (io->in.nb_flags & NBT_NM_GROUP)?false:true;
    390         state->io->in.ttl             = io->in.ttl;
    391         state->io->in.timeout         = 3;
    392         state->io->in.retries         = 2;
    393 
    394         state->nbtsock     = nbtsock;
    395         state->address_idx = 0;
    396 
    397         state->req = nbt_name_register_send(nbtsock, state->io);
    398         if (state->req == NULL) goto failed;
    399 
    400         state->req->async.fn      = name_register_wins_handler;
    401         state->req->async.private_data = c;
    402 
    403         c->private_data = state;
    404         c->state        = COMPOSITE_STATE_IN_PROGRESS;
    405         c->event_ctx    = nbtsock->event_ctx;
    406 
    407         return c;
    408 
    409 failed:
    410         talloc_free(c);
    411         return NULL;
     444
     445                subreq->async.fn = nbt_name_register_wins_handler;
     446                subreq->async.private_data = req;
     447                return;
     448        }
     449
     450        tevent_req_done(req);
    412451}
    413452
     
    415454  multi-homed WINS name register - recv side
    416455*/
    417 _PUBLIC_ NTSTATUS nbt_name_register_wins_recv(struct composite_context *c, TALLOC_CTX *mem_ctx,
    418                                      struct nbt_name_register_wins *io)
    419 {
    420         NTSTATUS status;
    421         status = composite_wait(c);
    422         if (NT_STATUS_IS_OK(status)) {
    423                 struct register_wins_state *state =
    424                         talloc_get_type(c->private_data, struct register_wins_state);
    425                 io->out.wins_server = talloc_steal(mem_ctx, state->wins_servers[0]);
    426                 io->out.rcode = state->io->out.rcode;
    427         }
    428         talloc_free(c);
    429         return status;
     456_PUBLIC_ NTSTATUS nbt_name_register_wins_recv(struct tevent_req *req,
     457                                              TALLOC_CTX *mem_ctx,
     458                                              struct nbt_name_register_wins *io)
     459{
     460        struct nbt_name_register_wins_state *state =
     461                tevent_req_data(req,
     462                struct nbt_name_register_wins_state);
     463        NTSTATUS status;
     464
     465        if (tevent_req_is_nterror(req, &status)) {
     466                tevent_req_received(req);
     467                return status;
     468        }
     469
     470        io->out.wins_server = talloc_move(mem_ctx, &state->wins_servers[0]);
     471        io->out.rcode = state->io.out.rcode;
     472
     473        tevent_req_received(req);
     474        return NT_STATUS_OK;
    430475}
    431476
     
    437482                                struct nbt_name_register_wins *io)
    438483{
    439         struct composite_context *c = nbt_name_register_wins_send(nbtsock, io);
    440         return nbt_name_register_wins_recv(c, mem_ctx, io);
    441 }
     484        TALLOC_CTX *frame = talloc_stackframe();
     485        struct tevent_context *ev;
     486        struct tevent_req *subreq;
     487        NTSTATUS status;
     488
     489        /*
     490         * TODO: create a temporary event context
     491         */
     492        ev = nbtsock->event_ctx;
     493
     494        subreq = nbt_name_register_wins_send(frame, ev, nbtsock, io);
     495        if (subreq == NULL) {
     496                talloc_free(frame);
     497                return NT_STATUS_NO_MEMORY;
     498        }
     499
     500        if (!tevent_req_poll(subreq, ev)) {
     501                status = map_nt_error_from_unix(errno);
     502                talloc_free(frame);
     503                return status;
     504        }
     505
     506        status = nbt_name_register_wins_recv(subreq, mem_ctx, io);
     507        if (!NT_STATUS_IS_OK(status)) {
     508                talloc_free(frame);
     509                return status;
     510        }
     511
     512        TALLOC_FREE(frame);
     513        return NT_STATUS_OK;
     514}
  • trunk/server/libcli/nbt/nbt_proto.h

    r414 r745  
     1/*
     2   Unix SMB/CIFS implementation.
     3
     4   manipulate nbt name structures
     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
    122#ifndef _____LIBCLI_NBT_NBT_PROTO_H__
    223#define _____LIBCLI_NBT_NBT_PROTO_H__
  • trunk/server/libcli/nbt/nbtname.c

    r596 r745  
    2828#include "librpc/gen_ndr/ndr_misc.h"
    2929#include "system/locale.h"
     30#include "lib/util/util_net.h"
    3031
    3132/* don't allow an unlimited number of name components */
     
    4950{
    5051        uint8_t len;
    51         uint_t loops = 0;
     52        unsigned int loops = 0;
    5253        while (loops < 5) {
    5354                if (*offset >= ndr->data_size) {
     
    176177
    177178                /* we need to make sure the length fits into 6 bytes */
    178                 if (complen >= 0x3F) {
     179                if (complen > 0x3F) {
    179180                        return ndr_push_error(ndr, NDR_ERR_STRING,
    180                                               "component length %u[%08X] > 0x00003F",
     181                                              "component length %u[%08X] > 0x0000003F",
    181182                                              (unsigned)complen, (unsigned)complen);
    182183                }
     
    383384  push a nbt name into a blob
    384385*/
    385 _PUBLIC_ NTSTATUS nbt_name_to_blob(TALLOC_CTX *mem_ctx, struct smb_iconv_convenience *iconv_convenience, DATA_BLOB *blob, struct nbt_name *name)
     386_PUBLIC_ NTSTATUS nbt_name_to_blob(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, struct nbt_name *name)
    386387{
    387388        enum ndr_err_code ndr_err;
    388389
    389         ndr_err = ndr_push_struct_blob(blob, mem_ctx, iconv_convenience, name, (ndr_push_flags_fn_t)ndr_push_nbt_name);
     390        ndr_err = ndr_push_struct_blob(blob, mem_ctx, name, (ndr_push_flags_fn_t)ndr_push_nbt_name);
    390391        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
    391392                return ndr_map_error2ntstatus(ndr_err);
     
    402403        enum ndr_err_code ndr_err;
    403404
    404         ndr_err = ndr_pull_struct_blob(blob, mem_ctx, NULL, name,
     405        ndr_err = ndr_pull_struct_blob(blob, mem_ctx, name,
    405406                                       (ndr_pull_flags_fn_t)ndr_pull_nbt_name);
    406407        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     
    520521        NDR_CHECK(ndr_pull_array_uint8(ndr, NDR_SCALARS, namebuf, namebuf_len));
    521522
     523        if ((namebuf_len % 4) == 0) {
     524                /*
     525                 * [MS-WINSRA] — v20091104 was wrong
     526                 * regarding section "2.2.10.1 Name Record"
     527                 *
     528                 * If the name buffer is already 4 byte aligned
     529                 * Windows (at least 2003 SP1 and 2008) add 4 extra
     530                 * bytes. This can happen when the name has a scope.
     531                 */
     532                uint32_t pad;
     533                NDR_CHECK(ndr_pull_uint32(ndr, NDR_SCALARS, &pad));
     534        }
     535
    522536        NDR_PULL_ALLOC(ndr, r);
    523537
     
    548562        if (!r->name) return ndr_pull_error(ndr, NDR_ERR_ALLOC, "out of memory");
    549563
    550         if (namebuf_len > 18) {
    551                 r->scope = talloc_strndup(r, (char *)(namebuf+17), namebuf_len-17);
     564        if (namebuf_len > 17) {
     565                r->scope = talloc_strndup(r, (char *)(namebuf+16), namebuf_len-17);
    552566                if (!r->scope) return ndr_pull_error(ndr, NDR_ERR_ALLOC, "out of memory");
    553567        } else {
     
    617631        NDR_CHECK(ndr_push_uint32(ndr, NDR_SCALARS, namebuf_len));
    618632        NDR_CHECK(ndr_push_array_uint8(ndr, NDR_SCALARS, namebuf, namebuf_len));
     633
     634        if ((namebuf_len % 4) == 0) {
     635                /*
     636                 * [MS-WINSRA] — v20091104 was wrong
     637                 * regarding section "2.2.10.1 Name Record"
     638                 *
     639                 * If the name buffer is already 4 byte aligned
     640                 * Windows (at least 2003 SP1 and 2008) add 4 extra
     641                 * bytes. This can happen when the name has a scope.
     642                 */
     643                NDR_CHECK(ndr_push_zero(ndr, 4));
     644        }
    619645
    620646        talloc_free(namebuf);
  • trunk/server/libcli/nbt/nbtsocket.c

    r414 r745  
    192192
    193193        /* parse the request */
    194         ndr_err = ndr_pull_struct_blob(&blob, packet, nbtsock->iconv_convenience, packet,
     194        ndr_err = ndr_pull_struct_blob(&blob, packet, packet,
    195195                                       (ndr_pull_flags_fn_t)ndr_pull_nbt_name_packet);
    196196        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     
    333333*/
    334334_PUBLIC_ struct nbt_name_socket *nbt_name_socket_init(TALLOC_CTX *mem_ctx,
    335                                              struct tevent_context *event_ctx,
    336                                              struct smb_iconv_convenience *iconv_convenience)
     335                                             struct tevent_context *event_ctx)
    337336{
    338337        struct nbt_name_socket *nbtsock;
     
    342341        if (nbtsock == NULL) goto failed;
    343342
    344         nbtsock->event_ctx = talloc_reference(nbtsock, event_ctx);
     343        nbtsock->event_ctx = event_ctx;
    345344        if (nbtsock->event_ctx == NULL) goto failed;
    346345
     
    359358        nbtsock->incoming.handler = NULL;
    360359        nbtsock->unexpected.handler = NULL;
    361         nbtsock->iconv_convenience = iconv_convenience;
    362360
    363361        nbtsock->fde = event_add_fd(nbtsock->event_ctx, nbtsock,
     
    417415
    418416        ndr_err = ndr_push_struct_blob(&req->encoded, req,
    419                                        req->nbtsock->iconv_convenience,
    420417                                       request,
    421418                                       (ndr_push_flags_fn_t)ndr_push_nbt_name_packet);
     
    466463
    467464        ndr_err = ndr_push_struct_blob(&req->encoded, req,
    468                                        req->nbtsock->iconv_convenience,
    469465                                       request,
    470466                                       (ndr_push_flags_fn_t)ndr_push_nbt_name_packet);
  • trunk/server/libcli/nbt/pynbt.c

    r414 r745  
    1818*/
    1919
     20#include <Python.h>
    2021#include "includes.h"
    21 #include <Python.h>
    2222#include "libcli/util/pyerrors.h"
    2323#include "scripting/python/modules.h"
     
    2525#include "lib/events/events.h"
    2626
     27void initnetbios(void);
     28
    2729#ifndef Py_RETURN_NONE
    2830#define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None
    2931#endif
    3032
    31 PyAPI_DATA(PyTypeObject) nbt_node_Type;
     33extern PyTypeObject nbt_node_Type;
    3234
    3335typedef struct {
     
    3739} nbt_node_Object;
    3840
    39 static void py_nbt_node_dealloc(PyObject *obj)
    40 {
    41         talloc_free(((nbt_node_Object *)obj)->mem_ctx);
    42         PyObject_Del(obj);
     41static void py_nbt_node_dealloc(nbt_node_Object *self)
     42{
     43        talloc_free(self->mem_ctx);
     44        self->ob_type->tp_free(self);
    4345}
    4446
     
    5355
    5456        ev = s4_event_context_init(ret->mem_ctx);
    55         ret->socket = nbt_name_socket_init(ret->mem_ctx, ev, py_iconv_convenience(ret->mem_ctx));
     57        ret->socket = nbt_name_socket_init(ret->mem_ctx, ev);
    5658        return (PyObject *)ret;
    5759}
     
    125127}
    126128
    127 static PyObject *PyObject_FromNBTName(struct nbt_name_socket *name_socket, struct smb_iconv_convenience *ic,
     129static PyObject *PyObject_FromNBTName(struct nbt_name_socket *name_socket,
    128130                                      struct nbt_name *name)
    129131{
     
    176178        PyTuple_SetItem(ret, 0, PyString_FromString(io.out.reply_from));
    177179
    178         py_name = PyObject_FromNBTName(node->socket, py_iconv_convenience(node->socket), &io.out.name);
     180        py_name = PyObject_FromNBTName(node->socket, &io.out.name);
    179181        if (py_name == NULL)
    180182                return NULL;
     
    234236        PyTuple_SetItem(ret, 0, PyString_FromString(io.out.reply_from));
    235237
    236         py_name = PyObject_FromNBTName(node->socket, py_iconv_convenience(NULL), &io.out.name);
     238        py_name = PyObject_FromNBTName(node->socket, &io.out.name);
    237239        if (py_name == NULL)
    238240                return NULL;
     
    297299        PyTuple_SetItem(ret, 0, PyString_FromString(io.out.reply_from));
    298300
    299         py_name = PyObject_FromNBTName(node->socket, py_iconv_convenience(NULL), &io.out.name);
     301        py_name = PyObject_FromNBTName(node->socket, &io.out.name);
    300302        if (py_name == NULL)
    301303                return NULL;
     
    352354        PyTuple_SetItem(ret, 0, PyString_FromString(io.out.reply_from));
    353355
    354         py_name = PyObject_FromNBTName(node->socket, py_iconv_convenience(NULL), &io.out.name);
     356        py_name = PyObject_FromNBTName(node->socket, &io.out.name);
    355357        if (py_name == NULL)
    356358                return NULL;
     
    394396        .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,
    395397        .tp_new = py_nbt_node_init,
    396         .tp_dealloc = py_nbt_node_dealloc,
     398        .tp_dealloc = (destructor)py_nbt_node_dealloc,
    397399        .tp_methods = py_nbt_methods,
    398400        .tp_doc = "Node()\n"
  • trunk/server/libcli/nbt/tools/nmblookup.c

    r414 r745  
    213213        }
    214214
    215         nbtsock = nbt_name_socket_init(tmp_ctx, ev, lp_iconv_convenience(lp_ctx));
     215        nbtsock = nbt_name_socket_init(tmp_ctx, ev);
    216216       
    217217        if (options.root_port) {
     
    358358        }
    359359
    360         load_interfaces(NULL, lp_interfaces(cmdline_lp_ctx), &ifaces);
     360        load_interfaces(NULL, lpcfg_interfaces(cmdline_lp_ctx), &ifaces);
    361361
    362362        ev = s4_event_context_init(talloc_autofree_context());
     
    365365                const char *name = poptGetArg(pc);
    366366
    367                 ret &= process_one(cmdline_lp_ctx, ev, ifaces, name, lp_nbt_port(cmdline_lp_ctx));
     367                ret &= process_one(cmdline_lp_ctx, ev, ifaces, name, lpcfg_nbt_port(cmdline_lp_ctx));
    368368        }
    369369
Note: See TracChangeset for help on using the changeset viewer.