/* Check that loading and saving a file given with a relative path * works. Bug #238 */ static void testRelPath(CuTest *tc) { int r; r = aug_rm(aug, "/augeas/load/*"); CuAssertPositive(tc, r); r = aug_set(aug, "/augeas/load/Hosts/lens", "Hosts.lns"); CuAssertRetSuccess(tc, r); r = aug_set(aug, "/augeas/load/Hosts/incl", "etc/hosts"); CuAssertRetSuccess(tc, r); r = aug_load(aug); CuAssertRetSuccess(tc, r); r = aug_match(aug, "/files/etc/hosts/1/alias[ . = 'new']", NULL); CuAssertIntEquals(tc, 0, r); r = aug_set(aug, "/files/etc/hosts/1/alias[last() + 1]", "new"); CuAssertRetSuccess(tc, r); r = aug_save(aug); CuAssertRetSuccess(tc, r); r = aug_match(aug, "/augeas//error", NULL); CuAssertIntEquals(tc, 0, r); /* Force reloading the file */ r = aug_rm(aug, "/augeas/files//mtime"); CuAssertPositive(tc, r); r = aug_load(aug); CuAssertRetSuccess(tc, r); r = aug_match(aug, "/files/etc/hosts/1/alias[. = 'new']", NULL); CuAssertIntEquals(tc, 1, r); }
int ntp_add_server(const char* udp_address, const char* association_type, bool iburst, bool prefer, char** msg) { int ret; char* path = NULL, *srv_path = NULL; assert(udp_address); assert(association_type); asprintf(&path, "/files/%s/%s", AUGEAS_NTP_CONF, association_type); ret = aug_match(sysaugeas, path, NULL); if (ret == -1) { asprintf(msg, "Augeas match for \"%s\" failed: %s", path, aug_error_message(sysaugeas)); free(path); return EXIT_FAILURE; } free(path); /* add new item after the last one */ ret++; asprintf(&srv_path, "/files/%s/%s[%d]", AUGEAS_NTP_CONF, association_type, ret); if (aug_set(sysaugeas, srv_path, udp_address) == -1) { asprintf(msg, "Setting NTP %s \"%s\" failed: %s", association_type, udp_address, aug_error_message(sysaugeas)); free(srv_path); return EXIT_FAILURE; } if (iburst) { path = NULL; asprintf(&path, "/files/%s/%s[%d]/iburst", AUGEAS_NTP_CONF, association_type, ret); if (aug_set(sysaugeas, path, NULL) == -1) { asprintf(msg, "Setting iburst option for %s \"%s\" failed: %s", association_type, udp_address, aug_error_message(sysaugeas)); free(path); aug_rm(sysaugeas, srv_path); free(srv_path); return EXIT_FAILURE; } free(path); } if (prefer) { path = NULL; asprintf(&path, "/files/%s/%s[%d]/prefer", AUGEAS_NTP_CONF, association_type, ret); if (aug_set(sysaugeas, path, NULL) == -1) { asprintf(msg, "Setting prefer option for %s \"%s\" failed: %s", association_type, udp_address, aug_error_message(sysaugeas)); free(path); aug_rm(sysaugeas, srv_path); free(srv_path); return EXIT_FAILURE; } free(path); } free(srv_path); return EXIT_SUCCESS; }
/** * Checks whether a given path must be pruned from the Augeas tree by comparing * it with the supplied keyset. If any operation during pruning fails, an error * is returned in order to prevent invalid keys. */ static int removeOrphan (augeas * handle, const char * treePath, void * data) { int result; struct OrphanSearch * orphanData = (struct OrphanSearch *)data; Key * key = createKeyFromPath (orphanData->parentKey, treePath); if (!ksLookup (orphanData->ks, key, KDB_O_NONE)) { char * nodeMatch; char ** matches; result = asprintf (&nodeMatch, "%s/*", treePath); if (result < 0) return -1; int numChildNodes = aug_match (handle, nodeMatch, &matches); elektraFree (nodeMatch); /* if the node is a leaf node we can safely delete it */ if (numChildNodes == 0) { aug_rm (handle, treePath); } else { short pruneTree = 1; for (int i = 0; i < numChildNodes; i++) { Key * childKey = createKeyFromPath (orphanData->parentKey, matches[i]); if (ksLookup (orphanData->ks, childKey, KDB_O_NONE)) { pruneTree = 0; } keyDel (childKey); elektraFree (matches[i]); } elektraFree (matches); if (pruneTree) { aug_rm (handle, treePath); } } } keyDel (key); return 0; }
int dns_rm_opt_attempts(void) { const char* path = "/files/"AUGEAS_DNS_CONF"/options/timeout"; aug_rm(sysaugeas, path); return EXIT_SUCCESS; }
int dns_rm_search_domain(const char* domain, char** msg) { int i, ret; const char* path = "/files/"AUGEAS_DNS_CONF"/search/domain"; char** matches; const char* value; assert(domain); if ((ret = aug_match(sysaugeas, path, &matches)) == -1) { asprintf(msg, "Augeas match for \"%s\" failed: %s", path, aug_error_message(sysaugeas)); return EXIT_FAILURE; } for (i = 0; i < ret; ++i) { aug_get(sysaugeas, matches[i], &value); if (strcmp(value, domain) == 0) { if (ret == 1) { /* Last search domain, delete the whole search node */ *strrchr(matches[0], '/') = '\0'; } aug_rm(sysaugeas, matches[i]); break; } } /* cleanup */ for (i = 0; i < ret; ++i) { free(matches[i]); } free(matches); return EXIT_SUCCESS; }
/* * call-seq: * rm(PATH) -> int * * Remove path and all its children. Returns the number of entries removed */ VALUE augeas_rm(VALUE s, VALUE path, VALUE sibling) { augeas *aug = aug_handle(s); const char *cpath = StringValueCStr(path) ; int callValue = aug_rm(aug, cpath) ; return INT2FIX(callValue) ; }
int dns_add_search_domain(const char* domain, int index, char** msg) { int ret; char* path; assert(domain); assert(index >= 1); if (domain == NULL || index < 1) { asprintf(msg, "NULL arguments."); return EXIT_FAILURE; } switch (ret = aug_match(sysaugeas, "/files/"AUGEAS_DNS_CONF"/search/domain", NULL)) { case -1: asprintf(msg, "Augeas match for \"%s\" failed: %s", "/files/"AUGEAS_DNS_CONF"/search/domain", aug_error_message(sysaugeas)); return EXIT_FAILURE; case 0: /* First domain to be added */ if (index != 1) { asprintf(msg, "Configuration data (dns-resolver search domains) are inconsistent with system configuration file (code 1)."); return EXIT_FAILURE; } break; default: /* Some domains already in the config file */ if ((index - ret) > 1) { asprintf(msg, "Configuration data (dns-resolver search domains) are inconsistent with system configuration file (code 2)."); return EXIT_FAILURE; } /* insert new (empty) node */ if (index == 1) { if (aug_insert(sysaugeas, "/files/"AUGEAS_DNS_CONF"/search/domain[1]", "domain", 1) == -1) { asprintf(msg, "Inserting DNS search domain configuration before \"%s\" failed (%s)", "/files/"AUGEAS_DNS_CONF"/search/domain[1]", aug_error_message(sysaugeas)); return (EXIT_FAILURE); } } else { asprintf(&path, "/files/%s/search/domain[%d]", AUGEAS_DNS_CONF, index - 1); if (aug_insert(sysaugeas, path, "domain", 0) == -1) { asprintf(msg, "Inserting DNS search domain configuration after \"%s\" failed (%s)", path, aug_error_message(sysaugeas)); free(path); return (EXIT_FAILURE); } free(path); path = NULL; } } /* Set the value of the newly inserted node (or possibly create it, too) */ asprintf(&path, "/files/%s/search/domain[%d]", AUGEAS_DNS_CONF, index); if (aug_set(sysaugeas, path, domain) == -1) { aug_rm(sysaugeas, path); /* previously inserted, do rollback */ asprintf(msg, "Unable to set DNS search domain \"%s\" (%s).", domain, aug_error_message(sysaugeas)); free(path); return EXIT_FAILURE; } free(path); return EXIT_SUCCESS; }
int ntp_rm_server(const char* udp_address, const char* association_type, bool iburst, bool prefer, char** msg) { int ret, i, j; char* path; const char* value; char** matches = NULL; assert(udp_address); assert(association_type); path = NULL; asprintf(&path, "/files/%s/%s", AUGEAS_NTP_CONF, association_type); ret = aug_match(sysaugeas, path, &matches); if (ret == -1) { asprintf(msg, "Augeas match for \"%s\" failed: %s", path, aug_error_message(sysaugeas)); free(path); return EXIT_FAILURE; } free(path); for (i = 0; i < ret; ++i) { aug_get(sysaugeas, matches[i], &value); if (value == NULL || strcmp(value, udp_address) != 0) { continue; } path = NULL; asprintf(&path, "/files/%s/%s[%d]/iburst", AUGEAS_NTP_CONF, association_type, i + 1); j = aug_match(sysaugeas, path, NULL); free(path); if ((iburst && j != 1) || (!iburst && j != 0)) { continue; } path = NULL; asprintf(&path, "/files/%s/%s[%d]/prefer", AUGEAS_NTP_CONF, association_type, i + 1); j = aug_match(sysaugeas, path, NULL); free(path); if ((prefer && j != 1) || (!prefer && j != 0)) { continue; } /* remove item and finish */ aug_rm(sysaugeas, matches[i]); break; } /* cleanup */ for (i = 0; i < ret; ++i) { free(matches[i]); } free(matches); return EXIT_SUCCESS; }
static void testNonExistentLens(CuTest *tc) { int r; r = aug_rm(aug, "/augeas/load/*"); CuAssertTrue(tc, r >= 0); r = aug_set(aug, "/augeas/load/Fake/lens", "Fake.lns"); CuAssertIntEquals(tc, 0, r); r = aug_set(aug, "/augeas/load/Fake/incl", "/fake"); CuAssertIntEquals(tc, 0, r); r = aug_set(aug, "/files/fake/entry", "value"); CuAssertIntEquals(tc, 0, r); r = aug_save(aug); CuAssertIntEquals(tc, -1, r); r = aug_error(aug); CuAssertIntEquals(tc, AUG_ENOLENS, r); }
int do_aug_rm (const char *path) { #ifdef HAVE_AUGEAS int r; NEED_AUG (-1); r = aug_rm (aug, path); if (r == -1) { reply_with_error ("Augeas rm failed"); return -1; } return r; #else NOT_AVAILABLE (-1); #endif }
int dns_rm_nameserver(int i, char** msg) { char* path = NULL; asprintf(&path, "/files/%s/nameserver[%d]", AUGEAS_DNS_CONF, i); switch (aug_match(sysaugeas, path, NULL)) { case -1: asprintf(msg, "Augeas match for \"%s\" failed: %s", path, aug_error_message(sysaugeas)); free(path); return EXIT_FAILURE; case 0: /* do nothing */ break; default: /* 1 */ aug_rm(sysaugeas, path); } free(path); return EXIT_SUCCESS; }
static errno_t sss_config_rm_option(struct sss_config_ctx *ctx, const char *section, const char *option) { TALLOC_CTX *tmp_ctx = NULL; char *option_path = NULL; errno_t ret; int aug_ret; tmp_ctx = talloc_new(NULL); if (tmp_ctx == NULL) { return ENOMEM; } option_path = build_option_path(tmp_ctx, ctx, section, option); if (option_path == NULL) { ret = ENOMEM; goto done; } /* Remove configuration option: * * rm /files/$file/target[. = "$section"]/$option */ aug_ret = aug_rm(ctx->auges_ctx, option_path); if (aug_ret != 1) { ret = EIO; goto done; } ret = EOK; done: talloc_free(tmp_ctx); return ret; }
void dns_rm_nameserver_all(void) { const char* path = "/files/"AUGEAS_DNS_CONF"/nameserver"; aug_rm(sysaugeas, path); }
void dns_rm_search_domain_all(void) { const char* path = "/files/"AUGEAS_DNS_CONF"/search"; aug_rm(sysaugeas, path); }
static int Paug_rm(lua_State *L) { augeas *a = Paug_checkarg(L, 1); const char *path = luaL_checkstring(L, 2); return pushresult(L, aug_rm(a, path), a, NULL); }