2015-08-10 10:32:49 +03:00
|
|
|
/* $NetBSD: cmds.c,v 1.34 2015/08/10 07:32:49 shm Exp $ */
|
2000-06-14 17:44:21 +04:00
|
|
|
|
|
|
|
/*
|
2009-03-02 06:47:44 +03:00
|
|
|
* Copyright (c) 1999-2009 The NetBSD Foundation, Inc.
|
2000-06-14 17:44:21 +04:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* 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.
|
2003-08-07 13:46:37 +04:00
|
|
|
* 3. Neither the name of the University nor the names of its contributors
|
2000-06-14 17:44:21 +04:00
|
|
|
* 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
|
2015-08-10 10:32:49 +03:00
|
|
|
__RCSID("$NetBSD: cmds.c,v 1.34 2015/08/10 07:32:49 shm Exp $");
|
2000-06-14 17:44:21 +04:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#include <arpa/ftp.h>
|
|
|
|
|
|
|
|
#include <dirent.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <tzfile.h>
|
|
|
|
#include <unistd.h>
|
2002-10-25 05:45:37 +04:00
|
|
|
#include <ctype.h>
|
2000-06-14 17:44:21 +04:00
|
|
|
|
2000-06-17 03:17:41 +04:00
|
|
|
#ifdef KERBEROS5
|
|
|
|
#include <krb5/krb5.h>
|
|
|
|
#endif
|
|
|
|
|
2000-06-14 17:44:21 +04:00
|
|
|
#include "extern.h"
|
|
|
|
|
2002-02-13 18:15:23 +03:00
|
|
|
typedef enum {
|
|
|
|
FE_MLSD = 1<<0, /* if op is MLSD (MLST otherwise ) */
|
|
|
|
FE_ISCURDIR = 1<<1, /* if name is the current directory */
|
|
|
|
} factflag_t;
|
|
|
|
|
2000-06-14 17:44:21 +04:00
|
|
|
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 */
|
2002-02-13 18:15:23 +03:00
|
|
|
factflag_t flags; /* flags */
|
2000-06-14 17:44:21 +04:00
|
|
|
} factelem;
|
|
|
|
|
|
|
|
static void ack(const char *);
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
static void base64_encode(const char *, size_t, char *, int);
|
2000-06-14 17:44:21 +04:00
|
|
|
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 *);
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
static int matchgroup(gid_t);
|
2000-06-14 17:44:21 +04:00
|
|
|
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 },
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
#define FACT_TYPE 0
|
2000-06-14 17:44:21 +04:00
|
|
|
{ "Size", 1, fact_size },
|
|
|
|
{ "Modify", 1, fact_modify },
|
|
|
|
{ "Perm", 1, fact_perm },
|
|
|
|
{ "Unique", 1, fact_unique },
|
|
|
|
/* "Create" */
|
|
|
|
/* "Lang" */
|
|
|
|
/* "Media-Type" */
|
|
|
|
/* "CharSet" */
|
|
|
|
};
|
|
|
|
|
2000-06-19 21:08:05 +04:00
|
|
|
#define FACTTABSIZE (sizeof(facttab) / sizeof(struct ftpfact))
|
|
|
|
|
2003-01-08 21:07:31 +03:00
|
|
|
static char cached_path[MAXPATHLEN + 1] = "/";
|
|
|
|
static void discover_path(char *, const char *);
|
2000-06-14 17:44:21 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
cwd(const char *path)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (chdir(path) < 0)
|
|
|
|
perror_reply(550, path);
|
|
|
|
else {
|
|
|
|
show_chdir_messages(250);
|
|
|
|
ack("CWD");
|
2003-01-08 21:07:31 +03:00
|
|
|
if (getcwd(cached_path, MAXPATHLEN) == NULL) {
|
|
|
|
discover_path(cached_path, path);
|
|
|
|
}
|
2000-06-14 17:44:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
delete(const char *name)
|
|
|
|
{
|
|
|
|
char *p = NULL;
|
|
|
|
|
|
|
|
if (remove(name) < 0) {
|
|
|
|
p = strerror(errno);
|
|
|
|
perror_reply(550, name);
|
|
|
|
} else
|
|
|
|
ack("DELE");
|
2000-12-18 05:32:50 +03:00
|
|
|
logxfer("delete", -1, name, NULL, NULL, p);
|
2000-06-14 17:44:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
feat(void)
|
|
|
|
{
|
2009-03-15 10:48:36 +03:00
|
|
|
size_t i;
|
2000-06-14 17:44:21 +04:00
|
|
|
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
reply(-211, "Features supported");
|
|
|
|
cprintf(stdout, " MDTM\r\n");
|
|
|
|
cprintf(stdout, " MLST ");
|
2000-06-19 21:08:05 +04:00
|
|
|
for (i = 0; i < FACTTABSIZE; i++)
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
cprintf(stdout, "%s%s;", facttab[i].name,
|
2000-06-14 17:44:21 +04:00
|
|
|
facttab[i].enabled ? "*" : "");
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
cprintf(stdout, "\r\n");
|
|
|
|
cprintf(stdout, " REST STREAM\r\n");
|
|
|
|
cprintf(stdout, " SIZE\r\n");
|
|
|
|
cprintf(stdout, " TVFS\r\n");
|
2000-06-14 17:44:21 +04:00
|
|
|
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.");
|
2000-12-18 05:32:50 +03:00
|
|
|
logxfer("mkdir", -1, name, NULL, NULL, p);
|
2000-06-14 17:44:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mlsd(const char *path)
|
|
|
|
{
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
struct dirent *dp;
|
|
|
|
struct stat sb, pdirstat;
|
2000-06-14 17:44:21 +04:00
|
|
|
factelem f;
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
FILE *dout;
|
|
|
|
DIR *dirp;
|
|
|
|
char name[MAXPATHLEN];
|
|
|
|
int hastypefact;
|
2000-06-14 17:44:21 +04:00
|
|
|
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
hastypefact = facttab[FACT_TYPE].enabled;
|
2000-06-14 17:44:21 +04:00
|
|
|
if (path == NULL)
|
|
|
|
path = ".";
|
|
|
|
if (stat(path, &pdirstat) == -1) {
|
|
|
|
mlsdperror:
|
|
|
|
perror_reply(550, path);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (! S_ISDIR(pdirstat.st_mode)) {
|
|
|
|
errno = ENOTDIR;
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
perror_reply(501, path);
|
|
|
|
return;
|
2000-06-14 17:44:21 +04:00
|
|
|
}
|
2002-02-01 07:35:30 +03:00
|
|
|
if ((dirp = opendir(path)) == NULL)
|
|
|
|
goto mlsdperror;
|
|
|
|
|
2000-06-14 17:44:21 +04:00
|
|
|
dout = dataconn("MLSD", (off_t)-1, "w");
|
2015-08-10 10:32:49 +03:00
|
|
|
if (dout == NULL) {
|
|
|
|
(void) closedir(dirp);
|
2000-06-14 17:44:21 +04:00
|
|
|
return;
|
2015-08-10 10:32:49 +03:00
|
|
|
}
|
2000-06-14 17:44:21 +04:00
|
|
|
|
2002-02-13 18:15:23 +03:00
|
|
|
memset(&f, 0, sizeof(f));
|
2000-06-14 17:44:21 +04:00
|
|
|
f.stat = &sb;
|
2002-02-13 18:15:23 +03:00
|
|
|
f.flags |= FE_MLSD;
|
2000-06-14 17:44:21 +04:00
|
|
|
while ((dp = readdir(dirp)) != NULL) {
|
|
|
|
snprintf(name, sizeof(name), "%s/%s", path, dp->d_name);
|
|
|
|
if (ISDOTDIR(dp->d_name)) { /* special case curdir: */
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
if (! hastypefact)
|
|
|
|
continue;
|
|
|
|
f.pdirstat = NULL; /* require stat of parent */
|
2000-06-14 17:44:21 +04:00
|
|
|
f.display = path; /* set name to real name */
|
2002-02-13 18:15:23 +03:00
|
|
|
f.flags |= FE_ISCURDIR; /* flag name is curdir */
|
2000-06-14 17:44:21 +04:00
|
|
|
} else {
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
if (ISDOTDOTDIR(dp->d_name)) {
|
|
|
|
if (! hastypefact)
|
|
|
|
continue;
|
2000-06-14 17:44:21 +04:00
|
|
|
f.pdirstat = NULL;
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
} else
|
2000-06-14 17:44:21 +04:00
|
|
|
f.pdirstat = &pdirstat; /* cache parent stat */
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
f.display = dp->d_name;
|
2002-02-13 18:15:23 +03:00
|
|
|
f.flags &= ~FE_ISCURDIR;
|
2000-06-14 17:44:21 +04:00
|
|
|
}
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
if (stat(name, &sb) == -1)
|
|
|
|
continue;
|
|
|
|
f.path = name;
|
2000-06-14 17:44:21 +04:00
|
|
|
mlsname(dout, &f);
|
|
|
|
}
|
|
|
|
(void)closedir(dirp);
|
|
|
|
|
|
|
|
if (ferror(dout) != 0)
|
|
|
|
perror_reply(550, "Data connection");
|
|
|
|
else
|
|
|
|
reply(226, "MLSD complete.");
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
closedataconn(dout);
|
2000-06-14 17:44:21 +04:00
|
|
|
total_xfers_out++;
|
|
|
|
total_xfers++;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mlst(const char *path)
|
|
|
|
{
|
|
|
|
struct stat sb;
|
|
|
|
factelem f;
|
|
|
|
|
|
|
|
if (path == NULL)
|
|
|
|
path = ".";
|
|
|
|
if (stat(path, &sb) == -1) {
|
|
|
|
perror_reply(550, path);
|
|
|
|
return;
|
|
|
|
}
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
reply(-250, "MLST %s", path);
|
2002-02-13 18:15:23 +03:00
|
|
|
memset(&f, 0, sizeof(f));
|
2000-06-14 17:44:21 +04:00
|
|
|
f.path = path;
|
|
|
|
f.display = path;
|
|
|
|
f.stat = &sb;
|
|
|
|
f.pdirstat = NULL;
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
CPUTC(' ', stdout);
|
2000-06-14 17:44:21 +04:00
|
|
|
mlsname(stdout, &f);
|
|
|
|
reply(250, "End");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
opts(const char *command)
|
|
|
|
{
|
|
|
|
struct tab *c;
|
|
|
|
char *ep;
|
|
|
|
|
|
|
|
if ((ep = strchr(command, ' ')) != NULL)
|
|
|
|
*ep++ = '\0';
|
|
|
|
c = lookup(cmdtab, command);
|
|
|
|
if (c == NULL) {
|
2002-10-12 12:35:16 +04:00
|
|
|
reply(502, "Unknown command '%s'.", command);
|
2000-06-14 17:44:21 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (! CMD_IMPLEMENTED(c)) {
|
2002-10-11 14:57:51 +04:00
|
|
|
reply(502, "%s command not implemented.", c->name);
|
2000-06-14 17:44:21 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (! CMD_HAS_OPTIONS(c)) {
|
|
|
|
reply(501, "%s command does not support persistent options.",
|
|
|
|
c->name);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* special case: MLST */
|
|
|
|
if (strcasecmp(command, "MLST") == 0) {
|
2000-06-19 21:08:05 +04:00
|
|
|
int enabled[FACTTABSIZE];
|
2009-03-15 10:48:36 +03:00
|
|
|
size_t i, onedone;
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
size_t len;
|
2000-06-14 17:44:21 +04:00
|
|
|
char *p;
|
|
|
|
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
for (i = 0; i < sizeof(enabled) / sizeof(int); i++)
|
|
|
|
enabled[i] = 0;
|
2000-06-14 17:44:21 +04:00
|
|
|
if (ep == NULL || *ep == '\0')
|
|
|
|
goto displaymlstopts;
|
|
|
|
|
|
|
|
/* don't like spaces, and need trailing ; */
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
len = strlen(ep);
|
|
|
|
if (strchr(ep, ' ') != NULL || ep[len - 1] != ';') {
|
|
|
|
badmlstopt:
|
2000-06-14 17:44:21 +04:00
|
|
|
reply(501, "Invalid MLST options");
|
|
|
|
return;
|
|
|
|
}
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
ep[len - 1] = '\0';
|
2000-06-14 17:44:21 +04:00
|
|
|
while ((p = strsep(&ep, ";")) != NULL) {
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
if (*p == '\0')
|
|
|
|
goto badmlstopt;
|
2000-06-19 21:08:05 +04:00
|
|
|
for (i = 0; i < FACTTABSIZE; i++)
|
2000-06-14 17:44:21 +04:00
|
|
|
if (strcasecmp(p, facttab[i].name) == 0) {
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
enabled[i] = 1;
|
2000-06-14 17:44:21 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
displaymlstopts:
|
2000-06-19 21:08:05 +04:00
|
|
|
for (i = 0; i < FACTTABSIZE; i++)
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
facttab[i].enabled = enabled[i];
|
|
|
|
cprintf(stdout, "200 MLST OPTS");
|
2000-06-19 21:08:05 +04:00
|
|
|
for (i = onedone = 0; i < FACTTABSIZE; i++) {
|
2000-06-14 17:44:21 +04:00
|
|
|
if (facttab[i].enabled) {
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
cprintf(stdout, "%s%s;", onedone ? "" : " ",
|
2000-06-14 17:44:21 +04:00
|
|
|
facttab[i].name);
|
|
|
|
onedone++;
|
|
|
|
}
|
|
|
|
}
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
cprintf(stdout, "\r\n");
|
|
|
|
fflush(stdout);
|
2000-06-14 17:44:21 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* default cases */
|
|
|
|
if (ep != NULL && *ep != '\0')
|
2006-02-01 17:20:12 +03:00
|
|
|
REASSIGN(c->options, ftpd_strdup(ep));
|
2000-06-14 17:44:21 +04:00
|
|
|
if (c->options != NULL)
|
|
|
|
reply(200, "Options for %s are '%s'.", c->name,
|
|
|
|
c->options);
|
|
|
|
else
|
|
|
|
reply(200, "No options defined for %s.", c->name);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
pwd(void)
|
|
|
|
{
|
|
|
|
char path[MAXPATHLEN];
|
|
|
|
|
2003-01-08 21:07:31 +03:00
|
|
|
if (getcwd(path, sizeof(path) - 1) == NULL) {
|
|
|
|
if (chdir(cached_path) < 0) {
|
|
|
|
reply(550, "Can't get the current directory: %s.",
|
|
|
|
strerror(errno));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
(void)strlcpy(path, cached_path, MAXPATHLEN);
|
|
|
|
}
|
|
|
|
replydirname(path, "is the current directory.");
|
2000-06-14 17:44:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
removedir(const char *name)
|
|
|
|
{
|
|
|
|
char *p = NULL;
|
|
|
|
|
|
|
|
if (rmdir(name) < 0) {
|
|
|
|
p = strerror(errno);
|
|
|
|
perror_reply(550, name);
|
|
|
|
} else
|
|
|
|
ack("RMD");
|
2000-12-18 05:32:50 +03:00
|
|
|
logxfer("rmdir", -1, name, NULL, NULL, p);
|
2000-06-14 17:44:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
renamefrom(const char *name)
|
|
|
|
{
|
|
|
|
struct stat st;
|
|
|
|
|
|
|
|
if (stat(name, &st) < 0) {
|
|
|
|
perror_reply(550, name);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
reply(350, "File exists, ready for destination name");
|
2006-02-01 17:20:12 +03:00
|
|
|
return (ftpd_strdup(name));
|
2000-06-14 17:44:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
renamecmd(const char *from, const char *to)
|
|
|
|
{
|
|
|
|
char *p = NULL;
|
|
|
|
|
|
|
|
if (rename(from, to) < 0) {
|
|
|
|
p = strerror(errno);
|
|
|
|
perror_reply(550, "rename");
|
|
|
|
} else
|
|
|
|
ack("RNTO");
|
2000-12-18 05:32:50 +03:00
|
|
|
logxfer("rename", -1, from, to, NULL, p);
|
2000-06-14 17:44:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
sizecmd(const char *filename)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case TYPE_L:
|
2000-12-18 05:32:50 +03:00
|
|
|
case TYPE_I:
|
|
|
|
{
|
2000-06-14 17:44:21 +04:00
|
|
|
struct stat stbuf;
|
|
|
|
if (stat(filename, &stbuf) < 0 || !S_ISREG(stbuf.st_mode))
|
|
|
|
reply(550, "%s: not a plain file.", filename);
|
|
|
|
else
|
2000-11-15 05:32:30 +03:00
|
|
|
reply(213, ULLF, (ULLT)stbuf.st_size);
|
2000-12-18 05:32:50 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case TYPE_A:
|
|
|
|
{
|
2000-06-14 17:44:21 +04:00
|
|
|
FILE *fin;
|
|
|
|
int c;
|
|
|
|
off_t count;
|
|
|
|
struct stat stbuf;
|
|
|
|
fin = fopen(filename, "r");
|
|
|
|
if (fin == NULL) {
|
|
|
|
perror_reply(550, filename);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (fstat(fileno(fin), &stbuf) < 0 || !S_ISREG(stbuf.st_mode)) {
|
|
|
|
reply(550, "%s: not a plain file.", filename);
|
|
|
|
(void) fclose(fin);
|
|
|
|
return;
|
|
|
|
}
|
2002-01-17 08:21:47 +03:00
|
|
|
if (stbuf.st_size > 10240) {
|
|
|
|
reply(550, "%s: file too large for SIZE.", filename);
|
|
|
|
(void) fclose(fin);
|
|
|
|
return;
|
|
|
|
}
|
2000-06-14 17:44:21 +04:00
|
|
|
|
|
|
|
count = 0;
|
2002-01-17 08:21:47 +03:00
|
|
|
while((c = getc(fin)) != EOF) {
|
2000-06-14 17:44:21 +04:00
|
|
|
if (c == '\n') /* will get expanded to \r\n */
|
|
|
|
count++;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
(void) fclose(fin);
|
|
|
|
|
2000-11-15 05:32:30 +03:00
|
|
|
reply(213, LLF, (LLT)count);
|
2000-12-18 05:32:50 +03:00
|
|
|
break;
|
|
|
|
}
|
2000-06-14 17:44:21 +04:00
|
|
|
default:
|
|
|
|
reply(504, "SIZE not implemented for Type %c.", "?AEIL"[type]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
statfilecmd(const char *filename)
|
|
|
|
{
|
|
|
|
FILE *fin;
|
|
|
|
int c;
|
2002-10-25 05:45:37 +04:00
|
|
|
int atstart;
|
2009-03-15 10:48:36 +03:00
|
|
|
const char *argv[] = { INTERNAL_LS, "-lgA", "", NULL };
|
2000-06-14 17:44:21 +04:00
|
|
|
|
2009-03-15 10:48:36 +03:00
|
|
|
argv[2] = filename;
|
2000-06-14 17:44:21 +04:00
|
|
|
fin = ftpd_popen(argv, "r", STDOUT_FILENO);
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
reply(-211, "status of %s:", filename);
|
|
|
|
/* XXX: use fgetln() or fparseln() here? */
|
2002-10-25 05:45:37 +04:00
|
|
|
atstart = 1;
|
2000-06-14 17:44:21 +04:00
|
|
|
while ((c = getc(fin)) != EOF) {
|
|
|
|
if (c == '\n') {
|
|
|
|
if (ferror(stdout)){
|
|
|
|
perror_reply(421, "control connection");
|
|
|
|
(void) ftpd_pclose(fin);
|
|
|
|
dologout(1);
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
if (ferror(fin)) {
|
|
|
|
perror_reply(551, filename);
|
|
|
|
(void) ftpd_pclose(fin);
|
|
|
|
return;
|
|
|
|
}
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
CPUTC('\r', stdout);
|
2000-06-14 17:44:21 +04:00
|
|
|
}
|
2002-10-25 05:45:37 +04:00
|
|
|
if (atstart && isdigit(c))
|
|
|
|
CPUTC(' ', stdout);
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
CPUTC(c, stdout);
|
2002-10-25 05:45:37 +04:00
|
|
|
atstart = (c == '\n');
|
2000-06-14 17:44:21 +04:00
|
|
|
}
|
|
|
|
(void) ftpd_pclose(fin);
|
|
|
|
reply(211, "End of Status");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -- */
|
|
|
|
|
|
|
|
static void
|
|
|
|
ack(const char *s)
|
|
|
|
{
|
|
|
|
|
|
|
|
reply(250, "%s command successful.", s);
|
|
|
|
}
|
|
|
|
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
/*
|
|
|
|
* Encode len bytes starting at clear using base64 encoding into encoded,
|
|
|
|
* which should be at least ((len + 2) * 4 / 3 + 1) in size.
|
2000-07-11 02:41:17 +04:00
|
|
|
* If nulterm is non-zero, terminate with \0 otherwise pad to 3 byte boundary
|
|
|
|
* with `='.
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
base64_encode(const char *clear, size_t len, char *encoded, int nulterm)
|
|
|
|
{
|
2000-07-09 18:26:34 +04:00
|
|
|
static const char base64[] =
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
2000-07-09 18:26:34 +04:00
|
|
|
const char *c;
|
|
|
|
char *e, termchar;
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
int i;
|
|
|
|
|
2000-07-11 02:41:17 +04:00
|
|
|
/* determine whether to pad with '=' or NUL terminate */
|
2000-07-09 18:26:34 +04:00
|
|
|
termchar = nulterm ? '\0' : '=';
|
|
|
|
c = clear;
|
|
|
|
e = encoded;
|
2000-07-11 02:41:17 +04:00
|
|
|
/* convert all but last 2 bytes */
|
|
|
|
for (i = len; i > 2; i -= 3, c += 3) {
|
|
|
|
*e++ = base64[(c[0] >> 2) & 0x3f];
|
|
|
|
*e++ = base64[((c[0] << 4) & 0x30) | ((c[1] >> 4) & 0x0f)];
|
|
|
|
*e++ = base64[((c[1] << 2) & 0x3c) | ((c[2] >> 6) & 0x03)];
|
|
|
|
*e++ = base64[(c[2]) & 0x3f];
|
|
|
|
}
|
|
|
|
/* handle slop at end */
|
|
|
|
if (i > 0) {
|
|
|
|
*e++ = base64[(c[0] >> 2) & 0x3f];
|
2000-07-09 18:26:34 +04:00
|
|
|
*e++ = base64[((c[0] << 4) & 0x30) |
|
2000-07-11 02:41:17 +04:00
|
|
|
(i > 1 ? ((c[1] >> 4) & 0x0f) : 0)];
|
|
|
|
*e++ = (i > 1) ? base64[(c[1] << 2) & 0x3c] : termchar;
|
|
|
|
*e++ = termchar;
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
}
|
2000-07-09 18:26:34 +04:00
|
|
|
*e = '\0';
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
}
|
|
|
|
|
2000-06-14 17:44:21 +04:00
|
|
|
static void
|
|
|
|
fact_modify(const char *fact, FILE *fd, factelem *fe)
|
|
|
|
{
|
|
|
|
struct tm *t;
|
|
|
|
|
|
|
|
t = gmtime(&(fe->stat->st_mtime));
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
cprintf(fd, "%s=%04d%02d%02d%02d%02d%02d;", fact,
|
2000-06-14 17:44:21 +04:00
|
|
|
TM_YEAR_BASE + t->tm_year,
|
|
|
|
t->tm_mon+1, t->tm_mday,
|
|
|
|
t->tm_hour, t->tm_min, t->tm_sec);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fact_perm(const char *fact, FILE *fd, factelem *fe)
|
|
|
|
{
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
int rok, wok, xok, pdirwok;
|
2000-06-14 17:44:21 +04:00
|
|
|
struct stat *pdir;
|
|
|
|
|
|
|
|
if (fe->stat->st_uid == geteuid()) {
|
|
|
|
rok = ((fe->stat->st_mode & S_IRUSR) != 0);
|
|
|
|
wok = ((fe->stat->st_mode & S_IWUSR) != 0);
|
|
|
|
xok = ((fe->stat->st_mode & S_IXUSR) != 0);
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
} else if (matchgroup(fe->stat->st_gid)) {
|
2000-06-14 17:44:21 +04:00
|
|
|
rok = ((fe->stat->st_mode & S_IRGRP) != 0);
|
|
|
|
wok = ((fe->stat->st_mode & S_IWGRP) != 0);
|
|
|
|
xok = ((fe->stat->st_mode & S_IXGRP) != 0);
|
|
|
|
} else {
|
|
|
|
rok = ((fe->stat->st_mode & S_IROTH) != 0);
|
|
|
|
wok = ((fe->stat->st_mode & S_IWOTH) != 0);
|
|
|
|
xok = ((fe->stat->st_mode & S_IXOTH) != 0);
|
|
|
|
}
|
|
|
|
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
cprintf(fd, "%s=", fact);
|
2000-06-14 17:44:21 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* if parent info not provided, look it up, but
|
|
|
|
* only if the current class has modify rights,
|
|
|
|
* since we only need this info in such a case.
|
|
|
|
*/
|
|
|
|
pdir = fe->pdirstat;
|
2000-11-16 16:15:13 +03:00
|
|
|
if (pdir == NULL && CURCLASS_FLAGS_ISSET(modify)) {
|
2000-06-14 17:44:21 +04:00
|
|
|
size_t len;
|
|
|
|
char realdir[MAXPATHLEN], *p;
|
|
|
|
struct stat dir;
|
|
|
|
|
|
|
|
len = strlcpy(realdir, fe->path, sizeof(realdir));
|
|
|
|
if (len < sizeof(realdir) - 4) {
|
|
|
|
if (S_ISDIR(fe->stat->st_mode))
|
|
|
|
strlcat(realdir, "/..", sizeof(realdir));
|
|
|
|
else {
|
|
|
|
/* if has a /, move back to it */
|
|
|
|
/* otherwise use '..' */
|
|
|
|
if ((p = strrchr(realdir, '/')) != NULL) {
|
|
|
|
if (p == realdir)
|
|
|
|
p++;
|
|
|
|
*p = '\0';
|
|
|
|
} else
|
|
|
|
strlcpy(realdir, "..", sizeof(realdir));
|
|
|
|
}
|
|
|
|
if (stat(realdir, &dir) == 0)
|
|
|
|
pdir = &dir;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pdirwok = 0;
|
|
|
|
if (pdir != NULL) {
|
|
|
|
if (pdir->st_uid == geteuid())
|
|
|
|
pdirwok = ((pdir->st_mode & S_IWUSR) != 0);
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
else if (matchgroup(pdir->st_gid))
|
2000-06-14 17:44:21 +04:00
|
|
|
pdirwok = ((pdir->st_mode & S_IWGRP) != 0);
|
|
|
|
else
|
|
|
|
pdirwok = ((pdir->st_mode & S_IWOTH) != 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 'a': can APPE to file */
|
2000-11-16 16:15:13 +03:00
|
|
|
if (wok && CURCLASS_FLAGS_ISSET(upload) && S_ISREG(fe->stat->st_mode))
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
CPUTC('a', fd);
|
2000-06-14 17:44:21 +04:00
|
|
|
|
|
|
|
/* 'c': can create or append to files in directory */
|
2000-11-16 16:15:13 +03:00
|
|
|
if (wok && CURCLASS_FLAGS_ISSET(modify) && S_ISDIR(fe->stat->st_mode))
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
CPUTC('c', fd);
|
2000-06-14 17:44:21 +04:00
|
|
|
|
|
|
|
/* 'd': can delete file or directory */
|
2000-11-16 16:15:13 +03:00
|
|
|
if (pdirwok && CURCLASS_FLAGS_ISSET(modify)) {
|
2000-06-14 17:44:21 +04:00
|
|
|
int candel;
|
|
|
|
|
|
|
|
candel = 1;
|
|
|
|
if (S_ISDIR(fe->stat->st_mode)) {
|
|
|
|
DIR *dirp;
|
|
|
|
struct dirent *dp;
|
|
|
|
|
|
|
|
if ((dirp = opendir(fe->display)) == NULL)
|
|
|
|
candel = 0;
|
|
|
|
else {
|
|
|
|
while ((dp = readdir(dirp)) != NULL) {
|
|
|
|
if (ISDOTDIR(dp->d_name) ||
|
|
|
|
ISDOTDOTDIR(dp->d_name))
|
|
|
|
continue;
|
|
|
|
candel = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
closedir(dirp);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (candel)
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
CPUTC('d', fd);
|
2000-06-14 17:44:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* 'e': can enter directory */
|
|
|
|
if (xok && S_ISDIR(fe->stat->st_mode))
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
CPUTC('e', fd);
|
2000-06-14 17:44:21 +04:00
|
|
|
|
|
|
|
/* 'f': can rename file or directory */
|
2000-11-16 16:15:13 +03:00
|
|
|
if (pdirwok && CURCLASS_FLAGS_ISSET(modify))
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
CPUTC('f', fd);
|
2000-06-14 17:44:21 +04:00
|
|
|
|
|
|
|
/* 'l': can list directory */
|
|
|
|
if (rok && xok && S_ISDIR(fe->stat->st_mode))
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
CPUTC('l', fd);
|
2000-06-14 17:44:21 +04:00
|
|
|
|
|
|
|
/* 'm': can create directory */
|
2000-11-16 16:15:13 +03:00
|
|
|
if (wok && CURCLASS_FLAGS_ISSET(modify) && S_ISDIR(fe->stat->st_mode))
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
CPUTC('m', fd);
|
2000-06-14 17:44:21 +04:00
|
|
|
|
|
|
|
/* 'p': can remove files in directory */
|
2000-11-16 16:15:13 +03:00
|
|
|
if (wok && CURCLASS_FLAGS_ISSET(modify) && S_ISDIR(fe->stat->st_mode))
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
CPUTC('p', fd);
|
2000-06-14 17:44:21 +04:00
|
|
|
|
|
|
|
/* 'r': can RETR file */
|
|
|
|
if (rok && S_ISREG(fe->stat->st_mode))
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
CPUTC('r', fd);
|
2000-06-14 17:44:21 +04:00
|
|
|
|
|
|
|
/* 'w': can STOR file */
|
2000-11-16 16:15:13 +03:00
|
|
|
if (wok && CURCLASS_FLAGS_ISSET(upload) && S_ISREG(fe->stat->st_mode))
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
CPUTC('w', fd);
|
2000-06-14 17:44:21 +04:00
|
|
|
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
CPUTC(';', fd);
|
2000-06-14 17:44:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fact_size(const char *fact, FILE *fd, factelem *fe)
|
|
|
|
{
|
|
|
|
|
|
|
|
if (S_ISREG(fe->stat->st_mode))
|
2000-11-15 05:32:30 +03:00
|
|
|
cprintf(fd, "%s=" LLF ";", fact, (LLT)fe->stat->st_size);
|
2000-06-14 17:44:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fact_type(const char *fact, FILE *fd, factelem *fe)
|
|
|
|
{
|
|
|
|
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
cprintf(fd, "%s=", fact);
|
2000-06-14 17:44:21 +04:00
|
|
|
switch (fe->stat->st_mode & S_IFMT) {
|
|
|
|
case S_IFDIR:
|
2002-02-13 18:15:23 +03:00
|
|
|
if (fe->flags & FE_MLSD) {
|
|
|
|
if ((fe->flags & FE_ISCURDIR) || ISDOTDIR(fe->display))
|
|
|
|
cprintf(fd, "cdir");
|
|
|
|
else if (ISDOTDOTDIR(fe->display))
|
|
|
|
cprintf(fd, "pdir");
|
|
|
|
else
|
|
|
|
cprintf(fd, "dir");
|
|
|
|
} else {
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
cprintf(fd, "dir");
|
2002-02-13 18:15:23 +03:00
|
|
|
}
|
2000-06-14 17:44:21 +04:00
|
|
|
break;
|
|
|
|
case S_IFREG:
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
cprintf(fd, "file");
|
2000-06-14 17:44:21 +04:00
|
|
|
break;
|
|
|
|
case S_IFIFO:
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
cprintf(fd, "OS.unix=fifo");
|
2000-06-14 17:44:21 +04:00
|
|
|
break;
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
case S_IFLNK: /* XXX: probably a NO-OP with stat() */
|
|
|
|
cprintf(fd, "OS.unix=slink");
|
2000-06-14 17:44:21 +04:00
|
|
|
break;
|
|
|
|
case S_IFSOCK:
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
cprintf(fd, "OS.unix=socket");
|
2000-06-14 17:44:21 +04:00
|
|
|
break;
|
|
|
|
case S_IFBLK:
|
|
|
|
case S_IFCHR:
|
2009-03-02 06:47:44 +03:00
|
|
|
cprintf(fd, "OS.unix=%s-" ULLF "/" ULLF,
|
2000-06-14 17:44:21 +04:00
|
|
|
S_ISBLK(fe->stat->st_mode) ? "blk" : "chr",
|
2009-03-02 06:47:44 +03:00
|
|
|
(ULLT)major(fe->stat->st_rdev),
|
|
|
|
(ULLT)minor(fe->stat->st_rdev));
|
2000-06-14 17:44:21 +04:00
|
|
|
break;
|
|
|
|
default:
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
cprintf(fd, "OS.unix=UNKNOWN(0%o)", fe->stat->st_mode & S_IFMT);
|
2000-06-14 17:44:21 +04:00
|
|
|
break;
|
|
|
|
}
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
CPUTC(';', fd);
|
2000-06-14 17:44:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
fact_unique(const char *fact, FILE *fd, factelem *fe)
|
|
|
|
{
|
2000-07-09 18:26:34 +04:00
|
|
|
char obuf[(sizeof(dev_t) + sizeof(ino_t) + 2) * 4 / 3 + 2];
|
|
|
|
char tbuf[sizeof(dev_t) + sizeof(ino_t)];
|
|
|
|
|
|
|
|
memcpy(tbuf,
|
|
|
|
(char *)&(fe->stat->st_dev), sizeof(dev_t));
|
|
|
|
memcpy(tbuf + sizeof(dev_t),
|
|
|
|
(char *)&(fe->stat->st_ino), sizeof(ino_t));
|
|
|
|
base64_encode(tbuf, sizeof(dev_t) + sizeof(ino_t), obuf, 1);
|
|
|
|
cprintf(fd, "%s=%s;", fact, obuf);
|
2000-06-14 17:44:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
matchgroup(gid_t gid)
|
2000-06-14 17:44:21 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
various fixes suggested by Robert Elz:
* implement closedataconn() and use appropriately (including in mlsd())
* only put leading space in front of MLST output (not MLSD output)
* MLSD: only output pdir and cdir entries when the type fact is requested.
* change error code for giving MLSD a non-directory from 550 to 501
* remove MLSx Type fact support for UNIX.* for now; it's not standardised yet.
* do a check_login when MLSD and MLST are given no args
* detect & complain about null facts in OPTS MLST
* cache getgroups() at login instead of calling each time in fact_perm()
other mods:
* implement cprintf(); as per fprintf() but increments total_bytes{,_out}
* implement CPUTC(); as per putc() but increments total_bytes{,_out}
* implement base64_encode()
* fact_unique() display base64 encoding of dev_t and ino_t rather than
hex output; should scale if size of those changes
* change reply() so that a negative code acts as the initial line in a reply,
code == 0 prefixes the line with 4 spaces, and code > 0 works as before.
deprecate lreply(code, ) and lreply(0, ) in favour of reply(-code, ) and
reply(0, ) respectively.
* use cprintf() and CPUTC() appropriately (often instead of printf(),
lreply(-2, ) or lreply(-1, ).
now we actually account for the data sent by MLST and MLSD.
* remove DEBUG support for sending MLSD output to control connection instead
of data connection (my ftp client now supports MLSD :-)
2000-06-19 19:15:03 +04:00
|
|
|
for (i = 0; i < gidcount; i++)
|
2000-06-14 17:44:21 +04:00
|
|
|
if (gid == gidlist[i])
|
|
|
|
return(1);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mlsname(FILE *fp, factelem *fe)
|
|
|
|
{
|
2002-02-13 18:15:23 +03:00
|
|
|
char realfile[MAXPATHLEN];
|
2009-03-15 10:48:36 +03:00
|
|
|
int userf = 0;
|
|
|
|
size_t i;
|
2000-06-14 17:44:21 +04:00
|
|
|
|
2000-06-19 21:08:05 +04:00
|
|
|
for (i = 0; i < FACTTABSIZE; i++) {
|
2000-06-14 17:44:21 +04:00
|
|
|
if (facttab[i].enabled)
|
|
|
|
(facttab[i].display)(facttab[i].name, fp, fe);
|
|
|
|
}
|
2002-02-13 18:15:23 +03:00
|
|
|
if ((fe->flags & FE_MLSD) &&
|
|
|
|
!(fe->flags & FE_ISCURDIR) && !ISDOTDIR(fe->display)) {
|
|
|
|
/* if MLSD and not "." entry, display as-is */
|
|
|
|
userf = 0;
|
|
|
|
} else {
|
|
|
|
/* if MLST, or MLSD and "." entry, realpath(3) it */
|
|
|
|
if (realpath(fe->display, realfile) != NULL)
|
|
|
|
userf = 1;
|
|
|
|
}
|
|
|
|
cprintf(fp, " %s\r\n", userf ? realfile : fe->display);
|
2000-06-14 17:44:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
replydirname(const char *name, const char *message)
|
|
|
|
{
|
2000-12-04 13:50:39 +03:00
|
|
|
char *p, *ep;
|
2001-01-09 09:07:01 +03:00
|
|
|
char npath[MAXPATHLEN * 2];
|
2000-06-14 17:44:21 +04:00
|
|
|
|
2000-12-04 13:50:39 +03:00
|
|
|
p = npath;
|
|
|
|
ep = &npath[sizeof(npath) - 1];
|
|
|
|
while (*name) {
|
2001-01-09 08:06:14 +03:00
|
|
|
if (*name == '"') {
|
|
|
|
if (ep - p < 2)
|
|
|
|
break;
|
2000-12-04 13:50:39 +03:00
|
|
|
*p++ = *name++;
|
|
|
|
*p++ = '"';
|
2001-01-09 08:06:14 +03:00
|
|
|
} else {
|
|
|
|
if (ep - p < 1)
|
|
|
|
break;
|
2000-12-04 13:50:39 +03:00
|
|
|
*p++ = *name++;
|
2001-01-09 08:06:14 +03:00
|
|
|
}
|
2000-06-14 17:44:21 +04:00
|
|
|
}
|
2000-12-04 13:50:39 +03:00
|
|
|
*p = '\0';
|
2000-06-14 17:44:21 +04:00
|
|
|
reply(257, "\"%s\" %s", npath, message);
|
|
|
|
}
|
2003-01-08 21:07:31 +03:00
|
|
|
|
|
|
|
static void
|
2012-06-19 10:06:34 +04:00
|
|
|
discover_path(char *last_path, const char *new_path)
|
2003-01-08 21:07:31 +03:00
|
|
|
{
|
|
|
|
char tp[MAXPATHLEN + 1] = "";
|
|
|
|
char tq[MAXPATHLEN + 1] = "";
|
|
|
|
char *cp;
|
|
|
|
char *cq;
|
|
|
|
int sz1, sz2;
|
|
|
|
int nomorelink;
|
|
|
|
struct stat st1, st2;
|
|
|
|
|
|
|
|
if (new_path[0] != '/') {
|
|
|
|
(void)strlcpy(tp, last_path, MAXPATHLEN);
|
|
|
|
(void)strlcat(tp, "/", MAXPATHLEN);
|
|
|
|
}
|
|
|
|
(void)strlcat(tp, new_path, MAXPATHLEN);
|
|
|
|
(void)strlcat(tp, "/", MAXPATHLEN);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* resolve symlinks. A symlink may introduce another symlink, so we
|
|
|
|
* loop trying to resolve symlinks until we don't find any of them.
|
|
|
|
*/
|
|
|
|
do {
|
|
|
|
/* Collapse any // into / */
|
|
|
|
while ((cp = strstr(tp, "//")) != NULL)
|
|
|
|
(void)memmove(cp, cp + 1, strlen(cp) - 1 + 1);
|
|
|
|
|
|
|
|
/* Collapse any /./ into / */
|
|
|
|
while ((cp = strstr(tp, "/./")) != NULL)
|
|
|
|
(void)memmove(cp, cp + 2, strlen(cp) - 2 + 1);
|
|
|
|
|
|
|
|
cp = tp;
|
|
|
|
nomorelink = 1;
|
|
|
|
|
2013-06-28 19:04:35 +04:00
|
|
|
while ((cp = strstr(cp + 1, "/")) != NULL) {
|
2008-06-09 04:33:39 +04:00
|
|
|
sz1 = (unsigned long)cp - (unsigned long)tp;
|
2003-01-08 21:07:31 +03:00
|
|
|
if (sz1 > MAXPATHLEN)
|
|
|
|
goto bad;
|
|
|
|
*cp = 0;
|
|
|
|
sz2 = readlink(tp, tq, MAXPATHLEN);
|
|
|
|
*cp = '/';
|
|
|
|
|
|
|
|
/* If this is not a symlink, move to next / */
|
|
|
|
if (sz2 <= 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We found a symlink, so we will have to
|
|
|
|
* do one more pass to check there is no
|
|
|
|
* more symlink in the path
|
|
|
|
*/
|
|
|
|
nomorelink = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Null terminate the string and remove trailing /
|
|
|
|
*/
|
|
|
|
tq[sz2] = 0;
|
|
|
|
sz2 = strlen(tq);
|
|
|
|
if (tq[sz2 - 1] == '/')
|
|
|
|
tq[--sz2] = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Is this an absolute link or a relative link?
|
|
|
|
*/
|
|
|
|
if (tq[0] == '/') {
|
|
|
|
/* absolute link */
|
|
|
|
if (strlen(cp) + sz2 > MAXPATHLEN)
|
|
|
|
goto bad;
|
|
|
|
memmove(tp + sz2, cp, strlen(cp) + 1);
|
|
|
|
memcpy(tp, tq, sz2);
|
|
|
|
} else {
|
|
|
|
/* relative link */
|
|
|
|
for (cq = cp - 1; *cq != '/'; cq--);
|
2008-06-09 04:33:39 +04:00
|
|
|
if (strlen(tp) -
|
|
|
|
((unsigned long)cq - (unsigned long)cp)
|
2003-01-08 21:07:31 +03:00
|
|
|
+ 1 + sz2 > MAXPATHLEN)
|
|
|
|
goto bad;
|
|
|
|
(void)memmove(cq + 1 + sz2,
|
|
|
|
cp, strlen(cp) + 1);
|
|
|
|
(void)memcpy(cq + 1, tq, sz2);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* start over, looking for new symlinks
|
|
|
|
*/
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (nomorelink == 0);
|
|
|
|
|
|
|
|
/* Collapse any /foo/../ into /foo/ */
|
|
|
|
while ((cp = strstr(tp, "/../")) != NULL) {
|
|
|
|
/* ^/../foo/ becomes ^/foo/ */
|
|
|
|
if (cp == tp) {
|
|
|
|
(void)memmove(cp, cp + 3,
|
|
|
|
strlen(cp) - 3 + 1);
|
|
|
|
} else {
|
|
|
|
for (cq = cp - 1; *cq != '/'; cq--);
|
|
|
|
(void)memmove(cq, cp + 3,
|
|
|
|
strlen(cp) - 3 + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* strip strailing / */
|
|
|
|
if (strlen(tp) != 1)
|
|
|
|
tp[strlen(tp) - 1] = '\0';
|
|
|
|
|
|
|
|
/* check that the path is correct */
|
2013-07-03 18:15:47 +04:00
|
|
|
if (stat(tp, &st1) == -1 || stat(".", &st2) == -1)
|
|
|
|
goto bad;
|
2003-01-08 21:07:31 +03:00
|
|
|
if ((st1.st_dev != st2.st_dev) || (st1.st_ino != st2.st_ino))
|
|
|
|
goto bad;
|
|
|
|
|
|
|
|
(void)strlcpy(last_path, tp, MAXPATHLEN);
|
|
|
|
return;
|
|
|
|
|
|
|
|
bad:
|
|
|
|
(void)strlcat(last_path, "/", MAXPATHLEN);
|
|
|
|
(void)strlcat(last_path, new_path, MAXPATHLEN);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|