ports/134229: [PORTS] ftp/uftp permissions loss fix, more informative logging
Denis Barov
dindin at dindin.ru
Tue May 5 11:33:19 UTC 2009
>Number: 134229
>Category: ports
>Synopsis: [PORTS] ftp/uftp permissions loss fix, more informative logging
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: freebsd-ports-bugs
>State: open
>Quarter:
>Keywords:
>Date-Required:
>Class: update
>Submitter-Id: current-users
>Arrival-Date: Tue May 05 11:30:00 UTC 2009
>Closed-Date:
>Last-Modified:
>Originator: Denis Barov
>Release: FreeBSD 6.X 7.X 8.X
>Organization:
Yandex
>Environment:
FreeBSD porter.yandex.ru 7.0-RELEASE FreeBSD 7.0-RELEASE #0: Wed Jul 23 22:43:25 MSD 2008 root at porter.yandex.ru:/space/obj/space/RELENG_7/src/sys/W7_AMD64_ULE amd64
>Description:
some improvement for ftp/uftp port:
- fix file permission loss due file transfer
- add errno to error logging
- rise hardcoded maximal serves number from 100 to 256
>How-To-Repeat:
>Fix:
Patch attached with submission follows:
diff -urN ftp/uftp/files/patch-Makefile ftp/uftp/files/patch-Makefile
--- ftp/uftp/files/patch-Makefile 2009-05-05 15:02:05.000000000 +0400
+++ ftp/uftp/files/patch-Makefile 2009-05-05 15:03:34.000000000 +0400
@@ -1,15 +1,14 @@
-*** /dev/null Wed Jun 4 14:07:15 2008
---- Makefile Wed Jun 4 14:07:49 2008
-***************
-*** 0 ****
---- 1,10 ----
-+ #
-+ # Makefile for uftp client and server
-+ #
-+ all: uftp uftpd
-+
-+ uftp: uftp.c
-+ ${CC} ${CFLAGS} -o $@ $< -lm
-+
-+ uftpd: uftpd.c
-+ ${CC} ${CFLAGS} -o $@ $< -lm
+diff -urN Makefile.orig Makefile
+--- Makefile.orig 1970-01-01 03:00:00.000000000 +0300
++++ Makefile 2009-05-05 14:50:35.000000000 +0400
+@@ -0,0 +1,10 @@
++#
++# Makefile for uftp client and server
++#
++all: uftp uftpd
++
++uftp: uftp.c uftp.h
++ ${CC} ${CFLAGS} -o $@ $< -lm
++
++uftpd: uftpd.c uftp.h
++ ${CC} ${CFLAGS} -o $@ $< -lm
diff -urN ftp/uftp/files/patch-uftp.c ftp/uftp/files/patch-uftp.c
--- ftp/uftp/files/patch-uftp.c 1970-01-01 03:00:00.000000000 +0300
+++ ftp/uftp/files/patch-uftp.c 2009-05-05 15:03:34.000000000 +0400
@@ -0,0 +1,27 @@
+diff -urN uftp.c.orig uftp.c
+--- uftp.c.orig 2009-04-27 06:42:35.000000000 +0400
++++ uftp.c 2009-05-05 14:50:35.000000000 +0400
+@@ -45,6 +45,7 @@
+ uint32_t txID;
+ int32_t numblocks,numsections,rate,packet_wait,client_wait;
+ f_offset_t filesize;
++mode_t filemode;
+ struct sockaddr_in listen_dest,receive_dest;
+ FILE *applog;
+
+@@ -195,6 +196,7 @@
+ header->tx_id=txID;
+ info->block_total=numblocks;
+ info->section_total=numsections;
++ info->fmode=filemode;
+ if (filesize>(f_offset_t)0x7FFFFFFF) {
+ info->fsize=0;
+ info->hilargefsize=(int32_t)(filesize >> 32);
+@@ -964,6 +966,7 @@
+ srand(getpid());
+ txID|=rand()&0xFFFF;
+ filesize=statbuf.st_size;
++ filemode=statbuf.st_mode;
+ numblocks=(int32_t)((filesize/BLOCKSIZE)+(filesize%BLOCKSIZE?1:0));
+ numsections=(numblocks/(BLOCKSIZE*8))+(numblocks%(BLOCKSIZE*8)?1:0);
+ naklist=(char *)malloc(numblocks);
diff -urN ftp/uftp/files/patch-uftp.h ftp/uftp/files/patch-uftp.h
--- ftp/uftp/files/patch-uftp.h 1970-01-01 03:00:00.000000000 +0300
+++ ftp/uftp/files/patch-uftp.h 2009-05-05 15:03:34.000000000 +0400
@@ -0,0 +1,20 @@
+diff -urN uftp.h.orig uftp.h
+--- uftp.h.orig 2009-04-27 06:42:35.000000000 +0400
++++ uftp.h 2009-05-05 14:50:35.000000000 +0400
+@@ -231,7 +231,7 @@
+
+ #define BLOCKSIZE 1400
+ #define PACKETSIZE (BLOCKSIZE+sizeof(struct uftp_h))
+-#define MAXDEST 100
++#define MAXDEST 256
+ #define MAXINFODEST 300
+ #define MAXOPENDEST 10000
+ #define MAXFILENAME 100
+@@ -259,6 +259,7 @@
+ int32_t block_total;
+ int32_t section_total;
+ int32_t open;
++ mode_t fmode;
+ struct in_addr mcast;
+ struct in_addr addr_list[MAXDEST];
+ char name[300];
diff -urN ftp/uftp/files/patch-uftpd.c ftp/uftp/files/patch-uftpd.c
--- ftp/uftp/files/patch-uftpd.c 2009-05-05 15:02:05.000000000 +0400
+++ ftp/uftp/files/patch-uftpd.c 2009-05-05 15:03:34.000000000 +0400
@@ -1,6 +1,126 @@
---- uftpd.c.orig 2008-12-26 16:54:54.000000000 +0300
-+++ uftpd.c 2008-12-26 16:55:36.000000000 +0300
-@@ -867,9 +867,9 @@
+diff -urN uftpd.c.orig uftpd.c
+--- uftpd.c.orig 2009-04-27 06:42:35.000000000 +0400
++++ uftpd.c 2009-05-05 14:54:38.000000000 +0400
+@@ -48,6 +48,7 @@
+ int32_t numblocks,numsections;
+ struct sockaddr_in dest;
+ f_offset_t filesize;
++ mode_t fmode;
+ int phase,attempt;
+ timestamp timeout_time;
+ int last;
+@@ -84,7 +85,7 @@
+
+ void gotpipe(int sig)
+ {
+- logfunc(applog,0,1,0,0,"Got SIGPIPE");
++ logfunc(applog,0,1,errno,0,"Got SIGPIPE");
+ }
+
+ void file_cleanup(int listindex)
+@@ -225,6 +226,7 @@
+ id_list[i].latency2=DEF_LATENCY2;
+ id_list[i].numblocks=info->block_total;
+ id_list[i].numsections=info->section_total;
++ id_list[i].fmode=info->fmode;
+ id_list[i].dest=dest;
+ if (info->fsize==0) {
+ id_list[i].filesize=(f_offset_t)info->hilargefsize<<32;
+@@ -261,7 +263,8 @@
+ else
+ logfunc(applog,id_list[listindex].txID,1,0,0,"Bytes: %ld, Blocks: %d, Sections: %d",id_list[listindex].filesize,id_list[listindex].numblocks,id_list[listindex].numsections);
+ logfunc(applog,id_list[listindex].txID,1,0,0,"Using private multicast address %s",inet_ntoa(id_list[listindex].multi));
+- if ((id_list[listindex].file=open(filepath,OPENWRITE|O_CREAT|O_TRUNC,0644))==-1) {
++// if ((id_list[listindex].file=open(filepath,OPENWRITE|O_CREAT|O_TRUNC,0644))==-1) {
++ if ((id_list[listindex].file=open(filepath,OPENWRITE|O_CREAT|O_TRUNC,id_list[listindex].fmode))==-1) {
+ logfunc(applog,id_list[listindex].txID,1,errno,0,"Error opening data file");
+ abort_msg(listener,&(id_list[listindex].dest),id_list[listindex].txID,"Error opening data file");
+ file_cleanup(listindex);
+@@ -460,15 +463,15 @@
+ data=&(buf[sizeof(struct uftp_h)]);
+
+ if (header->func==ABORT) {
+- logfunc(applog,id_list[listindex].txID,1,0,0,"Error: Transfer aborted by server: %s",data);
++ logfunc(applog,id_list[listindex].txID,1,errno,0,"Error: Transfer aborted by server: %s",data);
+ file_cleanup(listindex);
+ } else if (header->func==FILESEG) {
+ if (verbose>=2) {
+ if (header->pass!=1)
+- logfunc(applog,id_list[listindex].txID,1,0,0,"Got packet %d",header->seq_num);
++ logfunc(applog,id_list[listindex].txID,1,errno,0,"Got packet %d",header->seq_num);
+ } else if (verbose==1) {
+ if (header->seq_num!=id_list[listindex].last+1)
+- logfunc(applog,id_list[listindex].txID,1,0,0,"Got packet %d, last was %d",header->seq_num,id_list[listindex].last);
++ logfunc(applog,id_list[listindex].txID,1,errno,0,"Got packet %d, last was %d",header->seq_num,id_list[listindex].last);
+ id_list[listindex].last=header->seq_num;
+ }
+ offset=(f_offset_t)header->seq_num*BLOCKSIZE;
+@@ -477,30 +480,30 @@
+ }
+ if (ret_val!=offset) {
+ if (sizeof(f_offset_t)>4)
+- logfunc(applog,id_list[listindex].txID,1,0,0,"offset is %s, should be %s",printll(ret_val),printll(offset));
++ logfunc(applog,id_list[listindex].txID,1,errno,0,"offset is %s, should be %s",printll(ret_val),printll(offset));
+ else
+- logfunc(applog,id_list[listindex].txID,1,0,0,"offset is %ld, should be %ld",ret_val,offset);
++ logfunc(applog,id_list[listindex].txID,1,errno,0,"offset is %ld, should be %ld",ret_val,offset);
+ }
+ if ((header->blsize!=BLOCKSIZE)&&(header->seq_num!=id_list[listindex].numblocks-1)) {
+- logfunc(applog,id_list[listindex].txID,1,0,0,"Bad block size: %d",header->blsize);
++ logfunc(applog,id_list[listindex].txID,1,errno,0,"Bad block size: %d",header->blsize);
+ }
+ if ((ret_val=write(id_list[listindex].file,data,header->blsize))==-1) {
+- logfunc(applog,id_list[listindex].txID,1,0,0,"Write failed for segment %d",header->seq_num);
++ logfunc(applog,id_list[listindex].txID,1,errno,0,"Write failed for segment %d",header->seq_num);
+ }
+ id_list[listindex].prev_offset=offset+ret_val;
+ if (ret_val!=header->blsize) {
+- logfunc(applog,id_list[listindex].txID,1,0,0,"Write failed for segment %d, only wrote %d bytes",header->seq_num,ret_val);
++ logfunc(applog,id_list[listindex].txID,1,errno,0,"Write failed for segment %d, only wrote %d bytes",header->seq_num,ret_val);
+ }
+ id_list[listindex].naklist[header->seq_num]=0;
+ set_timeout(listindex);
+ } else if (header->func==DONE) {
+- logfunc(applog,id_list[listindex].txID,1,0,0,"Got DONE message for pass %d section %d",header->pass,header->section_num);
++ logfunc(applog,id_list[listindex].txID,1,errno,0,"Got DONE message for pass %d section %d",header->pass,header->section_num);
+ if (addr_in_list(info)) {
+ send_status(listindex,header->pass,header->section_num);
+ }
+ set_timeout(listindex);
+ } else if ((header->func!=REG_CONF)&&(header->func!=DONE_CONF)) {
+- logfunc(applog,id_list[listindex].txID,1,0,0,"Invalid FILESEG message: wrong func: %s",strfunc(header->func));
++ logfunc(applog,id_list[listindex].txID,1,errno,0,"Invalid FILESEG message: wrong func: %s",strfunc(header->func));
+ }
+ }
+
+@@ -516,14 +519,14 @@
+ data=&(buf[sizeof(struct uftp_h)]);
+
+ if (header->func==ABORT) {
+- logfunc(applog,id_list[listindex].txID,1,0,0,"Error: Transfer aborted by server: %s",data);
++ logfunc(applog,id_list[listindex].txID,1,errno,0,"Error: Transfer aborted by server: %s",data);
+ file_cleanup(listindex);
+ } else if (header->func!=DONE_CONF) {
+- logfunc(applog,id_list[listindex].txID,1,0,0,"Invalid DONE_CONF message: wrong func: %s",strfunc(header->func));
++ logfunc(applog,id_list[listindex].txID,1,errno,0,"Invalid DONE_CONF message: wrong func: %s",strfunc(header->func));
+ } else if (addr_in_list(info)) {
+ move_file(listindex);
+ t=time(NULL);
+- logfunc(applog,id_list[listindex].txID,0,0,0,"File transfer confirmed at %s",ctime(&t));
++ logfunc(applog,id_list[listindex].txID,0,errno,0,"File transfer confirmed at %s",ctime(&t));
+ file_cleanup(listindex);
+ }
+ }
+@@ -555,7 +558,7 @@
+ send_register(i);
+ break;
+ case 2:
+- logfunc(applog,id_list[i].txID,1,0,0,"Transfer timed out");
++ logfunc(applog,id_list[i].txID,1,errno,0,"Transfer timed out");
+ abort_msg(listener,&(id_list[i].dest),id_list[i].txID,"Transfer timed out");
+ file_cleanup(i);
+ break;
+@@ -866,9 +869,9 @@
applog=stderr;
nice(-20);
for (c=1;c<=17;c++)
>Release-Note:
>Audit-Trail:
>Unformatted:
More information about the freebsd-ports-bugs
mailing list