void print_help(const int debuglvl, char *part) { struct vrmr_list HelpList; int max_height = 0, max_width = 0, height = 0, width = 0, startx = 0, starty = 0; #ifdef USE_WIDEC wchar_t wpart[32] = L""; #endif /* USE_WIDEC */ /* get screensize */ getmaxyx(stdscr, max_height, max_width); width = 72; height = max_height - 6; startx = max_width - width - 5; starty = 3; #ifdef USE_WIDEC if(utf8_mode == FALSE) { #endif /* USE_WIDEC */ /* read the helpfile */ if(read_helpfile(debuglvl, &HelpList, part) < 0) return; set_lines(debuglvl, &HelpList, (size_t)(width - 4)); print_list(debuglvl, &HelpList, gettext("Help"), height, width, starty, startx, UTF8_FALSE); vrmr_list_cleanup(debuglvl, &HelpList); #ifdef USE_WIDEC } else { /* convert the part name to a wchar_t string */ mbstowcs(wpart, part, wsizeof(wpart)); if(debuglvl >= LOW) vrmr_debug(__FUNC__, "part: %s, wpart %ls, %u", part, wpart, wsizeof(wpart)); /* read the helpfile */ if(read_wide_helpfile(debuglvl, &HelpList, wpart) < 0) return; set_wide_lines(debuglvl, &HelpList, width - 4); print_list(debuglvl, &HelpList, gettext("Help"), height, width, starty, startx, UTF8_TRUE); vrmr_list_cleanup(debuglvl, &HelpList); } #endif /* USE_WIDEC */ }
void vrmr_zone_free(const int debuglvl, struct vrmr_zone *zone_ptr) { if(!zone_ptr) return; if(zone_ptr->type == VRMR_TYPE_GROUP) (void)vrmr_list_cleanup(debuglvl, &zone_ptr->GroupList); if(zone_ptr->type == VRMR_TYPE_NETWORK) { (void)vrmr_list_cleanup(debuglvl, &zone_ptr->InterfaceList); (void)vrmr_list_cleanup(debuglvl, &zone_ptr->ProtectList); } free(zone_ptr); }
void print_about(const int debuglvl) { int max_height = 0, max_width = 0, height = 0, width = 0, startx = 0, starty = 0; struct vrmr_list about_list; /* top menu */ char *key_choices[] = { "F10" }; int key_choices_n = 1; char *cmd_choices[] = { gettext("back") }; int cmd_choices_n = 1; char about_version_string[sizeof(version_string)]; /* create the about version string */ snprintf(about_version_string, sizeof(about_version_string), "Version: %s\n", version_string); /* get screensize */ getmaxyx(stdscr, max_height, max_width); width = 72; height = max_height - 8; startx = (max_width - width) / 2; starty = 4; vrmr_list_setup(debuglvl, &about_list, free_helpword); (void)read_helpline(debuglvl, &about_list, "Vuurmuur_conf\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "=============\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, about_version_string); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "Copyright 2003-2007 (c) Victor Julien <victor(at)vuurmuur(dot)org>.\n"); (void)read_helpline(debuglvl, &about_list, "This program is distributed under the terms of the GPL.\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "Support\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "=======\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "Website: http://www.vuurmuur.org/\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "Mailinglist: http://sourceforge.net/mail/?group_id=114382\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "Forum: http://sourceforge.net/forum/?group_id=114382\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "IRC: irc://irc.freenode.net/vuurmuur\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "Thanks to\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "=========\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "Philippe Baumgart (documentation).\n"); (void)read_helpline(debuglvl, &about_list, "Michiel Bodewes (website development).\n"); (void)read_helpline(debuglvl, &about_list, "Nicolas Dejardin <zephura(at)free(dot)fr> (French translation).\n"); (void)read_helpline(debuglvl, &about_list, "Adi Kriegisch (coding, documentation, Debian packages).\n"); (void)read_helpline(debuglvl, &about_list, "Sebastian Marten (documentation).\n"); (void)read_helpline(debuglvl, &about_list, "Holger Ohmacht (German translation).\n"); (void)read_helpline(debuglvl, &about_list, "Hugo Ribeiro (Brazilian Portuguese translation).\n"); (void)read_helpline(debuglvl, &about_list, "Aleksandr Shubnik <alshu(at)tut(dot)by> (rpm development, Russian translation).\n"); (void)read_helpline(debuglvl, &about_list, "Per Olav Siggerud (Norwegian translation).\n"); (void)read_helpline(debuglvl, &about_list, "Alexandre Simon (coding).\n"); (void)read_helpline(debuglvl, &about_list, "Stefan Ubbink (Gentoo ebuilds, coding).\n"); (void)read_helpline(debuglvl, &about_list, "Rob de Wit (wiki hosting).\n"); (void)read_helpline(debuglvl, &about_list, "\n"); (void)read_helpline(debuglvl, &about_list, "See: http://www.vuurmuur.org/trac/wiki/Credits for the latest information.\n"); (void)read_helpline(debuglvl, &about_list, "\n"); set_lines(debuglvl, &about_list, (size_t)(width - 4)); draw_top_menu(debuglvl, top_win, gettext("About"), key_choices_n, key_choices, cmd_choices_n, cmd_choices); /* print the status list */ print_list(debuglvl, &about_list, gettext("About"), height, width, starty, startx, UTF8_FALSE); vrmr_list_cleanup(debuglvl, &about_list); }
int main(int argc, char *argv[]) { struct vrmr_ctx vctx; int retval = 0, optch = 0; static char optstring[] = "c:d:hVW"; struct option long_options[] = { {"configfile", required_argument, NULL, 'c'}, {"debug", required_argument, NULL, 'd'}, {"help", no_argument, NULL, 'h'}, {"version", no_argument, NULL, 'V'}, {"wizard", no_argument, NULL, 'W'}, {0, 0, 0, 0}, }; int longopt_index = 0; int debug_level = NONE; PANEL *main_panels[5]; char *s = NULL; /* some defaults */ vuurmuur_semid = -1; vuurmuur_shmid = -1; vuurmuurlog_semid = -1; vuurmuurlog_shmid = -1; /* create the version string */ snprintf(version_string, sizeof(version_string), "%s (using libvuurmuur %s)", VUURMUURCONF_VERSION, libvuurmuur_get_version()); /* some initilization */ if (vrmr_init(&vctx, "vuurmuur_conf") < 0) exit(EXIT_FAILURE); /* settings file */ memset(vccnf.configfile_location, 0, sizeof(vccnf.configfile_location)); if (vctx.conf.etcdir[0] == '\0') (void)strlcpy(vccnf.configfile_location, VUURMUURCONF_CONFIGFILE, sizeof(vccnf.configfile_location)); else (void)snprintf(vccnf.configfile_location, sizeof(vccnf.configfile_location), "%s/vuurmuur/vuurmuur_conf.conf", vctx.conf.etcdir); #ifdef ENABLE_NLS setlocale(LC_ALL, ""); setlocale(LC_TIME, ""); setlocale(LC_MESSAGES, ""); setlocale(LC_COLLATE, ""); setlocale(LC_CTYPE, ""); setlocale(LC_MONETARY, ""); setlocale(LC_NUMERIC, ""); #endif /* check if we are in utf-8 mode */ utf8_mode = 0; if ((s = getenv("LC_ALL")) || (s = getenv("LC_CTYPE")) || (s = getenv("LANG"))) { if (strstr(s, "UTF-8")) utf8_mode = 1; } #ifdef ENABLE_NLS bindtextdomain("vuurmuur", xstr(VRMR_LOCALEDIR)); textdomain("vuurmuur"); #endif /* process commandline options */ while ((optch = getopt_long(argc, argv, optstring, long_options, &longopt_index)) != -1) { switch (optch) { case 'h': print_commandline_args(); break; /* configfile */ case 'c': if (strlcpy(vctx.conf.configfile, optarg, sizeof(vctx.conf.configfile)) >= sizeof(vctx.conf.configfile)) { vrmr_error(EXIT_FAILURE, VR_ERR, gettext("commandline argument too long for option " "-c.")); exit(EXIT_FAILURE); } break; case 'd': /* convert the debug string and check the result */ debug_level = atoi(optarg); if (debug_level < 0 || debug_level > HIGH) { vrmr_error(EXIT_FAILURE, VR_ERR, gettext("commandline debuglevel out of range.")); exit(EXIT_FAILURE); } vrmr_debug_level = debug_level; fprintf(stdout, "vuurmuur_conf: debugging enabled.\n"); fprintf(stdout, "vuurmuur_conf: debug level: %d\n", debug_level); break; case 'V': /* print version */ fprintf(stdout, "Vuurmuur_conf %s\n", version_string); fprintf(stdout, "%s\n", VUURMUUR_COPYRIGHT); exit(EXIT_SUCCESS); case 'W': { char wizard_path[512] = ""; snprintf(wizard_path, sizeof(wizard_path), "%s/scripts/vuurmuur-wizard.sh", vctx.conf.datadir); printf("Running %s...\n", wizard_path); exec_wizard(wizard_path); exit(EXIT_SUCCESS); } default: vrmr_error(EXIT_FAILURE, VR_ERR, gettext("unknown commandline option.")); exit(EXIT_FAILURE); } } /* close the STDERR_FILENO because it gives us annoying "Broken Pipe" errors on some systems with bash3. Let's see if this has negative side-effects. */ close(STDERR_FILENO); /* init vuurmuur_conf config already to get background */ (void)init_vcconfig(&vctx.conf, vccnf.configfile_location, &vccnf); /* Initialize curses */ (void)initscr(); (void)start_color(); (void)cbreak(); (void)noecho(); (void)keypad(stdscr, (bool)TRUE); setup_colors(); /* create the three main windows */ if (!(status_frame_win = create_newwin( 3, COLS, LINES - 3, 0, NULL, vccnf.color_bgd))) exit(EXIT_FAILURE); if (!(status_win = create_newwin( 1, COLS - 4, LINES - 2, 2, NULL, vccnf.color_bgd))) exit(EXIT_FAILURE); if (!(top_win = create_newwin(3, COLS, 0, 0, NULL, vccnf.color_bgd))) exit(EXIT_FAILURE); if (!(main_win = create_newwin( LINES - 6, COLS, 3, 0, NULL, vccnf.color_bgd))) exit(EXIT_FAILURE); if (!(mainlog_win = newwin(LINES - 8, COLS - 2, 4, 1))) exit(EXIT_FAILURE); (void)wbkgd(mainlog_win, vccnf.color_bgd); wattron(status_frame_win, vccnf.color_bgd); mvwprintw(status_frame_win, 0, 2, " %s ", gettext("Status")); mvwprintw(status_frame_win, 2, (int)(COLS - 4 - StrLen(vctx.user_data.realusername) - 6), " user: %s ", vctx.user_data.realusername); wattroff(status_frame_win, vccnf.color_bgd); /* Attach a panel to each window */ main_panels[0] = new_panel(top_win); main_panels[1] = new_panel(main_win); main_panels[2] = new_panel(status_win); main_panels[3] = new_panel(mainlog_win); main_panels[4] = new_panel(status_frame_win); (void)update_panels(); (void)doupdate(); /* init the vrprint functions for the Gui */ vrprint.error = vuumuurconf_print_error; vrprint.warning = vuumuurconf_print_warning; vrprint.info = vuumuurconf_print_info; if (status_print(status_win, gettext("This is Vuurmuur_conf %s, %s"), version_string, VUURMUUR_COPYRIGHT) < 0) exit(EXIT_FAILURE); /* setup the global busywin */ VrBusyWinCreate(); VrBusyWinHide(); // form_test(); /* startup_screen inits the config, loads the zones, rules, etc */ if (startup_screen(&vctx, &vctx.rules, &vctx.zones, &vctx.services, &vctx.interfaces, &vctx.blocklist, &vctx.reg) < 0) { /* failure! Lets quit. */ /* delete panels and windows */ (void)del_panel(main_panels[0]); (void)del_panel(main_panels[1]); (void)del_panel(main_panels[2]); (void)del_panel(main_panels[3]); (void)del_panel(main_panels[4]); (void)destroy_win(top_win); (void)destroy_win(main_win); (void)destroy_win(status_win); (void)destroy_win(status_frame_win); /* clear screen */ (void)refresh(); /* end ncurses mode */ (void)endwin(); exit(EXIT_FAILURE); } /* setup statuslist */ (void)setup_statuslist(); status_print(status_win, STR_READY); mm_status_checkall(&vctx, NULL, &vctx.rules, &vctx.zones, &vctx.interfaces, &vctx.services); /* main menu loop */ while (main_menu(&vctx, &vctx.rules, &vctx.zones, &vctx.interfaces, &vctx.services, &vctx.blocklist, &vctx.reg) == 1) ; /* clean up the status list */ vrmr_list_cleanup(&vuurmuur_status.StatusList); /* detach from shared memory, if we were attached */ if (vuurmuur_shmp != NULL && vuurmuur_shmp != (char *)(-1) && vuurmuur_shmtable != 0) { if (vrmr_lock(vuurmuur_semid)) { vuurmuur_shmtable->configtool.connected = 3; vrmr_unlock(vuurmuur_semid); } (void)shmdt(vuurmuur_shmp); } if (vuurmuurlog_shmp != NULL && vuurmuurlog_shmp != (char *)(-1) && vuurmuurlog_shmtable != 0) { if (vrmr_lock(vuurmuurlog_semid)) { vuurmuurlog_shmtable->configtool.connected = 3; vrmr_unlock(vuurmuurlog_semid); } (void)shmdt(vuurmuurlog_shmp); } /* destroy the global busywin */ VrBusyWinDelete(); /* delete panels and windows */ (void)del_panel(main_panels[0]); (void)del_panel(main_panels[1]); (void)del_panel(main_panels[2]); (void)del_panel(main_panels[3]); (void)del_panel(main_panels[4]); (void)destroy_win(mainlog_win); (void)destroy_win(top_win); (void)destroy_win(main_win); (void)destroy_win(status_win); (void)destroy_win(status_frame_win); /* clear screen */ (void)refresh(); /* end ncurses mode */ (void)endwin(); /* set error functions to the stdout versions */ vrprint.error = vrmr_stdoutprint_error; vrprint.warning = vrmr_stdoutprint_warning; vrprint.info = vrmr_stdoutprint_info; vrprint.debug = vrmr_stdoutprint_debug; vrprint.audit = vrmr_stdoutprint_audit; /* unload the backends */ if (vrmr_backends_unload(&vctx.conf, &vctx) < 0) { vrmr_error(-1, VR_ERR, gettext("unloading the backends failed")); retval = -1; } /* cleanup the datastructures */ (void)vrmr_list_cleanup(&vctx.blocklist.list); (void)vrmr_destroy_serviceslist(&vctx.services); (void)vrmr_destroy_zonedatalist(&vctx.zones); (void)vrmr_rules_cleanup_list(&vctx.rules); (void)vrmr_destroy_interfaceslist(&vctx.interfaces); vrmr_deinit(&vctx); return (retval); }
int tell_textdir(void *backend, const char *name, const char *question, const char *answer, int overwrite, enum vrmr_objecttypes type) { int retval = 0; char *file_location = NULL; char line[512] = "", *line_ptr = NULL, *tmp_line_ptr = NULL; int i = 0, found = 0, skip = 0; FILE *fp = NULL; struct vrmr_list storelist; struct vrmr_list_node *d_node = NULL; assert(backend && name && question && answer); vrmr_debug(HIGH, "question: %s, answer: %s, name: %s, overwrite: %d, type: %d", question, answer, name, overwrite, type); struct textdir_backend *tb = (struct textdir_backend *)backend; if (!tb->backend_open) { vrmr_error(-1, "Error", "backend not opened yet"); return (-1); } /* only uppercase allowed */ while (question[i]) { if ((question[i] >= 'a') && (question[i] <= 'z')) return (-1); ++i; } if (!(file_location = get_filelocation(backend, name, type))) return (-1); /* first open the file for reading */ if (!(fp = vuurmuur_fopen(tb->cfg, file_location, "r"))) { vrmr_error(-1, "Error", "unable to open file '%s' for reading: %s.", file_location, strerror(errno)); free(file_location); return (-1); } /* initialize the store list */ vrmr_list_setup(&storelist, free); /* loop trough the current file */ while (fgets(line, MAX_LINE_LENGTH, fp) != NULL) { skip = 0; size_t line_size = sizeof(line); if (!(line_ptr = malloc(line_size))) { vrmr_error(-1, "Error", "malloc failed: %s", strerror(errno)); /* cleanup */ vrmr_list_cleanup(&storelist); free(file_location); fclose(fp); return (-1); } if (strncmp(question, line, strlen(question)) == 0 && line[strlen(question)] == '=') { if (overwrite && !found) { snprintf(line_ptr, line_size, "%s=\"%s\"\n", question, answer); found = 1; } else if (overwrite && found) { skip = 1; } else { (void)strlcpy(line_ptr, line, line_size); found = 1; } } else { (void)strlcpy(line_ptr, line, line_size); } /* now append the line to the storelist, except if we were told to skip this one. Then just free the data. */ if (!skip) { if (vrmr_list_append(&storelist, line_ptr) == NULL) { vrmr_error(-1, "Internal Error", "inserting line into temporary storage list failed"); /* cleanup */ vrmr_list_cleanup(&storelist); free(line_ptr); free(file_location); fclose(fp); return (-1); } } else { /* free and null */ free(line_ptr); line_ptr = NULL; } } /* if we are not overwriting and the type of data is already found somewhere, we try to insert is just below the last one. */ if (!overwrite && found) { if (!(line_ptr = malloc(sizeof(line)))) { vrmr_error(-1, "Error", "malloc failed: %s", strerror(errno)); /* cleanup */ vrmr_list_cleanup(&storelist); free(file_location); fclose(fp); return (-1); } /* assemble the line */ snprintf(line_ptr, sizeof(line), "%s=\"%s\"\n", question, answer); /* loop the list bottom up so we match the last one first */ for (d_node = storelist.bot; d_node; d_node = d_node->prev) { if (!(tmp_line_ptr = d_node->data)) { vrmr_error(-1, "Internal Error", "NULL pointer"); /* cleanup */ vrmr_list_cleanup(&storelist); free(file_location); free(line_ptr); fclose(fp); return (-1); } /* check if the line is the same. If so insert after it. */ if (strncmp(question, tmp_line_ptr, strlen(question)) == 0) { if (vrmr_list_insert_after(&storelist, d_node, line_ptr) == NULL) { vrmr_error(-1, "Internal Error", "inserting line into temporary storage list " "failed"); /* cleanup */ vrmr_list_cleanup(&storelist); free(file_location); free(line_ptr); fclose(fp); return (-1); } /* after inserting we're done */ line_ptr = NULL; break; } /* Don't free line_ptr yet, because it might be used again in the * next iteration */ } /* we no longer need these */ tmp_line_ptr = NULL; free(line_ptr); line_ptr = NULL; } /* if its not found, we insert it at the end of the list */ if (found == 0) { /* first alloc */ if (!(line_ptr = malloc(sizeof(line)))) { vrmr_error(-1, "Error", "malloc failed: %s.", strerror(errno)); /* cleanup */ vrmr_list_cleanup(&storelist); free(file_location); fclose(fp); return (-1); } snprintf(line_ptr, sizeof(line), "%s=\"%s\"\n", question, answer); /* append into the list */ if (vrmr_list_append(&storelist, line_ptr) == NULL) { vrmr_error(-1, "Internal Error", "inserting line into temporary storage list failed"); /* cleanup */ vrmr_list_cleanup(&storelist); free(file_location); free(line_ptr); fclose(fp); return (-1); } /* we no longer need this */ line_ptr = NULL; } /* close the file */ (void)fclose(fp); /* now open the file for writing */ if (!(fp = vuurmuur_fopen(tb->cfg, file_location, "w+"))) { vrmr_error(-1, "Error", "unable to open file '%s' for writing: %s", file_location, strerror(errno)); /* cleanup */ vrmr_list_cleanup(&storelist); free(file_location); return (-1); } /* print the list into the file */ for (d_node = storelist.top; d_node; d_node = d_node->next) { if (d_node->data == NULL) continue; fprintf(fp, "%s", (char *)d_node->data); } (void)fclose(fp); /* destroy the temp storage */ vrmr_list_cleanup(&storelist); free(file_location); return (retval); }