"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "source4/dsdb/samdb/ldb_modules/vlv_pagination.c" between
samba-4.12.3.tar.gz and samba-4.12.5.tar.gz

About: Samba is the standard Windows interoperability suite of programs for Linux and Unix providing secure, stable and fast file and print services for all clients using the SMB/CIFS protocol. 4.12 series.

vlv_pagination.c  (samba-4.12.3):vlv_pagination.c  (samba-4.12.5)
skipping to change at line 380 skipping to change at line 380
/* The following formula was discovered by probing Windows. */ /* The following formula was discovered by probing Windows. */
fraction = (offset - 1.0) / (denominator - 1.0); fraction = (offset - 1.0) / (denominator - 1.0);
return (int)(fraction * (n_entries - 1.0) + 0.5); return (int)(fraction * (n_entries - 1.0) + 0.5);
} }
/* vlv_results() is called when there is a valid contextID -- meaning the search /* vlv_results() is called when there is a valid contextID -- meaning the search
has been prepared earlier and saved -- or by vlv_search_callback() when a has been prepared earlier and saved -- or by vlv_search_callback() when a
search has just been completed. */ search has just been completed. */
static int vlv_results(struct vlv_context *ac) static int vlv_results(struct vlv_context *ac, struct ldb_reply *ares)
{ {
struct ldb_vlv_resp_control *vlv; struct ldb_vlv_resp_control *vlv;
unsigned int num_ctrls; unsigned int num_ctrls;
int ret, i, first_i, last_i; int ret, i, first_i, last_i;
struct ldb_vlv_req_control *vlv_details; struct ldb_vlv_req_control *vlv_details;
struct ldb_server_sort_control *sort_details; struct ldb_server_sort_control *sort_details;
int target = 0; int target = 0;
if (ac->store == NULL) { if (ac->store == NULL) {
return LDB_ERR_OPERATIONS_ERROR; ret = LDB_ERR_OPERATIONS_ERROR;
return ldb_module_done(
ac->req, ac->controls, ares->response, ret);
} }
if (ac->store->first_ref) { if (ac->store->first_ref) {
/* There is no right place to put references in the sorted /* There is no right place to put references in the sorted
results, so we send them as soon as possible. results, so we send them as soon as possible.
*/ */
ret = send_referrals(ac->store, ac->req); ret = send_referrals(ac->store, ac->req);
if (ret != LDB_SUCCESS) { if (ret != LDB_SUCCESS) {
/*
* send_referrals will have called ldb_module_done
* if there was an error.
*/
return ret; return ret;
} }
} }
vlv_details = ac->store->vlv_details; vlv_details = ac->store->vlv_details;
sort_details = ac->store->sort_details; sort_details = ac->store->sort_details;
if (ac->store->num_entries != 0) { if (ac->store->num_entries != 0) {
if (vlv_details->type == 1) { if (vlv_details->type == 1) {
target = vlv_gt_eq_to_index(ac, ac->store->results, target = vlv_gt_eq_to_index(ac, ac->store->results,
vlv_details, vlv_details,
sort_details, &ret); sort_details, &ret);
if (ret != LDB_SUCCESS) { if (ret != LDB_SUCCESS) {
return ret; return ldb_module_done(
ac->req,
ac->controls,
ares->response,
ret);
} }
} else { } else {
target = vlv_calc_real_offset(vlv_details->match.byOffset .offset, target = vlv_calc_real_offset(vlv_details->match.byOffset .offset,
vlv_details->match.byOffset .contentCount, vlv_details->match.byOffset .contentCount,
ac->store->num_entries); ac->store->num_entries);
if (target == -1) { if (target == -1) {
return LDB_ERR_OPERATIONS_ERROR; ret = LDB_ERR_OPERATIONS_ERROR;
return ldb_module_done(
ac->req,
ac->controls,
ares->response,
ret);
} }
} }
/* send the results */ /* send the results */
first_i = MAX(target - vlv_details->beforeCount, 0); first_i = MAX(target - vlv_details->beforeCount, 0);
last_i = MIN(target + vlv_details->afterCount, last_i = MIN(target + vlv_details->afterCount,
ac->store->num_entries - 1); ac->store->num_entries - 1);
for (i = first_i; i <= last_i; i++) { for (i = first_i; i <= last_i; i++) {
struct ldb_result *result = NULL; struct ldb_result *result = NULL;
struct GUID *guid = &ac->store->results[i]; struct GUID *guid = &ac->store->results[i];
ret = vlv_search_by_dn_guid(ac->module, ac, &result, guid , ret = vlv_search_by_dn_guid(ac->module, ac, &result, guid ,
ac->req->op.search.attrs); ac->req->op.search.attrs);
if (ret == LDAP_NO_SUCH_OBJECT) { if (ret == LDAP_NO_SUCH_OBJECT
/* The thing isn't there, which we quietly || result->count != 1) {
ignore and go on to send an extra one /*
instead. */ * The thing isn't there, which we quietly
* ignore and go on to send an extra one
* instead.
*
* result->count == 0 or > 1 can only
* happen if ASQ (which breaks all the
* rules) is somehow invoked (as this
* is a BASE search).
*
* (We skip the ASQ cookie for the
* GUID searches)
*/
if (last_i < ac->store->num_entries - 1) { if (last_i < ac->store->num_entries - 1) {
last_i++; last_i++;
} }
continue; continue;
} else if (ret != LDB_SUCCESS) { } else if (ret != LDB_SUCCESS) {
return ret; return ldb_module_done(
ac->req,
ac->controls,
ares->response,
ret);
} }
ret = ldb_module_send_entry(ac->req, result->msgs[0], ret = ldb_module_send_entry(ac->req, result->msgs[0],
NULL); NULL);
if (ret != LDB_SUCCESS) { if (ret != LDB_SUCCESS) {
/*
* ldb_module_send_entry will have called
* ldb_module_done if there was an error
*/
return ret; return ret;
} }
} }
} else { } else {
target = -1; target = -1;
} }
/* return result done */ /* return result done */
num_ctrls = 1; num_ctrls = 1;
i = 0; i = 0;
if (ac->store->controls != NULL) { if (ac->store->controls != NULL) {
while (ac->store->controls[i]){ while (ac->store->controls[i]){
i++; /* counting */ i++; /* counting */
} }
num_ctrls += i; num_ctrls += i;
} }
ac->controls = talloc_array(ac, struct ldb_control *, num_ctrls + 1); ac->controls = talloc_array(ac, struct ldb_control *, num_ctrls + 1);
if (ac->controls == NULL) { if (ac->controls == NULL) {
return LDB_ERR_OPERATIONS_ERROR; ret = LDB_ERR_OPERATIONS_ERROR;
return ldb_module_done(
ac->req, ac->controls, ares->response, ret);
} }
ac->controls[num_ctrls] = NULL; ac->controls[num_ctrls] = NULL;
for (i = 0; i < (num_ctrls -1); i++) { for (i = 0; i < (num_ctrls -1); i++) {
ac->controls[i] = talloc_reference(ac->controls, ac->store->contr ols[i]); ac->controls[i] = talloc_reference(ac->controls, ac->store->contr ols[i]);
} }
ac->controls[i] = talloc(ac->controls, struct ldb_control); ac->controls[i] = talloc(ac->controls, struct ldb_control);
if (ac->controls[i] == NULL) { if (ac->controls[i] == NULL) {
return LDB_ERR_OPERATIONS_ERROR; ret = LDB_ERR_OPERATIONS_ERROR;
return ldb_module_done(
ac->req, ac->controls, ares->response, ret);
} }
ac->controls[i]->oid = talloc_strdup(ac->controls[i], ac->controls[i]->oid = talloc_strdup(ac->controls[i],
LDB_CONTROL_VLV_RESP_OID); LDB_CONTROL_VLV_RESP_OID);
if (ac->controls[i]->oid == NULL) { if (ac->controls[i]->oid == NULL) {
return LDB_ERR_OPERATIONS_ERROR; ret = LDB_ERR_OPERATIONS_ERROR;
return ldb_module_done(
ac->req, ac->controls, ares->response, ret);
} }
ac->controls[i]->critical = 0; ac->controls[i]->critical = 0;
vlv = talloc(ac->controls[i], struct ldb_vlv_resp_control); vlv = talloc(ac->controls[i], struct ldb_vlv_resp_control);
if (vlv == NULL) { if (vlv == NULL) {
return LDB_ERR_OPERATIONS_ERROR; ret = LDB_ERR_OPERATIONS_ERROR;
return ldb_module_done(
ac->req, ac->controls, ares->response, ret);
} }
ac->controls[i]->data = vlv; ac->controls[i]->data = vlv;
ac->store->timestamp = time(NULL); ac->store->timestamp = time(NULL);
ac->store->contextId = ac->priv->next_free_id; ac->store->contextId = ac->priv->next_free_id;
ac->priv->next_free_id++; ac->priv->next_free_id++;
vlv->contextId = talloc_memdup(vlv, &ac->store->contextId, sizeof(uint32_ t)); vlv->contextId = talloc_memdup(vlv, &ac->store->contextId, sizeof(uint32_ t));
vlv->ctxid_len = sizeof(uint32_t); vlv->ctxid_len = sizeof(uint32_t);
vlv->vlv_result = 0; vlv->vlv_result = 0;
skipping to change at line 581 skipping to change at line 623
struct GUID, struct GUID,
store->num_entries); store->num_entries);
if (store->results == NULL) { if (store->results == NULL) {
return ldb_module_done(ac->req, NULL, NULL, return ldb_module_done(ac->req, NULL, NULL,
LDB_ERR_OPERATIONS_ERROR); LDB_ERR_OPERATIONS_ERROR);
} }
} }
store->result_array_size = store->num_entries; store->result_array_size = store->num_entries;
ac->store->controls = talloc_move(ac->store, &ares->controls); ac->store->controls = talloc_move(ac->store, &ares->controls);
ret = vlv_results(ac); ret = vlv_results(ac, ares);
if (ret != LDB_SUCCESS) {
/* vlv_results will have called ldb_module_done
* if there was an error.
*/
return ret;
}
return ldb_module_done(ac->req, ac->controls, return ldb_module_done(ac->req, ac->controls,
ares->response, ret); ares->response, ret);
} }
return LDB_SUCCESS; return LDB_SUCCESS;
} }
static int copy_search_details(struct results_store *store, static int copy_search_details(struct results_store *store,
struct ldb_vlv_req_control *vlv_ctrl, struct ldb_vlv_req_control *vlv_ctrl,
struct ldb_server_sort_control *sort_ctrl) struct ldb_server_sort_control *sort_ctrl)
skipping to change at line 673 skipping to change at line 721
new_controls = talloc_array(mem_ctx, struct ldb_control *, num_ctrls); new_controls = talloc_array(mem_ctx, struct ldb_control *, num_ctrls);
if (new_controls == NULL) { if (new_controls == NULL) {
return NULL; return NULL;
} }
for (j = 0, i = 0; i < (num_ctrls); i++) { for (j = 0, i = 0; i < (num_ctrls); i++) {
struct ldb_control *control = controls[i]; struct ldb_control *control = controls[i];
if (control->oid == NULL) { if (control->oid == NULL) {
break; break;
} }
if (strncmp(control->oid, LDB_CONTROL_VLV_REQ_OID, sizeof(LDB_CON /*
TROL_VLV_REQ_OID)) == 0 || * Do not re-use VLV, nor the server-sort, both are
strncmp(control->oid, LDB_CONTROL_SERVER_SORT_OID, sizeof(LDB * already handled here.
_CONTROL_SERVER_SORT_OID)) == 0) { */
if (strcmp(control->oid, LDB_CONTROL_VLV_REQ_OID) == 0 ||
strcmp(control->oid, LDB_CONTROL_SERVER_SORT_OID) == 0) {
continue;
}
/*
* ASQ changes everything, do not copy it down for the
* per-GUID search
*/
if (strcmp(control->oid, LDB_CONTROL_ASQ_OID) == 0) {
continue; continue;
} }
new_controls[j] = talloc_steal(new_controls, control); new_controls[j] = talloc_steal(new_controls, control);
/*
* Sadly the caller is not obliged to make this a
* proper talloc tree, so we do so here.
*/
if (control->data) {
talloc_steal(control, control->data);
}
j++; j++;
} }
new_controls[j] = NULL; new_controls[j] = NULL;
return new_controls; return new_controls;
} }
static int vlv_search(struct ldb_module *module, struct ldb_request *req) static int vlv_search(struct ldb_module *module, struct ldb_request *req)
{ {
struct ldb_context *ldb; struct ldb_context *ldb;
struct ldb_control *control; struct ldb_control *control;
skipping to change at line 814 skipping to change at line 880
return ldb_next_request(module, req); return ldb_next_request(module, req);
} }
} }
ac->store = current; ac->store = current;
ret = copy_search_details(ac->store, vlv_ctrl, sort_ctrl[0]); ret = copy_search_details(ac->store, vlv_ctrl, sort_ctrl[0]);
if (ret != LDB_SUCCESS) { if (ret != LDB_SUCCESS) {
return ret; return ret;
} }
ret = vlv_results(ac); ret = vlv_results(ac, NULL);
if (ret != LDB_SUCCESS) { if (ret != LDB_SUCCESS) {
return ldb_module_done(req, NULL, NULL, ret); return ret;
} }
return ldb_module_done(req, ac->controls, NULL, return ldb_module_done(req, ac->controls, NULL,
LDB_SUCCESS); LDB_SUCCESS);
} }
} }
static int vlv_request_init(struct ldb_module *module) static int vlv_request_init(struct ldb_module *module)
{ {
struct ldb_context *ldb; struct ldb_context *ldb;
struct private_data *data; struct private_data *data;
 End of changes. 17 change blocks. 
20 lines changed or deleted 84 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)