From ef2e26c91b80556af033d3335e55f5dfa6fff31d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 13 Aug 2003 01:53:07 +0000 Subject: first public release of samba4 code (This used to be commit b0510b5428b3461aeb9bbe3cc95f62fc73e2b97f) --- source4/libcli/raw/README | 5 + source4/libcli/raw/clikrb5.c | 399 ++++++++++++++ source4/libcli/raw/clioplock.c | 57 ++ source4/libcli/raw/clirewrite.c | 22 + source4/libcli/raw/clisession.c | 444 +++++++++++++++ source4/libcli/raw/clisocket.c | 148 +++++ source4/libcli/raw/clispnego.c | 533 ++++++++++++++++++ source4/libcli/raw/clitransport.c | 218 ++++++++ source4/libcli/raw/clitree.c | 290 ++++++++++ source4/libcli/raw/raweas.c | 147 +++++ source4/libcli/raw/rawfile.c | 687 +++++++++++++++++++++++ source4/libcli/raw/rawfileinfo.c | 527 ++++++++++++++++++ source4/libcli/raw/rawfsinfo.c | 282 ++++++++++ source4/libcli/raw/rawioctl.c | 118 ++++ source4/libcli/raw/rawnegotiate.c | 157 ++++++ source4/libcli/raw/rawnotify.c | 116 ++++ source4/libcli/raw/rawreadwrite.c | 321 +++++++++++ source4/libcli/raw/rawrequest.c | 1019 +++++++++++++++++++++++++++++++++++ source4/libcli/raw/rawsearch.c | 569 +++++++++++++++++++ source4/libcli/raw/rawsetfileinfo.c | 335 ++++++++++++ source4/libcli/raw/rawtrans.c | 489 +++++++++++++++++ source4/libcli/raw/smb_signing.c | 341 ++++++++++++ 22 files changed, 7224 insertions(+) create mode 100644 source4/libcli/raw/README create mode 100644 source4/libcli/raw/clikrb5.c create mode 100644 source4/libcli/raw/clioplock.c create mode 100644 source4/libcli/raw/clirewrite.c create mode 100644 source4/libcli/raw/clisession.c create mode 100644 source4/libcli/raw/clisocket.c create mode 100644 source4/libcli/raw/clispnego.c create mode 100644 source4/libcli/raw/clitransport.c create mode 100644 source4/libcli/raw/clitree.c create mode 100644 source4/libcli/raw/raweas.c create mode 100644 source4/libcli/raw/rawfile.c create mode 100644 source4/libcli/raw/rawfileinfo.c create mode 100644 source4/libcli/raw/rawfsinfo.c create mode 100644 source4/libcli/raw/rawioctl.c create mode 100644 source4/libcli/raw/rawnegotiate.c create mode 100644 source4/libcli/raw/rawnotify.c create mode 100644 source4/libcli/raw/rawreadwrite.c create mode 100644 source4/libcli/raw/rawrequest.c create mode 100644 source4/libcli/raw/rawsearch.c create mode 100644 source4/libcli/raw/rawsetfileinfo.c create mode 100644 source4/libcli/raw/rawtrans.c create mode 100644 source4/libcli/raw/smb_signing.c (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/README b/source4/libcli/raw/README new file mode 100644 index 0000000000..cb3e507e3a --- /dev/null +++ b/source4/libcli/raw/README @@ -0,0 +1,5 @@ +Design notes for client library restructure: + +1 - no references to cli_state should exist in libcli/raw. +2 - all interfaces to functions in this directory should use cli_session or cli_tree as + the primary context structure \ No newline at end of file diff --git a/source4/libcli/raw/clikrb5.c b/source4/libcli/raw/clikrb5.c new file mode 100644 index 0000000000..5edc56daa9 --- /dev/null +++ b/source4/libcli/raw/clikrb5.c @@ -0,0 +1,399 @@ +/* + Unix SMB/CIFS implementation. + simple kerberos5 routines for active directory + Copyright (C) Andrew Tridgell 2001 + Copyright (C) Luke Howard 2002-2003 + + 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. +*/ + +#include "includes.h" + +#ifdef HAVE_KRB5 + +#ifdef HAVE_KRB5_KEYBLOCK_KEYVALUE +#define KRB5_KEY_TYPE(k) ((k)->keytype) +#define KRB5_KEY_LENGTH(k) ((k)->keyvalue.length) +#define KRB5_KEY_DATA(k) ((k)->keyvalue.data) +#else +#define KRB5_KEY_TYPE(k) ((k)->enctype) +#define KRB5_KEY_LENGTH(k) ((k)->length) +#define KRB5_KEY_DATA(k) ((k)->contents) +#endif /* HAVE_KRB5_KEYBLOCK_KEYVALUE */ + +#ifndef HAVE_KRB5_SET_REAL_TIME +/* + * This function is not in the Heimdal mainline. + */ + krb5_error_code krb5_set_real_time(krb5_context context, int32_t seconds, int32_t microseconds) +{ + krb5_error_code ret; + int32_t sec, usec; + + ret = krb5_us_timeofday(context, &sec, &usec); + if (ret) + return ret; + + context->kdc_sec_offset = seconds - sec; + context->kdc_usec_offset = microseconds - usec; + + return 0; +} +#endif + +#if defined(HAVE_KRB5_SET_DEFAULT_IN_TKT_ETYPES) && !defined(HAVE_KRB5_SET_DEFAULT_TGS_KTYPES) + krb5_error_code krb5_set_default_tgs_ktypes(krb5_context ctx, const krb5_enctype *enc) +{ + return krb5_set_default_in_tkt_etypes(ctx, enc); +} +#endif + +#if defined(HAVE_ADDR_TYPE_IN_KRB5_ADDRESS) +/* HEIMDAL */ + void setup_kaddr( krb5_address *pkaddr, struct sockaddr *paddr) +{ + pkaddr->addr_type = KRB5_ADDRESS_INET; + pkaddr->address.length = sizeof(((struct sockaddr_in *)paddr)->sin_addr); + pkaddr->address.data = (char *)&(((struct sockaddr_in *)paddr)->sin_addr); +} +#elif defined(HAVE_ADDRTYPE_IN_KRB5_ADDRESS) +/* MIT */ + void setup_kaddr( krb5_address *pkaddr, struct sockaddr *paddr) +{ + pkaddr->addrtype = ADDRTYPE_INET; + pkaddr->length = sizeof(((struct sockaddr_in *)paddr)->sin_addr); + pkaddr->contents = (char *)&(((struct sockaddr_in *)paddr)->sin_addr); +} +#else + __ERROR__XX__UNKNOWN_ADDRTYPE +#endif + +#if defined(HAVE_KRB5_PRINCIPAL2SALT) && defined(HAVE_KRB5_USE_ENCTYPE) && defined(HAVE_KRB5_STRING_TO_KEY) + int create_kerberos_key_from_string(krb5_context context, + krb5_principal host_princ, + krb5_data *password, + krb5_keyblock *key, + krb5_enctype enctype) +{ + int ret; + krb5_data salt; + krb5_encrypt_block eblock; + + ret = krb5_principal2salt(context, host_princ, &salt); + if (ret) { + DEBUG(1,("krb5_principal2salt failed (%s)\n", error_message(ret))); + return ret; + } + krb5_use_enctype(context, &eblock, enctype); + return krb5_string_to_key(context, &eblock, key, password, &salt); +} +#elif defined(HAVE_KRB5_GET_PW_SALT) && defined(HAVE_KRB5_STRING_TO_KEY_SALT) + int create_kerberos_key_from_string(krb5_context context, + krb5_principal host_princ, + krb5_data *password, + krb5_keyblock *key, + krb5_enctype enctype) +{ + int ret; + krb5_salt salt; + + ret = krb5_get_pw_salt(context, host_princ, &salt); + if (ret) { + DEBUG(1,("krb5_get_pw_salt failed (%s)\n", error_message(ret))); + return ret; + } + return krb5_string_to_key_salt(context, enctype, password->data, + salt, key); +} +#else + __ERROR_XX_UNKNOWN_CREATE_KEY_FUNCTIONS +#endif + +#if defined(HAVE_KRB5_GET_PERMITTED_ENCTYPES) +krb5_error_code get_kerberos_allowed_etypes(krb5_context context, + krb5_enctype **enctypes) +{ + return krb5_get_permitted_enctypes(context, enctypes); +} +#elif defined(HAVE_KRB5_GET_DEFAULT_IN_TKT_ETYPES) +krb5_error_code get_kerberos_allowed_etypes(krb5_context context, + krb5_enctype **enctypes) +{ + return krb5_get_default_in_tkt_etypes(context, enctypes); +} +#else +#error UNKNOWN_GET_ENCTYPES_FUNCTIONS +#endif + + void free_kerberos_etypes(krb5_context context, + krb5_enctype *enctypes) +{ +#if defined(HAVE_KRB5_FREE_KTYPES) + krb5_free_ktypes(context, enctypes); + return; +#else + SAFE_FREE(enctypes); + return; +#endif +} + +#if defined(HAVE_KRB5_AUTH_CON_SETKEY) && !defined(HAVE_KRB5_AUTH_CON_SETUSERUSERKEY) + krb5_error_code krb5_auth_con_setuseruserkey(krb5_context context, + krb5_auth_context auth_context, + krb5_keyblock *keyblock) +{ + return krb5_auth_con_setkey(context, auth_context, keyblock); +} +#endif + + void get_auth_data_from_tkt(DATA_BLOB *auth_data, krb5_ticket *tkt) +{ +#if defined(HAVE_KRB5_TKT_ENC_PART2) + if (tkt->enc_part2) + *auth_data = data_blob(tkt->enc_part2->authorization_data[0]->contents, + tkt->enc_part2->authorization_data[0]->length); +#else + if (tkt->ticket.authorization_data && tkt->ticket.authorization_data->len) + *auth_data = data_blob(tkt->ticket.authorization_data->val->ad_data.data, + tkt->ticket.authorization_data->val->ad_data.length); +#endif +} + + krb5_const_principal get_principal_from_tkt(krb5_ticket *tkt) +{ +#if defined(HAVE_KRB5_TKT_ENC_PART2) + return tkt->enc_part2->client; +#else + return tkt->client; +#endif +} + +#if !defined(HAVE_KRB5_LOCATE_KDC) + krb5_error_code krb5_locate_kdc(krb5_context ctx, const krb5_data *realm, struct sockaddr **addr_pp, int *naddrs, int get_masters) +{ + krb5_krbhst_handle hnd; + krb5_krbhst_info *hinfo; + krb5_error_code rc; + int num_kdcs, i; + struct sockaddr *sa; + + *addr_pp = NULL; + *naddrs = 0; + + rc = krb5_krbhst_init(ctx, realm->data, KRB5_KRBHST_KDC, &hnd); + if (rc) { + DEBUG(0, ("krb5_locate_kdc: krb5_krbhst_init failed (%s)\n", error_message(rc))); + return rc; + } + + for ( num_kdcs = 0; (rc = krb5_krbhst_next(ctx, hnd, &hinfo) == 0); num_kdcs++) + ; + + krb5_krbhst_reset(ctx, hnd); + + if (!num_kdcs) { + DEBUG(0, ("krb5_locate_kdc: zero kdcs found !\n")); + krb5_krbhst_free(ctx, hnd); + return -1; + } + + sa = malloc( sizeof(struct sockaddr) * num_kdcs ); + if (!sa) { + DEBUG(0, ("krb5_locate_kdc: malloc failed\n")); + krb5_krbhst_free(ctx, hnd); + naddrs = 0; + return -1; + } + + memset(*addr_pp, '\0', sizeof(struct sockaddr) * num_kdcs ); + + for (i = 0; i < num_kdcs && (rc = krb5_krbhst_next(ctx, hnd, &hinfo) == 0); i++) { + if (hinfo->ai->ai_family == AF_INET) + memcpy(&sa[i], hinfo->ai->ai_addr, sizeof(struct sockaddr)); + } + + krb5_krbhst_free(ctx, hnd); + + *naddrs = num_kdcs; + *addr_pp = sa; + return 0; +} +#endif + +/* + we can't use krb5_mk_req because w2k wants the service to be in a particular format +*/ +static krb5_error_code krb5_mk_req2(krb5_context context, + krb5_auth_context *auth_context, + const krb5_flags ap_req_options, + const char *principal, + krb5_ccache ccache, + krb5_data *outbuf) +{ + krb5_error_code retval; + krb5_principal server; + krb5_creds * credsp; + krb5_creds creds; + krb5_data in_data; + + retval = krb5_parse_name(context, principal, &server); + if (retval) { + DEBUG(1,("Failed to parse principal %s\n", principal)); + return retval; + } + + /* obtain ticket & session key */ + memset((char *)&creds, 0, sizeof(creds)); + if ((retval = krb5_copy_principal(context, server, &creds.server))) { + DEBUG(1,("krb5_copy_principal failed (%s)\n", + error_message(retval))); + goto cleanup_princ; + } + + if ((retval = krb5_cc_get_principal(context, ccache, &creds.client))) { + DEBUG(1,("krb5_cc_get_principal failed (%s)\n", + error_message(retval))); + goto cleanup_creds; + } + + if ((retval = krb5_get_credentials(context, 0, + ccache, &creds, &credsp))) { + DEBUG(1,("krb5_get_credentials failed for %s (%s)\n", + principal, error_message(retval))); + goto cleanup_creds; + } + + /* cope with the ticket being in the future due to clock skew */ + if ((unsigned)credsp->times.starttime > time(NULL)) { + time_t t = time(NULL); + int time_offset = (unsigned)credsp->times.starttime - t; + DEBUG(4,("Advancing clock by %d seconds to cope with clock skew\n", time_offset)); + krb5_set_real_time(context, t + time_offset + 1, 0); + } + + in_data.length = 0; + retval = krb5_mk_req_extended(context, auth_context, ap_req_options, + &in_data, credsp, outbuf); + if (retval) { + DEBUG(1,("krb5_mk_req_extended failed (%s)\n", + error_message(retval))); + } + + krb5_free_creds(context, credsp); + +cleanup_creds: + krb5_free_cred_contents(context, &creds); + +cleanup_princ: + krb5_free_principal(context, server); + + return retval; +} + +/* + get a kerberos5 ticket for the given service +*/ +DATA_BLOB krb5_get_ticket(const char *principal, time_t time_offset) +{ + krb5_error_code retval; + krb5_data packet; + krb5_ccache ccdef; + krb5_context context; + krb5_auth_context auth_context = NULL; + DATA_BLOB ret; + krb5_enctype enc_types[] = { +#ifdef ENCTYPE_ARCFOUR_HMAC + ENCTYPE_ARCFOUR_HMAC, +#endif + ENCTYPE_DES_CBC_MD5, + ENCTYPE_DES_CBC_CRC, + ENCTYPE_NULL}; + + retval = krb5_init_context(&context); + if (retval) { + DEBUG(1,("krb5_init_context failed (%s)\n", + error_message(retval))); + goto failed; + } + + if (time_offset != 0) { + krb5_set_real_time(context, time(NULL) + time_offset, 0); + } + + if ((retval = krb5_cc_default(context, &ccdef))) { + DEBUG(1,("krb5_cc_default failed (%s)\n", + error_message(retval))); + goto failed; + } + + if ((retval = krb5_set_default_tgs_ktypes(context, enc_types))) { + DEBUG(1,("krb5_set_default_tgs_ktypes failed (%s)\n", + error_message(retval))); + goto failed; + } + + if ((retval = krb5_mk_req2(context, + &auth_context, + 0, + principal, + ccdef, &packet))) { + goto failed; + } + + ret = data_blob(packet.data, packet.length); +/* Hmm, heimdal dooesn't have this - what's the correct call? */ +/* krb5_free_data_contents(context, &packet); */ + krb5_free_context(context); + return ret; + +failed: + if ( context ) + krb5_free_context(context); + + return data_blob(NULL, 0); +} + + BOOL krb5_get_smb_session_key(krb5_context context, krb5_auth_context auth_context, uint8 session_key[16]) + { +#ifdef ENCTYPE_ARCFOUR_HMAC + krb5_keyblock *skey; +#endif + BOOL ret = False; + + memset(session_key, 0, 16); + +#ifdef ENCTYPE_ARCFOUR_HMAC + if (krb5_auth_con_getremotesubkey(context, auth_context, &skey) == 0 && skey != NULL) { + if (KRB5_KEY_TYPE(skey) == + ENCTYPE_ARCFOUR_HMAC + && KRB5_KEY_LENGTH(skey) == 16) { + memcpy(session_key, KRB5_KEY_DATA(skey), KRB5_KEY_LENGTH(skey)); + ret = True; + } + krb5_free_keyblock(context, skey); + } +#endif /* ENCTYPE_ARCFOUR_HMAC */ + + return ret; + } +#else /* HAVE_KRB5 */ + /* this saves a few linking headaches */ +DATA_BLOB krb5_get_ticket(const char *principal, time_t time_offset) + { + DEBUG(0,("NO KERBEROS SUPPORT\n")); + return data_blob(NULL, 0); + } + +#endif diff --git a/source4/libcli/raw/clioplock.c b/source4/libcli/raw/clioplock.c new file mode 100644 index 0000000000..8f69716bda --- /dev/null +++ b/source4/libcli/raw/clioplock.c @@ -0,0 +1,57 @@ +/* + Unix SMB/CIFS implementation. + SMB client oplock functions + Copyright (C) Andrew Tridgell 2001 + + 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. +*/ + +#include "includes.h" + +/**************************************************************************** +send an ack for an oplock break request +****************************************************************************/ +BOOL cli_oplock_ack(struct cli_tree *tree, uint16 fnum, uint16 ack_level) +{ + BOOL ret; + struct cli_request *req; + + req = cli_request_setup(tree, SMBlockingX, 8, 0); + + SSVAL(req->out.vwv,VWV(0),0xFF); + SSVAL(req->out.vwv,VWV(1),0); + SSVAL(req->out.vwv,VWV(2),fnum); + SSVAL(req->out.vwv,VWV(3),ack_level); + SIVAL(req->out.vwv,VWV(4),0); + SSVAL(req->out.vwv,VWV(6),0); + SSVAL(req->out.vwv,VWV(7),0); + + ret = cli_request_send(req); + cli_request_destroy(req); + + return ret; +} + + +/**************************************************************************** +set the oplock handler for a connection +****************************************************************************/ +void cli_oplock_handler(struct cli_transport *transport, + BOOL (*handler)(struct cli_transport *, uint16, uint16, uint8, void *), + void *private) +{ + transport->oplock.handler = handler; + transport->oplock.private = private; +} diff --git a/source4/libcli/raw/clirewrite.c b/source4/libcli/raw/clirewrite.c new file mode 100644 index 0000000000..2d2e2e3feb --- /dev/null +++ b/source4/libcli/raw/clirewrite.c @@ -0,0 +1,22 @@ +#include "includes.h" + +/* + + this is a set of temporary stub functions used during the libsmb rewrite. + This file will need to go away before the rewrite is complete. +*/ + +void become_root(void) +{} + +void unbecome_root(void) +{} + +BOOL become_user_permanently(uid_t uid, gid_t gid) +{ return True; } + +void set_effective_uid(uid_t uid) +{} + +uid_t sec_initial_uid(void) +{ return 0; } diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c new file mode 100644 index 0000000000..406491e432 --- /dev/null +++ b/source4/libcli/raw/clisession.c @@ -0,0 +1,444 @@ +/* + Unix SMB/CIFS implementation. + SMB client session context management functions + Copyright (C) Andrew Tridgell 1994-1998 + Copyright (C) James Myers 2003 + + 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. +*/ + +#include "includes.h" + +#define SETUP_REQUEST_SESSION(cmd, wct, buflen) do { \ + req = cli_request_setup_session(session, cmd, wct, buflen); \ + if (!req) return NULL; \ +} while (0) + +/**************************************************************************** + Initialize the session context +****************************************************************************/ +struct cli_session *cli_session_init(struct cli_transport *transport) +{ + struct cli_session *session; + TALLOC_CTX *mem_ctx = talloc_init("cli_session"); + if (mem_ctx == NULL) { + return NULL; + } + + session = talloc_zero(mem_ctx, sizeof(*session)); + if (!session) { + talloc_destroy(mem_ctx); + return NULL; + } + + session->mem_ctx = mem_ctx; + session->transport = transport; + session->pid = (uint16)getpid(); + session->vuid = UID_FIELD_INVALID; + session->transport->reference_count++; + + return session; +} + +/**************************************************************************** +reduce reference_count and destroy is <= 0 +****************************************************************************/ +void cli_session_close(struct cli_session *session) +{ + session->reference_count--; + if (session->reference_count <= 0) { + cli_transport_close(session->transport); + talloc_destroy(session->mem_ctx); + } +} + +/**************************************************************************** + Perform a session setup (async send) +****************************************************************************/ +struct cli_request *smb_raw_session_setup_send(struct cli_session *session, union smb_sesssetup *parms) +{ + struct cli_request *req; + + switch (parms->generic.level) { + case RAW_SESSSETUP_GENERIC: + /* handled elsewhere */ + return NULL; + + case RAW_SESSSETUP_OLD: + SETUP_REQUEST_SESSION(SMBsesssetupX, 10, 0); + SSVAL(req->out.vwv, VWV(0), SMB_CHAIN_NONE); + SSVAL(req->out.vwv, VWV(1), 0); + SSVAL(req->out.vwv,VWV(2),parms->old.in.bufsize); + SSVAL(req->out.vwv,VWV(3),parms->old.in.mpx_max); + SSVAL(req->out.vwv,VWV(4),parms->old.in.vc_num); + SIVAL(req->out.vwv,VWV(5),parms->old.in.sesskey); + SSVAL(req->out.vwv,VWV(7),parms->old.in.password.length); + cli_req_append_blob(req, &parms->old.in.password); + cli_req_append_string(req, parms->old.in.user, STR_TERMINATE); + cli_req_append_string(req, parms->old.in.domain, STR_TERMINATE|STR_UPPER); + cli_req_append_string(req, parms->old.in.os, STR_TERMINATE); + cli_req_append_string(req, parms->old.in.lanman, STR_TERMINATE); + break; + + case RAW_SESSSETUP_NT1: + SETUP_REQUEST_SESSION(SMBsesssetupX, 13, 0); + SSVAL(req->out.vwv, VWV(0), SMB_CHAIN_NONE); + SSVAL(req->out.vwv, VWV(1), 0); + SSVAL(req->out.vwv, VWV(2), parms->nt1.in.bufsize); + SSVAL(req->out.vwv, VWV(3), parms->nt1.in.mpx_max); + SSVAL(req->out.vwv, VWV(4), parms->nt1.in.vc_num); + SIVAL(req->out.vwv, VWV(5), parms->nt1.in.sesskey); + SSVAL(req->out.vwv, VWV(7), parms->nt1.in.password1.length); + SSVAL(req->out.vwv, VWV(8), parms->nt1.in.password2.length); + SIVAL(req->out.vwv, VWV(9), 0); /* reserved */ + SIVAL(req->out.vwv, VWV(11), parms->nt1.in.capabilities); + cli_req_append_blob(req, &parms->nt1.in.password1); + cli_req_append_blob(req, &parms->nt1.in.password2); + cli_req_append_string(req, parms->nt1.in.user, STR_TERMINATE); + cli_req_append_string(req, parms->nt1.in.domain, STR_TERMINATE|STR_UPPER); + cli_req_append_string(req, parms->nt1.in.os, STR_TERMINATE); + cli_req_append_string(req, parms->nt1.in.lanman, STR_TERMINATE); + break; + + case RAW_SESSSETUP_SPNEGO: + SETUP_REQUEST_SESSION(SMBsesssetupX, 12, 0); + SSVAL(req->out.vwv, VWV(0), SMB_CHAIN_NONE); + SSVAL(req->out.vwv, VWV(1), 0); + SSVAL(req->out.vwv, VWV(2), parms->spnego.in.bufsize); + SSVAL(req->out.vwv, VWV(3), parms->spnego.in.mpx_max); + SSVAL(req->out.vwv, VWV(4), parms->spnego.in.vc_num); + SIVAL(req->out.vwv, VWV(5), parms->spnego.in.sesskey); + SSVAL(req->out.vwv, VWV(7), parms->spnego.in.secblob.length); + SIVAL(req->out.vwv, VWV(10), parms->spnego.in.capabilities); + cli_req_append_blob(req, &parms->spnego.in.secblob); + cli_req_append_string(req, parms->spnego.in.os, STR_TERMINATE); + cli_req_append_string(req, parms->spnego.in.lanman, STR_TERMINATE); + break; + } + + if (!cli_request_send(req)) { + cli_request_destroy(req); + return NULL; + } + + return req; +} + + +/**************************************************************************** + Perform a session setup (async recv) +****************************************************************************/ +NTSTATUS smb_raw_session_setup_recv(struct cli_request *req, + TALLOC_CTX *mem_ctx, + union smb_sesssetup *parms) +{ + uint16 len; + char *p; + + if (!cli_request_receive(req)) { + return cli_request_destroy(req); + } + + if (!NT_STATUS_IS_OK(req->status) && + !NT_STATUS_EQUAL(req->status,NT_STATUS_MORE_PROCESSING_REQUIRED)) { + return cli_request_destroy(req); + } + + switch (parms->generic.level) { + case RAW_SESSSETUP_GENERIC: + /* handled elsewhere */ + return NT_STATUS_INVALID_LEVEL; + + case RAW_SESSSETUP_OLD: + CLI_CHECK_WCT(req, 3); + ZERO_STRUCT(parms->old.out); + parms->old.out.vuid = SVAL(req->in.hdr, HDR_UID); + parms->old.out.action = SVAL(req->in.vwv, VWV(2)); + p = req->in.data; + if (p) { + p += cli_req_pull_string(req, mem_ctx, &parms->old.out.os, p, -1, STR_TERMINATE); + p += cli_req_pull_string(req, mem_ctx, &parms->old.out.lanman, p, -1, STR_TERMINATE); + p += cli_req_pull_string(req, mem_ctx, &parms->old.out.domain, p, -1, STR_TERMINATE); + } + break; + + case RAW_SESSSETUP_NT1: + CLI_CHECK_WCT(req, 3); + ZERO_STRUCT(parms->nt1.out); + parms->nt1.out.vuid = SVAL(req->in.hdr, HDR_UID); + parms->nt1.out.action = SVAL(req->in.vwv, VWV(2)); + p = req->in.data; + if (p) { + p += cli_req_pull_string(req, mem_ctx, &parms->nt1.out.os, p, -1, STR_TERMINATE); + p += cli_req_pull_string(req, mem_ctx, &parms->nt1.out.lanman, p, -1, STR_TERMINATE); + if (p < (req->in.data + req->in.data_size)) { + p += cli_req_pull_string(req, mem_ctx, &parms->nt1.out.domain, p, -1, STR_TERMINATE); + } + } + break; + + case RAW_SESSSETUP_SPNEGO: + CLI_CHECK_WCT(req, 4); + ZERO_STRUCT(parms->spnego.out); + parms->spnego.out.vuid = SVAL(req->in.hdr, HDR_UID); + parms->spnego.out.action = SVAL(req->in.vwv, VWV(2)); + len = SVAL(req->in.vwv, VWV(3)); + p = req->in.data; + if (!p) { + break; + } + + parms->spnego.out.secblob = cli_req_pull_blob(req, mem_ctx, p, len); + p += parms->spnego.out.secblob.length; + p += cli_req_pull_string(req, mem_ctx, &parms->spnego.out.os, p, -1, STR_TERMINATE); + p += cli_req_pull_string(req, mem_ctx, &parms->spnego.out.lanman, p, -1, STR_TERMINATE); + p += cli_req_pull_string(req, mem_ctx, &parms->spnego.out.domain, p, -1, STR_TERMINATE); + break; + } + +failed: + return cli_request_destroy(req); +} + +/* + form an encrypted lanman password from a plaintext password + and the server supplied challenge +*/ +static DATA_BLOB lanman_blob(const char *pass, DATA_BLOB challenge) +{ + DATA_BLOB blob = data_blob(NULL, 24); + SMBencrypt(pass, challenge.data, blob.data); + return blob; +} + +/* + form an encrypted NT password from a plaintext password + and the server supplied challenge +*/ +static DATA_BLOB nt_blob(const char *pass, DATA_BLOB challenge) +{ + DATA_BLOB blob = data_blob(NULL, 24); + SMBNTencrypt(pass, challenge.data, blob.data); + return blob; +} + +/* + setup signing for a NT1 style session setup +*/ +static void setup_nt1_signing(struct cli_transport *transport, const char *password) +{ + uchar nt_hash[16]; + uchar session_key[16]; + DATA_BLOB nt_response; + + E_md4hash(password, nt_hash); + SMBsesskeygen_ntv1(nt_hash, NULL, session_key); + nt_response = nt_blob(password, transport->negotiate.secblob); + + cli_transport_simple_set_signing(transport, session_key, nt_response); +} + +/**************************************************************************** + Perform a session setup (sync interface) using generic interface and the old + style sesssetup call +****************************************************************************/ +static NTSTATUS smb_raw_session_setup_generic_old(struct cli_session *session, + TALLOC_CTX *mem_ctx, + union smb_sesssetup *parms) +{ + NTSTATUS status; + union smb_sesssetup s2; + + /* use the old interface */ + s2.generic.level = RAW_SESSSETUP_OLD; + s2.old.in.bufsize = ~0; + s2.old.in.mpx_max = 50; + s2.old.in.vc_num = 1; + s2.old.in.sesskey = parms->generic.in.sesskey; + s2.old.in.domain = parms->generic.in.domain; + s2.old.in.user = parms->generic.in.user; + s2.old.in.os = "Unix"; + s2.old.in.lanman = "Samba"; + + if (session->transport->negotiate.sec_mode & NEGOTIATE_SECURITY_CHALLENGE_RESPONSE) { + s2.old.in.password = lanman_blob(parms->generic.in.password, + session->transport->negotiate.secblob); + } else { + s2.old.in.password = data_blob(parms->generic.in.password, + strlen(parms->generic.in.password)); + } + + status = smb_raw_session_setup(session, mem_ctx, &s2); + + data_blob_free(&s2.old.in.password); + + if (!NT_STATUS_IS_OK(status)) { + return status; + } + + parms->generic.out.vuid = s2.old.out.vuid; + parms->generic.out.os = s2.old.out.os; + parms->generic.out.lanman = s2.old.out.lanman; + parms->generic.out.domain = s2.old.out.domain; + + return NT_STATUS_OK; +} + +/**************************************************************************** + Perform a session setup (sync interface) using generic interface and the NT1 + style sesssetup call +****************************************************************************/ +static NTSTATUS smb_raw_session_setup_generic_nt1(struct cli_session *session, + TALLOC_CTX *mem_ctx, + union smb_sesssetup *parms) +{ + NTSTATUS status; + union smb_sesssetup s2; + + s2.generic.level = RAW_SESSSETUP_NT1; + s2.nt1.in.bufsize = ~0; + s2.nt1.in.mpx_max = 50; + s2.nt1.in.vc_num = 1; + s2.nt1.in.sesskey = parms->generic.in.sesskey; + s2.nt1.in.capabilities = parms->generic.in.capabilities; + s2.nt1.in.domain = parms->generic.in.domain; + s2.nt1.in.user = parms->generic.in.user; + s2.nt1.in.os = "Unix"; + s2.nt1.in.lanman = "Samba"; + + if (session->transport->negotiate.sec_mode & + NEGOTIATE_SECURITY_CHALLENGE_RESPONSE) { + s2.nt1.in.password1 = lanman_blob(parms->generic.in.password, + session->transport->negotiate.secblob); + s2.nt1.in.password2 = nt_blob(parms->generic.in.password, + session->transport->negotiate.secblob); + setup_nt1_signing(session->transport, parms->generic.in.password); + } else { + s2.nt1.in.password1 = data_blob(parms->generic.in.password, + strlen(parms->generic.in.password)); + s2.nt1.in.password2 = data_blob(NULL, 0); + } + + status = smb_raw_session_setup(session, mem_ctx, &s2); + + data_blob_free(&s2.nt1.in.password1); + data_blob_free(&s2.nt1.in.password2); + + if (!NT_STATUS_IS_OK(status)) { + return status; + } + + parms->generic.out.vuid = s2.nt1.out.vuid; + parms->generic.out.os = s2.nt1.out.os; + parms->generic.out.lanman = s2.nt1.out.lanman; + parms->generic.out.domain = s2.nt1.out.domain; + + return NT_STATUS_OK; +} + + +/**************************************************************************** + Perform a session setup (sync interface) using generic interface +****************************************************************************/ +static NTSTATUS smb_raw_session_setup_generic(struct cli_session *session, + TALLOC_CTX *mem_ctx, + union smb_sesssetup *parms) +{ + if (session->transport->negotiate.protocol < PROTOCOL_LANMAN1) { + /* no session setup at all in earliest protocols */ + ZERO_STRUCT(parms->generic.out); + return NT_STATUS_OK; + } + + /* see if we need to use the original session setup interface */ + if (session->transport->negotiate.protocol < PROTOCOL_NT1) { + return smb_raw_session_setup_generic_old(session, mem_ctx, parms); + } + + /* see if we should use the NT1 interface */ + if (!(session->transport->negotiate.capabilities & CAP_EXTENDED_SECURITY) || + !session->transport->options.use_spnego) { + return smb_raw_session_setup_generic_nt1(session, mem_ctx, parms); + } + + /* default to using SPNEGO/NTLMSSP */ + DEBUG(0,("Need to add client SPNEGO code back in\n")); + return NT_STATUS_UNSUCCESSFUL; +} + + +/**************************************************************************** + Perform a session setup (sync interface) +this interface allows for RAW_SESSSETUP_GENERIC to auto-select session +setup varient based on negotiated protocol options +****************************************************************************/ +NTSTATUS smb_raw_session_setup(struct cli_session *session, TALLOC_CTX *mem_ctx, + union smb_sesssetup *parms) +{ + struct cli_request *req; + + if (parms->generic.level == RAW_SESSSETUP_GENERIC) { + return smb_raw_session_setup_generic(session, mem_ctx, parms); + } + + req = smb_raw_session_setup_send(session, parms); + return smb_raw_session_setup_recv(req, mem_ctx, parms); +} + + +/**************************************************************************** + Send a uloggoff (async send) +*****************************************************************************/ +struct cli_request *smb_raw_ulogoff_send(struct cli_session *session) +{ + struct cli_request *req; + + SETUP_REQUEST_SESSION(SMBulogoffX, 2, 0); + + SSVAL(req->out.vwv, VWV(0), SMB_CHAIN_NONE); + SSVAL(req->out.vwv, VWV(1), 0); + + if (!cli_request_send(req)) { + cli_request_destroy(req); + return NULL; + } + + return req; +} + +/**************************************************************************** + Send a uloggoff (sync interface) +*****************************************************************************/ +NTSTATUS smb_raw_ulogoff(struct cli_session *session) +{ + struct cli_request *req = smb_raw_ulogoff_send(session); + return cli_request_simple_recv(req); +} + + +/**************************************************************************** + Send a SMBexit +****************************************************************************/ +NTSTATUS smb_raw_exit(struct cli_session *session) +{ + struct cli_request *req; + + req = cli_request_setup_session(session, SMBexit, 0, 0); + + if (cli_request_send(req)) { + cli_request_receive(req); + } + return cli_request_destroy(req); +} diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c new file mode 100644 index 0000000000..f0e05085c4 --- /dev/null +++ b/source4/libcli/raw/clisocket.c @@ -0,0 +1,148 @@ +/* + Unix SMB/CIFS implementation. + SMB client socket context management functions + Copyright (C) Andrew Tridgell 1994-1998 + Copyright (C) James Myers 2003 + + 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. +*/ + +#include "includes.h" + + +/* + create a cli_socket context +*/ +struct cli_socket *cli_sock_init(void) +{ + struct cli_socket *sock; + TALLOC_CTX *mem_ctx; + + mem_ctx = talloc_init("cli_socket"); + if (!mem_ctx) return NULL; + + sock = talloc_zero(mem_ctx, sizeof(*sock)); + if (!sock) { + talloc_destroy(mem_ctx); + return NULL; + } + + sock->mem_ctx = mem_ctx; + sock->fd = -1; + sock->port = 445; + /* 20 second default timeout */ + sock->timeout = 20000; + + return sock; +} + +/* + connect a cli_socket context to an IP/port pair + if port is 0 then choose 445 then 139 +*/ +BOOL cli_sock_connect(struct cli_socket *sock, struct in_addr *ip, int port) +{ + if (getenv("LIBSMB_PROG")) { + sock->fd = sock_exec(getenv("LIBSMB_PROG")); + return sock->fd != -1; + } + + if (port == 0) { + return cli_sock_connect(sock, ip, 445) || + cli_sock_connect(sock, ip, 139); + } + + sock->dest_ip = *ip; + sock->port = port; + sock->fd = open_socket_out(SOCK_STREAM, + &sock->dest_ip, + sock->port, + LONG_CONNECT_TIMEOUT); + return (sock->fd != -1); +} + + +/**************************************************************************** + reduce socket reference count - if it becomes zero then close +****************************************************************************/ +void cli_sock_close(struct cli_socket *sock) +{ + sock->reference_count--; + if (sock->reference_count <= 0 && sock->fd != -1) { + close(sock->fd); + sock->fd = -1; + } +} + +/**************************************************************************** + Set socket options on a open connection. +****************************************************************************/ +void cli_sock_set_options(struct cli_socket *sock, const char *options) +{ + set_socket_options(sock->fd, options); +} + +/**************************************************************************** + Write to socket. Return amount written. +****************************************************************************/ +ssize_t cli_sock_write(struct cli_socket *sock, const char *data, size_t len) +{ + return write_data(sock->fd, data, len); +} + + +/**************************************************************************** + Read from socket. return amount read +****************************************************************************/ +ssize_t cli_sock_read(struct cli_socket *sock, char *data, size_t len) +{ + return read_data(sock->fd, data, len); +} + +/**************************************************************************** +resolve a hostname and connect +****************************************************************************/ +BOOL cli_sock_connect_byname(struct cli_socket *sock, const char *host, int port) +{ + int name_type = 0x20; + struct in_addr ip; + TALLOC_CTX *mem_ctx; + char *name, *p; + + if (getenv("LIBSMB_PROG")) { + sock->fd = sock_exec(getenv("LIBSMB_PROG")); + return sock->fd != -1; + } + + mem_ctx = talloc_init("cli_sock_connect_byname"); + if (!mem_ctx) return False; + + name = talloc_strdup(mem_ctx, host); + + /* allow hostnames of the form NAME#xx and do a netbios lookup */ + if ((p = strchr(name, '#'))) { + name_type = strtol(p+1, NULL, 16); + *p = 0; + } + + if (!resolve_name(mem_ctx, name, &ip, name_type)) { + talloc_destroy(mem_ctx); + return False; + } + + talloc_destroy(mem_ctx); + + return cli_sock_connect(sock, &ip, port); +} diff --git a/source4/libcli/raw/clispnego.c b/source4/libcli/raw/clispnego.c new file mode 100644 index 0000000000..53f7eb6e7d --- /dev/null +++ b/source4/libcli/raw/clispnego.c @@ -0,0 +1,533 @@ +/* + Unix SMB/CIFS implementation. + simple kerberos5/SPNEGO routines + Copyright (C) Andrew Tridgell 2001 + Copyright (C) Jim McDonough 2002 + Copyright (C) Luke Howard 2003 + + 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. +*/ + +#include "includes.h" + +/* + generate a negTokenInit packet given a GUID, a list of supported + OIDs (the mechanisms) and a principal name string +*/ +DATA_BLOB spnego_gen_negTokenInit(uint8 guid[16], + const char *OIDs[], + const char *principal) +{ + int i; + ASN1_DATA data; + DATA_BLOB ret; + + memset(&data, 0, sizeof(data)); + + asn1_write(&data, guid, 16); + asn1_push_tag(&data,ASN1_APPLICATION(0)); + asn1_write_OID(&data,OID_SPNEGO); + asn1_push_tag(&data,ASN1_CONTEXT(0)); + asn1_push_tag(&data,ASN1_SEQUENCE(0)); + + asn1_push_tag(&data,ASN1_CONTEXT(0)); + asn1_push_tag(&data,ASN1_SEQUENCE(0)); + for (i=0; OIDs[i]; i++) { + asn1_write_OID(&data,OIDs[i]); + } + asn1_pop_tag(&data); + asn1_pop_tag(&data); + + asn1_push_tag(&data, ASN1_CONTEXT(3)); + asn1_push_tag(&data, ASN1_SEQUENCE(0)); + asn1_push_tag(&data, ASN1_CONTEXT(0)); + asn1_write_GeneralString(&data,principal); + asn1_pop_tag(&data); + asn1_pop_tag(&data); + asn1_pop_tag(&data); + + asn1_pop_tag(&data); + asn1_pop_tag(&data); + + asn1_pop_tag(&data); + + if (data.has_error) { + DEBUG(1,("Failed to build negTokenInit at offset %d\n", (int)data.ofs)); + asn1_free(&data); + } + + ret = data_blob(data.data, data.length); + asn1_free(&data); + + return ret; +} + +/* + Generate a negTokenInit as used by the client side ... It has a mechType + (OID), and a mechToken (a security blob) ... + + Really, we need to break out the NTLMSSP stuff as well, because it could be + raw in the packets! +*/ +DATA_BLOB gen_negTokenInit(const char *OID, DATA_BLOB blob) +{ + ASN1_DATA data; + DATA_BLOB ret; + + memset(&data, 0, sizeof(data)); + + asn1_push_tag(&data, ASN1_APPLICATION(0)); + asn1_write_OID(&data,OID_SPNEGO); + asn1_push_tag(&data, ASN1_CONTEXT(0)); + asn1_push_tag(&data, ASN1_SEQUENCE(0)); + + asn1_push_tag(&data, ASN1_CONTEXT(0)); + asn1_push_tag(&data, ASN1_SEQUENCE(0)); + asn1_write_OID(&data, OID); + asn1_pop_tag(&data); + asn1_pop_tag(&data); + + asn1_push_tag(&data, ASN1_CONTEXT(2)); + asn1_write_OctetString(&data,blob.data,blob.length); + asn1_pop_tag(&data); + + asn1_pop_tag(&data); + asn1_pop_tag(&data); + + asn1_pop_tag(&data); + + if (data.has_error) { + DEBUG(1,("Failed to build negTokenInit at offset %d\n", (int)data.ofs)); + asn1_free(&data); + } + + ret = data_blob(data.data, data.length); + asn1_free(&data); + + return ret; +} + +/* + parse a negTokenInit packet giving a GUID, a list of supported + OIDs (the mechanisms) and a principal name string +*/ +BOOL spnego_parse_negTokenInit(DATA_BLOB blob, + char *OIDs[ASN1_MAX_OIDS], + char **principal) +{ + int i; + BOOL ret; + ASN1_DATA data; + + asn1_load(&data, blob); + + asn1_start_tag(&data,ASN1_APPLICATION(0)); + asn1_check_OID(&data,OID_SPNEGO); + asn1_start_tag(&data,ASN1_CONTEXT(0)); + asn1_start_tag(&data,ASN1_SEQUENCE(0)); + + asn1_start_tag(&data,ASN1_CONTEXT(0)); + asn1_start_tag(&data,ASN1_SEQUENCE(0)); + for (i=0; asn1_tag_remaining(&data) > 0 && i < ASN1_MAX_OIDS; i++) { + char *oid = NULL; + asn1_read_OID(&data,&oid); + OIDs[i] = oid; + } + OIDs[i] = NULL; + asn1_end_tag(&data); + asn1_end_tag(&data); + + asn1_start_tag(&data, ASN1_CONTEXT(3)); + asn1_start_tag(&data, ASN1_SEQUENCE(0)); + asn1_start_tag(&data, ASN1_CONTEXT(0)); + asn1_read_GeneralString(&data,principal); + asn1_end_tag(&data); + asn1_end_tag(&data); + asn1_end_tag(&data); + + asn1_end_tag(&data); + asn1_end_tag(&data); + + asn1_end_tag(&data); + + ret = !data.has_error; + asn1_free(&data); + return ret; +} + + +/* + generate a negTokenTarg packet given a list of OIDs and a security blob +*/ +DATA_BLOB gen_negTokenTarg(const char *OIDs[], DATA_BLOB blob) +{ + int i; + ASN1_DATA data; + DATA_BLOB ret; + + memset(&data, 0, sizeof(data)); + + asn1_push_tag(&data, ASN1_APPLICATION(0)); + asn1_write_OID(&data,OID_SPNEGO); + asn1_push_tag(&data, ASN1_CONTEXT(0)); + asn1_push_tag(&data, ASN1_SEQUENCE(0)); + + asn1_push_tag(&data, ASN1_CONTEXT(0)); + asn1_push_tag(&data, ASN1_SEQUENCE(0)); + for (i=0; OIDs[i]; i++) { + asn1_write_OID(&data,OIDs[i]); + } + asn1_pop_tag(&data); + asn1_pop_tag(&data); + + asn1_push_tag(&data, ASN1_CONTEXT(2)); + asn1_write_OctetString(&data,blob.data,blob.length); + asn1_pop_tag(&data); + + asn1_pop_tag(&data); + asn1_pop_tag(&data); + + asn1_pop_tag(&data); + + if (data.has_error) { + DEBUG(1,("Failed to build negTokenTarg at offset %d\n", (int)data.ofs)); + asn1_free(&data); + } + + ret = data_blob(data.data, data.length); + asn1_free(&data); + + return ret; +} + + +/* + parse a negTokenTarg packet giving a list of OIDs and a security blob +*/ +BOOL parse_negTokenTarg(DATA_BLOB blob, char *OIDs[ASN1_MAX_OIDS], DATA_BLOB *secblob) +{ + int i; + ASN1_DATA data; + + asn1_load(&data, blob); + asn1_start_tag(&data, ASN1_APPLICATION(0)); + asn1_check_OID(&data,OID_SPNEGO); + asn1_start_tag(&data, ASN1_CONTEXT(0)); + asn1_start_tag(&data, ASN1_SEQUENCE(0)); + + asn1_start_tag(&data, ASN1_CONTEXT(0)); + asn1_start_tag(&data, ASN1_SEQUENCE(0)); + for (i=0; asn1_tag_remaining(&data) > 0 && i < ASN1_MAX_OIDS; i++) { + char *oid = NULL; + asn1_read_OID(&data,&oid); + OIDs[i] = oid; + } + OIDs[i] = NULL; + asn1_end_tag(&data); + asn1_end_tag(&data); + + asn1_start_tag(&data, ASN1_CONTEXT(2)); + asn1_read_OctetString(&data,secblob); + asn1_end_tag(&data); + + asn1_end_tag(&data); + asn1_end_tag(&data); + + asn1_end_tag(&data); + + if (data.has_error) { + DEBUG(1,("Failed to parse negTokenTarg at offset %d\n", (int)data.ofs)); + asn1_free(&data); + return False; + } + + asn1_free(&data); + return True; +} + +/* + generate a krb5 GSS-API wrapper packet given a ticket +*/ +DATA_BLOB spnego_gen_krb5_wrap(DATA_BLOB ticket, const uint8 tok_id[2]) +{ + ASN1_DATA data; + DATA_BLOB ret; + + memset(&data, 0, sizeof(data)); + + asn1_push_tag(&data, ASN1_APPLICATION(0)); + asn1_write_OID(&data, OID_KERBEROS5); + + asn1_write(&data, tok_id, 2); + asn1_write(&data, ticket.data, ticket.length); + asn1_pop_tag(&data); + + if (data.has_error) { + DEBUG(1,("Failed to build krb5 wrapper at offset %d\n", (int)data.ofs)); + asn1_free(&data); + } + + ret = data_blob(data.data, data.length); + asn1_free(&data); + + return ret; +} + +/* + parse a krb5 GSS-API wrapper packet giving a ticket +*/ +BOOL spnego_parse_krb5_wrap(DATA_BLOB blob, DATA_BLOB *ticket, uint8 tok_id[2]) +{ + BOOL ret; + ASN1_DATA data; + int data_remaining; + + asn1_load(&data, blob); + asn1_start_tag(&data, ASN1_APPLICATION(0)); + asn1_check_OID(&data, OID_KERBEROS5); + + data_remaining = asn1_tag_remaining(&data); + + if (data_remaining < 3) { + data.has_error = True; + } else { + asn1_read(&data, tok_id, 2); + data_remaining -= 2; + *ticket = data_blob(NULL, data_remaining); + asn1_read(&data, ticket->data, ticket->length); + } + + asn1_end_tag(&data); + + ret = !data.has_error; + + asn1_free(&data); + + return ret; +} + + +/* + generate a SPNEGO negTokenTarg packet, ready for a EXTENDED_SECURITY + kerberos session setup +*/ +DATA_BLOB spnego_gen_negTokenTarg(const char *principal, int time_offset) +{ + DATA_BLOB tkt, tkt_wrapped, targ; + const char *krb_mechs[] = {OID_KERBEROS5_OLD, OID_NTLMSSP, NULL}; + + /* get a kerberos ticket for the service */ + tkt = krb5_get_ticket(principal, time_offset); + + /* wrap that up in a nice GSS-API wrapping */ + tkt_wrapped = spnego_gen_krb5_wrap(tkt, TOK_ID_KRB_AP_REQ); + + /* and wrap that in a shiny SPNEGO wrapper */ + targ = gen_negTokenTarg(krb_mechs, tkt_wrapped); + + data_blob_free(&tkt_wrapped); + data_blob_free(&tkt); + + return targ; +} + + +/* + parse a spnego NTLMSSP challenge packet giving two security blobs +*/ +BOOL spnego_parse_challenge(const DATA_BLOB blob, + DATA_BLOB *chal1, DATA_BLOB *chal2) +{ + BOOL ret; + ASN1_DATA data; + + ZERO_STRUCTP(chal1); + ZERO_STRUCTP(chal2); + + asn1_load(&data, blob); + asn1_start_tag(&data,ASN1_CONTEXT(1)); + asn1_start_tag(&data,ASN1_SEQUENCE(0)); + + asn1_start_tag(&data,ASN1_CONTEXT(0)); + asn1_check_enumerated(&data,1); + asn1_end_tag(&data); + + asn1_start_tag(&data,ASN1_CONTEXT(1)); + asn1_check_OID(&data, OID_NTLMSSP); + asn1_end_tag(&data); + + asn1_start_tag(&data,ASN1_CONTEXT(2)); + asn1_read_OctetString(&data, chal1); + asn1_end_tag(&data); + + /* the second challenge is optional (XP doesn't send it) */ + if (asn1_tag_remaining(&data)) { + asn1_start_tag(&data,ASN1_CONTEXT(3)); + asn1_read_OctetString(&data, chal2); + asn1_end_tag(&data); + } + + asn1_end_tag(&data); + asn1_end_tag(&data); + + ret = !data.has_error; + asn1_free(&data); + return ret; +} + + +/* + generate a SPNEGO auth packet. This will contain the encrypted passwords +*/ +DATA_BLOB spnego_gen_auth(DATA_BLOB blob) +{ + ASN1_DATA data; + DATA_BLOB ret; + + memset(&data, 0, sizeof(data)); + + asn1_push_tag(&data, ASN1_CONTEXT(1)); + asn1_push_tag(&data, ASN1_SEQUENCE(0)); + asn1_push_tag(&data, ASN1_CONTEXT(2)); + asn1_write_OctetString(&data,blob.data,blob.length); + asn1_pop_tag(&data); + asn1_pop_tag(&data); + asn1_pop_tag(&data); + + ret = data_blob(data.data, data.length); + + asn1_free(&data); + + return ret; +} + +/* + parse a SPNEGO auth packet. This contains the encrypted passwords +*/ +BOOL spnego_parse_auth(DATA_BLOB blob, DATA_BLOB *auth) +{ + ASN1_DATA data; + + asn1_load(&data, blob); + asn1_start_tag(&data, ASN1_CONTEXT(1)); + asn1_start_tag(&data, ASN1_SEQUENCE(0)); + asn1_start_tag(&data, ASN1_CONTEXT(2)); + asn1_read_OctetString(&data,auth); + asn1_end_tag(&data); + asn1_end_tag(&data); + asn1_end_tag(&data); + + if (data.has_error) { + DEBUG(3,("spnego_parse_auth failed at %d\n", (int)data.ofs)); + asn1_free(&data); + return False; + } + + asn1_free(&data); + return True; +} + +/* + generate a minimal SPNEGO response packet. Doesn't contain much. +*/ +DATA_BLOB spnego_gen_auth_response(DATA_BLOB *reply, NTSTATUS nt_status, + const char *mechOID) +{ + ASN1_DATA data; + DATA_BLOB ret; + uint8 negResult; + + if (NT_STATUS_IS_OK(nt_status)) { + negResult = SPNEGO_NEG_RESULT_ACCEPT; + } else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { + negResult = SPNEGO_NEG_RESULT_INCOMPLETE; + } else { + negResult = SPNEGO_NEG_RESULT_REJECT; + } + + ZERO_STRUCT(data); + + asn1_push_tag(&data, ASN1_CONTEXT(1)); + asn1_push_tag(&data, ASN1_SEQUENCE(0)); + asn1_push_tag(&data, ASN1_CONTEXT(0)); + asn1_write_enumerated(&data, negResult); + asn1_pop_tag(&data); + + if (reply->data != NULL) { + asn1_push_tag(&data,ASN1_CONTEXT(1)); + asn1_write_OID(&data, mechOID); + asn1_pop_tag(&data); + + asn1_push_tag(&data,ASN1_CONTEXT(2)); + asn1_write_OctetString(&data, reply->data, reply->length); + asn1_pop_tag(&data); + } + + asn1_pop_tag(&data); + asn1_pop_tag(&data); + + ret = data_blob(data.data, data.length); + asn1_free(&data); + return ret; +} + +/* + parse a SPNEGO NTLMSSP auth packet. This contains the encrypted passwords +*/ +BOOL spnego_parse_auth_response(DATA_BLOB blob, NTSTATUS nt_status, + DATA_BLOB *auth) +{ + ASN1_DATA data; + uint8 negResult; + + if (NT_STATUS_IS_OK(nt_status)) { + negResult = SPNEGO_NEG_RESULT_ACCEPT; + } else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { + negResult = SPNEGO_NEG_RESULT_INCOMPLETE; + } else { + negResult = SPNEGO_NEG_RESULT_REJECT; + } + + asn1_load(&data, blob); + asn1_start_tag(&data, ASN1_CONTEXT(1)); + asn1_start_tag(&data, ASN1_SEQUENCE(0)); + asn1_start_tag(&data, ASN1_CONTEXT(0)); + asn1_check_enumerated(&data, negResult); + asn1_end_tag(&data); + + if (negResult == SPNEGO_NEG_RESULT_INCOMPLETE) { + asn1_start_tag(&data,ASN1_CONTEXT(1)); + asn1_check_OID(&data, OID_NTLMSSP); + asn1_end_tag(&data); + + asn1_start_tag(&data,ASN1_CONTEXT(2)); + asn1_read_OctetString(&data, auth); + asn1_end_tag(&data); + } + + asn1_end_tag(&data); + asn1_end_tag(&data); + + if (data.has_error) { + DEBUG(3,("spnego_parse_auth_response failed at %d\n", (int)data.ofs)); + asn1_free(&data); + data_blob_free(auth); + return False; + } + + asn1_free(&data); + return True; +} + diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c new file mode 100644 index 0000000000..80bb1e301f --- /dev/null +++ b/source4/libcli/raw/clitransport.c @@ -0,0 +1,218 @@ +/* + Unix SMB/CIFS implementation. + SMB client transport context management functions + Copyright (C) Andrew Tridgell 1994-2003 + Copyright (C) James Myers 2003 + + 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. +*/ + +#include "includes.h" + +/* + create a transport structure based on an established socket +*/ +struct cli_transport *cli_transport_init(struct cli_socket *sock) +{ + TALLOC_CTX *mem_ctx; + struct cli_transport *transport; + + mem_ctx = talloc_init("cli_transport"); + if (!mem_ctx) return NULL; + + transport = talloc_zero(mem_ctx, sizeof(*transport)); + if (!transport) return NULL; + + transport->mem_ctx = mem_ctx; + transport->socket = sock; + transport->negotiate.protocol = PROTOCOL_NT1; + transport->negotiate.max_xmit = ~0; + cli_null_set_signing(transport); + transport->socket->reference_count++; + + return transport; +} + +/* + decrease reference count on a transport, and destroy if it becomes + zero +*/ +void cli_transport_close(struct cli_transport *transport) +{ + transport->reference_count--; + if (transport->reference_count <= 0) { + cli_sock_close(transport->socket); + talloc_destroy(transport->mem_ctx); + } +} + + + +/**************************************************************************** +send a session request (if appropriate) +****************************************************************************/ +BOOL cli_transport_connect(struct cli_transport *transport, + struct nmb_name *calling, + struct nmb_name *called) +{ + char *p; + int len = NBT_HDR_SIZE; + struct cli_request *req; + + /* 445 doesn't have session request */ + if (transport->socket->port == 445) { + return True; + } + + /* allocate output buffer */ + req = cli_request_setup_nonsmb(transport, NBT_HDR_SIZE + 2*nbt_mangled_name_len()); + + /* put in the destination name */ + p = req->out.buffer + NBT_HDR_SIZE; + name_mangle(called->name, p, called->name_type); + len += name_len(p); + + /* and my name */ + p = req->out.buffer+len; + name_mangle(calling->name, p, calling->name_type); + len += name_len(p); + + _smb_setlen(req->out.buffer,len-4); + SCVAL(req->out.buffer,0,0x81); + + if (!cli_request_send(req) || + !cli_request_receive(req)) { + cli_request_destroy(req); + return False; + } + + if (CVAL(req->in.buffer,0) != 0x82) { + transport->error.etype = ETYPE_NBT; + transport->error.e.nbt_error = CVAL(req->in.buffer,4); + cli_request_destroy(req); + return False; + } + + cli_request_destroy(req); + return True; +} + + +/**************************************************************************** +get next mid in sequence +****************************************************************************/ +uint16 cli_transport_next_mid(struct cli_transport *transport) +{ + uint16 mid; + struct cli_request *req; + + mid = transport->next_mid; + +again: + /* now check to see if this mid is being used by one of the + pending requests. This is quite efficient because the list is + usually very short */ + + /* the zero mid is reserved for requests that don't have a mid */ + if (mid == 0) mid = 1; + + for (req=transport->pending_requests; req; req=req->next) { + if (req->mid == mid) { + mid++; + goto again; + } + } + + transport->next_mid = mid+1; + return mid; +} + +/* + setup the idle handler for a transport +*/ +void cli_transport_idle_handler(struct cli_transport *transport, + void (*idle_func)(struct cli_transport *, void *), + uint_t period, + void *private) +{ + transport->idle.func = idle_func; + transport->idle.private = private; + transport->idle.period = period; +} + + +/* + determine if a packet is pending for receive on a transport +*/ +BOOL cli_transport_pending(struct cli_transport *transport) +{ + return socket_pending(transport->socket->fd); +} + + + +/* + wait for data on a transport, periodically calling a wait function + if one has been defined + return True if a packet is received +*/ +BOOL cli_transport_select(struct cli_transport *transport) +{ + fd_set fds; + int selrtn; + int fd; + struct timeval timeout; + + fd = transport->socket->fd; + + if (fd == -1) { + return False; + } + + do { + uint_t period = 1000; + + FD_ZERO(&fds); + FD_SET(fd,&fds); + + if (transport->idle.func) { + period = transport->idle.period; + } + + timeout.tv_sec = period / 1000; + timeout.tv_usec = 1000*(period%1000); + + selrtn = sys_select_intr(fd+1,&fds,NULL,NULL,&timeout); + + if (selrtn == 1) { + /* the fd is readable */ + return True; + } + + if (selrtn == -1) { + /* sys_select_intr() already handles EINTR, so this + is an error. The socket is probably dead */ + return False; + } + + /* only other possibility is that we timed out - call the idle function + if there is one */ + if (transport->idle.func) { + transport->idle.func(transport, transport->idle.private); + } + } while (selrtn == 0); + + return True; +} diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c new file mode 100644 index 0000000000..2a41273913 --- /dev/null +++ b/source4/libcli/raw/clitree.c @@ -0,0 +1,290 @@ +/* + Unix SMB/CIFS implementation. + SMB client tree context management functions + Copyright (C) Andrew Tridgell 1994-1998 + Copyright (C) James Myers 2003 + + 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. +*/ + +#include "includes.h" + +#define SETUP_REQUEST_TREE(cmd, wct, buflen) do { \ + req = cli_request_setup(tree, cmd, wct, buflen); \ + if (!req) return NULL; \ +} while (0) + + +/**************************************************************************** + Initialize the tree context +****************************************************************************/ +struct cli_tree *cli_tree_init(struct cli_session *session) +{ + struct cli_tree *tree; + TALLOC_CTX *mem_ctx = talloc_init("cli_tree"); + if (mem_ctx == NULL) { + return NULL; + } + + tree = talloc_zero(mem_ctx, sizeof(*tree)); + if (!tree) { + talloc_destroy(mem_ctx); + return NULL; + } + + tree->mem_ctx = mem_ctx; + tree->session = session; + tree->session->reference_count++; + + return tree; +} + +/**************************************************************************** +reduce reference count on a tree and destroy if <= 0 +****************************************************************************/ +void cli_tree_close(struct cli_tree *tree) +{ + if (!tree) return; + tree->reference_count--; + if (tree->reference_count <= 0) { + cli_session_close(tree->session); + talloc_destroy(tree->mem_ctx); + } +} + + +/**************************************************************************** + Send a tconX (async send) +****************************************************************************/ +struct cli_request *smb_tree_connect_send(struct cli_tree *tree, union smb_tcon *parms) +{ + struct cli_request *req; + + switch (parms->tcon.level) { + case RAW_TCON_TCON: + SETUP_REQUEST_TREE(SMBtcon, 0, 0); + cli_req_append_ascii4(req, parms->tcon.in.service, STR_ASCII); + cli_req_append_ascii4(req, parms->tcon.in.password,STR_ASCII); + cli_req_append_ascii4(req, parms->tcon.in.dev, STR_ASCII); + break; + + case RAW_TCON_TCONX: + SETUP_REQUEST_TREE(SMBtconX, 4, 0); + SSVAL(req->out.vwv, VWV(0), 0xFF); + SSVAL(req->out.vwv, VWV(1), 0); + SSVAL(req->out.vwv, VWV(2), parms->tconx.in.flags); + SSVAL(req->out.vwv, VWV(3), parms->tconx.in.password.length); + cli_req_append_blob(req, &parms->tconx.in.password); + cli_req_append_string(req, parms->tconx.in.path, STR_TERMINATE | STR_UPPER); + cli_req_append_string(req, parms->tconx.in.device, STR_TERMINATE | STR_ASCII); + break; + } + + if (!cli_request_send(req)) { + cli_request_destroy(req); + return NULL; + } + + return req; +} + +/**************************************************************************** + Send a tconX (async recv) +****************************************************************************/ +NTSTATUS smb_tree_connect_recv(struct cli_request *req, TALLOC_CTX *mem_ctx, union smb_tcon *parms) +{ + char *p; + + if (!cli_request_receive(req) || + cli_request_is_error(req)) { + goto failed; + } + + switch (parms->tcon.level) { + case RAW_TCON_TCON: + CLI_CHECK_WCT(req, 2); + parms->tcon.out.max_xmit = SVAL(req->in.vwv, VWV(0)); + parms->tcon.out.cnum = SVAL(req->in.vwv, VWV(1)); + break; + + case RAW_TCON_TCONX: + ZERO_STRUCT(parms->tconx.out); + CLI_CHECK_MIN_WCT(req, 0); /* this depends on the protocol level */ + parms->tconx.out.cnum = SVAL(req->in.hdr, HDR_TID); + if (req->in.wct >= 4) { + parms->tconx.out.options = SVAL(req->in.vwv, VWV(3)); + } + + /* output is actual service name */ + p = req->in.data; + if (!p) break; + + p += cli_req_pull_string(req, mem_ctx, &parms->tconx.out.dev_type, + p, -1, STR_ASCII | STR_TERMINATE); + p += cli_req_pull_string(req, mem_ctx, &parms->tconx.out.fs_type, + p, -1, STR_TERMINATE); + break; + } + +failed: + return cli_request_destroy(req); +} + +/**************************************************************************** + Send a tconX (sync interface) +****************************************************************************/ +NTSTATUS smb_tree_connect(struct cli_tree *tree, TALLOC_CTX *mem_ctx, union smb_tcon *parms) +{ + struct cli_request *req = smb_tree_connect_send(tree, parms); + return smb_tree_connect_recv(req, mem_ctx, parms); +} + + +/**************************************************************************** + Send a tree disconnect. +****************************************************************************/ +NTSTATUS smb_tree_disconnect(struct cli_tree *tree) +{ + struct cli_request *req; + + if (!tree) return NT_STATUS_OK; + req = cli_request_setup(tree, SMBtdis, 0, 0); + + if (cli_request_send(req)) { + cli_request_receive(req); + } + return cli_request_destroy(req); +} + + +/* + a convenient function to establish a cli_tree from scratch, using reasonable default + parameters +*/ +NTSTATUS cli_tree_full_connection(struct cli_tree **ret_tree, + const char *my_name, + const char *dest_host, int port, + const char *service, const char *service_type, + const char *user, const char *domain, + const char *password) +{ + struct cli_socket *sock; + struct cli_transport *transport; + struct cli_session *session; + struct cli_tree *tree; + NTSTATUS status; + struct nmb_name calling; + struct nmb_name called; + union smb_sesssetup setup; + union smb_tcon tcon; + TALLOC_CTX *mem_ctx; + + *ret_tree = NULL; + + sock = cli_sock_init(); + if (!sock) { + return NT_STATUS_NO_MEMORY; + } + + /* open a TCP socket to the server */ + if (!cli_sock_connect_byname(sock, dest_host, port)) { + DEBUG(2,("Failed to establish socket connection - %s\n", strerror(errno))); + return NT_STATUS_UNSUCCESSFUL; + } + + transport = cli_transport_init(sock); + if (!transport) { + cli_sock_close(sock); + return NT_STATUS_NO_MEMORY; + } + + /* send a NBT session request, if applicable */ + make_nmb_name(&calling, my_name, 0x0); + make_nmb_name(&called, dest_host, 0x20); + + if (!cli_transport_connect(transport, &calling, &called)) { + cli_transport_close(transport); + return NT_STATUS_UNSUCCESSFUL; + } + + + /* negotiate protocol options with the server */ + status = smb_raw_negotiate(transport); + if (!NT_STATUS_IS_OK(status)) { + cli_transport_close(transport); + return status; + } + + session = cli_session_init(transport); + if (!session) { + cli_transport_close(transport); + return NT_STATUS_NO_MEMORY; + } + + /* prepare a session setup to establish a security context */ + setup.generic.level = RAW_SESSSETUP_GENERIC; + setup.generic.in.sesskey = transport->negotiate.sesskey; + setup.generic.in.capabilities = CAP_UNICODE | CAP_STATUS32 | + CAP_LARGE_FILES | CAP_NT_SMBS | CAP_LEVEL_II_OPLOCKS | + CAP_W2K_SMBS | CAP_LARGE_READX | CAP_LARGE_WRITEX; + setup.generic.in.password = password; + setup.generic.in.user = user; + setup.generic.in.domain = domain; + + mem_ctx = talloc_init("tcon"); + if (!mem_ctx) { + cli_tree_close(tree); + return NT_STATUS_NO_MEMORY; + } + + status = smb_raw_session_setup(session, mem_ctx, &setup); + if (!NT_STATUS_IS_OK(status)) { + cli_session_close(session); + talloc_destroy(mem_ctx); + return status; + } + + session->vuid = setup.generic.out.vuid; + + tree = cli_tree_init(session); + if (!tree) { + cli_session_close(session); + talloc_destroy(mem_ctx); + return NT_STATUS_NO_MEMORY; + } + + /* connect to a share using a tree connect */ + tcon.generic.level = RAW_TCON_TCONX; + tcon.tconx.in.flags = 0; + tcon.tconx.in.password = data_blob(NULL, 0); + tcon.tconx.in.path = service; + tcon.tconx.in.device = service_type; + + status = smb_tree_connect(tree, mem_ctx, &tcon); + if (!NT_STATUS_IS_OK(status)) { + cli_tree_close(tree); + talloc_destroy(mem_ctx); + return status; + } + + tree->tid = tcon.tconx.out.cnum; + tree->device = talloc_strdup(tree->mem_ctx, tcon.tconx.out.dev_type); + tree->fs_type = talloc_strdup(tree->mem_ctx, tcon.tconx.out.fs_type); + + talloc_destroy(mem_ctx); + + *ret_tree = tree; + return NT_STATUS_OK; +} diff --git a/source4/libcli/raw/raweas.c b/source4/libcli/raw/raweas.c new file mode 100644 index 0000000000..ce0368c304 --- /dev/null +++ b/source4/libcli/raw/raweas.c @@ -0,0 +1,147 @@ +/* + Unix SMB/CIFS implementation. + parsing of EA (extended attribute) lists + Copyright (C) Andrew Tridgell 2003 + + 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. +*/ + +#include "includes.h" + +/* + work out how many bytes on the wire a ea list will consume. + This assumes the names are strict ascii, which should be a + reasonable assumption +*/ +uint_t ea_list_size(uint_t num_eas, struct ea_struct *eas) +{ + uint_t total = 4; + int i; + for (i=0;ilength < 6) { + return 0; + } + + ea->flags = CVAL(blob->data, 0); + nlen = CVAL(blob->data, 1); + vlen = SVAL(blob->data, 2); + + if (nlen+1+vlen > blob->length-4) { + return 0; + } + + ea->name.s = talloc_strndup(mem_ctx, blob->data+4, nlen); + ea->name.private_length = nlen; + ea->value = data_blob_talloc(mem_ctx, NULL, vlen+1); + if (!ea->value.data) return 0; + if (vlen) { + memcpy(ea->value.data, blob->data+4+nlen+1, vlen); + } + ea->value.data[vlen] = 0; + ea->value.length--; + + return 4 + nlen+1 + vlen; +} + + +/* + pull a ea_list from a buffer +*/ +NTSTATUS ea_pull_list(const DATA_BLOB *blob, + TALLOC_CTX *mem_ctx, + uint_t *num_eas, struct ea_struct **eas) +{ + int n; + uint32 ea_size, ofs; + + if (blob->length < 4) { + return NT_STATUS_INFO_LENGTH_MISMATCH; + } + + ea_size = IVAL(blob->data, 0); + if (ea_size > blob->length) { + return NT_STATUS_INVALID_PARAMETER; + } + + ofs = 4; + n = 0; + *num_eas = 0; + *eas = NULL; + + while (ofs < ea_size) { + uint_t len; + DATA_BLOB blob2; + + blob2.data = blob->data + ofs; + blob2.length = ea_size - ofs; + + *eas = talloc_realloc(mem_ctx, *eas, sizeof(**eas) * (n+1)); + if (! *eas) return NT_STATUS_NO_MEMORY; + + len = ea_pull_struct(&blob2, mem_ctx, &(*eas)[n]); + if (len == 0) { + return NT_STATUS_INVALID_PARAMETER; + } + + ofs += len; + n++; + } + + *num_eas = n; + + return NT_STATUS_OK; +} + diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c new file mode 100644 index 0000000000..279dfcf0c1 --- /dev/null +++ b/source4/libcli/raw/rawfile.c @@ -0,0 +1,687 @@ +/* + Unix SMB/CIFS implementation. + client file operations + Copyright (C) Andrew Tridgell 1994-1998 + Copyright (C) Jeremy Allison 2001-2002 + Copyright (C) James Myers 2003 + + 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. +*/ + +#include "includes.h" + +#define SETUP_REQUEST(cmd, wct, buflen) do { \ + req = cli_request_setup(tree, cmd, wct, buflen); \ + if (!req) return NULL; \ +} while (0) + + +/**************************************************************************** + Rename a file - async interface +****************************************************************************/ +struct cli_request *smb_raw_rename_send(struct cli_tree *tree, + struct smb_rename *parms) +{ + struct cli_request *req; + + SETUP_REQUEST(SMBmv, 1, 0); + + SSVAL(req->out.vwv, VWV(0), parms->in.attrib); + + cli_req_append_ascii4(req, parms->in.pattern1, STR_TERMINATE); + cli_req_append_ascii4(req, parms->in.pattern2, STR_TERMINATE); + + if (!cli_request_send(req)) { + cli_request_destroy(req); + return NULL; + } + + return req; +} + +/**************************************************************************** + Rename a file - sync interface +****************************************************************************/ +NTSTATUS smb_raw_rename(struct cli_tree *tree, + struct smb_rename *parms) +{ + struct cli_request *req = smb_raw_rename_send(tree, parms); + return cli_request_simple_recv(req); +} + + +/**************************************************************************** + Delete a file - async interface +****************************************************************************/ +struct cli_request *smb_raw_unlink_send(struct cli_tree *tree, + struct smb_unlink *parms) +{ + struct cli_request *req; + + SETUP_REQUEST(SMBunlink, 1, 0); + + SSVAL(req->out.vwv, VWV(0), parms->in.attrib); + cli_req_append_ascii4(req, parms->in.pattern, STR_TERMINATE); + + if (!cli_request_send(req)) { + cli_request_destroy(req); + return NULL; + } + return req; +} + +/* + delete a file - sync interface +*/ +NTSTATUS smb_raw_unlink(struct cli_tree *tree, + struct smb_unlink *parms) +{ + struct cli_request *req = smb_raw_unlink_send(tree, parms); + return cli_request_simple_recv(req); +} + + +/**************************************************************************** + create a directory using TRANSACT2_MKDIR - async interface +****************************************************************************/ +static struct cli_request *smb_raw_t2mkdir_send(struct cli_tree *tree, + union smb_mkdir *parms) +{ + struct smb_trans2 t2; + uint16 setup = TRANSACT2_MKDIR; + TALLOC_CTX *mem_ctx; + struct cli_request *req; + uint16 data_total; + + mem_ctx = talloc_init("t2mkdir"); + + data_total = ea_list_size(parms->t2mkdir.in.num_eas, parms->t2mkdir.in.eas); + + t2.in.max_param = 0; + t2.in.max_data = 0; + t2.in.max_setup = 0; + t2.in.flags = 0; + t2.in.timeout = 0; + t2.in.setup_count = 1; + t2.in.setup = &setup; + t2.in.params = data_blob_talloc(mem_ctx, NULL, 4); + t2.in.data = data_blob_talloc(mem_ctx, NULL, data_total); + + SIVAL(t2.in.params.data, VWV(0), 0); /* reserved */ + + cli_blob_append_string(tree->session, mem_ctx, + &t2.in.params, parms->t2mkdir.in.path, 0); + + ea_put_list(t2.in.data.data, parms->t2mkdir.in.num_eas, parms->t2mkdir.in.eas); + + req = smb_raw_trans2_send(tree, &t2); + + talloc_destroy(mem_ctx); + + return req; +} + +/**************************************************************************** + Create a directory - async interface +****************************************************************************/ +struct cli_request *smb_raw_mkdir_send(struct cli_tree *tree, + union smb_mkdir *parms) +{ + struct cli_request *req; + + if (parms->generic.level == RAW_MKDIR_T2MKDIR) { + return smb_raw_t2mkdir_send(tree, parms); + } + + if (parms->generic.level != RAW_MKDIR_MKDIR) { + return NULL; + } + + SETUP_REQUEST(SMBmkdir, 0, 0); + + cli_req_append_ascii4(req, parms->mkdir.in.path, STR_TERMINATE); + + if (!cli_request_send(req)) { + return NULL; + } + + return req; +} + +/**************************************************************************** + Create a directory - sync interface +****************************************************************************/ +NTSTATUS smb_raw_mkdir(struct cli_tree *tree, + union smb_mkdir *parms) +{ + struct cli_request *req = smb_raw_mkdir_send(tree, parms); + return cli_request_simple_recv(req); +} + +/**************************************************************************** + Remove a directory - async interface +****************************************************************************/ +struct cli_request *smb_raw_rmdir_send(struct cli_tree *tree, + struct smb_rmdir *parms) +{ + struct cli_request *req; + + SETUP_REQUEST(SMBrmdir, 0, 0); + + cli_req_append_ascii4(req, parms->in.path, STR_TERMINATE); + + if (!cli_request_send(req)) { + cli_request_destroy(req); + return NULL; + } + + return req; +} + +/**************************************************************************** + Remove a directory - sync interface +****************************************************************************/ +NTSTATUS smb_raw_rmdir(struct cli_tree *tree, + struct smb_rmdir *parms) +{ + struct cli_request *req = smb_raw_rmdir_send(tree, parms); + return cli_request_simple_recv(req); +} + + +/**************************************************************************** + Open a file using TRANSACT2_OPEN - async send +****************************************************************************/ +static struct cli_request *smb_raw_t2open_send(struct cli_tree *tree, + union smb_open *parms) +{ + struct smb_trans2 t2; + uint16 setup = TRANSACT2_OPEN; + TALLOC_CTX *mem_ctx = talloc_init("smb_raw_t2open"); + struct cli_request *req; + uint16 list_size; + + list_size = ea_list_size(parms->t2open.in.num_eas, parms->t2open.in.eas); + + t2.in.max_param = 30; + t2.in.max_data = 0; + t2.in.max_setup = 0; + t2.in.flags = 0; + t2.in.timeout = 0; + t2.in.setup_count = 1; + t2.in.setup = &setup; + t2.in.params = data_blob_talloc(mem_ctx, NULL, 28); + t2.in.data = data_blob_talloc(mem_ctx, NULL, list_size); + + SSVAL(t2.in.params.data, VWV(0), parms->t2open.in.flags); + SSVAL(t2.in.params.data, VWV(1), parms->t2open.in.open_mode); + SSVAL(t2.in.params.data, VWV(2), 0); /* reserved */ + SSVAL(t2.in.params.data, VWV(3), parms->t2open.in.file_attrs); + put_dos_date(t2.in.params.data, VWV(4), parms->t2open.in.write_time); + SSVAL(t2.in.params.data, VWV(6), parms->t2open.in.open_func); + SIVAL(t2.in.params.data, VWV(7), parms->t2open.in.size); + SIVAL(t2.in.params.data, VWV(9), parms->t2open.in.timeout); + SIVAL(t2.in.params.data, VWV(11), 0); + SSVAL(t2.in.params.data, VWV(13), 0); + + cli_blob_append_string(tree->session, mem_ctx, + &t2.in.params, parms->t2open.in.fname, + STR_TERMINATE); + + ea_put_list(t2.in.data.data, parms->t2open.in.num_eas, parms->t2open.in.eas); + + req = smb_raw_trans2_send(tree, &t2); + + talloc_destroy(mem_ctx); + + return req; +} + + +/**************************************************************************** + Open a file using TRANSACT2_OPEN - async recv +****************************************************************************/ +static NTSTATUS smb_raw_t2open_recv(struct cli_request *req, TALLOC_CTX *mem_ctx, union smb_open *parms) +{ + struct smb_trans2 t2; + NTSTATUS status; + + status = smb_raw_trans2_recv(req, mem_ctx, &t2); + if (!NT_STATUS_IS_OK(status)) return status; + + if (t2.out.params.length < 30) { + return NT_STATUS_INFO_LENGTH_MISMATCH; + } + + parms->t2open.out.fnum = SVAL(t2.out.params.data, VWV(0)); + parms->t2open.out.attrib = SVAL(t2.out.params.data, VWV(1)); + parms->t2open.out.write_time = make_unix_date3(t2.out.params.data + VWV(2)); + parms->t2open.out.size = IVAL(t2.out.params.data, VWV(4)); + parms->t2open.out.access = SVAL(t2.out.params.data, VWV(6)); + parms->t2open.out.ftype = SVAL(t2.out.params.data, VWV(7)); + parms->t2open.out.devstate = SVAL(t2.out.params.data, VWV(8)); + parms->t2open.out.action = SVAL(t2.out.params.data, VWV(9)); + parms->t2open.out.unknown = SVAL(t2.out.params.data, VWV(10)); + + return NT_STATUS_OK; +} + +/**************************************************************************** + Open a file - async send +****************************************************************************/ +struct cli_request *smb_raw_open_send(struct cli_tree *tree, union smb_open *parms) +{ + int len; + struct cli_request *req = NULL; + + switch (parms->open.level) { + case RAW_OPEN_T2OPEN: + return smb_raw_t2open_send(tree, parms); + + case RAW_OPEN_OPEN: + SETUP_REQUEST(SMBopen, 2, 0); + SSVAL(req->out.vwv, VWV(0), parms->open.in.flags); + SSVAL(req->out.vwv, VWV(1), parms->open.in.search_attrs); + cli_req_append_ascii4(req, parms->open.in.fname, STR_TERMINATE); + break; + + case RAW_OPEN_OPENX: + SETUP_REQUEST(SMBopenX, 15, 0); + SSVAL(req->out.vwv, VWV(0), SMB_CHAIN_NONE); + SSVAL(req->out.vwv, VWV(1), 0); + SSVAL(req->out.vwv, VWV(2), parms->openx.in.flags); + SSVAL(req->out.vwv, VWV(3), parms->openx.in.open_mode); + SSVAL(req->out.vwv, VWV(4), parms->openx.in.search_attrs); + SSVAL(req->out.vwv, VWV(5), parms->openx.in.file_attrs); + put_dos_date3(req->out.vwv, VWV(6), parms->openx.in.write_time); + SSVAL(req->out.vwv, VWV(8), parms->openx.in.open_func); + SIVAL(req->out.vwv, VWV(9), parms->openx.in.size); + SIVAL(req->out.vwv, VWV(11),parms->openx.in.timeout); + SIVAL(req->out.vwv, VWV(13),0); /* reserved */ + cli_req_append_string(req, parms->openx.in.fname, STR_TERMINATE); + break; + + case RAW_OPEN_MKNEW: + SETUP_REQUEST(SMBmknew, 3, 0); + SSVAL(req->out.vwv, VWV(0), parms->mknew.in.attrib); + put_dos_date3(req->out.vwv, VWV(1), parms->mknew.in.write_time); + cli_req_append_ascii4(req, parms->mknew.in.fname, STR_TERMINATE); + break; + + case RAW_OPEN_CTEMP: + SETUP_REQUEST(SMBctemp, 3, 0); + SSVAL(req->out.vwv, VWV(0), parms->ctemp.in.attrib); + put_dos_date3(req->out.vwv, VWV(1), parms->ctemp.in.write_time); + cli_req_append_ascii4(req, parms->ctemp.in.directory, STR_TERMINATE); + break; + + case RAW_OPEN_SPLOPEN: + SETUP_REQUEST(SMBsplopen, 2, 0); + SSVAL(req->out.vwv, VWV(0), parms->splopen.in.setup_length); + SSVAL(req->out.vwv, VWV(1), parms->splopen.in.mode); + break; + + case RAW_OPEN_NTCREATEX: + SETUP_REQUEST(SMBntcreateX, 24, 0); + SSVAL(req->out.vwv, VWV(0),SMB_CHAIN_NONE); + SSVAL(req->out.vwv, VWV(1),0); + SCVAL(req->out.vwv, VWV(2),0); /* padding */ + SIVAL(req->out.vwv, 7, parms->ntcreatex.in.flags); + SIVAL(req->out.vwv, 11, parms->ntcreatex.in.root_fid); + SIVAL(req->out.vwv, 15, parms->ntcreatex.in.access_mask); + SBVAL(req->out.vwv, 19, parms->ntcreatex.in.alloc_size); + SIVAL(req->out.vwv, 27, parms->ntcreatex.in.file_attr); + SIVAL(req->out.vwv, 31, parms->ntcreatex.in.share_access); + SIVAL(req->out.vwv, 35, parms->ntcreatex.in.open_disposition); + SIVAL(req->out.vwv, 39, parms->ntcreatex.in.create_options); + SIVAL(req->out.vwv, 43, parms->ntcreatex.in.impersonation); + SCVAL(req->out.vwv, 47, parms->ntcreatex.in.security_flags); + + cli_req_append_string_len(req, parms->ntcreatex.in.fname, STR_TERMINATE, &len); + SSVAL(req->out.vwv, 5, len); + break; + } + + if (!cli_request_send(req)) { + cli_request_destroy(req); + return NULL; + } + + return req; +} + +/**************************************************************************** + Open a file - async recv +****************************************************************************/ +NTSTATUS smb_raw_open_recv(struct cli_request *req, TALLOC_CTX *mem_ctx, union smb_open *parms) +{ + if (!cli_request_receive(req) || + cli_request_is_error(req)) { + goto failed; + } + + switch (parms->open.level) { + case RAW_OPEN_T2OPEN: + return smb_raw_t2open_recv(req, mem_ctx, parms); + + case RAW_OPEN_OPEN: + CLI_CHECK_WCT(req, 7); + parms->open.out.fnum = SVAL(req->in.vwv, VWV(0)); + parms->open.out.attrib = SVAL(req->in.vwv, VWV(1)); + parms->open.out.write_time = make_unix_date3(req->in.vwv + VWV(2)); + parms->open.out.size = IVAL(req->in.vwv, VWV(4)); + parms->open.out.rmode = SVAL(req->in.vwv, VWV(6)); + break; + + case RAW_OPEN_OPENX: + CLI_CHECK_MIN_WCT(req, 15); + parms->openx.out.fnum = SVAL(req->in.vwv, VWV(2)); + parms->openx.out.attrib = SVAL(req->in.vwv, VWV(3)); + parms->openx.out.write_time = make_unix_date3(req->in.vwv + VWV(4)); + parms->openx.out.size = IVAL(req->in.vwv, VWV(6)); + parms->openx.out.access = SVAL(req->in.vwv, VWV(8)); + parms->openx.out.ftype = SVAL(req->in.vwv, VWV(9)); + parms->openx.out.devstate = SVAL(req->in.vwv, VWV(10)); + parms->openx.out.action = SVAL(req->in.vwv, VWV(11)); + parms->openx.out.unique_fid = IVAL(req->in.vwv, VWV(12)); + if (req->in.wct >= 19) { + parms->openx.out.access_mask = IVAL(req->in.vwv, VWV(15)); + parms->openx.out.unknown = IVAL(req->in.vwv, VWV(17)); + } else { + parms->openx.out.access_mask = 0; + parms->openx.out.unknown = 0; + } + break; + + case RAW_OPEN_MKNEW: + CLI_CHECK_WCT(req, 1); + parms->mknew.out.fnum = SVAL(req->in.vwv, VWV(0)); + break; + + case RAW_OPEN_CTEMP: + CLI_CHECK_WCT(req, 1); + parms->ctemp.out.fnum = SVAL(req->in.vwv, VWV(0)); + cli_req_pull_string(req, mem_ctx, &parms->ctemp.out.name, req->in.data, -1, STR_TERMINATE | STR_ASCII); + break; + + case RAW_OPEN_SPLOPEN: + CLI_CHECK_WCT(req, 1); + parms->splopen.out.fnum = SVAL(req->in.vwv, VWV(0)); + break; + + case RAW_OPEN_NTCREATEX: + CLI_CHECK_MIN_WCT(req, 34); + parms->ntcreatex.out.oplock_level = CVAL(req->in.vwv, 4); + parms->ntcreatex.out.fnum = SVAL(req->in.vwv, 5); + parms->ntcreatex.out.create_action = IVAL(req->in.vwv, 7); + parms->ntcreatex.out.create_time = cli_pull_nttime(req->in.vwv, 11); + parms->ntcreatex.out.access_time = cli_pull_nttime(req->in.vwv, 19); + parms->ntcreatex.out.write_time = cli_pull_nttime(req->in.vwv, 27); + parms->ntcreatex.out.change_time = cli_pull_nttime(req->in.vwv, 35); + parms->ntcreatex.out.attrib = IVAL(req->in.vwv, 43); + parms->ntcreatex.out.alloc_size = BVAL(req->in.vwv, 47); + parms->ntcreatex.out.size = BVAL(req->in.vwv, 55); + parms->ntcreatex.out.file_type = SVAL(req->in.vwv, 63); + parms->ntcreatex.out.ipc_state = SVAL(req->in.vwv, 65); + parms->ntcreatex.out.is_directory = CVAL(req->in.vwv, 67); + break; + } + +failed: + return cli_request_destroy(req); +} + + +/**************************************************************************** + Open a file - sync interface +****************************************************************************/ +NTSTATUS smb_raw_open(struct cli_tree *tree, TALLOC_CTX *mem_ctx, union smb_open *parms) +{ + struct cli_request *req = smb_raw_open_send(tree, parms); + return smb_raw_open_recv(req, mem_ctx, parms); +} + + +/**************************************************************************** + Close a file - async send +****************************************************************************/ +struct cli_request *smb_raw_close_send(struct cli_tree *tree, union smb_close *parms) +{ + struct cli_request *req; + + switch (parms->generic.level) { + case RAW_CLOSE_GENERIC: + return NULL; + + case RAW_CLOSE_CLOSE: + SETUP_REQUEST(SMBclose, 3, 0); + SSVAL(req->out.vwv, VWV(0), parms->close.in.fnum); + put_dos_date3(req->out.vwv, VWV(1), parms->close.in.write_time); + break; + + case RAW_CLOSE_SPLCLOSE: + SETUP_REQUEST(SMBsplclose, 3, 0); + SSVAL(req->out.vwv, VWV(0), parms->splclose.in.fnum); + SIVAL(req->out.vwv, VWV(1), 0); /* reserved */ + break; + } + + if (!req) return NULL; + + if (!cli_request_send(req)) { + cli_request_destroy(req); + return NULL; + } + + return req; +} + + +/**************************************************************************** + Close a file - sync interface +****************************************************************************/ +NTSTATUS smb_raw_close(struct cli_tree *tree, union smb_close *parms) +{ + struct cli_request *req = smb_raw_close_send(tree, parms); + return cli_request_simple_recv(req); +} + + +/**************************************************************************** + Locking calls - async interface +****************************************************************************/ +struct cli_request *smb_raw_lock_send(struct cli_tree *tree, union smb_lock *parms) +{ + struct cli_request *req; + + switch (parms->generic.level) { + case RAW_LOCK_GENERIC: + return NULL; + + case RAW_LOCK_LOCK: + SETUP_REQUEST(SMBlock, 5, 0); + SSVAL(req->out.vwv, VWV(0), parms->lock.in.fnum); + SIVAL(req->out.vwv, VWV(1), parms->lock.in.count); + SIVAL(req->out.vwv, VWV(3), parms->lock.in.offset); + break; + + case RAW_LOCK_UNLOCK: + SETUP_REQUEST(SMBunlock, 5, 0); + SSVAL(req->out.vwv, VWV(0), parms->unlock.in.fnum); + SIVAL(req->out.vwv, VWV(1), parms->unlock.in.count); + SIVAL(req->out.vwv, VWV(3), parms->unlock.in.offset); + break; + + case RAW_LOCK_LOCKX: { + struct smb_lock_entry *lockp; + uint_t lck_size = (parms->lockx.in.mode & LOCKING_ANDX_LARGE_FILES)? 20 : 10; + uint_t lock_count = parms->lockx.in.ulock_cnt + parms->lockx.in.lock_cnt; + int i; + + SETUP_REQUEST(SMBlockingX, 8, lck_size * lock_count); + SSVAL(req->out.vwv, VWV(0), SMB_CHAIN_NONE); + SSVAL(req->out.vwv, VWV(1), 0); + SSVAL(req->out.vwv, VWV(2), parms->lockx.in.fnum); + SSVAL(req->out.vwv, VWV(3), parms->lockx.in.mode); + SIVAL(req->out.vwv, VWV(4), parms->lockx.in.timeout); + SSVAL(req->out.vwv, VWV(6), parms->lockx.in.ulock_cnt); + SSVAL(req->out.vwv, VWV(7), parms->lockx.in.lock_cnt); + + /* copy in all the locks */ + lockp = &parms->lockx.in.locks[0]; + for (i = 0; i < lock_count; i++) { + char *p = req->out.data + lck_size * i; + SSVAL(p, 0, lockp[i].pid); + if (parms->lockx.in.mode & LOCKING_ANDX_LARGE_FILES) { + SSVAL(p, 2, 0); /* reserved */ + SIVAL(p, 4, lockp[i].offset>>32); + SIVAL(p, 8, lockp[i].offset); + SIVAL(p, 12, lockp[i].count>>32); + SIVAL(p, 16, lockp[i].count); + } else { + SIVAL(p, 2, lockp[i].offset); + SIVAL(p, 6, lockp[i].count); + } + } + } + } + + if (!cli_request_send(req)) { + cli_request_destroy(req); + return NULL; + } + + return req; +} + +/**************************************************************************** + Locking calls - sync interface +****************************************************************************/ +NTSTATUS smb_raw_lock(struct cli_tree *tree, union smb_lock *parms) +{ + struct cli_request *req = smb_raw_lock_send(tree, parms); + return cli_request_simple_recv(req); +} + + +/**************************************************************************** + Check for existence of a dir - async send +****************************************************************************/ +struct cli_request *smb_raw_chkpath_send(struct cli_tree *tree, struct smb_chkpath *parms) +{ + struct cli_request *req; + + SETUP_REQUEST(SMBchkpth, 0, 0); + + cli_req_append_ascii4(req, parms->in.path, STR_TERMINATE); + + if (!cli_request_send(req)) { + cli_request_destroy(req); + return NULL; + } + + return req; +} + +/**************************************************************************** + Check for existence of a dir - sync interface +****************************************************************************/ +NTSTATUS smb_raw_chkpath(struct cli_tree *tree, struct smb_chkpath *parms) +{ + struct cli_request *req = smb_raw_chkpath_send(tree, parms); + return cli_request_simple_recv(req); +} + + + + +/**************************************************************************** + flush a file - async send + a flush to fnum 0xFFFF will flush all files +****************************************************************************/ +struct cli_request *smb_raw_flush_send(struct cli_tree *tree, struct smb_flush *parms) +{ + struct cli_request *req; + + SETUP_REQUEST(SMBflush, 1, 0); + SSVAL(req->out.vwv, VWV(0), parms->in.fnum); + + if (!cli_request_send(req)) { + cli_request_destroy(req); + return NULL; + } + + return req; +} + + +/**************************************************************************** + flush a file - sync interface +****************************************************************************/ +NTSTATUS smb_raw_flush(struct cli_tree *tree, struct smb_flush *parms) +{ + struct cli_request *req = smb_raw_flush_send(tree, parms); + return cli_request_simple_recv(req); +} + + +/**************************************************************************** + seek a file - async send +****************************************************************************/ +struct cli_request *smb_raw_seek_send(struct cli_tree *tree, + struct smb_seek *parms) +{ + struct cli_request *req; + + SETUP_REQUEST(SMBlseek, 4, 0); + + SSVAL(req->out.vwv, VWV(0), parms->in.fnum); + SSVAL(req->out.vwv, VWV(1), parms->in.mode); + SIVALS(req->out.vwv, VWV(2), parms->in.offset); + + if (!cli_request_send(req)) { + cli_request_destroy(req); + return NULL; + } + return req; +} + +/**************************************************************************** + seek a file - async receive +****************************************************************************/ +NTSTATUS smb_raw_seek_recv(struct cli_request *req, + struct smb_seek *parms) +{ + if (!cli_request_receive(req) || + cli_request_is_error(req)) { + return cli_request_destroy(req); + } + + CLI_CHECK_WCT(req, 2); + parms->out.offset = IVAL(req->in.vwv, VWV(0)); + +failed: + return cli_request_destroy(req); +} + +/* + seek a file - sync interface +*/ +NTSTATUS smb_raw_seek(struct cli_tree *tree, + struct smb_seek *parms) +{ + struct cli_request *req = smb_raw_seek_send(tree, parms); + return smb_raw_seek_recv(req, parms); +} diff --git a/source4/libcli/raw/rawfileinfo.c b/source4/libcli/raw/rawfileinfo.c new file mode 100644 index 0000000000..f685cef9c3 --- /dev/null +++ b/source4/libcli/raw/rawfileinfo.c @@ -0,0 +1,527 @@ +/* + Unix SMB/CIFS implementation. + client trans2 operations + Copyright (C) James Myers 2003 + Copyright (C) Andrew Tridgell 2003 + + 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. +*/ + +#include "includes.h" + +/* local macros to make the code more readable */ +#define FINFO_CHECK_MIN_SIZE(size) if (blob->length < (size)) { \ + DEBUG(1,("Unexpected FILEINFO reply size %d for level %u - expected min of %d\n", \ + blob->length, parms->generic.level, (size))); \ + return NT_STATUS_INFO_LENGTH_MISMATCH; \ +} +#define FINFO_CHECK_SIZE(size) if (blob->length != (size)) { \ + DEBUG(1,("Unexpected FILEINFO reply size %d for level %u - expected %d\n", \ + blob->length, parms->generic.level, (size))); \ + return NT_STATUS_INFO_LENGTH_MISMATCH; \ +} + +/**************************************************************************** + Handle qfileinfo/qpathinfo trans2 backend. +****************************************************************************/ +static NTSTATUS smb_raw_info_backend(struct cli_session *session, + TALLOC_CTX *mem_ctx, + union smb_fileinfo *parms, + DATA_BLOB *blob) +{ + uint_t len, ofs; + + switch (parms->generic.level) { + case RAW_FILEINFO_GENERIC: + case RAW_FILEINFO_GETATTR: + case RAW_FILEINFO_GETATTRE: + /* not handled here */ + return NT_STATUS_INVALID_LEVEL; + + case RAW_FILEINFO_STANDARD: + FINFO_CHECK_SIZE(22); + parms->standard.out.create_time = make_unix_date2(blob->data + 0); + parms->standard.out.access_time = make_unix_date2(blob->data + 4); + parms->standard.out.write_time = make_unix_date2(blob->data + 8); + parms->standard.out.size = IVAL(blob->data, 12); + parms->standard.out.alloc_size = IVAL(blob->data, 16); + parms->standard.out.attrib = SVAL(blob->data, 20); + return NT_STATUS_OK; + + case RAW_FILEINFO_EA_SIZE: + FINFO_CHECK_SIZE(26); + parms->ea_size.out.create_time = make_unix_date2(blob->data + 0); + parms->ea_size.out.access_time = make_unix_date2(blob->data + 4); + parms->ea_size.out.write_time = make_unix_date2(blob->data + 8); + parms->ea_size.out.size = IVAL(blob->data, 12); + parms->ea_size.out.alloc_size = IVAL(blob->data, 16); + parms->ea_size.out.attrib = SVAL(blob->data, 20); + parms->ea_size.out.ea_size = IVAL(blob->data, 22); + return NT_STATUS_OK; + + case RAW_FILEINFO_ALL_EAS: + FINFO_CHECK_MIN_SIZE(4); + return ea_pull_list(blob, mem_ctx, + &parms->all_eas.out.num_eas, + &parms->all_eas.out.eas); + + case RAW_FILEINFO_IS_NAME_VALID: + /* no data! */ + FINFO_CHECK_SIZE(0); + return NT_STATUS_OK; + + case RAW_FILEINFO_BASIC_INFO: + case RAW_FILEINFO_BASIC_INFORMATION: + /* some servers return 40 bytes and some 36. w2k3 return 40, so thats + what we should do, but we need to accept 36 */ + if (blob->length != 36) { + FINFO_CHECK_SIZE(40); + } + parms->basic_info.out.create_time = cli_pull_nttime(blob->data, 0); + parms->basic_info.out.access_time = cli_pull_nttime(blob->data, 8); + parms->basic_info.out.write_time = cli_pull_nttime(blob->data, 16); + parms->basic_info.out.change_time = cli_pull_nttime(blob->data, 24); + parms->basic_info.out.attrib = IVAL(blob->data, 32); + return NT_STATUS_OK; + + case RAW_FILEINFO_STANDARD_INFO: + case RAW_FILEINFO_STANDARD_INFORMATION: + FINFO_CHECK_SIZE(24); + parms->standard_info.out.alloc_size = BVAL(blob->data, 0); + parms->standard_info.out.size = BVAL(blob->data, 8); + parms->standard_info.out.nlink = IVAL(blob->data, 16); + parms->standard_info.out.delete_pending = CVAL(blob->data, 20); + parms->standard_info.out.directory = CVAL(blob->data, 21); + return NT_STATUS_OK; + + case RAW_FILEINFO_EA_INFO: + case RAW_FILEINFO_EA_INFORMATION: + FINFO_CHECK_SIZE(4); + parms->ea_info.out.ea_size = IVAL(blob->data, 0); + return NT_STATUS_OK; + + case RAW_FILEINFO_NAME_INFO: + case RAW_FILEINFO_NAME_INFORMATION: + FINFO_CHECK_MIN_SIZE(4); + cli_blob_pull_string(session, mem_ctx, blob, + &parms->name_info.out.fname, 0, 4, STR_UNICODE); + return NT_STATUS_OK; + + case RAW_FILEINFO_ALL_INFO: + case RAW_FILEINFO_ALL_INFORMATION: + FINFO_CHECK_MIN_SIZE(72); + parms->all_info.out.create_time = cli_pull_nttime(blob->data, 0); + parms->all_info.out.access_time = cli_pull_nttime(blob->data, 8); + parms->all_info.out.write_time = cli_pull_nttime(blob->data, 16); + parms->all_info.out.change_time = cli_pull_nttime(blob->data, 24); + parms->all_info.out.attrib = IVAL(blob->data, 32); + parms->all_info.out.alloc_size = BVAL(blob->data, 40); + parms->all_info.out.size = BVAL(blob->data, 48); + parms->all_info.out.nlink = IVAL(blob->data, 56); + parms->all_info.out.delete_pending = CVAL(blob->data, 60); + parms->all_info.out.directory = CVAL(blob->data, 61); + parms->all_info.out.ea_size = IVAL(blob->data, 64); + cli_blob_pull_string(session, mem_ctx, blob, + &parms->all_info.out.fname, 68, 72, STR_UNICODE); + return NT_STATUS_OK; + + case RAW_FILEINFO_ALT_NAME_INFO: + case RAW_FILEINFO_ALT_NAME_INFORMATION: + FINFO_CHECK_MIN_SIZE(4); + cli_blob_pull_string(session, mem_ctx, blob, + &parms->alt_name_info.out.fname, 0, 4, STR_UNICODE); + return NT_STATUS_OK; + + case RAW_FILEINFO_STREAM_INFO: + case RAW_FILEINFO_STREAM_INFORMATION: + FINFO_CHECK_MIN_SIZE(0); + ofs = 0; + parms->stream_info.out.num_streams = 0; + parms->stream_info.out.streams = NULL; + + while (blob->length - ofs >= 24) { + uint_t n = parms->stream_info.out.num_streams; + parms->stream_info.out.streams = + talloc_realloc(mem_ctx,parms->stream_info.out.streams, + (n+1) * sizeof(parms->stream_info.out.streams[0])); + if (!parms->stream_info.out.streams) { + return NT_STATUS_NO_MEMORY; + } + parms->stream_info.out.streams[n].size = BVAL(blob->data, ofs + 8); + parms->stream_info.out.streams[n].alloc_size = BVAL(blob->data, ofs + 16); + cli_blob_pull_string(session, mem_ctx, blob, + &parms->stream_info.out.streams[n].stream_name, + ofs+4, ofs+24, STR_UNICODE); + parms->stream_info.out.num_streams++; + len = IVAL(blob->data, ofs); + if (len > blob->length - ofs) return NT_STATUS_INFO_LENGTH_MISMATCH; + if (len == 0) break; + ofs += len; + } + return NT_STATUS_OK; + + case RAW_FILEINFO_INTERNAL_INFORMATION: + FINFO_CHECK_SIZE(8); + parms->internal_information.out.device = IVAL(blob->data, 0); + parms->internal_information.out.inode = IVAL(blob->data, 4); + return NT_STATUS_OK; + + case RAW_FILEINFO_ACCESS_INFORMATION: + FINFO_CHECK_SIZE(4); + parms->access_information.out.access_flags = IVAL(blob->data, 0); + return NT_STATUS_OK; + + case RAW_FILEINFO_POSITION_INFORMATION: + FINFO_CHECK_SIZE(8); + parms->position_information.out.position = BVAL(blob->data, 0); + return NT_STATUS_OK; + + case RAW_FILEINFO_MODE_INFORMATION: + FINFO_CHECK_SIZE(4); + parms->mode_information.out.mode = IVAL(blob->data, 0); + return NT_STATUS_OK; + + case RAW_FILEINFO_ALIGNMENT_INFORMATION: + FINFO_CHECK_SIZE(4); + parms->alignment_information.out.alignment_requirement + = IVAL(blob->data, 0); + return NT_STATUS_OK; + + case RAW_FILEINFO_COMPRESSION_INFO: + case RAW_FILEINFO_COMPRESSION_INFORMATION: + FINFO_CHECK_SIZE(16); + parms->compression_info.out.compressed_size = BVAL(blob->data, 0); + parms->compression_info.out.format = SVAL(blob->data, 8); + parms->compression_info.out.unit_shift = CVAL(blob->data, 10); + parms->compression_info.out.chunk_shift = CVAL(blob->data, 11); + parms->compression_info.out.cluster_shift = CVAL(blob->data, 12); + /* 3 bytes of padding */ + return NT_STATUS_OK; + + case RAW_FILEINFO_UNIX_BASIC: + FINFO_CHECK_SIZE(100); + parms->unix_basic_info.out.end_of_file = BVAL(blob->data, 0); + parms->unix_basic_info.out.num_bytes = BVAL(blob->data, 8); + parms->unix_basic_info.out.status_change_time = cli_pull_nttime(blob->data, 16); + parms->unix_basic_info.out.access_time = cli_pull_nttime(blob->data, 24); + parms->unix_basic_info.out.change_time = cli_pull_nttime(blob->data, 32); + parms->unix_basic_info.out.uid = BVAL(blob->data, 40); + parms->unix_basic_info.out.gid = BVAL(blob->data, 48); + parms->unix_basic_info.out.file_type = IVAL(blob->data, 52); + parms->unix_basic_info.out.dev_major = BVAL(blob->data, 60); + parms->unix_basic_info.out.dev_minor = BVAL(blob->data, 68); + parms->unix_basic_info.out.unique_id = BVAL(blob->data, 76); + parms->unix_basic_info.out.permissions = BVAL(blob->data, 84); + parms->unix_basic_info.out.nlink = BVAL(blob->data, 92); + return NT_STATUS_OK; + + case RAW_FILEINFO_UNIX_LINK: + FINFO_CHECK_MIN_SIZE(0); + cli_blob_pull_string(session, mem_ctx, blob, + &parms->unix_link_info.out.link_dest, 0, 4, STR_UNICODE); + return NT_STATUS_OK; + + case RAW_FILEINFO_NETWORK_OPEN_INFORMATION: + FINFO_CHECK_SIZE(56); + parms->network_open_information.out.create_time = cli_pull_nttime(blob->data, 0); + parms->network_open_information.out.access_time = cli_pull_nttime(blob->data, 8); + parms->network_open_information.out.write_time = cli_pull_nttime(blob->data, 16); + parms->network_open_information.out.change_time = cli_pull_nttime(blob->data, 24); + parms->network_open_information.out.alloc_size = BVAL(blob->data, 32); + parms->network_open_information.out.size = BVAL(blob->data, 40); + parms->network_open_information.out.attrib = IVAL(blob->data, 48); + return NT_STATUS_OK; + + case RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION: + FINFO_CHECK_SIZE(8); + parms->attribute_tag_information.out.attrib = IVAL(blob->data, 0); + parms->attribute_tag_information.out.reparse_tag = IVAL(blob->data, 4); + return NT_STATUS_OK; + } + + return NT_STATUS_INVALID_LEVEL; +} + +/**************************************************************************** + Very raw query file info - returns param/data blobs - (async send) +****************************************************************************/ +static struct cli_request *smb_raw_fileinfo_blob_send(struct cli_tree *tree, + uint16 fnum, uint16 info_level) +{ + struct smb_trans2 tp; + uint16 setup = TRANSACT2_QFILEINFO; + struct cli_request *req; + TALLOC_CTX *mem_ctx = talloc_init("raw_fileinfo"); + + tp.in.max_setup = 0; + tp.in.flags = 0; + tp.in.timeout = 0; + tp.in.setup_count = 1; + tp.in.data = data_blob(NULL, 0); + tp.in.max_param = 2; + tp.in.max_data = 0xFFFF; + tp.in.setup = &setup; + + tp.in.params = data_blob_talloc(mem_ctx, NULL, 4); + if (!tp.in.params.data) { + talloc_destroy(mem_ctx); + return NULL; + } + + SIVAL(tp.in.params.data, 0, fnum); + SSVAL(tp.in.params.data, 2, info_level); + + req = smb_raw_trans2_send(tree, &tp); + + talloc_destroy(mem_ctx); + + return req; +} + + +/**************************************************************************** + Very raw query file info - returns param/data blobs - (async recv) +****************************************************************************/ +static NTSTATUS smb_raw_fileinfo_blob_recv(struct cli_request *req, + TALLOC_CTX *mem_ctx, + DATA_BLOB *blob) +{ + struct smb_trans2 tp; + NTSTATUS status = smb_raw_trans2_recv(req, mem_ctx, &tp); + if (NT_STATUS_IS_OK(status)) { + *blob = tp.out.data; + } + return status; +} + +/**************************************************************************** + Very raw query path info - returns param/data blobs (async send) +****************************************************************************/ +static struct cli_request *smb_raw_pathinfo_blob_send(struct cli_tree *tree, + const char *fname, + uint16 info_level) +{ + struct smb_trans2 tp; + uint16 setup = TRANSACT2_QPATHINFO; + struct cli_request *req; + TALLOC_CTX *mem_ctx = talloc_init("raw_pathinfo"); + + tp.in.max_setup = 0; + tp.in.flags = 0; + tp.in.timeout = 0; + tp.in.setup_count = 1; + tp.in.data = data_blob(NULL, 0); + tp.in.max_param = 2; + tp.in.max_data = 0xFFFF; + tp.in.setup = &setup; + + tp.in.params = data_blob_talloc(mem_ctx, NULL, 6); + if (!tp.in.params.data) { + talloc_destroy(mem_ctx); + return NULL; + } + + SSVAL(tp.in.params.data, 0, info_level); + SIVAL(tp.in.params.data, 2, 0); + cli_blob_append_string(tree->session, mem_ctx, &tp.in.params, + fname, STR_TERMINATE); + + req = smb_raw_trans2_send(tree, &tp); + + talloc_destroy(mem_ctx); + + return req; +} + +/**************************************************************************** + send a SMBgetatr (async send) +****************************************************************************/ +static struct cli_request *smb_raw_getattr_send(struct cli_tree *tree, + union smb_fileinfo *parms) +{ + struct cli_request *req; + + req = cli_request_setup(tree, SMBgetatr, 0, 0); + if (!req) return NULL; + + cli_req_append_ascii4(req, parms->getattr.in.fname, STR_TERMINATE); + + if (!cli_request_send(req)) { + cli_request_destroy(req); + return NULL; + } + + return req; +} + +/**************************************************************************** + send a SMBgetatr (async recv) +****************************************************************************/ +static NTSTATUS smb_raw_getattr_recv(struct cli_request *req, + union smb_fileinfo *parms) +{ + if (!cli_request_receive(req) || + cli_request_is_error(req)) { + return cli_request_destroy(req); + } + + CLI_CHECK_WCT(req, 10); + parms->getattr.out.attrib = SVAL(req->in.vwv, VWV(0)); + parms->getattr.out.write_time = make_unix_date3(req->in.vwv + VWV(1)); + parms->getattr.out.size = IVAL(req->in.vwv, VWV(3)); + +failed: + return cli_request_destroy(req); +} + + +/**************************************************************************** + Handle SMBgetattrE (async send) +****************************************************************************/ +static struct cli_request *smb_raw_getattrE_send(struct cli_tree *tree, + union smb_fileinfo *parms) +{ + struct cli_request *req; + + req = cli_request_setup(tree, SMBgetattrE, 1, 0); + if (!req) return NULL; + + SSVAL(req->out.vwv, VWV(0), parms->getattre.in.fnum); + if (!cli_request_send(req)) { + cli_request_destroy(req); + return NULL; + } + + return req; +} + +/**************************************************************************** + Handle SMBgetattrE (async send) +****************************************************************************/ +static NTSTATUS smb_raw_getattrE_recv(struct cli_request *req, + union smb_fileinfo *parms) +{ + if (!cli_request_receive(req) || + cli_request_is_error(req)) { + return cli_request_destroy(req); + } + + CLI_CHECK_WCT(req, 11); + parms->getattre.out.create_time = make_unix_date2(req->in.vwv + VWV(0)); + parms->getattre.out.access_time = make_unix_date2(req->in.vwv + VWV(2)); + parms->getattre.out.write_time = make_unix_date2(req->in.vwv + VWV(4)); + parms->getattre.out.size = IVAL(req->in.vwv, VWV(6)); + parms->getattre.out.alloc_size = IVAL(req->in.vwv, VWV(8)); + parms->getattre.out.attrib = SVAL(req->in.vwv, VWV(10)); + +failed: + return cli_request_destroy(req); +} + + +/**************************************************************************** + Query file info (async send) +****************************************************************************/ +struct cli_request *smb_raw_fileinfo_send(struct cli_tree *tree, + union smb_fileinfo *parms) +{ + /* pass off the non-trans2 level to specialised functions */ + if (parms->generic.level == RAW_FILEINFO_GETATTRE) { + return smb_raw_getattrE_send(tree, parms); + } + if (parms->generic.level >= RAW_FILEINFO_GENERIC) { + return NULL; + } + + return smb_raw_fileinfo_blob_send(tree, + parms->generic.in.fnum, + parms->generic.level); +} + +/**************************************************************************** + Query file info (async recv) +****************************************************************************/ +NTSTATUS smb_raw_fileinfo_recv(struct cli_request *req, + TALLOC_CTX *mem_ctx, + union smb_fileinfo *parms) +{ + DATA_BLOB blob; + NTSTATUS status; + struct cli_session *session = req?req->session:NULL; + + if (parms->generic.level == RAW_FILEINFO_GETATTRE) { + return smb_raw_getattrE_recv(req, parms); + } + if (parms->generic.level == RAW_FILEINFO_GETATTR) { + return smb_raw_getattr_recv(req, parms); + } + + status = smb_raw_fileinfo_blob_recv(req, mem_ctx, &blob); + if (!NT_STATUS_IS_OK(status)) { + return status; + } + + return smb_raw_info_backend(session, mem_ctx, parms, &blob); +} + +/**************************************************************************** + Query file info (sync interface) +****************************************************************************/ +NTSTATUS smb_raw_fileinfo(struct cli_tree *tree, + TALLOC_CTX *mem_ctx, + union smb_fileinfo *parms) +{ + struct cli_request *req = smb_raw_fileinfo_send(tree, parms); + return smb_raw_fileinfo_recv(req, mem_ctx, parms); +} + +/**************************************************************************** + Query path info (async send) +****************************************************************************/ +struct cli_request *smb_raw_pathinfo_send(struct cli_tree *tree, + union smb_fileinfo *parms) +{ + if (parms->generic.level == RAW_FILEINFO_GETATTR) { + return smb_raw_getattr_send(tree, parms); + } + if (parms->generic.level >= RAW_FILEINFO_GENERIC) { + return NULL; + } + + return smb_raw_pathinfo_blob_send(tree, parms->generic.in.fname, + parms->generic.level); +} + +/**************************************************************************** + Query path info (async recv) +****************************************************************************/ +NTSTATUS smb_raw_pathinfo_recv(struct cli_request *req, + TALLOC_CTX *mem_ctx, + union smb_fileinfo *parms) +{ + /* recv is idential to fileinfo */ + return smb_raw_fileinfo_recv(req, mem_ctx, parms); +} + +/**************************************************************************** + Query path info (sync interface) +****************************************************************************/ +NTSTATUS smb_raw_pathinfo(struct cli_tree *tree, + TALLOC_CTX *mem_ctx, + union smb_fileinfo *parms) +{ + struct cli_request *req = smb_raw_pathinfo_send(tree, parms); + return smb_raw_pathinfo_recv(req, mem_ctx, parms); +} diff --git a/source4/libcli/raw/rawfsinfo.c b/source4/libcli/raw/rawfsinfo.c new file mode 100644 index 0000000000..362063bfc5 --- /dev/null +++ b/source4/libcli/raw/rawfsinfo.c @@ -0,0 +1,282 @@ +/* + Unix SMB/CIFS implementation. + + RAW_QFS_* operations + + Copyright (C) Andrew Tridgell 2003 + + 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. +*/ + +#include "includes.h" + +/**************************************************************************** + Query FS Info - SMBdskattr call (async send) +****************************************************************************/ +static struct cli_request *smb_raw_dskattr_send(struct cli_tree *tree, + union smb_fsinfo *fsinfo) +{ + struct cli_request *req; + + req = cli_request_setup(tree, SMBdskattr, 0, 0); + + if (!cli_request_send(req)) { + cli_request_destroy(req); + return NULL; + } + + return req; +} + +/**************************************************************************** + Query FS Info - SMBdskattr call (async recv) +****************************************************************************/ +static NTSTATUS smb_raw_dskattr_recv(struct cli_request *req, + union smb_fsinfo *fsinfo) +{ + if (!cli_request_receive(req) || + cli_request_is_error(req)) { + goto failed; + } + + CLI_CHECK_WCT(req, 5); + fsinfo->dskattr.out.units_total = SVAL(req->in.vwv, VWV(0)); + fsinfo->dskattr.out.blocks_per_unit = SVAL(req->in.vwv, VWV(1)); + fsinfo->dskattr.out.block_size = SVAL(req->in.vwv, VWV(2)); + fsinfo->dskattr.out.units_free = SVAL(req->in.vwv, VWV(3)); + +failed: + return cli_request_destroy(req); +} + + +/**************************************************************************** + RAW_QFS_ trans2 interface via blobs (async send) +****************************************************************************/ +static struct cli_request *smb_raw_qfsinfo_send(struct cli_tree *tree, + TALLOC_CTX *mem_ctx, + uint16 info_level) +{ + struct smb_trans2 tp; + uint16 setup = TRANSACT2_QFSINFO; + + tp.in.max_setup = 0; + tp.in.flags = 0; + tp.in.timeout = 0; + tp.in.setup_count = 1; + tp.in.max_param = 0; + tp.in.max_data = 0x1000; /* plenty for all possible QFS levels */ + tp.in.setup = &setup; + tp.in.data = data_blob(NULL, 0); + tp.in.timeout = 0; + + tp.in.params = data_blob_talloc(mem_ctx, NULL, 2); + if (!tp.in.params.data) { + return NULL; + } + SSVAL(tp.in.params.data, 0, info_level); + + return smb_raw_trans2_send(tree, &tp); +} + +/**************************************************************************** + RAW_QFS_ trans2 interface via blobs (async recv) +****************************************************************************/ +static NTSTATUS smb_raw_qfsinfo_blob_recv(struct cli_request *req, + TALLOC_CTX *mem_ctx, + DATA_BLOB *blob) +{ + struct smb_trans2 tp; + NTSTATUS status; + + status = smb_raw_trans2_recv(req, mem_ctx, &tp); + + if (NT_STATUS_IS_OK(status)) { + (*blob) = tp.out.data; + } + + return status; +} + + +/* local macros to make the code more readable */ +#define QFS_CHECK_MIN_SIZE(size) if (blob.length < (size)) { \ + DEBUG(1,("Unexpected QFS reply size %d for level %u - expected min of %d\n", \ + blob.length, fsinfo->generic.level, (size))); \ + status = NT_STATUS_INFO_LENGTH_MISMATCH; \ + goto failed; \ +} +#define QFS_CHECK_SIZE(size) if (blob.length != (size)) { \ + DEBUG(1,("Unexpected QFS reply size %d for level %u - expected %d\n", \ + blob.length, fsinfo->generic.level, (size))); \ + status = NT_STATUS_INFO_LENGTH_MISMATCH; \ + goto failed; \ +} + + +/**************************************************************************** + Query FSInfo raw interface (async send) +****************************************************************************/ +struct cli_request *smb_raw_fsinfo_send(struct cli_tree *tree, + TALLOC_CTX *mem_ctx, + union smb_fsinfo *fsinfo) +{ + uint16 info_level; + + /* handle the only non-trans2 call separately */ + if (fsinfo->generic.level == RAW_QFS_DSKATTR) { + return smb_raw_dskattr_send(tree, fsinfo); + } + if (fsinfo->generic.level >= RAW_QFS_GENERIC) { + return NULL; + } + + /* the headers map the trans2 levels direct to info levels */ + info_level = (uint16)fsinfo->generic.level; + + return smb_raw_qfsinfo_send(tree, mem_ctx, info_level); +} + + +/**************************************************************************** + Query FSInfo raw interface (async recv) +****************************************************************************/ +NTSTATUS smb_raw_fsinfo_recv(struct cli_request *req, + TALLOC_CTX *mem_ctx, + union smb_fsinfo *fsinfo) +{ + DATA_BLOB blob; + NTSTATUS status; + int i; + struct cli_session *session = req?req->session:NULL; + + if (fsinfo->generic.level == RAW_QFS_DSKATTR) { + return smb_raw_dskattr_recv(req, fsinfo); + } + + status = smb_raw_qfsinfo_blob_recv(req, mem_ctx, &blob); + if (!NT_STATUS_IS_OK(status)) { + return status; + } + + /* parse the results */ + switch (fsinfo->generic.level) { + case RAW_QFS_GENERIC: + case RAW_QFS_DSKATTR: + /* handled above */ + break; + + case RAW_QFS_ALLOCATION: + QFS_CHECK_SIZE(18); + fsinfo->allocation.out.fs_id = IVAL(blob.data, 0); + fsinfo->allocation.out.sectors_per_unit = IVAL(blob.data, 4); + fsinfo->allocation.out.total_alloc_units = IVAL(blob.data, 8); + fsinfo->allocation.out.avail_alloc_units = IVAL(blob.data, 12); + fsinfo->allocation.out.bytes_per_sector = SVAL(blob.data, 16); + break; + + case RAW_QFS_VOLUME: + QFS_CHECK_MIN_SIZE(5); + fsinfo->volume.out.serial_number = IVAL(blob.data, 0); + cli_blob_pull_string(session, mem_ctx, &blob, + &fsinfo->volume.out.volume_name, + 4, 5, STR_LEN8BIT | STR_NOALIGN); + break; + + case RAW_QFS_VOLUME_INFO: + case RAW_QFS_VOLUME_INFORMATION: + QFS_CHECK_MIN_SIZE(18); + fsinfo->volume_info.out.create_time = cli_pull_nttime(blob.data, 0); + fsinfo->volume_info.out.serial_number = IVAL(blob.data, 8); + cli_blob_pull_string(session, mem_ctx, &blob, + &fsinfo->volume_info.out.volume_name, + 12, 18, STR_UNICODE); + break; + + case RAW_QFS_SIZE_INFO: + case RAW_QFS_SIZE_INFORMATION: + QFS_CHECK_SIZE(24); + fsinfo->size_info.out.total_alloc_units = BVAL(blob.data, 0); + fsinfo->size_info.out.avail_alloc_units = BVAL(blob.data, 8); + fsinfo->size_info.out.sectors_per_unit = IVAL(blob.data, 16); + fsinfo->size_info.out.bytes_per_sector = IVAL(blob.data, 20); + break; + + case RAW_QFS_DEVICE_INFO: + case RAW_QFS_DEVICE_INFORMATION: + QFS_CHECK_SIZE(8); + fsinfo->device_info.out.device_type = IVAL(blob.data, 0); + fsinfo->device_info.out.characteristics = IVAL(blob.data, 4); + break; + + case RAW_QFS_ATTRIBUTE_INFO: + case RAW_QFS_ATTRIBUTE_INFORMATION: + QFS_CHECK_MIN_SIZE(12); + fsinfo->attribute_info.out.fs_attr = IVAL(blob.data, 0); + fsinfo->attribute_info.out.max_file_component_length = IVAL(blob.data, 4); + cli_blob_pull_string(session, mem_ctx, &blob, + &fsinfo->attribute_info.out.fs_type, + 8, 12, STR_UNICODE); + break; + + case RAW_QFS_UNIX_INFO: + QFS_CHECK_SIZE(12); + fsinfo->unix_info.out.major_version = SVAL(blob.data, 0); + fsinfo->unix_info.out.minor_version = SVAL(blob.data, 2); + fsinfo->unix_info.out.capability = SVAL(blob.data, 4); + break; + + case RAW_QFS_QUOTA_INFORMATION: + QFS_CHECK_SIZE(48); + fsinfo->quota_information.out.unknown[0] = BVAL(blob.data, 0); + fsinfo->quota_information.out.unknown[1] = BVAL(blob.data, 8); + fsinfo->quota_information.out.unknown[2] = BVAL(blob.data, 16); + fsinfo->quota_information.out.quota_soft = BVAL(blob.data, 24); + fsinfo->quota_information.out.quota_hard = BVAL(blob.data, 32); + fsinfo->quota_information.out.quota_flags = BVAL(blob.data, 40); + break; + + case RAW_QFS_FULL_SIZE_INFORMATION: + QFS_CHECK_SIZE(32); + fsinfo->full_size_information.out.total_alloc_units = BVAL(blob.data, 0); + fsinfo->full_size_information.out.call_avail_alloc_units = BVAL(blob.data, 8); + fsinfo->full_size_information.out.actual_avail_alloc_units = BVAL(blob.data, 16); + fsinfo->full_size_information.out.sectors_per_unit = IVAL(blob.data, 24); + fsinfo->full_size_information.out.bytes_per_sector = IVAL(blob.data, 28); + break; + + case RAW_QFS_OBJECTID_INFORMATION: + QFS_CHECK_SIZE(64); + memcpy(fsinfo->objectid_information.out.guid.info, blob.data, GUID_SIZE); + for (i=0;i<6;i++) { + fsinfo->objectid_information.out.unknown[i] = BVAL(blob.data, 16 + i*8); + } + break; + } + +failed: + return status; +} + +/**************************************************************************** + Query FSInfo raw interface (sync interface) +****************************************************************************/ +NTSTATUS smb_raw_fsinfo(struct cli_tree *tree, + TALLOC_CTX *mem_ctx, + union smb_fsinfo *fsinfo) +{ + struct cli_request *req = smb_raw_fsinfo_send(tree, mem_ctx, fsinfo); + return smb_raw_fsinfo_recv(req, mem_ctx, fsinfo); +} diff --git a/source4/libcli/raw/rawioctl.c b/source4/libcli/raw/rawioctl.c new file mode 100644 index 0000000000..506bddd497 --- /dev/null +++ b/source4/libcli/raw/rawioctl.c @@ -0,0 +1,118 @@ +/* + Unix SMB/CIFS implementation. + client file operations + Copyright (C) Andrew Tridgell 2003 + + 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. +*/ + +#include "includes.h" + +#define SETUP_REQUEST(cmd, wct, buflen) do { \ + req = cli_request_setup(tree, cmd, wct, buflen); \ + if (!req) return NULL; \ +} while (0) + +/* + send a raw ioctl - async send +*/ +struct cli_request *smb_raw_ioctl_send(struct cli_tree *tree, struct smb_ioctl *parms) +{ + struct cli_request *req; + + SETUP_REQUEST(SMBioctl, 3, 0); + + SSVAL(req->out.vwv, VWV(0), parms->in.fnum); + SIVAL(req->out.vwv, VWV(1), parms->in.request); + + if (!cli_request_send(req)) { + cli_request_destroy(req); + return NULL; + } + + return req; +} + +/* + send a raw ioctl - async recv +*/ +NTSTATUS smb_raw_ioctl_recv(struct cli_request *req, TALLOC_CTX *mem_ctx, struct smb_ioctl *parms) +{ + if (!cli_request_receive(req) || + cli_request_is_error(req)) { + return cli_request_destroy(req); + } + + parms->out.blob = cli_req_pull_blob(req, mem_ctx, req->in.data, -1); + return cli_request_destroy(req); +} + +/* + send a raw ioctl - sync interface +*/ +NTSTATUS smb_raw_ioctl(struct cli_tree *tree, TALLOC_CTX *mem_ctx, struct smb_ioctl *parms) +{ + struct cli_request *req = smb_raw_ioctl_send(tree, parms); + return smb_raw_ioctl_recv(req, mem_ctx, parms); +} + + + + +/**************************************************************************** +NT ioctl (async send) +****************************************************************************/ +struct cli_request *smb_raw_ntioctl_send(struct cli_tree *tree, + struct smb_ntioctl *parms) +{ + struct smb_nttrans nt; + uint16 setup[4]; + + nt.in.max_setup = 0; + nt.in.max_param = 0; + nt.in.max_data = 0; + nt.in.setup_count = 4; + nt.in.setup = setup; + SIVAL(setup, 0, parms->in.function); + SSVAL(setup, 4, parms->in.fnum); + SCVAL(setup, 6, parms->in.fsctl); + SCVAL(setup, 7, parms->in.filter); + nt.in.function = NT_TRANSACT_IOCTL; + nt.in.params = data_blob(NULL, 0); + nt.in.data = data_blob(NULL, 0); + + return smb_raw_nttrans_send(tree, &nt); +} + +/**************************************************************************** +NT ioctl (async recv) +****************************************************************************/ +NTSTATUS smb_raw_ntioctl_recv(struct cli_request *req, + struct smb_ntioctl *parms) +{ + struct smb_nttrans nt; + + return smb_raw_nttrans_recv(req, req->mem_ctx, &nt); +} + +/**************************************************************************** +NT ioctl (sync interface) +****************************************************************************/ +NTSTATUS smb_raw_ntioctl(struct cli_tree *tree, + struct smb_ntioctl *parms) +{ + struct cli_request *req = smb_raw_ntioctl_send(tree, parms); + return smb_raw_ntioctl_recv(req, parms); +} diff --git a/source4/libcli/raw/rawnegotiate.c b/source4/libcli/raw/rawnegotiate.c new file mode 100644 index 0000000000..78b2e00706 --- /dev/null +++ b/source4/libcli/raw/rawnegotiate.c @@ -0,0 +1,157 @@ +/* + Unix SMB/CIFS implementation. + SMB client negotiate context management functions + Copyright (C) Andrew Tridgell 1994-1998 + Copyright (C) James Myers 2003 + + 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. +*/ + +#include "includes.h" + +static const struct { + int prot; + const char *name; +} prots[] = { + {PROTOCOL_CORE,"PC NETWORK PROGRAM 1.0"}, + {PROTOCOL_COREPLUS,"MICROSOFT NETWORKS 1.03"}, + {PROTOCOL_LANMAN1,"MICROSOFT NETWORKS 3.0"}, + {PROTOCOL_LANMAN1,"LANMAN1.0"}, + {PROTOCOL_LANMAN1,"Windows for Workgroups 3.1a"}, + {PROTOCOL_LANMAN2,"LM1.2X002"}, + {PROTOCOL_LANMAN2,"DOS LANMAN2.1"}, + {PROTOCOL_LANMAN2,"Samba"}, + {PROTOCOL_NT1,"NT LANMAN 1.0"}, + {PROTOCOL_NT1,"NT LM 0.12"}, +}; + +/**************************************************************************** + Send a negprot command. +****************************************************************************/ +struct cli_request *smb_negprot_send(struct cli_transport *transport, int maxprotocol) +{ + struct cli_request *req; + int i; + + req = cli_request_setup_transport(transport, SMBnegprot, 0, 0); + if (!req) { + return NULL; + } + + /* setup the protocol strings */ + for (i=0; i < ARRAY_SIZE(prots) && prots[i].prot <= maxprotocol; i++) { + cli_req_append_bytes(req, "\2", 1); + cli_req_append_string(req, prots[i].name, STR_TERMINATE | STR_ASCII); + } + + if (!cli_request_send(req)) { + cli_request_destroy(req); + return NULL; + } + + return req; +} + +/**************************************************************************** + Send a negprot command. +****************************************************************************/ +NTSTATUS smb_raw_negotiate(struct cli_transport *transport) +{ + struct cli_request *req; + int protocol; + + req = smb_negprot_send(transport, PROTOCOL_NT1); + if (!req) { + return NT_STATUS_UNSUCCESSFUL; + } + + if (!cli_request_receive(req) || + cli_request_is_error(req)) { + return cli_request_destroy(req); + } + + CLI_CHECK_MIN_WCT(req, 1); + + protocol = SVALS(req->in.vwv, VWV(0)); + + if (protocol >= ARRAY_SIZE(prots) || protocol < 0) { + req->status = NT_STATUS_UNSUCCESSFUL; + return cli_request_destroy(req); + } + + transport->negotiate.protocol = prots[protocol].prot; + + if (transport->negotiate.protocol >= PROTOCOL_NT1) { + NTTIME ntt; + + /* NT protocol */ + CLI_CHECK_WCT(req, 17); + transport->negotiate.sec_mode = CVAL(req->in.vwv,VWV(1)); + transport->negotiate.max_mux = SVAL(req->in.vwv,VWV(1)+1); + transport->negotiate.max_xmit = IVAL(req->in.vwv,VWV(3)+1); + transport->negotiate.sesskey = IVAL(req->in.vwv,VWV(7)+1); + transport->negotiate.server_zone = SVALS(req->in.vwv,VWV(15)+1) * 60; + + /* this time arrives in real GMT */ + ntt = cli_pull_nttime(req->in.vwv, VWV(11)+1); + transport->negotiate.server_time = nt_time_to_unix(&ntt); + transport->negotiate.capabilities = IVAL(req->in.vwv,VWV(9)+1); + + transport->negotiate.secblob = cli_req_pull_blob(req, transport->mem_ctx, req->in.data, req->in.data_size); + if (transport->negotiate.capabilities & CAP_RAW_MODE) { + transport->negotiate.readbraw_supported = True; + transport->negotiate.writebraw_supported = True; + } + + /* work out if they sent us a workgroup */ + if ((transport->negotiate.capabilities & CAP_EXTENDED_SECURITY) && + req->in.data_size > 16) { + cli_req_pull_string(req, transport->mem_ctx, &transport->negotiate.server_domain, + req->in.data+16, + req->in.data_size-16, STR_UNICODE|STR_NOALIGN); + } + } else if (transport->negotiate.protocol >= PROTOCOL_LANMAN1) { + CLI_CHECK_WCT(req, 13); + transport->negotiate.sec_mode = SVAL(req->in.vwv,VWV(1)); + transport->negotiate.max_xmit = SVAL(req->in.vwv,VWV(2)); + transport->negotiate.sesskey = IVAL(req->in.vwv,VWV(6)); + transport->negotiate.server_zone = SVALS(req->in.vwv,VWV(10)) * 60; + + /* this time is converted to GMT by make_unix_date */ + transport->negotiate.server_time = make_unix_date(req->in.vwv+VWV(8)); + if ((SVAL(req->in.vwv,VWV(5)) & 0x1)) { + transport->negotiate.readbraw_supported = 1; + } + if ((SVAL(req->in.vwv,VWV(5)) & 0x2)) { + transport->negotiate.writebraw_supported = 1; + } + transport->negotiate.secblob = cli_req_pull_blob(req, transport->mem_ctx, + req->in.data, req->in.data_size); + } else { + /* the old core protocol */ + transport->negotiate.sec_mode = 0; + transport->negotiate.server_time = time(NULL); + transport->negotiate.max_xmit = ~0; + transport->negotiate.server_zone = TimeDiff(time(NULL)); + } + + /* a way to force ascii SMB */ + if (getenv("CLI_FORCE_ASCII")) { + transport->negotiate.capabilities &= ~CAP_UNICODE; + } + +failed: + return cli_request_destroy(req); +} diff --git a/source4/libcli/raw/rawnotify.c b/source4/libcli/raw/rawnotify.c new file mode 100644 index 0000000000..7d635da0dc --- /dev/null +++ b/source4/libcli/raw/rawnotify.c @@ -0,0 +1,116 @@ +/* + Unix SMB/CIFS implementation. + client change notify operations + Copyright (C) Andrew Tridgell 2003 + + 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. +*/ + +#include "includes.h" + +/**************************************************************************** +change notify (async send) +****************************************************************************/ +struct cli_request *smb_raw_changenotify_send(struct cli_tree *tree, struct smb_notify *parms) +{ + struct smb_nttrans nt; + uint16 setup[4]; + + nt.in.max_setup = 0; + nt.in.max_param = parms->in.buffer_size; + nt.in.max_data = 0; + nt.in.setup_count = 4; + nt.in.setup = setup; + SIVAL(setup, 0, parms->in.completion_filter); + SSVAL(setup, 4, parms->in.fnum); + SSVAL(setup, 6, parms->in.recursive); + nt.in.function = NT_TRANSACT_NOTIFY_CHANGE; + nt.in.params = data_blob(NULL, 0); + nt.in.data = data_blob(NULL, 0); + + return smb_raw_nttrans_send(tree, &nt); +} + +/**************************************************************************** +change notify (async recv) +****************************************************************************/ +NTSTATUS smb_raw_changenotify_recv(struct cli_request *req, + TALLOC_CTX *mem_ctx, struct smb_notify *parms) +{ + struct smb_nttrans nt; + NTSTATUS status; + uint32 ofs, i; + struct cli_session *session = req?req->session:NULL; + + status = smb_raw_nttrans_recv(req, mem_ctx, &nt); + if (!NT_STATUS_IS_OK(status)) { + return status; + } + + parms->out.changes = NULL; + parms->out.num_changes = 0; + + /* count them */ + for (ofs=0; nt.out.params.length - ofs > 12; ) { + uint32 next = IVAL(nt.out.params.data, ofs); + parms->out.num_changes++; + if (next == 0 || + ofs + next >= nt.out.params.length) break; + ofs += next; + } + + /* allocate array */ + parms->out.changes = talloc(mem_ctx, sizeof(parms->out.changes[0]) * + parms->out.num_changes); + if (!parms->out.changes) { + return NT_STATUS_NO_MEMORY; + } + + for (i=ofs=0; iout.num_changes; i++) { + parms->out.changes[i].action = IVAL(nt.out.params.data, ofs+4); + cli_blob_pull_string(session, mem_ctx, &nt.out.params, + &parms->out.changes[i].name, + ofs+8, ofs+12, STR_UNICODE); + ofs += IVAL(nt.out.params.data, ofs); + } + + return NT_STATUS_OK; +} + + +/**************************************************************************** + Send a NT Cancel request - used to hurry along a pending request. Usually + used to cancel a pending change notify request + note that this request does not expect a response! +****************************************************************************/ +NTSTATUS smb_raw_ntcancel(struct cli_request *oldreq) +{ + struct cli_request *req; + + req = cli_request_setup_transport(oldreq->transport, SMBntcancel, 0, 0); + + SSVAL(req->out.hdr, HDR_MID, SVAL(oldreq->out.hdr, HDR_MID)); + SSVAL(req->out.hdr, HDR_PID, SVAL(oldreq->out.hdr, HDR_PID)); + SSVAL(req->out.hdr, HDR_TID, SVAL(oldreq->out.hdr, HDR_TID)); + SSVAL(req->out.hdr, HDR_UID, SVAL(oldreq->out.hdr, HDR_UID)); + + /* this request does not expect a reply, so tell the signing + subsystem not to allocate an id for a reply */ + req->one_way_request = 1; + + cli_request_send(req); + + return cli_request_destroy(req); +} diff --git a/source4/libcli/raw/rawreadwrite.c b/source4/libcli/raw/rawreadwrite.c new file mode 100644 index 0000000000..84c7e3c00f --- /dev/null +++ b/source4/libcli/raw/rawreadwrite.c @@ -0,0 +1,321 @@ +/* + Unix SMB/CIFS implementation. + client file read/write routines + Copyright (C) Andrew Tridgell 1994-1998 + Copyright (C) James Myers 2003 + + 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. +*/ + +#include "includes.h" + +#define SETUP_REQUEST(cmd, wct, buflen) do { \ + req = cli_request_setup(tree, cmd, wct, buflen); \ + if (!req) return NULL; \ +} while (0) + + +/**************************************************************************** + low level read operation (async send) +****************************************************************************/ +struct cli_request *smb_raw_read_send(struct cli_tree *tree, union smb_read *parms) +{ + BOOL bigoffset = False; + struct cli_request *req; + + switch (parms->generic.level) { + case RAW_READ_GENERIC: + return NULL; + + case RAW_READ_READBRAW: + if (parms->readbraw.in.offset >= 0x80000000) { + bigoffset = True; + } + SETUP_REQUEST(SMBreadbraw, bigoffset? 10:8, 0); + SSVAL(req->out.vwv, VWV(0), parms->readbraw.in.fnum); + SIVAL(req->out.vwv, VWV(1), parms->readbraw.in.offset); + SSVAL(req->out.vwv, VWV(3), parms->readbraw.in.maxcnt); + SSVAL(req->out.vwv, VWV(4), parms->readbraw.in.mincnt); + SIVAL(req->out.vwv, VWV(5), parms->readbraw.in.timeout); + SSVAL(req->out.vwv, VWV(7), 0); /* reserved */ + if (bigoffset) { + SIVAL(req->out.vwv, VWV(8),parms->readbraw.in.offset>>32); + } + break; + + case RAW_READ_LOCKREAD: + SETUP_REQUEST(SMBlockread, 5, 0); + SSVAL(req->out.vwv, VWV(0), parms->lockread.in.fnum); + SSVAL(req->out.vwv, VWV(1), parms->lockread.in.count); + SIVAL(req->out.vwv, VWV(2), parms->lockread.in.offset); + SSVAL(req->out.vwv, VWV(4), parms->lockread.in.remaining); + break; + + case RAW_READ_READ: + SETUP_REQUEST(SMBread, 5, 0); + SSVAL(req->out.vwv, VWV(0), parms->read.in.fnum); + SSVAL(req->out.vwv, VWV(1), parms->read.in.count); + SIVAL(req->out.vwv, VWV(2), parms->read.in.offset); + SSVAL(req->out.vwv, VWV(4), parms->read.in.remaining); + break; + + case RAW_READ_READX: + if (parms->readx.in.offset >= 0x80000000) { + bigoffset = True; + } + SETUP_REQUEST(SMBreadX, bigoffset ? 12 : 10, 0); + SSVAL(req->out.vwv, VWV(0), 0xFF); + SSVAL(req->out.vwv, VWV(1), 0); + SSVAL(req->out.vwv, VWV(2), parms->readx.in.fnum); + SIVAL(req->out.vwv, VWV(3), parms->readx.in.offset); + SSVAL(req->out.vwv, VWV(5), parms->readx.in.maxcnt); + SSVAL(req->out.vwv, VWV(6), parms->readx.in.mincnt); + SIVAL(req->out.vwv, VWV(7), 0); /* reserved */ + SSVAL(req->out.vwv, VWV(9), parms->readx.in.remaining); + if (bigoffset) { + SIVAL(req->out.vwv, VWV(10),parms->readx.in.offset>>32); + } + break; + } + + if (!cli_request_send(req)) { + cli_request_destroy(req); + return NULL; + } + + /* the transport layer needs to know that a readbraw is pending + and handle receives a little differently */ + if (parms->generic.level == RAW_READ_READBRAW) { + tree->session->transport->readbraw_pending = 1; + } + + return req; +} + +/**************************************************************************** + low level read operation (async recv) +****************************************************************************/ +NTSTATUS smb_raw_read_recv(struct cli_request *req, union smb_read *parms) +{ + if (!cli_request_receive(req) || + cli_request_is_error(req)) { + goto failed; + } + + switch (parms->generic.level) { + case RAW_READ_GENERIC: + /* handled in _send() */ + break; + + case RAW_READ_READBRAW: + parms->readbraw.out.nread = req->in.size - NBT_HDR_SIZE; + if (parms->readbraw.out.nread > + MAX(parms->readx.in.mincnt, parms->readx.in.maxcnt)) { + req->status = NT_STATUS_BUFFER_TOO_SMALL; + goto failed; + } + memcpy(parms->readbraw.out.data, req->in.buffer + NBT_HDR_SIZE, parms->readbraw.out.nread); + break; + + case RAW_READ_LOCKREAD: + CLI_CHECK_WCT(req, 5); + parms->lockread.out.nread = SVAL(req->in.vwv, VWV(0)); + if (parms->lockread.out.nread > parms->lockread.in.count || + !cli_raw_pull_data(req, req->in.data+3, + parms->lockread.out.nread, parms->lockread.out.data)) { + req->status = NT_STATUS_BUFFER_TOO_SMALL; + } + break; + + case RAW_READ_READ: + /* there are 4 reserved words in the reply */ + CLI_CHECK_WCT(req, 5); + parms->read.out.nread = SVAL(req->in.vwv, VWV(0)); + if (parms->read.out.nread > parms->read.in.count || + !cli_raw_pull_data(req, req->in.data+3, + parms->read.out.nread, parms->read.out.data)) { + req->status = NT_STATUS_BUFFER_TOO_SMALL; + } + break; + + case RAW_READ_READX: + /* there are 5 reserved words in the reply */ + CLI_CHECK_WCT(req, 12); + parms->readx.out.remaining = SVAL(req->in.vwv, VWV(2)); + parms->readx.out.compaction_mode = SVAL(req->in.vwv, VWV(3)); + parms->readx.out.nread = SVAL(req->in.vwv, VWV(5)); + if (parms->readx.out.nread > MAX(parms->readx.in.mincnt, parms->readx.in.maxcnt) || + !cli_raw_pull_data(req, req->in.hdr + SVAL(req->in.vwv, VWV(6)), + parms->readx.out.nread, + parms->readx.out.data)) { + req->status = NT_STATUS_BUFFER_TOO_SMALL; + } + break; + } + +failed: + return cli_request_destroy(req); +} + +/**************************************************************************** + low level read operation (sync interface) +****************************************************************************/ +NTSTATUS smb_raw_read(struct cli_tree *tree, union smb_read *parms) +{ + struct cli_request *req = smb_raw_read_send(tree, parms); + return smb_raw_read_recv(req, parms); +} + + +/**************************************************************************** + raw write interface (async send) +****************************************************************************/ +struct cli_request *smb_raw_write_send(struct cli_tree *tree, union smb_write *parms) +{ + BOOL bigoffset = False; + struct cli_request *req; + + switch (parms->generic.level) { + case RAW_WRITE_GENERIC: + return NULL; + + case RAW_WRITE_WRITEUNLOCK: + SETUP_REQUEST(SMBwriteunlock, 5, 3 + parms->writeunlock.in.count); + SSVAL(req->out.vwv, VWV(0), parms->writeunlock.in.fnum); + SSVAL(req->out.vwv, VWV(1), parms->writeunlock.in.count); + SIVAL(req->out.vwv, VWV(2), parms->writeunlock.in.offset); + SSVAL(req->out.vwv, VWV(4), parms->writeunlock.in.remaining); + SCVAL(req->out.data, 0, SMB_DATA_BLOCK); + SSVAL(req->out.data, 1, parms->writeunlock.in.count); + if (parms->writeunlock.in.count > 0) { + memcpy(req->out.data+3, parms->writeunlock.in.data, + parms->writeunlock.in.count); + } + break; + + case RAW_WRITE_WRITE: + SETUP_REQUEST(SMBwrite, 5, 3 + parms->write.in.count); + SSVAL(req->out.vwv, VWV(0), parms->write.in.fnum); + SSVAL(req->out.vwv, VWV(1), parms->write.in.count); + SIVAL(req->out.vwv, VWV(2), parms->write.in.offset); + SSVAL(req->out.vwv, VWV(4), parms->write.in.remaining); + SCVAL(req->out.data, 0, SMB_DATA_BLOCK); + SSVAL(req->out.data, 1, parms->write.in.count); + if (parms->write.in.count > 0) { + memcpy(req->out.data+3, parms->write.in.data, parms->write.in.count); + } + break; + + case RAW_WRITE_WRITECLOSE: + SETUP_REQUEST(SMBwriteclose, 6, 1 + parms->writeclose.in.count); + SSVAL(req->out.vwv, VWV(0), parms->writeclose.in.fnum); + SSVAL(req->out.vwv, VWV(1), parms->writeclose.in.count); + SIVAL(req->out.vwv, VWV(2), parms->writeclose.in.offset); + put_dos_date3(req->out.vwv, VWV(4), parms->writeclose.in.mtime); + SCVAL(req->out.data, 0, 0); + if (parms->writeclose.in.count > 0) { + memcpy(req->out.data+1, parms->writeclose.in.data, + parms->writeclose.in.count); + } + break; + + case RAW_WRITE_WRITEX: + if (parms->writex.in.offset >= 0x80000000) { + bigoffset = True; + } + SETUP_REQUEST(SMBwriteX, bigoffset ? 14 : 12, parms->writex.in.count); + SSVAL(req->out.vwv, VWV(0), 0xFF); + SSVAL(req->out.vwv, VWV(1), 0); + SSVAL(req->out.vwv, VWV(2), parms->writex.in.fnum); + SIVAL(req->out.vwv, VWV(3), parms->writex.in.offset); + SIVAL(req->out.vwv, VWV(5), 0); /* reserved */ + SSVAL(req->out.vwv, VWV(7), parms->writex.in.wmode); + SSVAL(req->out.vwv, VWV(8), parms->writex.in.remaining); + SSVAL(req->out.vwv, VWV(9), 0); /* reserved */ + SSVAL(req->out.vwv, VWV(10), parms->writex.in.count); + SSVAL(req->out.vwv, VWV(11), PTR_DIFF(req->out.data, req->out.hdr)); + if (bigoffset) { + SIVAL(req->out.vwv,VWV(12),parms->writex.in.offset>>32); + } + if (parms->writex.in.count > 0) { + memcpy(req->out.data, parms->writex.in.data, parms->writex.in.count); + } + break; + + case RAW_WRITE_SPLWRITE: + SETUP_REQUEST(SMBsplwr, 1, parms->splwrite.in.count); + SSVAL(req->out.vwv, VWV(0), parms->splwrite.in.fnum); + if (parms->splwrite.in.count > 0) { + memcpy(req->out.data, parms->splwrite.in.data, parms->splwrite.in.count); + } + break; + } + + if (!cli_request_send(req)) { +cli_request_destroy(req); + return NULL; + } + + return req; +} + + +/**************************************************************************** + raw write interface (async recv) +****************************************************************************/ +NTSTATUS smb_raw_write_recv(struct cli_request *req, union smb_write *parms) +{ + if (!cli_request_receive(req) || + cli_request_is_error(req)) { + goto failed; + } + + switch (parms->generic.level) { + case RAW_WRITE_GENERIC: + break; + case RAW_WRITE_WRITEUNLOCK: + CLI_CHECK_WCT(req, 1); + parms->writeunlock.out.nwritten = SVAL(req->in.vwv, VWV(0)); + break; + case RAW_WRITE_WRITE: + CLI_CHECK_WCT(req, 1); + parms->write.out.nwritten = SVAL(req->in.vwv, VWV(0)); + break; + case RAW_WRITE_WRITECLOSE: + CLI_CHECK_WCT(req, 1); + parms->writeclose.out.nwritten = SVAL(req->in.vwv, VWV(0)); + break; + case RAW_WRITE_WRITEX: + CLI_CHECK_WCT(req, 6); + parms->writex.out.nwritten = SVAL(req->in.vwv, VWV(2)); + parms->writex.out.nwritten += (CVAL(req->in.vwv, VWV(4)) << 16); + parms->writex.out.remaining = SVAL(req->in.vwv, VWV(3)); + break; + case RAW_WRITE_SPLWRITE: + break; + } + +failed: + return cli_request_destroy(req); +} + +/**************************************************************************** + raw write interface (sync interface) +****************************************************************************/ +NTSTATUS smb_raw_write(struct cli_tree *tree, union smb_write *parms) +{ + struct cli_request *req = smb_raw_write_send(tree, parms); + return smb_raw_write_recv(req, parms); +} diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c new file mode 100644 index 0000000000..9c2b2c7367 --- /dev/null +++ b/source4/libcli/raw/rawrequest.c @@ -0,0 +1,1019 @@ +/* + Unix SMB/CIFS implementation. + + Copyright (C) Andrew Tridgell 2003 + Copyright (C) James Myers 2003 + + 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 file implements functions for manipulating the 'struct cli_request' structure in libsmb +*/ + +#include "includes.h" + +/* we over allocate the data buffer to prevent too many realloc calls */ +#define REQ_OVER_ALLOCATION 256 + +/* assume that a character will not consume more than 3 bytes per char */ +#define MAX_BYTES_PER_CHAR 3 + +/* destroy a request structure and return final status */ +NTSTATUS cli_request_destroy(struct cli_request *req) +{ + NTSTATUS status; + + /* this is the error code we give the application for when a + _send() call fails completely */ + if (!req) return NT_STATUS_UNSUCCESSFUL; + + /* remove it from the list of pending requests (a null op if + its not in the list) */ + DLIST_REMOVE(req->transport->pending_requests, req); + + /* ahh, its so nice to destroy a complex structure in such a + simple way! */ + status = req->status; + talloc_destroy(req->mem_ctx); + return status; +} + + +/* + low-level function to setup a request buffer for a non-SMB packet + at the transport level +*/ +struct cli_request *cli_request_setup_nonsmb(struct cli_transport *transport, uint_t size) +{ + struct cli_request *req; + TALLOC_CTX *mem_ctx; + + /* each request gets its own talloc context. The request + structure itself is also allocated inside this context, + so we need to allocate it before we construct the request + */ + mem_ctx = talloc_init("cli_request"); + if (!mem_ctx) { + return NULL; + } + + req = talloc(mem_ctx, sizeof(struct cli_request)); + if (!req) { + return NULL; + } + ZERO_STRUCTP(req); + + /* setup the request context */ + req->mem_ctx = mem_ctx; + req->transport = transport; + req->session = NULL; + req->tree = NULL; + req->out.size = size; + + /* over allocate by a small amount */ + req->out.allocated = req->out.size + REQ_OVER_ALLOCATION; + + req->out.buffer = talloc(req->mem_ctx, req->out.allocated); + if (!req->out.buffer) { + return NULL; + } + + SIVAL(req->out.buffer, 0, 0); + + return req; +} + + +/* + setup a SMB packet at transport level +*/ +struct cli_request *cli_request_setup_transport(struct cli_transport *transport, + uint8 command, unsigned wct, unsigned buflen) +{ + struct cli_request *req; + + req = cli_request_setup_nonsmb(transport, NBT_HDR_SIZE + MIN_SMB_SIZE + wct*2 + buflen); + + if (!req) return NULL; + + req->out.hdr = req->out.buffer + NBT_HDR_SIZE; + req->out.vwv = req->out.hdr + HDR_VWV; + req->out.wct = wct; + req->out.data = req->out.vwv + VWV(wct) + 2; + req->out.data_size = buflen; + req->out.ptr = req->out.data; + + SCVAL(req->out.hdr, HDR_WCT, wct); + SSVAL(req->out.vwv, VWV(wct), buflen); + + memcpy(req->out.hdr, "\377SMB", 4); + SCVAL(req->out.hdr,HDR_COM,command); + + SCVAL(req->out.hdr,HDR_FLG, FLAG_CASELESS_PATHNAMES); + SSVAL(req->out.hdr,HDR_FLG2, 0); + + /* assign a mid */ + req->mid = cli_transport_next_mid(transport); + + /* copy the pid, uid and mid to the request */ + SSVAL(req->out.hdr, HDR_PID, 0); + SSVAL(req->out.hdr, HDR_UID, 0); + SSVAL(req->out.hdr, HDR_MID, req->mid); + SSVAL(req->out.hdr, HDR_TID,0); + SSVAL(req->out.hdr, HDR_PIDHIGH,0); + SIVAL(req->out.hdr, HDR_RCLS, 0); + memset(req->out.hdr+HDR_SS_FIELD, 0, 10); + + return req; +} + +/* + setup a reply in req->out with the given word count and initial data + buffer size. the caller will then fill in the command words and + data before calling cli_request_send() to send the reply on its + way. This interface is used before a session is setup. +*/ +struct cli_request *cli_request_setup_session(struct cli_session *session, + uint8 command, unsigned wct, unsigned buflen) +{ + struct cli_request *req; + uint16 flags2; + uint32 capabilities; + + req = cli_request_setup_transport(session->transport, command, wct, buflen); + + if (!req) return NULL; + + req->session = session; + + flags2 = FLAGS2_LONG_PATH_COMPONENTS; + capabilities = session->transport->negotiate.capabilities; + + if (capabilities & CAP_UNICODE) { + flags2 |= FLAGS2_UNICODE_STRINGS; + } + if (capabilities & CAP_STATUS32) { + flags2 |= FLAGS2_32_BIT_ERROR_CODES; + } + if (capabilities & CAP_EXTENDED_SECURITY) { + flags2 |= FLAGS2_EXTENDED_SECURITY; + } + if (session->transport->negotiate.sign_info.doing_signing) { + flags2 |= FLAGS2_SMB_SECURITY_SIGNATURES; + } + + SSVAL(req->out.hdr, HDR_FLG2, flags2); + SSVAL(req->out.hdr, HDR_PID, session->pid); + SSVAL(req->out.hdr, HDR_UID, session->vuid); + + return req; +} + +/* + setup a request for tree based commands +*/ +struct cli_request *cli_request_setup(struct cli_tree *tree, + uint8 command, + unsigned wct, unsigned buflen) +{ + struct cli_request *req; + + req = cli_request_setup_session(tree->session, command, wct, buflen); + if (req) { + req->tree = tree; + SSVAL(req->out.hdr,HDR_TID,tree->tid); + } + return req; +} + +/* + grow the allocation of the data buffer portion of a reply + packet. Note that as this can reallocate the packet buffer this + invalidates any local pointers into the packet. + + To cope with this req->out.ptr is supplied. This will be updated to + point at the same offset into the packet as before this call +*/ +static void cli_req_grow_allocation(struct cli_request *req, unsigned new_size) +{ + int delta; + char *buf2; + + delta = new_size - req->out.data_size; + if (delta + req->out.size <= req->out.allocated) { + /* it fits in the preallocation */ + return; + } + + /* we need to realloc */ + req->out.allocated = req->out.size + delta + REQ_OVER_ALLOCATION; + buf2 = talloc_realloc(req->mem_ctx, req->out.buffer, req->out.allocated); + if (buf2 == NULL) { + smb_panic("out of memory in req_grow_allocation"); + } + + if (buf2 == req->out.buffer) { + /* the malloc library gave us the same pointer */ + return; + } + + /* update the pointers into the packet */ + req->out.data = buf2 + PTR_DIFF(req->out.data, req->out.buffer); + req->out.ptr = buf2 + PTR_DIFF(req->out.ptr, req->out.buffer); + req->out.vwv = buf2 + PTR_DIFF(req->out.vwv, req->out.buffer); + req->out.hdr = buf2 + PTR_DIFF(req->out.hdr, req->out.buffer); + + req->out.buffer = buf2; +} + + +/* + grow the data buffer portion of a reply packet. Note that as this + can reallocate the packet buffer this invalidates any local pointers + into the packet. + + To cope with this req->out.ptr is supplied. This will be updated to + point at the same offset into the packet as before this call +*/ +static void cli_req_grow_data(struct cli_request *req, unsigned new_size) +{ + int delta; + + cli_req_grow_allocation(req, new_size); + + delta = new_size - req->out.data_size; + + req->out.size += delta; + req->out.data_size += delta; + + /* set the BCC to the new data size */ + SSVAL(req->out.vwv, VWV(req->out.wct), new_size); +} + +/* + send a message +*/ +BOOL cli_request_send(struct cli_request *req) +{ + if (IVAL(req->out.buffer, 0) == 0) { + _smb_setlen(req->out.buffer, req->out.size - NBT_HDR_SIZE); + } + + cli_request_calculate_sign_mac(req); + + if (req->out.size != cli_sock_write(req->transport->socket, req->out.buffer, req->out.size)) { + req->transport->error.etype = ETYPE_SOCKET; + req->transport->error.e.socket_error = SOCKET_WRITE_ERROR; + DEBUG(0,("Error writing %d bytes to server - %s\n", + (int)req->out.size, strerror(errno))); + return False; + } + + /* add it to the list of pending requests */ + DLIST_ADD(req->transport->pending_requests, req); + + return True; +} + + +/* + receive a response to a packet +*/ +BOOL cli_request_receive(struct cli_request *req) +{ + /* req can be NULL when a send has failed. This eliminates lots of NULL + checks in each module */ + if (!req) return False; + + /* keep receiving packets until this one is replied to */ + while (!req->in.buffer) { + if (!cli_transport_select(req->transport)) { + return False; + } + + cli_request_receive_next(req->transport); + } + + return True; +} + + +/* + handle oplock break requests from the server - return True if the request was + an oplock break +*/ +static BOOL handle_oplock_break(struct cli_transport *transport, uint_t len, const char *hdr, const char *vwv) +{ + /* we must be very fussy about what we consider an oplock break to avoid + matching readbraw replies */ + if (len != MIN_SMB_SIZE + VWV(8) || + (CVAL(hdr, HDR_FLG) & FLAG_REPLY) || + CVAL(hdr,HDR_COM) != SMBlockingX || + SVAL(hdr, HDR_MID) != 0xFFFF || + SVAL(vwv,VWV(6)) != 0 || + SVAL(vwv,VWV(7)) != 0) { + return False; + } + + if (transport->oplock.handler) { + uint16 tid = SVAL(hdr, HDR_TID); + uint16 fnum = SVAL(vwv,VWV(2)); + uint8 level = CVAL(vwv,VWV(3)); + transport->oplock.handler(transport, tid, fnum, level, transport->oplock.private); + } + + return True; +} + + +/* + receive an async message from the server + this function assumes that the caller already knows that the socket is readable + and that there is a packet waiting + + The packet is not actually returned by this function, instead any + registered async message handlers are called + + return True if a packet was successfully received and processed + return False if the socket appears to be dead +*/ +BOOL cli_request_receive_next(struct cli_transport *transport) +{ + BOOL ret; + int len; + char header[NBT_HDR_SIZE]; + char *buffer, *hdr, *vwv; + TALLOC_CTX *mem_ctx; + struct cli_request *req; + uint16 wct, mid = 0; + + len = cli_sock_read(transport->socket, header, 4); + if (len != 4) { + return False; + } + + len = smb_len(header); + + mem_ctx = talloc_init("cli_request_receive_next"); + + /* allocate the incoming buffer at the right size */ + buffer = talloc(mem_ctx, len+NBT_HDR_SIZE); + if (!buffer) { + talloc_destroy(mem_ctx); + return False; + } + + /* fill in the already received header */ + memcpy(buffer, header, NBT_HDR_SIZE); + + ret = cli_sock_read(transport->socket, buffer + NBT_HDR_SIZE, len); + /* If the server is not responding, note that now */ + if (ret != len) { + return False; + } + + hdr = buffer+NBT_HDR_SIZE; + vwv = hdr + HDR_VWV; + + /* see if it could be an oplock break request */ + if (handle_oplock_break(transport, len, hdr, vwv)) { + goto done; + } + + /* at this point we need to check for a readbraw reply, as these can be any length */ + if (transport->readbraw_pending) { + transport->readbraw_pending = 0; + + /* it must match the first entry in the pending queue as the client is not allowed + to have outstanding readbraw requests */ + req = transport->pending_requests; + if (!req) goto done; + + req->in.buffer = buffer; + talloc_steal(mem_ctx, req->mem_ctx, buffer); + req->in.size = len + NBT_HDR_SIZE; + req->in.allocated = req->in.size; + goto async; + } + + if (len >= MIN_SMB_SIZE) { + /* extract the mid for matching to pending requests */ + mid = SVAL(hdr, HDR_MID); + wct = CVAL(hdr, HDR_WCT); + } + + /* match the incoming request against the list of pending requests */ + for (req=transport->pending_requests; req; req=req->next) { + if (req->mid == mid) break; + } + + if (!req) { + DEBUG(3,("Discarding unmatched reply with mid %d\n", mid)); + goto done; + } + + /* fill in the 'in' portion of the matching request */ + req->in.buffer = buffer; + talloc_steal(mem_ctx, req->mem_ctx, buffer); + req->in.size = len + NBT_HDR_SIZE; + req->in.allocated = req->in.size; + + /* handle non-SMB replies */ + if (req->in.size < NBT_HDR_SIZE + MIN_SMB_SIZE) { + goto done; + } + + if (req->in.size < NBT_HDR_SIZE + MIN_SMB_SIZE + VWV(wct)) { + DEBUG(2,("bad reply size for mid %d\n", mid)); + req->status = NT_STATUS_UNSUCCESSFUL; + goto done; + } + + req->in.hdr = hdr; + req->in.vwv = vwv; + req->in.wct = wct; + if (req->in.size >= NBT_HDR_SIZE + MIN_SMB_SIZE + VWV(wct)) { + req->in.data = req->in.vwv + VWV(wct) + 2; + req->in.data_size = SVAL(req->in.vwv, VWV(wct)); + if (req->in.size < NBT_HDR_SIZE + MIN_SMB_SIZE + VWV(wct) + req->in.data_size) { + DEBUG(3,("bad data size for mid %d\n", mid)); + /* blergh - w2k3 gives a bogus data size values in some + openX replies */ + req->in.data_size = req->in.size - (NBT_HDR_SIZE + MIN_SMB_SIZE + VWV(wct)); + } + } + req->in.ptr = req->in.data; + req->flags2 = SVAL(req->in.hdr, HDR_FLG2); + + if (!(req->flags2 & FLAGS2_32_BIT_ERROR_CODES)) { + transport->error.etype = ETYPE_DOS; + transport->error.e.dos.eclass = CVAL(req->in.hdr,HDR_RCLS); + transport->error.e.dos.ecode = SVAL(req->in.hdr,HDR_ERR); + req->status = dos_to_ntstatus(transport->error.e.dos.eclass, + transport->error.e.dos.ecode); + } else { + transport->error.etype = ETYPE_NT; + transport->error.e.nt_status = NT_STATUS(IVAL(req->in.hdr, HDR_RCLS)); + req->status = transport->error.e.nt_status; + } + + if (!cli_request_check_sign_mac(req)) { + transport->error.etype = ETYPE_SOCKET; + transport->error.e.socket_error = SOCKET_READ_BAD_SIG; + return False; + }; + +async: + /* if this request has an async handler then call that to + notify that the reply has been received. This might destroy + the request so it must happen last */ + if (req->async.fn) { + req->async.fn(req); + } + +done: + talloc_destroy(mem_ctx); + return True; +} + + +/* + wait for a reply to be received for a packet that just returns an error + code and nothing more +*/ +NTSTATUS cli_request_simple_recv(struct cli_request *req) +{ + cli_request_receive(req); + return cli_request_destroy(req); +} + + +/* Return true if the last packet was in error */ +BOOL cli_request_is_error(struct cli_request *req) +{ + return NT_STATUS_IS_ERR(req->status); +} + +/* + append a string into the data portion of the request packet + + return the number of bytes added to the packet +*/ +size_t cli_req_append_string(struct cli_request *req, const char *str, unsigned flags) +{ + size_t len; + + /* determine string type to use */ + if (!(flags & (STR_ASCII|STR_UNICODE))) { + flags |= (req->transport->negotiate.capabilities & CAP_UNICODE) ? STR_UNICODE : STR_ASCII; + } + + len = (strlen(str)+2) * MAX_BYTES_PER_CHAR; + + cli_req_grow_allocation(req, len + req->out.data_size); + + len = push_string(NULL, req->out.data + req->out.data_size, str, len, flags); + + cli_req_grow_data(req, len + req->out.data_size); + + return len; +} + +/* + this is like cli_req_append_string but it also return the + non-terminated string byte length, which can be less than the number + of bytes consumed in the packet for 2 reasons: + + 1) the string in the packet may be null terminated + 2) the string in the packet may need a 1 byte UCS2 alignment + + this is used in places where the non-terminated string byte length is + placed in the packet as a separate field +*/ +size_t cli_req_append_string_len(struct cli_request *req, const char *str, unsigned flags, int *len) +{ + int diff = 0; + size_t ret; + + /* determine string type to use */ + if (!(flags & (STR_ASCII|STR_UNICODE))) { + flags |= (req->transport->negotiate.capabilities & CAP_UNICODE) ? STR_UNICODE : STR_ASCII; + } + + /* see if an alignment byte will be used */ + if ((flags & STR_UNICODE) && !(flags & STR_NOALIGN)) { + diff = ucs2_align(NULL, req->out.data + req->out.data_size, flags); + } + + /* do the hard work */ + ret = cli_req_append_string(req, str, flags); + + /* see if we need to subtract the termination */ + if (flags & STR_TERMINATE) { + diff += (flags & STR_UNICODE) ? 2 : 1; + } + + if (ret >= diff) { + (*len) = ret - diff; + } else { + (*len) = ret; + } + + return ret; +} + + +/* + push a string into the data portion of the request packet, growing it if necessary + this gets quite tricky - please be very careful to cover all cases when modifying this + + if dest is NULL, then put the string at the end of the data portion of the packet + + if dest_len is -1 then no limit applies +*/ +size_t cli_req_append_ascii4(struct cli_request *req, const char *str, unsigned flags) +{ + size_t size; + cli_req_append_bytes(req, (const uint8 *)"\4", 1); + size = cli_req_append_string(req, str, flags); + return size + 1; +} + + +/* + push a blob into the data portion of the request packet, growing it if necessary + this gets quite tricky - please be very careful to cover all cases when modifying this + + if dest is NULL, then put the blob at the end of the data portion of the packet +*/ +size_t cli_req_append_blob(struct cli_request *req, const DATA_BLOB *blob) +{ + cli_req_grow_allocation(req, req->out.data_size + blob->length); + memcpy(req->out.data + req->out.data_size, blob->data, blob->length); + cli_req_grow_data(req, req->out.data_size + blob->length); + return blob->length; +} + +/* + append raw bytes into the data portion of the request packet + return the number of bytes added +*/ +size_t cli_req_append_bytes(struct cli_request *req, const uint8 *bytes, size_t byte_len) +{ + cli_req_grow_allocation(req, byte_len + req->out.data_size); + memcpy(req->out.data + req->out.data_size, bytes, byte_len); + cli_req_grow_data(req, byte_len + req->out.data_size); + return byte_len; +} + +/* + append variable block (type 5 buffer) into the data portion of the request packet + return the number of bytes added +*/ +size_t cli_req_append_var_block(struct cli_request *req, const uint8 *bytes, uint16 byte_len) +{ + cli_req_grow_allocation(req, byte_len + 3 + req->out.data_size); + SCVAL(req->out.data + req->out.data_size, 0, 5); + SSVAL(req->out.data + req->out.data_size, 1, byte_len); /* add field length */ + if (byte_len > 0) { + memcpy(req->out.data + req->out.data_size + 3, bytes, byte_len); + } + cli_req_grow_data(req, byte_len + 3 + req->out.data_size); + return byte_len + 3; +} + + +/* + pull a UCS2 string from a request packet, returning a talloced unix string + + the string length is limited by the 3 things: + - the data size in the request (end of packet) + - the passed 'byte_len' if it is not -1 + - the end of string (null termination) + + Note that 'byte_len' is the number of bytes in the packet + + on failure zero is returned and *dest is set to NULL, otherwise the number + of bytes consumed in the packet is returned +*/ +static size_t cli_req_pull_ucs2(struct cli_request *req, TALLOC_CTX *mem_ctx, + char **dest, const char *src, int byte_len, unsigned flags) +{ + int src_len, src_len2, alignment=0; + ssize_t ret; + + if (!(flags & STR_NOALIGN) && ucs2_align(req->in.buffer, src, flags)) { + src++; + alignment=1; + if (byte_len != -1) { + byte_len--; + } + } + + src_len = req->in.data_size - PTR_DIFF(src, req->in.data); + if (src_len < 0) { + *dest = NULL; + return 0; + } + if (byte_len != -1 && src_len > byte_len) { + src_len = byte_len; + } + + src_len2 = strnlen_w((const smb_ucs2_t *)src, src_len/2) * 2; + if (src_len2 < src_len - 2) { + /* include the termination if we didn't reach the end of the packet */ + src_len2 += 2; + } + + /* ucs2 strings must be at least 2 bytes long */ + if (src_len2 < 2) { + *dest = NULL; + return 0; + } + + ret = convert_string_talloc(mem_ctx, CH_UCS2, CH_UNIX, src, src_len2, (const void **)dest); + if (ret == -1) { + *dest = NULL; + return 0; + } + + return src_len2 + alignment; +} + +/* + pull a ascii string from a request packet, returning a talloced string + + the string length is limited by the 3 things: + - the data size in the request (end of packet) + - the passed 'byte_len' if it is not -1 + - the end of string (null termination) + + Note that 'byte_len' is the number of bytes in the packet + + on failure zero is returned and *dest is set to NULL, otherwise the number + of bytes consumed in the packet is returned +*/ +size_t cli_req_pull_ascii(struct cli_request *req, TALLOC_CTX *mem_ctx, + char **dest, const char *src, int byte_len, unsigned flags) +{ + int src_len, src_len2; + ssize_t ret; + + src_len = req->in.data_size - PTR_DIFF(src, req->in.data); + if (src_len < 0) { + *dest = NULL; + return 0; + } + if (byte_len != -1 && src_len > byte_len) { + src_len = byte_len; + } + src_len2 = strnlen(src, src_len); + if (src_len2 < src_len - 1) { + /* include the termination if we didn't reach the end of the packet */ + src_len2++; + } + + ret = convert_string_talloc(mem_ctx, CH_DOS, CH_UNIX, src, src_len2, (const void **)dest); + + if (ret == -1) { + *dest = NULL; + return 0; + } + + return ret; +} + +/* + pull a string from a request packet, returning a talloced string + + the string length is limited by the 3 things: + - the data size in the request (end of packet) + - the passed 'byte_len' if it is not -1 + - the end of string (null termination) + + Note that 'byte_len' is the number of bytes in the packet + + on failure zero is returned and *dest is set to NULL, otherwise the number + of bytes consumed in the packet is returned +*/ +size_t cli_req_pull_string(struct cli_request *req, TALLOC_CTX *mem_ctx, + char **dest, const char *src, int byte_len, unsigned flags) +{ + if (!(flags & STR_ASCII) && + ((flags & STR_UNICODE || (req->flags2 & FLAGS2_UNICODE_STRINGS)))) { + return cli_req_pull_ucs2(req, mem_ctx, dest, src, byte_len, flags); + } + + return cli_req_pull_ascii(req, mem_ctx, dest, src, byte_len, flags); +} + + +/* + pull a DATA_BLOB from a reply packet, returning a talloced blob + make sure we don't go past end of packet + + if byte_len is -1 then limit the blob only by packet size +*/ +DATA_BLOB cli_req_pull_blob(struct cli_request *req, TALLOC_CTX *mem_ctx, const char *src, int byte_len) +{ + int src_len; + + src_len = req->in.data_size - PTR_DIFF(src, req->in.data); + + if (src_len < 0) { + return data_blob(NULL, 0); + } + + if (byte_len != -1 && src_len > byte_len) { + src_len = byte_len; + } + + return data_blob_talloc(mem_ctx, src, src_len); +} + +/* check that a lump of data in a request is within the bounds of the data section of + the packet */ +static BOOL cli_req_data_oob(struct cli_request *req, const char *ptr, uint32 count) +{ + /* be careful with wraparound! */ + if (ptr < req->in.data || + ptr >= req->in.data + req->in.data_size || + count > req->in.data_size || + ptr + count > req->in.data + req->in.data_size) { + return True; + } + return False; +} + +/* + pull a lump of data from a request packet + + return False if any part is outside the data portion of the packet +*/ +BOOL cli_raw_pull_data(struct cli_request *req, const char *src, int len, char *dest) +{ + if (len == 0) return True; + + if (cli_req_data_oob(req, src, len)) { + return False; + } + + memcpy(dest, src, len); + return True; +} + + +/* + put a NTTIME into a packet +*/ + +void cli_push_nttime(void *base, uint16 offset, NTTIME *t) +{ + SIVAL(base, offset, t->low); + SIVAL(base, offset+4, t->high); +} + +/* + pull a NTTIME from a packet +*/ +NTTIME cli_pull_nttime(void *base, uint16 offset) +{ + NTTIME ret; + ret.low = IVAL(base, offset); + ret.high = IVAL(base, offset+4); + return ret; +} + +/* + pull a UCS2 string from a blob, returning a talloced unix string + + the string length is limited by the 3 things: + - the data size in the blob + - the passed 'byte_len' if it is not -1 + - the end of string (null termination) + + Note that 'byte_len' is the number of bytes in the packet + + on failure zero is returned and *dest is set to NULL, otherwise the number + of bytes consumed in the blob is returned +*/ +static size_t cli_blob_pull_ucs2(TALLOC_CTX* mem_ctx, + DATA_BLOB *blob, const char **dest, + const char *src, int byte_len, unsigned flags) +{ + int src_len, src_len2, alignment=0; + ssize_t ret; + + if (src < (const char *)blob->data || + src >= (const char *)(blob->data + blob->length)) { + *dest = NULL; + return 0; + } + + src_len = blob->length - PTR_DIFF(src, blob->data); + + if (byte_len != -1 && src_len > byte_len) { + src_len = byte_len; + } + + if (!(flags & STR_NOALIGN) && ucs2_align(blob->data, src, flags)) { + src++; + alignment=1; + src_len--; + } + + if (src_len < 2) { + *dest = NULL; + return 0; + } + + src_len2 = strnlen_w((const smb_ucs2_t *)src, src_len/2) * 2; + + if (src_len2 < src_len - 2) { + /* include the termination if we didn't reach the end of the packet */ + src_len2 += 2; + } + + ret = convert_string_talloc(mem_ctx, CH_UCS2, CH_UNIX, src, src_len2, (const void **)dest); + if (ret == -1) { + *dest = NULL; + return 0; + } + + return src_len2 + alignment; +} + +/* + pull a ascii string from a blob, returning a talloced string + + the string length is limited by the 3 things: + - the data size in the blob + - the passed 'byte_len' if it is not -1 + - the end of string (null termination) + + Note that 'byte_len' is the number of bytes in the blob + + on failure zero is returned and *dest is set to NULL, otherwise the number + of bytes consumed in the blob is returned +*/ +static size_t cli_blob_pull_ascii(TALLOC_CTX *mem_ctx, + DATA_BLOB *blob, const char **dest, + const char *src, int byte_len, unsigned flags) +{ + int src_len, src_len2; + ssize_t ret; + + src_len = blob->length - PTR_DIFF(src, blob->data); + if (src_len < 0) { + *dest = NULL; + return 0; + } + if (byte_len != -1 && src_len > byte_len) { + src_len = byte_len; + } + src_len2 = strnlen(src, src_len); + + if (src_len2 < src_len - 1) { + /* include the termination if we didn't reach the end of the packet */ + src_len2++; + } + + ret = convert_string_talloc(mem_ctx, CH_DOS, CH_UNIX, src, src_len2, (const void **)dest); + + if (ret == -1) { + *dest = NULL; + return 0; + } + + return ret; +} + +/* + pull a string from a blob, returning a talloced WIRE_STRING + + the string length is limited by the 3 things: + - the data size in the blob + - length field on the wire + - the end of string (null termination) + + if STR_LEN8BIT is set in the flags then assume the length field is + 8 bits, instead of 32 + + on failure zero is returned and dest->s is set to NULL, otherwise the number + of bytes consumed in the blob is returned +*/ +size_t cli_blob_pull_string(struct cli_session *session, + TALLOC_CTX *mem_ctx, + DATA_BLOB *blob, + WIRE_STRING *dest, + uint16 len_offset, uint16 str_offset, + unsigned flags) +{ + dest->s = NULL; + + if (len_offset > blob->length-4) { + return 0; + } + if (flags & STR_LEN8BIT) { + dest->private_length = CVAL(blob->data, len_offset); + } else { + dest->private_length = IVAL(blob->data, len_offset); + } + dest->s = NULL; + if (!(flags & STR_ASCII) && + ((flags & STR_UNICODE) || + (session->transport->negotiate.capabilities & CAP_UNICODE))) { + if ((str_offset&1) && !(flags & STR_NOALIGN)) { + str_offset++; + } + return cli_blob_pull_ucs2(mem_ctx, blob, &dest->s, + blob->data+str_offset, dest->private_length, flags); + } + + return cli_blob_pull_ascii(mem_ctx, blob, &dest->s, + blob->data+str_offset, dest->private_length, flags); +} + +/* + append a string into a blob +*/ +size_t cli_blob_append_string(struct cli_session *session, + TALLOC_CTX *mem_ctx, DATA_BLOB *blob, + const char *str, unsigned flags) +{ + size_t max_len; + int len; + + if (!str) return 0; + + /* determine string type to use */ + if (!(flags & (STR_ASCII|STR_UNICODE))) { + flags |= (session->transport->negotiate.capabilities & CAP_UNICODE) ? STR_UNICODE : STR_ASCII; + } + + max_len = (strlen(str)+2) * MAX_BYTES_PER_CHAR; + + blob->data = talloc_realloc(mem_ctx, blob->data, blob->length + max_len); + if (!blob->data) { + return 0; + } + + len = push_string(NULL, blob->data + blob->length, str, max_len, flags); + + blob->length += len; + + return len; +} diff --git a/source4/libcli/raw/rawsearch.c b/source4/libcli/raw/rawsearch.c new file mode 100644 index 0000000000..bdc39bb68c --- /dev/null +++ b/source4/libcli/raw/rawsearch.c @@ -0,0 +1,569 @@ +/* + Unix SMB/CIFS implementation. + client directory search routines + Copyright (C) James Myers 2003 + + 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. +*/ + +#include "includes.h" + +/**************************************************************************** + Old style search backend - process output. +****************************************************************************/ +static void smb_raw_search_backend(struct cli_request *req, + TALLOC_CTX *mem_ctx, + uint16 count, + void *private, + BOOL (*callback)(void *private, union smb_search_data *file)) + +{ + union smb_search_data search_data; + int i; + char *p; + + if (req->in.data_size < 3 + count*43) { + req->status = NT_STATUS_INVALID_PARAMETER; + return; + } + + p = req->in.data + 3; + + for (i=0; i < count; i++) { + search_data.search.search_id = cli_req_pull_blob(req, mem_ctx, p, 21); + search_data.search.attrib = CVAL(p, 21); + search_data.search.write_time = make_unix_date(p + 22); + search_data.search.size = IVAL(p, 26); + cli_req_pull_ascii(req, mem_ctx, &search_data.search.name, p+30, 13, STR_ASCII); + if (!callback(private, &search_data)) { + break; + } + p += 43; + } +} + +/**************************************************************************** + Old style search first. +****************************************************************************/ +static NTSTATUS smb_raw_search_first_old(struct cli_tree *tree, + TALLOC_CTX *mem_ctx, + union smb_search_first *io, void *private, + BOOL (*callback)(void *private, union smb_search_data *file)) + +{ + struct cli_request *req; + + req = cli_request_setup(tree, SMBsearch, 2, 0); + if (!req) { + return NT_STATUS_NO_MEMORY; + } + + SSVAL(req->out.vwv, VWV(0), io->search_first.in.max_count); + SSVAL(req->out.vwv, VWV(1), io->search_first.in.search_attrib); + cli_req_append_ascii4(req, io->search_first.in.pattern, STR_TERMINATE); + cli_req_append_var_block(req, NULL, 0); + + if (!cli_request_send(req) || + !cli_request_receive(req)) { + return cli_request_destroy(req); + } + + if (NT_STATUS_IS_OK(req->status)) { + io->search_first.out.count = SVAL(req->in.vwv, VWV(0)); + smb_raw_search_backend(req, mem_ctx, io->search_first.out.count, private, callback); + } + + return cli_request_destroy(req); +} + +/**************************************************************************** + Old style search next. +****************************************************************************/ +static NTSTATUS smb_raw_search_next_old(struct cli_tree *tree, + TALLOC_CTX *mem_ctx, + union smb_search_next *io, void *private, + BOOL (*callback)(void *private, union smb_search_data *file)) + +{ + struct cli_request *req; + + req = cli_request_setup(tree, SMBsearch, 2, 0); + if (!req) { + return NT_STATUS_NO_MEMORY; + } + + SSVAL(req->out.vwv, VWV(0), io->search_next.in.max_count); + SSVAL(req->out.vwv, VWV(1), io->search_next.in.search_attrib); + cli_req_append_ascii4(req, "", STR_TERMINATE); + cli_req_append_var_block(req, io->search_next.in.search_id.data, 21); + + if (!cli_request_send(req) || + !cli_request_receive(req)) { + return cli_request_destroy(req); + } + + if (NT_STATUS_IS_OK(req->status)) { + io->search_next.out.count = SVAL(req->in.vwv, VWV(0)); + smb_raw_search_backend(req, mem_ctx, io->search_next.out.count, private, callback); + } + + return cli_request_destroy(req); +} + +/**************************************************************************** + Very raw search first - returns param/data blobs. +****************************************************************************/ +static NTSTATUS smb_raw_search_first_blob(struct cli_tree *tree, + TALLOC_CTX *mem_ctx, /* used to allocate output blobs */ + union smb_search_first *io, + uint16 info_level, + DATA_BLOB *out_param_blob, + DATA_BLOB *out_data_blob) +{ + struct smb_trans2 tp; + uint16 setup = TRANSACT2_FINDFIRST; + NTSTATUS status; + + tp.in.max_setup = 0; + tp.in.flags = 0; + tp.in.timeout = 0; + tp.in.setup_count = 1; + tp.in.data = data_blob(NULL, 0); + tp.in.max_param = 1024; + tp.in.max_data = 8192; + tp.in.setup = &setup; + + tp.in.params = data_blob_talloc(mem_ctx, NULL, 12); + if (!tp.in.params.data) { + return NT_STATUS_NO_MEMORY; + } + + SSVAL(tp.in.params.data, 0, io->t2ffirst.in.search_attrib); + SSVAL(tp.in.params.data, 2, io->t2ffirst.in.max_count); + SSVAL(tp.in.params.data, 4, io->t2ffirst.in.flags); + SSVAL(tp.in.params.data, 6, info_level); + SIVAL(tp.in.params.data, 8, io->t2ffirst.in.storage_type); + + cli_blob_append_string(tree->session, mem_ctx, &tp.in.params, + io->t2ffirst.in.pattern, STR_TERMINATE); + + status = smb_raw_trans2(tree, mem_ctx, &tp); + if (!NT_STATUS_IS_OK(status)) { + return status; + } + + out_param_blob->length = tp.out.params.length; + out_param_blob->data = tp.out.params.data; + out_data_blob->length = tp.out.data.length; + out_data_blob->data = tp.out.data.data; + + return NT_STATUS_OK; +} + + +/**************************************************************************** + Very raw search first - returns param/data blobs. + Used in CIFS-on-CIFS NTVFS. +****************************************************************************/ +static NTSTATUS smb_raw_search_next_blob(struct cli_tree *tree, + TALLOC_CTX *mem_ctx, + union smb_search_next *io, + uint16 info_level, + DATA_BLOB *out_param_blob, + DATA_BLOB *out_data_blob) +{ + struct smb_trans2 tp; + uint16 setup = TRANSACT2_FINDNEXT; + NTSTATUS status; + + tp.in.max_setup = 0; + tp.in.flags = 0; + tp.in.timeout = 0; + tp.in.setup_count = 1; + tp.in.data = data_blob(NULL, 0); + tp.in.max_param = 1024; + tp.in.max_data = 8192; + tp.in.setup = &setup; + + tp.in.params = data_blob_talloc(mem_ctx, NULL, 12); + if (!tp.in.params.data) { + return NT_STATUS_NO_MEMORY; + } + + SSVAL(tp.in.params.data, 0, io->t2fnext.in.handle); + SSVAL(tp.in.params.data, 2, io->t2fnext.in.max_count); + SSVAL(tp.in.params.data, 4, info_level); + SIVAL(tp.in.params.data, 6, io->t2fnext.in.resume_key); + SSVAL(tp.in.params.data, 10, io->t2fnext.in.flags); + + cli_blob_append_string(tree->session, mem_ctx, &tp.in.params, + io->t2fnext.in.last_name, + STR_TERMINATE); + + status = smb_raw_trans2(tree, mem_ctx, &tp); + if (!NT_STATUS_IS_OK(status)) { + return status; + } + + out_param_blob->length = tp.out.params.length; + out_param_blob->data = tp.out.params.data; + out_data_blob->length = tp.out.data.length; + out_data_blob->data = tp.out.data.data; + + return NT_STATUS_OK; +} + + +/* + parse a trans2 search response. + Return the number of bytes consumed + return 0 for success with end of list + return -1 for a parse error +*/ +static int parse_trans2_search(struct cli_tree *tree, + TALLOC_CTX *mem_ctx, + enum search_level level, + uint16 flags, + DATA_BLOB *blob, + union smb_search_data *data) +{ + uint_t len, ofs; + + switch (level) { + case RAW_SEARCH_GENERIC: + case RAW_SEARCH_SEARCH: + /* handled elsewhere */ + return -1; + + case RAW_SEARCH_STANDARD: + if (flags & FLAG_TRANS2_FIND_REQUIRE_RESUME) { + if (blob->length < 4) return -1; + data->standard.resume_key = IVAL(blob->data, 0); + blob->data += 4; + blob->length -= 4; + } + if (blob->length < 24) return -1; + data->standard.create_time = make_unix_date2(blob->data + 0); + data->standard.access_time = make_unix_date2(blob->data + 4); + data->standard.write_time = make_unix_date2(blob->data + 8); + data->standard.size = IVAL(blob->data, 12); + data->standard.alloc_size = IVAL(blob->data, 16); + data->standard.attrib = SVAL(blob->data, 20); + len = cli_blob_pull_string(tree->session, mem_ctx, blob, + &data->standard.name, + 22, 23, STR_LEN8BIT); + return (len + 23 + 3) & ~3; + + case RAW_SEARCH_EA_SIZE: + if (flags & FLAG_TRANS2_FIND_REQUIRE_RESUME) { + if (blob->length < 4) return -1; + data->ea_size.resume_key = IVAL(blob->data, 0); + blob->data += 4; + blob->length -= 4; + } + if (blob->length < 28) return -1; + data->ea_size.create_time = make_unix_date2(blob->data + 0); + data->ea_size.access_time = make_unix_date2(blob->data + 4); + data->ea_size.write_time = make_unix_date2(blob->data + 8); + data->ea_size.size = IVAL(blob->data, 12); + data->ea_size.alloc_size = IVAL(blob->data, 16); + data->ea_size.attrib = SVAL(blob->data, 20); + data->ea_size.ea_size = IVAL(blob->data, 22); + len = cli_blob_pull_string(tree->session, mem_ctx, blob, + &data->ea_size.name, + 26, 27, STR_LEN8BIT | STR_NOALIGN); + return len + 27; + + case RAW_SEARCH_DIRECTORY_INFO: + if (blob->length < 65) return -1; + ofs = IVAL(blob->data, 0); + data->directory_info.file_index = IVAL(blob->data, 4); + data->directory_info.create_time = cli_pull_nttime(blob->data, 8); + data->directory_info.access_time = cli_pull_nttime(blob->data, 16); + data->directory_info.write_time = cli_pull_nttime(blob->data, 24); + data->directory_info.change_time = cli_pull_nttime(blob->data, 32); + data->directory_info.size = BVAL(blob->data, 40); + data->directory_info.alloc_size = BVAL(blob->data, 48); + data->directory_info.attrib = IVAL(blob->data, 56); + len = cli_blob_pull_string(tree->session, mem_ctx, blob, + &data->directory_info.name, + 60, 64, 0); + if (ofs != 0 && ofs < 64+len) { + return -1; + } + return ofs; + + case RAW_SEARCH_FULL_DIRECTORY_INFO: + if (blob->length < 69) return -1; + ofs = IVAL(blob->data, 0); + data->full_directory_info.file_index = IVAL(blob->data, 4); + data->full_directory_info.create_time = cli_pull_nttime(blob->data, 8); + data->full_directory_info.access_time = cli_pull_nttime(blob->data, 16); + data->full_directory_info.write_time = cli_pull_nttime(blob->data, 24); + data->full_directory_info.change_time = cli_pull_nttime(blob->data, 32); + data->full_directory_info.size = BVAL(blob->data, 40); + data->full_directory_info.alloc_size = BVAL(blob->data, 48); + data->full_directory_info.attrib = IVAL(blob->data, 56); + data->full_directory_info.ea_size = IVAL(blob->data, 64); + len = cli_blob_pull_string(tree->session, mem_ctx, blob, + &data->full_directory_info.name, + 60, 68, 0); + if (ofs != 0 && ofs < 68+len) { + return -1; + } + return ofs; + + case RAW_SEARCH_NAME_INFO: + if (blob->length < 13) return -1; + ofs = IVAL(blob->data, 0); + data->name_info.file_index = IVAL(blob->data, 4); + len = cli_blob_pull_string(tree->session, mem_ctx, blob, + &data->name_info.name, + 8, 12, 0); + if (ofs != 0 && ofs < 12+len) { + return -1; + } + return ofs; + + + case RAW_SEARCH_BOTH_DIRECTORY_INFO: + if (blob->length < 95) return -1; + ofs = IVAL(blob->data, 0); + data->both_directory_info.file_index = IVAL(blob->data, 4); + data->both_directory_info.create_time = cli_pull_nttime(blob->data, 8); + data->both_directory_info.access_time = cli_pull_nttime(blob->data, 16); + data->both_directory_info.write_time = cli_pull_nttime(blob->data, 24); + data->both_directory_info.change_time = cli_pull_nttime(blob->data, 32); + data->both_directory_info.size = BVAL(blob->data, 40); + data->both_directory_info.alloc_size = BVAL(blob->data, 48); + data->both_directory_info.attrib = IVAL(blob->data, 56); + data->both_directory_info.ea_size = IVAL(blob->data, 64); + cli_blob_pull_string(tree->session, mem_ctx, blob, + &data->both_directory_info.short_name, + 68, 70, STR_LEN8BIT | STR_UNICODE); + len = cli_blob_pull_string(tree->session, mem_ctx, blob, + &data->both_directory_info.name, + 60, 94, 0); + if (ofs != 0 && ofs < 94+len) { + return -1; + } + return ofs; + + + case RAW_SEARCH_261: + if (blob->length < 81) return -1; + ofs = IVAL(blob->data, 0); + data->level_261.file_index = IVAL(blob->data, 4); + data->level_261.create_time = cli_pull_nttime(blob->data, 8); + data->level_261.access_time = cli_pull_nttime(blob->data, 16); + data->level_261.write_time = cli_pull_nttime(blob->data, 24); + data->level_261.change_time = cli_pull_nttime(blob->data, 32); + data->level_261.size = BVAL(blob->data, 40); + data->level_261.alloc_size = BVAL(blob->data, 48); + data->level_261.attrib = IVAL(blob->data, 56); + data->level_261.ea_size = IVAL(blob->data, 64); + data->level_261.unknown[0] = IVAL(blob->data, 68); + data->level_261.unknown[1] = IVAL(blob->data, 72); + data->level_261.unknown[2] = IVAL(blob->data, 76); + len = cli_blob_pull_string(tree->session, mem_ctx, blob, + &data->level_261.name, + 60, 80, 0); + if (ofs != 0 && ofs < 80+len) { + return -1; + } + return ofs; + + case RAW_SEARCH_262: + if (blob->length < 105) return -1; + ofs = IVAL(blob->data, 0); + data->level_262.file_index = IVAL(blob->data, 4); + data->level_262.create_time = cli_pull_nttime(blob->data, 8); + data->level_262.access_time = cli_pull_nttime(blob->data, 16); + data->level_262.write_time = cli_pull_nttime(blob->data, 24); + data->level_262.change_time = cli_pull_nttime(blob->data, 32); + data->level_262.size = BVAL(blob->data, 40); + data->level_262.alloc_size = BVAL(blob->data, 48); + data->level_262.attrib = SVAL(blob->data, 56); + data->level_262.ea_size = IVAL(blob->data, 64); + cli_blob_pull_string(tree->session, mem_ctx, blob, + &data->level_262.short_name, + 68, 70, STR_LEN8BIT | STR_UNICODE); + data->level_262.unknown[0] = IVAL(blob->data, 94); + data->level_262.unknown[1] = IVAL(blob->data, 98); + len = cli_blob_pull_string(tree->session, mem_ctx, blob, + &data->level_262.name, + 60, 104, 0); + if (ofs != 0 && ofs < 104+len) { + return -1; + } + return ofs; + } + + /* invalid level */ + return -1; +} + +/**************************************************************************** + Trans2 search backend - process output. +****************************************************************************/ +static NTSTATUS smb_raw_t2search_backend(struct cli_tree *tree, + TALLOC_CTX *mem_ctx, + enum search_level level, + uint16 flags, + int16 count, + DATA_BLOB *blob, + void *private, + BOOL (*callback)(void *private, union smb_search_data *file)) + +{ + int i; + DATA_BLOB blob2; + + blob2.data = blob->data; + blob2.length = blob->length; + + for (i=0; i < count; i++) { + union smb_search_data search_data; + uint_t len; + + len = parse_trans2_search(tree, mem_ctx, level, flags, &blob2, &search_data); + if (len == -1) { + return NT_STATUS_INVALID_PARAMETER; + } + + /* the callback function can tell us that no more will + fit - in that case we stop, but it isn't an error */ + if (!callback(private, &search_data)) { + break; + } + + if (len == 0) break; + + blob2.data += len; + blob2.length -= len; + } + + return NT_STATUS_OK; +} + + +/* Implements trans2findfirst2 and old search + */ +NTSTATUS smb_raw_search_first(struct cli_tree *tree, + TALLOC_CTX *mem_ctx, + union smb_search_first *io, void *private, + BOOL (*callback)(void *private, union smb_search_data *file)) +{ + uint16 info_level = 0; + DATA_BLOB p_blob, d_blob; + NTSTATUS status; + + if (io->generic.level == RAW_SEARCH_SEARCH) { + return smb_raw_search_first_old(tree, mem_ctx, io, private, callback); + } + if (io->generic.level >= RAW_SEARCH_GENERIC) { + return NT_STATUS_INVALID_LEVEL; + } + info_level = (uint16)io->generic.level; + + status = smb_raw_search_first_blob(tree, mem_ctx, + io, info_level, &p_blob, &d_blob); + if (!NT_STATUS_IS_OK(status)) { + return status; + } + + if (p_blob.length != 10) { + DEBUG(1,("smb_raw_search_first: parms wrong size %d != expected_param_size\n", + p_blob.length)); + return NT_STATUS_INVALID_PARAMETER; + } + + /* process output data */ + io->t2ffirst.out.handle = SVAL(p_blob.data, 0); + io->t2ffirst.out.count = SVAL(p_blob.data, 2); + io->t2ffirst.out.end_of_search = SVAL(p_blob.data, 4); + + status = smb_raw_t2search_backend(tree, mem_ctx, + io->generic.level, + io->t2ffirst.in.flags, io->t2ffirst.out.count, + &d_blob, private, callback); + + return status; +} + +/* Implements trans2findnext2 and old smbsearch + */ +NTSTATUS smb_raw_search_next(struct cli_tree *tree, + TALLOC_CTX *mem_ctx, + union smb_search_next *io, void *private, + BOOL (*callback)(void *private, union smb_search_data *file)) +{ + uint16 info_level = 0; + DATA_BLOB p_blob, d_blob; + NTSTATUS status; + + if (io->generic.level == RAW_SEARCH_SEARCH) { + return smb_raw_search_next_old(tree, mem_ctx, io, private, callback); + } + if (io->generic.level >= RAW_SEARCH_GENERIC) { + return NT_STATUS_INVALID_LEVEL; + } + info_level = (uint16)io->generic.level; + + status = smb_raw_search_next_blob(tree, mem_ctx, + io, info_level, &p_blob, &d_blob); + if (!NT_STATUS_IS_OK(status)) { + return status; + } + + if (p_blob.length != 8) { + DEBUG(1,("smb_raw_search_next: parms wrong size %d != expected_param_size\n", + p_blob.length)); + return NT_STATUS_INVALID_PARAMETER; + } + + /* process output data */ + io->t2fnext.out.count = SVAL(p_blob.data, 0); + io->t2fnext.out.end_of_search = SVAL(p_blob.data, 2); + + status = smb_raw_t2search_backend(tree, mem_ctx, + io->generic.level, + io->t2fnext.in.flags, io->t2fnext.out.count, + &d_blob, private, callback); + + return status; +} + +/* + Implements trans2findclose2 + */ +NTSTATUS smb_raw_search_close(struct cli_tree *tree, + union smb_search_close *io) +{ + struct cli_request *req; + + req = cli_request_setup(tree, SMBfindclose, 1, 0); + if (!req) { + return NT_STATUS_NO_MEMORY; + } + + SSVAL(req->out.vwv, VWV(0), io->findclose.in.handle); + + if (cli_request_send(req)) { + cli_request_receive(req); + } + + return cli_request_destroy(req); +} diff --git a/source4/libcli/raw/rawsetfileinfo.c b/source4/libcli/raw/rawsetfileinfo.c new file mode 100644 index 0000000000..4044686c64 --- /dev/null +++ b/source4/libcli/raw/rawsetfileinfo.c @@ -0,0 +1,335 @@ +/* + Unix SMB/CIFS implementation. + RAW_SFILEINFO_* calls + Copyright (C) James Myers 2003 + Copyright (C) Andrew Tridgell 2003 + + 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. +*/ + +#include "includes.h" + +/**************************************************************************** + Handle qfileinfo/qpathinfo trans2 backend. +****************************************************************************/ +static BOOL smb_raw_setinfo_backend(struct cli_tree *tree, + TALLOC_CTX *mem_ctx, + union smb_setfileinfo *parms, + DATA_BLOB *blob) +{ + uint_t len; + +#define NEED_BLOB(n) do { \ + *blob = data_blob_talloc(mem_ctx, NULL, n); \ + if (blob->data == NULL) return False; \ + } while (0) + + switch (parms->generic.level) { + case RAW_SFILEINFO_GENERIC: + case RAW_SFILEINFO_SETATTR: + case RAW_SFILEINFO_SETATTRE: + /* not handled here */ + return False; + + case RAW_SFILEINFO_STANDARD: + NEED_BLOB(12); + put_dos_date2(blob->data, 0, parms->standard.in.create_time); + put_dos_date2(blob->data, 4, parms->standard.in.access_time); + put_dos_date2(blob->data, 8, parms->standard.in.write_time); + return True; + + case RAW_SFILEINFO_EA_SET: + NEED_BLOB(ea_list_size(1, &parms->ea_set.in.ea)); + ea_put_list(blob->data, 1, &parms->ea_set.in.ea); + return True; + + case RAW_SFILEINFO_BASIC_INFO: + case RAW_SFILEINFO_BASIC_INFORMATION: + NEED_BLOB(40); + cli_push_nttime(blob->data, 0, &parms->basic_info.in.create_time); + cli_push_nttime(blob->data, 8, &parms->basic_info.in.access_time); + cli_push_nttime(blob->data, 16, &parms->basic_info.in.write_time); + cli_push_nttime(blob->data, 24, &parms->basic_info.in.change_time); + SIVAL(blob->data, 32, parms->basic_info.in.attrib); + SIVAL(blob->data, 36, 0); /* padding */ + return True; + + case RAW_SFILEINFO_UNIX_BASIC: + NEED_BLOB(92); + SBVAL(blob->data, 0, parms->unix_basic.in.end_of_file); + SBVAL(blob->data, 8, parms->unix_basic.in.num_bytes); + cli_push_nttime(blob->data, 16, &parms->unix_basic.in.status_change_time); + cli_push_nttime(blob->data, 24, &parms->unix_basic.in.access_time); + cli_push_nttime(blob->data, 32, &parms->unix_basic.in.change_time); + SBVAL(blob->data, 40, parms->unix_basic.in.uid); + SBVAL(blob->data, 48, parms->unix_basic.in.gid); + SIVAL(blob->data, 56, parms->unix_basic.in.file_type); + SBVAL(blob->data, 60, parms->unix_basic.in.dev_major); + SBVAL(blob->data, 68, parms->unix_basic.in.dev_minor); + SBVAL(blob->data, 76, parms->unix_basic.in.unique_id); + SBVAL(blob->data, 84, parms->unix_basic.in.nlink); + return True; + + case RAW_SFILEINFO_DISPOSITION_INFO: + case RAW_SFILEINFO_DISPOSITION_INFORMATION: + NEED_BLOB(4); + SIVAL(blob->data, 0, parms->disposition_info.in.delete_on_close); + return True; + + case RAW_SFILEINFO_ALLOCATION_INFO: + case RAW_SFILEINFO_ALLOCATION_INFORMATION: + NEED_BLOB(8); + SBVAL(blob->data, 0, parms->allocation_info.in.alloc_size); + return True; + + case RAW_SFILEINFO_END_OF_FILE_INFO: + case RAW_SFILEINFO_END_OF_FILE_INFORMATION: + NEED_BLOB(8); + SBVAL(blob->data, 0, parms->end_of_file_info.in.size); + return True; + + case RAW_SFILEINFO_RENAME_INFORMATION: + NEED_BLOB(12); + SIVAL(blob->data, 0, parms->rename_information.in.overwrite); + SIVAL(blob->data, 4, parms->rename_information.in.root_fid); + len = cli_blob_append_string(tree->session, mem_ctx, blob, + parms->rename_information.in.new_name, + STR_UNICODE|STR_TERMINATE); + SIVAL(blob->data, 8, len - 2); + return True; + + case RAW_SFILEINFO_POSITION_INFORMATION: + NEED_BLOB(8); + SBVAL(blob->data, 0, parms->position_information.in.position); + return True; + + case RAW_SFILEINFO_MODE_INFORMATION: + NEED_BLOB(4); + SIVAL(blob->data, 0, parms->mode_information.in.mode); + return True; + } + + return False; +} + +/**************************************************************************** + Very raw set file info - takes data blob (async send) +****************************************************************************/ +static struct cli_request *smb_raw_setfileinfo_blob_send(struct cli_tree *tree, + TALLOC_CTX *mem_ctx, + uint16 fnum, + uint16 info_level, + DATA_BLOB *blob) +{ + struct smb_trans2 tp; + uint16 setup = TRANSACT2_SETFILEINFO; + + tp.in.max_setup = 0; + tp.in.flags = 0; + tp.in.timeout = 0; + tp.in.setup_count = 1; + tp.in.max_param = 2; + tp.in.max_data = 0; + tp.in.setup = &setup; + + tp.in.params = data_blob_talloc(mem_ctx, NULL, 6); + if (!tp.in.params.data) { + return NULL; + } + SSVAL(tp.in.params.data, 0, fnum); + SSVAL(tp.in.params.data, 2, info_level); + SSVAL(tp.in.params.data, 4, 0); /* reserved */ + + tp.in.data = *blob; + + return smb_raw_trans2_send(tree, &tp); +} + +/**************************************************************************** + Very raw set path info - takes data blob +****************************************************************************/ +static struct cli_request *smb_raw_setpathinfo_blob_send(struct cli_tree *tree, + TALLOC_CTX *mem_ctx, + const char *fname, + uint16 info_level, + DATA_BLOB *blob) +{ + struct smb_trans2 tp; + uint16 setup = TRANSACT2_SETPATHINFO; + + tp.in.max_setup = 0; + tp.in.flags = 0; + tp.in.timeout = 0; + tp.in.setup_count = 1; + tp.in.max_param = 2; + tp.in.max_data = 0; + tp.in.setup = &setup; + + tp.in.params = data_blob_talloc(mem_ctx, NULL, 4); + if (!tp.in.params.data) { + return NULL; + } + SSVAL(tp.in.params.data, 0, info_level); + SSVAL(tp.in.params.data, 2, 0); + cli_blob_append_string(tree->session, mem_ctx, + &tp.in.params, + fname, STR_TERMINATE); + + tp.in.data = *blob; + + return smb_raw_trans2_send(tree, &tp); +} + +/**************************************************************************** + Handle setattr (async send) +****************************************************************************/ +static struct cli_request *smb_raw_setattr_send(struct cli_tree *tree, + union smb_setfileinfo *parms) +{ + struct cli_request *req; + + req = cli_request_setup(tree, SMBsetatr, 8, 0); + if (!req) return NULL; + + SSVAL(req->out.vwv, VWV(0), parms->setattr.in.attrib); + put_dos_date3(req->out.vwv, VWV(1), parms->setattr.in.write_time); + memset(req->out.vwv + VWV(3), 0, 10); /* reserved */ + cli_req_append_ascii4(req, parms->setattr.file.fname, STR_TERMINATE); + cli_req_append_ascii4(req, "", STR_TERMINATE); + + if (!cli_request_send(req)) { + cli_request_destroy(req); + return NULL; + } + + return req; +} + +/**************************************************************************** + Handle setattrE. (async send) +****************************************************************************/ +static struct cli_request *smb_raw_setattrE_send(struct cli_tree *tree, + union smb_setfileinfo *parms) +{ + struct cli_request *req; + + req = cli_request_setup(tree, SMBsetattrE, 7, 0); + if (!req) return NULL; + + SSVAL(req->out.vwv, VWV(0), parms->setattre.file.fnum); + put_dos_date2(req->out.vwv, VWV(1), parms->setattre.in.create_time); + put_dos_date2(req->out.vwv, VWV(3), parms->setattre.in.access_time); + put_dos_date2(req->out.vwv, VWV(5), parms->setattre.in.write_time); + + if (!cli_request_send(req)) { + cli_request_destroy(req); + return NULL; + } + + return req; +} + +/**************************************************************************** + Set file info (async send) +****************************************************************************/ +struct cli_request *smb_raw_setfileinfo_send(struct cli_tree *tree, + union smb_setfileinfo *parms) +{ + DATA_BLOB blob; + TALLOC_CTX *mem_ctx; + struct cli_request *req; + + if (parms->generic.level == RAW_SFILEINFO_SETATTRE) { + return smb_raw_setattrE_send(tree, parms); + } + if (parms->generic.level >= RAW_SFILEINFO_GENERIC) { + return NULL; + } + + mem_ctx = talloc_init("setpathinfo"); + if (!mem_ctx) return NULL; + + if (!smb_raw_setinfo_backend(tree, mem_ctx, parms, &blob)) { + talloc_destroy(mem_ctx); + return NULL; + } + + /* send request and process the output */ + req = smb_raw_setfileinfo_blob_send(tree, + mem_ctx, + parms->generic.file.fnum, + parms->generic.level, + &blob); + + talloc_destroy(mem_ctx); + return req; +} + +/**************************************************************************** + Set file info (async send) +****************************************************************************/ +NTSTATUS smb_raw_setfileinfo(struct cli_tree *tree, + union smb_setfileinfo *parms) +{ + struct cli_request *req = smb_raw_setfileinfo_send(tree, parms); + return cli_request_simple_recv(req); +} + + +/**************************************************************************** + Set path info (async send) +****************************************************************************/ +struct cli_request *smb_raw_setpathinfo_send(struct cli_tree *tree, + union smb_setfileinfo *parms) +{ + DATA_BLOB blob; + TALLOC_CTX *mem_ctx; + struct cli_request *req; + + if (parms->generic.level == RAW_SFILEINFO_SETATTR) { + return smb_raw_setattr_send(tree, parms); + } + if (parms->generic.level >= RAW_SFILEINFO_GENERIC) { + return NULL; + } + + mem_ctx = talloc_init("setpathinfo"); + if (!mem_ctx) return NULL; + + if (!smb_raw_setinfo_backend(tree, mem_ctx, parms, &blob)) { + talloc_destroy(mem_ctx); + return NULL; + } + + /* send request and process the output */ + req = smb_raw_setpathinfo_blob_send(tree, + mem_ctx, + parms->generic.file.fname, + parms->generic.level, + &blob); + + talloc_destroy(mem_ctx); + return req; +} + +/**************************************************************************** + Set path info (sync interface) +****************************************************************************/ +NTSTATUS smb_raw_setpathinfo(struct cli_tree *tree, + union smb_setfileinfo *parms) +{ + struct cli_request *req = smb_raw_setpathinfo_send(tree, parms); + return cli_request_simple_recv(req); +} diff --git a/source4/libcli/raw/rawtrans.c b/source4/libcli/raw/rawtrans.c new file mode 100644 index 0000000000..508f920268 --- /dev/null +++ b/source4/libcli/raw/rawtrans.c @@ -0,0 +1,489 @@ +/* + Unix SMB/CIFS implementation. + raw trans/trans2/nttrans operations + + Copyright (C) James Myers 2003 + + 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. +*/ + +#include "includes.h" + + +/* + check out of bounds for incoming data +*/ +static BOOL raw_trans_oob(struct cli_request *req, + uint_t offset, uint_t count) +{ + char *ptr; + + if (count == 0) { + return False; + } + + ptr = req->in.hdr + offset; + + /* be careful with wraparound! */ + if (ptr < req->in.data || + ptr >= req->in.data + req->in.data_size || + count > req->in.data_size || + ptr + count > req->in.data + req->in.data_size) { + return True; + } + return False; +} + +/**************************************************************************** + receive a SMB trans or trans2 response allocating the necessary memory + ****************************************************************************/ +NTSTATUS smb_raw_trans2_recv(struct cli_request *req, + TALLOC_CTX *mem_ctx, + struct smb_trans2 *parms) +{ + int total_data=0; + int total_param=0; + char *tdata; + char *tparam; + + parms->out.data.length = 0; + parms->out.data.data = NULL; + parms->out.params.length = 0; + parms->out.params.data = NULL; + + if (!cli_request_receive(req)) { + req->status = NT_STATUS_UNSUCCESSFUL; + return cli_request_destroy(req); + } + + /* + * An NT RPC pipe call can return ERRDOS, ERRmoredata + * to a trans call. This is not an error and should not + * be treated as such. + */ + if (NT_STATUS_IS_ERR(req->status)) { + return cli_request_destroy(req); + } + + CLI_CHECK_MIN_WCT(req, 10); + + /* parse out the lengths */ + total_data = SVAL(req->in.vwv, VWV(1)); + total_param = SVAL(req->in.vwv, VWV(0)); + + /* allocate it */ + if (total_data != 0) { + tdata = talloc_realloc(mem_ctx, parms->out.data.data,total_data); + if (!tdata) { + DEBUG(0,("smb_raw_receive_trans: failed to enlarge data buffer to %d bytes\n", total_data)); + req->status = NT_STATUS_NO_MEMORY; + return cli_request_destroy(req); + } + parms->out.data.data = tdata; + } + + if (total_param != 0) { + tparam = talloc_realloc(mem_ctx, parms->out.params.data,total_param); + if (!tparam) { + DEBUG(0,("smb_raw_receive_trans: failed to enlarge param buffer to %d bytes\n", total_param)); + req->status = NT_STATUS_NO_MEMORY; + return cli_request_destroy(req); + } + parms->out.params.data = tparam; + } + + parms->out.setup_count = SVAL(req->in.vwv, VWV(9)); + CLI_CHECK_WCT(req, 10 + parms->out.setup_count); + + if (parms->out.setup_count > 0) { + int i; + parms->out.setup = talloc(mem_ctx, 2 * parms->out.setup_count); + if (!parms->out.setup) { + req->status = NT_STATUS_NO_MEMORY; + return cli_request_destroy(req); + } + for (i=0;iout.setup_count;i++) { + parms->out.setup[i] = SVAL(req->in.vwv, VWV(10+i)); + } + } + + while (1) { + uint16 param_count, param_ofs, param_disp; + uint16 data_count, data_ofs, data_disp; + uint16 total_data2, total_param2; + + /* parse out the total lengths again - they can shrink! */ + total_data2 = SVAL(req->in.vwv, VWV(1)); + total_param2 = SVAL(req->in.vwv, VWV(0)); + + if (total_data2 > total_data || + total_param2 > total_param) { + /* they must *only* shrink */ + DEBUG(1,("smb_raw_receive_trans: data/params expanded!\n")); + req->status = NT_STATUS_BUFFER_TOO_SMALL; + return cli_request_destroy(req); + } + + total_data = total_data2; + total_param = total_param2; + + /* parse params for this lump */ + param_count = SVAL(req->in.vwv, VWV(3)); + param_ofs = SVAL(req->in.vwv, VWV(4)); + param_disp = SVAL(req->in.vwv, VWV(5)); + + data_count = SVAL(req->in.vwv, VWV(6)); + data_ofs = SVAL(req->in.vwv, VWV(7)); + data_disp = SVAL(req->in.vwv, VWV(8)); + + if (data_count + data_disp > total_data || + param_count + param_disp > total_param) { + DEBUG(1,("smb_raw_receive_trans: Buffer overflow\n")); + req->status = NT_STATUS_BUFFER_TOO_SMALL; + return cli_request_destroy(req); + } + + /* check the server isn't being nasty */ + if (raw_trans_oob(req, param_ofs, param_count) || + raw_trans_oob(req, data_ofs, data_count)) { + DEBUG(1,("smb_raw_receive_trans: out of bounds parameters!\n")); + req->status = NT_STATUS_BUFFER_TOO_SMALL; + return cli_request_destroy(req); + } + + if (data_count) { + memcpy(parms->out.data.data + data_disp, + req->in.hdr + data_ofs, + data_count); + } + + if (param_count) { + memcpy(parms->out.params.data + param_disp, + req->in.hdr + param_ofs, + param_count); + } + + parms->out.data.length += data_count; + parms->out.params.length += param_count; + + if (total_data <= parms->out.data.length && total_param <= parms->out.params.length) + break; + + /* to receive more requests we need to mark this request as not received */ + req->in.buffer = NULL; + + if (!cli_request_receive(req)) { + req->status = NT_STATUS_UNSUCCESSFUL; + return cli_request_destroy(req); + } + } + +failed: + return cli_request_destroy(req); +} + + +/**************************************************************************** + trans2 raw async interface - only BLOBs used in this interface. +note that this doesn't yet support multi-part requests +****************************************************************************/ +struct cli_request *smb_raw_trans2_send(struct cli_tree *tree, + struct smb_trans2 *parms) +{ + uint8 command = SMBtrans2; + int wct = 14 + parms->in.setup_count; + struct cli_request *req; + char *outdata,*outparam; + int data_sent, param_sent; + int i; + const int padding = 3; + + req = cli_request_setup(tree, command, wct, padding); + if (!req) { + return NULL; + } + + /* fill in SMB parameters */ + data_sent = parms->in.data.length; + param_sent = parms->in.params.length; + outparam = req->out.data + padding; + outdata = outparam + param_sent; + + /* make sure we don't leak data via the padding */ + memset(req->out.data, 0, padding); + + /* primary request */ + SSVAL(req->out.vwv,VWV(0),parms->in.params.length); + SSVAL(req->out.vwv,VWV(1),parms->in.data.length); + SSVAL(req->out.vwv,VWV(2),parms->in.max_param); + SSVAL(req->out.vwv,VWV(3),parms->in.max_data); + SSVAL(req->out.vwv,VWV(4),parms->in.max_setup); + SSVAL(req->out.vwv,VWV(5),parms->in.flags); + SIVAL(req->out.vwv,VWV(6),parms->in.timeout); + SSVAL(req->out.vwv,VWV(8),0); /* reserved */ + SSVAL(req->out.vwv,VWV(9),parms->in.params.length); + SSVAL(req->out.vwv,VWV(10),PTR_DIFF(outparam,req->out.hdr)); + SSVAL(req->out.vwv,VWV(11),parms->in.data.length); + SSVAL(req->out.vwv,VWV(12),PTR_DIFF(outdata,req->out.hdr)); + SSVAL(req->out.vwv,VWV(13),parms->in.setup_count); + for (i=0;iin.setup_count;i++) { + SSVAL(req->out.vwv,VWV(14)+i*2,parms->in.setup[i]); + } + if (parms->in.params.data) { + cli_req_append_blob(req, &parms->in.params); + } + if (parms->in.data.data) { + cli_req_append_blob(req, &parms->in.data); + } + + if (!cli_request_send(req)) { + cli_request_destroy(req); + return NULL; + } + + return req; +} + +/* + trans2 synchronous blob interface +*/ +NTSTATUS smb_raw_trans2(struct cli_tree *tree, + TALLOC_CTX *mem_ctx, + struct smb_trans2 *parms) +{ + struct cli_request *req; + req = smb_raw_trans2_send(tree, parms); + if (!req) return NT_STATUS_UNSUCCESSFUL; + return smb_raw_trans2_recv(req, mem_ctx, parms); +} + + +/**************************************************************************** + receive a SMB nttrans response allocating the necessary memory + ****************************************************************************/ +NTSTATUS smb_raw_nttrans_recv(struct cli_request *req, + TALLOC_CTX *mem_ctx, + struct smb_nttrans *parms) +{ + uint32 total_data, recvd_data=0; + uint32 total_param, recvd_param=0; + + if (!cli_request_receive(req) || + cli_request_is_error(req)) { + return cli_request_destroy(req); + } + + /* sanity check */ + if (CVAL(req->in.hdr, HDR_COM) != SMBnttrans) { + DEBUG(0,("smb_raw_receive_nttrans: Expected %s response, got command 0x%02x\n", + "SMBnttrans", + CVAL(req->in.hdr,HDR_COM))); + req->status = NT_STATUS_UNSUCCESSFUL; + return cli_request_destroy(req); + } + + CLI_CHECK_MIN_WCT(req, 18); + + /* parse out the lengths */ + total_param = IVAL(req->in.vwv, 3); + total_data = IVAL(req->in.vwv, 7); + + parms->out.data = data_blob_talloc(mem_ctx, NULL, total_data); + parms->out.params = data_blob_talloc(mem_ctx, NULL, total_param); + + if (parms->out.data.length != total_data || + parms->out.params.length != total_param) { + req->status = NT_STATUS_NO_MEMORY; + return cli_request_destroy(req); + } + + parms->out.setup_count = CVAL(req->in.vwv, 35); + CLI_CHECK_WCT(req, 18 + parms->out.setup_count); + + if (parms->out.setup_count > 0) { + int i; + parms->out.setup = talloc(mem_ctx, 2 * parms->out.setup_count); + if (!parms->out.setup) { + req->status = NT_STATUS_NO_MEMORY; + return cli_request_destroy(req); + } + for (i=0;iout.setup_count;i++) { + parms->out.setup[i] = SVAL(req->in.vwv, VWV(18+i)); + } + } + + while (recvd_data < total_data || + recvd_param < total_param) { + uint32 param_count, param_ofs, param_disp; + uint32 data_count, data_ofs, data_disp; + uint32 total_data2, total_param2; + + /* parse out the total lengths again - they can shrink! */ + total_param2 = IVAL(req->in.vwv, 3); + total_data2 = IVAL(req->in.vwv, 7); + + if (total_data2 > total_data || + total_param2 > total_param) { + /* they must *only* shrink */ + DEBUG(1,("smb_raw_receive_nttrans: data/params expanded!\n")); + req->status = NT_STATUS_BUFFER_TOO_SMALL; + return cli_request_destroy(req); + } + + total_data = total_data2; + total_param = total_param2; + parms->out.data.length = total_data; + parms->out.params.length = total_param; + + /* parse params for this lump */ + param_count = IVAL(req->in.vwv, 11); + param_ofs = IVAL(req->in.vwv, 15); + param_disp = IVAL(req->in.vwv, 19); + + data_count = IVAL(req->in.vwv, 23); + data_ofs = IVAL(req->in.vwv, 27); + data_disp = IVAL(req->in.vwv, 31); + + if (data_count + data_disp > total_data || + param_count + param_disp > total_param) { + DEBUG(1,("smb_raw_receive_nttrans: Buffer overflow\n")); + req->status = NT_STATUS_BUFFER_TOO_SMALL; + return cli_request_destroy(req); + } + + /* check the server isn't being nasty */ + if (raw_trans_oob(req, param_ofs, param_count) || + raw_trans_oob(req, data_ofs, data_count)) { + DEBUG(1,("smb_raw_receive_nttrans: out of bounds parameters!\n")); + req->status = NT_STATUS_BUFFER_TOO_SMALL; + return cli_request_destroy(req); + } + + if (data_count) { + memcpy(parms->out.data.data + data_disp, + req->in.hdr + data_ofs, + data_count); + } + + if (param_count) { + memcpy(parms->out.params.data + param_disp, + req->in.hdr + param_ofs, + param_count); + } + + recvd_param += param_count; + recvd_data += data_count; + + if (recvd_data >= total_data && + recvd_param >= total_param) { + break; + } + + if (!cli_request_receive(req) || + cli_request_is_error(req)) { + return cli_request_destroy(req); + } + + /* sanity check */ + if (CVAL(req->in.hdr, HDR_COM) != SMBnttrans) { + DEBUG(0,("smb_raw_receive_nttrans: Expected nttranss, got command 0x%02x\n", + CVAL(req->in.hdr, HDR_COM))); + req->status = NT_STATUS_UNSUCCESSFUL; + return cli_request_destroy(req); + } + } + +failed: + return cli_request_destroy(req); +} + + +/**************************************************************************** + nttrans raw - only BLOBs used in this interface. + at the moment we only handle a single primary request +****************************************************************************/ +struct cli_request *smb_raw_nttrans_send(struct cli_tree *tree, + struct smb_nttrans *parms) +{ + struct cli_request *req; + char *outdata, *outparam; + int i; + int align = 0; + + /* only align if there are parameters or data */ + if (parms->in.params.length || parms->in.data.length) { + align = 3; + } + + req = cli_request_setup(tree, SMBnttrans, + 19 + parms->in.setup_count, + align + + parms->in.params.length + + parms->in.data.length); + if (!req) { + return NULL; + } + + /* fill in SMB parameters */ + outparam = req->out.data + align; + outdata = outparam + parms->in.params.length; + + SCVAL(req->out.vwv, 0, parms->in.max_setup); + SSVAL(req->out.vwv, 1, 0); /* reserved */ + SIVAL(req->out.vwv, 3, parms->in.params.length); + SIVAL(req->out.vwv, 7, parms->in.data.length); + SIVAL(req->out.vwv, 11, parms->in.max_param); + SIVAL(req->out.vwv, 15, parms->in.max_data); + SIVAL(req->out.vwv, 19, parms->in.params.length); + SIVAL(req->out.vwv, 23, PTR_DIFF(outparam,req->out.hdr)); + SIVAL(req->out.vwv, 27, parms->in.data.length); + SIVAL(req->out.vwv, 31, PTR_DIFF(outdata,req->out.hdr)); + SCVAL(req->out.vwv, 35, parms->in.setup_count); + SSVAL(req->out.vwv, 36, parms->in.function); + for (i=0;iin.setup_count;i++) { + SSVAL(req->out.vwv,VWV(19+i),parms->in.setup[i]); + } + if (parms->in.params.length) { + memcpy(outparam, parms->in.params.data, parms->in.params.length); + } + if (parms->in.data.length) { + memcpy(outparam, parms->in.data.data, parms->in.data.length); + } + + if (!cli_request_send(req)) { + cli_request_destroy(req); + return NULL; + } + + return req; +} + + +/**************************************************************************** + receive a SMB nttrans response allocating the necessary memory + ****************************************************************************/ +NTSTATUS smb_raw_nttrans(struct cli_tree *tree, + TALLOC_CTX *mem_ctx, + struct smb_nttrans *parms) +{ + struct cli_request *req; + + req = smb_raw_nttrans_send(tree, parms); + if (!req) { + return NT_STATUS_UNSUCCESSFUL; + } + + return smb_raw_nttrans_recv(req, mem_ctx, parms); +} diff --git a/source4/libcli/raw/smb_signing.c b/source4/libcli/raw/smb_signing.c new file mode 100644 index 0000000000..2ab61aa001 --- /dev/null +++ b/source4/libcli/raw/smb_signing.c @@ -0,0 +1,341 @@ +/* + Unix SMB/CIFS implementation. + SMB Signing Code + Copyright (C) Jeremy Allison 2002. + Copyright (C) Andrew Bartlett 2002-2003 + Copyright (C) James J Myers 2003 + + 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. +*/ + +#include "includes.h" + +struct smb_basic_signing_context { + DATA_BLOB mac_key; + uint32 next_seq_num; +}; + +/*********************************************************** + SMB signing - Common code before we set a new signing implementation +************************************************************/ +static BOOL set_smb_signing_common(struct cli_transport *transport) +{ + if (!(transport->negotiate.sec_mode & + (NEGOTIATE_SECURITY_SIGNATURES_REQUIRED|NEGOTIATE_SECURITY_SIGNATURES_ENABLED))) { + return False; + } + + if (transport->negotiate.sign_info.doing_signing) { + return False; + } + + if (transport->negotiate.sign_info.free_signing_context) + transport->negotiate.sign_info.free_signing_context(transport); + + /* These calls are INCOMPATIBLE with SMB signing */ + transport->negotiate.readbraw_supported = False; + transport->negotiate.writebraw_supported = False; + + return True; +} + +/*********************************************************** + SMB signing - Common code for 'real' implementations +************************************************************/ +static BOOL set_smb_signing_real_common(struct cli_transport *transport) +{ + if (transport->negotiate.sec_mode & NEGOTIATE_SECURITY_SIGNATURES_REQUIRED) { + DEBUG(5, ("Mandatory SMB signing enabled!\n")); + transport->negotiate.sign_info.doing_signing = True; + } + + DEBUG(5, ("SMB signing enabled!\n")); + + return True; +} + +static void mark_packet_signed(struct cli_request *req) +{ + uint16 flags2; + flags2 = SVAL(req->out.hdr, HDR_FLG2); + flags2 |= FLAGS2_SMB_SECURITY_SIGNATURES; + SSVAL(req->out.hdr, HDR_FLG2, flags2); +} + +static BOOL signing_good(struct cli_request *req, BOOL good) +{ + if (good && !req->transport->negotiate.sign_info.doing_signing) { + req->transport->negotiate.sign_info.doing_signing = True; + } + + if (!good) { + if (req->transport->negotiate.sign_info.doing_signing) { + DEBUG(1, ("SMB signature check failed!\n")); + return False; + } else { + DEBUG(3, ("Server did not sign reply correctly\n")); + cli_transport_free_signing_context(req->transport); + return False; + } + } + return True; +} + +/*********************************************************** + SMB signing - Simple implementation - calculate a MAC to send. +************************************************************/ +static void cli_request_simple_sign_outgoing_message(struct cli_request *req) +{ + unsigned char calc_md5_mac[16]; + struct MD5Context md5_ctx; + struct smb_basic_signing_context *data = req->transport->negotiate.sign_info.signing_context; + +#if 0 + /* enable this when packet signing is preventing you working out why valgrind + says that data is uninitialised */ + file_save("pkt.dat", req->out.buffer, req->out.size); +#endif + + req->seq_num = data->next_seq_num; + + /* some requests (eg. NTcancel) are one way, and the sequence number + should be increased by 1 not 2 */ + if (req->one_way_request) { + data->next_seq_num += 1; + } else { + data->next_seq_num += 2; + } + + /* + * Firstly put the sequence number into the first 4 bytes. + * and zero out the next 4 bytes. + */ + SIVAL(req->out.hdr, HDR_SS_FIELD, req->seq_num); + SIVAL(req->out.hdr, HDR_SS_FIELD + 4, 0); + + /* mark the packet as signed - BEFORE we sign it...*/ + mark_packet_signed(req); + + /* Calculate the 16 byte MAC and place first 8 bytes into the field. */ + MD5Init(&md5_ctx); + MD5Update(&md5_ctx, data->mac_key.data, + data->mac_key.length); + MD5Update(&md5_ctx, + req->out.buffer + NBT_HDR_SIZE, + req->out.size - NBT_HDR_SIZE); + MD5Final(calc_md5_mac, &md5_ctx); + + memcpy(&req->out.hdr[HDR_SS_FIELD], calc_md5_mac, 8); + +/* req->out.hdr[HDR_SS_FIELD+2]=0; + Uncomment this to test if the remote server actually verifies signitures...*/ +} + + +/*********************************************************** + SMB signing - Simple implementation - check a MAC sent by server. +************************************************************/ +static BOOL cli_request_simple_check_incoming_message(struct cli_request *req) +{ + BOOL good; + unsigned char calc_md5_mac[16]; + unsigned char server_sent_mac[8]; + unsigned char sequence_buf[8]; + struct MD5Context md5_ctx; + struct smb_basic_signing_context *data = req->transport->negotiate.sign_info.signing_context; + const size_t offset_end_of_sig = (HDR_SS_FIELD + 8); + int i; + const int sign_range = 0; + + /* its quite bogus to be guessing sequence numbers, but very useful + when debugging signing implementations */ + for (i = 1-sign_range; i <= 1+sign_range; i++) { + /* + * Firstly put the sequence number into the first 4 bytes. + * and zero out the next 4 bytes. + */ + SIVAL(sequence_buf, 0, req->seq_num+i); + SIVAL(sequence_buf, 4, 0); + + /* get a copy of the server-sent mac */ + memcpy(server_sent_mac, &req->in.hdr[HDR_SS_FIELD], sizeof(server_sent_mac)); + + /* Calculate the 16 byte MAC and place first 8 bytes into the field. */ + MD5Init(&md5_ctx); + MD5Update(&md5_ctx, data->mac_key.data, + data->mac_key.length); + MD5Update(&md5_ctx, req->in.hdr, HDR_SS_FIELD); + MD5Update(&md5_ctx, sequence_buf, sizeof(sequence_buf)); + + MD5Update(&md5_ctx, req->in.hdr + offset_end_of_sig, + req->in.size - NBT_HDR_SIZE - (offset_end_of_sig)); + MD5Final(calc_md5_mac, &md5_ctx); + + good = (memcmp(server_sent_mac, calc_md5_mac, 8) == 0); + if (good) break; + } + + if (good && i != 1) { + DEBUG(0,("SIGNING OFFSET %d\n", i)); + } + + if (!good) { + DEBUG(5, ("cli_request_simple_check_incoming_message: BAD SIG: wanted SMB signature of\n")); + dump_data(5, calc_md5_mac, 8); + + DEBUG(5, ("cli_request_simple_check_incoming_message: BAD SIG: got SMB signature of\n")); + dump_data(5, server_sent_mac, 8); + } + return signing_good(req, good); +} + + +/*********************************************************** + SMB signing - Simple implementation - free signing context +************************************************************/ +static void cli_transport_simple_free_signing_context(struct cli_transport *transport) +{ + struct smb_basic_signing_context *data = transport->negotiate.sign_info.signing_context; + + data_blob_free(&data->mac_key); + SAFE_FREE(transport->negotiate.sign_info.signing_context); + + return; +} + + +/*********************************************************** + SMB signing - Simple implementation - setup the MAC key. +************************************************************/ +BOOL cli_transport_simple_set_signing(struct cli_transport *transport, + const uchar user_transport_key[16], const DATA_BLOB response) +{ + struct smb_basic_signing_context *data; + + if (!set_smb_signing_common(transport)) { + return False; + } + + if (!set_smb_signing_real_common(transport)) { + return False; + } + + data = smb_xmalloc(sizeof(*data)); + transport->negotiate.sign_info.signing_context = data; + + data->mac_key = data_blob(NULL, MIN(response.length + 16, 40)); + + memcpy(&data->mac_key.data[0], user_transport_key, 16); + memcpy(&data->mac_key.data[16],response.data, MIN(response.length, 40 - 16)); + + /* Initialise the sequence number */ + data->next_seq_num = 0; + + transport->negotiate.sign_info.sign_outgoing_message = cli_request_simple_sign_outgoing_message; + transport->negotiate.sign_info.check_incoming_message = cli_request_simple_check_incoming_message; + transport->negotiate.sign_info.free_signing_context = cli_transport_simple_free_signing_context; + + return True; +} + + +/*********************************************************** + SMB signing - NULL implementation - calculate a MAC to send. +************************************************************/ +static void cli_request_null_sign_outgoing_message(struct cli_request *req) +{ + /* we can't zero out the sig, as we might be trying to send a + transport request - which is NBT-level, not SMB level and doesn't + have the field */ +} + + +/*********************************************************** + SMB signing - NULL implementation - check a MAC sent by server. +************************************************************/ +static BOOL cli_request_null_check_incoming_message(struct cli_request *req) +{ + return True; +} + + +/*********************************************************** + SMB signing - NULL implementation - free signing context +************************************************************/ +static void cli_null_free_signing_context(struct cli_transport *transport) +{ +} + +/** + SMB signing - NULL implementation - setup the MAC key. + + @note Used as an initialisation only - it will not correctly + shut down a real signing mechanism +*/ +BOOL cli_null_set_signing(struct cli_transport *transport) +{ + transport->negotiate.sign_info.signing_context = NULL; + + transport->negotiate.sign_info.sign_outgoing_message = cli_request_null_sign_outgoing_message; + transport->negotiate.sign_info.check_incoming_message = cli_request_null_check_incoming_message; + transport->negotiate.sign_info.free_signing_context = cli_null_free_signing_context; + + return True; +} + + +/** + * Free the signing context + */ +void cli_transport_free_signing_context(struct cli_transport *transport) +{ + if (transport->negotiate.sign_info.free_signing_context) { + transport->negotiate.sign_info.free_signing_context(transport); + } + + cli_null_set_signing(transport); +} + + +/** + * Sign a packet with the current mechanism + */ +void cli_request_calculate_sign_mac(struct cli_request *req) +{ + req->transport->negotiate.sign_info.sign_outgoing_message(req); +} + + +/** + * Check a packet with the current mechanism + * @return False if we had an established signing connection + * which had a back checksum, True otherwise + */ +BOOL cli_request_check_sign_mac(struct cli_request *req) +{ + BOOL good; + + if (req->in.size < (HDR_SS_FIELD + 8)) { + good = False; + } else { + good = req->transport->negotiate.sign_info.check_incoming_message(req); + } + + if (!good && req->transport->negotiate.sign_info.doing_signing) { + return False; + } + + return True; +} -- cgit From e063ea70ad05d9a8cc927ddbcf61aa3b4ea04ade Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 13 Aug 2003 02:01:01 +0000 Subject: use the \\server\share form of tconx to work with servers that don't cope with the simpler form (This used to be commit 295cc63fb8d99d403c863a7b30cb30382070a6f9) --- source4/libcli/raw/clitree.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index 2a41273913..60e8610bd8 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -269,10 +269,13 @@ NTSTATUS cli_tree_full_connection(struct cli_tree **ret_tree, tcon.generic.level = RAW_TCON_TCONX; tcon.tconx.in.flags = 0; tcon.tconx.in.password = data_blob(NULL, 0); - tcon.tconx.in.path = service; + asprintf(&tcon.tconx.in.path, "\\\\%s\\%s", dest_host, service); tcon.tconx.in.device = service_type; status = smb_tree_connect(tree, mem_ctx, &tcon); + + free(tcon.tconx.in.path); + if (!NT_STATUS_IS_OK(status)) { cli_tree_close(tree); talloc_destroy(mem_ctx); -- cgit From b05a2aad5434b188b624db97fb53dc67534a24c6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 13 Aug 2003 02:02:17 +0000 Subject: add support for 32 bit pid using the PIDHIGH field. This allows the test suite to see if it is supported. w2k3 doesn't seem to support it. (This used to be commit c946be06a49e9a187045f2372ef7c1b987eaf6e5) --- source4/libcli/raw/rawrequest.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 9c2b2c7367..52349d415c 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -176,7 +176,8 @@ struct cli_request *cli_request_setup_session(struct cli_session *session, } SSVAL(req->out.hdr, HDR_FLG2, flags2); - SSVAL(req->out.hdr, HDR_PID, session->pid); + SSVAL(req->out.hdr, HDR_PID, session->pid & 0xFFFF); + SSVAL(req->out.hdr, HDR_PIDHIGH, session->pid >> 16); SSVAL(req->out.hdr, HDR_UID, session->vuid); return req; -- cgit From 75c0125fb71b0562e7bdd85c391764796b5f12f6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 13 Aug 2003 16:04:21 +0000 Subject: - added SMBntrename test suite - allow username of form DOMAIN\username or DOMAIN/username - added ntrename to gentest (This used to be commit 2b464472c17b791eb5b117f89d5aaea2bf60f6ad) --- source4/libcli/raw/rawfile.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c index 279dfcf0c1..57b6ded66f 100644 --- a/source4/libcli/raw/rawfile.c +++ b/source4/libcli/raw/rawfile.c @@ -32,16 +32,27 @@ Rename a file - async interface ****************************************************************************/ struct cli_request *smb_raw_rename_send(struct cli_tree *tree, - struct smb_rename *parms) + union smb_rename *parms) { struct cli_request *req; - SETUP_REQUEST(SMBmv, 1, 0); - - SSVAL(req->out.vwv, VWV(0), parms->in.attrib); - - cli_req_append_ascii4(req, parms->in.pattern1, STR_TERMINATE); - cli_req_append_ascii4(req, parms->in.pattern2, STR_TERMINATE); + switch (parms->generic.level) { + case RAW_RENAME_RENAME: + SETUP_REQUEST(SMBmv, 1, 0); + SSVAL(req->out.vwv, VWV(0), parms->rename.in.attrib); + cli_req_append_ascii4(req, parms->rename.in.pattern1, STR_TERMINATE); + cli_req_append_ascii4(req, parms->rename.in.pattern2, STR_TERMINATE); + break; + + case RAW_RENAME_NTRENAME: + SETUP_REQUEST(SMBntrename, 4, 0); + SSVAL(req->out.vwv, VWV(0), parms->ntrename.in.attrib); + SSVAL(req->out.vwv, VWV(1), parms->ntrename.in.flags); + SIVAL(req->out.vwv, VWV(2), parms->ntrename.in.root_fid); + cli_req_append_ascii4(req, parms->ntrename.in.old_name, STR_TERMINATE); + cli_req_append_ascii4(req, parms->ntrename.in.new_name, STR_TERMINATE); + break; + } if (!cli_request_send(req)) { cli_request_destroy(req); @@ -55,7 +66,7 @@ struct cli_request *smb_raw_rename_send(struct cli_tree *tree, Rename a file - sync interface ****************************************************************************/ NTSTATUS smb_raw_rename(struct cli_tree *tree, - struct smb_rename *parms) + union smb_rename *parms) { struct cli_request *req = smb_raw_rename_send(tree, parms); return cli_request_simple_recv(req); -- cgit From 4b3d329ca21e731729af0a305386bee5d748ae92 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 13 Aug 2003 22:23:18 +0000 Subject: - added a raw smb scanner - its not a root_fid in ntrename (This used to be commit 74be55efdc77d4ba7e70d0554cbd72472522abff) --- source4/libcli/raw/rawfile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c index 57b6ded66f..97ec7c1f00 100644 --- a/source4/libcli/raw/rawfile.c +++ b/source4/libcli/raw/rawfile.c @@ -48,7 +48,7 @@ struct cli_request *smb_raw_rename_send(struct cli_tree *tree, SETUP_REQUEST(SMBntrename, 4, 0); SSVAL(req->out.vwv, VWV(0), parms->ntrename.in.attrib); SSVAL(req->out.vwv, VWV(1), parms->ntrename.in.flags); - SIVAL(req->out.vwv, VWV(2), parms->ntrename.in.root_fid); + SIVAL(req->out.vwv, VWV(2), parms->ntrename.in.unknown); cli_req_append_ascii4(req, parms->ntrename.in.old_name, STR_TERMINATE); cli_req_append_ascii4(req, parms->ntrename.in.new_name, STR_TERMINATE); break; -- cgit From 89f55d36f31ae51e365fc0e4020be0728091bd53 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 14 Aug 2003 01:31:31 +0000 Subject: added the ancient SMBcreate operation to the testsuite and client lib (This used to be commit 3eef35e581b5e1802711b9b5297f61800a7e242e) --- source4/libcli/raw/rawfile.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c index 97ec7c1f00..e9d3a8305d 100644 --- a/source4/libcli/raw/rawfile.c +++ b/source4/libcli/raw/rawfile.c @@ -330,6 +330,13 @@ struct cli_request *smb_raw_open_send(struct cli_tree *tree, union smb_open *par put_dos_date3(req->out.vwv, VWV(1), parms->mknew.in.write_time); cli_req_append_ascii4(req, parms->mknew.in.fname, STR_TERMINATE); break; + + case RAW_OPEN_CREATE: + SETUP_REQUEST(SMBcreate, 3, 0); + SSVAL(req->out.vwv, VWV(0), parms->create.in.attrib); + put_dos_date3(req->out.vwv, VWV(1), parms->create.in.write_time); + cli_req_append_ascii4(req, parms->create.in.fname, STR_TERMINATE); + break; case RAW_OPEN_CTEMP: SETUP_REQUEST(SMBctemp, 3, 0); @@ -421,6 +428,11 @@ NTSTATUS smb_raw_open_recv(struct cli_request *req, TALLOC_CTX *mem_ctx, union s parms->mknew.out.fnum = SVAL(req->in.vwv, VWV(0)); break; + case RAW_OPEN_CREATE: + CLI_CHECK_WCT(req, 1); + parms->create.out.fnum = SVAL(req->in.vwv, VWV(0)); + break; + case RAW_OPEN_CTEMP: CLI_CHECK_WCT(req, 1); parms->ctemp.out.fnum = SVAL(req->in.vwv, VWV(0)); -- cgit From 9e96467d36e9c4bf51ba74390cde0b84f08eeac7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 15 Aug 2003 15:13:24 +0000 Subject: nicer formatting in getattre (This used to be commit 52657c369b26710ed4d3a8cce81dd518547c583e) --- source4/libcli/raw/rawfileinfo.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawfileinfo.c b/source4/libcli/raw/rawfileinfo.c index f685cef9c3..70121025d0 100644 --- a/source4/libcli/raw/rawfileinfo.c +++ b/source4/libcli/raw/rawfileinfo.c @@ -419,12 +419,12 @@ static NTSTATUS smb_raw_getattrE_recv(struct cli_request *req, } CLI_CHECK_WCT(req, 11); - parms->getattre.out.create_time = make_unix_date2(req->in.vwv + VWV(0)); - parms->getattre.out.access_time = make_unix_date2(req->in.vwv + VWV(2)); - parms->getattre.out.write_time = make_unix_date2(req->in.vwv + VWV(4)); - parms->getattre.out.size = IVAL(req->in.vwv, VWV(6)); - parms->getattre.out.alloc_size = IVAL(req->in.vwv, VWV(8)); - parms->getattre.out.attrib = SVAL(req->in.vwv, VWV(10)); + parms->getattre.out.create_time = make_unix_date2(req->in.vwv + VWV(0)); + parms->getattre.out.access_time = make_unix_date2(req->in.vwv + VWV(2)); + parms->getattre.out.write_time = make_unix_date2(req->in.vwv + VWV(4)); + parms->getattre.out.size = IVAL(req->in.vwv, VWV(6)); + parms->getattre.out.alloc_size = IVAL(req->in.vwv, VWV(8)); + parms->getattre.out.attrib = SVAL(req->in.vwv, VWV(10)); failed: return cli_request_destroy(req); -- cgit From 0efd81efec653f97e6d24e9b19cc6bd6f72185fe Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 15 Aug 2003 15:13:43 +0000 Subject: fixed a comment typo (This used to be commit 4cc8fef8ca278b19eb4601e7660fc1976594412e) --- source4/libcli/raw/rawsetfileinfo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawsetfileinfo.c b/source4/libcli/raw/rawsetfileinfo.c index 4044686c64..b82c20176b 100644 --- a/source4/libcli/raw/rawsetfileinfo.c +++ b/source4/libcli/raw/rawsetfileinfo.c @@ -22,7 +22,7 @@ #include "includes.h" /**************************************************************************** - Handle qfileinfo/qpathinfo trans2 backend. + Handle setfileinfo/setpathinfo trans2 backend. ****************************************************************************/ static BOOL smb_raw_setinfo_backend(struct cli_tree *tree, TALLOC_CTX *mem_ctx, @@ -232,7 +232,7 @@ static struct cli_request *smb_raw_setattrE_send(struct cli_tree *tree, put_dos_date2(req->out.vwv, VWV(1), parms->setattre.in.create_time); put_dos_date2(req->out.vwv, VWV(3), parms->setattre.in.access_time); put_dos_date2(req->out.vwv, VWV(5), parms->setattre.in.write_time); - + if (!cli_request_send(req)) { cli_request_destroy(req); return NULL; -- cgit From d3bc355533af429be645bb1c965350fa532d03d4 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 15 Aug 2003 15:14:14 +0000 Subject: some servers don't return a fs_type and dev_type (This used to be commit eaec1bdaadd744c63fb270b3807bc284dfadb37d) --- source4/libcli/raw/clitree.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index 60e8610bd8..a088ae7023 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -283,8 +283,12 @@ NTSTATUS cli_tree_full_connection(struct cli_tree **ret_tree, } tree->tid = tcon.tconx.out.cnum; - tree->device = talloc_strdup(tree->mem_ctx, tcon.tconx.out.dev_type); - tree->fs_type = talloc_strdup(tree->mem_ctx, tcon.tconx.out.fs_type); + if (tcon.tconx.out.dev_type) { + tree->device = talloc_strdup(tree->mem_ctx, tcon.tconx.out.dev_type); + } + if (tcon.tconx.out.fs_type) { + tree->fs_type = talloc_strdup(tree->mem_ctx, tcon.tconx.out.fs_type); + } talloc_destroy(mem_ctx); -- cgit From cc38992e3f6c6ca04ae7170cb03028d3d1c06ae3 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 15 Aug 2003 16:19:48 +0000 Subject: fixed some places where we don't brace (flags & STR_UNICODE) this fixes the samba4 server with ascii clients (This used to be commit c770603ac6c3331a4ac79a650cbbbeb21c778137) --- source4/libcli/raw/rawrequest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 52349d415c..fa3b3ab627 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -754,7 +754,7 @@ size_t cli_req_pull_string(struct cli_request *req, TALLOC_CTX *mem_ctx, char **dest, const char *src, int byte_len, unsigned flags) { if (!(flags & STR_ASCII) && - ((flags & STR_UNICODE || (req->flags2 & FLAGS2_UNICODE_STRINGS)))) { + (((flags & STR_UNICODE) || (req->flags2 & FLAGS2_UNICODE_STRINGS)))) { return cli_req_pull_ucs2(req, mem_ctx, dest, src, byte_len, flags); } -- cgit From efacfb37fc0d7310c72c40bfed4b52ecaf365b11 Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Fri, 15 Aug 2003 17:50:16 +0000 Subject: wrong typecast (This used to be commit de7674ebefe3a8b0f953afe983ce058e11f827c2) --- source4/libcli/raw/clikrb5.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clikrb5.c b/source4/libcli/raw/clikrb5.c index 5edc56daa9..24da1455de 100644 --- a/source4/libcli/raw/clikrb5.c +++ b/source4/libcli/raw/clikrb5.c @@ -74,7 +74,7 @@ { pkaddr->addrtype = ADDRTYPE_INET; pkaddr->length = sizeof(((struct sockaddr_in *)paddr)->sin_addr); - pkaddr->contents = (char *)&(((struct sockaddr_in *)paddr)->sin_addr); + pkaddr->contents = (krb5_octet *)&(((struct sockaddr_in *)paddr)->sin_addr); } #else __ERROR__XX__UNKNOWN_ADDRTYPE -- cgit From 8e4ab747b02207671203d40cd2a78692da78faef Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 15 Aug 2003 18:33:43 +0000 Subject: more fixes from the IRIX compiler (thanks herb!) (This used to be commit 4cf3839b727c77a727abb558bd9473119a092913) --- source4/libcli/raw/clitree.c | 2 -- source4/libcli/raw/rawfileinfo.c | 2 -- source4/libcli/raw/rawnegotiate.c | 2 +- 3 files changed, 1 insertion(+), 5 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index a088ae7023..1e9104308e 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -121,7 +121,6 @@ NTSTATUS smb_tree_connect_recv(struct cli_request *req, TALLOC_CTX *mem_ctx, uni case RAW_TCON_TCONX: ZERO_STRUCT(parms->tconx.out); - CLI_CHECK_MIN_WCT(req, 0); /* this depends on the protocol level */ parms->tconx.out.cnum = SVAL(req->in.hdr, HDR_TID); if (req->in.wct >= 4) { parms->tconx.out.options = SVAL(req->in.vwv, VWV(3)); @@ -245,7 +244,6 @@ NTSTATUS cli_tree_full_connection(struct cli_tree **ret_tree, mem_ctx = talloc_init("tcon"); if (!mem_ctx) { - cli_tree_close(tree); return NT_STATUS_NO_MEMORY; } diff --git a/source4/libcli/raw/rawfileinfo.c b/source4/libcli/raw/rawfileinfo.c index 70121025d0..41fe1225cc 100644 --- a/source4/libcli/raw/rawfileinfo.c +++ b/source4/libcli/raw/rawfileinfo.c @@ -146,7 +146,6 @@ static NTSTATUS smb_raw_info_backend(struct cli_session *session, case RAW_FILEINFO_STREAM_INFO: case RAW_FILEINFO_STREAM_INFORMATION: - FINFO_CHECK_MIN_SIZE(0); ofs = 0; parms->stream_info.out.num_streams = 0; parms->stream_info.out.streams = NULL; @@ -228,7 +227,6 @@ static NTSTATUS smb_raw_info_backend(struct cli_session *session, return NT_STATUS_OK; case RAW_FILEINFO_UNIX_LINK: - FINFO_CHECK_MIN_SIZE(0); cli_blob_pull_string(session, mem_ctx, blob, &parms->unix_link_info.out.link_dest, 0, 4, STR_UNICODE); return NT_STATUS_OK; diff --git a/source4/libcli/raw/rawnegotiate.c b/source4/libcli/raw/rawnegotiate.c index 78b2e00706..04941f6118 100644 --- a/source4/libcli/raw/rawnegotiate.c +++ b/source4/libcli/raw/rawnegotiate.c @@ -22,7 +22,7 @@ #include "includes.h" static const struct { - int prot; + enum protocol_types prot; const char *name; } prots[] = { {PROTOCOL_CORE,"PC NETWORK PROGRAM 1.0"}, -- cgit From de10237719db8101cd9487b257761d4721f857ab Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 15 Aug 2003 18:54:44 +0000 Subject: more fixes from the IRIX compiler (thanks herb!) (This used to be commit 02d068ba7d81d6db25122144981c63f74ad44025) --- source4/libcli/raw/rawtrans.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawtrans.c b/source4/libcli/raw/rawtrans.c index 508f920268..f8076f7133 100644 --- a/source4/libcli/raw/rawtrans.c +++ b/source4/libcli/raw/rawtrans.c @@ -206,7 +206,6 @@ struct cli_request *smb_raw_trans2_send(struct cli_tree *tree, int wct = 14 + parms->in.setup_count; struct cli_request *req; char *outdata,*outparam; - int data_sent, param_sent; int i; const int padding = 3; @@ -216,10 +215,8 @@ struct cli_request *smb_raw_trans2_send(struct cli_tree *tree, } /* fill in SMB parameters */ - data_sent = parms->in.data.length; - param_sent = parms->in.params.length; outparam = req->out.data + padding; - outdata = outparam + param_sent; + outdata = outparam + parms->in.params.length; /* make sure we don't leak data via the padding */ memset(req->out.data, 0, padding); -- cgit From 11c5869a450d5f78a9395889ec03f77732cc8be5 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 31 Aug 2003 03:16:52 +0000 Subject: I think I've finally got the ascii/unicode issues right in trans2 find first Also expanded the rename test a little (This used to be commit 723af7f097a8c7f23dac23039e479811559ac3cb) --- source4/libcli/raw/rawfile.c | 2 +- source4/libcli/raw/rawrequest.c | 23 +++++++++++++++++------ source4/libcli/raw/rawsearch.c | 8 ++++---- 3 files changed, 22 insertions(+), 11 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c index e9d3a8305d..0dc2a15c11 100644 --- a/source4/libcli/raw/rawfile.c +++ b/source4/libcli/raw/rawfile.c @@ -48,7 +48,7 @@ struct cli_request *smb_raw_rename_send(struct cli_tree *tree, SETUP_REQUEST(SMBntrename, 4, 0); SSVAL(req->out.vwv, VWV(0), parms->ntrename.in.attrib); SSVAL(req->out.vwv, VWV(1), parms->ntrename.in.flags); - SIVAL(req->out.vwv, VWV(2), parms->ntrename.in.unknown); + SIVAL(req->out.vwv, VWV(2), parms->ntrename.in.cluster_size); cli_req_append_ascii4(req, parms->ntrename.in.old_name, STR_TERMINATE); cli_req_append_ascii4(req, parms->ntrename.in.new_name, STR_TERMINATE); break; diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index fa3b3ab627..139f031178 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -963,8 +963,9 @@ size_t cli_blob_pull_string(struct cli_session *session, uint16 len_offset, uint16 str_offset, unsigned flags) { + int extra; dest->s = NULL; - + if (len_offset > blob->length-4) { return 0; } @@ -973,19 +974,29 @@ size_t cli_blob_pull_string(struct cli_session *session, } else { dest->private_length = IVAL(blob->data, len_offset); } + extra = 0; dest->s = NULL; if (!(flags & STR_ASCII) && ((flags & STR_UNICODE) || (session->transport->negotiate.capabilities & CAP_UNICODE))) { + int align = 0; if ((str_offset&1) && !(flags & STR_NOALIGN)) { - str_offset++; + align = 1; + } + if (flags & STR_LEN_NOTERM) { + extra = 2; } - return cli_blob_pull_ucs2(mem_ctx, blob, &dest->s, - blob->data+str_offset, dest->private_length, flags); + return align + extra + cli_blob_pull_ucs2(mem_ctx, blob, &dest->s, + blob->data+str_offset+align, + dest->private_length, flags); + } + + if (flags & STR_LEN_NOTERM) { + extra = 1; } - return cli_blob_pull_ascii(mem_ctx, blob, &dest->s, - blob->data+str_offset, dest->private_length, flags); + return extra + cli_blob_pull_ascii(mem_ctx, blob, &dest->s, + blob->data+str_offset, dest->private_length, flags); } /* diff --git a/source4/libcli/raw/rawsearch.c b/source4/libcli/raw/rawsearch.c index bdc39bb68c..222bf53623 100644 --- a/source4/libcli/raw/rawsearch.c +++ b/source4/libcli/raw/rawsearch.c @@ -263,8 +263,8 @@ static int parse_trans2_search(struct cli_tree *tree, data->standard.attrib = SVAL(blob->data, 20); len = cli_blob_pull_string(tree->session, mem_ctx, blob, &data->standard.name, - 22, 23, STR_LEN8BIT); - return (len + 23 + 3) & ~3; + 22, 23, STR_LEN8BIT | STR_TERMINATE | STR_LEN_NOTERM); + return len + 23; case RAW_SEARCH_EA_SIZE: if (flags & FLAG_TRANS2_FIND_REQUIRE_RESUME) { @@ -283,8 +283,8 @@ static int parse_trans2_search(struct cli_tree *tree, data->ea_size.ea_size = IVAL(blob->data, 22); len = cli_blob_pull_string(tree->session, mem_ctx, blob, &data->ea_size.name, - 26, 27, STR_LEN8BIT | STR_NOALIGN); - return len + 27; + 26, 27, STR_LEN8BIT | STR_TERMINATE | STR_NOALIGN); + return len + 27 + 1; case RAW_SEARCH_DIRECTORY_INFO: if (blob->length < 65) return -1; -- cgit From 0becf4d68329ca599f3e34ee97ca3f72d0e9425f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 2 Sep 2003 04:37:33 +0000 Subject: thanks to ntfsd and some google searches I worked out what the unknown fields in level 261 and level 262 of directory search are, plus the names of the levels the unknown fields are a 64bit unique file id, and match the 64 bit number from the internal_information qfileinfo level (This used to be commit b69f54eb028a24144a2e813f059b08644118ab09) --- source4/libcli/raw/rawfileinfo.c | 3 +-- source4/libcli/raw/rawsearch.c | 53 +++++++++++++++++++--------------------- 2 files changed, 26 insertions(+), 30 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawfileinfo.c b/source4/libcli/raw/rawfileinfo.c index 41fe1225cc..fd66080057 100644 --- a/source4/libcli/raw/rawfileinfo.c +++ b/source4/libcli/raw/rawfileinfo.c @@ -173,8 +173,7 @@ static NTSTATUS smb_raw_info_backend(struct cli_session *session, case RAW_FILEINFO_INTERNAL_INFORMATION: FINFO_CHECK_SIZE(8); - parms->internal_information.out.device = IVAL(blob->data, 0); - parms->internal_information.out.inode = IVAL(blob->data, 4); + parms->internal_information.out.file_id = BVAL(blob->data, 0); return NT_STATUS_OK; case RAW_FILEINFO_ACCESS_INFORMATION: diff --git a/source4/libcli/raw/rawsearch.c b/source4/libcli/raw/rawsearch.c index 222bf53623..430cf925a6 100644 --- a/source4/libcli/raw/rawsearch.c +++ b/source4/libcli/raw/rawsearch.c @@ -362,48 +362,45 @@ static int parse_trans2_search(struct cli_tree *tree, return ofs; - case RAW_SEARCH_261: + case RAW_SEARCH_ID_FULL_DIRECTORY_INFO: if (blob->length < 81) return -1; ofs = IVAL(blob->data, 0); - data->level_261.file_index = IVAL(blob->data, 4); - data->level_261.create_time = cli_pull_nttime(blob->data, 8); - data->level_261.access_time = cli_pull_nttime(blob->data, 16); - data->level_261.write_time = cli_pull_nttime(blob->data, 24); - data->level_261.change_time = cli_pull_nttime(blob->data, 32); - data->level_261.size = BVAL(blob->data, 40); - data->level_261.alloc_size = BVAL(blob->data, 48); - data->level_261.attrib = IVAL(blob->data, 56); - data->level_261.ea_size = IVAL(blob->data, 64); - data->level_261.unknown[0] = IVAL(blob->data, 68); - data->level_261.unknown[1] = IVAL(blob->data, 72); - data->level_261.unknown[2] = IVAL(blob->data, 76); + data->id_full_directory_info.file_index = IVAL(blob->data, 4); + data->id_full_directory_info.create_time = cli_pull_nttime(blob->data, 8); + data->id_full_directory_info.access_time = cli_pull_nttime(blob->data, 16); + data->id_full_directory_info.write_time = cli_pull_nttime(blob->data, 24); + data->id_full_directory_info.change_time = cli_pull_nttime(blob->data, 32); + data->id_full_directory_info.size = BVAL(blob->data, 40); + data->id_full_directory_info.alloc_size = BVAL(blob->data, 48); + data->id_full_directory_info.attrib = IVAL(blob->data, 56); + data->id_full_directory_info.ea_size = IVAL(blob->data, 64); + data->id_full_directory_info.file_id = BVAL(blob->data, 72); len = cli_blob_pull_string(tree->session, mem_ctx, blob, - &data->level_261.name, + &data->id_full_directory_info.name, 60, 80, 0); if (ofs != 0 && ofs < 80+len) { return -1; } return ofs; - case RAW_SEARCH_262: + case RAW_SEARCH_ID_BOTH_DIRECTORY_INFO: if (blob->length < 105) return -1; ofs = IVAL(blob->data, 0); - data->level_262.file_index = IVAL(blob->data, 4); - data->level_262.create_time = cli_pull_nttime(blob->data, 8); - data->level_262.access_time = cli_pull_nttime(blob->data, 16); - data->level_262.write_time = cli_pull_nttime(blob->data, 24); - data->level_262.change_time = cli_pull_nttime(blob->data, 32); - data->level_262.size = BVAL(blob->data, 40); - data->level_262.alloc_size = BVAL(blob->data, 48); - data->level_262.attrib = SVAL(blob->data, 56); - data->level_262.ea_size = IVAL(blob->data, 64); + data->id_both_directory_info.file_index = IVAL(blob->data, 4); + data->id_both_directory_info.create_time = cli_pull_nttime(blob->data, 8); + data->id_both_directory_info.access_time = cli_pull_nttime(blob->data, 16); + data->id_both_directory_info.write_time = cli_pull_nttime(blob->data, 24); + data->id_both_directory_info.change_time = cli_pull_nttime(blob->data, 32); + data->id_both_directory_info.size = BVAL(blob->data, 40); + data->id_both_directory_info.alloc_size = BVAL(blob->data, 48); + data->id_both_directory_info.attrib = SVAL(blob->data, 56); + data->id_both_directory_info.ea_size = IVAL(blob->data, 64); cli_blob_pull_string(tree->session, mem_ctx, blob, - &data->level_262.short_name, + &data->id_both_directory_info.short_name, 68, 70, STR_LEN8BIT | STR_UNICODE); - data->level_262.unknown[0] = IVAL(blob->data, 94); - data->level_262.unknown[1] = IVAL(blob->data, 98); + data->id_both_directory_info.file_id = BVAL(blob->data, 96); len = cli_blob_pull_string(tree->session, mem_ctx, blob, - &data->level_262.name, + &data->id_both_directory_info.name, 60, 104, 0); if (ofs != 0 && ofs < 104+len) { return -1; -- cgit From 931dc553909c4ee345f7c16ca79f56f84ae39ff6 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 28 Oct 2003 10:17:05 +0000 Subject: Implement raw SMBtrans by backending the SMBtrans2 send code. Receive is the same for trans and trans2. (This used to be commit 7d21af3fdf6cf5144a41021425179ca2bba553b3) --- source4/libcli/raw/rawtrans.c | 61 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 53 insertions(+), 8 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawtrans.c b/source4/libcli/raw/rawtrans.c index f8076f7133..f31b1eaf7e 100644 --- a/source4/libcli/raw/rawtrans.c +++ b/source4/libcli/raw/rawtrans.c @@ -194,20 +194,32 @@ failed: return cli_request_destroy(req); } +NTSTATUS smb_raw_trans_recv(struct cli_request *req, + TALLOC_CTX *mem_ctx, + struct smb_trans2 *parms) +{ + return smb_raw_trans2_recv(req, mem_ctx, parms); +} /**************************************************************************** - trans2 raw async interface - only BLOBs used in this interface. -note that this doesn't yet support multi-part requests + trans/trans2 raw async interface - only BLOBs used in this interface. + note that this doesn't yet support multi-part requests ****************************************************************************/ -struct cli_request *smb_raw_trans2_send(struct cli_tree *tree, - struct smb_trans2 *parms) +struct cli_request *smb_raw_trans_send_backend(struct cli_tree *tree, + struct smb_trans2 *parms, + uint8 command) { - uint8 command = SMBtrans2; int wct = 14 + parms->in.setup_count; struct cli_request *req; char *outdata,*outparam; int i; - const int padding = 3; + int padding; + size_t namelen = 0; + + if (command == SMBtrans) + padding = 1; + else + padding = 3; req = cli_request_setup(tree, command, wct, padding); if (!req) { @@ -231,9 +243,12 @@ struct cli_request *smb_raw_trans2_send(struct cli_tree *tree, SIVAL(req->out.vwv,VWV(6),parms->in.timeout); SSVAL(req->out.vwv,VWV(8),0); /* reserved */ SSVAL(req->out.vwv,VWV(9),parms->in.params.length); - SSVAL(req->out.vwv,VWV(10),PTR_DIFF(outparam,req->out.hdr)); + if (command == SMBtrans && parms->in.trans_name) + namelen = cli_req_append_string(req, parms->in.trans_name, + STR_TERMINATE); + SSVAL(req->out.vwv,VWV(10),PTR_DIFF(outparam,req->out.hdr)+namelen); SSVAL(req->out.vwv,VWV(11),parms->in.data.length); - SSVAL(req->out.vwv,VWV(12),PTR_DIFF(outdata,req->out.hdr)); + SSVAL(req->out.vwv,VWV(12),PTR_DIFF(outdata,req->out.hdr)+namelen); SSVAL(req->out.vwv,VWV(13),parms->in.setup_count); for (i=0;iin.setup_count;i++) { SSVAL(req->out.vwv,VWV(14)+i*2,parms->in.setup[i]); @@ -253,6 +268,23 @@ struct cli_request *smb_raw_trans2_send(struct cli_tree *tree, return req; } +/**************************************************************************** + trans/trans2 raw async interface - only BLOBs used in this interface. +note that this doesn't yet support multi-part requests +****************************************************************************/ + +struct cli_request *smb_raw_trans_send(struct cli_tree *tree, + struct smb_trans2 *parms) +{ + return smb_raw_trans_send_backend(tree, parms, SMBtrans); +} + +struct cli_request *smb_raw_trans2_send(struct cli_tree *tree, + struct smb_trans2 *parms) +{ + return smb_raw_trans_send_backend(tree, parms, SMBtrans2); +} + /* trans2 synchronous blob interface */ @@ -267,6 +299,19 @@ NTSTATUS smb_raw_trans2(struct cli_tree *tree, } +/* + trans synchronous blob interface +*/ +NTSTATUS smb_raw_trans(struct cli_tree *tree, + TALLOC_CTX *mem_ctx, + struct smb_trans2 *parms) +{ + struct cli_request *req; + req = smb_raw_trans_send(tree, parms); + if (!req) return NT_STATUS_UNSUCCESSFUL; + return smb_raw_trans_recv(req, mem_ctx, parms); +} + /**************************************************************************** receive a SMB nttrans response allocating the necessary memory ****************************************************************************/ -- cgit From 476adf5725cd06bcd04623a2c61701158076a3b9 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 28 Oct 2003 10:24:13 +0000 Subject: Initial version of raw dcerpc client support. (This used to be commit 34a2cc10992953897268ca864f2851f4c2d99e1e) --- source4/libcli/raw/rawdcerpc.c | 222 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 222 insertions(+) create mode 100644 source4/libcli/raw/rawdcerpc.c (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawdcerpc.c b/source4/libcli/raw/rawdcerpc.c new file mode 100644 index 0000000000..11bd0057ce --- /dev/null +++ b/source4/libcli/raw/rawdcerpc.c @@ -0,0 +1,222 @@ +/* + Unix SMB/CIFS implementation. + raw dcerpc operations + + Copyright (C) Tim Potter, 2003 + + 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. +*/ + +#include "includes.h" + +static int put_uuid(char *data, int offset, struct dcerpc_uuid *uuid) +{ + int i; + + SIVAL(data, offset, uuid->time_low); offset += 4; + SSVAL(data, offset, uuid->time_mid); offset += 2; + SSVAL(data, offset, uuid->time_hi_and_version); offset += 2; + for (i = 0; i < 8; i++) + SCVAL(data, offset + i, uuid->remaining[i]); + offset += 8; + + return offset; +} + +DATA_BLOB dcerpc_raw_bind_setup(struct dcerpc_bind *parms) +{ + int i, offset, size; + char *data; + + /* Allocate storage for bind request */ + + size = 28; + for (i = 0; i < parms->in.num_contexts; i++) { + size += 24; /* as header + uuid */ + size += 20 * parms->in.ctx_list[i].num_ts; /* xfer syntaxes */ + } + size += parms->in.auth_verifier.length; + + data = smb_xmalloc(size); + memset(data, 0, size); + + parms->in.hdr.frag_len = size; + + /* Create bind request */ + + SCVAL(data, 0, parms->in.hdr.rpc_vers); + SCVAL(data, 1, parms->in.hdr.rpc_vers_minor); + SCVAL(data, 2, parms->in.hdr.ptype); + SCVAL(data, 3, parms->in.hdr.pfc_flags); + for (i = 0; i < 4; i++) + SCVAL(data, 4 + i, parms->in.hdr.drep[i]); + SSVAL(data, 8, parms->in.hdr.frag_len); + SSVAL(data, 10, parms->in.auth_verifier.length); + SIVAL(data, 12, parms->in.hdr.call_id); + + SSVAL(data, 16, parms->in.max_xmit_frag); + SSVAL(data, 18, parms->in.max_recv_frag); + SIVAL(data, 20, parms->in.assoc_group_id); + SIVAL(data, 24, parms->in.num_contexts); + + offset = 28; + for (i = 0; i < parms->in.num_contexts; i++) { + struct p_ctx_list *ctx = &parms->in.ctx_list[i]; + int j; + + SSVAL(data, offset, ctx->cont_id); offset += 2; + SSVAL(data, offset, ctx->num_ts); offset += 2; + offset = put_uuid(data, offset, &ctx->as->if_uuid); + SIVAL(data, offset, ctx->as->if_version); offset += 4; + for (j = 0; j < ctx->num_ts; j++) { + offset = put_uuid(data, offset, &ctx->ts[i]->if_uuid); + SIVAL(data, offset, ctx->ts[i]->if_version); + offset += 4; + } + } + + if (parms->in.auth_verifier.length) + memcpy(&data[offset], parms->in.auth_verifier.data, + parms->in.auth_verifier.length); + + return data_blob(data, size); +} + +NTSTATUS dcerpc_raw_bind_send(struct cli_dcerpc_pipe *p, + struct dcerpc_bind *parms) +{ + struct smb_trans2 trans; + DATA_BLOB blob; + NTSTATUS result; + uint16 setup[2]; + + blob = dcerpc_raw_bind_setup(parms); + + ZERO_STRUCT(trans); + + trans.in.max_data = blob.length; + trans.in.setup_count = 2; + trans.in.setup = setup; + trans.in.trans_name = "\\PIPE\\"; + + setup[0] = TRANSACT_DCERPCCMD; + setup[1] = p->fnum; + + trans.in.data = blob; + + result = smb_raw_trans(p->tree, p->mem_ctx, &trans); + + data_blob_free(&blob); + + return result; +} + +NTSTATUS dcerpc_raw_bind_recv(struct cli_dcerpc_pipe *p, + struct dcerpc_bind *parms) +{ + return NT_STATUS_UNSUCCESSFUL; +} + +NTSTATUS dcerpc_raw_bind(struct cli_dcerpc_pipe *p, struct dcerpc_bind *parms) +{ + NTSTATUS result; + + result = dcerpc_raw_bind_send(p, parms); + if (NT_STATUS_IS_ERR(result)) + return result; + return dcerpc_raw_bind_recv(p, parms); +} + +DATA_BLOB dcerpc_raw_request_setup(struct dcerpc_request *parms) +{ + int size, i; + char *data; + + /* Allocate storage for request */ + + size = 24 + parms->in.stub_data.length; + + data = smb_xmalloc(size); + memset(data, 0, size); + + parms->in.hdr.frag_len = size; + parms->in.alloc_hint = parms->in.stub_data.length; + + SCVAL(data, 0, parms->in.hdr.rpc_vers); + SCVAL(data, 1, parms->in.hdr.rpc_vers_minor); + SCVAL(data, 2, parms->in.hdr.ptype); + SCVAL(data, 3, parms->in.hdr.pfc_flags); + for (i = 0; i < 4; i++) + SCVAL(data, 4 + i, parms->in.hdr.drep[i]); + SSVAL(data, 8, parms->in.hdr.frag_len); + SSVAL(data, 10, parms->in.auth_verifier.length); + SIVAL(data, 12, parms->in.hdr.call_id); + + SIVAL(data, 16, parms->in.alloc_hint); + SSVAL(data, 20, parms->in.cont_id); + SSVAL(data, 22, parms->in.opnum); + + if (parms->in.stub_data.length) + memcpy(&data[24], parms->in.stub_data.data, + parms->in.stub_data.length); + + return data_blob(data, size); +} + +NTSTATUS dcerpc_raw_request_send(struct cli_dcerpc_pipe *p, + struct dcerpc_request *parms) +{ + struct smb_trans2 trans; + DATA_BLOB blob; + NTSTATUS result; + uint16 setup[2]; + + blob = dcerpc_raw_request_setup(parms); + + ZERO_STRUCT(trans); + + trans.in.max_data = blob.length; + trans.in.setup_count = 2; + trans.in.setup = setup; + trans.in.trans_name = "\\PIPE\\"; + + setup[0] = TRANSACT_DCERPCCMD; + setup[1] = p->fnum; + + trans.in.data = blob; + + result = smb_raw_trans(p->tree, p->mem_ctx, &trans); + + data_blob_free(&blob); + + return result; +} + +NTSTATUS dcerpc_raw_request_recv(struct cli_dcerpc_pipe *p, + struct dcerpc_request *parms) +{ + return NT_STATUS_UNSUCCESSFUL; +} + +NTSTATUS dcerpc_raw_request(struct cli_dcerpc_pipe *p, + struct dcerpc_request *parms) +{ + NTSTATUS result; + + result = dcerpc_raw_request_send(p, parms); + if (NT_STATUS_IS_ERR(result)) + return result; + return dcerpc_raw_request_recv(p, parms); +} -- cgit From 4cac564d71f7387497fa23f2b6bcc0461a1978bc Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 28 Oct 2003 10:59:19 +0000 Subject: A fix for making transfer syntax a pointer instead of an array of pointers in struct p_ctx_list. (This used to be commit e99e28aa36f31e862e89cef246b50a34b5115af9) --- source4/libcli/raw/rawdcerpc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawdcerpc.c b/source4/libcli/raw/rawdcerpc.c index 11bd0057ce..1cc034de78 100644 --- a/source4/libcli/raw/rawdcerpc.c +++ b/source4/libcli/raw/rawdcerpc.c @@ -81,8 +81,8 @@ DATA_BLOB dcerpc_raw_bind_setup(struct dcerpc_bind *parms) offset = put_uuid(data, offset, &ctx->as->if_uuid); SIVAL(data, offset, ctx->as->if_version); offset += 4; for (j = 0; j < ctx->num_ts; j++) { - offset = put_uuid(data, offset, &ctx->ts[i]->if_uuid); - SIVAL(data, offset, ctx->ts[i]->if_version); + offset = put_uuid(data, offset, &ctx->ts[i].if_uuid); + SIVAL(data, offset, ctx->ts[i].if_version); offset += 4; } } -- cgit From 7fd381376f88ae99a4bf022d89f21ae497b48c1a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 30 Oct 2003 08:32:26 +0000 Subject: - a few portability fixes from Jim Myers - added SMBD_LISTEN_BACKLOG in local.h - added the beginnings of a ndr/rpc parsing framework for Samba4. It currently correctly parses security descriptors for the nttrans QUERY_SECDESC call, but I hope it will become a reasonable framework that an idl based generator can work to (This used to be commit 9bf904fc34f88e0581f93656e73d3c01ca96f761) --- source4/libcli/raw/rawacl.c | 97 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 source4/libcli/raw/rawacl.c (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawacl.c b/source4/libcli/raw/rawacl.c new file mode 100644 index 0000000000..4cd3338ec5 --- /dev/null +++ b/source4/libcli/raw/rawacl.c @@ -0,0 +1,97 @@ +/* + Unix SMB/CIFS implementation. + ACL get/set operations + Copyright (C) Andrew Tridgell 2003 + + 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. +*/ + +#include "includes.h" + +/**************************************************************************** +fetch file ACL (async send) +****************************************************************************/ +struct cli_request *smb_raw_query_secdesc_send(struct cli_tree *tree, + struct smb_query_secdesc *query) +{ + struct smb_nttrans nt; + uint8 params[8]; + + nt.in.max_setup = 0; + nt.in.max_param = 4; + nt.in.max_data = 0x10000; + nt.in.setup_count = 0; + nt.in.function = NT_TRANSACT_QUERY_SECURITY_DESC; + nt.in.setup = NULL; + + SSVAL(params, 0, query->in.fnum); + SSVAL(params, 2, 0); /* padding */ + SIVAL(params, 4, query->in.secinfo_flags); + + nt.in.params.data = params; + nt.in.params.length = 8; + + nt.in.data = data_blob(NULL, 0); + + return smb_raw_nttrans_send(tree, &nt); +} + + +/**************************************************************************** +fetch file ACL (async recv) +****************************************************************************/ +NTSTATUS smb_raw_query_secdesc_recv(struct cli_request *req, + TALLOC_CTX *mem_ctx, + struct smb_query_secdesc *query) +{ + NTSTATUS status; + struct smb_nttrans nt; + struct ndr_parse *rpc; + + status = smb_raw_nttrans_recv(req, mem_ctx, &nt); + if (!NT_STATUS_IS_OK(status)) { + return status; + } + + /* check that the basics are valid */ + if (nt.out.params.length != 4 || + IVAL(nt.out.params.data, 0) > nt.out.data.length) { + return NT_STATUS_INVALID_PARAMETER; + } + + nt.out.data.length = IVAL(nt.out.params.data, 0); + + rpc = ndr_parse_init_blob(&nt.out.data, mem_ctx); + if (!rpc) { + return NT_STATUS_INVALID_PARAMETER; + } + + status = ndr_parse_security_descriptor(rpc, &query->out.sd); + + return NT_STATUS_OK; +} + + +/**************************************************************************** +fetch file ACL (sync interface) +****************************************************************************/ +NTSTATUS smb_raw_query_secdesc(struct cli_tree *tree, + TALLOC_CTX *mem_ctx, + struct smb_query_secdesc *query) +{ + struct cli_request *req = smb_raw_query_secdesc_send(tree, query); + return smb_raw_query_secdesc_recv(req, mem_ctx, query); +} + -- cgit From c5cf47443985c34ad32c44c322901e0fc3a065d7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 3 Nov 2003 06:22:45 +0000 Subject: a major revamp of the low level dcerpc code in samba4, We can now do a successful LSA OpenPolicy using smbtorture (This used to be commit e925c315f55905060fcca1b188ae1f7e40baf514) --- source4/libcli/raw/clisession.c | 4 +- source4/libcli/raw/rawacl.c | 52 +++++++++- source4/libcli/raw/rawdcerpc.c | 215 +++++++--------------------------------- source4/libcli/raw/rawsearch.c | 8 +- 4 files changed, 92 insertions(+), 187 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index 406491e432..9d154e10cd 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -318,8 +318,8 @@ static NTSTATUS smb_raw_session_setup_generic_nt1(struct cli_session *session, s2.nt1.in.os = "Unix"; s2.nt1.in.lanman = "Samba"; - if (session->transport->negotiate.sec_mode & - NEGOTIATE_SECURITY_CHALLENGE_RESPONSE) { + if (s2.nt1.in.user[0] && + (session->transport->negotiate.sec_mode & NEGOTIATE_SECURITY_CHALLENGE_RESPONSE)) { s2.nt1.in.password1 = lanman_blob(parms->generic.in.password, session->transport->negotiate.secblob); s2.nt1.in.password2 = nt_blob(parms->generic.in.password, diff --git a/source4/libcli/raw/rawacl.c b/source4/libcli/raw/rawacl.c index 4cd3338ec5..c45152381d 100644 --- a/source4/libcli/raw/rawacl.c +++ b/source4/libcli/raw/rawacl.c @@ -58,7 +58,7 @@ NTSTATUS smb_raw_query_secdesc_recv(struct cli_request *req, { NTSTATUS status; struct smb_nttrans nt; - struct ndr_parse *rpc; + struct ndr_pull *ndr; status = smb_raw_nttrans_recv(req, mem_ctx, &nt); if (!NT_STATUS_IS_OK(status)) { @@ -73,12 +73,12 @@ NTSTATUS smb_raw_query_secdesc_recv(struct cli_request *req, nt.out.data.length = IVAL(nt.out.params.data, 0); - rpc = ndr_parse_init_blob(&nt.out.data, mem_ctx); - if (!rpc) { + ndr = ndr_pull_init_blob(&nt.out.data, mem_ctx); + if (!ndr) { return NT_STATUS_INVALID_PARAMETER; } - status = ndr_parse_security_descriptor(rpc, &query->out.sd); + status = ndr_pull_security_descriptor(ndr, &query->out.sd); return NT_STATUS_OK; } @@ -95,3 +95,47 @@ NTSTATUS smb_raw_query_secdesc(struct cli_tree *tree, return smb_raw_query_secdesc_recv(req, mem_ctx, query); } + + +/**************************************************************************** +set file ACL (async send) +****************************************************************************/ +struct cli_request *smb_raw_set_secdesc_send(struct cli_tree *tree, + struct smb_set_secdesc *set) +{ + struct smb_nttrans nt; + uint8 params[8]; + struct ndr_push *ndr; + struct cli_request *req; + NTSTATUS status; + + nt.in.max_setup = 0; + nt.in.max_param = 0; + nt.in.max_data = 0; + nt.in.setup_count = 0; + nt.in.function = NT_TRANSACT_SET_SECURITY_DESC; + nt.in.setup = NULL; + + SSVAL(params, 0, set->in.fnum); + SSVAL(params, 2, 0); /* padding */ + SIVAL(params, 4, set->in.secinfo_flags); + + nt.in.params.data = params; + nt.in.params.length = 8; + + ndr = ndr_push_init(); + if (!ndr) return NULL; + +// status = ndr_push_security_descriptor(ndr, set->in.sd); + if (!NT_STATUS_IS_OK(status)) { + ndr_push_free(ndr); + return NULL; + } + + nt.in.data = ndr_push_blob(ndr); + + req = smb_raw_nttrans_send(tree, &nt); + + ndr_push_free(ndr); + return req; +} diff --git a/source4/libcli/raw/rawdcerpc.c b/source4/libcli/raw/rawdcerpc.c index 1cc034de78..4a5159948d 100644 --- a/source4/libcli/raw/rawdcerpc.c +++ b/source4/libcli/raw/rawdcerpc.c @@ -2,7 +2,8 @@ Unix SMB/CIFS implementation. raw dcerpc operations - Copyright (C) Tim Potter, 2003 + Copyright (C) Tim Potter 2003 + Copyright (C) Andrew Tridgell 2003 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 @@ -21,202 +22,62 @@ #include "includes.h" -static int put_uuid(char *data, int offset, struct dcerpc_uuid *uuid) -{ - int i; - - SIVAL(data, offset, uuid->time_low); offset += 4; - SSVAL(data, offset, uuid->time_mid); offset += 2; - SSVAL(data, offset, uuid->time_hi_and_version); offset += 2; - for (i = 0; i < 8; i++) - SCVAL(data, offset + i, uuid->remaining[i]); - offset += 8; - - return offset; -} - -DATA_BLOB dcerpc_raw_bind_setup(struct dcerpc_bind *parms) -{ - int i, offset, size; - char *data; - - /* Allocate storage for bind request */ - - size = 28; - for (i = 0; i < parms->in.num_contexts; i++) { - size += 24; /* as header + uuid */ - size += 20 * parms->in.ctx_list[i].num_ts; /* xfer syntaxes */ - } - size += parms->in.auth_verifier.length; - - data = smb_xmalloc(size); - memset(data, 0, size); - - parms->in.hdr.frag_len = size; - - /* Create bind request */ - - SCVAL(data, 0, parms->in.hdr.rpc_vers); - SCVAL(data, 1, parms->in.hdr.rpc_vers_minor); - SCVAL(data, 2, parms->in.hdr.ptype); - SCVAL(data, 3, parms->in.hdr.pfc_flags); - for (i = 0; i < 4; i++) - SCVAL(data, 4 + i, parms->in.hdr.drep[i]); - SSVAL(data, 8, parms->in.hdr.frag_len); - SSVAL(data, 10, parms->in.auth_verifier.length); - SIVAL(data, 12, parms->in.hdr.call_id); - - SSVAL(data, 16, parms->in.max_xmit_frag); - SSVAL(data, 18, parms->in.max_recv_frag); - SIVAL(data, 20, parms->in.assoc_group_id); - SIVAL(data, 24, parms->in.num_contexts); - - offset = 28; - for (i = 0; i < parms->in.num_contexts; i++) { - struct p_ctx_list *ctx = &parms->in.ctx_list[i]; - int j; - - SSVAL(data, offset, ctx->cont_id); offset += 2; - SSVAL(data, offset, ctx->num_ts); offset += 2; - offset = put_uuid(data, offset, &ctx->as->if_uuid); - SIVAL(data, offset, ctx->as->if_version); offset += 4; - for (j = 0; j < ctx->num_ts; j++) { - offset = put_uuid(data, offset, &ctx->ts[i].if_uuid); - SIVAL(data, offset, ctx->ts[i].if_version); - offset += 4; - } - } - - if (parms->in.auth_verifier.length) - memcpy(&data[offset], parms->in.auth_verifier.data, - parms->in.auth_verifier.length); - - return data_blob(data, size); -} - -NTSTATUS dcerpc_raw_bind_send(struct cli_dcerpc_pipe *p, - struct dcerpc_bind *parms) +struct cli_request *dcerpc_raw_send(struct dcerpc_pipe *p, DATA_BLOB *blob) { struct smb_trans2 trans; - DATA_BLOB blob; - NTSTATUS result; uint16 setup[2]; + struct cli_request *req; + TALLOC_CTX *mem_ctx; - blob = dcerpc_raw_bind_setup(parms); + mem_ctx = talloc_init("dcerpc_raw_send"); + if (!mem_ctx) return NULL; - ZERO_STRUCT(trans); + trans.in.data = *blob; + trans.in.params = data_blob(NULL, 0); + + setup[0] = TRANSACT_DCERPCCMD; + setup[1] = p->fnum; - trans.in.max_data = blob.length; + trans.in.max_param = 0; + trans.in.max_data = 0x8000; trans.in.setup_count = 2; trans.in.setup = setup; trans.in.trans_name = "\\PIPE\\"; - setup[0] = TRANSACT_DCERPCCMD; - setup[1] = p->fnum; - - trans.in.data = blob; - - result = smb_raw_trans(p->tree, p->mem_ctx, &trans); - - data_blob_free(&blob); + req = smb_raw_trans_send(p->tree, &trans); - return result; -} + talloc_destroy(mem_ctx); -NTSTATUS dcerpc_raw_bind_recv(struct cli_dcerpc_pipe *p, - struct dcerpc_bind *parms) -{ - return NT_STATUS_UNSUCCESSFUL; + return req; } -NTSTATUS dcerpc_raw_bind(struct cli_dcerpc_pipe *p, struct dcerpc_bind *parms) -{ - NTSTATUS result; - - result = dcerpc_raw_bind_send(p, parms); - if (NT_STATUS_IS_ERR(result)) - return result; - return dcerpc_raw_bind_recv(p, parms); -} - -DATA_BLOB dcerpc_raw_request_setup(struct dcerpc_request *parms) -{ - int size, i; - char *data; - - /* Allocate storage for request */ - - size = 24 + parms->in.stub_data.length; - - data = smb_xmalloc(size); - memset(data, 0, size); - - parms->in.hdr.frag_len = size; - parms->in.alloc_hint = parms->in.stub_data.length; - - SCVAL(data, 0, parms->in.hdr.rpc_vers); - SCVAL(data, 1, parms->in.hdr.rpc_vers_minor); - SCVAL(data, 2, parms->in.hdr.ptype); - SCVAL(data, 3, parms->in.hdr.pfc_flags); - for (i = 0; i < 4; i++) - SCVAL(data, 4 + i, parms->in.hdr.drep[i]); - SSVAL(data, 8, parms->in.hdr.frag_len); - SSVAL(data, 10, parms->in.auth_verifier.length); - SIVAL(data, 12, parms->in.hdr.call_id); - - SIVAL(data, 16, parms->in.alloc_hint); - SSVAL(data, 20, parms->in.cont_id); - SSVAL(data, 22, parms->in.opnum); - - if (parms->in.stub_data.length) - memcpy(&data[24], parms->in.stub_data.data, - parms->in.stub_data.length); - - return data_blob(data, size); -} - -NTSTATUS dcerpc_raw_request_send(struct cli_dcerpc_pipe *p, - struct dcerpc_request *parms) +NTSTATUS dcerpc_raw_recv(struct dcerpc_pipe *p, + struct cli_request *req, + TALLOC_CTX *mem_ctx, + DATA_BLOB *blob) { struct smb_trans2 trans; - DATA_BLOB blob; - NTSTATUS result; - uint16 setup[2]; - - blob = dcerpc_raw_request_setup(parms); - - ZERO_STRUCT(trans); + NTSTATUS status; - trans.in.max_data = blob.length; - trans.in.setup_count = 2; - trans.in.setup = setup; - trans.in.trans_name = "\\PIPE\\"; - - setup[0] = TRANSACT_DCERPCCMD; - setup[1] = p->fnum; - - trans.in.data = blob; - - result = smb_raw_trans(p->tree, p->mem_ctx, &trans); + status = smb_raw_trans_recv(req, mem_ctx, &trans); + if (!NT_STATUS_IS_OK(status)) { + return status; + } - data_blob_free(&blob); + if (blob) { + *blob = trans.out.data; + } - return result; + return status; } -NTSTATUS dcerpc_raw_request_recv(struct cli_dcerpc_pipe *p, - struct dcerpc_request *parms) +NTSTATUS dcerpc_raw_packet(struct dcerpc_pipe *p, + TALLOC_CTX *mem_ctx, + DATA_BLOB *request_blob, + DATA_BLOB *reply_blob) { - return NT_STATUS_UNSUCCESSFUL; -} - -NTSTATUS dcerpc_raw_request(struct cli_dcerpc_pipe *p, - struct dcerpc_request *parms) -{ - NTSTATUS result; - - result = dcerpc_raw_request_send(p, parms); - if (NT_STATUS_IS_ERR(result)) - return result; - return dcerpc_raw_request_recv(p, parms); + struct cli_request *req; + req = dcerpc_raw_send(p, request_blob); + return dcerpc_raw_recv(p, req, mem_ctx, reply_blob); } + diff --git a/source4/libcli/raw/rawsearch.c b/source4/libcli/raw/rawsearch.c index 430cf925a6..4c7da6ec4d 100644 --- a/source4/libcli/raw/rawsearch.c +++ b/source4/libcli/raw/rawsearch.c @@ -307,7 +307,7 @@ static int parse_trans2_search(struct cli_tree *tree, case RAW_SEARCH_FULL_DIRECTORY_INFO: if (blob->length < 69) return -1; - ofs = IVAL(blob->data, 0); + ofs = IVAL(blob->data, 0); data->full_directory_info.file_index = IVAL(blob->data, 4); data->full_directory_info.create_time = cli_pull_nttime(blob->data, 8); data->full_directory_info.access_time = cli_pull_nttime(blob->data, 16); @@ -364,7 +364,7 @@ static int parse_trans2_search(struct cli_tree *tree, case RAW_SEARCH_ID_FULL_DIRECTORY_INFO: if (blob->length < 81) return -1; - ofs = IVAL(blob->data, 0); + ofs = IVAL(blob->data, 0); data->id_full_directory_info.file_index = IVAL(blob->data, 4); data->id_full_directory_info.create_time = cli_pull_nttime(blob->data, 8); data->id_full_directory_info.access_time = cli_pull_nttime(blob->data, 16); @@ -385,7 +385,7 @@ static int parse_trans2_search(struct cli_tree *tree, case RAW_SEARCH_ID_BOTH_DIRECTORY_INFO: if (blob->length < 105) return -1; - ofs = IVAL(blob->data, 0); + ofs = IVAL(blob->data, 0); data->id_both_directory_info.file_index = IVAL(blob->data, 4); data->id_both_directory_info.create_time = cli_pull_nttime(blob->data, 8); data->id_both_directory_info.access_time = cli_pull_nttime(blob->data, 16); @@ -481,7 +481,7 @@ NTSTATUS smb_raw_search_first(struct cli_tree *tree, return status; } - if (p_blob.length != 10) { + if (p_blob.length < 10) { DEBUG(1,("smb_raw_search_first: parms wrong size %d != expected_param_size\n", p_blob.length)); return NT_STATUS_INVALID_PARAMETER; -- cgit From 994301bfec372f0b929a61425fc1eb180d16cbb1 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 4 Nov 2003 02:28:08 +0000 Subject: added fragmentation support on receive for dcerpc packets. I have successfully used SourceData with 200M of data in rpcecho (This used to be commit a9aa7954fe84c925bb158af8b73aa71b7ea84e2b) --- source4/libcli/raw/rawdcerpc.c | 141 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 139 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawdcerpc.c b/source4/libcli/raw/rawdcerpc.c index 4a5159948d..d548129ab1 100644 --- a/source4/libcli/raw/rawdcerpc.c +++ b/source4/libcli/raw/rawdcerpc.c @@ -51,6 +51,7 @@ struct cli_request *dcerpc_raw_send(struct dcerpc_pipe *p, DATA_BLOB *blob) return req; } + NTSTATUS dcerpc_raw_recv(struct dcerpc_pipe *p, struct cli_request *req, TALLOC_CTX *mem_ctx, @@ -58,14 +59,78 @@ NTSTATUS dcerpc_raw_recv(struct dcerpc_pipe *p, { struct smb_trans2 trans; NTSTATUS status; + uint16 frag_length; + DATA_BLOB payload; status = smb_raw_trans_recv(req, mem_ctx, &trans); - if (!NT_STATUS_IS_OK(status)) { + /* STATUS_BUFFER_OVERFLOW means that there is more data + available via SMBreadX */ + if (!NT_STATUS_IS_OK(status) && + !NT_STATUS_EQUAL(status, STATUS_BUFFER_OVERFLOW)) { return status; } + payload = trans.out.data; + + if (trans.out.data.length < 16 || + !NT_STATUS_EQUAL(status, STATUS_BUFFER_OVERFLOW)) { + goto done; + } + + /* we might have recieved a partial fragment, in which case we + need to pull the rest of it */ + frag_length = SVAL(payload.data, 8); + if (frag_length <= payload.length) { + goto done; + } + + /* make sure the payload can hold the whole fragment */ + payload.data = talloc_realloc(mem_ctx, payload.data, frag_length); + if (!payload.data) { + return NT_STATUS_NO_MEMORY; + } + + /* the rest of the data is available via SMBreadX */ + while (frag_length > payload.length) { + uint32 n; + union smb_read io; + + n = frag_length - payload.length; + if (n > 0xFF00) { + n = 0xFF00; + } + + io.generic.level = RAW_READ_READX; + io.readx.in.fnum = p->fnum; + io.readx.in.mincnt = n; + io.readx.in.maxcnt = n; + io.readx.in.offset = 0; + io.readx.in.remaining = 0; + io.readx.out.data = payload.data + payload.length; + status = smb_raw_read(p->tree, &io); + if (!NT_STATUS_IS_OK(status) && + !NT_STATUS_EQUAL(status, STATUS_BUFFER_OVERFLOW)) { + break; + } + + n = io.readx.out.nread; + if (n == 0) { + status = NT_STATUS_UNSUCCESSFUL; + break; + } + + payload.length += n; + + /* if the SMBreadX returns NT_STATUS_OK then there + isn't any more data to be read */ + if (NT_STATUS_IS_OK(status)) { + break; + } + } + +done: if (blob) { - *blob = trans.out.data; + *blob = payload; } return status; @@ -81,3 +146,75 @@ NTSTATUS dcerpc_raw_packet(struct dcerpc_pipe *p, return dcerpc_raw_recv(p, req, mem_ctx, reply_blob); } + +/* + retrieve a secondary pdu from a pipe +*/ +NTSTATUS dcerpc_raw_packet_secondary(struct dcerpc_pipe *p, + TALLOC_CTX *mem_ctx, + DATA_BLOB *blob) +{ + union smb_read io; + uint32 n = 0x2000; + uint32 frag_length; + NTSTATUS status; + + *blob = data_blob_talloc(mem_ctx, NULL, n); + if (!blob->data) { + return NT_STATUS_NO_MEMORY; + } + + io.generic.level = RAW_READ_READX; + io.readx.in.fnum = p->fnum; + io.readx.in.mincnt = n; + io.readx.in.maxcnt = n; + io.readx.in.offset = 0; + io.readx.in.remaining = 0; + io.readx.out.data = blob->data; + + status = smb_raw_read(p->tree, &io); + if (!NT_STATUS_IS_OK(status) && + !NT_STATUS_EQUAL(status, STATUS_BUFFER_OVERFLOW)) { + return status; + } + + blob->length = io.readx.out.nread; + + if (blob->length < 16) { + return status; + } + + frag_length = SVAL(blob->data, 8); + if (frag_length <= blob->length) { + return status; + } + + blob->data = talloc_realloc(mem_ctx, blob->data, frag_length); + if (!blob->data) { + return NT_STATUS_NO_MEMORY; + } + + while (frag_length > blob->length && + NT_STATUS_EQUAL(status, STATUS_BUFFER_OVERFLOW)) { + + n = frag_length - blob->length; + if (n > 0xFF00) { + n = 0xFF00; + } + + io.readx.in.mincnt = n; + io.readx.in.maxcnt = n; + io.readx.out.data = blob->data + blob->length; + status = smb_raw_read(p->tree, &io); + + if (!NT_STATUS_IS_OK(status) && + !NT_STATUS_EQUAL(status, STATUS_BUFFER_OVERFLOW)) { + return status; + } + + n = io.readx.out.nread; + blob->length += n; + } + + return status; +} -- cgit From d8cbe76b868eb6f2b3876fa540e0847bd2d4f9d7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 4 Nov 2003 03:38:46 +0000 Subject: added support for fragmented sends (This used to be commit f51a216136b7cc7d4d07d4acb80e0a710d82841a) --- source4/libcli/raw/rawdcerpc.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawdcerpc.c b/source4/libcli/raw/rawdcerpc.c index d548129ab1..a6cd75eeaa 100644 --- a/source4/libcli/raw/rawdcerpc.c +++ b/source4/libcli/raw/rawdcerpc.c @@ -218,3 +218,35 @@ NTSTATUS dcerpc_raw_packet_secondary(struct dcerpc_pipe *p, return status; } + + +/* + send an initial pdu in a multi-pdu sequence +*/ +NTSTATUS dcerpc_raw_packet_initial(struct dcerpc_pipe *p, + TALLOC_CTX *mem_ctx, + DATA_BLOB *blob) +{ + union smb_write io; + NTSTATUS status; + + io.generic.level = RAW_WRITE_WRITEX; + io.writex.in.fnum = p->fnum; + io.writex.in.offset = 0; + io.writex.in.wmode = PIPE_START_MESSAGE; + io.writex.in.remaining = blob->length; + io.writex.in.count = blob->length; + io.writex.in.data = blob->data; + + status = smb_raw_write(p->tree, &io); + if (NT_STATUS_IS_OK(status)) { + return status; + } + + /* make sure it accepted it all */ + if (io.writex.out.nwritten != blob->length) { + return NT_STATUS_UNSUCCESSFUL; + } + + return status; +} -- cgit From 46046aa69be01d4868395b9b52b8bcd22c3859e5 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 4 Nov 2003 09:10:31 +0000 Subject: yipee! we can now do lsaOpenPolicy() via the new interfaces, without using any of the old lsa code (This used to be commit f5bd301ff7befa223a1d761a37ae8f7ce7f1fcd1) --- source4/libcli/raw/rawdcerpc.c | 62 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawdcerpc.c b/source4/libcli/raw/rawdcerpc.c index a6cd75eeaa..6a3275c7a4 100644 --- a/source4/libcli/raw/rawdcerpc.c +++ b/source4/libcli/raw/rawdcerpc.c @@ -22,6 +22,68 @@ #include "includes.h" + +/* + open a rpc connection to a named pipe +*/ +NTSTATUS dcerpc_pipe_open_smb(struct dcerpc_pipe *p, const char *pipe_name) +{ + NTSTATUS status; + char *name = NULL; + union smb_open io; + TALLOC_CTX *mem_ctx; + + asprintf(&name, "\\%s", pipe_name); + if (!name) { + return NT_STATUS_NO_MEMORY; + } + + io.ntcreatex.level = RAW_OPEN_NTCREATEX; + io.ntcreatex.in.flags = 0; + io.ntcreatex.in.root_fid = 0; + io.ntcreatex.in.access_mask = + STD_RIGHT_READ_CONTROL_ACCESS | + SA_RIGHT_FILE_WRITE_ATTRIBUTES | + SA_RIGHT_FILE_WRITE_EA | + GENERIC_RIGHTS_FILE_READ | + GENERIC_RIGHTS_FILE_WRITE; + io.ntcreatex.in.file_attr = 0; + io.ntcreatex.in.alloc_size = 0; + io.ntcreatex.in.share_access = + NTCREATEX_SHARE_ACCESS_READ | + NTCREATEX_SHARE_ACCESS_WRITE; + io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN; + io.ntcreatex.in.create_options = 0; + io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION; + io.ntcreatex.in.security_flags = 0; + io.ntcreatex.in.fname = name; + + mem_ctx = talloc_init("torture_rpc_connection"); + status = smb_raw_open(p->tree, mem_ctx, &io); + free(name); + talloc_destroy(mem_ctx); + + if (!NT_STATUS_IS_OK(status)) { + return status; + } + + p->fnum = io.ntcreatex.out.fnum; + + /* bind to the pipe, using the pipe_name as the key */ + status = dcerpc_bind_byname(p, pipe_name); + + if (!NT_STATUS_IS_OK(status)) { + union smb_close c; + c.close.level = RAW_CLOSE_CLOSE; + c.close.in.fnum = p->fnum; + c.close.in.write_time = 0; + smb_raw_close(p->tree, &c); + } + + return status; +} + + struct cli_request *dcerpc_raw_send(struct dcerpc_pipe *p, DATA_BLOB *blob) { struct smb_trans2 trans; -- cgit From 41304b3c5791be0a5492844a048784c4ef4acfe9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 4 Nov 2003 11:16:07 +0000 Subject: lsa_EnumSids() now works (This used to be commit 25a8692fede323b53240192e5d349b39fe0b7342) --- source4/libcli/raw/rawdcerpc.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawdcerpc.c b/source4/libcli/raw/rawdcerpc.c index 6a3275c7a4..a253e0eb65 100644 --- a/source4/libcli/raw/rawdcerpc.c +++ b/source4/libcli/raw/rawdcerpc.c @@ -59,6 +59,9 @@ NTSTATUS dcerpc_pipe_open_smb(struct dcerpc_pipe *p, const char *pipe_name) io.ntcreatex.in.fname = name; mem_ctx = talloc_init("torture_rpc_connection"); + if (!mem_ctx) { + return NT_STATUS_NO_MEMORY; + } status = smb_raw_open(p->tree, mem_ctx, &io); free(name); talloc_destroy(mem_ctx); -- cgit From c1b3ebb1fa51a8b91e94d48ec272846235de1c03 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 4 Nov 2003 22:42:00 +0000 Subject: fixed some error found by valgrind (This used to be commit ca5f0ccb6cd10d51c96a5cd8e0cd97d50cbb9a73) --- source4/libcli/raw/rawdcerpc.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawdcerpc.c b/source4/libcli/raw/rawdcerpc.c index a253e0eb65..0541200015 100644 --- a/source4/libcli/raw/rawdcerpc.c +++ b/source4/libcli/raw/rawdcerpc.c @@ -105,7 +105,10 @@ struct cli_request *dcerpc_raw_send(struct dcerpc_pipe *p, DATA_BLOB *blob) trans.in.max_param = 0; trans.in.max_data = 0x8000; + trans.in.max_setup = 0; trans.in.setup_count = 2; + trans.in.flags = 0; + trans.in.timeout = 0; trans.in.setup = setup; trans.in.trans_name = "\\PIPE\\"; -- cgit From 4fa0f615f286631820316f8c87dd61eda494e203 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 6 Nov 2003 12:34:04 +0000 Subject: another major bit of restructuring of rpc in Samba4. Mostly moving files around, but also added the first bits of auto-generated code for the lsa pipe. I haven't updated the Makefile to call pidl yet, so for now the code was cut-and-pasted into librpc/ndr/ndr_lsa.c manually (This used to be commit 6b222d3b6541ee74cf8bf3f0913cd444903ca991) --- source4/libcli/raw/rawdcerpc.c | 320 ----------------------------------------- 1 file changed, 320 deletions(-) delete mode 100644 source4/libcli/raw/rawdcerpc.c (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawdcerpc.c b/source4/libcli/raw/rawdcerpc.c deleted file mode 100644 index 0541200015..0000000000 --- a/source4/libcli/raw/rawdcerpc.c +++ /dev/null @@ -1,320 +0,0 @@ -/* - Unix SMB/CIFS implementation. - raw dcerpc operations - - Copyright (C) Tim Potter 2003 - Copyright (C) Andrew Tridgell 2003 - - 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. -*/ - -#include "includes.h" - - -/* - open a rpc connection to a named pipe -*/ -NTSTATUS dcerpc_pipe_open_smb(struct dcerpc_pipe *p, const char *pipe_name) -{ - NTSTATUS status; - char *name = NULL; - union smb_open io; - TALLOC_CTX *mem_ctx; - - asprintf(&name, "\\%s", pipe_name); - if (!name) { - return NT_STATUS_NO_MEMORY; - } - - io.ntcreatex.level = RAW_OPEN_NTCREATEX; - io.ntcreatex.in.flags = 0; - io.ntcreatex.in.root_fid = 0; - io.ntcreatex.in.access_mask = - STD_RIGHT_READ_CONTROL_ACCESS | - SA_RIGHT_FILE_WRITE_ATTRIBUTES | - SA_RIGHT_FILE_WRITE_EA | - GENERIC_RIGHTS_FILE_READ | - GENERIC_RIGHTS_FILE_WRITE; - io.ntcreatex.in.file_attr = 0; - io.ntcreatex.in.alloc_size = 0; - io.ntcreatex.in.share_access = - NTCREATEX_SHARE_ACCESS_READ | - NTCREATEX_SHARE_ACCESS_WRITE; - io.ntcreatex.in.open_disposition = NTCREATEX_DISP_OPEN; - io.ntcreatex.in.create_options = 0; - io.ntcreatex.in.impersonation = NTCREATEX_IMPERSONATION_IMPERSONATION; - io.ntcreatex.in.security_flags = 0; - io.ntcreatex.in.fname = name; - - mem_ctx = talloc_init("torture_rpc_connection"); - if (!mem_ctx) { - return NT_STATUS_NO_MEMORY; - } - status = smb_raw_open(p->tree, mem_ctx, &io); - free(name); - talloc_destroy(mem_ctx); - - if (!NT_STATUS_IS_OK(status)) { - return status; - } - - p->fnum = io.ntcreatex.out.fnum; - - /* bind to the pipe, using the pipe_name as the key */ - status = dcerpc_bind_byname(p, pipe_name); - - if (!NT_STATUS_IS_OK(status)) { - union smb_close c; - c.close.level = RAW_CLOSE_CLOSE; - c.close.in.fnum = p->fnum; - c.close.in.write_time = 0; - smb_raw_close(p->tree, &c); - } - - return status; -} - - -struct cli_request *dcerpc_raw_send(struct dcerpc_pipe *p, DATA_BLOB *blob) -{ - struct smb_trans2 trans; - uint16 setup[2]; - struct cli_request *req; - TALLOC_CTX *mem_ctx; - - mem_ctx = talloc_init("dcerpc_raw_send"); - if (!mem_ctx) return NULL; - - trans.in.data = *blob; - trans.in.params = data_blob(NULL, 0); - - setup[0] = TRANSACT_DCERPCCMD; - setup[1] = p->fnum; - - trans.in.max_param = 0; - trans.in.max_data = 0x8000; - trans.in.max_setup = 0; - trans.in.setup_count = 2; - trans.in.flags = 0; - trans.in.timeout = 0; - trans.in.setup = setup; - trans.in.trans_name = "\\PIPE\\"; - - req = smb_raw_trans_send(p->tree, &trans); - - talloc_destroy(mem_ctx); - - return req; -} - - -NTSTATUS dcerpc_raw_recv(struct dcerpc_pipe *p, - struct cli_request *req, - TALLOC_CTX *mem_ctx, - DATA_BLOB *blob) -{ - struct smb_trans2 trans; - NTSTATUS status; - uint16 frag_length; - DATA_BLOB payload; - - status = smb_raw_trans_recv(req, mem_ctx, &trans); - /* STATUS_BUFFER_OVERFLOW means that there is more data - available via SMBreadX */ - if (!NT_STATUS_IS_OK(status) && - !NT_STATUS_EQUAL(status, STATUS_BUFFER_OVERFLOW)) { - return status; - } - - payload = trans.out.data; - - if (trans.out.data.length < 16 || - !NT_STATUS_EQUAL(status, STATUS_BUFFER_OVERFLOW)) { - goto done; - } - - /* we might have recieved a partial fragment, in which case we - need to pull the rest of it */ - frag_length = SVAL(payload.data, 8); - if (frag_length <= payload.length) { - goto done; - } - - /* make sure the payload can hold the whole fragment */ - payload.data = talloc_realloc(mem_ctx, payload.data, frag_length); - if (!payload.data) { - return NT_STATUS_NO_MEMORY; - } - - /* the rest of the data is available via SMBreadX */ - while (frag_length > payload.length) { - uint32 n; - union smb_read io; - - n = frag_length - payload.length; - if (n > 0xFF00) { - n = 0xFF00; - } - - io.generic.level = RAW_READ_READX; - io.readx.in.fnum = p->fnum; - io.readx.in.mincnt = n; - io.readx.in.maxcnt = n; - io.readx.in.offset = 0; - io.readx.in.remaining = 0; - io.readx.out.data = payload.data + payload.length; - status = smb_raw_read(p->tree, &io); - if (!NT_STATUS_IS_OK(status) && - !NT_STATUS_EQUAL(status, STATUS_BUFFER_OVERFLOW)) { - break; - } - - n = io.readx.out.nread; - if (n == 0) { - status = NT_STATUS_UNSUCCESSFUL; - break; - } - - payload.length += n; - - /* if the SMBreadX returns NT_STATUS_OK then there - isn't any more data to be read */ - if (NT_STATUS_IS_OK(status)) { - break; - } - } - -done: - if (blob) { - *blob = payload; - } - - return status; -} - -NTSTATUS dcerpc_raw_packet(struct dcerpc_pipe *p, - TALLOC_CTX *mem_ctx, - DATA_BLOB *request_blob, - DATA_BLOB *reply_blob) -{ - struct cli_request *req; - req = dcerpc_raw_send(p, request_blob); - return dcerpc_raw_recv(p, req, mem_ctx, reply_blob); -} - - -/* - retrieve a secondary pdu from a pipe -*/ -NTSTATUS dcerpc_raw_packet_secondary(struct dcerpc_pipe *p, - TALLOC_CTX *mem_ctx, - DATA_BLOB *blob) -{ - union smb_read io; - uint32 n = 0x2000; - uint32 frag_length; - NTSTATUS status; - - *blob = data_blob_talloc(mem_ctx, NULL, n); - if (!blob->data) { - return NT_STATUS_NO_MEMORY; - } - - io.generic.level = RAW_READ_READX; - io.readx.in.fnum = p->fnum; - io.readx.in.mincnt = n; - io.readx.in.maxcnt = n; - io.readx.in.offset = 0; - io.readx.in.remaining = 0; - io.readx.out.data = blob->data; - - status = smb_raw_read(p->tree, &io); - if (!NT_STATUS_IS_OK(status) && - !NT_STATUS_EQUAL(status, STATUS_BUFFER_OVERFLOW)) { - return status; - } - - blob->length = io.readx.out.nread; - - if (blob->length < 16) { - return status; - } - - frag_length = SVAL(blob->data, 8); - if (frag_length <= blob->length) { - return status; - } - - blob->data = talloc_realloc(mem_ctx, blob->data, frag_length); - if (!blob->data) { - return NT_STATUS_NO_MEMORY; - } - - while (frag_length > blob->length && - NT_STATUS_EQUAL(status, STATUS_BUFFER_OVERFLOW)) { - - n = frag_length - blob->length; - if (n > 0xFF00) { - n = 0xFF00; - } - - io.readx.in.mincnt = n; - io.readx.in.maxcnt = n; - io.readx.out.data = blob->data + blob->length; - status = smb_raw_read(p->tree, &io); - - if (!NT_STATUS_IS_OK(status) && - !NT_STATUS_EQUAL(status, STATUS_BUFFER_OVERFLOW)) { - return status; - } - - n = io.readx.out.nread; - blob->length += n; - } - - return status; -} - - -/* - send an initial pdu in a multi-pdu sequence -*/ -NTSTATUS dcerpc_raw_packet_initial(struct dcerpc_pipe *p, - TALLOC_CTX *mem_ctx, - DATA_BLOB *blob) -{ - union smb_write io; - NTSTATUS status; - - io.generic.level = RAW_WRITE_WRITEX; - io.writex.in.fnum = p->fnum; - io.writex.in.offset = 0; - io.writex.in.wmode = PIPE_START_MESSAGE; - io.writex.in.remaining = blob->length; - io.writex.in.count = blob->length; - io.writex.in.data = blob->data; - - status = smb_raw_write(p->tree, &io); - if (NT_STATUS_IS_OK(status)) { - return status; - } - - /* make sure it accepted it all */ - if (io.writex.out.nwritten != blob->length) { - return NT_STATUS_UNSUCCESSFUL; - } - - return status; -} -- cgit From 7d212460a5c00b4039440c2db0dde56e7d519d66 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 8 Nov 2003 11:21:57 +0000 Subject: - corrected some lsa idl - updated lsa parse code from pidl (This used to be commit 3983b2aee77b0e093847bfc02e02b83ab281f5dd) --- source4/libcli/raw/rawacl.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawacl.c b/source4/libcli/raw/rawacl.c index c45152381d..067189d987 100644 --- a/source4/libcli/raw/rawacl.c +++ b/source4/libcli/raw/rawacl.c @@ -78,7 +78,11 @@ NTSTATUS smb_raw_query_secdesc_recv(struct cli_request *req, return NT_STATUS_INVALID_PARAMETER; } - status = ndr_pull_security_descriptor(ndr, &query->out.sd); + query->out.sd = talloc(mem_ctx, sizeof(query->out.sd)); + if (!query->out.sd) { + return NT_STATUS_NO_MEMORY; + } + status = ndr_pull_security_descriptor(ndr, query->out.sd); return NT_STATUS_OK; } -- cgit From bf48b6e69a638dc78ab119424e27adc0ccc6c610 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 17 Nov 2003 03:38:13 +0000 Subject: added OpenPrinter and a test function. Note that the Samba3 structure for OpenPrinter was wrong. (This used to be commit 186ddbbf8774d0960852ea9186c8e4e6f7be7a0f) --- source4/libcli/raw/clitransport.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 80bb1e301f..2d614cc3bd 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -42,6 +42,8 @@ struct cli_transport *cli_transport_init(struct cli_socket *sock) cli_null_set_signing(transport); transport->socket->reference_count++; + ZERO_STRUCT(transport->called); + return transport; } @@ -71,6 +73,10 @@ BOOL cli_transport_connect(struct cli_transport *transport, int len = NBT_HDR_SIZE; struct cli_request *req; + if (called) { + transport->called = *called; + } + /* 445 doesn't have session request */ if (transport->socket->port == 445) { return True; -- cgit From 59df3ce5b5c5b484793a0e16faeb581ef343e167 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 17 Nov 2003 06:27:45 +0000 Subject: security descriptors are no longer a "special" type, they are handled using the [relative] property this also fixes level3 of PrinterInfo (a relative secdesc) (This used to be commit d5a15257fdd5f6cfe2706765a7c29f623ec1c6f8) --- source4/libcli/raw/rawacl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawacl.c b/source4/libcli/raw/rawacl.c index 067189d987..cfc086c7ce 100644 --- a/source4/libcli/raw/rawacl.c +++ b/source4/libcli/raw/rawacl.c @@ -82,7 +82,7 @@ NTSTATUS smb_raw_query_secdesc_recv(struct cli_request *req, if (!query->out.sd) { return NT_STATUS_NO_MEMORY; } - status = ndr_pull_security_descriptor(ndr, query->out.sd); + status = ndr_pull_security_descriptor(ndr, NDR_SCALARS|NDR_BUFFERS, query->out.sd); return NT_STATUS_OK; } -- cgit From e1e98ab0496ae38b2d68d50133ec1da532f02757 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 19 Nov 2003 23:17:55 +0000 Subject: updated copyright year (This used to be commit 4dcc06d04c67c6e063c5b2a88f693423c77f342d) --- source4/libcli/raw/clisocket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index f0e05085c4..6ccdeef366 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -1,7 +1,7 @@ /* Unix SMB/CIFS implementation. SMB client socket context management functions - Copyright (C) Andrew Tridgell 1994-1998 + Copyright (C) Andrew Tridgell 1994-2003 Copyright (C) James Myers 2003 This program is free software; you can redistribute it and/or modify -- cgit From 940ce958a6914fb9b70de3cf95a0c062063e2253 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 20 Nov 2003 00:36:10 +0000 Subject: make the socket send code a little clearer (This used to be commit 48028fbb856ea7ee642f36ba9ed0d5815763f52b) --- source4/libcli/raw/rawrequest.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 139f031178..4191d3775e 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -269,13 +269,17 @@ static void cli_req_grow_data(struct cli_request *req, unsigned new_size) */ BOOL cli_request_send(struct cli_request *req) { + uint_t ret; + if (IVAL(req->out.buffer, 0) == 0) { _smb_setlen(req->out.buffer, req->out.size - NBT_HDR_SIZE); } cli_request_calculate_sign_mac(req); - if (req->out.size != cli_sock_write(req->transport->socket, req->out.buffer, req->out.size)) { + ret = cli_sock_write(req->transport->socket, req->out.buffer, req->out.size); + + if (req->out.size != ret) { req->transport->error.etype = ETYPE_SOCKET; req->transport->error.e.socket_error = SOCKET_WRITE_ERROR; DEBUG(0,("Error writing %d bytes to server - %s\n", -- cgit From 3e0501082cc5e5715dd315f890560a5759331df3 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 26 Nov 2003 21:57:29 +0000 Subject: fixed default port handling pointed out by Tom Jansen (This used to be commit 8246e6ca0bd0eaa92de602db46a119d368e93391) --- source4/libcli/raw/clisocket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 6ccdeef366..f596cba854 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -41,7 +41,7 @@ struct cli_socket *cli_sock_init(void) sock->mem_ctx = mem_ctx; sock->fd = -1; - sock->port = 445; + sock->port = 0; /* 20 second default timeout */ sock->timeout = 20000; -- cgit From 926240428c0646aabb13539745940b61a7cf44a9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 4 Dec 2003 02:03:06 +0000 Subject: * patch based on work by Jim Myers to unify the ioctl handling to be more like the other major SMB functions * added SMBntrename code (This used to be commit f2d3dc9893fa0e089c407fa16ce9ff13587e70cd) --- source4/libcli/raw/rawioctl.c | 105 ++++++++++++++++++++++++++++-------------- 1 file changed, 71 insertions(+), 34 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawioctl.c b/source4/libcli/raw/rawioctl.c index 506bddd497..2ea2cabb89 100644 --- a/source4/libcli/raw/rawioctl.c +++ b/source4/libcli/raw/rawioctl.c @@ -2,6 +2,7 @@ Unix SMB/CIFS implementation. client file operations Copyright (C) Andrew Tridgell 2003 + Copyright (C) James J Myers 2003 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 @@ -26,16 +27,17 @@ } while (0) /* - send a raw ioctl - async send + send a raw smb ioctl - async send */ -struct cli_request *smb_raw_ioctl_send(struct cli_tree *tree, struct smb_ioctl *parms) +static struct cli_request *smb_raw_smbioctl_send(struct cli_tree *tree, + union smb_ioctl *parms) { struct cli_request *req; SETUP_REQUEST(SMBioctl, 3, 0); - SSVAL(req->out.vwv, VWV(0), parms->in.fnum); - SIVAL(req->out.vwv, VWV(1), parms->in.request); + SSVAL(req->out.vwv, VWV(0), parms->ioctl.in.fnum); + SIVAL(req->out.vwv, VWV(1), parms->ioctl.in.request); if (!cli_request_send(req)) { cli_request_destroy(req); @@ -46,36 +48,28 @@ struct cli_request *smb_raw_ioctl_send(struct cli_tree *tree, struct smb_ioctl * } /* - send a raw ioctl - async recv + send a raw smb ioctl - async recv */ -NTSTATUS smb_raw_ioctl_recv(struct cli_request *req, TALLOC_CTX *mem_ctx, struct smb_ioctl *parms) +static NTSTATUS smb_raw_smbioctl_recv(struct cli_request *req, + TALLOC_CTX *mem_ctx, + union smb_ioctl *parms) { if (!cli_request_receive(req) || cli_request_is_error(req)) { return cli_request_destroy(req); } - parms->out.blob = cli_req_pull_blob(req, mem_ctx, req->in.data, -1); + parms->ioctl.out.blob = cli_req_pull_blob(req, mem_ctx, req->in.data, -1); return cli_request_destroy(req); } -/* - send a raw ioctl - sync interface -*/ -NTSTATUS smb_raw_ioctl(struct cli_tree *tree, TALLOC_CTX *mem_ctx, struct smb_ioctl *parms) -{ - struct cli_request *req = smb_raw_ioctl_send(tree, parms); - return smb_raw_ioctl_recv(req, mem_ctx, parms); -} - - /**************************************************************************** NT ioctl (async send) ****************************************************************************/ -struct cli_request *smb_raw_ntioctl_send(struct cli_tree *tree, - struct smb_ntioctl *parms) +static struct cli_request *smb_raw_ntioctl_send(struct cli_tree *tree, + union smb_ioctl *parms) { struct smb_nttrans nt; uint16 setup[4]; @@ -85,10 +79,10 @@ struct cli_request *smb_raw_ntioctl_send(struct cli_tree *tree, nt.in.max_data = 0; nt.in.setup_count = 4; nt.in.setup = setup; - SIVAL(setup, 0, parms->in.function); - SSVAL(setup, 4, parms->in.fnum); - SCVAL(setup, 6, parms->in.fsctl); - SCVAL(setup, 7, parms->in.filter); + SIVAL(setup, 0, parms->ntioctl.in.function); + SSVAL(setup, 4, parms->ntioctl.in.fnum); + SCVAL(setup, 6, parms->ntioctl.in.fsctl); + SCVAL(setup, 7, parms->ntioctl.in.filter); nt.in.function = NT_TRANSACT_IOCTL; nt.in.params = data_blob(NULL, 0); nt.in.data = data_blob(NULL, 0); @@ -99,20 +93,63 @@ struct cli_request *smb_raw_ntioctl_send(struct cli_tree *tree, /**************************************************************************** NT ioctl (async recv) ****************************************************************************/ -NTSTATUS smb_raw_ntioctl_recv(struct cli_request *req, - struct smb_ntioctl *parms) +static NTSTATUS smb_raw_ntioctl_recv(struct cli_request *req, + TALLOC_CTX *mem_ctx, + union smb_ioctl *parms) { - struct smb_nttrans nt; + if (!cli_request_receive(req) || + cli_request_is_error(req)) { + return cli_request_destroy(req); + } - return smb_raw_nttrans_recv(req, req->mem_ctx, &nt); + parms->ntioctl.out.blob = cli_req_pull_blob(req, mem_ctx, req->in.data, -1); + return cli_request_destroy(req); } -/**************************************************************************** -NT ioctl (sync interface) -****************************************************************************/ -NTSTATUS smb_raw_ntioctl(struct cli_tree *tree, - struct smb_ntioctl *parms) + +/* + send a raw ioctl - async send +*/ +struct cli_request *smb_raw_ioctl_send(struct cli_tree *tree, union smb_ioctl *parms) +{ + struct cli_request *req = NULL; + + switch (parms->generic.level) { + case RAW_IOCTL_IOCTL: + req = smb_raw_smbioctl_send(tree, parms); + break; + + case RAW_IOCTL_NTIOCTL: + req = smb_raw_ntioctl_send(tree, parms); + break; + } + + return req; +} + +/* + recv a raw ioctl - async recv +*/ +NTSTATUS smb_raw_ioctl_recv(struct cli_request *req, + TALLOC_CTX *mem_ctx, union smb_ioctl *parms) { - struct cli_request *req = smb_raw_ntioctl_send(tree, parms); - return smb_raw_ntioctl_recv(req, parms); + switch (parms->generic.level) { + case RAW_IOCTL_IOCTL: + return smb_raw_smbioctl_recv(req, mem_ctx, parms); + + case RAW_IOCTL_NTIOCTL: + return smb_raw_ntioctl_recv(req, mem_ctx, parms); + } + return NT_STATUS_INVALID_LEVEL; +} + +/* + send a raw ioctl - sync interface +*/ +NTSTATUS smb_raw_ioctl(struct cli_tree *tree, + TALLOC_CTX *mem_ctx, union smb_ioctl *parms) +{ + struct cli_request *req; + req = smb_raw_ioctl_send(tree, parms); + return smb_raw_ioctl_recv(req, mem_ctx, parms); } -- cgit From fcc4efd1ea637c810eed8444080b87d7f92c837a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 11 Dec 2003 09:07:45 +0000 Subject: the next step in the dcerpc server code. Added the link between the IPC IO routines and the dcerpc endpoint servers. (This used to be commit 4929c53bc8dddda8a763fdfbcf81a79776d01113) --- source4/libcli/raw/rawtrans.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawtrans.c b/source4/libcli/raw/rawtrans.c index f31b1eaf7e..f7a3b4aa43 100644 --- a/source4/libcli/raw/rawtrans.c +++ b/source4/libcli/raw/rawtrans.c @@ -233,6 +233,11 @@ struct cli_request *smb_raw_trans_send_backend(struct cli_tree *tree, /* make sure we don't leak data via the padding */ memset(req->out.data, 0, padding); + if (command == SMBtrans && parms->in.trans_name) { + namelen = cli_req_append_string(req, parms->in.trans_name, + STR_TERMINATE); + } + /* primary request */ SSVAL(req->out.vwv,VWV(0),parms->in.params.length); SSVAL(req->out.vwv,VWV(1),parms->in.data.length); @@ -243,9 +248,6 @@ struct cli_request *smb_raw_trans_send_backend(struct cli_tree *tree, SIVAL(req->out.vwv,VWV(6),parms->in.timeout); SSVAL(req->out.vwv,VWV(8),0); /* reserved */ SSVAL(req->out.vwv,VWV(9),parms->in.params.length); - if (command == SMBtrans && parms->in.trans_name) - namelen = cli_req_append_string(req, parms->in.trans_name, - STR_TERMINATE); SSVAL(req->out.vwv,VWV(10),PTR_DIFF(outparam,req->out.hdr)+namelen); SSVAL(req->out.vwv,VWV(11),parms->in.data.length); SSVAL(req->out.vwv,VWV(12),PTR_DIFF(outdata,req->out.hdr)+namelen); -- cgit From 24c22aef90d8534ee2d016b37b2b302f1367d106 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 16 Dec 2003 09:02:58 +0000 Subject: a fairly large commit! This adds support for bigendian rpc in the client. I have installed SUN pcnetlink locally and am using it to test the samba4 rpc code. This allows us to easily find places where we have stuffed up the types (such as 2 uint16 versus a uint32), as testing both big-endian and little-endian easily shows which is correct. I have now used this to fix several bugs like that in the samba4 IDL. In order to make this work I also had to redefine a GUID as a true structure, not a blob. From the pcnetlink wire it is clear that it is indeed defined as a structure (the byte order changes). This required changing lots of Samba code to use a GUID as a structure. I also had to fix the if_version code in dcerpc syntax IDs, as it turns out they are a single uint32 not two uint16s. The big-endian support is a bit ugly at the moment, and breaks the layering in some places. More work is needed, especially on the server side. (This used to be commit bb1af644a5a7b188290ce36232f255da0e5d66d2) --- source4/libcli/raw/rawfsinfo.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawfsinfo.c b/source4/libcli/raw/rawfsinfo.c index 362063bfc5..85daf654d3 100644 --- a/source4/libcli/raw/rawfsinfo.c +++ b/source4/libcli/raw/rawfsinfo.c @@ -259,7 +259,8 @@ NTSTATUS smb_raw_fsinfo_recv(struct cli_request *req, case RAW_QFS_OBJECTID_INFORMATION: QFS_CHECK_SIZE(64); - memcpy(fsinfo->objectid_information.out.guid.info, blob.data, GUID_SIZE); + status = ndr_pull_struct_blob(&blob, mem_ctx, &fsinfo->objectid_information.out.guid, + (ndr_pull_flags_fn_t)ndr_pull_GUID); for (i=0;i<6;i++) { fsinfo->objectid_information.out.unknown[i] = BVAL(blob.data, 16 + i*8); } -- cgit From 7db3bbc0482789efd68cd043459a1822a439f4da Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 2 Jan 2004 01:04:59 +0000 Subject: Autodetect service_type in cli_tree_full_connection() if the caller passes in NULL. (This used to be commit b63ebaa770940a276ab63583a13d8cc349b6efe6) --- source4/libcli/raw/clitree.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index 1e9104308e..1114c8a9c5 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -268,6 +268,12 @@ NTSTATUS cli_tree_full_connection(struct cli_tree **ret_tree, tcon.tconx.in.flags = 0; tcon.tconx.in.password = data_blob(NULL, 0); asprintf(&tcon.tconx.in.path, "\\\\%s\\%s", dest_host, service); + if (!service_type) { + if (strequal(service, "IPC$")) + service_type = "IPC"; + else + service_type = "?????"; + } tcon.tconx.in.device = service_type; status = smb_tree_connect(tree, mem_ctx, &tcon); -- cgit From ff4a1461684bcf57da70067e4d40b0c5e183eed7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 15 Jan 2004 23:19:07 +0000 Subject: * fixed a segv when -U is not used in smbtorture. * fixed the handling of anonymous logins (This used to be commit 7cbc4ad8710ad33387145bfc9974d0ed4b0fb231) --- source4/libcli/raw/clisession.c | 12 +++++++++--- source4/libcli/raw/clitree.c | 12 +++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index 9d154e10cd..c5d4888089 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -272,7 +272,10 @@ static NTSTATUS smb_raw_session_setup_generic_old(struct cli_session *session, s2.old.in.os = "Unix"; s2.old.in.lanman = "Samba"; - if (session->transport->negotiate.sec_mode & NEGOTIATE_SECURITY_CHALLENGE_RESPONSE) { + if (!parms->generic.in.password) { + s2.old.in.password = data_blob(NULL, 0); + } else if (session->transport->negotiate.sec_mode & + NEGOTIATE_SECURITY_CHALLENGE_RESPONSE) { s2.old.in.password = lanman_blob(parms->generic.in.password, session->transport->negotiate.secblob); } else { @@ -318,8 +321,11 @@ static NTSTATUS smb_raw_session_setup_generic_nt1(struct cli_session *session, s2.nt1.in.os = "Unix"; s2.nt1.in.lanman = "Samba"; - if (s2.nt1.in.user[0] && - (session->transport->negotiate.sec_mode & NEGOTIATE_SECURITY_CHALLENGE_RESPONSE)) { + if (!parms->generic.in.password) { + s2.nt1.in.password1 = data_blob(NULL, 0); + s2.nt1.in.password2 = data_blob(NULL, 0); + } else if (session->transport->negotiate.sec_mode & + NEGOTIATE_SECURITY_CHALLENGE_RESPONSE) { s2.nt1.in.password1 = lanman_blob(parms->generic.in.password, session->transport->negotiate.secblob); s2.nt1.in.password2 = nt_blob(parms->generic.in.password, diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index 1114c8a9c5..b35bf67c94 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -238,9 +238,15 @@ NTSTATUS cli_tree_full_connection(struct cli_tree **ret_tree, setup.generic.in.capabilities = CAP_UNICODE | CAP_STATUS32 | CAP_LARGE_FILES | CAP_NT_SMBS | CAP_LEVEL_II_OPLOCKS | CAP_W2K_SMBS | CAP_LARGE_READX | CAP_LARGE_WRITEX; - setup.generic.in.password = password; - setup.generic.in.user = user; - setup.generic.in.domain = domain; + if (!user || !user[0]) { + setup.generic.in.password = NULL; + setup.generic.in.user = ""; + setup.generic.in.domain = ""; + } else { + setup.generic.in.password = password; + setup.generic.in.user = user; + setup.generic.in.domain = domain; + } mem_ctx = talloc_init("tcon"); if (!mem_ctx) { -- cgit From 670ccc7d643b8e04743542b4336f6830ac065463 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sun, 1 Feb 2004 11:26:25 +0000 Subject: merge: ldap and krb5 configure tests libads/*.c and libcli/raw/clikrb5.c from 3.0 metze (This used to be commit 64b5bfcd73d7626d6f687a641b11e64821144df7) --- source4/libcli/raw/clikrb5.c | 96 ++++++++++++++++++++++++++---------------- source4/libcli/raw/clispnego.c | 20 ++++++--- 2 files changed, 72 insertions(+), 44 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clikrb5.c b/source4/libcli/raw/clikrb5.c index 24da1455de..1d9c02f7f4 100644 --- a/source4/libcli/raw/clikrb5.c +++ b/source4/libcli/raw/clikrb5.c @@ -97,7 +97,9 @@ return ret; } krb5_use_enctype(context, &eblock, enctype); - return krb5_string_to_key(context, &eblock, key, password, &salt); + ret = krb5_string_to_key(context, &eblock, key, password, &salt); + SAFE_FREE(salt.data); + return ret; } #elif defined(HAVE_KRB5_GET_PW_SALT) && defined(HAVE_KRB5_STRING_TO_KEY_SALT) int create_kerberos_key_from_string(krb5_context context, @@ -235,12 +237,12 @@ krb5_error_code get_kerberos_allowed_etypes(krb5_context context, /* we can't use krb5_mk_req because w2k wants the service to be in a particular format */ -static krb5_error_code krb5_mk_req2(krb5_context context, - krb5_auth_context *auth_context, - const krb5_flags ap_req_options, - const char *principal, - krb5_ccache ccache, - krb5_data *outbuf) +static krb5_error_code ads_krb5_mk_req(krb5_context context, + krb5_auth_context *auth_context, + const krb5_flags ap_req_options, + const char *principal, + krb5_ccache ccache, + krb5_data *outbuf) { krb5_error_code retval; krb5_principal server; @@ -255,7 +257,7 @@ static krb5_error_code krb5_mk_req2(krb5_context context, } /* obtain ticket & session key */ - memset((char *)&creds, 0, sizeof(creds)); + ZERO_STRUCT(creds); if ((retval = krb5_copy_principal(context, server, &creds.server))) { DEBUG(1,("krb5_copy_principal failed (%s)\n", error_message(retval))); @@ -305,14 +307,14 @@ cleanup_princ: /* get a kerberos5 ticket for the given service */ -DATA_BLOB krb5_get_ticket(const char *principal, time_t time_offset) +int cli_krb5_get_ticket(const char *principal, time_t time_offset, + DATA_BLOB *ticket, DATA_BLOB *session_key_krb5) { krb5_error_code retval; krb5_data packet; krb5_ccache ccdef; krb5_context context; krb5_auth_context auth_context = NULL; - DATA_BLOB ret; krb5_enctype enc_types[] = { #ifdef ENCTYPE_ARCFOUR_HMAC ENCTYPE_ARCFOUR_HMAC, @@ -344,56 +346,76 @@ DATA_BLOB krb5_get_ticket(const char *principal, time_t time_offset) goto failed; } - if ((retval = krb5_mk_req2(context, - &auth_context, - 0, - principal, - ccdef, &packet))) { + if ((retval = ads_krb5_mk_req(context, + &auth_context, + AP_OPTS_USE_SUBKEY, + principal, + ccdef, &packet))) { goto failed; } - ret = data_blob(packet.data, packet.length); + get_krb5_smb_session_key(context, auth_context, session_key_krb5, False); + + *ticket = data_blob(packet.data, packet.length); + /* Hmm, heimdal dooesn't have this - what's the correct call? */ -/* krb5_free_data_contents(context, &packet); */ - krb5_free_context(context); - return ret; +#ifdef HAVE_KRB5_FREE_DATA_CONTENTS + krb5_free_data_contents(context, &packet); +#endif failed: if ( context ) krb5_free_context(context); - return data_blob(NULL, 0); + return retval; } - BOOL krb5_get_smb_session_key(krb5_context context, krb5_auth_context auth_context, uint8 session_key[16]) + BOOL get_krb5_smb_session_key(krb5_context context, krb5_auth_context auth_context, DATA_BLOB *session_key, BOOL remote) { -#ifdef ENCTYPE_ARCFOUR_HMAC krb5_keyblock *skey; -#endif + krb5_error_code err; BOOL ret = False; memset(session_key, 0, 16); -#ifdef ENCTYPE_ARCFOUR_HMAC - if (krb5_auth_con_getremotesubkey(context, auth_context, &skey) == 0 && skey != NULL) { - if (KRB5_KEY_TYPE(skey) == - ENCTYPE_ARCFOUR_HMAC - && KRB5_KEY_LENGTH(skey) == 16) { - memcpy(session_key, KRB5_KEY_DATA(skey), KRB5_KEY_LENGTH(skey)); - ret = True; - } + if (remote) + err = krb5_auth_con_getremotesubkey(context, auth_context, &skey); + else + err = krb5_auth_con_getlocalsubkey(context, auth_context, &skey); + if (err == 0 && skey != NULL) { + DEBUG(10, ("Got KRB5 session key of length %d\n", KRB5_KEY_LENGTH(skey))); + *session_key = data_blob(KRB5_KEY_DATA(skey), KRB5_KEY_LENGTH(skey)); + dump_data_pw("KRB5 Session Key:\n", session_key->data, session_key->length); + + ret = True; + krb5_free_keyblock(context, skey); + } else { + DEBUG(10, ("KRB5 error getting session key %d\n", err)); } -#endif /* ENCTYPE_ARCFOUR_HMAC */ return ret; } + + +#if defined(HAVE_KRB5_PRINCIPAL_GET_COMP_STRING) && !defined(HAVE_KRB5_PRINC_COMPONENT) + const krb5_data *krb5_princ_component(krb5_context context, krb5_principal principal, int i ) +{ + static krb5_data kdata; + + kdata.data = krb5_principal_get_comp_string(context, principal, i); + kdata.length = strlen(kdata.data); + return &kdata; +} +#endif + #else /* HAVE_KRB5 */ - /* this saves a few linking headaches */ -DATA_BLOB krb5_get_ticket(const char *principal, time_t time_offset) - { +/* this saves a few linking headaches */ +int cli_krb5_get_ticket(const char *principal, time_t time_offset, + DATA_BLOB *ticket, DATA_BLOB *session_key_krb5) +{ DEBUG(0,("NO KERBEROS SUPPORT\n")); - return data_blob(NULL, 0); - } + return 1; +} #endif diff --git a/source4/libcli/raw/clispnego.c b/source4/libcli/raw/clispnego.c index 53f7eb6e7d..e6cadc466c 100644 --- a/source4/libcli/raw/clispnego.c +++ b/source4/libcli/raw/clispnego.c @@ -2,7 +2,7 @@ Unix SMB/CIFS implementation. simple kerberos5/SPNEGO routines Copyright (C) Andrew Tridgell 2001 - Copyright (C) Jim McDonough 2002 + Copyright (C) Jim McDonough 2002 Copyright (C) Luke Howard 2003 This program is free software; you can redistribute it and/or modify @@ -323,24 +323,30 @@ BOOL spnego_parse_krb5_wrap(DATA_BLOB blob, DATA_BLOB *ticket, uint8 tok_id[2]) generate a SPNEGO negTokenTarg packet, ready for a EXTENDED_SECURITY kerberos session setup */ -DATA_BLOB spnego_gen_negTokenTarg(const char *principal, int time_offset) +int spnego_gen_negTokenTarg(const char *principal, int time_offset, + DATA_BLOB *targ, + DATA_BLOB *session_key_krb5) { - DATA_BLOB tkt, tkt_wrapped, targ; + int retval; + DATA_BLOB tkt, tkt_wrapped; const char *krb_mechs[] = {OID_KERBEROS5_OLD, OID_NTLMSSP, NULL}; - /* get a kerberos ticket for the service */ - tkt = krb5_get_ticket(principal, time_offset); + /* get a kerberos ticket for the service and extract the session key */ + retval = cli_krb5_get_ticket(principal, time_offset, &tkt, session_key_krb5); + + if (retval) + return retval; /* wrap that up in a nice GSS-API wrapping */ tkt_wrapped = spnego_gen_krb5_wrap(tkt, TOK_ID_KRB_AP_REQ); /* and wrap that in a shiny SPNEGO wrapper */ - targ = gen_negTokenTarg(krb_mechs, tkt_wrapped); + *targ = gen_negTokenTarg(krb_mechs, tkt_wrapped); data_blob_free(&tkt_wrapped); data_blob_free(&tkt); - return targ; + return retval; } -- cgit From 6c7e231773ec83c0ec31df51866ad5765e593100 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 21 Feb 2004 04:02:00 +0000 Subject: fixed a problem with the smb client code spinning when the connection is lost. We now close the cli_transport when there is a socket io error (This used to be commit 138cb5f2f5f8ce1479ac687d18e6a0e355e55b7f) --- source4/libcli/raw/rawrequest.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 4191d3775e..2b84345abb 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -309,7 +309,11 @@ BOOL cli_request_receive(struct cli_request *req) return False; } - cli_request_receive_next(req->transport); + if (!cli_request_receive_next(req->transport)) { + cli_transport_close(req->transport); + req->status = NT_STATUS_UNEXPECTED_NETWORK_ERROR; + return False; + } } return True; -- cgit From 14591dc0eaa8751e8eb982d4157862e8ab8f2841 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 8 Mar 2004 07:11:13 +0000 Subject: fixed two writex client bugs - always use the 14 word writex varient even for small transfers as long as large offsets are negotiated (this matches windows behaviour) - make sure we fill in the top 16 bits of the count for large writex calls (This used to be commit 9ea20d0c9a1cb4800f3f54195cbbe70c98c8e423) --- source4/libcli/raw/rawreadwrite.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawreadwrite.c b/source4/libcli/raw/rawreadwrite.c index 84c7e3c00f..3aa95c35aa 100644 --- a/source4/libcli/raw/rawreadwrite.c +++ b/source4/libcli/raw/rawreadwrite.c @@ -40,7 +40,7 @@ struct cli_request *smb_raw_read_send(struct cli_tree *tree, union smb_read *par return NULL; case RAW_READ_READBRAW: - if (parms->readbraw.in.offset >= 0x80000000) { + if (tree->session->transport->negotiate.capabilities & CAP_LARGE_FILES) { bigoffset = True; } SETUP_REQUEST(SMBreadbraw, bigoffset? 10:8, 0); @@ -72,7 +72,7 @@ struct cli_request *smb_raw_read_send(struct cli_tree *tree, union smb_read *par break; case RAW_READ_READX: - if (parms->readx.in.offset >= 0x80000000) { + if (tree->session->transport->negotiate.capabilities & CAP_LARGE_FILES) { bigoffset = True; } SETUP_REQUEST(SMBreadX, bigoffset ? 12 : 10, 0); @@ -232,7 +232,7 @@ struct cli_request *smb_raw_write_send(struct cli_tree *tree, union smb_write *p break; case RAW_WRITE_WRITEX: - if (parms->writex.in.offset >= 0x80000000) { + if (tree->session->transport->negotiate.capabilities & CAP_LARGE_FILES) { bigoffset = True; } SETUP_REQUEST(SMBwriteX, bigoffset ? 14 : 12, parms->writex.in.count); @@ -243,7 +243,7 @@ struct cli_request *smb_raw_write_send(struct cli_tree *tree, union smb_write *p SIVAL(req->out.vwv, VWV(5), 0); /* reserved */ SSVAL(req->out.vwv, VWV(7), parms->writex.in.wmode); SSVAL(req->out.vwv, VWV(8), parms->writex.in.remaining); - SSVAL(req->out.vwv, VWV(9), 0); /* reserved */ + SSVAL(req->out.vwv, VWV(9), parms->writex.in.count>>16); SSVAL(req->out.vwv, VWV(10), parms->writex.in.count); SSVAL(req->out.vwv, VWV(11), PTR_DIFF(req->out.data, req->out.hdr)); if (bigoffset) { -- cgit From f169d83a8b707d6d480c456bf4e4ca7c85dadbae Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 25 Mar 2004 02:41:19 +0000 Subject: fixed the handling of level II oplocks in samba4, especially when acting as a cifs redirectory (using the cifs backend) (This used to be commit 06a8100e6a2f3f079af5b6ec32d87d1d25f56c3c) --- source4/libcli/raw/clioplock.c | 3 ++- source4/libcli/raw/rawrequest.c | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clioplock.c b/source4/libcli/raw/clioplock.c index 8f69716bda..f27bf937ce 100644 --- a/source4/libcli/raw/clioplock.c +++ b/source4/libcli/raw/clioplock.c @@ -33,7 +33,8 @@ BOOL cli_oplock_ack(struct cli_tree *tree, uint16 fnum, uint16 ack_level) SSVAL(req->out.vwv,VWV(0),0xFF); SSVAL(req->out.vwv,VWV(1),0); SSVAL(req->out.vwv,VWV(2),fnum); - SSVAL(req->out.vwv,VWV(3),ack_level); + SCVAL(req->out.vwv,VWV(3),LOCKING_ANDX_OPLOCK_RELEASE); + SCVAL(req->out.vwv,VWV(3)+1,ack_level); SIVAL(req->out.vwv,VWV(4),0); SSVAL(req->out.vwv,VWV(6),0); SSVAL(req->out.vwv,VWV(7),0); diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 2b84345abb..f03cc5cf16 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -340,7 +340,7 @@ static BOOL handle_oplock_break(struct cli_transport *transport, uint_t len, con if (transport->oplock.handler) { uint16 tid = SVAL(hdr, HDR_TID); uint16 fnum = SVAL(vwv,VWV(2)); - uint8 level = CVAL(vwv,VWV(3)); + uint8 level = CVAL(vwv,VWV(3)+1); transport->oplock.handler(transport, tid, fnum, level, transport->oplock.private); } -- cgit From a8a42e7f53c67b09954ea2232830c07c6e011aa0 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 7 Apr 2004 07:18:37 +0000 Subject: r100: remember the user session key during session setup so it can be used in various crypto routines (This used to be commit f6cf9020c8899e784385ea0e14fa465685441ee6) --- source4/libcli/raw/clisession.c | 2 ++ source4/libcli/raw/clitransport.c | 9 +++++++++ 2 files changed, 11 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index c5d4888089..1c0af77d11 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -247,6 +247,8 @@ static void setup_nt1_signing(struct cli_transport *transport, const char *passw SMBsesskeygen_ntv1(nt_hash, NULL, session_key); nt_response = nt_blob(password, transport->negotiate.secblob); + cli_transport_set_session_key(transport, session_key); + cli_transport_simple_set_signing(transport, session_key, nt_response); } diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 2d614cc3bd..62152bbe4d 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -222,3 +222,12 @@ BOOL cli_transport_select(struct cli_transport *transport) return True; } + +/* + store the user session key for a transport +*/ +void cli_transport_set_session_key(struct cli_transport *transport, + const uint8 session_key[16]) +{ + memcpy(transport->negotiate.user_session_key, session_key, 16); +} -- cgit From ac193579e7db00c7a2ea0aadaaf0d34c10dcf1a5 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 10 Apr 2004 20:18:22 +0000 Subject: r152: a quick airport commit .... added ldbedit, a _really_ useful command added ldbadd, ldbdel, ldbsearch and ldbmodify to build solved lots of timezone issues, we now pass the torture tests with client and server in different zones fixed several build issues I know this breaks the no-LDAP build. Wait till I arrive in San Jose for that fix. (This used to be commit af34710d4da1841653624fe304b1c8d812c0fdd9) --- source4/libcli/raw/rawdate.c | 81 +++++++++++++++++++++++++++++++++++++ source4/libcli/raw/rawfile.c | 27 ++++++++----- source4/libcli/raw/rawfileinfo.c | 30 +++++++++----- source4/libcli/raw/rawnegotiate.c | 7 ++-- source4/libcli/raw/rawreadwrite.c | 3 +- source4/libcli/raw/rawsearch.c | 21 ++++++---- source4/libcli/raw/rawsetfileinfo.c | 21 ++++++---- 7 files changed, 153 insertions(+), 37 deletions(-) create mode 100644 source4/libcli/raw/rawdate.c (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawdate.c b/source4/libcli/raw/rawdate.c new file mode 100644 index 0000000000..e80c376bf7 --- /dev/null +++ b/source4/libcli/raw/rawdate.c @@ -0,0 +1,81 @@ +/* + Unix SMB/CIFS implementation. + + raw date handling functions + + Copyright (C) Andrew Tridgell 2004 + + 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. +*/ + +#include "includes.h" + +/******************************************************************* +put a dos date into a buffer (time/date format) +This takes GMT time and puts local time for zone_offset in the buffer +********************************************************************/ +void raw_push_dos_date(struct cli_transport *transport, + uint8 *buf, int offset, time_t unixdate) +{ + push_dos_date(buf, offset, unixdate, transport->negotiate.server_zone); +} + +/******************************************************************* +put a dos date into a buffer (date/time format) +This takes GMT time and puts local time in the buffer +********************************************************************/ +void raw_push_dos_date2(struct cli_transport *transport, + char *buf, int offset, time_t unixdate) +{ + push_dos_date2(buf, offset, unixdate, transport->negotiate.server_zone); +} + +/******************************************************************* +put a dos 32 bit "unix like" date into a buffer. This routine takes +GMT and converts it to LOCAL time in zone_offset before putting it +********************************************************************/ +void raw_push_dos_date3(struct cli_transport *transport, + char *buf, int offset, time_t unixdate) +{ + push_dos_date3(buf, offset, unixdate, transport->negotiate.server_zone); +} + +/******************************************************************* +convert a dos date +********************************************************************/ +time_t raw_pull_dos_date(struct cli_transport *transport, + const uint8 *date_ptr) +{ + return pull_dos_date(date_ptr, transport->negotiate.server_zone); +} + +/******************************************************************* +like raw_pull_dos_date() but the words are reversed +********************************************************************/ +time_t raw_pull_dos_date2(struct cli_transport *transport, + const uint8 *date_ptr) +{ + return pull_dos_date2(date_ptr, transport->negotiate.server_zone); +} + +/******************************************************************* + create a unix GMT date from a dos date in 32 bit "unix like" format + these arrive in server zone, with corresponding DST + ******************************************************************/ +time_t raw_pull_dos_date3(struct cli_transport *transport, + const uint8 *date_ptr) +{ + return pull_dos_date3(date_ptr, transport->negotiate.server_zone); +} diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c index 0dc2a15c11..d1a665ab14 100644 --- a/source4/libcli/raw/rawfile.c +++ b/source4/libcli/raw/rawfile.c @@ -240,7 +240,8 @@ static struct cli_request *smb_raw_t2open_send(struct cli_tree *tree, SSVAL(t2.in.params.data, VWV(1), parms->t2open.in.open_mode); SSVAL(t2.in.params.data, VWV(2), 0); /* reserved */ SSVAL(t2.in.params.data, VWV(3), parms->t2open.in.file_attrs); - put_dos_date(t2.in.params.data, VWV(4), parms->t2open.in.write_time); + raw_push_dos_date(tree->session->transport, + t2.in.params.data, VWV(4), parms->t2open.in.write_time); SSVAL(t2.in.params.data, VWV(6), parms->t2open.in.open_func); SIVAL(t2.in.params.data, VWV(7), parms->t2open.in.size); SIVAL(t2.in.params.data, VWV(9), parms->t2open.in.timeout); @@ -278,7 +279,8 @@ static NTSTATUS smb_raw_t2open_recv(struct cli_request *req, TALLOC_CTX *mem_ctx parms->t2open.out.fnum = SVAL(t2.out.params.data, VWV(0)); parms->t2open.out.attrib = SVAL(t2.out.params.data, VWV(1)); - parms->t2open.out.write_time = make_unix_date3(t2.out.params.data + VWV(2)); + parms->t2open.out.write_time = raw_pull_dos_date3(req->transport, + t2.out.params.data + VWV(2)); parms->t2open.out.size = IVAL(t2.out.params.data, VWV(4)); parms->t2open.out.access = SVAL(t2.out.params.data, VWV(6)); parms->t2open.out.ftype = SVAL(t2.out.params.data, VWV(7)); @@ -316,7 +318,8 @@ struct cli_request *smb_raw_open_send(struct cli_tree *tree, union smb_open *par SSVAL(req->out.vwv, VWV(3), parms->openx.in.open_mode); SSVAL(req->out.vwv, VWV(4), parms->openx.in.search_attrs); SSVAL(req->out.vwv, VWV(5), parms->openx.in.file_attrs); - put_dos_date3(req->out.vwv, VWV(6), parms->openx.in.write_time); + raw_push_dos_date3(tree->session->transport, + req->out.vwv, VWV(6), parms->openx.in.write_time); SSVAL(req->out.vwv, VWV(8), parms->openx.in.open_func); SIVAL(req->out.vwv, VWV(9), parms->openx.in.size); SIVAL(req->out.vwv, VWV(11),parms->openx.in.timeout); @@ -327,21 +330,24 @@ struct cli_request *smb_raw_open_send(struct cli_tree *tree, union smb_open *par case RAW_OPEN_MKNEW: SETUP_REQUEST(SMBmknew, 3, 0); SSVAL(req->out.vwv, VWV(0), parms->mknew.in.attrib); - put_dos_date3(req->out.vwv, VWV(1), parms->mknew.in.write_time); + raw_push_dos_date3(tree->session->transport, + req->out.vwv, VWV(1), parms->mknew.in.write_time); cli_req_append_ascii4(req, parms->mknew.in.fname, STR_TERMINATE); break; case RAW_OPEN_CREATE: SETUP_REQUEST(SMBcreate, 3, 0); SSVAL(req->out.vwv, VWV(0), parms->create.in.attrib); - put_dos_date3(req->out.vwv, VWV(1), parms->create.in.write_time); + raw_push_dos_date3(tree->session->transport, + req->out.vwv, VWV(1), parms->create.in.write_time); cli_req_append_ascii4(req, parms->create.in.fname, STR_TERMINATE); break; case RAW_OPEN_CTEMP: SETUP_REQUEST(SMBctemp, 3, 0); SSVAL(req->out.vwv, VWV(0), parms->ctemp.in.attrib); - put_dos_date3(req->out.vwv, VWV(1), parms->ctemp.in.write_time); + raw_push_dos_date3(tree->session->transport, + req->out.vwv, VWV(1), parms->ctemp.in.write_time); cli_req_append_ascii4(req, parms->ctemp.in.directory, STR_TERMINATE); break; @@ -398,7 +404,8 @@ NTSTATUS smb_raw_open_recv(struct cli_request *req, TALLOC_CTX *mem_ctx, union s CLI_CHECK_WCT(req, 7); parms->open.out.fnum = SVAL(req->in.vwv, VWV(0)); parms->open.out.attrib = SVAL(req->in.vwv, VWV(1)); - parms->open.out.write_time = make_unix_date3(req->in.vwv + VWV(2)); + parms->open.out.write_time = raw_pull_dos_date3(req->transport, + req->in.vwv + VWV(2)); parms->open.out.size = IVAL(req->in.vwv, VWV(4)); parms->open.out.rmode = SVAL(req->in.vwv, VWV(6)); break; @@ -407,7 +414,8 @@ NTSTATUS smb_raw_open_recv(struct cli_request *req, TALLOC_CTX *mem_ctx, union s CLI_CHECK_MIN_WCT(req, 15); parms->openx.out.fnum = SVAL(req->in.vwv, VWV(2)); parms->openx.out.attrib = SVAL(req->in.vwv, VWV(3)); - parms->openx.out.write_time = make_unix_date3(req->in.vwv + VWV(4)); + parms->openx.out.write_time = raw_pull_dos_date3(req->transport, + req->in.vwv + VWV(4)); parms->openx.out.size = IVAL(req->in.vwv, VWV(6)); parms->openx.out.access = SVAL(req->in.vwv, VWV(8)); parms->openx.out.ftype = SVAL(req->in.vwv, VWV(9)); @@ -491,7 +499,8 @@ struct cli_request *smb_raw_close_send(struct cli_tree *tree, union smb_close *p case RAW_CLOSE_CLOSE: SETUP_REQUEST(SMBclose, 3, 0); SSVAL(req->out.vwv, VWV(0), parms->close.in.fnum); - put_dos_date3(req->out.vwv, VWV(1), parms->close.in.write_time); + raw_push_dos_date3(tree->session->transport, + req->out.vwv, VWV(1), parms->close.in.write_time); break; case RAW_CLOSE_SPLCLOSE: diff --git a/source4/libcli/raw/rawfileinfo.c b/source4/libcli/raw/rawfileinfo.c index fd66080057..9d715e6104 100644 --- a/source4/libcli/raw/rawfileinfo.c +++ b/source4/libcli/raw/rawfileinfo.c @@ -52,9 +52,12 @@ static NTSTATUS smb_raw_info_backend(struct cli_session *session, case RAW_FILEINFO_STANDARD: FINFO_CHECK_SIZE(22); - parms->standard.out.create_time = make_unix_date2(blob->data + 0); - parms->standard.out.access_time = make_unix_date2(blob->data + 4); - parms->standard.out.write_time = make_unix_date2(blob->data + 8); + parms->standard.out.create_time = raw_pull_dos_date2(session->transport, + blob->data + 0); + parms->standard.out.access_time = raw_pull_dos_date2(session->transport, + blob->data + 4); + parms->standard.out.write_time = raw_pull_dos_date2(session->transport, + blob->data + 8); parms->standard.out.size = IVAL(blob->data, 12); parms->standard.out.alloc_size = IVAL(blob->data, 16); parms->standard.out.attrib = SVAL(blob->data, 20); @@ -62,9 +65,12 @@ static NTSTATUS smb_raw_info_backend(struct cli_session *session, case RAW_FILEINFO_EA_SIZE: FINFO_CHECK_SIZE(26); - parms->ea_size.out.create_time = make_unix_date2(blob->data + 0); - parms->ea_size.out.access_time = make_unix_date2(blob->data + 4); - parms->ea_size.out.write_time = make_unix_date2(blob->data + 8); + parms->ea_size.out.create_time = raw_pull_dos_date2(session->transport, + blob->data + 0); + parms->ea_size.out.access_time = raw_pull_dos_date2(session->transport, + blob->data + 4); + parms->ea_size.out.write_time = raw_pull_dos_date2(session->transport, + blob->data + 8); parms->ea_size.out.size = IVAL(blob->data, 12); parms->ea_size.out.alloc_size = IVAL(blob->data, 16); parms->ea_size.out.attrib = SVAL(blob->data, 20); @@ -376,7 +382,8 @@ static NTSTATUS smb_raw_getattr_recv(struct cli_request *req, CLI_CHECK_WCT(req, 10); parms->getattr.out.attrib = SVAL(req->in.vwv, VWV(0)); - parms->getattr.out.write_time = make_unix_date3(req->in.vwv + VWV(1)); + parms->getattr.out.write_time = raw_pull_dos_date3(req->transport, + req->in.vwv + VWV(1)); parms->getattr.out.size = IVAL(req->in.vwv, VWV(3)); failed: @@ -416,9 +423,12 @@ static NTSTATUS smb_raw_getattrE_recv(struct cli_request *req, } CLI_CHECK_WCT(req, 11); - parms->getattre.out.create_time = make_unix_date2(req->in.vwv + VWV(0)); - parms->getattre.out.access_time = make_unix_date2(req->in.vwv + VWV(2)); - parms->getattre.out.write_time = make_unix_date2(req->in.vwv + VWV(4)); + parms->getattre.out.create_time = raw_pull_dos_date2(req->transport, + req->in.vwv + VWV(0)); + parms->getattre.out.access_time = raw_pull_dos_date2(req->transport, + req->in.vwv + VWV(2)); + parms->getattre.out.write_time = raw_pull_dos_date2(req->transport, + req->in.vwv + VWV(4)); parms->getattre.out.size = IVAL(req->in.vwv, VWV(6)); parms->getattre.out.alloc_size = IVAL(req->in.vwv, VWV(8)); parms->getattre.out.attrib = SVAL(req->in.vwv, VWV(10)); diff --git a/source4/libcli/raw/rawnegotiate.c b/source4/libcli/raw/rawnegotiate.c index 04941f6118..587050bef8 100644 --- a/source4/libcli/raw/rawnegotiate.c +++ b/source4/libcli/raw/rawnegotiate.c @@ -129,8 +129,9 @@ NTSTATUS smb_raw_negotiate(struct cli_transport *transport) transport->negotiate.sesskey = IVAL(req->in.vwv,VWV(6)); transport->negotiate.server_zone = SVALS(req->in.vwv,VWV(10)) * 60; - /* this time is converted to GMT by make_unix_date */ - transport->negotiate.server_time = make_unix_date(req->in.vwv+VWV(8)); + /* this time is converted to GMT by raw_pull_dos_date */ + transport->negotiate.server_time = raw_pull_dos_date(transport, + req->in.vwv+VWV(8)); if ((SVAL(req->in.vwv,VWV(5)) & 0x1)) { transport->negotiate.readbraw_supported = 1; } @@ -144,7 +145,7 @@ NTSTATUS smb_raw_negotiate(struct cli_transport *transport) transport->negotiate.sec_mode = 0; transport->negotiate.server_time = time(NULL); transport->negotiate.max_xmit = ~0; - transport->negotiate.server_zone = TimeDiff(time(NULL)); + transport->negotiate.server_zone = get_time_zone(transport->negotiate.server_time); } /* a way to force ascii SMB */ diff --git a/source4/libcli/raw/rawreadwrite.c b/source4/libcli/raw/rawreadwrite.c index 3aa95c35aa..3e3b29d252 100644 --- a/source4/libcli/raw/rawreadwrite.c +++ b/source4/libcli/raw/rawreadwrite.c @@ -223,7 +223,8 @@ struct cli_request *smb_raw_write_send(struct cli_tree *tree, union smb_write *p SSVAL(req->out.vwv, VWV(0), parms->writeclose.in.fnum); SSVAL(req->out.vwv, VWV(1), parms->writeclose.in.count); SIVAL(req->out.vwv, VWV(2), parms->writeclose.in.offset); - put_dos_date3(req->out.vwv, VWV(4), parms->writeclose.in.mtime); + raw_push_dos_date3(tree->session->transport, + req->out.vwv, VWV(4), parms->writeclose.in.mtime); SCVAL(req->out.data, 0, 0); if (parms->writeclose.in.count > 0) { memcpy(req->out.data+1, parms->writeclose.in.data, diff --git a/source4/libcli/raw/rawsearch.c b/source4/libcli/raw/rawsearch.c index 4c7da6ec4d..a4236d2dbe 100644 --- a/source4/libcli/raw/rawsearch.c +++ b/source4/libcli/raw/rawsearch.c @@ -44,7 +44,8 @@ static void smb_raw_search_backend(struct cli_request *req, for (i=0; i < count; i++) { search_data.search.search_id = cli_req_pull_blob(req, mem_ctx, p, 21); search_data.search.attrib = CVAL(p, 21); - search_data.search.write_time = make_unix_date(p + 22); + search_data.search.write_time = raw_pull_dos_date(req->transport, + p + 22); search_data.search.size = IVAL(p, 26); cli_req_pull_ascii(req, mem_ctx, &search_data.search.name, p+30, 13, STR_ASCII); if (!callback(private, &search_data)) { @@ -255,9 +256,12 @@ static int parse_trans2_search(struct cli_tree *tree, blob->length -= 4; } if (blob->length < 24) return -1; - data->standard.create_time = make_unix_date2(blob->data + 0); - data->standard.access_time = make_unix_date2(blob->data + 4); - data->standard.write_time = make_unix_date2(blob->data + 8); + data->standard.create_time = raw_pull_dos_date2(tree->session->transport, + blob->data + 0); + data->standard.access_time = raw_pull_dos_date2(tree->session->transport, + blob->data + 4); + data->standard.write_time = raw_pull_dos_date2(tree->session->transport, + blob->data + 8); data->standard.size = IVAL(blob->data, 12); data->standard.alloc_size = IVAL(blob->data, 16); data->standard.attrib = SVAL(blob->data, 20); @@ -274,9 +278,12 @@ static int parse_trans2_search(struct cli_tree *tree, blob->length -= 4; } if (blob->length < 28) return -1; - data->ea_size.create_time = make_unix_date2(blob->data + 0); - data->ea_size.access_time = make_unix_date2(blob->data + 4); - data->ea_size.write_time = make_unix_date2(blob->data + 8); + data->ea_size.create_time = raw_pull_dos_date2(tree->session->transport, + blob->data + 0); + data->ea_size.access_time = raw_pull_dos_date2(tree->session->transport, + blob->data + 4); + data->ea_size.write_time = raw_pull_dos_date2(tree->session->transport, + blob->data + 8); data->ea_size.size = IVAL(blob->data, 12); data->ea_size.alloc_size = IVAL(blob->data, 16); data->ea_size.attrib = SVAL(blob->data, 20); diff --git a/source4/libcli/raw/rawsetfileinfo.c b/source4/libcli/raw/rawsetfileinfo.c index b82c20176b..9da94f161c 100644 --- a/source4/libcli/raw/rawsetfileinfo.c +++ b/source4/libcli/raw/rawsetfileinfo.c @@ -45,9 +45,12 @@ static BOOL smb_raw_setinfo_backend(struct cli_tree *tree, case RAW_SFILEINFO_STANDARD: NEED_BLOB(12); - put_dos_date2(blob->data, 0, parms->standard.in.create_time); - put_dos_date2(blob->data, 4, parms->standard.in.access_time); - put_dos_date2(blob->data, 8, parms->standard.in.write_time); + raw_push_dos_date2(tree->session->transport, + blob->data, 0, parms->standard.in.create_time); + raw_push_dos_date2(tree->session->transport, + blob->data, 4, parms->standard.in.access_time); + raw_push_dos_date2(tree->session->transport, + blob->data, 8, parms->standard.in.write_time); return True; case RAW_SFILEINFO_EA_SET: @@ -204,7 +207,8 @@ static struct cli_request *smb_raw_setattr_send(struct cli_tree *tree, if (!req) return NULL; SSVAL(req->out.vwv, VWV(0), parms->setattr.in.attrib); - put_dos_date3(req->out.vwv, VWV(1), parms->setattr.in.write_time); + raw_push_dos_date3(tree->session->transport, + req->out.vwv, VWV(1), parms->setattr.in.write_time); memset(req->out.vwv + VWV(3), 0, 10); /* reserved */ cli_req_append_ascii4(req, parms->setattr.file.fname, STR_TERMINATE); cli_req_append_ascii4(req, "", STR_TERMINATE); @@ -229,9 +233,12 @@ static struct cli_request *smb_raw_setattrE_send(struct cli_tree *tree, if (!req) return NULL; SSVAL(req->out.vwv, VWV(0), parms->setattre.file.fnum); - put_dos_date2(req->out.vwv, VWV(1), parms->setattre.in.create_time); - put_dos_date2(req->out.vwv, VWV(3), parms->setattre.in.access_time); - put_dos_date2(req->out.vwv, VWV(5), parms->setattre.in.write_time); + raw_push_dos_date2(tree->session->transport, + req->out.vwv, VWV(1), parms->setattre.in.create_time); + raw_push_dos_date2(tree->session->transport, + req->out.vwv, VWV(3), parms->setattre.in.access_time); + raw_push_dos_date2(tree->session->transport, + req->out.vwv, VWV(5), parms->setattre.in.write_time); if (!cli_request_send(req)) { cli_request_destroy(req); -- cgit From 00cedc0c0448b3520678c7959ea9269d6e5c10f1 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 12 Apr 2004 21:17:58 +0000 Subject: r189: Added UNIX search into tests - added client library parse code. Jeremy. (This used to be commit a25ae9addbb362abf67a0cbd6e62bf4cbe06d8b7) --- source4/libcli/raw/rawsearch.c | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawsearch.c b/source4/libcli/raw/rawsearch.c index a4236d2dbe..ef854679dc 100644 --- a/source4/libcli/raw/rawsearch.c +++ b/source4/libcli/raw/rawsearch.c @@ -413,8 +413,34 @@ static int parse_trans2_search(struct cli_tree *tree, return -1; } return ofs; - } + case RAW_SEARCH_UNIX_INFO: + if (blob->length < 105) return -1; + ofs = IVAL(blob->data, 0); + data->unix_info.file_index = IVAL(blob->data, 4); + data->unix_info.size = BVAL(blob->data, 8); + data->unix_info.alloc_size = BVAL(blob->data, 16); + data->unix_info.status_change_time = cli_pull_nttime(blob->data, 24); + data->unix_info.access_time = cli_pull_nttime(blob->data, 32); + data->unix_info.change_time = cli_pull_nttime(blob->data, 40); + data->unix_info.uid = IVAL(blob->data, 48); + data->unix_info.gid = IVAL(blob->data, 56); + data->unix_info.file_type = IVAL(blob->data, 64); + data->unix_info.dev_major = BVAL(blob->data, 68); + data->unix_info.dev_minor = BVAL(blob->data, 76); + data->unix_info.unique_id = BVAL(blob->data, 84); + data->unix_info.permissions = IVAL(blob->data, 92); + data->unix_info.nlink = IVAL(blob->data, 100); + /* There is no length field for this name but we know it's null terminated. */ + len = cli_blob_pull_string(tree->session, mem_ctx, blob, + &data->unix_info.name, + 0, 104, 0); + if (ofs != 0 && ofs < 104+len) { + return -1; + } + return ofs; + + } /* invalid level */ return -1; } -- cgit From 763c4bc9acc0e9162bcb7c8e487522fa62aedae6 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 14 Apr 2004 01:09:41 +0000 Subject: r204: Turns out that the string in the SEARCH unix_info level is that rare thing, a non-length string (ie. not a WIRE_STRING) but a null terminated char string. There wasn't a good interface to pull that out of a blob (all the string interfaces assumed WIRE_STRINGS). Added a new one, only used for this call. Sucks, I know - but the alternatives suck more. Added tests for some of the unix info returned. Jeremy. (This used to be commit 4d0ed04c54b105789ffd32334c3b0e544f02418c) --- source4/libcli/raw/rawrequest.c | 46 +++++++++++++++++++++++++++++++++++++++++ source4/libcli/raw/rawsearch.c | 9 ++++---- 2 files changed, 50 insertions(+), 5 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index f03cc5cf16..321d43f220 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -1007,6 +1007,52 @@ size_t cli_blob_pull_string(struct cli_session *session, blob->data+str_offset, dest->private_length, flags); } +/* + pull a string from a blob, returning a talloced char * + + Currently only used by the UNIX search info level. + + the string length is limited by 2 things: + - the data size in the blob + - the end of string (null termination) + + on failure zero is returned and dest->s is set to NULL, otherwise the number + of bytes consumed in the blob is returned +*/ +size_t cli_blob_pull_unix_string(struct cli_session *session, + TALLOC_CTX *mem_ctx, + DATA_BLOB *blob, + const char **dest, + uint16 str_offset, + unsigned flags) +{ + int extra = 0; + *dest = NULL; + + if (!(flags & STR_ASCII) && + ((flags & STR_UNICODE) || + (session->transport->negotiate.capabilities & CAP_UNICODE))) { + int align = 0; + if ((str_offset&1) && !(flags & STR_NOALIGN)) { + align = 1; + } + if (flags & STR_LEN_NOTERM) { + extra = 2; + } + return align + extra + cli_blob_pull_ucs2(mem_ctx, blob, dest, + blob->data+str_offset+align, + -1, flags); + } + + if (flags & STR_LEN_NOTERM) { + extra = 1; + } + + return extra + cli_blob_pull_ascii(mem_ctx, blob, dest, + blob->data+str_offset, -1, flags); +} + + /* append a string into a blob */ diff --git a/source4/libcli/raw/rawsearch.c b/source4/libcli/raw/rawsearch.c index ef854679dc..8b60633fe8 100644 --- a/source4/libcli/raw/rawsearch.c +++ b/source4/libcli/raw/rawsearch.c @@ -415,7 +415,7 @@ static int parse_trans2_search(struct cli_tree *tree, return ofs; case RAW_SEARCH_UNIX_INFO: - if (blob->length < 105) return -1; + if (blob->length < 109) return -1; ofs = IVAL(blob->data, 0); data->unix_info.file_index = IVAL(blob->data, 4); data->unix_info.size = BVAL(blob->data, 8); @@ -432,10 +432,9 @@ static int parse_trans2_search(struct cli_tree *tree, data->unix_info.permissions = IVAL(blob->data, 92); data->unix_info.nlink = IVAL(blob->data, 100); /* There is no length field for this name but we know it's null terminated. */ - len = cli_blob_pull_string(tree->session, mem_ctx, blob, - &data->unix_info.name, - 0, 104, 0); - if (ofs != 0 && ofs < 104+len) { + len = cli_blob_pull_unix_string(tree->session, mem_ctx, blob, + &data->unix_info.name, 108, 0); + if (ofs != 0 && ofs < 108+len) { return -1; } return ofs; -- cgit From 493a37ba663686b7bee3f7093d6650a24250f101 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 23 Apr 2004 04:21:22 +0000 Subject: r335: added much better handling of servers that die unexpectedly during a request (a dead socket). I discovered this when testing against Sun's PC-NetLink. cleaned up the naming of some of the samr requests add IDL and test code for samr_QueryGroupMember(), samr_SetMemberAttributesOfGroup() and samr_Shutdown(). (actually, I didn't leave the samr_Shutdown() test in, as its fatal to windows servers due to doing exactly what it says it does). (This used to be commit 925bc2622c105dee4ffff809c6c35cd209a839f8) --- source4/libcli/raw/clisocket.c | 26 +++++++++++++++++++++++--- source4/libcli/raw/clitransport.c | 8 ++++++++ source4/libcli/raw/rawrequest.c | 11 +++++++---- source4/libcli/raw/rawtrans.c | 1 - 4 files changed, 38 insertions(+), 8 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index f596cba854..4dae7d517d 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -74,15 +74,25 @@ BOOL cli_sock_connect(struct cli_socket *sock, struct in_addr *ip, int port) } +/**************************************************************************** + mark the socket as dead +****************************************************************************/ +void cli_sock_dead(struct cli_socket *sock) +{ + if (sock->fd != -1) { + close(sock->fd); + sock->fd = -1; + } +} + /**************************************************************************** reduce socket reference count - if it becomes zero then close ****************************************************************************/ void cli_sock_close(struct cli_socket *sock) { sock->reference_count--; - if (sock->reference_count <= 0 && sock->fd != -1) { - close(sock->fd); - sock->fd = -1; + if (sock->reference_count <= 0) { + cli_sock_dead(sock); } } @@ -99,6 +109,11 @@ void cli_sock_set_options(struct cli_socket *sock, const char *options) ****************************************************************************/ ssize_t cli_sock_write(struct cli_socket *sock, const char *data, size_t len) { + if (sock->fd == -1) { + errno = EIO; + return -1; + } + return write_data(sock->fd, data, len); } @@ -108,6 +123,11 @@ ssize_t cli_sock_write(struct cli_socket *sock, const char *data, size_t len) ****************************************************************************/ ssize_t cli_sock_read(struct cli_socket *sock, char *data, size_t len) { + if (sock->fd == -1) { + errno = EIO; + return -1; + } + return read_data(sock->fd, data, len); } diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 62152bbe4d..b8eef65c7f 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -60,6 +60,14 @@ void cli_transport_close(struct cli_transport *transport) } } +/* + mark the transport as dead +*/ +void cli_transport_dead(struct cli_transport *transport) +{ + cli_sock_dead(transport->socket); +} + /**************************************************************************** diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 321d43f220..35a2d363df 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -40,9 +40,11 @@ NTSTATUS cli_request_destroy(struct cli_request *req) _send() call fails completely */ if (!req) return NT_STATUS_UNSUCCESSFUL; - /* remove it from the list of pending requests (a null op if - its not in the list) */ - DLIST_REMOVE(req->transport->pending_requests, req); + if (req->transport) { + /* remove it from the list of pending requests (a null op if + its not in the list) */ + DLIST_REMOVE(req->transport->pending_requests, req); + } /* ahh, its so nice to destroy a complex structure in such a simple way! */ @@ -306,11 +308,12 @@ BOOL cli_request_receive(struct cli_request *req) /* keep receiving packets until this one is replied to */ while (!req->in.buffer) { if (!cli_transport_select(req->transport)) { + req->status = NT_STATUS_UNSUCCESSFUL; return False; } if (!cli_request_receive_next(req->transport)) { - cli_transport_close(req->transport); + cli_transport_dead(req->transport); req->status = NT_STATUS_UNEXPECTED_NETWORK_ERROR; return False; } diff --git a/source4/libcli/raw/rawtrans.c b/source4/libcli/raw/rawtrans.c index f7a3b4aa43..1fd91b29d7 100644 --- a/source4/libcli/raw/rawtrans.c +++ b/source4/libcli/raw/rawtrans.c @@ -64,7 +64,6 @@ NTSTATUS smb_raw_trans2_recv(struct cli_request *req, parms->out.params.data = NULL; if (!cli_request_receive(req)) { - req->status = NT_STATUS_UNSUCCESSFUL; return cli_request_destroy(req); } -- cgit From dce84ffd379012812170f68f7de8aab73123f0b3 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sun, 9 May 2004 12:42:18 +0000 Subject: r610: - Merge the Samba3 'ntlm_auth --diagnostics' testsuite to Samba4. - This required using NETLOGON_NEG_AUTH2_FLAGS for the SetupCredentials2 negotiation flags, which is what Samba3 does, because otherwise the server uses different crypto. - This tests the returned session keys, which we decrypt. - Update the Samba4 notion of a 'session key' to be a DATA_BLOB in most places. - Fix session key code to return NT_STATUS_NO_SESSION_KEY if none is available. - Remove a useless argument to SMBsesskeygen_ntv1 - move netr_CredentialState from the .idl to the new credentials.h Andrew Bartlett (This used to be commit 44f8b5b53e6abd4de8a676f78d729988fadff320) --- source4/libcli/raw/clisession.c | 29 +++++++++++++++++++++-------- source4/libcli/raw/clitransport.c | 8 -------- source4/libcli/raw/smb_signing.c | 12 ++++++++---- 3 files changed, 29 insertions(+), 20 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index 1c0af77d11..fe64565597 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -234,22 +234,34 @@ static DATA_BLOB nt_blob(const char *pass, DATA_BLOB challenge) return blob; } +/* + store the user session key for a transport +*/ +void cli_session_set_user_session_key(struct cli_session *session, + const DATA_BLOB *session_key) +{ + session->user_session_key = data_blob_talloc(session->mem_ctx, + session_key->data, + session_key->length); +} + /* setup signing for a NT1 style session setup */ -static void setup_nt1_signing(struct cli_transport *transport, const char *password) +static void use_nt1_session_keys(struct cli_session *session, + const char *password, const DATA_BLOB *nt_response) { + struct cli_transport *transport = session->transport; uchar nt_hash[16]; - uchar session_key[16]; - DATA_BLOB nt_response; + DATA_BLOB session_key = data_blob(NULL, 16); E_md4hash(password, nt_hash); - SMBsesskeygen_ntv1(nt_hash, NULL, session_key); - nt_response = nt_blob(password, transport->negotiate.secblob); + SMBsesskeygen_ntv1(nt_hash, session_key.data); - cli_transport_set_session_key(transport, session_key); + cli_transport_simple_set_signing(transport, session_key, *nt_response); - cli_transport_simple_set_signing(transport, session_key, nt_response); + cli_session_set_user_session_key(session, &session_key); + data_blob_free(&session_key); } /**************************************************************************** @@ -332,7 +344,8 @@ static NTSTATUS smb_raw_session_setup_generic_nt1(struct cli_session *session, session->transport->negotiate.secblob); s2.nt1.in.password2 = nt_blob(parms->generic.in.password, session->transport->negotiate.secblob); - setup_nt1_signing(session->transport, parms->generic.in.password); + use_nt1_session_keys(session, parms->generic.in.password, &s2.nt1.in.password2); + } else { s2.nt1.in.password1 = data_blob(parms->generic.in.password, strlen(parms->generic.in.password)); diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index b8eef65c7f..72cad2e925 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -231,11 +231,3 @@ BOOL cli_transport_select(struct cli_transport *transport) return True; } -/* - store the user session key for a transport -*/ -void cli_transport_set_session_key(struct cli_transport *transport, - const uint8 session_key[16]) -{ - memcpy(transport->negotiate.user_session_key, session_key, 16); -} diff --git a/source4/libcli/raw/smb_signing.c b/source4/libcli/raw/smb_signing.c index 2ab61aa001..5f47a5e42a 100644 --- a/source4/libcli/raw/smb_signing.c +++ b/source4/libcli/raw/smb_signing.c @@ -220,7 +220,8 @@ static void cli_transport_simple_free_signing_context(struct cli_transport *tran SMB signing - Simple implementation - setup the MAC key. ************************************************************/ BOOL cli_transport_simple_set_signing(struct cli_transport *transport, - const uchar user_transport_key[16], const DATA_BLOB response) + const DATA_BLOB user_session_key, + const DATA_BLOB response) { struct smb_basic_signing_context *data; @@ -235,10 +236,13 @@ BOOL cli_transport_simple_set_signing(struct cli_transport *transport, data = smb_xmalloc(sizeof(*data)); transport->negotiate.sign_info.signing_context = data; - data->mac_key = data_blob(NULL, MIN(response.length + 16, 40)); + data->mac_key = data_blob(NULL, response.length + user_session_key.length); - memcpy(&data->mac_key.data[0], user_transport_key, 16); - memcpy(&data->mac_key.data[16],response.data, MIN(response.length, 40 - 16)); + memcpy(&data->mac_key.data[0], user_session_key.data, user_session_key.length); + + if (response.length) { + memcpy(&data->mac_key.data[user_session_key.length],response.data, response.length); + } /* Initialise the sequence number */ data->next_seq_num = 0; -- cgit From 6b921d1d2175f3b6267cb6e89b463cff852880cc Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 14 May 2004 05:41:21 +0000 Subject: r719: Follow the trend - remove more unused functions. Andrew Bartlett (This used to be commit 62eef851fd79b2739b93b4ed7829514a3dcbf1d0) --- source4/libcli/raw/clirewrite.c | 22 ---------------------- 1 file changed, 22 deletions(-) delete mode 100644 source4/libcli/raw/clirewrite.c (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clirewrite.c b/source4/libcli/raw/clirewrite.c deleted file mode 100644 index 2d2e2e3feb..0000000000 --- a/source4/libcli/raw/clirewrite.c +++ /dev/null @@ -1,22 +0,0 @@ -#include "includes.h" - -/* - - this is a set of temporary stub functions used during the libsmb rewrite. - This file will need to go away before the rewrite is complete. -*/ - -void become_root(void) -{} - -void unbecome_root(void) -{} - -BOOL become_user_permanently(uid_t uid, gid_t gid) -{ return True; } - -void set_effective_uid(uid_t uid) -{} - -uid_t sec_initial_uid(void) -{ return 0; } -- cgit From 579c13da43d5b40ac6d6c1436399fbc1d8dfd054 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 25 May 2004 13:57:39 +0000 Subject: r873: converted samba4 to use real 64 bit integers instead of structures. This was suggested by metze recently. I checked on the build farm and all the machines we have support 64 bit ints, and support the LL suffix for 64 bit constants. I suspect some won't support strtoll() and related functions, so we will probably need replacements for those. (This used to be commit 9a9244a1c66654c12abe4379661cba83a73c4c21) --- source4/libcli/raw/clispnego.c | 12 ++++++------ source4/libcli/raw/rawnegotiate.c | 2 +- source4/libcli/raw/rawrequest.c | 10 +++------- source4/libcli/raw/rawsetfileinfo.c | 14 +++++++------- 4 files changed, 17 insertions(+), 21 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clispnego.c b/source4/libcli/raw/clispnego.c index e6cadc466c..7ad6be1006 100644 --- a/source4/libcli/raw/clispnego.c +++ b/source4/libcli/raw/clispnego.c @@ -141,9 +141,9 @@ BOOL spnego_parse_negTokenInit(DATA_BLOB blob, asn1_start_tag(&data,ASN1_CONTEXT(0)); asn1_start_tag(&data,ASN1_SEQUENCE(0)); for (i=0; asn1_tag_remaining(&data) > 0 && i < ASN1_MAX_OIDS; i++) { - char *oid = NULL; - asn1_read_OID(&data,&oid); - OIDs[i] = oid; + char *aoid = NULL; + asn1_read_OID(&data,&aoid); + OIDs[i] = aoid; } OIDs[i] = NULL; asn1_end_tag(&data); @@ -230,9 +230,9 @@ BOOL parse_negTokenTarg(DATA_BLOB blob, char *OIDs[ASN1_MAX_OIDS], DATA_BLOB *se asn1_start_tag(&data, ASN1_CONTEXT(0)); asn1_start_tag(&data, ASN1_SEQUENCE(0)); for (i=0; asn1_tag_remaining(&data) > 0 && i < ASN1_MAX_OIDS; i++) { - char *oid = NULL; - asn1_read_OID(&data,&oid); - OIDs[i] = oid; + char *aoid = NULL; + asn1_read_OID(&data,&aoid); + OIDs[i] = aoid; } OIDs[i] = NULL; asn1_end_tag(&data); diff --git a/source4/libcli/raw/rawnegotiate.c b/source4/libcli/raw/rawnegotiate.c index 587050bef8..5b94ef63d8 100644 --- a/source4/libcli/raw/rawnegotiate.c +++ b/source4/libcli/raw/rawnegotiate.c @@ -106,7 +106,7 @@ NTSTATUS smb_raw_negotiate(struct cli_transport *transport) /* this time arrives in real GMT */ ntt = cli_pull_nttime(req->in.vwv, VWV(11)+1); - transport->negotiate.server_time = nt_time_to_unix(&ntt); + transport->negotiate.server_time = nt_time_to_unix(ntt); transport->negotiate.capabilities = IVAL(req->in.vwv,VWV(9)+1); transport->negotiate.secblob = cli_req_pull_blob(req, transport->mem_ctx, req->in.data, req->in.data_size); diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 35a2d363df..085b445fba 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -831,11 +831,9 @@ BOOL cli_raw_pull_data(struct cli_request *req, const char *src, int len, char * /* put a NTTIME into a packet */ - -void cli_push_nttime(void *base, uint16 offset, NTTIME *t) +void cli_push_nttime(void *base, uint16 offset, NTTIME t) { - SIVAL(base, offset, t->low); - SIVAL(base, offset+4, t->high); + SBVAL(base, offset, t); } /* @@ -843,9 +841,7 @@ void cli_push_nttime(void *base, uint16 offset, NTTIME *t) */ NTTIME cli_pull_nttime(void *base, uint16 offset) { - NTTIME ret; - ret.low = IVAL(base, offset); - ret.high = IVAL(base, offset+4); + NTTIME ret = BVAL(base, offset); return ret; } diff --git a/source4/libcli/raw/rawsetfileinfo.c b/source4/libcli/raw/rawsetfileinfo.c index 9da94f161c..d8fc78972d 100644 --- a/source4/libcli/raw/rawsetfileinfo.c +++ b/source4/libcli/raw/rawsetfileinfo.c @@ -61,10 +61,10 @@ static BOOL smb_raw_setinfo_backend(struct cli_tree *tree, case RAW_SFILEINFO_BASIC_INFO: case RAW_SFILEINFO_BASIC_INFORMATION: NEED_BLOB(40); - cli_push_nttime(blob->data, 0, &parms->basic_info.in.create_time); - cli_push_nttime(blob->data, 8, &parms->basic_info.in.access_time); - cli_push_nttime(blob->data, 16, &parms->basic_info.in.write_time); - cli_push_nttime(blob->data, 24, &parms->basic_info.in.change_time); + cli_push_nttime(blob->data, 0, parms->basic_info.in.create_time); + cli_push_nttime(blob->data, 8, parms->basic_info.in.access_time); + cli_push_nttime(blob->data, 16, parms->basic_info.in.write_time); + cli_push_nttime(blob->data, 24, parms->basic_info.in.change_time); SIVAL(blob->data, 32, parms->basic_info.in.attrib); SIVAL(blob->data, 36, 0); /* padding */ return True; @@ -73,9 +73,9 @@ static BOOL smb_raw_setinfo_backend(struct cli_tree *tree, NEED_BLOB(92); SBVAL(blob->data, 0, parms->unix_basic.in.end_of_file); SBVAL(blob->data, 8, parms->unix_basic.in.num_bytes); - cli_push_nttime(blob->data, 16, &parms->unix_basic.in.status_change_time); - cli_push_nttime(blob->data, 24, &parms->unix_basic.in.access_time); - cli_push_nttime(blob->data, 32, &parms->unix_basic.in.change_time); + cli_push_nttime(blob->data, 16, parms->unix_basic.in.status_change_time); + cli_push_nttime(blob->data, 24, parms->unix_basic.in.access_time); + cli_push_nttime(blob->data, 32, parms->unix_basic.in.change_time); SBVAL(blob->data, 40, parms->unix_basic.in.uid); SBVAL(blob->data, 48, parms->unix_basic.in.gid); SIVAL(blob->data, 56, parms->unix_basic.in.file_type); -- cgit From f9d8f8843dc0ab8c9d59abde7222e0f118b86b5d Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 25 May 2004 16:24:13 +0000 Subject: r884: convert samba4 to use [u]int32_t instead of [u]int32 metze (This used to be commit 0e5517d937a2eb7cf707991d1c7498c1ab456095) --- source4/libcli/raw/clikrb5.c | 4 ++-- source4/libcli/raw/raweas.c | 4 ++-- source4/libcli/raw/rawnotify.c | 4 ++-- source4/libcli/raw/rawrequest.c | 4 ++-- source4/libcli/raw/rawtrans.c | 10 +++++----- source4/libcli/raw/smb_signing.c | 2 +- 6 files changed, 14 insertions(+), 14 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clikrb5.c b/source4/libcli/raw/clikrb5.c index 1d9c02f7f4..0d4fade295 100644 --- a/source4/libcli/raw/clikrb5.c +++ b/source4/libcli/raw/clikrb5.c @@ -37,10 +37,10 @@ /* * This function is not in the Heimdal mainline. */ - krb5_error_code krb5_set_real_time(krb5_context context, int32_t seconds, int32_t microseconds) + krb5_error_code krb5_set_real_time(krb5_context context, int32_t_t seconds, int32_t_t microseconds) { krb5_error_code ret; - int32_t sec, usec; + int32_t_t sec, usec; ret = krb5_us_timeofday(context, &sec, &usec); if (ret) diff --git a/source4/libcli/raw/raweas.c b/source4/libcli/raw/raweas.c index ce0368c304..f265c8281d 100644 --- a/source4/libcli/raw/raweas.c +++ b/source4/libcli/raw/raweas.c @@ -42,7 +42,7 @@ uint_t ea_list_size(uint_t num_eas, struct ea_struct *eas) void ea_put_list(char *data, uint_t num_eas, struct ea_struct *eas) { int i; - uint32 ea_size; + uint32_t ea_size; ea_size = ea_list_size(num_eas, eas); @@ -105,7 +105,7 @@ NTSTATUS ea_pull_list(const DATA_BLOB *blob, uint_t *num_eas, struct ea_struct **eas) { int n; - uint32 ea_size, ofs; + uint32_t ea_size, ofs; if (blob->length < 4) { return NT_STATUS_INFO_LENGTH_MISMATCH; diff --git a/source4/libcli/raw/rawnotify.c b/source4/libcli/raw/rawnotify.c index 7d635da0dc..1030a61704 100644 --- a/source4/libcli/raw/rawnotify.c +++ b/source4/libcli/raw/rawnotify.c @@ -51,7 +51,7 @@ NTSTATUS smb_raw_changenotify_recv(struct cli_request *req, { struct smb_nttrans nt; NTSTATUS status; - uint32 ofs, i; + uint32_t ofs, i; struct cli_session *session = req?req->session:NULL; status = smb_raw_nttrans_recv(req, mem_ctx, &nt); @@ -64,7 +64,7 @@ NTSTATUS smb_raw_changenotify_recv(struct cli_request *req, /* count them */ for (ofs=0; nt.out.params.length - ofs > 12; ) { - uint32 next = IVAL(nt.out.params.data, ofs); + uint32_t next = IVAL(nt.out.params.data, ofs); parms->out.num_changes++; if (next == 0 || ofs + next >= nt.out.params.length) break; diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 085b445fba..d8e4d80b39 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -153,7 +153,7 @@ struct cli_request *cli_request_setup_session(struct cli_session *session, { struct cli_request *req; uint16 flags2; - uint32 capabilities; + uint32_t capabilities; req = cli_request_setup_transport(session->transport, command, wct, buflen); @@ -798,7 +798,7 @@ DATA_BLOB cli_req_pull_blob(struct cli_request *req, TALLOC_CTX *mem_ctx, const /* check that a lump of data in a request is within the bounds of the data section of the packet */ -static BOOL cli_req_data_oob(struct cli_request *req, const char *ptr, uint32 count) +static BOOL cli_req_data_oob(struct cli_request *req, const char *ptr, uint32_t count) { /* be careful with wraparound! */ if (ptr < req->in.data || diff --git a/source4/libcli/raw/rawtrans.c b/source4/libcli/raw/rawtrans.c index 1fd91b29d7..d13a1227dd 100644 --- a/source4/libcli/raw/rawtrans.c +++ b/source4/libcli/raw/rawtrans.c @@ -320,8 +320,8 @@ NTSTATUS smb_raw_nttrans_recv(struct cli_request *req, TALLOC_CTX *mem_ctx, struct smb_nttrans *parms) { - uint32 total_data, recvd_data=0; - uint32 total_param, recvd_param=0; + uint32_t total_data, recvd_data=0; + uint32_t total_param, recvd_param=0; if (!cli_request_receive(req) || cli_request_is_error(req)) { @@ -369,9 +369,9 @@ NTSTATUS smb_raw_nttrans_recv(struct cli_request *req, while (recvd_data < total_data || recvd_param < total_param) { - uint32 param_count, param_ofs, param_disp; - uint32 data_count, data_ofs, data_disp; - uint32 total_data2, total_param2; + uint32_t param_count, param_ofs, param_disp; + uint32_t data_count, data_ofs, data_disp; + uint32_t total_data2, total_param2; /* parse out the total lengths again - they can shrink! */ total_param2 = IVAL(req->in.vwv, 3); diff --git a/source4/libcli/raw/smb_signing.c b/source4/libcli/raw/smb_signing.c index 5f47a5e42a..bb295ee991 100644 --- a/source4/libcli/raw/smb_signing.c +++ b/source4/libcli/raw/smb_signing.c @@ -24,7 +24,7 @@ struct smb_basic_signing_context { DATA_BLOB mac_key; - uint32 next_seq_num; + uint32_t next_seq_num; }; /*********************************************************** -- cgit From f88bf54c7f6d1c2ef833047eb8327953c304b5ff Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 25 May 2004 17:24:24 +0000 Subject: r889: convert samba4 to use [u]int16_t instead of [u]int16 metze (This used to be commit af6f1f8a01bebbecd99bc8c066519e89966e65e3) --- source4/libcli/raw/clioplock.c | 2 +- source4/libcli/raw/clisession.c | 4 ++-- source4/libcli/raw/clitransport.c | 4 ++-- source4/libcli/raw/raweas.c | 2 +- source4/libcli/raw/rawfile.c | 8 ++++---- source4/libcli/raw/rawfileinfo.c | 8 ++++---- source4/libcli/raw/rawfsinfo.c | 8 ++++---- source4/libcli/raw/rawioctl.c | 2 +- source4/libcli/raw/rawnotify.c | 2 +- source4/libcli/raw/rawrequest.c | 18 +++++++++--------- source4/libcli/raw/rawsearch.c | 24 ++++++++++++------------ source4/libcli/raw/rawsetfileinfo.c | 10 +++++----- source4/libcli/raw/rawtrans.c | 6 +++--- source4/libcli/raw/smb_signing.c | 2 +- 14 files changed, 50 insertions(+), 50 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clioplock.c b/source4/libcli/raw/clioplock.c index f27bf937ce..eacfd411a0 100644 --- a/source4/libcli/raw/clioplock.c +++ b/source4/libcli/raw/clioplock.c @@ -23,7 +23,7 @@ /**************************************************************************** send an ack for an oplock break request ****************************************************************************/ -BOOL cli_oplock_ack(struct cli_tree *tree, uint16 fnum, uint16 ack_level) +BOOL cli_oplock_ack(struct cli_tree *tree, uint16_t fnum, uint16_t ack_level) { BOOL ret; struct cli_request *req; diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index fe64565597..b3876f2490 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -45,7 +45,7 @@ struct cli_session *cli_session_init(struct cli_transport *transport) session->mem_ctx = mem_ctx; session->transport = transport; - session->pid = (uint16)getpid(); + session->pid = (uint16_t)getpid(); session->vuid = UID_FIELD_INVALID; session->transport->reference_count++; @@ -144,7 +144,7 @@ NTSTATUS smb_raw_session_setup_recv(struct cli_request *req, TALLOC_CTX *mem_ctx, union smb_sesssetup *parms) { - uint16 len; + uint16_t len; char *p; if (!cli_request_receive(req)) { diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 72cad2e925..1e9032459f 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -127,9 +127,9 @@ BOOL cli_transport_connect(struct cli_transport *transport, /**************************************************************************** get next mid in sequence ****************************************************************************/ -uint16 cli_transport_next_mid(struct cli_transport *transport) +uint16_t cli_transport_next_mid(struct cli_transport *transport) { - uint16 mid; + uint16_t mid; struct cli_request *req; mid = transport->next_mid; diff --git a/source4/libcli/raw/raweas.c b/source4/libcli/raw/raweas.c index f265c8281d..ae58790baa 100644 --- a/source4/libcli/raw/raweas.c +++ b/source4/libcli/raw/raweas.c @@ -69,7 +69,7 @@ uint_t ea_pull_struct(const DATA_BLOB *blob, struct ea_struct *ea) { uint8 nlen; - uint16 vlen; + uint16_t vlen; if (blob->length < 6) { return 0; diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c index d1a665ab14..5128ba96ce 100644 --- a/source4/libcli/raw/rawfile.c +++ b/source4/libcli/raw/rawfile.c @@ -111,10 +111,10 @@ static struct cli_request *smb_raw_t2mkdir_send(struct cli_tree *tree, union smb_mkdir *parms) { struct smb_trans2 t2; - uint16 setup = TRANSACT2_MKDIR; + uint16_t setup = TRANSACT2_MKDIR; TALLOC_CTX *mem_ctx; struct cli_request *req; - uint16 data_total; + uint16_t data_total; mem_ctx = talloc_init("t2mkdir"); @@ -219,10 +219,10 @@ static struct cli_request *smb_raw_t2open_send(struct cli_tree *tree, union smb_open *parms) { struct smb_trans2 t2; - uint16 setup = TRANSACT2_OPEN; + uint16_t setup = TRANSACT2_OPEN; TALLOC_CTX *mem_ctx = talloc_init("smb_raw_t2open"); struct cli_request *req; - uint16 list_size; + uint16_t list_size; list_size = ea_list_size(parms->t2open.in.num_eas, parms->t2open.in.eas); diff --git a/source4/libcli/raw/rawfileinfo.c b/source4/libcli/raw/rawfileinfo.c index 9d715e6104..f27a0d7281 100644 --- a/source4/libcli/raw/rawfileinfo.c +++ b/source4/libcli/raw/rawfileinfo.c @@ -261,10 +261,10 @@ static NTSTATUS smb_raw_info_backend(struct cli_session *session, Very raw query file info - returns param/data blobs - (async send) ****************************************************************************/ static struct cli_request *smb_raw_fileinfo_blob_send(struct cli_tree *tree, - uint16 fnum, uint16 info_level) + uint16_t fnum, uint16_t info_level) { struct smb_trans2 tp; - uint16 setup = TRANSACT2_QFILEINFO; + uint16_t setup = TRANSACT2_QFILEINFO; struct cli_request *req; TALLOC_CTX *mem_ctx = talloc_init("raw_fileinfo"); @@ -314,10 +314,10 @@ static NTSTATUS smb_raw_fileinfo_blob_recv(struct cli_request *req, ****************************************************************************/ static struct cli_request *smb_raw_pathinfo_blob_send(struct cli_tree *tree, const char *fname, - uint16 info_level) + uint16_t info_level) { struct smb_trans2 tp; - uint16 setup = TRANSACT2_QPATHINFO; + uint16_t setup = TRANSACT2_QPATHINFO; struct cli_request *req; TALLOC_CTX *mem_ctx = talloc_init("raw_pathinfo"); diff --git a/source4/libcli/raw/rawfsinfo.c b/source4/libcli/raw/rawfsinfo.c index 85daf654d3..faf375deb0 100644 --- a/source4/libcli/raw/rawfsinfo.c +++ b/source4/libcli/raw/rawfsinfo.c @@ -67,10 +67,10 @@ failed: ****************************************************************************/ static struct cli_request *smb_raw_qfsinfo_send(struct cli_tree *tree, TALLOC_CTX *mem_ctx, - uint16 info_level) + uint16_t info_level) { struct smb_trans2 tp; - uint16 setup = TRANSACT2_QFSINFO; + uint16_t setup = TRANSACT2_QFSINFO; tp.in.max_setup = 0; tp.in.flags = 0; @@ -133,7 +133,7 @@ struct cli_request *smb_raw_fsinfo_send(struct cli_tree *tree, TALLOC_CTX *mem_ctx, union smb_fsinfo *fsinfo) { - uint16 info_level; + uint16_t info_level; /* handle the only non-trans2 call separately */ if (fsinfo->generic.level == RAW_QFS_DSKATTR) { @@ -144,7 +144,7 @@ struct cli_request *smb_raw_fsinfo_send(struct cli_tree *tree, } /* the headers map the trans2 levels direct to info levels */ - info_level = (uint16)fsinfo->generic.level; + info_level = (uint16_t)fsinfo->generic.level; return smb_raw_qfsinfo_send(tree, mem_ctx, info_level); } diff --git a/source4/libcli/raw/rawioctl.c b/source4/libcli/raw/rawioctl.c index 2ea2cabb89..271758c65c 100644 --- a/source4/libcli/raw/rawioctl.c +++ b/source4/libcli/raw/rawioctl.c @@ -72,7 +72,7 @@ static struct cli_request *smb_raw_ntioctl_send(struct cli_tree *tree, union smb_ioctl *parms) { struct smb_nttrans nt; - uint16 setup[4]; + uint16_t setup[4]; nt.in.max_setup = 0; nt.in.max_param = 0; diff --git a/source4/libcli/raw/rawnotify.c b/source4/libcli/raw/rawnotify.c index 1030a61704..b8efa2fcd6 100644 --- a/source4/libcli/raw/rawnotify.c +++ b/source4/libcli/raw/rawnotify.c @@ -26,7 +26,7 @@ change notify (async send) struct cli_request *smb_raw_changenotify_send(struct cli_tree *tree, struct smb_notify *parms) { struct smb_nttrans nt; - uint16 setup[4]; + uint16_t setup[4]; nt.in.max_setup = 0; nt.in.max_param = parms->in.buffer_size; diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index d8e4d80b39..d7085ea3d2 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -152,7 +152,7 @@ struct cli_request *cli_request_setup_session(struct cli_session *session, uint8 command, unsigned wct, unsigned buflen) { struct cli_request *req; - uint16 flags2; + uint16_t flags2; uint32_t capabilities; req = cli_request_setup_transport(session->transport, command, wct, buflen); @@ -341,8 +341,8 @@ static BOOL handle_oplock_break(struct cli_transport *transport, uint_t len, con } if (transport->oplock.handler) { - uint16 tid = SVAL(hdr, HDR_TID); - uint16 fnum = SVAL(vwv,VWV(2)); + uint16_t tid = SVAL(hdr, HDR_TID); + uint16_t fnum = SVAL(vwv,VWV(2)); uint8 level = CVAL(vwv,VWV(3)+1); transport->oplock.handler(transport, tid, fnum, level, transport->oplock.private); } @@ -370,7 +370,7 @@ BOOL cli_request_receive_next(struct cli_transport *transport) char *buffer, *hdr, *vwv; TALLOC_CTX *mem_ctx; struct cli_request *req; - uint16 wct, mid = 0; + uint16_t wct, mid = 0; len = cli_sock_read(transport->socket, header, 4); if (len != 4) { @@ -635,7 +635,7 @@ size_t cli_req_append_bytes(struct cli_request *req, const uint8 *bytes, size_t append variable block (type 5 buffer) into the data portion of the request packet return the number of bytes added */ -size_t cli_req_append_var_block(struct cli_request *req, const uint8 *bytes, uint16 byte_len) +size_t cli_req_append_var_block(struct cli_request *req, const uint8 *bytes, uint16_t byte_len) { cli_req_grow_allocation(req, byte_len + 3 + req->out.data_size); SCVAL(req->out.data + req->out.data_size, 0, 5); @@ -831,7 +831,7 @@ BOOL cli_raw_pull_data(struct cli_request *req, const char *src, int len, char * /* put a NTTIME into a packet */ -void cli_push_nttime(void *base, uint16 offset, NTTIME t) +void cli_push_nttime(void *base, uint16_t offset, NTTIME t) { SBVAL(base, offset, t); } @@ -839,7 +839,7 @@ void cli_push_nttime(void *base, uint16 offset, NTTIME t) /* pull a NTTIME from a packet */ -NTTIME cli_pull_nttime(void *base, uint16 offset) +NTTIME cli_pull_nttime(void *base, uint16_t offset) { NTTIME ret = BVAL(base, offset); return ret; @@ -967,7 +967,7 @@ size_t cli_blob_pull_string(struct cli_session *session, TALLOC_CTX *mem_ctx, DATA_BLOB *blob, WIRE_STRING *dest, - uint16 len_offset, uint16 str_offset, + uint16_t len_offset, uint16_t str_offset, unsigned flags) { int extra; @@ -1022,7 +1022,7 @@ size_t cli_blob_pull_unix_string(struct cli_session *session, TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const char **dest, - uint16 str_offset, + uint16_t str_offset, unsigned flags) { int extra = 0; diff --git a/source4/libcli/raw/rawsearch.c b/source4/libcli/raw/rawsearch.c index 8b60633fe8..bdb57aa6c4 100644 --- a/source4/libcli/raw/rawsearch.c +++ b/source4/libcli/raw/rawsearch.c @@ -25,7 +25,7 @@ ****************************************************************************/ static void smb_raw_search_backend(struct cli_request *req, TALLOC_CTX *mem_ctx, - uint16 count, + uint16_t count, void *private, BOOL (*callback)(void *private, union smb_search_data *file)) @@ -129,12 +129,12 @@ static NTSTATUS smb_raw_search_next_old(struct cli_tree *tree, static NTSTATUS smb_raw_search_first_blob(struct cli_tree *tree, TALLOC_CTX *mem_ctx, /* used to allocate output blobs */ union smb_search_first *io, - uint16 info_level, + uint16_t info_level, DATA_BLOB *out_param_blob, DATA_BLOB *out_data_blob) { struct smb_trans2 tp; - uint16 setup = TRANSACT2_FINDFIRST; + uint16_t setup = TRANSACT2_FINDFIRST; NTSTATUS status; tp.in.max_setup = 0; @@ -181,12 +181,12 @@ static NTSTATUS smb_raw_search_first_blob(struct cli_tree *tree, static NTSTATUS smb_raw_search_next_blob(struct cli_tree *tree, TALLOC_CTX *mem_ctx, union smb_search_next *io, - uint16 info_level, + uint16_t info_level, DATA_BLOB *out_param_blob, DATA_BLOB *out_data_blob) { struct smb_trans2 tp; - uint16 setup = TRANSACT2_FINDNEXT; + uint16_t setup = TRANSACT2_FINDNEXT; NTSTATUS status; tp.in.max_setup = 0; @@ -236,7 +236,7 @@ static NTSTATUS smb_raw_search_next_blob(struct cli_tree *tree, static int parse_trans2_search(struct cli_tree *tree, TALLOC_CTX *mem_ctx, enum search_level level, - uint16 flags, + uint16_t flags, DATA_BLOB *blob, union smb_search_data *data) { @@ -450,8 +450,8 @@ static int parse_trans2_search(struct cli_tree *tree, static NTSTATUS smb_raw_t2search_backend(struct cli_tree *tree, TALLOC_CTX *mem_ctx, enum search_level level, - uint16 flags, - int16 count, + uint16_t flags, + int16_t count, DATA_BLOB *blob, void *private, BOOL (*callback)(void *private, union smb_search_data *file)) @@ -495,7 +495,7 @@ NTSTATUS smb_raw_search_first(struct cli_tree *tree, union smb_search_first *io, void *private, BOOL (*callback)(void *private, union smb_search_data *file)) { - uint16 info_level = 0; + uint16_t info_level = 0; DATA_BLOB p_blob, d_blob; NTSTATUS status; @@ -505,7 +505,7 @@ NTSTATUS smb_raw_search_first(struct cli_tree *tree, if (io->generic.level >= RAW_SEARCH_GENERIC) { return NT_STATUS_INVALID_LEVEL; } - info_level = (uint16)io->generic.level; + info_level = (uint16_t)io->generic.level; status = smb_raw_search_first_blob(tree, mem_ctx, io, info_level, &p_blob, &d_blob); @@ -539,7 +539,7 @@ NTSTATUS smb_raw_search_next(struct cli_tree *tree, union smb_search_next *io, void *private, BOOL (*callback)(void *private, union smb_search_data *file)) { - uint16 info_level = 0; + uint16_t info_level = 0; DATA_BLOB p_blob, d_blob; NTSTATUS status; @@ -549,7 +549,7 @@ NTSTATUS smb_raw_search_next(struct cli_tree *tree, if (io->generic.level >= RAW_SEARCH_GENERIC) { return NT_STATUS_INVALID_LEVEL; } - info_level = (uint16)io->generic.level; + info_level = (uint16_t)io->generic.level; status = smb_raw_search_next_blob(tree, mem_ctx, io, info_level, &p_blob, &d_blob); diff --git a/source4/libcli/raw/rawsetfileinfo.c b/source4/libcli/raw/rawsetfileinfo.c index d8fc78972d..3dcda401f5 100644 --- a/source4/libcli/raw/rawsetfileinfo.c +++ b/source4/libcli/raw/rawsetfileinfo.c @@ -132,12 +132,12 @@ static BOOL smb_raw_setinfo_backend(struct cli_tree *tree, ****************************************************************************/ static struct cli_request *smb_raw_setfileinfo_blob_send(struct cli_tree *tree, TALLOC_CTX *mem_ctx, - uint16 fnum, - uint16 info_level, + uint16_t fnum, + uint16_t info_level, DATA_BLOB *blob) { struct smb_trans2 tp; - uint16 setup = TRANSACT2_SETFILEINFO; + uint16_t setup = TRANSACT2_SETFILEINFO; tp.in.max_setup = 0; tp.in.flags = 0; @@ -166,11 +166,11 @@ static struct cli_request *smb_raw_setfileinfo_blob_send(struct cli_tree *tree, static struct cli_request *smb_raw_setpathinfo_blob_send(struct cli_tree *tree, TALLOC_CTX *mem_ctx, const char *fname, - uint16 info_level, + uint16_t info_level, DATA_BLOB *blob) { struct smb_trans2 tp; - uint16 setup = TRANSACT2_SETPATHINFO; + uint16_t setup = TRANSACT2_SETPATHINFO; tp.in.max_setup = 0; tp.in.flags = 0; diff --git a/source4/libcli/raw/rawtrans.c b/source4/libcli/raw/rawtrans.c index d13a1227dd..04dbcdc87d 100644 --- a/source4/libcli/raw/rawtrans.c +++ b/source4/libcli/raw/rawtrans.c @@ -119,9 +119,9 @@ NTSTATUS smb_raw_trans2_recv(struct cli_request *req, } while (1) { - uint16 param_count, param_ofs, param_disp; - uint16 data_count, data_ofs, data_disp; - uint16 total_data2, total_param2; + uint16_t param_count, param_ofs, param_disp; + uint16_t data_count, data_ofs, data_disp; + uint16_t total_data2, total_param2; /* parse out the total lengths again - they can shrink! */ total_data2 = SVAL(req->in.vwv, VWV(1)); diff --git a/source4/libcli/raw/smb_signing.c b/source4/libcli/raw/smb_signing.c index bb295ee991..989b5527aa 100644 --- a/source4/libcli/raw/smb_signing.c +++ b/source4/libcli/raw/smb_signing.c @@ -68,7 +68,7 @@ static BOOL set_smb_signing_real_common(struct cli_transport *transport) static void mark_packet_signed(struct cli_request *req) { - uint16 flags2; + uint16_t flags2; flags2 = SVAL(req->out.hdr, HDR_FLG2); flags2 |= FLAGS2_SMB_SECURITY_SIGNATURES; SSVAL(req->out.hdr, HDR_FLG2, flags2); -- cgit From fcd718c7d8a6850ae8719f23ed044b06b57501cd Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 25 May 2004 17:50:17 +0000 Subject: r890: convert samba4 to use [u]int8_t instead of [u]int8 metze (This used to be commit 2986c5f08c8f0c26a2ea7b6ce20aae025183109f) --- source4/libcli/raw/clispnego.c | 10 +++++----- source4/libcli/raw/rawacl.c | 4 ++-- source4/libcli/raw/rawdate.c | 8 ++++---- source4/libcli/raw/raweas.c | 2 +- source4/libcli/raw/rawrequest.c | 14 +++++++------- source4/libcli/raw/rawtrans.c | 2 +- 6 files changed, 20 insertions(+), 20 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clispnego.c b/source4/libcli/raw/clispnego.c index 7ad6be1006..ff7d45c8c1 100644 --- a/source4/libcli/raw/clispnego.c +++ b/source4/libcli/raw/clispnego.c @@ -26,7 +26,7 @@ generate a negTokenInit packet given a GUID, a list of supported OIDs (the mechanisms) and a principal name string */ -DATA_BLOB spnego_gen_negTokenInit(uint8 guid[16], +DATA_BLOB spnego_gen_negTokenInit(uint8_t guid[16], const char *OIDs[], const char *principal) { @@ -260,7 +260,7 @@ BOOL parse_negTokenTarg(DATA_BLOB blob, char *OIDs[ASN1_MAX_OIDS], DATA_BLOB *se /* generate a krb5 GSS-API wrapper packet given a ticket */ -DATA_BLOB spnego_gen_krb5_wrap(DATA_BLOB ticket, const uint8 tok_id[2]) +DATA_BLOB spnego_gen_krb5_wrap(DATA_BLOB ticket, const uint8_t tok_id[2]) { ASN1_DATA data; DATA_BLOB ret; @@ -288,7 +288,7 @@ DATA_BLOB spnego_gen_krb5_wrap(DATA_BLOB ticket, const uint8 tok_id[2]) /* parse a krb5 GSS-API wrapper packet giving a ticket */ -BOOL spnego_parse_krb5_wrap(DATA_BLOB blob, DATA_BLOB *ticket, uint8 tok_id[2]) +BOOL spnego_parse_krb5_wrap(DATA_BLOB blob, DATA_BLOB *ticket, uint8_t tok_id[2]) { BOOL ret; ASN1_DATA data; @@ -453,7 +453,7 @@ DATA_BLOB spnego_gen_auth_response(DATA_BLOB *reply, NTSTATUS nt_status, { ASN1_DATA data; DATA_BLOB ret; - uint8 negResult; + uint8_t negResult; if (NT_STATUS_IS_OK(nt_status)) { negResult = SPNEGO_NEG_RESULT_ACCEPT; @@ -496,7 +496,7 @@ BOOL spnego_parse_auth_response(DATA_BLOB blob, NTSTATUS nt_status, DATA_BLOB *auth) { ASN1_DATA data; - uint8 negResult; + uint8_t negResult; if (NT_STATUS_IS_OK(nt_status)) { negResult = SPNEGO_NEG_RESULT_ACCEPT; diff --git a/source4/libcli/raw/rawacl.c b/source4/libcli/raw/rawacl.c index cfc086c7ce..ca93591597 100644 --- a/source4/libcli/raw/rawacl.c +++ b/source4/libcli/raw/rawacl.c @@ -27,7 +27,7 @@ struct cli_request *smb_raw_query_secdesc_send(struct cli_tree *tree, struct smb_query_secdesc *query) { struct smb_nttrans nt; - uint8 params[8]; + uint8_t params[8]; nt.in.max_setup = 0; nt.in.max_param = 4; @@ -108,7 +108,7 @@ struct cli_request *smb_raw_set_secdesc_send(struct cli_tree *tree, struct smb_set_secdesc *set) { struct smb_nttrans nt; - uint8 params[8]; + uint8_t params[8]; struct ndr_push *ndr; struct cli_request *req; NTSTATUS status; diff --git a/source4/libcli/raw/rawdate.c b/source4/libcli/raw/rawdate.c index e80c376bf7..3b731d653b 100644 --- a/source4/libcli/raw/rawdate.c +++ b/source4/libcli/raw/rawdate.c @@ -27,7 +27,7 @@ put a dos date into a buffer (time/date format) This takes GMT time and puts local time for zone_offset in the buffer ********************************************************************/ void raw_push_dos_date(struct cli_transport *transport, - uint8 *buf, int offset, time_t unixdate) + uint8_t *buf, int offset, time_t unixdate) { push_dos_date(buf, offset, unixdate, transport->negotiate.server_zone); } @@ -56,7 +56,7 @@ void raw_push_dos_date3(struct cli_transport *transport, convert a dos date ********************************************************************/ time_t raw_pull_dos_date(struct cli_transport *transport, - const uint8 *date_ptr) + const uint8_t *date_ptr) { return pull_dos_date(date_ptr, transport->negotiate.server_zone); } @@ -65,7 +65,7 @@ time_t raw_pull_dos_date(struct cli_transport *transport, like raw_pull_dos_date() but the words are reversed ********************************************************************/ time_t raw_pull_dos_date2(struct cli_transport *transport, - const uint8 *date_ptr) + const uint8_t *date_ptr) { return pull_dos_date2(date_ptr, transport->negotiate.server_zone); } @@ -75,7 +75,7 @@ time_t raw_pull_dos_date2(struct cli_transport *transport, these arrive in server zone, with corresponding DST ******************************************************************/ time_t raw_pull_dos_date3(struct cli_transport *transport, - const uint8 *date_ptr) + const uint8_t *date_ptr) { return pull_dos_date3(date_ptr, transport->negotiate.server_zone); } diff --git a/source4/libcli/raw/raweas.c b/source4/libcli/raw/raweas.c index ae58790baa..e07fbcd288 100644 --- a/source4/libcli/raw/raweas.c +++ b/source4/libcli/raw/raweas.c @@ -68,7 +68,7 @@ uint_t ea_pull_struct(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, struct ea_struct *ea) { - uint8 nlen; + uint8_t nlen; uint16_t vlen; if (blob->length < 6) { diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index d7085ea3d2..fd2d85cc65 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -103,7 +103,7 @@ struct cli_request *cli_request_setup_nonsmb(struct cli_transport *transport, ui setup a SMB packet at transport level */ struct cli_request *cli_request_setup_transport(struct cli_transport *transport, - uint8 command, unsigned wct, unsigned buflen) + uint8_t command, unsigned wct, unsigned buflen) { struct cli_request *req; @@ -149,7 +149,7 @@ struct cli_request *cli_request_setup_transport(struct cli_transport *transport, way. This interface is used before a session is setup. */ struct cli_request *cli_request_setup_session(struct cli_session *session, - uint8 command, unsigned wct, unsigned buflen) + uint8_t command, unsigned wct, unsigned buflen) { struct cli_request *req; uint16_t flags2; @@ -189,7 +189,7 @@ struct cli_request *cli_request_setup_session(struct cli_session *session, setup a request for tree based commands */ struct cli_request *cli_request_setup(struct cli_tree *tree, - uint8 command, + uint8_t command, unsigned wct, unsigned buflen) { struct cli_request *req; @@ -343,7 +343,7 @@ static BOOL handle_oplock_break(struct cli_transport *transport, uint_t len, con if (transport->oplock.handler) { uint16_t tid = SVAL(hdr, HDR_TID); uint16_t fnum = SVAL(vwv,VWV(2)); - uint8 level = CVAL(vwv,VWV(3)+1); + uint8_t level = CVAL(vwv,VWV(3)+1); transport->oplock.handler(transport, tid, fnum, level, transport->oplock.private); } @@ -599,7 +599,7 @@ size_t cli_req_append_string_len(struct cli_request *req, const char *str, unsig size_t cli_req_append_ascii4(struct cli_request *req, const char *str, unsigned flags) { size_t size; - cli_req_append_bytes(req, (const uint8 *)"\4", 1); + cli_req_append_bytes(req, (const uint8_t *)"\4", 1); size = cli_req_append_string(req, str, flags); return size + 1; } @@ -623,7 +623,7 @@ size_t cli_req_append_blob(struct cli_request *req, const DATA_BLOB *blob) append raw bytes into the data portion of the request packet return the number of bytes added */ -size_t cli_req_append_bytes(struct cli_request *req, const uint8 *bytes, size_t byte_len) +size_t cli_req_append_bytes(struct cli_request *req, const uint8_t *bytes, size_t byte_len) { cli_req_grow_allocation(req, byte_len + req->out.data_size); memcpy(req->out.data + req->out.data_size, bytes, byte_len); @@ -635,7 +635,7 @@ size_t cli_req_append_bytes(struct cli_request *req, const uint8 *bytes, size_t append variable block (type 5 buffer) into the data portion of the request packet return the number of bytes added */ -size_t cli_req_append_var_block(struct cli_request *req, const uint8 *bytes, uint16_t byte_len) +size_t cli_req_append_var_block(struct cli_request *req, const uint8_t *bytes, uint16_t byte_len) { cli_req_grow_allocation(req, byte_len + 3 + req->out.data_size); SCVAL(req->out.data + req->out.data_size, 0, 5); diff --git a/source4/libcli/raw/rawtrans.c b/source4/libcli/raw/rawtrans.c index 04dbcdc87d..fb2abf3e2d 100644 --- a/source4/libcli/raw/rawtrans.c +++ b/source4/libcli/raw/rawtrans.c @@ -206,7 +206,7 @@ NTSTATUS smb_raw_trans_recv(struct cli_request *req, ****************************************************************************/ struct cli_request *smb_raw_trans_send_backend(struct cli_tree *tree, struct smb_trans2 *parms, - uint8 command) + uint8_t command) { int wct = 14 + parms->in.setup_count; struct cli_request *req; -- cgit From e80dad7561edbf65605e9c94ef8801e4416ba002 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 25 May 2004 18:12:55 +0000 Subject: r891: fix compile (This used to be commit 8b6c048a02b4be0ba9c67ed82973041dccdd5c51) --- source4/libcli/raw/clikrb5.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clikrb5.c b/source4/libcli/raw/clikrb5.c index 0d4fade295..1d9c02f7f4 100644 --- a/source4/libcli/raw/clikrb5.c +++ b/source4/libcli/raw/clikrb5.c @@ -37,10 +37,10 @@ /* * This function is not in the Heimdal mainline. */ - krb5_error_code krb5_set_real_time(krb5_context context, int32_t_t seconds, int32_t_t microseconds) + krb5_error_code krb5_set_real_time(krb5_context context, int32_t seconds, int32_t microseconds) { krb5_error_code ret; - int32_t_t sec, usec; + int32_t sec, usec; ret = krb5_us_timeofday(context, &sec, &usec); if (ret) -- cgit From 47864891ffd6309764fdc3a5227ec2e83c6f7107 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 26 May 2004 01:13:12 +0000 Subject: r893: a few more _t conversions (This used to be commit 66eb46dbb1486c5916194bf6b303cf16373a272a) --- source4/libcli/raw/clioplock.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clioplock.c b/source4/libcli/raw/clioplock.c index eacfd411a0..0cd6adb41f 100644 --- a/source4/libcli/raw/clioplock.c +++ b/source4/libcli/raw/clioplock.c @@ -50,7 +50,7 @@ BOOL cli_oplock_ack(struct cli_tree *tree, uint16_t fnum, uint16_t ack_level) set the oplock handler for a connection ****************************************************************************/ void cli_oplock_handler(struct cli_transport *transport, - BOOL (*handler)(struct cli_transport *, uint16, uint16, uint8, void *), + BOOL (*handler)(struct cli_transport *, uint16_t, uint16_t, uint8_t, void *), void *private) { transport->oplock.handler = handler; -- cgit From 45e93c19ef95978f908f5b14962770510634cd3b Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sat, 29 May 2004 08:11:46 +0000 Subject: r943: change samba4 to use 'uint8_t' instead of 'unsigned char' metze (This used to be commit b5378803fdcb3b3afe7c2932a38828e83470f61a) --- source4/libcli/raw/smb_signing.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/smb_signing.c b/source4/libcli/raw/smb_signing.c index 989b5527aa..c82946ac53 100644 --- a/source4/libcli/raw/smb_signing.c +++ b/source4/libcli/raw/smb_signing.c @@ -98,7 +98,7 @@ static BOOL signing_good(struct cli_request *req, BOOL good) ************************************************************/ static void cli_request_simple_sign_outgoing_message(struct cli_request *req) { - unsigned char calc_md5_mac[16]; + uint8_t calc_md5_mac[16]; struct MD5Context md5_ctx; struct smb_basic_signing_context *data = req->transport->negotiate.sign_info.signing_context; @@ -150,9 +150,9 @@ static void cli_request_simple_sign_outgoing_message(struct cli_request *req) static BOOL cli_request_simple_check_incoming_message(struct cli_request *req) { BOOL good; - unsigned char calc_md5_mac[16]; - unsigned char server_sent_mac[8]; - unsigned char sequence_buf[8]; + uint8_t calc_md5_mac[16]; + uint8_t server_sent_mac[8]; + uint8_t sequence_buf[8]; struct MD5Context md5_ctx; struct smb_basic_signing_context *data = req->transport->negotiate.sign_info.signing_context; const size_t offset_end_of_sig = (HDR_SS_FIELD + 8); -- cgit From 98d291423ff581786a369ce373c861f94c654aa0 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 1 Jun 2004 08:30:34 +0000 Subject: r961: convert 'uchar' to 'uint8_t' metze (This used to be commit 9f914e4af99e18b469d4cf9d8b1514a2bd28ddec) --- source4/libcli/raw/clisession.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index b3876f2490..641eff053e 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -252,7 +252,7 @@ static void use_nt1_session_keys(struct cli_session *session, const char *password, const DATA_BLOB *nt_response) { struct cli_transport *transport = session->transport; - uchar nt_hash[16]; + uint8_t nt_hash[16]; DATA_BLOB session_key = data_blob(NULL, 16); E_md4hash(password, nt_hash); -- cgit From 770e3307ce3da928762e15a136c562df86a9c799 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 1 Jun 2004 10:12:52 +0000 Subject: r962: convert 'unsigned' and 'unsigned int' to uint_t metze (This used to be commit 57151e80eb1090281401930c8fe25b20a8cf3a38) --- source4/libcli/raw/clikrb5.c | 4 ++-- source4/libcli/raw/rawrequest.c | 32 ++++++++++++++++---------------- 2 files changed, 18 insertions(+), 18 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clikrb5.c b/source4/libcli/raw/clikrb5.c index 1d9c02f7f4..ba3e9ccd17 100644 --- a/source4/libcli/raw/clikrb5.c +++ b/source4/libcli/raw/clikrb5.c @@ -278,9 +278,9 @@ static krb5_error_code ads_krb5_mk_req(krb5_context context, } /* cope with the ticket being in the future due to clock skew */ - if ((unsigned)credsp->times.starttime > time(NULL)) { + if ((uint_t)credsp->times.starttime > time(NULL)) { time_t t = time(NULL); - int time_offset = (unsigned)credsp->times.starttime - t; + int time_offset = (uint_t)credsp->times.starttime - t; DEBUG(4,("Advancing clock by %d seconds to cope with clock skew\n", time_offset)); krb5_set_real_time(context, t + time_offset + 1, 0); } diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index fd2d85cc65..c31f07505f 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -103,7 +103,7 @@ struct cli_request *cli_request_setup_nonsmb(struct cli_transport *transport, ui setup a SMB packet at transport level */ struct cli_request *cli_request_setup_transport(struct cli_transport *transport, - uint8_t command, unsigned wct, unsigned buflen) + uint8_t command, uint_t wct, uint_t buflen) { struct cli_request *req; @@ -149,7 +149,7 @@ struct cli_request *cli_request_setup_transport(struct cli_transport *transport, way. This interface is used before a session is setup. */ struct cli_request *cli_request_setup_session(struct cli_session *session, - uint8_t command, unsigned wct, unsigned buflen) + uint8_t command, uint_t wct, uint_t buflen) { struct cli_request *req; uint16_t flags2; @@ -190,7 +190,7 @@ struct cli_request *cli_request_setup_session(struct cli_session *session, */ struct cli_request *cli_request_setup(struct cli_tree *tree, uint8_t command, - unsigned wct, unsigned buflen) + uint_t wct, uint_t buflen) { struct cli_request *req; @@ -210,7 +210,7 @@ struct cli_request *cli_request_setup(struct cli_tree *tree, To cope with this req->out.ptr is supplied. This will be updated to point at the same offset into the packet as before this call */ -static void cli_req_grow_allocation(struct cli_request *req, unsigned new_size) +static void cli_req_grow_allocation(struct cli_request *req, uint_t new_size) { int delta; char *buf2; @@ -251,7 +251,7 @@ static void cli_req_grow_allocation(struct cli_request *req, unsigned new_size) To cope with this req->out.ptr is supplied. This will be updated to point at the same offset into the packet as before this call */ -static void cli_req_grow_data(struct cli_request *req, unsigned new_size) +static void cli_req_grow_data(struct cli_request *req, uint_t new_size) { int delta; @@ -524,7 +524,7 @@ BOOL cli_request_is_error(struct cli_request *req) return the number of bytes added to the packet */ -size_t cli_req_append_string(struct cli_request *req, const char *str, unsigned flags) +size_t cli_req_append_string(struct cli_request *req, const char *str, uint_t flags) { size_t len; @@ -555,7 +555,7 @@ size_t cli_req_append_string(struct cli_request *req, const char *str, unsigned this is used in places where the non-terminated string byte length is placed in the packet as a separate field */ -size_t cli_req_append_string_len(struct cli_request *req, const char *str, unsigned flags, int *len) +size_t cli_req_append_string_len(struct cli_request *req, const char *str, uint_t flags, int *len) { int diff = 0; size_t ret; @@ -596,7 +596,7 @@ size_t cli_req_append_string_len(struct cli_request *req, const char *str, unsig if dest_len is -1 then no limit applies */ -size_t cli_req_append_ascii4(struct cli_request *req, const char *str, unsigned flags) +size_t cli_req_append_ascii4(struct cli_request *req, const char *str, uint_t flags) { size_t size; cli_req_append_bytes(req, (const uint8_t *)"\4", 1); @@ -662,7 +662,7 @@ size_t cli_req_append_var_block(struct cli_request *req, const uint8_t *bytes, u of bytes consumed in the packet is returned */ static size_t cli_req_pull_ucs2(struct cli_request *req, TALLOC_CTX *mem_ctx, - char **dest, const char *src, int byte_len, unsigned flags) + char **dest, const char *src, int byte_len, uint_t flags) { int src_len, src_len2, alignment=0; ssize_t ret; @@ -719,7 +719,7 @@ static size_t cli_req_pull_ucs2(struct cli_request *req, TALLOC_CTX *mem_ctx, of bytes consumed in the packet is returned */ size_t cli_req_pull_ascii(struct cli_request *req, TALLOC_CTX *mem_ctx, - char **dest, const char *src, int byte_len, unsigned flags) + char **dest, const char *src, int byte_len, uint_t flags) { int src_len, src_len2; ssize_t ret; @@ -762,7 +762,7 @@ size_t cli_req_pull_ascii(struct cli_request *req, TALLOC_CTX *mem_ctx, of bytes consumed in the packet is returned */ size_t cli_req_pull_string(struct cli_request *req, TALLOC_CTX *mem_ctx, - char **dest, const char *src, int byte_len, unsigned flags) + char **dest, const char *src, int byte_len, uint_t flags) { if (!(flags & STR_ASCII) && (((flags & STR_UNICODE) || (req->flags2 & FLAGS2_UNICODE_STRINGS)))) { @@ -860,7 +860,7 @@ NTTIME cli_pull_nttime(void *base, uint16_t offset) */ static size_t cli_blob_pull_ucs2(TALLOC_CTX* mem_ctx, DATA_BLOB *blob, const char **dest, - const char *src, int byte_len, unsigned flags) + const char *src, int byte_len, uint_t flags) { int src_len, src_len2, alignment=0; ssize_t ret; @@ -919,7 +919,7 @@ static size_t cli_blob_pull_ucs2(TALLOC_CTX* mem_ctx, */ static size_t cli_blob_pull_ascii(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const char **dest, - const char *src, int byte_len, unsigned flags) + const char *src, int byte_len, uint_t flags) { int src_len, src_len2; ssize_t ret; @@ -968,7 +968,7 @@ size_t cli_blob_pull_string(struct cli_session *session, DATA_BLOB *blob, WIRE_STRING *dest, uint16_t len_offset, uint16_t str_offset, - unsigned flags) + uint_t flags) { int extra; dest->s = NULL; @@ -1023,7 +1023,7 @@ size_t cli_blob_pull_unix_string(struct cli_session *session, DATA_BLOB *blob, const char **dest, uint16_t str_offset, - unsigned flags) + uint_t flags) { int extra = 0; *dest = NULL; @@ -1057,7 +1057,7 @@ size_t cli_blob_pull_unix_string(struct cli_session *session, */ size_t cli_blob_append_string(struct cli_session *session, TALLOC_CTX *mem_ctx, DATA_BLOB *blob, - const char *str, unsigned flags) + const char *str, uint_t flags) { size_t max_len; int len; -- cgit From 73c077d37b69267646986ea3fc2ed99d7ef15d4c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 9 Jun 2004 00:07:59 +0000 Subject: r1091: Added in timing tests for deferred opens. Added extra debug info to signing mistakes. Jeremy. (This used to be commit 5c3a2417cfe1bdbdfb35d933d49f77f6696790b3) --- source4/libcli/raw/smb_signing.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/smb_signing.c b/source4/libcli/raw/smb_signing.c index c82946ac53..a39f33c290 100644 --- a/source4/libcli/raw/smb_signing.c +++ b/source4/libcli/raw/smb_signing.c @@ -188,7 +188,7 @@ static BOOL cli_request_simple_check_incoming_message(struct cli_request *req) } if (good && i != 1) { - DEBUG(0,("SIGNING OFFSET %d\n", i)); + DEBUG(0,("SIGNING OFFSET %d (should be %d)\n", i, req->seq_num+1)); } if (!good) { -- cgit From bf598954f75bfd924b9aa22649975b372c74a49e Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 19 Jun 2004 08:15:41 +0000 Subject: r1198: Merge the Samba 3.0 ntlm_auth, including the kerberos and SPENGO parts. I have moved the SPNEGO and Kerberos code into libcli/auth, and intend to refactor them into the same format as NTLMSSP. Andrew Bartlett (This used to be commit 58da78a7460d5d0a4abee7d7b84799c228e6bc0b) --- source4/libcli/raw/clikrb5.c | 421 -------------------------------- source4/libcli/raw/clispnego.c | 539 ----------------------------------------- 2 files changed, 960 deletions(-) delete mode 100644 source4/libcli/raw/clikrb5.c delete mode 100644 source4/libcli/raw/clispnego.c (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clikrb5.c b/source4/libcli/raw/clikrb5.c deleted file mode 100644 index ba3e9ccd17..0000000000 --- a/source4/libcli/raw/clikrb5.c +++ /dev/null @@ -1,421 +0,0 @@ -/* - Unix SMB/CIFS implementation. - simple kerberos5 routines for active directory - Copyright (C) Andrew Tridgell 2001 - Copyright (C) Luke Howard 2002-2003 - - 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. -*/ - -#include "includes.h" - -#ifdef HAVE_KRB5 - -#ifdef HAVE_KRB5_KEYBLOCK_KEYVALUE -#define KRB5_KEY_TYPE(k) ((k)->keytype) -#define KRB5_KEY_LENGTH(k) ((k)->keyvalue.length) -#define KRB5_KEY_DATA(k) ((k)->keyvalue.data) -#else -#define KRB5_KEY_TYPE(k) ((k)->enctype) -#define KRB5_KEY_LENGTH(k) ((k)->length) -#define KRB5_KEY_DATA(k) ((k)->contents) -#endif /* HAVE_KRB5_KEYBLOCK_KEYVALUE */ - -#ifndef HAVE_KRB5_SET_REAL_TIME -/* - * This function is not in the Heimdal mainline. - */ - krb5_error_code krb5_set_real_time(krb5_context context, int32_t seconds, int32_t microseconds) -{ - krb5_error_code ret; - int32_t sec, usec; - - ret = krb5_us_timeofday(context, &sec, &usec); - if (ret) - return ret; - - context->kdc_sec_offset = seconds - sec; - context->kdc_usec_offset = microseconds - usec; - - return 0; -} -#endif - -#if defined(HAVE_KRB5_SET_DEFAULT_IN_TKT_ETYPES) && !defined(HAVE_KRB5_SET_DEFAULT_TGS_KTYPES) - krb5_error_code krb5_set_default_tgs_ktypes(krb5_context ctx, const krb5_enctype *enc) -{ - return krb5_set_default_in_tkt_etypes(ctx, enc); -} -#endif - -#if defined(HAVE_ADDR_TYPE_IN_KRB5_ADDRESS) -/* HEIMDAL */ - void setup_kaddr( krb5_address *pkaddr, struct sockaddr *paddr) -{ - pkaddr->addr_type = KRB5_ADDRESS_INET; - pkaddr->address.length = sizeof(((struct sockaddr_in *)paddr)->sin_addr); - pkaddr->address.data = (char *)&(((struct sockaddr_in *)paddr)->sin_addr); -} -#elif defined(HAVE_ADDRTYPE_IN_KRB5_ADDRESS) -/* MIT */ - void setup_kaddr( krb5_address *pkaddr, struct sockaddr *paddr) -{ - pkaddr->addrtype = ADDRTYPE_INET; - pkaddr->length = sizeof(((struct sockaddr_in *)paddr)->sin_addr); - pkaddr->contents = (krb5_octet *)&(((struct sockaddr_in *)paddr)->sin_addr); -} -#else - __ERROR__XX__UNKNOWN_ADDRTYPE -#endif - -#if defined(HAVE_KRB5_PRINCIPAL2SALT) && defined(HAVE_KRB5_USE_ENCTYPE) && defined(HAVE_KRB5_STRING_TO_KEY) - int create_kerberos_key_from_string(krb5_context context, - krb5_principal host_princ, - krb5_data *password, - krb5_keyblock *key, - krb5_enctype enctype) -{ - int ret; - krb5_data salt; - krb5_encrypt_block eblock; - - ret = krb5_principal2salt(context, host_princ, &salt); - if (ret) { - DEBUG(1,("krb5_principal2salt failed (%s)\n", error_message(ret))); - return ret; - } - krb5_use_enctype(context, &eblock, enctype); - ret = krb5_string_to_key(context, &eblock, key, password, &salt); - SAFE_FREE(salt.data); - return ret; -} -#elif defined(HAVE_KRB5_GET_PW_SALT) && defined(HAVE_KRB5_STRING_TO_KEY_SALT) - int create_kerberos_key_from_string(krb5_context context, - krb5_principal host_princ, - krb5_data *password, - krb5_keyblock *key, - krb5_enctype enctype) -{ - int ret; - krb5_salt salt; - - ret = krb5_get_pw_salt(context, host_princ, &salt); - if (ret) { - DEBUG(1,("krb5_get_pw_salt failed (%s)\n", error_message(ret))); - return ret; - } - return krb5_string_to_key_salt(context, enctype, password->data, - salt, key); -} -#else - __ERROR_XX_UNKNOWN_CREATE_KEY_FUNCTIONS -#endif - -#if defined(HAVE_KRB5_GET_PERMITTED_ENCTYPES) -krb5_error_code get_kerberos_allowed_etypes(krb5_context context, - krb5_enctype **enctypes) -{ - return krb5_get_permitted_enctypes(context, enctypes); -} -#elif defined(HAVE_KRB5_GET_DEFAULT_IN_TKT_ETYPES) -krb5_error_code get_kerberos_allowed_etypes(krb5_context context, - krb5_enctype **enctypes) -{ - return krb5_get_default_in_tkt_etypes(context, enctypes); -} -#else -#error UNKNOWN_GET_ENCTYPES_FUNCTIONS -#endif - - void free_kerberos_etypes(krb5_context context, - krb5_enctype *enctypes) -{ -#if defined(HAVE_KRB5_FREE_KTYPES) - krb5_free_ktypes(context, enctypes); - return; -#else - SAFE_FREE(enctypes); - return; -#endif -} - -#if defined(HAVE_KRB5_AUTH_CON_SETKEY) && !defined(HAVE_KRB5_AUTH_CON_SETUSERUSERKEY) - krb5_error_code krb5_auth_con_setuseruserkey(krb5_context context, - krb5_auth_context auth_context, - krb5_keyblock *keyblock) -{ - return krb5_auth_con_setkey(context, auth_context, keyblock); -} -#endif - - void get_auth_data_from_tkt(DATA_BLOB *auth_data, krb5_ticket *tkt) -{ -#if defined(HAVE_KRB5_TKT_ENC_PART2) - if (tkt->enc_part2) - *auth_data = data_blob(tkt->enc_part2->authorization_data[0]->contents, - tkt->enc_part2->authorization_data[0]->length); -#else - if (tkt->ticket.authorization_data && tkt->ticket.authorization_data->len) - *auth_data = data_blob(tkt->ticket.authorization_data->val->ad_data.data, - tkt->ticket.authorization_data->val->ad_data.length); -#endif -} - - krb5_const_principal get_principal_from_tkt(krb5_ticket *tkt) -{ -#if defined(HAVE_KRB5_TKT_ENC_PART2) - return tkt->enc_part2->client; -#else - return tkt->client; -#endif -} - -#if !defined(HAVE_KRB5_LOCATE_KDC) - krb5_error_code krb5_locate_kdc(krb5_context ctx, const krb5_data *realm, struct sockaddr **addr_pp, int *naddrs, int get_masters) -{ - krb5_krbhst_handle hnd; - krb5_krbhst_info *hinfo; - krb5_error_code rc; - int num_kdcs, i; - struct sockaddr *sa; - - *addr_pp = NULL; - *naddrs = 0; - - rc = krb5_krbhst_init(ctx, realm->data, KRB5_KRBHST_KDC, &hnd); - if (rc) { - DEBUG(0, ("krb5_locate_kdc: krb5_krbhst_init failed (%s)\n", error_message(rc))); - return rc; - } - - for ( num_kdcs = 0; (rc = krb5_krbhst_next(ctx, hnd, &hinfo) == 0); num_kdcs++) - ; - - krb5_krbhst_reset(ctx, hnd); - - if (!num_kdcs) { - DEBUG(0, ("krb5_locate_kdc: zero kdcs found !\n")); - krb5_krbhst_free(ctx, hnd); - return -1; - } - - sa = malloc( sizeof(struct sockaddr) * num_kdcs ); - if (!sa) { - DEBUG(0, ("krb5_locate_kdc: malloc failed\n")); - krb5_krbhst_free(ctx, hnd); - naddrs = 0; - return -1; - } - - memset(*addr_pp, '\0', sizeof(struct sockaddr) * num_kdcs ); - - for (i = 0; i < num_kdcs && (rc = krb5_krbhst_next(ctx, hnd, &hinfo) == 0); i++) { - if (hinfo->ai->ai_family == AF_INET) - memcpy(&sa[i], hinfo->ai->ai_addr, sizeof(struct sockaddr)); - } - - krb5_krbhst_free(ctx, hnd); - - *naddrs = num_kdcs; - *addr_pp = sa; - return 0; -} -#endif - -/* - we can't use krb5_mk_req because w2k wants the service to be in a particular format -*/ -static krb5_error_code ads_krb5_mk_req(krb5_context context, - krb5_auth_context *auth_context, - const krb5_flags ap_req_options, - const char *principal, - krb5_ccache ccache, - krb5_data *outbuf) -{ - krb5_error_code retval; - krb5_principal server; - krb5_creds * credsp; - krb5_creds creds; - krb5_data in_data; - - retval = krb5_parse_name(context, principal, &server); - if (retval) { - DEBUG(1,("Failed to parse principal %s\n", principal)); - return retval; - } - - /* obtain ticket & session key */ - ZERO_STRUCT(creds); - if ((retval = krb5_copy_principal(context, server, &creds.server))) { - DEBUG(1,("krb5_copy_principal failed (%s)\n", - error_message(retval))); - goto cleanup_princ; - } - - if ((retval = krb5_cc_get_principal(context, ccache, &creds.client))) { - DEBUG(1,("krb5_cc_get_principal failed (%s)\n", - error_message(retval))); - goto cleanup_creds; - } - - if ((retval = krb5_get_credentials(context, 0, - ccache, &creds, &credsp))) { - DEBUG(1,("krb5_get_credentials failed for %s (%s)\n", - principal, error_message(retval))); - goto cleanup_creds; - } - - /* cope with the ticket being in the future due to clock skew */ - if ((uint_t)credsp->times.starttime > time(NULL)) { - time_t t = time(NULL); - int time_offset = (uint_t)credsp->times.starttime - t; - DEBUG(4,("Advancing clock by %d seconds to cope with clock skew\n", time_offset)); - krb5_set_real_time(context, t + time_offset + 1, 0); - } - - in_data.length = 0; - retval = krb5_mk_req_extended(context, auth_context, ap_req_options, - &in_data, credsp, outbuf); - if (retval) { - DEBUG(1,("krb5_mk_req_extended failed (%s)\n", - error_message(retval))); - } - - krb5_free_creds(context, credsp); - -cleanup_creds: - krb5_free_cred_contents(context, &creds); - -cleanup_princ: - krb5_free_principal(context, server); - - return retval; -} - -/* - get a kerberos5 ticket for the given service -*/ -int cli_krb5_get_ticket(const char *principal, time_t time_offset, - DATA_BLOB *ticket, DATA_BLOB *session_key_krb5) -{ - krb5_error_code retval; - krb5_data packet; - krb5_ccache ccdef; - krb5_context context; - krb5_auth_context auth_context = NULL; - krb5_enctype enc_types[] = { -#ifdef ENCTYPE_ARCFOUR_HMAC - ENCTYPE_ARCFOUR_HMAC, -#endif - ENCTYPE_DES_CBC_MD5, - ENCTYPE_DES_CBC_CRC, - ENCTYPE_NULL}; - - retval = krb5_init_context(&context); - if (retval) { - DEBUG(1,("krb5_init_context failed (%s)\n", - error_message(retval))); - goto failed; - } - - if (time_offset != 0) { - krb5_set_real_time(context, time(NULL) + time_offset, 0); - } - - if ((retval = krb5_cc_default(context, &ccdef))) { - DEBUG(1,("krb5_cc_default failed (%s)\n", - error_message(retval))); - goto failed; - } - - if ((retval = krb5_set_default_tgs_ktypes(context, enc_types))) { - DEBUG(1,("krb5_set_default_tgs_ktypes failed (%s)\n", - error_message(retval))); - goto failed; - } - - if ((retval = ads_krb5_mk_req(context, - &auth_context, - AP_OPTS_USE_SUBKEY, - principal, - ccdef, &packet))) { - goto failed; - } - - get_krb5_smb_session_key(context, auth_context, session_key_krb5, False); - - *ticket = data_blob(packet.data, packet.length); - -/* Hmm, heimdal dooesn't have this - what's the correct call? */ -#ifdef HAVE_KRB5_FREE_DATA_CONTENTS - krb5_free_data_contents(context, &packet); -#endif - -failed: - if ( context ) - krb5_free_context(context); - - return retval; -} - - BOOL get_krb5_smb_session_key(krb5_context context, krb5_auth_context auth_context, DATA_BLOB *session_key, BOOL remote) - { - krb5_keyblock *skey; - krb5_error_code err; - BOOL ret = False; - - memset(session_key, 0, 16); - - if (remote) - err = krb5_auth_con_getremotesubkey(context, auth_context, &skey); - else - err = krb5_auth_con_getlocalsubkey(context, auth_context, &skey); - if (err == 0 && skey != NULL) { - DEBUG(10, ("Got KRB5 session key of length %d\n", KRB5_KEY_LENGTH(skey))); - *session_key = data_blob(KRB5_KEY_DATA(skey), KRB5_KEY_LENGTH(skey)); - dump_data_pw("KRB5 Session Key:\n", session_key->data, session_key->length); - - ret = True; - - krb5_free_keyblock(context, skey); - } else { - DEBUG(10, ("KRB5 error getting session key %d\n", err)); - } - - return ret; - } - - -#if defined(HAVE_KRB5_PRINCIPAL_GET_COMP_STRING) && !defined(HAVE_KRB5_PRINC_COMPONENT) - const krb5_data *krb5_princ_component(krb5_context context, krb5_principal principal, int i ) -{ - static krb5_data kdata; - - kdata.data = krb5_principal_get_comp_string(context, principal, i); - kdata.length = strlen(kdata.data); - return &kdata; -} -#endif - -#else /* HAVE_KRB5 */ -/* this saves a few linking headaches */ -int cli_krb5_get_ticket(const char *principal, time_t time_offset, - DATA_BLOB *ticket, DATA_BLOB *session_key_krb5) -{ - DEBUG(0,("NO KERBEROS SUPPORT\n")); - return 1; -} - -#endif diff --git a/source4/libcli/raw/clispnego.c b/source4/libcli/raw/clispnego.c deleted file mode 100644 index ff7d45c8c1..0000000000 --- a/source4/libcli/raw/clispnego.c +++ /dev/null @@ -1,539 +0,0 @@ -/* - Unix SMB/CIFS implementation. - simple kerberos5/SPNEGO routines - Copyright (C) Andrew Tridgell 2001 - Copyright (C) Jim McDonough 2002 - Copyright (C) Luke Howard 2003 - - 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. -*/ - -#include "includes.h" - -/* - generate a negTokenInit packet given a GUID, a list of supported - OIDs (the mechanisms) and a principal name string -*/ -DATA_BLOB spnego_gen_negTokenInit(uint8_t guid[16], - const char *OIDs[], - const char *principal) -{ - int i; - ASN1_DATA data; - DATA_BLOB ret; - - memset(&data, 0, sizeof(data)); - - asn1_write(&data, guid, 16); - asn1_push_tag(&data,ASN1_APPLICATION(0)); - asn1_write_OID(&data,OID_SPNEGO); - asn1_push_tag(&data,ASN1_CONTEXT(0)); - asn1_push_tag(&data,ASN1_SEQUENCE(0)); - - asn1_push_tag(&data,ASN1_CONTEXT(0)); - asn1_push_tag(&data,ASN1_SEQUENCE(0)); - for (i=0; OIDs[i]; i++) { - asn1_write_OID(&data,OIDs[i]); - } - asn1_pop_tag(&data); - asn1_pop_tag(&data); - - asn1_push_tag(&data, ASN1_CONTEXT(3)); - asn1_push_tag(&data, ASN1_SEQUENCE(0)); - asn1_push_tag(&data, ASN1_CONTEXT(0)); - asn1_write_GeneralString(&data,principal); - asn1_pop_tag(&data); - asn1_pop_tag(&data); - asn1_pop_tag(&data); - - asn1_pop_tag(&data); - asn1_pop_tag(&data); - - asn1_pop_tag(&data); - - if (data.has_error) { - DEBUG(1,("Failed to build negTokenInit at offset %d\n", (int)data.ofs)); - asn1_free(&data); - } - - ret = data_blob(data.data, data.length); - asn1_free(&data); - - return ret; -} - -/* - Generate a negTokenInit as used by the client side ... It has a mechType - (OID), and a mechToken (a security blob) ... - - Really, we need to break out the NTLMSSP stuff as well, because it could be - raw in the packets! -*/ -DATA_BLOB gen_negTokenInit(const char *OID, DATA_BLOB blob) -{ - ASN1_DATA data; - DATA_BLOB ret; - - memset(&data, 0, sizeof(data)); - - asn1_push_tag(&data, ASN1_APPLICATION(0)); - asn1_write_OID(&data,OID_SPNEGO); - asn1_push_tag(&data, ASN1_CONTEXT(0)); - asn1_push_tag(&data, ASN1_SEQUENCE(0)); - - asn1_push_tag(&data, ASN1_CONTEXT(0)); - asn1_push_tag(&data, ASN1_SEQUENCE(0)); - asn1_write_OID(&data, OID); - asn1_pop_tag(&data); - asn1_pop_tag(&data); - - asn1_push_tag(&data, ASN1_CONTEXT(2)); - asn1_write_OctetString(&data,blob.data,blob.length); - asn1_pop_tag(&data); - - asn1_pop_tag(&data); - asn1_pop_tag(&data); - - asn1_pop_tag(&data); - - if (data.has_error) { - DEBUG(1,("Failed to build negTokenInit at offset %d\n", (int)data.ofs)); - asn1_free(&data); - } - - ret = data_blob(data.data, data.length); - asn1_free(&data); - - return ret; -} - -/* - parse a negTokenInit packet giving a GUID, a list of supported - OIDs (the mechanisms) and a principal name string -*/ -BOOL spnego_parse_negTokenInit(DATA_BLOB blob, - char *OIDs[ASN1_MAX_OIDS], - char **principal) -{ - int i; - BOOL ret; - ASN1_DATA data; - - asn1_load(&data, blob); - - asn1_start_tag(&data,ASN1_APPLICATION(0)); - asn1_check_OID(&data,OID_SPNEGO); - asn1_start_tag(&data,ASN1_CONTEXT(0)); - asn1_start_tag(&data,ASN1_SEQUENCE(0)); - - asn1_start_tag(&data,ASN1_CONTEXT(0)); - asn1_start_tag(&data,ASN1_SEQUENCE(0)); - for (i=0; asn1_tag_remaining(&data) > 0 && i < ASN1_MAX_OIDS; i++) { - char *aoid = NULL; - asn1_read_OID(&data,&aoid); - OIDs[i] = aoid; - } - OIDs[i] = NULL; - asn1_end_tag(&data); - asn1_end_tag(&data); - - asn1_start_tag(&data, ASN1_CONTEXT(3)); - asn1_start_tag(&data, ASN1_SEQUENCE(0)); - asn1_start_tag(&data, ASN1_CONTEXT(0)); - asn1_read_GeneralString(&data,principal); - asn1_end_tag(&data); - asn1_end_tag(&data); - asn1_end_tag(&data); - - asn1_end_tag(&data); - asn1_end_tag(&data); - - asn1_end_tag(&data); - - ret = !data.has_error; - asn1_free(&data); - return ret; -} - - -/* - generate a negTokenTarg packet given a list of OIDs and a security blob -*/ -DATA_BLOB gen_negTokenTarg(const char *OIDs[], DATA_BLOB blob) -{ - int i; - ASN1_DATA data; - DATA_BLOB ret; - - memset(&data, 0, sizeof(data)); - - asn1_push_tag(&data, ASN1_APPLICATION(0)); - asn1_write_OID(&data,OID_SPNEGO); - asn1_push_tag(&data, ASN1_CONTEXT(0)); - asn1_push_tag(&data, ASN1_SEQUENCE(0)); - - asn1_push_tag(&data, ASN1_CONTEXT(0)); - asn1_push_tag(&data, ASN1_SEQUENCE(0)); - for (i=0; OIDs[i]; i++) { - asn1_write_OID(&data,OIDs[i]); - } - asn1_pop_tag(&data); - asn1_pop_tag(&data); - - asn1_push_tag(&data, ASN1_CONTEXT(2)); - asn1_write_OctetString(&data,blob.data,blob.length); - asn1_pop_tag(&data); - - asn1_pop_tag(&data); - asn1_pop_tag(&data); - - asn1_pop_tag(&data); - - if (data.has_error) { - DEBUG(1,("Failed to build negTokenTarg at offset %d\n", (int)data.ofs)); - asn1_free(&data); - } - - ret = data_blob(data.data, data.length); - asn1_free(&data); - - return ret; -} - - -/* - parse a negTokenTarg packet giving a list of OIDs and a security blob -*/ -BOOL parse_negTokenTarg(DATA_BLOB blob, char *OIDs[ASN1_MAX_OIDS], DATA_BLOB *secblob) -{ - int i; - ASN1_DATA data; - - asn1_load(&data, blob); - asn1_start_tag(&data, ASN1_APPLICATION(0)); - asn1_check_OID(&data,OID_SPNEGO); - asn1_start_tag(&data, ASN1_CONTEXT(0)); - asn1_start_tag(&data, ASN1_SEQUENCE(0)); - - asn1_start_tag(&data, ASN1_CONTEXT(0)); - asn1_start_tag(&data, ASN1_SEQUENCE(0)); - for (i=0; asn1_tag_remaining(&data) > 0 && i < ASN1_MAX_OIDS; i++) { - char *aoid = NULL; - asn1_read_OID(&data,&aoid); - OIDs[i] = aoid; - } - OIDs[i] = NULL; - asn1_end_tag(&data); - asn1_end_tag(&data); - - asn1_start_tag(&data, ASN1_CONTEXT(2)); - asn1_read_OctetString(&data,secblob); - asn1_end_tag(&data); - - asn1_end_tag(&data); - asn1_end_tag(&data); - - asn1_end_tag(&data); - - if (data.has_error) { - DEBUG(1,("Failed to parse negTokenTarg at offset %d\n", (int)data.ofs)); - asn1_free(&data); - return False; - } - - asn1_free(&data); - return True; -} - -/* - generate a krb5 GSS-API wrapper packet given a ticket -*/ -DATA_BLOB spnego_gen_krb5_wrap(DATA_BLOB ticket, const uint8_t tok_id[2]) -{ - ASN1_DATA data; - DATA_BLOB ret; - - memset(&data, 0, sizeof(data)); - - asn1_push_tag(&data, ASN1_APPLICATION(0)); - asn1_write_OID(&data, OID_KERBEROS5); - - asn1_write(&data, tok_id, 2); - asn1_write(&data, ticket.data, ticket.length); - asn1_pop_tag(&data); - - if (data.has_error) { - DEBUG(1,("Failed to build krb5 wrapper at offset %d\n", (int)data.ofs)); - asn1_free(&data); - } - - ret = data_blob(data.data, data.length); - asn1_free(&data); - - return ret; -} - -/* - parse a krb5 GSS-API wrapper packet giving a ticket -*/ -BOOL spnego_parse_krb5_wrap(DATA_BLOB blob, DATA_BLOB *ticket, uint8_t tok_id[2]) -{ - BOOL ret; - ASN1_DATA data; - int data_remaining; - - asn1_load(&data, blob); - asn1_start_tag(&data, ASN1_APPLICATION(0)); - asn1_check_OID(&data, OID_KERBEROS5); - - data_remaining = asn1_tag_remaining(&data); - - if (data_remaining < 3) { - data.has_error = True; - } else { - asn1_read(&data, tok_id, 2); - data_remaining -= 2; - *ticket = data_blob(NULL, data_remaining); - asn1_read(&data, ticket->data, ticket->length); - } - - asn1_end_tag(&data); - - ret = !data.has_error; - - asn1_free(&data); - - return ret; -} - - -/* - generate a SPNEGO negTokenTarg packet, ready for a EXTENDED_SECURITY - kerberos session setup -*/ -int spnego_gen_negTokenTarg(const char *principal, int time_offset, - DATA_BLOB *targ, - DATA_BLOB *session_key_krb5) -{ - int retval; - DATA_BLOB tkt, tkt_wrapped; - const char *krb_mechs[] = {OID_KERBEROS5_OLD, OID_NTLMSSP, NULL}; - - /* get a kerberos ticket for the service and extract the session key */ - retval = cli_krb5_get_ticket(principal, time_offset, &tkt, session_key_krb5); - - if (retval) - return retval; - - /* wrap that up in a nice GSS-API wrapping */ - tkt_wrapped = spnego_gen_krb5_wrap(tkt, TOK_ID_KRB_AP_REQ); - - /* and wrap that in a shiny SPNEGO wrapper */ - *targ = gen_negTokenTarg(krb_mechs, tkt_wrapped); - - data_blob_free(&tkt_wrapped); - data_blob_free(&tkt); - - return retval; -} - - -/* - parse a spnego NTLMSSP challenge packet giving two security blobs -*/ -BOOL spnego_parse_challenge(const DATA_BLOB blob, - DATA_BLOB *chal1, DATA_BLOB *chal2) -{ - BOOL ret; - ASN1_DATA data; - - ZERO_STRUCTP(chal1); - ZERO_STRUCTP(chal2); - - asn1_load(&data, blob); - asn1_start_tag(&data,ASN1_CONTEXT(1)); - asn1_start_tag(&data,ASN1_SEQUENCE(0)); - - asn1_start_tag(&data,ASN1_CONTEXT(0)); - asn1_check_enumerated(&data,1); - asn1_end_tag(&data); - - asn1_start_tag(&data,ASN1_CONTEXT(1)); - asn1_check_OID(&data, OID_NTLMSSP); - asn1_end_tag(&data); - - asn1_start_tag(&data,ASN1_CONTEXT(2)); - asn1_read_OctetString(&data, chal1); - asn1_end_tag(&data); - - /* the second challenge is optional (XP doesn't send it) */ - if (asn1_tag_remaining(&data)) { - asn1_start_tag(&data,ASN1_CONTEXT(3)); - asn1_read_OctetString(&data, chal2); - asn1_end_tag(&data); - } - - asn1_end_tag(&data); - asn1_end_tag(&data); - - ret = !data.has_error; - asn1_free(&data); - return ret; -} - - -/* - generate a SPNEGO auth packet. This will contain the encrypted passwords -*/ -DATA_BLOB spnego_gen_auth(DATA_BLOB blob) -{ - ASN1_DATA data; - DATA_BLOB ret; - - memset(&data, 0, sizeof(data)); - - asn1_push_tag(&data, ASN1_CONTEXT(1)); - asn1_push_tag(&data, ASN1_SEQUENCE(0)); - asn1_push_tag(&data, ASN1_CONTEXT(2)); - asn1_write_OctetString(&data,blob.data,blob.length); - asn1_pop_tag(&data); - asn1_pop_tag(&data); - asn1_pop_tag(&data); - - ret = data_blob(data.data, data.length); - - asn1_free(&data); - - return ret; -} - -/* - parse a SPNEGO auth packet. This contains the encrypted passwords -*/ -BOOL spnego_parse_auth(DATA_BLOB blob, DATA_BLOB *auth) -{ - ASN1_DATA data; - - asn1_load(&data, blob); - asn1_start_tag(&data, ASN1_CONTEXT(1)); - asn1_start_tag(&data, ASN1_SEQUENCE(0)); - asn1_start_tag(&data, ASN1_CONTEXT(2)); - asn1_read_OctetString(&data,auth); - asn1_end_tag(&data); - asn1_end_tag(&data); - asn1_end_tag(&data); - - if (data.has_error) { - DEBUG(3,("spnego_parse_auth failed at %d\n", (int)data.ofs)); - asn1_free(&data); - return False; - } - - asn1_free(&data); - return True; -} - -/* - generate a minimal SPNEGO response packet. Doesn't contain much. -*/ -DATA_BLOB spnego_gen_auth_response(DATA_BLOB *reply, NTSTATUS nt_status, - const char *mechOID) -{ - ASN1_DATA data; - DATA_BLOB ret; - uint8_t negResult; - - if (NT_STATUS_IS_OK(nt_status)) { - negResult = SPNEGO_NEG_RESULT_ACCEPT; - } else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { - negResult = SPNEGO_NEG_RESULT_INCOMPLETE; - } else { - negResult = SPNEGO_NEG_RESULT_REJECT; - } - - ZERO_STRUCT(data); - - asn1_push_tag(&data, ASN1_CONTEXT(1)); - asn1_push_tag(&data, ASN1_SEQUENCE(0)); - asn1_push_tag(&data, ASN1_CONTEXT(0)); - asn1_write_enumerated(&data, negResult); - asn1_pop_tag(&data); - - if (reply->data != NULL) { - asn1_push_tag(&data,ASN1_CONTEXT(1)); - asn1_write_OID(&data, mechOID); - asn1_pop_tag(&data); - - asn1_push_tag(&data,ASN1_CONTEXT(2)); - asn1_write_OctetString(&data, reply->data, reply->length); - asn1_pop_tag(&data); - } - - asn1_pop_tag(&data); - asn1_pop_tag(&data); - - ret = data_blob(data.data, data.length); - asn1_free(&data); - return ret; -} - -/* - parse a SPNEGO NTLMSSP auth packet. This contains the encrypted passwords -*/ -BOOL spnego_parse_auth_response(DATA_BLOB blob, NTSTATUS nt_status, - DATA_BLOB *auth) -{ - ASN1_DATA data; - uint8_t negResult; - - if (NT_STATUS_IS_OK(nt_status)) { - negResult = SPNEGO_NEG_RESULT_ACCEPT; - } else if (NT_STATUS_EQUAL(nt_status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { - negResult = SPNEGO_NEG_RESULT_INCOMPLETE; - } else { - negResult = SPNEGO_NEG_RESULT_REJECT; - } - - asn1_load(&data, blob); - asn1_start_tag(&data, ASN1_CONTEXT(1)); - asn1_start_tag(&data, ASN1_SEQUENCE(0)); - asn1_start_tag(&data, ASN1_CONTEXT(0)); - asn1_check_enumerated(&data, negResult); - asn1_end_tag(&data); - - if (negResult == SPNEGO_NEG_RESULT_INCOMPLETE) { - asn1_start_tag(&data,ASN1_CONTEXT(1)); - asn1_check_OID(&data, OID_NTLMSSP); - asn1_end_tag(&data); - - asn1_start_tag(&data,ASN1_CONTEXT(2)); - asn1_read_OctetString(&data, auth); - asn1_end_tag(&data); - } - - asn1_end_tag(&data); - asn1_end_tag(&data); - - if (data.has_error) { - DEBUG(3,("spnego_parse_auth_response failed at %d\n", (int)data.ofs)); - asn1_free(&data); - data_blob_free(auth); - return False; - } - - asn1_free(&data); - return True; -} - -- cgit From 37fcf2236433bc5e74f19d2afac3d1d0055dcd01 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sun, 27 Jun 2004 11:06:10 +0000 Subject: r1268: varient -> variant (This used to be commit de5984c95602ca67e8ac3139c3aa4330b74266e0) --- source4/libcli/raw/clisession.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index 641eff053e..780ff5837b 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -403,7 +403,7 @@ static NTSTATUS smb_raw_session_setup_generic(struct cli_session *session, /**************************************************************************** Perform a session setup (sync interface) this interface allows for RAW_SESSSETUP_GENERIC to auto-select session -setup varient based on negotiated protocol options +setup variant based on negotiated protocol options ****************************************************************************/ NTSTATUS smb_raw_session_setup(struct cli_session *session, TALLOC_CTX *mem_ctx, union smb_sesssetup *parms) -- cgit From 4f0e5e069064c11a8efc407cd42412d38534d0d2 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 5 Jul 2004 23:28:49 +0000 Subject: r1345: add extended security spnego support to the smb client code set lp_use_spnego = False, because I can't get it working yet but I commit it so others can help me metze (This used to be commit 2445cceba9ab9bd928c8bc50927a39509e4526b0) --- source4/libcli/raw/clisession.c | 111 ++++++++++++++++++++++++++++++++++++-- source4/libcli/raw/clitransport.c | 1 + source4/libcli/raw/clitree.c | 4 +- source4/libcli/raw/rawnegotiate.c | 47 +++++++++++----- source4/libcli/raw/smb_signing.c | 50 +++++++++++++++++ 5 files changed, 194 insertions(+), 19 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index 780ff5837b..7ff5db59c3 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -121,10 +121,12 @@ struct cli_request *smb_raw_session_setup_send(struct cli_session *session, unio SSVAL(req->out.vwv, VWV(4), parms->spnego.in.vc_num); SIVAL(req->out.vwv, VWV(5), parms->spnego.in.sesskey); SSVAL(req->out.vwv, VWV(7), parms->spnego.in.secblob.length); + SIVAL(req->out.vwv, VWV(8), 0); /* reserved */ SIVAL(req->out.vwv, VWV(10), parms->spnego.in.capabilities); cli_req_append_blob(req, &parms->spnego.in.secblob); cli_req_append_string(req, parms->spnego.in.os, STR_TERMINATE); cli_req_append_string(req, parms->spnego.in.lanman, STR_TERMINATE); + cli_req_append_string(req, parms->spnego.in.domain, STR_TERMINATE); break; } @@ -369,6 +371,109 @@ static NTSTATUS smb_raw_session_setup_generic_nt1(struct cli_session *session, return NT_STATUS_OK; } +/**************************************************************************** + Perform a session setup (sync interface) using generic interface and the SPNEGO + style sesssetup call +****************************************************************************/ +static NTSTATUS smb_raw_session_setup_generic_spnego(struct cli_session *session, + TALLOC_CTX *mem_ctx, + union smb_sesssetup *parms) +{ + NTSTATUS status; + union smb_sesssetup s2; + + s2.generic.level = RAW_SESSSETUP_SPNEGO; + s2.spnego.in.bufsize = ~0; + s2.spnego.in.mpx_max = 50; + s2.spnego.in.vc_num = 1; + s2.spnego.in.sesskey = parms->generic.in.sesskey; + s2.spnego.in.capabilities = parms->generic.in.capabilities; + s2.spnego.in.domain = parms->generic.in.domain; + s2.spnego.in.os = "Unix"; + s2.spnego.in.lanman = "Samba"; + + cli_temp_set_signing(session->transport); + + status = gensec_client_start(&session->gensec); + if (!NT_STATUS_IS_OK(status)) { + DEBUG(1, ("Failed to start GENSEC client mode: %s\n", nt_errstr(status))); + goto done; + } + + status = gensec_set_domain(session->gensec, parms->generic.in.domain); + if (!NT_STATUS_IS_OK(status)) { + DEBUG(1, ("Failed to start set GENSEC client domain to %s: %s\n", + parms->generic.in.domain, nt_errstr(status))); + goto done; + } + + status = gensec_set_username(session->gensec, parms->generic.in.user); + if (!NT_STATUS_IS_OK(status)) { + DEBUG(1, ("Failed to start set GENSEC client username to %s: %s\n", + parms->generic.in.user, nt_errstr(status))); + goto done; + } + + status = gensec_set_password(session->gensec, parms->generic.in.password); + if (!NT_STATUS_IS_OK(status)) { + DEBUG(1, ("Failed to start set GENSEC client password: %s\n", + nt_errstr(status))); + goto done; + } + + status = gensec_start_mech_by_name(session->gensec, "spnego"); + if (!NT_STATUS_IS_OK(status)) { + DEBUG(1, ("Failed to start set GENSEC client SPNEGO mechanism: %s\n", + nt_errstr(status))); + goto done; + } + + status = gensec_update(session->gensec, mem_ctx, + session->transport->negotiate.secblob, + &s2.spnego.in.secblob); + + if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { + goto done; + } + + while(1) { + status = smb_raw_session_setup(session, mem_ctx, &s2); + if (!NT_STATUS_IS_OK(status) && + !NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { + goto done; + } + + status = gensec_update(session->gensec, mem_ctx, + s2.spnego.out.secblob, + &s2.spnego.in.secblob); + + if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { + goto done; + } + } + +done: + if (NT_STATUS_IS_OK(status)) { + DATA_BLOB null_data_blob = data_blob(NULL, 0); + DATA_BLOB session_key = data_blob(NULL, 0); + + status = gensec_session_key(session->gensec, &session_key); + if (!NT_STATUS_IS_OK(status)) { + return status; + } + + cli_transport_simple_set_signing(session->transport, session_key, null_data_blob); + + cli_session_set_user_session_key(session, &session_key); + + parms->generic.out.vuid = s2.spnego.out.vuid; + parms->generic.out.os = s2.spnego.out.os; + parms->generic.out.lanman = s2.spnego.out.lanman; + parms->generic.out.domain = s2.spnego.out.domain; + } + + return status; +} /**************************************************************************** Perform a session setup (sync interface) using generic interface @@ -389,14 +494,12 @@ static NTSTATUS smb_raw_session_setup_generic(struct cli_session *session, } /* see if we should use the NT1 interface */ - if (!(session->transport->negotiate.capabilities & CAP_EXTENDED_SECURITY) || - !session->transport->options.use_spnego) { + if (!(session->transport->negotiate.capabilities & CAP_EXTENDED_SECURITY)) { return smb_raw_session_setup_generic_nt1(session, mem_ctx, parms); } /* default to using SPNEGO/NTLMSSP */ - DEBUG(0,("Need to add client SPNEGO code back in\n")); - return NT_STATUS_UNSUCCESSFUL; + return smb_raw_session_setup_generic_spnego(session, mem_ctx, parms); } diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 1e9032459f..a378ac8aad 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -38,6 +38,7 @@ struct cli_transport *cli_transport_init(struct cli_socket *sock) transport->mem_ctx = mem_ctx; transport->socket = sock; transport->negotiate.protocol = PROTOCOL_NT1; + transport->options.use_spnego = lp_use_spnego(); transport->negotiate.max_xmit = ~0; cli_null_set_signing(transport); transport->socket->reference_count++; diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index b35bf67c94..3b16c4c336 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -235,9 +235,7 @@ NTSTATUS cli_tree_full_connection(struct cli_tree **ret_tree, /* prepare a session setup to establish a security context */ setup.generic.level = RAW_SESSSETUP_GENERIC; setup.generic.in.sesskey = transport->negotiate.sesskey; - setup.generic.in.capabilities = CAP_UNICODE | CAP_STATUS32 | - CAP_LARGE_FILES | CAP_NT_SMBS | CAP_LEVEL_II_OPLOCKS | - CAP_W2K_SMBS | CAP_LARGE_READX | CAP_LARGE_WRITEX; + setup.generic.in.capabilities = transport->negotiate.capabilities; if (!user || !user[0]) { setup.generic.in.password = NULL; setup.generic.in.user = ""; diff --git a/source4/libcli/raw/rawnegotiate.c b/source4/libcli/raw/rawnegotiate.c index 5b94ef63d8..6bf35fb26d 100644 --- a/source4/libcli/raw/rawnegotiate.c +++ b/source4/libcli/raw/rawnegotiate.c @@ -32,6 +32,7 @@ static const struct { {PROTOCOL_LANMAN1,"Windows for Workgroups 3.1a"}, {PROTOCOL_LANMAN2,"LM1.2X002"}, {PROTOCOL_LANMAN2,"DOS LANMAN2.1"}, + {PROTOCOL_LANMAN2,"LANMAN2.1"}, {PROTOCOL_LANMAN2,"Samba"}, {PROTOCOL_NT1,"NT LANMAN 1.0"}, {PROTOCOL_NT1,"NT LM 0.12"}, @@ -44,12 +45,25 @@ struct cli_request *smb_negprot_send(struct cli_transport *transport, int maxpro { struct cli_request *req; int i; + uint16_t flags2 = 0; req = cli_request_setup_transport(transport, SMBnegprot, 0, 0); if (!req) { return NULL; } + flags2 |= FLAGS2_32_BIT_ERROR_CODES; + flags2 |= FLAGS2_UNICODE_STRINGS; + flags2 |= FLAGS2_EXTENDED_ATTRIBUTES; + flags2 |= FLAGS2_LONG_PATH_COMPONENTS; + flags2 |= FLAGS2_IS_LONG_NAME; + + if (transport->options.use_spnego) { + flags2 |= FLAGS2_EXTENDED_SECURITY; + } + + SSVAL(req->out.hdr,HDR_FLG2, flags2); + /* setup the protocol strings */ for (i=0; i < ARRAY_SIZE(prots) && prots[i].prot <= maxprotocol; i++) { cli_req_append_bytes(req, "\2", 1); @@ -102,26 +116,35 @@ NTSTATUS smb_raw_negotiate(struct cli_transport *transport) transport->negotiate.max_mux = SVAL(req->in.vwv,VWV(1)+1); transport->negotiate.max_xmit = IVAL(req->in.vwv,VWV(3)+1); transport->negotiate.sesskey = IVAL(req->in.vwv,VWV(7)+1); - transport->negotiate.server_zone = SVALS(req->in.vwv,VWV(15)+1) * 60; + transport->negotiate.capabilities = IVAL(req->in.vwv,VWV(9)+1); /* this time arrives in real GMT */ ntt = cli_pull_nttime(req->in.vwv, VWV(11)+1); - transport->negotiate.server_time = nt_time_to_unix(ntt); - transport->negotiate.capabilities = IVAL(req->in.vwv,VWV(9)+1); + transport->negotiate.server_time = nt_time_to_unix(ntt); + transport->negotiate.server_zone = SVALS(req->in.vwv,VWV(15)+1) * 60; + transport->negotiate.key_len = CVAL(req->in.vwv,VWV(16)+1); + + if (transport->negotiate.capabilities & CAP_EXTENDED_SECURITY) { + if (req->in.data_size < 16) { + goto failed; + } + transport->negotiate.server_guid = cli_req_pull_blob(req, transport->mem_ctx, req->in.data, 16); + transport->negotiate.secblob = cli_req_pull_blob(req, transport->mem_ctx, req->in.data + 16, req->in.data_size - 16); + } else { + if (req->in.data_size < (transport->negotiate.key_len)) { + goto failed; + } + transport->negotiate.secblob = cli_req_pull_blob(req, transport->mem_ctx, req->in.data, transport->negotiate.key_len); + cli_req_pull_string(req, transport->mem_ctx, &transport->negotiate.server_domain, + req->in.data+transport->negotiate.key_len, + req->in.data_size-transport->negotiate.key_len, STR_UNICODE|STR_NOALIGN); + /* here comes the server name */ + } - transport->negotiate.secblob = cli_req_pull_blob(req, transport->mem_ctx, req->in.data, req->in.data_size); if (transport->negotiate.capabilities & CAP_RAW_MODE) { transport->negotiate.readbraw_supported = True; transport->negotiate.writebraw_supported = True; } - - /* work out if they sent us a workgroup */ - if ((transport->negotiate.capabilities & CAP_EXTENDED_SECURITY) && - req->in.data_size > 16) { - cli_req_pull_string(req, transport->mem_ctx, &transport->negotiate.server_domain, - req->in.data+16, - req->in.data_size-16, STR_UNICODE|STR_NOALIGN); - } } else if (transport->negotiate.protocol >= PROTOCOL_LANMAN1) { CLI_CHECK_WCT(req, 13); transport->negotiate.sec_mode = SVAL(req->in.vwv,VWV(1)); diff --git a/source4/libcli/raw/smb_signing.c b/source4/libcli/raw/smb_signing.c index a39f33c290..20b44a5348 100644 --- a/source4/libcli/raw/smb_signing.c +++ b/source4/libcli/raw/smb_signing.c @@ -299,6 +299,56 @@ BOOL cli_null_set_signing(struct cli_transport *transport) return True; } +/*********************************************************** + SMB signing - TEMP implementation - calculate a MAC to send. +************************************************************/ +static void cli_request_temp_sign_outgoing_message(struct cli_request *req) +{ + /* mark the packet as signed - BEFORE we sign it...*/ + mark_packet_signed(req); + + /* I wonder what BSRSPYL stands for - but this is what MS + actually sends! */ + memcpy((req->out.hdr + HDR_SS_FIELD), "BSRSPYL ", 8); + return; +} + +/*********************************************************** + SMB signing - TEMP implementation - check a MAC sent by server. +************************************************************/ +static BOOL cli_request_temp_check_incoming_message(struct cli_request *req) +{ + return True; +} + +/*********************************************************** + SMB signing - NULL implementation - free signing context +************************************************************/ +static void cli_temp_free_signing_context(struct cli_transport *transport) +{ + return; +} + +/** + SMB signing - TEMP implementation - setup the MAC key. + + @note Used as an initialisation only - it will not correctly + shut down a real signing mechanism +*/ +BOOL cli_temp_set_signing(struct cli_transport *transport) +{ + if (!set_smb_signing_common(transport)) { + return False; + } + + transport->negotiate.sign_info.signing_context = NULL; + + transport->negotiate.sign_info.sign_outgoing_message = cli_request_temp_sign_outgoing_message; + transport->negotiate.sign_info.check_incoming_message = cli_request_temp_check_incoming_message; + transport->negotiate.sign_info.free_signing_context = cli_temp_free_signing_context; + + return True; +} /** * Free the signing context -- cgit From 1828f5d50696682be5f81408fe3cc0dd44d8406e Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 6 Jul 2004 00:22:27 +0000 Subject: r1348: get gensec backend by OID instead of name metze (This used to be commit 38e00f87191b86901b603e66aec1e7e71f74c29f) --- source4/libcli/raw/clisession.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index 7ff5db59c3..fd6737eeb7 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -421,7 +421,7 @@ static NTSTATUS smb_raw_session_setup_generic_spnego(struct cli_session *session goto done; } - status = gensec_start_mech_by_name(session->gensec, "spnego"); + status = gensec_start_mech_by_oid(session->gensec, OID_SPNEGO); if (!NT_STATUS_IS_OK(status)) { DEBUG(1, ("Failed to start set GENSEC client SPNEGO mechanism: %s\n", nt_errstr(status))); -- cgit From 0fa2b94c5629104000afe12e7eb0447ac515613f Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 8 Jul 2004 18:03:14 +0000 Subject: r1406: I got spnego in the smb client working so I set 'use spnego = True' metze (This used to be commit e06898f88c82c286574f9d73de1a9de829b1ded8) --- source4/libcli/raw/clisession.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index fd6737eeb7..dd13657549 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -391,6 +391,7 @@ static NTSTATUS smb_raw_session_setup_generic_spnego(struct cli_session *session s2.spnego.in.domain = parms->generic.in.domain; s2.spnego.in.os = "Unix"; s2.spnego.in.lanman = "Samba"; + s2.spnego.out.vuid = UID_FIELD_INVALID; cli_temp_set_signing(session->transport); @@ -437,7 +438,9 @@ static NTSTATUS smb_raw_session_setup_generic_spnego(struct cli_session *session } while(1) { + session->vuid = s2.spnego.out.vuid; status = smb_raw_session_setup(session, mem_ctx, &s2); + session->vuid = UID_FIELD_INVALID; if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { goto done; -- cgit From 2c87cb390d9c46bb1259c4fae95f4a44be97297b Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 8 Jul 2004 18:32:53 +0000 Subject: r1409: if we have no user name don't use extended security the capabilities in the union smb_sesssetup should be used to decide if we can use extented security metze (This used to be commit e3760fcc17cc645d942f0fc7f7325976391309ea) --- source4/libcli/raw/clisession.c | 2 +- source4/libcli/raw/clitree.c | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index dd13657549..d420aa7cd6 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -497,7 +497,7 @@ static NTSTATUS smb_raw_session_setup_generic(struct cli_session *session, } /* see if we should use the NT1 interface */ - if (!(session->transport->negotiate.capabilities & CAP_EXTENDED_SECURITY)) { + if (!(parms->generic.in.capabilities & CAP_EXTENDED_SECURITY)) { return smb_raw_session_setup_generic_nt1(session, mem_ctx, parms); } diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index 3b16c4c336..f1513ea51c 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -240,6 +240,7 @@ NTSTATUS cli_tree_full_connection(struct cli_tree **ret_tree, setup.generic.in.password = NULL; setup.generic.in.user = ""; setup.generic.in.domain = ""; + setup.generic.in.capabilities &= ~CAP_EXTENDED_SECURITY; } else { setup.generic.in.password = password; setup.generic.in.user = user; -- cgit From e053c719ab0f270dbad46dfb9e6eeae22e3b833d Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 12 Jul 2004 09:02:09 +0000 Subject: r1460: Avoid a compile warning. Andrew Bartlett (This used to be commit 10a973da88441b255eda7cbc263ef5c4f2f0fcae) --- source4/libcli/raw/clitree.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index f1513ea51c..fcb0a9a660 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -189,6 +189,7 @@ NTSTATUS cli_tree_full_connection(struct cli_tree **ret_tree, union smb_sesssetup setup; union smb_tcon tcon; TALLOC_CTX *mem_ctx; + char *in_path = NULL; *ret_tree = NULL; @@ -272,7 +273,9 @@ NTSTATUS cli_tree_full_connection(struct cli_tree **ret_tree, tcon.generic.level = RAW_TCON_TCONX; tcon.tconx.in.flags = 0; tcon.tconx.in.password = data_blob(NULL, 0); - asprintf(&tcon.tconx.in.path, "\\\\%s\\%s", dest_host, service); + + asprintf(in_path, "\\\\%s\\%s", dest_host, service); + tcon.tconx.in.path = in_path; if (!service_type) { if (strequal(service, "IPC$")) service_type = "IPC"; @@ -283,7 +286,7 @@ NTSTATUS cli_tree_full_connection(struct cli_tree **ret_tree, status = smb_tree_connect(tree, mem_ctx, &tcon); - free(tcon.tconx.in.path); + SAFE_FREE(in_path); if (!NT_STATUS_IS_OK(status)) { cli_tree_close(tree); -- cgit From 88002b851bd30e3c03a5a9442baf3ced7aa6090f Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 12 Jul 2004 09:11:13 +0000 Subject: r1462: GENSEC Kerberos and SPENGO work: - Spelling - it's SPNEGO, not SPENGO - SMB signing - Krb5 logins are now correctly signed - SPNEGO - Changes to always tell GENSEC about incoming packets, empty or not. Andrew Bartlett (This used to be commit cea578d6f39a2ea4a24e7a0064c95193ab6f6df7) --- source4/libcli/raw/clisession.c | 30 ++++++----- source4/libcli/raw/clitransport.c | 4 +- source4/libcli/raw/smb_signing.c | 101 ++++++++++++++++++++++++++++---------- 3 files changed, 95 insertions(+), 40 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index d420aa7cd6..5aaceb103a 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -260,7 +260,7 @@ static void use_nt1_session_keys(struct cli_session *session, E_md4hash(password, nt_hash); SMBsesskeygen_ntv1(nt_hash, session_key.data); - cli_transport_simple_set_signing(transport, session_key, *nt_response); + cli_transport_simple_set_signing(transport, session_key, *nt_response, 0); cli_session_set_user_session_key(session, &session_key); data_blob_free(&session_key); @@ -381,6 +381,8 @@ static NTSTATUS smb_raw_session_setup_generic_spnego(struct cli_session *session { NTSTATUS status; union smb_sesssetup s2; + DATA_BLOB session_key = data_blob(NULL, 0); + DATA_BLOB null_data_blob = data_blob(NULL, 0); s2.generic.level = RAW_SESSSETUP_SPNEGO; s2.spnego.in.bufsize = ~0; @@ -433,39 +435,41 @@ static NTSTATUS smb_raw_session_setup_generic_spnego(struct cli_session *session session->transport->negotiate.secblob, &s2.spnego.in.secblob); - if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { - goto done; - } - while(1) { + if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED) && !NT_STATUS_IS_OK(status)) { + break; + } + + status = gensec_session_key(session->gensec, &session_key); + if (NT_STATUS_IS_OK(status)) { + cli_transport_simple_set_signing(session->transport, session_key, null_data_blob, 0); + } + session->vuid = s2.spnego.out.vuid; status = smb_raw_session_setup(session, mem_ctx, &s2); session->vuid = UID_FIELD_INVALID; if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { - goto done; + break; } status = gensec_update(session->gensec, mem_ctx, s2.spnego.out.secblob, &s2.spnego.in.secblob); - if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { - goto done; + if (NT_STATUS_IS_OK(status)) { + break; } } done: if (NT_STATUS_IS_OK(status)) { - DATA_BLOB null_data_blob = data_blob(NULL, 0); - DATA_BLOB session_key = data_blob(NULL, 0); - status = gensec_session_key(session->gensec, &session_key); if (!NT_STATUS_IS_OK(status)) { return status; } - - cli_transport_simple_set_signing(session->transport, session_key, null_data_blob); + + cli_transport_simple_set_signing(session->transport, session_key, null_data_blob, 2 /* two legs on last packet */); cli_session_set_user_session_key(session, &session_key); diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index a378ac8aad..18784fe33a 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -40,7 +40,9 @@ struct cli_transport *cli_transport_init(struct cli_socket *sock) transport->negotiate.protocol = PROTOCOL_NT1; transport->options.use_spnego = lp_use_spnego(); transport->negotiate.max_xmit = ~0; - cli_null_set_signing(transport); + + cli_init_signing(transport); + transport->socket->reference_count++; ZERO_STRUCT(transport->called); diff --git a/source4/libcli/raw/smb_signing.c b/source4/libcli/raw/smb_signing.c index 20b44a5348..52e08d05f8 100644 --- a/source4/libcli/raw/smb_signing.c +++ b/source4/libcli/raw/smb_signing.c @@ -40,14 +40,18 @@ static BOOL set_smb_signing_common(struct cli_transport *transport) if (transport->negotiate.sign_info.doing_signing) { return False; } - + + if (!transport->negotiate.sign_info.allow_smb_signing) { + return False; + } + if (transport->negotiate.sign_info.free_signing_context) transport->negotiate.sign_info.free_signing_context(transport); /* These calls are INCOMPATIBLE with SMB signing */ transport->negotiate.readbraw_supported = False; transport->negotiate.writebraw_supported = False; - + return True; } @@ -56,9 +60,8 @@ static BOOL set_smb_signing_common(struct cli_transport *transport) ************************************************************/ static BOOL set_smb_signing_real_common(struct cli_transport *transport) { - if (transport->negotiate.sec_mode & NEGOTIATE_SECURITY_SIGNATURES_REQUIRED) { + if (transport->negotiate.sign_info.mandatory_signing) { DEBUG(5, ("Mandatory SMB signing enabled!\n")); - transport->negotiate.sign_info.doing_signing = True; } DEBUG(5, ("SMB signing enabled!\n")); @@ -74,24 +77,37 @@ static void mark_packet_signed(struct cli_request *req) SSVAL(req->out.hdr, HDR_FLG2, flags2); } -static BOOL signing_good(struct cli_request *req, BOOL good) +static BOOL signing_good(struct cli_request *req, int seq, BOOL good) { - if (good && !req->transport->negotiate.sign_info.doing_signing) { - req->transport->negotiate.sign_info.doing_signing = True; - } - - if (!good) { - if (req->transport->negotiate.sign_info.doing_signing) { - DEBUG(1, ("SMB signature check failed!\n")); - return False; + if (good) { + if (!req->transport->negotiate.sign_info.doing_signing) { + req->transport->negotiate.sign_info.doing_signing = True; + } + if (!req->transport->negotiate.sign_info.seen_valid) { + req->transport->negotiate.sign_info.seen_valid = True; + } + } else { + if (!req->transport->negotiate.sign_info.mandatory_signing && !req->transport->negotiate.sign_info.seen_valid) { + + /* Non-mandatory signing - just turn off if this is the first bad packet.. */ + DEBUG(5, ("srv_check_incoming_message: signing negotiated but not required and peer\n" + "isn't sending correct signatures. Turning off.\n")); + req->transport->negotiate.sign_info.negotiated_smb_signing = False; + req->transport->negotiate.sign_info.allow_smb_signing = False; + req->transport->negotiate.sign_info.doing_signing = False; + if (req->transport->negotiate.sign_info.free_signing_context) + req->transport->negotiate.sign_info.free_signing_context(req->transport); + cli_null_set_signing(req->transport); + return True; } else { - DEBUG(3, ("Server did not sign reply correctly\n")); - cli_transport_free_signing_context(req->transport); + /* Mandatory signing or bad packet after signing started - fail and disconnect. */ + if (seq) + DEBUG(0, ("signing_good: BAD SIG: seq %u\n", (unsigned int)seq)); return False; } } return True; -} +} /*********************************************************** SMB signing - Simple implementation - calculate a MAC to send. @@ -139,6 +155,9 @@ static void cli_request_simple_sign_outgoing_message(struct cli_request *req) memcpy(&req->out.hdr[HDR_SS_FIELD], calc_md5_mac, 8); + DEBUG(5, ("cli_request_simple_sign_outgoing_message: SENT SIG (seq: %d, next %d): sent SMB signature of\n", + req->seq_num, data->next_seq_num)); + dump_data(5, calc_md5_mac, 8); /* req->out.hdr[HDR_SS_FIELD+2]=0; Uncomment this to test if the remote server actually verifies signitures...*/ } @@ -184,6 +203,20 @@ static BOOL cli_request_simple_check_incoming_message(struct cli_request *req) MD5Final(calc_md5_mac, &md5_ctx); good = (memcmp(server_sent_mac, calc_md5_mac, 8) == 0); + + if (i == 1) { + if (!good) { + DEBUG(5, ("cli_request_simple_check_incoming_message: BAD SIG (seq: %d): wanted SMB signature of\n", req->seq_num + i)); + dump_data(5, calc_md5_mac, 8); + + DEBUG(5, ("cli_request_simple_check_incoming_message: BAD SIG (seq: %d): got SMB signature of\n", req->seq_num + i)); + dump_data(5, server_sent_mac, 8); + } else { + DEBUG(15, ("cli_request_simple_check_incoming_message: GOOD SIG (seq: %d): got SMB signature of\n", req->seq_num + i)); + dump_data(5, server_sent_mac, 8); + } + } + if (good) break; } @@ -191,14 +224,7 @@ static BOOL cli_request_simple_check_incoming_message(struct cli_request *req) DEBUG(0,("SIGNING OFFSET %d (should be %d)\n", i, req->seq_num+1)); } - if (!good) { - DEBUG(5, ("cli_request_simple_check_incoming_message: BAD SIG: wanted SMB signature of\n")); - dump_data(5, calc_md5_mac, 8); - - DEBUG(5, ("cli_request_simple_check_incoming_message: BAD SIG: got SMB signature of\n")); - dump_data(5, server_sent_mac, 8); - } - return signing_good(req, good); + return signing_good(req, req->seq_num+1, good); } @@ -221,7 +247,8 @@ static void cli_transport_simple_free_signing_context(struct cli_transport *tran ************************************************************/ BOOL cli_transport_simple_set_signing(struct cli_transport *transport, const DATA_BLOB user_session_key, - const DATA_BLOB response) + const DATA_BLOB response, + int seq_num) { struct smb_basic_signing_context *data; @@ -245,7 +272,7 @@ BOOL cli_transport_simple_set_signing(struct cli_transport *transport, } /* Initialise the sequence number */ - data->next_seq_num = 0; + data->next_seq_num = seq_num; transport->negotiate.sign_info.sign_outgoing_message = cli_request_simple_sign_outgoing_message; transport->negotiate.sign_info.check_incoming_message = cli_request_simple_check_incoming_message; @@ -393,3 +420,25 @@ BOOL cli_request_check_sign_mac(struct cli_request *req) return True; } + + +BOOL cli_init_signing(struct cli_transport *transport) +{ + if (!cli_null_set_signing(transport)) { + return False; + } + + switch (lp_client_signing()) { + case SMB_SIGNING_OFF: + transport->negotiate.sign_info.allow_smb_signing = False; + break; + case SMB_SIGNING_SUPPORTED: + transport->negotiate.sign_info.allow_smb_signing = True; + break; + case SMB_SIGNING_REQUIRED: + transport->negotiate.sign_info.allow_smb_signing = True; + transport->negotiate.sign_info.mandatory_signing = True; + break; + } + return True; +} -- cgit From bff4e6963c0b7b58a0886a207f4da0398377157f Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 12 Jul 2004 15:34:34 +0000 Subject: r1469: fix a segfault and compiler warning, introduced by the "compiler warning fix" in rev 1460... metze (This used to be commit ffb7ba35cdb2fb19b8271a3585eef075948bef9c) --- source4/libcli/raw/clitree.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index fcb0a9a660..a580ded010 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -272,9 +272,8 @@ NTSTATUS cli_tree_full_connection(struct cli_tree **ret_tree, /* connect to a share using a tree connect */ tcon.generic.level = RAW_TCON_TCONX; tcon.tconx.in.flags = 0; - tcon.tconx.in.password = data_blob(NULL, 0); - - asprintf(in_path, "\\\\%s\\%s", dest_host, service); + tcon.tconx.in.password = data_blob(NULL, 0); + asprintf(&in_path, "\\\\%s\\%s", dest_host, service); tcon.tconx.in.path = in_path; if (!service_type) { if (strequal(service, "IPC$")) -- cgit From ed03516c915c4a4c8ae6f7decfa04d51049d9dd5 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 13 Jul 2004 05:14:59 +0000 Subject: r1475: More kerberos work - We can now connect to hosts that follow the SPNEGO RFC, and *do not* give us their principal name in the mechListMIC. - The client code now remembers the hostname it connects to - We now kinit for a user, if there is not valid ticket already - Re-introduce clock skew compensation TODO: - See if the username in the ccache matches the username specified - Use a private ccache, rather then the global one, for a 'new' kinit - Determine 'default' usernames. - The default for Krb5 is the one in the ccache, then $USER - For NTLMSSP, it's just $USER Andrew Bartlett (This used to be commit de5da669397db4ac87c6da08d3533ca3030da2b0) --- source4/libcli/raw/clisession.c | 7 +++++++ source4/libcli/raw/clisocket.c | 11 ++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index 5aaceb103a..e31cf07bf8 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -424,6 +424,13 @@ static NTSTATUS smb_raw_session_setup_generic_spnego(struct cli_session *session goto done; } + status = gensec_set_target_hostname(session->gensec, session->transport->socket->hostname); + if (!NT_STATUS_IS_OK(status)) { + DEBUG(1, ("Failed to start set GENSEC target hostname: %s\n", + nt_errstr(status))); + goto done; + } + status = gensec_start_mech_by_oid(session->gensec, OID_SPNEGO); if (!NT_STATUS_IS_OK(status)) { DEBUG(1, ("Failed to start set GENSEC client SPNEGO mechanism: %s\n", diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 4dae7d517d..5cd6f33689 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -45,6 +45,8 @@ struct cli_socket *cli_sock_init(void) /* 20 second default timeout */ sock->timeout = 20000; + sock->hostname = NULL; + return sock; } @@ -140,6 +142,7 @@ BOOL cli_sock_connect_byname(struct cli_socket *sock, const char *host, int port struct in_addr ip; TALLOC_CTX *mem_ctx; char *name, *p; + BOOL ret; if (getenv("LIBSMB_PROG")) { sock->fd = sock_exec(getenv("LIBSMB_PROG")); @@ -162,7 +165,13 @@ BOOL cli_sock_connect_byname(struct cli_socket *sock, const char *host, int port return False; } + ret = cli_sock_connect(sock, &ip, port); + + if (ret) { + sock->hostname = talloc_steal(mem_ctx, sock->mem_ctx, name); + } + talloc_destroy(mem_ctx); - return cli_sock_connect(sock, &ip, port); + return ret; } -- cgit From ad8d0190f1c188e74d61e4867f8c5ebd7fb20994 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 14 Jul 2004 09:00:28 +0000 Subject: r1494: fix debug message metze (This used to be commit 463982bf3f37bac67e1aaa488e4142d0ecc23307) --- source4/libcli/raw/smb_signing.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/smb_signing.c b/source4/libcli/raw/smb_signing.c index 52e08d05f8..fc10413108 100644 --- a/source4/libcli/raw/smb_signing.c +++ b/source4/libcli/raw/smb_signing.c @@ -90,7 +90,7 @@ static BOOL signing_good(struct cli_request *req, int seq, BOOL good) if (!req->transport->negotiate.sign_info.mandatory_signing && !req->transport->negotiate.sign_info.seen_valid) { /* Non-mandatory signing - just turn off if this is the first bad packet.. */ - DEBUG(5, ("srv_check_incoming_message: signing negotiated but not required and peer\n" + DEBUG(5, ("signing_good: signing negotiated but not required and peer\n" "isn't sending correct signatures. Turning off.\n")); req->transport->negotiate.sign_info.negotiated_smb_signing = False; req->transport->negotiate.sign_info.allow_smb_signing = False; -- cgit From b3c46674a670ea51607d5c2a73271dff531ae7d6 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 16 Jul 2004 02:54:57 +0000 Subject: r1521: Updates to our SMB signing code. - This causes our client and server code to use the same core code, with the same debugs etc. - In turn, this will allow the 'mandetory/fallback' signing algorithms to be shared, and only written once. Updates to the SPNEGO code - Don't wrap an empty token to the server, if we are actually already finished. Andrew Bartlett (This used to be commit 35b83eb329482ac1b3bc67285854cc47844ff353) --- source4/libcli/raw/clisession.c | 43 +++++++---- source4/libcli/raw/smb_signing.c | 152 ++++++++++++++++++++++----------------- 2 files changed, 115 insertions(+), 80 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index e31cf07bf8..c6d7f800a4 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -260,7 +260,7 @@ static void use_nt1_session_keys(struct cli_session *session, E_md4hash(password, nt_hash); SMBsesskeygen_ntv1(nt_hash, session_key.data); - cli_transport_simple_set_signing(transport, session_key, *nt_response, 0); + cli_transport_simple_set_signing(transport, session_key, *nt_response); cli_session_set_user_session_key(session, &session_key); data_blob_free(&session_key); @@ -380,6 +380,7 @@ static NTSTATUS smb_raw_session_setup_generic_spnego(struct cli_session *session union smb_sesssetup *parms) { NTSTATUS status; + NTSTATUS session_key_err = NT_STATUS_NO_USER_SESSION_KEY; union smb_sesssetup s2; DATA_BLOB session_key = data_blob(NULL, 0); DATA_BLOB null_data_blob = data_blob(NULL, 0); @@ -443,15 +444,20 @@ static NTSTATUS smb_raw_session_setup_generic_spnego(struct cli_session *session &s2.spnego.in.secblob); while(1) { + if (NT_STATUS_IS_OK(status) && s2.spnego.in.secblob.length == 0) { + break; + } if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED) && !NT_STATUS_IS_OK(status)) { break; } - status = gensec_session_key(session->gensec, &session_key); - if (NT_STATUS_IS_OK(status)) { - cli_transport_simple_set_signing(session->transport, session_key, null_data_blob, 0); + if (!NT_STATUS_IS_OK(session_key_err)) { + session_key_err = gensec_session_key(session->gensec, &session_key); } - + if (NT_STATUS_IS_OK(session_key_err)) { + cli_transport_simple_set_signing(session->transport, session_key, null_data_blob); + } + session->vuid = s2.spnego.out.vuid; status = smb_raw_session_setup(session, mem_ctx, &s2); session->vuid = UID_FIELD_INVALID; @@ -464,19 +470,14 @@ static NTSTATUS smb_raw_session_setup_generic_spnego(struct cli_session *session s2.spnego.out.secblob, &s2.spnego.in.secblob); - if (NT_STATUS_IS_OK(status)) { - break; - } } done: if (NT_STATUS_IS_OK(status)) { - status = gensec_session_key(session->gensec, &session_key); - if (!NT_STATUS_IS_OK(status)) { - return status; + if (!NT_STATUS_IS_OK(session_key_err)) { + DEBUG(1, ("Failed to get user session key: %s\n", nt_errstr(session_key_err))); + return session_key_err; } - - cli_transport_simple_set_signing(session->transport, session_key, null_data_blob, 2 /* two legs on last packet */); cli_session_set_user_session_key(session, &session_key); @@ -484,6 +485,9 @@ done: parms->generic.out.os = s2.spnego.out.os; parms->generic.out.lanman = s2.spnego.out.lanman; parms->generic.out.domain = s2.spnego.out.domain; + } else { + DEBUG(1, ("Failed to login with SPNEGO: %s\n", nt_errstr(status))); + return status; } return status; @@ -528,7 +532,18 @@ NTSTATUS smb_raw_session_setup(struct cli_session *session, TALLOC_CTX *mem_ctx, struct cli_request *req; if (parms->generic.level == RAW_SESSSETUP_GENERIC) { - return smb_raw_session_setup_generic(session, mem_ctx, parms); + NTSTATUS ret = smb_raw_session_setup_generic(session, mem_ctx, parms); + + if (NT_STATUS_IS_OK(ret) + && parms->generic.in.user + && *parms->generic.in.user) { + if (!session->transport->negotiate.sign_info.doing_signing + && session->transport->negotiate.sign_info.mandatory_signing) { + DEBUG(0, ("SMB signing required, but server does not support it\n")); + return NT_STATUS_ACCESS_DENIED; + } + } + return ret; } req = smb_raw_session_setup_send(session, parms); diff --git a/source4/libcli/raw/smb_signing.c b/source4/libcli/raw/smb_signing.c index fc10413108..20f8921acb 100644 --- a/source4/libcli/raw/smb_signing.c +++ b/source4/libcli/raw/smb_signing.c @@ -69,15 +69,15 @@ static BOOL set_smb_signing_real_common(struct cli_transport *transport) return True; } -static void mark_packet_signed(struct cli_request *req) +static void mark_packet_signed(struct request_buffer *out) { uint16_t flags2; - flags2 = SVAL(req->out.hdr, HDR_FLG2); + flags2 = SVAL(out->hdr, HDR_FLG2); flags2 |= FLAGS2_SMB_SECURITY_SIGNATURES; - SSVAL(req->out.hdr, HDR_FLG2, flags2); + SSVAL(out->hdr, HDR_FLG2, flags2); } -static BOOL signing_good(struct cli_request *req, int seq, BOOL good) +static BOOL signing_good(struct cli_request *req, unsigned int seq, BOOL good) { if (good) { if (!req->transport->negotiate.sign_info.doing_signing) { @@ -87,9 +87,8 @@ static BOOL signing_good(struct cli_request *req, int seq, BOOL good) req->transport->negotiate.sign_info.seen_valid = True; } } else { - if (!req->transport->negotiate.sign_info.mandatory_signing && !req->transport->negotiate.sign_info.seen_valid) { - - /* Non-mandatory signing - just turn off if this is the first bad packet.. */ + if (!req->transport->negotiate.sign_info.seen_valid) { + /* If we have never seen a good packet, just turn it off */ DEBUG(5, ("signing_good: signing negotiated but not required and peer\n" "isn't sending correct signatures. Turning off.\n")); req->transport->negotiate.sign_info.negotiated_smb_signing = False; @@ -100,119 +99,97 @@ static BOOL signing_good(struct cli_request *req, int seq, BOOL good) cli_null_set_signing(req->transport); return True; } else { - /* Mandatory signing or bad packet after signing started - fail and disconnect. */ - if (seq) - DEBUG(0, ("signing_good: BAD SIG: seq %u\n", (unsigned int)seq)); + /* bad packet after signing started - fail and disconnect. */ + DEBUG(0, ("signing_good: BAD SIG: seq %u\n", seq)); return False; } } return True; } -/*********************************************************** - SMB signing - Simple implementation - calculate a MAC to send. -************************************************************/ -static void cli_request_simple_sign_outgoing_message(struct cli_request *req) +void sign_outgoing_message(struct request_buffer *out, DATA_BLOB *mac_key, uint_t seq_num) { uint8_t calc_md5_mac[16]; struct MD5Context md5_ctx; - struct smb_basic_signing_context *data = req->transport->negotiate.sign_info.signing_context; - -#if 0 - /* enable this when packet signing is preventing you working out why valgrind - says that data is uninitialised */ - file_save("pkt.dat", req->out.buffer, req->out.size); -#endif - - req->seq_num = data->next_seq_num; - - /* some requests (eg. NTcancel) are one way, and the sequence number - should be increased by 1 not 2 */ - if (req->one_way_request) { - data->next_seq_num += 1; - } else { - data->next_seq_num += 2; - } - /* * Firstly put the sequence number into the first 4 bytes. * and zero out the next 4 bytes. */ - SIVAL(req->out.hdr, HDR_SS_FIELD, req->seq_num); - SIVAL(req->out.hdr, HDR_SS_FIELD + 4, 0); + SIVAL(out->hdr, HDR_SS_FIELD, seq_num); + SIVAL(out->hdr, HDR_SS_FIELD + 4, 0); /* mark the packet as signed - BEFORE we sign it...*/ - mark_packet_signed(req); + mark_packet_signed(out); /* Calculate the 16 byte MAC and place first 8 bytes into the field. */ MD5Init(&md5_ctx); - MD5Update(&md5_ctx, data->mac_key.data, - data->mac_key.length); + MD5Update(&md5_ctx, mac_key->data, + mac_key->length); MD5Update(&md5_ctx, - req->out.buffer + NBT_HDR_SIZE, - req->out.size - NBT_HDR_SIZE); + out->buffer + NBT_HDR_SIZE, + out->size - NBT_HDR_SIZE); MD5Final(calc_md5_mac, &md5_ctx); - memcpy(&req->out.hdr[HDR_SS_FIELD], calc_md5_mac, 8); + memcpy(&out->hdr[HDR_SS_FIELD], calc_md5_mac, 8); - DEBUG(5, ("cli_request_simple_sign_outgoing_message: SENT SIG (seq: %d, next %d): sent SMB signature of\n", - req->seq_num, data->next_seq_num)); + DEBUG(5, ("sign_outgoing_message: SENT SIG (seq: %d): sent SMB signature of\n", + seq_num)); dump_data(5, calc_md5_mac, 8); /* req->out.hdr[HDR_SS_FIELD+2]=0; Uncomment this to test if the remote server actually verifies signitures...*/ } - -/*********************************************************** - SMB signing - Simple implementation - check a MAC sent by server. -************************************************************/ -static BOOL cli_request_simple_check_incoming_message(struct cli_request *req) +BOOL check_signed_incoming_message(struct request_buffer *in, DATA_BLOB *mac_key, uint_t seq_num) { BOOL good; uint8_t calc_md5_mac[16]; uint8_t server_sent_mac[8]; uint8_t sequence_buf[8]; struct MD5Context md5_ctx; - struct smb_basic_signing_context *data = req->transport->negotiate.sign_info.signing_context; const size_t offset_end_of_sig = (HDR_SS_FIELD + 8); int i; const int sign_range = 0; + /* room enough for the signature? */ + if (in->size < NBT_HDR_SIZE + HDR_SS_FIELD + 8) { + return False; + } + /* its quite bogus to be guessing sequence numbers, but very useful when debugging signing implementations */ - for (i = 1-sign_range; i <= 1+sign_range; i++) { + for (i = 0-sign_range; i <= 0+sign_range; i++) { /* * Firstly put the sequence number into the first 4 bytes. * and zero out the next 4 bytes. */ - SIVAL(sequence_buf, 0, req->seq_num+i); + SIVAL(sequence_buf, 0, seq_num + i); SIVAL(sequence_buf, 4, 0); /* get a copy of the server-sent mac */ - memcpy(server_sent_mac, &req->in.hdr[HDR_SS_FIELD], sizeof(server_sent_mac)); + memcpy(server_sent_mac, &in->hdr[HDR_SS_FIELD], sizeof(server_sent_mac)); /* Calculate the 16 byte MAC and place first 8 bytes into the field. */ MD5Init(&md5_ctx); - MD5Update(&md5_ctx, data->mac_key.data, - data->mac_key.length); - MD5Update(&md5_ctx, req->in.hdr, HDR_SS_FIELD); + MD5Update(&md5_ctx, mac_key->data, + mac_key->length); + MD5Update(&md5_ctx, in->hdr, HDR_SS_FIELD); MD5Update(&md5_ctx, sequence_buf, sizeof(sequence_buf)); - MD5Update(&md5_ctx, req->in.hdr + offset_end_of_sig, - req->in.size - NBT_HDR_SIZE - (offset_end_of_sig)); + MD5Update(&md5_ctx, in->hdr + offset_end_of_sig, + in->size - NBT_HDR_SIZE - (offset_end_of_sig)); MD5Final(calc_md5_mac, &md5_ctx); good = (memcmp(server_sent_mac, calc_md5_mac, 8) == 0); - if (i == 1) { + if (i == 0) { if (!good) { - DEBUG(5, ("cli_request_simple_check_incoming_message: BAD SIG (seq: %d): wanted SMB signature of\n", req->seq_num + i)); + DEBUG(5, ("check_signed_incoming_message: BAD SIG (seq: %d): wanted SMB signature of\n", seq_num + i)); dump_data(5, calc_md5_mac, 8); - DEBUG(5, ("cli_request_simple_check_incoming_message: BAD SIG (seq: %d): got SMB signature of\n", req->seq_num + i)); + DEBUG(5, ("check_signed_incoming_message: BAD SIG (seq: %d): got SMB signature of\n", seq_num + i)); dump_data(5, server_sent_mac, 8); } else { - DEBUG(15, ("cli_request_simple_check_incoming_message: GOOD SIG (seq: %d): got SMB signature of\n", req->seq_num + i)); + DEBUG(15, ("check_signed_incoming_message: GOOD SIG (seq: %d): got SMB signature of\n", seq_num + i)); dump_data(5, server_sent_mac, 8); } } @@ -220,10 +197,51 @@ static BOOL cli_request_simple_check_incoming_message(struct cli_request *req) if (good) break; } - if (good && i != 1) { - DEBUG(0,("SIGNING OFFSET %d (should be %d)\n", i, req->seq_num+1)); + if (good && i != 0) { + DEBUG(0,("SIGNING OFFSET %d (should be %d)\n", i, seq_num)); + } + return good; +} + +/*********************************************************** + SMB signing - Simple implementation - calculate a MAC to send. +************************************************************/ +static void cli_request_simple_sign_outgoing_message(struct cli_request *req) +{ + struct smb_basic_signing_context *data = req->transport->negotiate.sign_info.signing_context; + +#if 0 + /* enable this when packet signing is preventing you working out why valgrind + says that data is uninitialised */ + file_save("pkt.dat", req->out.buffer, req->out.size); +#endif + + req->seq_num = data->next_seq_num; + + /* some requests (eg. NTcancel) are one way, and the sequence number + should be increased by 1 not 2 */ + if (req->one_way_request) { + data->next_seq_num += 1; + } else { + data->next_seq_num += 2; } + + sign_outgoing_message(&req->out, &data->mac_key, req->seq_num); +} + +/*********************************************************** + SMB signing - Simple implementation - check a MAC sent by server. +************************************************************/ +static BOOL cli_request_simple_check_incoming_message(struct cli_request *req) +{ + struct smb_basic_signing_context *data + = req->transport->negotiate.sign_info.signing_context; + + BOOL good = check_signed_incoming_message(&req->in, + &data->mac_key, + req->seq_num+1); + return signing_good(req, req->seq_num+1, good); } @@ -247,8 +265,7 @@ static void cli_transport_simple_free_signing_context(struct cli_transport *tran ************************************************************/ BOOL cli_transport_simple_set_signing(struct cli_transport *transport, const DATA_BLOB user_session_key, - const DATA_BLOB response, - int seq_num) + const DATA_BLOB response) { struct smb_basic_signing_context *data; @@ -271,8 +288,10 @@ BOOL cli_transport_simple_set_signing(struct cli_transport *transport, memcpy(&data->mac_key.data[user_session_key.length],response.data, response.length); } + dump_data_pw("Started Signing with key:\n", data->mac_key.data, data->mac_key.length); + /* Initialise the sequence number */ - data->next_seq_num = seq_num; + data->next_seq_num = 0; transport->negotiate.sign_info.sign_outgoing_message = cli_request_simple_sign_outgoing_message; transport->negotiate.sign_info.check_incoming_message = cli_request_simple_check_incoming_message; @@ -332,11 +351,12 @@ BOOL cli_null_set_signing(struct cli_transport *transport) static void cli_request_temp_sign_outgoing_message(struct cli_request *req) { /* mark the packet as signed - BEFORE we sign it...*/ - mark_packet_signed(req); + mark_packet_signed(&req->out); /* I wonder what BSRSPYL stands for - but this is what MS actually sends! */ memcpy((req->out.hdr + HDR_SS_FIELD), "BSRSPYL ", 8); + return; } -- cgit From d093b7e7771c3f143546889c95f97dd0be16998f Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 19 Jul 2004 10:35:05 +0000 Subject: r1547: rename 'enum _level' -> 'enum smb__level' e.g. we now have 'union smb_mkdir' and 'enum smb_mkdir_level' in sync we may should also rename 'RAW_MKDIR_*' -> 'SMB_MKDIR_*' metze (This used to be commit 0bb50dcf1ccb9797000fcbea4d8a73f2d2a3db77) --- source4/libcli/raw/rawsearch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawsearch.c b/source4/libcli/raw/rawsearch.c index bdb57aa6c4..a4ba8e8696 100644 --- a/source4/libcli/raw/rawsearch.c +++ b/source4/libcli/raw/rawsearch.c @@ -235,7 +235,7 @@ static NTSTATUS smb_raw_search_next_blob(struct cli_tree *tree, */ static int parse_trans2_search(struct cli_tree *tree, TALLOC_CTX *mem_ctx, - enum search_level level, + enum smb_search_level level, uint16_t flags, DATA_BLOB *blob, union smb_search_data *data) @@ -449,7 +449,7 @@ static int parse_trans2_search(struct cli_tree *tree, ****************************************************************************/ static NTSTATUS smb_raw_t2search_backend(struct cli_tree *tree, TALLOC_CTX *mem_ctx, - enum search_level level, + enum smb_search_level level, uint16_t flags, int16_t count, DATA_BLOB *blob, -- cgit From 5ddf678e0113f81aa2b5f99134cda4fe8c01afb7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 23 Jul 2004 06:40:49 +0000 Subject: r1578: the first stage of the async client rewrite. Up to now the client code has had an async API, and operated asynchronously at the packet level, but was not truly async in that it assumed that it could always write to the socket and when a partial packet came in that it could block waiting for the rest of the packet. This change makes the SMB client library full async, by adding a separate outgoing packet queue, using non-blocking socket IO and having a input buffer that can fill asynchonously until the full packet has arrived. The main complexity was in dealing with the events structure when using the CIFS proxy backend. In that case the same events structure needs to be used in both the client library and the main smbd server, so that when the client library is waiting for a reply that the main server keeps processing packets. This required some changes in the events library code. Next step is to make the generated rpc client code use these new capabilities. (This used to be commit 96bf4da3edc4d64b0f58ef520269f3b385b8da02) --- source4/libcli/raw/clisocket.c | 8 +- source4/libcli/raw/clitransport.c | 337 +++++++++++++++++++++++++++++++++----- source4/libcli/raw/rawrequest.c | 186 +-------------------- 3 files changed, 306 insertions(+), 225 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 5cd6f33689..eb5d3c0342 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -72,7 +72,13 @@ BOOL cli_sock_connect(struct cli_socket *sock, struct in_addr *ip, int port) &sock->dest_ip, sock->port, LONG_CONNECT_TIMEOUT); - return (sock->fd != -1); + if (sock->fd == -1) { + return False; + } + + set_blocking(sock->fd, False); + + return True; } diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 18784fe33a..96d5a18a71 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -21,6 +21,17 @@ #include "includes.h" +/* + an event has happened on the socket +*/ +static void cli_transport_event_handler(struct event_context *ev, struct fd_event *fde, + time_t t, uint16_t flags) +{ + struct cli_transport *transport = fde->private; + + cli_transport_process(transport); +} + /* create a transport structure based on an established socket */ @@ -28,6 +39,7 @@ struct cli_transport *cli_transport_init(struct cli_socket *sock) { TALLOC_CTX *mem_ctx; struct cli_transport *transport; + struct fd_event fde; mem_ctx = talloc_init("cli_transport"); if (!mem_ctx) return NULL; @@ -35,6 +47,12 @@ struct cli_transport *cli_transport_init(struct cli_socket *sock) transport = talloc_zero(mem_ctx, sizeof(*transport)); if (!transport) return NULL; + transport->event.ctx = event_context_init(); + if (transport->event.ctx == NULL) { + talloc_destroy(mem_ctx); + return NULL; + } + transport->mem_ctx = mem_ctx; transport->socket = sock; transport->negotiate.protocol = PROTOCOL_NT1; @@ -47,6 +65,14 @@ struct cli_transport *cli_transport_init(struct cli_socket *sock) ZERO_STRUCT(transport->called); + fde.fd = sock->fd; + fde.flags = EVENT_FD_READ; + fde.handler = cli_transport_event_handler; + fde.private = transport; + fde.ref_count = 1; + + transport->event.fde = event_add_fd(transport->event.ctx, &fde); + return transport; } @@ -59,6 +85,9 @@ void cli_transport_close(struct cli_transport *transport) transport->reference_count--; if (transport->reference_count <= 0) { cli_sock_close(transport->socket); + event_remove_fd(transport->event.ctx, transport->event.fde); + event_remove_timed(transport->event.ctx, transport->event.te); + event_context_destroy(transport->event.ctx); talloc_destroy(transport->mem_ctx); } } @@ -72,6 +101,21 @@ void cli_transport_dead(struct cli_transport *transport) } +/* + enable select for write on a transport +*/ +static void cli_transport_write_enable(struct cli_transport *transport) +{ + transport->event.fde->flags |= EVENT_FD_WRITE; +} + +/* + disable select for write on a transport +*/ +static void cli_transport_write_disable(struct cli_transport *transport) +{ + transport->event.fde->flags &= ~EVENT_FD_WRITE; +} /**************************************************************************** send a session request (if appropriate) @@ -145,7 +189,7 @@ again: /* the zero mid is reserved for requests that don't have a mid */ if (mid == 0) mid = 1; - for (req=transport->pending_requests; req; req=req->next) { + for (req=transport->pending_recv; req; req=req->next) { if (req->mid == mid) { mid++; goto again; @@ -156,81 +200,284 @@ again: return mid; } +static void idle_handler(struct event_context *ev, + struct timed_event *te, time_t t) +{ + struct cli_transport *transport = te->private; + te->next_event = t + transport->idle.period; + transport->idle.func(transport, transport->idle.private); +} + /* setup the idle handler for a transport + the period is in seconds */ void cli_transport_idle_handler(struct cli_transport *transport, void (*idle_func)(struct cli_transport *, void *), uint_t period, void *private) { + struct timed_event te; transport->idle.func = idle_func; transport->idle.private = private; transport->idle.period = period; -} + if (transport->event.te != NULL) { + event_remove_timed(transport->event.ctx, transport->event.te); + } + + te.next_event = time(NULL) + period; + te.handler = idle_handler; + te.private = transport; + transport->event.te = event_add_timed(transport->event.ctx, &te); +} /* - determine if a packet is pending for receive on a transport + process some pending sends */ -BOOL cli_transport_pending(struct cli_transport *transport) +static void cli_transport_process_send(struct cli_transport *transport) { - return socket_pending(transport->socket->fd); -} - + while (transport->pending_send) { + struct cli_request *req = transport->pending_send; + ssize_t ret; + ret = cli_sock_write(transport->socket, req->out.buffer, req->out.size); + if (ret == -1) { + if (errno == EAGAIN || errno == EINTR) { + return; + } + cli_transport_dead(transport); + } + req->out.buffer += ret; + req->out.size -= ret; + if (req->out.size == 0) { + req->state = CLI_REQUEST_RECV; + DLIST_REMOVE(transport->pending_send, req); + DLIST_ADD(transport->pending_recv, req); + } + } + /* we're out of requests to send, so don't wait for write + events any more */ + cli_transport_write_disable(transport); +} /* - wait for data on a transport, periodically calling a wait function - if one has been defined - return True if a packet is received -*/ -BOOL cli_transport_select(struct cli_transport *transport) + we have a full request in our receive buffer - match it to a pending request + and process + */ +static void cli_transport_finish_recv(struct cli_transport *transport) { - fd_set fds; - int selrtn; - int fd; - struct timeval timeout; + uint8_t *buffer, *hdr, *vwv; + int len; + uint16_t wct, mid = 0; + struct cli_request *req; - fd = transport->socket->fd; + buffer = transport->recv_buffer.buffer; + len = transport->recv_buffer.req_size; - if (fd == -1) { - return False; + hdr = buffer+NBT_HDR_SIZE; + vwv = hdr + HDR_VWV; + + /* see if it could be an oplock break request */ + if (handle_oplock_break(transport, len, hdr, vwv)) { + talloc_free(transport->mem_ctx, buffer); + ZERO_STRUCT(transport->recv_buffer); + return; } - do { - uint_t period = 1000; + /* at this point we need to check for a readbraw reply, as + these can be any length */ + if (transport->readbraw_pending) { + transport->readbraw_pending = 0; + + /* it must match the first entry in the pending queue + as the client is not allowed to have outstanding + readbraw requests */ + req = transport->pending_recv; + if (!req) goto error; + + req->in.buffer = buffer; + talloc_steal(transport->mem_ctx, req->mem_ctx, buffer); + req->in.size = len + NBT_HDR_SIZE; + req->in.allocated = req->in.size; + goto async; + } - FD_ZERO(&fds); - FD_SET(fd,&fds); - - if (transport->idle.func) { - period = transport->idle.period; + if (len >= MIN_SMB_SIZE) { + /* extract the mid for matching to pending requests */ + mid = SVAL(hdr, HDR_MID); + wct = CVAL(hdr, HDR_WCT); + } + + /* match the incoming request against the list of pending requests */ + for (req=transport->pending_recv; req; req=req->next) { + if (req->mid == mid) break; + } + + if (!req) { + DEBUG(1,("Discarding unmatched reply with mid %d\n", mid)); + goto error; + } + + /* fill in the 'in' portion of the matching request */ + req->in.buffer = buffer; + talloc_steal(transport->mem_ctx, req->mem_ctx, buffer); + req->in.size = len + NBT_HDR_SIZE; + req->in.allocated = req->in.size; + + /* handle non-SMB replies */ + if (req->in.size < NBT_HDR_SIZE + MIN_SMB_SIZE) { + req->state = CLI_REQUEST_ERROR; + goto error; + } + + if (req->in.size < NBT_HDR_SIZE + MIN_SMB_SIZE + VWV(wct)) { + DEBUG(2,("bad reply size for mid %d\n", mid)); + req->status = NT_STATUS_UNSUCCESSFUL; + req->state = CLI_REQUEST_ERROR; + goto error; + } + + req->in.hdr = hdr; + req->in.vwv = vwv; + req->in.wct = wct; + if (req->in.size >= NBT_HDR_SIZE + MIN_SMB_SIZE + VWV(wct)) { + req->in.data = req->in.vwv + VWV(wct) + 2; + req->in.data_size = SVAL(req->in.vwv, VWV(wct)); + if (req->in.size < NBT_HDR_SIZE + MIN_SMB_SIZE + VWV(wct) + req->in.data_size) { + DEBUG(3,("bad data size for mid %d\n", mid)); + /* blergh - w2k3 gives a bogus data size values in some + openX replies */ + req->in.data_size = req->in.size - (NBT_HDR_SIZE + MIN_SMB_SIZE + VWV(wct)); } + } + req->in.ptr = req->in.data; + req->flags2 = SVAL(req->in.hdr, HDR_FLG2); + + if (!(req->flags2 & FLAGS2_32_BIT_ERROR_CODES)) { + transport->error.etype = ETYPE_DOS; + transport->error.e.dos.eclass = CVAL(req->in.hdr,HDR_RCLS); + transport->error.e.dos.ecode = SVAL(req->in.hdr,HDR_ERR); + req->status = dos_to_ntstatus(transport->error.e.dos.eclass, + transport->error.e.dos.ecode); + } else { + transport->error.etype = ETYPE_NT; + transport->error.e.nt_status = NT_STATUS(IVAL(req->in.hdr, HDR_RCLS)); + req->status = transport->error.e.nt_status; + } + + if (!cli_request_check_sign_mac(req)) { + transport->error.etype = ETYPE_SOCKET; + transport->error.e.socket_error = SOCKET_READ_BAD_SIG; + req->state = CLI_REQUEST_ERROR; + goto error; + }; + +async: + /* if this request has an async handler then call that to + notify that the reply has been received. This might destroy + the request so it must happen last */ + ZERO_STRUCT(transport->recv_buffer); + DLIST_REMOVE(transport->pending_recv, req); + req->state = CLI_REQUEST_DONE; + if (req->async.fn) { + req->async.fn(req); + } + return; + +error: + if (req) { + DLIST_REMOVE(transport->pending_recv, req); + req->state = CLI_REQUEST_ERROR; + } + ZERO_STRUCT(transport->recv_buffer); +} - timeout.tv_sec = period / 1000; - timeout.tv_usec = 1000*(period%1000); - - selrtn = sys_select_intr(fd+1,&fds,NULL,NULL,&timeout); - - if (selrtn == 1) { - /* the fd is readable */ - return True; +/* + process some pending receives +*/ +static void cli_transport_process_recv(struct cli_transport *transport) +{ + /* a incoming packet goes through 2 stages - first we read the + 4 byte header, which tells us how much more is coming. Then + we read the rest */ + if (transport->recv_buffer.received < NBT_HDR_SIZE) { + ssize_t ret; + ret = cli_sock_read(transport->socket, + transport->recv_buffer.header + + transport->recv_buffer.received, + NBT_HDR_SIZE - transport->recv_buffer.received); + if (ret == -1) { + if (errno == EINTR || errno == EAGAIN) { + return; + } + cli_transport_dead(transport); + return; } - - if (selrtn == -1) { - /* sys_select_intr() already handles EINTR, so this - is an error. The socket is probably dead */ - return False; + + transport->recv_buffer.received += ret; + + if (transport->recv_buffer.received == NBT_HDR_SIZE) { + /* we've got a full header */ + transport->recv_buffer.req_size = smb_len(transport->recv_buffer.header) + NBT_HDR_SIZE; + transport->recv_buffer.buffer = talloc(transport->mem_ctx, + NBT_HDR_SIZE+transport->recv_buffer.req_size); + if (transport->recv_buffer.buffer == NULL) { + cli_transport_dead(transport); + return; + } + memcpy(transport->recv_buffer.buffer, transport->recv_buffer.header, NBT_HDR_SIZE); } - - /* only other possibility is that we timed out - call the idle function - if there is one */ - if (transport->idle.func) { - transport->idle.func(transport, transport->idle.private); + } + + if (transport->recv_buffer.received < transport->recv_buffer.req_size) { + ssize_t ret; + ret = cli_sock_read(transport->socket, + transport->recv_buffer.buffer + + transport->recv_buffer.received, + transport->recv_buffer.req_size - + transport->recv_buffer.received); + if (ret == -1) { + if (errno == EINTR || errno == EAGAIN) { + return; + } + cli_transport_dead(transport); + return; } - } while (selrtn == 0); + transport->recv_buffer.received += ret; + } + + if (transport->recv_buffer.received != 0 && + transport->recv_buffer.received == transport->recv_buffer.req_size) { + cli_transport_finish_recv(transport); + } +} +/* + process some read/write requests that are pending + return False if the socket is dead +*/ +BOOL cli_transport_process(struct cli_transport *transport) +{ + cli_transport_process_send(transport); + cli_transport_process_recv(transport); + if (transport->socket->fd == -1) { + return False; + } return True; } + + +/* + put a request into the send queue +*/ +void cli_transport_send(struct cli_request *req) +{ + /* put it on the outgoing socket queue */ + req->state = CLI_REQUEST_SEND; + DLIST_ADD(req->transport->pending_send, req); + + /* make sure we look for write events */ + cli_transport_write_enable(req->transport); +} diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index c31f07505f..ce6cd0a1a4 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -43,7 +43,7 @@ NTSTATUS cli_request_destroy(struct cli_request *req) if (req->transport) { /* remove it from the list of pending requests (a null op if its not in the list) */ - DLIST_REMOVE(req->transport->pending_requests, req); + DLIST_REMOVE(req->transport->pending_recv, req); } /* ahh, its so nice to destroy a complex structure in such a @@ -79,6 +79,7 @@ struct cli_request *cli_request_setup_nonsmb(struct cli_transport *transport, ui ZERO_STRUCTP(req); /* setup the request context */ + req->state = CLI_REQUEST_INIT; req->mem_ctx = mem_ctx; req->transport = transport; req->session = NULL; @@ -266,32 +267,20 @@ static void cli_req_grow_data(struct cli_request *req, uint_t new_size) SSVAL(req->out.vwv, VWV(req->out.wct), new_size); } + /* send a message */ BOOL cli_request_send(struct cli_request *req) { - uint_t ret; - if (IVAL(req->out.buffer, 0) == 0) { _smb_setlen(req->out.buffer, req->out.size - NBT_HDR_SIZE); } cli_request_calculate_sign_mac(req); - ret = cli_sock_write(req->transport->socket, req->out.buffer, req->out.size); - - if (req->out.size != ret) { - req->transport->error.etype = ETYPE_SOCKET; - req->transport->error.e.socket_error = SOCKET_WRITE_ERROR; - DEBUG(0,("Error writing %d bytes to server - %s\n", - (int)req->out.size, strerror(errno))); - return False; - } + cli_transport_send(req); - /* add it to the list of pending requests */ - DLIST_ADD(req->transport->pending_requests, req); - return True; } @@ -306,17 +295,8 @@ BOOL cli_request_receive(struct cli_request *req) if (!req) return False; /* keep receiving packets until this one is replied to */ - while (!req->in.buffer) { - if (!cli_transport_select(req->transport)) { - req->status = NT_STATUS_UNSUCCESSFUL; - return False; - } - - if (!cli_request_receive_next(req->transport)) { - cli_transport_dead(req->transport); - req->status = NT_STATUS_UNEXPECTED_NETWORK_ERROR; - return False; - } + while (req->state <= CLI_REQUEST_RECV) { + event_loop_once(req->transport->event.ctx); } return True; @@ -327,7 +307,7 @@ BOOL cli_request_receive(struct cli_request *req) handle oplock break requests from the server - return True if the request was an oplock break */ -static BOOL handle_oplock_break(struct cli_transport *transport, uint_t len, const char *hdr, const char *vwv) +BOOL handle_oplock_break(struct cli_transport *transport, uint_t len, const char *hdr, const char *vwv) { /* we must be very fussy about what we consider an oplock break to avoid matching readbraw replies */ @@ -350,158 +330,6 @@ static BOOL handle_oplock_break(struct cli_transport *transport, uint_t len, con return True; } - -/* - receive an async message from the server - this function assumes that the caller already knows that the socket is readable - and that there is a packet waiting - - The packet is not actually returned by this function, instead any - registered async message handlers are called - - return True if a packet was successfully received and processed - return False if the socket appears to be dead -*/ -BOOL cli_request_receive_next(struct cli_transport *transport) -{ - BOOL ret; - int len; - char header[NBT_HDR_SIZE]; - char *buffer, *hdr, *vwv; - TALLOC_CTX *mem_ctx; - struct cli_request *req; - uint16_t wct, mid = 0; - - len = cli_sock_read(transport->socket, header, 4); - if (len != 4) { - return False; - } - - len = smb_len(header); - - mem_ctx = talloc_init("cli_request_receive_next"); - - /* allocate the incoming buffer at the right size */ - buffer = talloc(mem_ctx, len+NBT_HDR_SIZE); - if (!buffer) { - talloc_destroy(mem_ctx); - return False; - } - - /* fill in the already received header */ - memcpy(buffer, header, NBT_HDR_SIZE); - - ret = cli_sock_read(transport->socket, buffer + NBT_HDR_SIZE, len); - /* If the server is not responding, note that now */ - if (ret != len) { - return False; - } - - hdr = buffer+NBT_HDR_SIZE; - vwv = hdr + HDR_VWV; - - /* see if it could be an oplock break request */ - if (handle_oplock_break(transport, len, hdr, vwv)) { - goto done; - } - - /* at this point we need to check for a readbraw reply, as these can be any length */ - if (transport->readbraw_pending) { - transport->readbraw_pending = 0; - - /* it must match the first entry in the pending queue as the client is not allowed - to have outstanding readbraw requests */ - req = transport->pending_requests; - if (!req) goto done; - - req->in.buffer = buffer; - talloc_steal(mem_ctx, req->mem_ctx, buffer); - req->in.size = len + NBT_HDR_SIZE; - req->in.allocated = req->in.size; - goto async; - } - - if (len >= MIN_SMB_SIZE) { - /* extract the mid for matching to pending requests */ - mid = SVAL(hdr, HDR_MID); - wct = CVAL(hdr, HDR_WCT); - } - - /* match the incoming request against the list of pending requests */ - for (req=transport->pending_requests; req; req=req->next) { - if (req->mid == mid) break; - } - - if (!req) { - DEBUG(3,("Discarding unmatched reply with mid %d\n", mid)); - goto done; - } - - /* fill in the 'in' portion of the matching request */ - req->in.buffer = buffer; - talloc_steal(mem_ctx, req->mem_ctx, buffer); - req->in.size = len + NBT_HDR_SIZE; - req->in.allocated = req->in.size; - - /* handle non-SMB replies */ - if (req->in.size < NBT_HDR_SIZE + MIN_SMB_SIZE) { - goto done; - } - - if (req->in.size < NBT_HDR_SIZE + MIN_SMB_SIZE + VWV(wct)) { - DEBUG(2,("bad reply size for mid %d\n", mid)); - req->status = NT_STATUS_UNSUCCESSFUL; - goto done; - } - - req->in.hdr = hdr; - req->in.vwv = vwv; - req->in.wct = wct; - if (req->in.size >= NBT_HDR_SIZE + MIN_SMB_SIZE + VWV(wct)) { - req->in.data = req->in.vwv + VWV(wct) + 2; - req->in.data_size = SVAL(req->in.vwv, VWV(wct)); - if (req->in.size < NBT_HDR_SIZE + MIN_SMB_SIZE + VWV(wct) + req->in.data_size) { - DEBUG(3,("bad data size for mid %d\n", mid)); - /* blergh - w2k3 gives a bogus data size values in some - openX replies */ - req->in.data_size = req->in.size - (NBT_HDR_SIZE + MIN_SMB_SIZE + VWV(wct)); - } - } - req->in.ptr = req->in.data; - req->flags2 = SVAL(req->in.hdr, HDR_FLG2); - - if (!(req->flags2 & FLAGS2_32_BIT_ERROR_CODES)) { - transport->error.etype = ETYPE_DOS; - transport->error.e.dos.eclass = CVAL(req->in.hdr,HDR_RCLS); - transport->error.e.dos.ecode = SVAL(req->in.hdr,HDR_ERR); - req->status = dos_to_ntstatus(transport->error.e.dos.eclass, - transport->error.e.dos.ecode); - } else { - transport->error.etype = ETYPE_NT; - transport->error.e.nt_status = NT_STATUS(IVAL(req->in.hdr, HDR_RCLS)); - req->status = transport->error.e.nt_status; - } - - if (!cli_request_check_sign_mac(req)) { - transport->error.etype = ETYPE_SOCKET; - transport->error.e.socket_error = SOCKET_READ_BAD_SIG; - return False; - }; - -async: - /* if this request has an async handler then call that to - notify that the reply has been received. This might destroy - the request so it must happen last */ - if (req->async.fn) { - req->async.fn(req); - } - -done: - talloc_destroy(mem_ctx); - return True; -} - - /* wait for a reply to be received for a packet that just returns an error code and nothing more -- cgit From b5061894dc91cd307d0e6b9157b36bd4f36a5c41 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 29 Jul 2004 08:14:34 +0000 Subject: r1602: make sure we honor the use_spnego flag (This used to be commit de764d9004a0d90479158e78e30b1266eb529e3e) --- source4/libcli/raw/clisession.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index c6d7f800a4..d5373bc76f 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -512,7 +512,8 @@ static NTSTATUS smb_raw_session_setup_generic(struct cli_session *session, } /* see if we should use the NT1 interface */ - if (!(parms->generic.in.capabilities & CAP_EXTENDED_SECURITY)) { + if (!session->transport->options.use_spnego || + !(parms->generic.in.capabilities & CAP_EXTENDED_SECURITY)) { return smb_raw_session_setup_generic_nt1(session, mem_ctx, parms); } -- cgit From 2de2ead42d93804d94407aaa92fc9dca4ed87129 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 29 Jul 2004 09:30:54 +0000 Subject: r1603: fixed in.size to not overstate the packet size by 4 bytes my apologies to abartlett for thinking this was his bug! (This used to be commit 6edbc55ddd2fc0d4686ec3075ba9bfc72ac24315) --- source4/libcli/raw/clitransport.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 96d5a18a71..abdcc0d392 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -298,7 +298,7 @@ static void cli_transport_finish_recv(struct cli_transport *transport) req->in.buffer = buffer; talloc_steal(transport->mem_ctx, req->mem_ctx, buffer); - req->in.size = len + NBT_HDR_SIZE; + req->in.size = len; req->in.allocated = req->in.size; goto async; } @@ -322,7 +322,7 @@ static void cli_transport_finish_recv(struct cli_transport *transport) /* fill in the 'in' portion of the matching request */ req->in.buffer = buffer; talloc_steal(transport->mem_ctx, req->mem_ctx, buffer); - req->in.size = len + NBT_HDR_SIZE; + req->in.size = len; req->in.allocated = req->in.size; /* handle non-SMB replies */ -- cgit From f1a215f5cb174a0bfe50f288fbd998c8fabb0b63 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 29 Jul 2004 10:13:34 +0000 Subject: r1604: Samba4 avoids memcpy() as much as possible - we don't need to make a copy here. Andrew Bartlett (This used to be commit 9efc94eeafbf0eb4488c53a1456cc7026c937f9f) --- source4/libcli/raw/smb_signing.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/smb_signing.c b/source4/libcli/raw/smb_signing.c index 20f8921acb..80615f2d72 100644 --- a/source4/libcli/raw/smb_signing.c +++ b/source4/libcli/raw/smb_signing.c @@ -143,7 +143,7 @@ BOOL check_signed_incoming_message(struct request_buffer *in, DATA_BLOB *mac_key { BOOL good; uint8_t calc_md5_mac[16]; - uint8_t server_sent_mac[8]; + uint8_t *server_sent_mac; uint8_t sequence_buf[8]; struct MD5Context md5_ctx; const size_t offset_end_of_sig = (HDR_SS_FIELD + 8); @@ -166,7 +166,7 @@ BOOL check_signed_incoming_message(struct request_buffer *in, DATA_BLOB *mac_key SIVAL(sequence_buf, 4, 0); /* get a copy of the server-sent mac */ - memcpy(server_sent_mac, &in->hdr[HDR_SS_FIELD], sizeof(server_sent_mac)); + server_sent_mac = &in->hdr[HDR_SS_FIELD]; /* Calculate the 16 byte MAC and place first 8 bytes into the field. */ MD5Init(&md5_ctx); -- cgit From 27ce337277211f7536b7bd750bb42b8a87089fc4 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 2 Aug 2004 05:51:42 +0000 Subject: r1618: fixed the receipt of multi-part replies to SMBtrans2 (This used to be commit bd4106a8e57fc98d1feddc01b58f87f68164247a) --- source4/libcli/raw/rawrequest.c | 13 +++++++++++++ source4/libcli/raw/rawtrans.c | 5 +---- 2 files changed, 14 insertions(+), 4 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index ce6cd0a1a4..9c53c4b18c 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -303,6 +303,19 @@ BOOL cli_request_receive(struct cli_request *req) } +/* + receive another reply to a request - this is used for requests that + have multi-part replies (such as SMBtrans2) +*/ +BOOL cli_request_receive_more(struct cli_request *req) +{ + req->state = CLI_REQUEST_RECV; + DLIST_ADD(req->transport->pending_recv, req); + + return cli_request_receive(req); +} + + /* handle oplock break requests from the server - return True if the request was an oplock break diff --git a/source4/libcli/raw/rawtrans.c b/source4/libcli/raw/rawtrans.c index fb2abf3e2d..5dde753368 100644 --- a/source4/libcli/raw/rawtrans.c +++ b/source4/libcli/raw/rawtrans.c @@ -180,10 +180,7 @@ NTSTATUS smb_raw_trans2_recv(struct cli_request *req, if (total_data <= parms->out.data.length && total_param <= parms->out.params.length) break; - /* to receive more requests we need to mark this request as not received */ - req->in.buffer = NULL; - - if (!cli_request_receive(req)) { + if (!cli_request_receive_more(req)) { req->status = NT_STATUS_UNSUCCESSFUL; return cli_request_destroy(req); } -- cgit From cfdd3e68bed5f0c8cfa7d50ee8d7ce70826aa664 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 3 Aug 2004 05:59:28 +0000 Subject: r1631: don't use req->transport after req has been destroyed (This used to be commit 35f4ad4700de25085a2d0e5d0f9674ca2e606cd1) --- source4/libcli/raw/rawfile.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c index 5128ba96ce..0d00ffcca6 100644 --- a/source4/libcli/raw/rawfile.c +++ b/source4/libcli/raw/rawfile.c @@ -267,6 +267,7 @@ static struct cli_request *smb_raw_t2open_send(struct cli_tree *tree, ****************************************************************************/ static NTSTATUS smb_raw_t2open_recv(struct cli_request *req, TALLOC_CTX *mem_ctx, union smb_open *parms) { + struct cli_transport *transport = req?req->transport:NULL; struct smb_trans2 t2; NTSTATUS status; @@ -279,8 +280,7 @@ static NTSTATUS smb_raw_t2open_recv(struct cli_request *req, TALLOC_CTX *mem_ctx parms->t2open.out.fnum = SVAL(t2.out.params.data, VWV(0)); parms->t2open.out.attrib = SVAL(t2.out.params.data, VWV(1)); - parms->t2open.out.write_time = raw_pull_dos_date3(req->transport, - t2.out.params.data + VWV(2)); + parms->t2open.out.write_time = raw_pull_dos_date3(transport, t2.out.params.data + VWV(2)); parms->t2open.out.size = IVAL(t2.out.params.data, VWV(4)); parms->t2open.out.access = SVAL(t2.out.params.data, VWV(6)); parms->t2open.out.ftype = SVAL(t2.out.params.data, VWV(7)); -- cgit From 53781e9d37b9adb1cf2d5be2a6ae6c1f5ace26c9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 3 Aug 2004 06:52:06 +0000 Subject: r1633: fixed a couple of async oplock handling errors (This used to be commit d7e2f39b90122088e94d4a8e8c7ffa7c91d7d664) --- source4/libcli/raw/clioplock.c | 5 ++++- source4/libcli/raw/clitransport.c | 14 +++++++++----- source4/libcli/raw/rawnotify.c | 3 ++- source4/libcli/raw/rawrequest.c | 2 +- source4/libcli/raw/smb_signing.c | 2 +- 5 files changed, 17 insertions(+), 9 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clioplock.c b/source4/libcli/raw/clioplock.c index 0cd6adb41f..29e44fc940 100644 --- a/source4/libcli/raw/clioplock.c +++ b/source4/libcli/raw/clioplock.c @@ -39,8 +39,11 @@ BOOL cli_oplock_ack(struct cli_tree *tree, uint16_t fnum, uint16_t ack_level) SSVAL(req->out.vwv,VWV(6),0); SSVAL(req->out.vwv,VWV(7),0); + /* this request does not expect a reply, so tell the signing + subsystem not to allocate an id for a reply */ + req->one_way_request = 1; + ret = cli_request_send(req); - cli_request_destroy(req); return ret; } diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index abdcc0d392..d2d78d0789 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -250,9 +250,14 @@ static void cli_transport_process_send(struct cli_transport *transport) req->out.buffer += ret; req->out.size -= ret; if (req->out.size == 0) { - req->state = CLI_REQUEST_RECV; DLIST_REMOVE(transport->pending_send, req); - DLIST_ADD(transport->pending_recv, req); + if (req->one_way_request) { + req->state = CLI_REQUEST_DONE; + cli_request_destroy(req); + } else { + req->state = CLI_REQUEST_RECV; + DLIST_ADD(transport->pending_recv, req); + } } } @@ -275,13 +280,14 @@ static void cli_transport_finish_recv(struct cli_transport *transport) buffer = transport->recv_buffer.buffer; len = transport->recv_buffer.req_size; + ZERO_STRUCT(transport->recv_buffer); + hdr = buffer+NBT_HDR_SIZE; vwv = hdr + HDR_VWV; /* see if it could be an oplock break request */ if (handle_oplock_break(transport, len, hdr, vwv)) { talloc_free(transport->mem_ctx, buffer); - ZERO_STRUCT(transport->recv_buffer); return; } @@ -377,7 +383,6 @@ async: /* if this request has an async handler then call that to notify that the reply has been received. This might destroy the request so it must happen last */ - ZERO_STRUCT(transport->recv_buffer); DLIST_REMOVE(transport->pending_recv, req); req->state = CLI_REQUEST_DONE; if (req->async.fn) { @@ -390,7 +395,6 @@ error: DLIST_REMOVE(transport->pending_recv, req); req->state = CLI_REQUEST_ERROR; } - ZERO_STRUCT(transport->recv_buffer); } /* diff --git a/source4/libcli/raw/rawnotify.c b/source4/libcli/raw/rawnotify.c index b8efa2fcd6..a9215fee10 100644 --- a/source4/libcli/raw/rawnotify.c +++ b/source4/libcli/raw/rawnotify.c @@ -108,9 +108,10 @@ NTSTATUS smb_raw_ntcancel(struct cli_request *oldreq) /* this request does not expect a reply, so tell the signing subsystem not to allocate an id for a reply */ + req->sign_single_increment = 1; req->one_way_request = 1; cli_request_send(req); - return cli_request_destroy(req); + return NT_STATUS_OK; } diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 9c53c4b18c..38b8f71f57 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -324,7 +324,7 @@ BOOL handle_oplock_break(struct cli_transport *transport, uint_t len, const char { /* we must be very fussy about what we consider an oplock break to avoid matching readbraw replies */ - if (len != MIN_SMB_SIZE + VWV(8) || + if (len != MIN_SMB_SIZE + VWV(8) + NBT_HDR_SIZE || (CVAL(hdr, HDR_FLG) & FLAG_REPLY) || CVAL(hdr,HDR_COM) != SMBlockingX || SVAL(hdr, HDR_MID) != 0xFFFF || diff --git a/source4/libcli/raw/smb_signing.c b/source4/libcli/raw/smb_signing.c index 80615f2d72..9c02fe50ec 100644 --- a/source4/libcli/raw/smb_signing.c +++ b/source4/libcli/raw/smb_signing.c @@ -220,7 +220,7 @@ static void cli_request_simple_sign_outgoing_message(struct cli_request *req) /* some requests (eg. NTcancel) are one way, and the sequence number should be increased by 1 not 2 */ - if (req->one_way_request) { + if (req->sign_single_increment) { data->next_seq_num += 1; } else { data->next_seq_num += 2; -- cgit From 682a02d7d41b7653e5c9e90e65d290a8314045f0 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 3 Aug 2004 07:16:41 +0000 Subject: r1634: to get signing right for async requests we must send requests in order. Fixed the linked list add to always add to the end for outgoing requests. (This used to be commit 81c450b434bb28b0fa8620c309f39203e8950497) --- source4/libcli/raw/clitransport.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index d2d78d0789..a33cc5e8f6 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -480,7 +480,7 @@ void cli_transport_send(struct cli_request *req) { /* put it on the outgoing socket queue */ req->state = CLI_REQUEST_SEND; - DLIST_ADD(req->transport->pending_send, req); + DLIST_ADD_END(req->transport->pending_send, req, struct cli_request *); /* make sure we look for write events */ cli_transport_write_enable(req->transport); -- cgit From bff2c7a5780433d815eea7a3d735ac562a0dbdf9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 3 Aug 2004 08:04:11 +0000 Subject: r1635: when a transport dies, setup errors for all pending sends and recvs, plus disalllow any more sends (This used to be commit 326fdc8c9d2848c6c08a49e34c72430fe0116d23) --- source4/libcli/raw/clitransport.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index a33cc5e8f6..3b3c10ed01 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -98,6 +98,28 @@ void cli_transport_close(struct cli_transport *transport) void cli_transport_dead(struct cli_transport *transport) { cli_sock_dead(transport->socket); + + /* all pending sends become errors */ + while (transport->pending_send) { + struct cli_request *req = transport->pending_send; + req->state = CLI_REQUEST_ERROR; + req->status = NT_STATUS_NET_WRITE_FAULT; + DLIST_REMOVE(transport->pending_send, req); + if (req->async.fn) { + req->async.fn(req); + } + } + + /* as do all pending receives */ + while (transport->pending_recv) { + struct cli_request *req = transport->pending_recv; + req->state = CLI_REQUEST_ERROR; + req->status = NT_STATUS_NET_WRITE_FAULT; + DLIST_REMOVE(transport->pending_recv, req); + if (req->async.fn) { + req->async.fn(req); + } + } } @@ -478,6 +500,13 @@ BOOL cli_transport_process(struct cli_transport *transport) */ void cli_transport_send(struct cli_request *req) { + /* check if the transport is dead */ + if (req->transport->socket->fd == -1) { + req->state = CLI_REQUEST_ERROR; + req->status = NT_STATUS_NET_WRITE_FAULT; + return; + } + /* put it on the outgoing socket queue */ req->state = CLI_REQUEST_SEND; DLIST_ADD_END(req->transport->pending_send, req, struct cli_request *); -- cgit From c5fbb6f23c2d399c7510bc552cdb1a27b1ef66a8 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 4 Aug 2004 13:23:35 +0000 Subject: r1654: rename cli_ -> smbcli_ rename CLI_ -> SMBCLI_ metze (This used to be commit 8441750fd9427dd6fe477f27e603821b4026f038) --- source4/libcli/raw/clioplock.c | 12 +- source4/libcli/raw/clisession.c | 140 +++++++++++----------- source4/libcli/raw/clisocket.c | 34 +++--- source4/libcli/raw/clitransport.c | 124 ++++++++++---------- source4/libcli/raw/clitree.c | 100 ++++++++-------- source4/libcli/raw/rawacl.c | 12 +- source4/libcli/raw/rawdate.c | 12 +- source4/libcli/raw/rawfile.c | 224 ++++++++++++++++++------------------ source4/libcli/raw/rawfileinfo.c | 118 +++++++++---------- source4/libcli/raw/rawfsinfo.c | 42 +++---- source4/libcli/raw/rawioctl.c | 46 ++++---- source4/libcli/raw/rawnegotiate.c | 48 ++++---- source4/libcli/raw/rawnotify.c | 16 +-- source4/libcli/raw/rawreadwrite.c | 62 +++++----- source4/libcli/raw/rawrequest.c | 144 +++++++++++------------ source4/libcli/raw/rawsearch.c | 138 +++++++++++----------- source4/libcli/raw/rawsetfileinfo.c | 68 +++++------ source4/libcli/raw/rawtrans.c | 110 +++++++++--------- source4/libcli/raw/smb_signing.c | 62 +++++----- 19 files changed, 756 insertions(+), 756 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clioplock.c b/source4/libcli/raw/clioplock.c index 29e44fc940..6ae21a08f4 100644 --- a/source4/libcli/raw/clioplock.c +++ b/source4/libcli/raw/clioplock.c @@ -23,12 +23,12 @@ /**************************************************************************** send an ack for an oplock break request ****************************************************************************/ -BOOL cli_oplock_ack(struct cli_tree *tree, uint16_t fnum, uint16_t ack_level) +BOOL smbcli_oplock_ack(struct smbcli_tree *tree, uint16_t fnum, uint16_t ack_level) { BOOL ret; - struct cli_request *req; + struct smbcli_request *req; - req = cli_request_setup(tree, SMBlockingX, 8, 0); + req = smbcli_request_setup(tree, SMBlockingX, 8, 0); SSVAL(req->out.vwv,VWV(0),0xFF); SSVAL(req->out.vwv,VWV(1),0); @@ -43,7 +43,7 @@ BOOL cli_oplock_ack(struct cli_tree *tree, uint16_t fnum, uint16_t ack_level) subsystem not to allocate an id for a reply */ req->one_way_request = 1; - ret = cli_request_send(req); + ret = smbcli_request_send(req); return ret; } @@ -52,8 +52,8 @@ BOOL cli_oplock_ack(struct cli_tree *tree, uint16_t fnum, uint16_t ack_level) /**************************************************************************** set the oplock handler for a connection ****************************************************************************/ -void cli_oplock_handler(struct cli_transport *transport, - BOOL (*handler)(struct cli_transport *, uint16_t, uint16_t, uint8_t, void *), +void smbcli_oplock_handler(struct smbcli_transport *transport, + BOOL (*handler)(struct smbcli_transport *, uint16_t, uint16_t, uint8_t, void *), void *private) { transport->oplock.handler = handler; diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index d5373bc76f..b32d59f340 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -22,17 +22,17 @@ #include "includes.h" #define SETUP_REQUEST_SESSION(cmd, wct, buflen) do { \ - req = cli_request_setup_session(session, cmd, wct, buflen); \ + req = smbcli_request_setup_session(session, cmd, wct, buflen); \ if (!req) return NULL; \ } while (0) /**************************************************************************** Initialize the session context ****************************************************************************/ -struct cli_session *cli_session_init(struct cli_transport *transport) +struct smbcli_session *smbcli_session_init(struct smbcli_transport *transport) { - struct cli_session *session; - TALLOC_CTX *mem_ctx = talloc_init("cli_session"); + struct smbcli_session *session; + TALLOC_CTX *mem_ctx = talloc_init("smbcli_session"); if (mem_ctx == NULL) { return NULL; } @@ -55,11 +55,11 @@ struct cli_session *cli_session_init(struct cli_transport *transport) /**************************************************************************** reduce reference_count and destroy is <= 0 ****************************************************************************/ -void cli_session_close(struct cli_session *session) +void smbcli_session_close(struct smbcli_session *session) { session->reference_count--; if (session->reference_count <= 0) { - cli_transport_close(session->transport); + smbcli_transport_close(session->transport); talloc_destroy(session->mem_ctx); } } @@ -67,9 +67,9 @@ void cli_session_close(struct cli_session *session) /**************************************************************************** Perform a session setup (async send) ****************************************************************************/ -struct cli_request *smb_raw_session_setup_send(struct cli_session *session, union smb_sesssetup *parms) +struct smbcli_request *smb_raw_session_setup_send(struct smbcli_session *session, union smb_sesssetup *parms) { - struct cli_request *req; + struct smbcli_request *req; switch (parms->generic.level) { case RAW_SESSSETUP_GENERIC: @@ -85,11 +85,11 @@ struct cli_request *smb_raw_session_setup_send(struct cli_session *session, unio SSVAL(req->out.vwv,VWV(4),parms->old.in.vc_num); SIVAL(req->out.vwv,VWV(5),parms->old.in.sesskey); SSVAL(req->out.vwv,VWV(7),parms->old.in.password.length); - cli_req_append_blob(req, &parms->old.in.password); - cli_req_append_string(req, parms->old.in.user, STR_TERMINATE); - cli_req_append_string(req, parms->old.in.domain, STR_TERMINATE|STR_UPPER); - cli_req_append_string(req, parms->old.in.os, STR_TERMINATE); - cli_req_append_string(req, parms->old.in.lanman, STR_TERMINATE); + smbcli_req_append_blob(req, &parms->old.in.password); + smbcli_req_append_string(req, parms->old.in.user, STR_TERMINATE); + smbcli_req_append_string(req, parms->old.in.domain, STR_TERMINATE|STR_UPPER); + smbcli_req_append_string(req, parms->old.in.os, STR_TERMINATE); + smbcli_req_append_string(req, parms->old.in.lanman, STR_TERMINATE); break; case RAW_SESSSETUP_NT1: @@ -104,12 +104,12 @@ struct cli_request *smb_raw_session_setup_send(struct cli_session *session, unio SSVAL(req->out.vwv, VWV(8), parms->nt1.in.password2.length); SIVAL(req->out.vwv, VWV(9), 0); /* reserved */ SIVAL(req->out.vwv, VWV(11), parms->nt1.in.capabilities); - cli_req_append_blob(req, &parms->nt1.in.password1); - cli_req_append_blob(req, &parms->nt1.in.password2); - cli_req_append_string(req, parms->nt1.in.user, STR_TERMINATE); - cli_req_append_string(req, parms->nt1.in.domain, STR_TERMINATE|STR_UPPER); - cli_req_append_string(req, parms->nt1.in.os, STR_TERMINATE); - cli_req_append_string(req, parms->nt1.in.lanman, STR_TERMINATE); + smbcli_req_append_blob(req, &parms->nt1.in.password1); + smbcli_req_append_blob(req, &parms->nt1.in.password2); + smbcli_req_append_string(req, parms->nt1.in.user, STR_TERMINATE); + smbcli_req_append_string(req, parms->nt1.in.domain, STR_TERMINATE|STR_UPPER); + smbcli_req_append_string(req, parms->nt1.in.os, STR_TERMINATE); + smbcli_req_append_string(req, parms->nt1.in.lanman, STR_TERMINATE); break; case RAW_SESSSETUP_SPNEGO: @@ -123,15 +123,15 @@ struct cli_request *smb_raw_session_setup_send(struct cli_session *session, unio SSVAL(req->out.vwv, VWV(7), parms->spnego.in.secblob.length); SIVAL(req->out.vwv, VWV(8), 0); /* reserved */ SIVAL(req->out.vwv, VWV(10), parms->spnego.in.capabilities); - cli_req_append_blob(req, &parms->spnego.in.secblob); - cli_req_append_string(req, parms->spnego.in.os, STR_TERMINATE); - cli_req_append_string(req, parms->spnego.in.lanman, STR_TERMINATE); - cli_req_append_string(req, parms->spnego.in.domain, STR_TERMINATE); + smbcli_req_append_blob(req, &parms->spnego.in.secblob); + smbcli_req_append_string(req, parms->spnego.in.os, STR_TERMINATE); + smbcli_req_append_string(req, parms->spnego.in.lanman, STR_TERMINATE); + smbcli_req_append_string(req, parms->spnego.in.domain, STR_TERMINATE); break; } - if (!cli_request_send(req)) { - cli_request_destroy(req); + if (!smbcli_request_send(req)) { + smbcli_request_destroy(req); return NULL; } @@ -142,20 +142,20 @@ struct cli_request *smb_raw_session_setup_send(struct cli_session *session, unio /**************************************************************************** Perform a session setup (async recv) ****************************************************************************/ -NTSTATUS smb_raw_session_setup_recv(struct cli_request *req, +NTSTATUS smb_raw_session_setup_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, union smb_sesssetup *parms) { uint16_t len; char *p; - if (!cli_request_receive(req)) { - return cli_request_destroy(req); + if (!smbcli_request_receive(req)) { + return smbcli_request_destroy(req); } if (!NT_STATUS_IS_OK(req->status) && !NT_STATUS_EQUAL(req->status,NT_STATUS_MORE_PROCESSING_REQUIRED)) { - return cli_request_destroy(req); + return smbcli_request_destroy(req); } switch (parms->generic.level) { @@ -164,35 +164,35 @@ NTSTATUS smb_raw_session_setup_recv(struct cli_request *req, return NT_STATUS_INVALID_LEVEL; case RAW_SESSSETUP_OLD: - CLI_CHECK_WCT(req, 3); + SMBCLI_CHECK_WCT(req, 3); ZERO_STRUCT(parms->old.out); parms->old.out.vuid = SVAL(req->in.hdr, HDR_UID); parms->old.out.action = SVAL(req->in.vwv, VWV(2)); p = req->in.data; if (p) { - p += cli_req_pull_string(req, mem_ctx, &parms->old.out.os, p, -1, STR_TERMINATE); - p += cli_req_pull_string(req, mem_ctx, &parms->old.out.lanman, p, -1, STR_TERMINATE); - p += cli_req_pull_string(req, mem_ctx, &parms->old.out.domain, p, -1, STR_TERMINATE); + p += smbcli_req_pull_string(req, mem_ctx, &parms->old.out.os, p, -1, STR_TERMINATE); + p += smbcli_req_pull_string(req, mem_ctx, &parms->old.out.lanman, p, -1, STR_TERMINATE); + p += smbcli_req_pull_string(req, mem_ctx, &parms->old.out.domain, p, -1, STR_TERMINATE); } break; case RAW_SESSSETUP_NT1: - CLI_CHECK_WCT(req, 3); + SMBCLI_CHECK_WCT(req, 3); ZERO_STRUCT(parms->nt1.out); parms->nt1.out.vuid = SVAL(req->in.hdr, HDR_UID); parms->nt1.out.action = SVAL(req->in.vwv, VWV(2)); p = req->in.data; if (p) { - p += cli_req_pull_string(req, mem_ctx, &parms->nt1.out.os, p, -1, STR_TERMINATE); - p += cli_req_pull_string(req, mem_ctx, &parms->nt1.out.lanman, p, -1, STR_TERMINATE); + p += smbcli_req_pull_string(req, mem_ctx, &parms->nt1.out.os, p, -1, STR_TERMINATE); + p += smbcli_req_pull_string(req, mem_ctx, &parms->nt1.out.lanman, p, -1, STR_TERMINATE); if (p < (req->in.data + req->in.data_size)) { - p += cli_req_pull_string(req, mem_ctx, &parms->nt1.out.domain, p, -1, STR_TERMINATE); + p += smbcli_req_pull_string(req, mem_ctx, &parms->nt1.out.domain, p, -1, STR_TERMINATE); } } break; case RAW_SESSSETUP_SPNEGO: - CLI_CHECK_WCT(req, 4); + SMBCLI_CHECK_WCT(req, 4); ZERO_STRUCT(parms->spnego.out); parms->spnego.out.vuid = SVAL(req->in.hdr, HDR_UID); parms->spnego.out.action = SVAL(req->in.vwv, VWV(2)); @@ -202,16 +202,16 @@ NTSTATUS smb_raw_session_setup_recv(struct cli_request *req, break; } - parms->spnego.out.secblob = cli_req_pull_blob(req, mem_ctx, p, len); + parms->spnego.out.secblob = smbcli_req_pull_blob(req, mem_ctx, p, len); p += parms->spnego.out.secblob.length; - p += cli_req_pull_string(req, mem_ctx, &parms->spnego.out.os, p, -1, STR_TERMINATE); - p += cli_req_pull_string(req, mem_ctx, &parms->spnego.out.lanman, p, -1, STR_TERMINATE); - p += cli_req_pull_string(req, mem_ctx, &parms->spnego.out.domain, p, -1, STR_TERMINATE); + p += smbcli_req_pull_string(req, mem_ctx, &parms->spnego.out.os, p, -1, STR_TERMINATE); + p += smbcli_req_pull_string(req, mem_ctx, &parms->spnego.out.lanman, p, -1, STR_TERMINATE); + p += smbcli_req_pull_string(req, mem_ctx, &parms->spnego.out.domain, p, -1, STR_TERMINATE); break; } failed: - return cli_request_destroy(req); + return smbcli_request_destroy(req); } /* @@ -239,7 +239,7 @@ static DATA_BLOB nt_blob(const char *pass, DATA_BLOB challenge) /* store the user session key for a transport */ -void cli_session_set_user_session_key(struct cli_session *session, +void smbcli_session_set_user_session_key(struct smbcli_session *session, const DATA_BLOB *session_key) { session->user_session_key = data_blob_talloc(session->mem_ctx, @@ -250,19 +250,19 @@ void cli_session_set_user_session_key(struct cli_session *session, /* setup signing for a NT1 style session setup */ -static void use_nt1_session_keys(struct cli_session *session, +static void use_nt1_session_keys(struct smbcli_session *session, const char *password, const DATA_BLOB *nt_response) { - struct cli_transport *transport = session->transport; + struct smbcli_transport *transport = session->transport; uint8_t nt_hash[16]; DATA_BLOB session_key = data_blob(NULL, 16); E_md4hash(password, nt_hash); SMBsesskeygen_ntv1(nt_hash, session_key.data); - cli_transport_simple_set_signing(transport, session_key, *nt_response); + smbcli_transport_simple_set_signing(transport, session_key, *nt_response); - cli_session_set_user_session_key(session, &session_key); + smbcli_session_set_user_session_key(session, &session_key); data_blob_free(&session_key); } @@ -270,7 +270,7 @@ static void use_nt1_session_keys(struct cli_session *session, Perform a session setup (sync interface) using generic interface and the old style sesssetup call ****************************************************************************/ -static NTSTATUS smb_raw_session_setup_generic_old(struct cli_session *session, +static NTSTATUS smb_raw_session_setup_generic_old(struct smbcli_session *session, TALLOC_CTX *mem_ctx, union smb_sesssetup *parms) { @@ -319,7 +319,7 @@ static NTSTATUS smb_raw_session_setup_generic_old(struct cli_session *session, Perform a session setup (sync interface) using generic interface and the NT1 style sesssetup call ****************************************************************************/ -static NTSTATUS smb_raw_session_setup_generic_nt1(struct cli_session *session, +static NTSTATUS smb_raw_session_setup_generic_nt1(struct smbcli_session *session, TALLOC_CTX *mem_ctx, union smb_sesssetup *parms) { @@ -375,7 +375,7 @@ static NTSTATUS smb_raw_session_setup_generic_nt1(struct cli_session *session, Perform a session setup (sync interface) using generic interface and the SPNEGO style sesssetup call ****************************************************************************/ -static NTSTATUS smb_raw_session_setup_generic_spnego(struct cli_session *session, +static NTSTATUS smb_raw_session_setup_generic_spnego(struct smbcli_session *session, TALLOC_CTX *mem_ctx, union smb_sesssetup *parms) { @@ -396,7 +396,7 @@ static NTSTATUS smb_raw_session_setup_generic_spnego(struct cli_session *session s2.spnego.in.lanman = "Samba"; s2.spnego.out.vuid = UID_FIELD_INVALID; - cli_temp_set_signing(session->transport); + smbcli_temp_set_signing(session->transport); status = gensec_client_start(&session->gensec); if (!NT_STATUS_IS_OK(status)) { @@ -455,7 +455,7 @@ static NTSTATUS smb_raw_session_setup_generic_spnego(struct cli_session *session session_key_err = gensec_session_key(session->gensec, &session_key); } if (NT_STATUS_IS_OK(session_key_err)) { - cli_transport_simple_set_signing(session->transport, session_key, null_data_blob); + smbcli_transport_simple_set_signing(session->transport, session_key, null_data_blob); } session->vuid = s2.spnego.out.vuid; @@ -479,7 +479,7 @@ done: return session_key_err; } - cli_session_set_user_session_key(session, &session_key); + smbcli_session_set_user_session_key(session, &session_key); parms->generic.out.vuid = s2.spnego.out.vuid; parms->generic.out.os = s2.spnego.out.os; @@ -496,7 +496,7 @@ done: /**************************************************************************** Perform a session setup (sync interface) using generic interface ****************************************************************************/ -static NTSTATUS smb_raw_session_setup_generic(struct cli_session *session, +static NTSTATUS smb_raw_session_setup_generic(struct smbcli_session *session, TALLOC_CTX *mem_ctx, union smb_sesssetup *parms) { @@ -527,10 +527,10 @@ static NTSTATUS smb_raw_session_setup_generic(struct cli_session *session, this interface allows for RAW_SESSSETUP_GENERIC to auto-select session setup variant based on negotiated protocol options ****************************************************************************/ -NTSTATUS smb_raw_session_setup(struct cli_session *session, TALLOC_CTX *mem_ctx, +NTSTATUS smb_raw_session_setup(struct smbcli_session *session, TALLOC_CTX *mem_ctx, union smb_sesssetup *parms) { - struct cli_request *req; + struct smbcli_request *req; if (parms->generic.level == RAW_SESSSETUP_GENERIC) { NTSTATUS ret = smb_raw_session_setup_generic(session, mem_ctx, parms); @@ -555,17 +555,17 @@ NTSTATUS smb_raw_session_setup(struct cli_session *session, TALLOC_CTX *mem_ctx, /**************************************************************************** Send a uloggoff (async send) *****************************************************************************/ -struct cli_request *smb_raw_ulogoff_send(struct cli_session *session) +struct smbcli_request *smb_raw_ulogoff_send(struct smbcli_session *session) { - struct cli_request *req; + struct smbcli_request *req; SETUP_REQUEST_SESSION(SMBulogoffX, 2, 0); SSVAL(req->out.vwv, VWV(0), SMB_CHAIN_NONE); SSVAL(req->out.vwv, VWV(1), 0); - if (!cli_request_send(req)) { - cli_request_destroy(req); + if (!smbcli_request_send(req)) { + smbcli_request_destroy(req); return NULL; } @@ -575,24 +575,24 @@ struct cli_request *smb_raw_ulogoff_send(struct cli_session *session) /**************************************************************************** Send a uloggoff (sync interface) *****************************************************************************/ -NTSTATUS smb_raw_ulogoff(struct cli_session *session) +NTSTATUS smb_raw_ulogoff(struct smbcli_session *session) { - struct cli_request *req = smb_raw_ulogoff_send(session); - return cli_request_simple_recv(req); + struct smbcli_request *req = smb_raw_ulogoff_send(session); + return smbcli_request_simple_recv(req); } /**************************************************************************** Send a SMBexit ****************************************************************************/ -NTSTATUS smb_raw_exit(struct cli_session *session) +NTSTATUS smb_raw_exit(struct smbcli_session *session) { - struct cli_request *req; + struct smbcli_request *req; - req = cli_request_setup_session(session, SMBexit, 0, 0); + req = smbcli_request_setup_session(session, SMBexit, 0, 0); - if (cli_request_send(req)) { - cli_request_receive(req); + if (smbcli_request_send(req)) { + smbcli_request_receive(req); } - return cli_request_destroy(req); + return smbcli_request_destroy(req); } diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index eb5d3c0342..78d37b9be1 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -23,14 +23,14 @@ /* - create a cli_socket context + create a smbcli_socket context */ -struct cli_socket *cli_sock_init(void) +struct smbcli_socket *smbcli_sock_init(void) { - struct cli_socket *sock; + struct smbcli_socket *sock; TALLOC_CTX *mem_ctx; - mem_ctx = talloc_init("cli_socket"); + mem_ctx = talloc_init("smbcli_socket"); if (!mem_ctx) return NULL; sock = talloc_zero(mem_ctx, sizeof(*sock)); @@ -51,10 +51,10 @@ struct cli_socket *cli_sock_init(void) } /* - connect a cli_socket context to an IP/port pair + connect a smbcli_socket context to an IP/port pair if port is 0 then choose 445 then 139 */ -BOOL cli_sock_connect(struct cli_socket *sock, struct in_addr *ip, int port) +BOOL smbcli_sock_connect(struct smbcli_socket *sock, struct in_addr *ip, int port) { if (getenv("LIBSMB_PROG")) { sock->fd = sock_exec(getenv("LIBSMB_PROG")); @@ -62,8 +62,8 @@ BOOL cli_sock_connect(struct cli_socket *sock, struct in_addr *ip, int port) } if (port == 0) { - return cli_sock_connect(sock, ip, 445) || - cli_sock_connect(sock, ip, 139); + return smbcli_sock_connect(sock, ip, 445) || + smbcli_sock_connect(sock, ip, 139); } sock->dest_ip = *ip; @@ -85,7 +85,7 @@ BOOL cli_sock_connect(struct cli_socket *sock, struct in_addr *ip, int port) /**************************************************************************** mark the socket as dead ****************************************************************************/ -void cli_sock_dead(struct cli_socket *sock) +void smbcli_sock_dead(struct smbcli_socket *sock) { if (sock->fd != -1) { close(sock->fd); @@ -96,18 +96,18 @@ void cli_sock_dead(struct cli_socket *sock) /**************************************************************************** reduce socket reference count - if it becomes zero then close ****************************************************************************/ -void cli_sock_close(struct cli_socket *sock) +void smbcli_sock_close(struct smbcli_socket *sock) { sock->reference_count--; if (sock->reference_count <= 0) { - cli_sock_dead(sock); + smbcli_sock_dead(sock); } } /**************************************************************************** Set socket options on a open connection. ****************************************************************************/ -void cli_sock_set_options(struct cli_socket *sock, const char *options) +void smbcli_sock_set_options(struct smbcli_socket *sock, const char *options) { set_socket_options(sock->fd, options); } @@ -115,7 +115,7 @@ void cli_sock_set_options(struct cli_socket *sock, const char *options) /**************************************************************************** Write to socket. Return amount written. ****************************************************************************/ -ssize_t cli_sock_write(struct cli_socket *sock, const char *data, size_t len) +ssize_t smbcli_sock_write(struct smbcli_socket *sock, const char *data, size_t len) { if (sock->fd == -1) { errno = EIO; @@ -129,7 +129,7 @@ ssize_t cli_sock_write(struct cli_socket *sock, const char *data, size_t len) /**************************************************************************** Read from socket. return amount read ****************************************************************************/ -ssize_t cli_sock_read(struct cli_socket *sock, char *data, size_t len) +ssize_t smbcli_sock_read(struct smbcli_socket *sock, char *data, size_t len) { if (sock->fd == -1) { errno = EIO; @@ -142,7 +142,7 @@ ssize_t cli_sock_read(struct cli_socket *sock, char *data, size_t len) /**************************************************************************** resolve a hostname and connect ****************************************************************************/ -BOOL cli_sock_connect_byname(struct cli_socket *sock, const char *host, int port) +BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, int port) { int name_type = 0x20; struct in_addr ip; @@ -155,7 +155,7 @@ BOOL cli_sock_connect_byname(struct cli_socket *sock, const char *host, int port return sock->fd != -1; } - mem_ctx = talloc_init("cli_sock_connect_byname"); + mem_ctx = talloc_init("smbcli_sock_connect_byname"); if (!mem_ctx) return False; name = talloc_strdup(mem_ctx, host); @@ -171,7 +171,7 @@ BOOL cli_sock_connect_byname(struct cli_socket *sock, const char *host, int port return False; } - ret = cli_sock_connect(sock, &ip, port); + ret = smbcli_sock_connect(sock, &ip, port); if (ret) { sock->hostname = talloc_steal(mem_ctx, sock->mem_ctx, name); diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 3b3c10ed01..5290dd953d 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -24,24 +24,24 @@ /* an event has happened on the socket */ -static void cli_transport_event_handler(struct event_context *ev, struct fd_event *fde, +static void smbcli_transport_event_handler(struct event_context *ev, struct fd_event *fde, time_t t, uint16_t flags) { - struct cli_transport *transport = fde->private; + struct smbcli_transport *transport = fde->private; - cli_transport_process(transport); + smbcli_transport_process(transport); } /* create a transport structure based on an established socket */ -struct cli_transport *cli_transport_init(struct cli_socket *sock) +struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock) { TALLOC_CTX *mem_ctx; - struct cli_transport *transport; + struct smbcli_transport *transport; struct fd_event fde; - mem_ctx = talloc_init("cli_transport"); + mem_ctx = talloc_init("smbcli_transport"); if (!mem_ctx) return NULL; transport = talloc_zero(mem_ctx, sizeof(*transport)); @@ -59,7 +59,7 @@ struct cli_transport *cli_transport_init(struct cli_socket *sock) transport->options.use_spnego = lp_use_spnego(); transport->negotiate.max_xmit = ~0; - cli_init_signing(transport); + smbcli_init_signing(transport); transport->socket->reference_count++; @@ -67,7 +67,7 @@ struct cli_transport *cli_transport_init(struct cli_socket *sock) fde.fd = sock->fd; fde.flags = EVENT_FD_READ; - fde.handler = cli_transport_event_handler; + fde.handler = smbcli_transport_event_handler; fde.private = transport; fde.ref_count = 1; @@ -80,11 +80,11 @@ struct cli_transport *cli_transport_init(struct cli_socket *sock) decrease reference count on a transport, and destroy if it becomes zero */ -void cli_transport_close(struct cli_transport *transport) +void smbcli_transport_close(struct smbcli_transport *transport) { transport->reference_count--; if (transport->reference_count <= 0) { - cli_sock_close(transport->socket); + smbcli_sock_close(transport->socket); event_remove_fd(transport->event.ctx, transport->event.fde); event_remove_timed(transport->event.ctx, transport->event.te); event_context_destroy(transport->event.ctx); @@ -95,14 +95,14 @@ void cli_transport_close(struct cli_transport *transport) /* mark the transport as dead */ -void cli_transport_dead(struct cli_transport *transport) +void smbcli_transport_dead(struct smbcli_transport *transport) { - cli_sock_dead(transport->socket); + smbcli_sock_dead(transport->socket); /* all pending sends become errors */ while (transport->pending_send) { - struct cli_request *req = transport->pending_send; - req->state = CLI_REQUEST_ERROR; + struct smbcli_request *req = transport->pending_send; + req->state = SMBCLI_REQUEST_ERROR; req->status = NT_STATUS_NET_WRITE_FAULT; DLIST_REMOVE(transport->pending_send, req); if (req->async.fn) { @@ -112,8 +112,8 @@ void cli_transport_dead(struct cli_transport *transport) /* as do all pending receives */ while (transport->pending_recv) { - struct cli_request *req = transport->pending_recv; - req->state = CLI_REQUEST_ERROR; + struct smbcli_request *req = transport->pending_recv; + req->state = SMBCLI_REQUEST_ERROR; req->status = NT_STATUS_NET_WRITE_FAULT; DLIST_REMOVE(transport->pending_recv, req); if (req->async.fn) { @@ -126,7 +126,7 @@ void cli_transport_dead(struct cli_transport *transport) /* enable select for write on a transport */ -static void cli_transport_write_enable(struct cli_transport *transport) +static void smbcli_transport_write_enable(struct smbcli_transport *transport) { transport->event.fde->flags |= EVENT_FD_WRITE; } @@ -134,7 +134,7 @@ static void cli_transport_write_enable(struct cli_transport *transport) /* disable select for write on a transport */ -static void cli_transport_write_disable(struct cli_transport *transport) +static void smbcli_transport_write_disable(struct smbcli_transport *transport) { transport->event.fde->flags &= ~EVENT_FD_WRITE; } @@ -142,13 +142,13 @@ static void cli_transport_write_disable(struct cli_transport *transport) /**************************************************************************** send a session request (if appropriate) ****************************************************************************/ -BOOL cli_transport_connect(struct cli_transport *transport, +BOOL smbcli_transport_connect(struct smbcli_transport *transport, struct nmb_name *calling, struct nmb_name *called) { char *p; int len = NBT_HDR_SIZE; - struct cli_request *req; + struct smbcli_request *req; if (called) { transport->called = *called; @@ -160,7 +160,7 @@ BOOL cli_transport_connect(struct cli_transport *transport, } /* allocate output buffer */ - req = cli_request_setup_nonsmb(transport, NBT_HDR_SIZE + 2*nbt_mangled_name_len()); + req = smbcli_request_setup_nonsmb(transport, NBT_HDR_SIZE + 2*nbt_mangled_name_len()); /* put in the destination name */ p = req->out.buffer + NBT_HDR_SIZE; @@ -175,20 +175,20 @@ BOOL cli_transport_connect(struct cli_transport *transport, _smb_setlen(req->out.buffer,len-4); SCVAL(req->out.buffer,0,0x81); - if (!cli_request_send(req) || - !cli_request_receive(req)) { - cli_request_destroy(req); + if (!smbcli_request_send(req) || + !smbcli_request_receive(req)) { + smbcli_request_destroy(req); return False; } if (CVAL(req->in.buffer,0) != 0x82) { transport->error.etype = ETYPE_NBT; transport->error.e.nbt_error = CVAL(req->in.buffer,4); - cli_request_destroy(req); + smbcli_request_destroy(req); return False; } - cli_request_destroy(req); + smbcli_request_destroy(req); return True; } @@ -196,10 +196,10 @@ BOOL cli_transport_connect(struct cli_transport *transport, /**************************************************************************** get next mid in sequence ****************************************************************************/ -uint16_t cli_transport_next_mid(struct cli_transport *transport) +uint16_t smbcli_transport_next_mid(struct smbcli_transport *transport) { uint16_t mid; - struct cli_request *req; + struct smbcli_request *req; mid = transport->next_mid; @@ -225,7 +225,7 @@ again: static void idle_handler(struct event_context *ev, struct timed_event *te, time_t t) { - struct cli_transport *transport = te->private; + struct smbcli_transport *transport = te->private; te->next_event = t + transport->idle.period; transport->idle.func(transport, transport->idle.private); } @@ -234,8 +234,8 @@ static void idle_handler(struct event_context *ev, setup the idle handler for a transport the period is in seconds */ -void cli_transport_idle_handler(struct cli_transport *transport, - void (*idle_func)(struct cli_transport *, void *), +void smbcli_transport_idle_handler(struct smbcli_transport *transport, + void (*idle_func)(struct smbcli_transport *, void *), uint_t period, void *private) { @@ -257,27 +257,27 @@ void cli_transport_idle_handler(struct cli_transport *transport, /* process some pending sends */ -static void cli_transport_process_send(struct cli_transport *transport) +static void smbcli_transport_process_send(struct smbcli_transport *transport) { while (transport->pending_send) { - struct cli_request *req = transport->pending_send; + struct smbcli_request *req = transport->pending_send; ssize_t ret; - ret = cli_sock_write(transport->socket, req->out.buffer, req->out.size); + ret = smbcli_sock_write(transport->socket, req->out.buffer, req->out.size); if (ret == -1) { if (errno == EAGAIN || errno == EINTR) { return; } - cli_transport_dead(transport); + smbcli_transport_dead(transport); } req->out.buffer += ret; req->out.size -= ret; if (req->out.size == 0) { DLIST_REMOVE(transport->pending_send, req); if (req->one_way_request) { - req->state = CLI_REQUEST_DONE; - cli_request_destroy(req); + req->state = SMBCLI_REQUEST_DONE; + smbcli_request_destroy(req); } else { - req->state = CLI_REQUEST_RECV; + req->state = SMBCLI_REQUEST_RECV; DLIST_ADD(transport->pending_recv, req); } } @@ -285,19 +285,19 @@ static void cli_transport_process_send(struct cli_transport *transport) /* we're out of requests to send, so don't wait for write events any more */ - cli_transport_write_disable(transport); + smbcli_transport_write_disable(transport); } /* we have a full request in our receive buffer - match it to a pending request and process */ -static void cli_transport_finish_recv(struct cli_transport *transport) +static void smbcli_transport_finish_recv(struct smbcli_transport *transport) { uint8_t *buffer, *hdr, *vwv; int len; uint16_t wct, mid = 0; - struct cli_request *req; + struct smbcli_request *req; buffer = transport->recv_buffer.buffer; len = transport->recv_buffer.req_size; @@ -355,14 +355,14 @@ static void cli_transport_finish_recv(struct cli_transport *transport) /* handle non-SMB replies */ if (req->in.size < NBT_HDR_SIZE + MIN_SMB_SIZE) { - req->state = CLI_REQUEST_ERROR; + req->state = SMBCLI_REQUEST_ERROR; goto error; } if (req->in.size < NBT_HDR_SIZE + MIN_SMB_SIZE + VWV(wct)) { DEBUG(2,("bad reply size for mid %d\n", mid)); req->status = NT_STATUS_UNSUCCESSFUL; - req->state = CLI_REQUEST_ERROR; + req->state = SMBCLI_REQUEST_ERROR; goto error; } @@ -394,10 +394,10 @@ static void cli_transport_finish_recv(struct cli_transport *transport) req->status = transport->error.e.nt_status; } - if (!cli_request_check_sign_mac(req)) { + if (!smbcli_request_check_sign_mac(req)) { transport->error.etype = ETYPE_SOCKET; transport->error.e.socket_error = SOCKET_READ_BAD_SIG; - req->state = CLI_REQUEST_ERROR; + req->state = SMBCLI_REQUEST_ERROR; goto error; }; @@ -406,7 +406,7 @@ async: notify that the reply has been received. This might destroy the request so it must happen last */ DLIST_REMOVE(transport->pending_recv, req); - req->state = CLI_REQUEST_DONE; + req->state = SMBCLI_REQUEST_DONE; if (req->async.fn) { req->async.fn(req); } @@ -415,21 +415,21 @@ async: error: if (req) { DLIST_REMOVE(transport->pending_recv, req); - req->state = CLI_REQUEST_ERROR; + req->state = SMBCLI_REQUEST_ERROR; } } /* process some pending receives */ -static void cli_transport_process_recv(struct cli_transport *transport) +static void smbcli_transport_process_recv(struct smbcli_transport *transport) { /* a incoming packet goes through 2 stages - first we read the 4 byte header, which tells us how much more is coming. Then we read the rest */ if (transport->recv_buffer.received < NBT_HDR_SIZE) { ssize_t ret; - ret = cli_sock_read(transport->socket, + ret = smbcli_sock_read(transport->socket, transport->recv_buffer.header + transport->recv_buffer.received, NBT_HDR_SIZE - transport->recv_buffer.received); @@ -437,7 +437,7 @@ static void cli_transport_process_recv(struct cli_transport *transport) if (errno == EINTR || errno == EAGAIN) { return; } - cli_transport_dead(transport); + smbcli_transport_dead(transport); return; } @@ -449,7 +449,7 @@ static void cli_transport_process_recv(struct cli_transport *transport) transport->recv_buffer.buffer = talloc(transport->mem_ctx, NBT_HDR_SIZE+transport->recv_buffer.req_size); if (transport->recv_buffer.buffer == NULL) { - cli_transport_dead(transport); + smbcli_transport_dead(transport); return; } memcpy(transport->recv_buffer.buffer, transport->recv_buffer.header, NBT_HDR_SIZE); @@ -458,7 +458,7 @@ static void cli_transport_process_recv(struct cli_transport *transport) if (transport->recv_buffer.received < transport->recv_buffer.req_size) { ssize_t ret; - ret = cli_sock_read(transport->socket, + ret = smbcli_sock_read(transport->socket, transport->recv_buffer.buffer + transport->recv_buffer.received, transport->recv_buffer.req_size - @@ -467,7 +467,7 @@ static void cli_transport_process_recv(struct cli_transport *transport) if (errno == EINTR || errno == EAGAIN) { return; } - cli_transport_dead(transport); + smbcli_transport_dead(transport); return; } transport->recv_buffer.received += ret; @@ -475,7 +475,7 @@ static void cli_transport_process_recv(struct cli_transport *transport) if (transport->recv_buffer.received != 0 && transport->recv_buffer.received == transport->recv_buffer.req_size) { - cli_transport_finish_recv(transport); + smbcli_transport_finish_recv(transport); } } @@ -483,10 +483,10 @@ static void cli_transport_process_recv(struct cli_transport *transport) process some read/write requests that are pending return False if the socket is dead */ -BOOL cli_transport_process(struct cli_transport *transport) +BOOL smbcli_transport_process(struct smbcli_transport *transport) { - cli_transport_process_send(transport); - cli_transport_process_recv(transport); + smbcli_transport_process_send(transport); + smbcli_transport_process_recv(transport); if (transport->socket->fd == -1) { return False; } @@ -498,19 +498,19 @@ BOOL cli_transport_process(struct cli_transport *transport) /* put a request into the send queue */ -void cli_transport_send(struct cli_request *req) +void smbcli_transport_send(struct smbcli_request *req) { /* check if the transport is dead */ if (req->transport->socket->fd == -1) { - req->state = CLI_REQUEST_ERROR; + req->state = SMBCLI_REQUEST_ERROR; req->status = NT_STATUS_NET_WRITE_FAULT; return; } /* put it on the outgoing socket queue */ - req->state = CLI_REQUEST_SEND; - DLIST_ADD_END(req->transport->pending_send, req, struct cli_request *); + req->state = SMBCLI_REQUEST_SEND; + DLIST_ADD_END(req->transport->pending_send, req, struct smbcli_request *); /* make sure we look for write events */ - cli_transport_write_enable(req->transport); + smbcli_transport_write_enable(req->transport); } diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index a580ded010..b9d572fd56 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -22,7 +22,7 @@ #include "includes.h" #define SETUP_REQUEST_TREE(cmd, wct, buflen) do { \ - req = cli_request_setup(tree, cmd, wct, buflen); \ + req = smbcli_request_setup(tree, cmd, wct, buflen); \ if (!req) return NULL; \ } while (0) @@ -30,10 +30,10 @@ /**************************************************************************** Initialize the tree context ****************************************************************************/ -struct cli_tree *cli_tree_init(struct cli_session *session) +struct smbcli_tree *smbcli_tree_init(struct smbcli_session *session) { - struct cli_tree *tree; - TALLOC_CTX *mem_ctx = talloc_init("cli_tree"); + struct smbcli_tree *tree; + TALLOC_CTX *mem_ctx = talloc_init("smbcli_tree"); if (mem_ctx == NULL) { return NULL; } @@ -54,12 +54,12 @@ struct cli_tree *cli_tree_init(struct cli_session *session) /**************************************************************************** reduce reference count on a tree and destroy if <= 0 ****************************************************************************/ -void cli_tree_close(struct cli_tree *tree) +void smbcli_tree_close(struct smbcli_tree *tree) { if (!tree) return; tree->reference_count--; if (tree->reference_count <= 0) { - cli_session_close(tree->session); + smbcli_session_close(tree->session); talloc_destroy(tree->mem_ctx); } } @@ -68,16 +68,16 @@ void cli_tree_close(struct cli_tree *tree) /**************************************************************************** Send a tconX (async send) ****************************************************************************/ -struct cli_request *smb_tree_connect_send(struct cli_tree *tree, union smb_tcon *parms) +struct smbcli_request *smb_tree_connect_send(struct smbcli_tree *tree, union smb_tcon *parms) { - struct cli_request *req; + struct smbcli_request *req; switch (parms->tcon.level) { case RAW_TCON_TCON: SETUP_REQUEST_TREE(SMBtcon, 0, 0); - cli_req_append_ascii4(req, parms->tcon.in.service, STR_ASCII); - cli_req_append_ascii4(req, parms->tcon.in.password,STR_ASCII); - cli_req_append_ascii4(req, parms->tcon.in.dev, STR_ASCII); + smbcli_req_append_ascii4(req, parms->tcon.in.service, STR_ASCII); + smbcli_req_append_ascii4(req, parms->tcon.in.password,STR_ASCII); + smbcli_req_append_ascii4(req, parms->tcon.in.dev, STR_ASCII); break; case RAW_TCON_TCONX: @@ -86,14 +86,14 @@ struct cli_request *smb_tree_connect_send(struct cli_tree *tree, union smb_tcon SSVAL(req->out.vwv, VWV(1), 0); SSVAL(req->out.vwv, VWV(2), parms->tconx.in.flags); SSVAL(req->out.vwv, VWV(3), parms->tconx.in.password.length); - cli_req_append_blob(req, &parms->tconx.in.password); - cli_req_append_string(req, parms->tconx.in.path, STR_TERMINATE | STR_UPPER); - cli_req_append_string(req, parms->tconx.in.device, STR_TERMINATE | STR_ASCII); + smbcli_req_append_blob(req, &parms->tconx.in.password); + smbcli_req_append_string(req, parms->tconx.in.path, STR_TERMINATE | STR_UPPER); + smbcli_req_append_string(req, parms->tconx.in.device, STR_TERMINATE | STR_ASCII); break; } - if (!cli_request_send(req)) { - cli_request_destroy(req); + if (!smbcli_request_send(req)) { + smbcli_request_destroy(req); return NULL; } @@ -103,18 +103,18 @@ struct cli_request *smb_tree_connect_send(struct cli_tree *tree, union smb_tcon /**************************************************************************** Send a tconX (async recv) ****************************************************************************/ -NTSTATUS smb_tree_connect_recv(struct cli_request *req, TALLOC_CTX *mem_ctx, union smb_tcon *parms) +NTSTATUS smb_tree_connect_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, union smb_tcon *parms) { char *p; - if (!cli_request_receive(req) || - cli_request_is_error(req)) { + if (!smbcli_request_receive(req) || + smbcli_request_is_error(req)) { goto failed; } switch (parms->tcon.level) { case RAW_TCON_TCON: - CLI_CHECK_WCT(req, 2); + SMBCLI_CHECK_WCT(req, 2); parms->tcon.out.max_xmit = SVAL(req->in.vwv, VWV(0)); parms->tcon.out.cnum = SVAL(req->in.vwv, VWV(1)); break; @@ -130,23 +130,23 @@ NTSTATUS smb_tree_connect_recv(struct cli_request *req, TALLOC_CTX *mem_ctx, uni p = req->in.data; if (!p) break; - p += cli_req_pull_string(req, mem_ctx, &parms->tconx.out.dev_type, + p += smbcli_req_pull_string(req, mem_ctx, &parms->tconx.out.dev_type, p, -1, STR_ASCII | STR_TERMINATE); - p += cli_req_pull_string(req, mem_ctx, &parms->tconx.out.fs_type, + p += smbcli_req_pull_string(req, mem_ctx, &parms->tconx.out.fs_type, p, -1, STR_TERMINATE); break; } failed: - return cli_request_destroy(req); + return smbcli_request_destroy(req); } /**************************************************************************** Send a tconX (sync interface) ****************************************************************************/ -NTSTATUS smb_tree_connect(struct cli_tree *tree, TALLOC_CTX *mem_ctx, union smb_tcon *parms) +NTSTATUS smb_tree_connect(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_tcon *parms) { - struct cli_request *req = smb_tree_connect_send(tree, parms); + struct smbcli_request *req = smb_tree_connect_send(tree, parms); return smb_tree_connect_recv(req, mem_ctx, parms); } @@ -154,35 +154,35 @@ NTSTATUS smb_tree_connect(struct cli_tree *tree, TALLOC_CTX *mem_ctx, union smb_ /**************************************************************************** Send a tree disconnect. ****************************************************************************/ -NTSTATUS smb_tree_disconnect(struct cli_tree *tree) +NTSTATUS smb_tree_disconnect(struct smbcli_tree *tree) { - struct cli_request *req; + struct smbcli_request *req; if (!tree) return NT_STATUS_OK; - req = cli_request_setup(tree, SMBtdis, 0, 0); + req = smbcli_request_setup(tree, SMBtdis, 0, 0); - if (cli_request_send(req)) { - cli_request_receive(req); + if (smbcli_request_send(req)) { + smbcli_request_receive(req); } - return cli_request_destroy(req); + return smbcli_request_destroy(req); } /* - a convenient function to establish a cli_tree from scratch, using reasonable default + a convenient function to establish a smbcli_tree from scratch, using reasonable default parameters */ -NTSTATUS cli_tree_full_connection(struct cli_tree **ret_tree, +NTSTATUS smbcli_tree_full_connection(struct smbcli_tree **ret_tree, const char *my_name, const char *dest_host, int port, const char *service, const char *service_type, const char *user, const char *domain, const char *password) { - struct cli_socket *sock; - struct cli_transport *transport; - struct cli_session *session; - struct cli_tree *tree; + struct smbcli_socket *sock; + struct smbcli_transport *transport; + struct smbcli_session *session; + struct smbcli_tree *tree; NTSTATUS status; struct nmb_name calling; struct nmb_name called; @@ -193,20 +193,20 @@ NTSTATUS cli_tree_full_connection(struct cli_tree **ret_tree, *ret_tree = NULL; - sock = cli_sock_init(); + sock = smbcli_sock_init(); if (!sock) { return NT_STATUS_NO_MEMORY; } /* open a TCP socket to the server */ - if (!cli_sock_connect_byname(sock, dest_host, port)) { + if (!smbcli_sock_connect_byname(sock, dest_host, port)) { DEBUG(2,("Failed to establish socket connection - %s\n", strerror(errno))); return NT_STATUS_UNSUCCESSFUL; } - transport = cli_transport_init(sock); + transport = smbcli_transport_init(sock); if (!transport) { - cli_sock_close(sock); + smbcli_sock_close(sock); return NT_STATUS_NO_MEMORY; } @@ -214,8 +214,8 @@ NTSTATUS cli_tree_full_connection(struct cli_tree **ret_tree, make_nmb_name(&calling, my_name, 0x0); make_nmb_name(&called, dest_host, 0x20); - if (!cli_transport_connect(transport, &calling, &called)) { - cli_transport_close(transport); + if (!smbcli_transport_connect(transport, &calling, &called)) { + smbcli_transport_close(transport); return NT_STATUS_UNSUCCESSFUL; } @@ -223,13 +223,13 @@ NTSTATUS cli_tree_full_connection(struct cli_tree **ret_tree, /* negotiate protocol options with the server */ status = smb_raw_negotiate(transport); if (!NT_STATUS_IS_OK(status)) { - cli_transport_close(transport); + smbcli_transport_close(transport); return status; } - session = cli_session_init(transport); + session = smbcli_session_init(transport); if (!session) { - cli_transport_close(transport); + smbcli_transport_close(transport); return NT_STATUS_NO_MEMORY; } @@ -255,16 +255,16 @@ NTSTATUS cli_tree_full_connection(struct cli_tree **ret_tree, status = smb_raw_session_setup(session, mem_ctx, &setup); if (!NT_STATUS_IS_OK(status)) { - cli_session_close(session); + smbcli_session_close(session); talloc_destroy(mem_ctx); return status; } session->vuid = setup.generic.out.vuid; - tree = cli_tree_init(session); + tree = smbcli_tree_init(session); if (!tree) { - cli_session_close(session); + smbcli_session_close(session); talloc_destroy(mem_ctx); return NT_STATUS_NO_MEMORY; } @@ -288,7 +288,7 @@ NTSTATUS cli_tree_full_connection(struct cli_tree **ret_tree, SAFE_FREE(in_path); if (!NT_STATUS_IS_OK(status)) { - cli_tree_close(tree); + smbcli_tree_close(tree); talloc_destroy(mem_ctx); return status; } diff --git a/source4/libcli/raw/rawacl.c b/source4/libcli/raw/rawacl.c index ca93591597..77374ae8b9 100644 --- a/source4/libcli/raw/rawacl.c +++ b/source4/libcli/raw/rawacl.c @@ -23,7 +23,7 @@ /**************************************************************************** fetch file ACL (async send) ****************************************************************************/ -struct cli_request *smb_raw_query_secdesc_send(struct cli_tree *tree, +struct smbcli_request *smb_raw_query_secdesc_send(struct smbcli_tree *tree, struct smb_query_secdesc *query) { struct smb_nttrans nt; @@ -52,7 +52,7 @@ struct cli_request *smb_raw_query_secdesc_send(struct cli_tree *tree, /**************************************************************************** fetch file ACL (async recv) ****************************************************************************/ -NTSTATUS smb_raw_query_secdesc_recv(struct cli_request *req, +NTSTATUS smb_raw_query_secdesc_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, struct smb_query_secdesc *query) { @@ -91,11 +91,11 @@ NTSTATUS smb_raw_query_secdesc_recv(struct cli_request *req, /**************************************************************************** fetch file ACL (sync interface) ****************************************************************************/ -NTSTATUS smb_raw_query_secdesc(struct cli_tree *tree, +NTSTATUS smb_raw_query_secdesc(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, struct smb_query_secdesc *query) { - struct cli_request *req = smb_raw_query_secdesc_send(tree, query); + struct smbcli_request *req = smb_raw_query_secdesc_send(tree, query); return smb_raw_query_secdesc_recv(req, mem_ctx, query); } @@ -104,13 +104,13 @@ NTSTATUS smb_raw_query_secdesc(struct cli_tree *tree, /**************************************************************************** set file ACL (async send) ****************************************************************************/ -struct cli_request *smb_raw_set_secdesc_send(struct cli_tree *tree, +struct smbcli_request *smb_raw_set_secdesc_send(struct smbcli_tree *tree, struct smb_set_secdesc *set) { struct smb_nttrans nt; uint8_t params[8]; struct ndr_push *ndr; - struct cli_request *req; + struct smbcli_request *req; NTSTATUS status; nt.in.max_setup = 0; diff --git a/source4/libcli/raw/rawdate.c b/source4/libcli/raw/rawdate.c index 3b731d653b..bfb7465bd5 100644 --- a/source4/libcli/raw/rawdate.c +++ b/source4/libcli/raw/rawdate.c @@ -26,7 +26,7 @@ put a dos date into a buffer (time/date format) This takes GMT time and puts local time for zone_offset in the buffer ********************************************************************/ -void raw_push_dos_date(struct cli_transport *transport, +void raw_push_dos_date(struct smbcli_transport *transport, uint8_t *buf, int offset, time_t unixdate) { push_dos_date(buf, offset, unixdate, transport->negotiate.server_zone); @@ -36,7 +36,7 @@ void raw_push_dos_date(struct cli_transport *transport, put a dos date into a buffer (date/time format) This takes GMT time and puts local time in the buffer ********************************************************************/ -void raw_push_dos_date2(struct cli_transport *transport, +void raw_push_dos_date2(struct smbcli_transport *transport, char *buf, int offset, time_t unixdate) { push_dos_date2(buf, offset, unixdate, transport->negotiate.server_zone); @@ -46,7 +46,7 @@ void raw_push_dos_date2(struct cli_transport *transport, put a dos 32 bit "unix like" date into a buffer. This routine takes GMT and converts it to LOCAL time in zone_offset before putting it ********************************************************************/ -void raw_push_dos_date3(struct cli_transport *transport, +void raw_push_dos_date3(struct smbcli_transport *transport, char *buf, int offset, time_t unixdate) { push_dos_date3(buf, offset, unixdate, transport->negotiate.server_zone); @@ -55,7 +55,7 @@ void raw_push_dos_date3(struct cli_transport *transport, /******************************************************************* convert a dos date ********************************************************************/ -time_t raw_pull_dos_date(struct cli_transport *transport, +time_t raw_pull_dos_date(struct smbcli_transport *transport, const uint8_t *date_ptr) { return pull_dos_date(date_ptr, transport->negotiate.server_zone); @@ -64,7 +64,7 @@ time_t raw_pull_dos_date(struct cli_transport *transport, /******************************************************************* like raw_pull_dos_date() but the words are reversed ********************************************************************/ -time_t raw_pull_dos_date2(struct cli_transport *transport, +time_t raw_pull_dos_date2(struct smbcli_transport *transport, const uint8_t *date_ptr) { return pull_dos_date2(date_ptr, transport->negotiate.server_zone); @@ -74,7 +74,7 @@ time_t raw_pull_dos_date2(struct cli_transport *transport, create a unix GMT date from a dos date in 32 bit "unix like" format these arrive in server zone, with corresponding DST ******************************************************************/ -time_t raw_pull_dos_date3(struct cli_transport *transport, +time_t raw_pull_dos_date3(struct smbcli_transport *transport, const uint8_t *date_ptr) { return pull_dos_date3(date_ptr, transport->negotiate.server_zone); diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c index 0d00ffcca6..8bd8e5d8af 100644 --- a/source4/libcli/raw/rawfile.c +++ b/source4/libcli/raw/rawfile.c @@ -23,7 +23,7 @@ #include "includes.h" #define SETUP_REQUEST(cmd, wct, buflen) do { \ - req = cli_request_setup(tree, cmd, wct, buflen); \ + req = smbcli_request_setup(tree, cmd, wct, buflen); \ if (!req) return NULL; \ } while (0) @@ -31,17 +31,17 @@ /**************************************************************************** Rename a file - async interface ****************************************************************************/ -struct cli_request *smb_raw_rename_send(struct cli_tree *tree, +struct smbcli_request *smb_raw_rename_send(struct smbcli_tree *tree, union smb_rename *parms) { - struct cli_request *req; + struct smbcli_request *req; switch (parms->generic.level) { case RAW_RENAME_RENAME: SETUP_REQUEST(SMBmv, 1, 0); SSVAL(req->out.vwv, VWV(0), parms->rename.in.attrib); - cli_req_append_ascii4(req, parms->rename.in.pattern1, STR_TERMINATE); - cli_req_append_ascii4(req, parms->rename.in.pattern2, STR_TERMINATE); + smbcli_req_append_ascii4(req, parms->rename.in.pattern1, STR_TERMINATE); + smbcli_req_append_ascii4(req, parms->rename.in.pattern2, STR_TERMINATE); break; case RAW_RENAME_NTRENAME: @@ -49,13 +49,13 @@ struct cli_request *smb_raw_rename_send(struct cli_tree *tree, SSVAL(req->out.vwv, VWV(0), parms->ntrename.in.attrib); SSVAL(req->out.vwv, VWV(1), parms->ntrename.in.flags); SIVAL(req->out.vwv, VWV(2), parms->ntrename.in.cluster_size); - cli_req_append_ascii4(req, parms->ntrename.in.old_name, STR_TERMINATE); - cli_req_append_ascii4(req, parms->ntrename.in.new_name, STR_TERMINATE); + smbcli_req_append_ascii4(req, parms->ntrename.in.old_name, STR_TERMINATE); + smbcli_req_append_ascii4(req, parms->ntrename.in.new_name, STR_TERMINATE); break; } - if (!cli_request_send(req)) { - cli_request_destroy(req); + if (!smbcli_request_send(req)) { + smbcli_request_destroy(req); return NULL; } @@ -65,29 +65,29 @@ struct cli_request *smb_raw_rename_send(struct cli_tree *tree, /**************************************************************************** Rename a file - sync interface ****************************************************************************/ -NTSTATUS smb_raw_rename(struct cli_tree *tree, +NTSTATUS smb_raw_rename(struct smbcli_tree *tree, union smb_rename *parms) { - struct cli_request *req = smb_raw_rename_send(tree, parms); - return cli_request_simple_recv(req); + struct smbcli_request *req = smb_raw_rename_send(tree, parms); + return smbcli_request_simple_recv(req); } /**************************************************************************** Delete a file - async interface ****************************************************************************/ -struct cli_request *smb_raw_unlink_send(struct cli_tree *tree, +struct smbcli_request *smb_raw_unlink_send(struct smbcli_tree *tree, struct smb_unlink *parms) { - struct cli_request *req; + struct smbcli_request *req; SETUP_REQUEST(SMBunlink, 1, 0); SSVAL(req->out.vwv, VWV(0), parms->in.attrib); - cli_req_append_ascii4(req, parms->in.pattern, STR_TERMINATE); + smbcli_req_append_ascii4(req, parms->in.pattern, STR_TERMINATE); - if (!cli_request_send(req)) { - cli_request_destroy(req); + if (!smbcli_request_send(req)) { + smbcli_request_destroy(req); return NULL; } return req; @@ -96,24 +96,24 @@ struct cli_request *smb_raw_unlink_send(struct cli_tree *tree, /* delete a file - sync interface */ -NTSTATUS smb_raw_unlink(struct cli_tree *tree, +NTSTATUS smb_raw_unlink(struct smbcli_tree *tree, struct smb_unlink *parms) { - struct cli_request *req = smb_raw_unlink_send(tree, parms); - return cli_request_simple_recv(req); + struct smbcli_request *req = smb_raw_unlink_send(tree, parms); + return smbcli_request_simple_recv(req); } /**************************************************************************** create a directory using TRANSACT2_MKDIR - async interface ****************************************************************************/ -static struct cli_request *smb_raw_t2mkdir_send(struct cli_tree *tree, +static struct smbcli_request *smb_raw_t2mkdir_send(struct smbcli_tree *tree, union smb_mkdir *parms) { struct smb_trans2 t2; uint16_t setup = TRANSACT2_MKDIR; TALLOC_CTX *mem_ctx; - struct cli_request *req; + struct smbcli_request *req; uint16_t data_total; mem_ctx = talloc_init("t2mkdir"); @@ -132,7 +132,7 @@ static struct cli_request *smb_raw_t2mkdir_send(struct cli_tree *tree, SIVAL(t2.in.params.data, VWV(0), 0); /* reserved */ - cli_blob_append_string(tree->session, mem_ctx, + smbcli_blob_append_string(tree->session, mem_ctx, &t2.in.params, parms->t2mkdir.in.path, 0); ea_put_list(t2.in.data.data, parms->t2mkdir.in.num_eas, parms->t2mkdir.in.eas); @@ -147,10 +147,10 @@ static struct cli_request *smb_raw_t2mkdir_send(struct cli_tree *tree, /**************************************************************************** Create a directory - async interface ****************************************************************************/ -struct cli_request *smb_raw_mkdir_send(struct cli_tree *tree, +struct smbcli_request *smb_raw_mkdir_send(struct smbcli_tree *tree, union smb_mkdir *parms) { - struct cli_request *req; + struct smbcli_request *req; if (parms->generic.level == RAW_MKDIR_T2MKDIR) { return smb_raw_t2mkdir_send(tree, parms); @@ -162,9 +162,9 @@ struct cli_request *smb_raw_mkdir_send(struct cli_tree *tree, SETUP_REQUEST(SMBmkdir, 0, 0); - cli_req_append_ascii4(req, parms->mkdir.in.path, STR_TERMINATE); + smbcli_req_append_ascii4(req, parms->mkdir.in.path, STR_TERMINATE); - if (!cli_request_send(req)) { + if (!smbcli_request_send(req)) { return NULL; } @@ -174,27 +174,27 @@ struct cli_request *smb_raw_mkdir_send(struct cli_tree *tree, /**************************************************************************** Create a directory - sync interface ****************************************************************************/ -NTSTATUS smb_raw_mkdir(struct cli_tree *tree, +NTSTATUS smb_raw_mkdir(struct smbcli_tree *tree, union smb_mkdir *parms) { - struct cli_request *req = smb_raw_mkdir_send(tree, parms); - return cli_request_simple_recv(req); + struct smbcli_request *req = smb_raw_mkdir_send(tree, parms); + return smbcli_request_simple_recv(req); } /**************************************************************************** Remove a directory - async interface ****************************************************************************/ -struct cli_request *smb_raw_rmdir_send(struct cli_tree *tree, +struct smbcli_request *smb_raw_rmdir_send(struct smbcli_tree *tree, struct smb_rmdir *parms) { - struct cli_request *req; + struct smbcli_request *req; SETUP_REQUEST(SMBrmdir, 0, 0); - cli_req_append_ascii4(req, parms->in.path, STR_TERMINATE); + smbcli_req_append_ascii4(req, parms->in.path, STR_TERMINATE); - if (!cli_request_send(req)) { - cli_request_destroy(req); + if (!smbcli_request_send(req)) { + smbcli_request_destroy(req); return NULL; } @@ -204,24 +204,24 @@ struct cli_request *smb_raw_rmdir_send(struct cli_tree *tree, /**************************************************************************** Remove a directory - sync interface ****************************************************************************/ -NTSTATUS smb_raw_rmdir(struct cli_tree *tree, +NTSTATUS smb_raw_rmdir(struct smbcli_tree *tree, struct smb_rmdir *parms) { - struct cli_request *req = smb_raw_rmdir_send(tree, parms); - return cli_request_simple_recv(req); + struct smbcli_request *req = smb_raw_rmdir_send(tree, parms); + return smbcli_request_simple_recv(req); } /**************************************************************************** Open a file using TRANSACT2_OPEN - async send ****************************************************************************/ -static struct cli_request *smb_raw_t2open_send(struct cli_tree *tree, +static struct smbcli_request *smb_raw_t2open_send(struct smbcli_tree *tree, union smb_open *parms) { struct smb_trans2 t2; uint16_t setup = TRANSACT2_OPEN; TALLOC_CTX *mem_ctx = talloc_init("smb_raw_t2open"); - struct cli_request *req; + struct smbcli_request *req; uint16_t list_size; list_size = ea_list_size(parms->t2open.in.num_eas, parms->t2open.in.eas); @@ -248,7 +248,7 @@ static struct cli_request *smb_raw_t2open_send(struct cli_tree *tree, SIVAL(t2.in.params.data, VWV(11), 0); SSVAL(t2.in.params.data, VWV(13), 0); - cli_blob_append_string(tree->session, mem_ctx, + smbcli_blob_append_string(tree->session, mem_ctx, &t2.in.params, parms->t2open.in.fname, STR_TERMINATE); @@ -265,9 +265,9 @@ static struct cli_request *smb_raw_t2open_send(struct cli_tree *tree, /**************************************************************************** Open a file using TRANSACT2_OPEN - async recv ****************************************************************************/ -static NTSTATUS smb_raw_t2open_recv(struct cli_request *req, TALLOC_CTX *mem_ctx, union smb_open *parms) +static NTSTATUS smb_raw_t2open_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, union smb_open *parms) { - struct cli_transport *transport = req?req->transport:NULL; + struct smbcli_transport *transport = req?req->transport:NULL; struct smb_trans2 t2; NTSTATUS status; @@ -294,10 +294,10 @@ static NTSTATUS smb_raw_t2open_recv(struct cli_request *req, TALLOC_CTX *mem_ctx /**************************************************************************** Open a file - async send ****************************************************************************/ -struct cli_request *smb_raw_open_send(struct cli_tree *tree, union smb_open *parms) +struct smbcli_request *smb_raw_open_send(struct smbcli_tree *tree, union smb_open *parms) { int len; - struct cli_request *req = NULL; + struct smbcli_request *req = NULL; switch (parms->open.level) { case RAW_OPEN_T2OPEN: @@ -307,7 +307,7 @@ struct cli_request *smb_raw_open_send(struct cli_tree *tree, union smb_open *par SETUP_REQUEST(SMBopen, 2, 0); SSVAL(req->out.vwv, VWV(0), parms->open.in.flags); SSVAL(req->out.vwv, VWV(1), parms->open.in.search_attrs); - cli_req_append_ascii4(req, parms->open.in.fname, STR_TERMINATE); + smbcli_req_append_ascii4(req, parms->open.in.fname, STR_TERMINATE); break; case RAW_OPEN_OPENX: @@ -324,7 +324,7 @@ struct cli_request *smb_raw_open_send(struct cli_tree *tree, union smb_open *par SIVAL(req->out.vwv, VWV(9), parms->openx.in.size); SIVAL(req->out.vwv, VWV(11),parms->openx.in.timeout); SIVAL(req->out.vwv, VWV(13),0); /* reserved */ - cli_req_append_string(req, parms->openx.in.fname, STR_TERMINATE); + smbcli_req_append_string(req, parms->openx.in.fname, STR_TERMINATE); break; case RAW_OPEN_MKNEW: @@ -332,7 +332,7 @@ struct cli_request *smb_raw_open_send(struct cli_tree *tree, union smb_open *par SSVAL(req->out.vwv, VWV(0), parms->mknew.in.attrib); raw_push_dos_date3(tree->session->transport, req->out.vwv, VWV(1), parms->mknew.in.write_time); - cli_req_append_ascii4(req, parms->mknew.in.fname, STR_TERMINATE); + smbcli_req_append_ascii4(req, parms->mknew.in.fname, STR_TERMINATE); break; case RAW_OPEN_CREATE: @@ -340,7 +340,7 @@ struct cli_request *smb_raw_open_send(struct cli_tree *tree, union smb_open *par SSVAL(req->out.vwv, VWV(0), parms->create.in.attrib); raw_push_dos_date3(tree->session->transport, req->out.vwv, VWV(1), parms->create.in.write_time); - cli_req_append_ascii4(req, parms->create.in.fname, STR_TERMINATE); + smbcli_req_append_ascii4(req, parms->create.in.fname, STR_TERMINATE); break; case RAW_OPEN_CTEMP: @@ -348,7 +348,7 @@ struct cli_request *smb_raw_open_send(struct cli_tree *tree, union smb_open *par SSVAL(req->out.vwv, VWV(0), parms->ctemp.in.attrib); raw_push_dos_date3(tree->session->transport, req->out.vwv, VWV(1), parms->ctemp.in.write_time); - cli_req_append_ascii4(req, parms->ctemp.in.directory, STR_TERMINATE); + smbcli_req_append_ascii4(req, parms->ctemp.in.directory, STR_TERMINATE); break; case RAW_OPEN_SPLOPEN: @@ -373,13 +373,13 @@ struct cli_request *smb_raw_open_send(struct cli_tree *tree, union smb_open *par SIVAL(req->out.vwv, 43, parms->ntcreatex.in.impersonation); SCVAL(req->out.vwv, 47, parms->ntcreatex.in.security_flags); - cli_req_append_string_len(req, parms->ntcreatex.in.fname, STR_TERMINATE, &len); + smbcli_req_append_string_len(req, parms->ntcreatex.in.fname, STR_TERMINATE, &len); SSVAL(req->out.vwv, 5, len); break; } - if (!cli_request_send(req)) { - cli_request_destroy(req); + if (!smbcli_request_send(req)) { + smbcli_request_destroy(req); return NULL; } @@ -389,10 +389,10 @@ struct cli_request *smb_raw_open_send(struct cli_tree *tree, union smb_open *par /**************************************************************************** Open a file - async recv ****************************************************************************/ -NTSTATUS smb_raw_open_recv(struct cli_request *req, TALLOC_CTX *mem_ctx, union smb_open *parms) +NTSTATUS smb_raw_open_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, union smb_open *parms) { - if (!cli_request_receive(req) || - cli_request_is_error(req)) { + if (!smbcli_request_receive(req) || + smbcli_request_is_error(req)) { goto failed; } @@ -401,7 +401,7 @@ NTSTATUS smb_raw_open_recv(struct cli_request *req, TALLOC_CTX *mem_ctx, union s return smb_raw_t2open_recv(req, mem_ctx, parms); case RAW_OPEN_OPEN: - CLI_CHECK_WCT(req, 7); + SMBCLI_CHECK_WCT(req, 7); parms->open.out.fnum = SVAL(req->in.vwv, VWV(0)); parms->open.out.attrib = SVAL(req->in.vwv, VWV(1)); parms->open.out.write_time = raw_pull_dos_date3(req->transport, @@ -411,7 +411,7 @@ NTSTATUS smb_raw_open_recv(struct cli_request *req, TALLOC_CTX *mem_ctx, union s break; case RAW_OPEN_OPENX: - CLI_CHECK_MIN_WCT(req, 15); + SMBCLI_CHECK_MIN_WCT(req, 15); parms->openx.out.fnum = SVAL(req->in.vwv, VWV(2)); parms->openx.out.attrib = SVAL(req->in.vwv, VWV(3)); parms->openx.out.write_time = raw_pull_dos_date3(req->transport, @@ -432,35 +432,35 @@ NTSTATUS smb_raw_open_recv(struct cli_request *req, TALLOC_CTX *mem_ctx, union s break; case RAW_OPEN_MKNEW: - CLI_CHECK_WCT(req, 1); + SMBCLI_CHECK_WCT(req, 1); parms->mknew.out.fnum = SVAL(req->in.vwv, VWV(0)); break; case RAW_OPEN_CREATE: - CLI_CHECK_WCT(req, 1); + SMBCLI_CHECK_WCT(req, 1); parms->create.out.fnum = SVAL(req->in.vwv, VWV(0)); break; case RAW_OPEN_CTEMP: - CLI_CHECK_WCT(req, 1); + SMBCLI_CHECK_WCT(req, 1); parms->ctemp.out.fnum = SVAL(req->in.vwv, VWV(0)); - cli_req_pull_string(req, mem_ctx, &parms->ctemp.out.name, req->in.data, -1, STR_TERMINATE | STR_ASCII); + smbcli_req_pull_string(req, mem_ctx, &parms->ctemp.out.name, req->in.data, -1, STR_TERMINATE | STR_ASCII); break; case RAW_OPEN_SPLOPEN: - CLI_CHECK_WCT(req, 1); + SMBCLI_CHECK_WCT(req, 1); parms->splopen.out.fnum = SVAL(req->in.vwv, VWV(0)); break; case RAW_OPEN_NTCREATEX: - CLI_CHECK_MIN_WCT(req, 34); + SMBCLI_CHECK_MIN_WCT(req, 34); parms->ntcreatex.out.oplock_level = CVAL(req->in.vwv, 4); parms->ntcreatex.out.fnum = SVAL(req->in.vwv, 5); parms->ntcreatex.out.create_action = IVAL(req->in.vwv, 7); - parms->ntcreatex.out.create_time = cli_pull_nttime(req->in.vwv, 11); - parms->ntcreatex.out.access_time = cli_pull_nttime(req->in.vwv, 19); - parms->ntcreatex.out.write_time = cli_pull_nttime(req->in.vwv, 27); - parms->ntcreatex.out.change_time = cli_pull_nttime(req->in.vwv, 35); + parms->ntcreatex.out.create_time = smbcli_pull_nttime(req->in.vwv, 11); + parms->ntcreatex.out.access_time = smbcli_pull_nttime(req->in.vwv, 19); + parms->ntcreatex.out.write_time = smbcli_pull_nttime(req->in.vwv, 27); + parms->ntcreatex.out.change_time = smbcli_pull_nttime(req->in.vwv, 35); parms->ntcreatex.out.attrib = IVAL(req->in.vwv, 43); parms->ntcreatex.out.alloc_size = BVAL(req->in.vwv, 47); parms->ntcreatex.out.size = BVAL(req->in.vwv, 55); @@ -471,16 +471,16 @@ NTSTATUS smb_raw_open_recv(struct cli_request *req, TALLOC_CTX *mem_ctx, union s } failed: - return cli_request_destroy(req); + return smbcli_request_destroy(req); } /**************************************************************************** Open a file - sync interface ****************************************************************************/ -NTSTATUS smb_raw_open(struct cli_tree *tree, TALLOC_CTX *mem_ctx, union smb_open *parms) +NTSTATUS smb_raw_open(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_open *parms) { - struct cli_request *req = smb_raw_open_send(tree, parms); + struct smbcli_request *req = smb_raw_open_send(tree, parms); return smb_raw_open_recv(req, mem_ctx, parms); } @@ -488,9 +488,9 @@ NTSTATUS smb_raw_open(struct cli_tree *tree, TALLOC_CTX *mem_ctx, union smb_open /**************************************************************************** Close a file - async send ****************************************************************************/ -struct cli_request *smb_raw_close_send(struct cli_tree *tree, union smb_close *parms) +struct smbcli_request *smb_raw_close_send(struct smbcli_tree *tree, union smb_close *parms) { - struct cli_request *req; + struct smbcli_request *req; switch (parms->generic.level) { case RAW_CLOSE_GENERIC: @@ -512,8 +512,8 @@ struct cli_request *smb_raw_close_send(struct cli_tree *tree, union smb_close *p if (!req) return NULL; - if (!cli_request_send(req)) { - cli_request_destroy(req); + if (!smbcli_request_send(req)) { + smbcli_request_destroy(req); return NULL; } @@ -524,19 +524,19 @@ struct cli_request *smb_raw_close_send(struct cli_tree *tree, union smb_close *p /**************************************************************************** Close a file - sync interface ****************************************************************************/ -NTSTATUS smb_raw_close(struct cli_tree *tree, union smb_close *parms) +NTSTATUS smb_raw_close(struct smbcli_tree *tree, union smb_close *parms) { - struct cli_request *req = smb_raw_close_send(tree, parms); - return cli_request_simple_recv(req); + struct smbcli_request *req = smb_raw_close_send(tree, parms); + return smbcli_request_simple_recv(req); } /**************************************************************************** Locking calls - async interface ****************************************************************************/ -struct cli_request *smb_raw_lock_send(struct cli_tree *tree, union smb_lock *parms) +struct smbcli_request *smb_raw_lock_send(struct smbcli_tree *tree, union smb_lock *parms) { - struct cli_request *req; + struct smbcli_request *req; switch (parms->generic.level) { case RAW_LOCK_GENERIC: @@ -590,8 +590,8 @@ struct cli_request *smb_raw_lock_send(struct cli_tree *tree, union smb_lock *par } } - if (!cli_request_send(req)) { - cli_request_destroy(req); + if (!smbcli_request_send(req)) { + smbcli_request_destroy(req); return NULL; } @@ -601,26 +601,26 @@ struct cli_request *smb_raw_lock_send(struct cli_tree *tree, union smb_lock *par /**************************************************************************** Locking calls - sync interface ****************************************************************************/ -NTSTATUS smb_raw_lock(struct cli_tree *tree, union smb_lock *parms) +NTSTATUS smb_raw_lock(struct smbcli_tree *tree, union smb_lock *parms) { - struct cli_request *req = smb_raw_lock_send(tree, parms); - return cli_request_simple_recv(req); + struct smbcli_request *req = smb_raw_lock_send(tree, parms); + return smbcli_request_simple_recv(req); } /**************************************************************************** Check for existence of a dir - async send ****************************************************************************/ -struct cli_request *smb_raw_chkpath_send(struct cli_tree *tree, struct smb_chkpath *parms) +struct smbcli_request *smb_raw_chkpath_send(struct smbcli_tree *tree, struct smb_chkpath *parms) { - struct cli_request *req; + struct smbcli_request *req; SETUP_REQUEST(SMBchkpth, 0, 0); - cli_req_append_ascii4(req, parms->in.path, STR_TERMINATE); + smbcli_req_append_ascii4(req, parms->in.path, STR_TERMINATE); - if (!cli_request_send(req)) { - cli_request_destroy(req); + if (!smbcli_request_send(req)) { + smbcli_request_destroy(req); return NULL; } @@ -630,10 +630,10 @@ struct cli_request *smb_raw_chkpath_send(struct cli_tree *tree, struct smb_chkpa /**************************************************************************** Check for existence of a dir - sync interface ****************************************************************************/ -NTSTATUS smb_raw_chkpath(struct cli_tree *tree, struct smb_chkpath *parms) +NTSTATUS smb_raw_chkpath(struct smbcli_tree *tree, struct smb_chkpath *parms) { - struct cli_request *req = smb_raw_chkpath_send(tree, parms); - return cli_request_simple_recv(req); + struct smbcli_request *req = smb_raw_chkpath_send(tree, parms); + return smbcli_request_simple_recv(req); } @@ -643,15 +643,15 @@ NTSTATUS smb_raw_chkpath(struct cli_tree *tree, struct smb_chkpath *parms) flush a file - async send a flush to fnum 0xFFFF will flush all files ****************************************************************************/ -struct cli_request *smb_raw_flush_send(struct cli_tree *tree, struct smb_flush *parms) +struct smbcli_request *smb_raw_flush_send(struct smbcli_tree *tree, struct smb_flush *parms) { - struct cli_request *req; + struct smbcli_request *req; SETUP_REQUEST(SMBflush, 1, 0); SSVAL(req->out.vwv, VWV(0), parms->in.fnum); - if (!cli_request_send(req)) { - cli_request_destroy(req); + if (!smbcli_request_send(req)) { + smbcli_request_destroy(req); return NULL; } @@ -662,20 +662,20 @@ struct cli_request *smb_raw_flush_send(struct cli_tree *tree, struct smb_flush * /**************************************************************************** flush a file - sync interface ****************************************************************************/ -NTSTATUS smb_raw_flush(struct cli_tree *tree, struct smb_flush *parms) +NTSTATUS smb_raw_flush(struct smbcli_tree *tree, struct smb_flush *parms) { - struct cli_request *req = smb_raw_flush_send(tree, parms); - return cli_request_simple_recv(req); + struct smbcli_request *req = smb_raw_flush_send(tree, parms); + return smbcli_request_simple_recv(req); } /**************************************************************************** seek a file - async send ****************************************************************************/ -struct cli_request *smb_raw_seek_send(struct cli_tree *tree, +struct smbcli_request *smb_raw_seek_send(struct smbcli_tree *tree, struct smb_seek *parms) { - struct cli_request *req; + struct smbcli_request *req; SETUP_REQUEST(SMBlseek, 4, 0); @@ -683,8 +683,8 @@ struct cli_request *smb_raw_seek_send(struct cli_tree *tree, SSVAL(req->out.vwv, VWV(1), parms->in.mode); SIVALS(req->out.vwv, VWV(2), parms->in.offset); - if (!cli_request_send(req)) { - cli_request_destroy(req); + if (!smbcli_request_send(req)) { + smbcli_request_destroy(req); return NULL; } return req; @@ -693,27 +693,27 @@ struct cli_request *smb_raw_seek_send(struct cli_tree *tree, /**************************************************************************** seek a file - async receive ****************************************************************************/ -NTSTATUS smb_raw_seek_recv(struct cli_request *req, +NTSTATUS smb_raw_seek_recv(struct smbcli_request *req, struct smb_seek *parms) { - if (!cli_request_receive(req) || - cli_request_is_error(req)) { - return cli_request_destroy(req); + if (!smbcli_request_receive(req) || + smbcli_request_is_error(req)) { + return smbcli_request_destroy(req); } - CLI_CHECK_WCT(req, 2); + SMBCLI_CHECK_WCT(req, 2); parms->out.offset = IVAL(req->in.vwv, VWV(0)); failed: - return cli_request_destroy(req); + return smbcli_request_destroy(req); } /* seek a file - sync interface */ -NTSTATUS smb_raw_seek(struct cli_tree *tree, +NTSTATUS smb_raw_seek(struct smbcli_tree *tree, struct smb_seek *parms) { - struct cli_request *req = smb_raw_seek_send(tree, parms); + struct smbcli_request *req = smb_raw_seek_send(tree, parms); return smb_raw_seek_recv(req, parms); } diff --git a/source4/libcli/raw/rawfileinfo.c b/source4/libcli/raw/rawfileinfo.c index f27a0d7281..8dc220b0b4 100644 --- a/source4/libcli/raw/rawfileinfo.c +++ b/source4/libcli/raw/rawfileinfo.c @@ -36,7 +36,7 @@ /**************************************************************************** Handle qfileinfo/qpathinfo trans2 backend. ****************************************************************************/ -static NTSTATUS smb_raw_info_backend(struct cli_session *session, +static NTSTATUS smb_raw_info_backend(struct smbcli_session *session, TALLOC_CTX *mem_ctx, union smb_fileinfo *parms, DATA_BLOB *blob) @@ -95,10 +95,10 @@ static NTSTATUS smb_raw_info_backend(struct cli_session *session, if (blob->length != 36) { FINFO_CHECK_SIZE(40); } - parms->basic_info.out.create_time = cli_pull_nttime(blob->data, 0); - parms->basic_info.out.access_time = cli_pull_nttime(blob->data, 8); - parms->basic_info.out.write_time = cli_pull_nttime(blob->data, 16); - parms->basic_info.out.change_time = cli_pull_nttime(blob->data, 24); + parms->basic_info.out.create_time = smbcli_pull_nttime(blob->data, 0); + parms->basic_info.out.access_time = smbcli_pull_nttime(blob->data, 8); + parms->basic_info.out.write_time = smbcli_pull_nttime(blob->data, 16); + parms->basic_info.out.change_time = smbcli_pull_nttime(blob->data, 24); parms->basic_info.out.attrib = IVAL(blob->data, 32); return NT_STATUS_OK; @@ -121,17 +121,17 @@ static NTSTATUS smb_raw_info_backend(struct cli_session *session, case RAW_FILEINFO_NAME_INFO: case RAW_FILEINFO_NAME_INFORMATION: FINFO_CHECK_MIN_SIZE(4); - cli_blob_pull_string(session, mem_ctx, blob, + smbcli_blob_pull_string(session, mem_ctx, blob, &parms->name_info.out.fname, 0, 4, STR_UNICODE); return NT_STATUS_OK; case RAW_FILEINFO_ALL_INFO: case RAW_FILEINFO_ALL_INFORMATION: FINFO_CHECK_MIN_SIZE(72); - parms->all_info.out.create_time = cli_pull_nttime(blob->data, 0); - parms->all_info.out.access_time = cli_pull_nttime(blob->data, 8); - parms->all_info.out.write_time = cli_pull_nttime(blob->data, 16); - parms->all_info.out.change_time = cli_pull_nttime(blob->data, 24); + parms->all_info.out.create_time = smbcli_pull_nttime(blob->data, 0); + parms->all_info.out.access_time = smbcli_pull_nttime(blob->data, 8); + parms->all_info.out.write_time = smbcli_pull_nttime(blob->data, 16); + parms->all_info.out.change_time = smbcli_pull_nttime(blob->data, 24); parms->all_info.out.attrib = IVAL(blob->data, 32); parms->all_info.out.alloc_size = BVAL(blob->data, 40); parms->all_info.out.size = BVAL(blob->data, 48); @@ -139,14 +139,14 @@ static NTSTATUS smb_raw_info_backend(struct cli_session *session, parms->all_info.out.delete_pending = CVAL(blob->data, 60); parms->all_info.out.directory = CVAL(blob->data, 61); parms->all_info.out.ea_size = IVAL(blob->data, 64); - cli_blob_pull_string(session, mem_ctx, blob, + smbcli_blob_pull_string(session, mem_ctx, blob, &parms->all_info.out.fname, 68, 72, STR_UNICODE); return NT_STATUS_OK; case RAW_FILEINFO_ALT_NAME_INFO: case RAW_FILEINFO_ALT_NAME_INFORMATION: FINFO_CHECK_MIN_SIZE(4); - cli_blob_pull_string(session, mem_ctx, blob, + smbcli_blob_pull_string(session, mem_ctx, blob, &parms->alt_name_info.out.fname, 0, 4, STR_UNICODE); return NT_STATUS_OK; @@ -166,7 +166,7 @@ static NTSTATUS smb_raw_info_backend(struct cli_session *session, } parms->stream_info.out.streams[n].size = BVAL(blob->data, ofs + 8); parms->stream_info.out.streams[n].alloc_size = BVAL(blob->data, ofs + 16); - cli_blob_pull_string(session, mem_ctx, blob, + smbcli_blob_pull_string(session, mem_ctx, blob, &parms->stream_info.out.streams[n].stream_name, ofs+4, ofs+24, STR_UNICODE); parms->stream_info.out.num_streams++; @@ -218,9 +218,9 @@ static NTSTATUS smb_raw_info_backend(struct cli_session *session, FINFO_CHECK_SIZE(100); parms->unix_basic_info.out.end_of_file = BVAL(blob->data, 0); parms->unix_basic_info.out.num_bytes = BVAL(blob->data, 8); - parms->unix_basic_info.out.status_change_time = cli_pull_nttime(blob->data, 16); - parms->unix_basic_info.out.access_time = cli_pull_nttime(blob->data, 24); - parms->unix_basic_info.out.change_time = cli_pull_nttime(blob->data, 32); + parms->unix_basic_info.out.status_change_time = smbcli_pull_nttime(blob->data, 16); + parms->unix_basic_info.out.access_time = smbcli_pull_nttime(blob->data, 24); + parms->unix_basic_info.out.change_time = smbcli_pull_nttime(blob->data, 32); parms->unix_basic_info.out.uid = BVAL(blob->data, 40); parms->unix_basic_info.out.gid = BVAL(blob->data, 48); parms->unix_basic_info.out.file_type = IVAL(blob->data, 52); @@ -232,16 +232,16 @@ static NTSTATUS smb_raw_info_backend(struct cli_session *session, return NT_STATUS_OK; case RAW_FILEINFO_UNIX_LINK: - cli_blob_pull_string(session, mem_ctx, blob, + smbcli_blob_pull_string(session, mem_ctx, blob, &parms->unix_link_info.out.link_dest, 0, 4, STR_UNICODE); return NT_STATUS_OK; case RAW_FILEINFO_NETWORK_OPEN_INFORMATION: FINFO_CHECK_SIZE(56); - parms->network_open_information.out.create_time = cli_pull_nttime(blob->data, 0); - parms->network_open_information.out.access_time = cli_pull_nttime(blob->data, 8); - parms->network_open_information.out.write_time = cli_pull_nttime(blob->data, 16); - parms->network_open_information.out.change_time = cli_pull_nttime(blob->data, 24); + parms->network_open_information.out.create_time = smbcli_pull_nttime(blob->data, 0); + parms->network_open_information.out.access_time = smbcli_pull_nttime(blob->data, 8); + parms->network_open_information.out.write_time = smbcli_pull_nttime(blob->data, 16); + parms->network_open_information.out.change_time = smbcli_pull_nttime(blob->data, 24); parms->network_open_information.out.alloc_size = BVAL(blob->data, 32); parms->network_open_information.out.size = BVAL(blob->data, 40); parms->network_open_information.out.attrib = IVAL(blob->data, 48); @@ -260,12 +260,12 @@ static NTSTATUS smb_raw_info_backend(struct cli_session *session, /**************************************************************************** Very raw query file info - returns param/data blobs - (async send) ****************************************************************************/ -static struct cli_request *smb_raw_fileinfo_blob_send(struct cli_tree *tree, +static struct smbcli_request *smb_raw_fileinfo_blob_send(struct smbcli_tree *tree, uint16_t fnum, uint16_t info_level) { struct smb_trans2 tp; uint16_t setup = TRANSACT2_QFILEINFO; - struct cli_request *req; + struct smbcli_request *req; TALLOC_CTX *mem_ctx = talloc_init("raw_fileinfo"); tp.in.max_setup = 0; @@ -297,7 +297,7 @@ static struct cli_request *smb_raw_fileinfo_blob_send(struct cli_tree *tree, /**************************************************************************** Very raw query file info - returns param/data blobs - (async recv) ****************************************************************************/ -static NTSTATUS smb_raw_fileinfo_blob_recv(struct cli_request *req, +static NTSTATUS smb_raw_fileinfo_blob_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, DATA_BLOB *blob) { @@ -312,13 +312,13 @@ static NTSTATUS smb_raw_fileinfo_blob_recv(struct cli_request *req, /**************************************************************************** Very raw query path info - returns param/data blobs (async send) ****************************************************************************/ -static struct cli_request *smb_raw_pathinfo_blob_send(struct cli_tree *tree, +static struct smbcli_request *smb_raw_pathinfo_blob_send(struct smbcli_tree *tree, const char *fname, uint16_t info_level) { struct smb_trans2 tp; uint16_t setup = TRANSACT2_QPATHINFO; - struct cli_request *req; + struct smbcli_request *req; TALLOC_CTX *mem_ctx = talloc_init("raw_pathinfo"); tp.in.max_setup = 0; @@ -338,7 +338,7 @@ static struct cli_request *smb_raw_pathinfo_blob_send(struct cli_tree *tree, SSVAL(tp.in.params.data, 0, info_level); SIVAL(tp.in.params.data, 2, 0); - cli_blob_append_string(tree->session, mem_ctx, &tp.in.params, + smbcli_blob_append_string(tree->session, mem_ctx, &tp.in.params, fname, STR_TERMINATE); req = smb_raw_trans2_send(tree, &tp); @@ -351,18 +351,18 @@ static struct cli_request *smb_raw_pathinfo_blob_send(struct cli_tree *tree, /**************************************************************************** send a SMBgetatr (async send) ****************************************************************************/ -static struct cli_request *smb_raw_getattr_send(struct cli_tree *tree, +static struct smbcli_request *smb_raw_getattr_send(struct smbcli_tree *tree, union smb_fileinfo *parms) { - struct cli_request *req; + struct smbcli_request *req; - req = cli_request_setup(tree, SMBgetatr, 0, 0); + req = smbcli_request_setup(tree, SMBgetatr, 0, 0); if (!req) return NULL; - cli_req_append_ascii4(req, parms->getattr.in.fname, STR_TERMINATE); + smbcli_req_append_ascii4(req, parms->getattr.in.fname, STR_TERMINATE); - if (!cli_request_send(req)) { - cli_request_destroy(req); + if (!smbcli_request_send(req)) { + smbcli_request_destroy(req); return NULL; } @@ -372,39 +372,39 @@ static struct cli_request *smb_raw_getattr_send(struct cli_tree *tree, /**************************************************************************** send a SMBgetatr (async recv) ****************************************************************************/ -static NTSTATUS smb_raw_getattr_recv(struct cli_request *req, +static NTSTATUS smb_raw_getattr_recv(struct smbcli_request *req, union smb_fileinfo *parms) { - if (!cli_request_receive(req) || - cli_request_is_error(req)) { - return cli_request_destroy(req); + if (!smbcli_request_receive(req) || + smbcli_request_is_error(req)) { + return smbcli_request_destroy(req); } - CLI_CHECK_WCT(req, 10); + SMBCLI_CHECK_WCT(req, 10); parms->getattr.out.attrib = SVAL(req->in.vwv, VWV(0)); parms->getattr.out.write_time = raw_pull_dos_date3(req->transport, req->in.vwv + VWV(1)); parms->getattr.out.size = IVAL(req->in.vwv, VWV(3)); failed: - return cli_request_destroy(req); + return smbcli_request_destroy(req); } /**************************************************************************** Handle SMBgetattrE (async send) ****************************************************************************/ -static struct cli_request *smb_raw_getattrE_send(struct cli_tree *tree, +static struct smbcli_request *smb_raw_getattrE_send(struct smbcli_tree *tree, union smb_fileinfo *parms) { - struct cli_request *req; + struct smbcli_request *req; - req = cli_request_setup(tree, SMBgetattrE, 1, 0); + req = smbcli_request_setup(tree, SMBgetattrE, 1, 0); if (!req) return NULL; SSVAL(req->out.vwv, VWV(0), parms->getattre.in.fnum); - if (!cli_request_send(req)) { - cli_request_destroy(req); + if (!smbcli_request_send(req)) { + smbcli_request_destroy(req); return NULL; } @@ -414,15 +414,15 @@ static struct cli_request *smb_raw_getattrE_send(struct cli_tree *tree, /**************************************************************************** Handle SMBgetattrE (async send) ****************************************************************************/ -static NTSTATUS smb_raw_getattrE_recv(struct cli_request *req, +static NTSTATUS smb_raw_getattrE_recv(struct smbcli_request *req, union smb_fileinfo *parms) { - if (!cli_request_receive(req) || - cli_request_is_error(req)) { - return cli_request_destroy(req); + if (!smbcli_request_receive(req) || + smbcli_request_is_error(req)) { + return smbcli_request_destroy(req); } - CLI_CHECK_WCT(req, 11); + SMBCLI_CHECK_WCT(req, 11); parms->getattre.out.create_time = raw_pull_dos_date2(req->transport, req->in.vwv + VWV(0)); parms->getattre.out.access_time = raw_pull_dos_date2(req->transport, @@ -434,14 +434,14 @@ static NTSTATUS smb_raw_getattrE_recv(struct cli_request *req, parms->getattre.out.attrib = SVAL(req->in.vwv, VWV(10)); failed: - return cli_request_destroy(req); + return smbcli_request_destroy(req); } /**************************************************************************** Query file info (async send) ****************************************************************************/ -struct cli_request *smb_raw_fileinfo_send(struct cli_tree *tree, +struct smbcli_request *smb_raw_fileinfo_send(struct smbcli_tree *tree, union smb_fileinfo *parms) { /* pass off the non-trans2 level to specialised functions */ @@ -460,13 +460,13 @@ struct cli_request *smb_raw_fileinfo_send(struct cli_tree *tree, /**************************************************************************** Query file info (async recv) ****************************************************************************/ -NTSTATUS smb_raw_fileinfo_recv(struct cli_request *req, +NTSTATUS smb_raw_fileinfo_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, union smb_fileinfo *parms) { DATA_BLOB blob; NTSTATUS status; - struct cli_session *session = req?req->session:NULL; + struct smbcli_session *session = req?req->session:NULL; if (parms->generic.level == RAW_FILEINFO_GETATTRE) { return smb_raw_getattrE_recv(req, parms); @@ -486,18 +486,18 @@ NTSTATUS smb_raw_fileinfo_recv(struct cli_request *req, /**************************************************************************** Query file info (sync interface) ****************************************************************************/ -NTSTATUS smb_raw_fileinfo(struct cli_tree *tree, +NTSTATUS smb_raw_fileinfo(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_fileinfo *parms) { - struct cli_request *req = smb_raw_fileinfo_send(tree, parms); + struct smbcli_request *req = smb_raw_fileinfo_send(tree, parms); return smb_raw_fileinfo_recv(req, mem_ctx, parms); } /**************************************************************************** Query path info (async send) ****************************************************************************/ -struct cli_request *smb_raw_pathinfo_send(struct cli_tree *tree, +struct smbcli_request *smb_raw_pathinfo_send(struct smbcli_tree *tree, union smb_fileinfo *parms) { if (parms->generic.level == RAW_FILEINFO_GETATTR) { @@ -514,7 +514,7 @@ struct cli_request *smb_raw_pathinfo_send(struct cli_tree *tree, /**************************************************************************** Query path info (async recv) ****************************************************************************/ -NTSTATUS smb_raw_pathinfo_recv(struct cli_request *req, +NTSTATUS smb_raw_pathinfo_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, union smb_fileinfo *parms) { @@ -525,10 +525,10 @@ NTSTATUS smb_raw_pathinfo_recv(struct cli_request *req, /**************************************************************************** Query path info (sync interface) ****************************************************************************/ -NTSTATUS smb_raw_pathinfo(struct cli_tree *tree, +NTSTATUS smb_raw_pathinfo(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_fileinfo *parms) { - struct cli_request *req = smb_raw_pathinfo_send(tree, parms); + struct smbcli_request *req = smb_raw_pathinfo_send(tree, parms); return smb_raw_pathinfo_recv(req, mem_ctx, parms); } diff --git a/source4/libcli/raw/rawfsinfo.c b/source4/libcli/raw/rawfsinfo.c index faf375deb0..aefe8e3085 100644 --- a/source4/libcli/raw/rawfsinfo.c +++ b/source4/libcli/raw/rawfsinfo.c @@ -25,15 +25,15 @@ /**************************************************************************** Query FS Info - SMBdskattr call (async send) ****************************************************************************/ -static struct cli_request *smb_raw_dskattr_send(struct cli_tree *tree, +static struct smbcli_request *smb_raw_dskattr_send(struct smbcli_tree *tree, union smb_fsinfo *fsinfo) { - struct cli_request *req; + struct smbcli_request *req; - req = cli_request_setup(tree, SMBdskattr, 0, 0); + req = smbcli_request_setup(tree, SMBdskattr, 0, 0); - if (!cli_request_send(req)) { - cli_request_destroy(req); + if (!smbcli_request_send(req)) { + smbcli_request_destroy(req); return NULL; } @@ -43,29 +43,29 @@ static struct cli_request *smb_raw_dskattr_send(struct cli_tree *tree, /**************************************************************************** Query FS Info - SMBdskattr call (async recv) ****************************************************************************/ -static NTSTATUS smb_raw_dskattr_recv(struct cli_request *req, +static NTSTATUS smb_raw_dskattr_recv(struct smbcli_request *req, union smb_fsinfo *fsinfo) { - if (!cli_request_receive(req) || - cli_request_is_error(req)) { + if (!smbcli_request_receive(req) || + smbcli_request_is_error(req)) { goto failed; } - CLI_CHECK_WCT(req, 5); + SMBCLI_CHECK_WCT(req, 5); fsinfo->dskattr.out.units_total = SVAL(req->in.vwv, VWV(0)); fsinfo->dskattr.out.blocks_per_unit = SVAL(req->in.vwv, VWV(1)); fsinfo->dskattr.out.block_size = SVAL(req->in.vwv, VWV(2)); fsinfo->dskattr.out.units_free = SVAL(req->in.vwv, VWV(3)); failed: - return cli_request_destroy(req); + return smbcli_request_destroy(req); } /**************************************************************************** RAW_QFS_ trans2 interface via blobs (async send) ****************************************************************************/ -static struct cli_request *smb_raw_qfsinfo_send(struct cli_tree *tree, +static struct smbcli_request *smb_raw_qfsinfo_send(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, uint16_t info_level) { @@ -94,7 +94,7 @@ static struct cli_request *smb_raw_qfsinfo_send(struct cli_tree *tree, /**************************************************************************** RAW_QFS_ trans2 interface via blobs (async recv) ****************************************************************************/ -static NTSTATUS smb_raw_qfsinfo_blob_recv(struct cli_request *req, +static NTSTATUS smb_raw_qfsinfo_blob_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, DATA_BLOB *blob) { @@ -129,7 +129,7 @@ static NTSTATUS smb_raw_qfsinfo_blob_recv(struct cli_request *req, /**************************************************************************** Query FSInfo raw interface (async send) ****************************************************************************/ -struct cli_request *smb_raw_fsinfo_send(struct cli_tree *tree, +struct smbcli_request *smb_raw_fsinfo_send(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_fsinfo *fsinfo) { @@ -153,14 +153,14 @@ struct cli_request *smb_raw_fsinfo_send(struct cli_tree *tree, /**************************************************************************** Query FSInfo raw interface (async recv) ****************************************************************************/ -NTSTATUS smb_raw_fsinfo_recv(struct cli_request *req, +NTSTATUS smb_raw_fsinfo_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, union smb_fsinfo *fsinfo) { DATA_BLOB blob; NTSTATUS status; int i; - struct cli_session *session = req?req->session:NULL; + struct smbcli_session *session = req?req->session:NULL; if (fsinfo->generic.level == RAW_QFS_DSKATTR) { return smb_raw_dskattr_recv(req, fsinfo); @@ -190,7 +190,7 @@ NTSTATUS smb_raw_fsinfo_recv(struct cli_request *req, case RAW_QFS_VOLUME: QFS_CHECK_MIN_SIZE(5); fsinfo->volume.out.serial_number = IVAL(blob.data, 0); - cli_blob_pull_string(session, mem_ctx, &blob, + smbcli_blob_pull_string(session, mem_ctx, &blob, &fsinfo->volume.out.volume_name, 4, 5, STR_LEN8BIT | STR_NOALIGN); break; @@ -198,9 +198,9 @@ NTSTATUS smb_raw_fsinfo_recv(struct cli_request *req, case RAW_QFS_VOLUME_INFO: case RAW_QFS_VOLUME_INFORMATION: QFS_CHECK_MIN_SIZE(18); - fsinfo->volume_info.out.create_time = cli_pull_nttime(blob.data, 0); + fsinfo->volume_info.out.create_time = smbcli_pull_nttime(blob.data, 0); fsinfo->volume_info.out.serial_number = IVAL(blob.data, 8); - cli_blob_pull_string(session, mem_ctx, &blob, + smbcli_blob_pull_string(session, mem_ctx, &blob, &fsinfo->volume_info.out.volume_name, 12, 18, STR_UNICODE); break; @@ -226,7 +226,7 @@ NTSTATUS smb_raw_fsinfo_recv(struct cli_request *req, QFS_CHECK_MIN_SIZE(12); fsinfo->attribute_info.out.fs_attr = IVAL(blob.data, 0); fsinfo->attribute_info.out.max_file_component_length = IVAL(blob.data, 4); - cli_blob_pull_string(session, mem_ctx, &blob, + smbcli_blob_pull_string(session, mem_ctx, &blob, &fsinfo->attribute_info.out.fs_type, 8, 12, STR_UNICODE); break; @@ -274,10 +274,10 @@ failed: /**************************************************************************** Query FSInfo raw interface (sync interface) ****************************************************************************/ -NTSTATUS smb_raw_fsinfo(struct cli_tree *tree, +NTSTATUS smb_raw_fsinfo(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_fsinfo *fsinfo) { - struct cli_request *req = smb_raw_fsinfo_send(tree, mem_ctx, fsinfo); + struct smbcli_request *req = smb_raw_fsinfo_send(tree, mem_ctx, fsinfo); return smb_raw_fsinfo_recv(req, mem_ctx, fsinfo); } diff --git a/source4/libcli/raw/rawioctl.c b/source4/libcli/raw/rawioctl.c index 271758c65c..798300451b 100644 --- a/source4/libcli/raw/rawioctl.c +++ b/source4/libcli/raw/rawioctl.c @@ -22,25 +22,25 @@ #include "includes.h" #define SETUP_REQUEST(cmd, wct, buflen) do { \ - req = cli_request_setup(tree, cmd, wct, buflen); \ + req = smbcli_request_setup(tree, cmd, wct, buflen); \ if (!req) return NULL; \ } while (0) /* send a raw smb ioctl - async send */ -static struct cli_request *smb_raw_smbioctl_send(struct cli_tree *tree, +static struct smbcli_request *smb_raw_smbioctl_send(struct smbcli_tree *tree, union smb_ioctl *parms) { - struct cli_request *req; + struct smbcli_request *req; SETUP_REQUEST(SMBioctl, 3, 0); SSVAL(req->out.vwv, VWV(0), parms->ioctl.in.fnum); SIVAL(req->out.vwv, VWV(1), parms->ioctl.in.request); - if (!cli_request_send(req)) { - cli_request_destroy(req); + if (!smbcli_request_send(req)) { + smbcli_request_destroy(req); return NULL; } @@ -50,17 +50,17 @@ static struct cli_request *smb_raw_smbioctl_send(struct cli_tree *tree, /* send a raw smb ioctl - async recv */ -static NTSTATUS smb_raw_smbioctl_recv(struct cli_request *req, +static NTSTATUS smb_raw_smbioctl_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, union smb_ioctl *parms) { - if (!cli_request_receive(req) || - cli_request_is_error(req)) { - return cli_request_destroy(req); + if (!smbcli_request_receive(req) || + smbcli_request_is_error(req)) { + return smbcli_request_destroy(req); } - parms->ioctl.out.blob = cli_req_pull_blob(req, mem_ctx, req->in.data, -1); - return cli_request_destroy(req); + parms->ioctl.out.blob = smbcli_req_pull_blob(req, mem_ctx, req->in.data, -1); + return smbcli_request_destroy(req); } @@ -68,7 +68,7 @@ static NTSTATUS smb_raw_smbioctl_recv(struct cli_request *req, /**************************************************************************** NT ioctl (async send) ****************************************************************************/ -static struct cli_request *smb_raw_ntioctl_send(struct cli_tree *tree, +static struct smbcli_request *smb_raw_ntioctl_send(struct smbcli_tree *tree, union smb_ioctl *parms) { struct smb_nttrans nt; @@ -93,26 +93,26 @@ static struct cli_request *smb_raw_ntioctl_send(struct cli_tree *tree, /**************************************************************************** NT ioctl (async recv) ****************************************************************************/ -static NTSTATUS smb_raw_ntioctl_recv(struct cli_request *req, +static NTSTATUS smb_raw_ntioctl_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, union smb_ioctl *parms) { - if (!cli_request_receive(req) || - cli_request_is_error(req)) { - return cli_request_destroy(req); + if (!smbcli_request_receive(req) || + smbcli_request_is_error(req)) { + return smbcli_request_destroy(req); } - parms->ntioctl.out.blob = cli_req_pull_blob(req, mem_ctx, req->in.data, -1); - return cli_request_destroy(req); + parms->ntioctl.out.blob = smbcli_req_pull_blob(req, mem_ctx, req->in.data, -1); + return smbcli_request_destroy(req); } /* send a raw ioctl - async send */ -struct cli_request *smb_raw_ioctl_send(struct cli_tree *tree, union smb_ioctl *parms) +struct smbcli_request *smb_raw_ioctl_send(struct smbcli_tree *tree, union smb_ioctl *parms) { - struct cli_request *req = NULL; + struct smbcli_request *req = NULL; switch (parms->generic.level) { case RAW_IOCTL_IOCTL: @@ -130,7 +130,7 @@ struct cli_request *smb_raw_ioctl_send(struct cli_tree *tree, union smb_ioctl *p /* recv a raw ioctl - async recv */ -NTSTATUS smb_raw_ioctl_recv(struct cli_request *req, +NTSTATUS smb_raw_ioctl_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, union smb_ioctl *parms) { switch (parms->generic.level) { @@ -146,10 +146,10 @@ NTSTATUS smb_raw_ioctl_recv(struct cli_request *req, /* send a raw ioctl - sync interface */ -NTSTATUS smb_raw_ioctl(struct cli_tree *tree, +NTSTATUS smb_raw_ioctl(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_ioctl *parms) { - struct cli_request *req; + struct smbcli_request *req; req = smb_raw_ioctl_send(tree, parms); return smb_raw_ioctl_recv(req, mem_ctx, parms); } diff --git a/source4/libcli/raw/rawnegotiate.c b/source4/libcli/raw/rawnegotiate.c index 6bf35fb26d..9b00aa6121 100644 --- a/source4/libcli/raw/rawnegotiate.c +++ b/source4/libcli/raw/rawnegotiate.c @@ -41,13 +41,13 @@ static const struct { /**************************************************************************** Send a negprot command. ****************************************************************************/ -struct cli_request *smb_negprot_send(struct cli_transport *transport, int maxprotocol) +struct smbcli_request *smb_negprot_send(struct smbcli_transport *transport, int maxprotocol) { - struct cli_request *req; + struct smbcli_request *req; int i; uint16_t flags2 = 0; - req = cli_request_setup_transport(transport, SMBnegprot, 0, 0); + req = smbcli_request_setup_transport(transport, SMBnegprot, 0, 0); if (!req) { return NULL; } @@ -66,12 +66,12 @@ struct cli_request *smb_negprot_send(struct cli_transport *transport, int maxpro /* setup the protocol strings */ for (i=0; i < ARRAY_SIZE(prots) && prots[i].prot <= maxprotocol; i++) { - cli_req_append_bytes(req, "\2", 1); - cli_req_append_string(req, prots[i].name, STR_TERMINATE | STR_ASCII); + smbcli_req_append_bytes(req, "\2", 1); + smbcli_req_append_string(req, prots[i].name, STR_TERMINATE | STR_ASCII); } - if (!cli_request_send(req)) { - cli_request_destroy(req); + if (!smbcli_request_send(req)) { + smbcli_request_destroy(req); return NULL; } @@ -81,9 +81,9 @@ struct cli_request *smb_negprot_send(struct cli_transport *transport, int maxpro /**************************************************************************** Send a negprot command. ****************************************************************************/ -NTSTATUS smb_raw_negotiate(struct cli_transport *transport) +NTSTATUS smb_raw_negotiate(struct smbcli_transport *transport) { - struct cli_request *req; + struct smbcli_request *req; int protocol; req = smb_negprot_send(transport, PROTOCOL_NT1); @@ -91,18 +91,18 @@ NTSTATUS smb_raw_negotiate(struct cli_transport *transport) return NT_STATUS_UNSUCCESSFUL; } - if (!cli_request_receive(req) || - cli_request_is_error(req)) { - return cli_request_destroy(req); + if (!smbcli_request_receive(req) || + smbcli_request_is_error(req)) { + return smbcli_request_destroy(req); } - CLI_CHECK_MIN_WCT(req, 1); + SMBCLI_CHECK_MIN_WCT(req, 1); protocol = SVALS(req->in.vwv, VWV(0)); if (protocol >= ARRAY_SIZE(prots) || protocol < 0) { req->status = NT_STATUS_UNSUCCESSFUL; - return cli_request_destroy(req); + return smbcli_request_destroy(req); } transport->negotiate.protocol = prots[protocol].prot; @@ -111,7 +111,7 @@ NTSTATUS smb_raw_negotiate(struct cli_transport *transport) NTTIME ntt; /* NT protocol */ - CLI_CHECK_WCT(req, 17); + SMBCLI_CHECK_WCT(req, 17); transport->negotiate.sec_mode = CVAL(req->in.vwv,VWV(1)); transport->negotiate.max_mux = SVAL(req->in.vwv,VWV(1)+1); transport->negotiate.max_xmit = IVAL(req->in.vwv,VWV(3)+1); @@ -119,7 +119,7 @@ NTSTATUS smb_raw_negotiate(struct cli_transport *transport) transport->negotiate.capabilities = IVAL(req->in.vwv,VWV(9)+1); /* this time arrives in real GMT */ - ntt = cli_pull_nttime(req->in.vwv, VWV(11)+1); + ntt = smbcli_pull_nttime(req->in.vwv, VWV(11)+1); transport->negotiate.server_time = nt_time_to_unix(ntt); transport->negotiate.server_zone = SVALS(req->in.vwv,VWV(15)+1) * 60; transport->negotiate.key_len = CVAL(req->in.vwv,VWV(16)+1); @@ -128,14 +128,14 @@ NTSTATUS smb_raw_negotiate(struct cli_transport *transport) if (req->in.data_size < 16) { goto failed; } - transport->negotiate.server_guid = cli_req_pull_blob(req, transport->mem_ctx, req->in.data, 16); - transport->negotiate.secblob = cli_req_pull_blob(req, transport->mem_ctx, req->in.data + 16, req->in.data_size - 16); + transport->negotiate.server_guid = smbcli_req_pull_blob(req, transport->mem_ctx, req->in.data, 16); + transport->negotiate.secblob = smbcli_req_pull_blob(req, transport->mem_ctx, req->in.data + 16, req->in.data_size - 16); } else { if (req->in.data_size < (transport->negotiate.key_len)) { goto failed; } - transport->negotiate.secblob = cli_req_pull_blob(req, transport->mem_ctx, req->in.data, transport->negotiate.key_len); - cli_req_pull_string(req, transport->mem_ctx, &transport->negotiate.server_domain, + transport->negotiate.secblob = smbcli_req_pull_blob(req, transport->mem_ctx, req->in.data, transport->negotiate.key_len); + smbcli_req_pull_string(req, transport->mem_ctx, &transport->negotiate.server_domain, req->in.data+transport->negotiate.key_len, req->in.data_size-transport->negotiate.key_len, STR_UNICODE|STR_NOALIGN); /* here comes the server name */ @@ -146,7 +146,7 @@ NTSTATUS smb_raw_negotiate(struct cli_transport *transport) transport->negotiate.writebraw_supported = True; } } else if (transport->negotiate.protocol >= PROTOCOL_LANMAN1) { - CLI_CHECK_WCT(req, 13); + SMBCLI_CHECK_WCT(req, 13); transport->negotiate.sec_mode = SVAL(req->in.vwv,VWV(1)); transport->negotiate.max_xmit = SVAL(req->in.vwv,VWV(2)); transport->negotiate.sesskey = IVAL(req->in.vwv,VWV(6)); @@ -161,7 +161,7 @@ NTSTATUS smb_raw_negotiate(struct cli_transport *transport) if ((SVAL(req->in.vwv,VWV(5)) & 0x2)) { transport->negotiate.writebraw_supported = 1; } - transport->negotiate.secblob = cli_req_pull_blob(req, transport->mem_ctx, + transport->negotiate.secblob = smbcli_req_pull_blob(req, transport->mem_ctx, req->in.data, req->in.data_size); } else { /* the old core protocol */ @@ -172,10 +172,10 @@ NTSTATUS smb_raw_negotiate(struct cli_transport *transport) } /* a way to force ascii SMB */ - if (getenv("CLI_FORCE_ASCII")) { + if (getenv("SMBCLI_FORCE_ASCII")) { transport->negotiate.capabilities &= ~CAP_UNICODE; } failed: - return cli_request_destroy(req); + return smbcli_request_destroy(req); } diff --git a/source4/libcli/raw/rawnotify.c b/source4/libcli/raw/rawnotify.c index a9215fee10..47553e735e 100644 --- a/source4/libcli/raw/rawnotify.c +++ b/source4/libcli/raw/rawnotify.c @@ -23,7 +23,7 @@ /**************************************************************************** change notify (async send) ****************************************************************************/ -struct cli_request *smb_raw_changenotify_send(struct cli_tree *tree, struct smb_notify *parms) +struct smbcli_request *smb_raw_changenotify_send(struct smbcli_tree *tree, struct smb_notify *parms) { struct smb_nttrans nt; uint16_t setup[4]; @@ -46,13 +46,13 @@ struct cli_request *smb_raw_changenotify_send(struct cli_tree *tree, struct smb_ /**************************************************************************** change notify (async recv) ****************************************************************************/ -NTSTATUS smb_raw_changenotify_recv(struct cli_request *req, +NTSTATUS smb_raw_changenotify_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, struct smb_notify *parms) { struct smb_nttrans nt; NTSTATUS status; uint32_t ofs, i; - struct cli_session *session = req?req->session:NULL; + struct smbcli_session *session = req?req->session:NULL; status = smb_raw_nttrans_recv(req, mem_ctx, &nt); if (!NT_STATUS_IS_OK(status)) { @@ -80,7 +80,7 @@ NTSTATUS smb_raw_changenotify_recv(struct cli_request *req, for (i=ofs=0; iout.num_changes; i++) { parms->out.changes[i].action = IVAL(nt.out.params.data, ofs+4); - cli_blob_pull_string(session, mem_ctx, &nt.out.params, + smbcli_blob_pull_string(session, mem_ctx, &nt.out.params, &parms->out.changes[i].name, ofs+8, ofs+12, STR_UNICODE); ofs += IVAL(nt.out.params.data, ofs); @@ -95,11 +95,11 @@ NTSTATUS smb_raw_changenotify_recv(struct cli_request *req, used to cancel a pending change notify request note that this request does not expect a response! ****************************************************************************/ -NTSTATUS smb_raw_ntcancel(struct cli_request *oldreq) +NTSTATUS smb_raw_ntcancel(struct smbcli_request *oldreq) { - struct cli_request *req; + struct smbcli_request *req; - req = cli_request_setup_transport(oldreq->transport, SMBntcancel, 0, 0); + req = smbcli_request_setup_transport(oldreq->transport, SMBntcancel, 0, 0); SSVAL(req->out.hdr, HDR_MID, SVAL(oldreq->out.hdr, HDR_MID)); SSVAL(req->out.hdr, HDR_PID, SVAL(oldreq->out.hdr, HDR_PID)); @@ -111,7 +111,7 @@ NTSTATUS smb_raw_ntcancel(struct cli_request *oldreq) req->sign_single_increment = 1; req->one_way_request = 1; - cli_request_send(req); + smbcli_request_send(req); return NT_STATUS_OK; } diff --git a/source4/libcli/raw/rawreadwrite.c b/source4/libcli/raw/rawreadwrite.c index 3e3b29d252..f0a9a063ed 100644 --- a/source4/libcli/raw/rawreadwrite.c +++ b/source4/libcli/raw/rawreadwrite.c @@ -22,7 +22,7 @@ #include "includes.h" #define SETUP_REQUEST(cmd, wct, buflen) do { \ - req = cli_request_setup(tree, cmd, wct, buflen); \ + req = smbcli_request_setup(tree, cmd, wct, buflen); \ if (!req) return NULL; \ } while (0) @@ -30,10 +30,10 @@ /**************************************************************************** low level read operation (async send) ****************************************************************************/ -struct cli_request *smb_raw_read_send(struct cli_tree *tree, union smb_read *parms) +struct smbcli_request *smb_raw_read_send(struct smbcli_tree *tree, union smb_read *parms) { BOOL bigoffset = False; - struct cli_request *req; + struct smbcli_request *req; switch (parms->generic.level) { case RAW_READ_GENERIC: @@ -90,8 +90,8 @@ struct cli_request *smb_raw_read_send(struct cli_tree *tree, union smb_read *par break; } - if (!cli_request_send(req)) { - cli_request_destroy(req); + if (!smbcli_request_send(req)) { + smbcli_request_destroy(req); return NULL; } @@ -107,10 +107,10 @@ struct cli_request *smb_raw_read_send(struct cli_tree *tree, union smb_read *par /**************************************************************************** low level read operation (async recv) ****************************************************************************/ -NTSTATUS smb_raw_read_recv(struct cli_request *req, union smb_read *parms) +NTSTATUS smb_raw_read_recv(struct smbcli_request *req, union smb_read *parms) { - if (!cli_request_receive(req) || - cli_request_is_error(req)) { + if (!smbcli_request_receive(req) || + smbcli_request_is_error(req)) { goto failed; } @@ -130,10 +130,10 @@ NTSTATUS smb_raw_read_recv(struct cli_request *req, union smb_read *parms) break; case RAW_READ_LOCKREAD: - CLI_CHECK_WCT(req, 5); + SMBCLI_CHECK_WCT(req, 5); parms->lockread.out.nread = SVAL(req->in.vwv, VWV(0)); if (parms->lockread.out.nread > parms->lockread.in.count || - !cli_raw_pull_data(req, req->in.data+3, + !smbcli_raw_pull_data(req, req->in.data+3, parms->lockread.out.nread, parms->lockread.out.data)) { req->status = NT_STATUS_BUFFER_TOO_SMALL; } @@ -141,10 +141,10 @@ NTSTATUS smb_raw_read_recv(struct cli_request *req, union smb_read *parms) case RAW_READ_READ: /* there are 4 reserved words in the reply */ - CLI_CHECK_WCT(req, 5); + SMBCLI_CHECK_WCT(req, 5); parms->read.out.nread = SVAL(req->in.vwv, VWV(0)); if (parms->read.out.nread > parms->read.in.count || - !cli_raw_pull_data(req, req->in.data+3, + !smbcli_raw_pull_data(req, req->in.data+3, parms->read.out.nread, parms->read.out.data)) { req->status = NT_STATUS_BUFFER_TOO_SMALL; } @@ -152,12 +152,12 @@ NTSTATUS smb_raw_read_recv(struct cli_request *req, union smb_read *parms) case RAW_READ_READX: /* there are 5 reserved words in the reply */ - CLI_CHECK_WCT(req, 12); + SMBCLI_CHECK_WCT(req, 12); parms->readx.out.remaining = SVAL(req->in.vwv, VWV(2)); parms->readx.out.compaction_mode = SVAL(req->in.vwv, VWV(3)); parms->readx.out.nread = SVAL(req->in.vwv, VWV(5)); if (parms->readx.out.nread > MAX(parms->readx.in.mincnt, parms->readx.in.maxcnt) || - !cli_raw_pull_data(req, req->in.hdr + SVAL(req->in.vwv, VWV(6)), + !smbcli_raw_pull_data(req, req->in.hdr + SVAL(req->in.vwv, VWV(6)), parms->readx.out.nread, parms->readx.out.data)) { req->status = NT_STATUS_BUFFER_TOO_SMALL; @@ -166,15 +166,15 @@ NTSTATUS smb_raw_read_recv(struct cli_request *req, union smb_read *parms) } failed: - return cli_request_destroy(req); + return smbcli_request_destroy(req); } /**************************************************************************** low level read operation (sync interface) ****************************************************************************/ -NTSTATUS smb_raw_read(struct cli_tree *tree, union smb_read *parms) +NTSTATUS smb_raw_read(struct smbcli_tree *tree, union smb_read *parms) { - struct cli_request *req = smb_raw_read_send(tree, parms); + struct smbcli_request *req = smb_raw_read_send(tree, parms); return smb_raw_read_recv(req, parms); } @@ -182,10 +182,10 @@ NTSTATUS smb_raw_read(struct cli_tree *tree, union smb_read *parms) /**************************************************************************** raw write interface (async send) ****************************************************************************/ -struct cli_request *smb_raw_write_send(struct cli_tree *tree, union smb_write *parms) +struct smbcli_request *smb_raw_write_send(struct smbcli_tree *tree, union smb_write *parms) { BOOL bigoffset = False; - struct cli_request *req; + struct smbcli_request *req; switch (parms->generic.level) { case RAW_WRITE_GENERIC: @@ -264,8 +264,8 @@ struct cli_request *smb_raw_write_send(struct cli_tree *tree, union smb_write *p break; } - if (!cli_request_send(req)) { -cli_request_destroy(req); + if (!smbcli_request_send(req)) { +smbcli_request_destroy(req); return NULL; } @@ -276,10 +276,10 @@ cli_request_destroy(req); /**************************************************************************** raw write interface (async recv) ****************************************************************************/ -NTSTATUS smb_raw_write_recv(struct cli_request *req, union smb_write *parms) +NTSTATUS smb_raw_write_recv(struct smbcli_request *req, union smb_write *parms) { - if (!cli_request_receive(req) || - cli_request_is_error(req)) { + if (!smbcli_request_receive(req) || + smbcli_request_is_error(req)) { goto failed; } @@ -287,19 +287,19 @@ NTSTATUS smb_raw_write_recv(struct cli_request *req, union smb_write *parms) case RAW_WRITE_GENERIC: break; case RAW_WRITE_WRITEUNLOCK: - CLI_CHECK_WCT(req, 1); + SMBCLI_CHECK_WCT(req, 1); parms->writeunlock.out.nwritten = SVAL(req->in.vwv, VWV(0)); break; case RAW_WRITE_WRITE: - CLI_CHECK_WCT(req, 1); + SMBCLI_CHECK_WCT(req, 1); parms->write.out.nwritten = SVAL(req->in.vwv, VWV(0)); break; case RAW_WRITE_WRITECLOSE: - CLI_CHECK_WCT(req, 1); + SMBCLI_CHECK_WCT(req, 1); parms->writeclose.out.nwritten = SVAL(req->in.vwv, VWV(0)); break; case RAW_WRITE_WRITEX: - CLI_CHECK_WCT(req, 6); + SMBCLI_CHECK_WCT(req, 6); parms->writex.out.nwritten = SVAL(req->in.vwv, VWV(2)); parms->writex.out.nwritten += (CVAL(req->in.vwv, VWV(4)) << 16); parms->writex.out.remaining = SVAL(req->in.vwv, VWV(3)); @@ -309,14 +309,14 @@ NTSTATUS smb_raw_write_recv(struct cli_request *req, union smb_write *parms) } failed: - return cli_request_destroy(req); + return smbcli_request_destroy(req); } /**************************************************************************** raw write interface (sync interface) ****************************************************************************/ -NTSTATUS smb_raw_write(struct cli_tree *tree, union smb_write *parms) +NTSTATUS smb_raw_write(struct smbcli_tree *tree, union smb_write *parms) { - struct cli_request *req = smb_raw_write_send(tree, parms); + struct smbcli_request *req = smb_raw_write_send(tree, parms); return smb_raw_write_recv(req, parms); } diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 38b8f71f57..4143cb12ca 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -20,7 +20,7 @@ */ /* - this file implements functions for manipulating the 'struct cli_request' structure in libsmb + this file implements functions for manipulating the 'struct smbcli_request' structure in libsmb */ #include "includes.h" @@ -32,7 +32,7 @@ #define MAX_BYTES_PER_CHAR 3 /* destroy a request structure and return final status */ -NTSTATUS cli_request_destroy(struct cli_request *req) +NTSTATUS smbcli_request_destroy(struct smbcli_request *req) { NTSTATUS status; @@ -58,28 +58,28 @@ NTSTATUS cli_request_destroy(struct cli_request *req) low-level function to setup a request buffer for a non-SMB packet at the transport level */ -struct cli_request *cli_request_setup_nonsmb(struct cli_transport *transport, uint_t size) +struct smbcli_request *smbcli_request_setup_nonsmb(struct smbcli_transport *transport, uint_t size) { - struct cli_request *req; + struct smbcli_request *req; TALLOC_CTX *mem_ctx; /* each request gets its own talloc context. The request structure itself is also allocated inside this context, so we need to allocate it before we construct the request */ - mem_ctx = talloc_init("cli_request"); + mem_ctx = talloc_init("smbcli_request"); if (!mem_ctx) { return NULL; } - req = talloc(mem_ctx, sizeof(struct cli_request)); + req = talloc(mem_ctx, sizeof(struct smbcli_request)); if (!req) { return NULL; } ZERO_STRUCTP(req); /* setup the request context */ - req->state = CLI_REQUEST_INIT; + req->state = SMBCLI_REQUEST_INIT; req->mem_ctx = mem_ctx; req->transport = transport; req->session = NULL; @@ -103,12 +103,12 @@ struct cli_request *cli_request_setup_nonsmb(struct cli_transport *transport, ui /* setup a SMB packet at transport level */ -struct cli_request *cli_request_setup_transport(struct cli_transport *transport, +struct smbcli_request *smbcli_request_setup_transport(struct smbcli_transport *transport, uint8_t command, uint_t wct, uint_t buflen) { - struct cli_request *req; + struct smbcli_request *req; - req = cli_request_setup_nonsmb(transport, NBT_HDR_SIZE + MIN_SMB_SIZE + wct*2 + buflen); + req = smbcli_request_setup_nonsmb(transport, NBT_HDR_SIZE + MIN_SMB_SIZE + wct*2 + buflen); if (!req) return NULL; @@ -129,7 +129,7 @@ struct cli_request *cli_request_setup_transport(struct cli_transport *transport, SSVAL(req->out.hdr,HDR_FLG2, 0); /* assign a mid */ - req->mid = cli_transport_next_mid(transport); + req->mid = smbcli_transport_next_mid(transport); /* copy the pid, uid and mid to the request */ SSVAL(req->out.hdr, HDR_PID, 0); @@ -146,17 +146,17 @@ struct cli_request *cli_request_setup_transport(struct cli_transport *transport, /* setup a reply in req->out with the given word count and initial data buffer size. the caller will then fill in the command words and - data before calling cli_request_send() to send the reply on its + data before calling smbcli_request_send() to send the reply on its way. This interface is used before a session is setup. */ -struct cli_request *cli_request_setup_session(struct cli_session *session, +struct smbcli_request *smbcli_request_setup_session(struct smbcli_session *session, uint8_t command, uint_t wct, uint_t buflen) { - struct cli_request *req; + struct smbcli_request *req; uint16_t flags2; uint32_t capabilities; - req = cli_request_setup_transport(session->transport, command, wct, buflen); + req = smbcli_request_setup_transport(session->transport, command, wct, buflen); if (!req) return NULL; @@ -189,13 +189,13 @@ struct cli_request *cli_request_setup_session(struct cli_session *session, /* setup a request for tree based commands */ -struct cli_request *cli_request_setup(struct cli_tree *tree, +struct smbcli_request *smbcli_request_setup(struct smbcli_tree *tree, uint8_t command, uint_t wct, uint_t buflen) { - struct cli_request *req; + struct smbcli_request *req; - req = cli_request_setup_session(tree->session, command, wct, buflen); + req = smbcli_request_setup_session(tree->session, command, wct, buflen); if (req) { req->tree = tree; SSVAL(req->out.hdr,HDR_TID,tree->tid); @@ -211,7 +211,7 @@ struct cli_request *cli_request_setup(struct cli_tree *tree, To cope with this req->out.ptr is supplied. This will be updated to point at the same offset into the packet as before this call */ -static void cli_req_grow_allocation(struct cli_request *req, uint_t new_size) +static void smbcli_req_grow_allocation(struct smbcli_request *req, uint_t new_size) { int delta; char *buf2; @@ -252,11 +252,11 @@ static void cli_req_grow_allocation(struct cli_request *req, uint_t new_size) To cope with this req->out.ptr is supplied. This will be updated to point at the same offset into the packet as before this call */ -static void cli_req_grow_data(struct cli_request *req, uint_t new_size) +static void smbcli_req_grow_data(struct smbcli_request *req, uint_t new_size) { int delta; - cli_req_grow_allocation(req, new_size); + smbcli_req_grow_allocation(req, new_size); delta = new_size - req->out.data_size; @@ -271,15 +271,15 @@ static void cli_req_grow_data(struct cli_request *req, uint_t new_size) /* send a message */ -BOOL cli_request_send(struct cli_request *req) +BOOL smbcli_request_send(struct smbcli_request *req) { if (IVAL(req->out.buffer, 0) == 0) { _smb_setlen(req->out.buffer, req->out.size - NBT_HDR_SIZE); } - cli_request_calculate_sign_mac(req); + smbcli_request_calculate_sign_mac(req); - cli_transport_send(req); + smbcli_transport_send(req); return True; } @@ -288,14 +288,14 @@ BOOL cli_request_send(struct cli_request *req) /* receive a response to a packet */ -BOOL cli_request_receive(struct cli_request *req) +BOOL smbcli_request_receive(struct smbcli_request *req) { /* req can be NULL when a send has failed. This eliminates lots of NULL checks in each module */ if (!req) return False; /* keep receiving packets until this one is replied to */ - while (req->state <= CLI_REQUEST_RECV) { + while (req->state <= SMBCLI_REQUEST_RECV) { event_loop_once(req->transport->event.ctx); } @@ -307,12 +307,12 @@ BOOL cli_request_receive(struct cli_request *req) receive another reply to a request - this is used for requests that have multi-part replies (such as SMBtrans2) */ -BOOL cli_request_receive_more(struct cli_request *req) +BOOL smbcli_request_receive_more(struct smbcli_request *req) { - req->state = CLI_REQUEST_RECV; + req->state = SMBCLI_REQUEST_RECV; DLIST_ADD(req->transport->pending_recv, req); - return cli_request_receive(req); + return smbcli_request_receive(req); } @@ -320,7 +320,7 @@ BOOL cli_request_receive_more(struct cli_request *req) handle oplock break requests from the server - return True if the request was an oplock break */ -BOOL handle_oplock_break(struct cli_transport *transport, uint_t len, const char *hdr, const char *vwv) +BOOL handle_oplock_break(struct smbcli_transport *transport, uint_t len, const char *hdr, const char *vwv) { /* we must be very fussy about what we consider an oplock break to avoid matching readbraw replies */ @@ -347,15 +347,15 @@ BOOL handle_oplock_break(struct cli_transport *transport, uint_t len, const char wait for a reply to be received for a packet that just returns an error code and nothing more */ -NTSTATUS cli_request_simple_recv(struct cli_request *req) +NTSTATUS smbcli_request_simple_recv(struct smbcli_request *req) { - cli_request_receive(req); - return cli_request_destroy(req); + smbcli_request_receive(req); + return smbcli_request_destroy(req); } /* Return true if the last packet was in error */ -BOOL cli_request_is_error(struct cli_request *req) +BOOL smbcli_request_is_error(struct smbcli_request *req) { return NT_STATUS_IS_ERR(req->status); } @@ -365,7 +365,7 @@ BOOL cli_request_is_error(struct cli_request *req) return the number of bytes added to the packet */ -size_t cli_req_append_string(struct cli_request *req, const char *str, uint_t flags) +size_t smbcli_req_append_string(struct smbcli_request *req, const char *str, uint_t flags) { size_t len; @@ -376,17 +376,17 @@ size_t cli_req_append_string(struct cli_request *req, const char *str, uint_t fl len = (strlen(str)+2) * MAX_BYTES_PER_CHAR; - cli_req_grow_allocation(req, len + req->out.data_size); + smbcli_req_grow_allocation(req, len + req->out.data_size); len = push_string(NULL, req->out.data + req->out.data_size, str, len, flags); - cli_req_grow_data(req, len + req->out.data_size); + smbcli_req_grow_data(req, len + req->out.data_size); return len; } /* - this is like cli_req_append_string but it also return the + this is like smbcli_req_append_string but it also return the non-terminated string byte length, which can be less than the number of bytes consumed in the packet for 2 reasons: @@ -396,7 +396,7 @@ size_t cli_req_append_string(struct cli_request *req, const char *str, uint_t fl this is used in places where the non-terminated string byte length is placed in the packet as a separate field */ -size_t cli_req_append_string_len(struct cli_request *req, const char *str, uint_t flags, int *len) +size_t smbcli_req_append_string_len(struct smbcli_request *req, const char *str, uint_t flags, int *len) { int diff = 0; size_t ret; @@ -412,7 +412,7 @@ size_t cli_req_append_string_len(struct cli_request *req, const char *str, uint_ } /* do the hard work */ - ret = cli_req_append_string(req, str, flags); + ret = smbcli_req_append_string(req, str, flags); /* see if we need to subtract the termination */ if (flags & STR_TERMINATE) { @@ -437,11 +437,11 @@ size_t cli_req_append_string_len(struct cli_request *req, const char *str, uint_ if dest_len is -1 then no limit applies */ -size_t cli_req_append_ascii4(struct cli_request *req, const char *str, uint_t flags) +size_t smbcli_req_append_ascii4(struct smbcli_request *req, const char *str, uint_t flags) { size_t size; - cli_req_append_bytes(req, (const uint8_t *)"\4", 1); - size = cli_req_append_string(req, str, flags); + smbcli_req_append_bytes(req, (const uint8_t *)"\4", 1); + size = smbcli_req_append_string(req, str, flags); return size + 1; } @@ -452,11 +452,11 @@ size_t cli_req_append_ascii4(struct cli_request *req, const char *str, uint_t fl if dest is NULL, then put the blob at the end of the data portion of the packet */ -size_t cli_req_append_blob(struct cli_request *req, const DATA_BLOB *blob) +size_t smbcli_req_append_blob(struct smbcli_request *req, const DATA_BLOB *blob) { - cli_req_grow_allocation(req, req->out.data_size + blob->length); + smbcli_req_grow_allocation(req, req->out.data_size + blob->length); memcpy(req->out.data + req->out.data_size, blob->data, blob->length); - cli_req_grow_data(req, req->out.data_size + blob->length); + smbcli_req_grow_data(req, req->out.data_size + blob->length); return blob->length; } @@ -464,11 +464,11 @@ size_t cli_req_append_blob(struct cli_request *req, const DATA_BLOB *blob) append raw bytes into the data portion of the request packet return the number of bytes added */ -size_t cli_req_append_bytes(struct cli_request *req, const uint8_t *bytes, size_t byte_len) +size_t smbcli_req_append_bytes(struct smbcli_request *req, const uint8_t *bytes, size_t byte_len) { - cli_req_grow_allocation(req, byte_len + req->out.data_size); + smbcli_req_grow_allocation(req, byte_len + req->out.data_size); memcpy(req->out.data + req->out.data_size, bytes, byte_len); - cli_req_grow_data(req, byte_len + req->out.data_size); + smbcli_req_grow_data(req, byte_len + req->out.data_size); return byte_len; } @@ -476,15 +476,15 @@ size_t cli_req_append_bytes(struct cli_request *req, const uint8_t *bytes, size_ append variable block (type 5 buffer) into the data portion of the request packet return the number of bytes added */ -size_t cli_req_append_var_block(struct cli_request *req, const uint8_t *bytes, uint16_t byte_len) +size_t smbcli_req_append_var_block(struct smbcli_request *req, const uint8_t *bytes, uint16_t byte_len) { - cli_req_grow_allocation(req, byte_len + 3 + req->out.data_size); + smbcli_req_grow_allocation(req, byte_len + 3 + req->out.data_size); SCVAL(req->out.data + req->out.data_size, 0, 5); SSVAL(req->out.data + req->out.data_size, 1, byte_len); /* add field length */ if (byte_len > 0) { memcpy(req->out.data + req->out.data_size + 3, bytes, byte_len); } - cli_req_grow_data(req, byte_len + 3 + req->out.data_size); + smbcli_req_grow_data(req, byte_len + 3 + req->out.data_size); return byte_len + 3; } @@ -502,7 +502,7 @@ size_t cli_req_append_var_block(struct cli_request *req, const uint8_t *bytes, u on failure zero is returned and *dest is set to NULL, otherwise the number of bytes consumed in the packet is returned */ -static size_t cli_req_pull_ucs2(struct cli_request *req, TALLOC_CTX *mem_ctx, +static size_t smbcli_req_pull_ucs2(struct smbcli_request *req, TALLOC_CTX *mem_ctx, char **dest, const char *src, int byte_len, uint_t flags) { int src_len, src_len2, alignment=0; @@ -559,7 +559,7 @@ static size_t cli_req_pull_ucs2(struct cli_request *req, TALLOC_CTX *mem_ctx, on failure zero is returned and *dest is set to NULL, otherwise the number of bytes consumed in the packet is returned */ -size_t cli_req_pull_ascii(struct cli_request *req, TALLOC_CTX *mem_ctx, +size_t smbcli_req_pull_ascii(struct smbcli_request *req, TALLOC_CTX *mem_ctx, char **dest, const char *src, int byte_len, uint_t flags) { int src_len, src_len2; @@ -602,15 +602,15 @@ size_t cli_req_pull_ascii(struct cli_request *req, TALLOC_CTX *mem_ctx, on failure zero is returned and *dest is set to NULL, otherwise the number of bytes consumed in the packet is returned */ -size_t cli_req_pull_string(struct cli_request *req, TALLOC_CTX *mem_ctx, +size_t smbcli_req_pull_string(struct smbcli_request *req, TALLOC_CTX *mem_ctx, char **dest, const char *src, int byte_len, uint_t flags) { if (!(flags & STR_ASCII) && (((flags & STR_UNICODE) || (req->flags2 & FLAGS2_UNICODE_STRINGS)))) { - return cli_req_pull_ucs2(req, mem_ctx, dest, src, byte_len, flags); + return smbcli_req_pull_ucs2(req, mem_ctx, dest, src, byte_len, flags); } - return cli_req_pull_ascii(req, mem_ctx, dest, src, byte_len, flags); + return smbcli_req_pull_ascii(req, mem_ctx, dest, src, byte_len, flags); } @@ -620,7 +620,7 @@ size_t cli_req_pull_string(struct cli_request *req, TALLOC_CTX *mem_ctx, if byte_len is -1 then limit the blob only by packet size */ -DATA_BLOB cli_req_pull_blob(struct cli_request *req, TALLOC_CTX *mem_ctx, const char *src, int byte_len) +DATA_BLOB smbcli_req_pull_blob(struct smbcli_request *req, TALLOC_CTX *mem_ctx, const char *src, int byte_len) { int src_len; @@ -639,7 +639,7 @@ DATA_BLOB cli_req_pull_blob(struct cli_request *req, TALLOC_CTX *mem_ctx, const /* check that a lump of data in a request is within the bounds of the data section of the packet */ -static BOOL cli_req_data_oob(struct cli_request *req, const char *ptr, uint32_t count) +static BOOL smbcli_req_data_oob(struct smbcli_request *req, const char *ptr, uint32_t count) { /* be careful with wraparound! */ if (ptr < req->in.data || @@ -656,11 +656,11 @@ static BOOL cli_req_data_oob(struct cli_request *req, const char *ptr, uint32_t return False if any part is outside the data portion of the packet */ -BOOL cli_raw_pull_data(struct cli_request *req, const char *src, int len, char *dest) +BOOL smbcli_raw_pull_data(struct smbcli_request *req, const char *src, int len, char *dest) { if (len == 0) return True; - if (cli_req_data_oob(req, src, len)) { + if (smbcli_req_data_oob(req, src, len)) { return False; } @@ -672,7 +672,7 @@ BOOL cli_raw_pull_data(struct cli_request *req, const char *src, int len, char * /* put a NTTIME into a packet */ -void cli_push_nttime(void *base, uint16_t offset, NTTIME t) +void smbcli_push_nttime(void *base, uint16_t offset, NTTIME t) { SBVAL(base, offset, t); } @@ -680,7 +680,7 @@ void cli_push_nttime(void *base, uint16_t offset, NTTIME t) /* pull a NTTIME from a packet */ -NTTIME cli_pull_nttime(void *base, uint16_t offset) +NTTIME smbcli_pull_nttime(void *base, uint16_t offset) { NTTIME ret = BVAL(base, offset); return ret; @@ -699,7 +699,7 @@ NTTIME cli_pull_nttime(void *base, uint16_t offset) on failure zero is returned and *dest is set to NULL, otherwise the number of bytes consumed in the blob is returned */ -static size_t cli_blob_pull_ucs2(TALLOC_CTX* mem_ctx, +static size_t smbcli_blob_pull_ucs2(TALLOC_CTX* mem_ctx, DATA_BLOB *blob, const char **dest, const char *src, int byte_len, uint_t flags) { @@ -758,7 +758,7 @@ static size_t cli_blob_pull_ucs2(TALLOC_CTX* mem_ctx, on failure zero is returned and *dest is set to NULL, otherwise the number of bytes consumed in the blob is returned */ -static size_t cli_blob_pull_ascii(TALLOC_CTX *mem_ctx, +static size_t smbcli_blob_pull_ascii(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const char **dest, const char *src, int byte_len, uint_t flags) { @@ -804,7 +804,7 @@ static size_t cli_blob_pull_ascii(TALLOC_CTX *mem_ctx, on failure zero is returned and dest->s is set to NULL, otherwise the number of bytes consumed in the blob is returned */ -size_t cli_blob_pull_string(struct cli_session *session, +size_t smbcli_blob_pull_string(struct smbcli_session *session, TALLOC_CTX *mem_ctx, DATA_BLOB *blob, WIRE_STRING *dest, @@ -834,7 +834,7 @@ size_t cli_blob_pull_string(struct cli_session *session, if (flags & STR_LEN_NOTERM) { extra = 2; } - return align + extra + cli_blob_pull_ucs2(mem_ctx, blob, &dest->s, + return align + extra + smbcli_blob_pull_ucs2(mem_ctx, blob, &dest->s, blob->data+str_offset+align, dest->private_length, flags); } @@ -843,7 +843,7 @@ size_t cli_blob_pull_string(struct cli_session *session, extra = 1; } - return extra + cli_blob_pull_ascii(mem_ctx, blob, &dest->s, + return extra + smbcli_blob_pull_ascii(mem_ctx, blob, &dest->s, blob->data+str_offset, dest->private_length, flags); } @@ -859,7 +859,7 @@ size_t cli_blob_pull_string(struct cli_session *session, on failure zero is returned and dest->s is set to NULL, otherwise the number of bytes consumed in the blob is returned */ -size_t cli_blob_pull_unix_string(struct cli_session *session, +size_t smbcli_blob_pull_unix_string(struct smbcli_session *session, TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const char **dest, @@ -879,7 +879,7 @@ size_t cli_blob_pull_unix_string(struct cli_session *session, if (flags & STR_LEN_NOTERM) { extra = 2; } - return align + extra + cli_blob_pull_ucs2(mem_ctx, blob, dest, + return align + extra + smbcli_blob_pull_ucs2(mem_ctx, blob, dest, blob->data+str_offset+align, -1, flags); } @@ -888,7 +888,7 @@ size_t cli_blob_pull_unix_string(struct cli_session *session, extra = 1; } - return extra + cli_blob_pull_ascii(mem_ctx, blob, dest, + return extra + smbcli_blob_pull_ascii(mem_ctx, blob, dest, blob->data+str_offset, -1, flags); } @@ -896,7 +896,7 @@ size_t cli_blob_pull_unix_string(struct cli_session *session, /* append a string into a blob */ -size_t cli_blob_append_string(struct cli_session *session, +size_t smbcli_blob_append_string(struct smbcli_session *session, TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const char *str, uint_t flags) { diff --git a/source4/libcli/raw/rawsearch.c b/source4/libcli/raw/rawsearch.c index a4ba8e8696..67410283ed 100644 --- a/source4/libcli/raw/rawsearch.c +++ b/source4/libcli/raw/rawsearch.c @@ -23,7 +23,7 @@ /**************************************************************************** Old style search backend - process output. ****************************************************************************/ -static void smb_raw_search_backend(struct cli_request *req, +static void smb_raw_search_backend(struct smbcli_request *req, TALLOC_CTX *mem_ctx, uint16_t count, void *private, @@ -42,12 +42,12 @@ static void smb_raw_search_backend(struct cli_request *req, p = req->in.data + 3; for (i=0; i < count; i++) { - search_data.search.search_id = cli_req_pull_blob(req, mem_ctx, p, 21); + search_data.search.search_id = smbcli_req_pull_blob(req, mem_ctx, p, 21); search_data.search.attrib = CVAL(p, 21); search_data.search.write_time = raw_pull_dos_date(req->transport, p + 22); search_data.search.size = IVAL(p, 26); - cli_req_pull_ascii(req, mem_ctx, &search_data.search.name, p+30, 13, STR_ASCII); + smbcli_req_pull_ascii(req, mem_ctx, &search_data.search.name, p+30, 13, STR_ASCII); if (!callback(private, &search_data)) { break; } @@ -58,27 +58,27 @@ static void smb_raw_search_backend(struct cli_request *req, /**************************************************************************** Old style search first. ****************************************************************************/ -static NTSTATUS smb_raw_search_first_old(struct cli_tree *tree, +static NTSTATUS smb_raw_search_first_old(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_search_first *io, void *private, BOOL (*callback)(void *private, union smb_search_data *file)) { - struct cli_request *req; + struct smbcli_request *req; - req = cli_request_setup(tree, SMBsearch, 2, 0); + req = smbcli_request_setup(tree, SMBsearch, 2, 0); if (!req) { return NT_STATUS_NO_MEMORY; } SSVAL(req->out.vwv, VWV(0), io->search_first.in.max_count); SSVAL(req->out.vwv, VWV(1), io->search_first.in.search_attrib); - cli_req_append_ascii4(req, io->search_first.in.pattern, STR_TERMINATE); - cli_req_append_var_block(req, NULL, 0); + smbcli_req_append_ascii4(req, io->search_first.in.pattern, STR_TERMINATE); + smbcli_req_append_var_block(req, NULL, 0); - if (!cli_request_send(req) || - !cli_request_receive(req)) { - return cli_request_destroy(req); + if (!smbcli_request_send(req) || + !smbcli_request_receive(req)) { + return smbcli_request_destroy(req); } if (NT_STATUS_IS_OK(req->status)) { @@ -86,33 +86,33 @@ static NTSTATUS smb_raw_search_first_old(struct cli_tree *tree, smb_raw_search_backend(req, mem_ctx, io->search_first.out.count, private, callback); } - return cli_request_destroy(req); + return smbcli_request_destroy(req); } /**************************************************************************** Old style search next. ****************************************************************************/ -static NTSTATUS smb_raw_search_next_old(struct cli_tree *tree, +static NTSTATUS smb_raw_search_next_old(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_search_next *io, void *private, BOOL (*callback)(void *private, union smb_search_data *file)) { - struct cli_request *req; + struct smbcli_request *req; - req = cli_request_setup(tree, SMBsearch, 2, 0); + req = smbcli_request_setup(tree, SMBsearch, 2, 0); if (!req) { return NT_STATUS_NO_MEMORY; } SSVAL(req->out.vwv, VWV(0), io->search_next.in.max_count); SSVAL(req->out.vwv, VWV(1), io->search_next.in.search_attrib); - cli_req_append_ascii4(req, "", STR_TERMINATE); - cli_req_append_var_block(req, io->search_next.in.search_id.data, 21); + smbcli_req_append_ascii4(req, "", STR_TERMINATE); + smbcli_req_append_var_block(req, io->search_next.in.search_id.data, 21); - if (!cli_request_send(req) || - !cli_request_receive(req)) { - return cli_request_destroy(req); + if (!smbcli_request_send(req) || + !smbcli_request_receive(req)) { + return smbcli_request_destroy(req); } if (NT_STATUS_IS_OK(req->status)) { @@ -120,13 +120,13 @@ static NTSTATUS smb_raw_search_next_old(struct cli_tree *tree, smb_raw_search_backend(req, mem_ctx, io->search_next.out.count, private, callback); } - return cli_request_destroy(req); + return smbcli_request_destroy(req); } /**************************************************************************** Very raw search first - returns param/data blobs. ****************************************************************************/ -static NTSTATUS smb_raw_search_first_blob(struct cli_tree *tree, +static NTSTATUS smb_raw_search_first_blob(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, /* used to allocate output blobs */ union smb_search_first *io, uint16_t info_level, @@ -157,7 +157,7 @@ static NTSTATUS smb_raw_search_first_blob(struct cli_tree *tree, SSVAL(tp.in.params.data, 6, info_level); SIVAL(tp.in.params.data, 8, io->t2ffirst.in.storage_type); - cli_blob_append_string(tree->session, mem_ctx, &tp.in.params, + smbcli_blob_append_string(tree->session, mem_ctx, &tp.in.params, io->t2ffirst.in.pattern, STR_TERMINATE); status = smb_raw_trans2(tree, mem_ctx, &tp); @@ -178,7 +178,7 @@ static NTSTATUS smb_raw_search_first_blob(struct cli_tree *tree, Very raw search first - returns param/data blobs. Used in CIFS-on-CIFS NTVFS. ****************************************************************************/ -static NTSTATUS smb_raw_search_next_blob(struct cli_tree *tree, +static NTSTATUS smb_raw_search_next_blob(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_search_next *io, uint16_t info_level, @@ -209,7 +209,7 @@ static NTSTATUS smb_raw_search_next_blob(struct cli_tree *tree, SIVAL(tp.in.params.data, 6, io->t2fnext.in.resume_key); SSVAL(tp.in.params.data, 10, io->t2fnext.in.flags); - cli_blob_append_string(tree->session, mem_ctx, &tp.in.params, + smbcli_blob_append_string(tree->session, mem_ctx, &tp.in.params, io->t2fnext.in.last_name, STR_TERMINATE); @@ -233,7 +233,7 @@ static NTSTATUS smb_raw_search_next_blob(struct cli_tree *tree, return 0 for success with end of list return -1 for a parse error */ -static int parse_trans2_search(struct cli_tree *tree, +static int parse_trans2_search(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, enum smb_search_level level, uint16_t flags, @@ -265,7 +265,7 @@ static int parse_trans2_search(struct cli_tree *tree, data->standard.size = IVAL(blob->data, 12); data->standard.alloc_size = IVAL(blob->data, 16); data->standard.attrib = SVAL(blob->data, 20); - len = cli_blob_pull_string(tree->session, mem_ctx, blob, + len = smbcli_blob_pull_string(tree->session, mem_ctx, blob, &data->standard.name, 22, 23, STR_LEN8BIT | STR_TERMINATE | STR_LEN_NOTERM); return len + 23; @@ -288,7 +288,7 @@ static int parse_trans2_search(struct cli_tree *tree, data->ea_size.alloc_size = IVAL(blob->data, 16); data->ea_size.attrib = SVAL(blob->data, 20); data->ea_size.ea_size = IVAL(blob->data, 22); - len = cli_blob_pull_string(tree->session, mem_ctx, blob, + len = smbcli_blob_pull_string(tree->session, mem_ctx, blob, &data->ea_size.name, 26, 27, STR_LEN8BIT | STR_TERMINATE | STR_NOALIGN); return len + 27 + 1; @@ -297,14 +297,14 @@ static int parse_trans2_search(struct cli_tree *tree, if (blob->length < 65) return -1; ofs = IVAL(blob->data, 0); data->directory_info.file_index = IVAL(blob->data, 4); - data->directory_info.create_time = cli_pull_nttime(blob->data, 8); - data->directory_info.access_time = cli_pull_nttime(blob->data, 16); - data->directory_info.write_time = cli_pull_nttime(blob->data, 24); - data->directory_info.change_time = cli_pull_nttime(blob->data, 32); + data->directory_info.create_time = smbcli_pull_nttime(blob->data, 8); + data->directory_info.access_time = smbcli_pull_nttime(blob->data, 16); + data->directory_info.write_time = smbcli_pull_nttime(blob->data, 24); + data->directory_info.change_time = smbcli_pull_nttime(blob->data, 32); data->directory_info.size = BVAL(blob->data, 40); data->directory_info.alloc_size = BVAL(blob->data, 48); data->directory_info.attrib = IVAL(blob->data, 56); - len = cli_blob_pull_string(tree->session, mem_ctx, blob, + len = smbcli_blob_pull_string(tree->session, mem_ctx, blob, &data->directory_info.name, 60, 64, 0); if (ofs != 0 && ofs < 64+len) { @@ -316,15 +316,15 @@ static int parse_trans2_search(struct cli_tree *tree, if (blob->length < 69) return -1; ofs = IVAL(blob->data, 0); data->full_directory_info.file_index = IVAL(blob->data, 4); - data->full_directory_info.create_time = cli_pull_nttime(blob->data, 8); - data->full_directory_info.access_time = cli_pull_nttime(blob->data, 16); - data->full_directory_info.write_time = cli_pull_nttime(blob->data, 24); - data->full_directory_info.change_time = cli_pull_nttime(blob->data, 32); + data->full_directory_info.create_time = smbcli_pull_nttime(blob->data, 8); + data->full_directory_info.access_time = smbcli_pull_nttime(blob->data, 16); + data->full_directory_info.write_time = smbcli_pull_nttime(blob->data, 24); + data->full_directory_info.change_time = smbcli_pull_nttime(blob->data, 32); data->full_directory_info.size = BVAL(blob->data, 40); data->full_directory_info.alloc_size = BVAL(blob->data, 48); data->full_directory_info.attrib = IVAL(blob->data, 56); data->full_directory_info.ea_size = IVAL(blob->data, 64); - len = cli_blob_pull_string(tree->session, mem_ctx, blob, + len = smbcli_blob_pull_string(tree->session, mem_ctx, blob, &data->full_directory_info.name, 60, 68, 0); if (ofs != 0 && ofs < 68+len) { @@ -336,7 +336,7 @@ static int parse_trans2_search(struct cli_tree *tree, if (blob->length < 13) return -1; ofs = IVAL(blob->data, 0); data->name_info.file_index = IVAL(blob->data, 4); - len = cli_blob_pull_string(tree->session, mem_ctx, blob, + len = smbcli_blob_pull_string(tree->session, mem_ctx, blob, &data->name_info.name, 8, 12, 0); if (ofs != 0 && ofs < 12+len) { @@ -349,18 +349,18 @@ static int parse_trans2_search(struct cli_tree *tree, if (blob->length < 95) return -1; ofs = IVAL(blob->data, 0); data->both_directory_info.file_index = IVAL(blob->data, 4); - data->both_directory_info.create_time = cli_pull_nttime(blob->data, 8); - data->both_directory_info.access_time = cli_pull_nttime(blob->data, 16); - data->both_directory_info.write_time = cli_pull_nttime(blob->data, 24); - data->both_directory_info.change_time = cli_pull_nttime(blob->data, 32); + data->both_directory_info.create_time = smbcli_pull_nttime(blob->data, 8); + data->both_directory_info.access_time = smbcli_pull_nttime(blob->data, 16); + data->both_directory_info.write_time = smbcli_pull_nttime(blob->data, 24); + data->both_directory_info.change_time = smbcli_pull_nttime(blob->data, 32); data->both_directory_info.size = BVAL(blob->data, 40); data->both_directory_info.alloc_size = BVAL(blob->data, 48); data->both_directory_info.attrib = IVAL(blob->data, 56); data->both_directory_info.ea_size = IVAL(blob->data, 64); - cli_blob_pull_string(tree->session, mem_ctx, blob, + smbcli_blob_pull_string(tree->session, mem_ctx, blob, &data->both_directory_info.short_name, 68, 70, STR_LEN8BIT | STR_UNICODE); - len = cli_blob_pull_string(tree->session, mem_ctx, blob, + len = smbcli_blob_pull_string(tree->session, mem_ctx, blob, &data->both_directory_info.name, 60, 94, 0); if (ofs != 0 && ofs < 94+len) { @@ -373,16 +373,16 @@ static int parse_trans2_search(struct cli_tree *tree, if (blob->length < 81) return -1; ofs = IVAL(blob->data, 0); data->id_full_directory_info.file_index = IVAL(blob->data, 4); - data->id_full_directory_info.create_time = cli_pull_nttime(blob->data, 8); - data->id_full_directory_info.access_time = cli_pull_nttime(blob->data, 16); - data->id_full_directory_info.write_time = cli_pull_nttime(blob->data, 24); - data->id_full_directory_info.change_time = cli_pull_nttime(blob->data, 32); + data->id_full_directory_info.create_time = smbcli_pull_nttime(blob->data, 8); + data->id_full_directory_info.access_time = smbcli_pull_nttime(blob->data, 16); + data->id_full_directory_info.write_time = smbcli_pull_nttime(blob->data, 24); + data->id_full_directory_info.change_time = smbcli_pull_nttime(blob->data, 32); data->id_full_directory_info.size = BVAL(blob->data, 40); data->id_full_directory_info.alloc_size = BVAL(blob->data, 48); data->id_full_directory_info.attrib = IVAL(blob->data, 56); data->id_full_directory_info.ea_size = IVAL(blob->data, 64); data->id_full_directory_info.file_id = BVAL(blob->data, 72); - len = cli_blob_pull_string(tree->session, mem_ctx, blob, + len = smbcli_blob_pull_string(tree->session, mem_ctx, blob, &data->id_full_directory_info.name, 60, 80, 0); if (ofs != 0 && ofs < 80+len) { @@ -394,19 +394,19 @@ static int parse_trans2_search(struct cli_tree *tree, if (blob->length < 105) return -1; ofs = IVAL(blob->data, 0); data->id_both_directory_info.file_index = IVAL(blob->data, 4); - data->id_both_directory_info.create_time = cli_pull_nttime(blob->data, 8); - data->id_both_directory_info.access_time = cli_pull_nttime(blob->data, 16); - data->id_both_directory_info.write_time = cli_pull_nttime(blob->data, 24); - data->id_both_directory_info.change_time = cli_pull_nttime(blob->data, 32); + data->id_both_directory_info.create_time = smbcli_pull_nttime(blob->data, 8); + data->id_both_directory_info.access_time = smbcli_pull_nttime(blob->data, 16); + data->id_both_directory_info.write_time = smbcli_pull_nttime(blob->data, 24); + data->id_both_directory_info.change_time = smbcli_pull_nttime(blob->data, 32); data->id_both_directory_info.size = BVAL(blob->data, 40); data->id_both_directory_info.alloc_size = BVAL(blob->data, 48); data->id_both_directory_info.attrib = SVAL(blob->data, 56); data->id_both_directory_info.ea_size = IVAL(blob->data, 64); - cli_blob_pull_string(tree->session, mem_ctx, blob, + smbcli_blob_pull_string(tree->session, mem_ctx, blob, &data->id_both_directory_info.short_name, 68, 70, STR_LEN8BIT | STR_UNICODE); data->id_both_directory_info.file_id = BVAL(blob->data, 96); - len = cli_blob_pull_string(tree->session, mem_ctx, blob, + len = smbcli_blob_pull_string(tree->session, mem_ctx, blob, &data->id_both_directory_info.name, 60, 104, 0); if (ofs != 0 && ofs < 104+len) { @@ -420,9 +420,9 @@ static int parse_trans2_search(struct cli_tree *tree, data->unix_info.file_index = IVAL(blob->data, 4); data->unix_info.size = BVAL(blob->data, 8); data->unix_info.alloc_size = BVAL(blob->data, 16); - data->unix_info.status_change_time = cli_pull_nttime(blob->data, 24); - data->unix_info.access_time = cli_pull_nttime(blob->data, 32); - data->unix_info.change_time = cli_pull_nttime(blob->data, 40); + data->unix_info.status_change_time = smbcli_pull_nttime(blob->data, 24); + data->unix_info.access_time = smbcli_pull_nttime(blob->data, 32); + data->unix_info.change_time = smbcli_pull_nttime(blob->data, 40); data->unix_info.uid = IVAL(blob->data, 48); data->unix_info.gid = IVAL(blob->data, 56); data->unix_info.file_type = IVAL(blob->data, 64); @@ -432,7 +432,7 @@ static int parse_trans2_search(struct cli_tree *tree, data->unix_info.permissions = IVAL(blob->data, 92); data->unix_info.nlink = IVAL(blob->data, 100); /* There is no length field for this name but we know it's null terminated. */ - len = cli_blob_pull_unix_string(tree->session, mem_ctx, blob, + len = smbcli_blob_pull_unix_string(tree->session, mem_ctx, blob, &data->unix_info.name, 108, 0); if (ofs != 0 && ofs < 108+len) { return -1; @@ -447,7 +447,7 @@ static int parse_trans2_search(struct cli_tree *tree, /**************************************************************************** Trans2 search backend - process output. ****************************************************************************/ -static NTSTATUS smb_raw_t2search_backend(struct cli_tree *tree, +static NTSTATUS smb_raw_t2search_backend(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, enum smb_search_level level, uint16_t flags, @@ -490,7 +490,7 @@ static NTSTATUS smb_raw_t2search_backend(struct cli_tree *tree, /* Implements trans2findfirst2 and old search */ -NTSTATUS smb_raw_search_first(struct cli_tree *tree, +NTSTATUS smb_raw_search_first(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_search_first *io, void *private, BOOL (*callback)(void *private, union smb_search_data *file)) @@ -534,7 +534,7 @@ NTSTATUS smb_raw_search_first(struct cli_tree *tree, /* Implements trans2findnext2 and old smbsearch */ -NTSTATUS smb_raw_search_next(struct cli_tree *tree, +NTSTATUS smb_raw_search_next(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_search_next *io, void *private, BOOL (*callback)(void *private, union smb_search_data *file)) @@ -578,21 +578,21 @@ NTSTATUS smb_raw_search_next(struct cli_tree *tree, /* Implements trans2findclose2 */ -NTSTATUS smb_raw_search_close(struct cli_tree *tree, +NTSTATUS smb_raw_search_close(struct smbcli_tree *tree, union smb_search_close *io) { - struct cli_request *req; + struct smbcli_request *req; - req = cli_request_setup(tree, SMBfindclose, 1, 0); + req = smbcli_request_setup(tree, SMBfindclose, 1, 0); if (!req) { return NT_STATUS_NO_MEMORY; } SSVAL(req->out.vwv, VWV(0), io->findclose.in.handle); - if (cli_request_send(req)) { - cli_request_receive(req); + if (smbcli_request_send(req)) { + smbcli_request_receive(req); } - return cli_request_destroy(req); + return smbcli_request_destroy(req); } diff --git a/source4/libcli/raw/rawsetfileinfo.c b/source4/libcli/raw/rawsetfileinfo.c index 3dcda401f5..b1667db50f 100644 --- a/source4/libcli/raw/rawsetfileinfo.c +++ b/source4/libcli/raw/rawsetfileinfo.c @@ -24,7 +24,7 @@ /**************************************************************************** Handle setfileinfo/setpathinfo trans2 backend. ****************************************************************************/ -static BOOL smb_raw_setinfo_backend(struct cli_tree *tree, +static BOOL smb_raw_setinfo_backend(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_setfileinfo *parms, DATA_BLOB *blob) @@ -61,10 +61,10 @@ static BOOL smb_raw_setinfo_backend(struct cli_tree *tree, case RAW_SFILEINFO_BASIC_INFO: case RAW_SFILEINFO_BASIC_INFORMATION: NEED_BLOB(40); - cli_push_nttime(blob->data, 0, parms->basic_info.in.create_time); - cli_push_nttime(blob->data, 8, parms->basic_info.in.access_time); - cli_push_nttime(blob->data, 16, parms->basic_info.in.write_time); - cli_push_nttime(blob->data, 24, parms->basic_info.in.change_time); + smbcli_push_nttime(blob->data, 0, parms->basic_info.in.create_time); + smbcli_push_nttime(blob->data, 8, parms->basic_info.in.access_time); + smbcli_push_nttime(blob->data, 16, parms->basic_info.in.write_time); + smbcli_push_nttime(blob->data, 24, parms->basic_info.in.change_time); SIVAL(blob->data, 32, parms->basic_info.in.attrib); SIVAL(blob->data, 36, 0); /* padding */ return True; @@ -73,9 +73,9 @@ static BOOL smb_raw_setinfo_backend(struct cli_tree *tree, NEED_BLOB(92); SBVAL(blob->data, 0, parms->unix_basic.in.end_of_file); SBVAL(blob->data, 8, parms->unix_basic.in.num_bytes); - cli_push_nttime(blob->data, 16, parms->unix_basic.in.status_change_time); - cli_push_nttime(blob->data, 24, parms->unix_basic.in.access_time); - cli_push_nttime(blob->data, 32, parms->unix_basic.in.change_time); + smbcli_push_nttime(blob->data, 16, parms->unix_basic.in.status_change_time); + smbcli_push_nttime(blob->data, 24, parms->unix_basic.in.access_time); + smbcli_push_nttime(blob->data, 32, parms->unix_basic.in.change_time); SBVAL(blob->data, 40, parms->unix_basic.in.uid); SBVAL(blob->data, 48, parms->unix_basic.in.gid); SIVAL(blob->data, 56, parms->unix_basic.in.file_type); @@ -107,7 +107,7 @@ static BOOL smb_raw_setinfo_backend(struct cli_tree *tree, NEED_BLOB(12); SIVAL(blob->data, 0, parms->rename_information.in.overwrite); SIVAL(blob->data, 4, parms->rename_information.in.root_fid); - len = cli_blob_append_string(tree->session, mem_ctx, blob, + len = smbcli_blob_append_string(tree->session, mem_ctx, blob, parms->rename_information.in.new_name, STR_UNICODE|STR_TERMINATE); SIVAL(blob->data, 8, len - 2); @@ -130,7 +130,7 @@ static BOOL smb_raw_setinfo_backend(struct cli_tree *tree, /**************************************************************************** Very raw set file info - takes data blob (async send) ****************************************************************************/ -static struct cli_request *smb_raw_setfileinfo_blob_send(struct cli_tree *tree, +static struct smbcli_request *smb_raw_setfileinfo_blob_send(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, uint16_t fnum, uint16_t info_level, @@ -163,7 +163,7 @@ static struct cli_request *smb_raw_setfileinfo_blob_send(struct cli_tree *tree, /**************************************************************************** Very raw set path info - takes data blob ****************************************************************************/ -static struct cli_request *smb_raw_setpathinfo_blob_send(struct cli_tree *tree, +static struct smbcli_request *smb_raw_setpathinfo_blob_send(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, const char *fname, uint16_t info_level, @@ -186,7 +186,7 @@ static struct cli_request *smb_raw_setpathinfo_blob_send(struct cli_tree *tree, } SSVAL(tp.in.params.data, 0, info_level); SSVAL(tp.in.params.data, 2, 0); - cli_blob_append_string(tree->session, mem_ctx, + smbcli_blob_append_string(tree->session, mem_ctx, &tp.in.params, fname, STR_TERMINATE); @@ -198,23 +198,23 @@ static struct cli_request *smb_raw_setpathinfo_blob_send(struct cli_tree *tree, /**************************************************************************** Handle setattr (async send) ****************************************************************************/ -static struct cli_request *smb_raw_setattr_send(struct cli_tree *tree, +static struct smbcli_request *smb_raw_setattr_send(struct smbcli_tree *tree, union smb_setfileinfo *parms) { - struct cli_request *req; + struct smbcli_request *req; - req = cli_request_setup(tree, SMBsetatr, 8, 0); + req = smbcli_request_setup(tree, SMBsetatr, 8, 0); if (!req) return NULL; SSVAL(req->out.vwv, VWV(0), parms->setattr.in.attrib); raw_push_dos_date3(tree->session->transport, req->out.vwv, VWV(1), parms->setattr.in.write_time); memset(req->out.vwv + VWV(3), 0, 10); /* reserved */ - cli_req_append_ascii4(req, parms->setattr.file.fname, STR_TERMINATE); - cli_req_append_ascii4(req, "", STR_TERMINATE); + smbcli_req_append_ascii4(req, parms->setattr.file.fname, STR_TERMINATE); + smbcli_req_append_ascii4(req, "", STR_TERMINATE); - if (!cli_request_send(req)) { - cli_request_destroy(req); + if (!smbcli_request_send(req)) { + smbcli_request_destroy(req); return NULL; } @@ -224,12 +224,12 @@ static struct cli_request *smb_raw_setattr_send(struct cli_tree *tree, /**************************************************************************** Handle setattrE. (async send) ****************************************************************************/ -static struct cli_request *smb_raw_setattrE_send(struct cli_tree *tree, +static struct smbcli_request *smb_raw_setattrE_send(struct smbcli_tree *tree, union smb_setfileinfo *parms) { - struct cli_request *req; + struct smbcli_request *req; - req = cli_request_setup(tree, SMBsetattrE, 7, 0); + req = smbcli_request_setup(tree, SMBsetattrE, 7, 0); if (!req) return NULL; SSVAL(req->out.vwv, VWV(0), parms->setattre.file.fnum); @@ -240,8 +240,8 @@ static struct cli_request *smb_raw_setattrE_send(struct cli_tree *tree, raw_push_dos_date2(tree->session->transport, req->out.vwv, VWV(5), parms->setattre.in.write_time); - if (!cli_request_send(req)) { - cli_request_destroy(req); + if (!smbcli_request_send(req)) { + smbcli_request_destroy(req); return NULL; } @@ -251,12 +251,12 @@ static struct cli_request *smb_raw_setattrE_send(struct cli_tree *tree, /**************************************************************************** Set file info (async send) ****************************************************************************/ -struct cli_request *smb_raw_setfileinfo_send(struct cli_tree *tree, +struct smbcli_request *smb_raw_setfileinfo_send(struct smbcli_tree *tree, union smb_setfileinfo *parms) { DATA_BLOB blob; TALLOC_CTX *mem_ctx; - struct cli_request *req; + struct smbcli_request *req; if (parms->generic.level == RAW_SFILEINFO_SETATTRE) { return smb_raw_setattrE_send(tree, parms); @@ -287,23 +287,23 @@ struct cli_request *smb_raw_setfileinfo_send(struct cli_tree *tree, /**************************************************************************** Set file info (async send) ****************************************************************************/ -NTSTATUS smb_raw_setfileinfo(struct cli_tree *tree, +NTSTATUS smb_raw_setfileinfo(struct smbcli_tree *tree, union smb_setfileinfo *parms) { - struct cli_request *req = smb_raw_setfileinfo_send(tree, parms); - return cli_request_simple_recv(req); + struct smbcli_request *req = smb_raw_setfileinfo_send(tree, parms); + return smbcli_request_simple_recv(req); } /**************************************************************************** Set path info (async send) ****************************************************************************/ -struct cli_request *smb_raw_setpathinfo_send(struct cli_tree *tree, +struct smbcli_request *smb_raw_setpathinfo_send(struct smbcli_tree *tree, union smb_setfileinfo *parms) { DATA_BLOB blob; TALLOC_CTX *mem_ctx; - struct cli_request *req; + struct smbcli_request *req; if (parms->generic.level == RAW_SFILEINFO_SETATTR) { return smb_raw_setattr_send(tree, parms); @@ -334,9 +334,9 @@ struct cli_request *smb_raw_setpathinfo_send(struct cli_tree *tree, /**************************************************************************** Set path info (sync interface) ****************************************************************************/ -NTSTATUS smb_raw_setpathinfo(struct cli_tree *tree, +NTSTATUS smb_raw_setpathinfo(struct smbcli_tree *tree, union smb_setfileinfo *parms) { - struct cli_request *req = smb_raw_setpathinfo_send(tree, parms); - return cli_request_simple_recv(req); + struct smbcli_request *req = smb_raw_setpathinfo_send(tree, parms); + return smbcli_request_simple_recv(req); } diff --git a/source4/libcli/raw/rawtrans.c b/source4/libcli/raw/rawtrans.c index 5dde753368..0c39abe880 100644 --- a/source4/libcli/raw/rawtrans.c +++ b/source4/libcli/raw/rawtrans.c @@ -25,7 +25,7 @@ /* check out of bounds for incoming data */ -static BOOL raw_trans_oob(struct cli_request *req, +static BOOL raw_trans_oob(struct smbcli_request *req, uint_t offset, uint_t count) { char *ptr; @@ -49,7 +49,7 @@ static BOOL raw_trans_oob(struct cli_request *req, /**************************************************************************** receive a SMB trans or trans2 response allocating the necessary memory ****************************************************************************/ -NTSTATUS smb_raw_trans2_recv(struct cli_request *req, +NTSTATUS smb_raw_trans2_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, struct smb_trans2 *parms) { @@ -63,8 +63,8 @@ NTSTATUS smb_raw_trans2_recv(struct cli_request *req, parms->out.params.length = 0; parms->out.params.data = NULL; - if (!cli_request_receive(req)) { - return cli_request_destroy(req); + if (!smbcli_request_receive(req)) { + return smbcli_request_destroy(req); } /* @@ -73,10 +73,10 @@ NTSTATUS smb_raw_trans2_recv(struct cli_request *req, * be treated as such. */ if (NT_STATUS_IS_ERR(req->status)) { - return cli_request_destroy(req); + return smbcli_request_destroy(req); } - CLI_CHECK_MIN_WCT(req, 10); + SMBCLI_CHECK_MIN_WCT(req, 10); /* parse out the lengths */ total_data = SVAL(req->in.vwv, VWV(1)); @@ -88,7 +88,7 @@ NTSTATUS smb_raw_trans2_recv(struct cli_request *req, if (!tdata) { DEBUG(0,("smb_raw_receive_trans: failed to enlarge data buffer to %d bytes\n", total_data)); req->status = NT_STATUS_NO_MEMORY; - return cli_request_destroy(req); + return smbcli_request_destroy(req); } parms->out.data.data = tdata; } @@ -98,20 +98,20 @@ NTSTATUS smb_raw_trans2_recv(struct cli_request *req, if (!tparam) { DEBUG(0,("smb_raw_receive_trans: failed to enlarge param buffer to %d bytes\n", total_param)); req->status = NT_STATUS_NO_MEMORY; - return cli_request_destroy(req); + return smbcli_request_destroy(req); } parms->out.params.data = tparam; } parms->out.setup_count = SVAL(req->in.vwv, VWV(9)); - CLI_CHECK_WCT(req, 10 + parms->out.setup_count); + SMBCLI_CHECK_WCT(req, 10 + parms->out.setup_count); if (parms->out.setup_count > 0) { int i; parms->out.setup = talloc(mem_ctx, 2 * parms->out.setup_count); if (!parms->out.setup) { req->status = NT_STATUS_NO_MEMORY; - return cli_request_destroy(req); + return smbcli_request_destroy(req); } for (i=0;iout.setup_count;i++) { parms->out.setup[i] = SVAL(req->in.vwv, VWV(10+i)); @@ -132,7 +132,7 @@ NTSTATUS smb_raw_trans2_recv(struct cli_request *req, /* they must *only* shrink */ DEBUG(1,("smb_raw_receive_trans: data/params expanded!\n")); req->status = NT_STATUS_BUFFER_TOO_SMALL; - return cli_request_destroy(req); + return smbcli_request_destroy(req); } total_data = total_data2; @@ -151,7 +151,7 @@ NTSTATUS smb_raw_trans2_recv(struct cli_request *req, param_count + param_disp > total_param) { DEBUG(1,("smb_raw_receive_trans: Buffer overflow\n")); req->status = NT_STATUS_BUFFER_TOO_SMALL; - return cli_request_destroy(req); + return smbcli_request_destroy(req); } /* check the server isn't being nasty */ @@ -159,7 +159,7 @@ NTSTATUS smb_raw_trans2_recv(struct cli_request *req, raw_trans_oob(req, data_ofs, data_count)) { DEBUG(1,("smb_raw_receive_trans: out of bounds parameters!\n")); req->status = NT_STATUS_BUFFER_TOO_SMALL; - return cli_request_destroy(req); + return smbcli_request_destroy(req); } if (data_count) { @@ -180,17 +180,17 @@ NTSTATUS smb_raw_trans2_recv(struct cli_request *req, if (total_data <= parms->out.data.length && total_param <= parms->out.params.length) break; - if (!cli_request_receive_more(req)) { + if (!smbcli_request_receive_more(req)) { req->status = NT_STATUS_UNSUCCESSFUL; - return cli_request_destroy(req); + return smbcli_request_destroy(req); } } failed: - return cli_request_destroy(req); + return smbcli_request_destroy(req); } -NTSTATUS smb_raw_trans_recv(struct cli_request *req, +NTSTATUS smb_raw_trans_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, struct smb_trans2 *parms) { @@ -201,12 +201,12 @@ NTSTATUS smb_raw_trans_recv(struct cli_request *req, trans/trans2 raw async interface - only BLOBs used in this interface. note that this doesn't yet support multi-part requests ****************************************************************************/ -struct cli_request *smb_raw_trans_send_backend(struct cli_tree *tree, +struct smbcli_request *smb_raw_trans_send_backend(struct smbcli_tree *tree, struct smb_trans2 *parms, uint8_t command) { int wct = 14 + parms->in.setup_count; - struct cli_request *req; + struct smbcli_request *req; char *outdata,*outparam; int i; int padding; @@ -217,7 +217,7 @@ struct cli_request *smb_raw_trans_send_backend(struct cli_tree *tree, else padding = 3; - req = cli_request_setup(tree, command, wct, padding); + req = smbcli_request_setup(tree, command, wct, padding); if (!req) { return NULL; } @@ -230,7 +230,7 @@ struct cli_request *smb_raw_trans_send_backend(struct cli_tree *tree, memset(req->out.data, 0, padding); if (command == SMBtrans && parms->in.trans_name) { - namelen = cli_req_append_string(req, parms->in.trans_name, + namelen = smbcli_req_append_string(req, parms->in.trans_name, STR_TERMINATE); } @@ -252,14 +252,14 @@ struct cli_request *smb_raw_trans_send_backend(struct cli_tree *tree, SSVAL(req->out.vwv,VWV(14)+i*2,parms->in.setup[i]); } if (parms->in.params.data) { - cli_req_append_blob(req, &parms->in.params); + smbcli_req_append_blob(req, &parms->in.params); } if (parms->in.data.data) { - cli_req_append_blob(req, &parms->in.data); + smbcli_req_append_blob(req, &parms->in.data); } - if (!cli_request_send(req)) { - cli_request_destroy(req); + if (!smbcli_request_send(req)) { + smbcli_request_destroy(req); return NULL; } @@ -271,13 +271,13 @@ struct cli_request *smb_raw_trans_send_backend(struct cli_tree *tree, note that this doesn't yet support multi-part requests ****************************************************************************/ -struct cli_request *smb_raw_trans_send(struct cli_tree *tree, +struct smbcli_request *smb_raw_trans_send(struct smbcli_tree *tree, struct smb_trans2 *parms) { return smb_raw_trans_send_backend(tree, parms, SMBtrans); } -struct cli_request *smb_raw_trans2_send(struct cli_tree *tree, +struct smbcli_request *smb_raw_trans2_send(struct smbcli_tree *tree, struct smb_trans2 *parms) { return smb_raw_trans_send_backend(tree, parms, SMBtrans2); @@ -286,11 +286,11 @@ struct cli_request *smb_raw_trans2_send(struct cli_tree *tree, /* trans2 synchronous blob interface */ -NTSTATUS smb_raw_trans2(struct cli_tree *tree, +NTSTATUS smb_raw_trans2(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, struct smb_trans2 *parms) { - struct cli_request *req; + struct smbcli_request *req; req = smb_raw_trans2_send(tree, parms); if (!req) return NT_STATUS_UNSUCCESSFUL; return smb_raw_trans2_recv(req, mem_ctx, parms); @@ -300,11 +300,11 @@ NTSTATUS smb_raw_trans2(struct cli_tree *tree, /* trans synchronous blob interface */ -NTSTATUS smb_raw_trans(struct cli_tree *tree, +NTSTATUS smb_raw_trans(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, struct smb_trans2 *parms) { - struct cli_request *req; + struct smbcli_request *req; req = smb_raw_trans_send(tree, parms); if (!req) return NT_STATUS_UNSUCCESSFUL; return smb_raw_trans_recv(req, mem_ctx, parms); @@ -313,16 +313,16 @@ NTSTATUS smb_raw_trans(struct cli_tree *tree, /**************************************************************************** receive a SMB nttrans response allocating the necessary memory ****************************************************************************/ -NTSTATUS smb_raw_nttrans_recv(struct cli_request *req, +NTSTATUS smb_raw_nttrans_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, struct smb_nttrans *parms) { uint32_t total_data, recvd_data=0; uint32_t total_param, recvd_param=0; - if (!cli_request_receive(req) || - cli_request_is_error(req)) { - return cli_request_destroy(req); + if (!smbcli_request_receive(req) || + smbcli_request_is_error(req)) { + return smbcli_request_destroy(req); } /* sanity check */ @@ -331,10 +331,10 @@ NTSTATUS smb_raw_nttrans_recv(struct cli_request *req, "SMBnttrans", CVAL(req->in.hdr,HDR_COM))); req->status = NT_STATUS_UNSUCCESSFUL; - return cli_request_destroy(req); + return smbcli_request_destroy(req); } - CLI_CHECK_MIN_WCT(req, 18); + SMBCLI_CHECK_MIN_WCT(req, 18); /* parse out the lengths */ total_param = IVAL(req->in.vwv, 3); @@ -346,18 +346,18 @@ NTSTATUS smb_raw_nttrans_recv(struct cli_request *req, if (parms->out.data.length != total_data || parms->out.params.length != total_param) { req->status = NT_STATUS_NO_MEMORY; - return cli_request_destroy(req); + return smbcli_request_destroy(req); } parms->out.setup_count = CVAL(req->in.vwv, 35); - CLI_CHECK_WCT(req, 18 + parms->out.setup_count); + SMBCLI_CHECK_WCT(req, 18 + parms->out.setup_count); if (parms->out.setup_count > 0) { int i; parms->out.setup = talloc(mem_ctx, 2 * parms->out.setup_count); if (!parms->out.setup) { req->status = NT_STATUS_NO_MEMORY; - return cli_request_destroy(req); + return smbcli_request_destroy(req); } for (i=0;iout.setup_count;i++) { parms->out.setup[i] = SVAL(req->in.vwv, VWV(18+i)); @@ -379,7 +379,7 @@ NTSTATUS smb_raw_nttrans_recv(struct cli_request *req, /* they must *only* shrink */ DEBUG(1,("smb_raw_receive_nttrans: data/params expanded!\n")); req->status = NT_STATUS_BUFFER_TOO_SMALL; - return cli_request_destroy(req); + return smbcli_request_destroy(req); } total_data = total_data2; @@ -400,7 +400,7 @@ NTSTATUS smb_raw_nttrans_recv(struct cli_request *req, param_count + param_disp > total_param) { DEBUG(1,("smb_raw_receive_nttrans: Buffer overflow\n")); req->status = NT_STATUS_BUFFER_TOO_SMALL; - return cli_request_destroy(req); + return smbcli_request_destroy(req); } /* check the server isn't being nasty */ @@ -408,7 +408,7 @@ NTSTATUS smb_raw_nttrans_recv(struct cli_request *req, raw_trans_oob(req, data_ofs, data_count)) { DEBUG(1,("smb_raw_receive_nttrans: out of bounds parameters!\n")); req->status = NT_STATUS_BUFFER_TOO_SMALL; - return cli_request_destroy(req); + return smbcli_request_destroy(req); } if (data_count) { @@ -431,9 +431,9 @@ NTSTATUS smb_raw_nttrans_recv(struct cli_request *req, break; } - if (!cli_request_receive(req) || - cli_request_is_error(req)) { - return cli_request_destroy(req); + if (!smbcli_request_receive(req) || + smbcli_request_is_error(req)) { + return smbcli_request_destroy(req); } /* sanity check */ @@ -441,12 +441,12 @@ NTSTATUS smb_raw_nttrans_recv(struct cli_request *req, DEBUG(0,("smb_raw_receive_nttrans: Expected nttranss, got command 0x%02x\n", CVAL(req->in.hdr, HDR_COM))); req->status = NT_STATUS_UNSUCCESSFUL; - return cli_request_destroy(req); + return smbcli_request_destroy(req); } } failed: - return cli_request_destroy(req); + return smbcli_request_destroy(req); } @@ -454,10 +454,10 @@ failed: nttrans raw - only BLOBs used in this interface. at the moment we only handle a single primary request ****************************************************************************/ -struct cli_request *smb_raw_nttrans_send(struct cli_tree *tree, +struct smbcli_request *smb_raw_nttrans_send(struct smbcli_tree *tree, struct smb_nttrans *parms) { - struct cli_request *req; + struct smbcli_request *req; char *outdata, *outparam; int i; int align = 0; @@ -467,7 +467,7 @@ struct cli_request *smb_raw_nttrans_send(struct cli_tree *tree, align = 3; } - req = cli_request_setup(tree, SMBnttrans, + req = smbcli_request_setup(tree, SMBnttrans, 19 + parms->in.setup_count, align + parms->in.params.length + @@ -502,8 +502,8 @@ struct cli_request *smb_raw_nttrans_send(struct cli_tree *tree, memcpy(outparam, parms->in.data.data, parms->in.data.length); } - if (!cli_request_send(req)) { - cli_request_destroy(req); + if (!smbcli_request_send(req)) { + smbcli_request_destroy(req); return NULL; } @@ -514,11 +514,11 @@ struct cli_request *smb_raw_nttrans_send(struct cli_tree *tree, /**************************************************************************** receive a SMB nttrans response allocating the necessary memory ****************************************************************************/ -NTSTATUS smb_raw_nttrans(struct cli_tree *tree, +NTSTATUS smb_raw_nttrans(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, struct smb_nttrans *parms) { - struct cli_request *req; + struct smbcli_request *req; req = smb_raw_nttrans_send(tree, parms); if (!req) { diff --git a/source4/libcli/raw/smb_signing.c b/source4/libcli/raw/smb_signing.c index 9c02fe50ec..ddde58fd88 100644 --- a/source4/libcli/raw/smb_signing.c +++ b/source4/libcli/raw/smb_signing.c @@ -30,7 +30,7 @@ struct smb_basic_signing_context { /*********************************************************** SMB signing - Common code before we set a new signing implementation ************************************************************/ -static BOOL set_smb_signing_common(struct cli_transport *transport) +static BOOL set_smb_signing_common(struct smbcli_transport *transport) { if (!(transport->negotiate.sec_mode & (NEGOTIATE_SECURITY_SIGNATURES_REQUIRED|NEGOTIATE_SECURITY_SIGNATURES_ENABLED))) { @@ -58,7 +58,7 @@ static BOOL set_smb_signing_common(struct cli_transport *transport) /*********************************************************** SMB signing - Common code for 'real' implementations ************************************************************/ -static BOOL set_smb_signing_real_common(struct cli_transport *transport) +static BOOL set_smb_signing_real_common(struct smbcli_transport *transport) { if (transport->negotiate.sign_info.mandatory_signing) { DEBUG(5, ("Mandatory SMB signing enabled!\n")); @@ -77,7 +77,7 @@ static void mark_packet_signed(struct request_buffer *out) SSVAL(out->hdr, HDR_FLG2, flags2); } -static BOOL signing_good(struct cli_request *req, unsigned int seq, BOOL good) +static BOOL signing_good(struct smbcli_request *req, unsigned int seq, BOOL good) { if (good) { if (!req->transport->negotiate.sign_info.doing_signing) { @@ -96,7 +96,7 @@ static BOOL signing_good(struct cli_request *req, unsigned int seq, BOOL good) req->transport->negotiate.sign_info.doing_signing = False; if (req->transport->negotiate.sign_info.free_signing_context) req->transport->negotiate.sign_info.free_signing_context(req->transport); - cli_null_set_signing(req->transport); + smbcli_null_set_signing(req->transport); return True; } else { /* bad packet after signing started - fail and disconnect. */ @@ -206,7 +206,7 @@ BOOL check_signed_incoming_message(struct request_buffer *in, DATA_BLOB *mac_key /*********************************************************** SMB signing - Simple implementation - calculate a MAC to send. ************************************************************/ -static void cli_request_simple_sign_outgoing_message(struct cli_request *req) +static void smbcli_request_simple_sign_outgoing_message(struct smbcli_request *req) { struct smb_basic_signing_context *data = req->transport->negotiate.sign_info.signing_context; @@ -233,7 +233,7 @@ static void cli_request_simple_sign_outgoing_message(struct cli_request *req) /*********************************************************** SMB signing - Simple implementation - check a MAC sent by server. ************************************************************/ -static BOOL cli_request_simple_check_incoming_message(struct cli_request *req) +static BOOL smbcli_request_simple_check_incoming_message(struct smbcli_request *req) { struct smb_basic_signing_context *data = req->transport->negotiate.sign_info.signing_context; @@ -249,7 +249,7 @@ static BOOL cli_request_simple_check_incoming_message(struct cli_request *req) /*********************************************************** SMB signing - Simple implementation - free signing context ************************************************************/ -static void cli_transport_simple_free_signing_context(struct cli_transport *transport) +static void smbcli_transport_simple_free_signing_context(struct smbcli_transport *transport) { struct smb_basic_signing_context *data = transport->negotiate.sign_info.signing_context; @@ -263,7 +263,7 @@ static void cli_transport_simple_free_signing_context(struct cli_transport *tran /*********************************************************** SMB signing - Simple implementation - setup the MAC key. ************************************************************/ -BOOL cli_transport_simple_set_signing(struct cli_transport *transport, +BOOL smbcli_transport_simple_set_signing(struct smbcli_transport *transport, const DATA_BLOB user_session_key, const DATA_BLOB response) { @@ -293,9 +293,9 @@ BOOL cli_transport_simple_set_signing(struct cli_transport *transport, /* Initialise the sequence number */ data->next_seq_num = 0; - transport->negotiate.sign_info.sign_outgoing_message = cli_request_simple_sign_outgoing_message; - transport->negotiate.sign_info.check_incoming_message = cli_request_simple_check_incoming_message; - transport->negotiate.sign_info.free_signing_context = cli_transport_simple_free_signing_context; + transport->negotiate.sign_info.sign_outgoing_message = smbcli_request_simple_sign_outgoing_message; + transport->negotiate.sign_info.check_incoming_message = smbcli_request_simple_check_incoming_message; + transport->negotiate.sign_info.free_signing_context = smbcli_transport_simple_free_signing_context; return True; } @@ -304,7 +304,7 @@ BOOL cli_transport_simple_set_signing(struct cli_transport *transport, /*********************************************************** SMB signing - NULL implementation - calculate a MAC to send. ************************************************************/ -static void cli_request_null_sign_outgoing_message(struct cli_request *req) +static void smbcli_request_null_sign_outgoing_message(struct smbcli_request *req) { /* we can't zero out the sig, as we might be trying to send a transport request - which is NBT-level, not SMB level and doesn't @@ -315,7 +315,7 @@ static void cli_request_null_sign_outgoing_message(struct cli_request *req) /*********************************************************** SMB signing - NULL implementation - check a MAC sent by server. ************************************************************/ -static BOOL cli_request_null_check_incoming_message(struct cli_request *req) +static BOOL smbcli_request_null_check_incoming_message(struct smbcli_request *req) { return True; } @@ -324,7 +324,7 @@ static BOOL cli_request_null_check_incoming_message(struct cli_request *req) /*********************************************************** SMB signing - NULL implementation - free signing context ************************************************************/ -static void cli_null_free_signing_context(struct cli_transport *transport) +static void smbcli_null_free_signing_context(struct smbcli_transport *transport) { } @@ -334,13 +334,13 @@ static void cli_null_free_signing_context(struct cli_transport *transport) @note Used as an initialisation only - it will not correctly shut down a real signing mechanism */ -BOOL cli_null_set_signing(struct cli_transport *transport) +BOOL smbcli_null_set_signing(struct smbcli_transport *transport) { transport->negotiate.sign_info.signing_context = NULL; - transport->negotiate.sign_info.sign_outgoing_message = cli_request_null_sign_outgoing_message; - transport->negotiate.sign_info.check_incoming_message = cli_request_null_check_incoming_message; - transport->negotiate.sign_info.free_signing_context = cli_null_free_signing_context; + transport->negotiate.sign_info.sign_outgoing_message = smbcli_request_null_sign_outgoing_message; + transport->negotiate.sign_info.check_incoming_message = smbcli_request_null_check_incoming_message; + transport->negotiate.sign_info.free_signing_context = smbcli_null_free_signing_context; return True; } @@ -348,7 +348,7 @@ BOOL cli_null_set_signing(struct cli_transport *transport) /*********************************************************** SMB signing - TEMP implementation - calculate a MAC to send. ************************************************************/ -static void cli_request_temp_sign_outgoing_message(struct cli_request *req) +static void smbcli_request_temp_sign_outgoing_message(struct smbcli_request *req) { /* mark the packet as signed - BEFORE we sign it...*/ mark_packet_signed(&req->out); @@ -363,7 +363,7 @@ static void cli_request_temp_sign_outgoing_message(struct cli_request *req) /*********************************************************** SMB signing - TEMP implementation - check a MAC sent by server. ************************************************************/ -static BOOL cli_request_temp_check_incoming_message(struct cli_request *req) +static BOOL smbcli_request_temp_check_incoming_message(struct smbcli_request *req) { return True; } @@ -371,7 +371,7 @@ static BOOL cli_request_temp_check_incoming_message(struct cli_request *req) /*********************************************************** SMB signing - NULL implementation - free signing context ************************************************************/ -static void cli_temp_free_signing_context(struct cli_transport *transport) +static void smbcli_temp_free_signing_context(struct smbcli_transport *transport) { return; } @@ -382,7 +382,7 @@ static void cli_temp_free_signing_context(struct cli_transport *transport) @note Used as an initialisation only - it will not correctly shut down a real signing mechanism */ -BOOL cli_temp_set_signing(struct cli_transport *transport) +BOOL smbcli_temp_set_signing(struct smbcli_transport *transport) { if (!set_smb_signing_common(transport)) { return False; @@ -390,9 +390,9 @@ BOOL cli_temp_set_signing(struct cli_transport *transport) transport->negotiate.sign_info.signing_context = NULL; - transport->negotiate.sign_info.sign_outgoing_message = cli_request_temp_sign_outgoing_message; - transport->negotiate.sign_info.check_incoming_message = cli_request_temp_check_incoming_message; - transport->negotiate.sign_info.free_signing_context = cli_temp_free_signing_context; + transport->negotiate.sign_info.sign_outgoing_message = smbcli_request_temp_sign_outgoing_message; + transport->negotiate.sign_info.check_incoming_message = smbcli_request_temp_check_incoming_message; + transport->negotiate.sign_info.free_signing_context = smbcli_temp_free_signing_context; return True; } @@ -400,20 +400,20 @@ BOOL cli_temp_set_signing(struct cli_transport *transport) /** * Free the signing context */ -void cli_transport_free_signing_context(struct cli_transport *transport) +void smbcli_transport_free_signing_context(struct smbcli_transport *transport) { if (transport->negotiate.sign_info.free_signing_context) { transport->negotiate.sign_info.free_signing_context(transport); } - cli_null_set_signing(transport); + smbcli_null_set_signing(transport); } /** * Sign a packet with the current mechanism */ -void cli_request_calculate_sign_mac(struct cli_request *req) +void smbcli_request_calculate_sign_mac(struct smbcli_request *req) { req->transport->negotiate.sign_info.sign_outgoing_message(req); } @@ -424,7 +424,7 @@ void cli_request_calculate_sign_mac(struct cli_request *req) * @return False if we had an established signing connection * which had a back checksum, True otherwise */ -BOOL cli_request_check_sign_mac(struct cli_request *req) +BOOL smbcli_request_check_sign_mac(struct smbcli_request *req) { BOOL good; @@ -442,9 +442,9 @@ BOOL cli_request_check_sign_mac(struct cli_request *req) } -BOOL cli_init_signing(struct cli_transport *transport) +BOOL smbcli_init_signing(struct smbcli_transport *transport) { - if (!cli_null_set_signing(transport)) { + if (!smbcli_null_set_signing(transport)) { return False; } -- cgit From 3ef16b2679bed40041483b8f862463fb30f426dc Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 9 Aug 2004 20:47:31 +0000 Subject: r1674: fixed a bug in the handling of STR_LEN8BIT flagged strings (This used to be commit 17a331529706266bd53b2d1c7b873cf4bbd7aaa7) --- source4/libcli/raw/rawrequest.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 4143cb12ca..70e924a99f 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -814,12 +814,15 @@ size_t smbcli_blob_pull_string(struct smbcli_session *session, int extra; dest->s = NULL; - if (len_offset > blob->length-4) { - return 0; - } if (flags & STR_LEN8BIT) { + if (len_offset > blob->length-1) { + return 0; + } dest->private_length = CVAL(blob->data, len_offset); } else { + if (len_offset > blob->length-4) { + return 0; + } dest->private_length = IVAL(blob->data, len_offset); } extra = 0; -- cgit From 9c41274ace0a1dd88b113ce2bf84b33b0c528efa Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 9 Aug 2004 20:51:16 +0000 Subject: r1676: - improved the handling of username/password in locktest and gentest - use lp_maxprotocol() in the libcli/raw/ negotiate code, so we obey the smb.conf "max protocol" option - better handling of -M option in masktest (This used to be commit 8685a584c92ab73a35b29a8c719f1ec207562837) --- source4/libcli/raw/rawnegotiate.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawnegotiate.c b/source4/libcli/raw/rawnegotiate.c index 9b00aa6121..dab7b38939 100644 --- a/source4/libcli/raw/rawnegotiate.c +++ b/source4/libcli/raw/rawnegotiate.c @@ -86,7 +86,7 @@ NTSTATUS smb_raw_negotiate(struct smbcli_transport *transport) struct smbcli_request *req; int protocol; - req = smb_negprot_send(transport, PROTOCOL_NT1); + req = smb_negprot_send(transport, lp_maxprotocol()); if (!req) { return NT_STATUS_UNSUCCESSFUL; } -- cgit From 6ffaf57fe715419bf3aa677027548161b642d17e Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 10 Aug 2004 04:38:03 +0000 Subject: r1686: Don't use a void* for the context inside the SMB signing code. Andrew Bartlett (This used to be commit 64fcd8ecebabdd09fed6b65e3c436bffc1da9de7) --- source4/libcli/raw/smb_signing.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/smb_signing.c b/source4/libcli/raw/smb_signing.c index ddde58fd88..ffbecb85fc 100644 --- a/source4/libcli/raw/smb_signing.c +++ b/source4/libcli/raw/smb_signing.c @@ -22,11 +22,6 @@ #include "includes.h" -struct smb_basic_signing_context { - DATA_BLOB mac_key; - uint32_t next_seq_num; -}; - /*********************************************************** SMB signing - Common code before we set a new signing implementation ************************************************************/ -- cgit From 7a523b2bc443c7031336d5afd6b6a884ba0e0fab Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Aug 2004 23:06:59 +0000 Subject: r1712: this should fix a bug with a spinning client when a server dies unexpectedly. bug found by abartlett. (This used to be commit 566b7a9ce986cdfeabb69f17c472782fc7494d43) --- source4/libcli/raw/clitransport.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 5290dd953d..784a6f1798 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -433,6 +433,10 @@ static void smbcli_transport_process_recv(struct smbcli_transport *transport) transport->recv_buffer.header + transport->recv_buffer.received, NBT_HDR_SIZE - transport->recv_buffer.received); + if (ret == 0) { + smbcli_transport_dead(transport); + return; + } if (ret == -1) { if (errno == EINTR || errno == EAGAIN) { return; -- cgit From 5a79e6cf484cd27092217a8e739e6d79bb8b12e9 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 11 Aug 2004 16:15:21 +0000 Subject: r1725: Remove a silly 'utility' function. Andrew Bartlett (This used to be commit 4d563d7e4afad1c5f583aca3f42087bfff0fb895) --- source4/libcli/raw/smb_signing.c | 20 ++++---------------- 1 file changed, 4 insertions(+), 16 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/smb_signing.c b/source4/libcli/raw/smb_signing.c index ffbecb85fc..b65513ebce 100644 --- a/source4/libcli/raw/smb_signing.c +++ b/source4/libcli/raw/smb_signing.c @@ -50,20 +50,6 @@ static BOOL set_smb_signing_common(struct smbcli_transport *transport) return True; } -/*********************************************************** - SMB signing - Common code for 'real' implementations -************************************************************/ -static BOOL set_smb_signing_real_common(struct smbcli_transport *transport) -{ - if (transport->negotiate.sign_info.mandatory_signing) { - DEBUG(5, ("Mandatory SMB signing enabled!\n")); - } - - DEBUG(5, ("SMB signing enabled!\n")); - - return True; -} - static void mark_packet_signed(struct request_buffer *out) { uint16_t flags2; @@ -268,10 +254,12 @@ BOOL smbcli_transport_simple_set_signing(struct smbcli_transport *transport, return False; } - if (!set_smb_signing_real_common(transport)) { - return False; + if (transport->negotiate.sign_info.mandatory_signing) { + DEBUG(5, ("Mandatory SMB signing enabled!\n")); } + DEBUG(5, ("SMB signing enabled!\n")); + data = smb_xmalloc(sizeof(*data)); transport->negotiate.sign_info.signing_context = data; -- cgit From d9ff454a87410d4756cd61612bfb4aa768301be5 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 11 Aug 2004 18:05:30 +0000 Subject: r1729: Make the SMB signing code more generic (to share more between client and servers). Andrew Bartlett (This used to be commit b90b04e84bc8add235cf9ee7797a608ff48c4ca0) --- source4/libcli/raw/smb_signing.c | 99 +++++++++++++++++++++++----------------- 1 file changed, 57 insertions(+), 42 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/smb_signing.c b/source4/libcli/raw/smb_signing.c index b65513ebce..c1fad1eaf8 100644 --- a/source4/libcli/raw/smb_signing.c +++ b/source4/libcli/raw/smb_signing.c @@ -41,7 +41,8 @@ static BOOL set_smb_signing_common(struct smbcli_transport *transport) } if (transport->negotiate.sign_info.free_signing_context) - transport->negotiate.sign_info.free_signing_context(transport); + transport->negotiate.sign_info + .free_signing_context(&transport->negotiate.sign_info); /* These calls are INCOMPATIBLE with SMB signing */ transport->negotiate.readbraw_supported = False; @@ -58,26 +59,27 @@ static void mark_packet_signed(struct request_buffer *out) SSVAL(out->hdr, HDR_FLG2, flags2); } -static BOOL signing_good(struct smbcli_request *req, unsigned int seq, BOOL good) +static BOOL signing_good(struct smb_signing_context *sign_info, + unsigned int seq, BOOL good) { if (good) { - if (!req->transport->negotiate.sign_info.doing_signing) { - req->transport->negotiate.sign_info.doing_signing = True; + if (!sign_info->doing_signing) { + sign_info->doing_signing = True; } - if (!req->transport->negotiate.sign_info.seen_valid) { - req->transport->negotiate.sign_info.seen_valid = True; + if (!sign_info->seen_valid) { + sign_info->seen_valid = True; } } else { - if (!req->transport->negotiate.sign_info.seen_valid) { + if (!sign_info->seen_valid) { /* If we have never seen a good packet, just turn it off */ DEBUG(5, ("signing_good: signing negotiated but not required and peer\n" "isn't sending correct signatures. Turning off.\n")); - req->transport->negotiate.sign_info.negotiated_smb_signing = False; - req->transport->negotiate.sign_info.allow_smb_signing = False; - req->transport->negotiate.sign_info.doing_signing = False; - if (req->transport->negotiate.sign_info.free_signing_context) - req->transport->negotiate.sign_info.free_signing_context(req->transport); - smbcli_null_set_signing(req->transport); + sign_info->negotiated_smb_signing = False; + sign_info->allow_smb_signing = False; + sign_info->doing_signing = False; + if (sign_info->free_signing_context) + sign_info->free_signing_context(sign_info); + smbcli_null_set_signing(sign_info); return True; } else { /* bad packet after signing started - fail and disconnect. */ @@ -223,45 +225,41 @@ static BOOL smbcli_request_simple_check_incoming_message(struct smbcli_request * &data->mac_key, req->seq_num+1); - return signing_good(req, req->seq_num+1, good); + return signing_good(&req->transport->negotiate.sign_info, + req->seq_num+1, good); } /*********************************************************** SMB signing - Simple implementation - free signing context ************************************************************/ -static void smbcli_transport_simple_free_signing_context(struct smbcli_transport *transport) +static void smbcli_transport_simple_free_signing_context(struct smb_signing_context *sign_info) { - struct smb_basic_signing_context *data = transport->negotiate.sign_info.signing_context; + struct smb_basic_signing_context *data = sign_info->signing_context; data_blob_free(&data->mac_key); - SAFE_FREE(transport->negotiate.sign_info.signing_context); + SAFE_FREE(sign_info->signing_context); return; } - /*********************************************************** SMB signing - Simple implementation - setup the MAC key. ************************************************************/ -BOOL smbcli_transport_simple_set_signing(struct smbcli_transport *transport, - const DATA_BLOB user_session_key, - const DATA_BLOB response) +BOOL smbcli_simple_set_signing(struct smb_signing_context *sign_info, + const DATA_BLOB user_session_key, + const DATA_BLOB response) { struct smb_basic_signing_context *data; - if (!set_smb_signing_common(transport)) { - return False; - } - - if (transport->negotiate.sign_info.mandatory_signing) { + if (sign_info->mandatory_signing) { DEBUG(5, ("Mandatory SMB signing enabled!\n")); } DEBUG(5, ("SMB signing enabled!\n")); data = smb_xmalloc(sizeof(*data)); - transport->negotiate.sign_info.signing_context = data; + sign_info->signing_context = data; data->mac_key = data_blob(NULL, response.length + user_session_key.length); @@ -276,14 +274,31 @@ BOOL smbcli_transport_simple_set_signing(struct smbcli_transport *transport, /* Initialise the sequence number */ data->next_seq_num = 0; - transport->negotiate.sign_info.sign_outgoing_message = smbcli_request_simple_sign_outgoing_message; - transport->negotiate.sign_info.check_incoming_message = smbcli_request_simple_check_incoming_message; - transport->negotiate.sign_info.free_signing_context = smbcli_transport_simple_free_signing_context; + sign_info->sign_outgoing_message = smbcli_request_simple_sign_outgoing_message; + sign_info->check_incoming_message = smbcli_request_simple_check_incoming_message; + sign_info->free_signing_context = smbcli_transport_simple_free_signing_context; return True; } +/*********************************************************** + SMB signing - Simple implementation - setup the MAC key. +************************************************************/ +BOOL smbcli_transport_simple_set_signing(struct smbcli_transport *transport, + const DATA_BLOB user_session_key, + const DATA_BLOB response) +{ + if (!set_smb_signing_common(transport)) { + return False; + } + + return smbcli_simple_set_signing(&transport->negotiate.sign_info, + user_session_key, + response); +} + + /*********************************************************** SMB signing - NULL implementation - calculate a MAC to send. ************************************************************/ @@ -307,7 +322,7 @@ static BOOL smbcli_request_null_check_incoming_message(struct smbcli_request *re /*********************************************************** SMB signing - NULL implementation - free signing context ************************************************************/ -static void smbcli_null_free_signing_context(struct smbcli_transport *transport) +static void smbcli_null_free_signing_context(struct smb_signing_context *sign_info) { } @@ -317,13 +332,13 @@ static void smbcli_null_free_signing_context(struct smbcli_transport *transport) @note Used as an initialisation only - it will not correctly shut down a real signing mechanism */ -BOOL smbcli_null_set_signing(struct smbcli_transport *transport) +BOOL smbcli_null_set_signing(struct smb_signing_context *sign_info) { - transport->negotiate.sign_info.signing_context = NULL; + sign_info->signing_context = NULL; - transport->negotiate.sign_info.sign_outgoing_message = smbcli_request_null_sign_outgoing_message; - transport->negotiate.sign_info.check_incoming_message = smbcli_request_null_check_incoming_message; - transport->negotiate.sign_info.free_signing_context = smbcli_null_free_signing_context; + sign_info->sign_outgoing_message = smbcli_request_null_sign_outgoing_message; + sign_info->check_incoming_message = smbcli_request_null_check_incoming_message; + sign_info->free_signing_context = smbcli_null_free_signing_context; return True; } @@ -354,7 +369,7 @@ static BOOL smbcli_request_temp_check_incoming_message(struct smbcli_request *re /*********************************************************** SMB signing - NULL implementation - free signing context ************************************************************/ -static void smbcli_temp_free_signing_context(struct smbcli_transport *transport) +static void smbcli_temp_free_signing_context(struct smb_signing_context *sign_info) { return; } @@ -383,13 +398,13 @@ BOOL smbcli_temp_set_signing(struct smbcli_transport *transport) /** * Free the signing context */ -void smbcli_transport_free_signing_context(struct smbcli_transport *transport) +void smbcli_transport_free_signing_context(struct smb_signing_context *sign_info) { - if (transport->negotiate.sign_info.free_signing_context) { - transport->negotiate.sign_info.free_signing_context(transport); + if (sign_info->free_signing_context) { + sign_info->free_signing_context(sign_info); } - smbcli_null_set_signing(transport); + smbcli_null_set_signing(sign_info); } @@ -427,7 +442,7 @@ BOOL smbcli_request_check_sign_mac(struct smbcli_request *req) BOOL smbcli_init_signing(struct smbcli_transport *transport) { - if (!smbcli_null_set_signing(transport)) { + if (!smbcli_null_set_signing(&transport->negotiate.sign_info)) { return False; } -- cgit From ca72bdfecbea2e332821bc292b4bb34f6c96ac2e Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 11 Aug 2004 19:29:22 +0000 Subject: r1735: Clean up SMB signing - we don't have more than one 'real' way to sign a packet, so don't pretend we do... Andrew Bartlett (This used to be commit 68a6d5aeb35e8972182fffbb6cc506f89584b2d5) --- source4/libcli/raw/smb_signing.c | 45 +++++++++++++--------------------------- 1 file changed, 14 insertions(+), 31 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/smb_signing.c b/source4/libcli/raw/smb_signing.c index c1fad1eaf8..adfccda65a 100644 --- a/source4/libcli/raw/smb_signing.c +++ b/source4/libcli/raw/smb_signing.c @@ -74,7 +74,6 @@ static BOOL signing_good(struct smb_signing_context *sign_info, /* If we have never seen a good packet, just turn it off */ DEBUG(5, ("signing_good: signing negotiated but not required and peer\n" "isn't sending correct signatures. Turning off.\n")); - sign_info->negotiated_smb_signing = False; sign_info->allow_smb_signing = False; sign_info->doing_signing = False; if (sign_info->free_signing_context) @@ -191,25 +190,25 @@ BOOL check_signed_incoming_message(struct request_buffer *in, DATA_BLOB *mac_key ************************************************************/ static void smbcli_request_simple_sign_outgoing_message(struct smbcli_request *req) { - struct smb_basic_signing_context *data = req->transport->negotiate.sign_info.signing_context; - #if 0 /* enable this when packet signing is preventing you working out why valgrind says that data is uninitialised */ file_save("pkt.dat", req->out.buffer, req->out.size); #endif - req->seq_num = data->next_seq_num; + req->seq_num = req->transport->negotiate.sign_info.next_seq_num; /* some requests (eg. NTcancel) are one way, and the sequence number should be increased by 1 not 2 */ if (req->sign_single_increment) { - data->next_seq_num += 1; + req->transport->negotiate.sign_info.next_seq_num += 1; } else { - data->next_seq_num += 2; + req->transport->negotiate.sign_info.next_seq_num += 2; } - sign_outgoing_message(&req->out, &data->mac_key, req->seq_num); + sign_outgoing_message(&req->out, + &req->transport->negotiate.sign_info.mac_key, + req->seq_num); } @@ -218,11 +217,8 @@ static void smbcli_request_simple_sign_outgoing_message(struct smbcli_request *r ************************************************************/ static BOOL smbcli_request_simple_check_incoming_message(struct smbcli_request *req) { - struct smb_basic_signing_context *data - = req->transport->negotiate.sign_info.signing_context; - BOOL good = check_signed_incoming_message(&req->in, - &data->mac_key, + &req->transport->negotiate.sign_info.mac_key, req->seq_num+1); return signing_good(&req->transport->negotiate.sign_info, @@ -235,11 +231,7 @@ static BOOL smbcli_request_simple_check_incoming_message(struct smbcli_request * ************************************************************/ static void smbcli_transport_simple_free_signing_context(struct smb_signing_context *sign_info) { - struct smb_basic_signing_context *data = sign_info->signing_context; - - data_blob_free(&data->mac_key); - SAFE_FREE(sign_info->signing_context); - + data_blob_free(&sign_info->mac_key); return; } @@ -250,29 +242,24 @@ BOOL smbcli_simple_set_signing(struct smb_signing_context *sign_info, const DATA_BLOB user_session_key, const DATA_BLOB response) { - struct smb_basic_signing_context *data; - if (sign_info->mandatory_signing) { DEBUG(5, ("Mandatory SMB signing enabled!\n")); } DEBUG(5, ("SMB signing enabled!\n")); - data = smb_xmalloc(sizeof(*data)); - sign_info->signing_context = data; - - data->mac_key = data_blob(NULL, response.length + user_session_key.length); + sign_info->mac_key = data_blob(NULL, response.length + user_session_key.length); - memcpy(&data->mac_key.data[0], user_session_key.data, user_session_key.length); + memcpy(&sign_info->mac_key.data[0], user_session_key.data, user_session_key.length); if (response.length) { - memcpy(&data->mac_key.data[user_session_key.length],response.data, response.length); + memcpy(&sign_info->mac_key.data[user_session_key.length],response.data, response.length); } - dump_data_pw("Started Signing with key:\n", data->mac_key.data, data->mac_key.length); + dump_data_pw("Started Signing with key:\n", sign_info->mac_key.data, sign_info->mac_key.length); /* Initialise the sequence number */ - data->next_seq_num = 0; + sign_info->next_seq_num = 0; sign_info->sign_outgoing_message = smbcli_request_simple_sign_outgoing_message; sign_info->check_incoming_message = smbcli_request_simple_check_incoming_message; @@ -334,8 +321,6 @@ static void smbcli_null_free_signing_context(struct smb_signing_context *sign_in */ BOOL smbcli_null_set_signing(struct smb_signing_context *sign_info) { - sign_info->signing_context = NULL; - sign_info->sign_outgoing_message = smbcli_request_null_sign_outgoing_message; sign_info->check_incoming_message = smbcli_request_null_check_incoming_message; sign_info->free_signing_context = smbcli_null_free_signing_context; @@ -344,7 +329,7 @@ BOOL smbcli_null_set_signing(struct smb_signing_context *sign_info) } /*********************************************************** - SMB signing - TEMP implementation - calculate a MAC to send. + SMB signing - TEMP implementation (send BSRSPYL during SPNEGO) - calculate a MAC to send. ************************************************************/ static void smbcli_request_temp_sign_outgoing_message(struct smbcli_request *req) { @@ -386,8 +371,6 @@ BOOL smbcli_temp_set_signing(struct smbcli_transport *transport) return False; } - transport->negotiate.sign_info.signing_context = NULL; - transport->negotiate.sign_info.sign_outgoing_message = smbcli_request_temp_sign_outgoing_message; transport->negotiate.sign_info.check_incoming_message = smbcli_request_temp_check_incoming_message; transport->negotiate.sign_info.free_signing_context = smbcli_temp_free_signing_context; -- cgit From b3e7722a88cec3ffdc937effbeff149b8353df72 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 11 Aug 2004 21:09:36 +0000 Subject: r1738: honor the "unicode=yes/no" option in the SMB client library (This used to be commit b6664bdd0f4125a483620b76a87ea69cad866d6a) --- source4/libcli/raw/rawnegotiate.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawnegotiate.c b/source4/libcli/raw/rawnegotiate.c index dab7b38939..5ec827eebb 100644 --- a/source4/libcli/raw/rawnegotiate.c +++ b/source4/libcli/raw/rawnegotiate.c @@ -53,7 +53,9 @@ struct smbcli_request *smb_negprot_send(struct smbcli_transport *transport, int } flags2 |= FLAGS2_32_BIT_ERROR_CODES; - flags2 |= FLAGS2_UNICODE_STRINGS; + if (lp_unicode()) { + flags2 |= FLAGS2_UNICODE_STRINGS; + } flags2 |= FLAGS2_EXTENDED_ATTRIBUTES; flags2 |= FLAGS2_LONG_PATH_COMPONENTS; flags2 |= FLAGS2_IS_LONG_NAME; @@ -172,7 +174,7 @@ NTSTATUS smb_raw_negotiate(struct smbcli_transport *transport) } /* a way to force ascii SMB */ - if (getenv("SMBCLI_FORCE_ASCII")) { + if (!lp_unicode() || getenv("SMBCLI_FORCE_ASCII")) { transport->negotiate.capabilities &= ~CAP_UNICODE; } -- cgit From 44e04cdb11a87ae78cabd76c61e11ae1f283dfaa Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 11 Aug 2004 21:10:16 +0000 Subject: r1739: fixed the padding in setpathinfo, noticed when forcing negotiated ascii strings (This used to be commit fc75dc49025f4beb0f1df656cfe4ec497e693dcc) --- source4/libcli/raw/rawsetfileinfo.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawsetfileinfo.c b/source4/libcli/raw/rawsetfileinfo.c index b1667db50f..2b525f2661 100644 --- a/source4/libcli/raw/rawsetfileinfo.c +++ b/source4/libcli/raw/rawsetfileinfo.c @@ -164,10 +164,10 @@ static struct smbcli_request *smb_raw_setfileinfo_blob_send(struct smbcli_tree * Very raw set path info - takes data blob ****************************************************************************/ static struct smbcli_request *smb_raw_setpathinfo_blob_send(struct smbcli_tree *tree, - TALLOC_CTX *mem_ctx, - const char *fname, - uint16_t info_level, - DATA_BLOB *blob) + TALLOC_CTX *mem_ctx, + const char *fname, + uint16_t info_level, + DATA_BLOB *blob) { struct smb_trans2 tp; uint16_t setup = TRANSACT2_SETPATHINFO; @@ -180,15 +180,15 @@ static struct smbcli_request *smb_raw_setpathinfo_blob_send(struct smbcli_tree * tp.in.max_data = 0; tp.in.setup = &setup; - tp.in.params = data_blob_talloc(mem_ctx, NULL, 4); + tp.in.params = data_blob_talloc(mem_ctx, NULL, 6); if (!tp.in.params.data) { return NULL; } SSVAL(tp.in.params.data, 0, info_level); - SSVAL(tp.in.params.data, 2, 0); + SIVAL(tp.in.params.data, 2, 0); smbcli_blob_append_string(tree->session, mem_ctx, - &tp.in.params, - fname, STR_TERMINATE); + &tp.in.params, + fname, STR_TERMINATE); tp.in.data = *blob; -- cgit From ffcfb97fb3d065e8c37d7f2de8b688d1e570a47b Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 12 Aug 2004 00:04:52 +0000 Subject: r1745: More work on cleaning up SMB signing. This removes the function pointer mess from the SMB signing code. Andrew Bartlett (This used to be commit 8830603e4bc821a11db87072a32a51b076a28e06) --- source4/libcli/raw/smb_signing.c | 288 +++++++++++++++------------------------ 1 file changed, 109 insertions(+), 179 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/smb_signing.c b/source4/libcli/raw/smb_signing.c index adfccda65a..03794829c2 100644 --- a/source4/libcli/raw/smb_signing.c +++ b/source4/libcli/raw/smb_signing.c @@ -21,6 +21,8 @@ */ #include "includes.h" +static void smbcli_free_signing_context(struct smb_signing_context *sign_info); +static BOOL smbcli_null_set_signing(struct smb_signing_context *sign_info); /*********************************************************** SMB signing - Common code before we set a new signing implementation @@ -40,9 +42,7 @@ static BOOL set_smb_signing_common(struct smbcli_transport *transport) return False; } - if (transport->negotiate.sign_info.free_signing_context) - transport->negotiate.sign_info - .free_signing_context(&transport->negotiate.sign_info); + smbcli_free_signing_context(&transport->negotiate.sign_info); /* These calls are INCOMPATIBLE with SMB signing */ transport->negotiate.readbraw_supported = False; @@ -74,10 +74,9 @@ static BOOL signing_good(struct smb_signing_context *sign_info, /* If we have never seen a good packet, just turn it off */ DEBUG(5, ("signing_good: signing negotiated but not required and peer\n" "isn't sending correct signatures. Turning off.\n")); - sign_info->allow_smb_signing = False; sign_info->doing_signing = False; - if (sign_info->free_signing_context) - sign_info->free_signing_context(sign_info); + smbcli_free_signing_context(sign_info); + smbcli_null_set_signing(sign_info); return True; } else { @@ -188,7 +187,7 @@ BOOL check_signed_incoming_message(struct request_buffer *in, DATA_BLOB *mac_key /*********************************************************** SMB signing - Simple implementation - calculate a MAC to send. ************************************************************/ -static void smbcli_request_simple_sign_outgoing_message(struct smbcli_request *req) +void smbcli_request_calculate_sign_mac(struct smbcli_request *req) { #if 0 /* enable this when packet signing is preventing you working out why valgrind @@ -196,51 +195,121 @@ static void smbcli_request_simple_sign_outgoing_message(struct smbcli_request *r file_save("pkt.dat", req->out.buffer, req->out.size); #endif - req->seq_num = req->transport->negotiate.sign_info.next_seq_num; - - /* some requests (eg. NTcancel) are one way, and the sequence number - should be increased by 1 not 2 */ - if (req->sign_single_increment) { - req->transport->negotiate.sign_info.next_seq_num += 1; - } else { - req->transport->negotiate.sign_info.next_seq_num += 2; + switch (req->transport->negotiate.sign_info.signing_state) { + case SMB_SIGNING_ENGINE_OFF: + break; + + case SMB_SIGNING_ENGINE_BSRSPYL: + /* mark the packet as signed - BEFORE we sign it...*/ + mark_packet_signed(&req->out); + + /* I wonder what BSRSPYL stands for - but this is what MS + actually sends! */ + memcpy((req->out.hdr + HDR_SS_FIELD), "BSRSPYL ", 8); + break; + + case SMB_SIGNING_ENGINE_ON: + + req->seq_num = req->transport->negotiate.sign_info.next_seq_num; + + /* some requests (eg. NTcancel) are one way, and the sequence number + should be increased by 1 not 2 */ + if (req->sign_single_increment) { + req->transport->negotiate.sign_info.next_seq_num += 1; + } else { + req->transport->negotiate.sign_info.next_seq_num += 2; + } + + sign_outgoing_message(&req->out, + &req->transport->negotiate.sign_info.mac_key, + req->seq_num); + break; } - - sign_outgoing_message(&req->out, - &req->transport->negotiate.sign_info.mac_key, - req->seq_num); + return; } -/*********************************************************** - SMB signing - Simple implementation - check a MAC sent by server. -************************************************************/ -static BOOL smbcli_request_simple_check_incoming_message(struct smbcli_request *req) +/** + SMB signing - NULL implementation - setup the MAC key. + + @note Used as an initialisation only - it will not correctly + shut down a real signing mechanism +*/ +static BOOL smbcli_null_set_signing(struct smb_signing_context *sign_info) { - BOOL good = check_signed_incoming_message(&req->in, - &req->transport->negotiate.sign_info.mac_key, - req->seq_num+1); - - return signing_good(&req->transport->negotiate.sign_info, - req->seq_num+1, good); + sign_info->mac_key = data_blob(NULL, 0); + sign_info->signing_state = SMB_SIGNING_ENGINE_OFF; + return True; } +/** + SMB signing - TEMP implementation - setup the MAC key. + + @note Used as an initialisation only - it will not correctly + shut down a real signing mechanism +*/ +BOOL smbcli_temp_set_signing(struct smbcli_transport *transport) +{ + if (!set_smb_signing_common(transport)) { + return False; + } + + transport->negotiate.sign_info.mac_key = data_blob(NULL, 0); + transport->negotiate.sign_info.signing_state = SMB_SIGNING_ENGINE_BSRSPYL; + + return True; +} + +/** + * Free the signing context + */ +static void smbcli_free_signing_context(struct smb_signing_context *sign_info) +{ + data_blob_free(&sign_info->mac_key); + smbcli_null_set_signing(sign_info); +} /*********************************************************** - SMB signing - Simple implementation - free signing context + SMB signing - Simple implementation - check a MAC sent by server. ************************************************************/ -static void smbcli_transport_simple_free_signing_context(struct smb_signing_context *sign_info) +/** + * Check a packet supplied by the server. + * @return False if we had an established signing connection + * which had a back checksum, True otherwise + */ +BOOL smbcli_request_check_sign_mac(struct smbcli_request *req) { - data_blob_free(&sign_info->mac_key); - return; + BOOL good; + + switch (req->transport->negotiate.sign_info.signing_state) + { + case SMB_SIGNING_ENGINE_OFF: + return True; + case SMB_SIGNING_ENGINE_BSRSPYL: + case SMB_SIGNING_ENGINE_ON: + { + if (req->in.size < (HDR_SS_FIELD + 8)) { + return False; + } else { + good = check_signed_incoming_message(&req->in, + &req->transport->negotiate.sign_info.mac_key, + req->seq_num+1); + + return signing_good(&req->transport->negotiate.sign_info, + req->seq_num+1, good); + } + } + } + return False; } + /*********************************************************** SMB signing - Simple implementation - setup the MAC key. ************************************************************/ -BOOL smbcli_simple_set_signing(struct smb_signing_context *sign_info, - const DATA_BLOB user_session_key, - const DATA_BLOB response) +static BOOL smbcli_simple_set_signing(struct smb_signing_context *sign_info, + const DATA_BLOB user_session_key, + const DATA_BLOB response) { if (sign_info->mandatory_signing) { DEBUG(5, ("Mandatory SMB signing enabled!\n")); @@ -261,9 +330,7 @@ BOOL smbcli_simple_set_signing(struct smb_signing_context *sign_info, /* Initialise the sequence number */ sign_info->next_seq_num = 0; - sign_info->sign_outgoing_message = smbcli_request_simple_sign_outgoing_message; - sign_info->check_incoming_message = smbcli_request_simple_check_incoming_message; - sign_info->free_signing_context = smbcli_transport_simple_free_signing_context; + sign_info->signing_state = SMB_SIGNING_ENGINE_ON; return True; } @@ -273,8 +340,8 @@ BOOL smbcli_simple_set_signing(struct smb_signing_context *sign_info, SMB signing - Simple implementation - setup the MAC key. ************************************************************/ BOOL smbcli_transport_simple_set_signing(struct smbcli_transport *transport, - const DATA_BLOB user_session_key, - const DATA_BLOB response) + const DATA_BLOB user_session_key, + const DATA_BLOB response) { if (!set_smb_signing_common(transport)) { return False; @@ -286,143 +353,6 @@ BOOL smbcli_transport_simple_set_signing(struct smbcli_transport *transport, } -/*********************************************************** - SMB signing - NULL implementation - calculate a MAC to send. -************************************************************/ -static void smbcli_request_null_sign_outgoing_message(struct smbcli_request *req) -{ - /* we can't zero out the sig, as we might be trying to send a - transport request - which is NBT-level, not SMB level and doesn't - have the field */ -} - - -/*********************************************************** - SMB signing - NULL implementation - check a MAC sent by server. -************************************************************/ -static BOOL smbcli_request_null_check_incoming_message(struct smbcli_request *req) -{ - return True; -} - - -/*********************************************************** - SMB signing - NULL implementation - free signing context -************************************************************/ -static void smbcli_null_free_signing_context(struct smb_signing_context *sign_info) -{ -} - -/** - SMB signing - NULL implementation - setup the MAC key. - - @note Used as an initialisation only - it will not correctly - shut down a real signing mechanism -*/ -BOOL smbcli_null_set_signing(struct smb_signing_context *sign_info) -{ - sign_info->sign_outgoing_message = smbcli_request_null_sign_outgoing_message; - sign_info->check_incoming_message = smbcli_request_null_check_incoming_message; - sign_info->free_signing_context = smbcli_null_free_signing_context; - - return True; -} - -/*********************************************************** - SMB signing - TEMP implementation (send BSRSPYL during SPNEGO) - calculate a MAC to send. -************************************************************/ -static void smbcli_request_temp_sign_outgoing_message(struct smbcli_request *req) -{ - /* mark the packet as signed - BEFORE we sign it...*/ - mark_packet_signed(&req->out); - - /* I wonder what BSRSPYL stands for - but this is what MS - actually sends! */ - memcpy((req->out.hdr + HDR_SS_FIELD), "BSRSPYL ", 8); - - return; -} - -/*********************************************************** - SMB signing - TEMP implementation - check a MAC sent by server. -************************************************************/ -static BOOL smbcli_request_temp_check_incoming_message(struct smbcli_request *req) -{ - return True; -} - -/*********************************************************** - SMB signing - NULL implementation - free signing context -************************************************************/ -static void smbcli_temp_free_signing_context(struct smb_signing_context *sign_info) -{ - return; -} - -/** - SMB signing - TEMP implementation - setup the MAC key. - - @note Used as an initialisation only - it will not correctly - shut down a real signing mechanism -*/ -BOOL smbcli_temp_set_signing(struct smbcli_transport *transport) -{ - if (!set_smb_signing_common(transport)) { - return False; - } - - transport->negotiate.sign_info.sign_outgoing_message = smbcli_request_temp_sign_outgoing_message; - transport->negotiate.sign_info.check_incoming_message = smbcli_request_temp_check_incoming_message; - transport->negotiate.sign_info.free_signing_context = smbcli_temp_free_signing_context; - - return True; -} - -/** - * Free the signing context - */ -void smbcli_transport_free_signing_context(struct smb_signing_context *sign_info) -{ - if (sign_info->free_signing_context) { - sign_info->free_signing_context(sign_info); - } - - smbcli_null_set_signing(sign_info); -} - - -/** - * Sign a packet with the current mechanism - */ -void smbcli_request_calculate_sign_mac(struct smbcli_request *req) -{ - req->transport->negotiate.sign_info.sign_outgoing_message(req); -} - - -/** - * Check a packet with the current mechanism - * @return False if we had an established signing connection - * which had a back checksum, True otherwise - */ -BOOL smbcli_request_check_sign_mac(struct smbcli_request *req) -{ - BOOL good; - - if (req->in.size < (HDR_SS_FIELD + 8)) { - good = False; - } else { - good = req->transport->negotiate.sign_info.check_incoming_message(req); - } - - if (!good && req->transport->negotiate.sign_info.doing_signing) { - return False; - } - - return True; -} - - BOOL smbcli_init_signing(struct smbcli_transport *transport) { if (!smbcli_null_set_signing(&transport->negotiate.sign_info)) { @@ -431,7 +361,7 @@ BOOL smbcli_init_signing(struct smbcli_transport *transport) switch (lp_client_signing()) { case SMB_SIGNING_OFF: - transport->negotiate.sign_info.allow_smb_signing = False; + transport->negotiate.sign_info.allow_smb_signing = False; break; case SMB_SIGNING_SUPPORTED: transport->negotiate.sign_info.allow_smb_signing = True; -- cgit From 912e79ade515451152be6b45cc3cc83a9d286827 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 12 Aug 2004 00:37:01 +0000 Subject: r1746: Remove more cruft from the SMB signing code. Andrew Bartlett (This used to be commit b176151b7294b03534921a26db4fb4be1e5d617c) --- source4/libcli/raw/smb_signing.c | 56 ++++++++++++++-------------------------- 1 file changed, 20 insertions(+), 36 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/smb_signing.c b/source4/libcli/raw/smb_signing.c index 03794829c2..09da8e9983 100644 --- a/source4/libcli/raw/smb_signing.c +++ b/source4/libcli/raw/smb_signing.c @@ -21,8 +21,7 @@ */ #include "includes.h" -static void smbcli_free_signing_context(struct smb_signing_context *sign_info); -static BOOL smbcli_null_set_signing(struct smb_signing_context *sign_info); +static BOOL smbcli_set_signing_off(struct smb_signing_context *sign_info); /*********************************************************** SMB signing - Common code before we set a new signing implementation @@ -42,8 +41,6 @@ static BOOL set_smb_signing_common(struct smbcli_transport *transport) return False; } - smbcli_free_signing_context(&transport->negotiate.sign_info); - /* These calls are INCOMPATIBLE with SMB signing */ transport->negotiate.readbraw_supported = False; transport->negotiate.writebraw_supported = False; @@ -74,10 +71,7 @@ static BOOL signing_good(struct smb_signing_context *sign_info, /* If we have never seen a good packet, just turn it off */ DEBUG(5, ("signing_good: signing negotiated but not required and peer\n" "isn't sending correct signatures. Turning off.\n")); - sign_info->doing_signing = False; - smbcli_free_signing_context(sign_info); - - smbcli_null_set_signing(sign_info); + smbcli_set_signing_off(sign_info); return True; } else { /* bad packet after signing started - fail and disconnect. */ @@ -162,25 +156,23 @@ BOOL check_signed_incoming_message(struct request_buffer *in, DATA_BLOB *mac_key good = (memcmp(server_sent_mac, calc_md5_mac, 8) == 0); - if (i == 0) { - if (!good) { - DEBUG(5, ("check_signed_incoming_message: BAD SIG (seq: %d): wanted SMB signature of\n", seq_num + i)); - dump_data(5, calc_md5_mac, 8); - - DEBUG(5, ("check_signed_incoming_message: BAD SIG (seq: %d): got SMB signature of\n", seq_num + i)); - dump_data(5, server_sent_mac, 8); - } else { - DEBUG(15, ("check_signed_incoming_message: GOOD SIG (seq: %d): got SMB signature of\n", seq_num + i)); - dump_data(5, server_sent_mac, 8); - } - } - if (good) break; } if (good && i != 0) { DEBUG(0,("SIGNING OFFSET %d (should be %d)\n", i, seq_num)); } + + if (!good) { + DEBUG(5, ("check_signed_incoming_message: BAD SIG (seq: %d): wanted SMB signature of\n", seq_num + i)); + dump_data(5, calc_md5_mac, 8); + + DEBUG(5, ("check_signed_incoming_message: BAD SIG (seq: %d): got SMB signature of\n", seq_num + i)); + dump_data(5, server_sent_mac, 8); + } else { + DEBUG(15, ("check_signed_incoming_message: GOOD SIG (seq: %d): got SMB signature of\n", seq_num + i)); + dump_data(5, server_sent_mac, 8); + } return good; } @@ -230,14 +222,15 @@ void smbcli_request_calculate_sign_mac(struct smbcli_request *req) /** - SMB signing - NULL implementation - setup the MAC key. + SMB signing - NULL implementation @note Used as an initialisation only - it will not correctly shut down a real signing mechanism */ -static BOOL smbcli_null_set_signing(struct smb_signing_context *sign_info) +static BOOL smbcli_set_signing_off(struct smb_signing_context *sign_info) { - sign_info->mac_key = data_blob(NULL, 0); + sign_info->doing_signing = False; + data_blob_free(&sign_info->mac_key); sign_info->signing_state = SMB_SIGNING_ENGINE_OFF; return True; } @@ -245,14 +238,13 @@ static BOOL smbcli_null_set_signing(struct smb_signing_context *sign_info) /** SMB signing - TEMP implementation - setup the MAC key. - @note Used as an initialisation only - it will not correctly - shut down a real signing mechanism */ BOOL smbcli_temp_set_signing(struct smbcli_transport *transport) { if (!set_smb_signing_common(transport)) { return False; } + smbcli_set_signing_off(&transport->negotiate.sign_info); transport->negotiate.sign_info.mac_key = data_blob(NULL, 0); transport->negotiate.sign_info.signing_state = SMB_SIGNING_ENGINE_BSRSPYL; @@ -260,15 +252,6 @@ BOOL smbcli_temp_set_signing(struct smbcli_transport *transport) return True; } -/** - * Free the signing context - */ -static void smbcli_free_signing_context(struct smb_signing_context *sign_info) -{ - data_blob_free(&sign_info->mac_key); - smbcli_null_set_signing(sign_info); -} - /*********************************************************** SMB signing - Simple implementation - check a MAC sent by server. ************************************************************/ @@ -355,7 +338,8 @@ BOOL smbcli_transport_simple_set_signing(struct smbcli_transport *transport, BOOL smbcli_init_signing(struct smbcli_transport *transport) { - if (!smbcli_null_set_signing(&transport->negotiate.sign_info)) { + transport->negotiate.sign_info.mac_key = data_blob(NULL, 0); + if (!smbcli_set_signing_off(&transport->negotiate.sign_info)) { return False; } -- cgit From f387277b7fa3dc190a6345394aaf79399b88851f Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 12 Aug 2004 07:26:42 +0000 Subject: r1768: Add some debugs to assist in SMB signing debugging. Andrew Bartlett (This used to be commit 32b45fc9e8ff1d0b73bbec1eb1d249af3ec52e46) --- source4/libcli/raw/smb_signing.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/smb_signing.c b/source4/libcli/raw/smb_signing.c index 09da8e9983..0b9c2864d3 100644 --- a/source4/libcli/raw/smb_signing.c +++ b/source4/libcli/raw/smb_signing.c @@ -30,14 +30,17 @@ static BOOL set_smb_signing_common(struct smbcli_transport *transport) { if (!(transport->negotiate.sec_mode & (NEGOTIATE_SECURITY_SIGNATURES_REQUIRED|NEGOTIATE_SECURITY_SIGNATURES_ENABLED))) { + DEBUG(5, ("SMB Signing is not negotiated by the peer\n")); return False; } if (transport->negotiate.sign_info.doing_signing) { + DEBUG(5, ("SMB Signing already in progress, so we don't start it again\n")); return False; } if (!transport->negotiate.sign_info.allow_smb_signing) { + DEBUG(5, ("SMB Signing has been locally disabled\n")); return False; } @@ -61,9 +64,11 @@ static BOOL signing_good(struct smb_signing_context *sign_info, { if (good) { if (!sign_info->doing_signing) { + DEBUG(5, ("Seen valid packet, so turning signing on\n")); sign_info->doing_signing = True; } if (!sign_info->seen_valid) { + DEBUG(5, ("Seen valid packet, so marking signing as 'seen valid'\n")); sign_info->seen_valid = True; } } else { @@ -130,6 +135,11 @@ BOOL check_signed_incoming_message(struct request_buffer *in, DATA_BLOB *mac_key return False; } + if (!mac_key->length) { + /* NO key yet */ + return False; + } + /* its quite bogus to be guessing sequence numbers, but very useful when debugging signing implementations */ for (i = 0-sign_range; i <= 0+sign_range; i++) { @@ -229,6 +239,7 @@ void smbcli_request_calculate_sign_mac(struct smbcli_request *req) */ static BOOL smbcli_set_signing_off(struct smb_signing_context *sign_info) { + DEBUG(5, ("Shutdown SMB signing\n")); sign_info->doing_signing = False; data_blob_free(&sign_info->mac_key); sign_info->signing_state = SMB_SIGNING_ENGINE_OFF; @@ -244,6 +255,7 @@ BOOL smbcli_temp_set_signing(struct smbcli_transport *transport) if (!set_smb_signing_common(transport)) { return False; } + DEBUG(5, ("BSRSPYL SMB signing enabled\n")); smbcli_set_signing_off(&transport->negotiate.sign_info); transport->negotiate.sign_info.mac_key = data_blob(NULL, 0); -- cgit From 63c5ca7d583691fae5ccf0b760f24b9d11a2141b Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 12 Aug 2004 07:29:49 +0000 Subject: r1769: Add a new torture test to check vuid properties, and SPNEGO/non-SPNEGO games. Andrew Bartlett (This used to be commit 90d70a63ee6d44172cec99a9115817f666b5d06d) --- source4/libcli/raw/clisession.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index b32d59f340..f46c238378 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -394,7 +394,7 @@ static NTSTATUS smb_raw_session_setup_generic_spnego(struct smbcli_session *sess s2.spnego.in.domain = parms->generic.in.domain; s2.spnego.in.os = "Unix"; s2.spnego.in.lanman = "Samba"; - s2.spnego.out.vuid = UID_FIELD_INVALID; + s2.spnego.out.vuid = session->vuid; smbcli_temp_set_signing(session->transport); -- cgit From 7b088a8f654f34911928dcdf320ca3cf79592aed Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 13 Aug 2004 00:16:57 +0000 Subject: r1796: Enable server-side SPNEGO, now that I have fixed the server-side SMB signing code to be able to cope. Andrew Bartlett (This used to be commit cb74d52b563730a50e33c92d868c45ee96a598e8) --- source4/libcli/raw/smb_signing.c | 109 ++++++++++++++++++++++++--------------- 1 file changed, 66 insertions(+), 43 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/smb_signing.c b/source4/libcli/raw/smb_signing.c index 0b9c2864d3..bd29abe3e6 100644 --- a/source4/libcli/raw/smb_signing.c +++ b/source4/libcli/raw/smb_signing.c @@ -21,26 +21,37 @@ */ #include "includes.h" -static BOOL smbcli_set_signing_off(struct smb_signing_context *sign_info); /*********************************************************** SMB signing - Common code before we set a new signing implementation ************************************************************/ -static BOOL set_smb_signing_common(struct smbcli_transport *transport) +BOOL set_smb_signing_common(struct smb_signing_context *sign_info) { - if (!(transport->negotiate.sec_mode & - (NEGOTIATE_SECURITY_SIGNATURES_REQUIRED|NEGOTIATE_SECURITY_SIGNATURES_ENABLED))) { - DEBUG(5, ("SMB Signing is not negotiated by the peer\n")); + if (sign_info->doing_signing) { + DEBUG(5, ("SMB Signing already in progress, so we don't start it again\n")); return False; } - if (transport->negotiate.sign_info.doing_signing) { - DEBUG(5, ("SMB Signing already in progress, so we don't start it again\n")); + if (!sign_info->allow_smb_signing) { + DEBUG(5, ("SMB Signing has been locally disabled\n")); return False; } - if (!transport->negotiate.sign_info.allow_smb_signing) { - DEBUG(5, ("SMB Signing has been locally disabled\n")); + return True; +} + +/*********************************************************** + SMB signing - Common code before we set a new signing implementation +************************************************************/ +static BOOL smbcli_set_smb_signing_common(struct smbcli_transport *transport) +{ + if (!set_smb_signing_common(&transport->negotiate.sign_info)) { + return False; + } + + if (!(transport->negotiate.sec_mode & + (NEGOTIATE_SECURITY_SIGNATURES_REQUIRED|NEGOTIATE_SECURITY_SIGNATURES_ENABLED))) { + DEBUG(5, ("SMB Signing is not negotiated by the peer\n")); return False; } @@ -51,7 +62,7 @@ static BOOL set_smb_signing_common(struct smbcli_transport *transport) return True; } -static void mark_packet_signed(struct request_buffer *out) +void mark_packet_signed(struct request_buffer *out) { uint16_t flags2; flags2 = SVAL(out->hdr, HDR_FLG2); @@ -59,7 +70,7 @@ static void mark_packet_signed(struct request_buffer *out) SSVAL(out->hdr, HDR_FLG2, flags2); } -static BOOL signing_good(struct smb_signing_context *sign_info, +BOOL signing_good(struct smb_signing_context *sign_info, unsigned int seq, BOOL good) { if (good) { @@ -166,6 +177,19 @@ BOOL check_signed_incoming_message(struct request_buffer *in, DATA_BLOB *mac_key good = (memcmp(server_sent_mac, calc_md5_mac, 8) == 0); + if (i == 0) { + if (!good) { + DEBUG(5, ("check_signed_incoming_message: BAD SIG (seq: %d): wanted SMB signature of\n", seq_num + i)); + dump_data(5, calc_md5_mac, 8); + + DEBUG(5, ("check_signed_incoming_message: BAD SIG (seq: %d): got SMB signature of\n", seq_num + i)); + dump_data(5, server_sent_mac, 8); + } else { + DEBUG(15, ("check_signed_incoming_message: GOOD SIG (seq: %d): got SMB signature of\n", seq_num + i)); + dump_data(5, server_sent_mac, 8); + } + } + if (good) break; } @@ -173,17 +197,20 @@ BOOL check_signed_incoming_message(struct request_buffer *in, DATA_BLOB *mac_key DEBUG(0,("SIGNING OFFSET %d (should be %d)\n", i, seq_num)); } - if (!good) { - DEBUG(5, ("check_signed_incoming_message: BAD SIG (seq: %d): wanted SMB signature of\n", seq_num + i)); - dump_data(5, calc_md5_mac, 8); - - DEBUG(5, ("check_signed_incoming_message: BAD SIG (seq: %d): got SMB signature of\n", seq_num + i)); - dump_data(5, server_sent_mac, 8); + return good; +} + +static void smbcli_req_allocate_seq_num(struct smbcli_request *req) +{ + req->seq_num = req->transport->negotiate.sign_info.next_seq_num; + + /* some requests (eg. NTcancel) are one way, and the sequence number + should be increased by 1 not 2 */ + if (req->sign_single_increment) { + req->transport->negotiate.sign_info.next_seq_num += 1; } else { - DEBUG(15, ("check_signed_incoming_message: GOOD SIG (seq: %d): got SMB signature of\n", seq_num + i)); - dump_data(5, server_sent_mac, 8); + req->transport->negotiate.sign_info.next_seq_num += 2; } - return good; } /*********************************************************** @@ -212,16 +239,7 @@ void smbcli_request_calculate_sign_mac(struct smbcli_request *req) case SMB_SIGNING_ENGINE_ON: - req->seq_num = req->transport->negotiate.sign_info.next_seq_num; - - /* some requests (eg. NTcancel) are one way, and the sequence number - should be increased by 1 not 2 */ - if (req->sign_single_increment) { - req->transport->negotiate.sign_info.next_seq_num += 1; - } else { - req->transport->negotiate.sign_info.next_seq_num += 2; - } - + smbcli_req_allocate_seq_num(req); sign_outgoing_message(&req->out, &req->transport->negotiate.sign_info.mac_key, req->seq_num); @@ -237,10 +255,11 @@ void smbcli_request_calculate_sign_mac(struct smbcli_request *req) @note Used as an initialisation only - it will not correctly shut down a real signing mechanism */ -static BOOL smbcli_set_signing_off(struct smb_signing_context *sign_info) +BOOL smbcli_set_signing_off(struct smb_signing_context *sign_info) { DEBUG(5, ("Shutdown SMB signing\n")); sign_info->doing_signing = False; + sign_info->next_seq_num = 0; data_blob_free(&sign_info->mac_key); sign_info->signing_state = SMB_SIGNING_ENGINE_OFF; return True; @@ -252,7 +271,7 @@ static BOOL smbcli_set_signing_off(struct smb_signing_context *sign_info) */ BOOL smbcli_temp_set_signing(struct smbcli_transport *transport) { - if (!set_smb_signing_common(transport)) { + if (!smbcli_set_smb_signing_common(transport)) { return False; } DEBUG(5, ("BSRSPYL SMB signing enabled\n")); @@ -302,9 +321,9 @@ BOOL smbcli_request_check_sign_mac(struct smbcli_request *req) /*********************************************************** SMB signing - Simple implementation - setup the MAC key. ************************************************************/ -static BOOL smbcli_simple_set_signing(struct smb_signing_context *sign_info, - const DATA_BLOB user_session_key, - const DATA_BLOB response) +BOOL smbcli_simple_set_signing(struct smb_signing_context *sign_info, + const DATA_BLOB *user_session_key, + const DATA_BLOB *response) { if (sign_info->mandatory_signing) { DEBUG(5, ("Mandatory SMB signing enabled!\n")); @@ -312,12 +331,16 @@ static BOOL smbcli_simple_set_signing(struct smb_signing_context *sign_info, DEBUG(5, ("SMB signing enabled!\n")); - sign_info->mac_key = data_blob(NULL, response.length + user_session_key.length); - - memcpy(&sign_info->mac_key.data[0], user_session_key.data, user_session_key.length); + if (response && response->length) { + sign_info->mac_key = data_blob(NULL, response->length + user_session_key->length); + } else { + sign_info->mac_key = data_blob(NULL, user_session_key->length); + } + + memcpy(&sign_info->mac_key.data[0], user_session_key->data, user_session_key->length); - if (response.length) { - memcpy(&sign_info->mac_key.data[user_session_key.length],response.data, response.length); + if (response && response->length) { + memcpy(&sign_info->mac_key.data[user_session_key->length],response->data, response->length); } dump_data_pw("Started Signing with key:\n", sign_info->mac_key.data, sign_info->mac_key.length); @@ -338,13 +361,13 @@ BOOL smbcli_transport_simple_set_signing(struct smbcli_transport *transport, const DATA_BLOB user_session_key, const DATA_BLOB response) { - if (!set_smb_signing_common(transport)) { + if (!smbcli_set_smb_signing_common(transport)) { return False; } return smbcli_simple_set_signing(&transport->negotiate.sign_info, - user_session_key, - response); + &user_session_key, + &response); } -- cgit From 64082214337e2ab50f0a69ca7f9bcf56762129cc Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 14 Aug 2004 05:56:12 +0000 Subject: r1819: changed "smb ports" to be a LIST parameter type in loadparm (its a classic case for a list) (This used to be commit e53d32c65ab0751b3e01f4f699f5d0e1892369ae) --- source4/libcli/raw/clisocket.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 78d37b9be1..b09bebf133 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -62,8 +62,15 @@ BOOL smbcli_sock_connect(struct smbcli_socket *sock, struct in_addr *ip, int por } if (port == 0) { - return smbcli_sock_connect(sock, ip, 445) || - smbcli_sock_connect(sock, ip, 139); + int i; + const char **ports = lp_smb_ports(); + for (i=0;ports[i];i++) { + int port = atoi(ports[i]); + if (port != 0 && smbcli_sock_connect(sock, ip, port)) { + return True; + } + } + return False; } sock->dest_ip = *ip; -- cgit From 39686072d5539003f8a2e2679311c5057ee82041 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 14 Aug 2004 18:24:33 +0000 Subject: r1824: nicer handling of NBT session replies, and handling of bad packets with the async SMB code (This used to be commit cef94978f43a8326b6cf1888c15ca8c568ebe9f8) --- source4/libcli/raw/clitransport.c | 6 ++++++ source4/libcli/raw/rawrequest.c | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 784a6f1798..03a0540be0 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -353,6 +353,12 @@ static void smbcli_transport_finish_recv(struct smbcli_transport *transport) req->in.size = len; req->in.allocated = req->in.size; + /* handle NBT session replies */ + if (req->in.buffer[0] != 0) { + req->status = NT_STATUS_OK; + goto async; + } + /* handle non-SMB replies */ if (req->in.size < NBT_HDR_SIZE + MIN_SMB_SIZE) { req->state = SMBCLI_REQUEST_ERROR; diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 70e924a99f..bc87af4297 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -252,7 +252,7 @@ static void smbcli_req_grow_allocation(struct smbcli_request *req, uint_t new_si To cope with this req->out.ptr is supplied. This will be updated to point at the same offset into the packet as before this call */ -static void smbcli_req_grow_data(struct smbcli_request *req, uint_t new_size) +void smbcli_req_grow_data(struct smbcli_request *req, uint_t new_size) { int delta; @@ -299,7 +299,7 @@ BOOL smbcli_request_receive(struct smbcli_request *req) event_loop_once(req->transport->event.ctx); } - return True; + return req->state == SMBCLI_REQUEST_DONE; } -- cgit From 7d032a99927d3d4ddfc5561e8a96d0315a28ed35 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 18 Aug 2004 13:43:53 +0000 Subject: r1883: I don't know why this was broken... tridge: can you please check if this is correct, I have only compiled it, but haven'T run it. metze (This used to be commit d3123c2e7357d8db4dce9e0253ac405318d05c48) --- source4/libcli/raw/rawacl.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawacl.c b/source4/libcli/raw/rawacl.c index 77374ae8b9..dde6b673a0 100644 --- a/source4/libcli/raw/rawacl.c +++ b/source4/libcli/raw/rawacl.c @@ -84,7 +84,7 @@ NTSTATUS smb_raw_query_secdesc_recv(struct smbcli_request *req, } status = ndr_pull_security_descriptor(ndr, NDR_SCALARS|NDR_BUFFERS, query->out.sd); - return NT_STATUS_OK; + return status; } @@ -130,12 +130,12 @@ struct smbcli_request *smb_raw_set_secdesc_send(struct smbcli_tree *tree, ndr = ndr_push_init(); if (!ndr) return NULL; -// status = ndr_push_security_descriptor(ndr, set->in.sd); + status = ndr_push_security_descriptor(ndr, NDR_SCALARS|NDR_BUFFERS, set->in.sd); if (!NT_STATUS_IS_OK(status)) { ndr_push_free(ndr); return NULL; } - + nt.in.data = ndr_push_blob(ndr); req = smb_raw_nttrans_send(tree, &nt); -- cgit From acc885855ac17d3fafaa309ac2e6b7ac3c899f52 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 18 Aug 2004 18:31:23 +0000 Subject: r1893: add a commented out lump of code to implement the "by the SPEC" ALL_INFO queryfileinfo level. It is useful having it here as many non-Microsoft servers implement it this way, which breaks just about all the torture tests, so when testing against these broken systems just change this one #if line and recompile smbtorture. (This used to be commit cd8887293e7735d8ee1cc2daebda233673801775) --- source4/libcli/raw/rawfileinfo.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawfileinfo.c b/source4/libcli/raw/rawfileinfo.c index 8dc220b0b4..9b82bf6fa0 100644 --- a/source4/libcli/raw/rawfileinfo.c +++ b/source4/libcli/raw/rawfileinfo.c @@ -138,9 +138,24 @@ static NTSTATUS smb_raw_info_backend(struct smbcli_session *session, parms->all_info.out.nlink = IVAL(blob->data, 56); parms->all_info.out.delete_pending = CVAL(blob->data, 60); parms->all_info.out.directory = CVAL(blob->data, 61); +#if 1 parms->all_info.out.ea_size = IVAL(blob->data, 64); smbcli_blob_pull_string(session, mem_ctx, blob, &parms->all_info.out.fname, 68, 72, STR_UNICODE); +#else + /* this is what the CIFS spec says - and its totally + wrong, but its useful having it here so we can + quickly adapt to broken servers when running + tests */ + parms->all_info.out.ea_size = IVAL(blob->data, 72); + /* access flags 4 bytes at 76 + current_position 8 bytes at 80 + mode 4 bytes at 88 + alignment 4 bytes at 92 + */ + smbcli_blob_pull_string(session, mem_ctx, blob, + &parms->all_info.out.fname, 96, 100, STR_UNICODE); +#endif return NT_STATUS_OK; case RAW_FILEINFO_ALT_NAME_INFO: -- cgit From 5f1f1e5e5c52ec8c453b5ea688f87004541cc5bd Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 18 Aug 2004 20:07:44 +0000 Subject: r1896: stricter check on packet parsing for NBT session replies (This used to be commit 30ab38559e8c52ecdaf7ca9b124875ade82c5c66) --- source4/libcli/raw/clitransport.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 03a0540be0..91f0f0f8f5 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -354,7 +354,7 @@ static void smbcli_transport_finish_recv(struct smbcli_transport *transport) req->in.allocated = req->in.size; /* handle NBT session replies */ - if (req->in.buffer[0] != 0) { + if (req->in.size >= 4 && req->in.buffer[0] != 0) { req->status = NT_STATUS_OK; goto async; } -- cgit From 1129c7808354dc04f7725be505fd23c0bf11a29d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 18 Aug 2004 20:13:08 +0000 Subject: r1897: added a choose_called_name() function that allows us to more sanely handle connections using the IP as the server name, while not trying for NBT name resolution on names like "192" and "192.168.1.2". also removed the ip address argument to smbcli_socket_connect() as it isn't used and doesn't really make sense. (This used to be commit 2ce4028842556328da4da0de9bee942bed02cc62) --- source4/libcli/raw/clitree.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index b9d572fd56..97c0910451 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -173,11 +173,11 @@ NTSTATUS smb_tree_disconnect(struct smbcli_tree *tree) parameters */ NTSTATUS smbcli_tree_full_connection(struct smbcli_tree **ret_tree, - const char *my_name, - const char *dest_host, int port, - const char *service, const char *service_type, - const char *user, const char *domain, - const char *password) + const char *my_name, + const char *dest_host, int port, + const char *service, const char *service_type, + const char *user, const char *domain, + const char *password) { struct smbcli_socket *sock; struct smbcli_transport *transport; @@ -212,7 +212,7 @@ NTSTATUS smbcli_tree_full_connection(struct smbcli_tree **ret_tree, /* send a NBT session request, if applicable */ make_nmb_name(&calling, my_name, 0x0); - make_nmb_name(&called, dest_host, 0x20); + choose_called_name(&called, dest_host, 0x20); if (!smbcli_transport_connect(transport, &calling, &called)) { smbcli_transport_close(transport); -- cgit From f42f0612364045702cea7e66cacd24aa20ecb54e Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 19 Aug 2004 11:37:36 +0000 Subject: r1910: this should not be a local var in this block metze (This used to be commit 0164cac6df46ca5996aae30b8c48a602999f7e0b) --- source4/libcli/raw/clisocket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index b09bebf133..343904999a 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -65,7 +65,7 @@ BOOL smbcli_sock_connect(struct smbcli_socket *sock, struct in_addr *ip, int por int i; const char **ports = lp_smb_ports(); for (i=0;ports[i];i++) { - int port = atoi(ports[i]); + port = atoi(ports[i]); if (port != 0 && smbcli_sock_connect(sock, ip, port)) { return True; } -- cgit From 8d6e233f66616c97fcce935253e56cdd6117242e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 20 Aug 2004 00:03:13 +0000 Subject: r1941: - fixed an allocation error with querying security descriptors remotely - print the received security_descriptor in the smbclient "acl" command - make sure we zero the alignment data in nttrans packet sends (This used to be commit 8925b8b2193905d084e1bfaaa3235ed7f9d1eb55) --- source4/libcli/raw/rawacl.c | 2 +- source4/libcli/raw/rawtrans.c | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawacl.c b/source4/libcli/raw/rawacl.c index dde6b673a0..20e6d6df31 100644 --- a/source4/libcli/raw/rawacl.c +++ b/source4/libcli/raw/rawacl.c @@ -78,7 +78,7 @@ NTSTATUS smb_raw_query_secdesc_recv(struct smbcli_request *req, return NT_STATUS_INVALID_PARAMETER; } - query->out.sd = talloc(mem_ctx, sizeof(query->out.sd)); + query->out.sd = talloc_p(mem_ctx, struct security_descriptor); if (!query->out.sd) { return NT_STATUS_NO_MEMORY; } diff --git a/source4/libcli/raw/rawtrans.c b/source4/libcli/raw/rawtrans.c index 0c39abe880..53f8075822 100644 --- a/source4/libcli/raw/rawtrans.c +++ b/source4/libcli/raw/rawtrans.c @@ -480,6 +480,10 @@ struct smbcli_request *smb_raw_nttrans_send(struct smbcli_tree *tree, outparam = req->out.data + align; outdata = outparam + parms->in.params.length; + if (align != 0) { + memset(req->out.data, 0, align); + } + SCVAL(req->out.vwv, 0, parms->in.max_setup); SSVAL(req->out.vwv, 1, 0); /* reserved */ SIVAL(req->out.vwv, 3, parms->in.params.length); -- cgit From b83ba93eaeb2dcb0bf11615591d886fda84e4162 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 21 Aug 2004 01:54:46 +0000 Subject: r1983: a completely new implementation of talloc This version does the following: 1) talloc_free(), talloc_realloc() and talloc_steal() lose their (redundent) first arguments 2) you can use _any_ talloc pointer as a talloc context to allocate more memory. This allows you to create complex data structures where the top level structure is the logical parent of the next level down, and those are the parents of the level below that. Then destroy either the lot with a single talloc_free() or destroy any sub-part with a talloc_free() of that part 3) you can name any pointer. Use talloc_named() which is just like talloc() but takes the printf style name argument as well as the parent context and the size. The whole thing ends up being a very simple piece of code, although some of the pointer walking gets hairy. So far, I'm just using the new talloc() like the old one. The next step is to actually take advantage of the new interface properly. Expect some new commits soon that simplify some common coding styles in samba4 by using the new talloc(). (This used to be commit e35bb094c52e550b3105dd1638d8d90de71d854f) --- source4/libcli/raw/clisession.c | 2 +- source4/libcli/raw/clisocket.c | 2 +- source4/libcli/raw/clitransport.c | 8 ++++---- source4/libcli/raw/clitree.c | 2 +- source4/libcli/raw/raweas.c | 2 +- source4/libcli/raw/rawfile.c | 6 +++--- source4/libcli/raw/rawfileinfo.c | 2 +- source4/libcli/raw/rawreadwrite.c | 4 ++-- source4/libcli/raw/rawrequest.c | 4 ++-- source4/libcli/raw/rawtrans.c | 4 ++-- 10 files changed, 18 insertions(+), 18 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index f46c238378..0ee631a549 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -69,7 +69,7 @@ void smbcli_session_close(struct smbcli_session *session) ****************************************************************************/ struct smbcli_request *smb_raw_session_setup_send(struct smbcli_session *session, union smb_sesssetup *parms) { - struct smbcli_request *req; + struct smbcli_request *req = NULL; switch (parms->generic.level) { case RAW_SESSSETUP_GENERIC: diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 343904999a..2bb50d200f 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -181,7 +181,7 @@ BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, in ret = smbcli_sock_connect(sock, &ip, port); if (ret) { - sock->hostname = talloc_steal(mem_ctx, sock->mem_ctx, name); + sock->hostname = talloc_steal(sock->mem_ctx, name); } talloc_destroy(mem_ctx); diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 91f0f0f8f5..82939467ae 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -296,7 +296,7 @@ static void smbcli_transport_finish_recv(struct smbcli_transport *transport) { uint8_t *buffer, *hdr, *vwv; int len; - uint16_t wct, mid = 0; + uint16_t wct=0, mid = 0; struct smbcli_request *req; buffer = transport->recv_buffer.buffer; @@ -309,7 +309,7 @@ static void smbcli_transport_finish_recv(struct smbcli_transport *transport) /* see if it could be an oplock break request */ if (handle_oplock_break(transport, len, hdr, vwv)) { - talloc_free(transport->mem_ctx, buffer); + talloc_free(buffer); return; } @@ -325,7 +325,7 @@ static void smbcli_transport_finish_recv(struct smbcli_transport *transport) if (!req) goto error; req->in.buffer = buffer; - talloc_steal(transport->mem_ctx, req->mem_ctx, buffer); + talloc_steal(req->mem_ctx, buffer); req->in.size = len; req->in.allocated = req->in.size; goto async; @@ -349,7 +349,7 @@ static void smbcli_transport_finish_recv(struct smbcli_transport *transport) /* fill in the 'in' portion of the matching request */ req->in.buffer = buffer; - talloc_steal(transport->mem_ctx, req->mem_ctx, buffer); + talloc_steal(req->mem_ctx, buffer); req->in.size = len; req->in.allocated = req->in.size; diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index 97c0910451..57e322da32 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -70,7 +70,7 @@ void smbcli_tree_close(struct smbcli_tree *tree) ****************************************************************************/ struct smbcli_request *smb_tree_connect_send(struct smbcli_tree *tree, union smb_tcon *parms) { - struct smbcli_request *req; + struct smbcli_request *req = NULL; switch (parms->tcon.level) { case RAW_TCON_TCON: diff --git a/source4/libcli/raw/raweas.c b/source4/libcli/raw/raweas.c index e07fbcd288..d78f10fe1a 100644 --- a/source4/libcli/raw/raweas.c +++ b/source4/libcli/raw/raweas.c @@ -128,7 +128,7 @@ NTSTATUS ea_pull_list(const DATA_BLOB *blob, blob2.data = blob->data + ofs; blob2.length = ea_size - ofs; - *eas = talloc_realloc(mem_ctx, *eas, sizeof(**eas) * (n+1)); + *eas = talloc_realloc(*eas, sizeof(**eas) * (n+1)); if (! *eas) return NT_STATUS_NO_MEMORY; len = ea_pull_struct(&blob2, mem_ctx, &(*eas)[n]); diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c index 8bd8e5d8af..1b858d489a 100644 --- a/source4/libcli/raw/rawfile.c +++ b/source4/libcli/raw/rawfile.c @@ -34,7 +34,7 @@ struct smbcli_request *smb_raw_rename_send(struct smbcli_tree *tree, union smb_rename *parms) { - struct smbcli_request *req; + struct smbcli_request *req = NULL; switch (parms->generic.level) { case RAW_RENAME_RENAME: @@ -490,7 +490,7 @@ NTSTATUS smb_raw_open(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_o ****************************************************************************/ struct smbcli_request *smb_raw_close_send(struct smbcli_tree *tree, union smb_close *parms) { - struct smbcli_request *req; + struct smbcli_request *req = NULL; switch (parms->generic.level) { case RAW_CLOSE_GENERIC: @@ -536,7 +536,7 @@ NTSTATUS smb_raw_close(struct smbcli_tree *tree, union smb_close *parms) ****************************************************************************/ struct smbcli_request *smb_raw_lock_send(struct smbcli_tree *tree, union smb_lock *parms) { - struct smbcli_request *req; + struct smbcli_request *req = NULL; switch (parms->generic.level) { case RAW_LOCK_GENERIC: diff --git a/source4/libcli/raw/rawfileinfo.c b/source4/libcli/raw/rawfileinfo.c index 9b82bf6fa0..aac8f2657b 100644 --- a/source4/libcli/raw/rawfileinfo.c +++ b/source4/libcli/raw/rawfileinfo.c @@ -174,7 +174,7 @@ static NTSTATUS smb_raw_info_backend(struct smbcli_session *session, while (blob->length - ofs >= 24) { uint_t n = parms->stream_info.out.num_streams; parms->stream_info.out.streams = - talloc_realloc(mem_ctx,parms->stream_info.out.streams, + talloc_realloc(parms->stream_info.out.streams, (n+1) * sizeof(parms->stream_info.out.streams[0])); if (!parms->stream_info.out.streams) { return NT_STATUS_NO_MEMORY; diff --git a/source4/libcli/raw/rawreadwrite.c b/source4/libcli/raw/rawreadwrite.c index f0a9a063ed..dbca6fb7a5 100644 --- a/source4/libcli/raw/rawreadwrite.c +++ b/source4/libcli/raw/rawreadwrite.c @@ -33,7 +33,7 @@ struct smbcli_request *smb_raw_read_send(struct smbcli_tree *tree, union smb_read *parms) { BOOL bigoffset = False; - struct smbcli_request *req; + struct smbcli_request *req = NULL; switch (parms->generic.level) { case RAW_READ_GENERIC: @@ -185,7 +185,7 @@ NTSTATUS smb_raw_read(struct smbcli_tree *tree, union smb_read *parms) struct smbcli_request *smb_raw_write_send(struct smbcli_tree *tree, union smb_write *parms) { BOOL bigoffset = False; - struct smbcli_request *req; + struct smbcli_request *req = NULL; switch (parms->generic.level) { case RAW_WRITE_GENERIC: diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index bc87af4297..20a389af4c 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -224,7 +224,7 @@ static void smbcli_req_grow_allocation(struct smbcli_request *req, uint_t new_si /* we need to realloc */ req->out.allocated = req->out.size + delta + REQ_OVER_ALLOCATION; - buf2 = talloc_realloc(req->mem_ctx, req->out.buffer, req->out.allocated); + buf2 = talloc_realloc(req->out.buffer, req->out.allocated); if (buf2 == NULL) { smb_panic("out of memory in req_grow_allocation"); } @@ -915,7 +915,7 @@ size_t smbcli_blob_append_string(struct smbcli_session *session, max_len = (strlen(str)+2) * MAX_BYTES_PER_CHAR; - blob->data = talloc_realloc(mem_ctx, blob->data, blob->length + max_len); + blob->data = talloc_realloc(blob->data, blob->length + max_len); if (!blob->data) { return 0; } diff --git a/source4/libcli/raw/rawtrans.c b/source4/libcli/raw/rawtrans.c index 53f8075822..49b43dd930 100644 --- a/source4/libcli/raw/rawtrans.c +++ b/source4/libcli/raw/rawtrans.c @@ -84,7 +84,7 @@ NTSTATUS smb_raw_trans2_recv(struct smbcli_request *req, /* allocate it */ if (total_data != 0) { - tdata = talloc_realloc(mem_ctx, parms->out.data.data,total_data); + tdata = talloc_realloc(parms->out.data.data,total_data); if (!tdata) { DEBUG(0,("smb_raw_receive_trans: failed to enlarge data buffer to %d bytes\n", total_data)); req->status = NT_STATUS_NO_MEMORY; @@ -94,7 +94,7 @@ NTSTATUS smb_raw_trans2_recv(struct smbcli_request *req, } if (total_param != 0) { - tparam = talloc_realloc(mem_ctx, parms->out.params.data,total_param); + tparam = talloc_realloc(parms->out.params.data,total_param); if (!tparam) { DEBUG(0,("smb_raw_receive_trans: failed to enlarge param buffer to %d bytes\n", total_param)); req->status = NT_STATUS_NO_MEMORY; -- cgit From b45f4ebbb880e41abf86abb54264123f3edbde05 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 21 Aug 2004 02:07:12 +0000 Subject: r1984: this change is what you should read to understand the new talloc() It simplifies our structure handling a lot, making the code shorter and easier to understand. Look at the diff carefully and see if you can understand it. If you're still confused then please ask. (This used to be commit 03c341aca7f09cb1f0d33ec65e074e6a00caa30f) --- source4/libcli/raw/clitransport.c | 4 ++-- source4/libcli/raw/rawrequest.c | 17 +++-------------- 2 files changed, 5 insertions(+), 16 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 82939467ae..5766fde03a 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -325,7 +325,7 @@ static void smbcli_transport_finish_recv(struct smbcli_transport *transport) if (!req) goto error; req->in.buffer = buffer; - talloc_steal(req->mem_ctx, buffer); + talloc_steal(req, buffer); req->in.size = len; req->in.allocated = req->in.size; goto async; @@ -349,7 +349,7 @@ static void smbcli_transport_finish_recv(struct smbcli_transport *transport) /* fill in the 'in' portion of the matching request */ req->in.buffer = buffer; - talloc_steal(req->mem_ctx, buffer); + talloc_steal(req, buffer); req->in.size = len; req->in.allocated = req->in.size; diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 20a389af4c..87bbe5a31b 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -49,7 +49,7 @@ NTSTATUS smbcli_request_destroy(struct smbcli_request *req) /* ahh, its so nice to destroy a complex structure in such a simple way! */ status = req->status; - talloc_destroy(req->mem_ctx); + talloc_free(req); return status; } @@ -61,18 +61,8 @@ NTSTATUS smbcli_request_destroy(struct smbcli_request *req) struct smbcli_request *smbcli_request_setup_nonsmb(struct smbcli_transport *transport, uint_t size) { struct smbcli_request *req; - TALLOC_CTX *mem_ctx; - - /* each request gets its own talloc context. The request - structure itself is also allocated inside this context, - so we need to allocate it before we construct the request - */ - mem_ctx = talloc_init("smbcli_request"); - if (!mem_ctx) { - return NULL; - } - req = talloc(mem_ctx, sizeof(struct smbcli_request)); + req = talloc_named(NULL, sizeof(struct smbcli_request), "smcli_request"); if (!req) { return NULL; } @@ -80,7 +70,6 @@ struct smbcli_request *smbcli_request_setup_nonsmb(struct smbcli_transport *tran /* setup the request context */ req->state = SMBCLI_REQUEST_INIT; - req->mem_ctx = mem_ctx; req->transport = transport; req->session = NULL; req->tree = NULL; @@ -89,7 +78,7 @@ struct smbcli_request *smbcli_request_setup_nonsmb(struct smbcli_transport *tran /* over allocate by a small amount */ req->out.allocated = req->out.size + REQ_OVER_ALLOCATION; - req->out.buffer = talloc(req->mem_ctx, req->out.allocated); + req->out.buffer = talloc(req, req->out.allocated); if (!req->out.buffer) { return NULL; } -- cgit From b7e1ea20dc873a753ff64653987130f03897a4e9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 21 Aug 2004 07:43:29 +0000 Subject: r1985: take advantage of the new talloc in a few more places (This used to be commit 6ffdfd779936ce8c5ca49c5f444e8da2bbeee0a8) --- source4/libcli/raw/clisession.c | 13 ++++--------- source4/libcli/raw/clisocket.c | 23 +++++++---------------- source4/libcli/raw/clitransport.c | 15 ++++++--------- source4/libcli/raw/clitree.c | 15 +++++---------- source4/libcli/raw/rawnegotiate.c | 10 +++++----- 5 files changed, 27 insertions(+), 49 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index 0ee631a549..af8a63328c 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -32,18 +32,13 @@ struct smbcli_session *smbcli_session_init(struct smbcli_transport *transport) { struct smbcli_session *session; - TALLOC_CTX *mem_ctx = talloc_init("smbcli_session"); - if (mem_ctx == NULL) { - return NULL; - } - session = talloc_zero(mem_ctx, sizeof(*session)); + session = talloc_named(NULL, sizeof(*session), "smbcli_session"); if (!session) { - talloc_destroy(mem_ctx); return NULL; } - session->mem_ctx = mem_ctx; + ZERO_STRUCTP(session); session->transport = transport; session->pid = (uint16_t)getpid(); session->vuid = UID_FIELD_INVALID; @@ -60,7 +55,7 @@ void smbcli_session_close(struct smbcli_session *session) session->reference_count--; if (session->reference_count <= 0) { smbcli_transport_close(session->transport); - talloc_destroy(session->mem_ctx); + talloc_free(session); } } @@ -242,7 +237,7 @@ static DATA_BLOB nt_blob(const char *pass, DATA_BLOB challenge) void smbcli_session_set_user_session_key(struct smbcli_session *session, const DATA_BLOB *session_key) { - session->user_session_key = data_blob_talloc(session->mem_ctx, + session->user_session_key = data_blob_talloc(session, session_key->data, session_key->length); } diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 2bb50d200f..94bb447f47 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -28,18 +28,13 @@ struct smbcli_socket *smbcli_sock_init(void) { struct smbcli_socket *sock; - TALLOC_CTX *mem_ctx; - mem_ctx = talloc_init("smbcli_socket"); - if (!mem_ctx) return NULL; - - sock = talloc_zero(mem_ctx, sizeof(*sock)); + sock = talloc_named(NULL, sizeof(*sock), "smbcli_socket"); if (!sock) { - talloc_destroy(mem_ctx); return NULL; } - sock->mem_ctx = mem_ctx; + ZERO_STRUCTP(sock); sock->fd = -1; sock->port = 0; /* 20 second default timeout */ @@ -153,7 +148,6 @@ BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, in { int name_type = 0x20; struct in_addr ip; - TALLOC_CTX *mem_ctx; char *name, *p; BOOL ret; @@ -162,10 +156,7 @@ BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, in return sock->fd != -1; } - mem_ctx = talloc_init("smbcli_sock_connect_byname"); - if (!mem_ctx) return False; - - name = talloc_strdup(mem_ctx, host); + name = talloc_strdup(sock, host); /* allow hostnames of the form NAME#xx and do a netbios lookup */ if ((p = strchr(name, '#'))) { @@ -173,18 +164,18 @@ BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, in *p = 0; } - if (!resolve_name(mem_ctx, name, &ip, name_type)) { - talloc_destroy(mem_ctx); + if (!resolve_name(name, name, &ip, name_type)) { + talloc_free(name); return False; } ret = smbcli_sock_connect(sock, &ip, port); if (ret) { - sock->hostname = talloc_steal(sock->mem_ctx, name); + sock->hostname = talloc_steal(sock, name); } - talloc_destroy(mem_ctx); + talloc_destroy(name); return ret; } diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 5766fde03a..cae8e2a3be 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -37,23 +37,20 @@ static void smbcli_transport_event_handler(struct event_context *ev, struct fd_e */ struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock) { - TALLOC_CTX *mem_ctx; struct smbcli_transport *transport; struct fd_event fde; - mem_ctx = talloc_init("smbcli_transport"); - if (!mem_ctx) return NULL; - - transport = talloc_zero(mem_ctx, sizeof(*transport)); + transport = talloc_named(NULL, sizeof(*transport), "smbcli_transport"); if (!transport) return NULL; + ZERO_STRUCTP(transport); + transport->event.ctx = event_context_init(); if (transport->event.ctx == NULL) { - talloc_destroy(mem_ctx); + talloc_destroy(transport); return NULL; } - transport->mem_ctx = mem_ctx; transport->socket = sock; transport->negotiate.protocol = PROTOCOL_NT1; transport->options.use_spnego = lp_use_spnego(); @@ -88,7 +85,7 @@ void smbcli_transport_close(struct smbcli_transport *transport) event_remove_fd(transport->event.ctx, transport->event.fde); event_remove_timed(transport->event.ctx, transport->event.te); event_context_destroy(transport->event.ctx); - talloc_destroy(transport->mem_ctx); + talloc_free(transport); } } @@ -456,7 +453,7 @@ static void smbcli_transport_process_recv(struct smbcli_transport *transport) if (transport->recv_buffer.received == NBT_HDR_SIZE) { /* we've got a full header */ transport->recv_buffer.req_size = smb_len(transport->recv_buffer.header) + NBT_HDR_SIZE; - transport->recv_buffer.buffer = talloc(transport->mem_ctx, + transport->recv_buffer.buffer = talloc(transport, NBT_HDR_SIZE+transport->recv_buffer.req_size); if (transport->recv_buffer.buffer == NULL) { smbcli_transport_dead(transport); diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index 57e322da32..2d642a9a8c 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -33,18 +33,13 @@ struct smbcli_tree *smbcli_tree_init(struct smbcli_session *session) { struct smbcli_tree *tree; - TALLOC_CTX *mem_ctx = talloc_init("smbcli_tree"); - if (mem_ctx == NULL) { - return NULL; - } - tree = talloc_zero(mem_ctx, sizeof(*tree)); + tree = talloc_named(NULL, sizeof(*tree), "smbcli_tree"); if (!tree) { - talloc_destroy(mem_ctx); return NULL; } - tree->mem_ctx = mem_ctx; + ZERO_STRUCTP(tree); tree->session = session; tree->session->reference_count++; @@ -60,7 +55,7 @@ void smbcli_tree_close(struct smbcli_tree *tree) tree->reference_count--; if (tree->reference_count <= 0) { smbcli_session_close(tree->session); - talloc_destroy(tree->mem_ctx); + talloc_free(tree); } } @@ -295,10 +290,10 @@ NTSTATUS smbcli_tree_full_connection(struct smbcli_tree **ret_tree, tree->tid = tcon.tconx.out.cnum; if (tcon.tconx.out.dev_type) { - tree->device = talloc_strdup(tree->mem_ctx, tcon.tconx.out.dev_type); + tree->device = talloc_strdup(tree, tcon.tconx.out.dev_type); } if (tcon.tconx.out.fs_type) { - tree->fs_type = talloc_strdup(tree->mem_ctx, tcon.tconx.out.fs_type); + tree->fs_type = talloc_strdup(tree, tcon.tconx.out.fs_type); } talloc_destroy(mem_ctx); diff --git a/source4/libcli/raw/rawnegotiate.c b/source4/libcli/raw/rawnegotiate.c index 5ec827eebb..fdc1d0eb60 100644 --- a/source4/libcli/raw/rawnegotiate.c +++ b/source4/libcli/raw/rawnegotiate.c @@ -130,14 +130,14 @@ NTSTATUS smb_raw_negotiate(struct smbcli_transport *transport) if (req->in.data_size < 16) { goto failed; } - transport->negotiate.server_guid = smbcli_req_pull_blob(req, transport->mem_ctx, req->in.data, 16); - transport->negotiate.secblob = smbcli_req_pull_blob(req, transport->mem_ctx, req->in.data + 16, req->in.data_size - 16); + transport->negotiate.server_guid = smbcli_req_pull_blob(req, transport, req->in.data, 16); + transport->negotiate.secblob = smbcli_req_pull_blob(req, transport, req->in.data + 16, req->in.data_size - 16); } else { if (req->in.data_size < (transport->negotiate.key_len)) { goto failed; } - transport->negotiate.secblob = smbcli_req_pull_blob(req, transport->mem_ctx, req->in.data, transport->negotiate.key_len); - smbcli_req_pull_string(req, transport->mem_ctx, &transport->negotiate.server_domain, + transport->negotiate.secblob = smbcli_req_pull_blob(req, transport, req->in.data, transport->negotiate.key_len); + smbcli_req_pull_string(req, transport, &transport->negotiate.server_domain, req->in.data+transport->negotiate.key_len, req->in.data_size-transport->negotiate.key_len, STR_UNICODE|STR_NOALIGN); /* here comes the server name */ @@ -163,7 +163,7 @@ NTSTATUS smb_raw_negotiate(struct smbcli_transport *transport) if ((SVAL(req->in.vwv,VWV(5)) & 0x2)) { transport->negotiate.writebraw_supported = 1; } - transport->negotiate.secblob = smbcli_req_pull_blob(req, transport->mem_ctx, + transport->negotiate.secblob = smbcli_req_pull_blob(req, transport, req->in.data, req->in.data_size); } else { /* the old core protocol */ -- cgit From b13a9a8f98469fffe0db4cce7e077390d35984a3 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 25 Aug 2004 02:07:53 +0000 Subject: r2040: fixed a memory handling error in clisocket (caught with valgrind) (This used to be commit f6dc62bf119c294db060b0870b6ca80bc28bd4a5) --- source4/libcli/raw/clisocket.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 94bb447f47..1004db4040 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -173,9 +173,9 @@ BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, in if (ret) { sock->hostname = talloc_steal(sock, name); + } else { + talloc_free(name); } - talloc_destroy(name); - return ret; } -- cgit From fa5a99b7a6e4f9bffa82eed1393e8e5e1f6404dc Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 25 Aug 2004 02:25:20 +0000 Subject: r2041: Fix NTLMSSP RPC sealing, client -> win2k3 server. The bug (found by tridge) is that Win2k3 is being tighter about the NTLMSSP flags. If we don't negotiate sealing, we can't use it. We now have a way to indicate to the GENSEC implementation mechanisms what things we want for a connection. Andrew Bartlett (This used to be commit 86f61568ea44c5719f9b583beeeefb12e0c26f4c) --- source4/libcli/raw/clisession.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index af8a63328c..32be6b68ed 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -399,6 +399,8 @@ static NTSTATUS smb_raw_session_setup_generic_spnego(struct smbcli_session *sess goto done; } + gensec_want_feature(session->gensec, GENSEC_WANT_SESSION_KEY); + status = gensec_set_domain(session->gensec, parms->generic.in.domain); if (!NT_STATUS_IS_OK(status)) { DEBUG(1, ("Failed to start set GENSEC client domain to %s: %s\n", -- cgit From 31c1c7846f6b6e5848bc39a28a65118bfa98e35d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 1 Sep 2004 04:39:06 +0000 Subject: r2159: converted samba4 over to UTF-16. I had previously thought this was unnecessary, as windows doesn't use standards compliant UTF-16, and for filesystem operations treats bytes as UCS-2, but Bjoern Jacke has pointed out to me that this means we don't correctly store extended UTF-16 characters as UTF-8 on disk. This can be seen with (for example) the gothic characters with codepoints above 64k. This commit also adds a LOCAL-ICONV torture test that tests the first 1 million codepoints against the system iconv library, and tests 5 million random UTF-16LE buffers for identical error handling to the system iconv library. the lib/iconv.c changes need backporting to samba3 (This used to be commit 756f28ac95feaa84b42402723d5f7286865c78db) --- source4/libcli/raw/rawrequest.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 87bbe5a31b..51c0c0b925 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -526,7 +526,7 @@ static size_t smbcli_req_pull_ucs2(struct smbcli_request *req, TALLOC_CTX *mem_c return 0; } - ret = convert_string_talloc(mem_ctx, CH_UCS2, CH_UNIX, src, src_len2, (const void **)dest); + ret = convert_string_talloc(mem_ctx, CH_UTF16, CH_UNIX, src, src_len2, (const void **)dest); if (ret == -1) { *dest = NULL; return 0; @@ -725,7 +725,7 @@ static size_t smbcli_blob_pull_ucs2(TALLOC_CTX* mem_ctx, src_len2 += 2; } - ret = convert_string_talloc(mem_ctx, CH_UCS2, CH_UNIX, src, src_len2, (const void **)dest); + ret = convert_string_talloc(mem_ctx, CH_UTF16, CH_UNIX, src, src_len2, (const void **)dest); if (ret == -1) { *dest = NULL; return 0; -- cgit From b990e9a97b02cec9f012bacc6bb266a0403f6792 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 2 Sep 2004 12:02:28 +0000 Subject: r2184: use the smb.conf socket options for client code too (This used to be commit 7256945b526a1ee68d18eb579e592f7389740c22) --- source4/libcli/raw/clisocket.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 1004db4040..9aea8624d0 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -79,6 +79,7 @@ BOOL smbcli_sock_connect(struct smbcli_socket *sock, struct in_addr *ip, int por } set_blocking(sock->fd, False); + set_socket_options(sock->fd, lp_socket_options()); return True; } -- cgit From 8293df91bcec574fb4a2b290cc11dd83353264ae Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 8 Sep 2004 00:00:56 +0000 Subject: r2247: talloc_destroy -> talloc_free (This used to be commit 6c1a72c5d667245b1eec94f58e68acd22dd720ce) --- source4/libcli/raw/clitransport.c | 2 +- source4/libcli/raw/clitree.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index cae8e2a3be..2d29ba371f 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -47,7 +47,7 @@ struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock) transport->event.ctx = event_context_init(); if (transport->event.ctx == NULL) { - talloc_destroy(transport); + talloc_free(transport); return NULL; } diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index 2d642a9a8c..03a49708b3 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -251,7 +251,7 @@ NTSTATUS smbcli_tree_full_connection(struct smbcli_tree **ret_tree, status = smb_raw_session_setup(session, mem_ctx, &setup); if (!NT_STATUS_IS_OK(status)) { smbcli_session_close(session); - talloc_destroy(mem_ctx); + talloc_free(mem_ctx); return status; } @@ -260,7 +260,7 @@ NTSTATUS smbcli_tree_full_connection(struct smbcli_tree **ret_tree, tree = smbcli_tree_init(session); if (!tree) { smbcli_session_close(session); - talloc_destroy(mem_ctx); + talloc_free(mem_ctx); return NT_STATUS_NO_MEMORY; } @@ -284,7 +284,7 @@ NTSTATUS smbcli_tree_full_connection(struct smbcli_tree **ret_tree, if (!NT_STATUS_IS_OK(status)) { smbcli_tree_close(tree); - talloc_destroy(mem_ctx); + talloc_free(mem_ctx); return status; } @@ -296,7 +296,7 @@ NTSTATUS smbcli_tree_full_connection(struct smbcli_tree **ret_tree, tree->fs_type = talloc_strdup(tree, tcon.tconx.out.fs_type); } - talloc_destroy(mem_ctx); + talloc_free(mem_ctx); *ret_tree = tree; return NT_STATUS_OK; -- cgit From d2c14a5dc6117d6593aa03090ce7fa4c9ebc3359 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 13 Sep 2004 04:28:10 +0000 Subject: r2307: Fix the use of 'raw' NTLMSSP to hosts that support extended security, but do not support SPNEGO (such as XP, when not joined to a domain). This is triggered by the presense or lack of a security blob in the negprot reply. Andrew Bartlett (This used to be commit 99f7a38c077725b22475f2ba68d0955114879c24) --- source4/libcli/raw/clisession.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index 32be6b68ed..dcf32c8485 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -379,6 +379,7 @@ static NTSTATUS smb_raw_session_setup_generic_spnego(struct smbcli_session *sess union smb_sesssetup s2; DATA_BLOB session_key = data_blob(NULL, 0); DATA_BLOB null_data_blob = data_blob(NULL, 0); + const char *chosen_oid; s2.generic.level = RAW_SESSSETUP_SPNEGO; s2.spnego.in.bufsize = ~0; @@ -429,21 +430,25 @@ static NTSTATUS smb_raw_session_setup_generic_spnego(struct smbcli_session *sess goto done; } - status = gensec_start_mech_by_oid(session->gensec, OID_SPNEGO); + if (session->transport->negotiate.secblob.length) { + chosen_oid = OID_SPNEGO; + } else { + /* without a sec blob, means raw NTLMSSP */ + chosen_oid = OID_NTLMSSP; + } + + status = gensec_start_mech_by_oid(session->gensec, chosen_oid); if (!NT_STATUS_IS_OK(status)) { - DEBUG(1, ("Failed to start set GENSEC client SPNEGO mechanism: %s\n", - nt_errstr(status))); + DEBUG(1, ("Failed to start set GENSEC client SPNEGO mechanism %s: %s\n", + gensec_get_name_by_oid(chosen_oid), nt_errstr(status))); goto done; } - + status = gensec_update(session->gensec, mem_ctx, - session->transport->negotiate.secblob, - &s2.spnego.in.secblob); + session->transport->negotiate.secblob, + &s2.spnego.in.secblob); while(1) { - if (NT_STATUS_IS_OK(status) && s2.spnego.in.secblob.length == 0) { - break; - } if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED) && !NT_STATUS_IS_OK(status)) { break; } @@ -455,6 +460,10 @@ static NTSTATUS smb_raw_session_setup_generic_spnego(struct smbcli_session *sess smbcli_transport_simple_set_signing(session->transport, session_key, null_data_blob); } + if (NT_STATUS_IS_OK(status) && s2.spnego.in.secblob.length == 0) { + break; + } + session->vuid = s2.spnego.out.vuid; status = smb_raw_session_setup(session, mem_ctx, &s2); session->vuid = UID_FIELD_INVALID; @@ -483,7 +492,7 @@ done: parms->generic.out.lanman = s2.spnego.out.lanman; parms->generic.out.domain = s2.spnego.out.domain; } else { - DEBUG(1, ("Failed to login with SPNEGO: %s\n", nt_errstr(status))); + DEBUG(1, ("Failed to login with %s: %s\n", gensec_get_name_by_oid(chosen_oid), nt_errstr(status))); return status; } -- cgit From 6b9b169c2746c0223f249700d7ff8a70feb8da62 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 20 Sep 2004 10:40:11 +0000 Subject: r2443: check return code of event_loop_once() to catch thet cases where the server closes the connetion and we got EBADF from select() and event_loop_once() fails metze (This used to be commit 9c0e50a6f3d628156b4543d5ded89e06be696f64) --- source4/libcli/raw/rawrequest.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 51c0c0b925..6536af3072 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -285,7 +285,9 @@ BOOL smbcli_request_receive(struct smbcli_request *req) /* keep receiving packets until this one is replied to */ while (req->state <= SMBCLI_REQUEST_RECV) { - event_loop_once(req->transport->event.ctx); + if (event_loop_once(req->transport->event.ctx) != 0) { + return False; + } } return req->state == SMBCLI_REQUEST_DONE; -- cgit From 23ba434b017d61f397befe9808fa3214c3964355 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 21 Sep 2004 08:46:47 +0000 Subject: r2469: complete overhaul of the old-style RAW_SEARCH_ calls (the OS/2 and original core level calls). The old code was completely wrong in many respects. also fixed the EA_SIZE level in the server extended the RAW-SEARCH test suite to test the new code properly (This used to be commit 71480271ad84b57fcdde264a54bb2408cf783255) --- source4/libcli/raw/rawsearch.c | 92 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 81 insertions(+), 11 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawsearch.c b/source4/libcli/raw/rawsearch.c index 67410283ed..df44dbffa4 100644 --- a/source4/libcli/raw/rawsearch.c +++ b/source4/libcli/raw/rawsearch.c @@ -42,11 +42,15 @@ static void smb_raw_search_backend(struct smbcli_request *req, p = req->in.data + 3; for (i=0; i < count; i++) { - search_data.search.search_id = smbcli_req_pull_blob(req, mem_ctx, p, 21); - search_data.search.attrib = CVAL(p, 21); - search_data.search.write_time = raw_pull_dos_date(req->transport, - p + 22); - search_data.search.size = IVAL(p, 26); + search_data.search.id.reserved = CVAL(p, 0); + memcpy(search_data.search.id.name, p+1, 11); + search_data.search.id.handle = CVAL(p, 12); + search_data.search.id.server_cookie = IVAL(p, 13); + search_data.search.id.client_cookie = IVAL(p, 17); + search_data.search.attrib = CVAL(p, 21); + search_data.search.write_time = raw_pull_dos_date(req->transport, + p + 22); + search_data.search.size = IVAL(p, 26); smbcli_req_pull_ascii(req, mem_ctx, &search_data.search.name, p+30, 13, STR_ASCII); if (!callback(private, &search_data)) { break; @@ -65,8 +69,15 @@ static NTSTATUS smb_raw_search_first_old(struct smbcli_tree *tree, { struct smbcli_request *req; - - req = smbcli_request_setup(tree, SMBsearch, 2, 0); + uint8_t op = SMBsearch; + + if (io->generic.level == RAW_SEARCH_FFIRST) { + op = SMBffirst; + } else if (io->generic.level == RAW_SEARCH_FUNIQUE) { + op = SMBfunique; + } + + req = smbcli_request_setup(tree, op, 2, 0); if (!req) { return NT_STATUS_NO_MEMORY; } @@ -99,8 +110,14 @@ static NTSTATUS smb_raw_search_next_old(struct smbcli_tree *tree, { struct smbcli_request *req; + uint8_t var_block[21]; + uint8_t op = SMBsearch; + + if (io->generic.level == RAW_SEARCH_FFIRST) { + op = SMBffirst; + } - req = smbcli_request_setup(tree, SMBsearch, 2, 0); + req = smbcli_request_setup(tree, op, 2, 0); if (!req) { return NT_STATUS_NO_MEMORY; } @@ -108,7 +125,14 @@ static NTSTATUS smb_raw_search_next_old(struct smbcli_tree *tree, SSVAL(req->out.vwv, VWV(0), io->search_next.in.max_count); SSVAL(req->out.vwv, VWV(1), io->search_next.in.search_attrib); smbcli_req_append_ascii4(req, "", STR_TERMINATE); - smbcli_req_append_var_block(req, io->search_next.in.search_id.data, 21); + + SCVAL(var_block, 0, io->search_next.in.id.reserved); + memcpy(&var_block[1], io->search_next.in.id.name, 11); + SCVAL(var_block, 12, io->search_next.in.id.handle); + SIVAL(var_block, 13, io->search_next.in.id.server_cookie); + SIVAL(var_block, 17, io->search_next.in.id.client_cookie); + + smbcli_req_append_var_block(req, var_block, 21); if (!smbcli_request_send(req) || !smbcli_request_receive(req)) { @@ -123,6 +147,43 @@ static NTSTATUS smb_raw_search_next_old(struct smbcli_tree *tree, return smbcli_request_destroy(req); } + +/**************************************************************************** + Old style search next. +****************************************************************************/ +static NTSTATUS smb_raw_search_close_old(struct smbcli_tree *tree, + union smb_search_close *io) +{ + struct smbcli_request *req; + uint8_t var_block[21]; + + req = smbcli_request_setup(tree, SMBfclose, 2, 0); + if (!req) { + return NT_STATUS_NO_MEMORY; + } + + SSVAL(req->out.vwv, VWV(0), io->fclose.in.max_count); + SSVAL(req->out.vwv, VWV(1), io->fclose.in.search_attrib); + smbcli_req_append_ascii4(req, "", STR_TERMINATE); + + SCVAL(var_block, 0, io->fclose.in.id.reserved); + memcpy(&var_block[1], io->fclose.in.id.name, 11); + SCVAL(var_block, 12, io->fclose.in.id.handle); + SIVAL(var_block, 13, io->fclose.in.id.server_cookie); + SIVAL(var_block, 17, io->fclose.in.id.client_cookie); + + smbcli_req_append_var_block(req, var_block, 21); + + if (!smbcli_request_send(req) || + !smbcli_request_receive(req)) { + return smbcli_request_destroy(req); + } + + return smbcli_request_destroy(req); +} + + + /**************************************************************************** Very raw search first - returns param/data blobs. ****************************************************************************/ @@ -245,6 +306,8 @@ static int parse_trans2_search(struct smbcli_tree *tree, switch (level) { case RAW_SEARCH_GENERIC: case RAW_SEARCH_SEARCH: + case RAW_SEARCH_FFIRST: + case RAW_SEARCH_FUNIQUE: /* handled elsewhere */ return -1; @@ -499,7 +562,9 @@ NTSTATUS smb_raw_search_first(struct smbcli_tree *tree, DATA_BLOB p_blob, d_blob; NTSTATUS status; - if (io->generic.level == RAW_SEARCH_SEARCH) { + if (io->generic.level == RAW_SEARCH_SEARCH || + io->generic.level == RAW_SEARCH_FFIRST || + io->generic.level == RAW_SEARCH_FUNIQUE) { return smb_raw_search_first_old(tree, mem_ctx, io, private, callback); } if (io->generic.level >= RAW_SEARCH_GENERIC) { @@ -543,7 +608,8 @@ NTSTATUS smb_raw_search_next(struct smbcli_tree *tree, DATA_BLOB p_blob, d_blob; NTSTATUS status; - if (io->generic.level == RAW_SEARCH_SEARCH) { + if (io->generic.level == RAW_SEARCH_SEARCH || + io->generic.level == RAW_SEARCH_FFIRST) { return smb_raw_search_next_old(tree, mem_ctx, io, private, callback); } if (io->generic.level >= RAW_SEARCH_GENERIC) { @@ -582,6 +648,10 @@ NTSTATUS smb_raw_search_close(struct smbcli_tree *tree, union smb_search_close *io) { struct smbcli_request *req; + + if (io->generic.level == RAW_FINDCLOSE_FCLOSE) { + return smb_raw_search_close_old(tree, io); + } req = smbcli_request_setup(tree, SMBfindclose, 1, 0); if (!req) { -- cgit From 57196843320a1b833bcd669d0b23b429dfd34fb3 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 22 Sep 2004 05:14:20 +0000 Subject: r2497: fixed an uninitialised 4 bytes in old style session setup (found with valgrind) (This used to be commit b2bb41721817256618124907a6922a00d50643dc) --- source4/libcli/raw/clisession.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index dcf32c8485..2bd2d0e054 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -80,6 +80,7 @@ struct smbcli_request *smb_raw_session_setup_send(struct smbcli_session *session SSVAL(req->out.vwv,VWV(4),parms->old.in.vc_num); SIVAL(req->out.vwv,VWV(5),parms->old.in.sesskey); SSVAL(req->out.vwv,VWV(7),parms->old.in.password.length); + SIVAL(req->out.vwv,VWV(8), 0); /* reserved */ smbcli_req_append_blob(req, &parms->old.in.password); smbcli_req_append_string(req, parms->old.in.user, STR_TERMINATE); smbcli_req_append_string(req, parms->old.in.domain, STR_TERMINATE|STR_UPPER); -- cgit From 9a9dcc7250ccd4544cb797c15b3bc3dfbb760be0 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 23 Sep 2004 00:51:45 +0000 Subject: r2552: Character set conversion and string handling updates. The intial motivation for this commit was to merge in some of the bugfixes present in Samba3's chrcnv and string handling code into Samba4. However, along the way I found a lot of unused functions, and decided to do a bit more... The strlen_m code now does not use a fixed buffer, but more work is needed to finish off other functions in str_util.c. These fixed length buffers hav caused very nasty, hard to chase down bugs at some sites. The strupper_m() function has a strupper_talloc() to replace it (we need to go around and fix more uses, but it's a start). Use of these new functions will avoid bugs where the upper or lowercase version of a string is a different length. I have removed the push_*_allocate functions, which are replaced by calls to push_*_talloc. Likewise, pstring and other 'fixed length' wrappers are removed, where possible. I have removed the first ('base pointer') argument, used by push_ucs2, as the Samba4 way of doing things ensures that this is always on an even boundary anyway. (It was used in only one place, in any case). (This used to be commit dfecb0150627b500cb026b8a4932fe87902ca392) --- source4/libcli/raw/rawrequest.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 6536af3072..1ff36d0a8d 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -369,13 +369,14 @@ size_t smbcli_req_append_string(struct smbcli_request *req, const char *str, uin smbcli_req_grow_allocation(req, len + req->out.data_size); - len = push_string(NULL, req->out.data + req->out.data_size, str, len, flags); + len = push_string(req->out.data + req->out.data_size, str, len, flags); smbcli_req_grow_data(req, len + req->out.data_size); return len; } + /* this is like smbcli_req_append_string but it also return the non-terminated string byte length, which can be less than the number @@ -528,7 +529,7 @@ static size_t smbcli_req_pull_ucs2(struct smbcli_request *req, TALLOC_CTX *mem_c return 0; } - ret = convert_string_talloc(mem_ctx, CH_UTF16, CH_UNIX, src, src_len2, (const void **)dest); + ret = convert_string_talloc(mem_ctx, CH_UTF16, CH_UNIX, src, src_len2, (void **)dest); if (ret == -1) { *dest = NULL; return 0; @@ -570,7 +571,7 @@ size_t smbcli_req_pull_ascii(struct smbcli_request *req, TALLOC_CTX *mem_ctx, src_len2++; } - ret = convert_string_talloc(mem_ctx, CH_DOS, CH_UNIX, src, src_len2, (const void **)dest); + ret = convert_string_talloc(mem_ctx, CH_DOS, CH_UNIX, src, src_len2, (void **)dest); if (ret == -1) { *dest = NULL; @@ -696,6 +697,7 @@ static size_t smbcli_blob_pull_ucs2(TALLOC_CTX* mem_ctx, { int src_len, src_len2, alignment=0; ssize_t ret; + char *dest2; if (src < (const char *)blob->data || src >= (const char *)(blob->data + blob->length)) { @@ -727,11 +729,12 @@ static size_t smbcli_blob_pull_ucs2(TALLOC_CTX* mem_ctx, src_len2 += 2; } - ret = convert_string_talloc(mem_ctx, CH_UTF16, CH_UNIX, src, src_len2, (const void **)dest); + ret = convert_string_talloc(mem_ctx, CH_UTF16, CH_UNIX, src, src_len2, (void **)&dest2); if (ret == -1) { *dest = NULL; return 0; } + *dest = dest2; return src_len2 + alignment; } @@ -755,6 +758,7 @@ static size_t smbcli_blob_pull_ascii(TALLOC_CTX *mem_ctx, { int src_len, src_len2; ssize_t ret; + char *dest2; src_len = blob->length - PTR_DIFF(src, blob->data); if (src_len < 0) { @@ -771,12 +775,13 @@ static size_t smbcli_blob_pull_ascii(TALLOC_CTX *mem_ctx, src_len2++; } - ret = convert_string_talloc(mem_ctx, CH_DOS, CH_UNIX, src, src_len2, (const void **)dest); + ret = convert_string_talloc(mem_ctx, CH_DOS, CH_UNIX, src, src_len2, (void **)&dest2); if (ret == -1) { *dest = NULL; return 0; } + *dest = dest2; return ret; } @@ -911,7 +916,7 @@ size_t smbcli_blob_append_string(struct smbcli_session *session, return 0; } - len = push_string(NULL, blob->data + blob->length, str, max_len, flags); + len = push_string(blob->data + blob->length, str, max_len, flags); blob->length += len; -- cgit From f5db8edc97a3dcbbab7a33a41b54fc17902872ea Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 24 Sep 2004 06:51:14 +0000 Subject: r2587: fixed a couple of authentication memory leaks. There are more to be fixed - I'll commit a little test suite soon. (This used to be commit 5b967c1cbb9831f7f2c6c6187f9e8e6dcc284497) --- source4/libcli/raw/clisession.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index 2bd2d0e054..264c1cd616 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -446,8 +446,8 @@ static NTSTATUS smb_raw_session_setup_generic_spnego(struct smbcli_session *sess } status = gensec_update(session->gensec, mem_ctx, - session->transport->negotiate.secblob, - &s2.spnego.in.secblob); + session->transport->negotiate.secblob, + &s2.spnego.in.secblob); while(1) { if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED) && !NT_STATUS_IS_OK(status)) { @@ -493,6 +493,7 @@ done: parms->generic.out.lanman = s2.spnego.out.lanman; parms->generic.out.domain = s2.spnego.out.domain; } else { + gensec_end(&session->gensec); DEBUG(1, ("Failed to login with %s: %s\n", gensec_get_name_by_oid(chosen_oid), nt_errstr(status))); return status; } -- cgit From 30381686c4874e4f9602a977a31399e49350e597 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 25 Sep 2004 11:15:18 +0000 Subject: r2621: - now that the client code is non-blocking, we no longer need write_data and read_data, which are inherently blocking operations - got rid of some old NBT keepalive routines that are not needed (This used to be commit e73b4ae4e500d3b7ee57e160e0f8b63c99b2542a) --- source4/libcli/raw/clisocket.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 9aea8624d0..654d8ee61b 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -125,7 +125,7 @@ ssize_t smbcli_sock_write(struct smbcli_socket *sock, const char *data, size_t l return -1; } - return write_data(sock->fd, data, len); + return write(sock->fd, data, len); } @@ -139,7 +139,7 @@ ssize_t smbcli_sock_read(struct smbcli_socket *sock, char *data, size_t len) return -1; } - return read_data(sock->fd, data, len); + return read(sock->fd, data, len); } /**************************************************************************** -- cgit From daa66ec96c2df1d59fa50c6e8869e4c1bcc2af88 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 25 Sep 2004 11:18:04 +0000 Subject: r2624: - save some system calls by only trying read/write operations that select has indicated are possible - when a socket is dead, don't try to do anything more on it (This used to be commit e95e5c591fcf9c3b7fde7fbdcc1837e22195e0a8) --- source4/libcli/raw/clitransport.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 2d29ba371f..85d5337da7 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -21,6 +21,10 @@ #include "includes.h" + +static void smbcli_transport_process_recv(struct smbcli_transport *transport); +static void smbcli_transport_process_send(struct smbcli_transport *transport); + /* an event has happened on the socket */ @@ -29,7 +33,12 @@ static void smbcli_transport_event_handler(struct event_context *ev, struct fd_e { struct smbcli_transport *transport = fde->private; - smbcli_transport_process(transport); + if (flags & EVENT_FD_READ) { + smbcli_transport_process_recv(transport); + } + if (flags & EVENT_FD_WRITE) { + smbcli_transport_process_send(transport); + } } /* @@ -265,6 +274,7 @@ static void smbcli_transport_process_send(struct smbcli_transport *transport) return; } smbcli_transport_dead(transport); + return; } req->out.buffer += ret; req->out.size -= ret; -- cgit From c5f4378361b9671e39fa83b043f28c972ab30b70 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 25 Sep 2004 12:08:57 +0000 Subject: r2629: convert gensec to the new talloc model by making our gensec structures a talloc child of the open connection we can be sure that it will be destroyed when the connection is dropped. (This used to be commit f12ee2f241aab1549bc1d9ca4c35a35a1ca0d09d) --- source4/libcli/raw/clisession.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index 264c1cd616..37992968a4 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -395,7 +395,7 @@ static NTSTATUS smb_raw_session_setup_generic_spnego(struct smbcli_session *sess smbcli_temp_set_signing(session->transport); - status = gensec_client_start(&session->gensec); + status = gensec_client_start(session, &session->gensec); if (!NT_STATUS_IS_OK(status)) { DEBUG(1, ("Failed to start GENSEC client mode: %s\n", nt_errstr(status))); goto done; -- cgit From ec0128ef012f4280b2fb607cb9c88c7673894fe6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 26 Sep 2004 04:59:03 +0000 Subject: r2649: - used some cpp tricks to make users of talloc() and talloc_realloc() to get auto-naming of pointers very cheaply. - fixed a couple of memory leaks found with the new tricks A typical exit report for smbd is now: talloc report on 'null_context' (total 811 bytes in 54 blocks) auth/auth_sam.c:334 contains 20 bytes in 1 blocks struct auth_serversupplied_info contains 498 bytes in 33 blocks UNNAMED contains 8 bytes in 1 blocks lib/data_blob.c:40 contains 16 bytes in 1 blocks iconv(CP850,UTF8) contains 61 bytes in 4 blocks iconv(UTF8,CP850) contains 61 bytes in 4 blocks iconv(UTF8,UTF-16LE) contains 67 bytes in 4 blocks iconv(UTF-16LE,UTF8) contains 67 bytes in 4 blocks UNNAMED contains 13 bytes in 1 blocks which is much better than before (This used to be commit 6e721393d03afd3c2f8ced8422533547a9e33342) --- source4/libcli/raw/rawtrans.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawtrans.c b/source4/libcli/raw/rawtrans.c index 49b43dd930..e6c928e3ed 100644 --- a/source4/libcli/raw/rawtrans.c +++ b/source4/libcli/raw/rawtrans.c @@ -84,7 +84,7 @@ NTSTATUS smb_raw_trans2_recv(struct smbcli_request *req, /* allocate it */ if (total_data != 0) { - tdata = talloc_realloc(parms->out.data.data,total_data); + tdata = talloc(mem_ctx, total_data); if (!tdata) { DEBUG(0,("smb_raw_receive_trans: failed to enlarge data buffer to %d bytes\n", total_data)); req->status = NT_STATUS_NO_MEMORY; @@ -94,7 +94,7 @@ NTSTATUS smb_raw_trans2_recv(struct smbcli_request *req, } if (total_param != 0) { - tparam = talloc_realloc(parms->out.params.data,total_param); + tparam = talloc(mem_ctx, total_param); if (!tparam) { DEBUG(0,("smb_raw_receive_trans: failed to enlarge param buffer to %d bytes\n", total_param)); req->status = NT_STATUS_NO_MEMORY; -- cgit From 3ea916b2278c202c99c80c02e80e588bd7daedb8 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 26 Sep 2004 06:44:08 +0000 Subject: r2654: fixed some more server memory leaks. We are now down to a single leak of 16 bytes, caused by the 16 byte data_blob in the smb_signing code. (This used to be commit 2f1b788e09686e065d22f621f5c0c585192c6740) --- source4/libcli/raw/clisession.c | 2 +- source4/libcli/raw/clisocket.c | 2 +- source4/libcli/raw/clitransport.c | 2 +- source4/libcli/raw/clitree.c | 2 +- source4/libcli/raw/rawrequest.c | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index 37992968a4..75b9645018 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -33,7 +33,7 @@ struct smbcli_session *smbcli_session_init(struct smbcli_transport *transport) { struct smbcli_session *session; - session = talloc_named(NULL, sizeof(*session), "smbcli_session"); + session = talloc_p(transport, struct smbcli_session); if (!session) { return NULL; } diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 654d8ee61b..5663672333 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -29,7 +29,7 @@ struct smbcli_socket *smbcli_sock_init(void) { struct smbcli_socket *sock; - sock = talloc_named(NULL, sizeof(*sock), "smbcli_socket"); + sock = talloc_p(NULL, struct smbcli_socket); if (!sock) { return NULL; } diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 85d5337da7..c0d84179d6 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -49,7 +49,7 @@ struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock) struct smbcli_transport *transport; struct fd_event fde; - transport = talloc_named(NULL, sizeof(*transport), "smbcli_transport"); + transport = talloc_p(sock, struct smbcli_transport); if (!transport) return NULL; ZERO_STRUCTP(transport); diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index 03a49708b3..c383eef768 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -34,7 +34,7 @@ struct smbcli_tree *smbcli_tree_init(struct smbcli_session *session) { struct smbcli_tree *tree; - tree = talloc_named(NULL, sizeof(*tree), "smbcli_tree"); + tree = talloc_p(session, struct smbcli_tree); if (!tree) { return NULL; } diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 1ff36d0a8d..a94e796628 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -62,7 +62,7 @@ struct smbcli_request *smbcli_request_setup_nonsmb(struct smbcli_transport *tran { struct smbcli_request *req; - req = talloc_named(NULL, sizeof(struct smbcli_request), "smcli_request"); + req = talloc_p(transport, struct smbcli_request); if (!req) { return NULL; } -- cgit From 954869efdb8b0006fd4457a1c6d56a31c3825421 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 26 Sep 2004 07:04:35 +0000 Subject: r2655: fixed an error in the shutdown of the sock->transport->session->tree smbcli raw context handling (This used to be commit d5fd6388751944f11c34e5124d403d57c8670e3b) --- source4/libcli/raw/clisession.c | 1 - source4/libcli/raw/clisocket.c | 1 + source4/libcli/raw/clitransport.c | 3 +-- source4/libcli/raw/clitree.c | 3 ++- 4 files changed, 4 insertions(+), 4 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index 75b9645018..516da2fa2e 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -55,7 +55,6 @@ void smbcli_session_close(struct smbcli_session *session) session->reference_count--; if (session->reference_count <= 0) { smbcli_transport_close(session->transport); - talloc_free(session); } } diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 5663672333..8481bc73e2 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -104,6 +104,7 @@ void smbcli_sock_close(struct smbcli_socket *sock) sock->reference_count--; if (sock->reference_count <= 0) { smbcli_sock_dead(sock); + talloc_free(sock); } } diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index c0d84179d6..d70ceceab3 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -90,11 +90,10 @@ void smbcli_transport_close(struct smbcli_transport *transport) { transport->reference_count--; if (transport->reference_count <= 0) { - smbcli_sock_close(transport->socket); event_remove_fd(transport->event.ctx, transport->event.fde); event_remove_timed(transport->event.ctx, transport->event.te); event_context_destroy(transport->event.ctx); - talloc_free(transport); + smbcli_sock_close(transport->socket); } } diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index c383eef768..e3a1a6d341 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -55,7 +55,6 @@ void smbcli_tree_close(struct smbcli_tree *tree) tree->reference_count--; if (tree->reference_count <= 0) { smbcli_session_close(tree->session); - talloc_free(tree); } } @@ -193,6 +192,8 @@ NTSTATUS smbcli_tree_full_connection(struct smbcli_tree **ret_tree, return NT_STATUS_NO_MEMORY; } + talloc_set_name_const(sock, "smbcli_tree_full_connection"); + /* open a TCP socket to the server */ if (!smbcli_sock_connect_byname(sock, dest_host, port)) { DEBUG(2,("Failed to establish socket connection - %s\n", strerror(errno))); -- cgit From e3880fa759cfa03222262327854fe7bbe585fe01 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 26 Sep 2004 11:30:20 +0000 Subject: r2660: - converted the libcli/raw/ library to use talloc_increase_ref_count() rather than manual reference counts - properly support SMBexit in the cifs and posix backends - added a logoff method to all backends With these changes the RAW-CONTEXT test now passes against the posix backend (This used to be commit c315d6ac1cc40546fde1474702a6d66d07ee13c8) --- source4/libcli/raw/clisession.c | 50 ++++++++++++++++++++++++--------------- source4/libcli/raw/clisocket.c | 28 ++++++++++++---------- source4/libcli/raw/clitransport.c | 34 +++++++++++++------------- source4/libcli/raw/clitree.c | 38 +++++++++++++---------------- 4 files changed, 80 insertions(+), 70 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index 516da2fa2e..0c6c80d94c 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -26,6 +26,17 @@ if (!req) return NULL; \ } while (0) + +/* + destroy a smbcli_session +*/ +static int session_destroy(void *ptr) +{ + struct smbcli_session *session = ptr; + talloc_free(session->transport); + return 0; +} + /**************************************************************************** Initialize the session context ****************************************************************************/ @@ -42,20 +53,10 @@ struct smbcli_session *smbcli_session_init(struct smbcli_transport *transport) session->transport = transport; session->pid = (uint16_t)getpid(); session->vuid = UID_FIELD_INVALID; - session->transport->reference_count++; - return session; -} + talloc_set_destructor(session, session_destroy); -/**************************************************************************** -reduce reference_count and destroy is <= 0 -****************************************************************************/ -void smbcli_session_close(struct smbcli_session *session) -{ - session->reference_count--; - if (session->reference_count <= 0) { - smbcli_transport_close(session->transport); - } + return session; } /**************************************************************************** @@ -590,16 +591,27 @@ NTSTATUS smb_raw_ulogoff(struct smbcli_session *session) /**************************************************************************** - Send a SMBexit -****************************************************************************/ -NTSTATUS smb_raw_exit(struct smbcli_session *session) + Send a exit (async send) +*****************************************************************************/ +struct smbcli_request *smb_raw_exit_send(struct smbcli_session *session) { struct smbcli_request *req; - req = smbcli_request_setup_session(session, SMBexit, 0, 0); + SETUP_REQUEST_SESSION(SMBexit, 0, 0); - if (smbcli_request_send(req)) { - smbcli_request_receive(req); + if (!smbcli_request_send(req)) { + smbcli_request_destroy(req); + return NULL; } - return smbcli_request_destroy(req); + + return req; +} + +/**************************************************************************** + Send a exit (sync interface) +*****************************************************************************/ +NTSTATUS smb_raw_exit(struct smbcli_session *session) +{ + struct smbcli_request *req = smb_raw_exit_send(session); + return smbcli_request_simple_recv(req); } diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 8481bc73e2..37188f4e77 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -21,6 +21,18 @@ #include "includes.h" +/* + destroy a socket + */ +static int sock_destructor(void *ptr) +{ + struct smbcli_socket *sock = ptr; + if (sock->fd != -1) { + close(sock->fd); + sock->fd = -1; + } + return 0; +} /* create a smbcli_socket context @@ -37,11 +49,13 @@ struct smbcli_socket *smbcli_sock_init(void) ZERO_STRUCTP(sock); sock->fd = -1; sock->port = 0; + /* 20 second default timeout */ sock->timeout = 20000; - sock->hostname = NULL; + talloc_set_destructor(sock, sock_destructor); + return sock; } @@ -96,18 +110,6 @@ void smbcli_sock_dead(struct smbcli_socket *sock) } } -/**************************************************************************** - reduce socket reference count - if it becomes zero then close -****************************************************************************/ -void smbcli_sock_close(struct smbcli_socket *sock) -{ - sock->reference_count--; - if (sock->reference_count <= 0) { - smbcli_sock_dead(sock); - talloc_free(sock); - } -} - /**************************************************************************** Set socket options on a open connection. ****************************************************************************/ diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index d70ceceab3..eb1d3631ee 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -41,6 +41,21 @@ static void smbcli_transport_event_handler(struct event_context *ev, struct fd_e } } +/* + destroy a transport + */ +static int transport_destructor(void *ptr) +{ + struct smbcli_transport *transport = ptr; + + smbcli_transport_dead(transport); + event_remove_fd(transport->event.ctx, transport->event.fde); + event_remove_timed(transport->event.ctx, transport->event.te); + event_context_destroy(transport->event.ctx); + talloc_free(transport->socket); + return 0; +} + /* create a transport structure based on an established socket */ @@ -67,8 +82,6 @@ struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock) smbcli_init_signing(transport); - transport->socket->reference_count++; - ZERO_STRUCT(transport->called); fde.fd = sock->fd; @@ -79,22 +92,9 @@ struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock) transport->event.fde = event_add_fd(transport->event.ctx, &fde); - return transport; -} + talloc_set_destructor(transport, transport_destructor); -/* - decrease reference count on a transport, and destroy if it becomes - zero -*/ -void smbcli_transport_close(struct smbcli_transport *transport) -{ - transport->reference_count--; - if (transport->reference_count <= 0) { - event_remove_fd(transport->event.ctx, transport->event.fde); - event_remove_timed(transport->event.ctx, transport->event.te); - event_context_destroy(transport->event.ctx); - smbcli_sock_close(transport->socket); - } + return transport; } /* diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index e3a1a6d341..e0072a31b1 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -26,6 +26,15 @@ if (!req) return NULL; \ } while (0) +/* + destroy a smbcli_tree +*/ +static int tree_destructor(void *ptr) +{ + struct smbcli_tree *tree = ptr; + talloc_free(tree->session); + return 0; +} /**************************************************************************** Initialize the tree context @@ -41,24 +50,11 @@ struct smbcli_tree *smbcli_tree_init(struct smbcli_session *session) ZERO_STRUCTP(tree); tree->session = session; - tree->session->reference_count++; + talloc_set_destructor(tree, tree_destructor); return tree; } -/**************************************************************************** -reduce reference count on a tree and destroy if <= 0 -****************************************************************************/ -void smbcli_tree_close(struct smbcli_tree *tree) -{ - if (!tree) return; - tree->reference_count--; - if (tree->reference_count <= 0) { - smbcli_session_close(tree->session); - } -} - - /**************************************************************************** Send a tconX (async send) ****************************************************************************/ @@ -202,7 +198,7 @@ NTSTATUS smbcli_tree_full_connection(struct smbcli_tree **ret_tree, transport = smbcli_transport_init(sock); if (!transport) { - smbcli_sock_close(sock); + talloc_free(sock); return NT_STATUS_NO_MEMORY; } @@ -211,7 +207,7 @@ NTSTATUS smbcli_tree_full_connection(struct smbcli_tree **ret_tree, choose_called_name(&called, dest_host, 0x20); if (!smbcli_transport_connect(transport, &calling, &called)) { - smbcli_transport_close(transport); + talloc_free(transport); return NT_STATUS_UNSUCCESSFUL; } @@ -219,13 +215,13 @@ NTSTATUS smbcli_tree_full_connection(struct smbcli_tree **ret_tree, /* negotiate protocol options with the server */ status = smb_raw_negotiate(transport); if (!NT_STATUS_IS_OK(status)) { - smbcli_transport_close(transport); + talloc_free(transport); return status; } session = smbcli_session_init(transport); if (!session) { - smbcli_transport_close(transport); + talloc_free(transport); return NT_STATUS_NO_MEMORY; } @@ -251,7 +247,7 @@ NTSTATUS smbcli_tree_full_connection(struct smbcli_tree **ret_tree, status = smb_raw_session_setup(session, mem_ctx, &setup); if (!NT_STATUS_IS_OK(status)) { - smbcli_session_close(session); + talloc_free(session); talloc_free(mem_ctx); return status; } @@ -260,7 +256,7 @@ NTSTATUS smbcli_tree_full_connection(struct smbcli_tree **ret_tree, tree = smbcli_tree_init(session); if (!tree) { - smbcli_session_close(session); + talloc_free(session); talloc_free(mem_ctx); return NT_STATUS_NO_MEMORY; } @@ -284,7 +280,7 @@ NTSTATUS smbcli_tree_full_connection(struct smbcli_tree **ret_tree, SAFE_FREE(in_path); if (!NT_STATUS_IS_OK(status)) { - smbcli_tree_close(tree); + talloc_free(tree); talloc_free(mem_ctx); return status; } -- cgit From 729d17c27013eae731a97ac8413135c93244bca6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 26 Sep 2004 12:51:49 +0000 Subject: r2664: fixed the final server leak for normal operation. We now get a clean report from --leak-check (This used to be commit 1ff41bbcae8dc7514a85d69679e44dc7c5b0342f) --- source4/libcli/raw/smb_signing.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/smb_signing.c b/source4/libcli/raw/smb_signing.c index bd29abe3e6..9ba385e062 100644 --- a/source4/libcli/raw/smb_signing.c +++ b/source4/libcli/raw/smb_signing.c @@ -321,7 +321,8 @@ BOOL smbcli_request_check_sign_mac(struct smbcli_request *req) /*********************************************************** SMB signing - Simple implementation - setup the MAC key. ************************************************************/ -BOOL smbcli_simple_set_signing(struct smb_signing_context *sign_info, +BOOL smbcli_simple_set_signing(TALLOC_CTX *mem_ctx, + struct smb_signing_context *sign_info, const DATA_BLOB *user_session_key, const DATA_BLOB *response) { @@ -332,9 +333,9 @@ BOOL smbcli_simple_set_signing(struct smb_signing_context *sign_info, DEBUG(5, ("SMB signing enabled!\n")); if (response && response->length) { - sign_info->mac_key = data_blob(NULL, response->length + user_session_key->length); + sign_info->mac_key = data_blob_talloc(mem_ctx, NULL, response->length + user_session_key->length); } else { - sign_info->mac_key = data_blob(NULL, user_session_key->length); + sign_info->mac_key = data_blob_talloc(mem_ctx, NULL, user_session_key->length); } memcpy(&sign_info->mac_key.data[0], user_session_key->data, user_session_key->length); @@ -365,7 +366,8 @@ BOOL smbcli_transport_simple_set_signing(struct smbcli_transport *transport, return False; } - return smbcli_simple_set_signing(&transport->negotiate.sign_info, + return smbcli_simple_set_signing(transport, + &transport->negotiate.sign_info, &user_session_key, &response); } -- cgit From 5b44130afad1bb1764d986de3ef0e8e04b0e7357 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 27 Sep 2004 01:36:19 +0000 Subject: r2671: we're getting too many errors caused by the talloc_realloc() API not taking a context (so when you pass a NULL pointer you end up with memory in a top level context). Fixed it by changing the API to take a context. The context is only used if the pointer you are reallocing is NULL. (This used to be commit 8dc23821c9f54b2f13049b5e608a0cafb81aa540) --- source4/libcli/raw/raweas.c | 2 +- source4/libcli/raw/rawfileinfo.c | 6 ++++-- source4/libcli/raw/rawrequest.c | 4 ++-- 3 files changed, 7 insertions(+), 5 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/raweas.c b/source4/libcli/raw/raweas.c index d78f10fe1a..e07fbcd288 100644 --- a/source4/libcli/raw/raweas.c +++ b/source4/libcli/raw/raweas.c @@ -128,7 +128,7 @@ NTSTATUS ea_pull_list(const DATA_BLOB *blob, blob2.data = blob->data + ofs; blob2.length = ea_size - ofs; - *eas = talloc_realloc(*eas, sizeof(**eas) * (n+1)); + *eas = talloc_realloc(mem_ctx, *eas, sizeof(**eas) * (n+1)); if (! *eas) return NT_STATUS_NO_MEMORY; len = ea_pull_struct(&blob2, mem_ctx, &(*eas)[n]); diff --git a/source4/libcli/raw/rawfileinfo.c b/source4/libcli/raw/rawfileinfo.c index aac8f2657b..cbb666b7ce 100644 --- a/source4/libcli/raw/rawfileinfo.c +++ b/source4/libcli/raw/rawfileinfo.c @@ -174,8 +174,10 @@ static NTSTATUS smb_raw_info_backend(struct smbcli_session *session, while (blob->length - ofs >= 24) { uint_t n = parms->stream_info.out.num_streams; parms->stream_info.out.streams = - talloc_realloc(parms->stream_info.out.streams, - (n+1) * sizeof(parms->stream_info.out.streams[0])); + talloc_realloc_p(mem_ctx, + parms->stream_info.out.streams, + struct stream_struct, + n+1); if (!parms->stream_info.out.streams) { return NT_STATUS_NO_MEMORY; } diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index a94e796628..a15d681a5c 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -213,7 +213,7 @@ static void smbcli_req_grow_allocation(struct smbcli_request *req, uint_t new_si /* we need to realloc */ req->out.allocated = req->out.size + delta + REQ_OVER_ALLOCATION; - buf2 = talloc_realloc(req->out.buffer, req->out.allocated); + buf2 = talloc_realloc(req, req->out.buffer, req->out.allocated); if (buf2 == NULL) { smb_panic("out of memory in req_grow_allocation"); } @@ -911,7 +911,7 @@ size_t smbcli_blob_append_string(struct smbcli_session *session, max_len = (strlen(str)+2) * MAX_BYTES_PER_CHAR; - blob->data = talloc_realloc(blob->data, blob->length + max_len); + blob->data = talloc_realloc(mem_ctx, blob->data, blob->length + max_len); if (!blob->data) { return 0; } -- cgit From aa12305945df5f1578250b56ae2f3653b051736f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 27 Sep 2004 08:41:39 +0000 Subject: r2680: switched the libcli/raw/ code over to use talloc_reference(), which simplifies things quite a bit (This used to be commit c82a9cf750829c4f6982ca3133295c8599023c4e) --- source4/libcli/raw/clisession.c | 14 +------------- source4/libcli/raw/clitransport.c | 3 +-- source4/libcli/raw/clitree.c | 22 +++++----------------- 3 files changed, 7 insertions(+), 32 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index 0c6c80d94c..431d225021 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -27,16 +27,6 @@ } while (0) -/* - destroy a smbcli_session -*/ -static int session_destroy(void *ptr) -{ - struct smbcli_session *session = ptr; - talloc_free(session->transport); - return 0; -} - /**************************************************************************** Initialize the session context ****************************************************************************/ @@ -50,12 +40,10 @@ struct smbcli_session *smbcli_session_init(struct smbcli_transport *transport) } ZERO_STRUCTP(session); - session->transport = transport; + session->transport = talloc_reference(session, transport); session->pid = (uint16_t)getpid(); session->vuid = UID_FIELD_INVALID; - talloc_set_destructor(session, session_destroy); - return session; } diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index eb1d3631ee..f06f2c57ff 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -52,7 +52,6 @@ static int transport_destructor(void *ptr) event_remove_fd(transport->event.ctx, transport->event.fde); event_remove_timed(transport->event.ctx, transport->event.te); event_context_destroy(transport->event.ctx); - talloc_free(transport->socket); return 0; } @@ -75,7 +74,7 @@ struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock) return NULL; } - transport->socket = sock; + transport->socket = talloc_reference(transport, sock); transport->negotiate.protocol = PROTOCOL_NT1; transport->options.use_spnego = lp_use_spnego(); transport->negotiate.max_xmit = ~0; diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index e0072a31b1..f19cbf8e28 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -26,16 +26,6 @@ if (!req) return NULL; \ } while (0) -/* - destroy a smbcli_tree -*/ -static int tree_destructor(void *ptr) -{ - struct smbcli_tree *tree = ptr; - talloc_free(tree->session); - return 0; -} - /**************************************************************************** Initialize the tree context ****************************************************************************/ @@ -49,8 +39,7 @@ struct smbcli_tree *smbcli_tree_init(struct smbcli_session *session) } ZERO_STRUCTP(tree); - tree->session = session; - talloc_set_destructor(tree, tree_destructor); + tree->session = talloc_reference(tree, session); return tree; } @@ -188,17 +177,16 @@ NTSTATUS smbcli_tree_full_connection(struct smbcli_tree **ret_tree, return NT_STATUS_NO_MEMORY; } - talloc_set_name_const(sock, "smbcli_tree_full_connection"); - /* open a TCP socket to the server */ if (!smbcli_sock_connect_byname(sock, dest_host, port)) { + talloc_free(sock); DEBUG(2,("Failed to establish socket connection - %s\n", strerror(errno))); return NT_STATUS_UNSUCCESSFUL; } transport = smbcli_transport_init(sock); + talloc_free(sock); if (!transport) { - talloc_free(sock); return NT_STATUS_NO_MEMORY; } @@ -220,8 +208,8 @@ NTSTATUS smbcli_tree_full_connection(struct smbcli_tree **ret_tree, } session = smbcli_session_init(transport); + talloc_free(transport); if (!session) { - talloc_free(transport); return NT_STATUS_NO_MEMORY; } @@ -255,8 +243,8 @@ NTSTATUS smbcli_tree_full_connection(struct smbcli_tree **ret_tree, session->vuid = setup.generic.out.vuid; tree = smbcli_tree_init(session); + talloc_free(session); if (!tree) { - talloc_free(session); talloc_free(mem_ctx); return NT_STATUS_NO_MEMORY; } -- cgit From b2f1a29e4348a5bc34a87d72d526e23e421ed9d5 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 28 Sep 2004 05:44:59 +0000 Subject: r2710: continue with the new style of providing a parent context whenever possible to a structure creation routine. This makes for much easier global cleanup. (This used to be commit e14ee428ec357fab76a960387a9820a673786e27) --- source4/libcli/raw/clisocket.c | 4 ++-- source4/libcli/raw/clitree.c | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 37188f4e77..14862a39f0 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -37,11 +37,11 @@ static int sock_destructor(void *ptr) /* create a smbcli_socket context */ -struct smbcli_socket *smbcli_sock_init(void) +struct smbcli_socket *smbcli_sock_init(TALLOC_CTX *mem_ctx) { struct smbcli_socket *sock; - sock = talloc_p(NULL, struct smbcli_socket); + sock = talloc_p(mem_ctx, struct smbcli_socket); if (!sock) { return NULL; } diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index f19cbf8e28..77fe0ebe2f 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -151,7 +151,8 @@ NTSTATUS smb_tree_disconnect(struct smbcli_tree *tree) a convenient function to establish a smbcli_tree from scratch, using reasonable default parameters */ -NTSTATUS smbcli_tree_full_connection(struct smbcli_tree **ret_tree, +NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx, + struct smbcli_tree **ret_tree, const char *my_name, const char *dest_host, int port, const char *service, const char *service_type, @@ -172,7 +173,7 @@ NTSTATUS smbcli_tree_full_connection(struct smbcli_tree **ret_tree, *ret_tree = NULL; - sock = smbcli_sock_init(); + sock = smbcli_sock_init(parent_ctx); if (!sock) { return NT_STATUS_NO_MEMORY; } -- cgit From 7d32679e9683c81aca538f0267684332a28a286f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 8 Oct 2004 08:13:00 +0000 Subject: r2857: this commit gets rid of smb_ucs2_t, wpstring and fpstring, plus lots of associated functions. The motivation for this change was to avoid having to convert to/from ucs2 strings for so many operations. Doing that was slow, used many static buffers, and was also incorrect as it didn't cope properly with unicode codepoints above 65536 (which could not be represented correctly as smb_ucs2_t chars) The two core functions that allowed this change are next_codepoint() and push_codepoint(). These functions allow you to correctly walk a arbitrary multi-byte string a character at a time without converting the whole string to ucs2. While doing this cleanup I also fixed several ucs2 string handling bugs. See the commit for details. The following code (which counts the number of occuraces of 'c' in a string) shows how to use the new interface: size_t count_chars(const char *s, char c) { size_t count = 0; while (*s) { size_t size; codepoint_t c2 = next_codepoint(s, &size); if (c2 == c) count++; s += size; } return count; } (This used to be commit 814881f0e50019196b3aa9fbe4aeadbb98172040) --- source4/libcli/raw/rawrequest.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index a15d681a5c..89155451da 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -517,11 +517,7 @@ static size_t smbcli_req_pull_ucs2(struct smbcli_request *req, TALLOC_CTX *mem_c src_len = byte_len; } - src_len2 = strnlen_w((const smb_ucs2_t *)src, src_len/2) * 2; - if (src_len2 < src_len - 2) { - /* include the termination if we didn't reach the end of the packet */ - src_len2 += 2; - } + src_len2 = utf16_len_n(src, src_len); /* ucs2 strings must be at least 2 bytes long */ if (src_len2 < 2) { @@ -722,12 +718,7 @@ static size_t smbcli_blob_pull_ucs2(TALLOC_CTX* mem_ctx, return 0; } - src_len2 = strnlen_w((const smb_ucs2_t *)src, src_len/2) * 2; - - if (src_len2 < src_len - 2) { - /* include the termination if we didn't reach the end of the packet */ - src_len2 += 2; - } + src_len2 = utf16_len_n(src, src_len); ret = convert_string_talloc(mem_ctx, CH_UTF16, CH_UNIX, src, src_len2, (void **)&dest2); if (ret == -1) { -- cgit From 6591a226144d371a6b68fc5e7201a90a77dc9153 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 17 Oct 2004 10:04:49 +0000 Subject: r3016: - converted the events code to talloc - added the new messaging system, based on unix domain sockets. It gets over 10k messages/second on my laptop without any socket cacheing, which is better than I expected. - added a LOCAL-MESSAGING torture test (This used to be commit 3af06478da7ab34a272226d8d9ac87e0a4940cfb) --- source4/libcli/raw/clitransport.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index f06f2c57ff..3944afb638 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -68,7 +68,7 @@ struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock) ZERO_STRUCTP(transport); - transport->event.ctx = event_context_init(); + transport->event.ctx = event_context_init(transport); if (transport->event.ctx == NULL) { talloc_free(transport); return NULL; -- cgit From 53891ed37e32a97380430e6911878f3b94133e01 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 17 Oct 2004 11:37:22 +0000 Subject: r3017: nicer memory handling for event_context_merge() (This used to be commit 1cef44505e5de9b8ae5206522b624082ad2343b2) --- source4/libcli/raw/clitransport.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 3944afb638..c84c025c74 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -51,7 +51,6 @@ static int transport_destructor(void *ptr) smbcli_transport_dead(transport); event_remove_fd(transport->event.ctx, transport->event.fde); event_remove_timed(transport->event.ctx, transport->event.te); - event_context_destroy(transport->event.ctx); return 0; } -- cgit From 20d17b80571f0d0265c99c1ccdc21910c2eed043 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 20 Oct 2004 08:28:31 +0000 Subject: r3081: several updates to ntvfs and server side async request handling in preparation for the full share modes and ntcreatex code that I am working on. highlights include: - changed the way a backend determines if it is allowed to process a request asynchronously. The previous method of looking at the send_fn caused problems when an intermediate ntvfs module disabled it, and the caller then wanted to finished processing using this function. The new method is a REQ_CONTROL_MAY_ASYNC flag in req->control_flags, which is also a bit easier to read - fixed 2 bugs in the readbraw server code. One related to trying to answer a readbraw with smb signing (which can't work, and crashed our signing code), the second related to error handling, which attempted to send a normal SMB error packet, when readbraw must send a 0 read reply (as it has no header) - added several more ntvfs_generic.c generic mapping functions. This means that backends no longer need to implement such esoteric functions as SMBwriteunlock() if they don't want to. The backend can just request the mapping layer turn it into a write followed by an unlock. This makes the backends considerably simpler as they only need to implement one style of each function for lock, read, write, open etc, rather than the full host of functions that SMB provides. A backend can still choose to implement them individually, of course, and the CIFS backend does that. - simplified the generic structures to make them identical to the principal call for several common SMB calls (such as RAW_WRITE_GENERIC now being an alias for RAW_WRITE_WRITEX). - started rewriting the pvfs_open() code in preparation for the full ntcreatex semantics. - in pvfs_open and ipc_open, initially allocate the open file structure as a child of the request, so on error we don't need to clean up. Then when we are going to succeed the open steal the pointer into the long term backend context. This makes for much simpler error handling (and fixes some bugs) - use a destructor in the ipc backend to make sure that everthing is cleaned up on receive error conditions. - switched the ipc backend to using idtree for fnum allocation - in the ntvfs_generic mapping routines, use a allocated secondary structure not a stack structure to ensure the request pointer remains valid even if the backend replies async. (This used to be commit 3457c1836c09c82956697eb21627dfa2ed37682e) --- source4/libcli/raw/rawfile.c | 6 ------ source4/libcli/raw/rawreadwrite.c | 12 ------------ 2 files changed, 18 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c index 1b858d489a..3eb2ab49b2 100644 --- a/source4/libcli/raw/rawfile.c +++ b/source4/libcli/raw/rawfile.c @@ -493,9 +493,6 @@ struct smbcli_request *smb_raw_close_send(struct smbcli_tree *tree, union smb_cl struct smbcli_request *req = NULL; switch (parms->generic.level) { - case RAW_CLOSE_GENERIC: - return NULL; - case RAW_CLOSE_CLOSE: SETUP_REQUEST(SMBclose, 3, 0); SSVAL(req->out.vwv, VWV(0), parms->close.in.fnum); @@ -539,9 +536,6 @@ struct smbcli_request *smb_raw_lock_send(struct smbcli_tree *tree, union smb_loc struct smbcli_request *req = NULL; switch (parms->generic.level) { - case RAW_LOCK_GENERIC: - return NULL; - case RAW_LOCK_LOCK: SETUP_REQUEST(SMBlock, 5, 0); SSVAL(req->out.vwv, VWV(0), parms->lock.in.fnum); diff --git a/source4/libcli/raw/rawreadwrite.c b/source4/libcli/raw/rawreadwrite.c index dbca6fb7a5..e145ff9c10 100644 --- a/source4/libcli/raw/rawreadwrite.c +++ b/source4/libcli/raw/rawreadwrite.c @@ -36,9 +36,6 @@ struct smbcli_request *smb_raw_read_send(struct smbcli_tree *tree, union smb_rea struct smbcli_request *req = NULL; switch (parms->generic.level) { - case RAW_READ_GENERIC: - return NULL; - case RAW_READ_READBRAW: if (tree->session->transport->negotiate.capabilities & CAP_LARGE_FILES) { bigoffset = True; @@ -115,10 +112,6 @@ NTSTATUS smb_raw_read_recv(struct smbcli_request *req, union smb_read *parms) } switch (parms->generic.level) { - case RAW_READ_GENERIC: - /* handled in _send() */ - break; - case RAW_READ_READBRAW: parms->readbraw.out.nread = req->in.size - NBT_HDR_SIZE; if (parms->readbraw.out.nread > @@ -188,9 +181,6 @@ struct smbcli_request *smb_raw_write_send(struct smbcli_tree *tree, union smb_wr struct smbcli_request *req = NULL; switch (parms->generic.level) { - case RAW_WRITE_GENERIC: - return NULL; - case RAW_WRITE_WRITEUNLOCK: SETUP_REQUEST(SMBwriteunlock, 5, 3 + parms->writeunlock.in.count); SSVAL(req->out.vwv, VWV(0), parms->writeunlock.in.fnum); @@ -284,8 +274,6 @@ NTSTATUS smb_raw_write_recv(struct smbcli_request *req, union smb_write *parms) } switch (parms->generic.level) { - case RAW_WRITE_GENERIC: - break; case RAW_WRITE_WRITEUNLOCK: SMBCLI_CHECK_WCT(req, 1); parms->writeunlock.out.nwritten = SVAL(req->in.vwv, VWV(0)); -- cgit From fef66179dd5a7c3498f23a79a43de9632f02648b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 26 Oct 2004 05:34:35 +0000 Subject: r3237: - allow for readx calls larger than 64k - combine setattre and standard levels in setfileinfo, as they use the same structure (This used to be commit e9aa1f789955533aca4fe43d5d74ffa1e8d1300b) --- source4/libcli/raw/rawreadwrite.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawreadwrite.c b/source4/libcli/raw/rawreadwrite.c index e145ff9c10..bc9730f33d 100644 --- a/source4/libcli/raw/rawreadwrite.c +++ b/source4/libcli/raw/rawreadwrite.c @@ -77,9 +77,9 @@ struct smbcli_request *smb_raw_read_send(struct smbcli_tree *tree, union smb_rea SSVAL(req->out.vwv, VWV(1), 0); SSVAL(req->out.vwv, VWV(2), parms->readx.in.fnum); SIVAL(req->out.vwv, VWV(3), parms->readx.in.offset); - SSVAL(req->out.vwv, VWV(5), parms->readx.in.maxcnt); + SSVAL(req->out.vwv, VWV(5), parms->readx.in.maxcnt & 0xFFFF); SSVAL(req->out.vwv, VWV(6), parms->readx.in.mincnt); - SIVAL(req->out.vwv, VWV(7), 0); /* reserved */ + SIVAL(req->out.vwv, VWV(7), parms->readx.in.maxcnt >> 16); SSVAL(req->out.vwv, VWV(9), parms->readx.in.remaining); if (bigoffset) { SIVAL(req->out.vwv, VWV(10),parms->readx.in.offset>>32); -- cgit From 971754c0ed8613b1897041bc5e5b67d1e3b68abe Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 27 Oct 2004 17:40:41 +0000 Subject: r3295: Fix for SMB signing with 56-bit DES session keys. From Nalin Dahyabhai . Jeremy. (This used to be commit afed78f359a15809b2d9b7566e16ade294944fa9) --- source4/libcli/raw/smb_signing.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/smb_signing.c b/source4/libcli/raw/smb_signing.c index 9ba385e062..e1d7b071f2 100644 --- a/source4/libcli/raw/smb_signing.c +++ b/source4/libcli/raw/smb_signing.c @@ -102,6 +102,8 @@ void sign_outgoing_message(struct request_buffer *out, DATA_BLOB *mac_key, uint_ { uint8_t calc_md5_mac[16]; struct MD5Context md5_ctx; + unsigned char key_buf[16]; + /* * Firstly put the sequence number into the first 4 bytes. * and zero out the next 4 bytes. @@ -114,8 +116,15 @@ void sign_outgoing_message(struct request_buffer *out, DATA_BLOB *mac_key, uint_ /* Calculate the 16 byte MAC and place first 8 bytes into the field. */ MD5Init(&md5_ctx); - MD5Update(&md5_ctx, mac_key->data, - mac_key->length); + + /* NB. When making and verifying SMB signatures, Windows apparently + zero-pads the key to 128 bits if it isn't long enough. + From Nalin Dahyabhai */ + MD5Update(&md5_ctx, mac_key->data, mac_key->length); + if (mac_key->length < sizeof(key_buf)) { + memset(key_buf, 0, sizeof(key_buf)); + MD5Update(&md5_ctx, key_buf, sizeof(key_buf) - mac_key->length); + } MD5Update(&md5_ctx, out->buffer + NBT_HDR_SIZE, out->size - NBT_HDR_SIZE); -- cgit From c272e60955bff28ff6431fd50e94807aca1ea016 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 28 Oct 2004 08:15:12 +0000 Subject: r3315: converted the libcli/raw/ code to use the generic socket library. This allows me to test with the socket:testnonblock option. It passes. (This used to be commit 7cb4bf8662825d507d8246647ffb10aa08bad794) --- source4/libcli/raw/clisocket.c | 83 ++++++++++++++++++++++----------------- source4/libcli/raw/clitransport.c | 6 +-- 2 files changed, 49 insertions(+), 40 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 14862a39f0..907206a5e8 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -21,19 +21,6 @@ #include "includes.h" -/* - destroy a socket - */ -static int sock_destructor(void *ptr) -{ - struct smbcli_socket *sock = ptr; - if (sock->fd != -1) { - close(sock->fd); - sock->fd = -1; - } - return 0; -} - /* create a smbcli_socket context */ @@ -47,15 +34,13 @@ struct smbcli_socket *smbcli_sock_init(TALLOC_CTX *mem_ctx) } ZERO_STRUCTP(sock); - sock->fd = -1; + sock->sock = NULL; sock->port = 0; /* 20 second default timeout */ sock->timeout = 20000; sock->hostname = NULL; - talloc_set_destructor(sock, sock_destructor); - return sock; } @@ -65,10 +50,7 @@ struct smbcli_socket *smbcli_sock_init(TALLOC_CTX *mem_ctx) */ BOOL smbcli_sock_connect(struct smbcli_socket *sock, struct in_addr *ip, int port) { - if (getenv("LIBSMB_PROG")) { - sock->fd = sock_exec(getenv("LIBSMB_PROG")); - return sock->fd != -1; - } + NTSTATUS status; if (port == 0) { int i; @@ -82,18 +64,23 @@ BOOL smbcli_sock_connect(struct smbcli_socket *sock, struct in_addr *ip, int por return False; } - sock->dest_ip = *ip; - sock->port = port; - sock->fd = open_socket_out(SOCK_STREAM, - &sock->dest_ip, - sock->port, - LONG_CONNECT_TIMEOUT); - if (sock->fd == -1) { + status = socket_create("ip", SOCKET_TYPE_STREAM, &sock->sock, 0); + if (!NT_STATUS_IS_OK(status)) { return False; } + talloc_steal(sock, sock->sock); - set_blocking(sock->fd, False); - set_socket_options(sock->fd, lp_socket_options()); + status = socket_connect(sock->sock, NULL, 0, inet_ntoa(*ip), port, 0); + if (!NT_STATUS_IS_OK(status)) { + talloc_free(sock->sock); + sock->sock = NULL; + return False; + } + + sock->dest_ip = *ip; + sock->port = port; + + socket_set_option(sock->sock, lp_socket_options(), NULL); return True; } @@ -104,9 +91,9 @@ BOOL smbcli_sock_connect(struct smbcli_socket *sock, struct in_addr *ip, int por ****************************************************************************/ void smbcli_sock_dead(struct smbcli_socket *sock) { - if (sock->fd != -1) { - close(sock->fd); - sock->fd = -1; + if (sock->sock != NULL) { + talloc_free(sock->sock); + sock->sock = NULL; } } @@ -115,7 +102,7 @@ void smbcli_sock_dead(struct smbcli_socket *sock) ****************************************************************************/ void smbcli_sock_set_options(struct smbcli_socket *sock, const char *options) { - set_socket_options(sock->fd, options); + socket_set_option(sock->sock, options, NULL); } /**************************************************************************** @@ -123,12 +110,24 @@ void smbcli_sock_set_options(struct smbcli_socket *sock, const char *options) ****************************************************************************/ ssize_t smbcli_sock_write(struct smbcli_socket *sock, const char *data, size_t len) { - if (sock->fd == -1) { + NTSTATUS status; + DATA_BLOB blob; + size_t nsent; + + if (sock->sock == NULL) { errno = EIO; return -1; } - return write(sock->fd, data, len); + blob.data = discard_const(data); + blob.length = len; + + status = socket_send(sock->sock, &blob, &nsent, 0); + if (NT_STATUS_IS_ERR(status)) { + return -1; + } + + return nsent; } @@ -137,12 +136,20 @@ ssize_t smbcli_sock_write(struct smbcli_socket *sock, const char *data, size_t l ****************************************************************************/ ssize_t smbcli_sock_read(struct smbcli_socket *sock, char *data, size_t len) { - if (sock->fd == -1) { + NTSTATUS status; + size_t nread; + + if (sock->sock == NULL) { errno = EIO; return -1; } - return read(sock->fd, data, len); + status = socket_recv(sock->sock, data, len, &nread, 0); + if (NT_STATUS_IS_ERR(status)) { + return -1; + } + + return nread; } /**************************************************************************** @@ -155,10 +162,12 @@ BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, in char *name, *p; BOOL ret; +#if 0 if (getenv("LIBSMB_PROG")) { sock->fd = sock_exec(getenv("LIBSMB_PROG")); return sock->fd != -1; } +#endif name = talloc_strdup(sock, host); diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index c84c025c74..d82d97a0d9 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -82,7 +82,7 @@ struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock) ZERO_STRUCT(transport->called); - fde.fd = sock->fd; + fde.fd = socket_get_fd(sock->sock); fde.flags = EVENT_FD_READ; fde.handler = smbcli_transport_event_handler; fde.private = transport; @@ -501,7 +501,7 @@ BOOL smbcli_transport_process(struct smbcli_transport *transport) { smbcli_transport_process_send(transport); smbcli_transport_process_recv(transport); - if (transport->socket->fd == -1) { + if (transport->socket->sock == NULL) { return False; } return True; @@ -515,7 +515,7 @@ BOOL smbcli_transport_process(struct smbcli_transport *transport) void smbcli_transport_send(struct smbcli_request *req) { /* check if the transport is dead */ - if (req->transport->socket->fd == -1) { + if (req->transport->socket->sock == NULL) { req->state = SMBCLI_REQUEST_ERROR; req->status = NT_STATUS_NET_WRITE_FAULT; return; -- cgit From 28c3dcf6a3be18fd9fcb56bff039925a1244508d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 28 Oct 2004 11:58:09 +0000 Subject: r3319: fixed a bug in the client library found by the new non-block testing code (This used to be commit 1e62aa262aac1c8e3676caac7b65086d21b7a01e) --- source4/libcli/raw/clitransport.c | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index d82d97a0d9..3335f557e5 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -443,14 +443,7 @@ static void smbcli_transport_process_recv(struct smbcli_transport *transport) transport->recv_buffer.header + transport->recv_buffer.received, NBT_HDR_SIZE - transport->recv_buffer.received); - if (ret == 0) { - smbcli_transport_dead(transport); - return; - } if (ret == -1) { - if (errno == EINTR || errno == EAGAIN) { - return; - } smbcli_transport_dead(transport); return; } @@ -478,9 +471,6 @@ static void smbcli_transport_process_recv(struct smbcli_transport *transport) transport->recv_buffer.req_size - transport->recv_buffer.received); if (ret == -1) { - if (errno == EINTR || errno == EAGAIN) { - return; - } smbcli_transport_dead(transport); return; } -- cgit From e481385391a25c19d82ce93fbec11a973cf82e9f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 28 Oct 2004 12:46:59 +0000 Subject: r3322: fixed a bunch of warnings in the build, including one case where it was a real bug (This used to be commit 02d5d0f685e44bd66aff4a007f0bf34c8f915574) --- source4/libcli/raw/rawrequest.c | 2 +- source4/libcli/raw/rawsearch.c | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 89155451da..dd21eb89ea 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -548,7 +548,7 @@ static size_t smbcli_req_pull_ucs2(struct smbcli_request *req, TALLOC_CTX *mem_c of bytes consumed in the packet is returned */ size_t smbcli_req_pull_ascii(struct smbcli_request *req, TALLOC_CTX *mem_ctx, - char **dest, const char *src, int byte_len, uint_t flags) + char **dest, const char *src, int byte_len, uint_t flags) { int src_len, src_len2; ssize_t ret; diff --git a/source4/libcli/raw/rawsearch.c b/source4/libcli/raw/rawsearch.c index df44dbffa4..dd8904dfd1 100644 --- a/source4/libcli/raw/rawsearch.c +++ b/source4/libcli/raw/rawsearch.c @@ -42,6 +42,8 @@ static void smb_raw_search_backend(struct smbcli_request *req, p = req->in.data + 3; for (i=0; i < count; i++) { + char *name; + search_data.search.id.reserved = CVAL(p, 0); memcpy(search_data.search.id.name, p+1, 11); search_data.search.id.handle = CVAL(p, 12); @@ -51,7 +53,8 @@ static void smb_raw_search_backend(struct smbcli_request *req, search_data.search.write_time = raw_pull_dos_date(req->transport, p + 22); search_data.search.size = IVAL(p, 26); - smbcli_req_pull_ascii(req, mem_ctx, &search_data.search.name, p+30, 13, STR_ASCII); + smbcli_req_pull_ascii(req, mem_ctx, &name, p+30, 13, STR_ASCII); + search_data.search.name = name; if (!callback(private, &search_data)) { break; } -- cgit From 072dfad0afc9940c4c51cbecad9b3acf0cc38844 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 29 Oct 2004 06:01:00 +0000 Subject: r3354: honor "max xmit" and "max mux" from smb.conf in our client code. This is important as it allows the test suite to exercise the multiple reply logic in smbd for trans2 search replies. (This used to be commit 865159016ab1e806465a55697444228fb3fa286e) --- source4/libcli/raw/clisession.c | 12 ++++++------ source4/libcli/raw/clitransport.c | 5 ++++- source4/libcli/raw/rawnegotiate.c | 2 +- 3 files changed, 11 insertions(+), 8 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index 431d225021..5d769f9e32 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -263,8 +263,8 @@ static NTSTATUS smb_raw_session_setup_generic_old(struct smbcli_session *session /* use the old interface */ s2.generic.level = RAW_SESSSETUP_OLD; - s2.old.in.bufsize = ~0; - s2.old.in.mpx_max = 50; + s2.old.in.bufsize = session->transport->options.max_xmit; + s2.old.in.mpx_max = session->transport->options.max_mux; s2.old.in.vc_num = 1; s2.old.in.sesskey = parms->generic.in.sesskey; s2.old.in.domain = parms->generic.in.domain; @@ -311,8 +311,8 @@ static NTSTATUS smb_raw_session_setup_generic_nt1(struct smbcli_session *session union smb_sesssetup s2; s2.generic.level = RAW_SESSSETUP_NT1; - s2.nt1.in.bufsize = ~0; - s2.nt1.in.mpx_max = 50; + s2.nt1.in.bufsize = session->transport->options.max_xmit; + s2.nt1.in.mpx_max = session->transport->options.max_mux; s2.nt1.in.vc_num = 1; s2.nt1.in.sesskey = parms->generic.in.sesskey; s2.nt1.in.capabilities = parms->generic.in.capabilities; @@ -371,8 +371,8 @@ static NTSTATUS smb_raw_session_setup_generic_spnego(struct smbcli_session *sess const char *chosen_oid; s2.generic.level = RAW_SESSSETUP_SPNEGO; - s2.spnego.in.bufsize = ~0; - s2.spnego.in.mpx_max = 50; + s2.spnego.in.bufsize = session->transport->options.max_xmit; + s2.spnego.in.mpx_max = session->transport->options.max_mux; s2.spnego.in.vc_num = 1; s2.spnego.in.sesskey = parms->generic.in.sesskey; s2.spnego.in.capabilities = parms->generic.in.capabilities; diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 3335f557e5..c0ec5d70fe 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -76,7 +76,10 @@ struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock) transport->socket = talloc_reference(transport, sock); transport->negotiate.protocol = PROTOCOL_NT1; transport->options.use_spnego = lp_use_spnego(); - transport->negotiate.max_xmit = ~0; + transport->options.max_xmit = lp_max_xmit(); + transport->options.max_mux = lp_maxmux(); + + transport->negotiate.max_xmit = transport->options.max_xmit; smbcli_init_signing(transport); diff --git a/source4/libcli/raw/rawnegotiate.c b/source4/libcli/raw/rawnegotiate.c index fdc1d0eb60..f99b9741f4 100644 --- a/source4/libcli/raw/rawnegotiate.c +++ b/source4/libcli/raw/rawnegotiate.c @@ -169,7 +169,7 @@ NTSTATUS smb_raw_negotiate(struct smbcli_transport *transport) /* the old core protocol */ transport->negotiate.sec_mode = 0; transport->negotiate.server_time = time(NULL); - transport->negotiate.max_xmit = ~0; + transport->negotiate.max_xmit = transport->options.max_xmit; transport->negotiate.server_zone = get_time_zone(transport->negotiate.server_time); } -- cgit From ad8c4ae941047aa7409ff0d8d10de721f5ff0659 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 30 Oct 2004 01:22:52 +0000 Subject: r3380: - changed the default behaviour of server signing. We now have a default setting of "server signing = auto", which means to offer signing only if we have domain logons enabled (ie. we are a DC). This is a better match for what windows clients want, as unfortunately windows clients always use signing if it is offered, and when they use signing they not only go slower because of the signing itself, they also disable large readx/writex support, so they end up sending very small IOs for. - changed the default max xmit again, this time matching longhorn, which uses 12288. That seems to be a fairly good compromise value. (This used to be commit e63edc81716fefd58a3be25deb3b25e45471f196) --- source4/libcli/raw/smb_signing.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/smb_signing.c b/source4/libcli/raw/smb_signing.c index e1d7b071f2..2a0c64f598 100644 --- a/source4/libcli/raw/smb_signing.c +++ b/source4/libcli/raw/smb_signing.c @@ -394,6 +394,7 @@ BOOL smbcli_init_signing(struct smbcli_transport *transport) transport->negotiate.sign_info.allow_smb_signing = False; break; case SMB_SIGNING_SUPPORTED: + case SMB_SIGNING_AUTO: transport->negotiate.sign_info.allow_smb_signing = True; break; case SMB_SIGNING_REQUIRED: -- cgit From 39883a90cf3ecabfc39e68e8b1d3265a4026d25c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 30 Oct 2004 02:17:03 +0000 Subject: r3383: avoid multi-part SMBtrans and SMBtrans2 replies until our client library can handle them properly (they are difficult to do in an async fashion). By choosing trans.in.max_data to fix in the negotiated buffer size a server won't send us multi-part replies. I notice that windows seems to avoid them too :) (This used to be commit e23edf762cace35f937959c9ffbef718431a79b9) --- source4/libcli/raw/rawacl.c | 2 +- source4/libcli/raw/rawfileinfo.c | 4 ++-- source4/libcli/raw/rawfsinfo.c | 2 +- source4/libcli/raw/rawsearch.c | 8 ++++---- source4/libcli/raw/rawtrans.c | 12 ++++++++++++ 5 files changed, 20 insertions(+), 8 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawacl.c b/source4/libcli/raw/rawacl.c index 20e6d6df31..9b4f2db3b2 100644 --- a/source4/libcli/raw/rawacl.c +++ b/source4/libcli/raw/rawacl.c @@ -31,7 +31,7 @@ struct smbcli_request *smb_raw_query_secdesc_send(struct smbcli_tree *tree, nt.in.max_setup = 0; nt.in.max_param = 4; - nt.in.max_data = 0x10000; + nt.in.max_data = smb_raw_max_trans_data(tree, 4); nt.in.setup_count = 0; nt.in.function = NT_TRANSACT_QUERY_SECURITY_DESC; nt.in.setup = NULL; diff --git a/source4/libcli/raw/rawfileinfo.c b/source4/libcli/raw/rawfileinfo.c index cbb666b7ce..a0ee7891bf 100644 --- a/source4/libcli/raw/rawfileinfo.c +++ b/source4/libcli/raw/rawfileinfo.c @@ -291,7 +291,7 @@ static struct smbcli_request *smb_raw_fileinfo_blob_send(struct smbcli_tree *tre tp.in.setup_count = 1; tp.in.data = data_blob(NULL, 0); tp.in.max_param = 2; - tp.in.max_data = 0xFFFF; + tp.in.max_data = smb_raw_max_trans_data(tree, 2); tp.in.setup = &setup; tp.in.params = data_blob_talloc(mem_ctx, NULL, 4); @@ -344,7 +344,7 @@ static struct smbcli_request *smb_raw_pathinfo_blob_send(struct smbcli_tree *tre tp.in.setup_count = 1; tp.in.data = data_blob(NULL, 0); tp.in.max_param = 2; - tp.in.max_data = 0xFFFF; + tp.in.max_data = smb_raw_max_trans_data(tree, 2); tp.in.setup = &setup; tp.in.params = data_blob_talloc(mem_ctx, NULL, 6); diff --git a/source4/libcli/raw/rawfsinfo.c b/source4/libcli/raw/rawfsinfo.c index aefe8e3085..49378887fa 100644 --- a/source4/libcli/raw/rawfsinfo.c +++ b/source4/libcli/raw/rawfsinfo.c @@ -77,7 +77,7 @@ static struct smbcli_request *smb_raw_qfsinfo_send(struct smbcli_tree *tree, tp.in.timeout = 0; tp.in.setup_count = 1; tp.in.max_param = 0; - tp.in.max_data = 0x1000; /* plenty for all possible QFS levels */ + tp.in.max_data = smb_raw_max_trans_data(tree, 0); tp.in.setup = &setup; tp.in.data = data_blob(NULL, 0); tp.in.timeout = 0; diff --git a/source4/libcli/raw/rawsearch.c b/source4/libcli/raw/rawsearch.c index dd8904dfd1..120a42f0d6 100644 --- a/source4/libcli/raw/rawsearch.c +++ b/source4/libcli/raw/rawsearch.c @@ -206,8 +206,8 @@ static NTSTATUS smb_raw_search_first_blob(struct smbcli_tree *tree, tp.in.timeout = 0; tp.in.setup_count = 1; tp.in.data = data_blob(NULL, 0); - tp.in.max_param = 1024; - tp.in.max_data = 8192; + tp.in.max_param = 10; + tp.in.max_data = smb_raw_max_trans_data(tree, 10); tp.in.setup = &setup; tp.in.params = data_blob_talloc(mem_ctx, NULL, 12); @@ -258,8 +258,8 @@ static NTSTATUS smb_raw_search_next_blob(struct smbcli_tree *tree, tp.in.timeout = 0; tp.in.setup_count = 1; tp.in.data = data_blob(NULL, 0); - tp.in.max_param = 1024; - tp.in.max_data = 8192; + tp.in.max_param = 10; + tp.in.max_data = smb_raw_max_trans_data(tree, 10); tp.in.setup = &setup; tp.in.params = data_blob_talloc(mem_ctx, NULL, 12); diff --git a/source4/libcli/raw/rawtrans.c b/source4/libcli/raw/rawtrans.c index e6c928e3ed..21e20d00e0 100644 --- a/source4/libcli/raw/rawtrans.c +++ b/source4/libcli/raw/rawtrans.c @@ -531,3 +531,15 @@ NTSTATUS smb_raw_nttrans(struct smbcli_tree *tree, return smb_raw_nttrans_recv(req, mem_ctx, parms); } + +/* + work out the maximum data size for a trans request while avoiding + multi-part replies + + TODO: we only need to avoid multi-part replies because the + multi-part trans receive code is broken. +*/ +size_t smb_raw_max_trans_data(struct smbcli_tree *tree, size_t param_size) +{ + return tree->session->transport->options.max_xmit - (70 + param_size); +} -- cgit From 1dc8e52f91797bb6953301cc1ebd9bb5a60626ea Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 30 Oct 2004 04:56:27 +0000 Subject: r3385: when discarding a unmatched reply print the command type to help debugging (This used to be commit 91139ed8d41a1d4b99379142b3e09c6d0a8ff159) --- source4/libcli/raw/clitransport.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index c0ec5d70fe..9d2dd49985 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -350,7 +350,8 @@ static void smbcli_transport_finish_recv(struct smbcli_transport *transport) } if (!req) { - DEBUG(1,("Discarding unmatched reply with mid %d\n", mid)); + DEBUG(1,("Discarding unmatched reply with mid %d op %d\n", + mid, CVAL(hdr, HDR_COM))); goto error; } -- cgit From b24fcfc1aadf56130f9f2f2371282c0c399611c2 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 31 Oct 2004 03:26:30 +0000 Subject: r3400: - allow callers to control the flags2 field in raw packets - added testing of the FLAGS2_READ_PERMIT_EXECUTE bit in the ntdeny tests (This used to be commit adf4a682705871186f3b77ea6d417942445fc5d3) --- source4/libcli/raw/clisession.c | 22 ++++++++++++++++++++++ source4/libcli/raw/rawrequest.c | 22 ++-------------------- 2 files changed, 24 insertions(+), 20 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index 5d769f9e32..9c73c07831 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -33,6 +33,8 @@ struct smbcli_session *smbcli_session_init(struct smbcli_transport *transport) { struct smbcli_session *session; + uint16_t flags2; + uint32_t capabilities; session = talloc_p(transport, struct smbcli_session); if (!session) { @@ -44,6 +46,26 @@ struct smbcli_session *smbcli_session_init(struct smbcli_transport *transport) session->pid = (uint16_t)getpid(); session->vuid = UID_FIELD_INVALID; + + capabilities = transport->negotiate.capabilities; + + flags2 = FLAGS2_LONG_PATH_COMPONENTS; + + if (capabilities & CAP_UNICODE) { + flags2 |= FLAGS2_UNICODE_STRINGS; + } + if (capabilities & CAP_STATUS32) { + flags2 |= FLAGS2_32_BIT_ERROR_CODES; + } + if (capabilities & CAP_EXTENDED_SECURITY) { + flags2 |= FLAGS2_EXTENDED_SECURITY; + } + if (session->transport->negotiate.sign_info.doing_signing) { + flags2 |= FLAGS2_SMB_SECURITY_SIGNATURES; + } + + session->flags2 = flags2; + return session; } diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index dd21eb89ea..26604cbcd4 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -139,35 +139,17 @@ struct smbcli_request *smbcli_request_setup_transport(struct smbcli_transport *t way. This interface is used before a session is setup. */ struct smbcli_request *smbcli_request_setup_session(struct smbcli_session *session, - uint8_t command, uint_t wct, uint_t buflen) + uint8_t command, uint_t wct, uint_t buflen) { struct smbcli_request *req; - uint16_t flags2; - uint32_t capabilities; req = smbcli_request_setup_transport(session->transport, command, wct, buflen); if (!req) return NULL; req->session = session; - - flags2 = FLAGS2_LONG_PATH_COMPONENTS; - capabilities = session->transport->negotiate.capabilities; - - if (capabilities & CAP_UNICODE) { - flags2 |= FLAGS2_UNICODE_STRINGS; - } - if (capabilities & CAP_STATUS32) { - flags2 |= FLAGS2_32_BIT_ERROR_CODES; - } - if (capabilities & CAP_EXTENDED_SECURITY) { - flags2 |= FLAGS2_EXTENDED_SECURITY; - } - if (session->transport->negotiate.sign_info.doing_signing) { - flags2 |= FLAGS2_SMB_SECURITY_SIGNATURES; - } - SSVAL(req->out.hdr, HDR_FLG2, flags2); + SSVAL(req->out.hdr, HDR_FLG2, session->flags2); SSVAL(req->out.hdr, HDR_PID, session->pid & 0xFFFF); SSVAL(req->out.hdr, HDR_PIDHIGH, session->pid >> 16); SSVAL(req->out.hdr, HDR_UID, session->vuid); -- cgit From 9f1210a243654fd6d94acdef83f468a33c1b3b3f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 1 Nov 2004 01:03:22 +0000 Subject: r3419: moved the libcli/raw structures into libcli/raw/libcliraw.h and made them private (This used to be commit 386ac565c452ede1d74e06acb401ca9db99d3ff3) --- source4/libcli/raw/clioplock.c | 1 + source4/libcli/raw/clisession.c | 1 + source4/libcli/raw/clisocket.c | 1 + source4/libcli/raw/clitransport.c | 1 + source4/libcli/raw/clitree.c | 1 + source4/libcli/raw/libcliraw.h | 286 ++++++++++++++++++++++++++++++++++++ source4/libcli/raw/rawacl.c | 1 + source4/libcli/raw/rawdate.c | 1 + source4/libcli/raw/raweas.c | 1 + source4/libcli/raw/rawfile.c | 1 + source4/libcli/raw/rawfileinfo.c | 1 + source4/libcli/raw/rawfsinfo.c | 1 + source4/libcli/raw/rawioctl.c | 1 + source4/libcli/raw/rawnegotiate.c | 1 + source4/libcli/raw/rawnotify.c | 1 + source4/libcli/raw/rawreadwrite.c | 1 + source4/libcli/raw/rawrequest.c | 1 + source4/libcli/raw/rawsearch.c | 1 + source4/libcli/raw/rawsetfileinfo.c | 1 + source4/libcli/raw/rawtrans.c | 1 + source4/libcli/raw/smb_signing.c | 1 + 21 files changed, 306 insertions(+) create mode 100644 source4/libcli/raw/libcliraw.h (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clioplock.c b/source4/libcli/raw/clioplock.c index 6ae21a08f4..f26aa0c5f2 100644 --- a/source4/libcli/raw/clioplock.c +++ b/source4/libcli/raw/clioplock.c @@ -19,6 +19,7 @@ */ #include "includes.h" +#include "libcli/raw/libcliraw.h" /**************************************************************************** send an ack for an oplock break request diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index 9c73c07831..14018f676c 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -20,6 +20,7 @@ */ #include "includes.h" +#include "libcli/raw/libcliraw.h" #define SETUP_REQUEST_SESSION(cmd, wct, buflen) do { \ req = smbcli_request_setup_session(session, cmd, wct, buflen); \ diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 907206a5e8..c641f8bf12 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -20,6 +20,7 @@ */ #include "includes.h" +#include "libcli/raw/libcliraw.h" /* create a smbcli_socket context diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 9d2dd49985..a6e8071a05 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -20,6 +20,7 @@ */ #include "includes.h" +#include "libcli/raw/libcliraw.h" static void smbcli_transport_process_recv(struct smbcli_transport *transport); diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index 77fe0ebe2f..daa8549099 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -20,6 +20,7 @@ */ #include "includes.h" +#include "libcli/raw/libcliraw.h" #define SETUP_REQUEST_TREE(cmd, wct, buflen) do { \ req = smbcli_request_setup(tree, cmd, wct, buflen); \ diff --git a/source4/libcli/raw/libcliraw.h b/source4/libcli/raw/libcliraw.h new file mode 100644 index 0000000000..48abc82a68 --- /dev/null +++ b/source4/libcli/raw/libcliraw.h @@ -0,0 +1,286 @@ +/* + Unix SMB/CIFS implementation. + SMB parameters and setup + Copyright (C) Andrew Tridgell 1992-1998 + Copyright (C) Luke Kenneth Casson Leighton 1996-1998 + Copyright (C) Jeremy Allison 1998 + Copyright (C) James Myers 2003 + + 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. +*/ + +struct smbcli_tree; /* forward declare */ +struct smbcli_request; /* forward declare */ +struct smbcli_session; /* forward declare */ +struct smbcli_transport; /* forward declare */ + +/* context that will be and has been negotiated between the client and server */ +struct smbcli_negotiate { + /* + * negotiated maximum transmit size - this is given to us by the server + */ + uint32_t max_xmit; + + /* maximum number of requests that can be multiplexed */ + uint16_t max_mux; + + /* the negotiatiated protocol */ + enum protocol_types protocol; + + uint8_t sec_mode; /* security mode returned by negprot */ + uint8_t key_len; + DATA_BLOB server_guid; /* server_guid */ + DATA_BLOB secblob; /* cryptkey or negTokenInit blob */ + uint32_t sesskey; + + struct smb_signing_context sign_info; + + /* capabilities that the server reported */ + uint32_t capabilities; + + int server_zone; + time_t server_time; + uint_t readbraw_supported:1; + uint_t writebraw_supported:1; + + char *server_domain; +}; + +/* this is the context for a SMB socket associated with the socket itself */ +struct smbcli_socket { + struct in_addr dest_ip; + /* dest hostname (which may or may not be a DNS name) */ + char *hostname; + + /* the port used */ + int port; + + struct socket_context *sock; + + /* a count of the number of packets we have received. We + * actually only care about zero/non-zero at this stage */ + uint_t pkt_count; + + /* the network address of the client */ + char *client_addr; + + /* timeout for socket operations in milliseconds. */ + int timeout; +}; + +/* + this structure allows applications to control the behaviour of the + client library +*/ +struct smbcli_options { + uint_t use_oplocks:1; + uint_t use_level2_oplocks:1; + uint_t use_spnego:1; + uint32_t max_xmit; + uint16_t max_mux; +}; + +/* this is the context for the client transport layer */ +struct smbcli_transport { + /* socket level info */ + struct smbcli_socket *socket; + + /* the next mid to be allocated - needed for signing and + request matching */ + uint16_t next_mid; + + /* negotiated protocol information */ + struct smbcli_negotiate negotiate; + + /* options to control the behaviour of the client code */ + struct smbcli_options options; + + /* is a readbraw pending? we need to handle that case + specially on receiving packets */ + uint_t readbraw_pending:1; + + /* an idle function - if this is defined then it will be + called once every period seconds while we are waiting + for a packet */ + struct { + void (*func)(struct smbcli_transport *, void *); + void *private; + uint_t period; + } idle; + + /* the error fields from the last message */ + struct { + enum {ETYPE_NONE, ETYPE_DOS, ETYPE_NT, ETYPE_SOCKET, ETYPE_NBT} etype; + union { + struct { + uint8_t eclass; + uint16_t ecode; + } dos; + NTSTATUS nt_status; + enum {SOCKET_READ_TIMEOUT, + SOCKET_READ_EOF, + SOCKET_READ_ERROR, + SOCKET_WRITE_ERROR, + SOCKET_READ_BAD_SIG} socket_error; + uint_t nbt_error; + } e; + } error; + + struct { + /* a oplock break request handler */ + BOOL (*handler)(struct smbcli_transport *transport, + uint16_t tid, uint16_t fnum, uint8_t level, void *private); + /* private data passed to the oplock handler */ + void *private; + } oplock; + + /* a list of async requests that are pending for send on this connection */ + struct smbcli_request *pending_send; + + /* a list of async requests that are pending for receive on this connection */ + struct smbcli_request *pending_recv; + + /* remember the called name - some sub-protocols require us to + know the server name */ + struct nmb_name called; + + /* a buffer for partially received SMB packets. */ + struct { + uint8_t header[NBT_HDR_SIZE]; + size_t req_size; + size_t received; + uint8_t *buffer; + } recv_buffer; + + /* the event handle for waiting for socket IO */ + struct { + struct event_context *ctx; + struct fd_event *fde; + struct timed_event *te; + } event; +}; + +/* this is the context for the user */ + +/* this is the context for the session layer */ +struct smbcli_session { + /* transport layer info */ + struct smbcli_transport *transport; + + /* after a session setup the server provides us with + a vuid identifying the security context */ + uint16_t vuid; + + /* default pid for this session */ + uint32_t pid; + + /* the flags2 for each packet - this allows + the user to control these for torture testing */ + uint16_t flags2; + + DATA_BLOB user_session_key; + + /* the spnego context if we use extented security */ + struct gensec_security *gensec; +}; + +/* + smbcli_tree context: internal state for a tree connection. + */ +struct smbcli_tree { + /* session layer info */ + struct smbcli_session *session; + + uint16_t tid; /* tree id, aka cnum */ + char *device; + char *fs_type; +}; + + +/* + a client request moves between the following 4 states. +*/ +enum smbcli_request_state {SMBCLI_REQUEST_INIT, /* we are creating the request */ + SMBCLI_REQUEST_SEND, /* the request is in the outgoing socket Q */ + SMBCLI_REQUEST_RECV, /* we are waiting for a matching reply */ + SMBCLI_REQUEST_DONE, /* the request is finished */ + SMBCLI_REQUEST_ERROR}; /* a packet or transport level error has occurred */ + +/* the context for a single SMB request. This is passed to any request-context + * functions (similar to context.h, the server version). + * This will allow requests to be multi-threaded. */ +struct smbcli_request { + /* allow a request to be part of a list of requests */ + struct smbcli_request *next, *prev; + + /* each request is in one of 4 possible states */ + enum smbcli_request_state state; + + /* a request always has a transport context, nearly always has + a session context and usually has a tree context */ + struct smbcli_transport *transport; + struct smbcli_session *session; + struct smbcli_tree *tree; + + /* the flags2 from the SMB request, in raw form (host byte + order). Used to parse strings */ + uint16_t flags2; + + /* the NT status for this request. Set by packet receive code + or code detecting error. */ + NTSTATUS status; + + /* the sequence number of this packet - used for signing */ + uint_t seq_num; + + /* set if this is a one-way request, meaning we are not + expecting a reply from the server. */ + uint_t one_way_request:1; + + /* set this when the request should only increment the signing + counter by one */ + uint_t sign_single_increment:1; + + /* the mid of this packet - used to match replies */ + uint16_t mid; + + struct request_buffer in; + struct request_buffer out; + + /* information on what to do with a reply when it is received + asyncronously. If this is not setup when a reply is received then + the reply is discarded + + The private pointer is private to the caller of the client + library (the application), not private to the library + */ + struct { + void (*fn)(struct smbcli_request *); + void *private; + } async; +}; + +/* useful way of catching wct errors with file and line number */ +#define SMBCLI_CHECK_MIN_WCT(req, wcount) if ((req)->in.wct < (wcount)) { \ + DEBUG(1,("Unexpected WCT %d at %s(%d) - expected min %d\n", (req)->in.wct, __FILE__, __LINE__, wcount)); \ + req->status = NT_STATUS_INVALID_PARAMETER; \ + goto failed; \ +} + +#define SMBCLI_CHECK_WCT(req, wcount) if ((req)->in.wct != (wcount)) { \ + DEBUG(1,("Unexpected WCT %d at %s(%d) - expected %d\n", (req)->in.wct, __FILE__, __LINE__, wcount)); \ + req->status = NT_STATUS_INVALID_PARAMETER; \ + goto failed; \ +} diff --git a/source4/libcli/raw/rawacl.c b/source4/libcli/raw/rawacl.c index 9b4f2db3b2..35c7ce2049 100644 --- a/source4/libcli/raw/rawacl.c +++ b/source4/libcli/raw/rawacl.c @@ -19,6 +19,7 @@ */ #include "includes.h" +#include "libcli/raw/libcliraw.h" /**************************************************************************** fetch file ACL (async send) diff --git a/source4/libcli/raw/rawdate.c b/source4/libcli/raw/rawdate.c index bfb7465bd5..db18a7a194 100644 --- a/source4/libcli/raw/rawdate.c +++ b/source4/libcli/raw/rawdate.c @@ -21,6 +21,7 @@ */ #include "includes.h" +#include "libcli/raw/libcliraw.h" /******************************************************************* put a dos date into a buffer (time/date format) diff --git a/source4/libcli/raw/raweas.c b/source4/libcli/raw/raweas.c index e07fbcd288..da079c402b 100644 --- a/source4/libcli/raw/raweas.c +++ b/source4/libcli/raw/raweas.c @@ -19,6 +19,7 @@ */ #include "includes.h" +#include "libcli/raw/libcliraw.h" /* work out how many bytes on the wire a ea list will consume. diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c index 3eb2ab49b2..92b995dd4a 100644 --- a/source4/libcli/raw/rawfile.c +++ b/source4/libcli/raw/rawfile.c @@ -21,6 +21,7 @@ */ #include "includes.h" +#include "libcli/raw/libcliraw.h" #define SETUP_REQUEST(cmd, wct, buflen) do { \ req = smbcli_request_setup(tree, cmd, wct, buflen); \ diff --git a/source4/libcli/raw/rawfileinfo.c b/source4/libcli/raw/rawfileinfo.c index a0ee7891bf..c844f923b8 100644 --- a/source4/libcli/raw/rawfileinfo.c +++ b/source4/libcli/raw/rawfileinfo.c @@ -20,6 +20,7 @@ */ #include "includes.h" +#include "libcli/raw/libcliraw.h" /* local macros to make the code more readable */ #define FINFO_CHECK_MIN_SIZE(size) if (blob->length < (size)) { \ diff --git a/source4/libcli/raw/rawfsinfo.c b/source4/libcli/raw/rawfsinfo.c index 49378887fa..7cec93b6bc 100644 --- a/source4/libcli/raw/rawfsinfo.c +++ b/source4/libcli/raw/rawfsinfo.c @@ -21,6 +21,7 @@ */ #include "includes.h" +#include "libcli/raw/libcliraw.h" /**************************************************************************** Query FS Info - SMBdskattr call (async send) diff --git a/source4/libcli/raw/rawioctl.c b/source4/libcli/raw/rawioctl.c index 798300451b..874d055013 100644 --- a/source4/libcli/raw/rawioctl.c +++ b/source4/libcli/raw/rawioctl.c @@ -20,6 +20,7 @@ */ #include "includes.h" +#include "libcli/raw/libcliraw.h" #define SETUP_REQUEST(cmd, wct, buflen) do { \ req = smbcli_request_setup(tree, cmd, wct, buflen); \ diff --git a/source4/libcli/raw/rawnegotiate.c b/source4/libcli/raw/rawnegotiate.c index f99b9741f4..da7bcabda9 100644 --- a/source4/libcli/raw/rawnegotiate.c +++ b/source4/libcli/raw/rawnegotiate.c @@ -20,6 +20,7 @@ */ #include "includes.h" +#include "libcli/raw/libcliraw.h" static const struct { enum protocol_types prot; diff --git a/source4/libcli/raw/rawnotify.c b/source4/libcli/raw/rawnotify.c index 47553e735e..ea5fada1ee 100644 --- a/source4/libcli/raw/rawnotify.c +++ b/source4/libcli/raw/rawnotify.c @@ -19,6 +19,7 @@ */ #include "includes.h" +#include "libcli/raw/libcliraw.h" /**************************************************************************** change notify (async send) diff --git a/source4/libcli/raw/rawreadwrite.c b/source4/libcli/raw/rawreadwrite.c index bc9730f33d..4978514d26 100644 --- a/source4/libcli/raw/rawreadwrite.c +++ b/source4/libcli/raw/rawreadwrite.c @@ -20,6 +20,7 @@ */ #include "includes.h" +#include "libcli/raw/libcliraw.h" #define SETUP_REQUEST(cmd, wct, buflen) do { \ req = smbcli_request_setup(tree, cmd, wct, buflen); \ diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 26604cbcd4..5cf1621d2d 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -24,6 +24,7 @@ */ #include "includes.h" +#include "libcli/raw/libcliraw.h" /* we over allocate the data buffer to prevent too many realloc calls */ #define REQ_OVER_ALLOCATION 256 diff --git a/source4/libcli/raw/rawsearch.c b/source4/libcli/raw/rawsearch.c index 120a42f0d6..4907eec70a 100644 --- a/source4/libcli/raw/rawsearch.c +++ b/source4/libcli/raw/rawsearch.c @@ -19,6 +19,7 @@ */ #include "includes.h" +#include "libcli/raw/libcliraw.h" /**************************************************************************** Old style search backend - process output. diff --git a/source4/libcli/raw/rawsetfileinfo.c b/source4/libcli/raw/rawsetfileinfo.c index 2b525f2661..0c263ac082 100644 --- a/source4/libcli/raw/rawsetfileinfo.c +++ b/source4/libcli/raw/rawsetfileinfo.c @@ -20,6 +20,7 @@ */ #include "includes.h" +#include "libcli/raw/libcliraw.h" /**************************************************************************** Handle setfileinfo/setpathinfo trans2 backend. diff --git a/source4/libcli/raw/rawtrans.c b/source4/libcli/raw/rawtrans.c index 21e20d00e0..32c12382f6 100644 --- a/source4/libcli/raw/rawtrans.c +++ b/source4/libcli/raw/rawtrans.c @@ -20,6 +20,7 @@ */ #include "includes.h" +#include "libcli/raw/libcliraw.h" /* diff --git a/source4/libcli/raw/smb_signing.c b/source4/libcli/raw/smb_signing.c index 2a0c64f598..d348c202f5 100644 --- a/source4/libcli/raw/smb_signing.c +++ b/source4/libcli/raw/smb_signing.c @@ -21,6 +21,7 @@ */ #include "includes.h" +#include "libcli/raw/libcliraw.h" /*********************************************************** SMB signing - Common code before we set a new signing implementation -- cgit From 284349482f5293a9a23d0f72d7c2aab46b55843b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 1 Nov 2004 22:48:25 +0000 Subject: r3443: the next stage in the include files re-organisation. I have created the include/system/ directory, which will contain the wrappers for the system includes for logical subsystems. So far I have created include/system/kerberos.h and include/system/network.h, which contain all the system includes for kerberos code and networking code. These are the included in subsystems that need kerberos or networking respectively. Note that this method avoids the mess of #ifdef HAVE_XXX_H in every C file, instead each C module includes the include/system/XXX.h file for the logical system support it needs, and the details are kept isolated in include/system/ This patch also creates a "struct ipv4_addr" which replaces "struct in_addr" in our code. That avoids every C file needing to import all the system networking headers. (This used to be commit 2e25c71853f8996f73755277e448e7d670810349) --- source4/libcli/raw/clisocket.c | 6 +++--- source4/libcli/raw/libcliraw.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index c641f8bf12..349b4b9a9c 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -49,7 +49,7 @@ struct smbcli_socket *smbcli_sock_init(TALLOC_CTX *mem_ctx) connect a smbcli_socket context to an IP/port pair if port is 0 then choose 445 then 139 */ -BOOL smbcli_sock_connect(struct smbcli_socket *sock, struct in_addr *ip, int port) +BOOL smbcli_sock_connect(struct smbcli_socket *sock, struct ipv4_addr *ip, int port) { NTSTATUS status; @@ -71,7 +71,7 @@ BOOL smbcli_sock_connect(struct smbcli_socket *sock, struct in_addr *ip, int por } talloc_steal(sock, sock->sock); - status = socket_connect(sock->sock, NULL, 0, inet_ntoa(*ip), port, 0); + status = socket_connect(sock->sock, NULL, 0, sys_inet_ntoa(*ip), port, 0); if (!NT_STATUS_IS_OK(status)) { talloc_free(sock->sock); sock->sock = NULL; @@ -159,7 +159,7 @@ resolve a hostname and connect BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, int port) { int name_type = 0x20; - struct in_addr ip; + struct ipv4_addr ip; char *name, *p; BOOL ret; diff --git a/source4/libcli/raw/libcliraw.h b/source4/libcli/raw/libcliraw.h index 48abc82a68..9bbdd8a222 100644 --- a/source4/libcli/raw/libcliraw.h +++ b/source4/libcli/raw/libcliraw.h @@ -60,7 +60,7 @@ struct smbcli_negotiate { /* this is the context for a SMB socket associated with the socket itself */ struct smbcli_socket { - struct in_addr dest_ip; + struct ipv4_addr dest_ip; /* dest hostname (which may or may not be a DNS name) */ char *hostname; -- cgit From ead3508ac81ff3ed2a48753f3b5e23537ba6ec73 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 2 Nov 2004 00:24:21 +0000 Subject: r3447: more include/system/XXX.h include files (This used to be commit 264ce9181089922547e8f6f67116f2d7277a5105) --- source4/libcli/raw/clitransport.c | 1 + source4/libcli/raw/rawnegotiate.c | 1 + 2 files changed, 2 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index a6e8071a05..e70ee915c6 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -21,6 +21,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" +#include "system/time.h" static void smbcli_transport_process_recv(struct smbcli_transport *transport); diff --git a/source4/libcli/raw/rawnegotiate.c b/source4/libcli/raw/rawnegotiate.c index da7bcabda9..4f7d7b4058 100644 --- a/source4/libcli/raw/rawnegotiate.c +++ b/source4/libcli/raw/rawnegotiate.c @@ -21,6 +21,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" +#include "system/time.h" static const struct { enum protocol_types prot; -- cgit From edbfc0f6e70150e321822365bf0eead2821551bd Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 2 Nov 2004 02:57:18 +0000 Subject: r3453: - split out the auth and popt includes - tidied up some of the system includes - moved a few more structures back from misc.idl to netlogon.idl and samr.idl now that pidl knows about inter-IDL dependencies (This used to be commit 7b7477ac42d96faac1b0ff361525d2c63cedfc64) --- source4/libcli/raw/clisession.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index 14018f676c..23e1d8507e 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -21,6 +21,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" +#include "auth/auth.h" #define SETUP_REQUEST_SESSION(cmd, wct, buflen) do { \ req = smbcli_request_setup_session(session, cmd, wct, buflen); \ -- cgit From 8692564e350db4dfa4a9ef4c4cb014d76b284d3b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 2 Nov 2004 04:17:30 +0000 Subject: r3458: more solaris portability fixes, the main one being that we can't use a structure element called "open" as its a macro on solaris. (This used to be commit 4e92e15c4e396b1d8cd211192888fea68c2cf0f9) --- source4/libcli/raw/rawfile.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c index 92b995dd4a..4da7ff3a9e 100644 --- a/source4/libcli/raw/rawfile.c +++ b/source4/libcli/raw/rawfile.c @@ -300,15 +300,15 @@ struct smbcli_request *smb_raw_open_send(struct smbcli_tree *tree, union smb_ope int len; struct smbcli_request *req = NULL; - switch (parms->open.level) { + switch (parms->generic.level) { case RAW_OPEN_T2OPEN: return smb_raw_t2open_send(tree, parms); case RAW_OPEN_OPEN: SETUP_REQUEST(SMBopen, 2, 0); - SSVAL(req->out.vwv, VWV(0), parms->open.in.flags); - SSVAL(req->out.vwv, VWV(1), parms->open.in.search_attrs); - smbcli_req_append_ascii4(req, parms->open.in.fname, STR_TERMINATE); + SSVAL(req->out.vwv, VWV(0), parms->openold.in.flags); + SSVAL(req->out.vwv, VWV(1), parms->openold.in.search_attrs); + smbcli_req_append_ascii4(req, parms->openold.in.fname, STR_TERMINATE); break; case RAW_OPEN_OPENX: @@ -397,18 +397,18 @@ NTSTATUS smb_raw_open_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, unio goto failed; } - switch (parms->open.level) { + switch (parms->openold.level) { case RAW_OPEN_T2OPEN: return smb_raw_t2open_recv(req, mem_ctx, parms); case RAW_OPEN_OPEN: SMBCLI_CHECK_WCT(req, 7); - parms->open.out.fnum = SVAL(req->in.vwv, VWV(0)); - parms->open.out.attrib = SVAL(req->in.vwv, VWV(1)); - parms->open.out.write_time = raw_pull_dos_date3(req->transport, + parms->openold.out.fnum = SVAL(req->in.vwv, VWV(0)); + parms->openold.out.attrib = SVAL(req->in.vwv, VWV(1)); + parms->openold.out.write_time = raw_pull_dos_date3(req->transport, req->in.vwv + VWV(2)); - parms->open.out.size = IVAL(req->in.vwv, VWV(4)); - parms->open.out.rmode = SVAL(req->in.vwv, VWV(6)); + parms->openold.out.size = IVAL(req->in.vwv, VWV(4)); + parms->openold.out.rmode = SVAL(req->in.vwv, VWV(6)); break; case RAW_OPEN_OPENX: -- cgit From a1d0b97ed40fe6985bb45b1715309638e7faaffc Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 2 Nov 2004 06:14:15 +0000 Subject: r3462: separate out the crypto includes (This used to be commit 3f75117db921e493bb77a5dc14b8ce91a6288f30) --- source4/libcli/raw/smb_signing.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/smb_signing.c b/source4/libcli/raw/smb_signing.c index d348c202f5..c0c1337312 100644 --- a/source4/libcli/raw/smb_signing.c +++ b/source4/libcli/raw/smb_signing.c @@ -22,6 +22,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" +#include "lib/crypto/crypto.h" /*********************************************************** SMB signing - Common code before we set a new signing implementation -- cgit From 3643fb11092e28a9538ef32cedce8ff21ad86a28 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 2 Nov 2004 06:42:15 +0000 Subject: r3463: separated out some more headers (asn_1.h, messages.h, dlinklist.h and ioctl.h) (This used to be commit b97e395c814762024336c1cf4d7c25be8da5813a) --- source4/libcli/raw/clisession.c | 1 + source4/libcli/raw/clitransport.c | 1 + source4/libcli/raw/rawrequest.c | 1 + 3 files changed, 3 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index 23e1d8507e..b7802d8065 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -22,6 +22,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" #include "auth/auth.h" +#include "asn_1.h" #define SETUP_REQUEST_SESSION(cmd, wct, buflen) do { \ req = smbcli_request_setup_session(session, cmd, wct, buflen); \ diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index e70ee915c6..c5e3d39545 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -22,6 +22,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" #include "system/time.h" +#include "dlinklist.h" static void smbcli_transport_process_recv(struct smbcli_transport *transport); diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 5cf1621d2d..0526fec74b 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -25,6 +25,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" +#include "dlinklist.h" /* we over allocate the data buffer to prevent too many realloc calls */ #define REQ_OVER_ALLOCATION 256 -- cgit From aa34fcebf8aa0660574a7c6976b33b3f37985e27 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 2 Nov 2004 07:18:24 +0000 Subject: r3466: split out request.h, signing.h, and smb_server.h (This used to be commit 7c4e6ebf05790dd6e29896dd316db0fff613aa4e) --- source4/libcli/raw/libcliraw.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/libcliraw.h b/source4/libcli/raw/libcliraw.h index 9bbdd8a222..9b03ab713b 100644 --- a/source4/libcli/raw/libcliraw.h +++ b/source4/libcli/raw/libcliraw.h @@ -21,6 +21,8 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#include "request.h" + struct smbcli_tree; /* forward declare */ struct smbcli_request; /* forward declare */ struct smbcli_session; /* forward declare */ -- cgit From a99b6219a810a1cd10bd62a6716780602808f0cd Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 2 Nov 2004 12:15:17 +0000 Subject: r3481: split out client.h and events.h (This used to be commit c6f486574470a311e0d336c026103f131451e21e) --- source4/libcli/raw/clitransport.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index c5e3d39545..00e52f3a14 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -23,6 +23,7 @@ #include "libcli/raw/libcliraw.h" #include "system/time.h" #include "dlinklist.h" +#include "events.h" static void smbcli_transport_process_recv(struct smbcli_transport *transport); -- cgit From dde07058075d357cfdc63624c8dcaa67ebd40add Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 3 Nov 2004 10:09:48 +0000 Subject: r3507: - added deferred replies on sharing violation in pvfs open. The deferred reply is short-circuited immediately when the file is closed by another user, allowing it to be opened by the waiting user. - added a sane set of timeval manipulation routines - converted all the events code and code that uses it to use struct timeval instead of time_t, which allows for microsecond resolution instead of 1 second resolution. This was needed for doing the pvfs deferred open code, and is why the patch is so big. (This used to be commit 0d51511d408d91eb5f68a35e980e0875299b1831) --- source4/libcli/raw/clitransport.c | 16 ++++++++-------- source4/libcli/raw/libcliraw.h | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 00e52f3a14..52cb4d8beb 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -33,7 +33,7 @@ static void smbcli_transport_process_send(struct smbcli_transport *transport); an event has happened on the socket */ static void smbcli_transport_event_handler(struct event_context *ev, struct fd_event *fde, - time_t t, uint16_t flags) + struct timeval t, uint16_t flags) { struct smbcli_transport *transport = fde->private; @@ -233,21 +233,21 @@ again: } static void idle_handler(struct event_context *ev, - struct timed_event *te, time_t t) + struct timed_event *te, struct timeval t) { struct smbcli_transport *transport = te->private; - te->next_event = t + transport->idle.period; + te->next_event = timeval_add(&te->next_event, 0, transport->idle.period); transport->idle.func(transport, transport->idle.private); } /* setup the idle handler for a transport - the period is in seconds + the period is in microseconds */ void smbcli_transport_idle_handler(struct smbcli_transport *transport, - void (*idle_func)(struct smbcli_transport *, void *), - uint_t period, - void *private) + void (*idle_func)(struct smbcli_transport *, void *), + uint64_t period, + void *private) { struct timed_event te; transport->idle.func = idle_func; @@ -258,7 +258,7 @@ void smbcli_transport_idle_handler(struct smbcli_transport *transport, event_remove_timed(transport->event.ctx, transport->event.te); } - te.next_event = time(NULL) + period; + te.next_event = timeval_current_ofs(0, period); te.handler = idle_handler; te.private = transport; transport->event.te = event_add_timed(transport->event.ctx, &te); diff --git a/source4/libcli/raw/libcliraw.h b/source4/libcli/raw/libcliraw.h index 9b03ab713b..b00af846b7 100644 --- a/source4/libcli/raw/libcliraw.h +++ b/source4/libcli/raw/libcliraw.h @@ -114,7 +114,7 @@ struct smbcli_transport { uint_t readbraw_pending:1; /* an idle function - if this is defined then it will be - called once every period seconds while we are waiting + called once every period microseconds while we are waiting for a packet */ struct { void (*func)(struct smbcli_transport *, void *); -- cgit From 70bb74eefd364908ec1234dd5a3ecf7090f7fad5 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 7 Nov 2004 10:00:32 +0000 Subject: r3591: to get a bit more useful info from valgrind I'm disabling the deliberate over-allocation of request structures in smbd and libcli/raw code for now. (This used to be commit 07596d87213e8ccbf6a0e7bc216d692065f43403) --- source4/libcli/raw/rawrequest.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 0526fec74b..8d0767b3f5 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -28,7 +28,7 @@ #include "dlinklist.h" /* we over allocate the data buffer to prevent too many realloc calls */ -#define REQ_OVER_ALLOCATION 256 +#define REQ_OVER_ALLOCATION 0 /* assume that a character will not consume more than 3 bytes per char */ #define MAX_BYTES_PER_CHAR 3 -- cgit From 017bf499d44d23c50406fb9647f9a2161be395f0 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 10 Nov 2004 04:52:22 +0000 Subject: r3652: Fix malloc-history dependent failures in smbtorture. Because -r 3591 removed the over-allocation, realloc() had a chance of returning a different pointer. This broke the length calculations in the trans2 send code. I think the length calculations coudld be better expressed (less cute PTR_DIFF tricks) but I'm not going to touch this any more than I need to. Andrew Bartlett (This used to be commit 4bfc916a2c3b9745f47ce4eaa892cdcc431e19db) --- source4/libcli/raw/rawtrans.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawtrans.c b/source4/libcli/raw/rawtrans.c index 32c12382f6..111a7ded2a 100644 --- a/source4/libcli/raw/rawtrans.c +++ b/source4/libcli/raw/rawtrans.c @@ -222,7 +222,13 @@ struct smbcli_request *smb_raw_trans_send_backend(struct smbcli_tree *tree, if (!req) { return NULL; } - + + /* Watch out, this changes the req->out.* pointers */ + if (command == SMBtrans && parms->in.trans_name) { + namelen = smbcli_req_append_string(req, parms->in.trans_name, + STR_TERMINATE); + } + /* fill in SMB parameters */ outparam = req->out.data + padding; outdata = outparam + parms->in.params.length; @@ -230,11 +236,6 @@ struct smbcli_request *smb_raw_trans_send_backend(struct smbcli_tree *tree, /* make sure we don't leak data via the padding */ memset(req->out.data, 0, padding); - if (command == SMBtrans && parms->in.trans_name) { - namelen = smbcli_req_append_string(req, parms->in.trans_name, - STR_TERMINATE); - } - /* primary request */ SSVAL(req->out.vwv,VWV(0),parms->in.params.length); SSVAL(req->out.vwv,VWV(1),parms->in.data.length); -- cgit From cb700e90c22d9e301a05142699df7b64402a08d8 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 10 Nov 2004 10:56:43 +0000 Subject: r3654: Add static and fix indentation. Andrew Bartlett (This used to be commit cef31134ec4cd09eafd4f9f8f64e5fe3d68f19de) --- source4/libcli/raw/rawreadwrite.c | 2 +- source4/libcli/raw/rawrequest.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawreadwrite.c b/source4/libcli/raw/rawreadwrite.c index 4978514d26..8381c7b2b0 100644 --- a/source4/libcli/raw/rawreadwrite.c +++ b/source4/libcli/raw/rawreadwrite.c @@ -256,7 +256,7 @@ struct smbcli_request *smb_raw_write_send(struct smbcli_tree *tree, union smb_wr } if (!smbcli_request_send(req)) { -smbcli_request_destroy(req); + smbcli_request_destroy(req); return NULL; } diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 8d0767b3f5..b56bfa9a3c 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -225,7 +225,7 @@ static void smbcli_req_grow_allocation(struct smbcli_request *req, uint_t new_si To cope with this req->out.ptr is supplied. This will be updated to point at the same offset into the packet as before this call */ -void smbcli_req_grow_data(struct smbcli_request *req, uint_t new_size) +static void smbcli_req_grow_data(struct smbcli_request *req, uint_t new_size) { int delta; -- cgit From 696fdc8cf91cc1660725fd93c2b91ec6b65d06b5 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 17 Nov 2004 12:36:14 +0000 Subject: r3806: added support to smb_server and pvfs for the NTTRANS Create call. This call has an optional sec_desc and ea_list. (This used to be commit 8379ad14e3d51a848a99865d9ce8d56a301e8a3c) --- source4/libcli/raw/raweas.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/raweas.c b/source4/libcli/raw/raweas.c index da079c402b..52c7832a6c 100644 --- a/source4/libcli/raw/raweas.c +++ b/source4/libcli/raw/raweas.c @@ -122,7 +122,7 @@ NTSTATUS ea_pull_list(const DATA_BLOB *blob, *num_eas = 0; *eas = NULL; - while (ofs < ea_size) { + while (ofs+6 < ea_size) { uint_t len; DATA_BLOB blob2; -- cgit From 856ee665374071c89f5ecf540dcc3d68ccf2ff16 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 17 Nov 2004 14:35:29 +0000 Subject: r3810: create a LIB_SECURITY subsystem - move dom_sid, security_descriptor, security_* funtions to one place and rename some of them metze (This used to be commit b620bdd672cfdf0e009492e648b0709e6b6d8596) --- source4/libcli/raw/rawacl.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawacl.c b/source4/libcli/raw/rawacl.c index 35c7ce2049..642d0ba72b 100644 --- a/source4/libcli/raw/rawacl.c +++ b/source4/libcli/raw/rawacl.c @@ -19,6 +19,7 @@ */ #include "includes.h" +#include "librpc/gen_ndr/ndr_security.h" #include "libcli/raw/libcliraw.h" /**************************************************************************** -- cgit From 5efd740d4d4597208f835c6ed787c180056d7264 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 17 Nov 2004 20:56:26 +0000 Subject: r3821: added client side code and test code for NTTRANS_CREATE (This used to be commit 8422789c06c203ea1c4761fecb16f79f99ac479b) --- source4/libcli/raw/rawfile.c | 133 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c index 4da7ff3a9e..5fc40bc45a 100644 --- a/source4/libcli/raw/rawfile.c +++ b/source4/libcli/raw/rawfile.c @@ -22,6 +22,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" +#include "librpc/gen_ndr/ndr_security.h" #define SETUP_REQUEST(cmd, wct, buflen) do { \ req = smbcli_request_setup(tree, cmd, wct, buflen); \ @@ -213,6 +214,132 @@ NTSTATUS smb_raw_rmdir(struct smbcli_tree *tree, } +/* + Open a file using TRANSACT2_OPEN - async recv +*/ +static NTSTATUS smb_raw_nttrans_create_recv(struct smbcli_request *req, + TALLOC_CTX *mem_ctx, + union smb_open *parms) +{ + NTSTATUS status; + struct smb_nttrans nt; + uint8_t *params; + + status = smb_raw_nttrans_recv(req, mem_ctx, &nt); + if (!NT_STATUS_IS_OK(status)) return status; + + if (nt.out.params.length < 69) { + return NT_STATUS_INVALID_PARAMETER; + } + + params = nt.out.params.data; + + parms->ntcreatex.out.oplock_level = CVAL(params, 0); + parms->ntcreatex.out.fnum = SVAL(params, 2); + parms->ntcreatex.out.create_action = IVAL(params, 4); + parms->ntcreatex.out.create_time = smbcli_pull_nttime(params, 12); + parms->ntcreatex.out.access_time = smbcli_pull_nttime(params, 20); + parms->ntcreatex.out.write_time = smbcli_pull_nttime(params, 28); + parms->ntcreatex.out.change_time = smbcli_pull_nttime(params, 36); + parms->ntcreatex.out.attrib = IVAL(params, 44); + parms->ntcreatex.out.alloc_size = BVAL(params, 48); + parms->ntcreatex.out.size = BVAL(params, 56); + parms->ntcreatex.out.file_type = SVAL(params, 64); + parms->ntcreatex.out.ipc_state = SVAL(params, 66); + parms->ntcreatex.out.is_directory = CVAL(params, 68); + + return NT_STATUS_OK; +} + + +/* + Open a file using NTTRANS CREATE - async send +*/ +static struct smbcli_request *smb_raw_nttrans_create_send(struct smbcli_tree *tree, + union smb_open *parms) +{ + struct smb_nttrans nt; + uint8_t *params; + TALLOC_CTX *mem_ctx = talloc(tree, 0); + uint16_t fname_len; + DATA_BLOB sd_blob, ea_blob; + struct smbcli_request *req; + NTSTATUS status; + + nt.in.max_setup = 0; + nt.in.max_param = 101; + nt.in.max_data = 0; + nt.in.setup_count = 0; + nt.in.function = NT_TRANSACT_CREATE; + nt.in.setup = NULL; + + sd_blob = data_blob(NULL, 0); + ea_blob = data_blob(NULL, 0); + + if (parms->ntcreatex.in.sec_desc) { + status = ndr_push_struct_blob(&sd_blob, mem_ctx, + parms->ntcreatex.in.sec_desc, + (ndr_push_flags_fn_t)ndr_push_security_descriptor); + if (!NT_STATUS_IS_OK(status)) { + talloc_free(mem_ctx); + return NULL; + } + } + + if (parms->ntcreatex.in.ea_list) { + uint32_t ea_size = ea_list_size(parms->ntcreatex.in.ea_list->num_eas, + parms->ntcreatex.in.ea_list->eas); + ea_blob = data_blob_talloc(mem_ctx, NULL, ea_size); + if (ea_blob.data == NULL) { + return NULL; + } + ea_put_list(ea_blob.data, + parms->ntcreatex.in.ea_list->num_eas, + parms->ntcreatex.in.ea_list->eas); + } + + nt.in.params = data_blob_talloc(mem_ctx, NULL, 54); + if (nt.in.params.data == NULL) { + talloc_free(mem_ctx); + return NULL; + } + + /* build the parameter section */ + params = nt.in.params.data; + + SIVAL(params, 0, parms->ntcreatex.in.flags); + SIVAL(params, 4, parms->ntcreatex.in.root_fid); + SIVAL(params, 8, parms->ntcreatex.in.access_mask); + SBVAL(params, 12, parms->ntcreatex.in.alloc_size); + SIVAL(params, 20, parms->ntcreatex.in.file_attr); + SIVAL(params, 24, parms->ntcreatex.in.share_access); + SIVAL(params, 28, parms->ntcreatex.in.open_disposition); + SIVAL(params, 32, parms->ntcreatex.in.create_options); + SIVAL(params, 36, sd_blob.length); + SIVAL(params, 40, ea_blob.length); + SIVAL(params, 48, parms->ntcreatex.in.impersonation); + SCVAL(params, 52, parms->ntcreatex.in.security_flags); + SCVAL(params, 53, 0); + + fname_len = smbcli_blob_append_string(tree->session, mem_ctx, &nt.in.params, + parms->ntcreatex.in.fname, STR_TERMINATE); + + SIVAL(nt.in.params.data, 44, fname_len); + + /* build the data section */ + nt.in.data = data_blob_talloc(mem_ctx, NULL, sd_blob.length + ea_blob.length); + memcpy(nt.in.data.data, sd_blob.data, sd_blob.length); + memcpy(nt.in.data.data+sd_blob.length, ea_blob.data, ea_blob.length); + + /* send the request on its way */ + req = smb_raw_nttrans_send(tree, &nt); + + talloc_free(mem_ctx); + + return req; +} + + /**************************************************************************** Open a file using TRANSACT2_OPEN - async send ****************************************************************************/ @@ -377,6 +504,9 @@ struct smbcli_request *smb_raw_open_send(struct smbcli_tree *tree, union smb_ope smbcli_req_append_string_len(req, parms->ntcreatex.in.fname, STR_TERMINATE, &len); SSVAL(req->out.vwv, 5, len); break; + + case RAW_OPEN_NTTRANS_CREATE: + return smb_raw_nttrans_create_send(tree, parms); } if (!smbcli_request_send(req)) { @@ -469,6 +599,9 @@ NTSTATUS smb_raw_open_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, unio parms->ntcreatex.out.ipc_state = SVAL(req->in.vwv, 65); parms->ntcreatex.out.is_directory = CVAL(req->in.vwv, 67); break; + + case RAW_OPEN_NTTRANS_CREATE: + return smb_raw_nttrans_create_recv(req, mem_ctx, parms); } failed: -- cgit From 5f868bc1acc9bdaed32ae70fb9906334663ccfff Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 17 Nov 2004 22:00:15 +0000 Subject: r3826: - added testing of ea lists in NTTRANS CREATE - fixed push/pull of chained ea lists - fixed a bug in the nttrans wire encoding (This used to be commit fcd09224076508f9c10095bf2e2c394232a4d297) --- source4/libcli/raw/raweas.c | 107 ++++++++++++++++++++++++++++++++++++++++-- source4/libcli/raw/rawfile.c | 10 ++-- source4/libcli/raw/rawtrans.c | 2 +- 3 files changed, 108 insertions(+), 11 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/raweas.c b/source4/libcli/raw/raweas.c index 52c7832a6c..5bd90766aa 100644 --- a/source4/libcli/raw/raweas.c +++ b/source4/libcli/raw/raweas.c @@ -36,6 +36,23 @@ uint_t ea_list_size(uint_t num_eas, struct ea_struct *eas) return total; } +/* + work out how many bytes on the wire a chained ea list will consume. + This assumes the names are strict ascii, which should be a + reasonable assumption +*/ +uint_t ea_list_size_chained(uint_t num_eas, struct ea_struct *eas) +{ + uint_t total = 0; + int i; + for (i=0;i blob->length) { return NT_STATUS_INVALID_PARAMETER; } - - ofs = 4; + + ofs = 4; n = 0; *num_eas = 0; *eas = NULL; - while (ofs+6 < ea_size) { + while (ofs < ea_size) { uint_t len; DATA_BLOB blob2; @@ -146,3 +191,55 @@ NTSTATUS ea_pull_list(const DATA_BLOB *blob, return NT_STATUS_OK; } + +/* + pull a chained ea_list from a buffer +*/ +NTSTATUS ea_pull_list_chained(const DATA_BLOB *blob, + TALLOC_CTX *mem_ctx, + uint_t *num_eas, struct ea_struct **eas) +{ + int n; + uint32_t ofs; + + if (blob->length < 4) { + return NT_STATUS_INFO_LENGTH_MISMATCH; + } + + ofs = 0; + n = 0; + *num_eas = 0; + *eas = NULL; + + while (ofs < blob->length) { + uint_t len; + DATA_BLOB blob2; + uint32_t next_ofs = IVAL(blob->data, ofs); + + blob2.data = blob->data + ofs + 4; + blob2.length = blob->length - (ofs + 4); + + *eas = talloc_realloc(mem_ctx, *eas, sizeof(**eas) * (n+1)); + if (! *eas) return NT_STATUS_NO_MEMORY; + + len = ea_pull_struct(&blob2, mem_ctx, &(*eas)[n]); + if (len == 0) { + return NT_STATUS_INVALID_PARAMETER; + } + + ofs += next_ofs; + + if (ofs+4 > blob->length) { + return NT_STATUS_INVALID_PARAMETER; + } + n++; + if (next_ofs == 0) break; + } + + *num_eas = n; + + return NT_STATUS_OK; +} + + + diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c index 5fc40bc45a..69b8c6a07c 100644 --- a/source4/libcli/raw/rawfile.c +++ b/source4/libcli/raw/rawfile.c @@ -287,15 +287,15 @@ static struct smbcli_request *smb_raw_nttrans_create_send(struct smbcli_tree *tr } if (parms->ntcreatex.in.ea_list) { - uint32_t ea_size = ea_list_size(parms->ntcreatex.in.ea_list->num_eas, - parms->ntcreatex.in.ea_list->eas); + uint32_t ea_size = ea_list_size_chained(parms->ntcreatex.in.ea_list->num_eas, + parms->ntcreatex.in.ea_list->eas); ea_blob = data_blob_talloc(mem_ctx, NULL, ea_size); if (ea_blob.data == NULL) { return NULL; } - ea_put_list(ea_blob.data, - parms->ntcreatex.in.ea_list->num_eas, - parms->ntcreatex.in.ea_list->eas); + ea_put_list_chained(ea_blob.data, + parms->ntcreatex.in.ea_list->num_eas, + parms->ntcreatex.in.ea_list->eas); } nt.in.params = data_blob_talloc(mem_ctx, NULL, 54); diff --git a/source4/libcli/raw/rawtrans.c b/source4/libcli/raw/rawtrans.c index 111a7ded2a..2554a736f5 100644 --- a/source4/libcli/raw/rawtrans.c +++ b/source4/libcli/raw/rawtrans.c @@ -505,7 +505,7 @@ struct smbcli_request *smb_raw_nttrans_send(struct smbcli_tree *tree, memcpy(outparam, parms->in.params.data, parms->in.params.length); } if (parms->in.data.length) { - memcpy(outparam, parms->in.data.data, parms->in.data.length); + memcpy(outdata, parms->in.data.data, parms->in.data.length); } if (!smbcli_request_send(req)) { -- cgit From bbf009b46f75f292a625b853b9331b5d5e0da7c2 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 18 Nov 2004 01:02:27 +0000 Subject: r3829: added a RAW-ACLS test suite that tests query/set of ACLs on a file (This used to be commit 2ff9816ae0ae41e0e63e4276a70d292888346dc7) --- source4/libcli/raw/rawacl.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawacl.c b/source4/libcli/raw/rawacl.c index 642d0ba72b..2e05002491 100644 --- a/source4/libcli/raw/rawacl.c +++ b/source4/libcli/raw/rawacl.c @@ -1,7 +1,8 @@ /* Unix SMB/CIFS implementation. ACL get/set operations - Copyright (C) Andrew Tridgell 2003 + + Copyright (C) Andrew Tridgell 2003-2004 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 @@ -107,7 +108,7 @@ NTSTATUS smb_raw_query_secdesc(struct smbcli_tree *tree, set file ACL (async send) ****************************************************************************/ struct smbcli_request *smb_raw_set_secdesc_send(struct smbcli_tree *tree, - struct smb_set_secdesc *set) + struct smb_set_secdesc *set) { struct smb_nttrans nt; uint8_t params[8]; @@ -145,3 +146,13 @@ struct smbcli_request *smb_raw_set_secdesc_send(struct smbcli_tree *tree, ndr_push_free(ndr); return req; } + +/**************************************************************************** +set file ACL (sync interface) +****************************************************************************/ +NTSTATUS smb_raw_set_secdesc(struct smbcli_tree *tree, + struct smb_set_secdesc *set) +{ + struct smbcli_request *req = smb_raw_set_secdesc_send(tree, set); + return smbcli_request_simple_recv(req); +} -- cgit From 012be92f0a771d8437f783dc8ed14f38c669893c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 18 Nov 2004 01:41:43 +0000 Subject: r3830: unified the query/set security descriptor code with the rest of the queryfileinfo/setfileinfo logic, so querying/setting a security descriptor is treated as just another file query/set operation. This will allow NTVFS backends to see the query/set security descriptor operations as RAW_FILEINFO_SEC_DESC and RAW_SFILEINFO_SEC_DESC operations. (This used to be commit f68a6b6b915c37e48c42390c1e74c2d1c2636fa9) --- source4/libcli/raw/rawacl.c | 33 +++++++++++++++++---------------- source4/libcli/raw/rawfileinfo.c | 9 ++++++++- source4/libcli/raw/rawsetfileinfo.c | 4 ++++ 3 files changed, 29 insertions(+), 17 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawacl.c b/source4/libcli/raw/rawacl.c index 2e05002491..253a3cbbe7 100644 --- a/source4/libcli/raw/rawacl.c +++ b/source4/libcli/raw/rawacl.c @@ -27,7 +27,7 @@ fetch file ACL (async send) ****************************************************************************/ struct smbcli_request *smb_raw_query_secdesc_send(struct smbcli_tree *tree, - struct smb_query_secdesc *query) + union smb_fileinfo *io) { struct smb_nttrans nt; uint8_t params[8]; @@ -39,9 +39,9 @@ struct smbcli_request *smb_raw_query_secdesc_send(struct smbcli_tree *tree, nt.in.function = NT_TRANSACT_QUERY_SECURITY_DESC; nt.in.setup = NULL; - SSVAL(params, 0, query->in.fnum); + SSVAL(params, 0, io->query_secdesc.in.fnum); SSVAL(params, 2, 0); /* padding */ - SIVAL(params, 4, query->in.secinfo_flags); + SIVAL(params, 4, io->query_secdesc.in.secinfo_flags); nt.in.params.data = params; nt.in.params.length = 8; @@ -57,7 +57,7 @@ fetch file ACL (async recv) ****************************************************************************/ NTSTATUS smb_raw_query_secdesc_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, - struct smb_query_secdesc *query) + union smb_fileinfo *io) { NTSTATUS status; struct smb_nttrans nt; @@ -81,11 +81,12 @@ NTSTATUS smb_raw_query_secdesc_recv(struct smbcli_request *req, return NT_STATUS_INVALID_PARAMETER; } - query->out.sd = talloc_p(mem_ctx, struct security_descriptor); - if (!query->out.sd) { + io->query_secdesc.out.sd = talloc_p(mem_ctx, struct security_descriptor); + if (!io->query_secdesc.out.sd) { return NT_STATUS_NO_MEMORY; } - status = ndr_pull_security_descriptor(ndr, NDR_SCALARS|NDR_BUFFERS, query->out.sd); + status = ndr_pull_security_descriptor(ndr, NDR_SCALARS|NDR_BUFFERS, + io->query_secdesc.out.sd); return status; } @@ -96,10 +97,10 @@ fetch file ACL (sync interface) ****************************************************************************/ NTSTATUS smb_raw_query_secdesc(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, - struct smb_query_secdesc *query) + union smb_fileinfo *io) { - struct smbcli_request *req = smb_raw_query_secdesc_send(tree, query); - return smb_raw_query_secdesc_recv(req, mem_ctx, query); + struct smbcli_request *req = smb_raw_query_secdesc_send(tree, io); + return smb_raw_query_secdesc_recv(req, mem_ctx, io); } @@ -108,7 +109,7 @@ NTSTATUS smb_raw_query_secdesc(struct smbcli_tree *tree, set file ACL (async send) ****************************************************************************/ struct smbcli_request *smb_raw_set_secdesc_send(struct smbcli_tree *tree, - struct smb_set_secdesc *set) + union smb_setfileinfo *io) { struct smb_nttrans nt; uint8_t params[8]; @@ -123,9 +124,9 @@ struct smbcli_request *smb_raw_set_secdesc_send(struct smbcli_tree *tree, nt.in.function = NT_TRANSACT_SET_SECURITY_DESC; nt.in.setup = NULL; - SSVAL(params, 0, set->in.fnum); + SSVAL(params, 0, io->set_secdesc.file.fnum); SSVAL(params, 2, 0); /* padding */ - SIVAL(params, 4, set->in.secinfo_flags); + SIVAL(params, 4, io->set_secdesc.in.secinfo_flags); nt.in.params.data = params; nt.in.params.length = 8; @@ -133,7 +134,7 @@ struct smbcli_request *smb_raw_set_secdesc_send(struct smbcli_tree *tree, ndr = ndr_push_init(); if (!ndr) return NULL; - status = ndr_push_security_descriptor(ndr, NDR_SCALARS|NDR_BUFFERS, set->in.sd); + status = ndr_push_security_descriptor(ndr, NDR_SCALARS|NDR_BUFFERS, io->set_secdesc.in.sd); if (!NT_STATUS_IS_OK(status)) { ndr_push_free(ndr); return NULL; @@ -151,8 +152,8 @@ struct smbcli_request *smb_raw_set_secdesc_send(struct smbcli_tree *tree, set file ACL (sync interface) ****************************************************************************/ NTSTATUS smb_raw_set_secdesc(struct smbcli_tree *tree, - struct smb_set_secdesc *set) + union smb_setfileinfo *io) { - struct smbcli_request *req = smb_raw_set_secdesc_send(tree, set); + struct smbcli_request *req = smb_raw_set_secdesc_send(tree, io); return smbcli_request_simple_recv(req); } diff --git a/source4/libcli/raw/rawfileinfo.c b/source4/libcli/raw/rawfileinfo.c index c844f923b8..6f875f51a7 100644 --- a/source4/libcli/raw/rawfileinfo.c +++ b/source4/libcli/raw/rawfileinfo.c @@ -48,6 +48,7 @@ static NTSTATUS smb_raw_info_backend(struct smbcli_session *session, case RAW_FILEINFO_GENERIC: case RAW_FILEINFO_GETATTR: case RAW_FILEINFO_GETATTRE: + case RAW_FILEINFO_SEC_DESC: /* not handled here */ return NT_STATUS_INVALID_LEVEL; @@ -460,12 +461,15 @@ failed: Query file info (async send) ****************************************************************************/ struct smbcli_request *smb_raw_fileinfo_send(struct smbcli_tree *tree, - union smb_fileinfo *parms) + union smb_fileinfo *parms) { /* pass off the non-trans2 level to specialised functions */ if (parms->generic.level == RAW_FILEINFO_GETATTRE) { return smb_raw_getattrE_send(tree, parms); } + if (parms->generic.level == RAW_FILEINFO_SEC_DESC) { + return smb_raw_query_secdesc_send(tree, parms); + } if (parms->generic.level >= RAW_FILEINFO_GENERIC) { return NULL; } @@ -489,6 +493,9 @@ NTSTATUS smb_raw_fileinfo_recv(struct smbcli_request *req, if (parms->generic.level == RAW_FILEINFO_GETATTRE) { return smb_raw_getattrE_recv(req, parms); } + if (parms->generic.level == RAW_FILEINFO_SEC_DESC) { + return smb_raw_query_secdesc_recv(req, mem_ctx, parms); + } if (parms->generic.level == RAW_FILEINFO_GETATTR) { return smb_raw_getattr_recv(req, parms); } diff --git a/source4/libcli/raw/rawsetfileinfo.c b/source4/libcli/raw/rawsetfileinfo.c index 0c263ac082..76756971ae 100644 --- a/source4/libcli/raw/rawsetfileinfo.c +++ b/source4/libcli/raw/rawsetfileinfo.c @@ -41,6 +41,7 @@ static BOOL smb_raw_setinfo_backend(struct smbcli_tree *tree, case RAW_SFILEINFO_GENERIC: case RAW_SFILEINFO_SETATTR: case RAW_SFILEINFO_SETATTRE: + case RAW_SFILEINFO_SEC_DESC: /* not handled here */ return False; @@ -262,6 +263,9 @@ struct smbcli_request *smb_raw_setfileinfo_send(struct smbcli_tree *tree, if (parms->generic.level == RAW_SFILEINFO_SETATTRE) { return smb_raw_setattrE_send(tree, parms); } + if (parms->generic.level == RAW_SFILEINFO_SEC_DESC) { + return smb_raw_set_secdesc_send(tree, parms); + } if (parms->generic.level >= RAW_SFILEINFO_GENERIC) { return NULL; } -- cgit From 7aeebaa96246660ab30c985859ea6b4323ea371f Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 22 Nov 2004 08:15:27 +0000 Subject: r3902: fix compiler warnings metze (This used to be commit ce7686ac3e15b0d52ef01bd8bd773641c8ce2e35) --- source4/libcli/raw/raweas.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/raweas.c b/source4/libcli/raw/raweas.c index 5bd90766aa..e5f81f5eea 100644 --- a/source4/libcli/raw/raweas.c +++ b/source4/libcli/raw/raweas.c @@ -57,7 +57,7 @@ uint_t ea_list_size_chained(uint_t num_eas, struct ea_struct *eas) put a ea_list into a pre-allocated buffer - buffer must be at least of size ea_list_size() */ -void ea_put_list(char *data, uint_t num_eas, struct ea_struct *eas) +void ea_put_list(void *data, uint_t num_eas, struct ea_struct *eas) { int i; uint32_t ea_size; @@ -83,7 +83,7 @@ void ea_put_list(char *data, uint_t num_eas, struct ea_struct *eas) put a chained ea_list into a pre-allocated buffer - buffer must be at least of size ea_list_size() */ -void ea_put_list_chained(char *data, uint_t num_eas, struct ea_struct *eas) +void ea_put_list_chained(void *data, uint_t num_eas, struct ea_struct *eas) { int i; -- cgit From aae697b9246a6688155895e6c666fda2f10d67f5 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 22 Nov 2004 08:31:36 +0000 Subject: r3903: better fix for -r 3902 (not introduce new warnings:-) metze (This used to be commit 36b11992dc3b08914db24ec23f10cc8b3eb55320) --- source4/libcli/raw/raweas.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/raweas.c b/source4/libcli/raw/raweas.c index e5f81f5eea..17e5ce8f75 100644 --- a/source4/libcli/raw/raweas.c +++ b/source4/libcli/raw/raweas.c @@ -57,7 +57,7 @@ uint_t ea_list_size_chained(uint_t num_eas, struct ea_struct *eas) put a ea_list into a pre-allocated buffer - buffer must be at least of size ea_list_size() */ -void ea_put_list(void *data, uint_t num_eas, struct ea_struct *eas) +void ea_put_list(uint8_t *data, uint_t num_eas, struct ea_struct *eas) { int i; uint32_t ea_size; @@ -83,7 +83,7 @@ void ea_put_list(void *data, uint_t num_eas, struct ea_struct *eas) put a chained ea_list into a pre-allocated buffer - buffer must be at least of size ea_list_size() */ -void ea_put_list_chained(void *data, uint_t num_eas, struct ea_struct *eas) +void ea_put_list_chained(uint8_t *data, uint_t num_eas, struct ea_struct *eas) { int i; -- cgit From 3308087bae76a99c02687bd11f4237d803f9f605 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 25 Nov 2004 20:01:47 +0000 Subject: r3971: fix compiler warnings metze (This used to be commit 234166606dc86b9e98226cff94b3869ec173671e) --- source4/libcli/raw/raweas.c | 2 +- source4/libcli/raw/rawtrans.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/raweas.c b/source4/libcli/raw/raweas.c index 17e5ce8f75..621181841f 100644 --- a/source4/libcli/raw/raweas.c +++ b/source4/libcli/raw/raweas.c @@ -129,7 +129,7 @@ uint_t ea_pull_struct(const DATA_BLOB *blob, return 0; } - ea->name.s = talloc_strndup(mem_ctx, blob->data+4, nlen); + ea->name.s = talloc_strndup(mem_ctx, (const char *)(blob->data+4), nlen); ea->name.private_length = nlen; ea->value = data_blob_talloc(mem_ctx, NULL, vlen+1); if (!ea->value.data) return 0; diff --git a/source4/libcli/raw/rawtrans.c b/source4/libcli/raw/rawtrans.c index 2554a736f5..371f50410d 100644 --- a/source4/libcli/raw/rawtrans.c +++ b/source4/libcli/raw/rawtrans.c @@ -56,8 +56,8 @@ NTSTATUS smb_raw_trans2_recv(struct smbcli_request *req, { int total_data=0; int total_param=0; - char *tdata; - char *tparam; + uint8_t *tdata; + uint8_t *tparam; parms->out.data.length = 0; parms->out.data.data = NULL; -- cgit From 75f58e2d0fc3d2b07659caf34a07a0fb20cc1756 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 30 Nov 2004 05:45:37 +0000 Subject: r4015: correct copyright attributions (This used to be commit 078d9ab05bffc79e4f329ea18fe3dafd144d989c) --- source4/libcli/raw/libcliraw.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/libcliraw.h b/source4/libcli/raw/libcliraw.h index b00af846b7..51b50fdcb9 100644 --- a/source4/libcli/raw/libcliraw.h +++ b/source4/libcli/raw/libcliraw.h @@ -1,9 +1,8 @@ /* Unix SMB/CIFS implementation. SMB parameters and setup - Copyright (C) Andrew Tridgell 1992-1998 - Copyright (C) Luke Kenneth Casson Leighton 1996-1998 - Copyright (C) Jeremy Allison 1998 + + Copyright (C) Andrew Tridgell 2002-2004 Copyright (C) James Myers 2003 This program is free software; you can redistribute it and/or modify -- cgit From 4183b2ac3832cdc2055d7eb3ed7121a9ea91085c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 2 Dec 2004 04:51:56 +0000 Subject: r4037: fixed a bunch of "might be uninitialised" warnings after enabling -O1 in my compile (This used to be commit 0928b1f5b68c858922c3ea6c27ed03b5091c6221) --- source4/libcli/raw/clisession.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index b7802d8065..c92e3ecb0b 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -393,7 +393,7 @@ static NTSTATUS smb_raw_session_setup_generic_spnego(struct smbcli_session *sess union smb_sesssetup s2; DATA_BLOB session_key = data_blob(NULL, 0); DATA_BLOB null_data_blob = data_blob(NULL, 0); - const char *chosen_oid; + const char *chosen_oid = NULL; s2.generic.level = RAW_SESSSETUP_SPNEGO; s2.spnego.in.bufsize = session->transport->options.max_xmit; -- cgit From 6e6374cb5bcffb4df8bdb0a83327fff92b61ac84 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 3 Dec 2004 07:20:30 +0000 Subject: r4055: fixed more places to use type safe allocation macros (This used to be commit eec698254f67365f27b4b7569fa982e22472aca1) --- source4/libcli/raw/raweas.c | 4 ++-- source4/libcli/raw/rawnotify.c | 3 +-- 2 files changed, 3 insertions(+), 4 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/raweas.c b/source4/libcli/raw/raweas.c index 621181841f..027705b381 100644 --- a/source4/libcli/raw/raweas.c +++ b/source4/libcli/raw/raweas.c @@ -174,7 +174,7 @@ NTSTATUS ea_pull_list(const DATA_BLOB *blob, blob2.data = blob->data + ofs; blob2.length = ea_size - ofs; - *eas = talloc_realloc(mem_ctx, *eas, sizeof(**eas) * (n+1)); + *eas = talloc_realloc_p(mem_ctx, *eas, struct ea_struct, n+1); if (! *eas) return NT_STATUS_NO_MEMORY; len = ea_pull_struct(&blob2, mem_ctx, &(*eas)[n]); @@ -219,7 +219,7 @@ NTSTATUS ea_pull_list_chained(const DATA_BLOB *blob, blob2.data = blob->data + ofs + 4; blob2.length = blob->length - (ofs + 4); - *eas = talloc_realloc(mem_ctx, *eas, sizeof(**eas) * (n+1)); + *eas = talloc_realloc_p(mem_ctx, *eas, struct ea_struct, n+1); if (! *eas) return NT_STATUS_NO_MEMORY; len = ea_pull_struct(&blob2, mem_ctx, &(*eas)[n]); diff --git a/source4/libcli/raw/rawnotify.c b/source4/libcli/raw/rawnotify.c index ea5fada1ee..918fb788cb 100644 --- a/source4/libcli/raw/rawnotify.c +++ b/source4/libcli/raw/rawnotify.c @@ -73,8 +73,7 @@ NTSTATUS smb_raw_changenotify_recv(struct smbcli_request *req, } /* allocate array */ - parms->out.changes = talloc(mem_ctx, sizeof(parms->out.changes[0]) * - parms->out.num_changes); + parms->out.changes = talloc_array_p(mem_ctx, struct notify_changes, parms->out.num_changes); if (!parms->out.changes) { return NT_STATUS_NO_MEMORY; } -- cgit From 9112a632f6791ffc3c3c1aadd214cbaba8fe816e Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sat, 4 Dec 2004 13:56:25 +0000 Subject: r4063: - change char * -> uint8_t in struct request_buffer - change smbcli_read/write to take void * for the buffers to match read(2)/write(2) all this fixes a lot of gcc-4 warnings metze (This used to be commit b94f92bc6637f748d6f7049f4f9a30b0b8d18a7a) --- source4/libcli/raw/clisession.c | 2 +- source4/libcli/raw/clisocket.c | 4 ++-- source4/libcli/raw/clitransport.c | 10 +++++----- source4/libcli/raw/clitree.c | 2 +- source4/libcli/raw/rawdate.c | 4 ++-- source4/libcli/raw/rawfile.c | 2 +- source4/libcli/raw/rawnegotiate.c | 2 +- source4/libcli/raw/rawrequest.c | 28 ++++++++++++++-------------- source4/libcli/raw/rawsearch.c | 2 +- source4/libcli/raw/rawtrans.c | 6 +++--- source4/libcli/raw/smb_signing.c | 2 +- 11 files changed, 32 insertions(+), 32 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index c92e3ecb0b..7d2b7ad9b8 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -156,7 +156,7 @@ NTSTATUS smb_raw_session_setup_recv(struct smbcli_request *req, union smb_sesssetup *parms) { uint16_t len; - char *p; + uint8_t *p; if (!smbcli_request_receive(req)) { return smbcli_request_destroy(req); diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 349b4b9a9c..fb9afeab81 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -109,7 +109,7 @@ void smbcli_sock_set_options(struct smbcli_socket *sock, const char *options) /**************************************************************************** Write to socket. Return amount written. ****************************************************************************/ -ssize_t smbcli_sock_write(struct smbcli_socket *sock, const char *data, size_t len) +ssize_t smbcli_sock_write(struct smbcli_socket *sock, const uint8_t *data, size_t len) { NTSTATUS status; DATA_BLOB blob; @@ -135,7 +135,7 @@ ssize_t smbcli_sock_write(struct smbcli_socket *sock, const char *data, size_t l /**************************************************************************** Read from socket. return amount read ****************************************************************************/ -ssize_t smbcli_sock_read(struct smbcli_socket *sock, char *data, size_t len) +ssize_t smbcli_sock_read(struct smbcli_socket *sock, uint8_t *data, size_t len) { NTSTATUS status; size_t nread; diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 52cb4d8beb..0af6df33b2 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -156,7 +156,7 @@ BOOL smbcli_transport_connect(struct smbcli_transport *transport, struct nmb_name *calling, struct nmb_name *called) { - char *p; + uint8_t *p; int len = NBT_HDR_SIZE; struct smbcli_request *req; @@ -174,13 +174,13 @@ BOOL smbcli_transport_connect(struct smbcli_transport *transport, /* put in the destination name */ p = req->out.buffer + NBT_HDR_SIZE; - name_mangle(called->name, p, called->name_type); - len += name_len(p); + name_mangle(called->name, (char *)p, called->name_type); + len += name_len((char *)p); /* and my name */ p = req->out.buffer+len; - name_mangle(calling->name, p, calling->name_type); - len += name_len(p); + name_mangle(calling->name, (char *)p, calling->name_type); + len += name_len((char *)p); _smb_setlen(req->out.buffer,len-4); SCVAL(req->out.buffer,0,0x81); diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index daa8549099..b9d0ffbc1f 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -85,7 +85,7 @@ struct smbcli_request *smb_tree_connect_send(struct smbcli_tree *tree, union smb ****************************************************************************/ NTSTATUS smb_tree_connect_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, union smb_tcon *parms) { - char *p; + uint8_t *p; if (!smbcli_request_receive(req) || smbcli_request_is_error(req)) { diff --git a/source4/libcli/raw/rawdate.c b/source4/libcli/raw/rawdate.c index db18a7a194..894eb53528 100644 --- a/source4/libcli/raw/rawdate.c +++ b/source4/libcli/raw/rawdate.c @@ -38,7 +38,7 @@ put a dos date into a buffer (date/time format) This takes GMT time and puts local time in the buffer ********************************************************************/ void raw_push_dos_date2(struct smbcli_transport *transport, - char *buf, int offset, time_t unixdate) + uint8_t *buf, int offset, time_t unixdate) { push_dos_date2(buf, offset, unixdate, transport->negotiate.server_zone); } @@ -48,7 +48,7 @@ put a dos 32 bit "unix like" date into a buffer. This routine takes GMT and converts it to LOCAL time in zone_offset before putting it ********************************************************************/ void raw_push_dos_date3(struct smbcli_transport *transport, - char *buf, int offset, time_t unixdate) + uint8_t *buf, int offset, time_t unixdate) { push_dos_date3(buf, offset, unixdate, transport->negotiate.server_zone); } diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c index 69b8c6a07c..028d8734e1 100644 --- a/source4/libcli/raw/rawfile.c +++ b/source4/libcli/raw/rawfile.c @@ -702,7 +702,7 @@ struct smbcli_request *smb_raw_lock_send(struct smbcli_tree *tree, union smb_loc /* copy in all the locks */ lockp = &parms->lockx.in.locks[0]; for (i = 0; i < lock_count; i++) { - char *p = req->out.data + lck_size * i; + uint8_t *p = req->out.data + lck_size * i; SSVAL(p, 0, lockp[i].pid); if (parms->lockx.in.mode & LOCKING_ANDX_LARGE_FILES) { SSVAL(p, 2, 0); /* reserved */ diff --git a/source4/libcli/raw/rawnegotiate.c b/source4/libcli/raw/rawnegotiate.c index 4f7d7b4058..a8cf603d46 100644 --- a/source4/libcli/raw/rawnegotiate.c +++ b/source4/libcli/raw/rawnegotiate.c @@ -70,7 +70,7 @@ struct smbcli_request *smb_negprot_send(struct smbcli_transport *transport, int /* setup the protocol strings */ for (i=0; i < ARRAY_SIZE(prots) && prots[i].prot <= maxprotocol; i++) { - smbcli_req_append_bytes(req, "\2", 1); + smbcli_req_append_bytes(req, (const uint8_t *)"\2", 1); smbcli_req_append_string(req, prots[i].name, STR_TERMINATE | STR_ASCII); } diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index b56bfa9a3c..7aa07bef41 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -187,7 +187,7 @@ struct smbcli_request *smbcli_request_setup(struct smbcli_tree *tree, static void smbcli_req_grow_allocation(struct smbcli_request *req, uint_t new_size) { int delta; - char *buf2; + uint8_t *buf2; delta = new_size - req->out.data_size; if (delta + req->out.size <= req->out.allocated) { @@ -295,7 +295,7 @@ BOOL smbcli_request_receive_more(struct smbcli_request *req) handle oplock break requests from the server - return True if the request was an oplock break */ -BOOL handle_oplock_break(struct smbcli_transport *transport, uint_t len, const char *hdr, const char *vwv) +BOOL handle_oplock_break(struct smbcli_transport *transport, uint_t len, const uint8_t *hdr, const uint8_t *vwv) { /* we must be very fussy about what we consider an oplock break to avoid matching readbraw replies */ @@ -479,7 +479,7 @@ size_t smbcli_req_append_var_block(struct smbcli_request *req, const uint8_t *by of bytes consumed in the packet is returned */ static size_t smbcli_req_pull_ucs2(struct smbcli_request *req, TALLOC_CTX *mem_ctx, - char **dest, const char *src, int byte_len, uint_t flags) + char **dest, const uint8_t *src, int byte_len, uint_t flags) { int src_len, src_len2, alignment=0; ssize_t ret; @@ -532,7 +532,7 @@ static size_t smbcli_req_pull_ucs2(struct smbcli_request *req, TALLOC_CTX *mem_c of bytes consumed in the packet is returned */ size_t smbcli_req_pull_ascii(struct smbcli_request *req, TALLOC_CTX *mem_ctx, - char **dest, const char *src, int byte_len, uint_t flags) + char **dest, const uint8_t *src, int byte_len, uint_t flags) { int src_len, src_len2; ssize_t ret; @@ -545,7 +545,7 @@ size_t smbcli_req_pull_ascii(struct smbcli_request *req, TALLOC_CTX *mem_ctx, if (byte_len != -1 && src_len > byte_len) { src_len = byte_len; } - src_len2 = strnlen(src, src_len); + src_len2 = strnlen((const char *)src, src_len); if (src_len2 < src_len - 1) { /* include the termination if we didn't reach the end of the packet */ src_len2++; @@ -575,7 +575,7 @@ size_t smbcli_req_pull_ascii(struct smbcli_request *req, TALLOC_CTX *mem_ctx, of bytes consumed in the packet is returned */ size_t smbcli_req_pull_string(struct smbcli_request *req, TALLOC_CTX *mem_ctx, - char **dest, const char *src, int byte_len, uint_t flags) + char **dest, const uint8_t *src, int byte_len, uint_t flags) { if (!(flags & STR_ASCII) && (((flags & STR_UNICODE) || (req->flags2 & FLAGS2_UNICODE_STRINGS)))) { @@ -592,7 +592,7 @@ size_t smbcli_req_pull_string(struct smbcli_request *req, TALLOC_CTX *mem_ctx, if byte_len is -1 then limit the blob only by packet size */ -DATA_BLOB smbcli_req_pull_blob(struct smbcli_request *req, TALLOC_CTX *mem_ctx, const char *src, int byte_len) +DATA_BLOB smbcli_req_pull_blob(struct smbcli_request *req, TALLOC_CTX *mem_ctx, const uint8_t *src, int byte_len) { int src_len; @@ -611,7 +611,7 @@ DATA_BLOB smbcli_req_pull_blob(struct smbcli_request *req, TALLOC_CTX *mem_ctx, /* check that a lump of data in a request is within the bounds of the data section of the packet */ -static BOOL smbcli_req_data_oob(struct smbcli_request *req, const char *ptr, uint32_t count) +static BOOL smbcli_req_data_oob(struct smbcli_request *req, const uint8_t *ptr, uint32_t count) { /* be careful with wraparound! */ if (ptr < req->in.data || @@ -628,7 +628,7 @@ static BOOL smbcli_req_data_oob(struct smbcli_request *req, const char *ptr, uin return False if any part is outside the data portion of the packet */ -BOOL smbcli_raw_pull_data(struct smbcli_request *req, const char *src, int len, char *dest) +BOOL smbcli_raw_pull_data(struct smbcli_request *req, const uint8_t *src, int len, uint8_t *dest) { if (len == 0) return True; @@ -673,14 +673,14 @@ NTTIME smbcli_pull_nttime(void *base, uint16_t offset) */ static size_t smbcli_blob_pull_ucs2(TALLOC_CTX* mem_ctx, DATA_BLOB *blob, const char **dest, - const char *src, int byte_len, uint_t flags) + const uint8_t *src, int byte_len, uint_t flags) { int src_len, src_len2, alignment=0; ssize_t ret; char *dest2; - if (src < (const char *)blob->data || - src >= (const char *)(blob->data + blob->length)) { + if (src < blob->data || + src >= (blob->data + blob->length)) { *dest = NULL; return 0; } @@ -729,7 +729,7 @@ static size_t smbcli_blob_pull_ucs2(TALLOC_CTX* mem_ctx, */ static size_t smbcli_blob_pull_ascii(TALLOC_CTX *mem_ctx, DATA_BLOB *blob, const char **dest, - const char *src, int byte_len, uint_t flags) + const uint8_t *src, int byte_len, uint_t flags) { int src_len, src_len2; ssize_t ret; @@ -743,7 +743,7 @@ static size_t smbcli_blob_pull_ascii(TALLOC_CTX *mem_ctx, if (byte_len != -1 && src_len > byte_len) { src_len = byte_len; } - src_len2 = strnlen(src, src_len); + src_len2 = strnlen((const char *)src, src_len); if (src_len2 < src_len - 1) { /* include the termination if we didn't reach the end of the packet */ diff --git a/source4/libcli/raw/rawsearch.c b/source4/libcli/raw/rawsearch.c index 4907eec70a..d55a47ca26 100644 --- a/source4/libcli/raw/rawsearch.c +++ b/source4/libcli/raw/rawsearch.c @@ -33,7 +33,7 @@ static void smb_raw_search_backend(struct smbcli_request *req, { union smb_search_data search_data; int i; - char *p; + uint8_t *p; if (req->in.data_size < 3 + count*43) { req->status = NT_STATUS_INVALID_PARAMETER; diff --git a/source4/libcli/raw/rawtrans.c b/source4/libcli/raw/rawtrans.c index 371f50410d..fb8ab4203f 100644 --- a/source4/libcli/raw/rawtrans.c +++ b/source4/libcli/raw/rawtrans.c @@ -29,7 +29,7 @@ static BOOL raw_trans_oob(struct smbcli_request *req, uint_t offset, uint_t count) { - char *ptr; + uint8_t *ptr; if (count == 0) { return False; @@ -208,7 +208,7 @@ struct smbcli_request *smb_raw_trans_send_backend(struct smbcli_tree *tree, { int wct = 14 + parms->in.setup_count; struct smbcli_request *req; - char *outdata,*outparam; + uint8_t *outdata,*outparam; int i; int padding; size_t namelen = 0; @@ -460,7 +460,7 @@ struct smbcli_request *smb_raw_nttrans_send(struct smbcli_tree *tree, struct smb_nttrans *parms) { struct smbcli_request *req; - char *outdata, *outparam; + uint8_t *outdata, *outparam; int i; int align = 0; diff --git a/source4/libcli/raw/smb_signing.c b/source4/libcli/raw/smb_signing.c index c0c1337312..4204f3b4dc 100644 --- a/source4/libcli/raw/smb_signing.c +++ b/source4/libcli/raw/smb_signing.c @@ -104,7 +104,7 @@ void sign_outgoing_message(struct request_buffer *out, DATA_BLOB *mac_key, uint_ { uint8_t calc_md5_mac[16]; struct MD5Context md5_ctx; - unsigned char key_buf[16]; + uint8_t key_buf[16]; /* * Firstly put the sequence number into the first 4 bytes. -- cgit From f99c93ec57691a393b4ae5ba57176b98f33efc17 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sun, 5 Dec 2004 16:29:27 +0000 Subject: r4070: move some defines from asn_1.h to the places they belong to metze (This used to be commit ab2c2f27e1c61516e885f02bf26350f97209057a) --- source4/libcli/raw/clisession.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index 7d2b7ad9b8..39df8fce02 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -22,7 +22,6 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" #include "auth/auth.h" -#include "asn_1.h" #define SETUP_REQUEST_SESSION(cmd, wct, buflen) do { \ req = smbcli_request_setup_session(session, cmd, wct, buflen); \ @@ -445,10 +444,10 @@ static NTSTATUS smb_raw_session_setup_generic_spnego(struct smbcli_session *sess } if (session->transport->negotiate.secblob.length) { - chosen_oid = OID_SPNEGO; + chosen_oid = GENSEC_OID_SPNEGO; } else { /* without a sec blob, means raw NTLMSSP */ - chosen_oid = OID_NTLMSSP; + chosen_oid = GENSEC_OID_NTLMSSP; } status = gensec_start_mech_by_oid(session->gensec, chosen_oid); -- cgit From 82da9a75d8b3976c79384e89ab248c235fc885e0 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 6 Dec 2004 15:45:48 +0000 Subject: r4080: missing file from the last commit metze (This used to be commit ea7b496995573426486b7eab5de822d5602d7368) --- source4/libcli/raw/clisession.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index 39df8fce02..4f77145d4d 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -413,7 +413,7 @@ static NTSTATUS smb_raw_session_setup_generic_spnego(struct smbcli_session *sess goto done; } - gensec_want_feature(session->gensec, GENSEC_WANT_SESSION_KEY); + gensec_want_feature(session->gensec, GENSEC_FEATURE_SESSION_KEY); status = gensec_set_domain(session->gensec, parms->generic.in.domain); if (!NT_STATUS_IS_OK(status)) { -- cgit From fbd8c61ff7a7c41d16c400ddb87ad290f4af167d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 13 Dec 2004 10:48:21 +0000 Subject: r4173: - new t2open code, that can cope with "create with EAs". Many thanks to kukks on #samba-technical for the sniffs that allowed me to work this out - much simpler ntvfs open generic mapping code - added t2open create with EA torture test to RAW-OPEN test (This used to be commit a56d95ad89b4f32a05974c4fe9a816d67aa369e3) --- source4/libcli/raw/clisession.c | 2 +- source4/libcli/raw/rawfile.c | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index 4f77145d4d..519f112ceb 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -51,7 +51,7 @@ struct smbcli_session *smbcli_session_init(struct smbcli_transport *transport) capabilities = transport->negotiate.capabilities; - flags2 = FLAGS2_LONG_PATH_COMPONENTS; + flags2 = FLAGS2_LONG_PATH_COMPONENTS | FLAGS2_EXTENDED_ATTRIBUTES; if (capabilities & CAP_UNICODE) { flags2 |= FLAGS2_UNICODE_STRINGS; diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c index 028d8734e1..bfd96bd360 100644 --- a/source4/libcli/raw/rawfile.c +++ b/source4/libcli/raw/rawfile.c @@ -366,10 +366,10 @@ static struct smbcli_request *smb_raw_t2open_send(struct smbcli_tree *tree, SSVAL(t2.in.params.data, VWV(0), parms->t2open.in.flags); SSVAL(t2.in.params.data, VWV(1), parms->t2open.in.open_mode); - SSVAL(t2.in.params.data, VWV(2), 0); /* reserved */ + SSVAL(t2.in.params.data, VWV(2), parms->t2open.in.search_attrs); SSVAL(t2.in.params.data, VWV(3), parms->t2open.in.file_attrs); raw_push_dos_date(tree->session->transport, - t2.in.params.data, VWV(4), parms->t2open.in.write_time); + t2.in.params.data, VWV(4), parms->t2open.in.write_time); SSVAL(t2.in.params.data, VWV(6), parms->t2open.in.open_func); SIVAL(t2.in.params.data, VWV(7), parms->t2open.in.size); SIVAL(t2.in.params.data, VWV(9), parms->t2open.in.timeout); @@ -377,8 +377,8 @@ static struct smbcli_request *smb_raw_t2open_send(struct smbcli_tree *tree, SSVAL(t2.in.params.data, VWV(13), 0); smbcli_blob_append_string(tree->session, mem_ctx, - &t2.in.params, parms->t2open.in.fname, - STR_TERMINATE); + &t2.in.params, parms->t2open.in.fname, + STR_TERMINATE); ea_put_list(t2.in.data.data, parms->t2open.in.num_eas, parms->t2open.in.eas); @@ -414,7 +414,7 @@ static NTSTATUS smb_raw_t2open_recv(struct smbcli_request *req, TALLOC_CTX *mem_ parms->t2open.out.ftype = SVAL(t2.out.params.data, VWV(7)); parms->t2open.out.devstate = SVAL(t2.out.params.data, VWV(8)); parms->t2open.out.action = SVAL(t2.out.params.data, VWV(9)); - parms->t2open.out.unknown = SVAL(t2.out.params.data, VWV(10)); + parms->t2open.out.file_id = SVAL(t2.out.params.data, VWV(10)); return NT_STATUS_OK; } @@ -433,7 +433,7 @@ struct smbcli_request *smb_raw_open_send(struct smbcli_tree *tree, union smb_ope case RAW_OPEN_OPEN: SETUP_REQUEST(SMBopen, 2, 0); - SSVAL(req->out.vwv, VWV(0), parms->openold.in.flags); + SSVAL(req->out.vwv, VWV(0), parms->openold.in.open_mode); SSVAL(req->out.vwv, VWV(1), parms->openold.in.search_attrs); smbcli_req_append_ascii4(req, parms->openold.in.fname, STR_TERMINATE); break; -- cgit From 275df9a5c3b1ade9f2467870c3628a2a896c004c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 13 Dec 2004 23:57:59 +0000 Subject: r4182: fixed trans2 mkdir, allowing mkdir with an initial EA list (This used to be commit 7d981c29c28391813c7f93245f64b3ee108378a4) --- source4/libcli/raw/rawfile.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c index bfd96bd360..4a11fd3834 100644 --- a/source4/libcli/raw/rawfile.c +++ b/source4/libcli/raw/rawfile.c @@ -122,7 +122,7 @@ static struct smbcli_request *smb_raw_t2mkdir_send(struct smbcli_tree *tree, data_total = ea_list_size(parms->t2mkdir.in.num_eas, parms->t2mkdir.in.eas); - t2.in.max_param = 0; + t2.in.max_param = 2; t2.in.max_data = 0; t2.in.max_setup = 0; t2.in.flags = 0; @@ -135,7 +135,7 @@ static struct smbcli_request *smb_raw_t2mkdir_send(struct smbcli_tree *tree, SIVAL(t2.in.params.data, VWV(0), 0); /* reserved */ smbcli_blob_append_string(tree->session, mem_ctx, - &t2.in.params, parms->t2mkdir.in.path, 0); + &t2.in.params, parms->t2mkdir.in.path, STR_TERMINATE); ea_put_list(t2.in.data.data, parms->t2mkdir.in.num_eas, parms->t2mkdir.in.eas); -- cgit From 62d803c4901fcd8c4724aae0356e87ee9443e208 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 16 Dec 2004 12:25:23 +0000 Subject: r4228: make sure the caller knows the packet is in error when a signing error occurs (This used to be commit 5e13571e6b9f5eb35f710c2c8bd85b5569665613) --- source4/libcli/raw/clitransport.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 0af6df33b2..dde77eaeea 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -416,6 +416,7 @@ static void smbcli_transport_finish_recv(struct smbcli_transport *transport) transport->error.etype = ETYPE_SOCKET; transport->error.e.socket_error = SOCKET_READ_BAD_SIG; req->state = SMBCLI_REQUEST_ERROR; + req->status = NT_STATUS_ACCESS_DENIED; goto error; }; -- cgit From 7bb5587097d7af1c42dab683c68afa06b35b7872 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 16 Dec 2004 12:29:04 +0000 Subject: r4229: - added support for multi-part SMBtrans and SMBtrans2 requests in the client code. This was essential to test the multi-part server code (which I will commit soon) - when the request state is an error, ensure that req->status is not NT_STATUS_OK (This used to be commit ef502c403044b68ccdff15b1a94d447d0f53473d) --- source4/libcli/raw/rawrequest.c | 15 ++++-- source4/libcli/raw/rawtrans.c | 109 +++++++++++++++++++++++++++++++++++----- 2 files changed, 106 insertions(+), 18 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 7aa07bef41..5c35618e00 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -48,8 +48,11 @@ NTSTATUS smbcli_request_destroy(struct smbcli_request *req) DLIST_REMOVE(req->transport->pending_recv, req); } - /* ahh, its so nice to destroy a complex structure in such a - simple way! */ + if (req->state == SMBCLI_REQUEST_ERROR && + NT_STATUS_IS_OK(req->status)) { + req->status = NT_STATUS_INTERNAL_ERROR; + } + status = req->status; talloc_free(req); return status; @@ -95,7 +98,7 @@ struct smbcli_request *smbcli_request_setup_nonsmb(struct smbcli_transport *tran setup a SMB packet at transport level */ struct smbcli_request *smbcli_request_setup_transport(struct smbcli_transport *transport, - uint8_t command, uint_t wct, uint_t buflen) + uint8_t command, uint_t wct, uint_t buflen) { struct smbcli_request *req; @@ -119,8 +122,10 @@ struct smbcli_request *smbcli_request_setup_transport(struct smbcli_transport *t SCVAL(req->out.hdr,HDR_FLG, FLAG_CASELESS_PATHNAMES); SSVAL(req->out.hdr,HDR_FLG2, 0); - /* assign a mid */ - req->mid = smbcli_transport_next_mid(transport); + if (command != SMBtranss && command != SMBtranss2) { + /* assign a mid */ + req->mid = smbcli_transport_next_mid(transport); + } /* copy the pid, uid and mid to the request */ SSVAL(req->out.hdr, HDR_PID, 0); diff --git a/source4/libcli/raw/rawtrans.c b/source4/libcli/raw/rawtrans.c index fb8ab4203f..ba80d59819 100644 --- a/source4/libcli/raw/rawtrans.c +++ b/source4/libcli/raw/rawtrans.c @@ -20,8 +20,10 @@ */ #include "includes.h" +#include "dlinklist.h" #include "libcli/raw/libcliraw.h" +#define TORTURE_TRANS_DATA 0 /* check out of bounds for incoming data @@ -198,20 +200,21 @@ NTSTATUS smb_raw_trans_recv(struct smbcli_request *req, return smb_raw_trans2_recv(req, mem_ctx, parms); } -/**************************************************************************** - trans/trans2 raw async interface - only BLOBs used in this interface. - note that this doesn't yet support multi-part requests -****************************************************************************/ + +/* + trans/trans2 raw async interface - only BLOBs used in this interface. +*/ struct smbcli_request *smb_raw_trans_send_backend(struct smbcli_tree *tree, - struct smb_trans2 *parms, - uint8_t command) + struct smb_trans2 *parms, + uint8_t command) { int wct = 14 + parms->in.setup_count; - struct smbcli_request *req; + struct smbcli_request *req, *req2; uint8_t *outdata,*outparam; int i; int padding; size_t namelen = 0; + uint16_t data_disp, data_length, max_data; if (command == SMBtrans) padding = 1; @@ -236,6 +239,19 @@ struct smbcli_request *smb_raw_trans_send_backend(struct smbcli_tree *tree, /* make sure we don't leak data via the padding */ memset(req->out.data, 0, padding); + data_length = parms->in.data.length; + + max_data = smb_raw_max_trans_data(tree, parms->in.params.length); + if (max_data < data_length) { + data_length = max_data; + } + +#if TORTURE_TRANS_DATA + if (data_length > 1) { + data_length /= 2; + } +#endif + /* primary request */ SSVAL(req->out.vwv,VWV(0),parms->in.params.length); SSVAL(req->out.vwv,VWV(1),parms->in.data.length); @@ -247,7 +263,7 @@ struct smbcli_request *smb_raw_trans_send_backend(struct smbcli_tree *tree, SSVAL(req->out.vwv,VWV(8),0); /* reserved */ SSVAL(req->out.vwv,VWV(9),parms->in.params.length); SSVAL(req->out.vwv,VWV(10),PTR_DIFF(outparam,req->out.hdr)+namelen); - SSVAL(req->out.vwv,VWV(11),parms->in.data.length); + SSVAL(req->out.vwv,VWV(11),data_length); SSVAL(req->out.vwv,VWV(12),PTR_DIFF(outdata,req->out.hdr)+namelen); SSVAL(req->out.vwv,VWV(13),parms->in.setup_count); for (i=0;iin.setup_count;i++) { @@ -257,22 +273,88 @@ struct smbcli_request *smb_raw_trans_send_backend(struct smbcli_tree *tree, smbcli_req_append_blob(req, &parms->in.params); } if (parms->in.data.data) { - smbcli_req_append_blob(req, &parms->in.data); + DATA_BLOB data; + data.data = parms->in.data.data; + data.length = data_length; + smbcli_req_append_blob(req, &data); } if (!smbcli_request_send(req)) { smbcli_request_destroy(req); return NULL; } + + data_disp = data_length; + + + if (data_disp != parms->in.data.length) { + /* TODO: this should be done asynchronously .... */ + if (!smbcli_request_receive(req) || + !NT_STATUS_IS_OK(req->status)) { + return req; + } + + req->state = SMBCLI_REQUEST_RECV; + DLIST_ADD(req->transport->pending_recv, req); + } + + + while (data_disp != parms->in.data.length) { + data_length = parms->in.data.length - data_disp; + + max_data = smb_raw_max_trans_data(tree, 0); + if (max_data < data_length) { + data_length = max_data; + } + +#if TORTURE_TRANS_DATA + if (data_length > 1) { + data_length /= 2; + } +#endif + + req2 = smbcli_request_setup(tree, command+1, 9, data_length); + if (!req2) { + return NULL; + } + req2->mid = req->mid; + SSVAL(req2->out.hdr, HDR_MID, req2->mid); + + outdata = req2->out.data; + + SSVAL(req2->out.vwv,VWV(0), parms->in.params.length); + SSVAL(req2->out.vwv,VWV(1), parms->in.data.length); + SSVAL(req2->out.vwv,VWV(2), 0); + SSVAL(req2->out.vwv,VWV(3), 0); + SSVAL(req2->out.vwv,VWV(4), 0); + SSVAL(req2->out.vwv,VWV(5), data_length); + SSVAL(req2->out.vwv,VWV(6), PTR_DIFF(outdata,req2->out.hdr)); + SSVAL(req2->out.vwv,VWV(7), data_disp); + SSVAL(req2->out.vwv,VWV(8), 0xFFFF); + + memcpy(req2->out.data, parms->in.data.data + data_disp, data_length); + + data_disp += data_length; + + req2->one_way_request = 1; + + if (!smbcli_request_send(req2)) { + smbcli_request_destroy(req2); + return NULL; + } + + req->seq_num = req2->seq_num; + } + return req; } -/**************************************************************************** - trans/trans2 raw async interface - only BLOBs used in this interface. -note that this doesn't yet support multi-part requests -****************************************************************************/ +/* + trans/trans2 raw async interface - only BLOBs used in this interface. + note that this doesn't yet support multi-part requests +*/ struct smbcli_request *smb_raw_trans_send(struct smbcli_tree *tree, struct smb_trans2 *parms) { @@ -312,6 +394,7 @@ NTSTATUS smb_raw_trans(struct smbcli_tree *tree, return smb_raw_trans_recv(req, mem_ctx, parms); } + /**************************************************************************** receive a SMB nttrans response allocating the necessary memory ****************************************************************************/ -- cgit From 3b8e83a8c8f32ca658841f1fae344399a48d66a4 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 17 Dec 2004 04:51:23 +0000 Subject: r4243: a sniff from kukks showed that the ea_set interface in trans2 setfileinfo allows for multiple EAs to be set at once. This fixes all the ea code to allow for that. (This used to be commit b26828bef5d55e5eef0e34a164e76292df45e207) --- source4/libcli/raw/raweas.c | 4 ++-- source4/libcli/raw/rawsetfileinfo.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/raweas.c b/source4/libcli/raw/raweas.c index 027705b381..14d4557995 100644 --- a/source4/libcli/raw/raweas.c +++ b/source4/libcli/raw/raweas.c @@ -147,8 +147,8 @@ uint_t ea_pull_struct(const DATA_BLOB *blob, pull a ea_list from a buffer */ NTSTATUS ea_pull_list(const DATA_BLOB *blob, - TALLOC_CTX *mem_ctx, - uint_t *num_eas, struct ea_struct **eas) + TALLOC_CTX *mem_ctx, + uint_t *num_eas, struct ea_struct **eas) { int n; uint32_t ea_size, ofs; diff --git a/source4/libcli/raw/rawsetfileinfo.c b/source4/libcli/raw/rawsetfileinfo.c index 76756971ae..9576bdf356 100644 --- a/source4/libcli/raw/rawsetfileinfo.c +++ b/source4/libcli/raw/rawsetfileinfo.c @@ -56,8 +56,8 @@ static BOOL smb_raw_setinfo_backend(struct smbcli_tree *tree, return True; case RAW_SFILEINFO_EA_SET: - NEED_BLOB(ea_list_size(1, &parms->ea_set.in.ea)); - ea_put_list(blob->data, 1, &parms->ea_set.in.ea); + NEED_BLOB(ea_list_size(parms->ea_set.in.num_eas, parms->ea_set.in.eas)); + ea_put_list(blob->data, parms->ea_set.in.num_eas, parms->ea_set.in.eas); return True; case RAW_SFILEINFO_BASIC_INFO: -- cgit From b706555b3a4ed3c8d459ae86b4c332fa41041f57 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 17 Dec 2004 22:47:49 +0000 Subject: r4261: added the RAW_FILEINFO_EA_LIST trans2 qfileinfo and qpathinfo level. Interestingly, this level did now show up on our trans2 scanner previously as we didn't have the FLAGS2_EXTENDED_ATTRIBUTES bit set in the client code. Now that we set that bit, new levels appear in windows servers. (This used to be commit 0b76d405a73e924dc2706f28bbf1084a59c9b393) --- source4/libcli/raw/raweas.c | 116 +++++++++++++++++++++++++++++++++++++++ source4/libcli/raw/rawfileinfo.c | 64 +++++++++++++++++---- 2 files changed, 170 insertions(+), 10 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/raweas.c b/source4/libcli/raw/raweas.c index 14d4557995..ec8bacdf64 100644 --- a/source4/libcli/raw/raweas.c +++ b/source4/libcli/raw/raweas.c @@ -36,6 +36,19 @@ uint_t ea_list_size(uint_t num_eas, struct ea_struct *eas) return total; } +/* + work out how many bytes on the wire a ea name list will consume. +*/ +static uint_t ea_name_list_size(uint_t num_names, struct ea_name *eas) +{ + uint_t total = 4; + int i; + for (i=0;ilength < 2) { + return 0; + } + + nlen = CVAL(blob->data, 0); + + if (nlen+2 > blob->length) { + return 0; + } + + ea->name.s = talloc_strndup(mem_ctx, (const char *)(blob->data+1), nlen); + ea->name.private_length = nlen; + + return nlen+2; +} + + +/* + pull a ea_name list from a buffer +*/ +NTSTATUS ea_pull_name_list(const DATA_BLOB *blob, + TALLOC_CTX *mem_ctx, + uint_t *num_names, struct ea_name **ea_names) +{ + int n; + uint32_t ea_size, ofs; + + if (blob->length < 4) { + return NT_STATUS_INFO_LENGTH_MISMATCH; + } + + ea_size = IVAL(blob->data, 0); + if (ea_size > blob->length) { + return NT_STATUS_INVALID_PARAMETER; + } + + ofs = 4; + n = 0; + *num_names = 0; + *ea_names = NULL; + + while (ofs < ea_size) { + uint_t len; + DATA_BLOB blob2; + + blob2.data = blob->data + ofs; + blob2.length = ea_size - ofs; + + *ea_names = talloc_realloc_p(mem_ctx, *ea_names, struct ea_name, n+1); + if (! *ea_names) return NT_STATUS_NO_MEMORY; + + len = ea_pull_name(&blob2, mem_ctx, &(*ea_names)[n]); + if (len == 0) { + return NT_STATUS_INVALID_PARAMETER; + } + + ofs += len; + n++; + } + + *num_names = n; + + return NT_STATUS_OK; +} + + +/* + put a ea_name list into a data blob +*/ +BOOL ea_push_name_list(TALLOC_CTX *mem_ctx, + DATA_BLOB *data, uint_t num_names, struct ea_name *eas) +{ + int i; + uint32_t ea_size; + uint32_t off; + + ea_size = ea_name_list_size(num_names, eas); + + *data = data_blob_talloc(mem_ctx, NULL, ea_size); + if (data->data == NULL) { + return False; + } + + SIVAL(data->data, 0, ea_size); + off = 4; + for (i=0;idata, off, nlen); + memcpy(data->data+off+1, eas[i].name.s, nlen+1); + off += 1+nlen+1; + } + + return True; +} diff --git a/source4/libcli/raw/rawfileinfo.c b/source4/libcli/raw/rawfileinfo.c index 6f875f51a7..8f694a23d8 100644 --- a/source4/libcli/raw/rawfileinfo.c +++ b/source4/libcli/raw/rawfileinfo.c @@ -79,6 +79,12 @@ static NTSTATUS smb_raw_info_backend(struct smbcli_session *session, parms->ea_size.out.ea_size = IVAL(blob->data, 22); return NT_STATUS_OK; + case RAW_FILEINFO_EA_LIST: + FINFO_CHECK_MIN_SIZE(4); + return ea_pull_list(blob, mem_ctx, + &parms->ea_list.out.num_eas, + &parms->ea_list.out.eas); + case RAW_FILEINFO_ALL_EAS: FINFO_CHECK_MIN_SIZE(4); return ea_pull_list(blob, mem_ctx, @@ -280,7 +286,9 @@ static NTSTATUS smb_raw_info_backend(struct smbcli_session *session, Very raw query file info - returns param/data blobs - (async send) ****************************************************************************/ static struct smbcli_request *smb_raw_fileinfo_blob_send(struct smbcli_tree *tree, - uint16_t fnum, uint16_t info_level) + uint16_t fnum, + uint16_t info_level, + DATA_BLOB data) { struct smb_trans2 tp; uint16_t setup = TRANSACT2_QFILEINFO; @@ -291,7 +299,7 @@ static struct smbcli_request *smb_raw_fileinfo_blob_send(struct smbcli_tree *tre tp.in.flags = 0; tp.in.timeout = 0; tp.in.setup_count = 1; - tp.in.data = data_blob(NULL, 0); + tp.in.data = data; tp.in.max_param = 2; tp.in.max_data = smb_raw_max_trans_data(tree, 2); tp.in.setup = &setup; @@ -332,8 +340,9 @@ static NTSTATUS smb_raw_fileinfo_blob_recv(struct smbcli_request *req, Very raw query path info - returns param/data blobs (async send) ****************************************************************************/ static struct smbcli_request *smb_raw_pathinfo_blob_send(struct smbcli_tree *tree, - const char *fname, - uint16_t info_level) + const char *fname, + uint16_t info_level, + DATA_BLOB data) { struct smb_trans2 tp; uint16_t setup = TRANSACT2_QPATHINFO; @@ -344,7 +353,7 @@ static struct smbcli_request *smb_raw_pathinfo_blob_send(struct smbcli_tree *tre tp.in.flags = 0; tp.in.timeout = 0; tp.in.setup_count = 1; - tp.in.data = data_blob(NULL, 0); + tp.in.data = data; tp.in.max_param = 2; tp.in.max_data = smb_raw_max_trans_data(tree, 2); tp.in.setup = &setup; @@ -463,6 +472,9 @@ failed: struct smbcli_request *smb_raw_fileinfo_send(struct smbcli_tree *tree, union smb_fileinfo *parms) { + DATA_BLOB data; + struct smbcli_request *req; + /* pass off the non-trans2 level to specialised functions */ if (parms->generic.level == RAW_FILEINFO_GETATTRE) { return smb_raw_getattrE_send(tree, parms); @@ -474,9 +486,24 @@ struct smbcli_request *smb_raw_fileinfo_send(struct smbcli_tree *tree, return NULL; } - return smb_raw_fileinfo_blob_send(tree, - parms->generic.in.fnum, - parms->generic.level); + data = data_blob(NULL, 0); + + if (parms->generic.level == RAW_FILEINFO_EA_LIST) { + if (!ea_push_name_list(tree, + &data, + parms->ea_list.in.num_names, + parms->ea_list.in.ea_names)) { + return NULL; + } + } + + req = smb_raw_fileinfo_blob_send(tree, + parms->generic.in.fnum, + parms->generic.level, data); + + data_blob_free(&data); + + return req; } /**************************************************************************** @@ -525,6 +552,9 @@ NTSTATUS smb_raw_fileinfo(struct smbcli_tree *tree, struct smbcli_request *smb_raw_pathinfo_send(struct smbcli_tree *tree, union smb_fileinfo *parms) { + DATA_BLOB data; + struct smbcli_request *req; + if (parms->generic.level == RAW_FILEINFO_GETATTR) { return smb_raw_getattr_send(tree, parms); } @@ -532,8 +562,22 @@ struct smbcli_request *smb_raw_pathinfo_send(struct smbcli_tree *tree, return NULL; } - return smb_raw_pathinfo_blob_send(tree, parms->generic.in.fname, - parms->generic.level); + data = data_blob(NULL, 0); + + if (parms->generic.level == RAW_FILEINFO_EA_LIST) { + if (!ea_push_name_list(tree, + &data, + parms->ea_list.in.num_names, + parms->ea_list.in.ea_names)) { + return NULL; + } + } + + req = smb_raw_pathinfo_blob_send(tree, parms->generic.in.fname, + parms->generic.level, data); + data_blob_free(&data); + + return req; } /**************************************************************************** -- cgit From ed42a64901ba0a7ad8cbaac582600688af1b7d72 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 18 Dec 2004 04:38:43 +0000 Subject: r4263: added support for the trans2 RAW_SEARCH_EA_LIST information level. This is quite a strange level that we've never seen before, but is used by the os2 workplace shell. note w2k screws up this level when unicode is negotiated, so it only passes the RAW-SEARCH test when you force non-unicode (This used to be commit 25189b8fbf6515d573e3398dc9fca56505dc37b9) --- source4/libcli/raw/rawfileinfo.c | 2 +- source4/libcli/raw/rawsearch.c | 61 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawfileinfo.c b/source4/libcli/raw/rawfileinfo.c index 8f694a23d8..ad7b9b900a 100644 --- a/source4/libcli/raw/rawfileinfo.c +++ b/source4/libcli/raw/rawfileinfo.c @@ -550,7 +550,7 @@ NTSTATUS smb_raw_fileinfo(struct smbcli_tree *tree, Query path info (async send) ****************************************************************************/ struct smbcli_request *smb_raw_pathinfo_send(struct smbcli_tree *tree, - union smb_fileinfo *parms) + union smb_fileinfo *parms) { DATA_BLOB data; struct smbcli_request *req; diff --git a/source4/libcli/raw/rawsearch.c b/source4/libcli/raw/rawsearch.c index d55a47ca26..3c271253e5 100644 --- a/source4/libcli/raw/rawsearch.c +++ b/source4/libcli/raw/rawsearch.c @@ -210,6 +210,15 @@ static NTSTATUS smb_raw_search_first_blob(struct smbcli_tree *tree, tp.in.max_param = 10; tp.in.max_data = smb_raw_max_trans_data(tree, 10); tp.in.setup = &setup; + + if (info_level == RAW_SEARCH_EA_LIST) { + if (!ea_push_name_list(mem_ctx, + &tp.in.data, + io->t2ffirst.in.num_names, + io->t2ffirst.in.ea_names)) { + return NT_STATUS_NO_MEMORY; + } + } tp.in.params = data_blob_talloc(mem_ctx, NULL, 12); if (!tp.in.params.data) { @@ -223,7 +232,7 @@ static NTSTATUS smb_raw_search_first_blob(struct smbcli_tree *tree, SIVAL(tp.in.params.data, 8, io->t2ffirst.in.storage_type); smbcli_blob_append_string(tree->session, mem_ctx, &tp.in.params, - io->t2ffirst.in.pattern, STR_TERMINATE); + io->t2ffirst.in.pattern, STR_TERMINATE); status = smb_raw_trans2(tree, mem_ctx, &tp); if (!NT_STATUS_IS_OK(status)) { @@ -262,6 +271,15 @@ static NTSTATUS smb_raw_search_next_blob(struct smbcli_tree *tree, tp.in.max_param = 10; tp.in.max_data = smb_raw_max_trans_data(tree, 10); tp.in.setup = &setup; + + if (info_level == RAW_SEARCH_EA_LIST) { + if (!ea_push_name_list(mem_ctx, + &tp.in.data, + io->t2fnext.in.num_names, + io->t2fnext.in.ea_names)) { + return NT_STATUS_NO_MEMORY; + } + } tp.in.params = data_blob_talloc(mem_ctx, NULL, 12); if (!tp.in.params.data) { @@ -306,6 +324,9 @@ static int parse_trans2_search(struct smbcli_tree *tree, union smb_search_data *data) { uint_t len, ofs; + uint32_t ea_size; + DATA_BLOB eablob; + NTSTATUS status; switch (level) { case RAW_SEARCH_GENERIC: @@ -360,6 +381,44 @@ static int parse_trans2_search(struct smbcli_tree *tree, 26, 27, STR_LEN8BIT | STR_TERMINATE | STR_NOALIGN); return len + 27 + 1; + case RAW_SEARCH_EA_LIST: + if (flags & FLAG_TRANS2_FIND_REQUIRE_RESUME) { + if (blob->length < 4) return -1; + data->ea_list.resume_key = IVAL(blob->data, 0); + blob->data += 4; + blob->length -= 4; + } + if (blob->length < 28) return -1; + data->ea_list.create_time = raw_pull_dos_date2(tree->session->transport, + blob->data + 0); + data->ea_list.access_time = raw_pull_dos_date2(tree->session->transport, + blob->data + 4); + data->ea_list.write_time = raw_pull_dos_date2(tree->session->transport, + blob->data + 8); + data->ea_list.size = IVAL(blob->data, 12); + data->ea_list.alloc_size = IVAL(blob->data, 16); + data->ea_list.attrib = SVAL(blob->data, 20); + ea_size = IVAL(blob->data, 22); + if (ea_size > 0xFFFF) { + return -1; + } + eablob.data = blob->data + 22; + eablob.length = ea_size; + if (eablob.length > blob->length - 24) { + return -1; + } + status = ea_pull_list(&eablob, mem_ctx, + &data->ea_list.eas.num_eas, + &data->ea_list.eas.eas); + if (!NT_STATUS_IS_OK(status)) { + return -1; + } + len = smbcli_blob_pull_string(tree->session, mem_ctx, blob, + &data->ea_list.name, + 22+ea_size, 23+ea_size, + STR_LEN8BIT | STR_TERMINATE | STR_NOALIGN); + return len + ea_size + 23 + 1; + case RAW_SEARCH_DIRECTORY_INFO: if (blob->length < 65) return -1; ofs = IVAL(blob->data, 0); -- cgit From fa4271fb39d593fd4516e8ee32234299ffd31967 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 21 Dec 2004 11:45:37 +0000 Subject: r4315: use the remote hosts max_xmit, not the local hosts, in calculating max trans2 data sizes (This used to be commit 827008cfebf29d081b457ba7162d89c8150cb24b) --- source4/libcli/raw/rawtrans.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawtrans.c b/source4/libcli/raw/rawtrans.c index ba80d59819..95555c3a82 100644 --- a/source4/libcli/raw/rawtrans.c +++ b/source4/libcli/raw/rawtrans.c @@ -626,5 +626,5 @@ NTSTATUS smb_raw_nttrans(struct smbcli_tree *tree, */ size_t smb_raw_max_trans_data(struct smbcli_tree *tree, size_t param_size) { - return tree->session->transport->options.max_xmit - (70 + param_size); + return tree->session->transport->negotiate.max_xmit - (70 + param_size); } -- cgit From 101d0333a333cee6d3fc33cb4655976145fb87e8 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 21 Dec 2004 11:47:08 +0000 Subject: r4316: - now that the trans2 code properly supports multi-part requests, we can set a maximum sized max_data in libcli trans2 code - fixed string termination in the EA_LIST trans2 findfirst level (This used to be commit a2a5f147f4faac8a48ff8f1b3e5f1334c92575bb) --- source4/libcli/raw/rawacl.c | 2 +- source4/libcli/raw/rawfileinfo.c | 4 ++-- source4/libcli/raw/rawfsinfo.c | 2 +- source4/libcli/raw/rawsearch.c | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawacl.c b/source4/libcli/raw/rawacl.c index 253a3cbbe7..97e0212137 100644 --- a/source4/libcli/raw/rawacl.c +++ b/source4/libcli/raw/rawacl.c @@ -34,7 +34,7 @@ struct smbcli_request *smb_raw_query_secdesc_send(struct smbcli_tree *tree, nt.in.max_setup = 0; nt.in.max_param = 4; - nt.in.max_data = smb_raw_max_trans_data(tree, 4); + nt.in.max_data = 0xFFFF; nt.in.setup_count = 0; nt.in.function = NT_TRANSACT_QUERY_SECURITY_DESC; nt.in.setup = NULL; diff --git a/source4/libcli/raw/rawfileinfo.c b/source4/libcli/raw/rawfileinfo.c index ad7b9b900a..3befb8ee4d 100644 --- a/source4/libcli/raw/rawfileinfo.c +++ b/source4/libcli/raw/rawfileinfo.c @@ -301,7 +301,7 @@ static struct smbcli_request *smb_raw_fileinfo_blob_send(struct smbcli_tree *tre tp.in.setup_count = 1; tp.in.data = data; tp.in.max_param = 2; - tp.in.max_data = smb_raw_max_trans_data(tree, 2); + tp.in.max_data = 0xFFFF; tp.in.setup = &setup; tp.in.params = data_blob_talloc(mem_ctx, NULL, 4); @@ -355,7 +355,7 @@ static struct smbcli_request *smb_raw_pathinfo_blob_send(struct smbcli_tree *tre tp.in.setup_count = 1; tp.in.data = data; tp.in.max_param = 2; - tp.in.max_data = smb_raw_max_trans_data(tree, 2); + tp.in.max_data = 0xFFFF; tp.in.setup = &setup; tp.in.params = data_blob_talloc(mem_ctx, NULL, 6); diff --git a/source4/libcli/raw/rawfsinfo.c b/source4/libcli/raw/rawfsinfo.c index 7cec93b6bc..fd99c4aeb9 100644 --- a/source4/libcli/raw/rawfsinfo.c +++ b/source4/libcli/raw/rawfsinfo.c @@ -78,7 +78,7 @@ static struct smbcli_request *smb_raw_qfsinfo_send(struct smbcli_tree *tree, tp.in.timeout = 0; tp.in.setup_count = 1; tp.in.max_param = 0; - tp.in.max_data = smb_raw_max_trans_data(tree, 0); + tp.in.max_data = 0xFFFF; tp.in.setup = &setup; tp.in.data = data_blob(NULL, 0); tp.in.timeout = 0; diff --git a/source4/libcli/raw/rawsearch.c b/source4/libcli/raw/rawsearch.c index 3c271253e5..90715ca8e2 100644 --- a/source4/libcli/raw/rawsearch.c +++ b/source4/libcli/raw/rawsearch.c @@ -208,7 +208,7 @@ static NTSTATUS smb_raw_search_first_blob(struct smbcli_tree *tree, tp.in.setup_count = 1; tp.in.data = data_blob(NULL, 0); tp.in.max_param = 10; - tp.in.max_data = smb_raw_max_trans_data(tree, 10); + tp.in.max_data = 0xFFFF; tp.in.setup = &setup; if (info_level == RAW_SEARCH_EA_LIST) { @@ -269,7 +269,7 @@ static NTSTATUS smb_raw_search_next_blob(struct smbcli_tree *tree, tp.in.setup_count = 1; tp.in.data = data_blob(NULL, 0); tp.in.max_param = 10; - tp.in.max_data = smb_raw_max_trans_data(tree, 10); + tp.in.max_data = 0xFFFF; tp.in.setup = &setup; if (info_level == RAW_SEARCH_EA_LIST) { @@ -416,7 +416,7 @@ static int parse_trans2_search(struct smbcli_tree *tree, len = smbcli_blob_pull_string(tree->session, mem_ctx, blob, &data->ea_list.name, 22+ea_size, 23+ea_size, - STR_LEN8BIT | STR_TERMINATE | STR_NOALIGN); + STR_LEN8BIT | STR_NOALIGN); return len + ea_size + 23 + 1; case RAW_SEARCH_DIRECTORY_INFO: -- cgit From 90b299603f7a8bc03617ae08d2fd7063d249bd24 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 24 Dec 2004 09:57:44 +0000 Subject: r4356: Allow anonymous connections to use NTLMSSP. The silly bugs that prevented this are gone. Andrew Bartlett (This used to be commit 87dad5ec538abad93d621078a82f162675847f9f) --- source4/libcli/raw/clitree.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index b9d0ffbc1f..777279f5f9 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -223,7 +223,6 @@ NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx, setup.generic.in.password = NULL; setup.generic.in.user = ""; setup.generic.in.domain = ""; - setup.generic.in.capabilities &= ~CAP_EXTENDED_SECURITY; } else { setup.generic.in.password = password; setup.generic.in.user = user; -- cgit From 24f209e89934cd9c522e2225e47cd6788834ba1f Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sat, 25 Dec 2004 14:12:31 +0000 Subject: r4361: fix the build metze (This used to be commit 78b2af77e9e4b97c698d6d9e680207b1df289cb4) --- source4/libcli/raw/clisession.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index 519f112ceb..dcc0c8adbe 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -410,7 +410,7 @@ static NTSTATUS smb_raw_session_setup_generic_spnego(struct smbcli_session *sess status = gensec_client_start(session, &session->gensec); if (!NT_STATUS_IS_OK(status)) { DEBUG(1, ("Failed to start GENSEC client mode: %s\n", nt_errstr(status))); - goto done; + return status; } gensec_want_feature(session->gensec, GENSEC_FEATURE_SESSION_KEY); @@ -505,7 +505,8 @@ done: parms->generic.out.lanman = s2.spnego.out.lanman; parms->generic.out.domain = s2.spnego.out.domain; } else { - gensec_end(&session->gensec); + talloc_free(session->gensec); + session->gensec = NULL; DEBUG(1, ("Failed to login with %s: %s\n", gensec_get_name_by_oid(chosen_oid), nt_errstr(status))); return status; } -- cgit From 5e4e61c8276d5f0a4a2d4c6cbc20047554096227 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 26 Dec 2004 08:13:01 +0000 Subject: r4364: - added support for testing of chained SMB operations in smbtorture - added test for chained OpenX/ReadX, simulating the OS/2 workplace shell - fixed a bug in handling chained fnum in openx and ntcreatex in the server (yes, I'm on holiday, but this bug was annoying me ....) (This used to be commit b3b8958a18e302b815d98c0e3879e404bced6a08) --- source4/libcli/raw/rawfile.c | 78 ++++++++++++++++++++++++++++++++++++++- source4/libcli/raw/rawreadwrite.c | 5 +-- source4/libcli/raw/rawrequest.c | 63 ++++++++++++++++++++++++++++++- 3 files changed, 140 insertions(+), 6 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c index 4a11fd3834..11be8ffba7 100644 --- a/source4/libcli/raw/rawfile.c +++ b/source4/libcli/raw/rawfile.c @@ -29,7 +29,6 @@ if (!req) return NULL; \ } while (0) - /**************************************************************************** Rename a file - async interface ****************************************************************************/ @@ -426,6 +425,7 @@ struct smbcli_request *smb_raw_open_send(struct smbcli_tree *tree, union smb_ope { int len; struct smbcli_request *req = NULL; + BOOL bigoffset = False; switch (parms->generic.level) { case RAW_OPEN_T2OPEN: @@ -507,6 +507,42 @@ struct smbcli_request *smb_raw_open_send(struct smbcli_tree *tree, union smb_ope case RAW_OPEN_NTTRANS_CREATE: return smb_raw_nttrans_create_send(tree, parms); + + + case RAW_OPEN_OPENX_READX: + SETUP_REQUEST(SMBopenX, 15, 0); + SSVAL(req->out.vwv, VWV(0), SMB_CHAIN_NONE); + SSVAL(req->out.vwv, VWV(1), 0); + SSVAL(req->out.vwv, VWV(2), parms->openxreadx.in.flags); + SSVAL(req->out.vwv, VWV(3), parms->openxreadx.in.open_mode); + SSVAL(req->out.vwv, VWV(4), parms->openxreadx.in.search_attrs); + SSVAL(req->out.vwv, VWV(5), parms->openxreadx.in.file_attrs); + raw_push_dos_date3(tree->session->transport, + req->out.vwv, VWV(6), parms->openxreadx.in.write_time); + SSVAL(req->out.vwv, VWV(8), parms->openxreadx.in.open_func); + SIVAL(req->out.vwv, VWV(9), parms->openxreadx.in.size); + SIVAL(req->out.vwv, VWV(11),parms->openxreadx.in.timeout); + SIVAL(req->out.vwv, VWV(13),0); + smbcli_req_append_string(req, parms->openxreadx.in.fname, STR_TERMINATE); + + if (tree->session->transport->negotiate.capabilities & CAP_LARGE_FILES) { + bigoffset = True; + } + + smbcli_chained_request_setup(req, SMBreadX, bigoffset ? 12 : 10, 0); + + SSVAL(req->out.vwv, VWV(0), SMB_CHAIN_NONE); + SSVAL(req->out.vwv, VWV(1), 0); + SSVAL(req->out.vwv, VWV(2), 0); + SIVAL(req->out.vwv, VWV(3), parms->openxreadx.in.offset); + SSVAL(req->out.vwv, VWV(5), parms->openxreadx.in.maxcnt & 0xFFFF); + SSVAL(req->out.vwv, VWV(6), parms->openxreadx.in.mincnt); + SIVAL(req->out.vwv, VWV(7), parms->openxreadx.in.maxcnt >> 16); + SSVAL(req->out.vwv, VWV(9), parms->openxreadx.in.remaining); + if (bigoffset) { + SIVAL(req->out.vwv, VWV(10),parms->openxreadx.in.offset>>32); + } + break; } if (!smbcli_request_send(req)) { @@ -522,6 +558,8 @@ struct smbcli_request *smb_raw_open_send(struct smbcli_tree *tree, union smb_ope ****************************************************************************/ NTSTATUS smb_raw_open_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, union smb_open *parms) { + NTSTATUS status; + if (!smbcli_request_receive(req) || smbcli_request_is_error(req)) { goto failed; @@ -602,6 +640,44 @@ NTSTATUS smb_raw_open_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, unio case RAW_OPEN_NTTRANS_CREATE: return smb_raw_nttrans_create_recv(req, mem_ctx, parms); + + case RAW_OPEN_OPENX_READX: + SMBCLI_CHECK_MIN_WCT(req, 15); + parms->openxreadx.out.fnum = SVAL(req->in.vwv, VWV(2)); + parms->openxreadx.out.attrib = SVAL(req->in.vwv, VWV(3)); + parms->openxreadx.out.write_time = raw_pull_dos_date3(req->transport, + req->in.vwv + VWV(4)); + parms->openxreadx.out.size = IVAL(req->in.vwv, VWV(6)); + parms->openxreadx.out.access = SVAL(req->in.vwv, VWV(8)); + parms->openxreadx.out.ftype = SVAL(req->in.vwv, VWV(9)); + parms->openxreadx.out.devstate = SVAL(req->in.vwv, VWV(10)); + parms->openxreadx.out.action = SVAL(req->in.vwv, VWV(11)); + parms->openxreadx.out.unique_fid = IVAL(req->in.vwv, VWV(12)); + if (req->in.wct >= 19) { + parms->openxreadx.out.access_mask = IVAL(req->in.vwv, VWV(15)); + parms->openxreadx.out.unknown = IVAL(req->in.vwv, VWV(17)); + } else { + parms->openxreadx.out.access_mask = 0; + parms->openxreadx.out.unknown = 0; + } + + status = smbcli_chained_advance(req); + if (!NT_STATUS_IS_OK(status)) { + return status; + } + + SMBCLI_CHECK_WCT(req, 12); + parms->openxreadx.out.remaining = SVAL(req->in.vwv, VWV(2)); + parms->openxreadx.out.compaction_mode = SVAL(req->in.vwv, VWV(3)); + parms->openxreadx.out.nread = SVAL(req->in.vwv, VWV(5)); + if (parms->openxreadx.out.nread > + MAX(parms->openxreadx.in.mincnt, parms->openxreadx.in.maxcnt) || + !smbcli_raw_pull_data(req, req->in.hdr + SVAL(req->in.vwv, VWV(6)), + parms->openxreadx.out.nread, + parms->openxreadx.out.data)) { + req->status = NT_STATUS_BUFFER_TOO_SMALL; + } + break; } failed: diff --git a/source4/libcli/raw/rawreadwrite.c b/source4/libcli/raw/rawreadwrite.c index 8381c7b2b0..d9fe3fdce0 100644 --- a/source4/libcli/raw/rawreadwrite.c +++ b/source4/libcli/raw/rawreadwrite.c @@ -27,7 +27,6 @@ if (!req) return NULL; \ } while (0) - /**************************************************************************** low level read operation (async send) ****************************************************************************/ @@ -74,7 +73,7 @@ struct smbcli_request *smb_raw_read_send(struct smbcli_tree *tree, union smb_rea bigoffset = True; } SETUP_REQUEST(SMBreadX, bigoffset ? 12 : 10, 0); - SSVAL(req->out.vwv, VWV(0), 0xFF); + SSVAL(req->out.vwv, VWV(0), SMB_CHAIN_NONE); SSVAL(req->out.vwv, VWV(1), 0); SSVAL(req->out.vwv, VWV(2), parms->readx.in.fnum); SIVAL(req->out.vwv, VWV(3), parms->readx.in.offset); @@ -228,7 +227,7 @@ struct smbcli_request *smb_raw_write_send(struct smbcli_tree *tree, union smb_wr bigoffset = True; } SETUP_REQUEST(SMBwriteX, bigoffset ? 14 : 12, parms->writex.in.count); - SSVAL(req->out.vwv, VWV(0), 0xFF); + SSVAL(req->out.vwv, VWV(0), SMB_CHAIN_NONE); SSVAL(req->out.vwv, VWV(1), 0); SSVAL(req->out.vwv, VWV(2), parms->writex.in.fnum); SIVAL(req->out.vwv, VWV(3), parms->writex.in.offset); diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 5c35618e00..178ccdbf48 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -168,8 +168,8 @@ struct smbcli_request *smbcli_request_setup_session(struct smbcli_session *sessi setup a request for tree based commands */ struct smbcli_request *smbcli_request_setup(struct smbcli_tree *tree, - uint8_t command, - uint_t wct, uint_t buflen) + uint8_t command, + uint_t wct, uint_t buflen) { struct smbcli_request *req; @@ -181,6 +181,7 @@ struct smbcli_request *smbcli_request_setup(struct smbcli_tree *tree, return req; } + /* grow the allocation of the data buffer portion of a reply packet. Note that as this can reallocate the packet buffer this @@ -246,6 +247,64 @@ static void smbcli_req_grow_data(struct smbcli_request *req, uint_t new_size) } +/* + setup a chained reply in req->out with the given word count and + initial data buffer size. +*/ +NTSTATUS smbcli_chained_request_setup(struct smbcli_request *req, + uint8_t command, + uint_t wct, uint_t buflen) +{ + uint_t new_size = 1 + (wct*2) + 2 + buflen; + + SSVAL(req->out.vwv, VWV(0), command); + SSVAL(req->out.vwv, VWV(1), req->out.size - NBT_HDR_SIZE); + + smbcli_req_grow_allocation(req, req->out.data_size + new_size); + + req->out.vwv = req->out.buffer + req->out.size + 1; + SCVAL(req->out.vwv, -1, wct); + SSVAL(req->out.vwv, VWV(wct), buflen); + + req->out.size += new_size; + + return NT_STATUS_OK; +} + +/* + aadvance to the next chained reply in a request +*/ +NTSTATUS smbcli_chained_advance(struct smbcli_request *req) +{ + uint8_t *buffer; + + if (CVAL(req->in.vwv, VWV(0)) == SMB_CHAIN_NONE) { + return NT_STATUS_NOT_FOUND; + } + + buffer = req->in.hdr + SVAL(req->in.vwv, VWV(1)); + + if (buffer + 3 > req->in.buffer + req->in.size) { + return NT_STATUS_BUFFER_TOO_SMALL; + } + + req->in.vwv = buffer + 1; + req->in.wct = CVAL(buffer, 0); + if (buffer + 3 + req->in.wct*2 > req->in.buffer + req->in.size) { + return NT_STATUS_BUFFER_TOO_SMALL; + } + req->in.data = req->in.vwv + 2 + req->in.wct * 2; + req->in.data_size = SVAL(req->in.vwv, VWV(req->in.wct)); + + if (buffer + 3 + req->in.wct*2 + req->in.data_size > + req->in.buffer + req->in.size) { + return NT_STATUS_BUFFER_TOO_SMALL; + } + + return NT_STATUS_OK; +} + + /* send a message */ -- cgit From cc55aef7c116d03ba2817625b0ba9edb378525e3 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 6 Jan 2005 02:32:43 +0000 Subject: r4547: - added talloc_new(ctx) macro that is a neater form of the common talloc(ctx, 0) call. - cleaned up some talloc usage in various files I'd like to get to the point that we have no calls to talloc(), at which point we will rename talloc_p() to talloc(), to encourage everyone to use the typesafe functions. (This used to be commit e6c81d7c9f8a6938947d3c1c8a971a0d6d50b67a) --- source4/libcli/raw/rawfile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c index 11be8ffba7..e0b54cacc3 100644 --- a/source4/libcli/raw/rawfile.c +++ b/source4/libcli/raw/rawfile.c @@ -259,7 +259,7 @@ static struct smbcli_request *smb_raw_nttrans_create_send(struct smbcli_tree *tr { struct smb_nttrans nt; uint8_t *params; - TALLOC_CTX *mem_ctx = talloc(tree, 0); + TALLOC_CTX *mem_ctx = talloc_new(tree); uint16_t fname_len; DATA_BLOB sd_blob, ea_blob; struct smbcli_request *req; -- cgit From ddc10d4d37984246a6547e34a32d629c689c40d1 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 6 Jan 2005 03:06:58 +0000 Subject: r4549: got rid of a lot more uses of plain talloc(), instead using talloc_size() or talloc_array_p() where appropriate. also fixed a memory leak in pvfs_copy_file() (failed to free a memory context) (This used to be commit 89b74b53546e1570b11b3702f40bee58aed8c503) --- source4/libcli/raw/clitransport.c | 4 ++-- source4/libcli/raw/rawrequest.c | 2 +- source4/libcli/raw/rawtrans.c | 8 ++++---- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index dde77eaeea..63ff1e4409 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -462,8 +462,8 @@ static void smbcli_transport_process_recv(struct smbcli_transport *transport) if (transport->recv_buffer.received == NBT_HDR_SIZE) { /* we've got a full header */ transport->recv_buffer.req_size = smb_len(transport->recv_buffer.header) + NBT_HDR_SIZE; - transport->recv_buffer.buffer = talloc(transport, - NBT_HDR_SIZE+transport->recv_buffer.req_size); + transport->recv_buffer.buffer = talloc_size(transport, + NBT_HDR_SIZE+transport->recv_buffer.req_size); if (transport->recv_buffer.buffer == NULL) { smbcli_transport_dead(transport); return; diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 178ccdbf48..b74f066ef4 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -83,7 +83,7 @@ struct smbcli_request *smbcli_request_setup_nonsmb(struct smbcli_transport *tran /* over allocate by a small amount */ req->out.allocated = req->out.size + REQ_OVER_ALLOCATION; - req->out.buffer = talloc(req, req->out.allocated); + req->out.buffer = talloc_size(req, req->out.allocated); if (!req->out.buffer) { return NULL; } diff --git a/source4/libcli/raw/rawtrans.c b/source4/libcli/raw/rawtrans.c index 95555c3a82..0ccecdc2d4 100644 --- a/source4/libcli/raw/rawtrans.c +++ b/source4/libcli/raw/rawtrans.c @@ -87,7 +87,7 @@ NTSTATUS smb_raw_trans2_recv(struct smbcli_request *req, /* allocate it */ if (total_data != 0) { - tdata = talloc(mem_ctx, total_data); + tdata = talloc_size(mem_ctx, total_data); if (!tdata) { DEBUG(0,("smb_raw_receive_trans: failed to enlarge data buffer to %d bytes\n", total_data)); req->status = NT_STATUS_NO_MEMORY; @@ -97,7 +97,7 @@ NTSTATUS smb_raw_trans2_recv(struct smbcli_request *req, } if (total_param != 0) { - tparam = talloc(mem_ctx, total_param); + tparam = talloc_size(mem_ctx, total_param); if (!tparam) { DEBUG(0,("smb_raw_receive_trans: failed to enlarge param buffer to %d bytes\n", total_param)); req->status = NT_STATUS_NO_MEMORY; @@ -111,7 +111,7 @@ NTSTATUS smb_raw_trans2_recv(struct smbcli_request *req, if (parms->out.setup_count > 0) { int i; - parms->out.setup = talloc(mem_ctx, 2 * parms->out.setup_count); + parms->out.setup = talloc_array(mem_ctx, 2, parms->out.setup_count, "setup"); if (!parms->out.setup) { req->status = NT_STATUS_NO_MEMORY; return smbcli_request_destroy(req); @@ -439,7 +439,7 @@ NTSTATUS smb_raw_nttrans_recv(struct smbcli_request *req, if (parms->out.setup_count > 0) { int i; - parms->out.setup = talloc(mem_ctx, 2 * parms->out.setup_count); + parms->out.setup = talloc_array(mem_ctx, 2, parms->out.setup_count, "setup"); if (!parms->out.setup) { req->status = NT_STATUS_NO_MEMORY; return smbcli_request_destroy(req); -- cgit From 11ce2cfd70df264c5c91b4daaa9a01c5abc673b0 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 7 Jan 2005 04:39:16 +0000 Subject: r4591: - converted the other _p talloc functions to not need _p - added #if TALLOC_DEPRECATED around the _p functions - fixes the code that broke from the above while doing this I fixed quite a number of places that were incorrectly using the non type-safe talloc functions to use the type safe ones. Some were even doing multiplies for array allocation, which is potentially unsafe. (This used to be commit 6e7754abd0c225527fb38363996a6e241b87b37e) --- source4/libcli/raw/rawnotify.c | 2 +- source4/libcli/raw/rawrequest.c | 4 ++-- source4/libcli/raw/rawtrans.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawnotify.c b/source4/libcli/raw/rawnotify.c index 918fb788cb..e48545419f 100644 --- a/source4/libcli/raw/rawnotify.c +++ b/source4/libcli/raw/rawnotify.c @@ -73,7 +73,7 @@ NTSTATUS smb_raw_changenotify_recv(struct smbcli_request *req, } /* allocate array */ - parms->out.changes = talloc_array_p(mem_ctx, struct notify_changes, parms->out.num_changes); + parms->out.changes = talloc_array(mem_ctx, struct notify_changes, parms->out.num_changes); if (!parms->out.changes) { return NT_STATUS_NO_MEMORY; } diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index b74f066ef4..8093b298bb 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -203,7 +203,7 @@ static void smbcli_req_grow_allocation(struct smbcli_request *req, uint_t new_si /* we need to realloc */ req->out.allocated = req->out.size + delta + REQ_OVER_ALLOCATION; - buf2 = talloc_realloc(req, req->out.buffer, req->out.allocated); + buf2 = talloc_realloc(req, req->out.buffer, uint8_t, req->out.allocated); if (buf2 == NULL) { smb_panic("out of memory in req_grow_allocation"); } @@ -950,7 +950,7 @@ size_t smbcli_blob_append_string(struct smbcli_session *session, max_len = (strlen(str)+2) * MAX_BYTES_PER_CHAR; - blob->data = talloc_realloc(mem_ctx, blob->data, blob->length + max_len); + blob->data = talloc_realloc(mem_ctx, blob->data, uint8_t, blob->length + max_len); if (!blob->data) { return 0; } diff --git a/source4/libcli/raw/rawtrans.c b/source4/libcli/raw/rawtrans.c index 0ccecdc2d4..118ac5e3fd 100644 --- a/source4/libcli/raw/rawtrans.c +++ b/source4/libcli/raw/rawtrans.c @@ -111,7 +111,7 @@ NTSTATUS smb_raw_trans2_recv(struct smbcli_request *req, if (parms->out.setup_count > 0) { int i; - parms->out.setup = talloc_array(mem_ctx, 2, parms->out.setup_count, "setup"); + parms->out.setup = talloc_array(mem_ctx, uint16_t, parms->out.setup_count); if (!parms->out.setup) { req->status = NT_STATUS_NO_MEMORY; return smbcli_request_destroy(req); @@ -439,7 +439,7 @@ NTSTATUS smb_raw_nttrans_recv(struct smbcli_request *req, if (parms->out.setup_count > 0) { int i; - parms->out.setup = talloc_array(mem_ctx, 2, parms->out.setup_count, "setup"); + parms->out.setup = talloc_array(mem_ctx, uint16_t, parms->out.setup_count); if (!parms->out.setup) { req->status = NT_STATUS_NO_MEMORY; return smbcli_request_destroy(req); -- cgit From 592fce7fb149ca5e82b14d9c8f13a4da1babe2b7 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 13 Jan 2005 18:49:10 +0000 Subject: r4726: - use the name tcon and tid instead of conn and cnum - make use of talloc destructors metze (This used to be commit 8308da6ce4a95f8c10e22949ef00e9e64f2dbb85) --- source4/libcli/raw/clitree.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index 777279f5f9..0f56c0fe2e 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -96,12 +96,12 @@ NTSTATUS smb_tree_connect_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, case RAW_TCON_TCON: SMBCLI_CHECK_WCT(req, 2); parms->tcon.out.max_xmit = SVAL(req->in.vwv, VWV(0)); - parms->tcon.out.cnum = SVAL(req->in.vwv, VWV(1)); + parms->tcon.out.tid = SVAL(req->in.vwv, VWV(1)); break; case RAW_TCON_TCONX: ZERO_STRUCT(parms->tconx.out); - parms->tconx.out.cnum = SVAL(req->in.hdr, HDR_TID); + parms->tconx.out.tid = SVAL(req->in.hdr, HDR_TID); if (req->in.wct >= 4) { parms->tconx.out.options = SVAL(req->in.vwv, VWV(3)); } @@ -274,7 +274,7 @@ NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx, return status; } - tree->tid = tcon.tconx.out.cnum; + tree->tid = tcon.tconx.out.tid; if (tcon.tconx.out.dev_type) { tree->device = talloc_strdup(tree, tcon.tconx.out.dev_type); } -- cgit From e89fd49df7e63dcf37ee1aa7e2f50965851725c9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 15 Jan 2005 10:38:12 +0000 Subject: r4757: added the ability of the clisocket level of libcli to handle async socket connections. This was complicated by a few factors: - it meant moving the event context from clitransport to clisocket, so lots of structures changed - we need to asynchronously handle connection to lists of port numbers, not just one port number. The code internally tries each port in the list in turn, without ever blocking - the man page on how connect() is supposed to work asynchronously doesn't work in practice (now why doesn't this surprise me?). The getsockopt() for SOL_ERROR is supposed to retrieve the error, but in fact the next (unrelated) connect() call on the same socket also gets an error, though not the right error. To work around this I need to tear down the whole socket between each attempted port. I hate posix. Note that clisocket.c still does a blocking name resolution call in smbcli_sock_connect_byname(). That will be fixed when we add the async NBT resolution code. Also note that I arranged things so that every SMB connection is now async internally, so using plain smbclient or smbtorture tests all the async features of this new code. (This used to be commit 468f8ebbfdbdf37c757fdc4863626aa9946a8870) --- source4/libcli/raw/clisocket.c | 244 ++++++++++++++++++++++++++++++-------- source4/libcli/raw/clitransport.c | 33 ++---- source4/libcli/raw/libcliraw.h | 31 ++--- source4/libcli/raw/rawrequest.c | 2 +- 4 files changed, 220 insertions(+), 90 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index fb9afeab81..d20dc4bf25 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -1,7 +1,8 @@ /* Unix SMB/CIFS implementation. SMB client socket context management functions - Copyright (C) Andrew Tridgell 1994-2003 + + Copyright (C) Andrew Tridgell 1994-2005 Copyright (C) James Myers 2003 This program is free software; you can redistribute it and/or modify @@ -20,7 +21,18 @@ */ #include "includes.h" +#include "events.h" #include "libcli/raw/libcliraw.h" +#include "libcli/composite/composite.h" + +/* + this private structure is used during async connection handling +*/ +struct clisocket_connect { + int *iports; + struct smbcli_socket *sock; + const char *dest_host; +}; /* create a smbcli_socket context @@ -29,61 +41,210 @@ struct smbcli_socket *smbcli_sock_init(TALLOC_CTX *mem_ctx) { struct smbcli_socket *sock; - sock = talloc_p(mem_ctx, struct smbcli_socket); + sock = talloc_zero(mem_ctx, struct smbcli_socket); if (!sock) { return NULL; } - ZERO_STRUCTP(sock); - sock->sock = NULL; - sock->port = 0; - - /* 20 second default timeout */ - sock->timeout = 20000; - sock->hostname = NULL; + sock->event.ctx = event_context_init(sock); + if (sock->event.ctx == NULL) { + talloc_free(sock); + return NULL; + } return sock; } +static NTSTATUS smbcli_sock_connect_one(struct smbcli_socket *sock, + const char *hostaddr, int port); + /* - connect a smbcli_socket context to an IP/port pair - if port is 0 then choose 445 then 139 + handle socket write events during an async connect. These happen when the OS + has either completed the connect() or has returned an error */ -BOOL smbcli_sock_connect(struct smbcli_socket *sock, struct ipv4_addr *ip, int port) +static void smbcli_sock_connect_handler(struct event_context *ev, struct fd_event *fde, + struct timeval t, uint16_t flags) { - NTSTATUS status; + struct smbcli_composite *c = fde->private; + struct clisocket_connect *conn = c->private; + 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); + c->state = SMBCLI_REQUEST_DONE; + if (c->async.fn) { + c->async.fn(c); + } + return; + } - if (port == 0) { - int i; - const char **ports = lp_smb_ports(); - for (i=0;ports[i];i++) { - port = atoi(ports[i]); - if (port != 0 && smbcli_sock_connect(sock, ip, port)) { - return True; + /* that port failed - try the next port */ + for (i=c->stage+1;conn->iports[i];i++) { + c->stage = i; + c->status = smbcli_sock_connect_one(conn->sock, + conn->dest_host, + conn->iports[i]); + if (NT_STATUS_EQUAL(c->status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { + conn->sock->event.fde->private = c; + return; + } + if (NT_STATUS_IS_OK(c->status)) { + c->state = SMBCLI_REQUEST_DONE; + if (c->async.fn) { + c->async.fn(c); } + return; } - return False; } - status = socket_create("ip", SOCKET_TYPE_STREAM, &sock->sock, 0); - if (!NT_STATUS_IS_OK(status)) { - return False; + c->state = SMBCLI_REQUEST_ERROR; + if (c->async.fn) { + c->async.fn(c); } - talloc_steal(sock, sock->sock); +} - status = socket_connect(sock->sock, NULL, 0, sys_inet_ntoa(*ip), port, 0); - if (!NT_STATUS_IS_OK(status)) { + +/* + try to connect to the given address/port +*/ +static NTSTATUS smbcli_sock_connect_one(struct smbcli_socket *sock, + const char *hostaddr, int port) +{ + struct fd_event fde; + NTSTATUS status; + + if (sock->sock) { talloc_free(sock->sock); sock->sock = NULL; - return False; } - sock->dest_ip = *ip; + if (sock->event.fde) { + event_remove_fd(sock->event.ctx, sock->event.fde); + sock->event.fde = NULL; + } + + status = socket_create("ip", SOCKET_TYPE_STREAM, &sock->sock, 0); + if (!NT_STATUS_IS_OK(status)) { + return status; + } + + talloc_steal(sock, sock->sock); + + /* we initially look for write - see the man page on + non-blocking connect */ + fde.fd = socket_get_fd(sock->sock); + fde.flags = EVENT_FD_WRITE; + fde.handler = smbcli_sock_connect_handler; + fde.private = sock; + + sock->event.fde = event_add_fd(sock->event.ctx, &fde); sock->port = port; + set_blocking(fde.fd, False); + + return socket_connect(sock->sock, NULL, 0, hostaddr, port, 0); +} + - socket_set_option(sock->sock, lp_socket_options(), NULL); +/* + connect a smbcli_socket context to an IP/port pair + if port is 0 then choose 445 then 139 + + this is the async send side of the interface +*/ +struct smbcli_composite *smbcli_sock_connect_send(struct smbcli_socket *sock, + struct ipv4_addr *ip, int port) +{ + struct smbcli_composite *c; + struct clisocket_connect *conn; + int i; + + c = talloc_zero(sock, struct smbcli_composite); + if (c == NULL) return NULL; + + c->event_ctx = sock->event.ctx; + + conn = talloc(c, struct clisocket_connect); + if (conn == NULL) goto failed; + + conn->sock = sock; + + /* work out what ports we will try */ + if (port == 0) { + const char **ports = lp_smb_ports(); + for (i=0;ports[i];i++) /* noop */ ; + conn->iports = talloc_array(c, int, i+1); + if (conn->iports == NULL) goto failed; + for (i=0;ports[i];i++) { + conn->iports[i] = atoi(ports[i]); + } + conn->iports[i] = 0; + } else { + conn->iports = talloc_array(c, int, 2); + if (conn->iports == NULL) goto failed; + conn->iports[0] = port; + conn->iports[1] = 0; + } - return True; + conn->dest_host = talloc_strdup(c, sys_inet_ntoa(*ip)); + if (conn->dest_host == NULL) goto failed; + + c->private = conn; + c->state = SMBCLI_REQUEST_SEND; + + /* startup the connect process for each port in turn until one + succeeds or tells us that it is pending */ + for (i=0;conn->iports[i];i++) { + c->stage = i; + conn->sock->port = conn->iports[i]; + c->status = smbcli_sock_connect_one(sock, + conn->dest_host, + conn->iports[i]); + if (NT_STATUS_EQUAL(c->status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { + sock->event.fde->private = c; + return c; + } + if (NT_STATUS_IS_OK(c->status)) { + c->state = SMBCLI_REQUEST_DONE; + return c; + } + } + + c->state = SMBCLI_REQUEST_ERROR; + return c; + +failed: + talloc_free(c); + return NULL; +} + +/* + finish a smbcli_sock_connect_send() operation +*/ +NTSTATUS smbcli_sock_connect_recv(struct smbcli_composite *c) +{ + NTSTATUS status; + status = smb_composite_wait(c); + talloc_free(c); + return status; +} + +/* + connect a smbcli_socket context to an IP/port pair + if port is 0 then choose the ports listed in smb.conf (normally 445 then 139) + + sync version of the function +*/ +NTSTATUS smbcli_sock_connect(struct smbcli_socket *sock, struct ipv4_addr *ip, int port) +{ + struct smbcli_composite *c; + + c = smbcli_sock_connect_send(sock, ip, port); + if (c == NULL) { + return NT_STATUS_NO_MEMORY; + } + + return smbcli_sock_connect_recv(c); } @@ -153,6 +314,7 @@ ssize_t smbcli_sock_read(struct smbcli_socket *sock, uint8_t *data, size_t len) return nread; } + /**************************************************************************** resolve a hostname and connect ****************************************************************************/ @@ -161,14 +323,7 @@ BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, in int name_type = 0x20; struct ipv4_addr ip; char *name, *p; - BOOL ret; - -#if 0 - if (getenv("LIBSMB_PROG")) { - sock->fd = sock_exec(getenv("LIBSMB_PROG")); - return sock->fd != -1; - } -#endif + NTSTATUS status; name = talloc_strdup(sock, host); @@ -179,17 +334,12 @@ BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, in } if (!resolve_name(name, name, &ip, name_type)) { - talloc_free(name); return False; } - ret = smbcli_sock_connect(sock, &ip, port); + sock->hostname = name; - if (ret) { - sock->hostname = talloc_steal(sock, name); - } else { - talloc_free(name); - } + status = smbcli_sock_connect(sock, &ip, port); - return ret; + return NT_STATUS_IS_OK(status); } diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 63ff1e4409..855543d670 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -53,8 +53,8 @@ static int transport_destructor(void *ptr) struct smbcli_transport *transport = ptr; smbcli_transport_dead(transport); - event_remove_fd(transport->event.ctx, transport->event.fde); - event_remove_timed(transport->event.ctx, transport->event.te); + event_remove_fd(transport->socket->event.ctx, transport->socket->event.fde); + event_remove_timed(transport->socket->event.ctx, transport->socket->event.te); return 0; } @@ -64,19 +64,12 @@ static int transport_destructor(void *ptr) struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock) { struct smbcli_transport *transport; - struct fd_event fde; transport = talloc_p(sock, struct smbcli_transport); if (!transport) return NULL; ZERO_STRUCTP(transport); - transport->event.ctx = event_context_init(transport); - if (transport->event.ctx == NULL) { - talloc_free(transport); - return NULL; - } - transport->socket = talloc_reference(transport, sock); transport->negotiate.protocol = PROTOCOL_NT1; transport->options.use_spnego = lp_use_spnego(); @@ -89,13 +82,11 @@ struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock) ZERO_STRUCT(transport->called); - fde.fd = socket_get_fd(sock->sock); - fde.flags = EVENT_FD_READ; - fde.handler = smbcli_transport_event_handler; - fde.private = transport; - fde.ref_count = 1; - - transport->event.fde = event_add_fd(transport->event.ctx, &fde); + /* take over event handling from the socket layer - it only + handles events up until we are connected */ + transport->socket->event.fde->handler = smbcli_transport_event_handler; + transport->socket->event.fde->private = transport; + transport->socket->event.fde->flags = EVENT_FD_READ; talloc_set_destructor(transport, transport_destructor); @@ -138,7 +129,7 @@ void smbcli_transport_dead(struct smbcli_transport *transport) */ static void smbcli_transport_write_enable(struct smbcli_transport *transport) { - transport->event.fde->flags |= EVENT_FD_WRITE; + transport->socket->event.fde->flags |= EVENT_FD_WRITE; } /* @@ -146,7 +137,7 @@ static void smbcli_transport_write_enable(struct smbcli_transport *transport) */ static void smbcli_transport_write_disable(struct smbcli_transport *transport) { - transport->event.fde->flags &= ~EVENT_FD_WRITE; + transport->socket->event.fde->flags &= ~EVENT_FD_WRITE; } /**************************************************************************** @@ -254,14 +245,14 @@ void smbcli_transport_idle_handler(struct smbcli_transport *transport, transport->idle.private = private; transport->idle.period = period; - if (transport->event.te != NULL) { - event_remove_timed(transport->event.ctx, transport->event.te); + if (transport->socket->event.te != NULL) { + event_remove_timed(transport->socket->event.ctx, transport->socket->event.te); } te.next_event = timeval_current_ofs(0, period); te.handler = idle_handler; te.private = transport; - transport->event.te = event_add_timed(transport->event.ctx, &te); + transport->socket->event.te = event_add_timed(transport->socket->event.ctx, &te); } /* diff --git a/source4/libcli/raw/libcliraw.h b/source4/libcli/raw/libcliraw.h index 51b50fdcb9..4047a5d369 100644 --- a/source4/libcli/raw/libcliraw.h +++ b/source4/libcli/raw/libcliraw.h @@ -61,24 +61,20 @@ struct smbcli_negotiate { /* this is the context for a SMB socket associated with the socket itself */ struct smbcli_socket { - struct ipv4_addr dest_ip; - /* dest hostname (which may or may not be a DNS name) */ - char *hostname; + struct socket_context *sock; - /* the port used */ + /* what port we ended up connected to */ int port; - - struct socket_context *sock; - /* a count of the number of packets we have received. We - * actually only care about zero/non-zero at this stage */ - uint_t pkt_count; + /* the hostname we connected to */ + const char *hostname; - /* the network address of the client */ - char *client_addr; - - /* timeout for socket operations in milliseconds. */ - int timeout; + /* the event handle for waiting for socket IO */ + struct { + struct event_context *ctx; + struct fd_event *fde; + struct timed_event *te; + } event; }; /* @@ -164,13 +160,6 @@ struct smbcli_transport { size_t received; uint8_t *buffer; } recv_buffer; - - /* the event handle for waiting for socket IO */ - struct { - struct event_context *ctx; - struct fd_event *fde; - struct timed_event *te; - } event; }; /* this is the context for the user */ diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 8093b298bb..7fb12dcf80 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -333,7 +333,7 @@ BOOL smbcli_request_receive(struct smbcli_request *req) /* keep receiving packets until this one is replied to */ while (req->state <= SMBCLI_REQUEST_RECV) { - if (event_loop_once(req->transport->event.ctx) != 0) { + if (event_loop_once(req->transport->socket->event.ctx) != 0) { return False; } } -- cgit From 61a3d370b98ca4b75cd61e22f0d6b0f3fb7561b3 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 15 Jan 2005 11:58:52 +0000 Subject: r4758: - added async support to the session request code - added async support to the negprot client code - removed two unused parameters from smbcli_full_connection() code - converted smbclient to use smbcli_full_connection() rather than reinventing everything itself (This used to be commit 71cbe2873473e039b4511511302cb63f1c50bce8) --- source4/libcli/raw/clisession.c | 4 +-- source4/libcli/raw/clitransport.c | 61 ++++++++++++++++++++++++++++----------- source4/libcli/raw/clitree.c | 14 +++++---- source4/libcli/raw/rawnegotiate.c | 36 ++++++++++++++--------- 4 files changed, 75 insertions(+), 40 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index dcc0c8adbe..322d27688e 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -38,16 +38,14 @@ struct smbcli_session *smbcli_session_init(struct smbcli_transport *transport) uint16_t flags2; uint32_t capabilities; - session = talloc_p(transport, struct smbcli_session); + session = talloc_zero(transport, struct smbcli_session); if (!session) { return NULL; } - ZERO_STRUCTP(session); session->transport = talloc_reference(session, transport); session->pid = (uint16_t)getpid(); session->vuid = UID_FIELD_INVALID; - capabilities = transport->negotiate.capabilities; diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 855543d670..fc9de577ee 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -140,12 +140,12 @@ static void smbcli_transport_write_disable(struct smbcli_transport *transport) transport->socket->event.fde->flags &= ~EVENT_FD_WRITE; } -/**************************************************************************** -send a session request (if appropriate) -****************************************************************************/ -BOOL smbcli_transport_connect(struct smbcli_transport *transport, - struct nmb_name *calling, - struct nmb_name *called) +/* + send a session request +*/ +struct smbcli_request *smbcli_transport_connect_send(struct smbcli_transport *transport, + struct nmb_name *calling, + struct nmb_name *called) { uint8_t *p; int len = NBT_HDR_SIZE; @@ -155,13 +155,10 @@ BOOL smbcli_transport_connect(struct smbcli_transport *transport, transport->called = *called; } - /* 445 doesn't have session request */ - if (transport->socket->port == 445) { - return True; - } - /* allocate output buffer */ - req = smbcli_request_setup_nonsmb(transport, NBT_HDR_SIZE + 2*nbt_mangled_name_len()); + req = smbcli_request_setup_nonsmb(transport, + NBT_HDR_SIZE + 2*nbt_mangled_name_len()); + if (req == NULL) return NULL; /* put in the destination name */ p = req->out.buffer + NBT_HDR_SIZE; @@ -176,15 +173,27 @@ BOOL smbcli_transport_connect(struct smbcli_transport *transport, _smb_setlen(req->out.buffer,len-4); SCVAL(req->out.buffer,0,0x81); - if (!smbcli_request_send(req) || - !smbcli_request_receive(req)) { + if (!smbcli_request_send(req)) { + smbcli_request_destroy(req); + return NULL; + } + + return req; +} + +/* + finish a smbcli_transport_connect() +*/ +BOOL smbcli_transport_connect_recv(struct smbcli_request *req) +{ + if (!smbcli_request_receive(req)) { smbcli_request_destroy(req); return False; } - + if (CVAL(req->in.buffer,0) != 0x82) { - transport->error.etype = ETYPE_NBT; - transport->error.e.nbt_error = CVAL(req->in.buffer,4); + req->transport->error.etype = ETYPE_NBT; + req->transport->error.e.nbt_error = CVAL(req->in.buffer,4); smbcli_request_destroy(req); return False; } @@ -194,6 +203,24 @@ BOOL smbcli_transport_connect(struct smbcli_transport *transport, } +/* + send a session request (if needed) +*/ +BOOL smbcli_transport_connect(struct smbcli_transport *transport, + struct nmb_name *calling, + struct nmb_name *called) +{ + struct smbcli_request *req; + + if (transport->socket->port == 445) { + return True; + } + + req = smbcli_transport_connect_send(transport, + calling, called); + return smbcli_transport_connect_recv(req); +} + /**************************************************************************** get next mid in sequence ****************************************************************************/ diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index 0f56c0fe2e..cc7fefd084 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -34,12 +34,11 @@ struct smbcli_tree *smbcli_tree_init(struct smbcli_session *session) { struct smbcli_tree *tree; - tree = talloc_p(session, struct smbcli_tree); + tree = talloc_zero(session, struct smbcli_tree); if (!tree) { return NULL; } - ZERO_STRUCTP(tree); tree->session = talloc_reference(tree, session); return tree; @@ -48,7 +47,8 @@ struct smbcli_tree *smbcli_tree_init(struct smbcli_session *session) /**************************************************************************** Send a tconX (async send) ****************************************************************************/ -struct smbcli_request *smb_tree_connect_send(struct smbcli_tree *tree, union smb_tcon *parms) +struct smbcli_request *smb_tree_connect_send(struct smbcli_tree *tree, + union smb_tcon *parms) { struct smbcli_request *req = NULL; @@ -83,7 +83,8 @@ struct smbcli_request *smb_tree_connect_send(struct smbcli_tree *tree, union smb /**************************************************************************** Send a tconX (async recv) ****************************************************************************/ -NTSTATUS smb_tree_connect_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, union smb_tcon *parms) +NTSTATUS smb_tree_connect_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, + union smb_tcon *parms) { uint8_t *p; @@ -124,7 +125,8 @@ failed: /**************************************************************************** Send a tconX (sync interface) ****************************************************************************/ -NTSTATUS smb_tree_connect(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_tcon *parms) +NTSTATUS smb_tree_connect(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, + union smb_tcon *parms) { struct smbcli_request *req = smb_tree_connect_send(tree, parms); return smb_tree_connect_recv(req, mem_ctx, parms); @@ -203,7 +205,7 @@ NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx, /* negotiate protocol options with the server */ - status = smb_raw_negotiate(transport); + status = smb_raw_negotiate(transport, lp_maxprotocol()); if (!NT_STATUS_IS_OK(status)) { talloc_free(transport); return status; diff --git a/source4/libcli/raw/rawnegotiate.c b/source4/libcli/raw/rawnegotiate.c index a8cf603d46..d2d6b66d59 100644 --- a/source4/libcli/raw/rawnegotiate.c +++ b/source4/libcli/raw/rawnegotiate.c @@ -1,7 +1,9 @@ /* Unix SMB/CIFS implementation. + SMB client negotiate context management functions - Copyright (C) Andrew Tridgell 1994-1998 + + Copyright (C) Andrew Tridgell 1994-2005 Copyright (C) James Myers 2003 This program is free software; you can redistribute it and/or modify @@ -40,10 +42,11 @@ static const struct { {PROTOCOL_NT1,"NT LM 0.12"}, }; -/**************************************************************************** - Send a negprot command. -****************************************************************************/ -struct smbcli_request *smb_negprot_send(struct smbcli_transport *transport, int maxprotocol) +/* + Send a negprot command. +*/ +struct smbcli_request *smb_raw_negotiate_send(struct smbcli_transport *transport, + int maxprotocol) { struct smbcli_request *req; int i; @@ -82,19 +85,14 @@ struct smbcli_request *smb_negprot_send(struct smbcli_transport *transport, int return req; } -/**************************************************************************** +/* Send a negprot command. -****************************************************************************/ -NTSTATUS smb_raw_negotiate(struct smbcli_transport *transport) +*/ +NTSTATUS smb_raw_negotiate_recv(struct smbcli_request *req) { - struct smbcli_request *req; + struct smbcli_transport *transport = req->transport; int protocol; - req = smb_negprot_send(transport, lp_maxprotocol()); - if (!req) { - return NT_STATUS_UNSUCCESSFUL; - } - if (!smbcli_request_receive(req) || smbcli_request_is_error(req)) { return smbcli_request_destroy(req); @@ -183,3 +181,13 @@ NTSTATUS smb_raw_negotiate(struct smbcli_transport *transport) failed: return smbcli_request_destroy(req); } + + +/* + Send a negprot command (sync interface) +*/ +NTSTATUS smb_raw_negotiate(struct smbcli_transport *transport, int maxprotocol) +{ + struct smbcli_request *req = smb_raw_negotiate_send(transport, maxprotocol); + return smb_raw_negotiate_recv(req); +} -- cgit From 8ea26bf2fdad4440d65b020943e19128c34c4ed9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 16 Jan 2005 01:21:18 +0000 Subject: r4765: simplify the async socket code to always go via the event handler rather than short-circuiting in the unlikely event the OS returns an immediate success on a non-blocking connect (This used to be commit db4380717041485e216f965103f9e803518b45c3) --- source4/libcli/raw/clisocket.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index d20dc4bf25..851cf67caa 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -85,17 +85,11 @@ static void smbcli_sock_connect_handler(struct event_context *ev, struct fd_even c->status = smbcli_sock_connect_one(conn->sock, conn->dest_host, conn->iports[i]); - if (NT_STATUS_EQUAL(c->status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { + if (NT_STATUS_IS_OK(c->status) || + NT_STATUS_EQUAL(c->status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { conn->sock->event.fde->private = c; return; } - if (NT_STATUS_IS_OK(c->status)) { - c->state = SMBCLI_REQUEST_DONE; - if (c->async.fn) { - c->async.fn(c); - } - return; - } } c->state = SMBCLI_REQUEST_ERROR; @@ -153,7 +147,7 @@ static NTSTATUS smbcli_sock_connect_one(struct smbcli_socket *sock, this is the async send side of the interface */ struct smbcli_composite *smbcli_sock_connect_send(struct smbcli_socket *sock, - struct ipv4_addr *ip, int port) + const char *host_addr, int port) { struct smbcli_composite *c; struct clisocket_connect *conn; @@ -186,7 +180,7 @@ struct smbcli_composite *smbcli_sock_connect_send(struct smbcli_socket *sock, conn->iports[1] = 0; } - conn->dest_host = talloc_strdup(c, sys_inet_ntoa(*ip)); + conn->dest_host = talloc_strdup(c, host_addr); if (conn->dest_host == NULL) goto failed; c->private = conn; @@ -200,14 +194,11 @@ struct smbcli_composite *smbcli_sock_connect_send(struct smbcli_socket *sock, c->status = smbcli_sock_connect_one(sock, conn->dest_host, conn->iports[i]); - if (NT_STATUS_EQUAL(c->status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { + if (NT_STATUS_IS_OK(c->status) || + NT_STATUS_EQUAL(c->status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { sock->event.fde->private = c; return c; } - if (NT_STATUS_IS_OK(c->status)) { - c->state = SMBCLI_REQUEST_DONE; - return c; - } } c->state = SMBCLI_REQUEST_ERROR; @@ -235,11 +226,11 @@ NTSTATUS smbcli_sock_connect_recv(struct smbcli_composite *c) sync version of the function */ -NTSTATUS smbcli_sock_connect(struct smbcli_socket *sock, struct ipv4_addr *ip, int port) +NTSTATUS smbcli_sock_connect(struct smbcli_socket *sock, const char *host_addr, int port) { struct smbcli_composite *c; - c = smbcli_sock_connect_send(sock, ip, port); + c = smbcli_sock_connect_send(sock, host_addr, port); if (c == NULL) { return NT_STATUS_NO_MEMORY; } @@ -339,7 +330,7 @@ BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, in sock->hostname = name; - status = smbcli_sock_connect(sock, &ip, port); + status = smbcli_sock_connect(sock, sys_inet_ntoa(ip), port); return NT_STATUS_IS_OK(status); } -- cgit From eec22cfe2fe8cf46190761369016382a274426c6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 16 Jan 2005 01:22:08 +0000 Subject: r4767: handle the different NBT session request refusals, and map them to reasonable NT_STATUS values (This used to be commit b193a9cb0c851a4ec55ad9956a815be93eea35e4) --- source4/libcli/raw/clitransport.c | 51 +++++++++++++++++++++++++++++++-------- 1 file changed, 41 insertions(+), 10 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index fc9de577ee..14c0779968 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -181,25 +181,54 @@ struct smbcli_request *smbcli_transport_connect_send(struct smbcli_transport *tr return req; } +/* + map a session request error to a NTSTATUS + */ +static NTSTATUS map_session_refused_error(uint8_t error) +{ + switch (error) { + case 0x80: + case 0x81: + return NT_STATUS_REMOTE_NOT_LISTENING; + case 0x82: + return NT_STATUS_RESOURCE_NAME_NOT_FOUND; + case 0x83: + return NT_STATUS_REMOTE_RESOURCES; + } + return NT_STATUS_UNEXPECTED_IO_ERROR; +} + + /* finish a smbcli_transport_connect() */ -BOOL smbcli_transport_connect_recv(struct smbcli_request *req) +NTSTATUS smbcli_transport_connect_recv(struct smbcli_request *req) { + NTSTATUS status; + if (!smbcli_request_receive(req)) { smbcli_request_destroy(req); - return False; + return NT_STATUS_UNEXPECTED_NETWORK_ERROR; } - if (CVAL(req->in.buffer,0) != 0x82) { - req->transport->error.etype = ETYPE_NBT; - req->transport->error.e.nbt_error = CVAL(req->in.buffer,4); - smbcli_request_destroy(req); - return False; + switch (CVAL(req->in.buffer,0)) { + case 0x82: + status = NT_STATUS_OK; + break; + case 0x83: + status = map_session_refused_error(CVAL(req->in.buffer,4)); + break; + case 0x84: + DEBUG(1,("Warning: session retarget not supported\n")); + status = NT_STATUS_NOT_SUPPORTED; + break; + default: + status = NT_STATUS_UNEXPECTED_IO_ERROR; + break; } smbcli_request_destroy(req); - return True; + return status; } @@ -211,14 +240,16 @@ BOOL smbcli_transport_connect(struct smbcli_transport *transport, struct nmb_name *called) { struct smbcli_request *req; - + NTSTATUS status; + if (transport->socket->port == 445) { return True; } req = smbcli_transport_connect_send(transport, calling, called); - return smbcli_transport_connect_recv(req); + status = smbcli_transport_connect_recv(req); + return NT_STATUS_IS_OK(status); } /**************************************************************************** -- cgit From 1e776edfc546f01341f153daa80e4155e5ff9855 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 16 Jan 2005 01:28:11 +0000 Subject: r4769: added a smb_composite_connect() function that provides a simple async interface to a complete SMB connection setup. Internally it does: - socket connection - session request (if needed) - negprot - session setup - tcon This is the first example of a composite function that builds on other composite components (the socket connection is a composite function, which is used as a building block for this function). I think this will be quite common in composite functions in the future, building up ever more complex composite functions from smaller building blocks, while hiding the details from the caller. There are two things missing from this now. The first is async name resolution routines (wins, bcast, DNS etc), and the second is that this code currently only does a NT1 style session setup. I'll work on adding spnego and old style session setup support next. (This used to be commit 6bc9e17f5c5236f662c7c8f308d03e6d97379b23) --- source4/libcli/raw/clisession.c | 6 +++--- source4/libcli/raw/clitree.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+), 3 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index 322d27688e..46236217ea 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -256,8 +256,8 @@ void smbcli_session_set_user_session_key(struct smbcli_session *session, /* setup signing for a NT1 style session setup */ -static void use_nt1_session_keys(struct smbcli_session *session, - const char *password, const DATA_BLOB *nt_response) +void smb_session_use_nt1_session_keys(struct smbcli_session *session, + const char *password, const DATA_BLOB *nt_response) { struct smbcli_transport *transport = session->transport; uint8_t nt_hash[16]; @@ -352,7 +352,7 @@ static NTSTATUS smb_raw_session_setup_generic_nt1(struct smbcli_session *session session->transport->negotiate.secblob); s2.nt1.in.password2 = nt_blob(parms->generic.in.password, session->transport->negotiate.secblob); - use_nt1_session_keys(session, parms->generic.in.password, &s2.nt1.in.password2); + smb_session_use_nt1_session_keys(session, parms->generic.in.password, &s2.nt1.in.password2); } else { s2.nt1.in.password1 = data_blob(parms->generic.in.password, diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index cc7fefd084..7339ca07f1 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -21,6 +21,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" +#include "libcli/composite/composite.h" #define SETUP_REQUEST_TREE(cmd, wct, buflen) do { \ req = smbcli_request_setup(tree, cmd, wct, buflen); \ @@ -289,3 +290,36 @@ NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx, *ret_tree = tree; return NT_STATUS_OK; } + + +/* + a convenient function to establish a smbcli_tree from scratch +*/ +NTSTATUS async_smbcli_tree_full_connection(TALLOC_CTX *parent_ctx, + struct smbcli_tree **ret_tree, + const char *my_name, + const char *dest_host, int port, + const char *service, const char *service_type, + const char *user, const char *domain, + const char *password) +{ + struct smb_composite_connect io; + NTSTATUS status; + + io.in.dest_host = dest_host; + io.in.port = port; + io.in.called_name = dest_host; + io.in.calling_name = my_name; + io.in.service = service; + io.in.service_type = service_type; + io.in.user = user; + io.in.domain = domain; + io.in.password = password; + + status = smb_composite_connect(&io, parent_ctx); + if (NT_STATUS_IS_OK(status)) { + *ret_tree = io.out.tree; + } + + return status; +} -- cgit From 7cbc768376ed0a839afca64aeea99cd53d0fbc6f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 16 Jan 2005 11:15:08 +0000 Subject: r4777: added a smb_composite_sesssetup() async composite function. This encapsulates all the different session setup methods, including the multi-pass spnego code. I have hooked this into all the places that previously used the RAW_SESSSETUP_GENERIC method, and have removed the old RAW_SESSSETUP_GENERIC code from clisession.c and clitree.c. A nice side effect is that these two modules are now very simple again, back to being "raw" session setup handling, which was what was originally intended. I have also used this to replace the session setup code in the smb_composite_connect() code, and used that to build a very simple replacement for smbcli_tree_full_connection(). As a result, smbclient, smbtorture and all our other SMB connection code now goes via these composite async functions. That should give them a good workout! (This used to be commit 080d0518bc7d6fd4bc3ef783e7d4d2e3275d0799) --- source4/libcli/raw/clisession.c | 358 +------------------------------------- source4/libcli/raw/clisocket.c | 2 + source4/libcli/raw/clitransport.c | 3 +- source4/libcli/raw/clitree.c | 147 +--------------- 4 files changed, 14 insertions(+), 496 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index 46236217ea..ed50601c25 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -1,7 +1,8 @@ /* Unix SMB/CIFS implementation. SMB client session context management functions - Copyright (C) Andrew Tridgell 1994-1998 + + Copyright (C) Andrew Tridgell 1994-2005 Copyright (C) James Myers 2003 This program is free software; you can redistribute it and/or modify @@ -76,11 +77,7 @@ struct smbcli_request *smb_raw_session_setup_send(struct smbcli_session *session { struct smbcli_request *req = NULL; - switch (parms->generic.level) { - case RAW_SESSSETUP_GENERIC: - /* handled elsewhere */ - return NULL; - + switch (parms->old.level) { case RAW_SESSSETUP_OLD: SETUP_REQUEST_SESSION(SMBsesssetupX, 10, 0); SSVAL(req->out.vwv, VWV(0), SMB_CHAIN_NONE); @@ -164,11 +161,7 @@ NTSTATUS smb_raw_session_setup_recv(struct smbcli_request *req, return smbcli_request_destroy(req); } - switch (parms->generic.level) { - case RAW_SESSSETUP_GENERIC: - /* handled elsewhere */ - return NT_STATUS_INVALID_LEVEL; - + switch (parms->old.level) { case RAW_SESSSETUP_OLD: SMBCLI_CHECK_WCT(req, 3); ZERO_STRUCT(parms->old.out); @@ -220,353 +213,14 @@ failed: return smbcli_request_destroy(req); } -/* - form an encrypted lanman password from a plaintext password - and the server supplied challenge -*/ -static DATA_BLOB lanman_blob(const char *pass, DATA_BLOB challenge) -{ - DATA_BLOB blob = data_blob(NULL, 24); - SMBencrypt(pass, challenge.data, blob.data); - return blob; -} - -/* - form an encrypted NT password from a plaintext password - and the server supplied challenge -*/ -static DATA_BLOB nt_blob(const char *pass, DATA_BLOB challenge) -{ - DATA_BLOB blob = data_blob(NULL, 24); - SMBNTencrypt(pass, challenge.data, blob.data); - return blob; -} - -/* - store the user session key for a transport -*/ -void smbcli_session_set_user_session_key(struct smbcli_session *session, - const DATA_BLOB *session_key) -{ - session->user_session_key = data_blob_talloc(session, - session_key->data, - session_key->length); -} /* - setup signing for a NT1 style session setup -*/ -void smb_session_use_nt1_session_keys(struct smbcli_session *session, - const char *password, const DATA_BLOB *nt_response) -{ - struct smbcli_transport *transport = session->transport; - uint8_t nt_hash[16]; - DATA_BLOB session_key = data_blob(NULL, 16); - - E_md4hash(password, nt_hash); - SMBsesskeygen_ntv1(nt_hash, session_key.data); - - smbcli_transport_simple_set_signing(transport, session_key, *nt_response); - - smbcli_session_set_user_session_key(session, &session_key); - data_blob_free(&session_key); -} - -/**************************************************************************** - Perform a session setup (sync interface) using generic interface and the old - style sesssetup call -****************************************************************************/ -static NTSTATUS smb_raw_session_setup_generic_old(struct smbcli_session *session, - TALLOC_CTX *mem_ctx, - union smb_sesssetup *parms) -{ - NTSTATUS status; - union smb_sesssetup s2; - - /* use the old interface */ - s2.generic.level = RAW_SESSSETUP_OLD; - s2.old.in.bufsize = session->transport->options.max_xmit; - s2.old.in.mpx_max = session->transport->options.max_mux; - s2.old.in.vc_num = 1; - s2.old.in.sesskey = parms->generic.in.sesskey; - s2.old.in.domain = parms->generic.in.domain; - s2.old.in.user = parms->generic.in.user; - s2.old.in.os = "Unix"; - s2.old.in.lanman = "Samba"; - - if (!parms->generic.in.password) { - s2.old.in.password = data_blob(NULL, 0); - } else if (session->transport->negotiate.sec_mode & - NEGOTIATE_SECURITY_CHALLENGE_RESPONSE) { - s2.old.in.password = lanman_blob(parms->generic.in.password, - session->transport->negotiate.secblob); - } else { - s2.old.in.password = data_blob(parms->generic.in.password, - strlen(parms->generic.in.password)); - } - - status = smb_raw_session_setup(session, mem_ctx, &s2); - - data_blob_free(&s2.old.in.password); - - if (!NT_STATUS_IS_OK(status)) { - return status; - } - - parms->generic.out.vuid = s2.old.out.vuid; - parms->generic.out.os = s2.old.out.os; - parms->generic.out.lanman = s2.old.out.lanman; - parms->generic.out.domain = s2.old.out.domain; - - return NT_STATUS_OK; -} - -/**************************************************************************** - Perform a session setup (sync interface) using generic interface and the NT1 - style sesssetup call -****************************************************************************/ -static NTSTATUS smb_raw_session_setup_generic_nt1(struct smbcli_session *session, - TALLOC_CTX *mem_ctx, - union smb_sesssetup *parms) -{ - NTSTATUS status; - union smb_sesssetup s2; - - s2.generic.level = RAW_SESSSETUP_NT1; - s2.nt1.in.bufsize = session->transport->options.max_xmit; - s2.nt1.in.mpx_max = session->transport->options.max_mux; - s2.nt1.in.vc_num = 1; - s2.nt1.in.sesskey = parms->generic.in.sesskey; - s2.nt1.in.capabilities = parms->generic.in.capabilities; - s2.nt1.in.domain = parms->generic.in.domain; - s2.nt1.in.user = parms->generic.in.user; - s2.nt1.in.os = "Unix"; - s2.nt1.in.lanman = "Samba"; - - if (!parms->generic.in.password) { - s2.nt1.in.password1 = data_blob(NULL, 0); - s2.nt1.in.password2 = data_blob(NULL, 0); - } else if (session->transport->negotiate.sec_mode & - NEGOTIATE_SECURITY_CHALLENGE_RESPONSE) { - s2.nt1.in.password1 = lanman_blob(parms->generic.in.password, - session->transport->negotiate.secblob); - s2.nt1.in.password2 = nt_blob(parms->generic.in.password, - session->transport->negotiate.secblob); - smb_session_use_nt1_session_keys(session, parms->generic.in.password, &s2.nt1.in.password2); - - } else { - s2.nt1.in.password1 = data_blob(parms->generic.in.password, - strlen(parms->generic.in.password)); - s2.nt1.in.password2 = data_blob(NULL, 0); - } - - status = smb_raw_session_setup(session, mem_ctx, &s2); - - data_blob_free(&s2.nt1.in.password1); - data_blob_free(&s2.nt1.in.password2); - - if (!NT_STATUS_IS_OK(status)) { - return status; - } - - parms->generic.out.vuid = s2.nt1.out.vuid; - parms->generic.out.os = s2.nt1.out.os; - parms->generic.out.lanman = s2.nt1.out.lanman; - parms->generic.out.domain = s2.nt1.out.domain; - - return NT_STATUS_OK; -} - -/**************************************************************************** - Perform a session setup (sync interface) using generic interface and the SPNEGO - style sesssetup call -****************************************************************************/ -static NTSTATUS smb_raw_session_setup_generic_spnego(struct smbcli_session *session, - TALLOC_CTX *mem_ctx, - union smb_sesssetup *parms) -{ - NTSTATUS status; - NTSTATUS session_key_err = NT_STATUS_NO_USER_SESSION_KEY; - union smb_sesssetup s2; - DATA_BLOB session_key = data_blob(NULL, 0); - DATA_BLOB null_data_blob = data_blob(NULL, 0); - const char *chosen_oid = NULL; - - s2.generic.level = RAW_SESSSETUP_SPNEGO; - s2.spnego.in.bufsize = session->transport->options.max_xmit; - s2.spnego.in.mpx_max = session->transport->options.max_mux; - s2.spnego.in.vc_num = 1; - s2.spnego.in.sesskey = parms->generic.in.sesskey; - s2.spnego.in.capabilities = parms->generic.in.capabilities; - s2.spnego.in.domain = parms->generic.in.domain; - s2.spnego.in.os = "Unix"; - s2.spnego.in.lanman = "Samba"; - s2.spnego.out.vuid = session->vuid; - - smbcli_temp_set_signing(session->transport); - - status = gensec_client_start(session, &session->gensec); - if (!NT_STATUS_IS_OK(status)) { - DEBUG(1, ("Failed to start GENSEC client mode: %s\n", nt_errstr(status))); - return status; - } - - gensec_want_feature(session->gensec, GENSEC_FEATURE_SESSION_KEY); - - status = gensec_set_domain(session->gensec, parms->generic.in.domain); - if (!NT_STATUS_IS_OK(status)) { - DEBUG(1, ("Failed to start set GENSEC client domain to %s: %s\n", - parms->generic.in.domain, nt_errstr(status))); - goto done; - } - - status = gensec_set_username(session->gensec, parms->generic.in.user); - if (!NT_STATUS_IS_OK(status)) { - DEBUG(1, ("Failed to start set GENSEC client username to %s: %s\n", - parms->generic.in.user, nt_errstr(status))); - goto done; - } - - status = gensec_set_password(session->gensec, parms->generic.in.password); - if (!NT_STATUS_IS_OK(status)) { - DEBUG(1, ("Failed to start set GENSEC client password: %s\n", - nt_errstr(status))); - goto done; - } - - status = gensec_set_target_hostname(session->gensec, session->transport->socket->hostname); - if (!NT_STATUS_IS_OK(status)) { - DEBUG(1, ("Failed to start set GENSEC target hostname: %s\n", - nt_errstr(status))); - goto done; - } - - if (session->transport->negotiate.secblob.length) { - chosen_oid = GENSEC_OID_SPNEGO; - } else { - /* without a sec blob, means raw NTLMSSP */ - chosen_oid = GENSEC_OID_NTLMSSP; - } - - status = gensec_start_mech_by_oid(session->gensec, chosen_oid); - if (!NT_STATUS_IS_OK(status)) { - DEBUG(1, ("Failed to start set GENSEC client SPNEGO mechanism %s: %s\n", - gensec_get_name_by_oid(chosen_oid), nt_errstr(status))); - goto done; - } - - status = gensec_update(session->gensec, mem_ctx, - session->transport->negotiate.secblob, - &s2.spnego.in.secblob); - - while(1) { - if (!NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED) && !NT_STATUS_IS_OK(status)) { - break; - } - - if (!NT_STATUS_IS_OK(session_key_err)) { - session_key_err = gensec_session_key(session->gensec, &session_key); - } - if (NT_STATUS_IS_OK(session_key_err)) { - smbcli_transport_simple_set_signing(session->transport, session_key, null_data_blob); - } - - if (NT_STATUS_IS_OK(status) && s2.spnego.in.secblob.length == 0) { - break; - } - - session->vuid = s2.spnego.out.vuid; - status = smb_raw_session_setup(session, mem_ctx, &s2); - session->vuid = UID_FIELD_INVALID; - if (!NT_STATUS_IS_OK(status) && - !NT_STATUS_EQUAL(status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { - break; - } - - status = gensec_update(session->gensec, mem_ctx, - s2.spnego.out.secblob, - &s2.spnego.in.secblob); - - } - -done: - if (NT_STATUS_IS_OK(status)) { - if (!NT_STATUS_IS_OK(session_key_err)) { - DEBUG(1, ("Failed to get user session key: %s\n", nt_errstr(session_key_err))); - return session_key_err; - } - - smbcli_session_set_user_session_key(session, &session_key); - - parms->generic.out.vuid = s2.spnego.out.vuid; - parms->generic.out.os = s2.spnego.out.os; - parms->generic.out.lanman = s2.spnego.out.lanman; - parms->generic.out.domain = s2.spnego.out.domain; - } else { - talloc_free(session->gensec); - session->gensec = NULL; - DEBUG(1, ("Failed to login with %s: %s\n", gensec_get_name_by_oid(chosen_oid), nt_errstr(status))); - return status; - } - - return status; -} - -/**************************************************************************** - Perform a session setup (sync interface) using generic interface -****************************************************************************/ -static NTSTATUS smb_raw_session_setup_generic(struct smbcli_session *session, - TALLOC_CTX *mem_ctx, - union smb_sesssetup *parms) -{ - if (session->transport->negotiate.protocol < PROTOCOL_LANMAN1) { - /* no session setup at all in earliest protocols */ - ZERO_STRUCT(parms->generic.out); - return NT_STATUS_OK; - } - - /* see if we need to use the original session setup interface */ - if (session->transport->negotiate.protocol < PROTOCOL_NT1) { - return smb_raw_session_setup_generic_old(session, mem_ctx, parms); - } - - /* see if we should use the NT1 interface */ - if (!session->transport->options.use_spnego || - !(parms->generic.in.capabilities & CAP_EXTENDED_SECURITY)) { - return smb_raw_session_setup_generic_nt1(session, mem_ctx, parms); - } - - /* default to using SPNEGO/NTLMSSP */ - return smb_raw_session_setup_generic_spnego(session, mem_ctx, parms); -} - - -/**************************************************************************** Perform a session setup (sync interface) -this interface allows for RAW_SESSSETUP_GENERIC to auto-select session -setup variant based on negotiated protocol options -****************************************************************************/ +*/ NTSTATUS smb_raw_session_setup(struct smbcli_session *session, TALLOC_CTX *mem_ctx, union smb_sesssetup *parms) { - struct smbcli_request *req; - - if (parms->generic.level == RAW_SESSSETUP_GENERIC) { - NTSTATUS ret = smb_raw_session_setup_generic(session, mem_ctx, parms); - - if (NT_STATUS_IS_OK(ret) - && parms->generic.in.user - && *parms->generic.in.user) { - if (!session->transport->negotiate.sign_info.doing_signing - && session->transport->negotiate.sign_info.mandatory_signing) { - DEBUG(0, ("SMB signing required, but server does not support it\n")); - return NT_STATUS_ACCESS_DENIED; - } - } - return ret; - } - - req = smb_raw_session_setup_send(session, parms); + struct smbcli_request *req = smb_raw_session_setup_send(session, parms); return smb_raw_session_setup_recv(req, mem_ctx, parms); } diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 851cf67caa..ad1c6a13b8 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -1,5 +1,6 @@ /* Unix SMB/CIFS implementation. + SMB client socket context management functions Copyright (C) Andrew Tridgell 1994-2005 @@ -72,6 +73,7 @@ static void smbcli_sock_connect_handler(struct event_context *ev, struct fd_even 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_host); c->state = SMBCLI_REQUEST_DONE; if (c->async.fn) { c->async.fn(c); diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 14c0779968..55a7e25f72 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -1,7 +1,8 @@ /* Unix SMB/CIFS implementation. SMB client transport context management functions - Copyright (C) Andrew Tridgell 1994-2003 + + Copyright (C) Andrew Tridgell 1994-2005 Copyright (C) James Myers 2003 This program is free software; you can redistribute it and/or modify diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index 7339ca07f1..c6b3fa5ad9 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -1,7 +1,9 @@ /* Unix SMB/CIFS implementation. + SMB client tree context management functions - Copyright (C) Andrew Tridgell 1994-1998 + + Copyright (C) Andrew Tridgell 1994-2005 Copyright (C) James Myers 2003 This program is free software; you can redistribute it and/or modify @@ -152,8 +154,7 @@ NTSTATUS smb_tree_disconnect(struct smbcli_tree *tree) /* - a convenient function to establish a smbcli_tree from scratch, using reasonable default - parameters + a convenient function to establish a smbcli_tree from scratch */ NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx, struct smbcli_tree **ret_tree, @@ -162,146 +163,6 @@ NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx, const char *service, const char *service_type, const char *user, const char *domain, const char *password) -{ - struct smbcli_socket *sock; - struct smbcli_transport *transport; - struct smbcli_session *session; - struct smbcli_tree *tree; - NTSTATUS status; - struct nmb_name calling; - struct nmb_name called; - union smb_sesssetup setup; - union smb_tcon tcon; - TALLOC_CTX *mem_ctx; - char *in_path = NULL; - - *ret_tree = NULL; - - sock = smbcli_sock_init(parent_ctx); - if (!sock) { - return NT_STATUS_NO_MEMORY; - } - - /* open a TCP socket to the server */ - if (!smbcli_sock_connect_byname(sock, dest_host, port)) { - talloc_free(sock); - DEBUG(2,("Failed to establish socket connection - %s\n", strerror(errno))); - return NT_STATUS_UNSUCCESSFUL; - } - - transport = smbcli_transport_init(sock); - talloc_free(sock); - if (!transport) { - return NT_STATUS_NO_MEMORY; - } - - /* send a NBT session request, if applicable */ - make_nmb_name(&calling, my_name, 0x0); - choose_called_name(&called, dest_host, 0x20); - - if (!smbcli_transport_connect(transport, &calling, &called)) { - talloc_free(transport); - return NT_STATUS_UNSUCCESSFUL; - } - - - /* negotiate protocol options with the server */ - status = smb_raw_negotiate(transport, lp_maxprotocol()); - if (!NT_STATUS_IS_OK(status)) { - talloc_free(transport); - return status; - } - - session = smbcli_session_init(transport); - talloc_free(transport); - if (!session) { - return NT_STATUS_NO_MEMORY; - } - - /* prepare a session setup to establish a security context */ - setup.generic.level = RAW_SESSSETUP_GENERIC; - setup.generic.in.sesskey = transport->negotiate.sesskey; - setup.generic.in.capabilities = transport->negotiate.capabilities; - if (!user || !user[0]) { - setup.generic.in.password = NULL; - setup.generic.in.user = ""; - setup.generic.in.domain = ""; - } else { - setup.generic.in.password = password; - setup.generic.in.user = user; - setup.generic.in.domain = domain; - } - - mem_ctx = talloc_init("tcon"); - if (!mem_ctx) { - return NT_STATUS_NO_MEMORY; - } - - status = smb_raw_session_setup(session, mem_ctx, &setup); - if (!NT_STATUS_IS_OK(status)) { - talloc_free(session); - talloc_free(mem_ctx); - return status; - } - - session->vuid = setup.generic.out.vuid; - - tree = smbcli_tree_init(session); - talloc_free(session); - if (!tree) { - talloc_free(mem_ctx); - return NT_STATUS_NO_MEMORY; - } - - /* connect to a share using a tree connect */ - tcon.generic.level = RAW_TCON_TCONX; - tcon.tconx.in.flags = 0; - tcon.tconx.in.password = data_blob(NULL, 0); - asprintf(&in_path, "\\\\%s\\%s", dest_host, service); - tcon.tconx.in.path = in_path; - if (!service_type) { - if (strequal(service, "IPC$")) - service_type = "IPC"; - else - service_type = "?????"; - } - tcon.tconx.in.device = service_type; - - status = smb_tree_connect(tree, mem_ctx, &tcon); - - SAFE_FREE(in_path); - - if (!NT_STATUS_IS_OK(status)) { - talloc_free(tree); - talloc_free(mem_ctx); - return status; - } - - tree->tid = tcon.tconx.out.tid; - if (tcon.tconx.out.dev_type) { - tree->device = talloc_strdup(tree, tcon.tconx.out.dev_type); - } - if (tcon.tconx.out.fs_type) { - tree->fs_type = talloc_strdup(tree, tcon.tconx.out.fs_type); - } - - talloc_free(mem_ctx); - - *ret_tree = tree; - return NT_STATUS_OK; -} - - -/* - a convenient function to establish a smbcli_tree from scratch -*/ -NTSTATUS async_smbcli_tree_full_connection(TALLOC_CTX *parent_ctx, - struct smbcli_tree **ret_tree, - const char *my_name, - const char *dest_host, int port, - const char *service, const char *service_type, - const char *user, const char *domain, - const char *password) { struct smb_composite_connect io; NTSTATUS status; -- cgit From 4a03172e66694b51a24f7b5566f361c1f1767e29 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 16 Jan 2005 23:23:45 +0000 Subject: r4791: used the new talloc type safety macros to make the "void *private" pointers in the composite code type safe. This is a bit of an experiement, I'd be interested in comments on whether we should use this more widely. (This used to be commit 0e1da827b380998355f75f4ef4f424802059c278) --- source4/libcli/raw/clisocket.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index ad1c6a13b8..66555695d3 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -66,8 +66,8 @@ static NTSTATUS smbcli_sock_connect_one(struct smbcli_socket *sock, static void smbcli_sock_connect_handler(struct event_context *ev, struct fd_event *fde, struct timeval t, uint16_t flags) { - struct smbcli_composite *c = fde->private; - struct clisocket_connect *conn = c->private; + struct smbcli_composite *c = talloc_get_type(fde->private, struct smbcli_composite); + struct clisocket_connect *conn = talloc_get_type(c->private, struct clisocket_connect); int i; c->status = socket_connect_complete(conn->sock->sock, 0); -- cgit From c06493912b9a8bb39a3d3459b9597daaa5d1c065 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 17 Jan 2005 22:53:00 +0000 Subject: r4810: fixed anonymous connections with smbclient. Thanks to jbm for pointing this out. (This used to be commit 7da0af98a0e0bc743d3c64be30b37cbc45e00737) --- source4/libcli/raw/clitree.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index c6b3fa5ad9..06963d5bc4 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -173,9 +173,13 @@ NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx, io.in.calling_name = my_name; io.in.service = service; io.in.service_type = service_type; - io.in.user = user; io.in.domain = domain; - io.in.password = password; + io.in.user = user; + if (user && user[0]) { + io.in.password = password; + } else { + io.in.password = NULL; + } status = smb_composite_connect(&io, parent_ctx); if (NT_STATUS_IS_OK(status)) { -- cgit From 196a5ec240c0386aff4f4442c9c44ac7cdd0a494 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 17 Jan 2005 22:53:37 +0000 Subject: r4811: now that the event context is at the socket level, the event cleanup should be there too (This used to be commit 058ae5527e3daeb50eeea9e0ecee858c84e7e17d) --- source4/libcli/raw/clisocket.c | 13 +++++++++++++ source4/libcli/raw/clitransport.c | 1 - 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 66555695d3..0edb95e1a1 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -35,6 +35,17 @@ struct clisocket_connect { const char *dest_host; }; + +static int smbcli_sock_destructor(void *ptr) +{ + struct smbcli_socket *sock = talloc_get_type(ptr, struct smbcli_socket); + + if (sock->event.fde && sock->event.ctx) { + event_remove_fd(sock->event.ctx, sock->event.fde); + } + return 0; +} + /* create a smbcli_socket context */ @@ -53,6 +64,8 @@ struct smbcli_socket *smbcli_sock_init(TALLOC_CTX *mem_ctx) return NULL; } + talloc_set_destructor(sock, smbcli_sock_destructor); + return sock; } diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 55a7e25f72..eb9d2dde78 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -54,7 +54,6 @@ static int transport_destructor(void *ptr) struct smbcli_transport *transport = ptr; smbcli_transport_dead(transport); - event_remove_fd(transport->socket->event.ctx, transport->socket->event.fde); event_remove_timed(transport->socket->event.ctx, transport->socket->event.te); return 0; } -- cgit From ad1c91250e3430a3262de405fbaf9da56e6e2610 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 21 Jan 2005 06:55:33 +0000 Subject: r4886: fixed two places where we process the send side of a socket after the recv side in the same event. That's a bad idea, as the first callback could decide to destroy the socket. (This used to be commit bf74ea34fc0e3c31e220c8f5a9217c95f3ca1d52) --- source4/libcli/raw/clitransport.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index eb9d2dde78..e6d40639c6 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -40,6 +40,7 @@ static void smbcli_transport_event_handler(struct event_context *ev, struct fd_e if (flags & EVENT_FD_READ) { smbcli_transport_process_recv(transport); + return; } if (flags & EVENT_FD_WRITE) { smbcli_transport_process_send(transport); -- cgit From 2383787f199c51cdc202a3cef5822a9fe6b8774c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 21 Jan 2005 11:18:56 +0000 Subject: r4891: - added a generic resolve_name() async interface in libcli/resolve/, which will eventually try all resolution methods setup in smb.conf - only resolution backend at the moment is bcast, which does a parallel broadcast to all configured network interfaces, and takes the first reply that comes in (this nicely demonstrates how to do parallel requests using the async APIs) - converted all the existing code to use the new resolve_name() api - removed all the old nmb code (yay!) (This used to be commit 239c310f255e43dd2d1c2433f666c9faaacbdce3) --- source4/libcli/raw/clisocket.c | 16 ++++++++----- source4/libcli/raw/clitransport.c | 47 ++++++++++++++++++++++++--------------- source4/libcli/raw/libcliraw.h | 3 ++- 3 files changed, 42 insertions(+), 24 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 0edb95e1a1..e981049535 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -326,10 +326,11 @@ resolve a hostname and connect ****************************************************************************/ BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, int port) { - int name_type = 0x20; - struct ipv4_addr ip; - char *name, *p; + int name_type = NBT_NAME_SERVER; + const char *address; NTSTATUS status; + struct nbt_name nbt_name; + char *name, *p; name = talloc_strdup(sock, host); @@ -339,13 +340,18 @@ BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, in *p = 0; } - if (!resolve_name(name, name, &ip, name_type)) { + nbt_name.name = name; + nbt_name.type = name_type; + nbt_name.scope = NULL; + + status = resolve_name(&nbt_name, sock, &address); + if (!NT_STATUS_IS_OK(status)) { return False; } sock->hostname = name; - status = smbcli_sock_connect(sock, sys_inet_ntoa(ip), port); + status = smbcli_sock_connect(sock, address, port); return NT_STATUS_IS_OK(status); } diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index e6d40639c6..918f18fa40 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -145,41 +145,52 @@ static void smbcli_transport_write_disable(struct smbcli_transport *transport) send a session request */ struct smbcli_request *smbcli_transport_connect_send(struct smbcli_transport *transport, - struct nmb_name *calling, - struct nmb_name *called) + struct nbt_name *calling, + struct nbt_name *called) { uint8_t *p; - int len = NBT_HDR_SIZE; struct smbcli_request *req; + DATA_BLOB calling_blob, called_blob; + TALLOC_CTX *tmp_ctx = talloc_new(transport); + NTSTATUS status; - if (called) { - transport->called = *called; - } + status = nbt_name_dup(transport, called, &transport->called); + if (!NT_STATUS_IS_OK(status)) goto failed; + + status = nbt_name_to_blob(tmp_ctx, &calling_blob, calling); + if (!NT_STATUS_IS_OK(status)) goto failed; + + status = nbt_name_to_blob(tmp_ctx, &called_blob, called); + if (!NT_STATUS_IS_OK(status)) goto failed; /* allocate output buffer */ req = smbcli_request_setup_nonsmb(transport, - NBT_HDR_SIZE + 2*nbt_mangled_name_len()); - if (req == NULL) return NULL; + NBT_HDR_SIZE + + calling_blob.length + called_blob.length); + if (req == NULL) goto failed; /* put in the destination name */ p = req->out.buffer + NBT_HDR_SIZE; - name_mangle(called->name, (char *)p, called->name_type); - len += name_len((char *)p); + memcpy(p, called_blob.data, called_blob.length); + p += called_blob.length; - /* and my name */ - p = req->out.buffer+len; - name_mangle(calling->name, (char *)p, calling->name_type); - len += name_len((char *)p); + memcpy(p, calling_blob.data, calling_blob.length); + p += calling_blob.length; - _smb_setlen(req->out.buffer,len-4); + _smb_setlen(req->out.buffer, PTR_DIFF(p, req->out.buffer)-4); SCVAL(req->out.buffer,0,0x81); if (!smbcli_request_send(req)) { smbcli_request_destroy(req); - return NULL; + goto failed; } + talloc_free(tmp_ctx); return req; + +failed: + talloc_free(tmp_ctx); + return NULL; } /* @@ -237,8 +248,8 @@ NTSTATUS smbcli_transport_connect_recv(struct smbcli_request *req) send a session request (if needed) */ BOOL smbcli_transport_connect(struct smbcli_transport *transport, - struct nmb_name *calling, - struct nmb_name *called) + struct nbt_name *calling, + struct nbt_name *called) { struct smbcli_request *req; NTSTATUS status; diff --git a/source4/libcli/raw/libcliraw.h b/source4/libcli/raw/libcliraw.h index 4047a5d369..d7414a237e 100644 --- a/source4/libcli/raw/libcliraw.h +++ b/source4/libcli/raw/libcliraw.h @@ -21,6 +21,7 @@ */ #include "request.h" +#include "librpc/gen_ndr/ndr_nbt.h" struct smbcli_tree; /* forward declare */ struct smbcli_request; /* forward declare */ @@ -151,7 +152,7 @@ struct smbcli_transport { /* remember the called name - some sub-protocols require us to know the server name */ - struct nmb_name called; + struct nbt_name called; /* a buffer for partially received SMB packets. */ struct { -- cgit From aefaa18554a55da5b5d9fdb9815eb246b539c8a2 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 22 Jan 2005 02:51:39 +0000 Subject: r4924: continue the effort to simplify and generalise the composite interface. This patch removes the "stage" variable, which is really better suited to the backend state structures (This used to be commit 39da684ea8bc72d7a4a12c00eaad56b4f32890a9) --- source4/libcli/raw/clisocket.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index e981049535..cbbd6490bd 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -30,6 +30,7 @@ this private structure is used during async connection handling */ struct clisocket_connect { + int port_num; int *iports; struct smbcli_socket *sock; const char *dest_host; @@ -95,8 +96,8 @@ static void smbcli_sock_connect_handler(struct event_context *ev, struct fd_even } /* that port failed - try the next port */ - for (i=c->stage+1;conn->iports[i];i++) { - c->stage = i; + for (i=conn->port_num+1;conn->iports[i];i++) { + conn->port_num = i; c->status = smbcli_sock_connect_one(conn->sock, conn->dest_host, conn->iports[i]); @@ -204,7 +205,7 @@ struct smbcli_composite *smbcli_sock_connect_send(struct smbcli_socket *sock, /* startup the connect process for each port in turn until one succeeds or tells us that it is pending */ for (i=0;conn->iports[i];i++) { - c->stage = i; + conn->port_num = i; conn->sock->port = conn->iports[i]; c->status = smbcli_sock_connect_one(sock, conn->dest_host, -- cgit From 9d6e923aab2036d6ce72e31aa4633d55b5991558 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 23 Jan 2005 09:01:46 +0000 Subject: r4938: allow the caller to supply an existing event_context if they want to in smb_composite_connect_send(). This makes doing parallel calls much easier. (This used to be commit 442308970c123b9fb25615673049e1c1c234a0b9) --- source4/libcli/raw/clisocket.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index cbbd6490bd..9249f453e8 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -49,8 +49,10 @@ static int smbcli_sock_destructor(void *ptr) /* create a smbcli_socket context + The event_ctx is optional - if not supplied one will be created */ -struct smbcli_socket *smbcli_sock_init(TALLOC_CTX *mem_ctx) +struct smbcli_socket *smbcli_sock_init(TALLOC_CTX *mem_ctx, + struct event_context *event_ctx) { struct smbcli_socket *sock; @@ -59,7 +61,11 @@ struct smbcli_socket *smbcli_sock_init(TALLOC_CTX *mem_ctx) return NULL; } - sock->event.ctx = event_context_init(sock); + if (event_ctx) { + sock->event.ctx = talloc_reference(sock, event_ctx); + } else { + sock->event.ctx = event_context_init(sock); + } if (sock->event.ctx == NULL) { talloc_free(sock); return NULL; -- cgit From fd62df64188c0f992876c72fdda8a6da5dba3090 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 23 Jan 2005 11:49:15 +0000 Subject: r4943: Smplified the events handling code a lot. The first source of complexity was that events didn't automatically cleanup themselves. This was because the events code was written before we had talloc destructors, so you needed to call event_remove_XX() to clean the event out of the event lists from every piece of code that used events. I have now added automatic event destructors, which in turn allowed me to simplify a lot of the calling code. The 2nd source of complexity was caused by the ref_count, which was needed to cope with event handlers destroying events while handling them, which meant the linked lists became invalid, so the ref_count ws used to mark events for later destruction. The new system is much simpler. I now have a ev->destruction_count, which is incremented in all event destructors. The event dispatch code checks for changes to this and handles it. (This used to be commit a3c7417cfeab429ffb22d5546b205818f531a7b4) --- source4/libcli/raw/clisocket.c | 20 +++----------------- source4/libcli/raw/clitransport.c | 2 +- 2 files changed, 4 insertions(+), 18 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 9249f453e8..847f5c1b0a 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -37,16 +37,6 @@ struct clisocket_connect { }; -static int smbcli_sock_destructor(void *ptr) -{ - struct smbcli_socket *sock = talloc_get_type(ptr, struct smbcli_socket); - - if (sock->event.fde && sock->event.ctx) { - event_remove_fd(sock->event.ctx, sock->event.fde); - } - return 0; -} - /* create a smbcli_socket context The event_ctx is optional - if not supplied one will be created @@ -71,8 +61,6 @@ struct smbcli_socket *smbcli_sock_init(TALLOC_CTX *mem_ctx, return NULL; } - talloc_set_destructor(sock, smbcli_sock_destructor); - return sock; } @@ -134,11 +122,7 @@ static NTSTATUS smbcli_sock_connect_one(struct smbcli_socket *sock, talloc_free(sock->sock); sock->sock = NULL; } - - if (sock->event.fde) { - event_remove_fd(sock->event.ctx, sock->event.fde); - sock->event.fde = NULL; - } + talloc_free(sock->event.fde); status = socket_create("ip", SOCKET_TYPE_STREAM, &sock->sock, 0); if (!NT_STATUS_IS_OK(status)) { @@ -155,6 +139,8 @@ static NTSTATUS smbcli_sock_connect_one(struct smbcli_socket *sock, fde.private = sock; sock->event.fde = event_add_fd(sock->event.ctx, &fde); + talloc_steal(sock, sock->event.fde); + sock->port = port; set_blocking(fde.fd, False); diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 918f18fa40..b053b362ca 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -55,7 +55,6 @@ static int transport_destructor(void *ptr) struct smbcli_transport *transport = ptr; smbcli_transport_dead(transport); - event_remove_timed(transport->socket->event.ctx, transport->socket->event.te); return 0; } @@ -323,6 +322,7 @@ void smbcli_transport_idle_handler(struct smbcli_transport *transport, te.handler = idle_handler; te.private = transport; transport->socket->event.te = event_add_timed(transport->socket->event.ctx, &te); + talloc_steal(transport, transport->socket->event.te); } /* -- cgit From 6c14b0133dede38294a812be7f5f5bd5ec3d498b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 23 Jan 2005 12:17:45 +0000 Subject: r4944: every event_add_*() caller was having to call talloc_steal() to take control of the event, so instead build that into the function. If you pass NULL as mem_ctx then it leaves it as a child of the events structure. (This used to be commit 7f981b9ed96f39027cbfd500f41e0c2be64cbb50) --- source4/libcli/raw/clisocket.c | 3 +-- source4/libcli/raw/clitransport.c | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 847f5c1b0a..c9934fa16d 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -138,8 +138,7 @@ static NTSTATUS smbcli_sock_connect_one(struct smbcli_socket *sock, fde.handler = smbcli_sock_connect_handler; fde.private = sock; - sock->event.fde = event_add_fd(sock->event.ctx, &fde); - talloc_steal(sock, sock->event.fde); + sock->event.fde = event_add_fd(sock->event.ctx, &fde, sock); sock->port = port; set_blocking(fde.fd, False); diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index b053b362ca..e3a8281f3f 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -321,8 +321,8 @@ void smbcli_transport_idle_handler(struct smbcli_transport *transport, te.next_event = timeval_current_ofs(0, period); te.handler = idle_handler; te.private = transport; - transport->socket->event.te = event_add_timed(transport->socket->event.ctx, &te); - talloc_steal(transport, transport->socket->event.te); + transport->socket->event.te = event_add_timed(transport->socket->event.ctx, + &te, transport); } /* -- cgit From 3e44c4a3ba6acd7d9bc997c012d1863377e9d873 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 24 Jan 2005 00:57:14 +0000 Subject: r4951: some of the code dealing with libcli was getting too complex trying to handle the inverted memory hierarchy that a normal session establishment gave. The inverted hierarchy came from that fact that you first establish a socket, then a transport, then a session and finally a tree. That leads to the socket being at the top of the memory hierarchy and the tree at the bottom, which makes no sense from the users point of view, as they want to be able to free the tree and have everything disappear. The core problem was that the libcli interface didn't distinguish between establishing a primary context and a secondary context. If you establish a 2nd session on a transport then you want the transport to be referenced by the session, whereas if you establish a primary session then you want the transport to be a child of the session. To fix this I have added "parent_ctx" and "primary" arguments to the libcli intialisation functions. This makes using the library much easier, and gives us a memory hierarchy that makes much more sense. I was prompted to do this by a bug in the cifs backend, which was caused by the socket not being properly torn down on a disconnect due to the inverted memory hierarchy. (This used to be commit 5e8fd5f70178992e249805c2e1ddafaf6840739b) --- source4/libcli/raw/clisession.c | 11 ++++++++--- source4/libcli/raw/clitransport.c | 13 ++++++++----- source4/libcli/raw/clitree.c | 12 +++++++++--- 3 files changed, 25 insertions(+), 11 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index ed50601c25..30382e0837 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -33,18 +33,23 @@ /**************************************************************************** Initialize the session context ****************************************************************************/ -struct smbcli_session *smbcli_session_init(struct smbcli_transport *transport) +struct smbcli_session *smbcli_session_init(struct smbcli_transport *transport, + TALLOC_CTX *parent_ctx, BOOL primary) { struct smbcli_session *session; uint16_t flags2; uint32_t capabilities; - session = talloc_zero(transport, struct smbcli_session); + session = talloc_zero(parent_ctx, struct smbcli_session); if (!session) { return NULL; } - session->transport = talloc_reference(session, transport); + if (primary) { + session->transport = talloc_steal(session, transport); + } else { + session->transport = talloc_reference(session, transport); + } session->pid = (uint16_t)getpid(); session->vuid = UID_FIELD_INVALID; diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index e3a8281f3f..c993fd7e60 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -61,16 +61,19 @@ static int transport_destructor(void *ptr) /* create a transport structure based on an established socket */ -struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock) +struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock, + TALLOC_CTX *parent_ctx, BOOL primary) { struct smbcli_transport *transport; - transport = talloc_p(sock, struct smbcli_transport); + transport = talloc_zero(parent_ctx, struct smbcli_transport); if (!transport) return NULL; - ZERO_STRUCTP(transport); - - transport->socket = talloc_reference(transport, sock); + if (primary) { + transport->socket = talloc_steal(transport, sock); + } else { + transport->socket = talloc_reference(transport, sock); + } transport->negotiate.protocol = PROTOCOL_NT1; transport->options.use_spnego = lp_use_spnego(); transport->options.max_xmit = lp_max_xmit(); diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index 06963d5bc4..ce4dafca9f 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -33,16 +33,22 @@ /**************************************************************************** Initialize the tree context ****************************************************************************/ -struct smbcli_tree *smbcli_tree_init(struct smbcli_session *session) +struct smbcli_tree *smbcli_tree_init(struct smbcli_session *session, + TALLOC_CTX *parent_ctx, BOOL primary) { struct smbcli_tree *tree; - tree = talloc_zero(session, struct smbcli_tree); + tree = talloc_zero(parent_ctx, struct smbcli_tree); if (!tree) { return NULL; } - tree->session = talloc_reference(tree, session); + if (primary) { + tree->session = talloc_steal(tree, session); + } else { + tree->session = talloc_reference(tree, session); + } + return tree; } -- cgit From af4ce4805ce1504fc8869ead032eabb72fca77a0 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 24 Jan 2005 01:51:45 +0000 Subject: r4954: we don't need the separate event_remove_*() calls any more, as you now remove an event by calling talloc_free(). (This used to be commit 8f19b6886cc58a56d52aecfc83a175197061e533) --- source4/libcli/raw/clitransport.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index c993fd7e60..1904618be9 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -318,7 +318,7 @@ void smbcli_transport_idle_handler(struct smbcli_transport *transport, transport->idle.period = period; if (transport->socket->event.te != NULL) { - event_remove_timed(transport->socket->event.ctx, transport->socket->event.te); + talloc_free(transport->socket->event.te); } te.next_event = timeval_current_ofs(0, period); -- cgit From 759da3b915e2006d4c87b5ace47f399accd9ce91 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 27 Jan 2005 07:08:20 +0000 Subject: r5037: got rid of all of the TALLOC_DEPRECATED stuff. My apologies for the large commit. I thought this was worthwhile to get done for consistency. (This used to be commit ec32b22ed5ec224f6324f5e069d15e92e38e15c0) --- source4/libcli/raw/rawacl.c | 2 +- source4/libcli/raw/raweas.c | 6 +++--- source4/libcli/raw/rawfile.c | 4 ++-- source4/libcli/raw/rawfileinfo.c | 10 +++++----- source4/libcli/raw/rawrequest.c | 2 +- source4/libcli/raw/rawsetfileinfo.c | 8 ++++---- 6 files changed, 16 insertions(+), 16 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawacl.c b/source4/libcli/raw/rawacl.c index 97e0212137..b2dac09f81 100644 --- a/source4/libcli/raw/rawacl.c +++ b/source4/libcli/raw/rawacl.c @@ -81,7 +81,7 @@ NTSTATUS smb_raw_query_secdesc_recv(struct smbcli_request *req, return NT_STATUS_INVALID_PARAMETER; } - io->query_secdesc.out.sd = talloc_p(mem_ctx, struct security_descriptor); + io->query_secdesc.out.sd = talloc(mem_ctx, struct security_descriptor); if (!io->query_secdesc.out.sd) { return NT_STATUS_NO_MEMORY; } diff --git a/source4/libcli/raw/raweas.c b/source4/libcli/raw/raweas.c index ec8bacdf64..49be9a43e6 100644 --- a/source4/libcli/raw/raweas.c +++ b/source4/libcli/raw/raweas.c @@ -187,7 +187,7 @@ NTSTATUS ea_pull_list(const DATA_BLOB *blob, blob2.data = blob->data + ofs; blob2.length = ea_size - ofs; - *eas = talloc_realloc_p(mem_ctx, *eas, struct ea_struct, n+1); + *eas = talloc_realloc(mem_ctx, *eas, struct ea_struct, n+1); if (! *eas) return NT_STATUS_NO_MEMORY; len = ea_pull_struct(&blob2, mem_ctx, &(*eas)[n]); @@ -232,7 +232,7 @@ NTSTATUS ea_pull_list_chained(const DATA_BLOB *blob, blob2.data = blob->data + ofs + 4; blob2.length = blob->length - (ofs + 4); - *eas = talloc_realloc_p(mem_ctx, *eas, struct ea_struct, n+1); + *eas = talloc_realloc(mem_ctx, *eas, struct ea_struct, n+1); if (! *eas) return NT_STATUS_NO_MEMORY; len = ea_pull_struct(&blob2, mem_ctx, &(*eas)[n]); @@ -312,7 +312,7 @@ NTSTATUS ea_pull_name_list(const DATA_BLOB *blob, blob2.data = blob->data + ofs; blob2.length = ea_size - ofs; - *ea_names = talloc_realloc_p(mem_ctx, *ea_names, struct ea_name, n+1); + *ea_names = talloc_realloc(mem_ctx, *ea_names, struct ea_name, n+1); if (! *ea_names) return NT_STATUS_NO_MEMORY; len = ea_pull_name(&blob2, mem_ctx, &(*ea_names)[n]); diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c index e0b54cacc3..c6652125c2 100644 --- a/source4/libcli/raw/rawfile.c +++ b/source4/libcli/raw/rawfile.c @@ -140,7 +140,7 @@ static struct smbcli_request *smb_raw_t2mkdir_send(struct smbcli_tree *tree, req = smb_raw_trans2_send(tree, &t2); - talloc_destroy(mem_ctx); + talloc_free(mem_ctx); return req; } @@ -383,7 +383,7 @@ static struct smbcli_request *smb_raw_t2open_send(struct smbcli_tree *tree, req = smb_raw_trans2_send(tree, &t2); - talloc_destroy(mem_ctx); + talloc_free(mem_ctx); return req; } diff --git a/source4/libcli/raw/rawfileinfo.c b/source4/libcli/raw/rawfileinfo.c index 3befb8ee4d..88c2f0d0fc 100644 --- a/source4/libcli/raw/rawfileinfo.c +++ b/source4/libcli/raw/rawfileinfo.c @@ -182,7 +182,7 @@ static NTSTATUS smb_raw_info_backend(struct smbcli_session *session, while (blob->length - ofs >= 24) { uint_t n = parms->stream_info.out.num_streams; parms->stream_info.out.streams = - talloc_realloc_p(mem_ctx, + talloc_realloc(mem_ctx, parms->stream_info.out.streams, struct stream_struct, n+1); @@ -306,7 +306,7 @@ static struct smbcli_request *smb_raw_fileinfo_blob_send(struct smbcli_tree *tre tp.in.params = data_blob_talloc(mem_ctx, NULL, 4); if (!tp.in.params.data) { - talloc_destroy(mem_ctx); + talloc_free(mem_ctx); return NULL; } @@ -315,7 +315,7 @@ static struct smbcli_request *smb_raw_fileinfo_blob_send(struct smbcli_tree *tre req = smb_raw_trans2_send(tree, &tp); - talloc_destroy(mem_ctx); + talloc_free(mem_ctx); return req; } @@ -360,7 +360,7 @@ static struct smbcli_request *smb_raw_pathinfo_blob_send(struct smbcli_tree *tre tp.in.params = data_blob_talloc(mem_ctx, NULL, 6); if (!tp.in.params.data) { - talloc_destroy(mem_ctx); + talloc_free(mem_ctx); return NULL; } @@ -371,7 +371,7 @@ static struct smbcli_request *smb_raw_pathinfo_blob_send(struct smbcli_tree *tre req = smb_raw_trans2_send(tree, &tp); - talloc_destroy(mem_ctx); + talloc_free(mem_ctx); return req; } diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 7fb12dcf80..7dbe6b3468 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -67,7 +67,7 @@ struct smbcli_request *smbcli_request_setup_nonsmb(struct smbcli_transport *tran { struct smbcli_request *req; - req = talloc_p(transport, struct smbcli_request); + req = talloc(transport, struct smbcli_request); if (!req) { return NULL; } diff --git a/source4/libcli/raw/rawsetfileinfo.c b/source4/libcli/raw/rawsetfileinfo.c index 9576bdf356..7934171ab0 100644 --- a/source4/libcli/raw/rawsetfileinfo.c +++ b/source4/libcli/raw/rawsetfileinfo.c @@ -274,7 +274,7 @@ struct smbcli_request *smb_raw_setfileinfo_send(struct smbcli_tree *tree, if (!mem_ctx) return NULL; if (!smb_raw_setinfo_backend(tree, mem_ctx, parms, &blob)) { - talloc_destroy(mem_ctx); + talloc_free(mem_ctx); return NULL; } @@ -285,7 +285,7 @@ struct smbcli_request *smb_raw_setfileinfo_send(struct smbcli_tree *tree, parms->generic.level, &blob); - talloc_destroy(mem_ctx); + talloc_free(mem_ctx); return req; } @@ -321,7 +321,7 @@ struct smbcli_request *smb_raw_setpathinfo_send(struct smbcli_tree *tree, if (!mem_ctx) return NULL; if (!smb_raw_setinfo_backend(tree, mem_ctx, parms, &blob)) { - talloc_destroy(mem_ctx); + talloc_free(mem_ctx); return NULL; } @@ -332,7 +332,7 @@ struct smbcli_request *smb_raw_setpathinfo_send(struct smbcli_tree *tree, parms->generic.level, &blob); - talloc_destroy(mem_ctx); + talloc_free(mem_ctx); return req; } -- cgit From 9a70f446fc4abc2bd1278772810c0e8132f4bea4 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 31 Jan 2005 08:30:44 +0000 Subject: r5126: the composite code is no longer client specific or smb specific, so rename the core structure to composite_context and the wait routine to composite_wait() (suggestion from metze) (This used to be commit cf11d05e35179c2c3e51c5ab370cd0a3fb15f24a) --- source4/libcli/raw/clisocket.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index c9934fa16d..78a096fb8f 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -74,7 +74,7 @@ static NTSTATUS smbcli_sock_connect_one(struct smbcli_socket *sock, static void smbcli_sock_connect_handler(struct event_context *ev, struct fd_event *fde, struct timeval t, uint16_t flags) { - struct smbcli_composite *c = talloc_get_type(fde->private, struct smbcli_composite); + struct composite_context *c = talloc_get_type(fde->private, struct composite_context); struct clisocket_connect *conn = talloc_get_type(c->private, struct clisocket_connect); int i; @@ -153,14 +153,14 @@ static NTSTATUS smbcli_sock_connect_one(struct smbcli_socket *sock, this is the async send side of the interface */ -struct smbcli_composite *smbcli_sock_connect_send(struct smbcli_socket *sock, +struct composite_context *smbcli_sock_connect_send(struct smbcli_socket *sock, const char *host_addr, int port) { - struct smbcli_composite *c; + struct composite_context *c; struct clisocket_connect *conn; int i; - c = talloc_zero(sock, struct smbcli_composite); + c = talloc_zero(sock, struct composite_context); if (c == NULL) return NULL; c->event_ctx = sock->event.ctx; @@ -219,10 +219,10 @@ failed: /* finish a smbcli_sock_connect_send() operation */ -NTSTATUS smbcli_sock_connect_recv(struct smbcli_composite *c) +NTSTATUS smbcli_sock_connect_recv(struct composite_context *c) { NTSTATUS status; - status = smb_composite_wait(c); + status = composite_wait(c); talloc_free(c); return status; } @@ -235,7 +235,7 @@ NTSTATUS smbcli_sock_connect_recv(struct smbcli_composite *c) */ NTSTATUS smbcli_sock_connect(struct smbcli_socket *sock, const char *host_addr, int port) { - struct smbcli_composite *c; + struct composite_context *c; c = smbcli_sock_connect_send(sock, host_addr, port); if (c == NULL) { -- cgit From 66170ef8b36b499aa5b44ef10c1bd362a50f2636 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 3 Feb 2005 02:35:52 +0000 Subject: r5185: make all the events data structures private to events.c. This will make it possible to add optimisations to the events code such as keeping the next timed event in a sorted list, and using epoll for file descriptor events. I also removed the loop events code, as it wasn't being used anywhere, and changed timed events to always be one-shot (as adding a new timed event in the event handler is so easy to do if needed) (This used to be commit d7b4b6de51342a65bf46fce772d313f92f8d73d3) --- source4/libcli/raw/clisocket.c | 27 ++++++++++------------- source4/libcli/raw/clitransport.c | 45 ++++++++++++++++++++++++--------------- source4/libcli/raw/rawrequest.c | 1 + 3 files changed, 40 insertions(+), 33 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 78a096fb8f..f9e662714b 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -65,16 +65,17 @@ struct smbcli_socket *smbcli_sock_init(TALLOC_CTX *mem_ctx, } static NTSTATUS smbcli_sock_connect_one(struct smbcli_socket *sock, - const char *hostaddr, int port); + const char *hostaddr, int port, + struct composite_context *c); /* handle socket write events during an async connect. These happen when the OS has either completed the connect() or has returned an error */ static void smbcli_sock_connect_handler(struct event_context *ev, struct fd_event *fde, - struct timeval t, uint16_t flags) + struct timeval t, uint16_t flags, void *private) { - struct composite_context *c = talloc_get_type(fde->private, struct composite_context); + struct composite_context *c = talloc_get_type(private, struct composite_context); struct clisocket_connect *conn = talloc_get_type(c->private, struct clisocket_connect); int i; @@ -94,10 +95,9 @@ static void smbcli_sock_connect_handler(struct event_context *ev, struct fd_even conn->port_num = i; c->status = smbcli_sock_connect_one(conn->sock, conn->dest_host, - conn->iports[i]); + conn->iports[i], c); if (NT_STATUS_IS_OK(c->status) || NT_STATUS_EQUAL(c->status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { - conn->sock->event.fde->private = c; return; } } @@ -113,9 +113,9 @@ static void smbcli_sock_connect_handler(struct event_context *ev, struct fd_even try to connect to the given address/port */ static NTSTATUS smbcli_sock_connect_one(struct smbcli_socket *sock, - const char *hostaddr, int port) + const char *hostaddr, int port, + struct composite_context *c) { - struct fd_event fde; NTSTATUS status; if (sock->sock) { @@ -133,15 +133,11 @@ static NTSTATUS smbcli_sock_connect_one(struct smbcli_socket *sock, /* we initially look for write - see the man page on non-blocking connect */ - fde.fd = socket_get_fd(sock->sock); - fde.flags = EVENT_FD_WRITE; - fde.handler = smbcli_sock_connect_handler; - fde.private = sock; - - sock->event.fde = event_add_fd(sock->event.ctx, &fde, sock); + sock->event.fde = event_add_fd(sock->event.ctx, sock, socket_get_fd(sock->sock), + EVENT_FD_WRITE, smbcli_sock_connect_handler, c); sock->port = port; - set_blocking(fde.fd, False); + set_blocking(socket_get_fd(sock->sock), False); return socket_connect(sock->sock, NULL, 0, hostaddr, port, 0); } @@ -200,10 +196,9 @@ struct composite_context *smbcli_sock_connect_send(struct smbcli_socket *sock, conn->sock->port = conn->iports[i]; c->status = smbcli_sock_connect_one(sock, conn->dest_host, - conn->iports[i]); + conn->iports[i], c); if (NT_STATUS_IS_OK(c->status) || NT_STATUS_EQUAL(c->status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { - sock->event.fde->private = c; return c; } } diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 1904618be9..21303a34aa 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -33,11 +33,13 @@ static void smbcli_transport_process_send(struct smbcli_transport *transport); /* an event has happened on the socket */ -static void smbcli_transport_event_handler(struct event_context *ev, struct fd_event *fde, - struct timeval t, uint16_t flags) +static void smbcli_transport_event_handler(struct event_context *ev, + struct fd_event *fde, + struct timeval t, + uint16_t flags, void *private) { - struct smbcli_transport *transport = fde->private; - + struct smbcli_transport *transport = talloc_get_type(private, + struct smbcli_transport); if (flags & EVENT_FD_READ) { smbcli_transport_process_recv(transport); return; @@ -87,9 +89,13 @@ struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock, /* take over event handling from the socket layer - it only handles events up until we are connected */ - transport->socket->event.fde->handler = smbcli_transport_event_handler; - transport->socket->event.fde->private = transport; - transport->socket->event.fde->flags = EVENT_FD_READ; + talloc_free(transport->socket->event.fde); + transport->socket->event.fde = event_add_fd(transport->socket->event.ctx, + transport->socket, + socket_get_fd(transport->socket->sock), + EVENT_FD_READ, + smbcli_transport_event_handler, + transport); talloc_set_destructor(transport, transport_destructor); @@ -132,7 +138,8 @@ void smbcli_transport_dead(struct smbcli_transport *transport) */ static void smbcli_transport_write_enable(struct smbcli_transport *transport) { - transport->socket->event.fde->flags |= EVENT_FD_WRITE; + struct fd_event *fde = transport->socket->event.fde; + EVENT_FD_WRITEABLE(fde); } /* @@ -140,7 +147,8 @@ static void smbcli_transport_write_enable(struct smbcli_transport *transport) */ static void smbcli_transport_write_disable(struct smbcli_transport *transport) { - transport->socket->event.fde->flags &= ~EVENT_FD_WRITE; + struct fd_event *fde = transport->socket->event.fde; + EVENT_FD_NOT_WRITEABLE(fde); } /* @@ -296,10 +304,15 @@ again: } static void idle_handler(struct event_context *ev, - struct timed_event *te, struct timeval t) + struct timed_event *te, struct timeval t, void *private) { - struct smbcli_transport *transport = te->private; - te->next_event = timeval_add(&te->next_event, 0, transport->idle.period); + struct smbcli_transport *transport = talloc_get_type(private, + struct smbcli_transport); + struct timeval next = timeval_add(&t, 0, transport->idle.period); + transport->socket->event.te = event_add_timed(transport->socket->event.ctx, + transport, + next, + idle_handler, transport); transport->idle.func(transport, transport->idle.private); } @@ -312,7 +325,6 @@ void smbcli_transport_idle_handler(struct smbcli_transport *transport, uint64_t period, void *private) { - struct timed_event te; transport->idle.func = idle_func; transport->idle.private = private; transport->idle.period = period; @@ -321,11 +333,10 @@ void smbcli_transport_idle_handler(struct smbcli_transport *transport, talloc_free(transport->socket->event.te); } - te.next_event = timeval_current_ofs(0, period); - te.handler = idle_handler; - te.private = transport; transport->socket->event.te = event_add_timed(transport->socket->event.ctx, - &te, transport); + transport, + timeval_current_ofs(0, period), + idle_handler, transport); } /* diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 7dbe6b3468..420ce0a3a2 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -26,6 +26,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" #include "dlinklist.h" +#include "events.h" /* we over allocate the data buffer to prevent too many realloc calls */ #define REQ_OVER_ALLOCATION 0 -- cgit From 0798d54b4fc28be881e2c4012663b1461bc85ba7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 3 Feb 2005 11:25:52 +0000 Subject: r5195: most events don't need the time of the event, so save a gettimeofday() call and just use timeval_current() when its actually needed (This used to be commit 236403cc4dc2924ed6a898acae0bb44cc1688dcc) --- source4/libcli/raw/clisocket.c | 2 +- source4/libcli/raw/clitransport.c | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index f9e662714b..69de86088a 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -73,7 +73,7 @@ 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, - struct timeval t, uint16_t flags, void *private) + uint16_t flags, void *private) { struct composite_context *c = talloc_get_type(private, struct composite_context); struct clisocket_connect *conn = talloc_get_type(c->private, struct clisocket_connect); diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 21303a34aa..d614d80d99 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -35,7 +35,6 @@ static void smbcli_transport_process_send(struct smbcli_transport *transport); */ static void smbcli_transport_event_handler(struct event_context *ev, struct fd_event *fde, - struct timeval t, uint16_t flags, void *private) { struct smbcli_transport *transport = talloc_get_type(private, -- cgit From 131dc76d56df40b3511c47e54f15412a25b491f8 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 3 Feb 2005 11:56:03 +0000 Subject: r5197: moved events code to lib/events/ (suggestion from metze) (This used to be commit 7f54c8a339f36aa43c9340be70ab7f0067593ef2) --- source4/libcli/raw/clisocket.c | 2 +- source4/libcli/raw/clitransport.c | 2 +- source4/libcli/raw/rawrequest.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 69de86088a..44c6a87e21 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -22,7 +22,7 @@ */ #include "includes.h" -#include "events.h" +#include "lib/events/events.h" #include "libcli/raw/libcliraw.h" #include "libcli/composite/composite.h" diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index d614d80d99..079783435c 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -24,7 +24,7 @@ #include "libcli/raw/libcliraw.h" #include "system/time.h" #include "dlinklist.h" -#include "events.h" +#include "lib/events/events.h" static void smbcli_transport_process_recv(struct smbcli_transport *transport); diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 420ce0a3a2..b49009ac22 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -26,7 +26,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" #include "dlinklist.h" -#include "events.h" +#include "lib/events/events.h" /* we over allocate the data buffer to prevent too many realloc calls */ #define REQ_OVER_ALLOCATION 0 -- cgit From e82aad1ce39a6b7a2e51b9e2cb494d74ec70e158 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 10 Feb 2005 05:09:35 +0000 Subject: r5298: - got rid of pstring.h from includes.h. This at least makes it a bit less likely that anyone will use pstring for new code - got rid of winbind_client.h from includes.h. This one triggered a huge change, as winbind_client.h was including system/filesys.h and defining the old uint32 and uint16 types, as well as its own pstring and fstring. (This used to be commit 9db6c79e902ec538108d6b7d3324039aabe1704f) --- source4/libcli/raw/clisession.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index 30382e0837..4eba464274 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -22,6 +22,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" +#include "system/filesys.h" #include "auth/auth.h" #define SETUP_REQUEST_SESSION(cmd, wct, buflen) do { \ -- cgit From bed7c9ec32b7d4083ba4ed2abbf3b6126bee7a25 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 10 Feb 2005 06:59:29 +0000 Subject: r5304: removed lib/socket/socket.h from includes.h (This used to be commit b902ea546d2d1327b23f40ddaeeaa8e7e3662454) --- source4/libcli/raw/clisocket.c | 1 + source4/libcli/raw/clitransport.c | 1 + 2 files changed, 2 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 44c6a87e21..cbb479ca1a 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -25,6 +25,7 @@ #include "lib/events/events.h" #include "libcli/raw/libcliraw.h" #include "libcli/composite/composite.h" +#include "lib/socket/socket.h" /* this private structure is used during async connection handling diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 079783435c..ee382da3c2 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -22,6 +22,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" +#include "lib/socket/socket.h" #include "system/time.h" #include "dlinklist.h" #include "lib/events/events.h" -- cgit From 9515fc4406464b6a015a06d89ca0370810977486 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 11 Feb 2005 02:08:39 +0000 Subject: r5322: removed a whole bunch of #include lines that minimal_includes.pl thinks are not needed. Now to see how this fares on the build farm :) (This used to be commit 80ffcc650c9c86141507edd8338b97814a85f868) --- source4/libcli/raw/clisession.c | 1 - source4/libcli/raw/clitransport.c | 1 - source4/libcli/raw/rawacl.c | 1 - source4/libcli/raw/raweas.c | 1 - 4 files changed, 4 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index 4eba464274..5f75701871 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -23,7 +23,6 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" #include "system/filesys.h" -#include "auth/auth.h" #define SETUP_REQUEST_SESSION(cmd, wct, buflen) do { \ req = smbcli_request_setup_session(session, cmd, wct, buflen); \ diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index ee382da3c2..05833b2f9a 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -23,7 +23,6 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" #include "lib/socket/socket.h" -#include "system/time.h" #include "dlinklist.h" #include "lib/events/events.h" diff --git a/source4/libcli/raw/rawacl.c b/source4/libcli/raw/rawacl.c index b2dac09f81..82c69ec706 100644 --- a/source4/libcli/raw/rawacl.c +++ b/source4/libcli/raw/rawacl.c @@ -21,7 +21,6 @@ #include "includes.h" #include "librpc/gen_ndr/ndr_security.h" -#include "libcli/raw/libcliraw.h" /**************************************************************************** fetch file ACL (async send) diff --git a/source4/libcli/raw/raweas.c b/source4/libcli/raw/raweas.c index 49be9a43e6..4ab3344135 100644 --- a/source4/libcli/raw/raweas.c +++ b/source4/libcli/raw/raweas.c @@ -19,7 +19,6 @@ */ #include "includes.h" -#include "libcli/raw/libcliraw.h" /* work out how many bytes on the wire a ea list will consume. -- cgit From d8da32a2845b99cc4272fedd28dff570331be63e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 13 Feb 2005 09:10:33 +0000 Subject: r5371: on port 139 the called name needs to be in uppercase (This used to be commit c5aef260c4581bfc0d32ec09fac3414156c40230) --- source4/libcli/raw/clitree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index ce4dafca9f..74db1c6952 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -175,8 +175,8 @@ NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx, io.in.dest_host = dest_host; io.in.port = port; - io.in.called_name = dest_host; - io.in.calling_name = my_name; + io.in.called_name = strupper_talloc(parent_ctx, dest_host); + io.in.calling_name = strupper_talloc(parent_ctx, my_name); io.in.service = service; io.in.service_type = service_type; io.in.domain = domain; -- cgit From 13b0776f60f6a0f35a4afc2b3d3c6b5ec9c1ca6a Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 21 Mar 2005 23:35:58 +0000 Subject: r5929: Use cli_credentials for the SMB functions as well. Fix a couple of bugs in the new cli_credentials code (This used to be commit 4ad481cfe5cde514d2ef9646147239f3faaa6173) --- source4/libcli/raw/clitree.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index 74db1c6952..0559c64dc1 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -167,8 +167,7 @@ NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx, const char *my_name, const char *dest_host, int port, const char *service, const char *service_type, - const char *user, const char *domain, - const char *password) + struct cli_credentials *credentials) { struct smb_composite_connect io; NTSTATUS status; @@ -179,10 +178,10 @@ NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx, io.in.calling_name = strupper_talloc(parent_ctx, my_name); io.in.service = service; io.in.service_type = service_type; - io.in.domain = domain; - io.in.user = user; - if (user && user[0]) { - io.in.password = password; + io.in.domain = cli_credentials_get_domain(credentials); + io.in.user = cli_credentials_get_username(credentials); + if (!cli_credentials_is_anonymous(credentials)) { + io.in.password = cli_credentials_get_password(credentials); } else { io.in.password = NULL; } -- cgit From 645711c602313940dcf80ec786557920ecfbf884 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 22 Mar 2005 08:00:45 +0000 Subject: r5941: Commit this patch much earlier than I would normally prefer, but metze needs a working tree... The main volume of this patch was what I started working on today: - Cleans up memory handling around DCE/RPC pipes, to have a parent talloc context. - Uses sepereate inner loops for some of the DCE/RPC tests The other and more important part of this patch fixes issues surrounding the new credentials framwork: This makes the struct cli_credentials always a talloc() structure, rather than on the stack. Parts of the cli_credentials code already assumed this. There were other issues, particularly in the DCERPC over SMB handling, as well as little things that had to be tidied up before test_w2k3.sh would start to pass. Andrew Bartlett (This used to be commit 0453f9d05d2e336fba1f85dbf2718d01fa2bf778) --- source4/libcli/raw/clitree.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index 0559c64dc1..f333cf7a98 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -167,7 +167,7 @@ NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx, const char *my_name, const char *dest_host, int port, const char *service, const char *service_type, - struct cli_credentials *credentials) + struct cli_credentials *credentials) { struct smb_composite_connect io; NTSTATUS status; @@ -180,11 +180,7 @@ NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx, io.in.service_type = service_type; io.in.domain = cli_credentials_get_domain(credentials); io.in.user = cli_credentials_get_username(credentials); - if (!cli_credentials_is_anonymous(credentials)) { - io.in.password = cli_credentials_get_password(credentials); - } else { - io.in.password = NULL; - } + io.in.password = cli_credentials_get_password(credentials); status = smb_composite_connect(&io, parent_ctx); if (NT_STATUS_IS_OK(status)) { -- cgit From 2eb3d680625286431a3a60e37b75f47e0738f253 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 24 Mar 2005 04:14:06 +0000 Subject: r6028: A MAJOR update to intergrate the new credentails system fully with GENSEC, and to pull SCHANNEL into GENSEC, by making it less 'special'. GENSEC now no longer has it's own handling of 'set username' etc, instead it uses cli_credentials calls. In order to link the credentails code right though Samba, a lot of interfaces have changed to remove 'username, domain, password' arguments, and these have been replaced with a single 'struct cli_credentials'. In the session setup code, a new parameter 'workgroup' contains the client/server current workgroup, which seems unrelated to the authentication exchange (it was being filled in from the auth info). This allows in particular kerberos to only call back for passwords when it actually needs to perform the kinit. The kerberos code has been modified not to use the SPNEGO provided 'principal name' (in the mechListMIC), but to instead use the name the host was connected to as. This better matches Microsoft behaviour, is more secure and allows better use of standard kerberos functions. To achieve this, I made changes to our socket code so that the hostname (before name resolution) is now recorded on the socket. In schannel, most of the code from librpc/rpc/dcerpc_schannel.c is now in libcli/auth/schannel.c, and it looks much more like a standard GENSEC module. The actual sign/seal code moved to libcli/auth/schannel_sign.c in a previous commit. The schannel credentails structure is now merged with the rest of the credentails, as many of the values (username, workstation, domain) where already present there. This makes handling this in a generic manner much easier, as there is no longer a custom entry-point. The auth_domain module continues to be developed, but is now just as functional as auth_winbind. The changes here are consequential to the schannel changes. The only removed function at this point is the RPC-LOGIN test (simulating the load of a WinXP login), which needs much more work to clean it up (it contains copies of too much code from all over the torture suite, and I havn't been able to penetrate its 'structure'). Andrew Bartlett (This used to be commit 2301a4b38a21aa60917973451687063d83d18d66) --- source4/libcli/raw/clisession.c | 4 ++-- source4/libcli/raw/clisocket.c | 28 ++++++++++++++++------------ source4/libcli/raw/clitree.c | 7 ++----- 3 files changed, 20 insertions(+), 19 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index 5f75701871..3156624589 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -134,7 +134,7 @@ struct smbcli_request *smb_raw_session_setup_send(struct smbcli_session *session smbcli_req_append_blob(req, &parms->spnego.in.secblob); smbcli_req_append_string(req, parms->spnego.in.os, STR_TERMINATE); smbcli_req_append_string(req, parms->spnego.in.lanman, STR_TERMINATE); - smbcli_req_append_string(req, parms->spnego.in.domain, STR_TERMINATE); + smbcli_req_append_string(req, parms->spnego.in.workgroup, STR_TERMINATE); break; } @@ -210,7 +210,7 @@ NTSTATUS smb_raw_session_setup_recv(struct smbcli_request *req, p += parms->spnego.out.secblob.length; p += smbcli_req_pull_string(req, mem_ctx, &parms->spnego.out.os, p, -1, STR_TERMINATE); p += smbcli_req_pull_string(req, mem_ctx, &parms->spnego.out.lanman, p, -1, STR_TERMINATE); - p += smbcli_req_pull_string(req, mem_ctx, &parms->spnego.out.domain, p, -1, STR_TERMINATE); + p += smbcli_req_pull_string(req, mem_ctx, &parms->spnego.out.workgroup, p, -1, STR_TERMINATE); break; } diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index cbb479ca1a..7cb7040131 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -34,7 +34,8 @@ struct clisocket_connect { int port_num; int *iports; struct smbcli_socket *sock; - const char *dest_host; + const char *dest_host_addr; + const char *dest_hostname; }; @@ -83,7 +84,7 @@ static void smbcli_sock_connect_handler(struct event_context *ev, struct fd_even 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_host); + conn->sock->hostname = talloc_strdup(conn->sock, conn->dest_hostname); c->state = SMBCLI_REQUEST_DONE; if (c->async.fn) { c->async.fn(c); @@ -95,7 +96,7 @@ static void smbcli_sock_connect_handler(struct event_context *ev, struct fd_even for (i=conn->port_num+1;conn->iports[i];i++) { conn->port_num = i; c->status = smbcli_sock_connect_one(conn->sock, - conn->dest_host, + conn->dest_host_addr, conn->iports[i], c); if (NT_STATUS_IS_OK(c->status) || NT_STATUS_EQUAL(c->status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { @@ -151,7 +152,8 @@ static NTSTATUS smbcli_sock_connect_one(struct smbcli_socket *sock, this is the async send side of the interface */ struct composite_context *smbcli_sock_connect_send(struct smbcli_socket *sock, - const char *host_addr, int port) + const char *host_addr, int port, + const char *host_name) { struct composite_context *c; struct clisocket_connect *conn; @@ -184,8 +186,11 @@ struct composite_context *smbcli_sock_connect_send(struct smbcli_socket *sock, conn->iports[1] = 0; } - conn->dest_host = talloc_strdup(c, host_addr); - if (conn->dest_host == NULL) goto failed; + conn->dest_host_addr = talloc_strdup(c, host_addr); + if (conn->dest_host_addr == NULL) goto failed; + + conn->dest_hostname = talloc_strdup(c, host_name); + if (conn->dest_hostname == NULL) goto failed; c->private = conn; c->state = SMBCLI_REQUEST_SEND; @@ -196,7 +201,7 @@ struct composite_context *smbcli_sock_connect_send(struct smbcli_socket *sock, conn->port_num = i; conn->sock->port = conn->iports[i]; c->status = smbcli_sock_connect_one(sock, - conn->dest_host, + conn->dest_host_addr, conn->iports[i], c); if (NT_STATUS_IS_OK(c->status) || NT_STATUS_EQUAL(c->status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { @@ -229,11 +234,12 @@ NTSTATUS smbcli_sock_connect_recv(struct composite_context *c) sync version of the function */ -NTSTATUS smbcli_sock_connect(struct smbcli_socket *sock, const char *host_addr, int port) +NTSTATUS smbcli_sock_connect(struct smbcli_socket *sock, const char *host_addr, int port, + const char *host_name) { struct composite_context *c; - c = smbcli_sock_connect_send(sock, host_addr, port); + c = smbcli_sock_connect_send(sock, host_addr, port, host_name); if (c == NULL) { return NT_STATUS_NO_MEMORY; } @@ -337,9 +343,7 @@ BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, in return False; } - sock->hostname = name; - - status = smbcli_sock_connect(sock, address, port); + status = smbcli_sock_connect(sock, address, port, name); return NT_STATUS_IS_OK(status); } diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index f333cf7a98..87c2dbba7c 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -164,7 +164,6 @@ NTSTATUS smb_tree_disconnect(struct smbcli_tree *tree) */ NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx, struct smbcli_tree **ret_tree, - const char *my_name, const char *dest_host, int port, const char *service, const char *service_type, struct cli_credentials *credentials) @@ -175,12 +174,10 @@ NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx, io.in.dest_host = dest_host; io.in.port = port; io.in.called_name = strupper_talloc(parent_ctx, dest_host); - io.in.calling_name = strupper_talloc(parent_ctx, my_name); io.in.service = service; io.in.service_type = service_type; - io.in.domain = cli_credentials_get_domain(credentials); - io.in.user = cli_credentials_get_username(credentials); - io.in.password = cli_credentials_get_password(credentials); + io.in.credentials = credentials; + io.in.workgroup = lp_workgroup(); status = smb_composite_connect(&io, parent_ctx); if (NT_STATUS_IS_OK(status)) { -- cgit From d9c15b0f280621fca844c0e8482b5e95f4ad2d11 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 14 Apr 2005 13:19:40 +0000 Subject: r6342: fixed a bad union assumption that caused ACLs to fail on 64 bit machines Thanks to lars and agruen for finding this (This used to be commit 2acc06918574b1178eecf3d61026f84f85bb40e1) --- source4/libcli/raw/rawacl.c | 2 +- source4/libcli/raw/rawfileinfo.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawacl.c b/source4/libcli/raw/rawacl.c index 82c69ec706..e168da9d1d 100644 --- a/source4/libcli/raw/rawacl.c +++ b/source4/libcli/raw/rawacl.c @@ -40,7 +40,7 @@ struct smbcli_request *smb_raw_query_secdesc_send(struct smbcli_tree *tree, SSVAL(params, 0, io->query_secdesc.in.fnum); SSVAL(params, 2, 0); /* padding */ - SIVAL(params, 4, io->query_secdesc.in.secinfo_flags); + SIVAL(params, 4, io->query_secdesc.secinfo_flags); nt.in.params.data = params; nt.in.params.length = 8; diff --git a/source4/libcli/raw/rawfileinfo.c b/source4/libcli/raw/rawfileinfo.c index 88c2f0d0fc..9f7786429c 100644 --- a/source4/libcli/raw/rawfileinfo.c +++ b/source4/libcli/raw/rawfileinfo.c @@ -310,7 +310,7 @@ static struct smbcli_request *smb_raw_fileinfo_blob_send(struct smbcli_tree *tre return NULL; } - SIVAL(tp.in.params.data, 0, fnum); + SSVAL(tp.in.params.data, 0, fnum); SSVAL(tp.in.params.data, 2, info_level); req = smb_raw_trans2_send(tree, &tp); -- cgit From 26d35d90a2a2e98b12ab866d330cbd9c0e220cef Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 14 Jun 2005 06:50:12 +0000 Subject: r7569: Fix typo in comments. (This used to be commit 64fb327ccf80d2d501ae559a6c4336a066191df0) --- source4/libcli/raw/clisession.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index 3156624589..130959e776 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -231,7 +231,7 @@ NTSTATUS smb_raw_session_setup(struct smbcli_session *session, TALLOC_CTX *mem_c /**************************************************************************** - Send a uloggoff (async send) + Send a ulogoff (async send) *****************************************************************************/ struct smbcli_request *smb_raw_ulogoff_send(struct smbcli_session *session) { @@ -251,7 +251,7 @@ struct smbcli_request *smb_raw_ulogoff_send(struct smbcli_session *session) } /**************************************************************************** - Send a uloggoff (sync interface) + Send a ulogoff (sync interface) *****************************************************************************/ NTSTATUS smb_raw_ulogoff(struct smbcli_session *session) { -- cgit From af237084ecd4f9928c6c282b9c5c73598d5c73d6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 16 Jun 2005 11:36:09 +0000 Subject: r7633: this patch started as an attempt to make the dcerpc code use a given event_context for the socket_connect() call, so that when things that use dcerpc are running alongside anything else it doesn't block the whole process during a connect. Then of course I needed to change any code that created a dcerpc connection (such as the auth code) to also take an event context, and anything that called that and so on .... thus the size of the patch. There were 3 places where I punted: - abartlet wanted me to add a gensec_set_event_context() call instead of adding it to the gensec init calls. Andrew, my apologies for not doing this. I didn't do it as adding a new parameter allowed me to catch all the callers with the compiler. Now that its done, we could go back and use gensec_set_event_context() - the ejs code calls auth initialisation, which means it should pass in the event context from the web server. I punted on that. Needs fixing. - I used a NULL event context in dcom_get_pipe(). This is equivalent to what we did already, but should be fixed to use a callers event context. Jelmer, can you think of a clean way to do that? I also cleaned up a couple of things: - libnet_context_destroy() makes no sense. I removed it. - removed some unused vars in various places (This used to be commit 3a3025485bdb8f600ab528c0b4b4eef0c65e3fc9) --- source4/libcli/raw/clitree.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index 87c2dbba7c..76cb1a43fe 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -166,7 +166,8 @@ NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx, struct smbcli_tree **ret_tree, const char *dest_host, int port, const char *service, const char *service_type, - struct cli_credentials *credentials) + struct cli_credentials *credentials, + struct event_context *ev) { struct smb_composite_connect io; NTSTATUS status; @@ -179,7 +180,7 @@ NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx, io.in.credentials = credentials; io.in.workgroup = lp_workgroup(); - status = smb_composite_connect(&io, parent_ctx); + status = smb_composite_connect(&io, parent_ctx, ev); if (NT_STATUS_IS_OK(status)) { *ret_tree = io.out.tree; } -- cgit From d13e788f20743989ff0d76b13262793027dc66bd Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 16 Jun 2005 23:19:03 +0000 Subject: r7654: - add a timeout to all smb requests (default 60 seconds) - add a request destructor, to make it safe to destroy a pending request with talloc_free() (This used to be commit 72c6988767249caa585f37fec4c0afbf41557ec2) --- source4/libcli/raw/clitransport.c | 46 +++++++++++++++++++++++++++++++++++++++ source4/libcli/raw/libcliraw.h | 4 ++++ 2 files changed, 50 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 05833b2f9a..999795b81e 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -79,6 +79,7 @@ struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock, transport->options.use_spnego = lp_use_spnego(); transport->options.max_xmit = lp_max_xmit(); transport->options.max_mux = lp_maxmux(); + transport->options.request_timeout = SMB_REQUEST_TIMEOUT; transport->negotiate.max_xmit = transport->options.max_xmit; @@ -580,6 +581,42 @@ BOOL smbcli_transport_process(struct smbcli_transport *transport) return True; } +/* + handle timeouts of individual smb requests +*/ +static void smbcli_timeout_handler(struct event_context *ev, struct timed_event *te, + struct timeval t, void *private) +{ + struct smbcli_request *req = talloc_get_type(private, struct smbcli_request); + + if (req->state == SMBCLI_REQUEST_SEND) { + DLIST_REMOVE(req->transport->pending_send, req); + } + if (req->state == SMBCLI_REQUEST_RECV) { + DLIST_REMOVE(req->transport->pending_recv, req); + } + req->status = NT_STATUS_IO_TIMEOUT; + req->state = SMBCLI_REQUEST_ERROR; + if (req->async.fn) { + req->async.fn(req); + } +} + + +/* + destroy a request +*/ +static int smbcli_request_destructor(void *ptr) +{ + struct smbcli_request *req = talloc_get_type(ptr, struct smbcli_request); + if (req->state == SMBCLI_REQUEST_SEND) { + DLIST_REMOVE(req->transport->pending_send, req); + } + if (req->state == SMBCLI_REQUEST_RECV) { + DLIST_REMOVE(req->transport->pending_recv, req); + } + return 0; +} /* @@ -600,4 +637,13 @@ void smbcli_transport_send(struct smbcli_request *req) /* make sure we look for write events */ smbcli_transport_write_enable(req->transport); + + /* add a timeout */ + if (req->transport->options.request_timeout) { + event_add_timed(req->transport->socket->event.ctx, req, + timeval_current_ofs(req->transport->options.request_timeout, 0), + smbcli_timeout_handler, req); + } + + talloc_set_destructor(req, smbcli_request_destructor); } diff --git a/source4/libcli/raw/libcliraw.h b/source4/libcli/raw/libcliraw.h index d7414a237e..2794a22da2 100644 --- a/source4/libcli/raw/libcliraw.h +++ b/source4/libcli/raw/libcliraw.h @@ -28,6 +28,9 @@ struct smbcli_request; /* forward declare */ struct smbcli_session; /* forward declare */ struct smbcli_transport; /* forward declare */ +/* default timeout for all smb requests */ +#define SMB_REQUEST_TIMEOUT 60 + /* context that will be and has been negotiated between the client and server */ struct smbcli_negotiate { /* @@ -88,6 +91,7 @@ struct smbcli_options { uint_t use_spnego:1; uint32_t max_xmit; uint16_t max_mux; + int request_timeout; }; /* this is the context for the client transport layer */ -- cgit From 777b4b021456f5bd8bbadfe97532efc13286e581 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 18 Jun 2005 00:30:49 +0000 Subject: r7705: prevent SIGPIPE. this is what causes BASE-NEGNOWAIT to sometimes fail (This used to be commit 0163d7fe99caee54c6c2bd614e4f076fd00a6176) --- source4/libcli/raw/clisocket.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 7cb7040131..d6007ec8ba 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -63,6 +63,9 @@ struct smbcli_socket *smbcli_sock_init(TALLOC_CTX *mem_ctx, return NULL; } + /* ensure we don't get SIGPIPE */ + BlockSignals(True,SIGPIPE); + return sock; } -- cgit From 025e03de549efa47979199adf80b6eef4c8f926b Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 28 Jun 2005 00:57:15 +0000 Subject: r7970: This SMB signing code (merged from 3.0) turned out to be bogus. Andrew Bartlett (This used to be commit 817160ec1a85724c8bf482f128ea687396de0888) --- source4/libcli/raw/smb_signing.c | 8 -------- 1 file changed, 8 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/smb_signing.c b/source4/libcli/raw/smb_signing.c index 4204f3b4dc..14dfc64737 100644 --- a/source4/libcli/raw/smb_signing.c +++ b/source4/libcli/raw/smb_signing.c @@ -118,15 +118,7 @@ void sign_outgoing_message(struct request_buffer *out, DATA_BLOB *mac_key, uint_ /* Calculate the 16 byte MAC and place first 8 bytes into the field. */ MD5Init(&md5_ctx); - - /* NB. When making and verifying SMB signatures, Windows apparently - zero-pads the key to 128 bits if it isn't long enough. - From Nalin Dahyabhai */ MD5Update(&md5_ctx, mac_key->data, mac_key->length); - if (mac_key->length < sizeof(key_buf)) { - memset(key_buf, 0, sizeof(key_buf)); - MD5Update(&md5_ctx, key_buf, sizeof(key_buf) - mac_key->length); - } MD5Update(&md5_ctx, out->buffer + NBT_HDR_SIZE, out->size - NBT_HDR_SIZE); -- cgit From 1050a54a3bb125af401f27cf0eb5a0ab51b085ea Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 30 Jun 2005 01:34:53 +0000 Subject: r8003: ensure that we don't try to send a trans request with more than 64k data or params (This used to be commit b4f2d17ace6a609ec87da103a89e36edee8903f9) --- source4/libcli/raw/rawtrans.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawtrans.c b/source4/libcli/raw/rawtrans.c index 118ac5e3fd..b523232bc0 100644 --- a/source4/libcli/raw/rawtrans.c +++ b/source4/libcli/raw/rawtrans.c @@ -216,6 +216,14 @@ struct smbcli_request *smb_raw_trans_send_backend(struct smbcli_tree *tree, size_t namelen = 0; uint16_t data_disp, data_length, max_data; + if (parms->in.params.length > UINT16_MAX || + parms->in.data.length > UINT16_MAX) { + DEBUG(3,("Attempt to send invalid trans2 request (params %u, data %u)\n", + parms->in.params.length, parms->in.data.length)); + return NULL; + } + + if (command == SMBtrans) padding = 1; else -- cgit From e0d521ca79314b7c27512565262f614f67e20e64 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 4 Jul 2005 01:23:38 +0000 Subject: r8104: - added support for our client library to not negotiate nt status codes, controlled with 'nt status support' option. - make nt_errstr() display nice strings for dos status codes encoded using NT_STATUS_DOS() - no longer map between dos and nt status codes in the client library, instead return using NT_STATUS_DOS() - fixed the RAW-CONTEXT test to look for NT_STATUS_DOS(ERRSRV, ERRbaduid) instead of NT_STATUS_INVALID_HANDLE (This used to be commit ff5549e87ffae9f062394f30d8fd1ae95b614735) --- source4/libcli/raw/clitransport.c | 21 ++++++++++++++------- source4/libcli/raw/libcliraw.h | 6 +----- source4/libcli/raw/rawnegotiate.c | 6 +++++- 3 files changed, 20 insertions(+), 13 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 999795b81e..51a718b10b 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -476,15 +476,22 @@ static void smbcli_transport_finish_recv(struct smbcli_transport *transport) req->flags2 = SVAL(req->in.hdr, HDR_FLG2); if (!(req->flags2 & FLAGS2_32_BIT_ERROR_CODES)) { - transport->error.etype = ETYPE_DOS; - transport->error.e.dos.eclass = CVAL(req->in.hdr,HDR_RCLS); - transport->error.e.dos.ecode = SVAL(req->in.hdr,HDR_ERR); - req->status = dos_to_ntstatus(transport->error.e.dos.eclass, - transport->error.e.dos.ecode); + int class = CVAL(req->in.hdr,HDR_RCLS); + int code = SVAL(req->in.hdr,HDR_ERR); + if (class == 0 && code == 0) { + transport->error.e.nt_status = NT_STATUS_OK; + } else { + transport->error.e.nt_status = NT_STATUS_DOS(class, code); + } } else { - transport->error.etype = ETYPE_NT; transport->error.e.nt_status = NT_STATUS(IVAL(req->in.hdr, HDR_RCLS)); - req->status = transport->error.e.nt_status; + } + + req->status = transport->error.e.nt_status; + if (NT_STATUS_IS_OK(req->status)) { + transport->error.etype = ETYPE_NONE; + } else { + transport->error.etype = ETYPE_SMB; } if (!smbcli_request_check_sign_mac(req)) { diff --git a/source4/libcli/raw/libcliraw.h b/source4/libcli/raw/libcliraw.h index 2794a22da2..bb13210e74 100644 --- a/source4/libcli/raw/libcliraw.h +++ b/source4/libcli/raw/libcliraw.h @@ -124,12 +124,8 @@ struct smbcli_transport { /* the error fields from the last message */ struct { - enum {ETYPE_NONE, ETYPE_DOS, ETYPE_NT, ETYPE_SOCKET, ETYPE_NBT} etype; + enum {ETYPE_NONE, ETYPE_SMB, ETYPE_SOCKET, ETYPE_NBT} etype; union { - struct { - uint8_t eclass; - uint16_t ecode; - } dos; NTSTATUS nt_status; enum {SOCKET_READ_TIMEOUT, SOCKET_READ_EOF, diff --git a/source4/libcli/raw/rawnegotiate.c b/source4/libcli/raw/rawnegotiate.c index d2d6b66d59..07b9dd572a 100644 --- a/source4/libcli/raw/rawnegotiate.c +++ b/source4/libcli/raw/rawnegotiate.c @@ -174,10 +174,14 @@ NTSTATUS smb_raw_negotiate_recv(struct smbcli_request *req) } /* a way to force ascii SMB */ - if (!lp_unicode() || getenv("SMBCLI_FORCE_ASCII")) { + if (!lp_unicode()) { transport->negotiate.capabilities &= ~CAP_UNICODE; } + if (!lp_nt_status_support()) { + transport->negotiate.capabilities &= ~CAP_STATUS32; + } + failed: return smbcli_request_destroy(req); } -- cgit From 950f6624842628b770bf58424f3b2ab9a7036263 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 4 Jul 2005 02:54:32 +0000 Subject: r8111: fixed the client library to work against w2k3 with nt status codes disabled. The main change is to turn off spnego, which cannot work at all without nt status codes (w2k3 gives a ERRHRD:ERRgeneral error when you try) I also modified NT_STATUS_EQUAL() to allow for nt->dos code equality, but only when nt status codes are disabled in smb.conf. That keeps all the existing torture code working, while still allowing us to correctly catch the cases where forced dos error codes are needed The dos->ntstatus mapping table has been removed completely, as it doesn't really make sense, is impossible to get right, and with the new dos status handling isn't needed. When matching a nt status code to a dos status code it makes far more sense to map from the nt code to the dos code and compare, rather than the reverse, as the nt->dos mapping is what windows has to do internally, so there really is a valid mapping table. (This used to be commit f21274e07b361ef40fdc0fe23e96f1c9c63a091c) --- source4/libcli/raw/clitransport.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 51a718b10b..f286eff0ea 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -76,7 +76,7 @@ struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock, transport->socket = talloc_reference(transport, sock); } transport->negotiate.protocol = PROTOCOL_NT1; - transport->options.use_spnego = lp_use_spnego(); + transport->options.use_spnego = lp_use_spnego() && lp_nt_status_support(); transport->options.max_xmit = lp_max_xmit(); transport->options.max_mux = lp_maxmux(); transport->options.request_timeout = SMB_REQUEST_TIMEOUT; -- cgit From cf601f71aad8e5007e8ec8ac9b455ccd7bda4432 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 4 Jul 2005 10:26:25 +0000 Subject: r8134: remove unused var metze (This used to be commit f308b72b19ab1e0e2f5a732bd1bc13082a634a9c) --- source4/libcli/raw/smb_signing.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/smb_signing.c b/source4/libcli/raw/smb_signing.c index 14dfc64737..df63c33cb9 100644 --- a/source4/libcli/raw/smb_signing.c +++ b/source4/libcli/raw/smb_signing.c @@ -104,7 +104,6 @@ void sign_outgoing_message(struct request_buffer *out, DATA_BLOB *mac_key, uint_ { uint8_t calc_md5_mac[16]; struct MD5Context md5_ctx; - uint8_t key_buf[16]; /* * Firstly put the sequence number into the first 4 bytes. -- cgit From 562498c5260108c17add1e1a392644d188ff5c79 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 13 Jul 2005 03:01:26 +0000 Subject: r8407: fixed a bug left over from our old socket code. Thanks to lha for giving me a login on a netbsd machine to see this (This used to be commit 4e66f682e4f1c31bbe9441a13af2c245db31433d) --- source4/libcli/raw/clisocket.c | 31 ++++++---------------- source4/libcli/raw/clitransport.c | 56 +++++++++++++++++++++++---------------- 2 files changed, 41 insertions(+), 46 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index d6007ec8ba..b325fa473e 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -273,48 +273,33 @@ void smbcli_sock_set_options(struct smbcli_socket *sock, const char *options) /**************************************************************************** Write to socket. Return amount written. ****************************************************************************/ -ssize_t smbcli_sock_write(struct smbcli_socket *sock, const uint8_t *data, size_t len) +NTSTATUS smbcli_sock_write(struct smbcli_socket *sock, const uint8_t *data, + size_t len, size_t *nsent) { - NTSTATUS status; DATA_BLOB blob; - size_t nsent; if (sock->sock == NULL) { - errno = EIO; - return -1; + return NT_STATUS_CONNECTION_DISCONNECTED; } blob.data = discard_const(data); blob.length = len; - status = socket_send(sock->sock, &blob, &nsent, 0); - if (NT_STATUS_IS_ERR(status)) { - return -1; - } - - return nsent; + return socket_send(sock->sock, &blob, nsent, 0); } /**************************************************************************** Read from socket. return amount read ****************************************************************************/ -ssize_t smbcli_sock_read(struct smbcli_socket *sock, uint8_t *data, size_t len) +NTSTATUS smbcli_sock_read(struct smbcli_socket *sock, uint8_t *data, + size_t len, size_t *nread) { - NTSTATUS status; - size_t nread; - if (sock->sock == NULL) { - errno = EIO; - return -1; - } - - status = socket_recv(sock->sock, data, len, &nread, 0); - if (NT_STATUS_IS_ERR(status)) { - return -1; + return NT_STATUS_CONNECTION_DISCONNECTED; } - return nread; + return socket_recv(sock->sock, data, len, nread, 0); } diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index f286eff0ea..d70d333039 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -346,17 +346,19 @@ static void smbcli_transport_process_send(struct smbcli_transport *transport) { while (transport->pending_send) { struct smbcli_request *req = transport->pending_send; - ssize_t ret; - ret = smbcli_sock_write(transport->socket, req->out.buffer, req->out.size); - if (ret == -1) { - if (errno == EAGAIN || errno == EINTR) { - return; - } + NTSTATUS status; + size_t nwritten; + + status = smbcli_sock_write(transport->socket, req->out.buffer, + req->out.size, &nwritten); + if (NT_STATUS_IS_ERR(status)) { smbcli_transport_dead(transport); + } + if (!NT_STATUS_IS_OK(status)) { return; } - req->out.buffer += ret; - req->out.size -= ret; + req->out.buffer += nwritten; + req->out.size -= nwritten; if (req->out.size == 0) { DLIST_REMOVE(transport->pending_send, req); if (req->one_way_request) { @@ -529,17 +531,21 @@ static void smbcli_transport_process_recv(struct smbcli_transport *transport) 4 byte header, which tells us how much more is coming. Then we read the rest */ if (transport->recv_buffer.received < NBT_HDR_SIZE) { - ssize_t ret; - ret = smbcli_sock_read(transport->socket, - transport->recv_buffer.header + - transport->recv_buffer.received, - NBT_HDR_SIZE - transport->recv_buffer.received); - if (ret == -1) { + NTSTATUS status; + size_t nread; + status = smbcli_sock_read(transport->socket, + transport->recv_buffer.header + + transport->recv_buffer.received, + NBT_HDR_SIZE - transport->recv_buffer.received, + &nread); + if (NT_STATUS_IS_ERR(status)) { smbcli_transport_dead(transport); + } + if (!NT_STATUS_IS_OK(status)) { return; } - transport->recv_buffer.received += ret; + transport->recv_buffer.received += nread; if (transport->recv_buffer.received == NBT_HDR_SIZE) { /* we've got a full header */ @@ -555,17 +561,21 @@ static void smbcli_transport_process_recv(struct smbcli_transport *transport) } if (transport->recv_buffer.received < transport->recv_buffer.req_size) { - ssize_t ret; - ret = smbcli_sock_read(transport->socket, - transport->recv_buffer.buffer + - transport->recv_buffer.received, - transport->recv_buffer.req_size - - transport->recv_buffer.received); - if (ret == -1) { + NTSTATUS status; + size_t nread; + status = smbcli_sock_read(transport->socket, + transport->recv_buffer.buffer + + transport->recv_buffer.received, + transport->recv_buffer.req_size - + transport->recv_buffer.received, + &nread); + if (NT_STATUS_IS_ERR(status)) { smbcli_transport_dead(transport); + } + if (!NT_STATUS_IS_OK(status)) { return; } - transport->recv_buffer.received += ret; + transport->recv_buffer.received += nread; } if (transport->recv_buffer.received != 0 && -- cgit From e835621799647ee70630b389fb53d15b15d68355 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 17 Jul 2005 09:20:52 +0000 Subject: r8520: fixed a pile of warnings from the build farm gcc -Wall output on S390. This is an attempt to avoid the panic we're seeing in the automatic builds. The main fixes are: - assumptions that sizeof(size_t) == sizeof(int), mostly in printf formats - use of NULL format statements to perform dn searches. - assumption that sizeof() returns an int (This used to be commit a58ea6b3854973b694d2b1e22323ed7eb00e3a3f) --- source4/libcli/raw/rawfileinfo.c | 4 ++-- source4/libcli/raw/rawfsinfo.c | 4 ++-- source4/libcli/raw/rawsearch.c | 4 ++-- source4/libcli/raw/rawtrans.c | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawfileinfo.c b/source4/libcli/raw/rawfileinfo.c index 9f7786429c..ede4391824 100644 --- a/source4/libcli/raw/rawfileinfo.c +++ b/source4/libcli/raw/rawfileinfo.c @@ -25,12 +25,12 @@ /* local macros to make the code more readable */ #define FINFO_CHECK_MIN_SIZE(size) if (blob->length < (size)) { \ DEBUG(1,("Unexpected FILEINFO reply size %d for level %u - expected min of %d\n", \ - blob->length, parms->generic.level, (size))); \ + (int)blob->length, parms->generic.level, (size))); \ return NT_STATUS_INFO_LENGTH_MISMATCH; \ } #define FINFO_CHECK_SIZE(size) if (blob->length != (size)) { \ DEBUG(1,("Unexpected FILEINFO reply size %d for level %u - expected %d\n", \ - blob->length, parms->generic.level, (size))); \ + (int)blob->length, parms->generic.level, (size))); \ return NT_STATUS_INFO_LENGTH_MISMATCH; \ } diff --git a/source4/libcli/raw/rawfsinfo.c b/source4/libcli/raw/rawfsinfo.c index fd99c4aeb9..3daa1c0f53 100644 --- a/source4/libcli/raw/rawfsinfo.c +++ b/source4/libcli/raw/rawfsinfo.c @@ -115,13 +115,13 @@ static NTSTATUS smb_raw_qfsinfo_blob_recv(struct smbcli_request *req, /* local macros to make the code more readable */ #define QFS_CHECK_MIN_SIZE(size) if (blob.length < (size)) { \ DEBUG(1,("Unexpected QFS reply size %d for level %u - expected min of %d\n", \ - blob.length, fsinfo->generic.level, (size))); \ + (int)blob.length, fsinfo->generic.level, (size))); \ status = NT_STATUS_INFO_LENGTH_MISMATCH; \ goto failed; \ } #define QFS_CHECK_SIZE(size) if (blob.length != (size)) { \ DEBUG(1,("Unexpected QFS reply size %d for level %u - expected %d\n", \ - blob.length, fsinfo->generic.level, (size))); \ + (int)blob.length, fsinfo->generic.level, (size))); \ status = NT_STATUS_INFO_LENGTH_MISMATCH; \ goto failed; \ } diff --git a/source4/libcli/raw/rawsearch.c b/source4/libcli/raw/rawsearch.c index 90715ca8e2..a9b49c07a4 100644 --- a/source4/libcli/raw/rawsearch.c +++ b/source4/libcli/raw/rawsearch.c @@ -643,7 +643,7 @@ NTSTATUS smb_raw_search_first(struct smbcli_tree *tree, if (p_blob.length < 10) { DEBUG(1,("smb_raw_search_first: parms wrong size %d != expected_param_size\n", - p_blob.length)); + (int)p_blob.length)); return NT_STATUS_INVALID_PARAMETER; } @@ -688,7 +688,7 @@ NTSTATUS smb_raw_search_next(struct smbcli_tree *tree, if (p_blob.length != 8) { DEBUG(1,("smb_raw_search_next: parms wrong size %d != expected_param_size\n", - p_blob.length)); + (int)p_blob.length)); return NT_STATUS_INVALID_PARAMETER; } diff --git a/source4/libcli/raw/rawtrans.c b/source4/libcli/raw/rawtrans.c index b523232bc0..207b5bee08 100644 --- a/source4/libcli/raw/rawtrans.c +++ b/source4/libcli/raw/rawtrans.c @@ -219,7 +219,7 @@ struct smbcli_request *smb_raw_trans_send_backend(struct smbcli_tree *tree, if (parms->in.params.length > UINT16_MAX || parms->in.data.length > UINT16_MAX) { DEBUG(3,("Attempt to send invalid trans2 request (params %u, data %u)\n", - parms->in.params.length, parms->in.data.length)); + (unsigned)parms->in.params.length, (unsigned)parms->in.data.length)); return NULL; } -- cgit From 6553dd0c60e922f42de347a02c8f792f087c393c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 28 Jul 2005 00:27:28 +0000 Subject: r8811: Fix the build.. (This used to be commit fac77f5fa267da57a55e88cad8993897e80741a0) --- source4/libcli/raw/rawfsinfo.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawfsinfo.c b/source4/libcli/raw/rawfsinfo.c index 3daa1c0f53..61f5a5027d 100644 --- a/source4/libcli/raw/rawfsinfo.c +++ b/source4/libcli/raw/rawfsinfo.c @@ -22,6 +22,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" +#include "librpc/gen_ndr/ndr_misc.h" /**************************************************************************** Query FS Info - SMBdskattr call (async send) -- cgit From 2fa50ab671ba4a7e552e001f0dfde3a7cc330f8e Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 9 Aug 2005 03:09:47 +0000 Subject: r9222: Rename smb_tree_connect() to smb_raw_tcon() to match other raw function names. (This used to be commit 26b191b3c9529b2dae5d004819dab46657064408) --- source4/libcli/raw/clitree.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index 76cb1a43fe..25f346ef5d 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -56,8 +56,8 @@ struct smbcli_tree *smbcli_tree_init(struct smbcli_session *session, /**************************************************************************** Send a tconX (async send) ****************************************************************************/ -struct smbcli_request *smb_tree_connect_send(struct smbcli_tree *tree, - union smb_tcon *parms) +struct smbcli_request *smb_raw_tcon_send(struct smbcli_tree *tree, + union smb_tcon *parms) { struct smbcli_request *req = NULL; @@ -92,8 +92,8 @@ struct smbcli_request *smb_tree_connect_send(struct smbcli_tree *tree, /**************************************************************************** Send a tconX (async recv) ****************************************************************************/ -NTSTATUS smb_tree_connect_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, - union smb_tcon *parms) +NTSTATUS smb_raw_tcon_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, + union smb_tcon *parms) { uint8_t *p; @@ -134,11 +134,11 @@ failed: /**************************************************************************** Send a tconX (sync interface) ****************************************************************************/ -NTSTATUS smb_tree_connect(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, - union smb_tcon *parms) +NTSTATUS smb_raw_tcon(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, + union smb_tcon *parms) { - struct smbcli_request *req = smb_tree_connect_send(tree, parms); - return smb_tree_connect_recv(req, mem_ctx, parms); + struct smbcli_request *req = smb_raw_tcon_send(tree, parms); + return smb_raw_tcon_recv(req, mem_ctx, parms); } -- cgit From 172cee9adc86ab1950b50ffc008587e6d42585ed Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 9 Aug 2005 04:11:09 +0000 Subject: r9223: Rename smb_raw_session_setup() to smb_raw_sesssetup(). (This used to be commit 5e6d330e7388e47e1b2bfc96fff07682e90f63a5) --- source4/libcli/raw/clisession.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index 130959e776..2942279b12 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -78,7 +78,8 @@ struct smbcli_session *smbcli_session_init(struct smbcli_transport *transport, /**************************************************************************** Perform a session setup (async send) ****************************************************************************/ -struct smbcli_request *smb_raw_session_setup_send(struct smbcli_session *session, union smb_sesssetup *parms) +struct smbcli_request *smb_raw_sesssetup_send(struct smbcli_session *session, + union smb_sesssetup *parms) { struct smbcli_request *req = NULL; @@ -150,9 +151,9 @@ struct smbcli_request *smb_raw_session_setup_send(struct smbcli_session *session /**************************************************************************** Perform a session setup (async recv) ****************************************************************************/ -NTSTATUS smb_raw_session_setup_recv(struct smbcli_request *req, - TALLOC_CTX *mem_ctx, - union smb_sesssetup *parms) +NTSTATUS smb_raw_sesssetup_recv(struct smbcli_request *req, + TALLOC_CTX *mem_ctx, + union smb_sesssetup *parms) { uint16_t len; uint8_t *p; @@ -222,11 +223,11 @@ failed: /* Perform a session setup (sync interface) */ -NTSTATUS smb_raw_session_setup(struct smbcli_session *session, TALLOC_CTX *mem_ctx, - union smb_sesssetup *parms) +NTSTATUS smb_raw_sesssetup(struct smbcli_session *session, + TALLOC_CTX *mem_ctx, union smb_sesssetup *parms) { - struct smbcli_request *req = smb_raw_session_setup_send(session, parms); - return smb_raw_session_setup_recv(req, mem_ctx, parms); + struct smbcli_request *req = smb_raw_sesssetup_send(session, parms); + return smb_raw_sesssetup_recv(req, mem_ctx, parms); } -- cgit From 76787d5da440cd1cb224484c34a86c1baa5787d9 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sat, 13 Aug 2005 01:15:32 +0000 Subject: r9291: Add a stub for smb_raw_lpq() which is in smb_interfaces.h but doesn't seem to be used anywhere yet. (This used to be commit 9e5ce3a28892241e2b080c0fa187ee99042c2330) --- source4/libcli/raw/rawlpq.c | 48 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 source4/libcli/raw/rawlpq.c (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawlpq.c b/source4/libcli/raw/rawlpq.c new file mode 100644 index 0000000000..e83ee48707 --- /dev/null +++ b/source4/libcli/raw/rawlpq.c @@ -0,0 +1,48 @@ +/* + Unix SMB/CIFS implementation. + client lpq operations + Copyright (C) Tim Potter 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. +*/ + +#include "includes.h" +#include "libcli/raw/libcliraw.h" + +/**************************************************************************** + lpq - async send +****************************************************************************/ +struct smbcli_request *smb_raw_lpq_send(struct smbcli_tree *tree, + union smb_lpq *parms) +{ + return NULL; +} + +/**************************************************************************** + lpq - async receive +****************************************************************************/ +NTSTATUS smb_raw_lpq_recv(struct smbcli_request *req, union smb_lpq *parms) +{ + return NT_STATUS_NOT_IMPLEMENTED; +} + +/* + lpq - sync interface +*/ +NTSTATUS smb_raw_lpq(struct smbcli_tree *tree, union smb_lpq *parms) +{ + struct smbcli_request *req = smb_raw_lpq_send(tree, parms); + return smb_raw_lpq_recv(req, parms); +} -- cgit From 5bd6a114711c0033403a656b42574380a6ebcd3d Mon Sep 17 00:00:00 2001 From: Alexander Bokovoy Date: Mon, 22 Aug 2005 14:07:52 +0000 Subject: r9476: Make intention to ignore result of receiving excplicit. Fixes warning found by Coverity (This used to be commit d1b7a4a24c3af1bfcc289a3476c9fb33ed2fb840) --- source4/libcli/raw/rawsearch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawsearch.c b/source4/libcli/raw/rawsearch.c index a9b49c07a4..65928d1154 100644 --- a/source4/libcli/raw/rawsearch.c +++ b/source4/libcli/raw/rawsearch.c @@ -724,7 +724,7 @@ NTSTATUS smb_raw_search_close(struct smbcli_tree *tree, SSVAL(req->out.vwv, VWV(0), io->findclose.in.handle); if (smbcli_request_send(req)) { - smbcli_request_receive(req); + (void) smbcli_request_receive(req); } return smbcli_request_destroy(req); -- cgit From 294f0aaf9ca61a72ed33b8f0b999f6871005da73 Mon Sep 17 00:00:00 2001 From: Alexander Bokovoy Date: Mon, 22 Aug 2005 16:02:11 +0000 Subject: r9479: More fixes for explicit ignoring of returned result to fix Coverity warnings (This used to be commit 4f9f4312e98cce7589fc8e094d08e76cc697ab3d) --- source4/libcli/raw/clitree.c | 2 +- source4/libcli/raw/rawrequest.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index 25f346ef5d..74e14db591 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -153,7 +153,7 @@ NTSTATUS smb_tree_disconnect(struct smbcli_tree *tree) req = smbcli_request_setup(tree, SMBtdis, 0, 0); if (smbcli_request_send(req)) { - smbcli_request_receive(req); + (void) smbcli_request_receive(req); } return smbcli_request_destroy(req); } diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index b49009ac22..e01626a15c 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -389,7 +389,7 @@ BOOL handle_oplock_break(struct smbcli_transport *transport, uint_t len, const u */ NTSTATUS smbcli_request_simple_recv(struct smbcli_request *req) { - smbcli_request_receive(req); + (void) smbcli_request_receive(req); return smbcli_request_destroy(req); } -- cgit From c98c6aa5611f26ab591c50fcded1fc55e81a0d07 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 28 Aug 2005 02:37:14 +0000 Subject: r9702: r9680@blu: tridge | 2005-08-27 18:45:08 +1000 - fixed ncacn_ip_tcp to use the generic async name resolution methods, so NBT names now work (as requested several times by abartlet!) - changed resolve_name() to take an event_context, so it doesn't cause the whole process to block - cleaned up the talloc_find_parent_bytype() calls to go via a cleaner event_context_find() call (This used to be commit b3d491b210a8b889a25efcb273e70fefbd01b7f7) --- source4/libcli/raw/clisocket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index b325fa473e..90fb98603e 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -326,7 +326,7 @@ BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, in nbt_name.type = name_type; nbt_name.scope = NULL; - status = resolve_name(&nbt_name, sock, &address); + status = resolve_name(&nbt_name, sock, &address, sock->event.ctx); if (!NT_STATUS_IS_OK(status)) { return False; } -- cgit From ab4d635b92b116b02b88843b4ec4f5b7517bab1a Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 26 Sep 2005 11:47:55 +0000 Subject: 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) --- source4/libcli/raw/clisocket.c | 16 ++++++++-------- source4/libcli/raw/clitree.c | 1 + 2 files changed, 9 insertions(+), 8 deletions(-) (limited to 'source4/libcli/raw') 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); \ -- cgit From 1c701527fff811ab7a60f38f91937d78509c1c01 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 27 Sep 2005 13:31:17 +0000 Subject: r10542: if the transport is dead we need to return tridge: I think this is correct, comments? metze (This used to be commit e06ca726f3df013d869d943338bc6b7a151cdd3f) --- source4/libcli/raw/clitransport.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index d70d333039..7d4891da00 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -353,6 +353,7 @@ static void smbcli_transport_process_send(struct smbcli_transport *transport) req->out.size, &nwritten); if (NT_STATUS_IS_ERR(status)) { smbcli_transport_dead(transport); + return; } if (!NT_STATUS_IS_OK(status)) { return; @@ -540,6 +541,7 @@ static void smbcli_transport_process_recv(struct smbcli_transport *transport) &nread); if (NT_STATUS_IS_ERR(status)) { smbcli_transport_dead(transport); + return; } if (!NT_STATUS_IS_OK(status)) { return; @@ -571,6 +573,7 @@ static void smbcli_transport_process_recv(struct smbcli_transport *transport) &nread); if (NT_STATUS_IS_ERR(status)) { smbcli_transport_dead(transport); + return; } if (!NT_STATUS_IS_OK(status)) { return; -- cgit From 97e8c5bcecb1fe4ef551906540b3d299f7c9c682 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 6 Oct 2005 05:25:35 +0000 Subject: r10754: fixed a valgrind error for unmatched SMB replies (This used to be commit b714ab64fd79d5cabc39779774fae7c3861a84da) --- source4/libcli/raw/clitransport.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 7d4891da00..b07bd630e9 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -385,7 +385,7 @@ static void smbcli_transport_finish_recv(struct smbcli_transport *transport) { uint8_t *buffer, *hdr, *vwv; int len; - uint16_t wct=0, mid = 0; + uint16_t wct=0, mid = 0, op = 0; struct smbcli_request *req; buffer = transport->recv_buffer.buffer; @@ -424,6 +424,7 @@ static void smbcli_transport_finish_recv(struct smbcli_transport *transport) /* extract the mid for matching to pending requests */ mid = SVAL(hdr, HDR_MID); wct = CVAL(hdr, HDR_WCT); + op = CVAL(hdr, HDR_COM); } /* match the incoming request against the list of pending requests */ @@ -432,8 +433,7 @@ static void smbcli_transport_finish_recv(struct smbcli_transport *transport) } if (!req) { - DEBUG(1,("Discarding unmatched reply with mid %d op %d\n", - mid, CVAL(hdr, HDR_COM))); + DEBUG(1,("Discarding unmatched reply with mid %d op %d\n", mid, op)); goto error; } -- cgit From d617556ef50863d6a03c81a04f0f6b05848a250e Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 10 Oct 2005 19:57:55 +0000 Subject: r10878: Reply to some comments by tridge and metze: * rename the composite helper functions from comp_* to composite_* * Move the lsa initialization to wb_connect_lsa.c * Equip smb_composite_connect with a fallback_to_anonymous The latter two simplify wb_init_domain.c quite a bit. Volker (This used to be commit deb127e04ea01ae93394da5ebffb39d81caeb6d9) --- source4/libcli/raw/clitree.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index cae93bdbe2..990552d64f 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -179,6 +179,7 @@ NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx, io.in.service = service; io.in.service_type = service_type; io.in.credentials = credentials; + io.in.fallback_to_anonymous = False; io.in.workgroup = lp_workgroup(); status = smb_composite_connect(&io, parent_ctx, ev); -- cgit From 134b2488c82ae13392121f71e4960178a38f3e01 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 28 Oct 2005 11:02:42 +0000 Subject: r11369: Implement socket_connect_multi: Connect to multiple ipv4 tcp ports in sequence, with a 2-millisecond timeout between firing the syn packets. Build smbcli_sock_connect_send upon that. Volker (This used to be commit 5718df44d90d113304c5deed1e2e7f82ff9e928f) --- source4/libcli/raw/clisocket.c | 324 ++++++++++++++++++----------------------- 1 file changed, 140 insertions(+), 184 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 688ee8a78b..8b8a0b0faf 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -27,206 +27,130 @@ #include "libcli/composite/composite.h" #include "lib/socket/socket.h" -/* - this private structure is used during async connection handling -*/ -struct clisocket_connect { - int port_num; - int *iports; - struct smbcli_socket *sock; - const char *dest_host_addr; - const char *dest_hostname; +struct sock_connect_state { + struct composite_context *ctx; + const char *host_name; + int num_ports; + uint16_t *ports; + struct smbcli_socket *result; }; - /* - create a smbcli_socket context - The event_ctx is optional - if not supplied one will be created + connect a smbcli_socket context to an IP/port pair + if port is 0 then choose 445 then 139 */ -struct smbcli_socket *smbcli_sock_init(TALLOC_CTX *mem_ctx, - struct event_context *event_ctx) + +static void smbcli_sock_connect_recv_conn(struct composite_context *ctx); + +struct composite_context *smbcli_sock_connect_send(TALLOC_CTX *mem_ctx, + const char *host_addr, + int port, + const char *host_name, + struct event_context *event_ctx) { - struct smbcli_socket *sock; + struct composite_context *result, *ctx; + struct sock_connect_state *state; - sock = talloc_zero(mem_ctx, struct smbcli_socket); - if (!sock) { - return NULL; - } + result = talloc_zero(mem_ctx, struct composite_context); + if (result == NULL) goto failed; + result->state = COMPOSITE_STATE_IN_PROGRESS; - if (event_ctx) { - sock->event.ctx = talloc_reference(sock, event_ctx); + if (event_ctx != NULL) { + result->event_ctx = talloc_reference(result, event_ctx); } else { - sock->event.ctx = event_context_init(sock); - } - if (sock->event.ctx == NULL) { - talloc_free(sock); - return NULL; + result->event_ctx = event_context_init(result); } - /* ensure we don't get SIGPIPE */ - BlockSignals(True,SIGPIPE); + if (result->event_ctx == NULL) goto failed; - return sock; -} + state = talloc(result, struct sock_connect_state); + if (state == NULL) goto failed; + state->ctx = result; + result->private_data = state; -static NTSTATUS smbcli_sock_connect_one(struct smbcli_socket *sock, - const char *hostaddr, int port, - struct composite_context *c); + state->host_name = talloc_strdup(state, host_name); + if (state->host_name == NULL) goto failed; -/* - handle socket write events during an async connect. These happen when the OS - 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_data) -{ - 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 = COMPOSITE_STATE_DONE; - if (c->async.fn) { - c->async.fn(c); - } - return; - } + if (port == 0) { + const char **ports = lp_smb_ports(); + int i; - /* that port failed - try the next port */ - for (i=conn->port_num+1;conn->iports[i];i++) { - conn->port_num = i; - c->status = smbcli_sock_connect_one(conn->sock, - conn->dest_host_addr, - conn->iports[i], c); - if (NT_STATUS_IS_OK(c->status) || - NT_STATUS_EQUAL(c->status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { - return; + for (i=0;ports[i];i++) /* noop */ ; + if (i == 0) { + DEBUG(3, ("no smb ports defined\n")); + goto failed; } + state->num_ports = i; + state->ports = talloc_array(state, uint16_t, i); + if (state->ports == NULL) goto failed; + for (i=0;ports[i];i++) { + state->ports[i] = atoi(ports[i]); + } + } else { + state->ports = talloc_array(state, uint16_t, 1); + if (state->ports == NULL) goto failed; + state->num_ports = 1; + state->ports[0] = port; } - c->state = COMPOSITE_STATE_ERROR; - if (c->async.fn) { - c->async.fn(c); - } -} - - -/* - try to connect to the given address/port -*/ -static NTSTATUS smbcli_sock_connect_one(struct smbcli_socket *sock, - const char *hostaddr, int port, - struct composite_context *c) -{ - NTSTATUS status; - - if (sock->sock) { - talloc_free(sock->sock); - sock->sock = NULL; - } - talloc_free(sock->event.fde); - - status = socket_create("ip", SOCKET_TYPE_STREAM, &sock->sock, 0); - if (!NT_STATUS_IS_OK(status)) { - return status; - } - - talloc_steal(sock, sock->sock); - - /* we initially look for write - see the man page on - non-blocking connect */ - sock->event.fde = event_add_fd(sock->event.ctx, sock, socket_get_fd(sock->sock), - EVENT_FD_WRITE, smbcli_sock_connect_handler, c); + ctx = socket_connect_multi_send(state, host_addr, + state->num_ports, state->ports, + state->ctx->event_ctx); + if (ctx == NULL) goto failed; + ctx->async.fn = smbcli_sock_connect_recv_conn; + ctx->async.private_data = state; + return result; - sock->port = port; - set_blocking(socket_get_fd(sock->sock), False); - - return socket_connect(sock->sock, NULL, 0, hostaddr, port, 0); +failed: + talloc_free(result); + return NULL; } - -/* - connect a smbcli_socket context to an IP/port pair - if port is 0 then choose 445 then 139 - - this is the async send side of the interface -*/ -struct composite_context *smbcli_sock_connect_send(struct smbcli_socket *sock, - const char *host_addr, int port, - const char *host_name) +static void smbcli_sock_connect_recv_conn(struct composite_context *ctx) { - struct composite_context *c; - struct clisocket_connect *conn; - int i; + struct sock_connect_state *state = + talloc_get_type(ctx->async.private_data, + struct sock_connect_state); + struct socket_context *sock; + uint16_t port; - c = talloc_zero(sock, struct composite_context); - if (c == NULL) return NULL; + state->ctx->status = socket_connect_multi_recv(ctx, state, &sock, + &port); + if (!composite_is_ok(state->ctx)) return; - c->event_ctx = sock->event.ctx; + state->ctx->status = + socket_set_option(sock, lp_socket_options(), NULL); + if (!composite_is_ok(state->ctx)) return; - conn = talloc(c, struct clisocket_connect); - if (conn == NULL) goto failed; - conn->sock = sock; + state->result = talloc_zero(state, struct smbcli_socket); + if (composite_nomem(state->result, state->ctx)) return; - /* work out what ports we will try */ - if (port == 0) { - const char **ports = lp_smb_ports(); - for (i=0;ports[i];i++) /* noop */ ; - conn->iports = talloc_array(c, int, i+1); - if (conn->iports == NULL) goto failed; - for (i=0;ports[i];i++) { - conn->iports[i] = atoi(ports[i]); - } - conn->iports[i] = 0; - } else { - conn->iports = talloc_array(c, int, 2); - if (conn->iports == NULL) goto failed; - conn->iports[0] = port; - conn->iports[1] = 0; - } + state->result->sock = talloc_steal(state->result, sock); + state->result->port = port; + state->result->hostname = talloc_steal(sock, state->host_name); - conn->dest_host_addr = talloc_strdup(c, host_addr); - if (conn->dest_host_addr == NULL) goto failed; - - conn->dest_hostname = talloc_strdup(c, host_name); - if (conn->dest_hostname == NULL) goto failed; - - 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 */ - for (i=0;conn->iports[i];i++) { - conn->port_num = i; - conn->sock->port = conn->iports[i]; - c->status = smbcli_sock_connect_one(sock, - conn->dest_host_addr, - conn->iports[i], c); - if (NT_STATUS_IS_OK(c->status) || - NT_STATUS_EQUAL(c->status, NT_STATUS_MORE_PROCESSING_REQUIRED)) { - return c; - } - } + state->result->event.ctx = + talloc_reference(state->result, state->ctx->event_ctx); + if (composite_nomem(state->result->event.ctx, state->ctx)) return; - c->state = COMPOSITE_STATE_ERROR; - return c; - -failed: - talloc_free(c); - return NULL; + composite_done(state->ctx); } /* finish a smbcli_sock_connect_send() operation */ -NTSTATUS smbcli_sock_connect_recv(struct composite_context *c) +NTSTATUS smbcli_sock_connect_recv(struct composite_context *c, + TALLOC_CTX *mem_ctx, + struct smbcli_socket **result) { - NTSTATUS status; - status = composite_wait(c); + NTSTATUS status = composite_wait(c); + if (NT_STATUS_IS_OK(status)) { + struct sock_connect_state *state = + talloc_get_type(c->private_data, + struct sock_connect_state); + *result = talloc_steal(mem_ctx, state->result); + } talloc_free(c); return status; } @@ -237,17 +161,16 @@ NTSTATUS smbcli_sock_connect_recv(struct composite_context *c) sync version of the function */ -NTSTATUS smbcli_sock_connect(struct smbcli_socket *sock, const char *host_addr, int port, - const char *host_name) +NTSTATUS smbcli_sock_connect(TALLOC_CTX *mem_ctx, + const char *host_addr, int port, + const char *host_name, + struct event_context *event_ctx, + struct smbcli_socket **result) { - struct composite_context *c; - - c = smbcli_sock_connect_send(sock, host_addr, port, host_name); - if (c == NULL) { - return NT_STATUS_NO_MEMORY; - } - - return smbcli_sock_connect_recv(c); + struct composite_context *c = + smbcli_sock_connect_send(mem_ctx, host_addr, port, host_name, + event_ctx); + return smbcli_sock_connect_recv(c, mem_ctx, result); } @@ -306,15 +229,39 @@ NTSTATUS smbcli_sock_read(struct smbcli_socket *sock, uint8_t *data, /**************************************************************************** resolve a hostname and connect ****************************************************************************/ -BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, int port) +struct smbcli_socket *smbcli_sock_connect_byname(const char *host, int port, + TALLOC_CTX *mem_ctx, + struct event_context *event_ctx) { int name_type = NBT_NAME_SERVER; const char *address; NTSTATUS status; struct nbt_name nbt_name; char *name, *p; + TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx); + struct smbcli_socket *result; + + if (tmp_ctx == NULL) { + DEBUG(0, ("talloc_new failed\n")); + return NULL; + } + + name = talloc_strdup(tmp_ctx, host); + if (name == NULL) { + DEBUG(0, ("talloc_strdup failed\n")); + talloc_free(tmp_ctx); + return NULL; + } + + if (event_ctx == NULL) { + event_ctx = event_context_init(mem_ctx); + } - name = talloc_strdup(sock, host); + if (event_ctx == NULL) { + DEBUG(0, ("event_context_init failed\n")); + talloc_free(tmp_ctx); + return NULL; + } /* allow hostnames of the form NAME#xx and do a netbios lookup */ if ((p = strchr(name, '#'))) { @@ -322,16 +269,25 @@ BOOL smbcli_sock_connect_byname(struct smbcli_socket *sock, const char *host, in *p = 0; } - nbt_name.name = name; - nbt_name.type = name_type; - nbt_name.scope = NULL; + make_nbt_name(&nbt_name, host, name_type); - status = resolve_name(&nbt_name, sock, &address, sock->event.ctx); + status = resolve_name(&nbt_name, tmp_ctx, &address, event_ctx); if (!NT_STATUS_IS_OK(status)) { + talloc_free(tmp_ctx); return False; } - status = smbcli_sock_connect(sock, address, port, name); + status = smbcli_sock_connect(mem_ctx, address, port, name, event_ctx, + &result); + + if (!NT_STATUS_IS_OK(status)) { + DEBUG(9, ("smbcli_sock_connect failed: %s\n", + nt_errstr(status))); + talloc_free(tmp_ctx); + return NULL; + } + + talloc_free(tmp_ctx); - return NT_STATUS_IS_OK(status); + return result; } -- cgit From 827cbb480c6de7471554c97cb4cef13e5db7b2b3 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 2 Nov 2005 03:08:52 +0000 Subject: r11466: Clear up some memory leaks in smbclient. Andrew Bartlett (This used to be commit 6535959fd7dfddd6bafb77a266ec3a641025f880) --- source4/libcli/raw/clitree.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index 990552d64f..96d36c569c 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -172,10 +172,14 @@ NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx, { struct smb_composite_connect io; NTSTATUS status; + TALLOC_CTX *tmp_ctx = talloc_new(parent_ctx); + if (!tmp_ctx) { + return NT_STATUS_NO_MEMORY; + } io.in.dest_host = dest_host; io.in.port = port; - io.in.called_name = strupper_talloc(parent_ctx, dest_host); + io.in.called_name = strupper_talloc(tmp_ctx, dest_host); io.in.service = service; io.in.service_type = service_type; io.in.credentials = credentials; @@ -186,6 +190,6 @@ NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx, if (NT_STATUS_IS_OK(status)) { *ret_tree = io.out.tree; } - + talloc_free(tmp_ctx); return status; } -- cgit From 1c07c25322802eef7b57dda3975baca6c9114c83 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 9 Nov 2005 08:13:41 +0000 Subject: r11596: switched the libcli/raw/ code over to using the lib/stream/ generic packet parsing code. This simplifies the logic in the raw client library a fair bit (This used to be commit f8d43f1f67876360e1295d85a3c3702d1d60ed7b) --- source4/libcli/raw/clitransport.c | 122 +++++++++++++++----------------------- source4/libcli/raw/libcliraw.h | 9 +-- 2 files changed, 49 insertions(+), 82 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index b07bd630e9..15959ce272 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -25,9 +25,9 @@ #include "lib/socket/socket.h" #include "dlinklist.h" #include "lib/events/events.h" +#include "lib/stream/packet.h" -static void smbcli_transport_process_recv(struct smbcli_transport *transport); static void smbcli_transport_process_send(struct smbcli_transport *transport); /* @@ -40,7 +40,7 @@ static void smbcli_transport_event_handler(struct event_context *ev, struct smbcli_transport *transport = talloc_get_type(private, struct smbcli_transport); if (flags & EVENT_FD_READ) { - smbcli_transport_process_recv(transport); + packet_recv(transport->packet); return; } if (flags & EVENT_FD_WRITE) { @@ -59,6 +59,18 @@ static int transport_destructor(void *ptr) return 0; } + +/* + handle receive errors +*/ +static void smbcli_transport_error(void *private, NTSTATUS status) +{ + struct smbcli_transport *transport = talloc_get_type(private, struct smbcli_transport); + smbcli_transport_dead(transport); +} + +static NTSTATUS smbcli_transport_finish_recv(void *private, DATA_BLOB blob); + /* create a transport structure based on an established socket */ @@ -82,7 +94,20 @@ struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock, transport->options.request_timeout = SMB_REQUEST_TIMEOUT; transport->negotiate.max_xmit = transport->options.max_xmit; - + + /* setup the stream -> packet parser */ + transport->packet = packet_init(transport); + if (transport->packet == NULL) { + talloc_free(transport); + return NULL; + } + packet_set_private(transport->packet, transport); + packet_set_socket(transport->packet, transport->socket->sock); + packet_set_callback(transport->packet, smbcli_transport_finish_recv); + packet_set_full_request(transport->packet, packet_full_request_nbt); + packet_set_error_handler(transport->packet, smbcli_transport_error); + packet_set_event_context(transport->packet, transport->socket->event.ctx); + smbcli_init_signing(transport); ZERO_STRUCT(transport->called); @@ -381,17 +406,17 @@ static void smbcli_transport_process_send(struct smbcli_transport *transport) we have a full request in our receive buffer - match it to a pending request and process */ -static void smbcli_transport_finish_recv(struct smbcli_transport *transport) +static NTSTATUS smbcli_transport_finish_recv(void *private, DATA_BLOB blob) { + struct smbcli_transport *transport = talloc_get_type(private, + struct smbcli_transport); uint8_t *buffer, *hdr, *vwv; int len; uint16_t wct=0, mid = 0, op = 0; struct smbcli_request *req; - buffer = transport->recv_buffer.buffer; - len = transport->recv_buffer.req_size; - - ZERO_STRUCT(transport->recv_buffer); + buffer = blob.data; + len = blob.length; hdr = buffer+NBT_HDR_SIZE; vwv = hdr + HDR_VWV; @@ -399,7 +424,7 @@ static void smbcli_transport_finish_recv(struct smbcli_transport *transport) /* see if it could be an oplock break request */ if (handle_oplock_break(transport, len, hdr, vwv)) { talloc_free(buffer); - return; + return NT_STATUS_OK; } /* at this point we need to check for a readbraw reply, as @@ -514,77 +539,14 @@ async: if (req->async.fn) { req->async.fn(req); } - return; + return NT_STATUS_OK; error: if (req) { DLIST_REMOVE(transport->pending_recv, req); req->state = SMBCLI_REQUEST_ERROR; } -} - -/* - process some pending receives -*/ -static void smbcli_transport_process_recv(struct smbcli_transport *transport) -{ - /* a incoming packet goes through 2 stages - first we read the - 4 byte header, which tells us how much more is coming. Then - we read the rest */ - if (transport->recv_buffer.received < NBT_HDR_SIZE) { - NTSTATUS status; - size_t nread; - status = smbcli_sock_read(transport->socket, - transport->recv_buffer.header + - transport->recv_buffer.received, - NBT_HDR_SIZE - transport->recv_buffer.received, - &nread); - if (NT_STATUS_IS_ERR(status)) { - smbcli_transport_dead(transport); - return; - } - if (!NT_STATUS_IS_OK(status)) { - return; - } - - transport->recv_buffer.received += nread; - - if (transport->recv_buffer.received == NBT_HDR_SIZE) { - /* we've got a full header */ - transport->recv_buffer.req_size = smb_len(transport->recv_buffer.header) + NBT_HDR_SIZE; - transport->recv_buffer.buffer = talloc_size(transport, - NBT_HDR_SIZE+transport->recv_buffer.req_size); - if (transport->recv_buffer.buffer == NULL) { - smbcli_transport_dead(transport); - return; - } - memcpy(transport->recv_buffer.buffer, transport->recv_buffer.header, NBT_HDR_SIZE); - } - } - - if (transport->recv_buffer.received < transport->recv_buffer.req_size) { - NTSTATUS status; - size_t nread; - status = smbcli_sock_read(transport->socket, - transport->recv_buffer.buffer + - transport->recv_buffer.received, - transport->recv_buffer.req_size - - transport->recv_buffer.received, - &nread); - if (NT_STATUS_IS_ERR(status)) { - smbcli_transport_dead(transport); - return; - } - if (!NT_STATUS_IS_OK(status)) { - return; - } - transport->recv_buffer.received += nread; - } - - if (transport->recv_buffer.received != 0 && - transport->recv_buffer.received == transport->recv_buffer.req_size) { - smbcli_transport_finish_recv(transport); - } + return NT_STATUS_OK; } /* @@ -593,8 +555,18 @@ static void smbcli_transport_process_recv(struct smbcli_transport *transport) */ BOOL smbcli_transport_process(struct smbcli_transport *transport) { + NTSTATUS status; + size_t npending; + smbcli_transport_process_send(transport); - smbcli_transport_process_recv(transport); + if (transport->socket->sock == NULL) { + return False; + } + + status = socket_pending(transport->socket->sock, &npending); + if (NT_STATUS_IS_OK(status) && npending > 0) { + packet_recv(transport->packet); + } if (transport->socket->sock == NULL) { return False; } diff --git a/source4/libcli/raw/libcliraw.h b/source4/libcli/raw/libcliraw.h index bb13210e74..a853bd177c 100644 --- a/source4/libcli/raw/libcliraw.h +++ b/source4/libcli/raw/libcliraw.h @@ -154,13 +154,8 @@ struct smbcli_transport { know the server name */ struct nbt_name called; - /* a buffer for partially received SMB packets. */ - struct { - uint8_t header[NBT_HDR_SIZE]; - size_t req_size; - size_t received; - uint8_t *buffer; - } recv_buffer; + /* context of the stream -> packet parser */ + struct packet_context *packet; }; /* this is the context for the user */ -- cgit From dce04d193eb0d195eb000c766921c51260d65f0e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 9 Nov 2005 13:34:36 +0000 Subject: r11606: use the generic packet send code in libcli/raw/ (This used to be commit 0bcea45b15b08cb42d7f6fbbb3a25f73b95f362c) --- source4/libcli/raw/clitransport.c | 100 +++++++++----------------------------- 1 file changed, 23 insertions(+), 77 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 15959ce272..aafdfca74c 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -28,8 +28,6 @@ #include "lib/stream/packet.h" -static void smbcli_transport_process_send(struct smbcli_transport *transport); - /* an event has happened on the socket */ @@ -44,7 +42,7 @@ static void smbcli_transport_event_handler(struct event_context *ev, return; } if (flags & EVENT_FD_WRITE) { - smbcli_transport_process_send(transport); + packet_queue_run(transport->packet); } } @@ -122,6 +120,8 @@ struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock, smbcli_transport_event_handler, transport); + packet_set_serialise(transport->packet, transport->socket->event.fde); + talloc_set_destructor(transport, transport_destructor); return transport; @@ -134,18 +134,7 @@ void smbcli_transport_dead(struct smbcli_transport *transport) { smbcli_sock_dead(transport->socket); - /* all pending sends become errors */ - while (transport->pending_send) { - struct smbcli_request *req = transport->pending_send; - req->state = SMBCLI_REQUEST_ERROR; - req->status = NT_STATUS_NET_WRITE_FAULT; - DLIST_REMOVE(transport->pending_send, req); - if (req->async.fn) { - req->async.fn(req); - } - } - - /* as do all pending receives */ + /* kill all pending receives */ while (transport->pending_recv) { struct smbcli_request *req = transport->pending_recv; req->state = SMBCLI_REQUEST_ERROR; @@ -158,24 +147,6 @@ void smbcli_transport_dead(struct smbcli_transport *transport) } -/* - enable select for write on a transport -*/ -static void smbcli_transport_write_enable(struct smbcli_transport *transport) -{ - struct fd_event *fde = transport->socket->event.fde; - EVENT_FD_WRITEABLE(fde); -} - -/* - disable select for write on a transport -*/ -static void smbcli_transport_write_disable(struct smbcli_transport *transport) -{ - struct fd_event *fde = transport->socket->event.fde; - EVENT_FD_NOT_WRITEABLE(fde); -} - /* send a session request */ @@ -364,44 +335,6 @@ void smbcli_transport_idle_handler(struct smbcli_transport *transport, idle_handler, transport); } -/* - process some pending sends -*/ -static void smbcli_transport_process_send(struct smbcli_transport *transport) -{ - while (transport->pending_send) { - struct smbcli_request *req = transport->pending_send; - NTSTATUS status; - size_t nwritten; - - status = smbcli_sock_write(transport->socket, req->out.buffer, - req->out.size, &nwritten); - if (NT_STATUS_IS_ERR(status)) { - smbcli_transport_dead(transport); - return; - } - if (!NT_STATUS_IS_OK(status)) { - return; - } - req->out.buffer += nwritten; - req->out.size -= nwritten; - if (req->out.size == 0) { - DLIST_REMOVE(transport->pending_send, req); - if (req->one_way_request) { - req->state = SMBCLI_REQUEST_DONE; - smbcli_request_destroy(req); - } else { - req->state = SMBCLI_REQUEST_RECV; - DLIST_ADD(transport->pending_recv, req); - } - } - } - - /* we're out of requests to send, so don't wait for write - events any more */ - smbcli_transport_write_disable(transport); -} - /* we have a full request in our receive buffer - match it to a pending request and process @@ -558,7 +491,7 @@ BOOL smbcli_transport_process(struct smbcli_transport *transport) NTSTATUS status; size_t npending; - smbcli_transport_process_send(transport); + packet_queue_run(transport->packet); if (transport->socket->sock == NULL) { return False; } @@ -616,6 +549,9 @@ static int smbcli_request_destructor(void *ptr) */ void smbcli_transport_send(struct smbcli_request *req) { + DATA_BLOB blob; + NTSTATUS status; + /* check if the transport is dead */ if (req->transport->socket->sock == NULL) { req->state = SMBCLI_REQUEST_ERROR; @@ -623,12 +559,22 @@ void smbcli_transport_send(struct smbcli_request *req) return; } - /* put it on the outgoing socket queue */ - req->state = SMBCLI_REQUEST_SEND; - DLIST_ADD_END(req->transport->pending_send, req, struct smbcli_request *); + /* put it on the socket queue */ + blob = data_blob_const(req->out.buffer, req->out.size); + status = packet_send(req->transport->packet, blob); + if (!NT_STATUS_IS_OK(status)) { + req->state = SMBCLI_REQUEST_ERROR; + req->status = status; + return; + } - /* make sure we look for write events */ - smbcli_transport_write_enable(req->transport); + if (req->one_way_request) { + req->state = SMBCLI_REQUEST_DONE; + smbcli_request_destroy(req); + } else { + req->state = SMBCLI_REQUEST_RECV; + DLIST_ADD(req->transport->pending_recv, req); + } /* add a timeout */ if (req->transport->options.request_timeout) { -- cgit From ac842774e4538d3e25159f1ff0bc273bc3c5faeb Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 9 Nov 2005 14:00:31 +0000 Subject: r11609: fixed handling of one way requests with new send code (This used to be commit d2b568a1114015839ca59c6f32bde4b06ea81ef9) --- source4/libcli/raw/clitransport.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index aafdfca74c..bc00b19ef5 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -571,11 +571,12 @@ void smbcli_transport_send(struct smbcli_request *req) if (req->one_way_request) { req->state = SMBCLI_REQUEST_DONE; smbcli_request_destroy(req); - } else { - req->state = SMBCLI_REQUEST_RECV; - DLIST_ADD(req->transport->pending_recv, req); + return; } + req->state = SMBCLI_REQUEST_RECV; + DLIST_ADD(req->transport->pending_recv, req); + /* add a timeout */ if (req->transport->options.request_timeout) { event_add_timed(req->transport->socket->event.ctx, req, -- cgit From 0eeedb97a5b28c20edcf13d37e52b8e8b98567f6 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 10 Nov 2005 03:48:56 +0000 Subject: r11626: Fix unhandled enum in case statement warnings by noting appropriately that some values aren't handled. The remaining warnings I think are actual bugs or required functionality that is missing (mostly lack of server side Unix extensions). (This used to be commit 03c7da27a06736f2a27d76e6a00a24ab54453af9) --- source4/libcli/raw/rawsetfileinfo.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawsetfileinfo.c b/source4/libcli/raw/rawsetfileinfo.c index 7934171ab0..5e780757e8 100644 --- a/source4/libcli/raw/rawsetfileinfo.c +++ b/source4/libcli/raw/rawsetfileinfo.c @@ -124,6 +124,18 @@ static BOOL smb_raw_setinfo_backend(struct smbcli_tree *tree, NEED_BLOB(4); SIVAL(blob->data, 0, parms->mode_information.in.mode); return True; + + /* Unhandled levels */ + + case RAW_SFILEINFO_UNIX_LINK: + case RAW_SFILEINFO_UNIX_HLINK: + case RAW_SFILEINFO_1023: + case RAW_SFILEINFO_1025: + case RAW_SFILEINFO_1029: + case RAW_SFILEINFO_1032: + case RAW_SFILEINFO_1039: + case RAW_SFILEINFO_1040: + break; } return False; -- cgit From 4c9ba2ffa13ebfe7e8a289ad3d27864fef7917d6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 10 Nov 2005 05:26:53 +0000 Subject: r11632: removed 2 unused functions (This used to be commit fa904afed93a350dd0dcd3cddc1521a4a1ad6711) --- source4/libcli/raw/clisocket.c | 33 --------------------------------- 1 file changed, 33 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 8b8a0b0faf..be25b36007 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -193,39 +193,6 @@ void smbcli_sock_set_options(struct smbcli_socket *sock, const char *options) socket_set_option(sock->sock, options, NULL); } -/**************************************************************************** - Write to socket. Return amount written. -****************************************************************************/ -NTSTATUS smbcli_sock_write(struct smbcli_socket *sock, const uint8_t *data, - size_t len, size_t *nsent) -{ - DATA_BLOB blob; - - if (sock->sock == NULL) { - return NT_STATUS_CONNECTION_DISCONNECTED; - } - - blob.data = discard_const(data); - blob.length = len; - - return socket_send(sock->sock, &blob, nsent, 0); -} - - -/**************************************************************************** - Read from socket. return amount read -****************************************************************************/ -NTSTATUS smbcli_sock_read(struct smbcli_socket *sock, uint8_t *data, - size_t len, size_t *nread) -{ - if (sock->sock == NULL) { - return NT_STATUS_CONNECTION_DISCONNECTED; - } - - return socket_recv(sock->sock, data, len, nread, 0); -} - - /**************************************************************************** resolve a hostname and connect ****************************************************************************/ -- cgit From 7118df6df0970ce3403056a2ee073c18d0b06bd7 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 10 Nov 2005 09:12:36 +0000 Subject: r11635: fix a handling of packet_send in the smb client lib this was cause of the PANIC on the build farm on metze01 as we use req->out.buffer from the old request in the smb_raw_ntcancel() and send a 0 TID, that causes our server code to crash (a fix for the server code will follow) metze (This used to be commit 97cd824e44b03178706b108c7a78753faf412e8f) --- source4/libcli/raw/clitransport.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index bc00b19ef5..6bf79ecfb0 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -559,7 +559,16 @@ void smbcli_transport_send(struct smbcli_request *req) return; } - /* put it on the socket queue */ + /* put it on the socket queue + * - as the buffer is a part of the smbcli_request struct + * we need to reference it here, because packet_queue_run() + * will call talloc_free() on it + */ + if (!talloc_reference(req, req->out.buffer)) { + req->state = SMBCLI_REQUEST_ERROR; + req->status = NT_STATUS_NO_MEMORY; + return; + } blob = data_blob_const(req->out.buffer, req->out.size); status = packet_send(req->transport->packet, blob); if (!NT_STATUS_IS_OK(status)) { -- cgit From 872b821fca36bf543f2c3baf1296f25d1cb7e5a7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 10 Nov 2005 11:10:40 +0000 Subject: r11636: a bit neater solution to the nt_cancel problem (This used to be commit ba7864b07eebecd4d4eb2ce515412a49964ae179) --- source4/libcli/raw/clitransport.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 6bf79ecfb0..1cd706f11e 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -105,6 +105,7 @@ struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock, packet_set_full_request(transport->packet, packet_full_request_nbt); packet_set_error_handler(transport->packet, smbcli_transport_error); packet_set_event_context(transport->packet, transport->socket->event.ctx); + packet_set_nofree(transport->packet); smbcli_init_signing(transport); @@ -559,16 +560,6 @@ void smbcli_transport_send(struct smbcli_request *req) return; } - /* put it on the socket queue - * - as the buffer is a part of the smbcli_request struct - * we need to reference it here, because packet_queue_run() - * will call talloc_free() on it - */ - if (!talloc_reference(req, req->out.buffer)) { - req->state = SMBCLI_REQUEST_ERROR; - req->status = NT_STATUS_NO_MEMORY; - return; - } blob = data_blob_const(req->out.buffer, req->out.size); status = packet_send(req->transport->packet, blob); if (!NT_STATUS_IS_OK(status)) { -- cgit From aecff39aacbc7d033330bb25c5a3a39cb65ea2c0 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 10 Nov 2005 14:16:50 +0000 Subject: r11644: free the buffer when it's not used metze (This used to be commit 16f2d92618a55188d260cadd144281b325cdacda) --- source4/libcli/raw/clitransport.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 1cd706f11e..4fed2ed9a0 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -479,6 +479,8 @@ error: if (req) { DLIST_REMOVE(transport->pending_recv, req); req->state = SMBCLI_REQUEST_ERROR; + } else { + talloc_free(buffer); } return NT_STATUS_OK; } -- cgit From 507286dbcdeeba77e630852257489129e7211b46 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 10 Nov 2005 15:27:27 +0000 Subject: r11647: add smbcli_ prefix metze (This used to be commit 356e7d037cf3fc24844b2efa5071917ea03e6163) --- source4/libcli/raw/clitransport.c | 2 +- source4/libcli/raw/rawrequest.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 4fed2ed9a0..f579457252 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -356,7 +356,7 @@ static NTSTATUS smbcli_transport_finish_recv(void *private, DATA_BLOB blob) vwv = hdr + HDR_VWV; /* see if it could be an oplock break request */ - if (handle_oplock_break(transport, len, hdr, vwv)) { + if (smbcli_handle_oplock_break(transport, len, hdr, vwv)) { talloc_free(buffer); return NT_STATUS_OK; } diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index e01626a15c..33ac9c55b1 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -360,7 +360,7 @@ BOOL smbcli_request_receive_more(struct smbcli_request *req) handle oplock break requests from the server - return True if the request was an oplock break */ -BOOL handle_oplock_break(struct smbcli_transport *transport, uint_t len, const uint8_t *hdr, const uint8_t *vwv) +BOOL smbcli_handle_oplock_break(struct smbcli_transport *transport, uint_t len, const uint8_t *hdr, const uint8_t *vwv) { /* we must be very fussy about what we consider an oplock break to avoid matching readbraw replies */ -- cgit From 3b42d207efccbb31f94626f8fd98379e4a32cc35 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 10 Nov 2005 16:09:44 +0000 Subject: r11649: - add support for ntcancel replies (they only happen in error cases, e.g when you supply an invalid TID or VUID) - as we don't yet understand how to check the smb_signing of this replies, we just ignore the whole packet abartlet,jra,tridge: can someone try to find out how to create and verify the signatures for this replies. what I noticed is that still use the increment by one for the request, and later requests are still generated fine, only the generating and verifying of the ntcancel replies make problems metze (This used to be commit e6eb0fd2c2f45d6f612d74c6b527c7b17094c907) --- source4/libcli/raw/clitransport.c | 3 +++ source4/libcli/raw/libcliraw.h | 3 +++ source4/libcli/raw/rawnotify.c | 43 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 49 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index f579457252..2580df4aeb 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -391,6 +391,9 @@ static NTSTATUS smbcli_transport_finish_recv(void *private, DATA_BLOB blob) if (req->mid == mid) break; } + /* see if it's a ntcancel reply for the current MID */ + req = smbcli_handle_ntcancel_reply(req, len, hdr); + if (!req) { DEBUG(1,("Discarding unmatched reply with mid %d op %d\n", mid, op)); goto error; diff --git a/source4/libcli/raw/libcliraw.h b/source4/libcli/raw/libcliraw.h index a853bd177c..dfc4dc37b5 100644 --- a/source4/libcli/raw/libcliraw.h +++ b/source4/libcli/raw/libcliraw.h @@ -231,6 +231,9 @@ struct smbcli_request { /* the sequence number of this packet - used for signing */ uint_t seq_num; + /* list of ntcancel request for this requests */ + struct smbcli_request *ntcancel; + /* set if this is a one-way request, meaning we are not expecting a reply from the server. */ uint_t one_way_request:1; diff --git a/source4/libcli/raw/rawnotify.c b/source4/libcli/raw/rawnotify.c index e48545419f..1215a93f59 100644 --- a/source4/libcli/raw/rawnotify.c +++ b/source4/libcli/raw/rawnotify.c @@ -20,6 +20,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" +#include "dlinklist.h" /**************************************************************************** change notify (async send) @@ -89,6 +90,37 @@ NTSTATUS smb_raw_changenotify_recv(struct smbcli_request *req, return NT_STATUS_OK; } +/**************************************************************************** + handle ntcancel replies from the server, + as the MID of the real reply and the ntcancel reply is the same + we need to do find out to what request the reply belongs +****************************************************************************/ +struct smbcli_request *smbcli_handle_ntcancel_reply(struct smbcli_request *req, + uint_t len, const uint8_t *hdr) +{ + struct smbcli_request *ntcancel; + + if (!req) return req; + + if (!req->ntcancel) return req; + + if (len >= MIN_SMB_SIZE + NBT_HDR_SIZE && + (CVAL(hdr, HDR_FLG) & FLAG_REPLY) && + CVAL(hdr,HDR_COM) == SMBntcancel) { + ntcancel = req->ntcancel; + DLIST_REMOVE(req->ntcancel, ntcancel); + + /* + * TODO: untill we understand how the + * smb_signing works for this case we + * return NULL, to just ignore the packet + */ + /*return ntcancel;*/ + return NULL; + } + + return req; +} /**************************************************************************** Send a NT Cancel request - used to hurry along a pending request. Usually @@ -111,7 +143,18 @@ NTSTATUS smb_raw_ntcancel(struct smbcli_request *oldreq) req->sign_single_increment = 1; req->one_way_request = 1; + /* + * smbcli_request_send() free's oneway requests + * but we want to keep it under oldreq->ntcancel + */ + if (!talloc_reference(oldreq, req)) { + talloc_free(req); + return NT_STATUS_NO_MEMORY; + } + smbcli_request_send(req); + DLIST_ADD_END(oldreq->ntcancel, req, struct smbcli_request *); + return NT_STATUS_OK; } -- cgit From b18ed75a75c111f23701295f31ecf3a117488e00 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 11 Nov 2005 01:38:39 +0000 Subject: r11660: - the libcli/raw/ lib no longer uses the SMBCLI_REQUEST_SEND state, or the associated send queue - fixed negnowait to not watch for the SMBCLI_REQUEST_SEND state (This used to be commit d19235ede5d352d0b0373d204f4357dddde5946f) --- source4/libcli/raw/clitransport.c | 6 ------ source4/libcli/raw/libcliraw.h | 4 ---- 2 files changed, 10 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 2580df4aeb..2aebb92790 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -520,9 +520,6 @@ static void smbcli_timeout_handler(struct event_context *ev, struct timed_event { struct smbcli_request *req = talloc_get_type(private, struct smbcli_request); - if (req->state == SMBCLI_REQUEST_SEND) { - DLIST_REMOVE(req->transport->pending_send, req); - } if (req->state == SMBCLI_REQUEST_RECV) { DLIST_REMOVE(req->transport->pending_recv, req); } @@ -540,9 +537,6 @@ static void smbcli_timeout_handler(struct event_context *ev, struct timed_event static int smbcli_request_destructor(void *ptr) { struct smbcli_request *req = talloc_get_type(ptr, struct smbcli_request); - if (req->state == SMBCLI_REQUEST_SEND) { - DLIST_REMOVE(req->transport->pending_send, req); - } if (req->state == SMBCLI_REQUEST_RECV) { DLIST_REMOVE(req->transport->pending_recv, req); } diff --git a/source4/libcli/raw/libcliraw.h b/source4/libcli/raw/libcliraw.h index dfc4dc37b5..decee83eb7 100644 --- a/source4/libcli/raw/libcliraw.h +++ b/source4/libcli/raw/libcliraw.h @@ -144,9 +144,6 @@ struct smbcli_transport { void *private; } oplock; - /* a list of async requests that are pending for send on this connection */ - struct smbcli_request *pending_send; - /* a list of async requests that are pending for receive on this connection */ struct smbcli_request *pending_recv; @@ -199,7 +196,6 @@ struct smbcli_tree { a client request moves between the following 4 states. */ enum smbcli_request_state {SMBCLI_REQUEST_INIT, /* we are creating the request */ - SMBCLI_REQUEST_SEND, /* the request is in the outgoing socket Q */ SMBCLI_REQUEST_RECV, /* we are waiting for a matching reply */ SMBCLI_REQUEST_DONE, /* the request is finished */ SMBCLI_REQUEST_ERROR}; /* a packet or transport level error has occurred */ -- cgit From 3015c6ba0435c9e99c202890e50187db891d761d Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 11 Nov 2005 07:38:25 +0000 Subject: r11669: - make sure req is initialized - call async callback on error metze (This used to be commit 43aa5cffd3fd8bf07b236a039f5146e1e44296c6) --- source4/libcli/raw/clitransport.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 2aebb92790..fba6c36bbe 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -347,7 +347,7 @@ static NTSTATUS smbcli_transport_finish_recv(void *private, DATA_BLOB blob) uint8_t *buffer, *hdr, *vwv; int len; uint16_t wct=0, mid = 0, op = 0; - struct smbcli_request *req; + struct smbcli_request *req = NULL; buffer = blob.data; len = blob.length; @@ -482,6 +482,9 @@ error: if (req) { DLIST_REMOVE(transport->pending_recv, req); req->state = SMBCLI_REQUEST_ERROR; + if (req->async.fn) { + req->async.fn(req); + } } else { talloc_free(buffer); } -- cgit From 614950aed35353854019db5cccec5b3154643ca3 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 14 Nov 2005 03:45:57 +0000 Subject: r11713: separate out the setting of the fde in the packet context from the enabling of packet serialisation (This used to be commit 6a47cd65a8b588f9ddd375c57caaba08281e7cbb) --- source4/libcli/raw/clitransport.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index fba6c36bbe..b60ea1dc02 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -121,7 +121,8 @@ struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock, smbcli_transport_event_handler, transport); - packet_set_serialise(transport->packet, transport->socket->event.fde); + packet_set_fde(transport->packet, transport->socket->event.fde); + packet_set_serialise(transport->packet); talloc_set_destructor(transport, transport_destructor); -- cgit From 6f49a2404cde1e3e8a20e7ce270e28191ab9037e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 14 Nov 2005 03:48:55 +0000 Subject: r11714: put in a workaround for a winbind problem volker asked me about. The problem is that winbind currently relies on being able to receive on a smb connection from within the same connections receive routine. This means it relies on a non-serialised connection, so disable the serialisation until winbind is fixed. The correct fix will be to get rid of full_request() in dcerpc.c so that bind requests can be fully async. (This used to be commit c4115293d83a4a6d103e049c5832d4bcdc0a9dbc) --- source4/libcli/raw/clitransport.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index b60ea1dc02..83b73f2e30 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -122,8 +122,11 @@ struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock, transport); packet_set_fde(transport->packet, transport->socket->event.fde); +#if 0 + /* winbind relies on non-serialised connections for dcerpc bind. Once that is + fixed we can go back to serialised connections */ packet_set_serialise(transport->packet); - +#endif talloc_set_destructor(transport, transport_destructor); return transport; -- cgit From b51703baf152c309ce325ce573c1683d7e503122 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 15 Nov 2005 04:38:59 +0000 Subject: r11730: added parsing and tests for a bunch more SMB2 getinfo levels (This used to be commit ca65bf0235cbfab451e5d5ceac9f714acc0cd46c) --- source4/libcli/raw/rawfileinfo.c | 74 +++++++++++++++++++++++++--------------- 1 file changed, 46 insertions(+), 28 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawfileinfo.c b/source4/libcli/raw/rawfileinfo.c index ede4391824..f631522182 100644 --- a/source4/libcli/raw/rawfileinfo.c +++ b/source4/libcli/raw/rawfileinfo.c @@ -34,6 +34,51 @@ return NT_STATUS_INFO_LENGTH_MISMATCH; \ } +/* + parse a stream information structure +*/ +NTSTATUS smbcli_parse_stream_info(DATA_BLOB blob, TALLOC_CTX *mem_ctx, + struct stream_information *io) +{ + uint32_t ofs = 0; + io->num_streams = 0; + io->streams = NULL; + + while (blob.length - ofs >= 24) { + uint_t n = io->num_streams; + uint32_t nlen, len; + ssize_t size; + void *vstr; + io->streams = + talloc_realloc(mem_ctx, io->streams, struct stream_struct, n+1); + if (!io->streams) { + return NT_STATUS_NO_MEMORY; + } + nlen = IVAL(blob.data, ofs + 0x04); + io->streams[n].size = BVAL(blob.data, ofs + 0x08); + io->streams[n].alloc_size = BVAL(blob.data, ofs + 0x10); + if (nlen > blob.length - (ofs + 24)) { + return NT_STATUS_INFO_LENGTH_MISMATCH; + } + size = convert_string_talloc(io->streams, CH_UTF16, CH_UNIX, + blob.data+ofs+24, nlen, &vstr); + if (size == -1) { + return NT_STATUS_ILLEGAL_CHARACTER; + } + io->streams[n].stream_name.s = vstr; + io->streams[n].stream_name.private_length = nlen; + io->num_streams++; + len = IVAL(blob.data, ofs); + if (len > blob.length - ofs) { + return NT_STATUS_INFO_LENGTH_MISMATCH; + } + if (len == 0) break; + ofs += len; + } + + return NT_STATUS_OK; +} + /**************************************************************************** Handle qfileinfo/qpathinfo trans2 backend. ****************************************************************************/ @@ -42,8 +87,6 @@ static NTSTATUS smb_raw_info_backend(struct smbcli_session *session, union smb_fileinfo *parms, DATA_BLOB *blob) { - uint_t len, ofs; - switch (parms->generic.level) { case RAW_FILEINFO_GENERIC: case RAW_FILEINFO_GETATTR: @@ -175,32 +218,7 @@ static NTSTATUS smb_raw_info_backend(struct smbcli_session *session, case RAW_FILEINFO_STREAM_INFO: case RAW_FILEINFO_STREAM_INFORMATION: - ofs = 0; - parms->stream_info.out.num_streams = 0; - parms->stream_info.out.streams = NULL; - - while (blob->length - ofs >= 24) { - uint_t n = parms->stream_info.out.num_streams; - parms->stream_info.out.streams = - talloc_realloc(mem_ctx, - parms->stream_info.out.streams, - struct stream_struct, - n+1); - if (!parms->stream_info.out.streams) { - return NT_STATUS_NO_MEMORY; - } - parms->stream_info.out.streams[n].size = BVAL(blob->data, ofs + 8); - parms->stream_info.out.streams[n].alloc_size = BVAL(blob->data, ofs + 16); - smbcli_blob_pull_string(session, mem_ctx, blob, - &parms->stream_info.out.streams[n].stream_name, - ofs+4, ofs+24, STR_UNICODE); - parms->stream_info.out.num_streams++; - len = IVAL(blob->data, ofs); - if (len > blob->length - ofs) return NT_STATUS_INFO_LENGTH_MISMATCH; - if (len == 0) break; - ofs += len; - } - return NT_STATUS_OK; + return smbcli_parse_stream_info(*blob, mem_ctx, &parms->stream_info.out); case RAW_FILEINFO_INTERNAL_INFORMATION: FINFO_CHECK_SIZE(8); -- cgit From c3cd4a0087d61a147f4a2f06f1668230f6704e7c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 17 Nov 2005 06:27:18 +0000 Subject: r11756: split out the parsers for the pass-through levels of QFSINFO and QFILEINFO levels in trans2, so they can be shared with SMB2 (This used to be commit 5ca2d609e6a3766ebd07763f850ecc62209a7db7) --- source4/libcli/raw/rawfileinfo.c | 261 ++++++++++++++++++++++++++------------- source4/libcli/raw/rawfsinfo.c | 141 ++++++++++++++------- source4/libcli/raw/rawrequest.c | 18 +-- 3 files changed, 277 insertions(+), 143 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawfileinfo.c b/source4/libcli/raw/rawfileinfo.c index f631522182..2edb6d5b42 100644 --- a/source4/libcli/raw/rawfileinfo.c +++ b/source4/libcli/raw/rawfileinfo.c @@ -79,67 +79,14 @@ NTSTATUS smbcli_parse_stream_info(DATA_BLOB blob, TALLOC_CTX *mem_ctx, return NT_STATUS_OK; } -/**************************************************************************** - Handle qfileinfo/qpathinfo trans2 backend. -****************************************************************************/ -static NTSTATUS smb_raw_info_backend(struct smbcli_session *session, - TALLOC_CTX *mem_ctx, - union smb_fileinfo *parms, - DATA_BLOB *blob) +/* + parse the fsinfo 'passthru' level replies +*/ +NTSTATUS smb_raw_fileinfo_passthru_parse(const DATA_BLOB *blob, TALLOC_CTX *mem_ctx, + enum smb_fileinfo_level level, + union smb_fileinfo *parms) { - switch (parms->generic.level) { - case RAW_FILEINFO_GENERIC: - case RAW_FILEINFO_GETATTR: - case RAW_FILEINFO_GETATTRE: - case RAW_FILEINFO_SEC_DESC: - /* not handled here */ - return NT_STATUS_INVALID_LEVEL; - - case RAW_FILEINFO_STANDARD: - FINFO_CHECK_SIZE(22); - parms->standard.out.create_time = raw_pull_dos_date2(session->transport, - blob->data + 0); - parms->standard.out.access_time = raw_pull_dos_date2(session->transport, - blob->data + 4); - parms->standard.out.write_time = raw_pull_dos_date2(session->transport, - blob->data + 8); - parms->standard.out.size = IVAL(blob->data, 12); - parms->standard.out.alloc_size = IVAL(blob->data, 16); - parms->standard.out.attrib = SVAL(blob->data, 20); - return NT_STATUS_OK; - - case RAW_FILEINFO_EA_SIZE: - FINFO_CHECK_SIZE(26); - parms->ea_size.out.create_time = raw_pull_dos_date2(session->transport, - blob->data + 0); - parms->ea_size.out.access_time = raw_pull_dos_date2(session->transport, - blob->data + 4); - parms->ea_size.out.write_time = raw_pull_dos_date2(session->transport, - blob->data + 8); - parms->ea_size.out.size = IVAL(blob->data, 12); - parms->ea_size.out.alloc_size = IVAL(blob->data, 16); - parms->ea_size.out.attrib = SVAL(blob->data, 20); - parms->ea_size.out.ea_size = IVAL(blob->data, 22); - return NT_STATUS_OK; - - case RAW_FILEINFO_EA_LIST: - FINFO_CHECK_MIN_SIZE(4); - return ea_pull_list(blob, mem_ctx, - &parms->ea_list.out.num_eas, - &parms->ea_list.out.eas); - - case RAW_FILEINFO_ALL_EAS: - FINFO_CHECK_MIN_SIZE(4); - return ea_pull_list(blob, mem_ctx, - &parms->all_eas.out.num_eas, - &parms->all_eas.out.eas); - - case RAW_FILEINFO_IS_NAME_VALID: - /* no data! */ - FINFO_CHECK_SIZE(0); - return NT_STATUS_OK; - - case RAW_FILEINFO_BASIC_INFO: + switch (level) { case RAW_FILEINFO_BASIC_INFORMATION: /* some servers return 40 bytes and some 36. w2k3 return 40, so thats what we should do, but we need to accept 36 */ @@ -153,7 +100,6 @@ static NTSTATUS smb_raw_info_backend(struct smbcli_session *session, parms->basic_info.out.attrib = IVAL(blob->data, 32); return NT_STATUS_OK; - case RAW_FILEINFO_STANDARD_INFO: case RAW_FILEINFO_STANDARD_INFORMATION: FINFO_CHECK_SIZE(24); parms->standard_info.out.alloc_size = BVAL(blob->data, 0); @@ -163,20 +109,17 @@ static NTSTATUS smb_raw_info_backend(struct smbcli_session *session, parms->standard_info.out.directory = CVAL(blob->data, 21); return NT_STATUS_OK; - case RAW_FILEINFO_EA_INFO: case RAW_FILEINFO_EA_INFORMATION: FINFO_CHECK_SIZE(4); parms->ea_info.out.ea_size = IVAL(blob->data, 0); return NT_STATUS_OK; - case RAW_FILEINFO_NAME_INFO: case RAW_FILEINFO_NAME_INFORMATION: FINFO_CHECK_MIN_SIZE(4); - smbcli_blob_pull_string(session, mem_ctx, blob, - &parms->name_info.out.fname, 0, 4, STR_UNICODE); + smbcli_blob_pull_string(NULL, mem_ctx, blob, + &parms->name_info.out.fname, 0, 4, STR_UNICODE); return NT_STATUS_OK; - case RAW_FILEINFO_ALL_INFO: case RAW_FILEINFO_ALL_INFORMATION: FINFO_CHECK_MIN_SIZE(72); parms->all_info.out.create_time = smbcli_pull_nttime(blob->data, 0); @@ -191,8 +134,8 @@ static NTSTATUS smb_raw_info_backend(struct smbcli_session *session, parms->all_info.out.directory = CVAL(blob->data, 61); #if 1 parms->all_info.out.ea_size = IVAL(blob->data, 64); - smbcli_blob_pull_string(session, mem_ctx, blob, - &parms->all_info.out.fname, 68, 72, STR_UNICODE); + smbcli_blob_pull_string(NULL, mem_ctx, blob, + &parms->all_info.out.fname, 68, 72, STR_UNICODE); #else /* this is what the CIFS spec says - and its totally wrong, but its useful having it here so we can @@ -204,19 +147,17 @@ static NTSTATUS smb_raw_info_backend(struct smbcli_session *session, mode 4 bytes at 88 alignment 4 bytes at 92 */ - smbcli_blob_pull_string(session, mem_ctx, blob, + smbcli_blob_pull_string(NULL, mem_ctx, blob, &parms->all_info.out.fname, 96, 100, STR_UNICODE); #endif return NT_STATUS_OK; - case RAW_FILEINFO_ALT_NAME_INFO: case RAW_FILEINFO_ALT_NAME_INFORMATION: FINFO_CHECK_MIN_SIZE(4); - smbcli_blob_pull_string(session, mem_ctx, blob, - &parms->alt_name_info.out.fname, 0, 4, STR_UNICODE); + smbcli_blob_pull_string(NULL, mem_ctx, blob, + &parms->alt_name_info.out.fname, 0, 4, STR_UNICODE); return NT_STATUS_OK; - case RAW_FILEINFO_STREAM_INFO: case RAW_FILEINFO_STREAM_INFORMATION: return smbcli_parse_stream_info(*blob, mem_ctx, &parms->stream_info.out); @@ -235,6 +176,12 @@ static NTSTATUS smb_raw_info_backend(struct smbcli_session *session, parms->position_information.out.position = BVAL(blob->data, 0); return NT_STATUS_OK; + case RAW_FILEINFO_FULL_EA_INFORMATION: + FINFO_CHECK_MIN_SIZE(4); + return ea_pull_list_chained(blob, mem_ctx, + &parms->all_eas.out.num_eas, + &parms->all_eas.out.eas); + case RAW_FILEINFO_MODE_INFORMATION: FINFO_CHECK_SIZE(4); parms->mode_information.out.mode = IVAL(blob->data, 0); @@ -246,7 +193,6 @@ static NTSTATUS smb_raw_info_backend(struct smbcli_session *session, = IVAL(blob->data, 0); return NT_STATUS_OK; - case RAW_FILEINFO_COMPRESSION_INFO: case RAW_FILEINFO_COMPRESSION_INFORMATION: FINFO_CHECK_SIZE(16); parms->compression_info.out.compressed_size = BVAL(blob->data, 0); @@ -257,6 +203,155 @@ static NTSTATUS smb_raw_info_backend(struct smbcli_session *session, /* 3 bytes of padding */ return NT_STATUS_OK; + case RAW_FILEINFO_NETWORK_OPEN_INFORMATION: + FINFO_CHECK_SIZE(56); + parms->network_open_information.out.create_time = smbcli_pull_nttime(blob->data, 0); + parms->network_open_information.out.access_time = smbcli_pull_nttime(blob->data, 8); + parms->network_open_information.out.write_time = smbcli_pull_nttime(blob->data, 16); + parms->network_open_information.out.change_time = smbcli_pull_nttime(blob->data, 24); + parms->network_open_information.out.alloc_size = BVAL(blob->data, 32); + parms->network_open_information.out.size = BVAL(blob->data, 40); + parms->network_open_information.out.attrib = IVAL(blob->data, 48); + return NT_STATUS_OK; + + case RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION: + FINFO_CHECK_SIZE(8); + parms->attribute_tag_information.out.attrib = IVAL(blob->data, 0); + parms->attribute_tag_information.out.reparse_tag = IVAL(blob->data, 4); + return NT_STATUS_OK; + + default: + break; + } + + return NT_STATUS_INVALID_LEVEL; +} + + +/**************************************************************************** + Handle qfileinfo/qpathinfo trans2 backend. +****************************************************************************/ +static NTSTATUS smb_raw_info_backend(struct smbcli_session *session, + TALLOC_CTX *mem_ctx, + union smb_fileinfo *parms, + DATA_BLOB *blob) +{ + switch (parms->generic.level) { + case RAW_FILEINFO_GENERIC: + case RAW_FILEINFO_GETATTR: + case RAW_FILEINFO_GETATTRE: + case RAW_FILEINFO_SEC_DESC: + /* not handled here */ + return NT_STATUS_INVALID_LEVEL; + + case RAW_FILEINFO_STANDARD: + FINFO_CHECK_SIZE(22); + parms->standard.out.create_time = raw_pull_dos_date2(session->transport, + blob->data + 0); + parms->standard.out.access_time = raw_pull_dos_date2(session->transport, + blob->data + 4); + parms->standard.out.write_time = raw_pull_dos_date2(session->transport, + blob->data + 8); + parms->standard.out.size = IVAL(blob->data, 12); + parms->standard.out.alloc_size = IVAL(blob->data, 16); + parms->standard.out.attrib = SVAL(blob->data, 20); + return NT_STATUS_OK; + + case RAW_FILEINFO_EA_SIZE: + FINFO_CHECK_SIZE(26); + parms->ea_size.out.create_time = raw_pull_dos_date2(session->transport, + blob->data + 0); + parms->ea_size.out.access_time = raw_pull_dos_date2(session->transport, + blob->data + 4); + parms->ea_size.out.write_time = raw_pull_dos_date2(session->transport, + blob->data + 8); + parms->ea_size.out.size = IVAL(blob->data, 12); + parms->ea_size.out.alloc_size = IVAL(blob->data, 16); + parms->ea_size.out.attrib = SVAL(blob->data, 20); + parms->ea_size.out.ea_size = IVAL(blob->data, 22); + return NT_STATUS_OK; + + case RAW_FILEINFO_EA_LIST: + FINFO_CHECK_MIN_SIZE(4); + return ea_pull_list(blob, mem_ctx, + &parms->ea_list.out.num_eas, + &parms->ea_list.out.eas); + + case RAW_FILEINFO_ALL_EAS: + FINFO_CHECK_MIN_SIZE(4); + return ea_pull_list(blob, mem_ctx, + &parms->all_eas.out.num_eas, + &parms->all_eas.out.eas); + + case RAW_FILEINFO_IS_NAME_VALID: + /* no data! */ + FINFO_CHECK_SIZE(0); + return NT_STATUS_OK; + + case RAW_FILEINFO_BASIC_INFO: + case RAW_FILEINFO_BASIC_INFORMATION: + return smb_raw_fileinfo_passthru_parse(blob, mem_ctx, + RAW_FILEINFO_BASIC_INFORMATION, parms); + + case RAW_FILEINFO_STANDARD_INFO: + case RAW_FILEINFO_STANDARD_INFORMATION: + return smb_raw_fileinfo_passthru_parse(blob, mem_ctx, + RAW_FILEINFO_STANDARD_INFORMATION, parms); + + case RAW_FILEINFO_EA_INFO: + case RAW_FILEINFO_EA_INFORMATION: + return smb_raw_fileinfo_passthru_parse(blob, mem_ctx, + RAW_FILEINFO_EA_INFORMATION, parms); + + case RAW_FILEINFO_NAME_INFO: + case RAW_FILEINFO_NAME_INFORMATION: + return smb_raw_fileinfo_passthru_parse(blob, mem_ctx, + RAW_FILEINFO_NAME_INFORMATION, parms); + + case RAW_FILEINFO_ALL_INFO: + case RAW_FILEINFO_ALL_INFORMATION: + return smb_raw_fileinfo_passthru_parse(blob, mem_ctx, + RAW_FILEINFO_ALL_INFORMATION, parms); + + case RAW_FILEINFO_ALT_NAME_INFO: + case RAW_FILEINFO_ALT_NAME_INFORMATION: + return smb_raw_fileinfo_passthru_parse(blob, mem_ctx, + RAW_FILEINFO_ALT_NAME_INFORMATION, parms); + + case RAW_FILEINFO_STREAM_INFO: + case RAW_FILEINFO_STREAM_INFORMATION: + return smb_raw_fileinfo_passthru_parse(blob, mem_ctx, + RAW_FILEINFO_STREAM_INFORMATION, parms); + + case RAW_FILEINFO_INTERNAL_INFORMATION: + return smb_raw_fileinfo_passthru_parse(blob, mem_ctx, + RAW_FILEINFO_INTERNAL_INFORMATION, parms); + + case RAW_FILEINFO_ACCESS_INFORMATION: + return smb_raw_fileinfo_passthru_parse(blob, mem_ctx, + RAW_FILEINFO_ACCESS_INFORMATION, parms); + + case RAW_FILEINFO_POSITION_INFORMATION: + return smb_raw_fileinfo_passthru_parse(blob, mem_ctx, + RAW_FILEINFO_POSITION_INFORMATION, parms); + + case RAW_FILEINFO_FULL_EA_INFORMATION: + return smb_raw_fileinfo_passthru_parse(blob, mem_ctx, + RAW_FILEINFO_FULL_EA_INFORMATION, parms); + + case RAW_FILEINFO_MODE_INFORMATION: + return smb_raw_fileinfo_passthru_parse(blob, mem_ctx, + RAW_FILEINFO_MODE_INFORMATION, parms); + + case RAW_FILEINFO_ALIGNMENT_INFORMATION: + return smb_raw_fileinfo_passthru_parse(blob, mem_ctx, + RAW_FILEINFO_ALIGNMENT_INFORMATION, parms); + + case RAW_FILEINFO_COMPRESSION_INFO: + case RAW_FILEINFO_COMPRESSION_INFORMATION: + return smb_raw_fileinfo_passthru_parse(blob, mem_ctx, + RAW_FILEINFO_COMPRESSION_INFORMATION, parms); + case RAW_FILEINFO_UNIX_BASIC: FINFO_CHECK_SIZE(100); parms->unix_basic_info.out.end_of_file = BVAL(blob->data, 0); @@ -280,26 +375,18 @@ static NTSTATUS smb_raw_info_backend(struct smbcli_session *session, return NT_STATUS_OK; case RAW_FILEINFO_NETWORK_OPEN_INFORMATION: - FINFO_CHECK_SIZE(56); - parms->network_open_information.out.create_time = smbcli_pull_nttime(blob->data, 0); - parms->network_open_information.out.access_time = smbcli_pull_nttime(blob->data, 8); - parms->network_open_information.out.write_time = smbcli_pull_nttime(blob->data, 16); - parms->network_open_information.out.change_time = smbcli_pull_nttime(blob->data, 24); - parms->network_open_information.out.alloc_size = BVAL(blob->data, 32); - parms->network_open_information.out.size = BVAL(blob->data, 40); - parms->network_open_information.out.attrib = IVAL(blob->data, 48); - return NT_STATUS_OK; + return smb_raw_fileinfo_passthru_parse(blob, mem_ctx, + RAW_FILEINFO_NETWORK_OPEN_INFORMATION, parms); case RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION: - FINFO_CHECK_SIZE(8); - parms->attribute_tag_information.out.attrib = IVAL(blob->data, 0); - parms->attribute_tag_information.out.reparse_tag = IVAL(blob->data, 4); - return NT_STATUS_OK; + return smb_raw_fileinfo_passthru_parse(blob, mem_ctx, + RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION, parms); } return NT_STATUS_INVALID_LEVEL; } + /**************************************************************************** Very raw query file info - returns param/data blobs - (async send) ****************************************************************************/ diff --git a/source4/libcli/raw/rawfsinfo.c b/source4/libcli/raw/rawfsinfo.c index 61f5a5027d..9b218586a2 100644 --- a/source4/libcli/raw/rawfsinfo.c +++ b/source4/libcli/raw/rawfsinfo.c @@ -151,6 +151,86 @@ struct smbcli_request *smb_raw_fsinfo_send(struct smbcli_tree *tree, return smb_raw_qfsinfo_send(tree, mem_ctx, info_level); } +/* + parse the fsinfo 'passthru' level replies +*/ +NTSTATUS smb_raw_fsinfo_passthru_parse(DATA_BLOB blob, TALLOC_CTX *mem_ctx, + enum smb_fsinfo_level level, + union smb_fsinfo *fsinfo) +{ + NTSTATUS status = NT_STATUS_OK; + int i; + + /* parse the results */ + switch (level) { + case RAW_QFS_VOLUME_INFORMATION: + QFS_CHECK_MIN_SIZE(18); + fsinfo->volume_info.out.create_time = smbcli_pull_nttime(blob.data, 0); + fsinfo->volume_info.out.serial_number = IVAL(blob.data, 8); + smbcli_blob_pull_string(NULL, mem_ctx, &blob, + &fsinfo->volume_info.out.volume_name, + 12, 18, STR_UNICODE); + break; + + case RAW_QFS_SIZE_INFORMATION: + QFS_CHECK_SIZE(24); + fsinfo->size_info.out.total_alloc_units = BVAL(blob.data, 0); + fsinfo->size_info.out.avail_alloc_units = BVAL(blob.data, 8); + fsinfo->size_info.out.sectors_per_unit = IVAL(blob.data, 16); + fsinfo->size_info.out.bytes_per_sector = IVAL(blob.data, 20); + break; + + case RAW_QFS_DEVICE_INFORMATION: + QFS_CHECK_SIZE(8); + fsinfo->device_info.out.device_type = IVAL(blob.data, 0); + fsinfo->device_info.out.characteristics = IVAL(blob.data, 4); + break; + + case RAW_QFS_ATTRIBUTE_INFORMATION: + QFS_CHECK_MIN_SIZE(12); + fsinfo->attribute_info.out.fs_attr = IVAL(blob.data, 0); + fsinfo->attribute_info.out.max_file_component_length = IVAL(blob.data, 4); + smbcli_blob_pull_string(NULL, mem_ctx, &blob, + &fsinfo->attribute_info.out.fs_type, + 8, 12, STR_UNICODE); + break; + + case RAW_QFS_QUOTA_INFORMATION: + QFS_CHECK_SIZE(48); + fsinfo->quota_information.out.unknown[0] = BVAL(blob.data, 0); + fsinfo->quota_information.out.unknown[1] = BVAL(blob.data, 8); + fsinfo->quota_information.out.unknown[2] = BVAL(blob.data, 16); + fsinfo->quota_information.out.quota_soft = BVAL(blob.data, 24); + fsinfo->quota_information.out.quota_hard = BVAL(blob.data, 32); + fsinfo->quota_information.out.quota_flags = BVAL(blob.data, 40); + break; + + case RAW_QFS_FULL_SIZE_INFORMATION: + QFS_CHECK_SIZE(32); + fsinfo->full_size_information.out.total_alloc_units = BVAL(blob.data, 0); + fsinfo->full_size_information.out.call_avail_alloc_units = BVAL(blob.data, 8); + fsinfo->full_size_information.out.actual_avail_alloc_units = BVAL(blob.data, 16); + fsinfo->full_size_information.out.sectors_per_unit = IVAL(blob.data, 24); + fsinfo->full_size_information.out.bytes_per_sector = IVAL(blob.data, 28); + break; + + case RAW_QFS_OBJECTID_INFORMATION: + QFS_CHECK_SIZE(64); + status = ndr_pull_struct_blob(&blob, mem_ctx, &fsinfo->objectid_information.out.guid, + (ndr_pull_flags_fn_t)ndr_pull_GUID); + for (i=0;i<6;i++) { + fsinfo->objectid_information.out.unknown[i] = BVAL(blob.data, 16 + i*8); + } + break; + + default: + status = NT_STATUS_INVALID_INFO_CLASS; + } + +failed: + return status; +} + /**************************************************************************** Query FSInfo raw interface (async recv) @@ -161,7 +241,6 @@ NTSTATUS smb_raw_fsinfo_recv(struct smbcli_request *req, { DATA_BLOB blob; NTSTATUS status; - int i; struct smbcli_session *session = req?req->session:NULL; if (fsinfo->generic.level == RAW_QFS_DSKATTR) { @@ -199,39 +278,23 @@ NTSTATUS smb_raw_fsinfo_recv(struct smbcli_request *req, case RAW_QFS_VOLUME_INFO: case RAW_QFS_VOLUME_INFORMATION: - QFS_CHECK_MIN_SIZE(18); - fsinfo->volume_info.out.create_time = smbcli_pull_nttime(blob.data, 0); - fsinfo->volume_info.out.serial_number = IVAL(blob.data, 8); - smbcli_blob_pull_string(session, mem_ctx, &blob, - &fsinfo->volume_info.out.volume_name, - 12, 18, STR_UNICODE); - break; + return smb_raw_fsinfo_passthru_parse(blob, mem_ctx, + RAW_QFS_VOLUME_INFORMATION, fsinfo); case RAW_QFS_SIZE_INFO: case RAW_QFS_SIZE_INFORMATION: - QFS_CHECK_SIZE(24); - fsinfo->size_info.out.total_alloc_units = BVAL(blob.data, 0); - fsinfo->size_info.out.avail_alloc_units = BVAL(blob.data, 8); - fsinfo->size_info.out.sectors_per_unit = IVAL(blob.data, 16); - fsinfo->size_info.out.bytes_per_sector = IVAL(blob.data, 20); - break; + return smb_raw_fsinfo_passthru_parse(blob, mem_ctx, + RAW_QFS_SIZE_INFORMATION, fsinfo); case RAW_QFS_DEVICE_INFO: case RAW_QFS_DEVICE_INFORMATION: - QFS_CHECK_SIZE(8); - fsinfo->device_info.out.device_type = IVAL(blob.data, 0); - fsinfo->device_info.out.characteristics = IVAL(blob.data, 4); - break; + return smb_raw_fsinfo_passthru_parse(blob, mem_ctx, + RAW_QFS_DEVICE_INFORMATION, fsinfo); case RAW_QFS_ATTRIBUTE_INFO: case RAW_QFS_ATTRIBUTE_INFORMATION: - QFS_CHECK_MIN_SIZE(12); - fsinfo->attribute_info.out.fs_attr = IVAL(blob.data, 0); - fsinfo->attribute_info.out.max_file_component_length = IVAL(blob.data, 4); - smbcli_blob_pull_string(session, mem_ctx, &blob, - &fsinfo->attribute_info.out.fs_type, - 8, 12, STR_UNICODE); - break; + return smb_raw_fsinfo_passthru_parse(blob, mem_ctx, + RAW_QFS_ATTRIBUTE_INFORMATION, fsinfo); case RAW_QFS_UNIX_INFO: QFS_CHECK_SIZE(12); @@ -241,32 +304,16 @@ NTSTATUS smb_raw_fsinfo_recv(struct smbcli_request *req, break; case RAW_QFS_QUOTA_INFORMATION: - QFS_CHECK_SIZE(48); - fsinfo->quota_information.out.unknown[0] = BVAL(blob.data, 0); - fsinfo->quota_information.out.unknown[1] = BVAL(blob.data, 8); - fsinfo->quota_information.out.unknown[2] = BVAL(blob.data, 16); - fsinfo->quota_information.out.quota_soft = BVAL(blob.data, 24); - fsinfo->quota_information.out.quota_hard = BVAL(blob.data, 32); - fsinfo->quota_information.out.quota_flags = BVAL(blob.data, 40); - break; + return smb_raw_fsinfo_passthru_parse(blob, mem_ctx, + RAW_QFS_QUOTA_INFORMATION, fsinfo); case RAW_QFS_FULL_SIZE_INFORMATION: - QFS_CHECK_SIZE(32); - fsinfo->full_size_information.out.total_alloc_units = BVAL(blob.data, 0); - fsinfo->full_size_information.out.call_avail_alloc_units = BVAL(blob.data, 8); - fsinfo->full_size_information.out.actual_avail_alloc_units = BVAL(blob.data, 16); - fsinfo->full_size_information.out.sectors_per_unit = IVAL(blob.data, 24); - fsinfo->full_size_information.out.bytes_per_sector = IVAL(blob.data, 28); - break; + return smb_raw_fsinfo_passthru_parse(blob, mem_ctx, + RAW_QFS_FULL_SIZE_INFORMATION, fsinfo); case RAW_QFS_OBJECTID_INFORMATION: - QFS_CHECK_SIZE(64); - status = ndr_pull_struct_blob(&blob, mem_ctx, &fsinfo->objectid_information.out.guid, - (ndr_pull_flags_fn_t)ndr_pull_GUID); - for (i=0;i<6;i++) { - fsinfo->objectid_information.out.unknown[i] = BVAL(blob.data, 16 + i*8); - } - break; + return smb_raw_fsinfo_passthru_parse(blob, mem_ctx, + RAW_QFS_OBJECTID_INFORMATION, fsinfo); } failed: diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 33ac9c55b1..6e02ddc5c1 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -737,8 +737,8 @@ NTTIME smbcli_pull_nttime(void *base, uint16_t offset) of bytes consumed in the blob is returned */ static size_t smbcli_blob_pull_ucs2(TALLOC_CTX* mem_ctx, - DATA_BLOB *blob, const char **dest, - const uint8_t *src, int byte_len, uint_t flags) + const DATA_BLOB *blob, const char **dest, + const uint8_t *src, int byte_len, uint_t flags) { int src_len, src_len2, alignment=0; ssize_t ret; @@ -793,8 +793,8 @@ static size_t smbcli_blob_pull_ucs2(TALLOC_CTX* mem_ctx, of bytes consumed in the blob is returned */ static size_t smbcli_blob_pull_ascii(TALLOC_CTX *mem_ctx, - DATA_BLOB *blob, const char **dest, - const uint8_t *src, int byte_len, uint_t flags) + const DATA_BLOB *blob, const char **dest, + const uint8_t *src, int byte_len, uint_t flags) { int src_len, src_len2; ssize_t ret; @@ -841,11 +841,11 @@ static size_t smbcli_blob_pull_ascii(TALLOC_CTX *mem_ctx, of bytes consumed in the blob is returned */ size_t smbcli_blob_pull_string(struct smbcli_session *session, - TALLOC_CTX *mem_ctx, - DATA_BLOB *blob, - WIRE_STRING *dest, - uint16_t len_offset, uint16_t str_offset, - uint_t flags) + TALLOC_CTX *mem_ctx, + const DATA_BLOB *blob, + WIRE_STRING *dest, + uint16_t len_offset, uint16_t str_offset, + uint_t flags) { int extra; dest->s = NULL; -- cgit From eedb92ce724e505f94ed49f9b238be617c52ccb4 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 17 Nov 2005 11:06:13 +0000 Subject: r11758: unified the parse code for the SMB and SMB2 qfsinfo and qfileinfo calls (This used to be commit ba897e537b9a1544dc214e9d5504c87fee6fced2) --- source4/libcli/raw/rawfileinfo.c | 64 +++++++++++++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 10 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawfileinfo.c b/source4/libcli/raw/rawfileinfo.c index 2edb6d5b42..7119eed5e7 100644 --- a/source4/libcli/raw/rawfileinfo.c +++ b/source4/libcli/raw/rawfileinfo.c @@ -176,12 +176,6 @@ NTSTATUS smb_raw_fileinfo_passthru_parse(const DATA_BLOB *blob, TALLOC_CTX *mem_ parms->position_information.out.position = BVAL(blob->data, 0); return NT_STATUS_OK; - case RAW_FILEINFO_FULL_EA_INFORMATION: - FINFO_CHECK_MIN_SIZE(4); - return ea_pull_list_chained(blob, mem_ctx, - &parms->all_eas.out.num_eas, - &parms->all_eas.out.eas); - case RAW_FILEINFO_MODE_INFORMATION: FINFO_CHECK_SIZE(4); parms->mode_information.out.mode = IVAL(blob->data, 0); @@ -220,6 +214,51 @@ NTSTATUS smb_raw_fileinfo_passthru_parse(const DATA_BLOB *blob, TALLOC_CTX *mem_ parms->attribute_tag_information.out.reparse_tag = IVAL(blob->data, 4); return NT_STATUS_OK; + case RAW_FILEINFO_SMB2_ALL_EAS: + FINFO_CHECK_MIN_SIZE(4); + return ea_pull_list_chained(blob, mem_ctx, + &parms->all_eas.out.num_eas, + &parms->all_eas.out.eas); + + case RAW_FILEINFO_SMB2_ALL_INFORMATION: + FINFO_CHECK_MIN_SIZE(0x64); + parms->all_info2.out.create_time = smbcli_pull_nttime(blob->data, 0x00); + parms->all_info2.out.access_time = smbcli_pull_nttime(blob->data, 0x08); + parms->all_info2.out.write_time = smbcli_pull_nttime(blob->data, 0x10); + parms->all_info2.out.change_time = smbcli_pull_nttime(blob->data, 0x18); + parms->all_info2.out.attrib = IVAL(blob->data, 0x20); + parms->all_info2.out.unknown1 = IVAL(blob->data, 0x24); + parms->all_info2.out.alloc_size = BVAL(blob->data, 0x28); + parms->all_info2.out.size = BVAL(blob->data, 0x30); + parms->all_info2.out.nlink = IVAL(blob->data, 0x38); + parms->all_info2.out.delete_pending = CVAL(blob->data, 0x3C); + parms->all_info2.out.directory = CVAL(blob->data, 0x3D); + parms->all_info2.out.file_id = BVAL(blob->data, 0x40); + parms->all_info2.out.ea_size = IVAL(blob->data, 0x48); + parms->all_info2.out.access_mask = IVAL(blob->data, 0x4C); + parms->all_info2.out.unknown2 = BVAL(blob->data, 0x50); + parms->all_info2.out.unknown3 = BVAL(blob->data, 0x58); + smbcli_blob_pull_string(NULL, mem_ctx, blob, + &parms->all_info2.out.fname, 0x60, 0x64, STR_UNICODE); + return NT_STATUS_OK; + + case RAW_FILEINFO_SEC_DESC: { + struct ndr_pull *ndr; + NTSTATUS status; + ndr = ndr_pull_init_blob(blob, mem_ctx); + if (!ndr) { + return NT_STATUS_NO_MEMORY; + } + parms->query_secdesc.out.sd = talloc(mem_ctx, struct security_descriptor); + if (parms->query_secdesc.out.sd == NULL) { + return NT_STATUS_NO_MEMORY; + } + status = ndr_pull_security_descriptor(ndr, NDR_SCALARS|NDR_BUFFERS, + parms->query_secdesc.out.sd); + talloc_free(ndr); + return status; + } + default: break; } @@ -335,10 +374,6 @@ static NTSTATUS smb_raw_info_backend(struct smbcli_session *session, return smb_raw_fileinfo_passthru_parse(blob, mem_ctx, RAW_FILEINFO_POSITION_INFORMATION, parms); - case RAW_FILEINFO_FULL_EA_INFORMATION: - return smb_raw_fileinfo_passthru_parse(blob, mem_ctx, - RAW_FILEINFO_FULL_EA_INFORMATION, parms); - case RAW_FILEINFO_MODE_INFORMATION: return smb_raw_fileinfo_passthru_parse(blob, mem_ctx, RAW_FILEINFO_MODE_INFORMATION, parms); @@ -381,6 +416,15 @@ static NTSTATUS smb_raw_info_backend(struct smbcli_session *session, case RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION: return smb_raw_fileinfo_passthru_parse(blob, mem_ctx, RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION, parms); + + case RAW_FILEINFO_SMB2_ALL_INFORMATION: + return smb_raw_fileinfo_passthru_parse(blob, mem_ctx, + RAW_FILEINFO_SMB2_ALL_INFORMATION, parms); + + case RAW_FILEINFO_SMB2_ALL_EAS: + return smb_raw_fileinfo_passthru_parse(blob, mem_ctx, + RAW_FILEINFO_SMB2_ALL_EAS, parms); + } return NT_STATUS_INVALID_LEVEL; -- cgit From 2ff21db535897eb2a4eae428b7465337bd7cfdd1 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 18 Nov 2005 06:28:15 +0000 Subject: r11771: - split out the setinfo blob construction in the libcli/raw code - added a smb2_setinfo call - added smb2_setinfo_file*() calls (This used to be commit da0b6fb93683331134ef2f4abd8707e0c3fc6d9d) --- source4/libcli/raw/rawsetfileinfo.c | 143 +++++++++++++++++++++++++----------- 1 file changed, 101 insertions(+), 42 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawsetfileinfo.c b/source4/libcli/raw/rawsetfileinfo.c index 5e780757e8..5779cf33fb 100644 --- a/source4/libcli/raw/rawsetfileinfo.c +++ b/source4/libcli/raw/rawsetfileinfo.c @@ -22,13 +22,14 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" -/**************************************************************************** - Handle setfileinfo/setpathinfo trans2 backend. -****************************************************************************/ -static BOOL smb_raw_setinfo_backend(struct smbcli_tree *tree, - TALLOC_CTX *mem_ctx, - union smb_setfileinfo *parms, - DATA_BLOB *blob) + +/* + Handle setfileinfo/setpathinfo passthu constructions +*/ +BOOL smb_raw_setfileinfo_passthru(TALLOC_CTX *mem_ctx, + enum smb_setfileinfo_level level, + union smb_setfileinfo *parms, + DATA_BLOB *blob) { uint_t len; @@ -37,6 +38,77 @@ static BOOL smb_raw_setinfo_backend(struct smbcli_tree *tree, if (blob->data == NULL) return False; \ } while (0) + switch (level) { + case RAW_SFILEINFO_BASIC_INFORMATION: + NEED_BLOB(40); + smbcli_push_nttime(blob->data, 0, parms->basic_info.in.create_time); + smbcli_push_nttime(blob->data, 8, parms->basic_info.in.access_time); + smbcli_push_nttime(blob->data, 16, parms->basic_info.in.write_time); + smbcli_push_nttime(blob->data, 24, parms->basic_info.in.change_time); + SIVAL(blob->data, 32, parms->basic_info.in.attrib); + SIVAL(blob->data, 36, 0); /* padding */ + return True; + + case RAW_SFILEINFO_DISPOSITION_INFORMATION: + NEED_BLOB(4); + SIVAL(blob->data, 0, parms->disposition_info.in.delete_on_close); + return True; + + case RAW_SFILEINFO_ALLOCATION_INFORMATION: + NEED_BLOB(8); + SBVAL(blob->data, 0, parms->allocation_info.in.alloc_size); + return True; + + case RAW_SFILEINFO_END_OF_FILE_INFORMATION: + NEED_BLOB(8); + SBVAL(blob->data, 0, parms->end_of_file_info.in.size); + return True; + + case RAW_SFILEINFO_RENAME_INFORMATION: + NEED_BLOB(12); + SIVAL(blob->data, 0, parms->rename_information.in.overwrite); + SIVAL(blob->data, 4, parms->rename_information.in.root_fid); + len = smbcli_blob_append_string(NULL, mem_ctx, blob, + parms->rename_information.in.new_name, + STR_UNICODE|STR_TERMINATE); + SIVAL(blob->data, 8, len - 2); + return True; + + case RAW_SFILEINFO_POSITION_INFORMATION: + NEED_BLOB(8); + SBVAL(blob->data, 0, parms->position_information.in.position); + return True; + + case RAW_SFILEINFO_MODE_INFORMATION: + NEED_BLOB(4); + SIVAL(blob->data, 0, parms->mode_information.in.mode); + return True; + + /* Unhandled levels */ + case RAW_SFILEINFO_1023: + case RAW_SFILEINFO_1025: + case RAW_SFILEINFO_1029: + case RAW_SFILEINFO_1032: + case RAW_SFILEINFO_1039: + case RAW_SFILEINFO_1040: + break; + + default: + DEBUG(0,("Unhandled setfileinfo passthru level %d\n", level)); + return False; + } + + return False; +} + +/* + Handle setfileinfo/setpathinfo trans2 backend. +*/ +static BOOL smb_raw_setinfo_backend(struct smbcli_tree *tree, + TALLOC_CTX *mem_ctx, + union smb_setfileinfo *parms, + DATA_BLOB *blob) +{ switch (parms->generic.level) { case RAW_SFILEINFO_GENERIC: case RAW_SFILEINFO_SETATTR: @@ -62,14 +134,8 @@ static BOOL smb_raw_setinfo_backend(struct smbcli_tree *tree, case RAW_SFILEINFO_BASIC_INFO: case RAW_SFILEINFO_BASIC_INFORMATION: - NEED_BLOB(40); - smbcli_push_nttime(blob->data, 0, parms->basic_info.in.create_time); - smbcli_push_nttime(blob->data, 8, parms->basic_info.in.access_time); - smbcli_push_nttime(blob->data, 16, parms->basic_info.in.write_time); - smbcli_push_nttime(blob->data, 24, parms->basic_info.in.change_time); - SIVAL(blob->data, 32, parms->basic_info.in.attrib); - SIVAL(blob->data, 36, 0); /* padding */ - return True; + return smb_raw_setfileinfo_passthru(mem_ctx, RAW_SFILEINFO_BASIC_INFORMATION, + parms, blob); case RAW_SFILEINFO_UNIX_BASIC: NEED_BLOB(92); @@ -89,52 +155,45 @@ static BOOL smb_raw_setinfo_backend(struct smbcli_tree *tree, case RAW_SFILEINFO_DISPOSITION_INFO: case RAW_SFILEINFO_DISPOSITION_INFORMATION: - NEED_BLOB(4); - SIVAL(blob->data, 0, parms->disposition_info.in.delete_on_close); - return True; + return smb_raw_setfileinfo_passthru(mem_ctx, RAW_SFILEINFO_DISPOSITION_INFORMATION, + parms, blob); case RAW_SFILEINFO_ALLOCATION_INFO: case RAW_SFILEINFO_ALLOCATION_INFORMATION: - NEED_BLOB(8); - SBVAL(blob->data, 0, parms->allocation_info.in.alloc_size); - return True; + return smb_raw_setfileinfo_passthru(mem_ctx, RAW_SFILEINFO_ALLOCATION_INFORMATION, + parms, blob); case RAW_SFILEINFO_END_OF_FILE_INFO: case RAW_SFILEINFO_END_OF_FILE_INFORMATION: - NEED_BLOB(8); - SBVAL(blob->data, 0, parms->end_of_file_info.in.size); - return True; + return smb_raw_setfileinfo_passthru(mem_ctx, RAW_SFILEINFO_END_OF_FILE_INFORMATION, + parms, blob); case RAW_SFILEINFO_RENAME_INFORMATION: - NEED_BLOB(12); - SIVAL(blob->data, 0, parms->rename_information.in.overwrite); - SIVAL(blob->data, 4, parms->rename_information.in.root_fid); - len = smbcli_blob_append_string(tree->session, mem_ctx, blob, - parms->rename_information.in.new_name, - STR_UNICODE|STR_TERMINATE); - SIVAL(blob->data, 8, len - 2); - return True; + return smb_raw_setfileinfo_passthru(mem_ctx, RAW_SFILEINFO_RENAME_INFORMATION, + parms, blob); case RAW_SFILEINFO_POSITION_INFORMATION: - NEED_BLOB(8); - SBVAL(blob->data, 0, parms->position_information.in.position); - return True; + return smb_raw_setfileinfo_passthru(mem_ctx, RAW_SFILEINFO_POSITION_INFORMATION, + parms, blob); case RAW_SFILEINFO_MODE_INFORMATION: - NEED_BLOB(4); - SIVAL(blob->data, 0, parms->mode_information.in.mode); - return True; + return smb_raw_setfileinfo_passthru(mem_ctx, RAW_SFILEINFO_MODE_INFORMATION, + parms, blob); - /* Unhandled levels */ - - case RAW_SFILEINFO_UNIX_LINK: - case RAW_SFILEINFO_UNIX_HLINK: + /* Unhandled passthru levels */ case RAW_SFILEINFO_1023: case RAW_SFILEINFO_1025: case RAW_SFILEINFO_1029: case RAW_SFILEINFO_1032: case RAW_SFILEINFO_1039: case RAW_SFILEINFO_1040: + return smb_raw_setfileinfo_passthru(mem_ctx, parms->generic.level, + parms, blob); + + /* Unhandled levels */ + + case RAW_SFILEINFO_UNIX_LINK: + case RAW_SFILEINFO_UNIX_HLINK: break; } -- cgit From 7d6f36682eab29cb23c40dd915acad61fb5d68cb Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 19 Nov 2005 05:55:08 +0000 Subject: r11800: - filled in unknown fields in SMB2 all_info level - allow setting of the ALL_EAS flags bits in SMB2 getinfo (This used to be commit 8c7c54a46dfb91c053d07a5e606892a41213c605) --- source4/libcli/raw/rawfileinfo.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawfileinfo.c b/source4/libcli/raw/rawfileinfo.c index 7119eed5e7..92d31b30ef 100644 --- a/source4/libcli/raw/rawfileinfo.c +++ b/source4/libcli/raw/rawfileinfo.c @@ -95,9 +95,9 @@ NTSTATUS smb_raw_fileinfo_passthru_parse(const DATA_BLOB *blob, TALLOC_CTX *mem_ } parms->basic_info.out.create_time = smbcli_pull_nttime(blob->data, 0); parms->basic_info.out.access_time = smbcli_pull_nttime(blob->data, 8); - parms->basic_info.out.write_time = smbcli_pull_nttime(blob->data, 16); + parms->basic_info.out.write_time = smbcli_pull_nttime(blob->data, 16); parms->basic_info.out.change_time = smbcli_pull_nttime(blob->data, 24); - parms->basic_info.out.attrib = IVAL(blob->data, 32); + parms->basic_info.out.attrib = IVAL(blob->data, 32); return NT_STATUS_OK; case RAW_FILEINFO_STANDARD_INFORMATION: @@ -236,8 +236,8 @@ NTSTATUS smb_raw_fileinfo_passthru_parse(const DATA_BLOB *blob, TALLOC_CTX *mem_ parms->all_info2.out.file_id = BVAL(blob->data, 0x40); parms->all_info2.out.ea_size = IVAL(blob->data, 0x48); parms->all_info2.out.access_mask = IVAL(blob->data, 0x4C); - parms->all_info2.out.unknown2 = BVAL(blob->data, 0x50); - parms->all_info2.out.unknown3 = BVAL(blob->data, 0x58); + parms->all_info2.out.position = BVAL(blob->data, 0x50); + parms->all_info2.out.mode = BVAL(blob->data, 0x58); smbcli_blob_pull_string(NULL, mem_ctx, blob, &parms->all_info2.out.fname, 0x60, 0x64, STR_UNICODE); return NT_STATUS_OK; -- cgit From a6852523d677f6c39a92e0e2b5d970211b29558b Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 20 Nov 2005 17:34:56 +0000 Subject: r11812: Convert winbind to the async bind routines. Also remove tridge's hack for the winbind "bug" :-) Volker (This used to be commit fb9a3c7ef376f289288c71bc47d67f548ddb7194) --- source4/libcli/raw/clitransport.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 83b73f2e30..1cd0a3046e 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -122,11 +122,7 @@ struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock, transport); packet_set_fde(transport->packet, transport->socket->event.fde); -#if 0 - /* winbind relies on non-serialised connections for dcerpc bind. Once that is - fixed we can go back to serialised connections */ packet_set_serialise(transport->packet); -#endif talloc_set_destructor(transport, transport_destructor); return transport; -- cgit From e8f17538a71b67a435882989325eb66dae8bc426 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 22 Nov 2005 13:12:22 +0000 Subject: r11848: separate out the info levels common to SMB and SMB2 for raw_search (This used to be commit ed8d3073472fbb0850209f81dd04bd94f6d1c33d) --- source4/libcli/raw/rawrequest.c | 7 + source4/libcli/raw/rawsearch.c | 288 +++++++++++++++++++++++----------------- 2 files changed, 174 insertions(+), 121 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 6e02ddc5c1..cd76e0e438 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -849,6 +849,13 @@ size_t smbcli_blob_pull_string(struct smbcli_session *session, { int extra; dest->s = NULL; + + /* this is here to cope with SMB2 calls using the SMB + parsers. SMB2 will pass smbcli_session==NULL, which forces + unicode on (as used by SMB2) */ + if (session == NULL && !(flags & STR_ASCII)) { + flags |= STR_UNICODE; + } if (flags & STR_LEN8BIT) { if (len_offset > blob->length-1) { diff --git a/source4/libcli/raw/rawsearch.c b/source4/libcli/raw/rawsearch.c index 65928d1154..e844a33358 100644 --- a/source4/libcli/raw/rawsearch.c +++ b/source4/libcli/raw/rawsearch.c @@ -310,6 +310,155 @@ static NTSTATUS smb_raw_search_next_blob(struct smbcli_tree *tree, } +/* + parse the wire search formats that are in common between SMB and + SMB2 +*/ +NTSTATUS smb_raw_search_common(TALLOC_CTX *mem_ctx, + enum smb_search_level level, + const DATA_BLOB *blob, + union smb_search_data *data, + uint_t *next_ofs, + uint_t str_flags) +{ + uint_t len, blen; + + if (blob->length < 4) { + return NT_STATUS_INFO_LENGTH_MISMATCH; + } + + *next_ofs = IVAL(blob->data, 0); + if (*next_ofs != 0) { + blen = *next_ofs; + } else { + blen = blob->length; + } + + switch (level) { + case RAW_SEARCH_DIRECTORY_INFO: + if (blen < 65) return NT_STATUS_INFO_LENGTH_MISMATCH; + data->directory_info.file_index = IVAL(blob->data, 4); + data->directory_info.create_time = smbcli_pull_nttime(blob->data, 8); + data->directory_info.access_time = smbcli_pull_nttime(blob->data, 16); + data->directory_info.write_time = smbcli_pull_nttime(blob->data, 24); + data->directory_info.change_time = smbcli_pull_nttime(blob->data, 32); + data->directory_info.size = BVAL(blob->data, 40); + data->directory_info.alloc_size = BVAL(blob->data, 48); + data->directory_info.attrib = IVAL(blob->data, 56); + len = smbcli_blob_pull_string(NULL, mem_ctx, blob, + &data->directory_info.name, + 60, 64, str_flags); + if (*next_ofs != 0 && *next_ofs < 64+len) { + return NT_STATUS_INFO_LENGTH_MISMATCH; + } + return NT_STATUS_OK; + + case RAW_SEARCH_FULL_DIRECTORY_INFO: + if (blen < 69) return NT_STATUS_INFO_LENGTH_MISMATCH; + data->full_directory_info.file_index = IVAL(blob->data, 4); + data->full_directory_info.create_time = smbcli_pull_nttime(blob->data, 8); + data->full_directory_info.access_time = smbcli_pull_nttime(blob->data, 16); + data->full_directory_info.write_time = smbcli_pull_nttime(blob->data, 24); + data->full_directory_info.change_time = smbcli_pull_nttime(blob->data, 32); + data->full_directory_info.size = BVAL(blob->data, 40); + data->full_directory_info.alloc_size = BVAL(blob->data, 48); + data->full_directory_info.attrib = IVAL(blob->data, 56); + data->full_directory_info.ea_size = IVAL(blob->data, 64); + len = smbcli_blob_pull_string(NULL, mem_ctx, blob, + &data->full_directory_info.name, + 60, 68, str_flags); + if (*next_ofs != 0 && *next_ofs < 68+len) { + return NT_STATUS_INFO_LENGTH_MISMATCH; + } + return NT_STATUS_OK; + + case RAW_SEARCH_NAME_INFO: + if (blen < 13) return NT_STATUS_INFO_LENGTH_MISMATCH; + data->name_info.file_index = IVAL(blob->data, 4); + len = smbcli_blob_pull_string(NULL, mem_ctx, blob, + &data->name_info.name, + 8, 12, str_flags); + if (*next_ofs != 0 && *next_ofs < 12+len) { + return NT_STATUS_INFO_LENGTH_MISMATCH; + } + return NT_STATUS_OK; + + + case RAW_SEARCH_BOTH_DIRECTORY_INFO: + if (blen < 95) return NT_STATUS_INFO_LENGTH_MISMATCH; + data->both_directory_info.file_index = IVAL(blob->data, 4); + data->both_directory_info.create_time = smbcli_pull_nttime(blob->data, 8); + data->both_directory_info.access_time = smbcli_pull_nttime(blob->data, 16); + data->both_directory_info.write_time = smbcli_pull_nttime(blob->data, 24); + data->both_directory_info.change_time = smbcli_pull_nttime(blob->data, 32); + data->both_directory_info.size = BVAL(blob->data, 40); + data->both_directory_info.alloc_size = BVAL(blob->data, 48); + data->both_directory_info.attrib = IVAL(blob->data, 56); + data->both_directory_info.ea_size = IVAL(blob->data, 64); + smbcli_blob_pull_string(NULL, mem_ctx, blob, + &data->both_directory_info.short_name, + 68, 70, STR_LEN8BIT | STR_UNICODE); + len = smbcli_blob_pull_string(NULL, mem_ctx, blob, + &data->both_directory_info.name, + 60, 94, str_flags); + if (*next_ofs != 0 && *next_ofs < 94+len) { + return NT_STATUS_INFO_LENGTH_MISMATCH; + } + return NT_STATUS_OK; + + + case RAW_SEARCH_ID_FULL_DIRECTORY_INFO: + if (blen < 81) return NT_STATUS_INFO_LENGTH_MISMATCH; + data->id_full_directory_info.file_index = IVAL(blob->data, 4); + data->id_full_directory_info.create_time = smbcli_pull_nttime(blob->data, 8); + data->id_full_directory_info.access_time = smbcli_pull_nttime(blob->data, 16); + data->id_full_directory_info.write_time = smbcli_pull_nttime(blob->data, 24); + data->id_full_directory_info.change_time = smbcli_pull_nttime(blob->data, 32); + data->id_full_directory_info.size = BVAL(blob->data, 40); + data->id_full_directory_info.alloc_size = BVAL(blob->data, 48); + data->id_full_directory_info.attrib = IVAL(blob->data, 56); + data->id_full_directory_info.ea_size = IVAL(blob->data, 64); + data->id_full_directory_info.file_id = BVAL(blob->data, 72); + len = smbcli_blob_pull_string(NULL, mem_ctx, blob, + &data->id_full_directory_info.name, + 60, 80, str_flags); + if (*next_ofs != 0 && *next_ofs < 80+len) { + return NT_STATUS_INFO_LENGTH_MISMATCH; + } + return NT_STATUS_OK; + + case RAW_SEARCH_ID_BOTH_DIRECTORY_INFO: + if (blen < 105) return NT_STATUS_INFO_LENGTH_MISMATCH; + data->id_both_directory_info.file_index = IVAL(blob->data, 4); + data->id_both_directory_info.create_time = smbcli_pull_nttime(blob->data, 8); + data->id_both_directory_info.access_time = smbcli_pull_nttime(blob->data, 16); + data->id_both_directory_info.write_time = smbcli_pull_nttime(blob->data, 24); + data->id_both_directory_info.change_time = smbcli_pull_nttime(blob->data, 32); + data->id_both_directory_info.size = BVAL(blob->data, 40); + data->id_both_directory_info.alloc_size = BVAL(blob->data, 48); + data->id_both_directory_info.attrib = SVAL(blob->data, 56); + data->id_both_directory_info.ea_size = IVAL(blob->data, 64); + smbcli_blob_pull_string(NULL, mem_ctx, blob, + &data->id_both_directory_info.short_name, + 68, 70, STR_LEN8BIT | STR_UNICODE); + data->id_both_directory_info.file_id = BVAL(blob->data, 96); + len = smbcli_blob_pull_string(NULL, mem_ctx, blob, + &data->id_both_directory_info.name, + 60, 104, str_flags); + if (*next_ofs != 0 && *next_ofs < 104+len) { + return NT_STATUS_INFO_LENGTH_MISMATCH; + } + return NT_STATUS_OK; + + default: + break; + } + + /* invalid level */ + return NT_STATUS_INVALID_INFO_CLASS; +} + + /* parse a trans2 search response. Return the number of bytes consumed @@ -419,127 +568,6 @@ static int parse_trans2_search(struct smbcli_tree *tree, STR_LEN8BIT | STR_NOALIGN); return len + ea_size + 23 + 1; - case RAW_SEARCH_DIRECTORY_INFO: - if (blob->length < 65) return -1; - ofs = IVAL(blob->data, 0); - data->directory_info.file_index = IVAL(blob->data, 4); - data->directory_info.create_time = smbcli_pull_nttime(blob->data, 8); - data->directory_info.access_time = smbcli_pull_nttime(blob->data, 16); - data->directory_info.write_time = smbcli_pull_nttime(blob->data, 24); - data->directory_info.change_time = smbcli_pull_nttime(blob->data, 32); - data->directory_info.size = BVAL(blob->data, 40); - data->directory_info.alloc_size = BVAL(blob->data, 48); - data->directory_info.attrib = IVAL(blob->data, 56); - len = smbcli_blob_pull_string(tree->session, mem_ctx, blob, - &data->directory_info.name, - 60, 64, 0); - if (ofs != 0 && ofs < 64+len) { - return -1; - } - return ofs; - - case RAW_SEARCH_FULL_DIRECTORY_INFO: - if (blob->length < 69) return -1; - ofs = IVAL(blob->data, 0); - data->full_directory_info.file_index = IVAL(blob->data, 4); - data->full_directory_info.create_time = smbcli_pull_nttime(blob->data, 8); - data->full_directory_info.access_time = smbcli_pull_nttime(blob->data, 16); - data->full_directory_info.write_time = smbcli_pull_nttime(blob->data, 24); - data->full_directory_info.change_time = smbcli_pull_nttime(blob->data, 32); - data->full_directory_info.size = BVAL(blob->data, 40); - data->full_directory_info.alloc_size = BVAL(blob->data, 48); - data->full_directory_info.attrib = IVAL(blob->data, 56); - data->full_directory_info.ea_size = IVAL(blob->data, 64); - len = smbcli_blob_pull_string(tree->session, mem_ctx, blob, - &data->full_directory_info.name, - 60, 68, 0); - if (ofs != 0 && ofs < 68+len) { - return -1; - } - return ofs; - - case RAW_SEARCH_NAME_INFO: - if (blob->length < 13) return -1; - ofs = IVAL(blob->data, 0); - data->name_info.file_index = IVAL(blob->data, 4); - len = smbcli_blob_pull_string(tree->session, mem_ctx, blob, - &data->name_info.name, - 8, 12, 0); - if (ofs != 0 && ofs < 12+len) { - return -1; - } - return ofs; - - - case RAW_SEARCH_BOTH_DIRECTORY_INFO: - if (blob->length < 95) return -1; - ofs = IVAL(blob->data, 0); - data->both_directory_info.file_index = IVAL(blob->data, 4); - data->both_directory_info.create_time = smbcli_pull_nttime(blob->data, 8); - data->both_directory_info.access_time = smbcli_pull_nttime(blob->data, 16); - data->both_directory_info.write_time = smbcli_pull_nttime(blob->data, 24); - data->both_directory_info.change_time = smbcli_pull_nttime(blob->data, 32); - data->both_directory_info.size = BVAL(blob->data, 40); - data->both_directory_info.alloc_size = BVAL(blob->data, 48); - data->both_directory_info.attrib = IVAL(blob->data, 56); - data->both_directory_info.ea_size = IVAL(blob->data, 64); - smbcli_blob_pull_string(tree->session, mem_ctx, blob, - &data->both_directory_info.short_name, - 68, 70, STR_LEN8BIT | STR_UNICODE); - len = smbcli_blob_pull_string(tree->session, mem_ctx, blob, - &data->both_directory_info.name, - 60, 94, 0); - if (ofs != 0 && ofs < 94+len) { - return -1; - } - return ofs; - - - case RAW_SEARCH_ID_FULL_DIRECTORY_INFO: - if (blob->length < 81) return -1; - ofs = IVAL(blob->data, 0); - data->id_full_directory_info.file_index = IVAL(blob->data, 4); - data->id_full_directory_info.create_time = smbcli_pull_nttime(blob->data, 8); - data->id_full_directory_info.access_time = smbcli_pull_nttime(blob->data, 16); - data->id_full_directory_info.write_time = smbcli_pull_nttime(blob->data, 24); - data->id_full_directory_info.change_time = smbcli_pull_nttime(blob->data, 32); - data->id_full_directory_info.size = BVAL(blob->data, 40); - data->id_full_directory_info.alloc_size = BVAL(blob->data, 48); - data->id_full_directory_info.attrib = IVAL(blob->data, 56); - data->id_full_directory_info.ea_size = IVAL(blob->data, 64); - data->id_full_directory_info.file_id = BVAL(blob->data, 72); - len = smbcli_blob_pull_string(tree->session, mem_ctx, blob, - &data->id_full_directory_info.name, - 60, 80, 0); - if (ofs != 0 && ofs < 80+len) { - return -1; - } - return ofs; - - case RAW_SEARCH_ID_BOTH_DIRECTORY_INFO: - if (blob->length < 105) return -1; - ofs = IVAL(blob->data, 0); - data->id_both_directory_info.file_index = IVAL(blob->data, 4); - data->id_both_directory_info.create_time = smbcli_pull_nttime(blob->data, 8); - data->id_both_directory_info.access_time = smbcli_pull_nttime(blob->data, 16); - data->id_both_directory_info.write_time = smbcli_pull_nttime(blob->data, 24); - data->id_both_directory_info.change_time = smbcli_pull_nttime(blob->data, 32); - data->id_both_directory_info.size = BVAL(blob->data, 40); - data->id_both_directory_info.alloc_size = BVAL(blob->data, 48); - data->id_both_directory_info.attrib = SVAL(blob->data, 56); - data->id_both_directory_info.ea_size = IVAL(blob->data, 64); - smbcli_blob_pull_string(tree->session, mem_ctx, blob, - &data->id_both_directory_info.short_name, - 68, 70, STR_LEN8BIT | STR_UNICODE); - data->id_both_directory_info.file_id = BVAL(blob->data, 96); - len = smbcli_blob_pull_string(tree->session, mem_ctx, blob, - &data->id_both_directory_info.name, - 60, 104, 0); - if (ofs != 0 && ofs < 104+len) { - return -1; - } - return ofs; - case RAW_SEARCH_UNIX_INFO: if (blob->length < 109) return -1; ofs = IVAL(blob->data, 0); @@ -565,7 +593,25 @@ static int parse_trans2_search(struct smbcli_tree *tree, } return ofs; + case RAW_SEARCH_DIRECTORY_INFO: + case RAW_SEARCH_FULL_DIRECTORY_INFO: + case RAW_SEARCH_NAME_INFO: + case RAW_SEARCH_BOTH_DIRECTORY_INFO: + case RAW_SEARCH_ID_FULL_DIRECTORY_INFO: + case RAW_SEARCH_ID_BOTH_DIRECTORY_INFO: { + uint_t str_flags = STR_UNICODE; + if (!(tree->session->transport->negotiate.capabilities & CAP_UNICODE)) { + str_flags = STR_ASCII; + } + + status = smb_raw_search_common(mem_ctx, level, blob, data, &ofs, str_flags); + if (!NT_STATUS_IS_OK(status)) { + return -1; + } + return ofs; } + } + /* invalid level */ return -1; } -- cgit From f5d4623ea5a755a9525b9ef4532420ee53729a3d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 1 Dec 2005 00:22:08 +0000 Subject: r11982: ensure the fde event gets freed before the socket itself, as otherwise we get a error from epoll about disabling events for a file descriptor that is closed (This used to be commit f32739307464a1f0c835cff886b8c4b960778900) --- source4/libcli/raw/clisocket.c | 8 ++++---- source4/libcli/raw/clitransport.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index be25b36007..40d9d2784a 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -179,10 +179,10 @@ NTSTATUS smbcli_sock_connect(TALLOC_CTX *mem_ctx, ****************************************************************************/ void smbcli_sock_dead(struct smbcli_socket *sock) { - if (sock->sock != NULL) { - talloc_free(sock->sock); - sock->sock = NULL; - } + talloc_free(sock->event.fde); + sock->event.fde = NULL; + talloc_free(sock->sock); + sock->sock = NULL; } /**************************************************************************** diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 1cd0a3046e..a0efe7042c 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -115,7 +115,7 @@ struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock, handles events up until we are connected */ talloc_free(transport->socket->event.fde); transport->socket->event.fde = event_add_fd(transport->socket->event.ctx, - transport->socket, + transport->socket->sock, socket_get_fd(transport->socket->sock), EVENT_FD_READ, smbcli_transport_event_handler, -- cgit From 2cd5ca7d25f12aa9198bf8c2deb6aea282f573ee Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 28 Dec 2005 15:38:36 +0000 Subject: r12542: Move some more prototypes out to seperate headers (This used to be commit 0aca5fd5130d980d07398f3291d294202aefe3c2) --- source4/libcli/raw/clitransport.c | 1 + source4/libcli/raw/libcliraw.h | 2 ++ source4/libcli/raw/rawacl.c | 1 + 3 files changed, 4 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index a0efe7042c..2972da07a0 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -26,6 +26,7 @@ #include "dlinklist.h" #include "lib/events/events.h" #include "lib/stream/packet.h" +#include "libcli/nbt/libnbt.h" /* diff --git a/source4/libcli/raw/libcliraw.h b/source4/libcli/raw/libcliraw.h index decee83eb7..b09361b5ff 100644 --- a/source4/libcli/raw/libcliraw.h +++ b/source4/libcli/raw/libcliraw.h @@ -269,3 +269,5 @@ struct smbcli_request { req->status = NT_STATUS_INVALID_PARAMETER; \ goto failed; \ } + +#include "libcli/raw/raw_proto.h" diff --git a/source4/libcli/raw/rawacl.c b/source4/libcli/raw/rawacl.c index e168da9d1d..ae17447784 100644 --- a/source4/libcli/raw/rawacl.c +++ b/source4/libcli/raw/rawacl.c @@ -21,6 +21,7 @@ #include "includes.h" #include "librpc/gen_ndr/ndr_security.h" +#include "libcli/raw/libcliraw.h" /**************************************************************************** fetch file ACL (async send) -- cgit From d4de4c2d210d2e8c9b5aedf70695594809ad6a0b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 30 Dec 2005 13:16:54 +0000 Subject: r12608: Remove some unused #include lines. (This used to be commit 70e7449318aa0e9d2639c76730a7d1683b2f4981) --- source4/libcli/raw/clitransport.c | 1 - source4/libcli/raw/clitree.c | 1 - source4/libcli/raw/rawacl.c | 1 - source4/libcli/raw/rawfile.c | 1 - source4/libcli/raw/rawlpq.c | 1 - 5 files changed, 5 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 2972da07a0..a0efe7042c 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -26,7 +26,6 @@ #include "dlinklist.h" #include "lib/events/events.h" #include "lib/stream/packet.h" -#include "libcli/nbt/libnbt.h" /* diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index 96d36c569c..6e120ed615 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -23,7 +23,6 @@ #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 { \ diff --git a/source4/libcli/raw/rawacl.c b/source4/libcli/raw/rawacl.c index ae17447784..08515eadde 100644 --- a/source4/libcli/raw/rawacl.c +++ b/source4/libcli/raw/rawacl.c @@ -20,7 +20,6 @@ */ #include "includes.h" -#include "librpc/gen_ndr/ndr_security.h" #include "libcli/raw/libcliraw.h" /**************************************************************************** diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c index c6652125c2..6981a76800 100644 --- a/source4/libcli/raw/rawfile.c +++ b/source4/libcli/raw/rawfile.c @@ -22,7 +22,6 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" -#include "librpc/gen_ndr/ndr_security.h" #define SETUP_REQUEST(cmd, wct, buflen) do { \ req = smbcli_request_setup(tree, cmd, wct, buflen); \ diff --git a/source4/libcli/raw/rawlpq.c b/source4/libcli/raw/rawlpq.c index e83ee48707..40669e51de 100644 --- a/source4/libcli/raw/rawlpq.c +++ b/source4/libcli/raw/rawlpq.c @@ -19,7 +19,6 @@ */ #include "includes.h" -#include "libcli/raw/libcliraw.h" /**************************************************************************** lpq - async send -- cgit From 78c50015bb8bd5a1d831a6e7ec796b3367c73145 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 3 Jan 2006 15:40:05 +0000 Subject: r12694: Move some headers to the directory of the subsystem they belong to. (This used to be commit c722f665c90103f3ed57621c460e32ad33e7a8a3) --- source4/libcli/raw/libcliraw.h | 1 + source4/libcli/raw/rawfile.c | 1 + source4/libcli/raw/smb_signing.c | 1 + 3 files changed, 3 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/libcliraw.h b/source4/libcli/raw/libcliraw.h index b09361b5ff..7eb0694bd2 100644 --- a/source4/libcli/raw/libcliraw.h +++ b/source4/libcli/raw/libcliraw.h @@ -21,6 +21,7 @@ */ #include "request.h" +#include "smb.h" #include "librpc/gen_ndr/ndr_nbt.h" struct smbcli_tree; /* forward declare */ diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c index 6981a76800..0cc7385cee 100644 --- a/source4/libcli/raw/rawfile.c +++ b/source4/libcli/raw/rawfile.c @@ -21,6 +21,7 @@ */ #include "includes.h" +#include "smb.h" #include "libcli/raw/libcliraw.h" #define SETUP_REQUEST(cmd, wct, buflen) do { \ diff --git a/source4/libcli/raw/smb_signing.c b/source4/libcli/raw/smb_signing.c index df63c33cb9..a73db78f7b 100644 --- a/source4/libcli/raw/smb_signing.c +++ b/source4/libcli/raw/smb_signing.c @@ -21,6 +21,7 @@ */ #include "includes.h" +#include "smb.h" #include "libcli/raw/libcliraw.h" #include "lib/crypto/crypto.h" -- cgit From db04cffbbfe15a52b954960ff0eb40d2a5e4f00d Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 5 Jan 2006 16:43:56 +0000 Subject: r12725: some minor updates metze (This used to be commit f2e97983f278211c6d70400ce1f43d6a69df0d8a) --- source4/libcli/raw/clitransport.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index a0efe7042c..df5c608d08 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -184,7 +184,7 @@ struct smbcli_request *smbcli_transport_connect_send(struct smbcli_transport *tr memcpy(p, calling_blob.data, calling_blob.length); p += calling_blob.length; - _smb_setlen(req->out.buffer, PTR_DIFF(p, req->out.buffer)-4); + _smb_setlen(req->out.buffer, PTR_DIFF(p, req->out.buffer) - NBT_HDR_SIZE); SCVAL(req->out.buffer,0,0x81); if (!smbcli_request_send(req)) { -- cgit From 5c8447773f306e302c7182611e4fc03978c340b6 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 9 Jan 2006 21:44:30 +0000 Subject: r12801: Some more include/ cleanups (remove unused macros + move files to specific dirs) (This used to be commit 243cf760b077e155f5ac508aeebf819f7708a84e) --- source4/libcli/raw/libcliraw.h | 2 +- source4/libcli/raw/request.h | 62 ++++++++++++++++++++++++++++++++++++++++++ source4/libcli/raw/signing.h | 40 +++++++++++++++++++++++++++ 3 files changed, 103 insertions(+), 1 deletion(-) create mode 100644 source4/libcli/raw/request.h create mode 100644 source4/libcli/raw/signing.h (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/libcliraw.h b/source4/libcli/raw/libcliraw.h index 7eb0694bd2..96a06b9bec 100644 --- a/source4/libcli/raw/libcliraw.h +++ b/source4/libcli/raw/libcliraw.h @@ -20,7 +20,7 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "request.h" +#include "libcli/raw/request.h" #include "smb.h" #include "librpc/gen_ndr/ndr_nbt.h" diff --git a/source4/libcli/raw/request.h b/source4/libcli/raw/request.h new file mode 100644 index 0000000000..4a569cfe66 --- /dev/null +++ b/source4/libcli/raw/request.h @@ -0,0 +1,62 @@ +#ifndef _REQUEST_H +#define _REQUEST_H +/* + Unix SMB/CIFS implementation. + SMB parameters and setup + Copyright (C) Andrew Tridgell 2003 + Copyright (C) James Myers 2003 + + 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. +*/ + +#include "libcli/raw/signing.h" + +/* + Shared state structure between client and server, representing the basic packet. +*/ + +struct request_buffer { + /* the raw SMB buffer, including the 4 byte length header */ + uint8_t *buffer; + + /* the size of the raw buffer, including 4 byte header */ + uint_t size; + + /* how much has been allocated - on reply the buffer is over-allocated to + prevent too many realloc() calls + */ + uint_t allocated; + + /* the start of the SMB header - this is always buffer+4 */ + uint8_t *hdr; + + /* the command words and command word count. vwv points + into the raw buffer */ + uint8_t *vwv; + uint_t wct; + + /* the data buffer and size. data points into the raw buffer */ + uint8_t *data; + uint_t data_size; + + /* ptr is used as a moving pointer into the data area + * of the packet. The reason its here and not a local + * variable in each function is that when a realloc of + * a send packet is done we need to move this + * pointer */ + uint8_t *ptr; +}; + +#endif diff --git a/source4/libcli/raw/signing.h b/source4/libcli/raw/signing.h new file mode 100644 index 0000000000..dfc5a4bd7e --- /dev/null +++ b/source4/libcli/raw/signing.h @@ -0,0 +1,40 @@ +#ifndef _SIGNING_H +#define _SIGNING_H +/* + Unix SMB/CIFS implementation. + SMB Signing + + Andrew Bartlett 2003-2004 + + 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. +*/ + +enum smb_signing_engine_state { + SMB_SIGNING_ENGINE_OFF, + SMB_SIGNING_ENGINE_BSRSPYL, + SMB_SIGNING_ENGINE_ON +}; + +struct smb_signing_context { + enum smb_signing_engine_state signing_state; + DATA_BLOB mac_key; + uint32_t next_seq_num; + BOOL allow_smb_signing; + BOOL doing_signing; + BOOL mandatory_signing; + BOOL seen_valid; /* Have I ever seen a validly signed packet? */ +}; + +#endif -- cgit From d3bcaf66a8568fc19a3013f9dc974fb08ee3a39a Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 23 Feb 2006 12:44:21 +0000 Subject: r13654: Move some more stuff out of include/ (This used to be commit 2ec7bba03a2edf713004941e9ed74798f5cf8d32) --- source4/libcli/raw/interfaces.h | 2035 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 2035 insertions(+) create mode 100644 source4/libcli/raw/interfaces.h (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h new file mode 100644 index 0000000000..49fe085f2c --- /dev/null +++ b/source4/libcli/raw/interfaces.h @@ -0,0 +1,2035 @@ +/* + Unix SMB/CIFS implementation. + SMB request interface structures + Copyright (C) Andrew Tridgell 2003 + Copyright (C) James J Myers 2003 + + 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 structure is just a wrapper for a string, the only reason we + bother with this is that it allows us to check the length provided + on the wire in testsuite test code to ensure that we are + terminating names in the same way that win2003 is. The *ONLY* time + you should ever look at the 'private_length' field in this + structure is inside compliance test code, in all other cases just + use the null terminated char* as the definitive definition of the + string + + also note that this structure is only used in packets where there + is an explicit length provided on the wire (hence the name). That + length is placed in 'private_length'. For packets where the length + is always determined by NULL or packet termination a normal char* + is used in the structure definition. + */ +typedef struct { + uint32_t private_length; + const char *s; +} WIRE_STRING; + + +/* + use the same structure for dom_sid2 as dom_sid. A dom_sid2 is really + just a dom sid, but with the sub_auths represented as a conformant + array. As with all in-structure conformant arrays, the array length + is placed before the start of the structure. That's what gives rise + to the extra num_auths elemenent. We don't want the Samba code to + have to bother with such esoteric NDR details, so its easier to just + define it as a dom_sid and use pidl magic to make it all work. It + just means you need to mark a sid as a "dom_sid2" in the IDL when you + know it is of the conformant array variety +*/ +#define dom_sid2 dom_sid + +/* same struct as dom_sid but inside a 28 bytes fixed buffer in NDR */ +#define dom_sid28 dom_sid + + +/* + this header defines the structures and unions used between the SMB + parser and the backends. +*/ + +/* struct used for SMBlseek call */ +struct smb_seek { + struct { + uint16_t fnum; + uint16_t mode; + int32_t offset; /* signed */ + } in; + struct { + int32_t offset; + } out; +}; + + +/* struct used in unlink() call */ +struct smb_unlink { + struct { + const char *pattern; + uint16_t attrib; + } in; +}; + + +/* struct used in chkpath() call */ +struct smb_chkpath { + struct { + const char *path; + } in; +}; + +enum smb_mkdir_level {RAW_MKDIR_GENERIC, RAW_MKDIR_MKDIR, RAW_MKDIR_T2MKDIR}; + +/* union used in mkdir() call */ +union smb_mkdir { + /* generic level */ + struct { + enum smb_mkdir_level level; + } generic; + + struct { + enum smb_mkdir_level level; + struct { + const char *path; + } in; + } mkdir; + + struct { + enum smb_mkdir_level level; + struct { + const char *path; + uint_t num_eas; + struct ea_struct *eas; + } in; + } t2mkdir; +}; + +/* struct used in rmdir() call */ +struct smb_rmdir { + struct { + const char *path; + } in; +}; + +/* struct used in rename() call */ +enum smb_rename_level {RAW_RENAME_RENAME, RAW_RENAME_NTRENAME}; + +union smb_rename { + struct { + enum smb_rename_level level; + } generic; + + /* SMBrename interface */ + struct { + enum smb_rename_level level; + + struct { + const char *pattern1; + const char *pattern2; + uint16_t attrib; + } in; + } rename; + + + /* SMBntrename interface */ + struct { + enum smb_rename_level level; + + struct { + uint16_t attrib; + uint16_t flags; /* see RENAME_FLAG_* */ + uint32_t cluster_size; + const char *old_name; + const char *new_name; + } in; + } ntrename; +}; + +enum smb_tcon_level {RAW_TCON_TCON, RAW_TCON_TCONX}; + +/* union used in tree connect call */ +union smb_tcon { + /* generic interface */ + struct { + enum smb_tcon_level level; + } generic; + + /* SMBtcon interface */ + struct { + enum smb_tcon_level level; + + struct { + const char *service; + const char *password; + const char *dev; + } in; + struct { + uint16_t max_xmit; + uint16_t tid; + } out; + } tcon; + + /* SMBtconX interface */ + struct { + enum smb_tcon_level level; + + struct { + uint16_t flags; + DATA_BLOB password; + const char *path; + const char *device; + } in; + struct { + uint16_t options; + char *dev_type; + char *fs_type; + uint16_t tid; + } out; + } tconx; +}; + + +enum smb_sesssetup_level {RAW_SESSSETUP_OLD, RAW_SESSSETUP_NT1, RAW_SESSSETUP_SPNEGO}; + +/* union used in session_setup call */ +union smb_sesssetup { + /* the pre-NT1 interface */ + struct { + enum smb_sesssetup_level level; + + struct { + uint16_t bufsize; + uint16_t mpx_max; + uint16_t vc_num; + uint32_t sesskey; + DATA_BLOB password; + const char *user; + const char *domain; + const char *os; + const char *lanman; + } in; + struct { + uint16_t action; + uint16_t vuid; + char *os; + char *lanman; + char *domain; + } out; + } old; + + /* the NT1 interface */ + struct { + enum smb_sesssetup_level level; + + struct { + uint16_t bufsize; + uint16_t mpx_max; + uint16_t vc_num; + uint32_t sesskey; + uint32_t capabilities; + DATA_BLOB password1; + DATA_BLOB password2; + const char *user; + const char *domain; + const char *os; + const char *lanman; + } in; + struct { + uint16_t action; + uint16_t vuid; + char *os; + char *lanman; + char *domain; + } out; + } nt1; + + + /* the SPNEGO interface */ + struct { + enum smb_sesssetup_level level; + + struct { + uint16_t bufsize; + uint16_t mpx_max; + uint16_t vc_num; + uint32_t sesskey; + uint32_t capabilities; + DATA_BLOB secblob; + const char *os; + const char *lanman; + const char *workgroup; + } in; + struct { + uint16_t action; + DATA_BLOB secblob; + char *os; + char *lanman; + char *workgroup; + uint16_t vuid; + } out; + } spnego; +}; + +/* Note that the specified enum values are identical to the actual info-levels used + * on the wire. + */ +enum smb_fileinfo_level { + RAW_FILEINFO_GENERIC = 0xF000, + RAW_FILEINFO_GETATTR, /* SMBgetatr */ + RAW_FILEINFO_GETATTRE, /* SMBgetattrE */ + RAW_FILEINFO_SEC_DESC, /* NT_TRANSACT_QUERY_SECURITY_DESC */ + RAW_FILEINFO_STANDARD = SMB_QFILEINFO_STANDARD, + RAW_FILEINFO_EA_SIZE = SMB_QFILEINFO_EA_SIZE, + RAW_FILEINFO_EA_LIST = SMB_QFILEINFO_EA_LIST, + RAW_FILEINFO_ALL_EAS = SMB_QFILEINFO_ALL_EAS, + RAW_FILEINFO_IS_NAME_VALID = SMB_QFILEINFO_IS_NAME_VALID, + RAW_FILEINFO_BASIC_INFO = SMB_QFILEINFO_BASIC_INFO, + RAW_FILEINFO_STANDARD_INFO = SMB_QFILEINFO_STANDARD_INFO, + RAW_FILEINFO_EA_INFO = SMB_QFILEINFO_EA_INFO, + RAW_FILEINFO_NAME_INFO = SMB_QFILEINFO_NAME_INFO, + RAW_FILEINFO_ALL_INFO = SMB_QFILEINFO_ALL_INFO, + RAW_FILEINFO_ALT_NAME_INFO = SMB_QFILEINFO_ALT_NAME_INFO, + RAW_FILEINFO_STREAM_INFO = SMB_QFILEINFO_STREAM_INFO, + RAW_FILEINFO_COMPRESSION_INFO = SMB_QFILEINFO_COMPRESSION_INFO, + RAW_FILEINFO_UNIX_BASIC = SMB_QFILEINFO_UNIX_BASIC, + RAW_FILEINFO_UNIX_LINK = SMB_QFILEINFO_UNIX_LINK, + RAW_FILEINFO_BASIC_INFORMATION = SMB_QFILEINFO_BASIC_INFORMATION, + RAW_FILEINFO_STANDARD_INFORMATION = SMB_QFILEINFO_STANDARD_INFORMATION, + RAW_FILEINFO_INTERNAL_INFORMATION = SMB_QFILEINFO_INTERNAL_INFORMATION, + RAW_FILEINFO_EA_INFORMATION = SMB_QFILEINFO_EA_INFORMATION, + RAW_FILEINFO_ACCESS_INFORMATION = SMB_QFILEINFO_ACCESS_INFORMATION, + RAW_FILEINFO_NAME_INFORMATION = SMB_QFILEINFO_NAME_INFORMATION, + RAW_FILEINFO_POSITION_INFORMATION = SMB_QFILEINFO_POSITION_INFORMATION, + RAW_FILEINFO_MODE_INFORMATION = SMB_QFILEINFO_MODE_INFORMATION, + RAW_FILEINFO_ALIGNMENT_INFORMATION = SMB_QFILEINFO_ALIGNMENT_INFORMATION, + RAW_FILEINFO_ALL_INFORMATION = SMB_QFILEINFO_ALL_INFORMATION, + RAW_FILEINFO_ALT_NAME_INFORMATION = SMB_QFILEINFO_ALT_NAME_INFORMATION, + RAW_FILEINFO_STREAM_INFORMATION = SMB_QFILEINFO_STREAM_INFORMATION, + RAW_FILEINFO_COMPRESSION_INFORMATION = SMB_QFILEINFO_COMPRESSION_INFORMATION, + RAW_FILEINFO_NETWORK_OPEN_INFORMATION = SMB_QFILEINFO_NETWORK_OPEN_INFORMATION, + RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION = SMB_QFILEINFO_ATTRIBUTE_TAG_INFORMATION, + /* SMB2 specific levels */ + RAW_FILEINFO_SMB2_ALL_EAS = 0x0f01, + RAW_FILEINFO_SMB2_ALL_INFORMATION = 0x1201 +}; + +/* + file handles in SMB2 are 16 bytes +*/ +struct smb2_handle { + uint64_t data[2]; +}; + + +/* union used in qfileinfo() and qpathinfo() backend calls */ +union smb_fileinfo { + /* generic interface: + * matches RAW_FILEINFO_GENERIC */ + struct { + enum smb_fileinfo_level level; + + /* each level can be called on either a pathname or a + filename, in either case the return format is + identical + On SMB2 a 16 byte handle is used + */ + union smb_fileinfo_in { + const char *fname; + uint16_t fnum; + struct smb2_handle handle; + } in; + + struct { + uint32_t attrib; + uint32_t ea_size; + uint_t num_eas; + struct ea_struct { + uint8_t flags; + WIRE_STRING name; + DATA_BLOB value; + } *eas; + NTTIME create_time; + NTTIME access_time; + NTTIME write_time; + NTTIME change_time; + uint64_t alloc_size; + uint64_t size; + uint32_t nlink; + WIRE_STRING fname; + WIRE_STRING alt_fname; + uint8_t delete_pending; + uint8_t directory; + uint64_t compressed_size; + uint16_t format; + uint8_t unit_shift; + uint8_t chunk_shift; + uint8_t cluster_shift; + uint64_t file_id; + uint32_t access_flags; /* seen 0x001f01ff from w2k3 */ + uint64_t position; + uint32_t mode; + uint32_t alignment_requirement; + uint32_t reparse_tag; + uint_t num_streams; + struct stream_struct { + uint64_t size; + uint64_t alloc_size; + WIRE_STRING stream_name; + } *streams; + } out; + } generic; + + + /* SMBgetatr interface: + * matches RAW_FILEINFO_GETATTR */ + struct { + enum smb_fileinfo_level level; + union smb_fileinfo_in in; + + struct { + uint16_t attrib; + uint32_t size; + time_t write_time; + } out; + } getattr; + + /* SMBgetattrE and RAW_FILEINFO_STANDARD interface */ + struct { + enum smb_fileinfo_level level; + union smb_fileinfo_in in; + + struct { + time_t create_time; + time_t access_time; + time_t write_time; + uint32_t size; + uint32_t alloc_size; + uint16_t attrib; + } out; + } getattre, standard; + + /* trans2 RAW_FILEINFO_EA_SIZE interface */ + struct { + enum smb_fileinfo_level level; + union smb_fileinfo_in in; + + struct { + time_t create_time; + time_t access_time; + time_t write_time; + uint32_t size; + uint32_t alloc_size; + uint16_t attrib; + uint32_t ea_size; + } out; + } ea_size; + + /* trans2 RAW_FILEINFO_EA_LIST interface */ + struct { + enum smb_fileinfo_level level; + union smb_fileinfo_in file; + + struct { + uint_t num_names; + struct ea_name { + WIRE_STRING name; + } *ea_names; + } in; + + struct smb_ea_list { + uint_t num_eas; + struct ea_struct *eas; + } out; + } ea_list; + + /* trans2 RAW_FILEINFO_ALL_EAS and RAW_FILEINFO_FULL_EA_INFORMATION interfaces */ + struct { + enum smb_fileinfo_level level; + union smb_fileinfo_in in; + uint8_t continue_flags; /* SMB2 only - SMB2_CONTINUE_FLAG_* */ + + struct smb_ea_list out; + } all_eas; + + /* trans2 qpathinfo RAW_FILEINFO_IS_NAME_VALID interface + only valid for a QPATHNAME call - no returned data */ + struct { + enum smb_fileinfo_level level; + union smb_fileinfo_in in; + } is_name_valid; + + /* RAW_FILEINFO_BASIC_INFO and RAW_FILEINFO_BASIC_INFORMATION interfaces */ + struct { + enum smb_fileinfo_level level; + union smb_fileinfo_in in; + + struct { + NTTIME create_time; + NTTIME access_time; + NTTIME write_time; + NTTIME change_time; + uint32_t attrib; + } out; + } basic_info; + + + /* RAW_FILEINFO_STANDARD_INFO and RAW_FILEINFO_STANDARD_INFORMATION interfaces */ + struct { + enum smb_fileinfo_level level; + union smb_fileinfo_in in; + + struct { + uint64_t alloc_size; + uint64_t size; + uint32_t nlink; + BOOL delete_pending; + BOOL directory; + } out; + } standard_info; + + /* RAW_FILEINFO_EA_INFO and RAW_FILEINFO_EA_INFORMATION interfaces */ + struct { + enum smb_fileinfo_level level; + union smb_fileinfo_in in; + + struct { + uint32_t ea_size; + } out; + } ea_info; + + /* RAW_FILEINFO_NAME_INFO and RAW_FILEINFO_NAME_INFORMATION interfaces */ + struct { + enum smb_fileinfo_level level; + union smb_fileinfo_in in; + + struct { + WIRE_STRING fname; + } out; + } name_info; + + /* RAW_FILEINFO_ALL_INFO and RAW_FILEINFO_ALL_INFORMATION interfaces */ + struct { + enum smb_fileinfo_level level; + union smb_fileinfo_in in; + + struct { + NTTIME create_time; + NTTIME access_time; + NTTIME write_time; + NTTIME change_time; + uint32_t attrib; + uint64_t alloc_size; + uint64_t size; + uint32_t nlink; + uint8_t delete_pending; + uint8_t directory; + uint32_t ea_size; + WIRE_STRING fname; + } out; + } all_info; + + /* RAW_FILEINFO_SMB2_ALL_INFORMATION interface */ + struct { + enum smb_fileinfo_level level; + union smb_fileinfo_in in; + + struct { + NTTIME create_time; + NTTIME access_time; + NTTIME write_time; + NTTIME change_time; + uint32_t attrib; + uint32_t unknown1; + uint64_t alloc_size; + uint64_t size; + uint32_t nlink; + uint8_t delete_pending; + uint8_t directory; + /* uint16_t _pad; */ + uint64_t file_id; + uint32_t ea_size; + uint32_t access_mask; + uint64_t position; + uint64_t mode; + WIRE_STRING fname; + } out; + } all_info2; + + /* RAW_FILEINFO_ALT_NAME_INFO and RAW_FILEINFO_ALT_NAME_INFORMATION interfaces */ + struct { + enum smb_fileinfo_level level; + union smb_fileinfo_in in; + + struct { + WIRE_STRING fname; + } out; + } alt_name_info; + + /* RAW_FILEINFO_STREAM_INFO and RAW_FILEINFO_STREAM_INFORMATION interfaces */ + struct { + enum smb_fileinfo_level level; + union smb_fileinfo_in in; + + struct stream_information { + uint_t num_streams; + struct stream_struct *streams; + } out; + } stream_info; + + /* RAW_FILEINFO_COMPRESSION_INFO and RAW_FILEINFO_COMPRESSION_INFORMATION interfaces */ + struct { + enum smb_fileinfo_level level; + union smb_fileinfo_in in; + + struct { + uint64_t compressed_size; + uint16_t format; + uint8_t unit_shift; + uint8_t chunk_shift; + uint8_t cluster_shift; + } out; + } compression_info; + + /* RAW_FILEINFO_UNIX_BASIC interface */ + struct { + enum smb_fileinfo_level level; + union smb_fileinfo_in in; + + struct { + uint64_t end_of_file; + uint64_t num_bytes; + NTTIME status_change_time; + NTTIME access_time; + NTTIME change_time; + uint64_t uid; + uint64_t gid; + uint32_t file_type; + uint64_t dev_major; + uint64_t dev_minor; + uint64_t unique_id; + uint64_t permissions; + uint64_t nlink; + } out; + } unix_basic_info; + + /* RAW_FILEINFO_UNIX_LINK interface */ + struct { + enum smb_fileinfo_level level; + union smb_fileinfo_in in; + + struct { + WIRE_STRING link_dest; + } out; + } unix_link_info; + + /* RAW_FILEINFO_INTERNAL_INFORMATION interface */ + struct { + enum smb_fileinfo_level level; + union smb_fileinfo_in in; + + struct { + uint64_t file_id; + } out; + } internal_information; + + /* RAW_FILEINFO_ACCESS_INFORMATION interface */ + struct { + enum smb_fileinfo_level level; + union smb_fileinfo_in in; + + struct { + uint32_t access_flags; + } out; + } access_information; + + /* RAW_FILEINFO_POSITION_INFORMATION interface */ + struct { + enum smb_fileinfo_level level; + union smb_fileinfo_in in; + + struct { + uint64_t position; + } out; + } position_information; + + /* RAW_FILEINFO_MODE_INFORMATION interface */ + struct { + enum smb_fileinfo_level level; + union smb_fileinfo_in in; + + struct { + uint32_t mode; + } out; + } mode_information; + + /* RAW_FILEINFO_ALIGNMENT_INFORMATION interface */ + struct { + enum smb_fileinfo_level level; + union smb_fileinfo_in in; + + struct { + uint32_t alignment_requirement; + } out; + } alignment_information; + + /* RAW_FILEINFO_NETWORK_OPEN_INFORMATION interface */ + struct { + enum smb_fileinfo_level level; + union smb_fileinfo_in in; + + struct { + NTTIME create_time; + NTTIME access_time; + NTTIME write_time; + NTTIME change_time; + uint64_t alloc_size; + uint64_t size; + uint32_t attrib; + } out; + } network_open_information; + + + /* RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION interface */ + struct { + enum smb_fileinfo_level level; + union smb_fileinfo_in in; + + struct { + uint32_t attrib; + uint32_t reparse_tag; + } out; + } attribute_tag_information; + + /* RAW_FILEINFO_SEC_DESC */ + struct { + enum smb_fileinfo_level level; + union smb_fileinfo_in in; + uint32_t secinfo_flags; + struct { + struct security_descriptor *sd; + } out; + } query_secdesc; +}; + + +enum smb_setfileinfo_level { + RAW_SFILEINFO_GENERIC = 0xF000, + RAW_SFILEINFO_SETATTR, /* SMBsetatr */ + RAW_SFILEINFO_SETATTRE, /* SMBsetattrE */ + RAW_SFILEINFO_SEC_DESC, /* NT_TRANSACT_SET_SECURITY_DESC */ + RAW_SFILEINFO_STANDARD = SMB_SFILEINFO_STANDARD, + RAW_SFILEINFO_EA_SET = SMB_SFILEINFO_EA_SET, + RAW_SFILEINFO_BASIC_INFO = SMB_SFILEINFO_BASIC_INFO, + RAW_SFILEINFO_DISPOSITION_INFO = SMB_SFILEINFO_DISPOSITION_INFO, + RAW_SFILEINFO_ALLOCATION_INFO = SMB_SFILEINFO_ALLOCATION_INFO, + RAW_SFILEINFO_END_OF_FILE_INFO = SMB_SFILEINFO_END_OF_FILE_INFO, + RAW_SFILEINFO_UNIX_BASIC = SMB_SFILEINFO_UNIX_BASIC, + RAW_SFILEINFO_UNIX_LINK = SMB_SFILEINFO_UNIX_LINK, + RAW_SFILEINFO_UNIX_HLINK = SMB_SFILEINFO_UNIX_HLINK, + RAW_SFILEINFO_BASIC_INFORMATION = SMB_SFILEINFO_BASIC_INFORMATION, + RAW_SFILEINFO_RENAME_INFORMATION = SMB_SFILEINFO_RENAME_INFORMATION, + RAW_SFILEINFO_DISPOSITION_INFORMATION = SMB_SFILEINFO_DISPOSITION_INFORMATION, + RAW_SFILEINFO_POSITION_INFORMATION = SMB_SFILEINFO_POSITION_INFORMATION, + RAW_SFILEINFO_MODE_INFORMATION = SMB_SFILEINFO_MODE_INFORMATION, + RAW_SFILEINFO_ALLOCATION_INFORMATION = SMB_SFILEINFO_ALLOCATION_INFORMATION, + RAW_SFILEINFO_END_OF_FILE_INFORMATION = SMB_SFILEINFO_END_OF_FILE_INFORMATION, + RAW_SFILEINFO_1023 = SMB_SFILEINFO_1023, + RAW_SFILEINFO_1025 = SMB_SFILEINFO_1025, + RAW_SFILEINFO_1029 = SMB_SFILEINFO_1029, + RAW_SFILEINFO_1032 = SMB_SFILEINFO_1032, + RAW_SFILEINFO_1039 = SMB_SFILEINFO_1039, + RAW_SFILEINFO_1040 = SMB_SFILEINFO_1040 +}; + +/* union used in setfileinfo() and setpathinfo() calls */ +union smb_setfileinfo { + /* generic interface */ + struct { + enum smb_setfileinfo_level level; + + /* we are combining setfileinfo and setpathinfo into one + interface */ + union setfileinfo_file { + const char *fname; + uint16_t fnum; + struct smb2_handle handle; /* only for SMB2 */ + } file; + } generic; + + /* RAW_SFILEINFO_SETATTR (SMBsetatr) interface - only via setpathinfo() */ + struct { + enum smb_setfileinfo_level level; + union setfileinfo_file file; + struct { + uint16_t attrib; + time_t write_time; + } in; + } setattr; + + /* RAW_SFILEINFO_SETATTRE (SMBsetattrE) interface - only via setfileinfo() + also RAW_SFILEINFO_STANDARD */ + struct { + enum smb_setfileinfo_level level; + union setfileinfo_file file; + + struct { + time_t create_time; + time_t access_time; + time_t write_time; + /* notice that size, alloc_size and attrib are not settable, + unlike the corresponding qfileinfo level */ + } in; + } setattre, standard; + + /* RAW_SFILEINFO_EA_SET interface */ + struct { + enum smb_setfileinfo_level level; + union setfileinfo_file file; + struct { + uint_t num_eas; + struct ea_struct *eas; + } in; + } ea_set; + + /* RAW_SFILEINFO_BASIC_INFO and + RAW_SFILEINFO_BASIC_INFORMATION interfaces */ + struct { + enum smb_setfileinfo_level level; + union setfileinfo_file file; + + struct { + NTTIME create_time; + NTTIME access_time; + NTTIME write_time; + NTTIME change_time; + uint32_t attrib; + } in; + } basic_info; + + /* RAW_SFILEINFO_DISPOSITION_INFO and + RAW_SFILEINFO_DISPOSITION_INFORMATION interfaces */ + struct { + enum smb_setfileinfo_level level; + union setfileinfo_file file; + + struct { + BOOL delete_on_close; + } in; + } disposition_info; + + /* RAW_SFILEINFO_ALLOCATION_INFO and + RAW_SFILEINFO_ALLOCATION_INFORMATION interfaces */ + struct { + enum smb_setfileinfo_level level; + union setfileinfo_file file; + + struct { + /* w2k3 rounds this up to nearest 4096 */ + uint64_t alloc_size; + } in; + } allocation_info; + + /* RAW_SFILEINFO_END_OF_FILE_INFO and + RAW_SFILEINFO_END_OF_FILE_INFORMATION interfaces */ + struct { + enum smb_setfileinfo_level level; + union setfileinfo_file file; + + struct { + uint64_t size; + } in; + } end_of_file_info; + + /* RAW_SFILEINFO_RENAME_INFORMATION interface */ + struct { + enum smb_setfileinfo_level level; + union setfileinfo_file file; + + struct smb_rename_information { + uint8_t overwrite; + uint32_t root_fid; + const char *new_name; + } in; + } rename_information; + + /* RAW_SFILEINFO_POSITION_INFORMATION interface */ + struct { + enum smb_setfileinfo_level level; + union setfileinfo_file file; + + struct { + uint64_t position; + } in; + } position_information; + + /* RAW_SFILEINFO_MODE_INFORMATION interface */ + struct { + enum smb_setfileinfo_level level; + union setfileinfo_file file; + + struct { + /* valid values seem to be 0, 2, 4 and 6 */ + uint32_t mode; + } in; + } mode_information; + + + + /* RAW_SFILEINFO_UNIX_BASIC interface */ + struct { + enum smb_setfileinfo_level level; + union setfileinfo_file file; + struct { + uint32_t mode; /* yuck - this field remains to fix compile of libcli/clifile.c */ + uint64_t end_of_file; + uint64_t num_bytes; + NTTIME status_change_time; + NTTIME access_time; + NTTIME change_time; + uint64_t uid; + uint64_t gid; + uint32_t file_type; + uint64_t dev_major; + uint64_t dev_minor; + uint64_t unique_id; + uint64_t permissions; + uint64_t nlink; + } in; + } unix_basic; + + /* RAW_SFILEINFO_UNIX_LINK, RAW_SFILEINFO_UNIX_HLINK interface */ + struct { + enum smb_setfileinfo_level level; + union setfileinfo_file file; + struct { + const char *link_dest; + } in; + } unix_link, unix_hlink; + + /* RAW_FILEINFO_SET_SEC_DESC */ + struct { + enum smb_setfileinfo_level level; + union setfileinfo_file file; + struct { + uint32_t secinfo_flags; + struct security_descriptor *sd; + } in; + } set_secdesc; +}; + + +enum smb_fsinfo_level { + RAW_QFS_GENERIC = 0xF000, + RAW_QFS_DSKATTR, /* SMBdskattr */ + RAW_QFS_ALLOCATION = SMB_QFS_ALLOCATION, + RAW_QFS_VOLUME = SMB_QFS_VOLUME, + RAW_QFS_VOLUME_INFO = SMB_QFS_VOLUME_INFO, + RAW_QFS_SIZE_INFO = SMB_QFS_SIZE_INFO, + RAW_QFS_DEVICE_INFO = SMB_QFS_DEVICE_INFO, + RAW_QFS_ATTRIBUTE_INFO = SMB_QFS_ATTRIBUTE_INFO, + RAW_QFS_UNIX_INFO = SMB_QFS_UNIX_INFO, + RAW_QFS_VOLUME_INFORMATION = SMB_QFS_VOLUME_INFORMATION, + RAW_QFS_SIZE_INFORMATION = SMB_QFS_SIZE_INFORMATION, + RAW_QFS_DEVICE_INFORMATION = SMB_QFS_DEVICE_INFORMATION, + RAW_QFS_ATTRIBUTE_INFORMATION = SMB_QFS_ATTRIBUTE_INFORMATION, + RAW_QFS_QUOTA_INFORMATION = SMB_QFS_QUOTA_INFORMATION, + RAW_QFS_FULL_SIZE_INFORMATION = SMB_QFS_FULL_SIZE_INFORMATION, + RAW_QFS_OBJECTID_INFORMATION = SMB_QFS_OBJECTID_INFORMATION}; + + +/* union for fsinfo() backend call. Note that there are no in + structures, as this call only contains out parameters */ +union smb_fsinfo { + /* generic interface */ + struct { + enum smb_fsinfo_level level; + struct smb2_handle handle; /* only for smb2 */ + + struct { + uint32_t block_size; + uint64_t blocks_total; + uint64_t blocks_free; + uint32_t fs_id; + NTTIME create_time; + uint32_t serial_number; + uint32_t fs_attr; + uint32_t max_file_component_length; + uint32_t device_type; + uint32_t device_characteristics; + uint64_t quota_soft; + uint64_t quota_hard; + uint64_t quota_flags; + struct GUID guid; + char *volume_name; + char *fs_type; + } out; + } generic; + + /* SMBdskattr interface */ + struct { + enum smb_fsinfo_level level; + + struct { + uint16_t units_total; + uint16_t blocks_per_unit; + uint16_t block_size; + uint16_t units_free; + } out; + } dskattr; + + /* trans2 RAW_QFS_ALLOCATION interface */ + struct { + enum smb_fsinfo_level level; + + struct { + uint32_t fs_id; + uint32_t sectors_per_unit; + uint32_t total_alloc_units; + uint32_t avail_alloc_units; + uint16_t bytes_per_sector; + } out; + } allocation; + + /* TRANS2 RAW_QFS_VOLUME interface */ + struct { + enum smb_fsinfo_level level; + + struct { + uint32_t serial_number; + WIRE_STRING volume_name; + } out; + } volume; + + /* TRANS2 RAW_QFS_VOLUME_INFO and RAW_QFS_VOLUME_INFORMATION interfaces */ + struct { + enum smb_fsinfo_level level; + struct smb2_handle handle; /* only for smb2 */ + + struct { + NTTIME create_time; + uint32_t serial_number; + WIRE_STRING volume_name; + } out; + } volume_info; + + /* trans2 RAW_QFS_SIZE_INFO and RAW_QFS_SIZE_INFORMATION interfaces */ + struct { + enum smb_fsinfo_level level; + struct smb2_handle handle; /* only for smb2 */ + + struct { + uint64_t total_alloc_units; + uint64_t avail_alloc_units; /* maps to call_avail_alloc_units */ + uint32_t sectors_per_unit; + uint32_t bytes_per_sector; + } out; + } size_info; + + /* TRANS2 RAW_QFS_DEVICE_INFO and RAW_QFS_DEVICE_INFORMATION interfaces */ + struct { + enum smb_fsinfo_level level; + struct smb2_handle handle; /* only for smb2 */ + + struct { + uint32_t device_type; + uint32_t characteristics; + } out; + } device_info; + + + /* TRANS2 RAW_QFS_ATTRIBUTE_INFO and RAW_QFS_ATTRIBUTE_INFORMATION interfaces */ + struct { + enum smb_fsinfo_level level; + struct smb2_handle handle; /* only for smb2 */ + + struct { + uint32_t fs_attr; + uint32_t max_file_component_length; + WIRE_STRING fs_type; + } out; + } attribute_info; + + + /* TRANS2 RAW_QFS_UNIX_INFO interface */ + struct { + enum smb_fsinfo_level level; + + struct { + uint16_t major_version; + uint16_t minor_version; + uint64_t capability; + } out; + } unix_info; + + /* trans2 RAW_QFS_QUOTA_INFORMATION interface */ + struct { + enum smb_fsinfo_level level; + struct smb2_handle handle; /* only for smb2 */ + + struct { + uint64_t unknown[3]; + uint64_t quota_soft; + uint64_t quota_hard; + uint64_t quota_flags; + } out; + } quota_information; + + /* trans2 RAW_QFS_FULL_SIZE_INFORMATION interface */ + struct { + enum smb_fsinfo_level level; + struct smb2_handle handle; /* only for smb2 */ + + struct { + uint64_t total_alloc_units; + uint64_t call_avail_alloc_units; + uint64_t actual_avail_alloc_units; + uint32_t sectors_per_unit; + uint32_t bytes_per_sector; + } out; + } full_size_information; + + /* trans2 RAW_QFS_OBJECTID_INFORMATION interface */ + struct { + enum smb_fsinfo_level level; + struct smb2_handle handle; /* only for smb2 */ + + struct { + struct GUID guid; + uint64_t unknown[6]; + } out; + } objectid_information; +}; + + + +enum smb_open_level { + RAW_OPEN_OPEN, RAW_OPEN_OPENX, + RAW_OPEN_MKNEW, RAW_OPEN_CREATE, + RAW_OPEN_CTEMP, RAW_OPEN_SPLOPEN, + RAW_OPEN_NTCREATEX, RAW_OPEN_T2OPEN, + RAW_OPEN_NTTRANS_CREATE, + RAW_OPEN_OPENX_READX}; + +/* the generic interface is defined to be equal to the NTCREATEX interface */ +#define RAW_OPEN_GENERIC RAW_OPEN_NTCREATEX + +/* union for open() backend call */ +union smb_open { + /* SMBNTCreateX interface */ + struct { + enum smb_open_level level; + + struct { + uint32_t flags; + uint32_t root_fid; + uint32_t access_mask; + uint64_t alloc_size; + uint32_t file_attr; + uint32_t share_access; + uint32_t open_disposition; + uint32_t create_options; + uint32_t impersonation; + uint8_t security_flags; + /* NOTE: fname can also be a pointer to a + uint64_t file_id if create_options has the + NTCREATEX_OPTIONS_OPEN_BY_FILE_ID flag set */ + const char *fname; + + /* these last 2 elements are only used in the + NTTRANS varient of the call */ + struct security_descriptor *sec_desc; + struct smb_ea_list *ea_list; + } in; + + struct { + uint8_t oplock_level; + uint16_t fnum; + uint32_t create_action; + NTTIME create_time; + NTTIME access_time; + NTTIME write_time; + NTTIME change_time; + uint32_t attrib; + uint64_t alloc_size; + uint64_t size; + uint16_t file_type; + uint16_t ipc_state; + uint8_t is_directory; + } out; + } ntcreatex, generic; + + /* TRANS2_OPEN interface */ + struct { + enum smb_open_level level; + + struct { + uint16_t flags; + uint16_t open_mode; + uint16_t search_attrs; + uint16_t file_attrs; + time_t write_time; + uint16_t open_func; + uint32_t size; + uint32_t timeout; + const char *fname; + uint_t num_eas; + struct ea_struct *eas; + } in; + + struct { + uint16_t fnum; + uint16_t attrib; + time_t write_time; + uint32_t size; + uint16_t access; + uint16_t ftype; + uint16_t devstate; + uint16_t action; + uint32_t file_id; + } out; + } t2open; + + /* SMBopen interface */ + struct { + enum smb_open_level level; + + struct { + uint16_t open_mode; + uint16_t search_attrs; + const char *fname; + } in; + struct { + uint16_t fnum; + uint16_t attrib; + time_t write_time; + uint32_t size; + uint16_t rmode; + } out; + } openold; + + /* SMBopenX interface */ + struct { + enum smb_open_level level; + + struct { + uint16_t flags; + uint16_t open_mode; + uint16_t search_attrs; /* not honoured by win2003 */ + uint16_t file_attrs; + time_t write_time; /* not honoured by win2003 */ + uint16_t open_func; + uint32_t size; /* note that this sets the + initial file size, not + just allocation size */ + uint32_t timeout; /* not honoured by win2003 */ + const char *fname; + } in; + struct { + uint16_t fnum; + uint16_t attrib; + time_t write_time; + uint32_t size; + uint16_t access; + uint16_t ftype; + uint16_t devstate; + uint16_t action; + uint32_t unique_fid; + uint32_t access_mask; + uint32_t unknown; + } out; + } openx; + + /* SMBmknew interface */ + struct { + enum smb_open_level level; + + struct { + uint16_t attrib; + time_t write_time; + const char *fname; + } in; + struct { + uint16_t fnum; + } out; + } mknew, create; + + /* SMBctemp interface */ + struct { + enum smb_open_level level; + + struct { + uint16_t attrib; + time_t write_time; + const char *directory; + } in; + struct { + uint16_t fnum; + /* temp name, relative to directory */ + char *name; + } out; + } ctemp; + + /* SMBsplopen interface */ + struct { + enum smb_open_level level; + + struct { + uint16_t setup_length; + uint16_t mode; + const char *ident; + } in; + struct { + uint16_t fnum; + } out; + } splopen; + + + /* chained OpenX/ReadX interface */ + struct { + enum smb_open_level level; + + struct { + uint16_t flags; + uint16_t open_mode; + uint16_t search_attrs; /* not honoured by win2003 */ + uint16_t file_attrs; + time_t write_time; /* not honoured by win2003 */ + uint16_t open_func; + uint32_t size; /* note that this sets the + initial file size, not + just allocation size */ + uint32_t timeout; /* not honoured by win2003 */ + const char *fname; + + /* readx part */ + uint64_t offset; + uint16_t mincnt; + uint32_t maxcnt; + uint16_t remaining; + } in; + struct { + uint16_t fnum; + uint16_t attrib; + time_t write_time; + uint32_t size; + uint16_t access; + uint16_t ftype; + uint16_t devstate; + uint16_t action; + uint32_t unique_fid; + uint32_t access_mask; + uint32_t unknown; + + /* readx part */ + uint8_t *data; + uint16_t remaining; + uint16_t compaction_mode; + uint16_t nread; + } out; + } openxreadx; +}; + + + +enum smb_read_level {RAW_READ_READBRAW, RAW_READ_LOCKREAD, RAW_READ_READ, RAW_READ_READX}; + +#define RAW_READ_GENERIC RAW_READ_READX + +/* union for read() backend call + + note that .infoX.out.data will be allocated before the backend is + called. It will be big enough to hold the maximum size asked for +*/ +union smb_read { + /* SMBreadX (and generic) interface */ + struct { + enum smb_read_level level; + + struct { + uint16_t fnum; + uint64_t offset; + uint16_t mincnt; + uint32_t maxcnt; + uint16_t remaining; + } in; + struct { + uint8_t *data; + uint16_t remaining; + uint16_t compaction_mode; + uint16_t nread; + } out; + } readx, generic; + + /* SMBreadbraw interface */ + struct { + enum smb_read_level level; + + struct { + uint16_t fnum; + uint64_t offset; + uint16_t maxcnt; + uint16_t mincnt; + uint32_t timeout; + } in; + struct { + uint8_t *data; + uint32_t nread; + } out; + } readbraw; + + + /* SMBlockandread interface */ + struct { + enum smb_read_level level; + + struct { + uint16_t fnum; + uint16_t count; + uint32_t offset; + uint16_t remaining; + } in; + struct { + uint8_t *data; + uint16_t nread; + } out; + } lockread; + + /* SMBread interface */ + struct { + enum smb_read_level level; + + struct { + uint16_t fnum; + uint16_t count; + uint32_t offset; + uint16_t remaining; + } in; + struct { + uint8_t *data; + uint16_t nread; + } out; + } read; +}; + + +enum smb_write_level {RAW_WRITE_WRITEUNLOCK, RAW_WRITE_WRITE, + RAW_WRITE_WRITEX, RAW_WRITE_WRITECLOSE, + RAW_WRITE_SPLWRITE}; + +#define RAW_WRITE_GENERIC RAW_WRITE_WRITEX + +/* union for write() backend call +*/ +union smb_write { + /* SMBwriteX interface */ + struct { + enum smb_write_level level; + + struct { + uint16_t fnum; + uint64_t offset; + uint16_t wmode; + uint16_t remaining; + uint32_t count; + const uint8_t *data; + } in; + struct { + uint32_t nwritten; + uint16_t remaining; + } out; + } writex, generic; + + /* SMBwriteunlock interface */ + struct { + enum smb_write_level level; + + struct { + uint16_t fnum; + uint16_t count; + uint32_t offset; + uint16_t remaining; + const uint8_t *data; + } in; + struct { + uint32_t nwritten; + } out; + } writeunlock; + + /* SMBwrite interface */ + struct { + enum smb_write_level level; + + struct { + uint16_t fnum; + uint16_t count; + uint32_t offset; + uint16_t remaining; + const uint8_t *data; + } in; + struct { + uint16_t nwritten; + } out; + } write; + + /* SMBwriteclose interface */ + struct { + enum smb_write_level level; + + struct { + uint16_t fnum; + uint16_t count; + uint32_t offset; + time_t mtime; + const uint8_t *data; + } in; + struct { + uint16_t nwritten; + } out; + } writeclose; + + /* SMBsplwrite interface */ + struct { + enum smb_write_level level; + + struct { + uint16_t fnum; + uint16_t count; + const uint8_t *data; + } in; + } splwrite; +}; + + +enum smb_lock_level {RAW_LOCK_LOCK, RAW_LOCK_UNLOCK, RAW_LOCK_LOCKX}; + +/* the generic interface is defined to be equal to the lockingX interface */ +#define RAW_LOCK_GENERIC RAW_LOCK_LOCKX + +/* union for lock() backend call +*/ +union smb_lock { + /* SMBlockingX (and generic) interface */ + struct { + enum smb_lock_level level; + + struct { + uint16_t fnum; + uint16_t mode; + uint32_t timeout; + uint16_t ulock_cnt; + uint16_t lock_cnt; + struct smb_lock_entry { + uint16_t pid; + uint64_t offset; + uint64_t count; + } *locks; /* unlocks are first in the arrray */ + } in; + } lockx, generic; + + /* SMBlock and SMBunlock interface */ + struct { + enum smb_lock_level level; + + struct { + uint16_t fnum; + uint32_t count; + uint32_t offset; + } in; + } lock, unlock; +}; + + +enum smb_close_level {RAW_CLOSE_CLOSE, RAW_CLOSE_SPLCLOSE}; + +#define RAW_CLOSE_GENERIC RAW_CLOSE_CLOSE + +/* + union for close() backend call +*/ +union smb_close { + /* SMBclose (and generic) interface */ + struct { + enum smb_close_level level; + + struct { + uint16_t fnum; + time_t write_time; + } in; + } close, generic; + + /* SMBsplclose interface - empty! */ + struct { + enum smb_close_level level; + + struct { + uint16_t fnum; + } in; + } splclose; +}; + + +enum smb_lpq_level {RAW_LPQ_GENERIC, RAW_LPQ_RETQ}; + +/* + union for lpq() backend +*/ +union smb_lpq { + /* generic interface */ + struct { + enum smb_lpq_level level; + + } generic; + + + /* SMBsplretq interface */ + struct { + enum smb_lpq_level level; + + struct { + uint16_t maxcount; + uint16_t startidx; + } in; + struct { + uint16_t count; + uint16_t restart_idx; + struct { + time_t time; + uint8_t status; + uint16_t job; + uint32_t size; + char *user; + } *queue; + } out; + } retq; +}; + +enum smb_ioctl_level {RAW_IOCTL_IOCTL, RAW_IOCTL_NTIOCTL}; + +/* + union for ioctl() backend +*/ +union smb_ioctl { + /* generic interface */ + struct { + enum smb_ioctl_level level; + + } generic; + + /* struct for SMBioctl */ + struct { + enum smb_ioctl_level level; + struct { + uint16_t fnum; + uint32_t request; + } in; + struct { + DATA_BLOB blob; + } out; + } ioctl; + + + /* struct for NT ioctl call */ + struct { + enum smb_ioctl_level level; + struct { + uint32_t function; + uint16_t fnum; + BOOL fsctl; + uint8_t filter; + } in; + struct { + DATA_BLOB blob; + } out; + } ntioctl; +}; + +/* struct for SMBflush */ +struct smb_flush { + struct { + uint16_t fnum; + } in; +}; + + +/* struct for SMBcopy */ +struct smb_copy { + struct { + uint16_t tid2; + uint16_t ofun; + uint16_t flags; + const char *path1; + const char *path2; + } in; + struct { + uint16_t count; + } out; +}; + + +/* struct for transact/transact2 call */ +struct smb_trans2 { + struct { + uint16_t max_param; + uint16_t max_data; + uint8_t max_setup; + uint16_t flags; + uint32_t timeout; + uint8_t setup_count; + uint16_t *setup; + const char *trans_name; /* SMBtrans only */ + DATA_BLOB params; + DATA_BLOB data; + } in; + + struct { + uint8_t setup_count; + uint16_t *setup; + DATA_BLOB params; + DATA_BLOB data; + } out; +}; + +/* struct for nttransact2 call */ +struct smb_nttrans { + struct { + uint8_t max_setup; + uint32_t max_param; + uint32_t max_data; + uint32_t setup_count; + uint16_t function; + uint16_t *setup; + DATA_BLOB params; + DATA_BLOB data; + } in; + + struct { + uint8_t setup_count; + uint16_t *setup; + DATA_BLOB params; + DATA_BLOB data; + } out; +}; + + +/* struct for nttrans change notify call */ +struct smb_notify { + struct { + uint32_t buffer_size; + uint32_t completion_filter; + uint16_t fnum; + BOOL recursive; + } in; + + struct { + uint32_t num_changes; + struct notify_changes { + uint32_t action; + WIRE_STRING name; + } *changes; + } out; +}; + + +enum smb_search_level {RAW_SEARCH_GENERIC = 0xF000, + RAW_SEARCH_SEARCH, /* SMBsearch */ + RAW_SEARCH_FFIRST, /* SMBffirst */ + RAW_SEARCH_FUNIQUE, /* SMBfunique */ + RAW_SEARCH_STANDARD = SMB_FIND_STANDARD, + RAW_SEARCH_EA_SIZE = SMB_FIND_EA_SIZE, + RAW_SEARCH_EA_LIST = SMB_FIND_EA_LIST, + RAW_SEARCH_DIRECTORY_INFO = SMB_FIND_DIRECTORY_INFO, + RAW_SEARCH_FULL_DIRECTORY_INFO = SMB_FIND_FULL_DIRECTORY_INFO, + RAW_SEARCH_NAME_INFO = SMB_FIND_NAME_INFO, + RAW_SEARCH_BOTH_DIRECTORY_INFO = SMB_FIND_BOTH_DIRECTORY_INFO, + RAW_SEARCH_ID_FULL_DIRECTORY_INFO = SMB_FIND_ID_FULL_DIRECTORY_INFO, + RAW_SEARCH_ID_BOTH_DIRECTORY_INFO = SMB_FIND_ID_BOTH_DIRECTORY_INFO, + RAW_SEARCH_UNIX_INFO = SMB_FIND_UNIX_INFO}; + + +/* union for file search */ +union smb_search_first { + struct { + enum smb_search_level level; + } generic; + + /* search (old) findfirst interface. + Also used for ffirst and funique. */ + struct { + enum smb_search_level level; + + struct { + uint16_t max_count; + uint16_t search_attrib; + const char *pattern; + } in; + struct { + int16_t count; + } out; + } search_first; + + /* trans2 findfirst interface */ + struct { + enum smb_search_level level; + + struct { + uint16_t search_attrib; + uint16_t max_count; + uint16_t flags; + uint32_t storage_type; + const char *pattern; + + /* the ea names are only used for RAW_SEARCH_EA_LIST */ + uint_t num_names; + struct ea_name *ea_names; + } in; + struct { + uint16_t handle; + uint16_t count; + uint16_t end_of_search; + } out; + } t2ffirst; +}; + +/* union for file search continue */ +union smb_search_next { + struct { + enum smb_search_level level; + } generic; + + /* search (old) findnext interface. Also used + for ffirst when continuing */ + struct { + enum smb_search_level level; + + struct { + uint16_t max_count; + uint16_t search_attrib; + struct smb_search_id { + uint8_t reserved; + char name[11]; + uint8_t handle; + uint32_t server_cookie; + uint32_t client_cookie; + } id; + } in; + struct { + uint16_t count; + } out; + } search_next; + + /* trans2 findnext interface */ + struct { + enum smb_search_level level; + + struct { + uint16_t handle; + uint16_t max_count; + uint32_t resume_key; + uint16_t flags; + const char *last_name; + + /* the ea names are only used for RAW_SEARCH_EA_LIST */ + uint_t num_names; + struct ea_name *ea_names; + } in; + struct { + uint16_t count; + uint16_t end_of_search; + } out; + } t2fnext; +}; + +/* union for search reply file data */ +union smb_search_data { + /* search (old) findfirst */ + struct { + uint16_t attrib; + time_t write_time; + uint32_t size; + struct smb_search_id id; + const char *name; + } search; + + /* trans2 findfirst RAW_SEARCH_STANDARD level */ + struct { + uint32_t resume_key; + time_t create_time; + time_t access_time; + time_t write_time; + uint32_t size; + uint32_t alloc_size; + uint16_t attrib; + WIRE_STRING name; + } standard; + + /* trans2 findfirst RAW_SEARCH_EA_SIZE level */ + struct { + uint32_t resume_key; + time_t create_time; + time_t access_time; + time_t write_time; + uint32_t size; + uint32_t alloc_size; + uint16_t attrib; + uint32_t ea_size; + WIRE_STRING name; + } ea_size; + + /* trans2 findfirst RAW_SEARCH_EA_LIST level */ + struct { + uint32_t resume_key; + time_t create_time; + time_t access_time; + time_t write_time; + uint32_t size; + uint32_t alloc_size; + uint16_t attrib; + struct smb_ea_list eas; + WIRE_STRING name; + } ea_list; + + /* RAW_SEARCH_DIRECTORY_INFO interface */ + struct { + uint32_t file_index; + NTTIME create_time; + NTTIME access_time; + NTTIME write_time; + NTTIME change_time; + uint64_t size; + uint64_t alloc_size; + uint32_t attrib; + WIRE_STRING name; + } directory_info; + + /* RAW_SEARCH_FULL_DIRECTORY_INFO interface */ + struct { + uint32_t file_index; + NTTIME create_time; + NTTIME access_time; + NTTIME write_time; + NTTIME change_time; + uint64_t size; + uint64_t alloc_size; + uint32_t attrib; + uint32_t ea_size; + WIRE_STRING name; + } full_directory_info; + + /* RAW_SEARCH_NAME_INFO interface */ + struct { + uint32_t file_index; + WIRE_STRING name; + } name_info; + + /* RAW_SEARCH_BOTH_DIRECTORY_INFO interface */ + struct { + uint32_t file_index; + NTTIME create_time; + NTTIME access_time; + NTTIME write_time; + NTTIME change_time; + uint64_t size; + uint64_t alloc_size; + uint32_t attrib; + uint32_t ea_size; + WIRE_STRING short_name; + WIRE_STRING name; + } both_directory_info; + + /* RAW_SEARCH_ID_FULL_DIRECTORY_INFO interface */ + struct { + uint32_t file_index; + NTTIME create_time; + NTTIME access_time; + NTTIME write_time; + NTTIME change_time; + uint64_t size; + uint64_t alloc_size; + uint32_t attrib; + uint32_t ea_size; + uint64_t file_id; + WIRE_STRING name; + } id_full_directory_info; + + /* RAW_SEARCH_ID_BOTH_DIRECTORY_INFO interface */ + struct { + uint32_t file_index; + NTTIME create_time; + NTTIME access_time; + NTTIME write_time; + NTTIME change_time; + uint64_t size; + uint64_t alloc_size; + uint32_t attrib; + uint32_t ea_size; + uint64_t file_id; + WIRE_STRING short_name; + WIRE_STRING name; + } id_both_directory_info; + + /* RAW_SEARCH_UNIX_INFO interface */ + struct { + uint32_t file_index; + uint64_t size; + uint64_t alloc_size; + NTTIME status_change_time; + NTTIME access_time; + NTTIME change_time; + uint64_t uid; + uint64_t gid; + uint32_t file_type; + uint64_t dev_major; + uint64_t dev_minor; + uint64_t unique_id; + uint64_t permissions; + uint64_t nlink; + const char *name; + } unix_info; +}; + + +enum smb_search_close_level {RAW_FINDCLOSE_GENERIC, RAW_FINDCLOSE_FCLOSE, RAW_FINDCLOSE_FINDCLOSE}; + +/* union for file search close */ +union smb_search_close { + struct { + enum smb_search_close_level level; + } generic; + + /* SMBfclose (old search) interface */ + struct { + enum smb_search_close_level level; + + struct { + /* max_count and search_attrib are not used, but are present */ + uint16_t max_count; + uint16_t search_attrib; + struct smb_search_id id; + } in; + } fclose; + + /* SMBfindclose interface */ + struct { + enum smb_search_close_level level; + + struct { + uint16_t handle; + } in; + } findclose; +}; + -- cgit From dfc517b05395d925a4d7b1ce9633a849f9468e70 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 23 Feb 2006 15:52:24 +0000 Subject: r13658: More moving around of files: - Collect the generic utility functions into a lib/util/ (a la GLib is for the GNOME folks) - Remove even more files from include/ (This used to be commit ba62880f5b05c2a505dc7f54676b231197a7e707) --- source4/libcli/raw/interfaces.h | 2 - source4/libcli/raw/ioctl.h | 33 +++ source4/libcli/raw/signing.h | 4 + source4/libcli/raw/trans2.h | 435 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 472 insertions(+), 2 deletions(-) create mode 100644 source4/libcli/raw/ioctl.h create mode 100644 source4/libcli/raw/trans2.h (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index 49fe085f2c..034878a464 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -19,8 +19,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - - /* this structure is just a wrapper for a string, the only reason we bother with this is that it allows us to check the length provided on the wire in testsuite test code to ensure that we are diff --git a/source4/libcli/raw/ioctl.h b/source4/libcli/raw/ioctl.h new file mode 100644 index 0000000000..cd658c121b --- /dev/null +++ b/source4/libcli/raw/ioctl.h @@ -0,0 +1,33 @@ +/* + Unix SMB/CIFS implementation. + ioctl and fsctl definitions + + Copyright (C) Andrew Tridgell 2003 + + 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. +*/ + + +/* ioctl codes */ +#define IOCTL_QUERY_JOB_INFO 0x530060 + + +/* filesystem control codes */ +#define FSCTL_FILESYSTEM 0x90000 +#define FSCTL_SET_SPARSE (FSCTL_FILESYSTEM | (49<<2)) +#define FSCTL_REQUEST_BATCH_OPLOCK (FSCTL_FILESYSTEM | (2<<2)) + +#define FSCTL_NAMED_PIPE 0x110000 +#define FSCTL_NAMED_PIPE_READ_WRITE (FSCTL_NAMED_PIPE | 0xc017) diff --git a/source4/libcli/raw/signing.h b/source4/libcli/raw/signing.h index dfc5a4bd7e..cea8556c2c 100644 --- a/source4/libcli/raw/signing.h +++ b/source4/libcli/raw/signing.h @@ -27,6 +27,10 @@ enum smb_signing_engine_state { SMB_SIGNING_ENGINE_ON }; +enum smb_signing_state { + SMB_SIGNING_OFF, SMB_SIGNING_SUPPORTED, + SMB_SIGNING_REQUIRED, SMB_SIGNING_AUTO}; + struct smb_signing_context { enum smb_signing_engine_state signing_state; DATA_BLOB mac_key; diff --git a/source4/libcli/raw/trans2.h b/source4/libcli/raw/trans2.h new file mode 100644 index 0000000000..a3f6e28a2a --- /dev/null +++ b/source4/libcli/raw/trans2.h @@ -0,0 +1,435 @@ +/* + Unix SMB/CIFS implementation. + SMB transaction2 handling + Copyright (C) Jeremy Allison 1994-2002. + Copyright (C) Andrew Tridgell 1995-2003. + + 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. +*/ + +#ifndef _TRANS2_H_ +#define _TRANS2_H_ + +/* These are the TRANS2 sub commands */ +#define TRANSACT2_OPEN 0 +#define TRANSACT2_FINDFIRST 1 +#define TRANSACT2_FINDNEXT 2 +#define TRANSACT2_QFSINFO 3 +#define TRANSACT2_SETFSINFO 4 +#define TRANSACT2_QPATHINFO 5 +#define TRANSACT2_SETPATHINFO 6 +#define TRANSACT2_QFILEINFO 7 +#define TRANSACT2_SETFILEINFO 8 +#define TRANSACT2_FSCTL 9 +#define TRANSACT2_IOCTL 0xA +#define TRANSACT2_FINDNOTIFYFIRST 0xB +#define TRANSACT2_FINDNOTIFYNEXT 0xC +#define TRANSACT2_MKDIR 0xD +#define TRANSACT2_SESSION_SETUP 0xE +#define TRANSACT2_GET_DFS_REFERRAL 0x10 +#define TRANSACT2_REPORT_DFS_INCONSISTANCY 0x11 + + +/* trans2 Query FS info levels */ +/* +w2k3 TRANS2ALIASES: +Checking for QFSINFO aliases + Found level 1 (0x001) of size 18 (0x12) + Found level 2 (0x002) of size 12 (0x0c) + Found level 258 (0x102) of size 26 (0x1a) + Found level 259 (0x103) of size 24 (0x18) + Found level 260 (0x104) of size 8 (0x08) + Found level 261 (0x105) of size 20 (0x14) + Found level 1001 (0x3e9) of size 26 (0x1a) + Found level 1003 (0x3eb) of size 24 (0x18) + Found level 1004 (0x3ec) of size 8 (0x08) + Found level 1005 (0x3ed) of size 20 (0x14) + Found level 1006 (0x3ee) of size 48 (0x30) + Found level 1007 (0x3ef) of size 32 (0x20) + Found level 1008 (0x3f0) of size 64 (0x40) +Found 13 levels with success status + Level 261 (0x105) and level 1005 (0x3ed) are possible aliases + Level 260 (0x104) and level 1004 (0x3ec) are possible aliases + Level 259 (0x103) and level 1003 (0x3eb) are possible aliases + Level 258 (0x102) and level 1001 (0x3e9) are possible aliases +Found 4 aliased levels +*/ +#define SMB_QFS_ALLOCATION 1 +#define SMB_QFS_VOLUME 2 +#define SMB_QFS_VOLUME_INFO 0x102 +#define SMB_QFS_SIZE_INFO 0x103 +#define SMB_QFS_DEVICE_INFO 0x104 +#define SMB_QFS_ATTRIBUTE_INFO 0x105 +#define SMB_QFS_UNIX_INFO 0x200 +#define SMB_QFS_POSIX_INFO 0x201 +#define SMB_QFS_VOLUME_INFORMATION 1001 +#define SMB_QFS_SIZE_INFORMATION 1003 +#define SMB_QFS_DEVICE_INFORMATION 1004 +#define SMB_QFS_ATTRIBUTE_INFORMATION 1005 +#define SMB_QFS_QUOTA_INFORMATION 1006 +#define SMB_QFS_FULL_SIZE_INFORMATION 1007 +#define SMB_QFS_OBJECTID_INFORMATION 1008 + + +/* trans2 qfileinfo/qpathinfo */ +/* w2k3 TRANS2ALIASES: +Checking for QPATHINFO aliases +setting up complex file \qpathinfo_aliases.txt + Found level 1 (0x001) of size 22 (0x16) + Found level 2 (0x002) of size 26 (0x1a) + Found level 4 (0x004) of size 41 (0x29) + Found level 6 (0x006) of size 0 (0x00) + Found level 257 (0x101) of size 40 (0x28) + Found level 258 (0x102) of size 24 (0x18) + Found level 259 (0x103) of size 4 (0x04) + Found level 260 (0x104) of size 48 (0x30) + Found level 263 (0x107) of size 126 (0x7e) + Found level 264 (0x108) of size 28 (0x1c) + Found level 265 (0x109) of size 38 (0x26) + Found level 267 (0x10b) of size 16 (0x10) + Found level 1004 (0x3ec) of size 40 (0x28) + Found level 1005 (0x3ed) of size 24 (0x18) + Found level 1006 (0x3ee) of size 8 (0x08) + Found level 1007 (0x3ef) of size 4 (0x04) + Found level 1008 (0x3f0) of size 4 (0x04) + Found level 1009 (0x3f1) of size 48 (0x30) + Found level 1014 (0x3f6) of size 8 (0x08) + Found level 1016 (0x3f8) of size 4 (0x04) + Found level 1017 (0x3f9) of size 4 (0x04) + Found level 1018 (0x3fa) of size 126 (0x7e) + Found level 1021 (0x3fd) of size 28 (0x1c) + Found level 1022 (0x3fe) of size 38 (0x26) + Found level 1028 (0x404) of size 16 (0x10) + Found level 1034 (0x40a) of size 56 (0x38) + Found level 1035 (0x40b) of size 8 (0x08) +Found 27 levels with success status + Level 267 (0x10b) and level 1028 (0x404) are possible aliases + Level 265 (0x109) and level 1022 (0x3fe) are possible aliases + Level 264 (0x108) and level 1021 (0x3fd) are possible aliases + Level 263 (0x107) and level 1018 (0x3fa) are possible aliases + Level 260 (0x104) and level 1009 (0x3f1) are possible aliases + Level 259 (0x103) and level 1007 (0x3ef) are possible aliases + Level 258 (0x102) and level 1005 (0x3ed) are possible aliases + Level 257 (0x101) and level 1004 (0x3ec) are possible aliases +Found 8 aliased levels +*/ +#define SMB_QFILEINFO_STANDARD 1 +#define SMB_QFILEINFO_EA_SIZE 2 +#define SMB_QFILEINFO_EA_LIST 3 +#define SMB_QFILEINFO_ALL_EAS 4 +#define SMB_QFILEINFO_IS_NAME_VALID 6 /* only for QPATHINFO */ +#define SMB_QFILEINFO_BASIC_INFO 0x101 +#define SMB_QFILEINFO_STANDARD_INFO 0x102 +#define SMB_QFILEINFO_EA_INFO 0x103 +#define SMB_QFILEINFO_NAME_INFO 0x104 +#define SMB_QFILEINFO_ALL_INFO 0x107 +#define SMB_QFILEINFO_ALT_NAME_INFO 0x108 +#define SMB_QFILEINFO_STREAM_INFO 0x109 +#define SMB_QFILEINFO_COMPRESSION_INFO 0x10b +#define SMB_QFILEINFO_UNIX_BASIC 0x200 +#define SMB_QFILEINFO_UNIX_LINK 0x201 +#define SMB_QFILEINFO_BASIC_INFORMATION 1004 +#define SMB_QFILEINFO_STANDARD_INFORMATION 1005 +#define SMB_QFILEINFO_INTERNAL_INFORMATION 1006 +#define SMB_QFILEINFO_EA_INFORMATION 1007 +#define SMB_QFILEINFO_ACCESS_INFORMATION 1008 +#define SMB_QFILEINFO_NAME_INFORMATION 1009 +#define SMB_QFILEINFO_POSITION_INFORMATION 1014 +#define SMB_QFILEINFO_MODE_INFORMATION 1016 +#define SMB_QFILEINFO_ALIGNMENT_INFORMATION 1017 +#define SMB_QFILEINFO_ALL_INFORMATION 1018 +#define SMB_QFILEINFO_ALT_NAME_INFORMATION 1021 +#define SMB_QFILEINFO_STREAM_INFORMATION 1022 +#define SMB_QFILEINFO_COMPRESSION_INFORMATION 1028 +#define SMB_QFILEINFO_NETWORK_OPEN_INFORMATION 1034 +#define SMB_QFILEINFO_ATTRIBUTE_TAG_INFORMATION 1035 + + + +/* trans2 setfileinfo/setpathinfo levels */ +/* +w2k3 TRANS2ALIASES +Checking for SETFILEINFO aliases +setting up complex file \setfileinfo_aliases.txt + Found level 1 (0x001) of size 2 (0x02) + Found level 2 (0x002) of size 2 (0x02) + Found level 257 (0x101) of size 40 (0x28) + Found level 258 (0x102) of size 2 (0x02) + Found level 259 (0x103) of size 8 (0x08) + Found level 260 (0x104) of size 8 (0x08) + Found level 1004 (0x3ec) of size 40 (0x28) + Found level 1010 (0x3f2) of size 2 (0x02) + Found level 1013 (0x3f5) of size 2 (0x02) + Found level 1014 (0x3f6) of size 8 (0x08) + Found level 1016 (0x3f8) of size 4 (0x04) + Found level 1019 (0x3fb) of size 8 (0x08) + Found level 1020 (0x3fc) of size 8 (0x08) + Found level 1023 (0x3ff) of size 8 (0x08) + Found level 1025 (0x401) of size 16 (0x10) + Found level 1029 (0x405) of size 72 (0x48) + Found level 1032 (0x408) of size 56 (0x38) + Found level 1039 (0x40f) of size 8 (0x08) + Found level 1040 (0x410) of size 8 (0x08) +Found 19 valid levels + +Checking for SETPATHINFO aliases + Found level 1004 (0x3ec) of size 40 (0x28) + Found level 1010 (0x3f2) of size 2 (0x02) + Found level 1013 (0x3f5) of size 2 (0x02) + Found level 1014 (0x3f6) of size 8 (0x08) + Found level 1016 (0x3f8) of size 4 (0x04) + Found level 1019 (0x3fb) of size 8 (0x08) + Found level 1020 (0x3fc) of size 8 (0x08) + Found level 1023 (0x3ff) of size 8 (0x08) + Found level 1025 (0x401) of size 16 (0x10) + Found level 1029 (0x405) of size 72 (0x48) + Found level 1032 (0x408) of size 56 (0x38) + Found level 1039 (0x40f) of size 8 (0x08) + Found level 1040 (0x410) of size 8 (0x08) +Found 13 valid levels +*/ +#define SMB_SFILEINFO_STANDARD 1 +#define SMB_SFILEINFO_EA_SET 2 +#define SMB_SFILEINFO_BASIC_INFO 0x101 +#define SMB_SFILEINFO_DISPOSITION_INFO 0x102 +#define SMB_SFILEINFO_ALLOCATION_INFO 0x103 +#define SMB_SFILEINFO_END_OF_FILE_INFO 0x104 +#define SMB_SFILEINFO_UNIX_BASIC 0x200 +#define SMB_SFILEINFO_UNIX_LINK 0x201 +#define SMB_SPATHINFO_UNIX_HLINK 0x203 +#define SMB_SPATHINFO_POSIX_ACL 0x204 +#define SMB_SPATHINFO_XATTR 0x205 +#define SMB_SFILEINFO_ATTR_FLAGS 0x206 +#define SMB_SFILEINFO_BASIC_INFORMATION 1004 +#define SMB_SFILEINFO_RENAME_INFORMATION 1010 +#define SMB_SFILEINFO_DISPOSITION_INFORMATION 1013 +#define SMB_SFILEINFO_POSITION_INFORMATION 1014 +#define SMB_SFILEINFO_MODE_INFORMATION 1016 +#define SMB_SFILEINFO_ALLOCATION_INFORMATION 1019 +#define SMB_SFILEINFO_END_OF_FILE_INFORMATION 1020 + +/* filemon shows FilePipeInformation */ +#define SMB_SFILEINFO_1023 1023 + +/* filemon shows FilePipeRemoteInformation */ +#define SMB_SFILEINFO_1025 1025 + +/* filemon shows CopyOnWriteInformation */ +#define SMB_SFILEINFO_1029 1029 + +/* filemon shows OleClassIdInformation */ +#define SMB_SFILEINFO_1032 1032 + +/* seems to be the file size - perhaps valid data size? + filemon shows 'InheritContentIndexInfo' +*/ +#define SMB_SFILEINFO_1039 1039 + +/* OLE_INFORMATION? */ +#define SMB_SFILEINFO_1040 1040 + + +/* trans2 findfirst levels */ +/* +w2k3 TRANS2ALIASES: +Checking for FINDFIRST aliases + Found level 1 (0x001) of size 68 (0x44) + Found level 2 (0x002) of size 70 (0x46) + Found level 257 (0x101) of size 108 (0x6c) + Found level 258 (0x102) of size 116 (0x74) + Found level 259 (0x103) of size 60 (0x3c) + Found level 260 (0x104) of size 140 (0x8c) + Found level 261 (0x105) of size 124 (0x7c) + Found level 262 (0x106) of size 148 (0x94) +Found 8 levels with success status +Found 0 aliased levels +*/ +#define SMB_FIND_STANDARD 1 +#define SMB_FIND_EA_SIZE 2 +#define SMB_FIND_EA_LIST 3 +#define SMB_FIND_DIRECTORY_INFO 0x101 +#define SMB_FIND_FULL_DIRECTORY_INFO 0x102 +#define SMB_FIND_NAME_INFO 0x103 +#define SMB_FIND_BOTH_DIRECTORY_INFO 0x104 +#define SMB_FIND_ID_FULL_DIRECTORY_INFO 0x105 +#define SMB_FIND_ID_BOTH_DIRECTORY_INFO 0x106 +#define SMB_FIND_UNIX_INFO 0x202 + +/* flags on trans2 findfirst/findnext that control search */ +#define FLAG_TRANS2_FIND_CLOSE 0x1 +#define FLAG_TRANS2_FIND_CLOSE_IF_END 0x2 +#define FLAG_TRANS2_FIND_REQUIRE_RESUME 0x4 +#define FLAG_TRANS2_FIND_CONTINUE 0x8 +#define FLAG_TRANS2_FIND_BACKUP_INTENT 0x10 + +/* + * DeviceType and Characteristics returned in a + * SMB_QFS_DEVICE_INFO call. + */ +#define QFS_DEVICETYPE_CD_ROM 0x2 +#define QFS_DEVICETYPE_CD_ROM_FILE_SYSTEM 0x3 +#define QFS_DEVICETYPE_DISK 0x7 +#define QFS_DEVICETYPE_DISK_FILE_SYSTEM 0x8 +#define QFS_DEVICETYPE_FILE_SYSTEM 0x9 + +/* Characteristics. */ +#define QFS_TYPE_REMOVABLE_MEDIA 0x1 +#define QFS_TYPE_READ_ONLY_DEVICE 0x2 +#define QFS_TYPE_FLOPPY 0x4 +#define QFS_TYPE_WORM 0x8 +#define QFS_TYPE_REMOTE 0x10 +#define QFS_TYPE_MOUNTED 0x20 +#define QFS_TYPE_VIRTUAL 0x40 + + +/* + * Thursby MAC extensions.... + */ + +/* + * MAC CIFS Extensions have the range 0x300 - 0x2FF reserved. + * Supposedly Microsoft have agreed to this. + */ + +#define MIN_MAC_INFO_LEVEL 0x300 +#define MAX_MAC_INFO_LEVEL 0x3FF +#define SMB_QFS_MAC_FS_INFO 0x301 + + + +/* UNIX CIFS Extensions - created by HP */ +/* + * UNIX CIFS Extensions have the range 0x200 - 0x2FF reserved. + * Supposedly Microsoft have agreed to this. + */ + +#define MIN_UNIX_INFO_LEVEL 0x200 +#define MAX_UNIX_INFO_LEVEL 0x2FF + +#define INFO_LEVEL_IS_UNIX(level) (((level) >= MIN_UNIX_INFO_LEVEL) && ((level) <= MAX_UNIX_INFO_LEVEL)) + +#define SMB_QFILEINFO_UNIX_BASIC 0x200 /* UNIX File Info*/ +#define SMB_SFILEINFO_UNIX_BASIC 0x200 + +#define SMB_MODE_NO_CHANGE 0xFFFFFFFF /* file mode value which */ + /* means "don't change it" */ +#define SMB_UID_NO_CHANGE 0xFFFFFFFF +#define SMB_GID_NO_CHANGE 0xFFFFFFFF + +#define SMB_SIZE_NO_CHANGE_LO 0xFFFFFFFF +#define SMB_SIZE_NO_CHANGE_HI 0xFFFFFFFF + +#define SMB_TIME_NO_CHANGE_LO 0xFFFFFFFF +#define SMB_TIME_NO_CHANGE_HI 0xFFFFFFFF + +/* +Offset Size Name +0 LARGE_INTEGER EndOfFile File size +8 LARGE_INTEGER Blocks Number of bytes used on disk (st_blocks). +16 LARGE_INTEGER CreationTime Creation time +24 LARGE_INTEGER LastAccessTime Last access time +32 LARGE_INTEGER LastModificationTime Last modification time +40 LARGE_INTEGER Uid Numeric user id for the owner +48 LARGE_INTEGER Gid Numeric group id of owner +56 ULONG Type Enumeration specifying the pathname type: + 0 -- File + 1 -- Directory + 2 -- Symbolic link + 3 -- Character device + 4 -- Block device + 5 -- FIFO (named pipe) + 6 -- Unix domain socket + +60 LARGE_INTEGER devmajor Major device number if type is device +68 LARGE_INTEGER devminor Minor device number if type is device +76 LARGE_INTEGER uniqueid This is a server-assigned unique id for the file. The client + will typically map this onto an inode number. The scope of + uniqueness is the share. +84 LARGE_INTEGER permissions Standard UNIX file permissions - see below. +92 LARGE_INTEGER nlinks The number of directory entries that map to this entry + (number of hard links) + +100 - end. +*/ + +/* UNIX filetype mappings. */ + +#define UNIX_TYPE_FILE 0 +#define UNIX_TYPE_DIR 1 +#define UNIX_TYPE_SYMLINK 2 +#define UNIX_TYPE_CHARDEV 3 +#define UNIX_TYPE_BLKDEV 4 +#define UNIX_TYPE_FIFO 5 +#define UNIX_TYPE_SOCKET 6 +#define UNIX_TYPE_UNKNOWN 0xFFFFFFFF + +/* + * Oh this is fun. "Standard UNIX permissions" has no + * meaning in POSIX. We need to define the mapping onto + * and off the wire as this was not done in the original HP + * spec. JRA. + */ + +#define UNIX_X_OTH 0000001 +#define UNIX_W_OTH 0000002 +#define UNIX_R_OTH 0000004 +#define UNIX_X_GRP 0000010 +#define UNIX_W_GRP 0000020 +#define UNIX_R_GRP 0000040 +#define UNIX_X_USR 0000100 +#define UNIX_W_USR 0000200 +#define UNIX_R_USR 0000400 +#define UNIX_STICKY 0001000 +#define UNIX_SET_GID 0002000 +#define UNIX_SET_UID 0004000 + +/* Masks for the above */ +#define UNIX_OTH_MASK 0000007 +#define UNIX_GRP_MASK 0000070 +#define UNIX_USR_MASK 0000700 +#define UNIX_PERM_MASK 0000777 +#define UNIX_EXTRA_MASK 0007000 +#define UNIX_ALL_MASK 0007777 + +#define SMB_QFILEINFO_UNIX_LINK 0x201 +#define SMB_SFILEINFO_UNIX_LINK 0x201 +#define SMB_SFILEINFO_UNIX_HLINK 0x203 + +#define SMB_FIND_FILE_UNIX 0x202 + +/* + Info level for QVOLINFO - returns version of CIFS UNIX extensions, plus + 64-bits worth of capability fun :-). +*/ + +#define SMB_QUERY_CIFS_UNIX_INFO 0x200 + +/* Returns the following. + + UINT16 major version number + UINT16 minor version number + LARGE_INTEGER capability bitfield + +*/ + +#define CIFS_UNIX_MAJOR_VERSION 1 +#define CIFS_UNIX_MINOR_VERSION 0 + +#define CIFS_UNIX_FCNTL_LOCKS_CAP 0x1 +#define CIFS_UNIX_POSIX_ACLS_CAP 0x2 + +/* ... more as we think of them :-). */ + +#endif -- cgit From 4ac2be99588b48b0652a524bf12fb1aa9c3f5fbb Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 7 Mar 2006 11:07:23 +0000 Subject: r13924: Split more prototypes out of include/proto.h + initial work on header file dependencies (This used to be commit 122835876748a3eaf5e8d31ad1abddab9acb8781) --- source4/libcli/raw/clisocket.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 40d9d2784a..4b1d70d8d2 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -26,6 +26,7 @@ #include "libcli/raw/libcliraw.h" #include "libcli/composite/composite.h" #include "lib/socket/socket.h" +#include "libcli/resolve/resolve.h" struct sock_connect_state { struct composite_context *ctx; -- cgit From 2d7353dea47f849ce6f18ecb6f896676f0a167df Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 10 Mar 2006 11:47:03 +0000 Subject: r14141: fixed bugzilla 2921, forcing correct alignment when in ascii mode (This used to be commit f432d23b044355ae5214812e3794ab319b01268f) --- source4/libcli/raw/rawfile.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c index 0cc7385cee..2eacd1d22e 100644 --- a/source4/libcli/raw/rawfile.c +++ b/source4/libcli/raw/rawfile.c @@ -297,7 +297,7 @@ static struct smbcli_request *smb_raw_nttrans_create_send(struct smbcli_tree *tr parms->ntcreatex.in.ea_list->eas); } - nt.in.params = data_blob_talloc(mem_ctx, NULL, 54); + nt.in.params = data_blob_talloc(mem_ctx, NULL, 53); if (nt.in.params.data == NULL) { talloc_free(mem_ctx); return NULL; @@ -319,7 +319,9 @@ static struct smbcli_request *smb_raw_nttrans_create_send(struct smbcli_tree *tr SIVAL(params, 48, parms->ntcreatex.in.impersonation); SCVAL(params, 52, parms->ntcreatex.in.security_flags); SCVAL(params, 53, 0); - + + /* the empty string first forces the correct alignment */ + smbcli_blob_append_string(tree->session, mem_ctx, &nt.in.params,"", 0); fname_len = smbcli_blob_append_string(tree->session, mem_ctx, &nt.in.params, parms->ntcreatex.in.fname, STR_TERMINATE); -- cgit From 3d9fc634ef8164a34adf14c0f77473c6268d2538 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 10 Mar 2006 15:10:47 +0000 Subject: r14160: don't write behind the buffer metze (This used to be commit bce4db8d1c293d05546dfd1b0229252babdb64b2) --- source4/libcli/raw/rawfile.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c index 2eacd1d22e..9d2611f7b2 100644 --- a/source4/libcli/raw/rawfile.c +++ b/source4/libcli/raw/rawfile.c @@ -318,7 +318,6 @@ static struct smbcli_request *smb_raw_nttrans_create_send(struct smbcli_tree *tr SIVAL(params, 40, ea_blob.length); SIVAL(params, 48, parms->ntcreatex.in.impersonation); SCVAL(params, 52, parms->ntcreatex.in.security_flags); - SCVAL(params, 53, 0); /* the empty string first forces the correct alignment */ smbcli_blob_append_string(tree->session, mem_ctx, &nt.in.params,"", 0); -- cgit From 307e43bb5628e8b53a930c2928279af994281ba5 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 10 Mar 2006 20:49:20 +0000 Subject: r14173: change smb interface structures to always use a union smb_file, to abtract - const char *path fot qpathinfo and setpathinfo - uint16_t fnum for SMB - smb2_handle handle for SMB2 the idea is to later add a struct ntvfs_handle *ntvfs so that the ntvfs subsystem don't need to know the difference between SMB and SMB2 metze (This used to be commit 2ef3f5970901b5accdb50f0d0115b5d46b0c788f) --- source4/libcli/raw/interfaces.h | 280 +++++++++++++++++++------------------- source4/libcli/raw/rawacl.c | 4 +- source4/libcli/raw/rawfile.c | 67 +++++---- source4/libcli/raw/rawfileinfo.c | 8 +- source4/libcli/raw/rawioctl.c | 4 +- source4/libcli/raw/rawnotify.c | 28 ++-- source4/libcli/raw/rawreadwrite.c | 18 +-- 7 files changed, 205 insertions(+), 204 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index 034878a464..0505078fd4 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -56,6 +56,29 @@ typedef struct { /* same struct as dom_sid but inside a 28 bytes fixed buffer in NDR */ #define dom_sid28 dom_sid +/* + a generic container for file handles +*/ +union smb_file { + /* + * this is only used for + * the qpathinfo and setpathinfo + * calls + */ + const char *path; + + /* + * this is used as file handle in SMB + */ + uint16_t fnum; + + /* + * this is used as file handle in SMB2 + */ + struct smb2_handle { + uint64_t data[2]; + } handle; +}; /* this header defines the structures and unions used between the SMB @@ -63,32 +86,37 @@ typedef struct { */ /* struct used for SMBlseek call */ -struct smb_seek { - struct { - uint16_t fnum; - uint16_t mode; - int32_t offset; /* signed */ - } in; +union smb_seek { struct { - int32_t offset; - } out; + union smb_file file; + struct { + uint16_t mode; + int32_t offset; /* signed */ + } in; + struct { + int32_t offset; + } out; + } lseek; }; - /* struct used in unlink() call */ -struct smb_unlink { +union smb_unlink { struct { - const char *pattern; - uint16_t attrib; - } in; + struct { + const char *pattern; + uint16_t attrib; + } in; + } unlink; }; /* struct used in chkpath() call */ -struct smb_chkpath { +union smb_chkpath { struct { - const char *path; - } in; + struct { + const char *path; + } in; + } chkpath; }; enum smb_mkdir_level {RAW_MKDIR_GENERIC, RAW_MKDIR_MKDIR, RAW_MKDIR_T2MKDIR}; @@ -326,32 +354,14 @@ enum smb_fileinfo_level { RAW_FILEINFO_SMB2_ALL_INFORMATION = 0x1201 }; -/* - file handles in SMB2 are 16 bytes -*/ -struct smb2_handle { - uint64_t data[2]; -}; - - /* union used in qfileinfo() and qpathinfo() backend calls */ union smb_fileinfo { /* generic interface: * matches RAW_FILEINFO_GENERIC */ struct { enum smb_fileinfo_level level; + union smb_file file; - /* each level can be called on either a pathname or a - filename, in either case the return format is - identical - On SMB2 a 16 byte handle is used - */ - union smb_fileinfo_in { - const char *fname; - uint16_t fnum; - struct smb2_handle handle; - } in; - struct { uint32_t attrib; uint32_t ea_size; @@ -397,7 +407,7 @@ union smb_fileinfo { * matches RAW_FILEINFO_GETATTR */ struct { enum smb_fileinfo_level level; - union smb_fileinfo_in in; + union smb_file file; struct { uint16_t attrib; @@ -409,7 +419,7 @@ union smb_fileinfo { /* SMBgetattrE and RAW_FILEINFO_STANDARD interface */ struct { enum smb_fileinfo_level level; - union smb_fileinfo_in in; + union smb_file file; struct { time_t create_time; @@ -424,7 +434,7 @@ union smb_fileinfo { /* trans2 RAW_FILEINFO_EA_SIZE interface */ struct { enum smb_fileinfo_level level; - union smb_fileinfo_in in; + union smb_file file; struct { time_t create_time; @@ -440,7 +450,7 @@ union smb_fileinfo { /* trans2 RAW_FILEINFO_EA_LIST interface */ struct { enum smb_fileinfo_level level; - union smb_fileinfo_in file; + union smb_file file; struct { uint_t num_names; @@ -458,9 +468,11 @@ union smb_fileinfo { /* trans2 RAW_FILEINFO_ALL_EAS and RAW_FILEINFO_FULL_EA_INFORMATION interfaces */ struct { enum smb_fileinfo_level level; - union smb_fileinfo_in in; - uint8_t continue_flags; /* SMB2 only - SMB2_CONTINUE_FLAG_* */ - + union smb_file file; + struct { + /* SMB2 only - SMB2_CONTINUE_FLAG_* */ + uint8_t continue_flags; + } in; struct smb_ea_list out; } all_eas; @@ -468,13 +480,13 @@ union smb_fileinfo { only valid for a QPATHNAME call - no returned data */ struct { enum smb_fileinfo_level level; - union smb_fileinfo_in in; + union smb_file file; } is_name_valid; /* RAW_FILEINFO_BASIC_INFO and RAW_FILEINFO_BASIC_INFORMATION interfaces */ struct { enum smb_fileinfo_level level; - union smb_fileinfo_in in; + union smb_file file; struct { NTTIME create_time; @@ -489,7 +501,7 @@ union smb_fileinfo { /* RAW_FILEINFO_STANDARD_INFO and RAW_FILEINFO_STANDARD_INFORMATION interfaces */ struct { enum smb_fileinfo_level level; - union smb_fileinfo_in in; + union smb_file file; struct { uint64_t alloc_size; @@ -503,7 +515,7 @@ union smb_fileinfo { /* RAW_FILEINFO_EA_INFO and RAW_FILEINFO_EA_INFORMATION interfaces */ struct { enum smb_fileinfo_level level; - union smb_fileinfo_in in; + union smb_file file; struct { uint32_t ea_size; @@ -513,7 +525,7 @@ union smb_fileinfo { /* RAW_FILEINFO_NAME_INFO and RAW_FILEINFO_NAME_INFORMATION interfaces */ struct { enum smb_fileinfo_level level; - union smb_fileinfo_in in; + union smb_file file; struct { WIRE_STRING fname; @@ -523,7 +535,7 @@ union smb_fileinfo { /* RAW_FILEINFO_ALL_INFO and RAW_FILEINFO_ALL_INFORMATION interfaces */ struct { enum smb_fileinfo_level level; - union smb_fileinfo_in in; + union smb_file file; struct { NTTIME create_time; @@ -544,7 +556,7 @@ union smb_fileinfo { /* RAW_FILEINFO_SMB2_ALL_INFORMATION interface */ struct { enum smb_fileinfo_level level; - union smb_fileinfo_in in; + union smb_file file; struct { NTTIME create_time; @@ -571,7 +583,7 @@ union smb_fileinfo { /* RAW_FILEINFO_ALT_NAME_INFO and RAW_FILEINFO_ALT_NAME_INFORMATION interfaces */ struct { enum smb_fileinfo_level level; - union smb_fileinfo_in in; + union smb_file file; struct { WIRE_STRING fname; @@ -581,7 +593,7 @@ union smb_fileinfo { /* RAW_FILEINFO_STREAM_INFO and RAW_FILEINFO_STREAM_INFORMATION interfaces */ struct { enum smb_fileinfo_level level; - union smb_fileinfo_in in; + union smb_file file; struct stream_information { uint_t num_streams; @@ -592,7 +604,7 @@ union smb_fileinfo { /* RAW_FILEINFO_COMPRESSION_INFO and RAW_FILEINFO_COMPRESSION_INFORMATION interfaces */ struct { enum smb_fileinfo_level level; - union smb_fileinfo_in in; + union smb_file file; struct { uint64_t compressed_size; @@ -606,7 +618,7 @@ union smb_fileinfo { /* RAW_FILEINFO_UNIX_BASIC interface */ struct { enum smb_fileinfo_level level; - union smb_fileinfo_in in; + union smb_file file; struct { uint64_t end_of_file; @@ -628,7 +640,7 @@ union smb_fileinfo { /* RAW_FILEINFO_UNIX_LINK interface */ struct { enum smb_fileinfo_level level; - union smb_fileinfo_in in; + union smb_file file; struct { WIRE_STRING link_dest; @@ -638,7 +650,7 @@ union smb_fileinfo { /* RAW_FILEINFO_INTERNAL_INFORMATION interface */ struct { enum smb_fileinfo_level level; - union smb_fileinfo_in in; + union smb_file file; struct { uint64_t file_id; @@ -648,7 +660,7 @@ union smb_fileinfo { /* RAW_FILEINFO_ACCESS_INFORMATION interface */ struct { enum smb_fileinfo_level level; - union smb_fileinfo_in in; + union smb_file file; struct { uint32_t access_flags; @@ -658,7 +670,7 @@ union smb_fileinfo { /* RAW_FILEINFO_POSITION_INFORMATION interface */ struct { enum smb_fileinfo_level level; - union smb_fileinfo_in in; + union smb_file file; struct { uint64_t position; @@ -668,7 +680,7 @@ union smb_fileinfo { /* RAW_FILEINFO_MODE_INFORMATION interface */ struct { enum smb_fileinfo_level level; - union smb_fileinfo_in in; + union smb_file file; struct { uint32_t mode; @@ -678,7 +690,7 @@ union smb_fileinfo { /* RAW_FILEINFO_ALIGNMENT_INFORMATION interface */ struct { enum smb_fileinfo_level level; - union smb_fileinfo_in in; + union smb_file file; struct { uint32_t alignment_requirement; @@ -688,7 +700,7 @@ union smb_fileinfo { /* RAW_FILEINFO_NETWORK_OPEN_INFORMATION interface */ struct { enum smb_fileinfo_level level; - union smb_fileinfo_in in; + union smb_file file; struct { NTTIME create_time; @@ -705,7 +717,7 @@ union smb_fileinfo { /* RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION interface */ struct { enum smb_fileinfo_level level; - union smb_fileinfo_in in; + union smb_file file; struct { uint32_t attrib; @@ -716,8 +728,10 @@ union smb_fileinfo { /* RAW_FILEINFO_SEC_DESC */ struct { enum smb_fileinfo_level level; - union smb_fileinfo_in in; - uint32_t secinfo_flags; + union smb_file file; + struct { + uint32_t secinfo_flags; + } in; struct { struct security_descriptor *sd; } out; @@ -760,19 +774,13 @@ union smb_setfileinfo { struct { enum smb_setfileinfo_level level; - /* we are combining setfileinfo and setpathinfo into one - interface */ - union setfileinfo_file { - const char *fname; - uint16_t fnum; - struct smb2_handle handle; /* only for SMB2 */ - } file; + union smb_file file; } generic; /* RAW_SFILEINFO_SETATTR (SMBsetatr) interface - only via setpathinfo() */ struct { enum smb_setfileinfo_level level; - union setfileinfo_file file; + union smb_file file; struct { uint16_t attrib; time_t write_time; @@ -783,8 +791,7 @@ union smb_setfileinfo { also RAW_SFILEINFO_STANDARD */ struct { enum smb_setfileinfo_level level; - union setfileinfo_file file; - + union smb_file file; struct { time_t create_time; time_t access_time; @@ -797,7 +804,7 @@ union smb_setfileinfo { /* RAW_SFILEINFO_EA_SET interface */ struct { enum smb_setfileinfo_level level; - union setfileinfo_file file; + union smb_file file; struct { uint_t num_eas; struct ea_struct *eas; @@ -808,8 +815,7 @@ union smb_setfileinfo { RAW_SFILEINFO_BASIC_INFORMATION interfaces */ struct { enum smb_setfileinfo_level level; - union setfileinfo_file file; - + union smb_file file; struct { NTTIME create_time; NTTIME access_time; @@ -823,8 +829,7 @@ union smb_setfileinfo { RAW_SFILEINFO_DISPOSITION_INFORMATION interfaces */ struct { enum smb_setfileinfo_level level; - union setfileinfo_file file; - + union smb_file file; struct { BOOL delete_on_close; } in; @@ -834,8 +839,7 @@ union smb_setfileinfo { RAW_SFILEINFO_ALLOCATION_INFORMATION interfaces */ struct { enum smb_setfileinfo_level level; - union setfileinfo_file file; - + union smb_file file; struct { /* w2k3 rounds this up to nearest 4096 */ uint64_t alloc_size; @@ -846,8 +850,7 @@ union smb_setfileinfo { RAW_SFILEINFO_END_OF_FILE_INFORMATION interfaces */ struct { enum smb_setfileinfo_level level; - union setfileinfo_file file; - + union smb_file file; struct { uint64_t size; } in; @@ -856,8 +859,7 @@ union smb_setfileinfo { /* RAW_SFILEINFO_RENAME_INFORMATION interface */ struct { enum smb_setfileinfo_level level; - union setfileinfo_file file; - + union smb_file file; struct smb_rename_information { uint8_t overwrite; uint32_t root_fid; @@ -868,8 +870,7 @@ union smb_setfileinfo { /* RAW_SFILEINFO_POSITION_INFORMATION interface */ struct { enum smb_setfileinfo_level level; - union setfileinfo_file file; - + union smb_file file; struct { uint64_t position; } in; @@ -878,8 +879,7 @@ union smb_setfileinfo { /* RAW_SFILEINFO_MODE_INFORMATION interface */ struct { enum smb_setfileinfo_level level; - union setfileinfo_file file; - + union smb_file file; struct { /* valid values seem to be 0, 2, 4 and 6 */ uint32_t mode; @@ -891,7 +891,7 @@ union smb_setfileinfo { /* RAW_SFILEINFO_UNIX_BASIC interface */ struct { enum smb_setfileinfo_level level; - union setfileinfo_file file; + union smb_file file; struct { uint32_t mode; /* yuck - this field remains to fix compile of libcli/clifile.c */ uint64_t end_of_file; @@ -913,7 +913,7 @@ union smb_setfileinfo { /* RAW_SFILEINFO_UNIX_LINK, RAW_SFILEINFO_UNIX_HLINK interface */ struct { enum smb_setfileinfo_level level; - union setfileinfo_file file; + union smb_file file; struct { const char *link_dest; } in; @@ -922,7 +922,7 @@ union smb_setfileinfo { /* RAW_FILEINFO_SET_SEC_DESC */ struct { enum smb_setfileinfo_level level; - union setfileinfo_file file; + union smb_file file; struct { uint32_t secinfo_flags; struct security_descriptor *sd; @@ -1131,6 +1131,8 @@ union smb_open { /* SMBNTCreateX interface */ struct { enum smb_open_level level; + /* this is the output file handle */ + union smb_file file; struct { uint32_t flags; @@ -1156,7 +1158,6 @@ union smb_open { struct { uint8_t oplock_level; - uint16_t fnum; uint32_t create_action; NTTIME create_time; NTTIME access_time; @@ -1174,6 +1175,8 @@ union smb_open { /* TRANS2_OPEN interface */ struct { enum smb_open_level level; + /* this is the output file handle */ + union smb_file file; struct { uint16_t flags; @@ -1190,7 +1193,6 @@ union smb_open { } in; struct { - uint16_t fnum; uint16_t attrib; time_t write_time; uint32_t size; @@ -1205,14 +1207,16 @@ union smb_open { /* SMBopen interface */ struct { enum smb_open_level level; + /* this is the output file handle */ + union smb_file file; struct { uint16_t open_mode; uint16_t search_attrs; const char *fname; } in; + struct { - uint16_t fnum; uint16_t attrib; time_t write_time; uint32_t size; @@ -1223,6 +1227,8 @@ union smb_open { /* SMBopenX interface */ struct { enum smb_open_level level; + /* this is the output file handle */ + union smb_file file; struct { uint16_t flags; @@ -1238,7 +1244,6 @@ union smb_open { const char *fname; } in; struct { - uint16_t fnum; uint16_t attrib; time_t write_time; uint32_t size; @@ -1255,20 +1260,21 @@ union smb_open { /* SMBmknew interface */ struct { enum smb_open_level level; + /* this is the output file handle */ + union smb_file file; struct { uint16_t attrib; time_t write_time; const char *fname; } in; - struct { - uint16_t fnum; - } out; } mknew, create; /* SMBctemp interface */ struct { enum smb_open_level level; + /* this is the output file handle */ + union smb_file file; struct { uint16_t attrib; @@ -1276,7 +1282,6 @@ union smb_open { const char *directory; } in; struct { - uint16_t fnum; /* temp name, relative to directory */ char *name; } out; @@ -1285,21 +1290,22 @@ union smb_open { /* SMBsplopen interface */ struct { enum smb_open_level level; + /* this is the output file handle */ + union smb_file file; struct { uint16_t setup_length; uint16_t mode; const char *ident; } in; - struct { - uint16_t fnum; - } out; } splopen; /* chained OpenX/ReadX interface */ struct { enum smb_open_level level; + /* this is the output file handle */ + union smb_file file; struct { uint16_t flags; @@ -1321,7 +1327,6 @@ union smb_open { uint16_t remaining; } in; struct { - uint16_t fnum; uint16_t attrib; time_t write_time; uint32_t size; @@ -1357,9 +1362,9 @@ union smb_read { /* SMBreadX (and generic) interface */ struct { enum smb_read_level level; + union smb_file file; struct { - uint16_t fnum; uint64_t offset; uint16_t mincnt; uint32_t maxcnt; @@ -1376,9 +1381,9 @@ union smb_read { /* SMBreadbraw interface */ struct { enum smb_read_level level; + union smb_file file; struct { - uint16_t fnum; uint64_t offset; uint16_t maxcnt; uint16_t mincnt; @@ -1394,9 +1399,9 @@ union smb_read { /* SMBlockandread interface */ struct { enum smb_read_level level; + union smb_file file; struct { - uint16_t fnum; uint16_t count; uint32_t offset; uint16_t remaining; @@ -1410,9 +1415,9 @@ union smb_read { /* SMBread interface */ struct { enum smb_read_level level; + union smb_file file; struct { - uint16_t fnum; uint16_t count; uint32_t offset; uint16_t remaining; @@ -1437,9 +1442,9 @@ union smb_write { /* SMBwriteX interface */ struct { enum smb_write_level level; + union smb_file file; struct { - uint16_t fnum; uint64_t offset; uint16_t wmode; uint16_t remaining; @@ -1455,9 +1460,9 @@ union smb_write { /* SMBwriteunlock interface */ struct { enum smb_write_level level; + union smb_file file; struct { - uint16_t fnum; uint16_t count; uint32_t offset; uint16_t remaining; @@ -1471,9 +1476,9 @@ union smb_write { /* SMBwrite interface */ struct { enum smb_write_level level; + union smb_file file; struct { - uint16_t fnum; uint16_t count; uint32_t offset; uint16_t remaining; @@ -1487,9 +1492,9 @@ union smb_write { /* SMBwriteclose interface */ struct { enum smb_write_level level; + union smb_file file; struct { - uint16_t fnum; uint16_t count; uint32_t offset; time_t mtime; @@ -1503,9 +1508,9 @@ union smb_write { /* SMBsplwrite interface */ struct { enum smb_write_level level; + union smb_file file; struct { - uint16_t fnum; uint16_t count; const uint8_t *data; } in; @@ -1524,9 +1529,9 @@ union smb_lock { /* SMBlockingX (and generic) interface */ struct { enum smb_lock_level level; + union smb_file file; struct { - uint16_t fnum; uint16_t mode; uint32_t timeout; uint16_t ulock_cnt; @@ -1542,9 +1547,9 @@ union smb_lock { /* SMBlock and SMBunlock interface */ struct { enum smb_lock_level level; + union smb_file file; struct { - uint16_t fnum; uint32_t count; uint32_t offset; } in; @@ -1563,9 +1568,9 @@ union smb_close { /* SMBclose (and generic) interface */ struct { enum smb_close_level level; + union smb_file file; struct { - uint16_t fnum; time_t write_time; } in; } close, generic; @@ -1573,10 +1578,7 @@ union smb_close { /* SMBsplclose interface - empty! */ struct { enum smb_close_level level; - - struct { - uint16_t fnum; - } in; + union smb_file file; } splclose; }; @@ -1625,14 +1627,15 @@ union smb_ioctl { /* generic interface */ struct { enum smb_ioctl_level level; + union smb_file file; } generic; /* struct for SMBioctl */ struct { enum smb_ioctl_level level; + union smb_file file; struct { - uint16_t fnum; uint32_t request; } in; struct { @@ -1644,9 +1647,9 @@ union smb_ioctl { /* struct for NT ioctl call */ struct { enum smb_ioctl_level level; + union smb_file file; struct { uint32_t function; - uint16_t fnum; BOOL fsctl; uint8_t filter; } in; @@ -1657,10 +1660,10 @@ union smb_ioctl { }; /* struct for SMBflush */ -struct smb_flush { +union smb_flush { struct { - uint16_t fnum; - } in; + union smb_file file; + } flush; }; @@ -1725,24 +1728,25 @@ struct smb_nttrans { /* struct for nttrans change notify call */ -struct smb_notify { +union smb_notify { struct { - uint32_t buffer_size; - uint32_t completion_filter; - uint16_t fnum; - BOOL recursive; - } in; + union smb_file file; + struct { + uint32_t buffer_size; + uint32_t completion_filter; + BOOL recursive; + } in; - struct { - uint32_t num_changes; - struct notify_changes { - uint32_t action; - WIRE_STRING name; - } *changes; - } out; + struct { + uint32_t num_changes; + struct notify_changes { + uint32_t action; + WIRE_STRING name; + } *changes; + } out; + } notify; }; - enum smb_search_level {RAW_SEARCH_GENERIC = 0xF000, RAW_SEARCH_SEARCH, /* SMBsearch */ RAW_SEARCH_FFIRST, /* SMBffirst */ diff --git a/source4/libcli/raw/rawacl.c b/source4/libcli/raw/rawacl.c index 08515eadde..7c0c17b4d7 100644 --- a/source4/libcli/raw/rawacl.c +++ b/source4/libcli/raw/rawacl.c @@ -38,9 +38,9 @@ struct smbcli_request *smb_raw_query_secdesc_send(struct smbcli_tree *tree, nt.in.function = NT_TRANSACT_QUERY_SECURITY_DESC; nt.in.setup = NULL; - SSVAL(params, 0, io->query_secdesc.in.fnum); + SSVAL(params, 0, io->query_secdesc.file.fnum); SSVAL(params, 2, 0); /* padding */ - SIVAL(params, 4, io->query_secdesc.secinfo_flags); + SIVAL(params, 4, io->query_secdesc.in.secinfo_flags); nt.in.params.data = params; nt.in.params.length = 8; diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c index 9d2611f7b2..0e63fa656f 100644 --- a/source4/libcli/raw/rawfile.c +++ b/source4/libcli/raw/rawfile.c @@ -78,14 +78,14 @@ NTSTATUS smb_raw_rename(struct smbcli_tree *tree, Delete a file - async interface ****************************************************************************/ struct smbcli_request *smb_raw_unlink_send(struct smbcli_tree *tree, - struct smb_unlink *parms) + union smb_unlink *parms) { struct smbcli_request *req; SETUP_REQUEST(SMBunlink, 1, 0); - SSVAL(req->out.vwv, VWV(0), parms->in.attrib); - smbcli_req_append_ascii4(req, parms->in.pattern, STR_TERMINATE); + SSVAL(req->out.vwv, VWV(0), parms->unlink.in.attrib); + smbcli_req_append_ascii4(req, parms->unlink.in.pattern, STR_TERMINATE); if (!smbcli_request_send(req)) { smbcli_request_destroy(req); @@ -98,7 +98,7 @@ struct smbcli_request *smb_raw_unlink_send(struct smbcli_tree *tree, delete a file - sync interface */ NTSTATUS smb_raw_unlink(struct smbcli_tree *tree, - struct smb_unlink *parms) + union smb_unlink *parms) { struct smbcli_request *req = smb_raw_unlink_send(tree, parms); return smbcli_request_simple_recv(req); @@ -234,7 +234,7 @@ static NTSTATUS smb_raw_nttrans_create_recv(struct smbcli_request *req, params = nt.out.params.data; parms->ntcreatex.out.oplock_level = CVAL(params, 0); - parms->ntcreatex.out.fnum = SVAL(params, 2); + parms->ntcreatex.file.fnum = SVAL(params, 2); parms->ntcreatex.out.create_action = IVAL(params, 4); parms->ntcreatex.out.create_time = smbcli_pull_nttime(params, 12); parms->ntcreatex.out.access_time = smbcli_pull_nttime(params, 20); @@ -406,7 +406,7 @@ static NTSTATUS smb_raw_t2open_recv(struct smbcli_request *req, TALLOC_CTX *mem_ return NT_STATUS_INFO_LENGTH_MISMATCH; } - parms->t2open.out.fnum = SVAL(t2.out.params.data, VWV(0)); + parms->t2open.file.fnum = SVAL(t2.out.params.data, VWV(0)); parms->t2open.out.attrib = SVAL(t2.out.params.data, VWV(1)); parms->t2open.out.write_time = raw_pull_dos_date3(transport, t2.out.params.data + VWV(2)); parms->t2open.out.size = IVAL(t2.out.params.data, VWV(4)); @@ -572,7 +572,7 @@ NTSTATUS smb_raw_open_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, unio case RAW_OPEN_OPEN: SMBCLI_CHECK_WCT(req, 7); - parms->openold.out.fnum = SVAL(req->in.vwv, VWV(0)); + parms->openold.file.fnum = SVAL(req->in.vwv, VWV(0)); parms->openold.out.attrib = SVAL(req->in.vwv, VWV(1)); parms->openold.out.write_time = raw_pull_dos_date3(req->transport, req->in.vwv + VWV(2)); @@ -582,7 +582,7 @@ NTSTATUS smb_raw_open_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, unio case RAW_OPEN_OPENX: SMBCLI_CHECK_MIN_WCT(req, 15); - parms->openx.out.fnum = SVAL(req->in.vwv, VWV(2)); + parms->openx.file.fnum = SVAL(req->in.vwv, VWV(2)); parms->openx.out.attrib = SVAL(req->in.vwv, VWV(3)); parms->openx.out.write_time = raw_pull_dos_date3(req->transport, req->in.vwv + VWV(4)); @@ -603,29 +603,29 @@ NTSTATUS smb_raw_open_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, unio case RAW_OPEN_MKNEW: SMBCLI_CHECK_WCT(req, 1); - parms->mknew.out.fnum = SVAL(req->in.vwv, VWV(0)); + parms->mknew.file.fnum = SVAL(req->in.vwv, VWV(0)); break; case RAW_OPEN_CREATE: SMBCLI_CHECK_WCT(req, 1); - parms->create.out.fnum = SVAL(req->in.vwv, VWV(0)); + parms->create.file.fnum = SVAL(req->in.vwv, VWV(0)); break; case RAW_OPEN_CTEMP: SMBCLI_CHECK_WCT(req, 1); - parms->ctemp.out.fnum = SVAL(req->in.vwv, VWV(0)); + parms->ctemp.file.fnum = SVAL(req->in.vwv, VWV(0)); smbcli_req_pull_string(req, mem_ctx, &parms->ctemp.out.name, req->in.data, -1, STR_TERMINATE | STR_ASCII); break; case RAW_OPEN_SPLOPEN: SMBCLI_CHECK_WCT(req, 1); - parms->splopen.out.fnum = SVAL(req->in.vwv, VWV(0)); + parms->splopen.file.fnum = SVAL(req->in.vwv, VWV(0)); break; case RAW_OPEN_NTCREATEX: SMBCLI_CHECK_MIN_WCT(req, 34); parms->ntcreatex.out.oplock_level = CVAL(req->in.vwv, 4); - parms->ntcreatex.out.fnum = SVAL(req->in.vwv, 5); + parms->ntcreatex.file.fnum = SVAL(req->in.vwv, 5); parms->ntcreatex.out.create_action = IVAL(req->in.vwv, 7); parms->ntcreatex.out.create_time = smbcli_pull_nttime(req->in.vwv, 11); parms->ntcreatex.out.access_time = smbcli_pull_nttime(req->in.vwv, 19); @@ -644,7 +644,7 @@ NTSTATUS smb_raw_open_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, unio case RAW_OPEN_OPENX_READX: SMBCLI_CHECK_MIN_WCT(req, 15); - parms->openxreadx.out.fnum = SVAL(req->in.vwv, VWV(2)); + parms->openxreadx.file.fnum = SVAL(req->in.vwv, VWV(2)); parms->openxreadx.out.attrib = SVAL(req->in.vwv, VWV(3)); parms->openxreadx.out.write_time = raw_pull_dos_date3(req->transport, req->in.vwv + VWV(4)); @@ -706,14 +706,14 @@ struct smbcli_request *smb_raw_close_send(struct smbcli_tree *tree, union smb_cl switch (parms->generic.level) { case RAW_CLOSE_CLOSE: SETUP_REQUEST(SMBclose, 3, 0); - SSVAL(req->out.vwv, VWV(0), parms->close.in.fnum); + SSVAL(req->out.vwv, VWV(0), parms->close.file.fnum); raw_push_dos_date3(tree->session->transport, req->out.vwv, VWV(1), parms->close.in.write_time); break; case RAW_CLOSE_SPLCLOSE: SETUP_REQUEST(SMBsplclose, 3, 0); - SSVAL(req->out.vwv, VWV(0), parms->splclose.in.fnum); + SSVAL(req->out.vwv, VWV(0), parms->splclose.file.fnum); SIVAL(req->out.vwv, VWV(1), 0); /* reserved */ break; } @@ -749,14 +749,14 @@ struct smbcli_request *smb_raw_lock_send(struct smbcli_tree *tree, union smb_loc switch (parms->generic.level) { case RAW_LOCK_LOCK: SETUP_REQUEST(SMBlock, 5, 0); - SSVAL(req->out.vwv, VWV(0), parms->lock.in.fnum); + SSVAL(req->out.vwv, VWV(0), parms->lock.file.fnum); SIVAL(req->out.vwv, VWV(1), parms->lock.in.count); SIVAL(req->out.vwv, VWV(3), parms->lock.in.offset); break; case RAW_LOCK_UNLOCK: SETUP_REQUEST(SMBunlock, 5, 0); - SSVAL(req->out.vwv, VWV(0), parms->unlock.in.fnum); + SSVAL(req->out.vwv, VWV(0), parms->unlock.file.fnum); SIVAL(req->out.vwv, VWV(1), parms->unlock.in.count); SIVAL(req->out.vwv, VWV(3), parms->unlock.in.offset); break; @@ -770,7 +770,7 @@ struct smbcli_request *smb_raw_lock_send(struct smbcli_tree *tree, union smb_loc SETUP_REQUEST(SMBlockingX, 8, lck_size * lock_count); SSVAL(req->out.vwv, VWV(0), SMB_CHAIN_NONE); SSVAL(req->out.vwv, VWV(1), 0); - SSVAL(req->out.vwv, VWV(2), parms->lockx.in.fnum); + SSVAL(req->out.vwv, VWV(2), parms->lockx.file.fnum); SSVAL(req->out.vwv, VWV(3), parms->lockx.in.mode); SIVAL(req->out.vwv, VWV(4), parms->lockx.in.timeout); SSVAL(req->out.vwv, VWV(6), parms->lockx.in.ulock_cnt); @@ -816,13 +816,13 @@ NTSTATUS smb_raw_lock(struct smbcli_tree *tree, union smb_lock *parms) /**************************************************************************** Check for existence of a dir - async send ****************************************************************************/ -struct smbcli_request *smb_raw_chkpath_send(struct smbcli_tree *tree, struct smb_chkpath *parms) +struct smbcli_request *smb_raw_chkpath_send(struct smbcli_tree *tree, union smb_chkpath *parms) { struct smbcli_request *req; SETUP_REQUEST(SMBchkpth, 0, 0); - smbcli_req_append_ascii4(req, parms->in.path, STR_TERMINATE); + smbcli_req_append_ascii4(req, parms->chkpath.in.path, STR_TERMINATE); if (!smbcli_request_send(req)) { smbcli_request_destroy(req); @@ -835,25 +835,22 @@ struct smbcli_request *smb_raw_chkpath_send(struct smbcli_tree *tree, struct smb /**************************************************************************** Check for existence of a dir - sync interface ****************************************************************************/ -NTSTATUS smb_raw_chkpath(struct smbcli_tree *tree, struct smb_chkpath *parms) +NTSTATUS smb_raw_chkpath(struct smbcli_tree *tree, union smb_chkpath *parms) { struct smbcli_request *req = smb_raw_chkpath_send(tree, parms); return smbcli_request_simple_recv(req); } - - - /**************************************************************************** flush a file - async send a flush to fnum 0xFFFF will flush all files ****************************************************************************/ -struct smbcli_request *smb_raw_flush_send(struct smbcli_tree *tree, struct smb_flush *parms) +struct smbcli_request *smb_raw_flush_send(struct smbcli_tree *tree, union smb_flush *parms) { struct smbcli_request *req; SETUP_REQUEST(SMBflush, 1, 0); - SSVAL(req->out.vwv, VWV(0), parms->in.fnum); + SSVAL(req->out.vwv, VWV(0), parms->flush.file.fnum); if (!smbcli_request_send(req)) { smbcli_request_destroy(req); @@ -867,7 +864,7 @@ struct smbcli_request *smb_raw_flush_send(struct smbcli_tree *tree, struct smb_f /**************************************************************************** flush a file - sync interface ****************************************************************************/ -NTSTATUS smb_raw_flush(struct smbcli_tree *tree, struct smb_flush *parms) +NTSTATUS smb_raw_flush(struct smbcli_tree *tree, union smb_flush *parms) { struct smbcli_request *req = smb_raw_flush_send(tree, parms); return smbcli_request_simple_recv(req); @@ -878,15 +875,15 @@ NTSTATUS smb_raw_flush(struct smbcli_tree *tree, struct smb_flush *parms) seek a file - async send ****************************************************************************/ struct smbcli_request *smb_raw_seek_send(struct smbcli_tree *tree, - struct smb_seek *parms) + union smb_seek *parms) { struct smbcli_request *req; SETUP_REQUEST(SMBlseek, 4, 0); - SSVAL(req->out.vwv, VWV(0), parms->in.fnum); - SSVAL(req->out.vwv, VWV(1), parms->in.mode); - SIVALS(req->out.vwv, VWV(2), parms->in.offset); + SSVAL(req->out.vwv, VWV(0), parms->lseek.file.fnum); + SSVAL(req->out.vwv, VWV(1), parms->lseek.in.mode); + SIVALS(req->out.vwv, VWV(2), parms->lseek.in.offset); if (!smbcli_request_send(req)) { smbcli_request_destroy(req); @@ -899,7 +896,7 @@ struct smbcli_request *smb_raw_seek_send(struct smbcli_tree *tree, seek a file - async receive ****************************************************************************/ NTSTATUS smb_raw_seek_recv(struct smbcli_request *req, - struct smb_seek *parms) + union smb_seek *parms) { if (!smbcli_request_receive(req) || smbcli_request_is_error(req)) { @@ -907,7 +904,7 @@ NTSTATUS smb_raw_seek_recv(struct smbcli_request *req, } SMBCLI_CHECK_WCT(req, 2); - parms->out.offset = IVAL(req->in.vwv, VWV(0)); + parms->lseek.out.offset = IVAL(req->in.vwv, VWV(0)); failed: return smbcli_request_destroy(req); @@ -917,7 +914,7 @@ failed: seek a file - sync interface */ NTSTATUS smb_raw_seek(struct smbcli_tree *tree, - struct smb_seek *parms) + union smb_seek *parms) { struct smbcli_request *req = smb_raw_seek_send(tree, parms); return smb_raw_seek_recv(req, parms); diff --git a/source4/libcli/raw/rawfileinfo.c b/source4/libcli/raw/rawfileinfo.c index 92d31b30ef..b50a330093 100644 --- a/source4/libcli/raw/rawfileinfo.c +++ b/source4/libcli/raw/rawfileinfo.c @@ -536,7 +536,7 @@ static struct smbcli_request *smb_raw_getattr_send(struct smbcli_tree *tree, req = smbcli_request_setup(tree, SMBgetatr, 0, 0); if (!req) return NULL; - smbcli_req_append_ascii4(req, parms->getattr.in.fname, STR_TERMINATE); + smbcli_req_append_ascii4(req, parms->getattr.file.path, STR_TERMINATE); if (!smbcli_request_send(req)) { smbcli_request_destroy(req); @@ -579,7 +579,7 @@ static struct smbcli_request *smb_raw_getattrE_send(struct smbcli_tree *tree, req = smbcli_request_setup(tree, SMBgetattrE, 1, 0); if (!req) return NULL; - SSVAL(req->out.vwv, VWV(0), parms->getattre.in.fnum); + SSVAL(req->out.vwv, VWV(0), parms->getattre.file.fnum); if (!smbcli_request_send(req)) { smbcli_request_destroy(req); return NULL; @@ -647,7 +647,7 @@ struct smbcli_request *smb_raw_fileinfo_send(struct smbcli_tree *tree, } req = smb_raw_fileinfo_blob_send(tree, - parms->generic.in.fnum, + parms->generic.file.fnum, parms->generic.level, data); data_blob_free(&data); @@ -722,7 +722,7 @@ struct smbcli_request *smb_raw_pathinfo_send(struct smbcli_tree *tree, } } - req = smb_raw_pathinfo_blob_send(tree, parms->generic.in.fname, + req = smb_raw_pathinfo_blob_send(tree, parms->generic.file.path, parms->generic.level, data); data_blob_free(&data); diff --git a/source4/libcli/raw/rawioctl.c b/source4/libcli/raw/rawioctl.c index 874d055013..28b58ff2a3 100644 --- a/source4/libcli/raw/rawioctl.c +++ b/source4/libcli/raw/rawioctl.c @@ -37,7 +37,7 @@ static struct smbcli_request *smb_raw_smbioctl_send(struct smbcli_tree *tree, SETUP_REQUEST(SMBioctl, 3, 0); - SSVAL(req->out.vwv, VWV(0), parms->ioctl.in.fnum); + SSVAL(req->out.vwv, VWV(0), parms->ioctl.file.fnum); SIVAL(req->out.vwv, VWV(1), parms->ioctl.in.request); if (!smbcli_request_send(req)) { @@ -81,7 +81,7 @@ static struct smbcli_request *smb_raw_ntioctl_send(struct smbcli_tree *tree, nt.in.setup_count = 4; nt.in.setup = setup; SIVAL(setup, 0, parms->ntioctl.in.function); - SSVAL(setup, 4, parms->ntioctl.in.fnum); + SSVAL(setup, 4, parms->ntioctl.file.fnum); SCVAL(setup, 6, parms->ntioctl.in.fsctl); SCVAL(setup, 7, parms->ntioctl.in.filter); nt.in.function = NT_TRANSACT_IOCTL; diff --git a/source4/libcli/raw/rawnotify.c b/source4/libcli/raw/rawnotify.c index 1215a93f59..3adb1b000b 100644 --- a/source4/libcli/raw/rawnotify.c +++ b/source4/libcli/raw/rawnotify.c @@ -25,19 +25,19 @@ /**************************************************************************** change notify (async send) ****************************************************************************/ -struct smbcli_request *smb_raw_changenotify_send(struct smbcli_tree *tree, struct smb_notify *parms) +struct smbcli_request *smb_raw_changenotify_send(struct smbcli_tree *tree, union smb_notify *parms) { struct smb_nttrans nt; uint16_t setup[4]; nt.in.max_setup = 0; - nt.in.max_param = parms->in.buffer_size; + nt.in.max_param = parms->notify.in.buffer_size; nt.in.max_data = 0; nt.in.setup_count = 4; nt.in.setup = setup; - SIVAL(setup, 0, parms->in.completion_filter); - SSVAL(setup, 4, parms->in.fnum); - SSVAL(setup, 6, parms->in.recursive); + SIVAL(setup, 0, parms->notify.in.completion_filter); + SSVAL(setup, 4, parms->notify.file.fnum); + SSVAL(setup, 6, parms->notify.in.recursive); nt.in.function = NT_TRANSACT_NOTIFY_CHANGE; nt.in.params = data_blob(NULL, 0); nt.in.data = data_blob(NULL, 0); @@ -49,7 +49,7 @@ struct smbcli_request *smb_raw_changenotify_send(struct smbcli_tree *tree, struc change notify (async recv) ****************************************************************************/ NTSTATUS smb_raw_changenotify_recv(struct smbcli_request *req, - TALLOC_CTX *mem_ctx, struct smb_notify *parms) + TALLOC_CTX *mem_ctx, union smb_notify *parms) { struct smb_nttrans nt; NTSTATUS status; @@ -61,28 +61,28 @@ NTSTATUS smb_raw_changenotify_recv(struct smbcli_request *req, return status; } - parms->out.changes = NULL; - parms->out.num_changes = 0; + parms->notify.out.changes = NULL; + parms->notify.out.num_changes = 0; /* count them */ for (ofs=0; nt.out.params.length - ofs > 12; ) { uint32_t next = IVAL(nt.out.params.data, ofs); - parms->out.num_changes++; + parms->notify.out.num_changes++; if (next == 0 || ofs + next >= nt.out.params.length) break; ofs += next; } /* allocate array */ - parms->out.changes = talloc_array(mem_ctx, struct notify_changes, parms->out.num_changes); - if (!parms->out.changes) { + parms->notify.out.changes = talloc_array(mem_ctx, struct notify_changes, parms->notify.out.num_changes); + if (!parms->notify.out.changes) { return NT_STATUS_NO_MEMORY; } - for (i=ofs=0; iout.num_changes; i++) { - parms->out.changes[i].action = IVAL(nt.out.params.data, ofs+4); + for (i=ofs=0; inotify.out.num_changes; i++) { + parms->notify.out.changes[i].action = IVAL(nt.out.params.data, ofs+4); smbcli_blob_pull_string(session, mem_ctx, &nt.out.params, - &parms->out.changes[i].name, + &parms->notify.out.changes[i].name, ofs+8, ofs+12, STR_UNICODE); ofs += IVAL(nt.out.params.data, ofs); } diff --git a/source4/libcli/raw/rawreadwrite.c b/source4/libcli/raw/rawreadwrite.c index d9fe3fdce0..00dc71971e 100644 --- a/source4/libcli/raw/rawreadwrite.c +++ b/source4/libcli/raw/rawreadwrite.c @@ -41,7 +41,7 @@ struct smbcli_request *smb_raw_read_send(struct smbcli_tree *tree, union smb_rea bigoffset = True; } SETUP_REQUEST(SMBreadbraw, bigoffset? 10:8, 0); - SSVAL(req->out.vwv, VWV(0), parms->readbraw.in.fnum); + SSVAL(req->out.vwv, VWV(0), parms->readbraw.file.fnum); SIVAL(req->out.vwv, VWV(1), parms->readbraw.in.offset); SSVAL(req->out.vwv, VWV(3), parms->readbraw.in.maxcnt); SSVAL(req->out.vwv, VWV(4), parms->readbraw.in.mincnt); @@ -54,7 +54,7 @@ struct smbcli_request *smb_raw_read_send(struct smbcli_tree *tree, union smb_rea case RAW_READ_LOCKREAD: SETUP_REQUEST(SMBlockread, 5, 0); - SSVAL(req->out.vwv, VWV(0), parms->lockread.in.fnum); + SSVAL(req->out.vwv, VWV(0), parms->lockread.file.fnum); SSVAL(req->out.vwv, VWV(1), parms->lockread.in.count); SIVAL(req->out.vwv, VWV(2), parms->lockread.in.offset); SSVAL(req->out.vwv, VWV(4), parms->lockread.in.remaining); @@ -62,7 +62,7 @@ struct smbcli_request *smb_raw_read_send(struct smbcli_tree *tree, union smb_rea case RAW_READ_READ: SETUP_REQUEST(SMBread, 5, 0); - SSVAL(req->out.vwv, VWV(0), parms->read.in.fnum); + SSVAL(req->out.vwv, VWV(0), parms->read.file.fnum); SSVAL(req->out.vwv, VWV(1), parms->read.in.count); SIVAL(req->out.vwv, VWV(2), parms->read.in.offset); SSVAL(req->out.vwv, VWV(4), parms->read.in.remaining); @@ -75,7 +75,7 @@ struct smbcli_request *smb_raw_read_send(struct smbcli_tree *tree, union smb_rea SETUP_REQUEST(SMBreadX, bigoffset ? 12 : 10, 0); SSVAL(req->out.vwv, VWV(0), SMB_CHAIN_NONE); SSVAL(req->out.vwv, VWV(1), 0); - SSVAL(req->out.vwv, VWV(2), parms->readx.in.fnum); + SSVAL(req->out.vwv, VWV(2), parms->readx.file.fnum); SIVAL(req->out.vwv, VWV(3), parms->readx.in.offset); SSVAL(req->out.vwv, VWV(5), parms->readx.in.maxcnt & 0xFFFF); SSVAL(req->out.vwv, VWV(6), parms->readx.in.mincnt); @@ -183,7 +183,7 @@ struct smbcli_request *smb_raw_write_send(struct smbcli_tree *tree, union smb_wr switch (parms->generic.level) { case RAW_WRITE_WRITEUNLOCK: SETUP_REQUEST(SMBwriteunlock, 5, 3 + parms->writeunlock.in.count); - SSVAL(req->out.vwv, VWV(0), parms->writeunlock.in.fnum); + SSVAL(req->out.vwv, VWV(0), parms->writeunlock.file.fnum); SSVAL(req->out.vwv, VWV(1), parms->writeunlock.in.count); SIVAL(req->out.vwv, VWV(2), parms->writeunlock.in.offset); SSVAL(req->out.vwv, VWV(4), parms->writeunlock.in.remaining); @@ -197,7 +197,7 @@ struct smbcli_request *smb_raw_write_send(struct smbcli_tree *tree, union smb_wr case RAW_WRITE_WRITE: SETUP_REQUEST(SMBwrite, 5, 3 + parms->write.in.count); - SSVAL(req->out.vwv, VWV(0), parms->write.in.fnum); + SSVAL(req->out.vwv, VWV(0), parms->write.file.fnum); SSVAL(req->out.vwv, VWV(1), parms->write.in.count); SIVAL(req->out.vwv, VWV(2), parms->write.in.offset); SSVAL(req->out.vwv, VWV(4), parms->write.in.remaining); @@ -210,7 +210,7 @@ struct smbcli_request *smb_raw_write_send(struct smbcli_tree *tree, union smb_wr case RAW_WRITE_WRITECLOSE: SETUP_REQUEST(SMBwriteclose, 6, 1 + parms->writeclose.in.count); - SSVAL(req->out.vwv, VWV(0), parms->writeclose.in.fnum); + SSVAL(req->out.vwv, VWV(0), parms->writeclose.file.fnum); SSVAL(req->out.vwv, VWV(1), parms->writeclose.in.count); SIVAL(req->out.vwv, VWV(2), parms->writeclose.in.offset); raw_push_dos_date3(tree->session->transport, @@ -229,7 +229,7 @@ struct smbcli_request *smb_raw_write_send(struct smbcli_tree *tree, union smb_wr SETUP_REQUEST(SMBwriteX, bigoffset ? 14 : 12, parms->writex.in.count); SSVAL(req->out.vwv, VWV(0), SMB_CHAIN_NONE); SSVAL(req->out.vwv, VWV(1), 0); - SSVAL(req->out.vwv, VWV(2), parms->writex.in.fnum); + SSVAL(req->out.vwv, VWV(2), parms->writex.file.fnum); SIVAL(req->out.vwv, VWV(3), parms->writex.in.offset); SIVAL(req->out.vwv, VWV(5), 0); /* reserved */ SSVAL(req->out.vwv, VWV(7), parms->writex.in.wmode); @@ -247,7 +247,7 @@ struct smbcli_request *smb_raw_write_send(struct smbcli_tree *tree, union smb_wr case RAW_WRITE_SPLWRITE: SETUP_REQUEST(SMBsplwr, 1, parms->splwrite.in.count); - SSVAL(req->out.vwv, VWV(0), parms->splwrite.in.fnum); + SSVAL(req->out.vwv, VWV(0), parms->splwrite.file.fnum); if (parms->splwrite.in.count > 0) { memcpy(req->out.data, parms->splwrite.in.data, parms->splwrite.in.count); } -- cgit From e5e10ca55ce94d371dc507b2cbb23e70440c9332 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 10 Mar 2006 21:38:07 +0000 Subject: r14174: fix typos metze (This used to be commit 29240bae4488749b3f8a2b49bccad1601d1aa184) --- source4/libcli/raw/rawsetfileinfo.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawsetfileinfo.c b/source4/libcli/raw/rawsetfileinfo.c index 5779cf33fb..73fcd82802 100644 --- a/source4/libcli/raw/rawsetfileinfo.c +++ b/source4/libcli/raw/rawsetfileinfo.c @@ -283,7 +283,7 @@ static struct smbcli_request *smb_raw_setattr_send(struct smbcli_tree *tree, raw_push_dos_date3(tree->session->transport, req->out.vwv, VWV(1), parms->setattr.in.write_time); memset(req->out.vwv + VWV(3), 0, 10); /* reserved */ - smbcli_req_append_ascii4(req, parms->setattr.file.fname, STR_TERMINATE); + smbcli_req_append_ascii4(req, parms->setattr.file.path, STR_TERMINATE); smbcli_req_append_ascii4(req, "", STR_TERMINATE); if (!smbcli_request_send(req)) { @@ -399,7 +399,7 @@ struct smbcli_request *smb_raw_setpathinfo_send(struct smbcli_tree *tree, /* send request and process the output */ req = smb_raw_setpathinfo_blob_send(tree, mem_ctx, - parms->generic.file.fname, + parms->generic.file.path, parms->generic.level, &blob); -- cgit From 32b0bb64bcb91a3f08fcaea72b89bf6409d0e67c Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sat, 11 Mar 2006 10:25:59 +0000 Subject: r14205: move smb specific stuff out of includes.h (finally!!!:-) all this changes really help ccache to speed up the samba4 build:-) metze (This used to be commit 180a79d1036e54fc0c50572b820818e9aafa28e9) --- source4/libcli/raw/interfaces.h | 71 ++++++++++++++++------------------------- source4/libcli/raw/raweas.c | 1 + source4/libcli/raw/rawlpq.c | 1 + source4/libcli/raw/rawrequest.c | 4 +-- 4 files changed, 31 insertions(+), 46 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index 0505078fd4..e476a00b68 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -34,27 +34,10 @@ is always determined by NULL or packet termination a normal char* is used in the structure definition. */ -typedef struct { +struct smb_wire_string { uint32_t private_length; const char *s; -} WIRE_STRING; - - -/* - use the same structure for dom_sid2 as dom_sid. A dom_sid2 is really - just a dom sid, but with the sub_auths represented as a conformant - array. As with all in-structure conformant arrays, the array length - is placed before the start of the structure. That's what gives rise - to the extra num_auths elemenent. We don't want the Samba code to - have to bother with such esoteric NDR details, so its easier to just - define it as a dom_sid and use pidl magic to make it all work. It - just means you need to mark a sid as a "dom_sid2" in the IDL when you - know it is of the conformant array variety -*/ -#define dom_sid2 dom_sid - -/* same struct as dom_sid but inside a 28 bytes fixed buffer in NDR */ -#define dom_sid28 dom_sid +}; /* a generic container for file handles @@ -368,7 +351,7 @@ union smb_fileinfo { uint_t num_eas; struct ea_struct { uint8_t flags; - WIRE_STRING name; + struct smb_wire_string name; DATA_BLOB value; } *eas; NTTIME create_time; @@ -378,8 +361,8 @@ union smb_fileinfo { uint64_t alloc_size; uint64_t size; uint32_t nlink; - WIRE_STRING fname; - WIRE_STRING alt_fname; + struct smb_wire_string fname; + struct smb_wire_string alt_fname; uint8_t delete_pending; uint8_t directory; uint64_t compressed_size; @@ -397,7 +380,7 @@ union smb_fileinfo { struct stream_struct { uint64_t size; uint64_t alloc_size; - WIRE_STRING stream_name; + struct smb_wire_string stream_name; } *streams; } out; } generic; @@ -455,7 +438,7 @@ union smb_fileinfo { struct { uint_t num_names; struct ea_name { - WIRE_STRING name; + struct smb_wire_string name; } *ea_names; } in; @@ -528,7 +511,7 @@ union smb_fileinfo { union smb_file file; struct { - WIRE_STRING fname; + struct smb_wire_string fname; } out; } name_info; @@ -549,7 +532,7 @@ union smb_fileinfo { uint8_t delete_pending; uint8_t directory; uint32_t ea_size; - WIRE_STRING fname; + struct smb_wire_string fname; } out; } all_info; @@ -576,7 +559,7 @@ union smb_fileinfo { uint32_t access_mask; uint64_t position; uint64_t mode; - WIRE_STRING fname; + struct smb_wire_string fname; } out; } all_info2; @@ -586,7 +569,7 @@ union smb_fileinfo { union smb_file file; struct { - WIRE_STRING fname; + struct smb_wire_string fname; } out; } alt_name_info; @@ -643,7 +626,7 @@ union smb_fileinfo { union smb_file file; struct { - WIRE_STRING link_dest; + struct smb_wire_string link_dest; } out; } unix_link_info; @@ -1009,7 +992,7 @@ union smb_fsinfo { struct { uint32_t serial_number; - WIRE_STRING volume_name; + struct smb_wire_string volume_name; } out; } volume; @@ -1021,7 +1004,7 @@ union smb_fsinfo { struct { NTTIME create_time; uint32_t serial_number; - WIRE_STRING volume_name; + struct smb_wire_string volume_name; } out; } volume_info; @@ -1058,7 +1041,7 @@ union smb_fsinfo { struct { uint32_t fs_attr; uint32_t max_file_component_length; - WIRE_STRING fs_type; + struct smb_wire_string fs_type; } out; } attribute_info; @@ -1741,7 +1724,7 @@ union smb_notify { uint32_t num_changes; struct notify_changes { uint32_t action; - WIRE_STRING name; + struct smb_wire_string name; } *changes; } out; } notify; @@ -1876,7 +1859,7 @@ union smb_search_data { uint32_t size; uint32_t alloc_size; uint16_t attrib; - WIRE_STRING name; + struct smb_wire_string name; } standard; /* trans2 findfirst RAW_SEARCH_EA_SIZE level */ @@ -1889,7 +1872,7 @@ union smb_search_data { uint32_t alloc_size; uint16_t attrib; uint32_t ea_size; - WIRE_STRING name; + struct smb_wire_string name; } ea_size; /* trans2 findfirst RAW_SEARCH_EA_LIST level */ @@ -1902,7 +1885,7 @@ union smb_search_data { uint32_t alloc_size; uint16_t attrib; struct smb_ea_list eas; - WIRE_STRING name; + struct smb_wire_string name; } ea_list; /* RAW_SEARCH_DIRECTORY_INFO interface */ @@ -1915,7 +1898,7 @@ union smb_search_data { uint64_t size; uint64_t alloc_size; uint32_t attrib; - WIRE_STRING name; + struct smb_wire_string name; } directory_info; /* RAW_SEARCH_FULL_DIRECTORY_INFO interface */ @@ -1929,13 +1912,13 @@ union smb_search_data { uint64_t alloc_size; uint32_t attrib; uint32_t ea_size; - WIRE_STRING name; + struct smb_wire_string name; } full_directory_info; /* RAW_SEARCH_NAME_INFO interface */ struct { uint32_t file_index; - WIRE_STRING name; + struct smb_wire_string name; } name_info; /* RAW_SEARCH_BOTH_DIRECTORY_INFO interface */ @@ -1949,8 +1932,8 @@ union smb_search_data { uint64_t alloc_size; uint32_t attrib; uint32_t ea_size; - WIRE_STRING short_name; - WIRE_STRING name; + struct smb_wire_string short_name; + struct smb_wire_string name; } both_directory_info; /* RAW_SEARCH_ID_FULL_DIRECTORY_INFO interface */ @@ -1965,7 +1948,7 @@ union smb_search_data { uint32_t attrib; uint32_t ea_size; uint64_t file_id; - WIRE_STRING name; + struct smb_wire_string name; } id_full_directory_info; /* RAW_SEARCH_ID_BOTH_DIRECTORY_INFO interface */ @@ -1980,8 +1963,8 @@ union smb_search_data { uint32_t attrib; uint32_t ea_size; uint64_t file_id; - WIRE_STRING short_name; - WIRE_STRING name; + struct smb_wire_string short_name; + struct smb_wire_string name; } id_both_directory_info; /* RAW_SEARCH_UNIX_INFO interface */ diff --git a/source4/libcli/raw/raweas.c b/source4/libcli/raw/raweas.c index 4ab3344135..4c609aa593 100644 --- a/source4/libcli/raw/raweas.c +++ b/source4/libcli/raw/raweas.c @@ -19,6 +19,7 @@ */ #include "includes.h" +#include "smb.h" /* work out how many bytes on the wire a ea list will consume. diff --git a/source4/libcli/raw/rawlpq.c b/source4/libcli/raw/rawlpq.c index 40669e51de..882ed3c302 100644 --- a/source4/libcli/raw/rawlpq.c +++ b/source4/libcli/raw/rawlpq.c @@ -19,6 +19,7 @@ */ #include "includes.h" +#include "smb.h" /**************************************************************************** lpq - async send diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index cd76e0e438..b07a92e3fa 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -827,7 +827,7 @@ static size_t smbcli_blob_pull_ascii(TALLOC_CTX *mem_ctx, } /* - pull a string from a blob, returning a talloced WIRE_STRING + pull a string from a blob, returning a talloced struct smb_wire_string the string length is limited by the 3 things: - the data size in the blob @@ -843,7 +843,7 @@ static size_t smbcli_blob_pull_ascii(TALLOC_CTX *mem_ctx, size_t smbcli_blob_pull_string(struct smbcli_session *session, TALLOC_CTX *mem_ctx, const DATA_BLOB *blob, - WIRE_STRING *dest, + struct smb_wire_string *dest, uint16_t len_offset, uint16_t str_offset, uint_t flags) { -- cgit From 7f0c7702f6b9db216fcd6c29165b2a11ea1f24a9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 11 Mar 2006 12:58:36 +0000 Subject: r14208: removed use of req->flags2 inside the ntvfs layer. This should help metze on his quest to unify the ntvfs strucures for the smb and smb2 servers. The only place we needed flags2 inside ntvfs was for the FLAGS2_READ_PERMIT_EXECUTE bit, which only affects readx, so I added a readx.in.read_for_execute flag instead. (This used to be commit b78abbbce60ab0009da19a72dd769800c44298a2) --- source4/libcli/raw/interfaces.h | 1 + source4/libcli/raw/rawreadwrite.c | 3 +++ 2 files changed, 4 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index e476a00b68..086686b9e9 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -1352,6 +1352,7 @@ union smb_read { uint16_t mincnt; uint32_t maxcnt; uint16_t remaining; + BOOL read_for_execute; } in; struct { uint8_t *data; diff --git a/source4/libcli/raw/rawreadwrite.c b/source4/libcli/raw/rawreadwrite.c index 00dc71971e..c4e2ab2498 100644 --- a/source4/libcli/raw/rawreadwrite.c +++ b/source4/libcli/raw/rawreadwrite.c @@ -84,6 +84,9 @@ struct smbcli_request *smb_raw_read_send(struct smbcli_tree *tree, union smb_rea if (bigoffset) { SIVAL(req->out.vwv, VWV(10),parms->readx.in.offset>>32); } + if (parms->readx.in.read_for_execute) { + req->flags2 |= FLAGS2_READ_PERMIT_EXECUTE; + } break; } -- cgit From a1b295ed4823ce8d06f830b8db9a5d965c934b54 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sun, 12 Mar 2006 22:48:25 +0000 Subject: r14256: - rename smb_file -> smb_handle - move it into the in/out substructs again - allow file.path only on smb_fileinfo/smb_setfileinfo metze (This used to be commit be6d5298a2cdb7e7c61d70471bad445645af5963) --- source4/libcli/raw/interfaces.h | 291 ++++++++++++++++++++---------------- source4/libcli/raw/rawacl.c | 4 +- source4/libcli/raw/rawfile.c | 34 ++--- source4/libcli/raw/rawfileinfo.c | 8 +- source4/libcli/raw/rawioctl.c | 4 +- source4/libcli/raw/rawnotify.c | 2 +- source4/libcli/raw/rawreadwrite.c | 18 +-- source4/libcli/raw/rawsetfileinfo.c | 8 +- 8 files changed, 199 insertions(+), 170 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index 086686b9e9..20b729caba 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -40,16 +40,45 @@ struct smb_wire_string { }; /* - a generic container for file handles + * SMB2 uses a 16Byte handle, + * (we can maybe use struct GUID later) + */ +struct smb2_handle { + uint64_t data[2]; +}; + +/* + * a generic container for file handles or file pathes + * for qfileinfo/setfileinfo and qpathinfo/setpathinfo */ -union smb_file { +union smb_handle_or_path { /* - * this is only used for + * this is used for * the qpathinfo and setpathinfo * calls */ const char *path; + /* + * this is used as file handle in SMB + */ + uint16_t fnum; + /* + * this is used as file handle in SMB2 + */ + struct smb2_handle handle; +}; + +/* + a generic container for file handles +*/ +union smb_handle { + /* + * this is used for + * the qpathinfo and setpathinfo + * calls + */ + const char *path; /* * this is used as file handle in SMB */ @@ -58,9 +87,7 @@ union smb_file { /* * this is used as file handle in SMB2 */ - struct smb2_handle { - uint64_t data[2]; - } handle; + struct smb2_handle handle; }; /* @@ -71,8 +98,8 @@ union smb_file { /* struct used for SMBlseek call */ union smb_seek { struct { - union smb_file file; struct { + union smb_handle file; uint16_t mode; int32_t offset; /* signed */ } in; @@ -343,8 +370,9 @@ union smb_fileinfo { * matches RAW_FILEINFO_GENERIC */ struct { enum smb_fileinfo_level level; - union smb_file file; - + struct { + union smb_handle_or_path file; + } in; struct { uint32_t attrib; uint32_t ea_size; @@ -390,8 +418,9 @@ union smb_fileinfo { * matches RAW_FILEINFO_GETATTR */ struct { enum smb_fileinfo_level level; - union smb_file file; - + struct { + union smb_handle_or_path file; + } in; struct { uint16_t attrib; uint32_t size; @@ -402,8 +431,9 @@ union smb_fileinfo { /* SMBgetattrE and RAW_FILEINFO_STANDARD interface */ struct { enum smb_fileinfo_level level; - union smb_file file; - + struct { + union smb_handle_or_path file; + } in; struct { time_t create_time; time_t access_time; @@ -417,8 +447,9 @@ union smb_fileinfo { /* trans2 RAW_FILEINFO_EA_SIZE interface */ struct { enum smb_fileinfo_level level; - union smb_file file; - + struct { + union smb_handle_or_path file; + } in; struct { time_t create_time; time_t access_time; @@ -433,9 +464,8 @@ union smb_fileinfo { /* trans2 RAW_FILEINFO_EA_LIST interface */ struct { enum smb_fileinfo_level level; - union smb_file file; - struct { + union smb_handle_or_path file; uint_t num_names; struct ea_name { struct smb_wire_string name; @@ -451,8 +481,8 @@ union smb_fileinfo { /* trans2 RAW_FILEINFO_ALL_EAS and RAW_FILEINFO_FULL_EA_INFORMATION interfaces */ struct { enum smb_fileinfo_level level; - union smb_file file; struct { + union smb_handle_or_path file; /* SMB2 only - SMB2_CONTINUE_FLAG_* */ uint8_t continue_flags; } in; @@ -463,14 +493,17 @@ union smb_fileinfo { only valid for a QPATHNAME call - no returned data */ struct { enum smb_fileinfo_level level; - union smb_file file; + struct { + union smb_handle_or_path file; + } in; } is_name_valid; /* RAW_FILEINFO_BASIC_INFO and RAW_FILEINFO_BASIC_INFORMATION interfaces */ struct { enum smb_fileinfo_level level; - union smb_file file; - + struct { + union smb_handle_or_path file; + } in; struct { NTTIME create_time; NTTIME access_time; @@ -484,8 +517,9 @@ union smb_fileinfo { /* RAW_FILEINFO_STANDARD_INFO and RAW_FILEINFO_STANDARD_INFORMATION interfaces */ struct { enum smb_fileinfo_level level; - union smb_file file; - + struct { + union smb_handle_or_path file; + } in; struct { uint64_t alloc_size; uint64_t size; @@ -498,8 +532,9 @@ union smb_fileinfo { /* RAW_FILEINFO_EA_INFO and RAW_FILEINFO_EA_INFORMATION interfaces */ struct { enum smb_fileinfo_level level; - union smb_file file; - + struct { + union smb_handle_or_path file; + } in; struct { uint32_t ea_size; } out; @@ -508,8 +543,9 @@ union smb_fileinfo { /* RAW_FILEINFO_NAME_INFO and RAW_FILEINFO_NAME_INFORMATION interfaces */ struct { enum smb_fileinfo_level level; - union smb_file file; - + struct { + union smb_handle_or_path file; + } in; struct { struct smb_wire_string fname; } out; @@ -518,8 +554,9 @@ union smb_fileinfo { /* RAW_FILEINFO_ALL_INFO and RAW_FILEINFO_ALL_INFORMATION interfaces */ struct { enum smb_fileinfo_level level; - union smb_file file; - + struct { + union smb_handle_or_path file; + } in; struct { NTTIME create_time; NTTIME access_time; @@ -539,8 +576,9 @@ union smb_fileinfo { /* RAW_FILEINFO_SMB2_ALL_INFORMATION interface */ struct { enum smb_fileinfo_level level; - union smb_file file; - + struct { + union smb_handle_or_path file; + } in; struct { NTTIME create_time; NTTIME access_time; @@ -561,13 +599,14 @@ union smb_fileinfo { uint64_t mode; struct smb_wire_string fname; } out; - } all_info2; + } all_info2; /* RAW_FILEINFO_ALT_NAME_INFO and RAW_FILEINFO_ALT_NAME_INFORMATION interfaces */ struct { enum smb_fileinfo_level level; - union smb_file file; - + struct { + union smb_handle_or_path file; + } in; struct { struct smb_wire_string fname; } out; @@ -576,8 +615,9 @@ union smb_fileinfo { /* RAW_FILEINFO_STREAM_INFO and RAW_FILEINFO_STREAM_INFORMATION interfaces */ struct { enum smb_fileinfo_level level; - union smb_file file; - + struct { + union smb_handle_or_path file; + } in; struct stream_information { uint_t num_streams; struct stream_struct *streams; @@ -587,8 +627,9 @@ union smb_fileinfo { /* RAW_FILEINFO_COMPRESSION_INFO and RAW_FILEINFO_COMPRESSION_INFORMATION interfaces */ struct { enum smb_fileinfo_level level; - union smb_file file; - + struct { + union smb_handle_or_path file; + } in; struct { uint64_t compressed_size; uint16_t format; @@ -601,8 +642,9 @@ union smb_fileinfo { /* RAW_FILEINFO_UNIX_BASIC interface */ struct { enum smb_fileinfo_level level; - union smb_file file; - + struct { + union smb_handle_or_path file; + } in; struct { uint64_t end_of_file; uint64_t num_bytes; @@ -623,8 +665,9 @@ union smb_fileinfo { /* RAW_FILEINFO_UNIX_LINK interface */ struct { enum smb_fileinfo_level level; - union smb_file file; - + struct { + union smb_handle_or_path file; + } in; struct { struct smb_wire_string link_dest; } out; @@ -633,8 +676,9 @@ union smb_fileinfo { /* RAW_FILEINFO_INTERNAL_INFORMATION interface */ struct { enum smb_fileinfo_level level; - union smb_file file; - + struct { + union smb_handle_or_path file; + } in; struct { uint64_t file_id; } out; @@ -643,8 +687,9 @@ union smb_fileinfo { /* RAW_FILEINFO_ACCESS_INFORMATION interface */ struct { enum smb_fileinfo_level level; - union smb_file file; - + struct { + union smb_handle_or_path file; + } in; struct { uint32_t access_flags; } out; @@ -653,8 +698,9 @@ union smb_fileinfo { /* RAW_FILEINFO_POSITION_INFORMATION interface */ struct { enum smb_fileinfo_level level; - union smb_file file; - + struct { + union smb_handle_or_path file; + } in; struct { uint64_t position; } out; @@ -663,8 +709,9 @@ union smb_fileinfo { /* RAW_FILEINFO_MODE_INFORMATION interface */ struct { enum smb_fileinfo_level level; - union smb_file file; - + struct { + union smb_handle_or_path file; + } in; struct { uint32_t mode; } out; @@ -673,8 +720,9 @@ union smb_fileinfo { /* RAW_FILEINFO_ALIGNMENT_INFORMATION interface */ struct { enum smb_fileinfo_level level; - union smb_file file; - + struct { + union smb_handle_or_path file; + } in; struct { uint32_t alignment_requirement; } out; @@ -683,8 +731,9 @@ union smb_fileinfo { /* RAW_FILEINFO_NETWORK_OPEN_INFORMATION interface */ struct { enum smb_fileinfo_level level; - union smb_file file; - + struct { + union smb_handle_or_path file; + } in; struct { NTTIME create_time; NTTIME access_time; @@ -700,8 +749,9 @@ union smb_fileinfo { /* RAW_FILEINFO_ATTRIBUTE_TAG_INFORMATION interface */ struct { enum smb_fileinfo_level level; - union smb_file file; - + struct { + union smb_handle_or_path file; + } in; struct { uint32_t attrib; uint32_t reparse_tag; @@ -711,8 +761,8 @@ union smb_fileinfo { /* RAW_FILEINFO_SEC_DESC */ struct { enum smb_fileinfo_level level; - union smb_file file; struct { + union smb_handle_or_path file; uint32_t secinfo_flags; } in; struct { @@ -756,15 +806,16 @@ union smb_setfileinfo { /* generic interface */ struct { enum smb_setfileinfo_level level; - - union smb_file file; + struct { + union smb_handle_or_path file; + } in; } generic; /* RAW_SFILEINFO_SETATTR (SMBsetatr) interface - only via setpathinfo() */ struct { enum smb_setfileinfo_level level; - union smb_file file; struct { + union smb_handle_or_path file; uint16_t attrib; time_t write_time; } in; @@ -774,8 +825,8 @@ union smb_setfileinfo { also RAW_SFILEINFO_STANDARD */ struct { enum smb_setfileinfo_level level; - union smb_file file; struct { + union smb_handle_or_path file; time_t create_time; time_t access_time; time_t write_time; @@ -787,8 +838,8 @@ union smb_setfileinfo { /* RAW_SFILEINFO_EA_SET interface */ struct { enum smb_setfileinfo_level level; - union smb_file file; struct { + union smb_handle_or_path file; uint_t num_eas; struct ea_struct *eas; } in; @@ -798,8 +849,8 @@ union smb_setfileinfo { RAW_SFILEINFO_BASIC_INFORMATION interfaces */ struct { enum smb_setfileinfo_level level; - union smb_file file; struct { + union smb_handle_or_path file; NTTIME create_time; NTTIME access_time; NTTIME write_time; @@ -812,8 +863,8 @@ union smb_setfileinfo { RAW_SFILEINFO_DISPOSITION_INFORMATION interfaces */ struct { enum smb_setfileinfo_level level; - union smb_file file; struct { + union smb_handle_or_path file; BOOL delete_on_close; } in; } disposition_info; @@ -822,8 +873,8 @@ union smb_setfileinfo { RAW_SFILEINFO_ALLOCATION_INFORMATION interfaces */ struct { enum smb_setfileinfo_level level; - union smb_file file; struct { + union smb_handle_or_path file; /* w2k3 rounds this up to nearest 4096 */ uint64_t alloc_size; } in; @@ -833,8 +884,8 @@ union smb_setfileinfo { RAW_SFILEINFO_END_OF_FILE_INFORMATION interfaces */ struct { enum smb_setfileinfo_level level; - union smb_file file; struct { + union smb_handle_or_path file; uint64_t size; } in; } end_of_file_info; @@ -842,8 +893,8 @@ union smb_setfileinfo { /* RAW_SFILEINFO_RENAME_INFORMATION interface */ struct { enum smb_setfileinfo_level level; - union smb_file file; - struct smb_rename_information { + struct { + union smb_handle_or_path file; uint8_t overwrite; uint32_t root_fid; const char *new_name; @@ -853,8 +904,8 @@ union smb_setfileinfo { /* RAW_SFILEINFO_POSITION_INFORMATION interface */ struct { enum smb_setfileinfo_level level; - union smb_file file; struct { + union smb_handle_or_path file; uint64_t position; } in; } position_information; @@ -862,8 +913,8 @@ union smb_setfileinfo { /* RAW_SFILEINFO_MODE_INFORMATION interface */ struct { enum smb_setfileinfo_level level; - union smb_file file; struct { + union smb_handle_or_path file; /* valid values seem to be 0, 2, 4 and 6 */ uint32_t mode; } in; @@ -874,8 +925,8 @@ union smb_setfileinfo { /* RAW_SFILEINFO_UNIX_BASIC interface */ struct { enum smb_setfileinfo_level level; - union smb_file file; struct { + union smb_handle_or_path file; uint32_t mode; /* yuck - this field remains to fix compile of libcli/clifile.c */ uint64_t end_of_file; uint64_t num_bytes; @@ -896,8 +947,8 @@ union smb_setfileinfo { /* RAW_SFILEINFO_UNIX_LINK, RAW_SFILEINFO_UNIX_HLINK interface */ struct { enum smb_setfileinfo_level level; - union smb_file file; struct { + union smb_handle_or_path file; const char *link_dest; } in; } unix_link, unix_hlink; @@ -905,8 +956,8 @@ union smb_setfileinfo { /* RAW_FILEINFO_SET_SEC_DESC */ struct { enum smb_setfileinfo_level level; - union smb_file file; struct { + union smb_handle_or_path file; uint32_t secinfo_flags; struct security_descriptor *sd; } in; @@ -1114,9 +1165,6 @@ union smb_open { /* SMBNTCreateX interface */ struct { enum smb_open_level level; - /* this is the output file handle */ - union smb_file file; - struct { uint32_t flags; uint32_t root_fid; @@ -1138,8 +1186,8 @@ union smb_open { struct security_descriptor *sec_desc; struct smb_ea_list *ea_list; } in; - struct { + union smb_handle file; uint8_t oplock_level; uint32_t create_action; NTTIME create_time; @@ -1158,9 +1206,6 @@ union smb_open { /* TRANS2_OPEN interface */ struct { enum smb_open_level level; - /* this is the output file handle */ - union smb_file file; - struct { uint16_t flags; uint16_t open_mode; @@ -1174,8 +1219,8 @@ union smb_open { uint_t num_eas; struct ea_struct *eas; } in; - struct { + union smb_handle file; uint16_t attrib; time_t write_time; uint32_t size; @@ -1190,16 +1235,13 @@ union smb_open { /* SMBopen interface */ struct { enum smb_open_level level; - /* this is the output file handle */ - union smb_file file; - struct { uint16_t open_mode; uint16_t search_attrs; const char *fname; } in; - struct { + union smb_handle file; uint16_t attrib; time_t write_time; uint32_t size; @@ -1210,9 +1252,6 @@ union smb_open { /* SMBopenX interface */ struct { enum smb_open_level level; - /* this is the output file handle */ - union smb_file file; - struct { uint16_t flags; uint16_t open_mode; @@ -1227,6 +1266,7 @@ union smb_open { const char *fname; } in; struct { + union smb_handle file; uint16_t attrib; time_t write_time; uint32_t size; @@ -1243,28 +1283,26 @@ union smb_open { /* SMBmknew interface */ struct { enum smb_open_level level; - /* this is the output file handle */ - union smb_file file; - struct { uint16_t attrib; time_t write_time; const char *fname; } in; + struct { + union smb_handle file; + } out; } mknew, create; /* SMBctemp interface */ struct { enum smb_open_level level; - /* this is the output file handle */ - union smb_file file; - struct { uint16_t attrib; time_t write_time; const char *directory; } in; struct { + union smb_handle file; /* temp name, relative to directory */ char *name; } out; @@ -1273,23 +1311,20 @@ union smb_open { /* SMBsplopen interface */ struct { enum smb_open_level level; - /* this is the output file handle */ - union smb_file file; - struct { uint16_t setup_length; uint16_t mode; const char *ident; } in; + struct { + union smb_handle file; + } out; } splopen; /* chained OpenX/ReadX interface */ struct { enum smb_open_level level; - /* this is the output file handle */ - union smb_file file; - struct { uint16_t flags; uint16_t open_mode; @@ -1310,6 +1345,7 @@ union smb_open { uint16_t remaining; } in; struct { + union smb_handle file; uint16_t attrib; time_t write_time; uint32_t size; @@ -1345,9 +1381,8 @@ union smb_read { /* SMBreadX (and generic) interface */ struct { enum smb_read_level level; - union smb_file file; - struct { + union smb_handle file; uint64_t offset; uint16_t mincnt; uint32_t maxcnt; @@ -1365,9 +1400,8 @@ union smb_read { /* SMBreadbraw interface */ struct { enum smb_read_level level; - union smb_file file; - struct { + union smb_handle file; uint64_t offset; uint16_t maxcnt; uint16_t mincnt; @@ -1383,9 +1417,8 @@ union smb_read { /* SMBlockandread interface */ struct { enum smb_read_level level; - union smb_file file; - struct { + union smb_handle file; uint16_t count; uint32_t offset; uint16_t remaining; @@ -1399,9 +1432,8 @@ union smb_read { /* SMBread interface */ struct { enum smb_read_level level; - union smb_file file; - struct { + union smb_handle file; uint16_t count; uint32_t offset; uint16_t remaining; @@ -1426,9 +1458,8 @@ union smb_write { /* SMBwriteX interface */ struct { enum smb_write_level level; - union smb_file file; - struct { + union smb_handle file; uint64_t offset; uint16_t wmode; uint16_t remaining; @@ -1444,9 +1475,8 @@ union smb_write { /* SMBwriteunlock interface */ struct { enum smb_write_level level; - union smb_file file; - struct { + union smb_handle file; uint16_t count; uint32_t offset; uint16_t remaining; @@ -1460,9 +1490,8 @@ union smb_write { /* SMBwrite interface */ struct { enum smb_write_level level; - union smb_file file; - struct { + union smb_handle file; uint16_t count; uint32_t offset; uint16_t remaining; @@ -1476,9 +1505,8 @@ union smb_write { /* SMBwriteclose interface */ struct { enum smb_write_level level; - union smb_file file; - struct { + union smb_handle file; uint16_t count; uint32_t offset; time_t mtime; @@ -1492,9 +1520,8 @@ union smb_write { /* SMBsplwrite interface */ struct { enum smb_write_level level; - union smb_file file; - struct { + union smb_handle file; uint16_t count; const uint8_t *data; } in; @@ -1513,9 +1540,8 @@ union smb_lock { /* SMBlockingX (and generic) interface */ struct { enum smb_lock_level level; - union smb_file file; - struct { + union smb_handle file; uint16_t mode; uint32_t timeout; uint16_t ulock_cnt; @@ -1531,9 +1557,8 @@ union smb_lock { /* SMBlock and SMBunlock interface */ struct { enum smb_lock_level level; - union smb_file file; - struct { + union smb_handle file; uint32_t count; uint32_t offset; } in; @@ -1552,9 +1577,8 @@ union smb_close { /* SMBclose (and generic) interface */ struct { enum smb_close_level level; - union smb_file file; - struct { + union smb_handle file; time_t write_time; } in; } close, generic; @@ -1562,7 +1586,9 @@ union smb_close { /* SMBsplclose interface - empty! */ struct { enum smb_close_level level; - union smb_file file; + struct { + union smb_handle file; + } in; } splclose; }; @@ -1611,15 +1637,16 @@ union smb_ioctl { /* generic interface */ struct { enum smb_ioctl_level level; - union smb_file file; - + struct { + union smb_handle file; + } in; } generic; /* struct for SMBioctl */ struct { enum smb_ioctl_level level; - union smb_file file; struct { + union smb_handle file; uint32_t request; } in; struct { @@ -1631,8 +1658,8 @@ union smb_ioctl { /* struct for NT ioctl call */ struct { enum smb_ioctl_level level; - union smb_file file; struct { + union smb_handle file; uint32_t function; BOOL fsctl; uint8_t filter; @@ -1646,7 +1673,9 @@ union smb_ioctl { /* struct for SMBflush */ union smb_flush { struct { - union smb_file file; + struct { + union smb_handle file; + } in; } flush; }; @@ -1714,8 +1743,8 @@ struct smb_nttrans { /* struct for nttrans change notify call */ union smb_notify { struct { - union smb_file file; struct { + union smb_handle file; uint32_t buffer_size; uint32_t completion_filter; BOOL recursive; diff --git a/source4/libcli/raw/rawacl.c b/source4/libcli/raw/rawacl.c index 7c0c17b4d7..59ac65a340 100644 --- a/source4/libcli/raw/rawacl.c +++ b/source4/libcli/raw/rawacl.c @@ -38,7 +38,7 @@ struct smbcli_request *smb_raw_query_secdesc_send(struct smbcli_tree *tree, nt.in.function = NT_TRANSACT_QUERY_SECURITY_DESC; nt.in.setup = NULL; - SSVAL(params, 0, io->query_secdesc.file.fnum); + SSVAL(params, 0, io->query_secdesc.in.file.fnum); SSVAL(params, 2, 0); /* padding */ SIVAL(params, 4, io->query_secdesc.in.secinfo_flags); @@ -123,7 +123,7 @@ struct smbcli_request *smb_raw_set_secdesc_send(struct smbcli_tree *tree, nt.in.function = NT_TRANSACT_SET_SECURITY_DESC; nt.in.setup = NULL; - SSVAL(params, 0, io->set_secdesc.file.fnum); + SSVAL(params, 0, io->set_secdesc.in.file.fnum); SSVAL(params, 2, 0); /* padding */ SIVAL(params, 4, io->set_secdesc.in.secinfo_flags); diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c index 0e63fa656f..6f8befebfe 100644 --- a/source4/libcli/raw/rawfile.c +++ b/source4/libcli/raw/rawfile.c @@ -234,7 +234,7 @@ static NTSTATUS smb_raw_nttrans_create_recv(struct smbcli_request *req, params = nt.out.params.data; parms->ntcreatex.out.oplock_level = CVAL(params, 0); - parms->ntcreatex.file.fnum = SVAL(params, 2); + parms->ntcreatex.out.file.fnum = SVAL(params, 2); parms->ntcreatex.out.create_action = IVAL(params, 4); parms->ntcreatex.out.create_time = smbcli_pull_nttime(params, 12); parms->ntcreatex.out.access_time = smbcli_pull_nttime(params, 20); @@ -406,7 +406,7 @@ static NTSTATUS smb_raw_t2open_recv(struct smbcli_request *req, TALLOC_CTX *mem_ return NT_STATUS_INFO_LENGTH_MISMATCH; } - parms->t2open.file.fnum = SVAL(t2.out.params.data, VWV(0)); + parms->t2open.out.file.fnum = SVAL(t2.out.params.data, VWV(0)); parms->t2open.out.attrib = SVAL(t2.out.params.data, VWV(1)); parms->t2open.out.write_time = raw_pull_dos_date3(transport, t2.out.params.data + VWV(2)); parms->t2open.out.size = IVAL(t2.out.params.data, VWV(4)); @@ -572,7 +572,7 @@ NTSTATUS smb_raw_open_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, unio case RAW_OPEN_OPEN: SMBCLI_CHECK_WCT(req, 7); - parms->openold.file.fnum = SVAL(req->in.vwv, VWV(0)); + parms->openold.out.file.fnum = SVAL(req->in.vwv, VWV(0)); parms->openold.out.attrib = SVAL(req->in.vwv, VWV(1)); parms->openold.out.write_time = raw_pull_dos_date3(req->transport, req->in.vwv + VWV(2)); @@ -582,7 +582,7 @@ NTSTATUS smb_raw_open_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, unio case RAW_OPEN_OPENX: SMBCLI_CHECK_MIN_WCT(req, 15); - parms->openx.file.fnum = SVAL(req->in.vwv, VWV(2)); + parms->openx.out.file.fnum = SVAL(req->in.vwv, VWV(2)); parms->openx.out.attrib = SVAL(req->in.vwv, VWV(3)); parms->openx.out.write_time = raw_pull_dos_date3(req->transport, req->in.vwv + VWV(4)); @@ -603,29 +603,29 @@ NTSTATUS smb_raw_open_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, unio case RAW_OPEN_MKNEW: SMBCLI_CHECK_WCT(req, 1); - parms->mknew.file.fnum = SVAL(req->in.vwv, VWV(0)); + parms->mknew.out.file.fnum = SVAL(req->in.vwv, VWV(0)); break; case RAW_OPEN_CREATE: SMBCLI_CHECK_WCT(req, 1); - parms->create.file.fnum = SVAL(req->in.vwv, VWV(0)); + parms->create.out.file.fnum = SVAL(req->in.vwv, VWV(0)); break; case RAW_OPEN_CTEMP: SMBCLI_CHECK_WCT(req, 1); - parms->ctemp.file.fnum = SVAL(req->in.vwv, VWV(0)); + parms->ctemp.out.file.fnum = SVAL(req->in.vwv, VWV(0)); smbcli_req_pull_string(req, mem_ctx, &parms->ctemp.out.name, req->in.data, -1, STR_TERMINATE | STR_ASCII); break; case RAW_OPEN_SPLOPEN: SMBCLI_CHECK_WCT(req, 1); - parms->splopen.file.fnum = SVAL(req->in.vwv, VWV(0)); + parms->splopen.out.file.fnum = SVAL(req->in.vwv, VWV(0)); break; case RAW_OPEN_NTCREATEX: SMBCLI_CHECK_MIN_WCT(req, 34); parms->ntcreatex.out.oplock_level = CVAL(req->in.vwv, 4); - parms->ntcreatex.file.fnum = SVAL(req->in.vwv, 5); + parms->ntcreatex.out.file.fnum = SVAL(req->in.vwv, 5); parms->ntcreatex.out.create_action = IVAL(req->in.vwv, 7); parms->ntcreatex.out.create_time = smbcli_pull_nttime(req->in.vwv, 11); parms->ntcreatex.out.access_time = smbcli_pull_nttime(req->in.vwv, 19); @@ -644,7 +644,7 @@ NTSTATUS smb_raw_open_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, unio case RAW_OPEN_OPENX_READX: SMBCLI_CHECK_MIN_WCT(req, 15); - parms->openxreadx.file.fnum = SVAL(req->in.vwv, VWV(2)); + parms->openxreadx.out.file.fnum = SVAL(req->in.vwv, VWV(2)); parms->openxreadx.out.attrib = SVAL(req->in.vwv, VWV(3)); parms->openxreadx.out.write_time = raw_pull_dos_date3(req->transport, req->in.vwv + VWV(4)); @@ -706,14 +706,14 @@ struct smbcli_request *smb_raw_close_send(struct smbcli_tree *tree, union smb_cl switch (parms->generic.level) { case RAW_CLOSE_CLOSE: SETUP_REQUEST(SMBclose, 3, 0); - SSVAL(req->out.vwv, VWV(0), parms->close.file.fnum); + SSVAL(req->out.vwv, VWV(0), parms->close.in.file.fnum); raw_push_dos_date3(tree->session->transport, req->out.vwv, VWV(1), parms->close.in.write_time); break; case RAW_CLOSE_SPLCLOSE: SETUP_REQUEST(SMBsplclose, 3, 0); - SSVAL(req->out.vwv, VWV(0), parms->splclose.file.fnum); + SSVAL(req->out.vwv, VWV(0), parms->splclose.in.file.fnum); SIVAL(req->out.vwv, VWV(1), 0); /* reserved */ break; } @@ -749,14 +749,14 @@ struct smbcli_request *smb_raw_lock_send(struct smbcli_tree *tree, union smb_loc switch (parms->generic.level) { case RAW_LOCK_LOCK: SETUP_REQUEST(SMBlock, 5, 0); - SSVAL(req->out.vwv, VWV(0), parms->lock.file.fnum); + SSVAL(req->out.vwv, VWV(0), parms->lock.in.file.fnum); SIVAL(req->out.vwv, VWV(1), parms->lock.in.count); SIVAL(req->out.vwv, VWV(3), parms->lock.in.offset); break; case RAW_LOCK_UNLOCK: SETUP_REQUEST(SMBunlock, 5, 0); - SSVAL(req->out.vwv, VWV(0), parms->unlock.file.fnum); + SSVAL(req->out.vwv, VWV(0), parms->unlock.in.file.fnum); SIVAL(req->out.vwv, VWV(1), parms->unlock.in.count); SIVAL(req->out.vwv, VWV(3), parms->unlock.in.offset); break; @@ -770,7 +770,7 @@ struct smbcli_request *smb_raw_lock_send(struct smbcli_tree *tree, union smb_loc SETUP_REQUEST(SMBlockingX, 8, lck_size * lock_count); SSVAL(req->out.vwv, VWV(0), SMB_CHAIN_NONE); SSVAL(req->out.vwv, VWV(1), 0); - SSVAL(req->out.vwv, VWV(2), parms->lockx.file.fnum); + SSVAL(req->out.vwv, VWV(2), parms->lockx.in.file.fnum); SSVAL(req->out.vwv, VWV(3), parms->lockx.in.mode); SIVAL(req->out.vwv, VWV(4), parms->lockx.in.timeout); SSVAL(req->out.vwv, VWV(6), parms->lockx.in.ulock_cnt); @@ -850,7 +850,7 @@ struct smbcli_request *smb_raw_flush_send(struct smbcli_tree *tree, union smb_fl struct smbcli_request *req; SETUP_REQUEST(SMBflush, 1, 0); - SSVAL(req->out.vwv, VWV(0), parms->flush.file.fnum); + SSVAL(req->out.vwv, VWV(0), parms->flush.in.file.fnum); if (!smbcli_request_send(req)) { smbcli_request_destroy(req); @@ -881,7 +881,7 @@ struct smbcli_request *smb_raw_seek_send(struct smbcli_tree *tree, SETUP_REQUEST(SMBlseek, 4, 0); - SSVAL(req->out.vwv, VWV(0), parms->lseek.file.fnum); + SSVAL(req->out.vwv, VWV(0), parms->lseek.in.file.fnum); SSVAL(req->out.vwv, VWV(1), parms->lseek.in.mode); SIVALS(req->out.vwv, VWV(2), parms->lseek.in.offset); diff --git a/source4/libcli/raw/rawfileinfo.c b/source4/libcli/raw/rawfileinfo.c index b50a330093..cf8f2f71b4 100644 --- a/source4/libcli/raw/rawfileinfo.c +++ b/source4/libcli/raw/rawfileinfo.c @@ -536,7 +536,7 @@ static struct smbcli_request *smb_raw_getattr_send(struct smbcli_tree *tree, req = smbcli_request_setup(tree, SMBgetatr, 0, 0); if (!req) return NULL; - smbcli_req_append_ascii4(req, parms->getattr.file.path, STR_TERMINATE); + smbcli_req_append_ascii4(req, parms->getattr.in.file.path, STR_TERMINATE); if (!smbcli_request_send(req)) { smbcli_request_destroy(req); @@ -579,7 +579,7 @@ static struct smbcli_request *smb_raw_getattrE_send(struct smbcli_tree *tree, req = smbcli_request_setup(tree, SMBgetattrE, 1, 0); if (!req) return NULL; - SSVAL(req->out.vwv, VWV(0), parms->getattre.file.fnum); + SSVAL(req->out.vwv, VWV(0), parms->getattre.in.file.fnum); if (!smbcli_request_send(req)) { smbcli_request_destroy(req); return NULL; @@ -647,7 +647,7 @@ struct smbcli_request *smb_raw_fileinfo_send(struct smbcli_tree *tree, } req = smb_raw_fileinfo_blob_send(tree, - parms->generic.file.fnum, + parms->generic.in.file.fnum, parms->generic.level, data); data_blob_free(&data); @@ -722,7 +722,7 @@ struct smbcli_request *smb_raw_pathinfo_send(struct smbcli_tree *tree, } } - req = smb_raw_pathinfo_blob_send(tree, parms->generic.file.path, + req = smb_raw_pathinfo_blob_send(tree, parms->generic.in.file.path, parms->generic.level, data); data_blob_free(&data); diff --git a/source4/libcli/raw/rawioctl.c b/source4/libcli/raw/rawioctl.c index 28b58ff2a3..db980a55d6 100644 --- a/source4/libcli/raw/rawioctl.c +++ b/source4/libcli/raw/rawioctl.c @@ -37,7 +37,7 @@ static struct smbcli_request *smb_raw_smbioctl_send(struct smbcli_tree *tree, SETUP_REQUEST(SMBioctl, 3, 0); - SSVAL(req->out.vwv, VWV(0), parms->ioctl.file.fnum); + SSVAL(req->out.vwv, VWV(0), parms->ioctl.in.file.fnum); SIVAL(req->out.vwv, VWV(1), parms->ioctl.in.request); if (!smbcli_request_send(req)) { @@ -81,7 +81,7 @@ static struct smbcli_request *smb_raw_ntioctl_send(struct smbcli_tree *tree, nt.in.setup_count = 4; nt.in.setup = setup; SIVAL(setup, 0, parms->ntioctl.in.function); - SSVAL(setup, 4, parms->ntioctl.file.fnum); + SSVAL(setup, 4, parms->ntioctl.in.file.fnum); SCVAL(setup, 6, parms->ntioctl.in.fsctl); SCVAL(setup, 7, parms->ntioctl.in.filter); nt.in.function = NT_TRANSACT_IOCTL; diff --git a/source4/libcli/raw/rawnotify.c b/source4/libcli/raw/rawnotify.c index 3adb1b000b..c06f0a59f7 100644 --- a/source4/libcli/raw/rawnotify.c +++ b/source4/libcli/raw/rawnotify.c @@ -36,7 +36,7 @@ struct smbcli_request *smb_raw_changenotify_send(struct smbcli_tree *tree, union nt.in.setup_count = 4; nt.in.setup = setup; SIVAL(setup, 0, parms->notify.in.completion_filter); - SSVAL(setup, 4, parms->notify.file.fnum); + SSVAL(setup, 4, parms->notify.in.file.fnum); SSVAL(setup, 6, parms->notify.in.recursive); nt.in.function = NT_TRANSACT_NOTIFY_CHANGE; nt.in.params = data_blob(NULL, 0); diff --git a/source4/libcli/raw/rawreadwrite.c b/source4/libcli/raw/rawreadwrite.c index c4e2ab2498..7f1aaf26d4 100644 --- a/source4/libcli/raw/rawreadwrite.c +++ b/source4/libcli/raw/rawreadwrite.c @@ -41,7 +41,7 @@ struct smbcli_request *smb_raw_read_send(struct smbcli_tree *tree, union smb_rea bigoffset = True; } SETUP_REQUEST(SMBreadbraw, bigoffset? 10:8, 0); - SSVAL(req->out.vwv, VWV(0), parms->readbraw.file.fnum); + SSVAL(req->out.vwv, VWV(0), parms->readbraw.in.file.fnum); SIVAL(req->out.vwv, VWV(1), parms->readbraw.in.offset); SSVAL(req->out.vwv, VWV(3), parms->readbraw.in.maxcnt); SSVAL(req->out.vwv, VWV(4), parms->readbraw.in.mincnt); @@ -54,7 +54,7 @@ struct smbcli_request *smb_raw_read_send(struct smbcli_tree *tree, union smb_rea case RAW_READ_LOCKREAD: SETUP_REQUEST(SMBlockread, 5, 0); - SSVAL(req->out.vwv, VWV(0), parms->lockread.file.fnum); + SSVAL(req->out.vwv, VWV(0), parms->lockread.in.file.fnum); SSVAL(req->out.vwv, VWV(1), parms->lockread.in.count); SIVAL(req->out.vwv, VWV(2), parms->lockread.in.offset); SSVAL(req->out.vwv, VWV(4), parms->lockread.in.remaining); @@ -62,7 +62,7 @@ struct smbcli_request *smb_raw_read_send(struct smbcli_tree *tree, union smb_rea case RAW_READ_READ: SETUP_REQUEST(SMBread, 5, 0); - SSVAL(req->out.vwv, VWV(0), parms->read.file.fnum); + SSVAL(req->out.vwv, VWV(0), parms->read.in.file.fnum); SSVAL(req->out.vwv, VWV(1), parms->read.in.count); SIVAL(req->out.vwv, VWV(2), parms->read.in.offset); SSVAL(req->out.vwv, VWV(4), parms->read.in.remaining); @@ -75,7 +75,7 @@ struct smbcli_request *smb_raw_read_send(struct smbcli_tree *tree, union smb_rea SETUP_REQUEST(SMBreadX, bigoffset ? 12 : 10, 0); SSVAL(req->out.vwv, VWV(0), SMB_CHAIN_NONE); SSVAL(req->out.vwv, VWV(1), 0); - SSVAL(req->out.vwv, VWV(2), parms->readx.file.fnum); + SSVAL(req->out.vwv, VWV(2), parms->readx.in.file.fnum); SIVAL(req->out.vwv, VWV(3), parms->readx.in.offset); SSVAL(req->out.vwv, VWV(5), parms->readx.in.maxcnt & 0xFFFF); SSVAL(req->out.vwv, VWV(6), parms->readx.in.mincnt); @@ -186,7 +186,7 @@ struct smbcli_request *smb_raw_write_send(struct smbcli_tree *tree, union smb_wr switch (parms->generic.level) { case RAW_WRITE_WRITEUNLOCK: SETUP_REQUEST(SMBwriteunlock, 5, 3 + parms->writeunlock.in.count); - SSVAL(req->out.vwv, VWV(0), parms->writeunlock.file.fnum); + SSVAL(req->out.vwv, VWV(0), parms->writeunlock.in.file.fnum); SSVAL(req->out.vwv, VWV(1), parms->writeunlock.in.count); SIVAL(req->out.vwv, VWV(2), parms->writeunlock.in.offset); SSVAL(req->out.vwv, VWV(4), parms->writeunlock.in.remaining); @@ -200,7 +200,7 @@ struct smbcli_request *smb_raw_write_send(struct smbcli_tree *tree, union smb_wr case RAW_WRITE_WRITE: SETUP_REQUEST(SMBwrite, 5, 3 + parms->write.in.count); - SSVAL(req->out.vwv, VWV(0), parms->write.file.fnum); + SSVAL(req->out.vwv, VWV(0), parms->write.in.file.fnum); SSVAL(req->out.vwv, VWV(1), parms->write.in.count); SIVAL(req->out.vwv, VWV(2), parms->write.in.offset); SSVAL(req->out.vwv, VWV(4), parms->write.in.remaining); @@ -213,7 +213,7 @@ struct smbcli_request *smb_raw_write_send(struct smbcli_tree *tree, union smb_wr case RAW_WRITE_WRITECLOSE: SETUP_REQUEST(SMBwriteclose, 6, 1 + parms->writeclose.in.count); - SSVAL(req->out.vwv, VWV(0), parms->writeclose.file.fnum); + SSVAL(req->out.vwv, VWV(0), parms->writeclose.in.file.fnum); SSVAL(req->out.vwv, VWV(1), parms->writeclose.in.count); SIVAL(req->out.vwv, VWV(2), parms->writeclose.in.offset); raw_push_dos_date3(tree->session->transport, @@ -232,7 +232,7 @@ struct smbcli_request *smb_raw_write_send(struct smbcli_tree *tree, union smb_wr SETUP_REQUEST(SMBwriteX, bigoffset ? 14 : 12, parms->writex.in.count); SSVAL(req->out.vwv, VWV(0), SMB_CHAIN_NONE); SSVAL(req->out.vwv, VWV(1), 0); - SSVAL(req->out.vwv, VWV(2), parms->writex.file.fnum); + SSVAL(req->out.vwv, VWV(2), parms->writex.in.file.fnum); SIVAL(req->out.vwv, VWV(3), parms->writex.in.offset); SIVAL(req->out.vwv, VWV(5), 0); /* reserved */ SSVAL(req->out.vwv, VWV(7), parms->writex.in.wmode); @@ -250,7 +250,7 @@ struct smbcli_request *smb_raw_write_send(struct smbcli_tree *tree, union smb_wr case RAW_WRITE_SPLWRITE: SETUP_REQUEST(SMBsplwr, 1, parms->splwrite.in.count); - SSVAL(req->out.vwv, VWV(0), parms->splwrite.file.fnum); + SSVAL(req->out.vwv, VWV(0), parms->splwrite.in.file.fnum); if (parms->splwrite.in.count > 0) { memcpy(req->out.data, parms->splwrite.in.data, parms->splwrite.in.count); } diff --git a/source4/libcli/raw/rawsetfileinfo.c b/source4/libcli/raw/rawsetfileinfo.c index 73fcd82802..46480c636e 100644 --- a/source4/libcli/raw/rawsetfileinfo.c +++ b/source4/libcli/raw/rawsetfileinfo.c @@ -283,7 +283,7 @@ static struct smbcli_request *smb_raw_setattr_send(struct smbcli_tree *tree, raw_push_dos_date3(tree->session->transport, req->out.vwv, VWV(1), parms->setattr.in.write_time); memset(req->out.vwv + VWV(3), 0, 10); /* reserved */ - smbcli_req_append_ascii4(req, parms->setattr.file.path, STR_TERMINATE); + smbcli_req_append_ascii4(req, parms->setattr.in.file.path, STR_TERMINATE); smbcli_req_append_ascii4(req, "", STR_TERMINATE); if (!smbcli_request_send(req)) { @@ -305,7 +305,7 @@ static struct smbcli_request *smb_raw_setattrE_send(struct smbcli_tree *tree, req = smbcli_request_setup(tree, SMBsetattrE, 7, 0); if (!req) return NULL; - SSVAL(req->out.vwv, VWV(0), parms->setattre.file.fnum); + SSVAL(req->out.vwv, VWV(0), parms->setattre.in.file.fnum); raw_push_dos_date2(tree->session->transport, req->out.vwv, VWV(1), parms->setattre.in.create_time); raw_push_dos_date2(tree->session->transport, @@ -352,7 +352,7 @@ struct smbcli_request *smb_raw_setfileinfo_send(struct smbcli_tree *tree, /* send request and process the output */ req = smb_raw_setfileinfo_blob_send(tree, mem_ctx, - parms->generic.file.fnum, + parms->generic.in.file.fnum, parms->generic.level, &blob); @@ -399,7 +399,7 @@ struct smbcli_request *smb_raw_setpathinfo_send(struct smbcli_tree *tree, /* send request and process the output */ req = smb_raw_setpathinfo_blob_send(tree, mem_ctx, - parms->generic.file.path, + parms->generic.in.file.path, parms->generic.level, &blob); -- cgit From add7ba54c1cbf0c2d3d6ef3230903a08522e8c33 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 14 Mar 2006 12:56:59 +0000 Subject: r14372: fix bug found by sparse metze (This used to be commit da1ac9b2243d0217c2d29879d885d62be9ddd290) --- source4/libcli/raw/clisocket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 4b1d70d8d2..0631d55a9c 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -242,7 +242,7 @@ struct smbcli_socket *smbcli_sock_connect_byname(const char *host, int port, status = resolve_name(&nbt_name, tmp_ctx, &address, event_ctx); if (!NT_STATUS_IS_OK(status)) { talloc_free(tmp_ctx); - return False; + return NULL; } status = smbcli_sock_connect(mem_ctx, address, port, name, event_ctx, -- cgit From f479571502750c2399103bbdd104966125ce3818 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 15 Mar 2006 02:41:57 +0000 Subject: r14413: don't do memcpy of length 0 (This used to be commit c43a7ec7ac3bcb3001d046615ca17a9ce083a2b0) --- source4/libcli/raw/rawtrans.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawtrans.c b/source4/libcli/raw/rawtrans.c index 207b5bee08..53e80d4753 100644 --- a/source4/libcli/raw/rawtrans.c +++ b/source4/libcli/raw/rawtrans.c @@ -340,7 +340,10 @@ struct smbcli_request *smb_raw_trans_send_backend(struct smbcli_tree *tree, SSVAL(req2->out.vwv,VWV(7), data_disp); SSVAL(req2->out.vwv,VWV(8), 0xFFFF); - memcpy(req2->out.data, parms->in.data.data + data_disp, data_length); + if (data_length != 0) { + memcpy(req2->out.data, parms->in.data.data + data_disp, + data_length); + } data_disp += data_length; -- cgit From 8528016978b084213ef53d66e1b6e831b1a01acc Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 16 Mar 2006 00:23:11 +0000 Subject: r14464: Don't include ndr_BASENAME.h files unless strictly required, instead try to include just the BASENAME.h files (containing only structs) (This used to be commit 3dd477ca5147f28a962b8437e2611a8222d706bd) --- source4/libcli/raw/clitransport.c | 1 + source4/libcli/raw/libcliraw.h | 2 +- source4/libcli/raw/rawacl.c | 1 + source4/libcli/raw/rawfile.c | 1 + source4/libcli/raw/rawfileinfo.c | 1 + 5 files changed, 5 insertions(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index df5c608d08..2ad155e9b9 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -26,6 +26,7 @@ #include "dlinklist.h" #include "lib/events/events.h" #include "lib/stream/packet.h" +#include "librpc/gen_ndr/ndr_nbt.h" /* diff --git a/source4/libcli/raw/libcliraw.h b/source4/libcli/raw/libcliraw.h index 96a06b9bec..f115a18d23 100644 --- a/source4/libcli/raw/libcliraw.h +++ b/source4/libcli/raw/libcliraw.h @@ -22,7 +22,7 @@ #include "libcli/raw/request.h" #include "smb.h" -#include "librpc/gen_ndr/ndr_nbt.h" +#include "librpc/gen_ndr/nbt.h" struct smbcli_tree; /* forward declare */ struct smbcli_request; /* forward declare */ diff --git a/source4/libcli/raw/rawacl.c b/source4/libcli/raw/rawacl.c index 59ac65a340..6f35b7f829 100644 --- a/source4/libcli/raw/rawacl.c +++ b/source4/libcli/raw/rawacl.c @@ -21,6 +21,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" +#include "librpc/gen_ndr/ndr_security.h" /**************************************************************************** fetch file ACL (async send) diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c index 6f8befebfe..d889b500fb 100644 --- a/source4/libcli/raw/rawfile.c +++ b/source4/libcli/raw/rawfile.c @@ -23,6 +23,7 @@ #include "includes.h" #include "smb.h" #include "libcli/raw/libcliraw.h" +#include "librpc/gen_ndr/ndr_security.h" #define SETUP_REQUEST(cmd, wct, buflen) do { \ req = smbcli_request_setup(tree, cmd, wct, buflen); \ diff --git a/source4/libcli/raw/rawfileinfo.c b/source4/libcli/raw/rawfileinfo.c index cf8f2f71b4..b33d0df828 100644 --- a/source4/libcli/raw/rawfileinfo.c +++ b/source4/libcli/raw/rawfileinfo.c @@ -21,6 +21,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" +#include "librpc/gen_ndr/ndr_security.h" /* local macros to make the code more readable */ #define FINFO_CHECK_MIN_SIZE(size) if (blob->length < (size)) { \ -- cgit From 5b0051e0325aea7e46715aa61bba0a1dc025132c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 17 Mar 2006 13:55:10 +0000 Subject: r14511: Install more headers (This used to be commit e1f896948fad8cf5a1aec300865c250c5721ee7d) --- source4/libcli/raw/interfaces.h | 6 ++++++ source4/libcli/raw/libcliraw.h | 7 ++++++- 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index 20b729caba..d662b9f5ae 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -19,6 +19,11 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#ifndef __LIBCLI_RAW_INTERFACES_H__ +#define __LIBCLI_RAW_INTERFACES_H__ + +#include "smb.h" + /* this structure is just a wrapper for a string, the only reason we bother with this is that it allows us to check the length provided on the wire in testsuite test code to ensure that we are @@ -2048,3 +2053,4 @@ union smb_search_close { } findclose; }; +#endif /* __LIBCLI_RAW_INTERFACES_H__ */ diff --git a/source4/libcli/raw/libcliraw.h b/source4/libcli/raw/libcliraw.h index f115a18d23..21d0b0dcdb 100644 --- a/source4/libcli/raw/libcliraw.h +++ b/source4/libcli/raw/libcliraw.h @@ -20,8 +20,10 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#ifndef __LIBCLI_RAW_H__ +#define __LIBCLI_RAW_H__ + #include "libcli/raw/request.h" -#include "smb.h" #include "librpc/gen_ndr/nbt.h" struct smbcli_tree; /* forward declare */ @@ -271,4 +273,7 @@ struct smbcli_request { goto failed; \ } +#include "libcli/raw/interfaces.h" #include "libcli/raw/raw_proto.h" + +#endif /* __LIBCLI_RAW__H__ */ -- cgit From 9225c02aee19478fc4825c4b798a6757d140b5c0 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 18 Mar 2006 09:07:47 +0000 Subject: r14539: get rid of a pointless union layer in struct smb_notify (This used to be commit 1e1c5593817e84c59c1a10b5a3c1957e363e5198) --- source4/libcli/raw/interfaces.h | 28 +++++++++++++--------------- source4/libcli/raw/rawnotify.c | 28 ++++++++++++++-------------- 2 files changed, 27 insertions(+), 29 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index d662b9f5ae..88daf304cf 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -1746,23 +1746,21 @@ struct smb_nttrans { /* struct for nttrans change notify call */ -union smb_notify { +struct smb_notify { struct { - struct { - union smb_handle file; - uint32_t buffer_size; - uint32_t completion_filter; - BOOL recursive; - } in; + union smb_handle file; + uint32_t buffer_size; + uint32_t completion_filter; + BOOL recursive; + } in; - struct { - uint32_t num_changes; - struct notify_changes { - uint32_t action; - struct smb_wire_string name; - } *changes; - } out; - } notify; + struct { + uint32_t num_changes; + struct notify_changes { + uint32_t action; + struct smb_wire_string name; + } *changes; + } out; }; enum smb_search_level {RAW_SEARCH_GENERIC = 0xF000, diff --git a/source4/libcli/raw/rawnotify.c b/source4/libcli/raw/rawnotify.c index c06f0a59f7..8ae5098c01 100644 --- a/source4/libcli/raw/rawnotify.c +++ b/source4/libcli/raw/rawnotify.c @@ -25,19 +25,19 @@ /**************************************************************************** change notify (async send) ****************************************************************************/ -struct smbcli_request *smb_raw_changenotify_send(struct smbcli_tree *tree, union smb_notify *parms) +struct smbcli_request *smb_raw_changenotify_send(struct smbcli_tree *tree, struct smb_notify *parms) { struct smb_nttrans nt; uint16_t setup[4]; nt.in.max_setup = 0; - nt.in.max_param = parms->notify.in.buffer_size; + nt.in.max_param = parms->in.buffer_size; nt.in.max_data = 0; nt.in.setup_count = 4; nt.in.setup = setup; - SIVAL(setup, 0, parms->notify.in.completion_filter); - SSVAL(setup, 4, parms->notify.in.file.fnum); - SSVAL(setup, 6, parms->notify.in.recursive); + SIVAL(setup, 0, parms->in.completion_filter); + SSVAL(setup, 4, parms->in.file.fnum); + SSVAL(setup, 6, parms->in.recursive); nt.in.function = NT_TRANSACT_NOTIFY_CHANGE; nt.in.params = data_blob(NULL, 0); nt.in.data = data_blob(NULL, 0); @@ -49,7 +49,7 @@ struct smbcli_request *smb_raw_changenotify_send(struct smbcli_tree *tree, union change notify (async recv) ****************************************************************************/ NTSTATUS smb_raw_changenotify_recv(struct smbcli_request *req, - TALLOC_CTX *mem_ctx, union smb_notify *parms) + TALLOC_CTX *mem_ctx, struct smb_notify *parms) { struct smb_nttrans nt; NTSTATUS status; @@ -61,28 +61,28 @@ NTSTATUS smb_raw_changenotify_recv(struct smbcli_request *req, return status; } - parms->notify.out.changes = NULL; - parms->notify.out.num_changes = 0; + parms->out.changes = NULL; + parms->out.num_changes = 0; /* count them */ for (ofs=0; nt.out.params.length - ofs > 12; ) { uint32_t next = IVAL(nt.out.params.data, ofs); - parms->notify.out.num_changes++; + parms->out.num_changes++; if (next == 0 || ofs + next >= nt.out.params.length) break; ofs += next; } /* allocate array */ - parms->notify.out.changes = talloc_array(mem_ctx, struct notify_changes, parms->notify.out.num_changes); - if (!parms->notify.out.changes) { + parms->out.changes = talloc_array(mem_ctx, struct notify_changes, parms->out.num_changes); + if (!parms->out.changes) { return NT_STATUS_NO_MEMORY; } - for (i=ofs=0; inotify.out.num_changes; i++) { - parms->notify.out.changes[i].action = IVAL(nt.out.params.data, ofs+4); + for (i=ofs=0; iout.num_changes; i++) { + parms->out.changes[i].action = IVAL(nt.out.params.data, ofs+4); smbcli_blob_pull_string(session, mem_ctx, &nt.out.params, - &parms->notify.out.changes[i].name, + &parms->out.changes[i].name, ofs+8, ofs+12, STR_UNICODE); ofs += IVAL(nt.out.params.data, ofs); } -- cgit From 35349a58df5b69446607fbd742a05f57f3515319 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 18 Mar 2006 15:42:57 +0000 Subject: r14542: Remove librpc, libndr and libnbt from includes.h (This used to be commit 51b4270513752d2eafbe77f9de598de16ef84a1f) --- source4/libcli/raw/libcliraw.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/libcliraw.h b/source4/libcli/raw/libcliraw.h index 21d0b0dcdb..2b856aa52b 100644 --- a/source4/libcli/raw/libcliraw.h +++ b/source4/libcli/raw/libcliraw.h @@ -31,6 +31,8 @@ struct smbcli_request; /* forward declare */ struct smbcli_session; /* forward declare */ struct smbcli_transport; /* forward declare */ +struct cli_credentials; + /* default timeout for all smb requests */ #define SMB_REQUEST_TIMEOUT 60 -- cgit From 508ba6026a0c958ac71762d36086742ec4825143 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sun, 2 Apr 2006 11:19:21 +0000 Subject: r14859: fix bugs noticed by the ibm code checker metze (This used to be commit afa8f944a7c572becd011b8c248eef13d7495ac7) --- source4/libcli/raw/rawrequest.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index b07a92e3fa..24390cd9e7 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -850,13 +850,17 @@ size_t smbcli_blob_pull_string(struct smbcli_session *session, int extra; dest->s = NULL; - /* this is here to cope with SMB2 calls using the SMB - parsers. SMB2 will pass smbcli_session==NULL, which forces - unicode on (as used by SMB2) */ - if (session == NULL && !(flags & STR_ASCII)) { - flags |= STR_UNICODE; + if (!(flags & STR_ASCII)) { + /* this is here to cope with SMB2 calls using the SMB + parsers. SMB2 will pass smbcli_session==NULL, which forces + unicode on (as used by SMB2) */ + if (session == NULL) { + flags |= STR_UNICODE; + } else if (session->transport->negotiate.capabilities & CAP_UNICODE) { + flags |= STR_UNICODE; + } } - + if (flags & STR_LEN8BIT) { if (len_offset > blob->length-1) { return 0; @@ -870,9 +874,7 @@ size_t smbcli_blob_pull_string(struct smbcli_session *session, } extra = 0; dest->s = NULL; - if (!(flags & STR_ASCII) && - ((flags & STR_UNICODE) || - (session->transport->negotiate.capabilities & CAP_UNICODE))) { + if (!(flags & STR_ASCII) && (flags & STR_UNICODE)) { int align = 0; if ((str_offset&1) && !(flags & STR_NOALIGN)) { align = 1; -- cgit From 7789fa412d3dcb70ed06fdccbda65f2a3eef06ee Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 8 Apr 2006 02:33:24 +0000 Subject: r14973: req cannot be NULL in smb_raw_t2open_recv() (found by IBM checker) (This used to be commit c2cde823ee004b53707acd1390d25fa9856b5179) --- source4/libcli/raw/rawfile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c index d889b500fb..2873011aa2 100644 --- a/source4/libcli/raw/rawfile.c +++ b/source4/libcli/raw/rawfile.c @@ -396,7 +396,7 @@ static struct smbcli_request *smb_raw_t2open_send(struct smbcli_tree *tree, ****************************************************************************/ static NTSTATUS smb_raw_t2open_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, union smb_open *parms) { - struct smbcli_transport *transport = req?req->transport:NULL; + struct smbcli_transport *transport = req->transport; struct smb_trans2 t2; NTSTATUS status; -- cgit From eae0b77a6e4ef80f7dd0749db5cfa15902e857ec Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 8 Apr 2006 02:35:00 +0000 Subject: r14974: work around an ibm checker bug (This used to be commit 2031e07a8a14d83ab621f8baaae6b4e1425667d7) --- source4/libcli/raw/rawioctl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawioctl.c b/source4/libcli/raw/rawioctl.c index db980a55d6..d4a299fe02 100644 --- a/source4/libcli/raw/rawioctl.c +++ b/source4/libcli/raw/rawioctl.c @@ -73,13 +73,13 @@ static struct smbcli_request *smb_raw_ntioctl_send(struct smbcli_tree *tree, union smb_ioctl *parms) { struct smb_nttrans nt; - uint16_t setup[4]; + uint8_t setup[8]; nt.in.max_setup = 0; nt.in.max_param = 0; nt.in.max_data = 0; nt.in.setup_count = 4; - nt.in.setup = setup; + nt.in.setup = (uint16_t *)setup; SIVAL(setup, 0, parms->ntioctl.in.function); SSVAL(setup, 4, parms->ntioctl.in.file.fnum); SCVAL(setup, 6, parms->ntioctl.in.fsctl); -- cgit From acc051674226d60a4d9739d883b2261ce98d651c Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 18 Apr 2006 13:05:24 +0000 Subject: r15121: fix pushing of the FLAGS2_READ_PERMIT_EXECUTE flag in the "readx.read_for_execute = True" case. metze (This used to be commit f30f9cd3285f75ac8cbbe8dc5a476fe6a714a2e3) --- source4/libcli/raw/rawreadwrite.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawreadwrite.c b/source4/libcli/raw/rawreadwrite.c index 7f1aaf26d4..7b424df6df 100644 --- a/source4/libcli/raw/rawreadwrite.c +++ b/source4/libcli/raw/rawreadwrite.c @@ -85,7 +85,9 @@ struct smbcli_request *smb_raw_read_send(struct smbcli_tree *tree, union smb_rea SIVAL(req->out.vwv, VWV(10),parms->readx.in.offset>>32); } if (parms->readx.in.read_for_execute) { - req->flags2 |= FLAGS2_READ_PERMIT_EXECUTE; + uint16_t flags2 = SVAL(req->out.hdr, HDR_FLG2); + flags2 |= FLAGS2_READ_PERMIT_EXECUTE; + SSVAL(req->out.hdr, HDR_FLG2, flags2); } break; } -- cgit From 0eddf14b307e905663b95296aa695a10d3fb90f7 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 24 Apr 2006 09:36:09 +0000 Subject: r15191: Avoid uint_t as it's not standard. (This used to be commit 7af59357b94e3819415b3a9257be0ced745ce130) --- source4/libcli/raw/raweas.c | 4 ++-- source4/libcli/raw/rawnotify.c | 2 +- source4/libcli/raw/rawrequest.c | 6 +++--- source4/libcli/raw/request.h | 8 ++++---- source4/libcli/raw/smb_signing.c | 2 +- 5 files changed, 11 insertions(+), 11 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/raweas.c b/source4/libcli/raw/raweas.c index 4c609aa593..26b04838d6 100644 --- a/source4/libcli/raw/raweas.c +++ b/source4/libcli/raw/raweas.c @@ -26,7 +26,7 @@ This assumes the names are strict ascii, which should be a reasonable assumption */ -uint_t ea_list_size(uint_t num_eas, struct ea_struct *eas) +size_t ea_list_size(uint_t num_eas, struct ea_struct *eas) { uint_t total = 4; int i; @@ -54,7 +54,7 @@ static uint_t ea_name_list_size(uint_t num_names, struct ea_name *eas) This assumes the names are strict ascii, which should be a reasonable assumption */ -uint_t ea_list_size_chained(uint_t num_eas, struct ea_struct *eas) +size_t ea_list_size_chained(uint_t num_eas, struct ea_struct *eas) { uint_t total = 0; int i; diff --git a/source4/libcli/raw/rawnotify.c b/source4/libcli/raw/rawnotify.c index 8ae5098c01..f4d4164016 100644 --- a/source4/libcli/raw/rawnotify.c +++ b/source4/libcli/raw/rawnotify.c @@ -96,7 +96,7 @@ NTSTATUS smb_raw_changenotify_recv(struct smbcli_request *req, we need to do find out to what request the reply belongs ****************************************************************************/ struct smbcli_request *smbcli_handle_ntcancel_reply(struct smbcli_request *req, - uint_t len, const uint8_t *hdr) + size_t len, const uint8_t *hdr) { struct smbcli_request *ntcancel; diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 24390cd9e7..f042c7b581 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -64,7 +64,7 @@ NTSTATUS smbcli_request_destroy(struct smbcli_request *req) low-level function to setup a request buffer for a non-SMB packet at the transport level */ -struct smbcli_request *smbcli_request_setup_nonsmb(struct smbcli_transport *transport, uint_t size) +struct smbcli_request *smbcli_request_setup_nonsmb(struct smbcli_transport *transport, size_t size) { struct smbcli_request *req; @@ -147,7 +147,7 @@ struct smbcli_request *smbcli_request_setup_transport(struct smbcli_transport *t way. This interface is used before a session is setup. */ struct smbcli_request *smbcli_request_setup_session(struct smbcli_session *session, - uint8_t command, uint_t wct, uint_t buflen) + uint8_t command, uint_t wct, size_t buflen) { struct smbcli_request *req; @@ -254,7 +254,7 @@ static void smbcli_req_grow_data(struct smbcli_request *req, uint_t new_size) */ NTSTATUS smbcli_chained_request_setup(struct smbcli_request *req, uint8_t command, - uint_t wct, uint_t buflen) + uint_t wct, size_t buflen) { uint_t new_size = 1 + (wct*2) + 2 + buflen; diff --git a/source4/libcli/raw/request.h b/source4/libcli/raw/request.h index 4a569cfe66..fedebf4c8d 100644 --- a/source4/libcli/raw/request.h +++ b/source4/libcli/raw/request.h @@ -32,12 +32,12 @@ struct request_buffer { uint8_t *buffer; /* the size of the raw buffer, including 4 byte header */ - uint_t size; + size_t size; /* how much has been allocated - on reply the buffer is over-allocated to prevent too many realloc() calls */ - uint_t allocated; + size_t allocated; /* the start of the SMB header - this is always buffer+4 */ uint8_t *hdr; @@ -45,11 +45,11 @@ struct request_buffer { /* the command words and command word count. vwv points into the raw buffer */ uint8_t *vwv; - uint_t wct; + size_t wct; /* the data buffer and size. data points into the raw buffer */ uint8_t *data; - uint_t data_size; + size_t data_size; /* ptr is used as a moving pointer into the data area * of the packet. The reason its here and not a local diff --git a/source4/libcli/raw/smb_signing.c b/source4/libcli/raw/smb_signing.c index a73db78f7b..541fd1fb8c 100644 --- a/source4/libcli/raw/smb_signing.c +++ b/source4/libcli/raw/smb_signing.c @@ -101,7 +101,7 @@ BOOL signing_good(struct smb_signing_context *sign_info, return True; } -void sign_outgoing_message(struct request_buffer *out, DATA_BLOB *mac_key, uint_t seq_num) +void sign_outgoing_message(struct request_buffer *out, DATA_BLOB *mac_key, unsigned int seq_num) { uint8_t calc_md5_mac[16]; struct MD5Context md5_ctx; -- cgit From 20b3b0f2e316f1689ea30e1901d97bdf86a71fa0 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 30 Apr 2006 00:00:28 +0000 Subject: r15338: Fix build of most things with shared libs enabled. (This used to be commit 8985093d3fba90287bd739aaaa0fbfdadca2b999) --- source4/libcli/raw/clioplock.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clioplock.c b/source4/libcli/raw/clioplock.c index f26aa0c5f2..f004532b26 100644 --- a/source4/libcli/raw/clioplock.c +++ b/source4/libcli/raw/clioplock.c @@ -24,7 +24,7 @@ /**************************************************************************** send an ack for an oplock break request ****************************************************************************/ -BOOL smbcli_oplock_ack(struct smbcli_tree *tree, uint16_t fnum, uint16_t ack_level) +_PUBLIC_ BOOL smbcli_oplock_ack(struct smbcli_tree *tree, uint16_t fnum, uint16_t ack_level) { BOOL ret; struct smbcli_request *req; @@ -53,7 +53,7 @@ BOOL smbcli_oplock_ack(struct smbcli_tree *tree, uint16_t fnum, uint16_t ack_lev /**************************************************************************** set the oplock handler for a connection ****************************************************************************/ -void smbcli_oplock_handler(struct smbcli_transport *transport, +_PUBLIC_ void smbcli_oplock_handler(struct smbcli_transport *transport, BOOL (*handler)(struct smbcli_transport *, uint16_t, uint16_t, uint8_t, void *), void *private) { -- cgit From 5c3a1d76ffc7b9e41846f7eaf6039f58184737a0 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 1 May 2006 18:11:15 +0000 Subject: r15379: Fix shared library build's unresolved dependencies (This used to be commit 0fafa2e59566f8f892d7dfd7dd33d0100b96a780) --- source4/libcli/raw/rawioctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawioctl.c b/source4/libcli/raw/rawioctl.c index d4a299fe02..49237fe9da 100644 --- a/source4/libcli/raw/rawioctl.c +++ b/source4/libcli/raw/rawioctl.c @@ -147,7 +147,7 @@ NTSTATUS smb_raw_ioctl_recv(struct smbcli_request *req, /* send a raw ioctl - sync interface */ -NTSTATUS smb_raw_ioctl(struct smbcli_tree *tree, +_PUBLIC_ NTSTATUS smb_raw_ioctl(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_ioctl *parms) { struct smbcli_request *req; -- cgit From c3958aa23112ba7ad1663e798d5226d1167639fe Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sun, 7 May 2006 20:53:45 +0000 Subject: r15505: - add 'generic' alias to smb_seek and smb_flush - add struct ntvfs_handle pointer to smb_file, this will later be used by the ntvfs backends metze (This used to be commit 8322fc70adbb951ad72b97dfcc91467c1d906afe) --- source4/libcli/raw/interfaces.h | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index 88daf304cf..f715c10e11 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -52,6 +52,8 @@ struct smb2_handle { uint64_t data[2]; }; +struct ntvfs_handle; + /* * a generic container for file handles or file pathes * for qfileinfo/setfileinfo and qpathinfo/setpathinfo @@ -72,18 +74,17 @@ union smb_handle_or_path { * this is used as file handle in SMB2 */ struct smb2_handle handle; + + /* + * this is used as generic file handle for the NTVFS layer + */ + struct ntvfs_handle *ntvfs; }; /* a generic container for file handles */ union smb_handle { - /* - * this is used for - * the qpathinfo and setpathinfo - * calls - */ - const char *path; /* * this is used as file handle in SMB */ @@ -93,6 +94,11 @@ union smb_handle { * this is used as file handle in SMB2 */ struct smb2_handle handle; + + /* + * this is used as generic file handle for the NTVFS layer + */ + struct ntvfs_handle *ntvfs; }; /* @@ -111,7 +117,7 @@ union smb_seek { struct { int32_t offset; } out; - } lseek; + } lseek, generic; }; /* struct used in unlink() call */ @@ -1681,7 +1687,7 @@ union smb_flush { struct { union smb_handle file; } in; - } flush; + } flush, generic; }; -- cgit From bb58d8497abe7178677c58e9dae307c44babbcef Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 16 May 2006 16:28:36 +0000 Subject: r15638: add a usefull macro to get a pointer the smb_handle union of smb_open, as it's not nicely alligned for all levels, If someone has an idea for a better solution where we can access it via op->generic.out.file.* please let me know:-) metze (This used to be commit d0a7408280c35dc4a5a21cbbded895c6c83819e6) --- source4/libcli/raw/interfaces.h | 44 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index f715c10e11..d9387cc6e2 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -1173,6 +1173,48 @@ enum smb_open_level { /* union for open() backend call */ union smb_open { +/* + * because the *.out.file structs are not aligned to the same offset for each level + * we provide a hepler macro that should be used to find the current smb_handle structure + */ +#define SMB_OPEN_OUT_FILE(op, file) do { \ + switch (op->generic.level) { \ + case RAW_OPEN_OPEN: \ + file = &op->openold.out.file; \ + break; \ + case RAW_OPEN_OPENX: \ + file = &op->openx.out.file; \ + break; \ + case RAW_OPEN_MKNEW: \ + file = &op->mknew.out.file; \ + break; \ + case RAW_OPEN_CREATE: \ + file = &op->create.out.file; \ + break; \ + case RAW_OPEN_CTEMP: \ + file = &op->ctemp.out.file; \ + break; \ + case RAW_OPEN_SPLOPEN: \ + file = &op->splopen.out.file; \ + break; \ + case RAW_OPEN_NTCREATEX: \ + file = &op->ntcreatex.out.file; \ + break; \ + case RAW_OPEN_T2OPEN: \ + file = &op->t2open.out.file; \ + break; \ + case RAW_OPEN_NTTRANS_CREATE: \ + file = &op->nttrans.out.file; \ + break; \ + case RAW_OPEN_OPENX_READX: \ + file = &op->openxreadx.out.file; \ + break; \ + default: \ + /* this must be a programmer error */ \ + file = NULL; \ + break; \ + } \ +} while (0) /* SMBNTCreateX interface */ struct { enum smb_open_level level; @@ -1212,7 +1254,7 @@ union smb_open { uint16_t ipc_state; uint8_t is_directory; } out; - } ntcreatex, generic; + } ntcreatex, nttrans, generic; /* TRANS2_OPEN interface */ struct { -- cgit From 410fb90322cf47780a9af4f5e38e57fcfa528471 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 16 May 2006 16:50:50 +0000 Subject: r15640: - NT IOCTL calls also have an 'in' data_blob - fix the receive code of NT IOCTL's we only need the NTTRANS data payload not the SMB payload here metze (This used to be commit 358d03143f0a78344c1af720e33ebe2619df09df) --- source4/libcli/raw/interfaces.h | 1 + source4/libcli/raw/rawioctl.c | 23 ++++++++++++++++------- 2 files changed, 17 insertions(+), 7 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index d9387cc6e2..e0696b45ec 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -1716,6 +1716,7 @@ union smb_ioctl { uint32_t function; BOOL fsctl; uint8_t filter; + DATA_BLOB blob; } in; struct { DATA_BLOB blob; diff --git a/source4/libcli/raw/rawioctl.c b/source4/libcli/raw/rawioctl.c index 49237fe9da..77c8c80158 100644 --- a/source4/libcli/raw/rawioctl.c +++ b/source4/libcli/raw/rawioctl.c @@ -86,7 +86,7 @@ static struct smbcli_request *smb_raw_ntioctl_send(struct smbcli_tree *tree, SCVAL(setup, 7, parms->ntioctl.in.filter); nt.in.function = NT_TRANSACT_IOCTL; nt.in.params = data_blob(NULL, 0); - nt.in.data = data_blob(NULL, 0); + nt.in.data = parms->ntioctl.in.blob; return smb_raw_nttrans_send(tree, &nt); } @@ -98,13 +98,22 @@ static NTSTATUS smb_raw_ntioctl_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, union smb_ioctl *parms) { - if (!smbcli_request_receive(req) || - smbcli_request_is_error(req)) { - return smbcli_request_destroy(req); - } + NTSTATUS status; + struct smb_nttrans nt; + TALLOC_CTX *tmp_mem; - parms->ntioctl.out.blob = smbcli_req_pull_blob(req, mem_ctx, req->in.data, -1); - return smbcli_request_destroy(req); + tmp_mem = talloc_new(mem_ctx); + NT_STATUS_HAVE_NO_MEMORY(tmp_mem); + + status = smb_raw_nttrans_recv(req, tmp_mem, &nt); + if (!NT_STATUS_IS_OK(status)) goto fail; + + parms->ntioctl.out.blob = nt.out.data; + talloc_steal(mem_ctx, parms->ntioctl.out.blob.data); + +fail: + talloc_free(tmp_mem); + return status; } -- cgit From 7e7a760b4b89db9db3afd6b292c99914c7c768f3 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 16 May 2006 16:59:08 +0000 Subject: r15643: add some FSCTL_ codes metze (This used to be commit 47dc1ed25323e76b93d9cef2a389726734d2e735) --- source4/libcli/raw/ioctl.h | 37 ++++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/ioctl.h b/source4/libcli/raw/ioctl.h index cd658c121b..2f0886e43e 100644 --- a/source4/libcli/raw/ioctl.h +++ b/source4/libcli/raw/ioctl.h @@ -25,9 +25,36 @@ /* filesystem control codes */ -#define FSCTL_FILESYSTEM 0x90000 -#define FSCTL_SET_SPARSE (FSCTL_FILESYSTEM | (49<<2)) -#define FSCTL_REQUEST_BATCH_OPLOCK (FSCTL_FILESYSTEM | (2<<2)) +#define FSCTL_METHOD_BUFFERED 0x00000000 +#define FSCTL_METHOD_IN_DIRECT 0x00000001 +#define FSCTL_METHOD_OUT_DIRECT 0x00000002 +#define FSCTL_METHOD_NEITHER 0x00000003 -#define FSCTL_NAMED_PIPE 0x110000 -#define FSCTL_NAMED_PIPE_READ_WRITE (FSCTL_NAMED_PIPE | 0xc017) +#define FSCTL_ACCESS_ANY 0x00000000 +#define FSCTL_ACCESS_READ 0x00004000 +#define FSCTL_ACCESS_WRITE 0x00008000 + +#define FSCTL_FILESYSTEM 0x00090000 +#define FSCTL_REQUEST_OPLOCK_LEVEL_1 (FSCTL_FILESYSTEM | FSCTL_ACCESS_ANY | 0x0000 | FSCTL_METHOD_BUFFERED) +#define FSCTL_REQUEST_OPLOCK_LEVEL_2 (FSCTL_FILESYSTEM | FSCTL_ACCESS_ANY | 0x0004 | FSCTL_METHOD_BUFFERED) +#define FSCTL_REQUEST_BATCH_OPLOCK (FSCTL_FILESYSTEM | FSCTL_ACCESS_ANY | 0x0008 | FSCTL_METHOD_BUFFERED) +#define FSCTL_OPLOCK_BREAK_ACKNOWLEDGE (FSCTL_FILESYSTEM | FSCTL_ACCESS_ANY | 0x000C | FSCTL_METHOD_BUFFERED) +#define FSCTL_OPBATCH_ACK_CLOSE_PENDING (FSCTL_FILESYSTEM | FSCTL_ACCESS_ANY | 0x0010 | FSCTL_METHOD_BUFFERED) +#define FSCTL_OPLOCK_BREAK_NOTIFY (FSCTL_FILESYSTEM | FSCTL_ACCESS_ANY | 0x0014 | FSCTL_METHOD_BUFFERED) +#define FSCTL_FILESYS_GET_STATISTICS (FSCTL_FILESYSTEM | FSCTL_ACCESS_ANY | 0x0060 | FSCTL_METHOD_BUFFERED) +#define FSCTL_GET_NTFS_VOLUME_DATA (FSCTL_FILESYSTEM | FSCTL_ACCESS_ANY | 0x0064 | FSCTL_METHOD_BUFFERED) +#define FSCTL_FIND_FILES_BY_SID (FSCTL_FILESYSTEM | FSCTL_ACCESS_ANY | 0x008C | FSCTL_METHOD_NEITHER) +#define FSCTL_SET_OBJECT_ID (FSCTL_FILESYSTEM | FSCTL_ACCESS_ANY | 0x0098 | FSCTL_METHOD_BUFFERED) +#define FSCTL_GET_OBJECT_ID (FSCTL_FILESYSTEM | FSCTL_ACCESS_ANY | 0x009C | FSCTL_METHOD_BUFFERED) +#define FSCTL_DELETE_OBJECT_ID (FSCTL_FILESYSTEM | FSCTL_ACCESS_ANY | 0x00A0 | FSCTL_METHOD_BUFFERED) +#define FSCTL_SET_REPARSE_POINT (FSCTL_FILESYSTEM | FSCTL_ACCESS_ANY | 0x00A4 | FSCTL_METHOD_BUFFERED) +#define FSCTL_GET_REPARSE_POINT (FSCTL_FILESYSTEM | FSCTL_ACCESS_ANY | 0x00A8 | FSCTL_METHOD_BUFFERED) +#define FSCTL_DELETE_REPARSE_POINT (FSCTL_FILESYSTEM | FSCTL_ACCESS_ANY | 0x00AC | FSCTL_METHOD_BUFFERED) +#define FSCTL_CREATE_OR_GET_OBJECT_ID (FSCTL_FILESYSTEM | FSCTL_ACCESS_ANY | 0x00C0 | FSCTL_METHOD_BUFFERED) +#define FSCTL_SET_SPARSE (FSCTL_FILESYSTEM | FSCTL_ACCESS_ANY | 0x00C4 | FSCTL_METHOD_BUFFERED) + +#define FSCTL_NAMED_PIPE 0x00110000 +#define FSCTL_NAMED_PIPE_READ_WRITE (FSCTL_NAMED_PIPE | FSCTL_ACCESS_ANY | 0xC014 | FSCTL_METHOD_NEITHER) + +#define FSCTL_NETWORK_FILESYSTEM 0x00140000 +#define FSCTL_GET_SHADOW_COPY_DATA (FSCTL_NETWORK_FILESYSTEM | FSCTL_ACCESS_READ | 0x0064 | FSCTL_METHOD_BUFFERED) -- cgit From 5ff4b74df3f32192c9828233295d9f8fedcceb23 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 17 May 2006 09:52:14 +0000 Subject: r15656: for NT IOCTL's we need to control the max_data field for some calls metze (This used to be commit 3cab02f6f513cf7eb3d8863e62952766bb4d908f) --- source4/libcli/raw/interfaces.h | 1 + source4/libcli/raw/rawioctl.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index e0696b45ec..d98b5de370 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -1716,6 +1716,7 @@ union smb_ioctl { uint32_t function; BOOL fsctl; uint8_t filter; + uint32_t max_data; DATA_BLOB blob; } in; struct { diff --git a/source4/libcli/raw/rawioctl.c b/source4/libcli/raw/rawioctl.c index 77c8c80158..356852edd8 100644 --- a/source4/libcli/raw/rawioctl.c +++ b/source4/libcli/raw/rawioctl.c @@ -77,7 +77,7 @@ static struct smbcli_request *smb_raw_ntioctl_send(struct smbcli_tree *tree, nt.in.max_setup = 0; nt.in.max_param = 0; - nt.in.max_data = 0; + nt.in.max_data = parms->ntioctl.in.max_data; nt.in.setup_count = 4; nt.in.setup = (uint16_t *)setup; SIVAL(setup, 0, parms->ntioctl.in.function); -- cgit From c18cd54bad426d8d83af1e320bd2bf499d8d6089 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 18 May 2006 11:15:18 +0000 Subject: r15688: windows sends 4 as max_setup count on NT IOCTL metze (This used to be commit 0d983fa46fff588cf94e58732e36e324e2f0478a) --- source4/libcli/raw/rawioctl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawioctl.c b/source4/libcli/raw/rawioctl.c index 356852edd8..af48fcb566 100644 --- a/source4/libcli/raw/rawioctl.c +++ b/source4/libcli/raw/rawioctl.c @@ -75,7 +75,7 @@ static struct smbcli_request *smb_raw_ntioctl_send(struct smbcli_tree *tree, struct smb_nttrans nt; uint8_t setup[8]; - nt.in.max_setup = 0; + nt.in.max_setup = 4; nt.in.max_param = 0; nt.in.max_data = parms->ntioctl.in.max_data; nt.in.setup_count = 4; -- cgit From 7f0e17e9030ad734977f66c2cc27faec501154a2 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 19 May 2006 15:10:39 +0000 Subject: r15718: - split the SMBflush with the 0xFFFF wildcard fnum into a different level metze (This used to be commit 95bf41b4d4ec96349802955e364fe44ef85f9077) --- source4/libcli/raw/interfaces.h | 7 +++++++ source4/libcli/raw/rawfile.c | 12 +++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index d98b5de370..84f897172e 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -1725,13 +1725,20 @@ union smb_ioctl { } ntioctl; }; +enum smb_flush_level {RAW_FLUSH_FLUSH, RAW_FLUSH_ALL}; + /* struct for SMBflush */ union smb_flush { struct { + enum smb_ioctl_level level; struct { union smb_handle file; } in; } flush, generic; + + struct { + enum smb_ioctl_level level; + } flush_all; }; diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c index 2873011aa2..fb3035c0a8 100644 --- a/source4/libcli/raw/rawfile.c +++ b/source4/libcli/raw/rawfile.c @@ -849,9 +849,19 @@ NTSTATUS smb_raw_chkpath(struct smbcli_tree *tree, union smb_chkpath *parms) struct smbcli_request *smb_raw_flush_send(struct smbcli_tree *tree, union smb_flush *parms) { struct smbcli_request *req; + uint16_t fnum; + + switch (parms->generic.level) { + case RAW_FLUSH_FLUSH: + fnum = parms->flush.in.file.fnum; + break; + case RAW_FLUSH_ALL: + fnum = 0xFFFF; + break; + } SETUP_REQUEST(SMBflush, 1, 0); - SSVAL(req->out.vwv, VWV(0), parms->flush.in.file.fnum); + SSVAL(req->out.vwv, VWV(0), fnum); if (!smbcli_request_send(req)) { smbcli_request_destroy(req); -- cgit From b77eaaa3bc7cd27320496440deda8a6ca62f7f5a Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sat, 20 May 2006 09:38:59 +0000 Subject: r15737: fix a typos and comment metze (This used to be commit 1f50b2e0534ee25861b6812b64d91f63cbb118ad) --- source4/libcli/raw/interfaces.h | 4 ++-- source4/libcli/raw/rawfile.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index 84f897172e..588237acb0 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -1730,14 +1730,14 @@ enum smb_flush_level {RAW_FLUSH_FLUSH, RAW_FLUSH_ALL}; /* struct for SMBflush */ union smb_flush { struct { - enum smb_ioctl_level level; + enum smb_flush_level level; struct { union smb_handle file; } in; } flush, generic; struct { - enum smb_ioctl_level level; + enum smb_flush_level level; } flush_all; }; diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c index fb3035c0a8..faa2cdbeb4 100644 --- a/source4/libcli/raw/rawfile.c +++ b/source4/libcli/raw/rawfile.c @@ -844,7 +844,7 @@ NTSTATUS smb_raw_chkpath(struct smbcli_tree *tree, union smb_chkpath *parms) /**************************************************************************** flush a file - async send - a flush to fnum 0xFFFF will flush all files + a flush with RAW_FLUSH_ALL will flush all files ****************************************************************************/ struct smbcli_request *smb_raw_flush_send(struct smbcli_tree *tree, union smb_flush *parms) { -- cgit From 2de1d5f7a8c2a3a815d81c217c274d2d5f1768cb Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sat, 20 May 2006 10:40:10 +0000 Subject: r15740: add TODO, that we should check if the server supports large offsets, before sending large offset requests metze (This used to be commit b9ba2b8c5a314ba9e559e50bea4deb692dc0f3ec) --- source4/libcli/raw/rawreadwrite.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawreadwrite.c b/source4/libcli/raw/rawreadwrite.c index 7b424df6df..63a60ad545 100644 --- a/source4/libcli/raw/rawreadwrite.c +++ b/source4/libcli/raw/rawreadwrite.c @@ -81,6 +81,10 @@ struct smbcli_request *smb_raw_read_send(struct smbcli_tree *tree, union smb_rea SSVAL(req->out.vwv, VWV(6), parms->readx.in.mincnt); SIVAL(req->out.vwv, VWV(7), parms->readx.in.maxcnt >> 16); SSVAL(req->out.vwv, VWV(9), parms->readx.in.remaining); + /* + * TODO: give an error when the offset is 64 bit + * and the server doesn't support it + */ if (bigoffset) { SIVAL(req->out.vwv, VWV(10),parms->readx.in.offset>>32); } -- cgit From e306c5bf129a981693bd251d45597f1e584ee850 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sat, 20 May 2006 10:46:38 +0000 Subject: r15741: move smb2 request structures into the main smb request structs as new levels metze (This used to be commit 91806353174704857dfcc15a730af7232cfde660) --- source4/libcli/raw/clisession.c | 7 + source4/libcli/raw/clitree.c | 7 + source4/libcli/raw/interfaces.h | 364 ++++++++++++++++++++++++++++++++++++-- source4/libcli/raw/rawfile.c | 10 ++ source4/libcli/raw/rawioctl.c | 6 + source4/libcli/raw/rawreadwrite.c | 13 ++ source4/libcli/raw/rawsearch.c | 1 + 7 files changed, 390 insertions(+), 18 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index 2942279b12..9e114aece8 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -137,6 +137,9 @@ struct smbcli_request *smb_raw_sesssetup_send(struct smbcli_session *session, smbcli_req_append_string(req, parms->spnego.in.lanman, STR_TERMINATE); smbcli_req_append_string(req, parms->spnego.in.workgroup, STR_TERMINATE); break; + + case RAW_SESSSETUP_SMB2: + return NULL; } if (!smbcli_request_send(req)) { @@ -213,6 +216,10 @@ NTSTATUS smb_raw_sesssetup_recv(struct smbcli_request *req, p += smbcli_req_pull_string(req, mem_ctx, &parms->spnego.out.lanman, p, -1, STR_TERMINATE); p += smbcli_req_pull_string(req, mem_ctx, &parms->spnego.out.workgroup, p, -1, STR_TERMINATE); break; + + case RAW_SESSSETUP_SMB2: + req->status = NT_STATUS_INTERNAL_ERROR; + break; } failed: diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index 6e120ed615..51f2e12457 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -79,6 +79,9 @@ struct smbcli_request *smb_raw_tcon_send(struct smbcli_tree *tree, smbcli_req_append_string(req, parms->tconx.in.path, STR_TERMINATE | STR_UPPER); smbcli_req_append_string(req, parms->tconx.in.device, STR_TERMINATE | STR_ASCII); break; + + case RAW_TCON_SMB2: + return NULL; } if (!smbcli_request_send(req)) { @@ -125,6 +128,10 @@ NTSTATUS smb_raw_tcon_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, p += smbcli_req_pull_string(req, mem_ctx, &parms->tconx.out.fs_type, p, -1, STR_TERMINATE); break; + + case RAW_TCON_SMB2: + req->status = NT_STATUS_INTERNAL_ERROR; + break; } failed: diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index 588237acb0..5fe64f064c 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -207,7 +207,11 @@ union smb_rename { } ntrename; }; -enum smb_tcon_level {RAW_TCON_TCON, RAW_TCON_TCONX}; +enum smb_tcon_level { + RAW_TCON_TCON, + RAW_TCON_TCONX, + RAW_TCON_SMB2 +}; /* union used in tree connect call */ union smb_tcon { @@ -248,10 +252,42 @@ union smb_tcon { uint16_t tid; } out; } tconx; + + /* SMB2 TreeConnect */ + struct smb2_tree_connect { + enum smb_tcon_level level; + + struct { + /* static body buffer 8 (0x08) bytes */ + /* uint16_t buffer_code; 0x09 = 0x08 + 1 */ + uint16_t unknown1; /* 0x0000 */ + /* uint16_t path_ofs */ + /* uint16_t path_size */ + + /* dynamic body */ + const char *path; /* as non-terminated UTF-16 on the wire */ + } in; + struct { + /* static body buffer 16 (0x10) bytes */ + /* uint16_t buffer_code; 0x10 */ + uint16_t unknown1; /* 0x02 */ + uint32_t unknown2; /* 0x00 */ + uint32_t unknown3; /* 0x00 */ + uint32_t access_mask; + + /* extracted from the SMB2 header */ + uint32_t tid; + } out; + } smb2; }; -enum smb_sesssetup_level {RAW_SESSSETUP_OLD, RAW_SESSSETUP_NT1, RAW_SESSSETUP_SPNEGO}; +enum smb_sesssetup_level { + RAW_SESSSETUP_OLD, + RAW_SESSSETUP_NT1, + RAW_SESSSETUP_SPNEGO, + RAW_SESSSETUP_SMB2 +}; /* union used in session_setup call */ union smb_sesssetup { @@ -330,6 +366,37 @@ union smb_sesssetup { uint16_t vuid; } out; } spnego; + + /* SMB2 SessionSetup */ + struct smb2_session_setup { + enum smb_sesssetup_level level; + + struct { + /* static body buffer 16 (0x10) bytes */ + /* uint16_t buffer_code; 0x11 = 0x10 + 1 */ + uint16_t _pad; + uint32_t unknown2; /* 0xF */ + uint32_t unknown3; /* 0x00 */ + /* uint16_t secblob_ofs */ + /* uint16_t secblob_size */ + + /* dynamic body */ + DATA_BLOB secblob; + } in; + struct { + /* static body buffer 8 (0x08) bytes */ + /* uint16_t buffer_code; 0x09 = 0x08 +1 */ + uint16_t _pad; + /* uint16_t secblob_ofs */ + /* uint16_t secblob_size */ + + /* dynamic body */ + DATA_BLOB secblob; + + /* extracted from the SMB2 header */ + uint64_t uid; + } out; + } smb2; }; /* Note that the specified enum values are identical to the actual info-levels used @@ -1161,12 +1228,18 @@ union smb_fsinfo { enum smb_open_level { - RAW_OPEN_OPEN, RAW_OPEN_OPENX, - RAW_OPEN_MKNEW, RAW_OPEN_CREATE, - RAW_OPEN_CTEMP, RAW_OPEN_SPLOPEN, - RAW_OPEN_NTCREATEX, RAW_OPEN_T2OPEN, - RAW_OPEN_NTTRANS_CREATE, - RAW_OPEN_OPENX_READX}; + RAW_OPEN_OPEN, + RAW_OPEN_OPENX, + RAW_OPEN_MKNEW, + RAW_OPEN_CREATE, + RAW_OPEN_CTEMP, + RAW_OPEN_SPLOPEN, + RAW_OPEN_NTCREATEX, + RAW_OPEN_T2OPEN, + RAW_OPEN_NTTRANS_CREATE, + RAW_OPEN_OPENX_READX, + RAW_OPEN_SMB2 +}; /* the generic interface is defined to be equal to the NTCREATEX interface */ #define RAW_OPEN_GENERIC RAW_OPEN_NTCREATEX @@ -1417,11 +1490,73 @@ union smb_open { uint16_t nread; } out; } openxreadx; + +#define SMB2_CREATE_FLAG_REQUEST_OPLOCK 0x0100 +#define SMB2_CREATE_FLAG_REQUEST_EXCLUSIVE_OPLOCK 0x0800 +#define SMB2_CREATE_FLAG_GRANT_OPLOCK 0x0001 +#define SMB2_CREATE_FLAG_GRANT_EXCLUSIVE_OPLOCK 0x0080 + + /* SMB2 Create */ + struct smb2_create { + enum smb_open_level level; + struct { + /* static body buffer 56 (0x38) bytes */ + /* uint16_t buffer_code; 0x39 = 0x38 + 1 */ + uint16_t oplock_flags; /* SMB2_CREATE_FLAG_* */ + uint32_t impersonation; + uint32_t unknown3[4]; + uint32_t access_mask; + + uint32_t file_attr; + uint32_t share_access; + uint32_t open_disposition; + uint32_t create_options; + + /* uint16_t fname_ofs */ + /* uint16_t fname_size */ + /* uint32_t blob_ofs; */ + /* uint32_t blob_size; */ + + /* dynamic body */ + const char *fname; + + /* optional list of extended attributes */ + struct smb_ea_list eas; + } in; + struct { + union smb_handle file; + + /* static body buffer 88 (0x58) bytes */ + /* uint16_t buffer_code; 0x59 = 0x58 + 1 */ + uint16_t oplock_flags; /* SMB2_CREATE_FLAG_* */ + uint32_t create_action; + NTTIME create_time; + NTTIME access_time; + NTTIME write_time; + NTTIME change_time; + uint64_t alloc_size; + uint64_t size; + uint32_t file_attr; + uint32_t _pad; + /* struct smb2_handle handle;*/ + /* uint32_t blob_ofs; */ + /* uint32_t blob_size; */ + + /* dynamic body */ + DATA_BLOB blob; + } out; + } smb2; }; -enum smb_read_level {RAW_READ_READBRAW, RAW_READ_LOCKREAD, RAW_READ_READ, RAW_READ_READX}; +enum smb_read_level { + RAW_READ_READBRAW, + RAW_READ_LOCKREAD, + RAW_READ_READ, + RAW_READ_READX, + RAW_READ_SMB2 +}; #define RAW_READ_GENERIC RAW_READ_READX @@ -1496,12 +1631,45 @@ union smb_read { uint16_t nread; } out; } read; + + /* SMB2 Read */ + struct smb2_read { + enum smb_read_level level; + struct { + union smb_handle file; + + /* static body buffer 48 (0x30) bytes */ + /* uint16_t buffer_code; 0x31 = 0x30 + 1 */ + uint16_t _pad; + uint32_t length; + uint64_t offset; + /* struct smb2_handle handle; */ + uint64_t unknown1; /* 0x0000000000000000 */ + uint64_t unknown2; /* 0x0000000000000000 */ + uint8_t _bug; + } in; + struct { + /* static body buffer 16 (0x10) bytes */ + /* uint16_t buffer_code; 0x11 = 0x10 + 1 */ + /* uint16_t data_ofs; */ + /* uint32_t data_size; */ + uint64_t unknown1; /* 0x0000000000000000 */ + + /* dynamic body */ + DATA_BLOB data; + } out; + } smb2; }; -enum smb_write_level {RAW_WRITE_WRITEUNLOCK, RAW_WRITE_WRITE, - RAW_WRITE_WRITEX, RAW_WRITE_WRITECLOSE, - RAW_WRITE_SPLWRITE}; +enum smb_write_level { + RAW_WRITE_WRITEUNLOCK, + RAW_WRITE_WRITE, + RAW_WRITE_WRITEX, + RAW_WRITE_WRITECLOSE, + RAW_WRITE_SPLWRITE, + RAW_WRITE_SMB2 +}; #define RAW_WRITE_GENERIC RAW_WRITE_WRITEX @@ -1579,6 +1747,34 @@ union smb_write { const uint8_t *data; } in; } splwrite; + + /* SMB2 Write */ + struct smb2_write { + enum smb_write_level level; + struct { + union smb_handle file; + + /* static body buffer 48 (0x30) bytes */ + /* uint16_t buffer_code; 0x31 = 0x30 + 1 */ + /* uint16_t data_ofs; */ + /* uint32_t data_size; */ + uint64_t offset; + /* struct smb2_handle handle; */ + uint64_t unknown1; /* 0xFFFFFFFFFFFFFFFF */ + uint64_t unknown2; /* 0xFFFFFFFFFFFFFFFF */ + + /* dynamic body */ + DATA_BLOB data; + } in; + struct { + /* static body buffer 17 (0x11) bytes */ + /* uint16_t buffer_code; 0x11 */ + uint16_t _pad; + uint32_t nwritten; + uint64_t unknown1; /* 0x0000000000000000 */ + uint8_t _bug; + } out; + } smb2; }; @@ -1619,7 +1815,11 @@ union smb_lock { }; -enum smb_close_level {RAW_CLOSE_CLOSE, RAW_CLOSE_SPLCLOSE}; +enum smb_close_level { + RAW_CLOSE_CLOSE, + RAW_CLOSE_SPLCLOSE, + RAW_CLOSE_SMB2 +}; #define RAW_CLOSE_GENERIC RAW_CLOSE_CLOSE @@ -1643,6 +1843,33 @@ union smb_close { union smb_handle file; } in; } splclose; + + /* SMB2 Close */ + struct smb2_close { + enum smb_close_level level; + struct { + union smb_handle file; + + /* static body buffer 24 (0x18) bytes */ + /* uint16_t buffer_code; 0x18 */ +#define SMB2_CLOSE_FLAGS_FULL_INFORMATION (1<<0) + uint16_t flags; /* SMB2_CLOSE_FLAGS_* */ + uint32_t _pad; + } in; + struct { + /* static body buffer 60 (0x3C) bytes */ + /* uint16_t buffer_code; 0x3C */ + uint16_t flags; + uint32_t _pad; + NTTIME create_time; + NTTIME access_time; + NTTIME write_time; + NTTIME change_time; + uint64_t alloc_size; + uint64_t size; + uint32_t file_attr; + } out; + } smb2; }; @@ -1681,7 +1908,11 @@ union smb_lpq { } retq; }; -enum smb_ioctl_level {RAW_IOCTL_IOCTL, RAW_IOCTL_NTIOCTL}; +enum smb_ioctl_level { + RAW_IOCTL_IOCTL, + RAW_IOCTL_NTIOCTL, + RAW_IOCTL_SMB2 +}; /* union for ioctl() backend @@ -1723,12 +1954,60 @@ union smb_ioctl { DATA_BLOB blob; } out; } ntioctl; + + /* SMB2 Ioctl */ + struct smb2_ioctl { + enum smb_ioctl_level level; + struct { + union smb_handle file; + + /* static body buffer 56 (0x38) bytes */ + /* uint16_t buffer_code; 0x39 = 0x38 + 1 */ + uint16_t _pad; + uint32_t function; + /*struct smb2_handle handle;*/ + /* uint32_t out_ofs; */ + /* uint32_t out_size; */ + uint32_t unknown2; + /* uint32_t in_ofs; */ + /* uint32_t in_size; */ + uint32_t max_response_size; + uint64_t flags; + + /* dynamic body */ + DATA_BLOB out; + DATA_BLOB in; + } in; + struct { + union smb_handle file; + + /* static body buffer 48 (0x30) bytes */ + /* uint16_t buffer_code; 0x31 = 0x30 + 1 */ + uint16_t _pad; + uint32_t function; + /* struct smb2_handle handle; */ + /* uint32_t in_ofs; */ + /* uint32_t in_size; */ + /* uint32_t out_ofs; */ + /* uint32_t out_size; */ + uint32_t unknown2; + uint32_t unknown3; + + /* dynamic body */ + DATA_BLOB in; + DATA_BLOB out; + } out; + } smb2; }; -enum smb_flush_level {RAW_FLUSH_FLUSH, RAW_FLUSH_ALL}; +enum smb_flush_level { + RAW_FLUSH_FLUSH, + RAW_FLUSH_ALL, + RAW_FLUSH_SMB2 +}; -/* struct for SMBflush */ union smb_flush { + /* struct for SMBflush */ struct { enum smb_flush_level level; struct { @@ -1736,11 +2015,20 @@ union smb_flush { } in; } flush, generic; + /* SMBflush with 0xFFFF wildcard fnum */ struct { enum smb_flush_level level; } flush_all; -}; + /* SMB2 Flush */ + struct smb2_flush { + enum smb_flush_level level; + struct { + union smb_handle file; + uint32_t unknown; + } in; + } smb2; +}; /* struct for SMBcopy */ struct smb_copy { @@ -1823,7 +2111,8 @@ struct smb_notify { enum smb_search_level {RAW_SEARCH_GENERIC = 0xF000, RAW_SEARCH_SEARCH, /* SMBsearch */ RAW_SEARCH_FFIRST, /* SMBffirst */ - RAW_SEARCH_FUNIQUE, /* SMBfunique */ + RAW_SEARCH_FUNIQUE, /* SMBfunique */ + RAW_SEARCH_SMB2, /* SMB2 Find */ RAW_SEARCH_STANDARD = SMB_FIND_STANDARD, RAW_SEARCH_EA_SIZE = SMB_FIND_EA_SIZE, RAW_SEARCH_EA_LIST = SMB_FIND_EA_LIST, @@ -1878,6 +2167,45 @@ union smb_search_first { uint16_t end_of_search; } out; } t2ffirst; + +/* + SMB2 uses different level numbers for the same old SMB search levels +*/ +#define SMB2_FIND_DIRECTORY_INFO 0x01 +#define SMB2_FIND_FULL_DIRECTORY_INFO 0x02 +#define SMB2_FIND_BOTH_DIRECTORY_INFO 0x03 +#define SMB2_FIND_NAME_INFO 0x0C +#define SMB2_FIND_ID_BOTH_DIRECTORY_INFO 0x25 +#define SMB2_FIND_ID_FULL_DIRECTORY_INFO 0x26 + /* SMB2 Find */ + struct smb2_find { + enum smb_search_level level; + struct { + union smb_handle file; + + /* static body buffer 32 (0x20) bytes */ + /* uint16_t buffer_code; 0x21 = 0x20 + 1 */ + uint8_t level; + uint8_t continue_flags; /* SMB2_CONTINUE_FLAG_* */ + uint32_t unknown; /* perhaps a continue token? */ + /* struct smb2_handle handle; */ + /* uint16_t pattern_ofs; */ + /* uint32_t pattern_size; */ + uint32_t max_response_size; + + /* dynamic body */ + const char *pattern; + } in; + struct { + /* static body buffer 8 (0x08) bytes */ + /* uint16_t buffer_code; 0x08 */ + /* uint16_t blob_ofs; */ + /* uint32_t blob_size; */ + + /* dynamic body */ + DATA_BLOB blob; + } out; + } smb2; }; /* union for file search continue */ diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c index faa2cdbeb4..3aad05a748 100644 --- a/source4/libcli/raw/rawfile.c +++ b/source4/libcli/raw/rawfile.c @@ -545,6 +545,8 @@ struct smbcli_request *smb_raw_open_send(struct smbcli_tree *tree, union smb_ope SIVAL(req->out.vwv, VWV(10),parms->openxreadx.in.offset>>32); } break; + case RAW_OPEN_SMB2: + return NULL; } if (!smbcli_request_send(req)) { @@ -680,6 +682,9 @@ NTSTATUS smb_raw_open_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, unio req->status = NT_STATUS_BUFFER_TOO_SMALL; } break; + case RAW_OPEN_SMB2: + req->status = NT_STATUS_INTERNAL_ERROR; + break; } failed: @@ -717,6 +722,9 @@ struct smbcli_request *smb_raw_close_send(struct smbcli_tree *tree, union smb_cl SSVAL(req->out.vwv, VWV(0), parms->splclose.in.file.fnum); SIVAL(req->out.vwv, VWV(1), 0); /* reserved */ break; + + case RAW_CLOSE_SMB2: + return NULL; } if (!req) return NULL; @@ -858,6 +866,8 @@ struct smbcli_request *smb_raw_flush_send(struct smbcli_tree *tree, union smb_fl case RAW_FLUSH_ALL: fnum = 0xFFFF; break; + case RAW_FLUSH_SMB2: + return NULL; } SETUP_REQUEST(SMBflush, 1, 0); diff --git a/source4/libcli/raw/rawioctl.c b/source4/libcli/raw/rawioctl.c index af48fcb566..0bd37785ac 100644 --- a/source4/libcli/raw/rawioctl.c +++ b/source4/libcli/raw/rawioctl.c @@ -132,6 +132,9 @@ struct smbcli_request *smb_raw_ioctl_send(struct smbcli_tree *tree, union smb_io case RAW_IOCTL_NTIOCTL: req = smb_raw_ntioctl_send(tree, parms); break; + + case RAW_IOCTL_SMB2: + return NULL; } return req; @@ -149,6 +152,9 @@ NTSTATUS smb_raw_ioctl_recv(struct smbcli_request *req, case RAW_IOCTL_NTIOCTL: return smb_raw_ntioctl_recv(req, mem_ctx, parms); + + case RAW_IOCTL_SMB2: + break; } return NT_STATUS_INVALID_LEVEL; } diff --git a/source4/libcli/raw/rawreadwrite.c b/source4/libcli/raw/rawreadwrite.c index 63a60ad545..7a47ce66f4 100644 --- a/source4/libcli/raw/rawreadwrite.c +++ b/source4/libcli/raw/rawreadwrite.c @@ -94,6 +94,9 @@ struct smbcli_request *smb_raw_read_send(struct smbcli_tree *tree, union smb_rea SSVAL(req->out.hdr, HDR_FLG2, flags2); } break; + + case RAW_READ_SMB2: + return NULL; } if (!smbcli_request_send(req)) { @@ -165,6 +168,10 @@ NTSTATUS smb_raw_read_recv(struct smbcli_request *req, union smb_read *parms) req->status = NT_STATUS_BUFFER_TOO_SMALL; } break; + + case RAW_READ_SMB2: + req->status = NT_STATUS_INTERNAL_ERROR; + break; } failed: @@ -261,6 +268,9 @@ struct smbcli_request *smb_raw_write_send(struct smbcli_tree *tree, union smb_wr memcpy(req->out.data, parms->splwrite.in.data, parms->splwrite.in.count); } break; + + case RAW_WRITE_SMB2: + return NULL; } if (!smbcli_request_send(req)) { @@ -303,6 +313,9 @@ NTSTATUS smb_raw_write_recv(struct smbcli_request *req, union smb_write *parms) break; case RAW_WRITE_SPLWRITE: break; + case RAW_WRITE_SMB2: + req->status = NT_STATUS_INTERNAL_ERROR; + break; } failed: diff --git a/source4/libcli/raw/rawsearch.c b/source4/libcli/raw/rawsearch.c index e844a33358..5e05d7c3c5 100644 --- a/source4/libcli/raw/rawsearch.c +++ b/source4/libcli/raw/rawsearch.c @@ -482,6 +482,7 @@ static int parse_trans2_search(struct smbcli_tree *tree, case RAW_SEARCH_SEARCH: case RAW_SEARCH_FFIRST: case RAW_SEARCH_FUNIQUE: + case RAW_SEARCH_SMB2: /* handled elsewhere */ return -1; -- cgit From 26047265cce081d0190ac781f3eba60fc12a4b60 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sat, 20 May 2006 18:34:59 +0000 Subject: r15756: handle RAW_OPEN_SMB2 metze (This used to be commit 8aebd7adc9a0288ebf6b8d84fc376d699054a520) --- source4/libcli/raw/interfaces.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index 5fe64f064c..49ac702e45 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -1282,6 +1282,9 @@ union smb_open { case RAW_OPEN_OPENX_READX: \ file = &op->openxreadx.out.file; \ break; \ + case RAW_OPEN_SMB2: \ + file = &op->smb2.out.file; \ + break; \ default: \ /* this must be a programmer error */ \ file = NULL; \ -- cgit From d9bdfb0a0720907151b71086be289a0f6ec2bb98 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 22 May 2006 17:21:38 +0000 Subject: r15814: add SMB2 Lock interface structure metze (This used to be commit 8f1850ef65dc8c860912639d787d82399d015f13) --- source4/libcli/raw/interfaces.h | 34 +++++++++++++++++++++++++++++++++- source4/libcli/raw/rawfile.c | 2 ++ 2 files changed, 35 insertions(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index 49ac702e45..8b144779f4 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -1781,7 +1781,12 @@ union smb_write { }; -enum smb_lock_level {RAW_LOCK_LOCK, RAW_LOCK_UNLOCK, RAW_LOCK_LOCKX}; +enum smb_lock_level { + RAW_LOCK_LOCK, + RAW_LOCK_UNLOCK, + RAW_LOCK_LOCKX, + RAW_LOCK_SMB2 +}; /* the generic interface is defined to be equal to the lockingX interface */ #define RAW_LOCK_GENERIC RAW_LOCK_LOCKX @@ -1815,6 +1820,33 @@ union smb_lock { uint32_t offset; } in; } lock, unlock; + + /* SMB2 Lock */ + struct smb2_lock { + enum smb_lock_level level; + struct { + union smb_handle file; + + /* static body buffer 48 (0x30) bytes */ + /* uint16_t buffer_code; 0x30 */ + uint16_t unknown1; /* must be 0x0001 */ + uint32_t unknown2; + /* struct smb2_handle handle; */ + uint64_t offset; + uint64_t count; + uint32_t unknown5; +#define SMB2_LOCK_FLAG_NONE 0x00000000 +#define SMB2_LOCK_FLAG_EXCLUSIV 0x00000002 +#define SMB2_LOCK_FLAG_UNLOCK 0x00000004 +#define SMB2_LOCK_FLAGS_MASK 0x00000006 + uint32_t flags; + } in; + struct { + /* static body buffer 4 (0x04) bytes */ + /* uint16_t buffer_code; 0x04 */ + uint16_t unknown1; + } out; + } smb2; }; diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c index 3aad05a748..5a38d4083d 100644 --- a/source4/libcli/raw/rawfile.c +++ b/source4/libcli/raw/rawfile.c @@ -802,6 +802,8 @@ struct smbcli_request *smb_raw_lock_send(struct smbcli_tree *tree, union smb_loc } } } + case RAW_LOCK_SMB2: + return NULL; } if (!smbcli_request_send(req)) { -- cgit From 0b56e916a762d77cb7dd06a4130ad78d33d57b53 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 23 May 2006 09:27:58 +0000 Subject: r15835: fixed locking in the client library (This used to be commit 7ea51fb624ded55f69f235a6791de871f754e8fa) --- source4/libcli/raw/rawfile.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c index 5a38d4083d..f8b5e90e4b 100644 --- a/source4/libcli/raw/rawfile.c +++ b/source4/libcli/raw/rawfile.c @@ -801,6 +801,7 @@ struct smbcli_request *smb_raw_lock_send(struct smbcli_tree *tree, union smb_loc SIVAL(p, 6, lockp[i].count); } } + break; } case RAW_LOCK_SMB2: return NULL; -- cgit From 971d30bb201f5c3faff5f575d26882eb79f7955a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 24 May 2006 07:34:11 +0000 Subject: r15854: more talloc_set_destructor() typesafe fixes (This used to be commit 61c6100617589ac6df4f527877241464cacbf8b3) --- source4/libcli/raw/clitransport.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 2ad155e9b9..fc257b9098 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -50,10 +50,8 @@ static void smbcli_transport_event_handler(struct event_context *ev, /* destroy a transport */ -static int transport_destructor(void *ptr) +static int transport_destructor(struct smbcli_transport *transport) { - struct smbcli_transport *transport = ptr; - smbcli_transport_dead(transport); return 0; } @@ -538,9 +536,8 @@ static void smbcli_timeout_handler(struct event_context *ev, struct timed_event /* destroy a request */ -static int smbcli_request_destructor(void *ptr) +static int smbcli_request_destructor(struct smbcli_request *req) { - struct smbcli_request *req = talloc_get_type(ptr, struct smbcli_request); if (req->state == SMBCLI_REQUEST_RECV) { DLIST_REMOVE(req->transport->pending_recv, req); } -- cgit From 7613015f47f6e45ee9ac4f652f773bd2980fc788 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 8 Jun 2006 07:11:25 +0000 Subject: r16091: Without this patch Samba3 will not accept this, and simply setting the "92" to "100" will give funny permissions... Volker (This used to be commit b76a3d4f590963d48eae8a9899d17ae3833c3dfa) --- source4/libcli/raw/rawsetfileinfo.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawsetfileinfo.c b/source4/libcli/raw/rawsetfileinfo.c index 46480c636e..030779ad14 100644 --- a/source4/libcli/raw/rawsetfileinfo.c +++ b/source4/libcli/raw/rawsetfileinfo.c @@ -138,7 +138,7 @@ static BOOL smb_raw_setinfo_backend(struct smbcli_tree *tree, parms, blob); case RAW_SFILEINFO_UNIX_BASIC: - NEED_BLOB(92); + NEED_BLOB(100); SBVAL(blob->data, 0, parms->unix_basic.in.end_of_file); SBVAL(blob->data, 8, parms->unix_basic.in.num_bytes); smbcli_push_nttime(blob->data, 16, parms->unix_basic.in.status_change_time); @@ -150,7 +150,8 @@ static BOOL smb_raw_setinfo_backend(struct smbcli_tree *tree, SBVAL(blob->data, 60, parms->unix_basic.in.dev_major); SBVAL(blob->data, 68, parms->unix_basic.in.dev_minor); SBVAL(blob->data, 76, parms->unix_basic.in.unique_id); - SBVAL(blob->data, 84, parms->unix_basic.in.nlink); + SBVAL(blob->data, 84, parms->unix_basic.in.permissions); + SBVAL(blob->data, 92, parms->unix_basic.in.nlink); return True; case RAW_SFILEINFO_DISPOSITION_INFO: -- cgit From 332f5b19a101115ce920b9291d10e78fbea8db62 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 29 Jun 2006 07:02:14 +0000 Subject: r16667: - use ndr_pull_struct_blob() to make the RAW_FILEINFO_SEC_DESC pull code simpler - use ndr_push_struct_blob() for RAW_SFILEINFO_SEC_DESC metze (This used to be commit 79e51f033e680303431e56e818346b66a836d044) --- source4/libcli/raw/rawfileinfo.c | 21 +++++++++------------ source4/libcli/raw/rawsetfileinfo.c | 14 +++++++++++++- 2 files changed, 22 insertions(+), 13 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawfileinfo.c b/source4/libcli/raw/rawfileinfo.c index b33d0df828..67cad83c6d 100644 --- a/source4/libcli/raw/rawfileinfo.c +++ b/source4/libcli/raw/rawfileinfo.c @@ -244,20 +244,17 @@ NTSTATUS smb_raw_fileinfo_passthru_parse(const DATA_BLOB *blob, TALLOC_CTX *mem_ return NT_STATUS_OK; case RAW_FILEINFO_SEC_DESC: { - struct ndr_pull *ndr; NTSTATUS status; - ndr = ndr_pull_init_blob(blob, mem_ctx); - if (!ndr) { - return NT_STATUS_NO_MEMORY; - } + parms->query_secdesc.out.sd = talloc(mem_ctx, struct security_descriptor); - if (parms->query_secdesc.out.sd == NULL) { - return NT_STATUS_NO_MEMORY; - } - status = ndr_pull_security_descriptor(ndr, NDR_SCALARS|NDR_BUFFERS, - parms->query_secdesc.out.sd); - talloc_free(ndr); - return status; + NT_STATUS_HAVE_NO_MEMORY(parms->query_secdesc.out.sd); + + status = ndr_pull_struct_blob(blob, mem_ctx, + parms->query_secdesc.out.sd, + (ndr_pull_flags_fn_t)ndr_pull_security_descriptor); + NT_STATUS_NOT_OK_RETURN(status); + + return NT_STATUS_OK; } default: diff --git a/source4/libcli/raw/rawsetfileinfo.c b/source4/libcli/raw/rawsetfileinfo.c index 030779ad14..0daf14e0cc 100644 --- a/source4/libcli/raw/rawsetfileinfo.c +++ b/source4/libcli/raw/rawsetfileinfo.c @@ -21,6 +21,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" +#include "librpc/gen_ndr/ndr_security.h" /* @@ -83,7 +84,18 @@ BOOL smb_raw_setfileinfo_passthru(TALLOC_CTX *mem_ctx, NEED_BLOB(4); SIVAL(blob->data, 0, parms->mode_information.in.mode); return True; - + + case RAW_FILEINFO_SEC_DESC: { + NTSTATUS status; + + status = ndr_push_struct_blob(blob, mem_ctx, + parms->set_secdesc.in.sd, + (ndr_push_flags_fn_t)ndr_push_security_descriptor); + if (!NT_STATUS_IS_OK(status)) return False; + + return True; + } + /* Unhandled levels */ case RAW_SFILEINFO_1023: case RAW_SFILEINFO_1025: -- cgit From d63dd113ae2c7f4f6d64def00a488548e805bc7e Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 29 Jun 2006 22:16:58 +0000 Subject: r16699: the layout of SMB2 Read and Write is identical... so we know that the 9th bytes is just uninitialized padding metze (This used to be commit f97a21b970ed23973cced2c67b5bc9ecd7afee88) --- source4/libcli/raw/interfaces.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index 8b144779f4..3665af9548 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -1649,7 +1649,6 @@ union smb_read { /* struct smb2_handle handle; */ uint64_t unknown1; /* 0x0000000000000000 */ uint64_t unknown2; /* 0x0000000000000000 */ - uint8_t _bug; } in; struct { /* static body buffer 16 (0x10) bytes */ @@ -1771,11 +1770,10 @@ union smb_write { } in; struct { /* static body buffer 17 (0x11) bytes */ - /* uint16_t buffer_code; 0x11 */ + /* uint16_t buffer_code; 0x11 = 0x10 + 1*/ uint16_t _pad; uint32_t nwritten; uint64_t unknown1; /* 0x0000000000000000 */ - uint8_t _bug; } out; } smb2; }; -- cgit From 63d0c5a0570908cee293cca3300a4b50f48f8afd Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 30 Jun 2006 11:07:47 +0000 Subject: r16708: the packet format of SMB2 SessionSetup has changed, there're 8 more unknown bytes... Note: - vista-CTP also support this as a server, but uses the old format as client - but vista-beta2 only uses and accept the new format metze (This used to be commit b3bdd4afdefc9ad3550f86a0aa6e6c90bf8ab416) --- source4/libcli/raw/interfaces.h | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index 3665af9548..c581978b81 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -372,13 +372,18 @@ union smb_sesssetup { enum smb_sesssetup_level level; struct { - /* static body buffer 16 (0x10) bytes */ - /* uint16_t buffer_code; 0x11 = 0x10 + 1 */ + /* NOTE: this was 0x11 = 0x10 + 1 in vista-CTP + * and changed in vista-beta2, but both server's + * can handle the 0x18 clients + */ + /* static body buffer 24 (0x18) bytes */ + /* uint16_t buffer_code; 0x19 = 0x18 + 1 */ uint16_t _pad; - uint32_t unknown2; /* 0xF */ - uint32_t unknown3; /* 0x00 */ + uint32_t unknown2; /* 0x0000000F(vista-CTP) 0x00000007(vista-beta2) */ + uint32_t unknown3; /* 0x0000000 */ /* uint16_t secblob_ofs */ /* uint16_t secblob_size */ + uint64_t unknown4; /* 0x0000000000000000 only present in vista-beta2 */ /* dynamic body */ DATA_BLOB secblob; -- cgit From af0a9eb52955cfae570bfdc01821f56385c860cf Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 6 Jul 2006 08:00:24 +0000 Subject: r16834: split the level's of smb_search_first/smb_search_next and the levels of smb_search_data metze (This used to be commit 78c201db8a47a71908698c4dda2add4cf85694d9) --- source4/libcli/raw/interfaces.h | 74 +++++++++++++++---------- source4/libcli/raw/rawsearch.c | 120 +++++++++++++++++++++++----------------- 2 files changed, 114 insertions(+), 80 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index c581978b81..f77d31a1c7 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -2146,33 +2146,41 @@ struct smb_notify { } out; }; -enum smb_search_level {RAW_SEARCH_GENERIC = 0xF000, - RAW_SEARCH_SEARCH, /* SMBsearch */ - RAW_SEARCH_FFIRST, /* SMBffirst */ - RAW_SEARCH_FUNIQUE, /* SMBfunique */ - RAW_SEARCH_SMB2, /* SMB2 Find */ - RAW_SEARCH_STANDARD = SMB_FIND_STANDARD, - RAW_SEARCH_EA_SIZE = SMB_FIND_EA_SIZE, - RAW_SEARCH_EA_LIST = SMB_FIND_EA_LIST, - RAW_SEARCH_DIRECTORY_INFO = SMB_FIND_DIRECTORY_INFO, - RAW_SEARCH_FULL_DIRECTORY_INFO = SMB_FIND_FULL_DIRECTORY_INFO, - RAW_SEARCH_NAME_INFO = SMB_FIND_NAME_INFO, - RAW_SEARCH_BOTH_DIRECTORY_INFO = SMB_FIND_BOTH_DIRECTORY_INFO, - RAW_SEARCH_ID_FULL_DIRECTORY_INFO = SMB_FIND_ID_FULL_DIRECTORY_INFO, - RAW_SEARCH_ID_BOTH_DIRECTORY_INFO = SMB_FIND_ID_BOTH_DIRECTORY_INFO, - RAW_SEARCH_UNIX_INFO = SMB_FIND_UNIX_INFO}; +enum smb_search_level { + RAW_SEARCH_SEARCH, /* SMBsearch */ + RAW_SEARCH_FFIRST, /* SMBffirst */ + RAW_SEARCH_FUNIQUE, /* SMBfunique */ + RAW_SEARCH_TRANS2, /* SMBtrans2 */ + RAW_SEARCH_SMB2 /* SMB2 Find */ +}; +enum smb_search_data_level { + RAW_SEARCH_DATA_GENERIC = 0x10000, /* only used in the smbcli_ code */ + RAW_SEARCH_DATA_SEARCH, + RAW_SEARCH_DATA_STANDARD = SMB_FIND_STANDARD, + RAW_SEARCH_DATA_EA_SIZE = SMB_FIND_EA_SIZE, + RAW_SEARCH_DATA_EA_LIST = SMB_FIND_EA_LIST, + RAW_SEARCH_DATA_DIRECTORY_INFO = SMB_FIND_DIRECTORY_INFO, + RAW_SEARCH_DATA_FULL_DIRECTORY_INFO = SMB_FIND_FULL_DIRECTORY_INFO, + RAW_SEARCH_DATA_NAME_INFO = SMB_FIND_NAME_INFO, + RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO = SMB_FIND_BOTH_DIRECTORY_INFO, + RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO = SMB_FIND_ID_FULL_DIRECTORY_INFO, + RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO = SMB_FIND_ID_BOTH_DIRECTORY_INFO, + RAW_SEARCH_DATA_UNIX_INFO = SMB_FIND_UNIX_INFO +}; /* union for file search */ union smb_search_first { struct { enum smb_search_level level; + enum smb_search_data_level data_level; } generic; /* search (old) findfirst interface. Also used for ffirst and funique. */ struct { enum smb_search_level level; + enum smb_search_data_level data_level; struct { uint16_t max_count; @@ -2187,6 +2195,7 @@ union smb_search_first { /* trans2 findfirst interface */ struct { enum smb_search_level level; + enum smb_search_data_level data_level; struct { uint16_t search_attrib; @@ -2207,7 +2216,7 @@ union smb_search_first { } t2ffirst; /* - SMB2 uses different level numbers for the same old SMB search levels + SMB2 uses different level numbers for the same old SMB trans2 search levels */ #define SMB2_FIND_DIRECTORY_INFO 0x01 #define SMB2_FIND_FULL_DIRECTORY_INFO 0x02 @@ -2218,6 +2227,7 @@ union smb_search_first { /* SMB2 Find */ struct smb2_find { enum smb_search_level level; + enum smb_search_data_level data_level; struct { union smb_handle file; @@ -2228,7 +2238,7 @@ union smb_search_first { uint32_t unknown; /* perhaps a continue token? */ /* struct smb2_handle handle; */ /* uint16_t pattern_ofs; */ - /* uint32_t pattern_size; */ + /* uint16_t pattern_size; */ uint32_t max_response_size; /* dynamic body */ @@ -2250,12 +2260,14 @@ union smb_search_first { union smb_search_next { struct { enum smb_search_level level; + enum smb_search_data_level data_level; } generic; /* search (old) findnext interface. Also used for ffirst when continuing */ struct { enum smb_search_level level; + enum smb_search_data_level data_level; struct { uint16_t max_count; @@ -2276,6 +2288,7 @@ union smb_search_next { /* trans2 findnext interface */ struct { enum smb_search_level level; + enum smb_search_data_level data_level; struct { uint16_t handle; @@ -2297,7 +2310,10 @@ union smb_search_next { /* union for search reply file data */ union smb_search_data { - /* search (old) findfirst */ + /* + * search (old) findfirst + * RAW_SEARCH_DATA_SEARCH + */ struct { uint16_t attrib; time_t write_time; @@ -2305,8 +2321,8 @@ union smb_search_data { struct smb_search_id id; const char *name; } search; - - /* trans2 findfirst RAW_SEARCH_STANDARD level */ + + /* trans2 findfirst RAW_SEARCH_DATA_STANDARD level */ struct { uint32_t resume_key; time_t create_time; @@ -2318,7 +2334,7 @@ union smb_search_data { struct smb_wire_string name; } standard; - /* trans2 findfirst RAW_SEARCH_EA_SIZE level */ + /* trans2 findfirst RAW_SEARCH_DATA_EA_SIZE level */ struct { uint32_t resume_key; time_t create_time; @@ -2331,7 +2347,7 @@ union smb_search_data { struct smb_wire_string name; } ea_size; - /* trans2 findfirst RAW_SEARCH_EA_LIST level */ + /* trans2 findfirst RAW_SEARCH_DATA_EA_LIST level */ struct { uint32_t resume_key; time_t create_time; @@ -2344,7 +2360,7 @@ union smb_search_data { struct smb_wire_string name; } ea_list; - /* RAW_SEARCH_DIRECTORY_INFO interface */ + /* RAW_SEARCH_DATA_DIRECTORY_INFO interface */ struct { uint32_t file_index; NTTIME create_time; @@ -2357,7 +2373,7 @@ union smb_search_data { struct smb_wire_string name; } directory_info; - /* RAW_SEARCH_FULL_DIRECTORY_INFO interface */ + /* RAW_SEARCH_DATA_FULL_DIRECTORY_INFO interface */ struct { uint32_t file_index; NTTIME create_time; @@ -2371,13 +2387,13 @@ union smb_search_data { struct smb_wire_string name; } full_directory_info; - /* RAW_SEARCH_NAME_INFO interface */ + /* RAW_SEARCH_DATA_NAME_INFO interface */ struct { uint32_t file_index; struct smb_wire_string name; } name_info; - /* RAW_SEARCH_BOTH_DIRECTORY_INFO interface */ + /* RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO interface */ struct { uint32_t file_index; NTTIME create_time; @@ -2392,7 +2408,7 @@ union smb_search_data { struct smb_wire_string name; } both_directory_info; - /* RAW_SEARCH_ID_FULL_DIRECTORY_INFO interface */ + /* RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO interface */ struct { uint32_t file_index; NTTIME create_time; @@ -2407,7 +2423,7 @@ union smb_search_data { struct smb_wire_string name; } id_full_directory_info; - /* RAW_SEARCH_ID_BOTH_DIRECTORY_INFO interface */ + /* RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO interface */ struct { uint32_t file_index; NTTIME create_time; @@ -2423,7 +2439,7 @@ union smb_search_data { struct smb_wire_string name; } id_both_directory_info; - /* RAW_SEARCH_UNIX_INFO interface */ + /* RAW_SEARCH_DATA_UNIX_INFO interface */ struct { uint32_t file_index; uint64_t size; diff --git a/source4/libcli/raw/rawsearch.c b/source4/libcli/raw/rawsearch.c index 5e05d7c3c5..4836766a93 100644 --- a/source4/libcli/raw/rawsearch.c +++ b/source4/libcli/raw/rawsearch.c @@ -194,7 +194,6 @@ static NTSTATUS smb_raw_search_close_old(struct smbcli_tree *tree, static NTSTATUS smb_raw_search_first_blob(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, /* used to allocate output blobs */ union smb_search_first *io, - uint16_t info_level, DATA_BLOB *out_param_blob, DATA_BLOB *out_data_blob) { @@ -211,7 +210,15 @@ static NTSTATUS smb_raw_search_first_blob(struct smbcli_tree *tree, tp.in.max_data = 0xFFFF; tp.in.setup = &setup; - if (info_level == RAW_SEARCH_EA_LIST) { + if (io->t2ffirst.level != RAW_SEARCH_TRANS2) { + return NT_STATUS_INVALID_LEVEL; + } + + if (io->t2ffirst.data_level >= RAW_SEARCH_DATA_GENERIC) { + return NT_STATUS_INVALID_LEVEL; + } + + if (io->t2ffirst.data_level == RAW_SEARCH_DATA_EA_LIST) { if (!ea_push_name_list(mem_ctx, &tp.in.data, io->t2ffirst.in.num_names, @@ -219,7 +226,7 @@ static NTSTATUS smb_raw_search_first_blob(struct smbcli_tree *tree, return NT_STATUS_NO_MEMORY; } } - + tp.in.params = data_blob_talloc(mem_ctx, NULL, 12); if (!tp.in.params.data) { return NT_STATUS_NO_MEMORY; @@ -228,7 +235,7 @@ static NTSTATUS smb_raw_search_first_blob(struct smbcli_tree *tree, SSVAL(tp.in.params.data, 0, io->t2ffirst.in.search_attrib); SSVAL(tp.in.params.data, 2, io->t2ffirst.in.max_count); SSVAL(tp.in.params.data, 4, io->t2ffirst.in.flags); - SSVAL(tp.in.params.data, 6, info_level); + SSVAL(tp.in.params.data, 6, io->t2ffirst.data_level); SIVAL(tp.in.params.data, 8, io->t2ffirst.in.storage_type); smbcli_blob_append_string(tree->session, mem_ctx, &tp.in.params, @@ -255,7 +262,6 @@ static NTSTATUS smb_raw_search_first_blob(struct smbcli_tree *tree, static NTSTATUS smb_raw_search_next_blob(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_search_next *io, - uint16_t info_level, DATA_BLOB *out_param_blob, DATA_BLOB *out_data_blob) { @@ -272,7 +278,15 @@ static NTSTATUS smb_raw_search_next_blob(struct smbcli_tree *tree, tp.in.max_data = 0xFFFF; tp.in.setup = &setup; - if (info_level == RAW_SEARCH_EA_LIST) { + if (io->t2fnext.level != RAW_SEARCH_TRANS2) { + return NT_STATUS_INVALID_LEVEL; + } + + if (io->t2fnext.data_level >= RAW_SEARCH_DATA_GENERIC) { + return NT_STATUS_INVALID_LEVEL; + } + + if (io->t2fnext.data_level == RAW_SEARCH_DATA_EA_LIST) { if (!ea_push_name_list(mem_ctx, &tp.in.data, io->t2fnext.in.num_names, @@ -287,8 +301,8 @@ static NTSTATUS smb_raw_search_next_blob(struct smbcli_tree *tree, } SSVAL(tp.in.params.data, 0, io->t2fnext.in.handle); - SSVAL(tp.in.params.data, 2, io->t2fnext.in.max_count); - SSVAL(tp.in.params.data, 4, info_level); + SSVAL(tp.in.params.data, 2, io->t2fnext.in.max_count); + SSVAL(tp.in.params.data, 4, io->t2fnext.data_level); SIVAL(tp.in.params.data, 6, io->t2fnext.in.resume_key); SSVAL(tp.in.params.data, 10, io->t2fnext.in.flags); @@ -315,7 +329,7 @@ static NTSTATUS smb_raw_search_next_blob(struct smbcli_tree *tree, SMB2 */ NTSTATUS smb_raw_search_common(TALLOC_CTX *mem_ctx, - enum smb_search_level level, + enum smb_search_data_level level, const DATA_BLOB *blob, union smb_search_data *data, uint_t *next_ofs, @@ -335,7 +349,7 @@ NTSTATUS smb_raw_search_common(TALLOC_CTX *mem_ctx, } switch (level) { - case RAW_SEARCH_DIRECTORY_INFO: + case RAW_SEARCH_DATA_DIRECTORY_INFO: if (blen < 65) return NT_STATUS_INFO_LENGTH_MISMATCH; data->directory_info.file_index = IVAL(blob->data, 4); data->directory_info.create_time = smbcli_pull_nttime(blob->data, 8); @@ -353,7 +367,7 @@ NTSTATUS smb_raw_search_common(TALLOC_CTX *mem_ctx, } return NT_STATUS_OK; - case RAW_SEARCH_FULL_DIRECTORY_INFO: + case RAW_SEARCH_DATA_FULL_DIRECTORY_INFO: if (blen < 69) return NT_STATUS_INFO_LENGTH_MISMATCH; data->full_directory_info.file_index = IVAL(blob->data, 4); data->full_directory_info.create_time = smbcli_pull_nttime(blob->data, 8); @@ -372,7 +386,7 @@ NTSTATUS smb_raw_search_common(TALLOC_CTX *mem_ctx, } return NT_STATUS_OK; - case RAW_SEARCH_NAME_INFO: + case RAW_SEARCH_DATA_NAME_INFO: if (blen < 13) return NT_STATUS_INFO_LENGTH_MISMATCH; data->name_info.file_index = IVAL(blob->data, 4); len = smbcli_blob_pull_string(NULL, mem_ctx, blob, @@ -384,7 +398,7 @@ NTSTATUS smb_raw_search_common(TALLOC_CTX *mem_ctx, return NT_STATUS_OK; - case RAW_SEARCH_BOTH_DIRECTORY_INFO: + case RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO: if (blen < 95) return NT_STATUS_INFO_LENGTH_MISMATCH; data->both_directory_info.file_index = IVAL(blob->data, 4); data->both_directory_info.create_time = smbcli_pull_nttime(blob->data, 8); @@ -407,7 +421,7 @@ NTSTATUS smb_raw_search_common(TALLOC_CTX *mem_ctx, return NT_STATUS_OK; - case RAW_SEARCH_ID_FULL_DIRECTORY_INFO: + case RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO: if (blen < 81) return NT_STATUS_INFO_LENGTH_MISMATCH; data->id_full_directory_info.file_index = IVAL(blob->data, 4); data->id_full_directory_info.create_time = smbcli_pull_nttime(blob->data, 8); @@ -427,7 +441,7 @@ NTSTATUS smb_raw_search_common(TALLOC_CTX *mem_ctx, } return NT_STATUS_OK; - case RAW_SEARCH_ID_BOTH_DIRECTORY_INFO: + case RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO: if (blen < 105) return NT_STATUS_INFO_LENGTH_MISMATCH; data->id_both_directory_info.file_index = IVAL(blob->data, 4); data->id_both_directory_info.create_time = smbcli_pull_nttime(blob->data, 8); @@ -467,7 +481,7 @@ NTSTATUS smb_raw_search_common(TALLOC_CTX *mem_ctx, */ static int parse_trans2_search(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, - enum smb_search_level level, + enum smb_search_data_level level, uint16_t flags, DATA_BLOB *blob, union smb_search_data *data) @@ -478,15 +492,12 @@ static int parse_trans2_search(struct smbcli_tree *tree, NTSTATUS status; switch (level) { - case RAW_SEARCH_GENERIC: - case RAW_SEARCH_SEARCH: - case RAW_SEARCH_FFIRST: - case RAW_SEARCH_FUNIQUE: - case RAW_SEARCH_SMB2: + case RAW_SEARCH_DATA_GENERIC: + case RAW_SEARCH_DATA_SEARCH: /* handled elsewhere */ return -1; - case RAW_SEARCH_STANDARD: + case RAW_SEARCH_DATA_STANDARD: if (flags & FLAG_TRANS2_FIND_REQUIRE_RESUME) { if (blob->length < 4) return -1; data->standard.resume_key = IVAL(blob->data, 0); @@ -508,7 +519,7 @@ static int parse_trans2_search(struct smbcli_tree *tree, 22, 23, STR_LEN8BIT | STR_TERMINATE | STR_LEN_NOTERM); return len + 23; - case RAW_SEARCH_EA_SIZE: + case RAW_SEARCH_DATA_EA_SIZE: if (flags & FLAG_TRANS2_FIND_REQUIRE_RESUME) { if (blob->length < 4) return -1; data->ea_size.resume_key = IVAL(blob->data, 0); @@ -531,7 +542,7 @@ static int parse_trans2_search(struct smbcli_tree *tree, 26, 27, STR_LEN8BIT | STR_TERMINATE | STR_NOALIGN); return len + 27 + 1; - case RAW_SEARCH_EA_LIST: + case RAW_SEARCH_DATA_EA_LIST: if (flags & FLAG_TRANS2_FIND_REQUIRE_RESUME) { if (blob->length < 4) return -1; data->ea_list.resume_key = IVAL(blob->data, 0); @@ -569,7 +580,7 @@ static int parse_trans2_search(struct smbcli_tree *tree, STR_LEN8BIT | STR_NOALIGN); return len + ea_size + 23 + 1; - case RAW_SEARCH_UNIX_INFO: + case RAW_SEARCH_DATA_UNIX_INFO: if (blob->length < 109) return -1; ofs = IVAL(blob->data, 0); data->unix_info.file_index = IVAL(blob->data, 4); @@ -594,12 +605,12 @@ static int parse_trans2_search(struct smbcli_tree *tree, } return ofs; - case RAW_SEARCH_DIRECTORY_INFO: - case RAW_SEARCH_FULL_DIRECTORY_INFO: - case RAW_SEARCH_NAME_INFO: - case RAW_SEARCH_BOTH_DIRECTORY_INFO: - case RAW_SEARCH_ID_FULL_DIRECTORY_INFO: - case RAW_SEARCH_ID_BOTH_DIRECTORY_INFO: { + case RAW_SEARCH_DATA_DIRECTORY_INFO: + case RAW_SEARCH_DATA_FULL_DIRECTORY_INFO: + case RAW_SEARCH_DATA_NAME_INFO: + case RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO: + case RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO: + case RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO: { uint_t str_flags = STR_UNICODE; if (!(tree->session->transport->negotiate.capabilities & CAP_UNICODE)) { str_flags = STR_ASCII; @@ -622,7 +633,7 @@ static int parse_trans2_search(struct smbcli_tree *tree, ****************************************************************************/ static NTSTATUS smb_raw_t2search_backend(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, - enum smb_search_level level, + enum smb_search_data_level level, uint16_t flags, int16_t count, DATA_BLOB *blob, @@ -668,22 +679,24 @@ NTSTATUS smb_raw_search_first(struct smbcli_tree *tree, union smb_search_first *io, void *private, BOOL (*callback)(void *private, union smb_search_data *file)) { - uint16_t info_level = 0; DATA_BLOB p_blob, d_blob; NTSTATUS status; - - if (io->generic.level == RAW_SEARCH_SEARCH || - io->generic.level == RAW_SEARCH_FFIRST || - io->generic.level == RAW_SEARCH_FUNIQUE) { + + switch (io->generic.level) { + case RAW_SEARCH_SEARCH: + case RAW_SEARCH_FFIRST: + case RAW_SEARCH_FUNIQUE: return smb_raw_search_first_old(tree, mem_ctx, io, private, callback); - } - if (io->generic.level >= RAW_SEARCH_GENERIC) { + + case RAW_SEARCH_TRANS2: + break; + + case RAW_SEARCH_SMB2: return NT_STATUS_INVALID_LEVEL; } - info_level = (uint16_t)io->generic.level; status = smb_raw_search_first_blob(tree, mem_ctx, - io, info_level, &p_blob, &d_blob); + io, &p_blob, &d_blob); if (!NT_STATUS_IS_OK(status)) { return status; } @@ -698,9 +711,9 @@ NTSTATUS smb_raw_search_first(struct smbcli_tree *tree, io->t2ffirst.out.handle = SVAL(p_blob.data, 0); io->t2ffirst.out.count = SVAL(p_blob.data, 2); io->t2ffirst.out.end_of_search = SVAL(p_blob.data, 4); - + status = smb_raw_t2search_backend(tree, mem_ctx, - io->generic.level, + io->generic.data_level, io->t2ffirst.in.flags, io->t2ffirst.out.count, &d_blob, private, callback); @@ -714,21 +727,26 @@ NTSTATUS smb_raw_search_next(struct smbcli_tree *tree, union smb_search_next *io, void *private, BOOL (*callback)(void *private, union smb_search_data *file)) { - uint16_t info_level = 0; DATA_BLOB p_blob, d_blob; NTSTATUS status; - if (io->generic.level == RAW_SEARCH_SEARCH || - io->generic.level == RAW_SEARCH_FFIRST) { + switch (io->generic.level) { + case RAW_SEARCH_SEARCH: + case RAW_SEARCH_FFIRST: return smb_raw_search_next_old(tree, mem_ctx, io, private, callback); - } - if (io->generic.level >= RAW_SEARCH_GENERIC) { + + case RAW_SEARCH_FUNIQUE: + return NT_STATUS_INVALID_LEVEL; + + case RAW_SEARCH_TRANS2: + break; + + case RAW_SEARCH_SMB2: return NT_STATUS_INVALID_LEVEL; } - info_level = (uint16_t)io->generic.level; status = smb_raw_search_next_blob(tree, mem_ctx, - io, info_level, &p_blob, &d_blob); + io, &p_blob, &d_blob); if (!NT_STATUS_IS_OK(status)) { return status; } @@ -744,7 +762,7 @@ NTSTATUS smb_raw_search_next(struct smbcli_tree *tree, io->t2fnext.out.end_of_search = SVAL(p_blob.data, 2); status = smb_raw_t2search_backend(tree, mem_ctx, - io->generic.level, + io->generic.data_level, io->t2fnext.in.flags, io->t2fnext.out.count, &d_blob, private, callback); -- cgit From bb158b74da65edc5ed8ed9fdbcb77ffae373df2e Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sat, 8 Jul 2006 08:18:55 +0000 Subject: r16871: zero padding bytes (found by valgrind) metze (This used to be commit 283bec8295b6302dfe3dc12c82d7870bdfee8b37) --- source4/libcli/raw/rawfileinfo.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawfileinfo.c b/source4/libcli/raw/rawfileinfo.c index 67cad83c6d..38f4d12369 100644 --- a/source4/libcli/raw/rawfileinfo.c +++ b/source4/libcli/raw/rawfileinfo.c @@ -234,6 +234,7 @@ NTSTATUS smb_raw_fileinfo_passthru_parse(const DATA_BLOB *blob, TALLOC_CTX *mem_ parms->all_info2.out.nlink = IVAL(blob->data, 0x38); parms->all_info2.out.delete_pending = CVAL(blob->data, 0x3C); parms->all_info2.out.directory = CVAL(blob->data, 0x3D); + /* 0x3E-0x3F padding */ parms->all_info2.out.file_id = BVAL(blob->data, 0x40); parms->all_info2.out.ea_size = IVAL(blob->data, 0x48); parms->all_info2.out.access_mask = IVAL(blob->data, 0x4C); -- cgit From a3797ff66a1b3b19329a622fa38b5a073328e003 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sat, 8 Jul 2006 12:34:31 +0000 Subject: r16875: implement SMB2 Find in the frontend metze (This used to be commit 58bed7322c7e552d0462a11ce5d46a282c31f8f7) --- source4/libcli/raw/interfaces.h | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index f77d31a1c7..27b3510371 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -2224,6 +2224,12 @@ union smb_search_first { #define SMB2_FIND_NAME_INFO 0x0C #define SMB2_FIND_ID_BOTH_DIRECTORY_INFO 0x25 #define SMB2_FIND_ID_FULL_DIRECTORY_INFO 0x26 + +/* flags for RAW_FILEINFO_SMB2_ALL_EAS */ +#define SMB2_CONTINUE_FLAG_RESTART 0x01 +#define SMB2_CONTINUE_FLAG_SINGLE 0x02 +#define SMB2_CONTINUE_FLAG_NEW 0x10 + /* SMB2 Find */ struct smb2_find { enum smb_search_level level; @@ -2306,6 +2312,9 @@ union smb_search_next { uint16_t end_of_search; } out; } t2fnext; + + /* SMB2 Find */ + struct smb2_find smb2; }; /* union for search reply file data */ -- cgit From 5468516f9af10cb3c67bc93c610c22b5383e20db Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 10 Jul 2006 14:01:53 +0000 Subject: r16918: the SMB2 Ioctls are sometimes called with a wildcard handle the operation doesn't need a valid file handle in that case metze (This used to be commit d41a83d55945b07020349339888f3a34ac4eff4e) --- source4/libcli/raw/interfaces.h | 3 ++- source4/libcli/raw/rawioctl.c | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index 27b3510371..8ebdd38bee 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -1949,7 +1949,8 @@ union smb_lpq { enum smb_ioctl_level { RAW_IOCTL_IOCTL, RAW_IOCTL_NTIOCTL, - RAW_IOCTL_SMB2 + RAW_IOCTL_SMB2, + RAW_IOCTL_SMB2_NO_HANDLE }; /* diff --git a/source4/libcli/raw/rawioctl.c b/source4/libcli/raw/rawioctl.c index 0bd37785ac..a9812022ea 100644 --- a/source4/libcli/raw/rawioctl.c +++ b/source4/libcli/raw/rawioctl.c @@ -134,6 +134,7 @@ struct smbcli_request *smb_raw_ioctl_send(struct smbcli_tree *tree, union smb_io break; case RAW_IOCTL_SMB2: + case RAW_IOCTL_SMB2_NO_HANDLE: return NULL; } @@ -154,6 +155,7 @@ NTSTATUS smb_raw_ioctl_recv(struct smbcli_request *req, return smb_raw_ntioctl_recv(req, mem_ctx, parms); case RAW_IOCTL_SMB2: + case RAW_IOCTL_SMB2_NO_HANDLE: break; } return NT_STATUS_INVALID_LEVEL; -- cgit From a8958391e8fd9ddd996d2d3aff7ddeed3243fc1f Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 12 Jul 2006 14:25:50 +0000 Subject: r16980: - make struct smb_notify a union and add levels RAW_NOTIFY_NTTRANS,RAW_NOTIFY_SMB2 - parse SMB2 Notify reponse metze (This used to be commit de50e0ccddfad16ad7b254770f4c52c1abe707b9) --- source4/libcli/raw/interfaces.h | 65 ++++++++++++++++++++++++++++++++--------- source4/libcli/raw/rawnotify.c | 38 ++++++++++++++---------- 2 files changed, 74 insertions(+), 29 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index 8ebdd38bee..d3e7611c75 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -2128,23 +2128,60 @@ struct smb_nttrans { } out; }; +enum smb_notify_level { + RAW_NOTIFY_NTTRANS, + RAW_NOTIFY_SMB2 +}; -/* struct for nttrans change notify call */ -struct smb_notify { +union smb_notify { + /* struct for nttrans change notify call */ struct { - union smb_handle file; - uint32_t buffer_size; - uint32_t completion_filter; - BOOL recursive; - } in; + enum smb_notify_level level; - struct { - uint32_t num_changes; - struct notify_changes { - uint32_t action; - struct smb_wire_string name; - } *changes; - } out; + struct { + union smb_handle file; + uint32_t buffer_size; + uint32_t completion_filter; + BOOL recursive; + } in; + + struct { + uint32_t num_changes; + struct notify_changes { + uint32_t action; + struct smb_wire_string name; + } *changes; + } out; + } nttrans; + + struct smb2_notify { + enum smb_notify_level level; + + struct { + union smb_handle file; + /* static body buffer 32 (0x20) bytes */ + /* uint16_t buffer_code; 0x32 */ + uint16_t recursive; + uint32_t buffer_size; + /*struct smb2_handle file;*/ + uint32_t completion_filter; + uint32_t unknown; + } in; + + struct { + /* static body buffer 8 (0x08) bytes */ + /* uint16_t buffer_code; 0x09 = 0x08 + 1 */ + /* uint16_t blob_ofs; */ + /* uint16_t blob_size; */ + + /* dynamic body */ + /*DATA_BLOB blob;*/ + + /* DATA_BLOB content */ + uint32_t num_changes; + struct notify_changes *changes; + } out; + } smb2; }; enum smb_search_level { diff --git a/source4/libcli/raw/rawnotify.c b/source4/libcli/raw/rawnotify.c index f4d4164016..2b68d96a1b 100644 --- a/source4/libcli/raw/rawnotify.c +++ b/source4/libcli/raw/rawnotify.c @@ -25,19 +25,23 @@ /**************************************************************************** change notify (async send) ****************************************************************************/ -struct smbcli_request *smb_raw_changenotify_send(struct smbcli_tree *tree, struct smb_notify *parms) +struct smbcli_request *smb_raw_changenotify_send(struct smbcli_tree *tree, union smb_notify *parms) { struct smb_nttrans nt; uint16_t setup[4]; + if (parms->nttrans.level != RAW_NOTIFY_NTTRANS) { + return NULL; + } + nt.in.max_setup = 0; - nt.in.max_param = parms->in.buffer_size; + nt.in.max_param = parms->nttrans.in.buffer_size; nt.in.max_data = 0; nt.in.setup_count = 4; nt.in.setup = setup; - SIVAL(setup, 0, parms->in.completion_filter); - SSVAL(setup, 4, parms->in.file.fnum); - SSVAL(setup, 6, parms->in.recursive); + SIVAL(setup, 0, parms->nttrans.in.completion_filter); + SSVAL(setup, 4, parms->nttrans.in.file.fnum); + SSVAL(setup, 6, parms->nttrans.in.recursive); nt.in.function = NT_TRANSACT_NOTIFY_CHANGE; nt.in.params = data_blob(NULL, 0); nt.in.data = data_blob(NULL, 0); @@ -49,41 +53,45 @@ struct smbcli_request *smb_raw_changenotify_send(struct smbcli_tree *tree, struc change notify (async recv) ****************************************************************************/ NTSTATUS smb_raw_changenotify_recv(struct smbcli_request *req, - TALLOC_CTX *mem_ctx, struct smb_notify *parms) + TALLOC_CTX *mem_ctx, union smb_notify *parms) { struct smb_nttrans nt; NTSTATUS status; uint32_t ofs, i; struct smbcli_session *session = req?req->session:NULL; + if (parms->nttrans.level != RAW_NOTIFY_NTTRANS) { + return NT_STATUS_INVALID_LEVEL; + } + status = smb_raw_nttrans_recv(req, mem_ctx, &nt); if (!NT_STATUS_IS_OK(status)) { return status; } - parms->out.changes = NULL; - parms->out.num_changes = 0; + parms->nttrans.out.changes = NULL; + parms->nttrans.out.num_changes = 0; /* count them */ for (ofs=0; nt.out.params.length - ofs > 12; ) { uint32_t next = IVAL(nt.out.params.data, ofs); - parms->out.num_changes++; + parms->nttrans.out.num_changes++; if (next == 0 || ofs + next >= nt.out.params.length) break; ofs += next; } /* allocate array */ - parms->out.changes = talloc_array(mem_ctx, struct notify_changes, parms->out.num_changes); - if (!parms->out.changes) { + parms->nttrans.out.changes = talloc_array(mem_ctx, struct notify_changes, parms->nttrans.out.num_changes); + if (!parms->nttrans.out.changes) { return NT_STATUS_NO_MEMORY; } - for (i=ofs=0; iout.num_changes; i++) { - parms->out.changes[i].action = IVAL(nt.out.params.data, ofs+4); + for (i=ofs=0; inttrans.out.num_changes; i++) { + parms->nttrans.out.changes[i].action = IVAL(nt.out.params.data, ofs+4); smbcli_blob_pull_string(session, mem_ctx, &nt.out.params, - &parms->out.changes[i].name, - ofs+8, ofs+12, STR_UNICODE); + &parms->nttrans.out.changes[i].name, + ofs+8, ofs+12, STR_UNICODE); ofs += IVAL(nt.out.params.data, ofs); } -- cgit From 440d0487a6ad9a39630d7364eb54e46367207d05 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 13 Jul 2006 17:37:45 +0000 Subject: r17020: pass the real error to the failing requests metze (This used to be commit 49b96ac44a883c020c69df7a12df154dc4faa4d5) --- source4/libcli/raw/clitransport.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index fc257b9098..641ad38031 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -52,7 +52,7 @@ static void smbcli_transport_event_handler(struct event_context *ev, */ static int transport_destructor(struct smbcli_transport *transport) { - smbcli_transport_dead(transport); + smbcli_transport_dead(transport, NT_STATUS_LOCAL_DISCONNECT); return 0; } @@ -63,7 +63,7 @@ static int transport_destructor(struct smbcli_transport *transport) static void smbcli_transport_error(void *private, NTSTATUS status) { struct smbcli_transport *transport = talloc_get_type(private, struct smbcli_transport); - smbcli_transport_dead(transport); + smbcli_transport_dead(transport, status); } static NTSTATUS smbcli_transport_finish_recv(void *private, DATA_BLOB blob); @@ -130,15 +130,19 @@ struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock, /* mark the transport as dead */ -void smbcli_transport_dead(struct smbcli_transport *transport) +void smbcli_transport_dead(struct smbcli_transport *transport, NTSTATUS status) { smbcli_sock_dead(transport->socket); + if (NT_STATUS_EQUAL(NT_STATUS_UNSUCCESSFUL, status)) { + status = NT_STATUS_UNEXPECTED_NETWORK_ERROR; + } + /* kill all pending receives */ while (transport->pending_recv) { struct smbcli_request *req = transport->pending_recv; req->state = SMBCLI_REQUEST_ERROR; - req->status = NT_STATUS_NET_WRITE_FAULT; + req->status = status; DLIST_REMOVE(transport->pending_recv, req); if (req->async.fn) { req->async.fn(req); -- cgit From 0329d755a7611ba3897fc1ee9bdce410cc33d7f8 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 30 Aug 2006 11:29:34 +0000 Subject: r17930: Merge noinclude branch: * Move dlinklist.h, smb.h to subsystem-specific directories * Clean up ads.h and move what is left of it to dsdb/ (only place where it's used) (This used to be commit f7afa1cb77f3cfa7020b57de12e6003db7cfcc42) --- source4/libcli/raw/clitransport.c | 2 +- source4/libcli/raw/rawnotify.c | 2 +- source4/libcli/raw/rawrequest.c | 2 +- source4/libcli/raw/rawtrans.c | 2 +- source4/libcli/raw/smb.h | 593 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 597 insertions(+), 4 deletions(-) create mode 100644 source4/libcli/raw/smb.h (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 641ad38031..8c4c7f7c43 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -23,7 +23,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" #include "lib/socket/socket.h" -#include "dlinklist.h" +#include "lib/util/dlinklist.h" #include "lib/events/events.h" #include "lib/stream/packet.h" #include "librpc/gen_ndr/ndr_nbt.h" diff --git a/source4/libcli/raw/rawnotify.c b/source4/libcli/raw/rawnotify.c index 2b68d96a1b..5f3fa0f50e 100644 --- a/source4/libcli/raw/rawnotify.c +++ b/source4/libcli/raw/rawnotify.c @@ -20,7 +20,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" -#include "dlinklist.h" +#include "lib/util/dlinklist.h" /**************************************************************************** change notify (async send) diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index f042c7b581..3eab563a40 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -25,7 +25,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" -#include "dlinklist.h" +#include "lib/util/dlinklist.h" #include "lib/events/events.h" /* we over allocate the data buffer to prevent too many realloc calls */ diff --git a/source4/libcli/raw/rawtrans.c b/source4/libcli/raw/rawtrans.c index 53e80d4753..cd309e0736 100644 --- a/source4/libcli/raw/rawtrans.c +++ b/source4/libcli/raw/rawtrans.c @@ -20,7 +20,7 @@ */ #include "includes.h" -#include "dlinklist.h" +#include "lib/util/dlinklist.h" #include "libcli/raw/libcliraw.h" #define TORTURE_TRANS_DATA 0 diff --git a/source4/libcli/raw/smb.h b/source4/libcli/raw/smb.h new file mode 100644 index 0000000000..98e7eca581 --- /dev/null +++ b/source4/libcli/raw/smb.h @@ -0,0 +1,593 @@ +/* + Unix SMB/CIFS implementation. + SMB parameters and setup, plus a whole lot more. + + Copyright (C) Andrew Tridgell 1992-2000 + Copyright (C) John H Terpstra 1996-2002 + Copyright (C) Luke Kenneth Casson Leighton 1996-2000 + Copyright (C) Paul Ashton 1998-2000 + Copyright (C) Simo Sorce 2001-2002 + Copyright (C) Martin Pool 2002 + + 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. +*/ + +#ifndef _SMB_H +#define _SMB_H + +/* deny modes */ +#define DENY_DOS 0 +#define DENY_ALL 1 +#define DENY_WRITE 2 +#define DENY_READ 3 +#define DENY_NONE 4 +#define DENY_FCB 7 + +/* open modes */ +#define DOS_OPEN_RDONLY 0 +#define DOS_OPEN_WRONLY 1 +#define DOS_OPEN_RDWR 2 +#define DOS_OPEN_FCB 0xF + + +/**********************************/ +/* SMBopen field definitions */ +#define OPEN_FLAGS_DENY_MASK 0x70 +#define OPEN_FLAGS_DENY_DOS 0x00 +#define OPEN_FLAGS_DENY_ALL 0x10 +#define OPEN_FLAGS_DENY_WRITE 0x20 +#define OPEN_FLAGS_DENY_READ 0x30 +#define OPEN_FLAGS_DENY_NONE 0x40 + +#define OPEN_FLAGS_MODE_MASK 0x0F +#define OPEN_FLAGS_OPEN_READ 0 +#define OPEN_FLAGS_OPEN_WRITE 1 +#define OPEN_FLAGS_OPEN_RDWR 2 +#define OPEN_FLAGS_FCB 0xFF + + +/**********************************/ +/* SMBopenX field definitions */ + +/* OpenX Flags field. */ +#define OPENX_FLAGS_ADDITIONAL_INFO 0x01 +#define OPENX_FLAGS_REQUEST_OPLOCK 0x02 +#define OPENX_FLAGS_REQUEST_BATCH_OPLOCK 0x04 +#define OPENX_FLAGS_EA_LEN 0x08 +#define OPENX_FLAGS_EXTENDED_RETURN 0x10 + +/* desired access (open_mode), split info 4 4-bit nibbles */ +#define OPENX_MODE_ACCESS_MASK 0x000F +#define OPENX_MODE_ACCESS_READ 0x0000 +#define OPENX_MODE_ACCESS_WRITE 0x0001 +#define OPENX_MODE_ACCESS_RDWR 0x0002 +#define OPENX_MODE_ACCESS_EXEC 0x0003 +#define OPENX_MODE_ACCESS_FCB 0x000F + +#define OPENX_MODE_DENY_SHIFT 4 +#define OPENX_MODE_DENY_MASK (0xF << OPENX_MODE_DENY_SHIFT) +#define OPENX_MODE_DENY_DOS (DENY_DOS << OPENX_MODE_DENY_SHIFT) +#define OPENX_MODE_DENY_ALL (DENY_ALL << OPENX_MODE_DENY_SHIFT) +#define OPENX_MODE_DENY_WRITE (DENY_WRITE << OPENX_MODE_DENY_SHIFT) +#define OPENX_MODE_DENY_READ (DENY_READ << OPENX_MODE_DENY_SHIFT) +#define OPENX_MODE_DENY_NONE (DENY_NONE << OPENX_MODE_DENY_SHIFT) +#define OPENX_MODE_DENY_FCB (0xF << OPENX_MODE_DENY_SHIFT) + +#define OPENX_MODE_LOCALITY_MASK 0x0F00 /* what does this do? */ + +#define OPENX_MODE_NO_CACHE 0x1000 +#define OPENX_MODE_WRITE_THRU 0x4000 + +/* open function values */ +#define OPENX_OPEN_FUNC_MASK 0x3 +#define OPENX_OPEN_FUNC_FAIL 0x0 +#define OPENX_OPEN_FUNC_OPEN 0x1 +#define OPENX_OPEN_FUNC_TRUNC 0x2 + +/* The above can be OR'ed with... */ +#define OPENX_OPEN_FUNC_CREATE 0x10 + +/* openx action in reply */ +#define OPENX_ACTION_EXISTED 1 +#define OPENX_ACTION_CREATED 2 +#define OPENX_ACTION_TRUNCATED 3 + + +/**********************************/ +/* SMBntcreateX field definitions */ + +/* ntcreatex flags field. */ +#define NTCREATEX_FLAGS_REQUEST_OPLOCK 0x02 +#define NTCREATEX_FLAGS_REQUEST_BATCH_OPLOCK 0x04 +#define NTCREATEX_FLAGS_OPEN_DIRECTORY 0x08 /* TODO: opens parent? we need + a test suite for this */ +#define NTCREATEX_FLAGS_EXTENDED 0x10 + +/* the ntcreatex access_mask field + this is split into 4 pieces + AAAABBBBCCCCCCCCDDDDDDDDDDDDDDDD + A -> GENERIC_RIGHT_* + B -> SEC_RIGHT_* + C -> STD_RIGHT_* + D -> SA_RIGHT_* + + which set of SA_RIGHT_* bits is applicable depends on the type + of object. +*/ + + + +/* ntcreatex share_access field */ +#define NTCREATEX_SHARE_ACCESS_NONE 0 +#define NTCREATEX_SHARE_ACCESS_READ 1 +#define NTCREATEX_SHARE_ACCESS_WRITE 2 +#define NTCREATEX_SHARE_ACCESS_DELETE 4 + +/* ntcreatex open_disposition field */ +#define NTCREATEX_DISP_SUPERSEDE 0 /* supersede existing file (if it exists) */ +#define NTCREATEX_DISP_OPEN 1 /* if file exists open it, else fail */ +#define NTCREATEX_DISP_CREATE 2 /* if file exists fail, else create it */ +#define NTCREATEX_DISP_OPEN_IF 3 /* if file exists open it, else create it */ +#define NTCREATEX_DISP_OVERWRITE 4 /* if exists overwrite, else fail */ +#define NTCREATEX_DISP_OVERWRITE_IF 5 /* if exists overwrite, else create */ + +/* ntcreatex create_options field */ +#define NTCREATEX_OPTIONS_DIRECTORY 0x0001 +#define NTCREATEX_OPTIONS_WRITE_THROUGH 0x0002 +#define NTCREATEX_OPTIONS_SEQUENTIAL_ONLY 0x0004 +#define NTCREATEX_OPTIONS_SYNC_ALERT 0x0010 +#define NTCREATEX_OPTIONS_ASYNC_ALERT 0x0020 +#define NTCREATEX_OPTIONS_NON_DIRECTORY_FILE 0x0040 +#define NTCREATEX_OPTIONS_NO_EA_KNOWLEDGE 0x0200 +#define NTCREATEX_OPTIONS_EIGHT_DOT_THREE_ONLY 0x0400 +#define NTCREATEX_OPTIONS_RANDOM_ACCESS 0x0800 +#define NTCREATEX_OPTIONS_DELETE_ON_CLOSE 0x1000 +#define NTCREATEX_OPTIONS_OPEN_BY_FILE_ID 0x2000 +#define NTCREATEX_OPTIONS_UNKNOWN_400000 0x400000 + +/* create options these bits are for private use by backends, they are + not valid on the wire */ +#define NTCREATEX_OPTIONS_PRIVATE_MASK 0xFF000000 +#define NTCREATEX_OPTIONS_PRIVATE_DENY_DOS 0x01000000 +#define NTCREATEX_OPTIONS_PRIVATE_DENY_FCB 0x02000000 + + +/* ntcreatex impersonation field */ +#define NTCREATEX_IMPERSONATION_ANONYMOUS 0 +#define NTCREATEX_IMPERSONATION_IDENTIFICATION 1 +#define NTCREATEX_IMPERSONATION_IMPERSONATION 2 +#define NTCREATEX_IMPERSONATION_DELEGATION 3 + +/* ntcreatex security flags bit field */ +#define NTCREATEX_SECURITY_DYNAMIC 1 +#define NTCREATEX_SECURITY_ALL 2 + +/* ntcreatex create_action in reply */ +#define NTCREATEX_ACTION_EXISTED 1 +#define NTCREATEX_ACTION_CREATED 2 +#define NTCREATEX_ACTION_TRUNCATED 3 +/* the value 5 can also be returned when you try to create a directory with + incorrect parameters - what does it mean? maybe created temporary file? */ +#define NTCREATEX_ACTION_UNKNOWN 5 + +#define SMB_MAGIC 0x424D53FF /* 0xFF 'S' 'M' 'B' */ + +/* the basic packet size, assuming no words or bytes. Does not include the NBT header */ +#define MIN_SMB_SIZE 35 + +/* when using NBT encapsulation every packet has a 4 byte header */ +#define NBT_HDR_SIZE 4 + +/* offsets into message header for common items - NOTE: These have + changed from being offsets from the base of the NBT packet to the base of the SMB packet. + this has reduced all these values by 4 +*/ +#define HDR_COM 4 +#define HDR_RCLS 5 +#define HDR_REH 6 +#define HDR_ERR 7 +#define HDR_FLG 9 +#define HDR_FLG2 10 +#define HDR_PIDHIGH 12 +#define HDR_SS_FIELD 14 +#define HDR_TID 24 +#define HDR_PID 26 +#define HDR_UID 28 +#define HDR_MID 30 +#define HDR_WCT 32 +#define HDR_VWV 33 + + +/* types of buffers in core SMB protocol */ +#define SMB_DATA_BLOCK 0x1 +#define SMB_ASCII4 0x4 + + +/* flag defines. CIFS spec 3.1.1 */ +#define FLAG_SUPPORT_LOCKREAD 0x01 +#define FLAG_CLIENT_BUF_AVAIL 0x02 +#define FLAG_RESERVED 0x04 +#define FLAG_CASELESS_PATHNAMES 0x08 +#define FLAG_CANONICAL_PATHNAMES 0x10 +#define FLAG_REQUEST_OPLOCK 0x20 +#define FLAG_REQUEST_BATCH_OPLOCK 0x40 +#define FLAG_REPLY 0x80 + +/* the complete */ +#define SMBmkdir 0x00 /* create directory */ +#define SMBrmdir 0x01 /* delete directory */ +#define SMBopen 0x02 /* open file */ +#define SMBcreate 0x03 /* create file */ +#define SMBclose 0x04 /* close file */ +#define SMBflush 0x05 /* flush file */ +#define SMBunlink 0x06 /* delete file */ +#define SMBmv 0x07 /* rename file */ +#define SMBgetatr 0x08 /* get file attributes */ +#define SMBsetatr 0x09 /* set file attributes */ +#define SMBread 0x0A /* read from file */ +#define SMBwrite 0x0B /* write to file */ +#define SMBlock 0x0C /* lock byte range */ +#define SMBunlock 0x0D /* unlock byte range */ +#define SMBctemp 0x0E /* create temporary file */ +#define SMBmknew 0x0F /* make new file */ +#define SMBchkpth 0x10 /* check directory path */ +#define SMBexit 0x11 /* process exit */ +#define SMBlseek 0x12 /* seek */ +#define SMBtcon 0x70 /* tree connect */ +#define SMBtconX 0x75 /* tree connect and X*/ +#define SMBtdis 0x71 /* tree disconnect */ +#define SMBnegprot 0x72 /* negotiate protocol */ +#define SMBdskattr 0x80 /* get disk attributes */ +#define SMBsearch 0x81 /* search directory */ +#define SMBsplopen 0xC0 /* open print spool file */ +#define SMBsplwr 0xC1 /* write to print spool file */ +#define SMBsplclose 0xC2 /* close print spool file */ +#define SMBsplretq 0xC3 /* return print queue */ +#define SMBsends 0xD0 /* send single block message */ +#define SMBsendb 0xD1 /* send broadcast message */ +#define SMBfwdname 0xD2 /* forward user name */ +#define SMBcancelf 0xD3 /* cancel forward */ +#define SMBgetmac 0xD4 /* get machine name */ +#define SMBsendstrt 0xD5 /* send start of multi-block message */ +#define SMBsendend 0xD6 /* send end of multi-block message */ +#define SMBsendtxt 0xD7 /* send text of multi-block message */ + +/* Core+ protocol */ +#define SMBlockread 0x13 /* Lock a range and read */ +#define SMBwriteunlock 0x14 /* write then range then unlock it */ +#define SMBreadbraw 0x1a /* read a block of data with no smb header */ +#define SMBwritebraw 0x1d /* write a block of data with no smb header */ +#define SMBwritec 0x20 /* secondary write request */ +#define SMBwriteclose 0x2c /* write a file then close it */ + +/* dos extended protocol */ +#define SMBreadBraw 0x1A /* read block raw */ +#define SMBreadBmpx 0x1B /* read block multiplexed */ +#define SMBreadBs 0x1C /* read block (secondary response) */ +#define SMBwriteBraw 0x1D /* write block raw */ +#define SMBwriteBmpx 0x1E /* write block multiplexed */ +#define SMBwriteBs 0x1F /* write block (secondary request) */ +#define SMBwriteC 0x20 /* write complete response */ +#define SMBsetattrE 0x22 /* set file attributes expanded */ +#define SMBgetattrE 0x23 /* get file attributes expanded */ +#define SMBlockingX 0x24 /* lock/unlock byte ranges and X */ +#define SMBtrans 0x25 /* transaction - name, bytes in/out */ +#define SMBtranss 0x26 /* transaction (secondary request/response) */ +#define SMBioctl 0x27 /* IOCTL */ +#define SMBioctls 0x28 /* IOCTL (secondary request/response) */ +#define SMBcopy 0x29 /* copy */ +#define SMBmove 0x2A /* move */ +#define SMBecho 0x2B /* echo */ +#define SMBopenX 0x2D /* open and X */ +#define SMBreadX 0x2E /* read and X */ +#define SMBwriteX 0x2F /* write and X */ +#define SMBsesssetupX 0x73 /* Session Set Up & X (including User Logon) */ +#define SMBffirst 0x82 /* find first */ +#define SMBfunique 0x83 /* find unique */ +#define SMBfclose 0x84 /* find close */ +#define SMBkeepalive 0x85 /* keepalive */ +#define SMBinvalid 0xFE /* invalid command */ + +/* Extended 2.0 protocol */ +#define SMBtrans2 0x32 /* TRANS2 protocol set */ +#define SMBtranss2 0x33 /* TRANS2 protocol set, secondary command */ +#define SMBfindclose 0x34 /* Terminate a TRANSACT2_FINDFIRST */ +#define SMBfindnclose 0x35 /* Terminate a TRANSACT2_FINDNOTIFYFIRST */ +#define SMBulogoffX 0x74 /* user logoff */ + +/* NT SMB extensions. */ +#define SMBnttrans 0xA0 /* NT transact */ +#define SMBnttranss 0xA1 /* NT transact secondary */ +#define SMBntcreateX 0xA2 /* NT create and X */ +#define SMBntcancel 0xA4 /* NT cancel */ +#define SMBntrename 0xA5 /* NT rename */ + +/* used to indicate end of chain */ +#define SMB_CHAIN_NONE 0xFF + +/* These are the trans subcommands */ +#define TRANSACT_SETNAMEDPIPEHANDLESTATE 0x01 +#define TRANSACT_DCERPCCMD 0x26 +#define TRANSACT_WAITNAMEDPIPEHANDLESTATE 0x53 + +/* These are the NT transact sub commands. */ +#define NT_TRANSACT_CREATE 1 +#define NT_TRANSACT_IOCTL 2 +#define NT_TRANSACT_SET_SECURITY_DESC 3 +#define NT_TRANSACT_NOTIFY_CHANGE 4 +#define NT_TRANSACT_RENAME 5 +#define NT_TRANSACT_QUERY_SECURITY_DESC 6 + +/* this is used on a TConX. I'm not sure the name is very helpful though */ +#define SMB_SUPPORT_SEARCH_BITS 0x0001 +#define SMB_SHARE_IN_DFS 0x0002 + +/* Named pipe write mode flags. Used in writeX calls. */ +#define PIPE_RAW_MODE 0x4 +#define PIPE_START_MESSAGE 0x8 + +/* the desired access to use when opening a pipe */ +#define DESIRED_ACCESS_PIPE 0x2019f + + +/* Mapping of generic access rights for files to specific rights. */ +#define FILE_GENERIC_ALL (STANDARD_RIGHTS_REQUIRED_ACCESS| NT_ACCESS_SYNCHRONIZE_ACCESS|FILE_ALL_ACCESS) + +#define FILE_GENERIC_READ (STANDARD_RIGHTS_READ_ACCESS|FILE_READ_DATA|FILE_READ_ATTRIBUTES|\ + FILE_READ_EA|NT_ACCESS_SYNCHRONIZE_ACCESS) + +#define FILE_GENERIC_WRITE (STANDARD_RIGHTS_WRITE_ACCESS|FILE_WRITE_DATA|FILE_WRITE_ATTRIBUTES|\ + FILE_WRITE_EA|FILE_APPEND_DATA|NT_ACCESS_SYNCHRONIZE_ACCESS) + +#define FILE_GENERIC_EXECUTE (STANDARD_RIGHTS_EXECUTE_ACCESS|FILE_READ_ATTRIBUTES|\ + FILE_EXECUTE|NT_ACCESS_SYNCHRONIZE_ACCESS) + + +/* FileAttributes (search attributes) field */ +#define FILE_ATTRIBUTE_READONLY 0x0001 +#define FILE_ATTRIBUTE_HIDDEN 0x0002 +#define FILE_ATTRIBUTE_SYSTEM 0x0004 +#define FILE_ATTRIBUTE_VOLUME 0x0008 +#define FILE_ATTRIBUTE_DIRECTORY 0x0010 +#define FILE_ATTRIBUTE_ARCHIVE 0x0020 +#define FILE_ATTRIBUTE_DEVICE 0x0040 +#define FILE_ATTRIBUTE_NORMAL 0x0080 +#define FILE_ATTRIBUTE_TEMPORARY 0x0100 +#define FILE_ATTRIBUTE_SPARSE 0x0200 +#define FILE_ATTRIBUTE_REPARSE_POINT 0x0400 +#define FILE_ATTRIBUTE_COMPRESSED 0x0800 +#define FILE_ATTRIBUTE_OFFLINE 0x1000 +#define FILE_ATTRIBUTE_NONINDEXED 0x2000 +#define FILE_ATTRIBUTE_ENCRYPTED 0x4000 + +/* Flags - combined with attributes. */ +#define FILE_FLAG_WRITE_THROUGH 0x80000000L +#define FILE_FLAG_NO_BUFFERING 0x20000000L +#define FILE_FLAG_RANDOM_ACCESS 0x10000000L +#define FILE_FLAG_SEQUENTIAL_SCAN 0x08000000L +#define FILE_FLAG_DELETE_ON_CLOSE 0x04000000L +#define FILE_FLAG_BACKUP_SEMANTICS 0x02000000L /* only if backup/restore privilege? */ +#define FILE_FLAG_POSIX_SEMANTICS 0x01000000L + +/* Responses when opening a file. */ +#define FILE_WAS_SUPERSEDED 0 +#define FILE_WAS_OPENED 1 +#define FILE_WAS_CREATED 2 +#define FILE_WAS_OVERWRITTEN 3 + +/* File type flags */ +#define FILE_TYPE_DISK 0 +#define FILE_TYPE_BYTE_MODE_PIPE 1 +#define FILE_TYPE_MESSAGE_MODE_PIPE 2 +#define FILE_TYPE_PRINTER 3 +#define FILE_TYPE_COMM_DEVICE 4 +#define FILE_TYPE_UNKNOWN 0xFFFF + +/* Flag for NT transact rename call. */ +#define RENAME_REPLACE_IF_EXISTS 1 + +/* flags for SMBntrename call */ +#define RENAME_FLAG_MOVE_CLUSTER_INFORMATION 0x102 /* ???? */ +#define RENAME_FLAG_HARD_LINK 0x103 +#define RENAME_FLAG_RENAME 0x104 +#define RENAME_FLAG_COPY 0x105 + +/* Filesystem Attributes. */ +#define FILE_CASE_SENSITIVE_SEARCH 0x01 +#define FILE_CASE_PRESERVED_NAMES 0x02 +#define FILE_UNICODE_ON_DISK 0x04 +/* According to cifs9f, this is 4, not 8 */ +/* Acconding to testing, this actually sets the security attribute! */ +#define FILE_PERSISTENT_ACLS 0x08 +/* These entries added from cifs9f --tsb */ +#define FILE_FILE_COMPRESSION 0x10 +#define FILE_VOLUME_QUOTAS 0x20 +/* I think this is wrong. JRA #define FILE_DEVICE_IS_MOUNTED 0x20 */ +#define FILE_VOLUME_SPARSE_FILE 0x40 +#define FILE_VOLUME_IS_COMPRESSED 0x8000 + +/* ChangeNotify flags. */ +#define FILE_NOTIFY_CHANGE_FILE_NAME 0x00000001 +#define FILE_NOTIFY_CHANGE_DIR_NAME 0x00000002 +#define FILE_NOTIFY_CHANGE_ATTRIBUTES 0x00000004 +#define FILE_NOTIFY_CHANGE_SIZE 0x00000008 +#define FILE_NOTIFY_CHANGE_LAST_WRITE 0x00000010 +#define FILE_NOTIFY_CHANGE_LAST_ACCESS 0x00000020 +#define FILE_NOTIFY_CHANGE_CREATION 0x00000040 +#define FILE_NOTIFY_CHANGE_EA 0x00000080 +#define FILE_NOTIFY_CHANGE_SECURITY 0x00000100 +#define FILE_NOTIFY_CHANGE_STREAM_NAME 0x00000200 +#define FILE_NOTIFY_CHANGE_STREAM_SIZE 0x00000400 +#define FILE_NOTIFY_CHANGE_STREAM_WRITE 0x00000800 + +#define FILE_NOTIFY_CHANGE_NAME \ + (FILE_NOTIFY_CHANGE_FILE_NAME|FILE_NOTIFY_CHANGE_DIR_NAME) + +/* change notify action results */ +#define NOTIFY_ACTION_ADDED 1 +#define NOTIFY_ACTION_REMOVED 2 +#define NOTIFY_ACTION_MODIFIED 3 +#define NOTIFY_ACTION_OLD_NAME 4 +#define NOTIFY_ACTION_NEW_NAME 5 +#define NOTIFY_ACTION_ADDED_STREAM 6 +#define NOTIFY_ACTION_REMOVED_STREAM 7 +#define NOTIFY_ACTION_MODIFIED_STREAM 8 + +/* seek modes for smb_seek */ +#define SEEK_MODE_START 0 +#define SEEK_MODE_CURRENT 1 +#define SEEK_MODE_END 2 + +/* where to find the base of the SMB packet proper */ +/* REWRITE TODO: smb_base needs to be removed */ +#define smb_base(buf) (((char *)(buf))+4) + +/* we don't allow server strings to be longer than 48 characters as + otherwise NT will not honour the announce packets */ +#define MAX_SERVER_STRING_LENGTH 48 + +/* This was set by JHT in liaison with Jeremy Allison early 1997 + * History: + * Version 4.0 - never made public + * Version 4.10 - New to 1.9.16p2, lost in space 1.9.16p3 to 1.9.16p9 + * - Reappeared in 1.9.16p11 with fixed smbd services + * Version 4.20 - To indicate that nmbd and browsing now works better + * Version 4.50 - Set at release of samba-2.2.0 by JHT + * + * Note: In the presence of NT4.X do not set above 4.9 + * Setting this above 4.9 can have undesired side-effects. + * This may change again in Samba-3.0 after further testing. JHT + */ + +#define DEFAULT_MAJOR_VERSION 0x04 +#define DEFAULT_MINOR_VERSION 0x09 + +/* Browser Election Values */ +#define BROWSER_ELECTION_VERSION 0x010f +#define BROWSER_CONSTANT 0xaa55 + +/* Sercurity mode bits. */ +#define NEGOTIATE_SECURITY_USER_LEVEL 0x01 +#define NEGOTIATE_SECURITY_CHALLENGE_RESPONSE 0x02 +#define NEGOTIATE_SECURITY_SIGNATURES_ENABLED 0x04 +#define NEGOTIATE_SECURITY_SIGNATURES_REQUIRED 0x08 + +/* NT Flags2 bits - cifs6.txt section 3.1.2 */ +#define FLAGS2_LONG_PATH_COMPONENTS 0x0001 +#define FLAGS2_EXTENDED_ATTRIBUTES 0x0002 +#define FLAGS2_SMB_SECURITY_SIGNATURES 0x0004 +#define FLAGS2_IS_LONG_NAME 0x0040 +#define FLAGS2_EXTENDED_SECURITY 0x0800 +#define FLAGS2_DFS_PATHNAMES 0x1000 +#define FLAGS2_READ_PERMIT_EXECUTE 0x2000 +#define FLAGS2_32_BIT_ERROR_CODES 0x4000 +#define FLAGS2_UNICODE_STRINGS 0x8000 + + +/* CIFS protocol capabilities */ +#define CAP_RAW_MODE 0x00000001 +#define CAP_MPX_MODE 0x00000002 +#define CAP_UNICODE 0x00000004 +#define CAP_LARGE_FILES 0x00000008 +#define CAP_NT_SMBS 0x00000010 +#define CAP_RPC_REMOTE_APIS 0x00000020 +#define CAP_STATUS32 0x00000040 +#define CAP_LEVEL_II_OPLOCKS 0x00000080 +#define CAP_LOCK_AND_READ 0x00000100 +#define CAP_NT_FIND 0x00000200 +#define CAP_DFS 0x00001000 +#define CAP_W2K_SMBS 0x00002000 +#define CAP_LARGE_READX 0x00004000 +#define CAP_LARGE_WRITEX 0x00008000 +#define CAP_UNIX 0x00800000 /* Capabilities for UNIX extensions. Created by HP. */ +#define CAP_EXTENDED_SECURITY 0x80000000 + +/* + * Global value meaning that the smb_uid field should be + * ingored (in share level security and protocol level == CORE) + */ + +#define UID_FIELD_INVALID 0 + +/* Lock types. */ +#define LOCKING_ANDX_SHARED_LOCK 0x01 +#define LOCKING_ANDX_OPLOCK_RELEASE 0x02 +#define LOCKING_ANDX_CHANGE_LOCKTYPE 0x04 +#define LOCKING_ANDX_CANCEL_LOCK 0x08 +#define LOCKING_ANDX_LARGE_FILES 0x10 + +/* + * Bits we test with. + */ + +#define OPLOCK_NONE 0 +#define OPLOCK_EXCLUSIVE 1 +#define OPLOCK_BATCH 2 +#define OPLOCK_LEVEL_II 4 + +#define CORE_OPLOCK_GRANTED (1<<5) +#define EXTENDED_OPLOCK_GRANTED (1<<15) + +/* + * Return values for oplock types. + */ + +#define NO_OPLOCK_RETURN 0 +#define EXCLUSIVE_OPLOCK_RETURN 1 +#define BATCH_OPLOCK_RETURN 2 +#define LEVEL_II_OPLOCK_RETURN 3 + +/* oplock levels sent in oplock break */ +#define OPLOCK_BREAK_TO_NONE 0 +#define OPLOCK_BREAK_TO_LEVEL_II 1 + + +#define CMD_REPLY 0x8000 + +/* The maximum length of a trust account password. + Used when we randomly create it, 15 char passwords + exceed NT4's max password length */ + +#define DEFAULT_TRUST_ACCOUNT_PASSWORD_LENGTH 14 + + +/* + filesystem attribute bits +*/ +#define FS_ATTR_CASE_SENSITIVE_SEARCH 0x00000001 +#define FS_ATTR_CASE_PRESERVED_NAMES 0x00000002 +#define FS_ATTR_UNICODE_ON_DISK 0x00000004 +#define FS_ATTR_PERSISTANT_ACLS 0x00000008 +#define FS_ATTR_COMPRESSION 0x00000010 +#define FS_ATTR_QUOTAS 0x00000020 +#define FS_ATTR_SPARSE_FILES 0x00000040 +#define FS_ATTR_REPARSE_POINTS 0x00000080 +#define FS_ATTR_REMOTE_STORAGE 0x00000100 +#define FS_ATTR_LFN_SUPPORT 0x00004000 +#define FS_ATTR_IS_COMPRESSED 0x00008000 +#define FS_ATTR_OBJECT_IDS 0x00010000 +#define FS_ATTR_ENCRYPTION 0x00020000 +#define FS_ATTR_NAMED_STREAMS 0x00040000 + +#define smb_len(buf) (PVAL(buf,3)|(PVAL(buf,2)<<8)|(PVAL(buf,1)<<16)) +#define _smb_setlen(buf,len) do {(buf)[0] = 0; (buf)[1] = ((len)&0x10000)>>16; \ + (buf)[2] = ((len)&0xFF00)>>8; (buf)[3] = (len)&0xFF;} while (0) +#define _smb2_setlen(buf,len) do {(buf)[0] = 0; (buf)[1] = ((len)&0xFF0000)>>16; \ + (buf)[2] = ((len)&0xFF00)>>8; (buf)[3] = (len)&0xFF;} while (0) + +#include "libcli/raw/trans2.h" +#include "libcli/raw/interfaces.h" + +#endif /* _SMB_H */ -- cgit From 1b5c28a627fa7d5f185537c85a43c7629273a2d9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 7 Sep 2006 09:49:34 +0000 Subject: r18211: wct is not a size, so don't use size_t this should fix a pile of printf format warnings (This used to be commit fe209e360e3857f39355335e4fa6a43b2db23038) --- source4/libcli/raw/request.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/request.h b/source4/libcli/raw/request.h index fedebf4c8d..689a5281ce 100644 --- a/source4/libcli/raw/request.h +++ b/source4/libcli/raw/request.h @@ -45,7 +45,7 @@ struct request_buffer { /* the command words and command word count. vwv points into the raw buffer */ uint8_t *vwv; - size_t wct; + uint_t wct; /* the data buffer and size. data points into the raw buffer */ uint8_t *data; -- cgit From 30ee8beb9316a99e8a49993306252591106cb349 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 9 Sep 2006 10:05:58 +0000 Subject: r18301: I discovered how to load the warnings from a build farm build into emacs compile mode (hint, paste to a file, and compile as "cat filename"). This allowed me to fix nearly all the warnings for a IA_64 SuSE build very quickly. (This used to be commit eba6c84efff735bb0ca941ac4b755ce2b0591667) --- source4/libcli/raw/rawfile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c index f8b5e90e4b..3d2d407583 100644 --- a/source4/libcli/raw/rawfile.c +++ b/source4/libcli/raw/rawfile.c @@ -860,7 +860,7 @@ NTSTATUS smb_raw_chkpath(struct smbcli_tree *tree, union smb_chkpath *parms) struct smbcli_request *smb_raw_flush_send(struct smbcli_tree *tree, union smb_flush *parms) { struct smbcli_request *req; - uint16_t fnum; + uint16_t fnum=0; switch (parms->generic.level) { case RAW_FLUSH_FLUSH: -- cgit From 921f73c7e58eac1900eb7ec9f7276cd3afaf0480 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 23 Sep 2006 02:19:15 +0000 Subject: r18835: expand IO limits on SMB2. Samba4 now tops out at 16.7MB IOs. (This used to be commit 1e34e4d5a1fd3d74080424140e4ab276b6042d12) --- source4/libcli/raw/interfaces.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index d3e7611c75..c2f0c3530b 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -1589,7 +1589,7 @@ union smb_read { uint8_t *data; uint16_t remaining; uint16_t compaction_mode; - uint16_t nread; + uint32_t nread; } out; } readx, generic; -- cgit From c72c3e983468bdee33e4482e7b7ccb45cb7c9ddb Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 8 Dec 2006 03:47:02 +0000 Subject: r20077: support large readx replies, as done by samba3 (and the snia spec), but not done by windows servers (This used to be commit e5dbbe177c13b2788b4b4765b3b37cc918b3405c) --- source4/libcli/raw/rawreadwrite.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawreadwrite.c b/source4/libcli/raw/rawreadwrite.c index 7a47ce66f4..e7a3209d07 100644 --- a/source4/libcli/raw/rawreadwrite.c +++ b/source4/libcli/raw/rawreadwrite.c @@ -161,6 +161,20 @@ NTSTATUS smb_raw_read_recv(struct smbcli_request *req, union smb_read *parms) parms->readx.out.remaining = SVAL(req->in.vwv, VWV(2)); parms->readx.out.compaction_mode = SVAL(req->in.vwv, VWV(3)); parms->readx.out.nread = SVAL(req->in.vwv, VWV(5)); + + /* handle oversize replies for non-chained readx replies with + CAP_LARGE_READX. The snia spec has must to answer for. */ + if ((req->tree->session->transport->negotiate.capabilities & CAP_LARGE_READX) + && CVAL(req->in.vwv, VWV(0)) == SMB_CHAIN_NONE && + req->in.size >= 0x10000) { + parms->readx.out.nread += (SVAL(req->in.vwv, VWV(7)) << 16); + if (req->in.hdr + SVAL(req->in.vwv, VWV(6)) + + parms->readx.out.nread <= + req->in.buffer + req->in.size) { + req->in.data_size += (SVAL(req->in.vwv, VWV(7)) << 16); + } + } + if (parms->readx.out.nread > MAX(parms->readx.in.mincnt, parms->readx.in.maxcnt) || !smbcli_raw_pull_data(req, req->in.hdr + SVAL(req->in.vwv, VWV(6)), parms->readx.out.nread, -- cgit From f6274959ba381b6b5d025cb0cee78665107a72a6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 10 Jan 2007 11:16:11 +0000 Subject: r20647: add cluster code (This used to be commit 5870830b99a8d76bda1ff5af3fcf8dda9aba50ec) --- source4/libcli/raw/trans2.h | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/trans2.h b/source4/libcli/raw/trans2.h index a3f6e28a2a..a1a34ea118 100644 --- a/source4/libcli/raw/trans2.h +++ b/source4/libcli/raw/trans2.h @@ -1,3 +1,8 @@ +/* + NTFS filesystem internals + +*/ + /* Unix SMB/CIFS implementation. SMB transaction2 handling -- cgit From 1c211a2e43db46c649a963ec883481cc4321870a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 10 Jan 2007 11:50:33 +0000 Subject: r20650: revert a bunch of code I didn't mean to commit yet (This used to be commit b3e2d4908781781a487eaeb683d22eb967e5597d) --- source4/libcli/raw/trans2.h | 5 ----- 1 file changed, 5 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/trans2.h b/source4/libcli/raw/trans2.h index a1a34ea118..a3f6e28a2a 100644 --- a/source4/libcli/raw/trans2.h +++ b/source4/libcli/raw/trans2.h @@ -1,8 +1,3 @@ -/* - NTFS filesystem internals - -*/ - /* Unix SMB/CIFS implementation. SMB transaction2 handling -- cgit From c471abbcfe21e853f5664320c5b3498cdd4ad186 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 23 Jan 2007 01:29:17 +0000 Subject: r20963: remove unused functions, run LOCAL-TDR by default (This used to be commit 0f34c67fff53d5bd3c1b5a5618190ad7154e8d07) --- source4/libcli/raw/rawacl.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawacl.c b/source4/libcli/raw/rawacl.c index 6f35b7f829..1a2d75d274 100644 --- a/source4/libcli/raw/rawacl.c +++ b/source4/libcli/raw/rawacl.c @@ -131,12 +131,12 @@ struct smbcli_request *smb_raw_set_secdesc_send(struct smbcli_tree *tree, nt.in.params.data = params; nt.in.params.length = 8; - ndr = ndr_push_init(); + ndr = ndr_push_init_ctx(NULL); if (!ndr) return NULL; status = ndr_push_security_descriptor(ndr, NDR_SCALARS|NDR_BUFFERS, io->set_secdesc.in.sd); if (!NT_STATUS_IS_OK(status)) { - ndr_push_free(ndr); + talloc_free(ndr); return NULL; } @@ -144,7 +144,7 @@ struct smbcli_request *smb_raw_set_secdesc_send(struct smbcli_tree *tree, req = smb_raw_nttrans_send(tree, &nt); - ndr_push_free(ndr); + talloc_free(ndr); return req; } -- cgit From 2342219d699eb17d48a2b31c297121a158ba85d0 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 6 Feb 2007 18:16:10 +0000 Subject: r21183: Commit the big/little endian fix for nttrans setup[] handling. Please check! For code symmetry reasons, trans2 might also see this fix, but this is left to the interested reader :-) Volker (This used to be commit f2d364ebe69fc5d624e456cc7d941071811a5567) --- source4/libcli/raw/rawtrans.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawtrans.c b/source4/libcli/raw/rawtrans.c index cd309e0736..08d7483a87 100644 --- a/source4/libcli/raw/rawtrans.c +++ b/source4/libcli/raw/rawtrans.c @@ -555,7 +555,6 @@ struct smbcli_request *smb_raw_nttrans_send(struct smbcli_tree *tree, { struct smbcli_request *req; uint8_t *outdata, *outparam; - int i; int align = 0; /* only align if there are parameters or data */ @@ -592,9 +591,8 @@ struct smbcli_request *smb_raw_nttrans_send(struct smbcli_tree *tree, SIVAL(req->out.vwv, 31, PTR_DIFF(outdata,req->out.hdr)); SCVAL(req->out.vwv, 35, parms->in.setup_count); SSVAL(req->out.vwv, 36, parms->in.function); - for (i=0;iin.setup_count;i++) { - SSVAL(req->out.vwv,VWV(19+i),parms->in.setup[i]); - } + memcpy(req->out.vwv + VWV(19), parms->in.setup, + sizeof(uint16_t) * parms->in.setup_count); if (parms->in.params.length) { memcpy(outparam, parms->in.params.data, parms->in.params.length); } -- cgit From 21650cf3779f20aad808f8ce4e95daa7a2d0e1e7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 7 Feb 2007 00:21:29 +0000 Subject: r21206: - a couple more nttrans places were a memcpy() should be used - changed the setup array in nttrans to be a uint8 array, instead of a uint16 array. This makes it clearer that it is the job of the caller to do any byte swapping within that data (This used to be commit fa3c9b29ae1c7c6a9bc97484cc386aeec9b5d266) --- source4/libcli/raw/interfaces.h | 6 +++--- source4/libcli/raw/rawioctl.c | 2 +- source4/libcli/raw/rawnotify.c | 2 +- source4/libcli/raw/rawtrans.c | 9 ++++----- 4 files changed, 9 insertions(+), 10 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index c2f0c3530b..60cefe6931 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -2115,14 +2115,14 @@ struct smb_nttrans { uint32_t max_data; uint32_t setup_count; uint16_t function; - uint16_t *setup; + uint8_t *setup; DATA_BLOB params; DATA_BLOB data; } in; struct { - uint8_t setup_count; - uint16_t *setup; + uint8_t setup_count; /* in units of 16 bit words */ + uint8_t *setup; DATA_BLOB params; DATA_BLOB data; } out; diff --git a/source4/libcli/raw/rawioctl.c b/source4/libcli/raw/rawioctl.c index a9812022ea..9477af4eb2 100644 --- a/source4/libcli/raw/rawioctl.c +++ b/source4/libcli/raw/rawioctl.c @@ -79,7 +79,7 @@ static struct smbcli_request *smb_raw_ntioctl_send(struct smbcli_tree *tree, nt.in.max_param = 0; nt.in.max_data = parms->ntioctl.in.max_data; nt.in.setup_count = 4; - nt.in.setup = (uint16_t *)setup; + nt.in.setup = setup; SIVAL(setup, 0, parms->ntioctl.in.function); SSVAL(setup, 4, parms->ntioctl.in.file.fnum); SCVAL(setup, 6, parms->ntioctl.in.fsctl); diff --git a/source4/libcli/raw/rawnotify.c b/source4/libcli/raw/rawnotify.c index 5f3fa0f50e..e847368f73 100644 --- a/source4/libcli/raw/rawnotify.c +++ b/source4/libcli/raw/rawnotify.c @@ -28,7 +28,7 @@ change notify (async send) struct smbcli_request *smb_raw_changenotify_send(struct smbcli_tree *tree, union smb_notify *parms) { struct smb_nttrans nt; - uint16_t setup[4]; + uint8_t setup[8]; if (parms->nttrans.level != RAW_NOTIFY_NTTRANS) { return NULL; diff --git a/source4/libcli/raw/rawtrans.c b/source4/libcli/raw/rawtrans.c index 08d7483a87..164354c701 100644 --- a/source4/libcli/raw/rawtrans.c +++ b/source4/libcli/raw/rawtrans.c @@ -449,15 +449,14 @@ NTSTATUS smb_raw_nttrans_recv(struct smbcli_request *req, SMBCLI_CHECK_WCT(req, 18 + parms->out.setup_count); if (parms->out.setup_count > 0) { - int i; - parms->out.setup = talloc_array(mem_ctx, uint16_t, parms->out.setup_count); + parms->out.setup = talloc_array(mem_ctx, uint8_t, + parms->out.setup_count*2); if (!parms->out.setup) { req->status = NT_STATUS_NO_MEMORY; return smbcli_request_destroy(req); } - for (i=0;iout.setup_count;i++) { - parms->out.setup[i] = SVAL(req->in.vwv, VWV(18+i)); - } + memcpy(parms->out.setup, VWV(18) + (uint8_t *)req->out.vwv, + sizeof(uint16_t) * parms->out.setup_count); } while (recvd_data < total_data || -- cgit From fcaeedeff3c7d65f65da19440eb7b1ac01481167 Mon Sep 17 00:00:00 2001 From: James Peach Date: Fri, 2 Mar 2007 23:24:27 +0000 Subject: r21668: Add SMB_QFS_POSIX_WHOAMI to trans2.h so it's easy to find. Add convenience API to create an anonymous credential. Don't clobber cmdline_credentials in the UNIX-WHOAMI test. (This used to be commit 73cea4e0c66f57057ed12b07bbb94b4e783ba6bf) --- source4/libcli/raw/trans2.h | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/trans2.h b/source4/libcli/raw/trans2.h index a3f6e28a2a..bdc5bb2168 100644 --- a/source4/libcli/raw/trans2.h +++ b/source4/libcli/raw/trans2.h @@ -74,6 +74,7 @@ Found 4 aliased levels #define SMB_QFS_ATTRIBUTE_INFO 0x105 #define SMB_QFS_UNIX_INFO 0x200 #define SMB_QFS_POSIX_INFO 0x201 +#define SMB_QFS_POSIX_WHOAMI 0x202 #define SMB_QFS_VOLUME_INFORMATION 1001 #define SMB_QFS_SIZE_INFORMATION 1003 #define SMB_QFS_DEVICE_INFORMATION 1004 -- cgit From 754d416ea54e1e520aa035a759ec8e3975ab5354 Mon Sep 17 00:00:00 2001 From: James Peach Date: Mon, 5 Mar 2007 22:26:38 +0000 Subject: r21710: Add client support for the UNIX_INFO2 info level in the QueryFile, QueryPath and FindFirst calls. Add a new torture test to verify the server side. (This used to be commit 7f56da2d1fa0718e5282bb4aea7d9a63a62f0bc7) --- source4/libcli/raw/interfaces.h | 84 +++++++++++++++++++++++++++++++++++-- source4/libcli/raw/rawfileinfo.c | 21 ++++++++++ source4/libcli/raw/rawsearch.c | 67 ++++++++++++++++++++++------- source4/libcli/raw/rawsetfileinfo.c | 21 ++++++++++ source4/libcli/raw/trans2.h | 46 +++++++++++++++++--- 5 files changed, 214 insertions(+), 25 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index 60cefe6931..e4efab3375 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -3,6 +3,7 @@ SMB request interface structures Copyright (C) Andrew Tridgell 2003 Copyright (C) James J Myers 2003 + Copyright (C) James Peach 2007 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 @@ -426,6 +427,7 @@ enum smb_fileinfo_level { RAW_FILEINFO_STREAM_INFO = SMB_QFILEINFO_STREAM_INFO, RAW_FILEINFO_COMPRESSION_INFO = SMB_QFILEINFO_COMPRESSION_INFO, RAW_FILEINFO_UNIX_BASIC = SMB_QFILEINFO_UNIX_BASIC, + RAW_FILEINFO_UNIX_INFO2 = SMB_QFILEINFO_UNIX_INFO2, RAW_FILEINFO_UNIX_LINK = SMB_QFILEINFO_UNIX_LINK, RAW_FILEINFO_BASIC_INFORMATION = SMB_QFILEINFO_BASIC_INFORMATION, RAW_FILEINFO_STANDARD_INFORMATION = SMB_QFILEINFO_STANDARD_INFORMATION, @@ -745,6 +747,32 @@ union smb_fileinfo { } out; } unix_basic_info; + /* RAW_FILEINFO_UNIX_INFO2 interface */ + struct { + enum smb_fileinfo_level level; + struct { + union smb_handle_or_path file; + } in; + struct { + uint64_t end_of_file; + uint64_t num_bytes; + NTTIME status_change_time; + NTTIME access_time; + NTTIME change_time; + uint64_t uid; + uint64_t gid; + uint32_t file_type; + uint64_t dev_major; + uint64_t dev_minor; + uint64_t unique_id; + uint64_t permissions; + uint64_t nlink; + NTTIME create_time; + uint32_t file_flags; + uint32_t flags_mask; + } out; + } unix_info2; + /* RAW_FILEINFO_UNIX_LINK interface */ struct { enum smb_fileinfo_level level; @@ -867,6 +895,7 @@ enum smb_setfileinfo_level { RAW_SFILEINFO_ALLOCATION_INFO = SMB_SFILEINFO_ALLOCATION_INFO, RAW_SFILEINFO_END_OF_FILE_INFO = SMB_SFILEINFO_END_OF_FILE_INFO, RAW_SFILEINFO_UNIX_BASIC = SMB_SFILEINFO_UNIX_BASIC, + RAW_SFILEINFO_UNIX_INFO2 = SMB_SFILEINFO_UNIX_INFO2, RAW_SFILEINFO_UNIX_LINK = SMB_SFILEINFO_UNIX_LINK, RAW_SFILEINFO_UNIX_HLINK = SMB_SFILEINFO_UNIX_HLINK, RAW_SFILEINFO_BASIC_INFORMATION = SMB_SFILEINFO_BASIC_INFORMATION, @@ -1003,8 +1032,6 @@ union smb_setfileinfo { } in; } mode_information; - - /* RAW_SFILEINFO_UNIX_BASIC interface */ struct { enum smb_setfileinfo_level level; @@ -1026,7 +1053,31 @@ union smb_setfileinfo { uint64_t nlink; } in; } unix_basic; - + + /* RAW_SFILEINFO_UNIX_INFO2 interface */ + struct { + enum smb_setfileinfo_level level; + struct { + union smb_handle_or_path file; + uint64_t end_of_file; + uint64_t num_bytes; + NTTIME status_change_time; + NTTIME access_time; + NTTIME change_time; + uint64_t uid; + uint64_t gid; + uint32_t file_type; + uint64_t dev_major; + uint64_t dev_minor; + uint64_t unique_id; + uint64_t permissions; + uint64_t nlink; + NTTIME create_time; + uint32_t file_flags; + uint32_t flags_mask; + } in; + } unix_info2; + /* RAW_SFILEINFO_UNIX_LINK, RAW_SFILEINFO_UNIX_HLINK interface */ struct { enum smb_setfileinfo_level level; @@ -2204,7 +2255,8 @@ enum smb_search_data_level { RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO = SMB_FIND_BOTH_DIRECTORY_INFO, RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO = SMB_FIND_ID_FULL_DIRECTORY_INFO, RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO = SMB_FIND_ID_BOTH_DIRECTORY_INFO, - RAW_SEARCH_DATA_UNIX_INFO = SMB_FIND_UNIX_INFO + RAW_SEARCH_DATA_UNIX_INFO = SMB_FIND_UNIX_INFO, + RAW_SEARCH_DATA_UNIX_INFO2 = SMB_FIND_UNIX_INFO2 }; /* union for file search */ @@ -2504,8 +2556,32 @@ union smb_search_data { uint64_t nlink; const char *name; } unix_info; + + /* RAW_SEARCH_DATA_UNIX_INFO2 interface */ + struct { + uint32_t file_index; + uint64_t end_of_file; + uint64_t num_bytes; + NTTIME status_change_time; + NTTIME access_time; + NTTIME change_time; + uint64_t uid; + uint64_t gid; + uint32_t file_type; + uint64_t dev_major; + uint64_t dev_minor; + uint64_t unique_id; + uint64_t permissions; + uint64_t nlink; + NTTIME create_time; + uint32_t file_flags; + uint32_t flags_mask; + const char *name; + } unix_info2; }; +/* Callback function passed to the raw search interface. */ +typedef BOOL (*smbcli_search_callback)(void *private, const union smb_search_data *file); enum smb_search_close_level {RAW_FINDCLOSE_GENERIC, RAW_FINDCLOSE_FCLOSE, RAW_FINDCLOSE_FINDCLOSE}; diff --git a/source4/libcli/raw/rawfileinfo.c b/source4/libcli/raw/rawfileinfo.c index 38f4d12369..7b15ce6fd6 100644 --- a/source4/libcli/raw/rawfileinfo.c +++ b/source4/libcli/raw/rawfileinfo.c @@ -3,6 +3,7 @@ client trans2 operations Copyright (C) James Myers 2003 Copyright (C) Andrew Tridgell 2003 + Copyright (C) James Peach 2007 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 @@ -403,6 +404,26 @@ static NTSTATUS smb_raw_info_backend(struct smbcli_session *session, parms->unix_basic_info.out.nlink = BVAL(blob->data, 92); return NT_STATUS_OK; + case RAW_FILEINFO_UNIX_INFO2: + FINFO_CHECK_SIZE(116); + parms->unix_info2.out.end_of_file = BVAL(blob->data, 0); + parms->unix_info2.out.num_bytes = BVAL(blob->data, 8); + parms->unix_info2.out.status_change_time = smbcli_pull_nttime(blob->data, 16); + parms->unix_info2.out.access_time = smbcli_pull_nttime(blob->data, 24); + parms->unix_info2.out.change_time = smbcli_pull_nttime(blob->data, 32); + parms->unix_info2.out.uid = BVAL(blob->data, 40); + parms->unix_info2.out.gid = BVAL(blob->data, 48); + parms->unix_info2.out.file_type = IVAL(blob->data, 52); + parms->unix_info2.out.dev_major = BVAL(blob->data, 60); + parms->unix_info2.out.dev_minor = BVAL(blob->data, 68); + parms->unix_info2.out.unique_id = BVAL(blob->data, 76); + parms->unix_info2.out.permissions = BVAL(blob->data, 84); + parms->unix_info2.out.nlink = BVAL(blob->data, 92); + parms->unix_info2.out.create_time = smbcli_pull_nttime(blob->data, 100); + parms->unix_info2.out.file_flags = IVAL(blob->data, 108); + parms->unix_info2.out.flags_mask = IVAL(blob->data, 112); + return NT_STATUS_OK; + case RAW_FILEINFO_UNIX_LINK: smbcli_blob_pull_string(session, mem_ctx, blob, &parms->unix_link_info.out.link_dest, 0, 4, STR_UNICODE); diff --git a/source4/libcli/raw/rawsearch.c b/source4/libcli/raw/rawsearch.c index 4836766a93..5abe19d50c 100644 --- a/source4/libcli/raw/rawsearch.c +++ b/source4/libcli/raw/rawsearch.c @@ -2,6 +2,7 @@ Unix SMB/CIFS implementation. client directory search routines Copyright (C) James Myers 2003 + Copyright (C) James Peach 2007 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 @@ -28,7 +29,7 @@ static void smb_raw_search_backend(struct smbcli_request *req, TALLOC_CTX *mem_ctx, uint16_t count, void *private, - BOOL (*callback)(void *private, union smb_search_data *file)) + smbcli_search_callback callback) { union smb_search_data search_data; @@ -69,7 +70,7 @@ static void smb_raw_search_backend(struct smbcli_request *req, static NTSTATUS smb_raw_search_first_old(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_search_first *io, void *private, - BOOL (*callback)(void *private, union smb_search_data *file)) + smbcli_search_callback callback) { struct smbcli_request *req; @@ -110,7 +111,7 @@ static NTSTATUS smb_raw_search_first_old(struct smbcli_tree *tree, static NTSTATUS smb_raw_search_next_old(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_search_next *io, void *private, - BOOL (*callback)(void *private, union smb_search_data *file)) + smbcli_search_callback callback) { struct smbcli_request *req; @@ -605,17 +606,51 @@ static int parse_trans2_search(struct smbcli_tree *tree, } return ofs; - case RAW_SEARCH_DATA_DIRECTORY_INFO: - case RAW_SEARCH_DATA_FULL_DIRECTORY_INFO: - case RAW_SEARCH_DATA_NAME_INFO: - case RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO: - case RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO: - case RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO: { - uint_t str_flags = STR_UNICODE; - if (!(tree->session->transport->negotiate.capabilities & CAP_UNICODE)) { - str_flags = STR_ASCII; + case RAW_SEARCH_DATA_UNIX_INFO2: + if (blob->length < (116 + 8 + 1)) { + return -1; } - + + ofs = IVAL(blob->data, 0); + data->unix_info2.file_index = IVAL(blob->data, 4); + data->unix_info2.end_of_file = BVAL(blob->data, 8); + data->unix_info2.num_bytes = BVAL(blob->data, 16); + data->unix_info2.status_change_time = smbcli_pull_nttime(blob->data, 24); + data->unix_info2.access_time = smbcli_pull_nttime(blob->data, 32); + data->unix_info2.change_time = smbcli_pull_nttime(blob->data, 40); + data->unix_info2.uid = IVAL(blob->data, 48); + data->unix_info2.gid = IVAL(blob->data, 56); + data->unix_info2.file_type = IVAL(blob->data, 64); + data->unix_info2.dev_major = BVAL(blob->data, 68); + data->unix_info2.dev_minor = BVAL(blob->data, 76); + data->unix_info2.unique_id = BVAL(blob->data, 84); + data->unix_info2.permissions = IVAL(blob->data, 92); + data->unix_info2.nlink = IVAL(blob->data, 100); + data->unix_info2.create_time = smbcli_pull_nttime(blob->data, 108); + data->unix_info2.file_flags = IVAL(blob->data, 116); + data->unix_info2.flags_mask = IVAL(blob->data, 120); + + /* There is no length field for this name but we know it's null terminated. */ + len = smbcli_blob_pull_unix_string(tree->session, mem_ctx, blob, + &data->unix_info2.name, 116 + 8, 0); + + if (ofs != 0 && ofs < (116 + 8 + len)) { + return -1; + } + + return ofs; + + case RAW_SEARCH_DATA_DIRECTORY_INFO: + case RAW_SEARCH_DATA_FULL_DIRECTORY_INFO: + case RAW_SEARCH_DATA_NAME_INFO: + case RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO: + case RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO: + case RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO: { + uint_t str_flags = STR_UNICODE; + if (!(tree->session->transport->negotiate.capabilities & CAP_UNICODE)) { + str_flags = STR_ASCII; + } + status = smb_raw_search_common(mem_ctx, level, blob, data, &ofs, str_flags); if (!NT_STATUS_IS_OK(status)) { return -1; @@ -638,7 +673,7 @@ static NTSTATUS smb_raw_t2search_backend(struct smbcli_tree *tree, int16_t count, DATA_BLOB *blob, void *private, - BOOL (*callback)(void *private, union smb_search_data *file)) + smbcli_search_callback callback) { int i; @@ -677,7 +712,7 @@ static NTSTATUS smb_raw_t2search_backend(struct smbcli_tree *tree, NTSTATUS smb_raw_search_first(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_search_first *io, void *private, - BOOL (*callback)(void *private, union smb_search_data *file)) + smbcli_search_callback callback) { DATA_BLOB p_blob, d_blob; NTSTATUS status; @@ -725,7 +760,7 @@ NTSTATUS smb_raw_search_first(struct smbcli_tree *tree, NTSTATUS smb_raw_search_next(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_search_next *io, void *private, - BOOL (*callback)(void *private, union smb_search_data *file)) + smbcli_search_callback callback) { DATA_BLOB p_blob, d_blob; NTSTATUS status; diff --git a/source4/libcli/raw/rawsetfileinfo.c b/source4/libcli/raw/rawsetfileinfo.c index 0daf14e0cc..794ba25480 100644 --- a/source4/libcli/raw/rawsetfileinfo.c +++ b/source4/libcli/raw/rawsetfileinfo.c @@ -3,6 +3,7 @@ RAW_SFILEINFO_* calls Copyright (C) James Myers 2003 Copyright (C) Andrew Tridgell 2003 + Copyright (C) James Peach 2007 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 @@ -166,6 +167,26 @@ static BOOL smb_raw_setinfo_backend(struct smbcli_tree *tree, SBVAL(blob->data, 92, parms->unix_basic.in.nlink); return True; + case RAW_SFILEINFO_UNIX_INFO2: + NEED_BLOB(116); + SBVAL(blob->data, 0, parms->unix_info2.in.end_of_file); + SBVAL(blob->data, 8, parms->unix_info2.in.num_bytes); + smbcli_push_nttime(blob->data, 16, parms->unix_info2.in.status_change_time); + smbcli_push_nttime(blob->data, 24, parms->unix_info2.in.access_time); + smbcli_push_nttime(blob->data, 32, parms->unix_info2.in.change_time); + SBVAL(blob->data, 40,parms->unix_info2.in.uid); + SBVAL(blob->data, 48,parms->unix_info2.in.gid); + SIVAL(blob->data, 52,parms->unix_info2.in.file_type); + SBVAL(blob->data, 60,parms->unix_info2.in.dev_major); + SBVAL(blob->data, 68,parms->unix_info2.in.dev_minor); + SBVAL(blob->data, 76,parms->unix_info2.in.unique_id); + SBVAL(blob->data, 84,parms->unix_info2.in.permissions); + SBVAL(blob->data, 92,parms->unix_info2.in.nlink); + smbcli_push_nttime(blob->data, 100, parms->unix_info2.in.create_time); + SIVAL(blob->data, 108, parms->unix_info2.in.file_flags); + SIVAL(blob->data, 112, parms->unix_info2.in.flags_mask); + return True; + case RAW_SFILEINFO_DISPOSITION_INFO: case RAW_SFILEINFO_DISPOSITION_INFORMATION: return smb_raw_setfileinfo_passthru(mem_ctx, RAW_SFILEINFO_DISPOSITION_INFORMATION, diff --git a/source4/libcli/raw/trans2.h b/source4/libcli/raw/trans2.h index bdc5bb2168..e4e85b58bc 100644 --- a/source4/libcli/raw/trans2.h +++ b/source4/libcli/raw/trans2.h @@ -3,6 +3,7 @@ SMB transaction2 handling Copyright (C) Jeremy Allison 1994-2002. Copyright (C) Andrew Tridgell 1995-2003. + Copyright (C) James Peach 2007 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 @@ -141,6 +142,7 @@ Found 8 aliased levels #define SMB_QFILEINFO_COMPRESSION_INFO 0x10b #define SMB_QFILEINFO_UNIX_BASIC 0x200 #define SMB_QFILEINFO_UNIX_LINK 0x201 +#define SMB_QFILEINFO_UNIX_INFO2 0x20b #define SMB_QFILEINFO_BASIC_INFORMATION 1004 #define SMB_QFILEINFO_STANDARD_INFORMATION 1005 #define SMB_QFILEINFO_INTERNAL_INFORMATION 1006 @@ -213,6 +215,7 @@ Found 13 valid levels #define SMB_SPATHINFO_POSIX_ACL 0x204 #define SMB_SPATHINFO_XATTR 0x205 #define SMB_SFILEINFO_ATTR_FLAGS 0x206 +#define SMB_SFILEINFO_UNIX_INFO2 0x20b #define SMB_SFILEINFO_BASIC_INFORMATION 1004 #define SMB_SFILEINFO_RENAME_INFORMATION 1010 #define SMB_SFILEINFO_DISPOSITION_INFORMATION 1013 @@ -267,6 +270,7 @@ Found 0 aliased levels #define SMB_FIND_ID_FULL_DIRECTORY_INFO 0x105 #define SMB_FIND_ID_BOTH_DIRECTORY_INFO 0x106 #define SMB_FIND_UNIX_INFO 0x202 +#define SMB_FIND_UNIX_INFO2 0x20b /* flags on trans2 findfirst/findnext that control search */ #define FLAG_TRANS2_FIND_CLOSE 0x1 @@ -321,9 +325,6 @@ Found 0 aliased levels #define INFO_LEVEL_IS_UNIX(level) (((level) >= MIN_UNIX_INFO_LEVEL) && ((level) <= MAX_UNIX_INFO_LEVEL)) -#define SMB_QFILEINFO_UNIX_BASIC 0x200 /* UNIX File Info*/ -#define SMB_SFILEINFO_UNIX_BASIC 0x200 - #define SMB_MODE_NO_CHANGE 0xFFFFFFFF /* file mode value which */ /* means "don't change it" */ #define SMB_UID_NO_CHANGE 0xFFFFFFFF @@ -336,6 +337,8 @@ Found 0 aliased levels #define SMB_TIME_NO_CHANGE_HI 0xFFFFFFFF /* +UNIX_BASIC info level: + Offset Size Name 0 LARGE_INTEGER EndOfFile File size 8 LARGE_INTEGER Blocks Number of bytes used on disk (st_blocks). @@ -365,6 +368,31 @@ Offset Size Name 100 - end. */ +/* +SMB_QUERY_FILE_UNIX_INFO2 is SMB_QUERY_FILE_UNIX_BASIC with create +time and file flags appended. The corresponding info level for +findfirst/findnext is SMB_FIND_FILE_UNIX_UNIX2. + +Size Offset Value +--------------------- +0 LARGE_INTEGER EndOfFile File size +8 LARGE_INTEGER Blocks Number of blocks used on disk +16 LARGE_INTEGER ChangeTime Attribute change time +24 LARGE_INTEGER LastAccessTime Last access time +32 LARGE_INTEGER LastModificationTime Last modification time +40 LARGE_INTEGER Uid Numeric user id for the owner +48 LARGE_INTEGER Gid Numeric group id of owner +56 ULONG Type Enumeration specifying the file type +60 LARGE_INTEGER devmajor Major device number if type is device +68 LARGE_INTEGER devminor Minor device number if type is device +76 LARGE_INTEGER uniqueid This is a server-assigned unique id +84 LARGE_INTEGER permissions Standard UNIX permissions +92 LARGE_INTEGER nlinks Number of hard link) +100 LARGE_INTEGER CreationTime Create/birth time +108 ULONG FileFlags File flags enumeration +112 ULONG FileFlagsMask Mask of valid flags +*/ + /* UNIX filetype mappings. */ #define UNIX_TYPE_FILE 0 @@ -404,12 +432,20 @@ Offset Size Name #define UNIX_EXTRA_MASK 0007000 #define UNIX_ALL_MASK 0007777 +/* Flags for the file_flags field in UNIX_INFO2: */ +#define EXT_SECURE_DELETE 0x00000001 +#define EXT_ENABLE_UNDELETE 0x00000002 +#define EXT_SYNCHRONOUS 0x00000004 +#define EXT_IMMUTABLE 0x00000008 +#define EXT_OPEN_APPEND_ONLY 0x00000010 +#define EXT_DO_NOT_BACKUP 0x00000020 +#define EXT_NO_UPDATE_ATIME 0x00000040 +#define EXT_HIDDEN 0x00000080 + #define SMB_QFILEINFO_UNIX_LINK 0x201 #define SMB_SFILEINFO_UNIX_LINK 0x201 #define SMB_SFILEINFO_UNIX_HLINK 0x203 -#define SMB_FIND_FILE_UNIX 0x202 - /* Info level for QVOLINFO - returns version of CIFS UNIX extensions, plus 64-bits worth of capability fun :-). -- cgit From c61db93c7e2d46ac0fd1a0f98199c111fd416a9b Mon Sep 17 00:00:00 2001 From: James Peach Date: Fri, 23 Mar 2007 19:24:21 +0000 Subject: r21949: After discussion with the Apple and Linux client maintainers, changing the FindFirst response for the UNIX_INFO2 level to include a length field before the name. The name is not required to be null terminated. the lenght field does not count any null. (This used to be commit eef672bfff6b112ceceec2a58c78042352e83276) --- source4/libcli/raw/interfaces.h | 2 +- source4/libcli/raw/rawsearch.c | 20 +++++++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index e4efab3375..4620baed78 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -2576,7 +2576,7 @@ union smb_search_data { NTTIME create_time; uint32_t file_flags; uint32_t flags_mask; - const char *name; + struct smb_wire_string name; } unix_info2; }; diff --git a/source4/libcli/raw/rawsearch.c b/source4/libcli/raw/rawsearch.c index 5abe19d50c..3c7ca5788e 100644 --- a/source4/libcli/raw/rawsearch.c +++ b/source4/libcli/raw/rawsearch.c @@ -607,7 +607,12 @@ static int parse_trans2_search(struct smbcli_tree *tree, return ofs; case RAW_SEARCH_DATA_UNIX_INFO2: - if (blob->length < (116 + 8 + 1)) { + /* 8 - size of ofs + file_index + * 116 - size of unix_info2 + * 4 - size of name length + * 2 - "." is the shortest name + */ + if (blob->length < (116 + 8 + 4 + 2)) { return -1; } @@ -630,11 +635,16 @@ static int parse_trans2_search(struct smbcli_tree *tree, data->unix_info2.file_flags = IVAL(blob->data, 116); data->unix_info2.flags_mask = IVAL(blob->data, 120); - /* There is no length field for this name but we know it's null terminated. */ - len = smbcli_blob_pull_unix_string(tree->session, mem_ctx, blob, - &data->unix_info2.name, 116 + 8, 0); + /* There is a 4 byte length field for this name. The length + * does not include the NULL terminator. + */ + len = smbcli_blob_pull_string(tree->session, mem_ctx, blob, + &data->unix_info2.name, + 8 + 116, /* offset to length */ + 8 + 116 + 4, /* offset to string */ + 0); - if (ofs != 0 && ofs < (116 + 8 + len)) { + if (ofs != 0 && ofs < (8 + 116 + 4 + len)) { return -1; } -- cgit From e1635caaf38b69cc0b237ebbc6c2dff08ac7e285 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 11 May 2007 10:03:04 +0000 Subject: r22790: fix initialization for chained requests metze (This used to be commit e1cc933c009f98264c0e8c65bfd93a0d1219a0e2) --- source4/libcli/raw/rawrequest.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 3eab563a40..7d1bfdb30d 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -268,6 +268,7 @@ NTSTATUS smbcli_chained_request_setup(struct smbcli_request *req, SSVAL(req->out.vwv, VWV(wct), buflen); req->out.size += new_size; + req->out.data_size += new_size; return NT_STATUS_OK; } -- cgit From 5151068d5a98a143dd77bddeb3af2a4775cb959d Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 14 May 2007 17:08:18 +0000 Subject: r22858: - let SMB2-LOCK-VALID-REQUEST pass against longhorn beta3 - add modify the SMB2-LOCK-BLOCK-WRITE test to also test reading and name in SMB2-LOCK-RW-EXCLUSIV - add SMB2-LOCK-NONE and SMB2-LOCK-SHARED metze (This used to be commit 258555975d3877cff3bc3022f3439cdd61f6c8ac) --- source4/libcli/raw/interfaces.h | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index 4620baed78..d0c3ab2d15 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -1889,11 +1889,12 @@ union smb_lock { uint64_t offset; uint64_t count; uint32_t unknown5; -#define SMB2_LOCK_FLAG_NONE 0x00000000 -#define SMB2_LOCK_FLAG_EXCLUSIV 0x00000002 -#define SMB2_LOCK_FLAG_UNLOCK 0x00000004 -#define SMB2_LOCK_FLAGS_MASK 0x00000006 - uint32_t flags; +#define SMB2_LOCK_FLAG_NONE 0x00000000 +#define SMB2_LOCK_FLAG_SHARED 0x00000001 +#define SMB2_LOCK_FLAG_EXCLUSIV 0x00000002 +#define SMB2_LOCK_FLAG_UNLOCK 0x00000004 +#define SMB2_LOCK_FLAG_NO_PENDING 0x00000010 + uint32_t flags; } in; struct { /* static body buffer 4 (0x04) bytes */ -- cgit From 31f047f734d763ac6661f33afae8f39cf2fd4bd4 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 21 May 2007 23:35:14 +0000 Subject: r23057: only call the async recv function for the first pending receive, not all pending receives, when the transport dies. This is because the async callback most commonly shuts down the connection (it's the only reasonable thing to do when it's dead), and that frees the whole context. That means that if we loop more than once, we'll end up using freed memory. (This used to be commit 75d537d3a5e3fc5258ce48bfec0c0ce6160978f6) --- source4/libcli/raw/clitransport.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 8c4c7f7c43..ea2aa880b6 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -138,8 +138,11 @@ void smbcli_transport_dead(struct smbcli_transport *transport, NTSTATUS status) status = NT_STATUS_UNEXPECTED_NETWORK_ERROR; } - /* kill all pending receives */ - while (transport->pending_recv) { + /* kill only the first pending receive - this is so that if + that async function frees the connection we don't die trying + to use old memory. The caller has to cope with only one + network error */ + if (transport->pending_recv) { struct smbcli_request *req = transport->pending_recv; req->state = SMBCLI_REQUEST_ERROR; req->status = status; -- cgit From c31e144a2d7cb24b866bf95cb27da80f8728c857 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 25 May 2007 10:42:29 +0000 Subject: r23138: added a raw interface for SMBecho operations (This used to be commit 590c6c21db5abd436441a9af62ee65436d6f1222) --- source4/libcli/raw/clitransport.c | 68 +++++++++++++++++++++++++++++++++++++++ source4/libcli/raw/interfaces.h | 18 +++++++++++ 2 files changed, 86 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index ea2aa880b6..71c87e631a 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -593,3 +593,71 @@ void smbcli_transport_send(struct smbcli_request *req) talloc_set_destructor(req, smbcli_request_destructor); } + + +/**************************************************************************** + Send an SMBecho (async send) +*****************************************************************************/ +struct smbcli_request *smb_raw_echo_send(struct smbcli_transport *transport, + struct smb_echo *p) +{ + struct smbcli_request *req; + + req = smbcli_request_setup_transport(transport, SMBecho, 1, p->in.size); + if (!req) return NULL; + + SSVAL(req->out.vwv, VWV(0), p->in.repeat_count); + + memcpy(req->out.data, p->in.data, p->in.size); + + ZERO_STRUCT(p->out); + + if (!smbcli_request_send(req)) { + smbcli_request_destroy(req); + return NULL; + } + + return req; +} + +/**************************************************************************** + raw echo interface (async recv) +****************************************************************************/ +NTSTATUS smb_raw_echo_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, + struct smb_echo *p) +{ + if (!smbcli_request_receive(req) || + smbcli_request_is_error(req)) { + goto failed; + } + + SMBCLI_CHECK_WCT(req, 1); + p->out.count++; + p->out.sequence_number = SVAL(req->in.vwv, VWV(0)); + p->out.size = req->in.data_size; + talloc_free(p->out.data); + p->out.data = talloc_size(mem_ctx, p->out.size); + NT_STATUS_HAVE_NO_MEMORY(p->out.data); + + if (!smbcli_raw_pull_data(req, req->in.data, p->out.size, p->out.data)) { + req->status = NT_STATUS_BUFFER_TOO_SMALL; + } + + if (p->out.count == p->in.repeat_count) { + return smbcli_request_destroy(req); + } + + return NT_STATUS_OK; + +failed: + return smbcli_request_destroy(req); +} + +/**************************************************************************** + Send a echo (sync interface) +*****************************************************************************/ +NTSTATUS smb_raw_echo(struct smbcli_transport *transport, struct smb_echo *p) +{ + struct smbcli_request *req = smb_raw_echo_send(transport, p); + return smbcli_request_simple_recv(req); +} diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index d0c3ab2d15..93d8dd2c20 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -2614,4 +2614,22 @@ union smb_search_close { } findclose; }; + +/* + struct for SMBecho call +*/ +struct smb_echo { + struct { + uint16_t repeat_count; + uint16_t size; + uint8_t *data; + } in; + struct { + uint16_t count; + uint16_t sequence_number; + uint16_t size; + uint8_t *data; + } out; +}; + #endif /* __LIBCLI_RAW_INTERFACES_H__ */ -- cgit From 491c63a78de92252148d0d7ac7cb50a2f420b062 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 16 Jun 2007 17:13:42 +0000 Subject: r23519: added libcli code for fetching shadow copy information (This used to be commit a9c23729f253f65825466cfef965d259ec35a54c) --- source4/libcli/raw/interfaces.h | 15 ++++++++ source4/libcli/raw/rawrequest.c | 6 ++-- source4/libcli/raw/rawshadow.c | 79 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 source4/libcli/raw/rawshadow.c (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index 93d8dd2c20..210fb1cccf 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -2632,4 +2632,19 @@ struct smb_echo { } out; }; +/* + struct for shadow copy volumes + */ +struct smb_shadow_copy { + struct { + union smb_handle file; + uint32_t max_data; + } in; + struct { + uint32_t num_volumes; + uint32_t num_names; + const char **names; + } out; +}; + #endif /* __LIBCLI_RAW_INTERFACES_H__ */ diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 7d1bfdb30d..a0dfe75096 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -737,9 +737,9 @@ NTTIME smbcli_pull_nttime(void *base, uint16_t offset) on failure zero is returned and *dest is set to NULL, otherwise the number of bytes consumed in the blob is returned */ -static size_t smbcli_blob_pull_ucs2(TALLOC_CTX* mem_ctx, - const DATA_BLOB *blob, const char **dest, - const uint8_t *src, int byte_len, uint_t flags) +size_t smbcli_blob_pull_ucs2(TALLOC_CTX* mem_ctx, + const DATA_BLOB *blob, const char **dest, + const uint8_t *src, int byte_len, uint_t flags) { int src_len, src_len2, alignment=0; ssize_t ret; diff --git a/source4/libcli/raw/rawshadow.c b/source4/libcli/raw/rawshadow.c new file mode 100644 index 0000000000..428ebc9f8d --- /dev/null +++ b/source4/libcli/raw/rawshadow.c @@ -0,0 +1,79 @@ +/* + Unix SMB/CIFS implementation. + + shadow copy file operations + + Copyright (C) Andrew Tridgell 2007 + + 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. +*/ + +#include "includes.h" +#include "libcli/raw/libcliraw.h" +#include "libcli/raw/ioctl.h" + +/* + get shadow volume data +*/ +_PUBLIC_ NTSTATUS smb_raw_shadow_data(struct smbcli_tree *tree, + TALLOC_CTX *mem_ctx, struct smb_shadow_copy *info) +{ + union smb_ioctl nt; + NTSTATUS status; + DATA_BLOB blob; + uint32_t dlength; + int i; + uint32_t ofs; + + nt.ntioctl.level = RAW_IOCTL_NTIOCTL; + nt.ntioctl.in.function = FSCTL_GET_SHADOW_COPY_DATA; + nt.ntioctl.in.file.fnum = info->in.file.fnum; + nt.ntioctl.in.fsctl = True; + nt.ntioctl.in.filter = 0; + nt.ntioctl.in.max_data = info->in.max_data; + nt.ntioctl.in.blob = data_blob(NULL, 0); + + status = smb_raw_ioctl(tree, mem_ctx, &nt); + + blob = nt.ntioctl.out.blob; + + if (blob.length < 12) { + return NT_STATUS_INVALID_NETWORK_RESPONSE; + } + + info->out.num_volumes = IVAL(blob.data, 0); + info->out.num_names = IVAL(blob.data, 4); + dlength = IVAL(blob.data, 8); + if (dlength > blob.length - 12) { + return NT_STATUS_INVALID_NETWORK_RESPONSE; + } + + info->out.names = talloc_array(mem_ctx, const char *, info->out.num_names); + NT_STATUS_HAVE_NO_MEMORY(info->out.names); + + ofs = 12; + for (i=0;iout.num_names;i++) { + size_t len; + len = smbcli_blob_pull_ucs2(info->out.names, + &blob, &info->out.names[i], + blob.data+ofs, -1, STR_TERMINATE); + if (len == 0) { + return NT_STATUS_INVALID_NETWORK_RESPONSE; + } + ofs += len; + } + + return status; +} -- cgit From b7b17c654da08e2abcad0e127ed30bb6991e64ab Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 9 Jul 2007 03:08:20 +0000 Subject: r23754: Make sure to check the status return before we de-reference the returned elements. Andrew Bartlett (This used to be commit 3a8192c74288b98bc61af95aa5cd39b1584411c1) --- source4/libcli/raw/rawshadow.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawshadow.c b/source4/libcli/raw/rawshadow.c index 428ebc9f8d..206abf56b4 100644 --- a/source4/libcli/raw/rawshadow.c +++ b/source4/libcli/raw/rawshadow.c @@ -46,6 +46,9 @@ _PUBLIC_ NTSTATUS smb_raw_shadow_data(struct smbcli_tree *tree, nt.ntioctl.in.blob = data_blob(NULL, 0); status = smb_raw_ioctl(tree, mem_ctx, &nt); + if (!NT_STATUS_IS_OK(status)) { + return status; + } blob = nt.ntioctl.out.blob; -- cgit From 0479a2f1cbae51fcd8dbdc3c148c808421fb4d25 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 02:07:03 +0000 Subject: r23792: convert Samba4 to GPLv3 There are still a few tidyups of old FSF addresses to come (in both s3 and s4). More commits soon. (This used to be commit fcf38a38ac691abd0fa51b89dc951a08e89fdafa) --- source4/libcli/raw/clioplock.c | 5 ++--- source4/libcli/raw/clisession.c | 5 ++--- source4/libcli/raw/clisocket.c | 5 ++--- source4/libcli/raw/clitransport.c | 5 ++--- source4/libcli/raw/clitree.c | 5 ++--- source4/libcli/raw/interfaces.h | 5 ++--- source4/libcli/raw/ioctl.h | 5 ++--- source4/libcli/raw/libcliraw.h | 5 ++--- source4/libcli/raw/rawacl.c | 5 ++--- source4/libcli/raw/rawdate.c | 5 ++--- source4/libcli/raw/raweas.c | 5 ++--- source4/libcli/raw/rawfile.c | 5 ++--- source4/libcli/raw/rawfileinfo.c | 5 ++--- source4/libcli/raw/rawfsinfo.c | 5 ++--- source4/libcli/raw/rawioctl.c | 5 ++--- source4/libcli/raw/rawlpq.c | 5 ++--- source4/libcli/raw/rawnegotiate.c | 5 ++--- source4/libcli/raw/rawnotify.c | 5 ++--- source4/libcli/raw/rawreadwrite.c | 5 ++--- source4/libcli/raw/rawrequest.c | 5 ++--- source4/libcli/raw/rawsearch.c | 5 ++--- source4/libcli/raw/rawsetfileinfo.c | 5 ++--- source4/libcli/raw/rawshadow.c | 5 ++--- source4/libcli/raw/rawtrans.c | 5 ++--- source4/libcli/raw/request.h | 5 ++--- source4/libcli/raw/signing.h | 5 ++--- source4/libcli/raw/smb.h | 5 ++--- source4/libcli/raw/smb_signing.c | 5 ++--- source4/libcli/raw/trans2.h | 5 ++--- 29 files changed, 58 insertions(+), 87 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clioplock.c b/source4/libcli/raw/clioplock.c index f004532b26..12b586aafa 100644 --- a/source4/libcli/raw/clioplock.c +++ b/source4/libcli/raw/clioplock.c @@ -5,7 +5,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -14,8 +14,7 @@ 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. + along with this program. If not, see . */ #include "includes.h" diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index 9e114aece8..c6c575b818 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -7,7 +7,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -16,8 +16,7 @@ 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. + along with this program. If not, see . */ #include "includes.h" diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 0631d55a9c..0aa6ec5616 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -8,7 +8,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -17,8 +17,7 @@ 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. + along with this program. If not, see . */ #include "includes.h" diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 71c87e631a..98f5042d99 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -7,7 +7,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -16,8 +16,7 @@ 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. + along with this program. If not, see . */ #include "includes.h" diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index 51f2e12457..a5217d74b2 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -8,7 +8,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -17,8 +17,7 @@ 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. + along with this program. If not, see . */ #include "includes.h" diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index 210fb1cccf..6b3ca94506 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -7,7 +7,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -16,8 +16,7 @@ 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. + along with this program. If not, see . */ #ifndef __LIBCLI_RAW_INTERFACES_H__ diff --git a/source4/libcli/raw/ioctl.h b/source4/libcli/raw/ioctl.h index 2f0886e43e..a9d3d1b7a6 100644 --- a/source4/libcli/raw/ioctl.h +++ b/source4/libcli/raw/ioctl.h @@ -6,7 +6,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -15,8 +15,7 @@ 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. + along with this program. If not, see . */ diff --git a/source4/libcli/raw/libcliraw.h b/source4/libcli/raw/libcliraw.h index 2b856aa52b..645ac46356 100644 --- a/source4/libcli/raw/libcliraw.h +++ b/source4/libcli/raw/libcliraw.h @@ -7,7 +7,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -16,8 +16,7 @@ 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. + along with this program. If not, see . */ #ifndef __LIBCLI_RAW_H__ diff --git a/source4/libcli/raw/rawacl.c b/source4/libcli/raw/rawacl.c index 1a2d75d274..168f9c0309 100644 --- a/source4/libcli/raw/rawacl.c +++ b/source4/libcli/raw/rawacl.c @@ -6,7 +6,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -15,8 +15,7 @@ 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. + along with this program. If not, see . */ #include "includes.h" diff --git a/source4/libcli/raw/rawdate.c b/source4/libcli/raw/rawdate.c index 894eb53528..9a86c88697 100644 --- a/source4/libcli/raw/rawdate.c +++ b/source4/libcli/raw/rawdate.c @@ -7,7 +7,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -16,8 +16,7 @@ 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. + along with this program. If not, see . */ #include "includes.h" diff --git a/source4/libcli/raw/raweas.c b/source4/libcli/raw/raweas.c index 26b04838d6..f79de88fa6 100644 --- a/source4/libcli/raw/raweas.c +++ b/source4/libcli/raw/raweas.c @@ -5,7 +5,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -14,8 +14,7 @@ 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. + along with this program. If not, see . */ #include "includes.h" diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c index 3d2d407583..60a9bf2656 100644 --- a/source4/libcli/raw/rawfile.c +++ b/source4/libcli/raw/rawfile.c @@ -7,7 +7,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -16,8 +16,7 @@ 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. + along with this program. If not, see . */ #include "includes.h" diff --git a/source4/libcli/raw/rawfileinfo.c b/source4/libcli/raw/rawfileinfo.c index 7b15ce6fd6..faae3a52b1 100644 --- a/source4/libcli/raw/rawfileinfo.c +++ b/source4/libcli/raw/rawfileinfo.c @@ -7,7 +7,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -16,8 +16,7 @@ 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. + along with this program. If not, see . */ #include "includes.h" diff --git a/source4/libcli/raw/rawfsinfo.c b/source4/libcli/raw/rawfsinfo.c index 9b218586a2..ced977333d 100644 --- a/source4/libcli/raw/rawfsinfo.c +++ b/source4/libcli/raw/rawfsinfo.c @@ -7,7 +7,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -16,8 +16,7 @@ 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. + along with this program. If not, see . */ #include "includes.h" diff --git a/source4/libcli/raw/rawioctl.c b/source4/libcli/raw/rawioctl.c index 9477af4eb2..9205f84e86 100644 --- a/source4/libcli/raw/rawioctl.c +++ b/source4/libcli/raw/rawioctl.c @@ -6,7 +6,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -15,8 +15,7 @@ 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. + along with this program. If not, see . */ #include "includes.h" diff --git a/source4/libcli/raw/rawlpq.c b/source4/libcli/raw/rawlpq.c index 882ed3c302..03f7a82f1c 100644 --- a/source4/libcli/raw/rawlpq.c +++ b/source4/libcli/raw/rawlpq.c @@ -5,7 +5,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -14,8 +14,7 @@ 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. + along with this program. If not, see . */ #include "includes.h" diff --git a/source4/libcli/raw/rawnegotiate.c b/source4/libcli/raw/rawnegotiate.c index 07b9dd572a..c2dc393481 100644 --- a/source4/libcli/raw/rawnegotiate.c +++ b/source4/libcli/raw/rawnegotiate.c @@ -8,7 +8,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -17,8 +17,7 @@ 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. + along with this program. If not, see . */ #include "includes.h" diff --git a/source4/libcli/raw/rawnotify.c b/source4/libcli/raw/rawnotify.c index e847368f73..91a12a8618 100644 --- a/source4/libcli/raw/rawnotify.c +++ b/source4/libcli/raw/rawnotify.c @@ -5,7 +5,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -14,8 +14,7 @@ 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. + along with this program. If not, see . */ #include "includes.h" diff --git a/source4/libcli/raw/rawreadwrite.c b/source4/libcli/raw/rawreadwrite.c index e7a3209d07..a288b7ec54 100644 --- a/source4/libcli/raw/rawreadwrite.c +++ b/source4/libcli/raw/rawreadwrite.c @@ -6,7 +6,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -15,8 +15,7 @@ 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. + along with this program. If not, see . */ #include "includes.h" diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index a0dfe75096..6bf2bb58cc 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -6,7 +6,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -15,8 +15,7 @@ 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. + along with this program. If not, see . */ /* diff --git a/source4/libcli/raw/rawsearch.c b/source4/libcli/raw/rawsearch.c index 3c7ca5788e..33fa90d68d 100644 --- a/source4/libcli/raw/rawsearch.c +++ b/source4/libcli/raw/rawsearch.c @@ -6,7 +6,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -15,8 +15,7 @@ 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. + along with this program. If not, see . */ #include "includes.h" diff --git a/source4/libcli/raw/rawsetfileinfo.c b/source4/libcli/raw/rawsetfileinfo.c index 794ba25480..7738e849e8 100644 --- a/source4/libcli/raw/rawsetfileinfo.c +++ b/source4/libcli/raw/rawsetfileinfo.c @@ -7,7 +7,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -16,8 +16,7 @@ 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. + along with this program. If not, see . */ #include "includes.h" diff --git a/source4/libcli/raw/rawshadow.c b/source4/libcli/raw/rawshadow.c index 206abf56b4..8fc81dab4c 100644 --- a/source4/libcli/raw/rawshadow.c +++ b/source4/libcli/raw/rawshadow.c @@ -7,7 +7,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -16,8 +16,7 @@ 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. + along with this program. If not, see . */ #include "includes.h" diff --git a/source4/libcli/raw/rawtrans.c b/source4/libcli/raw/rawtrans.c index 164354c701..fe26a71310 100644 --- a/source4/libcli/raw/rawtrans.c +++ b/source4/libcli/raw/rawtrans.c @@ -6,7 +6,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -15,8 +15,7 @@ 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. + along with this program. If not, see . */ #include "includes.h" diff --git a/source4/libcli/raw/request.h b/source4/libcli/raw/request.h index 689a5281ce..803a450e3c 100644 --- a/source4/libcli/raw/request.h +++ b/source4/libcli/raw/request.h @@ -8,7 +8,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -17,8 +17,7 @@ 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. + along with this program. If not, see . */ #include "libcli/raw/signing.h" diff --git a/source4/libcli/raw/signing.h b/source4/libcli/raw/signing.h index cea8556c2c..62b06579d5 100644 --- a/source4/libcli/raw/signing.h +++ b/source4/libcli/raw/signing.h @@ -8,7 +8,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -17,8 +17,7 @@ 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. + along with this program. If not, see . */ enum smb_signing_engine_state { diff --git a/source4/libcli/raw/smb.h b/source4/libcli/raw/smb.h index 98e7eca581..e054ed6522 100644 --- a/source4/libcli/raw/smb.h +++ b/source4/libcli/raw/smb.h @@ -11,7 +11,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -20,8 +20,7 @@ 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. + along with this program. If not, see . */ #ifndef _SMB_H diff --git a/source4/libcli/raw/smb_signing.c b/source4/libcli/raw/smb_signing.c index 541fd1fb8c..99044d23ae 100644 --- a/source4/libcli/raw/smb_signing.c +++ b/source4/libcli/raw/smb_signing.c @@ -7,7 +7,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -16,8 +16,7 @@ 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. + along with this program. If not, see . */ #include "includes.h" diff --git a/source4/libcli/raw/trans2.h b/source4/libcli/raw/trans2.h index e4e85b58bc..5b7987aa8c 100644 --- a/source4/libcli/raw/trans2.h +++ b/source4/libcli/raw/trans2.h @@ -7,7 +7,7 @@ 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 + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -16,8 +16,7 @@ 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. + along with this program. If not, see . */ #ifndef _TRANS2_H_ -- cgit From 61ffa08f4c95e29d301de9fbabd6e71c2dbc1056 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 27 Aug 2007 18:10:19 +0000 Subject: r24712: No longer expose the 'BOOL' data type in any interfaces. (This used to be commit 1ce32673d960c8b05b6c1b1b99e1976a402417ae) --- source4/libcli/raw/interfaces.h | 14 +++++++------- source4/libcli/raw/libcliraw.h | 2 +- source4/libcli/raw/signing.h | 8 ++++---- 3 files changed, 12 insertions(+), 12 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index 6b3ca94506..23de6c3838 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -608,8 +608,8 @@ union smb_fileinfo { uint64_t alloc_size; uint64_t size; uint32_t nlink; - BOOL delete_pending; - BOOL directory; + bool delete_pending; + bool directory; } out; } standard_info; @@ -976,7 +976,7 @@ union smb_setfileinfo { enum smb_setfileinfo_level level; struct { union smb_handle_or_path file; - BOOL delete_on_close; + bool delete_on_close; } in; } disposition_info; @@ -1633,7 +1633,7 @@ union smb_read { uint16_t mincnt; uint32_t maxcnt; uint16_t remaining; - BOOL read_for_execute; + bool read_for_execute; } in; struct { uint8_t *data; @@ -2035,7 +2035,7 @@ union smb_ioctl { struct { union smb_handle file; uint32_t function; - BOOL fsctl; + bool fsctl; uint8_t filter; uint32_t max_data; DATA_BLOB blob; @@ -2193,7 +2193,7 @@ union smb_notify { union smb_handle file; uint32_t buffer_size; uint32_t completion_filter; - BOOL recursive; + bool recursive; } in; struct { @@ -2581,7 +2581,7 @@ union smb_search_data { }; /* Callback function passed to the raw search interface. */ -typedef BOOL (*smbcli_search_callback)(void *private, const union smb_search_data *file); +typedef bool (*smbcli_search_callback)(void *private, const union smb_search_data *file); enum smb_search_close_level {RAW_FINDCLOSE_GENERIC, RAW_FINDCLOSE_FCLOSE, RAW_FINDCLOSE_FINDCLOSE}; diff --git a/source4/libcli/raw/libcliraw.h b/source4/libcli/raw/libcliraw.h index 645ac46356..a11a9c9e58 100644 --- a/source4/libcli/raw/libcliraw.h +++ b/source4/libcli/raw/libcliraw.h @@ -142,7 +142,7 @@ struct smbcli_transport { struct { /* a oplock break request handler */ - BOOL (*handler)(struct smbcli_transport *transport, + bool (*handler)(struct smbcli_transport *transport, uint16_t tid, uint16_t fnum, uint8_t level, void *private); /* private data passed to the oplock handler */ void *private; diff --git a/source4/libcli/raw/signing.h b/source4/libcli/raw/signing.h index 62b06579d5..56e977ed7c 100644 --- a/source4/libcli/raw/signing.h +++ b/source4/libcli/raw/signing.h @@ -34,10 +34,10 @@ struct smb_signing_context { enum smb_signing_engine_state signing_state; DATA_BLOB mac_key; uint32_t next_seq_num; - BOOL allow_smb_signing; - BOOL doing_signing; - BOOL mandatory_signing; - BOOL seen_valid; /* Have I ever seen a validly signed packet? */ + bool allow_smb_signing; + bool doing_signing; + bool mandatory_signing; + bool seen_valid; /* Have I ever seen a validly signed packet? */ }; #endif -- cgit From 6cf69fee189857ae6f85cd3f81a6a58364839942 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 7 Sep 2007 13:31:15 +0000 Subject: r24994: Fix some C++ warnings. (This used to be commit 925abf74fa1ed5ae726bae8781ec549302786b39) --- source4/libcli/raw/clitransport.c | 2 +- source4/libcli/raw/rawfileinfo.c | 2 +- source4/libcli/raw/rawrequest.c | 2 +- source4/libcli/raw/rawtrans.c | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 98f5042d99..0482b04f24 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -635,7 +635,7 @@ NTSTATUS smb_raw_echo_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, p->out.sequence_number = SVAL(req->in.vwv, VWV(0)); p->out.size = req->in.data_size; talloc_free(p->out.data); - p->out.data = talloc_size(mem_ctx, p->out.size); + p->out.data = talloc_array(mem_ctx, uint8_t, p->out.size); NT_STATUS_HAVE_NO_MEMORY(p->out.data); if (!smbcli_raw_pull_data(req, req->in.data, p->out.size, p->out.data)) { diff --git a/source4/libcli/raw/rawfileinfo.c b/source4/libcli/raw/rawfileinfo.c index faae3a52b1..8481995c1a 100644 --- a/source4/libcli/raw/rawfileinfo.c +++ b/source4/libcli/raw/rawfileinfo.c @@ -66,7 +66,7 @@ NTSTATUS smbcli_parse_stream_info(DATA_BLOB blob, TALLOC_CTX *mem_ctx, if (size == -1) { return NT_STATUS_ILLEGAL_CHARACTER; } - io->streams[n].stream_name.s = vstr; + io->streams[n].stream_name.s = (const char *)vstr; io->streams[n].stream_name.private_length = nlen; io->num_streams++; len = IVAL(blob.data, ofs); diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 6bf2bb58cc..778b896abd 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -83,7 +83,7 @@ struct smbcli_request *smbcli_request_setup_nonsmb(struct smbcli_transport *tran /* over allocate by a small amount */ req->out.allocated = req->out.size + REQ_OVER_ALLOCATION; - req->out.buffer = talloc_size(req, req->out.allocated); + req->out.buffer = talloc_array(req, uint8_t, req->out.allocated); if (!req->out.buffer) { return NULL; } diff --git a/source4/libcli/raw/rawtrans.c b/source4/libcli/raw/rawtrans.c index fe26a71310..40a30bd067 100644 --- a/source4/libcli/raw/rawtrans.c +++ b/source4/libcli/raw/rawtrans.c @@ -86,7 +86,7 @@ NTSTATUS smb_raw_trans2_recv(struct smbcli_request *req, /* allocate it */ if (total_data != 0) { - tdata = talloc_size(mem_ctx, total_data); + tdata = talloc_array(mem_ctx, uint8_t, total_data); if (!tdata) { DEBUG(0,("smb_raw_receive_trans: failed to enlarge data buffer to %d bytes\n", total_data)); req->status = NT_STATUS_NO_MEMORY; @@ -96,7 +96,7 @@ NTSTATUS smb_raw_trans2_recv(struct smbcli_request *req, } if (total_param != 0) { - tparam = talloc_size(mem_ctx, total_param); + tparam = talloc_array(mem_ctx, uint8_t, total_param); if (!tparam) { DEBUG(0,("smb_raw_receive_trans: failed to enlarge param buffer to %d bytes\n", total_param)); req->status = NT_STATUS_NO_MEMORY; -- cgit From 959915a8cbea0c598ef1f29ce666329a521ef2f6 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 7 Sep 2007 15:35:18 +0000 Subject: r25001: Fix more C++ and other warnings, fix some of the indentation with ts=4 lines that I accidently added earlier. (This used to be commit 0bcb21ed740fcec0f48ad36bbc2deee2948e8fc7) --- source4/libcli/raw/raweas.c | 1 + source4/libcli/raw/rawlpq.c | 1 + source4/libcli/raw/smb_signing.c | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/raweas.c b/source4/libcli/raw/raweas.c index f79de88fa6..06b5b4fc4d 100644 --- a/source4/libcli/raw/raweas.c +++ b/source4/libcli/raw/raweas.c @@ -19,6 +19,7 @@ #include "includes.h" #include "smb.h" +#include "libcli/raw/libcliraw.h" /* work out how many bytes on the wire a ea list will consume. diff --git a/source4/libcli/raw/rawlpq.c b/source4/libcli/raw/rawlpq.c index 03f7a82f1c..46e0efaaf5 100644 --- a/source4/libcli/raw/rawlpq.c +++ b/source4/libcli/raw/rawlpq.c @@ -19,6 +19,7 @@ #include "includes.h" #include "smb.h" +#include "libcli/raw/libcliraw.h" /**************************************************************************** lpq - async send diff --git a/source4/libcli/raw/smb_signing.c b/source4/libcli/raw/smb_signing.c index 99044d23ae..a37c9a7836 100644 --- a/source4/libcli/raw/smb_signing.c +++ b/source4/libcli/raw/smb_signing.c @@ -375,7 +375,7 @@ BOOL smbcli_transport_simple_set_signing(struct smbcli_transport *transport, } -BOOL smbcli_init_signing(struct smbcli_transport *transport) +bool smbcli_init_signing(struct smbcli_transport *transport) { transport->negotiate.sign_info.mac_key = data_blob(NULL, 0); if (!smbcli_set_signing_off(&transport->negotiate.sign_info)) { -- cgit From ffeee68e4b72dd94fee57366bd8d38b8c284c3d4 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 8 Sep 2007 12:42:09 +0000 Subject: r25026: Move param/param.h out of includes.h (This used to be commit abe8349f9b4387961ff3665d8c589d61cd2edf31) --- source4/libcli/raw/clisocket.c | 1 + source4/libcli/raw/clitransport.c | 1 + source4/libcli/raw/clitree.c | 1 + source4/libcli/raw/rawnegotiate.c | 1 + source4/libcli/raw/smb_signing.c | 1 + 5 files changed, 5 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 0aa6ec5616..51f631eb67 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -26,6 +26,7 @@ #include "libcli/composite/composite.h" #include "lib/socket/socket.h" #include "libcli/resolve/resolve.h" +#include "param/param.h" struct sock_connect_state { struct composite_context *ctx; diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 0482b04f24..90f51b2969 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -26,6 +26,7 @@ #include "lib/events/events.h" #include "lib/stream/packet.h" #include "librpc/gen_ndr/ndr_nbt.h" +#include "param/param.h" /* diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index a5217d74b2..6a15c25eb9 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -23,6 +23,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" #include "libcli/smb_composite/smb_composite.h" +#include "param/param.h" #define SETUP_REQUEST_TREE(cmd, wct, buflen) do { \ req = smbcli_request_setup(tree, cmd, wct, buflen); \ diff --git a/source4/libcli/raw/rawnegotiate.c b/source4/libcli/raw/rawnegotiate.c index c2dc393481..eff22ee8bc 100644 --- a/source4/libcli/raw/rawnegotiate.c +++ b/source4/libcli/raw/rawnegotiate.c @@ -23,6 +23,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" #include "system/time.h" +#include "param/param.h" static const struct { enum protocol_types prot; diff --git a/source4/libcli/raw/smb_signing.c b/source4/libcli/raw/smb_signing.c index a37c9a7836..1a82ea0536 100644 --- a/source4/libcli/raw/smb_signing.c +++ b/source4/libcli/raw/smb_signing.c @@ -23,6 +23,7 @@ #include "smb.h" #include "libcli/raw/libcliraw.h" #include "lib/crypto/crypto.h" +#include "param/param.h" /*********************************************************** SMB signing - Common code before we set a new signing implementation -- cgit From 9b009c900987517359485799be8be4167494b376 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 23 Sep 2007 21:35:03 +0000 Subject: r25301: Merge my includes.h cleanups. (This used to be commit 37425495f392a2d0122a93aa2c42758eab7dab5a) --- source4/libcli/raw/clierror.c | 72 +++++++++++++++++++++++++++++++++++++++++ source4/libcli/raw/interfaces.h | 1 + 2 files changed, 73 insertions(+) create mode 100644 source4/libcli/raw/clierror.c (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clierror.c b/source4/libcli/raw/clierror.c new file mode 100644 index 0000000000..c515259ee7 --- /dev/null +++ b/source4/libcli/raw/clierror.c @@ -0,0 +1,72 @@ +/* + Unix SMB/CIFS implementation. + client error handling routines + Copyright (C) Andrew Tridgell 1994-1998 + Copyright (C) James Myers 2003 + + 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 3 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, see . +*/ + +#include "includes.h" +#include "libcli/raw/libcliraw.h" + + +/*************************************************************************** + Return an error message from the last response +****************************************************************************/ +const char *smbcli_errstr(struct smbcli_tree *tree) +{ + switch (tree->session->transport->error.etype) { + case ETYPE_SMB: + return nt_errstr(tree->session->transport->error.e.nt_status); + + case ETYPE_SOCKET: + return "socket_error"; + + case ETYPE_NBT: + return "nbt_error"; + + case ETYPE_NONE: + return "no_error"; + } + return NULL; +} + + +/* Return the 32-bit NT status code from the last packet */ +NTSTATUS smbcli_nt_error(struct smbcli_tree *tree) +{ + switch (tree->session->transport->error.etype) { + case ETYPE_SMB: + return tree->session->transport->error.e.nt_status; + + case ETYPE_SOCKET: + return NT_STATUS_UNSUCCESSFUL; + + case ETYPE_NBT: + return NT_STATUS_UNSUCCESSFUL; + + case ETYPE_NONE: + return NT_STATUS_OK; + } + + return NT_STATUS_UNSUCCESSFUL; +} + + +/* Return true if the last packet was an error */ +bool smbcli_is_error(struct smbcli_tree *tree) +{ + return NT_STATUS_IS_ERR(smbcli_nt_error(tree)); +} diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index 23de6c3838..00ab788184 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -23,6 +23,7 @@ #define __LIBCLI_RAW_INTERFACES_H__ #include "smb.h" +#include "librpc/gen_ndr/misc.h" /* for struct GUID */ /* this structure is just a wrapper for a string, the only reason we bother with this is that it allows us to check the length provided -- cgit From 37d53832a4623653f706e77985a79d84bd7c6694 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 28 Sep 2007 01:17:46 +0000 Subject: r25398: Parse loadparm context to all lp_*() functions. (This used to be commit 3fcc960839c6e5ca4de2c3c042f12f369ac5f238) --- source4/libcli/raw/clisocket.c | 4 ++-- source4/libcli/raw/clitransport.c | 7 ++++--- source4/libcli/raw/clitree.c | 2 +- source4/libcli/raw/rawnegotiate.c | 6 +++--- source4/libcli/raw/smb_signing.c | 2 +- 5 files changed, 11 insertions(+), 10 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 51f631eb67..a748b40a32 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -73,7 +73,7 @@ struct composite_context *smbcli_sock_connect_send(TALLOC_CTX *mem_ctx, if (state->host_name == NULL) goto failed; if (port == 0) { - const char **ports = lp_smb_ports(); + const char **ports = lp_smb_ports(global_loadparm); int i; for (i=0;ports[i];i++) /* noop */ ; @@ -120,7 +120,7 @@ static void smbcli_sock_connect_recv_conn(struct composite_context *ctx) if (!composite_is_ok(state->ctx)) return; state->ctx->status = - socket_set_option(sock, lp_socket_options(), NULL); + socket_set_option(sock, lp_socket_options(global_loadparm), NULL); if (!composite_is_ok(state->ctx)) return; diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 90f51b2969..6b2c4c37fe 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -85,9 +85,10 @@ struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock, transport->socket = talloc_reference(transport, sock); } transport->negotiate.protocol = PROTOCOL_NT1; - transport->options.use_spnego = lp_use_spnego() && lp_nt_status_support(); - transport->options.max_xmit = lp_max_xmit(); - transport->options.max_mux = lp_maxmux(); + transport->options.use_spnego = lp_use_spnego(global_loadparm) && + lp_nt_status_support(global_loadparm); + transport->options.max_xmit = lp_max_xmit(global_loadparm); + transport->options.max_mux = lp_maxmux(global_loadparm); transport->options.request_timeout = SMB_REQUEST_TIMEOUT; transport->negotiate.max_xmit = transport->options.max_xmit; diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index 6a15c25eb9..4ff11f3a69 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -190,7 +190,7 @@ NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx, io.in.service_type = service_type; io.in.credentials = credentials; io.in.fallback_to_anonymous = False; - io.in.workgroup = lp_workgroup(); + io.in.workgroup = lp_workgroup(global_loadparm); status = smb_composite_connect(&io, parent_ctx, ev); if (NT_STATUS_IS_OK(status)) { diff --git a/source4/libcli/raw/rawnegotiate.c b/source4/libcli/raw/rawnegotiate.c index eff22ee8bc..c58ac1f0df 100644 --- a/source4/libcli/raw/rawnegotiate.c +++ b/source4/libcli/raw/rawnegotiate.c @@ -58,7 +58,7 @@ struct smbcli_request *smb_raw_negotiate_send(struct smbcli_transport *transport } flags2 |= FLAGS2_32_BIT_ERROR_CODES; - if (lp_unicode()) { + if (lp_unicode(global_loadparm)) { flags2 |= FLAGS2_UNICODE_STRINGS; } flags2 |= FLAGS2_EXTENDED_ATTRIBUTES; @@ -174,11 +174,11 @@ NTSTATUS smb_raw_negotiate_recv(struct smbcli_request *req) } /* a way to force ascii SMB */ - if (!lp_unicode()) { + if (!lp_unicode(global_loadparm)) { transport->negotiate.capabilities &= ~CAP_UNICODE; } - if (!lp_nt_status_support()) { + if (!lp_nt_status_support(global_loadparm)) { transport->negotiate.capabilities &= ~CAP_STATUS32; } diff --git a/source4/libcli/raw/smb_signing.c b/source4/libcli/raw/smb_signing.c index 1a82ea0536..59c13bbeb6 100644 --- a/source4/libcli/raw/smb_signing.c +++ b/source4/libcli/raw/smb_signing.c @@ -383,7 +383,7 @@ bool smbcli_init_signing(struct smbcli_transport *transport) return False; } - switch (lp_client_signing()) { + switch (lp_client_signing(global_loadparm)) { case SMB_SIGNING_OFF: transport->negotiate.sign_info.allow_smb_signing = False; break; -- cgit From 2151cde58014ea2e822c13d2f8a369b45dc19ca8 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 6 Oct 2007 22:28:14 +0000 Subject: r25554: Convert last instances of BOOL, True and False to the standard types. (This used to be commit 566aa14139510788548a874e9213d91317f83ca9) --- source4/libcli/raw/clioplock.c | 6 +-- source4/libcli/raw/clisession.c | 2 +- source4/libcli/raw/clitransport.c | 17 +++---- source4/libcli/raw/clitree.c | 4 +- source4/libcli/raw/raweas.c | 6 +-- source4/libcli/raw/rawfile.c | 4 +- source4/libcli/raw/rawnegotiate.c | 4 +- source4/libcli/raw/rawreadwrite.c | 10 ++--- source4/libcli/raw/rawrequest.c | 38 ++++++++-------- source4/libcli/raw/rawsetfileinfo.c | 40 ++++++++--------- source4/libcli/raw/rawshadow.c | 2 +- source4/libcli/raw/rawtrans.c | 8 ++-- source4/libcli/raw/smb_signing.c | 88 ++++++++++++++++++------------------- 13 files changed, 115 insertions(+), 114 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clioplock.c b/source4/libcli/raw/clioplock.c index 12b586aafa..ae4e58ae01 100644 --- a/source4/libcli/raw/clioplock.c +++ b/source4/libcli/raw/clioplock.c @@ -23,9 +23,9 @@ /**************************************************************************** send an ack for an oplock break request ****************************************************************************/ -_PUBLIC_ BOOL smbcli_oplock_ack(struct smbcli_tree *tree, uint16_t fnum, uint16_t ack_level) +_PUBLIC_ bool smbcli_oplock_ack(struct smbcli_tree *tree, uint16_t fnum, uint16_t ack_level) { - BOOL ret; + bool ret; struct smbcli_request *req; req = smbcli_request_setup(tree, SMBlockingX, 8, 0); @@ -53,7 +53,7 @@ _PUBLIC_ BOOL smbcli_oplock_ack(struct smbcli_tree *tree, uint16_t fnum, uint16_ set the oplock handler for a connection ****************************************************************************/ _PUBLIC_ void smbcli_oplock_handler(struct smbcli_transport *transport, - BOOL (*handler)(struct smbcli_transport *, uint16_t, uint16_t, uint8_t, void *), + bool (*handler)(struct smbcli_transport *, uint16_t, uint16_t, uint8_t, void *), void *private) { transport->oplock.handler = handler; diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index c6c575b818..617131c53c 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -33,7 +33,7 @@ Initialize the session context ****************************************************************************/ struct smbcli_session *smbcli_session_init(struct smbcli_transport *transport, - TALLOC_CTX *parent_ctx, BOOL primary) + TALLOC_CTX *parent_ctx, bool primary) { struct smbcli_session *session; uint16_t flags2; diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 6b2c4c37fe..0bf805910e 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -72,7 +72,8 @@ static NTSTATUS smbcli_transport_finish_recv(void *private, DATA_BLOB blob); create a transport structure based on an established socket */ struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock, - TALLOC_CTX *parent_ctx, BOOL primary) + TALLOC_CTX *parent_ctx, + bool primary) { struct smbcli_transport *transport; @@ -261,7 +262,7 @@ NTSTATUS smbcli_transport_connect_recv(struct smbcli_request *req) /* send a session request (if needed) */ -BOOL smbcli_transport_connect(struct smbcli_transport *transport, +bool smbcli_transport_connect(struct smbcli_transport *transport, struct nbt_name *calling, struct nbt_name *called) { @@ -269,7 +270,7 @@ BOOL smbcli_transport_connect(struct smbcli_transport *transport, NTSTATUS status; if (transport->socket->port == 445) { - return True; + return true; } req = smbcli_transport_connect_send(transport, @@ -500,16 +501,16 @@ error: /* process some read/write requests that are pending - return False if the socket is dead + return false if the socket is dead */ -BOOL smbcli_transport_process(struct smbcli_transport *transport) +bool smbcli_transport_process(struct smbcli_transport *transport) { NTSTATUS status; size_t npending; packet_queue_run(transport->packet); if (transport->socket->sock == NULL) { - return False; + return false; } status = socket_pending(transport->socket->sock, &npending); @@ -517,9 +518,9 @@ BOOL smbcli_transport_process(struct smbcli_transport *transport) packet_recv(transport->packet); } if (transport->socket->sock == NULL) { - return False; + return false; } - return True; + return true; } /* diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index 4ff11f3a69..54f8ac95a4 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -34,7 +34,7 @@ Initialize the tree context ****************************************************************************/ struct smbcli_tree *smbcli_tree_init(struct smbcli_session *session, - TALLOC_CTX *parent_ctx, BOOL primary) + TALLOC_CTX *parent_ctx, bool primary) { struct smbcli_tree *tree; @@ -189,7 +189,7 @@ NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx, io.in.service = service; io.in.service_type = service_type; io.in.credentials = credentials; - io.in.fallback_to_anonymous = False; + io.in.fallback_to_anonymous = false; io.in.workgroup = lp_workgroup(global_loadparm); status = smb_composite_connect(&io, parent_ctx, ev); diff --git a/source4/libcli/raw/raweas.c b/source4/libcli/raw/raweas.c index 06b5b4fc4d..8ea8e621c9 100644 --- a/source4/libcli/raw/raweas.c +++ b/source4/libcli/raw/raweas.c @@ -333,7 +333,7 @@ NTSTATUS ea_pull_name_list(const DATA_BLOB *blob, /* put a ea_name list into a data blob */ -BOOL ea_push_name_list(TALLOC_CTX *mem_ctx, +bool ea_push_name_list(TALLOC_CTX *mem_ctx, DATA_BLOB *data, uint_t num_names, struct ea_name *eas) { int i; @@ -344,7 +344,7 @@ BOOL ea_push_name_list(TALLOC_CTX *mem_ctx, *data = data_blob_talloc(mem_ctx, NULL, ea_size); if (data->data == NULL) { - return False; + return false; } SIVAL(data->data, 0, ea_size); @@ -357,5 +357,5 @@ BOOL ea_push_name_list(TALLOC_CTX *mem_ctx, off += 1+nlen+1; } - return True; + return true; } diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c index 60a9bf2656..83303cf470 100644 --- a/source4/libcli/raw/rawfile.c +++ b/source4/libcli/raw/rawfile.c @@ -426,7 +426,7 @@ struct smbcli_request *smb_raw_open_send(struct smbcli_tree *tree, union smb_ope { int len; struct smbcli_request *req = NULL; - BOOL bigoffset = False; + bool bigoffset = false; switch (parms->generic.level) { case RAW_OPEN_T2OPEN: @@ -527,7 +527,7 @@ struct smbcli_request *smb_raw_open_send(struct smbcli_tree *tree, union smb_ope smbcli_req_append_string(req, parms->openxreadx.in.fname, STR_TERMINATE); if (tree->session->transport->negotiate.capabilities & CAP_LARGE_FILES) { - bigoffset = True; + bigoffset = true; } smbcli_chained_request_setup(req, SMBreadX, bigoffset ? 12 : 10, 0); diff --git a/source4/libcli/raw/rawnegotiate.c b/source4/libcli/raw/rawnegotiate.c index c58ac1f0df..82d6fe5236 100644 --- a/source4/libcli/raw/rawnegotiate.c +++ b/source4/libcli/raw/rawnegotiate.c @@ -144,8 +144,8 @@ NTSTATUS smb_raw_negotiate_recv(struct smbcli_request *req) } if (transport->negotiate.capabilities & CAP_RAW_MODE) { - transport->negotiate.readbraw_supported = True; - transport->negotiate.writebraw_supported = True; + transport->negotiate.readbraw_supported = true; + transport->negotiate.writebraw_supported = true; } } else if (transport->negotiate.protocol >= PROTOCOL_LANMAN1) { SMBCLI_CHECK_WCT(req, 13); diff --git a/source4/libcli/raw/rawreadwrite.c b/source4/libcli/raw/rawreadwrite.c index a288b7ec54..b0c49ddab7 100644 --- a/source4/libcli/raw/rawreadwrite.c +++ b/source4/libcli/raw/rawreadwrite.c @@ -31,13 +31,13 @@ ****************************************************************************/ struct smbcli_request *smb_raw_read_send(struct smbcli_tree *tree, union smb_read *parms) { - BOOL bigoffset = False; + bool bigoffset = false; struct smbcli_request *req = NULL; switch (parms->generic.level) { case RAW_READ_READBRAW: if (tree->session->transport->negotiate.capabilities & CAP_LARGE_FILES) { - bigoffset = True; + bigoffset = true; } SETUP_REQUEST(SMBreadbraw, bigoffset? 10:8, 0); SSVAL(req->out.vwv, VWV(0), parms->readbraw.in.file.fnum); @@ -69,7 +69,7 @@ struct smbcli_request *smb_raw_read_send(struct smbcli_tree *tree, union smb_rea case RAW_READ_READX: if (tree->session->transport->negotiate.capabilities & CAP_LARGE_FILES) { - bigoffset = True; + bigoffset = true; } SETUP_REQUEST(SMBreadX, bigoffset ? 12 : 10, 0); SSVAL(req->out.vwv, VWV(0), SMB_CHAIN_NONE); @@ -206,7 +206,7 @@ NTSTATUS smb_raw_read(struct smbcli_tree *tree, union smb_read *parms) ****************************************************************************/ struct smbcli_request *smb_raw_write_send(struct smbcli_tree *tree, union smb_write *parms) { - BOOL bigoffset = False; + bool bigoffset = false; struct smbcli_request *req = NULL; switch (parms->generic.level) { @@ -253,7 +253,7 @@ struct smbcli_request *smb_raw_write_send(struct smbcli_tree *tree, union smb_wr case RAW_WRITE_WRITEX: if (tree->session->transport->negotiate.capabilities & CAP_LARGE_FILES) { - bigoffset = True; + bigoffset = true; } SETUP_REQUEST(SMBwriteX, bigoffset ? 14 : 12, parms->writex.in.count); SSVAL(req->out.vwv, VWV(0), SMB_CHAIN_NONE); diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 778b896abd..6a4f432088 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -309,7 +309,7 @@ NTSTATUS smbcli_chained_advance(struct smbcli_request *req) /* send a message */ -BOOL smbcli_request_send(struct smbcli_request *req) +bool smbcli_request_send(struct smbcli_request *req) { if (IVAL(req->out.buffer, 0) == 0) { _smb_setlen(req->out.buffer, req->out.size - NBT_HDR_SIZE); @@ -319,23 +319,23 @@ BOOL smbcli_request_send(struct smbcli_request *req) smbcli_transport_send(req); - return True; + return true; } /* receive a response to a packet */ -BOOL smbcli_request_receive(struct smbcli_request *req) +bool smbcli_request_receive(struct smbcli_request *req) { /* req can be NULL when a send has failed. This eliminates lots of NULL checks in each module */ - if (!req) return False; + if (!req) return false; /* keep receiving packets until this one is replied to */ while (req->state <= SMBCLI_REQUEST_RECV) { if (event_loop_once(req->transport->socket->event.ctx) != 0) { - return False; + return false; } } @@ -347,7 +347,7 @@ BOOL smbcli_request_receive(struct smbcli_request *req) receive another reply to a request - this is used for requests that have multi-part replies (such as SMBtrans2) */ -BOOL smbcli_request_receive_more(struct smbcli_request *req) +bool smbcli_request_receive_more(struct smbcli_request *req) { req->state = SMBCLI_REQUEST_RECV; DLIST_ADD(req->transport->pending_recv, req); @@ -357,10 +357,10 @@ BOOL smbcli_request_receive_more(struct smbcli_request *req) /* - handle oplock break requests from the server - return True if the request was + handle oplock break requests from the server - return true if the request was an oplock break */ -BOOL smbcli_handle_oplock_break(struct smbcli_transport *transport, uint_t len, const uint8_t *hdr, const uint8_t *vwv) +bool smbcli_handle_oplock_break(struct smbcli_transport *transport, uint_t len, const uint8_t *hdr, const uint8_t *vwv) { /* we must be very fussy about what we consider an oplock break to avoid matching readbraw replies */ @@ -370,7 +370,7 @@ BOOL smbcli_handle_oplock_break(struct smbcli_transport *transport, uint_t len, SVAL(hdr, HDR_MID) != 0xFFFF || SVAL(vwv,VWV(6)) != 0 || SVAL(vwv,VWV(7)) != 0) { - return False; + return false; } if (transport->oplock.handler) { @@ -380,7 +380,7 @@ BOOL smbcli_handle_oplock_break(struct smbcli_transport *transport, uint_t len, transport->oplock.handler(transport, tid, fnum, level, transport->oplock.private); } - return True; + return true; } /* @@ -395,7 +395,7 @@ NTSTATUS smbcli_request_simple_recv(struct smbcli_request *req) /* Return true if the last packet was in error */ -BOOL smbcli_request_is_error(struct smbcli_request *req) +bool smbcli_request_is_error(struct smbcli_request *req) { return NT_STATUS_IS_ERR(req->status); } @@ -676,33 +676,33 @@ DATA_BLOB smbcli_req_pull_blob(struct smbcli_request *req, TALLOC_CTX *mem_ctx, /* check that a lump of data in a request is within the bounds of the data section of the packet */ -static BOOL smbcli_req_data_oob(struct smbcli_request *req, const uint8_t *ptr, uint32_t count) +static bool smbcli_req_data_oob(struct smbcli_request *req, const uint8_t *ptr, uint32_t count) { /* be careful with wraparound! */ if (ptr < req->in.data || ptr >= req->in.data + req->in.data_size || count > req->in.data_size || ptr + count > req->in.data + req->in.data_size) { - return True; + return true; } - return False; + return false; } /* pull a lump of data from a request packet - return False if any part is outside the data portion of the packet + return false if any part is outside the data portion of the packet */ -BOOL smbcli_raw_pull_data(struct smbcli_request *req, const uint8_t *src, int len, uint8_t *dest) +bool smbcli_raw_pull_data(struct smbcli_request *req, const uint8_t *src, int len, uint8_t *dest) { - if (len == 0) return True; + if (len == 0) return true; if (smbcli_req_data_oob(req, src, len)) { - return False; + return false; } memcpy(dest, src, len); - return True; + return true; } diff --git a/source4/libcli/raw/rawsetfileinfo.c b/source4/libcli/raw/rawsetfileinfo.c index 7738e849e8..5fa0c1f2da 100644 --- a/source4/libcli/raw/rawsetfileinfo.c +++ b/source4/libcli/raw/rawsetfileinfo.c @@ -27,7 +27,7 @@ /* Handle setfileinfo/setpathinfo passthu constructions */ -BOOL smb_raw_setfileinfo_passthru(TALLOC_CTX *mem_ctx, +bool smb_raw_setfileinfo_passthru(TALLOC_CTX *mem_ctx, enum smb_setfileinfo_level level, union smb_setfileinfo *parms, DATA_BLOB *blob) @@ -36,7 +36,7 @@ BOOL smb_raw_setfileinfo_passthru(TALLOC_CTX *mem_ctx, #define NEED_BLOB(n) do { \ *blob = data_blob_talloc(mem_ctx, NULL, n); \ - if (blob->data == NULL) return False; \ + if (blob->data == NULL) return false; \ } while (0) switch (level) { @@ -48,22 +48,22 @@ BOOL smb_raw_setfileinfo_passthru(TALLOC_CTX *mem_ctx, smbcli_push_nttime(blob->data, 24, parms->basic_info.in.change_time); SIVAL(blob->data, 32, parms->basic_info.in.attrib); SIVAL(blob->data, 36, 0); /* padding */ - return True; + return true; case RAW_SFILEINFO_DISPOSITION_INFORMATION: NEED_BLOB(4); SIVAL(blob->data, 0, parms->disposition_info.in.delete_on_close); - return True; + return true; case RAW_SFILEINFO_ALLOCATION_INFORMATION: NEED_BLOB(8); SBVAL(blob->data, 0, parms->allocation_info.in.alloc_size); - return True; + return true; case RAW_SFILEINFO_END_OF_FILE_INFORMATION: NEED_BLOB(8); SBVAL(blob->data, 0, parms->end_of_file_info.in.size); - return True; + return true; case RAW_SFILEINFO_RENAME_INFORMATION: NEED_BLOB(12); @@ -73,17 +73,17 @@ BOOL smb_raw_setfileinfo_passthru(TALLOC_CTX *mem_ctx, parms->rename_information.in.new_name, STR_UNICODE|STR_TERMINATE); SIVAL(blob->data, 8, len - 2); - return True; + return true; case RAW_SFILEINFO_POSITION_INFORMATION: NEED_BLOB(8); SBVAL(blob->data, 0, parms->position_information.in.position); - return True; + return true; case RAW_SFILEINFO_MODE_INFORMATION: NEED_BLOB(4); SIVAL(blob->data, 0, parms->mode_information.in.mode); - return True; + return true; case RAW_FILEINFO_SEC_DESC: { NTSTATUS status; @@ -91,9 +91,9 @@ BOOL smb_raw_setfileinfo_passthru(TALLOC_CTX *mem_ctx, status = ndr_push_struct_blob(blob, mem_ctx, parms->set_secdesc.in.sd, (ndr_push_flags_fn_t)ndr_push_security_descriptor); - if (!NT_STATUS_IS_OK(status)) return False; + if (!NT_STATUS_IS_OK(status)) return false; - return True; + return true; } /* Unhandled levels */ @@ -107,16 +107,16 @@ BOOL smb_raw_setfileinfo_passthru(TALLOC_CTX *mem_ctx, default: DEBUG(0,("Unhandled setfileinfo passthru level %d\n", level)); - return False; + return false; } - return False; + return false; } /* Handle setfileinfo/setpathinfo trans2 backend. */ -static BOOL smb_raw_setinfo_backend(struct smbcli_tree *tree, +static bool smb_raw_setinfo_backend(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_setfileinfo *parms, DATA_BLOB *blob) @@ -127,7 +127,7 @@ static BOOL smb_raw_setinfo_backend(struct smbcli_tree *tree, case RAW_SFILEINFO_SETATTRE: case RAW_SFILEINFO_SEC_DESC: /* not handled here */ - return False; + return false; case RAW_SFILEINFO_STANDARD: NEED_BLOB(12); @@ -137,12 +137,12 @@ static BOOL smb_raw_setinfo_backend(struct smbcli_tree *tree, blob->data, 4, parms->standard.in.access_time); raw_push_dos_date2(tree->session->transport, blob->data, 8, parms->standard.in.write_time); - return True; + return true; case RAW_SFILEINFO_EA_SET: NEED_BLOB(ea_list_size(parms->ea_set.in.num_eas, parms->ea_set.in.eas)); ea_put_list(blob->data, parms->ea_set.in.num_eas, parms->ea_set.in.eas); - return True; + return true; case RAW_SFILEINFO_BASIC_INFO: case RAW_SFILEINFO_BASIC_INFORMATION: @@ -164,7 +164,7 @@ static BOOL smb_raw_setinfo_backend(struct smbcli_tree *tree, SBVAL(blob->data, 76, parms->unix_basic.in.unique_id); SBVAL(blob->data, 84, parms->unix_basic.in.permissions); SBVAL(blob->data, 92, parms->unix_basic.in.nlink); - return True; + return true; case RAW_SFILEINFO_UNIX_INFO2: NEED_BLOB(116); @@ -184,7 +184,7 @@ static BOOL smb_raw_setinfo_backend(struct smbcli_tree *tree, smbcli_push_nttime(blob->data, 100, parms->unix_info2.in.create_time); SIVAL(blob->data, 108, parms->unix_info2.in.file_flags); SIVAL(blob->data, 112, parms->unix_info2.in.flags_mask); - return True; + return true; case RAW_SFILEINFO_DISPOSITION_INFO: case RAW_SFILEINFO_DISPOSITION_INFORMATION: @@ -230,7 +230,7 @@ static BOOL smb_raw_setinfo_backend(struct smbcli_tree *tree, break; } - return False; + return false; } /**************************************************************************** diff --git a/source4/libcli/raw/rawshadow.c b/source4/libcli/raw/rawshadow.c index 8fc81dab4c..4c58c91383 100644 --- a/source4/libcli/raw/rawshadow.c +++ b/source4/libcli/raw/rawshadow.c @@ -39,7 +39,7 @@ _PUBLIC_ NTSTATUS smb_raw_shadow_data(struct smbcli_tree *tree, nt.ntioctl.level = RAW_IOCTL_NTIOCTL; nt.ntioctl.in.function = FSCTL_GET_SHADOW_COPY_DATA; nt.ntioctl.in.file.fnum = info->in.file.fnum; - nt.ntioctl.in.fsctl = True; + nt.ntioctl.in.fsctl = true; nt.ntioctl.in.filter = 0; nt.ntioctl.in.max_data = info->in.max_data; nt.ntioctl.in.blob = data_blob(NULL, 0); diff --git a/source4/libcli/raw/rawtrans.c b/source4/libcli/raw/rawtrans.c index 40a30bd067..53670d22a3 100644 --- a/source4/libcli/raw/rawtrans.c +++ b/source4/libcli/raw/rawtrans.c @@ -27,13 +27,13 @@ /* check out of bounds for incoming data */ -static BOOL raw_trans_oob(struct smbcli_request *req, +static bool raw_trans_oob(struct smbcli_request *req, uint_t offset, uint_t count) { uint8_t *ptr; if (count == 0) { - return False; + return false; } ptr = req->in.hdr + offset; @@ -43,9 +43,9 @@ static BOOL raw_trans_oob(struct smbcli_request *req, ptr >= req->in.data + req->in.data_size || count > req->in.data_size || ptr + count > req->in.data + req->in.data_size) { - return True; + return true; } - return False; + return false; } /**************************************************************************** diff --git a/source4/libcli/raw/smb_signing.c b/source4/libcli/raw/smb_signing.c index 59c13bbeb6..e19e81af7e 100644 --- a/source4/libcli/raw/smb_signing.c +++ b/source4/libcli/raw/smb_signing.c @@ -28,41 +28,41 @@ /*********************************************************** SMB signing - Common code before we set a new signing implementation ************************************************************/ -BOOL set_smb_signing_common(struct smb_signing_context *sign_info) +bool set_smb_signing_common(struct smb_signing_context *sign_info) { if (sign_info->doing_signing) { DEBUG(5, ("SMB Signing already in progress, so we don't start it again\n")); - return False; + return false; } if (!sign_info->allow_smb_signing) { DEBUG(5, ("SMB Signing has been locally disabled\n")); - return False; + return false; } - return True; + return true; } /*********************************************************** SMB signing - Common code before we set a new signing implementation ************************************************************/ -static BOOL smbcli_set_smb_signing_common(struct smbcli_transport *transport) +static bool smbcli_set_smb_signing_common(struct smbcli_transport *transport) { if (!set_smb_signing_common(&transport->negotiate.sign_info)) { - return False; + return false; } if (!(transport->negotiate.sec_mode & (NEGOTIATE_SECURITY_SIGNATURES_REQUIRED|NEGOTIATE_SECURITY_SIGNATURES_ENABLED))) { DEBUG(5, ("SMB Signing is not negotiated by the peer\n")); - return False; + return false; } /* These calls are INCOMPATIBLE with SMB signing */ - transport->negotiate.readbraw_supported = False; - transport->negotiate.writebraw_supported = False; + transport->negotiate.readbraw_supported = false; + transport->negotiate.writebraw_supported = false; - return True; + return true; } void mark_packet_signed(struct request_buffer *out) @@ -73,17 +73,17 @@ void mark_packet_signed(struct request_buffer *out) SSVAL(out->hdr, HDR_FLG2, flags2); } -BOOL signing_good(struct smb_signing_context *sign_info, - unsigned int seq, BOOL good) +bool signing_good(struct smb_signing_context *sign_info, + unsigned int seq, bool good) { if (good) { if (!sign_info->doing_signing) { DEBUG(5, ("Seen valid packet, so turning signing on\n")); - sign_info->doing_signing = True; + sign_info->doing_signing = true; } if (!sign_info->seen_valid) { DEBUG(5, ("Seen valid packet, so marking signing as 'seen valid'\n")); - sign_info->seen_valid = True; + sign_info->seen_valid = true; } } else { if (!sign_info->seen_valid) { @@ -91,14 +91,14 @@ BOOL signing_good(struct smb_signing_context *sign_info, DEBUG(5, ("signing_good: signing negotiated but not required and peer\n" "isn't sending correct signatures. Turning off.\n")); smbcli_set_signing_off(sign_info); - return True; + return true; } else { /* bad packet after signing started - fail and disconnect. */ DEBUG(0, ("signing_good: BAD SIG: seq %u\n", seq)); - return False; + return false; } } - return True; + return true; } void sign_outgoing_message(struct request_buffer *out, DATA_BLOB *mac_key, unsigned int seq_num) @@ -133,9 +133,9 @@ void sign_outgoing_message(struct request_buffer *out, DATA_BLOB *mac_key, unsig Uncomment this to test if the remote server actually verifies signitures...*/ } -BOOL check_signed_incoming_message(struct request_buffer *in, DATA_BLOB *mac_key, uint_t seq_num) +bool check_signed_incoming_message(struct request_buffer *in, DATA_BLOB *mac_key, uint_t seq_num) { - BOOL good; + bool good; uint8_t calc_md5_mac[16]; uint8_t *server_sent_mac; uint8_t sequence_buf[8]; @@ -146,12 +146,12 @@ BOOL check_signed_incoming_message(struct request_buffer *in, DATA_BLOB *mac_key /* room enough for the signature? */ if (in->size < NBT_HDR_SIZE + HDR_SS_FIELD + 8) { - return False; + return false; } if (!mac_key->length) { /* NO key yet */ - return False; + return false; } /* its quite bogus to be guessing sequence numbers, but very useful @@ -258,24 +258,24 @@ void smbcli_request_calculate_sign_mac(struct smbcli_request *req) @note Used as an initialisation only - it will not correctly shut down a real signing mechanism */ -BOOL smbcli_set_signing_off(struct smb_signing_context *sign_info) +bool smbcli_set_signing_off(struct smb_signing_context *sign_info) { DEBUG(5, ("Shutdown SMB signing\n")); - sign_info->doing_signing = False; + sign_info->doing_signing = false; sign_info->next_seq_num = 0; data_blob_free(&sign_info->mac_key); sign_info->signing_state = SMB_SIGNING_ENGINE_OFF; - return True; + return true; } /** SMB signing - TEMP implementation - setup the MAC key. */ -BOOL smbcli_temp_set_signing(struct smbcli_transport *transport) +bool smbcli_temp_set_signing(struct smbcli_transport *transport) { if (!smbcli_set_smb_signing_common(transport)) { - return False; + return false; } DEBUG(5, ("BSRSPYL SMB signing enabled\n")); smbcli_set_signing_off(&transport->negotiate.sign_info); @@ -283,7 +283,7 @@ BOOL smbcli_temp_set_signing(struct smbcli_transport *transport) transport->negotiate.sign_info.mac_key = data_blob(NULL, 0); transport->negotiate.sign_info.signing_state = SMB_SIGNING_ENGINE_BSRSPYL; - return True; + return true; } /*********************************************************** @@ -291,22 +291,22 @@ BOOL smbcli_temp_set_signing(struct smbcli_transport *transport) ************************************************************/ /** * Check a packet supplied by the server. - * @return False if we had an established signing connection - * which had a back checksum, True otherwise + * @return false if we had an established signing connection + * which had a back checksum, true otherwise */ -BOOL smbcli_request_check_sign_mac(struct smbcli_request *req) +bool smbcli_request_check_sign_mac(struct smbcli_request *req) { - BOOL good; + bool good; switch (req->transport->negotiate.sign_info.signing_state) { case SMB_SIGNING_ENGINE_OFF: - return True; + return true; case SMB_SIGNING_ENGINE_BSRSPYL: case SMB_SIGNING_ENGINE_ON: { if (req->in.size < (HDR_SS_FIELD + 8)) { - return False; + return false; } else { good = check_signed_incoming_message(&req->in, &req->transport->negotiate.sign_info.mac_key, @@ -317,14 +317,14 @@ BOOL smbcli_request_check_sign_mac(struct smbcli_request *req) } } } - return False; + return false; } /*********************************************************** SMB signing - Simple implementation - setup the MAC key. ************************************************************/ -BOOL smbcli_simple_set_signing(TALLOC_CTX *mem_ctx, +bool smbcli_simple_set_signing(TALLOC_CTX *mem_ctx, struct smb_signing_context *sign_info, const DATA_BLOB *user_session_key, const DATA_BLOB *response) @@ -354,19 +354,19 @@ BOOL smbcli_simple_set_signing(TALLOC_CTX *mem_ctx, sign_info->signing_state = SMB_SIGNING_ENGINE_ON; - return True; + return true; } /*********************************************************** SMB signing - Simple implementation - setup the MAC key. ************************************************************/ -BOOL smbcli_transport_simple_set_signing(struct smbcli_transport *transport, +bool smbcli_transport_simple_set_signing(struct smbcli_transport *transport, const DATA_BLOB user_session_key, const DATA_BLOB response) { if (!smbcli_set_smb_signing_common(transport)) { - return False; + return false; } return smbcli_simple_set_signing(transport, @@ -380,21 +380,21 @@ bool smbcli_init_signing(struct smbcli_transport *transport) { transport->negotiate.sign_info.mac_key = data_blob(NULL, 0); if (!smbcli_set_signing_off(&transport->negotiate.sign_info)) { - return False; + return false; } switch (lp_client_signing(global_loadparm)) { case SMB_SIGNING_OFF: - transport->negotiate.sign_info.allow_smb_signing = False; + transport->negotiate.sign_info.allow_smb_signing = false; break; case SMB_SIGNING_SUPPORTED: case SMB_SIGNING_AUTO: - transport->negotiate.sign_info.allow_smb_signing = True; + transport->negotiate.sign_info.allow_smb_signing = true; break; case SMB_SIGNING_REQUIRED: - transport->negotiate.sign_info.allow_smb_signing = True; - transport->negotiate.sign_info.mandatory_signing = True; + transport->negotiate.sign_info.allow_smb_signing = true; + transport->negotiate.sign_info.mandatory_signing = true; break; } - return True; + return true; } -- cgit From 529763a9aa192a6785ba878aceeb1683c2510913 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 9 Nov 2007 19:24:51 +0100 Subject: r25920: ndr: change NTSTAUS into enum ndr_err_code (samba4 callers) lib/messaging/ lib/registry/ lib/ldb-samba/ librpc/rpc/ auth/auth_winbind.c auth/gensec/ auth/kerberos/ dsdb/repl/ dsdb/samdb/ dsdb/schema/ torture/ cluster/ctdb/ kdc/ ntvfs/ipc/ torture/rap/ ntvfs/ utils/getntacl.c ntptr/ smb_server/ libcli/wrepl/ wrepl_server/ libcli/cldap/ libcli/dgram/ libcli/ldap/ libcli/raw/ libcli/nbt/ libnet/ winbind/ rpc_server/ metze (This used to be commit 6223c7fddc972687eb577e04fc1c8e0604c35435) --- source4/libcli/raw/rawacl.c | 16 ++++++++++------ source4/libcli/raw/rawfile.c | 10 +++++----- source4/libcli/raw/rawfileinfo.c | 12 +++++++----- source4/libcli/raw/rawfsinfo.c | 8 ++++++-- source4/libcli/raw/rawsetfileinfo.c | 14 ++++++++------ 5 files changed, 36 insertions(+), 24 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawacl.c b/source4/libcli/raw/rawacl.c index 168f9c0309..0f2fdb60af 100644 --- a/source4/libcli/raw/rawacl.c +++ b/source4/libcli/raw/rawacl.c @@ -61,6 +61,7 @@ NTSTATUS smb_raw_query_secdesc_recv(struct smbcli_request *req, NTSTATUS status; struct smb_nttrans nt; struct ndr_pull *ndr; + enum ndr_err_code ndr_err; status = smb_raw_nttrans_recv(req, mem_ctx, &nt); if (!NT_STATUS_IS_OK(status)) { @@ -84,10 +85,13 @@ NTSTATUS smb_raw_query_secdesc_recv(struct smbcli_request *req, if (!io->query_secdesc.out.sd) { return NT_STATUS_NO_MEMORY; } - status = ndr_pull_security_descriptor(ndr, NDR_SCALARS|NDR_BUFFERS, - io->query_secdesc.out.sd); + ndr_err = ndr_pull_security_descriptor(ndr, NDR_SCALARS|NDR_BUFFERS, + io->query_secdesc.out.sd); + if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { + return ndr_map_error2ntstatus(ndr_err); + } - return status; + return NT_STATUS_OK; } @@ -114,7 +118,7 @@ struct smbcli_request *smb_raw_set_secdesc_send(struct smbcli_tree *tree, uint8_t params[8]; struct ndr_push *ndr; struct smbcli_request *req; - NTSTATUS status; + enum ndr_err_code ndr_err; nt.in.max_setup = 0; nt.in.max_param = 0; @@ -133,8 +137,8 @@ struct smbcli_request *smb_raw_set_secdesc_send(struct smbcli_tree *tree, ndr = ndr_push_init_ctx(NULL); if (!ndr) return NULL; - status = ndr_push_security_descriptor(ndr, NDR_SCALARS|NDR_BUFFERS, io->set_secdesc.in.sd); - if (!NT_STATUS_IS_OK(status)) { + ndr_err = ndr_push_security_descriptor(ndr, NDR_SCALARS|NDR_BUFFERS, io->set_secdesc.in.sd); + if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { talloc_free(ndr); return NULL; } diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c index 83303cf470..c34cb9c52f 100644 --- a/source4/libcli/raw/rawfile.c +++ b/source4/libcli/raw/rawfile.c @@ -263,7 +263,6 @@ static struct smbcli_request *smb_raw_nttrans_create_send(struct smbcli_tree *tr uint16_t fname_len; DATA_BLOB sd_blob, ea_blob; struct smbcli_request *req; - NTSTATUS status; nt.in.max_setup = 0; nt.in.max_param = 101; @@ -276,10 +275,11 @@ static struct smbcli_request *smb_raw_nttrans_create_send(struct smbcli_tree *tr ea_blob = data_blob(NULL, 0); if (parms->ntcreatex.in.sec_desc) { - status = ndr_push_struct_blob(&sd_blob, mem_ctx, - parms->ntcreatex.in.sec_desc, - (ndr_push_flags_fn_t)ndr_push_security_descriptor); - if (!NT_STATUS_IS_OK(status)) { + enum ndr_err_code ndr_err; + ndr_err = ndr_push_struct_blob(&sd_blob, mem_ctx, + parms->ntcreatex.in.sec_desc, + (ndr_push_flags_fn_t)ndr_push_security_descriptor); + if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { talloc_free(mem_ctx); return NULL; } diff --git a/source4/libcli/raw/rawfileinfo.c b/source4/libcli/raw/rawfileinfo.c index 8481995c1a..17e1792fe3 100644 --- a/source4/libcli/raw/rawfileinfo.c +++ b/source4/libcli/raw/rawfileinfo.c @@ -245,15 +245,17 @@ NTSTATUS smb_raw_fileinfo_passthru_parse(const DATA_BLOB *blob, TALLOC_CTX *mem_ return NT_STATUS_OK; case RAW_FILEINFO_SEC_DESC: { - NTSTATUS status; + enum ndr_err_code ndr_err; parms->query_secdesc.out.sd = talloc(mem_ctx, struct security_descriptor); NT_STATUS_HAVE_NO_MEMORY(parms->query_secdesc.out.sd); - status = ndr_pull_struct_blob(blob, mem_ctx, - parms->query_secdesc.out.sd, - (ndr_pull_flags_fn_t)ndr_pull_security_descriptor); - NT_STATUS_NOT_OK_RETURN(status); + ndr_err = ndr_pull_struct_blob(blob, mem_ctx, + parms->query_secdesc.out.sd, + (ndr_pull_flags_fn_t)ndr_pull_security_descriptor); + if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { + return ndr_map_error2ntstatus(ndr_err); + } return NT_STATUS_OK; } diff --git a/source4/libcli/raw/rawfsinfo.c b/source4/libcli/raw/rawfsinfo.c index ced977333d..73f1192df0 100644 --- a/source4/libcli/raw/rawfsinfo.c +++ b/source4/libcli/raw/rawfsinfo.c @@ -158,6 +158,7 @@ NTSTATUS smb_raw_fsinfo_passthru_parse(DATA_BLOB blob, TALLOC_CTX *mem_ctx, union smb_fsinfo *fsinfo) { NTSTATUS status = NT_STATUS_OK; + enum ndr_err_code ndr_err; int i; /* parse the results */ @@ -215,8 +216,11 @@ NTSTATUS smb_raw_fsinfo_passthru_parse(DATA_BLOB blob, TALLOC_CTX *mem_ctx, case RAW_QFS_OBJECTID_INFORMATION: QFS_CHECK_SIZE(64); - status = ndr_pull_struct_blob(&blob, mem_ctx, &fsinfo->objectid_information.out.guid, - (ndr_pull_flags_fn_t)ndr_pull_GUID); + ndr_err = ndr_pull_struct_blob(&blob, mem_ctx, &fsinfo->objectid_information.out.guid, + (ndr_pull_flags_fn_t)ndr_pull_GUID); + if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { + status = ndr_map_error2ntstatus(ndr_err); + } for (i=0;i<6;i++) { fsinfo->objectid_information.out.unknown[i] = BVAL(blob.data, 16 + i*8); } diff --git a/source4/libcli/raw/rawsetfileinfo.c b/source4/libcli/raw/rawsetfileinfo.c index 5fa0c1f2da..3ae2a2dd20 100644 --- a/source4/libcli/raw/rawsetfileinfo.c +++ b/source4/libcli/raw/rawsetfileinfo.c @@ -86,12 +86,14 @@ bool smb_raw_setfileinfo_passthru(TALLOC_CTX *mem_ctx, return true; case RAW_FILEINFO_SEC_DESC: { - NTSTATUS status; - - status = ndr_push_struct_blob(blob, mem_ctx, - parms->set_secdesc.in.sd, - (ndr_push_flags_fn_t)ndr_push_security_descriptor); - if (!NT_STATUS_IS_OK(status)) return false; + enum ndr_err_code ndr_err; + + ndr_err = ndr_push_struct_blob(blob, mem_ctx, + parms->set_secdesc.in.sd, + (ndr_push_flags_fn_t)ndr_push_security_descriptor); + if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { + return false; + } return true; } -- cgit From 089acd77b6cfb81b8951ae6db0fefc73c2599b22 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sun, 11 Nov 2007 13:59:01 +0100 Subject: r25924: fix bug in UNIX_INFO2 push code found make make valgrindtest metze (This used to be commit 9b151e6ceaeaa15e8cbd92f452522fe005f2382f) --- source4/libcli/raw/rawsetfileinfo.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawsetfileinfo.c b/source4/libcli/raw/rawsetfileinfo.c index 3ae2a2dd20..67dadf3287 100644 --- a/source4/libcli/raw/rawsetfileinfo.c +++ b/source4/libcli/raw/rawsetfileinfo.c @@ -177,7 +177,7 @@ static bool smb_raw_setinfo_backend(struct smbcli_tree *tree, smbcli_push_nttime(blob->data, 32, parms->unix_info2.in.change_time); SBVAL(blob->data, 40,parms->unix_info2.in.uid); SBVAL(blob->data, 48,parms->unix_info2.in.gid); - SIVAL(blob->data, 52,parms->unix_info2.in.file_type); + SIVAL(blob->data, 56,parms->unix_info2.in.file_type); SBVAL(blob->data, 60,parms->unix_info2.in.dev_major); SBVAL(blob->data, 68,parms->unix_info2.in.dev_minor); SBVAL(blob->data, 76,parms->unix_info2.in.unique_id); -- cgit From 6c999cd12344f2bb8b1d2941210b4c205b3e0aad Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 2 Dec 2007 22:32:11 +0100 Subject: r26236: Remove more uses of global_loadparm or specify loadparm_context explicitly. (This used to be commit 5b29ef7c03d9ae76b0ca909e9f03a58e1bad3521) --- source4/libcli/raw/rawnegotiate.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawnegotiate.c b/source4/libcli/raw/rawnegotiate.c index 82d6fe5236..78b9082521 100644 --- a/source4/libcli/raw/rawnegotiate.c +++ b/source4/libcli/raw/rawnegotiate.c @@ -46,6 +46,7 @@ static const struct { Send a negprot command. */ struct smbcli_request *smb_raw_negotiate_send(struct smbcli_transport *transport, + bool unicode, int maxprotocol) { struct smbcli_request *req; @@ -58,7 +59,7 @@ struct smbcli_request *smb_raw_negotiate_send(struct smbcli_transport *transport } flags2 |= FLAGS2_32_BIT_ERROR_CODES; - if (lp_unicode(global_loadparm)) { + if (unicode) { flags2 |= FLAGS2_UNICODE_STRINGS; } flags2 |= FLAGS2_EXTENDED_ATTRIBUTES; @@ -190,8 +191,8 @@ failed: /* Send a negprot command (sync interface) */ -NTSTATUS smb_raw_negotiate(struct smbcli_transport *transport, int maxprotocol) +NTSTATUS smb_raw_negotiate(struct smbcli_transport *transport, bool unicode, int maxprotocol) { - struct smbcli_request *req = smb_raw_negotiate_send(transport, maxprotocol); + struct smbcli_request *req = smb_raw_negotiate_send(transport, unicode, maxprotocol); return smb_raw_negotiate_recv(req); } -- cgit From 1fbdd6ef1dfb8704de0524fc6f5c33e1418858cd Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 3 Dec 2007 18:47:35 +0100 Subject: r26264: pass name resolve order explicitly, use torture context for settings in dssync tests. (This used to be commit c7eae1c7842f9ff8b70cce9e5d6f3ebbbe78e83b) --- source4/libcli/raw/clisocket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index a748b40a32..e3420313c5 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -239,7 +239,7 @@ struct smbcli_socket *smbcli_sock_connect_byname(const char *host, int port, make_nbt_name(&nbt_name, host, name_type); - status = resolve_name(&nbt_name, tmp_ctx, &address, event_ctx); + status = resolve_name(&nbt_name, tmp_ctx, &address, event_ctx, lp_name_resolve_order(global_loadparm)); if (!NT_STATUS_IS_OK(status)) { talloc_free(tmp_ctx); return NULL; -- cgit From 2f8dc4f48f1802baa3405e7803563f6840e0d1b3 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 3 Dec 2007 21:25:06 +0100 Subject: r26266: Remove more global_loadparm uses. (This used to be commit 99113075c4a96679bcec4f4d6bba4acb3dee4245) --- source4/libcli/raw/clisocket.c | 3 ++- source4/libcli/raw/clitransport.c | 8 +++++--- 2 files changed, 7 insertions(+), 4 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index e3420313c5..6e12d8073d 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -199,6 +199,7 @@ resolve a hostname and connect ****************************************************************************/ struct smbcli_socket *smbcli_sock_connect_byname(const char *host, int port, TALLOC_CTX *mem_ctx, + const char **name_resolve_order, struct event_context *event_ctx) { int name_type = NBT_NAME_SERVER; @@ -239,7 +240,7 @@ struct smbcli_socket *smbcli_sock_connect_byname(const char *host, int port, make_nbt_name(&nbt_name, host, name_type); - status = resolve_name(&nbt_name, tmp_ctx, &address, event_ctx, lp_name_resolve_order(global_loadparm)); + status = resolve_name(&nbt_name, tmp_ctx, &address, event_ctx, name_resolve_order); if (!NT_STATUS_IS_OK(status)) { talloc_free(tmp_ctx); return NULL; diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 0bf805910e..11df6c6c96 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -73,7 +73,9 @@ static NTSTATUS smbcli_transport_finish_recv(void *private, DATA_BLOB blob); */ struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock, TALLOC_CTX *parent_ctx, - bool primary) + bool primary, + int max_xmit, + int max_mux) { struct smbcli_transport *transport; @@ -88,8 +90,8 @@ struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock, transport->negotiate.protocol = PROTOCOL_NT1; transport->options.use_spnego = lp_use_spnego(global_loadparm) && lp_nt_status_support(global_loadparm); - transport->options.max_xmit = lp_max_xmit(global_loadparm); - transport->options.max_mux = lp_maxmux(global_loadparm); + transport->options.max_xmit = max_xmit; + transport->options.max_mux = max_mux; transport->options.request_timeout = SMB_REQUEST_TIMEOUT; transport->negotiate.max_xmit = transport->options.max_xmit; -- cgit From 39ee38d9c1aabf4db065b433d067d0da053d7d61 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 6 Dec 2007 17:52:23 +0100 Subject: r26316: Use contexts for conversion functions. (This used to be commit f6420d933b5b011d428974f3a2a57edf19e6f482) --- source4/libcli/raw/rawfileinfo.c | 4 +++- source4/libcli/raw/rawrequest.c | 24 ++++++++++++------------ 2 files changed, 15 insertions(+), 13 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawfileinfo.c b/source4/libcli/raw/rawfileinfo.c index 17e1792fe3..972ae7f5e1 100644 --- a/source4/libcli/raw/rawfileinfo.c +++ b/source4/libcli/raw/rawfileinfo.c @@ -61,7 +61,9 @@ NTSTATUS smbcli_parse_stream_info(DATA_BLOB blob, TALLOC_CTX *mem_ctx, if (nlen > blob.length - (ofs + 24)) { return NT_STATUS_INFO_LENGTH_MISMATCH; } - size = convert_string_talloc(io->streams, CH_UTF16, CH_UNIX, + size = convert_string_talloc(io->streams, + global_smb_iconv_convenience, + CH_UTF16, CH_UNIX, blob.data+ofs+24, nlen, &vstr); if (size == -1) { return NT_STATUS_ILLEGAL_CHARACTER; diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 6a4f432088..43c984721b 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -418,7 +418,7 @@ size_t smbcli_req_append_string(struct smbcli_request *req, const char *str, uin smbcli_req_grow_allocation(req, len + req->out.data_size); - len = push_string(req->out.data + req->out.data_size, str, len, flags); + len = push_string(global_smb_iconv_convenience, req->out.data + req->out.data_size, str, len, flags); smbcli_req_grow_data(req, len + req->out.data_size); @@ -574,7 +574,7 @@ static size_t smbcli_req_pull_ucs2(struct smbcli_request *req, TALLOC_CTX *mem_c return 0; } - ret = convert_string_talloc(mem_ctx, CH_UTF16, CH_UNIX, src, src_len2, (void **)dest); + ret = convert_string_talloc(mem_ctx, global_smb_iconv_convenience, CH_UTF16, CH_UNIX, src, src_len2, (void **)dest); if (ret == -1) { *dest = NULL; return 0; @@ -616,7 +616,7 @@ size_t smbcli_req_pull_ascii(struct smbcli_request *req, TALLOC_CTX *mem_ctx, src_len2++; } - ret = convert_string_talloc(mem_ctx, CH_DOS, CH_UNIX, src, src_len2, (void **)dest); + ret = convert_string_talloc(mem_ctx, global_smb_iconv_convenience, CH_DOS, CH_UNIX, src, src_len2, (void **)dest); if (ret == -1) { *dest = NULL; @@ -626,7 +626,7 @@ size_t smbcli_req_pull_ascii(struct smbcli_request *req, TALLOC_CTX *mem_ctx, return ret; } -/* +/** pull a string from a request packet, returning a talloced string the string length is limited by the 3 things: @@ -651,7 +651,7 @@ size_t smbcli_req_pull_string(struct smbcli_request *req, TALLOC_CTX *mem_ctx, } -/* +/** pull a DATA_BLOB from a reply packet, returning a talloced blob make sure we don't go past end of packet @@ -723,7 +723,7 @@ NTTIME smbcli_pull_nttime(void *base, uint16_t offset) return ret; } -/* +/** pull a UCS2 string from a blob, returning a talloced unix string the string length is limited by the 3 things: @@ -769,7 +769,7 @@ size_t smbcli_blob_pull_ucs2(TALLOC_CTX* mem_ctx, src_len2 = utf16_len_n(src, src_len); - ret = convert_string_talloc(mem_ctx, CH_UTF16, CH_UNIX, src, src_len2, (void **)&dest2); + ret = convert_string_talloc(mem_ctx, global_smb_iconv_convenience, CH_UTF16, CH_UNIX, src, src_len2, (void **)&dest2); if (ret == -1) { *dest = NULL; return 0; @@ -779,7 +779,7 @@ size_t smbcli_blob_pull_ucs2(TALLOC_CTX* mem_ctx, return src_len2 + alignment; } -/* +/** pull a ascii string from a blob, returning a talloced string the string length is limited by the 3 things: @@ -815,7 +815,7 @@ static size_t smbcli_blob_pull_ascii(TALLOC_CTX *mem_ctx, src_len2++; } - ret = convert_string_talloc(mem_ctx, CH_DOS, CH_UNIX, src, src_len2, (void **)&dest2); + ret = convert_string_talloc(mem_ctx, global_smb_iconv_convenience, CH_DOS, CH_UNIX, src, src_len2, (void **)&dest2); if (ret == -1) { *dest = NULL; @@ -826,7 +826,7 @@ static size_t smbcli_blob_pull_ascii(TALLOC_CTX *mem_ctx, return ret; } -/* +/** pull a string from a blob, returning a talloced struct smb_wire_string the string length is limited by the 3 things: @@ -895,7 +895,7 @@ size_t smbcli_blob_pull_string(struct smbcli_session *session, blob->data+str_offset, dest->private_length, flags); } -/* +/** pull a string from a blob, returning a talloced char * Currently only used by the UNIX search info level. @@ -965,7 +965,7 @@ size_t smbcli_blob_append_string(struct smbcli_session *session, return 0; } - len = push_string(blob->data + blob->length, str, max_len, flags); + len = push_string(global_smb_iconv_convenience, blob->data + blob->length, str, max_len, flags); blob->length += len; -- cgit From 01d2acfdb4c4c0349a28a18c5c0da5b960b02791 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 7 Dec 2007 16:04:17 +0100 Subject: r26335: Specify name_resolve_order to socket code. (This used to be commit b03e5d00110be3f1fe5809dad4eb6ca5cea7463d) --- source4/libcli/raw/clisocket.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 6e12d8073d..9b744dcc18 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -96,6 +96,7 @@ struct composite_context *smbcli_sock_connect_send(TALLOC_CTX *mem_ctx, ctx = socket_connect_multi_send(state, host_addr, state->num_ports, state->ports, + lp_name_resolve_order(global_loadparm), state->ctx->event_ctx); if (ctx == NULL) goto failed; ctx->async.fn = smbcli_sock_connect_recv_conn; -- cgit From 5f4842cf65ce64bfdf577cd549565da20ca818cf Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 10 Dec 2007 18:41:19 +0100 Subject: r26376: Add context for libcli_resolve. (This used to be commit 459e1466a411d6f83b7372e248566e6e71c745fc) --- source4/libcli/raw/clisocket.c | 6 +++--- source4/libcli/raw/libcliraw.h | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 9b744dcc18..c09104e256 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -96,7 +96,7 @@ struct composite_context *smbcli_sock_connect_send(TALLOC_CTX *mem_ctx, ctx = socket_connect_multi_send(state, host_addr, state->num_ports, state->ports, - lp_name_resolve_order(global_loadparm), + lp_resolve_context(global_loadparm), state->ctx->event_ctx); if (ctx == NULL) goto failed; ctx->async.fn = smbcli_sock_connect_recv_conn; @@ -200,7 +200,7 @@ resolve a hostname and connect ****************************************************************************/ struct smbcli_socket *smbcli_sock_connect_byname(const char *host, int port, TALLOC_CTX *mem_ctx, - const char **name_resolve_order, + struct resolve_context *resolve_ctx, struct event_context *event_ctx) { int name_type = NBT_NAME_SERVER; @@ -241,7 +241,7 @@ struct smbcli_socket *smbcli_sock_connect_byname(const char *host, int port, make_nbt_name(&nbt_name, host, name_type); - status = resolve_name(&nbt_name, tmp_ctx, &address, event_ctx, name_resolve_order); + status = resolve_name(resolve_ctx, &nbt_name, tmp_ctx, &address, event_ctx); if (!NT_STATUS_IS_OK(status)) { talloc_free(tmp_ctx); return NULL; diff --git a/source4/libcli/raw/libcliraw.h b/source4/libcli/raw/libcliraw.h index a11a9c9e58..6c97e61f04 100644 --- a/source4/libcli/raw/libcliraw.h +++ b/source4/libcli/raw/libcliraw.h @@ -30,6 +30,7 @@ struct smbcli_request; /* forward declare */ struct smbcli_session; /* forward declare */ struct smbcli_transport; /* forward declare */ +struct resolve_context; struct cli_credentials; /* default timeout for all smb requests */ -- cgit From 4b0199a5493ea2b88558cc40871e63c1dc8dbb56 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 12 Dec 2007 02:15:29 +0100 Subject: r26409: Pass smb ports along. (This used to be commit 2833f320de1f1fd39c710ad0a61c3fa1bb1df31f) --- source4/libcli/raw/clisocket.c | 36 +++++++++++------------------------- source4/libcli/raw/clitree.c | 4 ++-- 2 files changed, 13 insertions(+), 27 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index c09104e256..9732ab1638 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -45,12 +45,13 @@ static void smbcli_sock_connect_recv_conn(struct composite_context *ctx); struct composite_context *smbcli_sock_connect_send(TALLOC_CTX *mem_ctx, const char *host_addr, - int port, + const char **ports, const char *host_name, struct event_context *event_ctx) { struct composite_context *result, *ctx; struct sock_connect_state *state; + int i; result = talloc_zero(mem_ctx, struct composite_context); if (result == NULL) goto failed; @@ -72,26 +73,11 @@ struct composite_context *smbcli_sock_connect_send(TALLOC_CTX *mem_ctx, state->host_name = talloc_strdup(state, host_name); if (state->host_name == NULL) goto failed; - if (port == 0) { - const char **ports = lp_smb_ports(global_loadparm); - int i; - - for (i=0;ports[i];i++) /* noop */ ; - if (i == 0) { - DEBUG(3, ("no smb ports defined\n")); - goto failed; - } - state->num_ports = i; - state->ports = talloc_array(state, uint16_t, i); - if (state->ports == NULL) goto failed; - for (i=0;ports[i];i++) { - state->ports[i] = atoi(ports[i]); - } - } else { - state->ports = talloc_array(state, uint16_t, 1); - if (state->ports == NULL) goto failed; - state->num_ports = 1; - state->ports[0] = port; + state->num_ports = str_list_length(ports); + state->ports = talloc_array(state, uint16_t, state->num_ports); + if (state->ports == NULL) goto failed; + for (i=0;ports[i];i++) { + state->ports[i] = atoi(ports[i]); } ctx = socket_connect_multi_send(state, host_addr, @@ -164,13 +150,13 @@ NTSTATUS smbcli_sock_connect_recv(struct composite_context *c, sync version of the function */ NTSTATUS smbcli_sock_connect(TALLOC_CTX *mem_ctx, - const char *host_addr, int port, + const char *host_addr, const char **ports, const char *host_name, struct event_context *event_ctx, struct smbcli_socket **result) { struct composite_context *c = - smbcli_sock_connect_send(mem_ctx, host_addr, port, host_name, + smbcli_sock_connect_send(mem_ctx, host_addr, ports, host_name, event_ctx); return smbcli_sock_connect_recv(c, mem_ctx, result); } @@ -198,7 +184,7 @@ void smbcli_sock_set_options(struct smbcli_socket *sock, const char *options) /**************************************************************************** resolve a hostname and connect ****************************************************************************/ -struct smbcli_socket *smbcli_sock_connect_byname(const char *host, int port, +struct smbcli_socket *smbcli_sock_connect_byname(const char *host, const char **ports, TALLOC_CTX *mem_ctx, struct resolve_context *resolve_ctx, struct event_context *event_ctx) @@ -247,7 +233,7 @@ struct smbcli_socket *smbcli_sock_connect_byname(const char *host, int port, return NULL; } - status = smbcli_sock_connect(mem_ctx, address, port, name, event_ctx, + status = smbcli_sock_connect(mem_ctx, address, ports, name, event_ctx, &result); if (!NT_STATUS_IS_OK(status)) { diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index 54f8ac95a4..890d5470da 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -171,7 +171,7 @@ NTSTATUS smb_tree_disconnect(struct smbcli_tree *tree) */ NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx, struct smbcli_tree **ret_tree, - const char *dest_host, int port, + const char *dest_host, const char **dest_ports, const char *service, const char *service_type, struct cli_credentials *credentials, struct event_context *ev) @@ -184,7 +184,7 @@ NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx, } io.in.dest_host = dest_host; - io.in.port = port; + io.in.dest_ports = dest_ports; io.in.called_name = strupper_talloc(tmp_ctx, dest_host); io.in.service = service; io.in.service_type = service_type; -- cgit From d891c0c74a03d797aed1c5ac0329fd9d1d78da63 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 13 Dec 2007 22:46:09 +0100 Subject: r26429: Avoid use of global_smb_iconv_convenience. (This used to be commit d37136b7abfbba75ef2e5ab855eb3382b9648b8c) --- source4/libcli/raw/rawfileinfo.c | 3 ++- source4/libcli/raw/rawrequest.c | 13 +++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawfileinfo.c b/source4/libcli/raw/rawfileinfo.c index 972ae7f5e1..9827217a04 100644 --- a/source4/libcli/raw/rawfileinfo.c +++ b/source4/libcli/raw/rawfileinfo.c @@ -22,6 +22,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" #include "librpc/gen_ndr/ndr_security.h" +#include "param/param.h" /* local macros to make the code more readable */ #define FINFO_CHECK_MIN_SIZE(size) if (blob->length < (size)) { \ @@ -62,7 +63,7 @@ NTSTATUS smbcli_parse_stream_info(DATA_BLOB blob, TALLOC_CTX *mem_ctx, return NT_STATUS_INFO_LENGTH_MISMATCH; } size = convert_string_talloc(io->streams, - global_smb_iconv_convenience, + lp_iconv_convenience(global_loadparm), CH_UTF16, CH_UNIX, blob.data+ofs+24, nlen, &vstr); if (size == -1) { diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 43c984721b..e7dffaf054 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -26,6 +26,7 @@ #include "libcli/raw/libcliraw.h" #include "lib/util/dlinklist.h" #include "lib/events/events.h" +#include "param/param.h" /* we over allocate the data buffer to prevent too many realloc calls */ #define REQ_OVER_ALLOCATION 0 @@ -418,7 +419,7 @@ size_t smbcli_req_append_string(struct smbcli_request *req, const char *str, uin smbcli_req_grow_allocation(req, len + req->out.data_size); - len = push_string(global_smb_iconv_convenience, req->out.data + req->out.data_size, str, len, flags); + len = push_string(lp_iconv_convenience(global_loadparm), req->out.data + req->out.data_size, str, len, flags); smbcli_req_grow_data(req, len + req->out.data_size); @@ -574,7 +575,7 @@ static size_t smbcli_req_pull_ucs2(struct smbcli_request *req, TALLOC_CTX *mem_c return 0; } - ret = convert_string_talloc(mem_ctx, global_smb_iconv_convenience, CH_UTF16, CH_UNIX, src, src_len2, (void **)dest); + ret = convert_string_talloc(mem_ctx, lp_iconv_convenience(global_loadparm), CH_UTF16, CH_UNIX, src, src_len2, (void **)dest); if (ret == -1) { *dest = NULL; return 0; @@ -616,7 +617,7 @@ size_t smbcli_req_pull_ascii(struct smbcli_request *req, TALLOC_CTX *mem_ctx, src_len2++; } - ret = convert_string_talloc(mem_ctx, global_smb_iconv_convenience, CH_DOS, CH_UNIX, src, src_len2, (void **)dest); + ret = convert_string_talloc(mem_ctx, lp_iconv_convenience(global_loadparm), CH_DOS, CH_UNIX, src, src_len2, (void **)dest); if (ret == -1) { *dest = NULL; @@ -769,7 +770,7 @@ size_t smbcli_blob_pull_ucs2(TALLOC_CTX* mem_ctx, src_len2 = utf16_len_n(src, src_len); - ret = convert_string_talloc(mem_ctx, global_smb_iconv_convenience, CH_UTF16, CH_UNIX, src, src_len2, (void **)&dest2); + ret = convert_string_talloc(mem_ctx, lp_iconv_convenience(global_loadparm), CH_UTF16, CH_UNIX, src, src_len2, (void **)&dest2); if (ret == -1) { *dest = NULL; return 0; @@ -815,7 +816,7 @@ static size_t smbcli_blob_pull_ascii(TALLOC_CTX *mem_ctx, src_len2++; } - ret = convert_string_talloc(mem_ctx, global_smb_iconv_convenience, CH_DOS, CH_UNIX, src, src_len2, (void **)&dest2); + ret = convert_string_talloc(mem_ctx, lp_iconv_convenience(global_loadparm), CH_DOS, CH_UNIX, src, src_len2, (void **)&dest2); if (ret == -1) { *dest = NULL; @@ -965,7 +966,7 @@ size_t smbcli_blob_append_string(struct smbcli_session *session, return 0; } - len = push_string(global_smb_iconv_convenience, blob->data + blob->length, str, max_len, flags); + len = push_string(lp_iconv_convenience(global_loadparm), blob->data + blob->length, str, max_len, flags); blob->length += len; -- cgit From 61873ce94c172c801a4831de5550a8e0fe54c5f5 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 13 Dec 2007 22:46:23 +0100 Subject: r26431: Require ndr_push creators to specify a iconv_convenience context. (This used to be commit 7352206f4450fdf881b95bda064cedd9d2477e4c) --- source4/libcli/raw/rawacl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawacl.c b/source4/libcli/raw/rawacl.c index 0f2fdb60af..e7747de94c 100644 --- a/source4/libcli/raw/rawacl.c +++ b/source4/libcli/raw/rawacl.c @@ -21,6 +21,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" #include "librpc/gen_ndr/ndr_security.h" +#include "param/param.h" /**************************************************************************** fetch file ACL (async send) @@ -134,7 +135,7 @@ struct smbcli_request *smb_raw_set_secdesc_send(struct smbcli_tree *tree, nt.in.params.data = params; nt.in.params.length = 8; - ndr = ndr_push_init_ctx(NULL); + ndr = ndr_push_init_ctx(NULL, lp_iconv_convenience(global_loadparm)); if (!ndr) return NULL; ndr_err = ndr_push_security_descriptor(ndr, NDR_SCALARS|NDR_BUFFERS, io->set_secdesc.in.sd); -- cgit From d1e716cf4331bf09cfe15a6634bc5887aff81d20 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 13 Dec 2007 22:46:27 +0100 Subject: r26432: Require ndr_pull users to specify iconv_convenience. (This used to be commit 28b1d36551b75241c1cf9fca5d74f45a6dc884ab) --- source4/libcli/raw/rawacl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawacl.c b/source4/libcli/raw/rawacl.c index e7747de94c..9d2068f35f 100644 --- a/source4/libcli/raw/rawacl.c +++ b/source4/libcli/raw/rawacl.c @@ -77,7 +77,8 @@ NTSTATUS smb_raw_query_secdesc_recv(struct smbcli_request *req, nt.out.data.length = IVAL(nt.out.params.data, 0); - ndr = ndr_pull_init_blob(&nt.out.data, mem_ctx); + ndr = ndr_pull_init_blob(&nt.out.data, mem_ctx, + lp_iconv_convenience(global_loadparm)); if (!ndr) { return NT_STATUS_INVALID_PARAMETER; } -- cgit From 86dc05e99f124db47f2743d1fc23117a7f5145ab Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 1 Jan 2008 22:05:05 -0600 Subject: r26638: libndr: Require explicitly specifying iconv_convenience for ndr_struct_push_blob(). (This used to be commit 61ad78ac98937ef7a9aa32075a91a1c95b7606b3) --- source4/libcli/raw/rawfile.c | 2 +- source4/libcli/raw/rawsetfileinfo.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c index c34cb9c52f..3b6ca68526 100644 --- a/source4/libcli/raw/rawfile.c +++ b/source4/libcli/raw/rawfile.c @@ -276,7 +276,7 @@ static struct smbcli_request *smb_raw_nttrans_create_send(struct smbcli_tree *tr if (parms->ntcreatex.in.sec_desc) { enum ndr_err_code ndr_err; - ndr_err = ndr_push_struct_blob(&sd_blob, mem_ctx, + ndr_err = ndr_push_struct_blob(&sd_blob, mem_ctx, NULL, parms->ntcreatex.in.sec_desc, (ndr_push_flags_fn_t)ndr_push_security_descriptor); if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { diff --git a/source4/libcli/raw/rawsetfileinfo.c b/source4/libcli/raw/rawsetfileinfo.c index 67dadf3287..a9a1a3547e 100644 --- a/source4/libcli/raw/rawsetfileinfo.c +++ b/source4/libcli/raw/rawsetfileinfo.c @@ -88,7 +88,7 @@ bool smb_raw_setfileinfo_passthru(TALLOC_CTX *mem_ctx, case RAW_FILEINFO_SEC_DESC: { enum ndr_err_code ndr_err; - ndr_err = ndr_push_struct_blob(blob, mem_ctx, + ndr_err = ndr_push_struct_blob(blob, mem_ctx, NULL, parms->set_secdesc.in.sd, (ndr_push_flags_fn_t)ndr_push_security_descriptor); if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { -- cgit From 7d5f0e0893d42b56145a3ffa34e3b4b9906cbd91 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 1 Jan 2008 22:05:13 -0600 Subject: r26639: librpc: Pass iconv convenience on from RPC connection to NDR library, so it can be overridden by OpenChange. (This used to be commit 2f29f80e07adef1f020173f2cd6d947d0ef505ce) --- source4/libcli/raw/rawfileinfo.c | 2 +- source4/libcli/raw/rawfsinfo.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawfileinfo.c b/source4/libcli/raw/rawfileinfo.c index 9827217a04..ed5475e926 100644 --- a/source4/libcli/raw/rawfileinfo.c +++ b/source4/libcli/raw/rawfileinfo.c @@ -253,7 +253,7 @@ NTSTATUS smb_raw_fileinfo_passthru_parse(const DATA_BLOB *blob, TALLOC_CTX *mem_ parms->query_secdesc.out.sd = talloc(mem_ctx, struct security_descriptor); NT_STATUS_HAVE_NO_MEMORY(parms->query_secdesc.out.sd); - ndr_err = ndr_pull_struct_blob(blob, mem_ctx, + ndr_err = ndr_pull_struct_blob(blob, mem_ctx, NULL, parms->query_secdesc.out.sd, (ndr_pull_flags_fn_t)ndr_pull_security_descriptor); if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { diff --git a/source4/libcli/raw/rawfsinfo.c b/source4/libcli/raw/rawfsinfo.c index 73f1192df0..bfb5db828e 100644 --- a/source4/libcli/raw/rawfsinfo.c +++ b/source4/libcli/raw/rawfsinfo.c @@ -216,7 +216,7 @@ NTSTATUS smb_raw_fsinfo_passthru_parse(DATA_BLOB blob, TALLOC_CTX *mem_ctx, case RAW_QFS_OBJECTID_INFORMATION: QFS_CHECK_SIZE(64); - ndr_err = ndr_pull_struct_blob(&blob, mem_ctx, &fsinfo->objectid_information.out.guid, + ndr_err = ndr_pull_struct_blob(&blob, mem_ctx, NULL, &fsinfo->objectid_information.out.guid, (ndr_pull_flags_fn_t)ndr_pull_GUID); if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { status = ndr_map_error2ntstatus(ndr_err); -- cgit From 771b347f9b185895390445be96081c781e28a26d Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 2 Jan 2008 18:39:01 -0600 Subject: r26644: Janitorial: Pass resolve_context explicitly to various SMB functions, should help fix the build for OpenChange. (This used to be commit 385ffe4f4cc9a21a760c0f00410f56e2592fd507) --- source4/libcli/raw/clisocket.c | 7 +++++-- source4/libcli/raw/clitransport.c | 6 +++--- source4/libcli/raw/clitree.c | 3 ++- 3 files changed, 10 insertions(+), 6 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 9732ab1638..8beaef3daa 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -47,6 +47,7 @@ struct composite_context *smbcli_sock_connect_send(TALLOC_CTX *mem_ctx, const char *host_addr, const char **ports, const char *host_name, + struct resolve_context *resolve_ctx, struct event_context *event_ctx) { struct composite_context *result, *ctx; @@ -152,11 +153,13 @@ NTSTATUS smbcli_sock_connect_recv(struct composite_context *c, NTSTATUS smbcli_sock_connect(TALLOC_CTX *mem_ctx, const char *host_addr, const char **ports, const char *host_name, + struct resolve_context *resolve_ctx, struct event_context *event_ctx, struct smbcli_socket **result) { struct composite_context *c = smbcli_sock_connect_send(mem_ctx, host_addr, ports, host_name, + resolve_ctx, event_ctx); return smbcli_sock_connect_recv(c, mem_ctx, result); } @@ -233,8 +236,8 @@ struct smbcli_socket *smbcli_sock_connect_byname(const char *host, const char ** return NULL; } - status = smbcli_sock_connect(mem_ctx, address, ports, name, event_ctx, - &result); + status = smbcli_sock_connect(mem_ctx, address, ports, name, resolve_ctx, + event_ctx, &result); if (!NT_STATUS_IS_OK(status)) { DEBUG(9, ("smbcli_sock_connect failed: %s\n", diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 11df6c6c96..bdaeaeb58a 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -75,7 +75,8 @@ struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock, TALLOC_CTX *parent_ctx, bool primary, int max_xmit, - int max_mux) + int max_mux, + bool use_spnego) { struct smbcli_transport *transport; @@ -88,8 +89,7 @@ struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock, transport->socket = talloc_reference(transport, sock); } transport->negotiate.protocol = PROTOCOL_NT1; - transport->options.use_spnego = lp_use_spnego(global_loadparm) && - lp_nt_status_support(global_loadparm); + transport->options.use_spnego = use_spnego; transport->options.max_xmit = max_xmit; transport->options.max_mux = max_mux; transport->options.request_timeout = SMB_REQUEST_TIMEOUT; diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index 890d5470da..6b14893c4e 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -174,6 +174,7 @@ NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx, const char *dest_host, const char **dest_ports, const char *service, const char *service_type, struct cli_credentials *credentials, + struct resolve_context *resolve_ctx, struct event_context *ev) { struct smb_composite_connect io; @@ -192,7 +193,7 @@ NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx, io.in.fallback_to_anonymous = false; io.in.workgroup = lp_workgroup(global_loadparm); - status = smb_composite_connect(&io, parent_ctx, ev); + status = smb_composite_connect(&io, parent_ctx, resolve_ctx, ev); if (NT_STATUS_IS_OK(status)) { *ret_tree = io.out.tree; } -- cgit From 969b8579c755441092e27b499ecedbd7d725816d Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 2 Jan 2008 18:39:15 -0600 Subject: r26646: libcli/smb_composite: Allow specifying SMB parameters in smb_composite_connect structure. AFAIK no global variables will now be used when doing RPC client connections. (This used to be commit 0ef75e4e3cb0e1bd10e367a00f5e9b725587c40a) --- source4/libcli/raw/clitree.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index 6b14893c4e..94fa37383b 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -192,6 +192,14 @@ NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx, io.in.credentials = credentials; io.in.fallback_to_anonymous = false; io.in.workgroup = lp_workgroup(global_loadparm); + io.in.max_xmit = lp_max_xmit(global_loadparm); + io.in.max_mux = lp_maxmux(global_loadparm); + io.in.ntstatus_support = lp_nt_status_support(global_loadparm); + io.in.max_protocol = lp_cli_maxprotocol(global_loadparm); + io.in.unicode = lp_unicode(global_loadparm); + io.in.use_spnego = lp_use_spnego(global_loadparm) && lp_nt_status_support(global_loadparm); + + status = smb_composite_connect(&io, parent_ctx, resolve_ctx, ev); if (NT_STATUS_IS_OK(status)) { -- cgit From 425732f688865ebe2bfe568c8278edec50cbdedf Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 3 Jan 2008 17:21:58 -0600 Subject: r26651: libsmb: Allow specifying signing policy from higher up. The number of arguments is getting a bit excessive now, so it probably makes sense to pass in the smbcli_options struct rather than all members individually and add a convenience function for obtaining a smbcli_options struct from a loadparm context. (This used to be commit 9f64213463b5bf3bcbf36913139e9a5042e967a2) --- source4/libcli/raw/clitransport.c | 4 +++- source4/libcli/raw/clitree.c | 3 +-- source4/libcli/raw/libcliraw.h | 1 + source4/libcli/raw/smb_signing.c | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index bdaeaeb58a..3ca828d46b 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -76,7 +76,8 @@ struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock, bool primary, int max_xmit, int max_mux, - bool use_spnego) + bool use_spnego, + enum smb_signing_state signing) { struct smbcli_transport *transport; @@ -93,6 +94,7 @@ struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock, transport->options.max_xmit = max_xmit; transport->options.max_mux = max_mux; transport->options.request_timeout = SMB_REQUEST_TIMEOUT; + transport->options.signing = signing; transport->negotiate.max_xmit = transport->options.max_xmit; diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index 94fa37383b..3d8a6760a1 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -198,8 +198,7 @@ NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx, io.in.max_protocol = lp_cli_maxprotocol(global_loadparm); io.in.unicode = lp_unicode(global_loadparm); io.in.use_spnego = lp_use_spnego(global_loadparm) && lp_nt_status_support(global_loadparm); - - + io.in.signing = lp_client_signing(global_loadparm); status = smb_composite_connect(&io, parent_ctx, resolve_ctx, ev); if (NT_STATUS_IS_OK(status)) { diff --git a/source4/libcli/raw/libcliraw.h b/source4/libcli/raw/libcliraw.h index 6c97e61f04..dd6904dec2 100644 --- a/source4/libcli/raw/libcliraw.h +++ b/source4/libcli/raw/libcliraw.h @@ -97,6 +97,7 @@ struct smbcli_options { uint32_t max_xmit; uint16_t max_mux; int request_timeout; + enum smb_signing_state signing; }; /* this is the context for the client transport layer */ diff --git a/source4/libcli/raw/smb_signing.c b/source4/libcli/raw/smb_signing.c index e19e81af7e..0053710aaf 100644 --- a/source4/libcli/raw/smb_signing.c +++ b/source4/libcli/raw/smb_signing.c @@ -383,7 +383,7 @@ bool smbcli_init_signing(struct smbcli_transport *transport) return false; } - switch (lp_client_signing(global_loadparm)) { + switch (transport->options.signing) { case SMB_SIGNING_OFF: transport->negotiate.sign_info.allow_smb_signing = false; break; -- cgit From dcc282590b34537fc1ead61c3300172528273b44 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 3 Jan 2008 17:22:12 -0600 Subject: r26654: libcli/smb_composite: Rather than specifying each of the gazillion options for SMB individually, just specify the smbcli_options struct. (This used to be commit 8a97886e24a4b969aa91409c06f423b71a45f6eb) --- source4/libcli/raw/clitransport.c | 12 ++---------- source4/libcli/raw/clitree.c | 12 +++--------- source4/libcli/raw/libcliraw.h | 3 +++ 3 files changed, 8 insertions(+), 19 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 3ca828d46b..62c32d3058 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -74,10 +74,7 @@ static NTSTATUS smbcli_transport_finish_recv(void *private, DATA_BLOB blob); struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock, TALLOC_CTX *parent_ctx, bool primary, - int max_xmit, - int max_mux, - bool use_spnego, - enum smb_signing_state signing) + struct smbcli_options *options) { struct smbcli_transport *transport; @@ -90,12 +87,7 @@ struct smbcli_transport *smbcli_transport_init(struct smbcli_socket *sock, transport->socket = talloc_reference(transport, sock); } transport->negotiate.protocol = PROTOCOL_NT1; - transport->options.use_spnego = use_spnego; - transport->options.max_xmit = max_xmit; - transport->options.max_mux = max_mux; - transport->options.request_timeout = SMB_REQUEST_TIMEOUT; - transport->options.signing = signing; - + transport->options = *options; transport->negotiate.max_xmit = transport->options.max_xmit; /* setup the stream -> packet parser */ diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index 3d8a6760a1..ae63d94acd 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -175,7 +175,8 @@ NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx, const char *service, const char *service_type, struct cli_credentials *credentials, struct resolve_context *resolve_ctx, - struct event_context *ev) + struct event_context *ev, + struct smbcli_options *options) { struct smb_composite_connect io; NTSTATUS status; @@ -191,14 +192,7 @@ NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx, io.in.service_type = service_type; io.in.credentials = credentials; io.in.fallback_to_anonymous = false; - io.in.workgroup = lp_workgroup(global_loadparm); - io.in.max_xmit = lp_max_xmit(global_loadparm); - io.in.max_mux = lp_maxmux(global_loadparm); - io.in.ntstatus_support = lp_nt_status_support(global_loadparm); - io.in.max_protocol = lp_cli_maxprotocol(global_loadparm); - io.in.unicode = lp_unicode(global_loadparm); - io.in.use_spnego = lp_use_spnego(global_loadparm) && lp_nt_status_support(global_loadparm); - io.in.signing = lp_client_signing(global_loadparm); + io.in.options = *options; status = smb_composite_connect(&io, parent_ctx, resolve_ctx, ev); if (NT_STATUS_IS_OK(status)) { diff --git a/source4/libcli/raw/libcliraw.h b/source4/libcli/raw/libcliraw.h index dd6904dec2..0032eb4e94 100644 --- a/source4/libcli/raw/libcliraw.h +++ b/source4/libcli/raw/libcliraw.h @@ -94,6 +94,9 @@ struct smbcli_options { uint_t use_oplocks:1; uint_t use_level2_oplocks:1; uint_t use_spnego:1; + uint_t unicode:1; + uint_t ntstatus_support:1; + int max_protocol; uint32_t max_xmit; uint16_t max_mux; int request_timeout; -- cgit From 2c8c9a535500e40084c4810da1890df8d9415659 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 5 Jan 2008 15:36:33 -0600 Subject: r26669: Janitorial: Remove uses of global_loadparm. (This used to be commit 50c46160d997e0448f51ae09e0f3c79e8519fa41) --- source4/libcli/raw/clisocket.c | 2 +- source4/libcli/raw/rawacl.c | 5 ++--- source4/libcli/raw/rawnegotiate.c | 4 ++-- 3 files changed, 5 insertions(+), 6 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 8beaef3daa..8fcb8bb48c 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -83,7 +83,7 @@ struct composite_context *smbcli_sock_connect_send(TALLOC_CTX *mem_ctx, ctx = socket_connect_multi_send(state, host_addr, state->num_ports, state->ports, - lp_resolve_context(global_loadparm), + resolve_ctx, state->ctx->event_ctx); if (ctx == NULL) goto failed; ctx->async.fn = smbcli_sock_connect_recv_conn; diff --git a/source4/libcli/raw/rawacl.c b/source4/libcli/raw/rawacl.c index 9d2068f35f..847d133173 100644 --- a/source4/libcli/raw/rawacl.c +++ b/source4/libcli/raw/rawacl.c @@ -77,8 +77,7 @@ NTSTATUS smb_raw_query_secdesc_recv(struct smbcli_request *req, nt.out.data.length = IVAL(nt.out.params.data, 0); - ndr = ndr_pull_init_blob(&nt.out.data, mem_ctx, - lp_iconv_convenience(global_loadparm)); + ndr = ndr_pull_init_blob(&nt.out.data, mem_ctx, NULL); if (!ndr) { return NT_STATUS_INVALID_PARAMETER; } @@ -136,7 +135,7 @@ struct smbcli_request *smb_raw_set_secdesc_send(struct smbcli_tree *tree, nt.in.params.data = params; nt.in.params.length = 8; - ndr = ndr_push_init_ctx(NULL, lp_iconv_convenience(global_loadparm)); + ndr = ndr_push_init_ctx(NULL, NULL); if (!ndr) return NULL; ndr_err = ndr_push_security_descriptor(ndr, NDR_SCALARS|NDR_BUFFERS, io->set_secdesc.in.sd); diff --git a/source4/libcli/raw/rawnegotiate.c b/source4/libcli/raw/rawnegotiate.c index 78b9082521..fc7725cc55 100644 --- a/source4/libcli/raw/rawnegotiate.c +++ b/source4/libcli/raw/rawnegotiate.c @@ -175,11 +175,11 @@ NTSTATUS smb_raw_negotiate_recv(struct smbcli_request *req) } /* a way to force ascii SMB */ - if (!lp_unicode(global_loadparm)) { + if (!transport->options.unicode) { transport->negotiate.capabilities &= ~CAP_UNICODE; } - if (!lp_nt_status_support(global_loadparm)) { + if (!transport->options.ntstatus_support) { transport->negotiate.capabilities &= ~CAP_STATUS32; } -- cgit From 9d09a06920c2de8c6312f3c0a0280faee65fd432 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 6 Jan 2008 22:01:31 -0600 Subject: r26676: libcli: Fill in lp_workgroup() again, should fix my breakage of cifsdd tests. Thanks to Andrew for catching this. Also fixes a typo in sessetup.c. (This used to be commit b97de4a655b989a481d5d001ce9a5d3969d2909c) --- source4/libcli/raw/clitree.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index ae63d94acd..35f3335322 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -192,6 +192,7 @@ NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx, io.in.service_type = service_type; io.in.credentials = credentials; io.in.fallback_to_anonymous = false; + io.in.workgroup = lp_workgroup(global_loadparm); io.in.options = *options; status = smb_composite_connect(&io, parent_ctx, resolve_ctx, ev); -- cgit From 7b96c53bcbe367963da4f4fa87704e1435c35055 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 12 Feb 2008 16:18:51 +1100 Subject: added some helper functions for GUID handling (This used to be commit 7d3ffd4d2b59d7c87c0a81030f349db21c071967) --- source4/libcli/raw/rawrequest.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index e7dffaf054..3551e5d441 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -972,3 +972,44 @@ size_t smbcli_blob_append_string(struct smbcli_session *session, return len; } + +/* + pull a GUID structure from the wire. The buffer must be at least 16 + bytes long + */ +enum ndr_err_code smbcli_pull_guid(void *base, uint16_t offset, + struct GUID *guid) +{ + DATA_BLOB blob; + TALLOC_CTX *tmp_ctx = talloc_new(NULL); + enum ndr_err_code ndr_err; + + ZERO_STRUCTP(guid); + + blob.data = offset + (uint8_t *)base; + blob.length = 16; + ndr_err = ndr_pull_struct_blob(&blob, tmp_ctx, NULL, guid, + (ndr_pull_flags_fn_t)ndr_pull_GUID); + talloc_free(tmp_ctx); + return ndr_err; +} + +/* + push a guid onto the wire. The buffer must hold 16 bytes + */ +enum ndr_err_code smbcli_push_guid(void *base, uint16_t offset, + const struct GUID *guid) +{ + TALLOC_CTX *tmp_ctx = talloc_new(NULL); + enum ndr_err_code ndr_err; + DATA_BLOB blob; + ndr_err = ndr_push_struct_blob(&blob, tmp_ctx, NULL, + guid, (ndr_push_flags_fn_t)ndr_push_GUID); + if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err) || blob.length != 16) { + talloc_free(tmp_ctx); + return ndr_err; + } + memcpy(offset + (uint8_t *)base, blob.data, blob.length); + talloc_free(tmp_ctx); + return ndr_err; +} -- cgit From 8fdb9504dcfc98080c5c2b5ce134b51ab631fa95 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 12 Feb 2008 16:20:13 +1100 Subject: converted the out side of SMB2 negprot handling This follows the SMB2 PFIF docs. Current versions of Vista can now connect to Samba4 as a SMB2 server and do basic operations (This used to be commit 9dc284770df9393a1a619735dc7a148713936fa7) --- source4/libcli/raw/rawnegotiate.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawnegotiate.c b/source4/libcli/raw/rawnegotiate.c index fc7725cc55..1f5e34779b 100644 --- a/source4/libcli/raw/rawnegotiate.c +++ b/source4/libcli/raw/rawnegotiate.c @@ -40,6 +40,10 @@ static const struct { {PROTOCOL_LANMAN2,"Samba"}, {PROTOCOL_NT1,"NT LANMAN 1.0"}, {PROTOCOL_NT1,"NT LM 0.12"}, +#if 0 + /* we don't yet handle chaining a SMB transport onto SMB2 */ + {PROTOCOL_SMB2,"SMB 2.002"}, +#endif }; /* -- cgit From 416360895f36d41ce8d29c25ef08e2b8b4e38571 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 12 Feb 2008 16:43:38 +1100 Subject: converted SMB2 session setup to use WSPP protocol field names (This used to be commit 3c2af0fdc4916dce32c2690e49dde0852d1a0c50) --- source4/libcli/raw/interfaces.h | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index 00ab788184..4211dadb2d 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -373,29 +373,22 @@ union smb_sesssetup { enum smb_sesssetup_level level; struct { - /* NOTE: this was 0x11 = 0x10 + 1 in vista-CTP - * and changed in vista-beta2, but both server's - * can handle the 0x18 clients - */ - /* static body buffer 24 (0x18) bytes */ - /* uint16_t buffer_code; 0x19 = 0x18 + 1 */ - uint16_t _pad; - uint32_t unknown2; /* 0x0000000F(vista-CTP) 0x00000007(vista-beta2) */ - uint32_t unknown3; /* 0x0000000 */ + /* static body 24 (0x18) bytes */ + uint8_t vc_number; + uint8_t security_mode; + uint32_t capabilities; + uint32_t channel; /* uint16_t secblob_ofs */ /* uint16_t secblob_size */ - uint64_t unknown4; /* 0x0000000000000000 only present in vista-beta2 */ - + uint64_t previous_sessionid; /* dynamic body */ DATA_BLOB secblob; } in; struct { - /* static body buffer 8 (0x08) bytes */ - /* uint16_t buffer_code; 0x09 = 0x08 +1 */ - uint16_t _pad; + /* body buffer 8 (0x08) bytes */ + uint16_t session_flags; /* uint16_t secblob_ofs */ /* uint16_t secblob_size */ - /* dynamic body */ DATA_BLOB secblob; -- cgit From e94d710b0b959d8e69eb02ef0704ebcff56485fb Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 13 Feb 2008 10:13:28 +1100 Subject: updated SMB2 tcon as per WSPP docs (This used to be commit 5913e3e549e71affc66c28cacb6563331fb0c790) --- source4/libcli/raw/interfaces.h | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index 4211dadb2d..ddbddf4c59 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -260,20 +260,19 @@ union smb_tcon { struct { /* static body buffer 8 (0x08) bytes */ - /* uint16_t buffer_code; 0x09 = 0x08 + 1 */ - uint16_t unknown1; /* 0x0000 */ + uint16_t reserved; /* uint16_t path_ofs */ /* uint16_t path_size */ - - /* dynamic body */ + /* dynamic body */ const char *path; /* as non-terminated UTF-16 on the wire */ } in; struct { /* static body buffer 16 (0x10) bytes */ /* uint16_t buffer_code; 0x10 */ - uint16_t unknown1; /* 0x02 */ - uint32_t unknown2; /* 0x00 */ - uint32_t unknown3; /* 0x00 */ + uint8_t share_type; + uint8_t reserved; + uint32_t flags; + uint32_t capabilities; uint32_t access_mask; /* extracted from the SMB2 header */ -- cgit From 88d2e0522737fb8856fb0f52c2af8a2f56130f19 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 13 Feb 2008 15:05:44 +1100 Subject: updated SMB2 create operation to match WSPP. Adding some defined for various new create options (This used to be commit d037dc23ced3df6bce98cbf4810fb5f1247336bd) --- source4/libcli/raw/interfaces.h | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index ddbddf4c59..ce6323f2e5 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -1552,16 +1552,16 @@ union smb_open { enum smb_open_level level; struct { /* static body buffer 56 (0x38) bytes */ - /* uint16_t buffer_code; 0x39 = 0x38 + 1 */ - uint16_t oplock_flags; /* SMB2_CREATE_FLAG_* */ - uint32_t impersonation; - uint32_t unknown3[4]; - uint32_t access_mask; - - uint32_t file_attr; - uint32_t share_access; - uint32_t open_disposition; - uint32_t create_options; + uint8_t security_flags; /* SMB2_SECURITY_* */ + uint8_t oplock_level; /* SMB2_OPLOCK_LEVEL_* */ + uint32_t impersonation_level; /* SMB2_IMPERSONATION_* */ + uint64_t create_flags; + uint64_t reserved; + uint32_t desired_access; + uint32_t file_attributes; + uint32_t share_access; /* NTCREATEX_SHARE_ACCESS_* */ + uint32_t create_disposition; /* NTCREATEX_DISP_* */ + uint32_t create_options; /* NTCREATEX_OPTIONS_* */ /* uint16_t fname_ofs */ /* uint16_t fname_size */ @@ -1579,7 +1579,8 @@ union smb_open { /* static body buffer 88 (0x58) bytes */ /* uint16_t buffer_code; 0x59 = 0x58 + 1 */ - uint16_t oplock_flags; /* SMB2_CREATE_FLAG_* */ + uint8_t oplock_level; + uint8_t reserved; uint32_t create_action; NTTIME create_time; NTTIME access_time; @@ -1588,7 +1589,7 @@ union smb_open { uint64_t alloc_size; uint64_t size; uint32_t file_attr; - uint32_t _pad; + uint32_t reserved2; /* struct smb2_handle handle;*/ /* uint32_t blob_ofs; */ /* uint32_t blob_size; */ -- cgit From e870cfec9f3512b0f1bd3110d7b975652525e28a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 14 Feb 2008 10:12:33 +1100 Subject: Convert SMB and SMB2 code to use a common buffer handling structure This converts our SMB and SMB2 code to use a common structure "struct request_bufinfo" for information on the buffer bounds of a packet, alignment information and string handling. This allows us to use a common backend for SMB and SMB2 code, while still using all the same string and blob handling functions. Up to now we had been passing a NULL req handle into these common routines from the SMB2 side of the server, which meant that we failed any operation which did a bounds checked string extraction (such as a RenameInformation setinfo call, which is what Vista uses for renaming files) There is still some more work to be done on this - for example we can now remove many of the SMB2 specific buffer handling functions that we had, and use the SMB ones. (This used to be commit ca6d9be6cb6a403a81b18fa6e9a6a0518d7f0f68) --- source4/libcli/raw/clisession.c | 20 ++++++++-------- source4/libcli/raw/clitransport.c | 4 +++- source4/libcli/raw/clitree.c | 6 ++--- source4/libcli/raw/libcliraw.h | 4 ++-- source4/libcli/raw/rawfile.c | 4 ++-- source4/libcli/raw/rawioctl.c | 2 +- source4/libcli/raw/rawnegotiate.c | 10 ++++---- source4/libcli/raw/rawreadwrite.c | 6 ++--- source4/libcli/raw/rawrequest.c | 50 +++++++++++++++++++++++++-------------- source4/libcli/raw/rawsearch.c | 2 +- source4/libcli/raw/request.h | 16 ++++++++++++- source4/libcli/raw/smb_signing.c | 6 ++--- 12 files changed, 80 insertions(+), 50 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index 617131c53c..55cb3ef305 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -177,9 +177,9 @@ NTSTATUS smb_raw_sesssetup_recv(struct smbcli_request *req, parms->old.out.action = SVAL(req->in.vwv, VWV(2)); p = req->in.data; if (p) { - p += smbcli_req_pull_string(req, mem_ctx, &parms->old.out.os, p, -1, STR_TERMINATE); - p += smbcli_req_pull_string(req, mem_ctx, &parms->old.out.lanman, p, -1, STR_TERMINATE); - p += smbcli_req_pull_string(req, mem_ctx, &parms->old.out.domain, p, -1, STR_TERMINATE); + p += smbcli_req_pull_string(&req->in.bufinfo, mem_ctx, &parms->old.out.os, p, -1, STR_TERMINATE); + p += smbcli_req_pull_string(&req->in.bufinfo, mem_ctx, &parms->old.out.lanman, p, -1, STR_TERMINATE); + p += smbcli_req_pull_string(&req->in.bufinfo, mem_ctx, &parms->old.out.domain, p, -1, STR_TERMINATE); } break; @@ -190,10 +190,10 @@ NTSTATUS smb_raw_sesssetup_recv(struct smbcli_request *req, parms->nt1.out.action = SVAL(req->in.vwv, VWV(2)); p = req->in.data; if (p) { - p += smbcli_req_pull_string(req, mem_ctx, &parms->nt1.out.os, p, -1, STR_TERMINATE); - p += smbcli_req_pull_string(req, mem_ctx, &parms->nt1.out.lanman, p, -1, STR_TERMINATE); + p += smbcli_req_pull_string(&req->in.bufinfo, mem_ctx, &parms->nt1.out.os, p, -1, STR_TERMINATE); + p += smbcli_req_pull_string(&req->in.bufinfo, mem_ctx, &parms->nt1.out.lanman, p, -1, STR_TERMINATE); if (p < (req->in.data + req->in.data_size)) { - p += smbcli_req_pull_string(req, mem_ctx, &parms->nt1.out.domain, p, -1, STR_TERMINATE); + p += smbcli_req_pull_string(&req->in.bufinfo, mem_ctx, &parms->nt1.out.domain, p, -1, STR_TERMINATE); } } break; @@ -209,11 +209,11 @@ NTSTATUS smb_raw_sesssetup_recv(struct smbcli_request *req, break; } - parms->spnego.out.secblob = smbcli_req_pull_blob(req, mem_ctx, p, len); + parms->spnego.out.secblob = smbcli_req_pull_blob(&req->in.bufinfo, mem_ctx, p, len); p += parms->spnego.out.secblob.length; - p += smbcli_req_pull_string(req, mem_ctx, &parms->spnego.out.os, p, -1, STR_TERMINATE); - p += smbcli_req_pull_string(req, mem_ctx, &parms->spnego.out.lanman, p, -1, STR_TERMINATE); - p += smbcli_req_pull_string(req, mem_ctx, &parms->spnego.out.workgroup, p, -1, STR_TERMINATE); + p += smbcli_req_pull_string(&req->in.bufinfo, mem_ctx, &parms->spnego.out.os, p, -1, STR_TERMINATE); + p += smbcli_req_pull_string(&req->in.bufinfo, mem_ctx, &parms->spnego.out.lanman, p, -1, STR_TERMINATE); + p += smbcli_req_pull_string(&req->in.bufinfo, mem_ctx, &parms->spnego.out.workgroup, p, -1, STR_TERMINATE); break; case RAW_SESSSETUP_SMB2: diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 62c32d3058..288f0612de 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -444,6 +444,8 @@ static NTSTATUS smbcli_transport_finish_recv(void *private, DATA_BLOB blob) req->in.ptr = req->in.data; req->flags2 = SVAL(req->in.hdr, HDR_FLG2); + smb_setup_bufinfo(req); + if (!(req->flags2 & FLAGS2_32_BIT_ERROR_CODES)) { int class = CVAL(req->in.hdr,HDR_RCLS); int code = SVAL(req->in.hdr,HDR_ERR); @@ -637,7 +639,7 @@ NTSTATUS smb_raw_echo_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, p->out.data = talloc_array(mem_ctx, uint8_t, p->out.size); NT_STATUS_HAVE_NO_MEMORY(p->out.data); - if (!smbcli_raw_pull_data(req, req->in.data, p->out.size, p->out.data)) { + if (!smbcli_raw_pull_data(&req->in.bufinfo, req->in.data, p->out.size, p->out.data)) { req->status = NT_STATUS_BUFFER_TOO_SMALL; } diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index 35f3335322..507bde999a 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -123,9 +123,9 @@ NTSTATUS smb_raw_tcon_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, p = req->in.data; if (!p) break; - p += smbcli_req_pull_string(req, mem_ctx, &parms->tconx.out.dev_type, - p, -1, STR_ASCII | STR_TERMINATE); - p += smbcli_req_pull_string(req, mem_ctx, &parms->tconx.out.fs_type, + p += smbcli_req_pull_string(&req->in.bufinfo, mem_ctx, &parms->tconx.out.dev_type, + p, -1, STR_ASCII | STR_TERMINATE); + p += smbcli_req_pull_string(&req->in.bufinfo, mem_ctx, &parms->tconx.out.fs_type, p, -1, STR_TERMINATE); break; diff --git a/source4/libcli/raw/libcliraw.h b/source4/libcli/raw/libcliraw.h index 0032eb4e94..7111649fc1 100644 --- a/source4/libcli/raw/libcliraw.h +++ b/source4/libcli/raw/libcliraw.h @@ -250,8 +250,8 @@ struct smbcli_request { /* the mid of this packet - used to match replies */ uint16_t mid; - struct request_buffer in; - struct request_buffer out; + struct smb_request_buffer in; + struct smb_request_buffer out; /* information on what to do with a reply when it is received asyncronously. If this is not setup when a reply is received then diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c index 3b6ca68526..d9383401b7 100644 --- a/source4/libcli/raw/rawfile.c +++ b/source4/libcli/raw/rawfile.c @@ -616,7 +616,7 @@ NTSTATUS smb_raw_open_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, unio case RAW_OPEN_CTEMP: SMBCLI_CHECK_WCT(req, 1); parms->ctemp.out.file.fnum = SVAL(req->in.vwv, VWV(0)); - smbcli_req_pull_string(req, mem_ctx, &parms->ctemp.out.name, req->in.data, -1, STR_TERMINATE | STR_ASCII); + smbcli_req_pull_string(&req->in.bufinfo, mem_ctx, &parms->ctemp.out.name, req->in.data, -1, STR_TERMINATE | STR_ASCII); break; case RAW_OPEN_SPLOPEN: @@ -675,7 +675,7 @@ NTSTATUS smb_raw_open_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, unio parms->openxreadx.out.nread = SVAL(req->in.vwv, VWV(5)); if (parms->openxreadx.out.nread > MAX(parms->openxreadx.in.mincnt, parms->openxreadx.in.maxcnt) || - !smbcli_raw_pull_data(req, req->in.hdr + SVAL(req->in.vwv, VWV(6)), + !smbcli_raw_pull_data(&req->in.bufinfo, req->in.hdr + SVAL(req->in.vwv, VWV(6)), parms->openxreadx.out.nread, parms->openxreadx.out.data)) { req->status = NT_STATUS_BUFFER_TOO_SMALL; diff --git a/source4/libcli/raw/rawioctl.c b/source4/libcli/raw/rawioctl.c index 9205f84e86..957e554c6b 100644 --- a/source4/libcli/raw/rawioctl.c +++ b/source4/libcli/raw/rawioctl.c @@ -59,7 +59,7 @@ static NTSTATUS smb_raw_smbioctl_recv(struct smbcli_request *req, return smbcli_request_destroy(req); } - parms->ioctl.out.blob = smbcli_req_pull_blob(req, mem_ctx, req->in.data, -1); + parms->ioctl.out.blob = smbcli_req_pull_blob(&req->in.bufinfo, mem_ctx, req->in.data, -1); return smbcli_request_destroy(req); } diff --git a/source4/libcli/raw/rawnegotiate.c b/source4/libcli/raw/rawnegotiate.c index 1f5e34779b..ec2ada53ff 100644 --- a/source4/libcli/raw/rawnegotiate.c +++ b/source4/libcli/raw/rawnegotiate.c @@ -135,14 +135,14 @@ NTSTATUS smb_raw_negotiate_recv(struct smbcli_request *req) if (req->in.data_size < 16) { goto failed; } - transport->negotiate.server_guid = smbcli_req_pull_blob(req, transport, req->in.data, 16); - transport->negotiate.secblob = smbcli_req_pull_blob(req, transport, req->in.data + 16, req->in.data_size - 16); + transport->negotiate.server_guid = smbcli_req_pull_blob(&req->in.bufinfo, transport, req->in.data, 16); + transport->negotiate.secblob = smbcli_req_pull_blob(&req->in.bufinfo, transport, req->in.data + 16, req->in.data_size - 16); } else { if (req->in.data_size < (transport->negotiate.key_len)) { goto failed; } - transport->negotiate.secblob = smbcli_req_pull_blob(req, transport, req->in.data, transport->negotiate.key_len); - smbcli_req_pull_string(req, transport, &transport->negotiate.server_domain, + transport->negotiate.secblob = smbcli_req_pull_blob(&req->in.bufinfo, transport, req->in.data, transport->negotiate.key_len); + smbcli_req_pull_string(&req->in.bufinfo, transport, &transport->negotiate.server_domain, req->in.data+transport->negotiate.key_len, req->in.data_size-transport->negotiate.key_len, STR_UNICODE|STR_NOALIGN); /* here comes the server name */ @@ -168,7 +168,7 @@ NTSTATUS smb_raw_negotiate_recv(struct smbcli_request *req) if ((SVAL(req->in.vwv,VWV(5)) & 0x2)) { transport->negotiate.writebraw_supported = 1; } - transport->negotiate.secblob = smbcli_req_pull_blob(req, transport, + transport->negotiate.secblob = smbcli_req_pull_blob(&req->in.bufinfo, transport, req->in.data, req->in.data_size); } else { /* the old core protocol */ diff --git a/source4/libcli/raw/rawreadwrite.c b/source4/libcli/raw/rawreadwrite.c index b0c49ddab7..2005e36e04 100644 --- a/source4/libcli/raw/rawreadwrite.c +++ b/source4/libcli/raw/rawreadwrite.c @@ -137,7 +137,7 @@ NTSTATUS smb_raw_read_recv(struct smbcli_request *req, union smb_read *parms) SMBCLI_CHECK_WCT(req, 5); parms->lockread.out.nread = SVAL(req->in.vwv, VWV(0)); if (parms->lockread.out.nread > parms->lockread.in.count || - !smbcli_raw_pull_data(req, req->in.data+3, + !smbcli_raw_pull_data(&req->in.bufinfo, req->in.data+3, parms->lockread.out.nread, parms->lockread.out.data)) { req->status = NT_STATUS_BUFFER_TOO_SMALL; } @@ -148,7 +148,7 @@ NTSTATUS smb_raw_read_recv(struct smbcli_request *req, union smb_read *parms) SMBCLI_CHECK_WCT(req, 5); parms->read.out.nread = SVAL(req->in.vwv, VWV(0)); if (parms->read.out.nread > parms->read.in.count || - !smbcli_raw_pull_data(req, req->in.data+3, + !smbcli_raw_pull_data(&req->in.bufinfo, req->in.data+3, parms->read.out.nread, parms->read.out.data)) { req->status = NT_STATUS_BUFFER_TOO_SMALL; } @@ -175,7 +175,7 @@ NTSTATUS smb_raw_read_recv(struct smbcli_request *req, union smb_read *parms) } if (parms->readx.out.nread > MAX(parms->readx.in.mincnt, parms->readx.in.maxcnt) || - !smbcli_raw_pull_data(req, req->in.hdr + SVAL(req->in.vwv, VWV(6)), + !smbcli_raw_pull_data(&req->in.bufinfo, req->in.hdr + SVAL(req->in.vwv, VWV(6)), parms->readx.out.nread, parms->readx.out.data)) { req->status = NT_STATUS_BUFFER_TOO_SMALL; diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 3551e5d441..dd60cc7f62 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -34,6 +34,17 @@ /* assume that a character will not consume more than 3 bytes per char */ #define MAX_BYTES_PER_CHAR 3 +/* setup the bufinfo used for strings and range checking */ +void smb_setup_bufinfo(struct smbcli_request *req) +{ + req->in.bufinfo.mem_ctx = req; + req->in.bufinfo.unicode = (req->flags2 & FLAGS2_UNICODE_STRINGS)?true:false; + req->in.bufinfo.align_base = req->in.buffer; + req->in.bufinfo.data = req->in.data; + req->in.bufinfo.data_size = req->in.data_size; +} + + /* destroy a request structure and return final status */ NTSTATUS smbcli_request_destroy(struct smbcli_request *req) { @@ -298,6 +309,9 @@ NTSTATUS smbcli_chained_advance(struct smbcli_request *req) req->in.data = req->in.vwv + 2 + req->in.wct * 2; req->in.data_size = SVAL(req->in.vwv, VWV(req->in.wct)); + /* fix the bufinfo */ + smb_setup_bufinfo(req); + if (buffer + 3 + req->in.wct*2 + req->in.data_size > req->in.buffer + req->in.size) { return NT_STATUS_BUFFER_TOO_SMALL; @@ -544,13 +558,13 @@ size_t smbcli_req_append_var_block(struct smbcli_request *req, const uint8_t *by on failure zero is returned and *dest is set to NULL, otherwise the number of bytes consumed in the packet is returned */ -static size_t smbcli_req_pull_ucs2(struct smbcli_request *req, TALLOC_CTX *mem_ctx, +static size_t smbcli_req_pull_ucs2(struct request_bufinfo *bufinfo, TALLOC_CTX *mem_ctx, char **dest, const uint8_t *src, int byte_len, uint_t flags) { int src_len, src_len2, alignment=0; ssize_t ret; - if (!(flags & STR_NOALIGN) && ucs2_align(req->in.buffer, src, flags)) { + if (!(flags & STR_NOALIGN) && ucs2_align(bufinfo->align_base, src, flags)) { src++; alignment=1; if (byte_len != -1) { @@ -558,7 +572,7 @@ static size_t smbcli_req_pull_ucs2(struct smbcli_request *req, TALLOC_CTX *mem_c } } - src_len = req->in.data_size - PTR_DIFF(src, req->in.data); + src_len = bufinfo->data_size - PTR_DIFF(src, bufinfo->data); if (src_len < 0) { *dest = NULL; return 0; @@ -597,13 +611,13 @@ static size_t smbcli_req_pull_ucs2(struct smbcli_request *req, TALLOC_CTX *mem_c on failure zero is returned and *dest is set to NULL, otherwise the number of bytes consumed in the packet is returned */ -size_t smbcli_req_pull_ascii(struct smbcli_request *req, TALLOC_CTX *mem_ctx, +size_t smbcli_req_pull_ascii(struct request_bufinfo *bufinfo, TALLOC_CTX *mem_ctx, char **dest, const uint8_t *src, int byte_len, uint_t flags) { int src_len, src_len2; ssize_t ret; - src_len = req->in.data_size - PTR_DIFF(src, req->in.data); + src_len = bufinfo->data_size - PTR_DIFF(src, bufinfo->data); if (src_len < 0) { *dest = NULL; return 0; @@ -640,15 +654,15 @@ size_t smbcli_req_pull_ascii(struct smbcli_request *req, TALLOC_CTX *mem_ctx, on failure zero is returned and *dest is set to NULL, otherwise the number of bytes consumed in the packet is returned */ -size_t smbcli_req_pull_string(struct smbcli_request *req, TALLOC_CTX *mem_ctx, +size_t smbcli_req_pull_string(struct request_bufinfo *bufinfo, TALLOC_CTX *mem_ctx, char **dest, const uint8_t *src, int byte_len, uint_t flags) { if (!(flags & STR_ASCII) && - (((flags & STR_UNICODE) || (req->flags2 & FLAGS2_UNICODE_STRINGS)))) { - return smbcli_req_pull_ucs2(req, mem_ctx, dest, src, byte_len, flags); + (((flags & STR_UNICODE) || bufinfo->unicode))) { + return smbcli_req_pull_ucs2(bufinfo, mem_ctx, dest, src, byte_len, flags); } - return smbcli_req_pull_ascii(req, mem_ctx, dest, src, byte_len, flags); + return smbcli_req_pull_ascii(bufinfo, mem_ctx, dest, src, byte_len, flags); } @@ -658,11 +672,11 @@ size_t smbcli_req_pull_string(struct smbcli_request *req, TALLOC_CTX *mem_ctx, if byte_len is -1 then limit the blob only by packet size */ -DATA_BLOB smbcli_req_pull_blob(struct smbcli_request *req, TALLOC_CTX *mem_ctx, const uint8_t *src, int byte_len) +DATA_BLOB smbcli_req_pull_blob(struct request_bufinfo *bufinfo, TALLOC_CTX *mem_ctx, const uint8_t *src, int byte_len) { int src_len; - src_len = req->in.data_size - PTR_DIFF(src, req->in.data); + src_len = bufinfo->data_size - PTR_DIFF(src, bufinfo->data); if (src_len < 0) { return data_blob(NULL, 0); @@ -677,13 +691,13 @@ DATA_BLOB smbcli_req_pull_blob(struct smbcli_request *req, TALLOC_CTX *mem_ctx, /* check that a lump of data in a request is within the bounds of the data section of the packet */ -static bool smbcli_req_data_oob(struct smbcli_request *req, const uint8_t *ptr, uint32_t count) +static bool smbcli_req_data_oob(struct request_bufinfo *bufinfo, const uint8_t *ptr, uint32_t count) { /* be careful with wraparound! */ - if (ptr < req->in.data || - ptr >= req->in.data + req->in.data_size || - count > req->in.data_size || - ptr + count > req->in.data + req->in.data_size) { + if (ptr < bufinfo->data || + ptr >= bufinfo->data + bufinfo->data_size || + count > bufinfo->data_size || + ptr + count > bufinfo->data + bufinfo->data_size) { return true; } return false; @@ -694,11 +708,11 @@ static bool smbcli_req_data_oob(struct smbcli_request *req, const uint8_t *ptr, return false if any part is outside the data portion of the packet */ -bool smbcli_raw_pull_data(struct smbcli_request *req, const uint8_t *src, int len, uint8_t *dest) +bool smbcli_raw_pull_data(struct request_bufinfo *bufinfo, const uint8_t *src, int len, uint8_t *dest) { if (len == 0) return true; - if (smbcli_req_data_oob(req, src, len)) { + if (smbcli_req_data_oob(bufinfo, src, len)) { return false; } diff --git a/source4/libcli/raw/rawsearch.c b/source4/libcli/raw/rawsearch.c index 33fa90d68d..fb2b09467c 100644 --- a/source4/libcli/raw/rawsearch.c +++ b/source4/libcli/raw/rawsearch.c @@ -54,7 +54,7 @@ static void smb_raw_search_backend(struct smbcli_request *req, search_data.search.write_time = raw_pull_dos_date(req->transport, p + 22); search_data.search.size = IVAL(p, 26); - smbcli_req_pull_ascii(req, mem_ctx, &name, p+30, 13, STR_ASCII); + smbcli_req_pull_ascii(&req->in.bufinfo, mem_ctx, &name, p+30, 13, STR_ASCII); search_data.search.name = name; if (!callback(private, &search_data)) { break; diff --git a/source4/libcli/raw/request.h b/source4/libcli/raw/request.h index 803a450e3c..6776d3c349 100644 --- a/source4/libcli/raw/request.h +++ b/source4/libcli/raw/request.h @@ -22,11 +22,22 @@ #include "libcli/raw/signing.h" +/* + buffer limit structure used by both SMB and SMB2 + */ +struct request_bufinfo { + TALLOC_CTX *mem_ctx; + bool unicode; + const uint8_t *align_base; + const uint8_t *data; + size_t data_size; +}; + /* Shared state structure between client and server, representing the basic packet. */ -struct request_buffer { +struct smb_request_buffer { /* the raw SMB buffer, including the 4 byte length header */ uint8_t *buffer; @@ -56,6 +67,9 @@ struct request_buffer { * a send packet is done we need to move this * pointer */ uint8_t *ptr; + + /* this is used to range check and align strings and buffers */ + struct request_bufinfo bufinfo; }; #endif diff --git a/source4/libcli/raw/smb_signing.c b/source4/libcli/raw/smb_signing.c index 0053710aaf..4acfb9d16d 100644 --- a/source4/libcli/raw/smb_signing.c +++ b/source4/libcli/raw/smb_signing.c @@ -65,7 +65,7 @@ static bool smbcli_set_smb_signing_common(struct smbcli_transport *transport) return true; } -void mark_packet_signed(struct request_buffer *out) +void mark_packet_signed(struct smb_request_buffer *out) { uint16_t flags2; flags2 = SVAL(out->hdr, HDR_FLG2); @@ -101,7 +101,7 @@ bool signing_good(struct smb_signing_context *sign_info, return true; } -void sign_outgoing_message(struct request_buffer *out, DATA_BLOB *mac_key, unsigned int seq_num) +void sign_outgoing_message(struct smb_request_buffer *out, DATA_BLOB *mac_key, unsigned int seq_num) { uint8_t calc_md5_mac[16]; struct MD5Context md5_ctx; @@ -133,7 +133,7 @@ void sign_outgoing_message(struct request_buffer *out, DATA_BLOB *mac_key, unsig Uncomment this to test if the remote server actually verifies signitures...*/ } -bool check_signed_incoming_message(struct request_buffer *in, DATA_BLOB *mac_key, uint_t seq_num) +bool check_signed_incoming_message(struct smb_request_buffer *in, DATA_BLOB *mac_key, uint_t seq_num) { bool good; uint8_t calc_md5_mac[16]; -- cgit From 839ab724dc2d204bfbb0693aeed64f6f83a4266b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 14 Feb 2008 12:30:31 +1100 Subject: Fixed SMB2 rename operations from Vista clients We needed a flag in bufinfo to mark packets as SMB2, as it seems that SMB2 uses a different format for the RenameInformation buffer than SMB does Also handle the fact that SMB2 clients give the full path to the target file in the rename, not a relative path (This used to be commit 52d7972d95ddc19d22a4187b4d4428a6c3ed32d5) --- source4/libcli/raw/interfaces.h | 2 +- source4/libcli/raw/rawrequest.c | 7 +++++-- source4/libcli/raw/request.h | 5 ++++- 3 files changed, 10 insertions(+), 4 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index ce6323f2e5..16db17d7ab 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -1000,7 +1000,7 @@ union smb_setfileinfo { struct { union smb_handle_or_path file; uint8_t overwrite; - uint32_t root_fid; + uint64_t root_fid; const char *new_name; } in; } rename_information; diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index dd60cc7f62..355d092583 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -38,7 +38,10 @@ void smb_setup_bufinfo(struct smbcli_request *req) { req->in.bufinfo.mem_ctx = req; - req->in.bufinfo.unicode = (req->flags2 & FLAGS2_UNICODE_STRINGS)?true:false; + req->in.bufinfo.flags = 0; + if (req->flags2 & FLAGS2_UNICODE_STRINGS) { + req->in.bufinfo.flags = BUFINFO_FLAG_UNICODE; + } req->in.bufinfo.align_base = req->in.buffer; req->in.bufinfo.data = req->in.data; req->in.bufinfo.data_size = req->in.data_size; @@ -658,7 +661,7 @@ size_t smbcli_req_pull_string(struct request_bufinfo *bufinfo, TALLOC_CTX *mem_c char **dest, const uint8_t *src, int byte_len, uint_t flags) { if (!(flags & STR_ASCII) && - (((flags & STR_UNICODE) || bufinfo->unicode))) { + (((flags & STR_UNICODE) || (bufinfo->flags & BUFINFO_FLAG_UNICODE)))) { return smbcli_req_pull_ucs2(bufinfo, mem_ctx, dest, src, byte_len, flags); } diff --git a/source4/libcli/raw/request.h b/source4/libcli/raw/request.h index 6776d3c349..2a572e58ee 100644 --- a/source4/libcli/raw/request.h +++ b/source4/libcli/raw/request.h @@ -22,12 +22,15 @@ #include "libcli/raw/signing.h" +#define BUFINFO_FLAG_UNICODE 0x0001 +#define BUFINFO_FLAG_SMB2 0x0002 + /* buffer limit structure used by both SMB and SMB2 */ struct request_bufinfo { TALLOC_CTX *mem_ctx; - bool unicode; + uint32_t flags; const uint8_t *align_base; const uint8_t *data; size_t data_size; -- cgit From 4a04a5e620a4666fc123d04cb96ef391de72c469 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 14 Feb 2008 14:54:21 +1100 Subject: A better way to handle the different format of RenameInformation in SMB2 We now define a separate info level RAW_SFILEINFO_RENAME_INFORMATION_SMB2 and set that level when handling SMB2 packets. This makes the parsers clearer. (This used to be commit f6cdf3f1177f63d80be757f007eb15380839b4f5) --- source4/libcli/raw/interfaces.h | 5 ++++- source4/libcli/raw/rawsetfileinfo.c | 11 +++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index 16db17d7ab..24e8ad4afc 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -902,7 +902,10 @@ enum smb_setfileinfo_level { RAW_SFILEINFO_1029 = SMB_SFILEINFO_1029, RAW_SFILEINFO_1032 = SMB_SFILEINFO_1032, RAW_SFILEINFO_1039 = SMB_SFILEINFO_1039, - RAW_SFILEINFO_1040 = SMB_SFILEINFO_1040 + RAW_SFILEINFO_1040 = SMB_SFILEINFO_1040, + + /* cope with breakage in SMB2 */ + RAW_SFILEINFO_RENAME_INFORMATION_SMB2 = SMB_SFILEINFO_RENAME_INFORMATION|0x80000000, }; /* union used in setfileinfo() and setpathinfo() calls */ diff --git a/source4/libcli/raw/rawsetfileinfo.c b/source4/libcli/raw/rawsetfileinfo.c index a9a1a3547e..f1e4ee3686 100644 --- a/source4/libcli/raw/rawsetfileinfo.c +++ b/source4/libcli/raw/rawsetfileinfo.c @@ -75,6 +75,16 @@ bool smb_raw_setfileinfo_passthru(TALLOC_CTX *mem_ctx, SIVAL(blob->data, 8, len - 2); return true; + case RAW_SFILEINFO_RENAME_INFORMATION_SMB2: + NEED_BLOB(20); + SIVAL(blob->data, 0, parms->rename_information.in.overwrite); + SBVAL(blob->data, 8, parms->rename_information.in.root_fid); + len = smbcli_blob_append_string(NULL, mem_ctx, blob, + parms->rename_information.in.new_name, + STR_UNICODE|STR_TERMINATE); + SIVAL(blob->data, 16, len - 2); + return true; + case RAW_SFILEINFO_POSITION_INFORMATION: NEED_BLOB(8); SBVAL(blob->data, 0, parms->position_information.in.position); @@ -229,6 +239,7 @@ static bool smb_raw_setinfo_backend(struct smbcli_tree *tree, case RAW_SFILEINFO_UNIX_LINK: case RAW_SFILEINFO_UNIX_HLINK: + case RAW_SFILEINFO_RENAME_INFORMATION_SMB2: break; } -- cgit From afe8e5551e41550f40271f49ab4ded5e5f0def9c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 16 Feb 2008 13:28:37 +1100 Subject: fixed RAW-READ after the bufinfo changes. Thanks to Metze for spotting this. (This used to be commit 3c9973b695a0b5c30d3a5bfabecf62dd1a25ebc1) --- source4/libcli/raw/rawreadwrite.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawreadwrite.c b/source4/libcli/raw/rawreadwrite.c index 2005e36e04..9e4edaf99c 100644 --- a/source4/libcli/raw/rawreadwrite.c +++ b/source4/libcli/raw/rawreadwrite.c @@ -171,6 +171,9 @@ NTSTATUS smb_raw_read_recv(struct smbcli_request *req, union smb_read *parms) parms->readx.out.nread <= req->in.buffer + req->in.size) { req->in.data_size += (SVAL(req->in.vwv, VWV(7)) << 16); + + /* update the bufinfo with the new size */ + smb_setup_bufinfo(req); } } -- cgit From 921b17648456027b6b46a582aa1d13024a5e9a90 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 21 Feb 2008 14:50:57 +0100 Subject: Remove more uses of global_loadparm. (This used to be commit 47d05ecf6fef66c90994f666b8c63e2e7b5a6cd8) --- source4/libcli/raw/clitransport.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 288f0612de..5c14e9f9b8 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -164,14 +164,15 @@ struct smbcli_request *smbcli_transport_connect_send(struct smbcli_transport *tr DATA_BLOB calling_blob, called_blob; TALLOC_CTX *tmp_ctx = talloc_new(transport); NTSTATUS status; + struct smb_iconv_convenience *iconv_convenience = lp_iconv_convenience(global_loadparm); status = nbt_name_dup(transport, called, &transport->called); if (!NT_STATUS_IS_OK(status)) goto failed; - status = nbt_name_to_blob(tmp_ctx, &calling_blob, calling); + status = nbt_name_to_blob(tmp_ctx, iconv_convenience, &calling_blob, calling); if (!NT_STATUS_IS_OK(status)) goto failed; - status = nbt_name_to_blob(tmp_ctx, &called_blob, called); + status = nbt_name_to_blob(tmp_ctx, iconv_convenience, &called_blob, called); if (!NT_STATUS_IS_OK(status)) goto failed; /* allocate output buffer */ -- cgit From 299265d47b5b2faac39fbf908c738f336ea21e67 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 21 Feb 2008 18:09:47 +0100 Subject: Remove yet more global_loadparm instances. (This used to be commit 5de88728ac5c567d3711d1ac6862bbdaced84b75) --- source4/libcli/raw/clisession.c | 3 +++ source4/libcli/raw/libcliraw.h | 5 +++++ 2 files changed, 8 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index 55cb3ef305..74e8d85c8e 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -51,6 +51,9 @@ struct smbcli_session *smbcli_session_init(struct smbcli_transport *transport, } session->pid = (uint16_t)getpid(); session->vuid = UID_FIELD_INVALID; + session->options.lanman_auth = lp_client_lanman_auth(global_loadparm); + session->options.ntlmv2_auth = lp_client_ntlmv2_auth(global_loadparm); + session->options.plaintext_auth = lp_client_plaintext_auth(global_loadparm); capabilities = transport->negotiate.capabilities; diff --git a/source4/libcli/raw/libcliraw.h b/source4/libcli/raw/libcliraw.h index 7111649fc1..0ea8f9dec2 100644 --- a/source4/libcli/raw/libcliraw.h +++ b/source4/libcli/raw/libcliraw.h @@ -186,6 +186,11 @@ struct smbcli_session { /* the spnego context if we use extented security */ struct gensec_security *gensec; + + struct smbcli_session_options { + uint_t lanman_auth; + uint_t ntlmv2_auth; + } options; }; /* -- cgit From 3c20b3eebafe46127a7b69cca573c6a128f8de89 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 21 Feb 2008 18:11:44 +0100 Subject: Fix the build. (This used to be commit f4b31ad76771d674ec85cd155b023eed377e6eb4) --- source4/libcli/raw/clisession.c | 1 + source4/libcli/raw/libcliraw.h | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index 74e8d85c8e..5a33d9cffc 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -22,6 +22,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" #include "system/filesys.h" +#include "param/param.h" #define SETUP_REQUEST_SESSION(cmd, wct, buflen) do { \ req = smbcli_request_setup_session(session, cmd, wct, buflen); \ diff --git a/source4/libcli/raw/libcliraw.h b/source4/libcli/raw/libcliraw.h index 0ea8f9dec2..0578a9eab1 100644 --- a/source4/libcli/raw/libcliraw.h +++ b/source4/libcli/raw/libcliraw.h @@ -188,8 +188,9 @@ struct smbcli_session { struct gensec_security *gensec; struct smbcli_session_options { - uint_t lanman_auth; - uint_t ntlmv2_auth; + uint_t lanman_auth:1; + uint_t ntlmv2_auth:1; + uint_t plaintext_auth:1; } options; }; -- cgit From 3101cb888d5cbad785050b8491b138d683d444fb Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 25 Feb 2008 12:51:55 +0100 Subject: Remove uses of global_loadparm. (This used to be commit a16c9a2129ce92e7e1a613b2badd168e42ead436) --- source4/libcli/raw/clisocket.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 8fcb8bb48c..eaa02e1047 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -33,6 +33,7 @@ struct sock_connect_state { const char *host_name; int num_ports; uint16_t *ports; + const char *socket_options; struct smbcli_socket *result; }; @@ -80,6 +81,7 @@ struct composite_context *smbcli_sock_connect_send(TALLOC_CTX *mem_ctx, for (i=0;ports[i];i++) { state->ports[i] = atoi(ports[i]); } + state->socket_options = lp_socket_options(global_loadparm); ctx = socket_connect_multi_send(state, host_addr, state->num_ports, state->ports, @@ -108,7 +110,7 @@ static void smbcli_sock_connect_recv_conn(struct composite_context *ctx) if (!composite_is_ok(state->ctx)) return; state->ctx->status = - socket_set_option(sock, lp_socket_options(global_loadparm), NULL); + socket_set_option(sock, state->socket_options, NULL); if (!composite_is_ok(state->ctx)) return; -- cgit From 3cbe47b2aef427f7f1fe8f4aa2496fbbe31a3ade Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 6 Mar 2008 15:11:16 +0100 Subject: libcli/raw: make it possible to not send CAP_LEVEL_II_OPLOCKS But the keep the default to always send it when the server supports it too. metze (This used to be commit 33caaef2e46557525a8ffb79d6dd0db46a079529) --- source4/libcli/raw/rawnegotiate.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawnegotiate.c b/source4/libcli/raw/rawnegotiate.c index ec2ada53ff..6c16935f21 100644 --- a/source4/libcli/raw/rawnegotiate.c +++ b/source4/libcli/raw/rawnegotiate.c @@ -187,6 +187,10 @@ NTSTATUS smb_raw_negotiate_recv(struct smbcli_request *req) transport->negotiate.capabilities &= ~CAP_STATUS32; } + if (!transport->options.use_level2_oplocks) { + transport->negotiate.capabilities &= ~CAP_LEVEL_II_OPLOCKS; + } + failed: return smbcli_request_destroy(req); } -- cgit From 6743de076db8f8ddadb59b13f2ceaabb17f385d0 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 11 Mar 2008 19:11:57 +0100 Subject: libcli/raw: add RAW_RENAME_NTTRANS support metze Signed-off-by: Stefan Metzmacher (This used to be commit bfe773a620640fa46efe008f38144f5452350825) --- source4/libcli/raw/interfaces.h | 13 ++++++++++++- source4/libcli/raw/rawfile.c | 26 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index 24e8ad4afc..3965c58204 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -175,7 +175,7 @@ struct smb_rmdir { }; /* struct used in rename() call */ -enum smb_rename_level {RAW_RENAME_RENAME, RAW_RENAME_NTRENAME}; +enum smb_rename_level {RAW_RENAME_RENAME, RAW_RENAME_NTRENAME, RAW_RENAME_NTTRANS}; union smb_rename { struct { @@ -206,6 +206,17 @@ union smb_rename { const char *new_name; } in; } ntrename; + + /* NT TRANS rename interface */ + struct { + enum smb_rename_level level; + + struct { + union smb_handle file; + uint16_t flags;/* see RENAME_REPLACE_IF_EXISTS */ + const char *new_name; + } in; + } nttrans; }; enum smb_tcon_level { diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c index d9383401b7..725034c3a9 100644 --- a/source4/libcli/raw/rawfile.c +++ b/source4/libcli/raw/rawfile.c @@ -36,6 +36,8 @@ struct smbcli_request *smb_raw_rename_send(struct smbcli_tree *tree, union smb_rename *parms) { struct smbcli_request *req = NULL; + struct smb_nttrans nt; + TALLOC_CTX *mem_ctx; switch (parms->generic.level) { case RAW_RENAME_RENAME: @@ -53,6 +55,30 @@ struct smbcli_request *smb_raw_rename_send(struct smbcli_tree *tree, smbcli_req_append_ascii4(req, parms->ntrename.in.old_name, STR_TERMINATE); smbcli_req_append_ascii4(req, parms->ntrename.in.new_name, STR_TERMINATE); break; + + case RAW_RENAME_NTTRANS: + + mem_ctx = talloc_new(tree); + + nt.in.max_setup = 0; + nt.in.max_param = 0; + nt.in.max_data = 0; + nt.in.setup_count = 0; + nt.in.setup = NULL; + nt.in.function = NT_TRANSACT_RENAME; + nt.in.params = data_blob_talloc(mem_ctx, NULL, 4); + nt.in.data = data_blob(NULL, 0); + + SSVAL(nt.in.params.data, VWV(0), parms->nttrans.in.file.fnum); + SSVAL(nt.in.params.data, VWV(1), parms->nttrans.in.flags); + + smbcli_blob_append_string(tree->session, mem_ctx, + &nt.in.params, parms->nttrans.in.new_name, + STR_TERMINATE); + + req = smb_raw_nttrans_send(tree, &nt); + talloc_free(mem_ctx); + return req; } if (!smbcli_request_send(req)) { -- cgit From afe3e8172ddaa5e4aa811faceecda4f943d6e2ef Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 2 Apr 2008 04:53:27 +0200 Subject: Install public header files again and include required prototypes. (This used to be commit 47ffbbf67435904754469544390b67d34c958343) --- source4/libcli/raw/clierror.c | 4 +- source4/libcli/raw/clioplock.c | 1 + source4/libcli/raw/clisession.c | 3 +- source4/libcli/raw/clisocket.c | 4 +- source4/libcli/raw/clitransport.c | 8 ++-- source4/libcli/raw/clitree.c | 7 ++-- source4/libcli/raw/libcliraw.h | 76 ++++++++++++++++++++++++++++++++++++- source4/libcli/raw/rawacl.c | 1 + source4/libcli/raw/rawfile.c | 25 ++++++------ source4/libcli/raw/rawfileinfo.c | 9 +++-- source4/libcli/raw/rawfsinfo.c | 3 +- source4/libcli/raw/rawioctl.c | 3 +- source4/libcli/raw/rawnegotiate.c | 1 + source4/libcli/raw/rawnotify.c | 5 ++- source4/libcli/raw/rawreadwrite.c | 11 +++--- source4/libcli/raw/rawrequest.c | 7 +++- source4/libcli/raw/rawsearch.c | 3 +- source4/libcli/raw/rawsetfileinfo.c | 7 ++-- source4/libcli/raw/rawshadow.c | 1 + source4/libcli/raw/rawtrans.c | 9 +++-- source4/libcli/raw/smb_signing.c | 1 + 21 files changed, 142 insertions(+), 47 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clierror.c b/source4/libcli/raw/clierror.c index c515259ee7..157bd847d4 100644 --- a/source4/libcli/raw/clierror.c +++ b/source4/libcli/raw/clierror.c @@ -25,7 +25,7 @@ /*************************************************************************** Return an error message from the last response ****************************************************************************/ -const char *smbcli_errstr(struct smbcli_tree *tree) +_PUBLIC_ const char *smbcli_errstr(struct smbcli_tree *tree) { switch (tree->session->transport->error.etype) { case ETYPE_SMB: @@ -45,7 +45,7 @@ const char *smbcli_errstr(struct smbcli_tree *tree) /* Return the 32-bit NT status code from the last packet */ -NTSTATUS smbcli_nt_error(struct smbcli_tree *tree) +_PUBLIC_ NTSTATUS smbcli_nt_error(struct smbcli_tree *tree) { switch (tree->session->transport->error.etype) { case ETYPE_SMB: diff --git a/source4/libcli/raw/clioplock.c b/source4/libcli/raw/clioplock.c index ae4e58ae01..47ffb6dd31 100644 --- a/source4/libcli/raw/clioplock.c +++ b/source4/libcli/raw/clioplock.c @@ -19,6 +19,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" +#include "libcli/raw/raw_proto.h" /**************************************************************************** send an ack for an oplock break request diff --git a/source4/libcli/raw/clisession.c b/source4/libcli/raw/clisession.c index 5a33d9cffc..ad4ca7b471 100644 --- a/source4/libcli/raw/clisession.c +++ b/source4/libcli/raw/clisession.c @@ -21,6 +21,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" +#include "libcli/raw/raw_proto.h" #include "system/filesys.h" #include "param/param.h" @@ -291,7 +292,7 @@ struct smbcli_request *smb_raw_exit_send(struct smbcli_session *session) /**************************************************************************** Send a exit (sync interface) *****************************************************************************/ -NTSTATUS smb_raw_exit(struct smbcli_session *session) +_PUBLIC_ NTSTATUS smb_raw_exit(struct smbcli_session *session) { struct smbcli_request *req = smb_raw_exit_send(session); return smbcli_request_simple_recv(req); diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index eaa02e1047..1dcf2d1c53 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -170,7 +170,7 @@ NTSTATUS smbcli_sock_connect(TALLOC_CTX *mem_ctx, /**************************************************************************** mark the socket as dead ****************************************************************************/ -void smbcli_sock_dead(struct smbcli_socket *sock) +_PUBLIC_ void smbcli_sock_dead(struct smbcli_socket *sock) { talloc_free(sock->event.fde); sock->event.fde = NULL; @@ -189,7 +189,7 @@ void smbcli_sock_set_options(struct smbcli_socket *sock, const char *options) /**************************************************************************** resolve a hostname and connect ****************************************************************************/ -struct smbcli_socket *smbcli_sock_connect_byname(const char *host, const char **ports, +_PUBLIC_ struct smbcli_socket *smbcli_sock_connect_byname(const char *host, const char **ports, TALLOC_CTX *mem_ctx, struct resolve_context *resolve_ctx, struct event_context *event_ctx) diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 5c14e9f9b8..34fb96230d 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -21,12 +21,14 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" +#include "libcli/raw/raw_proto.h" #include "lib/socket/socket.h" #include "lib/util/dlinklist.h" #include "lib/events/events.h" #include "lib/stream/packet.h" #include "librpc/gen_ndr/ndr_nbt.h" #include "param/param.h" +#include "libcli/nbt/libnbt.h" /* @@ -322,7 +324,7 @@ static void idle_handler(struct event_context *ev, setup the idle handler for a transport the period is in microseconds */ -void smbcli_transport_idle_handler(struct smbcli_transport *transport, +_PUBLIC_ void smbcli_transport_idle_handler(struct smbcli_transport *transport, void (*idle_func)(struct smbcli_transport *, void *), uint64_t period, void *private) @@ -502,7 +504,7 @@ error: process some read/write requests that are pending return false if the socket is dead */ -bool smbcli_transport_process(struct smbcli_transport *transport) +_PUBLIC_ bool smbcli_transport_process(struct smbcli_transport *transport) { NTSTATUS status; size_t npending; @@ -599,7 +601,7 @@ void smbcli_transport_send(struct smbcli_request *req) /**************************************************************************** Send an SMBecho (async send) *****************************************************************************/ -struct smbcli_request *smb_raw_echo_send(struct smbcli_transport *transport, +_PUBLIC_ struct smbcli_request *smb_raw_echo_send(struct smbcli_transport *transport, struct smb_echo *p) { struct smbcli_request *req; diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index 507bde999a..d5075f9271 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -22,6 +22,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" +#include "libcli/raw/raw_proto.h" #include "libcli/smb_composite/smb_composite.h" #include "param/param.h" @@ -33,7 +34,7 @@ /**************************************************************************** Initialize the tree context ****************************************************************************/ -struct smbcli_tree *smbcli_tree_init(struct smbcli_session *session, +_PUBLIC_ struct smbcli_tree *smbcli_tree_init(struct smbcli_session *session, TALLOC_CTX *parent_ctx, bool primary) { struct smbcli_tree *tree; @@ -141,7 +142,7 @@ failed: /**************************************************************************** Send a tconX (sync interface) ****************************************************************************/ -NTSTATUS smb_raw_tcon(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, +_PUBLIC_ NTSTATUS smb_raw_tcon(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_tcon *parms) { struct smbcli_request *req = smb_raw_tcon_send(tree, parms); @@ -152,7 +153,7 @@ NTSTATUS smb_raw_tcon(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, /**************************************************************************** Send a tree disconnect. ****************************************************************************/ -NTSTATUS smb_tree_disconnect(struct smbcli_tree *tree) +_PUBLIC_ NTSTATUS smb_tree_disconnect(struct smbcli_tree *tree) { struct smbcli_request *req; diff --git a/source4/libcli/raw/libcliraw.h b/source4/libcli/raw/libcliraw.h index 0578a9eab1..16a98ad66e 100644 --- a/source4/libcli/raw/libcliraw.h +++ b/source4/libcli/raw/libcliraw.h @@ -286,6 +286,80 @@ struct smbcli_request { } #include "libcli/raw/interfaces.h" -#include "libcli/raw/raw_proto.h" + +NTSTATUS smb_raw_read_recv(struct smbcli_request *req, union smb_read *parms); +struct smbcli_request *smb_raw_read_send(struct smbcli_tree *tree, union smb_read *parms); +NTSTATUS smb_raw_trans_recv(struct smbcli_request *req, + TALLOC_CTX *mem_ctx, + struct smb_trans2 *parms); +size_t smb_raw_max_trans_data(struct smbcli_tree *tree, size_t param_size); +struct smbcli_request *smb_raw_trans_send(struct smbcli_tree *tree, struct smb_trans2 *parms); +NTSTATUS smbcli_request_destroy(struct smbcli_request *req); +struct smbcli_request *smb_raw_write_send(struct smbcli_tree *tree, union smb_write *parms); +struct smbcli_request *smb_raw_close_send(struct smbcli_tree *tree, union smb_close *parms); +NTSTATUS smb_raw_open_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, union smb_open *parms); +struct smbcli_request *smb_raw_open_send(struct smbcli_tree *tree, union smb_open *parms); + +bool smbcli_transport_process(struct smbcli_transport *transport); +const char *smbcli_errstr(struct smbcli_tree *tree); +NTSTATUS smb_raw_fsinfo(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_fsinfo *fsinfo); +NTSTATUS smb_raw_pathinfo(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_fileinfo *parms); +NTSTATUS smb_raw_shadow_data(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, struct smb_shadow_copy *info); +NTSTATUS smb_raw_fileinfo(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_fileinfo *parms); +struct smbcli_tree *smbcli_tree_init(struct smbcli_session *session, TALLOC_CTX *parent_ctx, bool primary); +NTSTATUS smb_raw_tcon(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_tcon *parms); +void smbcli_oplock_handler(struct smbcli_transport *transport, + bool (*handler)(struct smbcli_transport *, uint16_t, uint16_t, uint8_t, void *), + void *private); +void smbcli_transport_idle_handler(struct smbcli_transport *transport, + void (*idle_func)(struct smbcli_transport *, void *), + uint64_t period, + void *private); +NTSTATUS smbcli_request_simple_recv(struct smbcli_request *req); +bool smbcli_oplock_ack(struct smbcli_tree *tree, uint16_t fnum, uint16_t ack_level); +NTSTATUS smb_raw_open(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_open *parms); +NTSTATUS smb_raw_close(struct smbcli_tree *tree, union smb_close *parms); +NTSTATUS smb_raw_unlink(struct smbcli_tree *tree, union smb_unlink *parms); +NTSTATUS smb_raw_chkpath(struct smbcli_tree *tree, union smb_chkpath *parms); +NTSTATUS smb_raw_mkdir(struct smbcli_tree *tree, union smb_mkdir *parms); +NTSTATUS smb_raw_rmdir(struct smbcli_tree *tree, struct smb_rmdir *parms); +NTSTATUS smb_raw_rename(struct smbcli_tree *tree, union smb_rename *parms); +NTSTATUS smb_raw_seek(struct smbcli_tree *tree, union smb_seek *parms); +NTSTATUS smb_raw_read(struct smbcli_tree *tree, union smb_read *parms); +NTSTATUS smb_raw_write(struct smbcli_tree *tree, union smb_write *parms); +NTSTATUS smb_raw_lock(struct smbcli_tree *tree, union smb_lock *parms); +NTSTATUS smb_raw_setpathinfo(struct smbcli_tree *tree, union smb_setfileinfo *parms); +NTSTATUS smb_raw_setfileinfo(struct smbcli_tree *tree, union smb_setfileinfo *parms); + +struct smbcli_request *smb_raw_changenotify_send(struct smbcli_tree *tree, union smb_notify *parms); +NTSTATUS smb_raw_changenotify_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, union smb_notify *parms); + +NTSTATUS smb_tree_disconnect(struct smbcli_tree *tree); +NTSTATUS smbcli_nt_error(struct smbcli_tree *tree); +NTSTATUS smb_raw_exit(struct smbcli_session *session); +NTSTATUS smb_raw_pathinfo_recv(struct smbcli_request *req, + TALLOC_CTX *mem_ctx, + union smb_fileinfo *parms); +struct smbcli_request *smb_raw_pathinfo_send(struct smbcli_tree *tree, + union smb_fileinfo *parms); +struct smbcli_request *smb_raw_setpathinfo_send(struct smbcli_tree *tree, + union smb_setfileinfo *parms); +struct smbcli_request *smb_raw_echo_send(struct smbcli_transport *transport, + struct smb_echo *p); +NTSTATUS smb_raw_search_first(struct smbcli_tree *tree, + TALLOC_CTX *mem_ctx, + union smb_search_first *io, void *private, + smbcli_search_callback callback); +NTSTATUS smb_raw_flush(struct smbcli_tree *tree, union smb_flush *parms); + +NTSTATUS smb_raw_trans(struct smbcli_tree *tree, + TALLOC_CTX *mem_ctx, + struct smb_trans2 *parms); + +struct smbcli_socket *smbcli_sock_connect_byname(const char *host, const char **ports, + TALLOC_CTX *mem_ctx, + struct resolve_context *resolve_ctx, + struct event_context *event_ctx); +void smbcli_sock_dead(struct smbcli_socket *sock); #endif /* __LIBCLI_RAW__H__ */ diff --git a/source4/libcli/raw/rawacl.c b/source4/libcli/raw/rawacl.c index 847d133173..466b94f4a9 100644 --- a/source4/libcli/raw/rawacl.c +++ b/source4/libcli/raw/rawacl.c @@ -20,6 +20,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" +#include "libcli/raw/raw_proto.h" #include "librpc/gen_ndr/ndr_security.h" #include "param/param.h" diff --git a/source4/libcli/raw/rawfile.c b/source4/libcli/raw/rawfile.c index 725034c3a9..3c5c1b742b 100644 --- a/source4/libcli/raw/rawfile.c +++ b/source4/libcli/raw/rawfile.c @@ -22,6 +22,7 @@ #include "includes.h" #include "smb.h" #include "libcli/raw/libcliraw.h" +#include "libcli/raw/raw_proto.h" #include "librpc/gen_ndr/ndr_security.h" #define SETUP_REQUEST(cmd, wct, buflen) do { \ @@ -92,7 +93,7 @@ struct smbcli_request *smb_raw_rename_send(struct smbcli_tree *tree, /**************************************************************************** Rename a file - sync interface ****************************************************************************/ -NTSTATUS smb_raw_rename(struct smbcli_tree *tree, +_PUBLIC_ NTSTATUS smb_raw_rename(struct smbcli_tree *tree, union smb_rename *parms) { struct smbcli_request *req = smb_raw_rename_send(tree, parms); @@ -123,7 +124,7 @@ struct smbcli_request *smb_raw_unlink_send(struct smbcli_tree *tree, /* delete a file - sync interface */ -NTSTATUS smb_raw_unlink(struct smbcli_tree *tree, +_PUBLIC_ NTSTATUS smb_raw_unlink(struct smbcli_tree *tree, union smb_unlink *parms) { struct smbcli_request *req = smb_raw_unlink_send(tree, parms); @@ -201,7 +202,7 @@ struct smbcli_request *smb_raw_mkdir_send(struct smbcli_tree *tree, /**************************************************************************** Create a directory - sync interface ****************************************************************************/ -NTSTATUS smb_raw_mkdir(struct smbcli_tree *tree, +_PUBLIC_ NTSTATUS smb_raw_mkdir(struct smbcli_tree *tree, union smb_mkdir *parms) { struct smbcli_request *req = smb_raw_mkdir_send(tree, parms); @@ -231,7 +232,7 @@ struct smbcli_request *smb_raw_rmdir_send(struct smbcli_tree *tree, /**************************************************************************** Remove a directory - sync interface ****************************************************************************/ -NTSTATUS smb_raw_rmdir(struct smbcli_tree *tree, +_PUBLIC_ NTSTATUS smb_raw_rmdir(struct smbcli_tree *tree, struct smb_rmdir *parms) { struct smbcli_request *req = smb_raw_rmdir_send(tree, parms); @@ -448,7 +449,7 @@ static NTSTATUS smb_raw_t2open_recv(struct smbcli_request *req, TALLOC_CTX *mem_ /**************************************************************************** Open a file - async send ****************************************************************************/ -struct smbcli_request *smb_raw_open_send(struct smbcli_tree *tree, union smb_open *parms) +_PUBLIC_ struct smbcli_request *smb_raw_open_send(struct smbcli_tree *tree, union smb_open *parms) { int len; struct smbcli_request *req = NULL; @@ -585,7 +586,7 @@ struct smbcli_request *smb_raw_open_send(struct smbcli_tree *tree, union smb_ope /**************************************************************************** Open a file - async recv ****************************************************************************/ -NTSTATUS smb_raw_open_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, union smb_open *parms) +_PUBLIC_ NTSTATUS smb_raw_open_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, union smb_open *parms) { NTSTATUS status; @@ -720,7 +721,7 @@ failed: /**************************************************************************** Open a file - sync interface ****************************************************************************/ -NTSTATUS smb_raw_open(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_open *parms) +_PUBLIC_ NTSTATUS smb_raw_open(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_open *parms) { struct smbcli_request *req = smb_raw_open_send(tree, parms); return smb_raw_open_recv(req, mem_ctx, parms); @@ -730,7 +731,7 @@ NTSTATUS smb_raw_open(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_o /**************************************************************************** Close a file - async send ****************************************************************************/ -struct smbcli_request *smb_raw_close_send(struct smbcli_tree *tree, union smb_close *parms) +_PUBLIC_ struct smbcli_request *smb_raw_close_send(struct smbcli_tree *tree, union smb_close *parms) { struct smbcli_request *req = NULL; @@ -766,7 +767,7 @@ struct smbcli_request *smb_raw_close_send(struct smbcli_tree *tree, union smb_cl /**************************************************************************** Close a file - sync interface ****************************************************************************/ -NTSTATUS smb_raw_close(struct smbcli_tree *tree, union smb_close *parms) +_PUBLIC_ NTSTATUS smb_raw_close(struct smbcli_tree *tree, union smb_close *parms) { struct smbcli_request *req = smb_raw_close_send(tree, parms); return smbcli_request_simple_recv(req); @@ -843,7 +844,7 @@ struct smbcli_request *smb_raw_lock_send(struct smbcli_tree *tree, union smb_loc /**************************************************************************** Locking calls - sync interface ****************************************************************************/ -NTSTATUS smb_raw_lock(struct smbcli_tree *tree, union smb_lock *parms) +_PUBLIC_ NTSTATUS smb_raw_lock(struct smbcli_tree *tree, union smb_lock *parms) { struct smbcli_request *req = smb_raw_lock_send(tree, parms); return smbcli_request_simple_recv(req); @@ -913,7 +914,7 @@ struct smbcli_request *smb_raw_flush_send(struct smbcli_tree *tree, union smb_fl /**************************************************************************** flush a file - sync interface ****************************************************************************/ -NTSTATUS smb_raw_flush(struct smbcli_tree *tree, union smb_flush *parms) +_PUBLIC_ NTSTATUS smb_raw_flush(struct smbcli_tree *tree, union smb_flush *parms) { struct smbcli_request *req = smb_raw_flush_send(tree, parms); return smbcli_request_simple_recv(req); @@ -962,7 +963,7 @@ failed: /* seek a file - sync interface */ -NTSTATUS smb_raw_seek(struct smbcli_tree *tree, +_PUBLIC_ NTSTATUS smb_raw_seek(struct smbcli_tree *tree, union smb_seek *parms) { struct smbcli_request *req = smb_raw_seek_send(tree, parms); diff --git a/source4/libcli/raw/rawfileinfo.c b/source4/libcli/raw/rawfileinfo.c index ed5475e926..71900be49c 100644 --- a/source4/libcli/raw/rawfileinfo.c +++ b/source4/libcli/raw/rawfileinfo.c @@ -21,6 +21,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" +#include "libcli/raw/raw_proto.h" #include "librpc/gen_ndr/ndr_security.h" #include "param/param.h" @@ -711,7 +712,7 @@ NTSTATUS smb_raw_fileinfo_recv(struct smbcli_request *req, /**************************************************************************** Query file info (sync interface) ****************************************************************************/ -NTSTATUS smb_raw_fileinfo(struct smbcli_tree *tree, +_PUBLIC_ NTSTATUS smb_raw_fileinfo(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_fileinfo *parms) { @@ -722,7 +723,7 @@ NTSTATUS smb_raw_fileinfo(struct smbcli_tree *tree, /**************************************************************************** Query path info (async send) ****************************************************************************/ -struct smbcli_request *smb_raw_pathinfo_send(struct smbcli_tree *tree, +_PUBLIC_ struct smbcli_request *smb_raw_pathinfo_send(struct smbcli_tree *tree, union smb_fileinfo *parms) { DATA_BLOB data; @@ -756,7 +757,7 @@ struct smbcli_request *smb_raw_pathinfo_send(struct smbcli_tree *tree, /**************************************************************************** Query path info (async recv) ****************************************************************************/ -NTSTATUS smb_raw_pathinfo_recv(struct smbcli_request *req, +_PUBLIC_ NTSTATUS smb_raw_pathinfo_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, union smb_fileinfo *parms) { @@ -767,7 +768,7 @@ NTSTATUS smb_raw_pathinfo_recv(struct smbcli_request *req, /**************************************************************************** Query path info (sync interface) ****************************************************************************/ -NTSTATUS smb_raw_pathinfo(struct smbcli_tree *tree, +_PUBLIC_ NTSTATUS smb_raw_pathinfo(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_fileinfo *parms) { diff --git a/source4/libcli/raw/rawfsinfo.c b/source4/libcli/raw/rawfsinfo.c index bfb5db828e..43a0919e38 100644 --- a/source4/libcli/raw/rawfsinfo.c +++ b/source4/libcli/raw/rawfsinfo.c @@ -21,6 +21,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" +#include "libcli/raw/raw_proto.h" #include "librpc/gen_ndr/ndr_misc.h" /**************************************************************************** @@ -326,7 +327,7 @@ failed: /**************************************************************************** Query FSInfo raw interface (sync interface) ****************************************************************************/ -NTSTATUS smb_raw_fsinfo(struct smbcli_tree *tree, +_PUBLIC_ NTSTATUS smb_raw_fsinfo(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_fsinfo *fsinfo) { diff --git a/source4/libcli/raw/rawioctl.c b/source4/libcli/raw/rawioctl.c index 957e554c6b..77c7b03f15 100644 --- a/source4/libcli/raw/rawioctl.c +++ b/source4/libcli/raw/rawioctl.c @@ -20,6 +20,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" +#include "libcli/raw/raw_proto.h" #define SETUP_REQUEST(cmd, wct, buflen) do { \ req = smbcli_request_setup(tree, cmd, wct, buflen); \ @@ -163,7 +164,7 @@ NTSTATUS smb_raw_ioctl_recv(struct smbcli_request *req, /* send a raw ioctl - sync interface */ -_PUBLIC_ NTSTATUS smb_raw_ioctl(struct smbcli_tree *tree, +NTSTATUS smb_raw_ioctl(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_ioctl *parms) { struct smbcli_request *req; diff --git a/source4/libcli/raw/rawnegotiate.c b/source4/libcli/raw/rawnegotiate.c index 6c16935f21..f0de4b48bd 100644 --- a/source4/libcli/raw/rawnegotiate.c +++ b/source4/libcli/raw/rawnegotiate.c @@ -22,6 +22,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" +#include "libcli/raw/raw_proto.h" #include "system/time.h" #include "param/param.h" diff --git a/source4/libcli/raw/rawnotify.c b/source4/libcli/raw/rawnotify.c index 91a12a8618..bf7578d7fc 100644 --- a/source4/libcli/raw/rawnotify.c +++ b/source4/libcli/raw/rawnotify.c @@ -19,12 +19,13 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" +#include "libcli/raw/raw_proto.h" #include "lib/util/dlinklist.h" /**************************************************************************** change notify (async send) ****************************************************************************/ -struct smbcli_request *smb_raw_changenotify_send(struct smbcli_tree *tree, union smb_notify *parms) +_PUBLIC_ struct smbcli_request *smb_raw_changenotify_send(struct smbcli_tree *tree, union smb_notify *parms) { struct smb_nttrans nt; uint8_t setup[8]; @@ -51,7 +52,7 @@ struct smbcli_request *smb_raw_changenotify_send(struct smbcli_tree *tree, union /**************************************************************************** change notify (async recv) ****************************************************************************/ -NTSTATUS smb_raw_changenotify_recv(struct smbcli_request *req, +_PUBLIC_ NTSTATUS smb_raw_changenotify_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, union smb_notify *parms) { struct smb_nttrans nt; diff --git a/source4/libcli/raw/rawreadwrite.c b/source4/libcli/raw/rawreadwrite.c index 9e4edaf99c..a8c7996310 100644 --- a/source4/libcli/raw/rawreadwrite.c +++ b/source4/libcli/raw/rawreadwrite.c @@ -20,6 +20,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" +#include "libcli/raw/raw_proto.h" #define SETUP_REQUEST(cmd, wct, buflen) do { \ req = smbcli_request_setup(tree, cmd, wct, buflen); \ @@ -29,7 +30,7 @@ /**************************************************************************** low level read operation (async send) ****************************************************************************/ -struct smbcli_request *smb_raw_read_send(struct smbcli_tree *tree, union smb_read *parms) +_PUBLIC_ struct smbcli_request *smb_raw_read_send(struct smbcli_tree *tree, union smb_read *parms) { bool bigoffset = false; struct smbcli_request *req = NULL; @@ -115,7 +116,7 @@ struct smbcli_request *smb_raw_read_send(struct smbcli_tree *tree, union smb_rea /**************************************************************************** low level read operation (async recv) ****************************************************************************/ -NTSTATUS smb_raw_read_recv(struct smbcli_request *req, union smb_read *parms) +_PUBLIC_ NTSTATUS smb_raw_read_recv(struct smbcli_request *req, union smb_read *parms) { if (!smbcli_request_receive(req) || smbcli_request_is_error(req)) { @@ -197,7 +198,7 @@ failed: /**************************************************************************** low level read operation (sync interface) ****************************************************************************/ -NTSTATUS smb_raw_read(struct smbcli_tree *tree, union smb_read *parms) +_PUBLIC_ NTSTATUS smb_raw_read(struct smbcli_tree *tree, union smb_read *parms) { struct smbcli_request *req = smb_raw_read_send(tree, parms); return smb_raw_read_recv(req, parms); @@ -207,7 +208,7 @@ NTSTATUS smb_raw_read(struct smbcli_tree *tree, union smb_read *parms) /**************************************************************************** raw write interface (async send) ****************************************************************************/ -struct smbcli_request *smb_raw_write_send(struct smbcli_tree *tree, union smb_write *parms) +_PUBLIC_ struct smbcli_request *smb_raw_write_send(struct smbcli_tree *tree, union smb_write *parms) { bool bigoffset = false; struct smbcli_request *req = NULL; @@ -341,7 +342,7 @@ failed: /**************************************************************************** raw write interface (sync interface) ****************************************************************************/ -NTSTATUS smb_raw_write(struct smbcli_tree *tree, union smb_write *parms) +_PUBLIC_ NTSTATUS smb_raw_write(struct smbcli_tree *tree, union smb_write *parms) { struct smbcli_request *req = smb_raw_write_send(tree, parms); return smb_raw_write_recv(req, parms); diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index 355d092583..a42c710547 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -24,9 +24,12 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" +#include "libcli/raw/raw_proto.h" #include "lib/util/dlinklist.h" #include "lib/events/events.h" #include "param/param.h" +#include "librpc/ndr/libndr.h" +#include "librpc/gen_ndr/ndr_misc.h" /* we over allocate the data buffer to prevent too many realloc calls */ #define REQ_OVER_ALLOCATION 0 @@ -49,7 +52,7 @@ void smb_setup_bufinfo(struct smbcli_request *req) /* destroy a request structure and return final status */ -NTSTATUS smbcli_request_destroy(struct smbcli_request *req) +_PUBLIC_ NTSTATUS smbcli_request_destroy(struct smbcli_request *req) { NTSTATUS status; @@ -405,7 +408,7 @@ bool smbcli_handle_oplock_break(struct smbcli_transport *transport, uint_t len, wait for a reply to be received for a packet that just returns an error code and nothing more */ -NTSTATUS smbcli_request_simple_recv(struct smbcli_request *req) +_PUBLIC_ NTSTATUS smbcli_request_simple_recv(struct smbcli_request *req) { (void) smbcli_request_receive(req); return smbcli_request_destroy(req); diff --git a/source4/libcli/raw/rawsearch.c b/source4/libcli/raw/rawsearch.c index fb2b09467c..99141574e2 100644 --- a/source4/libcli/raw/rawsearch.c +++ b/source4/libcli/raw/rawsearch.c @@ -20,6 +20,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" +#include "libcli/raw/raw_proto.h" /**************************************************************************** Old style search backend - process output. @@ -718,7 +719,7 @@ static NTSTATUS smb_raw_t2search_backend(struct smbcli_tree *tree, /* Implements trans2findfirst2 and old search */ -NTSTATUS smb_raw_search_first(struct smbcli_tree *tree, +_PUBLIC_ NTSTATUS smb_raw_search_first(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, union smb_search_first *io, void *private, smbcli_search_callback callback) diff --git a/source4/libcli/raw/rawsetfileinfo.c b/source4/libcli/raw/rawsetfileinfo.c index f1e4ee3686..16052e8708 100644 --- a/source4/libcli/raw/rawsetfileinfo.c +++ b/source4/libcli/raw/rawsetfileinfo.c @@ -21,6 +21,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" +#include "libcli/raw/raw_proto.h" #include "librpc/gen_ndr/ndr_security.h" @@ -409,7 +410,7 @@ struct smbcli_request *smb_raw_setfileinfo_send(struct smbcli_tree *tree, /**************************************************************************** Set file info (async send) ****************************************************************************/ -NTSTATUS smb_raw_setfileinfo(struct smbcli_tree *tree, +_PUBLIC_ NTSTATUS smb_raw_setfileinfo(struct smbcli_tree *tree, union smb_setfileinfo *parms) { struct smbcli_request *req = smb_raw_setfileinfo_send(tree, parms); @@ -420,7 +421,7 @@ NTSTATUS smb_raw_setfileinfo(struct smbcli_tree *tree, /**************************************************************************** Set path info (async send) ****************************************************************************/ -struct smbcli_request *smb_raw_setpathinfo_send(struct smbcli_tree *tree, +_PUBLIC_ struct smbcli_request *smb_raw_setpathinfo_send(struct smbcli_tree *tree, union smb_setfileinfo *parms) { DATA_BLOB blob; @@ -456,7 +457,7 @@ struct smbcli_request *smb_raw_setpathinfo_send(struct smbcli_tree *tree, /**************************************************************************** Set path info (sync interface) ****************************************************************************/ -NTSTATUS smb_raw_setpathinfo(struct smbcli_tree *tree, +_PUBLIC_ NTSTATUS smb_raw_setpathinfo(struct smbcli_tree *tree, union smb_setfileinfo *parms) { struct smbcli_request *req = smb_raw_setpathinfo_send(tree, parms); diff --git a/source4/libcli/raw/rawshadow.c b/source4/libcli/raw/rawshadow.c index 4c58c91383..b318c3e025 100644 --- a/source4/libcli/raw/rawshadow.c +++ b/source4/libcli/raw/rawshadow.c @@ -21,6 +21,7 @@ #include "includes.h" #include "libcli/raw/libcliraw.h" +#include "libcli/raw/raw_proto.h" #include "libcli/raw/ioctl.h" /* diff --git a/source4/libcli/raw/rawtrans.c b/source4/libcli/raw/rawtrans.c index 53670d22a3..29881afd2b 100644 --- a/source4/libcli/raw/rawtrans.c +++ b/source4/libcli/raw/rawtrans.c @@ -21,6 +21,7 @@ #include "includes.h" #include "lib/util/dlinklist.h" #include "libcli/raw/libcliraw.h" +#include "libcli/raw/raw_proto.h" #define TORTURE_TRANS_DATA 0 @@ -192,7 +193,7 @@ failed: return smbcli_request_destroy(req); } -NTSTATUS smb_raw_trans_recv(struct smbcli_request *req, +_PUBLIC_ NTSTATUS smb_raw_trans_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, struct smb_trans2 *parms) { @@ -365,7 +366,7 @@ struct smbcli_request *smb_raw_trans_send_backend(struct smbcli_tree *tree, trans/trans2 raw async interface - only BLOBs used in this interface. note that this doesn't yet support multi-part requests */ -struct smbcli_request *smb_raw_trans_send(struct smbcli_tree *tree, +_PUBLIC_ struct smbcli_request *smb_raw_trans_send(struct smbcli_tree *tree, struct smb_trans2 *parms) { return smb_raw_trans_send_backend(tree, parms, SMBtrans); @@ -394,7 +395,7 @@ NTSTATUS smb_raw_trans2(struct smbcli_tree *tree, /* trans synchronous blob interface */ -NTSTATUS smb_raw_trans(struct smbcli_tree *tree, +_PUBLIC_ NTSTATUS smb_raw_trans(struct smbcli_tree *tree, TALLOC_CTX *mem_ctx, struct smb_trans2 *parms) { @@ -631,7 +632,7 @@ NTSTATUS smb_raw_nttrans(struct smbcli_tree *tree, TODO: we only need to avoid multi-part replies because the multi-part trans receive code is broken. */ -size_t smb_raw_max_trans_data(struct smbcli_tree *tree, size_t param_size) +_PUBLIC_ size_t smb_raw_max_trans_data(struct smbcli_tree *tree, size_t param_size) { return tree->session->transport->negotiate.max_xmit - (70 + param_size); } diff --git a/source4/libcli/raw/smb_signing.c b/source4/libcli/raw/smb_signing.c index 4acfb9d16d..97bb688d1a 100644 --- a/source4/libcli/raw/smb_signing.c +++ b/source4/libcli/raw/smb_signing.c @@ -22,6 +22,7 @@ #include "includes.h" #include "smb.h" #include "libcli/raw/libcliraw.h" +#include "libcli/raw/raw_proto.h" #include "lib/crypto/crypto.h" #include "param/param.h" -- cgit From 275f32ae2df333c089343dd20fc4efee1bed2b7b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 14 Apr 2008 11:31:17 +0200 Subject: fill in unknown fields in SMB2 READ call (This used to be commit 9b686c138037f613da15168d0722786e00f023e5) --- source4/libcli/raw/interfaces.h | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index 3965c58204..61441b2cdc 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -1706,19 +1706,27 @@ union smb_read { /* static body buffer 48 (0x30) bytes */ /* uint16_t buffer_code; 0x31 = 0x30 + 1 */ - uint16_t _pad; + uint8_t _pad; + uint8_t reserved; uint32_t length; uint64_t offset; /* struct smb2_handle handle; */ - uint64_t unknown1; /* 0x0000000000000000 */ - uint64_t unknown2; /* 0x0000000000000000 */ + uint32_t min_count; + uint32_t channel; + uint32_t remaining; + /* the docs give no indication of what + these channel variables are for */ + uint16_t channel_offset; + uint16_t channel_length; } in; struct { /* static body buffer 16 (0x10) bytes */ /* uint16_t buffer_code; 0x11 = 0x10 + 1 */ - /* uint16_t data_ofs; */ + /* uint8_t data_ofs; */ + /* uint8_t reserved; */ /* uint32_t data_size; */ - uint64_t unknown1; /* 0x0000000000000000 */ + uint32_t remaining; + uint32_t reserved; /* dynamic body */ DATA_BLOB data; -- cgit From 578539216fcb275e5ec013b3ed1c81e4baced80e Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 16 Apr 2008 10:03:08 +0200 Subject: libcli/smb2: make it possible to pass additional extra blobs in smb2_create() This also fixes the alignment from 8 to 4 byte bounderies. metze (This used to be commit e0a0d8e36acd735b587cd7870625af52c5dc3431) --- source4/libcli/raw/interfaces.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index 61441b2cdc..cf5a3aa25e 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -1587,6 +1587,14 @@ union smb_open { /* optional list of extended attributes */ struct smb_ea_list eas; + + struct smb2_create_blobs { + uint32_t num_blobs; + struct smb2_create_blob { + const char *tag; + DATA_BLOB data; + } *blobs; + } blobs; } in; struct { union smb_handle file; -- cgit From 11703b298685c9984a6a3c3a64eddb8a1a516b90 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 17 Apr 2008 15:20:39 +0200 Subject: fix the overflow/wrap checks in Samba4 for new gcc optimisation behavior The approach I have used is as set out in https://www.securecoding.cert.org/confluence/display/seccode/ARR38-C.+Do+not+add+or+subtract+an+integer+to+a+pointer+if+the+resulting+value+does+not+refer+to+an+element+within+the+array (This used to be commit 92d5fb531db39be655f0cbd2d75b5f675a0a4cfa) --- source4/libcli/raw/rawrequest.c | 6 +++--- source4/libcli/raw/rawtrans.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index a42c710547..ef856c6ea1 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -700,10 +700,10 @@ DATA_BLOB smbcli_req_pull_blob(struct request_bufinfo *bufinfo, TALLOC_CTX *mem_ static bool smbcli_req_data_oob(struct request_bufinfo *bufinfo, const uint8_t *ptr, uint32_t count) { /* be careful with wraparound! */ - if (ptr < bufinfo->data || - ptr >= bufinfo->data + bufinfo->data_size || + if ((uintptr_t)ptr < (uintptr_t)bufinfo->data || + (uintptr_t)ptr >= (uintptr_t)bufinfo->data + bufinfo->data_size || count > bufinfo->data_size || - ptr + count > bufinfo->data + bufinfo->data_size) { + (uintptr_t)ptr + count > (uintptr_t)bufinfo->data + bufinfo->data_size) { return true; } return false; diff --git a/source4/libcli/raw/rawtrans.c b/source4/libcli/raw/rawtrans.c index 29881afd2b..0f15b2151b 100644 --- a/source4/libcli/raw/rawtrans.c +++ b/source4/libcli/raw/rawtrans.c @@ -40,10 +40,10 @@ static bool raw_trans_oob(struct smbcli_request *req, ptr = req->in.hdr + offset; /* be careful with wraparound! */ - if (ptr < req->in.data || - ptr >= req->in.data + req->in.data_size || + if ((uintptr_t)ptr < (uintptr_t)req->in.data || + (uintptr_t)ptr >= (uintptr_t)req->in.data + req->in.data_size || count > req->in.data_size || - ptr + count > req->in.data + req->in.data_size) { + (uintptr_t)ptr + count > (uintptr_t)req->in.data + req->in.data_size) { return true; } return false; -- cgit From 670b7dcae3d50e62902fce45d6bb1eeef8530f7c Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 18 Apr 2008 22:19:08 +0200 Subject: libcli: define structure for SMB2 Break metze (This used to be commit 5ffea702c3a1c92a797afab1a3cadf2f2a18729f) --- source4/libcli/raw/interfaces.h | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index cf5a3aa25e..bad3743721 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -1862,7 +1862,8 @@ enum smb_lock_level { RAW_LOCK_LOCK, RAW_LOCK_UNLOCK, RAW_LOCK_LOCKX, - RAW_LOCK_SMB2 + RAW_LOCK_SMB2, + RAW_LOCK_SMB2_BREAK }; /* the generic interface is defined to be equal to the lockingX interface */ @@ -1925,6 +1926,20 @@ union smb_lock { uint16_t unknown1; } out; } smb2; + + /* SMB2 Break */ + struct smb2_break { + enum smb_lock_level level; + struct { + union smb_handle file; + + /* static body buffer 24 (0x18) bytes */ + uint8_t oplock_level; + uint8_t reserved; + uint32_t reserved2; + /* struct smb2_handle handle; */ + } in, out; + } smb2_break; }; -- cgit From 4e83011f72ba3df387512755a17760b42a7bf2f2 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 21 Apr 2008 17:58:23 -0400 Subject: Remove more event_context_init() uses from function calls within deep down the code. Make sure we pass around the event_context where we need it instead. All test but a few python ones fail. Jelmer promised to fix them. (This used to be commit 3045d391626fba169aa26be52174883e18d323e9) --- source4/libcli/raw/clisocket.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clisocket.c b/source4/libcli/raw/clisocket.c index 1dcf2d1c53..49838e8a1c 100644 --- a/source4/libcli/raw/clisocket.c +++ b/source4/libcli/raw/clisocket.c @@ -59,12 +59,7 @@ struct composite_context *smbcli_sock_connect_send(TALLOC_CTX *mem_ctx, if (result == NULL) goto failed; result->state = COMPOSITE_STATE_IN_PROGRESS; - if (event_ctx != NULL) { - result->event_ctx = talloc_reference(result, event_ctx); - } else { - result->event_ctx = event_context_init(result); - } - + result->event_ctx = talloc_reference(result, event_ctx); if (result->event_ctx == NULL) goto failed; state = talloc(result, struct sock_connect_state); @@ -202,6 +197,11 @@ _PUBLIC_ struct smbcli_socket *smbcli_sock_connect_byname(const char *host, cons TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx); struct smbcli_socket *result; + if (event_ctx == NULL) { + DEBUG(0, ("Invalid NULL event context passed in as parameter\n")); + return NULL; + } + if (tmp_ctx == NULL) { DEBUG(0, ("talloc_new failed\n")); return NULL; @@ -214,16 +214,6 @@ _PUBLIC_ struct smbcli_socket *smbcli_sock_connect_byname(const char *host, cons return NULL; } - if (event_ctx == NULL) { - event_ctx = event_context_init(mem_ctx); - } - - if (event_ctx == NULL) { - DEBUG(0, ("event_context_init failed\n")); - talloc_free(tmp_ctx); - return NULL; - } - /* allow hostnames of the form NAME#xx and do a netbios lookup */ if ((p = strchr(name, '#'))) { name_type = strtol(p+1, NULL, 16); -- cgit From d67e47e5cd11c928299dc03ce2ff521e2d3cca83 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 24 Apr 2008 16:27:36 +0100 Subject: Add comment explaining why io.in.workgroup isn't important. This protocol feild isn't used by servers (apparently), so we might be able to get rid of it. Andrew Bartlett (This used to be commit 58935acc7c8e97323d5d5979234ef26ef8a100a4) --- source4/libcli/raw/clitree.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitree.c b/source4/libcli/raw/clitree.c index d5075f9271..15cd70833c 100644 --- a/source4/libcli/raw/clitree.c +++ b/source4/libcli/raw/clitree.c @@ -193,6 +193,11 @@ NTSTATUS smbcli_tree_full_connection(TALLOC_CTX *parent_ctx, io.in.service_type = service_type; io.in.credentials = credentials; io.in.fallback_to_anonymous = false; + + /* This workgroup gets sent out by the SPNEGO session setup. + * I don't know of any servers that look at it, so we might + * hardcode it to "" some day, when the war on global_loadparm + * is complete -- abartlet 2008-04-28 */ io.in.workgroup = lp_workgroup(global_loadparm); io.in.options = *options; -- cgit From 8846981807a08e86c19b585be135b738eb9edf61 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 15 May 2008 20:46:10 +1000 Subject: update some SMB2 find flags (This used to be commit b7560afd4bab984c0083e9687b69bc42970ad932) --- source4/libcli/raw/interfaces.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index bad3743721..871bab01db 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -2354,10 +2354,11 @@ union smb_search_first { #define SMB2_FIND_ID_BOTH_DIRECTORY_INFO 0x25 #define SMB2_FIND_ID_FULL_DIRECTORY_INFO 0x26 -/* flags for RAW_FILEINFO_SMB2_ALL_EAS */ +/* flags for SMB2 find */ #define SMB2_CONTINUE_FLAG_RESTART 0x01 #define SMB2_CONTINUE_FLAG_SINGLE 0x02 -#define SMB2_CONTINUE_FLAG_NEW 0x10 +#define SMB2_CONTINUE_FLAG_INDEX 0x04 +#define SMB2_CONTINUE_FLAG_REOPEN 0x10 /* SMB2 Find */ struct smb2_find { @@ -2370,7 +2371,7 @@ union smb_search_first { /* uint16_t buffer_code; 0x21 = 0x20 + 1 */ uint8_t level; uint8_t continue_flags; /* SMB2_CONTINUE_FLAG_* */ - uint32_t unknown; /* perhaps a continue token? */ + uint32_t file_index; /* struct smb2_handle handle; */ /* uint16_t pattern_ofs; */ /* uint16_t pattern_size; */ -- cgit From 4d39976dddf2adf6a0d659050c3a21a6e0ff8ab2 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 21 May 2008 22:12:20 +1000 Subject: fixed SMB2 locking - SMB2 locking is different in several ways from SMB locking. To fix it properly we will need a new generic mapping structure for locking, but for now do a best effort mapping - added locking to gentest_smb2 (This used to be commit ea6d9cf602302adafe0f9d5f5f90a9b26d1ead6f) --- source4/libcli/raw/interfaces.h | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index 871bab01db..149b91916a 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -1866,13 +1866,12 @@ enum smb_lock_level { RAW_LOCK_SMB2_BREAK }; -/* the generic interface is defined to be equal to the lockingX interface */ -#define RAW_LOCK_GENERIC RAW_LOCK_LOCKX +#define RAW_LOCK_GENERIC RAW_LOCK_LOCKX /* union for lock() backend call */ union smb_lock { - /* SMBlockingX (and generic) interface */ + /* SMBlockingX and generic interface */ struct { enum smb_lock_level level; struct { @@ -1887,7 +1886,7 @@ union smb_lock { uint64_t count; } *locks; /* unlocks are first in the arrray */ } in; - } lockx, generic; + } generic, lockx; /* SMBlock and SMBunlock interface */ struct { @@ -1907,23 +1906,26 @@ union smb_lock { /* static body buffer 48 (0x30) bytes */ /* uint16_t buffer_code; 0x30 */ - uint16_t unknown1; /* must be 0x0001 */ - uint32_t unknown2; + uint16_t lock_count; + uint32_t reserved; /* struct smb2_handle handle; */ - uint64_t offset; - uint64_t count; - uint32_t unknown5; + struct smb2_lock_element { + uint64_t offset; + uint64_t length; +/* these flags are the same as the SMB2 lock flags */ #define SMB2_LOCK_FLAG_NONE 0x00000000 #define SMB2_LOCK_FLAG_SHARED 0x00000001 -#define SMB2_LOCK_FLAG_EXCLUSIV 0x00000002 +#define SMB2_LOCK_FLAG_EXCLUSIVE 0x00000002 #define SMB2_LOCK_FLAG_UNLOCK 0x00000004 -#define SMB2_LOCK_FLAG_NO_PENDING 0x00000010 - uint32_t flags; +#define SMB2_LOCK_FLAG_FAIL_IMMEDIATELY 0x00000010 + uint32_t flags; + uint32_t reserved; + } *locks; } in; struct { /* static body buffer 4 (0x04) bytes */ /* uint16_t buffer_code; 0x04 */ - uint16_t unknown1; + uint16_t reserved; } out; } smb2; -- cgit From aed93a238e13247945073921d91408c91ae210c3 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 21 May 2008 22:51:21 +1000 Subject: fixed SMB2 flush call, and added flush to gentest_smb2 (This used to be commit c52fe1fe1c77636d87355d3c4baa66e052fe9008) --- source4/libcli/raw/interfaces.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index 149b91916a..3370021d48 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -2156,8 +2156,12 @@ union smb_flush { enum smb_flush_level level; struct { union smb_handle file; - uint32_t unknown; + uint16_t reserved1; + uint32_t reserved2; } in; + struct { + uint16_t reserved; + } out; } smb2; }; -- cgit From dec930448f957aca7e70e975221a2ac060819b2e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 22 May 2008 14:49:21 +1000 Subject: fixed parsing of the SMB2 ALL_INFO qfileinfo level (This used to be commit a7be5ba22e0cf2c61501f5a05e64673f31ba145c) --- source4/libcli/raw/interfaces.h | 3 ++- source4/libcli/raw/rawfileinfo.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index 3370021d48..bae0e67b02 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -684,7 +684,8 @@ union smb_fileinfo { uint32_t ea_size; uint32_t access_mask; uint64_t position; - uint64_t mode; + uint32_t mode; + uint32_t alignment_requirement; struct smb_wire_string fname; } out; } all_info2; diff --git a/source4/libcli/raw/rawfileinfo.c b/source4/libcli/raw/rawfileinfo.c index 71900be49c..0ea5a93606 100644 --- a/source4/libcli/raw/rawfileinfo.c +++ b/source4/libcli/raw/rawfileinfo.c @@ -243,7 +243,8 @@ NTSTATUS smb_raw_fileinfo_passthru_parse(const DATA_BLOB *blob, TALLOC_CTX *mem_ parms->all_info2.out.ea_size = IVAL(blob->data, 0x48); parms->all_info2.out.access_mask = IVAL(blob->data, 0x4C); parms->all_info2.out.position = BVAL(blob->data, 0x50); - parms->all_info2.out.mode = BVAL(blob->data, 0x58); + parms->all_info2.out.mode = IVAL(blob->data, 0x58); + parms->all_info2.out.alignment_requirement = IVAL(blob->data, 0x5C); smbcli_blob_pull_string(NULL, mem_ctx, blob, &parms->all_info2.out.fname, 0x60, 0x64, STR_UNICODE); return NT_STATUS_OK; -- cgit From a6e5c70da75e62c84eff0911c279c6a9b0b00b45 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 22 May 2008 17:54:06 +1000 Subject: added a define for all valid file attributes (This used to be commit 198ed9336756f973cebd7cc3df7f51e2c4575205) --- source4/libcli/raw/smb.h | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/smb.h b/source4/libcli/raw/smb.h index e054ed6522..74869e8a45 100644 --- a/source4/libcli/raw/smb.h +++ b/source4/libcli/raw/smb.h @@ -370,6 +370,7 @@ #define FILE_ATTRIBUTE_OFFLINE 0x1000 #define FILE_ATTRIBUTE_NONINDEXED 0x2000 #define FILE_ATTRIBUTE_ENCRYPTED 0x4000 +#define FILE_ATTRIBUTE_ALL_MASK 0x7FFF /* Flags - combined with attributes. */ #define FILE_FLAG_WRITE_THROUGH 0x80000000L -- cgit From d5def936fe67c1cde2c4ed00834c4ce325dfcb55 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 22 May 2008 22:46:29 +1000 Subject: pass in the required alignment to the EA construction routines (This used to be commit af31030e0b78b6b220740529901ec8d2d9f5a3fe) --- source4/libcli/raw/raweas.c | 9 +++++---- source4/libcli/raw/rawfile.c | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/raweas.c b/source4/libcli/raw/raweas.c index 8ea8e621c9..07b517ade3 100644 --- a/source4/libcli/raw/raweas.c +++ b/source4/libcli/raw/raweas.c @@ -54,13 +54,13 @@ static uint_t ea_name_list_size(uint_t num_names, struct ea_name *eas) This assumes the names are strict ascii, which should be a reasonable assumption */ -size_t ea_list_size_chained(uint_t num_eas, struct ea_struct *eas) +size_t ea_list_size_chained(uint_t num_eas, struct ea_struct *eas, unsigned alignment) { uint_t total = 0; int i; for (i=0;intcreatex.in.ea_list) { uint32_t ea_size = ea_list_size_chained(parms->ntcreatex.in.ea_list->num_eas, - parms->ntcreatex.in.ea_list->eas); + parms->ntcreatex.in.ea_list->eas, 4); ea_blob = data_blob_talloc(mem_ctx, NULL, ea_size); if (ea_blob.data == NULL) { return NULL; } ea_put_list_chained(ea_blob.data, parms->ntcreatex.in.ea_list->num_eas, - parms->ntcreatex.in.ea_list->eas); + parms->ntcreatex.in.ea_list->eas, 4); } nt.in.params = data_blob_talloc(mem_ctx, NULL, 53); -- cgit From 2ad2bdda89c07c0b8ce754c3b0cd4664eefc697d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 26 May 2008 15:02:43 +1000 Subject: stricter checks for valid inputs in SMB2 open and lock (This used to be commit a7b5689a73adde59de28770aa3949660441291ea) --- source4/libcli/raw/interfaces.h | 1 + source4/libcli/raw/smb.h | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index bae0e67b02..36d8c3abb0 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -1919,6 +1919,7 @@ union smb_lock { #define SMB2_LOCK_FLAG_EXCLUSIVE 0x00000002 #define SMB2_LOCK_FLAG_UNLOCK 0x00000004 #define SMB2_LOCK_FLAG_FAIL_IMMEDIATELY 0x00000010 +#define SMB2_LOCK_FLAG_ALL_MASK 0x00000017 uint32_t flags; uint32_t reserved; } *locks; diff --git a/source4/libcli/raw/smb.h b/source4/libcli/raw/smb.h index 74869e8a45..5a92b99757 100644 --- a/source4/libcli/raw/smb.h +++ b/source4/libcli/raw/smb.h @@ -133,6 +133,7 @@ #define NTCREATEX_SHARE_ACCESS_READ 1 #define NTCREATEX_SHARE_ACCESS_WRITE 2 #define NTCREATEX_SHARE_ACCESS_DELETE 4 +#define NTCREATEX_SHARE_ACCESS_MASK 7 /* ntcreatex open_disposition field */ #define NTCREATEX_DISP_SUPERSEDE 0 /* supersede existing file (if it exists) */ @@ -154,14 +155,18 @@ #define NTCREATEX_OPTIONS_RANDOM_ACCESS 0x0800 #define NTCREATEX_OPTIONS_DELETE_ON_CLOSE 0x1000 #define NTCREATEX_OPTIONS_OPEN_BY_FILE_ID 0x2000 -#define NTCREATEX_OPTIONS_UNKNOWN_400000 0x400000 - +#define NTCREATEX_OPTIONS_BACKUP_INTENT 0x4000 +#define NTCREATEX_OPTIONS_REPARSE_POINT 0x200000 +#define NTCREATEX_OPTIONS_UNKNOWN_400000 0x400000 /* create options these bits are for private use by backends, they are not valid on the wire */ #define NTCREATEX_OPTIONS_PRIVATE_MASK 0xFF000000 #define NTCREATEX_OPTIONS_PRIVATE_DENY_DOS 0x01000000 #define NTCREATEX_OPTIONS_PRIVATE_DENY_FCB 0x02000000 +#define NTCREATEX_OPTIONS_NOT_SUPPORTED_MASK 0x00DFA188 + + /* ntcreatex impersonation field */ #define NTCREATEX_IMPERSONATION_ANONYMOUS 0 -- cgit From cb36437db2d75e7facc91cf0089f2caa20bf0ca0 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 27 May 2008 16:43:36 +1000 Subject: added support for the output fields of SMB2 close (This used to be commit 2633bc749792c224acc73a2e4ca723404331c19c) --- source4/libcli/raw/interfaces.h | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index 36d8c3abb0..68ebc19bdb 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -1950,23 +1950,43 @@ union smb_lock { enum smb_close_level { RAW_CLOSE_CLOSE, RAW_CLOSE_SPLCLOSE, - RAW_CLOSE_SMB2 + RAW_CLOSE_SMB2, + RAW_CLOSE_GENERIC, }; -#define RAW_CLOSE_GENERIC RAW_CLOSE_CLOSE - /* union for close() backend call */ union smb_close { - /* SMBclose (and generic) interface */ + /* generic interface */ struct { enum smb_close_level level; struct { union smb_handle file; time_t write_time; +#define SMB2_CLOSE_FLAGS_FULL_INFORMATION (1<<0) + uint16_t flags; /* SMB2_CLOSE_FLAGS_* */ } in; - } close, generic; + struct { + uint16_t flags; + NTTIME create_time; + NTTIME access_time; + NTTIME write_time; + NTTIME change_time; + uint64_t alloc_size; + uint64_t size; + uint32_t file_attr; + } out; + } generic; + + /* SMBclose interface */ + struct { + enum smb_close_level level; + struct { + union smb_handle file; + time_t write_time; + } in; + } close; /* SMBsplclose interface - empty! */ struct { @@ -1984,7 +2004,6 @@ union smb_close { /* static body buffer 24 (0x18) bytes */ /* uint16_t buffer_code; 0x18 */ -#define SMB2_CLOSE_FLAGS_FULL_INFORMATION (1<<0) uint16_t flags; /* SMB2_CLOSE_FLAGS_* */ uint32_t _pad; } in; -- cgit From 8daeee5c5d7d5851677089cceaf26a0e32675a96 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 27 May 2008 18:20:23 +1000 Subject: ensure that we honor SMB2 read min_count properly (This used to be commit 318038d6f670efffa96d8b0db63f46b3752e1cd3) --- source4/libcli/raw/interfaces.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index 68ebc19bdb..17c85138ac 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -1647,7 +1647,7 @@ union smb_read { struct { union smb_handle file; uint64_t offset; - uint16_t mincnt; + uint32_t mincnt; /* enforced on SMB2, 16 bit on SMB */ uint32_t maxcnt; uint16_t remaining; bool read_for_execute; -- cgit From 2173169e191754887acddb669a937b872b7ce017 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 28 May 2008 15:27:50 +1000 Subject: added support for all of the known SMB2 create tags in our client library (This used to be commit 597b38e97b01d2137e6ac96ca07cd56fadb2c09e) --- source4/libcli/raw/interfaces.h | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index 17c85138ac..d170006d3b 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -1586,9 +1586,17 @@ union smb_open { /* dynamic body */ const char *fname; - /* optional list of extended attributes */ + /* now some optional parameters - encoded as tagged blobs */ struct smb_ea_list eas; - + uint64_t alloc_size; + struct security_descriptor *sec_desc; + bool durable_open; + struct smb2_handle *durable_handle; + bool query_maximal_access; + NTTIME timewarp; + bool query_on_disk_id; + + /* and any additional blobs the caller wants */ struct smb2_create_blobs { uint32_t num_blobs; struct smb2_create_blob { @@ -1617,8 +1625,12 @@ union smb_open { /* uint32_t blob_ofs; */ /* uint32_t blob_size; */ - /* dynamic body */ - DATA_BLOB blob; + /* optional return values matching tagged values in the call */ + uint32_t maximal_access; + uint8_t on_disk_id[32]; + + /* tagged blobs in the reply */ + struct smb2_create_blobs blobs; } out; } smb2; }; -- cgit From c86dc11be6e626fa81f025d7ec78226fb4249cdc Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 29 May 2008 19:16:26 +1000 Subject: added support for returning the maximal access MXAC tag in SMB2 create (This used to be commit 4eb49335d5f0319f9aa47ded5215a2977d3336bf) --- source4/libcli/raw/interfaces.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index d170006d3b..19d51893a6 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -1354,7 +1354,7 @@ union smb_open { break; \ } \ } while (0) - /* SMBNTCreateX interface */ + /* SMBNTCreateX, nttrans and generic interface */ struct { enum smb_open_level level; struct { @@ -1377,6 +1377,9 @@ union smb_open { NTTRANS varient of the call */ struct security_descriptor *sec_desc; struct smb_ea_list *ea_list; + + /* some optional parameters from the SMB2 varient */ + bool query_maximal_access; } in; struct { union smb_handle file; @@ -1392,6 +1395,10 @@ union smb_open { uint16_t file_type; uint16_t ipc_state; uint8_t is_directory; + + /* optional return values matching SMB2 tagged + values in the call */ + uint32_t maximal_access; } out; } ntcreatex, nttrans, generic; -- cgit From 3850d47fef103c4118f1baff4b91b403ab4dde71 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 2 Jun 2008 11:02:57 +1000 Subject: updated some info levels based on WSPP docs (This used to be commit f84620324a8cebcd2fd19388d910928ca1ad1334) --- source4/libcli/raw/interfaces.h | 17 +++++++++++++---- source4/libcli/raw/rawsetfileinfo.c | 29 +++++++++++++++++++++++------ source4/libcli/raw/trans2.h | 27 ++++++++++++++++----------- 3 files changed, 52 insertions(+), 21 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index 19d51893a6..8e23510f06 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -906,15 +906,24 @@ enum smb_setfileinfo_level { RAW_SFILEINFO_RENAME_INFORMATION = SMB_SFILEINFO_RENAME_INFORMATION, RAW_SFILEINFO_DISPOSITION_INFORMATION = SMB_SFILEINFO_DISPOSITION_INFORMATION, RAW_SFILEINFO_POSITION_INFORMATION = SMB_SFILEINFO_POSITION_INFORMATION, + RAW_SFILEINFO_FULL_EA_INFORMATION = SMB_SFILEINFO_FULL_EA_INFORMATION, RAW_SFILEINFO_MODE_INFORMATION = SMB_SFILEINFO_MODE_INFORMATION, RAW_SFILEINFO_ALLOCATION_INFORMATION = SMB_SFILEINFO_ALLOCATION_INFORMATION, RAW_SFILEINFO_END_OF_FILE_INFORMATION = SMB_SFILEINFO_END_OF_FILE_INFORMATION, - RAW_SFILEINFO_1023 = SMB_SFILEINFO_1023, + RAW_SFILEINFO_PIPE_INFORMATION = SMB_SFILEINFO_PIPE_INFORMATION, + RAW_SFILEINFO_VALID_DATA_INFORMATION = SMB_SFILEINFO_VALID_DATA_INFORMATION, + RAW_SFILEINFO_SHORT_NAME_INFORMATION = SMB_SFILEINFO_SHORT_NAME_INFORMATION, RAW_SFILEINFO_1025 = SMB_SFILEINFO_1025, + RAW_SFILEINFO_1027 = SMB_SFILEINFO_1027, RAW_SFILEINFO_1029 = SMB_SFILEINFO_1029, + RAW_SFILEINFO_1030 = SMB_SFILEINFO_1030, + RAW_SFILEINFO_1031 = SMB_SFILEINFO_1031, RAW_SFILEINFO_1032 = SMB_SFILEINFO_1032, - RAW_SFILEINFO_1039 = SMB_SFILEINFO_1039, - RAW_SFILEINFO_1040 = SMB_SFILEINFO_1040, + RAW_SFILEINFO_1036 = SMB_SFILEINFO_1036, + RAW_SFILEINFO_1041 = SMB_SFILEINFO_1041, + RAW_SFILEINFO_1042 = SMB_SFILEINFO_1042, + RAW_SFILEINFO_1043 = SMB_SFILEINFO_1043, + RAW_SFILEINFO_1044 = SMB_SFILEINFO_1044, /* cope with breakage in SMB2 */ RAW_SFILEINFO_RENAME_INFORMATION_SMB2 = SMB_SFILEINFO_RENAME_INFORMATION|0x80000000, @@ -1901,7 +1910,7 @@ union smb_lock { uint16_t ulock_cnt; uint16_t lock_cnt; struct smb_lock_entry { - uint16_t pid; + uint32_t pid; /* 16 bits in SMB1 */ uint64_t offset; uint64_t count; } *locks; /* unlocks are first in the arrray */ diff --git a/source4/libcli/raw/rawsetfileinfo.c b/source4/libcli/raw/rawsetfileinfo.c index 16052e8708..5a4706778a 100644 --- a/source4/libcli/raw/rawsetfileinfo.c +++ b/source4/libcli/raw/rawsetfileinfo.c @@ -110,12 +110,20 @@ bool smb_raw_setfileinfo_passthru(TALLOC_CTX *mem_ctx, } /* Unhandled levels */ - case RAW_SFILEINFO_1023: + case RAW_SFILEINFO_PIPE_INFORMATION: + case RAW_SFILEINFO_VALID_DATA_INFORMATION: + case RAW_SFILEINFO_SHORT_NAME_INFORMATION: case RAW_SFILEINFO_1025: + case RAW_SFILEINFO_1027: case RAW_SFILEINFO_1029: + case RAW_SFILEINFO_1030: + case RAW_SFILEINFO_1031: case RAW_SFILEINFO_1032: - case RAW_SFILEINFO_1039: - case RAW_SFILEINFO_1040: + case RAW_SFILEINFO_1036: + case RAW_SFILEINFO_1041: + case RAW_SFILEINFO_1042: + case RAW_SFILEINFO_1043: + case RAW_SFILEINFO_1044: break; default: @@ -227,12 +235,21 @@ static bool smb_raw_setinfo_backend(struct smbcli_tree *tree, parms, blob); /* Unhandled passthru levels */ - case RAW_SFILEINFO_1023: + case RAW_SFILEINFO_PIPE_INFORMATION: + case RAW_SFILEINFO_VALID_DATA_INFORMATION: + case RAW_SFILEINFO_SHORT_NAME_INFORMATION: + case RAW_SFILEINFO_FULL_EA_INFORMATION: case RAW_SFILEINFO_1025: + case RAW_SFILEINFO_1027: case RAW_SFILEINFO_1029: + case RAW_SFILEINFO_1030: + case RAW_SFILEINFO_1031: case RAW_SFILEINFO_1032: - case RAW_SFILEINFO_1039: - case RAW_SFILEINFO_1040: + case RAW_SFILEINFO_1036: + case RAW_SFILEINFO_1041: + case RAW_SFILEINFO_1042: + case RAW_SFILEINFO_1043: + case RAW_SFILEINFO_1044: return smb_raw_setfileinfo_passthru(mem_ctx, parms->generic.level, parms, blob); diff --git a/source4/libcli/raw/trans2.h b/source4/libcli/raw/trans2.h index 5b7987aa8c..63632eb5ed 100644 --- a/source4/libcli/raw/trans2.h +++ b/source4/libcli/raw/trans2.h @@ -217,32 +217,37 @@ Found 13 valid levels #define SMB_SFILEINFO_UNIX_INFO2 0x20b #define SMB_SFILEINFO_BASIC_INFORMATION 1004 #define SMB_SFILEINFO_RENAME_INFORMATION 1010 +#define SMB_SFILEINFO_LINK_INFORMATION 1011 #define SMB_SFILEINFO_DISPOSITION_INFORMATION 1013 #define SMB_SFILEINFO_POSITION_INFORMATION 1014 +#define SMB_SFILEINFO_FULL_EA_INFORMATION 1015 #define SMB_SFILEINFO_MODE_INFORMATION 1016 #define SMB_SFILEINFO_ALLOCATION_INFORMATION 1019 #define SMB_SFILEINFO_END_OF_FILE_INFORMATION 1020 - -/* filemon shows FilePipeInformation */ -#define SMB_SFILEINFO_1023 1023 +#define SMB_SFILEINFO_PIPE_INFORMATION 1023 +#define SMB_SFILEINFO_VALID_DATA_INFORMATION 1039 +#define SMB_SFILEINFO_SHORT_NAME_INFORMATION 1040 /* filemon shows FilePipeRemoteInformation */ #define SMB_SFILEINFO_1025 1025 +/* vista scan responds */ +#define SMB_SFILEINFO_1027 1027 + /* filemon shows CopyOnWriteInformation */ #define SMB_SFILEINFO_1029 1029 /* filemon shows OleClassIdInformation */ #define SMB_SFILEINFO_1032 1032 -/* seems to be the file size - perhaps valid data size? - filemon shows 'InheritContentIndexInfo' -*/ -#define SMB_SFILEINFO_1039 1039 - -/* OLE_INFORMATION? */ -#define SMB_SFILEINFO_1040 1040 - +/* vista scan responds to these */ +#define SMB_SFILEINFO_1030 1030 +#define SMB_SFILEINFO_1031 1031 +#define SMB_SFILEINFO_1036 1036 +#define SMB_SFILEINFO_1041 1041 +#define SMB_SFILEINFO_1042 1042 +#define SMB_SFILEINFO_1043 1043 +#define SMB_SFILEINFO_1044 1044 /* trans2 findfirst levels */ /* -- cgit From 3df3bf577d5510f30aceca13b6be29267c1c6380 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 6 Jun 2008 10:53:00 -0700 Subject: ensure we don't end up with a partially initialised EA structure (This used to be commit 388f4fde3655146bf57b4c51c59c39f475aa7fe8) --- source4/libcli/raw/raweas.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/raweas.c b/source4/libcli/raw/raweas.c index 07b517ade3..6317c49fd7 100644 --- a/source4/libcli/raw/raweas.c +++ b/source4/libcli/raw/raweas.c @@ -131,6 +131,8 @@ uint_t ea_pull_struct(const DATA_BLOB *blob, uint8_t nlen; uint16_t vlen; + ZERO_STRUCTP(ea); + if (blob->length < 6) { return 0; } -- cgit From 70ccb7e7ce0154c98b3bb26c4a85b52b4929ecf1 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 4 Jul 2008 20:16:36 +0200 Subject: libcli/raw: the nttrans setup count is only 8-bit metze (This used to be commit a65599cc83a12ec61e5a6ba6ad9628619a0dc8a3) --- source4/libcli/raw/interfaces.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/interfaces.h b/source4/libcli/raw/interfaces.h index 8e23510f06..537041c137 100644 --- a/source4/libcli/raw/interfaces.h +++ b/source4/libcli/raw/interfaces.h @@ -2258,7 +2258,7 @@ struct smb_nttrans { uint8_t max_setup; uint32_t max_param; uint32_t max_data; - uint32_t setup_count; + uint8_t setup_count; uint16_t function; uint8_t *setup; DATA_BLOB params; -- cgit From 7718a89222549d3d38f58193374d7b5d6b0e79fa Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 4 Jul 2008 19:52:23 +0200 Subject: libcli/raw: add a recv_helper hook infrastructure The recv helper will be called when a response comes and the recv helper can decide to let the request on the SMBCLI_REQUEST_RECV when more reponse packets are expected. It's up to the helper function to keep a reference to the in buffers, each incoming response overwrites req->in. metze (This used to be commit 6d84af89ba96627abe142ba7080c24ae2421ed6c) --- source4/libcli/raw/clitransport.c | 16 +++++++++++++++- source4/libcli/raw/libcliraw.h | 8 ++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/clitransport.c b/source4/libcli/raw/clitransport.c index 34fb96230d..e95ae3271e 100644 --- a/source4/libcli/raw/clitransport.c +++ b/source4/libcli/raw/clitransport.c @@ -480,8 +480,22 @@ async: /* if this request has an async handler then call that to notify that the reply has been received. This might destroy the request so it must happen last */ - DLIST_REMOVE(transport->pending_recv, req); + req->state = SMBCLI_REQUEST_DONE; + + if (req->recv_helper.fn) { + /* + * let the recv helper decide in + * what state the request really is + */ + req->state = req->recv_helper.fn(req); + + /* if more parts are needed, wait for them */ + if (req->state <= SMBCLI_REQUEST_RECV) { + return NT_STATUS_OK; + } + } + DLIST_REMOVE(transport->pending_recv, req); if (req->async.fn) { req->async.fn(req); } diff --git a/source4/libcli/raw/libcliraw.h b/source4/libcli/raw/libcliraw.h index 16a98ad66e..d55b4cc42c 100644 --- a/source4/libcli/raw/libcliraw.h +++ b/source4/libcli/raw/libcliraw.h @@ -231,6 +231,14 @@ struct smbcli_request { struct smbcli_session *session; struct smbcli_tree *tree; + /* a receive helper, smbcli_transport_finish_recv will not call + req->async.fn callback handler unless the recv_helper returns + a value > SMBCLI_REQUEST_RECV. */ + struct { + enum smbcli_request_state (*fn)(struct smbcli_request *); + void *private_data; + } recv_helper; + /* the flags2 from the SMB request, in raw form (host byte order). Used to parse strings */ uint16_t flags2; -- cgit From b4726d48e517b38733a3fcc6e3d3cd23993c4f3d Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 4 Jul 2008 20:07:52 +0200 Subject: libcli/raw: use the new recv_helper infrastructure for nttrans replies metze (This used to be commit 5bf136e233e26b4372155f494bae5118ef777a76) --- source4/libcli/raw/rawtrans.c | 247 +++++++++++++++++++++++++----------------- 1 file changed, 145 insertions(+), 102 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawtrans.c b/source4/libcli/raw/rawtrans.c index 0f15b2151b..9fa52eedae 100644 --- a/source4/libcli/raw/rawtrans.c +++ b/source4/libcli/raw/rawtrans.c @@ -405,146 +405,177 @@ _PUBLIC_ NTSTATUS smb_raw_trans(struct smbcli_tree *tree, return smb_raw_trans_recv(req, mem_ctx, parms); } +struct smb_raw_nttrans_recv_state { + bool got_first; + uint32_t recvd_data; + uint32_t recvd_param; + struct smb_nttrans io; +}; -/**************************************************************************** - receive a SMB nttrans response allocating the necessary memory - ****************************************************************************/ NTSTATUS smb_raw_nttrans_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, struct smb_nttrans *parms) { - uint32_t total_data, recvd_data=0; - uint32_t total_param, recvd_param=0; + struct smb_raw_nttrans_recv_state *state; if (!smbcli_request_receive(req) || smbcli_request_is_error(req)) { - return smbcli_request_destroy(req); + goto failed; + } + + state = talloc_get_type(req->recv_helper.private_data, + struct smb_raw_nttrans_recv_state); + + parms->out = state->io.out; + talloc_steal(mem_ctx, parms->out.setup); + talloc_steal(mem_ctx, parms->out.params.data); + talloc_steal(mem_ctx, parms->out.data.data); + talloc_free(state); + + ZERO_STRUCT(req->recv_helper); + +failed: + return smbcli_request_destroy(req); +} + +/* + * This helper returns SMBCLI_REQUEST_RECV until all data has arrived + */ +static enum smbcli_request_state smb_raw_nttrans_recv_helper(struct smbcli_request *req) +{ + struct smb_raw_nttrans_recv_state *state = talloc_get_type(req->recv_helper.private_data, + struct smb_raw_nttrans_recv_state); + uint32_t param_count, param_ofs, param_disp; + uint32_t data_count, data_ofs, data_disp; + uint32_t total_data, total_param; + uint8_t setup_count; + + /* + * An NT RPC pipe call can return ERRDOS, ERRmoredata + * to a trans call. This is not an error and should not + * be treated as such. + */ + if (smbcli_request_is_error(req)) { + goto failed; } /* sanity check */ if (CVAL(req->in.hdr, HDR_COM) != SMBnttrans) { - DEBUG(0,("smb_raw_receive_nttrans: Expected %s response, got command 0x%02x\n", + DEBUG(0,("smb_raw_nttrans_recv_helper: Expected %s response, got command 0x%02x\n", "SMBnttrans", CVAL(req->in.hdr,HDR_COM))); - req->status = NT_STATUS_UNSUCCESSFUL; - return smbcli_request_destroy(req); + req->status = NT_STATUS_INVALID_NETWORK_RESPONSE; + goto failed; } + /* this is the first packet of the response */ SMBCLI_CHECK_MIN_WCT(req, 18); - /* parse out the lengths */ total_param = IVAL(req->in.vwv, 3); total_data = IVAL(req->in.vwv, 7); + setup_count = CVAL(req->in.vwv, 35); + + param_count = IVAL(req->in.vwv, 11); + param_ofs = IVAL(req->in.vwv, 15); + param_disp = IVAL(req->in.vwv, 19); + + data_count = IVAL(req->in.vwv, 23); + data_ofs = IVAL(req->in.vwv, 27); + data_disp = IVAL(req->in.vwv, 31); + + if (!state->got_first) { + if (total_param > 0) { + state->io.out.params = data_blob_talloc(state, NULL, total_param); + if (!state->io.out.params.data) { + goto nomem; + } + } - parms->out.data = data_blob_talloc(mem_ctx, NULL, total_data); - parms->out.params = data_blob_talloc(mem_ctx, NULL, total_param); - - if (parms->out.data.length != total_data || - parms->out.params.length != total_param) { - req->status = NT_STATUS_NO_MEMORY; - return smbcli_request_destroy(req); - } - - parms->out.setup_count = CVAL(req->in.vwv, 35); - SMBCLI_CHECK_WCT(req, 18 + parms->out.setup_count); + if (total_data > 0) { + state->io.out.data = data_blob_talloc(state, NULL, total_data); + if (!state->io.out.data.data) { + goto nomem; + } + } - if (parms->out.setup_count > 0) { - parms->out.setup = talloc_array(mem_ctx, uint8_t, - parms->out.setup_count*2); - if (!parms->out.setup) { - req->status = NT_STATUS_NO_MEMORY; - return smbcli_request_destroy(req); + if (setup_count > 0) { + SMBCLI_CHECK_WCT(req, 18 + setup_count); + + state->io.out.setup_count = setup_count; + state->io.out.setup = talloc_array(state, uint8_t, + setup_count * VWV(1)); + if (!state->io.out.setup) { + goto nomem; + } + memcpy(state->io.out.setup, (uint8_t *)req->out.vwv + VWV(18), + setup_count * VWV(1)); } - memcpy(parms->out.setup, VWV(18) + (uint8_t *)req->out.vwv, - sizeof(uint16_t) * parms->out.setup_count); + + state->got_first = true; } - - while (recvd_data < total_data || - recvd_param < total_param) { - uint32_t param_count, param_ofs, param_disp; - uint32_t data_count, data_ofs, data_disp; - uint32_t total_data2, total_param2; - /* parse out the total lengths again - they can shrink! */ - total_param2 = IVAL(req->in.vwv, 3); - total_data2 = IVAL(req->in.vwv, 7); + if (total_data > state->io.out.data.length || + total_param > state->io.out.params.length) { + /* they must *only* shrink */ + DEBUG(1,("smb_raw_nttrans_recv_helper: data/params expanded!\n")); + req->status = NT_STATUS_BUFFER_TOO_SMALL; + goto failed; + } - if (total_data2 > total_data || - total_param2 > total_param) { - /* they must *only* shrink */ - DEBUG(1,("smb_raw_receive_nttrans: data/params expanded!\n")); - req->status = NT_STATUS_BUFFER_TOO_SMALL; - return smbcli_request_destroy(req); - } + state->io.out.data.length = total_data; + state->io.out.params.length = total_param; - total_data = total_data2; - total_param = total_param2; - parms->out.data.length = total_data; - parms->out.params.length = total_param; + if (data_count + data_disp > total_data || + param_count + param_disp > total_param) { + DEBUG(1,("smb_raw_nttrans_recv_helper: Buffer overflow\n")); + req->status = NT_STATUS_BUFFER_TOO_SMALL; + goto failed; + } - /* parse params for this lump */ - param_count = IVAL(req->in.vwv, 11); - param_ofs = IVAL(req->in.vwv, 15); - param_disp = IVAL(req->in.vwv, 19); + /* check the server isn't being nasty */ + if (raw_trans_oob(req, param_ofs, param_count) || + raw_trans_oob(req, data_ofs, data_count)) { + DEBUG(1,("smb_raw_nttrans_recv_helper: out of bounds parameters!\n")); + req->status = NT_STATUS_BUFFER_TOO_SMALL; + goto failed; + } - data_count = IVAL(req->in.vwv, 23); - data_ofs = IVAL(req->in.vwv, 27); - data_disp = IVAL(req->in.vwv, 31); + if (data_count) { + memcpy(state->io.out.data.data + data_disp, + req->in.hdr + data_ofs, + data_count); + } - if (data_count + data_disp > total_data || - param_count + param_disp > total_param) { - DEBUG(1,("smb_raw_receive_nttrans: Buffer overflow\n")); - req->status = NT_STATUS_BUFFER_TOO_SMALL; - return smbcli_request_destroy(req); - } - - /* check the server isn't being nasty */ - if (raw_trans_oob(req, param_ofs, param_count) || - raw_trans_oob(req, data_ofs, data_count)) { - DEBUG(1,("smb_raw_receive_nttrans: out of bounds parameters!\n")); - req->status = NT_STATUS_BUFFER_TOO_SMALL; - return smbcli_request_destroy(req); - } + if (param_count) { + memcpy(state->io.out.params.data + param_disp, + req->in.hdr + param_ofs, + param_count); + } - if (data_count) { - memcpy(parms->out.data.data + data_disp, - req->in.hdr + data_ofs, - data_count); - } + state->recvd_param += param_count; + state->recvd_data += data_count; - if (param_count) { - memcpy(parms->out.params.data + param_disp, - req->in.hdr + param_ofs, - param_count); - } + if (state->recvd_data < total_data || + state->recvd_param < total_param) { - recvd_param += param_count; - recvd_data += data_count; + /* we don't need the in buffer any more */ + talloc_free(req->in.buffer); + ZERO_STRUCT(req->in); - if (recvd_data >= total_data && - recvd_param >= total_param) { - break; - } - - if (!smbcli_request_receive(req) || - smbcli_request_is_error(req)) { - return smbcli_request_destroy(req); - } - - /* sanity check */ - if (CVAL(req->in.hdr, HDR_COM) != SMBnttrans) { - DEBUG(0,("smb_raw_receive_nttrans: Expected nttranss, got command 0x%02x\n", - CVAL(req->in.hdr, HDR_COM))); - req->status = NT_STATUS_UNSUCCESSFUL; - return smbcli_request_destroy(req); - } + /* we still wait for more data */ + DEBUG(10,("smb_raw_nttrans_recv_helper: more data needed\n")); + return SMBCLI_REQUEST_RECV; } + DEBUG(10,("smb_raw_nttrans_recv_helper: done\n")); + return SMBCLI_REQUEST_DONE; + +nomem: + req->status = NT_STATUS_NO_MEMORY; failed: - return smbcli_request_destroy(req); + return SMBCLI_REQUEST_ERROR; } - /**************************************************************************** nttrans raw - only BLOBs used in this interface. at the moment we only handle a single primary request @@ -553,6 +584,7 @@ struct smbcli_request *smb_raw_nttrans_send(struct smbcli_tree *tree, struct smb_nttrans *parms) { struct smbcli_request *req; + struct smb_raw_nttrans_recv_state *state; uint8_t *outdata, *outparam; int align = 0; @@ -569,7 +601,13 @@ struct smbcli_request *smb_raw_nttrans_send(struct smbcli_tree *tree, if (!req) { return NULL; } - + + state = talloc_zero(req, struct smb_raw_nttrans_recv_state); + if (!state) { + talloc_free(req); + return NULL; + } + /* fill in SMB parameters */ outparam = req->out.data + align; outdata = outparam + parms->in.params.length; @@ -599,6 +637,11 @@ struct smbcli_request *smb_raw_nttrans_send(struct smbcli_tree *tree, memcpy(outdata, parms->in.data.data, parms->in.data.length); } + /* add the helper which will check that all multi-part replies are + in before an async client callack will be issued */ + req->recv_helper.fn = smb_raw_nttrans_recv_helper; + req->recv_helper.private_data = state; + if (!smbcli_request_send(req)) { smbcli_request_destroy(req); return NULL; -- cgit From 177773424057668339af993f7a0df610dd9b6ae2 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 4 Jul 2008 20:46:10 +0200 Subject: libcli/raw: use the new recv_helper infrastructure for trans/trans2 replies metze (This used to be commit ec67c61b6a82e4f39a15f37a98ae3fe93bb81316) --- source4/libcli/raw/rawtrans.c | 497 ++++++++++++++++++++++++++---------------- 1 file changed, 313 insertions(+), 184 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawtrans.c b/source4/libcli/raw/rawtrans.c index 9fa52eedae..9f5e1da293 100644 --- a/source4/libcli/raw/rawtrans.c +++ b/source4/libcli/raw/rawtrans.c @@ -49,148 +49,188 @@ static bool raw_trans_oob(struct smbcli_request *req, return false; } -/**************************************************************************** - receive a SMB trans or trans2 response allocating the necessary memory - ****************************************************************************/ +static size_t raw_trans_space_left(struct smbcli_request *req) +{ + if (req->transport->negotiate.max_xmit <= req->out.size) { + return 0; + } + + return req->transport->negotiate.max_xmit - req->out.size; +} + +struct smb_raw_trans2_recv_state { + uint8_t command; + uint32_t params_total; + uint32_t data_total; + uint32_t params_left; + uint32_t data_left; + bool got_first; + uint32_t recvd_data; + uint32_t recvd_param; + struct smb_trans2 io; +}; + NTSTATUS smb_raw_trans2_recv(struct smbcli_request *req, TALLOC_CTX *mem_ctx, struct smb_trans2 *parms) { - int total_data=0; - int total_param=0; - uint8_t *tdata; - uint8_t *tparam; + struct smb_raw_trans2_recv_state *state; - parms->out.data.length = 0; - parms->out.data.data = NULL; - parms->out.params.length = 0; - parms->out.params.data = NULL; - - if (!smbcli_request_receive(req)) { - return smbcli_request_destroy(req); + if (!smbcli_request_receive(req) || + smbcli_request_is_error(req)) { + goto failed; } - + + state = talloc_get_type(req->recv_helper.private_data, + struct smb_raw_trans2_recv_state); + + parms->out = state->io.out; + talloc_steal(mem_ctx, parms->out.setup); + talloc_steal(mem_ctx, parms->out.params.data); + talloc_steal(mem_ctx, parms->out.data.data); + talloc_free(state); + + ZERO_STRUCT(req->recv_helper); + +failed: + return smbcli_request_destroy(req); +} + +static enum smbcli_request_state smb_raw_trans2_ship_rest(struct smbcli_request *req, + struct smb_raw_trans2_recv_state *state); + +/* + * This helper returns SMBCLI_REQUEST_RECV until all data has arrived + */ +static enum smbcli_request_state smb_raw_trans2_recv_helper(struct smbcli_request *req) +{ + struct smb_raw_trans2_recv_state *state = talloc_get_type(req->recv_helper.private_data, + struct smb_raw_trans2_recv_state); + uint16_t param_count, param_ofs, param_disp; + uint16_t data_count, data_ofs, data_disp; + uint16_t total_data, total_param; + uint16_t setup_count; + /* * An NT RPC pipe call can return ERRDOS, ERRmoredata * to a trans call. This is not an error and should not * be treated as such. */ - if (NT_STATUS_IS_ERR(req->status)) { - return smbcli_request_destroy(req); + if (smbcli_request_is_error(req)) { + goto failed; + } + + if (state->params_left > 0 || state->data_left > 0) { + return smb_raw_trans2_ship_rest(req, state); } SMBCLI_CHECK_MIN_WCT(req, 10); - /* parse out the lengths */ total_data = SVAL(req->in.vwv, VWV(1)); total_param = SVAL(req->in.vwv, VWV(0)); + setup_count = SVAL(req->in.vwv, VWV(9)); - /* allocate it */ - if (total_data != 0) { - tdata = talloc_array(mem_ctx, uint8_t, total_data); - if (!tdata) { - DEBUG(0,("smb_raw_receive_trans: failed to enlarge data buffer to %d bytes\n", total_data)); - req->status = NT_STATUS_NO_MEMORY; - return smbcli_request_destroy(req); + param_count = SVAL(req->in.vwv, VWV(3)); + param_ofs = SVAL(req->in.vwv, VWV(4)); + param_disp = SVAL(req->in.vwv, VWV(5)); + + data_count = SVAL(req->in.vwv, VWV(6)); + data_ofs = SVAL(req->in.vwv, VWV(7)); + data_disp = SVAL(req->in.vwv, VWV(8)); + + if (!state->got_first) { + if (total_param > 0) { + state->io.out.params = data_blob_talloc(state, NULL, total_param); + if (!state->io.out.params.data) { + goto nomem; + } } - parms->out.data.data = tdata; - } - if (total_param != 0) { - tparam = talloc_array(mem_ctx, uint8_t, total_param); - if (!tparam) { - DEBUG(0,("smb_raw_receive_trans: failed to enlarge param buffer to %d bytes\n", total_param)); - req->status = NT_STATUS_NO_MEMORY; - return smbcli_request_destroy(req); + if (total_data > 0) { + state->io.out.data = data_blob_talloc(state, NULL, total_data); + if (!state->io.out.data.data) { + goto nomem; + } } - parms->out.params.data = tparam; - } - parms->out.setup_count = SVAL(req->in.vwv, VWV(9)); - SMBCLI_CHECK_WCT(req, 10 + parms->out.setup_count); + if (setup_count > 0) { + uint16_t i; - if (parms->out.setup_count > 0) { - int i; - parms->out.setup = talloc_array(mem_ctx, uint16_t, parms->out.setup_count); - if (!parms->out.setup) { - req->status = NT_STATUS_NO_MEMORY; - return smbcli_request_destroy(req); - } - for (i=0;iout.setup_count;i++) { - parms->out.setup[i] = SVAL(req->in.vwv, VWV(10+i)); + SMBCLI_CHECK_WCT(req, 10 + setup_count); + + state->io.out.setup_count = setup_count; + state->io.out.setup = talloc_array(state, uint16_t, setup_count); + if (!state->io.out.setup) { + goto nomem; + } + for (i=0; i < setup_count; i++) { + state->io.out.setup[i] = SVAL(req->in.vwv, VWV(10+i)); + } } - } - while (1) { - uint16_t param_count, param_ofs, param_disp; - uint16_t data_count, data_ofs, data_disp; - uint16_t total_data2, total_param2; + state->got_first = true; + } - /* parse out the total lengths again - they can shrink! */ - total_data2 = SVAL(req->in.vwv, VWV(1)); - total_param2 = SVAL(req->in.vwv, VWV(0)); + if (total_data > state->io.out.data.length || + total_param > state->io.out.params.length) { + /* they must *only* shrink */ + DEBUG(1,("smb_raw_trans2_recv_helper: data/params expanded!\n")); + req->status = NT_STATUS_BUFFER_TOO_SMALL; + goto failed; + } - if (total_data2 > total_data || - total_param2 > total_param) { - /* they must *only* shrink */ - DEBUG(1,("smb_raw_receive_trans: data/params expanded!\n")); - req->status = NT_STATUS_BUFFER_TOO_SMALL; - return smbcli_request_destroy(req); - } + state->io.out.data.length = total_data; + state->io.out.params.length = total_param; - total_data = total_data2; - total_param = total_param2; + if (data_count + data_disp > total_data || + param_count + param_disp > total_param) { + DEBUG(1,("smb_raw_trans2_recv_helper: Buffer overflow\n")); + req->status = NT_STATUS_BUFFER_TOO_SMALL; + goto failed; + } - /* parse params for this lump */ - param_count = SVAL(req->in.vwv, VWV(3)); - param_ofs = SVAL(req->in.vwv, VWV(4)); - param_disp = SVAL(req->in.vwv, VWV(5)); + /* check the server isn't being nasty */ + if (raw_trans_oob(req, param_ofs, param_count) || + raw_trans_oob(req, data_ofs, data_count)) { + DEBUG(1,("smb_raw_trans2_recv_helper: out of bounds parameters!\n")); + req->status = NT_STATUS_BUFFER_TOO_SMALL; + goto failed; + } - data_count = SVAL(req->in.vwv, VWV(6)); - data_ofs = SVAL(req->in.vwv, VWV(7)); - data_disp = SVAL(req->in.vwv, VWV(8)); + if (data_count) { + memcpy(state->io.out.data.data + data_disp, + req->in.hdr + data_ofs, + data_count); + } - if (data_count + data_disp > total_data || - param_count + param_disp > total_param) { - DEBUG(1,("smb_raw_receive_trans: Buffer overflow\n")); - req->status = NT_STATUS_BUFFER_TOO_SMALL; - return smbcli_request_destroy(req); - } - - /* check the server isn't being nasty */ - if (raw_trans_oob(req, param_ofs, param_count) || - raw_trans_oob(req, data_ofs, data_count)) { - DEBUG(1,("smb_raw_receive_trans: out of bounds parameters!\n")); - req->status = NT_STATUS_BUFFER_TOO_SMALL; - return smbcli_request_destroy(req); - } + if (param_count) { + memcpy(state->io.out.params.data + param_disp, + req->in.hdr + param_ofs, + param_count); + } - if (data_count) { - memcpy(parms->out.data.data + data_disp, - req->in.hdr + data_ofs, - data_count); - } + state->recvd_param += param_count; + state->recvd_data += data_count; - if (param_count) { - memcpy(parms->out.params.data + param_disp, - req->in.hdr + param_ofs, - param_count); - } + if (state->recvd_data < total_data || + state->recvd_param < total_param) { - parms->out.data.length += data_count; - parms->out.params.length += param_count; + /* we don't need the in buffer any more */ + talloc_free(req->in.buffer); + ZERO_STRUCT(req->in); - if (total_data <= parms->out.data.length && total_param <= parms->out.params.length) - break; - - if (!smbcli_request_receive_more(req)) { - req->status = NT_STATUS_UNSUCCESSFUL; - return smbcli_request_destroy(req); - } + /* we still wait for more data */ + DEBUG(10,("smb_raw_trans2_recv_helper: more data needed\n")); + return SMBCLI_REQUEST_RECV; } + DEBUG(10,("smb_raw_trans2_recv_helper: done\n")); + return SMBCLI_REQUEST_DONE; + +nomem: + req->status = NT_STATUS_NO_MEMORY; failed: - return smbcli_request_destroy(req); + return SMBCLI_REQUEST_ERROR; } _PUBLIC_ NTSTATUS smb_raw_trans_recv(struct smbcli_request *req, @@ -208,13 +248,17 @@ struct smbcli_request *smb_raw_trans_send_backend(struct smbcli_tree *tree, struct smb_trans2 *parms, uint8_t command) { - int wct = 14 + parms->in.setup_count; - struct smbcli_request *req, *req2; - uint8_t *outdata,*outparam; + struct smb_raw_trans2_recv_state *state; + struct smbcli_request *req; int i; int padding; + size_t space_left; size_t namelen = 0; - uint16_t data_disp, data_length, max_data; + DATA_BLOB params_chunk; + uint16_t ofs; + uint16_t params_ofs = 0; + DATA_BLOB data_chunk; + uint16_t data_ofs = 0; if (parms->in.params.length > UINT16_MAX || parms->in.data.length > UINT16_MAX) { @@ -229,37 +273,83 @@ struct smbcli_request *smb_raw_trans_send_backend(struct smbcli_tree *tree, else padding = 3; - req = smbcli_request_setup(tree, command, wct, padding); + req = smbcli_request_setup(tree, command, + 14 + parms->in.setup_count, + padding); if (!req) { return NULL; } + state = talloc_zero(req, struct smb_raw_trans2_recv_state); + if (!state) { + smbcli_request_destroy(req); + return NULL; + } + + state->command = command; + + /* make sure we don't leak data via the padding */ + memset(req->out.data, 0, padding); + /* Watch out, this changes the req->out.* pointers */ if (command == SMBtrans && parms->in.trans_name) { namelen = smbcli_req_append_string(req, parms->in.trans_name, STR_TERMINATE); } - /* fill in SMB parameters */ - outparam = req->out.data + padding; - outdata = outparam + parms->in.params.length; + ofs = PTR_DIFF(req->out.data,req->out.hdr)+padding+namelen; - /* make sure we don't leak data via the padding */ - memset(req->out.data, 0, padding); + /* see how much bytes of the params block we can ship in the first request */ + space_left = raw_trans_space_left(req); + + params_chunk.length = MIN(parms->in.params.length, space_left); + params_chunk.data = parms->in.params.data; + params_ofs = ofs; - data_length = parms->in.data.length; + state->params_left = parms->in.params.length - params_chunk.length; - max_data = smb_raw_max_trans_data(tree, parms->in.params.length); - if (max_data < data_length) { - data_length = max_data; + if (state->params_left > 0) { + /* we copy the whole params block, if needed we can optimize that latter */ + state->io.in.params = data_blob_talloc(state, NULL, parms->in.params.length); + if (!state->io.in.params.data) { + smbcli_request_destroy(req); + return NULL; + } + memcpy(state->io.in.params.data, + parms->in.params.data, + parms->in.params.length); } + /* see how much bytes of the data block we can ship in the first request */ + space_left -= params_chunk.length; + #if TORTURE_TRANS_DATA - if (data_length > 1) { - data_length /= 2; + if (space_left > 1) { + space_left /= 2; } #endif + data_chunk.length = MIN(parms->in.data.length, space_left); + data_chunk.data = parms->in.data.data; + data_ofs = params_ofs + params_chunk.length; + + state->data_left = parms->in.data.length - data_chunk.length; + + if (state->data_left > 0) { + /* we copy the whole params block, if needed we can optimize that latter */ + state->io.in.data = data_blob_talloc(state, NULL, parms->in.data.length); + if (!state->io.in.data.data) { + smbcli_request_destroy(req); + return NULL; + } + memcpy(state->io.in.data.data, + parms->in.data.data, + parms->in.data.length); + } + + state->params_total = parms->in.params.length; + state->data_total = parms->in.data.length; + /* primary request */ SSVAL(req->out.vwv,VWV(0),parms->in.params.length); SSVAL(req->out.vwv,VWV(1),parms->in.data.length); @@ -269,96 +359,135 @@ struct smbcli_request *smb_raw_trans_send_backend(struct smbcli_tree *tree, SSVAL(req->out.vwv,VWV(5),parms->in.flags); SIVAL(req->out.vwv,VWV(6),parms->in.timeout); SSVAL(req->out.vwv,VWV(8),0); /* reserved */ - SSVAL(req->out.vwv,VWV(9),parms->in.params.length); - SSVAL(req->out.vwv,VWV(10),PTR_DIFF(outparam,req->out.hdr)+namelen); - SSVAL(req->out.vwv,VWV(11),data_length); - SSVAL(req->out.vwv,VWV(12),PTR_DIFF(outdata,req->out.hdr)+namelen); + SSVAL(req->out.vwv,VWV(9),params_chunk.length); + SSVAL(req->out.vwv,VWV(10),params_ofs); + SSVAL(req->out.vwv,VWV(11),data_chunk.length); + SSVAL(req->out.vwv,VWV(12),data_ofs); SSVAL(req->out.vwv,VWV(13),parms->in.setup_count); for (i=0;iin.setup_count;i++) { - SSVAL(req->out.vwv,VWV(14)+i*2,parms->in.setup[i]); - } - if (parms->in.params.data) { - smbcli_req_append_blob(req, &parms->in.params); - } - if (parms->in.data.data) { - DATA_BLOB data; - data.data = parms->in.data.data; - data.length = data_length; - smbcli_req_append_blob(req, &data); + SSVAL(req->out.vwv,VWV(14)+VWV(i),parms->in.setup[i]); } + smbcli_req_append_blob(req, ¶ms_chunk); + smbcli_req_append_blob(req, &data_chunk); + + /* add the helper which will check that all multi-part replies are + in before an async client callack will be issued */ + req->recv_helper.fn = smb_raw_trans2_recv_helper; + req->recv_helper.private_data = state; if (!smbcli_request_send(req)) { smbcli_request_destroy(req); return NULL; } - data_disp = data_length; + return req; +} +static enum smbcli_request_state smb_raw_trans2_ship_next(struct smbcli_request *req, + struct smb_raw_trans2_recv_state *state) +{ + struct smbcli_request *req2; + size_t space_left; + DATA_BLOB params_chunk; + uint16_t ofs; + uint16_t params_ofs = 0; + uint16_t params_disp = 0; + DATA_BLOB data_chunk; + uint16_t data_ofs = 0; + uint16_t data_disp = 0; + uint8_t wct; - if (data_disp != parms->in.data.length) { - /* TODO: this should be done asynchronously .... */ - if (!smbcli_request_receive(req) || - !NT_STATUS_IS_OK(req->status)) { - return req; - } + if (state->command == SMBtrans2) { + wct = 9; + } else { + wct = 8; + } - req->state = SMBCLI_REQUEST_RECV; - DLIST_ADD(req->transport->pending_recv, req); + req2 = smbcli_request_setup(req->tree, state->command+1, wct, 0); + if (!req2) { + goto nomem; } + req2->mid = req->mid; + SSVAL(req2->out.hdr, HDR_MID, req2->mid); + ofs = PTR_DIFF(req2->out.data,req2->out.hdr); - while (data_disp != parms->in.data.length) { - data_length = parms->in.data.length - data_disp; + /* see how much bytes of the params block we can ship in the first request */ + space_left = raw_trans_space_left(req2); - max_data = smb_raw_max_trans_data(tree, 0); - if (max_data < data_length) { - data_length = max_data; - } + params_disp = state->io.in.params.length - state->params_left; + params_chunk.length = MIN(state->params_left, space_left); + params_chunk.data = state->io.in.params.data + params_disp; + params_ofs = ofs; + + state->params_left -= params_chunk.length; + + /* see how much bytes of the data block we can ship in the first request */ + space_left -= params_chunk.length; #if TORTURE_TRANS_DATA - if (data_length > 1) { - data_length /= 2; - } + if (space_left > 1) { + space_left /= 2; + } #endif - req2 = smbcli_request_setup(tree, command+1, 9, data_length); - if (!req2) { - return NULL; - } - req2->mid = req->mid; - SSVAL(req2->out.hdr, HDR_MID, req2->mid); - - outdata = req2->out.data; - - SSVAL(req2->out.vwv,VWV(0), parms->in.params.length); - SSVAL(req2->out.vwv,VWV(1), parms->in.data.length); - SSVAL(req2->out.vwv,VWV(2), 0); - SSVAL(req2->out.vwv,VWV(3), 0); - SSVAL(req2->out.vwv,VWV(4), 0); - SSVAL(req2->out.vwv,VWV(5), data_length); - SSVAL(req2->out.vwv,VWV(6), PTR_DIFF(outdata,req2->out.hdr)); - SSVAL(req2->out.vwv,VWV(7), data_disp); + data_disp = state->io.in.data.length - state->data_left; + data_chunk.length = MIN(state->data_left, space_left); + data_chunk.data = state->io.in.data.data + data_disp; + data_ofs = params_ofs+params_chunk.length; + + state->data_left -= data_chunk.length; + + SSVAL(req2->out.vwv,VWV(0), state->params_total); + SSVAL(req2->out.vwv,VWV(1), state->data_total); + SSVAL(req2->out.vwv,VWV(2), params_chunk.length); + SSVAL(req2->out.vwv,VWV(3), params_ofs); + SSVAL(req2->out.vwv,VWV(4), params_disp); + SSVAL(req2->out.vwv,VWV(5), data_chunk.length); + SSVAL(req2->out.vwv,VWV(6), data_ofs); + SSVAL(req2->out.vwv,VWV(7), data_disp); + if (wct == 9) { SSVAL(req2->out.vwv,VWV(8), 0xFFFF); + } - if (data_length != 0) { - memcpy(req2->out.data, parms->in.data.data + data_disp, - data_length); - } - - data_disp += data_length; + smbcli_req_append_blob(req2, ¶ms_chunk); + smbcli_req_append_blob(req2, &data_chunk); - req2->one_way_request = 1; + /* + * it's a one way request but we need + * the seq_num, so we destroy req2 by hand + */ + if (!smbcli_request_send(req2)) { + goto failed; + } - if (!smbcli_request_send(req2)) { - smbcli_request_destroy(req2); - return NULL; - } + req->seq_num = req2->seq_num; + smbcli_request_destroy(req2); + + return SMBCLI_REQUEST_RECV; - req->seq_num = req2->seq_num; +nomem: + req->status = NT_STATUS_NO_MEMORY; +failed: + if (req2) { + req->status = smbcli_request_destroy(req2); } - - - return req; + return SMBCLI_REQUEST_ERROR; +} + +static enum smbcli_request_state smb_raw_trans2_ship_rest(struct smbcli_request *req, + struct smb_raw_trans2_recv_state *state) +{ + enum smbcli_request_state ret = SMBCLI_REQUEST_ERROR; + + while (state->params_left > 0 || state->data_left > 0) { + ret = smb_raw_trans2_ship_next(req, state); + if (ret != SMBCLI_REQUEST_RECV) { + break; + } + } + + return ret; } -- cgit From fd1ce8c263adf84c665753bd7635d39d7ec533bc Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 4 Jul 2008 20:47:24 +0200 Subject: libcli/raw: remove unused smbcli_request_receive_more() function metze (This used to be commit e1d81388fcabba9a947ed0be9ccae875e2b19135) --- source4/libcli/raw/rawrequest.c | 13 ------------- 1 file changed, 13 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawrequest.c b/source4/libcli/raw/rawrequest.c index ef856c6ea1..a0e6452748 100644 --- a/source4/libcli/raw/rawrequest.c +++ b/source4/libcli/raw/rawrequest.c @@ -364,19 +364,6 @@ bool smbcli_request_receive(struct smbcli_request *req) } -/* - receive another reply to a request - this is used for requests that - have multi-part replies (such as SMBtrans2) -*/ -bool smbcli_request_receive_more(struct smbcli_request *req) -{ - req->state = SMBCLI_REQUEST_RECV; - DLIST_ADD(req->transport->pending_recv, req); - - return smbcli_request_receive(req); -} - - /* handle oplock break requests from the server - return true if the request was an oplock break -- cgit From 848ab7fa3be4c4fe2a103df365f0b6b41ee0736d Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 7 Jul 2008 14:00:09 +0200 Subject: libcli/raw: trans(2) setup count is uint8_t metze (This used to be commit 48ccb51caf7976ec07c8a9bfc1afd3076bf4ee22) --- source4/libcli/raw/rawtrans.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawtrans.c b/source4/libcli/raw/rawtrans.c index 9f5e1da293..fb5f9fa8d0 100644 --- a/source4/libcli/raw/rawtrans.c +++ b/source4/libcli/raw/rawtrans.c @@ -109,7 +109,7 @@ static enum smbcli_request_state smb_raw_trans2_recv_helper(struct smbcli_reques uint16_t param_count, param_ofs, param_disp; uint16_t data_count, data_ofs, data_disp; uint16_t total_data, total_param; - uint16_t setup_count; + uint8_t setup_count; /* * An NT RPC pipe call can return ERRDOS, ERRmoredata @@ -128,7 +128,7 @@ static enum smbcli_request_state smb_raw_trans2_recv_helper(struct smbcli_reques total_data = SVAL(req->in.vwv, VWV(1)); total_param = SVAL(req->in.vwv, VWV(0)); - setup_count = SVAL(req->in.vwv, VWV(9)); + setup_count = CVAL(req->in.vwv, VWV(9)); param_count = SVAL(req->in.vwv, VWV(3)); param_ofs = SVAL(req->in.vwv, VWV(4)); @@ -355,7 +355,8 @@ struct smbcli_request *smb_raw_trans_send_backend(struct smbcli_tree *tree, SSVAL(req->out.vwv,VWV(1),parms->in.data.length); SSVAL(req->out.vwv,VWV(2),parms->in.max_param); SSVAL(req->out.vwv,VWV(3),parms->in.max_data); - SSVAL(req->out.vwv,VWV(4),parms->in.max_setup); + SCVAL(req->out.vwv,VWV(4),parms->in.max_setup); + SCVAL(req->out.vwv,VWV(4)+1,0); /* reserved */ SSVAL(req->out.vwv,VWV(5),parms->in.flags); SIVAL(req->out.vwv,VWV(6),parms->in.timeout); SSVAL(req->out.vwv,VWV(8),0); /* reserved */ @@ -363,7 +364,8 @@ struct smbcli_request *smb_raw_trans_send_backend(struct smbcli_tree *tree, SSVAL(req->out.vwv,VWV(10),params_ofs); SSVAL(req->out.vwv,VWV(11),data_chunk.length); SSVAL(req->out.vwv,VWV(12),data_ofs); - SSVAL(req->out.vwv,VWV(13),parms->in.setup_count); + SCVAL(req->out.vwv,VWV(13),parms->in.setup_count); + SCVAL(req->out.vwv,VWV(13)+1,0); /* reserved */ for (i=0;iin.setup_count;i++) { SSVAL(req->out.vwv,VWV(14)+VWV(i),parms->in.setup[i]); } -- cgit From efaf4cedb27f6ffade8c5212919ff08602bd3e7a Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 7 Jul 2008 15:04:59 +0200 Subject: libcli/raw: make multi fragmented nttrans requests possible metze (This used to be commit a6aa055097313975299f214d8ebe8d45aa51d10a) --- source4/libcli/raw/rawtrans.c | 195 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 178 insertions(+), 17 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawtrans.c b/source4/libcli/raw/rawtrans.c index fb5f9fa8d0..7a90236c9c 100644 --- a/source4/libcli/raw/rawtrans.c +++ b/source4/libcli/raw/rawtrans.c @@ -537,6 +537,10 @@ _PUBLIC_ NTSTATUS smb_raw_trans(struct smbcli_tree *tree, } struct smb_raw_nttrans_recv_state { + uint32_t params_total; + uint32_t data_total; + uint32_t params_left; + uint32_t data_left; bool got_first; uint32_t recvd_data; uint32_t recvd_param; @@ -569,6 +573,9 @@ failed: return smbcli_request_destroy(req); } +static enum smbcli_request_state smb_raw_nttrans_ship_rest(struct smbcli_request *req, + struct smb_raw_nttrans_recv_state *state); + /* * This helper returns SMBCLI_REQUEST_RECV until all data has arrived */ @@ -599,6 +606,10 @@ static enum smbcli_request_state smb_raw_nttrans_recv_helper(struct smbcli_reque goto failed; } + if (state->params_left > 0 || state->data_left > 0) { + return smb_raw_nttrans_ship_rest(req, state); + } + /* this is the first packet of the response */ SMBCLI_CHECK_MIN_WCT(req, 18); @@ -716,7 +727,12 @@ struct smbcli_request *smb_raw_nttrans_send(struct smbcli_tree *tree, { struct smbcli_request *req; struct smb_raw_nttrans_recv_state *state; - uint8_t *outdata, *outparam; + uint32_t ofs; + size_t space_left; + DATA_BLOB params_chunk; + uint32_t params_ofs; + DATA_BLOB data_chunk; + uint32_t data_ofs; int align = 0; /* only align if there are parameters or data */ @@ -725,10 +741,7 @@ struct smbcli_request *smb_raw_nttrans_send(struct smbcli_tree *tree, } req = smbcli_request_setup(tree, SMBnttrans, - 19 + parms->in.setup_count, - align + - parms->in.params.length + - parms->in.data.length); + 19 + parms->in.setup_count, align); if (!req) { return NULL; } @@ -740,33 +753,81 @@ struct smbcli_request *smb_raw_nttrans_send(struct smbcli_tree *tree, } /* fill in SMB parameters */ - outparam = req->out.data + align; - outdata = outparam + parms->in.params.length; if (align != 0) { memset(req->out.data, 0, align); } + ofs = PTR_DIFF(req->out.data,req->out.hdr)+align; + + /* see how much bytes of the params block we can ship in the first request */ + space_left = raw_trans_space_left(req); + + params_chunk.length = MIN(parms->in.params.length, space_left); + params_chunk.data = parms->in.params.data; + params_ofs = ofs; + + state->params_left = parms->in.params.length - params_chunk.length; + + if (state->params_left > 0) { + /* we copy the whole params block, if needed we can optimize that latter */ + state->io.in.params = data_blob_talloc(state, NULL, parms->in.params.length); + if (!state->io.in.params.data) { + smbcli_request_destroy(req); + return NULL; + } + memcpy(state->io.in.params.data, + parms->in.params.data, + parms->in.params.length); + } + + /* see how much bytes of the data block we can ship in the first request */ + space_left -= params_chunk.length; + +#if TORTURE_TRANS_DATA + if (space_left > 1) { + space_left /= 2; + } +#endif + + data_chunk.length = MIN(parms->in.data.length, space_left); + data_chunk.data = parms->in.data.data; + data_ofs = params_ofs + params_chunk.length; + + state->data_left = parms->in.data.length - data_chunk.length; + + if (state->data_left > 0) { + /* we copy the whole params block, if needed we can optimize that latter */ + state->io.in.data = data_blob_talloc(state, NULL, parms->in.data.length); + if (!state->io.in.data.data) { + smbcli_request_destroy(req); + return NULL; + } + memcpy(state->io.in.data.data, + parms->in.data.data, + parms->in.data.length); + } + + state->params_total = parms->in.params.length; + state->data_total = parms->in.data.length; + SCVAL(req->out.vwv, 0, parms->in.max_setup); SSVAL(req->out.vwv, 1, 0); /* reserved */ SIVAL(req->out.vwv, 3, parms->in.params.length); SIVAL(req->out.vwv, 7, parms->in.data.length); SIVAL(req->out.vwv, 11, parms->in.max_param); SIVAL(req->out.vwv, 15, parms->in.max_data); - SIVAL(req->out.vwv, 19, parms->in.params.length); - SIVAL(req->out.vwv, 23, PTR_DIFF(outparam,req->out.hdr)); - SIVAL(req->out.vwv, 27, parms->in.data.length); - SIVAL(req->out.vwv, 31, PTR_DIFF(outdata,req->out.hdr)); + SIVAL(req->out.vwv, 19, params_chunk.length); + SIVAL(req->out.vwv, 23, params_ofs); + SIVAL(req->out.vwv, 27, data_chunk.length); + SIVAL(req->out.vwv, 31, data_ofs); SCVAL(req->out.vwv, 35, parms->in.setup_count); SSVAL(req->out.vwv, 36, parms->in.function); memcpy(req->out.vwv + VWV(19), parms->in.setup, sizeof(uint16_t) * parms->in.setup_count); - if (parms->in.params.length) { - memcpy(outparam, parms->in.params.data, parms->in.params.length); - } - if (parms->in.data.length) { - memcpy(outdata, parms->in.data.data, parms->in.data.length); - } + + smbcli_req_append_blob(req, ¶ms_chunk); + smbcli_req_append_blob(req, &data_chunk); /* add the helper which will check that all multi-part replies are in before an async client callack will be issued */ @@ -781,6 +842,106 @@ struct smbcli_request *smb_raw_nttrans_send(struct smbcli_tree *tree, return req; } +static enum smbcli_request_state smb_raw_nttrans_ship_next(struct smbcli_request *req, + struct smb_raw_nttrans_recv_state *state) +{ + struct smbcli_request *req2; + size_t space_left; + DATA_BLOB params_chunk; + uint32_t ofs; + uint32_t params_ofs = 0; + uint32_t params_disp = 0; + DATA_BLOB data_chunk; + uint32_t data_ofs = 0; + uint32_t data_disp = 0; + + req2 = smbcli_request_setup(req->tree, SMBnttranss, 18, 0); + if (!req2) { + goto nomem; + } + req2->mid = req->mid; + SSVAL(req2->out.hdr, HDR_MID, req2->mid); + + ofs = PTR_DIFF(req2->out.data,req2->out.hdr); + + /* see how much bytes of the params block we can ship in the first request */ + space_left = raw_trans_space_left(req2); + + params_disp = state->io.in.params.length - state->params_left; + params_chunk.length = MIN(state->params_left, space_left); + params_chunk.data = state->io.in.params.data + params_disp; + params_ofs = ofs; + + state->params_left -= params_chunk.length; + + /* see how much bytes of the data block we can ship in the first request */ + space_left -= params_chunk.length; + +#if TORTURE_TRANS_DATA + if (space_left > 1) { + space_left /= 2; + } +#endif + + data_disp = state->io.in.data.length - state->data_left; + data_chunk.length = MIN(state->data_left, space_left); + data_chunk.data = state->io.in.data.data + data_disp; + data_ofs = params_ofs+params_chunk.length; + + state->data_left -= data_chunk.length; + + SSVAL(req2->out.vwv,0, 0); /* reserved */ + SCVAL(req2->out.vwv,2, 0); /* reserved */ + SIVAL(req2->out.vwv,3, state->params_total); + SIVAL(req2->out.vwv,7, state->data_total); + SIVAL(req2->out.vwv,11, params_chunk.length); + SIVAL(req2->out.vwv,15, params_ofs); + SIVAL(req2->out.vwv,19, params_disp); + SIVAL(req2->out.vwv,23, data_chunk.length); + SIVAL(req2->out.vwv,27, data_ofs); + SIVAL(req2->out.vwv,31, data_disp); + SCVAL(req2->out.vwv,35, 0); /* reserved */ + + smbcli_req_append_blob(req2, ¶ms_chunk); + smbcli_req_append_blob(req2, &data_chunk); + + /* + * it's a one way request but we need + * the seq_num, so we destroy req2 by hand + */ + if (!smbcli_request_send(req2)) { + goto failed; + } + + req->seq_num = req2->seq_num; + smbcli_request_destroy(req2); + + return SMBCLI_REQUEST_RECV; + +nomem: + req->status = NT_STATUS_NO_MEMORY; +failed: + if (req2) { + req->status = smbcli_request_destroy(req2); + } + return SMBCLI_REQUEST_ERROR; +} + +static enum smbcli_request_state smb_raw_nttrans_ship_rest(struct smbcli_request *req, + struct smb_raw_nttrans_recv_state *state) +{ + enum smbcli_request_state ret = SMBCLI_REQUEST_ERROR; + + while (state->params_left > 0 || state->data_left > 0) { + ret = smb_raw_nttrans_ship_next(req, state); + if (ret != SMBCLI_REQUEST_RECV) { + break; + } + } + + return ret; +} + /**************************************************************************** receive a SMB nttrans response allocating the necessary memory -- cgit From 997f539bf568f555f9e7a7f51de23cd13c732b1c Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 7 Jul 2008 16:34:36 +0200 Subject: libcli/raw: remove unused smb_raw_max_trans_data() function metze (This used to be commit d235ce673705641e06b4ad5f5679e146b59a19e1) --- source4/libcli/raw/rawtrans.c | 12 ------------ 1 file changed, 12 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/rawtrans.c b/source4/libcli/raw/rawtrans.c index 7a90236c9c..2f529863dc 100644 --- a/source4/libcli/raw/rawtrans.c +++ b/source4/libcli/raw/rawtrans.c @@ -959,15 +959,3 @@ NTSTATUS smb_raw_nttrans(struct smbcli_tree *tree, return smb_raw_nttrans_recv(req, mem_ctx, parms); } - -/* - work out the maximum data size for a trans request while avoiding - multi-part replies - - TODO: we only need to avoid multi-part replies because the - multi-part trans receive code is broken. -*/ -_PUBLIC_ size_t smb_raw_max_trans_data(struct smbcli_tree *tree, size_t param_size) -{ - return tree->session->transport->negotiate.max_xmit - (70 + param_size); -} -- cgit From e92125e6319d49185a3d0456a8a0e5c1b8d364e7 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 16 Jul 2008 14:00:18 +1000 Subject: Ignore and handle more NT Create & X options. The MS-SMB document explains that some of these options should be ignored. The test proves it. /* Must be ignored by the server, per MS-SMB 2.2.8 */ /* Must be ignored by the server, per MS-SMB 2.2.8 */ If we implement HSM in samba4 (likely) we should honour this bit. /* Don't pull this file off tape in a HSM system */ Andrew Bartlett (This used to be commit 502739ff90d56d2c9aabe8e224317f6ceb175c17) --- source4/libcli/raw/smb.h | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/smb.h b/source4/libcli/raw/smb.h index 5a92b99757..f54e979de2 100644 --- a/source4/libcli/raw/smb.h +++ b/source4/libcli/raw/smb.h @@ -156,15 +156,20 @@ #define NTCREATEX_OPTIONS_DELETE_ON_CLOSE 0x1000 #define NTCREATEX_OPTIONS_OPEN_BY_FILE_ID 0x2000 #define NTCREATEX_OPTIONS_BACKUP_INTENT 0x4000 -#define NTCREATEX_OPTIONS_REPARSE_POINT 0x200000 -#define NTCREATEX_OPTIONS_UNKNOWN_400000 0x400000 +/* Must be ignored by the server, per MS-SMB 2.2.8 */ +#define NTCREATEX_OPTIONS_OPFILTER 0x00100000 +#define NTCREATEX_OPTIONS_REPARSE_POINT 0x00200000 +/* Don't pull this file off tape in a HSM system */ +#define NTCREATEX_OPTIONS_NO_RECALL 0x00400000 +/* Must be ignored by the server, per MS-SMB 2.2.8 */ +#define NTCREATEX_OPTIONS_FREE_SPACE_QUERY 0x00800000 /* create options these bits are for private use by backends, they are not valid on the wire */ #define NTCREATEX_OPTIONS_PRIVATE_MASK 0xFF000000 #define NTCREATEX_OPTIONS_PRIVATE_DENY_DOS 0x01000000 #define NTCREATEX_OPTIONS_PRIVATE_DENY_FCB 0x02000000 -#define NTCREATEX_OPTIONS_NOT_SUPPORTED_MASK 0x00DFA188 +#define NTCREATEX_OPTIONS_NOT_SUPPORTED_MASK 0x000FA188 -- cgit From 853194c308a0f2171808b78b17aed50c5fab1b3b Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 18 Jul 2008 18:40:19 +1000 Subject: More 'must be ignored' options from the MS-SMB doc. Also in particular the 'sync' flags (which Samba has traditionally ignored). Thanks to Olivier Salamin for pointing out more flags that needed to be handled. Andrew Bartlett (This used to be commit 370bb39cd79fe49efd36a1ceb3e896d386e6d3ce) --- source4/libcli/raw/smb.h | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/smb.h b/source4/libcli/raw/smb.h index f54e979de2..8663792f78 100644 --- a/source4/libcli/raw/smb.h +++ b/source4/libcli/raw/smb.h @@ -144,32 +144,38 @@ #define NTCREATEX_DISP_OVERWRITE_IF 5 /* if exists overwrite, else create */ /* ntcreatex create_options field */ -#define NTCREATEX_OPTIONS_DIRECTORY 0x0001 -#define NTCREATEX_OPTIONS_WRITE_THROUGH 0x0002 -#define NTCREATEX_OPTIONS_SEQUENTIAL_ONLY 0x0004 -#define NTCREATEX_OPTIONS_SYNC_ALERT 0x0010 -#define NTCREATEX_OPTIONS_ASYNC_ALERT 0x0020 -#define NTCREATEX_OPTIONS_NON_DIRECTORY_FILE 0x0040 -#define NTCREATEX_OPTIONS_NO_EA_KNOWLEDGE 0x0200 -#define NTCREATEX_OPTIONS_EIGHT_DOT_THREE_ONLY 0x0400 -#define NTCREATEX_OPTIONS_RANDOM_ACCESS 0x0800 -#define NTCREATEX_OPTIONS_DELETE_ON_CLOSE 0x1000 -#define NTCREATEX_OPTIONS_OPEN_BY_FILE_ID 0x2000 -#define NTCREATEX_OPTIONS_BACKUP_INTENT 0x4000 +#define NTCREATEX_OPTIONS_DIRECTORY 0x0001 +#define NTCREATEX_OPTIONS_WRITE_THROUGH 0x0002 +#define NTCREATEX_OPTIONS_SEQUENTIAL_ONLY 0x0004 +#define NTCREATEX_OPTIONS_NO_INTERMEDIATE_BUFFERING 0x0008 +#define NTCREATEX_OPTIONS_SYNC_ALERT 0x0010 +#define NTCREATEX_OPTIONS_ASYNC_ALERT 0x0020 +#define NTCREATEX_OPTIONS_NON_DIRECTORY_FILE 0x0040 +#define NTCREATEX_OPTIONS_TREE_CONNECTION 0x0080 +#define NTCREATEX_OPTIONS_COMPLETE_IF_OPLOCKED 0x0100 +#define NTCREATEX_OPTIONS_NO_EA_KNOWLEDGE 0x0200 +#define NTCREATEX_OPTIONS_OPEN_FOR_RECOVERY 0x0400 +#define NTCREATEX_OPTIONS_RANDOM_ACCESS 0x0800 +#define NTCREATEX_OPTIONS_DELETE_ON_CLOSE 0x1000 +#define NTCREATEX_OPTIONS_OPEN_BY_FILE_ID 0x2000 +#define NTCREATEX_OPTIONS_BACKUP_INTENT 0x4000 +#define NTCREATEX_OPTIONS_NO_COMPRESSION 0x8000 /* Must be ignored by the server, per MS-SMB 2.2.8 */ -#define NTCREATEX_OPTIONS_OPFILTER 0x00100000 -#define NTCREATEX_OPTIONS_REPARSE_POINT 0x00200000 +#define NTCREATEX_OPTIONS_OPFILTER 0x00100000 +#define NTCREATEX_OPTIONS_REPARSE_POINT 0x00200000 /* Don't pull this file off tape in a HSM system */ -#define NTCREATEX_OPTIONS_NO_RECALL 0x00400000 +#define NTCREATEX_OPTIONS_NO_RECALL 0x00400000 /* Must be ignored by the server, per MS-SMB 2.2.8 */ -#define NTCREATEX_OPTIONS_FREE_SPACE_QUERY 0x00800000 +#define NTCREATEX_OPTIONS_FREE_SPACE_QUERY 0x00800000 /* create options these bits are for private use by backends, they are not valid on the wire */ -#define NTCREATEX_OPTIONS_PRIVATE_MASK 0xFF000000 -#define NTCREATEX_OPTIONS_PRIVATE_DENY_DOS 0x01000000 -#define NTCREATEX_OPTIONS_PRIVATE_DENY_FCB 0x02000000 +#define NTCREATEX_OPTIONS_PRIVATE_MASK 0xFF000000 +#define NTCREATEX_OPTIONS_PRIVATE_DENY_DOS 0x01000000 +#define NTCREATEX_OPTIONS_PRIVATE_DENY_FCB 0x02000000 -#define NTCREATEX_OPTIONS_NOT_SUPPORTED_MASK 0x000FA188 +#define NTCREATEX_OPTIONS_MUST_IGNORE_MASK ( NTCREATEX_OPTIONS_TREE_CONNECTION | NTCREATEX_OPTIONS_COMPLETE_IF_OPLOCKED | NTCREATEX_OPTIONS_OPEN_FOR_RECOVERY | NTCREATEX_OPTIONS_FREE_SPACE_QUERY | NTCREATEX_OPTIONS_OPFILTER ) + +#define NTCREATEX_OPTIONS_NOT_SUPPORTED_MASK (0x000F0000 | NTCREATEX_OPTIONS_OPEN_BY_FILE_ID) -- cgit From dbcdbb33485b034b48b32e4801a538bbc239d1c2 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 14 Aug 2008 12:44:25 +0200 Subject: libcli/raw: fix the special NTCREATE_OPTIONS_*_MASK values We now reuse ignored values for the ntvfs backend private flags. metze (This used to be commit 14eda93aeface307e1ffd1ea012d8f236fa78290) --- source4/libcli/raw/smb.h | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/smb.h b/source4/libcli/raw/smb.h index 8663792f78..d4091acf48 100644 --- a/source4/libcli/raw/smb.h +++ b/source4/libcli/raw/smb.h @@ -167,17 +167,30 @@ #define NTCREATEX_OPTIONS_NO_RECALL 0x00400000 /* Must be ignored by the server, per MS-SMB 2.2.8 */ #define NTCREATEX_OPTIONS_FREE_SPACE_QUERY 0x00800000 -/* create options these bits are for private use by backends, they are - not valid on the wire */ -#define NTCREATEX_OPTIONS_PRIVATE_MASK 0xFF000000 -#define NTCREATEX_OPTIONS_PRIVATE_DENY_DOS 0x01000000 -#define NTCREATEX_OPTIONS_PRIVATE_DENY_FCB 0x02000000 -#define NTCREATEX_OPTIONS_MUST_IGNORE_MASK ( NTCREATEX_OPTIONS_TREE_CONNECTION | NTCREATEX_OPTIONS_COMPLETE_IF_OPLOCKED | NTCREATEX_OPTIONS_OPEN_FOR_RECOVERY | NTCREATEX_OPTIONS_FREE_SPACE_QUERY | NTCREATEX_OPTIONS_OPFILTER ) +#define NTCREATEX_OPTIONS_MUST_IGNORE_MASK (NTCREATEX_OPTIONS_TREE_CONNECTION | \ + NTCREATEX_OPTIONS_OPEN_FOR_RECOVERY | \ + NTCREATEX_OPTIONS_FREE_SPACE_QUERY | \ + 0x000F0000) -#define NTCREATEX_OPTIONS_NOT_SUPPORTED_MASK (0x000F0000 | NTCREATEX_OPTIONS_OPEN_BY_FILE_ID) +#define NTCREATEX_OPTIONS_NOT_SUPPORTED_MASK (NTCREATEX_OPTIONS_OPEN_BY_FILE_ID) +#define NTCREATEX_OPTIONS_INVALID_PARAM_MASK (NTCREATEX_OPTIONS_OPFILTER | \ + NTCREATEX_OPTIONS_SYNC_ALERT | \ + NTCREATEX_OPTIONS_ASYNC_ALERT | \ + NTCREATEX_OPTIONS_OPFILTER | \ + 0xFF000000) +/* + * We reuse some ignored flags for private use. + * This values have different meaning for some ntvfs backends. + * + * TODO: use values that are ignore for sure... + */ +#define NTCREATEX_OPTIONS_PRIVATE_DENY_DOS 0x00010000 +#define NTCREATEX_OPTIONS_PRIVATE_DENY_FCB 0x00020000 +#define NTCREATEX_OPTIONS_PRIVATE_MASK (NTCREATEX_OPTIONS_PRIVATE_DENY_DOS | \ + NTCREATEX_OPTIONS_PRIVATE_DENY_FCB) /* ntcreatex impersonation field */ #define NTCREATEX_IMPERSONATION_ANONYMOUS 0 -- cgit From d104a706d1adb5d75abd05a9a3f938385eefc5d4 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 6 Sep 2008 09:07:41 +1000 Subject: Make SMB signing work with Windows 2008 and kerberos. Pinched from b53e6387e30010509034835acf88b91b380ff44a by metze. Andrew Bartlett (This used to be commit d55602e23e7947462cb402b20b2d354b96aa7ba3) --- source4/libcli/raw/smb_signing.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'source4/libcli/raw') diff --git a/source4/libcli/raw/smb_signing.c b/source4/libcli/raw/smb_signing.c index 97bb688d1a..1d03686d9a 100644 --- a/source4/libcli/raw/smb_signing.c +++ b/source4/libcli/raw/smb_signing.c @@ -263,7 +263,6 @@ bool smbcli_set_signing_off(struct smb_signing_context *sign_info) { DEBUG(5, ("Shutdown SMB signing\n")); sign_info->doing_signing = false; - sign_info->next_seq_num = 0; data_blob_free(&sign_info->mac_key); sign_info->signing_state = SMB_SIGNING_ENGINE_OFF; return true; @@ -350,9 +349,6 @@ bool smbcli_simple_set_signing(TALLOC_CTX *mem_ctx, dump_data_pw("Started Signing with key:\n", sign_info->mac_key.data, sign_info->mac_key.length); - /* Initialise the sequence number */ - sign_info->next_seq_num = 0; - sign_info->signing_state = SMB_SIGNING_ENGINE_ON; return true; @@ -379,6 +375,7 @@ bool smbcli_transport_simple_set_signing(struct smbcli_transport *transport, bool smbcli_init_signing(struct smbcli_transport *transport) { + transport->negotiate.sign_info.next_seq_num = 0; transport->negotiate.sign_info.mac_key = data_blob(NULL, 0); if (!smbcli_set_signing_off(&transport->negotiate.sign_info)) { return false; -- cgit