1 /*************************************************
2 * Exim - an Internet mail transport agent *
3 *************************************************/
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 */
11 #include "lf_functions.h"
13 #include <rpcsvc/ypclnt.h>
16 /*************************************************
18 *************************************************/
20 /* See local README for interface description. This serves for both
21 the "nis" and "nis0" lookup types. */
24 nis_open(const uschar * filename, uschar ** errmsg)
27 if (yp_get_default_domain(&nis_domain) != 0)
29 *errmsg = US"failed to get default NIS domain";
37 /*************************************************
38 * Find entry point for nis *
39 *************************************************/
41 /* See local README for interface description. A separate function is used
42 for nis0 because they are so short it isn't worth trying to use any common
46 nis_find(void * handle, const uschar * filename, const uschar * keystring,
47 int length, uschar ** result, uschar ** errmsg, uint * do_cache,
53 do_cache = do_cache; /* Placate picky compilers */
54 if ((rc = yp_match(CCS handle, CCS filename, CCS keystring, length,
55 CSS &nis_data, &nis_data_length)) == 0)
57 *result = string_copy(nis_data);
58 (*result)[nis_data_length] = 0; /* remove final '\n' */
61 return (rc == YPERR_KEY || rc == YPERR_MAP)? FAIL : DEFER;
66 /*************************************************
67 * Find entry point for nis0 *
68 *************************************************/
70 /* See local README for interface description. */
73 nis0_find(void * handle, const uschar * filename, const uschar * keystring,
74 int length, uschar ** result, uschar ** errmsg, uint * do_cache,
80 do_cache = do_cache; /* Placate picky compilers */
81 if ((rc = yp_match(CCS handle, CCS filename, CCS keystring, length + 1,
82 CSS &nis_data, &nis_data_length)) == 0)
84 *result = string_copy(nis_data);
85 (*result)[nis_data_length] = 0; /* remove final '\n' */
88 return (rc == YPERR_KEY || rc == YPERR_MAP)? FAIL : DEFER;
93 /*************************************************
94 * Version reporting entry point *
95 *************************************************/
97 /* See local README for interface description. */
99 #include "../version.h"
102 nis_version_report(gstring * g)
105 g = string_fmt_append(g, "Library version: NIS: Exim version %s\n", EXIM_VERSION_STR);
111 static lookup_info nis_lookup_info = {
112 .name = US"nis", /* lookup name */
113 .type = 0, /* not abs file, not query style*/
114 .open = nis_open, /* open function */
115 .check = NULL, /* check function */
116 .find = nis_find, /* find function */
117 .close = NULL, /* no close function */
118 .tidy = NULL, /* no tidy function */
119 .quote = NULL, /* no quoting function */
120 .version_report = nis_version_report /* version reporting */
123 static lookup_info nis0_lookup_info = {
124 .name = US"nis0", /* lookup name */
125 .type = 0, /* not absfile, not query style */
126 .open = nis_open, /* sic */ /* open function */
127 .check = NULL, /* check function */
128 .find = nis0_find, /* find function */
129 .close = NULL, /* no close function */
130 .tidy = NULL, /* no tidy function */
131 .quote = NULL, /* no quoting function */
132 .version_report = NULL /* no version reporting (redundant) */
136 #define nis_lookup_module_info _lookup_module_info
139 static lookup_info *_lookup_list[] = { &nis_lookup_info, &nis0_lookup_info };
140 lookup_module_info nis_lookup_module_info = { LOOKUP_MODULE_INFO_MAGIC, _lookup_list, 2 };
142 /* End of lookups/nis.c */