Ignore:
Timestamp:
Nov 25, 2016, 8:04:54 PM (9 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to version 4.4.7

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source3/nmbd/nmbd_packets.c

    r988 r989  
    16841684        enum packet_type type;
    16851685        bool broadcast;
     1686        int fd;
     1687        bool triggered;
    16861688};
    16871689
    1688 static bool create_listen_pollfds(struct pollfd **pfds,
    1689                                   struct socket_attributes **pattrs,
     1690static bool create_listen_array(struct socket_attributes **pattrs,
    16901691                                  int *pnum_sockets)
    16911692{
     
    16931694        int count = 0;
    16941695        int num = 0;
    1695         struct pollfd *fds;
    16961696        struct socket_attributes *attrs;
    16971697
     
    17171717        }
    17181718
    1719         fds = talloc_zero_array(NULL, struct pollfd, count);
    1720         if (fds == NULL) {
    1721                 DEBUG(1, ("create_listen_pollfds: malloc fail for fds. "
     1719        attrs = talloc_zero_array(NULL, struct socket_attributes, count);
     1720        if (attrs == NULL) {
     1721                DEBUG(1, ("talloc fail for attrs. "
    17221722                          "size %d\n", count));
    17231723                return true;
    17241724        }
    17251725
    1726         attrs = talloc_array(NULL, struct socket_attributes, count);
    1727         if (fds == NULL) {
    1728                 DEBUG(1, ("create_listen_pollfds: malloc fail for attrs. "
    1729                           "size %d\n", count));
    1730                 TALLOC_FREE(fds);
    1731                 return true;
    1732         }
    1733 
    17341726        num = 0;
    17351727
    1736         fds[num].fd = ClientNMB;
     1728        attrs[num].fd = ClientNMB;
    17371729        attrs[num].type = NMB_PACKET;
    17381730        attrs[num].broadcast = false;
    17391731        num += 1;
    17401732
    1741         fds[num].fd = ClientDGRAM;
     1733        attrs[num].fd = ClientDGRAM;
    17421734        attrs[num].type = DGRAM_PACKET;
    17431735        attrs[num].broadcast = false;
     
    17471739
    17481740                if (subrec->nmb_sock != -1) {
    1749                         fds[num].fd = subrec->nmb_sock;
     1741                        attrs[num].fd = subrec->nmb_sock;
    17501742                        attrs[num].type = NMB_PACKET;
    17511743                        attrs[num].broadcast = false;
     
    17541746
    17551747                if (subrec->nmb_bcast != -1) {
    1756                         fds[num].fd = subrec->nmb_bcast;
     1748                        attrs[num].fd = subrec->nmb_bcast;
    17571749                        attrs[num].type = NMB_PACKET;
    17581750                        attrs[num].broadcast = true;
     
    17611753
    17621754                if (subrec->dgram_sock != -1) {
    1763                         fds[num].fd = subrec->dgram_sock;
     1755                        attrs[num].fd = subrec->dgram_sock;
    17641756                        attrs[num].type = DGRAM_PACKET;
    17651757                        attrs[num].broadcast = false;
     
    17681760
    17691761                if (subrec->dgram_bcast != -1) {
    1770                         fds[num].fd = subrec->dgram_bcast;
     1762                        attrs[num].fd = subrec->dgram_bcast;
    17711763                        attrs[num].type = DGRAM_PACKET;
    17721764                        attrs[num].broadcast = true;
     
    17741766                }
    17751767        }
    1776 
    1777         TALLOC_FREE(*pfds);
    1778         *pfds = fds;
    17791768
    17801769        TALLOC_FREE(*pattrs);
     
    18651854
    18661855/****************************************************************************
     1856 Timeout callback - just notice we timed out.
     1857***************************************************************************/
     1858
     1859static void nmbd_timeout_handler(struct tevent_context *ev,
     1860                        struct tevent_timer *te,
     1861                        struct timeval current_time,
     1862                        void *private_data)
     1863{
     1864        bool *got_timeout = private_data;
     1865        *got_timeout = true;
     1866}
     1867
     1868/****************************************************************************
     1869 fd callback - remember the fd that triggered.
     1870***************************************************************************/
     1871
     1872static void nmbd_fd_handler(struct tevent_context *ev,
     1873                                struct tevent_fd *fde,
     1874                                uint16_t flags,
     1875                                void *private_data)
     1876{
     1877        struct socket_attributes *attr = private_data;
     1878        attr->triggered = true;
     1879}
     1880
     1881/****************************************************************************
    18671882  Listens for NMB or DGRAM packets, and queues them.
    18681883  return True if the socket is dead
     
    18711886bool listen_for_packets(struct messaging_context *msg, bool run_election)
    18721887{
    1873         static struct pollfd *fds = NULL;
    18741888        static struct socket_attributes *attrs = NULL;
    18751889        static int listen_number = 0;
    18761890        int num_sockets;
    18771891        int i;
    1878 
    1879         int pollrtn;
    1880         int timeout;
     1892        int loop_rtn;
     1893        int timeout_secs;
     1894
    18811895#ifndef SYNC_DNS
    18821896        int dns_fd;
     
    18841898#endif
    18851899        struct processed_packet *processed_packet_list = NULL;
    1886 
    1887         if ((fds == NULL) || rescan_listen_set) {
    1888                 if (create_listen_pollfds(&fds, &attrs, &listen_number)) {
     1900        struct tevent_timer *te = NULL;
     1901        bool got_timeout = false;
     1902        TALLOC_CTX *frame = talloc_stackframe();
     1903
     1904        if ((attrs == NULL) || rescan_listen_set) {
     1905                if (create_listen_array(&attrs, &listen_number)) {
    18891906                        DEBUG(0,("listen_for_packets: Fatal error. unable to create listen set. Exiting.\n"));
     1907                        TALLOC_FREE(frame);
    18901908                        return True;
    18911909                }
     
    18931911        }
    18941912
    1895         /*
    1896          * "fds" can be enlarged by event_add_to_poll_args
    1897          * below. Shrink it again to what was given to us by
    1898          * create_listen_pollfds.
    1899          */
    1900 
    1901         fds = talloc_realloc(NULL, fds, struct pollfd, listen_number);
    1902         if (fds == NULL) {
    1903                 return true;
    1904         }
    19051913        num_sockets = listen_number;
    19061914
     
    19081916        dns_fd = asyncdns_fd();
    19091917        if (dns_fd != -1) {
    1910                 fds = talloc_realloc(NULL, fds, struct pollfd, num_sockets+1);
    1911                 if (fds == NULL) {
     1918                attrs = talloc_realloc(NULL,
     1919                                        attrs,
     1920                                        struct socket_attributes,
     1921                                        num_sockets + 1);
     1922                if (attrs == NULL) {
     1923                        TALLOC_FREE(frame);
    19121924                        return true;
    19131925                }
    19141926                dns_pollidx = num_sockets;
    1915                 fds[num_sockets].fd = dns_fd;
     1927                attrs[dns_pollidx].fd = dns_fd;
     1928                /*
     1929                 * dummy values, we only need
     1930                 * fd and triggered.
     1931                 */
     1932                attrs[dns_pollidx].type = NMB_PACKET;
     1933                attrs[dns_pollidx].broadcast = false;
    19161934                num_sockets += 1;
    19171935        }
     
    19191937
    19201938        for (i=0; i<num_sockets; i++) {
    1921                 fds[i].events = POLLIN|POLLHUP;
    1922         }
    1923 
    1924         /* Process a signal and timer events now... */
    1925         if (run_events_poll(nmbd_event_context(), 0, NULL, 0)) {
    1926                 return False;
     1939                struct tevent_fd *tfd = tevent_add_fd(nmbd_event_context(),
     1940                                                        frame,
     1941                                                        attrs[i].fd,
     1942                                                        TEVENT_FD_READ,
     1943                                                        nmbd_fd_handler,
     1944                                                        &attrs[i]);
     1945                if (tfd == NULL) {
     1946                        TALLOC_FREE(frame);
     1947                        return true;
     1948                }
     1949                attrs[i].triggered = false;
    19271950        }
    19281951
     
    19341957         */
    19351958
    1936         timeout = ((run_election||num_response_packets)
    1937                    ? 1 : NMBD_SELECT_LOOP) * 1000;
    1938 
    1939         event_add_to_poll_args(nmbd_event_context(), NULL,
    1940                                &fds, &num_sockets, &timeout);
    1941 
    1942         pollrtn = poll(fds, num_sockets, timeout);
    1943 
    1944         if (run_events_poll(nmbd_event_context(), pollrtn, fds, num_sockets)) {
    1945                 return False;
    1946         }
    1947 
    1948         if (pollrtn == -1) {
    1949                 return False;
     1959        if (run_election||num_response_packets) {
     1960                timeout_secs = 1;
     1961        } else {
     1962                timeout_secs = NMBD_SELECT_LOOP;
     1963        }
     1964
     1965        te = tevent_add_timer(nmbd_event_context(),
     1966                                frame,
     1967                                tevent_timeval_current_ofs(timeout_secs, 0),
     1968                                nmbd_timeout_handler,
     1969                                &got_timeout);
     1970        if (te == NULL) {
     1971                TALLOC_FREE(frame);
     1972                return true;
     1973        }
     1974
     1975        loop_rtn = tevent_loop_once(nmbd_event_context());
     1976
     1977        if (loop_rtn == -1) {
     1978                TALLOC_FREE(frame);
     1979                return true;
     1980        }
     1981
     1982        if (got_timeout) {
     1983                TALLOC_FREE(frame);
     1984                return false;
    19501985        }
    19511986
    19521987#ifndef SYNC_DNS
    19531988        if ((dns_fd != -1) && (dns_pollidx != -1) &&
    1954             (fds[dns_pollidx].revents & (POLLIN|POLLHUP|POLLERR))) {
     1989            attrs[dns_pollidx].triggered){
    19551990                run_dns_queue(msg);
     1991                TALLOC_FREE(frame);
     1992                return false;
    19561993        }
    19571994#endif
     
    19642001                int client_port;
    19652002
    1966                 if ((fds[i].revents & (POLLIN|POLLHUP|POLLERR)) == 0) {
     2003                if (!attrs[i].triggered) {
    19672004                        continue;
    19682005                }
     
    19822019                }
    19832020
    1984                 packet = read_packet(fds[i].fd, packet_type);
     2021                packet = read_packet(attrs[i].fd, packet_type);
    19852022                if (!packet) {
    19862023                        continue;
     
    19922029                 */
    19932030                if (lp_bind_interfaces_only() &&
    1994                     (fds[i].fd == client_fd) &&
     2031                    (attrs[i].fd == client_fd) &&
    19952032                    (!is_local_net_v4(packet->ip))) {
    19962033                        DEBUG(7,("discarding %s packet sent to broadcast socket from %s:%d\n",
     
    20312068                if (attrs[i].broadcast) {
    20322069                        /* this is a broadcast socket */
    2033                         packet->send_fd = fds[i-1].fd;
     2070                        packet->send_fd = attrs[i-1].fd;
    20342071                } else {
    20352072                        /* this is already a unicast socket */
    2036                         packet->send_fd = fds[i].fd;
     2073                        packet->send_fd = attrs[i].fd;
    20372074                }
    20382075
     
    20412078
    20422079        free_processed_packet_list(&processed_packet_list);
     2080        TALLOC_FREE(frame);
    20432081        return False;
    20442082}
Note: See TracChangeset for help on using the changeset viewer.