本文整理汇总了C++中context_free函数的典型用法代码示例。如果您正苦于以下问题:C++ context_free函数的具体用法?C++ context_free怎么用?C++ context_free使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了context_free函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: defaultcon
/*
This function takes a path and a mode, it calls computecon to get the
label of the path object if the current process created it, then it calls
matchpathcon to get the default type for the object. It substitutes the
default type into label. It tells the SELinux Kernel to label all new file
system objects created by the current process with this label.
Returns -1 on failure. errno will be set appropriately.
*/
int
defaultcon (char const *path, mode_t mode)
{
int rc = -1;
char *scon = NULL;
char *tcon = NULL;
context_t scontext = 0, tcontext = 0;
const char *contype;
char *constr;
char *newpath = NULL;
if (! IS_ABSOLUTE_FILE_NAME (path))
{
/* Generate absolute path as required by subsequent matchpathcon(),
with libselinux < 2.1.5 2011-0826. */
newpath = canonicalize_filename_mode (path, CAN_MISSING);
if (! newpath)
error (EXIT_FAILURE, errno, _("error canonicalizing %s"),
quote (path));
path = newpath;
}
if (matchpathcon (path, mode, &scon) < 0)
{
/* "No such file or directory" is a confusing error,
when processing files, when in fact it was the
associated default context that was not found.
Therefore map the error to something more appropriate
to the context in which we're using matchpathcon(). */
if (errno == ENOENT)
errno = ENODATA;
goto quit;
}
if (computecon (path, mode, &tcon) < 0)
goto quit;
if (!(scontext = context_new (scon)))
goto quit;
if (!(tcontext = context_new (tcon)))
goto quit;
if (!(contype = context_type_get (scontext)))
goto quit;
if (context_type_set (tcontext, contype))
goto quit;
if (!(constr = context_str (tcontext)))
goto quit;
rc = setfscreatecon (constr);
quit:
context_free (scontext);
context_free (tcontext);
freecon (scon);
freecon (tcon);
free (newpath);
return rc;
}
示例2: context_deinit
/*
* implementation for context_deinit
*/
void context_deinit() {
if (current_context != top_context && current_context != NULL) context_free(current_context);
if (top_context != NULL) {
top_context->pFiber = NULL;
context_free(top_context);
top_context = NULL;
}
current_context = NULL;
return;
}
示例3: set_context_from_socket
static int set_context_from_socket( const struct service_config *scp, int fd )
{
security_context_t curr_context = NULL;
security_context_t peer_context = NULL;
security_context_t exec_context = NULL;
context_t bcon = NULL;
context_t pcon = NULL;
security_context_t new_context = NULL;
security_context_t new_exec_context = NULL;
int retval = -1;
const char *exepath = NULL;
if (getcon(&curr_context) < 0)
goto fail;
if (getpeercon(fd, &peer_context) < 0)
goto fail;
exepath = SC_SERVER_ARGV( scp )[0];
if (getfilecon(exepath, &exec_context) < 0)
goto fail;
if (!(bcon = context_new(curr_context)))
goto fail;
if (!(pcon = context_new(peer_context)))
goto fail;
if (!context_range_get(pcon))
goto fail;
if (context_range_set(bcon, context_range_get(pcon)))
goto fail;
if (!(new_context = context_str(bcon)))
goto fail;
if (security_compute_create(new_context, exec_context, SECCLASS_PROCESS,
&new_exec_context) < 0)
goto fail;
retval = set_context(new_exec_context);
freecon(new_exec_context);
fail:
context_free(pcon);
context_free(bcon);
freecon(exec_context);
freecon(peer_context);
freecon(curr_context);
return retval;
}
示例4: testSELinuxGenLabel
static int
testSELinuxGenLabel(const void *opaque)
{
const struct testSELinuxGenLabelData *data = opaque;
int ret = -1;
virDomainDefPtr def;
context_t con = NULL;
context_t imgcon = NULL;
if (setcon_raw((security_context_t)data->pidcon) < 0) {
perror("Cannot set process security context");
return -1;
}
if (!(def = testBuildDomainDef(data->dynamic,
data->label,
data->baselabel)))
goto cleanup;
if (virSecurityManagerGenLabel(data->mgr, def) < 0) {
virErrorPtr err = virGetLastError();
fprintf(stderr, "Cannot generate label: %s\n", err->message);
goto cleanup;
}
VIR_DEBUG("label=%s imagelabel=%s",
def->seclabels[0]->label, def->seclabels[0]->imagelabel);
if (!(con = context_new(def->seclabels[0]->label)))
goto cleanup;
if (!(imgcon = context_new(def->seclabels[0]->imagelabel)))
goto cleanup;
if (!testSELinuxCheckCon(con,
data->user, data->role, data->type,
data->sensMin, data->sensMax,
data->catMin, data->catMax))
goto cleanup;
if (!testSELinuxCheckCon(imgcon,
data->user, data->imagerole, data->imagetype,
data->sensMin, data->sensMax,
data->catMin, data->catMax))
goto cleanup;
ret = 0;
cleanup:
context_free(con);
context_free(imgcon);
virDomainDefFree(def);
return ret;
}
示例5: file_con_fixup
/* Set the context of all files associated with this VM to the new context
* complete with the unique generated category.
*/
static int
file_con_fixup (data_t *data)
{
security_context_t sec_con = { 0, };
context_t con = { 0, };
char mcs_str[9] = { 0, };
int ret = 0, p_ret = 0, i = 0;;
p_ret = snprintf (mcs_str, sizeof (mcs_str), "s0:c%d", data->category);
if (p_ret < 0 || p_ret > 9) {
syslog (LOG_CRIT, "insufficient buffer size");
return -1;
}
for (i = 0; data->files [i] != NULL; ++i) {
if (getfilecon (data->files [i], &sec_con) == -1) {
syslog (LOG_CRIT,
"error getting context from file: %s, error %s",
data->files [i], strerror (errno));
continue;
}
con = context_new (sec_con);
if (con == NULL) {
syslog (LOG_CRIT,
"Error creating new context from string: %s",
sec_con);
ret = -1;
goto err_freecon;
}
if (context_range_set (con, mcs_str) == -1) {
syslog (LOG_CRIT,
"Error setting context range to %s, "
"error: %s", mcs_str, strerror (errno));
ret = -1;
goto err_confree;
}
syslog (LOG_INFO, "Setting context for file %s to %s",
data->files [i], context_str (con));
ret = setfilecon (data->files [i], context_str (con));
if (ret != 0)
syslog (LOG_CRIT, "setfilecon error:%s",
strerror (errno));
context_free (con);
freecon (sec_con);
}
return ret;
err_confree:
context_free (con);
err_freecon:
freecon (sec_con);
return ret;
}
示例6: pa_assert
pa_context *pa_context_new_with_proplist(pa_mainloop_api *mainloop, const char *name, pa_proplist *p) {
pa_context *c;
pa_assert(mainloop);
if (pa_detect_fork())
return NULL;
pa_init_i18n();
c = pa_xnew0(pa_context, 1);
PA_REFCNT_INIT(c);
c->proplist = p ? pa_proplist_copy(p) : pa_proplist_new();
if (name)
pa_proplist_sets(c->proplist, PA_PROP_APPLICATION_NAME, name);
#ifdef HAVE_DBUS
c->system_bus = c->session_bus = NULL;
#endif
c->mainloop = mainloop;
c->playback_streams = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
c->record_streams = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
c->client_index = PA_INVALID_INDEX;
c->use_rtclock = pa_mainloop_is_our_api(mainloop);
PA_LLIST_HEAD_INIT(pa_stream, c->streams);
PA_LLIST_HEAD_INIT(pa_operation, c->operations);
c->error = PA_OK;
c->state = PA_CONTEXT_UNCONNECTED;
reset_callbacks(c);
#ifndef MSG_NOSIGNAL
#ifdef SIGPIPE
pa_check_signal_is_blocked(SIGPIPE);
#endif
#endif
c->conf = pa_client_conf_new();
pa_client_conf_load(c->conf, true, true);
c->srb_template.readfd = -1;
c->srb_template.writefd = -1;
if (!(c->mempool = pa_mempool_new(!c->conf->disable_shm, c->conf->shm_size))) {
if (!c->conf->disable_shm)
c->mempool = pa_mempool_new(false, c->conf->shm_size);
if (!c->mempool) {
context_free(c);
return NULL;
}
}
return c;
}
示例7: main
int main(void) {
Context ctx = context_new("<stdin>", file_to_char_stream(stdin));
ctx.color_enabled = true;
int ret_value = EXIT_SUCCESS;
if (yyparse(&ctx) == 0) {
printf("Parsed as:\n");
translation_unit_pprint(&ctx, stdout, &ctx.ast);
putchar('\n');
for (size_t i = 0; i < ctx.ast.num_top_levels; i++) {
if (!type_check_top_level(&ctx, &ctx.ast.top_levels[i])) {
fprintf(stderr, "Failed to type check \"%s\".\n",
ctx.ast.top_levels[i].name);
ret_value = EXIT_FAILURE;
}
}
} else {
ret_value = EXIT_FAILURE;
}
context_free(&ctx);
putchar('\n');
print_allocation_info(stdout);
return ret_value;
}
示例8: operation_shutdown
static void
operation_shutdown (gboolean operation_status)
{
/* Cleanup context and finish async operation */
context_free (ctx);
qmicli_async_operation_done (operation_status);
}
示例9: pa_context_unref
void pa_context_unref(pa_context *c) {
pa_assert(c);
pa_assert(PA_REFCNT_VALUE(c) >= 1);
if (PA_REFCNT_DEC(c) <= 0)
context_free(c);
}
示例10: raw_color
/* Look up colors.
*/
int raw_color(const security_context_t raw, char **color_str) {
#define CHARS_PER_COLOR 16
context_t con;
uint32_t i, j, mask = 0;
const secolor_t *items[N_COLOR];
char *result, *components[N_COLOR];
char buf[CHARS_PER_COLOR + 1];
size_t result_size = (N_COLOR * CHARS_PER_COLOR) + 1;
int rc = -1;
if (!color_str || *color_str) {
return -1;
}
/* parse context and allocate memory */
con = context_new(raw);
if (!con)
return -1;
if (parse_components(con, components) < 0)
goto out;
result = malloc(result_size);
if (!result)
goto out;
result[0] = '\0';
/* find colors for which we have a match */
for (i = 0; i < N_COLOR; i++) {
items[i] = find_color(i, components[i], raw);
if (items[i])
mask |= (1 << i);
}
if (mask == 0) {
items[0] = &default_color;
mask = 1;
}
/* propagate colors according to the precedence rules */
for (i = 0; i < N_COLOR; i++)
if (!(mask & (1 << i)))
for (j = 0; j < N_COLOR - 1; j++)
if (mask & (1 << precedence[i][j])) {
items[i] = items[precedence[i][j]];
break;
}
/* print results into a big long string */
for (i = 0; i < N_COLOR; i++) {
snprintf(buf, sizeof(buf), "#%06x #%06x ",
items[i]->fg, items[i]->bg);
strncat(result, buf, result_size-1);
}
*color_str = result;
rc = 0;
out:
context_free(con);
return rc;
}
示例11: main
int main(int argc, char *argv[]) {
Context context = {};
int r, n, fd;
log_parse_environment();
log_open();
r = parse_argv(argc, argv);
if (r <= 0)
goto finish;
r = sd_event_default(&context.event);
if (r < 0) {
log_error_errno(r, "Failed to allocate event loop: %m");
goto finish;
}
r = sd_resolve_default(&context.resolve);
if (r < 0) {
log_error_errno(r, "Failed to allocate resolver: %m");
goto finish;
}
r = sd_resolve_attach_event(context.resolve, context.event, 0);
if (r < 0) {
log_error_errno(r, "Failed to attach resolver: %m");
goto finish;
}
sd_event_set_watchdog(context.event, true);
n = sd_listen_fds(1);
if (n < 0) {
log_error("Failed to receive sockets from parent.");
r = n;
goto finish;
} else if (n == 0) {
log_error("Didn't get any sockets passed in.");
r = -EINVAL;
goto finish;
}
for (fd = SD_LISTEN_FDS_START; fd < SD_LISTEN_FDS_START + n; fd++) {
r = add_listen_socket(&context, fd);
if (r < 0)
goto finish;
}
r = sd_event_loop(context.event);
if (r < 0) {
log_error_errno(r, "Failed to run event loop: %m");
goto finish;
}
finish:
context_free(&context);
return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}
示例12: check_dominance
static int check_dominance(const char *pattern, const char *raw) {
security_context_t ctx;
context_t con;
struct av_decision avd;
int rc = -1;
context_t my_tmp;
const char *raw_range;
security_class_t context_class = string_to_security_class("context");
access_vector_t context_contains_perm = string_to_av_perm(context_class, "contains");
con = context_new(raw);
if (!con)
return -1;
raw_range = context_range_get(con);
my_tmp = context_new(my_context);
if (!my_tmp) {
context_free(con);
return -1;
}
ctx = NULL;
if (context_range_set(my_tmp, pattern))
goto out;
ctx = strdup(context_str(my_tmp));
if (!ctx)
goto out;
if (context_range_set(my_tmp, raw_range))
goto out;
raw = context_str(my_tmp);
if (!raw)
goto out;
rc = security_compute_av_raw(ctx, (security_context_t)raw, context_class, context_contains_perm, &avd);
if (rc)
goto out;
rc = (context_contains_perm & avd.allowed) != context_contains_perm;
out:
free(ctx);
context_free(my_tmp);
context_free(con);
return rc;
}
示例13: kplugs_exit
/* the module clean function */
static void __exit kplugs_exit(void)
{
device_destroy(kplugs_class, kplugs_devno);
cdev_del(kplugs_cdev);
class_destroy(kplugs_class);
unregister_chrdev_region(kplugs_devno, 1);
context_free(GLOBAL_CONTEXT);
memory_stop();
}
示例14: kplugs_release
/* release callback */
static int kplugs_release(struct inode *inode, struct file *filp)
{
if (filp->private_data) {
/* free this file's context */
context_free((context_t *)filp->private_data);
filp->private_data = NULL;
}
return 0;
}
示例15: mls_range_allowed
static int mls_range_allowed(pam_handle_t *pamh, security_context_t src, security_context_t dst, int debug)
{
struct av_decision avd;
int retval;
unsigned int bit = CONTEXT__CONTAINS;
context_t src_context = context_new (src);
context_t dst_context = context_new (dst);
context_range_set(dst_context, context_range_get(src_context));
if (debug)
pam_syslog(pamh, LOG_NOTICE, "Checking if %s mls range valid for %s", dst, context_str(dst_context));
retval = security_compute_av(context_str(dst_context), dst, SECCLASS_CONTEXT, bit, &avd);
context_free(src_context);
context_free(dst_context);
if (retval || ((bit & avd.allowed) != bit))
return 0;
return 1;
}