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

Samba Server: update vendor to 3.6.0

Location:
vendor/current/source4/wrepl_server
Files:
1 added
1 deleted
7 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source4/wrepl_server/wrepl_apply_records.c

    r414 r740  
    2121
    2222#include "includes.h"
     23#include <tevent.h>
    2324#include "smbd/service_task.h"
    2425#include "lib/messaging/irpc.h"
    25 #include "librpc/gen_ndr/ndr_irpc.h"
     26#include "librpc/gen_ndr/ndr_irpc_c.h"
    2627#include "librpc/gen_ndr/ndr_winsrepl.h"
    2728#include "wrepl_server/wrepl_server.h"
     
    883884
    884885struct r_do_challenge_state {
    885         struct messaging_context *msg_ctx;
     886        struct dcerpc_binding_handle *irpc_handle;
    886887        struct wreplsrv_partner *partner;
    887888        struct winsdb_record *rec;
     
    889890        struct wrepl_name replica;
    890891        struct nbtd_proxy_wins_challenge r;
     892        struct nbtd_proxy_wins_release_demand dr;
    891893};
    892894
    893 static void r_do_late_release_demand_handler(struct irpc_request *ireq)
     895static void r_do_late_release_demand_handler(struct tevent_req *subreq)
    894896{
    895897        NTSTATUS status;
    896         struct r_do_challenge_state *state = talloc_get_type(ireq->async.private_data,
    897                                                              struct r_do_challenge_state);
    898 
    899         status = irpc_call_recv(ireq);
     898        struct r_do_challenge_state *state =
     899                tevent_req_callback_data(subreq,
     900                struct r_do_challenge_state);
     901
     902        status = dcerpc_nbtd_proxy_wins_release_demand_r_recv(subreq, state);
     903        TALLOC_FREE(subreq);
     904
    900905        /* don't care about the result */
    901906        talloc_free(state);
     
    904909static NTSTATUS r_do_late_release_demand(struct r_do_challenge_state *state)
    905910{
    906         struct irpc_request *ireq;
    907         struct server_id *nbt_servers;
    908         struct nbtd_proxy_wins_release_demand r;
     911        struct tevent_req *subreq;
    909912        uint32_t i;
    910913
     
    912915                 nbt_name_string(state, &state->replica.name)));
    913916
    914         nbt_servers = irpc_servers_byname(state->msg_ctx, state, "nbt_server");
    915         if ((nbt_servers == NULL) || (nbt_servers[0].id == 0)) {
    916                 return NT_STATUS_INTERNAL_ERROR;
    917         }
    918 
    919         r.in.name       = state->replica.name;
    920         r.in.num_addrs  = state->r.out.num_addrs;
    921         r.in.addrs      = talloc_array(state, struct nbtd_proxy_wins_addr, r.in.num_addrs);
    922         NT_STATUS_HAVE_NO_MEMORY(r.in.addrs);
     917        state->dr.in.name       = state->replica.name;
     918        state->dr.in.num_addrs  = state->r.out.num_addrs;
     919        state->dr.in.addrs      = talloc_array(state,
     920                                               struct nbtd_proxy_wins_addr,
     921                                               state->dr.in.num_addrs);
     922        NT_STATUS_HAVE_NO_MEMORY(state->dr.in.addrs);
    923923        /* TODO: fix pidl to handle inline ipv4address arrays */
    924         for (i=0; i < r.in.num_addrs; i++) {
    925                 r.in.addrs[i].addr = state->r.out.addrs[i].addr;
    926         }
    927 
    928         ireq = IRPC_CALL_SEND(state->msg_ctx, nbt_servers[0],
    929                               irpc, NBTD_PROXY_WINS_RELEASE_DEMAND,
    930                               &r, state);
    931         NT_STATUS_HAVE_NO_MEMORY(ireq);
    932 
    933         ireq->async.fn          = r_do_late_release_demand_handler;
    934         ireq->async.private_data= state;
     924        for (i=0; i < state->dr.in.num_addrs; i++) {
     925                state->dr.in.addrs[i].addr = state->r.out.addrs[i].addr;
     926        }
     927
     928        subreq = dcerpc_nbtd_proxy_wins_release_demand_r_send(state,
     929                        state->partner->service->task->event_ctx,
     930                        state->irpc_handle,
     931                        &state->dr);
     932        NT_STATUS_HAVE_NO_MEMORY(subreq);
     933
     934        tevent_req_set_callback(subreq, r_do_late_release_demand_handler, state);
    935935
    936936        return NT_STATUS_OK;
     
    952952_UA_MA_DI_A<00>: C:BEST vs. B:BEST2 (C:ALL) => B:MHOMED => MHOMED_MERGE
    953953*/
    954 static void r_do_challenge_handler(struct irpc_request *ireq)
     954static void r_do_challenge_handler(struct tevent_req *subreq)
    955955{
    956956        NTSTATUS status;
    957         struct r_do_challenge_state *state = talloc_get_type(ireq->async.private_data,
    958                                                              struct r_do_challenge_state);
     957        struct r_do_challenge_state *state =
     958                tevent_req_callback_data(subreq,
     959                struct r_do_challenge_state);
    959960        bool old_is_subset = false;
    960961        bool new_is_subset = false;
     
    963964        uint32_t num_rec_addrs;
    964965
    965         status = irpc_call_recv(ireq);
     966        status = dcerpc_nbtd_proxy_wins_challenge_r_recv(subreq, state);
     967        TALLOC_FREE(subreq);
    966968
    967969        DEBUG(4,("r_do_challenge_handler: %s: %s\n",
     
    10341036                               struct wrepl_name *replica)
    10351037{
    1036         struct irpc_request *ireq;
    10371038        struct r_do_challenge_state *state;
    1038         struct server_id *nbt_servers;
     1039        struct tevent_req *subreq;
    10391040        const char **addrs;
    10401041        uint32_t i;
     
    10451046        state = talloc_zero(mem_ctx, struct r_do_challenge_state);
    10461047        NT_STATUS_HAVE_NO_MEMORY(state);
    1047         state->msg_ctx  = partner->service->task->msg_ctx;
    10481048        state->partner  = partner;
    10491049        state->rec      = talloc_steal(state, rec);
     
    10551055        talloc_steal(state, replica->addresses);
    10561056
    1057         nbt_servers = irpc_servers_byname(state->msg_ctx, state, "nbt_server");
    1058         if ((nbt_servers == NULL) || (nbt_servers[0].id == 0)) {
     1057        state->irpc_handle = irpc_binding_handle_by_name(state,
     1058                                                         partner->service->task->msg_ctx,
     1059                                                         "nbt_server",
     1060                                                         &ndr_table_irpc);
     1061        if (state->irpc_handle == NULL) {
    10591062                return NT_STATUS_INTERNAL_ERROR;
    10601063        }
     
    10711074        }
    10721075
    1073         ireq = IRPC_CALL_SEND(state->msg_ctx, nbt_servers[0],
    1074                               irpc, NBTD_PROXY_WINS_CHALLENGE,
    1075                               &state->r, state);
    1076         NT_STATUS_HAVE_NO_MEMORY(ireq);
    1077 
    1078         ireq->async.fn          = r_do_challenge_handler;
    1079         ireq->async.private_data= state;
     1076        subreq = dcerpc_nbtd_proxy_wins_challenge_r_send(state,
     1077                        state->partner->service->task->event_ctx,
     1078                        state->irpc_handle,
     1079                        &state->r);
     1080        NT_STATUS_HAVE_NO_MEMORY(subreq);
     1081
     1082        tevent_req_set_callback(subreq, r_do_challenge_handler, state);
    10801083
    10811084        talloc_steal(partner, state);
     
    10841087
    10851088struct r_do_release_demand_state {
    1086         struct messaging_context *msg_ctx;
    10871089        struct nbtd_proxy_wins_release_demand r;
    10881090};
    10891091
    1090 static void r_do_release_demand_handler(struct irpc_request *ireq)
     1092static void r_do_release_demand_handler(struct tevent_req *subreq)
    10911093{
    10921094        NTSTATUS status;
    1093         struct r_do_release_demand_state *state = talloc_get_type(ireq->async.private_data,
    1094                                                   struct r_do_release_demand_state);
    1095 
    1096         status = irpc_call_recv(ireq);
     1095        struct r_do_release_demand_state *state =
     1096                tevent_req_callback_data(subreq,
     1097                struct r_do_release_demand_state);
     1098
     1099        status = dcerpc_nbtd_proxy_wins_release_demand_r_recv(subreq, state);
     1100        TALLOC_FREE(subreq);
     1101
    10971102        /* don't care about the result */
    10981103        talloc_free(state);
     
    11061111{
    11071112        NTSTATUS status;
    1108         struct irpc_request *ireq;
    1109         struct server_id *nbt_servers;
     1113        struct dcerpc_binding_handle *irpc_handle;
    11101114        const char **addrs;
    11111115        struct winsdb_addr **addresses;
    11121116        struct r_do_release_demand_state *state;
     1117        struct tevent_req *subreq;
    11131118        uint32_t i;
    11141119
     
    11281133        state = talloc_zero(mem_ctx, struct r_do_release_demand_state);
    11291134        NT_STATUS_HAVE_NO_MEMORY(state);
    1130         state->msg_ctx  = partner->service->task->msg_ctx;
    1131 
    1132         nbt_servers = irpc_servers_byname(state->msg_ctx, state, "nbt_server");
    1133         if ((nbt_servers == NULL) || (nbt_servers[0].id == 0)) {
     1135
     1136        irpc_handle = irpc_binding_handle_by_name(state,
     1137                                                  partner->service->task->msg_ctx,
     1138                                                  "nbt_server",
     1139                                                  &ndr_table_irpc);
     1140        if (irpc_handle == NULL) {
    11341141                return NT_STATUS_INTERNAL_ERROR;
    11351142        }
     
    11471154        }
    11481155
    1149         ireq = IRPC_CALL_SEND(state->msg_ctx, nbt_servers[0],
    1150                               irpc, NBTD_PROXY_WINS_RELEASE_DEMAND,
    1151                               &state->r, state);
    1152         NT_STATUS_HAVE_NO_MEMORY(ireq);
    1153 
    1154         ireq->async.fn          = r_do_release_demand_handler;
    1155         ireq->async.private_data= state;
     1156        subreq = dcerpc_nbtd_proxy_wins_release_demand_r_send(state,
     1157                        partner->service->task->event_ctx,
     1158                        irpc_handle,
     1159                        &state->r);
     1160        NT_STATUS_HAVE_NO_MEMORY(subreq);
     1161
     1162        tevent_req_set_callback(subreq, r_do_release_demand_handler, state);
    11561163
    11571164        talloc_steal(partner, state);
     
    11941201        bool skip_replica_owned_by_us = false;
    11951202        bool become_owner = true;
    1196         bool propagate = lp_parm_bool(partner->service->task->lp_ctx, NULL, "wreplsrv", "propagate name releases", false);
     1203        bool propagate = lpcfg_parm_bool(partner->service->task->lp_ctx, NULL, "wreplsrv", "propagate name releases", false);
    11971204        const char *local_owner = partner->service->wins_db->local_owner;
    11981205
     
    13581365        bool replica_vs_replica = false;
    13591366        bool local_vs_replica = false;
     1367
     1368        if (replica->name.scope) {
     1369                TALLOC_CTX *parent;
     1370                const char *scope;
     1371
     1372                /*
     1373                 * Windows 2008 truncates the scope to 237 bytes,
     1374                 * so we do...
     1375                 */
     1376                parent = talloc_parent(replica->name.scope);
     1377                scope = talloc_strndup(parent, replica->name.scope, 237);
     1378                NT_STATUS_HAVE_NO_MEMORY(scope);
     1379                replica->name.scope = scope;
     1380        }
    13601381
    13611382        status = winsdb_lookup(partner->service->wins_db,
  • vendor/current/source4/wrepl_server/wrepl_in_call.c

    r414 r740  
    2222#include "includes.h"
    2323#include "lib/events/events.h"
    24 #include "lib/socket/socket.h"
     24#include "lib/tsocket/tsocket.h"
     25#include "smbd/service_task.h"
    2526#include "smbd/service_stream.h"
    2627#include "libcli/wrepl/winsrepl.h"
     
    2829#include "libcli/composite/composite.h"
    2930#include "nbt_server/wins/winsdb.h"
    30 #include "lib/ldb/include/ldb.h"
    31 #include "lib/ldb/include/ldb_errors.h"
     31#include <ldb.h>
     32#include <ldb_errors.h>
    3233#include "system/time.h"
     34#include "lib/util/tsort.h"
     35#include "param/param.h"
    3336
    3437static NTSTATUS wreplsrv_in_start_association(struct wreplsrv_in_call *call)
     
    199202        struct winsdb_record *rec;
    200203        NTSTATUS status;
    201         uint32_t i, j;
     204        unsigned int i, j;
    202205        time_t now = time(NULL);
    203206
     
    301304
    302305        /* sort the names before we send them */
    303         qsort(names, j, sizeof(struct wrepl_wins_name), (comparison_fn_t)wreplsrv_in_sort_wins_name);
     306        TYPESAFE_QSORT(names, j, wreplsrv_in_sort_wins_name);
    304307
    305308        DEBUG(2,("WINSREPL:reply [%u] records owner[%s] min[%llu] max[%llu] to partner[%s]\n",
     
    341344        struct wrepl_table *update_in = &call->req_packet.message.replication.info.table;
    342345        struct wreplsrv_in_update_state *update_state;
    343         uint16_t fde_flags;
     346        NTSTATUS status;
    344347
    345348        DEBUG(2,("WREPL_REPL_UPDATE: partner[%s] initiator[%s] num_owners[%u]\n",
    346349                call->wreplconn->partner->address,
    347350                update_in->initiator, update_in->partner_count));
    348 
    349         /*
    350          * we need to flip the connection into a client connection
    351          * and do a WREPL_REPL_SEND_REQUEST's on the that connection
    352          * and then stop this connection
    353          */
    354         fde_flags = event_get_fd_flags(wrepl_in->conn->event.fde);
    355         talloc_free(wrepl_in->conn->event.fde);
    356         wrepl_in->conn->event.fde = NULL;
    357351
    358352        update_state = talloc(wrepl_in, struct wreplsrv_in_update_state);
     
    365359        wrepl_out->assoc_ctx.our_ctx    = wrepl_in->assoc_ctx.our_ctx;
    366360        wrepl_out->assoc_ctx.peer_ctx   = wrepl_in->assoc_ctx.peer_ctx;
    367         wrepl_out->sock                 = wrepl_socket_merge(wrepl_out,
    368                                                              wrepl_in->conn->event.ctx,
    369                                                              wrepl_in->conn->socket,
    370                                                              wrepl_in->packet);
    371         NT_STATUS_HAVE_NO_MEMORY(wrepl_out->sock);
    372 
    373         event_set_fd_flags(wrepl_out->sock->event.fde, fde_flags);
     361        wrepl_out->sock                 = wrepl_socket_init(wrepl_out,
     362                                                            wrepl_in->conn->event.ctx);
     363                                                           
     364        NT_STATUS_HAVE_NO_MEMORY_AND_FREE(wrepl_out->sock, update_state);
     365
     366        TALLOC_FREE(wrepl_in->send_queue);
     367
     368        status = wrepl_socket_donate_stream(wrepl_out->sock, &wrepl_in->tstream);
     369        NT_STATUS_NOT_OK_RETURN_AND_FREE(status, update_state);
    374370
    375371        update_state->wrepl_in                  = wrepl_in;
     
    382378        update_state->creq = wreplsrv_pull_cycle_send(update_state, &update_state->cycle_io);
    383379        if (!update_state->creq) {
     380                talloc_free(update_state);
    384381                return NT_STATUS_INTERNAL_ERROR;
    385382        }
     
    433430
    434431        if (!call->wreplconn->partner) {
    435                 struct socket_address *partner_ip = socket_get_peer_addr(call->wreplconn->conn->socket, call);
    436 
    437                 call->wreplconn->partner = wreplsrv_find_partner(call->wreplconn->service, partner_ip->addr);
     432                struct tsocket_address *peer_addr = call->wreplconn->conn->remote_address;
     433                char *peer_ip;
     434
     435                if (!tsocket_address_is_inet(peer_addr, "ipv4")) {
     436                        DEBUG(0,("wreplsrv_in_replication: non ipv4 peer addr '%s'\n",
     437                                tsocket_address_string(peer_addr, call)));
     438                        return NT_STATUS_INTERNAL_ERROR;
     439                }
     440
     441                peer_ip = tsocket_address_inet_addr_string(peer_addr, call);
     442                if (peer_ip == NULL) {
     443                        return NT_STATUS_NO_MEMORY;
     444                }
     445
     446                call->wreplconn->partner = wreplsrv_find_partner(call->wreplconn->service, peer_ip);
    438447                if (!call->wreplconn->partner) {
    439                         DEBUG(1,("Failing WINS replication from non-partner %s\n",
    440                                  partner_ip ? partner_ip->addr : NULL));
     448                        DEBUG(1,("Failing WINS replication from non-partner %s\n", peer_ip));
    441449                        return wreplsrv_in_stop_assoc_ctx(call);
    442450                }
  • vendor/current/source4/wrepl_server/wrepl_in_connection.c

    r414 r740  
    3232#include "system/network.h"
    3333#include "lib/socket/netif.h"
     34#include "lib/tsocket/tsocket.h"
     35#include "libcli/util/tstream.h"
    3436#include "param/param.h"
    3537
     
    3941}
    4042
    41 static int terminate_after_send_destructor(struct wreplsrv_in_connection **tas)
    42 {
    43         wreplsrv_terminate_in_connection(*tas, "wreplsrv_in_connection: terminate_after_send");
    44         return 0;
    45 }
    46 
    4743/*
    4844  receive some data on a WREPL connection
    4945*/
    50 static NTSTATUS wreplsrv_recv_request(void *private_data, DATA_BLOB blob)
    51 {
    52         struct wreplsrv_in_connection *wreplconn = talloc_get_type(private_data, struct wreplsrv_in_connection);
    53         struct wreplsrv_in_call *call;
    54         DATA_BLOB packet_in_blob;
    55         DATA_BLOB packet_out_blob;
     46static NTSTATUS wreplsrv_process(struct wreplsrv_in_connection *wrepl_conn,
     47                                 struct wreplsrv_in_call **_call)
     48{
    5649        struct wrepl_wrap packet_out_wrap;
    5750        NTSTATUS status;
    5851        enum ndr_err_code ndr_err;
    59 
    60         call = talloc_zero(wreplconn, struct wreplsrv_in_call);
    61         NT_STATUS_HAVE_NO_MEMORY(call);
    62         call->wreplconn = wreplconn;
    63         talloc_steal(call, blob.data);
    64 
    65         packet_in_blob.data = blob.data + 4;
    66         packet_in_blob.length = blob.length - 4;
    67 
    68         ndr_err = ndr_pull_struct_blob(&packet_in_blob, call,
    69                                        lp_iconv_convenience(wreplconn->service->task->lp_ctx),
     52        struct wreplsrv_in_call *call = *_call;
     53
     54        ndr_err = ndr_pull_struct_blob(&call->in, call,
    7055                                       &call->req_packet,
    7156                                       (ndr_pull_flags_fn_t)ndr_pull_wrepl_packet);
     
    7560
    7661        if (DEBUGLVL(10)) {
    77                 DEBUG(10,("Received WINS-Replication packet of length %u\n", 
    78                           (unsigned)packet_in_blob.length + 4));
     62                DEBUG(10,("Received WINS-Replication packet of length %u\n",
     63                          (unsigned int) call->in.length + 4));
    7964                NDR_PRINT_DEBUG(wrepl_packet, &call->req_packet);
    8065        }
     
    8570                /* w2k just ignores invalid packets, so we do */
    8671                DEBUG(10,("Received WINS-Replication packet was invalid, we just ignore it\n"));
    87                 talloc_free(call);
     72                TALLOC_FREE(call);
     73                *_call = NULL;
    8874                return NT_STATUS_OK;
    8975        }
     
    9177        /* and now encode the reply */
    9278        packet_out_wrap.packet = call->rep_packet;
    93         ndr_err = ndr_push_struct_blob(&packet_out_blob, call,
    94                                        lp_iconv_convenience(wreplconn->service->task->lp_ctx),
     79        ndr_err = ndr_push_struct_blob(&call->out, call,
    9580                                       &packet_out_wrap,
    96                                       (ndr_push_flags_fn_t)ndr_push_wrepl_wrap);
     81                                       (ndr_push_flags_fn_t) ndr_push_wrepl_wrap);
    9782        if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
    9883                return ndr_map_error2ntstatus(ndr_err);
     
    10085
    10186        if (DEBUGLVL(10)) {
    102                 DEBUG(10,("Sending WINS-Replication packet of length %d\n", (int)packet_out_blob.length));
     87                DEBUG(10,("Sending WINS-Replication packet of length %u\n",
     88                         (unsigned int) call->out.length));
    10389                NDR_PRINT_DEBUG(wrepl_packet, &call->rep_packet);
    10490        }
    10591
     92        return NT_STATUS_OK;
     93}
     94
     95static void wreplsrv_call_loop(struct tevent_req *subreq);
     96
     97/*
     98  called when we get a new connection
     99*/
     100static void wreplsrv_accept(struct stream_connection *conn)
     101{
     102        struct wreplsrv_service *service = talloc_get_type(conn->private_data, struct wreplsrv_service);
     103        struct wreplsrv_in_connection *wrepl_conn;
     104        struct tsocket_address *peer_addr;
     105        char *peer_ip;
     106        struct tevent_req *subreq;
     107        int rc;
     108
     109        wrepl_conn = talloc_zero(conn, struct wreplsrv_in_connection);
     110        if (wrepl_conn == NULL) {
     111                stream_terminate_connection(conn,
     112                                            "wreplsrv_accept: out of memory");
     113                return;
     114        }
     115
     116        wrepl_conn->send_queue = tevent_queue_create(conn, "wrepl_accept");
     117        if (wrepl_conn->send_queue == NULL) {
     118                stream_terminate_connection(conn,
     119                                            "wrepl_accept: out of memory");
     120                return;
     121        }
     122
     123        TALLOC_FREE(conn->event.fde);
     124
     125        rc = tstream_bsd_existing_socket(wrepl_conn,
     126                                         socket_get_fd(conn->socket),
     127                                         &wrepl_conn->tstream);
     128        if (rc < 0) {
     129                stream_terminate_connection(conn,
     130                                            "wrepl_accept: out of memory");
     131                return;
     132        }
     133        socket_set_flags(conn->socket, SOCKET_FLAG_NOCLOSE);
     134
     135        wrepl_conn->conn = conn;
     136        wrepl_conn->service = service;
     137
     138        peer_addr = conn->remote_address;
     139
     140        if (!tsocket_address_is_inet(peer_addr, "ipv4")) {
     141                DEBUG(0,("wreplsrv_accept: non ipv4 peer addr '%s'\n",
     142                        tsocket_address_string(peer_addr, wrepl_conn)));
     143                wreplsrv_terminate_in_connection(wrepl_conn, "wreplsrv_accept: "
     144                                "invalid peer IP");
     145                return;
     146        }
     147
     148        peer_ip = tsocket_address_inet_addr_string(peer_addr, wrepl_conn);
     149        if (peer_ip == NULL) {
     150                wreplsrv_terminate_in_connection(wrepl_conn, "wreplsrv_accept: "
     151                                "could not convert peer IP into a string");
     152                return;
     153        }
     154
     155        wrepl_conn->partner = wreplsrv_find_partner(service, peer_ip);
     156        irpc_add_name(conn->msg_ctx, "wreplsrv_connection");
     157
     158        /*
     159         * The wrepl pdu's has the length as 4 byte (initial_read_size),
     160         * packet_full_request_u32 provides the pdu length then.
     161         */
     162        subreq = tstream_read_pdu_blob_send(wrepl_conn,
     163                                            wrepl_conn->conn->event.ctx,
     164                                            wrepl_conn->tstream,
     165                                            4, /* initial_read_size */
     166                                            packet_full_request_u32,
     167                                            wrepl_conn);
     168        if (subreq == NULL) {
     169                wreplsrv_terminate_in_connection(wrepl_conn, "wrepl_accept: "
     170                                "no memory for tstream_read_pdu_blob_send");
     171                return;
     172        }
     173        tevent_req_set_callback(subreq, wreplsrv_call_loop, wrepl_conn);
     174}
     175
     176static void wreplsrv_call_writev_done(struct tevent_req *subreq);
     177
     178static void wreplsrv_call_loop(struct tevent_req *subreq)
     179{
     180        struct wreplsrv_in_connection *wrepl_conn = tevent_req_callback_data(subreq,
     181                                      struct wreplsrv_in_connection);
     182        struct wreplsrv_in_call *call;
     183        NTSTATUS status;
     184
     185        call = talloc_zero(wrepl_conn, struct wreplsrv_in_call);
     186        if (call == NULL) {
     187                wreplsrv_terminate_in_connection(wrepl_conn, "wreplsrv_call_loop: "
     188                                "no memory for wrepl_samba3_call");
     189                return;
     190        }
     191        call->wreplconn = wrepl_conn;
     192
     193        status = tstream_read_pdu_blob_recv(subreq,
     194                                            call,
     195                                            &call->in);
     196        TALLOC_FREE(subreq);
     197        if (!NT_STATUS_IS_OK(status)) {
     198                const char *reason;
     199
     200                reason = talloc_asprintf(call, "wreplsrv_call_loop: "
     201                                         "tstream_read_pdu_blob_recv() - %s",
     202                                         nt_errstr(status));
     203                if (!reason) {
     204                        reason = nt_errstr(status);
     205                }
     206
     207                wreplsrv_terminate_in_connection(wrepl_conn, reason);
     208                return;
     209        }
     210
     211        DEBUG(10,("Received wrepl packet of length %lu from %s\n",
     212                 (long) call->in.length,
     213                 tsocket_address_string(wrepl_conn->conn->remote_address, call)));
     214
     215        /* skip length header */
     216        call->in.data += 4;
     217        call->in.length -= 4;
     218
     219        status = wreplsrv_process(wrepl_conn, &call);
     220        if (!NT_STATUS_IS_OK(status)) {
     221                const char *reason;
     222
     223                reason = talloc_asprintf(call, "wreplsrv_call_loop: "
     224                                         "tstream_read_pdu_blob_recv() - %s",
     225                                         nt_errstr(status));
     226                if (reason == NULL) {
     227                        reason = nt_errstr(status);
     228                }
     229
     230                wreplsrv_terminate_in_connection(wrepl_conn, reason);
     231                return;
     232        }
     233
     234        /* We handed over the connection so we're done here */
     235        if (wrepl_conn->tstream == NULL) {
     236            return;
     237        }
     238
     239        /* Invalid WINS-Replication packet, we just ignore it */
     240        if (call == NULL) {
     241                goto noreply;
     242        }
     243
     244        call->out_iov[0].iov_base = (char *) call->out.data;
     245        call->out_iov[0].iov_len = call->out.length;
     246
     247        subreq = tstream_writev_queue_send(call,
     248                                           wrepl_conn->conn->event.ctx,
     249                                           wrepl_conn->tstream,
     250                                           wrepl_conn->send_queue,
     251                                           call->out_iov, 1);
     252        if (subreq == NULL) {
     253                wreplsrv_terminate_in_connection(wrepl_conn, "wreplsrv_call_loop: "
     254                                "no memory for tstream_writev_queue_send");
     255                return;
     256        }
     257        tevent_req_set_callback(subreq, wreplsrv_call_writev_done, call);
     258
     259noreply:
     260        /*
     261         * The wrepl pdu's has the length as 4 byte (initial_read_size),
     262         *  provides the pdu length then.
     263         */
     264        subreq = tstream_read_pdu_blob_send(wrepl_conn,
     265                                            wrepl_conn->conn->event.ctx,
     266                                            wrepl_conn->tstream,
     267                                            4, /* initial_read_size */
     268                                            packet_full_request_u32,
     269                                            wrepl_conn);
     270        if (subreq == NULL) {
     271                wreplsrv_terminate_in_connection(wrepl_conn, "wreplsrv_call_loop: "
     272                                "no memory for tstream_read_pdu_blob_send");
     273                return;
     274        }
     275        tevent_req_set_callback(subreq, wreplsrv_call_loop, wrepl_conn);
     276}
     277
     278static void wreplsrv_call_writev_done(struct tevent_req *subreq)
     279{
     280        struct wreplsrv_in_call *call = tevent_req_callback_data(subreq,
     281                        struct wreplsrv_in_call);
     282        int sys_errno;
     283        int rc;
     284
     285        rc = tstream_writev_queue_recv(subreq, &sys_errno);
     286        TALLOC_FREE(subreq);
     287        if (rc == -1) {
     288                const char *reason;
     289
     290                reason = talloc_asprintf(call, "wreplsrv_call_writev_done: "
     291                                         "tstream_writev_queue_recv() - %d:%s",
     292                                         sys_errno, strerror(sys_errno));
     293                if (reason == NULL) {
     294                        reason = "wreplsrv_call_writev_done: "
     295                                 "tstream_writev_queue_recv() failed";
     296                }
     297
     298                wreplsrv_terminate_in_connection(call->wreplconn, reason);
     299                return;
     300        }
     301
    106302        if (call->terminate_after_send) {
    107                 struct wreplsrv_in_connection **tas;
    108                 tas = talloc(packet_out_blob.data, struct wreplsrv_in_connection *);
    109                 NT_STATUS_HAVE_NO_MEMORY(tas);
    110                 *tas = wreplconn;
    111                 talloc_set_destructor(tas, terminate_after_send_destructor);
    112         }
    113 
    114         status = packet_send(wreplconn->packet, packet_out_blob);
    115         NT_STATUS_NOT_OK_RETURN(status);
     303                wreplsrv_terminate_in_connection(call->wreplconn,
     304                                "wreplsrv_in_connection: terminate_after_send");
     305                return;
     306        }
    116307
    117308        talloc_free(call);
    118         return NT_STATUS_OK;
    119 }
    120 
    121 /*
    122   called when the socket becomes readable
     309}
     310
     311/*
     312  called on a tcp recv
    123313*/
    124314static void wreplsrv_recv(struct stream_connection *conn, uint16_t flags)
    125315{
    126         struct wreplsrv_in_connection *wreplconn = talloc_get_type(conn->private_data,
    127                                                                    struct wreplsrv_in_connection);
    128 
    129         packet_recv(wreplconn->packet);
    130 }
    131 
    132 /*
    133   called when the socket becomes writable
     316        struct wreplsrv_in_connection *wrepl_conn = talloc_get_type(conn->private_data,
     317                                                        struct wreplsrv_in_connection);
     318        /* this should never be triggered! */
     319        DEBUG(0,("Terminating connection - '%s'\n", "wrepl_recv: called"));
     320        wreplsrv_terminate_in_connection(wrepl_conn, "wrepl_recv: called");
     321}
     322
     323/*
     324  called when we can write to a connection
    134325*/
    135326static void wreplsrv_send(struct stream_connection *conn, uint16_t flags)
    136327{
    137         struct wreplsrv_in_connection *wreplconn = talloc_get_type(conn->private_data,
    138                                                                    struct wreplsrv_in_connection);
    139         packet_queue_run(wreplconn->packet);
    140 }
    141 
    142 /*
    143   handle socket recv errors
    144 */
    145 static void wreplsrv_recv_error(void *private_data, NTSTATUS status)
    146 {
    147         struct wreplsrv_in_connection *wreplconn = talloc_get_type(private_data,
    148                                                                    struct wreplsrv_in_connection);
    149         wreplsrv_terminate_in_connection(wreplconn, nt_errstr(status));
    150 }
    151 
    152 /*
    153   called when we get a new connection
    154 */
    155 static void wreplsrv_accept(struct stream_connection *conn)
    156 {
    157         struct wreplsrv_service *service = talloc_get_type(conn->private_data, struct wreplsrv_service);
    158         struct wreplsrv_in_connection *wreplconn;
    159         struct socket_address *peer_ip;
    160 
    161         wreplconn = talloc_zero(conn, struct wreplsrv_in_connection);
    162         if (!wreplconn) {
    163                 stream_terminate_connection(conn, "wreplsrv_accept: out of memory");
    164                 return;
    165         }
    166 
    167         wreplconn->packet = packet_init(wreplconn);
    168         if (!wreplconn->packet) {
    169                 wreplsrv_terminate_in_connection(wreplconn, "wreplsrv_accept: out of memory");
    170                 return;
    171         }
    172         packet_set_private(wreplconn->packet, wreplconn);
    173         packet_set_socket(wreplconn->packet, conn->socket);
    174         packet_set_callback(wreplconn->packet, wreplsrv_recv_request);
    175         packet_set_full_request(wreplconn->packet, packet_full_request_u32);
    176         packet_set_error_handler(wreplconn->packet, wreplsrv_recv_error);
    177         packet_set_event_context(wreplconn->packet, conn->event.ctx);
    178         packet_set_fde(wreplconn->packet, conn->event.fde);
    179         packet_set_serialise(wreplconn->packet);
    180 
    181         wreplconn->conn         = conn;
    182         wreplconn->service      = service;
    183 
    184         peer_ip = socket_get_peer_addr(conn->socket, wreplconn);
    185         if (!peer_ip) {
    186                 wreplsrv_terminate_in_connection(wreplconn, "wreplsrv_accept: could not obtain peer IP from kernel");
    187                 return;
    188         }
    189 
    190         wreplconn->partner      = wreplsrv_find_partner(service, peer_ip->addr);
    191 
    192         conn->private_data = wreplconn;
    193 
    194         irpc_add_name(conn->msg_ctx, "wreplsrv_connection");
     328        struct wreplsrv_in_connection *wrepl_conn = talloc_get_type(conn->private_data,
     329                                                        struct wreplsrv_in_connection);
     330        /* this should never be triggered! */
     331        DEBUG(0,("Terminating connection - '%s'\n", "wrepl_send: called"));
     332        wreplsrv_terminate_in_connection(wrepl_conn, "wrepl_send: called");
    195333}
    196334
     
    206344*/
    207345NTSTATUS wreplsrv_in_connection_merge(struct wreplsrv_partner *partner,
    208                                       struct socket_context *sock,
    209                                       struct packet_context *packet,
     346                                      uint32_t peer_assoc_ctx,
     347                                      struct tstream_context **stream,
    210348                                      struct wreplsrv_in_connection **_wrepl_in)
    211349{
     
    214352        const struct model_ops *model_ops;
    215353        struct stream_connection *conn;
     354        struct tevent_req *subreq;
    216355        NTSTATUS status;
    217356
     
    219358           ask for the single process model ops and pass these to the
    220359           stream_setup_socket() call. */
    221         model_ops = process_model_startup(service->task->event_ctx, "single");
     360        model_ops = process_model_startup("single");
    222361        if (!model_ops) {
    223362                DEBUG(0,("Can't find 'single' process model_ops"));
     
    230369        wrepl_in->service       = service;
    231370        wrepl_in->partner       = partner;
    232 
    233         status = stream_new_connection_merge(service->task->event_ctx, service->task->lp_ctx, model_ops,
    234                                              sock, &wreplsrv_stream_ops, service->task->msg_ctx,
    235                                              wrepl_in, &conn);
     371        wrepl_in->tstream       = talloc_move(wrepl_in, stream);
     372        wrepl_in->assoc_ctx.peer_ctx = peer_assoc_ctx;
     373
     374        status = stream_new_connection_merge(service->task->event_ctx,
     375                                             service->task->lp_ctx,
     376                                             model_ops,
     377                                             &wreplsrv_stream_ops,
     378                                             service->task->msg_ctx,
     379                                             wrepl_in,
     380                                             &conn);
    236381        NT_STATUS_NOT_OK_RETURN(status);
    237382
     
    243388        talloc_steal(conn, wrepl_in);
    244389
     390        wrepl_in->send_queue = tevent_queue_create(wrepl_in, "wreplsrv_in_connection_merge");
     391        if (wrepl_in->send_queue == NULL) {
     392                stream_terminate_connection(conn,
     393                                            "wreplsrv_in_connection_merge: out of memory");
     394                return NT_STATUS_NO_MEMORY;
     395        }
     396
    245397        /*
    246          * now update the packet handling callback,...
     398         * The wrepl pdu's has the length as 4 byte (initial_read_size),
     399         * packet_full_request_u32 provides the pdu length then.
    247400         */
    248         wrepl_in->packet        = talloc_steal(wrepl_in, packet);
    249         packet_set_private(wrepl_in->packet, wrepl_in);
    250         packet_set_socket(wrepl_in->packet, conn->socket);
    251         packet_set_callback(wrepl_in->packet, wreplsrv_recv_request);
    252         packet_set_full_request(wrepl_in->packet, packet_full_request_u32);
    253         packet_set_error_handler(wrepl_in->packet, wreplsrv_recv_error);
    254         packet_set_event_context(wrepl_in->packet, conn->event.ctx);
    255         packet_set_fde(wrepl_in->packet, conn->event.fde);
    256         packet_set_serialise(wrepl_in->packet);
     401        subreq = tstream_read_pdu_blob_send(wrepl_in,
     402                                            wrepl_in->conn->event.ctx,
     403                                            wrepl_in->tstream,
     404                                            4, /* initial_read_size */
     405                                            packet_full_request_u32,
     406                                            wrepl_in);
     407        if (subreq == NULL) {
     408                wreplsrv_terminate_in_connection(wrepl_in, "wreplsrv_in_connection_merge: "
     409                                "no memory for tstream_read_pdu_blob_send");
     410                return NT_STATUS_NO_MEMORY;
     411        }
     412        tevent_req_set_callback(subreq, wreplsrv_call_loop, wrepl_in);
    257413
    258414        *_wrepl_in = wrepl_in;
     415
    259416        return NT_STATUS_OK;
    260417}
     
    274431           ask for the single process model ops and pass these to the
    275432           stream_setup_socket() call. */
    276         model_ops = process_model_startup(task->event_ctx, "single");
     433        model_ops = process_model_startup("single");
    277434        if (!model_ops) {
    278435                DEBUG(0,("Can't find 'single' process model_ops"));
     
    280437        }
    281438
    282         if (lp_interfaces(lp_ctx) && lp_bind_interfaces_only(lp_ctx)) {
     439        if (lpcfg_interfaces(lp_ctx) && lpcfg_bind_interfaces_only(lp_ctx)) {
    283440                int num_interfaces;
    284441                int i;
    285442                struct interface *ifaces;
    286443
    287                 load_interfaces(task, lp_interfaces(lp_ctx), &ifaces);
     444                load_interfaces(task, lpcfg_interfaces(lp_ctx), &ifaces);
    288445
    289446                num_interfaces = iface_count(ifaces);
     
    295452                for(i = 0; i < num_interfaces; i++) {
    296453                        address = iface_n_ip(ifaces, i);
    297                         status = stream_setup_socket(task->event_ctx,
    298                                                      task->lp_ctx, model_ops, 
     454                        status = stream_setup_socket(task, task->event_ctx,
     455                                                     task->lp_ctx, model_ops,
    299456                                                     &wreplsrv_stream_ops,
    300457                                                     "ipv4", address, &port,
    301                                                       lp_socket_options(task->lp_ctx),
     458                                                      lpcfg_socket_options(task->lp_ctx),
    302459                                                     service);
    303460                        if (!NT_STATUS_IS_OK(status)) {
     
    308465                }
    309466        } else {
    310                 address = lp_socket_address(lp_ctx);
    311                 status = stream_setup_socket(task->event_ctx, task->lp_ctx,
     467                address = lpcfg_socket_address(lp_ctx);
     468                status = stream_setup_socket(task, task->event_ctx, task->lp_ctx,
    312469                                             model_ops, &wreplsrv_stream_ops,
    313                                              "ipv4", address, &port, lp_socket_options(task->lp_ctx),
     470                                             "ipv4", address, &port, lpcfg_socket_options(task->lp_ctx),
    314471                                             service);
    315472                if (!NT_STATUS_IS_OK(status)) {
  • vendor/current/source4/wrepl_server/wrepl_out_helpers.c

    r414 r740  
    4242        enum wreplsrv_out_connect_stage stage;
    4343        struct composite_context *c;
    44         struct wrepl_request *req;
    45         struct composite_context *c_req;
    4644        struct wrepl_associate assoc_io;
    4745        enum winsrepl_partner_type type;
    4846        struct wreplsrv_out_connection *wreplconn;
     47        struct tevent_req *subreq;
    4948};
    5049
    51 static void wreplsrv_out_connect_handler_creq(struct composite_context *c_req);
    52 static void wreplsrv_out_connect_handler_req(struct wrepl_request *req);
     50static void wreplsrv_out_connect_handler_treq(struct tevent_req *subreq);
    5351
    5452static NTSTATUS wreplsrv_out_connect_wait_socket(struct wreplsrv_out_connect_state *state)
     
    5654        NTSTATUS status;
    5755
    58         status = wrepl_connect_recv(state->c_req);
    59         NT_STATUS_NOT_OK_RETURN(status);
    60 
    61         state->req = wrepl_associate_send(state->wreplconn->sock, &state->assoc_io);
    62         NT_STATUS_HAVE_NO_MEMORY(state->req);
    63 
    64         state->req->async.fn            = wreplsrv_out_connect_handler_req;
    65         state->req->async.private_data  = state;
     56        status = wrepl_connect_recv(state->subreq);
     57        TALLOC_FREE(state->subreq);
     58        NT_STATUS_NOT_OK_RETURN(status);
     59
     60        state->subreq = wrepl_associate_send(state,
     61                                             state->wreplconn->service->task->event_ctx,
     62                                             state->wreplconn->sock, &state->assoc_io);
     63        NT_STATUS_HAVE_NO_MEMORY(state->subreq);
     64
     65        tevent_req_set_callback(state->subreq,
     66                                wreplsrv_out_connect_handler_treq,
     67                                state);
    6668
    6769        state->stage = WREPLSRV_OUT_CONNECT_STAGE_WAIT_ASSOC_CTX;
     
    7476        NTSTATUS status;
    7577
    76         status = wrepl_associate_recv(state->req, &state->assoc_io);
     78        status = wrepl_associate_recv(state->subreq, &state->assoc_io);
     79        TALLOC_FREE(state->subreq);
    7780        NT_STATUS_NOT_OK_RETURN(status);
    7881
     
    122125}
    123126
    124 static void wreplsrv_out_connect_handler_creq(struct composite_context *creq)
    125 {
    126         struct wreplsrv_out_connect_state *state = talloc_get_type(creq->async.private_data,
    127                                                    struct wreplsrv_out_connect_state);
    128         wreplsrv_out_connect_handler(state);
    129         return;
    130 }
    131 
    132 static void wreplsrv_out_connect_handler_req(struct wrepl_request *req)
    133 {
    134         struct wreplsrv_out_connect_state *state = talloc_get_type(req->async.private_data,
     127static void wreplsrv_out_connect_handler_treq(struct tevent_req *subreq)
     128{
     129        struct wreplsrv_out_connect_state *state = tevent_req_callback_data(subreq,
    135130                                                   struct wreplsrv_out_connect_state);
    136131        wreplsrv_out_connect_handler(state);
     
    172167        /* we have a connection already, so use it */
    173168        if (wreplconn) {
    174                 if (!wreplconn->sock->dead) {
     169                if (wrepl_socket_is_connected(wreplconn->sock)) {
    175170                        state->stage    = WREPLSRV_OUT_CONNECT_STAGE_DONE;
    176171                        state->wreplconn= wreplconn;
     
    193188        wreplconn->service      = service;
    194189        wreplconn->partner      = partner;
    195         wreplconn->sock         = wrepl_socket_init(wreplconn, service->task->event_ctx, lp_iconv_convenience(service->task->lp_ctx));
     190        wreplconn->sock         = wrepl_socket_init(wreplconn, service->task->event_ctx);
    196191        if (!wreplconn->sock) goto failed;
    197192
    198193        state->stage    = WREPLSRV_OUT_CONNECT_STAGE_WAIT_SOCKET;
    199194        state->wreplconn= wreplconn;
    200         state->c_req    = wrepl_connect_send(wreplconn->sock,
     195        state->subreq   = wrepl_connect_send(state,
     196                                             service->task->event_ctx,
     197                                             wreplconn->sock,
    201198                                             partner->our_address?partner->our_address:wrepl_best_ip(service->task->lp_ctx, partner->address),
    202199                                             partner->address);
    203         if (!state->c_req) goto failed;
    204 
    205         state->c_req->async.fn                  = wreplsrv_out_connect_handler_creq;
    206         state->c_req->async.private_data        = state;
     200        if (!state->subreq) goto failed;
     201
     202        tevent_req_set_callback(state->subreq,
     203                                wreplsrv_out_connect_handler_treq,
     204                                state);
    207205
    208206        return c;
     
    256254        enum wreplsrv_pull_table_stage stage;
    257255        struct composite_context *c;
    258         struct wrepl_request *req;
    259256        struct wrepl_pull_table table_io;
    260257        struct wreplsrv_pull_table_io *io;
    261258        struct composite_context *creq;
    262259        struct wreplsrv_out_connection *wreplconn;
     260        struct tevent_req *subreq;
    263261};
    264262
    265 static void wreplsrv_pull_table_handler_req(struct wrepl_request *req);
     263static void wreplsrv_pull_table_handler_treq(struct tevent_req *subreq);
    266264
    267265static NTSTATUS wreplsrv_pull_table_wait_connection(struct wreplsrv_pull_table_state *state)
     
    273271
    274272        state->table_io.in.assoc_ctx = state->wreplconn->assoc_ctx.peer_ctx;
    275         state->req = wrepl_pull_table_send(state->wreplconn->sock, &state->table_io);
    276         NT_STATUS_HAVE_NO_MEMORY(state->req);
    277 
    278         state->req->async.fn            = wreplsrv_pull_table_handler_req;
    279         state->req->async.private_data  = state;
     273        state->subreq = wrepl_pull_table_send(state,
     274                                              state->wreplconn->service->task->event_ctx,
     275                                              state->wreplconn->sock, &state->table_io);
     276        NT_STATUS_HAVE_NO_MEMORY(state->subreq);
     277
     278        tevent_req_set_callback(state->subreq,
     279                                wreplsrv_pull_table_handler_treq,
     280                                state);
    280281
    281282        state->stage = WREPLSRV_PULL_TABLE_STAGE_WAIT_TABLE_REPLY;
     
    288289        NTSTATUS status;
    289290
    290         status = wrepl_pull_table_recv(state->req, state, &state->table_io);
     291        status = wrepl_pull_table_recv(state->subreq, state, &state->table_io);
     292        TALLOC_FREE(state->subreq);
    291293        NT_STATUS_NOT_OK_RETURN(status);
    292294
     
    329331}
    330332
    331 static void wreplsrv_pull_table_handler_req(struct wrepl_request *req)
    332 {
    333         struct wreplsrv_pull_table_state *state = talloc_get_type(req->async.private_data,
     333static void wreplsrv_pull_table_handler_treq(struct tevent_req *subreq)
     334{
     335        struct wreplsrv_pull_table_state *state = tevent_req_callback_data(subreq,
    334336                                                  struct wreplsrv_pull_table_state);
    335337        wreplsrv_pull_table_handler(state);
     
    415417        enum wreplsrv_pull_names_stage stage;
    416418        struct composite_context *c;
    417         struct wrepl_request *req;
    418419        struct wrepl_pull_names pull_io;
    419420        struct wreplsrv_pull_names_io *io;
    420421        struct composite_context *creq;
    421422        struct wreplsrv_out_connection *wreplconn;
     423        struct tevent_req *subreq;
    422424};
    423425
    424 static void wreplsrv_pull_names_handler_req(struct wrepl_request *req);
     426static void wreplsrv_pull_names_handler_treq(struct tevent_req *subreq);
    425427
    426428static NTSTATUS wreplsrv_pull_names_wait_connection(struct wreplsrv_pull_names_state *state)
     
    433435        state->pull_io.in.assoc_ctx     = state->wreplconn->assoc_ctx.peer_ctx;
    434436        state->pull_io.in.partner       = state->io->in.owner;
    435         state->req = wrepl_pull_names_send(state->wreplconn->sock, &state->pull_io);
    436         NT_STATUS_HAVE_NO_MEMORY(state->req);
    437 
    438         state->req->async.fn            = wreplsrv_pull_names_handler_req;
    439         state->req->async.private_data  = state;
     437        state->subreq = wrepl_pull_names_send(state,
     438                                              state->wreplconn->service->task->event_ctx,
     439                                              state->wreplconn->sock,
     440                                              &state->pull_io);
     441        NT_STATUS_HAVE_NO_MEMORY(state->subreq);
     442
     443        tevent_req_set_callback(state->subreq,
     444                                wreplsrv_pull_names_handler_treq,
     445                                state);
    440446
    441447        state->stage = WREPLSRV_PULL_NAMES_STAGE_WAIT_SEND_REPLY;
     
    448454        NTSTATUS status;
    449455
    450         status = wrepl_pull_names_recv(state->req, state, &state->pull_io);
     456        status = wrepl_pull_names_recv(state->subreq, state, &state->pull_io);
     457        TALLOC_FREE(state->subreq);
    451458        NT_STATUS_NOT_OK_RETURN(status);
    452459
     
    489496}
    490497
    491 static void wreplsrv_pull_names_handler_req(struct wrepl_request *req)
    492 {
    493         struct wreplsrv_pull_names_state *state = talloc_get_type(req->async.private_data,
     498static void wreplsrv_pull_names_handler_treq(struct tevent_req *subreq)
     499{
     500        struct wreplsrv_pull_names_state *state = tevent_req_callback_data(subreq,
    494501                                                  struct wreplsrv_pull_names_state);
    495502        wreplsrv_pull_names_handler(state);
     
    566573        struct composite_context *creq;
    567574        struct wrepl_associate_stop assoc_stop_io;
    568         struct wrepl_request *req;
     575        struct tevent_req *subreq;
    569576};
    570577
    571578static void wreplsrv_pull_cycle_handler_creq(struct composite_context *creq);
    572 static void wreplsrv_pull_cycle_handler_req(struct wrepl_request *req);
     579static void wreplsrv_pull_cycle_handler_treq(struct tevent_req *subreq);
    573580
    574581static NTSTATUS wreplsrv_pull_cycle_next_owner_do_work(struct wreplsrv_pull_cycle_state *state)
     
    648655                state->assoc_stop_io.in.assoc_ctx       = state->io->in.wreplconn->assoc_ctx.peer_ctx;
    649656                state->assoc_stop_io.in.reason          = 0;
    650                 state->req = wrepl_associate_stop_send(state->io->in.wreplconn->sock, &state->assoc_stop_io);
    651                 NT_STATUS_HAVE_NO_MEMORY(state->req);
    652 
    653                 state->req->async.fn            = wreplsrv_pull_cycle_handler_req;
    654                 state->req->async.private_data  = state;
     657                state->subreq = wrepl_associate_stop_send(state,
     658                                                          state->io->in.wreplconn->service->task->event_ctx,
     659                                                          state->io->in.wreplconn->sock,
     660                                                          &state->assoc_stop_io);
     661                NT_STATUS_HAVE_NO_MEMORY(state->subreq);
     662
     663                tevent_req_set_callback(state->subreq,
     664                                        wreplsrv_pull_cycle_handler_treq,
     665                                        state);
    655666
    656667                state->stage = WREPLSRV_PULL_CYCLE_STAGE_WAIT_STOP_ASSOC;
     
    725736        NTSTATUS status;
    726737
    727         status = wrepl_associate_stop_recv(state->req, &state->assoc_stop_io);
     738        status = wrepl_associate_stop_recv(state->subreq, &state->assoc_stop_io);
     739        TALLOC_FREE(state->subreq);
    728740        NT_STATUS_NOT_OK_RETURN(status);
    729741
     
    772784}
    773785
    774 static void wreplsrv_pull_cycle_handler_req(struct wrepl_request *req)
    775 {
    776         struct wreplsrv_pull_cycle_state *state = talloc_get_type(req->async.private_data,
     786static void wreplsrv_pull_cycle_handler_treq(struct tevent_req *subreq)
     787{
     788        struct wreplsrv_pull_cycle_state *state = tevent_req_callback_data(subreq,
    777789                                                  struct wreplsrv_pull_cycle_state);
    778790        wreplsrv_pull_cycle_handler(state);
     
    826838enum wreplsrv_push_notify_stage {
    827839        WREPLSRV_PUSH_NOTIFY_STAGE_WAIT_CONNECT,
     840        WREPLSRV_PUSH_NOTIFY_STAGE_WAIT_UPDATE,
    828841        WREPLSRV_PUSH_NOTIFY_STAGE_WAIT_INFORM,
    829842        WREPLSRV_PUSH_NOTIFY_STAGE_DONE
     
    837850        bool full_table;
    838851        struct wrepl_send_ctrl ctrl;
    839         struct wrepl_request *req;
    840852        struct wrepl_packet req_packet;
    841853        struct wrepl_packet *rep_packet;
    842854        struct composite_context *creq;
    843855        struct wreplsrv_out_connection *wreplconn;
     856        struct tevent_req *subreq;
    844857};
    845858
    846859static void wreplsrv_push_notify_handler_creq(struct composite_context *creq);
    847 static void wreplsrv_push_notify_handler_req(struct wrepl_request *req);
     860static void wreplsrv_push_notify_handler_treq(struct tevent_req *subreq);
    848861
    849862static NTSTATUS wreplsrv_push_notify_update(struct wreplsrv_push_notify_state *state)
     
    853866        struct wrepl_replication *repl_out = &state->req_packet.message.replication;
    854867        struct wrepl_table *table_out = &state->req_packet.message.replication.info.table;
    855         struct wreplsrv_in_connection *wrepl_in;
    856         NTSTATUS status;
    857         struct socket_context *sock;
    858         struct packet_context *packet;
    859         uint16_t fde_flags;
     868        NTSTATUS status;
    860869
    861870        /* prepare the outgoing request */
     
    871880
    872881        /* queue the request */
    873         state->req = wrepl_request_send(state->wreplconn->sock, req, NULL);
    874         NT_STATUS_HAVE_NO_MEMORY(state->req);
    875 
    876         /*
    877          * now we need to convert the wrepl_socket (client connection)
    878          * into a wreplsrv_in_connection (server connection), because
    879          * we'll act as a server on this connection after the WREPL_REPL_UPDATE*
    880          * message is received by the peer.
    881          */
    882 
    883         /* steal the socket_context */
    884         sock = state->wreplconn->sock->sock;
    885         state->wreplconn->sock->sock = NULL;
    886         talloc_steal(state, sock);
    887 
    888         /*
    889          * steal the packet_context
    890          * note the request DATA_BLOB we just send on the
    891          * wrepl_socket (client connection) is still unter the
    892          * packet context and will be send to the wire
    893          */
    894         packet = state->wreplconn->sock->packet;
    895         state->wreplconn->sock->packet = NULL;
    896         talloc_steal(state, packet);
    897 
    898         /*
    899          * get the fde_flags of the old fde event,
    900          * so that we can later set the same flags to the new one
    901          */
    902         fde_flags = event_get_fd_flags(state->wreplconn->sock->event.fde);
    903 
    904         /*
    905          * free the wrepl_socket (client connection)
    906          */
    907         talloc_free(state->wreplconn->sock);
    908         state->wreplconn->sock = NULL;
    909 
    910         /*
    911          * now create a wreplsrv_in_connection,
    912          * on which we act as server
    913          *
    914          * NOTE: sock and packet will be stolen by
    915          *       wreplsrv_in_connection_merge()
    916          */
    917         status = wreplsrv_in_connection_merge(state->io->in.partner,
    918                                               sock, packet, &wrepl_in);
    919         NT_STATUS_NOT_OK_RETURN(status);
    920 
    921         event_set_fd_flags(wrepl_in->conn->event.fde, fde_flags);
    922 
    923         wrepl_in->assoc_ctx.peer_ctx    = state->wreplconn->assoc_ctx.peer_ctx;
    924         wrepl_in->assoc_ctx.our_ctx     = 0;
    925 
    926         /* now we can free the wreplsrv_out_connection */
    927         talloc_free(state->wreplconn);
    928         state->wreplconn = NULL;
    929 
    930         state->stage = WREPLSRV_PUSH_NOTIFY_STAGE_DONE;
     882        state->subreq = wrepl_request_send(state,
     883                                           state->wreplconn->service->task->event_ctx,
     884                                           state->wreplconn->sock, req, NULL);
     885        NT_STATUS_HAVE_NO_MEMORY(state->subreq);
     886
     887        tevent_req_set_callback(state->subreq,
     888                                wreplsrv_push_notify_handler_treq,
     889                                state);
     890
     891        state->stage = WREPLSRV_PUSH_NOTIFY_STAGE_WAIT_UPDATE;
    931892
    932893        return NT_STATUS_OK;
     
    954915        state->ctrl.send_only           = true;
    955916
    956         state->req = wrepl_request_send(state->wreplconn->sock, req, &state->ctrl);
    957         NT_STATUS_HAVE_NO_MEMORY(state->req);
    958 
    959         state->req->async.fn            = wreplsrv_push_notify_handler_req;
    960         state->req->async.private_data  = state;
     917        state->subreq = wrepl_request_send(state,
     918                                           state->wreplconn->service->task->event_ctx,
     919                                           state->wreplconn->sock, req, &state->ctrl);
     920        NT_STATUS_HAVE_NO_MEMORY(state->subreq);
     921
     922        tevent_req_set_callback(state->subreq,
     923                                wreplsrv_push_notify_handler_treq,
     924                                state);
    961925
    962926        state->stage = WREPLSRV_PUSH_NOTIFY_STAGE_WAIT_INFORM;
     
    1004968                return NT_STATUS_INTERNAL_ERROR;
    1005969        }
    1006 
    1007         return NT_STATUS_INTERNAL_ERROR;
     970}
     971
     972static NTSTATUS wreplsrv_push_notify_wait_update(struct wreplsrv_push_notify_state *state)
     973{
     974        struct wreplsrv_in_connection *wrepl_in;
     975        struct tstream_context *stream;
     976        NTSTATUS status;
     977
     978        status = wrepl_request_recv(state->subreq, state, NULL);
     979        TALLOC_FREE(state->subreq);
     980        NT_STATUS_NOT_OK_RETURN(status);
     981
     982        /*
     983         * now we need to convert the wrepl_socket (client connection)
     984         * into a wreplsrv_in_connection (server connection), because
     985         * we'll act as a server on this connection after the WREPL_REPL_UPDATE*
     986         * message is received by the peer.
     987         */
     988
     989        status = wrepl_socket_split_stream(state->wreplconn->sock, state, &stream);
     990        NT_STATUS_NOT_OK_RETURN(status);
     991
     992        /*
     993         * now create a wreplsrv_in_connection,
     994         * on which we act as server
     995         *
     996         * NOTE: stream will be stolen by
     997         *       wreplsrv_in_connection_merge()
     998         */
     999        status = wreplsrv_in_connection_merge(state->io->in.partner,
     1000                                              state->wreplconn->assoc_ctx.peer_ctx,
     1001                                              &stream,
     1002                                              &wrepl_in);
     1003        NT_STATUS_NOT_OK_RETURN(status);
     1004
     1005        /* now we can free the wreplsrv_out_connection */
     1006        TALLOC_FREE(state->wreplconn);
     1007
     1008        state->stage = WREPLSRV_PUSH_NOTIFY_STAGE_DONE;
     1009        return NT_STATUS_OK;
    10081010}
    10091011
     
    10121014        NTSTATUS status;
    10131015
    1014         status =  wrepl_request_recv(state->req, state, NULL);
     1016        status = wrepl_request_recv(state->subreq, state, NULL);
     1017        TALLOC_FREE(state->subreq);
    10151018        NT_STATUS_NOT_OK_RETURN(status);
    10161019
     
    10261029        case WREPLSRV_PUSH_NOTIFY_STAGE_WAIT_CONNECT:
    10271030                c->status = wreplsrv_push_notify_wait_connect(state);
     1031                break;
     1032        case WREPLSRV_PUSH_NOTIFY_STAGE_WAIT_UPDATE:
     1033                c->status = wreplsrv_push_notify_wait_update(state);
    10281034                break;
    10291035        case WREPLSRV_PUSH_NOTIFY_STAGE_WAIT_INFORM:
     
    10551061}
    10561062
    1057 static void wreplsrv_push_notify_handler_req(struct wrepl_request *req)
    1058 {
    1059         struct wreplsrv_push_notify_state *state = talloc_get_type(req->async.private_data,
     1063static void wreplsrv_push_notify_handler_treq(struct tevent_req *subreq)
     1064{
     1065        struct wreplsrv_push_notify_state *state = tevent_req_callback_data(subreq,
    10601066                                                   struct wreplsrv_push_notify_state);
    10611067        wreplsrv_push_notify_handler(state);
  • vendor/current/source4/wrepl_server/wrepl_scavenging.c

    r414 r740  
    2424#include "wrepl_server/wrepl_server.h"
    2525#include "nbt_server/wins/winsdb.h"
    26 #include "ldb/include/ldb.h"
    27 #include "ldb/include/ldb_errors.h"
     26#include <ldb.h>
     27#include <ldb_errors.h>
    2828#include "system/time.h"
    2929#include "smbd/service_task.h"
    3030#include "lib/messaging/irpc.h"
    31 #include "librpc/gen_ndr/ndr_irpc.h"
     31#include "librpc/gen_ndr/ndr_irpc_c.h"
    3232#include "librpc/gen_ndr/ndr_nbt.h"
    3333#include "param/param.h"
     
    5353        const char *owner_filter;
    5454        const char *filter;
    55         uint32_t i;
     55        unsigned int i;
    5656        int ret;
    5757        time_t now = time(NULL);
     
    6666        struct timeval tombstone_extra_time;
    6767        const char *local_owner = service->wins_db->local_owner;
    68         bool propagate = lp_parm_bool(service->task->lp_ctx, NULL, "wreplsrv", "propagate name releases", false);
     68        bool propagate = lpcfg_parm_bool(service->task->lp_ctx, NULL, "wreplsrv", "propagate name releases", false);
    6969
    7070        now_timestr = ldb_timestring(tmp_mem, now);
     
    207207        const char *owner_filter;
    208208        const char *filter;
    209         uint32_t i;
     209        unsigned int i;
    210210        int ret;
    211211        time_t now = time(NULL);
     
    313313};
    314314
    315 static void verify_handler(struct irpc_request *ireq)
     315static void verify_handler(struct tevent_req *subreq)
    316316{
    317         struct verify_state *s = talloc_get_type(ireq->async.private_data,
    318                                  struct verify_state);
     317        struct verify_state *s =
     318                tevent_req_callback_data(subreq,
     319                struct verify_state);
    319320        struct winsdb_record *rec = s->rec;
    320321        const char *action;
     
    337338         * - if an error happens do nothing
    338339         */
    339         status = irpc_call_recv(ireq);
     340        status = dcerpc_nbtd_proxy_wins_challenge_r_recv(subreq, s);
     341        TALLOC_FREE(subreq);
    340342        if (NT_STATUS_EQUAL(NT_STATUS_OBJECT_NAME_NOT_FOUND, status)) {
    341343                delete_record = true;
     
    422424        const char *owner_filter;
    423425        const char *filter;
    424         uint32_t i;
     426        unsigned int i;
    425427        int ret;
    426428        time_t now = time(NULL);
    427429        const char *now_timestr;
    428         struct irpc_request *ireq;
     430        struct tevent_req *subreq;
    429431        struct verify_state *s;
    430         struct server_id *nbt_servers;
    431 
    432         nbt_servers = irpc_servers_byname(service->task->msg_ctx, tmp_mem, "nbt_server");
    433         if ((nbt_servers == NULL) || (nbt_servers[0].id == 0)) {
    434                 return NT_STATUS_INTERNAL_ERROR;
    435         }
     432        struct dcerpc_binding_handle *irpc_handle;
    436433
    437434        now_timestr = ldb_timestring(tmp_mem, now);
     
    490487                s->r.in.addrs[0].addr   = rec->wins_owner;
    491488
    492                 ireq = IRPC_CALL_SEND(s->msg_ctx, nbt_servers[0],
    493                                       irpc, NBTD_PROXY_WINS_CHALLENGE,
    494                                       &s->r, s);
    495                 NT_STATUS_HAVE_NO_MEMORY(ireq);
    496 
    497                 ireq->async.fn          = verify_handler;
    498                 ireq->async.private_data= s;
     489                irpc_handle = irpc_binding_handle_by_name(s,
     490                                                          service->task->msg_ctx,
     491                                                          "nbt_server",
     492                                                          &ndr_table_irpc);
     493                if (irpc_handle == NULL) {
     494                        return NT_STATUS_INTERNAL_ERROR;
     495                }
     496
     497                subreq = dcerpc_nbtd_proxy_wins_challenge_r_send(s,
     498                                                                 service->task->event_ctx,
     499                                                                 irpc_handle,
     500                                                                 &s->r);
     501                NT_STATUS_HAVE_NO_MEMORY(subreq);
     502
     503                tevent_req_set_callback(subreq, verify_handler, s);
    499504
    500505                talloc_steal(service, s);
  • vendor/current/source4/wrepl_server/wrepl_server.c

    r414 r740  
    2828#include "wrepl_server/wrepl_server.h"
    2929#include "nbt_server/wins/winsdb.h"
    30 #include "ldb/include/ldb.h"
    31 #include "ldb/include/ldb_errors.h"
     30#include <ldb.h>
     31#include <ldb_errors.h>
    3232#include "auth/auth.h"
    3333#include "ldb_wrap.h"
     
    3939                                                  struct loadparm_context *lp_ctx)
    4040{
    41         return ldb_wrap_connect(mem_ctx, ev_ctx, lp_ctx, private_path(mem_ctx, 
    42                                 lp_ctx, lp_wins_config_url(lp_ctx)),
    43                                 system_session(mem_ctx, lp_ctx), NULL, 0, NULL);
     41        return ldb_wrap_connect(mem_ctx, ev_ctx, lp_ctx, private_path(mem_ctx,
     42                                lp_ctx, lpcfg_wins_config_url(lp_ctx)),
     43                                system_session(lp_ctx), NULL, 0);
    4444}
    4545
     
    7575                                     struct loadparm_context *lp_ctx)
    7676{
    77         const char *owner = lp_parm_string(lp_ctx, NULL, "winsdb", "local_owner");
     77        const char *owner = lpcfg_parm_string(lp_ctx, NULL, "winsdb", "local_owner");
    7878
    7979        if (owner == NULL) {
    8080                struct interface *ifaces;
    81                 load_interfaces(service, lp_interfaces(lp_ctx), &ifaces);
     81                load_interfaces(service, lpcfg_interfaces(lp_ctx), &ifaces);
    8282                owner = iface_n_ip(ifaces, 0);
    8383        }
     
    9494
    9595        /* the default renew interval is 6 days */
    96         service->config.renew_interval    = lp_parm_int(lp_ctx, NULL,"wreplsrv","renew_interval", 6*24*60*60);
     96        service->config.renew_interval    = lpcfg_parm_int(lp_ctx, NULL,"wreplsrv","renew_interval", 6*24*60*60);
    9797
    9898        /* the default tombstone (extinction) interval is 6 days */
    99         service->config.tombstone_interval= lp_parm_int(lp_ctx, NULL,"wreplsrv","tombstone_interval", 6*24*60*60);
     99        service->config.tombstone_interval= lpcfg_parm_int(lp_ctx, NULL,"wreplsrv","tombstone_interval", 6*24*60*60);
    100100
    101101        /* the default tombstone (extinction) timeout is 1 day */
    102         service->config.tombstone_timeout = lp_parm_int(lp_ctx, NULL,"wreplsrv","tombstone_timeout", 1*24*60*60);
     102        service->config.tombstone_timeout = lpcfg_parm_int(lp_ctx, NULL,"wreplsrv","tombstone_timeout", 1*24*60*60);
    103103
    104104        /* the default tombstone extra timeout is 3 days */
    105         service->config.tombstone_extra_timeout = lp_parm_int(lp_ctx, NULL,"wreplsrv","tombstone_extra_timeout", 3*24*60*60);
     105        service->config.tombstone_extra_timeout = lpcfg_parm_int(lp_ctx, NULL,"wreplsrv","tombstone_extra_timeout", 3*24*60*60);
    106106
    107107        /* the default verify interval is 24 days */
    108         service->config.verify_interval   = lp_parm_int(lp_ctx, NULL,"wreplsrv","verify_interval", 24*24*60*60);
     108        service->config.verify_interval   = lpcfg_parm_int(lp_ctx, NULL,"wreplsrv","verify_interval", 24*24*60*60);
    109109
    110110        /* the default scavenging interval is 'renew_interval/2' */
    111         service->config.scavenging_interval=lp_parm_int(lp_ctx, NULL,"wreplsrv","scavenging_interval",
     111        service->config.scavenging_interval=lpcfg_parm_int(lp_ctx, NULL,"wreplsrv","scavenging_interval",
    112112                                                        service->config.renew_interval/2);
    113113
    114114        /* the maximun interval to the next periodic processing event */
    115         service->config.periodic_interval = lp_parm_int(lp_ctx, NULL,"wreplsrv","periodic_interval", 15);
     115        service->config.periodic_interval = lpcfg_parm_int(lp_ctx, NULL,"wreplsrv","periodic_interval", 15);
    116116
    117117        return NT_STATUS_OK;
     
    140140        int ret;
    141141        TALLOC_CTX *tmp_ctx;
    142         int i;
     142        unsigned int i;
    143143        uint64_t new_seqnumber;
    144144
     
    364364        TALLOC_CTX *tmp_ctx = talloc_new(service);
    365365        struct ldb_context *ldb = service->wins_db->ldb;
    366         int i;
     366        unsigned int i;
    367367        struct wreplsrv_owner *local_owner;
    368368        const char *wins_owner;
     
    452452        struct wreplsrv_service *service;
    453453
    454         if (!lp_wins_support(task->lp_ctx)) {
     454        if (!lpcfg_wins_support(task->lp_ctx)) {
    455455                return;
    456456        }
     
    486486
    487487        /*
    488          * setup listen sockets, so we can anwser requests from our partners,
     488         * setup listen sockets, so we can answer requests from our partners,
    489489         * which pull from us
    490490         */
  • vendor/current/source4/wrepl_server/wrepl_server.h

    r414 r740  
    1919   along with this program.  If not, see <http://www.gnu.org/licenses/>.
    2020*/
     21
     22#include "system/network.h"
    2123
    2224struct wreplsrv_service;
     
    3638        struct wrepl_packet rep_packet;
    3739        bool terminate_after_send;
     40
     41        DATA_BLOB in;
     42        DATA_BLOB out;
     43        struct iovec out_iov[1];
    3844};
    3945
     
    4450        struct wreplsrv_in_connection *prev,*next;
    4551        struct stream_connection *conn;
    46         struct packet_context *packet;
     52        struct tstream_context *tstream;
     53        struct tevent_queue *send_queue;
    4754
    4855        /* our global service context */
Note: See TracChangeset for help on using the changeset viewer.