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
2001-11-17 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>
2001-11-17 Alain Magloire
Move util_cpystr() in the mu_ namespace.
* include/mailutils/mutil.h: util_cpystr() to mu_cpystr().
* mailbox/address.c: util_cpystr() to mu_cpystr().
* mailbox/url.c: util_cpystr() to mu_cpystr().
* mailbox/mutil.c: util_cpystr() to mu_cpystr().
* mailbox/wicket.c: util_cpystr() to mu_cpystr().
2001-11-15 Alain Magloire
After exchange with Sam Roberts, it should be possible to
set a stream on the message and have the message_t do
the rfc822 parsing.
{
message_t mesg = NULL;
header_t header = NULL;
stream_t stream = NULL;
char buffer[512];
off_t off = 0;
size_t n = 0;
message_create (mesg, NULL);
file_stream_crete (&stream, "/home/user/mh/mesg_1");
message_set_stream (mesg, stream, NULL);
stream = NULL;
message_get_header (mesg, &header);
header_get_stream (header, &stream);
while (stream_readline (stream, buffer, sizeof buffer, off, &n) == 0
&& n > 0) {
printf ("%s", buffer);
off += n;
}
message_destroy (&mesg, NULL);
}
* mailbox/message.c (message_header_fill): New
function implements a header if there was a stream set on the message.
(message_body_read): Implements the stream_read of body_t of
a message if there were a stream set.
(message_is_modified): Check if an object was set to message_t
and flag it as modified.
(message_get_body): If a stream was set on the message create a
temporary stream for the body.
(message_set_body): Set the message modified.
(message_set_header): Set the message modified.
(message_set_envelope): Set the message modified.
(message_set_attribute): Set the message modified.
* mailbox/include/message0.h: field hdr_buf removed.
* mailbox/wicket.c (wicket_destroy): return void.
* include/mailutils/auth.h: wicket_destroy ()
should return void.
* mailbox/body.c (body_is_modified): Implemented.
(body_clear_modified): Implemented.
(_body_get_size0): New function.
(_body_get_lines0): New function.
(body_get_lines): Call _body_get_lines0().
(body_get_size): Call _body_get_size0().
(body_lines): Fall back on the stream and iterate
the entire stream to find the line numbers.
(body_size): Fall back on the stream for the size.
* mailbox/folder_imap.c: Check if memory_stream_create()
succeed and bailout if not.
* mailbox/header.c (header_destroy): Free header->mstream.
(fill_blurb): Remove redundant code, header_free_cache was
doing the same. Implement the code in term of a memory
stream to hold the temporary header blurb.
(header_write): Implemented.
* mailbox/include/header0.h: Remove fields temp_blurb and
temp_blurb_len, we use mstream a memory stream and stream_len.
* mailbox/memory_stream.c (_memory_read): Cast the offset to size_t
(_memory_readline): Cast the offset to size_t.
(_memory_write): Cast the offset to size_t.
2001-11-15 Sergey Poznyakoff
* imap4d/append.c: Removed mailbox_destroy_folder kludge. It is
......
......@@ -19,6 +19,7 @@
#define _MAILUTILS_AUTH_H
#include <sys/types.h>
#include <mailutils/url.h>
#ifndef __P
#ifdef __STDC__
......@@ -42,8 +43,9 @@ extern int ticket_set_destroy __P ((ticket_t, void (*)
__P ((ticket_t)), void *owner));
extern void *ticket_get_owner __P ((ticket_t));
extern int ticket_set_pop __P ((ticket_t, int (*_pop) __P ((ticket_t, const char *, char **)), void *));
extern int ticket_pop __P ((ticket_t, const char *, char **));
extern int ticket_set_pop __P ((ticket_t, int (*_pop)
__P ((ticket_t, url_t, const char *, char **)), void *));
extern int ticket_pop __P ((ticket_t, url_t, const char *, char **));
extern int ticket_set_data __P ((ticket_t, void *, void *owner));
extern int ticket_get_data __P ((ticket_t, void **));
......
......@@ -225,7 +225,7 @@ authenticate_imap_login (authority_t auth)
/* Was it in the URL? */
status = url_get_user (folder->url, NULL, 0, &n);
if (status != 0 || n == 0)
ticket_pop (ticket, "Imap User: ", &f_imap->user);
ticket_pop (ticket, folder->url, "Imap User: ", &f_imap->user);
else
{
f_imap->user = calloc (1, n + 1);
......@@ -234,7 +234,7 @@ authenticate_imap_login (authority_t auth)
/* Was it in the URL? */
status = url_get_passwd (folder->url, NULL, 0, &n);
if (status != 0 || n == 0)
ticket_pop (ticket, "Imap Passwd: ", &f_imap->passwd);
ticket_pop (ticket, folder->url, "Imap Passwd: ", &f_imap->passwd);
else
{
f_imap->passwd = calloc (1, n + 1);
......
......@@ -42,7 +42,7 @@ struct _ticket
void *owner;
char *challenge;
void *data;
int (*_pop) __P ((ticket_t, const char *challenge, char **));
int (*_pop) __P ((ticket_t, url_t, const char *challenge, char **));
void (*_destroy) __P ((ticket_t));
};
......
......@@ -62,7 +62,6 @@ struct _message
int ref;
/* Holder for message_write. */
char *hdr_buf;
size_t hdr_buflen;
int hdr_done;
......
......@@ -1858,7 +1858,7 @@ pop_get_user (authority_t auth)
/* Was it in the URL? */
status = url_get_user (mbox->url, NULL, 0, &n);
if (status != 0 || n == 0)
ticket_pop (ticket, "Pop User: ", &mpd->user);
ticket_pop (ticket, mbox->url, "Pop User: ", &mpd->user);
else
{
mpd->user = calloc (1, n + 1);
......@@ -1888,7 +1888,7 @@ pop_get_passwd (authority_t auth)
/* Was it in the URL? */
status = url_get_passwd (mbox->url, NULL, 0, &n);
if (status != 0 || n == 0)
ticket_pop (ticket, "Pop Passwd: ", &mpd->passwd);
ticket_pop (ticket, mbox->url, "Pop Passwd: ", &mpd->passwd);
else
{
mpd->passwd = calloc (1, n + 1);
......
......@@ -810,8 +810,6 @@ message_write (stream_t os, const char *buf, size_t buflen,
if ((status = message_get_body (msg, &body)) != 0 ||
(status = body_get_stream (msg->body, &bs)) != 0)
{
free (msg->hdr_buf);
msg->hdr_buf = NULL;
msg->hdr_buflen = msg->hdr_done = 0;
return status;
}
......
......@@ -96,7 +96,7 @@ ticket_get_owner (ticket_t ticket)
int
ticket_set_pop (ticket_t ticket,
int (*_pop) __P ((ticket_t, const char *, char **)),
int (*_pop) __P ((ticket_t, url_t, const char *, char **)),
void *owner)
{
if (ticket == NULL)
......@@ -108,12 +108,12 @@ ticket_set_pop (ticket_t ticket,
}
int
ticket_pop (ticket_t ticket, const char *challenge, char **parg)
ticket_pop (ticket_t ticket, url_t url, const char *challenge, char **parg)
{
if (ticket == NULL || parg == NULL)
return EINVAL;
if (ticket->_pop)
return ticket->_pop (ticket, challenge, parg);
return ticket->_pop (ticket, url, challenge, parg);
else
{
char arg[256];
......
......@@ -21,6 +21,7 @@
#include <errno.h>
#include <sys/types.h>
#include <pwd.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
......@@ -34,13 +35,15 @@ struct myticket_data
{
char *user;
char *pass;
char *filename;
};
static char * stripwhite __P ((char *));
static int myticket_create __P ((ticket_t *, const char *, const char *));
static int myticket_create __P ((ticket_t *, const char *, const char *, const char *));
static void myticket_destroy __P ((ticket_t));
static int _get_ticket __P ((ticket_t *, const char *, const char *));
static int myticket_pop __P ((ticket_t, const char *, char **));
static int myticket_pop __P ((ticket_t, url_t, const char *, char **));
static char * get_pass __P ((url_t, const char *, const char *));
static char * get_user __P ((url_t, const char *));
int
wicket_create (wicket_t *pwicket, const char *filename)
......@@ -111,7 +114,7 @@ int
wicket_get_ticket (wicket_t wicket, ticket_t *pticket, const char *user,
const char *type)
{
if (wicket == NULL || pticket == NULL || user == NULL)
if (wicket == NULL || pticket == NULL)
return EINVAL;
if (wicket->filename == NULL)
......@@ -119,86 +122,11 @@ wicket_get_ticket (wicket_t wicket, ticket_t *pticket, const char *user,
if (wicket->_get_ticket)
return wicket->_get_ticket (wicket, user, type, pticket);
return _get_ticket (pticket, wicket->filename, user);
return myticket_create (pticket, user, NULL, wicket->filename);
}
/* FIXME: This is a proof of concept ... write a more intelligent parser. */
static int
_get_ticket (ticket_t *pticket, const char *filename, const char *user)
{
FILE *fp;
char *buf;
size_t buflen;
int status = ENOENT;
fp = fopen (filename, "r");
if (fp == NULL)
return errno;
buflen = 128;
buf = malloc (buflen);
if (buf)
{
char *ptr = buf;
while (fgets (ptr, buflen, fp) != NULL)
{
size_t len = strlen (buf);
char *sep;
/* Check if a complete line. */
if (len && buf[len - 1] != '\n')
{
char *tmp = realloc (buf, 2*buflen);
if (tmp == NULL)
{
status = ENOMEM;
break;
}
buf = tmp;
ptr = buf + len;
continue;
}
ptr = buf;
/* Comments. */
if (*ptr == '#')
continue;
/* Skip leading spaces. */
while (isspace (*ptr))
{
ptr++;
len--;
}
/* user:passwd. Separator maybe ": \t" */
if (len && ((sep = memchr (ptr, ':', len)) != NULL
|| (sep = memchr (ptr, ' ', len)) != NULL
|| (sep = memchr (ptr, '\t', len)) != NULL))
{
*sep++ = '\0';
ptr = stripwhite (ptr);
if (strcmp (ptr, user) == 0)
{
sep = stripwhite (sep);
status = myticket_create (pticket, ptr, sep);
break;
}
}
ptr = buf;
}
}
else
status = ENOMEM;
if (buf)
free (buf);
fclose (fp);
return status;
}
static int
myticket_create (ticket_t *pticket, const char *user, const char *pass)
myticket_create (ticket_t *pticket, const char *user, const char *pass, const char *filename)
{
struct myticket_data *mdata;
int status = ticket_create (pticket, NULL);
......@@ -207,29 +135,63 @@ myticket_create (ticket_t *pticket, const char *user, const char *pass)
mdata = calloc (1, sizeof *mdata);
if (mdata == NULL)
{
ticket_destroy (pticket, NULL);
return ENOMEM;
}
ticket_set_destroy (*pticket, myticket_destroy, NULL);
ticket_set_pop (*pticket, myticket_pop, NULL);
ticket_set_data (*pticket, mdata, NULL);
if ((mdata->user = strdup (user)) == NULL
|| (mdata->pass = strdup (pass)) == NULL)
if (filename)
{
mdata->filename = strdup (filename);
if (mdata->filename == NULL)
{
ticket_destroy (pticket, NULL);
status = ENOMEM;
return status;
}
}
if (user)
{
mdata->user = strdup (user);
if (mdata->user == NULL)
{
ticket_destroy (pticket, NULL);
status = ENOMEM;
return status;
}
if (!pass)
mdata->pass = get_pass (NULL, user, filename);
}
if (pass)
{
mdata->pass = strdup (pass);
if (mdata->pass == NULL)
{
ticket_destroy (pticket, NULL);
status = ENOMEM;
return status;
}
}
return 0;
}
static int
myticket_pop (ticket_t ticket, const char *challenge, char **parg)
myticket_pop (ticket_t ticket, url_t url, const char *challenge, char **parg)
{
struct myticket_data *mdata = NULL;
ticket_get_data (ticket, (void **)&mdata);
if (challenge && (strstr (challenge, "ass") != NULL
|| strstr (challenge, "ASS") != NULL))
*parg = strdup (mdata->pass);
*parg = (mdata->pass) ? strdup (mdata->pass) : get_pass (url, mdata->user, mdata->filename);
else
*parg = strdup (mdata->user);
*parg = (mdata->user) ? strdup (mdata->user) : get_user (url, mdata->filename);
return 0;
}
......@@ -244,6 +206,8 @@ myticket_destroy (ticket_t ticket)
free (mdata->user);
if (mdata->pass)
free (mdata->pass);
if (mdata->filename)
free (mdata->filename);
free (mdata);
}
}
......@@ -268,3 +232,112 @@ stripwhite (char *string)
return s;
}
static char *
get_user (url_t url, const char *filename)
{
struct passwd *pw;
char *u = (char *)"";
if (url)
{
size_t n = 0;
url_get_user (url, NULL, 0, &n);
u = calloc (1, n + 1);
url_get_user (url, u, n + 1, NULL);
return u;
}
else if (filename)
{
/* do something. */
}
pw = getpwuid (getuid ());
if (pw)
u = pw->pw_name;
return strdup (u);
}
static char *
get_pass (url_t url, const char *u, const char *filename)
{
char *user = NULL;
char *pass = NULL;
if (u)
user = strdup (u);
else if (url)
{
size_t n = 0;
url_get_user (url, NULL, 0, &n);
user = calloc (1, n + 1);
url_get_user (url, user, n + 1, NULL);
}
else
user = get_user (NULL, filename);
if (filename && user)
{
FILE *fp;
fp = fopen (filename, "r");
if (fp)
{
char *buf;
size_t buflen;
buflen = 128;
buf = malloc (buflen);
if (buf)
{
char *ptr = buf;
while (fgets (ptr, buflen, fp) != NULL)
{
size_t len = strlen (buf);
char *sep;
/* Check if a complete line. */
if (len && buf[len - 1] != '\n')
{
char *tmp = realloc (buf, 2*buflen);
if (tmp == NULL)
break;
buf = tmp;
ptr = buf + len;
continue;
}
ptr = buf;
/* Comments. */
if (*ptr == '#')
continue;
/* Skip leading spaces. */
while (isspace (*ptr))
{
ptr++;
len--;
}
/* user:passwd. Separator maybe ": \t" */
if (len && ((sep = memchr (ptr, ':', len)) != NULL
|| (sep = memchr (ptr, ' ', len)) != NULL
|| (sep = memchr (ptr, '\t', len)) != NULL))
{
*sep++ = '\0';
ptr = stripwhite (ptr);
if (strcmp (ptr, user) == 0)
{
pass = strdup (stripwhite (sep));
break;
}
}
ptr = buf;
}
}
if (buf)
free (buf);
fclose (fp);
}
}
free (user);
return pass;
}
......