1 /* config.c - shell backend configuration file routine */
2 /* $OpenLDAP$ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4  *
5  * Copyright 1998-2021 The OpenLDAP Foundation.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted only as authorized by the OpenLDAP
10  * Public License.
11  *
12  * A copy of this license is available in the file LICENSE in the
13  * top-level directory of the distribution or, alternatively, at
14  * <http://www.OpenLDAP.org/license.html>.
15  */
16 /* Portions Copyright (c) 1995 Regents of the University of Michigan.
17  * All rights reserved.
18  *
19  * Redistribution and use in source and binary forms are permitted
20  * provided that this notice is preserved and that due credit is given
21  * to the University of Michigan at Ann Arbor. The name of the University
22  * may not be used to endorse or promote products derived from this
23  * software without specific prior written permission. This software
24  * is provided ``as is'' without express or implied warranty.
25  */
26 /* ACKNOWLEDGEMENTS:
27  * This work was originally developed by the University of Michigan
28  * (as part of U-MICH LDAP).
29  */
30 
31 #include "portable.h"
32 
33 #include <stdio.h>
34 
35 #include <ac/string.h>
36 #include <ac/socket.h>
37 
38 #include "slap.h"
39 #include "shell.h"
40 #include "config.h"
41 
42 static ConfigDriver shell_cf;
43 
44 enum {
45 	SHELL_BIND = 0,
46 	SHELL_UNBIND = 1,
47 	SHELL_SEARCH,
48 	SHELL_COMPARE,
49 	SHELL_MODIFY,
50 	SHELL_MODRDN,
51 	SHELL_ADD,
52 	SHELL_DELETE
53 };
54 
55 static ConfigTable shellcfg[] = {
56 	{ "bind", "args", 2, 0, 0, ARG_MAGIC|SHELL_BIND, shell_cf,
57 		"( OLcfgDbAt:10.1 NAME 'olcShellBind' "
58 			"DESC 'Bind command and arguments' "
59 			"EQUALITY caseExactMatch "
60 			"SYNTAX OMsDirectoryString SINGLE-VALUE ) ", NULL, NULL },
61 	{ "unbind", "args", 2, 0, 0, ARG_MAGIC|SHELL_UNBIND, shell_cf,
62 		"( OLcfgDbAt:10.2 NAME 'olcShellUnbind' "
63 			"DESC 'Unbind command and arguments' "
64 			"EQUALITY caseExactMatch "
65 			"SYNTAX OMsDirectoryString SINGLE-VALUE ) ", NULL, NULL },
66 	{ "search", "args", 2, 0, 0, ARG_MAGIC|SHELL_SEARCH, shell_cf,
67 		"( OLcfgDbAt:10.3 NAME 'olcShellSearch' "
68 			"DESC 'Search command and arguments' "
69 			"EQUALITY caseExactMatch "
70 			"SYNTAX OMsDirectoryString SINGLE-VALUE ) ", NULL, NULL },
71 	{ "compare", "args", 2, 0, 0, ARG_MAGIC|SHELL_COMPARE, shell_cf,
72 		"( OLcfgDbAt:10.4 NAME 'olcShellCompare' "
73 			"DESC 'Compare command and arguments' "
74 			"EQUALITY caseExactMatch "
75 			"SYNTAX OMsDirectoryString SINGLE-VALUE ) ", NULL, NULL },
76 	{ "modify", "args", 2, 0, 0, ARG_MAGIC|SHELL_MODIFY, shell_cf,
77 		"( OLcfgDbAt:10.5 NAME 'olcShellModify' "
78 			"DESC 'Modify command and arguments' "
79 			"EQUALITY caseExactMatch "
80 			"SYNTAX OMsDirectoryString SINGLE-VALUE ) ", NULL, NULL },
81 	{ "modrdn", "args", 2, 0, 0, ARG_MAGIC|SHELL_MODRDN, shell_cf,
82 		"( OLcfgDbAt:10.6 NAME 'olcShellModRDN' "
83 			"DESC 'ModRDN command and arguments' "
84 			"EQUALITY caseExactMatch "
85 			"SYNTAX OMsDirectoryString SINGLE-VALUE ) ", NULL, NULL },
86 	{ "add", "args", 2, 0, 0, ARG_MAGIC|SHELL_ADD, shell_cf,
87 		"( OLcfgDbAt:10.7 NAME 'olcShellAdd' "
88 			"DESC 'Add command and arguments' "
89 			"EQUALITY caseExactMatch "
90 			"SYNTAX OMsDirectoryString SINGLE-VALUE ) ", NULL, NULL },
91 	{ "delete", "args", 2, 0, 0, ARG_MAGIC|SHELL_DELETE, shell_cf,
92 		"( OLcfgDbAt:10.8 NAME 'olcShellDelete' "
93 			"DESC 'Delete command and arguments' "
94 			"EQUALITY caseExactMatch "
95 			"SYNTAX OMsDirectoryString SINGLE-VALUE ) ", NULL, NULL },
96 	{ NULL }
97 };
98 
99 static ConfigOCs shellocs[] = {
100 	{ "( OLcfgDbOc:10.1 "
101 		"NAME 'olcShellConfig'  "
102 		"DESC 'Shell backend configuration' "
103 		"SUP olcDatabaseConfig "
104 		"MAY ( olcShellBind $ olcShellUnbind $ olcShellSearch $ "
105 			"olcShellCompare $ olcShellModify $ olcShellModRDN $ "
106 			"olcShellAdd $ olcShellDelete ) )",
107 				Cft_Database, shellcfg },
108 	{ NULL }
109 };
110 
111 static int
shell_cf(ConfigArgs * c)112 shell_cf( ConfigArgs *c )
113 {
114 	struct shellinfo	*si = (struct shellinfo *) c->be->be_private;
115 	char ***arr = &si->si_bind;
116 
117 	if ( c->op == SLAP_CONFIG_EMIT ) {
118 		struct berval bv;
119 		if ( !arr[c->type] ) return 1;
120 		bv.bv_val = ldap_charray2str( arr[c->type], " " );
121 		bv.bv_len = strlen( bv.bv_val );
122 		ber_bvarray_add( &c->rvalue_vals, &bv );
123 	} else if ( c->op == LDAP_MOD_DELETE ) {
124 		ldap_charray_free( arr[c->type] );
125 		arr[c->type] = NULL;
126 	} else {
127 		arr[c->type] = ldap_charray_dup( &c->argv[1] );
128 	}
129 	return 0;
130 }
131 
132 int
shell_back_init_cf(BackendInfo * bi)133 shell_back_init_cf( BackendInfo *bi )
134 {
135 	bi->bi_cf_ocs = shellocs;
136 	return config_register_schema( shellcfg, shellocs );
137 }
138