Update all copyright messages to cover 1995 - 2009. Remove tab from exim_checkaccess.src
[exim.git] / src / src / lookups / nis.c
CommitLineData
0a49a7a4 1/* $Cambridge: exim/src/src/lookups/nis.c,v 1.5 2009/11/16 19:50:38 nm4 Exp $ */
0756eb3c
PH
2
3/*************************************************
4* Exim - an Internet mail transport agent *
5*************************************************/
6
0a49a7a4 7/* Copyright (c) University of Cambridge 1995 - 2009 */
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
15functions if they are not wanted, because we need to have the NIS header
16available for compiling. Therefore, compile these functions only if LOOKUP_NIS
17is defined. However, some compilers don't like compiling empty modules, so keep
18them happy with a dummy when skipping the rest. Make it reference itself to
19stop picky compilers complaining that it is unused, and put in a dummy argument
20to stop even pickier compilers complaining about infinite loops. */
21
22#ifndef LOOKUP_NIS
23static 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
34the "nis" and "nis0" lookup types. */
35
36void *
37nis_open(uschar *filename, uschar **errmsg)
38{
39char *nis_domain;
40if (yp_get_default_domain(&nis_domain) != 0)
41 {
42 *errmsg = string_sprintf("failed to get default NIS domain");
43 return NULL;
44 }
45return 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
55for nis0 because they are so short it isn't worth trying to use any common
56code. */
57
58int
59nis_find(void *handle, uschar *filename, uschar *keystring, int length,
60 uschar **result, uschar **errmsg, BOOL *do_cache)
61{
62int rc;
63uschar *nis_data;
64int nis_data_length;
65do_cache = do_cache; /* Placate picky compilers */
66if ((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 }
73return (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
84int
85nis0_find(void *handle, uschar *filename, uschar *keystring, int length,
86 uschar **result, uschar **errmsg, BOOL *do_cache)
87{
88int rc;
89uschar *nis_data;
90int nis_data_length;
91do_cache = do_cache; /* Placate picky compilers */
92if ((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 }
99return (rc == YPERR_KEY || rc == YPERR_MAP)? FAIL : DEFER;
100}
101
102#endif /* LOOKUP_NIS */
103
104/* End of lookups/nis.c */