SPDX: license tags (mostly by guesswork)
[exim.git] / src / src / lookups / passwd.c
1 /*************************************************
2 *     Exim - an Internet mail transport agent    *
3 *************************************************/
4
5 /* Copyright (c) The Exim Maintainers 2020 - 2022 */
6 /* Copyright (c) University of Cambridge 1995 - 2015 */
7 /* See the file NOTICE for conditions of use and distribution. */
8 /* SPDX-License-Identifier: GPL-2.0-only */
9
10 #include "../exim.h"
11
12
13
14 /*************************************************
15 *              Open entry point                  *
16 *************************************************/
17
18 /* See local README for interface description */
19
20 static void *
21 passwd_open(const uschar * filename, uschar ** errmsg)
22 {
23 return (void *)(-1);     /* Just return something non-null */
24 }
25
26
27
28
29 /*************************************************
30 *         Find entry point for passwd           *
31 *************************************************/
32
33 /* See local README for interface description */
34
35 static int
36 passwd_find(void * handle, const uschar * filename, const uschar * keystring,
37   int length, uschar ** result, uschar ** errmsg, uint * do_cache,
38   const uschar * opts)
39 {
40 struct passwd *pw;
41
42 if (!route_finduser(keystring, &pw, NULL)) return FAIL;
43 *result = string_sprintf("*:%d:%d:%s:%s:%s", (int)pw->pw_uid, (int)pw->pw_gid,
44   pw->pw_gecos, pw->pw_dir, pw->pw_shell);
45 return OK;
46 }
47
48
49
50 /*************************************************
51 *         Version reporting entry point          *
52 *************************************************/
53
54 /* See local README for interface description. */
55
56 #include "../version.h"
57
58 gstring *
59 passwd_version_report(gstring * g)
60 {
61 #ifdef DYNLOOKUP
62 g = string_fmt_append(g, "Library version: passwd: Exim version %s\n", EXIM_VERSION_STR);
63 #endif
64 return g;
65 }
66
67 static lookup_info _lookup_info = {
68   .name = US"passwd",                   /* lookup name */
69   .type = lookup_querystyle,            /* query-style lookup */
70   .open = passwd_open,                  /* open function */
71   .check = NULL,                        /* no check function */
72   .find = passwd_find,                  /* find function */
73   .close = NULL,                        /* no close function */
74   .tidy = NULL,                         /* no tidy function */
75   .quote = NULL,                        /* no quoting function */
76   .version_report = passwd_version_report          /* version reporting */
77 };
78
79 #ifdef DYNLOOKUP
80 #define passwd_lookup_module_info _lookup_module_info
81 #endif
82
83 static lookup_info *_lookup_list[] = { &_lookup_info };
84 lookup_module_info passwd_lookup_module_info = { LOOKUP_MODULE_INFO_MAGIC, _lookup_list, 1 };
85
86 /* End of lookups/passwd.c */