1 /* $Cambridge: exim/src/src/lookups/nis.c,v 1.4 2007/01/08 10:50:19 ph10 Exp $ */
3 /*************************************************
4 * Exim - an Internet mail transport agent *
5 *************************************************/
7 /* Copyright (c) University of Cambridge 1995 - 2007 */
8 /* See the file NOTICE for conditions of use and distribution. */
11 #include "lf_functions.h"
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. */
23 static void dummy(int x) { dummy(x-1); }
26 #include <rpcsvc/ypclnt.h>
29 /*************************************************
31 *************************************************/
33 /* See local README for interface description. This serves for both
34 the "nis" and "nis0" lookup types. */
37 nis_open(uschar *filename, uschar **errmsg)
40 if (yp_get_default_domain(&nis_domain) != 0)
42 *errmsg = string_sprintf("failed to get default NIS domain");
50 /*************************************************
51 * Find entry point for nis *
52 *************************************************/
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
59 nis_find(void *handle, uschar *filename, uschar *keystring, int length,
60 uschar **result, uschar **errmsg, BOOL *do_cache)
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)
69 *result = string_copy(nis_data);
70 (*result)[nis_data_length] = 0; /* remove final '\n' */
73 return (rc == YPERR_KEY || rc == YPERR_MAP)? FAIL : DEFER;
78 /*************************************************
79 * Find entry point for nis0 *
80 *************************************************/
82 /* See local README for interface description. */
85 nis0_find(void *handle, uschar *filename, uschar *keystring, int length,
86 uschar **result, uschar **errmsg, BOOL *do_cache)
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)
95 *result = string_copy(nis_data);
96 (*result)[nis_data_length] = 0; /* remove final '\n' */
99 return (rc == YPERR_KEY || rc == YPERR_MAP)? FAIL : DEFER;
102 #endif /* LOOKUP_NIS */
104 /* End of lookups/nis.c */