2021-10-26 11:40:49 +00:00
|
|
|
package acl
|
|
|
|
|
2021-12-29 07:48:01 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
2021-10-26 11:40:49 +00:00
|
|
|
const (
|
2021-12-17 10:03:10 +00:00
|
|
|
// PublicBasicRule is a basic ACL value for final public-read-write container for which extended ACL CANNOT be set.
|
2021-10-26 11:40:49 +00:00
|
|
|
PublicBasicRule = 0x1FBFBFFF
|
|
|
|
|
2021-12-17 10:03:10 +00:00
|
|
|
// PrivateBasicRule is a basic ACL value for final private container for which extended ACL CANNOT be set.
|
2021-10-26 11:40:49 +00:00
|
|
|
PrivateBasicRule = 0x1C8C8CCC
|
|
|
|
|
2021-12-17 10:03:10 +00:00
|
|
|
// ReadOnlyBasicRule is a basic ACL value for final public-read container for which extended ACL CANNOT be set.
|
2021-10-26 11:40:49 +00:00
|
|
|
ReadOnlyBasicRule = 0x1FBF8CFF
|
|
|
|
|
2021-12-17 10:03:10 +00:00
|
|
|
// PublicAppendRule is a basic ACL value for final public-append container for which extended ACL CANNOT be set.
|
2021-10-26 11:40:49 +00:00
|
|
|
PublicAppendRule = 0x1FBF9FFF
|
2021-12-17 10:03:10 +00:00
|
|
|
|
|
|
|
// EACLPublicBasicRule is a basic ACL value for non-final public-read-write container for which extended ACL CAN be set.
|
|
|
|
EACLPublicBasicRule = 0x0FBFBFFF
|
|
|
|
|
|
|
|
// EACLPrivateBasicRule is a basic ACL value for non-final private container for which extended ACL CAN be set.
|
|
|
|
EACLPrivateBasicRule = 0x0C8C8CCC
|
|
|
|
|
|
|
|
// EACLReadOnlyBasicRule is a basic ACL value for non-final public-read container for which extended ACL CAN be set.
|
|
|
|
EACLReadOnlyBasicRule = 0x0FBF8CFF
|
|
|
|
|
|
|
|
// EACLPublicAppendRule is a basic ACL value for non-final public-append container for which extended ACL CAN be set.
|
|
|
|
EACLPublicAppendRule = 0x0FBF9FFF
|
2021-10-26 11:40:49 +00:00
|
|
|
)
|
2021-12-29 07:41:35 +00:00
|
|
|
|
|
|
|
const (
|
|
|
|
// PublicBasicName is a well-known name for 0x1FBFBFFF basic ACL.
|
|
|
|
PublicBasicName = "public-read-write"
|
|
|
|
|
|
|
|
// PrivateBasicName is a well-known name for 0x1C8C8CCC basic ACL.
|
|
|
|
PrivateBasicName = "private"
|
|
|
|
|
|
|
|
// ReadOnlyBasicName is a well-known name for 0x1FBF8CFF basic ACL.
|
|
|
|
ReadOnlyBasicName = "public-read"
|
|
|
|
|
|
|
|
// PublicAppendName is a well-known name for 0x1FBF9FFF basic ACL.
|
|
|
|
PublicAppendName = "public-append"
|
|
|
|
|
|
|
|
// EACLPublicBasicName is a well-known name for 0x0FBFBFFF basic ACL.
|
|
|
|
EACLPublicBasicName = "eacl-public-read-write"
|
|
|
|
|
|
|
|
// EACLPrivateBasicName is a well-known name for 0x0C8C8CCC basic ACL.
|
|
|
|
EACLPrivateBasicName = "eacl-private"
|
|
|
|
|
|
|
|
// EACLReadOnlyBasicName is a well-known name for 0x0FBF8CFF basic ACL.
|
|
|
|
EACLReadOnlyBasicName = "eacl-public-read"
|
|
|
|
|
|
|
|
// EACLPublicAppendName is a well-known name for 0x0FBF9FFF basic ACL.
|
|
|
|
EACLPublicAppendName = "eacl-public-append"
|
|
|
|
)
|
2021-12-29 07:48:01 +00:00
|
|
|
|
|
|
|
// ParseBasicACL parse string ACL (well-known names or hex representation).
|
|
|
|
func ParseBasicACL(basicACL string) (uint32, error) {
|
|
|
|
switch basicACL {
|
|
|
|
case PublicBasicName:
|
|
|
|
return PublicBasicRule, nil
|
|
|
|
case PrivateBasicName:
|
|
|
|
return PrivateBasicRule, nil
|
|
|
|
case ReadOnlyBasicName:
|
|
|
|
return ReadOnlyBasicRule, nil
|
|
|
|
case PublicAppendName:
|
|
|
|
return PublicAppendRule, nil
|
|
|
|
case EACLPublicBasicName:
|
|
|
|
return EACLPublicBasicRule, nil
|
|
|
|
case EACLPrivateBasicName:
|
|
|
|
return EACLPrivateBasicRule, nil
|
|
|
|
case EACLReadOnlyBasicName:
|
|
|
|
return EACLReadOnlyBasicRule, nil
|
|
|
|
case EACLPublicAppendName:
|
|
|
|
return EACLPublicAppendRule, nil
|
|
|
|
default:
|
|
|
|
basicACL = strings.Trim(strings.ToLower(basicACL), "0x")
|
|
|
|
|
|
|
|
value, err := strconv.ParseUint(basicACL, 16, 32)
|
|
|
|
if err != nil {
|
|
|
|
return 0, fmt.Errorf("can't parse basic ACL: %s", basicACL)
|
|
|
|
}
|
|
|
|
|
|
|
|
return uint32(value), nil
|
|
|
|
}
|
|
|
|
}
|