Skip to content

Commit

Permalink
Merge pull request #126 from proftpd/core-host-cmd-bug3289
Browse files Browse the repository at this point in the history
Bug#3289 - Support the HOST command
  • Loading branch information
Castaglia committed May 22, 2015
2 parents 569488b + cf673bf commit ab34a8d
Show file tree
Hide file tree
Showing 29 changed files with 1,670 additions and 1,090 deletions.
39 changes: 37 additions & 2 deletions contrib/mod_ban.c
Expand Up @@ -147,6 +147,12 @@ struct ban_data {
struct ban_event_list events;
};

/* Tracks whether we have already seen the client connect, so that we only
* generate the 'client-connect-rate' event once, even in the face of multiple
* HOST commands.
*/
static int ban_client_connected = FALSE;

static struct ban_data *ban_lists = NULL;
static int ban_engine = -1;

Expand Down Expand Up @@ -209,6 +215,7 @@ static unsigned long ban_cache_opts = 0UL;
#define BAN_CACHE_OPT_MATCH_SERVER 0x001

static int ban_lock_shm(int);
static int ban_sess_init(void);

static void ban_anonrejectpasswords_ev(const void *, void *);
static void ban_badprotocol_ev(const void *, void *);
Expand Down Expand Up @@ -2990,6 +2997,27 @@ static void ban_restart_ev(const void *event_data, void *user_data) {
return;
}

static void ban_sess_reinit_ev(const void *event_data, void *user_data) {
int res;

/* A HOST command changed the main_server pointer, reinitialize ourselves. */

ban_cache_opts = 0UL;

if (mcache != NULL) {
(void) pr_memcache_conn_set_namespace(mcache, &ban_module, NULL);
mcache = NULL;
}

pr_event_unregister(&ban_module, "core.session-reinit", ban_sess_reinit_ev);

res = ban_sess_init();
if (res < 0) {
pr_session_disconnect(&ban_module, PR_SESS_DISCONNECT_SESSION_INIT_FAILED,
NULL);
}
}

static void ban_rootlogin_ev(const void *event_data, void *user_data) {
const char *ipstr = pr_netaddr_get_ipstr(session.c->remote_addr);

Expand Down Expand Up @@ -3119,8 +3147,12 @@ static int ban_sess_init(void) {
const char *remote_ip;
char *rule_mesg = NULL;

if (ban_engine != TRUE)
pr_event_register(&ban_module, "core.session-reinit", ban_sess_reinit_ev,
NULL);

if (ban_engine != TRUE) {
return 0;
}

/* Check to see if the BanEngine directive is set to 'off'. */
c = find_config(main_server->conf, CONF_PARAM, "BanEngine", FALSE);
Expand Down Expand Up @@ -3204,7 +3236,10 @@ static int ban_sess_init(void) {
}
}

pr_event_generate("mod_ban.client-connect-rate", session.c);
if (!ban_client_connected) {
pr_event_generate("mod_ban.client-connect-rate", session.c);
ban_client_connected = TRUE;
}

pr_event_unregister(&ban_module, "core.restart", ban_restart_ev);

Expand Down
3 changes: 3 additions & 0 deletions contrib/mod_copy.c
Expand Up @@ -38,10 +38,13 @@

extern pr_response_t *resp_list, *resp_err_list;

module copy_module;
static int copy_engine = TRUE;

static const char *trace_channel = "copy";

static int copy_sess_init(void);

/* These are copied largely from src/mkhome.c */

static int create_dir(const char *dir) {
Expand Down
55 changes: 43 additions & 12 deletions contrib/mod_deflate.c
Expand Up @@ -25,7 +25,6 @@
* This is mod_deflate, contrib software for proftpd 1.3.x and above.
* For more information contact TJ Saunders <tj@castaglia.org>.
*
* $Id: mod_deflate.c,v 1.14 2014-01-03 07:19:01 castaglia Exp $
* $Libraries: -lz $
*/

Expand All @@ -43,6 +42,8 @@

module deflate_module;

static int deflate_sess_init(void);

static int deflate_enabled = FALSE;
static int deflate_engine = FALSE;
static int deflate_logfd = -1;
Expand Down Expand Up @@ -920,12 +921,43 @@ MODRET deflate_mode(cmd_rec *cmd) {
return PR_DECLINED(cmd);
}

/* Event listeners
*/

static void deflate_sess_reinit_ev(const void *event_data, void *user_data) {
int res;

/* A HOST command changed the main_server pointer, reinitialize ourselves. */

pr_event_unregister(&deflate_module, "core.session-reinit",
deflate_sess_reinit_ev);

deflate_engine = FALSE;
pr_feat_remove("MODE Z");
(void) close(deflate_logfd);
deflate_logfd = -1;

res = deflate_sess_init();
if (res < 0) {
pr_session_disconnect(&deflate_module,
PR_SESS_DISCONNECT_SESSION_INIT_FAILED, NULL);
}
}

/* Initialization functions
*/

static int deflate_init(void) {
pr_log_debug(DEBUG5, MOD_DEFLATE_VERSION ": using zlib " ZLIB_VERSION);
return 0;
}

static int deflate_sess_init(void) {
config_rec *c;

pr_event_register(&deflate_module, "core.session-reinit",
deflate_sess_reinit_ev, NULL);

c = find_config(main_server->conf, CONF_PARAM, "DeflateEngine", FALSE);
if (c &&
*((unsigned int *) c->argv[0]) == TRUE) {
Expand Down Expand Up @@ -978,19 +1010,18 @@ static int deflate_sess_init(void) {
* Look up the optimal transfer buffer size, and use a factor of 8.
* Later, if needed, a larger buffer will be allocated when necessary.
*/
deflate_zbufsz = pr_config_get_xfer_bufsz() * 8;
deflate_zbuf_ptr = deflate_zbuf = pcalloc(session.pool, deflate_zbufsz);
deflate_zbuflen = 0;

deflate_rbufsz = pr_config_get_xfer_bufsz();
deflate_rbuf = palloc(session.pool, deflate_rbufsz);
deflate_rbuflen = 0;
if (deflate_zbuf == NULL) {
deflate_zbufsz = pr_config_get_xfer_bufsz() * 8;
deflate_zbuf_ptr = deflate_zbuf = pcalloc(session.pool, deflate_zbufsz);
deflate_zbuflen = 0;
}

return 0;
}
if (deflate_rbuf == NULL) {
deflate_rbufsz = pr_config_get_xfer_bufsz();
deflate_rbuf = palloc(session.pool, deflate_rbufsz);
deflate_rbuflen = 0;
}

static int deflate_init(void) {
pr_log_debug(DEBUG5, MOD_DEFLATE_VERSION ": using zlib " ZLIB_VERSION);
return 0;
}

Expand Down

0 comments on commit ab34a8d

Please sign in to comment.