xref: /netbsd-src/external/bsd/openldap/dist/libraries/libldap/ldifutil.c (revision 549b59ed3ccf0d36d3097190a0db27b770f3a839)
1*549b59edSchristos /*	$NetBSD: ldifutil.c,v 1.2 2021/08/14 16:14:56 christos Exp $	*/
2e670fd5cSchristos 
3e670fd5cSchristos /* $OpenLDAP$ */
4e670fd5cSchristos /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5e670fd5cSchristos  *
6e670fd5cSchristos  * Copyright 1998-2021 The OpenLDAP Foundation.
7e670fd5cSchristos  * All rights reserved.
8e670fd5cSchristos  *
9e670fd5cSchristos  * Redistribution and use in source and binary forms, with or without
10e670fd5cSchristos  * modification, are permitted only as authorized by the OpenLDAP
11e670fd5cSchristos  * Public License.
12e670fd5cSchristos  *
13e670fd5cSchristos  * A copy of this license is available in the file LICENSE in the
14e670fd5cSchristos  * top-level directory of the distribution or, alternatively, at
15e670fd5cSchristos  * <http://www.OpenLDAP.org/license.html>.
16e670fd5cSchristos  */
17e670fd5cSchristos /* Portions Copyright (c) 1990 Regents of the University of Michigan.
18e670fd5cSchristos  * All rights reserved.
19e670fd5cSchristos  */
20e670fd5cSchristos 
21e670fd5cSchristos /*
22e670fd5cSchristos  * This file contains public API to help with parsing LDIF
23e670fd5cSchristos  */
24e670fd5cSchristos 
25e670fd5cSchristos #include <sys/cdefs.h>
26*549b59edSchristos __RCSID("$NetBSD: ldifutil.c,v 1.2 2021/08/14 16:14:56 christos Exp $");
27e670fd5cSchristos 
28e670fd5cSchristos #include "portable.h"
29e670fd5cSchristos 
30e670fd5cSchristos #include <stdio.h>
31e670fd5cSchristos 
32e670fd5cSchristos #include <ac/stdlib.h>
33e670fd5cSchristos #include <ac/ctype.h>
34e670fd5cSchristos #include <ac/string.h>
35e670fd5cSchristos #include <ac/unistd.h>
36e670fd5cSchristos #include <ac/socket.h>
37e670fd5cSchristos #include <ac/time.h>
38e670fd5cSchristos 
39e670fd5cSchristos #include "ldap-int.h"
40e670fd5cSchristos #include "ldif.h"
41e670fd5cSchristos 
42e670fd5cSchristos #define	M_SEP	0x7f
43e670fd5cSchristos 
44e670fd5cSchristos /* strings found in LDIF entries */
45e670fd5cSchristos static struct berval BV_VERSION = BER_BVC("version");
46e670fd5cSchristos static struct berval BV_DN = BER_BVC("dn");
47e670fd5cSchristos static struct berval BV_CONTROL = BER_BVC("control");
48e670fd5cSchristos static struct berval BV_CHANGETYPE = BER_BVC("changetype");
49e670fd5cSchristos static struct berval BV_ADDCT = BER_BVC("add");
50e670fd5cSchristos static struct berval BV_MODIFYCT = BER_BVC("modify");
51e670fd5cSchristos static struct berval BV_DELETECT = BER_BVC("delete");
52e670fd5cSchristos static struct berval BV_MODRDNCT = BER_BVC("modrdn");
53e670fd5cSchristos static struct berval BV_MODDNCT = BER_BVC("moddn");
54e670fd5cSchristos static struct berval BV_RENAMECT = BER_BVC("rename");
55e670fd5cSchristos static struct berval BV_MODOPADD = BER_BVC("add");
56e670fd5cSchristos static struct berval BV_MODOPREPLACE = BER_BVC("replace");
57e670fd5cSchristos static struct berval BV_MODOPDELETE = BER_BVC("delete");
58e670fd5cSchristos static struct berval BV_MODOPINCREMENT = BER_BVC("increment");
59e670fd5cSchristos static struct berval BV_NEWRDN = BER_BVC("newrdn");
60e670fd5cSchristos static struct berval BV_DELETEOLDRDN = BER_BVC("deleteoldrdn");
61e670fd5cSchristos static struct berval BV_NEWSUP = BER_BVC("newsuperior");
62e670fd5cSchristos 
63e670fd5cSchristos #define	BV_CASEMATCH(a, b) \
64e670fd5cSchristos 	((a)->bv_len == (b)->bv_len && 0 == strcasecmp((a)->bv_val, (b)->bv_val))
65e670fd5cSchristos 
66e670fd5cSchristos static int parse_ldif_control LDAP_P(( struct berval *bval, LDAPControl ***ppctrls ));
67e670fd5cSchristos 
68e670fd5cSchristos void
ldap_ldif_record_done(LDIFRecord * lr)69e670fd5cSchristos ldap_ldif_record_done( LDIFRecord *lr )
70e670fd5cSchristos {
71e670fd5cSchristos 	int i;
72e670fd5cSchristos 
73e670fd5cSchristos 	/* the LDAPControl stuff does not allow the use of memory contexts */
74e670fd5cSchristos 	if (lr->lr_ctrls != NULL) {
75e670fd5cSchristos 		ldap_controls_free( lr->lr_ctrls );
76e670fd5cSchristos 	}
77e670fd5cSchristos 	if ( lr->lr_lm != NULL ) {
78e670fd5cSchristos 		ber_memfree_x( lr->lr_lm, lr->lr_ctx );
79e670fd5cSchristos 	}
80e670fd5cSchristos 	if ( lr->lr_mops != NULL ) {
81e670fd5cSchristos 		ber_memfree_x( lr->lr_mops, lr->lr_ctx );
82e670fd5cSchristos 	}
83e670fd5cSchristos 	for (i=lr->lr_lines-1; i>=0; i--)
84e670fd5cSchristos 		if ( lr->lr_freeval[i] ) ber_memfree_x( lr->lr_vals[i].bv_val, lr->lr_ctx );
85e670fd5cSchristos 	ber_memfree_x( lr->lr_btype, lr->lr_ctx );
86e670fd5cSchristos 
87e670fd5cSchristos 	memset( lr, 0, sizeof(LDIFRecord) );
88e670fd5cSchristos }
89e670fd5cSchristos 
90e670fd5cSchristos /*
91e670fd5cSchristos  * ldap_parse_ldif_record_x() will convert an LDIF record read with ldif_read_record()
92e670fd5cSchristos  * into an array of LDAPMod* and an array of LDAPControl*, suitable for passing
93e670fd5cSchristos  * directly to any other LDAP API function that takes LDAPMod** and LDAPControl**
94e670fd5cSchristos  * arguments, such as ldap_modify_s().
95e670fd5cSchristos  *
96e670fd5cSchristos  * rbuf - the ldif record buffer returned from ldif_read_record - rbuf.bv_val must be
97e670fd5cSchristos  *        writable - will use ldif_getline to read from it
98e670fd5cSchristos  * linenum - the ldif line number returned from ldif_read_record
99e670fd5cSchristos  *         - used for logging errors (e.g. error at line N)
100e670fd5cSchristos  * lr - holds the data to return
101e670fd5cSchristos  * errstr - a string used for logging (usually the program name e.g. "ldapmodify"
102e670fd5cSchristos  * flags - 0 or some combination of LDIF_DEFAULT_ADD LDIF_ENTRIES_ONLY LDIF_NO_CONTROLS
103e670fd5cSchristos  * ctx is the memory allocation context - if NULL, use the standard memory allocator
104e670fd5cSchristos  */
105e670fd5cSchristos int
ldap_parse_ldif_record_x(struct berval * rbuf,unsigned long linenum,LDIFRecord * lr,const char * errstr,unsigned int flags,void * ctx)106e670fd5cSchristos ldap_parse_ldif_record_x(
107e670fd5cSchristos 	struct berval *rbuf,
108e670fd5cSchristos 	unsigned long linenum,
109e670fd5cSchristos 	LDIFRecord *lr,
110e670fd5cSchristos 	const char *errstr,
111e670fd5cSchristos 	unsigned int flags,
112e670fd5cSchristos 	void *ctx )
113e670fd5cSchristos {
114e670fd5cSchristos 	char	*line, *dn;
115e670fd5cSchristos 	int		rc, modop;
116e670fd5cSchristos 	int		expect_modop, expect_sep;
117e670fd5cSchristos 	int		ldapadd, new_entry, delete_entry, got_all, no_dn;
118e670fd5cSchristos 	LDAPMod	**pmods;
119e670fd5cSchristos 	int version;
120e670fd5cSchristos 	LDAPControl **pctrls;
121e670fd5cSchristos 	int i, j, k, idn, nmods;
122e670fd5cSchristos 	struct berval **bvl, bv;
123e670fd5cSchristos 
124e670fd5cSchristos 	assert( lr != NULL );
125e670fd5cSchristos 	assert( rbuf != NULL );
126e670fd5cSchristos 	memset( lr, 0, sizeof(LDIFRecord) );
127e670fd5cSchristos 	lr->lr_ctx = ctx; /* save memory context for later */
128e670fd5cSchristos 	ldapadd = flags & LDIF_DEFAULT_ADD;
129e670fd5cSchristos 	no_dn = flags & LDIF_NO_DN;
130e670fd5cSchristos 	expect_modop = flags & LDIF_MODS_ONLY;
131e670fd5cSchristos 	new_entry = ldapadd;
132e670fd5cSchristos 
133e670fd5cSchristos 	rc = got_all = delete_entry = modop = 0;
134e670fd5cSchristos 	expect_sep = 0;
135e670fd5cSchristos 	version = 0;
136e670fd5cSchristos 	pmods = NULL;
137e670fd5cSchristos 	pctrls = NULL;
138e670fd5cSchristos 	dn = NULL;
139e670fd5cSchristos 
140e670fd5cSchristos 	lr->lr_lines = ldif_countlines( rbuf->bv_val );
141e670fd5cSchristos 	lr->lr_btype = ber_memcalloc_x( 1, (lr->lr_lines+1)*2*sizeof(struct berval)+lr->lr_lines, ctx );
142e670fd5cSchristos 	if ( !lr->lr_btype )
143e670fd5cSchristos 		return LDAP_NO_MEMORY;
144e670fd5cSchristos 
145e670fd5cSchristos 	lr->lr_vals = lr->lr_btype+lr->lr_lines+1;
146e670fd5cSchristos 	lr->lr_freeval = (char *)(lr->lr_vals+lr->lr_lines+1);
147e670fd5cSchristos 	i = -1;
148e670fd5cSchristos 
149e670fd5cSchristos 	while ( rc == 0 && ( line = ldif_getline( &rbuf->bv_val )) != NULL ) {
150e670fd5cSchristos 		int freev;
151e670fd5cSchristos 
152e670fd5cSchristos 		if ( *line == '\n' || *line == '\0' ) {
153e670fd5cSchristos 			break;
154e670fd5cSchristos 		}
155e670fd5cSchristos 
156e670fd5cSchristos 		++i;
157e670fd5cSchristos 
158e670fd5cSchristos 		if ( line[0] == '-' && !line[1] ) {
159e670fd5cSchristos 			BER_BVZERO( lr->lr_btype+i );
160e670fd5cSchristos 			lr->lr_freeval[i] = 0;
161e670fd5cSchristos 			continue;
162e670fd5cSchristos 		}
163e670fd5cSchristos 
164e670fd5cSchristos 		if ( ( rc = ldif_parse_line2( line, lr->lr_btype+i, lr->lr_vals+i, &freev ) ) < 0 ) {
165e670fd5cSchristos 			fprintf( stderr, _("%s: invalid format (line %lu) entry: \"%s\"\n"),
166e670fd5cSchristos 				errstr, linenum+i, dn == NULL ? "" : dn );
167e670fd5cSchristos 			rc = LDAP_PARAM_ERROR;
168e670fd5cSchristos 			goto leave;
169e670fd5cSchristos 		}
170e670fd5cSchristos 		lr->lr_freeval[i] = freev;
171e670fd5cSchristos 
172e670fd5cSchristos 		if ( dn == NULL && !no_dn ) {
173e670fd5cSchristos 			if ( linenum+i == 1 && BV_CASEMATCH( lr->lr_btype+i, &BV_VERSION )) {
174e670fd5cSchristos 				/* lutil_atoi() introduces a dependence of libldap
175e670fd5cSchristos 				 * on liblutil; we only allow version 1 by now (ITS#6654)
176e670fd5cSchristos 				 */
177e670fd5cSchristos #if 0
178e670fd5cSchristos 				int	v;
179e670fd5cSchristos 				if( lr->lr_vals[i].bv_len == 0 || lutil_atoi( &v, lr->lr_vals[i].bv_val) != 0 || v != 1 )
180e670fd5cSchristos #endif
181e670fd5cSchristos 				static const struct berval version1 = { 1, "1" };
182e670fd5cSchristos 				if ( lr->lr_vals[i].bv_len != version1.bv_len || strncmp( lr->lr_vals[i].bv_val, version1.bv_val, version1.bv_len ) != 0 )
183e670fd5cSchristos 				{
184e670fd5cSchristos 					fprintf( stderr,
185e670fd5cSchristos 						_("%s: invalid version %s, line %lu (ignored)\n"),
186e670fd5cSchristos 						errstr, lr->lr_vals[i].bv_val, linenum );
187e670fd5cSchristos 				}
188e670fd5cSchristos 				version++;
189e670fd5cSchristos 
190e670fd5cSchristos 			} else if ( BV_CASEMATCH( lr->lr_btype+i, &BV_DN )) {
191e670fd5cSchristos 				lr->lr_dn = lr->lr_vals[i];
192e670fd5cSchristos 				dn = lr->lr_dn.bv_val; /* primarily for logging */
193e670fd5cSchristos 				idn = i;
194e670fd5cSchristos 			}
195e670fd5cSchristos 			/* skip all lines until we see "dn:" */
196e670fd5cSchristos 		}
197e670fd5cSchristos 	}
198e670fd5cSchristos 
199e670fd5cSchristos 	/* check to make sure there was a dn: line */
200e670fd5cSchristos 	if ( !dn && !no_dn ) {
201e670fd5cSchristos 		rc = 0;
202e670fd5cSchristos 		goto leave;
203e670fd5cSchristos 	}
204e670fd5cSchristos 
205e670fd5cSchristos 	lr->lr_lines = i+1;
206e670fd5cSchristos 
207e670fd5cSchristos 	if( lr->lr_lines == 0 ) {
208e670fd5cSchristos 		rc = 0;
209e670fd5cSchristos 		goto leave;
210e670fd5cSchristos 	}
211e670fd5cSchristos 
212e670fd5cSchristos 	if( version && lr->lr_lines == 1 ) {
213e670fd5cSchristos 		rc = 0;
214e670fd5cSchristos 		goto leave;
215e670fd5cSchristos 	}
216e670fd5cSchristos 
217e670fd5cSchristos 	if ( no_dn ) {
218e670fd5cSchristos 		i = 0;
219e670fd5cSchristos 	} else {
220e670fd5cSchristos 		i = idn+1;
221e670fd5cSchristos 		/* Check for "control" tag after dn and before changetype. */
222e670fd5cSchristos 		if ( BV_CASEMATCH( lr->lr_btype+i, &BV_CONTROL )) {
223e670fd5cSchristos 			/* Parse and add it to the list of controls */
224e670fd5cSchristos 			if ( !( flags & LDIF_NO_CONTROLS ) ) {
225e670fd5cSchristos 				rc = parse_ldif_control( lr->lr_vals+i, &pctrls );
226e670fd5cSchristos 				if (rc != 0) {
227e670fd5cSchristos 					fprintf( stderr,
228e670fd5cSchristos 							 _("%s: Error processing %s line, line %lu: %s\n"),
229e670fd5cSchristos 							 errstr, BV_CONTROL.bv_val, linenum+i, ldap_err2string(rc) );
230e670fd5cSchristos 				}
231e670fd5cSchristos 			}
232e670fd5cSchristos 			i++;
233e670fd5cSchristos 			if ( i>= lr->lr_lines ) {
234e670fd5cSchristos short_input:
235e670fd5cSchristos 				fprintf( stderr,
236e670fd5cSchristos 					_("%s: Expecting more input after %s line, line %lu\n"),
237e670fd5cSchristos 					errstr, lr->lr_btype[i-1].bv_val, linenum+i );
238e670fd5cSchristos 
239e670fd5cSchristos 				rc = LDAP_PARAM_ERROR;
240e670fd5cSchristos 				goto leave;
241e670fd5cSchristos 			}
242e670fd5cSchristos 		}
243e670fd5cSchristos 	}
244e670fd5cSchristos 
245e670fd5cSchristos 	/* Check for changetype */
246e670fd5cSchristos 	if ( BV_CASEMATCH( lr->lr_btype+i, &BV_CHANGETYPE )) {
247e670fd5cSchristos #ifdef LIBERAL_CHANGETYPE_MODOP
248e670fd5cSchristos 		/* trim trailing spaces (and log warning ...) */
249e670fd5cSchristos 		int icnt;
250e670fd5cSchristos 		for ( icnt = lr->lr_vals[i].bv_len; --icnt > 0; ) {
251e670fd5cSchristos 			if ( !isspace( (unsigned char) lr->lr_vals[i].bv_val[icnt] ) ) {
252e670fd5cSchristos 				break;
253e670fd5cSchristos 			}
254e670fd5cSchristos 		}
255e670fd5cSchristos 
256e670fd5cSchristos 		if ( ++icnt != lr->lr_vals[i].bv_len ) {
257e670fd5cSchristos 			fprintf( stderr, _("%s: illegal trailing space after"
258e670fd5cSchristos 				" \"%s: %s\" trimmed (line %lu, entry \"%s\")\n"),
259e670fd5cSchristos 				errstr, BV_CHANGETYPE.bv_val, lr->lr_vals[i].bv_val, linenum+i, dn );
260e670fd5cSchristos 			lr->lr_vals[i].bv_val[icnt] = '\0';
261e670fd5cSchristos 		}
262e670fd5cSchristos #endif /* LIBERAL_CHANGETYPE_MODOP */
263e670fd5cSchristos 
264e670fd5cSchristos 		/* if LDIF_ENTRIES_ONLY, then either the changetype must be add, or
265e670fd5cSchristos 		   there must be no changetype, and the flag LDIF_DEFAULT_ADD must be set */
266e670fd5cSchristos 		if ( flags & LDIF_ENTRIES_ONLY ) {
267e670fd5cSchristos 			if ( !( BV_CASEMATCH( lr->lr_vals+i, &BV_ADDCT )) ) {
268e670fd5cSchristos 				ber_pvt_log_printf( LDAP_DEBUG_ANY, ldif_debug,
269e670fd5cSchristos 									_("%s: skipping LDIF record beginning at line %lu: "
270e670fd5cSchristos 									  "changetype '%.*s' found but entries only was requested\n"),
271e670fd5cSchristos 									errstr, linenum,
272e670fd5cSchristos 									(int)lr->lr_vals[i].bv_len,
273e670fd5cSchristos 									(const char *)lr->lr_vals[i].bv_val );
274e670fd5cSchristos 				goto leave;
275e670fd5cSchristos 			}
276e670fd5cSchristos 		}
277e670fd5cSchristos 
278e670fd5cSchristos 		if ( BV_CASEMATCH( lr->lr_vals+i, &BV_MODIFYCT )) {
279e670fd5cSchristos 			new_entry = 0;
280e670fd5cSchristos 			expect_modop = 1;
281e670fd5cSchristos 		} else if ( BV_CASEMATCH( lr->lr_vals+i, &BV_ADDCT )) {
282e670fd5cSchristos 			new_entry = 1;
283e670fd5cSchristos 			modop = LDAP_MOD_ADD;
284e670fd5cSchristos 		} else if ( BV_CASEMATCH( lr->lr_vals+i, &BV_MODRDNCT )
285e670fd5cSchristos 			|| BV_CASEMATCH( lr->lr_vals+i, &BV_MODDNCT )
286e670fd5cSchristos 			|| BV_CASEMATCH( lr->lr_vals+i, &BV_RENAMECT ))
287e670fd5cSchristos 		{
288e670fd5cSchristos 			i++;
289e670fd5cSchristos 			if ( i >= lr->lr_lines )
290e670fd5cSchristos 				goto short_input;
291e670fd5cSchristos 			if ( !BV_CASEMATCH( lr->lr_btype+i, &BV_NEWRDN )) {
292e670fd5cSchristos 				fprintf( stderr, _("%s: expecting \"%s:\" but saw"
293e670fd5cSchristos 					" \"%s:\" (line %lu, entry \"%s\")\n"),
294e670fd5cSchristos 					errstr, BV_NEWRDN.bv_val, lr->lr_btype[i].bv_val, linenum+i, dn );
295e670fd5cSchristos 				rc = LDAP_PARAM_ERROR;
296e670fd5cSchristos 				goto leave;
297e670fd5cSchristos 			}
298e670fd5cSchristos 			lr->lrop_newrdn = lr->lr_vals[i];
299e670fd5cSchristos 			i++;
300e670fd5cSchristos 			if ( i >= lr->lr_lines )
301e670fd5cSchristos 				goto short_input;
302e670fd5cSchristos 			if ( !BV_CASEMATCH( lr->lr_btype+i, &BV_DELETEOLDRDN )) {
303e670fd5cSchristos 				fprintf( stderr, _("%s: expecting \"%s:\" but saw"
304e670fd5cSchristos 					" \"%s:\" (line %lu, entry \"%s\")\n"),
305e670fd5cSchristos 					errstr, BV_DELETEOLDRDN.bv_val, lr->lr_btype[i].bv_val, linenum+i, dn );
306e670fd5cSchristos 				rc = LDAP_PARAM_ERROR;
307e670fd5cSchristos 				goto leave;
308e670fd5cSchristos 			}
309e670fd5cSchristos 			lr->lrop_delold = ( lr->lr_vals[i].bv_val[0] == '0' ) ? 0 : 1;
310e670fd5cSchristos 			i++;
311e670fd5cSchristos 			if ( i < lr->lr_lines ) {
312e670fd5cSchristos 				if ( !BV_CASEMATCH( lr->lr_btype+i, &BV_NEWSUP )) {
313e670fd5cSchristos 					fprintf( stderr, _("%s: expecting \"%s:\" but saw"
314e670fd5cSchristos 						" \"%s:\" (line %lu, entry \"%s\")\n"),
315e670fd5cSchristos 						errstr, BV_NEWSUP.bv_val, lr->lr_btype[i].bv_val, linenum+i, dn );
316e670fd5cSchristos 					rc = LDAP_PARAM_ERROR;
317e670fd5cSchristos 					goto leave;
318e670fd5cSchristos 				}
319e670fd5cSchristos 				lr->lrop_newsup = lr->lr_vals[i];
320e670fd5cSchristos 				i++;
321e670fd5cSchristos 			}
322e670fd5cSchristos 			got_all = 1;
323e670fd5cSchristos 		} else if ( BV_CASEMATCH( lr->lr_vals+i, &BV_DELETECT )) {
324e670fd5cSchristos 			got_all = delete_entry = 1;
325e670fd5cSchristos 		} else {
326e670fd5cSchristos 			fprintf( stderr,
327e670fd5cSchristos 				_("%s:  unknown %s \"%s\" (line %lu, entry \"%s\")\n"),
328e670fd5cSchristos 				errstr, BV_CHANGETYPE.bv_val, lr->lr_vals[i].bv_val, linenum+i, dn );
329e670fd5cSchristos 			rc = LDAP_PARAM_ERROR;
330e670fd5cSchristos 			goto leave;
331e670fd5cSchristos 		}
332e670fd5cSchristos 		i++;
333e670fd5cSchristos 	} else if ( ldapadd ) {		/*  missing changetype => add */
334e670fd5cSchristos 		new_entry = 1;
335e670fd5cSchristos 		modop = LDAP_MOD_ADD;
336e670fd5cSchristos 	} else {
337e670fd5cSchristos 		/* if LDIF_ENTRIES_ONLY, then either the changetype must be add, or
338e670fd5cSchristos 		   there must be no changetype, and the flag LDIF_DEFAULT_ADD must be set */
339e670fd5cSchristos 		if ( flags & LDIF_ENTRIES_ONLY ) {
340e670fd5cSchristos 			ber_pvt_log_printf( LDAP_DEBUG_ANY, ldif_debug,
341e670fd5cSchristos 								_("%s: skipping LDIF record beginning at line %lu: "
342e670fd5cSchristos 								  "no changetype found but entries only was requested and "
343e670fd5cSchristos 								  "the default setting for missing changetype is modify\n"),
344e670fd5cSchristos 								errstr, linenum );
345e670fd5cSchristos 			goto leave;
346e670fd5cSchristos 		}
347e670fd5cSchristos 		expect_modop = 1;	/* missing changetype => modify */
348e670fd5cSchristos 	}
349e670fd5cSchristos 
350e670fd5cSchristos 	if ( got_all ) {
351e670fd5cSchristos 		if ( i < lr->lr_lines ) {
352e670fd5cSchristos 			fprintf( stderr,
353e670fd5cSchristos 				_("%s: extra lines at end (line %lu, entry \"%s\")\n"),
354e670fd5cSchristos 				errstr, linenum+i, dn );
355e670fd5cSchristos 			rc = LDAP_PARAM_ERROR;
356e670fd5cSchristos 			goto leave;
357e670fd5cSchristos 		}
358e670fd5cSchristos 		goto doit;
359e670fd5cSchristos 	}
360e670fd5cSchristos 
361e670fd5cSchristos 	nmods = lr->lr_lines - i;
362e670fd5cSchristos 	idn = i;
363e670fd5cSchristos 
364e670fd5cSchristos 	if ( new_entry ) {
365e670fd5cSchristos 		int fv;
366e670fd5cSchristos 
367e670fd5cSchristos 		/* Make sure all attributes with multiple values are contiguous */
368e670fd5cSchristos 		for (; i<lr->lr_lines; i++) {
369e670fd5cSchristos 			for (j=i+1; j<lr->lr_lines; j++) {
370e670fd5cSchristos 				if ( !lr->lr_btype[j].bv_val ) {
371e670fd5cSchristos 					fprintf( stderr,
372e670fd5cSchristos 						_("%s: missing attributeDescription (line %lu, entry \"%s\")\n"),
373e670fd5cSchristos 						errstr, linenum+j, dn );
374e670fd5cSchristos 					rc = LDAP_PARAM_ERROR;
375e670fd5cSchristos 					goto leave;
376e670fd5cSchristos 				}
377e670fd5cSchristos 				if ( BV_CASEMATCH( lr->lr_btype+i, lr->lr_btype+j )) {
378e670fd5cSchristos 					nmods--;
379e670fd5cSchristos 					/* out of order, move intervening attributes down */
380e670fd5cSchristos 					if ( j != i+1 ) {
381e670fd5cSchristos 						bv = lr->lr_vals[j];
382e670fd5cSchristos 						fv = lr->lr_freeval[j];
383e670fd5cSchristos 						for (k=j; k>i; k--) {
384e670fd5cSchristos 							lr->lr_btype[k] = lr->lr_btype[k-1];
385e670fd5cSchristos 							lr->lr_vals[k] = lr->lr_vals[k-1];
386e670fd5cSchristos 							lr->lr_freeval[k] = lr->lr_freeval[k-1];
387e670fd5cSchristos 						}
388e670fd5cSchristos 						k++;
389e670fd5cSchristos 						lr->lr_btype[k] = lr->lr_btype[i];
390e670fd5cSchristos 						lr->lr_vals[k] = bv;
391e670fd5cSchristos 						lr->lr_freeval[k] = fv;
392e670fd5cSchristos 					}
393e670fd5cSchristos 					i++;
394e670fd5cSchristos 				}
395e670fd5cSchristos 			}
396e670fd5cSchristos 		}
397e670fd5cSchristos 		/* Allocate space for array of mods, array of pointers to mods,
398e670fd5cSchristos 		 * and array of pointers to values, allowing for NULL terminators
399e670fd5cSchristos 		 * for the pointer arrays...
400e670fd5cSchristos 		 */
401e670fd5cSchristos 		lr->lr_lm = ber_memalloc_x( nmods * sizeof(LDAPMod) +
402e670fd5cSchristos 			(nmods+1) * sizeof(LDAPMod*) +
403e670fd5cSchristos 			(lr->lr_lines + nmods - idn) * sizeof(struct berval *), ctx );
404e670fd5cSchristos 		if ( lr->lr_lm == NULL ) {
405e670fd5cSchristos 			rc = LDAP_NO_MEMORY;
406e670fd5cSchristos 			goto leave;
407e670fd5cSchristos 		}
408e670fd5cSchristos 
409e670fd5cSchristos 		pmods = (LDAPMod **)(lr->lr_lm+nmods);
410e670fd5cSchristos 		bvl = (struct berval **)(pmods+nmods+1);
411e670fd5cSchristos 
412e670fd5cSchristos 		j = 0;
413e670fd5cSchristos 		k = -1;
414e670fd5cSchristos 		BER_BVZERO(&bv);
415e670fd5cSchristos 		for (i=idn; i<lr->lr_lines; i++) {
416e670fd5cSchristos 			if ( BV_CASEMATCH( lr->lr_btype+i, &BV_DN )) {
417e670fd5cSchristos 				fprintf( stderr, _("%s: attributeDescription \"%s\":"
418e670fd5cSchristos 					" (possible missing newline"
419e670fd5cSchristos 						" after line %lu, entry \"%s\"?)\n"),
420e670fd5cSchristos 					errstr, lr->lr_btype[i].bv_val, linenum+i - 1, dn );
421e670fd5cSchristos 			}
422e670fd5cSchristos 			if ( !BV_CASEMATCH( lr->lr_btype+i, &bv )) {
423e670fd5cSchristos 				bvl[k++] = NULL;
424e670fd5cSchristos 				bv = lr->lr_btype[i];
425e670fd5cSchristos 				lr->lr_lm[j].mod_op = LDAP_MOD_ADD | LDAP_MOD_BVALUES;
426e670fd5cSchristos 				lr->lr_lm[j].mod_type = bv.bv_val;
427e670fd5cSchristos 				lr->lr_lm[j].mod_bvalues = bvl+k;
428e670fd5cSchristos 				pmods[j] = lr->lr_lm+j;
429e670fd5cSchristos 				j++;
430e670fd5cSchristos 			}
431e670fd5cSchristos 			bvl[k++] = lr->lr_vals+i;
432e670fd5cSchristos 		}
433e670fd5cSchristos 		bvl[k] = NULL;
434e670fd5cSchristos 		pmods[j] = NULL;
435e670fd5cSchristos 		goto doit;
436e670fd5cSchristos 	}
437e670fd5cSchristos 
438e670fd5cSchristos 	lr->lr_mops = ber_memalloc_x( lr->lr_lines+1, ctx );
439e670fd5cSchristos 	if ( lr->lr_mops == NULL ) {
440e670fd5cSchristos 		rc = LDAP_NO_MEMORY;
441e670fd5cSchristos 		goto leave;
442e670fd5cSchristos 	}
443e670fd5cSchristos 
444e670fd5cSchristos 	lr->lr_mops[lr->lr_lines] = M_SEP;
445e670fd5cSchristos 	if ( i > 0 )
446e670fd5cSchristos 		lr->lr_mops[i-1] = M_SEP;
447e670fd5cSchristos 
448e670fd5cSchristos 	for ( ; i<lr->lr_lines; i++ ) {
449e670fd5cSchristos 		if ( expect_modop ) {
450e670fd5cSchristos #ifdef LIBERAL_CHANGETYPE_MODOP
451e670fd5cSchristos 			/* trim trailing spaces (and log warning ...) */
452e670fd5cSchristos 		    int icnt;
453e670fd5cSchristos 		    for ( icnt = lr->lr_vals[i].bv_len; --icnt > 0; ) {
454e670fd5cSchristos 				if ( !isspace( (unsigned char) lr->lr_vals[i].bv_val[icnt] ) ) break;
455e670fd5cSchristos 			}
456e670fd5cSchristos 
457e670fd5cSchristos 			if ( ++icnt != lr->lr_vals[i].bv_len ) {
458e670fd5cSchristos 				fprintf( stderr, _("%s: illegal trailing space after"
459e670fd5cSchristos 					" \"%s: %s\" trimmed (line %lu, entry \"%s\")\n"),
460e670fd5cSchristos 					errstr, type, lr->lr_vals[i].bv_val, linenum+i, dn );
461e670fd5cSchristos 				lr->lr_vals[i].bv_val[icnt] = '\0';
462e670fd5cSchristos 			}
463e670fd5cSchristos #endif /* LIBERAL_CHANGETYPE_MODOP */
464e670fd5cSchristos 
465e670fd5cSchristos 			expect_modop = 0;
466e670fd5cSchristos 			expect_sep = 1;
467e670fd5cSchristos 			if ( BV_CASEMATCH( lr->lr_btype+i, &BV_MODOPADD )) {
468e670fd5cSchristos 				modop = LDAP_MOD_ADD;
469e670fd5cSchristos 				lr->lr_mops[i] = M_SEP;
470e670fd5cSchristos 				nmods--;
471e670fd5cSchristos 			} else if ( BV_CASEMATCH( lr->lr_btype+i, &BV_MODOPREPLACE )) {
472e670fd5cSchristos 			/* defer handling these since they might have no values.
473e670fd5cSchristos 			 * Use the BVALUES flag to signal that these were
474e670fd5cSchristos 			 * deferred. If values are provided later, this
475e670fd5cSchristos 			 * flag will be switched off.
476e670fd5cSchristos 			 */
477e670fd5cSchristos 				modop = LDAP_MOD_REPLACE;
478e670fd5cSchristos 				lr->lr_mops[i] = modop | LDAP_MOD_BVALUES;
479e670fd5cSchristos 				lr->lr_btype[i] = lr->lr_vals[i];
480e670fd5cSchristos 			} else if ( BV_CASEMATCH( lr->lr_btype+i, &BV_MODOPDELETE )) {
481e670fd5cSchristos 				modop = LDAP_MOD_DELETE;
482e670fd5cSchristos 				lr->lr_mops[i] = modop | LDAP_MOD_BVALUES;
483e670fd5cSchristos 				lr->lr_btype[i] = lr->lr_vals[i];
484e670fd5cSchristos 			} else if ( BV_CASEMATCH( lr->lr_btype+i, &BV_MODOPINCREMENT )) {
485e670fd5cSchristos 				modop = LDAP_MOD_INCREMENT;
486e670fd5cSchristos 				lr->lr_mops[i] = M_SEP;
487e670fd5cSchristos 				nmods--;
488e670fd5cSchristos 			} else {	/* no modify op: invalid LDIF */
489e670fd5cSchristos 				fprintf( stderr, _("%s: modify operation type is missing at"
490e670fd5cSchristos 					" line %lu, entry \"%s\"\n"),
491e670fd5cSchristos 					errstr, linenum+i, dn );
492e670fd5cSchristos 				rc = LDAP_PARAM_ERROR;
493e670fd5cSchristos 				goto leave;
494e670fd5cSchristos 			}
495e670fd5cSchristos 			bv = lr->lr_vals[i];
496e670fd5cSchristos 		} else if ( expect_sep && BER_BVISEMPTY( lr->lr_btype+i )) {
497e670fd5cSchristos 			lr->lr_mops[i] = M_SEP;
498e670fd5cSchristos 			expect_sep = 0;
499e670fd5cSchristos 			expect_modop = 1;
500e670fd5cSchristos 			nmods--;
501e670fd5cSchristos 		} else {
502e670fd5cSchristos 			if ( !BV_CASEMATCH( lr->lr_btype+i, &bv )) {
503e670fd5cSchristos 				fprintf( stderr, _("%s: wrong attributeType at"
504e670fd5cSchristos 					" line %lu, entry \"%s\"\n"),
505e670fd5cSchristos 					errstr, linenum+i, dn );
506e670fd5cSchristos 				rc = LDAP_PARAM_ERROR;
507e670fd5cSchristos 				goto leave;
508e670fd5cSchristos 			}
509e670fd5cSchristos 			lr->lr_mops[i] = modop;
510e670fd5cSchristos 			/* If prev op was deferred and matches this type,
511e670fd5cSchristos 			 * clear the flag
512e670fd5cSchristos 			 */
513e670fd5cSchristos 			if ( (lr->lr_mops[i-1] & LDAP_MOD_BVALUES)
514e670fd5cSchristos 				&& BV_CASEMATCH( lr->lr_btype+i, lr->lr_btype+i-1 ))
515e670fd5cSchristos 			{
516e670fd5cSchristos 				lr->lr_mops[i-1] = M_SEP;
517e670fd5cSchristos 				nmods--;
518e670fd5cSchristos 			}
519e670fd5cSchristos 		}
520e670fd5cSchristos 	}
521e670fd5cSchristos 
522e670fd5cSchristos 	/* Allocate space for array of mods, array of pointers to mods,
523e670fd5cSchristos 	 * and array of pointers to values, allowing for NULL terminators
524e670fd5cSchristos 	 * for the pointer arrays...
525e670fd5cSchristos 	 */
526e670fd5cSchristos 	lr->lr_lm = ber_memalloc_x( nmods * sizeof(LDAPMod) +
527e670fd5cSchristos 		(nmods+1) * sizeof(LDAPMod*) +
528e670fd5cSchristos 		(lr->lr_lines + nmods - idn) * sizeof(struct berval *), ctx );
529e670fd5cSchristos 	if ( lr->lr_lm == NULL ) {
530e670fd5cSchristos 		rc = LDAP_NO_MEMORY;
531e670fd5cSchristos 		goto leave;
532e670fd5cSchristos 	}
533e670fd5cSchristos 
534e670fd5cSchristos 	pmods = (LDAPMod **)(lr->lr_lm+nmods);
535e670fd5cSchristos 	bvl = (struct berval **)(pmods+nmods+1);
536e670fd5cSchristos 
537e670fd5cSchristos 	j = 0;
538e670fd5cSchristos 	k = -1;
539e670fd5cSchristos 	BER_BVZERO(&bv);
540e670fd5cSchristos 	if ( idn > 0 )
541e670fd5cSchristos 		lr->lr_mops[idn-1] = M_SEP;
542e670fd5cSchristos 	for (i=idn; i<lr->lr_lines; i++) {
543e670fd5cSchristos 		if ( lr->lr_mops[i] == M_SEP )
544e670fd5cSchristos 			continue;
545e670fd5cSchristos 		if ( lr->lr_mops[i] != lr->lr_mops[i-1] || !BV_CASEMATCH( lr->lr_btype+i, &bv )) {
546e670fd5cSchristos 			bvl[k++] = NULL;
547e670fd5cSchristos 			bv = lr->lr_btype[i];
548e670fd5cSchristos 			lr->lr_lm[j].mod_op = lr->lr_mops[i] | LDAP_MOD_BVALUES;
549e670fd5cSchristos 			lr->lr_lm[j].mod_type = bv.bv_val;
550e670fd5cSchristos 			if ( lr->lr_mops[i] & LDAP_MOD_BVALUES ) {
551e670fd5cSchristos 				lr->lr_lm[j].mod_bvalues = NULL;
552e670fd5cSchristos 			} else {
553e670fd5cSchristos 				lr->lr_lm[j].mod_bvalues = bvl+k;
554e670fd5cSchristos 			}
555e670fd5cSchristos 			pmods[j] = lr->lr_lm+j;
556e670fd5cSchristos 			j++;
557e670fd5cSchristos 		}
558e670fd5cSchristos 		bvl[k++] = lr->lr_vals+i;
559e670fd5cSchristos 	}
560e670fd5cSchristos 	bvl[k] = NULL;
561e670fd5cSchristos 	pmods[j] = NULL;
562e670fd5cSchristos 
563e670fd5cSchristos doit:
564e670fd5cSchristos 	/* first, set the common fields */
565e670fd5cSchristos 	lr->lr_ctrls = pctrls;
566e670fd5cSchristos 	/* next, set the op */
567e670fd5cSchristos 	if ( delete_entry ) {
568e670fd5cSchristos 		lr->lr_op = LDAP_REQ_DELETE;
569e670fd5cSchristos 	} else if ( lr->lrop_newrdn.bv_val != NULL ) {
570e670fd5cSchristos 		lr->lr_op = LDAP_REQ_MODDN;
571e670fd5cSchristos 	} else {
572e670fd5cSchristos 		/* for now, either add or modify */
573e670fd5cSchristos 		lr->lrop_mods = pmods;
574e670fd5cSchristos 		if ( new_entry ) {
575e670fd5cSchristos 			lr->lr_op = LDAP_REQ_ADD;
576e670fd5cSchristos 		} else {
577e670fd5cSchristos 			lr->lr_op = LDAP_REQ_MODIFY;
578e670fd5cSchristos 		}
579e670fd5cSchristos 	}
580e670fd5cSchristos 
581e670fd5cSchristos leave:
582e670fd5cSchristos 	if ( rc != LDAP_SUCCESS ) {
583e670fd5cSchristos 		ldap_ldif_record_done( lr );
584e670fd5cSchristos 	}
585e670fd5cSchristos 
586e670fd5cSchristos 	return( rc );
587e670fd5cSchristos }
588e670fd5cSchristos 
589e670fd5cSchristos /* Same as ldap_parse_ldif_record_x()
590e670fd5cSchristos  * public API does not expose memory context
591e670fd5cSchristos  */
592e670fd5cSchristos int
ldap_parse_ldif_record(struct berval * rbuf,unsigned long linenum,LDIFRecord * lr,const char * errstr,unsigned int flags)593e670fd5cSchristos ldap_parse_ldif_record(
594e670fd5cSchristos 	struct berval *rbuf,
595e670fd5cSchristos 	unsigned long linenum,
596e670fd5cSchristos 	LDIFRecord *lr,
597e670fd5cSchristos 	const char *errstr,
598e670fd5cSchristos 	unsigned int flags )
599e670fd5cSchristos {
600e670fd5cSchristos 	return ldap_parse_ldif_record_x( rbuf, linenum, lr, errstr, flags, NULL );
601e670fd5cSchristos }
602e670fd5cSchristos 
603e670fd5cSchristos /* Parse an LDIF control line of the form
604e670fd5cSchristos       control:  oid  [true/false]  [: value]              or
605e670fd5cSchristos       control:  oid  [true/false]  [:: base64-value]      or
606e670fd5cSchristos       control:  oid  [true/false]  [:< url]
607e670fd5cSchristos    The control is added to the list of controls in *ppctrls.
608e670fd5cSchristos */
609e670fd5cSchristos static int
parse_ldif_control(struct berval * bval,LDAPControl *** ppctrls)610e670fd5cSchristos parse_ldif_control(
611e670fd5cSchristos 	struct berval *bval,
612e670fd5cSchristos 	LDAPControl ***ppctrls)
613e670fd5cSchristos {
614e670fd5cSchristos 	char *oid = NULL;
615e670fd5cSchristos 	int criticality = 0;   /* Default is false if not present */
616e670fd5cSchristos 	int i, rc=0;
617e670fd5cSchristos 	char *s, *oidStart;
618e670fd5cSchristos 	LDAPControl *newctrl = NULL;
619e670fd5cSchristos 	LDAPControl **pctrls = NULL;
620e670fd5cSchristos 	struct berval type, bv = BER_BVNULL;
621e670fd5cSchristos 	int freeval = 0;
622e670fd5cSchristos 
623e670fd5cSchristos 	if (ppctrls) pctrls = *ppctrls;
624e670fd5cSchristos 	/* OID should come first. Validate and extract it. */
625e670fd5cSchristos 	s = bval->bv_val;
626e670fd5cSchristos 	if (*s == 0) return ( LDAP_PARAM_ERROR );
627e670fd5cSchristos 	oidStart = s;
628e670fd5cSchristos 	while (isdigit((unsigned char)*s) || *s == '.') {
629e670fd5cSchristos 		s++;                           /* OID should be digits or . */
630e670fd5cSchristos 	}
631e670fd5cSchristos 	if (s == oidStart) {
632e670fd5cSchristos 		return ( LDAP_PARAM_ERROR );   /* OID was not present */
633e670fd5cSchristos 	}
634e670fd5cSchristos 	if (*s) {                          /* End of OID should be space or NULL */
635e670fd5cSchristos 		if (!isspace((unsigned char)*s)) {
636e670fd5cSchristos 			return ( LDAP_PARAM_ERROR ); /* else OID contained invalid chars */
637e670fd5cSchristos 		}
638e670fd5cSchristos 		*s++ = 0;                    /* Replace space with null to terminate */
639e670fd5cSchristos 	}
640e670fd5cSchristos 
641e670fd5cSchristos 	oid = ber_strdup(oidStart);
642e670fd5cSchristos 	if (oid == NULL) return ( LDAP_NO_MEMORY );
643e670fd5cSchristos 
644e670fd5cSchristos 	/* Optional Criticality field is next. */
645e670fd5cSchristos 	while (*s && isspace((unsigned char)*s)) {
646e670fd5cSchristos 		s++;                         /* Skip white space before criticality */
647e670fd5cSchristos 	}
648e670fd5cSchristos 	if (strncasecmp(s, "true", 4) == 0) {
649e670fd5cSchristos 		criticality = 1;
650e670fd5cSchristos 		s += 4;
651e670fd5cSchristos 	}
652e670fd5cSchristos 	else if (strncasecmp(s, "false", 5) == 0) {
653e670fd5cSchristos 		criticality = 0;
654e670fd5cSchristos 		s += 5;
655e670fd5cSchristos 	}
656e670fd5cSchristos 
657e670fd5cSchristos 	/* Optional value field is next */
658e670fd5cSchristos 	while (*s && isspace((unsigned char)*s)) {
659e670fd5cSchristos 		s++;                         /* Skip white space before value */
660e670fd5cSchristos 	}
661e670fd5cSchristos 	if (*s) {
662e670fd5cSchristos 		if (*s != ':') {           /* If value is present, must start with : */
663e670fd5cSchristos 			rc = LDAP_PARAM_ERROR;
664e670fd5cSchristos 			goto cleanup;
665e670fd5cSchristos 		}
666e670fd5cSchristos 
667e670fd5cSchristos 		/* Back up so value is in the form
668e670fd5cSchristos 		     a: value
669e670fd5cSchristos 		     a:: base64-value
670e670fd5cSchristos 		     a:< url
671e670fd5cSchristos 		   Then we can use ldif_parse_line2 to extract and decode the value
672e670fd5cSchristos 		*/
673e670fd5cSchristos 		s--;
674e670fd5cSchristos 		*s = 'a';
675e670fd5cSchristos 
676e670fd5cSchristos 		rc = ldif_parse_line2(s, &type, &bv, &freeval);
677e670fd5cSchristos 		if (rc < 0) {
678e670fd5cSchristos 			rc = LDAP_PARAM_ERROR;
679e670fd5cSchristos 			goto cleanup;
680e670fd5cSchristos 		}
681e670fd5cSchristos     }
682e670fd5cSchristos 
683e670fd5cSchristos 	/* Create a new LDAPControl structure. */
684e670fd5cSchristos 	newctrl = (LDAPControl *)ber_memalloc(sizeof(LDAPControl));
685e670fd5cSchristos 	if ( newctrl == NULL ) {
686e670fd5cSchristos 		rc = LDAP_NO_MEMORY;
687e670fd5cSchristos 		goto cleanup;
688e670fd5cSchristos 	}
689e670fd5cSchristos 	newctrl->ldctl_oid = oid;
690e670fd5cSchristos 	oid = NULL;
691e670fd5cSchristos 	newctrl->ldctl_iscritical = criticality;
692e670fd5cSchristos 	if ( freeval )
693e670fd5cSchristos 		newctrl->ldctl_value = bv;
694e670fd5cSchristos 	else
695e670fd5cSchristos 		ber_dupbv( &newctrl->ldctl_value, &bv );
696e670fd5cSchristos 
697e670fd5cSchristos 	/* Add the new control to the passed-in list of controls. */
698e670fd5cSchristos 	i = 0;
699e670fd5cSchristos 	if (pctrls) {
700e670fd5cSchristos 		while ( pctrls[i] ) {    /* Count the # of controls passed in */
701e670fd5cSchristos 			i++;
702e670fd5cSchristos 		}
703e670fd5cSchristos 	}
704e670fd5cSchristos 	/* Allocate 1 more slot for the new control and 1 for the NULL. */
705e670fd5cSchristos 	pctrls = (LDAPControl **) ber_memrealloc(pctrls,
706e670fd5cSchristos 		(i+2)*(sizeof(LDAPControl *)));
707e670fd5cSchristos 	if (pctrls == NULL) {
708e670fd5cSchristos 		rc = LDAP_NO_MEMORY;
709e670fd5cSchristos 		goto cleanup;
710e670fd5cSchristos 	}
711e670fd5cSchristos 	pctrls[i] = newctrl;
712e670fd5cSchristos 	newctrl = NULL;
713e670fd5cSchristos 	pctrls[i+1] = NULL;
714e670fd5cSchristos 	*ppctrls = pctrls;
715e670fd5cSchristos 
716e670fd5cSchristos cleanup:
717e670fd5cSchristos 	if (newctrl) {
718e670fd5cSchristos 		if (newctrl->ldctl_oid) ber_memfree(newctrl->ldctl_oid);
719e670fd5cSchristos 		if (newctrl->ldctl_value.bv_val) {
720e670fd5cSchristos 			ber_memfree(newctrl->ldctl_value.bv_val);
721e670fd5cSchristos 		}
722e670fd5cSchristos 		ber_memfree(newctrl);
723e670fd5cSchristos 	}
724e670fd5cSchristos 	if (oid) ber_memfree(oid);
725e670fd5cSchristos 
726e670fd5cSchristos 	return( rc );
727e670fd5cSchristos }
728e670fd5cSchristos 
729e670fd5cSchristos 
730