Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / openldap / dist / servers / slapd / back-shell / add.c
blobee16e4b389fa3170cb1f03b52fd445d18224b9f9
1 /* add.c - shell backend add function */
2 /* $OpenLDAP: pkg/ldap/servers/slapd/back-shell/add.c,v 1.27.2.3 2008/02/11 23:26:47 kurt Exp $ */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2008 The OpenLDAP Foundation.
6 * All rights reserved.
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.
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>.
16 /* Portions Copyright (c) 1995 Regents of the University of Michigan.
17 * All rights reserved.
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.
26 /* ACKNOWLEDGEMENTS:
27 * This work was originally developed by the University of Michigan
28 * (as part of U-MICH LDAP).
31 #include "portable.h"
33 #include <stdio.h>
35 #include <ac/string.h>
36 #include <ac/socket.h>
38 #include "slap.h"
39 #include "shell.h"
41 int
42 shell_back_add(
43 Operation *op,
44 SlapReply *rs )
46 struct shellinfo *si = (struct shellinfo *) op->o_bd->be_private;
47 AttributeDescription *entry = slap_schema.si_ad_entry;
48 FILE *rfp, *wfp;
49 int len;
51 if ( si->si_add == NULL ) {
52 send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
53 "add not implemented" );
54 return( -1 );
57 if ( ! access_allowed( op, op->oq_add.rs_e,
58 entry, NULL, ACL_WADD, NULL ) )
60 send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS, NULL );
61 return -1;
64 if ( forkandexec( si->si_add, &rfp, &wfp ) == (pid_t)-1 ) {
65 send_ldap_error( op, rs, LDAP_OTHER,
66 "could not fork/exec" );
67 return( -1 );
70 /* write out the request to the add process */
71 fprintf( wfp, "ADD\n" );
72 fprintf( wfp, "msgid: %ld\n", (long) op->o_msgid );
73 print_suffixes( wfp, op->o_bd );
74 ldap_pvt_thread_mutex_lock( &entry2str_mutex );
75 fprintf( wfp, "%s", entry2str( op->oq_add.rs_e, &len ) );
76 ldap_pvt_thread_mutex_unlock( &entry2str_mutex );
77 fclose( wfp );
79 /* read in the result and send it along */
80 read_and_send_results( op, rs, rfp );
82 fclose( rfp );
83 return( 0 );