Commit f5492813 f5492813de2f4c1f092fcece7e63b931cbf24d21 by Alain Magloire

* mailbox/folder_imap.c (authenticate_imap_login): Pass the

	url in  ticket_pop.
	* mailbox/mbx_pop.c (pop_get_user): Pass the url in ticket_pop()
	* mailbox/mbx_pop.c (pop_get_passwd): Pass the url in ticket_pop()
	* mailbox/ticket.c (ticket_set_pop): Change the prototype.
	(ticket_pop): Change the prototype.
	* mailbox/wicket.c (get_pass): New function get passwd.
	(get_user): New function get user.
	(myticket_create): Take filenanme as argument and
	save the information.
	(_get_ticket): Removed.
	(myticket_pop): Take an url in argument.
	* mailbox/include/auth0.h: field _pop() prototype changed.
	* include/mailutils/auth.h: ticket_pop and ticket_set_pop
	proptotype changed, add url. Include <mailutils/url.h>
1 parent 002b3bcb
1 2001-11-17 Alain Magloire
2
3 * mailbox/folder_imap.c (authenticate_imap_login): Pass the
4 url in ticket_pop.
5 * mailbox/mbx_pop.c (pop_get_user): Pass the url in ticket_pop()
6 * mailbox/mbx_pop.c (pop_get_passwd): Pass the url in ticket_pop()
7 * mailbox/ticket.c (ticket_set_pop): Change the prototype.
8 (ticket_pop): Change the prototype.
9 * mailbox/wicket.c (get_pass): New function get passwd.
10 (get_user): New function get user.
11 (myticket_create): Take filenanme as argument and
12 save the information.
13 (_get_ticket): Removed.
14 (myticket_pop): Take an url in argument.
15 * mailbox/include/auth0.h: field _pop() prototype changed.
16 * include/mailutils/auth.h: ticket_pop and ticket_set_pop
17 proptotype changed, add url. Include <mailutils/url.h>
18
19 2001-11-17 Alain Magloire
20
21 Move util_cpystr() in the mu_ namespace.
22
23 * include/mailutils/mutil.h: util_cpystr() to mu_cpystr().
24 * mailbox/address.c: util_cpystr() to mu_cpystr().
25 * mailbox/url.c: util_cpystr() to mu_cpystr().
26 * mailbox/mutil.c: util_cpystr() to mu_cpystr().
27 * mailbox/wicket.c: util_cpystr() to mu_cpystr().
28
29 2001-11-15 Alain Magloire
30
31 After exchange with Sam Roberts, it should be possible to
32 set a stream on the message and have the message_t do
33 the rfc822 parsing.
34 {
35 message_t mesg = NULL;
36 header_t header = NULL;
37 stream_t stream = NULL;
38 char buffer[512];
39 off_t off = 0;
40 size_t n = 0;
41
42 message_create (mesg, NULL);
43 file_stream_crete (&stream, "/home/user/mh/mesg_1");
44 message_set_stream (mesg, stream, NULL);
45
46 stream = NULL;
47 message_get_header (mesg, &header);
48 header_get_stream (header, &stream);
49 while (stream_readline (stream, buffer, sizeof buffer, off, &n) == 0
50 && n > 0) {
51 printf ("%s", buffer);
52 off += n;
53 }
54 message_destroy (&mesg, NULL);
55 }
56
57 * mailbox/message.c (message_header_fill): New
58 function implements a header if there was a stream set on the message.
59 (message_body_read): Implements the stream_read of body_t of
60 a message if there were a stream set.
61 (message_is_modified): Check if an object was set to message_t
62 and flag it as modified.
63 (message_get_body): If a stream was set on the message create a
64 temporary stream for the body.
65 (message_set_body): Set the message modified.
66 (message_set_header): Set the message modified.
67 (message_set_envelope): Set the message modified.
68 (message_set_attribute): Set the message modified.
69 * mailbox/include/message0.h: field hdr_buf removed.
70
71 * mailbox/wicket.c (wicket_destroy): return void.
72 * include/mailutils/auth.h: wicket_destroy ()
73 should return void.
74 * mailbox/body.c (body_is_modified): Implemented.
75 (body_clear_modified): Implemented.
76 (_body_get_size0): New function.
77 (_body_get_lines0): New function.
78 (body_get_lines): Call _body_get_lines0().
79 (body_get_size): Call _body_get_size0().
80 (body_lines): Fall back on the stream and iterate
81 the entire stream to find the line numbers.
82 (body_size): Fall back on the stream for the size.
83
84 * mailbox/folder_imap.c: Check if memory_stream_create()
85 succeed and bailout if not.
86
87 * mailbox/header.c (header_destroy): Free header->mstream.
88 (fill_blurb): Remove redundant code, header_free_cache was
89 doing the same. Implement the code in term of a memory
90 stream to hold the temporary header blurb.
91 (header_write): Implemented.
92 * mailbox/include/header0.h: Remove fields temp_blurb and
93 temp_blurb_len, we use mstream a memory stream and stream_len.
94
95 * mailbox/memory_stream.c (_memory_read): Cast the offset to size_t
96 (_memory_readline): Cast the offset to size_t.
97 (_memory_write): Cast the offset to size_t.
98
1 2001-11-15 Sergey Poznyakoff 99 2001-11-15 Sergey Poznyakoff
2 100
3 * imap4d/append.c: Removed mailbox_destroy_folder kludge. It is 101 * imap4d/append.c: Removed mailbox_destroy_folder kludge. It is
......
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
19 #define _MAILUTILS_AUTH_H 19 #define _MAILUTILS_AUTH_H
20 20
21 #include <sys/types.h> 21 #include <sys/types.h>
22 #include <mailutils/url.h>
22 23
23 #ifndef __P 24 #ifndef __P
24 #ifdef __STDC__ 25 #ifdef __STDC__
...@@ -42,8 +43,9 @@ extern int ticket_set_destroy __P ((ticket_t, void (*) ...@@ -42,8 +43,9 @@ extern int ticket_set_destroy __P ((ticket_t, void (*)
42 __P ((ticket_t)), void *owner)); 43 __P ((ticket_t)), void *owner));
43 extern void *ticket_get_owner __P ((ticket_t)); 44 extern void *ticket_get_owner __P ((ticket_t));
44 45
45 extern int ticket_set_pop __P ((ticket_t, int (*_pop) __P ((ticket_t, const char *, char **)), void *)); 46 extern int ticket_set_pop __P ((ticket_t, int (*_pop)
46 extern int ticket_pop __P ((ticket_t, const char *, char **)); 47 __P ((ticket_t, url_t, const char *, char **)), void *));
48 extern int ticket_pop __P ((ticket_t, url_t, const char *, char **));
47 extern int ticket_set_data __P ((ticket_t, void *, void *owner)); 49 extern int ticket_set_data __P ((ticket_t, void *, void *owner));
48 extern int ticket_get_data __P ((ticket_t, void **)); 50 extern int ticket_get_data __P ((ticket_t, void **));
49 51
......
...@@ -225,7 +225,7 @@ authenticate_imap_login (authority_t auth) ...@@ -225,7 +225,7 @@ authenticate_imap_login (authority_t auth)
225 /* Was it in the URL? */ 225 /* Was it in the URL? */
226 status = url_get_user (folder->url, NULL, 0, &n); 226 status = url_get_user (folder->url, NULL, 0, &n);
227 if (status != 0 || n == 0) 227 if (status != 0 || n == 0)
228 ticket_pop (ticket, "Imap User: ", &f_imap->user); 228 ticket_pop (ticket, folder->url, "Imap User: ", &f_imap->user);
229 else 229 else
230 { 230 {
231 f_imap->user = calloc (1, n + 1); 231 f_imap->user = calloc (1, n + 1);
...@@ -234,7 +234,7 @@ authenticate_imap_login (authority_t auth) ...@@ -234,7 +234,7 @@ authenticate_imap_login (authority_t auth)
234 /* Was it in the URL? */ 234 /* Was it in the URL? */
235 status = url_get_passwd (folder->url, NULL, 0, &n); 235 status = url_get_passwd (folder->url, NULL, 0, &n);
236 if (status != 0 || n == 0) 236 if (status != 0 || n == 0)
237 ticket_pop (ticket, "Imap Passwd: ", &f_imap->passwd); 237 ticket_pop (ticket, folder->url, "Imap Passwd: ", &f_imap->passwd);
238 else 238 else
239 { 239 {
240 f_imap->passwd = calloc (1, n + 1); 240 f_imap->passwd = calloc (1, n + 1);
......
...@@ -42,7 +42,7 @@ struct _ticket ...@@ -42,7 +42,7 @@ struct _ticket
42 void *owner; 42 void *owner;
43 char *challenge; 43 char *challenge;
44 void *data; 44 void *data;
45 int (*_pop) __P ((ticket_t, const char *challenge, char **)); 45 int (*_pop) __P ((ticket_t, url_t, const char *challenge, char **));
46 void (*_destroy) __P ((ticket_t)); 46 void (*_destroy) __P ((ticket_t));
47 }; 47 };
48 48
......
...@@ -62,7 +62,6 @@ struct _message ...@@ -62,7 +62,6 @@ struct _message
62 int ref; 62 int ref;
63 63
64 /* Holder for message_write. */ 64 /* Holder for message_write. */
65 char *hdr_buf;
66 size_t hdr_buflen; 65 size_t hdr_buflen;
67 int hdr_done; 66 int hdr_done;
68 67
......
...@@ -1858,7 +1858,7 @@ pop_get_user (authority_t auth) ...@@ -1858,7 +1858,7 @@ pop_get_user (authority_t auth)
1858 /* Was it in the URL? */ 1858 /* Was it in the URL? */
1859 status = url_get_user (mbox->url, NULL, 0, &n); 1859 status = url_get_user (mbox->url, NULL, 0, &n);
1860 if (status != 0 || n == 0) 1860 if (status != 0 || n == 0)
1861 ticket_pop (ticket, "Pop User: ", &mpd->user); 1861 ticket_pop (ticket, mbox->url, "Pop User: ", &mpd->user);
1862 else 1862 else
1863 { 1863 {
1864 mpd->user = calloc (1, n + 1); 1864 mpd->user = calloc (1, n + 1);
...@@ -1888,7 +1888,7 @@ pop_get_passwd (authority_t auth) ...@@ -1888,7 +1888,7 @@ pop_get_passwd (authority_t auth)
1888 /* Was it in the URL? */ 1888 /* Was it in the URL? */
1889 status = url_get_passwd (mbox->url, NULL, 0, &n); 1889 status = url_get_passwd (mbox->url, NULL, 0, &n);
1890 if (status != 0 || n == 0) 1890 if (status != 0 || n == 0)
1891 ticket_pop (ticket, "Pop Passwd: ", &mpd->passwd); 1891 ticket_pop (ticket, mbox->url, "Pop Passwd: ", &mpd->passwd);
1892 else 1892 else
1893 { 1893 {
1894 mpd->passwd = calloc (1, n + 1); 1894 mpd->passwd = calloc (1, n + 1);
......
...@@ -810,8 +810,6 @@ message_write (stream_t os, const char *buf, size_t buflen, ...@@ -810,8 +810,6 @@ message_write (stream_t os, const char *buf, size_t buflen,
810 if ((status = message_get_body (msg, &body)) != 0 || 810 if ((status = message_get_body (msg, &body)) != 0 ||
811 (status = body_get_stream (msg->body, &bs)) != 0) 811 (status = body_get_stream (msg->body, &bs)) != 0)
812 { 812 {
813 free (msg->hdr_buf);
814 msg->hdr_buf = NULL;
815 msg->hdr_buflen = msg->hdr_done = 0; 813 msg->hdr_buflen = msg->hdr_done = 0;
816 return status; 814 return status;
817 } 815 }
......
...@@ -96,7 +96,7 @@ ticket_get_owner (ticket_t ticket) ...@@ -96,7 +96,7 @@ ticket_get_owner (ticket_t ticket)
96 96
97 int 97 int
98 ticket_set_pop (ticket_t ticket, 98 ticket_set_pop (ticket_t ticket,
99 int (*_pop) __P ((ticket_t, const char *, char **)), 99 int (*_pop) __P ((ticket_t, url_t, const char *, char **)),
100 void *owner) 100 void *owner)
101 { 101 {
102 if (ticket == NULL) 102 if (ticket == NULL)
...@@ -108,12 +108,12 @@ ticket_set_pop (ticket_t ticket, ...@@ -108,12 +108,12 @@ ticket_set_pop (ticket_t ticket,
108 } 108 }
109 109
110 int 110 int
111 ticket_pop (ticket_t ticket, const char *challenge, char **parg) 111 ticket_pop (ticket_t ticket, url_t url, const char *challenge, char **parg)
112 { 112 {
113 if (ticket == NULL || parg == NULL) 113 if (ticket == NULL || parg == NULL)
114 return EINVAL; 114 return EINVAL;
115 if (ticket->_pop) 115 if (ticket->_pop)
116 return ticket->_pop (ticket, challenge, parg); 116 return ticket->_pop (ticket, url, challenge, parg);
117 else 117 else
118 { 118 {
119 char arg[256]; 119 char arg[256];
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
21 21
22 #include <errno.h> 22 #include <errno.h>
23 #include <sys/types.h> 23 #include <sys/types.h>
24 #include <pwd.h>
24 #include <string.h> 25 #include <string.h>
25 #include <stdlib.h> 26 #include <stdlib.h>
26 #include <stdio.h> 27 #include <stdio.h>
...@@ -34,13 +35,15 @@ struct myticket_data ...@@ -34,13 +35,15 @@ struct myticket_data
34 { 35 {
35 char *user; 36 char *user;
36 char *pass; 37 char *pass;
38 char *filename;
37 }; 39 };
38 40
39 static char * stripwhite __P ((char *)); 41 static char * stripwhite __P ((char *));
40 static int myticket_create __P ((ticket_t *, const char *, const char *)); 42 static int myticket_create __P ((ticket_t *, const char *, const char *, const char *));
41 static void myticket_destroy __P ((ticket_t)); 43 static void myticket_destroy __P ((ticket_t));
42 static int _get_ticket __P ((ticket_t *, const char *, const char *)); 44 static int myticket_pop __P ((ticket_t, url_t, const char *, char **));
43 static int myticket_pop __P ((ticket_t, const char *, char **)); 45 static char * get_pass __P ((url_t, const char *, const char *));
46 static char * get_user __P ((url_t, const char *));
44 47
45 int 48 int
46 wicket_create (wicket_t *pwicket, const char *filename) 49 wicket_create (wicket_t *pwicket, const char *filename)
...@@ -111,7 +114,7 @@ int ...@@ -111,7 +114,7 @@ int
111 wicket_get_ticket (wicket_t wicket, ticket_t *pticket, const char *user, 114 wicket_get_ticket (wicket_t wicket, ticket_t *pticket, const char *user,
112 const char *type) 115 const char *type)
113 { 116 {
114 if (wicket == NULL || pticket == NULL || user == NULL) 117 if (wicket == NULL || pticket == NULL)
115 return EINVAL; 118 return EINVAL;
116 119
117 if (wicket->filename == NULL) 120 if (wicket->filename == NULL)
...@@ -119,86 +122,11 @@ wicket_get_ticket (wicket_t wicket, ticket_t *pticket, const char *user, ...@@ -119,86 +122,11 @@ wicket_get_ticket (wicket_t wicket, ticket_t *pticket, const char *user,
119 122
120 if (wicket->_get_ticket) 123 if (wicket->_get_ticket)
121 return wicket->_get_ticket (wicket, user, type, pticket); 124 return wicket->_get_ticket (wicket, user, type, pticket);
122 return _get_ticket (pticket, wicket->filename, user); 125 return myticket_create (pticket, user, NULL, wicket->filename);
123 } 126 }
124 127
125 /* FIXME: This is a proof of concept ... write a more intelligent parser. */
126 static int 128 static int
127 _get_ticket (ticket_t *pticket, const char *filename, const char *user) 129 myticket_create (ticket_t *pticket, const char *user, const char *pass, const char *filename)
128 {
129 FILE *fp;
130 char *buf;
131 size_t buflen;
132 int status = ENOENT;
133
134 fp = fopen (filename, "r");
135 if (fp == NULL)
136 return errno;
137
138 buflen = 128;
139 buf = malloc (buflen);
140 if (buf)
141 {
142 char *ptr = buf;
143 while (fgets (ptr, buflen, fp) != NULL)
144 {
145 size_t len = strlen (buf);
146 char *sep;
147 /* Check if a complete line. */
148 if (len && buf[len - 1] != '\n')
149 {
150 char *tmp = realloc (buf, 2*buflen);
151 if (tmp == NULL)
152 {
153 status = ENOMEM;
154 break;
155 }
156 buf = tmp;
157 ptr = buf + len;
158 continue;
159 }
160
161 ptr = buf;
162
163 /* Comments. */
164 if (*ptr == '#')
165 continue;
166
167 /* Skip leading spaces. */
168 while (isspace (*ptr))
169 {
170 ptr++;
171 len--;
172 }
173
174 /* user:passwd. Separator maybe ": \t" */
175 if (len && ((sep = memchr (ptr, ':', len)) != NULL
176 || (sep = memchr (ptr, ' ', len)) != NULL
177 || (sep = memchr (ptr, '\t', len)) != NULL))
178 {
179 *sep++ = '\0';
180 ptr = stripwhite (ptr);
181 if (strcmp (ptr, user) == 0)
182 {
183 sep = stripwhite (sep);
184 status = myticket_create (pticket, ptr, sep);
185 break;
186 }
187 }
188 ptr = buf;
189 }
190 }
191 else
192 status = ENOMEM;
193
194 if (buf)
195 free (buf);
196 fclose (fp);
197 return status;
198 }
199
200 static int
201 myticket_create (ticket_t *pticket, const char *user, const char *pass)
202 { 130 {
203 struct myticket_data *mdata; 131 struct myticket_data *mdata;
204 int status = ticket_create (pticket, NULL); 132 int status = ticket_create (pticket, NULL);
...@@ -207,29 +135,63 @@ myticket_create (ticket_t *pticket, const char *user, const char *pass) ...@@ -207,29 +135,63 @@ myticket_create (ticket_t *pticket, const char *user, const char *pass)
207 135
208 mdata = calloc (1, sizeof *mdata); 136 mdata = calloc (1, sizeof *mdata);
209 if (mdata == NULL) 137 if (mdata == NULL)
210 ticket_destroy (pticket, NULL); 138 {
139 ticket_destroy (pticket, NULL);
140 return ENOMEM;
141 }
142
211 ticket_set_destroy (*pticket, myticket_destroy, NULL); 143 ticket_set_destroy (*pticket, myticket_destroy, NULL);
212 ticket_set_pop (*pticket, myticket_pop, NULL); 144 ticket_set_pop (*pticket, myticket_pop, NULL);
213 ticket_set_data (*pticket, mdata, NULL); 145 ticket_set_data (*pticket, mdata, NULL);
214 if ((mdata->user = strdup (user)) == NULL 146
215 || (mdata->pass = strdup (pass)) == NULL) 147 if (filename)
216 { 148 {
217 status = ENOMEM; 149 mdata->filename = strdup (filename);
218 ticket_destroy (pticket, NULL); 150 if (mdata->filename == NULL)
151 {
152 ticket_destroy (pticket, NULL);
153 status = ENOMEM;
154 return status;
155 }
156 }
157
158 if (user)
159 {
160 mdata->user = strdup (user);
161 if (mdata->user == NULL)
162 {
163 ticket_destroy (pticket, NULL);
164 status = ENOMEM;
165 return status;
166 }
167 if (!pass)
168 mdata->pass = get_pass (NULL, user, filename);
219 } 169 }
220 return status; 170
171 if (pass)
172 {
173 mdata->pass = strdup (pass);
174 if (mdata->pass == NULL)
175 {
176 ticket_destroy (pticket, NULL);
177 status = ENOMEM;
178 return status;
179 }
180 }
181
182 return 0;
221 } 183 }
222 184
223 static int 185 static int
224 myticket_pop (ticket_t ticket, const char *challenge, char **parg) 186 myticket_pop (ticket_t ticket, url_t url, const char *challenge, char **parg)
225 { 187 {
226 struct myticket_data *mdata = NULL; 188 struct myticket_data *mdata = NULL;
227 ticket_get_data (ticket, (void **)&mdata); 189 ticket_get_data (ticket, (void **)&mdata);
228 if (challenge && (strstr (challenge, "ass") != NULL 190 if (challenge && (strstr (challenge, "ass") != NULL
229 || strstr (challenge, "ASS") != NULL)) 191 || strstr (challenge, "ASS") != NULL))
230 *parg = strdup (mdata->pass); 192 *parg = (mdata->pass) ? strdup (mdata->pass) : get_pass (url, mdata->user, mdata->filename);
231 else 193 else
232 *parg = strdup (mdata->user); 194 *parg = (mdata->user) ? strdup (mdata->user) : get_user (url, mdata->filename);
233 return 0; 195 return 0;
234 } 196 }
235 197
...@@ -244,6 +206,8 @@ myticket_destroy (ticket_t ticket) ...@@ -244,6 +206,8 @@ myticket_destroy (ticket_t ticket)
244 free (mdata->user); 206 free (mdata->user);
245 if (mdata->pass) 207 if (mdata->pass)
246 free (mdata->pass); 208 free (mdata->pass);
209 if (mdata->filename)
210 free (mdata->filename);
247 free (mdata); 211 free (mdata);
248 } 212 }
249 } 213 }
...@@ -268,3 +232,112 @@ stripwhite (char *string) ...@@ -268,3 +232,112 @@ stripwhite (char *string)
268 232
269 return s; 233 return s;
270 } 234 }
235
236 static char *
237 get_user (url_t url, const char *filename)
238 {
239 struct passwd *pw;
240 char *u = (char *)"";
241 if (url)
242 {
243 size_t n = 0;
244 url_get_user (url, NULL, 0, &n);
245 u = calloc (1, n + 1);
246 url_get_user (url, u, n + 1, NULL);
247 return u;
248 }
249 else if (filename)
250 {
251 /* do something. */
252 }
253 pw = getpwuid (getuid ());
254 if (pw)
255 u = pw->pw_name;
256 return strdup (u);
257 }
258
259 static char *
260 get_pass (url_t url, const char *u, const char *filename)
261 {
262 char *user = NULL;
263 char *pass = NULL;
264
265 if (u)
266 user = strdup (u);
267 else if (url)
268 {
269 size_t n = 0;
270 url_get_user (url, NULL, 0, &n);
271 user = calloc (1, n + 1);
272 url_get_user (url, user, n + 1, NULL);
273 }
274 else
275 user = get_user (NULL, filename);
276
277 if (filename && user)
278 {
279 FILE *fp;
280 fp = fopen (filename, "r");
281 if (fp)
282 {
283 char *buf;
284 size_t buflen;
285
286 buflen = 128;
287 buf = malloc (buflen);
288 if (buf)
289 {
290 char *ptr = buf;
291 while (fgets (ptr, buflen, fp) != NULL)
292 {
293 size_t len = strlen (buf);
294 char *sep;
295 /* Check if a complete line. */
296 if (len && buf[len - 1] != '\n')
297 {
298 char *tmp = realloc (buf, 2*buflen);
299 if (tmp == NULL)
300 break;
301 buf = tmp;
302 ptr = buf + len;
303 continue;
304 }
305
306 ptr = buf;
307
308 /* Comments. */
309 if (*ptr == '#')
310 continue;
311
312 /* Skip leading spaces. */
313 while (isspace (*ptr))
314 {
315 ptr++;
316 len--;
317 }
318
319 /* user:passwd. Separator maybe ": \t" */
320 if (len && ((sep = memchr (ptr, ':', len)) != NULL
321 || (sep = memchr (ptr, ' ', len)) != NULL
322 || (sep = memchr (ptr, '\t', len)) != NULL))
323 {
324 *sep++ = '\0';
325 ptr = stripwhite (ptr);
326 if (strcmp (ptr, user) == 0)
327 {
328 pass = strdup (stripwhite (sep));
329 break;
330 }
331 }
332 ptr = buf;
333 }
334 }
335
336 if (buf)
337 free (buf);
338 fclose (fp);
339 }
340 }
341 free (user);
342 return pass;
343 }
......