The branch, master has been updated
       via  538f2b9 rwrap: Fix strict aliasing warnings for symbol binding
       via  07592c5 tests: Migrate to new cmocka API
       via  96c55c9 Find the correct symbol when res_* is a define to __res_*
      from  c6e0ecf cmake: Drop test results via https.

https://git.samba.org/?p=resolv_wrapper.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 538f2b9fda0e9015839b13db7fea3749e4a0044b
Author: Andreas Schneider <a...@cryptomilk.org>
Date:   Wed Aug 12 15:59:53 2015 +0200

    rwrap: Fix strict aliasing warnings for symbol binding
    
    Signed-off-by: Andreas Schneider <a...@cryptomilk.org>
    Reviewed-by: Stefan Metzmacher <me...@samba.org>

commit 07592c591647a467e3d73e173ea19605d45058a2
Author: Andreas Schneider <a...@cryptomilk.org>
Date:   Wed Aug 12 16:07:27 2015 +0200

    tests: Migrate to new cmocka API
    
    Signed-off-by: Andreas Schneider <a...@cryptomilk.org>
    Reviewed-by: Stefan Metzmacher <me...@samba.org>

commit 96c55c94429b7d0e0c52e14a60ea6d3d93689045
Author: Andrew Bartlett <abart...@samba.org>
Date:   Wed Aug 12 13:50:48 2015 +1200

    Find the correct symbol when res_* is a define to __res_*
    
    Signed-off-by: Andrew Bartlett <abart...@samba.org>
    Reviewed-by: Andreas Schneider <a...@cryptomilk.org>
    Reviewed-by: Stefan Metzmacher <me...@samba.org>

-----------------------------------------------------------------------

Summary of changes:
 src/resolv_wrapper.c          | 227 +++++++++++++++++++++++-------------------
 tests/test_dns_fake.c         |  26 ++---
 tests/test_real_res_query.c   |   8 +-
 tests/test_res_init.c         |  19 ++--
 tests/test_res_query_search.c |  24 +++--
 5 files changed, 165 insertions(+), 139 deletions(-)


Changeset truncated at 500 lines:

