some cleanup:

* pass `--' to all programs after args
 * use `show_file' to output contents of various files
 * use built-in ls if there is no external


git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@7719 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Johan Danielsson
2000-01-05 13:46:04 +00:00
parent fa3d70f98a
commit ecfb13fe6c

View File

@@ -202,7 +202,7 @@ static char *port_string;
static char *umask_string; static char *umask_string;
static char *auth_string; static char *auth_string;
int use_builtin_ls; int use_builtin_ls = -1;
static int help_flag; static int help_flag;
static int version_flag; static int version_flag;
@@ -232,6 +232,24 @@ usage (int code)
exit (code); exit (code);
} }
/* output contents of a file */
static int
show_file(const char *file, int code)
{
FILE *f;
char buf[128];
f = fopen(file, "r");
if(f == NULL)
return -1;
while(fgets(buf, sizeof(buf), f)){
buf[strcspn(buf, "\r\n")] = '\0';
lreply(code, "%s", buf);
}
fclose(f);
return 0;
}
int int
main(int argc, char **argv) main(int argc, char **argv)
{ {
@@ -376,27 +394,12 @@ main(int argc, char **argv)
tmpline[0] = '\0'; tmpline[0] = '\0';
/* If logins are disabled, print out the message. */ /* If logins are disabled, print out the message. */
if ((fd = fopen(_PATH_NOLOGIN,"r")) != NULL) { if(show_file(_PATH_NOLOGIN, 530) == 0) {
while (fgets(line, sizeof(line), fd) != NULL) {
if ((cp = strchr(line, '\n')) != NULL)
*cp = '\0';
lreply(530, "%s", line);
}
fflush(stdout);
fclose(fd);
reply(530, "System not available."); reply(530, "System not available.");
exit(0); exit(0);
} }
if ((fd = fopen(_PATH_FTPWELCOME, "r")) != NULL) { show_file(_PATH_FTPWELCOME, 220);
while (fgets(line, sizeof(line), fd) != NULL) { /* reply(220,) must follow */
if ((cp = strchr(line, '\n')) != NULL)
*cp = '\0';
lreply(220, "%s", line);
}
fflush(stdout);
fclose(fd);
/* reply(220,) must follow */
}
gethostname(hostname, sizeof(hostname)); gethostname(hostname, sizeof(hostname));
reply(220, "%s FTP server (%s" reply(220, "%s FTP server (%s"
@@ -703,24 +706,6 @@ checkaccess(char *name)
#undef ALLOWED #undef ALLOWED
#undef NOT_ALLOWED #undef NOT_ALLOWED
/* output contents of /etc/issue.net, or /etc/issue */
static void
show_issue(int code)
{
FILE *f;
char buf[128];
f = fopen("/etc/issue.net", "r");
if(f == NULL)
f = fopen("/etc/issue", "r");
if(f){
while(fgets(buf, sizeof(buf), f)){
buf[strcspn(buf, "\r\n")] = '\0';
lreply(code, "%s", buf);
}
fclose(f);
}
}
int do_login(int code, char *passwd) int do_login(int code, char *passwd)
{ {
@@ -764,21 +749,26 @@ int do_login(int code, char *passwd)
reply(550, "Can't set uid."); reply(550, "Can't set uid.");
return -1; return -1;
} }
if(use_builtin_ls == -1) {
struct stat st;
/* if /bin/ls exist and is a regular file, use it, otherwise
use built-in ls */
if(stat("/bin/ls", &st) == 0 &&
S_ISREG(st.st_mode))
use_builtin_ls = 0;
else
use_builtin_ls = 1;
}
/* /*
* Display a login message, if it exists. * Display a login message, if it exists.
* N.B. reply(code,) must follow the message. * N.B. reply(code,) must follow the message.
*/ */
if ((fd = fopen(_PATH_FTPLOGINMESG, "r")) != NULL) { show_file(_PATH_FTPLOGINMESG, code);
char *cp, line[LINE_MAX]; if(show_file(_PATH_ISSUE_NET, code) != 0)
show_file(_PATH_ISSUE, code);
while (fgets(line, sizeof(line), fd) != NULL) {
if ((cp = strchr(line, '\n')) != NULL)
*cp = '\0';
lreply(code, "%s", line);
}
}
if (guest) { if (guest) {
show_issue(code);
reply(code, "Guest login ok, access restrictions apply."); reply(code, "Guest login ok, access restrictions apply.");
#ifdef HAVE_SETPROCTITLE #ifdef HAVE_SETPROCTITLE
snprintf (proctitle, sizeof(proctitle), snprintf (proctitle, sizeof(proctitle),
@@ -802,7 +792,6 @@ int do_login(int code, char *passwd)
passwd); passwd);
} }
} else { } else {
show_issue(code);
reply(code, "User %s logged in.", pw->pw_name); reply(code, "User %s logged in.", pw->pw_name);
#ifdef HAVE_SETPROCTITLE #ifdef HAVE_SETPROCTITLE
snprintf(proctitle, sizeof(proctitle), "%s: %s", remotehost, pw->pw_name); snprintf(proctitle, sizeof(proctitle), "%s: %s", remotehost, pw->pw_name);
@@ -956,8 +945,8 @@ retrieve(const char *cmd, char *name)
{".tar", "/bin/gtar cPf - %s", NULL}, {".tar", "/bin/gtar cPf - %s", NULL},
{".tar.gz", "/bin/gtar zcPf - %s", NULL}, {".tar.gz", "/bin/gtar zcPf - %s", NULL},
{".tar.Z", "/bin/gtar ZcPf - %s", NULL}, {".tar.Z", "/bin/gtar ZcPf - %s", NULL},
{".gz", "/bin/gzip -c %s", "/bin/gzip -c -d %s"}, {".gz", "/bin/gzip -c -- %s", "/bin/gzip -c -d -- %s"},
{".Z", "/bin/compress -c %s", "/bin/uncompress -c -d %s"}, {".Z", "/bin/compress -c -- %s", "/bin/uncompress -c -- %s"},
{NULL, NULL} {NULL, NULL}
}; };
struct cmds *p; struct cmds *p;
@@ -1500,7 +1489,7 @@ statfilecmd(char *filename)
int c; int c;
char line[LINE_MAX]; char line[LINE_MAX];
snprintf(line, sizeof(line), "/bin/ls -la %s", filename); snprintf(line, sizeof(line), "/bin/ls -la -- %s", filename);
fin = ftpd_popen(line, "r", 1, 0); fin = ftpd_popen(line, "r", 1, 0);
lreply(211, "status of %s:", filename); lreply(211, "status of %s:", filename);
while ((c = getc(fin)) != EOF) { while ((c = getc(fin)) != EOF) {
@@ -2091,9 +2080,9 @@ list_file(char *file)
pdata = -1; pdata = -1;
} else { } else {
#ifdef HAVE_LS_A #ifdef HAVE_LS_A
const char *cmd = "/bin/ls -lA %s"; const char *cmd = "/bin/ls -lA -- %s";
#else #else
const char *cmd = "/bin/ls -la %s"; const char *cmd = "/bin/ls -la -- %s";
#endif #endif
retrieve(cmd, file); retrieve(cmd, file);
} }
@@ -2144,7 +2133,7 @@ send_file_list(char *whichf)
*/ */
if (dirname[0] == '-' && *dirlist == NULL && if (dirname[0] == '-' && *dirlist == NULL &&
transflag == 0) { transflag == 0) {
retrieve("/bin/ls %s", dirname); retrieve("/bin/ls -- %s", dirname);
goto out; goto out;
} }
perror_reply(550, whichf); perror_reply(550, whichf);
@@ -2239,7 +2228,7 @@ find(char *pattern)
FILE *f; FILE *f;
snprintf(line, sizeof(line), snprintf(line, sizeof(line),
"/bin/locate -d %s %s", "/bin/locate -d %s -- %s",
ftp_rooted("/etc/locatedb"), ftp_rooted("/etc/locatedb"),
pattern); pattern);
f = ftpd_popen(line, "r", 1, 1); f = ftpd_popen(line, "r", 1, 1);