annotate src/auth/auth-stream.c @ 9490:fd84592e817b HEAD

dovecot-example.conf: Updated dict comments.
author Timo Sirainen <tss@iki.fi>
date Mon, 23 Nov 2009 13:08:47 -0500
parents b9faf4db2a9f
children 00cd9aacd03c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8590
b9faf4db2a9f Updated copyright notices to include year 2009.
Timo Sirainen <tss@iki.fi>
parents: 7485
diff changeset
1 /* Copyright (c) 2005-2009 Dovecot authors, see the included COPYING file */
3526
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 #include "common.h"
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
4 #include "str.h"
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5 #include "ostream.h"
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6 #include "auth-request.h"
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7 #include "auth-stream.h"
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
8
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
9 struct auth_stream_reply {
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
10 string_t *str;
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11 };
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
12
7388
08d31d752893 Use auth-stream API to build all TAB-delimited strings to make sure strings
Timo Sirainen <tss@iki.fi>
parents: 7122
diff changeset
13 struct auth_stream_reply *auth_stream_reply_init(pool_t pool)
3526
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14 {
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15 struct auth_stream_reply *reply;
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16
7388
08d31d752893 Use auth-stream API to build all TAB-delimited strings to make sure strings
Timo Sirainen <tss@iki.fi>
parents: 7122
diff changeset
17 reply = p_new(pool, struct auth_stream_reply, 1);
7485
8bed019c834d Memory pool allocation tweaks.
Timo Sirainen <tss@iki.fi>
parents: 7388
diff changeset
18 reply->str = str_new(pool, 128);
3526
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
19 return reply;
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
20 }
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
21
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
22 void auth_stream_reply_add(struct auth_stream_reply *reply,
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
23 const char *key, const char *value)
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
24 {
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
25 if (str_len(reply->str) > 0)
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
26 str_append_c(reply->str, '\t');
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
27 if (key != NULL) {
4017
e2d267e6f930 Check that we don't pass around key=value pairs with empty keys.
Timo Sirainen <tss@iki.fi>
parents: 3526
diff changeset
28 i_assert(*key != '\0');
3526
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
29 i_assert(strchr(key, '\t') == NULL &&
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
30 strchr(key, '\n') == NULL);
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
31
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
32 str_append(reply->str, key);
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
33 if (value != NULL)
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
34 str_append_c(reply->str, '=');
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
35 }
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
36 if (value != NULL) {
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
37 /* escape dangerous characters in the value */
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
38 for (; *value != '\0'; value++) {
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
39 switch (*value) {
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
40 case '\001':
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
41 str_append_c(reply->str, '\001');
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
42 str_append_c(reply->str, '1');
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
43 break;
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
44 case '\t':
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
45 str_append_c(reply->str, '\001');
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
46 str_append_c(reply->str, 't');
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
47 break;
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
48 case '\n':
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
49 str_append_c(reply->str, '\001');
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
50 str_append_c(reply->str, 'n');
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
51 break;
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
52 default:
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
53 str_append_c(reply->str, *value);
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
54 break;
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
55 }
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
56 }
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
57 }
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
58 }
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
59
7122
fb03422c0760 Added "proxy_maybe" field. If it's used instead of "proxy" and the
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
60 void auth_stream_reply_remove(struct auth_stream_reply *reply, const char *key)
fb03422c0760 Added "proxy_maybe" field. If it's used instead of "proxy" and the
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
61 {
fb03422c0760 Added "proxy_maybe" field. If it's used instead of "proxy" and the
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
62 const char *str = str_c(reply->str);
fb03422c0760 Added "proxy_maybe" field. If it's used instead of "proxy" and the
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
63 unsigned int i, start, key_len = strlen(key);
fb03422c0760 Added "proxy_maybe" field. If it's used instead of "proxy" and the
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
64
fb03422c0760 Added "proxy_maybe" field. If it's used instead of "proxy" and the
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
65 i = 0;
fb03422c0760 Added "proxy_maybe" field. If it's used instead of "proxy" and the
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
66 while (str[i] != '\0') {
fb03422c0760 Added "proxy_maybe" field. If it's used instead of "proxy" and the
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
67 start = i;
fb03422c0760 Added "proxy_maybe" field. If it's used instead of "proxy" and the
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
68 for (; str[i] != '\0'; i++) {
fb03422c0760 Added "proxy_maybe" field. If it's used instead of "proxy" and the
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
69 if (str[i] == '\t') {
fb03422c0760 Added "proxy_maybe" field. If it's used instead of "proxy" and the
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
70 i++;
fb03422c0760 Added "proxy_maybe" field. If it's used instead of "proxy" and the
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
71 break;
fb03422c0760 Added "proxy_maybe" field. If it's used instead of "proxy" and the
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
72 }
fb03422c0760 Added "proxy_maybe" field. If it's used instead of "proxy" and the
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
73 }
fb03422c0760 Added "proxy_maybe" field. If it's used instead of "proxy" and the
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
74
fb03422c0760 Added "proxy_maybe" field. If it's used instead of "proxy" and the
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
75 if (strncmp(str+start, key, key_len) == 0 &&
fb03422c0760 Added "proxy_maybe" field. If it's used instead of "proxy" and the
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
76 (str[start+key_len] == '=' ||
fb03422c0760 Added "proxy_maybe" field. If it's used instead of "proxy" and the
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
77 str[start+key_len] == '\t' ||
fb03422c0760 Added "proxy_maybe" field. If it's used instead of "proxy" and the
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
78 str[start+key_len] == '\0')) {
fb03422c0760 Added "proxy_maybe" field. If it's used instead of "proxy" and the
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
79 str_delete(reply->str, start, i-start);
fb03422c0760 Added "proxy_maybe" field. If it's used instead of "proxy" and the
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
80 if (str_len(reply->str) == start && start > 0)
fb03422c0760 Added "proxy_maybe" field. If it's used instead of "proxy" and the
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
81 str_delete(reply->str, start - 1, 1);
fb03422c0760 Added "proxy_maybe" field. If it's used instead of "proxy" and the
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
82 break;
fb03422c0760 Added "proxy_maybe" field. If it's used instead of "proxy" and the
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
83 }
fb03422c0760 Added "proxy_maybe" field. If it's used instead of "proxy" and the
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
84 }
fb03422c0760 Added "proxy_maybe" field. If it's used instead of "proxy" and the
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
85 }
fb03422c0760 Added "proxy_maybe" field. If it's used instead of "proxy" and the
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
86
3526
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
87 void auth_stream_reply_reset(struct auth_stream_reply *reply)
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
88 {
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
89 str_truncate(reply->str, 0);
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
90 }
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
91
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
92 void auth_stream_reply_import(struct auth_stream_reply *reply, const char *str)
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
93 {
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
94 if (str_len(reply->str) > 0)
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
95 str_append_c(reply->str, '\t');
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
96 str_append(reply->str, str);
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
97 }
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
98
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
99 const char *auth_stream_reply_export(struct auth_stream_reply *reply)
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
100 {
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
101 return str_c(reply->str);
0bcee5d7da39 Accidentally committed earlier parts of changes to authentication streams,
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
102 }
5005
7a8f68b0cc31 extra_fields == NULL and empty extra_fields (reset after each passdb
Timo Sirainen <tss@iki.fi>
parents: 4017
diff changeset
103
7a8f68b0cc31 extra_fields == NULL and empty extra_fields (reset after each passdb
Timo Sirainen <tss@iki.fi>
parents: 4017
diff changeset
104 bool auth_stream_is_empty(struct auth_stream_reply *reply)
7a8f68b0cc31 extra_fields == NULL and empty extra_fields (reset after each passdb
Timo Sirainen <tss@iki.fi>
parents: 4017
diff changeset
105 {
7a8f68b0cc31 extra_fields == NULL and empty extra_fields (reset after each passdb
Timo Sirainen <tss@iki.fi>
parents: 4017
diff changeset
106 return reply == NULL || str_len(reply->str) == 0;
7a8f68b0cc31 extra_fields == NULL and empty extra_fields (reset after each passdb
Timo Sirainen <tss@iki.fi>
parents: 4017
diff changeset
107 }
7122
fb03422c0760 Added "proxy_maybe" field. If it's used instead of "proxy" and the
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
108
fb03422c0760 Added "proxy_maybe" field. If it's used instead of "proxy" and the
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
109 const char *const *auth_stream_split(struct auth_stream_reply *reply)
fb03422c0760 Added "proxy_maybe" field. If it's used instead of "proxy" and the
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
110 {
fb03422c0760 Added "proxy_maybe" field. If it's used instead of "proxy" and the
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
111 return t_strsplit(str_c(reply->str), "\t");
fb03422c0760 Added "proxy_maybe" field. If it's used instead of "proxy" and the
Timo Sirainen <tss@iki.fi>
parents: 7086
diff changeset
112 }
7388
08d31d752893 Use auth-stream API to build all TAB-delimited strings to make sure strings
Timo Sirainen <tss@iki.fi>
parents: 7122
diff changeset
113
08d31d752893 Use auth-stream API to build all TAB-delimited strings to make sure strings
Timo Sirainen <tss@iki.fi>
parents: 7122
diff changeset
114 string_t *auth_stream_reply_get_str(struct auth_stream_reply *reply)
08d31d752893 Use auth-stream API to build all TAB-delimited strings to make sure strings
Timo Sirainen <tss@iki.fi>
parents: 7122
diff changeset
115 {
08d31d752893 Use auth-stream API to build all TAB-delimited strings to make sure strings
Timo Sirainen <tss@iki.fi>
parents: 7122
diff changeset
116 return reply->str;
08d31d752893 Use auth-stream API to build all TAB-delimited strings to make sure strings
Timo Sirainen <tss@iki.fi>
parents: 7122
diff changeset
117 }