diff options
author | Stefan Metzmacher <metze@samba.org> | 2005-09-26 11:47:55 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:38:57 -0500 |
commit | ab4d635b92b116b02b88843b4ec4f5b7517bab1a (patch) | |
tree | 63c3ee12153b629071d2ba0209a0a31b134c449e /source4/libcli | |
parent | 0d46be147a1e755bdd6f21a5ddc83b5c39585529 (diff) | |
download | samba-ab4d635b92b116b02b88843b4ec4f5b7517bab1a.tar.gz samba-ab4d635b92b116b02b88843b4ec4f5b7517bab1a.tar.xz samba-ab4d635b92b116b02b88843b4ec4f5b7517bab1a.zip |
r10504: - seperate implementation specific stuff, from the generic composite
stuff.
- don't use SMBCLI_REQUEST_* state's in the genreic composite stuff
- move monitor_fn to libnet.
NOTE: I have maybe found some bugs, in code that is dirrectly in DONE or ERROR
state in the _send() function. I haven't fixed this bugs in this
commit! We may need some composite_trigger_*() functions or so.
And maybe some other generic helper functions...
metze
(This used to be commit 4527815a0a9b96e460f301cb1f0c0b3964c166fc)
Diffstat (limited to 'source4/libcli')
20 files changed, 379 insertions, 379 deletions
diff --git a/source4/libcli/cliconnect.c b/source4/libcli/cliconnect.c index aba7f361a2..00c5012074 100644 --- a/source4/libcli/cliconnect.c +++ b/source4/libcli/cliconnect.c @@ -23,6 +23,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" #include "libcli/composite/composite.h" +#include "libcli/smb_composite/smb_composite.h" /* wrapper around smbcli_sock_connect() diff --git a/source4/libcli/composite/composite.c b/source4/libcli/composite/composite.c index f04309bbfb..4a5247c9ea 100644 --- a/source4/libcli/composite/composite.c +++ b/source4/libcli/composite/composite.c @@ -34,7 +34,7 @@ NTSTATUS composite_wait(struct composite_context *c) { if (c == NULL) return NT_STATUS_NO_MEMORY; - while (c->state < SMBCLI_REQUEST_DONE) { + while (c->state < COMPOSITE_STATE_DONE) { if (event_loop_once(c->event_ctx) != 0) { return NT_STATUS_UNSUCCESSFUL; } @@ -51,7 +51,6 @@ static void composite_trigger(struct event_context *ev, struct timed_event *te, struct timeval t, void *ptr) { struct composite_context *c = talloc_get_type(ptr, struct composite_context); - c->state = SMBCLI_REQUEST_DONE; if (c->async.fn) { c->async.fn(c); } @@ -65,6 +64,7 @@ static void composite_trigger(struct event_context *ev, struct timed_event *te, */ void composite_trigger_done(struct composite_context *c) { + c->state = COMPOSITE_STATE_DONE; /* a zero timeout means immediate */ event_add_timed(c->event_ctx, c, timeval_zero(), composite_trigger, c); } diff --git a/source4/libcli/composite/composite.h b/source4/libcli/composite/composite.h index be7fbd9972..83857edd14 100644 --- a/source4/libcli/composite/composite.h +++ b/source4/libcli/composite/composite.h @@ -1,7 +1,7 @@ /* Unix SMB/CIFS implementation. - SMB composite request interfaces + composite request interfaces Copyright (C) Andrew Tridgell 2005 @@ -23,19 +23,28 @@ /* this defines the structures associated with "composite" requests. Composite requests are libcli requests that are internally - implemented as multiple libcli/raw/ calls, but can be treated as a + implemented as multiple async calls, but can be treated as a single call via these composite calls. The composite calls are - particularly designed to be used in async applications + particularly designed to be used in async applications. + you can also stack multiple level of composite call */ +/* + a composite call moves between the following 3 states. +*/ +enum composite_state {COMPOSITE_STATE_INIT, /* we are creating the request */ + COMPOSITE_STATE_IN_PROGRESS, /* the request is in the outgoing socket Q */ + COMPOSITE_STATE_DONE, /* the request is received by the caller finished */ + COMPOSITE_STATE_ERROR}; /* a packet or transport level error has occurred */ +/* the context of one "composite" call */ struct composite_context { /* the external state - will be queried by the caller */ - enum smbcli_request_state state; + enum composite_state state; /* a private pointer for use by the composite function implementation */ - void *private; + void *private_data; /* status code when finished */ NTSTATUS status; @@ -46,132 +55,6 @@ struct composite_context { /* information on what to do on completion */ struct { void (*fn)(struct composite_context *); - void *private; + void *private_data; } async; - - /* information about the progress */ - void (*monitor_fn)(struct monitor_msg *); -}; - - -/* - a composite open/read(s)/close request that loads a whole file - into memory. Used as a demo of the composite system. -*/ -struct smb_composite_loadfile { - struct { - const char *fname; - } in; - struct { - uint8_t *data; - uint32_t size; - } out; -}; - -struct smb_composite_fetchfile { - struct { - const char *dest_host; - int port; - const char *called_name; - const char *service; - const char *service_type; - struct cli_credentials *credentials; - const char *workgroup; - const char *filename; - } in; - struct { - uint8_t *data; - uint32_t size; - } out; -}; - -/* - a composite open/write(s)/close request that saves a whole file from - memory. Used as a demo of the composite system. -*/ -struct smb_composite_savefile { - struct { - const char *fname; - uint8_t *data; - uint32_t size; - } in; -}; - - -/* - a composite request for a full connection to a remote server. Includes - - - socket establishment - - session request - - negprot - - session setup - - tree connect -*/ -struct smb_composite_connect { - struct { - const char *dest_host; - int port; - const char *called_name; - const char *service; - const char *service_type; - struct cli_credentials *credentials; - const char *workgroup; - } in; - struct { - struct smbcli_tree *tree; - } out; -}; - - -/* - generic session setup interface that takes care of which - session setup varient to use -*/ -struct smb_composite_sesssetup { - struct { - uint32_t sesskey; - uint32_t capabilities; - struct cli_credentials *credentials; - const char *workgroup; - } in; - struct { - uint16_t vuid; - } out; -}; - -/* - query file system info -*/ -struct smb_composite_fsinfo { - struct { - const char *dest_host; - int port; - const char *called_name; - const char *service; - const char *service_type; - struct cli_credentials *credentials; - const char *workgroup; - enum smb_fsinfo_level level; - } in; - - struct { - union smb_fsinfo *fsinfo; - } out; -}; - -/* - composite call for appending new acl to the file's security descriptor and get - new full acl -*/ - -struct smb_composite_appendacl { - struct { - const char *fname; - - const struct security_descriptor *sd; - } in; - - struct { - struct security_descriptor *sd; - } out; }; diff --git a/source4/libcli/composite/monitor.h b/source4/libcli/composite/monitor.h deleted file mode 100644 index dce9dedc92..0000000000 --- a/source4/libcli/composite/monitor.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - Definitions of composite function monitoring messages. - - Copyright (C) Rafal Szczesniak 2005 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -/* - * Monitor structure and message types definitions. Composite function monitoring - * allows client application to be notified on function progress. This enables - * eg. gui client to display progress bars, status messages, etc. - */ - - -#define rpc_create_user (0x00000001) /* userman.h */ -#define rpc_open_user (0x00000002) /* userinfo.h */ -#define rpc_query_user (0x00000003) /* userinfo.h */ -#define rpc_close_user (0x00000004) /* userinfo.h */ -#define rpc_lookup_name (0x00000005) /* userman.h */ -#define rpc_delete_user (0x00000006) /* userman.h */ - - -struct monitor_msg { - uint32_t type; - void *data; - size_t data_size; -}; diff --git a/source4/libcli/config.mk b/source4/libcli/config.mk index 248e0c2b95..62530ed64b 100644 --- a/source4/libcli/config.mk +++ b/source4/libcli/config.mk @@ -10,21 +10,21 @@ ADD_OBJ_FILES = libcli/util/asn1.o \ ADD_OBJ_FILES = libcli/util/clilsa.o REQUIRED_SUBSYSTEMS = RPC_NDR_LSA -[SUBSYSTEM::LIBCLI_COMPOSITE_BASE] +[SUBSYSTEM::LIBCLI_COMPOSITE] ADD_OBJ_FILES = \ libcli/composite/composite.o REQUIRED_SUBSYSTEMS = LIBEVENTS -[SUBSYSTEM::LIBCLI_COMPOSITE] +[SUBSYSTEM::LIBCLI_SMB_COMPOSITE] ADD_OBJ_FILES = \ - libcli/composite/loadfile.o \ - libcli/composite/savefile.o \ - libcli/composite/connect.o \ - libcli/composite/sesssetup.o \ - libcli/composite/fetchfile.o \ - libcli/composite/appendacl.o \ - libcli/composite/fsinfo.o -REQUIRED_SUBSYSTEMS = LIBCLI_COMPOSITE_BASE + libcli/smb_composite/loadfile.o \ + libcli/smb_composite/savefile.o \ + libcli/smb_composite/connect.o \ + libcli/smb_composite/sesssetup.o \ + libcli/smb_composite/fetchfile.o \ + libcli/smb_composite/appendacl.o \ + libcli/smb_composite/fsinfo.o +REQUIRED_SUBSYSTEMS = LIBCLI_COMPOSITE [SUBSYSTEM::LIBCLI_NBT] ADD_OBJ_FILES = \ @@ -34,7 +34,7 @@ ADD_OBJ_FILES = \ libcli/nbt/nameregister.o \ libcli/nbt/namerefresh.o \ libcli/nbt/namerelease.o -REQUIRED_SUBSYSTEMS = NDR_RAW NDR_NBT SOCKET LIBCLI_COMPOSITE_BASE LIBEVENTS \ +REQUIRED_SUBSYSTEMS = NDR_RAW NDR_NBT SOCKET LIBCLI_COMPOSITE LIBEVENTS \ LIB_SECURITY_NDR [SUBSYSTEM::LIBCLI_DGRAM] @@ -69,7 +69,7 @@ REQUIRED_SUBSYSTEMS = LIBCLI_NBT [SUBSYSTEM::LIBCLI] REQUIRED_SUBSYSTEMS = LIBCLI_RAW LIBCLI_UTILS LIBCLI_AUTH \ - LIBCLI_COMPOSITE LIBCLI_NBT LIB_SECURITY LIBCLI_RESOLVE \ + LIBCLI_SMB_COMPOSITE LIBCLI_NBT LIB_SECURITY LIBCLI_RESOLVE \ LIBCLI_DGRAM [SUBSYSTEM::LIBSMB] diff --git a/source4/libcli/nbt/namerefresh.c b/source4/libcli/nbt/namerefresh.c index a344f2c6e8..d9f2070d4c 100644 --- a/source4/libcli/nbt/namerefresh.c +++ b/source4/libcli/nbt/namerefresh.c @@ -22,7 +22,6 @@ #include "includes.h" #include "libcli/nbt/libnbt.h" -#include "libcli/raw/libcliraw.h" #include "libcli/composite/composite.h" /* @@ -154,7 +153,7 @@ static void name_refresh_wins_handler(struct nbt_name_request *req) { struct composite_context *c = talloc_get_type(req->async.private, struct composite_context); - struct refresh_wins_state *state = talloc_get_type(c->private, + struct refresh_wins_state *state = talloc_get_type(c->private_data, struct refresh_wins_state); NTSTATUS status; @@ -164,7 +163,7 @@ static void name_refresh_wins_handler(struct nbt_name_request *req) state->wins_servers++; state->address_idx = 0; if (state->wins_servers[0] == NULL) { - c->state = SMBCLI_REQUEST_ERROR; + c->state = COMPOSITE_STATE_ERROR; c->status = status; goto done; } @@ -172,14 +171,14 @@ static void name_refresh_wins_handler(struct nbt_name_request *req) state->io->in.address = state->addresses[0]; state->req = nbt_name_refresh_send(state->nbtsock, state->io); if (state->req == NULL) { - c->state = SMBCLI_REQUEST_ERROR; + c->state = COMPOSITE_STATE_ERROR; c->status = NT_STATUS_NO_MEMORY; } else { state->req->async.fn = name_refresh_wins_handler; state->req->async.private = c; } } else if (!NT_STATUS_IS_OK(status)) { - c->state = SMBCLI_REQUEST_ERROR; + c->state = COMPOSITE_STATE_ERROR; c->status = status; } else { if (state->io->out.rcode == 0 && @@ -188,20 +187,20 @@ static void name_refresh_wins_handler(struct nbt_name_request *req) state->io->in.address = state->addresses[++(state->address_idx)]; state->req = nbt_name_refresh_send(state->nbtsock, state->io); if (state->req == NULL) { - c->state = SMBCLI_REQUEST_ERROR; + c->state = COMPOSITE_STATE_ERROR; c->status = NT_STATUS_NO_MEMORY; } else { state->req->async.fn = name_refresh_wins_handler; state->req->async.private = c; } } else { - c->state = SMBCLI_REQUEST_DONE; + c->state = COMPOSITE_STATE_DONE; c->status = NT_STATUS_OK; } } done: - if (c->state >= SMBCLI_REQUEST_DONE && + if (c->state >= COMPOSITE_STATE_DONE && c->async.fn) { c->async.fn(c); } @@ -251,9 +250,9 @@ struct composite_context *nbt_name_refresh_wins_send(struct nbt_name_socket *nbt state->req->async.fn = name_refresh_wins_handler; state->req->async.private = c; - c->private = state; - c->state = SMBCLI_REQUEST_SEND; - c->event_ctx = nbtsock->event_ctx; + c->private_data = state; + c->state = COMPOSITE_STATE_IN_PROGRESS; + c->event_ctx = nbtsock->event_ctx; return c; @@ -272,7 +271,7 @@ NTSTATUS nbt_name_refresh_wins_recv(struct composite_context *c, TALLOC_CTX *mem status = composite_wait(c); if (NT_STATUS_IS_OK(status)) { struct refresh_wins_state *state = - talloc_get_type(c->private, struct refresh_wins_state); + talloc_get_type(c->private_data, struct refresh_wins_state); io->out.wins_server = talloc_steal(mem_ctx, state->wins_servers[0]); io->out.rcode = state->io->out.rcode; } diff --git a/source4/libcli/nbt/nameregister.c b/source4/libcli/nbt/nameregister.c index 276b8e4ac3..4dac500780 100644 --- a/source4/libcli/nbt/nameregister.c +++ b/source4/libcli/nbt/nameregister.c @@ -22,7 +22,6 @@ #include "includes.h" #include "libcli/nbt/libnbt.h" -#include "libcli/raw/libcliraw.h" #include "libcli/composite/composite.h" /* @@ -156,14 +155,14 @@ struct register_bcast_state { static void name_register_bcast_handler(struct nbt_name_request *req) { struct composite_context *c = talloc_get_type(req->async.private, struct composite_context); - struct register_bcast_state *state = talloc_get_type(c->private, struct register_bcast_state); + struct register_bcast_state *state = talloc_get_type(c->private_data, struct register_bcast_state); NTSTATUS status; status = nbt_name_register_recv(state->req, state, state->io); if (NT_STATUS_EQUAL(status, NT_STATUS_IO_TIMEOUT)) { if (state->io->in.register_demand == True) { /* all done */ - c->state = SMBCLI_REQUEST_DONE; + c->state = COMPOSITE_STATE_DONE; c->status = NT_STATUS_OK; goto done; } @@ -173,17 +172,17 @@ static void name_register_bcast_handler(struct nbt_name_request *req) state->io->in.retries = 0; state->req = nbt_name_register_send(state->nbtsock, state->io); if (state->req == NULL) { - c->state = SMBCLI_REQUEST_ERROR; + c->state = COMPOSITE_STATE_ERROR; c->status = NT_STATUS_NO_MEMORY; } else { state->req->async.fn = name_register_bcast_handler; state->req->async.private = c; } } else if (!NT_STATUS_IS_OK(status)) { - c->state = SMBCLI_REQUEST_ERROR; + c->state = COMPOSITE_STATE_ERROR; c->status = status; } else { - c->state = SMBCLI_REQUEST_ERROR; + c->state = COMPOSITE_STATE_ERROR; c->status = NT_STATUS_CONFLICTING_ADDRESSES; DEBUG(3,("Name registration conflict from %s for %s with ip %s - rcode %d\n", state->io->out.reply_from, @@ -193,7 +192,7 @@ static void name_register_bcast_handler(struct nbt_name_request *req) } done: - if (c->state >= SMBCLI_REQUEST_DONE && + if (c->state >= COMPOSITE_STATE_DONE && c->async.fn) { c->async.fn(c); } @@ -203,7 +202,7 @@ done: the async send call for a 4 stage name registration */ struct composite_context *nbt_name_register_bcast_send(struct nbt_name_socket *nbtsock, - struct nbt_name_register_bcast *io) + struct nbt_name_register_bcast *io) { struct composite_context *c; struct register_bcast_state *state; @@ -236,9 +235,9 @@ struct composite_context *nbt_name_register_bcast_send(struct nbt_name_socket *n state->req->async.fn = name_register_bcast_handler; state->req->async.private = c; - c->private = state; - c->state = SMBCLI_REQUEST_SEND; - c->event_ctx = nbtsock->event_ctx; + c->private_data = state; + c->state = COMPOSITE_STATE_IN_PROGRESS; + c->event_ctx = nbtsock->event_ctx; return c; @@ -291,7 +290,7 @@ static void name_register_wins_handler(struct nbt_name_request *req) { struct composite_context *c = talloc_get_type(req->async.private, struct composite_context); - struct register_wins_state *state = talloc_get_type(c->private, + struct register_wins_state *state = talloc_get_type(c->private_data, struct register_wins_state); NTSTATUS status; @@ -301,7 +300,7 @@ static void name_register_wins_handler(struct nbt_name_request *req) state->wins_servers++; state->address_idx = 0; if (state->wins_servers[0] == NULL) { - c->state = SMBCLI_REQUEST_ERROR; + c->state = COMPOSITE_STATE_ERROR; c->status = status; goto done; } @@ -309,14 +308,14 @@ static void name_register_wins_handler(struct nbt_name_request *req) state->io->in.address = state->addresses[0]; state->req = nbt_name_register_send(state->nbtsock, state->io); if (state->req == NULL) { - c->state = SMBCLI_REQUEST_ERROR; + c->state = COMPOSITE_STATE_ERROR; c->status = NT_STATUS_NO_MEMORY; } else { state->req->async.fn = name_register_wins_handler; state->req->async.private = c; } } else if (!NT_STATUS_IS_OK(status)) { - c->state = SMBCLI_REQUEST_ERROR; + c->state = COMPOSITE_STATE_ERROR; c->status = status; } else { if (state->io->out.rcode == 0 && @@ -325,20 +324,20 @@ static void name_register_wins_handler(struct nbt_name_request *req) state->io->in.address = state->addresses[++(state->address_idx)]; state->req = nbt_name_register_send(state->nbtsock, state->io); if (state->req == NULL) { - c->state = SMBCLI_REQUEST_ERROR; + c->state = COMPOSITE_STATE_ERROR; c->status = NT_STATUS_NO_MEMORY; } else { state->req->async.fn = name_register_wins_handler; state->req->async.private = c; } } else { - c->state = SMBCLI_REQUEST_DONE; + c->state = COMPOSITE_STATE_DONE; c->status = NT_STATUS_OK; } } done: - if (c->state >= SMBCLI_REQUEST_DONE && + if (c->state >= COMPOSITE_STATE_DONE && c->async.fn) { c->async.fn(c); } @@ -390,9 +389,9 @@ struct composite_context *nbt_name_register_wins_send(struct nbt_name_socket *nb state->req->async.fn = name_register_wins_handler; state->req->async.private = c; - c->private = state; - c->state = SMBCLI_REQUEST_SEND; - c->event_ctx = nbtsock->event_ctx; + c->private_data = state; + c->state = COMPOSITE_STATE_IN_PROGRESS; + c->event_ctx = nbtsock->event_ctx; return c; @@ -411,7 +410,7 @@ NTSTATUS nbt_name_register_wins_recv(struct composite_context *c, TALLOC_CTX *me status = composite_wait(c); if (NT_STATUS_IS_OK(status)) { struct register_wins_state *state = - talloc_get_type(c->private, struct register_wins_state); + talloc_get_type(c->private_data, struct register_wins_state); io->out.wins_server = talloc_steal(mem_ctx, state->wins_servers[0]); io->out.rcode = state->io->out.rcode; } diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 90fb98603e..688ee8a78b 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -78,17 +78,17 @@ static NTSTATUS smbcli_sock_connect_one(struct smbcli_socket *sock, has either completed the connect() or has returned an error */ static void smbcli_sock_connect_handler(struct event_context *ev, struct fd_event *fde, - uint16_t flags, void *private) + uint16_t flags, void *private_data) { - struct composite_context *c = talloc_get_type(private, struct composite_context); - struct clisocket_connect *conn = talloc_get_type(c->private, struct clisocket_connect); + struct composite_context *c = talloc_get_type(private_data, struct composite_context); + struct clisocket_connect *conn = talloc_get_type(c->private_data, struct clisocket_connect); int i; c->status = socket_connect_complete(conn->sock->sock, 0); if (NT_STATUS_IS_OK(c->status)) { socket_set_option(conn->sock->sock, lp_socket_options(), NULL); conn->sock->hostname = talloc_strdup(conn->sock, conn->dest_hostname); - c->state = SMBCLI_REQUEST_DONE; + c->state = COMPOSITE_STATE_DONE; if (c->async.fn) { c->async.fn(c); } @@ -107,7 +107,7 @@ static void smbcli_sock_connect_handler(struct event_context *ev, struct fd_even } } - c->state = SMBCLI_REQUEST_ERROR; + c->state = COMPOSITE_STATE_ERROR; if (c->async.fn) { c->async.fn(c); } @@ -195,8 +195,8 @@ struct composite_context *smbcli_sock_connect_send(struct smbcli_socket *sock, conn->dest_hostname = talloc_strdup(c, host_name); if (conn->dest_hostname == NULL) goto failed; - c->private = conn; - c->state = SMBCLI_REQUEST_SEND; + c->private_data = conn; + c->state = COMPOSITE_STATE_IN_PROGRESS; /* startup the connect process for each port in turn until one succeeds or tells us that it is pending */ @@ -212,7 +212,7 @@ struct composite_context *smbcli_sock_connect_send(struct smbcli_socket *sock, } } - c->state = SMBCLI_REQUEST_ERROR; + c->state = COMPOSITE_STATE_ERROR; return c; failed: diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index 74e14db591..cae93bdbe2 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -24,6 +24,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" #include "libcli/composite/composite.h" +#include "libcli/smb_composite/smb_composite.h" #define SETUP_REQUEST_TREE(cmd, wct, buflen) do { \ req = smbcli_request_setup(tree, cmd, wct, buflen); \ diff --git a/source4/libcli/resolve/host.c b/source4/libcli/resolve/host.c index a5edfcbc8a..13503b66b3 100644 --- a/source4/libcli/resolve/host.c +++ b/source4/libcli/resolve/host.c @@ -66,7 +66,7 @@ static int host_destructor(void *ptr) */ static void run_child(struct composite_context *c, int fd) { - struct host_state *state = talloc_get_type(c->private, struct host_state); + struct host_state *state = talloc_get_type(c->private_data, struct host_state); struct ipv4_addr ip; const char *address; @@ -84,10 +84,10 @@ static void run_child(struct composite_context *c, int fd) handle a read event on the pipe */ static void pipe_handler(struct event_context *ev, struct fd_event *fde, - uint16_t flags, void *private) + uint16_t flags, void *private_data) { - struct composite_context *c = talloc_get_type(private, struct composite_context); - struct host_state *state = talloc_get_type(c->private, struct host_state); + struct composite_context *c = talloc_get_type(private_data, struct composite_context); + struct host_state *state = talloc_get_type(c->private_data, struct host_state); char address[128]; int ret; @@ -113,7 +113,7 @@ static void pipe_handler(struct event_context *ev, struct fd_event *fde, if (state->reply_addr == NULL) goto failed; c->status = NT_STATUS_OK; - c->state = SMBCLI_REQUEST_DONE; + c->state = COMPOSITE_STATE_DONE; if (c->async.fn) { c->async.fn(c); } @@ -121,7 +121,7 @@ static void pipe_handler(struct event_context *ev, struct fd_event *fde, failed: c->status = NT_STATUS_BAD_NETWORK_NAME; - c->state = SMBCLI_REQUEST_ERROR; + c->state = COMPOSITE_STATE_ERROR; if (c->async.fn) { c->async.fn(c); } @@ -148,8 +148,8 @@ struct composite_context *resolve_name_host_send(struct nbt_name *name, status = nbt_name_dup(state, name, &state->name); if (!NT_STATUS_IS_OK(status)) goto failed; - c->state = SMBCLI_REQUEST_SEND; - c->private = state; + c->state = COMPOSITE_STATE_IN_PROGRESS; + c->private_data = state; c->event_ctx = talloc_reference(c, event_ctx); /* setup a pipe to chat to our child */ @@ -206,7 +206,7 @@ NTSTATUS resolve_name_host_recv(struct composite_context *c, status = composite_wait(c); if (NT_STATUS_IS_OK(status)) { - struct host_state *state = talloc_get_type(c->private, struct host_state); + struct host_state *state = talloc_get_type(c->private_data, struct host_state); *reply_addr = talloc_steal(mem_ctx, state->reply_addr); } diff --git a/source4/libcli/resolve/nbtlist.c b/source4/libcli/resolve/nbtlist.c index 7080c62e43..4fb4ccbb20 100644 --- a/source4/libcli/resolve/nbtlist.c +++ b/source4/libcli/resolve/nbtlist.c @@ -44,8 +44,8 @@ struct nbtlist_state { static void nbtlist_handler(struct nbt_name_request *req) { struct composite_context *c = talloc_get_type(req->async.private, - struct composite_context); - struct nbtlist_state *state = talloc_get_type(c->private, struct nbtlist_state); + struct composite_context); + struct nbtlist_state *state = talloc_get_type(c->private_data, struct nbtlist_state); int i; for (i=0;i<state->num_queries;i++) { @@ -54,20 +54,20 @@ static void nbtlist_handler(struct nbt_name_request *req) if (i == state->num_queries) { /* not for us?! */ c->status = NT_STATUS_INTERNAL_ERROR; - c->state = SMBCLI_REQUEST_ERROR; + c->state = COMPOSITE_STATE_ERROR; goto done; - } + } c->status = nbt_name_query_recv(req, state, &state->io_queries[i]); if (!NT_STATUS_IS_OK(c->status)) { - c->state = SMBCLI_REQUEST_ERROR; + c->state = COMPOSITE_STATE_ERROR; } else { if (state->io_queries[i].out.num_addrs < 1) { - c->state = SMBCLI_REQUEST_ERROR; + c->state = COMPOSITE_STATE_ERROR; c->status = NT_STATUS_UNEXPECTED_NETWORK_ERROR; } else { struct nbt_name_query *q = &state->io_queries[i]; - c->state = SMBCLI_REQUEST_DONE; + c->state = COMPOSITE_STATE_DONE; /* favor a local address if possible */ state->reply_addr = NULL; for (i=0;i<q->out.num_addrs;i++) { @@ -150,8 +150,8 @@ struct composite_context *resolve_name_nbtlist_send(struct nbt_name *name, state->queries[i]->async.private = c; } - c->state = SMBCLI_REQUEST_SEND; - c->private = state; + c->state = COMPOSITE_STATE_IN_PROGRESS; + c->private_data = state; c->event_ctx = talloc_reference(c, state->nbtsock->event_ctx); return c; @@ -172,7 +172,7 @@ NTSTATUS resolve_name_nbtlist_recv(struct composite_context *c, status = composite_wait(c); if (NT_STATUS_IS_OK(status)) { - struct nbtlist_state *state = talloc_get_type(c->private, struct nbtlist_state); + struct nbtlist_state *state = talloc_get_type(c->private_data, struct nbtlist_state); *reply_addr = talloc_steal(mem_ctx, state->reply_addr); } diff --git a/source4/libcli/resolve/resolve.c b/source4/libcli/resolve/resolve.c index c21b29b57f..c9e2fa503b 100644 --- a/source4/libcli/resolve/resolve.c +++ b/source4/libcli/resolve/resolve.c @@ -28,7 +28,7 @@ struct resolve_state { struct nbt_name name; const char **methods; - struct composite_context *req; + struct composite_context *creq; const char *reply_addr; }; @@ -65,26 +65,26 @@ static const struct resolve_method *find_method(const char *name) /* handle completion of one name resolve method */ -static void resolve_handler(struct composite_context *req) +static void resolve_handler(struct composite_context *creq) { - struct composite_context *c = req->async.private; - struct resolve_state *state = talloc_get_type(c->private, struct resolve_state); + struct composite_context *c = creq->async.private_data; + struct resolve_state *state = talloc_get_type(c->private_data, struct resolve_state); const struct resolve_method *method = find_method(state->methods[0]); - c->status = method->recv_fn(req, state, &state->reply_addr); + c->status = method->recv_fn(creq, state, &state->reply_addr); if (!NT_STATUS_IS_OK(c->status)) { state->methods++; - state->req = setup_next_method(c); - if (state->req != NULL) { + state->creq = setup_next_method(c); + if (state->creq != NULL) { return; } } if (!NT_STATUS_IS_OK(c->status)) { - c->state = SMBCLI_REQUEST_ERROR; + c->state = COMPOSITE_STATE_ERROR; } else { - c->state = SMBCLI_REQUEST_DONE; + c->state = COMPOSITE_STATE_DONE; } if (c->async.fn) { c->async.fn(c); @@ -94,23 +94,23 @@ static void resolve_handler(struct composite_context *req) static struct composite_context *setup_next_method(struct composite_context *c) { - struct resolve_state *state = talloc_get_type(c->private, struct resolve_state); - struct composite_context *req = NULL; + struct resolve_state *state = talloc_get_type(c->private_data, struct resolve_state); + struct composite_context *creq = NULL; do { const struct resolve_method *method = find_method(state->methods[0]); if (method) { - req = method->send_fn(&state->name, c->event_ctx); + creq = method->send_fn(&state->name, c->event_ctx); } - if (req == NULL && state->methods[0]) state->methods++; - } while (!req && state->methods[0]); + if (creq == NULL && state->methods[0]) state->methods++; + } while (!creq && state->methods[0]); - if (req) { - req->async.fn = resolve_handler; - req->async.private = c; + if (creq) { + creq->async.fn = resolve_handler; + creq->async.private_data = c; } - return req; + return creq; } /* @@ -136,8 +136,8 @@ struct composite_context *resolve_name_send(struct nbt_name *name, struct event_ state->methods = str_list_copy(state, methods); if (state->methods == NULL) goto failed; - c->state = SMBCLI_REQUEST_SEND; - c->private = state; + c->state = COMPOSITE_STATE_IN_PROGRESS; + c->private_data = state; if (event_ctx == NULL) { c->event_ctx = event_context_init(c); if (c->event_ctx == NULL) goto failed; @@ -154,8 +154,8 @@ struct composite_context *resolve_name_send(struct nbt_name *name, struct event_ return c; } - state->req = setup_next_method(c); - if (state->req == NULL) goto failed; + state->creq = setup_next_method(c); + if (state->creq == NULL) goto failed; return c; @@ -175,7 +175,7 @@ NTSTATUS resolve_name_recv(struct composite_context *c, status = composite_wait(c); if (NT_STATUS_IS_OK(status)) { - struct resolve_state *state = talloc_get_type(c->private, struct resolve_state); + struct resolve_state *state = talloc_get_type(c->private_data, struct resolve_state); *reply_addr = talloc_steal(mem_ctx, state->reply_addr); } diff --git a/source4/libcli/composite/appendacl.c b/source4/libcli/smb_composite/appendacl.c index 76702e6bca..b47a41a43b 100644 --- a/source4/libcli/composite/appendacl.c +++ b/source4/libcli/smb_composite/appendacl.c @@ -1,6 +1,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" #include "libcli/composite/composite.h" +#include "libcli/smb_composite/smb_composite.h" #include "librpc/gen_ndr/ndr_security.h" /* the stages of this call */ @@ -24,7 +25,7 @@ struct appendacl_state { static NTSTATUS appendacl_open(struct composite_context *c, struct smb_composite_appendacl *io) { - struct appendacl_state *state = talloc_get_type(c->private, struct appendacl_state); + struct appendacl_state *state = talloc_get_type(c->private_data, struct appendacl_state); struct smbcli_tree *tree = state->req->tree; NTSTATUS status; @@ -55,7 +56,7 @@ static NTSTATUS appendacl_open(struct composite_context *c, static NTSTATUS appendacl_get(struct composite_context *c, struct smb_composite_appendacl *io) { - struct appendacl_state *state = talloc_get_type(c->private, struct appendacl_state); + struct appendacl_state *state = talloc_get_type(c->private_data, struct appendacl_state); struct smbcli_tree *tree = state->req->tree; int i; NTSTATUS status; @@ -101,7 +102,7 @@ static NTSTATUS appendacl_get(struct composite_context *c, static NTSTATUS appendacl_set(struct composite_context *c, struct smb_composite_appendacl *io) { - struct appendacl_state *state = talloc_get_type(c->private, struct appendacl_state); + struct appendacl_state *state = talloc_get_type(c->private_data, struct appendacl_state); struct smbcli_tree *tree = state->req->tree; NTSTATUS status; @@ -134,7 +135,7 @@ static NTSTATUS appendacl_set(struct composite_context *c, static NTSTATUS appendacl_getagain(struct composite_context *c, struct smb_composite_appendacl *io) { - struct appendacl_state *state = talloc_get_type(c->private, struct appendacl_state); + struct appendacl_state *state = talloc_get_type(c->private_data, struct appendacl_state); struct smbcli_tree *tree = state->req->tree; union smb_close *io_close; NTSTATUS status; @@ -170,13 +171,13 @@ static NTSTATUS appendacl_getagain(struct composite_context *c, static NTSTATUS appendacl_close(struct composite_context *c, struct smb_composite_appendacl *io) { - struct appendacl_state *state = talloc_get_type(c->private, struct appendacl_state); + struct appendacl_state *state = talloc_get_type(c->private_data, struct appendacl_state); NTSTATUS status; status = smbcli_request_simple_recv(state->req); NT_STATUS_NOT_OK_RETURN(status); - c->state = SMBCLI_REQUEST_DONE; + c->state = COMPOSITE_STATE_DONE; return NT_STATUS_OK; } @@ -187,7 +188,7 @@ static NTSTATUS appendacl_close(struct composite_context *c, static void appendacl_handler(struct smbcli_request *req) { struct composite_context *c = req->async.private; - struct appendacl_state *state = talloc_get_type(c->private, struct appendacl_state); + struct appendacl_state *state = talloc_get_type(c->private_data, struct appendacl_state); /* when this handler is called, the stage indicates what call has just finished */ @@ -215,10 +216,10 @@ static void appendacl_handler(struct smbcli_request *req) /* We should get here if c->state >= SMBCLI_REQUEST_DONE */ if (!NT_STATUS_IS_OK(c->status)) { - c->state = SMBCLI_REQUEST_ERROR; + c->state = COMPOSITE_STATE_ERROR; } - if (c->state >= SMBCLI_REQUEST_DONE && + if (c->state >= COMPOSITE_STATE_DONE && c->async.fn) { c->async.fn(c); } @@ -243,8 +244,8 @@ struct composite_context *smb_composite_appendacl_send(struct smbcli_tree *tree, state->io = io; - c->private = state; - c->state = SMBCLI_REQUEST_SEND; + c->private_data = state; + c->state = COMPOSITE_STATE_IN_PROGRESS; c->event_ctx = tree->session->transport->socket->event.ctx; /* setup structures for opening file */ @@ -289,7 +290,7 @@ NTSTATUS smb_composite_appendacl_recv(struct composite_context *c, TALLOC_CTX *m status = composite_wait(c); if (NT_STATUS_IS_OK(status)) { - struct appendacl_state *state = talloc_get_type(c->private, struct appendacl_state); + struct appendacl_state *state = talloc_get_type(c->private_data, struct appendacl_state); state->io->out.sd = security_descriptor_copy (mem_ctx, state->io->out.sd); } diff --git a/source4/libcli/composite/connect.c b/source4/libcli/smb_composite/connect.c index a5ce5308e5..56d9d988c3 100644 --- a/source4/libcli/composite/connect.c +++ b/source4/libcli/smb_composite/connect.c @@ -24,6 +24,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" #include "libcli/composite/composite.h" +#include "libcli/smb_composite/smb_composite.h" /* the stages of this call */ enum connect_stage {CONNECT_RESOLVE, @@ -55,7 +56,7 @@ static void composite_handler(struct composite_context *); static NTSTATUS connect_send_negprot(struct composite_context *c, struct smb_composite_connect *io) { - struct connect_state *state = talloc_get_type(c->private, struct connect_state); + struct connect_state *state = talloc_get_type(c->private_data, struct connect_state); state->req = smb_raw_negotiate_send(state->transport, lp_maxprotocol()); NT_STATUS_HAVE_NO_MEMORY(state->req); @@ -74,7 +75,7 @@ static NTSTATUS connect_send_negprot(struct composite_context *c, static NTSTATUS connect_tcon(struct composite_context *c, struct smb_composite_connect *io) { - struct connect_state *state = talloc_get_type(c->private, struct connect_state); + struct connect_state *state = talloc_get_type(c->private_data, struct connect_state); NTSTATUS status; status = smb_raw_tcon_recv(state->req, c, state->io_tcon); @@ -91,7 +92,7 @@ static NTSTATUS connect_tcon(struct composite_context *c, } /* all done! */ - c->state = SMBCLI_REQUEST_DONE; + c->state = COMPOSITE_STATE_DONE; return NT_STATUS_OK; } @@ -103,7 +104,7 @@ static NTSTATUS connect_tcon(struct composite_context *c, static NTSTATUS connect_session_setup(struct composite_context *c, struct smb_composite_connect *io) { - struct connect_state *state = talloc_get_type(c->private, struct connect_state); + struct connect_state *state = talloc_get_type(c->private_data, struct connect_state); NTSTATUS status; status = smb_composite_sesssetup_recv(state->creq); @@ -153,7 +154,7 @@ static NTSTATUS connect_session_setup(struct composite_context *c, static NTSTATUS connect_negprot(struct composite_context *c, struct smb_composite_connect *io) { - struct connect_state *state = talloc_get_type(c->private, struct connect_state); + struct connect_state *state = talloc_get_type(c->private_data, struct connect_state); NTSTATUS status; status = smb_raw_negotiate_recv(state->req); @@ -174,12 +175,12 @@ static NTSTATUS connect_negprot(struct composite_context *c, state->creq = smb_composite_sesssetup_send(state->session, state->io_setup); NT_STATUS_HAVE_NO_MEMORY(state->creq); - if (state->creq->state == SMBCLI_REQUEST_ERROR) { + if (state->creq->state == COMPOSITE_STATE_ERROR) { return state->creq->status; } state->creq->async.fn = composite_handler; - state->creq->async.private = c; + state->creq->async.private_data = c; state->stage = CONNECT_SESSION_SETUP; return NT_STATUS_OK; @@ -192,7 +193,7 @@ static NTSTATUS connect_negprot(struct composite_context *c, static NTSTATUS connect_session_request(struct composite_context *c, struct smb_composite_connect *io) { - struct connect_state *state = talloc_get_type(c->private, struct connect_state); + struct connect_state *state = talloc_get_type(c->private_data, struct connect_state); NTSTATUS status; status = smbcli_transport_connect_recv(state->req); @@ -208,7 +209,7 @@ static NTSTATUS connect_session_request(struct composite_context *c, static NTSTATUS connect_socket(struct composite_context *c, struct smb_composite_connect *io) { - struct connect_state *state = talloc_get_type(c->private, struct connect_state); + struct connect_state *state = talloc_get_type(c->private_data, struct connect_state); NTSTATUS status; struct nbt_name calling, called; @@ -250,7 +251,7 @@ static NTSTATUS connect_socket(struct composite_context *c, static NTSTATUS connect_resolve(struct composite_context *c, struct smb_composite_connect *io) { - struct connect_state *state = talloc_get_type(c->private, struct connect_state); + struct connect_state *state = talloc_get_type(c->private_data, struct connect_state); NTSTATUS status; const char *address; @@ -261,7 +262,7 @@ static NTSTATUS connect_resolve(struct composite_context *c, NT_STATUS_HAVE_NO_MEMORY(state->creq); state->stage = CONNECT_SOCKET; - state->creq->async.private = c; + state->creq->async.private_data = c; state->creq->async.fn = composite_handler; return NT_STATUS_OK; @@ -273,7 +274,7 @@ static NTSTATUS connect_resolve(struct composite_context *c, */ static void state_handler(struct composite_context *c) { - struct connect_state *state = talloc_get_type(c->private, struct connect_state); + struct connect_state *state = talloc_get_type(c->private_data, struct connect_state); switch (state->stage) { case CONNECT_RESOLVE: @@ -297,10 +298,10 @@ static void state_handler(struct composite_context *c) } if (!NT_STATUS_IS_OK(c->status)) { - c->state = SMBCLI_REQUEST_ERROR; + c->state = COMPOSITE_STATE_ERROR; } - if (c->state >= SMBCLI_REQUEST_DONE && + if (c->state >= COMPOSITE_STATE_DONE && c->async.fn) { c->async.fn(c); } @@ -320,9 +321,9 @@ static void request_handler(struct smbcli_request *req) /* handler for completion of a smbcli_composite sub-request */ -static void composite_handler(struct composite_context *req) +static void composite_handler(struct composite_context *creq) { - struct composite_context *c = talloc_get_type(req->async.private, + struct composite_context *c = talloc_get_type(creq->async.private_data, struct composite_context); state_handler(c); } @@ -348,16 +349,16 @@ struct composite_context *smb_composite_connect_send(struct smb_composite_connec state->io = io; - c->state = SMBCLI_REQUEST_SEND; + c->state = COMPOSITE_STATE_IN_PROGRESS; c->event_ctx = talloc_reference(c, state->sock->event.ctx); - c->private = state; + c->private_data = state; state->stage = CONNECT_RESOLVE; make_nbt_name_server(&name, io->in.dest_host); state->creq = resolve_name_send(&name, c->event_ctx, lp_name_resolve_order()); if (state->creq == NULL) goto failed; - state->creq->async.private = c; + state->creq->async.private_data = c; state->creq->async.fn = composite_handler; return c; @@ -376,7 +377,7 @@ NTSTATUS smb_composite_connect_recv(struct composite_context *c, TALLOC_CTX *mem status = composite_wait(c); if (NT_STATUS_IS_OK(status)) { - struct connect_state *state = talloc_get_type(c->private, struct connect_state); + struct connect_state *state = talloc_get_type(c->private_data, struct connect_state); talloc_steal(mem_ctx, state->io->out.tree); } diff --git a/source4/libcli/composite/fetchfile.c b/source4/libcli/smb_composite/fetchfile.c index c9e8321db2..9e88fb669d 100644 --- a/source4/libcli/composite/fetchfile.c +++ b/source4/libcli/smb_composite/fetchfile.c @@ -24,6 +24,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" #include "libcli/composite/composite.h" +#include "libcli/smb_composite/smb_composite.h" enum fetchfile_stage {FETCHFILE_CONNECT, FETCHFILE_READ}; @@ -31,7 +32,7 @@ enum fetchfile_stage {FETCHFILE_CONNECT, struct fetchfile_state { enum fetchfile_stage stage; struct smb_composite_fetchfile *io; - struct composite_context *req; + struct composite_context *creq; struct smb_composite_connect *connect; struct smb_composite_loadfile *loadfile; }; @@ -43,9 +44,9 @@ static NTSTATUS fetchfile_connect(struct composite_context *c, { NTSTATUS status; struct fetchfile_state *state; - state = talloc_get_type(c->private, struct fetchfile_state); + state = talloc_get_type(c->private_data, struct fetchfile_state); - status = smb_composite_connect_recv(state->req, c); + status = smb_composite_connect_recv(state->creq, c); NT_STATUS_NOT_OK_RETURN(status); state->loadfile = talloc(state, struct smb_composite_loadfile); @@ -53,15 +54,15 @@ static NTSTATUS fetchfile_connect(struct composite_context *c, state->loadfile->in.fname = io->in.filename; - state->req = smb_composite_loadfile_send(state->connect->out.tree, + state->creq = smb_composite_loadfile_send(state->connect->out.tree, state->loadfile); - NT_STATUS_HAVE_NO_MEMORY(state->req); + NT_STATUS_HAVE_NO_MEMORY(state->creq); - state->req->async.private = c; - state->req->async.fn = fetchfile_composite_handler; + state->creq->async.private_data = c; + state->creq->async.fn = fetchfile_composite_handler; state->stage = FETCHFILE_READ; - c->event_ctx = talloc_reference(c, state->req->event_ctx); + c->event_ctx = talloc_reference(c, state->creq->event_ctx); return NT_STATUS_OK; } @@ -71,15 +72,15 @@ static NTSTATUS fetchfile_read(struct composite_context *c, { NTSTATUS status; struct fetchfile_state *state; - state = talloc_get_type(c->private, struct fetchfile_state); + state = talloc_get_type(c->private_data, struct fetchfile_state); - status = smb_composite_loadfile_recv(state->req, NULL); + status = smb_composite_loadfile_recv(state->creq, NULL); NT_STATUS_NOT_OK_RETURN(status); io->out.data = state->loadfile->out.data; io->out.size = state->loadfile->out.size; - c->state = SMBCLI_REQUEST_DONE; + c->state = COMPOSITE_STATE_DONE; if (c->async.fn) c->async.fn(c); @@ -91,7 +92,7 @@ static void fetchfile_state_handler(struct composite_context *c) struct fetchfile_state *state; NTSTATUS status; - state = talloc_get_type(c->private, struct fetchfile_state); + state = talloc_get_type(c->private_data, struct fetchfile_state); /* when this handler is called, the stage indicates what call has just finished */ @@ -106,22 +107,22 @@ static void fetchfile_state_handler(struct composite_context *c) if (!NT_STATUS_IS_OK(status)) { c->status = status; - c->state = SMBCLI_REQUEST_ERROR; + c->state = COMPOSITE_STATE_ERROR; if (c->async.fn) { c->async.fn(c); } } } -static void fetchfile_composite_handler(struct composite_context *req) +static void fetchfile_composite_handler(struct composite_context *creq) { - struct composite_context *c = talloc_get_type(req->async.private, - struct composite_context); + struct composite_context *c = talloc_get_type(creq->async.private_data, + struct composite_context); fetchfile_state_handler(c); } struct composite_context *smb_composite_fetchfile_send(struct smb_composite_fetchfile *io, - struct event_context *event_ctx) + struct event_context *event_ctx) { struct composite_context *c; struct fetchfile_state *state; @@ -145,16 +146,16 @@ struct composite_context *smb_composite_fetchfile_send(struct smb_composite_fetc state->connect->in.credentials = io->in.credentials; state->connect->in.workgroup = io->in.workgroup; - state->req = smb_composite_connect_send(state->connect, event_ctx); - if (state->req == NULL) goto failed; + state->creq = smb_composite_connect_send(state->connect, event_ctx); + if (state->creq == NULL) goto failed; - state->req->async.private = c; - state->req->async.fn = fetchfile_composite_handler; + state->creq->async.private_data = c; + state->creq->async.fn = fetchfile_composite_handler; - c->state = SMBCLI_REQUEST_SEND; + c->state = COMPOSITE_STATE_IN_PROGRESS; state->stage = FETCHFILE_CONNECT; - c->event_ctx = talloc_reference(c, state->req->event_ctx); - c->private = state; + c->event_ctx = talloc_reference(c, state->creq->event_ctx); + c->private_data = state; return c; failed: @@ -170,7 +171,7 @@ NTSTATUS smb_composite_fetchfile_recv(struct composite_context *c, status = composite_wait(c); if (NT_STATUS_IS_OK(status)) { - struct fetchfile_state *state = talloc_get_type(c->private, struct fetchfile_state); + struct fetchfile_state *state = talloc_get_type(c->private_data, struct fetchfile_state); talloc_steal(mem_ctx, state->io->out.data); } diff --git a/source4/libcli/composite/fsinfo.c b/source4/libcli/smb_composite/fsinfo.c index e0accbb6a6..e870225906 100644 --- a/source4/libcli/composite/fsinfo.c +++ b/source4/libcli/smb_composite/fsinfo.c @@ -5,6 +5,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" #include "libcli/composite/composite.h" +#include "libcli/smb_composite/smb_composite.h" #include "librpc/gen_ndr/ndr_security.h" /* the stages of this call */ @@ -30,7 +31,7 @@ static NTSTATUS fsinfo_connect(struct composite_context *c, { NTSTATUS status; struct fsinfo_state *state; - state = talloc_get_type(c->private, struct fsinfo_state); + state = talloc_get_type(c->private_data, struct fsinfo_state); status = smb_composite_connect_recv(state->creq, c); NT_STATUS_NOT_OK_RETURN(status); @@ -59,14 +60,14 @@ static NTSTATUS fsinfo_query(struct composite_context *c, { NTSTATUS status; struct fsinfo_state *state; - state = talloc_get_type(c->private, struct fsinfo_state); + state = talloc_get_type(c->private_data, struct fsinfo_state); status = smb_raw_fsinfo_recv(state->req, state, state->fsinfo); NT_STATUS_NOT_OK_RETURN(status); state->io->out.fsinfo = state->fsinfo; - c->state = SMBCLI_REQUEST_DONE; + c->state = COMPOSITE_STATE_DONE; if (c->async.fn) c->async.fn(c); @@ -78,28 +79,28 @@ static NTSTATUS fsinfo_query(struct composite_context *c, /* handler for completion of a sub-request in fsinfo */ -static void fsinfo_state_handler(struct composite_context *req) +static void fsinfo_state_handler(struct composite_context *creq) { - struct fsinfo_state *state = talloc_get_type(req->private, struct fsinfo_state); + struct fsinfo_state *state = talloc_get_type(creq->private_data, struct fsinfo_state); /* when this handler is called, the stage indicates what call has just finished */ switch (state->stage) { case FSINFO_CONNECT: - req->status = fsinfo_connect(req, state->io); + creq->status = fsinfo_connect(creq, state->io); break; case FSINFO_QUERY: - req->status = fsinfo_query(req, state->io); + creq->status = fsinfo_query(creq, state->io); break; } - if (!NT_STATUS_IS_OK(req->status)) { - req->state = SMBCLI_REQUEST_ERROR; + if (!NT_STATUS_IS_OK(creq->status)) { + creq->state = COMPOSITE_STATE_ERROR; } - if (req->state >= SMBCLI_REQUEST_DONE && req->async.fn) { - req->async.fn(req); + if (creq->state >= COMPOSITE_STATE_DONE && creq->async.fn) { + creq->async.fn(creq); } } @@ -114,9 +115,9 @@ static void fsinfo_raw_handler(struct smbcli_request *req) fsinfo_state_handler(c); } -static void fsinfo_composite_handler(struct composite_context *req) +static void fsinfo_composite_handler(struct composite_context *creq) { - struct composite_context *c = talloc_get_type(req->async.private, + struct composite_context *c = talloc_get_type(creq->async.private_data, struct composite_context); fsinfo_state_handler(c); } @@ -150,16 +151,16 @@ struct composite_context *smb_composite_fsinfo_send(struct smbcli_tree *tree, state->connect->in.credentials = io->in.credentials; state->connect->in.workgroup = io->in.workgroup; - c->state = SMBCLI_REQUEST_SEND; + c->state = COMPOSITE_STATE_IN_PROGRESS; state->stage = FSINFO_CONNECT; c->event_ctx = talloc_reference(c, tree->session->transport->socket->event.ctx); - c->private = state; + c->private_data = state; state->creq = smb_composite_connect_send(state->connect, c->event_ctx); if (state->creq == NULL) goto failed; - state->creq->async.private = c; + state->creq->async.private_data = c; state->creq->async.fn = fsinfo_composite_handler; return c; @@ -178,7 +179,7 @@ NTSTATUS smb_composite_fsinfo_recv(struct composite_context *c, TALLOC_CTX *mem_ status = composite_wait(c); if (NT_STATUS_IS_OK(status)) { - struct fsinfo_state *state = talloc_get_type(c->private, struct fsinfo_state); + struct fsinfo_state *state = talloc_get_type(c->private_data, struct fsinfo_state); talloc_steal(mem_ctx, state->io->out.fsinfo); } diff --git a/source4/libcli/composite/loadfile.c b/source4/libcli/smb_composite/loadfile.c index 69a8219dba..93122e287f 100644 --- a/source4/libcli/composite/loadfile.c +++ b/source4/libcli/smb_composite/loadfile.c @@ -24,6 +24,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" #include "libcli/composite/composite.h" +#include "libcli/smb_composite/smb_composite.h" #include "librpc/gen_ndr/ndr_security.h" /* the stages of this call */ @@ -46,7 +47,7 @@ struct loadfile_state { static NTSTATUS setup_close(struct composite_context *c, struct smbcli_tree *tree, uint16_t fnum) { - struct loadfile_state *state = talloc_get_type(c->private, struct loadfile_state); + struct loadfile_state *state = talloc_get_type(c->private_data, struct loadfile_state); union smb_close *io_close; /* nothing to read, setup the close */ @@ -75,7 +76,7 @@ static NTSTATUS setup_close(struct composite_context *c, static NTSTATUS loadfile_open(struct composite_context *c, struct smb_composite_loadfile *io) { - struct loadfile_state *state = talloc_get_type(c->private, struct loadfile_state); + struct loadfile_state *state = talloc_get_type(c->private_data, struct loadfile_state); struct smbcli_tree *tree = state->req->tree; NTSTATUS status; @@ -129,7 +130,7 @@ static NTSTATUS loadfile_open(struct composite_context *c, static NTSTATUS loadfile_read(struct composite_context *c, struct smb_composite_loadfile *io) { - struct loadfile_state *state = talloc_get_type(c->private, struct loadfile_state); + struct loadfile_state *state = talloc_get_type(c->private_data, struct loadfile_state); struct smbcli_tree *tree = state->req->tree; NTSTATUS status; @@ -163,13 +164,13 @@ static NTSTATUS loadfile_read(struct composite_context *c, static NTSTATUS loadfile_close(struct composite_context *c, struct smb_composite_loadfile *io) { - struct loadfile_state *state = talloc_get_type(c->private, struct loadfile_state); + struct loadfile_state *state = talloc_get_type(c->private_data, struct loadfile_state); NTSTATUS status; status = smbcli_request_simple_recv(state->req); NT_STATUS_NOT_OK_RETURN(status); - c->state = SMBCLI_REQUEST_DONE; + c->state = COMPOSITE_STATE_DONE; return NT_STATUS_OK; } @@ -181,7 +182,7 @@ static NTSTATUS loadfile_close(struct composite_context *c, static void loadfile_handler(struct smbcli_request *req) { struct composite_context *c = req->async.private; - struct loadfile_state *state = talloc_get_type(c->private, struct loadfile_state); + struct loadfile_state *state = talloc_get_type(c->private_data, struct loadfile_state); /* when this handler is called, the stage indicates what call has just finished */ @@ -200,10 +201,10 @@ static void loadfile_handler(struct smbcli_request *req) } if (!NT_STATUS_IS_OK(c->status)) { - c->state = SMBCLI_REQUEST_ERROR; + c->state = COMPOSITE_STATE_ERROR; } - if (c->state >= SMBCLI_REQUEST_DONE && + if (c->state >= COMPOSITE_STATE_DONE && c->async.fn) { c->async.fn(c); } @@ -227,8 +228,8 @@ struct composite_context *smb_composite_loadfile_send(struct smbcli_tree *tree, state->io = io; - c->private = state; - c->state = SMBCLI_REQUEST_SEND; + c->private_data = state; + c->state = COMPOSITE_STATE_IN_PROGRESS; c->event_ctx = tree->session->transport->socket->event.ctx; /* setup for the open */ @@ -271,7 +272,7 @@ NTSTATUS smb_composite_loadfile_recv(struct composite_context *c, TALLOC_CTX *me status = composite_wait(c); if (NT_STATUS_IS_OK(status)) { - struct loadfile_state *state = talloc_get_type(c->private, struct loadfile_state); + struct loadfile_state *state = talloc_get_type(c->private_data, struct loadfile_state); talloc_steal(mem_ctx, state->io->out.data); } diff --git a/source4/libcli/composite/savefile.c b/source4/libcli/smb_composite/savefile.c index 0b08963966..0e11031dab 100644 --- a/source4/libcli/composite/savefile.c +++ b/source4/libcli/smb_composite/savefile.c @@ -24,6 +24,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" #include "libcli/composite/composite.h" +#include "libcli/smb_composite/smb_composite.h" #include "librpc/gen_ndr/ndr_security.h" /* the stages of this call */ @@ -47,7 +48,7 @@ struct savefile_state { static NTSTATUS setup_close(struct composite_context *c, struct smbcli_tree *tree, uint16_t fnum) { - struct savefile_state *state = talloc_get_type(c->private, struct savefile_state); + struct savefile_state *state = talloc_get_type(c->private_data, struct savefile_state); union smb_close *io_close; /* nothing to write, setup the close */ @@ -76,7 +77,7 @@ static NTSTATUS setup_close(struct composite_context *c, static NTSTATUS savefile_open(struct composite_context *c, struct smb_composite_savefile *io) { - struct savefile_state *state = talloc_get_type(c->private, struct savefile_state); + struct savefile_state *state = talloc_get_type(c->private_data, struct savefile_state); union smb_write *io_write; struct smbcli_tree *tree = state->req->tree; NTSTATUS status; @@ -122,7 +123,7 @@ static NTSTATUS savefile_open(struct composite_context *c, static NTSTATUS savefile_write(struct composite_context *c, struct smb_composite_savefile *io) { - struct savefile_state *state = talloc_get_type(c->private, struct savefile_state); + struct savefile_state *state = talloc_get_type(c->private_data, struct savefile_state); struct smbcli_tree *tree = state->req->tree; NTSTATUS status; uint32_t max_xmit = tree->session->transport->negotiate.max_xmit; @@ -160,7 +161,7 @@ static NTSTATUS savefile_write(struct composite_context *c, static NTSTATUS savefile_close(struct composite_context *c, struct smb_composite_savefile *io) { - struct savefile_state *state = talloc_get_type(c->private, struct savefile_state); + struct savefile_state *state = talloc_get_type(c->private_data, struct savefile_state); NTSTATUS status; status = smbcli_request_simple_recv(state->req); @@ -170,7 +171,7 @@ static NTSTATUS savefile_close(struct composite_context *c, return NT_STATUS_DISK_FULL; } - c->state = SMBCLI_REQUEST_DONE; + c->state = COMPOSITE_STATE_DONE; return NT_STATUS_OK; } @@ -182,7 +183,7 @@ static NTSTATUS savefile_close(struct composite_context *c, static void savefile_handler(struct smbcli_request *req) { struct composite_context *c = req->async.private; - struct savefile_state *state = talloc_get_type(c->private, struct savefile_state); + struct savefile_state *state = talloc_get_type(c->private_data, struct savefile_state); /* when this handler is called, the stage indicates what call has just finished */ @@ -201,10 +202,10 @@ static void savefile_handler(struct smbcli_request *req) } if (!NT_STATUS_IS_OK(c->status)) { - c->state = SMBCLI_REQUEST_ERROR; + c->state = COMPOSITE_STATE_ERROR; } - if (c->state >= SMBCLI_REQUEST_DONE && + if (c->state >= COMPOSITE_STATE_DONE && c->async.fn) { c->async.fn(c); } @@ -215,7 +216,7 @@ static void savefile_handler(struct smbcli_request *req) followed by a close */ struct composite_context *smb_composite_savefile_send(struct smbcli_tree *tree, - struct smb_composite_savefile *io) + struct smb_composite_savefile *io) { struct composite_context *c; struct savefile_state *state; @@ -224,7 +225,7 @@ struct composite_context *smb_composite_savefile_send(struct smbcli_tree *tree, c = talloc_zero(tree, struct composite_context); if (c == NULL) goto failed; - c->state = SMBCLI_REQUEST_SEND; + c->state = COMPOSITE_STATE_IN_PROGRESS; c->event_ctx = tree->session->transport->socket->event.ctx; state = talloc(c, struct savefile_state); @@ -255,7 +256,7 @@ struct composite_context *smb_composite_savefile_send(struct smbcli_tree *tree, /* setup the callback handler */ state->req->async.fn = savefile_handler; state->req->async.private = c; - c->private = state; + c->private_data = state; return c; diff --git a/source4/libcli/composite/sesssetup.c b/source4/libcli/smb_composite/sesssetup.c index 3bd9ed285d..2ca862fb2f 100644 --- a/source4/libcli/composite/sesssetup.c +++ b/source4/libcli/smb_composite/sesssetup.c @@ -24,6 +24,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" #include "libcli/composite/composite.h" +#include "libcli/smb_composite/smb_composite.h" #include "auth/auth.h" #include "version.h" @@ -74,7 +75,7 @@ static void set_user_session_key(struct smbcli_session *session, static void request_handler(struct smbcli_request *req) { struct composite_context *c = req->async.private; - struct sesssetup_state *state = talloc_get_type(c->private, struct sesssetup_state); + struct sesssetup_state *state = talloc_get_type(c->private_data, struct sesssetup_state); struct smbcli_session *session = req->session; DATA_BLOB session_key = data_blob(NULL, 0); DATA_BLOB null_data_blob = data_blob(NULL, 0); @@ -144,9 +145,9 @@ static void request_handler(struct smbcli_request *req) } if (NT_STATUS_IS_OK(c->status)) { - c->state = SMBCLI_REQUEST_DONE; + c->state = COMPOSITE_STATE_DONE; } else { - c->state = SMBCLI_REQUEST_ERROR; + c->state = COMPOSITE_STATE_ERROR; } if (c->async.fn) { c->async.fn(c); @@ -162,7 +163,7 @@ static NTSTATUS session_setup_nt1(struct composite_context *c, struct smb_composite_sesssetup *io, struct smbcli_request **req) { - struct sesssetup_state *state = talloc_get_type(c->private, struct sesssetup_state); + struct sesssetup_state *state = talloc_get_type(c->private_data, struct sesssetup_state); const struct samr_Password *nt_hash = cli_credentials_get_nt_hash(io->in.credentials, state); const char *password = cli_credentials_get_password(io->in.credentials); @@ -252,7 +253,7 @@ static NTSTATUS session_setup_old(struct composite_context *c, struct smb_composite_sesssetup *io, struct smbcli_request **req) { - struct sesssetup_state *state = talloc_get_type(c->private, struct sesssetup_state); + struct sesssetup_state *state = talloc_get_type(c->private_data, struct sesssetup_state); const char *password = cli_credentials_get_password(io->in.credentials); state->setup.old.level = RAW_SESSSETUP_OLD; @@ -293,7 +294,7 @@ static NTSTATUS session_setup_spnego(struct composite_context *c, struct smb_composite_sesssetup *io, struct smbcli_request **req) { - struct sesssetup_state *state = talloc_get_type(c->private, struct sesssetup_state); + struct sesssetup_state *state = talloc_get_type(c->private_data, struct sesssetup_state); NTSTATUS status, session_key_err; DATA_BLOB session_key = data_blob(NULL, 0); DATA_BLOB null_data_blob = data_blob(NULL, 0); @@ -397,20 +398,20 @@ struct composite_context *smb_composite_sesssetup_send(struct smbcli_session *se state = talloc(c, struct sesssetup_state); if (state == NULL) { - c->state = SMBCLI_REQUEST_ERROR; + c->state = COMPOSITE_STATE_ERROR; c->status = NT_STATUS_NO_MEMORY; } state->io = io; - c->state = SMBCLI_REQUEST_SEND; - c->private = state; + c->state = COMPOSITE_STATE_IN_PROGRESS; + c->private_data = state; c->event_ctx = session->transport->socket->event.ctx; /* no session setup at all in earliest protocol varients */ if (session->transport->negotiate.protocol < PROTOCOL_LANMAN1) { ZERO_STRUCT(io->out); - c->state = SMBCLI_REQUEST_DONE; + c->state = COMPOSITE_STATE_DONE; return c; } @@ -431,7 +432,7 @@ struct composite_context *smb_composite_sesssetup_send(struct smbcli_session *se return c; } - c->state = SMBCLI_REQUEST_ERROR; + c->state = COMPOSITE_STATE_ERROR; c->status = status; return c; } diff --git a/source4/libcli/smb_composite/smb_composite.h b/source4/libcli/smb_composite/smb_composite.h new file mode 100644 index 0000000000..08031c2f4b --- /dev/null +++ b/source4/libcli/smb_composite/smb_composite.h @@ -0,0 +1,152 @@ +/* + Unix SMB/CIFS implementation. + + SMB composite request interfaces + + Copyright (C) Andrew Tridgell 2005 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +/* + this defines the structures associated with "composite" + requests. Composite requests are libcli requests that are internally + implemented as multiple libcli/raw/ calls, but can be treated as a + single call via these composite calls. The composite calls are + particularly designed to be used in async applications +*/ + + +/* + a composite open/read(s)/close request that loads a whole file + into memory. Used as a demo of the composite system. +*/ +struct smb_composite_loadfile { + struct { + const char *fname; + } in; + struct { + uint8_t *data; + uint32_t size; + } out; +}; + +struct smb_composite_fetchfile { + struct { + const char *dest_host; + int port; + const char *called_name; + const char *service; + const char *service_type; + struct cli_credentials *credentials; + const char *workgroup; + const char *filename; + } in; + struct { + uint8_t *data; + uint32_t size; + } out; +}; + +/* + a composite open/write(s)/close request that saves a whole file from + memory. Used as a demo of the composite system. +*/ +struct smb_composite_savefile { + struct { + const char *fname; + uint8_t *data; + uint32_t size; + } in; +}; + + +/* + a composite request for a full connection to a remote server. Includes + + - socket establishment + - session request + - negprot + - session setup + - tree connect +*/ +struct smb_composite_connect { + struct { + const char *dest_host; + int port; + const char *called_name; + const char *service; + const char *service_type; + struct cli_credentials *credentials; + const char *workgroup; + } in; + struct { + struct smbcli_tree *tree; + } out; +}; + + +/* + generic session setup interface that takes care of which + session setup varient to use +*/ +struct smb_composite_sesssetup { + struct { + uint32_t sesskey; + uint32_t capabilities; + struct cli_credentials *credentials; + const char *workgroup; + } in; + struct { + uint16_t vuid; + } out; +}; + +/* + query file system info +*/ +struct smb_composite_fsinfo { + struct { + const char *dest_host; + int port; + const char *called_name; + const char *service; + const char *service_type; + struct cli_credentials *credentials; + const char *workgroup; + enum smb_fsinfo_level level; + } in; + + struct { + union smb_fsinfo *fsinfo; + } out; +}; + +/* + composite call for appending new acl to the file's security descriptor and get + new full acl +*/ + +struct smb_composite_appendacl { + struct { + const char *fname; + + const struct security_descriptor *sd; + } in; + + struct { + struct security_descriptor *sd; + } out; +}; |