1 # Tests for limiting processes forked on accept by the standard process model
3 # Copyright (C) Andrew Bartlett <abartlet@samba.org> 2018
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 """Tests limits on processes forked by fork on accept in the standard process
20 NOTE: This test runs in an environment with an artificially low setting for
26 from samba.tests import TestCase
27 from samba.samdb import SamDB
28 from ldb import LdbError, ERR_OPERATIONS_ERROR
31 class StandardModelProcessLimitTests(TestCase):
34 super(StandardModelProcessLimitTests, self).setUp()
37 super(StandardModelProcessLimitTests, self).tearDown()
39 def simple_bind(self):
40 creds = self.insta_creds(template=self.get_credentials())
41 creds.set_bind_dn("%s\\%s" % (creds.get_domain(),
42 creds.get_username()))
44 return SamDB(url="ldaps://%s" % os.environ["SERVER"],
45 lp=self.get_loadparm(),
48 def test_process_limits(self):
49 creds = self.insta_creds(template=self.get_credentials())
50 creds.set_bind_dn("%s\\%s" % (creds.get_domain(),
51 creds.get_username()))
55 # Open a series of LDAP connections, the maximum number of
56 # active connections should be 20, so the 21st should fail.
57 # But as it is possible that there may be other processes holding
58 # connections, need to allow for earlier connection failures.
60 connections.append(self.simple_bind())
62 "Processes not limited, able to make more than 20 connections")
64 (errno, estr) = e.args
65 if errno != ERR_OPERATIONS_ERROR:
67 if not (estr.endswith("NT_STATUS_CONNECTION_DISCONNECTED") or
68 estr.endswith("NT_STATUS_CONNECTION_RESET")):
72 # Clean up the connections we've just opened, by deleting the
73 # connection in python. This should invoke the talloc destructor to
74 # release any resources and close the actual connection to the server.