~ubuntu-branches/ubuntu/trusty/389-ds-base/trusty

« back to all changes in this revision

Viewing changes to ldap/admin/src/scripts/template-schema-reload.pl.in

  • Committer: Package Import Robot
  • Author(s): Timo Aaltonen
  • Date: 2013-08-30 00:31:55 UTC
  • mfrom: (1.2.1)
  • Revision ID: package-import@ubuntu.com-20130830003155-oimuzdqopkvp2cd0
Tags: 1.3.1.7-0ubuntu1
Sync from unreleased debian git.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
35
35
36
36
# Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
37
 
# Copyright (C) 2008 Red Hat, Inc.
 
37
# Copyright (C) 2013 Red Hat, Inc.
38
38
# All rights reserved.
39
39
# END COPYRIGHT BLOCK
40
40
#
41
41
 
42
 
sub usage {
43
 
    print(STDERR "Usage: $0 [-v] -D rootdn { -w password | -w - | -j filename } \n");
44
 
    print(STDERR "        [-d schemadir]\n");
45
 
    print(STDERR " Opts: -D rootdn           - Directory Manager\n");
46
 
    print(STDERR "     : -w password         - Directory Manager's password\n");
47
 
    print(STDERR "     : -w -                - Prompt for Directory Manager's password\n");
48
 
    print(STDERR "     : -j filename         - Read Directory Manager's password from file\n");
49
 
    print(STDERR "     : -d schemadir        - Directory where schema files are located\n");
50
 
    print(STDERR "     : -v                  - verbose\n");
51
 
}
52
 
 
53
 
$rootdn = "";
54
 
$passwd = "";
55
 
$passwdfile = "";
56
 
$schemadir = "";
57
 
$schemadir_arg = "";
58
 
$verbose = 0;
59
 
 
60
 
$prefix = "{{DS-ROOT}}";
61
 
 
62
 
$ENV{'PATH'} = "$prefix@ldaptool_bindir@:$prefix/usr/bin:@ldaptool_bindir@:/usr/bin";
63
 
 
64
 
libpath_add("$prefix@nss_libdir@");
65
 
libpath_add("$prefix/usr/lib");
66
 
libpath_add("@nss_libdir@");
67
 
libpath_add("/usr/lib");
68
 
 
69
 
$ENV{'SHLIB_PATH'} = "$ENV{'LD_LIBRARY_PATH'}";
70
 
 
71
 
$i = 0;
72
 
while ($i <= $#ARGV) 
73
 
{
74
 
    if ("$ARGV[$i]" eq "-d")
75
 
    {
76
 
        # schemadir
77
 
        $i++; $schemadir_arg = $ARGV[$i];
78
 
    }
79
 
    elsif ("$ARGV[$i]" eq "-D") 
80
 
    {    
81
 
        # Directory Manager
82
 
        $i++; $rootdn = $ARGV[$i];
83
 
    }
84
 
    elsif ("$ARGV[$i]" eq "-w") 
85
 
    {    
86
 
        # Directory Manager's password
87
 
        $i++; $passwd = $ARGV[$i];
88
 
    } 
89
 
    elsif ("$ARGV[$i]" eq "-j")
90
 
    {
91
 
         # Read Directory Manager's password from a file
92
 
        $i++; $passwdfile = $ARGV[$i];
93
 
    }
94
 
    elsif ("$ARGV[$i]" eq "-v") 
95
 
    {    
96
 
        # verbose
97
 
        $verbose = 1;
98
 
    }
99
 
    else
100
 
    {
101
 
        &usage; exit(1);
102
 
    }
103
 
    $i++;
104
 
}
105
 
 
106
 
if ($passwdfile ne ""){
107
 
# Open file and get the password
108
 
    unless (open (RPASS, $passwdfile)) {
109
 
        die "Error, cannot open password file $passwdfile\n";
110
 
    }
111
 
    $passwd = <RPASS>;
112
 
    chomp($passwd);
113
 
    close(RPASS);
114
 
} elsif ($passwd eq "-"){
115
 
# Read the password from terminal
116
 
        print "Bind Password: ";
117
 
        # Disable console echo
118
 
        system("@sttyexec@ -echo") if -t STDIN;
119
 
        # read the answer
120
 
        $passwd = <STDIN>;
121
 
        # Enable console echo
122
 
        system("@sttyexec@ echo") if -t STDIN;
123
 
        print "\n";
124
 
        chop($passwd); # trim trailing newline
125
 
}
126
 
 
127
 
if ( $rootdn eq "" || $passwd eq "" )
128
 
129
 
    &usage; 
130
 
    exit(1); 
131
 
}
132
 
 
133
 
$vstr = "";
134
 
if ($verbose != 0) 
135
 
136
 
    $vstr = "-v"; 
137
 
}
138
 
 
139
 
# Use a timestamp as part of the task entry name
140
 
($s, $m, $h, $dy, $mn, $yr, $wdy, $ydy, $r) = localtime(time);
141
 
$mn++; $yr += 1900;
142
 
$taskname = "schema_reload_${yr}_${mn}_${dy}_${h}_${m}_${s}";
143
 
 
144
 
# Build the task entry to add
145
 
$dn = "dn: cn=$taskname, cn=schema reload task, cn=tasks, cn=config\n";
146
 
$misc = "changetype: add\nobjectclass: top\nobjectclass: extensibleObject\n";
147
 
$cn =  "cn: $taskname\n";
148
 
 
149
 
if ( $schemadir_arg ne "" )
150
 
{
151
 
    $schemadir = "schemadir: $schemadir_arg\n";
152
 
}
153
 
 
154
 
$entry = "${dn}${misc}${cn}${basedn}${schemadir}";
155
 
open(FOO, "| ldapmodify @ldaptool_opts@ $vstr -h {{SERVER-NAME}} -p {{SERVER-PORT}} -D \"$rootdn\" -w \"$passwd\" -a" );
156
 
print(FOO "$entry");
157
 
close(FOO);
158
 
 
159
 
sub libpath_add {
160
 
    my $libpath = shift;
161
 
 
162
 
    if ($libpath) {
163
 
        if ($ENV{'LD_LIBRARY_PATH'}) {
164
 
            $ENV{'LD_LIBRARY_PATH'} = "$ENV{'LD_LIBRARY_PATH'}:$libpath";
 
42
# We lose args that are quoted when passing ARGV to a wrapper
 
43
while ($i <= $#ARGV) {
 
44
        if($ARGV[$i] =~ /^-/){
 
45
                $wrapperArgs[$i] = $ARGV[$i];
165
46
        } else {
166
 
            $ENV{'LD_LIBRARY_PATH'} = "$libpath";
 
47
                $wrapperArgs[$i] = "\"$ARGV[$i]\"";
167
48
        }
168
 
    }
 
49
        $i++;
169
50
}
 
51
 
 
52
exec "{{SERVERBIN-DIR}}/schema-reload.pl @wrapperArgs -Z {{SERV-ID}}";
 
53
 
 
54
exit ($?);
 
 
b'\\ No newline at end of file'