Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/libexec/ftpd changes to improve portability:
details: https://anonhg.NetBSD.org/src/rev/6ee6447f2fe5
branches: trunk
changeset: 499260:6ee6447f2fe5
user: lukem <lukem%NetBSD.org@localhost>
date: Wed Nov 15 02:32:30 2000 +0000
description:
changes to improve portability:
* replace union sockunion {} with struct sockinet {}, and modify the code
accordingly. this is possibly more portable, as it doesn't rely upon
the structure alignment within the union for our own stuff. uses local
su_len unless HAVE_SOCKADDR_SA_LEN is defined (set ifdef BSD4_4)
(XXX: haven't tested the ipv6 stuff)
* always use getaddrinfo() and getnameinfo() instead of maintaining two code
paths. (lukemftpd will provide replacements for these on older systems)
* use lockf() instead of open(.., O_EXLOCK) to lock the pid file
* minor KNF
* clean up long long support: create helper #defines and use as appropriate:
#define NO_LONG_LONG ! NO_LONG_LONG
------- ------------ --------------
LLF "%ld" "%lld"
LLFP(x) "%" x "ld" "%" x "lld"
LLT long long long
ULLF "%lu" "%llu"
ULLFP(x) "%" x "lu" "%" x "llu"
ULLT unsigned long unsigned long long
STRTOLL(x,y,z) strtol(x,y,z) strtoll(x,y,z)
diffstat:
libexec/ftpd/cmds.c | 10 +-
libexec/ftpd/conf.c | 11 +-
libexec/ftpd/extern.h | 73 ++++++++---
libexec/ftpd/ftpcmd.y | 69 +++++-----
libexec/ftpd/ftpd.c | 310 +++++++++++++++++++++---------------------------
libexec/ftpd/version.h | 4 +-
6 files changed, 234 insertions(+), 243 deletions(-)
diffs (truncated from 1004 to 300 lines):
diff -r 46d371cce1d2 -r 6ee6447f2fe5 libexec/ftpd/cmds.c
--- a/libexec/ftpd/cmds.c Wed Nov 15 02:00:31 2000 +0000
+++ b/libexec/ftpd/cmds.c Wed Nov 15 02:32:30 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: cmds.c,v 1.6 2000/07/10 22:41:17 lukem Exp $ */
+/* $NetBSD: cmds.c,v 1.7 2000/11/15 02:32:30 lukem Exp $ */
/*
* Copyright (c) 1999-2000 The NetBSD Foundation, Inc.
@@ -101,7 +101,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: cmds.c,v 1.6 2000/07/10 22:41:17 lukem Exp $");
+__RCSID("$NetBSD: cmds.c,v 1.7 2000/11/15 02:32:30 lukem Exp $");
#endif /* not lint */
#include <sys/param.h>
@@ -451,7 +451,7 @@
if (stat(filename, &stbuf) < 0 || !S_ISREG(stbuf.st_mode))
reply(550, "%s: not a plain file.", filename);
else
- reply(213, "%qu", (qufmt_t)stbuf.st_size);
+ reply(213, ULLF, (ULLT)stbuf.st_size);
break; }
case TYPE_A: {
FILE *fin;
@@ -477,7 +477,7 @@
}
(void) fclose(fin);
- reply(213, "%qd", (qdfmt_t)count);
+ reply(213, LLF, (LLT)count);
break; }
default:
reply(504, "SIZE not implemented for Type %c.", "?AEIL"[type]);
@@ -705,7 +705,7 @@
{
if (S_ISREG(fe->stat->st_mode))
- cprintf(fd, "%s=%lld;", fact, (long long)fe->stat->st_size);
+ cprintf(fd, "%s=" LLF ";", fact, (LLT)fe->stat->st_size);
}
static void
diff -r 46d371cce1d2 -r 6ee6447f2fe5 libexec/ftpd/conf.c
--- a/libexec/ftpd/conf.c Wed Nov 15 02:00:31 2000 +0000
+++ b/libexec/ftpd/conf.c Wed Nov 15 02:32:30 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: conf.c,v 1.34 2000/07/23 14:40:48 lukem Exp $ */
+/* $NetBSD: conf.c,v 1.35 2000/11/15 02:32:30 lukem Exp $ */
/*-
* Copyright (c) 1997-2000 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: conf.c,v 1.34 2000/07/23 14:40:48 lukem Exp $");
+__RCSID("$NetBSD: conf.c,v 1.35 2000/11/15 02:32:30 lukem Exp $");
#endif /* not lint */
#include <sys/types.h>
@@ -871,8 +871,10 @@
pids = NULL;
connections = 1;
- if ((fd = open(fn, O_RDWR | O_CREAT | O_EXLOCK, 0600)) == -1)
+ if ((fd = open(fn, O_RDWR | O_CREAT, 0600)) == -1)
return;
+ if (lockf(fd, F_TLOCK, 0) == -1)
+ goto cleanup_count;
if (fstat(fd, &sb) == -1)
goto cleanup_count;
if ((pids = malloc(sb.st_size + sizeof(pid_t))) == NULL)
@@ -910,7 +912,8 @@
(void)ftruncate(fd, count);
cleanup_count:
- (void)flock(fd, LOCK_UN);
+ if (lseek(fd, 0, SEEK_SET) != -1)
+ (void)lockf(fd, F_ULOCK, 0);
close(fd);
REASSIGN(pids, NULL);
}
diff -r 46d371cce1d2 -r 6ee6447f2fe5 libexec/ftpd/extern.h
--- a/libexec/ftpd/extern.h Wed Nov 15 02:00:31 2000 +0000
+++ b/libexec/ftpd/extern.h Wed Nov 15 02:32:30 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: extern.h,v 1.33 2000/11/13 11:50:46 itojun Exp $ */
+/* $NetBSD: extern.h,v 1.34 2000/11/15 02:32:30 lukem Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -157,9 +157,6 @@
char *xstrdup(const char *);
void yyerror(char *);
-typedef long long qdfmt_t;
-typedef unsigned long long qufmt_t;
-
typedef enum {
CLASS_GUEST,
CLASS_CHROOT,
@@ -213,20 +210,34 @@
#include <netinet/in.h>
-union sockunion {
- struct sockinet {
- u_char si_len;
- u_char si_family;
- u_short si_port;
- } su_si;
- struct sockaddr_in su_sin;
+#ifdef BSD4_4
+# define HAVE_SOCKADDR_SA_LEN 1
+#endif
+
+struct sockinet {
+ union sockunion {
+ struct sockaddr_in su_sin;
#ifdef INET6
- struct sockaddr_in6 su_sin6;
+ struct sockaddr_in6 su_sin6;
+#endif
+ } si_su;
+#if !HAVE_SOCKADDR_SA_LEN
+ int si_len;
#endif
};
-#define su_len su_si.si_len
-#define su_family su_si.si_family
-#define su_port su_si.si_port
+
+#if !HAVE_SOCKADDR_SA_LEN
+# define su_len si_len
+#else
+# define su_len si_su.su_sin.sin_len
+#endif
+#define su_addr si_su.su_sin.sin_addr
+#define su_family si_su.su_sin.sin_family
+#define su_port si_su.su_sin.sin_port
+#ifdef INET6
+# define su_6addr si_su.su_sin6.sin6_addr
+# define su_scope_id si_su.su_sin6.sin6_scope_id
+#endif
extern int yyparse(void);
@@ -235,11 +246,11 @@
#endif
-GLOBAL union sockunion ctrl_addr;
-GLOBAL union sockunion data_dest;
-GLOBAL union sockunion data_source;
-GLOBAL union sockunion his_addr;
-GLOBAL union sockunion pasv_addr;
+GLOBAL struct sockinet ctrl_addr;
+GLOBAL struct sockinet data_dest;
+GLOBAL struct sockinet data_source;
+GLOBAL struct sockinet his_addr;
+GLOBAL struct sockinet pasv_addr;
GLOBAL int connections;
GLOBAL struct ftpclass curclass;
GLOBAL int debug;
@@ -304,3 +315,25 @@
} while ((W) != NULL && *(W) == '\0')
#define PLURAL(s) ((s) == 1 ? "" : "s")
#define REASSIGN(X,Y) do { if (X) free(X); (X)=(Y); } while (/*CONSTCOND*/0)
+
+#ifndef IPPORT_ANONMAX
+# define IPPORT_ANONMAX 65535
+#endif
+
+#ifdef NO_LONG_LONG
+# define LLF "%ld"
+# define LLFP(x) "%" x "ld"
+# define LLT long
+# define ULLF "%lu"
+# define ULLFP(x) "%" x "lu"
+# define ULLT unsigned long
+# define STRTOLL(x,y,z) strtol(x,y,z)
+#else
+# define LLF "%lld"
+# define LLFP(x) "%" x "lld"
+# define LLT long long
+# define ULLF "%llu"
+# define ULLFP(x) "%" x "llu"
+# define ULLT unsigned long long
+# define STRTOLL(x,y,z) strtoll(x,y,z)
+#endif
diff -r 46d371cce1d2 -r 6ee6447f2fe5 libexec/ftpd/ftpcmd.y
--- a/libexec/ftpd/ftpcmd.y Wed Nov 15 02:00:31 2000 +0000
+++ b/libexec/ftpd/ftpcmd.y Wed Nov 15 02:32:30 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ftpcmd.y,v 1.54 2000/11/13 11:50:46 itojun Exp $ */
+/* $NetBSD: ftpcmd.y,v 1.55 2000/11/15 02:32:30 lukem Exp $ */
/*-
* Copyright (c) 1997-2000 The NetBSD Foundation, Inc.
@@ -83,7 +83,7 @@
#if 0
static char sccsid[] = "@(#)ftpcmd.y 8.3 (Berkeley) 4/6/94";
#else
-__RCSID("$NetBSD: ftpcmd.y,v 1.54 2000/11/13 11:50:46 itojun Exp $");
+__RCSID("$NetBSD: ftpcmd.y,v 1.55 2000/11/15 02:32:30 lukem Exp $");
#endif
#endif /* not lint */
@@ -227,26 +227,26 @@
if (logged_in) {
reply(-221, "%s", "");
reply(0,
- "Data traffic for this session was %qd byte%s in %qd file%s.",
- (qdfmt_t)total_data, PLURAL(total_data),
- (qdfmt_t)total_files, PLURAL(total_files));
+ "Data traffic for this session was " LLF " byte%s in " LLF " file%s.",
+ (LLT)total_data, PLURAL(total_data),
+ (LLT)total_files, PLURAL(total_files));
reply(0,
- "Total traffic for this session was %qd byte%s in %qd transfer%s.",
- (qdfmt_t)total_bytes, PLURAL(total_bytes),
- (qdfmt_t)total_xfers, PLURAL(total_xfers));
+ "Total traffic for this session was " LLF " byte%s in " LLF " transfer%s.",
+ (LLT)total_bytes, PLURAL(total_bytes),
+ (LLT)total_xfers, PLURAL(total_xfers));
}
reply(221,
"Thank you for using the FTP service on %s.",
hostname);
if (logged_in) {
syslog(LOG_INFO,
- "Data traffic: %qd byte%s in %qd file%s",
- (qdfmt_t)total_data, PLURAL(total_data),
- (qdfmt_t)total_files, PLURAL(total_files));
+ "Data traffic: " LLF " byte%s in " LLF " file%s",
+ (LLT)total_data, PLURAL(total_data),
+ (LLT)total_files, PLURAL(total_files));
syslog(LOG_INFO,
- "Total traffic: %qd byte%s in %qd transfer%s",
- (qdfmt_t)total_bytes, PLURAL(total_bytes),
- (qdfmt_t)total_xfers, PLURAL(total_xfers));
+ "Total traffic: " LLF " byte%s in " LLF " transfer%s",
+ (LLT)total_bytes, PLURAL(total_bytes),
+ (LLT)total_xfers, PLURAL(total_xfers));
}
dologout(0);
@@ -855,9 +855,9 @@
if ($2) {
fromname = NULL;
restart_point = $4; /* XXX $3 is only "int" */
- reply(350, "Restarting at %qd. %s",
- (qdfmt_t)restart_point,
- "Send STORE or RETRIEVE to initiate transfer.");
+ reply(350,
+ "Restarting at " LLF ". Send STORE or RETRIEVE to initiate transfer.",
+ (LLT)restart_point);
}
}
@@ -895,11 +895,12 @@
{
char *a, *p;
+ memset(&data_dest, 0, sizeof(data_dest));
data_dest.su_len = sizeof(struct sockaddr_in);
data_dest.su_family = AF_INET;
- p = (char *)&data_dest.su_sin.sin_port;
+ p = (char *)&data_dest.su_port;
p[0] = $9; p[1] = $11;
- a = (char *)&data_dest.su_sin.sin_addr;
+ a = (char *)&data_dest.su_addr;
a[0] = $1; a[1] = $3; a[2] = $5; a[3] = $7;
}
;
@@ -911,12 +912,12 @@
{
char *a, *p;
- data_dest.su_sin.sin_len =
- sizeof(struct sockaddr_in);
+ memset(&data_dest, 0, sizeof(data_dest));
+ data_dest.su_len = sizeof(struct sockaddr_in);
data_dest.su_family = AF_INET;
p = (char *)&data_dest.su_port;
p[0] = $15; p[1] = $17;
- a = (char *)&data_dest.su_sin.sin_addr;
+ a = (char *)&data_dest.su_addr;
a[0] = $5; a[1] = $7; a[2] = $9; a[3] = $11;
/* reject invalid LPRT command */
@@ -936,24 +937,23 @@
#ifdef INET6
char *a, *p;
- data_dest.su_sin6.sin6_len =
- sizeof(struct sockaddr_in6);
Home |
Main Index |
Thread Index |
Old Index