2 # Actually create a new base DN
4 require './ldap-server-lib.pl';
6 &error_setup($text{'create_err'});
7 $access{'create'} || &error($text{'create_ecannot'});
8 $ldap = &connect_ldap_db();
9 ref($ldap) || &error($ldap);
12 if ($in{'mode'} == 0) {
13 $in{'domain'} =~ /^[a-z0-9\.\-]+$/ || &error($text{'create_edom'});
14 @p = split(/\./, $in{'domain'});
15 $dn = join(", ", map { "dc=$_" } @p);
18 $in{'dn'} =~ /^\S+=\S+/ || &error($text{'create_edn'});
22 # Work out class for the DN
23 $schema = $ldap->schema();
24 @allocs = map { $_->{'name'} }
25 grep { $_->{'structural'} }
26 $schema->all_objectclasses();
28 foreach my $poc ("top", "domain") {
29 if (&indexof($poc, @allocs) >= 0) {
33 @ocs || &error(&text('create_eoc'));
35 # Do it, while showing the user
36 &ui_print_unbuffered_header(undef, $text{'create_title'}, "");
39 print &text('create_doingdn', "<tt>".&html_escape($dn)."</tt>"),"<br>\n";
40 @attrs = ( "objectClass", \@ocs );
41 if (&indexof("domain", @ocs) >= 0) {
42 # Domain class needs dc
43 if ($dn =~ /^([^=]+)=([^, ]+)/) {
47 $rv = $ldap->add($dn, attr => \@attrs);
48 if (!$rv || $rv->code) {
49 print &text('create_edoingdn', &ldap_error($rv)),"<p>\n";
52 print $text{'create_done'},"<p>\n";
56 if ($ok && $in{'example'}) {
57 # Add the example user/alias
58 if ($in{'example'} == 1 || $in{'example'} == 2) {
60 $edn = "uid=example, ".$dn;
61 @attrs = ( "cn", "Example user",
66 "loginShell", "/bin/sh",
67 "homeDirectory", "/home/example",
68 "objectClass", [ "posixAccount", "person" ],
69 "userPassword", "*LK*" );
70 if ($in{'example'} == 2) {
72 push(@attrs, "mail", "example\@example.com");
75 elsif ($in{'example'} == 3) {
77 # XXX not sure about these .. is there any standard?
78 $edn = "cn=example\@example.com, ".$dn;
79 @attrs = ( "mail", "example\@example.com",
80 "mailForwardingAddress", "example\@somewhere.com",
81 "objectClass", [ "top" ] );
83 elsif ($in{'example'} == 4) {
85 $edn = "cn=example, ".$dn;
86 @attrs = ( "cn", "example",
88 "memberUid", "example",
89 "objectClass", [ "posixGroup" ] );
92 print &text('create_doingex',
93 "<tt>".&html_escape($edn)."</tt>"),"<br>\n";
94 $rv = $ldap->add($edn, attr => \@attrs);
95 if (!$rv || $rv->code) {
96 print &text('create_edoingex', &ldap_error($rv)),"<p>\n";
99 print $text{'create_done'},"<p>\n";
104 &webmin_log("create", undef, $dn);
106 &ui_print_footer("", $text{'index_return'});