diff --git a/modules/mod_core.c b/modules/mod_core.c
index e33ee11..f680748 100644
--- a/modules/mod_core.c
+++ b/modules/mod_core.c
@@ -4775,6 +4775,7 @@ MODRET core_rmd(cmd_rec *cmd) {
dir = dir_canonical_path(cmd->tmp_pool, dir);
if (dir == NULL) {
int xerrno = EINVAL;
+ cmd->error_code = EINVAL;
pr_response_add_err(R_550, "%s: %s", cmd->arg, strerror(xerrno));
@@ -4784,6 +4785,7 @@ MODRET core_rmd(cmd_rec *cmd) {
if (!dir_check_canon(cmd->tmp_pool, cmd, cmd->group, dir, NULL)) {
int xerrno = EACCES;
+ cmd->error_code = EACCES;
pr_response_add_err(R_550, "%s: %s", cmd->arg, strerror(xerrno));
@@ -4793,6 +4795,7 @@ MODRET core_rmd(cmd_rec *cmd) {
if (pr_fsio_rmdir(dir) < 0) {
int xerrno = errno;
+ cmd->error_code = errno;
(void) pr_trace_msg("fileperms", 1, "%s, user '%s' (UID %lu, GID %lu): "
"error removing directory '%s': %s", cmd->argv[0], session.user,
@@ -4849,6 +4852,7 @@ MODRET core_mkd(cmd_rec *cmd) {
dir = dir_canonical_path(cmd->tmp_pool, dir);
if (dir == NULL) {
int xerrno = EINVAL;
+ cmd->error_code = EINVAL;
pr_response_add_err(R_550, "%s: %s", cmd->arg, strerror(xerrno));
@@ -4858,6 +4862,7 @@ MODRET core_mkd(cmd_rec *cmd) {
if (!dir_check_canon(cmd->tmp_pool, cmd, cmd->group, dir, NULL)) {
int xerrno = EACCES;
+ cmd->error_code = EACCES;
pr_log_debug(DEBUG8, "%s command denied by <Limit> config", cmd->argv[0]);
pr_response_add_err(R_550, "%s: %s", cmd->arg, strerror(xerrno));
@@ -4869,6 +4874,7 @@ MODRET core_mkd(cmd_rec *cmd) {
if (pr_fsio_smkdir(cmd->tmp_pool, dir, 0777, session.fsuid,
session.fsgid) < 0) {
int xerrno = errno;
+ cmd->error_code = errno;
(void) pr_trace_msg("fileperms", 1, "%s, user '%s' (UID %lu, GID %lu): "
"error making directory '%s': %s", cmd->argv[0], session.user,
@@ -4915,6 +4921,7 @@ MODRET core_mdtm(cmd_rec *cmd) {
!dir_check(cmd->tmp_pool, cmd, cmd->group, path, NULL) ||
pr_fsio_stat(path, &st) == -1) {
int xerrno = errno;
+ cmd->error_code = errno;
pr_response_add_err(R_550, "%s: %s", cmd->arg, strerror(xerrno));
@@ -5026,6 +5033,7 @@ MODRET core_dele(cmd_rec *cmd) {
path = dir_canonical_path(cmd->tmp_pool, path);
if (path == NULL) {
int xerrno = ENOENT;
+ cmd->error_code = ENOENT;
pr_response_add_err(R_550, "%s: %s", cmd->arg, strerror(xerrno));
@@ -5035,6 +5043,7 @@ MODRET core_dele(cmd_rec *cmd) {
if (!dir_check(cmd->tmp_pool, cmd, cmd->group, path, NULL)) {
int xerrno = errno;
+ cmd->error_code = errno;
pr_log_debug(DEBUG7, "deleting '%s' denied by <Limit> configuration", path);
pr_response_add_err(R_550, "%s: %s", cmd->arg, strerror(xerrno));
@@ -5051,6 +5060,7 @@ MODRET core_dele(cmd_rec *cmd) {
pr_fs_clear_cache();
if (pr_fsio_lstat(path, &st) < 0) {
int xerrno = errno;
+ cmd->error_code = errno;
pr_log_debug(DEBUG3, "unable to lstat '%s': %s", path, strerror(xerrno));
pr_response_add_err(R_550, "%s: %s", cmd->arg, strerror(xerrno));
@@ -5065,6 +5075,7 @@ MODRET core_dele(cmd_rec *cmd) {
*/
if (S_ISDIR(st.st_mode)) {
int xerrno = EISDIR;
+ cmd->error_code = EISDIR;
(void) pr_trace_msg("fileperms", 1, "%s, user '%s' (UID %lu, GID %lu): "
"error deleting '%s': %s", cmd->argv[0], session.user,
@@ -5081,6 +5092,7 @@ MODRET core_dele(cmd_rec *cmd) {
if (pr_fsio_unlink(path) < 0) {
int xerrno = errno;
+ cmd->error_code = errno;
(void) pr_trace_msg("fileperms", 1, "%s, user '%s' (UID %lu, GID %lu): "
"error deleting '%s': %s", cmd->argv[0], session.user,
@@ -5165,6 +5177,7 @@ MODRET core_rnto(cmd_rec *cmd) {
pr_log_debug(DEBUG6, "AllowOverwrite denied permission for %s", path);
pr_response_add_err(R_550, _("%s: Rename permission denied"), cmd->arg);
errno = EACCES;
+ cmd->error_code = EACCES;
return PR_ERROR(cmd);
}
@@ -5172,6 +5185,7 @@ MODRET core_rnto(cmd_rec *cmd) {
!dir_check_canon(cmd->tmp_pool, cmd, cmd->group, path, NULL) ||
pr_fsio_rename(session.xfer.path, path) == -1) {
int xerrno = errno;
+ cmd->error_code = errno;
if (xerrno != EXDEV) {
(void) pr_trace_msg("fileperms", 1, "%s, user '%s' (UID %lu, GID %lu): "
@@ -5223,6 +5237,7 @@ MODRET core_rnto(cmd_rec *cmd) {
*/
if (pr_fs_copy_file(session.xfer.path, path) < 0) {
xerrno = errno;
+ cmd->error_code = errno;
(void) pr_trace_msg("fileperms", 1, "%s, user '%s' (UID %lu, GID %lu): "
"error copying '%s' to '%s': %s", cmd->argv[0], session.user,
@@ -5238,6 +5253,8 @@ MODRET core_rnto(cmd_rec *cmd) {
/* Once copied, unlink the original file. */
if (pr_fsio_unlink(session.xfer.path) < 0) {
+ cmd->error_code = errno;
+
pr_log_debug(DEBUG0, "error unlinking '%s': %s", session.xfer.path,
strerror(errno));
}
@@ -5295,6 +5312,7 @@ MODRET core_rnfr(cmd_rec *cmd) {
!dir_check(cmd->tmp_pool, cmd, cmd->group, path, NULL) ||
!exists(path)) {
int xerrno = errno;
+ cmd->error_code = errno;
pr_response_add_err(R_550, "%s: %s", cmd->arg, strerror(xerrno));
--- a/modules/mod_xfer.c 2016-03-10 17:04:32.000000000 -0800
+++ proftpd-1.3.5b/modules/mod_xfer.c 2016-04-01 01:54:06.383804153 -0700
@@ -1187,6 +1187,7 @@
if (cmd->argc < 2) {
pr_response_add_err(R_500, _("'%s' not understood"),
pr_cmd_get_displayable_str(cmd, NULL));
+ cmd->error_code = EINVAL;
errno = EINVAL;
return PR_ERROR(cmd);
}
@@ -1197,6 +1198,7 @@
if (!path ||
!dir_check(cmd->tmp_pool, cmd, cmd->group, path, NULL)) {
int xerrno = errno;
+ cmd->error_code = errno;
pr_log_debug(DEBUG8, "%s %s denied by <Limit> configuration", cmd->argv[0],
cmd->arg);
@@ -1229,6 +1231,7 @@
if (xfer_check_limit(cmd) < 0) {
pr_response_add_err(R_451, _("%s: Too many transfers"), cmd->arg);
errno = EPERM;
+ cmd->error_code = EPERM;
return PR_ERROR(cmd);
}
@@ -1241,6 +1244,7 @@
pr_log_debug(DEBUG6, "AllowOverwrite denied permission for %s", cmd->arg);
pr_response_add_err(R_550, _("%s: Overwrite permission denied"), cmd->arg);
errno = EACCES;
+ cmd->error_code = EACCES;
return PR_ERROR(cmd);
}
@@ -1264,6 +1268,7 @@
/* Deliberately use EISDIR for anything non-file (e.g. directories). */
errno = EISDIR;
+ cmd->error_code = EISDIR;
return PR_ERROR(cmd);
}
}
@@ -1282,6 +1287,7 @@
session.restart_pos = 0L;
session.xfer.xfer_type = STOR_DEFAULT;
errno = EPERM;
+ cmd->error_code = EPERM;
return PR_ERROR(cmd);
}
@@ -1303,6 +1309,7 @@
/* Otherwise everthing is good */
if (pr_table_add(cmd->notes, "mod_xfer.store-path",
pstrdup(cmd->pool, path), 0) < 0) {
+ cmd->error_code = errno;
if (errno != EEXIST) {
pr_log_pri(PR_LOG_NOTICE,
"notice: error adding 'mod_xfer.store-path': %s", strerror(errno));
@@ -1323,6 +1330,7 @@
pr_response_add_err(R_501,
_("REST not compatible with server configuration"));
errno = EINVAL;
+ cmd->error_code = EINVAL;
return PR_ERROR(cmd);
}
@@ -1332,6 +1340,7 @@
pr_response_add_err(R_550,
_("APPE not compatible with server configuration"));
errno = EINVAL;
+ cmd->error_code = EINVAL;
return PR_ERROR(cmd);
}
@@ -1398,6 +1407,7 @@
stou_fd = mkstemp(filename);
if (stou_fd < 0) {
int xerrno = errno;
+ cmd->error_code = errno;
pr_log_pri(PR_LOG_WARNING, "error: unable to use mkstemp(): %s",
strerror(xerrno));
@@ -1426,6 +1436,7 @@
if (filename == NULL ||
!dir_check(cmd->tmp_pool, cmd, cmd->group, filename, NULL)) {
int xerrno = errno;
+ cmd->error_code = errno;
/* Do not forget to delete the file created by mkstemp(3) if there is
* an error.
@@ -1459,12 +1470,14 @@
/* Deliberately use EISDIR for anything non-file (e.g. directories). */
errno = EISDIR;
+ cmd->error_code = errno;
return PR_ERROR(cmd);
}
/* Otherwise everthing is good */
if (pr_table_add(cmd->notes, "mod_xfer.store-path",
pstrdup(cmd->pool, filename), 0) < 0) {
+ cmd->error_code = errno;
if (errno != EEXIST) {
pr_log_pri(PR_LOG_NOTICE,
"notice: error adding 'mod_xfer.store-path': %s", strerror(errno));
@@ -1499,6 +1512,8 @@
perms = (0666 & ~mask);
if (pr_fsio_chmod(cmd->arg, perms) < 0) {
+ cmd->error_code = errno;
+
/* Not much to do but log the error. */
pr_log_pri(PR_LOG_NOTICE, "error: unable to chmod '%s' to %04o: %s",
cmd->arg, perms, strerror(errno));
@@ -1516,6 +1531,7 @@
if (xfer_check_limit(cmd) < 0) {
pr_response_add_err(R_451, _("%s: Too many transfers"), cmd->arg);
errno = EPERM;
+ cmd->error_code = EPERM;
return PR_ERROR(cmd);
}
@@ -1586,6 +1602,7 @@
if (stor_fh) {
if (pr_fsio_lseek(stor_fh, 0, SEEK_END) == (off_t) -1) {
+ cmd->error_code = errno;
pr_log_debug(DEBUG4, "unable to seek to end of '%s' for appending: %s",
cmd->arg, strerror(errno));
(void) pr_fsio_close(stor_fh);
@@ -1594,6 +1611,7 @@
} else {
ferrno = errno;
+ cmd->error_code = errno;
(void) pr_trace_msg("fileperms", 1, "%s, user '%s' (UID %lu, GID %lu): "
"error opening '%s': %s", cmd->argv[0], session.user,
@@ -1607,6 +1625,7 @@
O_WRONLY|(session.restart_pos ? 0 : O_TRUNC|O_CREAT));
if (stor_fh == NULL) {
ferrno = errno;
+ cmd->error_code = errno;
(void) pr_trace_msg("fileperms", 1, "%s, user '%s' (UID %lu, GID %lu): "
"error opening '%s': %s", cmd->argv[0], session.user,
@@ -1620,11 +1639,13 @@
int xerrno = 0;
if (pr_fsio_lseek(stor_fh, session.restart_pos, SEEK_SET) == -1) {
+ cmd->error_code = errno;
pr_log_debug(DEBUG4, "unable to seek to position %" PR_LU " of '%s': %s",
(pr_off_t) session.restart_pos, cmd->arg, strerror(errno));
xerrno = errno;
} else if (pr_fsio_stat(path, &st) == -1) {
+ cmd->error_code = errno;
pr_log_debug(DEBUG4, "unable to stat '%s': %s", cmd->arg,
strerror(errno));
xerrno = errno;
@@ -1761,6 +1782,7 @@
pr_data_abort(EPERM, FALSE);
errno = EPERM;
#endif
+ cmd->error_code = errno;
return PR_ERROR(cmd);
}
@@ -1772,6 +1794,7 @@
res = pr_fsio_write(stor_fh, lbuf, len);
if (res != len) {
int xerrno = EIO;
+ cmd->error_code = errno;
if (res < 0)
xerrno = errno;
@@ -1801,6 +1824,7 @@
/* default abort errno, in case session.d et al has already gone away */
int xerrno = ECONNABORTED;
+ cmd->error_code = ECONNABORTED;
stor_abort();
@@ -1820,6 +1844,7 @@
if (stor_complete() < 0) {
int xerrno = errno;
+ cmd->error_code = errno;
_log_transfer('i', 'i');
@@ -1832,12 +1857,14 @@
if (xerrno == EDQUOT) {
pr_response_add_err(R_552, "%s: %s", cmd->arg, strerror(xerrno));
errno = xerrno;
+ cmd->error_code = errno;
return PR_ERROR(cmd);
}
#elif defined(EFBIG)
if (xerrno == EFBIG) {
pr_response_add_err(R_552, "%s: %s", cmd->arg, strerror(xerrno));
errno = xerrno;
+ cmd->error_code = errno;
return PR_ERROR(cmd);
}
#endif
@@ -1851,6 +1878,7 @@
session.xfer.path_hidden) {
if (pr_fsio_rename(session.xfer.path_hidden, session.xfer.path) != 0) {
int xerrno = errno;
+ cmd->error_code = errno;
/* This should only fail on a race condition with a chmod/chown
* or if STOR_APPEND is on and the permissions are squirrely.
@@ -1953,6 +1981,7 @@
pr_response_add_err(R_500, _("'%s' not understood"),
pr_cmd_get_displayable_str(cmd, NULL));
errno = EINVAL;
+ cmd->error_code = EINVAL;
return PR_ERROR(cmd);
}
@@ -1962,6 +1991,7 @@
if (!dir ||
!dir_check(cmd->tmp_pool, cmd, cmd->group, dir, NULL)) {
int xerrno = errno;
+ cmd->error_code;
pr_response_add_err(R_550, "%s: %s", cmd->arg, strerror(xerrno));
@@ -1984,12 +2014,14 @@
if (xfer_check_limit(cmd) < 0) {
pr_response_add_err(R_451, _("%s: Too many transfers"), cmd->arg);
errno = EPERM;
+ cmd->error_code = EPERM;
return PR_ERROR(cmd);
}
fmode = file_mode(dir);
if (fmode == 0) {
int xerrno = errno;
+ cmd->error_code = errno;
pr_response_add_err(R_550, "%s: %s", cmd->arg, strerror(xerrno));
@@ -2006,6 +2038,7 @@
/* Deliberately use EISDIR for anything non-file (e.g. directories). */
errno = EISDIR;
+ cmd->error_code = EISDIR;
return PR_ERROR(cmd);
}
@@ -2020,12 +2053,14 @@
cmd->arg);
session.restart_pos = 0L;
errno = EPERM;
+ cmd->error_code = EPERM;
return PR_ERROR(cmd);
}
/* Otherwise everthing is good */
if (pr_table_add(cmd->notes, "mod_xfer.retr-path",
pstrdup(cmd->pool, dir), 0) < 0) {
+ cmd->error_code = errno;
if (errno != EEXIST) {
pr_log_pri(PR_LOG_NOTICE, "notice: error adding 'mod_xfer.retr-path': %s",
strerror(errno));
@@ -2052,6 +2087,7 @@
retr_fh = pr_fsio_open(dir, O_RDONLY);
if (retr_fh == NULL) {
int xerrno = errno;
+ cmd->error_code = errno;
(void) pr_trace_msg("fileperms", 1, "%s, user '%s' (UID %lu, GID %lu): "
"error opening '%s': %s", cmd->argv[0], session.user,
@@ -2065,6 +2101,7 @@
if (pr_fsio_stat(dir, &st) < 0) {
/* Error stat'ing the file. */
int xerrno = errno;
+ cmd->error_code = errno;
pr_fsio_close(retr_fh);
errno = xerrno;
@@ -2089,6 +2126,7 @@
if (pr_fsio_lseek(retr_fh, session.restart_pos,
SEEK_SET) == (off_t) -1) {
int xerrno = errno;
+ cmd->error_code = errno;
pr_fsio_close(retr_fh);
errno = xerrno;
retr_fh = NULL;
@@ -2149,6 +2187,7 @@
retr_abort();
/* Set errno to EPERM ("Operation not permitted") */
+ cmd->error_code = EPERM;
pr_data_abort(EPERM, FALSE);
return PR_ERROR(cmd);
}
@@ -2180,6 +2219,7 @@
* is preserved; errno itself might be overwritten in retr_abort().
*/
int xerrno = errno;
+ cmd->error_code = errno;
retr_abort();
pr_data_abort(xerrno, FALSE);
--- a/include/dirtree.h 2016-03-10 17:04:32.000000000 -0800
+++ proftpd-1.3.5b/include/dirtree.h 2016-04-01 02:00:13.315707095 -0700
@@ -127,6 +127,10 @@
int cmd_id; /* Index into commands list, for faster comparisons */
+ int error_code; /* Stores errno of failed file transfer commands.
+ * Required for Solaris auditing.
+ */
+
/* If we detect that the client sent commands for a protocol OTHER than
* FTP, then this field will be FALSE; the protocol field will identify
* the detected protocol.