Copyright updates:
[exim.git] / src / src / lookups / nis.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
9 #include "../exim.h"
10 #include "lf_functions.h"
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
20 the "nis" and "nis0" lookup types. */
21
22 static void *
23 nis_open(const uschar * filename, uschar ** errmsg)
24 {
25 char *nis_domain;
26 if (yp_get_default_domain(&nis_domain) != 0)
27   {
28   *errmsg = US"failed to get default NIS domain";
29   return NULL;
30   }
31 return 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
41 for nis0 because they are so short it isn't worth trying to use any common
42 code. */
43
44 static int
45 nis_find(void * handle, const uschar * filename, const uschar * keystring,
46   int length, uschar ** result, uschar ** errmsg, uint * do_cache,
47   const uschar * opts)
48 {
49 int rc;
50 uschar *nis_data;
51 int nis_data_length;
52 do_cache = do_cache;   /* Placate picky compilers */
53 if ((rc = yp_match(CCS handle, CCS filename, CCS keystring, length,
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   }
60 return (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
71 static int
72 nis0_find(void * handle, const uschar * filename, const uschar * keystring,
73   int length, uschar ** result, uschar ** errmsg, uint * do_cache,
74   const uschar * opts)
75 {
76 int rc;
77 uschar *nis_data;
78 int nis_data_length;
79 do_cache = do_cache;   /* Placate picky compilers */
80 if ((rc = yp_match(CCS handle, CCS filename, CCS keystring, length + 1,
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   }
87 return (rc == YPERR_KEY || rc == YPERR_MAP)? FAIL : DEFER;
88 }
89
90
91
92 /*************************************************
93 *         Version reporting entry point          *
94 *************************************************/
95
96 /* See local README for interface description. */
97
98 #include "../version.h"
99
100 gstring *
101 nis_version_report(gstring * g)
102 {
103 #ifdef DYNLOOKUP
104 g = string_fmt_append(g, "Library version: NIS: Exim version %s\n", EXIM_VERSION_STR);
105 #endif
106 return g;
107 }
108
109
110 static lookup_info nis_lookup_info = {
111   .name = US"nis",                      /* lookup name */
112   .type = 0,                            /* not abs file, not query style*/
113   .open = nis_open,                     /* open function */
114   .check = NULL,                        /* check function */
115   .find = nis_find,                     /* find function */
116   .close = NULL,                        /* no close function */
117   .tidy = NULL,                         /* no tidy function */
118   .quote = NULL,                        /* no quoting function */
119   .version_report = nis_version_report             /* version reporting */
120 };
121
122 static lookup_info nis0_lookup_info = {
123   .name = US"nis0",                     /* lookup name */
124   .type = 0,                            /* not absfile, not query style */
125   .open = nis_open,                     /* sic */         /* open function */
126   .check = NULL,                        /* check function */
127   .find = nis0_find,                    /* find function */
128   .close = NULL,                        /* no close function */
129   .tidy = NULL,                         /* no tidy function */
130   .quote = NULL,                        /* no quoting function */
131   .version_report = NULL                           /* no version reporting (redundant) */
132 };
133
134 #ifdef DYNLOOKUP
135 #define nis_lookup_module_info _lookup_module_info
136 #endif
137
138 static lookup_info *_lookup_list[] = { &nis_lookup_info, &nis0_lookup_info };
139 lookup_module_info nis_lookup_module_info = { LOOKUP_MODULE_INFO_MAGIC, _lookup_list, 2 };
140
141 /* End of lookups/nis.c */