pikhq / musl-nscd

Musl-nscd is an implementation of the NSCD protocol, suitable for use with musl and with standard NSS modules
Other
46 stars 14 forks source link

possibility of integration with mdns? #32

Open tigerinus opened 3 years ago

tigerinus commented 3 years ago

Tried to build libnss_mdns against musl-nscd-dev on Alpine. However got errors when building libnss_mdns against musl-nscd-dev:

$ make -j4
make  all-am
make[1]: Entering directory '/mnt/home/wxh/junk/nss-mdns-0.15.1'
  CC       src/libnss_mdns_la-util.lo
  CC       src/libnss_mdns_la-avahi.lo
  CC       src/libnss_mdns_la-nss.lo
  CC       src/libnss_mdns4_la-util.lo
In file included from src/util.c:32:
src/util.h:114:54: warning: 'struct gaih_addrtuple' declared inside parameter list will not be visible outside of this definition or declaration
  114 |                                               struct gaih_addrtuple** pat,
      |                                                      ^~~~~~~~~~~~~~
src/util.c: In function 'local_soa':
src/util.c:125:14: warning: implicit declaration of function 'res_ninit'; did you mean 'res_init'? [-Wimplicit-function-declaration]
  125 |     result = res_ninit(&state);
      |              ^~~~~~~~~
      |              res_init
src/util.c:129:9: warning: implicit declaration of function 'res_nquery'; did you mean 'res_query'? [-Wimplicit-function-declaration]
  129 |         res_nquery(&state, "local", ns_c_in, ns_t_soa, answer, sizeof answer);
      |         ^~~~~~~~~~
      |         res_query
src/util.c:130:5: warning: implicit declaration of function 'res_nclose' [-Wimplicit-function-declaration]
  130 |     res_nclose(&state);
      |     ^~~~~~~~~~
src/util.c: At top level:
src/util.c:217:54: warning: 'struct gaih_addrtuple' declared inside parameter list will not be visible outside of this definition or declaration
  217 |                                               struct gaih_addrtuple** pat,
      |                                                      ^~~~~~~~~~~~~~
