示例#1
0
int main(int argc, const char **argv)
{
	struct ldb_context *ldb;
	int count=0;
	int i, ret=LDB_SUCCESS;
	struct ldb_cmdline *options;

	ldb = ldb_init(NULL, NULL);

	options = ldb_cmdline_process(ldb, argc, argv, usage);

	if (options->argc == 0) {
		ret = process_file(ldb, stdin, &count);
	} else {
		for (i=0;i<options->argc;i++) {
			const char *fname = options->argv[i];
			FILE *f;
			f = fopen(fname, "r");
			if (!f) {
				perror(fname);
				exit(1);
			}
			ret = process_file(ldb, f, &count);
			fclose(f);
		}
	}

	talloc_free(ldb);

	printf("Modified %d records with %d failures\n", count, failures);

	return ret;
}
示例#2
0
文件: ldbrename.c 项目: gojdic/samba
int main(int argc, const char **argv)
{
	struct ldb_context *ldb;
	int ret;
	struct ldb_cmdline *options;
	const struct ldb_dn *dn1, *dn2;

	ldb_global_init();

	ldb = ldb_init(NULL);

	options = ldb_cmdline_process(ldb, argc, argv, usage);

	if (options->argc < 2) {
		usage();
	}

	dn1 = ldb_dn_explode(ldb, options->argv[0]);
	dn2 = ldb_dn_explode(ldb, options->argv[1]);

	ret = ldb_rename(ldb, dn1, dn2);
	if (ret == 0) {
		printf("Renamed 1 record\n");
	} else  {
		printf("rename of '%s' to '%s' failed - %s\n", 
			options->argv[0], options->argv[1], ldb_errstring(ldb));
	}

	talloc_free(ldb);
	
	return ret;
}
示例#3
0
int otherTest()
{
    lc3 lc3;
    lc3_init(&lc3);
    ldb db;
    ldb_init(&db, &lc3);
    if(ldb_loadObj(&db,"testcases/Project1.obj")!=OPEN)
        return -1;
    lc3.mem[0x30f0] = 25;
    lc3.mem[0x30f1] = 4;
    //ldb_setUnconBP(&db,0x3001);
    //ldb_setBP(&db, 0x3001, 1, bp_neq, bp_reg, 0, 0xbeef);
    ldb_run(&db);

    for(int i = 0; i < GPR_NUM; i++)
    {
        printf("R%d    : x%04x | %d\n",i,lc3.registers[i],(int16_t)lc3.registers[i]);
    }
    for(int i = 0; i < 8; i++)
    {
        printf("x%x : x%04x | %d\n",0x3000+i,lc3.mem[0x3000+i],(int16_t)lc3.mem[0x3000+i]);
    }
    printf("x%x : x%04x | %d\n",0x30f2,lc3.mem[0x30f2],(int16_t)lc3.mem[0x30f2]);
    printf("%llu cycles\n",(long long unsigned int)db.cycleCount);

    ldb_dump_lc3_r(&db,"dump/dump.lc3rdump");
    ldb_dump_lc3_t(&db,"dump/dump.lc3tdump");
    ldb_dump_lc3_b(&db,"dump/dump.lc3bdump");

    return 0;
}
示例#4
0
文件: prestat.c 项目: kingiol/cmoon
int main(int argc, char *argv[])
{
    NEOERR *err = STATUS_OK;
    HASH *dbh, *evth;

    mtc_init(TC_ROOT"prestat");

    err = lerr_init();
    DIE_NOK_MTL(err);

    err = mconfig_parse_file(SITE_CONFIG, &g_cfg);
    DIE_NOK_MTL(err);

    err = ldb_init(&dbh);
    DIE_NOK_MTL(err);

    err = levt_init(&evth);
    DIE_NOK_MTL(err);

    err = fill_trackarea(evth, dbh);
    TRACE_NOK(err);

    levt_destroy(evth);
    ldb_destroy(dbh);
    mconfig_cleanup(&g_cfg);
    return 0;
}
示例#5
0
文件: ltpl.c 项目: adderly/cmoon
NEOERR* ltpl_parse_dir(char *dir, HASH *outhash)
{
    struct dirent **eps = NULL;
    int n;
    NEOERR *err;

    if (!dir) return nerr_raise(NERR_ASSERT, "can't read null directory");

    HASH *dbh, *evth;
    void *lib = dlopen(NULL, RTLD_NOW|RTLD_GLOBAL);
    if (!lib) return nerr_raise(NERR_SYSTEM, "dlopen %s", dlerror());
    
    err = ldb_init(&dbh);
    if (err != STATUS_OK) return nerr_pass(err);

    err = levt_init(&evth);
    if (err != STATUS_OK) return nerr_pass(err);
    
    n = scandir(dir, &eps, ltpl_config, alphasort);
    for (int i = 0; i < n; i++) {
        mtc_dbg("parse file %s", eps[i]->d_name);
        err = ltpl_parse_file(dbh, evth, lib, dir, eps[i]->d_name, outhash);
        TRACE_NOK(err);
        free(eps[i]);
    }

    ldb_destroy(dbh);
    levt_destroy(evth);
    dlclose(lib);
    
    if (n > 0) free(eps);
    else mtc_warn("no .hdf file found in %s", dir);

    return STATUS_OK;
}
示例#6
0
文件: ldb_wrap.c 项目: ebrainte/Samba
 struct ldb_context *samba_ldb_init(TALLOC_CTX *mem_ctx,
				    struct tevent_context *ev,
				    struct loadparm_context *lp_ctx,
				    struct auth_session_info *session_info,
				    struct cli_credentials *credentials)
{
	struct ldb_context *ldb;
	int ret;

	ldb = ldb_init(mem_ctx, ev);
	if (ldb == NULL) {
		return NULL;
	}

	ldb_set_modules_dir(ldb, modules_path(ldb, "ldb"));

	ldb_set_debug(ldb, ldb_wrap_debug, NULL);

	ldb_set_utf8_fns(ldb, NULL, wrap_casefold);

	if (session_info) {
		if (ldb_set_opaque(ldb, "sessionInfo", session_info)) {
			talloc_free(ldb);
			return NULL;
		}
	}

	if (credentials) {
		if (ldb_set_opaque(ldb, "credentials", credentials)) {
			talloc_free(ldb);
			return NULL;
		}
	}

	if (ldb_set_opaque(ldb, "loadparm", lp_ctx)) {
		talloc_free(ldb);
		return NULL;
	}

	/* This must be done before we load the schema, as these
	 * handlers for objectSid and objectGUID etc must take
	 * precedence over the 'binary attribute' declaration in the
	 * schema */
	ret = ldb_register_samba_handlers(ldb);
	if (ret != LDB_SUCCESS) {
		talloc_free(ldb);
		return NULL;
	}

	/* we usually want Samba databases to be private. If we later
	   find we need one public, we will need to add a parameter to
	   ldb_wrap_connect() */
	ldb_set_create_perms(ldb, 0600);

	return ldb;
}
示例#7
0
文件: ldbadd.c 项目: amitay/samba
int main(int argc, const char **argv)
{
	struct ldb_context *ldb;
	unsigned int i, count = 0;
	int ret = LDB_SUCCESS;
	TALLOC_CTX *mem_ctx = talloc_new(NULL);

	ldb = ldb_init(mem_ctx, NULL);
	if (ldb == NULL) {
		return LDB_ERR_OPERATIONS_ERROR;
	}

	options = ldb_cmdline_process(ldb, argc, argv, usage);

	ret = ldb_transaction_start(ldb);
	if (ret != LDB_SUCCESS) {
		printf("Failed to start transaction: %s\n", ldb_errstring(ldb));
		return ret;
	}

	if (options->argc == 0) {
		ret = process_file(ldb, stdin, &count);
	} else {
		for (i=0;i<options->argc;i++) {
			const char *fname = options->argv[i];
			FILE *f;
			f = fopen(fname, "r");
			if (!f) {
				perror(fname);
				return LDB_ERR_OPERATIONS_ERROR;
			}
			ret = process_file(ldb, f, &count);
			fclose(f);
		}
	}

	if (count != 0) {
		ret = ldb_transaction_commit(ldb);
		if (ret != LDB_SUCCESS) {
			printf("Failed to commit transaction: %s\n", ldb_errstring(ldb));
			return ret;
		}
	} else {
		ldb_transaction_cancel(ldb);
	}

	talloc_free(mem_ctx);

	if (ret) {
		printf("Add failed after processing %u records\n", count);
	} else {
		printf("Added %u records successfully\n", count);
	}

	return ret;
}
示例#8
0
 int main(int argc, char *argv[])
{
	bool emergency = false;
	int c, rc;
	char *fname;
	struct ldb_dn *dn = NULL;

	ldb = ldb_init(NULL, NULL);
	if (ldb == NULL) {
		fprintf(stderr, "ldb: ldb_init failed()");
		exit(1);
	}

	rc = ldb_modules_hook(ldb, LDB_MODULE_HOOK_CMDLINE_PRECONNECT);
	if (rc != LDB_SUCCESS) {
		fprintf(stderr, "ldb: failed to run preconnect hooks (needed to get Samba LDIF handlers): %s\n", ldb_strerror(rc));
		exit(1);
	}

	if (argc < 2) {
		printf("Usage: ldbdump <fname>\n");
		exit(1);
	}

	while ((c = getopt( argc, argv, "hd:ec")) != -1) {
		switch (c) {
		case 'h':
			usage();
			exit( 0);
		case 'd':
			dn = ldb_dn_new(ldb, ldb, optarg);
			if (!dn) {
				fprintf(stderr, "ldb failed to parse %s as a DN\n", optarg);
				exit(1);
			}
			break;
		case 'e':
			emergency = true;
			break;
		case 'i':
			show_index = true;
			break;
		case 'c':
			validate_contents = true;
			break;
		default:
			usage();
			exit( 1);
		}
	}

	fname = argv[optind];

	return dump_tdb(fname, dn, emergency);
}
/*
 * Test set up
 */
