Beispiel #1
0
static gboolean
parse_mailbox (const gchar *argument, gint index, gint *parsed_position,
               GError **error)
{
    gint i = 0;
    gint local_part_parsed_position, domain_parsed_position;

    if (!parse_local_part(argument, index, &local_part_parsed_position, error))
        return FALSE;
    i += local_part_parsed_position;

    if (argument[index + i] != '@')
        RETURN_ERROR_WITH_POSITION("'@' is missing in mailbox",
                                   argument, index + i);
    i++;

    if (!argument[index + i] || !argument[index + i + 1])
        RETURN_ERROR_WITH_POSITION("domain is missing in mailbox",
                                   argument, index + i);

    if (!parse_domain(argument, index + i, &domain_parsed_position, error))
        return FALSE;
    i += domain_parsed_position;

    *parsed_position = i;
    return TRUE;
}
Beispiel #2
0
/**************************************************************************
 *          CoInternetParseUrl    (URLMON.@)
 */
HRESULT WINAPI CoInternetParseUrl(LPCWSTR pwzUrl, PARSEACTION ParseAction, DWORD dwFlags,
        LPWSTR pszResult, DWORD cchResult, DWORD *pcchResult, DWORD dwReserved)
{
    if(dwReserved)
        WARN("dwReserved = %d\n", dwReserved);

    switch(ParseAction) {
    case PARSE_CANONICALIZE:
        return parse_canonicalize_url(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
    case PARSE_SECURITY_URL:
        return parse_security_url(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
    case PARSE_ENCODE:
        return parse_encode(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
    case PARSE_PATH_FROM_URL:
        return parse_path_from_url(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
    case PARSE_SCHEMA:
        return parse_schema(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
    case PARSE_SECURITY_DOMAIN:
        return parse_security_domain(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
    case PARSE_DOMAIN:
        return parse_domain(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
    case PARSE_ROOTDOCUMENT:
        return parse_rootdocument(pwzUrl, dwFlags, pszResult, cchResult, pcchResult);
    default:
        FIXME("not supported action %d\n", ParseAction);
    }

    return E_NOTIMPL;
}
Beispiel #3
0
static gboolean
parse_source_route (const gchar *argument, gint index, gint *parsed_position,
                    GError **error)
{
    gint i, domain_parsed_position;
    const gchar *source_route;

    source_route = argument + index;
    i = -1;
    do {
        i++;

        if (source_route[i] != '@')
            break;
        i++;

        if (!parse_domain(argument, index + i, &domain_parsed_position, error))
            return FALSE;
        i += domain_parsed_position;
    } while (source_route[i] == ',');

    *parsed_position = i;
    return TRUE;
}
Beispiel #4
0
int
main(int argc, char **argv)
{
    char              line[MAX_LENGTH];
    int               i, len;
    char             *p, *last;
    tldnode          *tree;
    string_t         *domain;
    http_result_t     result;
    public_suffix_t  *ps;

    tree = init_tld_tree(tld_string);
    if (tree == NULL) {
        fprintf(stderr, "can't init the TLD tree.\n");
        return -1;
    }

    /*print_tld_tree(tree, " ");*/

    if (argc > 1) {
        test_domain_case(tree);
        goto end;
    }
    
    domain = &result.domain;

    printf("Input the domain line by line from STDIN\n");

    while (fgets(line, MAX_LENGTH, stdin) != NULL) {

        memset(&result, 0, sizeof(http_result_t));

        len = strlen(line);
        if (len == 0) {
            break;
        }

        i = len;
        p = line;
        while (i) {
            /* lower the domain letter */
            *p = tolower(*p);

            p++;
            i--;
        }

        /* chmop the useless charset in the end */
        last = line + len - 1;
        while (len) {

            if (*last == '\r' || *last == '\n') {
                last--;
                len--;
                continue;
            }

            break;
        }

        if (len <= 0) {
            continue;
        }

        domain->data = line;
        domain->len = len;

        if (parse_domain(tree, &result, domain) != 0) {
            fprintf(stderr, "can't parse the domain: \"%.*s\"\n",
                    (int)domain->len, domain->data);
            continue;
        }

        ps = &result.complex_domain;

        printf("tld:\"%.*s\", ", (int)ps->tld.len, ps->tld.data);
        printf("sld:\"%.*s\", ", (int)ps->sld.len, ps->sld.data);
        printf("trd:\"%.*s\", ", (int)ps->trd.len, ps->trd.data);
        printf("domain:\"%.*s\", ", (int)ps->domain.len, ps->domain.data);
        printf("subdomain:\"%.*s\"\n", (int)ps->subdomain.len, ps->subdomain.data);
    }
    
end:

    free_tld_tree(tree);

    return 0;
}
Beispiel #5
0
static int
test_domain_case(tldnode *tree)
{
    char              line[MAX_LENGTH];
    int               i, len, count;
    char             *p, *last;
    test_t           *test;
    string_t         *domain;
    http_result_t     result;
    public_suffix_t  *ps;

    domain = &result.domain;
    test = tests;
    count = 0;

    while (test->full_domain) {

        strncpy(line, test->full_domain, MAX_LENGTH);
        memset(&result, 0, sizeof(http_result_t));

        len = strlen(line);
        if (len == 0) {
            break;
        }

        i = len;
        p = line;
        while (i) {
            /* lower the domain letter */
            *p = tolower(*p);

            p++;
            i--;
        }

        /* chmop the useless charset in the end */
        last = line + len - 1;
        while (len) {

            if (*last == '\r' || *last == '\n') {
                last--;
                len--;
                continue;
            }

            break;
        }

        if (len <= 0) {
            goto next;
        }

        domain->data = line;
        domain->len = len;

        if (parse_domain(tree, &result, domain) != 0) {

            if (test->domain != NULL) {
                goto fail;
            }

            goto next;
        }

        ps = &result.complex_domain;

        if (ps->domain.len == 0 && test->domain == NULL) {
            goto next;
        }

        if (test->domain == NULL) {
            goto fail;
        }

        if (strncmp(ps->domain.data, test->domain, ps->domain.len)) {
            goto fail;
        }

next:
        count++;
        test++;
        continue;
fail:
        printf("wanted:\"%s\"\n", test->domain);
        printf("got:\"%.*s\"\n", (int)ps->domain.len, ps->domain.data);

        return -1;
    }

    printf("test successfully with %d cases.\n", count);

    return 0;
}
static void
parse_line(GSList    **cookies_p,
           const char *line,
           const char *end,
           const char *domain_filter,
           int         port_filter,
           const char *name_filter,
           HippoBrowserKind browser)
{
    const char *p;
    const char *start;
    int field;
    Field fields[N_FIELDS];
    
    // see if it's an empty or comment line
    if (is_empty_line(line, end))
        return;
        
    for (field = 0; field < N_FIELDS; ++field) {
        fields[field].which = field;
        fields[field].text = NULL;
    }
    
    start = line;
    field = 0;
    for (p = line; p <= end; ++p) {
        g_assert(p >= start);
        if (*p == '\t' || p == end) {
            
            if (field >= N_FIELDS) {
                // too many fields on this line, give up
                goto out;
            }
            
            fields[field].text = g_strndup(start, p - start);
            
            start = p + 1;
            ++field;
        }
    }
    
    /* ATTR_VALUE is optional, the other fields are not */
    for (field = 0; field < N_FIELDS; ++field) {
        if (field != ATTR_VALUE && fields[field].text == NULL)
            goto out;
    }    
    
    {
        char *domain;
        int port;
        gboolean all_hosts_match;
        gboolean secure_connection_required;
        GTime timestamp;

        if (!parse_bool(fields[DOMAIN_FLAG].text, &all_hosts_match))
            goto out;
            
        if (!parse_bool(fields[SECURE_FLAG].text, &secure_connection_required))
            goto out;
            
        if (!parse_time(fields[TIMESTAMP].text, &timestamp))
            goto out;

        if (!parse_domain(fields[DOMAIN].text, &domain, &port))
            goto out;
        
        if ((domain_filter == NULL || strcmp(domain_filter, domain) == 0) &&
            (port_filter < 0 || port_filter == port) &&
            (name_filter == NULL || strcmp(name_filter, fields[ATTR_NAME].text) == 0)) {
            HippoCookie *cookie;
            cookie = hippo_cookie_new(browser,
                                      domain, port, all_hosts_match,
                                      fields[PATH].text,
                                      secure_connection_required, timestamp,
                                      fields[ATTR_NAME].text,
                                      fields[ATTR_VALUE].text);
            *cookies_p = g_slist_prepend(*cookies_p, cookie);
        }
                                  
        g_free(domain);
    }
                        
  out:
    for (field = 0; field < N_FIELDS; ++field) {
        g_free(fields[field].text);
    }    
}
Beispiel #7
0
/* Examine a digest challenge: return 0 if it is a valid Digest challenge,
 * else non-zero. */
static int digest_challenge(http_auth_session *sess,
			    struct http_auth_chall *parms) 
{
    struct md5_ctx tmp;
    unsigned char tmp_md5[16];
    char *password;

    /* Do we understand this challenge? */
    if (parms->alg == http_auth_alg_unknown) {
	DEBUG(DEBUG_HTTPAUTH, "Unknown algorithm.\n");
	return -1;
    }
    if ((parms->alg == http_auth_alg_md5_sess) &&
	!(parms->qop_auth || parms->qop_auth_int)) {
	DEBUG(DEBUG_HTTPAUTH, "Server did not give qop with MD5-session alg.\n");
	return -1;
    }
    if ((parms->realm==NULL) || (parms->nonce==NULL)) {
	DEBUG(DEBUG_HTTPAUTH, "Challenge missing nonce or realm.\n");
	return -1;
    }

    if (parms->stale) {
	/* Just a stale response, don't need to get a new username/password */
	DEBUG(DEBUG_HTTPAUTH, "Stale digest challenge.\n");
    } else {
	/* Forget the old session details */
	DEBUG(DEBUG_HTTPAUTH, "In digest challenge.\n");

	clean_session(sess);
	sess->unq_realm = shave_string(parms->realm, '"');

	/* Not a stale response: really need user authentication */
	if (get_credentials(sess, &password)) {
	    /* Failed to get credentials */
	    HTTP_FREE(sess->unq_realm);
	    return -1;
	}
    }
    sess->alg = parms->alg;
    sess->scheme = http_auth_scheme_digest;
    sess->unq_nonce = shave_string(parms->nonce, '"');
    sess->unq_cnonce = get_cnonce();
    if (parms->domain) {
	if (parse_domain(sess, parms->domain)) {
	    /* TODO: Handle the error? */
	}
    } else {
	sess->domain = NULL;
	sess->domain_count = 0;
    }
    if (parms->opaque != NULL) {
	sess->opaque = ne_strdup(parms->opaque); /* don't strip the quotes */
    }
    
    if (parms->got_qop) {
	/* What type of qop are we to apply to the message? */
	DEBUG(DEBUG_HTTPAUTH, "Got qop directive.\n");
	sess->nonce_count = 0;
	if (parms->qop_auth_int) {
	    sess->qop = http_auth_qop_auth_int;
	} else {
	    sess->qop = http_auth_qop_auth;
	}
    } else {
	/* No qop at all/ */
	sess->qop = http_auth_qop_none;
    }
    
    if (!parms->stale) {
	/* Calculate H(A1).
	 * tmp = H(unq(username-value) ":" unq(realm-value) ":" passwd)
	 */
	DEBUG(DEBUG_HTTPAUTH, "Calculating H(A1).\n");
	md5_init_ctx(&tmp);
	md5_process_bytes(sess->username, strlen(sess->username), &tmp);
	md5_process_bytes(":", 1, &tmp);
	md5_process_bytes(sess->unq_realm, strlen(sess->unq_realm), &tmp);
	md5_process_bytes(":", 1, &tmp);
	if (password != NULL)
	    md5_process_bytes(password, strlen(password), &tmp);
	md5_finish_ctx(&tmp, tmp_md5);
	if (sess->alg == http_auth_alg_md5_sess) {
	    unsigned char a1_md5[16];
	    struct md5_ctx a1;
	    char tmp_md5_ascii[33];
	    /* Now we calculate the SESSION H(A1)
	     *    A1 = H(...above...) ":" unq(nonce-value) ":" unq(cnonce-value) 
	     */
	    md5_to_ascii(tmp_md5, tmp_md5_ascii);
	    md5_init_ctx(&a1);
	    md5_process_bytes(tmp_md5_ascii, 32, &a1);
	    md5_process_bytes(":", 1, &a1);
	    md5_process_bytes(sess->unq_nonce, strlen(sess->unq_nonce), &a1);
	    md5_process_bytes(":", 1, &a1);
	    md5_process_bytes(sess->unq_cnonce, strlen(sess->unq_cnonce), &a1);
	    md5_finish_ctx(&a1, a1_md5);
	    md5_to_ascii(a1_md5, sess->h_a1);
	    DEBUG(DEBUG_HTTPAUTH, "Session H(A1) is [%s]\n", sess->h_a1);
	} else {
	    md5_to_ascii(tmp_md5, sess->h_a1);
	    DEBUG(DEBUG_HTTPAUTH, "H(A1) is [%s]\n", sess->h_a1);
	}
	
	HTTP_FREE(password);
    }
    
    DEBUG(DEBUG_HTTPAUTH, "I like this Digest challenge.\n");

    return 0;
}