To be used in smbXsrv_open.c, for this we need a lower bound.
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
/**
allocate a new id randomly in the given range
*/
-_PUBLIC_ int idr_get_new_random(struct idr_context *idp, void *ptr, int limit)
+_PUBLIC_ int idr_get_new_random(struct idr_context *idp,
+ void *ptr,
+ int starting_id,
+ int limit)
{
int id;
then start randomly in the bottom half of the range. This can only
fail if the range is over half full, and finally fallback to any
free id */
- id = idr_get_new_above(idp, ptr, 1+(generate_random() % limit), limit);
+ id = idr_get_new_above(
+ idp, ptr, starting_id+(generate_random() % limit), limit);
if (id == -1) {
- id = idr_get_new_above(idp, ptr, 1+(generate_random()%(limit/2)), limit);
+ id = idr_get_new_above(
+ idp,
+ ptr,
+ starting_id+(generate_random()%(limit/2)),
+ limit);
}
if (id == -1) {
- id = idr_get_new_above(idp, ptr, 1, limit);
+ id = idr_get_new_above(idp, ptr, starting_id, limit);
}
return id;
/**
allocate a new id randomly in the given range
*/
-int idr_get_new_random(struct idr_context *idp, void *ptr, int limit);
+int idr_get_new_random(struct idr_context *idp,
+ void *ptr,
+ int starting_id,
+ int limit);
#endif /* _SAMBA_IDTREE_RANDOM_H_ */
state->request.dest = NULL;
}
- state->message_id = idr_get_new_random(cldap->searches.idr,
- state, UINT16_MAX);
+ state->message_id = idr_get_new_random(
+ cldap->searches.idr, state, 1, UINT16_MAX);
if (state->message_id == -1) {
tevent_req_nterror(req, NT_STATUS_INSUFFICIENT_RESOURCES);
goto post;
/* we select a random transaction id unless the user supplied one */
if (request->name_trn_id == 0) {
- id = idr_get_new_random(req->nbtsock->idr, req, UINT16_MAX);
+ id = idr_get_new_random(
+ req->nbtsock->idr, req, 1, UINT16_MAX);
} else {
if (idr_find(req->nbtsock->idr, request->name_trn_id)) goto failed;
id = idr_get_new_above(req->nbtsock->idr, req, request->name_trn_id,
id = idr_get_new_random(dce_ctx->assoc_groups_idr,
assoc_group,
+ 1,
UINT16_MAX);
if (id == -1) {
TALLOC_FREE(assoc_group);
}
id = idr_get_new_random(
- dce_ctx->assoc_groups_idr, assoc_group, UINT16_MAX);
+ dce_ctx->assoc_groups_idr, assoc_group, 1, UINT16_MAX);
if (id == -1) {
talloc_free(assoc_group);
DBG_WARNING("Out of association groups!\n");
return NULL;
}
- id = idr_get_new_random(dce_ctx->assoc_groups_idr, assoc_group, UINT16_MAX);
+ id = idr_get_new_random(
+ dce_ctx->assoc_groups_idr, assoc_group, 1, UINT16_MAX);
if (id == -1) {
talloc_free(assoc_group);
DEBUG(0,(__location__ ": Out of association groups!\n"));
if (!sess) return NULL;
sess->smb_conn = smb_conn;
- i = idr_get_new_random(smb_conn->sessions.idtree_vuid, sess, smb_conn->sessions.idtree_limit);
+ i = idr_get_new_random(
+ smb_conn->sessions.idtree_vuid,
+ sess,
+ 1,
+ smb_conn->sessions.idtree_limit);
if (i == -1) {
DEBUG(1,("ERROR! Out of connection structures\n"));
talloc_free(sess);
goto failed;
}
- i = idr_get_new_random(tcons_ctx->idtree_tid, tcon, tcons_ctx->idtree_limit);
+ i = idr_get_new_random(
+ tcons_ctx->idtree_tid, tcon, 1, tcons_ctx->idtree_limit);
if (i == -1) {
DEBUG(1,("ERROR! Out of connection structures\n"));
goto failed;