static int setup(void **state)
{
	struct ldbtest_ctx *test_ctx	= NULL;
	struct ldb_module *eol		= NULL;
	int rc;

	test_ctx = talloc_zero(NULL, struct ldbtest_ctx);
	assert_non_null(test_ctx);

	test_ctx->ev = tevent_context_init(test_ctx);
	assert_non_null(test_ctx->ev);

	test_ctx->ldb = ldb_init(test_ctx, test_ctx->ev);
	assert_non_null(test_ctx->ldb);

	test_ctx->domain_sid = talloc_zero(test_ctx, struct dom_sid);
	assert_non_null(test_ctx->domain_sid);
	assert_true(string_to_sid(test_ctx->domain_sid, DOMAIN_SID));
	ldb_set_opaque(test_ctx->ldb, "cache.domain_sid", test_ctx->domain_sid);

        test_ctx->module = ldb_module_new(
		test_ctx,
		test_ctx->ldb,
		"unique_object_sids",
		&ldb_unique_object_sids_module_ops);
	assert_non_null(test_ctx->module);
	eol = ldb_module_new(test_ctx, test_ctx->ldb, "eol", &eol_ops);
	assert_non_null(eol);
	ldb_module_set_next(test_ctx->module, eol);

	test_ctx->dbfile = talloc_strdup(test_ctx, "duptest.ldb");
	assert_non_null(test_ctx->dbfile);

	test_ctx->lockfile = talloc_asprintf(test_ctx, "%s-lock",
					     test_ctx->dbfile);
	assert_non_null(test_ctx->lockfile);

	test_ctx->dbpath = talloc_asprintf(test_ctx,
			TEST_BE"://%s", test_ctx->dbfile);
	assert_non_null(test_ctx->dbpath);

	unlink_old_db(test_ctx);

	rc = ldb_connect(test_ctx->ldb, test_ctx->dbpath, 0, NULL);
	assert_int_equal(rc, LDB_SUCCESS);

	rc = unique_object_sids_init(test_ctx->module);
	assert_int_equal(rc, LDB_SUCCESS);

	*state = test_ctx;

	last_request = NULL;
	return 0;
}
示例#10
0
void db_run_destruction(MYSQL_RES *dstrres)
{
	char delquery[QUERYLEN];
	MYSQL_ROW data;
	unsigned long uid;
	char *estr;

	if (!dstrres)
	{
		return;
	}
	if (mysql_num_rows(dstrres) < 1)
	{
		mysql_free_result(dstrres);
		return;
	}

	if (!ldb_init())
	{
		if (LocalDB)
		{
			if (rundaemon) { syslog(LOG_WARNING, "LocalDB connection failed: %s", mysql_error(LocalDB)); }
			else if (dlvl(1)) { fprintf(stdout, "LocalDB connection failed: %s\n", mysql_error(LocalDB)); }
			ldb_deinit();
		}
		else
		{
			if (rundaemon) { syslog(LOG_WARNING, "LocalDB connection failed: unknown"); }
			else if (dlvl(1)) { fprintf(stdout, "LocalDB connection failed: unknown\n"); }
		}
		mysql_free_result(dstrres);
		return;
	}
	while (data = mysql_fetch_row(dstrres))
	{
		uid = stringtoulong(data[1]);
		if (db_destroy(data[0], data[2]) == 0)
		{
			estr = (char *)malloc((strlen(data[0]) * 2) + 1);
			memset(estr, 0, ((strlen(data[0]) * 2) + 1));
			mysql_real_escape_string(DBhandle, estr, data[0], strlen(data[0]));
			memset(delquery, 0, QUERYLEN);
			snprintf(delquery, QUERYLEN, "delete from sql_destroy where uid=%lu and name=\"%s\"", uid, estr);
			free(estr);
			if (dlvl(5) && !rundaemon) { fprintf(stdout, "QUERY: %s\n", delquery); }
			mysql_query(DBhandle, delquery);
		}
	}
	mysql_free_result(dstrres);
	ldb_deinit();
}
示例#11
0
} END_TEST

// ^ Unit test ----------------------------------------------------------------

// v Suite definition ---------------------------------------------------------

static void create_ldb_from_ldif(const char *ldb_path, const char *ldif_path,
				 const char *default_context, const char *root_context)
{
	FILE *f;
	struct ldb_ldif *ldif;
	struct ldb_context *ldb_ctx = NULL;
	TALLOC_CTX *local_mem_ctx = talloc_new(NULL);
	struct ldb_message *msg;

	ldb_ctx = ldb_init(local_mem_ctx, NULL);
	ldb_connect(ldb_ctx, ldb_path, 0, 0);
	f = fopen(ldif_path, "r");

	msg = ldb_msg_new(local_mem_ctx);
	msg->dn = ldb_dn_new(msg, ldb_ctx, "@INDEXLIST");
	ldb_msg_add_string(msg, "@IDXATTR", "cn");
	ldb_msg_add_string(msg, "@IDXATTR", "oleguid");
	ldb_msg_add_string(msg, "@IDXATTR", "mappedId");
	msg->elements[0].flags = LDB_FLAG_MOD_ADD;
	ldb_add(ldb_ctx, msg);

	while ((ldif = ldb_ldif_read_file(ldb_ctx, f))) {
		struct ldb_message *normalized_msg;
		ldb_msg_normalize(ldb_ctx, local_mem_ctx, ldif->msg,
				  &normalized_msg);
		ldb_add(ldb_ctx, normalized_msg);
		talloc_free(normalized_msg);
		ldb_ldif_read_free(ldb_ctx, ldif);
	}

	if (default_context && root_context) {
		msg = ldb_msg_new(local_mem_ctx);
		msg->dn = ldb_dn_new(msg, ldb_ctx, "@ROOTDSE");
		ldb_msg_add_string(msg, "defaultNamingContext", default_context);
		ldb_msg_add_string(msg, "rootDomainNamingContext", root_context);
		msg->elements[0].flags = LDB_FLAG_MOD_REPLACE;
		ldb_add(ldb_ctx, msg);
	}

	fclose(f);
	talloc_free(local_mem_ctx);
}
示例#12
0
/*
  return the default DN for a ldap server given a connected RPC pipe to the
  server
 */
static const char *torture_get_ldap_base_dn(struct torture_context *tctx, struct dcerpc_pipe *p)
{
	const char *hostname = p->binding->host;
	struct ldb_context *ldb;
	const char *ldap_url = talloc_asprintf(p, "ldap://%s", hostname);
	const char *attrs[] = { "defaultNamingContext", NULL };
	const char *dnstr;
	TALLOC_CTX *tmp_ctx = talloc_new(tctx);
	int ret;
	struct ldb_result *res;

	ldb = ldb_init(tmp_ctx, tctx->ev);
	if (ldb == NULL) {
		talloc_free(tmp_ctx);
		return NULL;
	}

	if (ldb_set_opaque(ldb, "loadparm", tctx->lp_ctx)) {
		talloc_free(ldb);
		return NULL;
	}

	ldb_set_modules_dir(ldb,
			    modules_path(ldb, "ldb"));

	ret = ldb_connect(ldb, ldap_url, 0, NULL);
	if (ret != LDB_SUCCESS) {
		torture_comment(tctx, "Failed to make LDB connection to target");
		talloc_free(tmp_ctx);
		return NULL;
	}

	ret = dsdb_search_dn(ldb, tmp_ctx, &res, ldb_dn_new(tmp_ctx, ldb, ""),
			     attrs, 0);
	if (ret != LDB_SUCCESS) {
		torture_comment(tctx, "Failed to get defaultNamingContext");
		talloc_free(tmp_ctx);
		return NULL;
	}

	dnstr = ldb_msg_find_attr_as_string(res->msgs[0], "defaultNamingContext", NULL);
	dnstr = talloc_strdup(tctx, dnstr);
	talloc_free(tmp_ctx);
	return dnstr;
}
示例#13
0
/*
  dump a set of cldap results
*/
static void cldap_dump_results(struct cldap_search *search)
{
	struct ldb_ldif ldif;
	struct ldb_context *ldb;

	if (!search || !(search->out.response)) {
		return;
	}

	/* we need a ldb context to use ldb_ldif_write_file() */
	ldb = ldb_init(NULL);

	ZERO_STRUCT(ldif);
	ldif.msg = ldap_msg_to_ldb(ldb, ldb, search->out.response);

	ldb_ldif_write_file(ldb, stdout, &ldif);

	talloc_free(ldb);
}
示例#14
0
文件: ldbdel.c 项目: gojdic/samba
int main(int argc, const char **argv)
{
	struct ldb_context *ldb;
	int ret = 0, i;
	struct ldb_cmdline *options;

	ldb = ldb_init(NULL, NULL);

	options = ldb_cmdline_process(ldb, argc, argv, usage);

	if (options->argc < 1) {
		usage();
		exit(1);
	}

	for (i=0;i<options->argc;i++) {
		struct ldb_dn *dn;

		dn = ldb_dn_new(ldb, ldb, options->argv[i]);
		if ( ! ldb_dn_validate(dn)) {
			printf("Invalid DN format\n");
			exit(1);
		}
		if (options->recursive) {
			ret = ldb_delete_recursive(ldb, dn);
		} else {
			ret = ldb_delete(ldb, dn);
			if (ret == 0) {
				printf("Deleted 1 record\n");
			}
		}
		if (ret != 0) {
			printf("delete of '%s' failed - %s\n",
				ldb_dn_get_linearized(dn),
				ldb_errstring(ldb));
		}
	}

	talloc_free(ldb);

	return ret;
}
示例#15
0
int dumpTest()
{
    lc3 lc3;
    lc3_init(&lc3);
    ldb db;
    ldb_init(&db, &lc3);
    if(ldb_dumpload_lc3_b(&db,"dump/dump.lc3bdump")!=OPEN)
        return -1;

    for(int i = 0; i < GPR_NUM; i++)
    {
        printf("R%d    : x%04x | %d\n",i,lc3.registers[i],(int16_t)lc3.registers[i]);
    }
    for(int i = 0; i < 8; i++)
    {
        printf("x%x : x%04x | %d\n",0x3000+i,lc3.mem[0x3000+i],(int16_t)lc3.mem[0x3000+i]);
    }
    printf("x%x : x%04x | %d\n",0x30f2,lc3.mem[0x30f2],(int16_t)lc3.mem[0x30f2]);
    printf("%llu cycles\n",(long long unsigned int)db.cycleCount);
    return 0;
}
示例#16
0
int main(int argc, const char **argv)
{
	struct ldb_context *ldb;
	int ret;
	struct ldb_cmdline *options;
	struct ldb_dn *dn1, *dn2;
	TALLOC_CTX *mem_ctx = talloc_new(NULL);

	ldb = ldb_init(mem_ctx, NULL);
	if (ldb == NULL) {
		return LDB_ERR_OPERATIONS_ERROR;
	}

	options = ldb_cmdline_process(ldb, argc, argv, usage);

	if (options->argc < 2) {
		usage(ldb);
	}

	dn1 = ldb_dn_new(ldb, ldb, options->argv[0]);
	dn2 = ldb_dn_new(ldb, ldb, options->argv[1]);
	if ((dn1 == NULL) || (dn2 == NULL)) {
		return LDB_ERR_OPERATIONS_ERROR;
	}

	ret = ldb_rename(ldb, dn1, dn2);
	if (ret == LDB_SUCCESS) {
		printf("Renamed 1 record\n");
	} else  {
		printf("rename of '%s' to '%s' failed - %s\n", 
			options->argv[0], options->argv[1], ldb_errstring(ldb));
	}

	talloc_free(mem_ctx);
	
	return ret;
}
示例#17
0
void p2p_cron_lookup(UCHAR * target, int type)
{
	UCHAR nodes_compact_list[IP_SIZE_META_TRIPLE8];
	int nodes_compact_size = 0;
	LOOKUP *l = NULL;
	UCHAR *p = NULL;
	UCHAR *id = NULL;
	ITEM *ti = NULL;
	int j = 0;
	IP sin;

	/* Start the incremental remote search program */
	nodes_compact_size = bckt_compact_list(_main->nbhd->bucket,
					       nodes_compact_list, target);

	/* Create tid and get the lookup table */
	ti = tdb_put(type);
	l = ldb_init(target, NULL, NULL);
	tdb_link_ldb(ti, l);

	p = nodes_compact_list;
	for (j = 0; j < nodes_compact_size; j += IP_SIZE_META_TRIPLE) {

		/* ID */
		id = p;
		p += SHA1_SIZE;

		/* IP + Port */
		p = ip_tuple_to_sin(&sin, p);

		/* Remember queried node */
		ldb_put(l, id, &sin);

		/* Query node */
		send_get_peers_request(&sin, target, tdb_tid(ti));
	}
}
示例#18
0
文件: sysdb.c 项目: stefwalter/sssd
errno_t sysdb_ldb_connect(TALLOC_CTX *mem_ctx, const char *filename,
                          struct ldb_context **_ldb)
{
    int ret;
    struct ldb_context *ldb;
    const char *mod_path;

