/* Demonstrates misfeature of original design */ static void test_aliasing_tolower(void **state) { char *abc = ToLowerStr("abc"); char *def = ToLowerStr("def"); assert_string_equal(abc, "def"); assert_string_equal(def, "def"); }
void SetDomainName(char *sp) /* Bas van der Vlies */ { char fqn[CF_MAXVARSIZE]; char *ptr; char buffer[CF_BUFSIZE]; if (gethostname(fqn, sizeof(fqn)) != -1) { strcpy(g_vfqname, fqn); strcpy(buffer, g_vfqname); AddClassToHeap(CanonifyName(buffer)); AddClassToHeap(CanonifyName(ToLowerStr(buffer))); if (strstr(fqn, ".")) { ptr = strchr(fqn, '.'); strcpy(g_vdomain, ++ptr); } } if (strstr(g_vfqname, ".") == 0 && (strcmp(g_vdomain, CF_START_DOMAIN) != 0)) { strcat(g_vfqname, "."); strcat(g_vfqname, g_vdomain); } AddClassToHeap(CanonifyName(g_vdomain)); DeleteClassFromHeap("undefined_domain"); }
static Topic *TopicExists(char *topic_name, char *topic_context) { Topic *tp; int slot; slot = GetHash(ToLowerStr(topic_name)); for (tp = TOPICHASH[slot]; tp != NULL; tp = tp->next) { if (strcmp(tp->topic_name, NormalizeTopic(topic_name)) == 0) { if (topic_context) { if (strlen(topic_context) > 0 && strcmp(tp->topic_context, NormalizeTopic(topic_context)) == 0) { return tp; } if (strlen(topic_context) == 0 && strcmp(tp->topic_context, "any") == 0) { return tp; } } } } return NULL; }
static void AddOccurrence(Occurrence **list, char *reference, Rlist *represents, enum representations rtype, char *context) { Occurrence *op = NULL; Rlist *rp; if ((op = OccurrenceExists(*list, reference, rtype, context)) == NULL) { op = xcalloc(1, sizeof(Occurrence)); op->occurrence_context = xstrdup(ToLowerStr(context)); op->locator = xstrdup(reference); op->rep_type = rtype; op->next = *list; *list = op; CF_OCCUR++; CfOut(cf_verbose, "", " -> Noted occurrence for %s::%s", context, reference); } /* Occurrence now exists, so add new subtype promises */ if (represents == NULL) { CfOut(cf_error, "", " !! Topic occurrence \"%s\" claims to represent no aspect of its topic, discarding...", reference); return; } for (rp = represents; rp != NULL; rp = rp->next) { IdempPrependRScalar(&(op->represents), rp->item, rp->type); } }
enum vnames ScanVariable(char *name) { int i = nonexistentvar; for (i = 0; VVNAMES[i] != '\0'; i++) { if (strcmp(VVNAMES[i],ToLowerStr(name)) == 0) { return (enum vnames) i; } } return (enum vnames) i; }
int TrueVar(char *var) { char buff[CF_EXPANDSIZE]; char varbuf[CF_MAXVARSIZE]; if (GetMacroValue(CONTEXTID,var)) { snprintf(varbuf,CF_MAXVARSIZE,"$(%s)",var); ExpandVarstring(varbuf,buff,NULL); if (strcmp(ToLowerStr(buff),"on") == 0) { return true; } if (strcmp(ToLowerStr(buff),"true") == 0) { return true; } } return false; }
local void hash_password(const char *name, const char *pwd, unsigned char out[HASHLEN], char work[NAMELEN+PWLEN]) { struct MD5Context ctx; memset(work, 0, NAMELEN+PWLEN); astrncpy(work, name, NAMELEN); ToLowerStr(work); astrncpy(work + NAMELEN, pwd, PWLEN); MD5Init(&ctx); MD5Update(&ctx, (unsigned char *)work, NAMELEN+PWLEN); MD5Final(out, &ctx); }
int GetTopicPid(char *classified_topic) { Topic *tp; int slot; char context[CF_MAXVARSIZE], name[CF_MAXVARSIZE]; name[0] = '\0'; DeClassifyTopic(classified_topic, name, context); slot = GetHash(ToLowerStr(name)); if ((tp = GetTopic(TOPICHASH[slot], classified_topic))) { return tp->id; } return 0; }
static char *NormalizeTopic(char *s) { char *sp; int special = false; for (sp = s; *sp != '\0'; sp++) { if (strchr("/\\&|=$@", *sp)) { special = true; break; } } if (special) { return s; } else { return ToLowerStr(s); } }
void GetNameInfo(void) { int i, found = false; char *sp, *sp2; time_t tloc; struct hostent *hp; struct sockaddr_in cin; #ifdef AIX char real_version[_SYS_NMLN]; #endif #ifdef IRIX char real_version[256]; /* see <sys/syssgi.h> */ #endif #ifdef HAVE_SYSINFO #ifdef SI_ARCHITECTURE long sz; #endif #endif Debug("GetNameInfo()\n"); g_vfqname[0] = g_vuqname[0] = '\0'; if (uname(&g_vsysname) == -1) { perror("uname "); FatalError("Uname couldn't get kernel name info!!\n"); } #ifdef AIX snprintf(real_version, _SYS_NMLN, "%.80s.%.80s", g_vsysname.version, g_vsysname.release); strncpy(g_vsysname.release, real_version, _SYS_NMLN); #elif defined IRIX /* This gets us something like `6.5.19m' rather than just `6.5'. */ syssgi (SGI_RELEASE_NAME, 256, real_version); #endif for (sp = g_vsysname.sysname; *sp != '\0'; sp++) { *sp = ToLower(*sp); } for (sp = g_vsysname.machine; *sp != '\0'; sp++) { *sp = ToLower(*sp); } for (i = 0; g_classattributes[i][0] != '\0'; i++) { if (WildMatch(g_classattributes[i][0], ToLowerStr(g_vsysname.sysname))) { if (WildMatch(g_classattributes[i][1], g_vsysname.machine)) { if (WildMatch(g_classattributes[i][2], g_vsysname.release)) { if (g_underscore_classes) { snprintf(g_vbuff, CF_BUFSIZE, "_%s", g_classtext[i]); AddClassToHeap(g_vbuff); } else { AddClassToHeap(g_classtext[i]); } found = true; g_vsystemhardclass = (enum classes) i; break; } } else { Debug2("Cfengine: I recognize %s but not %s\n", g_vsysname.sysname, g_vsysname.machine); continue; } } } if ((sp = malloc(strlen(g_vsysname.nodename)+1)) == NULL) { FatalError("malloc failure in initialize()"); } strcpy(sp, g_vsysname.nodename); SetDomainName(sp); /* Truncate fully qualified name */ for (sp2=sp; *sp2 != '\0'; sp2++) { if (*sp2 == '.') { *sp2 = '\0'; Debug("Truncating fully qualified hostname %s to %s\n", g_vsysname.nodename,sp); break; } } g_vdefaultbinserver.name = sp; AddClassToHeap(CanonifyName(sp)); if ((tloc = time((time_t *)NULL)) == -1) { printf("Couldn't read system clock\n"); } if (g_verbose || g_debug || g_d2 || g_d3) { if (g_underscore_classes) { snprintf(g_vbuff, CF_BUFSIZE, "_%s", g_classtext[i]); } else { snprintf(g_vbuff, CF_BUFSIZE, "%s", g_classtext[i]); } if (g_iscfengine) { printf ("cfng: configuration agent (cfagent) - \n%s\n%s\n\n", VERSION, g_copyright); } else { printf ("cfng: configuration server (cfservd) - \n%s\n%s\n\n", VERSION, g_copyright); } printf ("------------------------------------------------------------------------\n\n"); printf ("Host name is: %s\n", g_vsysname.nodename); printf ("Operating System Type is %s\n", g_vsysname.sysname); printf ("Operating System Release is %s\n", g_vsysname.release); printf ("Architecture = %s\n\n\n", g_vsysname.machine); printf ("Using internal soft-class %s for host %s\n\n", g_vbuff, g_classtext[g_vsystemhardclass]); printf ("The time is now %s\n\n", ctime(&tloc)); printf ("------------------------------------------------------------------------\n\n"); } sprintf(g_vbuff, "%d_bit", sizeof(long)*8); AddClassToHeap(g_vbuff); Verbose("Additional hard class defined as: %s\n", CanonifyName(g_vbuff)); snprintf(g_vbuff, CF_BUFSIZE, "%s_%s", g_vsysname.sysname, g_vsysname.release); AddClassToHeap(CanonifyName(g_vbuff)); #ifdef IRIX /* * Get something like `irix64_6_5_19m' defined as well as * `irix64_6_5'. Just copying the latter into g_vsysname.release * wouldn't be backwards-compatible. */ snprintf(g_vbuff, CF_BUFSIZE, "%s_%s", g_vsysname.sysname, real_version); AddClassToHeap(CanonifyName(g_vbuff)); #endif AddClassToHeap(CanonifyName(g_vsysname.machine)); Verbose("Additional hard class defined as: %s\n",CanonifyName(g_vbuff)); snprintf(g_vbuff, CF_BUFSIZE,"%s_%s", g_vsysname.sysname, g_vsysname.machine); AddClassToHeap(CanonifyName(g_vbuff)); Verbose("Additional hard class defined as: %s\n",CanonifyName(g_vbuff)); snprintf(g_vbuff, CF_BUFSIZE, "%s_%s_%s", g_vsysname.sysname, g_vsysname.machine, g_vsysname.release); AddClassToHeap(CanonifyName(g_vbuff)); Verbose("Additional hard class defined as: %s\n", CanonifyName(g_vbuff)); #ifdef HAVE_SYSINFO #ifdef SI_ARCHITECTURE sz = sysinfo(SI_ARCHITECTURE, g_vbuff, CF_BUFSIZE); if (sz == -1) { Verbose("cfagent internal: sysinfo returned -1\n"); } else { AddClassToHeap(CanonifyName(g_vbuff)); Verbose("Additional hard class defined as: %s\n", g_vbuff); } #endif #endif snprintf(g_vbuff, CF_BUFSIZE, "%s_%s_%s_%s", g_vsysname.sysname, g_vsysname.machine, g_vsysname.release, g_vsysname.version); if (strlen(g_vbuff) < CF_MAXVARSIZE-2) { g_varch = strdup(CanonifyName(g_vbuff)); } else { Verbose("cfagent internal: $(arch) overflows CF_MAXVARSIZE! Truncating\n"); g_varch = strdup(CanonifyName(g_vsysname.sysname)); } snprintf(g_vbuff, CF_BUFSIZE, "%s_%s", g_vsysname.sysname, g_vsysname.machine); g_varch2 = strdup(CanonifyName(g_vbuff)); AddClassToHeap(g_varch); Verbose("Additional hard class defined as: %s\n", g_varch); if (! found) { CfLog(cferror,"Cfengine: I don't understand " "what architecture this is!",""); } strcpy(g_vbuff, "compiled_on_"); strcat(g_vbuff, CanonifyName(AUTOCONF_SYSNAME)); AddClassToHeap(CanonifyName(g_vbuff)); Verbose("\nGNU autoconf class from compile time: %s\n\n", g_vbuff); /* Get IP address from nameserver */ if ((hp = gethostbyname(g_vsysname.nodename)) == NULL) { return; } else { memset(&cin, 0, sizeof(cin)); cin.sin_addr.s_addr = ((struct in_addr *)(hp->h_addr))->s_addr; Verbose("Address given by nameserver: %s\n", inet_ntoa(cin.sin_addr)); strcpy(g_vipaddress, inet_ntoa(cin.sin_addr)); for (i=0; hp->h_aliases[i] != NULL; i++) { Debug("Adding alias %s..\n", hp->h_aliases[i]); AddClassToHeap(CanonifyName(hp->h_aliases[i])); } } }
static void test_hi_alphabet_tolower(void **state) { assert_string_equal(ToLowerStr(hi_alphabet), lo_alphabet); }
static void test_weird_chars_tolower(void **state) { static const char *weirdstuff = "1345\0xff%$#@!"; assert_string_equal(ToLowerStr(weirdstuff), weirdstuff); }
static void test_empty_tolower(void **state) { assert_string_equal(ToLowerStr(""), ""); }
static void test_mix_case_tolower(void **state) { assert_string_equal(ToLowerStr("aBcD"), "abcd"); }
static TopicAssociation *AssociationExists(TopicAssociation *list, char *fwd, char *bwd) { TopicAssociation *ta; int yfwd = false, ybwd = false; char l[CF_BUFSIZE], r[CF_BUFSIZE]; if (fwd == NULL || (fwd && strlen(fwd) == 0)) { CfOut(cf_error, "", "NULL forward association name\n"); return NULL; } if (bwd == NULL || (bwd && strlen(bwd) == 0)) { CfOut(cf_verbose, "", "NULL backward association name\n"); } for (ta = list; ta != NULL; ta = ta->next) { if (fwd && (strcmp(fwd, ta->fwd_name) == 0)) { CfOut(cf_verbose, "", "Association '%s' exists already\n", fwd); yfwd = true; } else if (fwd && ta->fwd_name) { strncpy(l, ToLowerStr(fwd), CF_MAXVARSIZE); strncpy(r, ToLowerStr(ta->fwd_name), CF_MAXVARSIZE); if (strcmp(l, r) == 0) { CfOut(cf_error, "", " ! Association \"%s\" exists with different capitalization \"%s\"\n", fwd, ta->fwd_name); yfwd = true; } else { yfwd = false; } } else { yfwd = false; } if (bwd && (strcmp(bwd, ta->bwd_name) == 0)) { CfOut(cf_verbose, "", " ! Association '%s' exists already\n", bwd); ybwd = true; } else if (bwd && ta->bwd_name) { strncpy(l, ToLowerStr(bwd), CF_MAXVARSIZE); strncpy(r, ToLowerStr(ta->bwd_name), CF_MAXVARSIZE); if (strcmp(l, r) == 0) { CfOut(cf_inform, "", " ! Association \"%s\" exists with different capitalization \"%s\"\n", bwd, ta->bwd_name); } ybwd = true; } else { ybwd = false; } if (yfwd && ybwd) { return ta; } } return NULL; }
static Topic *InsertTopic(char *name, char *context) { int slot = GetHash(ToLowerStr(name)); return AddTopic(&(TOPICHASH[slot]), name, context); }