58 lines
1.5 KiB
C++
58 lines
1.5 KiB
C++
// SPDX-FileCopyrightText: Matteo Settenvini <matteo.settenvini@montecristosoftware.eu>
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
#include "get_host.hh"
|
|
#include "helpers.hh"
|
|
#include "logger.hh"
|
|
#include "user_policy.hh"
|
|
|
|
namespace /* anonymous */ {
|
|
|
|
static const malcontent::UserPolicy USER_POLICY;
|
|
|
|
} // ~ namespace anonymous
|
|
|
|
|
|
auto malcontent::get_host::by_name(ResolverArgs& args) -> nss_status {
|
|
set_if_valid(args.errnop, 0);
|
|
set_if_valid(args.h_errnop, HErrno::Success);
|
|
|
|
try {
|
|
auto resolver = USER_POLICY.resolver({});
|
|
if (!resolver) {
|
|
return nss_status::NSS_STATUS_NOTFOUND;
|
|
}
|
|
return resolver->resolve(args);
|
|
} catch(const std::exception& e) {
|
|
Logger::error(e.what());
|
|
return nss_status::NSS_STATUS_UNAVAIL;
|
|
}
|
|
}
|
|
|
|
auto malcontent::get_host::by_addr(
|
|
const void * /* addr */,
|
|
socklen_t /* len */,
|
|
int /* family */,
|
|
hostent * /* host */,
|
|
char * /* buffer */,
|
|
size_t /* buflen */,
|
|
int *errnop,
|
|
HErrno *h_errnop,
|
|
int32_t * /* ttlp */
|
|
) -> nss_status {
|
|
set_if_valid(errnop, 0);
|
|
set_if_valid(h_errnop, HErrno::Success);
|
|
|
|
// At the moment, we are not handling this function
|
|
// in our module.
|
|
//
|
|
// We assume it is fine to go to the next module
|
|
// in the nsswitch.conf list to get an authoritative
|
|
// answer.
|
|
//
|
|
// The use case for reverse IP lookup
|
|
// should not impact parental controls.
|
|
|
|
return nss_status::NSS_STATUS_UNAVAIL;
|
|
}
|