    if (_ldb == NULL) {
        return EINVAL;
    }

    ldb = ldb_init(mem_ctx, NULL);
    if (!ldb) {
        return EIO;
    }

    ret = ldb_set_debug(ldb, ldb_debug_messages, NULL);
    if (ret != LDB_SUCCESS) {
        return EIO;
    }

    mod_path = getenv(LDB_MODULES_PATH);
    if (mod_path != NULL) {
        DEBUG(SSSDBG_TRACE_ALL, "Setting ldb module path to [%s].\n", mod_path);
        ldb_set_modules_dir(ldb, mod_path);
    }

    ret = ldb_connect(ldb, filename, 0, NULL);
    if (ret != LDB_SUCCESS) {
        return EIO;
    }

    *_ldb = ldb;

    return EOK;
}
示例#19
0
int debuggerTest()
{
    lc3 lc3;
    lc3_init(&lc3);
    ldb db;
    ldb_init(&db, &lc3);
    if(ldb_loadObj(&db,"testcases/lsi.obj") != OPEN)
        return -1;
    //ldb_setUnconBP(&db,0x3001);
    ldb_setBP(&db, 0x3001, 1, ldb_neq, ldb_reg, 0, 0xbeef);
    ldb_run(&db);

    for(int i = 0; i < GPR_NUM; i++)
    {
        printf("R%d    : x%04x | %d\n",i,lc3.registers[i],(int16_t)lc3.registers[i]);
    }
    for(int i = 0; i < 8; i++)
    {
        printf("x%x : x%04x | %d\n",0x3000+i,lc3.mem[0x3000+i],(int16_t)lc3.mem[0x3000+i]);
    }
    printf("%llu cycles\n",(long long unsigned int) db.cycleCount);

    return 0;
}
示例#20
0
文件: ldb.c 项目: gojdic/samba
static bool torture_ldb_dn_invalid_extended(struct torture_context *torture)
{
    TALLOC_CTX *mem_ctx = talloc_new(torture);
    struct ldb_context *ldb;
    struct ldb_dn *dn;

    const char *dn_str = "cn=admin,cn=users,dc=samba,dc=org";

    torture_assert(torture,
                   ldb = ldb_init(mem_ctx, torture->ev),
                   "Failed to init ldb");

    torture_assert_int_equal(torture,
                             ldb_register_samba_handlers(ldb), 0,
                             "Failed to register Samba handlers");

    ldb_set_utf8_fns(ldb, NULL, wrap_casefold);

    /* Check behaviour of a normal DN */
    torture_assert(torture,
                   dn = ldb_dn_new(mem_ctx, ldb, "samba,dc=org"),
                   "Failed to create a 'normal' invalid DN");

    torture_assert(torture,
                   ldb_dn_validate(dn) == false,
                   "should have failed to validate 'normal' invalid DN");

    /* Now make an extended DN */
    torture_assert(torture,
                   dn = ldb_dn_new_fmt(mem_ctx, ldb, "<PID=%s>;%s",
                                       sid, dn_str),
                   "Failed to create an invalid 'extended' DN");

    torture_assert(torture,
                   ldb_dn_validate(dn) == false,
                   "should have failed to validate 'extended' DN");

    torture_assert(torture,
                   dn = ldb_dn_new_fmt(mem_ctx, ldb, "<GUID=%s>%s",
                                       sid, dn_str),
                   "Failed to create an invalid 'extended' DN");

    torture_assert(torture,
                   ldb_dn_validate(dn) == false,
                   "should have failed to validate 'extended' DN");

    torture_assert(torture,
                   dn = ldb_dn_new_fmt(mem_ctx, ldb, "<GUID=%s>;",
                                       sid),
                   "Failed to create an invalid 'extended' DN");

    torture_assert(torture,
                   ldb_dn_validate(dn) == false,
                   "should have failed to validate 'extended' DN");

    torture_assert(torture,
                   dn = ldb_dn_new_fmt(mem_ctx, ldb, "<GUID=%s>;",
                                       hex_sid),
                   "Failed to create an invalid 'extended' DN");

    torture_assert(torture,
                   ldb_dn_validate(dn) == false,
                   "should have failed to validate 'extended' DN");

    torture_assert(torture,
                   dn = ldb_dn_new_fmt(mem_ctx, ldb, "<SID=%s>;",
                                       hex_guid),
                   "Failed to create an invalid 'extended' DN");

    torture_assert(torture,
                   ldb_dn_validate(dn) == false,
                   "should have failed to validate 'extended' DN");

    torture_assert(torture,
                   dn = ldb_dn_new_fmt(mem_ctx, ldb, "<SID=%s>;",
                                       guid),
                   "Failed to create an invalid 'extended' DN");

    torture_assert(torture,
                   ldb_dn_validate(dn) == false,
                   "should have failed to validate 'extended' DN");

    torture_assert(torture,
                   dn = ldb_dn_new_fmt(mem_ctx, ldb, "<GUID=>"),
                   "Failed to create an invalid 'extended' DN");

    torture_assert(torture,
                   ldb_dn_validate(dn) == false,
                   "should have failed to validate 'extended' DN");

    return true;
}
示例#21
0
文件: ldb.c 项目: gojdic/samba
static bool torture_ldb_dn(struct torture_context *torture)
{
    TALLOC_CTX *mem_ctx = talloc_new(torture);
    struct ldb_context *ldb;
    struct ldb_dn *dn;
    struct ldb_dn *child_dn;
    struct ldb_dn *typo_dn;

    torture_assert(torture,
                   ldb = ldb_init(mem_ctx, torture->ev),
                   "Failed to init ldb");

    torture_assert_int_equal(torture,
                             ldb_register_samba_handlers(ldb), 0,
                             "Failed to register Samba handlers");

    ldb_set_utf8_fns(ldb, NULL, wrap_casefold);

    /* Check behaviour of a normal DN */
    torture_assert(torture,
                   dn = ldb_dn_new(mem_ctx, ldb, NULL),
                   "Failed to create a NULL DN");

    torture_assert(torture,
                   ldb_dn_validate(dn),
                   "Failed to validate NULL DN");

    torture_assert(torture,
                   ldb_dn_add_base_fmt(dn, "dc=org"),
                   "Failed to add base DN");

    torture_assert(torture,
                   ldb_dn_add_child_fmt(dn, "dc=samba"),
                   "Failed to add base DN");

    torture_assert_str_equal(torture, ldb_dn_get_linearized(dn), "dc=samba,dc=org",
                             "linearized DN incorrect");

    torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 0), "dc=samba,dc=org",
                             "extended linearized DN incorrect");

    /* Check child DN comparisons */
    torture_assert(torture,
                   child_dn = ldb_dn_new(mem_ctx, ldb, "CN=users,DC=SAMBA,DC=org"),
                   "Failed to create child DN");

    torture_assert(torture,
                   ldb_dn_compare(dn, child_dn) != 0,
                   "Comparison on dc=samba,dc=org and CN=users,DC=SAMBA,DC=org should != 0");

    torture_assert(torture,
                   ldb_dn_compare_base(child_dn, dn) != 0,
                   "Base Comparison of CN=users,DC=SAMBA,DC=org and dc=samba,dc=org should != 0");

    torture_assert(torture,
                   ldb_dn_compare_base(dn, child_dn) == 0,
                   "Base Comparison on dc=samba,dc=org and CN=users,DC=SAMBA,DC=org should == 0");

    /* Check comparisons with a truncated DN */
    torture_assert(torture,
                   typo_dn = ldb_dn_new(mem_ctx, ldb, "c=samba,dc=org"),
                   "Failed to create 'typo' DN");

    torture_assert(torture,
                   ldb_dn_compare(dn, typo_dn) != 0,
                   "Comparison on dc=samba,dc=org and c=samba,dc=org should != 0");

    torture_assert(torture,
                   ldb_dn_compare_base(typo_dn, dn) != 0,
                   "Base Comparison of c=samba,dc=org and dc=samba,dc=org should != 0");

    torture_assert(torture,
                   ldb_dn_compare_base(dn, typo_dn) != 0,
                   "Base Comparison on dc=samba,dc=org and c=samba,dc=org should != 0");

    talloc_free(mem_ctx);
    return true;
}
示例#22
0
文件: ldb.c 项目: gojdic/samba
static bool torture_ldb_attrs(struct torture_context *torture)
{
    TALLOC_CTX *mem_ctx = talloc_new(torture);
    struct ldb_context *ldb;
    const struct ldb_schema_attribute *attr;
    struct ldb_val string_sid_blob, binary_sid_blob;
    struct ldb_val string_guid_blob, string_guid_blob2, binary_guid_blob;

    DATA_BLOB sid_blob = strhex_to_data_blob(mem_ctx, hex_sid);
    DATA_BLOB guid_blob = strhex_to_data_blob(mem_ctx, hex_guid);

    torture_assert(torture,
                   ldb = ldb_init(mem_ctx, torture->ev),
                   "Failed to init ldb");

    torture_assert_int_equal(torture,
                             ldb_register_samba_handlers(ldb), 0,
                             "Failed to register Samba handlers");

    ldb_set_utf8_fns(ldb, NULL, wrap_casefold);

    /* Test SID behaviour */
    torture_assert(torture, attr = ldb_schema_attribute_by_name(ldb, "objectSid"),
                   "Failed to get objectSid schema attribute");

    string_sid_blob = data_blob_string_const(sid);

    torture_assert_int_equal(torture,
                             attr->syntax->ldif_read_fn(ldb, mem_ctx,
                                     &string_sid_blob, &binary_sid_blob), 0,
                             "Failed to parse string SID");

    torture_assert_data_blob_equal(torture, binary_sid_blob, sid_blob,
                                   "Read SID into blob form failed");

    torture_assert_int_equal(torture,
                             attr->syntax->ldif_read_fn(ldb, mem_ctx,
                                     &sid_blob, &binary_sid_blob), -1,
                             "Should have failed to parse binary SID");

    torture_assert_int_equal(torture,
                             attr->syntax->ldif_write_fn(ldb, mem_ctx, &binary_sid_blob, &string_sid_blob), 0,
                             "Failed to parse binary SID");

    torture_assert_data_blob_equal(torture,
                                   string_sid_blob, data_blob_string_const(sid),
                                   "Write SID into string form failed");

    torture_assert_int_equal(torture,
                             attr->syntax->comparison_fn(ldb, mem_ctx, &binary_sid_blob, &string_sid_blob), 0,
                             "Failed to compare binary and string SID");

    torture_assert_int_equal(torture,
                             attr->syntax->comparison_fn(ldb, mem_ctx, &string_sid_blob, &binary_sid_blob), 0,
                             "Failed to compare string and binary binary SID");

    torture_assert_int_equal(torture,
                             attr->syntax->comparison_fn(ldb, mem_ctx, &string_sid_blob, &string_sid_blob), 0,
                             "Failed to compare string and string SID");

    torture_assert_int_equal(torture,
                             attr->syntax->comparison_fn(ldb, mem_ctx, &binary_sid_blob, &binary_sid_blob), 0,
                             "Failed to compare binary and binary SID");

    torture_assert(torture, attr->syntax->comparison_fn(ldb, mem_ctx, &guid_blob, &binary_sid_blob) != 0,
                   "Failed to distinguish binary GUID and binary SID");


    /* Test GUID behaviour */
    torture_assert(torture, attr = ldb_schema_attribute_by_name(ldb, "objectGUID"),
                   "Failed to get objectGUID schema attribute");

    string_guid_blob = data_blob_string_const(guid);

    torture_assert_int_equal(torture,
                             attr->syntax->ldif_read_fn(ldb, mem_ctx,
                                     &string_guid_blob, &binary_guid_blob), 0,
                             "Failed to parse string GUID");

    torture_assert_data_blob_equal(torture, binary_guid_blob, guid_blob,
                                   "Read GUID into blob form failed");

    string_guid_blob2 = data_blob_string_const(guid2);

    torture_assert_int_equal(torture,
                             attr->syntax->ldif_read_fn(ldb, mem_ctx,
                                     &string_guid_blob2, &binary_guid_blob), 0,
                             "Failed to parse string GUID");

    torture_assert_data_blob_equal(torture, binary_guid_blob, guid_blob,
                                   "Read GUID into blob form failed");

    torture_assert_int_equal(torture,
                             attr->syntax->ldif_read_fn(ldb, mem_ctx,
                                     &guid_blob, &binary_guid_blob), 0,
                             "Failed to parse binary GUID");

    torture_assert_data_blob_equal(torture, binary_guid_blob, guid_blob,
                                   "Read GUID into blob form failed");

    torture_assert_int_equal(torture,
                             attr->syntax->ldif_write_fn(ldb, mem_ctx, &binary_guid_blob, &string_guid_blob), 0,
                             "Failed to print binary GUID as string");

    torture_assert_data_blob_equal(torture, string_sid_blob, data_blob_string_const(sid),
                                   "Write SID into string form failed");

    torture_assert_int_equal(torture,
                             attr->syntax->comparison_fn(ldb, mem_ctx, &binary_guid_blob, &string_guid_blob), 0,
                             "Failed to compare binary and string GUID");

    torture_assert_int_equal(torture,
                             attr->syntax->comparison_fn(ldb, mem_ctx, &string_guid_blob, &binary_guid_blob), 0,
                             "Failed to compare string and binary binary GUID");

    torture_assert_int_equal(torture,
                             attr->syntax->comparison_fn(ldb, mem_ctx, &string_guid_blob, &string_guid_blob), 0,
                             "Failed to compare string and string GUID");

    torture_assert_int_equal(torture,
                             attr->syntax->comparison_fn(ldb, mem_ctx, &binary_guid_blob, &binary_guid_blob), 0,
                             "Failed to compare binary and binary GUID");



    talloc_free(mem_ctx);
    return true;
}
示例#23
0
文件: ldb.c 项目: gojdic/samba
static bool torture_ldb_dn_extended(struct torture_context *torture)
{
    TALLOC_CTX *mem_ctx = talloc_new(torture);
    struct ldb_context *ldb;
    struct ldb_dn *dn, *dn2;

    DATA_BLOB sid_blob = strhex_to_data_blob(mem_ctx, hex_sid);
    DATA_BLOB guid_blob = strhex_to_data_blob(mem_ctx, hex_guid);

    const char *dn_str = "cn=admin,cn=users,dc=samba,dc=org";

    torture_assert(torture,
                   ldb = ldb_init(mem_ctx, torture->ev),
                   "Failed to init ldb");

    torture_assert_int_equal(torture,
                             ldb_register_samba_handlers(ldb), 0,
                             "Failed to register Samba handlers");

    ldb_set_utf8_fns(ldb, NULL, wrap_casefold);

    /* Check behaviour of a normal DN */
    torture_assert(torture,
                   dn = ldb_dn_new(mem_ctx, ldb, dn_str),
                   "Failed to create a 'normal' DN");

    torture_assert(torture,
                   ldb_dn_validate(dn),
                   "Failed to validate 'normal' DN");

    torture_assert(torture, ldb_dn_has_extended(dn) == false,
                   "Should not find plain DN to be 'extended'");

    torture_assert(torture, ldb_dn_get_extended_component(dn, "SID") == NULL,
                   "Should not find an SID on plain DN");

    torture_assert(torture, ldb_dn_get_extended_component(dn, "GUID") == NULL,
                   "Should not find an GUID on plain DN");

    torture_assert(torture, ldb_dn_get_extended_component(dn, "WKGUID") == NULL,
                   "Should not find an WKGUID on plain DN");

    /* Now make an extended DN */
    torture_assert(torture,
                   dn = ldb_dn_new_fmt(mem_ctx, ldb, "<GUID=%s>;<SID=%s>;%s",
                                       guid, sid, dn_str),
                   "Failed to create an 'extended' DN");

    torture_assert(torture,
                   dn2 = ldb_dn_copy(mem_ctx, dn),
                   "Failed to copy the 'extended' DN");
    talloc_free(dn);
    dn = dn2;

    torture_assert(torture,
                   ldb_dn_validate(dn),
                   "Failed to validate 'extended' DN");

    torture_assert(torture, ldb_dn_has_extended(dn) == true,
                   "Should find extended DN to be 'extended'");

    torture_assert(torture, ldb_dn_get_extended_component(dn, "SID") != NULL,
                   "Should find an SID on extended DN");

    torture_assert(torture, ldb_dn_get_extended_component(dn, "GUID") != NULL,
                   "Should find an GUID on extended DN");

    torture_assert_data_blob_equal(torture, *ldb_dn_get_extended_component(dn, "SID"), sid_blob,
                                   "Extended DN SID incorect");

    torture_assert_data_blob_equal(torture, *ldb_dn_get_extended_component(dn, "GUID"), guid_blob,
                                   "Extended DN GUID incorect");

    torture_assert_str_equal(torture, ldb_dn_get_linearized(dn), dn_str,
                             "linearized DN incorrect");

    torture_assert_str_equal(torture, ldb_dn_get_casefold(dn), strupper_talloc(mem_ctx, dn_str),
                             "casefolded DN incorrect");

    torture_assert_str_equal(torture, ldb_dn_get_component_name(dn, 0), "cn",
                             "componet zero incorrect");

    torture_assert_data_blob_equal(torture, *ldb_dn_get_component_val(dn, 0), data_blob_string_const("admin"),
                                   "componet zero incorrect");

    torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 1),
                             talloc_asprintf(mem_ctx, "<GUID=%s>;<SID=%s>;%s",
                                     guid, sid, dn_str),
                             "Clear extended linearized DN incorrect");

    torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 0),
                             talloc_asprintf(mem_ctx, "<GUID=%s>;<SID=%s>;%s",
                                     hex_guid, hex_sid, dn_str),
                             "HEX extended linearized DN incorrect");

    torture_assert(torture, ldb_dn_remove_child_components(dn, 1) == true,
                   "Failed to remove DN child");

    torture_assert(torture, ldb_dn_has_extended(dn) == false,
                   "Extended DN flag should be cleared after child element removal");

    torture_assert(torture, ldb_dn_get_extended_component(dn, "SID") == NULL,
                   "Should not find an SID on DN");

    torture_assert(torture, ldb_dn_get_extended_component(dn, "GUID") == NULL,
                   "Should not find an GUID on DN");


    /* TODO:  test setting these in the other order, and ensure it still comes out 'GUID first' */
    torture_assert_int_equal(torture, ldb_dn_set_extended_component(dn, "GUID", &guid_blob), 0,
                             "Failed to set a GUID on DN");

    torture_assert_int_equal(torture, ldb_dn_set_extended_component(dn, "SID", &sid_blob), 0,
                             "Failed to set a SID on DN");

    torture_assert_data_blob_equal(torture, *ldb_dn_get_extended_component(dn, "SID"), sid_blob,
                                   "Extended DN SID incorect");

    torture_assert_data_blob_equal(torture, *ldb_dn_get_extended_component(dn, "GUID"), guid_blob,
                                   "Extended DN GUID incorect");

    torture_assert_str_equal(torture, ldb_dn_get_linearized(dn), "cn=users,dc=samba,dc=org",
                             "linearized DN incorrect");

    torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 1),
                             talloc_asprintf(mem_ctx, "<GUID=%s>;<SID=%s>;%s",
                                     guid, sid, "cn=users,dc=samba,dc=org"),
                             "Clear extended linearized DN incorrect");

    torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 0),
                             talloc_asprintf(mem_ctx, "<GUID=%s>;<SID=%s>;%s",
                                     hex_guid, hex_sid, "cn=users,dc=samba,dc=org"),
                             "HEX extended linearized DN incorrect");

    /* Now check a 'just GUID' DN (clear format) */
    torture_assert(torture,
                   dn = ldb_dn_new_fmt(mem_ctx, ldb, "<GUID=%s>",
                                       guid),
                   "Failed to create an 'extended' DN");

    torture_assert(torture,
                   ldb_dn_validate(dn),
                   "Failed to validate 'extended' DN");

    torture_assert(torture, ldb_dn_has_extended(dn) == true,
                   "Should find extended DN to be 'extended'");

    torture_assert(torture, ldb_dn_get_extended_component(dn, "SID") == NULL,
                   "Should not find an SID on this DN");

    torture_assert_int_equal(torture, ldb_dn_get_comp_num(dn), 0,
                             "Should not find an 'normal' componet on this DN");

    torture_assert(torture, ldb_dn_get_extended_component(dn, "GUID") != NULL,
                   "Should find an GUID on this DN");

    torture_assert_data_blob_equal(torture, *ldb_dn_get_extended_component(dn, "GUID"), guid_blob,
                                   "Extended DN GUID incorect");

    torture_assert_str_equal(torture, ldb_dn_get_linearized(dn), "",
                             "linearized DN incorrect");

    torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 1),
                             talloc_asprintf(mem_ctx, "<GUID=%s>",
                                     guid),
                             "Clear extended linearized DN incorrect");

    torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 0),
                             talloc_asprintf(mem_ctx, "<GUID=%s>",
                                     hex_guid),
                             "HEX extended linearized DN incorrect");

    /* Now check a 'just GUID' DN (HEX format) */
    torture_assert(torture,
                   dn = ldb_dn_new_fmt(mem_ctx, ldb, "<GUID=%s>",
                                       hex_guid),
                   "Failed to create an 'extended' DN");

    torture_assert(torture,
                   ldb_dn_validate(dn),
                   "Failed to validate 'extended' DN");

    torture_assert(torture, ldb_dn_has_extended(dn) == true,
                   "Should find extended DN to be 'extended'");

    torture_assert(torture, ldb_dn_get_extended_component(dn, "SID") == NULL,
                   "Should not find an SID on this DN");

    torture_assert(torture, ldb_dn_get_extended_component(dn, "GUID") != NULL,
                   "Should find an GUID on this DN");

    torture_assert_data_blob_equal(torture, *ldb_dn_get_extended_component(dn, "GUID"), guid_blob,
                                   "Extended DN GUID incorect");

    torture_assert_str_equal(torture, ldb_dn_get_linearized(dn), "",
                             "linearized DN incorrect");

    /* Now check a 'just SID' DN (clear format) */
    torture_assert(torture,
                   dn = ldb_dn_new_fmt(mem_ctx, ldb, "<SID=%s>",
                                       sid),
                   "Failed to create an 'extended' DN");

    torture_assert(torture,
                   ldb_dn_validate(dn),
                   "Failed to validate 'extended' DN");

    torture_assert(torture, ldb_dn_has_extended(dn) == true,
                   "Should find extended DN to be 'extended'");

    torture_assert(torture, ldb_dn_get_extended_component(dn, "GUID") == NULL,
                   "Should not find an SID on this DN");

    torture_assert(torture, ldb_dn_get_extended_component(dn, "SID") != NULL,
                   "Should find an SID on this DN");

    torture_assert_data_blob_equal(torture, *ldb_dn_get_extended_component(dn, "SID"), sid_blob,
                                   "Extended DN SID incorect");

    torture_assert_str_equal(torture, ldb_dn_get_linearized(dn), "",
                             "linearized DN incorrect");

    torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 1),
                             talloc_asprintf(mem_ctx, "<SID=%s>",
                                     sid),
                             "Clear extended linearized DN incorrect");

    torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 0),
                             talloc_asprintf(mem_ctx, "<SID=%s>",
                                     hex_sid),
                             "HEX extended linearized DN incorrect");

    /* Now check a 'just SID' DN (HEX format) */
    torture_assert(torture,
                   dn = ldb_dn_new_fmt(mem_ctx, ldb, "<SID=%s>",
                                       hex_sid),
                   "Failed to create an 'extended' DN");

    torture_assert(torture,
                   ldb_dn_validate(dn),
                   "Failed to validate 'extended' DN");

    torture_assert(torture, ldb_dn_has_extended(dn) == true,
                   "Should find extended DN to be 'extended'");

    torture_assert(torture, ldb_dn_get_extended_component(dn, "GUID") == NULL,
                   "Should not find an SID on this DN");

    torture_assert(torture, ldb_dn_get_extended_component(dn, "SID") != NULL,
                   "Should find an SID on this DN");

    torture_assert_data_blob_equal(torture, *ldb_dn_get_extended_component(dn, "SID"), sid_blob,
                                   "Extended DN SID incorect");

    torture_assert_str_equal(torture, ldb_dn_get_linearized(dn), "",
                             "linearized DN incorrect");

    talloc_free(mem_ctx);
    return true;
}
示例#24
0
文件: ldb.c 项目: gojdic/samba
static bool torture_ldb_dn_attrs(struct torture_context *torture)
{
    TALLOC_CTX *mem_ctx = talloc_new(torture);
    struct ldb_context *ldb;
    const struct ldb_dn_extended_syntax *attr;
    struct ldb_val string_sid_blob, binary_sid_blob;
    struct ldb_val string_guid_blob, binary_guid_blob;
    struct ldb_val hex_sid_blob, hex_guid_blob;

    DATA_BLOB sid_blob = strhex_to_data_blob(mem_ctx, hex_sid);
    DATA_BLOB guid_blob = strhex_to_data_blob(mem_ctx, hex_guid);

    torture_assert(torture,
                   ldb = ldb_init(mem_ctx, torture->ev),
                   "Failed to init ldb");

    torture_assert_int_equal(torture,
                             ldb_register_samba_handlers(ldb), 0,
                             "Failed to register Samba handlers");

    ldb_set_utf8_fns(ldb, NULL, wrap_casefold);

    /* Test SID behaviour */
    torture_assert(torture, attr = ldb_dn_extended_syntax_by_name(ldb, "SID"),
                   "Failed to get SID DN syntax");

    string_sid_blob = data_blob_string_const(sid);

    torture_assert_int_equal(torture,
                             attr->read_fn(ldb, mem_ctx,
                                           &string_sid_blob, &binary_sid_blob), 0,
                             "Failed to parse string SID");

    torture_assert_data_blob_equal(torture, binary_sid_blob, sid_blob,
                                   "Read SID into blob form failed");

    hex_sid_blob = data_blob_string_const(hex_sid);

    torture_assert_int_equal(torture,
                             attr->read_fn(ldb, mem_ctx,
                                           &hex_sid_blob, &binary_sid_blob), 0,
                             "Failed to parse HEX SID");

    torture_assert_data_blob_equal(torture, binary_sid_blob, sid_blob,
                                   "Read SID into blob form failed");

    torture_assert_int_equal(torture,
                             attr->read_fn(ldb, mem_ctx,
                                           &sid_blob, &binary_sid_blob), -1,
                             "Should have failed to parse binary SID");

    torture_assert_int_equal(torture,
                             attr->write_hex_fn(ldb, mem_ctx, &sid_blob, &hex_sid_blob), 0,
                             "Failed to parse binary SID");

    torture_assert_data_blob_equal(torture,
                                   hex_sid_blob, data_blob_string_const(hex_sid),
                                   "Write SID into HEX string form failed");

    torture_assert_int_equal(torture,
                             attr->write_clear_fn(ldb, mem_ctx, &sid_blob, &string_sid_blob), 0,
                             "Failed to parse binary SID");

    torture_assert_data_blob_equal(torture,
                                   string_sid_blob, data_blob_string_const(sid),
                                   "Write SID into clear string form failed");


    /* Test GUID behaviour */
    torture_assert(torture, attr = ldb_dn_extended_syntax_by_name(ldb, "GUID"),
                   "Failed to get GUID DN syntax");

    string_guid_blob = data_blob_string_const(guid);

    torture_assert_int_equal(torture,
                             attr->read_fn(ldb, mem_ctx,
                                           &string_guid_blob, &binary_guid_blob), 0,
                             "Failed to parse string GUID");

    torture_assert_data_blob_equal(torture, binary_guid_blob, guid_blob,
                                   "Read GUID into blob form failed");

    hex_guid_blob = data_blob_string_const(hex_guid);

    torture_assert_int_equal(torture,
                             attr->read_fn(ldb, mem_ctx,
                                           &hex_guid_blob, &binary_guid_blob), 0,
                             "Failed to parse HEX GUID");

    torture_assert_data_blob_equal(torture, binary_guid_blob, guid_blob,
                                   "Read GUID into blob form failed");

    torture_assert_int_equal(torture,
                             attr->read_fn(ldb, mem_ctx,
                                           &guid_blob, &binary_guid_blob), -1,
                             "Should have failed to parse binary GUID");

    torture_assert_int_equal(torture,
                             attr->write_hex_fn(ldb, mem_ctx, &guid_blob, &hex_guid_blob), 0,
                             "Failed to parse binary GUID");

    torture_assert_data_blob_equal(torture,
                                   hex_guid_blob, data_blob_string_const(hex_guid),
                                   "Write GUID into HEX string form failed");

    torture_assert_int_equal(torture,
                             attr->write_clear_fn(ldb, mem_ctx, &guid_blob, &string_guid_blob), 0,
                             "Failed to parse binary GUID");

    torture_assert_data_blob_equal(torture,
                                   string_guid_blob, data_blob_string_const(guid),
                                   "Write GUID into clear string form failed");



    talloc_free(mem_ctx);
    return true;
}
示例#25
0
int main(int argc, const char **argv)
{
	struct ldb_context *ldb;
	struct ldb_result *resultMsg;
	int i;

	/*
	  This is the always the first thing you want to do in an LDB
	  application - initialise up the context structure.

	  Note that you can use the context structure as a parent
	  for talloc allocations as well
	*/
	ldb = ldb_init(NULL);

	/*
	  We now open the database. In this example we just hard code the connection path.

	  Also note that the database is being opened read-only. This means that the 
	  call will fail unless the database already exists. 
	*/
	if (LDB_SUCCESS != ldb_connect(ldb, "tdb://tdbtest.ldb", LDB_FLG_RDONLY, NULL) ){
		printf("Problem on connection\n");
		exit(-1);
	}

	/*
	  At this stage we have an open database, and can start using it. It is opened
	  read-only, so a query is possible. 

	  We construct a search that just returns all the (sensible) contents. You can do
	  quite fine grained results with the LDAP search syntax, however it is a bit
	  confusing to start with. See RFC2254.
	*/
	if (LDB_SUCCESS != ldb_search(ldb, ldb, &resultMsg, NULL, LDB_SCOPE_DEFAULT,
				      NULL, "(dn=*)") ) {
		printf("Problem in search\n");
		exit(-1);
	}
	
	printf("%i records returned\n", resultMsg->count);

	/*
	  We can now iterate through the results, writing them out
	  (to standard output) with our custom output routine as defined
	  at the top of this file
	*/
	for (i = 0; i < resultMsg->count; ++i) {
		struct ldb_ldif ldifMsg;

		printf("Message: %i\n", i+1);
		
		ldifMsg.changetype = LDB_CHANGETYPE_NONE;
		ldifMsg.msg = resultMsg->msgs[i];
		ldb_ldif_write(ldb, vprintf_fn, NULL, &ldifMsg);
	}

	/*
	  There are two objects to clean up - the result from the 
	  ldb_search() query, and the original ldb context.
	*/
	talloc_free(resultMsg);

	talloc_free(ldb);

	return 0;
}
示例#26
0
bool test_DsCrackNames(struct torture_context *tctx,
		       struct DsPrivate *priv)
{
	NTSTATUS status;
	const char *err_msg;
	struct drsuapi_DsCrackNames r;
	union drsuapi_DsNameRequest req;
	uint32_t level_out;
	union drsuapi_DsNameCtr ctr;
	struct drsuapi_DsNameString names[1];
	const char *dns_domain;
	const char *nt4_domain;
	const char *FQDN_1779_name;
	struct ldb_context *ldb;
	struct ldb_dn *FQDN_1779_dn;
	struct ldb_dn *realm_dn;
	const char *realm_dn_str;
	const char *realm_canonical;
	const char *realm_canonical_ex;
	const char *user_principal_name;
	char *user_principal_name_short;
	const char *service_principal_name;
	const char *canonical_name;
	const char *canonical_ex_name;
	const char *dom_sid;
	const char *test_dc = torture_join_netbios_name(priv->join);
	struct dcerpc_pipe *p = priv->drs_pipe;
	TALLOC_CTX *mem_ctx = priv;

