void pw_pgsql_parse(const char * const file)
{
    if (generic_parser(file, pgsql_config_keywords) != 0) {
        die(421, LOG_ERR, MSG_CONF_ERR ": " MSG_ILLEGAL_CONFIG_FILE_SQL ": %s" , file);
    }    
    if (server == NULL ) {
        die(421, LOG_ERR, MSG_SQL_MISSING_SERVER);        
    }
    if (port_s != NULL) {
        port = atoi(port_s);
        if (port <= 0 || port > 65535) {
            port = PGSQL_DEFAULT_PORT;
        }
        free(port_s);
        port_s = NULL;
    }
}
예제 #2
0
void pw_ldap_parse(const char * const file)
{
    if (generic_parser(file, ldap_config_keywords) != 0) {
        illegal_config:
        die(421, LOG_ERR, MSG_CONF_ERR ": " MSG_ILLEGAL_CONFIG_FILE_LDAP
            ": %s" , file == NULL ? "-" : file);
    }
    if (ldap_scheme == NULL) {
        if ((ldap_scheme = strdup(LDAP_DEFAULT_SCHEME)) == NULL) {
            die_mem();
        }
    }
    if (ldap_host == NULL) {
        if ((ldap_host = strdup(LDAP_DEFAULT_SERVER)) == NULL) {
            die_mem();
        }
    }
    if (port_s == NULL) {
        port = LDAP_DEFAULT_PORT;
    } else {
        port = atoi(port_s);
        if (port <= 0 || port > 65535) {
            port = LDAP_DEFAULT_PORT;
        }
        free(port_s);
        port_s = NULL;
    }
    if (ldap_filter == NULL) {
        if ((ldap_filter = strdup(LDAP_DEFAULT_FILTER)) == NULL) {
            die_mem();
        }
    }
    {
        char *t;

        if (strchr(ldap_filter, '%') != NULL) {
            goto illegal_config;
        }
        if ((t = strchr(ldap_filter, '\\')) != NULL) {
            if (t[1] != 'L') {
                goto illegal_config;
            }
            *t++ = '%';
            *t = 's';
        }
    }
    if (ldap_homedirectory == NULL) {
        if ((ldap_homedirectory = strdup(LDAP_HOMEDIRECTORY)) == NULL) {
            die_mem();
        }
    }
    if (ldap_version_s != NULL) {
        ldap_version = atoi(ldap_version_s);
        free(ldap_version_s);
        ldap_version_s = NULL;
    } else {
        ldap_version = LDAP_DEFAULT_VERSION;
    }
    if (default_uid_s != NULL) {
        default_uid = (uid_t) strtoul(default_uid_s, NULL, 10);
        free(default_uid_s);
        default_uid_s = NULL;
    }
    if (default_gid_s != NULL) {
        default_gid = (gid_t) strtoul(default_gid_s, NULL, 10);
        free(default_gid_s);
        default_gid_s = NULL;
    }
    if (force_default_uid_s != NULL) {
        if (strcasecmp(force_default_uid_s, "True") == 0) {
            force_default_uid = 1;
        }
        free(force_default_uid_s);
        force_default_uid_s = NULL;
    }
    if (force_default_gid_s != NULL) {
        if (strcasecmp(force_default_gid_s, "True") == 0) {
            force_default_gid = 1;
        }
        free(force_default_gid_s);
        force_default_gid_s = NULL;
    }
    use_tls = 0;
    if (use_tls_s != NULL) {
        if (strcasecmp(use_tls_s, "True") == 0) {
            use_tls = 1;
        }
        free(use_tls_s);
        use_tls_s = NULL;
    }
    /* Build ldap URI string */
    ldap_uri = NULL;
    {
        const size_t sizeof_ldap_uri =
            strlen(ldap_scheme) +
            sizeof URI_SCHEME_SEPARATOR - 1U +
            sizeof URI_AUTHORITY_LEADER - 1U +
            strlen(ldap_host) +
            sizeof URI_PORT_LEADER - 1U +
            5U + /* string representation of port; 5 digits at most */
            1U; /* null byte */

        if ((ldap_uri = malloc(sizeof_ldap_uri)) == NULL) {
            die_mem();
        }
        snprintf(ldap_uri, sizeof_ldap_uri, "%s%s%s%s%s%d",
                 ldap_scheme, URI_SCHEME_SEPARATOR, URI_AUTHORITY_LEADER,
                 ldap_host, URI_PORT_LEADER, port);
    }

    /* Default to auth method bind, but for backward compatibility, if a binddn
     * is supplied, default to password checking. */
    if (binddn == NULL) {
        use_ldap_bind_method = 1;
    } else {
        use_ldap_bind_method = 0;
    }

    if (ldap_auth_method_s != NULL) {
        if (strcasecmp(ldap_auth_method_s, "bind") == 0) {
            use_ldap_bind_method = 1;
        } else if (strcasecmp(ldap_auth_method_s, "password") == 0) {
            use_ldap_bind_method = 0;
        } else {
            die(421, LOG_ERR, MSG_LDAP_INVALID_AUTH_METHOD);
        }
        free(ldap_auth_method_s);
        ldap_auth_method_s = NULL;
    }
    if (base == NULL) {
        die(421, LOG_ERR, MSG_LDAP_MISSING_BASE);
    }
    if (binddn == NULL) {
        pwd = NULL;
    }
}