config.c revision 1.1.1.3
1/*	$NetBSD: config.c,v 1.1.1.3 2010/12/12 15:23:22 adam Exp $	*/
2
3/* config.c - sock backend configuration file routine */
4/* OpenLDAP: pkg/ldap/servers/slapd/back-sock/config.c,v 1.5.2.3 2010/04/13 20:23:40 kurt Exp */
5/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
6 *
7 * Copyright 2007-2010 The OpenLDAP Foundation.
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted only as authorized by the OpenLDAP
12 * Public License.
13 *
14 * A copy of this license is available in the file LICENSE in the
15 * top-level directory of the distribution or, alternatively, at
16 * <http://www.OpenLDAP.org/license.html>.
17 */
18/* ACKNOWLEDGEMENTS:
19 * This work was initially developed by Brian Candler for inclusion
20 * in OpenLDAP Software. Dynamic config support by Howard Chu.
21 */
22
23#include "portable.h"
24
25#include <stdio.h>
26
27#include <ac/string.h>
28#include <ac/socket.h>
29
30#include "slap.h"
31#include "config.h"
32#include "back-sock.h"
33
34static ConfigDriver bs_cf_gen;
35
36enum {
37	BS_EXT = 1
38};
39
40static ConfigTable bscfg[] = {
41	{ "socketpath", "pathname", 2, 2, 0, ARG_STRING|ARG_OFFSET,
42		(void *)offsetof(struct sockinfo, si_sockpath),
43		"( OLcfgDbAt:7.1 NAME 'olcDbSocketPath' "
44			"DESC 'Pathname for Unix domain socket' "
45			"EQUALITY caseExactMatch "
46			"SYNTAX OMsDirectoryString SINGLE-VALUE )", NULL, NULL },
47	{ "extensions", "ext", 2, 0, 0, ARG_MAGIC|BS_EXT,
48		bs_cf_gen, "( OLcfgDbAt:7.2 NAME 'olcDbSocketExtensions' "
49			"DESC 'binddn, peername, or ssf' "
50			"EQUALITY caseIgnoreMatch "
51			"SYNTAX OMsDirectoryString )", NULL, NULL },
52	{ NULL, NULL }
53};
54
55static ConfigOCs bsocs[] = {
56	{ "( OLcfgDbOc:7.1 "
57		"NAME 'olcDbSocketConfig' "
58		"DESC 'Socket backend configuration' "
59		"SUP olcDatabaseConfig "
60		"MUST olcDbSocketPath "
61		"MAY olcDbSocketExtensions )",
62			Cft_Database, bscfg },
63	{ NULL, 0, NULL }
64};
65
66static slap_verbmasks bs_exts[] = {
67	{ BER_BVC("binddn"), SOCK_EXT_BINDDN },
68	{ BER_BVC("peername"), SOCK_EXT_PEERNAME },
69	{ BER_BVC("ssf"), SOCK_EXT_SSF },
70	{ BER_BVNULL, 0 }
71};
72
73static int
74bs_cf_gen( ConfigArgs *c )
75{
76	struct sockinfo	*si = c->be->be_private;
77	int rc;
78
79	if ( c->op == SLAP_CONFIG_EMIT ) {
80		switch( c->type ) {
81		case BS_EXT:
82			return mask_to_verbs( bs_exts, si->si_extensions, &c->rvalue_vals );
83		}
84	} else if ( c->op == LDAP_MOD_DELETE ) {
85		switch( c->type ) {
86		case BS_EXT:
87			if ( c->valx < 0 ) {
88				si->si_extensions = 0;
89				rc = 0;
90			} else {
91				slap_mask_t dels = 0;
92				rc = verbs_to_mask( c->argc, c->argv, bs_exts, &dels );
93				if ( rc == 0 )
94					si->si_extensions ^= dels;
95			}
96			return rc;
97		}
98
99	} else {
100		switch( c->type ) {
101		case BS_EXT:
102			return verbs_to_mask( c->argc, c->argv, bs_exts, &si->si_extensions );
103		}
104	}
105	return 1;
106}
107
108int
109sock_back_init_cf( BackendInfo *bi )
110{
111	bi->bi_cf_ocs = bsocs;
112
113	return config_register_schema( bscfg, bsocs );
114}
115