예제 #1
0
파일: testfile.c 프로젝트: kheradmand/Break
static void test_fail_read_flush(CuTest *tc)
{
    apr_file_t *f;
    const char *fname = "data/testflush.dat";
    apr_status_t rv;
    char buf[2];

    apr_file_remove(fname, p);

    apr_assert_success(tc, "open test file",
                       apr_file_open(&f, fname,
                                     APR_CREATE|APR_READ|APR_BUFFERED,
                                     APR_UREAD|APR_UWRITE, p));

    /* this write should be buffered. */
    apr_assert_success(tc, "buffered write should succeed",
                       apr_file_puts("hello", f));

    /* Now, trying a read should fail since the write must be flushed,
     * and should fail with something other than EOF since the file is
     * opened read-only. */
    rv = apr_file_read_full(f, buf, 2, NULL);

    CuAssert(tc, "read should flush buffered write and fail",
             rv != APR_SUCCESS && rv != APR_EOF);

    /* Likewise for gets */
    rv = apr_file_gets(buf, 2, f);

    CuAssert(tc, "gets should flush buffered write and fail",
             rv != APR_SUCCESS && rv != APR_EOF);

    apr_file_close(f);
    apr_file_remove(fname, p);
}
예제 #2
0
파일: htcacheclean.c 프로젝트: aptana/Jaxer
/*
 * delete cache file set
 */
