1 |
diff -Nur -x '*.orig' -x '*.rej' smeserver-zabbix-server-0.1/root/etc/e-smith/db/configuration/migrate/zabbix-server-database mezzanine_patched_smeserver-zabbix-server-0.1/root/etc/e-smith/db/configuration/migrate/zabbix-server-database |
2 |
--- smeserver-zabbix-server-0.1/root/etc/e-smith/db/configuration/migrate/zabbix-server-database 2009-02-02 21:01:58.000000000 +0100 |
3 |
+++ mezzanine_patched_smeserver-zabbix-server-0.1/root/etc/e-smith/db/configuration/migrate/zabbix-server-database 2009-02-11 09:40:44.000000000 +0100 |
4 |
@@ -1,11 +1,33 @@ |
5 |
{ |
6 |
- use MIME::Base64 qw(encode_base64); |
7 |
+ my $rec = $DB->get('zabbix-server') |
8 |
+ || $DB->new_record('zabbix-server', {type => 'service'}); |
9 |
+ my $pw = $rec->prop('DbPassword'); |
10 |
+ if (not $pw or length($pw) < 57) |
11 |
+ { |
12 |
+ use MIME::Base64 qw(encode_base64); |
13 |
|
14 |
- my $rec = $DB->get('zabbix-server') || $DB->new_record('zabbix-server', {type => 'service'}); |
15 |
- |
16 |
- my $pw = $rec->prop('DbPassword'); |
17 |
- return "" if $pw; |
18 |
- |
19 |
- $rec->set_prop('DbPassword', sprintf("%15.0f", int( (1000000000000000) * rand() ))); |
20 |
-} |
21 |
+ $pw = "not set due to error"; |
22 |
+ if ( open( RANDOM, "/dev/urandom" ) ) |
23 |
+ { |
24 |
+ my $buf; |
25 |
+ # 57 bytes is a full line of Base64 coding, and contains |
26 |
+ # 456 bits of randomness - given a perfectly random /dev/random |
27 |
+ if ( read( RANDOM, $buf, 57 ) != 57 ) |
28 |
+ { |
29 |
+ warn("Short read from /dev/random: $!"); |
30 |
+ } |
31 |
+ else |
32 |
+ { |
33 |
+ $pw = encode_base64($buf); |
34 |
+ chomp $pw; |
35 |
+ } |
36 |
+ close RANDOM; |
37 |
+ } |
38 |
+ else |
39 |
+ { |
40 |
+ warn "Could not open /dev/urandom: $!"; |
41 |
+ } |
42 |
+ $rec->set_prop('DbPassword', $pw); |
43 |
+ } |
44 |
+} |
45 |
|