~ubuntu-branches/ubuntu/trusty/freeipa/trusty

« back to all changes in this revision

Viewing changes to install/tools/ipa-dns-install

  • Committer: Package Import Robot
  • Author(s): Timo Aaltonen
  • Date: 2013-03-07 14:10:03 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20130307141003-kz4lq9vj4x692mqq
Tags: 3.1.2-0ubuntu1
* Merge from unreleased debian git.
  - new upstream release
  - doesn't use chkconfig anymore (LP: #1025018, #1124093)
  - drop -U from the ntpdate options (LP: #1149468)

Show diffs side-by-side

added added

removed removed

Lines of Context:
19
19
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
20
#
21
21
 
22
 
import traceback
23
 
 
24
22
from ipaserver.plugins.ldap2 import ldap2
25
 
from ipaserver.install import bindinstance, ntpinstance
 
23
from ipaserver.install import service, bindinstance, ntpinstance, httpinstance
26
24
from ipaserver.install.installutils import *
27
25
from ipaserver.install import installutils
28
26
from ipapython import version
29
27
from ipapython import ipautil, sysrestore
30
28
from ipalib import api, errors, util
31
29
from ipapython.config import IPAOptionParser
32
 
from ipalib.constants import DNS_ZONE_REFRESH
 
30
from optparse import OptionGroup, SUPPRESS_HELP
33
31
import krbV
34
32
import ldap
 
33
from ipapython.ipa_log_manager import *
 
34
 
 
35
log_file_name = "/var/log/ipaserver-install.log"
35
36
 
36
37
def parse_options():
37
38
    parser = IPAOptionParser(version=version.VERSION)
47
48
                      default=False, help="Do not add any DNS forwarders, use root servers instead")
48
49
    parser.add_option("--reverse-zone", dest="reverse_zone", help="The reverse DNS zone to use")
49
50
    parser.add_option("--no-reverse", dest="no_reverse", action="store_true",
50
 
                      default=False, help="Do not create reverse DNS zone")
51
 
    parser.add_option("--zonemgr", dest="zonemgr", 
52
 
                      help="DNS zone manager e-mail address. Defaults to root")
 
51
                      default=False, help="Do not create new reverse DNS zone")
 
52
    parser.add_option("--zonemgr", action="callback", callback=bindinstance.zonemgr_callback,
 
53
                      type="string",
 
54
                      help="DNS zone manager e-mail address. Defaults to hostmaster@DOMAIN")
 
55
    # this option name has been deprecated, persistent search has been enabled by default
53
56
    parser.add_option("--zone-notif", dest="zone_notif",
54
 
                      action="store_true", default=False,
55
 
                      help="Let name server receive notification when a new zone is added." \
56
 
                           "Zone refresh is turned off when zone notification is enabled")
 
57
                      action="store_true", default=False, help=SUPPRESS_HELP)
 
58
    parser.add_option("--no-persistent-search", dest="persistent_search",
 
59
                      default=True, action="store_false",
 
60
                      help="Do not enable persistent search feature in the name server")
57
61
    parser.add_option("--zone-refresh", dest="zone_refresh",
58
 
                      default=DNS_ZONE_REFRESH, type="int",
59
 
                      help="A delay between checks for new DNS zones. Defaults to %d" \
60
 
                              % DNS_ZONE_REFRESH)
 
62
                      default=0, type="int",
 
63
                      help="When set to non-zero the name server will use DNS zone "
 
64
                           "detection based on polling instead of a persistent search")
 
65
    parser.add_option("--no-serial-autoincrement", dest="serial_autoincrement",
 
66
                      default=True, action="store_false",
 
67
                      help="Do not enable SOA serial autoincrement")
61
68
    parser.add_option("-U", "--unattended", dest="unattended", action="store_true",
62
69
                      default=False, help="unattended installation never prompts the user")
63
70
 
75
82
 
76
83
    if options.zone_refresh < 0:
77
84
        parser.error("negative numbers not allowed for --zone-refresh")
78
 
 
79
 
    if options.zone_notif:   # mutually exclusive features
80
 
        options.zone_refresh = 0
 
85
    elif options.zone_refresh > 0:
 
86
        options.persistent_search = False   # mutually exclusive features
 
87
 
 
88
    if options.zone_notif:
 
89
        print >>sys.stderr, "WARNING: --zone-notif option is deprecated and has no effect"
 
90
 
 
91
    if options.serial_autoincrement and not options.persistent_search:
 
92
        parser.error('persistent search feature is required for '
 
93
                     'DNS SOA serial autoincrement')
81
94
 
82
95
    return safe_options, options
83
96
 
87
100
    if os.getegid() != 0:
88
101
        sys.exit("Must be root to setup server")
89
102
 
90
 
    standard_logging_setup("/var/log/ipaserver-install.log", options.debug, filemode='a')
91
 
    print "\nThe log file for this installation can be found in /var/log/ipaserver-install.log"
 
103
    standard_logging_setup(log_file_name, debug=options.debug, filemode='a')
 
104
    print "\nThe log file for this installation can be found in %s" % log_file_name
92
105
 
93
 
    logging.debug('%s was invoked with options: %s' % (sys.argv[0], safe_options))
94
 
    logging.debug("missing options might be asked for interactively later\n")
 
106
    root_logger.debug('%s was invoked with options: %s' % (sys.argv[0], safe_options))
 
107
    root_logger.debug("missing options might be asked for interactively later\n")
95
108
 
96
109
    installutils.check_server_configuration()
97
110
 
145
158
    else:
146
159
        hostaddr = resolve_host(api.env.host)
