Ignore:
Timestamp:
Nov 27, 2012, 4:43:17 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: updated trunk to 3.6.0

Location:
trunk/server
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/server

  • trunk/server/source4/lib/ldb/modules/asq.c

    r414 r745  
    3333 */
    3434
     35#include "replace.h"
     36#include "system/filesys.h"
     37#include "system/time.h"
    3538#include "ldb_module.h"
    3639
     
    5659
    5760        struct ldb_request **reqs;
    58         int num_reqs;
    59         int cur_req;
     61        unsigned int num_reqs;
     62        unsigned int cur_req;
    6063
    6164        struct ldb_control **controls;
     
    8689{
    8790        struct ldb_asq_control *asq;
    88         int i;
     91        unsigned int i;
    8992
    9093        if (ac->controls) {
     
    238241                                        ac->req);
    239242        if (ret != LDB_SUCCESS) {
    240                 return LDB_ERR_OPERATIONS_ERROR;
     243                return ret;
    241244        }
    242245
     
    251254        struct ldb_dn *dn;
    252255        struct ldb_message_element *el;
    253         int ret, i;
     256        unsigned int i;
     257        int ret;
    254258
    255259        if (ac->base_res == NULL) {
     
    293297                                                ac->req);
    294298                if (ret != LDB_SUCCESS) {
    295                         return LDB_ERR_OPERATIONS_ERROR;
     299                        return ret;
    296300                }
    297301
    298302                /* remove the ASQ control itself */
    299303                control = ldb_request_get_control(ac->req, LDB_CONTROL_ASQ_OID);
    300                 if (!save_controls(control, ac->reqs[i], &saved_controls)) {
     304                if (!ldb_save_controls(control, ac->reqs[i], &saved_controls)) {
    301305                        return LDB_ERR_OPERATIONS_ERROR;
    302306                }
     
    400404}
    401405
    402 const struct ldb_module_ops ldb_asq_module_ops = {
     406static const struct ldb_module_ops ldb_asq_module_ops = {
    403407        .name              = "asq",
    404408        .search            = asq_search,
    405409        .init_context      = asq_init
    406410};
     411
     412int ldb_asq_init(const char *version)
     413{
     414        LDB_MODULE_CHECK_VERSION(version);
     415        return ldb_register_module(&ldb_asq_module_ops);
     416}
  • trunk/server/source4/lib/ldb/modules/paged_results.c

    r414 r745  
    3333 */
    3434
    35 #include "ldb_includes.h"
     35#include "replace.h"
     36#include "system/filesys.h"
     37#include "system/time.h"
    3638#include "ldb_module.h"
    3739
     
    6668
    6769struct private_data {
    68 
    69         int next_free_id;
     70        unsigned int next_free_id;
    7071        struct results_store *store;
    7172       
     
    9697{
    9798        struct results_store *newr;
    98         int new_id = priv->next_free_id++;
     99        unsigned int new_id = priv->next_free_id++;
    99100
    100101        /* TODO: we should have a limit on the number of
     
    141142        struct ldb_paged_control *paged;
    142143        struct message_store *msg;
    143         int i, num_ctrls, ret;
     144        unsigned int i, num_ctrls;
     145        int ret;
    144146
    145147        if (ac->store == NULL) {
     
    327329        ac->req = req;
    328330        ac->size = paged_ctrl->size;
     331        if (ac->size < 0) {
     332                /* apparently some clients send more than 2^31. This
     333                   violates the ldap standard, but we need to cope */
     334                ac->size = 0x7FFFFFFF;
     335        }
    329336
    330337        /* check if it is a continuation search the store */
     
    348355                                                paged_search_callback,
    349356                                                req);
     357                if (ret != LDB_SUCCESS) {
     358                        return ret;
     359                }
    350360
    351361                /* save it locally and remove it from the list */
    352362                /* we do not need to replace them later as we
    353363                 * are keeping the original req intact */
    354                 if (!save_controls(control, search_req, &saved_controls)) {
     364                if (!ldb_save_controls(control, search_req, &saved_controls)) {
    355365                        return LDB_ERR_OPERATIONS_ERROR;
    356366                }
     
    416426}
    417427
    418 const struct ldb_module_ops ldb_paged_results_module_ops = {
     428static const struct ldb_module_ops ldb_paged_results_module_ops = {
    419429        .name           = "paged_results",
    420430        .search         = paged_search,
    421431        .init_context   = paged_request_init
    422432};
     433
     434int ldb_paged_results_init(const char *version)
     435{
     436        LDB_MODULE_CHECK_VERSION(version);
     437        return ldb_register_module(&ldb_paged_results_module_ops);
     438}
  • trunk/server/source4/lib/ldb/modules/paged_searches.c

    r414 r745  
    3434 */
    3535
    36 #include "includes.h"
     36#include "replace.h"
     37#include "system/filesys.h"
     38#include "system/time.h"
    3739#include "ldb_module.h"
    3840
     
    5355
    5456        char **saved_referrals;
    55         int num_referrals;
     57        unsigned int num_referrals;
    5658
    5759        struct ldb_request *down_req;
     
    7981                        return LDB_ERR_OPERATIONS_ERROR;
    8082                } else {
    81                         /* No cookie recived yet, valid to just return the full data set */
     83                        /* No cookie received yet, valid to just return the full data set */
    8284
    8385                        /* we are done */
     
    133135        struct ldb_reply *ares;
    134136        int ret;
    135         int i;
     137        unsigned int i;
    136138
    137139        for (i = 0; i < ac->num_referrals; i++) {
     
    271273                                        ps_callback,
    272274                                        ac->req);
     275        LDB_REQ_SET_LOCATION(ac->down_req);
    273276        if (ret != LDB_SUCCESS) {
    274277                return ret;
     
    352355                                   data, check_supported_paged,
    353356                                   NULL);
     357        LDB_REQ_SET_LOCATION(req);
    354358        if (ret != LDB_SUCCESS) {
    355359                return ret;
     
    370374}
    371375
    372 _PUBLIC_ const struct ldb_module_ops ldb_paged_searches_module_ops = {
     376static const struct ldb_module_ops ldb_paged_searches_module_ops = {
    373377        .name           = "paged_searches",
    374378        .search         = ps_search,
    375379        .init_context   = ps_init
    376380};
     381
     382int ldb_paged_searches_init(const char *version)
     383{
     384        LDB_MODULE_CHECK_VERSION(version);
     385        return ldb_register_module(&ldb_paged_searches_module_ops);
     386}
  • trunk/server/source4/lib/ldb/modules/rdn_name.c

    r414 r745  
    22   ldb database library
    33
    4    Copyright (C) Andrew Bartlett 2005
     4   Copyright (C) Andrew Bartlett 2005-2009
    55   Copyright (C) Simo Sorce 2006-2008
    66
     
    3737 */
    3838
    39 #include "ldb_includes.h"
     39#include "replace.h"
     40#include "system/filesys.h"
     41#include "system/time.h"
    4042#include "ldb_module.h"
    4143
    4244struct rename_context {
    43 
    4445        struct ldb_module *module;
    4546        struct ldb_request *req;
     
    4748        struct ldb_reply *ares;
    4849};
    49 
    50 static struct ldb_message_element *rdn_name_find_attribute(const struct ldb_message *msg, const char *name)
    51 {
    52         int i;
    53 
    54         for (i = 0; i < msg->num_elements; i++) {
    55                 if (ldb_attr_cmp(name, msg->elements[i].name) == 0) {
    56                         return &msg->elements[i];
    57                 }
    58         }
    59 
    60         return NULL;
    61 }
    6250
    6351static int rdn_name_add_callback(struct ldb_request *req,
     
    7260                                        LDB_ERR_OPERATIONS_ERROR);
    7361        }
     62
     63        if (ares->type == LDB_REPLY_REFERRAL) {
     64                return ldb_module_send_referral(ac->req, ares->referral);
     65        }
     66
    7467        if (ares->error != LDB_SUCCESS) {
    7568                return ldb_module_done(ac->req, ares->controls,
     
    9588        const struct ldb_schema_attribute *a;
    9689        const char *rdn_name;
     90        const struct ldb_val *rdn_val_p;
    9791        struct ldb_val rdn_val;
    98         int i, ret;
     92        unsigned int i;
     93        int ret;
    9994
    10095        ldb = ldb_module_get_ctx(module);
    101         ldb_debug(ldb, LDB_DEBUG_TRACE, "rdn_name_add_record");
    10296
    10397        /* do not manipulate our control entries */
     
    121115        rdn_name = ldb_dn_get_rdn_name(msg->dn);
    122116        if (rdn_name == NULL) {
    123                 talloc_free(ac);
    124117                return LDB_ERR_OPERATIONS_ERROR;
    125118        }
    126119       
    127         rdn_val = ldb_val_dup(msg, ldb_dn_get_rdn_val(msg->dn));
    128        
    129         /* Perhaps someone above us tried to set this? */
    130         if ((attribute = rdn_name_find_attribute(msg, "name")) != NULL ) {
    131                 attribute->num_values = 0;
    132         }
    133 
    134         if (ldb_msg_add_value(msg, "name", &rdn_val, NULL) != 0) {
    135                 talloc_free(ac);
    136                 return LDB_ERR_OPERATIONS_ERROR;
    137         }
    138 
    139         attribute = rdn_name_find_attribute(msg, rdn_name);
    140 
     120        rdn_val_p = ldb_dn_get_rdn_val(msg->dn);
     121        if (rdn_val_p == NULL) {
     122                return LDB_ERR_OPERATIONS_ERROR;
     123        }
     124        if (rdn_val_p->length == 0) {
     125                ldb_asprintf_errstring(ldb, "Empty RDN value on %s not permitted!",
     126                                       ldb_dn_get_linearized(req->op.add.message->dn));
     127                return LDB_ERR_INVALID_DN_SYNTAX;
     128        }
     129        rdn_val = ldb_val_dup(msg, rdn_val_p);
     130
     131        /* Perhaps someone above us tried to set this? Then ignore it */
     132        ldb_msg_remove_attr(msg, "name");
     133
     134        ret = ldb_msg_add_value(msg, "name", &rdn_val, NULL);
     135        if (ret != LDB_SUCCESS) {
     136                return ret;
     137        }
     138
     139        a = ldb_schema_attribute_by_name(ldb, rdn_name);
     140        if (a == NULL) {
     141                return LDB_ERR_OPERATIONS_ERROR;
     142        }
     143
     144        attribute = ldb_msg_find_element(msg, rdn_name);
    141145        if (!attribute) {
    142                 if (ldb_msg_add_value(msg, rdn_name, &rdn_val, NULL) != 0) {
    143                         talloc_free(ac);
    144                         return LDB_ERR_OPERATIONS_ERROR;
     146                /* add entry with normalised RDN information if possible */
     147                if (a->name != NULL) {
     148                        ret = ldb_msg_add_value(msg, a->name, &rdn_val, NULL);
     149                } else {
     150                        ret = ldb_msg_add_value(msg, rdn_name, &rdn_val, NULL);
     151                }
     152                if (ret != LDB_SUCCESS) {
     153                        return ret;
    145154                }
    146155        } else {
    147                 a = ldb_schema_attribute_by_name(ldb, rdn_name);
    148 
     156                /* normalise attribute name if possible */
     157                if (a->name != NULL) {
     158                        attribute->name = a->name;
     159                }
     160                /* normalise attribute value */
    149161                for (i = 0; i < attribute->num_values; i++) {
    150                         ret = a->syntax->comparison_fn(ldb, msg,
    151                                         &rdn_val, &attribute->values[i]);
    152                         if (ret == 0) {
     162                        bool matched;
     163                        if (a->syntax->operator_fn) {
     164                                ret = a->syntax->operator_fn(ldb, LDB_OP_EQUALITY, a,
     165                                                             &rdn_val, &attribute->values[i], &matched);
     166                                if (ret != LDB_SUCCESS) return ret;
     167                        } else {
     168                                matched = (a->syntax->comparison_fn(ldb, msg,
     169                                                                    &rdn_val, &attribute->values[i]) == 0);
     170                        }
     171                        if (matched) {
    153172                                /* overwrite so it matches in case */
    154173                                attribute->values[i] = rdn_val;
     
    157176                }
    158177                if (i == attribute->num_values) {
    159                         char *rdn_errstring = talloc_asprintf(ac, "RDN mismatch on %s: %s (%.*s) should match one of:",
    160                                                           ldb_dn_get_linearized(msg->dn), rdn_name,
    161                                                           (int)rdn_val.length, (const char *)rdn_val.data);
     178                        char *rdn_errstring = talloc_asprintf(ac,
     179                                "RDN mismatch on %s: %s (%.*s) should match one of:",
     180                                ldb_dn_get_linearized(msg->dn), rdn_name,
     181                                (int)rdn_val.length, (const char *)rdn_val.data);
    162182                        for (i = 0; i < attribute->num_values; i++) {
    163                                 rdn_errstring = talloc_asprintf_append(rdn_errstring, " (%.*s)",
    164                                                                        (int)attribute->values[i].length,
    165                                                                        (const char *)attribute->values[i].data);
     183                                rdn_errstring = talloc_asprintf_append(
     184                                        rdn_errstring, " (%.*s)",
     185                                        (int)attribute->values[i].length,
     186                                        (const char *)attribute->values[i].data);
    166187                        }
    167                         ldb_debug_set(ldb, LDB_DEBUG_FATAL, "%s", rdn_errstring);
    168                         talloc_free(ac);
     188                        ldb_set_errstring(ldb, rdn_errstring);
    169189                        /* Match AD's error here */
    170190                        return LDB_ERR_INVALID_DN_SYNTAX;
     
    197217                                        LDB_ERR_OPERATIONS_ERROR);
    198218        }
     219
     220        if (ares->type == LDB_REPLY_REFERRAL) {
     221                return ldb_module_send_referral(ac->req, ares->referral);
     222        }
     223
    199224        if (ares->error != LDB_SUCCESS) {
    200225                return ldb_module_done(ac->req, ares->controls,
     
    219244        struct ldb_request *mod_req;
    220245        const char *rdn_name;
     246        const struct ldb_val *rdn_val_p;
    221247        struct ldb_val rdn_val;
    222248        struct ldb_message *msg;
     
    229255                goto error;
    230256        }
     257
     258        if (ares->type == LDB_REPLY_REFERRAL) {
     259                return ldb_module_send_referral(ac->req, ares->referral);
     260        }
     261
    231262        if (ares->error != LDB_SUCCESS) {
    232263                return ldb_module_done(ac->req, ares->controls,
     
    250281                goto error;
    251282        }
     283
    252284        rdn_name = ldb_dn_get_rdn_name(ac->req->op.rename.newdn);
    253285        if (rdn_name == NULL) {
    254286                goto error;
    255287        }
    256        
    257         rdn_val = ldb_val_dup(msg, ldb_dn_get_rdn_val(ac->req->op.rename.newdn));
    258        
     288
     289        rdn_val_p = ldb_dn_get_rdn_val(msg->dn);
     290        if (rdn_val_p == NULL) {
     291                goto error;
     292        }
     293        if (rdn_val_p->length == 0) {
     294                ldb_asprintf_errstring(ldb, "Empty RDN value on %s not permitted!",
     295                                       ldb_dn_get_linearized(req->op.rename.olddn));
     296                return ldb_module_done(ac->req, NULL, NULL,
     297                                       LDB_ERR_NAMING_VIOLATION);
     298        }
     299        rdn_val = ldb_val_dup(msg, rdn_val_p);
     300
    259301        if (ldb_msg_add_empty(msg, rdn_name, LDB_FLAG_MOD_REPLACE, NULL) != 0) {
    260302                goto error;
     
    279321        talloc_steal(mod_req, msg);
    280322
    281         /* do the mod call */
    282         return ldb_request(ldb, mod_req);
     323        /* go on with the call chain */
     324        return ldb_next_request(ac->module, mod_req);
    283325
    284326error:
    285         return ldb_module_done(ac->req, NULL, NULL,
    286                                                 LDB_ERR_OPERATIONS_ERROR);
     327        return ldb_module_done(ac->req, NULL, NULL, LDB_ERR_OPERATIONS_ERROR);
    287328}
    288329
     
    295336
    296337        ldb = ldb_module_get_ctx(module);
    297         ldb_debug(ldb, LDB_DEBUG_TRACE, "rdn_name_rename");
    298338
    299339        /* do not manipulate our control entries */
     
    321361
    322362        if (ret != LDB_SUCCESS) {
    323                 return LDB_ERR_OPERATIONS_ERROR;
     363                return ret;
    324364        }
    325365
     
    328368}
    329369
    330 const struct ldb_module_ops ldb_rdn_name_module_ops = {
     370static int rdn_name_modify(struct ldb_module *module, struct ldb_request *req)
     371{
     372        struct ldb_context *ldb;
     373        const struct ldb_val *rdn_val_p;
     374
     375        ldb = ldb_module_get_ctx(module);
     376
     377        /* do not manipulate our control entries */
     378        if (ldb_dn_is_special(req->op.mod.message->dn)) {
     379                return ldb_next_request(module, req);
     380        }
     381
     382        rdn_val_p = ldb_dn_get_rdn_val(req->op.mod.message->dn);
     383        if (rdn_val_p == NULL) {
     384                return LDB_ERR_OPERATIONS_ERROR;
     385        }
     386        if (rdn_val_p->length == 0) {
     387                ldb_asprintf_errstring(ldb, "Empty RDN value on %s not permitted!",
     388                                       ldb_dn_get_linearized(req->op.mod.message->dn));
     389                return LDB_ERR_INVALID_DN_SYNTAX;
     390        }
     391
     392        if (ldb_msg_find_element(req->op.mod.message, "distinguishedName")) {
     393                ldb_asprintf_errstring(ldb, "Modify of 'distinguishedName' on %s not permitted, must use 'rename' operation instead",
     394                                       ldb_dn_get_linearized(req->op.mod.message->dn));
     395                return LDB_ERR_CONSTRAINT_VIOLATION;
     396        }
     397
     398        if (ldb_msg_find_element(req->op.mod.message, "name")) {
     399                ldb_asprintf_errstring(ldb, "Modify of 'name' on %s not permitted, must use 'rename' operation instead",
     400                                       ldb_dn_get_linearized(req->op.mod.message->dn));
     401                return LDB_ERR_NOT_ALLOWED_ON_RDN;
     402        }
     403
     404        if (ldb_msg_find_element(req->op.mod.message, ldb_dn_get_rdn_name(req->op.mod.message->dn))) {
     405                ldb_asprintf_errstring(ldb, "Modify of RDN '%s' on %s not permitted, must use 'rename' operation instead",
     406                                       ldb_dn_get_rdn_name(req->op.mod.message->dn), ldb_dn_get_linearized(req->op.mod.message->dn));
     407                return LDB_ERR_NOT_ALLOWED_ON_RDN;
     408        }
     409
     410        /* All OK, they kept their fingers out of the special attributes */
     411        return ldb_next_request(module, req);
     412}
     413
     414static int rdn_name_search(struct ldb_module *module, struct ldb_request *req)
     415{
     416        struct ldb_context *ldb;
     417        const char *rdn_name;
     418        const struct ldb_val *rdn_val_p;
     419
     420        ldb = ldb_module_get_ctx(module);
     421
     422        /* do not manipulate our control entries */
     423        if (ldb_dn_is_special(req->op.search.base)) {
     424                return ldb_next_request(module, req);
     425        }
     426
     427        rdn_name = ldb_dn_get_rdn_name(req->op.search.base);
     428        rdn_val_p = ldb_dn_get_rdn_val(req->op.search.base);
     429        if ((rdn_name != NULL) && (rdn_val_p == NULL)) {
     430                return LDB_ERR_OPERATIONS_ERROR;
     431        }
     432        if ((rdn_val_p != NULL) && (rdn_val_p->length == 0)) {
     433                ldb_asprintf_errstring(ldb, "Empty RDN value on %s not permitted!",
     434                                       ldb_dn_get_linearized(req->op.search.base));
     435                return LDB_ERR_INVALID_DN_SYNTAX;
     436        }
     437
     438        return ldb_next_request(module, req);
     439}
     440
     441static const struct ldb_module_ops ldb_rdn_name_module_ops = {
    331442        .name              = "rdn_name",
    332443        .add               = rdn_name_add,
     444        .modify            = rdn_name_modify,
    333445        .rename            = rdn_name_rename,
     446        .search            = rdn_name_search
    334447};
     448
     449int ldb_rdn_name_init(const char *version)
     450{
     451        LDB_MODULE_CHECK_VERSION(version);
     452        return ldb_register_module(&ldb_rdn_name_module_ops);
     453}
  • trunk/server/source4/lib/ldb/modules/skel.c

    r414 r745  
    1 /* 
     1/*
    22   ldb database library
    33
     
    77     ** library. This does NOT imply that all of Samba is released
    88     ** under the LGPL
    9    
     9
    1010   This library is free software; you can redistribute it and/or
    1111   modify it under the terms of the GNU Lesser General Public
     
    3232 */
    3333
     34#include "replace.h"
     35#include "system/filesys.h"
     36#include "system/time.h"
    3437#include "ldb_module.h"
    3538
     
    124127}
    125128
    126 const struct ldb_module_ops ldb_skel_module_ops = {
     129static const struct ldb_module_ops ldb_skel_module_ops = {
    127130        .name              = "skel",
    128131        .init_context      = skel_init,
     
    137140        .del_transaction   = skel_del_trans,
    138141};
     142
     143int ldb_skel_init(const char *version)
     144{
     145        LDB_MODULE_CHECK_VERSION(version);
     146        return ldb_register_module(&ldb_skel_module_ops);
     147}
  • trunk/server/source4/lib/ldb/modules/sort.c

    r414 r745  
    3232 */
    3333
     34#include "replace.h"
     35#include "system/filesys.h"
     36#include "system/time.h"
    3437#include "ldb_module.h"
    3538
     
    4548        struct ldb_module *module;
    4649
    47         char *attributeName;
    48         char *orderingRule;
     50        const char *attributeName;
     51        const char *orderingRule;
    4952        int reverse;
    5053
     
    5255        struct ldb_message **msgs;
    5356        char **referrals;
    54         int num_msgs;
    55         int num_refs;
     57        unsigned int num_msgs;
     58        unsigned int num_refs;
    5659
    5760        const struct ldb_schema_attribute *a;
     
    6366        struct ldb_control **controls;
    6467        struct ldb_sort_resp_control *resp;
    65         int i;
     68        unsigned int i;
    6669
    6770        if (*ctrls) {
     
    138141        struct ldb_context *ldb;
    139142        struct ldb_reply *ares;
    140         int i, ret;
     143        unsigned int i;
     144        int ret;
    141145
    142146        ldb = ldb_module_get_ctx(ac->module);
     
    145149        ac->sort_result = 0;
    146150
    147         ldb_qsort(ac->msgs, ac->num_msgs,
    148                   sizeof(struct ldb_message *),
    149                   ac, (ldb_qsort_cmp_fn_t)sort_compare);
     151        LDB_TYPESAFE_QSORT(ac->msgs, ac->num_msgs, ac, sort_compare);
    150152
    151153        if (ac->sort_result != LDB_SUCCESS) {
     
    316318                                        req);
    317319        if (ret != LDB_SUCCESS) {
    318                 return LDB_ERR_OPERATIONS_ERROR;
     320                return ret;
    319321        }
    320322
     
    322324        /* we do not need to replace them later as we
    323325         * are keeping the original req intact */
    324         if (!save_controls(control, down_req, &saved_controls)) {
     326        if (!ldb_save_controls(control, down_req, &saved_controls)) {
    325327                return LDB_ERR_OPERATIONS_ERROR;
    326328        }
     
    346348}
    347349
    348 const struct ldb_module_ops ldb_server_sort_module_ops = {
     350static const struct ldb_module_ops ldb_server_sort_module_ops = {
    349351        .name              = "server_sort",
    350352        .search            = server_sort_search,
    351353        .init_context      = server_sort_init
    352354};
     355
     356int ldb_server_sort_init(const char *version)
     357{
     358        LDB_MODULE_CHECK_VERSION(version);
     359        return ldb_register_module(&ldb_server_sort_module_ops);
     360}
Note: See TracChangeset for help on using the changeset viewer.