Esempio n. 1
0
bool spnego_free_data(struct spnego_data *spnego)
{
	bool ret = true;

	if (!spnego) goto out;

	switch(spnego->type) {
	case SPNEGO_NEG_TOKEN_INIT:
		if (spnego->negTokenInit.mechTypes) {
			talloc_free(discard_const(spnego->negTokenInit.mechTypes));
		}
		data_blob_free(&spnego->negTokenInit.reqFlags);
		data_blob_free(&spnego->negTokenInit.mechToken);
		data_blob_free(&spnego->negTokenInit.mechListMIC);
		talloc_free(spnego->negTokenInit.targetPrincipal);
		break;
	case SPNEGO_NEG_TOKEN_TARG:
		if (spnego->negTokenTarg.supportedMech) {
			talloc_free(discard_const(spnego->negTokenTarg.supportedMech));
		}
		data_blob_free(&spnego->negTokenTarg.responseToken);
		data_blob_free(&spnego->negTokenTarg.mechListMIC);
		break;
	default:
		ret = false;
		break;
	}
	ZERO_STRUCTP(spnego);
out:
	return ret;
}
Esempio n. 2
0
static void free_scsi_device(struct scsi_device *sdev)
{
	if (sdev->error_str) {
		free(discard_const(sdev->error_str));
		sdev->error_str = NULL;
	}
	if (sdev->iscsi_url) {
		free(discard_const(sdev->iscsi_url));
		sdev->iscsi_url = NULL;
	}
	if (sdev->iscsi_ctx) {
		iscsi_logout_sync(sdev->iscsi_ctx);
		iscsi_destroy_context(sdev->iscsi_ctx);
		sdev->iscsi_ctx = NULL;
	}

	if (sdev->sgio_dev) {
		free(discard_const(sdev->sgio_dev));
		sdev->sgio_dev = NULL;
	}
	if (sdev->sgio_fd != -1) {
		close(sdev->sgio_fd);
		sdev->sgio_fd = -1;
	}
	free(sdev);
}
Esempio n. 3
0
END_TEST

START_TEST(test_group_both_set)
{
    struct tevent_req *req;

    test_ctx->ctx->allow_groups = discard_const(ulist_1);
    test_ctx->ctx->deny_groups = discard_const(ulist_1);

    req = simple_access_check_send(test_ctx, test_ctx->ev,
                                   test_ctx->ctx, "u1");
    fail_unless(test_ctx != NULL, "Cannot create request\n");
    tevent_req_set_callback(req, simple_access_check_done, test_ctx);

    test_loop(test_ctx);
    test_ctx->done = false;

    fail_unless(test_ctx->error == EOK, "access_simple_check failed.");
    fail_unless(test_ctx->access_granted == false,
                "Access granted while user is in deny list.");

    req = simple_access_check_send(test_ctx, test_ctx->ev,
                                   test_ctx->ctx, "u3");
    fail_unless(test_ctx != NULL, "Cannot create request\n");
    tevent_req_set_callback(req, simple_access_check_done, test_ctx);

    test_loop(test_ctx);

    fail_unless(test_ctx->error == EOK, "access_simple_check failed.");
    fail_unless(test_ctx->access_granted == false,
                "Access granted while user is not in allow list.");
}
Esempio n. 4
0
void opt_test_inherit(void **state)
{
    struct dp_option *opts = talloc_get_type(*state, struct dp_option);
    int ret;
    struct dp_option *opts_copy;
    const char *s;
    const char *sd_inherit_match[] = { "string_nodefault",
                                       "blob_nodefault",
                                       "int_nodefault",
                                       "bool_true",
                                       NULL };

    ret = dp_copy_defaults(opts, test_def_opts,
                           OPT_NUM_OPTS, &opts_copy);
    assert_int_equal(ret, EOK);
    assert_defaults(opts);

    dp_option_inherit(NULL, OPT_STRING_NODEFAULT,
                      opts, opts_copy);
    s = dp_opt_get_string(opts_copy, OPT_STRING_NODEFAULT);
    assert_null(s);

    /* string */
    assert_nondefault_string_empty(opts_copy);
    set_nondefault_string(opts);
    dp_option_inherit(discard_const(sd_inherit_match),
                      OPT_STRING_NODEFAULT,
                      opts, opts_copy);
    check_nondefault_string(opts_copy);

    /* blob */
    assert_nondefault_blob_empty(opts_copy);
    set_nondefault_blob(opts);
    dp_option_inherit(discard_const(sd_inherit_match),
                      OPT_BLOB_NODEFAULT,
                      opts, opts_copy);
    check_nondefault_blob(opts_copy);

    /* number */
    assert_nondefault_int_notset(opts_copy);
    set_nondefault_int(opts);
    dp_option_inherit(discard_const(sd_inherit_match),
                      OPT_INT_NODEFAULT,
                      opts, opts_copy);
    assert_nondefault_int_set(opts_copy);

    /* bool */
    assert_true(dp_opt_get_bool(opts_copy, OPT_BOOL_TRUE));

    ret = dp_opt_set_bool(opts, OPT_BOOL_TRUE, false);
    assert_int_equal(ret, EOK);

    dp_option_inherit(discard_const(sd_inherit_match),
                      OPT_BOOL_TRUE,
                      opts, opts_copy);

    assert_false(dp_opt_get_bool(opts_copy, OPT_BOOL_TRUE));
}
Esempio n. 5
0
/* returns the size of the uncompressed file, or 0 if it could not be
 * determined.
 */
