Ejemplo n.º 1
0
static int func_http_repl_send_start(clientHttpRequest *http)
{
	assert(http);
    if (0 == http->request->flags.redirected)
        return -1;

    HttpHeader *hdr = &http->reply->header;
    HttpHeaderEntry e;
    stringInit(&e.name,"Content-Disposition");
    stringInit(&e.value,"attachment; filename=\"");

    char *filename = strrchr(http->uri, '/');
    if (NULL == filename)
        return -1;
    filename++;
    stringAppend(&e.value, filename, strlen(filename));
    stringAppend(&e.value, "\"", 1);

    e.id = HDR_CONTENT_DISPOSITION;
    httpHeaderDelById(hdr, e.id);  
    httpHeaderAddEntry(hdr, httpHeaderEntryClone(&e));
    stringClean(&e.name);
    stringClean(&e.value);
	return 0;
}
Ejemplo n.º 2
0
/**
 * Parses a quoted-string field (RFC 2616 section 2.2), complains if
 * something went wrong, returns non-zero on success.
 * start should point at the first double-quote.
 * RC TODO: This is too looose. We should honour the BNF and exclude CTL's
 */
int
httpHeaderParseQuotedString(const char *start, String * val)
{
    const char *end, *pos;
    stringClean(val);
    if (*start != '"') {
	debug(66, 2) ("failed to parse a quoted-string header field near '%s'\n", start);
	return 0;
    }
    pos = start + 1;

    while (*pos != '"') {
	int quoted = (*pos == '\\');
	if (quoted)
	    pos++;
	if (!*pos) {
	    debug(66, 2) ("failed to parse a quoted-string header field near '%s'\n", start);
	    stringClean(val);
	    return 0;
	}
	end = pos + strcspn(pos + quoted, "\"\\") + quoted;
	stringAppend(val, pos, end - pos);
	pos = end;
    }
    /* Make sure it's defined even if empty "" */
    if (!val->buf)
	stringLimitInit(val, "", 0);
    return 1;
}
Ejemplo n.º 3
0
//???????ͷŵ?callback
static int free_callback(void* param)
{
	int loop;
	struct mod_conf_param* data = (struct mod_conf_param*) param;

	if(data)
	{
		for(loop=0; loop<data->count; loop++)
		{
			if(data->acp[loop])
			{
				if(data->acp[loop]->hdr)
				{
					if(strLen(data->acp[loop]->hdr->header))
						stringClean(&data->acp[loop]->hdr->header);
					if(strLen(data->acp[loop]->hdr->value))
						stringClean(&data->acp[loop]->hdr->value);		
					memPoolFree(header_info_pool, data->acp[loop]->hdr);
					data->acp[loop]->hdr = NULL;
				}
				memPoolFree(action_part_pool, data->acp[loop]);
				data->acp[loop] = NULL;
			}
		}
		memPoolFree(mod_config_pool, data);
		data = NULL;
	}

	return 0;
}
void
requestDestroy(request_t * req)
{
    assert(req);
    if (req->body_reader)
	requestAbortBody(req);
    if (req->auth_user_request)
	authenticateAuthUserRequestUnlock(req->auth_user_request);
    safe_free(req->canonical);
    safe_free(req->vary_hdr);
    safe_free(req->vary_headers);
    stringClean(&req->vary_encoding);
    safe_free(req->urlgroup);
    safe_free(req->extacl_user);
    safe_free(req->extacl_passwd);
    stringClean(&req->urlpath);
    httpHeaderClean(&req->header);
    if (req->cache_control)
	httpHdrCcDestroy(req->cache_control);
    if (req->range)
	httpHdrRangeDestroy(req->range);
    stringClean(&req->extacl_log);
    if (req->vary) {
	if (req->etags == &req->vary->etags)
	    req->etags = NULL;
	storeLocateVaryDone(req->vary);
	req->vary = NULL;
    }
    assert(req->etags == NULL);
    safe_free(req->etag);
    if (req->pinned_connection)
	cbdataUnlock(req->pinned_connection);
    req->pinned_connection = NULL;
    memFree(req, MEM_REQUEST_T);
}
Ejemplo n.º 5
0
void
httpHdrExtFieldDestroy(HttpHdrExtField * f)
{
    assert(f);
    stringClean(&f->name);
    stringClean(&f->value);
    xfree(f);
}
Ejemplo n.º 6
0
void stringClean(char s[], int i) {
	if (s[i] == 0) {
		return;
	}
	if (s[i] == s[i+1]) {
		shiftLeft(s, i);
		stringClean(s, i);
	} else {
		stringClean(s, i+1);
	}
}
Ejemplo n.º 7
0
	// Given a string, return recursively a "cleaned" string where adjacent chars that are the same have been reduced to a single char. So "yyzzza" yields "yza".
	string stringClean( string str )
	{
		if( str.empty() || str.length() <= 1 )
			return str;

		string iter = str.substr( 1 );
		string token = str.substr( 0, 1 );

		return ( token.at( 0 ) == iter.at( 0 ) ) ?
			stringClean( iter ) : token + stringClean( iter );
	}
Ejemplo n.º 8
0
static int free_callback(void* param)
{
	struct mod_conf_param* data = (struct mod_conf_param*) param;
	if(data)
	{
		if(strLen(data->orig_name))
			stringClean(&data->orig_name);
		if(strLen(data->new_name))
			stringClean(&data->new_name);
		memPoolFree(mod_config_pool, data);
		data = NULL;
	}
	return 0;
}
Ejemplo n.º 9
0
static void
httpHeaderEntryDestroy(HttpHeaderEntry * e)
{
    assert(e);
    assert_eid(e->id);
    debug(55, 9) ("destroying entry %p: '%s: %s'\n", e, strBuf(e->name), strBuf(e->value));
    /* clean name if needed */
    if (e->id == HDR_OTHER)
	stringClean(&e->name);
    stringClean(&e->value);
    assert(Headers[e->id].stat.aliveCount);
    Headers[e->id].stat.aliveCount--;
    e->id = -1;
    memFree(e, MEM_HTTP_HDR_ENTRY);
}
Ejemplo n.º 10
0
/*
 *This line is to modify the header
 */
