return r;
}
-int Client::unlink(const char *relpath)
+int Client::unlink(const char *relpath, const UserPerm& perm)
{
Mutex::Locker lock(client_lock);
tout(cct) << "unlink" << std::endl;
string name = path.last_dentry();
path.pop_dentry();
InodeRef dir;
- int r = path_walk(path, &dir);
+ int r = path_walk(path, &dir, perm);
if (r < 0)
return r;
if (cct->_conf->client_permissions) {
- r = may_delete(dir.get(), name.c_str());
+ r = may_delete(dir.get(), name.c_str(), perm);
if (r < 0)
return r;
}
- return _unlink(dir.get(), name.c_str());
+ return _unlink(dir.get(), name.c_str(), perm);
}
int Client::rename(const char *relfrom, const char *relto)
return r;
}
-int Client::_unlink(Inode *dir, const char *name, int uid, int gid)
+int Client::_unlink(Inode *dir, const char *name, const UserPerm& perm)
{
- ldout(cct, 3) << "_unlink(" << dir->ino << " " << name << " uid " << uid << " gid " << gid << ")" << dendl;
+ ldout(cct, 3) << "_unlink(" << dir->ino << " " << name
+ << " uid " << perm.uid() << " gid " << perm.gid()
+ << ")" << dendl;
if (dir->snapid != CEPH_NOSNAP) {
return -EROFS;
req->dentry_drop = CEPH_CAP_FILE_SHARED;
req->dentry_unless = CEPH_CAP_FILE_EXCL;
- res = _lookup(dir, name, 0, &otherin, uid, gid);
+ res = _lookup(dir, name, 0, &otherin, perm);
if (res < 0)
goto fail;
req->set_other_inode(otherin.get());
req->set_inode(dir);
- res = make_request(req, uid, gid);
+ res = make_request(req, perm);
trim_cache();
ldout(cct, 3) << "unlink(" << path << ") = " << res << dendl;
return res;
}
-int Client::ll_unlink(Inode *in, const char *name, int uid, int gid)
+int Client::ll_unlink(Inode *in, const char *name, const UserPerm& perm)
{
Mutex::Locker lock(client_lock);
tout(cct) << name << std::endl;
if (!cct->_conf->fuse_default_permissions) {
- int r = may_delete(in, name, uid, gid);
+ int r = may_delete(in, name, perm);
if (r < 0)
return r;
}
- return _unlink(in, name, uid, gid);
+ return _unlink(in, name, perm);
}
int Client::_rmdir(Inode *dir, const char *name, int uid, int gid)
int _link(Inode *in, Inode *dir, const char *name, const UserPerm& perm,
InodeRef *inp = 0);
- int _unlink(Inode *dir, const char *name, int uid=-1, int gid=-1);
+ int _unlink(Inode *dir, const char *name, const UserPerm& perm);
int _rename(Inode *olddir, const char *oname, Inode *ndir, const char *nname, int uid=-1, int gid=-1);
int _mkdir(Inode *dir, const char *name, mode_t mode, int uid=-1, int gid=-1, InodeRef *inp = 0);
int _rmdir(Inode *dir, const char *name, int uid=-1, int gid=-1);
void seekdir(dir_result_t *dirp, loff_t offset);
int link(const char *existing, const char *newname, const UserPerm& perm);
- int unlink(const char *path);
+ int unlink(const char *path, const UserPerm& perm);
int rename(const char *from, const char *to);
// dirs
Inode **out, int uid = -1, int gid = -1);
int ll_symlink(Inode *in, const char *name, const char *value,
struct stat *attr, Inode **out, int uid = -1, int gid = -1);
- int ll_unlink(Inode *in, const char *name, int uid = -1, int gid = -1);
+ int ll_unlink(Inode *in, const char *name, const UserPerm& perm);
int ll_rmdir(Inode *in, const char *name, int uid = -1, int gid = -1);
int ll_rename(Inode *parent, const char *name, Inode *newparent,
const char *newname, int uid = -1, int gid = -1);
client->link(a, b, perms);
} else if (strcmp(op, "unlink") == 0) {
const char *a = t.get_string(buf, p);
- client->unlink(a);
+ client->unlink(a, perms);
} else if (strcmp(op, "rename") == 0) {
const char *a = t.get_string(buf, p);
const char *b = t.get_string(buf2, p);
const char *n = t.get_string(buf, p);
if (ll_inos.count(i)) {
i1 = client->ll_get_inode(vinodeno_t(ll_inos[i],CEPH_NOSNAP));
- client->ll_unlink(i1, n);
+ client->ll_unlink(i1, n, perms);
client->ll_put(i1);
}
} else if (strcmp(op, "ll_rmdir") == 0) {
clean_dir(file);
client->rmdir(file.c_str());
} else {
- client->unlink(file.c_str());
+ client->unlink(file.c_str(), perms);
}
}
{
int whoami = client->get_nodeid().v;
char d[255];
+ UserPerm perms = client->pick_my_perms();
if (priv) {
for (int c=0; c<count; c++) {
if (more) {
client->lstat(d, &st);
int fd = client->open(d, O_RDONLY);
- client->unlink(d);
+ client->unlink(d, perms);
client->close(fd);
}
{
// files
char d[255];
+ UserPerm perms = client->pick_my_perms();
for (int c=0; c<count; c++) {
// open
list<int> fds;
if (false && client->get_nodeid() == 0)
for (int n=0; n<num; n++) {
snprintf(d, sizeof(d), "test/file.%d", n);
- client->unlink(d);
+ client->unlink(d, perms);
}
while (!fds.empty()) {
int SyntheticClient::rm_file(string& fn)
{
- return client->unlink(fn.c_str());
+ UserPerm perms = client->pick_my_perms();
+ return client->unlink(fn.c_str(), perms);
}
int SyntheticClient::write_file(string& fn, int size, loff_t wrsize) // size is in MB, wrsize in bytes
if (contents.empty())
op = CEPH_MDS_OP_READDIR;
else
- r = client->unlink( get_random_sub() ); // will fail on dirs
+ r = client->unlink(get_random_sub(), perms); // will fail on dirs
}
if (op == CEPH_MDS_OP_RENAME) {
}
for (int i=0; i<10; i++) {
snprintf(b, sizeof(b), "/b/%d", i);
- client->unlink(b);
+ client->unlink(b, perms);
}
}
return;
// bug1.cpp
const char *fn = "blah";
char buffer[8192];
- client->unlink(fn);
+ client->unlink(fn, perms);
int handle = client->open(fn,O_CREAT|O_RDWR,S_IRWXU);
assert(handle>=0);
int r=client->write(handle,buffer,8192);
char dst[80];
snprintf(src, sizeof(src), "syn.0.0/dir.%d/dir.%d/file.%d", a, b, c);
snprintf(dst, sizeof(dst), "syn.0.0/dir.%d/dir.%d/newlink.%d", d, e, f);
- client->unlink(dst);
+ client->unlink(dst, perms);
}
// unlink fun
client->mknod("a", 0644);
- client->unlink("a");
+ client->unlink("a", perms);
client->mknod("b", 0644);
client->link("b", "c", perms);
- client->unlink("c");
+ client->unlink("c", perms);
client->mkdir("d", 0755);
- client->unlink("d");
+ client->unlink("d", perms);
client->rmdir("d");
// rename fun
break;
case 1:
client->mknod(src.c_str(), 0755);
- client->unlink(dst.c_str());
+ client->unlink(dst.c_str(), perms);
client->link(src.c_str(), dst.c_str(), perms);
break;
- case 2: client->unlink(src.c_str()); break;
- case 3: client->unlink(dst.c_str()); break;
+ case 2: client->unlink(src.c_str(), perms); break;
+ case 3: client->unlink(dst.c_str(), perms); break;
//case 4: client->mknod(src.c_str(), 0755); break;
//case 5: client->mknod(dst.c_str(), 0755); break;
}
CephFuse::Handle *cfuse = fuse_ll_req_prepare(req);
const struct fuse_ctx *ctx = fuse_req_ctx(req);
Inode *in = cfuse->iget(parent);
+ UserPerm perm(ctx->uid, ctx->gid);
- int r = cfuse->client->ll_unlink(in, name, ctx->uid, ctx->gid);
+ int r = cfuse->client->ll_unlink(in, name, perm);
fuse_reply_err(req, -r);
cfuse->iput(in); // iput required
{
if (!cmount->is_mounted())
return -ENOTCONN;
- return cmount->get_client()->unlink(path);
+ UserPerm perms = cmount->get_client()->pick_my_perms();
+ return cmount->get_client()->unlink(path, perms);
}
extern "C" int ceph_rename(struct ceph_mount_info *cmount, const char *from,
Inode *in, const char *name,
int uid, int gid)
{
- return (cmount->get_client()->ll_unlink(in, name, uid, gid));
+ UserPerm perms(uid, gid);
+ return (cmount->get_client()->ll_unlink(in, name, perms));
}
extern "C" int ceph_ll_statfs(class ceph_mount_info *cmount,