static off_t get_uncompressed_size(const char *path)
{
        struct ecm *ecm;
        size_t pos;
        TDB_DATA key, data;

        LOG("GET_UNCOMPRESSED_SIZE [%s]\n", path);

        key.dptr = discard_const(path);
        key.dsize = strlen(path);
        data = tdb_fetch(filesize_tdb, key);
        if (data.dptr) {
                off_t size = *(off_t *)data.dptr;
                free(data.dptr);
                return size;
        }

        LOG("GET_UNCOMPRESSED_SIZE SLOW PATH [%s]\n", path);

        ecm = ecm_open_file(dir_fd, path);
        if (ecm == NULL) {
                LOG("Failed to open ECM file %s in get_uncompressed_size\n",
                    path);
                return 0;
        }
        pos = ecm_get_file_size(ecm);
        ecm_close_file(ecm);
        LOG("GET_UNCOMPRESSED_SIZE [%s] %zu\n", path, pos);

        data.dptr = (uint8_t *)&pos;
        data.dsize = sizeof(pos);
        tdb_store(filesize_tdb, key, data, TDB_REPLACE);

        return pos;
}
Esempio n. 6
0
static errno_t
ipa_sudo_conv_store(hash_table_t *table,
                    const char *key,
                    void *value)
{
    hash_key_t hkey;
    hash_value_t hvalue;
    int hret;

    if (table == NULL || key == NULL) {
        return EINVAL;
    }

    hkey.type = HASH_KEY_STRING;
    hkey.str = discard_const(key);

    /* If value is NULL we don't want to override existing entry. */
    if (value == NULL && hash_has_key(table, &hkey)) {
        return EEXIST;
    }

    hvalue.type = HASH_VALUE_PTR;
    hvalue.ptr = value;

    hret = hash_enter(table, &hkey, &hvalue);
    if (hret != HASH_SUCCESS) {
        return EIO;
    }

    if (value != NULL) {
        talloc_steal(table, value);
    }

    return EOK;
}
Esempio n. 7
0
void dyndns_test_error(void **state)
{
    struct tevent_req *req;
    errno_t ret;
    TALLOC_CTX *tmp_ctx;

    tmp_ctx = talloc_new(global_talloc_context);
    assert_non_null(tmp_ctx);
    check_leaks_push(tmp_ctx);

    dyndns_test_ctx->state = MOCK_NSUPDATE_ERR;

    req = be_nsupdate_send(tmp_ctx, dyndns_test_ctx->tctx->ev,
                           BE_NSUPDATE_AUTH_GSS_TSIG,
                           discard_const("test message"), false);
    assert_non_null(req);
    tevent_req_set_callback(req, dyndns_test_done, dyndns_test_ctx);

    /* Wait until the test finishes with EIO (child error) */
    ret = test_ev_loop(dyndns_test_ctx->tctx);
    DEBUG(SSSDBG_TRACE_LIBS,
          "Child request returned [%d]: %s\n", ret, strerror(ret));
    assert_int_equal(ret, ERR_DYNDNS_FAILED);

    assert_true(WIFEXITED(dyndns_test_ctx->child_status));
    assert_int_equal(WEXITSTATUS(dyndns_test_ctx->child_status), 1);

    assert_true(check_leaks_pop(tmp_ctx) == true);
    talloc_free(tmp_ctx);
}
Esempio n. 8
0
/*
	Just try locking/unlocking a single record once
*/
static void fetch_lock_once(struct ctdb_context *ctdb, struct event_context *ev)
{
	TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
	TDB_DATA key, data;
	struct ctdb_record_handle *h;
	static time_t t = 0, t2;

	key.dptr = discard_const(TESTKEY);
	key.dsize = strlen(TESTKEY);

//	printf("Trying to fetch lock the record ...\n");

	h = ctdb_fetch_readonly_lock(ctdb_db, tmp_ctx, key, &data, true);
	if (h == NULL) {
		printf("Failed to fetch record '%s' on node %d\n", 
	       		(const char *)key.dptr, ctdb_get_pnn(ctdb));
		talloc_free(tmp_ctx);
		exit(10);
	}

	count++;
	t2 = time(NULL);
	if (t != 0 && t != t2) {
		static int last_count = 0;

		printf("count : %d\n", count - last_count);
		last_count = count;
	}
	t = t2;

	talloc_free(tmp_ctx);
}
Esempio n. 9
0
static void do_test1(void)
{
	struct hash_count_context *hc = NULL;
	TALLOC_CTX *mem_ctx = talloc_new(NULL);
	struct timeval interval = {1, 0};
	TDB_DATA key;
	int count = 0;
	int ret, i;

	key.dptr = (uint8_t *)discard_const(KEY);
	key.dsize = strlen(KEY);

	ret = hash_count_increment(hc, key);
	assert(ret == EINVAL);

	ret = hash_count_init(mem_ctx, interval, NULL, NULL, &hc);
	assert(ret == EINVAL);

	ret = hash_count_init(mem_ctx, interval, test1_handler, &count, &hc);
	assert(ret == 0);
	assert(hc != NULL);

	for (i=0; i<10; i++) {
		ret = hash_count_increment(hc, key);
		assert(ret == 0);
		assert(count == i+1);
	}

	talloc_free(hc);
	ret = talloc_get_size(mem_ctx);
	assert(ret == 0);

	talloc_free(mem_ctx);
}
Esempio n. 10
0
END_TEST