diff --git a/src/resolv_wrapper.c b/src/resolv_wrapper.c
index 10af360..d36d080 100644
--- a/src/resolv_wrapper.c
+++ b/src/resolv_wrapper.c
@@ -981,51 +981,68 @@ static int rwrap_res_fake_hosts(const char *hostfile,
 
 #include <dlfcn.h>
 
-struct rwrap_libc_fns {
-       int (*libc_res_init)(void);
-       int (*libc___res_init)(void);
-       int (*libc_res_ninit)(struct __res_state *state);
-       int (*libc___res_ninit)(struct __res_state *state);
-       void (*libc_res_nclose)(struct __res_state *state);
-       void (*libc___res_nclose)(struct __res_state *state);
-       void (*libc_res_close)(void);
-       void (*libc___res_close)(void);
-       int (*libc_res_nquery)(struct __res_state *state,
-                              const char *dname,
-                              int class,
-                              int type,
-                              unsigned char *answer,
-                              int anslen);
-       int (*libc___res_nquery)(struct __res_state *state,
+typedef int (*__libc_res_ninit)(struct __res_state *state);
+typedef int (*__libc___res_ninit)(struct __res_state *state);
+typedef void (*__libc_res_nclose)(struct __res_state *state);
+typedef void (*__libc___res_nclose)(struct __res_state *state);
+typedef int (*__libc_res_nquery)(struct __res_state *state,
                                 const char *dname,
                                 int class,
                                 int type,
                                 unsigned char *answer,
                                 int anslen);
-       int (*libc_res_nsearch)(struct __res_state *state,
-                               const char *dname,
-                               int class,
-                               int type,
-                               unsigned char *answer,
-                               int anslen);
-       int (*libc___res_nsearch)(struct __res_state *state,
+typedef int (*__libc___res_nquery)(struct __res_state *state,
+                                  const char *dname,
+                                  int class,
+                                  int type,
+                                  unsigned char *answer,
+                                  int anslen);
+typedef int (*__libc_res_nsearch)(struct __res_state *state,
                                  const char *dname,
                                  int class,
                                  int type,
                                  unsigned char *answer,
                                  int anslen);
+typedef int (*__libc___res_nsearch)(struct __res_state *state,
+                                   const char *dname,
+                                   int class,
+                                   int type,
+                                   unsigned char *answer,
+                                   int anslen);
+
+#define RWRAP_SYMBOL_ENTRY(i) \
+       union { \
+               __libc_##i f; \
+               void *obj; \
+       } _libc_##i
+
+struct rwrap_libc_symbols {
+       RWRAP_SYMBOL_ENTRY(res_ninit);
+       RWRAP_SYMBOL_ENTRY(__res_ninit);
+       RWRAP_SYMBOL_ENTRY(res_nclose);
+       RWRAP_SYMBOL_ENTRY(__res_nclose);
+       RWRAP_SYMBOL_ENTRY(res_nquery);
+       RWRAP_SYMBOL_ENTRY(__res_nquery);
+       RWRAP_SYMBOL_ENTRY(res_nsearch);
+       RWRAP_SYMBOL_ENTRY(__res_nsearch);
 };
+#undef RWRAP_SYMBOL_ENTRY
 
 struct rwrap {
-       void *libc_handle;
-       void *libresolv_handle;
+       struct {
+               void *handle;
+               struct rwrap_libc_symbols symbols;
+       } libc;
+
+       struct {
+               void *handle;
+               struct rwrap_libc_symbols symbols;
+       } libresolv;
 
        bool initialised;
        bool enabled;
 
        char *socket_dir;
-
-       struct rwrap_libc_fns fns;
 };
 
 static struct rwrap rwrap;
@@ -1063,7 +1080,7 @@ static void *rwrap_load_lib_handle(enum rwrap_lib lib)
        switch (lib) {
        case RWRAP_LIBRESOLV:
 #ifdef HAVE_LIBRESOLV
-               handle = rwrap.libresolv_handle;
+               handle = rwrap.libresolv.handle;
                if (handle == NULL) {
                        for (i = 10; i >= 0; i--) {
                                char soname[256] = {0};
@@ -1075,18 +1092,18 @@ static void *rwrap_load_lib_handle(enum rwrap_lib lib)
                                }
                        }
 
-                       rwrap.libresolv_handle = handle;
+                       rwrap.libresolv.handle = handle;
                }
                break;
 #endif
                /* FALL TROUGH */
        case RWRAP_LIBC:
-               handle = rwrap.libc_handle;
+               handle = rwrap.libc.handle;
 #ifdef LIBC_SO
                if (handle == NULL) {
                        handle = dlopen(LIBC_SO, flags);
 
-                       rwrap.libc_handle = handle;
+                       rwrap.libc.handle = handle;
                }
 #endif
                if (handle == NULL) {
@@ -1100,14 +1117,14 @@ static void *rwrap_load_lib_handle(enum rwrap_lib lib)
                                }
                        }
 
-                       rwrap.libc_handle = handle;
+                       rwrap.libc.handle = handle;
                }
                break;
        }
 
        if (handle == NULL) {
 #ifdef RTLD_NEXT
-               handle = rwrap.libc_handle = rwrap.libresolv_handle = RTLD_NEXT;
+               handle = rwrap.libc.handle = rwrap.libresolv.handle = RTLD_NEXT;
 #else
                RWRAP_LOG(RWRAP_LOG_ERROR,
                          "Failed to dlopen library: %s\n",
@@ -1119,7 +1136,7 @@ static void *rwrap_load_lib_handle(enum rwrap_lib lib)
        return handle;
 }
 
-static void *_rwrap_load_lib_function(enum rwrap_lib lib, const char *fn_name)
+static void *_rwrap_bind_symbol(enum rwrap_lib lib, const char *fn_name)
 {
        void *handle;
        void *func;
@@ -1140,10 +1157,16 @@ static void *_rwrap_load_lib_function(enum rwrap_lib 
lib, const char *fn_name)
        return func;
 }
 
-#define rwrap_load_lib_function(lib, fn_name) \
-       if (rwrap.fns.libc_##fn_name == NULL) { \
-               *(void **) (&rwrap.fns.libc_##fn_name) = \
-                       _rwrap_load_lib_function(lib, #fn_name); \
+#define rwrap_bind_symbol_libc(sym_name) \
+       if (rwrap.libc.symbols._libc_##sym_name.obj == NULL) { \
+               rwrap.libc.symbols._libc_##sym_name.obj = \
+                       _rwrap_bind_symbol(RWRAP_LIBC, #sym_name); \
+       }
+
+#define rwrap_bind_symbol_libresolv(sym_name) \
+       if (rwrap.libresolv.symbols._libc_##sym_name.obj == NULL) { \
+               rwrap.libresolv.symbols._libc_##sym_name.obj = \
+                       _rwrap_bind_symbol(RWRAP_LIBRESOLV, #sym_name); \
        }
 
 /*
@@ -1154,36 +1177,25 @@ static void *_rwrap_load_lib_function(enum rwrap_lib 
lib, const char *fn_name)
  * has probably something todo with with the linker.
  * So we need load each function at the point it is called the first time.
  */
-#if 0
-static int libc_res_init(void)
-{
-#if defined(HAVE_RES_INIT)
-       rwrap_load_lib_function(RWRAP_LIBRESOLV, res_init);
-
-       return rwrap.fns.libc_res_init();
-#elif defined(HAVE___RES_INIT)
-       rwrap_load_lib_function(RWRAP_LIBRESOLV, __res_init);
-
-       return rwrap.fns.libc___res_init();
-#endif
-}
-#endif
 
 static int libc_res_ninit(struct __res_state *state)
 {
-#if defined(HAVE_RES_NINIT)
+#if !defined(res_ninit) && defined(HAVE_RES_NINIT)
 
 #if defined(HAVE_RES_NINIT_IN_LIBRESOLV)
-       rwrap_load_lib_function(RWRAP_LIBRESOLV, res_ninit);
+       rwrap_bind_symbol_libresolv(res_ninit);
+
+       return rwrap.libresolv.symbols._libc_res_ninit.f(state);
 #else /* HAVE_RES_NINIT_IN_LIBRESOLV */
-       rwrap_load_lib_function(RWRAP_LIBC, res_ninit);
+       rwrap_bind_symbol_libc(res_ninit);
+
+       return rwrap.libc.symbols._libc_res_ninit.f(state);
 #endif /* HAVE_RES_NINIT_IN_LIBRESOLV */
 
-       return rwrap.fns.libc_res_ninit(state);
 #elif defined(HAVE___RES_NINIT)
-       rwrap_load_lib_function(RWRAP_LIBC, __res_ninit);
+       rwrap_bind_symbol_libc(__res_ninit);
 
-       return rwrap.fns.libc___res_ninit(state);
+       return rwrap.libc.symbols._libc___res_ninit.f(state);
 #else
 #error "No res_ninit function"
 #endif
@@ -1191,19 +1203,24 @@ static int libc_res_ninit(struct __res_state *state)
 
 static void libc_res_nclose(struct __res_state *state)
 {
-#if defined(HAVE_RES_NCLOSE)
+#if !defined(res_close) && defined(HAVE_RES_NCLOSE)
 
 #if defined(HAVE_RES_NCLOSE_IN_LIBRESOLV)
-       rwrap_load_lib_function(RWRAP_LIBRESOLV, res_nclose);
+       rwrap_bind_symbol_libresolv(res_nclose);
+
+       rwrap.libresolv.symbols._libc_res_nclose.f(state);
+       return;
 #else /* HAVE_RES_NCLOSE_IN_LIBRESOLV */
-       rwrap_load_lib_function(RWRAP_LIBC, res_nclose);
+       rwrap_bind_symbol_libc(res_nclose);
+
+       rwrap.libc.symbols._libc_res_nclose.f(state);
+       return;
 #endif /* HAVE_RES_NCLOSE_IN_LIBRESOLV */
 
-       rwrap.fns.libc_res_nclose(state);
 #elif defined(HAVE___RES_NCLOSE)
-       rwrap_load_lib_function(RWRAP_LIBC, __res_nclose);
+       rwrap_bind_symbol_libc(__res_nclose);
 
-       rwrap.fns.libc___res_nclose(state);
+       rwrap.libc.symbols._libc___res_nclose.f(state);
 #else
 #error "No res_nclose function"
 #endif
@@ -1216,24 +1233,24 @@ static int libc_res_nquery(struct __res_state *state,
                           unsigned char *answer,
                           int anslen)
 {
-#if defined(HAVE_RES_NQUERY)
-       rwrap_load_lib_function(RWRAP_LIBRESOLV, res_nquery);
-
-       return rwrap.fns.libc_res_nquery(state,
-                                        dname,
-                                        class,
-                                        type,
-                                        answer,
-                                        anslen);
+#if !defined(res_nquery) && defined(HAVE_RES_NQUERY)
+       rwrap_bind_symbol_libresolv(res_nquery);
+
+       return rwrap.libresolv.symbols._libc_res_nquery.f(state,
+                                                         dname,
+                                                         class,
+                                                         type,
+                                                         answer,
+                                                         anslen);
 #elif defined(HAVE___RES_NQUERY)
-       rwrap_load_lib_function(RWRAP_LIBRESOLV, __res_nquery);
-
-       return rwrap.fns.libc___res_nquery(state,
-                                          dname,
-                                          class,
-                                          type,
-                                          answer,
-                                          anslen);
+       rwrap_bind_symbol_libresolv(__res_nquery);
+
+       return rwrap.libresolv.symbols._libc___res_nquery.f(state,
+                                                           dname,
+                                                           class,
+                                                           type,
+                                                           answer,
+                                                           anslen);
 #else
 #error "No res_nquery function"
 #endif
@@ -1246,24 +1263,24 @@ static int libc_res_nsearch(struct __res_state *state,
                            unsigned char *answer,
                            int anslen)
 {
-#if defined(HAVE_RES_NSEARCH)
-       rwrap_load_lib_function(RWRAP_LIBRESOLV, res_nsearch);
-
-       return rwrap.fns.libc_res_nsearch(state,
-                                         dname,
-                                         class,
-                                         type,
-                                         answer,
-                                         anslen);
+#if !defined(res_nsearch) && defined(HAVE_RES_NSEARCH)
+       rwrap_bind_symbol_libresolv(res_nsearch);
+
+       return rwrap.libresolv.symbols._libc_res_nsearch.f(state,
+                                                          dname,
+                                                          class,
+                                                          type,
+                                                          answer,
+                                                          anslen);
 #elif defined(HAVE___RES_NSEARCH)
-       rwrap_load_lib_function(RWRAP_LIBRESOLV, __res_nsearch);
-
-       return rwrap.fns.libc___res_nsearch(state,
-                                           dname,
-                                           class,
-                                           type,
-                                           answer,
-                                           anslen);
+       rwrap_bind_symbol_libresolv(__res_nsearch);
+
+       return rwrap.libresolv.symbols._libc___res_nsearch.f(state,
+                                                            dname,
+                                                            class,
+                                                            type,
+                                                            answer,
+                                                            anslen);
 #else
 #error "No res_nsearch function"
 #endif
@@ -1418,7 +1435,7 @@ static int rwrap_res_ninit(struct __res_state *state)
        return rc;
 }
 
-#if defined(HAVE_RES_NINIT)
+#if !defined(res_ninit) && defined(HAVE_RES_NINIT)
 int res_ninit(struct __res_state *state)
 #elif defined(HAVE___RES_NINIT)
 int __res_ninit(struct __res_state *state)
@@ -1442,7 +1459,7 @@ static int rwrap_res_init(void)
        return rc;
 }
 
-#if defined(HAVE_RES_INIT)
+#if !defined(res_ninit) && defined(HAVE_RES_INIT)
 int res_init(void)
 #elif defined(HAVE___RES_INIT)
 int __res_init(void)
@@ -1472,7 +1489,7 @@ static void rwrap_res_nclose(struct __res_state *state)
 #endif
 }
 
-#if defined(HAVE_RES_NCLOSE)
+#if !defined(res_nclose) && defined(HAVE_RES_NCLOSE)
 void res_nclose(struct __res_state *state)
 #elif defined(HAVE___RES_NCLOSE)
 void __res_nclose(struct __res_state *state)
@@ -1545,7 +1562,7 @@ static int rwrap_res_nquery(struct __res_state *state,
        return rc;
 }
 
-#if defined(HAVE_RES_NQUERY)
+#if !defined(res_nquery) && defined(HAVE_RES_NQUERY)
 int res_nquery(struct __res_state *state,
               const char *dname,
               int class,
@@ -1591,7 +1608,7 @@ static int rwrap_res_query(const char *dname,
        return rc;
 }
 
-#if defined(HAVE_RES_QUERY)
+#if !defined(res_query) && defined(HAVE_RES_QUERY)
 int res_query(const char *dname,
              int class,
              int type,
@@ -1653,7 +1670,7 @@ static int rwrap_res_nsearch(struct __res_state *state,
        return rc;
 }
 
-#if defined(HAVE_RES_NSEARCH)
+#if !defined(res_nsearch) && defined(HAVE_RES_NSEARCH)
 int res_nsearch(struct __res_state *state,
                const char *dname,
                int class,
@@ -1699,7 +1716,7 @@ static int rwrap_res_search(const char *dname,
        return rc;
 }
 
-#if defined(HAVE_RES_SEARCH)
+#if !defined(res_search) && defined(HAVE_RES_SEARCH)
 int res_search(const char *dname,
               int class,
               int type,
diff --git a/tests/test_dns_fake.c b/tests/test_dns_fake.c
index 527ea71..9bc92cd 100644
--- a/tests/test_dns_fake.c
+++ b/tests/test_dns_fake.c
@@ -563,21 +563,21 @@ int main(void)
 {
        int rc;
 
-       const UnitTest tests[] = {
-               unit_test(test_res_fake_a_query),
-               unit_test(test_res_fake_a_query_case_insensitive),
-               unit_test(test_res_fake_a_query_trailing_dot),
-               unit_test(test_res_fake_a_query_notfound),
-               unit_test(test_res_fake_aaaa_query),
-               unit_test(test_res_fake_aaaa_query_notfound),
-               unit_test(test_res_fake_srv_query),
-               unit_test(test_res_fake_srv_query_minimal),
-               unit_test(test_res_fake_soa_query),
-               unit_test(test_res_fake_cname_query),
-               unit_test(test_res_fake_a_via_cname),
+       const struct CMUnitTest fake_tests[] = {
+               cmocka_unit_test(test_res_fake_a_query),
+               cmocka_unit_test(test_res_fake_a_query_case_insensitive),
+               cmocka_unit_test(test_res_fake_a_query_trailing_dot),
+               cmocka_unit_test(test_res_fake_a_query_notfound),
+               cmocka_unit_test(test_res_fake_aaaa_query),
+               cmocka_unit_test(test_res_fake_aaaa_query_notfound),
+               cmocka_unit_test(test_res_fake_srv_query),
+               cmocka_unit_test(test_res_fake_srv_query_minimal),
+               cmocka_unit_test(test_res_fake_soa_query),
+               cmocka_unit_test(test_res_fake_cname_query),
+               cmocka_unit_test(test_res_fake_a_via_cname),
        };
 
-       rc = run_tests(tests);
+       rc = cmocka_run_group_tests(fake_tests, NULL, NULL);
 
        return rc;
 }
diff --git a/tests/test_real_res_query.c b/tests/test_real_res_query.c
index 9c8132a..04ade89 100644
--- a/tests/test_real_res_query.c
+++ b/tests/test_real_res_query.c
@@ -189,12 +189,12 @@ int main(void)
 {
        int rc;
 
-       const UnitTest tests[] = {
-               unit_test(test_res_query_a_record),
-               unit_test(test_res_query_srv_record),
+       const struct CMUnitTest real_tests[] = {
+               cmocka_unit_test(test_res_query_a_record),
+               cmocka_unit_test(test_res_query_srv_record),
        };
 
-       rc = run_tests(tests);
+       rc = cmocka_run_group_tests(real_tests, NULL, NULL);
 
        return rc;
 }
diff --git a/tests/test_res_init.c b/tests/test_res_init.c
index e42b8a4..5cd3591 100644
--- a/tests/test_res_init.c
+++ b/tests/test_res_init.c
@@ -23,7 +23,7 @@ struct resolv_conf_test_state {
        char *resolv_conf_path;
 };
 
-static void setup(void **state)
+static int setup(void **state)
 {
        struct resolv_conf_test_state *test_state;
 
@@ -40,15 +40,17 @@ static void setup(void **state)
        assert_non_null(test_state->resolv_conf);
 
        *state = test_state;
+
+       return 0;
 }
 
-static void teardown(void **state)
+static int teardown(void **state)
 {
        struct resolv_conf_test_state *test_state;
 
        test_state = (struct resolv_conf_test_state *) *state;
 
-       if (test_state == NULL) return;
+       if (test_state == NULL) return -1;
 
        if (test_state->resolv_conf) {
                fclose(test_state->resolv_conf);
@@ -64,6 +66,8 @@ static void teardown(void **state)
        }
 
        free(test_state);
+


-- 
Resolv Wrapper Repository

Reply via email to