Skip to content

Commit

Permalink
Password feature
Browse files Browse the repository at this point in the history
  • Loading branch information
rgpublic committed Jul 4, 2019
1 parent 04ea51c commit 936f1fc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/ftpcmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "uftpd.h"
#include <ctype.h>
#include <crypt.h>
#include <arpa/ftp.h>
#ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
Expand Down Expand Up @@ -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;
}

This comment has been minimized.

Copy link
@troglobit

troglobit Jul 4, 2019

Since strcmp() returns 0 on match, shouldn't you return 1 then?


if (!strcmp("anonymous", ctrl->name))
return 1;

Expand Down
8 changes: 7 additions & 1 deletion src/uftpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand All @@ -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') {
Expand Down
1 change: 1 addition & 0 deletions src/uftpd.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 936f1fc

Please sign in to comment.