• Home
  • History
  • Annotate
  • Line#
  • Navigate
  • Raw
  • Download
  • only in /asuswrt-rt-n18u-9.0.0.4.380.2695/release/src-rt-6.x.4708/router/netatalk-3.0.5/libatalk/cnid/cdb/
1#ifdef HAVE_CONFIG_H
2#include "config.h"
3#endif /* HAVE_CONFIG_H */
4
5#ifdef CNID_BACKEND_CDB
6#include "cnid_cdb_private.h"
7
8/* Return CNID for a given did/name. */
9cnid_t cnid_cdb_get(struct _cnid_db *cdb, cnid_t did, const char *name, size_t len)
10{
11    char start[CNID_DID_LEN + MAXPATHLEN + 1], *buf;
12    CNID_private *db;
13    DBT key, data;
14    cnid_t id;
15    int rc;
16
17    if (!cdb || !(db = cdb->_private) || (len > MAXPATHLEN)) {
18        return 0;
19    }
20
21    memset(&key, 0, sizeof(key));
22    memset(&data, 0, sizeof(data));
23
24    buf = start;
25    memcpy(buf, &did, sizeof(did));
26    buf += sizeof(did);
27    memcpy(buf, name, len);
28    *(buf + len) = '\0'; /* Make it a C-string. */
29    key.data = start;
30    key.size = CNID_DID_LEN + len + 1;
31
32    while ((rc = db->db_didname->get(db->db_didname, NULL, &key, &data, 0))) {
33
34        if (rc != DB_NOTFOUND) {
35            LOG(log_error, logtype_default, "cnid_get: Unable to get CNID %u, name %s: %s",
36                ntohl(did), name, db_strerror(rc));
37        }
38
39        return 0;
40    }
41
42    memcpy(&id, data.data, sizeof(id));
43#ifdef DEBUG
44    LOG(log_debug9, logtype_default, "cnid_get: Returning CNID for %u, name %s as %u",
45        ntohl(did), name, ntohl(id));
46#endif
47    return id;
48}
49
50#endif /* CNID_BACKEND_CDB */
51