sdap_async_sudo_hostinfo.c revision d6133b04d4ee47f147db26cd732ea5d209af5b8e
842ae4bd224140319ae7feec1872b93dfd491143fielding Pavel Březina <pbrezina@redhat.com>
842ae4bd224140319ae7feec1872b93dfd491143fielding Copyright (C) 2012 Red Hat
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding This program is free software; you can redistribute it and/or modify
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd it under the terms of the GNU General Public License as published by
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding the Free Software Foundation; either version 3 of the License, or
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd (at your option) any later version.
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd This program is distributed in the hope that it will be useful,
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd but WITHOUT ANY WARRANTY; without even the implied warranty of
ce9621257ef9e54c1bbe5ad8a5f445a1f211c2dcnd MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding GNU General Public License for more details.
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding You should have received a copy of the GNU General Public License
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding along with this program. If not, see <http://www.gnu.org/licenses/>.
1b21d7b3d97def358b2e923655edeb16613a1c31gsteinstatic int sdap_sudo_get_ip_addresses(TALLOC_CTX *mem_ctx, char ***_ip_addr);
1b21d7b3d97def358b2e923655edeb16613a1c31gsteinstruct tevent_req * sdap_sudo_get_hostinfo_send(TALLOC_CTX *mem_ctx,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding /* create request */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding req = tevent_req_create(mem_ctx, &state, struct sdap_sudo_get_hostinfo_state);
963f8b44ac95132458ea3b6aaa8ebc135188e473takashi DEBUG(SSSDBG_FATAL_FAILURE, ("tevent_req_create() failed\n"));
cb9e6e5c78f5a1690214e9548250fc6af1fc73b5wrowe /* load info from configuration */
cb9e6e5c78f5a1690214e9548250fc6af1fc73b5wrowe conf_hostnames = dp_opt_get_string(opts->basic, SDAP_SUDO_HOSTNAMES);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding conf_ip_addr = dp_opt_get_string(opts->basic, SDAP_SUDO_IP);
8a3228198adb03e6996f7738c361a612777ecab6aaron ret = split_on_separator(state, conf_hostnames, ' ', true,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ("Unable to parse hostnames [%d]: %s\n", ret, strerror(ret)));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding DEBUG(SSSDBG_CONF_SETTINGS, ("Hostnames set to: %s\n", conf_hostnames));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ret = split_on_separator(state, conf_ip_addr, ' ', true,
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ("Unable to parse IP addresses [%d]: %s\n", ret, strerror(ret)));
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding DEBUG(SSSDBG_CONF_SETTINGS, ("IP addresses set to: %s\n", conf_ip_addr));
8a3228198adb03e6996f7738c361a612777ecab6aaron /* if IP addresses are not specified, configure it automatically */
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding ret = sdap_sudo_get_ip_addresses(state, &state->ip_addr);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding state = tevent_req_data(req, struct sdap_sudo_get_hostinfo_state);
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fieldingstatic int sdap_sudo_get_ip_addresses(TALLOC_CTX *mem_ctx, char ***_ip_addr_list)
09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1fielding unsigned int netmask = 0;
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick DEBUG(SSSDBG_CRIT_FAILURE, ("talloc_new() failed\n"));
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton DEBUG(SSSDBG_CRIT_FAILURE, ("Could not read interfaces [%d][%s]\n",
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton for (iface = ifaces; iface != NULL; iface = iface->ifa_next) {
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton /* Some interfaces don't have an ifa_addr */
7117ace448072813fa6eb7180ef206fc2e8fcfc7wrowe ip4_network = (struct sockaddr_in*)(iface->ifa_netmask);
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton /* ignore loopback */
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton if (inet_netof(ip4_addr->sin_addr) == IN_LOOPBACKNET) {
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton /* ignore multicast */
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton /* ignore broadcast */
f3a0be90718c1fa5da1bf25e38974d2db3ef8a30jorton if (ntohl(ip4_addr->sin_addr.s_addr) == INADDR_BROADCAST) {
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick /* get network mask length */
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe /* get network address */
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe ip4_network->sin_addr.s_addr = ip4_addr->sin_addr.s_addr
d7b781abdcdc6fc4d4fcd513d5babd3c42dff43dwrowe ip6_network = (struct sockaddr_in6*)(iface->ifa_netmask);
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick /* ignore loopback */
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick /* ignore multicast */
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick /* get network mask length */
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick for (i = 0; i < 4; i++) {
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick ip6_netmask = ntohl(((uint32_t*)(&ip6_network->sin6_addr))[i]);
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick /* get network address */
82d2a5debc5a6ed2118ac5916d9ba36ad0b5d78btrawick for (i = 0; i < 4; i++) {
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe /* skip other families */
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe /* ip address */
92eed7d377d8be7cd8e48d1299412fc8c742b7f5jorton DEBUG(SSSDBG_MINOR_FAILURE, ("inet_ntop() failed [%d]: %s\n",
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe /* network */
649c9dd342a580016d29c2866de88a4609eb6457wrowe if (inet_ntop(iface->ifa_addr->sa_family, sinx_network,
649c9dd342a580016d29c2866de88a4609eb6457wrowe DEBUG(SSSDBG_MINOR_FAILURE, ("inet_ntop() failed [%d]: %s\n",
649c9dd342a580016d29c2866de88a4609eb6457wrowe ip_addr_list = talloc_realloc(tmp_ctx, ip_addr_list, char*,
649c9dd342a580016d29c2866de88a4609eb6457wrowe ip_addr_list[addr_count - 2] = talloc_strdup(ip_addr_list, ip_addr);
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe ip_addr_list[addr_count - 1] = talloc_asprintf(ip_addr_list, "%s/%d",
b3edf21d591bfd0e64bbec0dda73c0e41d7ecdb6wrowe ("Found IP address: %s in network %s/%d\n",