2 * This file is part of the Palacios Virtual Machine Monitor developed
3 * by the V3VEE Project with funding from the United States National
4 * Science Foundation and the Department of Energy.
6 * The V3VEE Project is a joint project between Northwestern University
7 * and the University of New Mexico. You can find out more at
10 * Copyright (c) 2011, Kyle C. Hale <kh@u.norhtwestern.edu>
11 * Copyright (c) 2011, The V3VEE Project <http://www.v3vee.org>
12 * All rights reserved.
14 * Author: Kyle C. Hale <kh@u.northwestern.edu>
16 * This is free software. You are permitted to use,
17 * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
19 #include <palacios/vmm.h>
20 #include <palacios/vm_guest.h>
21 #include <palacios/vmm_intr.h>
22 #include <palacios/vmm_extensions.h>
24 #include <gears/process_environment.h>
25 #include <gears/execve_hook.h>
26 #include <gears/env_inject.h>
28 static struct v3_env_injects env_injects;
30 static int free_env_inject (struct v3_vm_info * vm, struct v3_env_inject_info * inject) {
31 list_del(&(inject->inject_node));
36 static int v3_env_inject_handler (struct guest_info * core, void * priv_data) {
38 struct v3_env_inject_info * inject = (struct v3_env_inject_info*)priv_data;
40 for (; i < inject->num_env_vars; i++) {
41 PrintDebug("Envvar[%d]: %s\n", i, inject->env_vars[i]);
44 int ret = v3_inject_strings(core, (const char**)NULL,
45 (const char**)inject->env_vars, 0, inject->num_env_vars);
47 PrintDebug("Error injecting strings in v3_env_inject_handler\n");
54 static int init_env_inject (struct v3_vm_info * vm, v3_cfg_tree_t * cfg, void ** priv_data) {
55 struct v3_env_injects * injects = &env_injects;
56 INIT_LIST_HEAD(&(injects->env_inject_list));
61 static int deinit_env_inject (struct v3_vm_info * vm, void * priv_data) {
62 struct v3_env_injects * injects = &env_injects;
63 struct v3_env_inject_info * inject = NULL;
64 struct v3_env_inject_info * tmp = NULL;
66 list_for_each_entry_safe(inject, tmp, &(injects->env_inject_list), inject_node) {
67 free_env_inject(vm, inject);
74 int v3_insert_env_inject (void * ginfo, char ** strings, int num_strings, char * bin_name) {
75 struct v3_env_injects * injects = &env_injects;
76 struct v3_env_inject_info * inject = V3_Malloc(sizeof(struct v3_env_inject_info));
78 memset(inject, 0, sizeof(struct v3_env_inject_info));
80 inject->env_vars = strings;
81 inject->num_env_vars = num_strings;
82 inject->bin_name = bin_name;
84 list_add(&(inject->inject_node), &(injects->env_inject_list));
86 v3_hook_executable((struct v3_vm_info *)ginfo, bin_name, v3_env_inject_handler, (void*)inject);
92 int v3_remove_env_inject (struct v3_vm_info * vm, struct v3_env_inject_info * inject) {
94 if (v3_unhook_executable(vm, inject->bin_name) < 0) {
95 PrintError("Problem unhooking executable in v3_remove_env_inject\n");
99 free_env_inject(vm, inject);
104 static struct v3_extension_impl env_inject_impl = {
105 .name = "env_inject",
106 .init = init_env_inject,
107 .deinit = deinit_env_inject,
114 register_extension(&env_inject_impl);