summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJakub Hrozek <jhrozek@redhat.com>2011-07-16 18:00:40 +0200
committerSimo Sorce <ssorce@redhat.com>2011-07-21 08:23:17 -0400
commit9b85268eabe33d624b9d184251e89c0c7ae829a2 (patch)
tree21ccb9734873f246657a78fb4cb8b60032b20075 /src
parent363d2fba991eae199d017f5b2d1b458f070fac6b (diff)
downloadsssd-9b85268eabe33d624b9d184251e89c0c7ae829a2.tar.gz
sssd-9b85268eabe33d624b9d184251e89c0c7ae829a2.tar.xz
sssd-9b85268eabe33d624b9d184251e89c0c7ae829a2.zip
fo_get_server_name() getter for a server name
Allows to be more concise in tests and more defensive in resolve callbacks
Diffstat (limited to 'src')
-rw-r--r--src/providers/data_provider_fo.c2
-rw-r--r--src/providers/fail_over.c9
-rw-r--r--src/providers/fail_over.h2
-rw-r--r--src/providers/ipa/ipa_common.c10
-rw-r--r--src/providers/ldap/ldap_common.c11
-rw-r--r--src/tests/fail_over-tests.c2
6 files changed, 32 insertions, 4 deletions
diff --git a/src/providers/data_provider_fo.c b/src/providers/data_provider_fo.c
index 6f9c757be..b5c417344 100644
--- a/src/providers/data_provider_fo.c
+++ b/src/providers/data_provider_fo.c
@@ -432,7 +432,7 @@ static void be_resolve_server_done(struct tevent_req *subreq)
/* all fine we got the server */
- if (debug_level >= 4) {
+ if (debug_level >= 4 && fo_get_server_name(state->srv)) {
struct resolv_hostent *srvaddr;
char ipaddr[128];
srvaddr = fo_get_server_hostent(state->srv);
diff --git a/src/providers/fail_over.c b/src/providers/fail_over.c
index 2bf69848a..6b967d4db 100644
--- a/src/providers/fail_over.c
+++ b/src/providers/fail_over.c
@@ -1375,6 +1375,15 @@ fo_get_server_port(struct fo_server *server)
return server->port;
}
+const char *
+fo_get_server_name(struct fo_server *server)
+{
+ if (!server->common) {
+ return NULL;
+ }
+ return server->common->name;
+}
+
const char *fo_get_server_str_name(struct fo_server *server)
{
if (!server->common) {
diff --git a/src/providers/fail_over.h b/src/providers/fail_over.h
index cb9e54e98..3ca6096c4 100644
--- a/src/providers/fail_over.h
+++ b/src/providers/fail_over.h
@@ -167,6 +167,8 @@ void *fo_get_server_user_data(struct fo_server *server);
int fo_get_server_port(struct fo_server *server);
+const char *fo_get_server_name(struct fo_server *server);
+
const char *fo_get_server_str_name(struct fo_server *server);
struct resolv_hostent *fo_get_server_hostent(struct fo_server *server);
diff --git a/src/providers/ipa/ipa_common.c b/src/providers/ipa/ipa_common.c
index 70272a2a4..08b051265 100644
--- a/src/providers/ipa/ipa_common.c
+++ b/src/providers/ipa/ipa_common.c
@@ -602,6 +602,7 @@ static void ipa_resolve_callback(void *private_data, struct fo_server *server)
char *address;
const char *safe_address;
char *new_uri;
+ const char *srv_name;
int ret;
tmp_ctx = talloc_new(NULL);
@@ -639,7 +640,14 @@ static void ipa_resolve_callback(void *private_data, struct fo_server *server)
return;
}
- new_uri = talloc_asprintf(service, "ldap://%s", fo_get_server_str_name(server));
+ srv_name = fo_get_server_name(server);
+ if (srv_name == NULL) {
+ DEBUG(1, ("Could not get server host name\n"));
+ talloc_free(tmp_ctx);
+ return;
+ }
+
+ new_uri = talloc_asprintf(service, "ldap://%s", srv_name);
if (!new_uri) {
DEBUG(2, ("Failed to copy URI ...\n"));
talloc_free(tmp_ctx);
diff --git a/src/providers/ldap/ldap_common.c b/src/providers/ldap/ldap_common.c
index 656c10263..78176ba8a 100644
--- a/src/providers/ldap/ldap_common.c
+++ b/src/providers/ldap/ldap_common.c
@@ -542,6 +542,7 @@ static void sdap_uri_callback(void *private_data, struct fo_server *server)
struct resolv_hostent *srvaddr;
struct sockaddr_storage *sockaddr;
const char *tmp;
+ const char *srv_name;
char *new_uri;
tmp_ctx = talloc_new(NULL);
@@ -579,8 +580,16 @@ static void sdap_uri_callback(void *private_data, struct fo_server *server)
DEBUG(1, ("Unknown service, using ldap\n"));
tmp = SSS_LDAP_SRV_NAME;
}
+
+ srv_name = fo_get_server_name(server);
+ if (srv_name == NULL) {
+ DEBUG(1, ("Could not get server host name\n"));
+ talloc_free(tmp_ctx);
+ return;
+ }
+
new_uri = talloc_asprintf(service, "%s://%s:%d",
- tmp, fo_get_server_str_name(server),
+ tmp, srv_name,
fo_get_server_port(server));
} else {
new_uri = talloc_strdup(service, tmp);
diff --git a/src/tests/fail_over-tests.c b/src/tests/fail_over-tests.c
index d8a6d510b..8beaa8a26 100644
--- a/src/tests/fail_over-tests.c
+++ b/src/tests/fail_over-tests.c
@@ -170,7 +170,7 @@ test_resolve_service_callback(struct tevent_req *req)
if (task->new_server_status >= 0)
fo_set_server_status(server, task->new_server_status);
- if (strcmp(fo_get_server_str_name(server), "unknown name")) {
+ if (fo_get_server_name(server) != NULL) {
he = fo_get_server_hostent(server);
fail_if(he == NULL, "%s: fo_get_server_hostent() returned NULL");
for (i = 0; he->addr_list[i]; i++) {