|
|
@ -18,37 +18,43 @@ package main |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"io" |
|
|
|
"io" |
|
|
|
|
|
|
|
"net/http" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// validates location constraint from the request body.
|
|
|
|
// Validates location constraint in PutBucket request body.
|
|
|
|
// the location value in the request body should match the Region in serverConfig.
|
|
|
|
// The location value in the request body should match the
|
|
|
|
// other values of location are not accepted.
|
|
|
|
// region configured at serverConfig, otherwise error is returned.
|
|
|
|
// make bucket fails in such cases.
|
|
|
|
func isValidLocationConstraint(r *http.Request) (s3Error APIErrorCode) { |
|
|
|
func isValidLocationContraint(reqBody io.Reader, serverRegion string) APIErrorCode { |
|
|
|
serverRegion := serverConfig.GetRegion() |
|
|
|
var locationContraint createBucketLocationConfiguration |
|
|
|
// If the request has no body with content-length set to 0,
|
|
|
|
var errCode APIErrorCode |
|
|
|
// we do not have to validate location constraint. Bucket will
|
|
|
|
errCode = ErrNone |
|
|
|
// be created at default region.
|
|
|
|
e := xmlDecoder(reqBody, &locationContraint) |
|
|
|
if r.ContentLength == 0 { |
|
|
|
if e != nil { |
|
|
|
return ErrNone |
|
|
|
if e == io.EOF { |
|
|
|
} |
|
|
|
// Do nothing.
|
|
|
|
locationConstraint := createBucketLocationConfiguration{} |
|
|
|
// failed due to empty body. The location will be set to default value from the serverConfig.
|
|
|
|
if err := xmlDecoder(r.Body, &locationConstraint, r.ContentLength); err != nil { |
|
|
|
// this is valid.
|
|
|
|
if err == io.EOF && r.ContentLength == -1 { |
|
|
|
errCode = ErrNone |
|
|
|
// EOF is a valid condition here when ContentLength is -1.
|
|
|
|
} else { |
|
|
|
return ErrNone |
|
|
|
// Failed due to malformed configuration.
|
|
|
|
|
|
|
|
errCode = ErrMalformedXML |
|
|
|
|
|
|
|
//writeErrorResponse(w, r, ErrMalformedXML, r.URL.Path)
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
// Region obtained from the body.
|
|
|
|
|
|
|
|
// It should be equal to Region in serverConfig.
|
|
|
|
|
|
|
|
// Else ErrInvalidRegion returned.
|
|
|
|
|
|
|
|
// For empty value location will be to set to default value from the serverConfig.
|
|
|
|
|
|
|
|
if locationContraint.Location != "" && serverRegion != locationContraint.Location { |
|
|
|
|
|
|
|
//writeErrorResponse(w, r, ErrInvalidRegion, r.URL.Path)
|
|
|
|
|
|
|
|
errCode = ErrInvalidRegion |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
errorIf(err, "Unable to xml decode location constraint") |
|
|
|
|
|
|
|
// Treat all other failures as XML parsing errors.
|
|
|
|
|
|
|
|
return ErrMalformedXML |
|
|
|
|
|
|
|
} // Successfully decoded, proceed to verify the region.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Once region has been obtained we proceed to verify it.
|
|
|
|
|
|
|
|
incomingRegion := locationConstraint.Location |
|
|
|
|
|
|
|
if incomingRegion == "" { |
|
|
|
|
|
|
|
// Location constraint is empty for region "us-east-1",
|
|
|
|
|
|
|
|
// in accordance with protocol.
|
|
|
|
|
|
|
|
incomingRegion = "us-east-1" |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// Return errInvalidRegion if location constraint does not match
|
|
|
|
|
|
|
|
// with configured region.
|
|
|
|
|
|
|
|
s3Error = ErrNone |
|
|
|
|
|
|
|
if serverRegion != incomingRegion { |
|
|
|
|
|
|
|
s3Error = ErrInvalidRegion |
|
|
|
} |
|
|
|
} |
|
|
|
return errCode |
|
|
|
return s3Error |
|
|
|
} |
|
|
|
} |
|
|
|