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

📄 simple_ldap_map.c

📁 samba最新软件
💻 C
📖 第 1 页 / 共 2 页
字号:
/*    ldb database module   LDAP semantics mapping module   Copyright (C) Jelmer Vernooij 2005   Copyright (C) Andrew Bartlett <abartlet@samba.org> 2006   This program is free software; you can redistribute it and/or modify   it under the terms of the GNU General Public License as published by   the Free Software Foundation; either version 3 of the License, or   (at your option) any later version.      This program is distributed in the hope that it will be useful,   but WITHOUT ANY WARRANTY; without even the implied warranty of   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the   GNU General Public License for more details.      You should have received a copy of the GNU General Public License   along with this program.  If not, see <http://www.gnu.org/licenses/>.*//*    This module relies on ldb_map to do all the real work, but performs   some of the trivial mappings between AD semantics and that provided   by OpenLDAP and similar servers.*/#include "includes.h"#include "ldb/include/ldb.h"#include "ldb/include/ldb_private.h"#include "ldb/include/ldb_errors.h"#include "ldb/ldb_map/ldb_map.h"#include "librpc/gen_ndr/ndr_misc.h"#include "librpc/ndr/libndr.h"struct entryuuid_private {	struct ldb_dn **base_dns;};static struct ldb_val encode_guid(struct ldb_module *module, TALLOC_CTX *ctx, const struct ldb_val *val){	struct GUID guid;	NTSTATUS status = GUID_from_string((char *)val->data, &guid);	enum ndr_err_code ndr_err;	struct ldb_val out = data_blob(NULL, 0);	if (!NT_STATUS_IS_OK(status)) {		return out;	}	ndr_err = ndr_push_struct_blob(&out, ctx, NULL, &guid,				       (ndr_push_flags_fn_t)ndr_push_GUID);	if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {		return out;	}	return out;}static struct ldb_val guid_always_string(struct ldb_module *module, TALLOC_CTX *ctx, const struct ldb_val *val){	struct GUID *guid;	struct ldb_val out = data_blob(NULL, 0);	if (val->length >= 32 && val->data[val->length] == '\0') {		ldb_handler_copy(module->ldb, ctx, val, &out);	} else {		enum ndr_err_code ndr_err;		guid = talloc(ctx, struct GUID);		if (guid == NULL) {			return out;		}		ndr_err = ndr_pull_struct_blob(val, guid, NULL, guid,					       (ndr_pull_flags_fn_t)ndr_pull_GUID);		if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {			talloc_free(guid);			return out;		}		out = data_blob_string_const(GUID_string(ctx, guid));		talloc_free(guid);	}	return out;}static struct ldb_val encode_ns_guid(struct ldb_module *module, TALLOC_CTX *ctx, const struct ldb_val *val){	struct GUID guid;	NTSTATUS status = NS_GUID_from_string((char *)val->data, &guid);	enum ndr_err_code ndr_err;	struct ldb_val out = data_blob(NULL, 0);	if (!NT_STATUS_IS_OK(status)) {		return out;	}	ndr_err = ndr_push_struct_blob(&out, ctx, NULL, &guid,				       (ndr_push_flags_fn_t)ndr_push_GUID);	if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {		return out;	}	return out;}static struct ldb_val guid_ns_string(struct ldb_module *module, TALLOC_CTX *ctx, const struct ldb_val *val){	struct ldb_val out = data_blob(NULL, 0);	if (val->length >= 32 && val->data[val->length] == '\0') {		struct GUID guid;		GUID_from_string((char *)val->data, &guid);		out = data_blob_string_const(NS_GUID_string(ctx, &guid));	} else {		enum ndr_err_code ndr_err;		struct GUID *guid_p;		guid_p = talloc(ctx, struct GUID);		if (guid_p == NULL) {			return out;		}		ndr_err = ndr_pull_struct_blob(val, guid_p, NULL, guid_p,					       (ndr_pull_flags_fn_t)ndr_pull_GUID);		if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {			talloc_free(guid_p);			return out;		}		out = data_blob_string_const(NS_GUID_string(ctx, guid_p));		talloc_free(guid_p);	}	return out;}/* The backend holds binary sids, so just copy them back */static struct ldb_val val_copy(struct ldb_module *module, TALLOC_CTX *ctx, const struct ldb_val *val){	struct ldb_val out = data_blob(NULL, 0);	ldb_handler_copy(module->ldb, ctx, val, &out);	return out;}/* Ensure we always convert sids into binary, so the backend doesn't have to know about both forms */static struct ldb_val sid_always_binary(struct ldb_module *module, TALLOC_CTX *ctx, const struct ldb_val *val){	struct ldb_val out = data_blob(NULL, 0);	const struct ldb_schema_attribute *a = ldb_schema_attribute_by_name(module->ldb, "objectSid");	if (a->syntax->canonicalise_fn(module->ldb, ctx, val, &out) != LDB_SUCCESS) {		return data_blob(NULL, 0);	}	return out;}/* Ensure we always convert objectCategory into a DN */static struct ldb_val objectCategory_always_dn(struct ldb_module *module, TALLOC_CTX *ctx, const struct ldb_val *val){	struct ldb_dn *dn;	struct ldb_val out = data_blob(NULL, 0);	const struct ldb_schema_attribute *a = ldb_schema_attribute_by_name(module->ldb, "objectCategory");	dn = ldb_dn_new(ctx, module->ldb, val->data);	if (dn && ldb_dn_is_valid(dn)) {		talloc_free(dn);		return val_copy(module, ctx, val);	}	talloc_free(dn);	if (a->syntax->canonicalise_fn(module->ldb, ctx, val, &out) != LDB_SUCCESS) {		return data_blob(NULL, 0);	}	return out;}static struct ldb_val normalise_to_signed32(struct ldb_module *module, TALLOC_CTX *ctx, const struct ldb_val *val){	long long int signed_ll = strtoll((const char *)val->data, NULL, 10);	if (signed_ll >= 0x80000000LL) {		union {			int32_t signed_int;			uint32_t unsigned_int;		} u = {			.unsigned_int = strtoul((const char *)val->data, NULL, 10)		};		struct ldb_val out = data_blob_string_const(talloc_asprintf(ctx, "%d", u.signed_int));		return out;	}	return val_copy(module, ctx, val);}static struct ldb_val usn_to_entryCSN(struct ldb_module *module, TALLOC_CTX *ctx, const struct ldb_val *val){	struct ldb_val out;	unsigned long long usn = strtoull((const char *)val->data, NULL, 10);	time_t t = (usn >> 24);	out = data_blob_string_const(talloc_asprintf(ctx, "%s#%06x#00#000000", ldb_timestring(ctx, t), (unsigned int)(usn & 0xFFFFFF)));	return out;}static unsigned long long entryCSN_to_usn_int(TALLOC_CTX *ctx, const struct ldb_val *val) {	char *entryCSN = talloc_strdup(ctx, (const char *)val->data);	char *mod_per_sec;	time_t t;	unsigned long long usn;	char *p;	if (!entryCSN) {		return 0;	}	p = strchr(entryCSN, '#');	if (!p) {		return 0;	}	p[0] = '\0';	p++;	mod_per_sec = p;	p = strchr(p, '#');	if (!p) {		return 0;	}	p[0] = '\0';	p++;	usn = strtol(mod_per_sec, NULL, 16);	t = ldb_string_to_time(entryCSN);		usn = usn | ((unsigned long long)t <<24);	return usn;}static struct ldb_val entryCSN_to_usn(struct ldb_module *module, TALLOC_CTX *ctx, const struct ldb_val *val){	struct ldb_val out;	unsigned long long usn = entryCSN_to_usn_int(ctx, val);	out = data_blob_string_const(talloc_asprintf(ctx, "%lld", usn));	return out;}static struct ldb_val usn_to_timestamp(struct ldb_module *module, TALLOC_CTX *ctx, const struct ldb_val *val){	struct ldb_val out;	unsigned long long usn = strtoull((const char *)val->data, NULL, 10);	time_t t = (usn >> 24);	out = data_blob_string_const(ldb_timestring(ctx, t));	return out;}static struct ldb_val timestamp_to_usn(struct ldb_module *module, TALLOC_CTX *ctx, const struct ldb_val *val){	struct ldb_val out;	time_t t;	unsigned long long usn;	t = ldb_string_to_time((const char *)val->data);		usn = ((unsigned long long)t <<24);	out = data_blob_string_const(talloc_asprintf(ctx, "%lld", usn));	return out;}static const struct ldb_map_attribute entryuuid_attributes[] = {	/* objectGUID */	{		.local_name = "objectGUID",		.type = MAP_CONVERT,		.u = {			.convert = {				.remote_name = "entryUUID", 				.convert_local = guid_always_string,				.convert_remote = encode_guid,			},		},	},	/* invocationId */	{		.local_name = "invocationId",		.type = MAP_CONVERT,		.u = {			.convert = {				.remote_name = "invocationId", 				.convert_local = guid_always_string,				.convert_remote = encode_guid,			},		},	},	/* objectSid */	{		.local_name = "objectSid",		.type = MAP_CONVERT,		.u = {			.convert = {				.remote_name = "objectSid", 				.convert_local = sid_always_binary,				.convert_remote = val_copy,			},		},	},	{		.local_name = "name",		.type = MAP_RENAME,		.u = {			.rename = {				 .remote_name = "samba4RDN"			 }		}	},	{		.local_name = "whenCreated",		.type = MAP_RENAME,		.u = {			.rename = {				 .remote_name = "createTimestamp"			 }		}	},	{		.local_name = "whenChanged",		.type = MAP_RENAME,		.u = {			.rename = {				 .remote_name = "modifyTimestamp"			 }		}	},	{		.local_name = "objectClasses",		.type = MAP_RENAME,		.u = {			.rename = {				 .remote_name = "samba4ObjectClasses"			 }		}	},	{		.local_name = "dITContentRules",		.type = MAP_RENAME,		.u = {			.rename = {				 .remote_name = "samba4DITContentRules"			 }		}	},	{		.local_name = "attributeTypes",		.type = MAP_RENAME,		.u = {			.rename = {				 .remote_name = "samba4AttributeTypes"			 }		}	},	{		.local_name = "sambaPassword",		.type = MAP_RENAME,		.u = {			.rename = {				 .remote_name = "userPassword"			 }		}	},	{		.local_name = "objectCategory",		.type = MAP_CONVERT,		.u = {			.convert = {				.remote_name = "objectCategory", 				.convert_local = objectCategory_always_dn,				.convert_remote = val_copy,			},		},	},	{		.local_name = "distinguishedName",		.type = MAP_RENAME,		.u = {			.rename = {				 .remote_name = "entryDN"			 }		}	},	{		.local_name = "groupType",		.type = MAP_CONVERT,		.u = {			.convert = {				 .remote_name = "groupType",				 .convert_local = normalise_to_signed32,				 .convert_remote = val_copy,			 },		}	},	{		.local_name = "sAMAccountType",		.type = MAP_CONVERT,		.u = {			.convert = {				 .remote_name = "sAMAccountType",				 .convert_local = normalise_to_signed32,				 .convert_remote = val_copy,			 },		}	},	{		.local_name = "usnChanged",

⌨️ 快捷键说明

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