~ubuntu-branches/ubuntu/hardy/openldap2.3/hardy-updates

« back to all changes in this revision

Viewing changes to servers/slapd/back-sock/modify.c

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2008-07-31 16:06:53 UTC
  • mfrom: (16.1.3 hardy-proposed)
  • Revision ID: james.westby@ubuntu.com-20080731160653-np1dr19qfutmqb0v
Tags: 2.4.9-0ubuntu0.8.04.1
* SECURITY UPDATE: denial of service via broken BER decoding.
* Added debian/patches/security-ber-decoding.patch: upstream fixes.
* References
  CVE-2008-2952

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* modify.c - sock backend modify function */
 
2
/* $OpenLDAP: pkg/ldap/servers/slapd/back-sock/modify.c,v 1.3.2.1 2008/02/09 00:46:09 quanah Exp $ */
 
3
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
 
4
 *
 
5
 * Copyright 2007-2008 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
/* ACKNOWLEDGEMENTS:
 
17
 * This work was initially developed by Brian Candler for inclusion
 
18
 * in OpenLDAP Software.
 
19
 */
 
20
 
 
21
#include "portable.h"
 
22
 
 
23
#include <stdio.h>
 
24
 
 
25
#include <ac/string.h>
 
26
#include <ac/socket.h>
 
27
 
 
28
#include "slap.h"
 
29
#include "back-sock.h"
 
30
 
 
31
int
 
32
sock_back_modify(
 
33
    Operation   *op,
 
34
    SlapReply   *rs )
 
35
{
 
36
        Modification *mod;
 
37
        struct sockinfo *si = (struct sockinfo *) op->o_bd->be_private;
 
38
        AttributeDescription *entry = slap_schema.si_ad_entry;
 
39
        Modifications *ml  = op->orm_modlist;
 
40
        Entry e;
 
41
        FILE                    *fp;
 
42
        int                     i;
 
43
 
 
44
        e.e_id = NOID;
 
45
        e.e_name = op->o_req_dn;
 
46
        e.e_nname = op->o_req_ndn;
 
47
        e.e_attrs = NULL;
 
48
        e.e_ocflags = 0;
 
49
        e.e_bv.bv_len = 0;
 
50
        e.e_bv.bv_val = NULL;
 
51
        e.e_private = NULL;
 
52
 
 
53
        if ( ! access_allowed( op, &e,
 
54
                entry, NULL, ACL_WRITE, NULL ) )
 
55
        {
 
56
                send_ldap_error( op, rs, LDAP_INSUFFICIENT_ACCESS, NULL );
 
57
                return -1;
 
58
        }
 
59
 
 
60
        if ( (fp = opensock( si->si_sockpath )) == NULL ) {
 
61
                send_ldap_error( op, rs, LDAP_OTHER,
 
62
                    "could not open socket" );
 
63
                return( -1 );
 
64
        }
 
65
 
 
66
        /* write out the request to the modify process */
 
67
        fprintf( fp, "MODIFY\n" );
 
68
        fprintf( fp, "msgid: %ld\n", (long) op->o_msgid );
 
69
        sock_print_conn( fp, op->o_conn, si );
 
70
        sock_print_suffixes( fp, op->o_bd );
 
71
        fprintf( fp, "dn: %s\n", op->o_req_dn.bv_val );
 
72
        for ( ; ml != NULL; ml = ml->sml_next ) {
 
73
                mod = &ml->sml_mod;
 
74
 
 
75
                /* FIXME: should use LDIF routines to deal with binary data */
 
76
 
 
77
                switch ( mod->sm_op ) {
 
78
                case LDAP_MOD_ADD:
 
79
                        fprintf( fp, "add: %s\n", mod->sm_desc->ad_cname.bv_val );
 
80
                        break;
 
81
 
 
82
                case LDAP_MOD_DELETE:
 
83
                        fprintf( fp, "delete: %s\n", mod->sm_desc->ad_cname.bv_val );
 
84
                        break;
 
85
 
 
86
                case LDAP_MOD_REPLACE:
 
87
                        fprintf( fp, "replace: %s\n", mod->sm_desc->ad_cname.bv_val );
 
88
                        break;
 
89
                }
 
90
 
 
91
                if( mod->sm_values != NULL ) {
 
92
                        for ( i = 0; mod->sm_values[i].bv_val != NULL; i++ ) {
 
93
                                fprintf( fp, "%s: %s\n", mod->sm_desc->ad_cname.bv_val,
 
94
                                        mod->sm_values[i].bv_val /* binary! */ );
 
95
                        }
 
96
                }
 
97
 
 
98
                fprintf( fp, "-\n" );
 
99
        }
 
100
        fprintf( fp, "\n" );
 
101
 
 
102
        /* read in the results and send them along */
 
103
        sock_read_and_send_results( op, rs, fp );
 
104
        fclose( fp );
 
105
        return( 0 );
 
106
}