summaryrefslogtreecommitdiffstats
path: root/src/providers
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2011-06-10 14:05:45 +0200
committerStephen Gallagher <sgallagh@redhat.com>2011-06-15 15:56:13 -0400
commit1240496176a07e804c57d43926509d5ccbf0fc41 (patch)
treef74391b6ad92996ba24fe23e09122a7452aa2e16 /src/providers
parent3d334807f302603b81996b41f2a365ce75f36d17 (diff)
downloadsssd-1240496176a07e804c57d43926509d5ccbf0fc41.tar.gz
sssd-1240496176a07e804c57d43926509d5ccbf0fc41.tar.xz
sssd-1240496176a07e804c57d43926509d5ccbf0fc41.zip
Switch resolver to using resolv_hostent and honor TTL
Diffstat (limited to 'src/providers')
-rw-r--r--src/providers/data_provider_fo.c9
-rw-r--r--src/providers/fail_over.c36
-rw-r--r--src/providers/fail_over.h2
-rw-r--r--src/providers/ipa/ipa_common.c4
-rw-r--r--src/providers/krb5/krb5_common.c2
-rw-r--r--src/providers/ldap/ldap_common.c4
6 files changed, 29 insertions, 28 deletions
diff --git a/src/providers/data_provider_fo.c b/src/providers/data_provider_fo.c
index f1e1e137c..58468c820 100644
--- a/src/providers/data_provider_fo.c
+++ b/src/providers/data_provider_fo.c
@@ -453,14 +453,15 @@ static void be_resolve_server_done(struct tevent_req *subreq)
/* all fine we got the server */
if (debug_level >= 4) {
- struct hostent *srvaddr;
+ struct resolv_hostent *srvaddr;
char ipaddr[128];
srvaddr = fo_get_server_hostent(state->srv);
- inet_ntop(srvaddr->h_addrtype, srvaddr->h_addr_list[0],
+ inet_ntop(srvaddr->family, srvaddr->addr_list[0]->ipaddr,
ipaddr, 128);
- DEBUG(4, ("Found address for server %s: [%s]\n",
- fo_get_server_name(state->srv), ipaddr));
+ DEBUG(4, ("Found address for server %s: [%s] TTL %d\n",
+ fo_get_server_name(state->srv), ipaddr,
+ srvaddr->addr_list[0]->ttl));
}
srv_status_change = fo_get_server_hostname_last_change(state->srv);
diff --git a/src/providers/fail_over.c b/src/providers/fail_over.c
index 3d29779df..c182d80c2 100644
--- a/src/providers/fail_over.c
+++ b/src/providers/fail_over.c
@@ -43,10 +43,6 @@
#define DEFAULT_SERVER_STATUS SERVER_NAME_NOT_RESOLVED
#define DEFAULT_SRV_STATUS SRV_NEUTRAL
-#ifndef HOSTNAME_RESOLVE_TIMEOUT
-#define HOSTNAME_RESOLVE_TIMEOUT 7200
-#endif /* HOSTNAME_RESOLVE_TIMEOUT */
-
enum srv_lookup_status {
SRV_NEUTRAL, /* We didn't try this SRV lookup yet */
SRV_RESOLVED, /* This SRV lookup is resolved */
@@ -94,7 +90,7 @@ struct server_common {
struct server_common *next;
char *name;
- struct hostent *hostent;
+ struct resolv_hostent *rhostent;
struct resolve_service_request *request_list;
int server_status;
struct timeval last_status_change;
@@ -328,7 +324,8 @@ get_server_status(struct fo_server *server)
}
}
- if (STATUS_DIFF(server->common, tv) > HOSTNAME_RESOLVE_TIMEOUT) {
+ if (server->common->rhostent && STATUS_DIFF(server->common, tv) >
+ server->common->rhostent->addr_list[0]->ttl) {
DEBUG(4, ("Hostname resolution expired, resetting the server "
"status of '%s'\n", SERVER_NAME(server)));
fo_set_server_status(server, SERVER_NAME_NOT_RESOLVED);
@@ -497,7 +494,7 @@ create_server_common(TALLOC_CTX *mem_ctx, struct fo_ctx *ctx, const char *name)
common->ctx = ctx;
common->prev = NULL;
common->next = NULL;
- common->hostent = NULL;
+ common->rhostent = NULL;
common->request_list = NULL;
common->server_status = DEFAULT_SERVER_STATUS;
common->last_status_change.tv_sec = 0;
@@ -846,7 +843,8 @@ fo_resolve_service_server(struct tevent_req *req)
subreq = resolv_gethostbyname_send(state->server->common,
state->ev, state->resolv,
state->server->common->name,
- state->fo_ctx->opts->family_order);
+ state->fo_ctx->opts->family_order,
+ default_host_dbs);
if (subreq == NULL) {
tevent_req_error(req, ENOMEM);
return true;
@@ -883,13 +881,13 @@ fo_resolve_service_done(struct tevent_req *subreq)
struct resolve_service_request *request;
int ret;
- if (state->server->common->hostent != NULL) {
- talloc_zfree(state->server->common->hostent);
+ if (state->server->common->rhostent != NULL) {
+ talloc_zfree(state->server->common->rhostent);
}
ret = resolv_gethostbyname_recv(subreq, state->server->common,
&resolv_status, NULL,
- &state->server->common->hostent);
+ &state->server->common->rhostent);
talloc_zfree(subreq);
if (ret != EOK) {
DEBUG(1, ("Failed to resolve server '%s': %s\n",
@@ -1224,7 +1222,8 @@ resolve_get_domain_send(TALLOC_CTX *mem_ctx,
subreq = resolv_gethostbyname_send(state, ev, resolv,
state->hostname,
- foctx->opts->family_order);
+ foctx->opts->family_order,
+ default_host_dbs);
if (!subreq) {
talloc_zfree(req);
return NULL;
@@ -1240,10 +1239,10 @@ static void resolve_get_domain_done(struct tevent_req *subreq)
struct tevent_req);
struct resolve_get_domain_state *state = tevent_req_data(req,
struct resolve_get_domain_state);
- struct hostent *hostent;
+ struct resolv_hostent *rhostent;
int ret;
- ret = resolv_gethostbyname_recv(subreq, req, NULL, NULL, &hostent);
+ ret = resolv_gethostbyname_recv(subreq, req, NULL, NULL, &rhostent);
talloc_zfree(subreq);
if (ret) {
DEBUG(2, ("Could not get fully qualified name for host name %s "
@@ -1251,8 +1250,8 @@ static void resolve_get_domain_done(struct tevent_req *subreq)
state->hostname, ret, strerror(ret)));
/* We'll proceed with hostname in this case */
} else {
- DEBUG(7, ("The full FQDN is: %s\n", hostent->h_name));
- state->fqdn = hostent->h_name;
+ DEBUG(7, ("The full FQDN is: %s\n", rhostent->name));
+ state->fqdn = rhostent->name;
}
tevent_req_done(req);
}
@@ -1388,14 +1387,15 @@ const char *fo_get_server_name(struct fo_server *server)
return server->common->name;
}
-struct hostent *
+struct resolv_hostent *
fo_get_server_hostent(struct fo_server *server)
{
if (server->common == NULL) {
DEBUG(1, ("Bug: Trying to get hostent from a name-less server\n"));
return NULL;
}
- return server->common->hostent;
+
+ return server->common->rhostent;
}
time_t
diff --git a/src/providers/fail_over.h b/src/providers/fail_over.h
index 54141e9c8..e5d6c525f 100644
--- a/src/providers/fail_over.h
+++ b/src/providers/fail_over.h
@@ -169,7 +169,7 @@ int fo_get_server_port(struct fo_server *server);
const char *fo_get_server_name(struct fo_server *server);
-struct hostent *fo_get_server_hostent(struct fo_server *server);
+struct resolv_hostent *fo_get_server_hostent(struct fo_server *server);
time_t fo_get_server_hostname_last_change(struct fo_server *server);
diff --git a/src/providers/ipa/ipa_common.c b/src/providers/ipa/ipa_common.c
index 6d8a02f20..f49030946 100644
--- a/src/providers/ipa/ipa_common.c
+++ b/src/providers/ipa/ipa_common.c
@@ -592,7 +592,7 @@ static void ipa_resolve_callback(void *private_data, struct fo_server *server)
{
TALLOC_CTX *tmp_ctx = NULL;
struct ipa_service *service;
- struct hostent *srvaddr;
+ struct resolv_hostent *srvaddr;
char *address;
const char *safe_address;
char *new_uri;
@@ -627,7 +627,7 @@ static void ipa_resolve_callback(void *private_data, struct fo_server *server)
}
safe_address = sss_ldap_escape_ip_address(tmp_ctx,
- srvaddr->h_addrtype,
+ srvaddr->family,
address);
if (safe_address == NULL) {
DEBUG(1, ("sss_ldap_escape_ip_address failed.\n"));
diff --git a/src/providers/krb5/krb5_common.c b/src/providers/krb5/krb5_common.c
index c0ed6ce30..b3d8d2228 100644
--- a/src/providers/krb5/krb5_common.c
+++ b/src/providers/krb5/krb5_common.c
@@ -377,7 +377,7 @@ done:
static void krb5_resolve_callback(void *private_data, struct fo_server *server)
{
struct krb5_service *krb5_service;
- struct hostent *srvaddr;
+ struct resolv_hostent *srvaddr;
char *address;
int ret;
diff --git a/src/providers/ldap/ldap_common.c b/src/providers/ldap/ldap_common.c
index 453e7d762..9796204f9 100644
--- a/src/providers/ldap/ldap_common.c
+++ b/src/providers/ldap/ldap_common.c
@@ -533,7 +533,7 @@ static void sdap_uri_callback(void *private_data, struct fo_server *server)
{
TALLOC_CTX *tmp_ctx = NULL;
struct sdap_service *service;
- struct hostent *srvaddr;
+ struct resolv_hostent *srvaddr;
char *address;
const char *safe_address;
const char *tmp;
@@ -571,7 +571,7 @@ static void sdap_uri_callback(void *private_data, struct fo_server *server)
}
safe_address = sss_ldap_escape_ip_address(tmp_ctx,
- srvaddr->h_addrtype,
+ srvaddr->family,
address);
talloc_zfree(address);
if (safe_address == NULL) {