nsresult nsMsgFilterDelegateFactory::getFilterDelegate(nsIRDFResource *aOuter, nsIMsgFilter **aResult) { nsresult rv; // now try to find ";filterName=" nsCString uri; rv = aOuter->GetValue(getter_Copies(uri)); if (NS_FAILED(rv)) return rv; PRInt32 separatorPosition = 0; const char *filterTag = uri.get(); while (filterTag && *filterTag != ';') { separatorPosition++; filterTag++; } // if no ;, and it's not a folder, // I don't know what the heck it is. if (!filterTag) return NS_ERROR_FAILURE; const char *filterName = getFilterName(filterTag); nsCOMPtr<nsIMsgFilterList> filterList; rv = getFilterList(uri.get(), separatorPosition, getter_AddRefs(filterList)); // now that we have the filter list and index, retrieve the filter. // XXX convert from UTF8 nsAutoString filterString; PRUnichar *unicodeString = nsTextFormatter::smprintf(unicodeFormatter, filterName); NS_ENSURE_TRUE(unicodeString, NS_ERROR_OUT_OF_MEMORY); filterString.Assign(unicodeString); nsTextFormatter::smprintf_free(unicodeString); nsCOMPtr<nsIMsgFilter> filter; rv = filterList->GetFilterNamed(filterString, getter_AddRefs(filter)); if (NS_FAILED(rv)) return rv; *aResult = filter; NS_IF_ADDREF(*aResult); return NS_OK; }
void processFW1Rulebase(char *line, struct nipperConfig *nipper) { // Variables... struct filterListConfig *filterListPointer = 0; struct filterConfig *filterPointer = 0; struct ciscoCommand command; char tempString[nipper->maxSize]; int tempInt = false; // Init... command = splitLine(line); // Get Filter List Pointer... command.part[1][strlen(command.part[1]) - 1] = 0; filterListPointer = getFilterList(nipper, command.part[1] + 4, "", false); // Does the list already exist? if (filterListPointer->filter != 0) { filterPointer = filterListPointer->filter; // Process lines while ((feof(nipper->input) == 0) && (strcasecmp(command.part[0], ")") != 0) && (filterPointer != 0)) { // Read line memset(line, 0, LINE_SIZE + 1); readLine(nipper->input, line, LINE_SIZE); // Init... command = splitLine(line); // Debug output if (nipper->debugMode == true) printf("Rulebase Line: %s\n", line); // Process Rules... if ((strcmp(command.part[0], ":rule") == 0) && (strcmp(command.part[1], "()") != 0)) { while ((feof(nipper->input) == 0) && (strcasecmp(command.part[0], ")") != 0) && (filterPointer != 0)) { // Read line memset(line, 0, LINE_SIZE + 1); readLine(nipper->input, line, LINE_SIZE); // Init... command = splitLine(line); // Debug output if (nipper->debugMode == true) printf("Rulebase Line: %s\n", line); // Comments... if ((strcasecmp(command.part[0], ":comments") == 0) && (strcasecmp(command.part[1], "()") != 0)) { command.part[1][strlen(command.part[1]) - 1] = 0; stripQuotes(command.part[1] + 1, filterPointer->remark, sizeof(filterPointer->remark) -1); } // Header Text... else if ((strcasecmp(command.part[0], ":header_text") == 0) && (strcasecmp(command.part[1], "()") != 0)) { command.part[1][strlen(command.part[1]) - 1] = 0; stripQuotes(command.part[1] + 1, tempString, sizeof(tempString) -1); insertFilterRemark(filterListPointer, filterPointer, true, tempString); tempInt = true; } // Process Unknown... else processFW1Unknown(nipper, line); } command.part[0][0] = 0; if (tempInt == false) filterPointer = filterPointer->next; else tempInt = false; } // Process Unknown... else processFW1Unknown(nipper, line); } command.part[0][0] = 0; } // List already exists... else { // Process lines while ((feof(nipper->input) == 0) && (strcasecmp(command.part[0], ")") != 0)) { // Read line memset(line, 0, LINE_SIZE + 1); readLine(nipper->input, line, LINE_SIZE); // Init... command = splitLine(line); // Debug output if (nipper->debugMode == true) printf("Rulebase Line: %s\n", line); // Process Rules... if ((strcmp(command.part[0], ":rule") == 0) && (strcmp(command.part[1], "()") != 0)) processFW1Rule(line, nipper, filterListPointer); // Process Unknown... else processFW1Unknown(nipper, line); } } }
void processSonicOSRule(char *line, struct nipperConfig *nipper) { // Variables... fpos_t filePosition; struct ciscoCommand command; struct filterListConfig *filterListPointer = 0; struct filterConfig *filterPointer = 0; struct filterConfig *filterSearchPointer = 0; struct filterObjectConfig *servicePointer = 0; struct filterObjectConfig *sourcePointer = 0; struct filterObjectConfig *destinationPointer = 0; int stopReading = false; int initialSetup = false; char sourceNet[32]; // Loop through the rule lines fgetpos(nipper->input, &filePosition); while ((feof(nipper->input) == 0) && (stopReading == false)) { // Debug output if (nipper->debugMode == true) printf("Rules Line: %s\n", line); // Init command = splitLine(line); // If filter does not yet exist... if (filterPointer == 0) { filterPointer = malloc(sizeof(struct filterConfig)); memset(filterPointer, 0, sizeof(struct filterConfig)); filterPointer->enabled = true; filterPointer->log = false; } // Rule Action... if (strncmp(command.part[0], "prefs_ruleAction_", 17) == 0) { if (initialSetup == false) { filterPointer->id = atoi(command.part[0] + 17); initialSetup = true; } if (filterPointer->id == atoi(command.part[0] + 17)) { if (strcasecmp(command.part[1], "allow") == 0) filterPointer->action = filter_action_accept; else if (strcasecmp(command.part[1], "deny") == 0) filterPointer->action = filter_action_reject; else filterPointer->action = filter_action_drop; } else stopReading = true; } // Service ID else if (strncmp(command.part[0], "prefs_ruleSvcID_", 16) == 0) { if (initialSetup == false) { filterPointer->id = atoi(command.part[0] + 16); initialSetup = true; } if (filterPointer->id == atoi(command.part[0] + 16)) { servicePointer = getFilterMember(filterPointer, command.part[1], object_filter_service); servicePointer->type = object_type_object; servicePointer->serviceOp = service_oper_eq; } else stopReading = true; } // Source Ethernet else if (strncmp(command.part[0], "prefs_ruleSrcEnet_", 18) == 0) { if (initialSetup == false) { filterPointer->id = atoi(command.part[0] + 18); initialSetup = true; } if (filterPointer->id == atoi(command.part[0] + 18)) strncpy(sourceNet, command.part[1], sizeof(sourceNet) - 1); else stopReading = true; } // Destination Ethernet else if (strncmp(command.part[0], "prefs_ruleDstEnet_", 18) == 0) { if (initialSetup == false) { filterPointer->id = atoi(command.part[0] + 18); initialSetup = true; } if (filterPointer->id == atoi(command.part[0] + 18)) { filterListPointer = getFilterList(nipper, sourceNet, command.part[1], false); filterListPointer->type = access_std; // If no filters yet... if (filterListPointer->filter == 0) filterListPointer->filter = filterPointer; else { filterSearchPointer = filterListPointer->filter; while (filterSearchPointer->next != 0) filterSearchPointer = filterSearchPointer->next; filterSearchPointer->next = filterPointer; } } else stopReading = true; } // Source Begin else if (strncmp(command.part[0], "prefs_ruleSrcBegin_", 19) == 0) { if (initialSetup == false) { filterPointer->id = atoi(command.part[0] + 19); initialSetup = true; } if (filterPointer->id == atoi(command.part[0] + 19)) sourcePointer = getFilterMember(filterPointer, command.part[1], object_filter_source); else stopReading = true; } // Source End else if (strncmp(command.part[0], "prefs_ruleSrcEnd_", 17) == 0) { if (initialSetup == false) { filterPointer->id = atoi(command.part[0] + 17); initialSetup = true; } if (filterPointer->id == atoi(command.part[0] + 17)) { strncpy(sourcePointer->netMask, command.part[1], sizeof(sourcePointer->netMask) - 1); if (strcmp(sourcePointer->name, "0.0.0.0") == 0) sourcePointer->type = object_type_any; else if (strcmp(sourcePointer->name, sourcePointer->netMask) != 0) sourcePointer->type = object_type_network; else sourcePointer->type = object_type_host; } else stopReading = true; } // Destination Begin else if (strncmp(command.part[0], "prefs_ruleDstBegin_", 19) == 0) { if (initialSetup == false) { filterPointer->id = atoi(command.part[0] + 19); initialSetup = true; } if (filterPointer->id == atoi(command.part[0] + 19)) destinationPointer = getFilterMember(filterPointer, command.part[1], object_filter_destination); else stopReading = true; } // Destination End else if (strncmp(command.part[0], "prefs_ruleDstEnd_", 17) == 0) { if (initialSetup == false) { filterPointer->id = atoi(command.part[0] + 17); initialSetup = true; } if (filterPointer->id == atoi(command.part[0] + 17)) { strncpy(destinationPointer->netMask, command.part[1], sizeof(destinationPointer->netMask) - 1); if (strcmp(destinationPointer->name, "0.0.0.0") == 0) destinationPointer->type = object_type_any; else if (strcmp(destinationPointer->name, destinationPointer->netMask) != 0) destinationPointer->type = object_type_network; else destinationPointer->type = object_type_host; } else stopReading = true; } // Rule Enabled else if (strncmp(command.part[0], "prefs_ruleEnabled_", 18) == 0) { if (initialSetup == false) { filterPointer->id = atoi(command.part[0] + 18); initialSetup = true; } if (filterPointer->id == atoi(command.part[0] + 18)) { if (strcmp(command.part[1], "1") == 0) filterPointer->enabled = true; else filterPointer->enabled = false; } else stopReading = true; } // Fragmentation else if (strncmp(command.part[0], "prefs_ruleAllowFrags_", 21) == 0) { if (initialSetup == false) { filterPointer->id = atoi(command.part[0] + 21); initialSetup = true; } if (filterPointer->id == atoi(command.part[0] + 21)) { if (strcmp(command.part[1], "off") == 0) filterPointer->fragments = false; else filterPointer->fragments = true; } else stopReading = true; } // Comments else if (strncmp(command.part[0], "ruleComment_", 12) == 0) { if (initialSetup == false) { filterPointer->id = atoi(command.part[0] + 12); initialSetup = true; } if (filterPointer->id == atoi(command.part[0] + 12)) strncpy(filterPointer->remark, line + strlen(command.part[0]) + 1, sizeof(filterPointer->remark) -1); else stopReading = true; } else if ((strncmp(command.part[0], "serviceNameInRule_", 18) != 0) || (strncmp(command.part[0], "prefs_rule", 10) == 0)) stopReading = true; if (stopReading == false) { // Get next line fgetpos(nipper->input, &filePosition); readLine(nipper->input, line, nipper->maxSize); } } // Set file position back fsetpos(nipper->input, &filePosition); // If the filter was not added to the list... if ((filterListPointer == 0) && (filterPointer != 0)) { if (sourcePointer != 0) free(sourcePointer); if (destinationPointer != 0) free(destinationPointer); if (servicePointer != 0) free (servicePointer); free(filterPointer); } }