Deleted Added
full compact
hv_kvp_daemon.c (271493) hv_kvp_daemon.c (272322)
1/*-
2 * Copyright (c) 2014 Microsoft Corp.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 270 unchanged lines hidden (view full) ---

279 size_t records_read;
280 char *fname;
281 struct kvp_record *record;
282 struct kvp_record *readp;
283 int num_blocks;
284 int i;
285 int alloc_unit = sizeof(struct kvp_record) * ENTRIES_PER_BLOCK;
286
1/*-
2 * Copyright (c) 2014 Microsoft Corp.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 270 unchanged lines hidden (view full) ---

279 size_t records_read;
280 char *fname;
281 struct kvp_record *record;
282 struct kvp_record *readp;
283 int num_blocks;
284 int i;
285 int alloc_unit = sizeof(struct kvp_record) * ENTRIES_PER_BLOCK;
286
287 if (access("/var/db/hyperv/pool", F_OK)) {
288 if (mkdir("/var/db/hyperv/pool",
289 S_IRUSR | S_IWUSR | S_IROTH)) {
290 KVP_LOG(LOG_ERR, " Failed to create /var/db/hyperv/pool\n");
291 exit(EXIT_FAILURE);
292 }
287 if (mkdir("/var/db/hyperv/pool", S_IRUSR | S_IWUSR | S_IROTH) < 0 &&
288 errno != EISDIR) {
289 KVP_LOG(LOG_ERR, " Failed to create /var/db/hyperv/pool\n");
290 exit(EXIT_FAILURE);
293 }
294
295 for (i = 0; i < HV_KVP_POOL_COUNT; i++)
296 {
297 fname = kvp_pools[i].fname;
298 records_read = 0;
299 num_blocks = 1;
300 snprintf(fname, MAX_FILE_NAME, "/var/db/hyperv/pool/.kvp_pool_%d", i);
301 fd = open(fname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IROTH);
302
303 if (fd == -1) {
304 return (1);
305 }
306
307
308 filep = fopen(fname, "r");
309 if (!filep) {
291 }
292
293 for (i = 0; i < HV_KVP_POOL_COUNT; i++)
294 {
295 fname = kvp_pools[i].fname;
296 records_read = 0;
297 num_blocks = 1;
298 snprintf(fname, MAX_FILE_NAME, "/var/db/hyperv/pool/.kvp_pool_%d", i);
299 fd = open(fname, O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IROTH);
300
301 if (fd == -1) {
302 return (1);
303 }
304
305
306 filep = fopen(fname, "r");
307 if (!filep) {
308 close(fd);
310 return (1);
311 }
312
313 record = malloc(alloc_unit * num_blocks);
314 if (record == NULL) {
309 return (1);
310 }
311
312 record = malloc(alloc_unit * num_blocks);
313 if (record == NULL) {
314 close(fd);
315 fclose(filep);
316 return (1);
317 }
318 for ( ; ; )
319 {
320 readp = &record[records_read];
321 records_read += fread(readp, sizeof(struct kvp_record),
322 ENTRIES_PER_BLOCK,

--- 8 unchanged lines hidden (view full) ---

331 if (!feof(filep)) {
332 /*
333 * More data to read.
334 */
335 num_blocks++;
336 record = realloc(record, alloc_unit *
337 num_blocks);
338 if (record == NULL) {
315 fclose(filep);
316 return (1);
317 }
318 for ( ; ; )
319 {
320 readp = &record[records_read];
321 records_read += fread(readp, sizeof(struct kvp_record),
322 ENTRIES_PER_BLOCK,

--- 8 unchanged lines hidden (view full) ---

331 if (!feof(filep)) {
332 /*
333 * More data to read.
334 */
335 num_blocks++;
336 record = realloc(record, alloc_unit *
337 num_blocks);
338 if (record == NULL) {
339 close(fd);
339 fclose(filep);
340 return (1);
341 }
342 continue;
343 }
344 break;
345 }
346 kvp_pools[i].pool_fd = fd;

--- 248 unchanged lines hidden (view full) ---

595static char *
596kvp_mac_to_if_name(char *mac)
597{
598 char *if_name = NULL;
599 struct ifaddrs *ifaddrs_ptr;
600 struct ifaddrs *head_ifaddrs_ptr;
601 struct sockaddr_dl *sdl;
602 int status;
340 fclose(filep);
341 return (1);
342 }
343 continue;
344 }
345 break;
346 }
347 kvp_pools[i].pool_fd = fd;