START_TEST(test_case_sensitive)
{
    char *result;
    int ret;
    const char *file_template = BASE"_%u";
    const char *expected_cs = BASE"_TestUser";
    const char *expected_ci = BASE"_testuser";

    kr->pd->user = discard_const("TestUser");
    ret = dp_opt_set_string(kr->krb5_ctx->opts, KRB5_CCACHEDIR, CCACHE_DIR);
    fail_unless(ret == EOK, "Failed to set Ccache dir");

    result = expand_ccname_template(tmp_ctx, kr, file_template, NULL, true, true);

    fail_unless(result != NULL, "Cannot expand template [%s].", file_template);
    fail_unless(strcmp(result, expected_cs) == 0,
                "Expansion failed, result [%s], expected [%s].",
                result, expected_cs);

    result = expand_ccname_template(tmp_ctx, kr, file_template, NULL, true, false);

    fail_unless(result != NULL, "Cannot expand template [%s].", file_template);
    fail_unless(strcmp(result, expected_ci) == 0,
                "Expansion failed, result [%s], expected [%s].",
                result, expected_ci);
}
Esempio n. 11
0
/*
  set a pointer in a existing MprVar, freeing it when the property goes away
*/
void mprSetPtrChild(struct MprVar *v, const char *propname, const void *p)
{
	mprSetVar(v, propname, mprCreatePtrVar(discard_const(p)));
	v = mprGetProperty(v, propname, NULL);
	v->allocatedData = 1;
	talloc_steal(mprMemCtx(), p);
}
Esempio n. 12
0
END_TEST


