title: SQUID3 - using multiple auth_param like basic_ncsa_auth & basic_ldap_auth
body: <p>i tried to setup squid3 with multiple auth_param. Basically, the first choice should be basic_ldap_auth and if this doesnt return OK it should try basic_ncsa_auth with the same values. As far as i know squid doesnt support it however there is the possibility to use <a href="http://wiki.squid-cache.org/ConfigExamples/Authenticate/MultipleSources" rel="nofollow">"external" ACL</a> </p>
  
  <pre><code>auth_param basic program /usr/lib/squid3/basic_fake_auth
  external_acl_type MultAuth %SRC %LOGIN %{Proxy-Authorization} /etc/squid3/multAuth.pl
  acl extAuth external MultAuth
  </code></pre>
  
  <p>my "multAuth.pl"</p>
  
  <pre><code>use URI::Escape;
  use MIME::Base64;
  
  $|=1;
  
     while (&lt;&gt;) {
        ($ip,$user,$auth) = split();
  
          # Retrieve the password from the authentication header
        $auth = uri_unescape($auth);
        ($type,$authData) = split(/ /, $auth);
        $authString = decode_base64($authData);
        ($username,$password) = split(/:/, $authString);
  
        # do the authentication and pass results back to Squid.
        $ldap = `/bin/bash auth/ldap.sh`;
        if ($ldap == "OK") {
          print "OK";
        } 
        $ncsa = `/bin/bash auth/ncsa.sh`;
        if ($ncsa == "OK") {
          print "OK";
        } else {
          print "ERR";
        }
  }
  </code></pre>
  
  <p>now i am trying to run with ncsa.sh and ldap.sh the "normal" shell command for these auth methods. </p>
  
  <pre><code>./basic_ldap_auth -R -b "dc=domain,dc=de" -D "CN=Administrator,CN=Users,DC=domain,DC=de" -w "password" -f sAMAccountName=%s -h domain.de
  user password
  </code></pre>
  
  <p>and</p>
  
  <pre><code>./basic_ncsa_auth /etc/squid3/users
  user password
  </code></pre>
  
  <p>Therefor i ran:
  auth/ncsa.sh</p>
  
  <pre><code>#!/usr/bin/expect
  eval spawn [lrange $argv 0 end]
  expect ""
  send [lindex $argv 1]
  send '\r'
  expect {
      "OK" {
          echo OK
          exp_continue
      }
      "ERR" {
          echo ERR
      exp_continue
      }
  interact
  </code></pre>
  
  <p>with </p>
  
  <pre><code>./ncsa.sh "/usr/lib/squid3/basic_ncsa_auth /etc/squid3/users" "user password"
  </code></pre>
  
  <p>and i generate the following error:</p>
  
  <pre><code>couldn't execute "/usr/lib/squid3/basic_ncsa_auth /etc/squid3/users": no such file or directory
  while executing
  "spawn {/usr/lib/squid3/basic_ncsa_auth /etc/squid3/users} {user password}"
      ("eval" body line 1)
      invoked from within
  "eval spawn [lrange $argv 0 end]"
      (file "./ncsa.sh" line 2)
  </code></pre>
  
  <p>Besides this error, i am not sure how to pass the variables (username &amp; password) forward and i am also not sure how to <a href="http://www.thegeekstuff.com/2010/10/expect-examples/" rel="nofollow">answer the shell</a> questions like for example the user &amp; pw input for basic_ldap_auth .</p>
  
  <p>Is there a nice way how to solve that? or any other good plan ?</p>
  
  <p>thanks!</p>