From abac0f3ec2baa597d8e21a8744de6f33506299ce Mon Sep 17 00:00:00 2001 From: Pavel Březina Date: Sat, 3 Aug 2013 01:02:02 +0200 Subject: utils: add is_host_in_domain() --- src/util/util.c | 15 +++++++++++++++ src/util/util.h | 2 ++ 2 files changed, 17 insertions(+) (limited to 'src/util') diff --git a/src/util/util.c b/src/util/util.c index 480296766..fb3bed146 100644 --- a/src/util/util.c +++ b/src/util/util.c @@ -724,3 +724,18 @@ int domain_to_basedn(TALLOC_CTX *memctx, const char *domain, char **basedn) *basedn = dn; return EOK; } + +bool is_host_in_domain(const char *host, const char *domain) +{ + int diff = strlen(host) - strlen(domain); + + if (diff == 0 && strcmp(host, domain) == 0) { + return true; + } + + if (diff > 0 && strcmp(host + diff, domain) == 0 && host[diff - 1] == '.') { + return true; + } + + return false; +} diff --git a/src/util/util.h b/src/util/util.h index 516edc81c..c2c31f5d5 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -506,6 +506,8 @@ void safezero(void *data, size_t size); int domain_to_basedn(TALLOC_CTX *memctx, const char *domain, char **basedn); +bool is_host_in_domain(const char *host, const char *domain); + /* from nscd.c */ enum nscd_db { NSCD_DB_PASSWD, -- cgit