Example #1
0
static void test_delenv(abts_case *tc, void *data)
{
    char *value;
    apr_status_t rv;

    if (!have_env_set) {
        ABTS_NOT_IMPL(tc, "apr_env_set (skip test for apr_env_delete)");
        return;
    }

    rv = apr_env_delete(TEST_ENVVAR_NAME, p);
    have_env_del = (rv != APR_ENOTIMPL);
    if (!have_env_del) {
        ABTS_NOT_IMPL(tc, "apr_env_delete");
        return;
    }
    APR_ASSERT_SUCCESS(tc, "delete environment variable", rv);

    if (!have_env_get) {
        ABTS_NOT_IMPL(tc, "apr_env_get (skip sanity check for apr_env_delete)");
        return;
    }
    rv = apr_env_get(&value, TEST_ENVVAR_NAME, p);
    ABTS_INT_EQUAL(tc, APR_ENOENT, rv);
}
Example #2
0
static const apr_crypto_driver_t *get_driver(abts_case *tc, apr_pool_t *pool,
        const char *name, const apr_array_header_t *params) {

    const apr_crypto_driver_t *driver = NULL;
    const apu_err_t *err = NULL;
    apr_status_t rv;

    rv = apr_crypto_init(pool, params);
    ABTS_ASSERT(tc, "failed to init apr_crypto", rv == APR_SUCCESS);

    rv = apr_crypto_get_driver(pool, name, &driver, params, &err);
    if (APR_SUCCESS != rv && err) {
        ABTS_NOT_IMPL(tc, err->msg);
        return NULL;
    }
    if (APR_ENOTIMPL == rv) {
        ABTS_NOT_IMPL(tc, (char *)driver);
        return NULL;
    }
    ABTS_ASSERT(tc, "failed to apr_crypto_get_driver", rv == APR_SUCCESS);
    ABTS_ASSERT(tc, "apr_crypto_get_driver returned NULL", driver != NULL);
    if (!driver || rv) {
        return NULL;
    }

    return driver;

}
static void test_thread_rwlock(abts_case *tc, void *data)
{
    apr_thread_t *t1, *t2, *t3, *t4;
    apr_status_t s1, s2, s3, s4;

    s1 = apr_thread_rwlock_create(&rwlock, p);
    if (s1 == APR_ENOTIMPL) {
        ABTS_NOT_IMPL(tc, "rwlocks not implemented");
        return;
    }
    APR_ASSERT_SUCCESS(tc, "rwlock_create", s1);
    ABTS_PTR_NOTNULL(tc, rwlock);

    i = 0;
    x = 0;

    s1 = apr_thread_create(&t1, NULL, thread_rwlock_func, NULL, p);
    APR_ASSERT_SUCCESS(tc, "create thread 1", s1);
    s2 = apr_thread_create(&t2, NULL, thread_rwlock_func, NULL, p);
    APR_ASSERT_SUCCESS(tc, "create thread 2", s2);
    s3 = apr_thread_create(&t3, NULL, thread_rwlock_func, NULL, p);
    APR_ASSERT_SUCCESS(tc, "create thread 3", s3);
    s4 = apr_thread_create(&t4, NULL, thread_rwlock_func, NULL, p);
    APR_ASSERT_SUCCESS(tc, "create thread 4", s4);

    apr_thread_join(&s1, t1);
    apr_thread_join(&s2, t2);
    apr_thread_join(&s3, t3);
    apr_thread_join(&s4, t4);

    ABTS_INT_EQUAL(tc, MAX_ITER, x);

    apr_thread_rwlock_destroy(rwlock);
}
Example #4
0
static void pollcb_default(abts_case *tc, void *data)
{
    apr_status_t rv1, rv2;
    apr_pollcb_t *pollcb;

    /* verify that APR will successfully create a pollcb if an invalid method
     * is specified as long as APR_POLLSET_NODEFAULT isn't specified
     * (no platform has both APR_POLLSET_PORT and APR_POLLSET_KQUEUE, so at
     * least one create call will succeed after having to switch to the default
     * type)
     */
    rv1 = apr_pollcb_create_ex(&pollcb, 1, p, 0, APR_POLLSET_PORT);
    if (rv1 == APR_ENOTIMPL) {
        ABTS_NOT_IMPL(tc, "pollcb interface not supported");
        return;
    }

    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv1);
    ABTS_PTR_NOTNULL(tc, pollcb);
    
    rv1 = apr_pollcb_create_ex(&pollcb, 1, p, 0, APR_POLLSET_KQUEUE);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv1);
    ABTS_PTR_NOTNULL(tc, pollcb);

    /* verify that APR will fail to create a pollcb if an invalid method is
     * specified along with APR_POLLSET_NODEFAULT
     * (no platform has both APR_POLLSET_PORT and APR_POLLSET_KQUEUE, so at
     * least one create call will fail since it can't switch to the default
     * type)
     */
    rv1 = apr_pollcb_create_ex(&pollcb, 1, p, APR_POLLSET_NODEFAULT,
                               APR_POLLSET_PORT);

    if (rv1 == APR_SUCCESS) {
        ABTS_PTR_NOTNULL(tc, pollcb);
    }
    
    rv2 = apr_pollcb_create_ex(&pollcb, 1, p, APR_POLLSET_NODEFAULT,
                               APR_POLLSET_KQUEUE);
    if (rv2 == APR_SUCCESS) {
        ABTS_PTR_NOTNULL(tc, pollcb);
    }
    
    ABTS_ASSERT(tc,
                "failure using APR_POLLSET_NODEFAULT with unsupported method",
                rv1 != APR_SUCCESS || rv2 != APR_SUCCESS);


    /* verify basic behavior for another method fallback case (this caused
     * APR to crash before r834029)
     */

    rv1 = apr_pollcb_create_ex(&pollcb, 1, p, 0, APR_POLLSET_POLL);
    if (rv1 != APR_ENOTIMPL) {
        ABTS_INT_EQUAL(tc, rv1, APR_SUCCESS);
        ABTS_PTR_NOTNULL(tc, pollcb);
    }
}
Example #5
0
static void udp6_socket(abts_case *tc, void *data)
{
#if APR_HAVE_IPV6
    apr_status_t rv;
    apr_socket_t *sock = NULL;

    rv = apr_socket_create(&sock, APR_INET6, SOCK_DGRAM, 0, p);
    if (V6_NOT_ENABLED(rv)) {
        ABTS_NOT_IMPL(tc, "IPv6 not enabled");
        return;
    }
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    ABTS_PTR_NOTNULL(tc, sock);
    apr_socket_close(sock);
#else
    ABTS_NOT_IMPL(tc, "IPv6");
#endif
}
Example #6
0
/** http://issues.apache.org/bugzilla/show_bug.cgi?id=40764 */
static void test_emptyenv(abts_case *tc, void *data)
{
    char *value;
    apr_status_t rv;

    if (!(have_env_set && have_env_get)) {
        ABTS_NOT_IMPL(tc, "apr_env_set (skip test_emptyenv)");
        return;
    }
    /** Set empty string and test that rv != ENOENT) */
    rv = apr_env_set(TEST_ENVVAR_NAME, "", p);
    APR_ASSERT_SUCCESS(tc, "set environment variable", rv);
    rv = apr_env_get(&value, TEST_ENVVAR_NAME, p);
    APR_ASSERT_SUCCESS(tc, "get environment variable", rv);
    ABTS_STR_EQUAL(tc, "", value);

    if (!have_env_del) {
        ABTS_NOT_IMPL(tc, "apr_env_del (skip recycle test_emptyenv)");
        return;
    }
    /** Delete and retest */
    rv = apr_env_delete(TEST_ENVVAR_NAME, p);
    APR_ASSERT_SUCCESS(tc, "delete environment variable", rv);
    rv = apr_env_get(&value, TEST_ENVVAR_NAME, p);
    ABTS_INT_EQUAL(tc, APR_ENOENT, rv);

    /** Set second variable + test*/
    rv = apr_env_set(TEST_ENVVAR2_NAME, TEST_ENVVAR_VALUE, p);
    APR_ASSERT_SUCCESS(tc, "set second environment variable", rv);
    rv = apr_env_get(&value, TEST_ENVVAR2_NAME, p);
    APR_ASSERT_SUCCESS(tc, "get second environment variable", rv);
    ABTS_STR_EQUAL(tc, TEST_ENVVAR_VALUE, value);

    /** Finally, test ENOENT (first variable) followed by second != ENOENT) */
    rv = apr_env_get(&value, TEST_ENVVAR_NAME, p);
    ABTS_INT_EQUAL(tc, APR_ENOENT, rv);
    rv = apr_env_get(&value, TEST_ENVVAR2_NAME, p);
    APR_ASSERT_SUCCESS(tc, "verify second environment variable", rv);
    ABTS_STR_EQUAL(tc, TEST_ENVVAR_VALUE, value);

    /** Cleanup */
    apr_env_delete(TEST_ENVVAR2_NAME, p);
}
Example #7
0
static void test_getenv(abts_case *tc, void *data)
{
    char *value;
    apr_status_t rv;

    if (!have_env_set) {
        ABTS_NOT_IMPL(tc, "apr_env_set (skip test for apr_env_get)");
        return;
    }

    rv = apr_env_get(&value, TEST_ENVVAR_NAME, p);
    have_env_get = (rv != APR_ENOTIMPL);
    if (!have_env_get) {
        ABTS_NOT_IMPL(tc, "apr_env_get");
        return;
    }
    APR_ASSERT_SUCCESS(tc, "get environment variable", rv);
    ABTS_STR_EQUAL(tc, TEST_ENVVAR_VALUE, value);
}
Example #8
0
static void test_insertfile(abts_case *tc, void *ctx)
{
    apr_bucket_alloc_t *ba = apr_bucket_alloc_create(p);
    apr_bucket_brigade *bb;
    const apr_off_t bignum = (APR_INT64_C(2) << 32) + 424242;
    apr_off_t count;
    apr_file_t *f;
    apr_bucket *e;

    ABTS_ASSERT(tc, "open test file",
                apr_file_open(&f, TIF_FNAME,
                              APR_FOPEN_WRITE | APR_FOPEN_TRUNCATE
                            | APR_FOPEN_CREATE | APR_FOPEN_SPARSE,
                              APR_OS_DEFAULT, p) == APR_SUCCESS);

    if (apr_file_trunc(f, bignum)) {
        apr_file_close(f);
        apr_file_remove(TIF_FNAME, p);
        ABTS_NOT_IMPL(tc, "Skipped: could not create large file");
        return;
    }
    
    bb = apr_brigade_create(p, ba);

    e = apr_brigade_insert_file(bb, f, 0, bignum, p);
    
    ABTS_ASSERT(tc, "inserted file was not at end of brigade",
                e == APR_BRIGADE_LAST(bb));

    /* check that the total size of inserted buckets is equal to the
     * total size of the file. */
    count = 0;

    for (e = APR_BRIGADE_FIRST(bb);
         e != APR_BRIGADE_SENTINEL(bb);
         e = APR_BUCKET_NEXT(e)) {
        ABTS_ASSERT(tc, "bucket size sane", e->length != (apr_size_t)-1);
        count += e->length;
    }

    ABTS_ASSERT(tc, "total size of buckets incorrect", count == bignum);

    apr_brigade_destroy(bb);

    /* Truncate the file to zero size before close() so that we don't
     * actually write out the large file if we are on a non-sparse file
     * system - like Mac OS X's HFS.  Otherwise, pity the poor user who
     * has to wait for the 8GB file to be written to disk.
     */
    apr_file_trunc(f, 0);

    apr_file_close(f);
    apr_bucket_alloc_destroy(ba);
    apr_file_remove(TIF_FNAME, p);
}
Example #9
0
static void setup_pollcb(abts_case *tc, void *data)
{
    apr_status_t rv;
    rv = apr_pollcb_create(&pollcb, LARGE_NUM_SOCKETS, p, 0);
    if (rv == APR_ENOTIMPL) {
        pollcb = NULL;
        ABTS_NOT_IMPL(tc, "pollcb interface not supported");
    }
    else {
        ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    }
}
Example #10
0
static void test_setenv(abts_case *tc, void *data)
{
    apr_status_t rv;

    rv = apr_env_set(TEST_ENVVAR_NAME, TEST_ENVVAR_VALUE, p);
    have_env_set = (rv != APR_ENOTIMPL);
    if (!have_env_set) {
        ABTS_NOT_IMPL(tc, "apr_env_set");
    } else {
        APR_ASSERT_SUCCESS(tc, "set environment variable", rv);
    }
}
Example #11
0
void apr_assert_success(abts_case* tc, const char* context, apr_status_t rv)
{
    if (rv == APR_ENOTIMPL) {
        ABTS_NOT_IMPL(tc, context);
    }

    if (rv != APR_SUCCESS) {
        char buf[STRING_MAX], ebuf[128];
        sprintf(buf, "%s (%d): %s\n", context, rv,
                apr_strerror(rv, ebuf, sizeof ebuf));
        ABTS_FAIL(tc, buf);
    }
}
Example #12
0
static void rand_exists(abts_case *tc, void *data)
{
#if !APR_HAS_RANDOM
    ABTS_NOT_IMPL(tc, "apr_generate_random_bytes");
#else
    unsigned char c[42];

    /* There must be a better way to test random-ness, but I don't know
     * what it is right now.
     */
    APR_ASSERT_SUCCESS(tc, "apr_generate_random_bytes failed",
                       apr_generate_random_bytes(c, sizeof c));
#endif
}
Example #13
0
static void udp6_socket(abts_case *tc, void *data)
{
    apr_status_t rv;
    apr_socket_t *sock = NULL;

    rv = apr_socket_create(&sock, APR_INET6, SOCK_DGRAM, 0, p);
    if (APR_STATUS_IS_EAFNOSUPPORT(rv)) {
        ABTS_NOT_IMPL(tc, "IPv6 not enabled");
        return;
    }
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    ABTS_PTR_NOTNULL(tc, sock);
    apr_socket_close(sock);
}
Example #14
0
static const apr_crypto_key_t *passphrase(abts_case *tc, apr_pool_t *pool,
        const apr_crypto_driver_t *driver, const apr_crypto_t *f,
        apr_crypto_block_key_type_e type, apr_crypto_block_key_mode_e mode,
        int doPad, const char *description) {

    apr_crypto_key_t *key = NULL;
    const apu_err_t *result = NULL;
    const char *pass = "******";
    const char *salt = "salt";
    apr_status_t rv;

    if (!f) {
        return NULL;
    }

    /* init the passphrase */
    rv = apr_crypto_passphrase(pool, f, pass, strlen(pass),
            (unsigned char *) salt, strlen(salt), type, mode, doPad, 4096,
            &key, NULL);
    if (APR_ENOCIPHER == rv) {
        apr_crypto_error(f, &result);
        ABTS_NOT_IMPL(tc, apr_psprintf(pool,
                "skipped: %s %s passphrase return APR_ENOCIPHER: error %d: %s (%s)\n",
                description, apr_crypto_driver_name(driver), result->rc,
                result->reason ? result->reason : "", result->msg ? result->msg : ""));
        return NULL;
    } else {
        if (APR_SUCCESS != rv) {
            apr_crypto_error(f, &result);
            fprintf(stderr, "passphrase: %s %s native error %d: %s (%s)\n",
                    description, apr_crypto_driver_name(driver), result->rc,
                    result->reason ? result->reason : "",
                    result->msg ? result->msg : "");
        }
        ABTS_ASSERT(tc, "apr_crypto_passphrase returned APR_ENOKEY", rv != APR_ENOKEY);
        ABTS_ASSERT(tc, "apr_crypto_passphrase returned APR_EPADDING", rv != APR_EPADDING);
        ABTS_ASSERT(tc, "apr_crypto_passphrase returned APR_EKEYTYPE", rv != APR_EKEYTYPE);
        ABTS_ASSERT(tc, "failed to apr_crypto_passphrase", rv == APR_SUCCESS);
        ABTS_ASSERT(tc, "apr_crypto_passphrase returned NULL context", key != NULL);
    }
    if (rv) {
        return NULL;
    }
    return key;

}
Example #15
0
static void pollset_wakeup(abts_case *tc, void *data)
{
    apr_status_t rv;
    apr_pollfd_t socket_pollfd;
    apr_pollset_t *pollset;
    apr_int32_t num;
    const apr_pollfd_t *descriptors;

    rv = apr_pollset_create_ex(&pollset, 1, p, APR_POLLSET_WAKEABLE,
                               default_pollset_impl);
    if (rv == APR_ENOTIMPL) {
        ABTS_NOT_IMPL(tc, "apr_pollset_wakeup() not supported");
        return;
    }
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);

    /* send wakeup but no data; apr_pollset_poll() should return APR_EINTR */
    rv = apr_pollset_wakeup(pollset);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);

    rv = apr_pollset_poll(pollset, -1, &num, &descriptors);
    ABTS_INT_EQUAL(tc, APR_EINTR, rv);

    /* send wakeup and data; apr_pollset_poll() should return APR_SUCCESS */
    socket_pollfd.desc_type = APR_POLL_SOCKET;
    socket_pollfd.reqevents = APR_POLLIN;
    socket_pollfd.desc.s = s[0];
    socket_pollfd.client_data = s[0];
    rv = apr_pollset_add(pollset, &socket_pollfd);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);

    send_msg(s, sa, 0, tc);

    rv = apr_pollset_wakeup(pollset);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);

    rv = apr_pollset_poll(pollset, -1, &num, &descriptors);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    ABTS_INT_EQUAL(tc, 1, num);
}
Example #16
0
static void corkable(abts_case *tc, void *data)
{
#if !APR_HAVE_CORKABLE_TCP
    ABTS_NOT_IMPL(tc, "TCP isn't corkable");
#else
    apr_status_t rv;
    apr_int32_t ck;

    rv = apr_socket_opt_set(sock, APR_TCP_NODELAY, 1);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);

    rv = apr_socket_opt_get(sock, APR_TCP_NODELAY, &ck);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    ABTS_INT_EQUAL(tc, 1, ck);

    rv = apr_socket_opt_set(sock, APR_TCP_NOPUSH, 1);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);

    rv = apr_socket_opt_get(sock, APR_TCP_NOPUSH, &ck);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    ABTS_INT_EQUAL(tc, 1, ck);

    rv = apr_socket_opt_get(sock, APR_TCP_NODELAY, &ck);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    /* TCP_NODELAY is now in an unknown state; it may be zero if
     * TCP_NOPUSH and TCP_NODELAY are mutually exclusive on this
     * platform, e.g. Linux < 2.6. */

    rv = apr_socket_opt_set(sock, APR_TCP_NOPUSH, 0);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    
    rv = apr_socket_opt_get(sock, APR_TCP_NODELAY, &ck);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    ABTS_INT_EQUAL(tc, 1, ck);
