Beispiel #1
0
void list_data_set_int(list_data *data, int num){
	str_reset(data->string);
	free(data->string);
	data->string = NULL;
	data->num = num;
	data->type = DATA_TYPE_INT;
}
Beispiel #2
0
void list_data_set_char(list_data *data, char *value){
	str_reset(data->string);
	free(data->string);
	data->string = NULL;
	data->num = -1;
	data->string = new_str_p(value);
	data->type = DATA_TYPE_STR;
}
Beispiel #3
0
void list_data_set_str(list_data *data, str *string){
	str_reset(data->string);
	free(data->string);
	data->string = NULL;
	data->num = -1;
	data->string = new_str_p_from_copy(string);
	data->type = DATA_TYPE_STR;
}
Beispiel #4
0
void list_data_reset(list_data *data){
	if (data == NULL){
		return;
	}
	str_reset(data->string);
	free(data->string);
	data->string = NULL;
	data->num = -1;
	data->type = DATA_TYPE_NULL;
}
Beispiel #5
0
void
var_set_str(struct variable *var, char *str)
{
	assert(var != NULL && str != NULL);

	var->type = VAR_STRING;

	str_reset(&var->str);
	str_append(&var->str, str);
}
Beispiel #6
0
static int ocserv_conv(int msg_size, const struct pam_message **msg, 
		struct pam_response **resp, void *uptr)
{
struct pam_ctx_st * pctx = uptr;
unsigned i;

	if (msg_size == 0)
		return PAM_SUCCESS;

	pctx->replies = calloc(1, msg_size*sizeof(*pctx->replies));
	if (pctx->replies == NULL)
		return PAM_BUF_ERR;

	for (i=0;i<msg_size;i++) {
		switch (msg[i]->msg_style) {
			case PAM_ERROR_MSG:
			case PAM_TEXT_INFO:
				syslog(LOG_DEBUG, "PAM-auth conv info: %s", msg[i]->msg);

				str_append_str(&pctx->msg, msg[i]->msg);
				str_append_data(&pctx->msg, " ", 1);
				pctx->sent_msg = 1;
				break;
			case PAM_PROMPT_ECHO_OFF:
			case PAM_PROMPT_ECHO_ON:
				if (pctx->sent_msg == 0) {
					/* no message, just asking for password */
					str_reset(&pctx->msg);
					pctx->sent_msg = 1;

				}

				if (msg[i]->msg) {
					str_append_str(&pctx->msg, msg[i]->msg);
				}

				syslog(LOG_DEBUG, "PAM-auth conv: echo-%s, msg: '%s'", (msg[i]->msg_style==PAM_PROMPT_ECHO_ON)?"on":"off", msg[i]->msg!=NULL?msg[i]->msg:"");

				pctx->state = PAM_S_WAIT_FOR_PASS;
				pctx->cr_ret = PAM_SUCCESS;
				co_resume();
				pctx->state = PAM_S_INIT;

				pctx->replies[i].resp = strdup(pctx->password);
				pctx->sent_msg = 0;
				break;
                }
	}

	*resp = pctx->replies;
	pctx->replies = NULL;
	return PAM_SUCCESS;  
}
Beispiel #7
0
void test_str(void)
{
    SECTION_BEGIN("str");
    str s;
    str_init(&s, "Some long text or something");
    TEST_BEGIN("find string");
    assert(str_find_cstr(&s, "or") == 15);
    str_reset(&s, "some other string 1232 and stuffy");
    assert(str_find_cstr(&s, " 12") == 17);
    assert(str_find_cstr(&s, "stringy") == -1);
    TEST_END("find string");
    SECTION_END("str");
}
Beispiel #8
0
void list_data_set_bin(list_data *data, char *value, int value_length){
	#if NULL_ARG_CHECK
	if (value == NULL){
		fprintf(stderr, "[error] list_data_set_bin: value == NULL\n");
		return;
	}
	#endif
	str_reset(data->string);
	free(data->string);
	data->string = NULL;
	data->num = -1;
	data->string = new_str_p_from_bin(value, value_length);
	data->type = DATA_TYPE_STR;
}
Beispiel #9
0
void list_append_split_bin(list *l, char *value, int value_length,
	char *split_key, byte skip_space){
	#if NULL_ARG_CHECK
	if (value == NULL){
		fprintf(stderr, "[error] list_append_split_bin: value == NULL\n");
		return;
	}
	if (split_key == NULL){
		fprintf(stderr, "[error] list_append_split_bin: split_key == NULL\n");
		return;
	}
	#endif
	str *string = new_str_p(NULL);
	int split_key_length = strlen(split_key);
	char *word = malloc(sizeof(char)*(value_length+1));
	int i;
	int word_i = 0;
	int split_key_i = 0;
	char j;
	for (i=0; i<value_length; i++){
		j = value[i];
		//if ((skip_space != 0) && (j == ' ' || j == '\t')){
		//	continue;
		//}
		word[word_i] = j;
		//word[word_i+1] = '\x00';
		word_i += 1;
		if (j == split_key[split_key_i]){
			split_key_i += 1;
		}
		else{
			split_key_i = 0;
		}
		if (split_key[split_key_i] == '\x00'){
			if (skip_space != 0){
				str_set_bin(string, word, word_i-split_key_length);
				str_strip(string);
				list_append_str(l, string);
			}
			else{
				list_append_bin(l, word, word_i-split_key_length);
			}
			word_i = 0;
			split_key_i = 0;
			word[0] = '\x00';
		}
		//printf("j %c split_key[split_key_i] %c split_key_i %d\n",
		//	j, split_key[split_key_i], split_key_i);
	}
	if (skip_space != 0){
		str_set_bin(string, word, word_i);
		str_strip(string);
		list_append_str(l, string);
	}
	else{
		list_append_bin(l, word, word_i);
	}
	str_reset(string);
	free(word);
	free(string);
	word = NULL;
	string = NULL;
}
Beispiel #10
0
FILE * find_file(const char *open_mode,
                 const char *prefix, const char *name, const char *extension)
{
    struct str path;
    FILE *f = NULL;
    size_t i;

    if (!str_init(&path)) {
        log_error("Failed to initialize path string.\n");
        return NULL;
    }

    for (i = 0; i < ARRAY_SIZE(search_paths) && f == NULL; i++) {
        str_reset(&path);

        switch (search_paths[i].pfx) {
            case PFX_NONE:
                break;

            case PFX_HOME_DIR:
                if (!str_append(&path, getenv("HOME")) ||
                    !str_append(&path, "/")) {

                    log_error("Failed to prepend $HOME to search path.\n");
                    continue;
                }
                break;

            case PFX_DATA_DIR:
                if (!str_append(&path, OOKIEDOKIE_DATA_DIR)) {
                    log_error("Failed to append \"%s\" to search path.\n",
                              OOKIEDOKIE_DATA_DIR);
                    continue;
                }
                break;
        }

        if (!str_append(&path, search_paths[i].path)) {
            log_error("Failed to append search path entry.\n");
            continue;
        }

        if (prefix && !str_append(&path, prefix)) {
            log_error("Failed to append file name prefix to path.\n");
            continue;
        }

        if (!str_append(&path, name)) {
            log_error("Failed to append file name to path.\n");
            continue;
        }

        if (extension && !str_append(&path, extension)) {
            log_error("Failed to append extension to path.\n");
            continue;
        }

        log_debug("Searching for: %s\n", path.buf);
        f = fopen(path.buf, open_mode);

        if (f) {
            log_debug("Opened %s\n", path.buf);
        }
    }

out:
    str_deinit(&path);
    return f;
}