--- 248 unchanged lines hidden (view full) ---

596static char *
597kvp_mac_to_if_name(char *mac)
598{
599 char *if_name = NULL;
600 struct ifaddrs *ifaddrs_ptr;
601 struct ifaddrs *head_ifaddrs_ptr;
602 struct sockaddr_dl *sdl;
603 int status;
603 size_t i;
604 char *buf_ptr;
604 char *buf_ptr, *p;
605
606 status = getifaddrs(&ifaddrs_ptr);
607
608 if (status >= 0) {
609 head_ifaddrs_ptr = ifaddrs_ptr;
610 do {
611 sdl = (struct sockaddr_dl *)(uintptr_t)ifaddrs_ptr->ifa_addr;
612 if (sdl->sdl_type == IFT_ETHER) {
613 buf_ptr = strdup(ether_ntoa((struct ether_addr *)(LLADDR(sdl))));
605
606 status = getifaddrs(&ifaddrs_ptr);
607
608 if (status >= 0) {
609 head_ifaddrs_ptr = ifaddrs_ptr;
610 do {
611 sdl = (struct sockaddr_dl *)(uintptr_t)ifaddrs_ptr->ifa_addr;
612 if (sdl->sdl_type == IFT_ETHER) {
613 buf_ptr = strdup(ether_ntoa((struct ether_addr *)(LLADDR(sdl))));
614 for (i = 0; i < strlen(buf_ptr); i++)
615 {
616 buf_ptr[i] = toupper(buf_ptr[i]);
617 }
614 if (buf_ptr != NULL) {
615 for (p = buf_ptr; *p != '\0'; p++)
616 *p = toupper(*p);
618
617
619 if (strncmp(buf_ptr, mac, strlen(mac)) == 0) {
620 /* Caller will free the memory */
621 if_name = strdup(ifaddrs_ptr->ifa_name);
622 free(buf_ptr);
623 break;
624 }else if (buf_ptr != NULL) {
625 free(buf_ptr);
618 if (strncmp(buf_ptr, mac, strlen(mac)) == 0) {
619 /* Caller will free the memory */
620 if_name = strdup(ifaddrs_ptr->ifa_name);
621 free(buf_ptr);
622 break;
623 } else
624 free(buf_ptr);
626 }
627 }
628 } while ((ifaddrs_ptr = ifaddrs_ptr->ifa_next) != NULL);
629 freeifaddrs(head_ifaddrs_ptr);
630 }
631 return (if_name);
632}
633

--- 610 unchanged lines hidden (view full) ---

1244 case FullyQualifiedDomainName:
1245 kvp_get_domain_name(key_value,
1246 HV_KVP_EXCHANGE_MAX_VALUE_SIZE);
1247 strcpy(key_name, "FullyQualifiedDomainName");
1248 break;
1249
1250 case IntegrationServicesVersion:
1251 strcpy(key_name, "IntegrationServicesVersion");
625 }
626 }
627 } while ((ifaddrs_ptr = ifaddrs_ptr->ifa_next) != NULL);
628 freeifaddrs(head_ifaddrs_ptr);
629 }
630 return (if_name);
631}
632

--- 610 unchanged lines hidden (view full) ---

