diff --git a/src/common.h b/src/common.h index d996c37..c141774 100644 --- a/src/common.h +++ b/src/common.h @@ -21,6 +21,7 @@ #ifndef S3FS_COMMON_H_ #define S3FS_COMMON_H_ +#include #include "../config.h" // diff --git a/src/s3fs.cpp b/src/s3fs.cpp index d2562a6..981e973 100644 --- a/src/s3fs.cpp +++ b/src/s3fs.cpp @@ -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; } diff --git a/src/s3fs_util.cpp b/src/s3fs_util.cpp index 9ebff28..c9984b1 100644 --- a/src/s3fs_util.cpp +++ b/src/s3fs_util.cpp @@ -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,9 +462,17 @@ string get_username(uid_t uid) if(0 == maxlen){ long res = sysconf(_SC_GETPW_R_SIZE_MAX); if(0 > res){ - S3FS_PRN_WARN("could not get max pw length."); - maxlen = 0; - return string(""); + // 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; } @@ -471,12 +480,22 @@ string get_username(uid_t uid) 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,10 +517,18 @@ 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){ - S3FS_PRN_ERR("could not get max name length."); - maxlen = 0; - return -ERANGE; + 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; }