147
160
        try:
148
 
            ip = hostaddr and ipautil.CheckedIPAddress(hostaddr, match_local=True)
 
161
            if len(hostaddr) > 1:
 
162
                print >> sys.stderr, "The server hostname resolves to more than one address:"
 
163
                for addr in hostaddr:
 
164
                    print >> sys.stderr, "  %s" % addr
 
165
 
 
166
                if options.ip_address:
 
167
                    if str(options.ip_address) not in hostaddr:
 
168
                        print >> sys.stderr, "Address passed in --ip-address did not match any resolved"
 
169
                        print >> sys.stderr, "address!"
 
170
                        sys.exit(1)
 
171
                    print "Selected IP address:", str(options.ip_address)
 
172
                    ip = options.ip_address
 
173
                else:
 
174
                    if options.unattended:
 
175
                        print >> sys.stderr, "Please use --ip-address option to specify the address"
 
176
                        sys.exit(1)
 
177
                    else:
 
178
                        ip = read_ip_address(api.env.host, fstore)
 
179
            else:
 
180
                ip = hostaddr and ipautil.CheckedIPAddress(hostaddr[0], match_local=True)
149
181
        except Exception, e:
150
182
            print "Error: Invalid IP Address %s: %s" % (ip, e)
151
183
            ip = None
156
188
        else:
157
189
            ip = read_ip_address(api.env.host, fstore)
158
190
    ip_address = str(ip)
159
 
    logging.debug("will use ip_address: %s\n", ip_address)
 
191
    root_logger.debug("will use ip_address: %s\n", ip_address)
160
192
 
161
193
    if options.reverse_zone and not bindinstance.verify_reverse_zone(options.reverse_zone, ip):
162
194
        sys.exit(1)
167
199
        dns_forwarders = options.forwarders
168
200
    else:
169
201
        dns_forwarders = read_dns_forwarders()
170
 
    logging.debug("will use dns_forwarders: %s\n", str(dns_forwarders))
 
202
    root_logger.debug("will use dns_forwarders: %s\n", str(dns_forwarders))
171
203
 
172
204
    if bind.dm_password:
173
 
        api.Backend.ldap2.connect(bind_dn="cn=Directory Manager", bind_pw=bind.dm_password)
 
205
        api.Backend.ldap2.connect(bind_dn=DN(('cn', 'Directory Manager')), bind_pw=bind.dm_password)
174
206
    else:
175
207
        # See if our LDAP server is up and we can talk to it over GSSAPI
176
208
        ccache = krbV.default_context().default_ccache().name
181
213
    else:
182
214
        reverse_zone = bindinstance.find_reverse_zone(ip)
183
215
        if reverse_zone is None and not options.no_reverse:
184
 
            reverse_zone = bindinstance.get_reverse_zone_default(ip)
185
 
            if not options.unattended and bindinstance.create_reverse():
 
216
            if options.unattended:
 
217
                reverse_zone = util.get_reverse_zone_default(ip)
 
218
            elif bindinstance.create_reverse():
 
219
                reverse_zone = util.get_reverse_zone_default(ip)
186
220
                reverse_zone = bindinstance.read_reverse_zone(reverse_zone, ip)
187
221
 
188
222
    if reverse_zone is not None:
199
233
    bind.setup(api.env.host, ip_address, api.env.realm, api.env.domain,
200
234
               dns_forwarders, conf_ntp, reverse_zone, zonemgr=options.zonemgr,
201
235
               zone_refresh=options.zone_refresh,
202
 
               zone_notif=options.zone_notif)
 
236
               persistent_search=options.persistent_search,
 
237
               serial_autoincrement=options.serial_autoincrement)
203
238
    bind.create_instance()
204
239
 
 
240
    # Restart http instance to make sure that python-dns has the right resolver
 
241
    # https://bugzilla.redhat.com/show_bug.cgi?id=800368
 
242
    http = httpinstance.HTTPInstance(fstore)
 
243
    service.print_msg("Restarting the web server")
 
244
    http.restart()
205
245
 
206
246
    print "=============================================================================="
207
247
    print "Setup complete"
208
248
    print ""
 
249
    bind.check_global_configuration()
 
250
    print ""
 
251
    print ""
209
252
    print "\tYou must make sure these network ports are open:"
210
253
    print "\t\tTCP Ports:"
211
254
    print "\t\t  * 53: bind"
214
257
 
215
258
    return 0
216
259
 
217
 
try:
218
 
    sys.exit(main())
219
 
except SystemExit, e:
220
 
    sys.exit(e)
221
 
except KeyboardInterrupt:
222
 
    print "Installation cancelled."
223
 
except RuntimeError, e:
224
 
    print str(e)
225
 
except HostnameLocalhost:
226
 
    print "The hostname resolves to the localhost address (127.0.0.1/::1)"
227
 
    print "Please change your /etc/hosts file so that the hostname"
228
 
    print "resolves to the ip address of your network interface."
229
 
    print "The KDC service does not listen on localhost"
230
 
    print ""
231
 
    print "Please fix your /etc/hosts file and restart the setup program"
232
 
except Exception, e:
233
 
    message = "Unexpected error - see ipaserver-install.log for details:\n %s" % str(e)
234
 
    print message
235
 
    message = str(e)
236
 
    for str in traceback.format_tb(sys.exc_info()[2]):
237
 
        message = message + "\n" + str
238
 
    logging.debug(message)
239
 
    sys.exit(1)
 
260
if __name__ == '__main__':
 
261
    installutils.run_script(main, log_file_name=log_file_name,
 
262
        operation_name='ipa-dns-install')