	ZERO_STRUCT(r);
	r.in.bind_handle		= &priv->bind_handle;
	r.in.level			= 1;
	r.in.req			= &req;
	r.in.req->req1.codepage		= 1252; /* german */
	r.in.req->req1.language		= 0x00000407; /* german */
	r.in.req->req1.count		= 1;
	r.in.req->req1.names		= names;
	r.in.req->req1.format_flags	= DRSUAPI_DS_NAME_FLAG_NO_FLAGS;

	r.in.req->req1.format_offered	= DRSUAPI_DS_NAME_FORMAT_SID_OR_SID_HISTORY;
	r.in.req->req1.format_desired	= DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT;

	r.out.level_out			= &level_out;
	r.out.ctr			= &ctr;

	dom_sid = dom_sid_string(mem_ctx, torture_join_sid(priv->join));
	
	names[0].str = dom_sid;

	torture_comment(tctx, "Testing DsCrackNames with name '%s' desired format:%d\n",
			names[0].str, r.in.req->req1.format_desired);

	status = dcerpc_drsuapi_DsCrackNames_r(p->binding_handle, mem_ctx, &r);
	if (!NT_STATUS_IS_OK(status)) {
		const char *errstr = nt_errstr(status);
		err_msg = talloc_asprintf(mem_ctx, "dcerpc_drsuapi_DsCrackNames failed - %s", errstr);
		torture_fail(tctx, err_msg);
	} else if (!W_ERROR_IS_OK(r.out.result)) {
		err_msg = talloc_asprintf(mem_ctx, "DsCrackNames failed - %s", win_errstr(r.out.result));
		torture_fail(tctx, err_msg);
	} else if (r.out.ctr->ctr1->array[0].status != DRSUAPI_DS_NAME_STATUS_OK) {
		err_msg = talloc_asprintf(mem_ctx, "DsCrackNames failed on name - %d",
					  r.out.ctr->ctr1->array[0].status);
		torture_fail(tctx, err_msg);
	}

