Merging multiple aliases files together

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Merging multiple aliases files together

Samuel Williams
I don't know the best way to achieve this.

I have some "user" packages which install various users on a linux
system. I want the setup to be entirely automated, and as part of this
I want to set up some mail aliases for each user, and add their alias
to the root alias. Essentially, the following represents one user:

root: bob
bob: [hidden email]

I have 0 or more of these user packages, and I want to, some how,
merge all these aliases together. So, if another user has `root:
dole`, the final entry would be equivalent to `root: bob, dole`.

I've got something working with augtool which updates the
/etc/postfix/aliases file. But, I don't really like this solution.

Ideally, I could just have something like /etc/postfix/aliases.d/bob
and newaliases would take care of the merging. It seems like it should
be possible, given how the database is updated, but I'm not really
sure how this should work. I tried reading the man pages of postalise
and newalias but it wasn't really obvious how I should do it.

And, perhaps there is a better way to achieve this?

Kind regards,
Samuel
Reply | Threaded
Open this post in threaded view
|

Re: Merging multiple aliases files together

Viktor Dukhovni

> On Mar 13, 2017, at 7:04 PM, Samuel Williams <[hidden email]> wrote:
>
> I have 0 or more of these user packages, and I want to, some how,
> merge all these aliases together. So, if another user has `root:
> dole`, the final entry would be equivalent to `root: bob, dole`.

Automatic combination of multiple results into a single comma-separated
outcome is a feature of the LDAP, MySQL and PgSQL table drivers.

Put your aliases into a database, and you'll get the automatic merging
of multiple lookup results.

--
        Viktor.

Reply | Threaded
Open this post in threaded view
|

Re: Merging multiple aliases files together

Samuel Williams
Thanks Viktor.

> Automatic combination of multiple results into a single comma-separated
outcome is a feature of the LDAP, MySQL and PgSQL table drivers.

> Put your aliases into a database, and you'll get the automatic merging
of multiple lookup results.

It's possible to achieve what I want just with one aliases file, but
the postalias tool for updating it doesn't merge records together in
any meaningful way and I don't know if it's possible using the current
implementation. The best thing I can think of is a custom tool to
merge those files.

I don't really want to add a full blown MySQL, PgSQL or LDAP daemon
for just 2-3 user accounts. It's not a primary function of the server
and adds a lot of overhead/surface area.

What would be nice if postalias could have a merge mode, which allows
multiple aliases files to be merged logically (e.g. same LHS, produce
ordered set union of RHS).
Reply | Threaded
Open this post in threaded view
|

Re: Merging multiple aliases files together

Samuel Williams
Just wondering, looking at the source code, it should be possible to
create a merge mode for postalias. Would you accept a PR for this? So
the use case would be something like

cat /etc/postfix/aliases /etc/postfix/aliases.d/* | postalias -Mi aliases

And it would merge together records if there were duplicates.

On 14 March 2017 at 12:34, Samuel Williams
<[hidden email]> wrote:

> Thanks Viktor.
>
>> Automatic combination of multiple results into a single comma-separated
> outcome is a feature of the LDAP, MySQL and PgSQL table drivers.
>
>> Put your aliases into a database, and you'll get the automatic merging
> of multiple lookup results.
>
> It's possible to achieve what I want just with one aliases file, but
> the postalias tool for updating it doesn't merge records together in
> any meaningful way and I don't know if it's possible using the current
> implementation. The best thing I can think of is a custom tool to
> merge those files.
>
> I don't really want to add a full blown MySQL, PgSQL or LDAP daemon
> for just 2-3 user accounts. It's not a primary function of the server
> and adds a lot of overhead/surface area.
>
> What would be nice if postalias could have a merge mode, which allows
> multiple aliases files to be merged logically (e.g. same LHS, produce
> ordered set union of RHS).
Reply | Threaded
Open this post in threaded view
|

Re: Merging multiple aliases files together

Viktor Dukhovni

> On Mar 13, 2017, at 7:56 PM, Samuel Williams <[hidden email]> wrote:
>
> Just wondering, looking at the source code, it should be possible to
> create a merge mode for postalias. Would you accept a PR for this? So
> the use case would be something like
>
> cat /etc/postfix/aliases /etc/postfix/aliases.d/* | postalias -Mi aliases
>
> And it would merge together records if there were duplicates.

Sorry, that's not sensible behaviour for postmap/postalias.  You
can use a Perl or Python script to generate a combined input stream,
much more easily than piling on C-code in postmap/postalias to
do the same thing.

--
        Viktor.

Reply | Threaded
Open this post in threaded view
|

Re: Merging multiple aliases files together

Noel Jones-2
In reply to this post by Samuel Williams
On 3/13/2017 6:34 PM, Samuel Williams wrote:
> I don't really want to add a full blown MySQL, PgSQL or LDAP daemon
> for just 2-3 user accounts. It's not a primary function of the server
> and adds a lot of overhead/surface area.

Consider using SQLite for this.  No daemon, minimal config, yet real
DBMS features.

http://www.postfix.org/SQLITE_README.html
http://www.postfix.org/sqlite_table.5.html

Or craft some perl pre-processor for newaliases.



  -- Noel Jones
Reply | Threaded
Open this post in threaded view
|

Re: Merging multiple aliases files together

Samuel Williams
Viktor, do you mind clarifying why you don't think it's sensible
behaviour? Like, what specifically is wrong with this approach?
Perhaps I'm missing something important.

I don't mind adding a script to merge aliases, and it may be what I
end up doing. I see both pros and cons with this approach. However,
after looking at postalias/postmap source code I realise that parsing
those files isn't trivial. Therefore, adding a -m option, which
trivially modifies the dictionary put logic into a dictionary merge
operation would make more sense from where I'm standing.

> piling on C-code in postmap/postalias to do the same thing.

I don't think it would be more than a few lines - if merging, when
duplicates are found, rather than printing a warning/error, you'd
concatenate the existing record with the new one.

Noel - adding SQLite3 is still a much larger surface area than aliases
alone, but I see it could be a solution. I don't actually want a DBMS,
I just want to add a few aliases. It won't grow beyond that. The
downside of this approach is that it necessitates changes to the main
postfix config, which I'd rather avoid, since this then needs to be
re-applied each time the postfix package is updated.

While working through this, I thought of one more situation where
modifying /etc/postfix/aliases isn't great - when you have a package
manager supplied set of defaults, but you want to add user-specific
ones. It would be nice to have a system supplied /etc/postfix/aliases,
plus any user specific ones, e.g. /etc/postfix/aliases.d/$username -
it would mean that upgrading the postfix package would work more
seamlessly as /etc/postfix/aliases could be updated without affecting
user supplied aliases.
Reply | Threaded
Open this post in threaded view
|

Re: Merging multiple aliases files together

Viktor Dukhovni

> On Mar 14, 2017, at 12:05 AM, Samuel Williams <[hidden email]> wrote:
>
> Viktor, do you mind clarifying why you don't think it's sensible
> behaviour? Like, what specifically is wrong with this approach?
> Perhaps I'm missing something important.

Poor orthogonality in tool design.  The postmap(1) and postalias(1)
utilities read key/value input and produce indexed tables with the
verbatim input they are fed.  Adding input data transformations is
not part of the job description.

--
        Viktor.