Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/libexec/ftpd major overhaul (just before netbsd 1.5 :-):
details: https://anonhg.NetBSD.org/src/rev/e4574e8f2422
branches: trunk
changeset: 487880:e4574e8f2422
user: lukem <lukem%NetBSD.org@localhost>
date: Wed Jun 14 13:44:21 2000 +0000
description:
major overhaul (just before netbsd 1.5 :-):
* implement draft-ietf-ftpext-mlst-10 commands, especially MLST and MLSD.
we already supported SIZE and MDTM. add the appropriate FEAT output lines.
* migrate a lot of the command code from ftpcmd.y and ftpd.c to cmds.c
* make dataconn(), feat(), lookup(), opts() and sizecmd() public
* modify struct tab so that it has a `flags' instead of `implemented' element,
and remove the `hasopts' element. If flags == 1, the command is implemented.
if flags == 2, the command is implemented and takes options
* add macros ISDOTDIR(x) (is x ".") and ISDOTDOTDIR(x) (is x "..")
* modify lreply() so that lreply(-2, ...) just outputs the given info without
a prefix or trailing \r\n. this saves doing b = printf(); total_* += b;
* enhance statcmd(). still needs work in the LPRT status stuff.
* crank version
diffstat:
libexec/ftpd/Makefile | 5 +-
libexec/ftpd/cmds.c | 779 +++++++++++++++++++++++++++++++++++++++++++++++++
libexec/ftpd/extern.h | 39 ++-
libexec/ftpd/ftpcmd.y | 306 +++++++-----------
libexec/ftpd/ftpd.8 | 9 +-
libexec/ftpd/ftpd.c | 273 +++--------------
libexec/ftpd/version.h | 4 +-
7 files changed, 990 insertions(+), 425 deletions(-)
diffs (truncated from 1837 to 300 lines):
diff -r c09ef79b42df -r e4574e8f2422 libexec/ftpd/Makefile
--- a/libexec/ftpd/Makefile Wed Jun 14 13:06:30 2000 +0000
+++ b/libexec/ftpd/Makefile Wed Jun 14 13:44:21 2000 +0000
@@ -1,12 +1,13 @@
-# $NetBSD: Makefile,v 1.40 2000/03/05 06:12:19 lukem Exp $
+# $NetBSD: Makefile,v 1.41 2000/06/14 13:44:21 lukem Exp $
# @(#)Makefile 8.2 (Berkeley) 4/4/94
SRCTOP= ../..
.include <bsd.crypto.mk>
PROG= ftpd
-SRCS= conf.c ftpd.c ftpcmd.y logutmp.c logwtmp.c popen.c
+SRCS= cmds.c conf.c ftpd.c ftpcmd.y logutmp.c logwtmp.c popen.c
CPPFLAGS+=-DHASSETPROCTITLE
+# CPPFLAGS+=-DDEBUG # XXX for lukem testing
DPADD+= ${LIBCRYPT} ${LIBUTIL}
LDADD+= -lcrypt -lutil
MAN= ftpd.conf.5 ftpusers.5 ftpd.8
diff -r c09ef79b42df -r e4574e8f2422 libexec/ftpd/cmds.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/libexec/ftpd/cmds.c Wed Jun 14 13:44:21 2000 +0000
@@ -0,0 +1,779 @@
+/* $NetBSD: cmds.c,v 1.1 2000/06/14 13:44:22 lukem Exp $ */
+
+/*
+ * Copyright (c) 1999-2000 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Luke Mewburn.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Copyright (c) 1985, 1988, 1990, 1992, 1993, 1994
+ * The Regents of the University of California. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * Copyright (C) 1997 and 1998 WIDE Project.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the project nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE PROJECT AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE PROJECT OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+
+#include <sys/cdefs.h>
+#ifndef lint
+__RCSID("$NetBSD: cmds.c,v 1.1 2000/06/14 13:44:22 lukem Exp $");
+#endif /* not lint */
+
+#include <sys/param.h>
+#include <sys/stat.h>
+
+#include <arpa/ftp.h>
+
+#include <dirent.h>
+#include <errno.h>
+#include <setjmp.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <tzfile.h>
+#include <unistd.h>
+
+#include "extern.h"
+
+typedef struct {
+ const char *path; /* full pathname */
+ const char *display; /* name to display */
+ struct stat *stat; /* stat of path */
+ struct stat *pdirstat; /* stat of path's parent dir */
+ int iscurdir; /* nonzero if name is the current dir */
+} factelem;
+
+static void ack(const char *);
+static void fact_type(const char *, FILE *, factelem *);
+static void fact_size(const char *, FILE *, factelem *);
+static void fact_modify(const char *, FILE *, factelem *);
+static void fact_perm(const char *, FILE *, factelem *);
+static void fact_unique(const char *, FILE *, factelem *);
+static void fact_unix_group(const char *, FILE *, factelem *);
+static void fact_unix_mode(const char *, FILE *, factelem *);
+static void fact_unix_owner(const char *, FILE *, factelem *);
+static int matchgroup(gid_t, gid_t *, int);
+static void mlsname(FILE *, factelem *);
+static void replydirname(const char *, const char *);
+
+struct ftpfact {
+ const char *name; /* name of fact */
+ int enabled; /* if fact is enabled */
+ void (*display)(const char *, FILE *, factelem *);
+ /* function to display fact */
+};
+
+struct ftpfact facttab[] = {
+ { "Type", 1, fact_type },
+ { "Size", 1, fact_size },
+ { "Modify", 1, fact_modify },
+ { "Perm", 1, fact_perm },
+ { "Unique", 1, fact_unique },
+ { "UNIX.mode", 1, fact_unix_mode },
+ { "UNIX.owner", 0, fact_unix_owner },
+ { "UNIX.group", 0, fact_unix_group },
+ /* "Create" */
+ /* "Lang" */
+ /* "Media-Type" */
+ /* "CharSet" */
+ { NULL, NULL, },
+};
+
+
+void
+cwd(const char *path)
+{
+
+ if (chdir(path) < 0)
+ perror_reply(550, path);
+ else {
+ show_chdir_messages(250);
+ ack("CWD");
+ }
+}
+
+void
+delete(const char *name)
+{
+ char *p = NULL;
+
+ if (remove(name) < 0) {
+ p = strerror(errno);
+ perror_reply(550, name);
+ } else
+ ack("DELE");
+ logcmd("delete", -1, name, NULL, NULL, p);
+}
+
+void
+feat(void)
+{
+ int i;
+
+ lreply(211, "Features supported");
+ lreply(-1, " MDTM");
+ lreply(-2, " MLST ");
+ for (i = 0; facttab[i].name; i++)
+ lreply(-2, "%s%s;", facttab[i].name,
+ facttab[i].enabled ? "*" : "");
+ lreply(-1, "");
+ lreply(-1, " REST STREAM");
+ lreply(-1, " SIZE");
+ lreply(-1, " TVFS");
+ reply(211, "End");
+}
+
+void
+makedir(const char *name)
+{
+ char *p = NULL;
+
+ if (mkdir(name, 0777) < 0) {
+ p = strerror(errno);
+ perror_reply(550, name);
+ } else
+ replydirname(name, "directory created.");
+ logcmd("mkdir", -1, name, NULL, NULL, p);
+}
+
+void
+mlsd(const char *path)
+{
+ FILE *dout;
+ DIR *dirp;
+ struct dirent *dp;
+ struct stat sb, pdirstat;
+ char name[MAXPATHLEN];
+ factelem f;
+
+ if (path == NULL)
+ path = ".";
+ if (stat(path, &pdirstat) == -1) {
+ mlsdperror:
+ perror_reply(550, path);
+ return;
+ }
+ if (! S_ISDIR(pdirstat.st_mode)) {
+ errno = ENOTDIR;
+ goto mlsdperror;
+ }
+#ifdef DEBUG /* send mlsd to ctrl connection not data connection */
+ dout = stdout;
+ lreply(250, "MLSD %s", path);
+#else
+ dout = dataconn("MLSD", (off_t)-1, "w");
+ if (dout == NULL)
+ return;
+#endif
+
+ if ((dirp = opendir(path)) == NULL)
+ goto mlsdperror;
+ f.stat = &sb;
+ while ((dp = readdir(dirp)) != NULL) {
+ snprintf(name, sizeof(name), "%s/%s", path, dp->d_name);
+/* printf("got >%s< >%s<\n", dp->d_name, name); */
+ if (stat(name, &sb) == -1)
+ continue;
+ f.path = name;
+ if (ISDOTDIR(dp->d_name)) { /* special case curdir: */
+ f.display = path; /* set name to real name */
+ f.iscurdir = 1; /* flag name is curdir */
+ f.pdirstat = NULL; /* require stat of parent */
+ } else {
+ f.display = dp->d_name;
+ f.iscurdir = 0;
+ if (ISDOTDOTDIR(dp->d_name))
+ f.pdirstat = NULL;
+ else
+ f.pdirstat = &pdirstat; /* cache parent stat */
+ }
+ mlsname(dout, &f);
+ }
+ (void)closedir(dirp);
Home |
Main Index |
Thread Index |
Old Index