2 * Copyright (c) 1997-2014 Erez Zadok
3 * Copyright (c) 1989 Jan-Simon Pendry
4 * Copyright (c) 1989 Imperial College of Science, Technology & Medicine
5 * Copyright (c) 1989 The Regents of the University of California.
8 * This code is derived from software contributed to Berkeley by
9 * Jan-Simon Pendry at Imperial College, London.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * File: am-utils/amd/info_ndbm.c
41 * Get info from NDBM map
46 #endif /* HAVE_CONFIG_H */
51 /* forward declarations */
52 int ndbm_init(mnt_map *m, char *map, time_t *tp);
53 int ndbm_mtime(mnt_map *m, char *map, time_t *tp);
54 int ndbm_search(mnt_map *m, char *map, char *key, char **pval, time_t *tp);
58 search_ndbm(mnt_map *m, DBM *db, char *key, char **val)
63 k.dsize = strlen(key) + 1;
66 if (m->cfm && (m->cfm->cfm_flags & CFM_SUN_MAP_SYNTAX))
67 *val = sun_entry2amd(key, v.dptr);
69 *val = xstrdup(v.dptr);
77 ndbm_search(mnt_map *m, char *map, char *key, char **pval, time_t *tp)
81 db = dbm_open(map, O_RDONLY, 0);
88 xstrlcpy(dbfilename, map, sizeof(dbfilename));
89 xstrlcat(dbfilename, DBM_SUFFIX, sizeof(dbfilename));
90 error = stat(dbfilename, &stb);
91 #else /* not DBM_SUFFIX */
92 error = fstat(dbm_pagfno(db), &stb);
93 #endif /* not DBM_SUFFIX */
94 if (!error && *tp < stb.st_mtime) {
98 error = search_ndbm(m, db, key, pval);
100 (void) dbm_close(db);
108 ndbm_init(mnt_map *m, char *map, time_t *tp)
112 db = dbm_open(map, O_RDONLY, 0);
117 char dbfilename[256];
119 xstrlcpy(dbfilename, map, sizeof(dbfilename));
120 xstrlcat(dbfilename, DBM_SUFFIX, sizeof(dbfilename));
121 error = stat(dbfilename, &stb);
122 #else /* not DBM_SUFFIX */
123 error = fstat(dbm_pagfno(db), &stb);
124 #endif /* not DBM_SUFFIX */
126 *tp = clocktime(NULL);
137 ndbm_mtime(mnt_map *m, char *map, time_t *tp)
139 return ndbm_init(m,map, tp);