Changeset 745 for trunk/server/source4/lib/ldb/modules
- Timestamp:
- Nov 27, 2012, 4:43:17 PM (13 years ago)
- Location:
- trunk/server
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/server
- Property svn:mergeinfo changed
/vendor/current merged: 581,587,591,594,597,600,615,618,740
- Property svn:mergeinfo changed
-
trunk/server/source4/lib/ldb/modules/asq.c
r414 r745 33 33 */ 34 34 35 #include "replace.h" 36 #include "system/filesys.h" 37 #include "system/time.h" 35 38 #include "ldb_module.h" 36 39 … … 56 59 57 60 struct ldb_request **reqs; 58 int num_reqs;59 int cur_req;61 unsigned int num_reqs; 62 unsigned int cur_req; 60 63 61 64 struct ldb_control **controls; … … 86 89 { 87 90 struct ldb_asq_control *asq; 88 int i;91 unsigned int i; 89 92 90 93 if (ac->controls) { … … 238 241 ac->req); 239 242 if (ret != LDB_SUCCESS) { 240 return LDB_ERR_OPERATIONS_ERROR;243 return ret; 241 244 } 242 245 … … 251 254 struct ldb_dn *dn; 252 255 struct ldb_message_element *el; 253 int ret, i; 256 unsigned int i; 257 int ret; 254 258 255 259 if (ac->base_res == NULL) { … … 293 297 ac->req); 294 298 if (ret != LDB_SUCCESS) { 295 return LDB_ERR_OPERATIONS_ERROR;299 return ret; 296 300 } 297 301 298 302 /* remove the ASQ control itself */ 299 303 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)) { 301 305 return LDB_ERR_OPERATIONS_ERROR; 302 306 } … … 400 404 } 401 405 402 const struct ldb_module_ops ldb_asq_module_ops = {406 static const struct ldb_module_ops ldb_asq_module_ops = { 403 407 .name = "asq", 404 408 .search = asq_search, 405 409 .init_context = asq_init 406 410 }; 411 412 int 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 33 33 */ 34 34 35 #include "ldb_includes.h" 35 #include "replace.h" 36 #include "system/filesys.h" 37 #include "system/time.h" 36 38 #include "ldb_module.h" 37 39 … … 66 68 67 69 struct private_data { 68 69 int next_free_id; 70 unsigned int next_free_id; 70 71 struct results_store *store; 71 72 … … 96 97 { 97 98 struct results_store *newr; 98 int new_id = priv->next_free_id++;99 unsigned int new_id = priv->next_free_id++; 99 100 100 101 /* TODO: we should have a limit on the number of … … 141 142 struct ldb_paged_control *paged; 142 143 struct message_store *msg; 143 int i, num_ctrls, ret; 144 unsigned int i, num_ctrls; 145 int ret; 144 146 145 147 if (ac->store == NULL) { … … 327 329 ac->req = req; 328 330 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 } 329 336 330 337 /* check if it is a continuation search the store */ … … 348 355 paged_search_callback, 349 356 req); 357 if (ret != LDB_SUCCESS) { 358 return ret; 359 } 350 360 351 361 /* save it locally and remove it from the list */ 352 362 /* we do not need to replace them later as we 353 363 * 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)) { 355 365 return LDB_ERR_OPERATIONS_ERROR; 356 366 } … … 416 426 } 417 427 418 const struct ldb_module_ops ldb_paged_results_module_ops = {428 static const struct ldb_module_ops ldb_paged_results_module_ops = { 419 429 .name = "paged_results", 420 430 .search = paged_search, 421 431 .init_context = paged_request_init 422 432 }; 433 434 int 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 34 34 */ 35 35 36 #include "includes.h" 36 #include "replace.h" 37 #include "system/filesys.h" 38 #include "system/time.h" 37 39 #include "ldb_module.h" 38 40 … … 53 55 54 56 char **saved_referrals; 55 int num_referrals;57 unsigned int num_referrals; 56 58 57 59 struct ldb_request *down_req; … … 79 81 return LDB_ERR_OPERATIONS_ERROR; 80 82 } else { 81 /* No cookie rec ived yet, valid to just return the full data set */83 /* No cookie received yet, valid to just return the full data set */ 82 84 83 85 /* we are done */ … … 133 135 struct ldb_reply *ares; 134 136 int ret; 135 int i;137 unsigned int i; 136 138 137 139 for (i = 0; i < ac->num_referrals; i++) { … … 271 273 ps_callback, 272 274 ac->req); 275 LDB_REQ_SET_LOCATION(ac->down_req); 273 276 if (ret != LDB_SUCCESS) { 274 277 return ret; … … 352 355 data, check_supported_paged, 353 356 NULL); 357 LDB_REQ_SET_LOCATION(req); 354 358 if (ret != LDB_SUCCESS) { 355 359 return ret; … … 370 374 } 371 375 372 _PUBLIC_const struct ldb_module_ops ldb_paged_searches_module_ops = {376 static const struct ldb_module_ops ldb_paged_searches_module_ops = { 373 377 .name = "paged_searches", 374 378 .search = ps_search, 375 379 .init_context = ps_init 376 380 }; 381 382 int 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 2 2 ldb database library 3 3 4 Copyright (C) Andrew Bartlett 2005 4 Copyright (C) Andrew Bartlett 2005-2009 5 5 Copyright (C) Simo Sorce 2006-2008 6 6 … … 37 37 */ 38 38 39 #include "ldb_includes.h" 39 #include "replace.h" 40 #include "system/filesys.h" 41 #include "system/time.h" 40 42 #include "ldb_module.h" 41 43 42 44 struct rename_context { 43 44 45 struct ldb_module *module; 45 46 struct ldb_request *req; … … 47 48 struct ldb_reply *ares; 48 49 }; 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 }62 50 63 51 static int rdn_name_add_callback(struct ldb_request *req, … … 72 60 LDB_ERR_OPERATIONS_ERROR); 73 61 } 62 63 if (ares->type == LDB_REPLY_REFERRAL) { 64 return ldb_module_send_referral(ac->req, ares->referral); 65 } 66 74 67 if (ares->error != LDB_SUCCESS) { 75 68 return ldb_module_done(ac->req, ares->controls, … … 95 88 const struct ldb_schema_attribute *a; 96 89 const char *rdn_name; 90 const struct ldb_val *rdn_val_p; 97 91 struct ldb_val rdn_val; 98 int i, ret; 92 unsigned int i; 93 int ret; 99 94 100 95 ldb = ldb_module_get_ctx(module); 101 ldb_debug(ldb, LDB_DEBUG_TRACE, "rdn_name_add_record");102 96 103 97 /* do not manipulate our control entries */ … … 121 115 rdn_name = ldb_dn_get_rdn_name(msg->dn); 122 116 if (rdn_name == NULL) { 123 talloc_free(ac);124 117 return LDB_ERR_OPERATIONS_ERROR; 125 118 } 126 119 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); 141 145 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; 145 154 } 146 155 } 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 */ 149 161 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) { 153 172 /* overwrite so it matches in case */ 154 173 attribute->values[i] = rdn_val; … … 157 176 } 158 177 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); 162 182 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); 166 187 } 167 ldb_debug_set(ldb, LDB_DEBUG_FATAL, "%s", rdn_errstring); 168 talloc_free(ac); 188 ldb_set_errstring(ldb, rdn_errstring); 169 189 /* Match AD's error here */ 170 190 return LDB_ERR_INVALID_DN_SYNTAX; … … 197 217 LDB_ERR_OPERATIONS_ERROR); 198 218 } 219 220 if (ares->type == LDB_REPLY_REFERRAL) { 221 return ldb_module_send_referral(ac->req, ares->referral); 222 } 223 199 224 if (ares->error != LDB_SUCCESS) { 200 225 return ldb_module_done(ac->req, ares->controls, … … 219 244 struct ldb_request *mod_req; 220 245 const char *rdn_name; 246 const struct ldb_val *rdn_val_p; 221 247 struct ldb_val rdn_val; 222 248 struct ldb_message *msg; … … 229 255 goto error; 230 256 } 257 258 if (ares->type == LDB_REPLY_REFERRAL) { 259 return ldb_module_send_referral(ac->req, ares->referral); 260 } 261 231 262 if (ares->error != LDB_SUCCESS) { 232 263 return ldb_module_done(ac->req, ares->controls, … … 250 281 goto error; 251 282 } 283 252 284 rdn_name = ldb_dn_get_rdn_name(ac->req->op.rename.newdn); 253 285 if (rdn_name == NULL) { 254 286 goto error; 255 287 } 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 259 301 if (ldb_msg_add_empty(msg, rdn_name, LDB_FLAG_MOD_REPLACE, NULL) != 0) { 260 302 goto error; … … 279 321 talloc_steal(mod_req, msg); 280 322 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); 283 325 284 326 error: 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); 287 328 } 288 329 … … 295 336 296 337 ldb = ldb_module_get_ctx(module); 297 ldb_debug(ldb, LDB_DEBUG_TRACE, "rdn_name_rename");298 338 299 339 /* do not manipulate our control entries */ … … 321 361 322 362 if (ret != LDB_SUCCESS) { 323 return LDB_ERR_OPERATIONS_ERROR;363 return ret; 324 364 } 325 365 … … 328 368 } 329 369 330 const struct ldb_module_ops ldb_rdn_name_module_ops = { 370 static 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 414 static 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 441 static const struct ldb_module_ops ldb_rdn_name_module_ops = { 331 442 .name = "rdn_name", 332 443 .add = rdn_name_add, 444 .modify = rdn_name_modify, 333 445 .rename = rdn_name_rename, 446 .search = rdn_name_search 334 447 }; 448 449 int 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 /* 2 2 ldb database library 3 3 … … 7 7 ** library. This does NOT imply that all of Samba is released 8 8 ** under the LGPL 9 9 10 10 This library is free software; you can redistribute it and/or 11 11 modify it under the terms of the GNU Lesser General Public … … 32 32 */ 33 33 34 #include "replace.h" 35 #include "system/filesys.h" 36 #include "system/time.h" 34 37 #include "ldb_module.h" 35 38 … … 124 127 } 125 128 126 const struct ldb_module_ops ldb_skel_module_ops = {129 static const struct ldb_module_ops ldb_skel_module_ops = { 127 130 .name = "skel", 128 131 .init_context = skel_init, … … 137 140 .del_transaction = skel_del_trans, 138 141 }; 142 143 int 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 32 32 */ 33 33 34 #include "replace.h" 35 #include "system/filesys.h" 36 #include "system/time.h" 34 37 #include "ldb_module.h" 35 38 … … 45 48 struct ldb_module *module; 46 49 47 c har *attributeName;48 c har *orderingRule;50 const char *attributeName; 51 const char *orderingRule; 49 52 int reverse; 50 53 … … 52 55 struct ldb_message **msgs; 53 56 char **referrals; 54 int num_msgs;55 int num_refs;57 unsigned int num_msgs; 58 unsigned int num_refs; 56 59 57 60 const struct ldb_schema_attribute *a; … … 63 66 struct ldb_control **controls; 64 67 struct ldb_sort_resp_control *resp; 65 int i;68 unsigned int i; 66 69 67 70 if (*ctrls) { … … 138 141 struct ldb_context *ldb; 139 142 struct ldb_reply *ares; 140 int i, ret; 143 unsigned int i; 144 int ret; 141 145 142 146 ldb = ldb_module_get_ctx(ac->module); … … 145 149 ac->sort_result = 0; 146 150 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); 150 152 151 153 if (ac->sort_result != LDB_SUCCESS) { … … 316 318 req); 317 319 if (ret != LDB_SUCCESS) { 318 return LDB_ERR_OPERATIONS_ERROR;320 return ret; 319 321 } 320 322 … … 322 324 /* we do not need to replace them later as we 323 325 * 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)) { 325 327 return LDB_ERR_OPERATIONS_ERROR; 326 328 } … … 346 348 } 347 349 348 const struct ldb_module_ops ldb_server_sort_module_ops = {350 static const struct ldb_module_ops ldb_server_sort_module_ops = { 349 351 .name = "server_sort", 350 352 .search = server_sort_search, 351 353 .init_context = server_sort_init 352 354 }; 355 356 int 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.