Ignore:
Timestamp:
Nov 24, 2016, 1:14:11 PM (9 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to version 4.4.3

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source3/lib/addrchange.c

    r740 r988  
    2626#include "linux/netlink.h"
    2727#include "linux/rtnetlink.h"
    28 #include "lib/async_req/async_sock.h"
     28#include "lib/tsocket/tsocket.h"
    2929
    3030struct addrchange_context {
    31         int sock;
     31        struct tdgram_context *sock;
    3232};
    33 
    34 static int addrchange_context_destructor(struct addrchange_context *c);
    3533
    3634NTSTATUS addrchange_context_create(TALLOC_CTX *mem_ctx,
     
    4038        struct sockaddr_nl addr;
    4139        NTSTATUS status;
     40        int sock = -1;
    4241        int res;
     42        bool ok;
    4343
    4444        ctx = talloc(mem_ctx, struct addrchange_context);
     
    4747        }
    4848
    49         ctx->sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
    50         if (ctx->sock == -1) {
    51                 status = map_nt_error_from_unix(errno);
    52                 goto fail;
    53         }
    54         talloc_set_destructor(ctx, addrchange_context_destructor);
     49        sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
     50        if (sock == -1) {
     51                status = map_nt_error_from_unix(errno);
     52                goto fail;
     53        }
     54
     55        ok = smb_set_close_on_exec(sock);
     56        if (!ok) {
     57                status = map_nt_error_from_unix(errno);
     58                goto fail;
     59        }
     60
     61        res = set_blocking(sock, false);
     62        if (res == -1) {
     63                status = map_nt_error_from_unix(errno);
     64                goto fail;
     65        }
    5566
    5667        /*
     
    6172        addr.nl_groups = RTMGRP_IPV6_IFADDR | RTMGRP_IPV4_IFADDR;
    6273
    63         res = bind(ctx->sock, (struct sockaddr *)(void *)&addr, sizeof(addr));
     74        res = bind(sock, (struct sockaddr *)(void *)&addr, sizeof(addr));
     75        if (res == -1) {
     76                status = map_nt_error_from_unix(errno);
     77                goto fail;
     78        }
     79
     80        res = tdgram_bsd_existing_socket(ctx, sock, &ctx->sock);
    6481        if (res == -1) {
    6582                status = map_nt_error_from_unix(errno);
     
    7087        return NT_STATUS_OK;
    7188fail:
     89        if (sock != -1) {
     90                close(sock);
     91        }
    7292        TALLOC_FREE(ctx);
    7393        return status;
    74 }
    75 
    76 static int addrchange_context_destructor(struct addrchange_context *c)
    77 {
    78         if (c->sock != -1) {
    79                 close(c->sock);
    80                 c->sock = -1;
    81         }
    82         return 0;
    8394}
    8495
     
    8697        struct tevent_context *ev;
    8798        struct addrchange_context *ctx;
    88         uint8_t buf[8192];
    89         struct sockaddr_storage fromaddr;
    90         socklen_t fromaddr_len;
     99        uint8_t *buf;
     100        struct tsocket_address *fromaddr;
    91101
    92102        enum addrchange_type type;
     
    110120        state->ctx = ctx;
    111121
    112         state->fromaddr_len = sizeof(state->fromaddr);
    113         subreq = recvfrom_send(state, state->ev, state->ctx->sock,
    114                                state->buf, sizeof(state->buf), 0,
    115                                &state->fromaddr, &state->fromaddr_len);
     122        subreq = tdgram_recvfrom_send(state, state->ev, state->ctx->sock);
    116123        if (tevent_req_nomem(subreq, req)) {
    117124                return tevent_req_post(req, state->ev);
     
    127134        struct addrchange_state *state = tevent_req_data(
    128135                req, struct addrchange_state);
    129         struct sockaddr_nl *addr;
     136        union {
     137                struct sockaddr sa;
     138                struct sockaddr_nl nl;
     139                struct sockaddr_storage ss;
     140        } fromaddr;
    130141        struct nlmsghdr *h;
    131142        struct ifaddrmsg *ifa;
     
    136147        bool found;
    137148
    138         received = recvfrom_recv(subreq, &err);
     149        received = tdgram_recvfrom_recv(subreq, &err, state,
     150                                        &state->buf,
     151                                        &state->fromaddr);
    139152        TALLOC_FREE(subreq);
    140153        if (received == -1) {
    141                 DEBUG(10, ("recvfrom returned %s\n", strerror(errno)));
     154                DEBUG(10, ("tdgram_recvfrom_recv returned %s\n", strerror(err)));
    142155                tevent_req_nterror(req, map_nt_error_from_unix(err));
    143156                return;
    144157        }
    145         if ((state->fromaddr_len != sizeof(struct sockaddr_nl))
    146             || (state->fromaddr.ss_family != AF_NETLINK)) {
     158        len = tsocket_address_bsd_sockaddr(state->fromaddr,
     159                                           &fromaddr.sa,
     160                                           sizeof(fromaddr));
     161
     162        if ((len != sizeof(fromaddr.nl) ||
     163            fromaddr.sa.sa_family != AF_NETLINK))
     164        {
    147165                DEBUG(10, ("Got message from wrong addr\n"));
    148166                goto retry;
    149167        }
    150168
    151         addr = (struct sockaddr_nl *)(void *)&state->addr;
    152         if (addr->nl_pid != 0) {
     169        if (fromaddr.nl.nl_pid != 0) {
    153170                DEBUG(10, ("Got msg from pid %d, not from the kernel\n",
    154                            (int)addr->nl_pid));
     171                           (int)fromaddr.nl.nl_pid));
    155172                goto retry;
    156173        }
     
    247264
    248265retry:
    249         state->fromaddr_len = sizeof(state->fromaddr);
    250         subreq = recvfrom_send(state, state->ev, state->ctx->sock,
    251                                state->buf, sizeof(state->buf), 0,
    252                                &state->fromaddr, &state->fromaddr_len);
     266        TALLOC_FREE(state->buf);
     267        TALLOC_FREE(state->fromaddr);
     268
     269        subreq = tdgram_recvfrom_send(state, state->ev, state->ctx->sock);
    253270        if (tevent_req_nomem(subreq, req)) {
    254271                return;
     
    265282
    266283        if (tevent_req_is_nterror(req, &status)) {
     284                tevent_req_received(req);
    267285                return status;
    268286        }
     
    270288        *type = state->type;
    271289        *addr = state->addr;
     290        tevent_req_received(req);
    272291        return NT_STATUS_OK;
    273292}
Note: See TracChangeset for help on using the changeset viewer.