mirror of
https://github.com/s3fs-fuse/s3fs-fuse.git
synced 2024-12-23 01:08:54 +00:00
commit
0f503ced25
@ -21,6 +21,7 @@
|
||||
#ifndef S3FS_COMMON_H_
|
||||
#define S3FS_COMMON_H_
|
||||
|
||||
#include <stdlib.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;
|
||||
if(meta.end() == (iter = meta.find("x-amz-meta-xattr"))){
|
||||
#if defined(XATTR_REPLACE)
|
||||
if(XATTR_REPLACE == (flags & XATTR_REPLACE)){
|
||||
// there is no xattr header but flags is replace, so failure.
|
||||
return -ENOATTR;
|
||||
}
|
||||
#endif
|
||||
}else{
|
||||
#if defined(XATTR_CREATE)
|
||||
if(XATTR_CREATE == (flags & XATTR_CREATE)){
|
||||
// found xattr header but flags is only creating, so failure.
|
||||
return -EEXIST;
|
||||
}
|
||||
#endif
|
||||
strxattrs = iter->second;
|
||||
}
|
||||
|
||||
|
@ -453,6 +453,7 @@ AutoLock::~AutoLock()
|
||||
string get_username(uid_t uid)
|
||||
{
|
||||
static size_t maxlen = 0; // set once
|
||||
int result;
|
||||
char* pbuf;
|
||||
struct passwd pwinfo;
|
||||
struct passwd* ppwinfo = NULL;
|
||||
@ -461,22 +462,40 @@ string get_username(uid_t uid)
|
||||
if(0 == maxlen){
|
||||
long res = sysconf(_SC_GETPW_R_SIZE_MAX);
|
||||
if(0 > res){
|
||||
// SUSv4tc1 says the following about _SC_GETGR_R_SIZE_MAX and
|
||||
// _SC_GETPW_R_SIZE_MAX:
|
||||
// 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;
|
||||
}
|
||||
if(NULL == (pbuf = (char*)malloc(sizeof(char) * maxlen))){
|
||||
S3FS_PRN_CRIT("failed to allocate memory.");
|
||||
return string("");
|
||||
}
|
||||
// get group information
|
||||
if(0 != getpwuid_r(uid, &pwinfo, pbuf, maxlen, &ppwinfo)){
|
||||
S3FS_PRN_WARN("could not get pw information.");
|
||||
// get pw information
|
||||
while(ERANGE == (result = getpwuid_r(uid, &pwinfo, pbuf, maxlen, &ppwinfo))){
|
||||
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);
|
||||
return string("");
|
||||
}
|
||||
|
||||
// check pw
|
||||
if(NULL == ppwinfo){
|
||||
free(pbuf);
|
||||
@ -498,11 +517,19 @@ int is_uid_include_group(uid_t uid, gid_t gid)
|
||||
// make buffer
|
||||
if(0 == maxlen){
|
||||
long res = sysconf(_SC_GETGR_R_SIZE_MAX);
|
||||
if(0 > res){
|
||||
if(0 > res) {
|
||||
// SUSv4tc1 says the following about _SC_GETGR_R_SIZE_MAX and
|
||||
// _SC_GETPW_R_SIZE_MAX:
|
||||
// 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;
|
||||
}
|
||||
if(NULL == (pbuf = (char*)malloc(sizeof(char) * maxlen))){
|
||||
|
Loading…
Reference in New Issue
Block a user