From d0009856814c13d13770db5aadd7b2fabf947776 Mon Sep 17 00:00:00 2001 From: Daniel Borkmann Date: Mon, 13 May 2013 13:53:27 +0200 Subject: staging: add mausezahn staging directory After some back and forth, we decided that it is easier to maintain mausezahn in a staging directory until it is fully reworked and cleaned up to be ready to be fully integrated. This way, it is better than having it in a separate branch, and we can also accept patches from outside more easily. Also, while at it, fix up some function mismatches with libcli. Signed-off-by: Daniel Borkmann Signed-off-by: Tobias Klauser --- staging/cli.c | 570 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 570 insertions(+) create mode 100644 staging/cli.c (limited to 'staging/cli.c') diff --git a/staging/cli.c b/staging/cli.c new file mode 100644 index 0000000..b74d688 --- /dev/null +++ b/staging/cli.c @@ -0,0 +1,570 @@ +/* + * Mausezahn - A fast versatile traffic generator + * Copyright (C) 2008-2010 Herbert Haas + * + * This program is free software; you can redistribute it and/or modify it under + * the terms of the GNU General Public License version 2 as published by the + * Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License along with + * this program; if not, see http://www.gnu.org/licenses/gpl-2.0.html + * +*/ + + + +#include "mz.h" +#include "cli.h" +#include "mops.h" +#include "llist.h" + +void mz_cli_init() +{ + amp_head = automops_init(); + + // Initialize default credentials (will be overwritten by mz.cfg) + strcpy(mz_username, MZ_DEFAULT_USERNAME); + strcpy(mz_password, MZ_DEFAULT_PASSWORD); + strcpy(mz_enable, MZ_DEFAULT_ENABLE_PASSWORD); + + // read login credentials from config file + if (cli_read_cfg("mz.cfg")) { + fprintf(stderr, "mz: Problems opening config file. Will use defaults\n"); + } + + if ((verbose) && (AUTOMOPS_ENABLED)) { + automops_dump_all(amp_head); + fprintf(stderr, "------------ MOPS/CLI initialization completed ------------\n"); + } +} + + + + +// Read in configuration file +int cli_read_cfg(char *str) +{ + char filename[256]; + char line[256]; + char path[256]; + char *ampfile; + char dev[256]; + FILE *fd; + int i, j=0, len, found=0, nonspc=0; + int user=0, pass=0, ena=0, amp=0, mgmt_only=0, cli=0; + + strncpy(filename, str, 255); + + if (getfullpath_cfg(filename)) return 1; + + if (verbose) { + fprintf(stderr, "Opening config file %s...\n", filename); + } + + fd = fopen (filename, "r"); + if (fd==NULL) return 1; + + while (fgets(line, 255, fd) != NULL) { + len=strnlen(line, 255); + // Take string left side of # (comments) + if (len) for(i=0;i