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