From ebe7c7a173efa32057908af43a5c3d74d8b3739a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 24 Nov 1997 13:44:52 +0000 Subject: added cli_rmdir and cli_mkdir added test in smbtorture for the server updating the directory modify time when a file is added to a directory cleanup in smbtorture so no garbage files are left on the server (This used to be commit 3a5e07f1e994396853e6340e8ef3f4d12bb0243e) --- source3/include/proto.h | 5 ++++ source3/libsmb/clientgen.c | 66 +++++++++++++++++++++++++++++++++++++++++++++- source3/utils/torture.c | 49 ++++++++++++++++++++++++++++++---- 3 files changed, 114 insertions(+), 6 deletions(-) (limited to 'source3') diff --git a/source3/include/proto.h b/source3/include/proto.h index a9ccda3b4a..1b8d5be141 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -66,6 +66,8 @@ BOOL cli_send_tconX(struct cli_state *cli, char *share, char *dev, char *pass, int passlen); BOOL cli_tdis(struct cli_state *cli); BOOL cli_unlink(struct cli_state *cli, char *fname); +BOOL cli_mkdir(struct cli_state *cli, char *dname); +BOOL cli_rmdir(struct cli_state *cli, char *dname); int cli_open(struct cli_state *cli, char *fname, int flags, int share_mode); BOOL cli_close(struct cli_state *cli, int fnum); BOOL cli_lock(struct cli_state *cli, int fnum, uint32 offset, uint32 len, int timeout); @@ -77,6 +79,9 @@ BOOL cli_getatr(struct cli_state *cli, char *fname, 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_qpathinfo2(struct cli_state *cli, char *fname, + time_t *c_time, time_t *a_time, time_t *m_time, + time_t *w_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); diff --git a/source3/libsmb/clientgen.c b/source3/libsmb/clientgen.c index 89557905fc..1bd55cffe8 100644 --- a/source3/libsmb/clientgen.c +++ b/source3/libsmb/clientgen.c @@ -594,7 +594,71 @@ BOOL cli_unlink(struct cli_state *cli, char *fname) p = smb_buf(cli->outbuf); *p++ = 4; strcpy(p,fname); - p = skip_string(p,1); + + send_smb(cli->fd,cli->outbuf); + if (!receive_smb(cli->fd,cli->inbuf,cli->timeout)) { + return False; + } + + if (CVAL(cli->inbuf,smb_rcls) != 0) { + return False; + } + + return True; +} + + +/**************************************************************************** +create a directory +****************************************************************************/ +BOOL cli_mkdir(struct cli_state *cli, char *dname) +{ + char *p; + + bzero(cli->outbuf,smb_size); + bzero(cli->inbuf,smb_size); + + set_message(cli->outbuf,0, 2 + strlen(dname),True); + + CVAL(cli->outbuf,smb_com) = SMBmkdir; + SSVAL(cli->outbuf,smb_tid,cli->cnum); + cli_setup_packet(cli); + + p = smb_buf(cli->outbuf); + *p++ = 4; + strcpy(p,dname); + + send_smb(cli->fd,cli->outbuf); + if (!receive_smb(cli->fd,cli->inbuf,cli->timeout)) { + return False; + } + + if (CVAL(cli->inbuf,smb_rcls) != 0) { + return False; + } + + return True; +} + +/**************************************************************************** +remove a directory +****************************************************************************/ +BOOL cli_rmdir(struct cli_state *cli, char *dname) +{ + char *p; + + bzero(cli->outbuf,smb_size); + bzero(cli->inbuf,smb_size); + + set_message(cli->outbuf,0, 2 + strlen(dname),True); + + CVAL(cli->outbuf,smb_com) = SMBrmdir; + SSVAL(cli->outbuf,smb_tid,cli->cnum); + cli_setup_packet(cli); + + p = smb_buf(cli->outbuf); + *p++ = 4; + strcpy(p,dname); send_smb(cli->fd,cli->outbuf); if (!receive_smb(cli->fd,cli->inbuf,cli->timeout)) { diff --git a/source3/utils/torture.c b/source3/utils/torture.c index d1bd6e5f00..8711af3fe1 100644 --- a/source3/utils/torture.c +++ b/source3/utils/torture.c @@ -172,6 +172,9 @@ static BOOL rw_torture(struct cli_state *c, int numops) } } + cli_close(c, fnum2); + cli_unlink(c, lockfname); + printf("%d\n", i); return True; @@ -587,6 +590,9 @@ static void run_unlinktest(void) printf("error: server allowed unlink on an open file\n"); } + cli_close(&cli, fnum); + cli_unlink(&cli, fname); + close_connection(&cli); printf("unlink test finished\n"); @@ -608,7 +614,7 @@ static void run_browsetest(void) { static struct cli_state cli; - printf("staring browse test\n"); + printf("starting browse test\n"); if (!open_connection(&cli)) { return; @@ -640,7 +646,7 @@ static void run_attrtest(void) time_t t, t2; char *fname = "\\attrib.tst"; - printf("staring attrib test\n"); + printf("starting attrib test\n"); if (!open_connection(&cli)) { return; @@ -676,6 +682,8 @@ static void run_attrtest(void) printf("%s", ctime(&t2)); } + cli_unlink(&cli, fname); + close_connection(&cli); printf("attrib test finished\n"); @@ -690,10 +698,12 @@ static void run_trans2test(void) static struct cli_state cli; int fnum; uint32 size; - time_t c_time, a_time, m_time, w_time; + time_t c_time, a_time, m_time, w_time, m_time2; char *fname = "\\trans2.tst"; + char *dname = "\\trans2"; + char *fname2 = "\\trans2\\trans2.tst"; - printf("staring trans2 test\n"); + printf("starting trans2 test\n"); if (!open_connection(&cli)) { return; @@ -727,7 +737,7 @@ static void run_trans2test(void) printf("This system appears to set a midnight access time\n"); } - if (abs(m_time - time(NULL)) > 60) { + if (abs(m_time - time(NULL)) > 60*60*24*7) { printf("ERROR: totally incorrect times - maybe word reversed?\n"); } } @@ -747,6 +757,35 @@ static void run_trans2test(void) } } + cli_unlink(&cli, fname); + + + /* check if the server updates the directory modification time + when creating a new file */ + if (!cli_mkdir(&cli, dname)) { + printf("ERROR: mkdir failed (%s)\n", cli_errstr(&cli)); + } + sleep(3); + if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time, + &w_time, &size)) { + printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli)); + } + + fnum = cli_open(&cli, fname2, + O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); + cli_write(&cli, fnum, (char *)&fnum, 0, sizeof(fnum)); + cli_close(&cli, fnum); + if (!cli_qpathinfo2(&cli, "\\trans2\\", &c_time, &a_time, &m_time2, + &w_time, &size)) { + printf("ERROR: qpathinfo2 failed (%s)\n", cli_errstr(&cli)); + } else { + if (m_time2 == m_time) + printf("This system does not update directory modification times\n"); + } + cli_unlink(&cli, fname2); + cli_rmdir(&cli, dname); + + close_connection(&cli); printf("trans2 test finished\n"); -- cgit