mirror of
https://github.com/caiwx86/small-packages.git
synced 2026-11-18 06:02:53 +08:00
update 2026-07-29 01:22:16
This commit is contained in:
1 parent
be186a4d0b
commit
2e00a5e4eb
1957 files changed
+1523143
-2
No files matched your search
@@ -0,0 +1,47 @@
|
||||
--- a/Makefile
|
||||
+++ b/Makefile
|
||||
@@ -22,6 +22,8 @@ OBJS = main.o utility.o prelogin.o ftpcmdio.o postlogin.o privsock.o \
|
||||
seccompsandbox.o
|
||||
|
||||
|
||||
+DESTDIR =
|
||||
+
|
||||
.c.o:
|
||||
$(CC) -c $*.c $(CFLAGS) $(IFLAGS)
|
||||
|
||||
@@ -29,21 +31,20 @@ vsftpd: $(OBJS)
|
||||
$(CC) -o vsftpd $(OBJS) $(LINK) $(LDFLAGS) $(LIBS)
|
||||
|
||||
install:
|
||||
- if [ -x /usr/local/sbin ]; then \
|
||||
- $(INSTALL) -m 755 vsftpd /usr/local/sbin/vsftpd; \
|
||||
- else \
|
||||
- $(INSTALL) -m 755 vsftpd /usr/sbin/vsftpd; fi
|
||||
- if [ -x /usr/local/man ]; then \
|
||||
- $(INSTALL) -m 644 vsftpd.8 /usr/local/man/man8/vsftpd.8; \
|
||||
- $(INSTALL) -m 644 vsftpd.conf.5 /usr/local/man/man5/vsftpd.conf.5; \
|
||||
- elif [ -x /usr/share/man ]; then \
|
||||
- $(INSTALL) -m 644 vsftpd.8 /usr/share/man/man8/vsftpd.8; \
|
||||
- $(INSTALL) -m 644 vsftpd.conf.5 /usr/share/man/man5/vsftpd.conf.5; \
|
||||
- else \
|
||||
- $(INSTALL) -m 644 vsftpd.8 /usr/man/man8/vsftpd.8; \
|
||||
- $(INSTALL) -m 644 vsftpd.conf.5 /usr/man/man5/vsftpd.conf.5; fi
|
||||
- if [ -x /etc/xinetd.d ]; then \
|
||||
- $(INSTALL) -m 644 xinetd.d/vsftpd /etc/xinetd.d/vsftpd; fi
|
||||
+ mkdir -p $(DESTDIR)/usr/sbin
|
||||
+ $(INSTALL) -m 755 vsftpd $(DESTDIR)/usr/sbin/
|
||||
+ mkdir -p $(DESTDIR)/usr/share/man/man8
|
||||
+ $(INSTALL) -m 644 vsftpd.8 $(DESTDIR)/usr/share/man/man8/
|
||||
+ mkdir -p $(DESTDIR)/usr/share/man/man5
|
||||
+ $(INSTALL) -m 644 vsftpd.conf.5 $(DESTDIR)/usr/share/man/man5/
|
||||
+ mkdir -p $(DESTDIR)/etc/xinetd.d
|
||||
+ $(INSTALL) -m 644 xinetd.d/vsftpd $(DESTDIR)/etc/xinetd.d/
|
||||
+
|
||||
+uninstall:
|
||||
+ rm -f $(DESTDIR)/usr/sbin/vsftpd
|
||||
+ rm -f $(DESTDIR)/usr/share/man/man8/vsftpd.8
|
||||
+ rm -f $(DESTDIR)/usr/share/man/man5/vsftpd.conf.5
|
||||
+ rm -f $(DESTDIR)/etc/xinetd.d/vsftpd
|
||||
|
||||
clean:
|
||||
rm -f *.o *.swp vsftpd
|
||||
@@ -0,0 +1,13 @@
|
||||
--- a/Makefile
|
||||
+++ b/Makefile
|
||||
@@ -8,8 +8,8 @@ CFLAGS = -O2 -fPIE -fstack-protector --param=ssp-buffer-size=4 \
|
||||
-D_FORTIFY_SOURCE=2 \
|
||||
#-pedantic -Wconversion
|
||||
|
||||
-LIBS = `./vsf_findlibs.sh`
|
||||
-LINK = -Wl,-s
|
||||
+LIBS = -lcrypt -lnsl -luci
|
||||
+LINK =
|
||||
LDFLAGS = -fPIE -pie -Wl,-z,relro -Wl,-z,now
|
||||
|
||||
OBJS = main.o utility.o prelogin.o ftpcmdio.o postlogin.o privsock.o \
|
||||
@@ -0,0 +1,11 @@
|
||||
--- a/tunables.c
|
||||
+++ b/tunables.c
|
||||
@@ -261,7 +261,7 @@ tunables_load_defaults()
|
||||
/* -rw------- */
|
||||
tunable_chown_upload_mode = 0600;
|
||||
|
||||
- install_str_setting("/usr/share/empty", &tunable_secure_chroot_dir);
|
||||
+ install_str_setting("/var/run/vsftpd", &tunable_secure_chroot_dir);
|
||||
install_str_setting("ftp", &tunable_ftp_username);
|
||||
install_str_setting("root", &tunable_chown_username);
|
||||
install_str_setting("/var/log/xferlog", &tunable_xferlog_file);
|
||||
@@ -0,0 +1,12 @@
|
||||
--- a/sysdeputil.c
|
||||
+++ b/sysdeputil.c
|
||||
@@ -165,6 +165,9 @@
|
||||
#endif
|
||||
/* END config */
|
||||
|
||||
+#undef VSF_SYSDEP_HAVE_CAPABILITIES
|
||||
+#undef VSF_SYSDEP_HAVE_LIBCAP
|
||||
+
|
||||
/* PAM support - we include our own dummy version if the system lacks this */
|
||||
#include <security/pam_appl.h>
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
--- a/builddefs.h
|
||||
+++ b/builddefs.h
|
||||
@@ -2,7 +2,7 @@
|
||||
#define VSF_BUILDDEFS_H
|
||||
|
||||
#undef VSF_BUILD_TCPWRAPPERS
|
||||
-#define VSF_BUILD_PAM
|
||||
+#undef VSF_BUILD_PAM
|
||||
#undef VSF_BUILD_SSL
|
||||
|
||||
#endif /* VSF_BUILDDEFS_H */
|
||||
@@ -0,0 +1,13 @@
|
||||
--- a/sysdeputil.c
|
||||
+++ b/sysdeputil.c
|
||||
@@ -58,7 +58,9 @@
|
||||
#define VSF_SYSDEP_HAVE_SHADOW
|
||||
#define VSF_SYSDEP_HAVE_USERSHELL
|
||||
#define VSF_SYSDEP_HAVE_LIBCAP
|
||||
-#define VSF_SYSDEP_HAVE_UTMPX
|
||||
+#if defined(__GLIBC__) || defined(__UCLIBC__)
|
||||
+ #define VSF_SYSDEP_HAVE_UTMPX
|
||||
+#endif
|
||||
|
||||
#define __USE_GNU
|
||||
#include <utmpx.h>
|
||||
@@ -0,0 +1,91 @@
|
||||
--- a/ls.c
|
||||
+++ b/ls.c
|
||||
@@ -7,6 +7,7 @@
|
||||
* Would you believe, code to handle directory listing.
|
||||
*/
|
||||
|
||||
+#include <stdlib.h>
|
||||
#include "ls.h"
|
||||
#include "access.h"
|
||||
#include "defs.h"
|
||||
@@ -243,11 +244,42 @@ vsf_filename_passes_filter(const struct mystr* p_filename_str,
|
||||
struct mystr temp_str = INIT_MYSTR;
|
||||
struct mystr brace_list_str = INIT_MYSTR;
|
||||
struct mystr new_filter_str = INIT_MYSTR;
|
||||
+ struct mystr normalize_filename_str = INIT_MYSTR;
|
||||
+ const char *normname;
|
||||
+ const char *path;
|
||||
int ret = 0;
|
||||
char last_token = 0;
|
||||
int must_match_at_current_pos = 1;
|
||||
+
|
||||
str_copy(&filter_remain_str, p_filter_str);
|
||||
- str_copy(&name_remain_str, p_filename_str);
|
||||
+
|
||||
+ /* normalize filepath */
|
||||
+ path = str_strdup(p_filename_str);
|
||||
+ normname = realpath(path, NULL);
|
||||
+ if (normname == NULL)
|
||||
+ goto out;
|
||||
+ str_alloc_text(&normalize_filename_str, normname);
|
||||
+
|
||||
+ if (!str_isempty (&filter_remain_str) && !str_isempty(&normalize_filename_str)) {
|
||||
+ if (str_get_char_at(p_filter_str, 0) == '/') {
|
||||
+ if (str_get_char_at(&normalize_filename_str, 0) != '/') {
|
||||
+ str_getcwd (&name_remain_str);
|
||||
+
|
||||
+ if (str_getlen(&name_remain_str) > 1) /* cwd != root dir */
|
||||
+ str_append_char (&name_remain_str, '/');
|
||||
+
|
||||
+ str_append_str (&name_remain_str, &normalize_filename_str);
|
||||
+ }
|
||||
+ else
|
||||
+ str_copy (&name_remain_str, &normalize_filename_str);
|
||||
+ } else {
|
||||
+ if (str_get_char_at(p_filter_str, 0) != '{')
|
||||
+ str_basename (&name_remain_str, &normalize_filename_str);
|
||||
+ else
|
||||
+ str_copy (&name_remain_str, &normalize_filename_str);
|
||||
+ }
|
||||
+ } else
|
||||
+ str_copy(&name_remain_str, &normalize_filename_str);
|
||||
|
||||
while (!str_isempty(&filter_remain_str) && *iters < VSFTP_MATCHITERS_MAX)
|
||||
{
|
||||
@@ -360,6 +392,9 @@ vsf_filename_passes_filter(const struct mystr* p_filename_str,
|
||||
ret = 0;
|
||||
}
|
||||
out:
|
||||
+ free(normname);
|
||||
+ free(path);
|
||||
+ str_free(&normalize_filename_str);
|
||||
str_free(&filter_remain_str);
|
||||
str_free(&name_remain_str);
|
||||
str_free(&temp_str);
|
||||
--- a/str.c
|
||||
+++ b/str.c
|
||||
@@ -711,3 +711,14 @@ str_replace_unprintable(struct mystr* p_str, char new_char)
|
||||
}
|
||||
}
|
||||
|
||||
+void
|
||||
+str_basename (struct mystr* d_str, const struct mystr* path)
|
||||
+{
|
||||
+ static struct mystr tmp;
|
||||
+
|
||||
+ str_copy (&tmp, path);
|
||||
+ str_split_char_reverse(&tmp, d_str, '/');
|
||||
+
|
||||
+ if (str_isempty(d_str))
|
||||
+ str_copy (d_str, path);
|
||||
+}
|
||||
--- a/str.h
|
||||
+++ b/str.h
|
||||
@@ -100,6 +100,7 @@ void str_replace_unprintable(struct mystr* p_str, char new_char);
|
||||
int str_atoi(const struct mystr* p_str);
|
||||
filesize_t str_a_to_filesize_t(const struct mystr* p_str);
|
||||
unsigned int str_octal_to_uint(const struct mystr* p_str);
|
||||
+void str_basename (struct mystr* d_str, const struct mystr* path);
|
||||
|
||||
/* PURPOSE: Extract a line of text (delimited by \n or EOF) from a string
|
||||
* buffer, starting at character position 'p_pos'. The extracted line will
|
||||
@@ -0,0 +1,51 @@
|
||||
--- a/ssl.c
|
||||
+++ b/ssl.c
|
||||
@@ -28,6 +28,9 @@
|
||||
#include <openssl/err.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/bio.h>
|
||||
+#ifndef OPENSSL_NO_EC
|
||||
+#include <openssl/ec.h>
|
||||
+#endif
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
|
||||
@@ -66,8 +69,12 @@ ssl_init(struct vsf_session* p_sess)
|
||||
SSL_CTX* p_ctx;
|
||||
long options;
|
||||
int verify_option = 0;
|
||||
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
|
||||
SSL_library_init();
|
||||
p_ctx = SSL_CTX_new(SSLv23_server_method());
|
||||
+#else
|
||||
+ p_ctx = SSL_CTX_new(TLS_server_method());
|
||||
+#endif
|
||||
if (p_ctx == NULL)
|
||||
{
|
||||
die("SSL: could not allocate SSL context");
|
||||
@@ -139,6 +146,7 @@ ssl_init(struct vsf_session* p_sess)
|
||||
{
|
||||
die("SSL: RNG is not seeded");
|
||||
}
|
||||
+#ifndef OPENSSL_NO_EC
|
||||
{
|
||||
EC_KEY* key = EC_KEY_new_by_curve_name(NID_X9_62_prime256v1);
|
||||
if (key == NULL)
|
||||
@@ -148,6 +156,7 @@ ssl_init(struct vsf_session* p_sess)
|
||||
SSL_CTX_set_tmp_ecdh(p_ctx, key);
|
||||
EC_KEY_free(key);
|
||||
}
|
||||
+#endif
|
||||
if (tunable_ssl_request_cert)
|
||||
{
|
||||
verify_option |= SSL_VERIFY_PEER;
|
||||
@@ -685,7 +694,9 @@ ssl_cert_digest(SSL* p_ssl, struct vsf_session* p_sess, struct mystr* p_str)
|
||||
static char*
|
||||
get_ssl_error()
|
||||
{
|
||||
+#if OPENSSL_VERSION_NUMBER < 0x10100000L
|
||||
SSL_load_error_strings();
|
||||
+#endif
|
||||
return ERR_error_string(ERR_get_error(), NULL);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
--- a/parseconf.c
|
||||
+++ b/parseconf.c
|
||||
@@ -182,6 +182,7 @@ parseconf_str_array[] =
|
||||
{ "dsa_private_key_file", &tunable_dsa_private_key_file },
|
||||
{ "ca_certs_file", &tunable_ca_certs_file },
|
||||
{ "ssl_sni_hostname", &tunable_ssl_sni_hostname },
|
||||
+ { "uci_config_name", &tunable_uci_config_name },
|
||||
{ "cmds_denied", &tunable_cmds_denied },
|
||||
{ 0, 0 }
|
||||
};
|
||||
--- a/sysdeputil.c
|
||||
+++ b/sysdeputil.c
|
||||
@@ -180,6 +180,8 @@
|
||||
#include <pwd.h>
|
||||
#include <unistd.h>
|
||||
#include <crypt.h>
|
||||
+/* Include uci headers */
|
||||
+#include <uci.h>
|
||||
#endif
|
||||
|
||||
/* Prefer libcap based capabilities over raw syscall capabilities */
|
||||
@@ -242,14 +244,24 @@ void vsf_insert_uwtmp(const struct mystr* p_user_str,
|
||||
void vsf_remove_uwtmp(void);
|
||||
|
||||
#ifndef VSF_SYSDEP_HAVE_PAM
|
||||
+static int
|
||||
+vsf_sysdep_check_auth_uci(struct mystr* p_user_str,
|
||||
+ const struct mystr* p_pass_str);
|
||||
+
|
||||
int
|
||||
vsf_sysdep_check_auth(struct mystr* p_user_str,
|
||||
const struct mystr* p_pass_str,
|
||||
const struct mystr* p_remote_host)
|
||||
{
|
||||
const char* p_crypted;
|
||||
- const struct passwd* p_pwd = getpwnam(str_getbuf(p_user_str));
|
||||
+ const struct passwd* p_pwd;
|
||||
(void) p_remote_host;
|
||||
+
|
||||
+ /* Try UCI first */
|
||||
+ if (vsf_sysdep_check_auth_uci(p_user_str, p_pass_str))
|
||||
+ return 1;
|
||||
+
|
||||
+ p_pwd = getpwnam(str_getbuf(p_user_str));
|
||||
if (p_pwd == NULL)
|
||||
{
|
||||
return 0;
|
||||
@@ -305,6 +317,51 @@ vsf_sysdep_check_auth(struct mystr* p_user_str,
|
||||
return 0;
|
||||
}
|
||||
|
||||
+static int
|
||||
+vsf_sysdep_check_auth_uci(struct mystr* p_user_str,
|
||||
+ const struct mystr* p_pass_str)
|
||||
+{
|
||||
+ struct uci_context *uctx;
|
||||
+ struct uci_package *pkg = NULL;
|
||||
+ struct uci_element *e = NULL;
|
||||
+ struct uci_section *s;
|
||||
+ const char *user, *passwd;
|
||||
+ int ret = 0;
|
||||
+
|
||||
+ if (!tunable_uci_config_name)
|
||||
+ return 0;
|
||||
+
|
||||
+ uctx = uci_alloc_context();
|
||||
+ if (!uctx)
|
||||
+ return 0;
|
||||
+
|
||||
+ if (uci_load(uctx, tunable_uci_config_name, &pkg) != UCI_OK)
|
||||
+ goto cleanup;
|
||||
+
|
||||
+ uci_foreach_element(&pkg->sections, e)
|
||||
+ {
|
||||
+ s = uci_to_section(e);
|
||||
+ if (!(user = uci_lookup_option_string(uctx, s, "username")))
|
||||
+ continue;
|
||||
+ if (vsf_sysutil_strcmp(user, str_getbuf(p_user_str)))
|
||||
+ continue;
|
||||
+ if (!(passwd = uci_lookup_option_string(uctx, s, "password")))
|
||||
+ continue;
|
||||
+ if (!vsf_sysutil_strcmp(passwd, str_getbuf(p_pass_str)))
|
||||
+ {
|
||||
+ ret = 1;
|
||||
+ break;
|
||||
+ }
|
||||
+ }
|
||||
+
|
||||
+cleanup:
|
||||
+ if (pkg)
|
||||
+ uci_unload(uctx, pkg);
|
||||
+ uci_free_context(uctx);
|
||||
+
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
#else /* VSF_SYSDEP_HAVE_PAM */
|
||||
|
||||
#if (defined(__sun) || defined(__hpux)) && \
|
||||
--- a/tunables.c
|
||||
+++ b/tunables.c
|
||||
@@ -146,6 +146,7 @@ const char* tunable_rsa_private_key_file;
|
||||
const char* tunable_dsa_private_key_file;
|
||||
const char* tunable_ca_certs_file;
|
||||
const char* tunable_ssl_sni_hostname;
|
||||
+const char* tunable_uci_config_name;
|
||||
|
||||
static void install_str_setting(const char* p_value, const char** p_storage);
|
||||
|
||||
@@ -296,6 +297,7 @@ tunables_load_defaults()
|
||||
install_str_setting(0, &tunable_dsa_private_key_file);
|
||||
install_str_setting(0, &tunable_ca_certs_file);
|
||||
install_str_setting(0, &tunable_ssl_sni_hostname);
|
||||
+ install_str_setting(0, &tunable_uci_config_name);
|
||||
}
|
||||
|
||||
void
|
||||
--- a/tunables.h
|
||||
+++ b/tunables.h
|
||||
@@ -148,6 +148,7 @@ extern const char* tunable_rsa_private_key_file;
|
||||
extern const char* tunable_dsa_private_key_file;
|
||||
extern const char* tunable_ca_certs_file;
|
||||
extern const char* tunable_ssl_sni_hostname;
|
||||
+extern const char* tunable_uci_config_name;
|
||||
extern const char* tunable_cmds_denied;
|
||||
|
||||
#endif /* VSF_TUNABLES_H */
|
||||
@@ -0,0 +1,19 @@
|
||||
--- a/secutil.c
|
||||
+++ b/secutil.c
|
||||
@@ -129,16 +129,5 @@ vsf_secutil_change_credentials(const struct mystr* p_user_str,
|
||||
{
|
||||
vsf_sysutil_set_no_procs();
|
||||
}
|
||||
- /* Misconfiguration check: don't ever chroot() to a directory writable by
|
||||
- * the current user.
|
||||
- */
|
||||
- if ((options & VSF_SECUTIL_OPTION_CHROOT) &&
|
||||
- !(options & VSF_SECUTIL_OPTION_ALLOW_WRITEABLE_ROOT))
|
||||
- {
|
||||
- if (vsf_sysutil_write_access("/"))
|
||||
- {
|
||||
- die("vsftpd: refusing to run with writable root inside chroot()");
|
||||
- }
|
||||
- }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
--- a/twoprocess.c
|
||||
+++ b/twoprocess.c
|
||||
@@ -426,7 +426,7 @@ common_do_login(struct vsf_session* p_sess, const struct mystr* p_user_str,
|
||||
*/
|
||||
vsf_set_die_if_parent_dies();
|
||||
priv_sock_set_child_context(p_sess);
|
||||
- if (tunable_guest_enable && !anon)
|
||||
+ if (tunable_guest_enable && !anon && !str_getpwnam(p_user_str))
|
||||
{
|
||||
p_sess->is_guest = 1;
|
||||
/* Remap to the guest user */
|
||||
Reference in new issue
Block a user