/*
** dav_fs_load_locknull_list:  Returns a dav_buffer dump of the locknull file
**    for the given directory.
*/
static dav_error * dav_fs_load_locknull_list(apr_pool_t *p, const char *dirpath,
                                             dav_buffer *pbuf)
{
    apr_finfo_t finfo;
    apr_file_t *file = NULL;
    dav_error *err = NULL;
    apr_size_t amt;
    apr_status_t rv;

    dav_buffer_init(p, pbuf, dirpath);

    if (pbuf->buf[pbuf->cur_len - 1] == '/')
        pbuf->buf[--pbuf->cur_len] = '\0';

    dav_buffer_place(p, pbuf, "/" DAV_FS_STATE_DIR "/" DAV_FS_LOCK_NULL_FILE);

    /* reset this in case we leave w/o reading into the buffer */
    pbuf->cur_len = 0;

    if (apr_file_open(&file, pbuf->buf, APR_READ | APR_BINARY, APR_OS_DEFAULT,
                p) != APR_SUCCESS) {
        return NULL;
    }

    rv = apr_file_info_get(&finfo, APR_FINFO_SIZE, file);
    if (rv != APR_SUCCESS) {
        err = dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, rv,
                            apr_psprintf(p,
                                        "Opened but could not stat file %s",
                                        pbuf->buf));
        goto loaderror;
    }

    if (finfo.size != (apr_size_t)finfo.size) {
        err = dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, 0,
                            apr_psprintf(p,
                                        "Opened but rejected huge file %s",
                                        pbuf->buf));
        goto loaderror;
    }

    amt = (apr_size_t)finfo.size;
    dav_set_bufsize(p, pbuf, amt);
    if ((rv = apr_file_read(file, pbuf->buf, &amt)) != APR_SUCCESS
        || amt != finfo.size) {
        err = dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0, rv,
                            apr_psprintf(p,
                                        "Failure reading locknull file "
                                        "for %s", dirpath));

        /* just in case the caller disregards the returned error */
        pbuf->cur_len = 0;
        goto loaderror;
    }

  loaderror:
    apr_file_close(file);
    return err;
}
Exemplo n.º 2
0
/**
 * Walk through the file system
 * @param params    Walk parameters
 * @param depth     In depth?
 * @param response  The response
 * @return          NULL on success
 */
static dav_error *dav_ns_walk(const dav_walk_params *params, int depth,
                               dav_response **response)
{
  dav_ns_walker_context  ctx = {0};
  dav_error              *err;

  ctx.params = params;

  ctx.walk_resource.walk_ctx = params->walk_ctx;
  ctx.walk_resource.pool     = params->pool;
  ctx.walk_resource.resource = params->root;

  dav_buffer_init(params->pool, &ctx.sfn, params->root->info->sfn);
  dav_buffer_init(params->pool, &ctx.uri, params->root->uri);

  err = dav_ns_walker(&ctx, depth);
  
  *response = ctx.walk_resource.response;

  return err;
}
Exemplo n.º 3
0
/*
** dav_fs_load_locknull_list:  Returns a dav_buffer dump of the locknull file
**    for the given directory.
*/
static dav_error * dav_fs_load_locknull_list(pool *p, const char *dirpath,
					     dav_buffer *pbuf) 
{
    struct stat finfo;
    int fd;
    dav_error *err = NULL;

    dav_buffer_init(p, pbuf, dirpath);

    if (pbuf->buf[pbuf->cur_len - 1] == '/')
	pbuf->buf[--pbuf->cur_len] = '\0';

    dav_buffer_place(p, pbuf, "/" DAV_FS_STATE_DIR "/" DAV_FS_LOCK_NULL_FILE);

    /* reset this in case we leave w/o reading into the buffer */
    pbuf->cur_len = 0;

    if ((fd = open(pbuf->buf, O_RDONLY | O_BINARY)) == -1) {
	return NULL;
    }

    if (fstat(fd, &finfo) == -1) {
	err = dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0,
			    ap_psprintf(p,
					"Opened but could not stat file %s",
					pbuf->buf));
	goto loaderror;
    }

    dav_set_bufsize(p, pbuf, finfo.st_size);
    if (read(fd, pbuf->buf, finfo.st_size) != finfo.st_size) {
	err = dav_new_error(p, HTTP_INTERNAL_SERVER_ERROR, 0,
			    ap_psprintf(p,
					"Failure reading locknull file "
					"for %s", dirpath));

	/* just in case the caller disregards the returned error */
	pbuf->cur_len = 0;
	goto loaderror;
    }

  loaderror:
    close(fd);
    return err;
}