<html><body><div style="color:#000; background-color:#fff; font-family:HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif;font-size:16px"><div id="yui_3_16_0_1_1438526383040_69070"><span id="yui_3_16_0_1_1438526383040_69076">Wow, thank you so much for such a complete explanation. I appreciate the effort. I am out for the next day or so but will try and implement this as soon as I can.</span></div><div id="yui_3_16_0_1_1438526383040_69288"><span id="yui_3_16_0_1_1438526383040_69076">Thank you again and I will let you know the results.<br></span></div>  <div id="yui_3_16_0_1_1438526383040_69391" style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 16px;"> <div id="yui_3_16_0_1_1438526383040_69390" style="font-family: HelveticaNeue, Helvetica Neue, Helvetica, Arial, Lucida Grande, sans-serif; font-size: 16px;"> <div id="yui_3_16_0_1_1438526383040_69389" dir="ltr"> <hr size="1">  <font face="Arial" size="2"> <b><span style="font-weight:bold;">From:</span></b> Alexander Bokovoy <abokovoy@redhat.com><br> <b><span style="font-weight: bold;">To:</span></b> Justean <justeank@yahoo.com> <br><b><span style="font-weight: bold;">Cc:</span></b> "freeipa-users@redhat.com" <freeipa-users@redhat.com> <br> <b><span style="font-weight: bold;">Sent:</span></b> Wednesday, August 5, 2015 12:40 PM<br> <b><span style="font-weight: bold;">Subject:</span></b> Re: [Freeipa-users] Change default email format<br> </font> </div> <div id="yui_3_16_0_1_1438526383040_69392" class="y_msg_container"><br>On Wed, 05 Aug 2015, Alexander Bokovoy wrote:<br clear="none">>On Mon, 03 Aug 2015, Justean wrote:<br clear="none">>>Good morning, I was wondering if there is a way to change the way<br clear="none">>>freeipa builds a user's email address by default. Currently it takes<br clear="none">>>the username and appends the domain name but I would like it to take<br clear="none">>>the form <a shape="rect" ymailto="mailto:firstname.lastname@domainname.com" href="mailto:firstname.lastname@domainname.com">firstname.lastname@domainname.com</a><br clear="none">>It is not possible to redefine email's format via configuration so you<br clear="none">>need to write some code. Luckily, you can amend existing code without<br clear="none">>touching it.<br clear="none">><br clear="none">>Below is an example:<br clear="none">>-----------------------------------------------------------------------<br clear="none">>/usr/lib/python2.7/site-packages/ipalib/plugins/user-ext-mail-format.py<br clear="none">>-----------------------------------------------------------------------<br clear="none">>from ipalib.plugins.user import user_add<br clear="none">><br clear="none">>def override_default_mail_cb(self, ldap, dn, entry_attrs, attrs_list, *keys, **options):<br clear="none">>   if not 'mail' in entry_attrs:<br clear="none">>        name = {'givenname': entry_attrs.get('givenname').lower(),<br clear="none">>                'sn': entry_attrs.get('sn').lower()}<br clear="none">>        mail = "{givenname}.{sn}".format(**name)<br clear="none">>        entry_attrs['mail'] = self.obj.normalize_and_validate_email(mail)<br clear="none">>   return dn<br clear="none">><br clear="none">>user_add.register_pre_callback(override_default_mail_cb, first=True)<br clear="none">>-----------------------------------------------------------------------<br clear="none">><br clear="none">>What this Python code does? It adds a callback to user-add method in IPA<br clear="none">>that is run before other callbacks (first=True). The callback is then<br clear="none">>checks if mail attribute was already specified by the administrator<br clear="none">>when calling 'ipa user-add' (Web UI calls this for you). If not, it<br clear="none">>derives mail format from lower-cased versions of first and last names of<br clear="none">>the user (known as 'givenname' and 'sn' attributes in LDAP<br clear="none">>correspondingly). It then sets mail attribute to a full email format via<br clear="none">>self.obj.normalize_and_validate_email() function which will pick up the<br clear="none">>default DNS domain value and construct correct email.<br clear="none">><br clear="none">>You need to maintain this plugin extension on all IPA masters used for<br clear="none">>creating users. Best way to do that is by packaging the plugin in an RPM<br clear="none">>and installing it on IPA masters.<br clear="none">><br clear="none">>You also need to restart httpd service on IPA master to apply the<br clear="none">>plugin.<br clear="none">><br clear="none">>It is used like this:<br clear="none">><br clear="none">># systemctl restart httpd<br clear="none">># ipa user-add some.user --first Some --last User <br clear="none">>----------------------<br clear="none">>Added user "some.user"<br clear="none">>----------------------<br clear="none">> User login: some.user<br clear="none">> First name: Some<br clear="none">> Last name: User<br clear="none">> Full name: Some User<br clear="none">> Display name: Some User<br clear="none">> Initials: SU<br clear="none">> Home directory: /home/some.user<br clear="none">> GECOS: Some User<br clear="none">> Login shell: /bin/sh<br clear="none">> Kerberos principal: <a shape="rect" ymailto="mailto:some.user@EXAMPLE.COM" href="mailto:some.user@EXAMPLE.COM">some.user@EXAMPLE.COM</a><br clear="none">> Email address: <a shape="rect" ymailto="mailto:some.user@example.com" href="mailto:some.user@example.com">some.user@example.com</a><br clear="none">> UID: 1634400022<br clear="none">> GID: 1634400022<br clear="none">> Password: False<br clear="none">> Member of groups: ipausers<br clear="none">> Kerberos keys available: False<br clear="none">Actually, I realized because I gave the same user login as<br clear="none">'FirstName.LastName', it might be less apparent that the code works.<br clear="none">Let's try with another user:<br clear="none"><br clear="none"># ipa user-add foo.bar --first Some --last User <br clear="none">--------------------<br clear="none">Added user "foo.bar"<br clear="none">--------------------<br clear="none">  User login: foo.bar<br clear="none">  First name: Some<br clear="none">  Last name: User<br clear="none">  Full name: Some User<br clear="none">  Display name: Some User<br clear="none">  Initials: SU<br clear="none">  Home directory: /home/foo.bar<br clear="none">  GECOS: Some User<br clear="none">  Login shell: /bin/sh<br clear="none">  Kerberos principal: <a shape="rect" ymailto="mailto:foo.bar@EXAMPLE.COM" href="mailto:foo.bar@EXAMPLE.COM">foo.bar@EXAMPLE.COM</a><br clear="none">  Email address: <a shape="rect" ymailto="mailto:some.user@example.com" href="mailto:some.user@example.com">some.user@example.com</a><br clear="none">  UID: 1634400023<br clear="none">  GID: 1634400023<div class="qtdSeparateBR"><br><br></div><div class="yqt9792164078" id="yqtfd21560"><br clear="none">  Password: False<br clear="none">  Member of groups: ipausers<br clear="none">  Kerberos keys available: False<br clear="none"><br clear="none"><br clear="none">-- <br clear="none">/ Alexander Bokovoy<br clear="none"></div><br><br></div> </div> </div>  </div></body></html>