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