]> git.sur5r.net Git - openldap/blob - servers/slapd/back-shell/modrdn.c
Preliminary Make rules to allow building backends as modules.
[openldap] / servers / slapd / back-shell / modrdn.c
1 /* modrdn.c - shell backend modrdn function */
2
3 /*
4  * LDAP v3 newSuperior support.
5  *
6  * Copyright 1999, Juan C. Gomez, All rights reserved.
7  * This software is not subject to any license of Silicon Graphics 
8  * Inc. or Purdue University.
9  *
10  * Redistribution and use in source and binary forms are permitted
11  * without restriction or fee of any kind as long as this notice
12  * is preserved.
13  *
14  */
15
16 #include "portable.h"
17
18 #include <stdio.h>
19
20 #include <ac/socket.h>
21 #include <ac/string.h>
22
23 #include "slap.h"
24 #include "shell.h"
25
26 int
27 shell_back_modrdn(
28     Backend     *be,
29     Connection  *conn,
30     Operation   *op,
31     char        *dn,
32     char        *newrdn,
33     int         deleteoldrdn,
34     char        *newSuperior
35 )
36 {
37         struct shellinfo        *si = (struct shellinfo *) be->be_private;
38         FILE                    *rfp, *wfp;
39
40         if ( si->si_modrdn == NULL ) {
41                 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
42                     "modrdn not implemented", NULL, NULL );
43                 return( -1 );
44         }
45
46         if ( (op->o_private = (void *) forkandexec( si->si_modrdn, &rfp, &wfp ))
47             == (void *) -1 ) {
48                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, NULL,
49                     "could not fork/exec", NULL, NULL );
50                 return( -1 );
51         }
52
53         /* write out the request to the modrdn process */
54         fprintf( wfp, "MODRDN\n" );
55         fprintf( wfp, "msgid: %ld\n", op->o_msgid );
56         print_suffixes( wfp, be );
57         fprintf( wfp, "dn: %s\n", dn );
58         fprintf( wfp, "newrdn: %s\n", newrdn );
59         fprintf( wfp, "deleteoldrdn: %d\n", deleteoldrdn ? 1 : 0 );
60         if (newSuperior != NULL) {
61                 fprintf( wfp, "newSuperior: %s\n", newSuperior );
62         }
63         fclose( wfp );
64
65         /* read in the results and send them along */
66         read_and_send_results( be, conn, op, rfp, NULL, 0 );
67         fclose( rfp );
68         return( 0 );
69 }