added some QPATHINFO and QFILEINFO tests into smbtorture.
authorAndrew Tridgell <tridge@samba.org>
Sun, 23 Nov 1997 05:55:44 +0000 (05:55 +0000)
committerAndrew Tridgell <tridge@samba.org>
Sun, 23 Nov 1997 05:55:44 +0000 (05:55 +0000)
This tests for things like midnight access times, sticky create times
and word reversed INFO_STANDARD returns
(This used to be commit 89141de14edf9e46ab279d2a74a9b026716a0ba8)

source3/include/proto.h
source3/include/trans2.h
source3/libsmb/clientgen.c
source3/utils/torture.c

index 1e8c33be15770e9716d8f4fa5b16ded349607f5b..a9ccda3b4a1493b7c73a83e4675b78449bd447a9 100644 (file)
@@ -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);
index 9a2de6310955533948d5c938faf7f023e629be85..5218604e0e1aaacf0b84a39e1df9083afc58de69 100644 (file)
@@ -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
 
 
index 39d1226f9d90ef4b7e493bd34fff95108b2a195a..7060467aee3866db8e459073181b68e00e974230 100644 (file)
@@ -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(&param[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, &param_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, &param_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
index d5258d2d6ab35eee8ba1a6b1d4d548976c99e382..fc6d5bcc151c8da4fd1c672450272c924ca44084 100644 (file)
@@ -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);
 }