"Ted Unangst" <[email protected]> writes:
> Jeremie Courreges-Anglas wrote:
>> I think that's a better choice.
>>
>> >
>> >>
>> >> > -#else
>> >> > - while (fgets(line, sizeof(line), fd) != NULL) {
>> >> > - line[strcspn(line, "\n")] = '\0';
>> >> > - lreply(530, "%s", line);
>> >> > - }
>> >> > - (void) fflush(stdout);
>> >> > - (void) close(fd);
>>
>> No need for the two lines above.
>
> this flips the code. to make the changes easier to read, left the old code in
> place for a bit. that'll then be deleted.
As discussed I prefer this direction, but:
- the fgets code will make the server hang
- it's not the ftp user's business to know that IPv4 mapped addresses
aren't supported. I'd rather log something to syslog.
Here's the diff I've just tried, obviously not intended for commit
as-is.
user POV
ritchie ~$ ftp ::1
Connected to ::1.
530 System not available.
xferlog
Aug 31 13:17:29 ritchie ftpd[44886]: Connection from IPv4 mapped
address is not supported.
Index: ftpd.c
===================================================================
RCS file: /cvs/src/libexec/ftpd/ftpd.c,v
retrieving revision 1.220
diff -u -p -p -u -r1.220 ftpd.c
--- ftpd.c 30 Aug 2016 14:56:39 -0000 1.220
+++ ftpd.c 31 Aug 2016 12:18:41 -0000
@@ -524,9 +524,10 @@ main(int argc, char *argv[])
syslog(LOG_ERR, "getsockname: %m");
exit(1);
}
- if (his_addr.su_family == AF_INET6 &&
- IN6_IS_ADDR_V4MAPPED(&his_addr.su_sin6.sin6_addr)) {
-#if 1
+// if (his_addr.su_family == AF_INET6 &&
+// IN6_IS_ADDR_V4MAPPED(&his_addr.su_sin6.sin6_addr)) {
+ if (his_addr.su_family == AF_INET6) {
+#if 0
/*
* IPv4 control connection arrived to AF_INET6 socket.
* I hate to do this, but this is the easiest solution.
@@ -552,15 +553,10 @@ main(int argc, char *argv[])
sizeof(ctrl_addr.su_sin.sin_addr));
ctrl_addr.su_sin.sin_port = tmp_addr.su_sin6.sin6_port;
#else
- while (fgets(line, sizeof(line), fd) != NULL) {
- line[strcspn(line, "\n")] = '\0';
- lreply(530, "%s", line);
- }
- (void) fflush(stdout);
- (void) close(fd);
- reply(530,
- "Connection from IPv4 mapped address is not
supported.");
- exit(0);
+ syslog(LOG_WARNING,
+ "Connection from IPv4 mapped address is not supported.");
+ reply(530, "System not available.");
+ exit(1);
#endif
}
if (his_addr.su_family == AF_INET) {
--
jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF DDCC 0DFA 74AE 1524 E7EE