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"
21 int main (int argc, char **argv) {
22 char *vm_dev, *env_file, *bin_name;
23 int err, bytes_read, num_strings;
26 char * strings[MAX_NUM_STRINGS];
27 char tmp_str[MAX_STRING_LEN];
32 v3_usage("<vm device> <env-file> <inject-point-exe>\n\n"
33 "\tenv-file : file containing a list of new-line separated env vars\n\n"
34 "\tinject-point-exe : if this is an exec-hooked inject, use this executable name\n");
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 printf("Transferring control to Palacios\n");
76 err = v3_vm_ioctl(vm_dev, V3_VM_ENV_INJECT, &env);
78 fprintf(stderr, "Error providing env var data to palacios\n");