void setup_talloc_context(void)
{
    int ret;
    int i;

    struct pam_data *pd;
    struct krb5_ctx *krb5_ctx;
    fail_unless(tmp_ctx == NULL, "Talloc context already initialized.");
    tmp_ctx = talloc_new(NULL);
    fail_unless(tmp_ctx != NULL, "Cannot create talloc context.");

    kr = talloc_zero(tmp_ctx, struct krb5child_req);
    fail_unless(kr != NULL, "Cannot create krb5child_req structure.");

    pd = create_pam_data(tmp_ctx);
    fail_unless(pd != NULL, "Cannot create pam_data structure.");

    krb5_ctx = talloc_zero(tmp_ctx, struct krb5_ctx);
    fail_unless(pd != NULL, "Cannot create krb5_ctx structure.");

    pd->user = discard_const(USERNAME);
    kr->uid = atoi(UID);
    kr->upn = discard_const(PRINCIPAL_NAME);
    pd->cli_pid = atoi(PID);

    krb5_ctx->opts = talloc_zero_array(tmp_ctx, struct dp_option, KRB5_OPTS);
    fail_unless(krb5_ctx->opts != NULL, "Cannot created options.");
    for (i = 0; i < KRB5_OPTS; i++) {
        krb5_ctx->opts[i].opt_name = default_krb5_opts[i].opt_name;
        krb5_ctx->opts[i].type = default_krb5_opts[i].type;
        krb5_ctx->opts[i].def_val = default_krb5_opts[i].def_val;
    }
    ret = dp_opt_set_string(krb5_ctx->opts, KRB5_REALM, REALM);
    fail_unless(ret == EOK, "Failed to set Realm");
    ret = dp_opt_set_string(krb5_ctx->opts, KRB5_CCACHEDIR, CCACHE_DIR);
    fail_unless(ret == EOK, "Failed to set Ccache dir");

    kr->homedir = HOME_DIRECTORY;

    kr->pd = pd;
    kr->krb5_ctx = krb5_ctx;

}
Esempio n. 13
0
static void
iscsi_free_discovery_addresses(struct iscsi_context *iscsi, struct iscsi_discovery_address *addresses)
{
	while (addresses != NULL) {
		struct iscsi_discovery_address *next = addresses->next;

		iscsi_free(iscsi, discard_const(addresses->target_name));
		addresses->target_name = NULL;

		iscsi_free(iscsi, discard_const(addresses->target_address));
		addresses->target_address = NULL;

		addresses->next = NULL;
		iscsi_free(iscsi, addresses);
		addresses = next;
	}
}
Esempio n. 14
0
NTSTATUS wbsrv_samba3_priv_pipe_dir(struct wbsrv_samba3_call *s3call)
{
	const char *path = s3call->wbconn->listen_socket->service->priv_socket_path;
	s3call->response.result		 = WINBINDD_OK;
	s3call->response.extra_data.data = discard_const(path);

	s3call->response.length += strlen(path) + 1;
	return NT_STATUS_OK;
}
Esempio n. 15
0
END_TEST

