static void add_transforms(char *ts, size_t tslen) { char *command; int r; char *t = NULL; bool added_transform = false; while ((t = argz_next(ts, tslen, t))) { r = xasprintf(&command, "transform %s", t); if (r < 0) fprintf(stderr, "error: Failed to add transform %s: could not allocate memory\n", t); r = aug_srun(aug, stdout, command); if (r < 0) fprintf(stderr, "error: Failed to add transform %s: %s\n", t, aug_error_message(aug)); free(command); added_transform = true; } if (added_transform) { r = aug_load(aug); if (r < 0) fprintf(stderr, "error: Failed to load with new transforms: %s\n", aug_error_message(aug)); } }
static int pusherror(lua_State *L, augeas *aug, const char *info) { lua_pushnil(L); if (info==NULL) lua_pushstring(L, aug_error_message(aug)); else lua_pushfstring(L, "%s: %s", info, aug_error_message(aug)); lua_pushinteger(L, aug_error(aug)); return 3; }
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; }
/* * Print out information for all nodes matching PATH using aug_ns_* * functions */ static void dump_var(struct augeas *aug, const char *path) { int nmatches; int i; /* Define the variable 'matches' to hold all the nodes we are interested in */ aug_defvar(aug, "matches", path); /* Count how many nodes we have */ nmatches = aug_match(aug, "$matches", NULL); if (nmatches < 0) { fprintf(stderr, "aug_match for '%s' failed\n", path); fprintf(stderr, "error: %s\n", aug_error_message(aug)); exit(1); } fprintf(stderr, "using var and aug_ns_*\n"); fprintf(stderr, "%d matches for %s\n", nmatches, path); for (i=0; i < nmatches; i++) { const char *value, *label; char *file = NULL; /* Get information about the ith node, equivalent to calling * aug_get etc. for "$matches[i]" but much more efficient internally */ aug_ns_attr(aug, "matches", i, &value, &label, &file); printf("%d: %s %s %s\n", i, label, value, file); free(file); } }
/* * Print out information for all nodes matching PATH using aug_match and * then aug_get etc. on each of the matches. */ static void dump_match(struct augeas *aug, const char *path) { char **matches; int nmatches; int i; nmatches = aug_match(aug, path, &matches); if (nmatches < 0) { fprintf(stderr, "aug_match for '%s' failed\n", path); fprintf(stderr, "error: %s\n", aug_error_message(aug)); exit(1); } fprintf(stderr, "iterating matches\n"); fprintf(stderr, "%d matches for %s\n", nmatches, path); for (i=0; i < nmatches; i++) { const char *value, *label; char *file; aug_get(aug, matches[i], &value); aug_label(aug, matches[i], &label); aug_source(aug, matches[i], &file); printf("%s: %s %s %s\n", matches[i], label, value, file); free(file); free(matches[i]); } free(matches); }
/* * call-seq: * error -> HASH * * Retrieve details about the last error encountered and return those * details in a HASH with the following entries: * - :code error code from +aug_error+ * - :message error message from +aug_error_message+ * - :minor minor error message from +aug_minor_error_message+ * - :details error details from +aug_error_details+ */ VALUE augeas_error(VALUE s) { augeas *aug = aug_handle(s); int code; const char *msg; VALUE result; result = rb_hash_new(); code = aug_error(aug); hash_set(result, "code", INT2NUM(code)); msg = aug_error_message(aug); if (msg != NULL) hash_set(result, "message", rb_str_new2(msg)); msg = aug_error_minor_message(aug); if (msg != NULL) hash_set(result, "minor", rb_str_new2(msg)); msg = aug_error_details(aug); if (msg != NULL) hash_set(result, "details", rb_str_new2(msg)); return result; }
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; }
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 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 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); }
int dns_set_opt_attempts(const char* number, char** msg) { const char *path = "/files/"AUGEAS_DNS_CONF"/options/attempts"; assert(number); /* Create or set existing one */ if (aug_set(sysaugeas, path, number) == -1) { asprintf(msg, "Setting DNS attempts option failed (%s)", aug_error_message(sysaugeas)); return (EXIT_FAILURE); } return EXIT_SUCCESS; }
static void print_aug_error(void) { if (aug_error(aug) == AUG_ENOMEM) { fprintf(stderr, "Out of memory.\n"); return; } if (aug_error(aug) != AUG_NOERROR) { fprintf(stderr, "error: %s\n", aug_error_message(aug)); if (aug_error_minor_message(aug) != NULL) fprintf(stderr, "error: %s\n", aug_error_minor_message(aug)); if (aug_error_details(aug) != NULL) { fputs(aug_error_details(aug), stderr); fprintf(stderr, "\n"); } } }
int dns_mod_nameserver(const char* address, int index, char** msg) { char *path = NULL; assert(address); assert(index >= 1); asprintf(&path, "/files/%s/nameserver[%d]", AUGEAS_DNS_CONF, index); if (aug_set(sysaugeas, path, address) == -1) { asprintf(msg, "Changing DNS server failed (%s)", aug_error_message(sysaugeas)); free(path); return (EXIT_FAILURE); } free(path); return EXIT_SUCCESS; }
static const char * getAugeasError (augeas * augeasHandle) { const char * reason = 0; if (aug_error (augeasHandle) != 0) { reason = aug_error_message (augeasHandle); } else { const char * augeasError; aug_get (augeasHandle, "/augeas/text" AUGEAS_TREE_ROOT "/error", &augeasError); if (augeasError) { const char * lens; const char * line; const char * character; const char * message; aug_get (augeasHandle, "/augeas/text" AUGEAS_TREE_ROOT "/error/lens", &lens); aug_get (augeasHandle, "/augeas/text" AUGEAS_TREE_ROOT "/error/line", &line); aug_get (augeasHandle, "/augeas/text" AUGEAS_TREE_ROOT "/error/char", &character); aug_get (augeasHandle, "/augeas/text" AUGEAS_TREE_ROOT "/error/message", &message); const char * format = "%s\n\tposition: %s:%s\n\tmessage: %s\n\tlens: %s"; size_t messageSize = strlen (lens) + strlen (line) + strlen (character) + strlen (message) + strlen (format); char * buffer = elektraMalloc (messageSize); sprintf (buffer, format, augeasError, line, character, message); reason = buffer; } else { reason = "No specific reason was reported"; } } /* should not happen, but avoid 0 return */ if (!reason) { reason = ""; } return reason; }
static const char *getAugeasError(augeas* augeasHandle) { const char* message = 0; if (aug_error (augeasHandle) != 0) { message = aug_error_message (augeasHandle); } else { aug_get (augeasHandle, "/augeas/text"AUGEAS_TREE_ROOT"/error/message", &message); if (!message) message = "No specific reason was reported"; } /* should not happen, but avoid 0 return */ if (!message) message = ""; return message; }
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; }
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; }
/* Internal helper to help extract errors */ static std::string augeasGetError() { std::vector<std::string> result; int err = aug_error(augeas); if(!err) return ""; std::stringstream msg; const char *p; if((p=aug_error_message(augeas))) msg << p; if((p=aug_error_minor_message(augeas))) msg << " (" << p << ")"; if((p=aug_error_details(augeas))) msg << " (" << p << ")"; switch(err) { case AUG_EPATHX: return std::string("Bad section/app used: " + msg.str()); default: return msg.str(); } }
static int Paug_error_message(lua_State *L) { augeas *a = Paug_checkarg(L, 1); lua_pushstring(L, aug_error_message(a)); return 1; }
xmlNodePtr dns_getconfig(xmlNsPtr ns, char** msg) { int i, done; char* path, *content = NULL; const char* value; xmlNodePtr dns_node, server, aux_node; assert(sysaugeas); /* dns-resolver */ dns_node = xmlNewNode(ns, BAD_CAST "dns-resolver"); /* dns-resolver/search[] */ for (i = 1, done = 0; !done; i++) { path = NULL; asprintf(&path, "/files/"AUGEAS_DNS_CONF"/search/domain[%d]", i); switch (aug_match(sysaugeas, path, NULL)) { case -1: asprintf(msg, "Augeas match for \"%s\" failed: %s", path, aug_error_message(sysaugeas)); free(path); xmlFreeNode(dns_node); return (NULL); case 0: /* index out of bounds, continue with next server type */ free(path); done = 1; break; default: /* 1 */ /* dns-resolver/search */ aug_get(sysaugeas, path, &value); xmlNewChild(dns_node, dns_node->ns, BAD_CAST "search", BAD_CAST value); free(path); path = NULL; break; } } /* dns-resolver/server[] */ for (i = 1, done = 0; !done; i++) { path = NULL; asprintf(&path, "/files/"AUGEAS_DNS_CONF"/nameserver[%d]", i); switch (aug_match(sysaugeas, path, NULL)) { case -1: asprintf(msg, "Augeas match for \"%s\" failed: %s", path, aug_error_message(sysaugeas)); free(path); xmlFreeNode(dns_node); return (NULL); case 0: /* index out of bounds, continue with next server type */ free(path); done = 1; break; default: /* 1 */ /* dns-resolver/server */ server = xmlNewChild(dns_node, dns_node->ns, BAD_CAST "server", NULL); /* dns-resolver/server/name */ asprintf(&content, "nameserver-%d", i); xmlNewChild(server, server->ns, BAD_CAST "name", BAD_CAST content); free(content); /* dns-resolver/server/udp-and-tcp/address */ aug_get(sysaugeas, path, &value); aux_node = xmlNewChild(server, server->ns, BAD_CAST "udp-and-tcp", NULL); xmlNewChild(aux_node, aux_node->ns, BAD_CAST "address", BAD_CAST value); free(path); /* port specification is not supported by Linux dns resolver implementation */ break; } } /* dns-resolver/options */ switch (aug_match(sysaugeas, "/files/"AUGEAS_DNS_CONF"/options", NULL)) { case -1: asprintf(msg, "Augeas match for \"%s\" failed: %s", path, aug_error_message(sysaugeas)); free(path); xmlFreeNode(dns_node); return (NULL); case 0: /* No options specified */ break; default: /* 1 */ aux_node = xmlNewChild(dns_node, dns_node->ns, BAD_CAST "options", NULL); /* dns-resolver/options/timeout */ value = NULL; aug_get(sysaugeas, "/files/"AUGEAS_DNS_CONF"/options/timeout", &value); if (value != NULL) { xmlNewChild(aux_node, aux_node->ns, BAD_CAST "timeout", BAD_CAST value); } /* dns-resolver/options/attempts */ value = NULL; aug_get(sysaugeas, "/files/"AUGEAS_DNS_CONF"/options/attempts", &value); if (value != NULL) { xmlNewChild(aux_node, aux_node->ns, BAD_CAST "attempts", BAD_CAST value); } break; } return (dns_node); }
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); }
xmlNodePtr ntp_getconfig(xmlNsPtr ns, char** errmsg) { int i, j; const char* type[2] = {"server", "peer"}; const char* value; char* path, *content = NULL; xmlNodePtr ntp_node, server, aux_node; assert(sysaugeas); /* ntp */ ntp_node = xmlNewNode(ns, BAD_CAST "ntp"); /* ntp/enabled */ xmlNewChild(ntp_node, ntp_node->ns, BAD_CAST "enabled", (ntp_status() == 1) ? BAD_CAST "true" : BAD_CAST "false"); /* ntp/server[] */ j = 0; loop: for (i = 1; j < 2; i++) { path = NULL; asprintf(&path, "/files/"AUGEAS_NTP_CONF"/%s[%d]", type[j], i); switch(aug_match(sysaugeas, path, NULL)) { case -1: asprintf(errmsg, "Augeas match for \"%s\" failed: %s", path, aug_error_message(sysaugeas)); free(path); xmlFreeNode(ntp_node); return (NULL); case 0: /* index out of bounds, continue with next server type */ free(path); j++; goto loop; default: /* 1 */ /* ntp/server/ */ server = xmlNewChild(ntp_node, ntp_node->ns, BAD_CAST "server", NULL); /* ntp/server/name */ asprintf(&content, "%s-%d", type[j], i); xmlNewChild(server, server->ns, BAD_CAST "name", BAD_CAST content); free(content); /* ntp/server/udp/address */ aug_get(sysaugeas, path, &value); aux_node = xmlNewChild(server, server->ns, BAD_CAST "udp", NULL); xmlNewChild(aux_node, aux_node->ns, BAD_CAST "address", BAD_CAST value); /* port specification is not supported by Linux ntp implementation */ free(path); /* ntp/server/association-type */ xmlNewChild(server, server->ns, BAD_CAST "association-type", BAD_CAST type[j]); /* ntp/server/iburst */ path = NULL; asprintf(&path, "/files/"AUGEAS_NTP_CONF"/%s[%d]/iburst", type[j], i); switch(aug_match(sysaugeas, path, NULL)) { case -1: asprintf(errmsg, "Augeas match for \"%s\" failed: %s", path, aug_error_message(sysaugeas)); free(path); xmlFreeNode(ntp_node); return (NULL); case 0: /* iburst not set */ xmlNewChild(server, server->ns, BAD_CAST "iburst", BAD_CAST "false"); break; default: /* 1 */ /* iburst set */ xmlNewChild(server, server->ns, BAD_CAST "iburst", BAD_CAST "true"); break; } free(path); /* ntp/server/prefer */ path = NULL; asprintf(&path, "/files/"AUGEAS_NTP_CONF"/%s[%d]/prefer", type[j], i); switch(aug_match(sysaugeas, path, NULL)) { case -1: asprintf(errmsg, "Augeas match for \"%s\" failed: %s", path, aug_error_message(sysaugeas)); free(path); xmlFreeNode(ntp_node); return (NULL); case 0: /* prefer not set */ xmlNewChild(server, server->ns, BAD_CAST "prefer", BAD_CAST "false"); break; default: /* 1 */ /* prefer set */ xmlNewChild(server, server->ns, BAD_CAST "prefer", BAD_CAST "true"); break; } free(path); } } return (ntp_node); }