]> git.ipfire.org Git - thirdparty/squid.git/blame - helpers/basic_auth/SMB/smb_auth.sh
Major rewrite of proxy authentication to support other schemes than
[thirdparty/squid.git] / helpers / basic_auth / SMB / smb_auth.sh
CommitLineData
94439e4e 1#!/bin/sh
2#
3# smb_auth - SMB proxy authentication module
4# Copyright (C) 1998 Richard Huveneers <richard@hekkihek.hacom.nl>
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 2 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program; if not, write to the Free Software
18# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20read DOMAINNAME
21read PASSTHROUGH
22read NMBADDR
23read NMBCAST
24read AUTHSHARE
25read AUTHFILE
26read SMBUSER
27read SMBPASS
28
29# Find domain controller
30echo "Domain name: $DOMAINNAME"
31if [ -n "$PASSTHROUGH" ]
32then
33 echo "Pass-through authentication: yes: $PASSTHROUGH"
34else
35 echo "Pass-through authentication: no"
36 PASSTHROUGH="$DOMAINNAME"
37fi
38if [ -n "$NMBADDR" ]
39then
40 if [ "$NMBCAST" = "1" ]
41 then
42 addropt="-U $NMBADDR -R"
43 else
44 addropt="-B $NMBADDR"
45 fi
46else
47 addropt=""
48fi
49echo "Query address options: $addropt"
50dcip=`$SAMBAPREFIX/bin/nmblookup $addropt "$PASSTHROUGH#1c" | awk '/^[0-9.]+ / { print $1 ; exit }'`
51echo "Domain controller IP address: $dcip"
52[ -n "$dcip" ] || exit 1
53
54# All right, we have the IP address of a domain controller,
55# but we need its name too
56dcname=`$SAMBAPREFIX/bin/nmblookup -A $dcip | awk '$2 == "<00>" { print $1 ; exit }'`
57echo "Domain controller NETBIOS name: $dcname"
58[ -n "$dcname" ] || exit 1
59
60# Pass password to smbclient through environment. Not really safe.
61USER="$SMBUSER%$SMBPASS"
62export USER
63
64# Read the contents of the file $AUTHFILE on the $AUTHSHARE share
65authfilebs=`echo "$AUTHFILE" | tr / '\\\\'`
66authinfo=`$SAMBAPREFIX/bin/smbclient "//$dcname/$AUTHSHARE" -I $dcip -d 0 -E -W "$DOMAINNAME" -c "get $authfilebs -" 2>/dev/null`
67echo "Contents of //$dcname/$AUTHSHARE/$AUTHFILE: $authinfo"
68
69# Allow for both \n and \r\n end-of-line termination
70[ "$authinfo" = "allow" -o "$authinfo" = "allow\r" ] || exit 1
71exit 0