Subversion Repositories planix.SVN

Rev

Rev 2 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#include "headers.h"
2
 
3
SmbProcessResult
4
smbcomsetinformation2(SmbSession *s, SmbHeader *h, uchar *pdata, SmbBuffer *)
5
{
6
	ushort fid, adate, atime, mdate, mtime;
7
	SmbTree *t;
8
	SmbFile *f;
9
	Dir d;
10
 
11
	if (h->wordcount != 7)
12
		return SmbProcessResultFormat;
13
	fid = smbnhgets(pdata);
14
	adate = smbnhgets(pdata + 6);
15
	atime = smbnhgets(pdata + 8);
16
	mdate = smbnhgets(pdata + 10);
17
	mtime = smbnhgets(pdata + 12);
18
	smblogprint(h->command,
19
		"smbcomsetinformation2: fid 0x%.4ux adate 0x%.4ux atime 0x%.4ux mdate 0x%.4ux mtime 0x%.4ux\n",
20
		fid, adate, atime, mdate, mtime);
21
	t = smbidmapfind(s->tidmap, h->tid);
22
	if (t == nil) {
23
		smbseterror(s, ERRSRV, ERRinvtid);
24
		return SmbProcessResultError;
25
	}
26
	f = smbidmapfind(s->fidmap, fid);
27
	if (f == nil) {
28
		smbseterror(s, ERRDOS, ERRbadfid);
29
		return SmbProcessResultError;
30
	}
31
	memset(&d, 0xff, sizeof(d));
32
	d.name = d.uid = d.gid = d.muid = nil;
33
	if (adate || atime || mdate || mtime) {
34
//smblogprint(-1, "smbcomsetinformation2: changing times not implemented\n");
35
//		return SmbProcessResultUnimp;
36
		/* something to change */
37
		if (!(adate && atime && mdate && mtime)) {
38
			/* some null entries */
39
			ushort odate, otime;
40
			Dir *od = dirfstat(f->fd);
41
			if (od == nil) {
42
				smbseterror(s, ERRDOS, ERRnoaccess);
43
				return SmbProcessResultError;
44
			}
45
			if (adate || atime) {
46
				/* something changed in access time */
47
				if (!(adate && atime)) {
48
					/* some nulls in access time */
49
					smbplan9time2datetime(d.atime, s->tzoff, &odate, &otime);
50
					if (adate == 0)
51
						adate = odate;
52
					if (atime == 0)
53
						atime = otime;
54
				}
55
				d.atime = smbdatetime2plan9time(adate, atime, s->tzoff);
56
			}
57
			if (mdate || mtime) {
58
				/* something changed in modify time */
59
				if (!(mdate && mtime)) {
60
					/* some nulls in modify time */
61
					smbplan9time2datetime(d.mtime, s->tzoff, &odate, &otime);
62
					if (mdate == 0)
63
						mdate = odate;
64
					if (mtime == 0)
65
						mtime = otime;
66
				}
67
				d.mtime = smbdatetime2plan9time(mdate, mtime, s->tzoff);
68
			}
69
			free(od);
70
		}
71
		if (dirfwstat(f->fd, &d) < 0) {
72
			smbseterror(s, ERRDOS, ERRnoaccess);
73
			return SmbProcessResultError;
74
		}
75
	}
76
	return smbbufferputack(s->response, h, &s->peerinfo);
77
}
78
 
79
SmbProcessResult
80
smbcomsetinformation(SmbSession *s, SmbHeader *h, uchar *pdata, SmbBuffer *b)
81
{
82
	ushort attr;
83
	ulong utime;
84
	char *name;
85
	if (h->wordcount != 8)
86
		return SmbProcessResultFormat;
87
	attr = smbnhgets(pdata); pdata += 2;
88
	utime = smbnhgetl(pdata);
89
	if (!smbbuffergetstring(b, h, SMB_STRING_PATH, &name))
90
		return SmbProcessResultFormat;
91
	smblogprint(h->command,
92
		"smbcomsetinformation: attr 0x%.4ux utime %lud path %s\n",
93
		attr, utime, name);
94
	if (utime) {
95
		Dir d;
96
		memset(&d, 0xff, sizeof(d));
97
		d.name = d.uid = d.gid = d.muid = nil;
98
		d.mtime = smbutime2plan9time(utime, s->tzoff);
99
		if (dirwstat(name, &d) < 0) {
100
			smbseterror(s, ERRDOS, ERRnoaccess);
101
			free(name);
102
			return SmbProcessResultError;
103
		}
104
	}
105
	free(name);		
106
	return smbbufferputack(s->response, h, &s->peerinfo);
107
}