START_TEST(test_parse_args)
{
    struct pa_testcase {
        const char *argstr;
        const char **parsed;
    };

    TALLOC_CTX *test_ctx;
    int i, ii;
    int ret;
    char **parsed;
    char **only_ret;
    char **only_exp;
    char **both;

    test_ctx = talloc_new(NULL);

    /* Positive tests */
    const char *parsed1[] = { "foo", NULL };
    const char *parsed2[] = { "foo", "a", NULL };
    const char *parsed3[] = { "foo", "b", NULL };
    const char *parsed4[] = { "foo", "a c", NULL };
    const char *parsed5[] = { "foo", "a", "d", NULL };
    const char *parsed6[] = { "foo", "a", "e", NULL };
    const char *parsed7[] = { "foo", "a", "f", NULL };
    const char *parsed8[] = { "foo", "a\tg", NULL };
    struct pa_testcase tc[] = {
        { "foo", parsed1 },
        { "foo a", parsed2 },
        { "foo  b", parsed3 },
        { "foo a\\ c", parsed4 },
        { "foo a d ", parsed5 },
        { "foo   a   e   ", parsed6 },
        { "foo	a	 	f 	", parsed7 },
        { "foo a\\\tg", parsed8 },
        { NULL, NULL }
    };

    for (i=0; tc[i].argstr != NULL; i++) {
        parsed = parse_args(tc[i].argstr);
        fail_if(parsed == NULL && tc[i].parsed != NULL,
                "Could not parse correct argument string '%s'\n");

        ret = diff_string_lists(test_ctx, parsed, discard_const(tc[i].parsed),
                                &only_ret, &only_exp, &both);
        fail_unless(ret == EOK, "diff_string_lists returned error [%d]", ret);
        fail_unless(only_ret[0] == NULL, "The parser returned more data than expected\n");
        fail_unless(only_exp[0] == NULL, "The parser returned less data than expected\n");

        for (ii = 0; parsed[ii]; ii++) free(parsed[ii]);
        free(parsed);
    }

    talloc_free(test_ctx);
}
Esempio n. 16
0
File: init.c Progetto: dooglus/ccan
int iscsi_destroy_context(struct iscsi_context *iscsi)
{
    struct iscsi_pdu *pdu;

    if (iscsi == NULL) {
        return 0;
    }
    if (iscsi->initiator_name != NULL) {
        free(discard_const(iscsi->initiator_name));
        iscsi->initiator_name = NULL;
    }
    if (iscsi->alias != NULL) {
        free(discard_const(iscsi->alias));
        iscsi->alias = NULL;
    }
    if (iscsi->is_loggedin != 0) {
        printf("deswtroying context while logged in\n");
    }
    if (iscsi->fd != -1) {
        iscsi_disconnect(iscsi);
    }

    if (iscsi->inbuf != NULL) {
        free(iscsi->inbuf);
        iscsi->inbuf = NULL;
        iscsi->insize = 0;
        iscsi->inpos = 0;
    }

    while ((pdu = iscsi->outqueue)) {
        DLIST_REMOVE(iscsi->outqueue, pdu);
        pdu->callback(iscsi, ISCSI_STATUS_CANCELLED, NULL, pdu->private_data);
        iscsi_free_pdu(iscsi, pdu);
    }
    while ((pdu = iscsi->waitpdu)) {
        DLIST_REMOVE(iscsi->waitpdu, pdu);
        pdu->callback(iscsi, ISCSI_STATUS_CANCELLED, NULL, pdu->private_data);
        iscsi_free_pdu(iscsi, pdu);
    }

    free(iscsi);

    return 0;
}
Esempio n. 17
0
static int fuse_nfs_write(const char *path, const char *buf, size_t size,
       off_t offset, struct fuse_file_info *fi)
{
	int ret = 0;
	struct nfsfh *nfsfh = (struct nfsfh *)fi->fh;

	ret = nfs_pwrite(nfs, nfsfh, offset, size, discard_const(buf));

	return ret;
}
Esempio n. 18
0
/*
	Just try locking/unlocking a single record once
*/
static void fetch_lock_once(struct ctdb_context *ctdb, struct event_context *ev, uint32_t generation)
{
	TALLOC_CTX *tmp_ctx = talloc_new(ctdb);
	TDB_DATA key, data;
	struct ctdb_record_handle *h;
	struct ctdb_ltdb_header *header;
	int ret;

	key.dptr = discard_const(TESTKEY);
	key.dsize = strlen(TESTKEY);

	printf("Trying to fetch lock the record ...\n");

	h = ctdb_fetch_readonly_lock(ctdb_db, tmp_ctx, key, &data, false);
	if (h == NULL) {
		printf("Failed to fetch record '%s' on node %d\n", 
	       		(const char *)key.dptr, ctdb_get_pnn(ctdb));
		talloc_free(tmp_ctx);
		exit(10);
	}

	printf("Record fetchlocked.\n");
	header = talloc_memdup(tmp_ctx, ctdb_header_from_record_handle(h), sizeof(*header));
       	printf("RSN:%d\n", (int)header->rsn);
	talloc_free(h);
	printf("Record released.\n");

	printf("Write new record with RSN+10\n");
	header->rsn += 10;
	data.dptr = (void *)talloc_asprintf(tmp_ctx, "%d", (int)header->rsn);
	data.dsize = strlen((char *)data.dptr);

	ret = ctdb_ctrl_updaterecord(ctdb, ctdb, timeval_zero(), CTDB_CURRENT_NODE, ctdb_db, key, header, data);
	if (ret != 0) {
		printf("Failed to writerecord,  ret==%d\n", ret);	
		exit(1);
	}

	printf("re-fetch the record\n");
	h = ctdb_fetch_lock(ctdb_db, tmp_ctx, key, &data);
	if (h == NULL) {
		printf("Failed to fetch record '%s' on node %d\n", 
	       		(const char *)key.dptr, ctdb_get_pnn(ctdb));
		talloc_free(tmp_ctx);
		exit(10);
	}

	printf("Record fetchlocked.\n");
	header = talloc_memdup(tmp_ctx, ctdb_header_from_record_handle(h), sizeof(*header));
       	printf("RSN:%d\n", (int)header->rsn);
	talloc_free(h);
	printf("Record released.\n");

	talloc_free(tmp_ctx);
}
Esempio n. 19
0
END_TEST

