/* add a new record */ static isc_result_t b9_add_record(struct dlz_bind9_data *state, const char *name, struct ldb_dn *dn, struct dnsp_DnssrvRpcRecord *rec) { struct ldb_message *msg; enum ndr_err_code ndr_err; struct ldb_val v; int ret; msg = ldb_msg_new(rec); if (msg == NULL) { return ISC_R_NOMEMORY; } msg->dn = dn; ret = ldb_msg_add_string(msg, "objectClass", "dnsNode"); if (ret != LDB_SUCCESS) { return ISC_R_FAILURE; } ndr_err = ndr_push_struct_blob(&v, rec, rec, (ndr_push_flags_fn_t)ndr_push_dnsp_DnssrvRpcRecord); if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { return ISC_R_FAILURE; } ret = ldb_msg_add_value(msg, "dnsRecord", &v, NULL); if (ret != LDB_SUCCESS) { return ISC_R_FAILURE; } ret = ldb_add(state->samdb, msg); if (ret != LDB_SUCCESS) { return ISC_R_FAILURE; } return ISC_R_SUCCESS; }
static BOOL samldb_msg_add_sid(struct ldb_module *module, struct ldb_message *msg, const char *name, const struct dom_sid *sid) { struct ldb_val v; NTSTATUS status; status = ndr_push_struct_blob(&v, msg, sid, (ndr_push_flags_fn_t)ndr_push_dom_sid); if (!NT_STATUS_IS_OK(status)) { return -1; } return (ldb_msg_add_value(msg, name, &v, NULL) == 0); }
/* add a value to a message, stealing it into the 'right' place */ int ldb_msg_add_steal_value(struct ldb_message *msg, const char *attr_name, struct ldb_val *val) { int ret; struct ldb_message_element *el; ret = ldb_msg_add_value(msg, attr_name, val, &el); if (ret == LDB_SUCCESS) { talloc_steal(el->values, val->data); } return ret; }
/* add a string element to a message */ int ldb_msg_add_string(struct ldb_message *msg, const char *attr_name, const char *str) { struct ldb_val val; val.data = discard_const_p(uint8_t, str); val.length = strlen(str); if (val.length == 0) { /* allow empty strings as non-existent attributes */ return LDB_SUCCESS; } return ldb_msg_add_value(msg, attr_name, &val, NULL); }
/* * Add an objectSID in string form to the supplied message * * */ static void add_sid( struct ldb_message *msg, const char *sid_str) { struct ldb_val v; enum ndr_err_code ndr_err; struct dom_sid *sid = NULL; sid = talloc_zero(msg, struct dom_sid); assert_non_null(sid); assert_true(string_to_sid(sid, sid_str)); ndr_err = ndr_push_struct_blob(&v, msg, sid, (ndr_push_flags_fn_t)ndr_push_dom_sid); assert_true(NDR_ERR_CODE_IS_SUCCESS(ndr_err)); assert_int_equal(0, ldb_msg_add_value(msg, "objectSID", &v, NULL)); }
/** * Prepares ldb_msg to be used for updating schemaInfo value in DB */ static int dsdb_schema_info_write_prepare(struct ldb_context *ldb, struct ldb_val *schema_info_blob, TALLOC_CTX *mem_ctx, struct ldb_message **_msg) { int ldb_err; struct ldb_message *msg; struct ldb_dn *schema_dn; struct ldb_message_element *return_el; schema_dn = ldb_get_schema_basedn(ldb); if (!schema_dn) { DEBUG(0,("dsdb_schema_info_write_prepare: no schema dn present\n")); return ldb_operr(ldb); } /* prepare ldb_msg to update schemaInfo */ msg = ldb_msg_new(mem_ctx); if (msg == NULL) { return ldb_oom(ldb); } msg->dn = schema_dn; ldb_err = ldb_msg_add_value(msg, "schemaInfo", schema_info_blob, &return_el); if (ldb_err != 0) { ldb_asprintf_errstring(ldb, "dsdb_schema_info_write_prepare: ldb_msg_add_value failed - %s\n", ldb_strerror(ldb_err)); talloc_free(msg); return ldb_err; } /* mark schemaInfo element for replacement */ return_el->flags = LDB_FLAG_MOD_REPLACE; *_msg = msg; return LDB_SUCCESS; }
static struct ldb_message *reg_ldb_pack_value(struct ldb_context *ctx, TALLOC_CTX *mem_ctx, const char *name, uint32_t type, DATA_BLOB data) { struct ldb_message *msg; char *name_dup, *type_str; int ret; msg = talloc_zero(mem_ctx, struct ldb_message); if (msg == NULL) { return NULL; } name_dup = talloc_strdup(msg, name); if (name_dup == NULL) { talloc_free(msg); return NULL; } ret = ldb_msg_add_string(msg, "value", name_dup); if (ret != LDB_SUCCESS) { talloc_free(msg); return NULL; } switch (type) { case REG_SZ: case REG_EXPAND_SZ: if ((data.length > 0) && (data.data != NULL)) { struct ldb_val *val; bool ret2 = false; val = talloc_zero(msg, struct ldb_val); if (val == NULL) { talloc_free(msg); return NULL; } /* The data is provided as UTF16 string */ ret2 = convert_string_talloc(mem_ctx, CH_UTF16, CH_UTF8, (void *)data.data, data.length, (void **)&val->data, &val->length); if (ret2) { ret = ldb_msg_add_value(msg, "data", val, NULL); } else { /* workaround for non-standard data */ ret = ldb_msg_add_empty(msg, "data", LDB_FLAG_MOD_DELETE, NULL); } } else { ret = ldb_msg_add_empty(msg, "data", LDB_FLAG_MOD_DELETE, NULL); } break; case REG_DWORD: case REG_DWORD_BIG_ENDIAN: if ((data.length > 0) && (data.data != NULL)) { if (data.length == sizeof(uint32_t)) { char *conv_str; conv_str = talloc_asprintf(msg, "0x%8.8x", IVAL(data.data, 0)); if (conv_str == NULL) { talloc_free(msg); return NULL; } ret = ldb_msg_add_string(msg, "data", conv_str); } else { /* workaround for non-standard data */ talloc_free(msg); return NULL; } } else { ret = ldb_msg_add_empty(msg, "data", LDB_FLAG_MOD_DELETE, NULL); } break; case REG_QWORD: if ((data.length > 0) && (data.data != NULL)) { if (data.length == sizeof(uint64_t)) { char *conv_str; conv_str = talloc_asprintf(msg, "0x%16.16llx", (unsigned long long)BVAL(data.data, 0)); if (conv_str == NULL) { talloc_free(msg); return NULL; } ret = ldb_msg_add_string(msg, "data", conv_str); } else { /* workaround for non-standard data */ talloc_free(msg); return NULL; } } else { ret = ldb_msg_add_empty(msg, "data", LDB_FLAG_MOD_DELETE, NULL); } break; case REG_BINARY: default: if ((data.length > 0) && (data.data != NULL)) { ret = ldb_msg_add_value(msg, "data", &data, NULL); } else { ret = ldb_msg_add_empty(msg, "data", LDB_FLAG_MOD_DELETE, NULL); } break; }
WERROR dsdb_write_prefixes_from_schema_to_ldb(TALLOC_CTX *mem_ctx, struct ldb_context *ldb, const struct dsdb_schema *schema) { WERROR status; int ldb_ret; struct ldb_message *msg; struct ldb_dn *schema_dn; struct prefixMapBlob pfm_blob; struct ldb_val ndr_blob; enum ndr_err_code ndr_err; TALLOC_CTX *temp_ctx; struct drsuapi_DsReplicaOIDMapping_Ctr *ctr; schema_dn = ldb_get_schema_basedn(ldb); if (!schema_dn) { DEBUG(0,("dsdb_write_prefixes_from_schema_to_ldb: no schema dn present\n")); return WERR_FOOBAR; } temp_ctx = talloc_new(mem_ctx); W_ERROR_HAVE_NO_MEMORY(temp_ctx); /* convert schema_prefixMap to prefixMap blob */ status = dsdb_get_oid_mappings_drsuapi(schema, false, temp_ctx, &ctr); if (!W_ERROR_IS_OK(status)) { talloc_free(temp_ctx); return status; } pfm_blob.version = PREFIX_MAP_VERSION_DSDB; pfm_blob.ctr.dsdb = *ctr; ndr_err = ndr_push_struct_blob(&ndr_blob, temp_ctx, &pfm_blob, (ndr_push_flags_fn_t)ndr_push_prefixMapBlob); if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { talloc_free(temp_ctx); return WERR_FOOBAR; } /* write serialized prefixMap into LDB */ msg = ldb_msg_new(temp_ctx); if (!msg) { talloc_free(temp_ctx); return WERR_NOMEM; } msg->dn = schema_dn; ldb_ret = ldb_msg_add_value(msg, "prefixMap", &ndr_blob, NULL); if (ldb_ret != 0) { talloc_free(temp_ctx); DEBUG(0,("dsdb_write_prefixes_from_schema_to_ldb: ldb_msg_add_value failed\n")); return WERR_NOMEM; } ldb_ret = dsdb_replace(ldb, msg, DSDB_FLAG_AS_SYSTEM); talloc_free(temp_ctx); if (ldb_ret != 0) { DEBUG(0,("dsdb_write_prefixes_from_schema_to_ldb: dsdb_replace failed\n")); return WERR_FOOBAR; } return WERR_OK; }
static WERROR dsdb_convert_object_ex(struct ldb_context *ldb, const struct dsdb_schema *schema, const struct drsuapi_DsReplicaObjectListItemEx *in, const DATA_BLOB *gensec_skey, TALLOC_CTX *mem_ctx, struct dsdb_extended_replicated_object *out) { NTSTATUS nt_status; WERROR status; uint32_t i; struct ldb_message *msg; struct replPropertyMetaDataBlob *md; struct ldb_val guid_value; NTTIME whenChanged = 0; time_t whenChanged_t; const char *whenChanged_s; const char *rdn_name = NULL; const struct ldb_val *rdn_value = NULL; const struct dsdb_attribute *rdn_attr = NULL; uint32_t rdn_attid; struct drsuapi_DsReplicaAttribute *name_a = NULL; struct drsuapi_DsReplicaMetaData *name_d = NULL; struct replPropertyMetaData1 *rdn_m = NULL; struct dom_sid *sid = NULL; uint32_t rid = 0; int ret; if (!in->object.identifier) { return WERR_FOOBAR; } if (!in->object.identifier->dn || !in->object.identifier->dn[0]) { return WERR_FOOBAR; } if (in->object.attribute_ctr.num_attributes != 0 && !in->meta_data_ctr) { return WERR_FOOBAR; } if (in->object.attribute_ctr.num_attributes != in->meta_data_ctr->count) { return WERR_FOOBAR; } sid = &in->object.identifier->sid; if (sid->num_auths > 0) { rid = sid->sub_auths[sid->num_auths - 1]; } msg = ldb_msg_new(mem_ctx); W_ERROR_HAVE_NO_MEMORY(msg); msg->dn = ldb_dn_new(msg, ldb, in->object.identifier->dn); W_ERROR_HAVE_NO_MEMORY(msg->dn); rdn_name = ldb_dn_get_rdn_name(msg->dn); rdn_attr = dsdb_attribute_by_lDAPDisplayName(schema, rdn_name); if (!rdn_attr) { return WERR_FOOBAR; } rdn_attid = rdn_attr->attributeID_id; rdn_value = ldb_dn_get_rdn_val(msg->dn); msg->num_elements = in->object.attribute_ctr.num_attributes; msg->elements = talloc_array(msg, struct ldb_message_element, msg->num_elements); W_ERROR_HAVE_NO_MEMORY(msg->elements); md = talloc(mem_ctx, struct replPropertyMetaDataBlob); W_ERROR_HAVE_NO_MEMORY(md); md->version = 1; md->reserved = 0; md->ctr.ctr1.count = in->meta_data_ctr->count; md->ctr.ctr1.reserved = 0; md->ctr.ctr1.array = talloc_array(mem_ctx, struct replPropertyMetaData1, md->ctr.ctr1.count + 1); /* +1 because of the RDN attribute */ W_ERROR_HAVE_NO_MEMORY(md->ctr.ctr1.array); for (i=0; i < in->meta_data_ctr->count; i++) { struct drsuapi_DsReplicaAttribute *a; struct drsuapi_DsReplicaMetaData *d; struct replPropertyMetaData1 *m; struct ldb_message_element *e; int j; a = &in->object.attribute_ctr.attributes[i]; d = &in->meta_data_ctr->meta_data[i]; m = &md->ctr.ctr1.array[i]; e = &msg->elements[i]; for (j=0; j<a->value_ctr.num_values; j++) { status = drsuapi_decrypt_attribute(a->value_ctr.values[j].blob, gensec_skey, rid, a); W_ERROR_NOT_OK_RETURN(status); } status = dsdb_attribute_drsuapi_to_ldb(ldb, schema, a, msg->elements, e); if (!NT_STATUS_IS_OK(status) && a->value_ctr.num_values == 0) { /* w2k8-r2 occasionally sends bogus empty attributes with rubbish attribute IDs. The only think we can do is discard these */ DEBUG(0,(__location__ ": Discarding bogus empty DsReplicaAttribute with attid 0x%x\n", a->attid)); ZERO_STRUCTP(e); continue; } W_ERROR_NOT_OK_RETURN(status); m->attid = a->attid; m->version = d->version; m->originating_change_time = d->originating_change_time; m->originating_invocation_id = d->originating_invocation_id; m->originating_usn = d->originating_usn; m->local_usn = 0; if (d->originating_change_time > whenChanged) { whenChanged = d->originating_change_time; } if (a->attid == DRSUAPI_ATTRIBUTE_name) { name_a = a; name_d = d; rdn_m = &md->ctr.ctr1.array[md->ctr.ctr1.count]; } } /* delete any empty elements */ for (i=0; i < msg->num_elements; i++) { if (msg->elements[i].name == NULL) { ldb_msg_remove_element(msg, &msg->elements[i]); i--; } } if (rdn_m) { struct ldb_message_element *el; el = ldb_msg_find_element(msg, rdn_attr->lDAPDisplayName); if (!el) { ret = ldb_msg_add_value(msg, rdn_attr->lDAPDisplayName, rdn_value, NULL); if (ret != LDB_SUCCESS) { return WERR_FOOBAR; } } else { if (el->num_values != 1) { DEBUG(0,(__location__ ": Unexpected num_values=%u\n", el->num_values)); return WERR_FOOBAR; } if (!ldb_val_equal_exact(&el->values[0], rdn_value)) { DEBUG(0,(__location__ ": RDN value changed? '%*.*s' '%*.*s'\n", (int)el->values[0].length, (int)el->values[0].length, el->values[0].data, (int)rdn_value->length, (int)rdn_value->length, rdn_value->data)); return WERR_FOOBAR; } } rdn_m->attid = rdn_attid; rdn_m->version = name_d->version; rdn_m->originating_change_time = name_d->originating_change_time; rdn_m->originating_invocation_id = name_d->originating_invocation_id; rdn_m->originating_usn = name_d->originating_usn; rdn_m->local_usn = 0; md->ctr.ctr1.count++; } whenChanged_t = nt_time_to_unix(whenChanged); whenChanged_s = ldb_timestring(msg, whenChanged_t); W_ERROR_HAVE_NO_MEMORY(whenChanged_s); nt_status = GUID_to_ndr_blob(&in->object.identifier->guid, msg, &guid_value); if (!NT_STATUS_IS_OK(nt_status)) { return ntstatus_to_werror(nt_status); } out->msg = msg; out->guid_value = guid_value; out->when_changed = whenChanged_s; out->meta_data = md; return WERR_OK; }
/* remember an established session key for a netr server authentication use a simple ldb structure */ NTSTATUS schannel_store_session_key_ldb(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, struct netlogon_creds_CredentialState *creds) { struct ldb_message *msg; struct ldb_val val, seed, client_state, server_state; struct ldb_val *sid_val; char *f; char *sct; int ret; f = talloc_asprintf(mem_ctx, "%u", (unsigned int)creds->negotiate_flags); if (f == NULL) { return NT_STATUS_NO_MEMORY; } sct = talloc_asprintf(mem_ctx, "%u", (unsigned int)creds->secure_channel_type); if (sct == NULL) { return NT_STATUS_NO_MEMORY; } msg = ldb_msg_new(ldb); if (msg == NULL) { return NT_STATUS_NO_MEMORY; } msg->dn = ldb_dn_new_fmt(msg, ldb, "computerName=%s", creds->computer_name); if ( ! msg->dn) { return NT_STATUS_NO_MEMORY; } sid_val = schannel_dom_sid_ldb_val(msg, creds->sid); if (sid_val == NULL) { return NT_STATUS_NO_MEMORY; } val.data = creds->session_key; val.length = sizeof(creds->session_key); seed.data = creds->seed.data; seed.length = sizeof(creds->seed.data); client_state.data = creds->client.data; client_state.length = sizeof(creds->client.data); server_state.data = creds->server.data; server_state.length = sizeof(creds->server.data); ldb_msg_add_string(msg, "objectClass", "schannelState"); ldb_msg_add_value(msg, "sessionKey", &val, NULL); ldb_msg_add_value(msg, "seed", &seed, NULL); ldb_msg_add_value(msg, "clientState", &client_state, NULL); ldb_msg_add_value(msg, "serverState", &server_state, NULL); ldb_msg_add_string(msg, "negotiateFlags", f); ldb_msg_add_string(msg, "secureChannelType", sct); ldb_msg_add_string(msg, "accountName", creds->account_name); ldb_msg_add_string(msg, "computerName", creds->computer_name); ldb_msg_add_value(msg, "objectSid", sid_val, NULL); ret = ldb_add(ldb, msg); if (ret == LDB_ERR_ENTRY_ALREADY_EXISTS) { int i; /* from samdb_replace() */ /* mark all the message elements as LDB_FLAG_MOD_REPLACE */ for (i=0;i<msg->num_elements;i++) { msg->elements[i].flags = LDB_FLAG_MOD_REPLACE; } ret = ldb_modify(ldb, msg); } /* We don't need a transaction here, as we either add or * modify records, never delete them, so it must exist */ if (ret != LDB_SUCCESS) { DEBUG(0,("Unable to add %s to session key db - %s\n", ldb_dn_get_linearized(msg->dn), ldb_errstring(ldb))); return NT_STATUS_INTERNAL_DB_CORRUPTION; } return NT_STATUS_OK; }
WERROR dsdb_convert_object_ex(struct ldb_context *ldb, const struct dsdb_schema *schema, const struct dsdb_schema_prefixmap *pfm_remote, const struct drsuapi_DsReplicaObjectListItemEx *in, const DATA_BLOB *gensec_skey, const uint32_t *ignore_attids, uint32_t dsdb_repl_flags, TALLOC_CTX *mem_ctx, struct dsdb_extended_replicated_object *out) { NTSTATUS nt_status; WERROR status = WERR_OK; uint32_t i; struct ldb_message *msg; struct replPropertyMetaDataBlob *md; int instanceType; struct ldb_message_element *instanceType_e = NULL; struct ldb_val guid_value; struct ldb_val parent_guid_value; NTTIME whenChanged = 0; time_t whenChanged_t; const char *whenChanged_s; struct drsuapi_DsReplicaAttribute *name_a = NULL; struct drsuapi_DsReplicaMetaData *name_d = NULL; struct replPropertyMetaData1 *rdn_m = NULL; struct dom_sid *sid = NULL; uint32_t rid = 0; uint32_t attr_count; int ret; if (!in->object.identifier) { return WERR_FOOBAR; } if (!in->object.identifier->dn || !in->object.identifier->dn[0]) { return WERR_FOOBAR; } if (in->object.attribute_ctr.num_attributes != 0 && !in->meta_data_ctr) { return WERR_FOOBAR; } if (in->object.attribute_ctr.num_attributes != in->meta_data_ctr->count) { return WERR_FOOBAR; } sid = &in->object.identifier->sid; if (sid->num_auths > 0) { rid = sid->sub_auths[sid->num_auths - 1]; } msg = ldb_msg_new(mem_ctx); W_ERROR_HAVE_NO_MEMORY(msg); msg->dn = ldb_dn_new(msg, ldb, in->object.identifier->dn); W_ERROR_HAVE_NO_MEMORY(msg->dn); msg->num_elements = in->object.attribute_ctr.num_attributes; msg->elements = talloc_array(msg, struct ldb_message_element, msg->num_elements + 1); /* +1 because of the RDN attribute */ W_ERROR_HAVE_NO_MEMORY(msg->elements); md = talloc(mem_ctx, struct replPropertyMetaDataBlob); W_ERROR_HAVE_NO_MEMORY(md); md->version = 1; md->reserved = 0; md->ctr.ctr1.count = in->meta_data_ctr->count; md->ctr.ctr1.reserved = 0; md->ctr.ctr1.array = talloc_array(mem_ctx, struct replPropertyMetaData1, md->ctr.ctr1.count + 1); /* +1 because of the RDN attribute */ W_ERROR_HAVE_NO_MEMORY(md->ctr.ctr1.array); for (i=0, attr_count=0; i < in->meta_data_ctr->count; i++, attr_count++) { struct drsuapi_DsReplicaAttribute *a; struct drsuapi_DsReplicaMetaData *d; struct replPropertyMetaData1 *m; struct ldb_message_element *e; uint32_t j; a = &in->object.attribute_ctr.attributes[i]; d = &in->meta_data_ctr->meta_data[i]; m = &md->ctr.ctr1.array[attr_count]; e = &msg->elements[attr_count]; if (dsdb_attid_in_list(ignore_attids, a->attid)) { attr_count--; continue; } if (GUID_all_zero(&d->originating_invocation_id)) { status = WERR_DS_SRC_GUID_MISMATCH; DEBUG(0, ("Refusing replication of object containing invalid zero invocationID on attribute %d of %s: %s\n", a->attid, ldb_dn_get_linearized(msg->dn), win_errstr(status))); return status; } if (a->attid == DRSUAPI_ATTID_instanceType) { if (instanceType_e != NULL) { return WERR_FOOBAR; } instanceType_e = e; } for (j=0; j<a->value_ctr.num_values; j++) { status = drsuapi_decrypt_attribute(a->value_ctr.values[j].blob, gensec_skey, rid, dsdb_repl_flags, a); if (!W_ERROR_IS_OK(status)) { break; } } if (W_ERROR_EQUAL(status, WERR_TOO_MANY_SECRETS)) { WERROR get_name_status = dsdb_attribute_drsuapi_to_ldb(ldb, schema, pfm_remote, a, msg->elements, e); if (W_ERROR_IS_OK(get_name_status)) { DEBUG(0, ("Unxpectedly got secret value %s on %s from DRS server\n", e->name, ldb_dn_get_linearized(msg->dn))); } else { DEBUG(0, ("Unxpectedly got secret value on %s from DRS server", ldb_dn_get_linearized(msg->dn))); } } else if (!W_ERROR_IS_OK(status)) { return status; } status = dsdb_attribute_drsuapi_to_ldb(ldb, schema, pfm_remote, a, msg->elements, e); W_ERROR_NOT_OK_RETURN(status); m->attid = a->attid; m->version = d->version; m->originating_change_time = d->originating_change_time; m->originating_invocation_id = d->originating_invocation_id; m->originating_usn = d->originating_usn; m->local_usn = 0; if (d->originating_change_time > whenChanged) { whenChanged = d->originating_change_time; } if (a->attid == DRSUAPI_ATTID_name) { name_a = a; name_d = d; } } msg->num_elements = attr_count; md->ctr.ctr1.count = attr_count; if (name_a) { rdn_m = &md->ctr.ctr1.array[md->ctr.ctr1.count]; } if (rdn_m) { struct ldb_message_element *el; const char *rdn_name = NULL; const struct ldb_val *rdn_value = NULL; const struct dsdb_attribute *rdn_attr = NULL; uint32_t rdn_attid; /* * We only need the schema calls for the RDN in this * codepath, and by doing this we avoid needing to * have the dsdb_attribute_by_lDAPDisplayName accessor * working during the schema load. */ rdn_name = ldb_dn_get_rdn_name(msg->dn); rdn_attr = dsdb_attribute_by_lDAPDisplayName(schema, rdn_name); if (!rdn_attr) { return WERR_FOOBAR; } rdn_attid = rdn_attr->attributeID_id; rdn_value = ldb_dn_get_rdn_val(msg->dn); el = ldb_msg_find_element(msg, rdn_attr->lDAPDisplayName); if (!el) { ret = ldb_msg_add_value(msg, rdn_attr->lDAPDisplayName, rdn_value, NULL); if (ret != LDB_SUCCESS) { return WERR_FOOBAR; } } else { if (el->num_values != 1) { DEBUG(0,(__location__ ": Unexpected num_values=%u\n", el->num_values)); return WERR_FOOBAR; } if (!ldb_val_equal_exact(&el->values[0], rdn_value)) { DEBUG(0,(__location__ ": RDN value changed? '%*.*s' '%*.*s'\n", (int)el->values[0].length, (int)el->values[0].length, el->values[0].data, (int)rdn_value->length, (int)rdn_value->length, rdn_value->data)); return WERR_FOOBAR; } } rdn_m->attid = rdn_attid; rdn_m->version = name_d->version; rdn_m->originating_change_time = name_d->originating_change_time; rdn_m->originating_invocation_id = name_d->originating_invocation_id; rdn_m->originating_usn = name_d->originating_usn; rdn_m->local_usn = 0; md->ctr.ctr1.count++; } if (instanceType_e == NULL) { return WERR_FOOBAR; } instanceType = ldb_msg_find_attr_as_int(msg, "instanceType", 0); if (dsdb_repl_flags & DSDB_REPL_FLAG_PARTIAL_REPLICA) { /* the instanceType type for partial_replica replication is sent via DRS with TYPE_WRITE set, but must be used on the client with TYPE_WRITE removed */ if (instanceType & INSTANCE_TYPE_WRITE) { /* * Make sure we do not change the order * of msg->elements! * * That's why we use * instanceType_e->num_values = 0 * instead of * ldb_msg_remove_attr(msg, "instanceType"); */ struct ldb_message_element *e; e = ldb_msg_find_element(msg, "instanceType"); if (e != instanceType_e) { DEBUG(0,("instanceType_e[%p] changed to e[%p]\n", instanceType_e, e)); return WERR_FOOBAR; } instanceType_e->num_values = 0; instanceType &= ~INSTANCE_TYPE_WRITE; if (ldb_msg_add_fmt(msg, "instanceType", "%d", instanceType) != LDB_SUCCESS) { return WERR_INTERNAL_ERROR; } } } else { if (!(instanceType & INSTANCE_TYPE_WRITE)) { DEBUG(0, ("Refusing to replicate %s from a read-only repilca into a read-write replica!\n", ldb_dn_get_linearized(msg->dn))); return WERR_DS_DRA_SOURCE_IS_PARTIAL_REPLICA; } } whenChanged_t = nt_time_to_unix(whenChanged); whenChanged_s = ldb_timestring(msg, whenChanged_t); W_ERROR_HAVE_NO_MEMORY(whenChanged_s); nt_status = GUID_to_ndr_blob(&in->object.identifier->guid, msg, &guid_value); if (!NT_STATUS_IS_OK(nt_status)) { return ntstatus_to_werror(nt_status); } if (in->parent_object_guid) { nt_status = GUID_to_ndr_blob(in->parent_object_guid, msg, &parent_guid_value); if (!NT_STATUS_IS_OK(nt_status)) { return ntstatus_to_werror(nt_status); } } else { parent_guid_value = data_blob_null; } out->msg = msg; out->guid_value = guid_value; out->parent_guid_value = parent_guid_value; out->when_changed = whenChanged_s; out->meta_data = md; return WERR_OK; }
/* remember an established session key for a netr server authentication use a simple ldb structure */ NTSTATUS schannel_store_session_key_ldb(TALLOC_CTX *mem_ctx, struct ldb_context *ldb, struct creds_CredentialState *creds) { struct ldb_message *msg; struct ldb_val val, seed, client_state, server_state; char *f; char *sct; int ret; f = talloc_asprintf(mem_ctx, "%u", (unsigned int)creds->negotiate_flags); if (f == NULL) { return NT_STATUS_NO_MEMORY; } sct = talloc_asprintf(mem_ctx, "%u", (unsigned int)creds->secure_channel_type); if (sct == NULL) { return NT_STATUS_NO_MEMORY; } msg = ldb_msg_new(ldb); if (msg == NULL) { return NT_STATUS_NO_MEMORY; } msg->dn = ldb_dn_new_fmt(msg, ldb, "computerName=%s", creds->computer_name); if ( ! msg->dn) { return NT_STATUS_NO_MEMORY; } val.data = creds->session_key; val.length = sizeof(creds->session_key); seed.data = creds->seed.data; seed.length = sizeof(creds->seed.data); client_state.data = creds->client.data; client_state.length = sizeof(creds->client.data); server_state.data = creds->server.data; server_state.length = sizeof(creds->server.data); ldb_msg_add_string(msg, "objectClass", "schannelState"); ldb_msg_add_value(msg, "sessionKey", &val, NULL); ldb_msg_add_value(msg, "seed", &seed, NULL); ldb_msg_add_value(msg, "clientState", &client_state, NULL); ldb_msg_add_value(msg, "serverState", &server_state, NULL); ldb_msg_add_string(msg, "negotiateFlags", f); ldb_msg_add_string(msg, "secureChannelType", sct); ldb_msg_add_string(msg, "accountName", creds->account_name); ldb_msg_add_string(msg, "computerName", creds->computer_name); ldb_msg_add_string(msg, "flatname", creds->domain); samdb_msg_add_dom_sid(ldb, mem_ctx, msg, "objectSid", creds->sid); ldb_delete(ldb, msg->dn); ret = ldb_add(ldb, msg); if (ret != 0) { DEBUG(0,("Unable to add %s to session key db - %s\n", ldb_dn_get_linearized(msg->dn), ldb_errstring(ldb))); return NT_STATUS_INTERNAL_DB_CORRUPTION; } return NT_STATUS_OK; }
static int rdn_name_add(struct ldb_module *module, struct ldb_request *req) { struct ldb_context *ldb; struct ldb_request *down_req; struct rename_context *ac; struct ldb_message *msg; struct ldb_message_element *attribute; const struct ldb_schema_attribute *a; const char *rdn_name; struct ldb_val rdn_val; int i, ret; ldb = ldb_module_get_ctx(module); /* do not manipulate our control entries */ if (ldb_dn_is_special(req->op.add.message->dn)) { return ldb_next_request(module, req); } ac = talloc_zero(req, struct rename_context); if (ac == NULL) { return LDB_ERR_OPERATIONS_ERROR; } ac->module = module; ac->req = req; msg = ldb_msg_copy_shallow(req, req->op.add.message); if (msg == NULL) { return LDB_ERR_OPERATIONS_ERROR; } rdn_name = ldb_dn_get_rdn_name(msg->dn); if (rdn_name == NULL) { return LDB_ERR_OPERATIONS_ERROR; } rdn_val = ldb_val_dup(msg, ldb_dn_get_rdn_val(msg->dn)); /* Perhaps someone above us tried to set this? */ if ((attribute = rdn_name_find_attribute(msg, "name")) != NULL ) { attribute->num_values = 0; } if (ldb_msg_add_value(msg, "name", &rdn_val, NULL) != 0) { return LDB_ERR_OPERATIONS_ERROR; } attribute = rdn_name_find_attribute(msg, rdn_name); if (!attribute) { if (ldb_msg_add_value(msg, rdn_name, &rdn_val, NULL) != 0) { return LDB_ERR_OPERATIONS_ERROR; } } else { a = ldb_schema_attribute_by_name(ldb, rdn_name); for (i = 0; i < attribute->num_values; i++) { ret = a->syntax->comparison_fn(ldb, msg, &rdn_val, &attribute->values[i]); if (ret == 0) { /* overwrite so it matches in case */ attribute->values[i] = rdn_val; break; } } if (i == attribute->num_values) { char *rdn_errstring = talloc_asprintf(ac, "RDN mismatch on %s: %s (%.*s) should match one of:", ldb_dn_get_linearized(msg->dn), rdn_name, (int)rdn_val.length, (const char *)rdn_val.data); for (i = 0; i < attribute->num_values; i++) { rdn_errstring = talloc_asprintf_append( rdn_errstring, " (%.*s)", (int)attribute->values[i].length, (const char *)attribute->values[i].data); } ldb_set_errstring(ldb, rdn_errstring); /* Match AD's error here */ return LDB_ERR_INVALID_DN_SYNTAX; } } ret = ldb_build_add_req(&down_req, ldb, req, msg, req->controls, ac, rdn_name_add_callback, req); if (ret != LDB_SUCCESS) { return ret; } talloc_steal(down_req, msg); /* go on with the call chain */ return ldb_next_request(module, down_req); }
static int rdn_rename_callback(struct ldb_request *req, struct ldb_reply *ares) { struct ldb_context *ldb; struct rename_context *ac; struct ldb_request *mod_req; const char *rdn_name; struct ldb_val rdn_val; struct ldb_message *msg; int ret; ac = talloc_get_type(req->context, struct rename_context); ldb = ldb_module_get_ctx(ac->module); if (!ares) { goto error; } if (ares->error != LDB_SUCCESS) { return ldb_module_done(ac->req, ares->controls, ares->response, ares->error); } /* the only supported reply right now is a LDB_REPLY_DONE */ if (ares->type != LDB_REPLY_DONE) { goto error; } /* save reply for caller */ ac->ares = talloc_steal(ac, ares); msg = ldb_msg_new(ac); if (msg == NULL) { goto error; } msg->dn = ldb_dn_copy(msg, ac->req->op.rename.newdn); if (msg->dn == NULL) { goto error; } rdn_name = ldb_dn_get_rdn_name(ac->req->op.rename.newdn); if (rdn_name == NULL) { goto error; } rdn_val = ldb_val_dup(msg, ldb_dn_get_rdn_val(ac->req->op.rename.newdn)); if (ldb_msg_add_empty(msg, rdn_name, LDB_FLAG_MOD_REPLACE, NULL) != 0) { goto error; } if (ldb_msg_add_value(msg, rdn_name, &rdn_val, NULL) != 0) { goto error; } if (ldb_msg_add_empty(msg, "name", LDB_FLAG_MOD_REPLACE, NULL) != 0) { goto error; } if (ldb_msg_add_value(msg, "name", &rdn_val, NULL) != 0) { goto error; } ret = ldb_build_mod_req(&mod_req, ldb, ac, msg, NULL, ac, rdn_modify_callback, req); if (ret != LDB_SUCCESS) { return ldb_module_done(ac->req, NULL, NULL, ret); } talloc_steal(mod_req, msg); /* go on with the call chain */ return ldb_next_request(ac->module, mod_req); error: return ldb_module_done(ac->req, NULL, NULL, LDB_ERR_OPERATIONS_ERROR); }