<commit_before>/*
  This file is part of nss-mdns.

  nss-mdns is free software; you can redistribute it and/or modify
  it under the terms of the GNU Lesser General Public License as published
  by the Free Software Foundation; either version 2 of the License,
  or (at your option) any later version.

  nss-mdns is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with nss-mdns; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

/* Original author: <NAME> <<EMAIL>> */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <sys/param.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/uio.h>
#include <sys/socket.h>
#include <sys/ktrace.h>

#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include <errno.h>
#include <pwd.h>
#include <grp.h>
#include <nss.h>

#include <netinet/in.h>
#include <netdb.h>

#include "avahi.h"
#include "config.h"
#include "util.h"

#ifdef MDNS_MINIMAL
/*
 * FreeBSD support prefers Avahi.
 */
#endif

/*
 * To turn on utrace() records, compile with -DDEBUG_UTRACE.
 */
#ifdef DEBUG_UTRACE
#define _NSS_UTRACE(msg)                                                       \
    do {                                                                       \
        static const char __msg[] = msg;                                       \
        (void)utrace(__msg, sizeof(__msg));                                    \
    } while (0)
#else
#define _NSS_UTRACE(msg)
#endif

ns_mtab* nss_module_register(const char* source, unsigned int* mtabsize,
                             nss_module_unregister_fn* unreg);

extern enum nss_status _nss_mdns_gethostbyname_r(const char* name,
                                                 struct hostent* result,
                                                 char* buffer, size_t buflen,
                                                 int* errnop, int* h_errnop);

extern enum nss_status _nss_mdns_gethostbyname2_r(const char* name, int af,
                                                  struct hostent* result,
                                                  char* buffer, size_t buflen,
                                                  int* errnop, int* h_errnop);
extern enum nss_status _nss_mdns_gethostbyaddr_r(struct in_addr* addr, int len,
                                                 int type,
                                                 struct hostent* result,
                                                 char* buffer, size_t buflen,
                                                 int* errnop, int* h_errnop);
extern enum nss_status _nss_mdns4_gethostbyname_r(const char* name,
                                                  struct hostent* result,
                                                  char* buffer, size_t buflen,
                                                  int* errnop, int* h_errnop);

extern enum nss_status _nss_mdns4_gethostbyname2_r(const char* name, int af,
                                                   struct hostent* result,
                                                   char* buffer, size_t buflen,
                                                   int* errnop, int* h_errnop);
extern enum nss_status _nss_mdns4_gethostbyaddr_r(struct in_addr* addr, int len,
                                                  int type,
                                                  struct hostent* result,
                                                  char* buffer, size_t buflen,
                                                  int* errnop, int* h_errnop);
extern enum nss_status _nss_mdns6_gethostbyname_r(const char* name,
                                                  struct hostent* result,
                                                  char* buffer, size_t buflen,
                                                  int* errnop, int* h_errnop);

extern enum nss_status _nss_mdns6_gethostbyname2_r(const char* name, int af,
                                                   struct hostent* result,
                                                   char* buffer, size_t buflen,
                                                   int* errnop, int* h_errnop);
extern enum nss_status _nss_mdns6_gethostbyaddr_r(struct in_addr* addr, int len,
                                                  int type,
                                                  struct hostent* result,
                                                  char* buffer, size_t buflen,
                                                  int* errnop, int* h_errnop);

typedef enum nss_status (*_bsd_nsstub_fn_t)(const char*, struct hostent*, char*,
                                            size_t, int*, int*);

/* XXX: FreeBSD 5.x is not supported. */
static NSS_METHOD_PROTOTYPE(__nss_bsdcompat_getaddrinfo);
static NSS_METHOD_PROTOTYPE(__nss_bsdcompat_gethostbyaddr_r);
static NSS_METHOD_PROTOTYPE(__nss_bsdcompat_gethostbyname2_r);
static NSS_METHOD_PROTOTYPE(__nss_bsdcompat_ghbyaddr);
static NSS_METHOD_PROTOTYPE(__nss_bsdcompat_ghbyname);

static ns_mtab methods[] = {
    /* database, name, method, mdata */
    {NSDB_HOSTS, "getaddrinfo", __nss_bsdcompat_getaddrinfo, NULL},
    {NSDB_HOSTS, "gethostbyaddr_r", __nss_bsdcompat_gethostbyaddr_r, NULL},
    {NSDB_HOSTS, "gethostbyname2_r", __nss_bsdcompat_gethostbyname2_r, NULL},
    {NSDB_HOSTS, "ghbyaddr", __nss_bsdcompat_ghbyaddr, NULL},
    {NSDB_HOSTS, "ghbyname", __nss_bsdcompat_ghbyname, NULL},
};

