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

(-)ssh.orig/sftp-server.c (-28 / +31 lines)
Lines 164-169 struct Handle { Link Here
164
	int fd;
164
	int fd;
165
	char *name;
165
	char *name;
166
	u_int64_t bytes_read, bytes_write;
166
	u_int64_t bytes_read, bytes_write;
167
	int next_unused;
167
};
168
};
168
169
169
enum {
170
enum {
Lines 172-211 enum { Link Here
172
	HANDLE_FILE
173
	HANDLE_FILE
173
};
174
};
174
175
175
Handle	handles[100];
176
Handle *handles = NULL;
176
177
u_int num_handles = 0;
177
static void
178
int first_unused = -1;
178
handle_init(void)
179
179
{
180
static void handle_unused(int i)
180
	u_int i;
181
{
181
182
	handles[i].use = HANDLE_UNUSED;
182
	for (i = 0; i < sizeof(handles)/sizeof(Handle); i++)
183
	handles[i].next_unused = first_unused;
183
		handles[i].use = HANDLE_UNUSED;
184
	first_unused = i;
184
}
185
}
185
186
186
static int
187
static int
187
handle_new(int use, const char *name, int fd, DIR *dirp)
188
handle_new(int use, const char *name, int fd, DIR *dirp)
188
{
189
{
189
	u_int i;
190
	int i;
190
191
191
	for (i = 0; i < sizeof(handles)/sizeof(Handle); i++) {
192
	if (first_unused == -1) {
192
		if (handles[i].use == HANDLE_UNUSED) {
193
		num_handles++;
193
			handles[i].use = use;
194
		handles = xrealloc(handles, num_handles, sizeof(Handle));
194
			handles[i].dirp = dirp;
195
		handle_unused(num_handles - 1);
195
			handles[i].fd = fd;
196
	}
196
			handles[i].name = xstrdup(name);
197
197
			handles[i].bytes_read = handles[i].bytes_write = 0;
198
	i = first_unused;
198
			return i;
199
	first_unused = handles[i].next_unused;
199
		}
200
200
	}
201
	handles[i].use = use;
201
	return -1;
202
	handles[i].dirp = dirp;
203
	handles[i].fd = fd;
204
	handles[i].name = xstrdup(name);
205
	handles[i].bytes_read = handles[i].bytes_write = 0;
206
207
	return i;
202
}
208
}
203
209
204
static int
210
static int
205
handle_is_ok(int i, int type)
211
handle_is_ok(int i, int type)
206
{
212
{
207
	return i >= 0 && (u_int)i < sizeof(handles)/sizeof(Handle) &&
213
	return i >= 0 && (u_int)i < num_handles && handles[i].use == type;
208
	    handles[i].use == type;
209
}
214
}
210
215
211
static int
216
static int
Lines 295-306 handle_close(int handle) Link Here
295
300
296
	if (handle_is_ok(handle, HANDLE_FILE)) {
301
	if (handle_is_ok(handle, HANDLE_FILE)) {
297
		ret = close(handles[handle].fd);
302
		ret = close(handles[handle].fd);
298
		handles[handle].use = HANDLE_UNUSED;
299
		xfree(handles[handle].name);
303
		xfree(handles[handle].name);
304
		handle_unused(handle);
300
	} else if (handle_is_ok(handle, HANDLE_DIR)) {
305
	} else if (handle_is_ok(handle, HANDLE_DIR)) {
301
		ret = closedir(handles[handle].dirp);
306
		ret = closedir(handles[handle].dirp);
302
		handles[handle].use = HANDLE_UNUSED;
303
		xfree(handles[handle].name);
307
		xfree(handles[handle].name);
308
		handle_unused(handle);
304
	} else {
309
	} else {
305
		errno = ENOENT;
310
		errno = ENOENT;
306
	}
311
	}
Lines 328-334 handle_log_exit(void) Link Here
328
{
333
{
329
	u_int i;
334
	u_int i;
330
335
331
	for (i = 0; i < sizeof(handles)/sizeof(Handle); i++)
336
	for (i = 0; i < num_handles; i++)
332
		if (handles[i].use != HANDLE_UNUSED)
337
		if (handles[i].use != HANDLE_UNUSED)
333
			handle_log_close(i, "forced");
338
			handle_log_close(i, "forced");
334
}
339
}
Lines 1249-1256 main(int argc, char **argv) Link Here
1249
	logit("session opened for local user %s from [%s]",
1254
	logit("session opened for local user %s from [%s]",
1250
	    pw->pw_name, client_addr);
1255
	    pw->pw_name, client_addr);
1251
1256
1252
	handle_init();
1253
1254
	in = dup(STDIN_FILENO);
1257
	in = dup(STDIN_FILENO);
1255
	out = dup(STDOUT_FILENO);
1258
	out = dup(STDOUT_FILENO);
1256
1259

Return to bug 1397