static void test_copy(void **state) { Rlist *list = NULL, *copy = NULL; PrependRScalar(&list, "stuff", CF_SCALAR); PrependRScalar(&list, "more-stuff", CF_SCALAR); copy = CopyRlist(list); assert_string_equal(list->item, copy->item); assert_string_equal(list->next->item, copy->next->item); DeleteRlist(list); DeleteRlist(copy); }
static void TexinfoShowRange(FILE *fout, char *s, enum cfdatatype type) { Rlist *list = NULL, *rp; if (strlen(s) == 0) { fprintf(fout, "@noindent @b{Allowed input range}: (arbitrary string)\n\n"); return; } if ((type == cf_opts) || (type == cf_olist)) { list = SplitStringAsRList(s, ','); fprintf(fout, "@noindent @b{Allowed input range}: @*\n@example"); for (rp = list; rp != NULL; rp = rp->next) { fprintf(fout, "\n @code{%s}", (char *) rp->item); } fprintf(fout, "\n@end example\n"); DeleteRlist(list); } else { fprintf(fout, "@noindent @b{Allowed input range}: @code{%s}\n\n", TexInfoEscape(s)); } }
static void test_last(void **state) { Rlist *l = NULL; assert_true(RlistLast(l) == NULL); AppendRlist(&l, "a", CF_SCALAR); assert_string_equal("a", ScalarValue(RlistLast(l))); AppendRlist(&l, "b", CF_SCALAR); assert_string_equal("b", ScalarValue(RlistLast(l))); DeleteRlist(l); }
static void test_prepend_scalar(void **state) { Rlist *list = NULL; PrependRScalar(&list, "stuff", CF_SCALAR); PrependRScalar(&list, "more-stuff", CF_SCALAR); assert_string_equal(list->item, "more-stuff"); DeleteRlist(list); }
static void test_prepend_scalar_idempotent(void **state) { Rlist *list = NULL; IdempPrependRScalar(&list, "stuff", CF_SCALAR); IdempPrependRScalar(&list, "stuff", CF_SCALAR); assert_string_equal(list->item, "stuff"); assert_int_equal(RlistLen(list), 1); DeleteRlist(list); }
void DeleteFnCall(FnCall *fp) { if (fp->name) { free(fp->name); } if (fp->args) { DeleteRlist(fp->args); } free(fp); }
static void test_length(void **state) { Rlist *list = NULL; assert_int_equal(RlistLen(list), 0); PrependRScalar(&list, "stuff", CF_SCALAR); assert_int_equal(RlistLen(list), 1); PrependRScalar(&list, "more-stuff", CF_SCALAR); assert_int_equal(RlistLen(list), 2); DeleteRlist(list); }
static Topic *AddTopic(Topic **list, char *name, char *context) { Topic *tp; if ((tp = TopicExists(name, context))) { CfOut(cf_verbose, "", " -> Topic %s already defined, ok\n", name); } else { tp = xmalloc(sizeof(Topic)); tp->topic_name = xstrdup(NormalizeTopic(name)); if (context && strlen(context) > 0) { tp->topic_context = xstrdup(NormalizeTopic(context)); } else { tp->topic_context = xstrdup("any"); } tp->id = GLOBAL_ID++; tp->associations = NULL; tp->next = *list; *list = tp; CF_TOPICS++; // This section must come last, as there is possible recursion and memory ref needs to be complete first if (strcmp(tp->topic_context, "any") != 0) { // Every topic in a special context is generalized by itself in context "any" char gen[CF_BUFSIZE]; Rlist *rlist = 0; snprintf(gen, CF_BUFSIZE - 1, "any::%s", tp->topic_name); PrependRScalar(&rlist, gen, CF_SCALAR); AddTopicAssociation(tp, &(tp->associations), KM_GENERALIZES_B, KM_GENERALIZES_F, rlist, true, tp->topic_context, tp->topic_name); DeleteRlist(rlist); } } return tp; }
static void ThisAgentInit(void) { strcpy(WEBDRIVER, ""); strcpy(LICENSE_COMPANY, ""); strcpy(MANDIR, "."); SHOWREPORTS = false; if (InsertTopic("any", "any")) { Rlist *list = NULL; PrependRScalar(&list, "Description", CF_SCALAR); AddOccurrence(&OCCURRENCES, "The generic knowledge context - any time, any place, anywhere", list, cfk_literal, "any"); DeleteRlist(list); } }
static void VerifyOccurrenceGroup(char *file, Promise *pp) { Attributes a = { {0} }; struct stat sb; char *sp, url[CF_BUFSIZE]; Rval retval; a = GetOccurrenceAttributes(pp); if (cfstat(file, &sb) == -1) { CfOut(cf_verbose, "", " !! File %s matched but could not be read", file); return; } if (a.path_root == NULL || a.web_root == NULL) { CfOut(cf_error, "", " !! No pathroot/webroot defined in representation"); PromiseRef(cf_error, pp); return; } Chop(a.path_root); DeleteSlash(a.path_root); sp = file + strlen(a.path_root) + 1; FullTextMatch(pp->promiser, sp); retval = ExpandPrivateRval("this", (Rval) {a.represents, CF_LIST}); DeleteScope("match"); if (strlen(a.web_root) > 0) { snprintf(url, CF_BUFSIZE - 1, "%s/%s", a.web_root, sp); } else { snprintf(url, CF_BUFSIZE - 1, "%s", sp); } AddOccurrence(&OCCURRENCES, url, retval.item, cfk_url, pp->classes); CfOut(cf_verbose, "", " -> File %s matched and being logged at %s", file, url); DeleteRlist((Rlist *) retval.item); }
static int TableExists(CfdbConn *cfdb, char *name) { Rlist *rp, *list = NULL; int match = false; list = GetSQLTables(cfdb); for (rp = list; rp != NULL; rp = rp->next) { if (strcmp(name, rp->item) == 0) { match = true; } } DeleteRlist(list); return match; }
static void XmlExportVariables(Writer *writer, const char *scope) { char *filebuffer = NULL; Rlist *rp = NULL; Rlist *list = NULL; /* START XML ELEMENT -- VARIABLE*-SCOPE */ XmlAttribute scope_name_attr = { "name", scope }; XmlStartTag(writer, XMLTAG_VARSCOPE, 1, scope_name_attr); /* XML ELEMENT -- INTRO */ filebuffer = ReadTexinfoFileF("varcontexts/%s_intro.texinfo", scope); XmlTag(writer, XMLTAG_INTRO, filebuffer, 0); free(filebuffer); HashToList(GetScope(scope), &list); list = AlphaSortRListNames(list); for (rp = list; rp != NULL; rp = rp->next) { /* START XML ELEMENT -- VARIABLE */ XmlAttribute var_name_attr = { "name", ScalarValue(rp) }; XmlStartTag(writer, XMLTAG_VARIABLE, 1, var_name_attr); /* XML ELEMENT -- LONG-DESCRIPTION */ filebuffer = ReadTexinfoFileF("vars/%s_%s.texinfo", scope, ScalarValue(rp)); XmlTag(writer, XMLTAG_LONGDESCRIPTION, filebuffer, 0); free(filebuffer); /* END XML ELEMENT -- VARIABLE */ XmlEndTag(writer, XMLTAG_VARIABLE); } DeleteRlist(list); /* END XML ELEMENT -- VARIABLE-SCOPE */ XmlEndTag(writer, XMLTAG_VARSCOPE); }
void XmlExportType(Writer *writer, enum cfdatatype dtype, const void *range) { Rlist *list = NULL; Rlist *rp = NULL; /* START XML ELEMENT -- TYPE */ XmlAttribute type_name_attr = { "name", CF_DATATYPES[dtype] }; XmlStartTag(writer, XMLTAG_TYPE, 1, type_name_attr); switch (dtype) { case cf_body: /* EXPORT CONSTRAINTS */ XmlExportConstraints(writer, (BodySyntax *) range); break; case cf_int: case cf_real: case cf_ilist: case cf_rlist: case cf_irange: case cf_rrange: if (range != NULL) { /* START XML ELEMENT -- RANGE */ XmlStartTag(writer, XMLTAG_RANGE, 0); /* XML ELEMENT -- MIN/MAX */ int i = 0; list = SplitStringAsRList((char *) range, ','); for (rp = list; rp != NULL; rp = rp->next, i++) { if (i == 0) { XmlTag(writer, XMLTAG_MIN, ScalarValue(rp), 0); } else { XmlTag(writer, XMLTAG_MAX, ScalarValue(rp), 0); } } DeleteRlist(list); /* END XML ELEMENT -- RANGE */ XmlEndTag(writer, XMLTAG_RANGE); break; } case cf_opts: case cf_olist: if (range != NULL) { /* START XML ELEMENT -- OPTIONS */ XmlStartTag(writer, XMLTAG_OPTIONS, 0); /* XML ELEMENT -- VALUE */ list = SplitStringAsRList((char *) range, ','); for (rp = list; rp != NULL; rp = rp->next) { XmlTag(writer, XMLTAG_VALUE, ScalarValue(rp), 0); } DeleteRlist(list); /* END XML ELEMENT -- OPTIONS */ XmlEndTag(writer, XMLTAG_OPTIONS); break; } case cf_str: case cf_slist: case cf_class: case cf_clist: /* XML ELEMENT -- ACCEPTED-VALUES */ if (strlen((char *) range) == 0) { XmlTag(writer, XMLTAG_ACCEPTEDVALS, "arbitrary string", 0); } else { XmlTag(writer, XMLTAG_ACCEPTEDVALS, (char *) range, 0); } break; case cf_bundle: case cf_notype: case cf_counter: /* NONE */ break; } /* END XML ELEMENT -- TYPE */ XmlEndTag(writer, XMLTAG_TYPE); }
int AddVariableHash(const char *scope, const char *lval, Rval rval, enum cfdatatype dtype, const char *fname, int lineno) { Scope *ptr; const Rlist *rp; CfAssoc *assoc; if (rval.rtype == CF_SCALAR) { CfDebug("AddVariableHash(%s.%s=%s (%s) rtype=%c)\n", scope, lval, (const char *) rval.item, CF_DATATYPES[dtype], rval.rtype); } else { CfDebug("AddVariableHash(%s.%s=(list) (%s) rtype=%c)\n", scope, lval, CF_DATATYPES[dtype], rval.rtype); } if (lval == NULL || scope == NULL) { CfOut(cf_error, "", "scope.value = %s.%s", scope, lval); ReportError("Bad variable or scope in a variable assignment"); FatalError("Should not happen - forgotten to register a function call in fncall.c?"); } if (rval.item == NULL) { CfDebug("No value to assignment - probably a parameter in an unused bundle/body\n"); return false; } if (strlen(lval) > CF_MAXVARSIZE) { ReportError("variable lval too long"); return false; } /* If we are not expanding a body template, check for recursive singularities */ if (strcmp(scope, "body") != 0) { switch (rval.rtype) { case CF_SCALAR: if (StringContainsVar((char *) rval.item, lval)) { CfOut(cf_error, "", "Scalar variable %s.%s contains itself (non-convergent): %s", scope, lval, (char *) rval.item); return false; } break; case CF_LIST: for (rp = rval.item; rp != NULL; rp = rp->next) { if (StringContainsVar((char *) rp->item, lval)) { CfOut(cf_error, "", "List variable %s contains itself (non-convergent)", lval); return false; } } break; } } ptr = GetScope(scope); if (ptr == NULL) { return false; } // Look for outstanding lists in variable rvals if (THIS_AGENT_TYPE == cf_common) { Rlist *listvars = NULL, *scalarvars = NULL; if (strcmp(CONTEXTID, "this") != 0) { MapIteratorsFromRval(CONTEXTID, &scalarvars, &listvars, rval, NULL); if (listvars != NULL) { CfOut(cf_error, "", " !! Redefinition of variable \"%s\" (embedded list in RHS) in context \"%s\"", lval, CONTEXTID); } DeleteRlist(scalarvars); DeleteRlist(listvars); } } assoc = HashLookupElement(ptr->hashtable, lval); if (assoc) { if (CompareVariableValue(rval, assoc) == 0) { /* Identical value, keep as is */ } else { /* Different value, bark and replace */ if (!UnresolvedVariables(assoc, rval.rtype)) { CfOut(cf_inform, "", " !! Duplicate selection of value for variable \"%s\" in scope %s", lval, ptr->scope); if (fname) { CfOut(cf_inform, "", " !! Rule from %s at/before line %d\n", fname, lineno); } else { CfOut(cf_inform, "", " !! in bundle parameterization\n"); } } DeleteRvalItem(assoc->rval); assoc->rval = CopyRvalItem(rval); assoc->dtype = dtype; CfDebug("Stored \"%s\" in context %s\n", lval, scope); } } else { if (!HashInsertElement(ptr->hashtable, lval, rval, dtype)) { FatalError("Hash table is full"); } } CfDebug("Added Variable %s in scope %s with value (omitted)\n", lval, scope); return true; }
void DeleteExpArgs(Rlist *args) { DeleteRlist(args); }
static int NewSQLColumns(char *table, Rlist *columns, char ***name_table, char ***type_table, int **size_table, int **done) { int i, no_of_cols = RlistLen(columns); Rlist *cols, *rp; *name_table = (char **) xmalloc(sizeof(char *) * (no_of_cols + 1)); *type_table = (char **) xmalloc(sizeof(char *) * (no_of_cols + 1)); *size_table = (int *) xmalloc(sizeof(int) * (no_of_cols + 1)); *done = (int *) xmalloc(sizeof(int) * (no_of_cols + 1)); for (i = 0, rp = columns; rp != NULL; rp = rp->next, i++) { (*done)[i] = 0; cols = SplitStringAsRList((char *) rp->item, ','); if (!cols) { CfOut(cf_error, "", "No columns promised for table \"%s\" - makes no sense", table); return false; } if (cols->item == NULL) { CfOut(cf_error, "", "Malformed column promise for table \"%s\" - found not even a name", table); free(*name_table); free(*type_table); free(*size_table); free(*done); return false; } (*name_table)[i] = xstrdup((char *) cols->item); if (cols->next == NULL) { CfOut(cf_error, "", "Malformed column \"%s\" promised for table \"%s\" - missing a type", (*name_table)[i], table); free(*name_table); free(*type_table); free(*size_table); free(*done); return false; } (*type_table)[i] = xstrdup(cols->next->item); if (cols->next->next == NULL) { (*size_table)[i] = 0; } else { if (cols->next->next->item) { (*size_table)[i] = Str2Int(cols->next->next->item); } else { (*size_table)[i] = 0; } } DeleteRlist(cols); } return true; }
static void VerifyOccurrencePromises(Promise *pp) { Attributes a = { {0} }; char name[CF_BUFSIZE]; enum representations rep_type; Rlist *contexts, *rp; a = GetOccurrenceAttributes(pp); if (a.rep_type) { rep_type = String2Representation(a.rep_type); } else { rep_type = cfk_url; } if (a.represents == NULL) { if (rep_type == cfk_literal) { CfOut(cf_error, "", " ! Occurrence of text information \"%s\" does not promise any topics to represent", pp->promiser); } else { CfOut(cf_error, "", " ! Occurrence or reference to information \"%s\" does not promise any topics to represent", pp->promiser); } return; } contexts = SplitContextExpression(pp->classes, pp); for (rp = contexts; rp != NULL; rp = rp->next) { CfOut(cf_verbose, "", " -> New occurrence promise for \"%s\" about context \"%s\"", pp->promiser, ScalarValue(rp)); switch (rep_type) { case cfk_file: if (a.web_root == NULL || a.path_root == NULL) { CfOut(cf_error, "", " !! File pattern but no complete url mapping path_root -> web_root"); return; } strncpy(name, a.path_root, CF_BUFSIZE - 1); if (!JoinPath(name, pp->promiser)) { CfOut(cf_error, "", " !! Unable to form pathname in search for local files"); return; } // FIXME - this should pass rp->item instead of pp->classes if we want to keep this LocateFilePromiserGroup(name, pp, VerifyOccurrenceGroup); break; default: AddOccurrence(&OCCURRENCES, pp->promiser, a.represents, rep_type, rp->item); break; } } DeleteRlist(contexts); }
void GetInterfacesInfo(enum cfagenttype ag) { int fd, len, i, j, first_address = false, ipdefault = false; struct ifreq ifbuf[CF_IFREQ], ifr, *ifp; struct ifconf list; struct sockaddr_in *sin; struct hostent *hp; char *sp, workbuf[CF_BUFSIZE]; char ip[CF_MAXVARSIZE]; char name[CF_MAXVARSIZE]; char last_name[CF_BUFSIZE]; Rlist *interfaces = NULL, *hardware = NULL, *ips = NULL; CfDebug("GetInterfacesInfo()\n"); // Long-running processes may call this many times DeleteItemList(IPADDRESSES); IPADDRESSES = NULL; memset(ifbuf, 0, sizeof(ifbuf)); InitIgnoreInterfaces(); last_name[0] = '\0'; if ((fd = socket(AF_INET, SOCK_DGRAM, 0)) == -1) { CfOut(cf_error, "socket", "Couldn't open socket"); exit(1); } list.ifc_len = sizeof(ifbuf); list.ifc_req = ifbuf; # ifdef SIOCGIFCONF if (ioctl(fd, SIOCGIFCONF, &list) == -1 || (list.ifc_len < (sizeof(struct ifreq)))) # else if (ioctl(fd, OSIOCGIFCONF, &list) == -1 || (list.ifc_len < (sizeof(struct ifreq)))) # endif { CfOut(cf_error, "ioctl", "Couldn't get interfaces - old kernel? Try setting CF_IFREQ to 1024"); exit(1); } last_name[0] = '\0'; for (j = 0, len = 0, ifp = list.ifc_req; len < list.ifc_len; len += SIZEOF_IFREQ(*ifp), j++, ifp = (struct ifreq *) ((char *) ifp + SIZEOF_IFREQ(*ifp))) { if (ifp->ifr_addr.sa_family == 0) { continue; } if (ifp->ifr_name == NULL || strlen(ifp->ifr_name) == 0) { continue; } /* Skip virtual network interfaces for Linux, which seems to be a problem */ if (IgnoreInterface(ifp->ifr_name)) { continue; } if (strstr(ifp->ifr_name, ":")) { if (VSYSTEMHARDCLASS == linuxx) { CfOut(cf_verbose, "", "Skipping apparent virtual interface %d: %s\n", j + 1, ifp->ifr_name); continue; } } else { CfOut(cf_verbose, "", "Interface %d: %s\n", j + 1, ifp->ifr_name); } // Ignore the loopback if (strcmp(ifp->ifr_name, "lo") == 0) { continue; } if (strncmp(last_name, ifp->ifr_name, sizeof(ifp->ifr_name)) == 0) { first_address = false; } else { strncpy(last_name, ifp->ifr_name, sizeof(ifp->ifr_name)); if (!first_address) { NewScalar("sys", "interface", last_name, cf_str); first_address = true; } } snprintf(workbuf, CF_BUFSIZE, "net_iface_%s", CanonifyName(ifp->ifr_name)); NewClass(workbuf); if (ifp->ifr_addr.sa_family == AF_INET) { strncpy(ifr.ifr_name, ifp->ifr_name, sizeof(ifp->ifr_name)); if (ioctl(fd, SIOCGIFFLAGS, &ifr) == -1) { CfOut(cf_error, "ioctl", "No such network device"); //close(fd); //return; continue; } if ((ifr.ifr_flags & IFF_UP) && !(ifr.ifr_flags & IFF_LOOPBACK)) { sin = (struct sockaddr_in *) &ifp->ifr_addr; if (IgnoreJailInterface(j + 1, sin)) { CfOut(cf_verbose, "", "Ignoring interface %d", j + 1); continue; } CfDebug("Adding hostip %s..\n", inet_ntoa(sin->sin_addr)); NewClass(inet_ntoa(sin->sin_addr)); if ((hp = gethostbyaddr((char *) &(sin->sin_addr.s_addr), sizeof(sin->sin_addr.s_addr), AF_INET)) == NULL) { CfDebug("No hostinformation for %s found\n", inet_ntoa(sin->sin_addr)); } else { if (hp->h_name != NULL) { CfDebug("Adding hostname %s..\n", hp->h_name); NewClass(hp->h_name); if (hp->h_aliases != NULL) { for (i = 0; hp->h_aliases[i] != NULL; i++) { CfOut(cf_verbose, "", "Adding alias %s..\n", hp->h_aliases[i]); NewClass(hp->h_aliases[i]); } } } } if (strcmp(inet_ntoa(sin->sin_addr), "0.0.0.0") == 0) { // Maybe we need to do something windows specific here? CfOut(cf_verbose, "", " !! Cannot discover hardware IP, using DNS value"); strcpy(ip, "ipv4_"); strcat(ip, VIPADDRESS); AppendItem(&IPADDRESSES, VIPADDRESS, ""); AppendRlist(&ips, VIPADDRESS, CF_SCALAR); for (sp = ip + strlen(ip) - 1; (sp > ip); sp--) { if (*sp == '.') { *sp = '\0'; NewClass(ip); } } strcpy(ip, VIPADDRESS); i = 3; for (sp = ip + strlen(ip) - 1; (sp > ip); sp--) { if (*sp == '.') { *sp = '\0'; snprintf(name, CF_MAXVARSIZE - 1, "ipv4_%d[%s]", i--, CanonifyName(VIPADDRESS)); NewScalar("sys", name, ip, cf_str); } } //close(fd); //return; continue; } strncpy(ip, "ipv4_", CF_MAXVARSIZE); strncat(ip, inet_ntoa(sin->sin_addr), CF_MAXVARSIZE - 6); NewClass(ip); if (!ipdefault) { ipdefault = true; NewScalar("sys", "ipv4", inet_ntoa(sin->sin_addr), cf_str); strcpy(VIPADDRESS, inet_ntoa(sin->sin_addr)); } AppendItem(&IPADDRESSES, inet_ntoa(sin->sin_addr), ""); AppendRlist(&ips, inet_ntoa(sin->sin_addr), CF_SCALAR); for (sp = ip + strlen(ip) - 1; (sp > ip); sp--) { if (*sp == '.') { *sp = '\0'; NewClass(ip); } } // Set the IPv4 on interface array strcpy(ip, inet_ntoa(sin->sin_addr)); if (ag != cf_know && ag != cf_gendoc) { snprintf(name, CF_MAXVARSIZE - 1, "ipv4[%s]", CanonifyName(ifp->ifr_name)); } else { snprintf(name, CF_MAXVARSIZE - 1, "ipv4[interface_name]"); } NewScalar("sys", name, ip, cf_str); i = 3; for (sp = ip + strlen(ip) - 1; (sp > ip); sp--) { if (*sp == '.') { *sp = '\0'; if (ag != cf_know && ag != cf_gendoc) { snprintf(name, CF_MAXVARSIZE - 1, "ipv4_%d[%s]", i--, CanonifyName(ifp->ifr_name)); } else { snprintf(name, CF_MAXVARSIZE - 1, "ipv4_%d[interface_name]", i--); } NewScalar("sys", name, ip, cf_str); } } } // Set the hardware/mac address array GetMacAddress(ag, fd, &ifr, ifp, &interfaces, &hardware); } } close(fd); NewList("sys", "interfaces", interfaces, cf_slist); NewList("sys", "hardware_addresses", hardware, cf_slist); NewList("sys", "ip_addresses", ips, cf_slist); DeleteRlist(interfaces); DeleteRlist(hardware); DeleteRlist(ips); FindV6InterfacesInfo(); }
static void AddTopicAssociation(Topic *this_tp, TopicAssociation **list, char *fwd_name, char *bwd_name, Rlist *passociates, int ok_to_add_inverse, char *from_context, char *from_topic) { TopicAssociation *ta = NULL, *texist; char fwd_context[CF_MAXVARSIZE]; Rlist *rp; Topic *new_tp; char contexttopic[CF_BUFSIZE], ntopic[CF_BUFSIZE], ncontext[CF_BUFSIZE]; strncpy(ntopic, NormalizeTopic(from_topic), CF_BUFSIZE - 1); strncpy(ncontext, NormalizeTopic(from_context), CF_BUFSIZE - 1); snprintf(contexttopic, CF_MAXVARSIZE, "%s::%s", ncontext, ntopic); strncpy(fwd_context, CanonifyName(fwd_name), CF_MAXVARSIZE - 1); if (passociates == NULL || passociates->item == NULL) { CfOut(cf_error, "", " !! A topic must have at least one associate in association %s", fwd_name); return; } if ((texist = AssociationExists(*list, fwd_name, bwd_name)) == NULL) { ta = xcalloc(1, sizeof(TopicAssociation)); ta->fwd_name = xstrdup(fwd_name); if (bwd_name) { ta->bwd_name = xstrdup(bwd_name); } ta->fwd_context = xstrdup(fwd_context); ta->next = *list; *list = ta; } else { ta = texist; } /* Association now exists, so add new members */ if (ok_to_add_inverse) { CfOut(cf_verbose, "", " -> BEGIN add fwd associates for %s::%s", ncontext, ntopic); } else { CfOut(cf_verbose, "", " ---> BEGIN reverse associations %s::%s", ncontext, ntopic); } // First make sure topics pointed to exist so that they can point to us also for (rp = passociates; rp != NULL; rp = rp->next) { char normalform[CF_BUFSIZE] = { 0 }; strncpy(normalform, NormalizeTopic(rp->item), CF_BUFSIZE - 1); new_tp = IdempInsertTopic(normalform); if (strcmp(contexttopic, normalform) == 0) { CfOut(cf_verbose, "", " ! Excluding self-reference to %s", ScalarValue(rp)); continue; } if (ok_to_add_inverse) { CfOut(cf_verbose, "", " --> Adding '%s' with id %d as an associate of '%s::%s'", normalform, new_tp->id, this_tp->topic_context, this_tp->topic_name); } else { CfOut(cf_verbose, "", " ---> Reverse '%s' with id %d as an associate of '%s::%s' (inverse)", normalform, new_tp->id, this_tp->topic_context, this_tp->topic_name); } if (!IsItemIn(ta->associates, normalform)) { PrependFullItem(&(ta->associates), normalform, NULL, new_tp->id, 0); if (ok_to_add_inverse) { // inverse is from normalform to ncontext::ntopic char rev[CF_BUFSIZE], ndt[CF_BUFSIZE], ndc[CF_BUFSIZE]; Rlist *rlist = 0; snprintf(rev, CF_BUFSIZE - 1, "%s::%s", ncontext, ntopic); PrependRScalar(&rlist, rev, CF_SCALAR); // Stupid to have to declassify + reclassify, but .. DeClassifyTopic(normalform, ndt, ndc); AddTopicAssociation(new_tp, &(new_tp->associations), bwd_name, fwd_name, rlist, false, ndc, ndt); DeleteRlist(rlist); } } else { CfOut(cf_verbose, "", " -> Already in %s::%s's associate list", ncontext, ntopic); } CF_EDGES++; } if (ok_to_add_inverse) { CfOut(cf_verbose, "", " -> END add fwd associates for %s::%s", ncontext, ntopic); } else { CfOut(cf_verbose, "", " ---> END reverse associations %s::%s", ncontext, ntopic); } }
static void VerifyTopicPromise(Promise *pp) { char id[CF_BUFSIZE]; Attributes a = { {0} }; Topic *tp = NULL, *otp; Rlist *rp, *rps, *contexts; char *handle = (char *) GetConstraintValue("handle", pp, CF_SCALAR); a = GetTopicsAttributes(pp); CfOut(cf_verbose, "", " -> Attempting to install topic %s::%s \n", pp->classes, pp->promiser); // Add a standard reserved word contexts = SplitContextExpression(pp->classes, pp); for (rp = contexts; rp != NULL; rp = rp->next) { if ((tp = InsertTopic(pp->promiser, rp->item)) == NULL) { return; } CfOut(cf_verbose, "", " -> New topic promise for \"%s\" about context \"%s\"", pp->promiser, ScalarValue(rp)); if (a.fwd_name && a.bwd_name) { AddTopicAssociation(tp, &(tp->associations), a.fwd_name, a.bwd_name, a.associates, true, rp->item, pp->promiser); } // Handle all synonyms as associations if (a.synonyms) { for (rps = a.synonyms; rps != NULL; rps = rps->next) { otp = IdempInsertTopic(rps->item); CfOut(cf_verbose, "", " ---> %s is a synonym for %s", ScalarValue(rps), tp->topic_name); } AddTopicAssociation(tp, &(tp->associations), KM_SYNONYM, KM_SYNONYM, a.synonyms, true, rp->item, pp->promiser); } // Handle all generalizations as associations if (a.general) { for (rps = a.general; rps != NULL; rps = rps->next) { otp = IdempInsertTopic(rps->item); CfOut(cf_verbose, "", " ---> %s is a generalization for %s", ScalarValue(rps), tp->topic_name); } AddTopicAssociation(tp, &(tp->associations), KM_GENERALIZES_B, KM_GENERALIZES_F, a.general, true, rp->item, pp->promiser); } if (handle) { char synonym[CF_BUFSIZE]; snprintf(synonym, CF_BUFSIZE - 1, "handles::%s", handle); otp = IdempInsertTopic(synonym); PrependRScalar(&(a.synonyms), otp->topic_name, CF_SCALAR); } // Treat comments as occurrences of information. if (pp->ref) { Rlist *list = NULL; snprintf(id, CF_MAXVARSIZE, "%s.%s", pp->classes, CanonifyName(pp->promiser)); PrependRScalar(&list, "description", CF_SCALAR); AddOccurrence(&OCCURRENCES, pp->ref, list, cfk_literal, id); DeleteRlist(list); } if (handle) { Rlist *list = NULL; PrependRScalar(&list, handle, CF_SCALAR); AddTopicAssociation(tp, &(tp->associations), "is the promise of", "stands for", list, true, rp->item, pp->promiser); DeleteRlist(list); list = NULL; snprintf(id, CF_MAXVARSIZE, "%s.%s", pp->classes, handle); PrependRScalar(&list, "description", CF_SCALAR); AddOccurrence(&OCCURRENCES, pp->ref, list, cfk_literal, id); DeleteRlist(list); } } DeleteRlist(contexts); }
static int HailServer(char *host, Attributes a, Promise *pp) { AgentConnection *conn; char sendbuffer[CF_BUFSIZE], recvbuffer[CF_BUFSIZE], peer[CF_MAXVARSIZE], ipv4[CF_MAXVARSIZE], digest[CF_MAXVARSIZE], user[CF_SMALLBUF]; bool gotkey; char reply[8]; a.copy.portnumber = (short) ParseHostname(host, peer); snprintf(ipv4, CF_MAXVARSIZE, "%s", Hostname2IPString(peer)); Address2Hostkey(ipv4, digest); GetCurrentUserName(user, CF_SMALLBUF); if (INTERACTIVE) { CfOut(cf_verbose, "", " -> Using interactive key trust...\n"); gotkey = HavePublicKey(user, peer, digest) != NULL; if (!gotkey) { gotkey = HavePublicKey(user, ipv4, digest) != NULL; } if (!gotkey) { printf("WARNING - You do not have a public key from host %s = %s\n", host, ipv4); printf(" Do you want to accept one on trust? (yes/no)\n\n--> "); while (true) { if (fgets(reply, 8, stdin) == NULL) { FatalError("EOF trying to read answer from terminal"); } if (Chop(reply, CF_EXPANDSIZE) == -1) { CfOut(cf_error, "", "Chop was called on a string that seemed to have no terminator"); } if (strcmp(reply, "yes") == 0) { printf(" -> Will trust the key...\n"); a.copy.trustkey = true; break; } else if (strcmp(reply, "no") == 0) { printf(" -> Will not trust the key...\n"); a.copy.trustkey = false; break; } else { printf(" !! Please reply yes or no...(%s)\n", reply); } } } } /* Continue */ #ifdef __MINGW32__ CfOut(cf_inform, "", "...........................................................................\n"); CfOut(cf_inform, "", " * Hailing %s : %u, with options \"%s\" (serial)\n", peer, a.copy.portnumber, REMOTE_AGENT_OPTIONS); CfOut(cf_inform, "", "...........................................................................\n"); #else /* !__MINGW32__ */ if (BACKGROUND) { CfOut(cf_inform, "", "Hailing %s : %u, with options \"%s\" (parallel)\n", peer, a.copy.portnumber, REMOTE_AGENT_OPTIONS); } else { CfOut(cf_inform, "", "...........................................................................\n"); CfOut(cf_inform, "", " * Hailing %s : %u, with options \"%s\" (serial)\n", peer, a.copy.portnumber, REMOTE_AGENT_OPTIONS); CfOut(cf_inform, "", "...........................................................................\n"); } #endif /* !__MINGW32__ */ a.copy.servers = SplitStringAsRList(peer, '*'); if (a.copy.servers == NULL || strcmp(a.copy.servers->item, "localhost") == 0) { cfPS(cf_inform, CF_NOP, "", pp, a, "No hosts are registered to connect to"); return false; } else { conn = NewServerConnection(a, pp); if (conn == NULL) { DeleteRlist(a.copy.servers); CfOut(cf_verbose, "", " -> No suitable server responded to hail\n"); return false; } } /* Check trust interaction*/ pp->cache = NULL; if (strlen(MENU) > 0) { #if defined(HAVE_NOVA) if (!Nova_ExecuteRunagent(conn, MENU)) { DisconnectServer(conn); DeleteRlist(a.copy.servers); return false; } #endif } else { HailExec(conn, peer, recvbuffer, sendbuffer); } DeleteRlist(a.copy.servers); return true; }
int HailServer(char *host,struct Attributes a,struct Promise *pp) { struct cfagent_connection *conn; char sendbuffer[CF_BUFSIZE],recvbuffer[CF_BUFSIZE],peer[CF_MAXVARSIZE],ipv4[CF_MAXVARSIZE],digest[CF_MAXVARSIZE],user[CF_SMALLBUF]; long gotkey; char reply[8]; struct Item *queries; a.copy.portnumber = (short)ParseHostname(host,peer); snprintf(ipv4,CF_MAXVARSIZE,"%s",Hostname2IPString(peer)); IPString2KeyDigest(ipv4,digest); GetCurrentUserName(user,CF_SMALLBUF); if (INTERACTIVE) { CfOut(cf_verbose,""," -> Using interactive key trust...\n"); gotkey = (long)HavePublicKey(user,peer,digest); if (!gotkey) { gotkey = (long)HavePublicKey(user,ipv4,digest); } if (!gotkey) { printf("WARNING - You do not have a public key from host %s = %s\n",host,ipv4); printf(" Do you want to accept one on trust? (yes/no)\n\n--> "); while (true) { fgets(reply,8,stdin); Chop(reply); if (strcmp(reply,"yes")==0) { printf(" -> Will trust the key...\n"); a.copy.trustkey = true; break; } else if (strcmp(reply,"no")==0) { printf(" -> Will not trust the key...\n"); a.copy.trustkey = false; break; } else { printf(" !! Please reply yes or no...(%s)\n",reply); } } } } /* Continue */ #ifdef MINGW CfOut(cf_inform,"","...........................................................................\n"); CfOut(cf_inform,""," * Hailing %s : %u, with options \"%s\" (serial)\n",peer,a.copy.portnumber,REMOTE_AGENT_OPTIONS); CfOut(cf_inform,"","...........................................................................\n"); #else /* NOT MINGW */ if (BACKGROUND) { CfOut(cf_inform,"","Hailing %s : %u, with options \"%s\" (parallel)\n",peer,a.copy.portnumber,REMOTE_AGENT_OPTIONS); } else { CfOut(cf_inform,"","...........................................................................\n"); CfOut(cf_inform,""," * Hailing %s : %u, with options \"%s\" (serial)\n",peer,a.copy.portnumber,REMOTE_AGENT_OPTIONS); CfOut(cf_inform,"","...........................................................................\n"); } #endif /* NOT MINGW */ a.copy.servers = SplitStringAsRList(peer,'*'); if (a.copy.servers == NULL || strcmp(a.copy.servers->item,"localhost") == 0) { cfPS(cf_inform,CF_NOP,"",pp,a,"No hosts are registered to connect to"); return false; } else { conn = NewServerConnection(a,pp); if (conn == NULL) { CfOut(cf_verbose,""," -> No suitable server responded to hail\n"); return false; } } /* Check trust interaction*/ pp->cache = NULL; if (strlen(MENU) > 0) { #ifdef HAVE_NOVA enum cfd_menu menu = String2Menu(MENU); switch(menu) { case cfd_menu_delta: Nova_QueryForKnowledgeMap(conn,MENU,time(0) - SECONDS_PER_MINUTE * 10); break; case cfd_menu_full: Nova_QueryForKnowledgeMap(conn,MENU,time(0) - SECONDS_PER_WEEK); break; case cfd_menu_relay: #ifdef HAVE_CONSTELLATION queries = Constellation_CreateAllQueries(); Constellation_QueryRelay(conn,queries); DeleteItemList(queries); #endif break; default: break; } #endif /* HAVE_NOVA */ } else { HailExec(conn,peer,recvbuffer,sendbuffer); } ServerDisconnection(conn); DeleteRlist(a.copy.servers); return true; }
static void TexinfoVariables(const char *source_dir, FILE *fout, char *scope) { char filename[CF_BUFSIZE], varname[CF_BUFSIZE]; Rlist *rp, *list = NULL; int i; char *extra_mon[] = { "listening_udp4_ports", "listening_tcp4_ports", "listening_udp6_ports", "listening_tcp6_ports", NULL }; HashToList(GetScope(scope), &list); list = AlphaSortRListNames(list); fprintf(fout, "\n\n@node Variable context %s\n@section Variable context @code{%s}\n\n", scope, scope); snprintf(filename, CF_BUFSIZE - 1, "varcontexts/%s_intro.texinfo", scope); IncludeManualFile(source_dir, fout, filename); fprintf(fout, "@menu\n"); if (strcmp(scope, "mon") != 0) { for (rp = list; rp != NULL; rp = rp->next) { fprintf(fout, "* Variable %s.%s::\n", scope, (char *) rp->item); } } else { for (i = 0; extra_mon[i] != NULL; i++) { fprintf(fout, "* Variable %s.%s::\n", "mon", extra_mon[i]); } for (i = 0; i < CF_OBSERVABLES; ++i) { if (strcmp(OBS[i][0], "spare") == 0) { break; } fprintf(fout, "* Variable mon.value_%s::\n", OBS[i][0]); fprintf(fout, "* Variable mon.av_%s::\n", OBS[i][0]); fprintf(fout, "* Variable mon.dev_%s::\n", OBS[i][0]); } } fprintf(fout, "@end menu\n"); if (strcmp(scope, "mon") != 0) { for (rp = list; rp != NULL; rp = rp->next) { fprintf(fout, "@node Variable %s.%s\n@subsection Variable %s.%s \n\n", scope, (char *) rp->item, scope, (char *) rp->item); snprintf(filename, CF_BUFSIZE - 1, "vars/%s_%s.texinfo", scope, (char *) rp->item); IncludeManualFile(source_dir, fout, filename); } } else { for (i = 0; extra_mon[i] != NULL; i++) { fprintf(fout, "\n@node Variable %s.%s\n@subsection Variable %s.%s \n\n", "mon", extra_mon[i], "mon", extra_mon[i]); fprintf(fout, "List variable containing an observational measure collected every 2.5 minutes from cf-monitord, description: port numbers that were observed to be set up to receive connections on the host concerned"); } for (i = 0; i < CF_OBSERVABLES; i++) { if (strcmp(OBS[i][0], "spare") == 0) { break; } snprintf(varname, CF_MAXVARSIZE, "value_%s", OBS[i][0]); fprintf(fout, "\n@node Variable %s.%s\n@subsection Variable %s.%s \n\n", scope, varname, scope, varname); fprintf(fout, "Observational measure collected every 2.5 minutes from cf-monitord, description: @var{%s}.", OBS[i][1]); snprintf(varname, CF_MAXVARSIZE, "av_%s", OBS[i][0]); fprintf(fout, "\n@node Variable %s.%s\n@subsection Variable %s.%s \n\n", scope, varname, scope, varname); fprintf(fout, "Observational measure collected every 2.5 minutes from cf-monitord, description: @var{%s}.", OBS[i][1]); snprintf(varname, CF_MAXVARSIZE, "dev_%s", OBS[i][0]); fprintf(fout, "\n@node Variable %s.%s\n@subsection Variable %s.%s \n\n", scope, varname, scope, varname); fprintf(fout, "Observational measure collected every 2.5 minutes from cf-monitord, description: @var{%s}.", OBS[i][1]); } } DeleteRlist(list); }