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

Samba Server: updated trunk to 3.6.0

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

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/lib/tsocket/tsocket.c

    r414 r745  
    4747                return -1;
    4848        default:
    49                 *perrno = EIO;
    50                 return -1;
     49                break;
    5150        }
    5251
  • trunk/server/lib/tsocket/tsocket.h

    r480 r745  
    8484
    8585/**
    86  * @brief Get a string representaion of the endpoint.
     86 * @brief Get a string representation of the endpoint.
    8787 *
    8888 * This function creates a string representation of the endpoint for debugging.
     
    102102 * @return              The address as a string representation, NULL on error.
    103103 *
     104 * @see tsocket_address_is_inet()
    104105 * @see tsocket_address_inet_addr_string()
    105106 * @see tsocket_address_inet_port()
     
    486487 * @{
    487488 */
     489
     490/**
     491 * @brief Find out if the tsocket_address represents an ipv4 or ipv6 endpoint.
     492 *
     493 * @param[in]  addr     The tsocket_address pointer
     494 *
     495 * @param[in]  fam      The family can be can be "ipv4", "ipv6" or "ip". With
     496 *                      "ip" is autodetects "ipv4" or "ipv6" based on the
     497 *                      addr.
     498 *
     499 * @return              true if addr represents an address of the given family,
     500 *                      otherwise false.
     501 */
     502bool tsocket_address_is_inet(const struct tsocket_address *addr, const char *fam);
    488503
    489504#if DOXYGEN
     
    534549 * @return              A newly allocated string of the address, NULL on error
    535550 *                      with errno set.
     551 *
     552 * @see tsocket_address_is_inet()
    536553 */
    537554char *tsocket_address_inet_addr_string(const struct tsocket_address *addr,
     
    559576                                  uint16_t port);
    560577
     578/**
     579 * @brief Find out if the tsocket_address represents an unix domain endpoint.
     580 *
     581 * @param[in]  addr     The tsocket_address pointer
     582 *
     583 * @return              true if addr represents an unix domain endpoint,
     584 *                      otherwise false.
     585 */
     586bool tsocket_address_is_unix(const struct tsocket_address *addr);
     587
    561588#ifdef DOXYGEN
    562589/**
     
    570597 *
    571598 * @return              0 on success, -1 on error with errno set.
     599 *
     600 * @see tsocket_address_is_unix()
    572601 */
    573602int tsocket_address_unix_from_path(TALLOC_CTX *mem_ctx,
     
    696725 * @param[in]  mem_ctx  The talloc memory context to use.
    697726 *
    698  * @param[in] stream   A tstream_context pointer to setup the tcp communication
     727 * @param[out] stream   A tstream_context pointer to setup the tcp communication
    699728 *                      on. This function will allocate the memory.
     729 *
     730 * @param[out] local    The real 'inet' tsocket_address of the local endpoint.
     731 *                      This parameter is optional and can be NULL.
    700732 *
    701733 * @return              0 on success, -1 on error with perrno set.
     
    704736                                  int *perrno,
    705737                                  TALLOC_CTX *mem_ctx,
    706                                   struct tstream_context **stream);
     738                                  struct tstream_context **stream,
     739                                  struct tsocket_address **local)
    707740#else
    708741int _tstream_inet_tcp_connect_recv(struct tevent_req *req,
     
    710743                                   TALLOC_CTX *mem_ctx,
    711744                                   struct tstream_context **stream,
     745                                   struct tsocket_address **local,
    712746                                   const char *location);
    713 #define tstream_inet_tcp_connect_recv(req, perrno, mem_ctx, stream) \
    714         _tstream_inet_tcp_connect_recv(req, perrno, mem_ctx, stream, \
     747#define tstream_inet_tcp_connect_recv(req, perrno, mem_ctx, stream, local) \
     748        _tstream_inet_tcp_connect_recv(req, perrno, mem_ctx, stream, local, \
    715749                                       __location__)
    716750#endif
     
    874908 * freed. If you still want to use the fd you have have to create a duplicate.
    875909 *
    876  * @param[in]  mem_ctx      The talloc memory context to use.
    877  *
    878  * @param[in]  fd           The non blocking fd to use!
    879  *
    880  * @param[in]  stream       The filed tstream_context you allocated before.
    881  *
    882  * @return              0 on success, -1 on error with errno set.
    883  *
    884  * @warning You should read the tsocket_bsd.c code and unterstand it in order
    885  * use this function.
     910 * @param[in]  mem_ctx  The talloc memory context to use.
     911 *
     912 * @param[in]  fd       The non blocking fd to use!
     913 *
     914 * @param[out] stream   A pointer to store an allocated tstream_context.
     915 *
     916 * @return              0 on success, -1 on error.
     917 *
     918 * Example:
     919 * @code
     920 *   fd2 = dup(fd);
     921 *   rc = tstream_bsd_existing_socket(mem_ctx, fd2, &tstream);
     922 *   if (rc < 0) {
     923 *     stream_terminate_connection(conn, "named_pipe_accept: out of memory");
     924 *     return;
     925 *   }
     926 * @endcode
     927 *
     928 * @warning This is an internal function. You should read the code to fully
     929 *          understand it if you plan to use it.
    886930 */
    887931int tstream_bsd_existing_socket(TALLOC_CTX *mem_ctx,
  • trunk/server/lib/tsocket/tsocket_bsd.c

    r480 r745  
    264264
    265265        bsda->sa_socklen = sa_socklen;
     266#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
     267        bsda->u.sa.sa_len = bsda->sa_socklen;
     268#endif
    266269
    267270        *_addr = addr;
     
    292295
    293296        memcpy(sa, &bsda->u.ss, sa_socklen);
     297#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
     298        sa->sa_len = sa_socklen;
     299#endif
    294300        return sa_socklen;
     301}
     302
     303bool tsocket_address_is_inet(const struct tsocket_address *addr, const char *fam)
     304{
     305        struct tsocket_address_bsd *bsda = talloc_get_type(addr->private_data,
     306                                           struct tsocket_address_bsd);
     307
     308        if (!bsda) {
     309                return false;
     310        }
     311
     312        switch (bsda->u.sa.sa_family) {
     313        case AF_INET:
     314                if (strcasecmp(fam, "ip") == 0) {
     315                        return true;
     316                }
     317
     318                if (strcasecmp(fam, "ipv4") == 0) {
     319                        return true;
     320                }
     321
     322                return false;
     323#ifdef HAVE_IPV6
     324        case AF_INET6:
     325                if (strcasecmp(fam, "ip") == 0) {
     326                        return true;
     327                }
     328
     329                if (strcasecmp(fam, "ipv6") == 0) {
     330                        return true;
     331                }
     332
     333                return false;
     334#endif
     335        }
     336
     337        return false;
    295338}
    296339
     
    465508
    466509        return 0;
     510}
     511
     512bool tsocket_address_is_unix(const struct tsocket_address *addr)
     513{
     514        struct tsocket_address_bsd *bsda = talloc_get_type(addr->private_data,
     515                                           struct tsocket_address_bsd);
     516
     517        if (!bsda) {
     518                return false;
     519        }
     520
     521        switch (bsda->u.sa.sa_family) {
     522        case AF_UNIX:
     523                return true;
     524        }
     525
     526        return false;
    467527}
    468528
     
    847907        ZERO_STRUCTP(bsda);
    848908        bsda->sa_socklen = sizeof(bsda->u.ss);
     909#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
     910        bsda->u.sa.sa_len = bsda->sa_socklen;
     911#endif
    849912
    850913        ret = recvfrom(bsds->fd, state->buf, state->len, 0,
     
    10541117        }
    10551118
     1119        TALLOC_FREE(bsds->fde);
    10561120        ret = close(bsds->fd);
    10571121        bsds->fd = -1;
     
    11841248        fd = socket(sa_fam, SOCK_DGRAM, 0);
    11851249        if (fd < 0) {
    1186                 return fd;
     1250                return -1;
    11871251        }
    11881252
    11891253        fd = tsocket_bsd_common_prepare_fd(fd, true);
    11901254        if (fd < 0) {
    1191                 return fd;
     1255                return -1;
    11921256        }
    11931257
     
    12171281                        talloc_free(dgram);
    12181282                        errno = saved_errno;
    1219                         return ret;
     1283                        return -1;
    12201284                }
    12211285        }
     
    12311295                        talloc_free(dgram);
    12321296                        errno = saved_errno;
    1233                         return ret;
     1297                        return -1;
    12341298                }
    12351299        }
     
    12441308                        talloc_free(dgram);
    12451309                        errno = saved_errno;
    1246                         return ret;
     1310                        return -1;
    12471311                }
    12481312        }
     
    12541318                        talloc_free(dgram);
    12551319                        errno = saved_errno;
    1256                         return ret;
     1320                        return -1;
    12571321                }
    12581322        }
     
    12701334                        talloc_free(dgram);
    12711335                        errno = saved_errno;
    1272                         return ret;
     1336                        return -1;
    12731337                }
    12741338        }
     
    16101674                        base = (uint8_t *)state->vector[0].iov_base;
    16111675                        base += ret;
    1612                         state->vector[0].iov_base = base;
     1676                        state->vector[0].iov_base = (void *)base;
    16131677                        state->vector[0].iov_len -= ret;
    16141678                        break;
     
    17701834                        base = (uint8_t *)state->vector[0].iov_base;
    17711835                        base += ret;
    1772                         state->vector[0].iov_base = base;
     1836                        state->vector[0].iov_base = (void *)base;
    17731837                        state->vector[0].iov_len -= ret;
    17741838                        break;
     
    18411905        }
    18421906
     1907        TALLOC_FREE(bsds->fde);
    18431908        ret = close(bsds->fd);
    18441909        bsds->fd = -1;
     
    19181983        struct tevent_fd *fde;
    19191984        struct tstream_conext *stream;
     1985        struct tsocket_address *local;
    19201986};
    19211987
     
    19362002                                            void *private_data);
    19372003
    1938 static struct tevent_req * tstream_bsd_connect_send(TALLOC_CTX *mem_ctx,
     2004static struct tevent_req *tstream_bsd_connect_send(TALLOC_CTX *mem_ctx,
    19392005                                        struct tevent_context *ev,
    19402006                                        int sys_errno,
     
    19472013                talloc_get_type_abort(local->private_data,
    19482014                struct tsocket_address_bsd);
     2015        struct tsocket_address_bsd *lrbsda = NULL;
    19492016        struct tsocket_address_bsd *rbsda =
    19502017                talloc_get_type_abort(remote->private_data,
     
    20262093        }
    20272094
     2095        if (is_inet) {
     2096                state->local = tsocket_address_create(state,
     2097                                                      &tsocket_address_bsd_ops,
     2098                                                      &lrbsda,
     2099                                                      struct tsocket_address_bsd,
     2100                                                      __location__ "bsd_connect");
     2101                if (tevent_req_nomem(state->local, req)) {
     2102                        goto post;
     2103                }
     2104
     2105                ZERO_STRUCTP(lrbsda);
     2106                lrbsda->sa_socklen = sizeof(lrbsda->u.ss);
     2107#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
     2108                lrbsda->u.sa.sa_len = lrbsda->sa_socklen;
     2109#endif
     2110        }
     2111
    20282112        state->fd = socket(sa_fam, SOCK_STREAM, 0);
    20292113        if (state->fd == -1) {
     
    20822166        }
    20832167        if (tevent_req_error(req, err)) {
     2168                goto post;
     2169        }
     2170
     2171        if (!state->local) {
     2172                tevent_req_done(req);
     2173                goto post;
     2174        }
     2175
     2176        ret = getsockname(state->fd, &lrbsda->u.sa, &lrbsda->sa_socklen);
     2177        if (ret == -1) {
     2178                tevent_req_error(req, errno);
    20842179                goto post;
    20852180        }
     
    21142209        struct tstream_bsd_connect_state *state = tevent_req_data(req,
    21152210                                        struct tstream_bsd_connect_state);
     2211        struct tsocket_address_bsd *lrbsda = NULL;
    21162212        int ret;
    21172213        int error=0;
     
    21362232        }
    21372233
     2234        if (!state->local) {
     2235                tevent_req_done(req);
     2236                return;
     2237        }
     2238
     2239        lrbsda = talloc_get_type_abort(state->local->private_data,
     2240                                       struct tsocket_address_bsd);
     2241
     2242        ret = getsockname(state->fd, &lrbsda->u.sa, &lrbsda->sa_socklen);
     2243        if (ret == -1) {
     2244                tevent_req_error(req, errno);
     2245                return;
     2246        }
     2247
    21382248        tevent_req_done(req);
    21392249}
     
    21432253                                    TALLOC_CTX *mem_ctx,
    21442254                                    struct tstream_context **stream,
     2255                                    struct tsocket_address **local,
    21452256                                    const char *location)
    21462257{
     
    21612272                TALLOC_FREE(state->fde);
    21622273                state->fd = -1;
     2274
     2275                if (local) {
     2276                        *local = talloc_move(mem_ctx, &state->local);
     2277                }
    21632278        }
    21642279
     
    22002315                                   TALLOC_CTX *mem_ctx,
    22012316                                   struct tstream_context **stream,
     2317                                   struct tsocket_address **local,
    22022318                                   const char *location)
    22032319{
    2204         return tstream_bsd_connect_recv(req, perrno, mem_ctx, stream, location);
     2320        return tstream_bsd_connect_recv(req, perrno,
     2321                                        mem_ctx, stream, local,
     2322                                        location);
    22052323}
    22062324
     
    22352353                                      const char *location)
    22362354{
    2237         return tstream_bsd_connect_recv(req, perrno, mem_ctx, stream, location);
     2355        return tstream_bsd_connect_recv(req, perrno,
     2356                                        mem_ctx, stream, NULL,
     2357                                        location);
    22382358}
    22392359
  • trunk/server/lib/tsocket/tsocket_guide.txt

    r414 r745  
    2424===============================
    2525
    26 The tsocket_address represents an socket endpoint genericly.
    27 As it's like an abstract class it has no specific constructor.
    28 The specific constructors are descripted later sections.
    29 
    30 There's a function get the string representation of the
    31 endpoint for debugging. Callers should not try to parse
    32 the string! The should use additional methods of the specific
    33 tsocket_address implemention to get more details.
     26A tsocket_address represents a generic socket endpoint.
     27It behaves like an abstract class, therefore it has no direct constructor.
     28Constructors are described in later sections of this document.
     29
     30A function get the string representation of an endpoint for debugging is
     31available but callers SHOULD NOT try to parse this string. To get more
     32details callers should use getter methods of the specific tsocket_address
     33implemention.
    3434
    3535  char *tsocket_address_string(const struct tsocket_address *addr,
    3636      TALLOC_CTX *mem_ctx);
    3737
    38 There's a function to create a copy of the tsocket_address.
    39 This is useful when before doing modifications to a socket
     38A function to create a copy of the tsocket_address is also avilable.
     39This is useful before doing modifications to a socket
    4040via additional methods of the specific tsocket_address implementation.
    4141
     
    4848The tdgram_context is like an abstract class for datagram
    4949based sockets. The interface provides async 'tevent_req' based
    50 functions on top functionality is similar to the
    51 recvfrom(2)/sendto(2)/close(2) syscalls.
     50functions similar to recvfrom(2)/sendto(2)/close(2) syscalls.
    5251
    5352The tdgram_recvfrom_send() method can be called to ask for the
    54 next available datagram on the abstracted tdgram_context.
     53next available datagram from the abstracted tdgram_context.
    5554It returns a 'tevent_req' handle, where the caller can register
    5655a callback with tevent_req_set_callback(). The callback is triggered
    57 when a datagram is available or an error happened.
     56when a datagram is available or an error occurs.
    5857
    5958The callback is then supposed to get the result by calling
     
    123122===============================
    124123
    125 The tstream_context is like an abstract class for stream
     124A tstream_context is like an abstract class for stream
    126125based sockets. The interface provides async 'tevent_req' based
    127 functions on top functionality is similar to the
    128 readv(2)/writev(2)/close(2) syscalls.
    129 
    130 The tstream_pending_bytes() function is able to report
    131 how much bytes of the incoming stream have arrived
    132 but not consumed yet. It returns -1 and sets 'errno' on failure.
    133 Otherwise it returns the number of uncomsumed bytes
    134 (it can return 0!).
     126functions similar to the readv(2)/writev(2)/close(2) syscalls.
     127
     128The tstream_pending_bytes() function is able to report how many bytes of
     129the incoming stream have been received but have not been consumed yet.
     130It returns -1 and sets 'errno' on failure.
     131Otherwise it returns the number of uncomsumed bytes (it can return 0!).
    135132
    136133  ssize_t tstream_pending_bytes(struct tstream_context *stream);
    137134
    138 The tstream_readv_send() method can be called to read for a
     135The tstream_readv_send() method can be called to read a
    139136specific amount of bytes from the stream into the buffers
    140137of the given iovec vector. The caller has to preallocate the buffers
     
    144141where the caller can register a callback with tevent_req_set_callback().
    145142The callback is triggered when all iovec buffers are completely
    146 filled with bytes from the socket or an error happened.
     143filled with bytes from the socket or an error occurs.
    147144
    148145The callback is then supposed to get the result by calling
    149146tstream_readv_recv() on the 'tevent_req'. It returns -1
    150147and sets '*perrno' to the actual 'errno' on failure.
    151 Otherwise it returns the length of the datagram
    152 (0 is never returned!).
     148Otherwise it returns the length of the datagram (0 is never returned!).
    153149
    154150The caller can only have one outstanding tstream_readv_send()
     
    166162The tstream_writev_send() method can be called to write
    167163buffers in the given iovec vector into the stream socket.
    168 It's invalid to pass an empty vector.
     164It is invalid to pass an empty vector.
    169165tstream_writev_send() returns a 'tevent_req' handle,
    170166where the caller can register a callback with tevent_req_set_callback().
     
    190186      int *perrno);
    191187
    192 The tstream_disconnect_send() method should be used to normally
     188The tstream_disconnect_send() method should normally be used to
    193189shutdown/close the abstracted socket.
    194190
     
    209205============================
    210206
    211 In order to make the live easier for callers which want to implement
     207In order to simplify the job, for callers that want to implement
    212208a function to receive a full PDU with a single async function pair,
    213 there're some helper functions.
     209some helper functions are provided.
    214210
    215211The caller can use the tstream_readv_pdu_send() function
     
    217213The caller needs to provide a "next_vector" function and a private
    218214state for this function. The tstream_readv_pdu engine will ask
    219 the next_vector function for the next iovec vetor to be filled.
     215the next_vector function for the next iovec vector to be used.
    220216There's a tstream_readv_send/recv pair for each vector returned
    221217by the next_vector function. If the next_vector function detects
     
    223219of the tevent_req (returned by tstream_readv_pdu_send()) is triggered.
    224220Note: the buffer allocation is completely up to the next_vector function
    225 and it's private state.
     221and its private state.
    226222
    227223See the 'dcerpc_read_ncacn_packet_send/recv' functions in Samba as an
     
    245241===========================================
    246242
    247 There're some cases where the caller wants doesn't care about the
    248 order of doing IO on the abstracted sockets.
     243In some cases the caller doesn't care about the IO ordering on the
     244abstracted socket.
    249245(Remember at the low level there's always only one IO in a specific
    250246 direction allowed, only one tdgram_sendto_send() at a time).
    251247
    252 There're some helpers using 'tevent_queue' to make it easier
    253 for callers. The functions just get a 'queue' argument
    254 and serialize the operations.
     248Some helpers that use 'tevent_queue' are avilable to simplify handling
     249multiple IO requests. The functions just get a 'queue' argument and
     250internally serialize all operations.
    255251
    256252  struct tevent_req *tdgram_sendto_queue_send(TALLOC_CTX *mem_ctx,
     
    296292(dns names are not allowed!). But it's valid to pass NULL,
    297293which gets mapped to "0.0.0.0" or "::".
    298 It return -1 and set errno on error. Otherwise it returns 0.
     294It returns -1 and sets errno on error. Otherwise it returns 0.
    299295
    300296  int tsocket_address_inet_from_strings(TALLOC_CTX *mem_ctx,
     
    343339you can use the tsocket_address_unix_path() function.
    344340It will return NULL and set errno to EINVAL if the tsocket_address
    345 doesn't represent an unix domain endpoint path.
     341doesn't represent a unix domain endpoint path.
    346342
    347343  char *tsocket_address_unix_path(const struct tsocket_address *addr,
     
    372368      struct tdgram_context **dgram);
    373369
    374 You can use tstream_inet_tcp_connect_send to async
     370You can use tstream_inet_tcp_connect_send to asynchronously
    375371connect to a remote ipv4 or ipv6 TCP endpoint and create a
    376372tstream_context for the stream based communication. "local_address" has to be
     
    398394      struct tstream_context **stream);
    399395
    400 You can use tstream_unix_connect_send to async
     396You can use tstream_unix_connect_send to asynchronously
    401397connect to a unix domain endpoint and create a
    402398tstream_context for the stream based communication.
     
    439435for that. This should only be used if really needed, because of
    440436already existing fixed APIs. Only AF_INET, AF_INET6 and AF_UNIX
    441 sockets are allowed. The function returns -1 and set errno on error.
     437sockets are allowed. The function returns -1 and sets errno on error.
    442438Otherwise it returns 0.
    443439
Note: See TracChangeset for help on using the changeset viewer.