diff options
| author | Sam Varshavchik | 2013-08-19 16:39:41 -0400 |
|---|---|---|
| committer | Sam Varshavchik | 2013-08-25 14:43:51 -0400 |
| commit | 9c45d9ad13fdf439d44d7443ae75da15ea0223ed (patch) | |
| tree | 7a81a04cb51efb078ee350859a64be2ebc6b8813 /tcpd/tcpdaccess.c | |
| parent | a9520698b770168d1f33d6301463bb70a19655ec (diff) | |
| download | courier-libs-9c45d9ad13fdf439d44d7443ae75da15ea0223ed.tar.bz2 | |
Initial checkin
Imported from subversion report, converted to git. Updated all paths in
scripts and makefiles, reflecting the new directory hierarchy.
Diffstat (limited to 'tcpd/tcpdaccess.c')
| -rw-r--r-- | tcpd/tcpdaccess.c | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/tcpd/tcpdaccess.c b/tcpd/tcpdaccess.c new file mode 100644 index 0000000..9c5b9f6 --- /dev/null +++ b/tcpd/tcpdaccess.c @@ -0,0 +1,68 @@ +/* +** Copyright 1998 - 2000 Double Precision, Inc. +** See COPYING for distribution information. +*/ + +#if HAVE_CONFIG_H +#include "config.h" +#endif +#include <stdio.h> +#include <errno.h> +#include <string.h> +#include <stdlib.h> +#include <ctype.h> +#include "dbobj.h" + + +static struct dbobj db; +static int db_isopen=0, db_isinit=0; + +int openaccess(const char *filename) +{ + if (!db_isinit) + { + dbobj_init(&db); + db_isinit=1; + } + if (db_isopen) + { + dbobj_close(&db); + db_isopen=0; + } + + if (dbobj_open(&db, filename, "R")) + return (-1); + db_isopen=1; + return (0); +} + +void closeaccess() +{ + if (!db_isopen) return; + dbobj_close(&db); + db_isopen=0; +} + +char *chkaccess(const char *ip) +{ +size_t l; +char *p, *q; + + if (!db_isopen) return (0); + + + p=dbobj_fetch(&db, ip, strlen(ip), &l, ""); + + if (!p) return (0); + q=(char *)malloc(l+1); + if (!q) + { + perror("malloc"); + free(p); + return (0); + } + memcpy(q, p, l); + q[l]=0; + free(p); + return (q); +} |
