1 |
diff -Nur e-smith-lib-2.4.0.old.8943/root/usr/share/perl5/vendor_perl/esmith/util.pm e-smith-lib-2.4.0.8943/root/usr/share/perl5/vendor_perl/esmith/util.pm |
2 |
--- e-smith-lib-2.4.0.old.8943/root/usr/share/perl5/vendor_perl/esmith/util.pm 2015-06-18 21:51:44.062723966 +0200 |
3 |
+++ e-smith-lib-2.4.0.8943/root/usr/share/perl5/vendor_perl/esmith/util.pm 2015-06-22 03:04:11.449937443 +0200 |
4 |
@@ -21,7 +21,7 @@ |
5 |
use File::Basename; |
6 |
use File::stat; |
7 |
use FileHandle; |
8 |
- |
9 |
+use Data::UUID; |
10 |
=pod |
11 |
|
12 |
=head1 NAME |
13 |
@@ -901,6 +901,55 @@ |
14 |
|
15 |
=pod |
16 |
|
17 |
+=head2 set_secret() |
18 |
+ |
19 |
+Shortcut method to create and set a password property on a record without having to extract the record first. |
20 |
+ |
21 |
+The password creation is based on an UID of 64 bits (Data::UUID). If the optional type option is passed, |
22 |
+it will be used to create the record if it does not already exist. Otherwise, a default 'service' type |
23 |
+will be used to create the record. |
24 |
+ |
25 |
+The $DB is expected to be an already open esmith::DB object, so that an open DB in the caller can be re-used. |
26 |
+Therefore in a migrate fragment you could just use $DB. |
27 |
+ |
28 |
+ esmith::util::set_secret($DB, '$key','$property'[,type=>'$type']); |
29 |
+ |
30 |
+For example in /etc/e-smith/db/configuration/migrate/90roundcube |
31 |
+ { |
32 |
+ esmith::util::set_secret($DB, 'foo','DbPassword',type=>'service'); |
33 |
+ } |
34 |
+ |
35 |
+The password will be generated to the property 'DbPassword' in the 'foo' key. |
36 |
+ |
37 |
+If you want to change the database then you must open another esmith::DB objet |
38 |
+ { |
39 |
+ my $database = esmith::ConfigDB->open('accounts') or |
40 |
+ die esmith::DB->error; |
41 |
+ esmith::util::set_secret($database, 'foo','DbPassword',type=>'user'); |
42 |
+ } |
43 |
+ |
44 |
+=cut |
45 |
+ |
46 |
+sub set_secret |
47 |
+ |
48 |
+{ |
49 |
+ my ($db, $key, $prop, %options) = @_; |
50 |
+ %options = (type => 'service', %options); |
51 |
+ |
52 |
+ my $record = $db->get($key) || |
53 |
+ $db->new_record($key, \%options) or |
54 |
+ die "Error creating new record"; |
55 |
+ |
56 |
+ return if $db->get_prop($key,$prop); |
57 |
+ |
58 |
+ $record->merge_props(%options, $prop => |
59 |
+ Data::UUID->new->create_b64()); |
60 |
+} |
61 |
+ |
62 |
+ |
63 |
+ |
64 |
+=pod |
65 |
+ |
66 |
=head1 HIGH LEVEL PASSWORD UTILITIES |
67 |
|
68 |
High-level password-changing utilities. These utilities |
69 |
@@ -1324,6 +1373,7 @@ |
70 |
return 1; |
71 |
} |
72 |
|
73 |
+ |
74 |
=head1 AUTHOR |
75 |
|
76 |
Mitel Networks Corp. |