예제 #1
0
파일: fwknop.c 프로젝트: g-reno/fwknop
static void
enable_fault_injections(fko_cli_options_t * const opts)
{
    if(opts->fault_injection_tag[0] != 0x0)
    {
        fiu_init(0);
        fiu_enable(opts->fault_injection_tag, 1, NULL, 0);
    }
    return;
}
예제 #2
0
int main(void) {
    fko_ctx_t       ctx = NULL;
    int             res = 0, i, es = EXIT_SUCCESS;
    int             exec=0, success=0, fail=0;

    fiu_init(0);

    for (i=0; i < sizeof(fiu_rvs)/sizeof(int); i++) {
        exec++;
        printf("[+] libfiu injection tag: %s\n", fiu_tags[i]);

        fiu_enable(fiu_tags[i], fiu_rvs[i], NULL, 0);

        res = fko_new(&ctx);

        if(strncmp(fiu_tags[i], "fko_set_rand_value_lenval",
                    strlen("fko_set_rand_value_lenval")) == 0)
            res = fko_set_rand_value(ctx, "asdf1234");

        if(strncmp(fiu_tags[i], "fko_set_rand_value_strdup",
                    strlen("fko_set_rand_value_strdup")) == 0)
            res = fko_set_rand_value(ctx, "asdf1234");

        if(strncmp(fiu_tags[i], "fko_set_username_valuser",
                    strlen("fko_set_username_valuser")) == 0)
            res = fko_set_username(ctx, "BADCHAR=");

        if(strncmp(fiu_tags[i], "fko_set_username_strdup",
                    strlen("fko_set_username_strdup")) == 0)
            res = fko_set_username(ctx, "normaluser");

        if(res == FKO_SUCCESS)
        {
            printf("[-] fko_new(): %s\n", fko_errstr(res));
            fail++;
            es = EXIT_FAILURE;
        }
        else
        {
            printf("[+] fko_new(): %s\n", fko_errstr(res));
            success++;
        }
        fko_destroy(ctx);
        ctx = NULL;

        fiu_disable(fiu_tags[i]);
    }

    printf("fiu_fault_injection() passed/failed/executed: %d/%d/%d\n",
            success, fail, exec);
    return es;
}
예제 #3
0
파일: fwknopd.c 프로젝트: weizn11/fwknop
static void
enable_fault_injections(fko_srv_options_t * const opts)
{
    if(opts->config[CONF_FAULT_INJECTION_TAG] != NULL)
    {
        if(opts->verbose)
            log_msg(LOG_INFO, "Enable fault injection tag: %s",
                    opts->config[CONF_FAULT_INJECTION_TAG]);
        if(fiu_init(0) != 0)
        {
            fprintf(stderr, "[*] Could not enable fault injection tag: %s\n",
                    opts->config[CONF_FAULT_INJECTION_TAG]);
            clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
        }
        if (fiu_enable(opts->config[CONF_FAULT_INJECTION_TAG], 1, NULL, 0) != 0)
        {
            fprintf(stderr, "[*] Could not enable fault injection tag: %s\n",
                    opts->config[CONF_FAULT_INJECTION_TAG]);
            clean_exit(opts, NO_FW_CLEANUP, EXIT_FAILURE);
        }
    }
    return;
}
예제 #4
0
파일: fwknop.c 프로젝트: rafavg77/fwknop
static int
enable_fault_injections(fko_cli_options_t * const opts)
{
    int rv = 1;
    if(opts->fault_injection_tag[0] != 0x0)
    {
        if(opts->verbose)
            log_msg(LOG_VERBOSITY_NORMAL, "[+] Enable fault injection tag: %s",
                    opts->fault_injection_tag);
        if(fiu_init(0) != 0)
        {
            log_msg(LOG_VERBOSITY_WARNING, "[*] Unable to set fault injection tag: %s",
                    opts->fault_injection_tag);
            rv = 0;
        }
        if(fiu_enable(opts->fault_injection_tag, 1, NULL, 0) != 0)
        {
            log_msg(LOG_VERBOSITY_WARNING, "[*] Unable to set fault injection tag: %s",
                    opts->fault_injection_tag);
            rv = 0;
        }
    }
    return rv;
}
예제 #5
0
파일: fiu-rc.c 프로젝트: daveh86/libfiu
/* Remote control command processing.
 *
 * Supported commands:
 *  - disable name=N
 *  - enable name=N,failnum=F,failinfo=I
 *  - enable_random <same as enable>,probability=P
 *  - enable_stack_by_name <same as enable>,func_name=F,pos_in_stack=P
 *
 * All enable* commands can also take an additional "onetime" parameter,
 * indicating that this should only fail once (analogous to the FIU_ONETIME
 * flag).
 *
 * This function is ugly, but we aim for simplicity and ease to extend for
 * future commands.
 */
