Skip to content

Commit

Permalink
client: plumb a mask argument into _lookup
Browse files Browse the repository at this point in the history
...and attempt to pass in a sane value there, based on what we'll do
with the resulting inode.

Signed-off-by: Jeff Layton <[email protected]>
  • Loading branch information
jtlayton committed Aug 2, 2016
1 parent a2ce16f commit f3605d3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
29 changes: 16 additions & 13 deletions src/client/Client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5208,7 +5208,7 @@ int Client::may_delete(Inode *dir, const char *name, int uid, int gid)
/* 'name == NULL' means rmsnap */
if (uid != 0 && name && (dir->mode & S_ISVTX)) {
InodeRef otherin;
r = _lookup(dir, name, &otherin, uid, gid);
r = _lookup(dir, name, CEPH_CAP_AUTH_SHARED, &otherin, uid, gid);
if (r < 0)
goto out;
if (dir->uid != (uid_t)uid && otherin->uid != (uid_t)uid)
Expand Down Expand Up @@ -5897,8 +5897,8 @@ int Client::_do_lookup(Inode *dir, const string& name, int mask, InodeRef *targe
return r;
}

int Client::_lookup(Inode *dir, const string& dname, InodeRef *target,
int uid, int gid)
int Client::_lookup(Inode *dir, const string& dname, int mask,
InodeRef *target, int uid, int gid)
{
int r = 0;
Dentry *dn = NULL;
Expand Down Expand Up @@ -5979,7 +5979,7 @@ int Client::_lookup(Inode *dir, const string& dname, InodeRef *target,
}
}

r = _do_lookup(dir, dname, 0, target, uid, gid);
r = _do_lookup(dir, dname, mask, target, uid, gid);
goto done;

hit_dn:
Expand Down Expand Up @@ -6049,6 +6049,7 @@ int Client::path_walk(const filepath& origpath, InodeRef *end, bool followsym,
ldout(cct, 10) << "path_walk " << path << dendl;

int symlinks = 0;
int caps = 0;

unsigned i=0;
while (i < path.depth() && cur) {
Expand All @@ -6060,8 +6061,9 @@ int Client::path_walk(const filepath& origpath, InodeRef *end, bool followsym,
int r = may_lookup(cur.get(), uid, gid);
if (r < 0)
return r;
caps = CEPH_CAP_AUTH_SHARED;
}
int r = _lookup(cur.get(), dname, &next, uid, gid);
int r = _lookup(cur.get(), dname, caps, &next, uid, gid);
if (r < 0)
return r;
// only follow trailing symlink if followsym. always follow
Expand Down Expand Up @@ -6245,16 +6247,17 @@ int Client::mkdirs(const char *relpath, mode_t mode)
//get through existing parts of path
filepath path(relpath);
unsigned int i;
int r=0;
int r = 0, caps = 0;
InodeRef cur, next;
cur = cwd;
for (i=0; i<path.depth(); ++i) {
if (cct->_conf->client_permissions) {
r = may_lookup(cur.get(), uid, gid);
if (r < 0)
break;
caps = CEPH_CAP_AUTH_SHARED;
}
r = _lookup(cur.get(), path[i].c_str(), &next, uid, gid);
r = _lookup(cur.get(), path[i].c_str(), caps, &next, uid, gid);
if (r < 0)
break;
cur.swap(next);
Expand Down Expand Up @@ -9522,7 +9525,7 @@ int Client::ll_lookup(Inode *parent, const char *name, struct stat *attr,
string dname(name);
InodeRef in;

r = _lookup(parent, dname, &in, uid, gid);
r = _lookup(parent, dname, CEPH_STAT_CAP_INODE_ALL, &in, uid, gid);
if (r < 0) {
attr->st_ino = 0;
goto out;
Expand Down Expand Up @@ -10850,7 +10853,7 @@ int Client::_unlink(Inode *dir, const char *name, int uid, int gid)
req->dentry_drop = CEPH_CAP_FILE_SHARED;
req->dentry_unless = CEPH_CAP_FILE_EXCL;

res = _lookup(dir, name, &otherin, uid, gid);
res = _lookup(dir, name, 0, &otherin, uid, gid);
if (res < 0)
goto fail;
req->set_other_inode(otherin.get());
Expand Down Expand Up @@ -10913,7 +10916,7 @@ int Client::_rmdir(Inode *dir, const char *name, int uid, int gid)
int res = get_or_create(dir, name, &de);
if (res < 0)
goto fail;
res = _lookup(dir, name, &in, uid, gid);
res = _lookup(dir, name, 0, &in, uid, gid);
if (res < 0)
goto fail;
if (req->get_op() == CEPH_MDS_OP_RMDIR) {
Expand Down Expand Up @@ -11010,13 +11013,13 @@ int Client::_rename(Inode *fromdir, const char *fromname, Inode *todir, const ch
req->dentry_unless = CEPH_CAP_FILE_EXCL;

InodeRef oldin, otherin;
res = _lookup(fromdir, fromname, &oldin, uid, gid);
res = _lookup(fromdir, fromname, 0, &oldin, uid, gid);
if (res < 0)
goto fail;
req->set_old_inode(oldin.get());
req->old_inode_drop = CEPH_CAP_LINK_SHARED;

res = _lookup(todir, toname, &otherin, uid, gid);
res = _lookup(todir, toname, 0, &otherin, uid, gid);
if (res != 0 && res != -ENOENT) {
goto fail;
} else if (res == 0) {
Expand Down Expand Up @@ -11352,7 +11355,7 @@ int Client::ll_create(Inode *parent, const char *name, mode_t mode,

bool created = false;
InodeRef in;
int r = _lookup(parent, name, &in, uid, gid);
int r = _lookup(parent, name, CEPH_STAT_CAP_INODE_ALL, &in, uid, gid);

if (r == 0 && (flags & O_CREAT) && (flags & O_EXCL))
return -EEXIST;
Expand Down
2 changes: 1 addition & 1 deletion src/client/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -751,7 +751,7 @@ class Client : public Dispatcher, public md_config_obs_t {
// internal interface
// call these with client_lock held!
int _do_lookup(Inode *dir, const string& name, int mask, InodeRef *target, int uid, int gid);
int _lookup(Inode *dir, const string& dname, InodeRef *target, int uid, int gid);
int _lookup(Inode *dir, const string& dname, int mask, InodeRef *target, int uid, int gid);

int _link(Inode *in, Inode *dir, const char *name, int uid=-1, int gid=-1, InodeRef *inp = 0);
int _unlink(Inode *dir, const char *name, int uid=-1, int gid=-1);
Expand Down

0 comments on commit f3605d3

Please sign in to comment.