static int mod_modify_s2o_header(HttpStateData* data, HttpHeader* hdr)
{
	assert(data);
	int fd = data->fd;
	int i, len;

	struct mod_conf_param *param = (struct mod_conf_param *)cc_get_mod_param(fd, mod);
	assert(param);

	debug(107, 3)("param->orig_name=%s, param->new_name=%s\n", strBuf(param->orig_name), strBuf(param->new_name));
	HttpHeaderPos pos = HttpHeaderInitPos;
	HttpHeaderEntry *myheader;
	HttpHeaderEntry e;

	while ((myheader = httpHeaderGetEntry(hdr, &pos)))
	{
		debug(107, 3)("myheader=%s, param->new_name=%s\n", strBuf(myheader->name), strBuf(param->new_name));
		if (strCaseCmp(myheader->name, strBuf(param->orig_name)) == 0)
		{
			debug(107, 3)("%s is myheader->value,%s is param->orig_name\n",strBuf(myheader->value), strBuf(param->orig_name));

			if(strLen(myheader->value) >= 4095)
			{
				debug(107, 3)("A too long header value!!\n");
				return -1;
			}

			stringInit(&e.name, strBuf(param->new_name));
			stringInit(&e.value, myheader->value.buf);
			len=strlen(strBuf(e.name));
			i=httpHeaderIdByNameDef(strBuf(e.name), len);
			if(-1 == i)
				e.id = HDR_OTHER;
			else    
				e.id = i;
			httpHeaderDelByName(hdr, strBuf(param->orig_name));
			httpHeaderAddEntry(hdr, httpHeaderEntryClone(&e));
			//httpHeaderDelAt(&request->header, pos);
			//httpHeaderRefreshMask(&request->header);
			//httpHeaderInsertEntry(&request->header, httpHeaderEntryClone(&e), pos);
			stringClean(&e.name);
			stringClean(&e.value);			
			break;
		}
	}
	return 0;

}
Ejemplo n.º 11
0
int main(void) {
	char x[11];
	scanf("%s", x);
	stringClean(x, 0);
	printf("%s\n", x);
	return EXIT_SUCCESS;
}
Ejemplo n.º 12
0
void
httpHeaderDestroyFieldsInfo(HttpHeaderFieldInfo * table, int count)
{
    int i;
    for (i = 0; i < count; ++i)
	stringClean(&table[i].name);
    xfree(table);
}
Ejemplo n.º 13
0
static void httpReplyHdrCacheClean_(HttpReply * rep)
{
	stringClean(&rep->content_type);
	if (rep->cache_control)
		httpHdrCcDestroy(rep->cache_control);
	if (rep->content_range)
		httpHdrContRangeDestroy(rep->content_range);
}
Ejemplo n.º 14
0
static void
peerDigestClean(PeerDigest * pd)
{
    assert(pd);
    if (pd->cd)
	cacheDigestDestroy(pd->cd);
    stringClean(&pd->host);
}
Ejemplo n.º 15
0
static char *
makeRefreshCheckRequest(StoreEntry * entry, refresh_check_format * format)
{
    static MemBuf mb = MemBufNULL;
    int first = 1;
    HttpReply *reply;
    String sb = StringNull;

    if (!entry->mem_obj)
	return NULL;

    reply = entry->mem_obj->reply;
    memBufReset(&mb);
    for (; format; format = format->next) {
	char buf[256];
	const char *str = NULL;
	const char *quoted;
	switch (format->type) {
	case REFRESH_CHECK_URI:
	    str = entry->mem_obj->url;
	    break;
	case REFRESH_CHECK_AGE:
	    snprintf(buf, sizeof(buf), "%ld", (long int) (squid_curtime - entry->timestamp));
	    str = buf;
	    break;
	case REFRESH_CHECK_RESP_HEADER:
	    sb = httpHeaderGetByName(&reply->header, format->header);
	    str = strBuf(sb);
	    break;
	case REFRESH_CHECK_RESP_HEADER_ID:
	    sb = httpHeaderGetStrOrList(&reply->header, format->header_id);
	    str = strBuf(sb);
	    break;
	case REFRESH_CHECK_RESP_HEADER_MEMBER:
	    sb = httpHeaderGetByNameListMember(&reply->header, format->header, format->member, format->separator);
	    str = strBuf(sb);
	    break;
	case REFRESH_CHECK_RESP_HEADER_ID_MEMBER:
	    sb = httpHeaderGetListMember(&reply->header, format->header_id, format->member, format->separator);
	    str = strBuf(sb);
	    break;

	case REFRESH_CHECK_UNKNOWN:
	case REFRESH_CHECK_END:
	    fatal("unknown refresh_check_program format error");
	    break;
	}
	if (!str || !*str)
	    str = "-";
	if (!first)
	    memBufAppend(&mb, " ", 1);
	quoted = rfc1738_escape(str);
	memBufAppend(&mb, quoted, strlen(quoted));
	stringClean(&sb);
	first = 0;
    }
    return mb.buf;
}
Ejemplo n.º 16
0
/* parses and inits header entry, returns new entry on success */
static HttpHeaderEntry *
httpHeaderEntryParseCreate(const char *field_start, const char *field_end)
{
    HttpHeaderEntry *e;
    int id;
    /* note: name_start == field_start */
    const char *name_end = strchr(field_start, ':');
    const int name_len = name_end ? name_end - field_start : 0;
    const char *value_start = field_start + name_len + 1;	/* skip ':' */
    /* note: value_end == field_end */

    HeaderEntryParsedCount++;

    /* do we have a valid field name within this field? */
    if (!name_len || name_end > field_end)
	return NULL;
    if (name_len > 65536) {
	/* String has a 64K limit */
	debug(55, 1) ("WARNING: ignoring header name of %d bytes\n", name_len);
	return NULL;
    }
    /* now we know we can parse it */
    e = memAllocate(MEM_HTTP_HDR_ENTRY);
    debug(55, 9) ("creating entry %p: near '%s'\n", e, getStringPrefix(field_start, field_end));
    /* is it a "known" field? */
    id = httpHeaderIdByName(field_start, name_len, Headers, HDR_ENUM_END);
    if (id < 0)
	id = HDR_OTHER;
    assert_eid(id);
    e->id = id;
    /* set field name */
    if (id == HDR_OTHER)
	stringLimitInit(&e->name, field_start, name_len);
    else
	e->name = Headers[id].name;
    /* trim field value */
    while (value_start < field_end && xisspace(*value_start))
	value_start++;
    if (field_end - value_start > 65536) {
	/* String has a 64K limit */
	debug(55, 1) ("WARNING: ignoring '%s' header of %d bytes\n",
	    strBuf(e->name), (int) (field_end - value_start));
	if (e->id == HDR_OTHER)
	    stringClean(&e->name);
	memFree(e, MEM_HTTP_HDR_ENTRY);
	return NULL;
    }
    /* set field value */
    stringLimitInit(&e->value, value_start, field_end - value_start);
    Headers[id].stat.seenCount++;
    Headers[id].stat.aliveCount++;
    debug(55, 9) ("created entry %p: '%s: %s'\n", e, strBuf(e->name), strBuf(e->value));
    return e;
}
Ejemplo n.º 17
0
void
requestDestroy(request_t * req)
{
    assert(req);
    safe_free(req->body);
    safe_free(req->canonical);
    stringClean(&req->urlpath);
    httpHeaderClean(&req->header);
    if (req->cache_control)
	httpHdrCcDestroy(req->cache_control);
    if (req->range)
	httpHdrRangeDestroy(req->range);
    memFree(req, MEM_REQUEST_T);
}
Ejemplo n.º 18
0
HttpHdrCc *
httpHeaderGetCc(const HttpHeader * hdr)
{
    HttpHdrCc *cc;
    String s;
    if (!CBIT_TEST(hdr->mask, HDR_CACHE_CONTROL))
	return NULL;
    s = httpHeaderGetList(hdr, HDR_CACHE_CONTROL);
    cc = httpHdrCcParseCreate(&s);
    HttpHeaderStats[hdr->owner].ccParsedCount++;
    if (cc)
	httpHdrCcUpdateStats(cc, &HttpHeaderStats[hdr->owner].ccTypeDistr);
    httpHeaderNoteParsedEntry(HDR_CACHE_CONTROL, s, !cc);
    stringClean(&s);
    return cc;
}
Ejemplo n.º 19
0
void
requestDestroy(request_t * req)
{
    assert(req);
    if (req->body_connection)
	clientAbortBody(req);
    if (req->auth_user_request)
	authenticateAuthUserRequestUnlock(req->auth_user_request);
    safe_free(req->canonical);
    safe_free(req->vary_headers);
    stringClean(&req->urlpath);
    httpHeaderClean(&req->header);
    if (req->cache_control)
	httpHdrCcDestroy(req->cache_control);
    if (req->range)
	httpHdrRangeDestroy(req->range);
    memFree(req, MEM_REQUEST_T);
}
Ejemplo n.º 20
0
/*
 * return true if a given directive is found in at least one of
 * the "connection" header-fields note: if HDR_PROXY_CONNECTION is
 * present we ignore HDR_CONNECTION.
 */