	dns_domain = r.out.ctr->ctr1->array[0].dns_domain_name;
	nt4_domain = r.out.ctr->ctr1->array[0].result_name;

	r.in.req->req1.format_desired	= DRSUAPI_DS_NAME_FORMAT_GUID;

	torture_comment(tctx, "Testing DsCrackNames with name '%s' desired format:%d\n",
			names[0].str, r.in.req->req1.format_desired);

	status = dcerpc_drsuapi_DsCrackNames_r(p->binding_handle, mem_ctx, &r);
	if (!NT_STATUS_IS_OK(status)) {
		const char *errstr = nt_errstr(status);
		err_msg = talloc_asprintf(mem_ctx, "dcerpc_drsuapi_DsCrackNames failed - %s", errstr);
		torture_fail(tctx, err_msg);
	} else if (!W_ERROR_IS_OK(r.out.result)) {
		err_msg = talloc_asprintf(mem_ctx, "DsCrackNames failed - %s", win_errstr(r.out.result));
		torture_fail(tctx, err_msg);
	} else if (r.out.ctr->ctr1->array[0].status != DRSUAPI_DS_NAME_STATUS_OK) {
		err_msg = talloc_asprintf(mem_ctx, "DsCrackNames failed on name - %d",
					  r.out.ctr->ctr1->array[0].status);
		torture_fail(tctx, err_msg);
	}

