void GetConfigFileOptions()

in Unix/server/servercommon.c [646:946]


void GetConfigFileOptions()
{
    char path[PAL_MAX_PATH_SIZE];
    Conf* conf;

    /* Form the configuration file path */
    Strlcpy(path, OMI_GetPath(ID_CONFIGFILE), sizeof(path));

    /* Open the configuration file */
    conf = Conf_Open(path);
    if (!conf)
    {
        err(ZT("failed to open configuration file: %s"), scs(path));
    }

    /* For each key=value pair in configuration file */
    for (;;)
    {
        const char* key;
        const char* value;
        int r = Conf_Read(conf, &key, &value);

        if (r == -1)
        {
            err(ZT("%s: %s\n"), path, scs(Conf_Error(conf)));
        }

        if (r == 1)
            break;

        if (strcmp(key, "httpport") == 0)
        {
            if ( _ParseHttpPortSpecification(&s_optsPtr->httpport, &s_optsPtr->httpport_size, value, CONFIG_HTTPPORT) )
            {
                err(ZT("%s(%u): invalid value for '%s': %s"), scs(path), Conf_Line(conf), scs(key), scs(value));
            }
        }
        else if (strcmp(key, "httpsport") == 0)
        {
            if ( _ParseHttpPortSpecification(&s_optsPtr->httpsport, &s_optsPtr->httpsport_size, value, CONFIG_HTTPSPORT) )
            {
                err(ZT("%s(%u): invalid value for '%s': %s"), scs(path), Conf_Line(conf), scs(key), scs(value));
            }
        }
        else if (strcmp(key, "idletimeout") == 0)
        {
            char* end;
            MI_Uint64 x = Strtoull(value, &end, 10);

            if (*end != '\0')
            {
                err(ZT("%s(%u): invalid value for '%s': %s"), scs(path), Conf_Line(conf), scs(key), scs(value));
            }

            s_optsPtr->idletimeout = x;
        }
        else if (strcmp(key, "livetime") == 0)
        {
            char* end;
            MI_Uint64 x = Strtoull(value, &end, 10);

            if (*end != '\0')
            {
                err(ZT("%s(%u): invalid value for '%s': %s"), scs(path), Conf_Line(conf), scs(key), scs(value));
            }

            s_optsPtr->livetime = x;
        }
        else if (strcmp(key, "trace") == 0)
        {
            if (Strcasecmp(value, "true") == 0)
            {
#if !defined(CONFIG_FAVORSIZE)
                s_optsPtr->trace = MI_TRUE;
#endif
            }
            else if (Strcasecmp(value, "false") == 0)
            {
#if !defined(CONFIG_FAVORSIZE)
                s_optsPtr->trace = MI_FALSE;
#endif
            }
            else
            {
                err(ZT("%s(%u): invalid value for '%s': %s"), scs(path), Conf_Line(conf), scs(key), scs(value));
            }
        }
        else if (strcmp(key, "httptrace") == 0)
        {
            if (Strcasecmp(value, "true") == 0)
            {
                s_optsPtr->httptrace = MI_TRUE;
            }
            else if (Strcasecmp(value, "false") == 0)
            {
                s_optsPtr->httptrace = MI_FALSE;
            }
            else
            {
                err(ZT("%s(%u): invalid value for '%s': %s"), scs(path), Conf_Line(conf), scs(key), scs(value));
            }
        }
        else if (strcmp(key, "loglevel") == 0)
        {
            if (Log_SetLevelFromString(value) != 0)
            {
                err(ZT("%s(%u): invalid value for '%s': %s"), scs(path), Conf_Line(conf), scs(key), scs(value));
            }
        }
        else if (strcmp(key, "sslciphersuite") == 0)
        {
            size_t valueLength = strlen(value);
            if (valueLength > SSLCIPHERSUITE_LIMIT)
            {
                err(ZT("Cipher length is more than reasonable limit"));
            }
            s_optsPtr->sslCipherSuite = PAL_Malloc(valueLength + 1);
            if (s_optsPtr->sslCipherSuite == NULL)
            {
                err(ZT("Out of memory"));
            }
            Strlcpy(s_optsPtr->sslCipherSuite, value, valueLength+1);
            s_optsPtr->sslCipherSuite[valueLength] = '\0';
        }
        else if (strcmp(key, "NoSSLv2") == 0)
        {
            if (Strcasecmp(value, "true") == 0)
            {
                s_optsPtr->sslOptions |= DISABLE_SSL_V2;
            }
            else if (Strcasecmp(value, "false") == 0)
            {
                s_optsPtr->sslOptions &= ~DISABLE_SSL_V2;
            }
            else
            {
                err(ZT("%s(%u): invalid value for '%s': %s"), scs(path), Conf_Line(conf), scs(key), scs(value));
            }
        }
        else if (strcmp(key, "NoSSLv3") == 0)
        {
            if (Strcasecmp(value, "true") == 0)
            {
                s_optsPtr->sslOptions |= DISABLE_SSL_V3;
            }
            else if (Strcasecmp(value, "false") == 0)
            {
                s_optsPtr->sslOptions &= ~DISABLE_SSL_V3;
            }
            else
            {
                err(ZT("%s(%u): invalid value for '%s': %s"), scs(path), Conf_Line(conf), scs(key), scs(value));
            }
        }
        else if (strcmp(key, "NoTLSv1_0") == 0)
        {
            if (Strcasecmp(value, "true") == 0)
            {
                s_optsPtr->sslOptions |= DISABLE_TLS_V1_0;
            }
            else if (Strcasecmp(value, "false") == 0)
            {
                s_optsPtr->sslOptions &= ~DISABLE_TLS_V1_0;
            }
            else
            {
                err(ZT("%s(%u): invalid value for '%s': %s"), scs(path), Conf_Line(conf), scs(key), scs(value));
            }
        }
        else if (strcmp(key, "NoTLSv1_1") == 0)
        {
            if (Strcasecmp(value, "true") == 0)
            {
                s_optsPtr->sslOptions |= DISABLE_TLS_V1_1;
            }
            else if (Strcasecmp(value, "false") == 0)
            {
                s_optsPtr->sslOptions &= ~DISABLE_TLS_V1_1;
            }
            else
            {
                err(ZT("%s(%u): invalid value for '%s': %s"), scs(path), Conf_Line(conf), scs(key), scs(value));
            }
        }
        else if (strcmp(key, "NoTLSv1_2") == 0)
        {
            if (Strcasecmp(value, "true") == 0)
            {
                s_optsPtr->sslOptions |= DISABLE_TLS_V1_2;
            }
            else if (Strcasecmp(value, "false") == 0)
            {
                s_optsPtr->sslOptions &= ~DISABLE_TLS_V1_2;
            }
            else
            {
                err(ZT("%s(%u): invalid value for '%s': %s"), scs(path), Conf_Line(conf), scs(key), scs(value));
            }
        }
        else if (strcmp(key, "NoSSLCompression") == 0)
        {
            if (Strcasecmp(value, "true") == 0)
            {
                s_optsPtr->sslOptions |= DISABLE_SSL_COMPRESSION;
            }
            else if (Strcasecmp(value, "false") == 0)
            {
                s_optsPtr->sslOptions &= ~DISABLE_SSL_COMPRESSION;
            }
            else
            {
                err(ZT("%s(%u): invalid value for '%s': %s"), scs(path), Conf_Line(conf), scs(key), scs(value));
            }
        }
        else if (IsNickname(key))
        {
            if (SetPathFromNickname(key, value) != 0)
            {
                err(ZT("SetPathFromNickname() failed"));
            }
        }
        else if (strcasecmp(key, "NtlmCredsFile") == 0)
        {
            if (value)
            {
                s_optsPtr->ntlmCredFile = PAL_Strdup(value);
            }
        }
        else if (strcasecmp(key, "Krb5CredCache") == 0)
        {
            if (value)
            {
                s_optsPtr->krb5CredCacheSpec = PAL_Strdup(value);
            }
        }
        else if (strcasecmp(key, "nonroot") == 0)
        {
            if (Strcasecmp(value, "true") == 0)
            {
                s_optsPtr->nonRoot = MI_TRUE;
            }
            else if (Strcasecmp(value, "false") == 0)
            {
                s_optsPtr->nonRoot = MI_FALSE;
            }
            else
            {
                err(ZT("%s(%u): invalid value for '%s': %s"), scs(path), Conf_Line(conf), scs(key), scs(value));
            }
        }
        else if (strcasecmp(key, "service") == 0)
        {
            if (value)
            {
                if (s_optsPtr->serviceAccount)
                {
                    PAL_Free((void*)s_optsPtr->serviceAccount);
                }
                s_optsPtr->serviceAccount = PAL_Strdup(value);
            }
        }
        else if (strcasecmp(key, "agentdebugging") == 0)
        {
            if (Strcasecmp(value, "true") == 0)
            {
                s_optsPtr->agentDebugging = MI_TRUE;
            }
            else if (Strcasecmp(value, "false") == 0)
            {
                s_optsPtr->agentDebugging = MI_FALSE;
            }
            else
            {
                err(ZT("%s(%u): invalid value for '%s': %s"), scs(path), Conf_Line(conf), scs(key), scs(value));
            }
        }
        else if (strcasecmp(key, "authorizedgroups") == 0)
        {
            if (value != 0)
            {
                _ParsePermissionGroups(&s_optsPtr->allowedList, (char*)value);
            }
        }
        else if (strcasecmp(key, "unauthorizedgroups") == 0)
        {
            if (value != 0)
            {
                _ParsePermissionGroups(&s_optsPtr->deniedList, (char*)value);
            }
        }
        else
        {
            err(ZT("%s(%u): unknown key: %s"), scs(path), Conf_Line(conf), scs(key));
        }
    }

    /* Close configuration file */
    Conf_Close(conf);

    return;
}