1/* This file is part of Mailfromd.             -*- c -*-
2   Copyright (C) 2006-2021 Sergey Poznyakoff
3
4   This program is free software; you can redistribute it and/or modify
5   it under the terms of the GNU General Public License as published by
6   the Free Software Foundation; either version 3, or (at your option)
7   any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   GNU General Public License for more details.
13
14   You should have received a copy of the GNU General Public License
15   along with this program.  If not, see <http://www.gnu.org/licenses/>. */
16
17MF_BUILTIN_MODULE
18
19#include "mflib/_register.h"
20
21static int
22valid_user_p(eval_environ_t env, const char *name)
23{
24	int rc;
25	struct mu_auth_data *auth_data = NULL;
26
27	rc = mu_get_auth(&auth_data, mu_auth_key_name, name);
28	mu_auth_data_free(auth_data);
29	switch (rc) {
30	case 0:
31		rc = 1;
32		break;
33
34	case MU_ERR_AUTH_FAILURE:
35		rc = 0;
36		break;
37
38	case EAGAIN:
39                MF_THROW(mfe_temp_failure,
40		         _("temporary failure querying for username %s"),
41			 name);
42		break;
43
44	default:
45                MF_THROW(mfe_failure,
46		         _("failure querying for username %s"),
47			 name);
48		break;
49	}
50
51	MF_DEBUG(MU_DEBUG_TRACE1,
52                 ("Checking user %s: %s", name, rc ? "true" : "false"));
53	return rc;
54}
55
56MF_DEFUN(validuser, NUMBER, STRING name)
57{
58	MF_RETURN(valid_user_p(env, name));
59}
60END
61
62MF_DEFUN(interval, NUMBER, STRING str)
63{
64       time_t t;
65       const char *endp;
66
67       MF_ASSERT(parse_time_interval(str, &t, &endp) == 0,
68	         mfe_invtime,
69		 _("unrecognized time format (near `%s')"), endp);
70       MF_RETURN(t);
71}
72END
73
74