source: vendor/current/source4/scripting/devel/addlotscontacts

Last change on this file was 988, checked in by Silvan Scherrer, 9 years ago

Samba Server: update vendor to version 4.4.3

File size: 3.0 KB
Line 
1#!/usr/bin/env python
2#
3# Copyright (C) Matthieu Patou <mat@matws.net> 2010
4#
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 3 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, see <http://www.gnu.org/licenses/>.
18
19
20__docformat__ = "restructuredText"
21
22
23import optparse
24import sys
25# Allow to run from s4 source directory (without installing samba)
26sys.path.insert(0, "bin/python")
27
28import samba.getopt as options
29from samba.credentials import DONT_USE_KERBEROS
30from samba.auth import system_session
31from samba import param
32from samba.provision import find_provision_key_parameters
33from samba.upgradehelpers import (get_paths, get_ldbs)
34from ldb import SCOPE_BASE, Message, MessageElement, Dn, FLAG_MOD_ADD
35
36parser = optparse.OptionParser("chgtdcpass [options]")
37sambaopts = options.SambaOptions(parser)
38parser.add_option_group(sambaopts)
39parser.add_option_group(options.VersionOptions(parser))
40credopts = options.CredentialsOptions(parser)
41parser.add_option_group(credopts)
42
43(opts, args) = parser.parse_args()
44
45lp = sambaopts.get_loadparm()
46smbconf = lp.configfile
47creds = credopts.get_credentials(lp)
48creds.set_kerberos_state(DONT_USE_KERBEROS)
49
50if len(args) > 0:
51 num_contacts = int(args[0])
52else:
53 num_contacts = 10000
54
55if __name__ == '__main__':
56 paths = get_paths(param, smbconf=smbconf)
57 session = system_session()
58
59 ldbs = get_ldbs(paths, creds, session, lp)
60 ldbs.startTransactions()
61
62 names = find_provision_key_parameters(ldbs.sam, ldbs.secrets, ldbs.idmap,
63 paths, smbconf, lp)
64
65 contactdn = "OU=Contacts,%s" % str(names.domaindn)
66 res = ldbs.sam.search(expression="(distinguishedName=%s)" % contactdn,
67 base=str(names.domaindn),
68 scope=SCOPE_BASE)
69
70 if (len(res) == 0):
71 msg = Message()
72 msg.dn = Dn(ldbs.sam, contactdn)
73 msg["objectClass"] = MessageElement("organizationalUnit", FLAG_MOD_ADD,
74 "objectClass")
75
76 ldbs.sam.add(msg)
77
78 print "Creating %d contacts" % num_contacts
79 count = 0
80 increment = num_contacts / 10
81 if increment > 5000:
82 increment = 5000
83
84 while (count < num_contacts):
85 msg = Message()
86 msg.dn = Dn(ldbs.sam, "CN=contact%d,%s" % (count + 1, contactdn))
87 msg["objectClass"] = MessageElement("contact", FLAG_MOD_ADD,
88 "objectClass")
89
90 if count !=0 and (count % increment) == 0:
91 print "Added contacts: %d" % count
92
93 ldbs.sam.add(msg)
94 count += 1
95
96 ldbs.groupedCommit()
Note: See TracBrowser for help on using the repository browser.