View | Details | Raw Unified | Return to bug 2159
Collapse All | Expand All

(-)sftp-server.c (-4 / +19 lines)
Lines 130-135 flags_from_portable(int pflags) Link Here
130
	} else if (pflags & SSH2_FXF_WRITE) {
130
	} else if (pflags & SSH2_FXF_WRITE) {
131
		flags = O_WRONLY;
131
		flags = O_WRONLY;
132
	}
132
	}
133
	if (pflags & SSH2_FXF_APPEND)
134
		flags |= O_APPEND;
133
	if (pflags & SSH2_FXF_CREAT)
135
	if (pflags & SSH2_FXF_CREAT)
134
		flags |= O_CREAT;
136
		flags |= O_CREAT;
135
	if (pflags & SSH2_FXF_TRUNC)
137
	if (pflags & SSH2_FXF_TRUNC)
Lines 156-161 string_from_portable(int pflags) Link Here
156
		PAPPEND("READ")
158
		PAPPEND("READ")
157
	if (pflags & SSH2_FXF_WRITE)
159
	if (pflags & SSH2_FXF_WRITE)
158
		PAPPEND("WRITE")
160
		PAPPEND("WRITE")
161
	if (pflags & SSH2_FXF_APPEND)
162
		PAPPEND("APPEND")
159
	if (pflags & SSH2_FXF_CREAT)
163
	if (pflags & SSH2_FXF_CREAT)
160
		PAPPEND("CREATE")
164
		PAPPEND("CREATE")
161
	if (pflags & SSH2_FXF_TRUNC)
165
	if (pflags & SSH2_FXF_TRUNC)
Lines 179-184 struct Handle { Link Here
179
	int use;
183
	int use;
180
	DIR *dirp;
184
	DIR *dirp;
181
	int fd;
185
	int fd;
186
	int flags;
182
	char *name;
187
	char *name;
183
	u_int64_t bytes_read, bytes_write;
188
	u_int64_t bytes_read, bytes_write;
184
	int next_unused;
189
	int next_unused;
Lines 202-208 static void handle_unused(int i) Link Here
202
}
207
}
203
208
204
static int
209
static int
205
handle_new(int use, const char *name, int fd, DIR *dirp)
210
handle_new(int use, const char *name, int fd, int flags, DIR *dirp)
206
{
211
{
207
	int i;
212
	int i;
208
213
Lines 220-225 handle_new(int use, const char *name, in Link Here
220
	handles[i].use = use;
225
	handles[i].use = use;
221
	handles[i].dirp = dirp;
226
	handles[i].dirp = dirp;
222
	handles[i].fd = fd;
227
	handles[i].fd = fd;
228
	handles[i].flags = flags;
223
	handles[i].name = xstrdup(name);
229
	handles[i].name = xstrdup(name);
224
	handles[i].bytes_read = handles[i].bytes_write = 0;
230
	handles[i].bytes_read = handles[i].bytes_write = 0;
225
231
Lines 282-287 handle_to_fd(int handle) Link Here
282
	return -1;
288
	return -1;
283
}
289
}
284
290
291
static int
292
handle_to_flags(int handle)
293
{
294
	if (handle_is_ok(handle, HANDLE_FILE))
295
		return handles[handle].flags;
296
	return -1;
297
}
298
285
static void
299
static void
286
handle_update_read(int handle, ssize_t bytes)
300
handle_update_read(int handle, ssize_t bytes)
287
{
301
{
Lines 567-573 process_open(void) Link Here
567
		if (fd < 0) {
581
		if (fd < 0) {
568
			status = errno_to_portable(errno);
582
			status = errno_to_portable(errno);
569
		} else {
583
		} else {
570
			handle = handle_new(HANDLE_FILE, name, fd, NULL);
584
			handle = handle_new(HANDLE_FILE, name, fd, flags, NULL);
571
			if (handle < 0) {
585
			if (handle < 0) {
572
				close(fd);
586
				close(fd);
573
			} else {
587
			} else {
Lines 660-666 process_write(void) Link Here
660
	else if (readonly)
674
	else if (readonly)
661
		status = SSH2_FX_PERMISSION_DENIED;
675
		status = SSH2_FX_PERMISSION_DENIED;
662
	else {
676
	else {
663
		if (lseek(fd, off, SEEK_SET) < 0) {
677
		if (!(handle_to_flags(handle) & O_APPEND) &&
678
				lseek(fd, off, SEEK_SET) < 0) {
664
			status = errno_to_portable(errno);
679
			status = errno_to_portable(errno);
665
			error("process_write: seek failed");
680
			error("process_write: seek failed");
666
		} else {
681
		} else {
Lines 893-899 process_opendir(void) Link Here
893
	if (dirp == NULL) {
908
	if (dirp == NULL) {
894
		status = errno_to_portable(errno);
909
		status = errno_to_portable(errno);
895
	} else {
910
	} else {
896
		handle = handle_new(HANDLE_DIR, path, 0, dirp);
911
		handle = handle_new(HANDLE_DIR, path, 0, 0, dirp);
897
		if (handle < 0) {
912
		if (handle < 0) {
898
			closedir(dirp);
913
			closedir(dirp);
899
		} else {
914
		} else {

Return to bug 2159