static void delete_entry(char *path, char *basename, apr_pool_t *pool)
{
    char *nextpath;
    apr_pool_t *p;

    if (dryrun) {
        return;
    }

    /* temp pool, otherwise lots of memory could be allocated */
    apr_pool_create(&p, pool);

    nextpath = apr_pstrcat(p, path, "/", basename, CACHE_HEADER_SUFFIX, NULL);
    apr_file_remove(nextpath, p);

    nextpath = apr_pstrcat(p, path, "/", basename, CACHE_DATA_SUFFIX, NULL);
    apr_file_remove(nextpath, p);

    apr_pool_destroy(p);

    if (benice) {
        delcount += 2;
        if (delcount >= DELETE_NICE) {
            apr_sleep(NICE_DELAY);
            delcount = 0;
        }
    }
}
예제 #3
0
파일: testfile.c 프로젝트: kheradmand/Break
static void test_fail_write_flush(CuTest *tc)
{
    apr_file_t *f;
    const char *fname = "data/testflush.dat";
    apr_status_t rv;
    char buf[APR_BUFFERSIZE];
    int n;

    apr_file_remove(fname, p);

    apr_assert_success(tc, "open test file",
                       apr_file_open(&f, fname,
                                     APR_CREATE|APR_READ|APR_BUFFERED,
                                     APR_UREAD|APR_UWRITE, p));

    memset(buf, 'A', sizeof buf);

    /* Try three writes.  One of these should fail when it exceeds the
     * internal buffer and actually tries to write to the file, which
     * was opened read-only and hence should be unwritable. */
    for (n = 0, rv = APR_SUCCESS; n < 4 && rv == APR_SUCCESS; n++) {
        apr_size_t bytes = sizeof buf;
        rv = apr_file_write(f, buf, &bytes);
    }

    CuAssert(tc, "failed to write to read-only buffered fd",
             rv != APR_SUCCESS);

    apr_file_close(f);
    apr_file_remove(fname, p);
}
예제 #4
0
/* Subversion delta editor callback */
static svn_error_t *de_delete_entry(const char *path, svn_revnum_t revision, void *parent_baton, apr_pool_t *pool)
{
	de_node_baton_t *node;
	de_node_baton_t *parent = (de_node_baton_t *)parent_baton;
	apr_hash_index_t *hi;
	int pathlen;

	DEBUG_MSG("de_delete_entry(%s@%ld)\n", path, revision);

	/* We can dump this entry directly */
	node = delta_create_node(path, parent);
	node->kind = svn_node_none;
	node->action = 'D';
	node->dump_needed = 1;
#if 0
	if ((err = delta_dump_node(node))) {
		return err;
	}
#endif

	/* This node might be a directory, so clear the data of all children */
	pathlen = strlen(node->path);
	for (hi = rhash_first(pool, delta_hash); hi; hi = rhash_next(hi)) {
		const char *npath;
		char *filename;
		rhash_this(hi, (const void **)(void *)&npath, NULL, (void **)(void *)&filename);
		/* TODO: This is a small hack to make sure the node is a directory */
		if (!strncmp(node->path, npath, pathlen) && (npath[pathlen] == '/')) {
#ifndef DUMP_DEBUG
			apr_file_remove(filename, node->pool);
#endif
			DEBUG_MSG("deleting %s from delta_hash\n", npath);
			rhash_set(delta_hash, npath, APR_HASH_KEY_STRING, NULL, 0);
		}
	}
	for (hi = rhash_first(pool, prop_hash); hi; hi = rhash_next(hi)) {
		const char *npath;
		char *filename;
		rhash_this(hi, (const void **)(void *)&npath, NULL, (void **)(void *)&filename);
		/* TODO: This is a small hack to make sure the node is a directory */
		if (!strncmp(node->path, npath, pathlen) && (npath[pathlen] == '/')) {
#ifndef DUMP_DEBUG
			apr_file_remove(filename, node->pool);
#endif
			DEBUG_MSG("deleting %s from prop_hash\n", npath);
			rhash_set(prop_hash, npath, APR_HASH_KEY_STRING, NULL, 0);
		}
	}
	for (hi = rhash_first(pool, md5_hash); hi; hi = rhash_next(hi)) {
		const char *npath;
		char *md5sum;
		rhash_this(hi, (const void **)(void *)&npath, NULL, (void **)(void *)&md5sum);
		if (!strncmp(node->path, npath, pathlen) && (npath[pathlen] == '/')) {
			DEBUG_MSG("deleting %s from md5_hash\n", npath);
			rhash_set(md5_hash, npath, APR_HASH_KEY_STRING, NULL, 0);
		}
	}

	return SVN_NO_ERROR;
}
예제 #5
0
파일: shm.c 프로젝트: MiKTeX/miktex
APR_DECLARE(apr_status_t) apr_shm_remove(const char *filename,
                                         apr_pool_t *pool)
{
#if APR_USE_SHMEM_SHMGET
    apr_status_t status;
    apr_file_t *file;  
    key_t shmkey;
    int shmid;
#endif

#if APR_USE_SHMEM_MMAP_TMP
    return apr_file_remove(filename, pool);
#elif APR_USE_SHMEM_MMAP_SHM
    const char *shm_name = make_shm_open_safe_name(filename, pool);
    if (shm_unlink(shm_name) == -1) {
        return errno;
    }
    return APR_SUCCESS;
#elif APR_USE_SHMEM_SHMGET
    /* Presume that the file already exists; just open for writing */    
    status = apr_file_open(&file, filename, APR_FOPEN_WRITE,
                           APR_OS_DEFAULT, pool);
    if (status) {
        return status;
    }

    /* ftok() (on solaris at least) requires that the file actually
     * exist before calling ftok(). */
    shmkey = our_ftok(filename);
    if (shmkey == (key_t)-1) {
        goto shm_remove_failed;
    }

    apr_file_close(file);

    if ((shmid = shmget(shmkey, 0, SHM_R | SHM_W)) < 0) {
        goto shm_remove_failed;
    }

    /* Indicate that the segment is to be destroyed as soon
     * as all processes have detached. This also disallows any
     * new attachments to the segment. */
    if (shmctl(shmid, IPC_RMID, NULL) == -1) {
        goto shm_remove_failed;
    }
    return apr_file_remove(filename, pool);

shm_remove_failed:
    status = errno;
    /* ensure the file has been removed anyway. */
    apr_file_remove(filename, pool);
    return status;
#else

    /* No support for anonymous shm */
    return APR_ENOTIMPL;
#endif
} 
예제 #6
0
파일: testfile.c 프로젝트: cmjonze/apr
static void test_file_trunc(abts_case *tc, void *data)
{
    apr_status_t rv;
    apr_file_t *f;
    const char *fname = "data/testtruncate.dat";
    const char *s;
    apr_size_t nbytes;
    apr_finfo_t finfo;

    apr_file_remove(fname, p);

    /* Test unbuffered */
    rv = apr_file_open(&f, fname,
                        APR_FOPEN_CREATE | APR_FOPEN_READ |
                        APR_FOPEN_WRITE,
                        APR_FPROT_UREAD | APR_FPROT_UWRITE, p);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);

    s = "some data";
    nbytes = strlen(s);
    rv = apr_file_write(f, s, &nbytes);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    ABTS_SIZE_EQUAL(tc, strlen(s), nbytes);
    rv = apr_file_trunc(f, 4);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    rv = apr_file_close(f);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    rv = apr_stat(&finfo, fname, APR_FINFO_SIZE, p);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    ABTS_ASSERT(tc, "File size mismatch, expected 4", finfo.size == 4);

    rv = apr_file_remove(fname, p);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    /* Test buffered */
    rv = apr_file_open(&f, fname,
                        APR_FOPEN_CREATE | APR_FOPEN_READ |
                        APR_FOPEN_WRITE | APR_FOPEN_BUFFERED,
                        APR_FPROT_UREAD | APR_FPROT_UWRITE, p);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);

    nbytes = strlen(s);
    rv = apr_file_write(f, s, &nbytes);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    ABTS_SIZE_EQUAL(tc, strlen(s), nbytes);
    rv = apr_file_trunc(f, 4);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    rv = apr_file_close(f);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    rv = apr_stat(&finfo, fname, APR_FINFO_SIZE, p);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
    ABTS_ASSERT(tc, "File size mismatch, expected 4", finfo.size == 4);

    rv = apr_file_remove(fname, p);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);
}
예제 #7
0
static void test_insertfile(abts_case *tc, void *ctx)
{
    apr_bucket_alloc_t *ba = apr_bucket_alloc_create(p);
    apr_bucket_brigade *bb;
    const apr_off_t bignum = (APR_INT64_C(2) << 32) + 424242;
    apr_off_t count;
    apr_file_t *f;
    apr_bucket *e;

    ABTS_ASSERT(tc, "open test file",
                apr_file_open(&f, TIF_FNAME,
                              APR_FOPEN_WRITE | APR_FOPEN_TRUNCATE
                            | APR_FOPEN_CREATE | APR_FOPEN_SPARSE,
                              APR_OS_DEFAULT, p) == APR_SUCCESS);

    if (apr_file_trunc(f, bignum)) {
        apr_file_close(f);
        apr_file_remove(TIF_FNAME, p);
        ABTS_NOT_IMPL(tc, "Skipped: could not create large file");
        return;
    }
    
    bb = apr_brigade_create(p, ba);

    e = apr_brigade_insert_file(bb, f, 0, bignum, p);
    
    ABTS_ASSERT(tc, "inserted file was not at end of brigade",
                e == APR_BRIGADE_LAST(bb));

    /* check that the total size of inserted buckets is equal to the
     * total size of the file. */
    count = 0;

    for (e = APR_BRIGADE_FIRST(bb);
         e != APR_BRIGADE_SENTINEL(bb);
         e = APR_BUCKET_NEXT(e)) {
        ABTS_ASSERT(tc, "bucket size sane", e->length != (apr_size_t)-1);
        count += e->length;
    }

    ABTS_ASSERT(tc, "total size of buckets incorrect", count == bignum);

    apr_brigade_destroy(bb);

    /* Truncate the file to zero size before close() so that we don't
     * actually write out the large file if we are on a non-sparse file
     * system - like Mac OS X's HFS.  Otherwise, pity the poor user who
     * has to wait for the 8GB file to be written to disk.
     */
    apr_file_trunc(f, 0);

    apr_file_close(f);
    apr_bucket_alloc_destroy(ba);
    apr_file_remove(TIF_FNAME, p);
}
예제 #8
0
파일: shm.c 프로젝트: AAthresh/quantlib
static apr_status_t shm_cleanup_owner(void *m_)
{
    apr_shm_t *m = (apr_shm_t *)m_;

    /* anonymous shared memory */
    if (m->filename == NULL) {
#if APR_USE_SHMEM_MMAP_ZERO || APR_USE_SHMEM_MMAP_ANON
        if (munmap(m->base, m->realsize) == -1) {
            return errno;
        }
        return APR_SUCCESS;
#endif
#if APR_USE_SHMEM_SHMGET_ANON
        if (shmdt(m->base) == -1) {
            return errno;
        }
        /* This segment will automatically remove itself after all
         * references have detached. */
        return APR_SUCCESS;
#endif
    }

    /* name-based shared memory */
    else {
#if APR_USE_SHMEM_MMAP_TMP
        if (munmap(m->base, m->realsize) == -1) {
            return errno;
        }
        return apr_file_remove(m->filename, m->pool);
#endif
#if APR_USE_SHMEM_MMAP_SHM
        if (munmap(m->base, m->realsize) == -1) {
            return errno;
        }
        if (shm_unlink(m->filename) == -1) {
            return errno;
        }
        return APR_SUCCESS;
#endif
#if APR_USE_SHMEM_SHMGET
        /* Indicate that the segment is to be destroyed as soon
         * as all processes have detached. This also disallows any
         * new attachments to the segment. */
        if (shmctl(m->shmid, IPC_RMID, NULL) == -1) {
            return errno;
        }
        if (shmdt(m->base) == -1) {
            return errno;
        }
        return apr_file_remove(m->filename, m->pool);
#endif
    }

    return APR_ENOTIMPL;
}
예제 #9
0
void core_teardown() {
  // created by various cookie test functions above
  apr_file_remove("/tmp/.metadata", request->pool);
  apr_file_remove("/tmp/.md5", request->pool);
  /* 
   * TODO(pames): figure out why one of these cookie/file-related tests creates
   * a /tmp/.md5 file in addition to the /tmp/.metadata file. and do the cleanup
   * there? 
   */
  apr_pool_destroy(request->pool);
  free(request);
}
예제 #10
0
파일: testfilecopy.c 프로젝트: cmjonze/apr
static void append_nonexist(abts_case *tc, void *data)
{
    apr_status_t rv;

    /* make absolutely sure that the dest file doesn't exist. */
    apr_file_remove("data/file_copy.txt", p);

    copy_helper(tc, "data/file_datafile.txt", "data/file_copy.txt", 
                APR_FPROT_FILE_SOURCE_PERMS, 0, p);
    rv = apr_file_remove("data/file_copy.txt", p);
    APR_ASSERT_SUCCESS(tc, "Couldn't remove copy file", rv);
}
예제 #11
0
	shared_page* shmdata_getNewSharedPage(pool* p, apr_shm_t** shm_t, int segmentsize, char* path){
		int overheadsize,usersize, x;
		shared_page* page;
		apr_status_t rv;
		overheadsize=sizeof(shared_page);
		usersize=segmentsize*2;
			
		rv=apr_shm_create(shm_t,overheadsize+usersize,path,p);
#ifdef WIN32
		if(rv==APR_EEXIST) { // try to attach it; seems windows specific behaviour
			rv = apr_shm_attach(shm_t,path,p);
		}
#endif
		if(rv!=APR_SUCCESS){
			//if failure then try to remove shm segment and try again
			if(apr_shm_attach(shm_t,path,p)==APR_SUCCESS){
				apr_shm_destroy(*shm_t);
				rv=apr_shm_create(shm_t,overheadsize+usersize,path,p);
				//if again failure..possible bad shm file...remove and retry
				if(rv!=APR_SUCCESS){
					rv=apr_file_remove(path,p);
					if(rv==APR_SUCCESS){
						rv=apr_shm_create(shm_t,overheadsize+usersize,path,p);
					}
				}
			}else{ //if cannot attach blow file away and try again
				rv=apr_file_remove(path,p);
				if(rv==APR_SUCCESS){
					rv=apr_shm_create(shm_t,overheadsize+usersize,path,p);
				}	
			}
		}
		
		if(rv==APR_SUCCESS){
			APACHE_LOG_DEBUG1("SHARED PAGES CREATED: Path=%s",path);
			page=apr_shm_baseaddr_get(*shm_t);
			page->itemmax=MAX_PAGE_ITEMS;
			page->segmentsize=segmentsize;
			page->timestamp=SHM_TIMESTAMP_INIT;
			page->flipcount=0;
			page->frontsegment=1;
			page->backsegment=0;
			page->data=(char*)(page+1);
			page->cursor=page->data;
			for(x=0;x<SEGMENTS_PER_PAGE;x++){
				page->segments[x].itemcount=0;
			}			
			return page;
		}
		APACHE_LOG_DEBUG("SHARED PAGE BAD");
	return NULL;
	}
