获取权限
接口定义:
void S3_get_acl(const S3BucketContext *bucketContext, const char *key,
char *ownerId, char *ownerDisplayName,
int *aclGrantCountReturn, S3AclGrant *aclGrants,
S3RequestContext *requestContext,
int timeoutMs,
const S3ResponseHandler *handler, void *callbackData);
参数:
参数名 | 类型 | 说明 |
---|---|---|
bucketContext | const S3BucketContext * | 包含bucket及相关的请求参数 |
key | const char * | 若获取对象的acl,则为对象名称;若获取bucket的acl,则为NULL |
ownerId | char * | 拥有者id |
ownerDisplayName | char * | 拥有者名称 |
aclGrantCountReturn | int * | 返回S3AclGrant的个数 |
aclGrants | S3AclGrant * | 权限信息结构构成的数组 |
requestContext | S3RequestContext * | 请求参数,如果为NULL,则立即同步执行请求 |
timeoutMs | int | 如果非0,则是以毫秒为单位的请求超时时间 |
handler | const S3ResponseHandler * | 回调函数 |
callbackData | void * | 回调数据 |
代码示例:
#include <unistd.h>
void get_acl(const char *outfilename)
{
FILE *outfile = 0;
if (outfilename)
{
outfile = fopen(outfilename, "w");
if (!outfile)
{
fprintf(stderr, "\nERROR: Failed to open output file %s: ",
outfilename);
perror(0);
exit(-1);
}
}
else
{
outfile = stdout;
}
int aclGrantCount;
S3AclGrant aclGrants[S3_MAX_ACL_GRANT_COUNT];
char ownerId[S3_MAX_GRANTEE_USER_ID_SIZE];
char ownerDisplayName[S3_MAX_GRANTEE_DISPLAY_NAME_SIZE];
S3ResponseHandler responseHandler =
{
&responsePropertiesCallback,
&responseCompleteCallback};
do
{
S3_get_acl(&bucketContext, test_key, ownerId, ownerDisplayName,
&aclGrantCount, aclGrants, 0, 0, &responseHandler, 0);
} while (S3_status_is_retryable(statusG) && should_retry());
if (statusG == S3StatusOK)
{
fprintf(outfile, "OwnerID %s %s\n", ownerId, ownerDisplayName);
fprintf(outfile, "%-6s %-90s %-12s\n", " Type",
" User Identifier",
" Permission");
fprintf(outfile, "------ "
"------------------------------------------------------------"
"------------------------------ ------------\n");
int i;
for (i = 0; i < aclGrantCount; i++)
{
S3AclGrant *grant = &(aclGrants[i]);
const char *type;
char composedId[S3_MAX_GRANTEE_USER_ID_SIZE +
S3_MAX_GRANTEE_DISPLAY_NAME_SIZE + 16];
const char *id;
switch (grant->granteeType)
{
case S3GranteeTypeAmazonCustomerByEmail:
type = "Email";
id = grant->grantee.amazonCustomerByEmail.emailAddress;
break;
case S3GranteeTypeCanonicalUser:
type = "UserID";
snprintf(composedId, sizeof(composedId),
"%s (%s)", grant->grantee.canonicalUser.id,
grant->grantee.canonicalUser.displayName);
id = composedId;
break;
case S3GranteeTypeAllAwsUsers:
type = "Group";
id = "Authenticated AWS Users";
break;
case S3GranteeTypeAllUsers:
type = "Group";
id = "All Users";
break;
default:
type = "Group";
id = "Log Delivery";
break;
}
const char *perm;
switch (grant->permission)
{
case S3PermissionRead:
perm = "READ";
break;
case S3PermissionWrite:
perm = "WRITE";
break;
case S3PermissionReadACP:
perm = "READ_ACP";
break;
case S3PermissionWriteACP:
perm = "WRITE_ACP";
break;
default:
perm = "FULL_CONTROL";
break;
}
fprintf(outfile, "%-6s %-90s %-12s\n", type, id, perm);
}
}
else
{
printError();
}
fclose(outfile);
}