⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ldb.c

📁 samba最新软件
💻 C
📖 第 1 页 / 共 3 页
字号:
		ldb->transaction_active--;	return ldb_transaction_cancel_internal(ldb);}static int ldb_autotransaction_start(struct ldb_context *ldb){	/* explicit transaction active, ignore autotransaction request */	if (ldb->transaction_active)		return LDB_SUCCESS;	return ldb_transaction_start_internal(ldb);}static int ldb_autotransaction_commit(struct ldb_context *ldb){	/* explicit transaction active, ignore autotransaction request */	if (ldb->transaction_active)		return LDB_SUCCESS;	return ldb_transaction_commit_internal(ldb);}static int ldb_autotransaction_cancel(struct ldb_context *ldb){	/* explicit transaction active, ignore autotransaction request */	if (ldb->transaction_active)		return LDB_SUCCESS;	return ldb_transaction_cancel_internal(ldb);}/* autostarts a transacion if none active */static int ldb_autotransaction_request(struct ldb_context *ldb, struct ldb_request *req){	int ret;	ret = ldb_autotransaction_start(ldb);	if (ret != LDB_SUCCESS) {		return ret;	}	ret = ldb_request(ldb, req);	if (ret == LDB_SUCCESS) {		ret = ldb_wait(req->handle, LDB_WAIT_ALL);	}	if (ret == LDB_SUCCESS) {		return ldb_autotransaction_commit(ldb);	}	ldb_autotransaction_cancel(ldb);	if (ldb->err_string == NULL) {		/* no error string was setup by the backend */		ldb_asprintf_errstring(ldb, "%s (%d)", ldb_strerror(ret), ret);	}	return ret;}int ldb_wait(struct ldb_handle *handle, enum ldb_wait_type type){	int ret;	if (!handle) {		return LDB_SUCCESS;	}	ret = handle->module->ops->wait(handle, type);	if (!ldb_errstring(handle->module->ldb)) {		/* Set a default error string, to place the blame somewhere */		ldb_asprintf_errstring(handle->module->ldb, "error waiting on module %s: %s (%d)", handle->module->ops->name, ldb_strerror(ret), ret);	}	return ret;}/* set the specified timeout or, if timeout is 0 set the default timeout *//* timeout == -1 means no timeout */int ldb_set_timeout(struct ldb_context *ldb, struct ldb_request *req, int timeout){	if (req == NULL) return LDB_ERR_OPERATIONS_ERROR;		if (timeout != 0) {		req->timeout = timeout;	} else {		req->timeout = ldb->default_timeout;	}	req->starttime = time(NULL);	return LDB_SUCCESS;}/* calculates the new timeout based on the previous starttime and timeout */int ldb_set_timeout_from_prev_req(struct ldb_context *ldb, struct ldb_request *oldreq, struct ldb_request *newreq){	time_t now;	if (newreq == NULL) return LDB_ERR_OPERATIONS_ERROR;	now = time(NULL);	if (oldreq == NULL)		return ldb_set_timeout(ldb, newreq, 0);	if ((now - oldreq->starttime) > oldreq->timeout) {		return LDB_ERR_TIME_LIMIT_EXCEEDED;	}	newreq->starttime = oldreq->starttime;	newreq->timeout = oldreq->timeout - (now - oldreq->starttime);	return LDB_SUCCESS;}/*    set the permissions for new files to be passed to open() in   backends that use local files */void ldb_set_create_perms(struct ldb_context *ldb, unsigned int perms){	ldb->create_perms = perms;}/*  start an ldb request  NOTE: the request must be a talloc context.  returns LDB_ERR_* on errors.*/int ldb_request(struct ldb_context *ldb, struct ldb_request *req){	struct ldb_module *module;	int ret;	ldb_reset_err_string(ldb);	/* call the first module in the chain */	switch (req->operation) {	case LDB_SEARCH:		FIRST_OP(ldb, search);		ret = module->ops->search(module, req);		break;	case LDB_ADD:		FIRST_OP(ldb, add);		ret = module->ops->add(module, req);		break;	case LDB_MODIFY:		FIRST_OP(ldb, modify);		ret = module->ops->modify(module, req);		break;	case LDB_DELETE:		FIRST_OP(ldb, del);		ret = module->ops->del(module, req);		break;	case LDB_RENAME:		FIRST_OP(ldb, rename);		ret = module->ops->rename(module, req);		break;	case LDB_EXTENDED:		FIRST_OP(ldb, extended);		ret = module->ops->extended(module, req);		break;	case LDB_SEQUENCE_NUMBER:		FIRST_OP(ldb, sequence_number);		ret = module->ops->sequence_number(module, req);		break;	default:		FIRST_OP(ldb, request);		ret = module->ops->request(module, req);		break;	}	return ret;}/*  search the database given a LDAP-like search expression  returns an LDB error code  Use talloc_free to free the ldb_message returned in 'res', if successful*/int ldb_search_default_callback(struct ldb_context *ldb, void *context, struct ldb_reply *ares){	struct ldb_result *res;	int n;	 	if (!context) {		ldb_set_errstring(ldb, "NULL Context in callback");		return LDB_ERR_OPERATIONS_ERROR;	}		res = talloc_get_type(context, struct ldb_result);	if (!res || !ares) {		ldb_set_errstring(ldb, "NULL res or ares in callback");		goto error;	}	switch (ares->type) {	case LDB_REPLY_ENTRY:		res->msgs = talloc_realloc(res, res->msgs, struct ldb_message *, res->count + 2);		if (! res->msgs) {			goto error;		}		res->msgs[res->count + 1] = NULL;		res->msgs[res->count] = talloc_move(res->msgs, &ares->message);		res->count++;		break;	case LDB_REPLY_REFERRAL:		if (res->refs) {			for (n = 0; res->refs[n]; n++) /*noop*/ ;		} else {			n = 0;		}		res->refs = talloc_realloc(res, res->refs, char *, n + 2);		if (! res->refs) {			goto error;		}		res->refs[n] = talloc_move(res->refs, &ares->referral);		res->refs[n + 1] = NULL;		break;	case LDB_REPLY_EXTENDED:	case LDB_REPLY_DONE:		/* TODO: we should really support controls on entries and referrals too! */		res->controls = talloc_move(res, &ares->controls);		break;			}	talloc_free(ares);	return LDB_SUCCESS;error:	talloc_free(ares);	return LDB_ERR_OPERATIONS_ERROR;}int ldb_build_search_req(struct ldb_request **ret_req,			struct ldb_context *ldb,			void *mem_ctx,			struct ldb_dn *base,	       		enum ldb_scope scope,			const char *expression,			const char * const *attrs,			struct ldb_control **controls,			void *context,			ldb_request_callback_t callback){	struct ldb_request *req;	*ret_req = NULL;	req = talloc(mem_ctx, struct ldb_request);	if (req == NULL) {		ldb_set_errstring(ldb, "Out of Memory");		return LDB_ERR_OPERATIONS_ERROR;	}	req->operation = LDB_SEARCH;	if (base == NULL) {		req->op.search.base = ldb_dn_new(req, ldb, NULL);	} else {		req->op.search.base = base;	}	req->op.search.scope = scope;	req->op.search.tree = ldb_parse_tree(req, expression);	if (req->op.search.tree == NULL) {		ldb_set_errstring(ldb, "Unable to parse search expression");		talloc_free(req);		return LDB_ERR_OPERATIONS_ERROR;	}	req->op.search.attrs = attrs;	req->controls = controls;	req->context = context;	req->callback = callback;	*ret_req = req;	return LDB_SUCCESS;}int ldb_build_add_req(struct ldb_request **ret_req,			struct ldb_context *ldb,			void *mem_ctx,			const struct ldb_message *message,			struct ldb_control **controls,			void *context,			ldb_request_callback_t callback){	struct ldb_request *req;	*ret_req = NULL;	req = talloc(mem_ctx, struct ldb_request);	if (req == NULL) {		ldb_set_errstring(ldb, "Out of Memory");		return LDB_ERR_OPERATIONS_ERROR;	}	req->operation = LDB_ADD;	req->op.add.message = message;	req->controls = controls;	req->context = context;	req->callback = callback;	*ret_req = req;	return LDB_SUCCESS;}int ldb_build_mod_req(struct ldb_request **ret_req,			struct ldb_context *ldb,			void *mem_ctx,			const struct ldb_message *message,			struct ldb_control **controls,			void *context,			ldb_request_callback_t callback){	struct ldb_request *req;	*ret_req = NULL;	req = talloc(mem_ctx, struct ldb_request);	if (req == NULL) {		ldb_set_errstring(ldb, "Out of Memory");		return LDB_ERR_OPERATIONS_ERROR;	}	req->operation = LDB_MODIFY;	req->op.mod.message = message;	req->controls = controls;	req->context = context;	req->callback = callback;	*ret_req = req;	return LDB_SUCCESS;}int ldb_build_del_req(struct ldb_request **ret_req,			struct ldb_context *ldb,			void *mem_ctx,			struct ldb_dn *dn,			struct ldb_control **controls,			void *context,			ldb_request_callback_t callback){	struct ldb_request *req;	*ret_req = NULL;	req = talloc(mem_ctx, struct ldb_request);	if (req == NULL) {		ldb_set_errstring(ldb, "Out of Memory");		return LDB_ERR_OPERATIONS_ERROR;	}	req->operation = LDB_DELETE;	req->op.del.dn = dn;	req->controls = controls;	req->context = context;	req->callback = callback;	*ret_req = req;	return LDB_SUCCESS;}int ldb_build_rename_req(struct ldb_request **ret_req,			struct ldb_context *ldb,			void *mem_ctx,			struct ldb_dn *olddn,			struct ldb_dn *newdn,			struct ldb_control **controls,			void *context,			ldb_request_callback_t callback){	struct ldb_request *req;	*ret_req = NULL;	req = talloc(mem_ctx, struct ldb_request);	if (req == NULL) {		ldb_set_errstring(ldb, "Out of Memory");		return LDB_ERR_OPERATIONS_ERROR;	}	req->operation = LDB_RENAME;	req->op.rename.olddn = olddn;	req->op.rename.newdn = newdn;	req->controls = controls;	req->context = context;	req->callback = callback;	*ret_req = req;	return LDB_SUCCESS;}int ldb_extended_default_callback(struct ldb_context *ldb, void *context, struct ldb_reply *ares){	struct ldb_result *res;	 	if (!context) {		ldb_set_errstring(ldb, "NULL Context in callback");		return LDB_ERR_OPERATIONS_ERROR;	}	res = talloc_get_type(context, struct ldb_result);	if (!res || !ares) {		ldb_set_errstring(ldb, "NULL res or ares in callback");		goto error;	}	switch (ares->type) {	case LDB_REPLY_ENTRY:	case LDB_REPLY_REFERRAL:	case LDB_REPLY_DONE:		ldb_set_errstring(ldb, "invalid ares type in callback");		goto error;	case LDB_REPLY_EXTENDED:		/* TODO: we should really support controls on entries and referrals too! */		res->extended = talloc_move(res, &ares->response);		res->controls = talloc_move(res, &ares->controls);		break;			}	talloc_free(ares);	return LDB_SUCCESS;error:	talloc_free(ares);	return LDB_ERR_OPERATIONS_ERROR;}int ldb_build_extended_req(struct ldb_request **ret_req,			   struct ldb_context *ldb,			   void *mem_ctx,			   const char *oid,			   void *data,			   struct ldb_control **controls,			   void *context,			   ldb_request_callback_t callback){	struct ldb_request *req;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -