~ubuntu-branches/ubuntu/jaunty/avahi/jaunty-updates

« back to all changes in this revision

Viewing changes to avahi-utils/stdb.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2006-09-03 20:25:37 UTC
  • mfrom: (1.1.15 upstream)
  • Revision ID: james.westby@ubuntu.com-20060903202537-syi99j0tijm9bldv
Tags: 0.6.13-2ubuntu1
* Merge with Debian, UVF Exception granted by Colin Watson
* debian/patches/03_foreground-console.patch:
  + Allow only foreground users access to the avahi-set-host-name utility as
    we don't use the "netdev" group anywhere. Thanks to Colin Watson for the
    hint.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: stdb.c 902 2005-10-27 22:49:37Z lennart $ */
 
1
/* $Id: stdb.c 1245 2006-08-06 11:54:31Z lennart $ */
2
2
 
3
3
/***
4
4
  This file is part of avahi.
19
19
  USA.
20
20
***/
21
21
 
 
22
#include <config.h>
 
23
#ifdef HAVE_GDBM
22
24
#include <gdbm.h>
 
25
#endif
 
26
#ifdef HAVE_DBM
 
27
#include <ndbm.h>
 
28
#include <fcntl.h>
 
29
#endif
23
30
#include <stdlib.h>
24
31
#include <string.h>
25
32
#include <locale.h>
29
36
 
30
37
#include "stdb.h"
31
38
 
 
39
#ifdef HAVE_GDBM
32
40
static GDBM_FILE gdbm_file = NULL;
 
41
#endif
 
42
#ifdef HAVE_DBM
 
43
static DBM *dbm_file = NULL;
 
44
#endif
33
45
static char *buffer = NULL;
34
46
 
35
47
static int init(void) {
36
48
 
 
49
#ifdef HAVE_GDBM
37
50
    if (gdbm_file)
38
51
        return 0;
39
52
 
40
53
    if (!(gdbm_file = gdbm_open((char*) DATABASE_FILE, 0, GDBM_READER, 0, NULL)))
41
54
        return -1;
 
55
#endif
 
56
#ifdef HAVE_DBM
 
57
    if (dbm_file)
 
58
        return 0;
 
59
 
 
60
    if (!(dbm_file = dbm_open((char*) DATABASE_FILE, O_RDONLY, 0)))
 
61
        return -1;
 
62
#endif
42
63
 
43
64
    return 0;
44
65
}
59
80
        snprintf(k, sizeof(k), "%s[%s]", name, loc);
60
81
        key.dptr = k;
61
82
        key.dsize = strlen(k);
 
83
#ifdef HAVE_GDBM
62
84
        data = gdbm_fetch(gdbm_file, key);
 
85
#endif
 
86
#ifdef HAVE_DBM
 
87
        data = dbm_fetch(dbm_file, key);
 
88
#endif
63
89
 
64
90
        if (!data.dptr) {
65
91
            char l[32], *e;
70
96
                snprintf(k, sizeof(k), "%s[%s]", name, l);
71
97
                key.dptr = k;
72
98
                key.dsize = strlen(k);
 
99
#ifdef HAVE_GDBM
73
100
                data = gdbm_fetch(gdbm_file, key);
 
101
#endif
 
102
#ifdef HAVE_DBM
 
103
                data = dbm_fetch(dbm_file, key);
 
104
#endif
74
105
            }
75
106
 
76
107
            if (!data.dptr) {
79
110
                    snprintf(k, sizeof(k), "%s[%s]", name, l);
80
111
                    key.dptr = k;
81
112
                    key.dsize = strlen(k);
 
113
#ifdef HAVE_GDBM
82
114
                    data = gdbm_fetch(gdbm_file, key);
 
115
#endif
 
116
#ifdef HAVE_DBM
 
117
                    data = dbm_fetch(dbm_file, key);
 
118
#endif
83
119
                }
84
120
            }
85
121
        }
88
124
    if (!data.dptr) {
89
125
        key.dptr = (char*) name;
90
126
        key.dsize = strlen(name);
 
127
#ifdef HAVE_GDBM
91
128
        data = gdbm_fetch(gdbm_file, key);
 
129
#endif
 
130
#ifdef HAVE_DBM
 
131
        data = dbm_fetch(dbm_file, key);
 
132
#endif
92
133
    }
93
134
 
94
135
    if (!data.dptr)
106
147
}
107
148
 
108
149
void stdb_shutdown(void) {
 
150
#ifdef HAVE_GDBM
109
151
    if (gdbm_file)
110
152
        gdbm_close(gdbm_file);
 
153
#endif
 
154
#ifdef HAVE_DBM
 
155
    if (dbm_file)
 
156
        dbm_close(dbm_file);
 
157
#endif
111
158
 
112
159
    avahi_free(buffer);
113
160
}