	priv->domain_dns_name = r.out.ctr->ctr1->array[0].dns_domain_name;
	priv->domain_guid_str = r.out.ctr->ctr1->array[0].result_name;
	GUID_from_string(priv->domain_guid_str, &priv->domain_guid);

	r.in.req->req1.format_desired	= DRSUAPI_DS_NAME_FORMAT_FQDN_1779;

	torture_comment(tctx, "Testing DsCrackNames with name '%s' desired format:%d\n",
			names[0].str, r.in.req->req1.format_desired);

	status = dcerpc_drsuapi_DsCrackNames_r(p->binding_handle, mem_ctx, &r);
	if (!NT_STATUS_IS_OK(status)) {
		const char *errstr = nt_errstr(status);
		err_msg = talloc_asprintf(mem_ctx, "dcerpc_drsuapi_DsCrackNames failed - %s", errstr);
		torture_fail(tctx, err_msg);
	} else if (!W_ERROR_IS_OK(r.out.result)) {
		err_msg = talloc_asprintf(mem_ctx, "DsCrackNames failed - %s", win_errstr(r.out.result));
		torture_fail(tctx, err_msg);
	} else if (r.out.ctr->ctr1->array[0].status != DRSUAPI_DS_NAME_STATUS_OK) {
		err_msg = talloc_asprintf(mem_ctx, "DsCrackNames failed on name - %d",
					  r.out.ctr->ctr1->array[0].status);
		torture_fail(tctx, err_msg);
	}

	ldb = ldb_init(mem_ctx, tctx->ev);
	
	realm_dn_str = r.out.ctr->ctr1->array[0].result_name;
	realm_dn =  ldb_dn_new(mem_ctx, ldb, realm_dn_str);
	realm_canonical = ldb_dn_canonical_string(mem_ctx, realm_dn);

	if (strcmp(realm_canonical,
		   talloc_asprintf(mem_ctx, "%s/", dns_domain))!= 0) {
		err_msg = talloc_asprintf(mem_ctx, "local Round trip on canonical name failed: %s != %s!",
				          realm_canonical,
				          talloc_asprintf(mem_ctx, "%s/", dns_domain));
		torture_fail(tctx, err_msg);
	};

	realm_canonical_ex = ldb_dn_canonical_ex_string(mem_ctx, realm_dn);

	if (strcmp(realm_canonical_ex, 
		   talloc_asprintf(mem_ctx, "%s\n", dns_domain))!= 0) {
		err_msg = talloc_asprintf(mem_ctx, "local Round trip on canonical ex name failed: %s != %s!",
				          realm_canonical,
				          talloc_asprintf(mem_ctx, "%s\n", dns_domain));
		torture_fail(tctx, err_msg);
	};

	r.in.req->req1.format_offered	= DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT;
	r.in.req->req1.format_desired	= DRSUAPI_DS_NAME_FORMAT_FQDN_1779;
	names[0].str = nt4_domain;

	torture_comment(tctx, "Testing DsCrackNames with name '%s' desired format:%d\n",
			names[0].str, r.in.req->req1.format_desired);

