diff options
Diffstat (limited to 'contrib/bind/lib/irs/nis.c')
| -rw-r--r-- | contrib/bind/lib/irs/nis.c | 61 |
1 files changed, 54 insertions, 7 deletions
diff --git a/contrib/bind/lib/irs/nis.c b/contrib/bind/lib/irs/nis.c index d53bde9699e7..fcd9b79428c7 100644 --- a/contrib/bind/lib/irs/nis.c +++ b/contrib/bind/lib/irs/nis.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 1998 by Internet Software Consortium. + * Copyright (c) 1996-1999 by Internet Software Consortium. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -16,7 +16,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static const char rcsid[] = "$Id: nis.c,v 1.10 1998/03/21 00:59:50 halley Exp $"; +static const char rcsid[] = "$Id: nis.c,v 1.13 1999/01/18 07:46:58 vixie Exp $"; #endif /* Imports */ @@ -34,6 +34,12 @@ static const char rcsid[] = "$Id: nis.c,v 1.10 1998/03/21 00:59:50 halley Exp $" #include <string.h> #include <errno.h> +#include <sys/types.h> +#include <netinet/in.h> +#include <arpa/nameser.h> +#include <resolv.h> + +#include <isc/memcluster.h> #include <irs.h> #include "port_after.h" @@ -45,6 +51,9 @@ static const char rcsid[] = "$Id: nis.c,v 1.10 1998/03/21 00:59:50 halley Exp $" /* Forward */ static void nis_close(struct irs_acc *); +static struct __res_state * nis_res_get(struct irs_acc *); +static void nis_res_set(struct irs_acc *, struct __res_state *, + void (*)(void *)); /* Public */ @@ -56,13 +65,13 @@ irs_nis_acc(const char *options) { if (yp_get_default_domain(&domain) != 0) return (NULL); - if (!(nis = malloc(sizeof *nis))) { + if (!(nis = memget(sizeof *nis))) { errno = ENOMEM; return (NULL); } memset(nis, 0, sizeof *nis); - if (!(acc = malloc(sizeof *acc))) { - free(nis); + if (!(acc = memget(sizeof *acc))) { + memput(nis, sizeof *nis); errno = ENOMEM; return (NULL); } @@ -84,19 +93,57 @@ irs_nis_acc(const char *options) { acc->ho_map = irs_nis_ho; acc->nw_map = irs_nis_nw; acc->ng_map = irs_nis_ng; + acc->res_get = nis_res_get; + acc->res_set = nis_res_set; acc->close = nis_close; return (acc); } /* Methods */ +static struct __res_state * +nis_res_get(struct irs_acc *this) { + struct nis_p *nis = (struct nis_p *)this->private; + + if (nis->res == NULL) { + struct __res_state *res; + res = (struct __res_state *)malloc(sizeof *res); + if (res == NULL) + return (NULL); + memset(res, 0, sizeof *res); + nis_res_set(this, res, free); + } + + if ((nis->res->options | RES_INIT) == 0 && + res_ninit(nis->res) < 0) + return (NULL); + + return (nis->res); +} + +static void +nis_res_set(struct irs_acc *this, struct __res_state *res, + void (*free_res)(void *)) { + struct nis_p *nis = (struct nis_p *)this->private; + + if (nis->res && nis->free_res) { + res_nclose(nis->res); + (*nis->free_res)(nis->res); + } + + nis->res = res; + nis->free_res = free_res; +} + static void nis_close(struct irs_acc *this) { struct nis_p *nis = (struct nis_p *)this->private; + if (nis->res && nis->free_res) + (*nis->free_res)(nis->res); free(nis->domain); - free(nis); - free(this); + memput(nis, sizeof *nis); + memput(this, sizeof *this); } #endif /*WANT_IRS_NIS*/ |