int
httpHeaderHasConnDir(const HttpHeader * hdr, const char *directive)
{
    String list;
    http_hdr_type ht;
    int res;
    /* what type of header do we have? */
    if (httpHeaderHas(hdr, HDR_PROXY_CONNECTION))
	ht = HDR_PROXY_CONNECTION;
    else if (httpHeaderHas(hdr, HDR_CONNECTION))
	ht = HDR_CONNECTION;
    else
	return 0;

    list = httpHeaderGetList(hdr, ht);
    res = strListIsMember(&list, directive, ',');
    stringClean(&list);
    return res;
}
Ejemplo n.º 21
0
static inline int url_replace(clientHttpRequest* http, struct mod_conf_param* param)
{
	char tmpUrl[BUFSIZ];
	int ret = 0;
	ret = regexec(&param->reg, http->uri, REPLACE_REGEX_SUBSTR_NUMBER+1, g_pmatch, 0);
	if(0 != ret) 
	{
		debug(120, 3)("url_replace: donot match regex, uri=[%s]\n", http->uri);
		return 0;
	}       
	String url = StringNull;
	stringAppend(&url, param->replace[0], strlen(param->replace[0]));
	int i = 1;
	while(0 != (ret=(long int)param->replace[i]))
	{       
		stringAppend(&url, http->uri+g_pmatch[ret].rm_so, g_pmatch[ret].rm_eo-g_pmatch[ret].rm_so);
		debug(120,3)("rm_so=%d, rm_eo=%d\n", g_pmatch[ret].rm_so, g_pmatch[ret].rm_eo);
		i++;    
		if(param->replace[i])
		{       
			stringAppend(&url, param->replace[i], strlen(param->replace[i]));
			i++;    
		}               
		else            
		{       
			break;
		}       
	}                       
	xfree(http->uri);       
	if (param->ingoreCase)
	{
		if (changeCase(url.buf, tmpUrl))
			http->uri = xstrdup(tmpUrl);
		else
			http->uri = xstrdup(url.buf);
	}
	else
		http->uri = xstrdup(url.buf);
	stringClean(&url);
	debug(120, 3)("url_replace: uri modified, uri=[%s]\n", http->uri);
	return 1;
}
Ejemplo n.º 22
0
/*
 * returns a the value of the specified list member, if any.
 */