	status = dcerpc_drsuapi_DsCrackNames_r(p->binding_handle, mem_ctx, &r);
	if (!NT_STATUS_IS_OK(status)) {
		const char *errstr = nt_errstr(status);
		err_msg = talloc_asprintf(mem_ctx, "dcerpc_drsuapi_DsCrackNames failed - %s", errstr);
		torture_fail(tctx, err_msg);
	} else if (!W_ERROR_IS_OK(r.out.result)) {
		err_msg = talloc_asprintf(mem_ctx, "DsCrackNames failed - %s", win_errstr(r.out.result));
		torture_fail(tctx, err_msg);
	} else if (r.out.ctr->ctr1->array[0].status != DRSUAPI_DS_NAME_STATUS_OK) {
		err_msg = talloc_asprintf(mem_ctx, "DsCrackNames failed on name - %d",
					  r.out.ctr->ctr1->array[0].status);
		torture_fail(tctx, err_msg);
	}

	priv->domain_obj_dn = r.out.ctr->ctr1->array[0].result_name;

	r.in.req->req1.format_offered	= DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT;
	r.in.req->req1.format_desired	= DRSUAPI_DS_NAME_FORMAT_FQDN_1779;
	names[0].str = talloc_asprintf(mem_ctx, "%s%s$", nt4_domain, test_dc);

	torture_comment(tctx, "Testing DsCrackNames with name '%s' desired format:%d\n",
			names[0].str, r.in.req->req1.format_desired);

	status = dcerpc_drsuapi_DsCrackNames_r(p->binding_handle, mem_ctx, &r);
	if (!NT_STATUS_IS_OK(status)) {
		const char *errstr = nt_errstr(status);
		err_msg = talloc_asprintf(mem_ctx, "dcerpc_drsuapi_DsCrackNames failed - %s", errstr);
		torture_fail(tctx, err_msg);
	} else if (!W_ERROR_IS_OK(r.out.result)) {
		err_msg = talloc_asprintf(mem_ctx, "DsCrackNames failed - %s", win_errstr(r.out.result));
		torture_fail(tctx, err_msg);
	} else if (r.out.ctr->ctr1->array[0].status != DRSUAPI_DS_NAME_STATUS_OK) {
		err_msg = talloc_asprintf(mem_ctx, "DsCrackNames failed on name - %d",
					  r.out.ctr->ctr1->array[0].status);
		torture_fail(tctx, err_msg);
	}

	FQDN_1779_name = r.out.ctr->ctr1->array[0].result_name;

	r.in.req->req1.format_offered	= DRSUAPI_DS_NAME_FORMAT_GUID;
	r.in.req->req1.format_desired	= DRSUAPI_DS_NAME_FORMAT_FQDN_1779;
	names[0].str = priv->domain_guid_str;

	torture_comment(tctx, "Testing DsCrackNames with name '%s' desired format:%d\n",
			names[0].str, r.in.req->req1.format_desired);

	status = dcerpc_drsuapi_DsCrackNames_r(p->binding_handle, mem_ctx, &r);
	if (!NT_STATUS_IS_OK(status)) {
		const char *errstr = nt_errstr(status);
		err_msg = talloc_asprintf(mem_ctx, "dcerpc_drsuapi_DsCrackNames failed - %s", errstr);
		torture_fail(tctx, err_msg);
	} else if (!W_ERROR_IS_OK(r.out.result)) {
		err_msg = talloc_asprintf(mem_ctx, "DsCrackNames failed - %s", win_errstr(r.out.result));
		torture_fail(tctx, err_msg);
	} else if (r.out.ctr->ctr1->array[0].status != DRSUAPI_DS_NAME_STATUS_OK) {
		err_msg = talloc_asprintf(mem_ctx, "DsCrackNames failed on name - %d",
					  r.out.ctr->ctr1->array[0].status);
		torture_fail(tctx, err_msg);
	}

	if (strcmp(priv->domain_dns_name, r.out.ctr->ctr1->array[0].dns_domain_name) != 0) {
		err_msg = talloc_asprintf(mem_ctx,
				"DsCrackNames failed to return same DNS name - expected %s got %s",
				priv->domain_dns_name, r.out.ctr->ctr1->array[0].dns_domain_name);
		torture_fail(tctx, err_msg);
	}

	FQDN_1779_dn = ldb_dn_new(mem_ctx, ldb, FQDN_1779_name);

	canonical_name = ldb_dn_canonical_string(mem_ctx, FQDN_1779_dn);
	canonical_ex_name = ldb_dn_canonical_ex_string(mem_ctx, FQDN_1779_dn);

	user_principal_name = talloc_asprintf(mem_ctx, "%s$@%s", test_dc, dns_domain);

	/* form up a user@DOMAIN */
	user_principal_name_short = talloc_asprintf(mem_ctx, "%s$@%s", test_dc, nt4_domain);
	/* variable nt4_domain includs a trailing \ */
	user_principal_name_short[strlen(user_principal_name_short) - 1] = '\0';
	
