Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 111152 | Differences between
and this patch

Collapse All | Expand All

(-)proftpd-1.3.1rc1.orig/modules/mod_codeconv.c (+223 lines)
Line 0 Link Here
1
/*
2
 * ProFTPD: mod_codeconv -- local <-> remote charset conversion
3
 *
4
 * Copyright (c) 2004 by TSUJIKAWA Tohru <tsujikawa@tsg.ne.jp> / All rights reserved.
5
 * Fixed segfault bug by Sergey Belyashov <Sergey.Belyashov@gmail.com>
6
 *
7
 * This program is free software; you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation; either version 2 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA.
20
 *
21
 */
22
23
24
#include	"conf.h"
25
#include	<iconv.h>
26
#include	<string.h>
27
28
//
29
// directive
30
//
31
#define	DIRECTIVE_CHARSETLOCAL		"CharsetLocal"
32
#define	DIRECTIVE_CHARSETREMOTE		"CharsetRemote"
33
34
static char charset_local[256] = "";
35
static char charset_remote[256] = "";
36
37
38
//
39
// initialization
40
//
41
static int codeconv_init(void)
42
{
43
	return 0;
44
}
45
46
static int codeconv_sess_init(void)
47
{
48
	return 0;
49
}
50
51
52
char* remote2local(struct pool* pool, char* remote)
53
{
54
	iconv_t	ic = (iconv_t)(-1);
55
	char*	local;
56
	char*	in_ptr;
57
	char*	out_ptr;
58
	size_t	inbytesleft, outbytesleft;
59
60
	if (strlen(charset_local)&&strlen(charset_remote))
61
		ic = iconv_open(charset_local, charset_remote);
62
	if (ic == (iconv_t)(-1)) return NULL;
63
64
	iconv(ic, NULL, NULL, NULL, NULL);
65
66
	inbytesleft = strlen(remote);
67
	outbytesleft = inbytesleft*3;
68
	local = palloc(pool, outbytesleft+1);
69
70
	in_ptr = remote; out_ptr = local;
71
	while (inbytesleft) {
72
		if (iconv(ic, &in_ptr, &inbytesleft, &out_ptr, &outbytesleft) == -1) {
73
			*out_ptr = '?'; out_ptr++; outbytesleft--;
74
			in_ptr++; inbytesleft--;
75
			break;
76
		}
77
	}
78
	*out_ptr = 0;
79
80
	iconv_close(ic);
81
82
	return local;
83
}
84
85
86
char* local2remote(char* local)
87
{
88
	iconv_t	ic = (iconv_t)(-1);
89
	char*	remote;
90
	char*	in_ptr;
91
	char*	out_ptr;
92
	size_t	inbytesleft, outbytesleft;
93
94
	if (strlen(charset_local)&&strlen(charset_remote))
95
		ic = iconv_open(charset_remote, charset_local);
96
	if (ic == (iconv_t)(-1)) return NULL;
97
98
	iconv(ic, NULL, NULL, NULL, NULL);
99
100
	inbytesleft = strlen(local);
101
	outbytesleft = inbytesleft*3;
102
	remote = malloc(outbytesleft+1);
103
104
	in_ptr = local; out_ptr = remote;
105
	while (inbytesleft) {
106
		if (iconv(ic, &in_ptr, &inbytesleft, &out_ptr, &outbytesleft) == -1) {
107
			*out_ptr = '?'; out_ptr++; outbytesleft--;
108
			in_ptr++; inbytesleft--;
109
			break;
110
		}
111
	}
112
	*out_ptr = 0;
113
114
	iconv_close(ic);
115
116
	return remote;
117
}
118
119
120
//
121
// module handler
122
//
123
MODRET codeconv_pre_any(cmd_rec* cmd)
124
{
125
	char*	p;
126
	int		i;
127
128
	p = remote2local(cmd->pool, cmd->arg);
129
	if (p) cmd->arg = p;
130
131
	for (i = 0; i < cmd->argc; i++) {
132
		p = remote2local(cmd->pool, cmd->argv[i]);
133
		if (p) cmd->argv[i] = p;
134
	}
135
136
	return DECLINED(cmd);
137
}
138
139
140
//
141
// local charset directive "CharsetLocal"
142
//
143
MODRET set_charsetlocal(cmd_rec *cmd) {
144
  config_rec *c = NULL;
145
146
  /* Syntax: CharsetLocal iconv-charset-name */
147
148
  CHECK_ARGS(cmd, 1);
149
  CHECK_CONF(cmd, CONF_ROOT|CONF_VIRTUAL|CONF_GLOBAL);
150
151
  c = add_config_param_str(DIRECTIVE_CHARSETLOCAL, 1, cmd->argv[1]);
152
  strncpy(charset_local, cmd->argv[1], sizeof(charset_local));
153
154
  return HANDLED(cmd);
155
}
156
157
//
158
// remote charset directive "CharsetRemote"
159
//
160
MODRET set_charsetremote(cmd_rec *cmd) {
161
  config_rec *c = NULL;
162
163
  /* Syntax: CharsetRemote iconv-charset-name */
164
165
  CHECK_ARGS(cmd, 1);
166
  CHECK_CONF(cmd, CONF_ROOT|CONF_VIRTUAL|CONF_GLOBAL);
167
168
  c = add_config_param_str(DIRECTIVE_CHARSETREMOTE, 1, cmd->argv[1]);
169
  strncpy(charset_remote, cmd->argv[1], sizeof(charset_remote));
170
171
  return HANDLED(cmd);
172
}
173
174
175
//
176
// module ÍÑ directive
177
//
178
static conftable codeconv_conftab[] = {
179
	{ DIRECTIVE_CHARSETLOCAL,		set_charsetlocal,		NULL },
180
	{ DIRECTIVE_CHARSETREMOTE,		set_charsetremote,		NULL },
181
	{ NULL, NULL, NULL }
182
};
183
184
185
//
186
// trap ¤¹¤ë¥³¥Þ¥ó¥É°ìÍ÷
187
//
188
static cmdtable codeconv_cmdtab[] = {
189
	{ PRE_CMD,		C_ANY,	G_NONE, codeconv_pre_any,	FALSE, FALSE },
190
	{ 0,			NULL }
191
};
192
193
194
//
195
// module ¾ðÊó
196
//
197
module codeconv_module = {
198
199
	/* Always NULL */
200
	NULL, NULL,
201
202
	/* Module API version (2.0) */
203
	0x20,
204
205
	/* Module name */
206
	"codeconv",
207
208
	/* Module configuration directive handlers */
209
	codeconv_conftab,
210
211
	/* Module command handlers */
212
	codeconv_cmdtab,
213
214
	/* Module authentication handlers (none in this case) */
215
	NULL,
216
217
	/* Module initialization */
218
	codeconv_init,
219
220
	/* Session initialization */
221
	codeconv_sess_init
222
223
};
(-)proftpd-1.3.1rc1.orig/modules/mod_df.c (+127 lines)
Line 0 Link Here
1
/*
2
 * ProFTPD: mod_df -- ¥Ç¥£¥¹¥¯¶õ¤­ÍÆÎÌÄÌÃΥ⥸¥å¡¼¥ë
3
 *
4
 * Copyright (c) 2002 by TSUJIKAWA Tohru <tsujikawa@tsg.ne.jp>
5
 *
6
 * This program is free software; you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation; either version 2 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307, USA.
19
 *
20
 */
