Lines Matching defs:?

0 /*	$NetBSD$	*/
4 * Copyright (c) 1997-2014 Erez Zadok
5 * Copyright (c) 1989 Jan-Simon Pendry
6 * Copyright (c) 1989 Imperial College of Science, Technology & Medicine
7 * Copyright (c) 1989 The Regents of the University of California.
8 * All rights reserved.
11 * Jan-Simon Pendry at Imperial College, London.
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its contributors
23 * without specific prior written permission.
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
35 * SUCH DAMAGE.
38 * File: am-utils/amd/info_hesiod.c
47 # include <config.h>
49 #include <am_defs.h>
50 #include <amd.h>
51 #include <sun_map.h>
53 #define HES_PREFIX "hesiod."
54 #define HES_PREFLEN 7
64 int amu_hesiod_init(mnt_map *m, char *map, time_t *tp);
65 int hesiod_search(mnt_map *m, char *map, char *key, char **pval, time_t *tp);
66 int hesiod_isup(mnt_map *m, char *map);
69 * No easy way to probe the server - check the map name begins with "hesiod."
70 * Note: this name includes 'amu_' so as to not conflict with libhesiod's
71 * hesiod_init() function.
74 amu_hesiod_init(mnt_map *m, char *map, time_t *tp)
76 dlog("amu_hesiod_init(%s)", map);
77 *tp = 0;
80 if (!hesiod_context && hesiod_init(&hesiod_context) != 0)
84 return NSTREQ(map, HES_PREFIX, HES_PREFLEN) ? 0 : ENOENT;
89 * Do a Hesiod nameserver call.
90 * Modify time is ignored by Hesiod - XXX
93 hesiod_search(mnt_map *m, char *map, char *key, char **pval, time_t *tp)
101 dlog("hesiod_search(m=%lx, map=%s, key=%s, pval=%lx tp=%lx)",
102 (unsigned long) m, map, key, (unsigned long) pval, (unsigned long) tp);
104 if (key[0] == '.')
107 xsnprintf(hes_key, sizeof(hes_key), "%s.%s", key, map + HES_PREFLEN);
112 dlog("Hesiod base is: %s\n", gopt.hesiod_base);
113 dlog("hesiod_search: hes_resolve(%s, %s)", hes_key, gopt.hesiod_base);
115 _res.options |= RES_DEBUG;
119 rvec = hesiod_resolve(hesiod_context, hes_key, gopt.hesiod_base);
121 rvec = hes_resolve(hes_key, gopt.hesiod_base);
125 * If a reply was forthcoming then return
128 if (rvec && *rvec) {
129 if (m->cfm && (m->cfm->cfm_flags & CFM_SUN_MAP_SYNTAX)) {
130 *pval = sun_entry2amd(key, *rvec);
133 *pval = *rvec;
134 while (*++rvec)
136 return 0;
144 * Otherwise reflect the hesiod error into a Un*x error
146 dlog("hesiod_search: Error: %d", hes_error());
148 case HES_ER_NOTFOUND:
149 error = ENOENT;
151 case HES_ER_CONFIG:
152 error = EIO;
154 case HES_ER_NET:
155 error = ETIMEDOUT;
157 default:
158 error = EINVAL;
161 dlog("hesiod_search: Returning: %d", error);
168 * Check if Hesiod is up, so we can determine if to clear the map or not.
169 * Test it by querying for /defaults.
170 * Returns: 0 if Hesiod is down, 1 if it is up.
173 hesiod_isup(mnt_map *m, char *map)
178 static int last_status = 1; /* assume up by default */
180 error = hesiod_search(m, map, "/defaults", &val, &mtime);
181 dlog("hesiod_isup(%s): %s", map, strerror(error));
182 if (error != 0 && error != ENOENT) {
184 "hesiod_isup: error getting `/defaults' entry in map %s: %m", map);
185 last_status = 0;
186 return 0; /* Hesiod is down */
188 if (last_status == 0) { /* if was down before */
189 plog(XLOG_INFO, "hesiod_isup: Hesiod came back up for map %s", map);
190 last_status = 1;
192 return 1; /* Hesiod is up */