Commit cf9c751d cf9c751dd6b97df3ead5e2947465bccb7c8c4521 by Sergey Poznyakoff

All client utilities: read ~/.mu-tickets

* NEWS: Update.
* include/mailutils/mailbox.h (mu_ticket_file): New extern.
* include/mailutils/message.h (mu_message_save_to_mailbox): Change proto.
* include/mailutils/sieve.h (mu_sieve_get_ticket, mu_sieve_set_ticket): Remove.
* libmu_sieve/actions.c (sieve_action_fileinto): Update call to
mu_message_save_to_mailbox.
* libmu_sieve/sieve-priv.h (struct mu_sieve_machine): Remove ticket.
* libmu_sieve/sieve.y (mu_sieve_get_ticket, mu_sieve_set_ticket): Remove.
* mailbox/mbx_default.c (mu_mailbox_create_default): Read a wicket file and
attach a ticket if mailbox opened successfully.
* mailbox/wicket.c: Re-format.
* sieve/sieve.c: Remove special wicket-handling code.

* libmu_auth/radius.c, movemail/movemail.c: Add missing includes
1 parent 234b002d
GNU mailutils NEWS -- history of user-visible changes. 2009-02-18
GNU mailutils NEWS -- history of user-visible changes. 2009-03-03
Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007,
2008 Free Software Foundation, Inc.
2008, 2009 Free Software Foundation, Inc.
See the end of file for copying conditions.
Please send mailutils bug reports to <bug-mailutils@gnu.org>.
......@@ -8,6 +8,30 @@ Please send mailutils bug reports to <bug-mailutils@gnu.org>.
Version 2.0.90 (Git)
* Ticket files
All MU client utilities make use of the user ticket file,
~/.mu-tickets, if it is present.
* API
** Removed functions
- mu_sieve_get_ticket
- mu_sieve_set_ticket
** Changed functions
- mu_message_save_to_mailbox: removed `ticket' argument.
New prototype is:
int mu_message_save_to_mailbox (mu_message_t msg,
mu_debug_t debug,
const char *toname,
int perms);
Version 2.0:
......
......@@ -28,6 +28,8 @@
extern "C" {
#endif
extern char *mu_ticket_file;
int mu_set_mail_directory (const char *p);
int mu_set_mailbox_pattern (const char *pat);
void mu_set_folder_directory (const char *p);
......
......@@ -123,7 +123,7 @@ extern int mu_message_get_attachment_name (mu_message_t, char *name,
size_t bufsz, size_t* sz);
extern int mu_message_aget_attachment_name (mu_message_t, char **name);
extern int mu_message_save_to_mailbox (mu_message_t msg, mu_ticket_t ticket,
extern int mu_message_save_to_mailbox (mu_message_t msg,
mu_debug_t debug, const char *toname,
int perms);
......
......@@ -217,7 +217,6 @@ void *mu_sieve_get_data (mu_sieve_machine_t mach);
mu_message_t mu_sieve_get_message (mu_sieve_machine_t mach);
size_t mu_sieve_get_message_num (mu_sieve_machine_t mach);
int mu_sieve_get_debug_level (mu_sieve_machine_t mach);
mu_ticket_t mu_sieve_get_ticket (mu_sieve_machine_t mach);
mu_mailer_t mu_sieve_get_mailer (mu_sieve_machine_t mach);
int mu_sieve_get_locus (mu_sieve_machine_t mach, mu_sieve_locus_t *);
char *mu_sieve_get_daemon_email (mu_sieve_machine_t mach);
......@@ -232,7 +231,6 @@ void mu_sieve_set_debug_object (mu_sieve_machine_t mach, mu_debug_t dbg);
void mu_sieve_set_debug_level (mu_sieve_machine_t mach, int level);
void mu_sieve_set_logger (mu_sieve_machine_t mach,
mu_sieve_action_log_t logger);
void mu_sieve_set_ticket (mu_sieve_machine_t mach, mu_ticket_t ticket);
void mu_sieve_set_mailer (mu_sieve_machine_t mach, mu_mailer_t mailer);
void mu_sieve_set_daemon_email (mu_sieve_machine_t mach, const char *email);
......
......@@ -42,6 +42,7 @@
#include <mailutils/errno.h>
#include <mailutils/nls.h>
#include <mailutils/vartab.h>
#include <mailutils/io.h>
#ifdef ENABLE_RADIUS
......
......@@ -105,7 +105,7 @@ sieve_action_fileinto (mu_sieve_machine_t mach, mu_list_t args, mu_list_t tags)
if (mu_sieve_is_dry_run (mach))
return 0;
rc = mu_message_save_to_mailbox (mach->msg, mach->ticket, mach->debug,
rc = mu_message_save_to_mailbox (mach->msg, mach->debug,
val->v.string, mbflags);
if (rc)
mu_sieve_error (mach, _("cannot save to mailbox: %s"),
......
......@@ -74,7 +74,6 @@ struct mu_sieve_machine {
mu_sieve_action_log_t logger;
mu_mailer_t mailer;
mu_ticket_t ticket;
mu_debug_t debug;
char *daemon_email;
void *data;
......
......@@ -477,18 +477,6 @@ mu_sieve_set_logger (mu_sieve_machine_t mach, mu_sieve_action_log_t logger)
mach->logger = logger;
}
void
mu_sieve_set_ticket (mu_sieve_machine_t mach, mu_ticket_t ticket)
{
mach->ticket = ticket;
}
mu_ticket_t
mu_sieve_get_ticket (mu_sieve_machine_t mach)
{
return mach->ticket;
}
mu_mailer_t
mu_sieve_get_mailer (mu_sieve_machine_t mach)
{
......
......@@ -34,10 +34,17 @@
#include <mailutils/mailbox.h>
#include <mailutils/mutil.h>
#include <mailutils/debug.h>
#include <mailutils/error.h>
#include <mailutils/errno.h>
#include <mailutils/mu_auth.h>
#include <mailutils/vartab.h>
#include <mailutils/folder.h>
#include <mailutils/auth.h>
#include <mailbox0.h>
char *mu_ticket_file = "~/.mu-tickets";
static char *_mu_mailbox_pattern;
......@@ -328,6 +335,44 @@ percent_expand (const char *file, char **mbox)
return status;
}
static void
attach_auth_ticket (mu_mailbox_t mbox)
{
mu_folder_t folder = NULL;
mu_authority_t auth = NULL;
if (mu_mailbox_get_folder (mbox, &folder) == 0
&& mu_folder_get_authority (folder, &auth) == 0)
{
char *filename = mu_tilde_expansion (mu_ticket_file, "/", NULL);
mu_wicket_t wicket;
int rc;
MU_DEBUG1 (mbox->debug, MU_DEBUG_TRACE1,
"Reading user ticket file %s\n", filename);
if ((rc = mu_wicket_create (&wicket, filename)) == 0)
{
mu_ticket_t ticket;
if ((rc = mu_wicket_get_ticket (wicket, &ticket, 0, 0)) == 0)
{
rc = mu_authority_set_ticket (auth, ticket);
MU_DEBUG1 (mbox->debug, MU_DEBUG_TRACE1,
"Retrieved and set ticket: %d\n", rc);
}
else
MU_DEBUG1 (mbox->debug, MU_DEBUG_ERROR,
"Error retrieving ticket: %s\n",
mu_strerror (rc));
mu_wicket_destroy (&wicket);
}
else
MU_DEBUG1 (mbox->debug, MU_DEBUG_ERROR,
"Error creating wicket: %s\n", mu_strerror (rc));
free (filename);
}
}
/* We are trying to be smart about the location of the mail.
mu_mailbox_create() is not doing this.
% --> system mailbox for the real uid
......@@ -415,5 +460,8 @@ mu_mailbox_create_default (mu_mailbox_t *pmbox, const char *mail)
status = mu_mailbox_create (pmbox, mbox);
free (mbox);
if (status == 0)
attach_auth_ticket (*pmbox);
return status;
}
......
......@@ -1110,7 +1110,7 @@ message_body_read (mu_stream_t stream, char *buffer, size_t n, mu_off_t off,
}
int
mu_message_save_to_mailbox (mu_message_t msg, mu_ticket_t ticket,
mu_message_save_to_mailbox (mu_message_t msg,
mu_debug_t debug,
const char *toname, int perms)
{
......@@ -1128,26 +1128,6 @@ mu_message_save_to_mailbox (mu_message_t msg, mu_ticket_t ticket,
if (debug && (rc = mu_mailbox_set_debug (to, debug)))
goto end;
if (ticket)
{
mu_folder_t folder = NULL;
if ((rc = mu_mailbox_get_folder (to, &folder)))
goto end;
/* FIXME: not all mailboxes have folders, thus this hack. */
if (folder)
{
mu_authority_t auth = NULL;
if ((rc = mu_folder_get_authority (folder, &auth)))
goto end;
/* FIXME: not all folders have authentication, thus this hack. */
if (auth && (rc = mu_authority_set_ticket (auth, ticket)))
goto end;
}
}
if ((rc = mu_mailbox_open (to,
MU_STREAM_WRITE | MU_STREAM_CREAT
| (perms & MU_STREAM_IMASK))))
......
......@@ -91,11 +91,11 @@ mu_wicket_destroy (mu_wicket_t *pwicket)
int
mu_wicket_get_filename (mu_wicket_t wicket, char *filename, size_t len,
size_t *pwriten)
size_t *pwriten)
{
size_t n;
if (wicket == NULL)
return EINVAL;
size_t n;
if (wicket == NULL)
return EINVAL;
n = mu_cpystr (filename, wicket->filename, len);
if (pwriten)
*pwriten = n;
......@@ -107,10 +107,10 @@ mu_wicket_set_filename (mu_wicket_t wicket, const char *filename)
{
if (wicket == NULL)
return EINVAL;
if (wicket->filename)
free (wicket->filename);
wicket->filename = (filename) ? strdup (filename) : NULL;
return 0;
}
......@@ -127,8 +127,9 @@ mu_wicket_set_ticket (mu_wicket_t wicket, int (*get_ticket)
}
int
mu_wicket_get_ticket (mu_wicket_t wicket, mu_ticket_t *pticket, const char *user,
const char *type)
mu_wicket_get_ticket (mu_wicket_t wicket, mu_ticket_t *pticket,
const char *user,
const char *type)
{
if (wicket == NULL || pticket == NULL)
return EINVAL;
......@@ -142,7 +143,8 @@ mu_wicket_get_ticket (mu_wicket_t wicket, mu_ticket_t *pticket, const char *user
}
static int
myticket_create (mu_ticket_t *pticket, const char *user, const char *pass, const char *filename)
myticket_create (mu_ticket_t *pticket, const char *user,
const char *pass, const char *filename)
{
struct myticket_data *mdata;
int status = mu_ticket_create (pticket, NULL);
......@@ -197,42 +199,35 @@ myticket_create (mu_ticket_t *pticket, const char *user, const char *pass, const
}
static int
myticket_pop (mu_ticket_t ticket, mu_url_t url, const char *challenge, char **parg)
myticket_pop (mu_ticket_t ticket, mu_url_t url,
const char *challenge, char **parg)
{
struct myticket_data *mdata = NULL;
int e = 0;
mu_ticket_get_data (ticket, (void **)&mdata);
if (challenge &&
(
strstr (challenge, "ass") != NULL ||
strstr (challenge, "ASS") != NULL
)
)
{
if(mdata->pass)
if (challenge && (strstr (challenge, "ass") != NULL ||
strstr (challenge, "ASS") != NULL))
{
*parg = strdup(mdata->pass);
if(!*parg)
e = ENOMEM;
}
else
{
e = get_pass (url, mdata->user, mdata->filename, parg);
if (mdata->pass)
{
*parg = strdup (mdata->pass);
if (!*parg)
e = ENOMEM;
}
else
e = get_pass (url, mdata->user, mdata->filename, parg);
}
}
else
{
if(mdata->user)
{
*parg = strdup(mdata->user);
if(!*parg)
e = ENOMEM;
}
else
{
e = get_user (url, mdata->filename, parg);
}
if (mdata->user)
{
*parg = strdup(mdata->user);
if (!*parg)
e = ENOMEM;
}
else
e = get_user (url, mdata->filename, parg);
}
return e;
}
......@@ -255,7 +250,8 @@ myticket_destroy (mu_ticket_t ticket)
}
static int
get_ticket (mu_url_t url, const char *user, const char *filename, mu_url_t * ticket)
get_ticket (mu_url_t url, const char *user, const char *filename,
mu_url_t * ticket)
{
int err = 0;
FILE *fp = NULL;
......
......@@ -29,6 +29,7 @@
#include <mailutils/tls.h>
#include <mu_asprintf.h>
#include "mailutils/libargp.h"
#include <lib/muaux.h>
const char *program_version = "movemail (" PACKAGE_STRING ")";
static char doc[] = N_("GNU movemail");
......
......@@ -106,8 +106,6 @@ static struct argp_option options[] =
int keep_going;
int compile_only;
char *mbox_url;
char *tickets;
int tickets_default;
int debug_level;
int sieve_debug;
int verbose;
......@@ -282,24 +280,13 @@ cb_email (mu_debug_t debug, void *data, mu_config_value_t *val)
return rc;
}
static int
cb_ticket (mu_debug_t debug, void *data, mu_config_value_t *val)
{
if (mu_cfg_assert_value_type (val, MU_CFG_STRING, debug))
return 1;
free (tickets);
tickets = mu_tilde_expansion (val->v.string, "/", NULL);
tickets_default = 0;
return 0;
}
static struct mu_cfg_param sieve_cfg_param[] = {
{ "keep-going", mu_cfg_bool, &keep_going, 0, NULL,
N_("Do not abort if execution fails on a message.") },
{ "mbox-url", mu_cfg_string, &mbox_url, 0, NULL,
N_("Mailbox to sieve (defaults to user's mail spool)."),
N_("url") },
{ "ticket", mu_cfg_callback, NULL, 0, cb_ticket,
{ "ticket", mu_cfg_string, &mu_ticket_file, 0, NULL,
N_("Ticket file for user authentication."),
N_("ticket") },
{ "debug", mu_cfg_callback, NULL, 0, cb_debug,
......@@ -405,12 +392,12 @@ sieve_message (mu_sieve_machine_t mach)
}
static int
sieve_mailbox (mu_sieve_machine_t mach, mu_ticket_t ticket, mu_debug_t debug)
sieve_mailbox (mu_sieve_machine_t mach, mu_debug_t debug)
{
int rc;
mu_mailbox_t mbox = NULL;
/* Create, give a ticket to, and open the mailbox. */
/* Create and open the mailbox. */
if ((rc = mu_mailbox_create_default (&mbox, mbox_url)) != 0)
{
if (mbox)
......@@ -428,34 +415,6 @@ sieve_mailbox (mu_sieve_machine_t mach, mu_ticket_t ticket, mu_debug_t debug)
goto cleanup;
}
if (ticket)
{
mu_folder_t folder = NULL;
mu_authority_t auth = NULL;
if ((rc = mu_mailbox_get_folder (mbox, &folder)))
{
mu_error (_("mu_mailbox_get_folder failed: %s"),
mu_strerror (rc));
goto cleanup;
}
if ((rc = mu_folder_get_authority (folder, &auth)))
{
mu_error (_("mu_folder_get_authority failed: %s"),
mu_strerror (rc));
goto cleanup;
}
/* Authentication-less folders don't have authorities. */
if (auth && (rc = mu_authority_set_ticket (auth, ticket)))
{
mu_error (_("mu_authority_set_ticket failed: %s"),
mu_strerror (rc));
goto cleanup;
}
}
/* Open the mailbox read-only if we aren't going to modify it. */
if (sieve_debug & MU_SIEVE_DRY_RUN)
rc = mu_mailbox_open (mbox, MU_STREAM_READ);
......@@ -516,8 +475,6 @@ int
main (int argc, char *argv[])
{
mu_sieve_machine_t mach;
mu_wicket_t wicket = 0;
mu_ticket_t ticket = 0;
mu_debug_t debug = 0;
int rc;
......@@ -532,8 +489,6 @@ main (int argc, char *argv[])
mu_register_all_formats ();
tickets = mu_tilde_expansion ("~/.tickets", "/", NULL);
tickets_default = 1;
debug_level = MU_DEBUG_LEVEL_MASK (MU_DEBUG_ERROR);
mu_log_facility = 0;
......@@ -574,27 +529,6 @@ main (int argc, char *argv[])
return EX_OK;
}
/* Create a ticket, if we can. */
if (tickets)
{
if ((rc = mu_wicket_create (&wicket, tickets)) == 0)
{
if ((rc = mu_wicket_get_ticket (wicket, &ticket, 0, 0)) != 0)
{
mu_error (_("ticket_get failed: %s"), mu_strerror (rc));
return EX_SOFTWARE; /* FIXME: really? */
}
}
else if (!(tickets_default && errno == ENOENT))
{
mu_error (_("mu_wicket_create `%s' failed: %s"),
tickets, mu_strerror (rc));
return EX_SOFTWARE;
}
if (ticket)
mu_sieve_set_ticket (mach, ticket);
}
/* Create a debug object, if needed. */
if (debug_level)
{
......@@ -617,7 +551,7 @@ main (int argc, char *argv[])
if (mbox_url && strcmp (mbox_url, "-") == 0)
rc = sieve_message (mach);
else
rc = sieve_mailbox (mach, ticket, debug);
rc = sieve_mailbox (mach, debug);
mu_debug_destroy (&debug, mach);
return rc;
......