/usr/share/perl5/CipUX/Object/Action/Create.pm is in libcipux-object-perl 3.4.0.5-2build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 | # +==========================================================================+
# || CipUX::Object::Action::Create ||
# || ||
# || CipUX Object Layer Class ||
# || ||
# || Copyright (C) 2007 - 2009 by Christian Kuelker. All rights reserved! ||
# || ||
# || License: GNU GPL - GNU General Public License version 2 or any later ||
# || version. ||
# +==========================================================================+
# $Id: Create.pm 5011 2010-07-30 23:31:16Z christian-guest $
# $Revision: 5011 $
# $HeadURL$
# $Date: 2010-07-31 01:31:16 +0200 (Sat, 31 Jul 2010) $
# $Source$
package CipUX::Object::Action::Create;
use 5.008001;
use strict;
use warnings;
use Carp;
use Class::Std;
use CipUX::Storage;
use Crypt::SmbHash qw(lmhash nthash);
use Data::Dumper;
use English qw( -no_match_vars);
use Hash::Merge qw( merge );
use Log::Log4perl qw(:easy);
use Readonly;
use base qw(CipUX::Object::Action);
{ # BEGIN CLASS
use version; our $VERSION = qv('3.4.0.5');
use re 'taint'; # Keep data captured by parens tainted
# +======================================================================+
# || CONSTANTS ||
# +======================================================================+
Readonly::Scalar my $EMPTY_STRING => q{};
# +======================================================================+
# || INIT ARGS ||
# +======================================================================+
#my %cfg_of :ATTR( init_arg => 'cfg'); # store conif file name
# +=======================================================================+
# || GLOBAL VARS ||
# +=======================================================================+
my $cfg_object_hr;
my $cfg_coupling_hr;
# +=======================================================================+
# || object ||
# +=======================================================================+
sub create_object_action {
# +------------------------------------------------------------------+
# | API
my ( $self, $arg_r ) = @_;
my $action
= exists $arg_r->{action}
? $self->l( $arg_r->{action} )
: $self->perr('action');
my $type
= exists $arg_r->{type}
? $self->l( $arg_r->{type} )
: $self->perr('type');
my $attr_hr
= exists $arg_r->{attr_hr} ? $self->h( $arg_r->{attr_hr} ) : {};
my $object
= exists $arg_r->{object}
? $self->l( $arg_r->{object} )
: $self->perr('object');
my $overwrite_hr
= exists $arg_r->{overwrite_hr}
? $self->h( $arg_r->{overwrite_hr} )
: {};
foreach my $p (qw(object type action)) {
if ( not defined $arg_r->{$p} ) {
$self->exc( { msg => 'parameter not defined', value => $p } );
}
}
# +------------------------------------------------------------------+
# | main
my $logger = get_logger(__PACKAGE__);
$logger->debug( 'action: ', $action );
$logger->debug( 'type: ', $type );
$logger->debug( 'object: ', $object );
$logger->debug('cfg: load cfg');
$cfg_coupling_hr = $self->get_coupling_cfg();
$cfg_object_hr = $self->get_object_cfg();
#if ( $debug > 128 and defined $attr_hr ) {
# my $msg = 'we got this dump as INPUT (sub object):';
# $logger->debug( { msg: => $msg } ,"\n");
# $self->var_dump( { var_r => $attr_hr, name => 'attr_hr' } );
#}
# list object types and check it
my $type_ar
= $self->list_type( { cfg_coupling_hr => $cfg_coupling_hr } );
my %type = ();
foreach my $t ( @{$type_ar} ) {
$type{$t} = 1;
$logger->debug( 'found type: ', $t );
}
if ( not defined $type{$type} ) {
$self->exc( { msg => 'unknown type', value => $type } );
}
# +---------------------------------------------------------------------+
# | create_object_action |
# +---------------------------------------------------------------------+
#my $overwrite_hr = $self->h( $arg_r->{overwrite_hr} )
# || $self->perr('overwrite_hr');
# TODO
#test_cfg( { cfg=>$config_hr0, task=>$task } );
my $add_ar = [];
#y @add = ();
# test if all mandatory attributes are given.
my $v_hr = $cfg_coupling_hr->{$type};
my $c_hr = {}; # create hash ref
#my $overwrite_hr = $v_hr->{overwrite};
# if ( $debug > 128 and defined $overwrite_hr ) {
# $self->var_dump(
# { var_r => $overwrite_hr, name => 'overwrite_hr' } );
#
# }
my $storage = CipUX::Storage->new();
# create every node in order:
# $o = cipux_account.group, cipux_account.user, ...
foreach my $o ( @{ $v_hr->{order} } ) { # for every object in 'order'
$logger->debug( 'object to create: ', $o );
# preset->auto->mandatory->rule->alias cascade
my $o_hr = $cfg_object_hr->{$o};
$logger->debug( 'href o_hr: ', $o_hr );
$c_hr->{$o} = $self->preset_auto_mandatory_rule_alias(
{
href => $o_hr,
vhref => $v_hr,
attr_hr => $attr_hr,
object => $object
}
);
# join attributes from different sources
# for now we have only one source, but this might change
my %merged = ( %{$c_hr} );
#if ( $debug > 128 ) {
# $self->var_dump( { name => 'merged', var_r => \%merged } );
#}
#my %merged2 = ();
# %{ $v_hr->{overwrite}->{$o} } :
# add overwrite attributes from CipUX::Object::Action::Create layer
# $cfg_coupling_hr->{overwrite}->{cipux_account.group};
# foreach cipux_account.group->attr, ...
# %{ $overwrite_hr->{$o} }
# add overwrite attributes from CipUX::Task layer
# foreach cipux_account.group->attr, ...
my %overwrite_task = ();
if ( exists $overwrite_hr->{$o} and defined $overwrite_hr->{$o} )
{
%overwrite_task = %{ $overwrite_hr->{$o} };
}
my %overwrite_object = ();
if ( defined $v_hr->{overwrite}->{$o} ) {
%overwrite_object = %{ $v_hr->{overwrite}->{$o} };
}
#C %merged2 = (
#C %{ $merged{$o} }, # calculated so far
#C %overwrite_object, # CipUX::Object::Action::Create overwrite
#C %overwrite_task, # CipUX::Task overwrite
#C );
$logger->debug('overwrite_hr from task:');
$logger->debug(
{ filter => \&Dumper, value => \%overwrite_task } );
$logger->debug('overwrite_hr from object:');
$logger->debug(
{ filter => \&Dumper, value => \%overwrite_object } );
$logger->debug('calculated overwrite:');
$logger->debug(
{ filter => \&Dumper, value => \%overwrite_object } );
Hash::Merge::set_behavior('RIGHT_PRECEDENT');
my %merged1 = %{ merge( $merged{$o}, \%overwrite_object ) };
my %merged2 = %{ merge( \%merged1, \%overwrite_task ) };
$logger->debug('merged overwrite:');
$logger->debug( { filter => \&Dumper, value => \%merged2 } );
# }elsif(defined()){
# %merged2 = (
# %{ $merged{$o} }, # calculated so far
# %{ $v_hr->{overwrite}->{$o} } # CipUX::Object::Action::Create overwrite
# );
# }
#if ( $debug > 128 ) {
# $self->var_dump( { name => 'merged', var_r => \%merged } );
#}
# add overwrite attributes from CipUX::Object::Action::Create layer
# $cfg_coupling_hr->{overwrite}->{cipux_account.group};
# foreach cipux_account.group->attr, ...
# foreach my $attr ( keys %{ $v_hr->{overwrite}->{$o} } ) {
# my $value = $v_hr->{overwrite}->{$o}->{$attr};
# my $msg = "overwrite from OBJECT [$o] attr [$attr]:=";
# $logger->debug($msg, $value ,"\n");
# $merged2{$attr} = $value;
# }
# add overwrite attributes from CipUX::Task layer
# foreach cipux_account.group->attr, ...
# foreach my $attr ( keys %{ $overwrite_hr->{$o} } ) {
# my $value = $overwrite_hr->{$o}->{$attr};
# my $msg = "overwrite from TASK [$o] attr [$attr]:=";
# $logger->debug($msg, $value ,"\n");
# $merged2{$attr} = $value;
# }
# do not need this meta info for creation
delete $merged2{struc_rdn};
# do not need this meta info for creation
delete $merged2{base_dn};
# do not need this meta info for creation
while ( delete $merged2{dn} ) {
$logger->debug( 'delete: ', 'dn' );
}
#if ( $debug > 128 ) {
# $self->var_dump( { name => 'merged2', var_r => \%merged2 } );
#}
# make a check for mandatory attributes, because it is better
# not partly creating a object (example: cipux_account.group OK,
# but cipux_account.user FAILED)
foreach my $m ( keys %{ $o_hr->{mandatory} } ) {
$logger->debug( 'check mandatory: ', $m, );
if ( not defined $merged2{$m} ) {
my $msg = 'This mandatory attribute is missing:';
$self->exc( { msg => $msg, value => $m } )
}
} ## end foreach my $m ( keys %{ $o_hr...
# will be executed later (push anon hash ref)
push @{$add_ar},
{
object_type_name => $o,
object_id => $object,
object_hr => \%merged2
};
} ## end foreach my $o ( @{ $v_hr->{...
#if ( $debug > 128 ) {
# $self->var_dump( { name => 'add_ar', var_r => $add_ar } );
#}
# and now try to execute the addition
# array_r of anon hash_rs
foreach my $a_hr ( @{$add_ar} ) {
# cipux_account.user
my $msg = 'object_type_name';
$logger->debug( $msg, $a_hr->{object_type_name} );
# login
$logger->debug( 'object_id: ', $a_hr->{object_id} );
$logger->debug( 'object_hr: ', $a_hr->{object_hr} );
my $value_hr = $storage->add_node(
{
type => $a_hr->{object_type_name},
obj => $a_hr->{object_id},
attr_hr => $a_hr->{object_hr}
}
);
} ## end foreach my $a_hr ( @{$add_ar...
return 1;
} ## end sub create_object_action
# +=======================================================================+
# || preset ||
# +=======================================================================+
sub preset {
# +------------------------------------------------------------------+
# | API
my ( $self, $arg_r ) = @_;
my $href = $arg_r->{href};
# +------------------------------------------------------------------+
# | main
my $logger = get_logger(__PACKAGE__);
$logger->debug('BEGIN');
#if ( $debug > 128 and defined $href ) {
# my $msg = 'we got this dump as result DEFAULT subroutine:';
# $logger->debug( { msg => $msg } ,"\n");
# #$self->var_dump( { var_r => $href, name => 'sub preset href' } );
#}
return $href;
} ## end sub preset
# +=======================================================================+
# || auto ||
# +=======================================================================+
sub auto {
# +------------------------------------------------------------------+
# | API
my ( $self, $arg_r ) = @_;
my $href = $arg_r->{href};
my $ahref = $arg_r->{ahref};
# values from CLI
my $attr_hr = $arg_r->{attr_hr};
# +------------------------------------------------------------------+
# | main
my $logger = get_logger(__PACKAGE__);
$logger->debug('BEGIN');
my $storage = CipUX::Storage->new();
my $cfg_basis_hr = $self->get_basis_cfg();
foreach my $var ( keys %{$ahref} ) {
#if ( $debug > 2 ) {
# my $msg = "auto: set [$var]:=";
# $logger->debug( $msg, $ahref->{$var} } ,"\n");
#}
# TODO: delete section? this might be done after: list_type
if ( $var eq 'struc_rdn' ) {
$ahref->{$var} = [];
push @{ $ahref->{$var} }, 'ou=room'; # TODO
my $msg = 'auto: struc_rdn:=';
$logger->debug( $msg, $ahref->{$var} );
}
elsif ( $var eq 'base_dn' ) {
$ahref->{$var} = [];
push @{ $ahref->{$var} }, 'dc=nodomain'; # TODO
my $msg = 'auto: base_dn:=';
$logger->debug( $msg, $ahref->{$var} );
}
elsif ( $var eq 'uidNumber' ) {
my $oid_number = $storage->oid_number_supremum(
{ cfg_basis_hr => $cfg_basis_hr } );
$ahref->{$var} = [];
push @{ $ahref->{$var} }, $oid_number;
my $msg = 'auto: uidNumber:=';
$logger->debug( $msg, $ahref->{$var} );
}
elsif ( $var eq 'gidNumber' ) {
my $oid_number = $storage->oid_number_supremum(
{ cfg_basis_hr => $cfg_basis_hr } );
$ahref->{$var} = [];
push @{ $ahref->{$var} }, $oid_number;
my $msg = 'auto: gidNumber:=';
$logger->debug( $msg, $ahref->{$var} );
}
elsif ( $var eq 'userPassword' ) {
# if defined $attr_hr->{userPassword}
# and ref( $attr_hr->{userPassword} ) eq 'ARRAY' <---- CLI
# elsif defined $attr_hr->{userPassword} <---- RPC
# else set it <---- RND
$attr_hr->{userPassword}
= ( defined $attr_hr->{userPassword}
and ref( $attr_hr->{userPassword} ) eq 'ARRAY' )
? $attr_hr->{userPassword}->[0]
: defined $attr_hr->{userPassword}
? $attr_hr->{userPassword}
: $self->random_password();
$ahref->{$var} = [];
my $password_hash
= $self->hash_password(
{ mode => 'crypt', password => $attr_hr->{userPassword} }
);
push @{ $ahref->{$var} }, '{crypt}' . $password_hash;
}
elsif ( $var eq 'sambaLMPassword' ) {
$attr_hr->{userPassword}
= ( defined $attr_hr->{userPassword}
and ref( $attr_hr->{userPassword} ) eq 'ARRAY' )
? $attr_hr->{userPassword}->[0]
: defined $attr_hr->{userPassword}
? $attr_hr->{userPassword}
: $self->random_password();
my $lm = lmhash( $attr_hr->{userPassword} );
$ahref->{$var} = [];
push @{ $ahref->{$var} }, $lm;
}
elsif ( $var eq 'sambaNTPassword' ) {
$attr_hr->{userPassword}
= ( defined $attr_hr->{userPassword}
and ref( $attr_hr->{userPassword} ) eq 'ARRAY' )
? $attr_hr->{userPassword}->[0]
: defined $attr_hr->{userPassword}
? $attr_hr->{userPassword}
: $self->random_password();
my $nt = nthash( $attr_hr->{userPassword} );
$ahref->{$var} = [];
push @{ $ahref->{$var} }, $nt;
}
elsif ( $var eq 'sambaSID' ) {
my $sid = $storage->get_sid();
my @uid = ();
if ( defined $ahref->{uidNumber} ) {
if ( ref $ahref->{uidNumber} eq 'ARRAY' ) {
@uid = @{ $ahref->{uidNumber} };
}
else {
push @uid, $ahref->{uidNumber};
}
}
elsif ( defined $ahref->{gidNumber} ) {
if ( ref $ahref->{uidNumber} eq 'ARRAY' ) {
@uid = @{ $ahref->{gidNumber} };
}
else {
push @uid, $ahref->{gidNumber};
}
}
if ( scalar(@uid) == 0 ) {
my $msg = 'No uidNumber or gidNumber available.';
$msg .= ' It is not possible to calculate';
$msg .= ' sambaSID value as auto value from ';
$msg .= ' cipux-samba-object.conf.';
confess($msg);
}
$sid = sprintf( "%s-%s", $sid, int( $uid[0] ) * 2 + 1000 );
$ahref->{$var} = [];
push @{ $ahref->{$var} }, $sid;
}
elsif ( $var eq 'cipuxCreationDate' ) {
$ahref->{$var} = [];
push @{ $ahref->{$var} }, $self->date_time( { today => 1 } );
my $msg = 'auto: set attr cipuxCreationDate:=';
$logger->debug( $msg, $ahref->{$var} );
}
elsif( $var eq 'sambaPwdLastSet'){
$ahref->{$var} = [];
push @{ $ahref->{$var} }, $self->date_epoch( { today => 1 } );
my $msg = 'auto: set attr sambaPwdLastSet:=';
$logger->debug( $msg, $ahref->{$var} );
}
else {
my $msg = 'auto: unknown auto variable';
$self->exc( { msg => $msg, value => $var } );
}
} ## end foreach my $var ( keys %{$ahref...
# 1: auto values (ahref) will overwrite href values
# 2: CLI (-x) will not be merge here (attr_href)
# They will be merged in sub mandatory
my %merge = ( %{$href}, %{$ahref} );
#if ( $debug > 128 ) {
# my $msg = 'we got this dump as result AUTO subroutine:';
# $logger->debug( { msg => $msg } ,"\n");
# $self->var_dump( { var_r => \%merge, name => 'merge' } );
#}
return \%merge
} ## end sub auto
# +=======================================================================+
# || mandatory ||
# +=======================================================================+
sub mandatory {
# +------------------------------------------------------------------+
# | API
my ( $self, $arg_r ) = @_;
# attributes calculated so far, and values from auto section
my $href = $arg_r->{href};
# mandatory section of object_node_name of config file
# Example: cipux_account.user->mandatory (cipuxFirstname, ...)
my $mhref = $arg_r->{mhref};
# new cn (object_id) from command line -o
my $object
= exists $arg_r->{object}
? $self->l( $arg_r->{object} )
: $self->perr('object');
# object_attr section from object_type_name
# Example: cipux_account->object_attr (uid,cn,...)
my $obj_attr_ar = $arg_r->{obj_attr_ar};
# -x from CLI
my $attr_hr = $arg_r->{attr_hr};
# +------------------------------------------------------------------+
# | main
my $logger = get_logger(__PACKAGE__);
$logger->debug('BEGIN');
$logger->debug( 'mandatory: object: ', $obj_attr_ar );
$logger->debug( 'obj_attr_ar: ',
{ filter => \&Dumper, value => $obj_attr_ar } );
# all mand. obj: uid, cipuxFirstname, ...
# TODO: If not all mandatory attributes of an object in
# cipux-object.conf are provided, we got
# here the problem, that mhref will not iterate over given CLI
# options (-x ATTR=VALUE). This given CLI options will
# therefore NOT be merged! (1) test if this is also true for
# other given CLI options (2) find a solution to overcome this
# by (2a) make this in config obsolete or (2b) write a test for
# it with exceptions.
foreach my $var ( keys %{$mhref} ) {
#if ( $debug > 1 ) {
# my $msg = "mandatory: process [$var]:=";
# $logger->debug($msg, $mhref->{$var} ,"\n");
#}
# all CLI -o replace objects: uid, cn, ...
# This only works if this is also a mandatory object
foreach my $o ( @{$obj_attr_ar} ) {
my $msg
= "mandatory: check for CLI object: is [$var] eq [$o]?";
$logger->debug( { msg => $msg } );
if ( $o eq $var ) {
my $msg = 'mandatory: yes! found replacement from -o ';
$logger->debug( $msg, $var );
# replace existing mand. obj with -o value
$href->{$var} = [];
push @{ $href->{$var} }, $object;
}
elsif ( defined $attr_hr->{$var} ) {
my $msg = 'mandatory: yes! found replacement from -x ';
$logger->debug( $msg, $var );
$href->{$var} = $attr_hr->{$var};
}
else {
my $msg = 'mandatory: no! obj and CLI (-o or -x) ';
$msg .= 'do not match';
$logger->debug( { msg => $msg } );
}
} ## end foreach my $o ( @{$obj_attr_ar...
} ## end foreach my $var ( keys %{$mhref...
#my %merge = ( %{$href}, %{$mhref} );
my %merge = ( %{$href} );
#if ( $debug > 128 ) {
# my $msg = 'we got this dump as result MANDATORY subroutine:';
# $logger->debug( { msg => $msg } ,"\n");
# $self->var_dump( { var_r => \%merge, name => 'merge' } );
#}
return \%merge;
} ## end sub mandatory
# +=======================================================================+
# || rule ||
# +=======================================================================+
sub rule {
# +------------------------------------------------------------------+
# | API
my ( $self, $arg_r ) = @_;
# attributes calculated so far, and values from mandatory section
my $href = $arg_r->{href};
# rule section of object_node_name of config file
# Example: cipux_account.user->rule (dn, homeDirectory, ...)
my $rhref = $arg_r->{rhref};
# +------------------------------------------------------------------+
# | main
my $logger = get_logger(__PACKAGE__);
$logger->debug('BEGIN');
# for every rule attribute (dn, homeDriectory, ...
foreach my $var ( keys %{$rhref} ) {
$logger->debug( 'rule attribute: ', $var );
$logger->debug( '\$rhref->{\$var}: ',
{ filter => \&Dumper, value => $rhref->{$var} } );
my $rule = undef;
if ( ref( $rhref->{$var} ) eq 'ARRAY' ) {
$rule = join $EMPTY_STRING, @{ $rhref->{$var} };
}
else {
$rule = $rhref->{$var};
}
next if not defined $rule;
$logger->debug( '\$rule: ',
{ filter => \&Dumper, value => $rule } );
my $replacement = $rule;
# TODO: Bad data
while ( $rule =~ m/<([^>]+?)>/gxsm ) {
my $attr = $1;
my $value = $href->{$attr};
if ( not defined $rule ) {
my $msg = 'Tryed to replace non-existing RULE ';
$msg .= 'in subroutine [rule]. The attribute was:';
$self->exc( { msg => $msg, value => $attr } );
}
$logger->debug( 'rule: ', $rule );
if ( not defined $attr ) {
my $msg = 'Tryed to replace non-existing ATTRIBUTE ';
$msg .= 'in subroutine [rule]. Rule was: ';
$self->exc( { msg => $msg, value => $rule } );
}
$logger->debug( 'attr: ', $attr );
if ( not defined $value ) {
my $msg = 'Tryed to replace non-existing VALUE ';
$msg .= 'in subroutine [rule] for rule ';
$msg .= "[$rule]. The attribute was: [$attr]. ";
$msg .= '(if you are using the command line, ';
$msg .= 'you may define the value with: ';
$msg .= "-x $attr=VALUE)";
$self->exc( { msg => $msg } );
} ## end if ( not defined $value)
$logger->debug( 'value: ', $value );
if ( ref($value) eq 'ARRAY' ) {
$value = join q{ }, @{$value};
}
$replacement =~ s/<$attr>/$value/gmxe;
$logger->debug("replace [<$attr>] with [$value]");
} ## end while ( $rule =~ m/<([^>]+?)>/gxsm)
#if ( $debug > 1 ) {
# my $msg = "rule: ... with replacement [$var]:=";
# $logger->debug($msg, $replacement ,"\n");
#}
$rhref->{$var} = [];
push @{ $rhref->{$var} }, $replacement; # remember this
$logger->debug("replacement [$replacement]");
} ## end foreach my $var ( keys %{$rhref...
my %merge = ( %{$href}, %{$rhref} );
#if ( $debug > 128 ) {
# my $msg = 'we got this dump as result RULE subroutine:';
# $logger->debug( { msg => $msg } ,"\n");
# $self->var_dump( { var_r => \%merge, name => 'merge' } );
#}
$logger->debug( '\%merge: ',
{ filter => \&Dumper, value => \%merge } );
return \%merge;
} ## end sub rule
# +=======================================================================+
# || alias ||
# +=======================================================================+
sub alias {
# +------------------------------------------------------------------+
# | API
my ( $self, $arg_r ) = @_;
# attr values processed so far
my $href = $arg_r->{href};
# alias section of config file
my $phref = $arg_r->{phref};
# +------------------------------------------------------------------+
# | main
my $logger = get_logger(__PACKAGE__);
$logger->debug('BEGIN');
foreach my $var ( keys %{$phref} ) {
my $msg = "alias: is href [$var] defined?";
$logger->debug( { msg => $msg } );
if ( defined $href->{ $phref->{$var} } ) {
my $msg = "alias: yes! set [$var]:=";
my $value = $href->{ $phref->{$var} };
$href->{$var} = $value;
$logger->debug( $msg, $value );
} ## end if ( defined $href->{ ...
} ## end foreach my $var ( keys %{$phref...
# foreach my $var ( keys %{$href} ) {
# my $msg = 'alias ['.$var.']:=['.join('][',@{$href->{$var}}).']';
# if(defined($phref->{$var})){
# $msg .=':=['.join('][',@{$phref->{$var}}).']';
# }
# $logger->debug( { msg => $msg } ,"\n");
# }
#my %merge = ( %{$href}, %{$phref} );
my %merge = ( %{$href} );
#if ( $debug > 128 ) {
# my $msg = 'we got this dump as result ALIAS subroutine:';
# $logger->debug( { msg => $msg } ,"\n");
# $self->var_dump( { var_r => \%merge, name => 'merge' } );
#}
return \%merge;
} ## end sub alias
# +=======================================================================+
# || preset_auto_mandatory_rule_alias ||
# +=======================================================================+
sub preset_auto_mandatory_rule_alias {
# +------------------------------------------------------------------+
# | API
my ( $self, $arg_r ) = @_;
my $o_hr = $arg_r->{href} || $self->perr('href');
my $v_hr = $arg_r->{vhref} || $self->perr('vhref');
# -o ID from CLI
my $object = $arg_r->{object} || $self->perr('object');
# -x attr=values from CLI
my $attr_hr = $arg_r->{attr_hr} || $self->perr('attr_hr');
# +------------------------------------------------------------------+
# | main
my $logger = get_logger(__PACKAGE__);
$logger->debug('BEGIN');
$logger->debug( 'href: ', $o_hr );
$logger->debug( 'vhref: ', $v_hr );
$logger->debug( 'object: ', $object );
if ( defined $attr_hr ) {
$logger->debug( 'attr_hr: ', $attr_hr );
}
my $cfg_basis_hr = $self->get_basis_cfg();
# DEFAULT
my $d_hr = $self->preset( { href => $o_hr->{preset} } );
# AUTO
my $a_hr = $self->auto(
{
href => $d_hr,
ahref => $o_hr->{auto},
cfg_basis_hr => $cfg_basis_hr,
# used only for testing, getting but not modifying
attr_hr => $attr_hr,
}
);
# MANDATORY
my $m_hr = $self->mandatory(
{
# auto_hr
href => $a_hr,
# object attributes for -o
obj_attr_ar => $v_hr->{object_attr},
# ID from -o CLI
object => $object,
# mandatory part of config
# You have to add ALL mandatory attributes, or
# sub mandatory will fail
mhref => $o_hr->{mandatory},
# attr values from CLI, will be merged here
attr_hr => $attr_hr
}
);
# RULE
my $r_hr = $self->rule(
{
href => $m_hr, # mandatory_hr
rhref => $o_hr->{rule}
}
);
# ALIAS
my $p_hr = $self->alias(
{
href => $r_hr,
phref => $o_hr->{alias}
}
);
return $p_hr;
} ## end sub preset_auto_mandatory_rule_alias
} # END INSIDE-OUT CLASS
1;
__END__
=pod
=head1 NAME
CipUX::Object::Action::Create - Object layer class for CipUX
=head1 VERSION
version 3.4.0.5
=head1 SYNOPSIS
use CipUX::Object::Action::Create;
=head1 DESCRIPTION
Provides the functions cipux_object_create
as well as some auto-calculated values for example for userPassword.
The function cipux_object_create may create one or several LDAP nodes
according to the configuration structure in /etc/cipux/cipux-object.conf
or ~/.cipux/cipux-object.conf.
=head1 SUBROUTINES/METHODS
The following functions will be exported by CipUX::Object::Action::Create.
=head2 new
Constructor
B<Syntax:>
my $cipux_object = CipUX::Object::Action::Create->new({});
=head2 preset
Creates a CipUX object
B<Syntax:>
$object->preset({ });
=head2 auto
Creates a CipUX object
B<Syntax:>
$object->auto({ });
=head2 mandatory
Creates a CipUX object
B<Syntax:>
$object->mandatory({ });
=head2 rule
Creates a CipUX object
B<Syntax:>
$object->rule({ });
=head2 alias
Creates a CipUX object
B<Syntax:>
$object->alias({ });
=head2 preset_auto_mandatory_rule_alias
Creates a CipUX object
B<Syntax:>
$object->preset_auto_mandatory_rule_alias({
});
=head2 create_object_action
TODO
=head2 oid_number_supremum
TODO
=head1 DIAGNOSTICS
TODO
=head1 CONFIGURATION AND ENVIRONMENT
TODO
=head1 DEPENDENCIES
Carp
Class:Std
=head1 INCOMPATIBILITIES
Not known.
=head1 BUGS AND LIMITATIONS
Not known.
=head1 SEE ALSO
See the CipUX web page and the manual at L<http://www.cipux.org>
See the mailing list L<http://sympa.cipworx.org/wws/info/cipux-devel>
=head1 AUTHOR
Christian Kuelker E<lt>christian.kuelker@cipworx.orgE<gt>
=head1 LICENSE AND COPYRIGHT
Copyright (C) 2007 - 2009 by Christian Kuelker
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA
=cut
|