static int owner_modify(void) { char *tmp; ne_propname pname = { "http://webdav.org/neon/litmus/", "random" }; ne_proppatch_operation pops[] = { { NULL, ne_propset, "foobar" }, { NULL } }; PRECOND(gotlock); ONV(ne_put(i_session, res, i_foo_fd), ("PUT on locked resource failed: %s", ne_get_error(i_session))); tmp = ne_concat(i_path, "whocares", NULL); ONN("COPY of locked resource", ne_copy(i_session, 1, NE_DEPTH_ZERO, res, tmp) == NE_ERROR); if (STATUS(201)) t_warning("COPY failed with %d not 201", GETSTATUS); ONN("DELETE of locked resource by owner", ne_delete(i_session, tmp) == NE_ERROR); if (STATUS(204)) t_warning("DELETE of %s failed with %d not 200", tmp, GETSTATUS); free(tmp); ONN("PROPPATCH of locked resource", ne_proppatch(i_session, res, pops) == NE_ERROR); if (STATUS(207)) t_warning("PROPPATCH failed with %d", GETSTATUS); return OK; }
void my_mkcol2_proppatch(char* uri, int depth, const ne_propname pops[]) { char tmp[256] = "/tmp/Davtest-XXXXXX"; char myuri[128]; int i, fd; if ( (fd=mkstemp(tmp)) < 0){ perror("mkstemp() :"); return ; } for( i=0; i<4; i++) write(fd, tmp, sizeof(tmp)); if ( depth > 1){ memset(myuri, 0, sizeof(myuri)); strcpy( myuri, uri); sprintf( myuri, "%ssub/", myuri); ONV(ne_mkcol(i_session, myuri), ("MKCOL %s: %s", myuri, ne_get_error(i_session))); ONMREQ("PROPPATCH",myuri, ne_proppatch(i_session, myuri, pops)); my_mkcol2( myuri, depth-1); }else if ( depth == 1) for ( i=0; i<pget_option.width; i++){ memset(myuri, 0, sizeof(myuri)); strcpy( myuri, uri); sprintf( myuri, "%sfile%d", myuri, i); ONV(ne_put(i_session, myuri, fd), ("PUT of %s: %s", myuri, ne_get_error(i_session))); } return; }
int upload_foo(const char *path) { char *uri = ne_concat(i_path, path, NULL); int ret; /* i_foo_fd is rewound automagically by ne_request.c */ ret = ne_put(i_session, uri, i_foo_fd); free(uri); if (ret) t_context("PUT of `%s': %s", uri, ne_get_error(i_session)); return ret; }
static int notowner_modify(void) { char *tmp; ne_propname pname = { "http://webdav.org/neon/litmus/", "random" }; ne_proppatch_operation pops[] = { { NULL, ne_propset, "foobar" }, { NULL } }; PRECOND(gotlock); pops[0].name = &pname; ONN("DELETE of locked resource should fail", ne_delete(i_session2, res) != NE_ERROR); if (STATUS2(423)) t_warning("DELETE failed with %d not 423", GETSTATUS2); tmp = ne_concat(i_path, "whocares", NULL); ONN("MOVE of locked resource should fail", ne_move(i_session2, 0, res, tmp) != NE_ERROR); free(tmp); if (STATUS2(423)) t_warning("MOVE failed with %d not 423", GETSTATUS2); ONN("COPY onto locked resource should fail", ne_copy(i_session2, 1, NE_DEPTH_ZERO, res2, res) != NE_ERROR); if (STATUS2(423)) t_warning("COPY failed with %d not 423", GETSTATUS2); ONN("PROPPATCH of locked resource should fail", ne_proppatch(i_session2, res, pops) != NE_ERROR); if (STATUS2(423)) t_warning("PROPPATCH failed with %d not 423", GETSTATUS2); ONN("PUT on locked resource should fail", ne_put(i_session2, res, i_foo_fd) != NE_ERROR); if (STATUS2(423)) t_warning("PUT failed with %d not 423", GETSTATUS2); return OK; }
static void put_file(const char *remote_path, const char *fname) { int fd, ret; /* * get fd for src file & put */ fd = do_open(fname); ret = ne_put(session.sess, remote_path, fd); if (ret != NE_OK) { printf("%s\n", remote_path); out_result(ret); quit(1); } count++; }
/* * create a hierarchy of 10 levels deep, NBOTTOM files at bottom level */ void my_mkcol2(char* uri, int depth) { char tmp[256] = "/tmp/Davtest-XXXXXX"; char myuri[128]; int i, fd; if ( (fd=mkstemp(tmp)) < 0){ perror("mkstemp() :"); return ; } for( i=0; i<4; i++) write(fd, tmp, sizeof(tmp)); if ( depth > 1){ memset(myuri, 0, sizeof(myuri)); strcpy( myuri, uri); sprintf( myuri, "%ssub/", myuri); if (ne_mkcol(i_session, myuri)){ printf("ne_mkcol failed\n"); return; } # Return error if myuri + "sub/" is > 128 if (strlen(myuri) >= sizeof(myuri) - 4) { printf("\nERROR: max depth reached.\n"); exit(1); } else { my_mkcol2( myuri, depth-1); } }else if ( depth == 1) for ( i=0; i<pget_option.width; i++){ memset(myuri, 0, sizeof(myuri)); strcpy( myuri, uri); sprintf( myuri, "%sfile%d", myuri, i); if (ne_put(i_session, myuri, fd)){ printf("ne_put failed\n"); return; } } unlink(tmp); return; }
static int owner_modify(void) { PRECOND(gotlock); ne_proppatch_operation pops[] = { { NULL, ne_propset, "foobar" }, { NULL } }; const ne_propname pname = { "http://webdav.org/neon/litmus/", "random" }; pops[0].name = &pname; ONV(ne_put(i_session, res, i_foo_fd), ("PUT on locked resource failed: %s", ne_get_error(i_session))); ONMREQ("PROPPATCH on locked resouce", res, ne_proppatch(i_session, res, pops)); return OK; }
/* TODO: does this work under cygwin? mkstemp() may or may not open the file using O_BINARY, and then we *do* upload it using O_BINARY, so maybe this will screw things up. Maybe we should fcntl it and set O_BINARY, if that is allowed under cygwin? */ void execute_edit(const char *remote) { char *real_remote; unsigned int can_lock; /* can we LOCK it? */ struct ne_lock *lock = NULL; char fname[PATH_MAX] = "/tmp/cadaver-edit-XXXXXX"; const char *pnt; int fd; int is_checkout, is_checkin; real_remote = resolve_path(session.uri.path, remote, false); /* Don't let them edit a collection, since PUT to a collection is * bogus. Really we want to be able to fetch a "DefaultDocument" * property, and edit on that instead: IIS does expose such a * property. Would be a nice hack to add the support to mod_dav * too. */ if (getrestype(real_remote) == resr_collection) { printf(_("You cannot edit a collection resource (%s).\n"), real_remote); goto edit_bail; } can_lock = is_lockable(real_remote); /* Give the local temp file the same extension as the remote path, * so the editor can have a stab at the content-type. */ pnt = strrchr(real_remote, '.'); if (pnt != NULL && strchr(pnt, '/') == NULL) { strncat(fname, pnt, PATH_MAX); fname[PATH_MAX-1] = '\0'; } fd = cad_mkstemp(fname); if (fd == -1) { printf(_("Could not create temporary file %s:\n%s\n"), fname, strerror(errno)); goto edit_bail; } /* Sanity check on the file perms. */ #ifdef HAVE_FCHMOD if (fchmod(fd, 0600) == -1) { #else if (chmod(fname, 0600) == -1) { #endif printf(_("Could not set file permissions for %s:\n%s\n"), fname, strerror(errno)); goto edit_bail; } if (can_lock) { lock = ne_lock_create(); ne_fill_server_uri(session.sess, &lock->uri); lock->uri.path = ne_strdup(real_remote); lock->owner = getowner(); out_start("Locking", remote); if (out_handle(ne_lock(session.sess, lock))) { ne_lockstore_add(session.locks, lock); } else { ne_lock_destroy(lock); goto edit_close; } } else { /* TODO: HEAD and get the Etag/modtime */ } /* Return 1: Checkin, 2: Checkout, 0: otherwise */ is_checkin = is_vcr(real_remote); if (is_checkin==1) { execute_checkout(real_remote); } output(o_download, _("Downloading `%s' to %s"), real_remote, fname); /* Don't puke if get fails -- perhaps we are creating a new one? */ out_result(ne_get(session.sess, real_remote, fd)); if (close(fd)) { output(o_finish, _("Error writing to temporary file: %s\n"), strerror(errno)); } else if (!run_editor(fname)) { int upload_okay = 0; fd = open(fname, O_RDONLY | OPEN_BINARY_FLAGS); if (fd < 0) { output(o_finish, _("Could not re-open temporary file: %s\n"), strerror(errno)); } else { do { output(o_upload, _("Uploading changes to `%s'"), real_remote); /* FIXME: conditional PUT using fetched Etag/modtime if * !can_lock */ if (out_handle(ne_put(session.sess, real_remote, fd))) { upload_okay = 1; } else { /* TODO: offer to save locally instead */ printf(_("Try uploading again (y/n)? ")); if (!yesno()) { upload_okay = 1; } } } while (!upload_okay); close(fd); } } if (unlink(fname)) { printf(_("Could not delete temporary file %s:\n%s\n"), fname, strerror(errno)); } /* Return 1: Checkin, 2: Checkout, 0: otherwise */ is_checkout = is_vcr(real_remote); if (is_checkout==2) { execute_checkin(real_remote); } /* UNLOCK it again whether we succeed or failed in our mission */ if (can_lock) { output(o_start, "Unlocking `%s':", remote); out_result(ne_unlock(session.sess, lock)); ne_lockstore_remove(session.locks, lock); ne_lock_destroy(lock); } goto edit_bail; edit_close: close(fd); edit_bail: free(real_remote); return; }
static int lock_on_no_file(void) { char *tmp; res = ne_concat(i_path, "locknullfile", NULL); tmp = ne_concat(i_path, "whocares", NULL); getlock(ne_lockscope_exclusive, NE_DEPTH_ZERO); if (STATUS(200)) t_warning("Lock Null failed with %d not 200", GETSTATUS); //FIXME: After Lock Null is created, Do Unlock it to maintain integrity of tests //ONNREQ2("unlock of second shared lock",ne_unlock(i_session, &gotlock)); // Copy of nulllock resource ONN("COPY null locked resource should ", ne_copy(i_session, 1, NE_DEPTH_ZERO, res, tmp) == NE_ERROR); // Delete of nulllockresource ONN("DELETE of locknull resource by owner", ne_delete(i_session, tmp) == NE_ERROR); free(tmp); // Move of nulllockresource tmp = ne_concat(i_path, "who-cares", NULL); ONN("MOVE of null-locked resource", ne_move(i_session, 0, res, tmp) == NE_ERROR); ONN("DELETE of locknull resource by owner after a MOVE with overwrite (F)", ne_delete(i_session, tmp) == NE_ERROR); /* Delete the locktoken from store */ ne_lockstore_remove(store, gotlock); getlock(ne_lockscope_exclusive, NE_DEPTH_ZERO); if (STATUS(200)) t_warning("Lock Null failed with %d not 200", GETSTATUS); /* Lot of code duplication, but want to test each case individually. * Locknull resource. How it behaves when it is copied * moved (with overwrite T/F) * PUT request on locknullresource should succeed. */ /*MOVE of null-locked resource with overwrite=T */ ONN("MOVE of null-locked resource with overwrite=T (1)", ne_move(i_session, 1, res, tmp) == NE_ERROR); ne_lockstore_remove(store, gotlock); getlock(ne_lockscope_exclusive, NE_DEPTH_ZERO); if (STATUS(200)) t_warning("Lock Null failed with %d not 200", GETSTATUS); ONN("MOVE of null-locked resource with overwrite=T (2)", ne_move(i_session, 1, res, tmp) == NE_ERROR); ne_lockstore_remove(store, gotlock); getlock(ne_lockscope_shared, NE_DEPTH_ZERO); if (STATUS(200)) t_warning("Lock Null failed with %d not 200", GETSTATUS); ONN("COPY on null-locked resource with overwrite=T", ne_copy(i_session, 1, NE_DEPTH_ZERO, tmp, res) == NE_ERROR); ONN("DELETE of locknull resource by owner after a MOVE (T) ", ne_delete(i_session, tmp) == NE_ERROR); free(tmp); // Put on nulllockresource ONV(ne_put(i_session,res, i_foo_fd), ("PUT on locknullfile resource failed: %s", ne_get_error(i_session))); return OK; }