diff options
-rw-r--r-- | source3/include/proto.h | 4 | ||||
-rw-r--r-- | source3/include/trans2.h | 7 | ||||
-rw-r--r-- | source3/libsmb/clientgen.c | 116 | ||||
-rw-r--r-- | source3/utils/torture.c | 59 |
4 files changed, 174 insertions, 12 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h index 1e8c33be15..a9ccda3b4a 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -75,6 +75,10 @@ int cli_write(struct cli_state *cli, int fnum, char *buf, uint32 offset, uint16 BOOL cli_getatr(struct cli_state *cli, char *fname, int *attr, uint32 *size, time_t *t); BOOL cli_setatr(struct cli_state *cli, char *fname, int attr, time_t t); +BOOL cli_qpathinfo(struct cli_state *cli, char *fname, + time_t *c_time, time_t *a_time, time_t *m_time, uint32 *size); +BOOL cli_qfileinfo(struct cli_state *cli, int fnum, + time_t *c_time, time_t *a_time, time_t *m_time, uint32 *size); BOOL cli_negprot(struct cli_state *cli); BOOL cli_session_request(struct cli_state *cli, char *host, int name_type, char *myname); diff --git a/source3/include/trans2.h b/source3/include/trans2.h index 9a2de63109..5218604e0e 100644 --- a/source3/include/trans2.h +++ b/source3/include/trans2.h @@ -238,13 +238,6 @@ Byte offset Type name description #define NT_FILE_ATTRIBUTE_NORMAL 0x80 -/* Function prototypes */ - - -int reply_findnclose(char *inbuf,char *outbuf,int length,int bufsize); - -int reply_findclose(char *inbuf,char *outbuf,int length,int bufsize); - #endif diff --git a/source3/libsmb/clientgen.c b/source3/libsmb/clientgen.c index 39d1226f9d..7060467aee 100644 --- a/source3/libsmb/clientgen.c +++ b/source3/libsmb/clientgen.c @@ -24,6 +24,7 @@ #endif #include "includes.h" +#include "trans2.h" extern int DEBUGLEVEL; @@ -57,8 +58,8 @@ static BOOL cli_send_trans(struct cli_state *cli, char *outdata,*outparam; char *p; - this_lparam = MIN(lparam,cli->max_xmit - (500+lsetup*SIZEOFWORD)); /* hack */ - this_ldata = MIN(ldata,cli->max_xmit - (500+lsetup*SIZEOFWORD+this_lparam)); + this_lparam = MIN(lparam,cli->max_xmit - (500+lsetup*2)); /* hack */ + this_ldata = MIN(ldata,cli->max_xmit - (500+lsetup*2+this_lparam)); bzero(cli->outbuf,smb_size); set_message(cli->outbuf,14+lsetup,0,True); @@ -83,7 +84,7 @@ static BOOL cli_send_trans(struct cli_state *cli, SSVAL(cli->outbuf,smb_dsoff,smb_offset(outdata,cli->outbuf)); /* dsoff */ SCVAL(cli->outbuf,smb_suwcnt,lsetup); /* suwcnt */ for (i=0;i<lsetup;i++) /* setup[] */ - SSVAL(cli->outbuf,smb_setup+i*SIZEOFWORD,setup[i]); + SSVAL(cli->outbuf,smb_setup+i*2,setup[i]); p = smb_buf(cli->outbuf); if (trans==SMBtrans) { strcpy(p,name); /* name[] */ @@ -131,7 +132,7 @@ static BOOL cli_send_trans(struct cli_state *cli, SSVAL(cli->outbuf,smb_sdsoff,smb_offset(outdata,cli->outbuf)); /* dsoff */ SSVAL(cli->outbuf,smb_sdsdisp,tot_data); /* dsdisp */ if (trans==SMBtrans2) - SSVAL(cli->outbuf,smb_sfid,fid); /* fid */ + SSVALS(cli->outbuf,smb_sfid,fid); /* fid */ if (this_lparam) /* param[] */ memcpy(outparam,param,this_lparam); if (this_ldata) /* data[] */ @@ -243,7 +244,7 @@ static BOOL cli_api(struct cli_state *cli, int *rdrcnt, char *param,char *data, char **rparam, char **rdata) { - cli_send_trans(cli,SMBtrans,"\\PIPE\\LANMAN",0,0, + cli_send_trans(cli,SMBtrans,PIPE_LANMAN,0,0, data,param,NULL, drcnt,prcnt,0, mdrcnt,mprcnt,0); @@ -942,6 +943,111 @@ BOOL cli_setatr(struct cli_state *cli, char *fname, int attr, time_t t) return True; } +/**************************************************************************** +send a qpathinfo call +****************************************************************************/ +BOOL cli_qpathinfo(struct cli_state *cli, char *fname, + time_t *c_time, time_t *a_time, time_t *m_time, uint32 *size) +{ + int data_len = 0; + int param_len = 0; + uint16 setup = TRANSACT2_QPATHINFO; + pstring param; + char *rparam=NULL, *rdata=NULL; + + param_len = strlen(fname) + 7; + + memset(param, 0, param_len); + SSVAL(param, 0, SMB_INFO_STANDARD); + pstrcpy(¶m[6], fname); + + if (!cli_send_trans(cli, SMBtrans2, NULL, -1, 0, + NULL, param, &setup, + data_len, param_len, 1, + cli->max_xmit, 10, 0)) { + return False; + } + + if (!cli_receive_trans(cli, SMBtrans2, &data_len, ¶m_len, + &rdata, &rparam)) { + return False; + } + + if (!rdata || data_len < 22) { + return False; + } + + if (c_time) { + *c_time = make_unix_date2(rdata+0); + } + if (a_time) { + *a_time = make_unix_date2(rdata+4); + } + if (m_time) { + *m_time = make_unix_date2(rdata+8); + } + if (size) { + *size = IVAL(rdata, 12); + } + + if (rdata) free(rdata); + if (rparam) free(rparam); + return True; +} + + +/**************************************************************************** +send a qfileinfo call +****************************************************************************/ +BOOL cli_qfileinfo(struct cli_state *cli, int fnum, + time_t *c_time, time_t *a_time, time_t *m_time, uint32 *size) +{ + int data_len = 0; + int param_len = 0; + uint16 setup = TRANSACT2_QFILEINFO; + pstring param; + char *rparam=NULL, *rdata=NULL; + + param_len = 4; + + memset(param, 0, param_len); + SSVAL(param, 0, fnum); + SSVAL(param, 2, SMB_INFO_STANDARD); + + if (!cli_send_trans(cli, SMBtrans2, NULL, -1, 0, + NULL, param, &setup, + data_len, param_len, 1, + cli->max_xmit, 2, 0)) { + return False; + } + + if (!cli_receive_trans(cli, SMBtrans2, &data_len, ¶m_len, + &rdata, &rparam)) { + return False; + } + + if (!rdata || data_len < 22) { + return False; + } + + if (c_time) { + *c_time = make_unix_date2(rdata+0); + } + if (a_time) { + *a_time = make_unix_date2(rdata+4); + } + if (m_time) { + *m_time = make_unix_date2(rdata+8); + } + if (size) { + *size = IVAL(rdata, 12); + } + + if (rdata) free(rdata); + if (rparam) free(rparam); + return True; +} + /**************************************************************************** send a negprot command diff --git a/source3/utils/torture.c b/source3/utils/torture.c index d5258d2d6a..fc6d5bcc15 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -682,6 +682,64 @@ static void run_attrtest(void) } +/* + This checks a couple of trans2 calls +*/ +static void run_trans2test(void) +{ + static struct cli_state cli; + int fnum; + uint32 size; + time_t c_time, a_time, m_time; + char *fname = "\\trans2.tst"; + + printf("staring trans2 test\n"); + + if (!open_connection(&cli)) { + return; + } + + cli_unlink(&cli, fname); + fnum = cli_open(&cli, fname, + O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); + if (!cli_qfileinfo(&cli, fnum, &c_time, &a_time, &m_time, &size)) { + printf("ERROR: qfileinfo failed (%s)\n", cli_errstr(&cli)); + } + cli_close(&cli, fnum); + + sleep(2); + + cli_unlink(&cli, fname); + fnum = cli_open(&cli, fname, + O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); + cli_close(&cli, fnum); + + if (!cli_qpathinfo(&cli, fname, &c_time, &a_time, &m_time, &size)) { + printf("ERROR: qpathinfo failed (%s)\n", cli_errstr(&cli)); + } else { + if (c_time != m_time) { + printf("create time=%s", ctime(&c_time)); + printf("modify time=%s", ctime(&m_time)); + printf("This system appears to have sticky create times\n"); + } + if (a_time % (60*60) == 0) { + printf("access time=%s", ctime(&a_time)); + printf("This system appears to set a midnight access time\n"); + } + + if (abs(m_time - time(NULL)) > 60) { + printf("ERROR: totally incorrect times - maybe word reversed?\n"); + } + } + + cli_unlink(&cli, fname); + + close_connection(&cli); + + printf("trans2 test finished\n"); +} + + static void create_procs(int nprocs, int numops) { int i, status; @@ -801,6 +859,7 @@ static void create_procs(int nprocs, int numops) run_unlinktest(); run_browsetest(); run_attrtest(); + run_trans2test(); return(0); } |