~ubuntu-branches/debian/lenny/netatalk/lenny

« back to all changes in this revision

Viewing changes to libatalk/cnid/cnid_get.c

  • Committer: Bazaar Package Importer
  • Author(s): Ante Karamatic
  • Date: 2005-10-07 13:46:11 UTC
  • mfrom: (1.1.2 upstream) (2.1.1 sarge)
  • Revision ID: james.westby@ubuntu.com-20051007134611-r07qa2g67xwkp2if
Tags: 2.0.3-1ubuntu1
* debian/netatalk.init
  - run cnid_metad if CNID_METAD_RUN=yes

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * $Id: cnid_get.c,v 1.13 2002/08/30 03:12:52 jmarcus Exp $
3
 
 */
4
 
 
5
 
#ifdef HAVE_CONFIG_H
6
 
#include "config.h"
7
 
#endif /* HAVE_CONFIG_H */
8
 
 
9
 
#ifdef CNID_DB
10
 
#include <stdio.h>
11
 
#include <string.h>
12
 
#include <sys/param.h>
13
 
#include <sys/stat.h>
14
 
#include <atalk/logger.h>
15
 
#include <errno.h>
16
 
 
17
 
#include <db.h>
18
 
#include <netatalk/endian.h>
19
 
#include <atalk/adouble.h>
20
 
#include <atalk/cnid.h>
21
 
 
22
 
#include "cnid_private.h"
23
 
 
24
 
/* Return CNID for a given did/name. */
25
 
cnid_t cnid_get(void *CNID, const cnid_t did, const char *name,
26
 
                const int len)
27
 
{
28
 
    char start[CNID_DID_LEN + MAXPATHLEN + 1], *buf;
29
 
    CNID_private *db;
30
 
    DBT key, data;
31
 
    cnid_t id;
32
 
    int rc;
33
 
 
34
 
    if (!(db = CNID) || (len > MAXPATHLEN)) {
35
 
        return 0;
36
 
    }
37
 
 
38
 
    memset(&key, 0, sizeof(key));
39
 
    memset(&data, 0, sizeof(data));
40
 
 
41
 
    buf = start;
42
 
    memcpy(buf, &did, sizeof(did));
43
 
    buf += sizeof(did);
44
 
    memcpy(buf, name, len);
45
 
    *(buf + len) = '\0'; /* Make it a C-string. */
46
 
    key.data = start;
47
 
    key.size = CNID_DID_LEN + len + 1;
48
 
 
49
 
    while ((rc = db->db_didname->get(db->db_didname, NULL, &key, &data, 0))) {
50
 
#ifndef CNID_DB_CDB
51
 
        if (rc == DB_LOCK_DEADLOCK) {
52
 
            continue;
53
 
        }
54
 
#endif /* CNID_DB_CDB */
55
 
 
56
 
        if (rc != DB_NOTFOUND) {
57
 
            LOG(log_error, logtype_default, "cnid_get: Unable to get CNID %u, name %s: %s",
58
 
                ntohl(did), name, db_strerror(rc));
59
 
        }
60
 
 
61
 
        return 0;
62
 
    }
63
 
 
64
 
    memcpy(&id, data.data, sizeof(id));
65
 
#ifdef DEBUG
66
 
    LOG(log_info, logtype_default, "cnid_get: Returning CNID for %u, name %s as %u",
67
 
        ntohl(did), name, ntohl(id));
68
 
#endif
69
 
    return id;
70
 
}
71
 
#endif /* CNID_DB */