From 540ceccf454d1419376cd788f4e8b2703e3315e8 Mon Sep 17 00:00:00 2001 From: Jeff Trawick Date: Thu, 19 Nov 2009 20:09:27 +0000 Subject: [PATCH] Remove errno from dav_error interface. Calls to dav_new_error() and dav_new_error_tag() must be adjusted to add an apr_status_t parameter. Reviewed by: jorton git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@882274 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 4 + include/ap_mmn.h | 1 + modules/dav/fs/dbm.c | 8 +- modules/dav/fs/lock.c | 39 +++++----- modules/dav/fs/repos.c | 144 +++++++++++++++++++---------------- modules/dav/lock/locks.c | 18 ++--- modules/dav/main/mod_dav.c | 51 ++++++------- modules/dav/main/mod_dav.h | 11 +-- modules/dav/main/props.c | 7 +- modules/dav/main/util.c | 75 +++++++++--------- modules/dav/main/util_lock.c | 14 ++-- 11 files changed, 192 insertions(+), 180 deletions(-) diff --git a/CHANGES b/CHANGES index a2fecb967d..da6296ad42 100644 --- a/CHANGES +++ b/CHANGES @@ -10,6 +10,10 @@ Changes with Apache 2.3.3 mod_proxy_ftp: NULL pointer dereference on error paths. [Stefan Fritsch , Joe Orton] + *) mod_dav: Remove errno from dav_error interface. Calls to dav_new_error() + and dav_new_error_tag() must be adjusted to add an apr_status_t parameter. + [Jeff Trawick] + *) mod_authnz_ldap: Add AuthLDAPBindAuthoritative to allow Authentication to try other providers in the case of an LDAP bind failure. PR 46608 [Justin Erenkrantz, Joe Schaefer, Tony Stevenson] diff --git a/include/ap_mmn.h b/include/ap_mmn.h index f98d28c52e..01c5a735b5 100644 --- a/include/ap_mmn.h +++ b/include/ap_mmn.h @@ -204,6 +204,7 @@ * proxy_dir_conf * 20091011.1 (2.3.3-dev) add debug_level to util_ldap_state_t * 20091031.0 (2.3.3-dev) remove public LDAP referral-related macros + * 20091119.0 (2.3.4-dev) dav_error interface uses apr_status_t parm, not errno * */ diff --git a/modules/dav/fs/dbm.c b/modules/dav/fs/dbm.c index aac5669e29..0fca875200 100644 --- a/modules/dav/fs/dbm.c +++ b/modules/dav/fs/dbm.c @@ -79,7 +79,6 @@ void dav_dbm_get_statefiles(apr_pool_t *p, const char *fname, static dav_error * dav_fs_dbm_error(dav_db *db, apr_pool_t *p, apr_status_t status) { - int save_errno = errno; int errcode; const char *errstr; dav_error *err; @@ -100,8 +99,7 @@ static dav_error * dav_fs_dbm_error(dav_db *db, apr_pool_t *p, errstr = apr_pstrdup(p, errbuf); } - err = dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, errcode, errstr); - err->save_errno = save_errno; + err = dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, errcode, status, errstr); return err; } @@ -419,7 +417,7 @@ static dav_error * dav_propdb_open(apr_pool_t *pool, /* call it a major version error */ return dav_new_error(pool, HTTP_INTERNAL_SERVER_ERROR, - DAV_ERR_PROP_BAD_MAJOR, + DAV_ERR_PROP_BAD_MAJOR, 0, "Prop database has the wrong major " "version number and cannot be used."); } @@ -441,7 +439,7 @@ static dav_error * dav_propdb_open(apr_pool_t *pool, dav_dbm_close(db); return dav_new_error(pool, HTTP_INTERNAL_SERVER_ERROR, - DAV_ERR_PROP_BAD_MAJOR, + DAV_ERR_PROP_BAD_MAJOR, 0, "Prop database has the wrong major " "version number and cannot be used."); } diff --git a/modules/dav/fs/lock.c b/modules/dav/fs/lock.c index 41dc5ed9e6..331d4e8314 100644 --- a/modules/dav/fs/lock.c +++ b/modules/dav/fs/lock.c @@ -248,7 +248,7 @@ static dav_error * dav_fs_parse_locktoken( if (ap_strstr_c(char_token, "opaquelocktoken:") != char_token) { return dav_new_error(p, - HTTP_BAD_REQUEST, DAV_ERR_LOCK_UNK_STATE_TOKEN, + HTTP_BAD_REQUEST, DAV_ERR_LOCK_UNK_STATE_TOKEN, 0, "The lock token uses an unknown State-token " "format and could not be parsed."); } @@ -256,7 +256,7 @@ static dav_error * dav_fs_parse_locktoken( locktoken = apr_pcalloc(p, sizeof(*locktoken)); if (apr_uuid_parse(&locktoken->uuid, char_token)) { - return dav_new_error(p, HTTP_BAD_REQUEST, DAV_ERR_LOCK_PARSE_TOKEN, + return dav_new_error(p, HTTP_BAD_REQUEST, DAV_ERR_LOCK_PARSE_TOKEN, 0, "The opaquelocktoken has an incorrect format " "and could not be parsed."); } @@ -345,7 +345,7 @@ static dav_error * dav_fs_open_lockdb(request_rec *r, int ro, int force, comb->priv.lockdb_path = dav_get_lockdb_path(r); if (comb->priv.lockdb_path == NULL) { return dav_new_error(r->pool, HTTP_INTERNAL_SERVER_ERROR, - DAV_ERR_LOCK_NO_DB, + DAV_ERR_LOCK_NO_DB, 0, "A lock database was not specified with the " "DAVLockDB directive. One must be specified " "to use the locking functionality."); @@ -424,7 +424,7 @@ static dav_error * dav_fs_save_lock_record(dav_lockdb *lockdb, apr_datum_t key, #if DAV_DEBUG if (lockdb->ro) { return dav_new_error(lockdb->info->pool, - HTTP_INTERNAL_SERVER_ERROR, 0, + HTTP_INTERNAL_SERVER_ERROR, 0, 0, "INTERNAL DESIGN ERROR: the lockdb was opened " "readonly, but an attempt to save locks was " "performed."); @@ -637,7 +637,7 @@ static dav_error * dav_fs_load_lock_record(dav_lockdb *lockdb, apr_datum_t key, --offset; return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, - DAV_ERR_LOCK_CORRUPT_DB, + DAV_ERR_LOCK_CORRUPT_DB, 0, apr_psprintf(p, "The lock database was found to " "be corrupt. offset %" @@ -694,7 +694,7 @@ static dav_error * dav_fs_resolve(dav_lockdb *lockdb, /* ### use a different description and/or error ID? */ return dav_new_error(lockdb->info->pool, HTTP_INTERNAL_SERVER_ERROR, - DAV_ERR_LOCK_CORRUPT_DB, + DAV_ERR_LOCK_CORRUPT_DB, 0, "The lock database was found to be corrupt. " "An indirect lock's direct lock could not " "be found."); @@ -768,7 +768,7 @@ static dav_error * dav_fs_load_locknull_list(apr_pool_t *p, const char *dirpath, rv = apr_file_info_get(&finfo, APR_FINFO_SIZE, file); if (rv != APR_SUCCESS) { - err = dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, + err = dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, rv, apr_psprintf(p, "Opened but could not stat file %s", pbuf->buf)); @@ -776,7 +776,7 @@ static dav_error * dav_fs_load_locknull_list(apr_pool_t *p, const char *dirpath, } if (finfo.size != (apr_size_t)finfo.size) { - err = dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, + err = dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, 0, apr_psprintf(p, "Opened but rejected huge file %s", pbuf->buf)); @@ -785,9 +785,9 @@ static dav_error * dav_fs_load_locknull_list(apr_pool_t *p, const char *dirpath, amt = (apr_size_t)finfo.size; dav_set_bufsize(p, pbuf, amt); - if (apr_file_read(file, pbuf->buf, &amt) != APR_SUCCESS + if ((rv = apr_file_read(file, pbuf->buf, &amt)) != APR_SUCCESS || amt != finfo.size) { - err = dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, + err = dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, rv, apr_psprintf(p, "Failure reading locknull file " "for %s", dirpath)); @@ -813,6 +813,7 @@ static dav_error * dav_fs_save_locknull_list(apr_pool_t *p, const char *dirpath, apr_file_t *file = NULL; dav_error *err = NULL; apr_size_t amt; + apr_status_t rv; if (pbuf->buf == NULL) return NULL; @@ -826,27 +827,27 @@ static dav_error * dav_fs_save_locknull_list(apr_pool_t *p, const char *dirpath, if (pbuf->cur_len == 0) { /* delete the file if cur_len == 0 */ - if (apr_file_remove(pathname, p) != 0) { - return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, + if ((rv = apr_file_remove(pathname, p)) != APR_SUCCESS) { + return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, rv, apr_psprintf(p, "Error removing %s", pathname)); } return NULL; } - if (apr_file_open(&file, pathname, - APR_WRITE | APR_CREATE | APR_TRUNCATE | APR_BINARY, - APR_OS_DEFAULT, p) != APR_SUCCESS) { - return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, + if ((rv = apr_file_open(&file, pathname, + APR_WRITE | APR_CREATE | APR_TRUNCATE | APR_BINARY, + APR_OS_DEFAULT, p)) != APR_SUCCESS) { + return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, rv, apr_psprintf(p, "Error opening %s for writing", pathname)); } amt = pbuf->cur_len; - if (apr_file_write(file, pbuf->buf, &amt) != APR_SUCCESS + if ((rv = apr_file_write(file, pbuf->buf, &amt)) != APR_SUCCESS || amt != pbuf->cur_len) { - err = dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, + err = dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, rv, apr_psprintf(p, "Error writing %" APR_SIZE_T_FMT " bytes to %s", @@ -1005,7 +1006,7 @@ static dav_error * dav_fs_get_locks(dav_lockdb *lockdb, #if DAV_DEBUG if (calltype == DAV_GETLOCKS_COMPLETE) { return dav_new_error(lockdb->info->pool, - HTTP_INTERNAL_SERVER_ERROR, 0, + HTTP_INTERNAL_SERVER_ERROR, 0, 0, "INTERNAL DESIGN ERROR: DAV_GETLOCKS_COMPLETE " "is not yet supported"); } diff --git a/modules/dav/fs/repos.c b/modules/dav/fs/repos.c index c3e66bc70b..f60071e152 100644 --- a/modules/dav/fs/repos.c +++ b/modules/dav/fs/repos.c @@ -282,7 +282,7 @@ dav_error * dav_fs_dir_file_name( *fname_p = ctx->pathname + dirlen; } else { - return dav_new_error(ctx->pool, HTTP_INTERNAL_SERVER_ERROR, 0, + return dav_new_error(ctx->pool, HTTP_INTERNAL_SERVER_ERROR, 0, rv, "An incomplete/bad path was found in " "dav_fs_dir_file_name."); } @@ -349,8 +349,8 @@ static dav_error * dav_fs_copymove_file( if (dst_finfo != NULL) { /* chmod it if it already exist */ - if (apr_file_perms_set(dst, perms)) { - return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, + if ((status = apr_file_perms_set(dst, perms)) != APR_SUCCESS) { + return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, status, "Could not set permissions on destination"); } } @@ -361,10 +361,10 @@ static dav_error * dav_fs_copymove_file( dav_set_bufsize(p, pbuf, DAV_FS_COPY_BLOCKSIZE); - if ((apr_file_open(&inf, src, APR_READ | APR_BINARY, APR_OS_DEFAULT, p)) - != APR_SUCCESS) { + if ((status = apr_file_open(&inf, src, APR_READ | APR_BINARY, + APR_OS_DEFAULT, p)) != APR_SUCCESS) { /* ### use something besides 500? */ - return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, + return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, status, "Could not open file for reading"); } @@ -374,7 +374,7 @@ static dav_error * dav_fs_copymove_file( if (status != APR_SUCCESS) { apr_file_close(inf); - return dav_new_error(p, MAP_IO2HTTP(status), 0, + return dav_new_error(p, MAP_IO2HTTP(status), 0, status, "Could not open file for writing"); } @@ -383,21 +383,24 @@ static dav_error * dav_fs_copymove_file( status = apr_file_read(inf, pbuf->buf, &len); if (status != APR_SUCCESS && status != APR_EOF) { + apr_status_t lcl_status; + apr_file_close(inf); apr_file_close(outf); - if (apr_file_remove(dst, p) != APR_SUCCESS) { + if ((lcl_status = apr_file_remove(dst, p)) != APR_SUCCESS) { /* ### ACK! Inconsistent state... */ /* ### use something besides 500? */ - return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, + return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, + lcl_status, "Could not delete output after read " "failure. Server is now in an " "inconsistent state."); } /* ### use something besides 500? */ - return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, + return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, status, "Could not read input file"); } @@ -407,20 +410,23 @@ static dav_error * dav_fs_copymove_file( /* write any bytes that were read */ status = apr_file_write_full(outf, pbuf->buf, len, NULL); if (status != APR_SUCCESS) { + apr_status_t lcl_status; + apr_file_close(inf); apr_file_close(outf); - if (apr_file_remove(dst, p) != APR_SUCCESS) { + if ((lcl_status = apr_file_remove(dst, p)) != APR_SUCCESS) { /* ### ACK! Inconsistent state... */ /* ### use something besides 500? */ return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, + lcl_status, "Could not delete output after write " "failure. Server is now in an " "inconsistent state."); } - return dav_new_error(p, MAP_IO2HTTP(status), 0, + return dav_new_error(p, MAP_IO2HTTP(status), 0, status, "Could not write output file"); } } @@ -430,37 +436,34 @@ static dav_error * dav_fs_copymove_file( if (is_move && (status = apr_file_remove(src, p)) != APR_SUCCESS) { dav_error *err; - int save_errno = errno; /* save the errno that got us here */ + apr_status_t lcl_status; if (APR_STATUS_IS_ENOENT(status)) { /* * Something is wrong here but the result is what we wanted. * We definitely should not remove the destination file. */ - err = dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, + err = dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, status, apr_psprintf(p, "Could not remove source " "file %s after move to %s. The " "server may be in an " "inconsistent state.", src, dst)); - err->save_errno = save_errno; return err; } - else if (apr_file_remove(dst, p) != APR_SUCCESS) { + else if ((lcl_status = apr_file_remove(dst, p)) != APR_SUCCESS) { /* ### ACK. this creates an inconsistency. do more!? */ /* ### use something besides 500? */ - /* Note that we use the latest errno */ - return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, + return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, lcl_status, "Could not remove source or destination " "file. Server is now in an inconsistent " "state."); } /* ### use something besides 500? */ - err = dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, + err = dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, status, "Could not remove source file after move. " "Destination was removed to ensure consistency."); - err->save_errno = save_errno; return err; } @@ -501,7 +504,7 @@ static dav_error * dav_fs_copymove_state( if (rv != APR_SUCCESS) { if (!APR_STATUS_IS_EEXIST(rv)) { /* ### use something besides 500? */ - return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, + return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, rv, "Could not create internal state directory"); } } @@ -511,7 +514,7 @@ static dav_error * dav_fs_copymove_state( if (rv != APR_SUCCESS && rv != APR_INCOMPLETE) { /* Ack! Where'd it go? */ /* ### use something besides 500? */ - return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, + return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, rv, "State directory disappeared"); } @@ -519,7 +522,7 @@ static dav_error * dav_fs_copymove_state( if (dst_state_finfo.filetype != APR_DIR) { /* ### try to recover by deleting this file? (and mkdir again) */ /* ### use something besides 500? */ - return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, + return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, 0, "State directory is actually a file"); } @@ -535,7 +538,7 @@ static dav_error * dav_fs_copymove_state( } if (rv != APR_SUCCESS) { /* ### use something besides 500? */ - return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, + return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, rv, "Could not move state file."); } } @@ -574,7 +577,7 @@ static dav_error *dav_fs_copymoveset(int is_move, apr_pool_t *p, #if DAV_DEBUG if ((src_state2 != NULL && dst_state2 == NULL) || (src_state2 == NULL && dst_state2 != NULL)) { - return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, + return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, 0, "DESIGN ERROR: dav_dbm_get_statefiles() " "returned inconsistent results."); } @@ -631,7 +634,7 @@ static dav_error *dav_fs_deleteset(apr_pool_t *p, const dav_resource *resource) /* note: we may get ENOENT if the state dir is not present */ if ((status = apr_file_remove(pathname, p)) != APR_SUCCESS && !APR_STATUS_IS_ENOENT(status)) { - return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, + return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, status, "Could not remove properties."); } @@ -646,7 +649,7 @@ static dav_error *dav_fs_deleteset(apr_pool_t *p, const dav_resource *resource) if ((status = apr_file_remove(pathname, p)) != APR_SUCCESS && !APR_STATUS_IS_ENOENT(status)) { /* ### CRAP. only removed half. */ - return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, + return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, status, "Could not fully remove properties. " "The server is now in an inconsistent " "state."); @@ -751,7 +754,7 @@ static dav_error * dav_fs_get_resource( ** be in path_info. The resource is simply an error: it ** can't be a null or a locknull resource. */ - return dav_new_error(r->pool, HTTP_BAD_REQUEST, 0, + return dav_new_error(r->pool, HTTP_BAD_REQUEST, 0, 0, "The URL contains extraneous path " "components. The resource could not " "be identified."); @@ -932,7 +935,7 @@ static dav_error * dav_fs_open_stream(const dav_resource *resource, } if (rv != APR_SUCCESS) { - return dav_new_error(p, MAP_IO2HTTP(rv), 0, + return dav_new_error(p, MAP_IO2HTTP(rv), 0, rv, "An error occurred while opening a resource."); } @@ -953,9 +956,11 @@ static dav_error * dav_fs_close_stream(dav_stream *stream, int commit) apr_pool_cleanup_run(stream->p, stream, tmpfile_cleanup); } else if (stream->unlink_on_error) { - if (apr_file_remove(stream->pathname, stream->p) != APR_SUCCESS) { + if ((rv = apr_file_remove(stream->pathname, stream->p)) + != APR_SUCCESS) { /* ### use a better description? */ return dav_new_error(stream->p, HTTP_INTERNAL_SERVER_ERROR, 0, + rv, "There was a problem removing (rolling " "back) the resource " "when it was being closed."); @@ -965,7 +970,7 @@ static dav_error * dav_fs_close_stream(dav_stream *stream, int commit) else if (stream->temppath) { rv = apr_file_rename(stream->temppath, stream->pathname, stream->p); if (rv) { - return dav_new_error(stream->p, HTTP_INTERNAL_SERVER_ERROR, rv, + return dav_new_error(stream->p, HTTP_INTERNAL_SERVER_ERROR, 0, rv, "There was a problem writing the file " "atomically after writes."); } @@ -982,13 +987,13 @@ static dav_error * dav_fs_write_stream(dav_stream *stream, status = apr_file_write_full(stream->f, buf, bufsize, NULL); if (APR_STATUS_IS_ENOSPC(status)) { - return dav_new_error(stream->p, HTTP_INSUFFICIENT_STORAGE, 0, + return dav_new_error(stream->p, HTTP_INSUFFICIENT_STORAGE, 0, status, "There is not enough storage to write to " "this resource."); } else if (status != APR_SUCCESS) { /* ### use something besides 500? */ - return dav_new_error(stream->p, HTTP_INTERNAL_SERVER_ERROR, 0, + return dav_new_error(stream->p, HTTP_INTERNAL_SERVER_ERROR, 0, status, "An error occurred while writing to a " "resource."); } @@ -997,11 +1002,14 @@ static dav_error * dav_fs_write_stream(dav_stream *stream, static dav_error * dav_fs_seek_stream(dav_stream *stream, apr_off_t abs_pos) { - if (apr_file_seek(stream->f, APR_SET, &abs_pos) != APR_SUCCESS) { + apr_status_t status; + + if ((status = apr_file_seek(stream->f, APR_SET, &abs_pos)) + != APR_SUCCESS) { /* ### should check whether apr_file_seek set abs_pos was set to the * correct position? */ /* ### use something besides 500? */ - return dav_new_error(stream->p, HTTP_INTERNAL_SERVER_ERROR, 0, + return dav_new_error(stream->p, HTTP_INTERNAL_SERVER_ERROR, 0, status, "Could not seek to specified position in the " "resource."); } @@ -1053,11 +1061,11 @@ static dav_error * dav_fs_deliver(const dav_resource *resource, if (resource->type != DAV_RESOURCE_TYPE_REGULAR && resource->type != DAV_RESOURCE_TYPE_VERSION && resource->type != DAV_RESOURCE_TYPE_WORKING) { - return dav_new_error(pool, HTTP_CONFLICT, 0, + return dav_new_error(pool, HTTP_CONFLICT, 0, 0, "Cannot GET this type of resource."); } if (resource->collection) { - return dav_new_error(pool, HTTP_CONFLICT, 0, + return dav_new_error(pool, HTTP_CONFLICT, 0, 0, "There is no default response to GET for a " "collection."); } @@ -1065,7 +1073,7 @@ static dav_error * dav_fs_deliver(const dav_resource *resource, if ((status = apr_file_open(&fd, resource->info->pathname, APR_READ | APR_BINARY, 0, pool)) != APR_SUCCESS) { - return dav_new_error(pool, HTTP_FORBIDDEN, 0, + return dav_new_error(pool, HTTP_FORBIDDEN, 0, status, "File permissions deny server access."); } @@ -1077,7 +1085,7 @@ static dav_error * dav_fs_deliver(const dav_resource *resource, APR_BRIGADE_INSERT_TAIL(bb, bkt); if ((status = ap_pass_brigade(output, bb)) != APR_SUCCESS) { - return dav_new_error(pool, HTTP_FORBIDDEN, 0, + return dav_new_error(pool, HTTP_FORBIDDEN, 0, status, "Could not write contents to filter."); } @@ -1094,18 +1102,18 @@ static dav_error * dav_fs_create_collection(dav_resource *resource) status = apr_dir_make(ctx->pathname, APR_OS_DEFAULT, ctx->pool); if (APR_STATUS_IS_ENOSPC(status)) { - return dav_new_error(ctx->pool, HTTP_INSUFFICIENT_STORAGE, 0, + return dav_new_error(ctx->pool, HTTP_INSUFFICIENT_STORAGE, 0, status, "There is not enough storage to create " "this collection."); } else if (APR_STATUS_IS_ENOENT(status)) { - return dav_new_error(ctx->pool, HTTP_CONFLICT, 0, + return dav_new_error(ctx->pool, HTTP_CONFLICT, 0, status, "Cannot create collection; intermediate " "collection does not exist."); } else if (status != APR_SUCCESS) { /* ### refine this error message? */ - return dav_new_error(ctx->pool, HTTP_FORBIDDEN, 0, + return dav_new_error(ctx->pool, HTTP_FORBIDDEN, 0, status, "Unable to create collection."); } @@ -1119,6 +1127,7 @@ static dav_error * dav_fs_create_collection(dav_resource *resource) static dav_error * dav_fs_copymove_walker(dav_walk_resource *wres, int calltype) { + apr_status_t status; dav_fs_copymove_walk_ctx *ctx = wres->walk_ctx; dav_resource_private *srcinfo = wres->resource->info; dav_resource_private *dstinfo = ctx->res_dst->info; @@ -1134,11 +1143,11 @@ static dav_error * dav_fs_copymove_walker(dav_walk_resource *wres, } else { /* copy/move of a collection. Create the new, target collection */ - if (apr_dir_make(dstinfo->pathname, APR_OS_DEFAULT, - ctx->pool) != APR_SUCCESS) { + if ((status = apr_dir_make(dstinfo->pathname, APR_OS_DEFAULT, + ctx->pool)) != APR_SUCCESS) { /* ### assume it was a permissions problem */ /* ### need a description here */ - err = dav_new_error(ctx->pool, HTTP_FORBIDDEN, 0, NULL); + err = dav_new_error(ctx->pool, HTTP_FORBIDDEN, 0, status, NULL); } } } @@ -1217,7 +1226,7 @@ static dav_error *dav_fs_copymove_resource( if ((*response = multi_status) != NULL) { /* some multistatus responses exist. wrap them in a 207 */ - return dav_new_error(src->info->pool, HTTP_MULTI_STATUS, 0, + return dav_new_error(src->info->pool, HTTP_MULTI_STATUS, 0, 0, "Error(s) occurred on some resources during " "the COPY/MOVE process."); } @@ -1253,7 +1262,7 @@ static dav_error * dav_fs_copy_resource( ** ### strictly speaking, this is a design error; we should not ** ### have reached this point. */ - return dav_new_error(src->info->pool, HTTP_INTERNAL_SERVER_ERROR, 0, + return dav_new_error(src->info->pool, HTTP_INTERNAL_SERVER_ERROR, 0, 0, "DESIGN ERROR: a mix of repositories " "was passed to copy_resource."); } @@ -1286,7 +1295,7 @@ static dav_error * dav_fs_move_resource( ** ### strictly speaking, this is a design error; we should not ** ### have reached this point. */ - return dav_new_error(src->info->pool, HTTP_INTERNAL_SERVER_ERROR, 0, + return dav_new_error(src->info->pool, HTTP_INTERNAL_SERVER_ERROR, 0, 0, "DESIGN ERROR: a mix of repositories " "was passed to move_resource."); } @@ -1315,7 +1324,7 @@ static dav_error * dav_fs_move_resource( if (rv != APR_SUCCESS) { /* ### should have a better error than this. */ - return dav_new_error(srcinfo->pool, HTTP_INTERNAL_SERVER_ERROR, 0, + return dav_new_error(srcinfo->pool, HTTP_INTERNAL_SERVER_ERROR, 0, rv, "Could not rename resource."); } @@ -1400,6 +1409,7 @@ static dav_error * dav_fs_delete_walker(dav_walk_resource *wres, int calltype) static dav_error * dav_fs_remove_resource(dav_resource *resource, dav_response **response) { + apr_status_t status; dav_resource_private *info = resource->info; *response = NULL; @@ -1427,7 +1437,7 @@ static dav_error * dav_fs_remove_resource(dav_resource *resource, if ((*response = multi_status) != NULL) { /* some multistatus responses exist. wrap them in a 207 */ - return dav_new_error(info->pool, HTTP_MULTI_STATUS, 0, + return dav_new_error(info->pool, HTTP_MULTI_STATUS, 0, 0, "Error(s) occurred on some resources during " "the deletion process."); } @@ -1440,9 +1450,9 @@ static dav_error * dav_fs_remove_resource(dav_resource *resource, } /* not a collection; remove the file and its properties */ - if (apr_file_remove(info->pathname, info->pool) != APR_SUCCESS) { + if ((status = apr_file_remove(info->pathname, info->pool)) != APR_SUCCESS) { /* ### put a description in here */ - return dav_new_error(info->pool, HTTP_FORBIDDEN, 0, NULL); + return dav_new_error(info->pool, HTTP_FORBIDDEN, 0, status, NULL); } /* update resource state */ @@ -1460,6 +1470,7 @@ static dav_error * dav_fs_walker(dav_fs_walker_context *fsctx, int depth) { const dav_walk_params *params = fsctx->params; apr_pool_t *pool = params->pool; + apr_status_t status; dav_error *err = NULL; int isdir = fsctx->res1.collection; apr_finfo_t dirent; @@ -1501,13 +1512,12 @@ static dav_error * dav_fs_walker(dav_fs_walker_context *fsctx, int depth) fsctx->res2.collection = 0; /* open and scan the directory */ - if ((apr_dir_open(&dirp, fsctx->path1.buf, pool)) != APR_SUCCESS) { + if ((status = apr_dir_open(&dirp, fsctx->path1.buf, pool)) != APR_SUCCESS) { /* ### need a better error */ - return dav_new_error(pool, HTTP_NOT_FOUND, 0, NULL); + return dav_new_error(pool, HTTP_NOT_FOUND, 0, status, NULL); } while ((apr_dir_read(&dirent, APR_FINFO_DIRENT, dirp)) == APR_SUCCESS) { apr_size_t len; - apr_status_t status; len = strlen(dirent.name); @@ -1544,7 +1554,7 @@ static dav_error * dav_fs_walker(dav_fs_walker_context *fsctx, int depth) if (status != APR_SUCCESS && status != APR_INCOMPLETE) { /* woah! where'd it go? */ /* ### should have a better error here */ - err = dav_new_error(pool, HTTP_NOT_FOUND, 0, NULL); + err = dav_new_error(pool, HTTP_NOT_FOUND, 0, status, NULL); break; } @@ -1744,7 +1754,7 @@ static dav_error * dav_fs_internal_walk(const dav_walk_params *params, #if DAV_DEBUG if ((params->walk_type & DAV_WALKTYPE_LOCKNULL) != 0 && params->lockdb == NULL) { - return dav_new_error(params->pool, HTTP_INTERNAL_SERVER_ERROR, 0, + return dav_new_error(params->pool, HTTP_INTERNAL_SERVER_ERROR, 0, 0, "DESIGN ERROR: walker called to walk locknull " "resources, but a lockdb was not provided."); } @@ -2015,7 +2025,7 @@ static dav_error *dav_fs_patch_validate(const dav_resource *resource, } if (operation == DAV_PROP_OP_DELETE) { - return dav_new_error(resource->info->pool, HTTP_CONFLICT, 0, + return dav_new_error(resource->info->pool, HTTP_CONFLICT, 0, 0, "The 'executable' property cannot be removed."); } @@ -2030,7 +2040,7 @@ static dav_error *dav_fs_patch_validate(const dav_resource *resource, if (cdata == NULL) { if (f_cdata == NULL) { - return dav_new_error(resource->info->pool, HTTP_CONFLICT, 0, + return dav_new_error(resource->info->pool, HTTP_CONFLICT, 0, 0, "The 'executable' property expects a single " "character, valued 'T' or 'F'. There was no " "value submitted."); @@ -2045,7 +2055,7 @@ static dav_error *dav_fs_patch_validate(const dav_resource *resource, value = cdata->text[0]; if (value != 'T' && value != 'F') { - return dav_new_error(resource->info->pool, HTTP_CONFLICT, 0, + return dav_new_error(resource->info->pool, HTTP_CONFLICT, 0, 0, "The 'executable' property expects a single " "character, valued 'T' or 'F'. The value " "submitted is invalid."); @@ -2056,7 +2066,7 @@ static dav_error *dav_fs_patch_validate(const dav_resource *resource, return NULL; too_long: - return dav_new_error(resource->info->pool, HTTP_CONFLICT, 0, + return dav_new_error(resource->info->pool, HTTP_CONFLICT, 0, 0, "The 'executable' property expects a single " "character, valued 'T' or 'F'. The value submitted " "has too many characters."); @@ -2071,6 +2081,7 @@ static dav_error *dav_fs_patch_exec(const dav_resource *resource, { long value = context != NULL; apr_fileperms_t perms = resource->info->finfo.protection; + apr_status_t status; long old_value = (perms & APR_UEXECUTE) != 0; /* assert: prop == executable. operation == SET. */ @@ -2084,9 +2095,10 @@ static dav_error *dav_fs_patch_exec(const dav_resource *resource, if (value) perms |= APR_UEXECUTE; - if (apr_file_perms_set(resource->info->pathname, perms) != APR_SUCCESS) { + if ((status = apr_file_perms_set(resource->info->pathname, perms)) + != APR_SUCCESS) { return dav_new_error(resource->info->pool, - HTTP_INTERNAL_SERVER_ERROR, 0, + HTTP_INTERNAL_SERVER_ERROR, 0, status, "Could not set the executable flag of the " "target resource."); } @@ -2112,6 +2124,7 @@ static dav_error *dav_fs_patch_rollback(const dav_resource *resource, dav_liveprop_rollback *rollback_ctx) { apr_fileperms_t perms = resource->info->finfo.protection & ~APR_UEXECUTE; + apr_status_t status; int value = rollback_ctx != NULL; /* assert: prop == executable. operation == SET. */ @@ -2120,9 +2133,10 @@ static dav_error *dav_fs_patch_rollback(const dav_resource *resource, if (value) perms |= APR_UEXECUTE; - if (apr_file_perms_set(resource->info->pathname, perms) != APR_SUCCESS) { + if ((status = apr_file_perms_set(resource->info->pathname, perms)) + != APR_SUCCESS) { return dav_new_error(resource->info->pool, - HTTP_INTERNAL_SERVER_ERROR, 0, + HTTP_INTERNAL_SERVER_ERROR, 0, status, "After a failure occurred, the resource's " "executable flag could not be restored."); } diff --git a/modules/dav/lock/locks.c b/modules/dav/lock/locks.c index a4e0e214c5..264a851a75 100644 --- a/modules/dav/lock/locks.c +++ b/modules/dav/lock/locks.c @@ -204,7 +204,6 @@ extern const dav_hooks_locks dav_hooks_locks_generic; static dav_error * dav_generic_dbm_new_error(apr_dbm_t *db, apr_pool_t *p, apr_status_t status) { - int save_errno = errno; int errcode; const char *errstr; dav_error *err; @@ -224,8 +223,7 @@ static dav_error * dav_generic_dbm_new_error(apr_dbm_t *db, apr_pool_t *p, errstr = apr_pstrdup(p, errbuf); } - err = dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, errcode, errstr); - err->save_errno = save_errno; + err = dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, errcode, status, errstr); return err; } @@ -264,7 +262,7 @@ static dav_error * dav_generic_parse_locktoken(apr_pool_t *p, if (ap_strstr_c(char_token, "opaquelocktoken:") != char_token) { return dav_new_error(p, - HTTP_BAD_REQUEST, DAV_ERR_LOCK_UNK_STATE_TOKEN, + HTTP_BAD_REQUEST, DAV_ERR_LOCK_UNK_STATE_TOKEN, 0, "The lock token uses an unknown State-token " "format and could not be parsed."); } @@ -272,7 +270,7 @@ static dav_error * dav_generic_parse_locktoken(apr_pool_t *p, locktoken = apr_pcalloc(p, sizeof(*locktoken)); if (apr_uuid_parse(&locktoken->uuid, char_token)) { - return dav_new_error(p, HTTP_BAD_REQUEST, DAV_ERR_LOCK_PARSE_TOKEN, + return dav_new_error(p, HTTP_BAD_REQUEST, DAV_ERR_LOCK_PARSE_TOKEN, 0, "The opaquelocktoken has an incorrect format " "and could not be parsed."); } @@ -363,7 +361,7 @@ static dav_error * dav_generic_open_lockdb(request_rec *r, int ro, int force, comb->priv.lockdb_path = dav_generic_get_lockdb_path(r); if (comb->priv.lockdb_path == NULL) { return dav_new_error(r->pool, HTTP_INTERNAL_SERVER_ERROR, - DAV_ERR_LOCK_NO_DB, + DAV_ERR_LOCK_NO_DB, 0, "A lock database was not specified with the " "DAVGenericLockDB directive. One must be " "specified to use the locking functionality."); @@ -447,7 +445,7 @@ static dav_error * dav_generic_save_lock_record(dav_lockdb *lockdb, #if DAV_DEBUG if (lockdb->ro) { return dav_new_error(lockdb->info->pool, - HTTP_INTERNAL_SERVER_ERROR, 0, + HTTP_INTERNAL_SERVER_ERROR, 0, 0, "INTERNAL DESIGN ERROR: the lockdb was opened " "readonly, but an attempt to save locks was " "performed."); @@ -665,7 +663,7 @@ static dav_error * dav_generic_load_lock_record(dav_lockdb *lockdb, --offset; return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, - DAV_ERR_LOCK_CORRUPT_DB, + DAV_ERR_LOCK_CORRUPT_DB, 0, apr_psprintf(p, "The lock database was found to " "be corrupt. offset %" @@ -722,7 +720,7 @@ static dav_error * dav_generic_resolve(dav_lockdb *lockdb, /* ### use a different description and/or error ID? */ return dav_new_error(lockdb->info->pool, HTTP_INTERNAL_SERVER_ERROR, - DAV_ERR_LOCK_CORRUPT_DB, + DAV_ERR_LOCK_CORRUPT_DB, 0, "The lock database was found to be corrupt. " "An indirect lock's direct lock could not " "be found."); @@ -798,7 +796,7 @@ static dav_error * dav_generic_get_locks(dav_lockdb *lockdb, #if DAV_DEBUG if (calltype == DAV_GETLOCKS_COMPLETE) { return dav_new_error(lockdb->info->pool, - HTTP_INTERNAL_SERVER_ERROR, 0, + HTTP_INTERNAL_SERVER_ERROR, 0, 0, "INTERNAL DESIGN ERROR: DAV_GETLOCKS_COMPLETE " "is not yet supported"); } diff --git a/modules/dav/main/mod_dav.c b/modules/dav/main/mod_dav.c index 1e6f303c56..f9a7c9ab5a 100644 --- a/modules/dav/main/mod_dav.c +++ b/modules/dav/main/mod_dav.c @@ -557,16 +557,8 @@ static void dav_log_err(request_rec *r, dav_error *err, int level) if (errscan->desc == NULL) continue; - if (errscan->save_errno != 0) { - errno = errscan->save_errno; - ap_log_rerror(APLOG_MARK, level, errno, r, "%s [%d, #%d]", - errscan->desc, errscan->status, errscan->error_id); - } - else { - ap_log_rerror(APLOG_MARK, level, 0, r, - "%s [%d, #%d]", - errscan->desc, errscan->status, errscan->error_id); - } + ap_log_rerror(APLOG_MARK, level, errscan->aprerr, r, "%s [%d, #%d]", + errscan->desc, errscan->status, errscan->error_id); } } @@ -729,7 +721,7 @@ static dav_error *dav_get_resource(request_rec *r, int label_allowed, /* Note: this shouldn't happen, but just be sure... */ if (*res_p == NULL) { /* ### maybe use HTTP_INTERNAL_SERVER_ERROR */ - return dav_new_error(r->pool, HTTP_NOT_FOUND, 0, + return dav_new_error(r->pool, HTTP_NOT_FOUND, 0, 0, apr_psprintf(r->pool, "The provider did not define a " "resource for %s.", @@ -981,7 +973,7 @@ static int dav_method_put(request_rec *r) APR_BLOCK_READ, DAV_READ_BLOCKSIZE); if (rc != APR_SUCCESS) { - err = dav_new_error(r->pool, HTTP_INTERNAL_SERVER_ERROR, 0, + err = dav_new_error(r->pool, HTTP_INTERNAL_SERVER_ERROR, 0, rc, apr_psprintf(r->pool, "Could not get next bucket " "brigade (URI: %s)", @@ -1007,7 +999,7 @@ static int dav_method_put(request_rec *r) rc = apr_bucket_read(b, &data, &len, APR_BLOCK_READ); if (rc != APR_SUCCESS) { - err = dav_new_error(r->pool, HTTP_BAD_REQUEST, 0, + err = dav_new_error(r->pool, HTTP_BAD_REQUEST, 0, rc, apr_psprintf(r->pool, "An error occurred while reading" " the request body (URI: %s)", @@ -1298,7 +1290,7 @@ static dav_error *dav_gen_supported_methods(request_rec *r, } if (name == NULL) { - return dav_new_error(r->pool, HTTP_BAD_REQUEST, 0, + return dav_new_error(r->pool, HTTP_BAD_REQUEST, 0, 0, "A DAV:supported-method element " "does not have a \"name\" attribute"); } @@ -1381,7 +1373,7 @@ static dav_error *dav_gen_supported_live_props(request_rec *r, } if (name == NULL) { - err = dav_new_error(r->pool, HTTP_BAD_REQUEST, 0, + err = dav_new_error(r->pool, HTTP_BAD_REQUEST, 0, 0, "A DAV:supported-live-property " "element does not have a \"name\" " "attribute"); @@ -1466,7 +1458,7 @@ static dav_error *dav_gen_supported_reports(request_rec *r, } if (name == NULL) { - return dav_new_error(r->pool, HTTP_BAD_REQUEST, 0, + return dav_new_error(r->pool, HTTP_BAD_REQUEST, 0, 0, "A DAV:supported-report element " "does not have a \"name\" attribute"); } @@ -2150,7 +2142,7 @@ static apr_text * dav_failed_proppatch(apr_pool_t *p, if (ctx->operation == DAV_PROP_OP_SET) { if (err424_set == NULL) - err424_set = dav_new_error(p, HTTP_FAILED_DEPENDENCY, 0, + err424_set = dav_new_error(p, HTTP_FAILED_DEPENDENCY, 0, 0, "Attempted DAV:set operation " "could not be completed due " "to other errors."); @@ -2158,7 +2150,7 @@ static apr_text * dav_failed_proppatch(apr_pool_t *p, } else if (ctx->operation == DAV_PROP_OP_DELETE) { if (err424_delete == NULL) - err424_delete = dav_new_error(p, HTTP_FAILED_DEPENDENCY, 0, + err424_delete = dav_new_error(p, HTTP_FAILED_DEPENDENCY, 0, 0, "Attempted DAV:remove " "operation could not be " "completed due to other " @@ -3038,7 +3030,7 @@ static int dav_method_lock(request_rec *r) return dav_handle_err(r, err, NULL); } if (parent && (!parent->exists || parent->collection != 1)) { - err = dav_new_error(r->pool, HTTP_CONFLICT, 0, + err = dav_new_error(r->pool, HTTP_CONFLICT, 0, 0, apr_psprintf(r->pool, "The parent resource of %s does not " "exist or is not a collection.", @@ -3343,14 +3335,14 @@ static int dav_method_vsn_control(request_rec *r) /* if not versioning existing resource, must specify version to select */ if (!resource->exists && target == NULL) { - err = dav_new_error(r->pool, HTTP_CONFLICT, 0, + err = dav_new_error(r->pool, HTTP_CONFLICT, 0, 0, ""); return dav_handle_err(r, err, NULL); } else if (resource->exists) { /* cannot add resource to existing version history */ if (target != NULL) { - err = dav_new_error(r->pool, HTTP_CONFLICT, 0, + err = dav_new_error(r->pool, HTTP_CONFLICT, 0, 0, ""); return dav_handle_err(r, err, NULL); } @@ -3358,7 +3350,7 @@ static int dav_method_vsn_control(request_rec *r) /* resource must be unversioned and versionable, or version selector */ if (resource->type != DAV_RESOURCE_TYPE_REGULAR || (!resource->versioned && !(vsn_hooks->versionable)(resource))) { - err = dav_new_error(r->pool, HTTP_CONFLICT, 0, + err = dav_new_error(r->pool, HTTP_CONFLICT, 0, 0, ""); return dav_handle_err(r, err, NULL); } @@ -3919,11 +3911,11 @@ static dav_error * dav_label_walker(dav_walk_resource *wres, int calltype) if (wres->resource->type != DAV_RESOURCE_TYPE_VERSION && (wres->resource->type != DAV_RESOURCE_TYPE_REGULAR || !wres->resource->versioned)) { - err = dav_new_error(ctx->w.pool, HTTP_CONFLICT, 0, + err = dav_new_error(ctx->w.pool, HTTP_CONFLICT, 0, 0, ""); } else if (wres->resource->working) { - err = dav_new_error(ctx->w.pool, HTTP_CONFLICT, 0, + err = dav_new_error(ctx->w.pool, HTTP_CONFLICT, 0, 0, ""); } else { @@ -4049,11 +4041,12 @@ static int dav_method_label(request_rec *r) * overall error to pass to dav_handle_err() */ if (depth == 0) { - err = dav_new_error(r->pool, multi_status->status, 0, multi_status->desc); + err = dav_new_error(r->pool, multi_status->status, 0, 0, + multi_status->desc); multi_status = NULL; } else { - err = dav_new_error(r->pool, HTTP_MULTI_STATUS, 0, + err = dav_new_error(r->pool, HTTP_MULTI_STATUS, 0, 0, "Errors occurred during the LABEL operation."); } @@ -4175,7 +4168,7 @@ static int dav_method_make_workspace(request_rec *r) /* resource must not already exist */ if (resource->exists) { - err = dav_new_error(r->pool, HTTP_CONFLICT, 0, + err = dav_new_error(r->pool, HTTP_CONFLICT, 0, 0, ""); return dav_handle_err(r, err, NULL); } @@ -4231,7 +4224,7 @@ static int dav_method_make_activity(request_rec *r) /* resource must not already exist */ if (resource->exists) { - err = dav_new_error(r->pool, HTTP_CONFLICT, 0, + err = dav_new_error(r->pool, HTTP_CONFLICT, 0, 0, ""); return dav_handle_err(r, err, NULL); } @@ -4240,7 +4233,7 @@ static int dav_method_make_activity(request_rec *r) an activity, i.e. whether the location is ok. */ if (vsn_hooks->can_be_activity != NULL && !(*vsn_hooks->can_be_activity)(resource)) { - err = dav_new_error(r->pool, HTTP_FORBIDDEN, 0, + err = dav_new_error(r->pool, HTTP_FORBIDDEN, 0, 0, ""); return dav_handle_err(r, err, NULL); } diff --git a/modules/dav/main/mod_dav.h b/modules/dav/main/mod_dav.h index 59ace41224..82c3539ce3 100644 --- a/modules/dav/main/mod_dav.h +++ b/modules/dav/main/mod_dav.h @@ -123,7 +123,7 @@ typedef struct dav_error { int error_id; /* DAV-specific error ID */ const char *desc; /* DAV:responsedescription and error log */ - int save_errno; /* copy of errno causing the error */ + apr_status_t aprerr; /* APR error if any, or 0/APR_SUCCESS */ const char *namespace; /* [optional] namespace of error */ const char *tagname; /* name of error-tag */ @@ -137,16 +137,17 @@ typedef struct dav_error { ** errno value. */ DAV_DECLARE(dav_error*) dav_new_error(apr_pool_t *p, int status, - int error_id, const char *desc); + int error_id, apr_status_t aprerr, + const char *desc); /* ** Create a new error structure with tagname and (optional) namespace; -** namespace may be NULL, which means "DAV:". save_errno will be -** filled with the current errno value. +** namespace may be NULL, which means "DAV:". */ DAV_DECLARE(dav_error*) dav_new_error_tag(apr_pool_t *p, int status, - int error_id, const char *desc, + int error_id, apr_status_t aprerr, + const char *desc, const char *namespace, const char *tagname); diff --git a/modules/dav/main/props.c b/modules/dav/main/props.c index b9601d78a7..d87dd61131 100644 --- a/modules/dav/main/props.c +++ b/modules/dav/main/props.c @@ -526,7 +526,7 @@ DAV_DECLARE(dav_error *)dav_open_propdb(request_rec *r, dav_lockdb *lockdb, #if DAV_DEBUG if (resource->uri == NULL) { - return dav_new_error(r->pool, HTTP_INTERNAL_SERVER_ERROR, 0, + return dav_new_error(r->pool, HTTP_INTERNAL_SERVER_ERROR, 0, 0, "INTERNAL DESIGN ERROR: resource must define " "its URI."); } @@ -789,6 +789,7 @@ DAV_DECLARE(dav_get_props_result) dav_get_props(dav_propdb *propdb, #if 0 /* ### need to change signature to return an error */ return dav_new_error(propdb->p, HTTP_INTERNAL_SERVER_ERROR, 0, + 0, "INTERNAL DESIGN ERROR: insert_liveprop " "did not insert what was asked for."); #endif @@ -932,7 +933,7 @@ DAV_DECLARE_NONSTD(void) dav_prop_validate(dav_prop_ctx *ctx) if (!dav_rw_liveprop(propdb, priv)) { ctx->err = dav_new_error(propdb->p, HTTP_CONFLICT, - DAV_ERR_PROP_READONLY, + DAV_ERR_PROP_READONLY, 0, "Property is read-only."); return; } @@ -968,7 +969,7 @@ DAV_DECLARE_NONSTD(void) dav_prop_validate(dav_prop_ctx *ctx) */ if (propdb->db == NULL) { ctx->err = dav_new_error(propdb->p, HTTP_INTERNAL_SERVER_ERROR, - DAV_ERR_PROP_NO_DATABASE, + DAV_ERR_PROP_NO_DATABASE, 0, "Attempted to set/remove a property " "without a valid, open, read/write " "property database."); diff --git a/modules/dav/main/util.c b/modules/dav/main/util.c index 5297b90848..3af8ecb78e 100644 --- a/modules/dav/main/util.c +++ b/modules/dav/main/util.c @@ -33,10 +33,9 @@ #include "http_log.h" #include "http_protocol.h" -DAV_DECLARE(dav_error*) dav_new_error(apr_pool_t *p, int status, - int error_id, const char *desc) +DAV_DECLARE(dav_error*) dav_new_error(apr_pool_t *p, int status, int error_id, + apr_status_t aprerr, const char *desc) { - int save_errno = errno; dav_error *err = apr_pcalloc(p, sizeof(*err)); /* DBG3("dav_new_error: %d %d %s", status, error_id, desc ? desc : "(no desc)"); */ @@ -44,17 +43,18 @@ DAV_DECLARE(dav_error*) dav_new_error(apr_pool_t *p, int status, err->status = status; err->error_id = error_id; err->desc = desc; - err->save_errno = save_errno; + err->aprerr = aprerr; return err; } DAV_DECLARE(dav_error*) dav_new_error_tag(apr_pool_t *p, int status, - int error_id, const char *desc, + int error_id, apr_status_t aprerr, + const char *desc, const char *namespace, const char *tagname) { - dav_error *err = dav_new_error(p, status, error_id, desc); + dav_error *err = dav_new_error(p, status, error_id, aprerr, desc); err->tagname = tagname; err->namespace = namespace; @@ -599,6 +599,7 @@ static dav_error * dav_process_if_header(request_rec *r, dav_if_header **p_ih) const char *state_token; const char *uri = NULL; /* scope of current production; NULL=no-tag */ apr_size_t uri_len = 0; + apr_status_t rv; dav_if_header *ih = NULL; apr_uri_t parsed_uri; const dav_hooks_locks *locks_hooks = DAV_GET_HOOKS_LOCKS(r); @@ -617,16 +618,16 @@ static dav_error * dav_process_if_header(request_rec *r, dav_if_header **p_ih) if (list_type == no_tagged || ((uri = dav_fetch_next_token(&str, '>')) == NULL)) { return dav_new_error(r->pool, HTTP_BAD_REQUEST, - DAV_ERR_IF_TAGGED, + DAV_ERR_IF_TAGGED, 0, "Invalid If-header: unclosed \"<\" or " "unexpected tagged-list production."); } /* 2518 specifies this must be an absolute URI; just take the * relative part for later comparison against r->uri */ - if (apr_uri_parse(r->pool, uri, &parsed_uri) != APR_SUCCESS) { + if ((rv = apr_uri_parse(r->pool, uri, &parsed_uri)) != APR_SUCCESS) { return dav_new_error(r->pool, HTTP_BAD_REQUEST, - DAV_ERR_IF_TAGGED, + DAV_ERR_IF_TAGGED, rv, "Invalid URI in tagged If-header."); } /* note that parsed_uri.path is allocated; we can trash it */ @@ -650,14 +651,14 @@ static dav_error * dav_process_if_header(request_rec *r, dav_if_header **p_ih) if ((list = dav_fetch_next_token(&str, ')')) == NULL) { return dav_new_error(r->pool, HTTP_BAD_REQUEST, - DAV_ERR_IF_UNCLOSED_PAREN, + DAV_ERR_IF_UNCLOSED_PAREN, 0, "Invalid If-header: unclosed \"(\"."); } if ((ih = dav_add_if_resource(r->pool, ih, uri, uri_len)) == NULL) { /* ### dav_add_if_resource() should return an error for us! */ return dav_new_error(r->pool, HTTP_BAD_REQUEST, - DAV_ERR_IF_PARSE, + DAV_ERR_IF_PARSE, 0, "Internal server error parsing \"If:\" " "header."); } @@ -672,7 +673,7 @@ static dav_error * dav_process_if_header(request_rec *r, dav_if_header **p_ih) if ((state_token = dav_fetch_next_token(&list, '>')) == NULL) { /* ### add a description to this error */ return dav_new_error(r->pool, HTTP_BAD_REQUEST, - DAV_ERR_IF_PARSE, NULL); + DAV_ERR_IF_PARSE, 0, NULL); } if ((err = dav_add_if_state(r->pool, ih, state_token, dav_if_opaquelock, @@ -687,7 +688,7 @@ static dav_error * dav_process_if_header(request_rec *r, dav_if_header **p_ih) if ((state_token = dav_fetch_next_token(&list, ']')) == NULL) { /* ### add a description to this error */ return dav_new_error(r->pool, HTTP_BAD_REQUEST, - DAV_ERR_IF_PARSE, NULL); + DAV_ERR_IF_PARSE, 0, NULL); } if ((err = dav_add_if_state(r->pool, ih, state_token, dav_if_etag, @@ -702,7 +703,7 @@ static dav_error * dav_process_if_header(request_rec *r, dav_if_header **p_ih) if (list[1] == 'o' && list[2] == 't') { if (condition != DAV_IF_COND_NORMAL) { return dav_new_error(r->pool, HTTP_BAD_REQUEST, - DAV_ERR_IF_MULTIPLE_NOT, + DAV_ERR_IF_MULTIPLE_NOT, 0, "Invalid \"If:\" header: " "Multiple \"not\" entries " "for the same state."); @@ -718,7 +719,7 @@ static dav_error * dav_process_if_header(request_rec *r, dav_if_header **p_ih) default: return dav_new_error(r->pool, HTTP_BAD_REQUEST, - DAV_ERR_IF_UNK_CHAR, + DAV_ERR_IF_UNK_CHAR, 0, apr_psprintf(r->pool, "Invalid \"If:\" " "header: Unexpected " @@ -737,7 +738,7 @@ static dav_error * dav_process_if_header(request_rec *r, dav_if_header **p_ih) default: return dav_new_error(r->pool, HTTP_BAD_REQUEST, - DAV_ERR_IF_UNK_CHAR, + DAV_ERR_IF_UNK_CHAR, 0, apr_psprintf(r->pool, "Invalid \"If:\" header: " "Unexpected character " @@ -883,7 +884,7 @@ static dav_error * dav_validate_resource_state(apr_pool_t *p, */ if (flags & DAV_LOCKSCOPE_EXCLUSIVE) { if (lock_list != NULL) { - return dav_new_error(p, HTTP_LOCKED, 0, + return dav_new_error(p, HTTP_LOCKED, 0, 0, "Existing lock(s) on the requested resource " "prevent an exclusive lock."); } @@ -901,7 +902,7 @@ static dav_error * dav_validate_resource_state(apr_pool_t *p, */ for (lock = lock_list; lock != NULL; lock = lock->next) { if (lock->scope == DAV_LOCKSCOPE_EXCLUSIVE) { - return dav_new_error(p, HTTP_LOCKED, 0, + return dav_new_error(p, HTTP_LOCKED, 0, 0, "The requested resource is already " "locked exclusively."); } @@ -940,7 +941,7 @@ static dav_error * dav_validate_resource_state(apr_pool_t *p, if (seen_locktoken) return NULL; - return dav_new_error(p, HTTP_LOCKED, 0, + return dav_new_error(p, HTTP_LOCKED, 0, 0, "This resource is locked and an \"If:\" header " "was not supplied to allow access to the " "resource."); @@ -964,7 +965,7 @@ static dav_error * dav_validate_resource_state(apr_pool_t *p, if (lock_list == NULL && if_header->dummy_header) { if (flags & DAV_VALIDATE_IS_PARENT) return NULL; - return dav_new_error(p, HTTP_BAD_REQUEST, 0, + return dav_new_error(p, HTTP_BAD_REQUEST, 0, 0, "The locktoken specified in the \"Lock-Token:\" " "header is invalid because this resource has no " "outstanding locks."); @@ -1170,7 +1171,7 @@ static dav_error * dav_validate_resource_state(apr_pool_t *p, "\" submitted a locktoken created " "by user \"", lock->auth_user, "\".", NULL); - return dav_new_error(p, HTTP_FORBIDDEN, 0, errmsg); + return dav_new_error(p, HTTP_FORBIDDEN, 0, 0, errmsg); } /* @@ -1290,7 +1291,7 @@ static dav_error * dav_validate_resource_state(apr_pool_t *p, return NULL; } - return dav_new_error(p, HTTP_LOCKED, 0 /* error_id */, + return dav_new_error(p, HTTP_LOCKED, 0 /* error_id */, 0, "This resource is locked and the \"If:\" " "header did not specify one of the " "locktokens for this resource's lock(s)."); @@ -1304,19 +1305,19 @@ static dav_error * dav_validate_resource_state(apr_pool_t *p, ** bad Lock-Token first. That is considered a 400 (Bad Request). */ if (if_header->dummy_header) { - return dav_new_error(p, HTTP_BAD_REQUEST, 0, + return dav_new_error(p, HTTP_BAD_REQUEST, 0, 0, "The locktoken specified in the " "\"Lock-Token:\" header did not specify one " "of this resource's locktoken(s)."); } if (reason == NULL) { - return dav_new_error(p, HTTP_PRECONDITION_FAILED, 0, + return dav_new_error(p, HTTP_PRECONDITION_FAILED, 0, 0, "The preconditions specified by the \"If:\" " "header did not match this resource."); } - return dav_new_error(p, HTTP_PRECONDITION_FAILED, 0, + return dav_new_error(p, HTTP_PRECONDITION_FAILED, 0, 0, apr_psprintf(p, "The precondition(s) specified by " "the \"If:\" header did not match " @@ -1361,13 +1362,13 @@ static dav_error * dav_validate_resource_state(apr_pool_t *p, ** We want to note the 400 (Bad Request) in favor of a 423 (Locked). */ if (if_header->dummy_header) { - return dav_new_error(p, HTTP_BAD_REQUEST, 0, + return dav_new_error(p, HTTP_BAD_REQUEST, 0, 0, "The locktoken specified in the " "\"Lock-Token:\" header did not specify one " "of this resource's locktoken(s)."); } - return dav_new_error(p, HTTP_LOCKED, 1 /* error_id */, + return dav_new_error(p, HTTP_LOCKED, 1 /* error_id */, 0, "This resource is locked and the \"If:\" header " "did not specify one of the " "locktokens for this resource's lock(s)."); @@ -1476,7 +1477,7 @@ DAV_DECLARE(dav_error *) dav_validate_request(request_rec *r, ** ### bleck. we can't return errors for other URIs unless we have ** ### a "response" ptr. */ - return dav_new_error(r->pool, HTTP_INTERNAL_SERVER_ERROR, 0, + return dav_new_error(r->pool, HTTP_INTERNAL_SERVER_ERROR, 0, 0, "DESIGN ERROR: dav_validate_request called " "with depth>0, but no response ptr."); } @@ -1508,7 +1509,7 @@ DAV_DECLARE(dav_error *) dav_validate_request(request_rec *r, apr_table_unset(r->headers_out, "ETag"); } if (result != OK) { - return dav_new_error(r->pool, result, 0, NULL); + return dav_new_error(r->pool, result, 0, 0, NULL); } /* always parse (and later process) the If: header */ @@ -1592,7 +1593,7 @@ DAV_DECLARE(dav_error *) dav_validate_request(request_rec *r, err = (*repos_hooks->get_parent_resource)(resource, &parent_resource); if (err == NULL && parent_resource == NULL) { - err = dav_new_error(r->pool, HTTP_FORBIDDEN, 0, + err = dav_new_error(r->pool, HTTP_FORBIDDEN, 0, 0, "Cannot access parent of repository root."); } else if (err == NULL) { @@ -1648,7 +1649,7 @@ DAV_DECLARE(dav_error *) dav_validate_request(request_rec *r, if ((flags & DAV_VALIDATE_USE_424) != 0) { /* manufacture a 424 error to hold the multistatus response(s) */ - return dav_new_error(r->pool, HTTP_FAILED_DEPENDENCY, 0, + return dav_new_error(r->pool, HTTP_FAILED_DEPENDENCY, 0, 0, "An error occurred on another resource, " "preventing the requested operation on " "this resource."); @@ -1683,7 +1684,7 @@ DAV_DECLARE(dav_error *) dav_validate_request(request_rec *r, *response = new_response; /* manufacture a 207 error for the multistatus response(s) */ - return dav_new_error(r->pool, HTTP_MULTI_STATUS, 0, + return dav_new_error(r->pool, HTTP_MULTI_STATUS, 0, 0, "Error(s) occurred on resources during the " "validation process."); } @@ -1727,7 +1728,7 @@ DAV_DECLARE(dav_error *) dav_get_locktoken_list(request_rec *r, } if (*ltl == NULL) { /* No nodes added */ - return dav_new_error(r->pool, HTTP_BAD_REQUEST, DAV_ERR_IF_ABSENT, + return dav_new_error(r->pool, HTTP_BAD_REQUEST, DAV_ERR_IF_ABSENT, 0, "No locktokens were specified in the \"If:\" " "header, so the refresh could not be performed."); } @@ -1824,7 +1825,7 @@ static dav_error * dav_can_auto_checkout( const dav_hooks_locks *locks_hooks = DAV_GET_HOOKS_LOCKS(r); if (locks_hooks == NULL) { - return dav_new_error(r->pool, HTTP_INTERNAL_SERVER_ERROR, 0, + return dav_new_error(r->pool, HTTP_INTERNAL_SERVER_ERROR, 0, 0, "Auto-checkout is only enabled for locked resources, " "but there is no lock provider."); } @@ -1879,7 +1880,7 @@ DAV_DECLARE(dav_error *) dav_auto_checkout( goto done; if (parent == NULL || !parent->exists) { - err = dav_new_error(r->pool, HTTP_CONFLICT, 0, + err = dav_new_error(r->pool, HTTP_CONFLICT, 0, 0, apr_psprintf(r->pool, "Missing one or more intermediate " "collections. Cannot create resource %s.", @@ -1901,7 +1902,7 @@ DAV_DECLARE(dav_error *) dav_auto_checkout( } if (!checkout_parent) { - err = dav_new_error(r->pool, HTTP_CONFLICT, 0, + err = dav_new_error(r->pool, HTTP_CONFLICT, 0, 0, ""); goto done; } @@ -1960,7 +1961,7 @@ DAV_DECLARE(dav_error *) dav_auto_checkout( } if (!checkout_resource) { - err = dav_new_error(r->pool, HTTP_CONFLICT, 0, + err = dav_new_error(r->pool, HTTP_CONFLICT, 0, 0, ""); goto done; } diff --git a/modules/dav/main/util_lock.c b/modules/dav/main/util_lock.c index c24426e884..ef75d9b3a0 100644 --- a/modules/dav/main/util_lock.c +++ b/modules/dav/main/util_lock.c @@ -172,7 +172,7 @@ DAV_DECLARE(dav_error *) dav_lock_parse_lockinfo(request_rec *r, dav_lock *lock; if (!dav_validate_root(doc, "lockinfo")) { - return dav_new_error(p, HTTP_BAD_REQUEST, 0, + return dav_new_error(p, HTTP_BAD_REQUEST, 0, 0, "The request body contains an unexpected " "XML root element."); } @@ -187,7 +187,7 @@ DAV_DECLARE(dav_error *) dav_lock_parse_lockinfo(request_rec *r, lock->depth = dav_get_depth(r, DAV_INFINITY); if (lock->depth == -1) { - return dav_new_error(p, HTTP_BAD_REQUEST, 0, + return dav_new_error(p, HTTP_BAD_REQUEST, 0, 0, "An invalid Depth header was specified."); } lock->timeout = dav_get_timeout(r); @@ -230,7 +230,7 @@ DAV_DECLARE(dav_error *) dav_lock_parse_lockinfo(request_rec *r, continue; } - return dav_new_error(p, HTTP_PRECONDITION_FAILED, 0, + return dav_new_error(p, HTTP_PRECONDITION_FAILED, 0, 0, apr_psprintf(p, "The server cannot satisfy the " "LOCK request due to an unknown XML " @@ -346,7 +346,7 @@ DAV_DECLARE(dav_error *) dav_add_lock(request_rec *r, if (multi_status != NULL) { /* manufacture a 207 error for the multistatus response */ *response = multi_status; - return dav_new_error(r->pool, HTTP_MULTI_STATUS, 0, + return dav_new_error(r->pool, HTTP_MULTI_STATUS, 0, 0, "Error(s) occurred on resources during the " "addition of a depth lock."); } @@ -450,7 +450,7 @@ static dav_error * dav_get_direct_resource(apr_pool_t *p, /* not found! that's an error. */ if (lock == NULL) { - return dav_new_error(p, HTTP_BAD_REQUEST, 0, + return dav_new_error(p, HTTP_BAD_REQUEST, 0, 0, "The specified locktoken does not correspond " "to an existing lock on this resource."); } @@ -471,7 +471,7 @@ static dav_error * dav_get_direct_resource(apr_pool_t *p, resource = parent; } - return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, + return dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, 0, "The lock database is corrupt. A direct lock could " "not be found for the corresponding indirect lock " "on this resource."); @@ -600,7 +600,7 @@ static dav_error * dav_inherit_locks(request_rec *r, dav_lockdb *lockdb, } if (parent == NULL) { /* ### map result to something nice; log an error */ - return dav_new_error(r->pool, HTTP_INTERNAL_SERVER_ERROR, 0, + return dav_new_error(r->pool, HTTP_INTERNAL_SERVER_ERROR, 0, 0, "Could not fetch parent resource. Unable to " "inherit locks from the parent and apply " "them to this resource."); -- 2.50.0