	service_principal_name = talloc_asprintf(mem_ctx, "HOST/%s", test_dc);
	{
		
		struct {
			enum drsuapi_DsNameFormat format_offered;
			enum drsuapi_DsNameFormat format_desired;
			const char *comment;
			const char *str;
			const char *expected_str;
			const char *expected_dns;
			enum drsuapi_DsNameStatus status;
			enum drsuapi_DsNameStatus alternate_status;
			enum drsuapi_DsNameFlags flags;
			bool skip;
		} crack[] = {
			{
				.format_offered	= DRSUAPI_DS_NAME_FORMAT_USER_PRINCIPAL,
				.format_desired	= DRSUAPI_DS_NAME_FORMAT_FQDN_1779,
				.str = user_principal_name,
				.expected_str = FQDN_1779_name,
				.status = DRSUAPI_DS_NAME_STATUS_OK
			},
			{
				.format_offered	= DRSUAPI_DS_NAME_FORMAT_USER_PRINCIPAL,
				.format_desired	= DRSUAPI_DS_NAME_FORMAT_FQDN_1779,
				.str = user_principal_name_short,
				.expected_str = FQDN_1779_name,
				.status = DRSUAPI_DS_NAME_STATUS_OK
			},
			{
				.format_offered	= DRSUAPI_DS_NAME_FORMAT_FQDN_1779,
示例#27
0
/*
  called to initialise the driver
 */
_PUBLIC_ isc_result_t dlz_create(const char *dlzname,
				 unsigned int argc, char *argv[],
				 void **dbdata, ...)
{
	struct dlz_bind9_data *state;
	const char *helper_name;
	va_list ap;
	isc_result_t result;
	TALLOC_CTX *tmp_ctx;
	int ret;
	struct ldb_dn *dn;
	struct b9_options options;

	ZERO_STRUCT(options);

	state = talloc_zero(NULL, struct dlz_bind9_data);
	if (state == NULL) {
		return ISC_R_NOMEMORY;
	}

	tmp_ctx = talloc_new(state);

	/* fill in the helper functions */
	va_start(ap, dbdata);
	while ((helper_name = va_arg(ap, const char *)) != NULL) {
		b9_add_helper(state, helper_name, va_arg(ap, void*));
	}
	va_end(ap);

	state->ev_ctx = s4_event_context_init(state);
	if (state->ev_ctx == NULL) {
		result = ISC_R_NOMEMORY;
		goto failed;
	}

	state->samdb = ldb_init(state, state->ev_ctx);
	if (state->samdb == NULL) {
		state->log(ISC_LOG_ERROR, "samba_dlz: Failed to create ldb");
		result = ISC_R_FAILURE;
		goto failed;
	}

	result = parse_options(state, argc, argv, &options);
	if (result != ISC_R_SUCCESS) {
		goto failed;
	}

	state->lp = loadparm_init_global(true);
	if (state->lp == NULL) {
		result = ISC_R_NOMEMORY;
		goto failed;
	}

	if (options.url == NULL) {
		options.url = talloc_asprintf(tmp_ctx, "ldapi://%s",
					      lpcfg_private_path(tmp_ctx, state->lp, "ldap_priv/ldapi"));
		if (options.url == NULL) {
			result = ISC_R_NOMEMORY;
			goto failed;
		}
	}

	ret = ldb_connect(state->samdb, options.url, 0, NULL);
	if (ret != LDB_SUCCESS) {
		state->log(ISC_LOG_ERROR, "samba_dlz: Failed to connect to %s - %s",
			   options.url, ldb_errstring(state->samdb));
		result = ISC_R_FAILURE;
		goto failed;
	}

	ret = ldb_modules_hook(state->samdb, LDB_MODULE_HOOK_CMDLINE_POSTCONNECT);
	if (ret != LDB_SUCCESS) {
		state->log(ISC_LOG_ERROR, "samba_dlz: Failed postconnect for %s - %s",
			   options.url, ldb_errstring(state->samdb));
		result = ISC_R_FAILURE;
		goto failed;
	}

	dn = ldb_get_default_basedn(state->samdb);
	if (dn == NULL) {
		state->log(ISC_LOG_ERROR, "samba_dlz: Unable to get basedn for %s - %s",
			   options.url, ldb_errstring(state->samdb));
		result = ISC_R_FAILURE;
		goto failed;
	}

	state->log(ISC_LOG_INFO, "samba_dlz: started for DN %s",
		   ldb_dn_get_linearized(dn));

	*dbdata = state;

	talloc_free(tmp_ctx);
	return ISC_R_SUCCESS;

failed:
	talloc_free(state);
	return result;
}
示例#28
0
文件: ldb.c 项目: 0x24bin/winexe-1
static bool torture_ldb_dn(struct torture_context *torture)
{
	TALLOC_CTX *mem_ctx = talloc_new(torture);
	struct ldb_context *ldb;
	struct ldb_dn *dn;
	struct ldb_dn *child_dn;
	struct ldb_dn *typo_dn;
	struct ldb_val val;

	torture_assert(torture, 
		       ldb = ldb_init(mem_ctx, torture->ev),
		       "Failed to init ldb");

	torture_assert_int_equal(torture, 
				 ldb_register_samba_handlers(ldb), 0, 
				 "Failed to register Samba handlers");

	ldb_set_utf8_fns(ldb, NULL, wrap_casefold);

	/* Check behaviour of a normal DN */
	torture_assert(torture, 
		       dn = ldb_dn_new(mem_ctx, ldb, NULL), 
		       "Failed to create a NULL DN");

	torture_assert(torture, 
		       ldb_dn_validate(dn),
		       "Failed to validate NULL DN");

	torture_assert(torture, 
		       ldb_dn_add_base_fmt(dn, "dc=org"), 
		       "Failed to add base DN");

	torture_assert(torture, 
		       ldb_dn_add_child_fmt(dn, "dc=samba"), 
		       "Failed to add base DN");

	torture_assert_str_equal(torture, ldb_dn_get_linearized(dn), "dc=samba,dc=org", 
				 "linearized DN incorrect");

	torture_assert_str_equal(torture, ldb_dn_get_extended_linearized(mem_ctx, dn, 0), "dc=samba,dc=org", 
				 "extended linearized DN incorrect");

	/* Check child DN comparisons */
	torture_assert(torture, 
		       child_dn = ldb_dn_new(mem_ctx, ldb, "CN=users,DC=SAMBA,DC=org"), 
		       "Failed to create child DN");

	torture_assert(torture, 
		       ldb_dn_compare(dn, child_dn) != 0,
		       "Comparison on dc=samba,dc=org and CN=users,DC=SAMBA,DC=org should != 0");

	torture_assert(torture, 
		       ldb_dn_compare_base(child_dn, dn) != 0,
		       "Base Comparison of CN=users,DC=SAMBA,DC=org and dc=samba,dc=org should != 0");

	torture_assert(torture, 
		       ldb_dn_compare_base(dn, child_dn) == 0,
		       "Base Comparison on dc=samba,dc=org and CN=users,DC=SAMBA,DC=org should == 0");

	/* Check comparisons with a truncated DN */
	torture_assert(torture, 
		       typo_dn = ldb_dn_new(mem_ctx, ldb, "c=samba,dc=org"), 
		       "Failed to create 'typo' DN");

	torture_assert(torture, 
		       ldb_dn_compare(dn, typo_dn) != 0,
		       "Comparison on dc=samba,dc=org and c=samba,dc=org should != 0");

	torture_assert(torture, 
		       ldb_dn_compare_base(typo_dn, dn) != 0,
		       "Base Comparison of c=samba,dc=org and dc=samba,dc=org should != 0");

	torture_assert(torture, 
		       ldb_dn_compare_base(dn, typo_dn) != 0,
		       "Base Comparison on dc=samba,dc=org and c=samba,dc=org should != 0");

	/* Check DN based on MS-ADTS:3.1.1.5.1.2 Naming Constraints*/
	torture_assert(torture,
		       dn = ldb_dn_new(mem_ctx, ldb, "CN=New\nLine,DC=SAMBA,DC=org"),
		       "Failed to create a DN with 0xA in it");

	/* this is a warning until we work out how the DEL: CNs work */
	if (ldb_dn_validate(dn) != false) {
		torture_warning(torture,
				"should have failed to validate a DN with 0xA in it");
	}

	val = data_blob_const("CN=Zer\0,DC=SAMBA,DC=org", 23);
	torture_assert(torture,
		       NULL == ldb_dn_from_ldb_val(mem_ctx, ldb, &val),
		       "should fail to create a DN with 0x0 in it");

	talloc_free(mem_ctx);
	return true;
}
示例#29
0
文件: viki.c 项目: kingiol/cmoon
int main(int argc, char **argv, char **envp)
{
    CGI *cgi;
    NEOERR *err;
    int ret;

    HASH *dbh;
    HASH *tplh;
    session_t *session = NULL;
    char *requri, *jsoncb;

    int (*data_handler)(CGI *cgi, HASH *dbh, session_t *session);
    void *lib;

    //sleep(20);
    mconfig_parse_file(SITE_CONFIG, &g_cfg);
    mtc_init(TC_ROOT"viki");

    ret = ltpl_init(&tplh);
    if (ret != RET_RBTOP_OK) {
        mtc_err("init templates error");
        mutil_redirect("初始化模板失败", TGT_SELF, URL_CLOSE, true);
        return ret;
    }

    ret = ldb_init(&dbh);
    if (ret != RET_RBTOP_OK) {
        mtc_err("init db error");
        mutil_redirect("初始化数据库失败", TGT_SELF, URL_CLOSE, true);
        return ret;
    }

    lib = dlopen(NULL, RTLD_NOW|RTLD_GLOBAL);
    if (lib == NULL) {
        mtc_err("possible? %s", dlerror());
        mutil_redirect("初始化库函数失败", TGT_SELF, URL_CLOSE, true);
        return 1;
    }
    
#ifndef DROP_FCGI
    cgiwrap_init_emu(NULL, &read_cb, &printf_cb, &write_cb, NULL, NULL, NULL);
    while (FCGI_Accept() >= 0) {
#endif
        cgiwrap_init_std(argc, argv, environ);
        err = cgi_init(&cgi, NULL);
        JUMP_NOK_CGI(err, response);
        err = cgi_parse(cgi);
        JUMP_NOK_CGI(err, response);

#ifdef NCGI_MODE
        hdf_set_value(cgi->hdf, PRE_REQ_URI_RW, "/csc/hc");
        hdf_set_value(cgi->hdf, PRE_COOKIE".uin", "1001");
        hdf_set_value(cgi->hdf, PRE_COOKIE".uname", "bigml");
        hdf_set_value(cgi->hdf, PRE_COOKIE".musn", "8Y]u0|v=*MS]U3J");
#endif
        
        ret = session_init(cgi->hdf, dbh, &session);
        if (ret != RET_RBTOP_OK) {
            mtc_err("init session failure");
            goto response;
        }

        requri = hdf_get_value(cgi->hdf, PRE_REQ_URI_RW, "NULL");
        if (mutil_client_attack(cgi->hdf, requri, LMT_CLI_ATTACK,
                                PERIOD_CLI_ATTACK)) {
            goto response;
        }
        
        ret = lfile_access_rewrited(cgi, dbh, session);
        if (ret != RET_RBTOP_OK) {
            goto response;
        }

        data_handler = lutil_get_data_handler(lib, cgi);
        if (data_handler == NULL) {
            mtc_err("get handler failure");
            ret = RET_RBTOP_NEXIST;
            goto response;
        }

        ret = (*data_handler)(cgi, dbh, session);
        
    response:
        if (cgi != NULL && cgi->hdf != NULL) {
#ifdef DEBUG_HDF
            hdf_write_file(cgi->hdf, TC_ROOT"hdf.viki");
#endif
            switch (CGI_REQ_TYPE(cgi)) {
            case CGI_REQ_HTML:
                if (CGI_REQ_METHOD(cgi) != CGI_REQ_GET) {
                    goto resp_ajax;
                }
                if (ret != RET_RBTOP_OK && ret == RET_RBTOP_NEXIST) {
                    cgi_redirect(cgi, "/404.html");
                } else {
                    ret = ltpl_render(cgi, tplh, session);
                    if (ret != RET_RBTOP_OK) {
                        if (ret == RET_RBTOP_NEXIST)
                            cgi_redirect(cgi, "/404.html");
                        else
                            cgi_redirect(cgi, "/503.html");
                    }
                }
                break;
            case CGI_REQ_AJAX:
            resp_ajax:
                ldb_opfinish_json(ret, cgi->hdf, NULL, 0);
                jsoncb = hdf_get_value(cgi->hdf, PRE_REQ_AJAX_FN, NULL);
                if (jsoncb != NULL) {
                    mjson_execute_hdf(cgi->hdf, jsoncb, session->tm_cache_browser);
                } else {
                    mjson_output_hdf(cgi->hdf, session->tm_cache_browser);
                }
                break;
            default:
                cgi_redirect(cgi, "/503.html");
                break;
            }
            cgi_destroy(&cgi);
            session_destroy(&session);
        }
#ifndef DROP_FCGI
    }
#endif

    ldb_destroy(dbh);
    ltpl_destroy(tplh);
    mconfig_cleanup(&g_cfg);
    return 0;
}
示例#30
0
static NTSTATUS torture_leave_ads_domain(struct torture_context *torture,
					 TALLOC_CTX *mem_ctx,
					 struct libnet_JoinDomain *libnet_r)
{
	int rtn;
	TALLOC_CTX *tmp_ctx;

	struct ldb_dn *server_dn;
	struct ldb_context *ldb_ctx;

	char *remote_ldb_url; 
	 
	/* Check if we are a domain controller. If not, exit. */
	if (!libnet_r->out.server_dn_str) {
		return NT_STATUS_OK;
	}

	tmp_ctx = talloc_named(mem_ctx, 0, "torture_leave temporary context");
	if (!tmp_ctx) {
		libnet_r->out.error_string = NULL;
		return NT_STATUS_NO_MEMORY;
	}

	ldb_ctx = ldb_init(tmp_ctx, torture->ev);
	if (!ldb_ctx) {
		libnet_r->out.error_string = NULL;
		talloc_free(tmp_ctx);
		return NT_STATUS_NO_MEMORY;
	}

	/* Remove CN=Servers,... entry from the AD. */ 
	server_dn = ldb_dn_new(tmp_ctx, ldb_ctx, libnet_r->out.server_dn_str);
	if (! ldb_dn_validate(server_dn)) {
		libnet_r->out.error_string = NULL;
		talloc_free(tmp_ctx);
		return NT_STATUS_NO_MEMORY;
	}

	remote_ldb_url = talloc_asprintf(tmp_ctx, "ldap://%s", libnet_r->out.samr_binding->host);
	if (!remote_ldb_url) {
		libnet_r->out.error_string = NULL;
		talloc_free(tmp_ctx);
		return NT_STATUS_NO_MEMORY;
	}

	ldb_set_opaque(ldb_ctx, "credentials", cmdline_credentials);
	ldb_set_opaque(ldb_ctx, "loadparm", cmdline_lp_ctx);

	rtn = ldb_connect(ldb_ctx, remote_ldb_url, 0, NULL);
	if (rtn != 0) {
		libnet_r->out.error_string = NULL;
		talloc_free(tmp_ctx);
		return NT_STATUS_UNSUCCESSFUL;
	}

	rtn = ldb_delete(ldb_ctx, server_dn);
	if (rtn != 0) {
		libnet_r->out.error_string = NULL;
		talloc_free(tmp_ctx);
		return NT_STATUS_UNSUCCESSFUL;
	}

	DEBUG(0, ("%s removed successfully.\n", libnet_r->out.server_dn_str));

	talloc_free(tmp_ctx); 
	return NT_STATUS_OK;
}