src/util.c:215:17: error: conflicting types for 'convert_userdata_to_addrtuple'
  215 | enum nss_status convert_userdata_to_addrtuple(const userdata_t* u,
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from src/util.c:32:
src/util.h:112:17: note: previous declaration of 'convert_userdata_to_addrtuple' was here
  112 | enum nss_status convert_userdata_to_addrtuple(const userdata_t* u,
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/util.c: In function 'convert_userdata_to_addrtuple':
src/util.c:237:36: error: invalid application of 'sizeof' to incomplete type 'struct gaih_addrtuple'
  237 |             memset(tuple, 0, sizeof(*tuple));
      |                                    ^
src/util.c:240:46: error: invalid application of 'sizeof' to incomplete type 'struct gaih_addrtuple'
  240 |             tuple = buffer_alloc(buf, sizeof(struct gaih_addrtuple));
      |                                              ^~~~~~
src/util.c:248:14: error: invalid use of undefined type 'struct gaih_addrtuple'
  248 |         tuple->name = buffer_name;
      |              ^~
src/util.c:251:14: error: invalid use of undefined type 'struct gaih_addrtuple'
  251 |         tuple->family = result->af;
      |              ^~
src/util.c:254:23: error: invalid use of undefined type 'struct gaih_addrtuple'
  254 |         memcpy(&(tuple->addr), &(result->address), address_length);
      |                       ^~
src/util.c:257:14: error: invalid use of undefined type 'struct gaih_addrtuple'
  257 |         tuple->scopeid = result->scopeid;
      |              ^~
src/util.c:265:23: error: invalid use of undefined type 'struct gaih_addrtuple'
  265 |             tuple_prev->next = tuple;
      |                       ^~
In file included from src/nss.c:35:
src/util.h:114:54: warning: 'struct gaih_addrtuple' declared inside parameter list will not be visible outside of this definition or declaration
  114 |                                               struct gaih_addrtuple** pat,
      |                                                      ^~~~~~~~~~~~~~
In file included from src/nss.c:36:
src/nss.h:38:64: warning: 'struct gaih_addrtuple' declared inside parameter list will not be visible outside of this definition or declaration
   38 | enum nss_status _nss_mdns_gethostbyname4_r(const char*, struct gaih_addrtuple**,
      |                                                                ^~~~~~~~~~~~~~
src/nss.c:152:51: warning: 'struct gaih_addrtuple' declared inside parameter list will not be visible outside of this definition or declaration
  152 |                                            struct gaih_addrtuple** pat,
      |                                                   ^~~~~~~~~~~~~~
src/nss.c:151:17: error: conflicting types for '_nss_mdns_gethostbyname4_r'
  151 | enum nss_status _nss_mdns_gethostbyname4_r(const char* name,
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from src/avahi.c:34:
src/util.h:114:54: warning: 'struct gaih_addrtuple' declared inside parameter list will not be visible outside of this definition or declaration
  114 |                                               struct gaih_addrtuple** pat,
      |                                                      ^~~~~~~~~~~~~~
In file included from src/nss.c:36:
src/nss.h:38:17: note: previous declaration of '_nss_mdns_gethostbyname4_r' was here
   38 | enum nss_status _nss_mdns_gethostbyname4_r(const char*, struct gaih_addrtuple**,
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~
make[1]: *** [Makefile:1156: src/libnss_mdns_la-util.lo] Error 1
make[1]: *** Waiting for unfinished jobs....
src/nss.c: In function '_nss_mdns_gethostbyname4_r':
src/nss.c:168:52: warning: passing argument 3 of 'convert_userdata_to_addrtuple' from incompatible pointer type [-Wincompatible-pointer-types]
  168 |     return convert_userdata_to_addrtuple(&u, name, pat, &buf, errnop, h_errnop);
      |                                                    ^~~
      |                                                    |
      |                                                    struct gaih_addrtuple **
In file included from src/nss.c:35:
src/util.h:114:71: note: expected 'struct gaih_addrtuple **' but argument is of type 'struct gaih_addrtuple **'
  114 |                                               struct gaih_addrtuple** pat,
      |                                               ~~~~~~~~~~~~~~~~~~~~~~~~^~~
In file included from src/util.c:32:
src/util.h:114:54: warning: 'struct gaih_addrtuple' declared inside parameter list will not be visible outside of this definition or declaration
  114 |                                               struct gaih_addrtuple** pat,
      |                                                      ^~~~~~~~~~~~~~
src/util.c: In function 'local_soa':
src/util.c:125:14: warning: implicit declaration of function 'res_ninit'; did you mean 'res_init'? [-Wimplicit-function-declaration]
  125 |     result = res_ninit(&state);
      |              ^~~~~~~~~
      |              res_init
src/util.c:129:9: warning: implicit declaration of function 'res_nquery'; did you mean 'res_query'? [-Wimplicit-function-declaration]
  129 |         res_nquery(&state, "local", ns_c_in, ns_t_soa, answer, sizeof answer);
      |         ^~~~~~~~~~
      |         res_query
src/util.c:130:5: warning: implicit declaration of function 'res_nclose' [-Wimplicit-function-declaration]
  130 |     res_nclose(&state);
      |     ^~~~~~~~~~
make[1]: *** [Makefile:1170: src/libnss_mdns_la-nss.lo] Error 1
src/util.c: At top level:
src/util.c:217:54: warning: 'struct gaih_addrtuple' declared inside parameter list will not be visible outside of this definition or declaration
  217 |                                               struct gaih_addrtuple** pat,
      |                                                      ^~~~~~~~~~~~~~
src/util.c:215:17: error: conflicting types for 'convert_userdata_to_addrtuple'
  215 | enum nss_status convert_userdata_to_addrtuple(const userdata_t* u,
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from src/util.c:32:
src/util.h:112:17: note: previous declaration of 'convert_userdata_to_addrtuple' was here
  112 | enum nss_status convert_userdata_to_addrtuple(const userdata_t* u,
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/util.c: In function 'convert_userdata_to_addrtuple':
src/util.c:237:36: error: invalid application of 'sizeof' to incomplete type 'struct gaih_addrtuple'
  237 |             memset(tuple, 0, sizeof(*tuple));
      |                                    ^
src/util.c:240:46: error: invalid application of 'sizeof' to incomplete type 'struct gaih_addrtuple'
  240 |             tuple = buffer_alloc(buf, sizeof(struct gaih_addrtuple));
      |                                              ^~~~~~
src/util.c:248:14: error: invalid use of undefined type 'struct gaih_addrtuple'
  248 |         tuple->name = buffer_name;
      |              ^~
src/util.c:251:14: error: invalid use of undefined type 'struct gaih_addrtuple'
  251 |         tuple->family = result->af;
      |              ^~
src/util.c:254:23: error: invalid use of undefined type 'struct gaih_addrtuple'
  254 |         memcpy(&(tuple->addr), &(result->address), address_length);
      |                       ^~
src/util.c:257:14: error: invalid use of undefined type 'struct gaih_addrtuple'
  257 |         tuple->scopeid = result->scopeid;
      |              ^~
src/util.c:265:23: error: invalid use of undefined type 'struct gaih_addrtuple'
  265 |             tuple_prev->next = tuple;
      |                       ^~
make[1]: *** [Makefile:1177: src/libnss_mdns4_la-util.lo] Error 1
make[1]: Leaving directory '/mnt/home/wxh/junk/nss-mdns-0.15.1'
make: *** [Makefile:819: all] Error 2
 wxh@lg-blk ~/junk/nss-mdns-0.15.1  1.638s  2 ❯ CFLAGS="-O3" CFLAG="-O3" make -j4
make  all-am
make[1]: Entering directory '/mnt/home/wxh/junk/nss-mdns-0.15.1'
  CC       src/libnss_mdns_la-util.lo
  CC       src/libnss_mdns_la-nss.lo
  CC       src/libnss_mdns4_la-util.lo
  CC       src/libnss_mdns4_la-avahi.lo
In file included from src/util.c:32:
src/util.h:114:54: warning: 'struct gaih_addrtuple' declared inside parameter list will not be visible outside of this definition or declaration
  114 |                                               struct gaih_addrtuple** pat,
      |                                                      ^~~~~~~~~~~~~~
In file included from src/avahi.c:34:
src/util.h:114:54: warning: 'struct gaih_addrtuple' declared inside parameter list will not be visible outside of this definition or declaration
  114 |                                               struct gaih_addrtuple** pat,
      |                                                      ^~~~~~~~~~~~~~
src/util.c: In function 'local_soa':
src/util.c:125:14: warning: implicit declaration of function 'res_ninit'; did you mean 'res_init'? [-Wimplicit-function-declaration]
  125 |     result = res_ninit(&state);
      |              ^~~~~~~~~
      |              res_init
src/util.c:129:9: warning: implicit declaration of function 'res_nquery'; did you mean 'res_query'? [-Wimplicit-function-declaration]
  129 |         res_nquery(&state, "local", ns_c_in, ns_t_soa, answer, sizeof answer);
      |         ^~~~~~~~~~
      |         res_query
src/util.c:130:5: warning: implicit declaration of function 'res_nclose' [-Wimplicit-function-declaration]
  130 |     res_nclose(&state);
      |     ^~~~~~~~~~
src/util.c: At top level:
src/util.c:217:54: warning: 'struct gaih_addrtuple' declared inside parameter list will not be visible outside of this definition or declaration
  217 |                                               struct gaih_addrtuple** pat,
      |                                                      ^~~~~~~~~~~~~~
src/util.c:215:17: error: conflicting types for 'convert_userdata_to_addrtuple'
  215 | enum nss_status convert_userdata_to_addrtuple(const userdata_t* u,
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from src/util.c:32:
src/util.h:112:17: note: previous declaration of 'convert_userdata_to_addrtuple' was here
  112 | enum nss_status convert_userdata_to_addrtuple(const userdata_t* u,
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/util.c: In function 'convert_userdata_to_addrtuple':
src/util.c:237:36: error: invalid application of 'sizeof' to incomplete type 'struct gaih_addrtuple'
  237 |             memset(tuple, 0, sizeof(*tuple));
      |                                    ^
src/util.c:240:46: error: invalid application of 'sizeof' to incomplete type 'struct gaih_addrtuple'
  240 |             tuple = buffer_alloc(buf, sizeof(struct gaih_addrtuple));
      |                                              ^~~~~~
src/util.c:248:14: error: invalid use of undefined type 'struct gaih_addrtuple'
  248 |         tuple->name = buffer_name;
      |              ^~
src/util.c:251:14: error: invalid use of undefined type 'struct gaih_addrtuple'
  251 |         tuple->family = result->af;
      |              ^~
src/util.c:254:23: error: invalid use of undefined type 'struct gaih_addrtuple'
  254 |         memcpy(&(tuple->addr), &(result->address), address_length);
      |                       ^~
src/util.c:257:14: error: invalid use of undefined type 'struct gaih_addrtuple'
  257 |         tuple->scopeid = result->scopeid;
      |              ^~
src/util.c:265:23: error: invalid use of undefined type 'struct gaih_addrtuple'
  265 |             tuple_prev->next = tuple;
      |                       ^~
In file included from src/util.c:32:
src/util.h:114:54: warning: 'struct gaih_addrtuple' declared inside parameter list will not be visible outside of this definition or declaration
  114 |                                               struct gaih_addrtuple** pat,
      |                                                      ^~~~~~~~~~~~~~
In file included from src/nss.c:35:
src/util.h:114:54: warning: 'struct gaih_addrtuple' declared inside parameter list will not be visible outside of this definition or declaration
  114 |                                               struct gaih_addrtuple** pat,
      |                                                      ^~~~~~~~~~~~~~
In file included from src/nss.c:36:
src/nss.h:38:64: warning: 'struct gaih_addrtuple' declared inside parameter list will not be visible outside of this definition or declaration
   38 | enum nss_status _nss_mdns_gethostbyname4_r(const char*, struct gaih_addrtuple**,
      |                                                                ^~~~~~~~~~~~~~
src/util.c: In function 'local_soa':
src/util.c:125:14: warning: implicit declaration of function 'res_ninit'; did you mean 'res_init'? [-Wimplicit-function-declaration]
  125 |     result = res_ninit(&state);
      |              ^~~~~~~~~
      |              res_init
src/util.c:129:9: warning: implicit declaration of function 'res_nquery'; did you mean 'res_query'? [-Wimplicit-function-declaration]
  129 |         res_nquery(&state, "local", ns_c_in, ns_t_soa, answer, sizeof answer);
      |         ^~~~~~~~~~
      |         res_query
src/nss.c:152:51: warning: 'struct gaih_addrtuple' declared inside parameter list will not be visible outside of this definition or declaration
  152 |                                            struct gaih_addrtuple** pat,
      |                                                   ^~~~~~~~~~~~~~
src/nss.c:151:17: error: conflicting types for '_nss_mdns_gethostbyname4_r'
  151 | enum nss_status _nss_mdns_gethostbyname4_r(const char* name,
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from src/nss.c:36:
src/nss.h:38:17: note: previous declaration of '_nss_mdns_gethostbyname4_r' was here
   38 | enum nss_status _nss_mdns_gethostbyname4_r(const char*, struct gaih_addrtuple**,
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~
src/nss.c: In function '_nss_mdns_gethostbyname4_r':
src/nss.c:168:52: warning: passing argument 3 of 'convert_userdata_to_addrtuple' from incompatible pointer type [-Wincompatible-pointer-types]
  168 |     return convert_userdata_to_addrtuple(&u, name, pat, &buf, errnop, h_errnop);
      |                                                    ^~~
      |                                                    |
      |                                                    struct gaih_addrtuple **
In file included from src/nss.c:35:
src/util.h:114:71: note: expected 'struct gaih_addrtuple **' but argument is of type 'struct gaih_addrtuple **'
  114 |                                               struct gaih_addrtuple** pat,
      |                                               ~~~~~~~~~~~~~~~~~~~~~~~~^~~
make[1]: *** [Makefile:1156: src/libnss_mdns_la-util.lo] Error 1
make[1]: *** Waiting for unfinished jobs....
src/util.c:130:5: warning: implicit declaration of function 'res_nclose' [-Wimplicit-function-declaration]
  130 |     res_nclose(&state);
      |     ^~~~~~~~~~
src/util.c: At top level:
src/util.c:217:54: warning: 'struct gaih_addrtuple' declared inside parameter list will not be visible outside of this definition or declaration
  217 |                                               struct gaih_addrtuple** pat,
      |                                                      ^~~~~~~~~~~~~~
src/util.c:215:17: error: conflicting types for 'convert_userdata_to_addrtuple'
  215 | enum nss_status convert_userdata_to_addrtuple(const userdata_t* u,
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from src/util.c:32:
src/util.h:112:17: note: previous declaration of 'convert_userdata_to_addrtuple' was here
  112 | enum nss_status convert_userdata_to_addrtuple(const userdata_t* u,
      |                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
src/util.c: In function 'convert_userdata_to_addrtuple':
src/util.c:237:36: error: invalid application of 'sizeof' to incomplete type 'struct gaih_addrtuple'
  237 |             memset(tuple, 0, sizeof(*tuple));
      |                                    ^
src/util.c:240:46: error: invalid application of 'sizeof' to incomplete type 'struct gaih_addrtuple'
  240 |             tuple = buffer_alloc(buf, sizeof(struct gaih_addrtuple));
      |                                              ^~~~~~
src/util.c:248:14: error: invalid use of undefined type 'struct gaih_addrtuple'
  248 |         tuple->name = buffer_name;
      |              ^~
src/util.c:251:14: error: invalid use of undefined type 'struct gaih_addrtuple'
  251 |         tuple->family = result->af;
      |              ^~
src/util.c:254:23: error: invalid use of undefined type 'struct gaih_addrtuple'
  254 |         memcpy(&(tuple->addr), &(result->address), address_length);
      |                       ^~
src/util.c:257:14: error: invalid use of undefined type 'struct gaih_addrtuple'
  257 |         tuple->scopeid = result->scopeid;
      |              ^~
src/util.c:265:23: error: invalid use of undefined type 'struct gaih_addrtuple'
  265 |             tuple_prev->next = tuple;
      |                       ^~
make[1]: *** [Makefile:1170: src/libnss_mdns_la-nss.lo] Error 1
make[1]: *** [Makefile:1177: src/libnss_mdns4_la-util.lo] Error 1
make[1]: Leaving directory '/mnt/home/wxh/junk/nss-mdns-0.15.1'
make: *** [Makefile:819: all] Error 2
predators46 commented 10 months ago

@tigerinus

i made a patch can you try this building nss-mdns on alpine

#ifndef _NSS_H
#define _NSS_H  1

#include <features.h>
#include <stddef.h>
#include <stdint.h>
#include <sys/types.h>

/* Possible results of lookup using a nss_* function.  */
enum nss_status
{
  NSS_STATUS_TRYAGAIN = -2,
  NSS_STATUS_UNAVAIL,
  NSS_STATUS_NOTFOUND,
  NSS_STATUS_SUCCESS,
  NSS_STATUS_RETURN
};

/* Data structure used for the 'gethostbyname4_r' function.  */
struct gaih_addrtuple
  {
    struct gaih_addrtuple *next;
    char *name;
    int family;
    uint32_t addr[4];
    uint32_t scopeid;
  };

#endif
tigerinus commented 10 months ago

@predators46 I've moved on to some other project, and lost the original environment for this issue.

I'm sorry I might not be able to help with testing ur patch.

Thanks for following up anyway!

ericonr commented 3 months ago

mdns integration doesn't make sense for this project at the moment.

About nss-mdns, I'm not sure that would be possible. musl itself does not query ncsd for DNS requests, because it's a complicated protocol, and it's simpler for them to perform a DNS request to a local resolver, which can be the one implementing mDNS.