2021-04-18 15:41:13 -04:00
|
|
|
// Copyright (c) 2015-2021 MinIO, Inc.
|
|
|
|
//
|
|
|
|
// This file is part of MinIO Object Storage stack
|
|
|
|
//
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2016-12-02 02:15:17 -05:00
|
|
|
|
|
|
|
package cmd
|
|
|
|
|
2017-11-25 14:58:29 -05:00
|
|
|
import (
|
2018-03-15 16:27:16 -04:00
|
|
|
"context"
|
2022-10-25 13:52:29 -04:00
|
|
|
"encoding/base64"
|
2020-05-14 02:55:38 -04:00
|
|
|
"runtime"
|
|
|
|
"strings"
|
2018-03-15 16:27:16 -04:00
|
|
|
|
2020-07-14 12:38:05 -04:00
|
|
|
"github.com/minio/minio-go/v7/pkg/s3utils"
|
2017-11-25 14:58:29 -05:00
|
|
|
)
|
2016-12-02 02:15:17 -05:00
|
|
|
|
2024-02-22 13:05:17 -05:00
|
|
|
// Checks on CopyObject arguments, bucket and object.
|
|
|
|
func checkCopyObjArgs(ctx context.Context, bucket, object string) error {
|
|
|
|
return checkBucketAndObjectNames(ctx, bucket, object)
|
|
|
|
}
|
|
|
|
|
2016-12-02 02:15:17 -05:00
|
|
|
// Checks on GetObject arguments, bucket and object.
|
2018-04-05 18:04:40 -04:00
|
|
|
func checkGetObjArgs(ctx context.Context, bucket, object string) error {
|
|
|
|
return checkBucketAndObjectNames(ctx, bucket, object)
|
2016-12-02 02:15:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Checks on DeleteObject arguments, bucket and object.
|
2018-04-05 18:04:40 -04:00
|
|
|
func checkDelObjArgs(ctx context.Context, bucket, object string) error {
|
|
|
|
return checkBucketAndObjectNames(ctx, bucket, object)
|
2016-12-02 02:15:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Checks bucket and object name validity, returns nil if both are valid.
|
2018-04-05 18:04:40 -04:00
|
|
|
func checkBucketAndObjectNames(ctx context.Context, bucket, object string) error {
|
2016-12-02 02:15:17 -05:00
|
|
|
// Verify if bucket is valid.
|
2024-01-30 15:43:25 -05:00
|
|
|
if !isMinioMetaBucketName(bucket) && s3utils.CheckValidBucketNameStrict(bucket) != nil {
|
2018-04-05 18:04:40 -04:00
|
|
|
return BucketNameInvalid{Bucket: bucket}
|
2016-12-02 02:15:17 -05:00
|
|
|
}
|
|
|
|
// Verify if object is valid.
|
2018-01-29 21:43:13 -05:00
|
|
|
if len(object) == 0 {
|
2018-04-05 18:04:40 -04:00
|
|
|
return ObjectNameInvalid{Bucket: bucket, Object: object}
|
2018-01-29 21:43:13 -05:00
|
|
|
}
|
|
|
|
if !IsValidObjectPrefix(object) {
|
2018-04-05 18:04:40 -04:00
|
|
|
return ObjectNameInvalid{Bucket: bucket, Object: object}
|
2016-12-02 02:15:17 -05:00
|
|
|
}
|
2020-05-14 02:55:38 -04:00
|
|
|
if runtime.GOOS == globalWindowsOSName && strings.Contains(object, "\\") {
|
|
|
|
// Objects cannot be contain \ in Windows and is listed as `Characters to Avoid`.
|
|
|
|
return ObjectNameInvalid{Bucket: bucket, Object: object}
|
|
|
|
}
|
2016-12-02 02:15:17 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Checks for all ListObjects arguments validity.
|
2024-01-30 15:43:25 -05:00
|
|
|
func checkListObjsArgs(ctx context.Context, bucket, prefix, marker string) error {
|
|
|
|
// Verify if bucket is valid.
|
|
|
|
if !isMinioMetaBucketName(bucket) && s3utils.CheckValidBucketNameStrict(bucket) != nil {
|
|
|
|
return BucketNameInvalid{Bucket: bucket}
|
2016-12-02 02:15:17 -05:00
|
|
|
}
|
2024-01-30 15:43:25 -05:00
|
|
|
|
2016-12-02 02:15:17 -05:00
|
|
|
// Validates object prefix validity after bucket exists.
|
|
|
|
if !IsValidObjectPrefix(prefix) {
|
2018-04-05 18:04:40 -04:00
|
|
|
return ObjectNameInvalid{
|
|
|
|
Bucket: bucket,
|
|
|
|
Object: prefix,
|
|
|
|
}
|
2016-12-02 02:15:17 -05:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Checks for all ListMultipartUploads arguments validity.
|
2024-01-30 15:43:25 -05:00
|
|
|
func checkListMultipartArgs(ctx context.Context, bucket, prefix, keyMarker, uploadIDMarker, delimiter string) error {
|
|
|
|
if err := checkListObjsArgs(ctx, bucket, prefix, keyMarker); err != nil {
|
2016-12-02 02:15:17 -05:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
if uploadIDMarker != "" {
|
2019-12-06 02:16:06 -05:00
|
|
|
if HasSuffix(keyMarker, SlashSeparator) {
|
2018-04-05 18:04:40 -04:00
|
|
|
return InvalidUploadIDKeyCombination{
|
|
|
|
UploadIDMarker: uploadIDMarker,
|
|
|
|
KeyMarker: keyMarker,
|
|
|
|
}
|
2016-12-02 02:15:17 -05:00
|
|
|
}
|
2022-11-09 19:41:16 -05:00
|
|
|
_, err := base64.RawURLEncoding.DecodeString(uploadIDMarker)
|
2022-10-25 13:52:29 -04:00
|
|
|
if err != nil {
|
2018-04-05 18:04:40 -04:00
|
|
|
return MalformedUploadID{
|
|
|
|
UploadID: uploadIDMarker,
|
|
|
|
}
|
2016-12-02 02:15:17 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Checks for NewMultipartUpload arguments validity, also validates if bucket exists.
|
2024-02-22 13:05:17 -05:00
|
|
|
func checkNewMultipartArgs(ctx context.Context, bucket, object string) error {
|
|
|
|
return checkObjectArgs(ctx, bucket, object)
|
2016-12-02 02:15:17 -05:00
|
|
|
}
|
|
|
|
|
2024-02-22 13:05:17 -05:00
|
|
|
func checkMultipartObjectArgs(ctx context.Context, bucket, object, uploadID string) error {
|
2023-08-17 12:37:55 -04:00
|
|
|
_, err := base64.RawURLEncoding.DecodeString(uploadID)
|
|
|
|
if err != nil {
|
|
|
|
return MalformedUploadID{
|
|
|
|
UploadID: uploadID,
|
|
|
|
}
|
|
|
|
}
|
2024-02-22 13:05:17 -05:00
|
|
|
return checkObjectArgs(ctx, bucket, object)
|
2016-12-02 02:15:17 -05:00
|
|
|
}
|
|
|
|
|
2023-08-17 12:37:55 -04:00
|
|
|
// Checks for PutObjectPart arguments validity, also validates if bucket exists.
|
2024-02-22 13:05:17 -05:00
|
|
|
func checkPutObjectPartArgs(ctx context.Context, bucket, object, uploadID string) error {
|
|
|
|
return checkMultipartObjectArgs(ctx, bucket, object, uploadID)
|
2023-08-17 12:37:55 -04:00
|
|
|
}
|
|
|
|
|
2016-12-02 02:15:17 -05:00
|
|
|
// Checks for ListParts arguments validity, also validates if bucket exists.
|
2024-02-22 13:05:17 -05:00
|
|
|
func checkListPartsArgs(ctx context.Context, bucket, object, uploadID string) error {
|
|
|
|
return checkMultipartObjectArgs(ctx, bucket, object, uploadID)
|
2016-12-02 02:15:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Checks for CompleteMultipartUpload arguments validity, also validates if bucket exists.
|
2024-02-22 13:05:17 -05:00
|
|
|
func checkCompleteMultipartArgs(ctx context.Context, bucket, object, uploadID string) error {
|
|
|
|
return checkMultipartObjectArgs(ctx, bucket, object, uploadID)
|
2016-12-02 02:15:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Checks for AbortMultipartUpload arguments validity, also validates if bucket exists.
|
2024-02-22 13:05:17 -05:00
|
|
|
func checkAbortMultipartArgs(ctx context.Context, bucket, object, uploadID string) error {
|
|
|
|
return checkMultipartObjectArgs(ctx, bucket, object, uploadID)
|
2016-12-02 02:15:17 -05:00
|
|
|
}
|
|
|
|
|
2024-01-30 15:43:25 -05:00
|
|
|
// Checks Object arguments validity.
|
2024-02-22 13:05:17 -05:00
|
|
|
func checkObjectArgs(ctx context.Context, bucket, object string) error {
|
2024-01-30 15:43:25 -05:00
|
|
|
// Verify if bucket is valid.
|
|
|
|
if !isMinioMetaBucketName(bucket) && s3utils.CheckValidBucketNameStrict(bucket) != nil {
|
|
|
|
return BucketNameInvalid{Bucket: bucket}
|
2016-12-02 02:15:17 -05:00
|
|
|
}
|
2019-07-12 00:38:12 -04:00
|
|
|
|
|
|
|
if err := checkObjectNameForLengthAndSlash(bucket, object); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2020-02-05 21:59:38 -05:00
|
|
|
|
2016-12-02 02:15:17 -05:00
|
|
|
// Validates object name validity after bucket exists.
|
|
|
|
if !IsValidObjectName(object) {
|
2018-04-05 18:04:40 -04:00
|
|
|
return ObjectNameInvalid{
|
|
|
|
Bucket: bucket,
|
|
|
|
Object: object,
|
|
|
|
}
|
2016-12-02 02:15:17 -05:00
|
|
|
}
|
2019-07-12 00:38:12 -04:00
|
|
|
|
2016-12-02 02:15:17 -05:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2024-01-30 15:43:25 -05:00
|
|
|
// Checks for PutObject arguments validity.
|
2023-11-17 08:29:50 -05:00
|
|
|
func checkPutObjectArgs(ctx context.Context, bucket, object string) error {
|
2024-01-30 15:43:25 -05:00
|
|
|
// Verify if bucket is valid.
|
|
|
|
if !isMinioMetaBucketName(bucket) && s3utils.CheckValidBucketNameStrict(bucket) != nil {
|
|
|
|
return BucketNameInvalid{Bucket: bucket}
|
|
|
|
}
|
|
|
|
|
2019-07-12 00:38:12 -04:00
|
|
|
if err := checkObjectNameForLengthAndSlash(bucket, object); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-02-09 18:19:30 -05:00
|
|
|
if len(object) == 0 ||
|
|
|
|
!IsValidObjectPrefix(object) {
|
2018-04-05 18:04:40 -04:00
|
|
|
return ObjectNameInvalid{
|
|
|
|
Bucket: bucket,
|
|
|
|
Object: object,
|
|
|
|
}
|
2018-02-09 18:19:30 -05:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|