int main(int argc, char **argv) { int r; setlocale(LC_ALL, ""); parse_opts(argc, argv); aug = aug_init(root, loadpath, flags|AUG_NO_ERR_CLOSE); if (aug == NULL || aug_error(aug) != AUG_NOERROR) { fprintf(stderr, "Failed to initialize Augeas\n"); if (aug != NULL) print_aug_error(); exit(EXIT_FAILURE); } add_transforms(transforms, transformslen); if (print_version) { print_version_info(); return EXIT_SUCCESS; } readline_init(); if (optind < argc) { // Accept one command from the command line r = run_args(argc - optind, argv+optind); } else { r = main_loop(); } if (history_file != NULL) write_history(history_file); return r == 0 ? EXIT_SUCCESS : EXIT_FAILURE; }
int elektraAugeasOpen (Plugin * handle, Key * parentKey) { augeas * augeasHandle; augeasHandle = aug_init (NULL, NULL, AUG_NO_MODL_AUTOLOAD | AUG_NO_ERR_CLOSE); int ret; if (aug_error (augeasHandle) != AUG_NOERROR) { char * errormessage; ret = asprintf (&errormessage, "Unable to initialize augeas: %s", aug_error_message (augeasHandle)); if (ret >= 0) { ELEKTRA_SET_ERROR (87, parentKey, "Unable to allocate memory for a detailed augeas error message"); return -1; } ELEKTRA_SET_ERROR (85, parentKey, errormessage); elektraFree (errormessage); return -1; } elektraPluginSetData (handle, augeasHandle); return 0; }
int main(int argc, char **argv) { int opt; int use_var = 0; const char *pattern = "/files//*"; struct timeval stop, start; while ((opt = getopt(argc, argv, "n")) != -1) { switch (opt) { case 'n': use_var = 1; break; default: fprintf(stderr, "Usage: %s [-n] [pattern]\n", argv[0]); fprintf(stderr, " without '-n', iterate matches\n"); fprintf(stderr, " with '-n', use a variable and aug_ns_*\n"); exit(EXIT_FAILURE); break; } } struct augeas *aug = aug_init(NULL, NULL, 0); if (optind < argc) pattern = argv[optind]; gettimeofday(&start, NULL); if (use_var) { dump_var(aug, pattern); } else { dump_match(aug, pattern); } gettimeofday(&stop, NULL); print_time_taken(&start, &stop); return 0; }
static void testSet(CuTest *tc) { int r; const char *value; struct augeas *aug; aug = aug_init(root, loadpath, AUG_NO_STDINC|AUG_NO_LOAD); CuAssertPtrNotNull(tc, aug); CuAssertIntEquals(tc, AUG_NOERROR, aug_error(aug)); /* aug_set returns 0 for a simple set */ r = aug_set(aug, "/augeas/testSet", "foo"); CuAssertIntEquals(tc, 0, r); CuAssertIntEquals(tc, AUG_NOERROR, aug_error(aug)); /* aug_set returns -1 when cannot set due to multiple nodes */ r = aug_set(aug, "/augeas/version/save/*", "foo"); CuAssertIntEquals(tc, -1, r); CuAssertIntEquals(tc, AUG_EMMATCH, aug_error(aug)); /* aug_set is able to set the context, even when currently invalid */ r = aug_set(aug, "/augeas/context", "( /files | /augeas )"); CuAssertIntEquals(tc, 0, r); CuAssertIntEquals(tc, AUG_NOERROR, aug_error(aug)); r = aug_get(aug, "/augeas/version", &value); CuAssertIntEquals(tc, -1, r); CuAssertIntEquals(tc, AUG_EMMATCH, aug_error(aug)); r = aug_set(aug, "/augeas/context", "/files"); CuAssertIntEquals(tc, 0, r); CuAssertIntEquals(tc, AUG_NOERROR, aug_error(aug)); aug_close(aug); }
/* We need to rewrite the root path so it is based at /sysroot. */ int do_aug_init (const char *root, int flags) { #ifdef HAVE_AUGEAS char *buf; if (aug) { aug_close (aug); aug = NULL; } buf = sysroot_path (root); if (!buf) { reply_with_perror ("malloc"); return -1; } aug = aug_init (buf, NULL, flags); free (buf); if (!aug) { reply_with_error ("Augeas initialization failed"); return -1; } return 0; #else NOT_AVAILABLE (-1); #endif }
static int Paug_init(lua_State *L) { augeas **a; struct aug_flagmap *f; const char *root = NULL, *loadpath = NULL; int flags = 0; if (lua_istable(L, 1)) { root = get_opt_string_field(L, 1, "root", NULL); loadpath = get_opt_string_field(L, 1, "loadpath", NULL); for (f = Taug_flagmap; f->name != NULL; f++) if (get_boolean_field(L, 1, f->name)) flags |= f->value; } else { root = luaL_optstring(L, 1, NULL); loadpath = luaL_optstring(L, 2, NULL); flags = luaL_optinteger(L, 3, AUG_NONE); } a = (augeas **) lua_newuserdata(L, sizeof(augeas *)); luaL_getmetatable(L, PAUG_META); lua_setmetatable(L, -2); *a = aug_init(root, loadpath, flags); if (*a == NULL) luaL_error(L, "aug_init failed"); return 1; }
/* Check that defining a variable leads to a corresponding entry in * /augeas/variables and that that entry disappears when the variable is * undefined */ static void testDefVarMeta(CuTest *tc) { int r; struct augeas *aug; static const char *const expr = "/augeas/version/save/mode"; const char *value; aug = aug_init(root, loadpath, AUG_NO_STDINC|AUG_NO_LOAD); CuAssertPtrNotNull(tc, aug); CuAssertIntEquals(tc, AUG_NOERROR, aug_error(aug)); r = aug_defvar(aug, "var", expr); CuAssertIntEquals(tc, 4, r); r = aug_match(aug, "/augeas/variables/*", NULL); CuAssertIntEquals(tc, 1, r); r = aug_get(aug, "/augeas/variables/var", &value); CuAssertStrEquals(tc, expr, value); r = aug_defvar(aug, "var", NULL); CuAssertIntEquals(tc, 0, r); r = aug_match(aug, "/augeas/variables/*", NULL); CuAssertIntEquals(tc, 0, r); aug_close(aug); }
/* Check that defining a variable with defnode leads to a corresponding * entry in /augeas/variables and that that entry disappears when the * variable is undefined */ static void testDefNodeCreateMeta(CuTest *tc) { int r, created; struct augeas *aug; static const char *const expr = "/augeas/version/save/mode[last()+1]"; static const char *const expr_can = "/augeas/version/save/mode[5]"; const char *value; aug = aug_init(root, loadpath, AUG_NO_STDINC|AUG_NO_LOAD); CuAssertPtrNotNull(tc, aug); CuAssertIntEquals(tc, AUG_NOERROR, aug_error(aug)); r = aug_defnode(aug, "var", expr, "other", &created); CuAssertIntEquals(tc, 1, r); CuAssertIntEquals(tc, 1, created); r = aug_match(aug, "/augeas/variables/*", NULL); CuAssertIntEquals(tc, 1, r); r = aug_get(aug, "/augeas/variables/var", &value); CuAssertStrEquals(tc, expr_can, value); r = aug_defvar(aug, "var", NULL); CuAssertIntEquals(tc, 0, r); r = aug_match(aug, "/augeas/variables/*", NULL); CuAssertIntEquals(tc, 0, r); aug_close(aug); }
int audit_crontab_delete(char *path, int sorf) { int r = 0; if (cannot_audit(0)) { return (0); } else { char *anc_name; anc_name = audit_cron_make_anc_name(path); if (anc_name != NULL) { r = unlink(anc_name); free(anc_name); } else r = -1; aug_init(); (void) aug_save_me(); aug_save_path(path); aug_save_event(AUE_crontab_delete); aug_save_sorf(sorf); if (aug_audit() != 0) return (-1); return (r); } }
bool augeas_init() { fs::path incl_path = getConfigPath(fs::path(MODULE_CONFDIR)); if(!fs::exists(incl_path)) { // Complain hard; even if we can create it, any files won't be picked up // after we've done aug_load. And user probably wont have any use of an empty // dir anyway, so tell him to fix it instead. AGO_ERROR() << "Cannot use " << incl_path << " as confdir, does not exist"; return false; } else if (!fs::is_directory(incl_path)) { AGO_ERROR() << "Cannot use " << incl_path << " as confdir, not a directory"; return false; } incl_path /= "*.conf"; // Look for augeas lens files in conf path too, in case // we have not installed globally fs::path extra_loadpath = getConfigPath(); if(augeas) { // Re-init aug_close(augeas); } AGO_TRACE() << "Loading Augeas with extra_loadpath=" << extra_loadpath.string() << " and include path=" << incl_path.string(); augeas = aug_init(NULL, extra_loadpath.c_str(), AUG_SAVE_BACKUP | AUG_NO_MODL_AUTOLOAD); if (augeas == NULL) { AGO_ERROR() << "Can't initalize augeas"; return false; } aug_set(augeas, "/augeas/load/Agocontrol/lens", "agocontrol.lns"); aug_set(augeas, "/augeas/load/Agocontrol/incl", incl_path.c_str()); if (aug_load(augeas) != 0) { // We can get errors below, even if we have 0 AGO_ERROR() << "Augeas load ret -1"; } if(aug_error(augeas)) { std::string err = augeasGetError(); AGO_ERROR() << "Augeas error: " << err; aug_close(augeas); augeas = NULL; return false; }else AGO_TRACE() << "Augeas inited without errors"; return true; }
static int switch_auth(const char *value, char **msg) { const char* sshdpid_env; augeas *augeas_running; char *path = NULL; asprintf(&path, "/files/%s/PasswordAuthentication", NETOPEER_SSHD_CONF); if (aug_set(sysaugeas, path, value) == -1) { asprintf(msg, "Unable to set PasswordAuthentication to \"%s\" (%s).", value, aug_error_message(sysaugeas)); free(path); return (EXIT_FAILURE); } free(path); path = NULL; /* Save the changes made by children callbacks via augeas */ if (augeas_save(msg) != 0) { return (EXIT_FAILURE); } asprintf(&path, "/files/%s.running", NETOPEER_SSHD_CONF); if ((sshdpid_env = getenv("SSHD_PID")) != NULL && access(path, F_OK) == 0) { /* we have info about listening SSH server, update its config and make * it reload the configuration. If something get wrong, still return * success, new settings just will be applied after the SSH server * reboot (if the settings will be stored also into startup datastore). */ augeas_running = aug_init(NULL, NULL, AUG_NO_MODL_AUTOLOAD | AUG_NO_ERR_CLOSE); if (aug_error(augeas_running) != AUG_NOERROR) { free(path); return EXIT_SUCCESS; } aug_set(augeas_running, "/augeas/load/Sshd/lens", "Sshd.lns"); aug_set(augeas_running, "/augeas/load/Sshd/incl", path); free(path); path = NULL; aug_load(augeas_running); if (aug_match(augeas_running, "/augeas//error", NULL) != 0) { aug_close(augeas_running); return EXIT_SUCCESS; } asprintf(&path, "/files/%s.running/PasswordAuthentication", NETOPEER_SSHD_CONF); if (aug_set(augeas_running, path, value) == 0 && aug_save(augeas_running) == 0) { /* make the server to reload configuration */ kill(atoi(sshdpid_env), SIGHUP); } free(path); aug_close(augeas_running); } return (EXIT_SUCCESS); }
VALUE augeas_init(VALUE m, VALUE r, VALUE l, VALUE f) { unsigned int flags = NUM2UINT(f); const char *root = StringValueCStrOrNull(r); const char *loadpath = StringValueCStrOrNull(l); augeas *aug = NULL; aug = aug_init(root, loadpath, flags); if (aug == NULL) { rb_raise(rb_eSystemCallError, "Failed to initialize Augeas"); } return Data_Wrap_Struct(c_augeas, NULL, augeas_free, aug); }
static int run_one_test(struct test *test) { int r; struct augeas *aug = NULL; struct memstream ms; int result = 0; MEMZERO(&ms, 1); aug = aug_init("/dev/null", lensdir, AUG_NO_STDINC|AUG_NO_MODL_AUTOLOAD); fail(aug == NULL, "aug_init"); fail(aug_error(aug) != AUG_NOERROR, "aug_init: errcode was %d", aug_error(aug)); printf("%-30s ... ", test->name); r = load_module(aug, test); if (r < 0) goto error; r = init_memstream(&ms); fail(r < 0, "init_memstream"); r = aug_srun(aug, ms.stream, test->cmd); fail(r != test->result, "return value: expected %d, actual %d", test->result, r); fail(aug_error(aug) != test->errcode, "errcode: expected %s, actual %s", errtokens[test->errcode], errtokens[aug_error(aug)]); r = close_memstream(&ms); fail(r < 0, "close_memstream"); fail(ms.buf == NULL, "close_memstream left buf NULL"); if (test->out != NULL) { fail(STRNEQ(ms.buf, test->out), "output: expected '%s', actual '%s'", test->out, ms.buf); } else if (test->out_present) { fail(strlen(ms.buf) == 0, "output: expected some output"); } else { fail(strlen(ms.buf) > 0, "output: expected nothing, actual '%s'", ms.buf); } printf("PASS\n"); done: free(ms.buf); aug_close(aug); return result; error: result = -1; goto done; }
static void testSetM(CuTest *tc) { int r; struct augeas *aug; aug = aug_init(root, loadpath, AUG_NO_STDINC|AUG_NO_LOAD); CuAssertPtrNotNull(tc, aug); CuAssertIntEquals(tc, AUG_NOERROR, aug_error(aug)); /* Change base nodes when SUB is NULL */ r = aug_setm(aug, "/augeas/version/save/*", NULL, "changed"); CuAssertIntEquals(tc, 4, r); r = aug_match(aug, "/augeas/version/save/*[. = 'changed']", NULL); CuAssertIntEquals(tc, 4, r); /* Only change existing nodes */ r = aug_setm(aug, "/augeas/version/save", "mode", "again"); CuAssertIntEquals(tc, 4, r); r = aug_match(aug, "/augeas/version/save/*", NULL); CuAssertIntEquals(tc, 4, r); r = aug_match(aug, "/augeas/version/save/*[. = 'again']", NULL); CuAssertIntEquals(tc, 4, r); /* Create a new node */ r = aug_setm(aug, "/augeas/version/save", "mode[last() + 1]", "newmode"); CuAssertIntEquals(tc, 1, r); r = aug_match(aug, "/augeas/version/save/*", NULL); CuAssertIntEquals(tc, 5, r); r = aug_match(aug, "/augeas/version/save/*[. = 'again']", NULL); CuAssertIntEquals(tc, 4, r); r = aug_match(aug, "/augeas/version/save/*[last()][. = 'newmode']", NULL); CuAssertIntEquals(tc, 1, r); /* Noexistent base */ r = aug_setm(aug, "/augeas/version/save[last()+1]", "mode", "newmode"); CuAssertIntEquals(tc, 0, r); /* Invalid path expressions */ r = aug_setm(aug, "/augeas/version/save[]", "mode", "invalid"); CuAssertIntEquals(tc, -1, r); r = aug_setm(aug, "/augeas/version/save/*", "mode[]", "invalid"); CuAssertIntEquals(tc, -1, r); aug_close(aug); }
/* ARGSUSED */ int audit_shutdown_setup(int argc, char **argv) { dprintf(("audit_shutdown_setup()\n")); if (cannot_audit(0)) { return (0); } (void) aug_init(); aug_save_event(AUE_shutdown_solaris); (void) aug_save_me(); return (0); }
static gchar * network_interfaces () { augeas *aug; gchar *value = NULL, **if_match, **option_match, *path, *result, *p, option[128]; gint if_number, option_number, i, j; aug = aug_init (NULL, NULL, AUG_NONE | AUG_NO_ERR_CLOSE | AUG_NO_MODL_AUTOLOAD); aug_set (aug, "/augeas/load/Interfaces/lens", "Interfaces.lns"); aug_set (aug, "/augeas/load/Interfaces/incl", "/etc/network/interfaces"); aug_load (aug); aug_get (aug, "//files/etc/network/interfaces", (const gchar **)&value); if_number = aug_match (aug, "//files/etc/network/interfaces/iface[.!='lo']", &if_match); result = g_strdup ("["); for (i = 0; i < if_number; i++) { aug_get (aug, if_match[i], (const gchar **)&value); p = result; result = g_strdup_printf ("%s{\"name\": \"%s\",", p, value); g_free (p); p = g_strdup_printf ("//files/etc/network/interfaces/iface[.='%s']/*", value); option_number = aug_match (aug, p, &option_match); g_free (p); for (j = 0; j < option_number; j++) { sscanf (option_match[j], "%*[^]]]/%[^/]", option); if (g_str_has_prefix (option, "#comment")) { continue; } aug_get (aug, option_match[j], (const gchar **)&value); p = result; result = g_strdup_printf ("%s\n\"%s\": \"%s\",", p, option, value); g_free (p); g_free (option_match[j]); } g_free (option_match); g_free (if_match[i]); result[strlen (result) - 1] = '}'; p = result; result = g_strdup_printf ("%s,", p); g_free (p); } g_free (if_match); aug_close (aug); result[strlen (result) - 1] = ']'; return result; }
int elektraAugeasOpen(Plugin *handle, Key *parentKey) { augeas *augeasHandle; augeasHandle = aug_init (NULL, NULL, AUG_NO_MODL_AUTOLOAD | AUG_NO_ERR_CLOSE); if (aug_error (augeasHandle) != AUG_NOERROR) { char *errormessage; asprintf (&errormessage, "Unable to initialize augeas: %s", aug_error_message (augeasHandle)); ELEKTRA_SET_ERROR(85, parentKey, errormessage); free (errormessage); return -1; } elektraPluginSetData (handle, augeasHandle); return 0; }
static void setup(CuTest *tc) { char *lensdir; if (asprintf(&root, "%s/build/test-save/%s", abs_top_builddir, tc->name) < 0) { CuFail(tc, "failed to set root"); } if (asprintf(&lensdir, "%s/lenses", abs_top_srcdir) < 0) CuFail(tc, "asprintf lensdir failed"); run(tc, "test -d %s && chmod -R u+w %s || :", root, root); run(tc, "rm -rf %s", root); run(tc, "mkdir -p %s", root); run(tc, "cp -pr %s/* %s", src_root, root); run(tc, "chmod -R u+w %s", root); aug = aug_init(root, lensdir, AUG_NO_STDINC); CuAssertPtrNotNull(tc, aug); }
static void testGet(CuTest *tc) { int r; const char *value; struct augeas *aug; aug = aug_init(root, loadpath, AUG_NO_STDINC|AUG_NO_LOAD); CuAssertPtrNotNull(tc, aug); CuAssertIntEquals(tc, AUG_NOERROR, aug_error(aug)); /* Make sure we're looking at the right thing */ r = aug_match(aug, "/augeas/version/save/*", NULL); CuAssertTrue(tc, r > 1); CuAssertIntEquals(tc, AUG_NOERROR, aug_error(aug)); /* aug_get returns 1 and the value if exactly one node matches */ r = aug_get(aug, "/augeas/version/save/*[1]", &value); CuAssertIntEquals(tc, 1, r); CuAssertPtrNotNull(tc, value); CuAssertIntEquals(tc, AUG_NOERROR, aug_error(aug)); /* aug_get returns 0 and no value when no node matches */ r = aug_get(aug, "/augeas/version/save/*[ last() + 1 ]", &value); CuAssertIntEquals(tc, 0, r); CuAssertPtrEquals(tc, NULL, value); CuAssertIntEquals(tc, AUG_NOERROR, aug_error(aug)); /* aug_get should return an error when multiple nodes match */ r = aug_get(aug, "/augeas/version/save/*", &value); CuAssertIntEquals(tc, -1, r); CuAssertPtrEquals(tc, NULL, value); CuAssertIntEquals(tc, AUG_EMMATCH, aug_error(aug)); /* augeas should prepend context if relative path given */ r = aug_set(aug, "/augeas/context", "/augeas/version"); r = aug_get(aug, "save/*[1]", &value); CuAssertIntEquals(tc, 1, r); CuAssertPtrNotNull(tc, value); CuAssertIntEquals(tc, AUG_NOERROR, aug_error(aug)); /* augeas should still work with an empty context */ r = aug_set(aug, "/augeas/context", ""); r = aug_get(aug, "/augeas/version", &value); CuAssertIntEquals(tc, 1, r); CuAssertPtrNotNull(tc, value); CuAssertIntEquals(tc, AUG_NOERROR, aug_error(aug)); /* augeas should ignore trailing slashes in context */ r = aug_set(aug, "/augeas/context", "/augeas/version/"); r = aug_get(aug, "save/*[1]", &value); CuAssertIntEquals(tc, 1, r); CuAssertPtrNotNull(tc, value); CuAssertIntEquals(tc, AUG_NOERROR, aug_error(aug)); /* augeas should create non-existent context path */ r = aug_set(aug, "/augeas/context", "/context/foo"); r = aug_set(aug, "bar", "value"); r = aug_get(aug, "/context/foo/bar", &value); CuAssertIntEquals(tc, 1, r); CuAssertPtrNotNull(tc, value); CuAssertIntEquals(tc, AUG_NOERROR, aug_error(aug)); aug_close(aug); }
const char *cvalue = StringValueCStrOrNull(value); /* FIXME: Figure out a way to return created, maybe accept a block that gets run when created == 1 ? */ int r = aug_defnode(aug, cname, cexpr, cvalue, NULL); return (r < 0) ? Qfalse : INT2NUM(r); } static VALUE init(VALUE class, VALUE m, VALUE r, VALUE l, VALUE f) { unsigned int flags = NUM2UINT(f); const char *root = StringValueCStrOrNull(r); const char *loadpath = StringValueCStrOrNull(l); augeas *aug = NULL; aug = aug_init(root, loadpath, flags); if (aug == NULL) { rb_raise(rb_eSystemCallError, "Failed to initialize Augeas"); } return Data_Wrap_Struct(class, NULL, augeas_free, aug); } VALUE augeas_init(VALUE m, VALUE r, VALUE l, VALUE f) { return init(c_augeas, m, r, l, f); } VALUE facade_init(VALUE m, VALUE r, VALUE l, VALUE f) { return init(c_facade, m, r, l, f); } VALUE augeas_close (VALUE s) {
int main(int argc, char **argv) { int opt; struct augeas *aug; char *loadpath = NULL; size_t loadpathlen = 0; enum { VAL_NO_STDINC = CHAR_MAX + 1, VAL_NO_TYPECHECK = VAL_NO_STDINC + 1, VAL_VERSION = VAL_NO_TYPECHECK + 1 }; struct option options[] = { { "help", 0, 0, 'h' }, { "include", 1, 0, 'I' }, { "trace", 0, 0, 't' }, { "nostdinc", 0, 0, VAL_NO_STDINC }, { "notypecheck", 0, 0, VAL_NO_TYPECHECK }, { "version", 0, 0, VAL_VERSION }, { 0, 0, 0, 0} }; int idx; unsigned int flags = AUG_TYPE_CHECK|AUG_NO_MODL_AUTOLOAD; progname = argv[0]; setlocale(LC_ALL, ""); while ((opt = getopt_long(argc, argv, "hI:t", options, &idx)) != -1) { switch(opt) { case 'I': argz_add(&loadpath, &loadpathlen, optarg); break; case 't': flags |= AUG_TRACE_MODULE_LOADING; break; case 'h': usage(); break; case VAL_NO_STDINC: flags |= AUG_NO_STDINC; break; case VAL_NO_TYPECHECK: flags &= ~(AUG_TYPE_CHECK); break; case VAL_VERSION: print_version = true; break; default: usage(); break; } } if (!print_version && optind >= argc) { fprintf(stderr, "Expected .aug file\n"); usage(); } argz_stringify(loadpath, loadpathlen, PATH_SEP_CHAR); aug = aug_init(NULL, loadpath, flags); if (aug == NULL) { fprintf(stderr, "Memory exhausted\n"); return 2; } if (print_version) { print_version_info(aug); return EXIT_SUCCESS; } if (__aug_load_module_file(aug, argv[optind]) == -1) { fprintf(stderr, "%s\n", aug_error_message(aug)); const char *s = aug_error_details(aug); if (s != NULL) { fprintf(stderr, "%s\n", s); } exit(EXIT_FAILURE); } aug_close(aug); free(loadpath); }
static gchar * set_network_interfaces (RequestData *request_data) { gchar *interfaces, *result, *name, *path, *value; augeas *aug; JSON_Value *val; JSON_Array *array; JSON_Object *obj; gint if_count, i, ret; aug = aug_init (NULL, NULL, AUG_NONE | AUG_NO_ERR_CLOSE | AUG_NO_MODL_AUTOLOAD); aug_set (aug, "/augeas/load/Interfaces/lens", "Interfaces.lns"); aug_set (aug, "/augeas/load/Interfaces/incl", "/etc/network/interfaces"); aug_load (aug); interfaces = request_data->raw_request + request_data->header_size; val = json_parse_string (interfaces); if (val == NULL) { GST_ERROR ("parse json type interfaces failure"); result = g_strdup_printf ("{\n \"result\": \"failure\",\n \"reason\": \"invalid data\"\n}"); aug_close (aug); return result; } array = json_value_get_array (val); if (array == NULL) { GST_ERROR ("get interfaces array failure"); result = g_strdup_printf ("{\n \"result\": \"failure\",\n \"reason\": \"not array type interfaces\"\n}"); aug_close (aug); json_value_free (val); return result; } if_count = json_array_get_count (array); for (i = 0; i < if_count; i++) { obj = json_array_get_object (array, i); name = (gchar *)json_object_get_string (obj, "name"); value = (gchar *)json_object_get_string (obj, "method"); if (value != NULL) { path = g_strdup_printf ("//files/etc/network/interfaces/iface[.='%s']/method", name); aug_set (aug, path, value); g_free (path); } value = (gchar *)json_object_get_string (obj, "address"); if (value != NULL) { path = g_strdup_printf ("//files/etc/network/interfaces/iface[.='%s']/address", name); ret = aug_set (aug, path, value); g_free (path); } value = (gchar *)json_object_get_string (obj, "netmask"); if (value != NULL) { path = g_strdup_printf ("//files/etc/network/interfaces/iface[.='%s']/netmask", name); aug_set (aug, path, value); g_free (path); } value = (gchar *)json_object_get_string (obj, "network"); if (value != NULL) { path = g_strdup_printf ("//files/etc/network/interfaces/iface[.='%s']/network", name); aug_set (aug, path, value); g_free (path); } value = (gchar *)json_object_get_string (obj, "broadcast"); if (value != NULL) { path = g_strdup_printf ("//files/etc/network/interfaces/iface[.='%s']/broadcast", name); aug_set (aug, path, value); g_free (path); } value = (gchar *)json_object_get_string (obj, "gateway"); if (value != NULL) { path = g_strdup_printf ("//files/etc/network/interfaces/iface[.='%s']/gateway", name); aug_set (aug, path, value); g_free (path); } } if (aug_save (aug) == -1) { aug_get (aug, "/augeas//error", (const gchar **)&value); GST_ERROR ("set /etc/network/interface failure: %s", value); result = g_strdup_printf ("{\n \"result\": \"failure\",\n \"reason\": \"%s\"\n}", value); } else { result = g_strdup ("{\n \"result\": \"success\"\n}"); } json_value_free (val); aug_close (aug); return result; }
int audit_crontab_modify(char *path, char *tmp_path, int sorf) { int r, create = 0; char *diffs = NULL; if (cannot_audit(0)) { return (0); } else { au_event_t event; char *anc_name; auditinfo_addr_t ai; if (getaudit_addr(&ai, sizeof (ai))) { return (-1); } r = audit_crontab_get_diffs(path, tmp_path, &diffs); if (r == AUDIT_GET_DIFFS_NO_DIFFS) { return (0); } if (diffs != NULL && r != AUDIT_GET_DIFFS_ERR) { aug_save_text(diffs); free(diffs); } if (r == AUDIT_GET_DIFFS_NO_CRONTAB) { create = 1; if (diffs == NULL) aug_save_text(""); } /* * create an ancilary file if audit characteristics exist * else delete an ancilary if if one exists */ anc_name = audit_cron_make_anc_name(path); if (anc_name == NULL) r = -1; else if (audit_crontab_process_not_audited()) { (void) unlink(anc_name); free(anc_name); } else { r = audit_cron_setinfo(anc_name, &ai); free(anc_name); } aug_init(); aug_save_auid(ai.ai_auid); aug_save_euid(geteuid()); aug_save_egid(getegid()); aug_save_uid(getuid()); aug_save_gid(getgid()); aug_save_pid(getpid()); aug_save_asid(ai.ai_asid); aug_save_tid_ex(ai.ai_termid.at_port, ai.ai_termid.at_addr, ai.ai_termid.at_type); aug_save_path(path); event = (create) ? AUE_crontab_create : AUE_crontab_mod; aug_save_event(event); aug_save_sorf(sorf); if (aug_audit() != 0) return (-1); return (r); } }