summaryrefslogtreecommitdiff
path: root/common/elapi
diff options
context:
space:
mode:
authorDmitri Pal <dpal@redhat.com>2009-10-02 21:06:25 -0400
committerStephen Gallagher <sgallagh@redhat.com>2009-10-05 17:15:40 -0400
commit770f47ae840d5234d75167bd8b904d6949472701 (patch)
treebba3178be38d1b4213bbab0061f8da374f813ff0 /common/elapi
parent9c2046dd570c9be06fc0f10e3ae0b1571d6310ac (diff)
downloadsssd-770f47ae840d5234d75167bd8b904d6949472701.tar.gz
sssd-770f47ae840d5234d75167bd8b904d6949472701.tar.bz2
sssd-770f47ae840d5234d75167bd8b904d6949472701.zip
ELAPI Fixed the host name resolution
The issue was that the host IP was recorded twice, once as a main address and another as IP alias. It seemed that the IP was returned as name but the issue turned out to be different. See https://fedorahosted.org/sssd/ticket/207.
Diffstat (limited to 'common/elapi')
-rw-r--r--common/elapi/elapi_event.c16
-rw-r--r--common/elapi/elapi_test/elapi_ut.c108
2 files changed, 111 insertions, 13 deletions
diff --git a/common/elapi/elapi_event.c b/common/elapi/elapi_event.c
index a517babd..e7a5d779 100644
--- a/common/elapi/elapi_event.c
+++ b/common/elapi/elapi_event.c
@@ -73,6 +73,7 @@ static int add_host_identity(struct collection_item *tpl, unsigned base)
int family;
int set_hostname = 0;
int set_ip = 0;
+ int used_this_ip = 0;
TRACE_FLOW_STRING("add_host_identity", "Entry");
@@ -99,6 +100,8 @@ static int add_host_identity(struct collection_item *tpl, unsigned base)
TRACE_FLOW_STRING("Top of the loop", "");
+ used_this_ip = 0;
+
if (!ifa->ifa_addr) {
ifa = ifa->ifa_next;
continue;
@@ -136,6 +139,8 @@ static int add_host_identity(struct collection_item *tpl, unsigned base)
0,
NI_NUMERICHOST /* Gets address as string */);
+ TRACE_INFO_STRING("Resolved host:", host);
+ TRACE_INFO_STRING("Resolved address:", address);
/* If we have not set host name set it */
if(!set_hostname) {
@@ -149,7 +154,7 @@ static int add_host_identity(struct collection_item *tpl, unsigned base)
hnm = hostname;
}
else {
- /* We we able to get a host name ? */
+ /* Were we able to get a host name ? */
if (gai_ret_host == EOK) {
TRACE_INFO_STRING("getnameinfo returned:", host);
hnm = host;
@@ -200,6 +205,7 @@ static int add_host_identity(struct collection_item *tpl, unsigned base)
return error;
}
set_ip = 1;
+ used_this_ip = 1;
}
}
@@ -231,13 +237,15 @@ static int add_host_identity(struct collection_item *tpl, unsigned base)
}
/* If we got then main IP and we are told to deal with opther IPs */
- if ((set_ip) && (base & E_HAVE_HOSTIPS)) {
+ if ((set_ip) && (base & E_HAVE_HOSTIPS) && (!used_this_ip)) {
- /* Do we have a host meaningful host name? */
+ TRACE_INFO_STRING("Considering address:", address);
+
+ /* Do we have a host meaningful IP */
if ((gai_ret_addr != EOK) ||
((gai_ret_addr == EOK) &&
((strcasecmp(address, LOCALADDRESS) == 0 ) ||
- (strcasecmp(address, LOCALADDRESSV6) == 0 )))) haddr = address;
+ (strcasecmp(address, LOCALADDRESSV6) == 0 )))) haddr = NULL;
else haddr = address;
if (haddr) {
diff --git a/common/elapi/elapi_test/elapi_ut.c b/common/elapi/elapi_test/elapi_ut.c
index 9097a438..ba493bbd 100644
--- a/common/elapi/elapi_test/elapi_ut.c
+++ b/common/elapi/elapi_test/elapi_ut.c
@@ -397,7 +397,7 @@ int complex_event_test(void)
E_MESSAGE,
"date = %(R_stamp__), pid = %(__pid__), "
"hostname = %(__host__), %(__halias__), "
- "ip = %(__ip__), [%(__iplist__);%(!__iplist__);%(__iplist__)]" ,
+ "ip = %(__ip__), [%(__iplist__); %(!__iplist__); %(__iplist__)]" ,
E_EOARG);
if (error) {
elapi_destroy_event_tplt(tpl);
@@ -411,7 +411,7 @@ int complex_event_test(void)
E_MESSAGE,
"date = %(R_stamp__), pid = %(__pid__), "
"hostname = %(__host__), %(__halias__), "
- "ip = %(__ip__), [%(__iplist__);%(__iplist__);%(__iplist__)]" ,
+ "ip = %(__ip__), [%(__iplist__); %(__iplist__); %(__iplist__)]" ,
E_EOARG);
if (error) {
elapi_destroy_event_tplt(tpl);
@@ -429,6 +429,101 @@ int complex_event_test(void)
}
+int template_test(void)
+{
+ int error = 0;
+ struct collection_item *event;
+
+ printf("Template test START:\n");
+
+ error = elapi_set_default_tplt(
+ E_HAVE_HOSTNAME,
+ E_EOARG);
+
+ if (error) {
+ printf("Failed to set default template! %d\n", error);
+ return error;
+ }
+
+ error = elapi_create_simple_event(
+ &event,
+ E_EOARG);
+
+ if (error) {
+ printf("Failed to create simple event! %d\n", error);
+ return error;
+ }
+
+ col_debug_collection(event, COL_TRAVERSE_DEFAULT);
+ elapi_destroy_event(event);
+
+ error = elapi_set_default_tplt(
+ E_HAVE_HOSTALIAS,
+ E_EOARG);
+
+ if (error) {
+ printf("Failed to set default template! %d\n", error);
+ return error;
+ }
+
+ error = elapi_create_simple_event(
+ &event,
+ E_EOARG);
+
+ if (error) {
+ printf("Failed to create simple event! %d\n", error);
+ return error;
+ }
+
+ col_debug_collection(event, COL_TRAVERSE_DEFAULT);
+ elapi_destroy_event(event);
+
+ error = elapi_set_default_tplt(
+ E_HAVE_HOSTIP,
+ E_EOARG);
+
+ if (error) {
+ printf("Failed to set default template! %d\n", error);
+ return error;
+ }
+
+ error = elapi_create_simple_event(
+ &event,
+ E_EOARG);
+
+ if (error) {
+ printf("Failed to create simple event! %d\n", error);
+ return error;
+ }
+
+ col_debug_collection(event, COL_TRAVERSE_DEFAULT);
+ elapi_destroy_event(event);
+
+ error = elapi_set_default_tplt(
+ E_HAVE_HOSTIPS,
+ E_EOARG);
+
+ if (error) {
+ printf("Failed to set default template! %d\n", error);
+ return error;
+ }
+
+ error = elapi_create_simple_event(
+ &event,
+ E_EOARG);
+
+ if (error) {
+ printf("Failed to create simple event! %d\n", error);
+ return error;
+ }
+
+ col_debug_collection(event, COL_TRAVERSE_DEFAULT);
+ elapi_destroy_event(event);
+
+ return EOK;
+}
+
+
/* Main function of the unit test */
int main(int argc, char *argv[])
@@ -438,18 +533,13 @@ int main(int argc, char *argv[])
elapi_get_default_tplt_test,
simple_event_test,
complex_event_test,
+ template_test,
NULL };
test_fn t;
int i = 0;
printf("Start\n");
- /* I added second pair of parentheses in the while below
- * becuase of the following warning I got:
- * warning: suggest parentheses around assignment used as truth value
- *
- * There was a suggestion in general to add less parentheses...
- * well it seems that compiler wants this one.
- */
+
while ((t = tests[i++])) {
error = t();
if (error) {