Help Center/ Object Storage Service/ SDK Reference/ C/ Bucket APIs (SDK for C)/ Block Public Access (BPA) (SDK for C)/ Obtaining the Public Access Status of a Bucket Policy (SDK for C)
Updated on 2026-08-03 GMT+08:00

Obtaining the Public Access Status of a Bucket Policy (SDK for C)

If you have any questions during development, post them on the Issues page of GitHub.

Function

This API is used to obtain the public access status of a bucket policy.

Restrictions

Method

void get_bucket_policy_public_status(const obs_options *options,
    obs_get_bucket_policy_public_status_handler *handler, void *callback_data);

Request Parameters

Table 1 List of request parameters

Parameter

Type

Mandatory (Yes/No)

Description

options

const obs_options*

Yes

Explanation:

Context of the requested bucket. You can set the AK, SK, endpoint, bucket, timeout interval, and temporary credentials through obs_options.

Restrictions:

None

handler

Table 2 *

Yes

Explanation:

A callback structure where all members are pointers to callback functions, used to set the callback functions that handle response data. You can set a callback function to copy the response data from the server to callback_data (custom callback data).

Restrictions:

None

callback_data

void *

No

Explanation:

Custom callback data.

Restrictions:

None

Value range:

None

Default value:

None

Table 2 obs_get_bucket_policy_public_status_handler

Parameter

Type

Mandatory (Yes/No)

Description

response_handler

obs_response_handler

Yes

Explanation:

Response callback function structure.

Restrictions:

None

get_policy_status_callback

Table 3*

Yes

Explanation:

Pointer to the callback function for obtaining the public access status of a bucket policy. You can read the content of obs_bucket_policy_status in the callback.

Restrictions:

None

Table 3 obs_get_bucket_policy_public_status_callback

Parameter

Type

Mandatory (Yes/No)

Description

policy_status

const Table 4*

Yes

Explanation:

Bucket policy public access status structure, including information about whether the bucket policy is public.

Restrictions:

The structure and the memory to which the pointer points will be released by the SDK after the callback. Copy them if you need to keep the data.

callback_data

void *

Yes

Explanation:

Pointer to the custom callback data.

Restrictions:

None

Value range:

None

Default value:

None

Table 4 obs_bucket_policy_status

Parameter

Type

Description

is_public

bool

Explanation:

Whether the bucket policy is public.

Restrictions:

None

Value range:

true (public) or false (non-public)

Default value:

false

Sample Code

This example obtains the public access status of a bucket policy.
#include "eSDKOBS.h"
#include <stdio.h>
obs_status response_properties_callback(const obs_response_properties *properties, void *callback_data);
void response_complete_callback(obs_status status, const obs_error_details *error, void *callback_data);
typedef struct PolicyStatusResult
{
    bool is_public;
    obs_status ret_status;
} PolicyStatusResult;
obs_status get_policy_status_callback(const obs_bucket_policy_status *policy_status, void *callback_data)
{
    PolicyStatusResult *result = (PolicyStatusResult *)callback_data;
    if (policy_status) {
        result->is_public = policy_status->is_public;
    }
    return OBS_STATUS_OK;
}
int main()
{
    obs_initialize(OBS_INIT_ALL);
    obs_options options;
    init_obs_options(&options);
    // Enter the endpoint corresponding to the bucket for host_name. CN-Hong Kong is used here as an example. Replace it with the one currently in use.
    options.bucket_options.host_name = "obs.ap-southeast-1.myhuaweicloud.com";
    // Hard-coded or plaintext AK and SK are risky. For security purposes, encrypt your AK and SK and store them in the configuration file or environment variables.
    // In this example, the AK and SK are stored in environment variables for identity authentication. Before running the code in this example, configure local environment variables ACCESS_KEY_ID and SECRET_ACCESS_KEY.
    options.bucket_options.access_key = getenv("ACCESS_KEY_ID");
    options.bucket_options.secret_access_key = getenv("SECRET_ACCESS_KEY");
    options.bucket_options.bucket_name = "example-bucket-name";
    obs_get_bucket_policy_public_status_handler handler = {0};
    handler.response_handler.properties_callback = &response_properties_callback;
    handler.response_handler.complete_callback = &response_complete_callback;
    handler.get_policy_status_callback = &get_policy_status_callback;
    PolicyStatusResult result;
    memset(&result, 0, sizeof(PolicyStatusResult));
    result.ret_status = OBS_STATUS_BUTT;
    get_bucket_policy_public_status(&options, &handler, &result);
    if (OBS_STATUS_OK == result.ret_status) {
        printf("get bucket policy public status successfully.\n");
        printf("is_public: %s\n", result.is_public ? "true" : "false");
    } else {
        printf("get bucket policy public status failed(%s).\n", obs_get_status_name(result.ret_status));
    }
    obs_deinitialize();
}
obs_status response_properties_callback(const obs_response_properties *properties, void *callback_data)
{
    (void)properties; (void)callback_data;
    return OBS_STATUS_OK;
}
void response_complete_callback(obs_status status, const obs_error_details *error, void *callback_data)
{
    if (callback_data) {
        PolicyStatusResult *result = (PolicyStatusResult *)callback_data;
        result->ret_status = status;
    }
    if (error && error->message) { printf("Error: %s\n", error->message); }
}