| 1 | #!/usr/bin/env python
|
|---|
| 2 |
|
|---|
| 3 | # Unix SMB/CIFS implementation.
|
|---|
| 4 | # A test for the ntlm_auth tool
|
|---|
| 5 | # Copyright (C) Kai Blin <[email protected]> 2008
|
|---|
| 6 | #
|
|---|
| 7 | # This program is free software; you can redistribute it and/or modify
|
|---|
| 8 | # it under the terms of the GNU General Public License as published by
|
|---|
| 9 | # the Free Software Foundation; either version 3 of the License, or
|
|---|
| 10 | # (at your option) any later version.
|
|---|
| 11 | #
|
|---|
| 12 | # This program is distributed in the hope that it will be useful,
|
|---|
| 13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 15 | # GNU General Public License for more details.
|
|---|
| 16 | #
|
|---|
| 17 | # You should have received a copy of the GNU General Public License
|
|---|
| 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|---|
| 19 | #
|
|---|
| 20 | """Test ntlm_auth
|
|---|
| 21 | This test program will start ntlm_auth with the given command line switches and
|
|---|
| 22 | see if it will get the expected results.
|
|---|
| 23 | """
|
|---|
| 24 |
|
|---|
| 25 | import os
|
|---|
| 26 | import sys
|
|---|
| 27 | from optparse import OptionParser
|
|---|
| 28 |
|
|---|
| 29 | class ReadChildError(Exception):
|
|---|
| 30 | pass
|
|---|
| 31 |
|
|---|
| 32 | class WriteChildError(Exception):
|
|---|
| 33 | pass
|
|---|
| 34 |
|
|---|
| 35 | def readLine(pipe):
|
|---|
| 36 | """readLine(pipe) -> str
|
|---|
| 37 | Read a line from the child's pipe, returns the string read.
|
|---|
| 38 | Throws ReadChildError if the read fails.
|
|---|
| 39 | """
|
|---|
| 40 | buf = os.read(pipe, 2047)
|
|---|
| 41 | newline = buf.find('\n')
|
|---|
| 42 | if newline == -1:
|
|---|
| 43 | raise ReadChildError()
|
|---|
| 44 | return buf[:newline]
|
|---|
| 45 |
|
|---|
| 46 | def writeLine(pipe, buf):
|
|---|
| 47 | """writeLine(pipe, buf) -> nul
|
|---|
| 48 | Write a line to the child's pipe.
|
|---|
| 49 | Raises WriteChildError if the write fails.
|
|---|
| 50 | """
|
|---|
| 51 | written = os.write(pipe, buf)
|
|---|
| 52 | if written != len(buf):
|
|---|
| 53 | raise WriteChildError()
|
|---|
| 54 | os.write(pipe, "\n")
|
|---|
| 55 |
|
|---|
| 56 | def parseCommandLine():
|
|---|
| 57 | """parseCommandLine() -> (opts, ntlm_auth_path)
|
|---|
| 58 | Parse the command line.
|
|---|
| 59 | Return a tuple consisting of the options and the path to ntlm_auth.
|
|---|
| 60 | """
|
|---|
| 61 | usage = "usage: %prog [options] path/to/ntlm_auth"
|
|---|
| 62 | parser = OptionParser(usage)
|
|---|
| 63 |
|
|---|
| 64 | parser.set_defaults(client_username="foo")
|
|---|
| 65 | parser.set_defaults(client_password="secret")
|
|---|
| 66 | parser.set_defaults(client_domain="FOO")
|
|---|
| 67 | parser.set_defaults(client_helper="ntlmssp-client-1")
|
|---|
| 68 |
|
|---|
| 69 | parser.set_defaults(server_username="foo")
|
|---|
| 70 | parser.set_defaults(server_password="secret")
|
|---|
| 71 | parser.set_defaults(server_domain="FOO")
|
|---|
| 72 | parser.set_defaults(server_helper="squid-2.5-ntlmssp")
|
|---|
| 73 | parser.set_defaults(config_file="/etc/samba/smb.conf")
|
|---|
| 74 |
|
|---|
| 75 | parser.add_option("--client-username", dest="client_username",\
|
|---|
| 76 | help="User name for the client. [default: foo]")
|
|---|
| 77 | parser.add_option("--client-password", dest="client_password",\
|
|---|
| 78 | help="Password the client will send. [default: secret]")
|
|---|
| 79 | parser.add_option("--client-domain", dest="client_domain",\
|
|---|
| 80 | help="Domain the client authenticates for. [default: FOO]")
|
|---|
| 81 | parser.add_option("--client-helper", dest="client_helper",\
|
|---|
| 82 | help="Helper mode for the ntlm_auth client. [default: ntlmssp-client-1]")
|
|---|
| 83 |
|
|---|
| 84 | parser.add_option("--server-username", dest="server_username",\
|
|---|
| 85 | help="User name server uses for local auth. [default: foo]")
|
|---|
| 86 | parser.add_option("--server-password", dest="server_password",\
|
|---|
| 87 | help="Password server uses for local auth. [default: secret]")
|
|---|
| 88 | parser.add_option("--server-domain", dest="server_domain",\
|
|---|
| 89 | help="Domain server uses for local auth. [default: FOO]")
|
|---|
| 90 | parser.add_option("--server-helper", dest="server_helper",\
|
|---|
|
|---|