예제 #12
0
static apr_status_t file_cache_errorcleanup(disk_cache_object_t *dobj, request_rec *r)
{
    /* Remove the header file and the body file. */
    apr_file_remove(dobj->hdrsfile, r->pool);
    apr_file_remove(dobj->datafile, r->pool);

    /* If we opened the temporary data file, close and remove it. */
    if (dobj->tfd) {
        apr_file_close(dobj->tfd);
        apr_file_remove(dobj->tempfile, r->pool);
        dobj->tfd = NULL;
    }

    return APR_SUCCESS;
}
예제 #13
0
/* should be apr_status_t really */
static void restore_slotmem(void *ptr, const char *name, apr_size_t size,
                            apr_pool_t *pool)
{
    const char *storename;
    apr_file_t *fp;
    apr_size_t nbytes = size;
    apr_status_t rv;

    storename = slotmem_filename(pool, name, 1);

    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf, APLOGNO(02335)
                 "restoring %s", storename);

    if (storename) {
        rv = apr_file_open(&fp, storename, APR_READ | APR_WRITE, APR_OS_DEFAULT,
                           pool);
        if (rv == APR_SUCCESS) {
            apr_finfo_t fi;
            if (apr_file_info_get(&fi, APR_FINFO_SIZE, fp) == APR_SUCCESS) {
                if (fi.size == nbytes) {
                    apr_file_read(fp, ptr, &nbytes);
                }
                else {
                    apr_file_close(fp);
                    apr_file_remove(storename, pool);
                    return;
                }
            }
            apr_file_close(fp);
        }
    }
}
예제 #14
0
static void store_slotmem(ap_slotmem_instance_t *slotmem)
{
    apr_file_t *fp;
    apr_status_t rv;
    apr_size_t nbytes;
    const char *storename;

    storename = slotmem_filename(slotmem->gpool, slotmem->name, 1);

    ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ap_server_conf, APLOGNO(02334)
                 "storing %s", storename);

    if (storename) {
        rv = apr_file_open(&fp, storename, APR_CREATE | APR_READ | APR_WRITE,
                           APR_OS_DEFAULT, slotmem->gpool);
        if (APR_STATUS_IS_EEXIST(rv)) {
            apr_file_remove(storename, slotmem->gpool);
            rv = apr_file_open(&fp, storename, APR_CREATE | APR_READ | APR_WRITE,
                               APR_OS_DEFAULT, slotmem->gpool);
        }
        if (rv != APR_SUCCESS) {
            return;
        }
        if (AP_SLOTMEM_IS_CLEARINUSE(slotmem)) {
            slotmem_clearinuse(slotmem);
        }
        nbytes = (slotmem->desc.size * slotmem->desc.num) +
                 (slotmem->desc.num * sizeof(char)) + AP_UNSIGNEDINT_OFFSET;
        /* XXX: Error handling */
        apr_file_write_full(fp, slotmem->persist, nbytes, NULL);
        apr_file_close(fp);
    }
}
static apr_status_t cleanup_slotmem(void *param)
{
    ap_slotmem_instance_t **mem = param;

    if (*mem) {
        ap_slotmem_instance_t *next = *mem;
        while (next) {
            if (AP_SLOTMEM_IS_PERSIST(next)) {
                store_slotmem(next);
            }
            if (next->fbased) {
                const char *name;
                apr_shm_remove(next->name, next->gpool);
                name = slotmem_filename(next->gpool, next->name, 0);
                if (name) {
                    apr_file_remove(name, next->gpool);
                }
            }
            apr_shm_destroy((apr_shm_t *)next->shm);
            next = next->next;
        }
    }
    /* apr_pool_destroy(gpool); */
    globallistmem = NULL;
    return APR_SUCCESS;
}
예제 #16
0
파일: testfile.c 프로젝트: aptana/Jaxer
static void test_bigfprintf(abts_case *tc, void *data)
{
    apr_file_t *f;
    const char *fname = "data/testbigfprintf.dat";
    char *to_write;
    int i;

    apr_file_remove(fname, p);

    APR_ASSERT_SUCCESS(tc, "open test file",
                       apr_file_open(&f, fname,
                                     APR_CREATE|APR_WRITE,
                                     APR_UREAD|APR_UWRITE, p));
    

    to_write = malloc(HUGE_STRING_LEN + 3);

    for (i = 0; i < HUGE_STRING_LEN + 1; ++i)
        to_write[i] = 'A' + i%26;

    strcpy(to_write + HUGE_STRING_LEN, "42");

    i = apr_file_printf(f, "%s", to_write);
    ABTS_INT_EQUAL(tc, HUGE_STRING_LEN + 2, i);

    apr_file_close(f);

    file_contents_equal(tc, fname, to_write, HUGE_STRING_LEN + 2);

    free(to_write);
}
예제 #17
0
파일: lock.c 프로젝트: jmckenna/mapcache
void mapcache_locker_disk_clear_all_locks(mapcache_context *ctx, mapcache_locker *self) {
  mapcache_locker_disk *ldisk = (mapcache_locker_disk*)self;
  apr_dir_t *lockdir;
  char errmsg[120];
  apr_finfo_t finfo;
  apr_status_t rv = apr_dir_open(&lockdir,ldisk->dir,ctx->pool);
  if(rv != APR_SUCCESS) {
    ctx->set_error(ctx,500, "failed to open lock directory %s: %s" ,ldisk->dir,apr_strerror(rv,errmsg,120));
    return;
  }

  while ((apr_dir_read(&finfo, APR_FINFO_DIRENT|APR_FINFO_TYPE|APR_FINFO_NAME, lockdir)) == APR_SUCCESS) {
    if(finfo.filetype == APR_REG) {
      if(!strncmp(finfo.name, MAPCACHE_LOCKFILE_PREFIX, strlen(MAPCACHE_LOCKFILE_PREFIX))) {
        ctx->log(ctx,MAPCACHE_WARN,"found old lockfile %s/%s, deleting it",ldisk->dir,
            finfo.name);
        rv = apr_file_remove(apr_psprintf(ctx->pool,"%s/%s",ldisk->dir, finfo.name),ctx->pool);
        if(rv != APR_SUCCESS) {
          ctx->set_error(ctx,500, "failed to remove lockfile %s: %s",finfo.name,apr_strerror(rv,errmsg,120));
          return;
        }

      }

    }
  }
  apr_dir_close(lockdir);
}
예제 #18
0
static apr_status_t file_cache_el_final(disk_cache_object_t *dobj,
                                        request_rec *r)
{
    /* move the data over */
    if (dobj->tfd) {
        apr_status_t rv;

        apr_file_close(dobj->tfd);

        /* This assumes that the tempfile is on the same file system
         * as the cache_root. If not, then we need a file copy/move
         * rather than a rename.
         */
        rv = apr_file_rename(dobj->tempfile, dobj->datafile, r->pool);
        if (rv != APR_SUCCESS) {
            ap_log_error(APLOG_MARK, APLOG_WARNING, rv, r->server,
                         "disk_cache: rename tempfile to datafile failed:"
                         " %s -> %s", dobj->tempfile, dobj->datafile);
            apr_file_remove(dobj->tempfile, r->pool);
        }

        dobj->tfd = NULL;
    }

    return APR_SUCCESS;
}
예제 #19
0
END_TEST