1243 case FullyQualifiedDomainName:
1244 kvp_get_domain_name(key_value,
1245 HV_KVP_EXCHANGE_MAX_VALUE_SIZE);
1246 strcpy(key_name, "FullyQualifiedDomainName");
1247 break;
1248
1249 case IntegrationServicesVersion:
1250 strcpy(key_name, "IntegrationServicesVersion");
1252 strcpy(key_value, lic_version);
1251 strlcpy(key_value, lic_version, HV_KVP_EXCHANGE_MAX_VALUE_SIZE);
1253 break;
1254
1255 case NetworkAddressIPv4:
1256 kvp_get_ip_info(AF_INET, NULL, HV_KVP_OP_ENUMERATE,
1257 key_value, HV_KVP_EXCHANGE_MAX_VALUE_SIZE);
1258 strcpy(key_name, "NetworkAddressIPv4");
1259 break;
1260
1261 case NetworkAddressIPv6:
1262 kvp_get_ip_info(AF_INET6, NULL, HV_KVP_OP_ENUMERATE,
1263 key_value, HV_KVP_EXCHANGE_MAX_VALUE_SIZE);
1264 strcpy(key_name, "NetworkAddressIPv6");
1265 break;
1266
1267 case OSBuildNumber:
1252 break;
1253
1254 case NetworkAddressIPv4:
1255 kvp_get_ip_info(AF_INET, NULL, HV_KVP_OP_ENUMERATE,
1256 key_value, HV_KVP_EXCHANGE_MAX_VALUE_SIZE);
1257 strcpy(key_name, "NetworkAddressIPv4");
1258 break;
1259
1260 case NetworkAddressIPv6:
1261 kvp_get_ip_info(AF_INET6, NULL, HV_KVP_OP_ENUMERATE,
1262 key_value, HV_KVP_EXCHANGE_MAX_VALUE_SIZE);
1263 strcpy(key_name, "NetworkAddressIPv6");
1264 break;
1265
1266 case OSBuildNumber:
1268 strcpy(key_value, os_build);
1267 strlcpy(key_value, os_build, HV_KVP_EXCHANGE_MAX_VALUE_SIZE);
1269 strcpy(key_name, "OSBuildNumber");
1270 break;
1271
1272 case OSName:
1268 strcpy(key_name, "OSBuildNumber");
1269 break;
1270
1271 case OSName:
1273 strcpy(key_value, os_name);
1272 strlcpy(key_value, os_name, HV_KVP_EXCHANGE_MAX_VALUE_SIZE);
1274 strcpy(key_name, "OSName");
1275 break;
1276
1277 case OSMajorVersion:
1273 strcpy(key_name, "OSName");
1274 break;
1275
1276 case OSMajorVersion:
1278 strcpy(key_value, os_major);
1277 strlcpy(key_value, os_major, HV_KVP_EXCHANGE_MAX_VALUE_SIZE);
1279 strcpy(key_name, "OSMajorVersion");
1280 break;
1281
1282 case OSMinorVersion:
1278 strcpy(key_name, "OSMajorVersion");
1279 break;
1280
1281 case OSMinorVersion:
1283 strcpy(key_value, os_minor);
1282 strlcpy(key_value, os_minor, HV_KVP_EXCHANGE_MAX_VALUE_SIZE);
1284 strcpy(key_name, "OSMinorVersion");
1285 break;
1286
1287 case OSVersion:
1283 strcpy(key_name, "OSMinorVersion");
1284 break;
1285
1286 case OSVersion:
1288 strcpy(key_value, os_build);
1287 strlcpy(key_value, os_build, HV_KVP_EXCHANGE_MAX_VALUE_SIZE);
1289 strcpy(key_name, "OSVersion");
1290 break;
1291
1292 case ProcessorArchitecture:
1288 strcpy(key_name, "OSVersion");
1289 break;
1290
1291 case ProcessorArchitecture:
1293 strcpy(key_value, processor_arch);
1292 strlcpy(key_value, processor_arch, HV_KVP_EXCHANGE_MAX_VALUE_SIZE);
1294 strcpy(key_name, "ProcessorArchitecture");
1295 break;
1296
1297 default:
1298#ifdef DEBUG
1299 KVP_LOG(LOG_ERR, "Auto pool Index %d not found.\n",
1300 op_msg->body.kvp_enum_data.index);
1301#endif

--- 217 unchanged lines hidden ---
1293 strcpy(key_name, "ProcessorArchitecture");
1294 break;
1295
1296 default:
1297#ifdef DEBUG
1298 KVP_LOG(LOG_ERR, "Auto pool Index %d not found.\n",
1299 op_msg->body.kvp_enum_data.index);
1300#endif

--- 217 unchanged lines hidden ---