21
22
 /*
23
   **** for Linux only ****
24
25
   CWD/CDUP ¥³¥Þ¥ó¥É¤Î¥ê¥¶¥ë¥È¤ÇÅö³º¥Ç¥£¥ì¥¯¥È¥ê¤Ç¤Î¥Ç¥£¥¹¥¯¶õ¤­ÍÆÎ̤òÄÌÃΤ¹¤ë¥â¥¸¥å¡¼¥ë¤Ç¤¹¡£
26
27
   statfs() ¤Î»ÅÍ;塤64bit ÍѤ˥³¥ó¥Ñ¥¤¥ë¤·¤Ê¤¤¾ì¹ç¤Ï 2TB °Ê¾å¤Î¥Ç¥£¥¹¥¯¤Î»þ¤Ë
28
   Àµ¾ï¤ÊÃͤòÊÖ¤µ¤Ê¤¤¤³¤È¤¬´üÂÔ¤µ¤ì¤Þ¤¹¡£
29
30
 */
31
32
33
#include	"conf.h"
34
#include	<sys/vfs.h>
35
36
37
//
38
// ½é´ü²½
39
//
40
static int df_init(void)
41
{
42
	return 0;
43
}
44
45
static int df_sess_init(void)
46
{
47
	return 0;
48
}
49
50
51
//
52
// module handler
53
//
54
MODRET df_post_cwd(cmd_rec* cmd)
55
{
56
	char	buf[PATH_MAX+1];
57
	struct statfs	sfs;
58
59
	if (getcwd(buf, sizeof(buf)) && statfs(buf, &sfs) == 0) {
60
		long long	f = (long long)sfs.f_bavail * (long long)sfs.f_bsize;
61
		if (f >= ((long long)1 << 10)*1000000000L) {
62
			sprintf(buf, "Disk free space at this directory is %lld,%03lld,%03lld MB.",
63
					(f >> 20)/1000000, (f >> 20)/1000%1000, (f >> 20)%1000);
64
		} else if (f >= ((long long)1 << 10)*1000000) {
65
			sprintf(buf, "Disk free space at this directory is %lld,%03lld,%03lld KB.",
66
					(f >> 10)/1000000, (f >> 10)/1000%1000, (f >> 10)%1000);
67
		} else if (f >= ((long long)1 << 10)*1000) {
68
			sprintf(buf, "DISK FREE SPACE AT THIS DIRECTORY IS ONLY %lld,%03lld KB.", (f >> 10)/1000, (f >> 10)%1000);
69
		} else if (f >= 1000) {
70
			sprintf(buf, "DISK FREE SPACE AT THIS DIRECTORY IS ONLY %lld,%03lld Bytes.", f/1000, f%1000);
71
		} else {
72
			sprintf(buf, "DISK FREE SPACE AT THIS DIRECTORY IS ONLY %lld Bytes.", f);
73
		}
74
		pr_response_send_raw("250-%s", buf);
75
	}
76
	return HANDLED(cmd);
77
}
78
79
80
//
81
// module ÍÑ directive
82
//
83
static conftable df_conftab[] = {
84
	{ NULL }						// directive ¤Ï¥µ¥Ý¡¼¥È¤·¤Ê¤¤
85
};
86
87
88
//
89
// trap ¤¹¤ë¥³¥Þ¥ó¥É°ìÍ÷
90
//
91
static cmdtable df_cmdtab[] = {
92
	{ POST_CMD,		C_CWD,	G_NONE, df_post_cwd,	FALSE, FALSE },
93
	{ POST_CMD,		C_CDUP,	G_NONE, df_post_cwd,	FALSE, FALSE },
94
	{ 0,			NULL }
95
};
96
97
98
//
99
// module ¾ðÊó
100
//
101
module df_module = {
102
103
	/* Always NULL */
104
	NULL, NULL,
105
106
	/* Module API version (2.0) */
107
	0x20,
108
109
	/* Module name */
110
	"df",
111
112
	/* Module configuration directive handlers */
113
	df_conftab,
114
115
	/* Module command handlers */
116
	df_cmdtab,
117
118
	/* Module authentication handlers (none in this case) */
119
	NULL,
120
121
	/* Module initialization */
122
	df_init,
123
124
	/* Session initialization */
125
	df_sess_init
126
127
};
(-)proftpd-1.3.1rc1.orig/modules/mod_ls.c (+11 lines)
Lines 242-252 Link Here
242
  return res;
