aboutsummaryrefslogtreecommitdiffstats
path: root/tools/hv/hv_kvp_daemon.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/hv/hv_kvp_daemon.c')
-rw-r--r--tools/hv/hv_kvp_daemon.c40
1 files changed, 27 insertions, 13 deletions
diff --git a/tools/hv/hv_kvp_daemon.c b/tools/hv/hv_kvp_daemon.c
index 5959affd8820..d25a46925e61 100644
--- a/tools/hv/hv_kvp_daemon.c
+++ b/tools/hv/hv_kvp_daemon.c
@@ -43,6 +43,7 @@
43#include <sys/stat.h> 43#include <sys/stat.h>
44#include <fcntl.h> 44#include <fcntl.h>
45#include <dirent.h> 45#include <dirent.h>
46#include <net/if.h>
46 47
47/* 48/*
48 * KVP protocol: The user mode component first registers with the 49 * KVP protocol: The user mode component first registers with the
@@ -88,6 +89,7 @@ static char *os_major = "";
88static char *os_minor = ""; 89static char *os_minor = "";
89static char *processor_arch; 90static char *processor_arch;
90static char *os_build; 91static char *os_build;
92static char *os_version;
91static char *lic_version = "Unknown version"; 93static char *lic_version = "Unknown version";
92static struct utsname uts_buf; 94static struct utsname uts_buf;
93 95
@@ -297,7 +299,7 @@ static int kvp_file_init(void)
297 return 0; 299 return 0;
298} 300}
299 301
300static int kvp_key_delete(int pool, __u8 *key, int key_size) 302static int kvp_key_delete(int pool, const char *key, int key_size)
301{ 303{
302 int i; 304 int i;
303 int j, k; 305 int j, k;
@@ -340,7 +342,7 @@ static int kvp_key_delete(int pool, __u8 *key, int key_size)
340 return 1; 342 return 1;
341} 343}
342 344
343static int kvp_key_add_or_modify(int pool, __u8 *key, int key_size, __u8 *value, 345static int kvp_key_add_or_modify(int pool, const char *key, int key_size, const char *value,
344 int value_size) 346 int value_size)
345{ 347{
346 int i; 348 int i;
@@ -394,7 +396,7 @@ static int kvp_key_add_or_modify(int pool, __u8 *key, int key_size, __u8 *value,
394 return 0; 396 return 0;
395} 397}
396 398
397static int kvp_get_value(int pool, __u8 *key, int key_size, __u8 *value, 399static int kvp_get_value(int pool, const char *key, int key_size, char *value,
398 int value_size) 400 int value_size)
399{ 401{
400 int i; 402 int i;
@@ -426,8 +428,8 @@ static int kvp_get_value(int pool, __u8 *key, int key_size, __u8 *value,
426 return 1; 428 return 1;
427} 429}
428 430
429static int kvp_pool_enumerate(int pool, int index, __u8 *key, int key_size, 431static int kvp_pool_enumerate(int pool, int index, char *key, int key_size,
430 __u8 *value, int value_size) 432 char *value, int value_size)
431{ 433{
432 struct kvp_record *record; 434 struct kvp_record *record;
433 435
@@ -453,7 +455,9 @@ void kvp_get_os_info(void)
453 char *p, buf[512]; 455 char *p, buf[512];
454 456
455 uname(&uts_buf); 457 uname(&uts_buf);
456 os_build = uts_buf.release; 458 os_version = uts_buf.release;
459 os_build = strdup(uts_buf.release);
460
457 os_name = uts_buf.sysname; 461 os_name = uts_buf.sysname;
458 processor_arch = uts_buf.machine; 462 processor_arch = uts_buf.machine;
459 463
@@ -462,7 +466,7 @@ void kvp_get_os_info(void)
462 * string to be of the form: x.y.z 466 * string to be of the form: x.y.z
463 * Strip additional information we may have. 467 * Strip additional information we may have.
464 */ 468 */
465 p = strchr(os_build, '-'); 469 p = strchr(os_version, '-');
466 if (p) 470 if (p)
467 *p = '\0'; 471 *p = '\0';
468 472
@@ -879,7 +883,7 @@ static int kvp_process_ip_address(void *addrp,
879 addr_length = INET6_ADDRSTRLEN; 883 addr_length = INET6_ADDRSTRLEN;
880 } 884 }
881 885
882 if ((length - *offset) < addr_length + 1) 886 if ((length - *offset) < addr_length + 2)
883 return HV_E_FAIL; 887 return HV_E_FAIL;
884 if (str == NULL) { 888 if (str == NULL) {
885 strcpy(buffer, "inet_ntop failed\n"); 889 strcpy(buffer, "inet_ntop failed\n");
@@ -887,11 +891,13 @@ static int kvp_process_ip_address(void *addrp,
887 } 891 }
888 if (*offset == 0) 892 if (*offset == 0)
889 strcpy(buffer, tmp); 893 strcpy(buffer, tmp);
890 else 894 else {
895 strcat(buffer, ";");
891 strcat(buffer, tmp); 896 strcat(buffer, tmp);
892 strcat(buffer, ";"); 897 }
893 898
894 *offset += strlen(str) + 1; 899 *offset += strlen(str) + 1;
900
895 return 0; 901 return 0;
896} 902}
897 903
@@ -953,7 +959,9 @@ kvp_get_ip_info(int family, char *if_name, int op,
953 * supported address families; if not we gather info on 959 * supported address families; if not we gather info on
954 * the specified address family. 960 * the specified address family.
955 */ 961 */
956 if ((family != 0) && (curp->ifa_addr->sa_family != family)) { 962 if ((((family != 0) &&
963 (curp->ifa_addr->sa_family != family))) ||
964 (curp->ifa_flags & IFF_LOOPBACK)) {
957 curp = curp->ifa_next; 965 curp = curp->ifa_next;
958 continue; 966 continue;
959 } 967 }
@@ -1478,13 +1486,19 @@ int main(void)
1478 len = recvfrom(fd, kvp_recv_buffer, sizeof(kvp_recv_buffer), 0, 1486 len = recvfrom(fd, kvp_recv_buffer, sizeof(kvp_recv_buffer), 0,
1479 addr_p, &addr_l); 1487 addr_p, &addr_l);
1480 1488
1481 if (len < 0 || addr.nl_pid) { 1489 if (len < 0) {
1482 syslog(LOG_ERR, "recvfrom failed; pid:%u error:%d %s", 1490 syslog(LOG_ERR, "recvfrom failed; pid:%u error:%d %s",
1483 addr.nl_pid, errno, strerror(errno)); 1491 addr.nl_pid, errno, strerror(errno));
1484 close(fd); 1492 close(fd);
1485 return -1; 1493 return -1;
1486 } 1494 }
1487 1495
1496 if (addr.nl_pid) {
1497 syslog(LOG_WARNING, "Received packet from untrusted pid:%u",
1498 addr.nl_pid);
1499 continue;
1500 }
1501
1488 incoming_msg = (struct nlmsghdr *)kvp_recv_buffer; 1502 incoming_msg = (struct nlmsghdr *)kvp_recv_buffer;
1489 incoming_cn_msg = (struct cn_msg *)NLMSG_DATA(incoming_msg); 1503 incoming_cn_msg = (struct cn_msg *)NLMSG_DATA(incoming_msg);
1490 hv_msg = (struct hv_kvp_msg *)incoming_cn_msg->data; 1504 hv_msg = (struct hv_kvp_msg *)incoming_cn_msg->data;
@@ -1649,7 +1663,7 @@ int main(void)
1649 strcpy(key_name, "OSMinorVersion"); 1663 strcpy(key_name, "OSMinorVersion");
1650 break; 1664 break;
1651 case OSVersion: 1665 case OSVersion:
1652 strcpy(key_value, os_build); 1666 strcpy(key_value, os_version);
1653 strcpy(key_name, "OSVersion"); 1667 strcpy(key_name, "OSVersion");
1654 break; 1668 break;
1655 case ProcessorArchitecture: 1669 case ProcessorArchitecture: