gen.c revision ab023a65562e62b85a824509d829b6fad87e00b1
990d0e893f5b70e735cdf990af66e9ec6e91fa78Tinderbox User * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * Copyright (c) 1996-1999 by Internet Software Consortium.
4a14ce5ba00ab7bc55c99ffdcf59c7a4ab902721Automatic Updater * Permission to use, copy, modify, and distribute this software for any
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * purpose with or without fee is hereby granted, provided that the above
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * copyright notice and this permission notice appear in all copies.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrewsstatic const char rcsid[] = "$Id: gen.c,v 1.7 2005/04/27 04:56:23 sra Exp $";
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * this is the top level dispatcher
c3dc968140ab7f04795acc7835e4e89ccb0c0a27Tinderbox User * The dispatcher is implemented as an accessor class; it is an
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * accessor class that calls other accessor classes, as controlled by a
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * configuration file.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * A big difference between this accessor class and others is that the
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * map class initializers are NULL, and the map classes are already
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews * filled in with method functions that will do the right thing.
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews/* Imports */
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews/* Definitions */
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews const char * name;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrewsstatic const struct nameval acc_names[irs_nacc+1] = {
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updatertypedef struct irs_acc *(*accinit) __P((const char *options));
be6c1c506161e6f45fcff5d0425f78801bc267c1Automatic Updaterstatic const struct nameval map_names[irs_nmap+1] = {
8ec3c085233cedb22b05da36e2773c8f357a7e45Automatic Updaterstatic const struct nameval option_names[] = {
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox Userstatic struct __res_state * gen_res_get(struct irs_acc *);
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox Userstatic void gen_res_set(struct irs_acc *, struct __res_state *,
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox User void (*)(void *));
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox Userstatic int find_name(const char *, const struct nameval nv[]);
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox Userstatic void init_map_rules(struct gen_p *, const char *conf_file);
6ea2385360e9e2167e65f9286447da9eea189457Tinderbox Userstatic struct irs_rule *release_rule(struct irs_rule *);
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater const char *);
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updaterirs_gen_acc(const char *options, const char *conf_file) {
0e1dece22e128f9dfa723316a35c4b3f06912381Tinderbox User memset(irs->accessors, 0, sizeof irs->accessors);
0e1dece22e128f9dfa723316a35c4b3f06912381Tinderbox User memset(irs->map_rules, 0, sizeof irs->map_rules);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews/* Methods */
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrewsstatic struct __res_state *
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews struct gen_p *irs = (struct gen_p *)this->private;
2895f101b5585a19015ac2c2c1e1812ac467fa12Automatic Updater res = (struct __res_state *)malloc(sizeof *res);
60a900e83bab52c3f023be66654f3ab023172778Automatic Updater if (((irs->res->options & RES_INIT) == 0U) && res_ninit(irs->res) < 0)
60a900e83bab52c3f023be66654f3ab023172778Automatic Updatergen_res_set(struct irs_acc *this, struct __res_state *res,
60a900e83bab52c3f023be66654f3ab023172778Automatic Updater void (*free_res)(void *)) {
60a900e83bab52c3f023be66654f3ab023172778Automatic Updater struct gen_p *irs = (struct gen_p *)this->private;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews for (rule = irs->map_rules[irs_ho]; rule; rule = rule->next) {
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews for (rule = irs->map_rules[irs_nw]; rule; rule = rule->next) {
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews struct gen_p *irs = (struct gen_p *)this->private;
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews /* Search rules. */
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews for (n = 0; n < irs_nmap; n++)
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews irs->map_rules[n] = release_rule(irs->map_rules[n]);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews /* Access methods. */
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews for (n = 0; n < irs_nacc; n++) {
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews /* Map objects. */
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews (*irs->accessors[n].gr->close)(irs->accessors[n].gr);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews (*irs->accessors[n].pw->close)(irs->accessors[n].pw);
dba3c818ae00b10388d31703e86a28415db398acTinderbox User (*irs->accessors[n].sv->close)(irs->accessors[n].sv);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews (*irs->accessors[n].pr->close)(irs->accessors[n].pr);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews (*irs->accessors[n].ho->close)(irs->accessors[n].ho);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews (*irs->accessors[n].nw->close)(irs->accessors[n].nw);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews (*irs->accessors[n].ng->close)(irs->accessors[n].ng);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews /* Enclosing accessor. */
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews (*irs->accessors[n].acc->close)(irs->accessors[n].acc);
d71e2e0c61df16ff37c9934c371a4a60c08974f7Mark Andrews /* The options string was strdup'd. */
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews /* The private data container. */
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews /* The object. */
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews/* Private */
97e74139b19368e385a3564746d42db70879195eAutomatic Updaterfind_name(const char *name, const struct nameval names[]) {
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews return (-1);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrewsstatic struct irs_rule *
52ece689e0265f9a3e518de5b2539e749f6d35acMark Andrews const char *cp;
52ece689e0265f9a3e518de5b2539e749f6d35acMark Andrews return (-1);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews return (-1);
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews return (-1);
7717ec7a6a898cdd3c35cbfba66010b7304ffd9bAutomatic Updater /* Try to instantiate map accessors for this if necessary & approp. */
3f9791eac42b243d9f328d604e117f91a3f67a37Tinderbox User if (inst->gr == NULL && inst->acc->gr_map != NULL)
3f9791eac42b243d9f328d604e117f91a3f67a37Tinderbox User if (inst->pw == NULL && inst->acc->pw_map != NULL)
3f9791eac42b243d9f328d604e117f91a3f67a37Tinderbox User if (inst->sv == NULL && inst->acc->sv_map != NULL)
3f9791eac42b243d9f328d604e117f91a3f67a37Tinderbox User if (inst->pr == NULL && inst->acc->pr_map != NULL)
3f9791eac42b243d9f328d604e117f91a3f67a37Tinderbox User if (inst->ho == NULL && inst->acc->ho_map != NULL)
3f9791eac42b243d9f328d604e117f91a3f67a37Tinderbox User if (inst->nw == NULL && inst->acc->nw_map != NULL)
3f9791eac42b243d9f328d604e117f91a3f67a37Tinderbox User if (inst->ng == NULL && inst->acc->ng_map != NULL)
5a4557e8de2951a2796676b5ec4b6a90caa5be14Mark Andrews /* Install time honoured and proved BSD style rules as default. */
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updaterinit_map_rules(struct gen_p *irs, const char *conf_file) {
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater char line[1024], pattern[40], mapname[20], accname[20], options[100];
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater /* A conf file of "" means compiled in defaults. Irpd wants this */
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater if (conf_file[0] == '\0' || (conf = fopen(conf_file, "r")) == NULL) {
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater (void) sprintf(pattern, "%%%lus %%%lus %%%lus\n",
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater (unsigned long)sizeof mapname,
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater (unsigned long)sizeof accname,
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater (unsigned long)sizeof options);
0a7ed88633a680bb881868b75ded4d09a7bbbc50Automatic Updater if (*tmp == '#' || *tmp == '\n' || *tmp == '\0')