2 * V3 Environment Variable Injection Utility
3 * This code allows a user to inject environment variables into a process
4 * marked by a specific binary name in a running guest.
6 * (c) Kyle C. Hale, 2012
14 #include <sys/types.h>
15 #include <sys/ioctl.h>
17 #include "iface-env-inject.h"
20 static void usage (char* bin) {
21 fprintf(stderr, "usage: %s /dev/v3-vm<N> env-file inject-point-exe\n", bin);
24 int main (int argc, char **argv) {
25 char *vm_dev, *env_file, *bin_name;
26 int vm_fd, err, bytes_read, num_strings;
29 char * strings[MAX_NUM_STRINGS];
30 char tmp_str[MAX_STRING_LEN];
43 t_fd = fopen(env_file, "r");
45 fprintf(stderr, "Error opening environment variable file: %s\n", env_file);
49 /* copy in the vars line by line */
50 while (fgets(tmp_str, MAX_STRING_LEN, t_fd) != NULL) {
51 int len = strlen(tmp_str) - 1;
52 if (tmp_str[len] == '\n')
54 strings[i] = (char*)malloc(MAX_STRING_LEN);
56 fprintf(stderr, "Error allocating space for variable\n");
59 strcpy(strings[i], tmp_str);
64 printf("Found %d environment variables to inject\n", i);
66 env.strings = (char**) strings;
69 fprintf(stderr, "Error: no binary hook provided\n");
73 strncpy(env.bin_name, bin_name, MAX_STRING_LEN);
75 vm_fd = open(vm_dev, O_RDONLY);
77 fprintf(stderr, "Error opening VM device: %s\n", vm_dev);
81 printf("Transferring control to Palacios\n");
82 err = ioctl(vm_fd, V3_VM_ENV_INJECT, &env);
84 fprintf(stderr, "Error providing env var data to palacios\n");