#endif
}
Example #17
0
static unsigned char *decrypt_block(abts_case *tc, apr_pool_t *pool,
        const apr_crypto_driver_t *driver, const apr_crypto_t *f,
        const apr_crypto_key_t *key, unsigned char *cipherText,
        apr_size_t cipherTextLen, unsigned char **plainText,
        apr_size_t *plainTextLen, const unsigned char *iv,
        apr_size_t *blockSize, const char *description) {

    apr_crypto_block_t *block = NULL;
    const apu_err_t *result = NULL;
    apr_size_t len = 0;
    apr_status_t rv;

    if (!driver || !f || !key || !cipherText) {
        return NULL;
    }

    /* init the decryption */
    rv = apr_crypto_block_decrypt_init(pool, f, key, iv, &block,
            blockSize);
    if (APR_ENOTIMPL == rv) {
        ABTS_NOT_IMPL(tc, "apr_crypto_block_decrypt_init returned APR_ENOTIMPL");
    } else {
        if (APR_SUCCESS != rv) {
            apr_crypto_error(f, &result);
            fprintf(stderr, "decrypt_init: %s %s native error %d: %s (%s)\n",
                    description, apr_crypto_driver_name(driver), result->rc,
                    result->reason ? result->reason : "",
                    result->msg ? result->msg : "");
        }
        ABTS_ASSERT(tc, "apr_crypto_block_decrypt_init returned APR_ENOKEY", rv != APR_ENOKEY);
        ABTS_ASSERT(tc, "apr_crypto_block_decrypt_init returned APR_ENOIV", rv != APR_ENOIV);
        ABTS_ASSERT(tc, "apr_crypto_block_decrypt_init returned APR_EKEYTYPE", rv != APR_EKEYTYPE);
        ABTS_ASSERT(tc, "apr_crypto_block_decrypt_init returned APR_EKEYLENGTH", rv != APR_EKEYLENGTH);
        ABTS_ASSERT(tc, "failed to apr_crypto_block_decrypt_init", rv == APR_SUCCESS);
        ABTS_ASSERT(tc, "apr_crypto_block_decrypt_init returned NULL context", block != NULL);
    }
    if (!block || rv) {
        return NULL;
    }

    /* decrypt the block */
    rv = apr_crypto_block_decrypt(f, block, plainText, plainTextLen,
            cipherText, cipherTextLen);
    if (APR_SUCCESS != rv) {
        apr_crypto_error(f, &result);
        fprintf(stderr, "decrypt: %s %s native error %d: %s (%s)\n",
                description, apr_crypto_driver_name(driver), result->rc,
                result->reason ? result->reason : "",
                result->msg ? result->msg : "");
    }
    ABTS_ASSERT(tc, "apr_crypto_block_decrypt returned APR_ECRYPT", rv != APR_ECRYPT);
    ABTS_ASSERT(tc, "failed to apr_crypto_block_decrypt", rv == APR_SUCCESS);
    ABTS_ASSERT(tc, "apr_crypto_block_decrypt failed to allocate buffer", *plainText != NULL);
    if (rv) {
        return NULL;
    }

    /* finalise the decryption */
    rv = apr_crypto_block_decrypt_finish(f, block, *plainText
            + *plainTextLen, &len);
    if (APR_SUCCESS != rv) {
        apr_crypto_error(f, &result);
        fprintf(stderr, "decrypt_finish: %s %s native error %d: %s (%s)\n",
                description, apr_crypto_driver_name(driver), result->rc,
                result->reason ? result->reason : "",
                result->msg ? result->msg : "");
    }
    ABTS_ASSERT(tc, "apr_crypto_block_decrypt_finish returned APR_ECRYPT", rv != APR_ECRYPT);
    ABTS_ASSERT(tc, "apr_crypto_block_decrypt_finish returned APR_EPADDING", rv != APR_EPADDING);
    ABTS_ASSERT(tc, "failed to apr_crypto_block_decrypt_finish", rv == APR_SUCCESS);
    if (rv) {
        return NULL;
    }

    *plainTextLen += len;
    apr_crypto_block_cleanup(f, block);

    return *plainText;

}
static void threads_not_impl(abts_case *tc, void *data)
{
    ABTS_NOT_IMPL(tc, "Threads not implemented on this platform");
}
Example #19
0
static void not_implemented(abts_case *tc, void *data)
{
    ABTS_NOT_IMPL(tc, "User functions");
}
Example #20
0
static void sendto_receivefrom_helper(abts_case *tc, const char *addr,
                                      int family)
{
    apr_status_t rv;
    apr_socket_t *sock = NULL;
    apr_socket_t *sock2 = NULL;
    char sendbuf[STRLEN] = "APR_INET, SOCK_DGRAM";
    char recvbuf[80];
    char *ip_addr;
    apr_port_t fromport;
    apr_sockaddr_t *from;
    apr_sockaddr_t *to;
    apr_size_t len = 30;

    rv = apr_socket_create(&sock, family, SOCK_DGRAM, 0, p);
#if APR_HAVE_IPV6
    if ((family == APR_INET6) && APR_STATUS_IS_EAFNOSUPPORT(rv)) {
        ABTS_NOT_IMPL(tc, "IPv6 not enabled");
        return;
    }
#endif
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    if (rv != APR_SUCCESS)
        return;
    rv = apr_socket_create(&sock2, family, SOCK_DGRAM, 0, p);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    if (rv != APR_SUCCESS)
        return;

    rv = apr_sockaddr_info_get(&to, addr, family, 7772, 0, p);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    rv = apr_sockaddr_info_get(&from, addr, family, 7771, 0, p);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);

    rv = apr_socket_opt_set(sock, APR_SO_REUSEADDR, 1);
    APR_ASSERT_SUCCESS(tc, "Could not set REUSEADDR on socket", rv);
    rv = apr_socket_opt_set(sock2, APR_SO_REUSEADDR, 1);
    APR_ASSERT_SUCCESS(tc, "Could not set REUSEADDR on socket2", rv);

    rv = apr_socket_bind(sock, to);
    APR_ASSERT_SUCCESS(tc, "Could not bind socket", rv);
    if (rv != APR_SUCCESS)
        return;

    rv = apr_socket_bind(sock2, from);
    APR_ASSERT_SUCCESS(tc, "Could not bind second socket", rv);
    if (rv != APR_SUCCESS)
        return;

    len = STRLEN;
    rv = apr_socket_sendto(sock2, to, 0, sendbuf, &len);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    ABTS_SIZE_EQUAL(tc, STRLEN, len);

    /* fill the "from" sockaddr with a random address from another
     * family to ensure that recvfrom sets it up properly. */
