1 /* $NetBSD: extended.c,v 1.3 2021/08/14 16:15:01 christos Exp $ */
2
3 /* extended.c - sock backend extended routines */
4 /* $OpenLDAP$ */
5 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
6 *
7 * Copyright 2000-2021 The OpenLDAP Foundation.
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted only as authorized by the OpenLDAP
12 * Public License.
13 *
14 * A copy of this license is available in the file LICENSE in the
15 * top-level directory of the distribution or, alternatively, at
16 * <http://www.OpenLDAP.org/license.html>.
17 */
18
19 #include <sys/cdefs.h>
20 __RCSID("$NetBSD: extended.c,v 1.3 2021/08/14 16:15:01 christos Exp $");
21
22 #include "portable.h"
23
24 #include <stdio.h>
25 #include <ac/string.h>
26
27 #include "slap.h"
28 #include "back-sock.h"
29
30 #include "lutil.h"
31
32 int
sock_back_extended(Operation * op,SlapReply * rs)33 sock_back_extended( Operation *op, SlapReply *rs )
34 {
35 int rc;
36 struct sockinfo *si = (struct sockinfo *) op->o_bd->be_private;
37 FILE *fp;
38 struct berval b64;
39
40 Debug( LDAP_DEBUG_ARGS, "==> sock_back_extended(%s, %s)\n",
41 op->ore_reqoid.bv_val, op->o_req_dn.bv_val );
42
43 if ( (fp = opensock( si->si_sockpath )) == NULL ) {
44 send_ldap_error( op, rs, LDAP_OTHER,
45 "could not open socket" );
46 return( -1 );
47 }
48
49 /* write out the request to the extended process */
50 fprintf( fp, "EXTENDED\n" );
51 fprintf( fp, "msgid: %ld\n", (long) op->o_msgid );
52 sock_print_conn( fp, op->o_conn, si );
53 sock_print_suffixes( fp, op->o_bd );
54 fprintf( fp, "oid: %s\n", op->ore_reqoid.bv_val );
55
56 if (op->ore_reqdata) {
57
58 b64.bv_len = LUTIL_BASE64_ENCODE_LEN( op->ore_reqdata->bv_len ) + 1;
59 b64.bv_val = op->o_tmpalloc( b64.bv_len + 1, op->o_tmpmemctx );
60
61 rc = lutil_b64_ntop(
62 (unsigned char *) op->ore_reqdata->bv_val, op->ore_reqdata->bv_len,
63 b64.bv_val, b64.bv_len );
64
65 b64.bv_len = rc;
66 assert( strlen(b64.bv_val) == b64.bv_len );
67
68 fprintf( fp, "value: %s\n", b64.bv_val );
69
70 op->o_tmpfree( b64.bv_val, op->o_tmpmemctx );
71
72 }
73
74 fprintf( fp, "\n" );
75
76 /* read in the results and send them along */
77 rc = sock_read_and_send_results( op, rs, fp );
78 fclose( fp );
79
80 return( rc );
81 }
82