xref: /original-bsd/usr.sbin/amd/amd/info_hes.c (revision 92ab646d)
1 /*
2  * $Id: info_hes.c,v 5.2 90/06/23 22:19:30 jsp Rel $
3  *
4  * Copyright (c) 1989 Jan-Simon Pendry
5  * Copyright (c) 1989 Imperial College of Science, Technology & Medicine
6  * Copyright (c) 1989 The Regents of the University of California.
7  * All rights reserved.
8  *
9  * This code is derived from software contributed to Berkeley by
10  * Jan-Simon Pendry at Imperial College, London.
11  *
12  * %sccs.include.redist.c%
13  *
14  *	@(#)info_hes.c	5.1 (Berkeley) 06/29/90
15  */
16 
17 /*
18  * Get info from Hesiod
19  */
20 
21 #include "am.h"
22 
23 #ifdef HAS_HESIOD_MAPS
24 #include <hesiod.h>
25 
26 #define	HES_PREFIX	"hesiod."
27 #define	HES_PREFLEN	7
28 
29 /*
30  * No way to probe the server - check the map name begins with "hesiod."
31  */
32 hesiod_init(map)
33 char *map;
34 {
35 	return strncmp(map, HES_PREFIX, HES_PREFLEN) == 0 ? 0 : ENOENT;
36 }
37 
38 
39 /*
40  * Do a Hesiod nameserver call.
41  * Modify time is ignored by Hesiod - XXX
42  */
43 int hesiod_search(m, map, key, pval, tp)
44 mnt_map *m;
45 char *map;
46 char *key;
47 char **pval;
48 time_t *tp;
49 {
50 	int error;
51 	char hes_map[MAXPATHLEN];
52 	char **rvec;
53 	/*
54 	 * Make Hesiod name.  Skip past the "hesiod."
55 	 * at the start of the map name and append
56 	 * ".automount".  The net effect is that a lookup
57 	 * of /defaults in hesiod.home will result in a
58 	 * call to hes_resolve("/defaults", "home.automount");
59 	 */
60 	sprintf(hes_map, "%s%s", map + HES_PREFLEN, ".automount");
61 	/*
62 	 * Call the resolver
63 	 */
64 	rvec = hes_resolve(key, hes_map);
65 	/*
66 	 * If a reply was forthcoming then return
67 	 * it (and free subsequent replies)
68 	 */
69 	if (rvec && *rvec) {
70 		*pval = *rvec;
71 		while (*++rvec)
72 			free(*rvec);
73 		return 0;
74 	}
75 
76 	/*
77 	 * Otherwise reflect the hesiod error into a Un*x error
78 	 */
79 	switch (hes_error()) {
80 	case HES_ER_NOTFOUND:	error = ENOENT; break;
81 	case HES_ER_CONFIG:	error = EIO; break;
82 	case HES_ER_NET:	error = ETIMEDOUT; break;
83 	default:		error = EINVAL; break;
84 	}
85 	return error;
86 }
87 #endif /* HAS_HESIOD_MAPS */
88