242
  return res;
243
}
243
}
244
244
245
extern char* local2remote(char*);
246
245
/* sendline() now has an internal buffer, to help speed up LIST output. */
247
/* sendline() now has an internal buffer, to help speed up LIST output. */
246
static int sendline(int flags, char *fmt, ...) {
248
static int sendline(int flags, char *fmt, ...) {
247
  static char listbuf[PR_TUNABLE_BUFFER_SIZE] = {'\0'};
249
  static char listbuf[PR_TUNABLE_BUFFER_SIZE] = {'\0'};
248
  va_list msg;
250
  va_list msg;
249
  char buf[PR_TUNABLE_BUFFER_SIZE+1] = {'\0'};
251
  char buf[PR_TUNABLE_BUFFER_SIZE+1] = {'\0'};
252
  char *buf2;
250
  int res = 0;
253
  int res = 0;
251
254
252
  if (flags & LS_SENDLINE_FL_FLUSH) {
255
  if (flags & LS_SENDLINE_FL_FLUSH) {
Lines 266-271 Link Here
266
269
267
  buf[sizeof(buf)-1] = '\0';
270
  buf[sizeof(buf)-1] = '\0';
268
271
272
  if (buf[0]) {
273
    buf2 = local2remote(buf);
274
    if (buf2) {
275
      strcpy(buf, buf2);
276
      free(buf2);
277
    }
278
  }
279
269
  /* If buf won't fit completely into listbuf, flush listbuf */
280
  /* If buf won't fit completely into listbuf, flush listbuf */
270
  if (strlen(buf) >= (sizeof(listbuf) - strlen(listbuf))) {
281
  if (strlen(buf) >= (sizeof(listbuf) - strlen(listbuf))) {
271
    res = pr_data_xfer(listbuf, strlen(listbuf));
282
    res = pr_data_xfer(listbuf, strlen(listbuf));
(-)proftpd-1.3.1rc1.orig/src/netio.c (+10 lines)
Lines 523-531 Link Here
523
  return -1;
523
  return -1;
524
}
524
}
525
525
526
extern char* local2remote(char* local);
527
526
int pr_netio_printf(pr_netio_stream_t *nstrm, const char *fmt, ...) {
528
int pr_netio_printf(pr_netio_stream_t *nstrm, const char *fmt, ...) {
527
  va_list msg;
529
  va_list msg;
528
  char buf[PR_RESPONSE_BUFFER_SIZE] = {'\0'};
530
  char buf[PR_RESPONSE_BUFFER_SIZE] = {'\0'};
531
  char* p;
529
532
530
  if (!nstrm) {
533
  if (!nstrm) {
531
    errno = EINVAL;
534
    errno = EINVAL;
Lines 537-542 Link Here
537
  va_end(msg);
540
  va_end(msg);
538
  buf[sizeof(buf)-1] = '\0';
541
  buf[sizeof(buf)-1] = '\0';
539
542
543
  if (buf[0]) {
544
    p = local2remote(buf);
545
    if (p) {
546
      strcpy(buf, p); free(p);
547
    }
548
  }
549
540
  return pr_netio_write(nstrm, buf, strlen(buf));
550
  return pr_netio_write(nstrm, buf, strlen(buf));
541
}
551
}
542
552

Return to bug 111152