s4:dsdb - always fail if a search filter could not be parsed
[mdw/samba.git] / source4 / dsdb / samdb / ldb_modules / proxy.c
index 72b47c308d2d44953637fd544c58043848e3b003..c3f12bae3a16dd2d07ee1d19588fcb10121e4331 100644 (file)
@@ -3,22 +3,18 @@
 
    Copyright (C) Andrew Tridgell 2005
 
-     ** NOTE! The following LGPL license applies to the ldb
-     ** library. This does NOT imply that all of Samba is released
-     ** under the LGPL
+   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 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,
+   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
-   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/>.
+   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/>.
 */
 
 /*
@@ -142,7 +138,7 @@ static int load_proxy_info(struct ldb_module *module)
        ldb_set_opaque(proxy->upstream, "credentials", creds);
 
        ret = ldb_connect(proxy->upstream, url, 0, NULL);
-       if (ret != 0) {
+       if (ret != LDB_SUCCESS) {
                ldb_debug(ldb, LDB_DEBUG_FATAL, "proxy failed to connect to %s\n", url);
                goto failed;
        }
@@ -159,7 +155,7 @@ failed:
        talloc_free(proxy->newdn);
        talloc_free(proxy->upstream);
        proxy->upstream = NULL;
-       return LDB_ERR_OPERATIONS_ERROR;
+       return ldb_operr(ldb);
 }
 
 
@@ -169,7 +165,7 @@ failed:
 static void proxy_convert_blob(TALLOC_CTX *mem_ctx, struct ldb_val *v,
                               const char *oldstr, const char *newstr)
 {
-       int len1, len2, len3;
+       size_t len1, len2, len3;
        uint8_t *olddata = v->data;
        char *p = strcasestr((char *)v->data, oldstr);
 
@@ -188,7 +184,7 @@ static void proxy_convert_blob(TALLOC_CTX *mem_ctx, struct ldb_val *v,
 */
 static void proxy_convert_value(struct proxy_data *proxy, struct ldb_message *msg, struct ldb_val *v)
 {
-       int i;
+       size_t i;
 
        for (i=0;proxy->oldstr[i];i++) {
                char *p = strcasestr((char *)v->data, proxy->oldstr[i]);
@@ -205,7 +201,7 @@ static struct ldb_parse_tree *proxy_convert_tree(TALLOC_CTX *mem_ctx,
                                                 struct proxy_data *proxy,
                                                 struct ldb_parse_tree *tree)
 {
-       int i;
+       size_t i;
        char *expression = ldb_filter_from_tree(mem_ctx, tree);
 
        for (i=0;proxy->newstr[i];i++) {
@@ -229,7 +225,7 @@ static void proxy_convert_record(struct ldb_context *ldb,
                                 struct proxy_data *proxy,
                                 struct ldb_message *msg)
 {
-       int attr, v;
+       unsigned int attr, v;
 
        /* fix the message DN */
        if (ldb_dn_compare_base(proxy->olddn, msg->dn) == 0) {
@@ -311,7 +307,8 @@ static int proxy_search_bytree(struct ldb_module *module, struct ldb_request *re
        struct proxy_data *proxy = talloc_get_type(ldb_module_get_private(module), struct proxy_data);
        struct ldb_request *newreq;
        struct ldb_dn *base;
-       int ret, i;
+       unsigned int i;
+       int ret;
 
        ldb = ldb_module_get_ctx(module);
 
@@ -322,7 +319,7 @@ static int proxy_search_bytree(struct ldb_module *module, struct ldb_request *re
        }
 
        if (load_proxy_info(module) != LDB_SUCCESS) {
-               return LDB_ERR_OPERATIONS_ERROR;
+               return ldb_operr(ldb);
        }
 
        /* see if the dn is within olddn */
@@ -332,7 +329,7 @@ static int proxy_search_bytree(struct ldb_module *module, struct ldb_request *re
 
        ac = talloc(req, struct proxy_ctx);
        if (ac == NULL) {
-               return LDB_ERR_OPERATIONS_ERROR;
+               return ldb_oom(ldb);
        }
 
        ac->module = module;
@@ -342,6 +339,9 @@ static int proxy_search_bytree(struct ldb_module *module, struct ldb_request *re
 #endif
 
        newtree = proxy_convert_tree(ac, proxy, req->op.search.tree);
+       if (newtree == NULL) {
+               goto failed;
+       }
 
        /* convert the basedn of this search */
        base = ldb_dn_copy(ac, req->op.search.base);
@@ -363,7 +363,7 @@ static int proxy_search_bytree(struct ldb_module *module, struct ldb_request *re
                                      req->controls,
                                      ac, proxy_search_callback,
                                      req);
-
+       LDB_REQ_SET_LOCATION(newreq);
        /* FIXME: warning, need a real event system hooked up for this to work properly,
         *        for now this makes the module *not* ASYNC */
        ret = ldb_request(proxy->upstream, newreq);
@@ -397,7 +397,13 @@ static int proxy_request(struct ldb_module *module, struct ldb_request *req)
        }
 }
 
-_PUBLIC_ const struct ldb_module_ops ldb_proxy_module_ops = {
+static const struct ldb_module_ops ldb_proxy_module_ops = {
        .name           = "proxy",
        .request        = proxy_request
 };
+
+int ldb_proxy_module_init(const char *version)
+{
+       LDB_MODULE_CHECK_VERSION(version);
+       return ldb_register_module(&ldb_proxy_module_ops);
+}