diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-12-31 14:25:13 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2016-12-31 14:25:13 +0200 |
commit | 66f7ed9562cce859f20166f9cf0c38a018a83dbe (patch) | |
tree | e2b11f6d2d74fd07bd981eae1d774ff58f2d80a7 /imap4d | |
parent | da63ec15b4c8fb3084075730332a8d20a9af374f (diff) | |
download | mailutils-66f7ed9562cce859f20166f9cf0c38a018a83dbe.tar.gz mailutils-66f7ed9562cce859f20166f9cf0c38a018a83dbe.tar.bz2 |
Provide a way to discern between erroneous return and user-induced break condition in foreach iterator functions
* libmailutils/diag/errors (MU_ERR_USER0-MU_ERR_USER7): New error constants.
Reserved for user's purposes, such as breaking from foreach iterators.
* libmaildutils/list/foreach.c (mu_list_foreach): Treat NULL list as a list
of 0 elements.
* libmailutils/list/foreachdir.c (mu_list_foreach_dir): Likewise.
* imap4d/imap4d.h (imap4d_auth_result): Remap constants to MU_ERR_USER[0-2]
* libmu_sieve/prog.c (mu_i_sv_lint_command): Use mu_list_locate with
the default comparator.
* mh/mh_list.c (_comp_name): Rewrite to match the definition of
mu_list_comparator_t
(mhl_format_run): Set _comp_name as comparator for the
env.printed_fields list.
(header_is_printed): Use mu_list_locate.
* imap4d/authenticate.c: Use MU_ERR_USER0-MU_ERR_USER7 to indicate
normal break condition in foreach iterators.
* imap4d/imap4d.c: Likewise.
* imap4d/namespace.c: Likewise.
* libmailutils/auth/auth.c: Likewise.
* libmailutils/cfg/driver.c: Likewise.
* libmailutils/cfg/parser.y: Likewise.
* libmailutils/server/acl.c: Likewise.
* libmailutils/server/msrv.c: Likewise.
* libmu_sieve/conf.c: Likewise.
* libmu_sieve/load.c: Likewise.
* libmu_sieve/sieve.l: Likewise.
* libmu_sieve/strexp.c: Likewise.
* libproto/imap/mbox.c: Likewise.
* libproto/imap/search.c: Likewise.
* mh/mh_format.c: Likewise.
* mh/send.c: Likewise.
* mh/sortm.c: Likewise.
* mimeview/mimetypes.y: Likewise.
* movemail/movemail.c: Likewise.
Diffstat (limited to 'imap4d')
-rw-r--r-- | imap4d/authenticate.c | 6 | ||||
-rw-r--r-- | imap4d/imap4d.c | 6 | ||||
-rw-r--r-- | imap4d/imap4d.h | 8 | ||||
-rw-r--r-- | imap4d/namespace.c | 16 |
4 files changed, 25 insertions, 11 deletions
diff --git a/imap4d/authenticate.c b/imap4d/authenticate.c index 92c4719d8..13fcf9a3e 100644 --- a/imap4d/authenticate.c +++ b/imap4d/authenticate.c @@ -96,7 +96,7 @@ imap4d_authenticate (struct imap4d_session *session, { char *auth_type; struct imap4d_auth adata; - enum imap4d_auth_result res; + int res; if (imap4d_tokbuf_argc (tok) != 3) return io_completion_response (command, RESP_BAD, "Invalid arguments"); @@ -136,6 +136,10 @@ imap4d_authenticate (struct imap4d_session *session, case imap4d_auth_fail: adata.response = RESP_NO; break; + + default: + adata.response = RESP_NO; + mu_error ("%s", mu_strerror (res)); } return io_completion_response (command, adata.response, "%s authentication failed", auth_type); diff --git a/imap4d/imap4d.c b/imap4d/imap4d.c index df9cc7a2b..348e615a0 100644 --- a/imap4d/imap4d.c +++ b/imap4d/imap4d.c @@ -340,11 +340,11 @@ check_user_groups (void *item, void *data) return 0; if (gp->gr_gid == auth_data->gid) - return MU_ERR_EXISTS; + return MU_ERR_USER0; for (p = gp->gr_mem; *p; p++) if (strcmp (*p, auth_data->name) == 0) - return MU_ERR_EXISTS; + return MU_ERR_USER0; return 0; } @@ -353,7 +353,7 @@ static int imap_check_group_list (mu_list_t l) { int rc = mu_list_foreach (l, check_user_groups, NULL); - if (rc == MU_ERR_EXISTS) + if (rc == MU_ERR_USER0) return 0; else if (rc == 0) return MU_ERR_NOENT; diff --git a/imap4d/imap4d.h b/imap4d/imap4d.h index d5472873c..c08290d30 100644 --- a/imap4d/imap4d.h +++ b/imap4d/imap4d.h @@ -467,10 +467,10 @@ struct imap4d_auth enum imap4d_auth_result { - imap4d_auth_nosup, - imap4d_auth_ok, - imap4d_auth_resp, - imap4d_auth_fail + imap4d_auth_nosup = 0, + imap4d_auth_ok = MU_ERR_USER0, + imap4d_auth_resp = MU_ERR_USER1, + imap4d_auth_fail = MU_ERR_USER2 }; typedef enum imap4d_auth_result diff --git a/imap4d/namespace.c b/imap4d/namespace.c index 9d694942c..e05aa132e 100644 --- a/imap4d/namespace.c +++ b/imap4d/namespace.c @@ -83,8 +83,18 @@ namespace_enumerate (int id, nsfp_t f, void *closure) nsc.id = id; nsc.fun = f; nsc.closure = closure; - return namespace[id] == 0 ? 0 : - mu_list_foreach (namespace[id], _enum_fun, &nsc); + if (namespace[id]) + { + int rc = mu_list_foreach (namespace[id], _enum_fun, &nsc); + if (rc == MU_ERR_USER0) + return 1; + else if (rc != 0) + { + mu_diag_funcall (MU_DIAG_ERROR, "mu_list_foreach", NULL, rc); + return 0; + } + } + return 0; } static int @@ -149,7 +159,7 @@ check_namespace (void *closure, int ns, char *path, int delim) { p->ns = ns; p->exact = len == p->namelen; - return 1; + return MU_ERR_USER0; } return 0; } |