Exemplo n.º 1
0
// given servlink2=nfs://192.168.88.13:/space&smb.user=nmt&smb.passwd=;1234;
// or  netfs_link2=nfs://[user=pwdbase64]192.168.88.13:/space
// extract nfs://192.168.88.13:/space
//
char *get_pingable_link(char *servlink) {

    char *result=NULL;
    char *link=NULL;

    HTML_LOG(1,"get pingable link for [%s]",servlink);

    link=remove_credentials(servlink);
    HTML_LOG(0,"remove creds [%s] = [%s]",servlink,link);

    if (ping_link(link) ) {
        result = link;
    } else if (util_starts_with(link,"smb:") && util_strreg(link,"//[0-9]+\\.",0) == NULL) {
        char  *iplink = wins_resolve(link);
        FREE(link);
        link = iplink;

        if (link != NULL) {
            if (ping_link(link) ) {
                result = link;
            }
        }
    }
    if (result != link ) {
        FREE(link);
    }
    HTML_LOG(0,"pingable link = [%s]",result);
    return result;
}
Exemplo n.º 2
0
bool t_auth::authorize(t_user *user_config, t_request *r, t_response *resp) {
    string username;
    string passwd;
    list<t_cr_cache_entry>::iterator i;
    t_challenge c;
    bool proxy;

    assert(resp->must_authenticate());

    if (resp->code == R_401_UNAUTHORIZED) {
        c = resp->hdr_www_authenticate.challenge;
        proxy = false;
    } else {
        c = resp->hdr_proxy_authenticate.challenge;
        proxy = true;
    }

    // Only DIGEST is supported
    if (c.auth_scheme != AUTH_DIGEST) {
        log_file->write_header("t_auth::authorize");
        log_file->write_raw("Unsupported authentication scheme: ");
        log_file->write_raw(c.auth_scheme);
        log_file->write_endl();
        log_file->write_footer();
        return false;
    }

    const t_digest_challenge &dc = c.digest_challenge;
    i = find_cache_entry(r->uri, dc.realm, proxy);

    if (auth_failed(r, c, proxy)) {
        // The current credentials are wrong. Remove them and
        // ask the user for a username and password.
        remove_credentials(r, c, proxy);
    } else {
        // Determine user name and password
        if (i != cache.end()) {
            username = i->credentials.digest_response.username;
            passwd = i->passwd;
        } else if (dc.realm == user_config->get_auth_realm() ||
                   user_config->get_auth_realm() == "") {
            username = user_config->get_auth_name();
            passwd = user_config->get_auth_pass();
        }

        if (dc.stale) {
            // The current credentials are stale. Remove them.
            remove_credentials(r, c, proxy);
        }
    }

    // Ask user for username/password
    if ((username == "" || passwd == "") && !re_register) {
        if (!ui->cb_ask_credentials(user_config, dc.realm, username, passwd)) {
            log_file->write_report("Asking user name and password failed.",
                                   "t_auth::authorize");
            return false;
        }
    }

    // No valid username/passwd
    if (username == "" && passwd == "") {
        log_file->write_report("Incorrect user name and/or password.",
                               "t_auth::authorize");
        return false;
    }

    bool auth_success;
    string fail_reason;
    if (!proxy) {
        t_credentials cr;
        auth_success = r->www_authorize(c, user_config,
                                        username, passwd, 1, NEW_CNONCE, cr, fail_reason);

        if (auth_success) {
            update_cache(r->uri, cr, passwd, proxy);
        }
    } else {
        t_credentials cr;
        auth_success = r->proxy_authorize(c, user_config,
                                          username, passwd, 1, NEW_CNONCE, cr, fail_reason);

        if (auth_success) {
            update_cache(r->uri, cr, passwd, proxy);
        }
    }

    if (!auth_success) {
        log_file->write_report(fail_reason, "t_auth::authorize");
        return false;
    }

    return true;
}