START_TEST(createCASCookie_test) {
  unsigned int i;
  char *path, *rv;
  char *ticket = "ST-ABCD";
  cas_cfg *c = ap_get_module_config(request->server->module_config,
                                    &auth_cas_module);
  c->CASCookiePath = "/tmp/";

  /* TODO(pames): const */
  rv = createCASCookie(request, "foo", NULL, ticket);

  path = apr_pstrcat(request->pool, c->CASCookiePath, rv, NULL);
  apr_file_remove(path, request->pool);

  for(i = 0; i < strlen(rv); i++) {
    if ((rv[i] < '0' || rv[i] > '9') &&
        (rv[i] < 'a' || rv[i] > 'f')) {
      fail();
    }
  }
  
  if (i != APR_MD5_DIGESTSIZE*2)
    fail();
}
예제 #20
0
static void
test_create_ouptput_stream(CuTest* tc)
{
    lcn_index_output_t *out;
    lcn_ram_file_t *file;

    {
        apr_pool_t *pool;
        LCN_TEST( apr_pool_create( &pool, main_pool ) );
        LCN_TEST( lcn_fs_index_output_create( &out, "test_file", pool ) );
        CuAssertStrEquals( tc, out->name, "test_file" );
        test_create_ostream_impl(tc, out );
        LCN_TEST( lcn_index_output_close( out ) );
        apr_file_remove( "test_file", pool );
        apr_pool_destroy( pool );
    }

    {
        apr_pool_t *ram_file_pool, *pool;
        LCN_TEST( apr_pool_create( &ram_file_pool, main_pool ) );
        LCN_TEST( lcn_ram_file_create( &file, ram_file_pool ) );

        {
            LCN_TEST( apr_pool_create( &pool, main_pool ) );
            LCN_TEST( lcn_ram_index_output_create( &out, file, pool ) );
            test_create_ostream_impl( tc, out );
            LCN_TEST( lcn_index_output_close( out ) );
            apr_pool_destroy( pool );
        }

        apr_pool_destroy( ram_file_pool );
    }
}
예제 #21
0
END_TEST

