%set %%username="rougail_test@silique.fr"
%set %%username_family="rougail_test@gnunux.info"
%set %%name_family="gnunux"
# Remote
%set %%acc = []
%for %%idx in %%range(3)
  %set %%name = 'remote_test' + %%str(%%idx)
%%acc.append(('cn=' + %%name + ',' + %%ldapclient_base_dn, %%get_password(server_name=%%domain_name_eth0, username=%%name, description="remote account", type="cleartext", hide=%%hide_secret, temporary=True)))%slurp
%end for
%for %%remote in %%accounts.remotes
 %set %%name = %%normalize_family(%%remote)
%%acc.append((%%accounts['remote_' + %%name]['dn_' + %%name], %%accounts['remote_' + %%name]['password_' + %%name]))%slurp
%end for
%for %%dn, %%password in %%acc
dn: %%dn
changetype: modify
replace: userPassword
userPassword:: %%ssha_encode(%%password)

%end for
# Users
%set %%userdn = 'cn=' + %%username + ',' + %%calc_ldapclient_base_dn(%%ldapclient_base_dn)
%set %%userfamilydn = 'cn=' + %%username_family + ',' + %%calc_ldapclient_base_dn(%%ldapclient_base_dn, family_name=%%name_family)
%set %%acc = [(%%userdn, %%username, ['alias_' + %%username]),
              (%%userfamilydn, %%username_family, ['alias_' + %%username_family]),
              ]
%set groups = {'users': [%%userdn],
               %%name_family: [%%userfamilydn],
			   }
%set %%users = %%ldapclient_user_dn
%for %%user in %%accounts.users.ldap_user_mail
%set %%userdn = 'cn=' + %%user + ',' + %%users
%%groups['users'].append(%%userdn)%slurp
%%acc.append((%%userdn, %%user, %%user.ldap_user_aliases))%slurp
%end for
%for %%family in %%accounts.families
  %set %%families = %%calc_ldapclient_base_dn(%%ldapclient_base_dn, %%family)
  %for %%user in %%accounts['family_' + %%family]['users_' + %%family]['ldap_user_mail_' + %%family]
%set %%userdn = 'cn=' + %%user + ',' + %%families
%%groups.setdefault(%%family, []).append(%%userdn)%slurp
%%acc.append((%%userdn, %%user, %%user['ldap_user_aliases_' + %%family]))%slurp
  %end for
%end for
%for %%userdn, %%user, %%aliases in %%acc
dn: %%userdn
changetype: modify
#add: objectClass
#objectClass: inetLocalMailRecipient
#-
replace: mailLocalAddress
mailLocalAddress: %%user
  %if %%aliases
    %for %%alias in %%aliases
mailLocalAddress: %%alias
    %end for
  %end if

%end for
# Groups
%set %%groupdn = %%ldapclient_group_dn
%for %%group, %%members in %%groups.items()
dn: cn=%%group,%%groupdn
changetype: modify
replace: member
 %for %%member in %%members
member: %%member
 %end for

%end for