String
httpHeaderGetListMember(const HttpHeader * hdr, http_hdr_type id, const char *member, const char separator)
{
    String result = StringNull;
    String header;
    const char *pos = NULL;
    const char *item;
    int ilen;
    int mlen = strlen(member);

    assert(hdr);
    assert_eid(id);

    header = httpHeaderGetStrOrList(hdr, id);

    while (strListGetItem(&header, separator, &item, &ilen, &pos)) {
	if (strncmp(item, member, mlen) == 0 && item[mlen] == '=') {
	    stringAppend(&result, item + mlen + 1, ilen - mlen - 1);
	    break;
	}
    }
    stringClean(&header);
    return result;
}
Ejemplo n.º 23
0
static void
authenticateDigestDecodeAuth(auth_user_request_t * auth_user_request, const char *proxy_auth)
{
    String temp;
    const char *item;
    const char *p;
    const char *pos = NULL;
    char *username = NULL;
    digest_nonce_h *nonce;
    int ilen;
    digest_request_h *digest_request;
    digest_user_h *digest_user;
    auth_user_t *auth_user;
    dlink_node *node;

    debug(29, 9) ("authenticateDigestDecodeAuth: beginning\n");
    assert(auth_user_request != NULL);

    digest_request = authDigestRequestNew();

    /* trim DIGEST from string */
    while (xisgraph(*proxy_auth))
	proxy_auth++;

    /* Trim leading whitespace before decoding */
    while (xisspace(*proxy_auth))
	proxy_auth++;

    stringInit(&temp, proxy_auth);
    while (strListGetItem(&temp, ',', &item, &ilen, &pos)) {
	if ((p = strchr(item, '=')) && (p - item < ilen))
	    ilen = p++ - item;
	if (!strncmp(item, "username", ilen)) {
	    /* white space */
	    while (xisspace(*p))
		p++;
	    /* quote mark */
	    p++;
	    username = xstrndup(p, strchr(p, '"') + 1 - p);
	    debug(29, 9) ("authDigestDecodeAuth: Found Username '%s'\n", username);
	} else if (!strncmp(item, "realm", ilen)) {
	    /* white space */
	    while (xisspace(*p))
		p++;
	    /* quote mark */
	    p++;
	    digest_request->realm = xstrndup(p, strchr(p, '"') + 1 - p);
	    debug(29, 9) ("authDigestDecodeAuth: Found realm '%s'\n", digest_request->realm);
	} else if (!strncmp(item, "qop", ilen)) {
	    /* white space */
	    while (xisspace(*p))
		p++;
	    if (*p == '\"')
		/* quote mark */
		p++;
	    digest_request->qop = xstrndup(p, strcspn(p, "\" \t\r\n()<>@,;:\\/[]?={}") + 1);
	    debug(29, 9) ("authDigestDecodeAuth: Found qop '%s'\n", digest_request->qop);
	} else if (!strncmp(item, "algorithm", ilen)) {
	    /* white space */
	    while (xisspace(*p))
		p++;
	    if (*p == '\"')
		/* quote mark */
		p++;
	    digest_request->algorithm = xstrndup(p, strcspn(p, "\" \t\r\n()<>@,;:\\/[]?={}") + 1);
	    debug(29, 9) ("authDigestDecodeAuth: Found algorithm '%s'\n", digest_request->algorithm);
	} else if (!strncmp(item, "uri", ilen)) {
	    /* white space */
	    while (xisspace(*p))
		p++;
	    /* quote mark */
	    p++;
	    digest_request->uri = xstrndup(p, strchr(p, '"') + 1 - p);
	    debug(29, 9) ("authDigestDecodeAuth: Found uri '%s'\n", digest_request->uri);
	} else if (!strncmp(item, "nonce", ilen)) {
	    /* white space */
	    while (xisspace(*p))
		p++;
	    /* quote mark */
	    p++;
	    digest_request->nonceb64 = xstrndup(p, strchr(p, '"') + 1 - p);
	    debug(29, 9) ("authDigestDecodeAuth: Found nonce '%s'\n", digest_request->nonceb64);
	} else if (!strncmp(item, "nc", ilen)) {
	    /* white space */
	    while (xisspace(*p))
		p++;
	    xstrncpy(digest_request->nc, p, 9);
	    debug(29, 9) ("authDigestDecodeAuth: Found noncecount '%s'\n", digest_request->nc);
	} else if (!strncmp(item, "cnonce", ilen)) {
	    /* white space */
	    while (xisspace(*p))
		p++;
	    /* quote mark */
	    p++;
	    digest_request->cnonce = xstrndup(p, strchr(p, '"') + 1 - p);
	    debug(29, 9) ("authDigestDecodeAuth: Found cnonce '%s'\n", digest_request->cnonce);
	} else if (!strncmp(item, "response", ilen)) {
	    /* white space */
	    while (xisspace(*p))
		p++;
	    /* quote mark */
	    p++;
	    digest_request->response = xstrndup(p, strchr(p, '"') + 1 - p);
	    debug(29, 9) ("authDigestDecodeAuth: Found response '%s'\n", digest_request->response);
	}
    }
    stringClean(&temp);


    /* now we validate the data given to us */

    /*
     * TODO: on invalid parameters we should return 400, not 407.
     * Find some clean way of doing this. perhaps return a valid
     * struct, and set the direction to clientwards combined with
     * a change to the clientwards handling code (ie let the
     * clientwards call set the error type (but limited to known
     * correct values - 400/401/407
     */

    /* first the NONCE count */
    if (digest_request->cnonce && strlen(digest_request->nc) != 8) {
	debug(29, 4) ("authenticateDigestDecode: nonce count length invalid\n");
	authDigestLogUsername(auth_user_request, username);

	/* we don't need the scheme specific data anymore */
	authDigestRequestDelete(digest_request);
	auth_user_request->scheme_data = NULL;
	return;
    }
    /* now the nonce */
    nonce = authenticateDigestNonceFindNonce(digest_request->nonceb64);
    if (!nonce) {
	/* we couldn't find a matching nonce! */
	debug(29, 4) ("authenticateDigestDecode: Unexpected or invalid nonce recieved\n");
	authDigestLogUsername(auth_user_request, username);

	/* we don't need the scheme specific data anymore */
	authDigestRequestDelete(digest_request);
	auth_user_request->scheme_data = NULL;
	return;
    }
    digest_request->nonce = nonce;
    authDigestNonceLink(nonce);

    /* check the qop is what we expected. Note that for compatability with 
     * RFC 2069 we should support a missing qop. Tough. */
    if (!digest_request->qop || strcmp(digest_request->qop, QOP_AUTH)) {
	/* we recieved a qop option we didn't send */
	debug(29, 4) ("authenticateDigestDecode: Invalid qop option recieved\n");
	authDigestLogUsername(auth_user_request, username);

	/* we don't need the scheme specific data anymore */
	authDigestRequestDelete(digest_request);
	auth_user_request->scheme_data = NULL;
	return;
    }
    /* we can't check the URI just yet. We'll check it in the
     * authenticate phase */

    /* is the response the correct length? */

    if (!digest_request->response || strlen(digest_request->response) != 32) {
	debug(29, 4) ("authenticateDigestDecode: Response length invalid\n");
	authDigestLogUsername(auth_user_request, username);

	/* we don't need the scheme specific data anymore */
	authDigestRequestDelete(digest_request);
	auth_user_request->scheme_data = NULL;
	return;
    }
    /* do we have a username ? */
    if (!username || username[0] == '\0') {
	debug(29, 4) ("authenticateDigestDecode: Empty or not present username\n");
	authDigestLogUsername(auth_user_request, username);

	/* we don't need the scheme specific data anymore */
	authDigestRequestDelete(digest_request);
	auth_user_request->scheme_data = NULL;
	return;
    }
    /* check that we're not being hacked / the username hasn't changed */
    if (nonce->auth_user && strcmp(username, authenticateUserUsername(nonce->auth_user))) {
	debug(29, 4) ("authenticateDigestDecode: Username for the nonce does not equal the username for the request\n");
	authDigestLogUsername(auth_user_request, username);

	/* we don't need the scheme specific data anymore */
	authDigestRequestDelete(digest_request);
	auth_user_request->scheme_data = NULL;
	return;
    }
    /* if we got a qop, did we get a cnonce or did we get a cnonce wihtout a qop? */
    if ((digest_request->qop && !digest_request->cnonce)
	|| (!digest_request->qop && digest_request->cnonce)) {
	debug(29, 4) ("authenticateDigestDecode: qop without cnonce, or vice versa!\n");
	authDigestLogUsername(auth_user_request, username);

	/* we don't need the scheme specific data anymore */
	authDigestRequestDelete(digest_request);
	auth_user_request->scheme_data = NULL;
	return;
    }
    /* check the algorithm is present and supported */
    if (!digest_request->algorithm)
	digest_request->algorithm = xstrndup("MD5", 4);
    else if (strcmp(digest_request->algorithm, "MD5")
	&& strcmp(digest_request->algorithm, "MD5-sess")) {
	debug(29, 4) ("authenticateDigestDecode: invalid algorithm specified!\n");
	authDigestLogUsername(auth_user_request, username);

	/* we don't need the scheme specific data anymore */
	authDigestRequestDelete(digest_request);
	auth_user_request->scheme_data = NULL;
	return;
    }
    /* the method we'll check at the authenticate step as well */


    /* we don't send or parse opaques. Ok so we're flexable ... */

    /* find the user */

    if ((auth_user = authDigestUserFindUsername(username)) == NULL) {
	/* the user doesn't exist in the username cache yet */
	debug(29, 9) ("authDigestDecodeAuth: Creating new digest user '%s'\n", username);
	/* new auth_user */
	auth_user = authenticateAuthUserNew("digest");
	/* new scheme user data */
	digest_user = authDigestUserNew();
	/* save the username */
	digest_user->username = username;
	/* link the primary struct in */
	auth_user->scheme_data = digest_user;
	/* set the user type */
	auth_user->auth_type = AUTH_DIGEST;
	/* this auth_user struct is the one to get added to the
	 * username cache */
	/* store user in hash's */
	authenticateUserNameCacheAdd(auth_user);
	/* 
	 * Add the digest to the user so we can tell if a hacking
	 * or spoofing attack is taking place. We do this by assuming
	 * the user agent won't change user name without warning.
	 */
	authDigestUserLinkNonce(auth_user, nonce);
    } else {
	debug(29, 9) ("authDigestDecodeAuth: Found user '%s' in the user cache as '%p'\n", username, auth_user);
	digest_user = auth_user->scheme_data;
	xfree(username);
    }
    /*link the request and the user */
    auth_user_request->auth_user = auth_user;
    auth_user_request->scheme_data = digest_request;
    /* lock for the request link */
    authenticateAuthUserLock(auth_user);
    node = dlinkNodeNew();
    dlinkAdd(auth_user_request, node, &auth_user->requests);

    debug(29, 9) ("username = '******'\nrealm = '%s'\nqop = '%s'\nalgorithm = '%s'\nuri = '%s'\nnonce = '%s'\nnc = '%s'\ncnonce = '%s'\nresponse = '%s'\ndigestnonce = '%p'\n",
	digest_user->username, digest_request->realm,
	digest_request->qop, digest_request->algorithm,
	digest_request->uri, digest_request->nonceb64,
	digest_request->nc, digest_request->cnonce, digest_request->response, nonce);

    return;
}
static void func_sys_after_parse_param()
{
	int i;
	for(i = 0 ; i < mod->mod_params.count; i++)
	{
		cc_mod_param *mod_param = mod->mod_params.items[i];
		mod_config *cfg = mod_param->param;

        // add by xueye.zhao
        // 2013-4-18

        if (is_http_move_status(cfg->ResponseStatus))
        {
            continue;
        }

        // end add

        if(is_url(cfg->location))
		{

			struct stat sb;
			if (stat("/data/proclog/log/squid/customized_error_page", &sb) != 0){
				mkdir("/data/proclog/log/squid/customized_error_page", S_IRWXU);
			}
			FILE *fp = popen("/usr/local/squid/bin/get_file_from_url.pl", "r");
			assert(fp);
			while(1)
			{
				char perloutput[512];
				if(!fgets(perloutput, 512, fp))
				{
					break;
				}

				debug(115, 1)("mod_customized_server_side_error_page get_file_from_url.pl said: %s\n", perloutput);
			}
			pclose(fp);


			/*
			   if (stat("/data/proclog/log/squid/customized_error_page", &sb) != 0){
			   mkdir("/data/proclog/log/squid/customized_error_page", S_IRWXU);
			   }
			   */
			if(stringConvert((cfg->location)))
			{
				debug(115,0) ( "mod_customized_server_side_error_page: cfg->location url error\n");
				continue;
			}

			debug(115,4) ( "mod_customized_server_side_error_page: cfg->location is: %s\n", cfg->location);

			//char* tmp = NULL;
			String tmp = StringNull;
			stringInit(&tmp, "/data/proclog/log/squid/customized_error_page/");
			stringAppend(&tmp, cfg->location+7, strlen(cfg->location)-7);
			memset(cfg->location,0,sizeof(cfg->location));
			strncpy(cfg->location,strBuf(tmp),strLen(tmp));
			errorTryLoadText(&cfg->customized_error_text, cfg->location);
			stringClean(&tmp);
		}
		else
		{
			//cfg->is_url = 0;
			errorTryLoadText(&cfg->customized_error_text, cfg->location);
		}
	}
}
Ejemplo n.º 25
0
/* Borrow part of code from libwww2 came with Mosaic distribution */
static void
gopherToHTML(GopherStateData * gopherState, char *inbuf, int len)
{
    char *pos = inbuf;
    char *lpos = NULL;
    char *tline = NULL;
    LOCAL_ARRAY(char, line, TEMP_BUF_SIZE);
    LOCAL_ARRAY(char, tmpbuf, TEMP_BUF_SIZE);
    String outbuf = StringNull;
    char *name = NULL;
    char *selector = NULL;
    char *host = NULL;
    char *port = NULL;
    char *escaped_selector = NULL;
    const char *icon_url = NULL;
    char gtype;
    StoreEntry *entry = NULL;

    memset(tmpbuf, '\0', TEMP_BUF_SIZE);
    memset(line, '\0', TEMP_BUF_SIZE);

    entry = gopherState->entry;

    if (gopherState->conversion == HTML_INDEX_PAGE) {
	char *html_url = html_quote(storeUrl(entry));
	gopherHTMLHeader(entry, "Gopher Index %s", html_url);
	storeAppendPrintf(entry,
	    "<p>This is a searchable Gopher index. Use the search\n"
	    "function of your browser to enter search terms.\n"
	    "<ISINDEX>\n");
	gopherHTMLFooter(entry);
	/* now let start sending stuff to client */
	storeBufferFlush(entry);
	gopherState->HTML_header_added = 1;
	return;
    }
    if (gopherState->conversion == HTML_CSO_PAGE) {
	char *html_url = html_quote(storeUrl(entry));
	gopherHTMLHeader(entry, "CSO Search of %s", html_url);
	storeAppendPrintf(entry,
	    "<P>A CSO database usually contains a phonebook or\n"
	    "directory.  Use the search function of your browser to enter\n"
	    "search terms.</P><ISINDEX>\n");
	gopherHTMLFooter(entry);
	/* now let start sending stuff to client */
	storeBufferFlush(entry);
	gopherState->HTML_header_added = 1;
	return;
    }
    inbuf[len] = '\0';

    if (!gopherState->HTML_header_added) {
	if (gopherState->conversion == HTML_CSO_RESULT)
	    gopherHTMLHeader(entry, "CSO Search Result", NULL);
	else
	    gopherHTMLHeader(entry, "Gopher Menu", NULL);
	strCat(outbuf, "<PRE>");
	gopherState->HTML_header_added = 1;
	gopherState->HTML_pre = 1;
    }
    while ((pos != NULL) && (pos < inbuf + len)) {

	if (gopherState->len != 0) {
	    /* there is something left from last tx. */
	    xstrncpy(line, gopherState->buf, gopherState->len + 1);
	    if (gopherState->len + len > TEMP_BUF_SIZE) {
		debug(10, 1) ("GopherHTML: Buffer overflow. Lost some data on URL: %s\n",
		    storeUrl(entry));
		len = TEMP_BUF_SIZE - gopherState->len;
	    }
	    lpos = (char *) memccpy(line + gopherState->len, inbuf, '\n', len);
	    if (lpos)
		*lpos = '\0';
	    else {
		/* there is no complete line in inbuf */
		/* copy it to temp buffer */
		if (gopherState->len + len > TEMP_BUF_SIZE) {
		    debug(10, 1) ("GopherHTML: Buffer overflow. Lost some data on URL: %s\n",
			storeUrl(entry));
		    len = TEMP_BUF_SIZE - gopherState->len;
		}
		xmemcpy(gopherState->buf + gopherState->len, inbuf, len);
		gopherState->len += len;
		return;
	    }

	    /* skip one line */
	    pos = (char *) memchr(pos, '\n', len);
	    if (pos)
		pos++;

	    /* we're done with the remain from last tx. */
	    gopherState->len = 0;
	    *(gopherState->buf) = '\0';
	} else {

	    lpos = (char *) memccpy(line, pos, '\n', len - (pos - inbuf));
	    if (lpos)
		*lpos = '\0';
	    else {
		/* there is no complete line in inbuf */
		/* copy it to temp buffer */
		if ((len - (pos - inbuf)) > TEMP_BUF_SIZE) {
		    debug(10, 1) ("GopherHTML: Buffer overflow. Lost some data on URL: %s\n",
			storeUrl(entry));
		    len = TEMP_BUF_SIZE;
		}
		if (len > (pos - inbuf)) {
		    xmemcpy(gopherState->buf, pos, len - (pos - inbuf));
		    gopherState->len = len - (pos - inbuf);
		}
		break;
	    }

	    /* skip one line */
	    pos = (char *) memchr(pos, '\n', len);
	    if (pos)
		pos++;

	}

	/* at this point. We should have one line in buffer to process */

	if (*line == '.') {
	    /* skip it */
	    memset(line, '\0', TEMP_BUF_SIZE);
	    continue;
	}
	switch (gopherState->conversion) {

	case HTML_INDEX_RESULT:
	case HTML_DIR:{
		tline = line;
		gtype = *tline++;
		name = tline;
		selector = strchr(tline, TAB);
		if (selector) {
		    *selector++ = '\0';
		    host = strchr(selector, TAB);
		    if (host) {
			*host++ = '\0';
			port = strchr(host, TAB);
			if (port) {
			    char *junk;
			    port[0] = ':';
			    junk = strchr(host, TAB);
			    if (junk)
				*junk++ = 0;	/* Chop port */
			    else {
				junk = strchr(host, '\r');
				if (junk)
				    *junk++ = 0;	/* Chop port */
				else {
				    junk = strchr(host, '\n');
				    if (junk)
					*junk++ = 0;	/* Chop port */
				}
			    }
			    if ((port[1] == '0') && (!port[2]))
				port[0] = 0;	/* 0 means none */
			}
			/* escape a selector here */
			escaped_selector = xstrdup(rfc1738_escape_part(selector));

			switch (gtype) {
			case GOPHER_DIRECTORY:
			    icon_url = mimeGetIconURL("internal-menu");
			    break;
			case GOPHER_HTML:
			case GOPHER_FILE:
			    icon_url = mimeGetIconURL("internal-text");
			    break;
			case GOPHER_INDEX:
			case GOPHER_CSO:
			    icon_url = mimeGetIconURL("internal-index");
			    break;
			case GOPHER_IMAGE:
			case GOPHER_GIF:
			case GOPHER_PLUS_IMAGE:
			    icon_url = mimeGetIconURL("internal-image");
			    break;
			case GOPHER_SOUND:
			case GOPHER_PLUS_SOUND:
			    icon_url = mimeGetIconURL("internal-sound");
			    break;
			case GOPHER_PLUS_MOVIE:
			    icon_url = mimeGetIconURL("internal-movie");
			    break;
			case GOPHER_TELNET:
			case GOPHER_3270:
			    icon_url = mimeGetIconURL("internal-telnet");
			    break;
			case GOPHER_BIN:
			case GOPHER_MACBINHEX:
			case GOPHER_DOSBIN:
			case GOPHER_UUENCODED:
			    icon_url = mimeGetIconURL("internal-binary");
			    break;
			case GOPHER_INFO:
			    icon_url = NULL;
			    break;
			default:
			    icon_url = mimeGetIconURL("internal-unknown");
			    break;
			}

			memset(tmpbuf, '\0', TEMP_BUF_SIZE);
			if ((gtype == GOPHER_TELNET) || (gtype == GOPHER_3270)) {
			    if (strlen(escaped_selector) != 0)
				snprintf(tmpbuf, TEMP_BUF_SIZE, "<IMG border=\"0\" SRC=\"%s\"> <A HREF=\"telnet://%s@%s%s%s/\">%s</A>\n",
				    icon_url, escaped_selector, rfc1738_escape_part(host),
				    *port ? ":" : "", port, html_quote(name));
			    else
				snprintf(tmpbuf, TEMP_BUF_SIZE, "<IMG border=\"0\" SRC=\"%s\"> <A HREF=\"telnet://%s%s%s/\">%s</A>\n",
				    icon_url, rfc1738_escape_part(host), *port ? ":" : "",
				    port, html_quote(name));

			} else if (gtype == GOPHER_INFO) {
			    snprintf(tmpbuf, TEMP_BUF_SIZE, "\t%s\n", html_quote(name));
			} else {
			    if (strncmp(selector, "GET /", 5) == 0) {
				/* WWW link */
				snprintf(tmpbuf, TEMP_BUF_SIZE, "<IMG border=\"0\" SRC=\"%s\"> <A HREF=\"http://%s/%s\">%s</A>\n",
				    icon_url, host, rfc1738_escape_unescaped(selector + 5), html_quote(name));
			    } else {
				/* Standard link */
				snprintf(tmpbuf, TEMP_BUF_SIZE, "<IMG border=\"0\" SRC=\"%s\"> <A HREF=\"gopher://%s/%c%s\">%s</A>\n",
				    icon_url, host, gtype, escaped_selector, html_quote(name));
			    }
			}
			safe_free(escaped_selector);
			strCat(outbuf, tmpbuf);
		    } else {
			memset(line, '\0', TEMP_BUF_SIZE);
			continue;
		    }
		} else {
		    memset(line, '\0', TEMP_BUF_SIZE);
		    continue;
		}
		break;
	    }			/* HTML_DIR, HTML_INDEX_RESULT */


	case HTML_CSO_RESULT:{
		if (line[0] == '-') {
		    int code, recno;
		    char *s_code, *s_recno, *result;

		    s_code = strtok(line + 1, ":\n");
		    s_recno = strtok(NULL, ":\n");
		    result = strtok(NULL, "\n");

		    if (!result)
			break;

		    code = atoi(s_code);
		    recno = atoi(s_recno);

		    if (code != 200)
			break;

		    if (gopherState->cso_recno != recno) {
			snprintf(tmpbuf, TEMP_BUF_SIZE, "</PRE><HR noshade size=\"1px\"><H2>Record# %d<br><i>%s</i></H2>\n<PRE>", recno, html_quote(result));
			gopherState->cso_recno = recno;
		    } else {
			snprintf(tmpbuf, TEMP_BUF_SIZE, "%s\n", html_quote(result));
		    }
		    strCat(outbuf, tmpbuf);
		    break;
		} else {
		    int code;
		    char *s_code, *result;

		    s_code = strtok(line, ":");
		    result = strtok(NULL, "\n");

		    if (!result)
			break;

		    code = atoi(s_code);
		    switch (code) {

		    case 200:{
			    /* OK */
			    /* Do nothing here */
			    break;
			}

		    case 102:	/* Number of matches */
		    case 501:	/* No Match */
		    case 502:	/* Too Many Matches */
			{
			    /* Print the message the server returns */
			    snprintf(tmpbuf, TEMP_BUF_SIZE, "</PRE><HR noshade size=\"1px\"><H2>%s</H2>\n<PRE>", html_quote(result));
			    strCat(outbuf, tmpbuf);
			    break;
			}


		    }
		}

	    }			/* HTML_CSO_RESULT */
	default:
	    break;		/* do nothing */

	}			/* switch */

    }				/* while loop */

    if (strLen(outbuf) > 0) {
	storeAppend(entry, strBuf(outbuf), strLen(outbuf));
	/* now let start sending stuff to client */
	storeBufferFlush(entry);
    }
    stringClean(&outbuf);
    return;
}
Ejemplo n.º 26
0
/*if the origindomain doesn't need cookie,this part is not neccessary 
 *
static int update_cookie_direction_0(clientHttpRequest *http)
{
	assert(http);
	assert(http->request);

	const char head_name_request[20] = "Cookie";
	int len = strlen(head_name_request);
	int flag = 0;
	HttpHeaderPos pos = HttpHeaderInitPos;

	request_t* request = http->request;

	char *uri = http->uri;
	char cookie_value[100]="0";
	
	char cookie_primary_key_name[20];
	char cookie_sub_key_name[20];
	int i = 0;

	debug(139,3)("in update_cookie_direction_0 receive uri %s\n",uri);

	HttpHeaderEntry e;
	HttpHeaderEntry *myheader;

	stringInit(&e.name, head_name_request);
	i = httpHeaderIdByNameDef(head_name_request, len);
	e.id = i;
	if (-1 == i)
		e.id = HDR_OTHER; 
	while ((myheader = httpHeaderGetEntry(&request->header, &pos))) 
	{
		if (strCaseCmp(myheader->name, head_name_request) == 0)
		{
			debug(139, 3)("%s is myheader->value,%s is name\n",myheader->value.buf,myheader->name.buf);
			flag = 1;
		}
	}

	debug(139,3)("flag=%d\n",flag);
	if(!flag)
	{
		if(0 == get_param_from_uri(uri,cookie_primary_key_name,cookie_sub_key_name))
		{
			return 1;
		}
		to_upper(cookie_primary_key_name);
		snprintf(cookie_value,100,"%s:(FM%s=0)",cookie_primary_key_name,cookie_sub_key_name);
		debug(139,3)("cookie value is %s\n",cookie_value);
		debug(139,3)("cookie_primary_key_name is %s\n",cookie_primary_key_name);
		debug(139,3)("cookie_sub_key_name is %s\n",cookie_sub_key_name);
		stringInit(&e.value, cookie_value);
		httpHeaderAddEntry(&request->header, httpHeaderEntryClone(&e));
	}
	return 1;
}
*/
static int update_cookie_direction_3(clientHttpRequest *http)
{
	assert(http);
	assert(http->request);

//	const char head_name_request[20] = "Cookie";
	const char head_name_reply[20] = "Set-Cookie";
//	int len = strlen(head_name_reply);
//	int flag = 0;
//	HttpHeaderPos pos = HttpHeaderInitPos;

//	request_t* request = http->request;
	HttpReply* reply = http->reply; 

	char *uri = http->uri;
//	char cookie_value[MAX_NAME_SIZE] = "0";
//	char cookie_value_from_url[MAX_NAME_SIZE] = "0 ";
	char cookie_primary_key_name[MAX_NAME_SIZE] = "0";
	char cookie_sub_key_name[MAX_NAME_SIZE] = "0";
	char cookie_file_name[MAX_NAME_SIZE] = "0";

	debug(139,3)("in update_cookie_direction_3 receive uri %s\n",uri);

	HttpHeaderEntry e;
//	HttpHeaderEntry *myheader;

	stringInit(&e.name, head_name_reply);
//	i = httpHeaderIdByNameDef(head_name_reply, len);
//	e.id = i;
	e.id = HDR_SET_COOKIE;
//	if (-1 == i)
//		e.id = HDR_OTHER; 
	/*
	while ((myheader = httpHeaderGetEntry(&request->header, &pos))) 
	{
		if (strCaseCmp(myheader->name, head_name_request) == 0)
		{
			debug(139, 3)("%s is myheader->value,%s is name\n",myheader->value.buf,myheader->name.buf);
			flag = 1;
			strcpy(cookie_value,myheader->value.buf);
			debug(139,5)("cookie_value =%s\n",cookie_value);
			if(0 == deal_with_cookie(cookie_value))
			{
				debug(139,3)("Cookie format is wrong\n");
				return 0;
			}
			if(0 == get_param_from_uri(uri,cookie_primary_key_name,cookie_sub_key_name))
			{
				debug(139,3)("get_param_from_uri error\n");
				return 0;
			}
			to_upper(cookie_primary_key_name);
			snprintf(cookie_value_from_url,100,"%s:(FM%s=",cookie_primary_key_name,cookie_sub_key_name);
			debug(139,5)("cookie_value_from_url is %s\n",cookie_value_from_url);
			if(strncmp(cookie_value,cookie_value_from_url,strlen(cookie_value_from_url)))
			{
				debug(139,3)("get_param_from_uri cookie_value_from_url doesn't match cookie_value\n");
				return 0;
			}

		}
	}
	*/

	if(reply->sline.status >= HTTP_OK && reply->sline.status < HTTP_BAD_REQUEST )
	{
		if(0 == get_param_from_uri(uri,cookie_primary_key_name,cookie_sub_key_name,cookie_file_name))
		{
			debug(139,3)("get_param_from_uri error\n");
			stringClean(&e.name);
			return 0;
		}
		struct tm *ptr;  
		ptr = gmtime(&reply->expires);  

		debug(139,3)("expires = %s\n", asctime(ptr));

		char tmpbuf[128];
		char cookie_value[MAX_HEADER_SIZE];

		strftime( tmpbuf, 128, "%a, %d %b %G %T GMT \n", ptr); 
		debug(139,3)("expires = %s\n", tmpbuf);
		snprintf(cookie_value,MAX_HEADER_SIZE,"DTAG=CAM=%s&LOC=%s&CRT=%s; expires=%s; path=/",cookie_primary_key_name,cookie_sub_key_name,cookie_file_name,tmpbuf);
		
		debug(139,5)("cookie value is %s\n",cookie_value);
		stringInit(&e.value, cookie_value);
		httpHeaderAddEntry(&reply->header, httpHeaderEntryClone(&e));
		stringClean(&e.value);
	}
	else
	{
		;//do nothing
	}
	stringClean(&e.name);


	return 1;
}
Ejemplo n.º 27
0
// confige line example:
// mod_header [direction add|del|modify header_name [header_value]]{1,..n} allow|deny acl
// ??????ͷ??ʼ?????? allow|deny ??ֹ
// ????????????
static int func_sys_parse_param(char *cfg_line)
{
	assert(cfg_line);

	struct mod_conf_param* data = NULL;
	char* token = NULL;
	int ret = 0;
	int i;
	
	// add by xueye.zhao
	// 2013/6/19
	
# if 0
	//?ҵ?allow????deny?? Ȼ????֮???Ľ?ȥ
	//zhoudshu add for bug mantis 0002002

	char* tmptoken = NULL;
	char* tmp_line = xstrdup(cfg_line);
	if ((tmptoken = strtok(tmp_line, w_space)) == NULL)
	{	
		debug(98, 3)("(mod_header) ->  parse line error\n");
		safe_free(tmp_line);
		return -1;
	
	}

	int haskey = 0;
	while(NULL != (tmptoken = strtok(NULL, w_space)))
	{
		if(strcmp("allow",tmptoken) == 0 || strcmp("deny",tmptoken) == 0){
			haskey = 1;
		}
	}

	safe_free(tmp_line);
	
	if(haskey != 1){
		debug(98, 3)("(mod_header) ->  has not key of allow or deny in config line \n");
		return -1;
	}	

#endif
	

	if (NULL == strstr(cfg_line, " allow "))
	{
		debug(98, 3)("(mod_header) ->  has not key of allow or deny in config line \n");
		return -1;
	}
	
	//end add

	//开始截取	
	if ((token = strtok(cfg_line, w_space)) != NULL)
	{
		if(strcmp(token, "mod_header"))
			goto errA;	
	}
	else
	{
		debug(98, 3)("(mod_header) ->  parse line error\n");
		goto errA;	
	}

	data = mod_config_pool_alloc();
	data->count = 0;
	//?????↑ʼѭ??ȡ??????..???Dz???+header+value?ķ?ʽ, ????,ѭ????????
	while(NULL != (token = strtok(NULL, w_space)))
	{
		if(strcmp("allow",token) == 0 || strcmp("deny",token) == 0 || strcmp("reply_check",token) == 0) {
			break;
		}	

		struct action_part* part;
		struct header_info* info;
		part = action_part_pool_alloc();
		info = header_info_pool_alloc();
		data->acp[data->count] = part;
		data->acp[data->count]->hdr = info;
		data->count++;
		
		part->direct = atoi(token); //fetch the direction

		if(part->direct > 3 || part->direct < 0)
		{
			debug(98, 3)("(mod_header) ->  parse direction error, cant be %d\n", part->direct);
			goto err;
		}

		//???↑ʼ?ǽ???????????
		if (NULL == (token = strtok(NULL, w_space)))
		{
			debug(98, 3)("(mod_header) ->  parse line data does not existed\n");
			goto err;
		}
		ret = parse_operation(part, token);//??????????, ???????????ṹ
		if(-1 == ret)
		{
			debug(98, 3)("(mod_header) ->  parse line operation error, cant be %s\n", token);
			goto err;
		}

		//?????и?header, ?????϶??е?
		if (NULL == (token = strtok(NULL, w_space)))
		{
			debug(98, 3)("(mod_header) ->  parse line data does not existed\n");
			goto err;
		}
		stringInit(&info->header, token);	

		//?и???header, value?Ͳ?һ??????. ????Ҫ??????��?ж???. ??????Ҫ?и?value, ?͸???
		if (1 != part->action)
		{
			if (NULL == (token = strtok(NULL, w_space))) {
				debug(98, 3)("(mod_header) ->  parse line data does not existed\n");
				goto err;
			}

			//??Ȼ??value, ?ͱ???????. ?? header һ???????ŵ?????.
			stringInit(&info->value, token);	

			/* case http://sis.ssr.chinacache.com/rms/view.php?id=4124 */
			if (*token == '\"') {
				stringClean(&info->value);
				stringInit(&info->value, token+1);	
				int len = 0;
				while (NULL !=(token = strtok(NULL,w_space))){
					len = strlen(token);
					if (token[len-1] == '\"'){
						stringAppend(&info->value, " ", 1);
						stringAppend(&info->value, token, len-1);
						break;
					}
					else if (strcmp("allow",token) == 0 || strcmp("deny",token) == 0) 
						goto err;
					else {
						stringAppend(&info->value, " ", 1);
						stringAppend(&info->value, token, len);
					}
				}
			}
		}
	}
	//һ??û???κ????ݣ? ֱ?ӱ???
	if(data->count == 0)
		goto err;
	else
		cc_register_mod_param(mod, data, free_callback);
	return 0;

err:
	debug(98,1)("mod_header: parse error\n");
	for(i=0; i<data->count; i++)
	{
		if(data->acp[i]->hdr)
		{
			if(strLen(data->acp[i]->hdr->header))
				stringClean(&data->acp[i]->hdr->header);
			if(strLen(data->acp[i]->hdr->value))
				stringClean(&data->acp[i]->hdr->value);
			memPoolFree(header_info_pool, data->acp[i]->hdr);
			data->acp[i]->hdr = NULL;
		}
		if(data->acp[i])
		{
			memPoolFree(action_part_pool, data->acp[i]);
			data->acp[i] = NULL;
		}
	}
errA:
	if (data)
	{
		memPoolFree(mod_config_pool, data);
		data = NULL;
	}
	return -1;
}
Ejemplo n.º 28
0
static char *
makeExternalAclKey(aclCheck_t * ch, external_acl_data * acl_data)
{
    static MemBuf mb = MemBufNULL;
    char buf[256];
    int first = 1;
    wordlist *arg;
    external_acl_format *format;
    request_t *request = ch->request;
    String sb = StringNull;
    memBufReset(&mb);
    for (format = acl_data->def->format; format; format = format->next) {
	const char *str = NULL;
	switch (format->type) {
	case EXT_ACL_LOGIN:
	    str = authenticateUserRequestUsername(request->auth_user_request);
	    break;
#if USE_IDENT
	case EXT_ACL_IDENT:
	    str = ch->rfc931;
	    if (!str || !*str) {
		ch->state[ACL_IDENT] = ACL_LOOKUP_NEEDED;
		return NULL;
	    }
	    break;
#endif
	case EXT_ACL_SRC:
	    str = inet_ntoa(ch->src_addr);
	    break;
	case EXT_ACL_DST:
	    str = request->host;
	    break;
	case EXT_ACL_PROTO:
	    str = ProtocolStr[request->protocol];
	    break;
	case EXT_ACL_PORT:
	    snprintf(buf, sizeof(buf), "%d", request->port);
	    str = buf;
	    break;
	case EXT_ACL_METHOD:
	    str = RequestMethodStr[request->method];
	    break;
	case EXT_ACL_HEADER:
	    sb = httpHeaderGetByName(&request->header, format->header);
	    str = strBuf(sb);
	    break;
	case EXT_ACL_HEADER_ID:
	    sb = httpHeaderGetStrOrList(&request->header, format->header_id);
	    str = strBuf(sb);
	    break;
	case EXT_ACL_HEADER_MEMBER:
	    sb = httpHeaderGetByNameListMember(&request->header, format->header, format->member, format->separator);
	    str = strBuf(sb);
	    break;
	case EXT_ACL_HEADER_ID_MEMBER:
	    sb = httpHeaderGetListMember(&request->header, format->header_id, format->member, format->separator);
	    str = strBuf(sb);
	    break;
	}
	if (str)
	    if (!*str)
		str = NULL;
	if (!str)
	    str = "-";
	if (!first)
	    memBufAppend(&mb, " ", 1);
	strwordquote(&mb, str);
	stringClean(&sb);
	first = 0;
    }
    for (arg = acl_data->arguments; arg; arg = arg->next) {
	if (!first)
	    memBufAppend(&mb, " ", 1);
	strwordquote(&mb, arg->key);
	first = 0;
    }
    return mb.buf;
}
Ejemplo n.º 29
0
/*
 *?????Ǵ????޸ġ?????һ??header?Ĵ??�??
 */