START_TEST(writeCASCacheEntry_test) {
  apr_file_t *f;
  cas_cache_entry cache;
  char *fname = "fedcba9876543210fedcba9876543210", *path;
  cas_cfg *c = ap_get_module_config(request->server->module_config,
                                    &auth_cas_module);
  c->CASCookiePath = "/tmp/";
 
  cache.user = "******";
  cache.issued = 86400;
  cache.lastactive = 87000;
  cache.path = "/bar";
  cache.ticket = "ST-4321";
  cache.attrs = NULL;

  writeCASCacheEntry(request, fname, &cache, FALSE);

  path = apr_pstrcat(request->pool, c->CASCookiePath, fname, NULL);
  fail_if(apr_file_open(&f, path, APR_READ, APR_OS_DEFAULT, request->pool) !=
          APR_SUCCESS);
  /* TODO(pames): verify file contents. */
  /* TODO(pames): test w/attributes */
  apr_file_close(f);
  apr_file_remove(path, request->pool);
}
예제 #22
0
/**
 * Remove the cache lock, if present.
 *
 * First, try to close the file handle, whose delete-on-close should
 * kill the file. Otherwise, just delete the file by name.
 *
 * If no lock name has yet been calculated, do the calculation of the
 * lock name first before trying to delete the file.
 *
 * If an optional bucket brigade is passed, the lock will only be
 * removed if the bucket brigade contains an EOS bucket.
 */
