File: AuthDatabase.Dict.txt

package info (click to toggle)
dovecot 1%3A2.2.13-11
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 38,472 kB
  • sloc: ansic: 341,153; sh: 16,920; makefile: 5,385; cpp: 1,474; perl: 265; xml: 44; python: 34; pascal: 27
file content (225 lines) | stat: -rw-r--r-- 6,256 bytes parent folder | download | duplicates (3)
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
Key-value authentication database (v2.1.9+)
===========================================

Key-value databases can be used as auth backends. They probably should be used
only for caching in front of e.g. SQL auth backends, since they don't currently
support user iteration.

Auth configuration
------------------

'dovecot.conf':

---%<-------------------------------------------------------------------------
passdb {
  driver = dict
  args = /etc/dovecot/dovecot-dict-auth.conf
}
userdb {
  driver = dict
  args = /etc/dovecot/dovecot-dict-auth.conf
}
---%<-------------------------------------------------------------------------

Dict configuration
------------------

See the 'dovecot-dict-auth.conf.ext' file from example-config for full list of
configuration options. Basically you need these:

'/etc/dovecot/dovecot-dict-auth.conf.ext':

---%<-------------------------------------------------------------------------
uri = redis:host=127.0.0.1:port=6379

password_key = dovecot/passdb/%u
user_key = dovecot/userdb/%u
iterate_disable = yes
default_pass_scheme = plain
---%<-------------------------------------------------------------------------

Example values
--------------

Currently only JSON object values are supported. For example userdb lookup
should return something like:

---%<-------------------------------------------------------------------------
{ "uid": 123, "gid": 123, "home": "/home/username" }
---%<-------------------------------------------------------------------------

Complete example for authenticating via a UNIX socket
-----------------------------------------------------

The Dict auth backend can be used to query a local UNIX socket for users. This
can be handy for accessing user databases which would otherwise only be
accessible via the <CheckPassword> [AuthDatabase.CheckPassword.txt] backend and
a scripting language.

When given a <"proxy:"> [Quota.Dict.txt] URL the Dict backend speaks a simple
protocol over a UNIX socket. The protocol is defined in
'src/lib-dict/dict-client.h' (Mercurial
[http://hg.dovecot.org/dovecot-2.2/file/tip/src/lib-dict/dict-client.h]).

Auth configuration
------------------

'dovecot.conf':

---%<-------------------------------------------------------------------------
passdb {
  driver = dict
  args = /etc/dovecot/dovecot-dict-auth.conf
}
userdb {
  # optional
  driver = prefetch
}
userdb {
  driver = dict
  args = /etc/dovecot/dovecot-dict-auth.conf
}
---%<-------------------------------------------------------------------------

Dict configuration
------------------

The last "dictionary name" ("somewhere") argument is redundant here.

'/etc/dovecot/dovecot-dict-auth.conf.ext':

---%<-------------------------------------------------------------------------
uri = proxy:/var/run/auth_proxy_dovecot/socket:somewhere

password_key = passdb/%u
user_key = userdb/%u
iterate_disable = yes
#default_pass_scheme = plain
---%<-------------------------------------------------------------------------

Server process for answering Dict lookups
-----------------------------------------

The server process listening on '/var/run/lookup_proxy_dovecot/socket' can be
written in any language.Here's an example in Perl:

---%<-------------------------------------------------------------------------
package AuthProxyDovecot;
use base qw( Net::Server::PreFork );

use strict;
use warnings;

use JSON::XS;

AuthProxyDovecot->run() or die "Could not initialize";

sub default_values
{
  return {
    port              => '/var/run/auth_proxy_dovecot/socket|unix',

    log_level         => 2,
    log_file          => 'Sys::Syslog',
    syslog_logsock    => 'unix',
    syslog_ident      => 'auth_proxy_dovecot',
    syslog_facility   => 'daemon',

    background        => 1,
    setsid            => 1,
    pid_file          => '/var/run/auth_proxy_dovecot.pid',

    user              => 'root',
    group             => 'root',

    no_client_stdout  => 1,
    max_spare_servers => 2,
    min_spare_servers => 1,
    min_servers       => 2,
    max_servers       => 10,

  };
} ## end sub default_values

##################################################

sub process_request {
    my $self   = shift;
    my $socket = $self->{server}->{client};

    my %L_handler = (
        passdb => sub {
            my ($arg) = @_;
            my $ret = {
                password        => '$1$JrTuEHAY$gZA1y4ElkLHtnsrWNHT/e.',
                userdb_home     => "/home/username/",
                userdb_uid      => 1000,
                userdb_gid      => 1000,
            };
            return $ret;
        },
        userdb => sub {
            my ($arg) = @_;
            my $ret = {
                home    => "/home/username/",
                uid     => 1000,
                gid     => 1000,
            };
            return $ret;
        },
    );

    # protocol from src/lib-dict/dict-client.h
    my $json = JSON::XS->new;
    eval {
        while (<$socket>) {
            $self->log(2, "Got request: $_");
            chomp;
            my $cmd = substr($_,0,1);
            next if $cmd eq 'H'; # "hello"
            my $ret;
            if ($cmd eq 'L') {
                my ($namespace,$type,$arg) = split ('/',substr($_,1),3);
                $self->log(4,"I:$namespace, $type, $arg");
                if ($namespace eq 'shared') {
                    my $f = $L_handler{$type};

                    if (defined $f && defined $arg) {
                        $ret = $f->($self->{lookup}, $arg);
                    }
                }
            }
            if ($ret) {
                my $json = JSON::XS->new->indent(0)->utf8->encode($ret);
                $self->log(4,"O:$json");
                syswrite $socket, "O".$json."\n";
            }
            else {
                syswrite $socket, "F\n" unless $ret;
            }
        }
        1;
    };
    if ($@) {
        $self->log(2, "Invalid request: $@");
    }
}

sub pre_loop_hook {
    my $self = shift;

    $self->log(1, 'Starting server');
}

sub pre_server_close_hook {
    my $self = shift;

    $self->log(1, 'Server is shut down');
}

1;

__END__
---%<-------------------------------------------------------------------------

(This file was created from the wiki on 2013-11-24 04:42)