/***************************************************************************
 *   Nipper - The network infrastructure parser                            *
 *   Copyright (C) 2006 - 2008 by Ian Ventura-Whiting (Fizz)               *
 *   fizz@titania.co.uk                                                    *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 3 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program. If not, see <http://www.gnu.org/licenses/>.  *
 ***************************************************************************/


void processNameMappings(struct nipperConfig *nipper)
{
	// Variables...
	char tempString[nipper->maxSize];

/*	// Pointers...
	struct namePIXList *namePIXPointer = 0;
	struct staticPIX *staticPIXPointer = 0;
	struct routePIX *routePIXPointer = 0;
	struct accessListPIX *accessPIXPointer = 0;
	struct accessListPIXPermission *permissionPIXPointer = 0;
	struct objectGroupList *objectGroupPointer = 0;
	struct objectList *objectPointer = 0;
	struct interfacePIXConfig *interfacePIXPointer = 0;*/
	struct filterObjectConfig *filterObjectPointer = 0;
	struct filterConfig *filterPointer = 0;
	struct filterListConfig *filterListPointer = 0;
	struct objectListConfig *objectListPointer = 0;
	struct objectConfig *objectPointer = 0;

/*
	switch (nipper->deviceType)
	{

		// PIX Devices...
		case type_pix_firewall:
		case type_asa_firewall:
		case type_fwsm_firewall:

			if (nipper->pix->nameList != 0)
			{
				// Convert Interfaces
				interfacePIXPointer = nipper->pix->interface;
				while (interfacePIXPointer != 0)
				{
					// Search for a match
					namePIXPointer = nipper->pix->nameList;
					while ((namePIXPointer->next != 0) && (strcmp(namePIXPointer->name, interfacePIXPointer->ipAddress) != 0))
						namePIXPointer = namePIXPointer->next;

					// If match has been found
					if (strcmp(namePIXPointer->name, interfacePIXPointer->ipAddress) == 0)
					{
						strncpy(interfacePIXPointer->ipAddress, namePIXPointer->address, sizeof(interfacePIXPointer->ipAddress) - 1);
						interfacePIXPointer->ipAddress[strlen(namePIXPointer->address)] = 0;
					}

					// Next Interface
					interfacePIXPointer = interfacePIXPointer->next;
				}

				// Static NAT (Mapped IP)
				staticPIXPointer = nipper->pix->staticNAT;
				while (staticPIXPointer != 0)
				{
					// Search for a match
					namePIXPointer = nipper->pix->nameList;
					while ((namePIXPointer->next != 0) && (strcmp(namePIXPointer->name, staticPIXPointer->ipMapped) != 0))
						namePIXPointer = namePIXPointer->next;

					// If match has been found
					if (strcmp(namePIXPointer->name, staticPIXPointer->ipMapped) == 0)
					{
						strncpy(staticPIXPointer->ipMapped, namePIXPointer->address, sizeof(staticPIXPointer->ipMapped) - 1);
						staticPIXPointer->ipMapped[strlen(namePIXPointer->address)] = 0;
					}

					// Next
					staticPIXPointer = staticPIXPointer->next;
				}

				// Static NAT (Real IP)
				staticPIXPointer = nipper->pix->staticNAT;
				while (staticPIXPointer != 0)
				{
					// Search for a match
					namePIXPointer = nipper->pix->nameList;
					while ((namePIXPointer->next != 0) && (strcmp(namePIXPointer->name, staticPIXPointer->ipReal) != 0))
						namePIXPointer = namePIXPointer->next;

					// If match has been found
					if (strcmp(namePIXPointer->name, staticPIXPointer->ipReal) == 0)
					{
						strncpy(staticPIXPointer->ipReal, namePIXPointer->address, sizeof(staticPIXPointer->ipReal) - 1);
						staticPIXPointer->ipReal[strlen(namePIXPointer->address)] = 0;
					}

					// Next
					staticPIXPointer = staticPIXPointer->next;
				}

				// Static Routing (IP Address)
				routePIXPointer = nipper->pix->route;
				while (routePIXPointer != 0)
				{
					// Search for a match
					namePIXPointer = nipper->pix->nameList;
					while ((namePIXPointer->next != 0) && (strcmp(namePIXPointer->name, routePIXPointer->ipAddress) != 0))
						namePIXPointer = namePIXPointer->next;

					// If match has been found
					if (strcmp(namePIXPointer->name, routePIXPointer->ipAddress) == 0)
					{
						strncpy(routePIXPointer->ipAddress, namePIXPointer->address, sizeof(routePIXPointer->ipAddress) - 1);
						routePIXPointer->ipAddress[strlen(namePIXPointer->address)] = 0;
					}

					// Next
					routePIXPointer = routePIXPointer->next;
				}

				// Static Routing (Gateway)
				routePIXPointer = nipper->pix->route;
				while (routePIXPointer != 0)
				{
					// Search for a match
					namePIXPointer = nipper->pix->nameList;
					while ((namePIXPointer->next != 0) && (strcmp(namePIXPointer->name, routePIXPointer->gateway) != 0))
						namePIXPointer = namePIXPointer->next;

					// If match has been found
					if (strcmp(namePIXPointer->name, routePIXPointer->gateway) == 0)
					{
						strncpy(routePIXPointer->gateway, namePIXPointer->address, sizeof(routePIXPointer->gateway) - 1);
						routePIXPointer->gateway[strlen(namePIXPointer->address)] = 0;
					}

					// Next
					routePIXPointer = routePIXPointer->next;
				}

				// ACL (Source)
				accessPIXPointer = nipper->pix->access;
				while (accessPIXPointer != 0)
				{
					permissionPIXPointer = accessPIXPointer->permission;
					while (permissionPIXPointer != 0)
					{
						// Search for a match
						namePIXPointer = nipper->pix->nameList;
						while ((namePIXPointer->next != 0) && (strcmp(namePIXPointer->name, permissionPIXPointer->source) != 0))
							namePIXPointer = namePIXPointer->next;

						// If match has been found
						if (strcmp(namePIXPointer->name, permissionPIXPointer->source) == 0)
						{
							strncpy(permissionPIXPointer->source, namePIXPointer->address, sizeof(permissionPIXPointer->source) - 1);
							permissionPIXPointer->source[strlen(namePIXPointer->address)] = 0;
						}

						// Next
						permissionPIXPointer = permissionPIXPointer->next;
					}

					// Next
					accessPIXPointer = accessPIXPointer->next;
				}

				// ACL (Destination)
				accessPIXPointer = nipper->pix->access;
				while (accessPIXPointer != 0)
				{
					permissionPIXPointer = accessPIXPointer->permission;
					while (permissionPIXPointer != 0)
					{
						// Search for a match
						namePIXPointer = nipper->pix->nameList;
						while ((namePIXPointer->next != 0) && (strcmp(namePIXPointer->name, permissionPIXPointer->dest) != 0))
							namePIXPointer = namePIXPointer->next;

						// If match has been found
						if (strcmp(namePIXPointer->name, permissionPIXPointer->dest) == 0)
						{
							strncpy(permissionPIXPointer->dest, namePIXPointer->address, sizeof(permissionPIXPointer->dest) - 1);
							permissionPIXPointer->dest[strlen(namePIXPointer->address)] = 0;
						}

						// Next
						permissionPIXPointer = permissionPIXPointer->next;
					}

					// Next
					accessPIXPointer = accessPIXPointer->next;
				}

				// Object Groups
				objectGroupPointer = nipper->pix->objectGroup;
				while (objectGroupPointer != 0)
				{
					if (objectGroupPointer->type == object_type_network)
					{
						objectPointer = objectGroupPointer->object;
						while (objectPointer != 0)
						{
							if ((objectPointer->type == object_type_host) || (objectPointer->type == object_type_network))
							{
								// Search for a match
								namePIXPointer = nipper->pix->nameList;
								while ((namePIXPointer->next != 0) && (strcmp(namePIXPointer->name, objectPointer->object) != 0))
									namePIXPointer = namePIXPointer->next;

								// If match has been found
								if (strcmp(namePIXPointer->name, objectPointer->object) == 0)
								{
									strncpy(objectPointer->object, namePIXPointer->address, sizeof(objectPointer->object) - 1);
									objectPointer->object[strlen(namePIXPointer->address)] = 0;
								}
							}

							// Next
							objectPointer = objectPointer->next;
						}
					}

					// Next
					objectGroupPointer = objectGroupPointer->next;
				}
			}
			break;
	}*/

	// Convert filters names to ip addresses
	if ((nipper->filterList != 0) && (nipper->objectList != 0))
	{
		filterListPointer = nipper->filterList;
		while (filterListPointer != 0)
		{
			filterPointer = filterListPointer->filter;
			while (filterPointer != 0)
			{
				// Source...
				filterObjectPointer = filterPointer->source;
				while (filterObjectPointer != 0)
				{
					objectListPointer = nipper->objectList;
					if ((nipper->deviceType == type_sos_firewall) && (objectListPointer != 0))
					{
						while ((strcasecmp(filterListPointer->fromZone, objectListPointer->name) != 0) && (objectListPointer->next != 0))
							objectListPointer = objectListPointer->next;
						if (strcasecmp(filterListPointer->fromZone, objectListPointer->name) != 0)
							objectListPointer = 0;
					}
					while (objectListPointer != 0)
					{
						objectPointer = objectListPointer->object;
						while (objectPointer != 0)
						{
							if (strcasecmp(objectPointer->name, filterObjectPointer->name) == 0)
							{
								if (objectPointer->type == object_type_network)
								{
									sprintf(tempString, "%s %s", objectPointer->address, objectPointer->netMask);
									strncpy(filterObjectPointer->name, tempString, sizeof(filterObjectPointer->name) - 1);
									filterObjectPointer->name[strlen(tempString)] = 0;
								}
								else if (objectPointer->type == object_type_machinesrange)
								{
									sprintf(tempString, "%s - %s", objectPointer->address, objectPointer->netMask);
									strncpy(filterObjectPointer->name, tempString, sizeof(filterObjectPointer->name) - 1);
									filterObjectPointer->name[strlen(tempString)] = 0;
								}
								else if ((objectPointer->type != object_type_group) && (objectPointer->type != object_type_gateway_cluster))
								{
									strncpy(filterObjectPointer->name, objectPointer->address, sizeof(filterObjectPointer->name) - 1);
									filterObjectPointer->name[strlen(objectPointer->address)] = 0;
								}
							}
							objectPointer = objectPointer->next;
						}
						objectListPointer = objectListPointer->next;
					}
					filterObjectPointer = filterObjectPointer->next;
				}

				// Destination...
				filterObjectPointer = filterPointer->destination;
				while (filterObjectPointer != 0)
				{
					objectListPointer = nipper->objectList;
					if ((nipper->deviceType == type_sos_firewall) && (objectListPointer != 0))
					{
						while ((strcasecmp(filterListPointer->toZone, objectListPointer->name) != 0) && (objectListPointer->next != 0))
							objectListPointer = objectListPointer->next;
						if (strcasecmp(filterListPointer->toZone, objectListPointer->name) != 0)
							objectListPointer = 0;
					}
					while (objectListPointer != 0)
					{
						objectPointer = objectListPointer->object;
						while (objectPointer != 0)
						{
							if (strcasecmp(objectPointer->name, filterObjectPointer->name) == 0)
							{
								if (objectPointer->type == object_type_network)
								{
									sprintf(tempString, "%s %s", objectPointer->address, objectPointer->netMask);
									strncpy(filterObjectPointer->name, tempString, sizeof(filterObjectPointer->name) - 1);
									filterObjectPointer->name[strlen(tempString)] = 0;
								}
								else if (objectPointer->type == object_type_machinesrange)
								{
									sprintf(tempString, "%s - %s", objectPointer->address, objectPointer->netMask);
									strncpy(filterObjectPointer->name, tempString, sizeof(filterObjectPointer->name) - 1);
									filterObjectPointer->name[strlen(tempString)] = 0;
								}
								else if ((objectPointer->type != object_type_group) && (objectPointer->type != object_type_gateway_cluster))
								{
									strncpy(filterObjectPointer->name, objectPointer->address, sizeof(filterObjectPointer->name) - 1);
									filterObjectPointer->name[strlen(objectPointer->address)] = 0;
								}
							}
							objectPointer = objectPointer->next;
						}
						objectListPointer = objectListPointer->next;
					}
					filterObjectPointer = filterObjectPointer->next;
				}

				// Through...
				filterObjectPointer = filterPointer->through;
				while (filterObjectPointer != 0)
				{
					objectListPointer = nipper->objectList;
					while (objectListPointer != 0)
					{
						objectPointer = objectListPointer->object;
						while (objectPointer != 0)
						{
							if (strcasecmp(objectPointer->name, filterObjectPointer->name) == 0)
							{
								if (objectPointer->type == object_type_network)
								{
									sprintf(tempString, "%s %s", objectPointer->address, objectPointer->netMask);
									strncpy(filterObjectPointer->name, tempString, sizeof(filterObjectPointer->name) - 1);
									filterObjectPointer->name[strlen(tempString)] = 0;
								}
								else if (objectPointer->type == object_type_machinesrange)
								{
									sprintf(tempString, "%s - %s", objectPointer->address, objectPointer->netMask);
									strncpy(filterObjectPointer->name, tempString, sizeof(filterObjectPointer->name) - 1);
									filterObjectPointer->name[strlen(tempString)] = 0;
								}
								else if ((objectPointer->type != object_type_group) && (objectPointer->type != object_type_gateway_cluster))
								{
									strncpy(filterObjectPointer->name, objectPointer->address, sizeof(filterObjectPointer->name) - 1);
									filterObjectPointer->name[strlen(objectPointer->address)] = 0;
								}
							}
							objectPointer = objectPointer->next;
						}
						objectListPointer = objectListPointer->next;
					}
					filterObjectPointer = filterObjectPointer->next;
				}

				// Installed on...
				filterObjectPointer = filterPointer->install;
				while (filterObjectPointer != 0)
				{
					objectListPointer = nipper->objectList;
					while (objectListPointer != 0)
					{
						objectPointer = objectListPointer->object;
						while (objectPointer != 0)
						{
							if (strcasecmp(objectPointer->name, filterObjectPointer->name) == 0)
							{
								if (objectPointer->type == object_type_network)
								{
									sprintf(tempString, "%s %s", objectPointer->address, objectPointer->netMask);
									strncpy(filterObjectPointer->name, tempString, sizeof(filterObjectPointer->name) - 1);
									filterObjectPointer->name[strlen(tempString)] = 0;
								}
								else if (objectPointer->type == object_type_machinesrange)
								{
									sprintf(tempString, "%s - %s", objectPointer->address, objectPointer->netMask);
									strncpy(filterObjectPointer->name, tempString, sizeof(filterObjectPointer->name) - 1);
									filterObjectPointer->name[strlen(tempString)] = 0;
								}
								else if ((objectPointer->type != object_type_group) && (objectPointer->type != object_type_gateway_cluster))
								{
									strncpy(filterObjectPointer->name, objectPointer->address, sizeof(filterObjectPointer->name) - 1);
									filterObjectPointer->name[strlen(objectPointer->address)] = 0;
								}
							}
							objectPointer = objectPointer->next;
						}
						objectListPointer = objectListPointer->next;
					}
					filterObjectPointer = filterObjectPointer->next;
				}

				filterPointer = filterPointer->next;
			}
			filterListPointer = filterListPointer->next;
		}
	}
}
