repos.c revision 0c9166d0186cf0e1ad397025f730ae6967f44ce6
842ae4bd224140319ae7feec1872b93dfd491143fielding/* Copyright 2000-2006 The Apache Software Foundation or its licensors, as
842ae4bd224140319ae7feec1872b93dfd491143fielding * applicable.
842ae4bd224140319ae7feec1872b93dfd491143fielding * Licensed under the Apache License, Version 2.0 (the "License");
842ae4bd224140319ae7feec1872b93dfd491143fielding * you may not use this file except in compliance with the License.
842ae4bd224140319ae7feec1872b93dfd491143fielding * You may obtain a copy of the License at
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * Unless required by applicable law or agreed to in writing, software
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * distributed under the License is distributed on an "AS IS" BASIS,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * See the License for the specific language governing permissions and
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * limitations under the License.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes** DAV filesystem-based repository provider
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#include "http_protocol.h" /* for ap_set_* (in dav_fs_set_headers) */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#include "http_request.h" /* for ap_update_mtime() */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/* to assist in debugging mod_dav's GET handling */
d266c3777146d36a4c23c17aad6f153aebea1bf4jorton#define DAV_FS_COPY_BLOCKSIZE 16384 /* copy 16k at a time */
d266c3777146d36a4c23c17aad6f153aebea1bf4jorton/* context needed to identify a resource */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_pool_t *pool; /* memory storage pool associated with request */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes const char *pathname; /* full pathname to resource */
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes/* private context for doing a filesystem walk */
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholestypedef struct {
22f8da8087791fcb95b836c8a81937c5a9bba202bnicholes /* the input walk parameters */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* reused as we walk */
0f60998368b493f90120180a93fc2e1e74490872covener /* MOVE/COPY need a secondary path */
0568280364eb026393be492ebc732795c4934643jortontypedef struct {
0568280364eb026393be492ebc732795c4934643jorton dav_buffer work_buf; /* handy buffer for copymove_file() */
0568280364eb026393be492ebc732795c4934643jorton /* CALLBACK: this is a secondary resource managed specially for us */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* copied from dav_walk_params (they are invariant across the walk) */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/* an internal WALKTYPE to walk hidden files (the .DAV directory) */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/* an internal WALKTYPE to call collections (again) after their contents */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#define DAV_CALLTYPE_POSTFIX 1000 /* a private call type */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/* pull this in from the other source file */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/* forward-declare the hook structures */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic const dav_hooks_repository dav_hooks_repository_fs;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic const dav_hooks_liveprop dav_hooks_liveprop_fs;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes** The namespace URIs that we use. This list and the enumeration must
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes** stay in sync.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic const char * const dav_fs_namespace_uris[] =
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes DAV_FS_URI_MYPROPS /* the namespace URI for our custom props */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes** Does this platform support an executable flag?
a1790fb35c4b352dab721370985c623a9f8f5062rpluem** ### need a way to portably abstract this query
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe** The single property that we define (in the DAV_FS_URI_MYPROPS namespace)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* standard DAV properties */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "creationdate",
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "getcontentlength",
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "getlastmodified",
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener /* our custom properties */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "executable",
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes 0 /* handled special in dav_fs_is_writable */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes { 0 } /* sentinel */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic const dav_liveprop_group dav_fs_liveprop_group =
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/* define the dav_stream structure for our use */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes const char *pathname; /* we may need to remove it at close time */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/* returns an appropriate HTTP status code given an APR status code for a
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * failed I/O operation. ### use something besides 500? */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#define MAP_IO2HTTP(e) (APR_STATUS_IS_ENOSPC(e) ? HTTP_INSUFFICIENT_STORAGE : \
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/* forward declaration for internal treewalkers */
1f299703465bd9975d94e9f229f76af807442de2covenerstatic dav_error * dav_fs_walk(const dav_walk_params *params, int depth,
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovenerstatic dav_error * dav_fs_internal_walk(const dav_walk_params *params,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/* --------------------------------------------------------------------
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes** PRIVATE REPOSITORY FUNCTIONS
9ad7b260be233be7d7b5576979825cac72e15498rederpjapr_pool_t *dav_fs_pool(const dav_resource *resource)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesconst char *dav_fs_pathname(const dav_resource *resource)
3e6d7277b90d3011db832139afc20efb5f17e203rederpj const char **dirpath_p,
3e6d7277b90d3011db832139afc20efb5f17e203rederpj const char **fname_p)
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener char *dirpath = ap_make_dirstr_parent(ctx->pool, ctx->pathname);
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener rv = apr_filepath_root(&rootpath, &testpath, 0, ctx->pool);
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener /* remove trailing slash from dirpath, unless it's a root path
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener /* ###: Looks like a response could be appropriate
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * APR_SUCCESS here tells us the dir is a root
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * APR_ERELATIVE told us we had no root (ok)
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * APR_EINCOMPLETE an incomplete testpath told us
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * there was no -file- name here!
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * APR_EBADPATH or other errors tell us this file
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener * path is undecipherable
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener return dav_new_error(ctx->pool, HTTP_INTERNAL_SERVER_ERROR, 0,
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener "An incomplete/bad path was found in "
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener "dav_fs_dir_file_name.");
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener/* Note: picked up from ap_gm_timestr_822() */
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener/* NOTE: buf must be at least DAV_TIMEBUF_SIZE chars in size */
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovenerstatic void dav_format_time(int style, apr_time_t sec, char *buf)
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener /* ### what to do if fails? */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* ### should we use "-00:00" instead of "Z" ?? */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes /* 20 chars plus null term */
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes /* RFC 822 date format; as strftime '%a, %d %b %Y %T GMT' */
e8f95a682820a599fe41b22977010636be5c2717jim /* 29 chars plus null term */
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes "%s, %.2d %s %d %.2d:%.2d:%.2d GMT",
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes/* Copy or move src to dst; src_finfo is used to propagate permissions
ebe5305f8b22507374358f32b74d12fb50c05a25covener * bits across if non-NULL; dst_finfo must be non-NULL iff dst already
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes * exists. */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes const char *src,
513b324e774c559b579896df131fd7c8471ed529rederpj const char *dst,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* Determine permissions to use for destination */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes if (src_finfo && src_finfo->valid & APR_FINFO_PROT
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* chmod it if it already exist */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes "Could not set permissions on destination");
9ad7b260be233be7d7b5576979825cac72e15498rederpj if ((apr_file_open(&inf, src, APR_READ | APR_BINARY, APR_OS_DEFAULT, p))
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes /* ### use something besides 500? */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0,
54d22ed1c429b903b029bbd62621f11a9e286137minfrin "Could not open file for reading");
ebe5305f8b22507374358f32b74d12fb50c05a25covener /* ### do we need to deal with the umask? */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes status = apr_file_open(&outf, dst, APR_WRITE | APR_CREATE | APR_TRUNCATE
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes "Could not open file for writing");
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* ### ACK! Inconsistent state... */
b08925593f214f621161742925dcf074a8047e0acovener /* ### use something besides 500? */
b08925593f214f621161742925dcf074a8047e0acovener return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "Could not delete output after read "
9ad7b260be233be7d7b5576979825cac72e15498rederpj "failure. Server is now in an "
9ad7b260be233be7d7b5576979825cac72e15498rederpj "inconsistent state.");
9ad7b260be233be7d7b5576979825cac72e15498rederpj /* ### use something besides 500? */
9ad7b260be233be7d7b5576979825cac72e15498rederpj return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0,
128a5d93141a86e3afa151e921035a07297c9833rederpj "Could not read input file");
128a5d93141a86e3afa151e921035a07297c9833rederpj /* write any bytes that were read */
9ad7b260be233be7d7b5576979825cac72e15498rederpj status = apr_file_write_full(outf, pbuf->buf, len, NULL);
9ad7b260be233be7d7b5576979825cac72e15498rederpj /* ### ACK! Inconsistent state... */
87587593f1a53030e840acc0dec6cc881022ea40covener /* ### use something besides 500? */
9ad7b260be233be7d7b5576979825cac72e15498rederpj return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0,
9ad7b260be233be7d7b5576979825cac72e15498rederpj "Could not delete output after write "
9ad7b260be233be7d7b5576979825cac72e15498rederpj "failure. Server is now in an "
9ad7b260be233be7d7b5576979825cac72e15498rederpj "inconsistent state.");
9ad7b260be233be7d7b5576979825cac72e15498rederpj "Could not write output file");
9ad7b260be233be7d7b5576979825cac72e15498rederpj if (is_move && apr_file_remove(src, p) != APR_SUCCESS) {
9ad7b260be233be7d7b5576979825cac72e15498rederpj int save_errno = errno; /* save the errno that got us here */
7add8f7fb048534390571801b7794f71cd9e127abnicholes /* ### ACK. this creates an inconsistency. do more!? */
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem /* ### use something besides 500? */
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem /* Note that we use the latest errno */
7add8f7fb048534390571801b7794f71cd9e127abnicholes return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0,
7add8f7fb048534390571801b7794f71cd9e127abnicholes "Could not remove source or destination "
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes "file. Server is now in an inconsistent "
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes /* ### use something besides 500? */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes err = dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0,
7add8f7fb048534390571801b7794f71cd9e127abnicholes "Could not remove source file after move. "
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes "Destination was removed to ensure consistency.");
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes/* copy/move a file from within a state dir to another state dir */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes/* ### need more buffers to replace the pool argument */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes apr_finfo_t dst_state_finfo; /* finfo for STATE directory */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes const char *src;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes const char *dst;
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes /* build the propset pathname for the source file */
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes src = apr_pstrcat(p, src_dir, "/" DAV_FS_STATE_DIR "/", src_file, NULL);
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes /* the source file doesn't exist */
3dfeb02cfb853d8717ca0cc259b59fea610173f5bnicholes rv = apr_stat(&src_finfo, src, APR_FINFO_NORM, p);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes /* build the pathname for the destination state dir */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes dst = apr_pstrcat(p, dst_dir, "/" DAV_FS_STATE_DIR, NULL);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes /* ### do we need to deal with the umask? */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes /* ensure that it exists */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes /* ### use something besides 500? */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes "Could not create internal state directory");
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes /* get info about the state directory */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes rv = apr_stat(&dst_state_finfo, dst, APR_FINFO_NORM, p);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes /* Ack! Where'd it go? */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes /* ### use something besides 500? */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes "State directory disappeared");
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes /* The mkdir() may have failed because a *file* exists there already */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes /* ### try to recover by deleting this file? (and mkdir again) */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes /* ### use something besides 500? */
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes "State directory is actually a file");
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes /* append the target file to the state directory pathname */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* copy/move the file now */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (is_move && src_finfo.device == dst_state_finfo.device) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* simple rename is possible since it is on the same device */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (apr_file_rename(src, dst, p) != APR_SUCCESS) {
e8f95a682820a599fe41b22977010636be5c2717jim /* ### use something besides 500? */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "Could not move state file.");
54d22ed1c429b903b029bbd62621f11a9e286137minfrin /* gotta copy (and delete) */
54d22ed1c429b903b029bbd62621f11a9e286137minfrin return dav_fs_copymove_file(is_move, p, src, dst, NULL, NULL, pbuf);
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholesstatic dav_error *dav_fs_copymoveset(int is_move, apr_pool_t *p,
d330a801b1e5d63a4b8b4fd431542ad0903fd71bbnicholes const char *src_dir;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes const char *dst_dir;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* Get directory and filename for resources */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* ### should test these result values... */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes (void) dav_fs_dir_file_name(src, &src_dir, &src_file);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes (void) dav_fs_dir_file_name(dst, &dst_dir, &dst_file);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* Get the corresponding state files for each resource */
54d22ed1c429b903b029bbd62621f11a9e286137minfrin dav_dbm_get_statefiles(p, src_file, &src_state1, &src_state2);
54d22ed1c429b903b029bbd62621f11a9e286137minfrin dav_dbm_get_statefiles(p, dst_file, &dst_state1, &dst_state2);
54d22ed1c429b903b029bbd62621f11a9e286137minfrin return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0,
54d22ed1c429b903b029bbd62621f11a9e286137minfrin "DESIGN ERROR: dav_dbm_get_statefiles() "
54d22ed1c429b903b029bbd62621f11a9e286137minfrin "returned inconsistent results.");
54d22ed1c429b903b029bbd62621f11a9e286137minfrin /* ### CRAP. inconsistency. */
54d22ed1c429b903b029bbd62621f11a9e286137minfrin /* ### should perform some cleanup at the target if we still
54d22ed1c429b903b029bbd62621f11a9e286137minfrin ### have the original files */
54d22ed1c429b903b029bbd62621f11a9e286137minfrin /* Change the error to reflect the bad server state. */
edc346c3223efd41e6a2057c37cea69744b73dccwrowe "Could not fully copy/move the properties. "
54d22ed1c429b903b029bbd62621f11a9e286137minfrin "The server is now in an inconsistent state.";
54d22ed1c429b903b029bbd62621f11a9e286137minfrinstatic dav_error *dav_fs_deleteset(apr_pool_t *p, const dav_resource *resource)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes const char *dirpath;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes const char *fname;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes const char *state1;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes const char *state2;
e8f95a682820a599fe41b22977010636be5c2717jim /* Get directory, filename, and state-file names for the resource */
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe /* ### should test this result value... */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes (void) dav_fs_dir_file_name(resource, &dirpath, &fname);
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe /* build the propset pathname for the file */
e8f95a682820a599fe41b22977010636be5c2717jim /* note: we may get ENOENT if the state dir is not present */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if ((status = apr_file_remove(pathname, p)) != APR_SUCCESS
9ad7b260be233be7d7b5576979825cac72e15498rederpj return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0,
9ad7b260be233be7d7b5576979825cac72e15498rederpj "Could not remove properties.");
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* build the propset pathname for the file */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if ((status = apr_file_remove(pathname, p)) != APR_SUCCESS
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* ### CRAP. only removed half. */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "Could not fully remove properties. "
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "The server is now in an inconsistent "
e8f95a682820a599fe41b22977010636be5c2717jim/* --------------------------------------------------------------------
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes** REPOSITORY HOOK FUNCTIONS
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes const char *label,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* ### optimize this into a single allocation! */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* Create private resource context descriptor */
560fd0658902ab57754616c172d8953e69fc4722bnicholes /* ### this should go away */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* Preserve case on OSes which fold canonical filenames */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* ### not available in Apache 2.0 yet */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ** If there is anything in the path_info, then this indicates that the
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ** entire path was not used to specify the file/dir. We want to append
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ** it onto the filename so that we get a "valid" pathname for null
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ** resources.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes s = apr_pstrcat(r->pool, filename, r->path_info, NULL);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* make sure the pathname does not have a trailing "/" */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* Create resource descriptor */
ebe5305f8b22507374358f32b74d12fb50c05a25covener /* make sure the URI does not have a trailing "/" */
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener resource->collection = r->finfo.filetype == APR_DIR;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* unused info in the URL will indicate a null resource */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (r->path_info != NULL && *r->path_info != '\0') {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* only a trailing "/" is allowed */
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener if (*r->path_info != '/' || r->path_info[1] != '\0') {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ** This URL/filename represents a locknull resource or
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ** possibly a destination of a MOVE/COPY
560fd0658902ab57754616c172d8953e69fc4722bnicholes ** The base of the path refers to a file -- nothing should
54d22ed1c429b903b029bbd62621f11a9e286137minfrin ** be in path_info. The resource is simply an error: it
54d22ed1c429b903b029bbd62621f11a9e286137minfrin ** can't be a null or a locknull resource.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return dav_new_error(r->pool, HTTP_BAD_REQUEST, 0,
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener "The URL contains extraneous path "
4e9c24785b525d2956e6e381015c0f2bd0a72f4bcovener "components. The resource could not "
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "be identified.");
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* retain proper integrity across the structures */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic dav_error * dav_fs_get_parent_resource(const dav_resource *resource,
e8f95a682820a599fe41b22977010636be5c2717jim /* If we're at the root of the URL space, then there is no parent. */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* If given resource is root, then there is no parent.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * Unless we can retrieve the filepath root, this is
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * intendend to fail. If we split the root and
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * no path info remains, then we also fail.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes rv = apr_filepath_root(&testroot, &testpath, 0, ctx->pool);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* ### optimize this into a single allocation! */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* Create private resource context descriptor */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes parent_ctx = apr_pcalloc(ctx->pool, sizeof(*parent_ctx));
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* ### this should go away */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes dirpath = ap_make_dirstr_parent(ctx->pool, ctx->pathname);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (strlen(dirpath) > 1 && dirpath[strlen(dirpath) - 1] == '/')
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes parent_resource = apr_pcalloc(ctx->pool, sizeof(*parent_resource));
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes parent_resource->hooks = &dav_hooks_repository_fs;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes char *uri = ap_make_dirstr_parent(ctx->pool, resource->uri);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (strlen(uri) > 1 && uri[strlen(uri) - 1] == '/')
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes rv = apr_stat(&parent_ctx->finfo, parent_ctx->pathname,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if ((ctx1->finfo.filetype != 0) && (ctx2->finfo.filetype != 0)
f43b67c5a9d29b572eac916f8335cedc80c908bebnicholes && (ctx1->finfo.valid & ctx2->finfo.valid & APR_FINFO_INODE)) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return strcmp(ctx1->pathname, ctx2->pathname) == 0;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* it is safe to use ctx2 now */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes && memcmp(ctx1->pathname, ctx2->pathname, len1) == 0
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic dav_error * dav_fs_open_stream(const dav_resource *resource,
e8f95a682820a599fe41b22977010636be5c2717jim switch (mode) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes flags = APR_WRITE | APR_CREATE | APR_TRUNCATE | APR_BINARY;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes rv = apr_file_open(&ds->f, ds->pathname, flags, APR_OS_DEFAULT, ds->p);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "An error occurred while opening a resource.");
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem /* (APR registers cleanups for the fd with the pool) */
8113dac419143273351446c3ad653f3fe5ba5cfdwrowestatic dav_error * dav_fs_close_stream(dav_stream *stream, int commit)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (apr_file_remove(stream->pathname, stream->p) != APR_SUCCESS) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* ### use a better description? */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return dav_new_error(stream->p, HTTP_INTERNAL_SERVER_ERROR, 0,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "There was a problem removing (rolling "
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "back) the resource "
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "when it was being closed.");
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic dav_error * dav_fs_write_stream(dav_stream *stream,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes status = apr_file_write_full(stream->f, buf, bufsize, NULL);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return dav_new_error(stream->p, HTTP_INSUFFICIENT_STORAGE, 0,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "There is not enough storage to write to "
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "this resource.");
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* ### use something besides 500? */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return dav_new_error(stream->p, HTTP_INTERNAL_SERVER_ERROR, 0,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "An error occurred while writing to a "
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "resource.");
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowestatic dav_error * dav_fs_seek_stream(dav_stream *stream, apr_off_t abs_pos)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (apr_file_seek(stream->f, APR_SET, &abs_pos) != APR_SUCCESS) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* ### should check whether apr_file_seek set abs_pos was set to the
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes * correct position? */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* ### use something besides 500? */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return dav_new_error(stream->p, HTTP_INTERNAL_SERVER_ERROR, 0,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "Could not seek to specified position in the "
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "resource.");
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes/* only define set_headers() and deliver() for debug purposes */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic dav_error * dav_fs_set_headers(request_rec *r,
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj /* ### this function isn't really used since we have a get_pathname */
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj /* make sure the proper mtime is in the request record */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* ### note that these use r->filename rather than <resource> */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* we accept byte-ranges */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_table_setn(r->headers_out, "Accept-Ranges", "bytes");
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* set up the Content-Length header */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ap_set_content_length(r, resource->info->finfo.size);
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj /* ### how to set the content type? */
f43b67c5a9d29b572eac916f8335cedc80c908bebnicholes /* ### until this is resolved, the Content-Type header is busted */
37af4b0cf648275b68ff41c866c665b4ccf4667dcovenerstatic dav_error * dav_fs_deliver(const dav_resource *resource,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* Check resource type */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "Cannot GET this type of resource.");
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "There is no default response to GET for a "
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "collection.");
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if ((status = apr_file_open(&fd, resource->info->pathname,
e8f95a682820a599fe41b22977010636be5c2717jim "File permissions deny server access.");
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe apr_brigade_insert_file(bb, fd, 0, resource->info->finfo.size, pool);
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj bkt = apr_bucket_eos_create(output->c->bucket_alloc);
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem if ((status = ap_pass_brigade(output, bb)) != APR_SUCCESS) {
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem "Could not write contents to filter.");
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes#endif /* DEBUG_GET_HANDLER */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic dav_error * dav_fs_create_collection(dav_resource *resource)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes status = apr_dir_make(ctx->pathname, APR_OS_DEFAULT, ctx->pool);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return dav_new_error(ctx->pool, HTTP_INSUFFICIENT_STORAGE, 0,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "There is not enough storage to create "
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "this collection.");
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "Cannot create collection; intermediate "
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "collection does not exist.");
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* ### refine this error message? */
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem "Unable to create collection.");
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem /* update resource state to show it exists as a collection */
8869662bb1a4078297020e94ae5e928626d877c6rederpjstatic dav_error * dav_fs_copymove_walker(dav_walk_resource *wres,
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem dav_resource_private *srcinfo = wres->resource->info;
8869662bb1a4078297020e94ae5e928626d877c6rederpj /* Postfix call for MOVE. delete the source dir.
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem * Note: when copying, we do not enable the postfix-traversal.
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem /* ### we are ignoring any error here; what should we do? */
8869662bb1a4078297020e94ae5e928626d877c6rederpj (void) apr_dir_remove(srcinfo->pathname, ctx->pool);
8869662bb1a4078297020e94ae5e928626d877c6rederpj /* copy/move of a collection. Create the new, target collection */
8869662bb1a4078297020e94ae5e928626d877c6rederpj /* ### assume it was a permissions problem */
8869662bb1a4078297020e94ae5e928626d877c6rederpj /* ### need a description here */
8869662bb1a4078297020e94ae5e928626d877c6rederpj err = dav_new_error(ctx->pool, HTTP_FORBIDDEN, 0, NULL);
8869662bb1a4078297020e94ae5e928626d877c6rederpj /* ### push a higher-level description? */
8869662bb1a4078297020e94ae5e928626d877c6rederpj ** If we have a "not so bad" error, then it might need to go into a
8869662bb1a4078297020e94ae5e928626d877c6rederpj ** multistatus response.
8869662bb1a4078297020e94ae5e928626d877c6rederpj ** For a MOVE, it will always go into the multistatus. It could be
8869662bb1a4078297020e94ae5e928626d877c6rederpj ** that everything has been moved *except* for the root. Using a
8869662bb1a4078297020e94ae5e928626d877c6rederpj ** multistatus (with no errors for the other resources) will signify
8869662bb1a4078297020e94ae5e928626d877c6rederpj ** this condition.
8869662bb1a4078297020e94ae5e928626d877c6rederpj ** For a COPY, we are traversing in a prefix fashion. If the root fails,
8869662bb1a4078297020e94ae5e928626d877c6rederpj ** then we can just bail out now.
8869662bb1a4078297020e94ae5e928626d877c6rederpj || !dav_fs_is_same_resource(wres->resource, ctx->root))) {
8869662bb1a4078297020e94ae5e928626d877c6rederpj /* ### use errno to generate DAV:responsedescription? */
8869662bb1a4078297020e94ae5e928626d877c6rederpj /* the error is in the multistatus now. do not stop the traversal. */
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem /* if a collection, recursively copy/move it and its children,
8869662bb1a4078297020e94ae5e928626d877c6rederpj * including the state dirs
8869662bb1a4078297020e94ae5e928626d877c6rederpj params.walk_type = DAV_WALKTYPE_NORMAL | DAV_WALKTYPE_HIDDEN;
8869662bb1a4078297020e94ae5e928626d877c6rederpj /* params.walk_ctx is managed by dav_fs_internal_walk() */
8869662bb1a4078297020e94ae5e928626d877c6rederpj /* postfix is needed for MOVE to delete source dirs */
8869662bb1a4078297020e94ae5e928626d877c6rederpj /* note that we return the error OR the multistatus. never both */
8869662bb1a4078297020e94ae5e928626d877c6rederpj if ((err = dav_fs_internal_walk(¶ms, depth, is_move, dst,
8869662bb1a4078297020e94ae5e928626d877c6rederpj /* on a "real" error, then just punt. nothing else to do. */
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem /* some multistatus responses exist. wrap them in a 207 */
8869662bb1a4078297020e94ae5e928626d877c6rederpj return dav_new_error(src->info->pool, HTTP_MULTI_STATUS, 0,
8869662bb1a4078297020e94ae5e928626d877c6rederpj "Error(s) occurred on some resources during "
8869662bb1a4078297020e94ae5e928626d877c6rederpj "the COPY/MOVE process.");
8869662bb1a4078297020e94ae5e928626d877c6rederpj /* not a collection */
8869662bb1a4078297020e94ae5e928626d877c6rederpj if ((err = dav_fs_copymove_file(is_move, src->info->pool,
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem /* ### push a higher-level description? */
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj /* copy/move properties as well */
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem return dav_fs_copymoveset(is_move, src->info->pool, src, dst, &work_buf);
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem ** ### strictly speaking, this is a design error; we should not
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem ** ### have reached this point.
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem return dav_new_error(src->info->pool, HTTP_INTERNAL_SERVER_ERROR, 0,
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem "DESIGN ERROR: a mix of repositories "
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem "was passed to copy_resource.");
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem if ((err = dav_fs_copymove_resource(0, src, dst, depth,
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem /* update state of destination resource to show it exists */
a9c4332dc6241dc11dd104826bd179d42ccc0f12fuankg ** ### strictly speaking, this is a design error; we should not
a9c4332dc6241dc11dd104826bd179d42ccc0f12fuankg ** ### have reached this point.
11ca38a20ab9b2d00258f745620e2724838e7e21rederpj return dav_new_error(src->info->pool, HTTP_INTERNAL_SERVER_ERROR, 0,
11ca38a20ab9b2d00258f745620e2724838e7e21rederpj "DESIGN ERROR: a mix of repositories "
11ca38a20ab9b2d00258f745620e2724838e7e21rederpj "was passed to move_resource.");
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem /* determine whether a simple rename will work.
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem * Assume source exists, else we wouldn't get called.
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem if (dstinfo->finfo.device == srcinfo->finfo.device) {
11ca38a20ab9b2d00258f745620e2724838e7e21rederpj /* target exists and is on the same device. */
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem const char *dirpath;
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem /* destination does not exist, but the parent directory should,
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem * so try it
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem dirpath = ap_make_dirstr_parent(dstinfo->pool, dstinfo->pathname);
85da6b76d07b7af570cbbec208a87697ba9c44f5rederpj * XXX: If missing dev ... then what test?
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj * Really need a try and failover for those platforms.
85da6b76d07b7af570cbbec208a87697ba9c44f5rederpj rv = apr_stat(&finfo, dirpath, APR_FINFO_DEV, dstinfo->pool);
85da6b76d07b7af570cbbec208a87697ba9c44f5rederpj && (finfo.valid & srcinfo->finfo.valid & APR_FINFO_DEV)
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem /* if we can't simply rename, then do it the hard way... */
85da6b76d07b7af570cbbec208a87697ba9c44f5rederpj if ((err = dav_fs_copymove_resource(1, src, dst, DAV_INFINITY,
85da6b76d07b7af570cbbec208a87697ba9c44f5rederpj /* update resource states */
85da6b76d07b7af570cbbec208a87697ba9c44f5rederpj /* a rename should work. do it, and move properties as well */
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj /* no multistatus response */
85da6b76d07b7af570cbbec208a87697ba9c44f5rederpj /* ### APR has no rename? */
85da6b76d07b7af570cbbec208a87697ba9c44f5rederpj if (apr_file_rename(srcinfo->pathname, dstinfo->pathname,
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem /* ### should have a better error than this. */
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem return dav_new_error(srcinfo->pool, HTTP_INTERNAL_SERVER_ERROR, 0,
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem "Could not rename resource.");
0e05808dc59a321566303084c84b9826a4353cefrederpj /* update resource states */
0e05808dc59a321566303084c84b9826a4353cefrederpj /* no error. we're done. go ahead and return now. */
0e05808dc59a321566303084c84b9826a4353cefrederpj /* error occurred during properties move; try to put resource back */
0e05808dc59a321566303084c84b9826a4353cefrederpj if (apr_file_rename(dstinfo->pathname, srcinfo->pathname,
0e05808dc59a321566303084c84b9826a4353cefrederpj /* couldn't put it back! */
0e05808dc59a321566303084c84b9826a4353cefrederpj "The resource was moved, but a failure "
0e05808dc59a321566303084c84b9826a4353cefrederpj "occurred during the move of its "
0e05808dc59a321566303084c84b9826a4353cefrederpj "properties. The resource could not be "
0e05808dc59a321566303084c84b9826a4353cefrederpj "restored to its original location. The "
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj "server is now in an inconsistent state.",
85da6b76d07b7af570cbbec208a87697ba9c44f5rederpj /* update resource states again */
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem /* resource moved back, but properties may be inconsistent */
85da6b76d07b7af570cbbec208a87697ba9c44f5rederpj "The resource was moved, but a failure "
85da6b76d07b7af570cbbec208a87697ba9c44f5rederpj "occurred during the move of its properties. "
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem "The resource was moved back to its original "
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem "location, but its properties may have been "
85da6b76d07b7af570cbbec208a87697ba9c44f5rederpj "partially moved. The server may be in an "
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj "inconsistent state.",
8445dae5cc606ba8ba04efc341cc1e081d95920drpluemstatic dav_error * dav_fs_delete_walker(dav_walk_resource *wres, int calltype)
85da6b76d07b7af570cbbec208a87697ba9c44f5rederpj /* do not attempt to remove a null resource,
85da6b76d07b7af570cbbec208a87697ba9c44f5rederpj * or a collection with children
85da6b76d07b7af570cbbec208a87697ba9c44f5rederpj (!wres->resource->collection || calltype == DAV_CALLTYPE_POSTFIX)) {
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj /* try to remove the resource */
0e05808dc59a321566303084c84b9826a4353cefrederpj ** If an error occurred, then add it to multistatus response.
0e05808dc59a321566303084c84b9826a4353cefrederpj ** Note that we add it for the root resource, too. It is quite
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem ** possible to delete the whole darn tree, yet fail on the root.
0e05808dc59a321566303084c84b9826a4353cefrederpj ** (also: remember we are deleting via a postfix traversal)
0e05808dc59a321566303084c84b9826a4353cefrederpj /* ### assume there is a permissions problem */
0e05808dc59a321566303084c84b9826a4353cefrederpj /* ### use errno to generate DAV:responsedescription? */
85da6b76d07b7af570cbbec208a87697ba9c44f5rederpjstatic dav_error * dav_fs_remove_resource(dav_resource *resource,
0e05808dc59a321566303084c84b9826a4353cefrederpj /* if a collection, recursively remove it and its children,
0e05808dc59a321566303084c84b9826a4353cefrederpj * including the state dirs
0e05808dc59a321566303084c84b9826a4353cefrederpj /* on a "real" error, then just punt. nothing else to do. */
0e05808dc59a321566303084c84b9826a4353cefrederpj /* some multistatus responses exist. wrap them in a 207 */
0e05808dc59a321566303084c84b9826a4353cefrederpj return dav_new_error(info->pool, HTTP_MULTI_STATUS, 0,
0e05808dc59a321566303084c84b9826a4353cefrederpj "Error(s) occurred on some resources during "
0e05808dc59a321566303084c84b9826a4353cefrederpj "the deletion process.");
0e05808dc59a321566303084c84b9826a4353cefrederpj /* no errors... update resource state */
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem /* not a collection; remove the file and its properties */
85da6b76d07b7af570cbbec208a87697ba9c44f5rederpj if (apr_file_remove(info->pathname, info->pool) != APR_SUCCESS) {
85da6b76d07b7af570cbbec208a87697ba9c44f5rederpj /* ### put a description in here */
85da6b76d07b7af570cbbec208a87697ba9c44f5rederpj return dav_new_error(info->pool, HTTP_FORBIDDEN, 0, NULL);
85da6b76d07b7af570cbbec208a87697ba9c44f5rederpj /* update resource state */
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem /* remove properties and return its result */
85da6b76d07b7af570cbbec208a87697ba9c44f5rederpj/* ### move this to dav_util? */
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem/* Walk recursively down through directories, *
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem * including lock-null resources as we go. */
8445dae5cc606ba8ba04efc341cc1e081d95920drpluemstatic dav_error * dav_fs_walker(dav_fs_walker_context *fsctx, int depth)
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem /* ensure the context is prepared properly, then call the func */
85da6b76d07b7af570cbbec208a87697ba9c44f5rederpj /* put a trailing slash onto the directory, in preparation for appending
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj * files to it as we discovery them within the directory */
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj dav_check_bufsize(pool, &fsctx->path1, DAV_BUFFER_PAD);
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj fsctx->path1.buf[fsctx->path1.cur_len] = '\0'; /* in pad area */
3f5585f7f4a7d74f2f94ec729ea8c1879d419e35rederpj /* if a secondary path is present, then do that, too */
e8f95a682820a599fe41b22977010636be5c2717jim fsctx->path2.buf[fsctx->path2.cur_len] = '\0'; /* in pad area */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* Note: the URI should ALREADY have a trailing "/" */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* for this first pass of files, all resources exist */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* a file is the default; we'll adjust if we hit a directory */
f05787953018140838ad51456c86c965d6a86267jim /* open and scan the directory */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if ((apr_dir_open(&dirp, fsctx->path1.buf, pool)) != APR_SUCCESS) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* ### need a better error */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return dav_new_error(pool, HTTP_NOT_FOUND, 0, NULL);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes while ((apr_dir_read(&dirent, APR_FINFO_DIRENT, dirp)) == APR_SUCCESS) {
e8f95a682820a599fe41b22977010636be5c2717jim /* avoid recursing into our current, parent, or state directories */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes && (len == 1 || (dirent.name[1] == '.' && len == 2))) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* ### need to authorize each file */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* ### example: .htaccess is normally configured to fail auth */
e8f95a682820a599fe41b22977010636be5c2717jim /* stuff in the state directory is never authorized! */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* skip the state dir unless a HIDDEN is performed */
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe /* append this file onto the path buffer (copy null term) */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes dav_buffer_place_mem(pool, &fsctx->path1, dirent.name, len + 1, 0);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* ### Optimize me, dirent can give us what we need! */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes status = apr_stat(&fsctx->info1.finfo, fsctx->path1.buf,
e8f95a682820a599fe41b22977010636be5c2717jim if (status != APR_SUCCESS && status != APR_INCOMPLETE) {
e8f95a682820a599fe41b22977010636be5c2717jim /* woah! where'd it go? */
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe /* ### should have a better error here */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes err = dav_new_error(pool, HTTP_NOT_FOUND, 0, NULL);
d64dd2fd4516c2b1b664c5e59c0628d9aff26984covener /* copy the file to the URI, too. NOTE: we will pad an extra byte
d64dd2fd4516c2b1b664c5e59c0628d9aff26984covener for the trailing slash later. */
d64dd2fd4516c2b1b664c5e59c0628d9aff26984covener dav_buffer_place_mem(pool, &fsctx->uri_buf, dirent.name, len + 1, 1);
c4f16f709c79bb7e2ddffb532bc7708eab9a9691covener /* if there is a secondary path, then do that, too */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes dav_buffer_place_mem(pool, &fsctx->path2, dirent.name, len + 1, 0);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* set up the (internal) pathnames for the two resources */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* set up the URI for the current resource */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* ### for now, only process regular files (e.g. skip symlinks) */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* call the function for the specified dir + file */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* ### maybe add a higher-level description? */
f43b67c5a9d29b572eac916f8335cedc80c908bebnicholes else if (fsctx->info1.finfo.filetype == APR_DIR) {
37af4b0cf648275b68ff41c866c665b4ccf4667dcovener /* adjust length to incorporate the subdir name */
37af4b0cf648275b68ff41c866c665b4ccf4667dcovener /* adjust URI length to incorporate subdir and a slash */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes fsctx->uri_buf.buf[fsctx->uri_buf.cur_len - 1] = '/';
f43b67c5a9d29b572eac916f8335cedc80c908bebnicholes fsctx->uri_buf.buf[fsctx->uri_buf.cur_len] = '\0';
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* switch over to a collection */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* recurse on the subdir */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* ### don't always want to quit on error from single child */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if ((err = dav_fs_walker(fsctx, depth - 1)) != NULL) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* ### maybe add a higher-level description? */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* put the various information back */
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe /* assert: res1.exists == 1 */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* ### check the return value of this? */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* null terminate the directory name */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes fsctx->path1.buf[fsctx->path1.cur_len - 1] = '\0';
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* Include any lock null resources found in this collection */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if ((err = dav_fs_get_locknull_members(&fsctx->res1,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* ### maybe add a higher-level description? */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* put a slash back on the end of the directory */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* these are all non-existant (files) */
37af4b0cf648275b68ff41c866c665b4ccf4667dcovener memset(&fsctx->info1.finfo, 0, sizeof(fsctx->info1.finfo));
37af4b0cf648275b68ff41c866c665b4ccf4667dcovener apr_size_t len = strlen(fsctx->locknull_buf.buf + offset);
f43b67c5a9d29b572eac916f8335cedc80c908bebnicholes ** Append the locknull file to the paths and the URI. Note that
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ** we don't have to pad the URI for a slash since a locknull
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ** resource is not a collection.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* set up the (internal) pathnames for the two resources */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* set up the URI for the current resource */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ** To prevent a PROPFIND showing an expired locknull
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ** resource, query the lock database to force removal
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ** of both the lock entry and .locknull, if necessary..
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ** Sure, the query in PROPFIND would do this.. after
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ** the locknull resource was already included in the
8bdea88407c848c1c2693655e2f8b23abde12307bnicholes ** NOTE: we assume the caller has opened the lock database
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ** if they have provided DAV_WALKTYPE_LOCKNULL.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* ### we should also look into opening it read-only and
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ### eliding timed-out items from the walk, yet leaving
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ### them in the locknull database until somebody opens
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ### the thing writable.
e8f95a682820a599fe41b22977010636be5c2717jim /* ### probably ought to use has_locks. note the problem
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe ### mentioned above, though... we would traverse this as
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ### a locknull, but then a PROPFIND would load the lock
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ### info, causing a timeout and the locks would not be
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ### reported. Therefore, a null resource would be returned
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ### in the PROPFIND.
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ### alternative: just load unresolved locks. any direct
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ### locks will be timed out (correct). any indirect will
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ### not (correct; consider if a parent timed out -- the
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ### timeout routines do not walk and remove indirects;
e8f95a682820a599fe41b22977010636be5c2717jim ### even the resolve func would probably fail when it
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes ### tried to find a timed-out direct lock).
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if ((err = dav_lock_query(params->lockdb, &fsctx->res1,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* ### maybe add a higher-level description? */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* call the function for the specified dir + file */
e8f95a682820a599fe41b22977010636be5c2717jim /* ### maybe add a higher-level description? */
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes /* reset the exists flag */
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes /* replace the dirs' trailing slashes with null terms */
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes fsctx->uri_buf.buf[--fsctx->uri_buf.cur_len] = '\0';
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes /* this is a collection which exists */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes return (*params->func)(&fsctx->wres, DAV_CALLTYPE_POSTFIX);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic dav_error * dav_fs_internal_walk(const dav_walk_params *params,
8113dac419143273351446c3ad653f3fe5ba5cfdwrowe return dav_new_error(params->pool, HTTP_INTERNAL_SERVER_ERROR, 0,
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes "DESIGN ERROR: walker called to walk locknull "
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes "resources, but a lockdb was not provided.");
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes /* ### zero out versioned, working, baselined? */
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes /* the pathname is stored in the path1 buffer */
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes dav_buffer_init(params->pool, &fsctx.path1, fsctx.info1.pathname);
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe /* internal call from the COPY/MOVE code. set it up. */
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes /* res2 does not exist -- clear its finfo structure */
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes memset(&fsctx.info2.finfo, 0, sizeof(fsctx.info2.finfo));
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes /* the pathname is stored in the path2 buffer */
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes dav_buffer_init(params->pool, &fsctx.path2, fsctx.info2.pathname);
c4f16f709c79bb7e2ddffb532bc7708eab9a9691covener /* prep the URI buffer */
c4f16f709c79bb7e2ddffb532bc7708eab9a9691covener dav_buffer_init(params->pool, &fsctx.uri_buf, params->root->uri);
d64dd2fd4516c2b1b664c5e59c0628d9aff26984covener /* if we have a directory, then ensure the URI has a trailing "/" */
d64dd2fd4516c2b1b664c5e59c0628d9aff26984covener && fsctx.uri_buf.buf[fsctx.uri_buf.cur_len - 1] != '/') {
c4f16f709c79bb7e2ddffb532bc7708eab9a9691covener /* this will fall into the pad area */
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes /* the current resource's URI is stored in the uri_buf buffer */
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes /* point the callback's resource at our structure */
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes /* always return the error, and any/all multistatus responses */
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholesstatic dav_error * dav_fs_walk(const dav_walk_params *params, int depth,
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes /* always return the error, and any/all multistatus responses */
f43b67c5a9d29b572eac916f8335cedc80c908bebnicholes return dav_fs_internal_walk(params, depth, 0, NULL, response);
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes/* dav_fs_etag: Stolen from ap_make_etag. Creates a strong etag
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes * for file path.
37af4b0cf648275b68ff41c866c665b4ccf4667dcovener * ### do we need to return weak tags sometimes?
37af4b0cf648275b68ff41c866c665b4ccf4667dcovenerstatic const char *dav_fs_getetag(const dav_resource *resource)
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes return apr_psprintf(ctx->pool, "\"%lx\"", (unsigned long) ctx->finfo.mtime);
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholesstatic const dav_hooks_repository dav_hooks_repository_fs =
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes DEBUG_GET_HANDLER, /* normally: special GET handling not required */
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholesstatic dav_prop_insert dav_fs_insert_prop(const dav_resource *resource,
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes const char *value;
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes const char *s;
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes /* an HTTP-date can be 29 chars plus a null term */
e8f95a682820a599fe41b22977010636be5c2717jim /* a 64-bit size can be 20 chars plus a null term */
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes ** None of FS provider properties are defined if the resource does not
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes ** exist. Just bail for this case.
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes ** Even though we state that the FS properties are not defined, the
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes ** client cannot store dead values -- we deny that thru the is_writable
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes ** hook function.
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes ** Closest thing to a creation date. since we don't actually
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes ** perform the operations that would modify ctime (after we
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes ** create the file), then we should be pretty safe here.
482f676c6c19b1c5bb5cca04dad11509c1da3a4cwrowe /* our property, but not defined on collection resources */
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes (void) sprintf(buf, "%" APR_OFF_T_FMT, resource->info->finfo.size);
03f4448f864e31ade79856ac8c264a5e6dce3b10bnicholes /* our property, but not defined on collection resources */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* our property, but not defined on this platform */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (!(resource->info->finfo.valid & APR_FINFO_UPROT))
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* the files are "ours" so we only need to check owner exec privs */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (resource->info->finfo.protection & APR_UEXECUTE)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* ### what the heck was this property? */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* assert: value != NULL */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* get the information and global NS index for the property */
e8f95a682820a599fe41b22977010636be5c2717jim global_ns = dav_get_liveprop_info(propid, &dav_fs_liveprop_group, &info);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* assert: info != NULL && info->name != NULL */
e8f95a682820a599fe41b22977010636be5c2717jim /* DBG3("FS: inserting lp%d:%s (local %d)", ns, scan->name, scan->ns); */
3effb85eb3124c6f02cd89e22ffed0fc9afaddb9bnicholes s = apr_psprintf(p, "<lp%d:%s>%s</lp%d:%s>" DEBUG_CR,
3effb85eb3124c6f02cd89e22ffed0fc9afaddb9bnicholes global_ns, info->name, value, global_ns, info->name);
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes s = apr_psprintf(p, "<lp%d:%s/>" DEBUG_CR, global_ns, info->name);
e8f95a682820a599fe41b22977010636be5c2717jim /* assert: what == DAV_PROP_INSERT_SUPPORTED */
e8f95a682820a599fe41b22977010636be5c2717jim "<D:supported-live-property D:name=\"%s\" "
e8f95a682820a599fe41b22977010636be5c2717jim /* we inserted what was asked for */
e8f95a682820a599fe41b22977010636be5c2717jimstatic int dav_fs_is_writable(const dav_resource *resource, int propid)
3effb85eb3124c6f02cd89e22ffed0fc9afaddb9bnicholes /* if we have the executable property, and this isn't a collection,
3effb85eb3124c6f02cd89e22ffed0fc9afaddb9bnicholes then the property is writable. */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (propid == DAV_PROPID_FS_executable && !resource->collection)
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes (void) dav_get_liveprop_info(propid, &dav_fs_liveprop_group, &info);
e8f95a682820a599fe41b22977010636be5c2717jimstatic dav_error *dav_fs_patch_validate(const dav_resource *resource,
3effb85eb3124c6f02cd89e22ffed0fc9afaddb9bnicholes return dav_new_error(resource->info->pool, HTTP_CONFLICT, 0,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "The 'executable' property cannot be removed.");
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem /* ### hmm. this isn't actually looking at all the possible text items */
e8f95a682820a599fe41b22977010636be5c2717jim /* DBG3("name=%s cdata=%s f_cdata=%s",elem->name,cdata ? cdata->text : "[null]",f_cdata ? f_cdata->text : "[null]"); */
e8f95a682820a599fe41b22977010636be5c2717jim return dav_new_error(resource->info->pool, HTTP_CONFLICT, 0,
43c3e6a4b559b76b750c245ee95e2782c15b4296jim "The 'executable' property expects a single "
3effb85eb3124c6f02cd89e22ffed0fc9afaddb9bnicholes "character, valued 'T' or 'F'. There was no "
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "value submitted.");
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (cdata->next != NULL || strlen(cdata->text) != 1)
8445dae5cc606ba8ba04efc341cc1e081d95920drpluem return dav_new_error(resource->info->pool, HTTP_CONFLICT, 0,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "The 'executable' property expects a single "
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "character, valued 'T' or 'F'. The value "
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "submitted is invalid.");
3effb85eb3124c6f02cd89e22ffed0fc9afaddb9bnicholes return dav_new_error(resource->info->pool, HTTP_CONFLICT, 0,
3effb85eb3124c6f02cd89e22ffed0fc9afaddb9bnicholes "The 'executable' property expects a single "
3effb85eb3124c6f02cd89e22ffed0fc9afaddb9bnicholes "character, valued 'T' or 'F'. The value submitted "
3effb85eb3124c6f02cd89e22ffed0fc9afaddb9bnicholes "has too many characters.");
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholesstatic dav_error *dav_fs_patch_exec(const dav_resource *resource,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes apr_fileperms_t perms = resource->info->finfo.protection;
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* assert: prop == executable. operation == SET. */
e8f95a682820a599fe41b22977010636be5c2717jim /* don't do anything if there is no change. no rollback info either. */
43c3e6a4b559b76b750c245ee95e2782c15b4296jim /* DBG2("new value=%d (old=%d)", value, old_value); */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes if (apr_file_perms_set(resource->info->pathname, perms) != APR_SUCCESS) {
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes "Could not set the executable flag of the "
e8f95a682820a599fe41b22977010636be5c2717jim "target resource.");
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* update the resource and set up the rollback context */
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes *rollback_ctx = (dav_liveprop_rollback *)old_value;
54d22ed1c429b903b029bbd62621f11a9e286137minfrinstatic void dav_fs_patch_commit(const dav_resource *resource,
54d22ed1c429b903b029bbd62621f11a9e286137minfrin /* nothing to do */
88adce5ec0da39b41450ce1d5a77659168097e0cjortonstatic dav_error *dav_fs_patch_rollback(const dav_resource *resource,
54d22ed1c429b903b029bbd62621f11a9e286137minfrin apr_fileperms_t perms = resource->info->finfo.protection & ~APR_UEXECUTE;
54d22ed1c429b903b029bbd62621f11a9e286137minfrin /* assert: prop == executable. operation == SET. */
54d22ed1c429b903b029bbd62621f11a9e286137minfrin /* restore the executable bit */
54d22ed1c429b903b029bbd62621f11a9e286137minfrin if (apr_file_perms_set(resource->info->pathname, perms) != APR_SUCCESS) {
54d22ed1c429b903b029bbd62621f11a9e286137minfrin "After a failure occurred, the resource's "
54d22ed1c429b903b029bbd62621f11a9e286137minfrin "executable flag could not be restored.");
54d22ed1c429b903b029bbd62621f11a9e286137minfrin /* restore the resource's state */
54d22ed1c429b903b029bbd62621f11a9e286137minfrinstatic const dav_hooks_liveprop dav_hooks_liveprop_fs =
54d22ed1c429b903b029bbd62621f11a9e286137minfrinvoid dav_fs_gather_propsets(apr_array_header_t *uris)
09338db7fdcf82ecc189195347da3a3ed5d0287abnicholesint dav_fs_find_liveprop(const dav_resource *resource,
54d22ed1c429b903b029bbd62621f11a9e286137minfrin /* don't try to find any liveprops if this isn't "our" resource */
54d22ed1c429b903b029bbd62621f11a9e286137minfrin return dav_do_find_liveprop(ns_uri, name, &dav_fs_liveprop_group, hooks);
54d22ed1c429b903b029bbd62621f11a9e286137minfrinvoid dav_fs_insert_all_liveprops(request_rec *r, const dav_resource *resource,
54d22ed1c429b903b029bbd62621f11a9e286137minfrin /* don't insert any liveprops if this isn't "our" resource */
54d22ed1c429b903b029bbd62621f11a9e286137minfrin /* a lock-null resource */
e8f95a682820a599fe41b22977010636be5c2717jim ** ### technically, we should insert empty properties. dunno offhand
e8f95a682820a599fe41b22977010636be5c2717jim ** ### what part of the spec said this, but it was essentially thus:
e8f95a682820a599fe41b22977010636be5c2717jim ** ### "the properties should be defined, but may have no value".
54d22ed1c429b903b029bbd62621f11a9e286137minfrin (void) dav_fs_insert_prop(resource, DAV_PROPID_creationdate,
5aa455d45abacfa675c88d4ff53fbe97c44ce545bnicholes (void) dav_fs_insert_prop(resource, DAV_PROPID_getcontentlength,
54d22ed1c429b903b029bbd62621f11a9e286137minfrin (void) dav_fs_insert_prop(resource, DAV_PROPID_getlastmodified,
5aa455d45abacfa675c88d4ff53fbe97c44ce545bnicholes (void) dav_fs_insert_prop(resource, DAV_PROPID_getetag,
d5b12fe8ae917e654a33247fd4e59dc9e75170aebnicholes /* Only insert this property if it is defined for this platform. */
54d22ed1c429b903b029bbd62621f11a9e286137minfrin (void) dav_fs_insert_prop(resource, DAV_PROPID_FS_executable,
54d22ed1c429b903b029bbd62621f11a9e286137minfrin /* ### we know the others aren't defined as liveprops */
54d22ed1c429b903b029bbd62621f11a9e286137minfrin /* register the namespace URIs */
54d22ed1c429b903b029bbd62621f11a9e286137minfrin dav_register_liveprop_group(p, &dav_fs_liveprop_group);
54d22ed1c429b903b029bbd62621f11a9e286137minfrin /* register the repository provider */
54d22ed1c429b903b029bbd62621f11a9e286137minfrin dav_register_provider(p, "filesystem", &dav_fs_provider);