Navigation


Changeset 706:4ffbc9f1e922 in freeDiameter for libfdcore/config.c


Ignore:
Timestamp:
Feb 9, 2011, 3:26:58 PM (13 years ago)
Author:
Sebastien Decugis <sdecugis@nict.go.jp>
Branch:
default
Phase:
public
Message:

Large UNTESTED commit with the following changes:

  • Improved DiameterIdentity? handling (esp. interationalization issues), and improve efficiency of some string operations in peers, sessions, and dictionary modules (closes #7)
  • Cleanup in the session module to free only unreferenced sessions (#16)
  • Removed fd_cpu_flush_cache(), replaced by more robust alternatives.
  • Improved peer state machine algorithm to counter SCTP multistream race condition.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libfdcore/config.c

    r686 r706  
    146146{
    147147        extern FILE * fddin;
     148        char * orig = NULL;
    148149       
    149150        /* Attempt to find the configuration file */
     
    154155        if ((fddin == NULL) && (*fd_g_config->cnf_file != '/')) {
    155156                /* 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 );
    159160                fddin = fopen(fd_g_config->cnf_file, "r");
    160161        }
    161162        if (fddin == NULL) {
    162163                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                }
    164173                return ret;
    165174        }
     
    178187        }
    179188       
     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       
    180203        /* Resolve hostname if not provided */
    181204        if (fd_g_config->cnf_diamid == NULL) {
    182 #ifndef HOST_NAME_MAX
    183 #define HOST_NAME_MAX 1024
    184 #endif /* HOST_NAME_MAX */
    185205                char buf[HOST_NAME_MAX + 1];
    186206                struct addrinfo hints, *info;
     
    202222                        return EINVAL;
    203223                }
    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) );
    205226                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        }
    210230       
    211231        /* Handle the realm part */
     
    220240                                        fd_g_config->cnf_diamid);
    221241                        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        }
    227249       
    228250        /* Validate some flags */
Note: See TracChangeset for help on using the changeset viewer.