1 /* $Cambridge: exim/src/src/lookups/nis.c,v 1.5 2009/11/16 19:50:38 nm4 Exp $ */
3 /*************************************************
4 * Exim - an Internet mail transport agent *
5 *************************************************/
7 /* Copyright (c) University of Cambridge 1995 - 2009 */
8 /* See the file NOTICE for conditions of use and distribution. */
11 #include "lf_functions.h"
13 #include <rpcsvc/ypclnt.h>
16 /*************************************************
18 *************************************************/
20 /* See local README for interface description. This serves for both
21 the "nis" and "nis0" lookup types. */
24 nis_open(uschar *filename, uschar **errmsg)
27 if (yp_get_default_domain(&nis_domain) != 0)
29 *errmsg = string_sprintf("failed to get default NIS domain");
37 /*************************************************
38 * Find entry point for nis *
39 *************************************************/
41 /* See local README for interface description. A separate function is used
42 for nis0 because they are so short it isn't worth trying to use any common
46 nis_find(void *handle, uschar *filename, uschar *keystring, int length,
47 uschar **result, uschar **errmsg, BOOL *do_cache)
52 do_cache = do_cache; /* Placate picky compilers */
53 if ((rc = yp_match(CS handle, CS filename, CS keystring, length,
54 CSS &nis_data, &nis_data_length)) == 0)
56 *result = string_copy(nis_data);
57 (*result)[nis_data_length] = 0; /* remove final '\n' */
60 return (rc == YPERR_KEY || rc == YPERR_MAP)? FAIL : DEFER;
65 /*************************************************
66 * Find entry point for nis0 *
67 *************************************************/
69 /* See local README for interface description. */
72 nis0_find(void *handle, uschar *filename, uschar *keystring, int length,
73 uschar **result, uschar **errmsg, BOOL *do_cache)
78 do_cache = do_cache; /* Placate picky compilers */
79 if ((rc = yp_match(CS handle, CS filename, CS keystring, length + 1,
80 CSS &nis_data, &nis_data_length)) == 0)
82 *result = string_copy(nis_data);
83 (*result)[nis_data_length] = 0; /* remove final '\n' */
86 return (rc == YPERR_KEY || rc == YPERR_MAP)? FAIL : DEFER;
89 static lookup_info nis_lookup_info = {
90 US"nis", /* lookup name */
91 0, /* not abs file, not query style*/
92 nis_open, /* open function */
93 NULL, /* check function */
94 nis_find, /* find function */
95 NULL, /* no close function */
96 NULL, /* no tidy function */
97 NULL /* no quoting function */
100 static lookup_info nis0_lookup_info = {
101 US"nis0", /* lookup name */
102 0, /* not absfile, not query style */
103 nis_open, /* sic */ /* open function */
104 NULL, /* check function */
105 nis0_find, /* find function */
106 NULL, /* no close function */
107 NULL, /* no tidy function */
108 NULL /* no quoting function */
112 #define nis_lookup_module_info _lookup_module_info
115 static lookup_info *_lookup_list[] = { &nis_lookup_info, &nis0_lookup_info };
116 lookup_module_info nis_lookup_module_info = { LOOKUP_MODULE_INFO_MAGIC, _lookup_list, 2 };
118 /* End of lookups/nis.c */