[SCM] Samba Shared Repository - branch master updated -
release-4-0-0alpha6-305-ga5e570b
Simo Sorce
idra at samba.org
Sun Feb 1 01:02:18 GMT 2009
The branch, master has been updated
via a5e570b56205f64fd330f0ac1fda9884a5ea8311 (commit)
from 5f13710ced2565355c3cdcef04067cacdf74a9ad (commit)
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit a5e570b56205f64fd330f0ac1fda9884a5ea8311
Author: Simo Sorce <idra at samba.org>
Date: Sat Jan 31 20:00:15 2009 -0500
Start restoring the sqlite3 backend
Passes many tests but not all yet.
-----------------------------------------------------------------------
Summary of changes:
source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c | 677 +++++++++++++++--------------
1 files changed, 357 insertions(+), 320 deletions(-)
Changeset truncated at 500 lines:
diff --git a/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c b/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c
index 39a77a5..8acbac4 100644
--- a/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c
+++ b/source4/lib/ldb/ldb_sqlite3/ldb_sqlite3.c
@@ -1,23 +1,23 @@
-/*
+/*
ldb database library
-
+
Copyright (C) Derrell Lipman 2005
- Copyright (C) Simo Sorce 2005-2006
-
+ Copyright (C) Simo Sorce 2005-2009
+
** NOTE! The following LGPL license applies to the ldb
** library. This does NOT imply that all of Samba is released
** under the LGPL
-
+
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 3 of the License, or (at your option) any later version.
-
+
This library 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
Lesser General Public License for more details.
-
+
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
@@ -50,6 +50,9 @@ struct lsql_context {
long long current_eid;
const char * const * attrs;
struct ldb_reply *ares;
+
+ bool callback_failed;
+ struct tevent_timer *timeout_event;
};
/*
@@ -63,7 +66,8 @@ struct lsql_context {
#define RESULT_ATTR_TABLE "temp_result_attrs"
-//#define TEMPTAB /* for testing, create non-temporary table */
+
+/* for testing, define to nothing, (create non-temporary table) */
#define TEMPTAB "TEMPORARY"
/*
@@ -144,7 +148,7 @@ base160_sql(sqlite3_context * hContext,
val = sqlite3_value_int64(argv[0]);
for (i = 3; i >= 0; i--) {
-
+
result[i] = base160tab[val % 160];
val /= 160;
}
@@ -244,6 +248,7 @@ static char *parsetree_to_sql(struct ldb_module *module,
void *mem_ctx,
const struct ldb_parse_tree *t)
{
+ struct ldb_context *ldb;
const struct ldb_schema_attribute *a;
struct ldb_val value, subval;
char *wild_card_string;
@@ -252,6 +257,7 @@ static char *parsetree_to_sql(struct ldb_module *module,
char *attr;
int i;
+ ldb = ldb_module_get_ctx(module);
switch(t->operation) {
case LDB_OP_AND:
@@ -271,7 +277,7 @@ static char *parsetree_to_sql(struct ldb_module *module,
ret = talloc_asprintf(mem_ctx, "SELECT * FROM ( %s )\n", tmp);
return ret;
-
+
case LDB_OP_OR:
tmp = parsetree_to_sql(module, mem_ctx, t->u.list.elements[0]);
@@ -304,10 +310,10 @@ static char *parsetree_to_sql(struct ldb_module *module,
*/
attr = ldb_attr_casefold(mem_ctx, t->u.equality.attr);
if (attr == NULL) return NULL;
- a = ldb_schema_attribute_by_name(module->ldb, attr);
+ a = ldb_schema_attribute_by_name(ldb, attr);
/* Get a canonicalised copy of the data */
- a->syntax->canonicalise_fn(module->ldb, mem_ctx, &(t->u.equality.value), &value);
+ a->syntax->canonicalise_fn(ldb, mem_ctx, &(t->u.equality.value), &value);
if (value.data == NULL) {
return NULL;
}
@@ -315,7 +321,7 @@ static char *parsetree_to_sql(struct ldb_module *module,
if (strcasecmp(t->u.equality.attr, "dn") == 0) {
/* DN query is a special ldb case */
const char *cdn = ldb_dn_get_casefold(
- ldb_dn_new(mem_ctx, module->ldb,
+ ldb_dn_new(mem_ctx, ldb,
(const char *)value.data));
return lsqlite3_tprintf(mem_ctx,
@@ -352,13 +358,13 @@ static char *parsetree_to_sql(struct ldb_module *module,
attr = ldb_attr_casefold(mem_ctx, t->u.substring.attr);
if (attr == NULL) return NULL;
- a = ldb_schema_attribute_by_name(module->ldb, attr);
+ a = ldb_schema_attribute_by_name(ldb, attr);
subval.data = (void *)wild_card_string;
subval.length = strlen(wild_card_string) + 1;
/* Get a canonicalised copy of the data */
- a->syntax->canonicalise_fn(module->ldb, mem_ctx, &(subval), &value);
+ a->syntax->canonicalise_fn(ldb, mem_ctx, &(subval), &value);
if (value.data == NULL) {
return NULL;
}
@@ -373,10 +379,10 @@ static char *parsetree_to_sql(struct ldb_module *module,
case LDB_OP_GREATER:
attr = ldb_attr_casefold(mem_ctx, t->u.equality.attr);
if (attr == NULL) return NULL;
- a = ldb_schema_attribute_by_name(module->ldb, attr);
+ a = ldb_schema_attribute_by_name(ldb, attr);
/* Get a canonicalised copy of the data */
- a->syntax->canonicalise_fn(module->ldb, mem_ctx, &(t->u.equality.value), &value);
+ a->syntax->canonicalise_fn(ldb, mem_ctx, &(t->u.equality.value), &value);
if (value.data == NULL) {
return NULL;
}
@@ -392,10 +398,10 @@ static char *parsetree_to_sql(struct ldb_module *module,
case LDB_OP_LESS:
attr = ldb_attr_casefold(mem_ctx, t->u.equality.attr);
if (attr == NULL) return NULL;
- a = ldb_schema_attribute_by_name(module->ldb, attr);
+ a = ldb_schema_attribute_by_name(ldb, attr);
/* Get a canonicalised copy of the data */
- a->syntax->canonicalise_fn(module->ldb, mem_ctx, &(t->u.equality.value), &value);
+ a->syntax->canonicalise_fn(ldb, mem_ctx, &(t->u.equality.value), &value);
if (value.data == NULL) {
return NULL;
}
@@ -424,10 +430,10 @@ static char *parsetree_to_sql(struct ldb_module *module,
case LDB_OP_APPROX:
attr = ldb_attr_casefold(mem_ctx, t->u.equality.attr);
if (attr == NULL) return NULL;
- a = ldb_schema_attribute_by_name(module->ldb, attr);
+ a = ldb_schema_attribute_by_name(ldb, attr);
/* Get a canonicalised copy of the data */
- a->syntax->canonicalise_fn(module->ldb, mem_ctx, &(t->u.equality.value), &value);
+ a->syntax->canonicalise_fn(ldb, mem_ctx, &(t->u.equality.value), &value);
if (value.data == NULL) {
return NULL;
}
@@ -439,7 +445,7 @@ static char *parsetree_to_sql(struct ldb_module *module,
attr,
value.data,
attr);
-
+
case LDB_OP_EXTENDED:
#warning "work out how to handle bitops"
return NULL;
@@ -473,22 +479,22 @@ query_int(const struct lsqlite3_private * lsqlite3,
char * p;
sqlite3_stmt * pStmt;
va_list args;
-
+
/* Begin access to variable argument list */
va_start(args, pSql);
-
+
/* Format the query */
if ((p = sqlite3_vmprintf(pSql, args)) == NULL) {
return SQLITE_NOMEM;
}
-
+
/*
* Prepare and execute the SQL statement. Loop allows retrying on
* certain errors, e.g. SQLITE_SCHEMA occurs if the schema changes,
* requiring retrying the operation.
*/
for (bLoop = TRUE; bLoop; ) {
-
+
/* Compile the SQL statement into sqlite virtual machine */
if ((ret = sqlite3_prepare(lsqlite3->sqlite,
p,
@@ -503,7 +509,7 @@ query_int(const struct lsqlite3_private * lsqlite3,
} else if (ret != SQLITE_OK) {
break;
}
-
+
/* One row expected */
if ((ret = sqlite3_step(pStmt)) == SQLITE_SCHEMA) {
if (stmtGetEID != NULL) {
@@ -516,10 +522,10 @@ query_int(const struct lsqlite3_private * lsqlite3,
(void) sqlite3_finalize(pStmt);
break;
}
-
+
/* Get the value to be returned */
*pRet = sqlite3_column_int64(pStmt, 0);
-
+
/* Free the virtual machine */
if ((ret = sqlite3_finalize(pStmt)) == SQLITE_SCHEMA) {
if (stmtGetEID != NULL) {
@@ -531,21 +537,21 @@ query_int(const struct lsqlite3_private * lsqlite3,
(void) sqlite3_finalize(pStmt);
break;
}
-
+
/*
* Normal condition is only one time through loop. Loop is
* rerun in error conditions, via "continue", above.
*/
bLoop = FALSE;
}
-
+
/* All done with variable argument list */
va_end(args);
-
+
/* Free the memory we allocated for our query string */
sqlite3_free(p);
-
+
return ret;
}
@@ -574,9 +580,9 @@ static void lsqlite3_compare(sqlite3_context *ctx, int argc,
/* greater */
case '>': /* >= */
a = ldb_schema_attribute_by_name(ldb, attr);
- valX.data = (void *)cmp;
+ valX.data = (uint8_t *)cmp;
valX.length = strlen(cmp);
- valY.data = (void *)val;
+ valY.data = (uint8_t *)val;
valY.length = strlen(val);
ret = a->syntax->comparison_fn(ldb, ldb, &valY, &valX);
if (ret >= 0)
@@ -588,9 +594,9 @@ static void lsqlite3_compare(sqlite3_context *ctx, int argc,
/* lesser */
case '<': /* <= */
a = ldb_schema_attribute_by_name(ldb, attr);
- valX.data = (void *)cmp;
+ valX.data = (uint8_t *)cmp;
valX.length = strlen(cmp);
- valY.data = (void *)val;
+ valY.data = (uint8_t *)val;
valY.length = strlen(val);
ret = a->syntax->comparison_fn(ldb, ldb, &valY, &valX);
if (ret <= 0)
@@ -656,49 +662,52 @@ static int lsqlite3_eid_callback(void *result, int col_num, char **cols, char **
*/
static int lsqlite3_search_callback(void *result, int col_num, char **cols, char **names)
{
- struct ldb_handle *handle = talloc_get_type(result, struct ldb_handle);
- struct lsql_context *ac = talloc_get_type(handle->private_data, struct lsql_context);
+ struct ldb_context *ldb;
+ struct lsql_context *ac;
struct ldb_message *msg;
long long eid;
- int i;
+ int i, ret;
+
+ ac = talloc_get_type(result, struct lsql_context);
+ ldb = ldb_module_get_ctx(ac->module);
/* eid, dn, attr_name, attr_value */
- if (col_num != 4)
- return SQLITE_ABORT;
+ if (col_num != 4) return SQLITE_ABORT;
eid = atoll(cols[0]);
+ if (ac->ares) {
+ msg = ac->ares->message;
+ }
+
if (eid != ac->current_eid) { /* here begin a new entry */
/* call the async callback for the last entry
* except the first time */
if (ac->current_eid != 0) {
- ac->ares->message = ldb_msg_canonicalize(ac->module->ldb, ac->ares->message);
- if (ac->ares->message == NULL)
- return SQLITE_ABORT;
-
- handle->status = ac->callback(ac->module->ldb, ac->context, ac->ares);
- if (handle->status != LDB_SUCCESS)
+ msg = ldb_msg_canonicalize(ldb, msg);
+ if (!msg) return SQLITE_ABORT;
+
+ ret = ldb_module_send_entry(ac->req, msg, NULL);
+ if (ret != LDB_SUCCESS) {
+ ac->callback_failed = true;
return SQLITE_ABORT;
+ }
}
/* start over */
ac->ares = talloc_zero(ac, struct ldb_reply);
- if (!ac->ares)
- return SQLITE_ABORT;
+ if (!ac->ares) return SQLITE_ABORT;
- ac->ares->message = ldb_msg_new(ac->ares);
- if (!ac->ares->message)
- return SQLITE_ABORT;
+ msg = ldb_msg_new(ac->ares);
+ if (!msg) return SQLITE_ABORT;
ac->ares->type = LDB_REPLY_ENTRY;
ac->current_eid = eid;
}
- msg = ac->ares->message;
-
if (msg->dn == NULL) {
- msg->dn = ldb_dn_new(msg, ac->module->ldb, cols[1]);
+ msg->dn = ldb_dn_new(msg, ldb, cols[1]);
if (msg->dn == NULL)
return SQLITE_ABORT;
}
@@ -711,13 +720,15 @@ static int lsqlite3_search_callback(void *result, int col_num, char **cols, char
break;
}
}
- if (!found) return SQLITE_OK;
+ if (!found) goto done;
}
if (ldb_msg_add_string(msg, cols[2], cols[3]) != 0) {
return SQLITE_ABORT;
}
+done:
+ ac->ares->message = msg;
return SQLITE_OK;
}
@@ -755,10 +766,10 @@ static long long lsqlite3_get_eid_ndn(sqlite3 *sqlite, void *mem_ctx, const char
return eid;
}
-static long long lsqlite3_get_eid(struct ldb_module *module, struct ldb_dn *dn)
+static long long lsqlite3_get_eid(struct lsqlite3_private *lsqlite3,
+ struct ldb_dn *dn)
{
TALLOC_CTX *local_ctx;
- struct lsqlite3_private *lsqlite3 = module->private_data;
long long eid = -1;
char *cdn;
@@ -788,38 +799,44 @@ done:
*/
/* search for matching records, by tree */
-int lsql_search(struct ldb_module *module, struct ldb_request *req)
+int lsql_search(struct lsql_context *ctx)
{
- struct lsqlite3_private *lsqlite3 = talloc_get_type(module->private_data, struct lsqlite3_private);
- struct lsql_context *lsql_ac;
+ struct ldb_module *module = ctx->module;
+ struct ldb_request *req = ctx->req;
+ struct lsqlite3_private *lsqlite3;
+ struct ldb_context *ldb;
char *norm_basedn;
char *sqlfilter;
char *errmsg;
char *query = NULL;
int ret;
- lsql_ac = talloc_get_type(req->handle->private_data, struct lsql_context);
+ ldb = ldb_module_get_ctx(module);
+ lsqlite3 = talloc_get_type(ldb_module_get_private(module),
+ struct lsqlite3_private);
- if ((( ! ldb_dn_is_valid(req->op.search.base)) || ldb_dn_is_null(req->op.search.base)) &&
- (req->op.search.scope == LDB_SCOPE_BASE || req->op.search.scope == LDB_SCOPE_ONELEVEL))
+ if ((( ! ldb_dn_is_valid(req->op.search.base)) ||
+ ldb_dn_is_null(req->op.search.base)) &&
+ (req->op.search.scope == LDB_SCOPE_BASE ||
+ req->op.search.scope == LDB_SCOPE_ONELEVEL)) {
return LDB_ERR_OPERATIONS_ERROR;
+ }
if (req->op.search.base) {
- norm_basedn = ldb_dn_alloc_casefold(lsql_ac, req->op.search.base);
+ norm_basedn = ldb_dn_alloc_casefold(ctx, req->op.search.base);
if (norm_basedn == NULL) {
- ret = LDB_ERR_INVALID_DN_SYNTAX;
- goto failed;
+ return LDB_ERR_OPERATIONS_ERROR;
}
- } else norm_basedn = talloc_strdup(lsql_ac, "");
+ } else norm_basedn = talloc_strdup(ctx, "");
/* Convert filter into a series of SQL conditions (constraints) */
- sqlfilter = parsetree_to_sql(module, lsql_ac, req->op.search.tree);
-
+ sqlfilter = parsetree_to_sql(module, ctx, req->op.search.tree);
+
switch(req->op.search.scope) {
case LDB_SCOPE_DEFAULT:
case LDB_SCOPE_SUBTREE:
if (*norm_basedn != '\0') {
- query = lsqlite3_tprintf(lsql_ac,
+ query = lsqlite3_tprintf(ctx,
"SELECT entry.eid,\n"
" entry.dn,\n"
" av.attr_name,\n"
@@ -843,7 +860,7 @@ int lsql_search(struct ldb_module *module, struct ldb_request *req)
norm_basedn,
sqlfilter);
} else {
- query = lsqlite3_tprintf(lsql_ac,
+ query = lsqlite3_tprintf(ctx,
"SELECT entry.eid,\n"
" entry.dn,\n"
" av.attr_name,\n"
@@ -865,9 +882,9 @@ int lsql_search(struct ldb_module *module, struct ldb_request *req)
}
break;
-
+
case LDB_SCOPE_BASE:
- query = lsqlite3_tprintf(lsql_ac,
+ query = lsqlite3_tprintf(ctx,
"SELECT entry.eid,\n"
" entry.dn,\n"
" av.attr_name,\n"
@@ -889,9 +906,9 @@ int lsql_search(struct ldb_module *module, struct ldb_request *req)
norm_basedn,
sqlfilter);
break;
-
+
case LDB_SCOPE_ONELEVEL:
- query = lsqlite3_tprintf(lsql_ac,
+ query = lsqlite3_tprintf(ctx,
"SELECT entry.eid,\n"
" entry.dn,\n"
" av.attr_name,\n"
@@ -917,113 +934,108 @@ int lsql_search(struct ldb_module *module, struct ldb_request *req)
}
if (query == NULL) {
- goto failed;
+ return LDB_ERR_OPERATIONS_ERROR;
}
/* * /
printf ("%s\n", query);
/ * */
- lsql_ac->current_eid = 0;
- lsql_ac->attrs = req->op.search.attrs;
- lsql_ac->ares = NULL;
+ ctx->current_eid = 0;
+ ctx->attrs = req->op.search.attrs;
+ ctx->ares = NULL;
- req->handle->state = LDB_ASYNC_PENDING;
+ ldb_request_set_state(req, LDB_ASYNC_PENDING);
- ret = sqlite3_exec(lsqlite3->sqlite, query, lsqlite3_search_callback, req->handle, &errmsg);
+ ret = sqlite3_exec(lsqlite3->sqlite, query, lsqlite3_search_callback, ctx, &errmsg);
if (ret != SQLITE_OK) {
if (errmsg) {
- ldb_set_errstring(module->ldb, errmsg);
+ ldb_set_errstring(ldb, errmsg);
free(errmsg);
}
- goto failed;
+ return LDB_ERR_OPERATIONS_ERROR;
}
--
Samba Shared Repository
More information about the samba-cvs
mailing list