1
0
mirror of https://github.com/samba-team/samba.git synced 2025-08-04 08:22:08 +03:00

test SMBsetatr as well

This commit is contained in:
Andrew Tridgell
-
parent bca9c49e6f
commit 2f29c24ba7
3 changed files with 75 additions and 11 deletions

View File

@ -72,7 +72,9 @@ BOOL cli_lock(struct cli_state *cli, int fnum, uint32 offset, uint32 len, int ti
BOOL cli_unlock(struct cli_state *cli, int fnum, uint32 offset, uint32 len, int timeout); BOOL cli_unlock(struct cli_state *cli, int fnum, uint32 offset, uint32 len, int timeout);
int cli_read(struct cli_state *cli, int fnum, char *buf, uint32 offset, uint16 size); int cli_read(struct cli_state *cli, int fnum, char *buf, uint32 offset, uint16 size);
int cli_write(struct cli_state *cli, int fnum, char *buf, uint32 offset, uint16 size); int cli_write(struct cli_state *cli, int fnum, char *buf, uint32 offset, uint16 size);
BOOL cli_stat(struct cli_state *cli, char *fname, struct stat *st); 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_negprot(struct cli_state *cli); BOOL cli_negprot(struct cli_state *cli);
BOOL cli_session_request(struct cli_state *cli, char *host, int name_type, BOOL cli_session_request(struct cli_state *cli, char *host, int name_type,
char *myname); char *myname);

View File

@ -861,10 +861,10 @@ int cli_write(struct cli_state *cli, int fnum, char *buf, uint32 offset, uint16
/**************************************************************************** /****************************************************************************
stat a file (actually a SMBgetattr call) do a SMBgetatr call
This only fills in a few of the stat fields
****************************************************************************/ ****************************************************************************/
BOOL cli_stat(struct cli_state *cli, char *fname, struct stat *st) BOOL cli_getatr(struct cli_state *cli, char *fname,
int *attr, uint32 *size, time_t *t)
{ {
char *p; char *p;
@ -890,10 +890,55 @@ BOOL cli_stat(struct cli_state *cli, char *fname, struct stat *st)
return False; return False;
} }
memset(st, 0, sizeof(*st)); if (size) {
st->st_size = IVAL(cli->inbuf, smb_vwv3); *size = IVAL(cli->inbuf, smb_vwv3);
}
if (t) {
*t = make_unix_date3(cli->inbuf+smb_vwv1);
}
if (attr) {
*attr = SVAL(cli->inbuf,smb_vwv0);
}
return True;
}
/****************************************************************************
do a SMBsetatr call
****************************************************************************/
BOOL cli_setatr(struct cli_state *cli, char *fname, int attr, time_t t)
{
char *p;
bzero(cli->outbuf,smb_size);
bzero(cli->inbuf,smb_size);
set_message(cli->outbuf,8,strlen(fname)+2,True);
CVAL(cli->outbuf,smb_com) = SMBsetatr;
SSVAL(cli->outbuf,smb_tid,cli->cnum);
cli_setup_packet(cli);
SSVAL(cli->outbuf,smb_vwv0, attr);
put_dos_date3(cli->outbuf,smb_vwv1, t);
p = smb_buf(cli->outbuf);
*p = 4;
strcpy(p+1, fname);
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;
}
st->st_mtime = make_unix_date3(cli->inbuf+smb_vwv1);
return True; return True;
} }

View File

@ -637,7 +637,7 @@ static void run_attrtest(void)
{ {
static struct cli_state cli; static struct cli_state cli;
int fnum; int fnum;
struct stat st; time_t t, t2;
char *fname = "\\attrib.tst"; char *fname = "\\attrib.tst";
printf("staring attrib test\n"); printf("staring attrib test\n");
@ -650,13 +650,30 @@ static void run_attrtest(void)
fnum = cli_open(&cli, fname, fnum = cli_open(&cli, fname,
O_RDWR | O_CREAT | O_TRUNC, DENY_NONE); O_RDWR | O_CREAT | O_TRUNC, DENY_NONE);
cli_close(&cli, fnum); cli_close(&cli, fnum);
if (!cli_stat(&cli, fname, &st)) { if (!cli_getatr(&cli, fname, NULL, NULL, &t)) {
printf("getatr failed (%s)\n", cli_errstr(&cli)); printf("getatr failed (%s)\n", cli_errstr(&cli));
} }
if (abs(st.st_mtime - time(NULL)) > 2) { if (abs(t - time(NULL)) > 2) {
printf("ERROR: SMBgetatr bug. time is %s", printf("ERROR: SMBgetatr bug. time is %s",
ctime(&st.st_mtime)); ctime(&t));
t = time(NULL);
}
t2 = t-60*60*24; /* 1 day ago */
if (!cli_setatr(&cli, fname, 0, t2)) {
printf("setatr failed (%s)\n", cli_errstr(&cli));
}
if (!cli_getatr(&cli, fname, NULL, NULL, &t)) {
printf("getatr failed (%s)\n", cli_errstr(&cli));
}
if (t != t2) {
printf("ERROR: getatr/setatr bug. times are\n%s",
ctime(&t));
printf("%s", ctime(&t2));
} }
close_connection(&cli); close_connection(&cli);