static int modifyHeader3(struct action_part* acp, HttpReply* reply)
{
	assert(acp);
	assert(reply);

	int flag = 0;
	int act = acp->action;
	struct header_info* hdr = acp->hdr;
	HttpHeaderEntry e;
	//HttpHeaderEntry *mye;
	int i;
	HttpHeaderEntry *myheader;
	HttpHeaderPos pos = HttpHeaderInitPos + HDR_ENUM_END;
	e.name = stringDup(&hdr->header);
	e.value = stringDup(&hdr->value);
	i = httpHeaderIdByNameDef(strBuf(hdr->header), strLen(hdr->header));
	e.id = i;
	if(i == -1)
	{
		e.id = HDR_OTHER;
		if(0 == act)
		{
			httpHeaderAddEntry(&reply->header, httpHeaderEntryClone(&e));
		}
		else if(2 == act)
		{
			while ((myheader = httpHeaderGetEntryPlus(&reply->header, &pos))) 
			{
				if (myheader->id == HDR_OTHER && strCaseCmp(myheader->name, strBuf(hdr->header)) == 0)
				{
					debug(98, 3)("%s is myheader->value,%s is hdr->value\n",strBuf(myheader->value), strBuf(hdr->value));
					stringReset(&myheader->value, strBuf(hdr->value));

				}
			}
		}
		else if(1 == act)
		{
			httpHeaderDelByName(&reply->header,strBuf(hdr->header));
		}
		else if(3 == act)
		{
			while ((myheader = httpHeaderGetEntryPlus(&reply->header, &pos))) 
			{
				if (myheader->id == HDR_OTHER && strCaseCmp(myheader->name, strBuf(hdr->header)) == 0)
				{
					debug(98, 3)("%s is myheader->value,%s is hdr->value\n",strBuf(myheader->value), strBuf(hdr->value));
					flag = 1;
					stringReset(&myheader->value, strBuf(hdr->value));

				}
			}
			
			if(!flag)
				httpHeaderAddEntry(&reply->header, httpHeaderEntryClone(&e));
		}
	}
	else
	{
		//mye = httpHeaderFindEntry2(&reply->header, i);
		//debug(98, 3) ("%d is i\n", i);

		if(0 == act)
		{
			httpHeaderAddEntry(&reply->header, httpHeaderEntryClone(&e));
		}
		else if(2 == act)
		{
			if(httpHeaderDelByName(&reply->header,strBuf(hdr->header)))
			{
				httpHeaderAddEntry(&reply->header, httpHeaderEntryClone(&e));
			}
			//mye = httpHeaderFindEntry2(&reply->header, i);
			//debug(98, 3)("%s is newvalue\n",strBuf(mye->value));
		}
		else if(1 == act)
		{
			httpHeaderDelByName(&reply->header,strBuf(hdr->header));
		}
		else if(3 == act)
		{
			httpHeaderDelByName(&reply->header,strBuf(hdr->header));
			httpHeaderAddEntry(&reply->header, httpHeaderEntryClone(&e));
		}
	}
	stringClean(&e.name);
	stringClean(&e.value);

	return 0;
}
Ejemplo n.º 30
0
// confige line example:
// mod_modify_s2o_header_name orig_header_name new_header_name allow/deny acl
// dont support func : on
static int func_sys_parse_param(char *cfg_line)
{
	struct mod_conf_param *data = mod_config_pool_alloc();
	char* token = NULL;
//mod_modify_s2o_header_name
	if ((token = strtok(cfg_line, w_space)) != NULL)
	{
		if(strcmp(token, "mod_modify_s2o_header_name"))
			goto err;	
	}
	else
	{
		debug(107, 1)("(mod_modify_s2o_header_name) ->  parse line error\n");
		goto err;	
	}
//orig_name
	if ((token = strtok(NULL, w_space)) != NULL)
	{
		stringInit(&data->orig_name, token);
	}
	else
	{
		debug(107, 1)("(mod_modify_s2o_header_name) ->  parse line error\n");
		goto err;	
	}
//new_name
	if ((token = strtok(NULL, w_space)) != NULL)
	{
		stringInit(&data->new_name, token);
	}
	else
	{
		debug(107, 1)("(mod_modify_s2o_header_name) ->  parse line error\n");
		goto err;	
	}
//allow or deny
	if ((token = strtok(NULL, w_space)) != NULL)
	{
		if(!(!strcmp(token, "allow")||!strcmp(token, "deny")||!strcmp(token, "on")||!strcmp(token, "off")))
			goto err;
	}
	else
	{
		debug(107, 1)("(mod_modify_s2o_header_name) ->  parse line error\n");
		goto err;	
	}


	cc_register_mod_param(mod, data, free_callback);

	return 0;		
err:
	if(data)
	{
		if(strLen(data->orig_name))
			stringClean(&data->orig_name);
		if(strLen(data->new_name))
			stringClean(&data->new_name);
		memPoolFree(mod_config_pool, data);
		data = NULL;
	}
	return -1;
}