1 /* 2 Unix SMB/CIFS implementation. 3 4 SMB composite request interfaces 5 6 Copyright (C) Andrew Tridgell 2005 7 8 This program is free software; you can redistribute it and/or modify 9 it under the terms of the GNU General Public License as published by 10 the Free Software Foundation; either version 3 of the License, or 11 (at your option) any later version. 12 13 This program is distributed in the hope that it will be useful, 14 but WITHOUT ANY WARRANTY; without even the implied warranty of 15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 GNU General Public License for more details. 17 18 You should have received a copy of the GNU General Public License 19 along with this program. If not, see <http://www.gnu.org/licenses/>. 20 */ 21 22 /* 23 this defines the structures associated with "composite" 24 requests. Composite requests are libcli requests that are internally 25 implemented as multiple libcli/raw/ calls, but can be treated as a 26 single call via these composite calls. The composite calls are 27 particularly designed to be used in async applications 28 */ 29 30 #ifndef __SMB_COMPOSITE_H__ 31 #define __SMB_COMPOSITE_H__ 32 33 #include "libcli/raw/libcliraw.h" 34 #include "libcli/smb2/smb2.h" 35 36 /* 37 a composite open/read(s)/close request that loads a whole file 38 into memory. Used as a demo of the composite system. 39 */ 40 struct smb_composite_loadfile { 41 struct { 42 const char *fname; 43 } in; 44 struct { 45 uint8_t *data; 46 uint32_t size; 47 } out; 48 }; 49 50 struct composite_context *smb_composite_loadfile_send(struct smbcli_tree *tree, 51 struct smb_composite_loadfile *io); 52 NTSTATUS smb_composite_loadfile_recv(struct composite_context *c, TALLOC_CTX *mem_ctx); 53 NTSTATUS smb_composite_loadfile(struct smbcli_tree *tree, 54 TALLOC_CTX *mem_ctx, 55 struct smb_composite_loadfile *io); 56 57 struct smb_composite_fetchfile { 58 struct { 59 const char *dest_host; 60 const char **ports; 61 const char *called_name; 62 const char *service; 63 const char *service_type; 64 const char *socket_options; 65 struct cli_credentials *credentials; 66 const char *workgroup; 67 const char *filename; 68 struct smbcli_options options; 69 struct smbcli_session_options session_options; 70 struct resolve_context *resolve_ctx; 71 struct gensec_settings *gensec_settings; 72 } in; 73 struct { 74 uint8_t *data; 75 uint32_t size; 76 } out; 77 }; 78 79 struct composite_context *smb_composite_fetchfile_send(struct smb_composite_fetchfile *io, 80 struct tevent_context *event_ctx); 81 NTSTATUS smb_composite_fetchfile_recv(struct composite_context *c, 82 TALLOC_CTX *mem_ctx); 83 NTSTATUS smb_composite_fetchfile(struct smb_composite_fetchfile *io, 84 TALLOC_CTX *mem_ctx); 85 86 /* 87 a composite open/write(s)/close request that saves a whole file from 88 memory. Used as a demo of the composite system. 89 */ 90 struct smb_composite_savefile { 91 struct { 92 const char *fname; 93 uint8_t *data; 94 uint32_t size; 95 } in; 96 }; 97 98 struct composite_context *smb_composite_savefile_send(struct smbcli_tree *tree, 99 struct smb_composite_savefile *io); 100 NTSTATUS smb_composite_savefile_recv(struct composite_context *c); 101 NTSTATUS smb_composite_savefile(struct smbcli_tree *tree, 102 struct smb_composite_savefile *io); 103 104 /* 105 a composite request for a low level connection to a remote server. Includes 106 107 - socket establishment 108 - session request 109 - negprot 110 */ 111 struct tevent_req *smb_connect_nego_send(TALLOC_CTX *mem_ctx, 112 struct tevent_context *ev, 113 struct resolve_context *resolve_ctx, 114 const struct smbcli_options *options, 115 const char *socket_options, 116 const char *dest_hostname, 117 const char *dest_address, /* optional */ 118 const char **dest_ports, 119 const char *target_hostname, 120 const char *called_name, 121 const char *calling_name); 122 NTSTATUS smb_connect_nego_recv(struct tevent_req *req, 123 TALLOC_CTX *mem_ctx, 124 struct smbXcli_conn **_conn); 125 126 /* 127 a composite request for a full connection to a remote server. Includes 128 129 - socket establishment 130 - session request 131 - negprot 132 - session setup (if credentials are not NULL) 133 - tree connect (if service is not NULL) 134 */ 135 struct smb_composite_connect { 136 struct { 137 const char *dest_host; 138 const char **dest_ports; 139 const char *socket_options; 140 const char *called_name; 141 const char *service; 142 const char *service_type; 143 struct smbXcli_conn *existing_conn; /* optional */ 144 struct cli_credentials *credentials; 145 bool fallback_to_anonymous; 146 const char *workgroup; 147 struct smbcli_options options; 148 struct smbcli_session_options session_options; 149 struct gensec_settings *gensec_settings; 150 } in; 151 struct { 152 struct smbcli_tree *tree; 153 bool anonymous_fallback_done; 154 } out; 155 }; 156 157 struct composite_context *smb_composite_connect_send(struct smb_composite_connect *io, 158 TALLOC_CTX *mem_ctx, 159 struct resolve_context *resolve_ctx, 160 struct tevent_context *event_ctx); 161 NTSTATUS smb_composite_connect_recv(struct composite_context *c, TALLOC_CTX *mem_ctx); 162 NTSTATUS smb_composite_connect(struct smb_composite_connect *io, TALLOC_CTX *mem_ctx, 163 struct resolve_context *resolve_ctx, 164 struct tevent_context *ev); 165 166 167 /* 168 generic session setup interface that takes care of which 169 session setup varient to use 170 */ 171 struct smb_composite_sesssetup { 172 struct { 173 uint32_t sesskey; 174 uint32_t capabilities; 175 struct cli_credentials *credentials; 176 const char *workgroup; 177 struct gensec_settings *gensec_settings; 178 } in; 179 struct { 180 uint16_t vuid; 181 } out; 182 }; 183 184 struct composite_context *smb_composite_sesssetup_send(struct smbcli_session *session, 185 struct smb_composite_sesssetup *io); 186 NTSTATUS smb_composite_sesssetup_recv(struct composite_context *c); 187 NTSTATUS smb_composite_sesssetup(struct smbcli_session *session, struct smb_composite_sesssetup *io); 188 189 /* 190 query file system info 191 */ 192 struct smb_composite_fsinfo { 193 struct { 194 const char *dest_host; 195 const char **dest_ports; 196 const char *socket_options; 197 const char *called_name; 198 const char *service; 199 const char *service_type; 200 struct cli_credentials *credentials; 201 const char *workgroup; 202 enum smb_fsinfo_level level; 203 struct gensec_settings *gensec_settings; 204 } in; 205 206 struct { 207 union smb_fsinfo *fsinfo; 208 } out; 209 }; 210 211 struct composite_context *smb_composite_fsinfo_send(struct smbcli_tree *tree, 212 struct smb_composite_fsinfo *io, 213 struct resolve_context *resolve_ctx, 214 struct tevent_context *event_ctx); 215 NTSTATUS smb_composite_fsinfo_recv(struct composite_context *c, TALLOC_CTX *mem_ctx); 216 NTSTATUS smb_composite_fsinfo(struct smbcli_tree *tree, 217 TALLOC_CTX *mem_ctx, 218 struct smb_composite_fsinfo *io, 219 struct resolve_context *resolve_ctx, 220 struct tevent_context *ev); 221 222 /* 223 composite call for appending new acl to the file's security descriptor and get 224 new full acl 225 */ 226 227 struct smb_composite_appendacl { 228 struct { 229 const char *fname; 230 231 const struct security_descriptor *sd; 232 } in; 233 234 struct { 235 struct security_descriptor *sd; 236 } out; 237 }; 238 239 struct composite_context *smb_composite_appendacl_send(struct smbcli_tree *tree, 240 struct smb_composite_appendacl *io); 241 NTSTATUS smb_composite_appendacl_recv(struct composite_context *c, TALLOC_CTX *mem_ctx); 242 NTSTATUS smb_composite_appendacl(struct smbcli_tree *tree, 243 TALLOC_CTX *mem_ctx, 244 struct smb_composite_appendacl *io); 245 246 /* 247 a composite API to fire connect() calls to multiple targets, picking the 248 first one. 249 */ 250 251 struct smb_composite_connectmulti { 252 struct { 253 int num_dests; 254 const char **hostnames; 255 const char **addresses; 256 int *ports; /* Either NULL for lpcfg_smb_ports() per 257 * destination or a list of explicit ports */ 258 } in; 259 struct { 260 struct smbcli_socket *socket; 261 } out; 262 }; 263 264 struct smbcli_session; 265 struct resolve_context; 266 267 struct composite_context *smb2_composite_unlink_send(struct smb2_tree *tree, 268 union smb_unlink *io); 269 NTSTATUS smb2_composite_unlink(struct smb2_tree *tree, union smb_unlink *io); 270 struct composite_context *smb2_composite_mkdir_send(struct smb2_tree *tree, 271 union smb_mkdir *io); 272 NTSTATUS smb2_composite_mkdir(struct smb2_tree *tree, union smb_mkdir *io); 273 struct composite_context *smb2_composite_rmdir_send(struct smb2_tree *tree, 274 struct smb_rmdir *io); 275 NTSTATUS smb2_composite_rmdir(struct smb2_tree *tree, struct smb_rmdir *io); 276 struct tevent_req *smb2_composite_setpathinfo_send(TALLOC_CTX *mem_ctx, 277 struct tevent_context *ev, 278 struct smb2_tree *tree, 279 const union smb_setfileinfo *io); 280 NTSTATUS smb2_composite_setpathinfo_recv(struct tevent_req *req); 281 NTSTATUS smb2_composite_setpathinfo(struct smb2_tree *tree, union smb_setfileinfo *io); 282 283 #endif /* __SMB_COMPOSITE_H__ */ 284