123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216 |
- #ifdef HAVE_CONFIG_H
- #include <config.h>
- #endif
- #include "ftmacros.h"
- #include <stdio.h>
- #include <string.h>
- #include <signal.h>
- #include <pcap.h> // for PCAP_ERRBUF_SIZE
- #include "sockutils.h"
- #include "portability.h"
- #include "rpcapd.h"
- #include "config_params.h"
- #include "fileconf.h"
- #include "rpcap-protocol.h"
- static int strrem(char *string, char chr);
- void fileconf_read(void)
- {
- FILE *fp;
- char msg[PCAP_ERRBUF_SIZE + 1];
- int i;
- if ((fp = fopen(loadfile, "r")) != NULL)
- {
- char line[MAX_LINE + 1];
- char *ptr;
- hostlist[0] = 0;
- i = 0;
- while (fgets(line, MAX_LINE, fp) != NULL)
- {
- if (line[0] == '\n') continue;
- if (line[0] == '\r') continue;
- if (line[0] == '#') continue;
- ptr = strstr(line, "ActiveClient");
- if (ptr)
- {
- char *address, *port;
- char *lasts;
- ptr = strchr(ptr, '=') + 1;
- address = pcap_strtok_r(ptr, RPCAP_HOSTLIST_SEP, &lasts);
- if ((address != NULL) && (i < MAX_ACTIVE_LIST))
- {
- port = pcap_strtok_r(NULL, RPCAP_HOSTLIST_SEP, &lasts);
- strlcpy(activelist[i].address, address, MAX_LINE);
- if (strcmp(port, "DEFAULT") == 0)
- strlcpy(activelist[i].port, RPCAP_DEFAULT_NETPORT_ACTIVE, MAX_LINE);
- else
- strlcpy(activelist[i].port, port, MAX_LINE);
- activelist[i].address[MAX_LINE] = 0;
- activelist[i].port[MAX_LINE] = 0;
- }
- else
- SOCK_DEBUG_MESSAGE("Only MAX_ACTIVE_LIST active connections are currently supported.");
- i++;
- continue;
- }
- ptr = strstr(line, "PassiveClient");
- if (ptr)
- {
- ptr = strchr(ptr, '=') + 1;
- strlcat(hostlist, ptr, MAX_HOST_LIST);
- strlcat(hostlist, ",", MAX_HOST_LIST);
- continue;
- }
- ptr = strstr(line, "NullAuthPermit");
- if (ptr)
- {
- ptr = strstr(ptr, "YES");
- if (ptr)
- nullAuthAllowed = 1;
- else
- nullAuthAllowed = 0;
- continue;
- }
- }
-
- while (i < MAX_ACTIVE_LIST)
- {
- activelist[i].address[0] = 0;
- activelist[i].port[0] = 0;
- i++;
- }
-
- strrem(hostlist, '\r');
- strrem(hostlist, '\n');
- pcap_snprintf(msg, PCAP_ERRBUF_SIZE, "New passive host list: %s\n\n", hostlist);
- SOCK_DEBUG_MESSAGE(msg);
- fclose(fp);
- }
- }
- int fileconf_save(const char *savefile)
- {
- FILE *fp;
- if ((fp = fopen(savefile, "w")) != NULL)
- {
- char *token;
- char temphostlist[MAX_HOST_LIST + 1];
- int i = 0;
- char *lasts;
- fprintf(fp, "# Configuration file help.\n\n");
-
- fprintf(fp, "# Hosts which are allowed to connect to this server (passive mode)\n");
- fprintf(fp, "# Format: PassiveClient = <name or address>\n\n");
- strncpy(temphostlist, hostlist, MAX_HOST_LIST);
- temphostlist[MAX_HOST_LIST] = 0;
- token = pcap_strtok_r(temphostlist, RPCAP_HOSTLIST_SEP, &lasts);
- while(token != NULL)
- {
- fprintf(fp, "PassiveClient = %s\n", token);
- token = pcap_strtok_r(NULL, RPCAP_HOSTLIST_SEP, &lasts);
- }
-
- fprintf(fp, "\n\n");
- fprintf(fp, "# Hosts to which this server is trying to connect to (active mode)\n");
- fprintf(fp, "# Format: ActiveClient = <name or address>, <port | DEFAULT>\n\n");
- while ((i < MAX_ACTIVE_LIST) && (activelist[i].address[0] != 0))
- {
- fprintf(fp, "ActiveClient = %s, %s\n", activelist[i].address, activelist[i].port);
- i++;
- }
-
- fprintf(fp, "\n\n");
- fprintf(fp, "# Permit NULL authentication: YES or NOT\n\n");
- if (nullAuthAllowed)
- fprintf(fp, "NullAuthPermit = YES\n");
- else
- fprintf(fp, "NullAuthPermit = NO\n");
- fclose(fp);
- return 0;
- }
- else
- {
- return -1;
- }
- }
- static int strrem(char *string, char chr)
- {
- char *pos;
- int num = 0;
- int len, i;
- while ((pos = strchr(string, chr)) != NULL)
- {
- num++;
- len = strlen(pos);
- for (i = 0; i < len; i++)
- pos[i] = pos[i+1];
- }
- return num;
- }
|