summaryrefslogtreecommitdiff
path: root/crypto/kerberosIV/appl/ftp/ftpd
diff options
context:
space:
mode:
authorAssar Westerlund <assar@FreeBSD.org>2000-12-29 21:00:22 +0000
committerAssar Westerlund <assar@FreeBSD.org>2000-12-29 21:00:22 +0000
commit5ad8ddfb6fdac21b0302d9dae0891ff8babd2f6f (patch)
tree3be1655d8572aa7a94f884419466a6be1d5e9e35 /crypto/kerberosIV/appl/ftp/ftpd
parentee695f07e219a80adee805e5a03a592ff2bb5558 (diff)
Notes
Diffstat (limited to 'crypto/kerberosIV/appl/ftp/ftpd')
-rw-r--r--crypto/kerberosIV/appl/ftp/ftpd/ftpcmd.y8
-rw-r--r--crypto/kerberosIV/appl/ftp/ftpd/ftpd.c116
-rw-r--r--crypto/kerberosIV/appl/ftp/ftpd/ls.c11
-rw-r--r--crypto/kerberosIV/appl/ftp/ftpd/pathnames.h3
4 files changed, 66 insertions, 72 deletions
diff --git a/crypto/kerberosIV/appl/ftp/ftpd/ftpcmd.y b/crypto/kerberosIV/appl/ftp/ftpd/ftpcmd.y
index 07ff9a5b2d8d..c48202967926 100644
--- a/crypto/kerberosIV/appl/ftp/ftpd/ftpcmd.y
+++ b/crypto/kerberosIV/appl/ftp/ftpd/ftpcmd.y
@@ -43,7 +43,7 @@
%{
#include "ftpd_locl.h"
-RCSID("$Id: ftpcmd.y,v 1.56 1999/10/26 11:56:23 assar Exp $");
+RCSID("$Id: ftpcmd.y,v 1.56.2.2 2000/06/23 02:48:19 assar Exp $");
off_t restart_point;
@@ -577,7 +577,7 @@ cmd
}
| SYST CRLF
{
-#if defined(unix) || defined(__unix__) || defined(__unix) || defined(_AIX) || defined(_CRAY)
+#if !defined(WIN32) && !defined(__EMX__) && !defined(__OS2__) && !defined(__CYGWIN32__)
reply(215, "UNIX Type: L%d", NBBY);
#else
reply(215, "UNKNOWN Type: L%d", NBBY);
@@ -620,7 +620,9 @@ cmd
"%s: not a plain file.", $3);
} else {
struct tm *t;
- t = gmtime(&stbuf.st_mtime);
+ time_t mtime = stbuf.st_mtime;
+
+ t = gmtime(&mtime);
reply(213,
"%04d%02d%02d%02d%02d%02d",
t->tm_year + 1900,
diff --git a/crypto/kerberosIV/appl/ftp/ftpd/ftpd.c b/crypto/kerberosIV/appl/ftp/ftpd/ftpd.c
index d3c9a6ac4598..51daa3fae0e5 100644
--- a/crypto/kerberosIV/appl/ftp/ftpd/ftpd.c
+++ b/crypto/kerberosIV/appl/ftp/ftpd/ftpd.c
@@ -38,7 +38,7 @@
#endif
#include "getarg.h"
-RCSID("$Id: ftpd.c,v 1.131 1999/11/30 19:18:38 assar Exp $");
+RCSID("$Id: ftpd.c,v 1.131.2.4 2000/09/26 09:30:26 assar Exp $");
static char version[] = "Version 6.00";
@@ -195,14 +195,13 @@ parse_auth_level(char *str)
* Print usage and die.
*/
-static int debug_flag;
static int interactive_flag;
static char *guest_umask_string;
static char *port_string;
static char *umask_string;
static char *auth_string;
-int use_builtin_ls;
+int use_builtin_ls = -1;
static int help_flag;
static int version_flag;
@@ -216,8 +215,8 @@ struct getargs args[] = {
{ NULL, 't', arg_integer, &ftpd_timeout, "initial timeout" },
{ NULL, 'T', arg_integer, &maxtimeout, "max timeout" },
{ NULL, 'u', arg_string, &umask_string, "umask for user logins" },
- { NULL, 'd', arg_flag, &debug_flag, "enable debugging" },
- { NULL, 'v', arg_flag, &debug_flag, "enable debugging" },
+ { NULL, 'd', arg_flag, &debug, "enable debugging" },
+ { NULL, 'v', arg_flag, &debug, "enable debugging" },
{ "builtin-ls", 'B', arg_flag, &use_builtin_ls, "use built-in ls to list files" },
{ "version", 0, arg_flag, &version_flag },
{ "help", 'h', arg_flag, &help_flag }
@@ -232,6 +231,24 @@ usage (int code)
exit (code);
}
+/* output contents of a file */
+static int
+show_file(const char *file, int code)
+{
+ FILE *f;
+ char buf[128];
+
+ f = fopen(file, "r");
+ if(f == NULL)
+ return -1;
+ while(fgets(buf, sizeof(buf), f)){
+ buf[strcspn(buf, "\r\n")] = '\0';
+ lreply(code, "%s", buf);
+ }
+ fclose(f);
+ return 0;
+}
+
int
main(int argc, char **argv)
{
@@ -377,27 +394,12 @@ main(int argc, char **argv)
tmpline[0] = '\0';
/* If logins are disabled, print out the message. */
- if ((fd = fopen(_PATH_NOLOGIN,"r")) != NULL) {
- while (fgets(line, sizeof(line), fd) != NULL) {
- if ((cp = strchr(line, '\n')) != NULL)
- *cp = '\0';
- lreply(530, "%s", line);
- }
- fflush(stdout);
- fclose(fd);
+ if(show_file(_PATH_NOLOGIN, 530) == 0) {
reply(530, "System not available.");
exit(0);
}
- if ((fd = fopen(_PATH_FTPWELCOME, "r")) != NULL) {
- while (fgets(line, sizeof(line), fd) != NULL) {
- if ((cp = strchr(line, '\n')) != NULL)
- *cp = '\0';
- lreply(220, "%s", line);
- }
- fflush(stdout);
- fclose(fd);
- /* reply(220,) must follow */
- }
+ show_file(_PATH_FTPWELCOME, 220);
+ /* reply(220,) must follow */
gethostname(hostname, sizeof(hostname));
reply(220, "%s FTP server (%s"
@@ -704,24 +706,6 @@ checkaccess(char *name)
#undef ALLOWED
#undef NOT_ALLOWED
-/* output contents of /etc/issue.net, or /etc/issue */
-static void
-show_issue(int code)
-{
- FILE *f;
- char buf[128];
-
- f = fopen("/etc/issue.net", "r");
- if(f == NULL)
- f = fopen("/etc/issue", "r");
- if(f){
- while(fgets(buf, sizeof(buf), f)){
- buf[strcspn(buf, "\r\n")] = '\0';
- lreply(code, "%s", buf);
- }
- fclose(f);
- }
-}
int do_login(int code, char *passwd)
{
@@ -765,28 +749,33 @@ int do_login(int code, char *passwd)
reply(550, "Can't set uid.");
return -1;
}
+
+ if(use_builtin_ls == -1) {
+ struct stat st;
+ /* if /bin/ls exist and is a regular file, use it, otherwise
+ use built-in ls */
+ if(stat("/bin/ls", &st) == 0 &&
+ S_ISREG(st.st_mode))
+ use_builtin_ls = 0;
+ else
+ use_builtin_ls = 1;
+ }
+
/*
* Display a login message, if it exists.
* N.B. reply(code,) must follow the message.
*/
- if ((fd = fopen(_PATH_FTPLOGINMESG, "r")) != NULL) {
- char *cp, line[LINE_MAX];
-
- while (fgets(line, sizeof(line), fd) != NULL) {
- if ((cp = strchr(line, '\n')) != NULL)
- *cp = '\0';
- lreply(code, "%s", line);
- }
- }
+ show_file(_PATH_FTPLOGINMESG, code);
+ if(show_file(_PATH_ISSUE_NET, code) != 0)
+ show_file(_PATH_ISSUE, code);
if (guest) {
- show_issue(code);
reply(code, "Guest login ok, access restrictions apply.");
#ifdef HAVE_SETPROCTITLE
snprintf (proctitle, sizeof(proctitle),
"%s: anonymous/%s",
remotehost,
passwd);
- setproctitle(proctitle);
+ setproctitle("%s", proctitle);
#endif /* HAVE_SETPROCTITLE */
if (logging) {
char data_addr[256];
@@ -803,11 +792,10 @@ int do_login(int code, char *passwd)
passwd);
}
} else {
- show_issue(code);
reply(code, "User %s logged in.", pw->pw_name);
#ifdef HAVE_SETPROCTITLE
snprintf(proctitle, sizeof(proctitle), "%s: %s", remotehost, pw->pw_name);
- setproctitle(proctitle);
+ setproctitle("%s", proctitle);
#endif /* HAVE_SETPROCTITLE */
if (logging) {
char data_addr[256];
@@ -957,8 +945,8 @@ retrieve(const char *cmd, char *name)
{".tar", "/bin/gtar cPf - %s", NULL},
{".tar.gz", "/bin/gtar zcPf - %s", NULL},
{".tar.Z", "/bin/gtar ZcPf - %s", NULL},
- {".gz", "/bin/gzip -c %s", "/bin/gzip -c -d %s"},
- {".Z", "/bin/compress -c %s", "/bin/uncompress -c -d %s"},
+ {".gz", "/bin/gzip -c -- %s", "/bin/gzip -c -d -- %s"},
+ {".Z", "/bin/compress -c -- %s", "/bin/uncompress -c -- %s"},
{NULL, NULL}
};
struct cmds *p;
@@ -1211,7 +1199,7 @@ dataconn(const char *name, off_t size, const char *mode)
*sizebuf = '\0';
if (pdata >= 0) {
struct sockaddr_storage from_ss;
- struct sockaddr *from = (struct sockaddr *)&from;
+ struct sockaddr *from = (struct sockaddr *)&from_ss;
int s;
int fromlen = sizeof(from_ss);
@@ -1501,7 +1489,7 @@ statfilecmd(char *filename)
int c;
char line[LINE_MAX];
- snprintf(line, sizeof(line), "/bin/ls -la %s", filename);
+ snprintf(line, sizeof(line), "/bin/ls -la -- %s", filename);
fin = ftpd_popen(line, "r", 1, 0);
lreply(211, "status of %s:", filename);
while ((c = getc(fin)) != EOF) {
@@ -1782,7 +1770,7 @@ dolog(struct sockaddr *sa)
inaddr2str (sin->sin_addr, remotehost, sizeof(remotehost));
#ifdef HAVE_SETPROCTITLE
snprintf(proctitle, sizeof(proctitle), "%s: connected", remotehost);
- setproctitle(proctitle);
+ setproctitle("%s", proctitle);
#endif /* HAVE_SETPROCTITLE */
if (logging) {
@@ -2093,9 +2081,9 @@ list_file(char *file)
pdata = -1;
} else {
#ifdef HAVE_LS_A
- const char *cmd = "/bin/ls -lA %s";
+ const char *cmd = "/bin/ls -lA -- %s";
#else
- const char *cmd = "/bin/ls -la %s";
+ const char *cmd = "/bin/ls -la -- %s";
#endif
retrieve(cmd, file);
}
@@ -2146,8 +2134,8 @@ send_file_list(char *whichf)
*/
if (dirname[0] == '-' && *dirlist == NULL &&
transflag == 0) {
- retrieve("/bin/ls %s", dirname);
- goto out;
+ list_file(dirname);
+ goto out;
}
perror_reply(550, whichf);
if (dout != NULL) {
@@ -2241,7 +2229,7 @@ find(char *pattern)
FILE *f;
snprintf(line, sizeof(line),
- "/bin/locate -d %s %s",
+ "/bin/locate -d %s -- %s",
ftp_rooted("/etc/locatedb"),
pattern);
f = ftpd_popen(line, "r", 1, 1);
diff --git a/crypto/kerberosIV/appl/ftp/ftpd/ls.c b/crypto/kerberosIV/appl/ftp/ftpd/ls.c
index 97eb77ed906d..6e2c9a188cae 100644
--- a/crypto/kerberosIV/appl/ftp/ftpd/ls.c
+++ b/crypto/kerberosIV/appl/ftp/ftpd/ls.c
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 1999 Kungliga Tekniska Högskolan
+ * Copyright (c) 1999 - 2000 Kungliga Tekniska Högskolan
* (Royal Institute of Technology, Stockholm, Sweden).
* All rights reserved.
*
@@ -32,7 +32,7 @@
#include "ftpd_locl.h"
-RCSID("$Id: ls.c,v 1.13 1999/11/20 20:49:41 assar Exp $");
+RCSID("$Id: ls.c,v 1.13.2.2 2000/06/23 02:51:09 assar Exp $");
struct fileinfo {
struct stat st;
@@ -164,9 +164,10 @@ make_fileinfo(const char *filename, struct fileinfo *file, int flags)
{
time_t t = time(NULL);
- struct tm *tm = localtime(&st->st_mtime);
- if((t - st->st_mtime > 6*30*24*60*60) ||
- (st->st_mtime - t > 6*30*24*60*60))
+ time_t mtime = st->st_mtime;
+ struct tm *tm = localtime(&mtime);
+ if((t - mtime > 6*30*24*60*60) ||
+ (mtime - t > 6*30*24*60*60))
strftime(buf, sizeof(buf), "%b %e %Y", tm);
else
strftime(buf, sizeof(buf), "%b %e %H:%M", tm);
diff --git a/crypto/kerberosIV/appl/ftp/ftpd/pathnames.h b/crypto/kerberosIV/appl/ftp/ftpd/pathnames.h
index 1bd2be1a1efa..ff2041bb6c79 100644
--- a/crypto/kerberosIV/appl/ftp/ftpd/pathnames.h
+++ b/crypto/kerberosIV/appl/ftp/ftpd/pathnames.h
@@ -53,3 +53,6 @@
#define _PATH_FTPCHROOT "/etc/ftpchroot"
#define _PATH_FTPWELCOME "/etc/ftpwelcome"
#define _PATH_FTPLOGINMESG "/etc/motd"
+
+#define _PATH_ISSUE "/etc/issue"
+#define _PATH_ISSUE_NET "/etc/issue.net"