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 --- 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 +++ e-smith-lib-2.4.0.8943/root/usr/share/perl5/vendor_perl/esmith/util.pm 2015-06-22 03:04:11.449937443 +0200 @@ -21,7 +21,7 @@ use File::Basename; use File::stat; use FileHandle; - +use Data::UUID; =pod =head1 NAME @@ -901,6 +901,55 @@ =pod +=head2 set_secret() + +Shortcut method to create and set a password property on a record without having to extract the record first. + +The password creation is based on an UID of 64 bits (Data::UUID). If the optional type option is passed, +it will be used to create the record if it does not already exist. Otherwise, a default 'service' type +will be used to create the record. + +The $DB is expected to be an already open esmith::DB object, so that an open DB in the caller can be re-used. +Therefore in a migrate fragment you could just use $DB. + + esmith::util::set_secret($DB, '$key','$property'[,type=>'$type']); + +For example in /etc/e-smith/db/configuration/migrate/90roundcube + { + esmith::util::set_secret($DB, 'foo','DbPassword',type=>'service'); + } + +The password will be generated to the property 'DbPassword' in the 'foo' key. + +If you want to change the database then you must open another esmith::DB objet + { + my $database = esmith::ConfigDB->open('accounts') or + die esmith::DB->error; + esmith::util::set_secret($database, 'foo','DbPassword',type=>'user'); + } + +=cut + +sub set_secret + +{ + my ($db, $key, $prop, %options) = @_; + %options = (type => 'service', %options); + + my $record = $db->get($key) || + $db->new_record($key, \%options) or + die "Error creating new record"; + + return if $db->get_prop($key,$prop); + + $record->merge_props(%options, $prop => + Data::UUID->new->create_b64()); +} + + + +=pod + =head1 HIGH LEVEL PASSWORD UTILITIES High-level password-changing utilities. These utilities @@ -1324,6 +1373,7 @@ return 1; } + =head1 AUTHOR Mitel Networks Corp.