tevent_req_error(req, ret);
return;
}
+ /*
+ * We need to limit the number of workers in order
+ * to put the worker index into a 16-bit space,
+ * in order to use a 16-bit association group space
+ * per worker.
+ */
+ if (state->num_workers > 65536) {
+ state->num_workers = 65536;
+ }
state->idle_seconds = smb_strtoul(
lines[1], NULL, 10, &ret, SMB_STR_FULL_STR_CONV);
* All workers are busy. We need to expand the number of
* workers because we were asked for an idle worker.
*/
- if (num_workers+1 < num_workers) {
+ if (num_workers >= UINT16_MAX) {
+ /*
+ * The worker index would not fix into 16-bits
+ */
return NULL;
}
tmp = talloc_realloc(
if (assoc_group_id != 0) {
size_t num_workers = talloc_array_length(server->workers);
- uint8_t worker_index = assoc_group_id >> 24;
+ uint16_t worker_index = assoc_group_id >> 16;
if (worker_index >= num_workers) {
DBG_DEBUG("Invalid assoc group id %"PRIu32"\n",
worker = &server->workers[worker_index];
if ((worker->pid == -1) || !worker->available) {
- DBG_DEBUG("Requested worker index %"PRIu8": "
+ DBG_DEBUG("Requested worker index %"PRIu16": "
"pid=%d, available=%d\n",
worker_index,
(int)worker->pid,
void *id_ptr = NULL;
/* find an association group given a assoc_group_id */
- id_ptr = idr_find(conn->dce_ctx->assoc_groups_idr, id & 0xffffff);
+ id_ptr = idr_find(conn->dce_ctx->assoc_groups_idr, id & UINT16_MAX);
if (id_ptr == NULL) {
DBG_NOTICE("Failed to find assoc_group 0x%08x\n", id);
return NULL;
ret = idr_remove(
assoc_group->dce_ctx->assoc_groups_idr,
- assoc_group->id & 0xffffff);
+ assoc_group->id & UINT16_MAX);
if (ret != 0) {
DBG_WARNING("Failed to remove assoc_group 0x%08x\n",
assoc_group->id);
allocate a new association group
*/
static struct dcesrv_assoc_group *rpc_worker_assoc_group_new(
- struct dcesrv_connection *conn, uint8_t worker_index)
+ struct dcesrv_connection *conn, uint16_t worker_index)
{
struct dcesrv_context *dce_ctx = conn->dce_ctx;
const struct dcesrv_endpoint *endpoint = conn->endpoint;
return NULL;
}
+ /*
+ * We use 16-bit to encode the worker index,
+ * have 16-bits left within the worker to form a
+ * 32-bit association group id.
+ */
id = idr_get_new_random(
dce_ctx->assoc_groups_idr, assoc_group, 1, UINT16_MAX);
if (id == -1) {
DBG_WARNING("Out of association groups!\n");
return NULL;
}
- assoc_group->id = (worker_index << 24) + id;
+ assoc_group->id = (((uint32_t)worker_index) << 16) | id;
assoc_group->transport = transport;
assoc_group->dce_ctx = dce_ctx;
uint32_t assoc_group_id = call->pkt.u.bind.assoc_group_id;
if (assoc_group_id != 0) {
- uint8_t worker_index = (assoc_group_id & 0xff000000) >> 24;
+ uint16_t worker_index = (assoc_group_id & 0xffff0000) >> 16;
if (worker_index != w->status.worker_index) {
- DBG_DEBUG("Wrong worker id %"PRIu8", "
- "expected %"PRIu8"\n",
+ DBG_DEBUG("Wrong worker id %"PRIu16", "
+ "expected %"PRIu32"\n",
worker_index,
w->status.worker_index);
return NT_STATUS_NOT_FOUND;
tevent_req_error(req, EINVAL);
return tevent_req_post(req, ev);
}
- if ((worker_index < 0) || ((unsigned)worker_index > UINT32_MAX)) {
+ if ((worker_index < 0) || ((unsigned)worker_index > UINT16_MAX)) {
DBG_ERR("Invalid worker index %d\n", worker_index);
tevent_req_error(req, EINVAL);
return tevent_req_post(req, ev);