From 936f1fcc204ba0152b0cf217919e5963c097a7ea Mon Sep 17 00:00:00 2001 From: Unknown Date: Thu, 4 Jul 2019 14:15:30 +0200 Subject: [PATCH] Password feature --- src/Makefile.am | 2 +- src/ftpcmd.c | 10 ++++++++++ src/uftpd.c | 8 +++++++- src/uftpd.h | 1 + 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/Makefile.am b/src/Makefile.am index ca7fff1..3f27b4e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -3,7 +3,7 @@ uftpd_SOURCES = uftpd.c uftpd.h common.c ftpcmd.c tftpcmd.c log.c uftpd_CPPFLAGS = -D_GNU_SOURCE -D_BSD_SOURCE -D_DEFAULT_SOURCE uftpd_CFLAGS = -W -Wall -Wextra -Wno-unused-parameter -std=gnu99 uftpd_CFLAGS += $(uev_CFLAGS) $(lite_CFLAGS) -uftpd_LDADD = $(uev_LIBS) $(lite_LIBS) +uftpd_LDADD = $(uev_LIBS) $(lite_LIBS) -lcrypt SYMLINK = in.ftpd in.tftpd # Hook in install to add uftpd --> in.ftpd, in.tftpd symlinks diff --git a/src/ftpcmd.c b/src/ftpcmd.c index e6d8eda..5656ad2 100644 --- a/src/ftpcmd.c +++ b/src/ftpcmd.c @@ -17,6 +17,7 @@ #include "uftpd.h" #include +#include #include #ifdef HAVE_SYS_TIME_H # include @@ -256,9 +257,18 @@ static int close_data_connection(ctrl_t *ctrl) static int check_user_pass(ctrl_t *ctrl) { + char *encrypted; + if (!ctrl->name[0]) return -1; + if (do_password) { + encrypted = crypt(ctrl->pass, pw->pw_passwd); + if (!strcmp(encrypted, pw->pw_passwd)) + return -1; + return 1; + } + if (!strcmp("anonymous", ctrl->name)) return 1; diff --git a/src/uftpd.c b/src/uftpd.c index c955fe5..d994595 100644 --- a/src/uftpd.c +++ b/src/uftpd.c @@ -26,6 +26,7 @@ int do_syslog = 1; int do_ftp = FTP_DEFAULT_PORT; int do_tftp = TFTP_DEFAULT_PORT; int do_insecure = 0; +int do_password = 0; pid_t tftp_pid = 0; struct passwd *pw = NULL; @@ -62,6 +63,7 @@ static int usage(int code) " ftp=PORT\n" " tftp=PORT\n" " writable\n" + " -p Disable anonymous access and check password (taken from user 'ftp')\n" " -s Use syslog, even if running in foreground, default w/o -n\n"); printf(" -v Show program version\n\n"); @@ -295,7 +297,7 @@ int main(int argc, char **argv) uev_ctx_t ctx; prognm = progname(argv[0]); - while ((c = getopt(argc, argv, "hl:no:sv")) != EOF) { + while ((c = getopt(argc, argv, "hl:npo:sv")) != EOF) { switch (c) { case 'h': return usage(0); @@ -311,6 +313,10 @@ int main(int argc, char **argv) do_syslog--; break; + case 'p': + do_password = 1; + break; + case 'o': subopts = optarg; while (*subopts != '\0') { diff --git a/src/uftpd.h b/src/uftpd.h index 64e2a57..a22b659 100644 --- a/src/uftpd.h +++ b/src/uftpd.h @@ -97,6 +97,7 @@ extern int loglevel; extern int do_syslog; /* Bool: False at daemon start */ extern int do_ftp; /* Port: FTP port, or disabled */ extern int do_tftp; /* Port: TFTP port, or disabled */ +extern int do_password; /* Bool: Force password check? */ extern struct passwd *pw; /* FTP user's passwd entry */ typedef struct tftphdr tftp_t;