ceb2235f23dc603a7ea25317b9ae1b11d198c384
[debian/amanda] / dumper-src / generic-dumper.pl.in
1
2
3 $command = $ARGV[0];
4 if ($command eq "privilege") {
5    wrapper_privilege();
6 }
7 elsif ($command eq "support") {
8    wrapper_support();
9 }
10 elsif ($command eq "selfcheck") {
11    wrapper_selfcheck();
12 }
13 elsif ($command eq "estimate") {
14    wrapper_estimate();
15 }
16 elsif ($command eq "estimate-parse") {
17    wrapper_estimate_parse();
18 }
19 elsif ($command eq "backup") {
20    wrapper_backup();
21 }
22 elsif ($command eq "backup-parse") {
23    wrapper_backup_parse();
24 }
25 elsif ($command eq "index-from-output") {
26    wrapper_index_from_output();
27 }
28 elsif ($command eq "index-from-image") {
29    wrapper_index_from_image();
30 }
31 elsif ($command eq "restore") {
32    wrapper_restore();
33 }
34 elsif ($command eq "print-command") {
35    wrapper_print_command();
36 }
37 else {
38    printf STDERR "Unknown command `$command'.\n";
39    exit 1;
40 }
41
42
43 sub wrapper_privilege() {
44    if(defined(&command_support)) {
45       command_privilege();
46       exit 0;
47    }
48    my($subcommand) = $ARGV[1];
49    if ($subcommand eq "support") {
50       wrapper_print_privilege($subcommand);
51    }
52    elsif ($subcommand eq "selfcheck") {
53       wrapper_print_privilege($subcommand);
54    }
55    elsif ($subcommand eq "estimate") {
56       wrapper_print_privilege($subcommand);
57    }
58    elsif ($subcommand eq "estimate-parse") {
59       wrapper_print_privilege($subcommand);
60    }
61    elsif ($subcommand eq "backup") {
62       wrapper_print_privilege($subcommand);
63    }
64    elsif ($subcommand eq "backup-parse") {
65       wrapper_print_privilege($subcommand);
66    }
67    elsif ($subcommand eq "index-from-output") {
68       wrapper_print_privilege($subcommand);
69    }
70    elsif ($subcommand eq "index-from-image") {
71       wrapper_print_privilege($subcommand);
72    }
73    elsif ($subcommand eq "restore") {
74       wrapper_print_privilege($subcommand);
75    }
76    elsif ($subcommand eq "print-command") {
77       wrapper_print_privilege($subcommand);
78    }
79    else {
80       printf STDERR "Unknown command `$subcommand'.\n";
81       exit 1;
82    }
83    if(defined($user_default) && defined($group_default)) {
84       print "USER $user_default\n";
85       print "GROUP $group_default\n";
86       exit 0;
87    }
88    exit 0;
89 }
90
91
92 sub wrapper_print_privilege {
93    my($command) = @_;
94    $command =~ s/-/_/g;
95    my($var_user) = "user_$command";
96    my($var_group) = "group_$command";
97    if(defined($$var_user) && defined($$var_group)) {
98       print "USER $$var_user\n";
99       print "GROUP $$var_group\n";
100       exit 0;
101    }
102    elsif(defined($$var_user) && !defined($$var_group)) {
103       print STDERR "\$$var_user defined but \$$var_group not defined\n";
104       exit 1;
105    }
106    elsif(!defined($$var_user) && defined($$var_group)) {
107       print STDERR "\$$var_group defined but \$$var_user not defined\n";
108       exit 1;
109    }
110 }
111
112 sub wrapper_support() {
113    if(defined(&command_support)) {
114       command_support();
115       exit 0;
116    }
117    my($subcommand) = $ARGV[1];
118    if ($subcommand eq "level-incrementals") {
119       if (defined($level_incrementals)) {
120          print "$level_incrementals\n";
121       }
122       else {
123          print "1\n";
124       }
125       exit 0;
126    }
127    elsif ($subcommand eq "index") {
128       my($index_generation);
129       foreach $index_generation (@index_generation) {
130          if( $index_generation eq "direct" ||
131              $index_generation eq "parse"  ||
132              $index_generation eq "output" ||
133              $index_generation eq "image") {
134                 print "$index_generation\n";
135          }
136          else {
137             print "unknow indexing method '$index_generation'\n";
138          }
139       }
140    exit 0;
141    }
142    elsif ($subcommand eq "parse-estimate") {
143       my($parse_estimate);
144       foreach $parse_estimate (@parse_estimate) {
145          if( $parse_estimate eq "direct" ||
146              $parse_estimate eq "parse" ) {
147             print "$parse_estimate\n";
148          }
149          else {
150             print "unknow parse-estimate method '$parse_estimate'\n";
151          }
152       }
153    exit 0;
154    }
155    elsif ($subcommand eq "parse-backup") {
156       print "direct\n" if (defined($parse_backup_direct));
157       print "parse\n"  if (defined($parse_backup_parse));
158       my($parse_backup);
159       foreach $parse_backup (@parse_backup) {
160          if( $parse_backup eq "direct" ||
161              $parse_backup eq "parse" ) {
162             print "$parse_backup\n";
163          }
164          else {
165             print "unknow parse-backup method '$parse_backup'\n";
166          }
167       }
168       exit 0;
169    }
170    else {
171       exit 1;
172    }
173 }
174
175 sub wrapper_selfcheck() {
176    if(defined(&command_selfcheck)) {
177       command_selfcheck();
178    }
179    else {
180       exit 1;
181    }
182 }
183
184 sub wrapper_estimate() {
185    my($estimate_type) = $ARGV[1];
186    my($option);
187    my($estimate_type_is_ok) = 0;
188    my($backups_type);
189    foreach $backups_type (@backup_type) {
190       $estimate_type_is_ok = 1 if($estimate_type eq $backups_type);
191    }
192    if($estimate_type_is_ok == 0) {
193       print "estimate type `$estimate_type' not supported.\n";
194       exit 3;
195    }
196    $option = 3 if ($estimate_type eq "full");
197    $option = 4 if ($estimate_type eq "level");
198    $option = 4 if ($estimate_type eq "diff");
199    parse_options($option);
200    if($option_estimate_direct + $option_estimate_parse > 1) {
201       print "Can't define both `estimate-direct' and `estimate-parse'.\n";
202       exit 5;
203    }
204    elsif($option_estimate_direct + $option_estimate_parse == 0) {
205       print "You must have the option `estimate-direct' or `estimate-parse'.\n";
206       exit 5;
207    }
208    if($estimate_type eq "full") {
209       command_estimate_full($ARGV[2]);
210    }
211     elsif($estimate_type eq "level") {
212       command_estimate_level($ARGV[2], $ARGV[3]);
213    }
214    elsif($estimate_type eq "diff") {
215       command_estimate_diff($ARGV[2], $ARGV[3]);
216    }
217 }
218
219 sub wrapper_estimate_parse() {
220    if(defined(&command_estimate_parse)) {
221       command_estimate_parse();
222    }
223    else {
224       printf STDERR "`estimate-parse' is not supported.\n";
225       exit 1;
226    }
227 }
228
229 sub wrapper_backup() {
230    my($backup_type) = $ARGV[1];
231    my($option);
232    my($backup_type_is_ok) = 0;
233    my($backups_type);
234    foreach $backups_type (@backup_type) {
235       $backup_type_is_ok = 1 if($backup_type eq $backups_type);
236    }
237    if($backup_type_is_ok == 0) {
238       print "backup type `$backup_type' not supported.\n";
239       exit 3;
240    }
241    $option = 3 if ($backup_type eq "full");
242    $option = 4 if ($backup_type eq "level");
243    $option = 4 if ($backup_type eq "diff");
244    parse_options($option);
245    if($option_backup_direct + $option_backup_parse > 1) {
246       print "Can't define both `backup-direct' and `backup-parse'.\n";
247       exit 5;
248    }
249    elsif($option_backup_direct + $option_backup_parse == 0) {
250       print "You must have the option `backup-direct' or `backup-parse'.\n";
251       exit 5;
252    }
253    if($backup_type eq "full") {
254       command_backup_full($ARGV[2]);
255    }
256    elsif($backup_type eq "level") {
257       command_backup_level($ARGV[2], $ARGV[3]);
258    }
259    elsif($backup_type eq "diff") {
260       command_backup_diff($ARGV[2], $ARGV[3]);
261    }
262 }
263
264 sub wrapper_backup_parse() {
265    if(defined(&command_backup_parse)) {
266       command_backup_parse();
267    }
268    else {
269       printf STDERR "`backup-parse' is not supported.\n";
270       exit 1;
271    }
272 }
273
274 sub wrapper_index_from_output() {
275    if(defined(&command_index_from_output)) {
276       command_index_from_output();
277    }
278    else {
279       printf STDERR "`index-from-output' is not supported.\n";
280       exit 1;
281    }
282 }
283
284 sub wrapper_index_from_image() {
285    if(defined(&command_index_from_image)) {
286       command_index_from_image();
287    }
288    else {
289       printf STDERR "command `index-from-image' is not supported.\n";
290       exit 1;
291    }
292 }
293
294 sub wrapper_restore() {
295    if(defined(&command_restore)) {
296       command_restore();
297    }
298    else {
299      printf STDERR "`restore' is not supported.\n";
300      exit 1;
301    }
302 }
303
304 sub wrapper_print_command() {
305    if(defined(&command_print_command)) {
306       command_print_command();
307    }
308    else {
309       printf STDERR "`print-command' is not supported.\n";
310       exit 1;
311    }
312 }
313
314
315 sub parse_options() {
316    my($no_option) = @_;
317    my($options, @options, $option, $name, $option_name, $value);
318
319    while($no_option <= $#ARGV) {
320       $options = $ARGV[${no_option}];
321       @options = split (/;/,$options);
322       foreach $option (@options) {
323          if( $option =~ /=/ ) {
324             ($name,$value) = split(/=/,$option);
325          }
326          else {
327             $name  = $option;
328             $value = 1;
329          }
330          $option_name = "option_$name";
331          $option_name =~ s/\-/\_/g;
332          $$option_name = $value;
333       }
334       $no_option++;
335    }
336 }
337
338 sub check_file {
339    my($filename, $mode) = @_;
340
341    stat($filename);
342
343    if($mode eq "e") {
344       if( -e _ ) {
345          print "OK $filename exists\n";
346       }
347       else {
348          print "ERROR [can not find $filename]\n";
349       }
350    }
351    elsif($mode eq "x") {
352       if( -x _ ) {
353          print "OK $filename executable\n";
354       }
355       else {
356          print "ERROR [can not execute $filename]\n";
357       }
358    }
359    elsif($mode eq "r") {
360       if( -r _ ) {
361          print "OK $filename readable\n";
362       }
363       else {
364          print "ERROR [can not read $filename]\n";
365       }
366    }
367    elsif($mode eq "w") {
368       if( -w _ ) {
369          print "OK $filename writable\n";
370       }
371       else {
372          print "ERROR [can not write $filename]\n";
373       }
374    }
375    else {
376       print "ERROR [check_file: unknow mode $mode]\n";
377    }
378 }
379
380 sub check_dir {
381 }
382
383 sub check_suid {
384 }
385
386 1;