struct async_req *req,
void (*trigger)(struct async_req *req));
+bool _async_req_setup(TALLOC_CTX *mem_ctx, struct async_req **preq,
+ void *pstate, size_t state_size, const char *typename);
+
+#define async_req_setup(_mem_ctx, _preq, _pstate, type) \
+ _async_req_setup((_mem_ctx), (_preq), (_pstate), sizeof(type), #type)
+
+
#endif
return true;
}
+
+bool _async_req_setup(TALLOC_CTX *mem_ctx, struct async_req **preq,
+ void *pstate, size_t state_size, const char *typename)
+{
+ struct async_req *req;
+ void **ppstate = (void **)pstate;
+ void *state;
+
+ req = async_req_new(mem_ctx);
+ if (req == NULL) {
+ return false;
+ }
+ state = talloc_size(req, state_size);
+ if (state == NULL) {
+ TALLOC_FREE(req);
+ return false;
+ }
+ talloc_set_name(state, typename);
+ req->private_data = state;
+
+ *preq = req;
+ *ppstate = state;
+
+ return true;
+}
struct async_req *result;
struct async_syscall_state *state;
- result = async_req_new(mem_ctx);
- if (result == NULL) {
- return NULL;
- }
-
- state = talloc(result, struct async_syscall_state);
- if (state == NULL) {
- TALLOC_FREE(result);
+ if (!async_req_setup(mem_ctx, &result, &state,
+ struct async_syscall_state)) {
return NULL;
}
-
state->syscall_type = type;
result->private_data = state;
struct fd_event *fde;
NTSTATUS status;
- result = async_req_new(mem_ctx);
- if (result == NULL) {
+ if (!async_req_setup(mem_ctx, &result, &state,
+ struct async_connect_state)) {
return NULL;
}
- state = talloc(result, struct async_connect_state);
- if (state == NULL) {
- goto fail;
- }
- result->private_data = state;
/**
* We have to set the socket to nonblocking for async connect(2). Keep
struct open_socket_out_state *state;
NTSTATUS status;
- result = async_req_new(mem_ctx);
- if (result == NULL) {
+ if (!async_req_setup(mem_ctx, &result, &state,
+ struct open_socket_out_state)) {
return NULL;
}
- state = talloc(result, struct open_socket_out_state);
- if (state == NULL) {
- goto fail;
- }
- result->private_data = state;
-
state->ev = ev;
state->ss = *pss;
state->port = port;
struct open_socket_out_defer_state *state;
NTSTATUS status;
- result = async_req_new(mem_ctx);
- if (result == NULL) {
+ if (!async_req_setup(mem_ctx, &result, &state,
+ struct open_socket_out_defer_state)) {
return NULL;
}
- state = talloc(result, struct open_socket_out_defer_state);
- if (state == NULL) {
- goto fail;
- }
- result->private_data = state;
-
state->ev = ev;
state->ss = *pss;
state->port = port;
struct async_req *result, *subreq;
struct req_read_state *state;
- result = async_req_new(mem_ctx);
- if (result == NULL) {
+ if (!async_req_setup(mem_ctx, &result, &state,
+ struct req_read_state)) {
return NULL;
}
-
- state = talloc(result, struct req_read_state);
- if (state == NULL) {
- goto nomem;
- }
- result->private_data = state;
-
state->fd = fd;
state->ev = ev;
state->max_extra_data = max_extra_data;
struct async_req *result, *subreq;
struct req_write_state *state;
- result = async_req_new(mem_ctx);
- if (result == NULL) {
+ if (!async_req_setup(mem_ctx, &result, &state,
+ struct req_write_state)) {
return NULL;
}
-
- state = talloc(result, struct req_write_state);
- if (state == NULL) {
- goto nomem;
- }
- result->private_data = state;
-
state->fd = fd;
state->ev = ev;
state->wb_req = wb_req;
struct async_req *result, *subreq;
struct resp_read_state *state;
- result = async_req_new(mem_ctx);
- if (result == NULL) {
+ if (!async_req_setup(mem_ctx, &result, &state,
+ struct resp_read_state)) {
return NULL;
}
-
- state = talloc(result, struct resp_read_state);
- if (state == NULL) {
- goto nomem;
- }
- result->private_data = state;
-
state->fd = fd;
state->ev = ev;
state->wb_resp = talloc(state, struct winbindd_response);
struct async_req *result, *subreq;
struct resp_write_state *state;
- result = async_req_new(mem_ctx);
- if (result == NULL) {
+ if (!async_req_setup(mem_ctx, &result, &state,
+ struct resp_write_state)) {
return NULL;
}
-
- state = talloc(result, struct resp_write_state);
- if (state == NULL) {
- goto nomem;
- }
- result->private_data = state;
-
state->fd = fd;
state->ev = ev;
state->wb_resp = wb_resp;
struct async_req *subreq;
struct wb_int_trans_state *state;
- result = async_req_new(mem_ctx);
- if (result == NULL) {
+ if (!async_req_setup(mem_ctx, &result, &state,
+ struct wb_int_trans_state)) {
return NULL;
}
- state = talloc(result, struct wb_int_trans_state);
- if (state == NULL) {
- goto fail;
- }
- result->private_data = state;
if (winbind_closed_fd(fd)) {
if (!async_post_status(result, ev,
struct async_req *subreq;
struct wb_open_pipe_state *state;
- result = async_req_new(mem_ctx);
- if (result == NULL) {
+ if (!async_req_setup(mem_ctx, &result, &state,
+ struct wb_open_pipe_state)) {
return NULL;
}
- state = talloc(result, struct wb_open_pipe_state);
- if (state == NULL) {
- goto fail;
- }
- result->private_data = state;
-
state->wb_ctx = wb_ctx;
state->ev = ev;
state->need_priv = need_priv;
struct async_req *result;
struct wb_trans_state *state;
- result = async_req_new(mem_ctx);
- if (result == NULL) {
+ if (!async_req_setup(mem_ctx, &result, &state,
+ struct wb_trans_state)) {
return NULL;
}
- state = talloc(result, struct wb_trans_state);
- if (state == NULL) {
- goto fail;
- }
- result->private_data = state;
-
state->wb_ctx = wb_ctx;
state->ev = ev;
state->wb_req = winbindd_request_copy(state, wb_req);
struct cli_pull_state *state;
int i;
- result = async_req_new(mem_ctx);
- if (result == NULL) {
- goto failed;
- }
- state = talloc(result, struct cli_pull_state);
- if (state == NULL) {
- goto failed;
+ if (!async_req_setup(mem_ctx, &result, &state,
+ struct cli_pull_state)) {
+ return NULL;
}
- result->private_data = state;
result->print = cli_pull_print;
state->req = result;
struct async_req *subreq;
struct cli_writeall_state *state;
- result = async_req_new(mem_ctx);
- if (result == NULL) {
- goto fail;
- }
- state = talloc(result, struct cli_writeall_state);
- if (state == NULL) {
- goto fail;
+ if (!async_req_setup(mem_ctx, &result, &state,
+ struct cli_writeall_state)) {
+ return NULL;
}
- result->private_data = state;
-
state->ev = ev;
state->cli = cli;
state->fnum = fnum;
struct cli_push_state *state;
int i;
- result = async_req_new(mem_ctx);
- if (result == NULL) {
- goto failed;
- }
- state = talloc(result, struct cli_push_state);
- if (state == NULL) {
- goto failed;
+ if (!async_req_setup(mem_ctx, &result, &state,
+ struct cli_push_state)) {
+ return NULL;
}
- result->private_data = state;
state->req = result;
state->cli = cli;
struct async_req *result, *subreq;
struct rpc_read_state *state;
- result = async_req_new(mem_ctx);
- if (result == NULL) {
+ if (!async_req_setup(mem_ctx, &result, &state,
+ struct rpc_read_state)) {
return NULL;
}
- state = talloc(result, struct rpc_read_state);
- if (state == NULL) {
- goto fail;
- }
- result->private_data = state;
-
state->ev = ev;
state->cli = cli;
state->data = data;
struct async_req *result, *subreq;
struct rpc_write_state *state;
- result = async_req_new(mem_ctx);
- if (result == NULL) {
+ if (!async_req_setup(mem_ctx, &result, &state,
+ struct rpc_write_state)) {
return NULL;
}
- state = talloc(result, struct rpc_write_state);
- if (state == NULL) {
- goto fail;
- }
- result->private_data = state;
-
state->ev = ev;
state->cli = cli;
state->data = data;
uint32_t pdu_len;
NTSTATUS status;
- result = async_req_new(mem_ctx);
- if (result == NULL) {
+ if (!async_req_setup(mem_ctx, &result, &state,
+ struct get_complete_frag_state)) {
return NULL;
}
- state = talloc(result, struct get_complete_frag_state);
- if (state == NULL) {
- goto fail;
- }
- result->private_data = state;
-
state->ev = ev;
state->cli = cli;
state->prhdr = prhdr;
if (async_post_status(result, ev, status)) {
return result;
}
- fail:
TALLOC_FREE(result);
return NULL;
}
struct cli_api_pipe_state *state;
NTSTATUS status;
- result = async_req_new(mem_ctx);
- if (result == NULL) {
+ if (!async_req_setup(mem_ctx, &result, &state,
+ struct cli_api_pipe_state)) {
return NULL;
}
- state = talloc(result, struct cli_api_pipe_state);
- if (state == NULL) {
- goto fail;
- }
- result->private_data = state;
-
state->ev = ev;
state->cli = cli;
state->max_rdata_len = max_rdata_len;
if (async_post_status(result, ev, status)) {
return result;
}
- fail:
TALLOC_FREE(result);
return NULL;
}
uint16_t max_recv_frag;
NTSTATUS status;
- result = async_req_new(mem_ctx);
- if (result == NULL) {
+ if (!async_req_setup(mem_ctx, &result, &state,
+ struct rpc_api_pipe_state)) {
return NULL;
}
- state = talloc(result, struct rpc_api_pipe_state);
- if (state == NULL) {
- goto fail;
- }
- result->private_data = state;
-
state->ev = ev;
state->cli = cli;
state->expected_pkt_type = expected_pkt_type;
if (async_post_status(result, ev, status)) {
return result;
}
- fail:
TALLOC_FREE(result);
return NULL;
}
NTSTATUS status;
bool is_last_frag;
- result = async_req_new(mem_ctx);
- if (result == NULL) {
+ if (!async_req_setup(mem_ctx, &result, &state,
+ struct rpc_api_pipe_req_state)) {
return NULL;
}
- state = talloc(result, struct rpc_api_pipe_req_state);
- if (state == NULL) {
- goto fail;
- }
- result->private_data = state;
-
state->ev = ev;
state->cli = cli;
state->op_num = op_num;
if (async_post_status(result, ev, status)) {
return result;
}
- fail:
TALLOC_FREE(result);
return NULL;
}
struct rpc_pipe_bind_state *state;
NTSTATUS status;
- result = async_req_new(mem_ctx);
- if (result == NULL) {
+ if (!async_req_setup(mem_ctx, &result, &state,
+ struct rpc_pipe_bind_state)) {
return NULL;
}
- state = talloc(result, struct rpc_pipe_bind_state);
- if (state == NULL) {
- goto fail;
- }
- result->private_data = state;
DEBUG(5,("Bind RPC Pipe: %s auth_type %u, auth_level %u\n",
rpccli_pipe_txt(debug_ctx(), cli),
if (async_post_status(result, ev, status)) {
return result;
}
- fail:
TALLOC_FREE(result);
return NULL;
}