mirror of
https://github.com/s3fs-fuse/s3fs-fuse.git
synced 2024-12-23 09:18:55 +00:00
commit
0f503ced25
@ -21,6 +21,7 @@
|
|||||||
#ifndef S3FS_COMMON_H_
|
#ifndef S3FS_COMMON_H_
|
||||||
#define S3FS_COMMON_H_
|
#define S3FS_COMMON_H_
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
#include "../config.h"
|
#include "../config.h"
|
||||||
|
|
||||||
//
|
//
|
||||||
|
@ -2973,15 +2973,19 @@ static int set_xattrs_to_header(headers_t& meta, const char* name, const char* v
|
|||||||
|
|
||||||
headers_t::iterator iter;
|
headers_t::iterator iter;
|
||||||
if(meta.end() == (iter = meta.find("x-amz-meta-xattr"))){
|
if(meta.end() == (iter = meta.find("x-amz-meta-xattr"))){
|
||||||
|
#if defined(XATTR_REPLACE)
|
||||||
if(XATTR_REPLACE == (flags & XATTR_REPLACE)){
|
if(XATTR_REPLACE == (flags & XATTR_REPLACE)){
|
||||||
// there is no xattr header but flags is replace, so failure.
|
// there is no xattr header but flags is replace, so failure.
|
||||||
return -ENOATTR;
|
return -ENOATTR;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}else{
|
}else{
|
||||||
|
#if defined(XATTR_CREATE)
|
||||||
if(XATTR_CREATE == (flags & XATTR_CREATE)){
|
if(XATTR_CREATE == (flags & XATTR_CREATE)){
|
||||||
// found xattr header but flags is only creating, so failure.
|
// found xattr header but flags is only creating, so failure.
|
||||||
return -EEXIST;
|
return -EEXIST;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
strxattrs = iter->second;
|
strxattrs = iter->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -453,6 +453,7 @@ AutoLock::~AutoLock()
|
|||||||
string get_username(uid_t uid)
|
string get_username(uid_t uid)
|
||||||
{
|
{
|
||||||
static size_t maxlen = 0; // set once
|
static size_t maxlen = 0; // set once
|
||||||
|
int result;
|
||||||
char* pbuf;
|
char* pbuf;
|
||||||
struct passwd pwinfo;
|
struct passwd pwinfo;
|
||||||
struct passwd* ppwinfo = NULL;
|
struct passwd* ppwinfo = NULL;
|
||||||
@ -461,9 +462,17 @@ string get_username(uid_t uid)
|
|||||||
if(0 == maxlen){
|
if(0 == maxlen){
|
||||||
long res = sysconf(_SC_GETPW_R_SIZE_MAX);
|
long res = sysconf(_SC_GETPW_R_SIZE_MAX);
|
||||||
if(0 > res){
|
if(0 > res){
|
||||||
S3FS_PRN_WARN("could not get max pw length.");
|
// SUSv4tc1 says the following about _SC_GETGR_R_SIZE_MAX and
|
||||||
maxlen = 0;
|
// _SC_GETPW_R_SIZE_MAX:
|
||||||
return string("");
|
// Note that sysconf(_SC_GETGR_R_SIZE_MAX) may return -1 if
|
||||||
|
// there is no hard limit on the size of the buffer needed to
|
||||||
|
// store all the groups returned.
|
||||||
|
if (errno != 0){
|
||||||
|
S3FS_PRN_WARN("could not get max pw length.");
|
||||||
|
maxlen = 0;
|
||||||
|
return string("");
|
||||||
|
}
|
||||||
|
res = 1024; // default initial length
|
||||||
}
|
}
|
||||||
maxlen = res;
|
maxlen = res;
|
||||||
}
|
}
|
||||||
@ -471,12 +480,22 @@ string get_username(uid_t uid)
|
|||||||
S3FS_PRN_CRIT("failed to allocate memory.");
|
S3FS_PRN_CRIT("failed to allocate memory.");
|
||||||
return string("");
|
return string("");
|
||||||
}
|
}
|
||||||
// get group information
|
// get pw information
|
||||||
if(0 != getpwuid_r(uid, &pwinfo, pbuf, maxlen, &ppwinfo)){
|
while(ERANGE == (result = getpwuid_r(uid, &pwinfo, pbuf, maxlen, &ppwinfo))){
|
||||||
S3FS_PRN_WARN("could not get pw information.");
|
free(pbuf);
|
||||||
|
maxlen *= 2;
|
||||||
|
if(NULL == (pbuf = (char*)malloc(sizeof(char) * maxlen))){
|
||||||
|
S3FS_PRN_CRIT("failed to allocate memory.");
|
||||||
|
return string("");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(0 != result){
|
||||||
|
S3FS_PRN_ERR("could not get pw information(%d).", result);
|
||||||
free(pbuf);
|
free(pbuf);
|
||||||
return string("");
|
return string("");
|
||||||
}
|
}
|
||||||
|
|
||||||
// check pw
|
// check pw
|
||||||
if(NULL == ppwinfo){
|
if(NULL == ppwinfo){
|
||||||
free(pbuf);
|
free(pbuf);
|
||||||
@ -498,10 +517,18 @@ int is_uid_include_group(uid_t uid, gid_t gid)
|
|||||||
// make buffer
|
// make buffer
|
||||||
if(0 == maxlen){
|
if(0 == maxlen){
|
||||||
long res = sysconf(_SC_GETGR_R_SIZE_MAX);
|
long res = sysconf(_SC_GETGR_R_SIZE_MAX);
|
||||||
if(0 > res){
|
if(0 > res) {
|
||||||
S3FS_PRN_ERR("could not get max name length.");
|
// SUSv4tc1 says the following about _SC_GETGR_R_SIZE_MAX and
|
||||||
maxlen = 0;
|
// _SC_GETPW_R_SIZE_MAX:
|
||||||
return -ERANGE;
|
// Note that sysconf(_SC_GETGR_R_SIZE_MAX) may return -1 if
|
||||||
|
// there is no hard limit on the size of the buffer needed to
|
||||||
|
// store all the groups returned.
|
||||||
|
if (errno != 0) {
|
||||||
|
S3FS_PRN_ERR("could not get max name length.");
|
||||||
|
maxlen = 0;
|
||||||
|
return -ERANGE;
|
||||||
|
}
|
||||||
|
res = 1024; // default initial length
|
||||||
}
|
}
|
||||||
maxlen = res;
|
maxlen = res;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user