use `alloc_buffer'
git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@1732 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -240,7 +240,7 @@ static FILE *getdatasock (char *);
|
|||||||
static char *gunique (char *);
|
static char *gunique (char *);
|
||||||
static RETSIGTYPE lostconn (int);
|
static RETSIGTYPE lostconn (int);
|
||||||
static int receive_data (FILE *, FILE *);
|
static int receive_data (FILE *, FILE *);
|
||||||
static void send_data (FILE *, FILE *, off_t);
|
static void send_data (FILE *, FILE *);
|
||||||
static struct passwd * sgetpwnam (char *);
|
static struct passwd * sgetpwnam (char *);
|
||||||
static void usage(void);
|
static void usage(void);
|
||||||
|
|
||||||
@@ -283,7 +283,7 @@ parse_auth_level(char *str)
|
|||||||
else if(strcmp(p, "none") == 0)
|
else if(strcmp(p, "none") == 0)
|
||||||
ret |= AUTH_PLAIN|AUTH_FTP;
|
ret |= AUTH_PLAIN|AUTH_FTP;
|
||||||
else
|
else
|
||||||
warnx("bad value for -a");
|
warnx("bad value for -a: `%s'", p);
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@@ -958,10 +958,7 @@ retrieve(char *cmd, char *name)
|
|||||||
fin = ftpd_popen(line, "r", 0, 0);
|
fin = ftpd_popen(line, "r", 0, 0);
|
||||||
closefunc = ftpd_pclose;
|
closefunc = ftpd_pclose;
|
||||||
st.st_size = -1;
|
st.st_size = -1;
|
||||||
#ifdef HAVE_ST_BLKSIZE
|
|
||||||
st.st_blksize = BUFSIZ;
|
|
||||||
cmd = line;
|
cmd = line;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -970,9 +967,6 @@ retrieve(char *cmd, char *name)
|
|||||||
fin = ftpd_popen(line, "r", 1, 0);
|
fin = ftpd_popen(line, "r", 1, 0);
|
||||||
closefunc = ftpd_pclose;
|
closefunc = ftpd_pclose;
|
||||||
st.st_size = -1;
|
st.st_size = -1;
|
||||||
#ifdef HAVE_ST_BLKSIZE
|
|
||||||
st.st_blksize = BUFSIZ;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
if (fin == NULL) {
|
if (fin == NULL) {
|
||||||
if (errno != 0) {
|
if (errno != 0) {
|
||||||
@@ -1014,11 +1008,7 @@ retrieve(char *cmd, char *name)
|
|||||||
if (dout == NULL)
|
if (dout == NULL)
|
||||||
goto done;
|
goto done;
|
||||||
set_buffer_size(fileno(dout), 0);
|
set_buffer_size(fileno(dout), 0);
|
||||||
#ifdef HAVE_ST_BLKSIZE
|
send_data(fin, dout);
|
||||||
send_data(fin, dout, st.st_blksize);
|
|
||||||
#else
|
|
||||||
send_data(fin, dout, BUFSIZ);
|
|
||||||
#endif
|
|
||||||
fclose(dout);
|
fclose(dout);
|
||||||
data = -1;
|
data = -1;
|
||||||
pdata = -1;
|
pdata = -1;
|
||||||
@@ -1249,10 +1239,11 @@ dataconn(char *name, off_t size, char *mode)
|
|||||||
* NB: Form isn't handled.
|
* NB: Form isn't handled.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
send_data(FILE *instr, FILE *outstr, off_t blksize)
|
send_data(FILE *instr, FILE *outstr)
|
||||||
{
|
{
|
||||||
int c, cnt, filefd, netfd;
|
int c, cnt, filefd, netfd;
|
||||||
char *buf;
|
static char *buf;
|
||||||
|
static size_t bufsize;
|
||||||
int i = 0;
|
int i = 0;
|
||||||
char s[1024];
|
char s[1024];
|
||||||
|
|
||||||
@@ -1313,19 +1304,22 @@ send_data(FILE *instr, FILE *outstr, off_t blksize)
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
if(transflag){
|
if(transflag){
|
||||||
if ((buf = malloc(10 * blksize)) == NULL) {
|
struct stat st;
|
||||||
|
|
||||||
|
netfd = fileno(outstr);
|
||||||
|
filefd = fileno(instr);
|
||||||
|
buf = alloc_buffer (buf, &bufsize,
|
||||||
|
fstat(filefd, &st) >= 0 ? &st : NULL);
|
||||||
|
if (buf == NULL) {
|
||||||
transflag = 0;
|
transflag = 0;
|
||||||
perror_reply(451, "Local resource failure: malloc");
|
perror_reply(451, "Local resource failure: malloc");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
netfd = fileno(outstr);
|
while ((cnt = read(filefd, buf, bufsize)) > 0 &&
|
||||||
filefd = fileno(instr);
|
|
||||||
while ((cnt = read(filefd, buf, 10 * blksize)) > 0 &&
|
|
||||||
auth_write(netfd, buf, cnt) == cnt)
|
auth_write(netfd, buf, cnt) == cnt)
|
||||||
byte_count += cnt;
|
byte_count += cnt;
|
||||||
auth_write(netfd, buf, 0); /* to end an encrypted stream */
|
auth_write(netfd, buf, 0); /* to end an encrypted stream */
|
||||||
transflag = 0;
|
transflag = 0;
|
||||||
free(buf);
|
|
||||||
if (cnt != 0) {
|
if (cnt != 0) {
|
||||||
if (cnt < 0)
|
if (cnt < 0)
|
||||||
goto file_err;
|
goto file_err;
|
||||||
@@ -1360,18 +1354,29 @@ static int
|
|||||||
receive_data(FILE *instr, FILE *outstr)
|
receive_data(FILE *instr, FILE *outstr)
|
||||||
{
|
{
|
||||||
int cnt, bare_lfs = 0;
|
int cnt, bare_lfs = 0;
|
||||||
char buf[100*BUFSIZ];
|
static char *buf;
|
||||||
|
static size_t bufsize;
|
||||||
|
struct stat st;
|
||||||
|
|
||||||
transflag++;
|
transflag++;
|
||||||
if (setjmp(urgcatch)) {
|
if (setjmp(urgcatch)) {
|
||||||
transflag = 0;
|
transflag = 0;
|
||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buf = alloc_buffer (buf, &bufsize,
|
||||||
|
fstat(fileno(outstr), &st) >= 0 ? &st : NULL);
|
||||||
|
if (buf == NULL) {
|
||||||
|
transflag = 0;
|
||||||
|
perror_reply(451, "Local resource failure: malloc");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
|
||||||
case TYPE_I:
|
case TYPE_I:
|
||||||
case TYPE_L:
|
case TYPE_L:
|
||||||
while ((cnt = auth_read(fileno(instr), buf, sizeof(buf))) > 0) {
|
while ((cnt = auth_read(fileno(instr), buf, bufsize)) > 0) {
|
||||||
if (write(fileno(outstr), buf, cnt) != cnt)
|
if (write(fileno(outstr), buf, cnt) != cnt)
|
||||||
goto file_err;
|
goto file_err;
|
||||||
byte_count += cnt;
|
byte_count += cnt;
|
||||||
@@ -1390,12 +1395,13 @@ receive_data(FILE *instr, FILE *outstr)
|
|||||||
{
|
{
|
||||||
char *p, *q;
|
char *p, *q;
|
||||||
int cr_flag = 0;
|
int cr_flag = 0;
|
||||||
while ((cnt = auth_read(fileno(instr), buf+cr_flag,
|
while ((cnt = auth_read(fileno(instr),
|
||||||
sizeof(buf)-cr_flag)) > 0){
|
buf + cr_flag,
|
||||||
|
bufsize - cr_flag)) > 0){
|
||||||
byte_count += cnt;
|
byte_count += cnt;
|
||||||
cnt += cr_flag;
|
cnt += cr_flag;
|
||||||
cr_flag = 0;
|
cr_flag = 0;
|
||||||
for(p = buf, q = buf; p < buf + cnt;){
|
for(p = buf, q = buf; p < buf + cnt;) {
|
||||||
if(*p == '\n')
|
if(*p == '\n')
|
||||||
bare_lfs++;
|
bare_lfs++;
|
||||||
if(*p == '\r')
|
if(*p == '\r')
|
||||||
|
Reference in New Issue
Block a user