nss-myhostname: move NSS boilerplate to nss-util.h
This commit is contained in:
parent
f48e75cb9a
commit
c9fdc26e96
|
@ -836,7 +836,8 @@ libsystemd_shared_la_SOURCES = \
|
||||||
src/shared/copy.c \
|
src/shared/copy.c \
|
||||||
src/shared/copy.h \
|
src/shared/copy.h \
|
||||||
src/shared/base-filesystem.c \
|
src/shared/base-filesystem.c \
|
||||||
src/shared/base-filesystem.h
|
src/shared/base-filesystem.h \
|
||||||
|
src/shared/nss-util.h
|
||||||
|
|
||||||
nodist_libsystemd_shared_la_SOURCES = \
|
nodist_libsystemd_shared_la_SOURCES = \
|
||||||
src/shared/errno-from-name.h \
|
src/shared/errno-from-name.h \
|
||||||
|
|
|
@ -32,6 +32,8 @@
|
||||||
|
|
||||||
#include "local-addresses.h"
|
#include "local-addresses.h"
|
||||||
#include "macro.h"
|
#include "macro.h"
|
||||||
|
#include "nss-util.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
/* Ensure that glibc's assert is used. We cannot use assert from macro.h, as
|
/* Ensure that glibc's assert is used. We cannot use assert from macro.h, as
|
||||||
* libnss_myhostname will be linked into arbitrary programs which will, in turn
|
* libnss_myhostname will be linked into arbitrary programs which will, in turn
|
||||||
|
@ -47,49 +49,8 @@
|
||||||
#define LOCALADDRESS_IPV6 &in6addr_loopback
|
#define LOCALADDRESS_IPV6 &in6addr_loopback
|
||||||
#define LOOPBACK_INTERFACE "lo"
|
#define LOOPBACK_INTERFACE "lo"
|
||||||
|
|
||||||
enum nss_status _nss_myhostname_gethostbyname4_r(
|
NSS_GETHOSTBYNAME_PROTOTYPES(myhostname);
|
||||||
const char *name,
|
NSS_GETHOSTBYADDR_PROTOTYPES(myhostname);
|
||||||
struct gaih_addrtuple **pat,
|
|
||||||
char *buffer, size_t buflen,
|
|
||||||
int *errnop, int *h_errnop,
|
|
||||||
int32_t *ttlp) _public_;
|
|
||||||
|
|
||||||
enum nss_status _nss_myhostname_gethostbyname3_r(
|
|
||||||
const char *name,
|
|
||||||
int af,
|
|
||||||
struct hostent *host,
|
|
||||||
char *buffer, size_t buflen,
|
|
||||||
int *errnop, int *h_errnop,
|
|
||||||
int32_t *ttlp,
|
|
||||||
char **canonp) _public_;
|
|
||||||
|
|
||||||
enum nss_status _nss_myhostname_gethostbyname2_r(
|
|
||||||
const char *name,
|
|
||||||
int af,
|
|
||||||
struct hostent *host,
|
|
||||||
char *buffer, size_t buflen,
|
|
||||||
int *errnop, int *h_errnop) _public_;
|
|
||||||
|
|
||||||
enum nss_status _nss_myhostname_gethostbyname_r(
|
|
||||||
const char *name,
|
|
||||||
struct hostent *host,
|
|
||||||
char *buffer, size_t buflen,
|
|
||||||
int *errnop, int *h_errnop) _public_;
|
|
||||||
|
|
||||||
enum nss_status _nss_myhostname_gethostbyaddr2_r(
|
|
||||||
const void* addr, socklen_t len,
|
|
||||||
int af,
|
|
||||||
struct hostent *host,
|
|
||||||
char *buffer, size_t buflen,
|
|
||||||
int *errnop, int *h_errnop,
|
|
||||||
int32_t *ttlp) _public_;
|
|
||||||
|
|
||||||
enum nss_status _nss_myhostname_gethostbyaddr_r(
|
|
||||||
const void* addr, socklen_t len,
|
|
||||||
int af,
|
|
||||||
struct hostent *host,
|
|
||||||
char *buffer, size_t buflen,
|
|
||||||
int *errnop, int *h_errnop) _public_;
|
|
||||||
|
|
||||||
enum nss_status _nss_myhostname_gethostbyname4_r(
|
enum nss_status _nss_myhostname_gethostbyname4_r(
|
||||||
const char *name,
|
const char *name,
|
||||||
|
@ -411,39 +372,6 @@ enum nss_status _nss_myhostname_gethostbyname3_r(
|
||||||
canonp);
|
canonp);
|
||||||
}
|
}
|
||||||
|
|
||||||
enum nss_status _nss_myhostname_gethostbyname2_r(
|
|
||||||
const char *name,
|
|
||||||
int af,
|
|
||||||
struct hostent *host,
|
|
||||||
char *buffer, size_t buflen,
|
|
||||||
int *errnop, int *h_errnop) {
|
|
||||||
|
|
||||||
return _nss_myhostname_gethostbyname3_r(
|
|
||||||
name,
|
|
||||||
af,
|
|
||||||
host,
|
|
||||||
buffer, buflen,
|
|
||||||
errnop, h_errnop,
|
|
||||||
NULL,
|
|
||||||
NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
enum nss_status _nss_myhostname_gethostbyname_r(
|
|
||||||
const char *name,
|
|
||||||
struct hostent *host,
|
|
||||||
char *buffer, size_t buflen,
|
|
||||||
int *errnop, int *h_errnop) {
|
|
||||||
|
|
||||||
return _nss_myhostname_gethostbyname3_r(
|
|
||||||
name,
|
|
||||||
AF_UNSPEC,
|
|
||||||
host,
|
|
||||||
buffer, buflen,
|
|
||||||
errnop, h_errnop,
|
|
||||||
NULL,
|
|
||||||
NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
enum nss_status _nss_myhostname_gethostbyaddr2_r(
|
enum nss_status _nss_myhostname_gethostbyaddr2_r(
|
||||||
const void* addr, socklen_t len,
|
const void* addr, socklen_t len,
|
||||||
int af,
|
int af,
|
||||||
|
@ -538,18 +466,5 @@ found:
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
enum nss_status _nss_myhostname_gethostbyaddr_r(
|
NSS_GETHOSTBYNAME_FALLBACKS(myhostname);
|
||||||
const void* addr, socklen_t len,
|
NSS_GETHOSTBYADDR_FALLBACKS(myhostname);
|
||||||
int af,
|
|
||||||
struct hostent *host,
|
|
||||||
char *buffer, size_t buflen,
|
|
||||||
int *errnop, int *h_errnop) {
|
|
||||||
|
|
||||||
return _nss_myhostname_gethostbyaddr2_r(
|
|
||||||
addr, len,
|
|
||||||
af,
|
|
||||||
host,
|
|
||||||
buffer, buflen,
|
|
||||||
errnop, h_errnop,
|
|
||||||
NULL);
|
|
||||||
}
|
|
||||||
|
|
|
@ -9,11 +9,11 @@
|
||||||
|
|
||||||
{
|
{
|
||||||
global:
|
global:
|
||||||
_nss_myhostname_gethostbyaddr2_r;
|
_nss_myhostname_gethostbyname_r;
|
||||||
_nss_myhostname_gethostbyaddr_r;
|
|
||||||
_nss_myhostname_gethostbyname2_r;
|
_nss_myhostname_gethostbyname2_r;
|
||||||
_nss_myhostname_gethostbyname3_r;
|
_nss_myhostname_gethostbyname3_r;
|
||||||
_nss_myhostname_gethostbyname4_r;
|
_nss_myhostname_gethostbyname4_r;
|
||||||
_nss_myhostname_gethostbyname_r;
|
_nss_myhostname_gethostbyaddr_r;
|
||||||
|
_nss_myhostname_gethostbyaddr2_r;
|
||||||
local: *;
|
local: *;
|
||||||
};
|
};
|
||||||
|
|
114
src/shared/nss-util.h
Normal file
114
src/shared/nss-util.h
Normal file
|
@ -0,0 +1,114 @@
|
||||||
|
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
/***
|
||||||
|
This file is part of systemd.
|
||||||
|
|
||||||
|
Copyright 2014 Lennart Poettering
|
||||||
|
|
||||||
|
systemd 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.1 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
systemd 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
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
|
along with systemd; If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
***/
|
||||||
|
|
||||||
|
#include <nss.h>
|
||||||
|
#include <netdb.h>
|
||||||
|
|
||||||
|
#define NSS_GETHOSTBYNAME_PROTOTYPES(module) \
|
||||||
|
enum nss_status _nss_##module##_gethostbyname4_r( \
|
||||||
|
const char *name, \
|
||||||
|
struct gaih_addrtuple **pat, \
|
||||||
|
char *buffer, size_t buflen, \
|
||||||
|
int *errnop, int *h_errnop, \
|
||||||
|
int32_t *ttlp) _public_; \
|
||||||
|
enum nss_status _nss_##module##_gethostbyname3_r( \
|
||||||
|
const char *name, \
|
||||||
|
int af, \
|
||||||
|
struct hostent *host, \
|
||||||
|
char *buffer, size_t buflen, \
|
||||||
|
int *errnop, int *h_errnop, \
|
||||||
|
int32_t *ttlp, \
|
||||||
|
char **canonp) _public_; \
|
||||||
|
enum nss_status _nss_##module##_gethostbyname2_r( \
|
||||||
|
const char *name, \
|
||||||
|
int af, \
|
||||||
|
struct hostent *host, \
|
||||||
|
char *buffer, size_t buflen, \
|
||||||
|
int *errnop, int *h_errnop) _public_; \
|
||||||
|
enum nss_status _nss_##module##_gethostbyname_r( \
|
||||||
|
const char *name, \
|
||||||
|
struct hostent *host, \
|
||||||
|
char *buffer, size_t buflen, \
|
||||||
|
int *errnop, int *h_errnop) _public_
|
||||||
|
|
||||||
|
#define NSS_GETHOSTBYADDR_PROTOTYPES(module) \
|
||||||
|
enum nss_status _nss_##module##_gethostbyaddr2_r( \
|
||||||
|
const void* addr, socklen_t len, \
|
||||||
|
int af, \
|
||||||
|
struct hostent *host, \
|
||||||
|
char *buffer, size_t buflen, \
|
||||||
|
int *errnop, int *h_errnop, \
|
||||||
|
int32_t *ttlp) _public_; \
|
||||||
|
enum nss_status _nss_##module##_gethostbyaddr_r( \
|
||||||
|
const void* addr, socklen_t len, \
|
||||||
|
int af, \
|
||||||
|
struct hostent *host, \
|
||||||
|
char *buffer, size_t buflen, \
|
||||||
|
int *errnop, int *h_errnop) _public_
|
||||||
|
|
||||||
|
#define NSS_GETHOSTBYNAME_FALLBACKS(module) \
|
||||||
|
enum nss_status _nss_##module##_gethostbyname2_r( \
|
||||||
|
const char *name, \
|
||||||
|
int af, \
|
||||||
|
struct hostent *host, \
|
||||||
|
char *buffer, size_t buflen, \
|
||||||
|
int *errnop, int *h_errnop) { \
|
||||||
|
return _nss_##module##_gethostbyname3_r( \
|
||||||
|
name, \
|
||||||
|
af, \
|
||||||
|
host, \
|
||||||
|
buffer, buflen, \
|
||||||
|
errnop, h_errnop, \
|
||||||
|
NULL, \
|
||||||
|
NULL); \
|
||||||
|
} \
|
||||||
|
enum nss_status _nss_##module##_gethostbyname_r( \
|
||||||
|
const char *name, \
|
||||||
|
struct hostent *host, \
|
||||||
|
char *buffer, size_t buflen, \
|
||||||
|
int *errnop, int *h_errnop) { \
|
||||||
|
return _nss_##module##_gethostbyname3_r( \
|
||||||
|
name, \
|
||||||
|
AF_UNSPEC, \
|
||||||
|
host, \
|
||||||
|
buffer, buflen, \
|
||||||
|
errnop, h_errnop, \
|
||||||
|
NULL, \
|
||||||
|
NULL); \
|
||||||
|
}
|
||||||
|
|
||||||
|
#define NSS_GETHOSTBYADDR_FALLBACKS(module) \
|
||||||
|
enum nss_status _nss_##module##_gethostbyaddr_r( \
|
||||||
|
const void* addr, socklen_t len, \
|
||||||
|
int af, \
|
||||||
|
struct hostent *host, \
|
||||||
|
char *buffer, size_t buflen, \
|
||||||
|
int *errnop, int *h_errnop) { \
|
||||||
|
return _nss_##module##_gethostbyaddr2_r( \
|
||||||
|
addr, len, \
|
||||||
|
af, \
|
||||||
|
host, \
|
||||||
|
buffer, buflen, \
|
||||||
|
errnop, h_errnop, \
|
||||||
|
NULL); \
|
||||||
|
}
|
Loading…
Reference in a new issue