Project

General

Profile

Bug #12617 ยป Client.cc.diff

Burkhard Linke, 08/05/2015 02:27 PM

View differences:

src/client/Client.cc
#include <fcntl.h>
#include <sys/utsname.h>
#include <sys/uio.h>
#include <grp.h>
#include <pwd.h>
#if defined(__linux__)
#include <linux/falloc.h>
......
int Client::check_permissions(Inode *in, int flags, int uid, int gid)
{
// initial number of group entries, defaults to posix standard of 16
// PAM implementations may provide more than 16 groups...
int initial_group_count = 16;
gid_t *sgids = NULL;
int sgid_count = 0;
if (getgroups_cb) {
......
return sgid_count;
}
}
else {
// use PAM to get the group list
sgid_count = initial_group_count;
sgids = (gid_t*)malloc (sgid_count * sizeof(gid_t));
if (sgids == NULL) {
ldout(cct, 3) << "allocating group memory failed!" << dendl;
return -EACCES;
}
struct passwd *pw;
pw = getpwuid(uid);
if (pw == NULL) {
ldout(cct, 3) << "getting user name failed!" << dendl;
return -EACCES;
}
while(1) {
if (getgrouplist(pw->pw_name, gid, sgids, &sgid_count) == -1) {
// we need to resize the group list and try again
sgids = (gid_t*)realloc(sgids, sgid_count * sizeof(gid_t));
continue;
}
// list was successfully retrieved
break;
}
}
// check permissions before doing anything else
int ret = 0;
if (uid != 0 && !in->check_mode(uid, gid, sgids, sgid_count, flags)) {
return -EACCES;
ret = -EACCES;
}
return 0;
// free group list
free (sgids);
return ret;
}
vinodeno_t Client::_get_vino(Inode *in)
    (1-1/1)