/** Table fields: * Mandatory fields: * `type` TINYINT(1) * `propType` INT(10) unsigned * `oleguid` VARCHAR(255) * `mappedId` INT(10) unsigned * Optional fields: * `propId` INT(10) unsigned * `propName` VARCHAR(255) * `oom` VARCHAR(255) * `canonical` VARCHAR(255) */ static bool insert_ldif_msg(MYSQL *conn, struct ldb_message *ldif) { const char *val = ldb_msg_find_attr_as_string(ldif, "objectClass", ""); if (strlen(val) < strlen("MNID_ID")) { // It's not a valid entry, ignore it return true; } TALLOC_CTX *mem_ctx = talloc_zero(NULL, TALLOC_CTX); const char **fields = (const char **) str_list_make_empty(mem_ctx); // Optional fields add_field_from_ldif(mem_ctx, ldif, &fields, "propId", false); add_field_from_ldif(mem_ctx, ldif, &fields, "propName", false); add_field_from_ldif(mem_ctx, ldif, &fields, "oom", false); add_field_from_ldif(mem_ctx, ldif, &fields, "canonical", false); // Mandatory fields // oleguid and mappedId if (!add_field_from_ldif(mem_ctx, ldif, &fields, "oleguid", true) || !add_field_from_ldif(mem_ctx, ldif, &fields, "mappedId", true)) { return false; } // type int type; if (strcmp(val, "MNID_STRING") == 0) { type = MNID_STRING; } else if (strcmp(val, "MNID_ID") == 0) { type = MNID_ID; } else { DEBUG(0, ("Invalid objectClass %s", val)); return false; } fields = str_list_add(fields, talloc_asprintf(mem_ctx, "type=%d", type)); // propType: it could be either an integer or a constant PT_*, we have // to store it as an integer val = ldb_msg_find_attr_as_string(ldif, "propType", ""); if (strlen(val) == 0) { DEBUG(0, ("propType value hasn't been found! malformed ldif?")); return false; } int propType; if (isalpha(val[0])) { propType = mapistore_namedprops_prop_type_from_string(val); if (propType == -1) { DEBUG(0, ("Invalid propType %s", val)); return false; } } else { propType = strtol(val, NULL, 10); } fields = str_list_add(fields, talloc_asprintf(mem_ctx, "propType=%d", propType)); // Done, we have all fields on fields array char *fields_sql = str_list_join(mem_ctx, fields, ','); char *sql = talloc_asprintf(mem_ctx, "INSERT INTO " NAMEDPROPS_MYSQL_TABLE " SET %s", fields_sql); mysql_query(conn, sql); talloc_free(mem_ctx); return true; }
static int prepare_modules_line(struct ldb_context *ldb, TALLOC_CTX *mem_ctx, const struct ldb_message *rootdse_msg, struct ldb_message *msg, const char *backend_attr, const char *backend_mod, const char **backend_mod_list) { int ret; const char **backend_full_list; const char *backend_dn; char *mod_list_string; char *full_string; TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx); if (!tmp_ctx) { return ldb_oom(ldb); } if (backend_attr) { backend_dn = ldb_msg_find_attr_as_string(rootdse_msg, backend_attr, NULL); if (!backend_dn) { ldb_asprintf_errstring(ldb, "samba_dsdb_init: " "unable to read %s from %s:%s", backend_attr, ldb_dn_get_linearized(rootdse_msg->dn), ldb_errstring(ldb)); return LDB_ERR_CONSTRAINT_VIOLATION; } } else { backend_dn = "*"; } if (backend_mod) { backend_full_list = (const char **)str_list_make_single(tmp_ctx, backend_mod); } else { backend_full_list = (const char **)str_list_make_empty(tmp_ctx); } if (!backend_full_list) { talloc_free(tmp_ctx); return ldb_oom(ldb); } backend_full_list = str_list_append_const(backend_full_list, backend_mod_list); if (!backend_full_list) { talloc_free(tmp_ctx); return ldb_oom(ldb); } mod_list_string = str_list_join(tmp_ctx, backend_full_list, ','); if (!mod_list_string) { talloc_free(tmp_ctx); return ldb_oom(ldb); } full_string = talloc_asprintf(tmp_ctx, "%s:%s", backend_dn, mod_list_string); ret = ldb_msg_add_steal_string(msg, "modules", full_string); talloc_free(tmp_ctx); return ret; }
static enum mapistore_error create_id(struct namedprops_context *self, struct MAPINAMEID nameid, uint16_t mapped_id) { TALLOC_CTX *mem_ctx = talloc_zero(NULL, TALLOC_CTX); const char **fields = (const char **) str_list_make_empty(mem_ctx); fields = str_list_add(fields, talloc_asprintf(mem_ctx, "type=%d", nameid.ulKind)); fields = str_list_add(fields, talloc_asprintf(mem_ctx, "propType=%d", PT_NULL)); char *guid = GUID_string(mem_ctx, &nameid.lpguid); fields = str_list_add(fields, talloc_asprintf(mem_ctx, "oleguid='%s'", guid)); fields = str_list_add(fields, talloc_asprintf(mem_ctx, "mappedId=%u", mapped_id)); if (nameid.ulKind == MNID_ID) { fields = str_list_add(fields, talloc_asprintf(mem_ctx, "propId=%u", nameid.kind.lid)); } else if (nameid.ulKind == MNID_STRING) { fields = str_list_add(fields, talloc_asprintf(mem_ctx, "propName='%s'", nameid.kind.lpwstr.Name)); } else { MAPISTORE_RETVAL_IF(true, MAPISTORE_ERROR, mem_ctx); } char *fields_sql = str_list_join(mem_ctx, fields, ','); char *sql = talloc_asprintf(mem_ctx, "INSERT INTO " NAMEDPROPS_MYSQL_TABLE " SET %s", fields_sql); DEBUG(5, ("Inserting record:\n%s\n", sql)); MYSQL *conn = self->data; if (mysql_query(conn, sql) != 0) { MAPISTORE_RETVAL_IF(true, MAPISTORE_ERR_DATABASE_OPS, mem_ctx); } talloc_free(mem_ctx); return MAPISTORE_SUCCESS; }
ldb_asprintf_errstring(ldb, "samba_dsdb_init: " "unable to read %s from %s:%s", backend_attr, ldb_dn_get_linearized(rootdse_msg->dn), ldb_errstring(ldb)); return LDB_ERR_CONSTRAINT_VIOLATION; } } else { backend_dn = "*"; } if (backend_mod) { char **b = str_list_make_single(tmp_ctx, backend_mod); backend_full_list = discard_const_p(const char *, b); } else { char **b = str_list_make_empty(tmp_ctx); backend_full_list = discard_const_p(const char *, b); } if (!backend_full_list) { talloc_free(tmp_ctx); return ldb_oom(ldb); } backend_full_list = str_list_append_const(backend_full_list, backend_mod_list); if (!backend_full_list) { talloc_free(tmp_ctx); return ldb_oom(ldb); } mod_list_string = str_list_join(tmp_ctx, backend_full_list, ','); if (!mod_list_string) {
static bool test_search_rootDSE(struct ldap_connection *conn, const char **basedn, const char ***partitions) { bool ret = true; struct ldap_message *msg, *result; struct ldap_request *req; int i; struct ldap_SearchResEntry *r; NTSTATUS status; printf("Testing RootDSE Search\n"); *basedn = NULL; if (partitions != NULL) { *partitions = const_str_list(str_list_make_empty(conn)); } msg = new_ldap_message(conn); if (!msg) { return false; } msg->type = LDAP_TAG_SearchRequest; msg->r.SearchRequest.basedn = ""; msg->r.SearchRequest.scope = LDAP_SEARCH_SCOPE_BASE; msg->r.SearchRequest.deref = LDAP_DEREFERENCE_NEVER; msg->r.SearchRequest.timelimit = 0; msg->r.SearchRequest.sizelimit = 0; msg->r.SearchRequest.attributesonly = false; msg->r.SearchRequest.tree = ldb_parse_tree(msg, "(objectclass=*)"); msg->r.SearchRequest.num_attributes = 0; msg->r.SearchRequest.attributes = NULL; req = ldap_request_send(conn, msg); if (req == NULL) { printf("Could not setup ldap search\n"); return false; } status = ldap_result_one(req, &result, LDAP_TAG_SearchResultEntry); if (!NT_STATUS_IS_OK(status)) { printf("search failed - %s\n", nt_errstr(status)); return false; } printf("received %d replies\n", req->num_replies); r = &result->r.SearchResultEntry; DEBUG(1,("\tdn: %s\n", r->dn)); for (i=0; i<r->num_attributes; i++) { int j; for (j=0; j<r->attributes[i].num_values; j++) { DEBUG(1,("\t%s: %d %.*s\n", r->attributes[i].name, (int)r->attributes[i].values[j].length, (int)r->attributes[i].values[j].length, (char *)r->attributes[i].values[j].data)); if (!(*basedn) && strcasecmp("defaultNamingContext",r->attributes[i].name)==0) { *basedn = talloc_asprintf(conn, "%.*s", (int)r->attributes[i].values[j].length, (char *)r->attributes[i].values[j].data); } if ((partitions != NULL) && (strcasecmp("namingContexts", r->attributes[i].name) == 0)) { char *entry = talloc_asprintf(conn, "%.*s", (int)r->attributes[i].values[j].length, (char *)r->attributes[i].values[j].data); *partitions = str_list_add(*partitions, entry); } } } return ret; }