Amos Jeffries [Fri, 30 Nov 2012 11:08:47 +0000 (00:08 +1300)]
Add kv-pir support to url_rewrite_helper interface
This stage of the helper reply protocol adds kv-pair support to the
url_rewrite_helper interfacefor URL redirect and rewrite operations.
It uses the new Notes objects and kv-pair field added by the stage 2
helper protocol instead of parsing the 'other' field. Although,
the 'other' field is still parsed when *no* result field is received
for backward compatibility with older helpers.
The response syntax for URL helpers becomes:
[channel-ID SP] result [SP kv-pair ...] [SP other] EOL
NP: 'other' field is now deprecated and will be ignored/discarded on any
response containing a result code field.
When result code "OK" is presented by the helper several kv-pairs are
reserved to control Squid actions:
* "rewrite-url=" is added to return a re-written URL.
- When this key is presented the URL is re-written to the new one by
Squid without client interaction.
- The 'url' keys presence will override this key.
* "url=" is added to return the redirected-to URL.
- When this key name is presented an HTTP redirect response is generated
for the client.
- This keys presence overrides the 'rewrite-url' key actions.
* "status=" is added to hold the HTTP status code for use in redirect
operations.
- This field is optional and status is no longer required for marking
redirect actions.
- If no redirect status is provided Squid will assign one (currently the
default is 302, that may change in the future).
- This key is only relevant when 'url' key is also presented. In all
other uses it is currently ignored.
When result codes BH or ERR are presented by the helper no redirect or
rewrite action is performed and no kv-pair key names are reserved for use
at this time.
Any other keys MAY be sent on any response. The URL helper interface
makes no other use of them, but this patch does pass them on to the ALE
object for logging as transaction Notes. All kv-pairs returned by the
helper (including the url, stauts rewrite-url keys) are available for
logging via the %{...}note log format option.
As with changes to other helpers interfaces in earlier updates, only
the first value presented for any of the reserved kv-pairs is used.
Multiple values are accepted as notes, but otherwise ignored by Squid and
do not affect the transaction outcome.
Additionally, when the BH result code is received from the helper a
simple recovery is attempted. The lookup request will be re-scheduled (up
to once) in an attempt to find a better responding helper.
NOTE: Helper notes are *not* passe to adaptation interfaces.
- REQMOD adaptation happens before URL helpers are used.
- REPMOD adaptation may at some point receive them, but that change is
not done by this update.
Amos Jeffries [Tue, 27 Nov 2012 22:02:02 +0000 (11:02 +1300)]
Helper protocol upgrade: add optional kv-pair field to responses
This adds an optional kv-pair field immediately following the result field
on all helper interface responses. This field contains a list of key=value
pairs where the value is a RFC1738 (URL) encoded token or a quoted string.
Quoted-string MAY contain whitespace and shell escaping.
The response syntax for all helpers becomes:
[channel-ID SP] result [SP key-pair ...] [SP other] EOL
The parser for HelperReply is also updated to map the old AF and NA
NTLM/Negotiate response fields into the HelperReply notes:
* "token=" is added to supply the NTLM and Negotiate server blob/token.
* "user=" is added to supply the user label field.
The relevant callback handlers are updated for these helpers to make use
of these new keys.
The bundled Digest authentication helpers are all upgraded to send the new
format responses. They now use ERR for failed lookup, BH for internal
errors, and OK with "ha1=" key added to supply a HA1 response. The handler
for Digest authentication is updated to process the new HelperReply fields
with failover the old format on Unknown result codes.
The external ACL handler is updated to pull its key=value pairs out of the
Notes list. The old parser loop becomes useless with this and is removed.
Taking with it support for several long deprecated keys "login=", "passwd=",
and "error=" which are now ignored.
Any other keys MAY be sent on any response. However at this stage 2 patch
they are ignored. As are repeated / secondary values for the expected key
names, only the first instance sent in the response is used.
Amos Jeffries [Tue, 27 Nov 2012 21:19:46 +0000 (10:19 +1300)]
Audit Review updates
* guarantee that note values output by the HelperReply parser are ""
nil-terminated string and not undefined String.
* rename HelperReply::responseKeys to 'notes'
* rename Notes::findByName() to find()
* add Note::firstValue() to locate first value provided for a given key
and present it as a char* terminated string
* various documentation updates
Amos Jeffries [Tue, 27 Nov 2012 10:57:12 +0000 (23:57 +1300)]
Treat no-cache and must-revalidate in Authentication
Wrapped as a violation because this operation is off-spec.
CC:no-cache was omitted from the HTTP spec apparently on grounds that
changing its caching effects on authentication would come as a surprise.
The actual operation is safe enough to use when parameterless no-cache
is treated strictly as an alias for must-revalidate (as done by Squid now).
Alex Rousskov [Mon, 26 Nov 2012 18:54:43 +0000 (11:54 -0700)]
Make it possible to match empty header field values using req_header and rep_header.
Warning: Some req_header and rep_header ACLs that were [accidentally] not
matching empty headers (e.g., "^$" or ".*") will now start matching them.
A new HttpHeader::getByNameIfPresent() method is added to be able to detect
presence of empty header fields while ACLHTTPHeaderData::match() is adjusted
to convert undefined String values into empty c-strings ("") for
ACLRegexData::match() to work.
Prior to these changes, when trying to match an empty header value with a
regex like "^$", ACLHTTPHeaderData::match() would return false because:
* HttpHeader::getStrOrList() and getByName() return an undefined String.
* String::termedBuf() returns NULL for undefined Strings; and
* ACLRegexData::match() always fails on NULL c-strings.
Amos Jeffries [Sat, 24 Nov 2012 14:30:02 +0000 (03:30 +1300)]
Fix helper reply length detection
Stateless helper reply handler was incrementing 't' position before
passing the details of response length to HelperReply parser.
Stateful helper reply handler was pointing at position of \n insteaf of
position of \r when \r\n received.
Both of these cause the response length parameter sent to the reply
parser to be longer than the actual response characters length. Breaking
parse on responses with just result code followed by \n since the string
comparison EOL is now tested against input length 2/3/4.
Amos Jeffries [Sun, 18 Nov 2012 10:37:19 +0000 (03:37 -0700)]
Fix several buffer termination bugs
* strcpy() replaced in several places with strncpy() to ensure destination
buffers are not overflowed.
* strncpy() does not nul-terminate the destination when the string being
copied in exactly fills the buffer. Ensure we have terminated strings
where it may matter.
Detected by Coverity Scan. Issues 740309, 740310, 740311, 740481, 740483
Amos Jeffries [Sun, 18 Nov 2012 10:02:38 +0000 (03:02 -0700)]
Remove MemPoolChunked::memPID
This member variable appears to have been missed when MemPool was split
into generic framework and specific Chunked implementation.
(rev:10513.1.1 aka trunnk rev:10517)
The memPID and its maintenance code was moved into MemImplementingAllocator
but this definitio left here un-initialized and shadowing the framework
member.
Amos Jeffries [Sun, 18 Nov 2012 07:06:26 +0000 (00:06 -0700)]
negotiate_kerberos_auth: better bounds checking
* sysconf() may return -N values on some platforms or values larger than
the hard-coded 1024 buffer size for hostname. Use sizeof() instead
since the buffer is hardcoded anyway.
* also, use return instead of exit() on the test binary to reduce
warnings from static analysis compilers.
Amos Jeffries [Sat, 17 Nov 2012 12:58:59 +0000 (05:58 -0700)]
Various memory leaks in configuration parsing
This lot are all small issues derived from allocating new memory and
assigning to a pointer already pointing at previous allocation, or
passing xstrdup() output to a caller which does not directly hold the
passed memory.
Both cases will disappear once we clean up teh string handlign in Squid
but for now these still need fixing to avoid leaking memory.
Detected by Coverity Scan. Issues 740430, 740432, 740439.
Amos Jeffries [Fri, 16 Nov 2012 06:45:56 +0000 (23:45 -0700)]
Fix various assertion with side effects
When compiled with high optimization and assert disabled these operations
would have disappeared. The side effects being:
* Disk I/O failure protection disabled. Allowing loops in diskd write.
* squidpurge error handling on command line parse gone. Causing segfault.
* squidpurge 'I am Alive' ticker feature cease working.
Detected by Coverity Scan. Issues 740299, 740300, 740301, 740302, 740303
Amos Jeffries [Thu, 15 Nov 2012 09:00:29 +0000 (02:00 -0700)]
ntlm_fake_auth: Fix nesting error
Broken macro wrapping leads to the fake authenticator sending bad
responses to Squid. This can ead to users being rejected by the fake
helper whose purpose is to accept everything.
Amos Jeffries [Wed, 14 Nov 2012 01:33:49 +0000 (18:33 -0700)]
digest_edirectory_auth: improved error handling
Malicious response from LDAP server can cause squid helper to crash.
Missing realm value returned from LDAP without error/missing value being
indicated in the response can lead to strcmp() using a NULL pointer.
Extremely unlikely to happen in practice, but worth fixing.
Changed HERE macro to be a true nop, clarified documentation, and marked is as deprecated.
Fixed syntax bug in comm.cc unearthed by the macro-to-function change.
- Try to update the index file in all cases the database modified
- The find operator in database should not modify the database. Currently
if an entry is expired, ssl_crtd removes the cert file but does not
update the index file.
rows. Currently we are using the new operator.
- Fix a small memory leak when remove entries from database: A row object
removed from TXT_DB indexes but never released. This patch:
* Use OPENSSL_malloc and OPENSSL_free to allocate/release memory for
TXT_DB rows. OpenSSL SDK assumes that always allocated using these
functions.
* Add code in Ssl::CertificateDb::Row destructor to correctly release
a TXT_DB row.
* Add the sq_TXT_DB_delete and sq_TXT_DB_delete_row functions which
removes a row from TXT_DB indexes.
Amos Jeffries [Fri, 9 Nov 2012 04:23:08 +0000 (17:23 +1300)]
Upgrade Digest authentication to use key=value parameters
* Update the Digest auth code in Squid to process the HelperReply key-pair
notes list for data
+ output upgrade WARNING messages when old format responses are identified
+ handle TT result code (as an error with critical level ERROR message)
+ handle BH result code (as an error)
* Adds a ha1="" key to Digest auth response protocol to pass the HA1.
* Upgrade the Digest helpers to use OK/ERR/BH result codes and key=value
parameters.
With the patch r12422 which added support for OK/ERR/BH helper response codes,
the ssl_crtd interface become broken. The ConnStateData::sslCrtdHandleReply
ssl_crtd reply handler, expects a response code included at the beggining of
the returned message. This is not true after the changes.
This patch add a parameter in Ssl::CrtdMessage constructor to define a message
as "ssl_crtd reply" or "ssl_crtd request" message. For ssl_crtd reply messages
the message parser does not expect helper response code.
Amos Jeffries [Wed, 7 Nov 2012 13:13:47 +0000 (02:13 +1300)]
Use Notes objects for key=pair handling in HelperReply
* NTLM/Negotiate auth are expeted to return OK/ERR/BH/TT codes and key=pair.
The old result lines are still received, but converted to the new format
silently.
* new key accepted:
'token=' for passing NTLM and Negotiate auth tokens
* some undocumented old tags accepted by external_acl_type are now ignored:
'error=' replaced by 'message='
'passwd=' replaced by 'password='
'login=' replaced by 'user='
These were replaced some time ago and never formally documented.
Amos Jeffries [Tue, 6 Nov 2012 22:32:56 +0000 (11:32 +1300)]
Update Notes API to support key=pair additions and lookup
* Adds a Notes::const_iterator definition to match Notes::iterator
* Adds a Notes::findByName(note-name) method to locate notes given their
textual key / name string.
* Adds a Notes::add(key, value) method to insert key and value as a
single operation. No more need for callers to be using Note::Pointer
or be aware of the Note:: API just to insert the value.
TODO:
* add "key=value" syntax parser to Notes. The current parse() method
onlyl accepts MiME header syntax (line- and whitespace- oriented).
* add ostream operator to dump the notes list content to a stream.
Amos Jeffries [Tue, 30 Oct 2012 09:16:33 +0000 (22:16 +1300)]
Fix HelperReply(const HelperReply&) is private
GCC 4.1 and possibly others use copy-constructor when an instance is
created in a function parameter list using copy by reference.
We must create such objects as loal variables and pass to the function
for best efficiency.
Amos Jeffries [Mon, 29 Oct 2012 23:12:04 +0000 (12:12 +1300)]
Support OK/ERR/BH response codes from any helper
Updates the helper reponse callback API from using char* buffer to a
HelperReply object storing teh response code, a blob buffer, and
pointer to the responding helper 'server' (if stateful).
* the helper I/O read handler is updated to parse the result code off
the start of the helper response as is currently done for channel-ID.
The callback handlers are altered to use the HelperReply::status instead
of parsing it off themselves individually.
* the remaining I/O read buffer is stored in a MemBuf and callbacks are
updated to use it via the method other().
* the responding helper-server is stored into the HelperReply object and
stateful helper callbacks are combined into the same API as stateless.
The callback handlers are updated to use HelperReply::lastserver instead
of function parameter.
After this patch the helper response format is:
[channel-ID] SP [result] [ [SP] blob] <terminator>
'SP' being one octet \0x20 character.
The behavour changes expected from this is that all helpers are now able
to send OK/ERR/BH states. Although the handlers for some helpers will
deal with the new states as unknown response. None of the bundled
helpers have yet been altered to make use of this changed potential.
TODO:
* implement key=value parser for the blob area of the format, and update
handlers to use the HelperReply API to retrieve them.
* upgrade helpers to make use of new response format
Amos Jeffries [Mon, 29 Oct 2012 04:59:58 +0000 (22:59 -0600)]
Polish: update the RefCount API a bt and split Lock out
* Shuffle RefCount.h and its unit-tests into src/base/
* Reworks struct Refcountable_ into class LockableObject in its own header
+ changing the reference counter accessors to a lock()/unlock() names
+ some minor symbol updates of code directly utilizing the RefCountable_
members
With this we can begin the process of replacing our multiple different
implementations of the reference-counting pattern using LockableObject.
No code changes have been made. Just symbol polishing.
TODO: update the unit-tests for refcounting to use CPPUnit