1 |
/* This file is part of GNU RADIUS. |
/* This file is part of GNU Radius. |
2 |
|
Copyright (C) 2000,2001,2002,2003 Sergey Poznyakoff |
3 |
|
|
4 |
This program is free software; you can redistribute it and/or modify |
GNU Radius is free software; you can redistribute it and/or modify |
5 |
it under the terms of the GNU General Public License as published by |
it under the terms of the GNU General Public License as published by |
6 |
the Free Software Foundation; either version 2 of the License, or |
the Free Software Foundation; either version 2 of the License, or |
7 |
(at your option) any later version. |
(at your option) any later version. |
8 |
|
|
9 |
This program is distributed in the hope that it will be useful, |
GNU Radius is distributed in the hope that it will be useful, |
10 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 |
GNU General Public License for more details. |
GNU General Public License for more details. |
13 |
|
|
14 |
You should have received a copy of the GNU General Public License |
You should have received a copy of the GNU General Public License |
15 |
along with this program; if not, write to the Free Software Foundation, |
along with GNU Radius; if not, write to the Free Software Foundation, |
16 |
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ |
17 |
|
|
18 |
#ifdef HAVE_CONFIG_H |
#ifdef HAVE_CONFIG_H |
21 |
|
|
22 |
#ifdef USE_DBM |
#ifdef USE_DBM |
23 |
|
|
|
#ifndef lint |
|
|
static char rcsid[] = |
|
|
"@(#) $Id$"; |
|
|
#endif |
|
|
|
|
24 |
#include <stdlib.h> |
#include <stdlib.h> |
25 |
#include <unistd.h> |
#include <unistd.h> |
26 |
#include <fcntl.h> |
#include <fcntl.h> |
29 |
#if USE_DBM == DBM_NDBM |
#if USE_DBM == DBM_NDBM |
30 |
|
|
31 |
int |
int |
32 |
open_dbm(name, dbmfile) |
open_dbm(char *name, DBM_FILE *dbmfile) |
|
char *name; |
|
|
DBM_FILE *dbmfile; |
|
33 |
{ |
{ |
34 |
return (*dbmfile = dbm_open(name, O_RDONLY, 0)) == NULL; |
return (*dbmfile = dbm_open(name, O_RDONLY, 0)) == NULL; |
35 |
} |
} |
36 |
|
|
37 |
int |
int |
38 |
create_dbm(name, dbmfile) |
create_dbm(char *name, DBM_FILE *dbmfile) |
|
char *name; |
|
|
DBM_FILE *dbmfile; |
|
39 |
{ |
{ |
40 |
return (*dbmfile = dbm_open(name, O_RDWR|O_CREAT|O_TRUNC, 0600)) |
return (*dbmfile = dbm_open(name, O_RDWR|O_CREAT|O_TRUNC, 0600)) |
41 |
== NULL; |
== NULL; |
42 |
} |
} |
43 |
|
|
44 |
int |
int |
45 |
close_dbm(dbmfile) |
close_dbm(DBM_FILE dbmfile) |
|
DBM_FILE dbmfile; |
|
46 |
{ |
{ |
47 |
dbm_close(dbmfile); |
dbm_close(dbmfile); |
48 |
return 0; |
return 0; |
49 |
} |
} |
50 |
|
|
51 |
int |
int |
52 |
fetch_dbm(dbmfile, key, ret) |
fetch_dbm(DBM_FILE dbmfile, DBM_DATUM key, DBM_DATUM *ret) |
|
DBM_FILE dbmfile; |
|
|
DBM_DATUM key; |
|
|
DBM_DATUM *ret; |
|
53 |
{ |
{ |
54 |
*ret = dbm_fetch(dbmfile, key); |
*ret = dbm_fetch(dbmfile, key); |
55 |
return ret->dptr == NULL; |
return ret->dptr == NULL; |
56 |
} |
} |
57 |
|
|
58 |
int |
int |
59 |
insert_dbm(dbmfile, key, contents) |
insert_dbm(DBM_FILE dbmfile, DBM_DATUM key, DBM_DATUM contents) |
|
DBM_FILE dbmfile; |
|
|
DBM_DATUM key; |
|
|
DBM_DATUM contents; |
|
60 |
{ |
{ |
61 |
return dbm_store(dbmfile, key, contents, DBM_INSERT); |
return dbm_store(dbmfile, key, contents, DBM_INSERT); |
62 |
} |
} |
65 |
|
|
66 |
/*ARGSUSED*/ |
/*ARGSUSED*/ |
67 |
int |
int |
68 |
open_dbm(name, dbmfile) |
open_dbm(char *name, DBM_FILE *dbmfile) |
|
char *name; |
|
|
DBM_FILE *dbmfile; |
|
69 |
{ |
{ |
70 |
return dbminit(name); |
return dbminit(name); |
71 |
} |
} |
72 |
|
|
73 |
int |
int |
74 |
create_dbm(name, dbmfile) |
create_dbm(char *name, DBM_FILE *dbmfile) |
|
char *name; |
|
|
DBM_FILE *dbmfile; |
|
75 |
{ |
{ |
76 |
int fd; |
int fd; |
77 |
char *p; |
char *p; |
96 |
|
|
97 |
/*ARGSUSED*/ |
/*ARGSUSED*/ |
98 |
int |
int |
99 |
close_dbm(dbmfile) |
close_dbm(DBM_FILE dbmfile) |
|
DBM_FILE dbmfile; |
|
100 |
{ |
{ |
101 |
dbmclose(); |
dbmclose(); |
102 |
} |
} |
103 |
|
|
104 |
/*ARGSUSED*/ |
/*ARGSUSED*/ |
105 |
int |
int |
106 |
fetch_dbm(dbmfile, key, ret) |
fetch_dbm(DBM_FILE dbmfile, DBM_DATUM key, DBM_DATUM *ret) |
|
DBM_FILE dbmfile; |
|
|
DBM_DATUM key; |
|
|
DBM_DATUM *ret; |
|
107 |
{ |
{ |
108 |
*ret = fetch(key); |
*ret = fetch(key); |
109 |
return ret->dptr == NULL; |
return ret->dptr == NULL; |
110 |
} |
} |
111 |
|
|
112 |
int |
int |
113 |
insert_dbm(dbmfile, key, contents) |
insert_dbm(DBM_FILE dbmfile, DBM_DATUM key, DBM_DATUM contents) |
|
DBM_FILE dbmfile; |
|
|
DBM_DATUM key; |
|
|
DBM_DATUM contents; |
|
114 |
{ |
{ |
115 |
return store(key, contents); |
return store(key, contents); |
116 |
} |
} |