static void FreeNsswitchConfContents(NsswitchConf *conf) { size_t i; for(i = 0; i < conf->lines.size; i++) { FreeNsswitchEntryContents(((NsswitchEntry *)conf->lines.data) + i); } }
static void FreeNsswitchConfContents(NsswitchConf *conf) { size_t i; for(i = 0; i < conf->lines.size; i++) { FreeNsswitchEntryContents(((NsswitchEntry *)conf->lines.data) + i); } CT_SAFE_FREE_STRING(conf->filename); CTArrayFree(&conf->lines); }
static DWORD AddFormattedLine(NsswitchConf *conf, const char *filename, const char *linestr, const char **endptr) { DWORD ceError = ERROR_SUCCESS; NsswitchEntry lineObj; const char *pos = linestr; const char *token_start = NULL; CTParseToken token; memset(&lineObj, 0, sizeof(lineObj)); memset(&token, 0, sizeof(token)); /* Find the leading whitespace in the line */ token_start = pos; while(isblank(*pos)) pos++; GCE(ceError = CTStrndup(token_start, pos - token_start, &lineObj.leadingWhiteSpace)); /* Read the name of the entry and attach its trailing : or = */ GCE(ceError = CTReadToken(&pos, &lineObj.name, "=: \t", ";#\r\n", "")); /* Create an array of the modules for this entry */ while(strchr("\r\n;#", *pos) == NULL) { GCE(ceError = CTReadToken(&pos, &token, ", \t", ";#\r\n", "")); GCE(ceError = CTArrayAppend(&lineObj.modules, sizeof(CTParseToken), &token, 1)); memset(&token, 0, sizeof(token)); } /*Read the comment, if there is one*/ token_start = pos; while(strchr("\r\n", *pos) == NULL) pos++; if(pos != token_start) GCE(ceError = CTStrndup(token_start, pos - token_start, &lineObj.comment)); GCE(ceError = CTArrayAppend(&conf->lines, sizeof(lineObj), &lineObj, 1)); memset(&lineObj, 0, sizeof(lineObj)); if(endptr != NULL) *endptr = pos; cleanup: FreeNsswitchEntryContents(&lineObj); CTFreeParseTokenContents(&token); return ceError; }
static DWORD RemoveLine(NsswitchConf *conf, int line) { DWORD ceError = ERROR_SUCCESS; NsswitchEntry *lineObj = (NsswitchEntry *)GetEntry(conf, line); if(lineObj == NULL) { GCE(ceError = ERROR_INVALID_PARAMETER); } FreeNsswitchEntryContents(lineObj); GCE(ceError = CTArrayRemove(&conf->lines, line, sizeof(NsswitchEntry), 1)); conf->modified = 1; cleanup: return ceError; }
static DWORD AddEntry(NsswitchConf *conf, const DistroInfo *distro, int *addedIndex, const char *name) { DWORD ceError = ERROR_SUCCESS; int line = -1; NsswitchEntry lineObj; const NsswitchEntry *copy; memset(&lineObj, 0, sizeof(lineObj)); GCE(ceError = CTStrdup(name, &lineObj.name.value)); for(line = 0; line < conf->lines.size; line++) { copy = GetEntry(conf, line); if(copy->name.value != NULL) { GCE(ceError = CTStrdup(copy->name.trailingSeparator, &lineObj.name.trailingSeparator)); break; } } if(lineObj.name.trailingSeparator == NULL) { //Couldn't find an existing line to copy the separator from. We'll //have to guess based on the OS if(distro->os == OS_AIX) GCE(ceError = CTStrdup(" = ", &lineObj.name.trailingSeparator)); else GCE(ceError = CTStrdup(": ", &lineObj.name.trailingSeparator)); } GCE(ceError = CTArrayAppend(&conf->lines, sizeof(NsswitchEntry), &lineObj, 1)); memset(&lineObj, 0, sizeof(lineObj)); conf->modified = 1; if(addedIndex != NULL) *addedIndex = conf->lines.size - 1; cleanup: FreeNsswitchEntryContents(&lineObj); return ceError; }