Changeset 706:4ffbc9f1e922 in freeDiameter for libfdcore/config.c
- Timestamp:
- Feb 9, 2011, 3:26:58 PM (13 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libfdcore/config.c
r686 r706 146 146 { 147 147 extern FILE * fddin; 148 char * orig = NULL; 148 149 149 150 /* Attempt to find the configuration file */ … … 154 155 if ((fddin == NULL) && (*fd_g_config->cnf_file != '/')) { 155 156 /* We got a relative path, attempt to add the default directory prefix */ 156 char * bkp= fd_g_config->cnf_file;157 CHECK_MALLOC( fd_g_config->cnf_file = malloc(strlen( bkp) + strlen(DEFAULT_CONF_PATH) + 2) ); /* we will not free it, but not important */158 sprintf( fd_g_config->cnf_file, DEFAULT_CONF_PATH "/%s", bkp);157 orig = fd_g_config->cnf_file; 158 CHECK_MALLOC( fd_g_config->cnf_file = malloc(strlen(orig) + strlen(DEFAULT_CONF_PATH) + 2) ); /* we will not free it, but not important */ 159 sprintf( fd_g_config->cnf_file, DEFAULT_CONF_PATH "/%s", orig ); 159 160 fddin = fopen(fd_g_config->cnf_file, "r"); 160 161 } 161 162 if (fddin == NULL) { 162 163 int ret = errno; 163 fprintf(stderr, "Unable to open configuration file %s for reading: %s\n", fd_g_config->cnf_file, strerror(ret)); 164 if (orig) { 165 fprintf(stderr, "Unable to open configuration file for reading\n" 166 "Tried the following locations:\n" 167 " - %s\n" 168 " - %s\n" 169 "Error: %s\n", orig, fd_g_config->cnf_file, strerror(ret)); 170 } else { 171 fprintf(stderr, "Unable to open '%s' for reading: %s\n", fd_g_config->cnf_file, strerror(ret)); 172 } 164 173 return ret; 165 174 } … … 178 187 } 179 188 189 /* If the CA is not provided, let's use the same file (assuming self-signed certificate) */ 190 if (! fd_g_config->cnf_sec_data.ca_file) { 191 CHECK_MALLOC( fd_g_config->cnf_sec_data.ca_file = strdup(fd_g_config->cnf_sec_data.cert_file) ); 192 CHECK_GNUTLS_DO( fd_g_config->cnf_sec_data.ca_file_nr += gnutls_certificate_set_x509_trust_file( 193 fd_g_config->cnf_sec_data.credentials, 194 fd_g_config->cnf_sec_data.ca_file, 195 GNUTLS_X509_FMT_PEM), 196 { 197 TRACE_DEBUG(INFO, "Unable to use the local certificate as trusted security anchor (CA), please provide a valid TLS_CA='...' directive."); 198 return EINVAL; 199 } ); 200 } 201 202 180 203 /* Resolve hostname if not provided */ 181 204 if (fd_g_config->cnf_diamid == NULL) { 182 #ifndef HOST_NAME_MAX183 #define HOST_NAME_MAX 1024184 #endif /* HOST_NAME_MAX */185 205 char buf[HOST_NAME_MAX + 1]; 186 206 struct addrinfo hints, *info; … … 202 222 return EINVAL; 203 223 } 204 CHECK_MALLOC( fd_g_config->cnf_diamid = strdup(info->ai_canonname) ); 224 fd_g_config->cnf_diamid = info->ai_canonname; 225 CHECK_FCT( fd_os_validate_DiameterIdentity(&fd_g_config->cnf_diamid, &fd_g_config->cnf_diamid_len, 1) ); 205 226 freeaddrinfo(info); 206 } 207 208 /* cache the length of the diameter id for the session module */ 209 fd_g_config->cnf_diamid_len = strlen(fd_g_config->cnf_diamid); 227 } else { 228 CHECK_FCT( fd_os_validate_DiameterIdentity(&fd_g_config->cnf_diamid, &fd_g_config->cnf_diamid_len, 0) ); 229 } 210 230 211 231 /* Handle the realm part */ … … 220 240 fd_g_config->cnf_diamid); 221 241 return EINVAL; 222 } 223 224 CHECK_MALLOC( fd_g_config->cnf_diamrlm = strdup( start + 1 ) ); 225 } 226 fd_g_config->cnf_diamrlm_len = strlen(fd_g_config->cnf_diamrlm); 242 } 243 244 fd_g_config->cnf_diamrlm = start + 1; 245 CHECK_FCT( fd_os_validate_DiameterIdentity(&fd_g_config->cnf_diamrlm, &fd_g_config->cnf_diamrlm_len, 1) ); 246 } else { 247 CHECK_FCT( fd_os_validate_DiameterIdentity(&fd_g_config->cnf_diamrlm, &fd_g_config->cnf_diamrlm_len, 0) ); 248 } 227 249 228 250 /* Validate some flags */
Note: See TracChangeset
for help on using the changeset viewer.