#if APR_HAVE_IPV6
    if (family == APR_INET)
        rv = apr_sockaddr_info_get(&from, "3ffE:816e:abcd:1234::1",
                                   APR_INET6, 4242, 0, p);
    else
#endif
        rv = apr_sockaddr_info_get(&from, "127.1.2.3", APR_INET, 4242, 0, p);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);

    len = 80;
    rv = apr_socket_recvfrom(from, sock, 0, recvbuf, &len);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    ABTS_SIZE_EQUAL(tc, STRLEN, len);
    ABTS_STR_EQUAL(tc, "APR_INET, SOCK_DGRAM", recvbuf);

    apr_sockaddr_ip_get(&ip_addr, from);
    fromport = from->port;
    ABTS_STR_EQUAL(tc, addr, ip_addr);
    ABTS_INT_EQUAL(tc, 7771, fromport);

    apr_socket_close(sock);
    apr_socket_close(sock2);
}
Example #21
0
static void test_get_addr(abts_case *tc, void *data)
{
    apr_status_t rv;
    apr_socket_t *ld, *sd, *cd;
    apr_sockaddr_t *sa, *ca;
    apr_pool_t *subp;
    char *a, *b;

    APR_ASSERT_SUCCESS(tc, "create subpool", apr_pool_create(&subp, p));

    if ((ld = setup_socket(tc)) != APR_SUCCESS)
        return;

    APR_ASSERT_SUCCESS(tc,
                       "get local address of bound socket",
                       apr_socket_addr_get(&sa, APR_LOCAL, ld));

    rv = apr_socket_create(&cd, sa->family, SOCK_STREAM,
                           APR_PROTO_TCP, subp);
    APR_ASSERT_SUCCESS(tc, "create client socket", rv);

    APR_ASSERT_SUCCESS(tc, "enable non-block mode",
                       apr_socket_opt_set(cd, APR_SO_NONBLOCK, 1));

    /* It is valid for a connect() on a socket with NONBLOCK set to
     * succeed (if the connection can be established synchronously),
     * but if it does, this test cannot proceed.  */
    rv = apr_socket_connect(cd, sa);
    if (rv == APR_SUCCESS) {
        apr_socket_close(ld);
        apr_socket_close(cd);
        ABTS_NOT_IMPL(tc, "Cannot test if connect completes "
                      "synchronously");
        return;
    }

    if (!APR_STATUS_IS_EINPROGRESS(rv)) {
        apr_socket_close(ld);
        apr_socket_close(cd);
        APR_ASSERT_SUCCESS(tc, "connect to listener", rv);
        return;
    }

    APR_ASSERT_SUCCESS(tc, "accept connection",
                       apr_socket_accept(&sd, ld, subp));
    
    {
        /* wait for writability */
        apr_pollfd_t pfd;
        int n;

        pfd.p = p;
        pfd.desc_type = APR_POLL_SOCKET;
        pfd.reqevents = APR_POLLOUT|APR_POLLHUP;
        pfd.desc.s = cd;
        pfd.client_data = NULL;

        APR_ASSERT_SUCCESS(tc, "poll for connect completion",
                           apr_poll(&pfd, 1, &n, 5 * APR_USEC_PER_SEC));

    }

    APR_ASSERT_SUCCESS(tc, "get local address of server socket",
                       apr_socket_addr_get(&sa, APR_LOCAL, sd));
    APR_ASSERT_SUCCESS(tc, "get remote address of client socket",
                       apr_socket_addr_get(&ca, APR_REMOTE, cd));

    /* Test that the pool of the returned sockaddr objects exactly
     * match the socket. */
    ABTS_PTR_EQUAL(tc, subp, sa->pool);
    ABTS_PTR_EQUAL(tc, subp, ca->pool);

    /* Check equivalence. */
    a = apr_psprintf(p, "%pI fam=%d", sa, sa->family);
    b = apr_psprintf(p, "%pI fam=%d", ca, ca->family);
    ABTS_STR_EQUAL(tc, a, b);

    /* Check pool of returned sockaddr, as above. */
    APR_ASSERT_SUCCESS(tc, "get local address of client socket",
                       apr_socket_addr_get(&sa, APR_LOCAL, cd));
    APR_ASSERT_SUCCESS(tc, "get remote address of server socket",
                       apr_socket_addr_get(&ca, APR_REMOTE, sd));

    /* Check equivalence. */
    a = apr_psprintf(p, "%pI fam=%d", sa, sa->family);
    b = apr_psprintf(p, "%pI fam=%d", ca, ca->family);
    ABTS_STR_EQUAL(tc, a, b);

    ABTS_PTR_EQUAL(tc, subp, sa->pool);
    ABTS_PTR_EQUAL(tc, subp, ca->pool);
                       
    apr_socket_close(cd);
    apr_socket_close(sd);
    apr_socket_close(ld);

    apr_pool_destroy(subp);
}
Example #22
0
static void test_get_addr(abts_case *tc, void *data)
{
    apr_status_t rv;
    apr_socket_t *ld, *sd, *cd;
    apr_sockaddr_t *sa, *ca;
    char a[128], b[128];

    ld = setup_socket(tc);

    APR_ASSERT_SUCCESS(tc,
                       "get local address of bound socket",
                       apr_socket_addr_get(&sa, APR_LOCAL, ld));

    rv = apr_socket_create(&cd, sa->family, SOCK_STREAM,
                           APR_PROTO_TCP, p);
    APR_ASSERT_SUCCESS(tc, "create client socket", rv);

    APR_ASSERT_SUCCESS(tc, "enable non-block mode",
                       apr_socket_opt_set(cd, APR_SO_NONBLOCK, 1));

    /* It is valid for a connect() on a socket with NONBLOCK set to
     * succeed (if the connection can be established synchronously),
     * but if it does, this test cannot proceed.  */
    rv = apr_socket_connect(cd, sa);
    if (rv == APR_SUCCESS) {
        apr_socket_close(ld);
        apr_socket_close(cd);
        ABTS_NOT_IMPL(tc, "Cannot test if connect completes "
                      "synchronously");
        return;
    }

    if (!APR_STATUS_IS_EINPROGRESS(rv)) {
        apr_socket_close(ld);
        apr_socket_close(cd);
        APR_ASSERT_SUCCESS(tc, "connect to listener", rv);
        return;
    }

    APR_ASSERT_SUCCESS(tc, "accept connection",
                       apr_socket_accept(&sd, ld, p));
    
    {
        /* wait for writability */
        apr_pollfd_t pfd;
        int n;

        pfd.p = p;
        pfd.desc_type = APR_POLL_SOCKET;
        pfd.reqevents = APR_POLLOUT|APR_POLLHUP;
        pfd.desc.s = cd;
        pfd.client_data = NULL;

        APR_ASSERT_SUCCESS(tc, "poll for connect completion",
                           apr_poll(&pfd, 1, &n, 5 * APR_USEC_PER_SEC));

    }

    APR_ASSERT_SUCCESS(tc, "get local address of server socket",
                       apr_socket_addr_get(&sa, APR_LOCAL, sd));

    APR_ASSERT_SUCCESS(tc, "get remote address of client socket",
                       apr_socket_addr_get(&ca, APR_REMOTE, cd));
    
    apr_snprintf(a, sizeof(a), "%pI", sa);
    apr_snprintf(b, sizeof(b), "%pI", ca);

    ABTS_STR_EQUAL(tc, a, b);
                       
    apr_socket_close(cd);
    apr_socket_close(sd);
    apr_socket_close(ld);
}
Example #23
0
static void oc_not_impl(abts_case *tc, void *data)
{
    ABTS_NOT_IMPL(tc, "Other child logic not implemented on this platform");
}