Author: wrowe
Date: Mon Mar 26 18:56:17 2007
New Revision: 522706
URL: http://svn.apache.org/viewvc?view=rev&rev=522706
Log:
The scope of FTPDirMask and FTPUMask are much more dir-centric than server-centric.
Refactor them out of the server_conf scope into the dir_conf scope.
Modified:
httpd/mod_ftp/trunk/modules/ftp/ftp_commands.c
httpd/mod_ftp/trunk/modules/ftp/mod_ftp.c
Modified: httpd/mod_ftp/trunk/modules/ftp/ftp_commands.c
URL: http://svn.apache.org/viewvc/httpd/mod_ftp/trunk/modules/ftp/ftp_commands.c?view=diff&rev=522706&r1=522705&r2=522706
==============================================================================
--- httpd/mod_ftp/trunk/modules/ftp/ftp_commands.c (original)
+++ httpd/mod_ftp/trunk/modules/ftp/ftp_commands.c Mon Mar 26 18:56:17 2007
@@ -836,12 +836,11 @@
static int ftp_cmd_mkd(request_rec *r, const char *arg)
{
ftp_connection *fc = ftp_get_module_config(r->request_config);
- conn_rec *c = r->connection;
- ftp_server_config *fsc = ftp_get_module_config(c->base_server->module_config);
-
apr_status_t rv;
int res;
request_rec *rr;
+ ftp_dir_config *dconf;
+ apr_fileperms_t dirperms;
if ((res = ftp_set_uri(r, arg))) {
return res;
@@ -855,9 +854,23 @@
ap_destroy_sub_req(rr);
return FTP_REPLY_FILE_NOT_FOUND;
}
+
+ dconf = ftp_get_module_config(rr->per_dir_config);
+ dirperms = dconf->dirperms;
ap_destroy_sub_req(rr);
- rv = apr_dir_make(r->filename, fsc->dirperms, r->pool);
+ if (dirperms == APR_OS_DEFAULT)
+ dirperms = FTP_DEFAULT_UMASK;
+
+ /* In the config phase, ->fileperms was a negative umask.
+ * for operation, exchange this with a positive protections
+ * to pass to the apr_dir_make protection flag.
+ */
+ dirperms = (APR_UREAD | APR_UWRITE | APR_UEXECUTE |
+ APR_GREAD | APR_GWRITE | APR_GEXECUTE |
+ APR_WREAD | APR_WWRITE | APR_WEXECUTE)
+ & ~dirperms;
+ rv = apr_dir_make(r->filename, dirperms, r->pool);
if (rv != APR_SUCCESS) {
char error_str[120];
@@ -866,7 +879,7 @@
return FTP_REPLY_FILE_NOT_FOUND;
}
else {
- apr_file_perms_set(r->filename, fsc->dirperms);
+ apr_file_perms_set(r->filename, dirperms);
fc->response_notes = apr_psprintf(r->pool, FTP_MSG_DIR_CREAT,
r->parsed_uri.path);
return FTP_REPLY_PATH_CREATED;
@@ -2180,7 +2193,7 @@
ftp_connection *fc = ftp_get_module_config(r->request_config);
conn_rec *c = r->connection;
conn_rec *cdata;
- ftp_server_config *fsc = ftp_get_module_config(c->base_server->module_config);
+ ftp_dir_config *dconf;
apr_file_t *file;
apr_status_t rv, res;
apr_bucket_brigade *bb;
@@ -2194,12 +2207,11 @@
#ifndef WIN32
int seen_cr = 0;
#endif
+ apr_fileperms_t creatperms;
#ifdef HAVE_FCHMOD
- apr_fileperms_t creatperms = 0;
+ mode_t fixmode;
apr_finfo_t finfo;
int fd;
-#else
- apr_fileperms_t creatperms = fsc->fileperms;
#endif
apr_table_setn(r->subprocess_env, "do_transfer_log", "1");
@@ -2217,8 +2229,27 @@
return FTP_REPLY_FILE_NOT_FOUND;
}
+ dconf = ftp_get_module_config(rr->per_dir_config);
+ creatperms = dconf->fileperms;
ap_destroy_sub_req(rr);
+ if (creatperms == APR_OS_DEFAULT)
+ creatperms = FTP_DEFAULT_UMASK;
+
+ /* In the config phase, ->creatperms was a negative umask.
+ * for operation, exchange this with a positive protections
+ * to pass to the apr_file_open protection flag.
+ */
+ creatperms = (APR_UREAD | APR_UWRITE |
+ APR_GREAD | APR_GWRITE |
+ APR_WREAD | APR_WWRITE)
+ & ~creatperms;
+
+#ifdef HAVE_FCHMOD
+ fixmode = ftp_unix_perms2mode(creatperms);
+ creatperms = 0;
+#endif
+
/* For the remainder of the operation, (openflag & APR_APPEND)
* reflects this was an append operation and we have no need
* to truncate. Presume, if not append and our restart point
@@ -2263,7 +2294,6 @@
}
else {
apr_os_file_get(&fd, file);
- creatperms = fsc->fileperms;
}
#endif
@@ -2278,7 +2308,7 @@
"Unable to perform file upload; "
"failed to skip to restart point");
#ifdef HAVE_FCHMOD
- if (fd != -1) fchmod(fd, ftp_unix_perms2mode(creatperms));
+ if (fd != -1) fchmod(fd, fixmode);
#endif
fc->restart_point = 0;
return FTP_REPLY_FILE_NOT_FOUND;
@@ -2295,7 +2325,7 @@
*/
if ( !(cdata = ftp_open_dataconn(r, 0)) ) {
#ifdef HAVE_FCHMOD
- if (fd != -1) fchmod(fd, ftp_unix_perms2mode(creatperms));
+ if (fd != -1) fchmod(fd, fixmode);
#endif
return FTP_REPLY_CANNOT_OPEN_DATACONN;
}
@@ -2371,7 +2401,7 @@
* to no longer hold a lock on the uploaded file...
*/
#ifdef HAVE_FCHMOD
- if (fd != -1) fchmod(fd, ftp_unix_perms2mode(creatperms));
+ if (fd != -1) fchmod(fd, fixmode);
#endif
/* and truncate anything beyond the end of the most recent upload
Modified: httpd/mod_ftp/trunk/modules/ftp/mod_ftp.c
URL: http://svn.apache.org/viewvc/httpd/mod_ftp/trunk/modules/ftp/mod_ftp.c?view=diff&rev=522706&r1=522705&r2=522706
==============================================================================
--- httpd/mod_ftp/trunk/modules/ftp/mod_ftp.c (original)
+++ httpd/mod_ftp/trunk/modules/ftp/mod_ftp.c Mon Mar 26 18:56:17 2007
@@ -86,26 +86,6 @@
for (; s; s = s->next) {
ftp_server_config *fsc = ftp_get_module_config(s->module_config);
- if (fsc->fileperms == APR_OS_DEFAULT)
- fsc->fileperms = FTP_DEFAULT_UMASK;
-
- if (fsc->dirperms == APR_OS_DEFAULT)
- fsc->dirperms = FTP_DEFAULT_UMASK;
-
- /* In the config phase, ->fileperms was a negative umask.
- * for operation, exchange this with a positive protections
- * to pass to the apr_file_open protection flag.
- */
- fsc->fileperms = (APR_UREAD | APR_UWRITE |
- APR_GREAD | APR_GWRITE |
- APR_WREAD | APR_WWRITE)
- & ~fsc->fileperms;
-
- fsc->dirperms = (APR_UREAD | APR_UWRITE | APR_UEXECUTE |
- APR_GREAD | APR_GWRITE | APR_GEXECUTE |
- APR_WREAD | APR_WWRITE | APR_WEXECUTE)
- & ~fsc->dirperms;
-
if (fsc->timeout_login == FTP_UNSPEC)
fsc->timeout_login = FTP_TIMEOUT_LOGIN;
if (fsc->timeout_idle == FTP_UNSPEC)
@@ -156,8 +136,6 @@
{
ftp_server_config *fsc = apr_pcalloc(p, sizeof(*fsc));
- fsc->fileperms = APR_OS_DEFAULT;
- fsc->dirperms = APR_OS_DEFAULT;
fsc->timeout_login = FTP_UNSPEC;
fsc->timeout_idle = FTP_UNSPEC;
fsc->timeout_data = FTP_UNSPEC;
@@ -189,12 +167,6 @@
*/
memcpy (fsc, add, sizeof(*fsc));
- if (fsc->fileperms == APR_OS_DEFAULT)
- fsc->fileperms = base->fileperms;
-
- if(fsc->dirperms == APR_OS_DEFAULT)
- fsc->dirperms = base->dirperms;
-
if (fsc->timeout_login == FTP_UNSPEC)
fsc->timeout_login = base->timeout_login;
if (fsc->timeout_idle == FTP_UNSPEC)
@@ -244,29 +216,27 @@
{
ftp_dir_config *conf = apr_pcalloc(p, sizeof(*conf));
+ conf->fileperms = APR_OS_DEFAULT;
+ conf->dirperms = APR_OS_DEFAULT;
+
return conf;
}
static void *merge_ftp_dir_config(apr_pool_t *p, void *basev, void *addv)
{
- /* XXX: base is unused, this is always symptomatic of bad config
- design. Needs review.
- */
ftp_dir_config *base = (ftp_dir_config *)basev;
ftp_dir_config *add = (ftp_dir_config *)addv;
ftp_dir_config *conf = apr_palloc(p, sizeof(*conf));
- /* NO-INHERIT the FTPReadmeMessage? */
+ /* XXX: NO-INHERIT the FTPReadmeMessage? */
conf->path = add->path;
conf->readme = add->readme;
conf->readme_isfile = add->readme_isfile;
- /* TODO:
- * if we adopt FTPUMask as a per-dir, we must blend it
- * with FTPReadmeMessage inheritence here.
- * since today we don't inherit FTPReadmeMessage this
- * merger is a no-op.
- */
+ conf->fileperms = (add->fileperms == APR_OS_DEFAULT)
+ ? base->fileperms : add->fileperms;
+ conf->dirperms = (add->dirperms == APR_OS_DEFAULT)
+ ? base->dirperms : add->dirperms;
return conf;
}
@@ -456,15 +426,14 @@
return NULL;
}
-static const char *ftp_umask(cmd_parms *cmd, void *dummy, const char *arg)
+static const char *ftp_umask(cmd_parms *cmd, void *dconf, const char *arg)
{
#ifdef HAVE_FCHMOD
int umask, mode;
char *endp;
char *error_str = NULL;
- ftp_server_config *fsc =
- ftp_get_module_config(cmd->server->module_config);
+ ftp_dir_config *d = dconf;
umask = strtol(arg, &endp, 8);
mode = umask & 0666;
@@ -475,7 +444,7 @@
cmd->directive->directive);
}
else {
- fsc->fileperms = ftp_unix_mode2perms(mode);
+ d->fileperms = ftp_unix_mode2perms(mode);
}
return error_str;
#else
@@ -484,16 +453,15 @@
}
-static const char *ftp_dirumask(cmd_parms *cmd, void *dummy, const char *arg)
+static const char *ftp_dirumask(cmd_parms *cmd, void *dconf, const char *arg)
{
#ifdef HAVE_FCHMOD
int umask, xmask, mode;
char *endp;
char *error_str = NULL;
- ftp_server_config *fsc =
- ftp_get_module_config(cmd->server->module_config);
-
+ ftp_dir_config *d = dconf;
+
umask = strtol(arg, &endp, 8);
/* Here the r bits of umask are taken to xmask all other bits
@@ -516,7 +484,7 @@
cmd->directive->directive);
}
else {
- fsc->dirperms = ftp_unix_mode2perms(mode);
+ d->dirperms = ftp_unix_mode2perms(mode);
}
return error_str;
#else
@@ -879,9 +847,9 @@
static const command_rec ftp_cmds[] = {
AP_INIT_FLAG("FTP", ftp_enable, NULL, RSRC_CONF,
"Run an FTP server on this host"),
- AP_INIT_TAKE1("FTPUmask", ftp_umask, NULL, RSRC_CONF,
+ AP_INIT_TAKE1("FTPUmask", ftp_umask, NULL, OR_FILEINFO,
"Set the umask for created files"),
- AP_INIT_TAKE1("FTPDirUmask", ftp_dirumask, NULL, RSRC_CONF,
+ AP_INIT_TAKE1("FTPDirUmask", ftp_dirumask, NULL, OR_FILEINFO,
"Set the umask for created directory"),
AP_INIT_TAKE1("FTPTimeoutLogin", ftp_set_int_slot,
(void *)APR_OFFSETOF(ftp_server_config,
|