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