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

📄 ldap_backend.c

📁 samba最新软件
💻 C
📖 第 1 页 / 共 2 页
字号:
				break;			}			msg->elements[i].num_values = req->mods[i].attrib.num_values;			if (msg->elements[i].num_values > 0) {				msg->elements[i].values = talloc_array(msg->elements, struct ldb_val,								       msg->elements[i].num_values);				NT_STATUS_HAVE_NO_MEMORY(msg->elements[i].values);				for (j=0; j < msg->elements[i].num_values; j++) {					if (!(req->mods[i].attrib.values[j].length > 0)) {						result = LDAP_OTHER;						errstr = "Empty attribute values are not allowed";						goto reply;					}					msg->elements[i].values[j].length = req->mods[i].attrib.values[j].length;					msg->elements[i].values[j].data = req->mods[i].attrib.values[j].data;							}			}		}	} else {		result = LDAP_OTHER;		errstr = "No mods are not allowed";		goto reply;	}reply:	modify_reply = ldapsrv_init_reply(call, LDAP_TAG_ModifyResponse);	NT_STATUS_HAVE_NO_MEMORY(modify_reply);	if (result == LDAP_SUCCESS) {		ldb_ret = ldb_modify(samdb, msg);		result = map_ldb_error(samdb, ldb_ret, &errstr);	}	modify_result = &modify_reply->msg->r.AddResponse;	modify_result->dn = NULL;	modify_result->resultcode = result;	modify_result->errormessage = (errstr?talloc_strdup(modify_reply, errstr):NULL);	modify_result->referral = NULL;	talloc_free(local_ctx);	ldapsrv_queue_reply(call, modify_reply);	return NT_STATUS_OK;}static NTSTATUS ldapsrv_AddRequest(struct ldapsrv_call *call){	struct ldap_AddRequest *req = &call->request->r.AddRequest;	struct ldap_Result *add_result;	struct ldapsrv_reply *add_reply;	void *local_ctx;	struct ldb_context *samdb = call->conn->ldb;	struct ldb_message *msg = NULL;	struct ldb_dn *dn;	const char *errstr = NULL;	int result = LDAP_SUCCESS;	int ldb_ret;	int i,j;	DEBUG(10, ("AddRequest"));	DEBUGADD(10, (" dn: %s", req->dn));	local_ctx = talloc_named(call, 0, "AddRequest local memory context");	NT_STATUS_HAVE_NO_MEMORY(local_ctx);	dn = ldb_dn_new(local_ctx, samdb, req->dn);	VALID_DN_SYNTAX(dn,1);	DEBUG(10, ("AddRequest: dn: [%s]\n", req->dn));	msg = talloc(local_ctx, struct ldb_message);	NT_STATUS_HAVE_NO_MEMORY(msg);	msg->dn = dn;	msg->num_elements = 0;	msg->elements = NULL;	if (req->num_attributes > 0) {		msg->num_elements = req->num_attributes;		msg->elements = talloc_array(msg, struct ldb_message_element, msg->num_elements);		NT_STATUS_HAVE_NO_MEMORY(msg->elements);		for (i=0; i < msg->num_elements; i++) {			msg->elements[i].name = discard_const_p(char, req->attributes[i].name);			msg->elements[i].flags = 0;			msg->elements[i].num_values = 0;			msg->elements[i].values = NULL;						if (req->attributes[i].num_values > 0) {				msg->elements[i].num_values = req->attributes[i].num_values;				msg->elements[i].values = talloc_array(msg->elements, struct ldb_val,								       msg->elements[i].num_values);				NT_STATUS_HAVE_NO_MEMORY(msg->elements[i].values);				for (j=0; j < msg->elements[i].num_values; j++) {					if (!(req->attributes[i].values[j].length > 0)) {						result = LDAP_OTHER;						errstr = "Empty attribute values are not allowed";						goto reply;					}					msg->elements[i].values[j].length = req->attributes[i].values[j].length;					msg->elements[i].values[j].data = req->attributes[i].values[j].data;							}			} else {				result = LDAP_OTHER;				errstr = "No attribute values are not allowed";				goto reply;			}		}	} else {		result = LDAP_OTHER;		errstr = "No attributes are not allowed";		goto reply;	}reply:	add_reply = ldapsrv_init_reply(call, LDAP_TAG_AddResponse);	NT_STATUS_HAVE_NO_MEMORY(add_reply);	if (result == LDAP_SUCCESS) {		ldb_ret = ldb_add(samdb, msg);		result = map_ldb_error(samdb, ldb_ret, &errstr);	}	add_result = &add_reply->msg->r.AddResponse;	add_result->dn = NULL;	add_result->resultcode = result;	add_result->errormessage = (errstr?talloc_strdup(add_reply,errstr):NULL);	add_result->referral = NULL;	talloc_free(local_ctx);	ldapsrv_queue_reply(call, add_reply);	return NT_STATUS_OK;}static NTSTATUS ldapsrv_DelRequest(struct ldapsrv_call *call){	struct ldap_DelRequest *req = &call->request->r.DelRequest;	struct ldap_Result *del_result;	struct ldapsrv_reply *del_reply;	void *local_ctx;	struct ldb_context *samdb = call->conn->ldb;	struct ldb_dn *dn;	const char *errstr = NULL;	int result = LDAP_SUCCESS;	int ldb_ret;	DEBUG(10, ("DelRequest"));	DEBUGADD(10, (" dn: %s", req->dn));	local_ctx = talloc_named(call, 0, "DelRequest local memory context");	NT_STATUS_HAVE_NO_MEMORY(local_ctx);	dn = ldb_dn_new(local_ctx, samdb, req->dn);	VALID_DN_SYNTAX(dn,1);	DEBUG(10, ("DelRequest: dn: [%s]\n", req->dn));reply:	del_reply = ldapsrv_init_reply(call, LDAP_TAG_DelResponse);	NT_STATUS_HAVE_NO_MEMORY(del_reply);	if (result == LDAP_SUCCESS) {		ldb_ret = ldb_delete(samdb, dn);		result = map_ldb_error(samdb, ldb_ret, &errstr);	}	del_result = &del_reply->msg->r.DelResponse;	del_result->dn = NULL;	del_result->resultcode = result;	del_result->errormessage = (errstr?talloc_strdup(del_reply,errstr):NULL);	del_result->referral = NULL;	talloc_free(local_ctx);	ldapsrv_queue_reply(call, del_reply);	return NT_STATUS_OK;}static NTSTATUS ldapsrv_ModifyDNRequest(struct ldapsrv_call *call){	struct ldap_ModifyDNRequest *req = &call->request->r.ModifyDNRequest;	struct ldap_Result *modifydn;	struct ldapsrv_reply *modifydn_r;	void *local_ctx;	struct ldb_context *samdb = call->conn->ldb;	struct ldb_dn *olddn, *newdn=NULL, *newrdn;	struct ldb_dn *parentdn = NULL;	const char *errstr = NULL;	int result = LDAP_SUCCESS;	int ldb_ret;	DEBUG(10, ("ModifyDNRequrest"));	DEBUGADD(10, (" dn: %s", req->dn));	DEBUGADD(10, (" newrdn: %s", req->newrdn));	local_ctx = talloc_named(call, 0, "ModifyDNRequest local memory context");	NT_STATUS_HAVE_NO_MEMORY(local_ctx);	olddn = ldb_dn_new(local_ctx, samdb, req->dn);	VALID_DN_SYNTAX(olddn, 2);	newrdn = ldb_dn_new(local_ctx, samdb, req->newrdn);	VALID_DN_SYNTAX(newrdn, 1);	DEBUG(10, ("ModifyDNRequest: olddn: [%s]\n", req->dn));	DEBUG(10, ("ModifyDNRequest: newrdn: [%s]\n", req->newrdn));	/* we can't handle the rename if we should not remove the old dn */	if (!req->deleteolddn) {		result = LDAP_UNWILLING_TO_PERFORM;		errstr = "Old RDN must be deleted";		goto reply;	}	if (req->newsuperior) {		parentdn = ldb_dn_new(local_ctx, samdb, req->newsuperior);		VALID_DN_SYNTAX(parentdn, 0);		DEBUG(10, ("ModifyDNRequest: newsuperior: [%s]\n", req->newsuperior));				if (ldb_dn_get_comp_num(parentdn) < 1) {			result = LDAP_AFFECTS_MULTIPLE_DSAS;			errstr = "Error new Superior DN invalid";			goto reply;		}	}	if (!parentdn) {		parentdn = ldb_dn_get_parent(local_ctx, olddn);		NT_STATUS_HAVE_NO_MEMORY(parentdn);	}	if ( ! ldb_dn_add_child_fmt(parentdn,				"%s=%s",				ldb_dn_get_rdn_name(newrdn),				(char *)ldb_dn_get_rdn_val(newrdn)->data)) {		result = LDAP_OTHER;		goto reply;	}	newdn = parentdn;reply:	modifydn_r = ldapsrv_init_reply(call, LDAP_TAG_ModifyDNResponse);	NT_STATUS_HAVE_NO_MEMORY(modifydn_r);	if (result == LDAP_SUCCESS) {		ldb_ret = ldb_rename(samdb, olddn, newdn);		result = map_ldb_error(samdb, ldb_ret, &errstr);	}	modifydn = &modifydn_r->msg->r.ModifyDNResponse;	modifydn->dn = NULL;	modifydn->resultcode = result;	modifydn->errormessage = (errstr?talloc_strdup(modifydn_r,errstr):NULL);	modifydn->referral = NULL;	talloc_free(local_ctx);	ldapsrv_queue_reply(call, modifydn_r);	return NT_STATUS_OK;}static NTSTATUS ldapsrv_CompareRequest(struct ldapsrv_call *call){	struct ldap_CompareRequest *req = &call->request->r.CompareRequest;	struct ldap_Result *compare;	struct ldapsrv_reply *compare_r;	void *local_ctx;	struct ldb_context *samdb = call->conn->ldb;	struct ldb_result *res = NULL;	struct ldb_dn *dn;	const char *attrs[1];	const char *errstr = NULL;	const char *filter = NULL;	int result = LDAP_SUCCESS;	int ldb_ret;	DEBUG(10, ("CompareRequest"));	DEBUGADD(10, (" dn: %s", req->dn));	local_ctx = talloc_named(call, 0, "CompareRequest local_memory_context");	NT_STATUS_HAVE_NO_MEMORY(local_ctx);	dn = ldb_dn_new(local_ctx, samdb, req->dn);	VALID_DN_SYNTAX(dn, 1);	DEBUG(10, ("CompareRequest: dn: [%s]\n", req->dn));	filter = talloc_asprintf(local_ctx, "(%s=%*s)", req->attribute, 				 (int)req->value.length, req->value.data);	NT_STATUS_HAVE_NO_MEMORY(filter);	DEBUGADD(10, ("CompareRequest: attribute: [%s]\n", filter));	attrs[0] = NULL;reply:	compare_r = ldapsrv_init_reply(call, LDAP_TAG_CompareResponse);	NT_STATUS_HAVE_NO_MEMORY(compare_r);	if (result == LDAP_SUCCESS) {		ldb_ret = ldb_search(samdb, dn, LDB_SCOPE_BASE, filter, attrs, &res);		talloc_steal(local_ctx, res);		if (ldb_ret != LDB_SUCCESS) {			result = map_ldb_error(samdb, ldb_ret, &errstr);			DEBUG(10,("CompareRequest: error: %s\n", errstr));		} else if (res->count == 0) {			DEBUG(10,("CompareRequest: doesn't matched\n"));			result = LDAP_COMPARE_FALSE;			errstr = NULL;		} else if (res->count == 1) {			DEBUG(10,("CompareRequest: matched\n"));			result = LDAP_COMPARE_TRUE;			errstr = NULL;		} else if (res->count > 1) {			result = LDAP_OTHER;			errstr = "too many objects match";			DEBUG(10,("CompareRequest: %d results: %s\n", res->count, errstr));		}	}	compare = &compare_r->msg->r.CompareResponse;	compare->dn = NULL;	compare->resultcode = result;	compare->errormessage = (errstr?talloc_strdup(compare_r,errstr):NULL);	compare->referral = NULL;	talloc_free(local_ctx);	ldapsrv_queue_reply(call, compare_r);	return NT_STATUS_OK;}static NTSTATUS ldapsrv_AbandonRequest(struct ldapsrv_call *call){/*	struct ldap_AbandonRequest *req = &call->request.r.AbandonRequest;*/	DEBUG(10, ("AbandonRequest\n"));	return NT_STATUS_OK;}NTSTATUS ldapsrv_do_call(struct ldapsrv_call *call){	int i;	struct ldap_message *msg = call->request;	/* Check for undecoded critical extensions */	for (i=0; msg->controls && msg->controls[i]; i++) {		if (!msg->controls_decoded[i] && 		    msg->controls[i]->critical) {			DEBUG(3, ("ldapsrv_do_call: Critical extension %s is not known to this server\n",				  msg->controls[i]->oid));			return ldapsrv_unwilling(call, LDAP_UNAVAILABLE_CRITICAL_EXTENSION);		}	}	switch(call->request->type) {	case LDAP_TAG_BindRequest:		return ldapsrv_BindRequest(call);	case LDAP_TAG_UnbindRequest:		return ldapsrv_UnbindRequest(call);	case LDAP_TAG_SearchRequest:		return ldapsrv_SearchRequest(call);	case LDAP_TAG_ModifyRequest:		return ldapsrv_ModifyRequest(call);	case LDAP_TAG_AddRequest:		return ldapsrv_AddRequest(call);	case LDAP_TAG_DelRequest:		return ldapsrv_DelRequest(call);	case LDAP_TAG_ModifyDNRequest:		return ldapsrv_ModifyDNRequest(call);	case LDAP_TAG_CompareRequest:		return ldapsrv_CompareRequest(call);	case LDAP_TAG_AbandonRequest:		return ldapsrv_AbandonRequest(call);	case LDAP_TAG_ExtendedRequest:		return ldapsrv_ExtendedRequest(call);	default:		return ldapsrv_unwilling(call, 2);	}}

⌨️ 快捷键说明

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