summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSumit Bose <sbose@redhat.com>2011-06-27 10:03:03 +0200
committerStephen Gallagher <sgallagh@redhat.com>2011-06-30 14:09:10 -0400
commit7087d51975f4059591c04718def24ba7b753644c (patch)
tree3e0e03d57143394ceff8f059568a34237416af8a
parentec425320a9bf42954a5a28b79cb567e3a9a58ecc (diff)
downloadsssd-7087d51975f4059591c04718def24ba7b753644c.tar.gz
sssd-7087d51975f4059591c04718def24ba7b753644c.tar.xz
sssd-7087d51975f4059591c04718def24ba7b753644c.zip
Add sockaddr_storage to sdap_service
-rw-r--r--src/providers/ipa/ipa_common.c10
-rw-r--r--src/providers/ldap/ldap_common.c11
-rw-r--r--src/providers/ldap/sdap.h1
-rw-r--r--src/resolv/async_resolv.c36
-rw-r--r--src/resolv/async_resolv.h4
5 files changed, 62 insertions, 0 deletions
diff --git a/src/providers/ipa/ipa_common.c b/src/providers/ipa/ipa_common.c
index f49030946..89a8751be 100644
--- a/src/providers/ipa/ipa_common.c
+++ b/src/providers/ipa/ipa_common.c
@@ -593,6 +593,7 @@ static void ipa_resolve_callback(void *private_data, struct fo_server *server)
TALLOC_CTX *tmp_ctx = NULL;
struct ipa_service *service;
struct resolv_hostent *srvaddr;
+ struct sockaddr_storage *sockaddr;
char *address;
const char *safe_address;
char *new_uri;
@@ -619,6 +620,13 @@ static void ipa_resolve_callback(void *private_data, struct fo_server *server)
return;
}
+ sockaddr = resolv_get_sockaddr_address(tmp_ctx, srvaddr, LDAP_PORT);
+ if (sockaddr == NULL) {
+ DEBUG(1, ("resolv_get_sockaddr_address failed.\n"));
+ talloc_free(tmp_ctx);
+ return;
+ }
+
address = resolv_get_string_address(tmp_ctx, srvaddr);
if (address == NULL) {
DEBUG(1, ("resolv_get_string_address failed.\n"));
@@ -646,6 +654,8 @@ static void ipa_resolve_callback(void *private_data, struct fo_server *server)
/* free old one and replace with new one */
talloc_zfree(service->sdap->uri);
service->sdap->uri = new_uri;
+ talloc_zfree(service->sdap->sockaddr);
+ service->sdap->sockaddr = talloc_steal(service, sockaddr);
talloc_zfree(service->krb5_service->address);
service->krb5_service->address = talloc_steal(service, address);
diff --git a/src/providers/ldap/ldap_common.c b/src/providers/ldap/ldap_common.c
index 9796204f9..997e027c4 100644
--- a/src/providers/ldap/ldap_common.c
+++ b/src/providers/ldap/ldap_common.c
@@ -536,6 +536,7 @@ static void sdap_uri_callback(void *private_data, struct fo_server *server)
struct resolv_hostent *srvaddr;
char *address;
const char *safe_address;
+ struct sockaddr_storage *sockaddr;
const char *tmp;
char *new_uri;
LDAPURLDesc *lud;
@@ -570,6 +571,14 @@ static void sdap_uri_callback(void *private_data, struct fo_server *server)
return;
}
+ sockaddr = resolv_get_sockaddr_address(tmp_ctx, srvaddr,
+ fo_get_server_port(server));
+ if (sockaddr == NULL) {
+ DEBUG(1, ("resolv_get_sockaddr_address failed.\n"));
+ talloc_free(tmp_ctx);
+ return;
+ }
+
safe_address = sss_ldap_escape_ip_address(tmp_ctx,
srvaddr->family,
address);
@@ -617,6 +626,8 @@ static void sdap_uri_callback(void *private_data, struct fo_server *server)
/* free old one and replace with new one */
talloc_zfree(service->uri);
service->uri = new_uri;
+ talloc_zfree(service->sockaddr);
+ service->sockaddr = talloc_steal(service, sockaddr);
talloc_free(tmp_ctx);
}
diff --git a/src/providers/ldap/sdap.h b/src/providers/ldap/sdap.h
index 4b662c15d..9184090e6 100644
--- a/src/providers/ldap/sdap.h
+++ b/src/providers/ldap/sdap.h
@@ -98,6 +98,7 @@ struct sdap_service {
char *name;
char *uri;
char *kinit_service_name;
+ struct sockaddr_storage *sockaddr;
};
struct sdap_ppolicy_data {
diff --git a/src/resolv/async_resolv.c b/src/resolv/async_resolv.c
index 1f8056722..9b9b0538e 100644
--- a/src/resolv/async_resolv.c
+++ b/src/resolv/async_resolv.c
@@ -1296,6 +1296,42 @@ resolv_get_string_address(TALLOC_CTX *mem_ctx, struct resolv_hostent *hostent)
return address;
}
+struct sockaddr_storage *
+resolv_get_sockaddr_address(TALLOC_CTX *mem_ctx, struct resolv_hostent *hostent,
+ int port)
+{
+ struct sockaddr_storage *sockaddr;
+
+ if (!hostent) return NULL;
+
+ sockaddr = talloc_zero(mem_ctx, struct sockaddr_storage);
+ if (sockaddr == NULL) {
+ DEBUG(1, ("talloc_zero failed.\n"));
+ return NULL;
+ }
+
+ switch(hostent->family) {
+ case AF_INET:
+ sockaddr->ss_family = AF_INET;
+ memcpy(&((struct sockaddr_in *) sockaddr)->sin_addr,
+ hostent->addr_list[0]->ipaddr, sizeof(struct in_addr));
+ ((struct sockaddr_in *) sockaddr)->sin_port = (in_port_t) htons(port);
+
+ break;
+ case AF_INET6:
+ sockaddr->ss_family = AF_INET6;
+ memcpy(&((struct sockaddr_in6 *) sockaddr)->sin6_addr,
+ hostent->addr_list[0]->ipaddr, sizeof(struct in6_addr));
+ ((struct sockaddr_in6 *) sockaddr)->sin6_port = (in_port_t) htons(port);
+ break;
+ default:
+ DEBUG(1, ("Unknown address family %d\n"));
+ return NULL;
+ }
+
+ return sockaddr;
+}
+
/*
* A simple helper function that will take an array of struct ares_srv_reply that
* was allocated by malloc() in c-ares and copies it using talloc. The old one
diff --git a/src/resolv/async_resolv.h b/src/resolv/async_resolv.h
index 907865f7a..b5547e5df 100644
--- a/src/resolv/async_resolv.h
+++ b/src/resolv/async_resolv.h
@@ -114,6 +114,10 @@ int resolv_gethostbyname_recv(struct tevent_req *req, TALLOC_CTX *mem_ctx,
char *
resolv_get_string_address(TALLOC_CTX *mem_ctx, struct resolv_hostent *hostent);
+struct sockaddr_storage *
+resolv_get_sockaddr_address(TALLOC_CTX *mem_ctx, struct resolv_hostent *hostent,
+ int port);
+
/** Get SRV record **/
struct tevent_req *resolv_getsrv_send(TALLOC_CTX *mem_ctx,
struct tevent_context *ev,