s4:dsdb - always fail if a search filter could not be parsed
[mdw/samba.git] / source4 / libcli / ldap / ldap_ildap.c
index 7b592c65ae9758666d14ec12274de10ad6a19975..8b6f8e8ddd41bfb7000b06417228f6399355b805 100644 (file)
 */
 
 #include "includes.h"
-#include "libcli/ldap/ldap.h"
+#include "libcli/ldap/libcli_ldap.h"
 #include "libcli/ldap/ldap_client.h"
 
 
 /*
   count the returned search entries
 */
-int ildap_count_entries(struct ldap_connection *conn, struct ldap_message **res)
+_PUBLIC_ int ildap_count_entries(struct ldap_connection *conn, struct ldap_message **res)
 {
        int i;
        for (i=0;res && res[i];i++) /* noop */ ;
@@ -39,7 +39,7 @@ int ildap_count_entries(struct ldap_connection *conn, struct ldap_message **res)
 /*
   perform a synchronous ldap search
 */
-NTSTATUS ildap_search_bytree(struct ldap_connection *conn, const char *basedn, 
+_PUBLIC_ NTSTATUS ildap_search_bytree(struct ldap_connection *conn, const char *basedn, 
                             int scope, struct ldb_parse_tree *tree,
                             const char * const *attrs, bool attributesonly, 
                             struct ldb_control **control_req,
@@ -69,11 +69,11 @@ NTSTATUS ildap_search_bytree(struct ldap_connection *conn, const char *basedn,
        msg->r.SearchRequest.attributesonly = attributesonly;
        msg->r.SearchRequest.tree = tree;
        msg->r.SearchRequest.num_attributes = n;
-       msg->r.SearchRequest.attributes = discard_const(attrs);
+       msg->r.SearchRequest.attributes = attrs;
        msg->controls = control_req;
 
        req = ldap_request_send(conn, msg);
-       talloc_steal(msg, req);
+       talloc_reparent(conn, msg, req);
        
        for (i=n=0;true;i++) {
                struct ldap_message *res;
@@ -112,15 +112,19 @@ NTSTATUS ildap_search_bytree(struct ldap_connection *conn, const char *basedn,
 /*
   perform a ldap search
 */
-NTSTATUS ildap_search(struct ldap_connection *conn, const char *basedn, 
+_PUBLIC_ NTSTATUS ildap_search(struct ldap_connection *conn, const char *basedn, 
                      int scope, const char *expression, 
                      const char * const *attrs, bool attributesonly, 
                      struct ldb_control **control_req,
                      struct ldb_control ***control_res,
                      struct ldap_message ***results)
 {
-       struct ldb_parse_tree *tree = ldb_parse_tree(conn, expression);
        NTSTATUS status;
+       struct ldb_parse_tree *tree = ldb_parse_tree(conn, expression);
+
+       if (tree == NULL) {
+               return NT_STATUS_INVALID_PARAMETER;
+       }
        status = ildap_search_bytree(conn, basedn, scope, tree, attrs,
                                     attributesonly, control_req,
                                     control_res, results);