summaryrefslogtreecommitdiffstats
path: root/servers/slapd/back-shell/config.c
blob: 9aa26b8629b72a13f6763c1b070520129db9d134 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/* config.c - shell backend configuration file routine */
/* $OpenLDAP$ */
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
 *
 * Copyright 1998-2018 The OpenLDAP Foundation.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted only as authorized by the OpenLDAP
 * Public License.
 *
 * A copy of this license is available in the file LICENSE in the
 * top-level directory of the distribution or, alternatively, at
 * <http://www.OpenLDAP.org/license.html>.
 */
/* Portions Copyright (c) 1995 Regents of the University of Michigan.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms are permitted
 * provided that this notice is preserved and that due credit is given
 * to the University of Michigan at Ann Arbor. The name of the University
 * may not be used to endorse or promote products derived from this
 * software without specific prior written permission. This software
 * is provided ``as is'' without express or implied warranty.
 */
/* ACKNOWLEDGEMENTS:
 * This work was originally developed by the University of Michigan
 * (as part of U-MICH LDAP).
 */

#include "portable.h"

#include <stdio.h>

#include <ac/string.h>
#include <ac/socket.h>

#include "slap.h"
#include "shell.h"
#include "config.h"

static ConfigDriver shell_cf;

enum {
	SHELL_BIND = 0,
	SHELL_UNBIND = 1,
	SHELL_SEARCH,
	SHELL_COMPARE,
	SHELL_MODIFY,
	SHELL_MODRDN,
	SHELL_ADD,
	SHELL_DELETE
};

static ConfigTable shellcfg[] = {
	{ "bind", "args", 2, 0, 0, ARG_MAGIC|SHELL_BIND, shell_cf,
		"( OLcfgDbAt:10.1 NAME 'olcShellBind' "
			"DESC 'Bind command and arguments' "
			"EQUALITY caseExactMatch "
			"SYNTAX OMsDirectoryString SINGLE-VALUE ) ", NULL, NULL },
	{ "unbind", "args", 2, 0, 0, ARG_MAGIC|SHELL_UNBIND, shell_cf,
		"( OLcfgDbAt:10.2 NAME 'olcShellUnbind' "
			"DESC 'Unbind command and arguments' "
			"EQUALITY caseExactMatch "
			"SYNTAX OMsDirectoryString SINGLE-VALUE ) ", NULL, NULL },
	{ "search", "args", 2, 0, 0, ARG_MAGIC|SHELL_SEARCH, shell_cf,
		"( OLcfgDbAt:10.3 NAME 'olcShellSearch' "
			"DESC 'Search command and arguments' "
			"EQUALITY caseExactMatch "
			"SYNTAX OMsDirectoryString SINGLE-VALUE ) ", NULL, NULL },
	{ "compare", "args", 2, 0, 0, ARG_MAGIC|SHELL_COMPARE, shell_cf,
		"( OLcfgDbAt:10.4 NAME 'olcShellCompare' "
			"DESC 'Compare command and arguments' "
			"EQUALITY caseExactMatch "
			"SYNTAX OMsDirectoryString SINGLE-VALUE ) ", NULL, NULL },
	{ "modify", "args", 2, 0, 0, ARG_MAGIC|SHELL_MODIFY, shell_cf,
		"( OLcfgDbAt:10.5 NAME 'olcShellModify' "
			"DESC 'Modify command and arguments' "
			"EQUALITY caseExactMatch "
			"SYNTAX OMsDirectoryString SINGLE-VALUE ) ", NULL, NULL },
	{ "modrdn", "args", 2, 0, 0, ARG_MAGIC|SHELL_MODRDN, shell_cf,
		"( OLcfgDbAt:10.6 NAME 'olcShellModRDN' "
			"DESC 'ModRDN command and arguments' "
			"EQUALITY caseExactMatch "
			"SYNTAX OMsDirectoryString SINGLE-VALUE ) ", NULL, NULL },
	{ "add", "args", 2, 0, 0, ARG_MAGIC|SHELL_ADD, shell_cf,
		"( OLcfgDbAt:10.7 NAME 'olcShellAdd' "
			"DESC 'Add command and arguments' "
			"EQUALITY caseExactMatch "
			"SYNTAX OMsDirectoryString SINGLE-VALUE ) ", NULL, NULL },
	{ "delete", "args", 2, 0, 0, ARG_MAGIC|SHELL_DELETE, shell_cf,
		"( OLcfgDbAt:10.8 NAME 'olcShellDelete' "
			"DESC 'Delete command and arguments' "
			"EQUALITY caseExactMatch "
			"SYNTAX OMsDirectoryString SINGLE-VALUE ) ", NULL, NULL },
	{ NULL }
};

static ConfigOCs shellocs[] = {
	{ "( OLcfgDbOc:10.1 "
		"NAME 'olcShellConfig'  "
		"DESC 'Shell backend configuration' "
		"SUP olcDatabaseConfig "
		"MAY ( olcShellBind $ olcShellUnbind $ olcShellSearch $ "
			"olcShellCompare $ olcShellModify $ olcShellModRDN $ "
			"olcShellAdd $ olcShellDelete ) )",
				Cft_Database, shellcfg },
	{ NULL }
};

static int
shell_cf( ConfigArgs *c )
{
	struct shellinfo	*si = (struct shellinfo *) c->be->be_private;
	char ***arr = &si->si_bind;

	if ( c->op == SLAP_CONFIG_EMIT ) {
		struct berval bv;
		if ( !arr[c->type] ) return 1;
		bv.bv_val = ldap_charray2str( arr[c->type], " " );
		bv.bv_len = strlen( bv.bv_val );
		ber_bvarray_add( &c->rvalue_vals, &bv );
	} else if ( c->op == LDAP_MOD_DELETE ) {
		ldap_charray_free( arr[c->type] );
		arr[c->type] = NULL;
	} else {
		arr[c->type] = ldap_charray_dup( &c->argv[1] );
	}
	return 0;
}

int
shell_back_init_cf( BackendInfo *bi )
{
	bi->bi_cf_ocs = shellocs;
	return config_register_schema( shellcfg, shellocs );
}