@ -266,7 +266,7 @@ func (api objectAPIHandlers) ListBucketsHandler(w http.ResponseWriter, r *http.R
listBuckets := objectAPI . ListBuckets
listBuckets := objectAPI . ListBuckets
accessKey , owner , s3Error := checkRequestAuthTypeToAccessKey ( ctx , r , policy . ListAllMyBucketsAction , "" , "" )
accessKey , owner , s3Error := checkRequestAuthTypeToAccessKey ( ctx , r , policy . ListAllMyBucketsAction , "" , "" )
if s3Error != ErrNone {
if s3Error != ErrNone && s3Error != ErrAccessDenied {
writeErrorResponse ( ctx , w , errorCodes . ToAPIErr ( s3Error ) , r . URL , guessIsBrowserReq ( r ) )
writeErrorResponse ( ctx , w , errorCodes . ToAPIErr ( s3Error ) , r . URL , guessIsBrowserReq ( r ) )
return
return
}
}
@ -295,32 +295,43 @@ func (api objectAPIHandlers) ListBucketsHandler(w http.ResponseWriter, r *http.R
}
}
}
}
// Set prefix value for "s3:prefix" policy conditionals.
if s3Error == ErrAccessDenied {
r . Header . Set ( "prefix" , "" )
// Set prefix value for "s3:prefix" policy conditionals.
r . Header . Set ( "prefix" , "" )
// Set delimiter value for "s3:delimiter" policy conditionals.
r . Header . Set ( "delimiter" , SlashSeparator )
// Set delimiter value for "s3:delimiter" policy conditionals.
r . Header . Set ( "delimiter" , SlashSeparator )
// err will be nil here as we already called this function
// earlier in this request.
// err will be nil here as we already called this function
claims , _ := getClaimsFromToken ( r )
// earlier in this request.
var newBucketsInfo [ ] BucketInfo
claims , _ := getClaimsFromToken ( r )
for _ , bucketInfo := range bucketsInfo {
n := 0
if globalIAMSys . IsAllowed ( iampolicy . Args {
// Use the following trick to filter in place
AccountName : accessKey ,
// https://github.com/golang/go/wiki/SliceTricks#filter-in-place
Action : iampolicy . ListBucketAction ,
for _ , bucketInfo := range bucketsInfo {
BucketName : bucketInfo . Name ,
if globalIAMSys . IsAllowed ( iampolicy . Args {
ConditionValues : getConditionValues ( r , "" , accessKey , claims ) ,
AccountName : accessKey ,
IsOwner : owner ,
Action : iampolicy . ListBucketAction ,
ObjectName : "" ,
BucketName : bucketInfo . Name ,
Claims : claims ,
ConditionValues : getConditionValues ( r , "" , accessKey , claims ) ,
} ) {
IsOwner : owner ,
newBucketsInfo = append ( newBucketsInfo , bucketInfo )
ObjectName : "" ,
Claims : claims ,
} ) {
bucketsInfo [ n ] = bucketInfo
n ++
}
}
bucketsInfo = bucketsInfo [ : n ]
// No buckets can be filtered return access denied error.
if len ( bucketsInfo ) == 0 {
writeErrorResponse ( ctx , w , errorCodes . ToAPIErr ( s3Error ) , r . URL , guessIsBrowserReq ( r ) )
return
}
}
}
}
// Generate response.
// Generate response.
response := generateListBucketsResponse ( newBucketsInfo )
response := generateListBucketsResponse ( b ucketsInfo)
encodedSuccessResponse := encodeResponse ( response )
encodedSuccessResponse := encodeResponse ( response )
// Write response.
// Write response.