ns_mtab* nss_module_register(const char* source, unsigned int* mtabsize,
                             nss_module_unregister_fn* unreg) {

    *mtabsize = sizeof(methods) / sizeof(methods[0]);
    *unreg = NULL;
    return (methods);<commit_msg>Remove "FreeBSD 5.x" comment<commit_after>/*
  This file is part of nss-mdns.

  nss-mdns is free software; you can redistribute it and/or modify
  it under the terms of the GNU Lesser General Public License as published
  by the Free Software Foundation; either version 2 of the License,
  or (at your option) any later version.

  nss-mdns is distributed in the hope that it will be useful, but
  WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  General Public License for more details.

  You should have received a copy of the GNU Lesser General Public
  License along with nss-mdns; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

/* Original author: <NAME> <<EMAIL>> */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <sys/param.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/uio.h>
#include <sys/socket.h>
#include <sys/ktrace.h>

#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include <errno.h>
#include <pwd.h>
#include <grp.h>
#include <nss.h>

#include <netinet/in.h>
#include <netdb.h>

#include "avahi.h"
#include "config.h"
#include "util.h"

#ifdef MDNS_MINIMAL
/*
 * FreeBSD support prefers Avahi.
 */
#endif

/*
 * To turn on utrace() records, compile with -DDEBUG_UTRACE.
 */
#ifdef DEBUG_UTRACE
#define _NSS_UTRACE(msg)                                                       \
    do {                                                                       \
        static const char __msg[] = msg;                                       \
        (void)utrace(__msg, sizeof(__msg));                                    \
    } while (0)
#else
#define _NSS_UTRACE(msg)
#endif

ns_mtab* nss_module_register(const char* source, unsigned int* mtabsize,
                             nss_module_unregister_fn* unreg);

extern enum nss_status _nss_mdns_gethostbyname_r(const char* name,
                                                 struct hostent* result,
                                                 char* buffer, size_t buflen,
                                                 int* errnop, int* h_errnop);

extern enum nss_status _nss_mdns_gethostbyname2_r(const char* name, int af,
                                                  struct hostent* result,
                                                  char* buffer, size_t buflen,
                                                  int* errnop, int* h_errnop);
extern enum nss_status _nss_mdns_gethostbyaddr_r(struct in_addr* addr, int len,
                                                 int type,
                                                 struct hostent* result,
                                                 char* buffer, size_t buflen,
                                                 int* errnop, int* h_errnop);
extern enum nss_status _nss_mdns4_gethostbyname_r(const char* name,
                                                  struct hostent* result,
                                                  char* buffer, size_t buflen,
                                                  int* errnop, int* h_errnop);

extern enum nss_status _nss_mdns4_gethostbyname2_r(const char* name, int af,
                                                   struct hostent* result,
                                                   char* buffer, size_t buflen,
                                                   int* errnop, int* h_errnop);
extern enum nss_status _nss_mdns4_gethostbyaddr_r(struct in_addr* addr, int len,
                                                  int type,
                                                  struct hostent* result,
                                                  char* buffer, size_t buflen,
                                                  int* errnop, int* h_errnop);
extern enum nss_status _nss_mdns6_gethostbyname_r(const char* name,
                                                  struct hostent* result,
                                                  char* buffer, size_t buflen,
                                                  int* errnop, int* h_errnop);

extern enum nss_status _nss_mdns6_gethostbyname2_r(const char* name, int af,
                                                   struct hostent* result,
                                                   char* buffer, size_t buflen,
                                                   int* errnop, int* h_errnop);
extern enum nss_status _nss_mdns6_gethostbyaddr_r(struct in_addr* addr, int len,
                                                  int type,
                                                  struct hostent* result,
                                                  char* buffer, size_t buflen,
                                                  int* errnop, int* h_errnop);

typedef enum nss_status (*_bsd_nsstub_fn_t)(const char*, struct hostent*, char*,
                                            size_t, int*, int*);

static NSS_METHOD_PROTOTYPE(__nss_bsdcompat_getaddrinfo);
static NSS_METHOD_PROTOTYPE(__nss_bsdcompat_gethostbyaddr_r);
static NSS_METHOD_PROTOTYPE(__nss_bsdcompat_gethostbyname2_r);
static NSS_METHOD_PROTOTYPE(__nss_bsdcompat_ghbyaddr);
static NSS_METHOD_PROTOTYPE(__nss_bsdcompat_ghbyname);

static ns_mtab methods[] = {
    /* database, name, method, mdata */
    {NSDB_HOSTS, "getaddrinfo", __nss_bsdcompat_getaddrinfo, NULL},
    {NSDB_HOSTS, "gethostbyaddr_r", __nss_bsdcompat_gethostbyaddr_r, NULL},
    {NSDB_HOSTS, "gethostbyname2_r", __nss_bsdcompat_gethostbyname2_r, NULL},
    {NSDB_HOSTS, "ghbyaddr", __nss_bsdcompat_ghbyaddr, NULL},
    {NSDB_HOSTS, "ghbyname", __nss_bsdcompat_ghbyname, NULL},
};

ns_mtab* nss_module_register(const char* source, unsigned int* mtabsize,
                             nss_module_unregister_fn* unreg) {

    *mtabsize = sizeof(methods) / sizeof(methods[0]);
    *unreg = NULL;
    return (methods);
{'fraction_non_alphanumeric': 0.07142857142857142, 'fraction_numerical': 0.004506008010680908, 'mean_word_length': 1.4544337497440099, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 140, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5779156', 'n_tokens_mistral': 3269, 'n_tokens_neox': 3196, 'n_words': 894}