Hello,
I'm researching possibility of using Apache DS as DNS server.
How I understood DNS provider should started as standalone application.
I wrote next small program (in attachment).
Apache DS started,
When I start DnsServer, it starts listen 53'th port:
DEBUG [AWT-EventQueue-0] (DnsServer.java:62) - Apache DNS Service
listening on port 53
And command "netstat -anl | grep :::53", reports that 53'th port listens
somebody (it's 100% DnsServer, no one other):
tcp 0 0 :::53 :::*
LISTEN
But command "dig @localhost ya.ru", reports next:
; <<>> DiG 9.3.4 <<>> @localhost ya.ru
; (1 server found)
;; global options: printcmd
;; connection timed out; no servers could be reached
Reports must be different, for instance:
dig noexistent.nodomain
; <<>> DiG 9.3.4 <<>> noexistent.nodomain
;; global options: printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 9446
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0
;; QUESTION SECTION:
;noexistent.nodomain. IN A
;; AUTHORITY SECTION:
. 600 IN SOA A.ROOT-SERVERS.NET.
NSTLD.VERISIGN-GRS.COM. 2007051701 1800 900 604800 86400
;; Query time: 165 msec
;; SERVER: 10.3.0.1#53(10.3.0.1)
;; WHEN: Fri May 18 15:09:04 2007
;; MSG SIZE rcvd: 112
What I'm doing wrong?
Partition "dc=example,dc=com" exists, but it empty, I don't know what
insert to it. If reason in it, can you send me example dns ldif file?
ps: I very new in DNS.
pps: sorry for my English.
import java.awt.Container;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.Map;
import javax.naming.Context;
import javax.naming.spi.InitialContextFactory;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.UIManager;
import org.apache.directory.server.dns.DnsConfiguration;
import org.apache.directory.server.dns.DnsServer;
import org.apache.directory.server.dns.store.JndiRecordStoreImpl;
import org.apache.mina.transport.socket.nio.SocketAcceptor;
public class DnsStarter extends JFrame {
private static final long serialVersionUID = -3782428822845544092L;
// private static final String FACTORY_CLASS_NAME = "com.sun.jndi.ldap.LdapCtxFactory";
private static final String FACTORY_CLASS_NAME = "org.apache.directory.server.core.jndi.CoreContextFactory";
public static void main(String[] args) {
System.setProperty("sun.desktop", "gnome");
try {
UIManager
.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
} catch (Exception e) {
e.printStackTrace();
}
new DnsStarter();
}
private JTextField textLdapUrl = null;
private JTextField textSecurityPrincipal = null;
private JTextField textSecurityCredential = null;
private JTextField textBaseDN = null;
private JButton buttonStart = null;
private JButton buttonStop = null;
private InitialContextFactory factory = null;
private boolean serverStarted = false;
private DnsServer server = null;
private Map properties = null;
public DnsStarter() {
textLdapUrl = new JTextField("ldap://localhost:10389/");
textSecurityPrincipal = new JTextField("uid=admin,ou=system");
textSecurityCredential = new JTextField("123456");
textBaseDN = new JTextField("dc=example,dc=com");
AbstractAction actionStart = new AbstractAction() {
private static final long serialVersionUID = -8323288906227889703L;
public void actionPerformed(ActionEvent e) {
if (factory == null) {
try {
factory = (InitialContextFactory) Class.forName(
FACTORY_CLASS_NAME).newInstance();
// factory.
} catch (InstantiationException e1) {
e1.printStackTrace();
return;
} catch (IllegalAccessException e1) {
e1.printStackTrace();
return;
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
return;
}
}
Map props = getProperties();
DnsConfiguration config = new DnsConfiguration(props);
JndiRecordStoreImpl recordStore = new JndiRecordStoreImpl(
config, factory);
SocketAcceptor acceptor = new SocketAcceptor();
server = new DnsServer(config, acceptor, recordStore);
serverStarted = true;
updateControlsState(true);
}
};
actionStart.putValue(Action.NAME, "Start");
AbstractAction actionStop = new AbstractAction() {
private static final long serialVersionUID = 8630346717756888018L;
public void actionPerformed(ActionEvent e) {
try {
server.destroy();
} catch (RuntimeException e1) {
e1.printStackTrace();
return;
}
serverStarted = false;
updateControlsState(false);
}
};
actionStop.putValue(Action.NAME, "Stop");
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
try {
if (serverStarted == true) {
server.destroy();
}
} catch (RuntimeException e1) {
e1.printStackTrace();
return;
}
}
});
buttonStart = new JButton(actionStart);
buttonStop = new JButton(actionStop);
buttonStop.setEnabled(false);
layoutComponents();
initComponents();
setVisible(true);
}
private void updateControlsState(boolean serverStarted) {
textLdapUrl.setEnabled(!serverStarted);
textSecurityPrincipal.setEnabled(!serverStarted);
textSecurityCredential.setEnabled(!serverStarted);
textBaseDN.setEnabled(!serverStarted);
buttonStart.setEnabled(!serverStarted);
buttonStop.setEnabled(serverStarted);
}
private void layoutComponents() {
Container contentPane = getContentPane();
contentPane.setLayout(new GridBagLayout());
JLabel labelLdapUrl = new JLabel("Ldap URL:");
JLabel labelSecurityPrincipal = new JLabel("Security principal (DN):");
JLabel labelSecurityCredentials = new JLabel("Security credential:");
JLabel labelBaseDN = new JLabel("Base DN:");
Insets insets = new Insets(5, 10, 0, 10);
GridBagConstraints constraints = new GridBagConstraints();
constraints.anchor = GridBagConstraints.WEST;
constraints.gridx = 0;
constraints.gridy = 0;
constraints.insets = insets;
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.weightx = 1.0;
contentPane.add(labelLdapUrl, constraints);
constraints.gridx = 1;
contentPane.add(textLdapUrl, constraints);
constraints.gridx = 0;
constraints.gridy = 1;
contentPane.add(labelSecurityPrincipal, constraints);
constraints.gridx = 1;
contentPane.add(textSecurityPrincipal, constraints);
constraints.gridy = 2;
constraints.gridx = 0;
contentPane.add(labelSecurityCredentials, constraints);
constraints.gridx = 1;
contentPane.add(textSecurityCredential, constraints);
constraints.gridx = 0;
constraints.gridy = 3;
contentPane.add(labelBaseDN, constraints);
constraints.gridx = 1;
contentPane.add(textBaseDN, constraints);
constraints.anchor = GridBagConstraints.EAST;
constraints.gridx = 0;
constraints.gridy = 4;
constraints.fill = GridBagConstraints.NONE;
insets = constraints.insets;
insets.top += 10;
insets.bottom = 5;
contentPane.add(buttonStart, constraints);
constraints.anchor = GridBagConstraints.WEST;
constraints.gridx = 1;
contentPane.add(buttonStop, constraints);
}
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("DNS starter");
pack();
setResizable(false);
}
private Map getProperties() {
if (properties == null) {
properties = DnsConfiguration.getDefaultConfig();
}
String ldapUrl = textLdapUrl.getText();
String securityPrincipal = textSecurityPrincipal.getText();
String securityCredentials = textSecurityCredential.getText();
String baseDN = textBaseDN.getText();
properties.put(Context.PROVIDER_URL, ldapUrl);
properties.put(Context.SECURITY_PRINCIPAL, securityPrincipal);
properties.put(Context.SECURITY_CREDENTIALS, securityCredentials);
properties.put(DnsConfiguration.CATALOG_BASEDN_KEY, ldapUrl + baseDN);
properties.put(DnsConfiguration.ENTRY_BASEDN_KEY, ldapUrl + baseDN);
properties.put(DnsConfiguration.IP_ADDRESS_KEY, "127.0.0.1");
properties.put(Context.INITIAL_CONTEXT_FACTORY, FACTORY_CLASS_NAME);
properties.put(Context.SECURITY_AUTHENTICATION, "simple");
return properties;
}
}