int fiu_rc_string(const char *cmd, char ** const error)
{
	char m_cmd[MAX_LINE];
	char command[MAX_LINE], parameters[MAX_LINE];

	/* We need a version of cmd we can write to for parsing */
	strncpy(m_cmd, cmd, MAX_LINE);

	/* Separate command and parameters */
	{
		char *tok = NULL, *state = NULL;

		tok = strtok_r(m_cmd, " \t", &state);
		if (tok == NULL) {
			*error = "Cannot get command";
			return -1;
		}
		strncpy(command, tok, MAX_LINE);

		tok = strtok_r(NULL, " \t", &state);
		if (tok == NULL) {
			*error = "Cannot get parameters";
			return -1;
		}
		strncpy(parameters, tok, MAX_LINE);
	}

	/* Parsing of parameters.
	 *
	 * To simplify the code, we parse the command parameters here. Not all
	 * commands use all the parameters, but since they're not ambiguous it
	 * makes it easier to do it this way. */
	char *fp_name = NULL;
	int failnum = 1;
	void *failinfo = NULL;
	unsigned int flags = 0;
	double probability = -1;
	char *func_name = NULL;
	int func_pos_in_stack = -1;

	{
		/* Different tokens that we accept as parameters */
		enum {
			OPT_NAME = 0,
			OPT_FAILNUM,
			OPT_FAILINFO,
			OPT_PROBABILITY,
			OPT_FUNC_NAME,
			OPT_POS_IN_STACK,
			FLAG_ONETIME,
		};
		char * const token[] = {
			[OPT_NAME] = "name",
			[OPT_FAILNUM] = "failnum",
			[OPT_FAILINFO] = "failinfo",
			[OPT_PROBABILITY] = "probability",
			[OPT_FUNC_NAME] = "func_name",
			[OPT_POS_IN_STACK] = "pos_in_stack",
			[FLAG_ONETIME] = "onetime",
			NULL
		};

		char *value;
		char *opts = parameters;
		while (*opts != '\0') {
			switch (getsubopt(&opts, token, &value)) {
			case OPT_NAME:
				fp_name = value;
				break;
			case OPT_FAILNUM:
				failnum = atoi(value);
				break;
			case OPT_FAILINFO:
				failinfo = (void *) strtoul(value, NULL, 10);
				break;
			case OPT_PROBABILITY:
				probability = strtod(value, NULL);
				break;
			case OPT_FUNC_NAME:
				func_name = value;
				break;
			case OPT_POS_IN_STACK:
				func_pos_in_stack = atoi(value);
				break;
			case FLAG_ONETIME:
				flags |= FIU_ONETIME;
				break;
			default:
				*error = "Unknown parameter";
				return -1;
			}
		}
	}

	/* Excecute the command */
	if (strcmp(command, "disable") == 0) {
		return fiu_disable(fp_name);
	} else if (strcmp(command, "enable") == 0) {
		return fiu_enable(fp_name, failnum, failinfo, flags);
	} else if (strcmp(command, "enable_random") == 0) {
		return fiu_enable_random(fp_name, failnum, failinfo,
				flags, probability);
	} else if (strcmp(command, "enable_stack_by_name") == 0) {
		return fiu_enable_stack_by_name(fp_name, failnum, failinfo,
				flags, func_name, func_pos_in_stack);
	} else {
		*error = "Unknown command";
		return -1;
	}
}