Ignore:
Timestamp:
Nov 14, 2012, 12:59:34 PM (12 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to 3.6.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TabularUnified vendor/current/source4/nbt_server/wins/winsclient.c

    r414 r740  
    2929#include "param/param.h"
    3030
    31 static void nbtd_wins_refresh_handler(struct composite_context *c);
    32 
    3331/* we send WINS client requests using our primary network interface
    3432*/
     
    5957{
    6058        uint32_t refresh_time;
    61         uint32_t max_refresh_time = lp_parm_int(iname->iface->nbtsrv->task->lp_ctx, NULL, "nbtd", "max_refresh_time", 7200);
     59        uint32_t max_refresh_time = lpcfg_parm_int(iname->iface->nbtsrv->task->lp_ctx, NULL, "nbtd", "max_refresh_time", 7200);
    6260
    6361        refresh_time = MIN(max_refresh_time, iname->ttl/2);
     
    6967}
    7068
     69struct nbtd_wins_refresh_state {
     70        struct nbtd_iface_name *iname;
     71        struct nbt_name_refresh_wins io;
     72};
     73
    7174/*
    7275  called when a wins name refresh has completed
    7376*/
    74 static void nbtd_wins_refresh_handler(struct composite_context *c)
     77static void nbtd_wins_refresh_handler(struct tevent_req *subreq)
    7578{
    7679        NTSTATUS status;
    77         struct nbt_name_refresh_wins io;
    78         struct nbtd_iface_name *iname = talloc_get_type(c->async.private_data,
    79                                                         struct nbtd_iface_name);
    80         TALLOC_CTX *tmp_ctx = talloc_new(iname);
    81 
    82         status = nbt_name_refresh_wins_recv(c, tmp_ctx, &io);
     80        struct nbtd_wins_refresh_state *state =
     81                tevent_req_callback_data(subreq,
     82                struct nbtd_wins_refresh_state);
     83        struct nbtd_iface_name *iname = state->iname;
     84
     85        status = nbt_name_refresh_wins_recv(subreq, state, &state->io);
     86        TALLOC_FREE(subreq);
    8387        if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
    8488                /* our WINS server is dead - start registration over
    8589                   from scratch */
    8690                DEBUG(2,("Failed to refresh %s with WINS server %s\n",
    87                          nbt_name_string(tmp_ctx, &iname->name), iname->wins_server));
    88                 talloc_free(tmp_ctx);
     91                         nbt_name_string(state, &iname->name), iname->wins_server));
     92                talloc_free(state);
    8993                nbtd_winsclient_register(iname);
    9094                return;
     
    9397        if (!NT_STATUS_IS_OK(status)) {
    9498                DEBUG(1,("Name refresh failure with WINS for %s - %s\n",
    95                          nbt_name_string(tmp_ctx, &iname->name), nt_errstr(status)));
    96                 talloc_free(tmp_ctx);
    97                 return;
    98         }
    99 
    100         if (io.out.rcode != 0) {
     99                         nbt_name_string(state, &iname->name), nt_errstr(status)));
     100                talloc_free(state);
     101                return;
     102        }
     103
     104        if (state->io.out.rcode != 0) {
    101105                DEBUG(1,("WINS server %s rejected name refresh of %s - %s\n",
    102                          io.out.wins_server, nbt_name_string(tmp_ctx, &iname->name),
    103                          nt_errstr(nbt_rcode_to_ntstatus(io.out.rcode))));
     106                         state->io.out.wins_server,
     107                         nbt_name_string(state, &iname->name),
     108                         nt_errstr(nbt_rcode_to_ntstatus(state->io.out.rcode))));
    104109                iname->nb_flags |= NBT_NM_CONFLICT;
    105                 talloc_free(tmp_ctx);
     110                talloc_free(state);
    106111                return;
    107112        }       
    108113
    109114        DEBUG(4,("Refreshed name %s with WINS server %s\n",
    110                  nbt_name_string(tmp_ctx, &iname->name), iname->wins_server));
     115                 nbt_name_string(state, &iname->name), iname->wins_server));
    111116        /* success - start a periodic name refresh */
    112117        iname->nb_flags |= NBT_NM_ACTIVE;
     
    116121                 * so steal it into the tmp context
    117122                 */
    118                 talloc_steal(tmp_ctx, iname->wins_server);
    119         }
    120         iname->wins_server = talloc_steal(iname, io.out.wins_server);
    121 
     123                talloc_steal(state, iname->wins_server);
     124        }
     125        iname->wins_server = talloc_move(iname, &state->io.out.wins_server);
    122126        iname->registration_time = timeval_current();
     127
     128        talloc_free(state);
     129
    123130        nbtd_wins_start_refresh_timer(iname);
    124 
    125         talloc_free(tmp_ctx);
    126131}
    127132
     
    135140        struct nbtd_iface_name *iname = talloc_get_type(private_data, struct nbtd_iface_name);
    136141        struct nbtd_interface *iface = iname->iface;
    137         struct nbt_name_refresh_wins io;
    138         struct composite_context *c;
    139         TALLOC_CTX *tmp_ctx = talloc_new(iname);
     142        struct nbt_name_socket *nbtsock = wins_socket(iface);
     143        struct tevent_req *subreq;
     144        struct nbtd_wins_refresh_state *state;
     145
     146        state = talloc_zero(iname, struct nbtd_wins_refresh_state);
     147        if (state == NULL) {
     148                return;
     149        }
     150
     151        state->iname = iname;
    140152
    141153        /* setup a wins name refresh request */
    142         io.in.name            = iname->name;
    143         io.in.wins_servers    = (const char **)str_list_make_single(tmp_ctx, iname->wins_server);
    144         io.in.wins_port       = lp_nbt_port(iface->nbtsrv->task->lp_ctx);
    145         io.in.addresses       = nbtd_address_list(iface, tmp_ctx);
    146         io.in.nb_flags        = iname->nb_flags;
    147         io.in.ttl             = iname->ttl;
    148 
    149         if (!io.in.addresses) {
    150                 talloc_free(tmp_ctx);
    151                 return;
    152         }
    153 
    154         c = nbt_name_refresh_wins_send(wins_socket(iface), &io);
    155         if (c == NULL) {
    156                 talloc_free(tmp_ctx);
    157                 return;
    158         }
    159         talloc_steal(c, io.in.addresses);
    160 
    161         c->async.fn = nbtd_wins_refresh_handler;
    162         c->async.private_data = iname;
    163 
    164         talloc_free(tmp_ctx);
    165 }
    166 
     154        state->io.in.name            = iname->name;
     155        state->io.in.wins_servers    = (const char **)str_list_make_single(state, iname->wins_server);
     156        state->io.in.wins_port       = lpcfg_nbt_port(iface->nbtsrv->task->lp_ctx);
     157        state->io.in.addresses       = nbtd_address_list(iface, state);
     158        state->io.in.nb_flags        = iname->nb_flags;
     159        state->io.in.ttl             = iname->ttl;
     160
     161        if (!state->io.in.addresses) {
     162                talloc_free(state);
     163                return;
     164        }
     165
     166        subreq = nbt_name_refresh_wins_send(state, ev, nbtsock, &state->io);
     167        if (subreq == NULL) {
     168                talloc_free(state);
     169                return;
     170        }
     171
     172        tevent_req_set_callback(subreq, nbtd_wins_refresh_handler, state);
     173}
     174
     175struct nbtd_wins_register_state {
     176        struct nbtd_iface_name *iname;
     177        struct nbt_name_register_wins io;
     178};
    167179
    168180/*
    169181  called when a wins name register has completed
    170182*/
    171 static void nbtd_wins_register_handler(struct composite_context *c)
     183static void nbtd_wins_register_handler(struct tevent_req *subreq)
    172184{
    173185        NTSTATUS status;
    174         struct nbt_name_register_wins io;
    175         struct nbtd_iface_name *iname = talloc_get_type(c->async.private_data,
    176                                                         struct nbtd_iface_name);
    177         TALLOC_CTX *tmp_ctx = talloc_new(iname);
    178 
    179         status = nbt_name_register_wins_recv(c, tmp_ctx, &io);
     186        struct nbtd_wins_register_state *state =
     187                tevent_req_callback_data(subreq,
     188                struct nbtd_wins_register_state);
     189        struct nbtd_iface_name *iname = state->iname;
     190
     191        status = nbt_name_register_wins_recv(subreq, state, &state->io);
     192        TALLOC_FREE(subreq);
    180193        if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) {
    181194                /* none of the WINS servers responded - try again
    182195                   periodically */
    183                 int wins_retry_time = lp_parm_int(iname->iface->nbtsrv->task->lp_ctx, NULL, "nbtd", "wins_retry", 300);
     196                int wins_retry_time = lpcfg_parm_int(iname->iface->nbtsrv->task->lp_ctx, NULL, "nbtd", "wins_retry", 300);
    184197                event_add_timed(iname->iface->nbtsrv->task->event_ctx,
    185198                                iname,
     
    187200                                nbtd_wins_register_retry,
    188201                                iname);
    189                 talloc_free(tmp_ctx);
     202                talloc_free(state);
    190203                return;
    191204        }
     
    193206        if (!NT_STATUS_IS_OK(status)) {
    194207                DEBUG(1,("Name register failure with WINS for %s - %s\n",
    195                          nbt_name_string(tmp_ctx, &iname->name), nt_errstr(status)));
    196                 talloc_free(tmp_ctx);
     208                         nbt_name_string(state, &iname->name), nt_errstr(status)));
     209                talloc_free(state);
    197210                return;
    198211        }       
    199212
    200         if (io.out.rcode != 0) {
     213        if (state->io.out.rcode != 0) {
    201214                DEBUG(1,("WINS server %s rejected name register of %s - %s\n",
    202                          io.out.wins_server, nbt_name_string(tmp_ctx, &iname->name),
    203                          nt_errstr(nbt_rcode_to_ntstatus(io.out.rcode))));
     215                         state->io.out.wins_server,
     216                         nbt_name_string(state, &iname->name),
     217                         nt_errstr(nbt_rcode_to_ntstatus(state->io.out.rcode))));
    204218                iname->nb_flags |= NBT_NM_CONFLICT;
    205                 talloc_free(tmp_ctx);
     219                talloc_free(state);
    206220                return;
    207221        }       
     
    214228                 * so steal it into the tmp context
    215229                 */
    216                 talloc_steal(tmp_ctx, iname->wins_server);
    217         }
    218         iname->wins_server = talloc_steal(iname, io.out.wins_server);
     230                talloc_steal(state, iname->wins_server);
     231        }
     232        iname->wins_server = talloc_move(iname, &state->io.out.wins_server);
    219233
    220234        iname->registration_time = timeval_current();
     235
     236        DEBUG(3,("Registered %s with WINS server %s\n",
     237                 nbt_name_string(state, &iname->name), iname->wins_server));
     238
     239        talloc_free(state);
     240
    221241        nbtd_wins_start_refresh_timer(iname);
    222 
    223         DEBUG(3,("Registered %s with WINS server %s\n",
    224                  nbt_name_string(tmp_ctx, &iname->name), iname->wins_server));
    225 
    226         talloc_free(tmp_ctx);
    227242}
    228243
     
    233248{
    234249        struct nbtd_interface *iface = iname->iface;
    235         struct nbt_name_register_wins io;
    236         struct composite_context *c;
     250        struct nbt_name_socket *nbtsock = wins_socket(iface);
     251        struct nbtd_wins_register_state *state;
     252        struct tevent_req *subreq;
     253
     254        state = talloc_zero(iname, struct nbtd_wins_register_state);
     255        if (state == NULL) {
     256                return;
     257        }
     258
     259        state->iname = iname;
    237260
    238261        /* setup a wins name register request */
    239         io.in.name            = iname->name;
    240         io.in.wins_port       = lp_nbt_port(iname->iface->nbtsrv->task->lp_ctx);
    241         io.in.wins_servers    = lp_wins_server_list(iname->iface->nbtsrv->task->lp_ctx);
    242         io.in.addresses       = nbtd_address_list(iface, iname);
    243         io.in.nb_flags        = iname->nb_flags;
    244         io.in.ttl             = iname->ttl;
    245 
    246         if (!io.in.addresses) {
    247                 return;
    248         }
    249 
    250         c = nbt_name_register_wins_send(wins_socket(iface), &io);
    251         if (c == NULL) {
    252                 talloc_free(io.in.addresses);
    253                 return;
    254         }
    255         talloc_steal(c, io.in.addresses);
    256 
    257         c->async.fn = nbtd_wins_register_handler;
    258         c->async.private_data = iname;
    259 }
     262        state->io.in.name         = iname->name;
     263        state->io.in.wins_port    = lpcfg_nbt_port(iface->nbtsrv->task->lp_ctx);
     264        state->io.in.wins_servers = lpcfg_wins_server_list(iface->nbtsrv->task->lp_ctx);
     265        state->io.in.addresses    = nbtd_address_list(iface, state);
     266        state->io.in.nb_flags     = iname->nb_flags;
     267        state->io.in.ttl          = iname->ttl;
     268
     269        if (state->io.in.addresses == NULL) {
     270                talloc_free(state);
     271                return;
     272        }
     273
     274        subreq = nbt_name_register_wins_send(state, iface->nbtsrv->task->event_ctx,
     275                                             nbtsock, &state->io);
     276        if (subreq == NULL) {
     277                talloc_free(state);
     278                return;
     279        }
     280
     281        tevent_req_set_callback(subreq, nbtd_wins_register_handler, state);
     282}
Note: See TracChangeset for help on using the changeset viewer.