Copyright updates:
[exim.git] / src / src / lookups / nis.c
CommitLineData
0756eb3c
PH
1/*************************************************
2* Exim - an Internet mail transport agent *
3*************************************************/
4
8d6d5106 5/* Copyright (c) University of Cambridge 1995 - 2015 */
1e1ddfac 6/* Copyright (c) The Exim Maintainers 2020 */
0756eb3c
PH
7/* See the file NOTICE for conditions of use and distribution. */
8
9#include "../exim.h"
10#include "lf_functions.h"
0756eb3c
PH
11
12#include <rpcsvc/ypclnt.h>
13
14
15/*************************************************
16* Open entry point *
17*************************************************/
18
19/* See local README for interface description. This serves for both
20the "nis" and "nis0" lookup types. */
21
e6d225ae 22static void *
d447dbd1 23nis_open(const uschar * filename, uschar ** errmsg)
0756eb3c
PH
24{
25char *nis_domain;
26if (yp_get_default_domain(&nis_domain) != 0)
27 {
f3ebb786 28 *errmsg = US"failed to get default NIS domain";
0756eb3c
PH
29 return NULL;
30 }
31return nis_domain;
32}
33
34
35
36/*************************************************
37* Find entry point for nis *
38*************************************************/
39
40/* See local README for interface description. A separate function is used
41for nis0 because they are so short it isn't worth trying to use any common
42code. */
43
e6d225ae 44static int
d447dbd1 45nis_find(void * handle, const uschar * filename, const uschar * keystring,
67a57a5a
JH
46 int length, uschar ** result, uschar ** errmsg, uint * do_cache,
47 const uschar * opts)
0756eb3c
PH
48{
49int rc;
50uschar *nis_data;
51int nis_data_length;
52do_cache = do_cache; /* Placate picky compilers */
2b01e535 53if ((rc = yp_match(CCS handle, CCS filename, CCS keystring, length,
0756eb3c
PH
54 CSS &nis_data, &nis_data_length)) == 0)
55 {
56 *result = string_copy(nis_data);
57 (*result)[nis_data_length] = 0; /* remove final '\n' */
58 return OK;
59 }
60return (rc == YPERR_KEY || rc == YPERR_MAP)? FAIL : DEFER;
61}
62
63
64
65/*************************************************
66* Find entry point for nis0 *
67*************************************************/
68
69/* See local README for interface description. */
70
e6d225ae 71static int
d447dbd1 72nis0_find(void * handle, const uschar * filename, const uschar * keystring,
67a57a5a
JH
73 int length, uschar ** result, uschar ** errmsg, uint * do_cache,
74 const uschar * opts)
0756eb3c
PH
75{
76int rc;
77uschar *nis_data;
78int nis_data_length;
79do_cache = do_cache; /* Placate picky compilers */
2b01e535 80if ((rc = yp_match(CCS handle, CCS filename, CCS keystring, length + 1,
0756eb3c
PH
81 CSS &nis_data, &nis_data_length)) == 0)
82 {
83 *result = string_copy(nis_data);
84 (*result)[nis_data_length] = 0; /* remove final '\n' */
85 return OK;
86 }
87return (rc == YPERR_KEY || rc == YPERR_MAP)? FAIL : DEFER;
88}
89
6545de78
PP
90
91
92/*************************************************
93* Version reporting entry point *
94*************************************************/
95
96/* See local README for interface description. */
97
98#include "../version.h"
99
100void
101nis_version_report(FILE *f)
102{
103#ifdef DYNLOOKUP
104fprintf(f, "Library version: NIS: Exim version %s\n", EXIM_VERSION_STR);
105#endif
106}
107
108
e6d225ae 109static lookup_info nis_lookup_info = {
9f400174
JH
110 .name = US"nis", /* lookup name */
111 .type = 0, /* not abs file, not query style*/
112 .open = nis_open, /* open function */
113 .check = NULL, /* check function */
114 .find = nis_find, /* find function */
115 .close = NULL, /* no close function */
116 .tidy = NULL, /* no tidy function */
117 .quote = NULL, /* no quoting function */
118 .version_report = nis_version_report /* version reporting */
e6d225ae
DW
119};
120
121static lookup_info nis0_lookup_info = {
9f400174
JH
122 .name = US"nis0", /* lookup name */
123 .type = 0, /* not absfile, not query style */
124 .open = nis_open, /* sic */ /* open function */
125 .check = NULL, /* check function */
126 .find = nis0_find, /* find function */
127 .close = NULL, /* no close function */
128 .tidy = NULL, /* no tidy function */
129 .quote = NULL, /* no quoting function */
130 .version_report = NULL /* no version reporting (redundant) */
e6d225ae
DW
131};
132
133#ifdef DYNLOOKUP
134#define nis_lookup_module_info _lookup_module_info
135#endif
136
137static lookup_info *_lookup_list[] = { &nis_lookup_info, &nis0_lookup_info };
138lookup_module_info nis_lookup_module_info = { LOOKUP_MODULE_INFO_MAGIC, _lookup_list, 2 };
0756eb3c
PH
139
140/* End of lookups/nis.c */