apr_status_t cache_remove_lock(cache_server_conf *conf,
        cache_request_rec *cache, request_rec *r, apr_bucket_brigade *bb)
{
    void *dummy;
    const char *lockname;

    if (!conf || !conf->lock || !conf->lockpath) {
        /* no locks configured, leave */
        return APR_SUCCESS;
    }
    if (bb) {
        apr_bucket *e;
        int eos_found = 0;
        for (e = APR_BRIGADE_FIRST(bb);
             e != APR_BRIGADE_SENTINEL(bb);
             e = APR_BUCKET_NEXT(e))
        {
            if (APR_BUCKET_IS_EOS(e)) {
                eos_found = 1;
                break;
            }
        }
        if (!eos_found) {
            /* no eos found in brigade, don't delete anything just yet,
             * we are not done.
             */
            return APR_SUCCESS;
        }
    }
    apr_pool_userdata_get(&dummy, CACHE_LOCKFILE_KEY, r->pool);
    if (dummy) {
        return apr_file_close((apr_file_t *)dummy);
    }
    apr_pool_userdata_get(&dummy, CACHE_LOCKNAME_KEY, r->pool);
    lockname = (const char *)dummy;
    if (!lockname) {
        char dir[5];

        /* create the key if it doesn't exist */
        if (!cache->key) {
            cache_generate_key(r, r->pool, &cache->key);
        }

        /* create a hashed filename from the key, and save it for later */
        lockname = ap_cache_generate_name(r->pool, 0, 0, cache->key);

        /* lock files represent discrete just-went-stale URLs "in flight", so
         * we support a simple two level directory structure, more is overkill.
         */
        dir[0] = '/';
        dir[1] = lockname[0];
        dir[2] = '/';
        dir[3] = lockname[1];
        dir[4] = 0;

        lockname = apr_pstrcat(r->pool, conf->lockpath, dir, "/", lockname, NULL);
    }
    return apr_file_remove(lockname, r->pool);
}
예제 #23
0
파일: testfile.c 프로젝트: XianliangJ/mtcp
static void link_existing(abts_case *tc, void *data)
{
    apr_status_t rv;

    rv = apr_file_link("data/file_datafile.txt", "data/file_datafile2.txt");
    apr_file_remove("data/file_datafile2.txt", p);
    ABTS_ASSERT(tc, "Couldn't create hardlink to file", rv == APR_SUCCESS);
}
예제 #24
0
파일: io_file.c 프로젝트: LuaDist/lua-apr
int lua_apr_file_remove(lua_State *L)
{
  apr_status_t status;
  const char *path;

  path = luaL_checkstring(L, 1);
  status = apr_file_remove(path, to_pool(L));

  return push_status(L, status);
}
예제 #25
0
파일: testfilecopy.c 프로젝트: cmjonze/apr
static void copy_over_existing(abts_case *tc, void *data)
{
    apr_status_t rv;
    
    /* make absolutely sure that the dest file doesn't exist. */
    apr_file_remove("data/file_copy.txt", p);
    
    /* This is a cheat.  I don't want to create a new file, so I just copy
     * one file, then I copy another.  If the second copy succeeds, then
     * this works.
     */
    copy_helper(tc, "data/file_datafile.txt", "data/file_copy.txt", 
                APR_FPROT_FILE_SOURCE_PERMS, 0, p);
    
    copy_helper(tc, "data/mmap_datafile.txt", "data/file_copy.txt", 
                APR_FPROT_FILE_SOURCE_PERMS, 0, p);
  
    rv = apr_file_remove("data/file_copy.txt", p);
    APR_ASSERT_SUCCESS(tc, "Couldn't remove copy file", rv);
}
예제 #26
0
static void
test_write_byte(CuTest* tc)
{
    lcn_index_input_t *in;
    lcn_ram_file_t *file;
    lcn_index_output_t *out;
    apr_pool_t *pool;
    unsigned char byte;

    {
        LCN_TEST( apr_pool_create( &pool, main_pool ) );
        LCN_TEST( lcn_fs_index_output_create( &out, "test_file", pool ) );
        LCN_TEST( lcn_index_output_write_byte( out, (unsigned char) 250 ) );
        LCN_TEST( lcn_index_output_close( out ) );
        apr_pool_destroy( pool );
    }

    {
        LCN_TEST( apr_pool_create( &pool, main_pool ) );
        LCN_TEST( lcn_index_input_create( &in, "test_file", pool ) );
        LCN_TEST( lcn_index_input_read_byte( in, &byte ) );
        CuAssertIntEquals(tc, byte, 250 );
        LCN_TEST( lcn_index_input_close( in ) );
        LCN_TEST( apr_file_remove( "test_file", pool ) );
        apr_pool_destroy( pool );
    }

    /* Test for RAMlcn_ostream_t implementation */
    {
        LCN_TEST( apr_pool_create( &pool, main_pool ) );
        LCN_TEST( lcn_ram_file_create( &file, pool ) );

        {
            apr_pool_t *os_pool;
            LCN_TEST( apr_pool_create( &os_pool, main_pool ) );
            LCN_TEST( lcn_ram_index_output_create( &out, file, os_pool ) );
            LCN_TEST( lcn_index_output_write_byte( out, (unsigned char) 250 ) );
            LCN_TEST( lcn_index_output_close( out ) );
            apr_pool_destroy( os_pool );
        }

        {
            apr_pool_t *is_pool;
            LCN_TEST( apr_pool_create( &is_pool, main_pool ) );
            LCN_TEST( lcn_ram_input_stream_create( &in, NULL, file, is_pool ) );
            LCN_TEST( lcn_index_input_read_byte(in, &byte ) );
            CuAssertIntEquals(tc, byte, 250 );
            LCN_TEST( lcn_index_input_close( in ) );
            apr_pool_destroy( is_pool );
        }

        apr_pool_destroy( pool );
    }
}
예제 #27
0
파일: testfile.c 프로젝트: kheradmand/Break
static void test_file_remove(CuTest *tc)
{
    apr_status_t rv;
    apr_file_t *filetest = NULL;

    rv = apr_file_remove(FILENAME, p);
    CuAssertIntEquals(tc, APR_SUCCESS, rv);

    rv = apr_file_open(&filetest, FILENAME, APR_READ, 
                       APR_UREAD | APR_UWRITE | APR_GREAD, p);
    CuAssertIntEquals(tc, 1, APR_STATUS_IS_ENOENT(rv));
}
예제 #28
0
파일: testfile.c 프로젝트: aptana/Jaxer
static void test_file_remove(abts_case *tc, void *data)
{
    apr_status_t rv;
    apr_file_t *filetest = NULL;

    rv = apr_file_remove(FILENAME, p);
    ABTS_INT_EQUAL(tc, APR_SUCCESS, rv);

    rv = apr_file_open(&filetest, FILENAME, APR_READ, 
                       APR_UREAD | APR_UWRITE | APR_GREAD, p);
    ABTS_INT_EQUAL(tc, 1, APR_STATUS_IS_ENOENT(rv));
}
예제 #29
0
static void
test_write_long(CuTest* tc)
{
    lcn_index_output_t *out;
    lcn_index_input_t *in;

    {
        apr_pool_t *pool;
        LCN_TEST( apr_pool_create( &pool, main_pool ) );
        LCN_TEST( lcn_fs_index_output_create( &out, "test_file_long", pool ) );
        test_write_vlong_write_impl( tc, lcn_index_output_write_vlong, out );
        LCN_TEST( lcn_index_output_close( out ) );
        apr_pool_destroy( pool );
    }

    {
        apr_pool_t *pool;
        LCN_TEST( apr_pool_create( &pool, main_pool ) );
        LCN_TEST( lcn_index_input_create( &in, "test_file_long", pool ) );
        test_write_vlong_read_impl( tc, lcn_index_input_read_vlong, in );
        LCN_TEST( lcn_index_input_close( in ) );
        LCN_TEST( apr_file_remove( "test_file_long", pool ) );
        apr_pool_destroy( pool );
    }

#if 0
    {
        apr_pool_t *pool;
        LCN_TEST( apr_pool_create( &pool, main_pool ) );
        LCN_TEST( lcn_ram_file_create( &file, pool ) );

        {
            apr_pool_t *os_pool;
            LCN_TEST( apr_pool_create( &os_pool, main_pool ) );
            LCN_TEST( lcn_ram_index_output_create( &out, file, os_pool ) );
            test_write_int_write_impl( lcn_index_output_write_int, out );
            LCN_TEST( lcn_index_output_close( out ) );
            apr_pool_destroy( os_pool );
        }

        {
            apr_pool_t *is_pool;
            LCN_TEST( apr_pool_create( &is_pool, main_pool ) );
            LCN_TEST( lcn_ram_input_stream_create( &in, file, is_pool ) );
            test_write_int_read_impl( lcn_index_input_read_int, in );
            LCN_TEST( lcn_index_input_close( in ) );
            apr_pool_destroy( is_pool );
        }

        apr_pool_destroy( pool );
    }
#endif
}
예제 #30
0
static void _mapcache_cache_disk_delete(mapcache_context *ctx, mapcache_tile *tile) {
   apr_status_t ret;
   char errmsg[120];
   char *filename;
   ((mapcache_cache_disk*)tile->tileset->cache)->tile_key(ctx, tile, &filename);
   GC_CHECK_ERROR(ctx);

   ret = apr_file_remove(filename,ctx->pool);
   if(ret != APR_SUCCESS && !APR_STATUS_IS_ENOENT(ret)) {
      ctx->set_error(ctx, 500,  "failed to remove file %s: %s",filename, apr_strerror(ret,errmsg,120));
   }
}