gboolean rra_path_part_free(rra_path_part *in_pp) { ustr_free(in_pp->value); in_pp->value = NULL; ustr_free(in_pp->encoded); in_pp->encoded = NULL; rra_free_type(rra_path_part, in_pp); return TRUE; }
int main(int argc, char *argv[]) { const char *prog_name = NULL; Ustr *s1 = USTR_NULL; Ustr *s2 = USTR_NULL; if (!argc) exit (EXIT_FAILURE); if ((prog_name = strrchr(argv[0], '/'))) ++prog_name; else prog_name = argv[0]; if (argc != 2) die(prog_name, "missing operand"); if (!(s1 = ustr_dup_cstr(argv[1]))) die(prog_name, strerror(errno)); if (!(s2 = u_dirname(s1))) die(prog_name, strerror(errno)); ustr_free(s1); if (!ustr_io_putfileline(&s2, stderr)) die(prog_name, strerror(errno)); USTR_CNTL_MALLOC_CHECK_END(); exit (EXIT_SUCCESS); }
static gboolean free_action(rra_diff_action *in_action) { switch(in_action->action) { case RRA_DI_ADD_KEY: case RRA_DI_DELETE_KEY: case RRA_DI_HIVE_NAME_CHANGE: ustr_free((ustring*)in_action->data); break; case RRA_DI_ADD_VALUE: case RRA_DI_DELETE_VALUE: return rra_di_value_action_free( (rra_di_value_action*)in_action->data); break; case RRA_DI_VERSION_CHANGE: g_free(in_action->data); break; default: return FALSE; }; in_action->data = NULL; in_action->action = RRA_DI_NULL; rra_free_type(rra_diff_action, in_action); return TRUE; }
gboolean rra_di_value_action_free(rra_di_value_action *in_action) { ustr_free(in_action->path); ustr_free(in_action->name); if (in_action->val_old != NULL) { value_free(in_action->val_old); } if (in_action->val_new != NULL) { value_free(in_action->val_new); } rra_free_type(rra_di_value_action, in_action); return TRUE; }
void cell_debug_print_long (Cell *in_cell) { ustring *xml_out = ustr_new(); cell_get_xml_output(in_cell, xml_out, TRUE); fprintf (stderr, "%s", ustr_as_utf8(xml_out)); ustr_free(xml_out); }
static void mark_dirty(ACList *in_list) { if (in_list->sddl != NULL) { ustr_free(in_list->sddl); in_list->sddl = NULL; } }
/* Helper function called via semanage_fcontext_iterate() */ static int fcontext_matches(const semanage_fcontext_t *fcontext, void *varg) { const char *oexpr = semanage_fcontext_get_expr(fcontext); fc_match_handle_t *handp = varg; struct Ustr *expr; regex_t re; int type, retval = -1; /* Only match ALL or DIR */ type = semanage_fcontext_get_type(fcontext); if (type != SEMANAGE_FCONTEXT_ALL && type != SEMANAGE_FCONTEXT_ALL) return 0; /* Convert oexpr into a Ustr and anchor it at the beginning */ expr = ustr_dup_cstr("^"); if (expr == USTR_NULL) goto done; if (!ustr_add_cstr(&expr, oexpr)) goto done; /* Strip off trailing ".+" or ".*" */ if (ustr_cmp_suffix_cstr_eq(expr, ".+") || ustr_cmp_suffix_cstr_eq(expr, ".*")) { if (!ustr_del(&expr, 2)) goto done; } /* Strip off trailing "(/.*)?" */ if (ustr_cmp_suffix_cstr_eq(expr, "(/.*)?")) { if (!ustr_del(&expr, 6)) goto done; } if (ustr_cmp_suffix_cstr_eq(expr, "/")) { if (!ustr_del(&expr, 1)) goto done; } /* Append pattern to eat up trailing slashes */ if (!ustr_add_cstr(&expr, "/*$")) goto done; /* Check dir against expr */ if (regcomp(&re, ustr_cstr(expr), REG_EXTENDED) != 0) goto done; if (regexec(&re, handp->dir, 0, NULL, 0) == 0) handp->matched = 1; regfree(&re); retval = 0; done: ustr_free(expr); return retval; }
/** Cleans up a console. */ int bbconsole_done(BBWidget * widget, void * data) { BBConsole * self = bbwidget_console(widget); Lilis * aid; if(!self) return BBWIDGET_HANDLE_IGNORE; self->buf = mem_free(self->buf); ustr_free(self->input); self->input = NULL; ustrlist_done(&self->text); return BBWIDGET_HANDLE_OK; }
void uservinfo_debug_print(const UserVInfo *in_info) { ustring *ustr = ustr_new(); if (uservinfo_get_debug_output(in_info, ustr)) { fprintf (stderr, "%s", ustr_as_utf8(ustr)); } ustr_free(ustr); }
void sam_info_debug_print(const SamInfo *in_info) { const SamFKey *key = get_fkey(in_info); ustring *ustr = ustr_new(); #define OUTPUT_PART(name) \ do { \ ustr_printfa(ustr, "%s: ", #name); \ ustr_hexstreama(ustr, (guint8*)&key->name, 0, \ sizeof(key->name), ','); \ ustr_printfa(ustr, "\n"); \ } while(0) ustr_printfa(ustr, "Hexdump:\n"); ustr_hexdumpa(ustr, value_cell_get_data(in_info->vcell), 0, value_cell_get_data_length(in_info->vcell), TRUE, TRUE); OUTPUT_PART(id); OUTPUT_PART(u4); OUTPUT_PART(u8); OUTPUT_PART(autoinc); OUTPUT_PART(u20); OUTPUT_PART(max_password_age); OUTPUT_PART(min_password_age); OUTPUT_PART(u40); OUTPUT_PART(lockout_duration); OUTPUT_PART(lockout_reset); OUTPUT_PART(u64); OUTPUT_PART(next_rid); OUTPUT_PART(flags); OUTPUT_PART(min_pass); OUTPUT_PART(enforce_password_history); OUTPUT_PART(lockout_threshold); OUTPUT_PART(u78); OUTPUT_PART(u80); OUTPUT_PART(u84); OUTPUT_PART(u88); OUTPUT_PART(u92); OUTPUT_PART(u94); OUTPUT_PART(u96); OUTPUT_PART(u100); OUTPUT_PART(obf); ustr_printfa(ustr, "\n"); fprintf (stderr, "%s", ustr_as_utf8(ustr)); ustr_free(ustr); }
static void mark_dirty(UserVInfo *in_info) { int i; for (i = 0; i < UV_FIELD_COUNT; i++) { if (in_info->vals[i] != NULL) { ustr_free(in_info->vals[i]); in_info->vals[i] = NULL; } } if (in_info->secdesc != NULL) { secdesc_free(in_info->secdesc); in_info->secdesc = NULL; } }
/** Puts a string on the console .*/ int bbconsole_puts(BBConsole * self, const char * str) { int index; int size = strlen(str); int leftsize = size; int lines = 0; USTR_INFO uinfo; BBTextInfo info = { 0, 0, 0, 0}; info.maxwidth = bbwidget_w(&self->widget) - 10; USTR * ustr; const USTR * uline; ustr = ustr_new(str); while(bbtextinfo_linefromtext(&info, ustr, self->widget.style.font)) { uline = bbtextinfo_refustr(&info, &uinfo, ustr); bbconsole_addustr(self, uline); // don't forget to skip to next line!!! bbtextinfo_next(&info); } uline = bbtextinfo_refustr(&info, &uinfo, ustr); bbconsole_addustr(self, uline); ustr_free(ustr); return lines; }
int tst(void) { Ustr *s3 = ustr_dup_cstr("abcdefg xxxx xxxx xxxx xxxx1234yyyy yyyy yyyy zzz"); Ustr *s4 = NULL; Ustr *s5 = NULL; ASSERT(s3); ASSERT(ustr_spn_cstr_fwd(s3, 0, "abcd") == 4); ASSERT(ustr_spn_cstr_fwd(s3, 0, "abcdefg ") == 8); ASSERT(ustr_spn_cstr_fwd(s3, 0, "abcdefg x") == 27); ASSERT(ustr_cspn_cstr_fwd(s3, 0, "x") == 8); ASSERT(ustr_cspn_cstr_fwd(s3, 0, "21") == 27); ASSERT(ustr_spn_cstr_rev(s3, 0, "z") == 3); ASSERT(ustr_spn_cstr_rev(s3, 0, "az") == 3); ASSERT(ustr_spn_cstr_rev(s3, 0, "ayz") == 3); ASSERT(ustr_spn_cstr_rev(s3, 0, "ayz ") == 18); ASSERT(ustr_cspn_cstr_rev(s3, 0, "34") == 18); ASSERT(ustr_cspn_cstr_rev(s3, 0, " ") == 3); ASSERT(ustr_cspn_cstr_rev(s3, 0, "x") == 22); ASSERT(ustr_spn_cstr_fwd(s3, 0, " xayzafg1234bcde ") == ustr_len(s3)); ASSERT(ustr_spn_cstr_rev(s3, 0, "1234abcdefg xayz ") == ustr_len(s3)); ASSERT(ustr_cspn_cstr_fwd(s3, 0, "!") == ustr_len(s3)); ASSERT(ustr_cspn_cstr_rev(s3, 0, "!") == ustr_len(s3)); ASSERT(ustr_cspn_cstr_fwd(s3, 0, "!@#") == ustr_len(s3)); ASSERT(ustr_cspn_cstr_rev(s3, 0, "!@#") == ustr_len(s3)); ASSERT((s4 = ustr_dup_subustr(s3, 1, ustr_spn_cstr_fwd(s3, 0, "abcdefg ")))); ASSERT(ustr_del_subustr(&s3, 1, ustr_len(s4))); ASSERT((s5 = ustr_dup(s4))); ASSERT((s5 = ustr_dup(s4))); ASSERT(ustr_set_subustr(&s5, s3, 1, ustr_spn_cstr_fwd(s3, 0, "x "))); ASSERT(ustr_del_subustr(&s3, 1, ustr_len(s5))); ASSERT(ustr_spn_cstr_fwd(s4, 0, "abcd") == 4); ASSERT(ustr_spn_cstr_fwd(s4, 0, "abcdefg ") == 8); ASSERT(ustr_spn_cstr_fwd(s4, 1, "abcdefg ") == 7); ASSERT(ustr_spn_cstr_fwd(s4, 2, "abcdefg ") == 6); ASSERT(ustr_spn_cstr_fwd(s4, 3, "abcdefg ") == 5); ASSERT(ustr_spn_cstr_fwd(s4, 4, "abcdefg ") == 4); ASSERT(ustr_spn_cstr_fwd(s4, 5, "abcdefg ") == 3); ASSERT(ustr_spn_cstr_fwd(s4, 6, "abcdefg ") == 2); ASSERT(ustr_spn_cstr_fwd(s4, 7, "abcdefg ") == 1); ASSERT(ustr_spn_cstr_fwd(s4, 8, "abcdefg ") == 0); ASSERT(ustr_spn_cstr_rev(s3, 0, "z") == 3); ASSERT(ustr_spn_cstr_rev(s3, 4, "y") == 4); ASSERT(ustr_spn_cstr_rev(s3, 0, "az") == 3); ASSERT(ustr_spn_cstr_rev(s3, 0, "ayz") == 3); ASSERT(ustr_spn_cstr_rev(s3, 0, "ayz ") == 18); ASSERT(ustr_spn_cstr_rev(s3, 0, "y ") == 0); ASSERT(ustr_spn_cstr_rev(s3, 1, "y ") == 0); ASSERT(ustr_spn_cstr_rev(s3, 2, "y ") == 0); ASSERT(ustr_spn_cstr_rev(s3, 3, "y ") == 15); ASSERT(ustr_spn_cstr_rev(s3, 4, "y ") == 14); ASSERT(ustr_spn_cstr_rev(s3, 5, "y ") == 13); ASSERT(ustr_spn_cstr_rev(s3, 6, "y ") == 12); ASSERT(ustr_spn_cstr_rev(s3, 7, "y ") == 11); ASSERT(ustr_spn_cstr_rev(s3, 8, "y ") == 10); ASSERT(ustr_spn_cstr_rev(s3, 9, "y ") == 9); ASSERT(ustr_cspn_cstr_fwd(s4, 0, "e") == 4); ASSERT(ustr_cspn_cstr_fwd(s4, 0, "!-") == 8); ASSERT(ustr_cspn_cstr_fwd(s4, 1, "!-") == 7); ASSERT(ustr_cspn_cstr_fwd(s4, 2, "!-") == 6); ASSERT(ustr_cspn_cstr_fwd(s4, 3, "!-") == 5); ASSERT(ustr_cspn_cstr_fwd(s4, 4, "!-") == 4); ASSERT(ustr_cspn_cstr_fwd(s4, 5, "!-") == 3); ASSERT(ustr_cspn_cstr_fwd(s4, 6, "!-") == 2); ASSERT(ustr_cspn_cstr_fwd(s4, 7, "!-") == 1); ASSERT(ustr_cspn_cstr_fwd(s4, 8, "!-") == 0); ASSERT(ustr_cspn_cstr_fwd(s4, 0, "!") == 8); ASSERT(ustr_cspn_cstr_fwd(s4, 1, "!") == 7); ASSERT(ustr_cspn_cstr_fwd(s4, 2, "!") == 6); ASSERT(ustr_cspn_cstr_fwd(s4, 3, "!") == 5); ASSERT(ustr_cspn_cstr_fwd(s4, 4, "!") == 4); ASSERT(ustr_cspn_cstr_fwd(s4, 5, "!") == 3); ASSERT(ustr_cspn_cstr_fwd(s4, 6, "!") == 2); ASSERT(ustr_cspn_cstr_fwd(s4, 7, "!") == 1); ASSERT(ustr_cspn_cstr_fwd(s4, 8, "!") == 0); ASSERT(ustr_cspn_cstr_rev(s4, 0, "e") == 3); ASSERT(ustr_cspn_cstr_rev(s4, 0, "!-") == 8); ASSERT(ustr_cspn_cstr_rev(s4, 1, "!-") == 7); ASSERT(ustr_cspn_cstr_rev(s4, 2, "!-") == 6); ASSERT(ustr_cspn_cstr_rev(s4, 3, "!-") == 5); ASSERT(ustr_cspn_cstr_rev(s4, 4, "!-") == 4); ASSERT(ustr_cspn_cstr_rev(s4, 5, "!-") == 3); ASSERT(ustr_cspn_cstr_rev(s4, 6, "!-") == 2); ASSERT(ustr_cspn_cstr_rev(s4, 7, "!-") == 1); ASSERT(ustr_cspn_cstr_rev(s4, 8, "!-") == 0); ASSERT(ustr_cspn_cstr_rev(s4, 0, "!") == 8); ASSERT(ustr_cspn_cstr_rev(s4, 1, "!") == 7); ASSERT(ustr_cspn_cstr_rev(s4, 2, "!") == 6); ASSERT(ustr_cspn_cstr_rev(s4, 3, "!") == 5); ASSERT(ustr_cspn_cstr_rev(s4, 4, "!") == 4); ASSERT(ustr_cspn_cstr_rev(s4, 5, "!") == 3); ASSERT(ustr_cspn_cstr_rev(s4, 6, "!") == 2); ASSERT(ustr_cspn_cstr_rev(s4, 7, "!") == 1); ASSERT(ustr_cspn_cstr_rev(s4, 8, "!") == 0); ASSERT(ustr_cspn_cstr_rev(s3, 0, "34") == 18); ASSERT(ustr_cspn_cstr_rev(s3, 0, " ") == 3); ASSERT(ustr_cspn_cstr_rev(s3, 0, "x") == 22); ASSERT(ustr_spn_cstr_fwd(s3, 0, "1") == 1); ASSERT(ustr_spn_cstr_fwd(s3, 0, "12") == 2); ASSERT(ustr_spn_cstr_fwd(s3, 0, "123") == 3); ASSERT(ustr_spn_cstr_fwd(s3, 0, "1234") == 4); ASSERT(ustr_spn_cstr_fwd(s3, 0, "1234y") == 8); ASSERT(ustr_del_subustr(&s3, 4, 4)); ASSERT(ustr_spn_cstr_fwd(s3, 0, "1234y") == 4); ustr_free(s3); ustr_free(s4); /* leaked, see above */ ustr_free(s4); ustr_free(s5); return (EXIT_SUCCESS); }
int tst(void) { size_t end = USTR__SIZE_MAX; size_t large = 1; size_t small = 4096; size_t num = 0; Ustr *s3 = USTR1(\3, "124"); ASSERT((s1 = ustr_dupx_empty(0, 0, 0, 0))); ASSERT(ustr_size_alloc(s1) > 0); /* max 32bit overhead */ while (num < (1 + 4 + sizeof(USTR_END_ALOCDx))) { ASSERT(!ustr_add_undef(&s1, end - num)); ASSERT(!ustr_dup_undef( end - num)); ASSERT(!ustr_ins_undef(&s3, 1, end - num)); ASSERT(!ustr_set_undef(&s1, end - num)); ++num; } while (num < (1 + 4 + sizeof(USTR_END_ALOCDx) + ustr_len(s3))) { ASSERT(!ustr_ins_undef(&s3, 1, end - num)); ++num; } num = (1 + 4 + sizeof(USTR_END_ALOCDx)); if (!USTR_CONF_HAVE_64bit_SIZE_MAX) { big_tst(small, end, USTR_TRUE, USTR_TRUE); big_tst( 0, end, USTR_TRUE, USTR_TRUE); return (EXIT_FAILED_OK); } /* max 64bit overhead */ while (num < (1 + 2 + 8 + 8 + sizeof(USTR_END_ALOCDx))) { ASSERT(!ustr_add_undef(&s1, end - num)); ASSERT(!ustr_dup_undef( end - num)); ASSERT(!ustr_ins_undef(&s3, 1, end - num)); ASSERT(!ustr_set_undef(&s1, end - num)); ++num; } while (num < (1 + 2 + 8 + 8 + sizeof(USTR_END_ALOCDx) + ustr_len(s3))) { ASSERT(!ustr_ins_undef(&s3, 1, end - num)); ++num; } ustr_free(s1); if (USTR_CONF_USE_DYNAMIC_CONF) { assert(ustr_cntl_opt(USTR_CNTL_OPT_SET_REF_BYTES, 8)); assert(ustr_cntl_opt(USTR_CNTL_OPT_SET_HAS_SIZE, 0)); ASSERT((s1 = ustr_dupx_undef(0, 8, 0, 0, 0))); ASSERT(ustr_ro(s1)); ASSERT((s1 = ustr_dupx_undef(1, 8, 0, 0, 0))); ASSERT(ustr_ro(s1)); } ASSERT((s1 = ustr_dupx_empty(0, 8, USTR_FALSE, USTR_FALSE))); ASSERT(ustr_sized(s1)); ASSERT(ustr_size_alloc(s1) >= 14); ASSERT(ustr_size_overhead(s1) >= 14); ustr_free(ustr_dup(s1)); big_tst(small, end, USTR_TRUE, USTR_TRUE); big_tst( 0, end, USTR_TRUE, USTR_TRUE); large *= 1024; large *= 1024; large *= 1024; large *= 9; return (big_tst(0, large, USTR_FALSE, USTR_FALSE)); }
gchar * rra_di_action_to_string(const rra_diff_action *in_action) { switch(in_action->action) { case RRA_DI_ADD_KEY: return g_strdup_printf(_("ADD_KEY(%s)"), ustr_as_utf8((ustring*)in_action->data)); break; case RRA_DI_DELETE_KEY: return g_strdup_printf(_("DELETE_KEY(%s)"), ustr_as_utf8((ustring*)in_action->data)); break; case RRA_DI_ADD_VALUE: { rra_di_value_action *va = (rra_di_value_action*)in_action->data; ustring *val_str = value_get_as_string(va->val_new); gchar *ret_val = g_strdup_printf( _("ADD_VALUE(%s, %s, %s, %s)"), ustr_as_utf8(va->path), ustr_as_utf8(va->name), value_get_type_str(va->val_new), ustr_as_utf8(val_str)); ustr_free(val_str); return ret_val; } break; case RRA_DI_DELETE_VALUE: { rra_di_value_action *va = (rra_di_value_action*)in_action->data; ustring *val_str = value_get_as_string(va->val_old); gchar *ret_val = g_strdup_printf( _("DELETE_VALUE(%s, %s, %s, %s)"), ustr_as_utf8(va->path), ustr_as_utf8(va->name), value_get_type_str(va->val_old), ustr_as_utf8(val_str)); ustr_free(val_str); return ret_val; } break; case RRA_DI_CHANGE_VALUE: { rra_di_value_action *va = (rra_di_value_action*)in_action->data; ustring *val_old_str = value_get_as_string(va->val_old); ustring *val_new_str = value_get_as_string(va->val_new); gchar *ret_val = g_strdup_printf( _("CHANGE_VALUE(%s, %s, %s, %s, %s, %s)"), ustr_as_utf8(va->path), ustr_as_utf8(va->name), value_get_type_str(va->val_old), ustr_as_utf8(val_old_str), value_get_type_str(va->val_new), ustr_as_utf8(val_new_str)); ustr_free(val_old_str); ustr_free(val_new_str); return ret_val; } break; case RRA_DI_VERSION_CHANGE: return g_strdup_printf(_("HIVE_VERSION_CHANGE()")); break; case RRA_DI_HIVE_NAME_CHANGE: return g_strdup_printf(_("HIVE_NAME_CHANGE(%s)"), ustr_as_utf8((ustring*)in_action->data)); break; default: return g_strdup(_("Unknown action type")); }; }