Commit | Line | Data |
---|---|---|
d7d7b7b9 | 1 | /* $Cambridge: exim/src/src/lookups/nis.c,v 1.3 2006/02/07 11:19:01 ph10 Exp $ */ |
0756eb3c PH |
2 | |
3 | /************************************************* | |
4 | * Exim - an Internet mail transport agent * | |
5 | *************************************************/ | |
6 | ||
d7d7b7b9 | 7 | /* Copyright (c) University of Cambridge 1995 - 2006 */ |
0756eb3c PH |
8 | /* See the file NOTICE for conditions of use and distribution. */ |
9 | ||
10 | #include "../exim.h" | |
11 | #include "lf_functions.h" | |
12 | #include "nis.h" | |
13 | ||
14 | /* We can't just compile this code and allow the library mechanism to omit the | |
15 | functions if they are not wanted, because we need to have the NIS header | |
16 | available for compiling. Therefore, compile these functions only if LOOKUP_NIS | |
17 | is defined. However, some compilers don't like compiling empty modules, so keep | |
18 | them happy with a dummy when skipping the rest. Make it reference itself to | |
19 | stop picky compilers complaining that it is unused, and put in a dummy argument | |
20 | to stop even pickier compilers complaining about infinite loops. */ | |
21 | ||
22 | #ifndef LOOKUP_NIS | |
23 | static void dummy(int x) { dummy(x-1); } | |
24 | #else | |
25 | ||
26 | #include <rpcsvc/ypclnt.h> | |
27 | ||
28 | ||
29 | /************************************************* | |
30 | * Open entry point * | |
31 | *************************************************/ | |
32 | ||
33 | /* See local README for interface description. This serves for both | |
34 | the "nis" and "nis0" lookup types. */ | |
35 | ||
36 | void * | |
37 | nis_open(uschar *filename, uschar **errmsg) | |
38 | { | |
39 | char *nis_domain; | |
40 | if (yp_get_default_domain(&nis_domain) != 0) | |
41 | { | |
42 | *errmsg = string_sprintf("failed to get default NIS domain"); | |
43 | return NULL; | |
44 | } | |
45 | return nis_domain; | |
46 | } | |
47 | ||
48 | ||
49 | ||
50 | /************************************************* | |
51 | * Find entry point for nis * | |
52 | *************************************************/ | |
53 | ||
54 | /* See local README for interface description. A separate function is used | |
55 | for nis0 because they are so short it isn't worth trying to use any common | |
56 | code. */ | |
57 | ||
58 | int | |
59 | nis_find(void *handle, uschar *filename, uschar *keystring, int length, | |
60 | uschar **result, uschar **errmsg, BOOL *do_cache) | |
61 | { | |
62 | int rc; | |
63 | uschar *nis_data; | |
64 | int nis_data_length; | |
65 | do_cache = do_cache; /* Placate picky compilers */ | |
66 | if ((rc = yp_match(CS handle, CS filename, CS keystring, length, | |
67 | CSS &nis_data, &nis_data_length)) == 0) | |
68 | { | |
69 | *result = string_copy(nis_data); | |
70 | (*result)[nis_data_length] = 0; /* remove final '\n' */ | |
71 | return OK; | |
72 | } | |
73 | return (rc == YPERR_KEY || rc == YPERR_MAP)? FAIL : DEFER; | |
74 | } | |
75 | ||
76 | ||
77 | ||
78 | /************************************************* | |
79 | * Find entry point for nis0 * | |
80 | *************************************************/ | |
81 | ||
82 | /* See local README for interface description. */ | |
83 | ||
84 | int | |
85 | nis0_find(void *handle, uschar *filename, uschar *keystring, int length, | |
86 | uschar **result, uschar **errmsg, BOOL *do_cache) | |
87 | { | |
88 | int rc; | |
89 | uschar *nis_data; | |
90 | int nis_data_length; | |
91 | do_cache = do_cache; /* Placate picky compilers */ | |
92 | if ((rc = yp_match(CS handle, CS filename, CS keystring, length + 1, | |
93 | CSS &nis_data, &nis_data_length)) == 0) | |
94 | { | |
95 | *result = string_copy(nis_data); | |
96 | (*result)[nis_data_length] = 0; /* remove final '\n' */ | |
97 | return OK; | |
98 | } | |
99 | return (rc == YPERR_KEY || rc == YPERR_MAP)? FAIL : DEFER; | |
100 | } | |
101 | ||
102 | #endif /* LOOKUP_NIS */ | |
103 | ||
104 | /* End of lookups/nis.c */ |