START_TEST(test_both_set)
{
    int ret;
    bool access_granted = false;

    ctx->allow_users = discard_const(ulist_1);
    ctx->deny_users = discard_const(ulist_1);

    ret = simple_access_check(ctx, "u1", &access_granted);
    fail_unless(ret == EOK, "access_simple_check failed.");
    fail_unless(access_granted == false, "Access granted "
                                         "while user is in deny list.");

    ret = simple_access_check(ctx, "u3", &access_granted);
    fail_unless(ret == EOK, "access_simple_check failed.");
    fail_unless(access_granted == false, "Access granted "
                                        "while user is not in allow list.");
}
Esempio n. 20
0
static bool test_create(struct torture_context *tctx, 
			const void *tcase_data, 
			const void *test_data)
{
	struct share_context *ctx = discard_const(tcase_data);
	int count;
	const char **names;
	int i;
	bool found = false;
	struct share_info inf[] = { 
		{ SHARE_INFO_STRING, SHARE_TYPE, discard_const_p(void *, "IPC$") },
Esempio n. 21
0
int ipapwd_get_cur_kvno(Slapi_Entry *target)
{
    Slapi_Attr *krbPrincipalKey = NULL;
    Slapi_ValueSet *svs;
    Slapi_Value *sv;
    BerElement *be = NULL;
    const struct berval *cbval;
    ber_tag_t tag, tmp;
    ber_int_t tkvno;
    int hint;
    int kvno;
    int ret;

    /* retrieve current kvno and and keys */
    ret = slapi_entry_attr_find(target, "krbPrincipalKey", &krbPrincipalKey);
    if (ret != 0) {
        return 0;
    }

    kvno = 0;

    slapi_attr_get_valueset(krbPrincipalKey, &svs);
    hint = slapi_valueset_first_value(svs, &sv);
    while (hint != -1) {
        cbval = slapi_value_get_berval(sv);
        if (!cbval) {
            LOG_TRACE("Error retrieving berval from Slapi_Value\n");
            goto next;
        }
        be = ber_init(discard_const(cbval));
        if (!be) {
            LOG_TRACE("ber_init() failed!\n");
            goto next;
        }

        tag = ber_scanf(be, "{xxt[i]", &tmp, &tkvno);
        if (tag == LBER_ERROR) {
            LOG_TRACE("Bad OLD key encoding ?!\n");
            ber_free(be, 1);
            goto next;
        }

        if (tkvno > kvno) {
            kvno = tkvno;
        }

        ber_free(be, 1);
next:
        hint = slapi_valueset_next_value(svs, hint, &sv);
    }

    return kvno;
}
Esempio n. 22
0
static bool test_list_empty(struct torture_context *tctx, 
			    const void *tcase_data, 
			    const void *test_data)
{
	struct share_context *ctx = discard_const(tcase_data);
	int count;
	const char **names;

	torture_assert_ntstatus_ok(tctx, share_list_all(tctx, ctx, &count, &names),
							   "share_list_all failed");

	return true;
}
Esempio n. 23
0
END_TEST

START_TEST(test_string_in_list)
{
    bool is_in;
    char *empty_list[] = {NULL};
    char *list[] = {discard_const("ABC"),
                    discard_const("DEF"),
                    discard_const("GHI"),
                    NULL};

    is_in = string_in_list(NULL, NULL, false);
    fail_unless(!is_in, "NULL string is in NULL list.");

    is_in = string_in_list(NULL, empty_list, false);
    fail_unless(!is_in, "NULL string is in empty list.");

    is_in = string_in_list(NULL, list, false);
    fail_unless(!is_in, "NULL string is in list.");

    is_in = string_in_list("ABC", NULL, false);
    fail_unless(!is_in, "String is in NULL list.");

    is_in = string_in_list("ABC", empty_list, false);
    fail_unless(!is_in, "String is in empty list.");

    is_in = string_in_list("ABC", list, false);
    fail_unless(is_in, "String is not list.");

    is_in = string_in_list("abc", list, false);
    fail_unless(is_in, "String is not case in-sensitive list.");

    is_in = string_in_list("abc", list, true);
    fail_unless(!is_in, "Wrong string found in case sensitive list.");

    is_in = string_in_list("123", list, false);
    fail_unless(!is_in, "Wrong string found in list.");

}
Esempio n. 24
0
/* This function takes a path to a file and returns true if this needs
 * ecm unpacking.
 * For a file <file> we need to unpack the file if
 *   <file>         does not exist
 *   <file>.ecm     exists
 *   <file>.ecm.edi exists
 * In that situation READDIR will just turn a single instance for the name
 * <file> and hide the entries for <file>.ecm and <file>.ecm.edi
 *
 * IF all three files exist, we do not mutate any of the READDIR data
 * and return all three names. Then we just redirect all I/O to the unpacked
 * file. The reason we do not hide the <file>.ecm and <file>.ecm.edi is to make
 * it possible for the user to see that something is odd/wrong and possibly
 * take action. (action == delete the unpacked file, it is redundant.)
 */
static int need_ecm_uncompress(const char *file) {
        char stripped[PATH_MAX];
        char tmp[PATH_MAX];
        struct stat st;
        TDB_DATA key, data;
        uint8_t ret = 1;

        LOG("NEED_ECM_UNCOMPRESS [%s]\n", file);
        key.dptr = discard_const(file);
        key.dsize = strlen(file);
        data = tdb_fetch(nu_tdb, key);
        if (data.dptr) {
                uint8_t val = data.dptr[0];
                free(data.dptr);
                return val;
        }

        LOG("NEED_ECM_UNCOMPRESS SLOW PATH [%s]\n", file);

        snprintf(stripped, PATH_MAX,"%s", file);
        if (strlen(stripped) > 4 &&
            !strcmp(stripped + strlen(stripped) - 4, ".edi")) {
                stripped[strlen(stripped) - 4] = 0;
        }
        if (strlen(stripped) > 4 &&
            !strcmp(stripped + strlen(stripped) - 4, ".ecm")) {
                stripped[strlen(stripped) - 4] = 0;
        }

        if (fstatat(dir_fd, stripped, &st, AT_NO_AUTOMOUNT) == 0) {
                ret = 0;
                goto finished;
        }
        snprintf(tmp, PATH_MAX, "%s.ecm", stripped);
        if (fstatat(dir_fd, tmp, &st, AT_NO_AUTOMOUNT) != 0) {
                ret = 0;
                goto finished;
        }
        snprintf(tmp, PATH_MAX, "%s.ecm.edi", stripped);
        if (fstatat(dir_fd, tmp, &st, AT_NO_AUTOMOUNT) != 0) {
                ret = 0;
                goto finished;
        }
        
finished:
        data.dptr = &ret;
        data.dsize = 1;
        tdb_store(nu_tdb, key, data, TDB_REPLACE);
        return ret;
}
Esempio n. 25
0
int iscsi_process_nop_out_reply(struct iscsi_context *iscsi, struct iscsi_pdu *pdu, const unsigned char *hdr, int size)
{
	struct iscsi_data data;

	data.data = NULL;
	data.size = 0;

	if (size > ISCSI_HEADER_SIZE) {
		data.data = discard_const(&hdr[ISCSI_HEADER_SIZE]);
		data.size = size - ISCSI_HEADER_SIZE;
	}
	pdu->callback(iscsi, ISCSI_STATUS_GOOD, &data, pdu->private_data);

	return 0;
}
Esempio n. 26
0
static struct sss_domain_info *create_test_domain(TALLOC_CTX *mem_ctx,
                                                  const char *name,
                                                  const char *flatname,
                                                  struct sss_domain_info *parent,
                                                  struct sss_names_ctx *nctx)
{
    struct sss_domain_info *dom;

    dom = talloc_zero(mem_ctx, struct sss_domain_info);
    assert_non_null(dom);

    /* just to make new_subdomain happy */
    dom->sysdb = talloc_zero(dom, struct sysdb_ctx);
    assert_non_null(dom->sysdb);

    dom->name = discard_const(name);
    dom->flat_name = discard_const(flatname);
    dom->parent = parent;
    dom->names = nctx;
    dom->provider = discard_const(PROVIDER);
    dom->conn_name = discard_const(CONNNAME);

    return dom;
}
Esempio n. 27
0
WERROR dsdb_load_oid_mappings_ldb(struct dsdb_schema *schema,
				  const struct ldb_val *prefixMap,
				  const struct ldb_val *schemaInfo)
{
	WERROR werr;
	const char *schema_info;
	struct dsdb_schema_prefixmap *pfm;
	TALLOC_CTX *mem_ctx;

	/* verify schemaInfo blob is valid one */
	if (!dsdb_schema_info_blob_is_valid(schemaInfo)) {
		DEBUG(0,(__location__": dsdb_schema_info_blob_is_valid() failed.\n"));
	        return WERR_INVALID_PARAMETER;
	}

	mem_ctx = talloc_new(schema);
	W_ERROR_HAVE_NO_MEMORY(mem_ctx);

	/* fetch prefixMap */
	werr = _dsdb_prefixmap_from_ldb_val(prefixMap,
					    mem_ctx, &pfm);
	if (!W_ERROR_IS_OK(werr)) {
		DEBUG(0, (__location__ " _dsdb_prefixmap_from_ldb_val failed: %s\n", win_errstr(werr)));
		talloc_free(mem_ctx);
		return werr;
	}

	/* decode schema_info */
	schema_info = hex_encode_talloc(mem_ctx,
					schemaInfo->data,
					schemaInfo->length);
	if (!schema_info) {
		talloc_free(mem_ctx);
		return WERR_NOMEM;
	}

	/* store prefixMap and schema_info into cached Schema */
	talloc_free(schema->prefixmap);
	schema->prefixmap = talloc_steal(schema, pfm);

	talloc_free(discard_const(schema->schema_info));
	schema->schema_info = talloc_steal(schema, schema_info);

	/* clean up locally allocated mem */
	talloc_free(mem_ctx);

	return WERR_OK;
}
Esempio n. 28
0
ssize_t pwrite(int fd, const void *buf, size_t count, off_t offset) {
	if (nfs_fd_list[fd].is_nfs == 1) {
		int ret;

		LD_NFS_DPRINTF(9, "pwrite(fd:%d offset:%d count:%d)", fd,
			(int)offset, (int)count);
		if ((ret = nfs_pwrite(nfs_fd_list[fd].nfs, nfs_fd_list[fd].fh,
				offset, count,
				(char *)discard_const(buf))) < 0) {
			errno = -ret;
			return -1;
		}
		return ret;
	}
	return real_pwrite(fd, buf, count, offset);
}
Esempio n. 29
0
WERROR dsdb_load_oid_mappings_ldb(struct dsdb_schema *schema,
				  const struct ldb_val *prefixMap,
				  const struct ldb_val *schemaInfo)
{
	WERROR status;
	const char *schema_info;
	struct dsdb_schema_prefixmap *pfm;
	TALLOC_CTX *mem_ctx;

	/* verify input params */
	if (schemaInfo->length != 21) {
		return WERR_INVALID_PARAMETER;
	}
	if (schemaInfo->data[0] != 0xFF) {
		return WERR_INVALID_PARAMETER;
	}

	mem_ctx = talloc_new(schema);
	W_ERROR_HAVE_NO_MEMORY(mem_ctx);

	/* fetch prefixMap */
	status = _dsdb_prefixmap_from_ldb_val(prefixMap,
					      schema->iconv_convenience,
					      mem_ctx, &pfm);
	W_ERROR_NOT_OK_RETURN(status);

	/* decode schema_info */
	schema_info = hex_encode_talloc(mem_ctx,
					schemaInfo->data,
					schemaInfo->length);
	if (!schema_info) {
		talloc_free(mem_ctx);
		return WERR_NOMEM;
	}

	/* store prefixMap and schema_info into cached Schema */
	talloc_free(schema->prefixmap);
	schema->prefixmap = talloc_steal(schema, pfm);

	talloc_free(discard_const(schema->schema_info));
	schema->schema_info = talloc_steal(schema, schema_info);

	/* clean up locally allocated mem */
	talloc_free(mem_ctx);

	return WERR_OK;
}
Esempio n. 30
0
static struct tevent_req *aio_posix_pwrite_send(
	struct vfs_handle_struct *handle,
	TALLOC_CTX *mem_ctx, struct tevent_context *ev,
	struct files_struct *fsp, const void *data, size_t n, off_t offset)
{
	struct tevent_req *req;
	struct aio_posix_state *state;
	struct aiocb *a;
	int ret;

	req = tevent_req_create(mem_ctx, &state, struct aio_posix_state);
	if (req == NULL) {
		return NULL;
	}

	a = &state->acb;

	a->aio_fildes = fsp->fh->fd;
	a->aio_buf = discard_const(data);
	a->aio_nbytes = n;
	a->aio_offset = offset;
	a->aio_sigevent.sigev_notify = SIGEV_SIGNAL;
	a->aio_sigevent.sigev_signo  = RT_SIGNAL_AIO;
	a->aio_sigevent.sigev_value.sival_ptr = req;

	ret = aio_write(a);
	if (ret == 0) {
		talloc_set_destructor(state, aio_posix_state_destructor);
		return req;
	}

	if (errno == EAGAIN) {
		/*
		 * aio overloaded, do the sync fallback
		 */
		state->ret = sys_pwrite(fsp->fh->fd, data, n, offset);
		if (state->ret == -1) {
			state->err = errno;
		}
		tevent_req_done(req);
		return tevent_req_post(req, ev);
	}

	tevent_req_error(req, errno);
	return tevent_req_post(req, ev);
}