summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorJelmer Vernooij <jelmer@samba.org>2009-01-18 17:27:41 +0100
committerJelmer Vernooij <jelmer@samba.org>2009-01-18 17:27:41 +0100
commit6ffe233f9442792a0e8e52167a01b76eabd83be9 (patch)
tree37a461845d9395c2290bbde73c3c7f95a7d3a37f /source3
parentbfbb0fb17f4eedb8f22d0694c5d4a3b82dfe189b (diff)
parent0dbd3968626445b4dcb00307e45206b37dd0e8ad (diff)
downloadsamba-6ffe233f9442792a0e8e52167a01b76eabd83be9.tar.gz
samba-6ffe233f9442792a0e8e52167a01b76eabd83be9.tar.bz2
samba-6ffe233f9442792a0e8e52167a01b76eabd83be9.zip
Merge branch 'master' of ssh://git.samba.org/data/git/samba
Diffstat (limited to 'source3')
-rw-r--r--source3/include/async_req.h7
-rw-r--r--source3/lib/async_req.c25
-rw-r--r--source3/lib/async_sock.c20
-rw-r--r--source3/lib/util_sock.c20
-rw-r--r--source3/lib/wb_reqtrans.c44
-rw-r--r--source3/lib/wbclient.c29
-rw-r--r--source3/libsmb/clireadwrite.c34
-rw-r--r--source3/rpc_client/cli_pipe.c74
8 files changed, 77 insertions, 176 deletions
diff --git a/source3/include/async_req.h b/source3/include/async_req.h
index 1b8dbf3346..3907a08f67 100644
--- a/source3/include/async_req.h
+++ b/source3/include/async_req.h
@@ -150,4 +150,11 @@ bool async_req_enqueue(struct async_req_queue *queue,
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
diff --git a/source3/lib/async_req.c b/source3/lib/async_req.c
index 13b64ba79a..011948a158 100644
--- a/source3/lib/async_req.c
+++ b/source3/lib/async_req.c
@@ -313,3 +313,28 @@ bool async_req_enqueue(struct async_req_queue *queue, struct event_context *ev,
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;
+}
diff --git a/source3/lib/async_sock.c b/source3/lib/async_sock.c
index bb89a1353a..73ff6f2870 100644
--- a/source3/lib/async_sock.c
+++ b/source3/lib/async_sock.c
@@ -106,17 +106,10 @@ static struct async_req *async_syscall_new(TALLOC_CTX *mem_ctx,
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;
@@ -569,15 +562,10 @@ struct async_req *async_connect_send(TALLOC_CTX *mem_ctx,
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
diff --git a/source3/lib/util_sock.c b/source3/lib/util_sock.c
index 98c25c1e24..3ddc4342a7 100644
--- a/source3/lib/util_sock.c
+++ b/source3/lib/util_sock.c
@@ -978,16 +978,10 @@ struct async_req *open_socket_out_send(TALLOC_CTX *mem_ctx,
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;
@@ -1170,16 +1164,10 @@ struct async_req *open_socket_out_defer_send(TALLOC_CTX *mem_ctx,
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;
diff --git a/source3/lib/wb_reqtrans.c b/source3/lib/wb_reqtrans.c
index 1f5f181aa1..0e6e5d15c4 100644
--- a/source3/lib/wb_reqtrans.c
+++ b/source3/lib/wb_reqtrans.c
@@ -43,17 +43,10 @@ struct async_req *wb_req_read_send(TALLOC_CTX *mem_ctx,
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;
@@ -205,17 +198,10 @@ struct async_req *wb_req_write_send(TALLOC_CTX *mem_ctx,
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;
@@ -304,17 +290,10 @@ struct async_req *wb_resp_read_send(TALLOC_CTX *mem_ctx,
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);
@@ -458,17 +437,10 @@ struct async_req *wb_resp_write_send(TALLOC_CTX *mem_ctx,
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;
diff --git a/source3/lib/wbclient.c b/source3/lib/wbclient.c
index d58c934c07..ea0bcb512e 100644
--- a/source3/lib/wbclient.c
+++ b/source3/lib/wbclient.c
@@ -289,15 +289,10 @@ static struct async_req *wb_int_trans_send(TALLOC_CTX *mem_ctx,
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,
@@ -420,16 +415,10 @@ static struct async_req *wb_open_pipe_send(TALLOC_CTX *mem_ctx,
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;
@@ -617,16 +606,10 @@ struct async_req *wb_trans_send(TALLOC_CTX *mem_ctx, struct event_context *ev,
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);
diff --git a/source3/libsmb/clireadwrite.c b/source3/libsmb/clireadwrite.c
index 1d5582e61d..1ba93d827d 100644
--- a/source3/libsmb/clireadwrite.c
+++ b/source3/libsmb/clireadwrite.c
@@ -278,15 +278,10 @@ struct async_req *cli_pull_send(TALLOC_CTX *mem_ctx,
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;
@@ -843,16 +838,10 @@ static struct async_req *cli_writeall_send(TALLOC_CTX *mem_ctx,
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;
@@ -969,15 +958,10 @@ struct async_req *cli_push_send(TALLOC_CTX *mem_ctx, struct event_context *ev,
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;
diff --git a/source3/rpc_client/cli_pipe.c b/source3/rpc_client/cli_pipe.c
index f3affd1cd8..cf621343e7 100644
--- a/source3/rpc_client/cli_pipe.c
+++ b/source3/rpc_client/cli_pipe.c
@@ -222,16 +222,10 @@ static struct async_req *rpc_read_send(TALLOC_CTX *mem_ctx,
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;
@@ -361,16 +355,10 @@ static struct async_req *rpc_write_send(TALLOC_CTX *mem_ctx,
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;
@@ -523,16 +511,10 @@ static struct async_req *get_complete_frag_send(TALLOC_CTX *mem_ctx,
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;
@@ -586,7 +568,6 @@ static struct async_req *get_complete_frag_send(TALLOC_CTX *mem_ctx,
if (async_post_status(result, ev, status)) {
return result;
}
- fail:
TALLOC_FREE(result);
return NULL;
}
@@ -1165,16 +1146,10 @@ static struct async_req *cli_api_pipe_send(TALLOC_CTX *mem_ctx,
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;
@@ -1227,7 +1202,6 @@ static struct async_req *cli_api_pipe_send(TALLOC_CTX *mem_ctx,
if (async_post_status(result, ev, status)) {
return result;
}
- fail:
TALLOC_FREE(result);
return NULL;
}
@@ -1370,16 +1344,10 @@ static struct async_req *rpc_api_pipe_send(TALLOC_CTX *mem_ctx,
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;
@@ -1423,7 +1391,6 @@ static struct async_req *rpc_api_pipe_send(TALLOC_CTX *mem_ctx,
if (async_post_status(result, ev, status)) {
return result;
}
- fail:
TALLOC_FREE(result);
return NULL;
}
@@ -2184,16 +2151,10 @@ struct async_req *rpc_api_pipe_req_send(TALLOC_CTX *mem_ctx,
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;
@@ -2250,7 +2211,6 @@ struct async_req *rpc_api_pipe_req_send(TALLOC_CTX *mem_ctx,
if (async_post_status(result, ev, status)) {
return result;
}
- fail:
TALLOC_FREE(result);
return NULL;
}
@@ -2667,15 +2627,10 @@ struct async_req *rpc_pipe_bind_send(TALLOC_CTX *mem_ctx,
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),
@@ -2717,7 +2672,6 @@ struct async_req *rpc_pipe_bind_send(TALLOC_CTX *mem_ctx,
if (async_post_status(result, ev, status)) {
return result;
}
- fail:
TALLOC_FREE(result);
return NULL;
}