| 1 |
/* extended.c - sock backend extended routines */ |
| 2 |
/* $OpenLDAP$ */ |
| 3 |
/* This work is part of OpenLDAP Software <http://www.openldap.org/>. |
| 4 |
* |
| 5 |
* Copyright 2000-2024 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 |
|
| 17 |
#include "portable.h" |
| 18 |
|
| 19 |
#include <stdio.h> |
| 20 |
#include <ac/string.h> |
| 21 |
|
| 22 |
#include "slap.h" |
| 23 |
#include "back-sock.h" |
| 24 |
|
| 25 |
#include "lutil.h" |
| 26 |
|
| 27 |
int |
| 28 |
sock_back_extended( Operation *op, SlapReply *rs ) |
| 29 |
{ |
| 30 |
int rc; |
| 31 |
struct sockinfo *si = (struct sockinfo *) op->o_bd->be_private; |
| 32 |
FILE *fp; |
| 33 |
struct berval b64; |
| 34 |
|
| 35 |
Debug( LDAP_DEBUG_ARGS, "==> sock_back_extended(%s, %s)\n", |
| 36 |
op->ore_reqoid.bv_val, op->o_req_dn.bv_val ); |
| 37 |
|
| 38 |
if ( (fp = opensock( si->si_sockpath )) == NULL ) { |
| 39 |
send_ldap_error( op, rs, LDAP_OTHER, |
| 40 |
"could not open socket" ); |
| 41 |
return( -1 ); |
| 42 |
} |
| 43 |
|
| 44 |
/* write out the request to the extended process */ |
| 45 |
fprintf( fp, "EXTENDED\n" ); |
| 46 |
fprintf( fp, "msgid: %ld\n", (long) op->o_msgid ); |
| 47 |
sock_print_conn( fp, op->o_conn, si ); |
| 48 |
sock_print_suffixes( fp, op->o_bd ); |
| 49 |
fprintf( fp, "oid: %s\n", op->ore_reqoid.bv_val ); |
| 50 |
|
| 51 |
if (op->ore_reqdata) { |
| 52 |
|
| 53 |
b64.bv_len = LUTIL_BASE64_ENCODE_LEN( op->ore_reqdata->bv_len ) + 1; |
| 54 |
b64.bv_val = op->o_tmpalloc( b64.bv_len + 1, op->o_tmpmemctx ); |
| 55 |
|
| 56 |
rc = lutil_b64_ntop( |
| 57 |
(unsigned char *) op->ore_reqdata->bv_val, op->ore_reqdata->bv_len, |
| 58 |
b64.bv_val, b64.bv_len ); |
| 59 |
|
| 60 |
b64.bv_len = rc; |
| 61 |
assert( strlen(b64.bv_val) == b64.bv_len ); |
| 62 |
|
| 63 |
fprintf( fp, "value: %s\n", b64.bv_val ); |
| 64 |
|
| 65 |
op->o_tmpfree( b64.bv_val, op->o_tmpmemctx ); |
| 66 |
|
| 67 |
} |
| 68 |
|
| 69 |
fprintf( fp, "\n" ); |
| 70 |
|
| 71 |
/* read in the results and send them along */ |
| 72 |
rc = sock_read_and_send_results( op, rs, fp ); |
| 73 |
fclose( fp ); |
| 74 |
|
| 75 |
return( rc ); |
| 76 |
} |