00001 /* 00002 * Copyright (c) 1987, 1993, 1994 00003 * The Regents of the University of California. All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions 00007 * are met: 00008 * 1. Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * 2. Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * 3. All advertising materials mentioning features or use of this software 00014 * must display the following acknowledgement: 00015 * This product includes software developed by the University of 00016 * California, Berkeley and its contributors. 00017 * 4. Neither the name of the University nor the names of its contributors 00018 * may be used to endorse or promote products derived from this software 00019 * without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 00022 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00023 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00024 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 00025 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00026 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 00027 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 00028 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 00029 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 00030 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00031 * SUCH DAMAGE. 00032 */ 00033 00034 00035 #include <stdio.h> 00036 #include <string.h> 00037 #include <signal.h> 00038 #include <pcap.h> // for PCAP_ERRBUF_SIZE 00039 #include "rpcapd.h" 00040 #include "pcap-remote.h" 00041 #include "sockutils.h" // for SOCK_ASSERT 00042 00043 00044 extern char hostlist[MAX_HOST_LIST + 1]; 00045 extern struct active_pars activelist[MAX_ACTIVE_LIST]; 00046 extern int nullAuthAllowed; 00047 extern char loadfile[MAX_LINE + 1]; 00048 00049 00050 00051 int strrem(char *string, char chr); 00052 00053 00054 00055 void fileconf_read(int sign) 00056 { 00057 FILE *fp; 00058 char msg[PCAP_ERRBUF_SIZE + 1]; 00059 int i; 00060 00061 #ifndef WIN32 00062 signal(SIGHUP, fileconf_read); 00063 #endif 00064 00065 if ((fp= fopen(loadfile, "r") ) != NULL) 00066 { 00067 char line[MAX_LINE + 1]; 00068 char *ptr; 00069 00070 hostlist[0]= 0; 00071 i= 0; 00072 00073 while ( fgets(line, MAX_LINE, fp) != NULL ) 00074 { 00075 if (line[0] == '\n') continue; // Blank line 00076 if (line[0] == '\r') continue; // Blank line 00077 if (line[0] == '#') continue; // Comment 00078 00079 if ( (ptr= strstr(line, "ActiveClient")) ) 00080 { 00081 char *address, *port; 00082 00083 ptr= strchr(ptr, '=') + 1; 00084 address= strtok(ptr, RPCAP_HOSTLIST_SEP); 00085 00086 if ( (address != NULL) && (i < MAX_ACTIVE_LIST) ) 00087 { 00088 port = strtok(NULL, RPCAP_HOSTLIST_SEP); 00089 snprintf(activelist[i].address, MAX_LINE, address); 00090 00091 if (strcmp(port, "DEFAULT") == 0) // the user choose a custom port 00092 snprintf(activelist[i].port, MAX_LINE, RPCAP_DEFAULT_NETPORT_ACTIVE); 00093 else 00094 snprintf(activelist[i].port, MAX_LINE, port); 00095 00096 activelist[i].address[MAX_LINE] = 0; 00097 activelist[i].port[MAX_LINE] = 0; 00098 } 00099 else 00100 SOCK_ASSERT("Only MAX_ACTIVE_LIST active connections are currently supported.", 1); 00101 00102 i++; 00103 continue; 00104 } 00105 00106 if ( (ptr= strstr(line, "PassiveClient")) ) 00107 { 00108 ptr= strchr(ptr, '=') + 1; 00109 strncat(hostlist, ptr, MAX_HOST_LIST); 00110 strncat(hostlist, ",", MAX_HOST_LIST); 00111 continue; 00112 } 00113 00114 if ( (ptr= strstr(line, "NullAuthPermit")) ) 00115 { 00116 ptr= strstr(ptr, "YES"); 00117 if (ptr) 00118 nullAuthAllowed= 1; 00119 else 00120 nullAuthAllowed= 0; 00121 continue; 00122 } 00123 } 00124 00125 // clear the remaining fields of the active list 00126 while (i < MAX_ACTIVE_LIST) 00127 { 00128 activelist[i].address[0] = 0; 00129 activelist[i].port[0] = 0; 00130 i++; 00131 } 00132 00133 // Remove all '\n' and '\r' from the strings 00134 strrem(hostlist, '\r'); 00135 strrem(hostlist, '\n'); 00136 00137 snprintf(msg, PCAP_ERRBUF_SIZE, "New passive host list: %s\n\n", hostlist); 00138 SOCK_ASSERT(msg, 1); 00139 fclose(fp); 00140 } 00141 } 00142 00143 00144 00145 int fileconf_save(const char *savefile) 00146 { 00147 FILE *fp; 00148 00149 if ((fp= fopen(savefile, "w") ) != NULL) 00150 { 00151 char *token; /*, *port;*/ // temp, needed to separate items into the hostlist 00152 char temphostlist[MAX_HOST_LIST + 1]; 00153 int i= 0; 00154 00155 fprintf(fp, "# Configuration file help.\n\n"); 00156 00157 // Save list of clients which are allowed to connect to us in passive mode 00158 fprintf(fp, "# Hosts which are allowed to connect to this server (passive mode)\n"); 00159 fprintf(fp, "# Format: PassiveClient = <name or address>\n\n"); 00160 00161 strncpy(temphostlist, hostlist, MAX_HOST_LIST); 00162 temphostlist[MAX_HOST_LIST]= 0; 00163 00164 token= strtok(temphostlist, RPCAP_HOSTLIST_SEP); 00165 while( token != NULL ) 00166 { 00167 fprintf(fp, "PassiveClient = %s\n", token); 00168 token = strtok(NULL, RPCAP_HOSTLIST_SEP); 00169 } 00170 00171 00172 // Save list of clients which are allowed to connect to us in active mode 00173 fprintf(fp, "\n\n"); 00174 fprintf(fp, "# Hosts to which this server is trying to connect to (active mode)\n"); 00175 fprintf(fp, "# Format: ActiveClient = <name or address>, <port | DEFAULT>\n\n"); 00176 00177 00178 while ( (activelist[i].address[0] != 0) && (i < MAX_ACTIVE_LIST) ) 00179 { 00180 fprintf(fp, "ActiveClient = %s, %s\n", activelist[i].address, activelist[i].port); 00181 i++; 00182 } 00183 00184 // Save if we want to permit NULL authentication 00185 fprintf(fp, "\n\n"); 00186 fprintf(fp, "# Permit NULL authentication: YES or NOT\n\n"); 00187 00188 if (nullAuthAllowed) 00189 fprintf(fp, "NullAuthPermit = YES\n"); 00190 else 00191 fprintf(fp, "NullAuthPermit = NO\n"); 00192 00193 fclose(fp); 00194 return 0; 00195 } 00196 else 00197 { 00198 return -1; 00199 } 00200 00201 } 00202 00203 00204 00205 int strrem(char *string, char chr) 00206 { 00207 char *pos; 00208 int num= 0; 00209 int len, i; 00210 00211 while ( (pos= strchr(string, chr) ) != NULL) 00212 { 00213 num++; 00214 len= strlen(pos); 00215 for (i=0; i<len; i++) 00216 pos[i]= pos[i+1]; 00217 } 00218 00219 return num; 00220 }
documentation. Copyright (c) 2002-2003 Politecnico di Torino. All rights reserved.