Bug#820790: ldapvi: sorts entries alphabetically which can break specific modifications where the order of the definitions is important

2021-02-21 Thread Ralf Becker
This bug causes editing of a schema definition to fail.

The error message reads:
```
ldap_modify: Other (e.g., implementation specific) error (80)
additional info: olcObjectClasses: ObjectClass not found: "idmPerson"
Error at: cn={8}yyy,cn=schema,cn=config
```

The reason for this is the sorting of the values.

## Example

This definition is only correct in exactly this order,
because `idmStudent` builds on `idmPerson`:
```
olcObjectClasses: {3}( 1.3.6.1.4.1..1 NAME 'idmPerson'
SUP top AUXILIARY MUST ( uid $ givenName ) )
...
olcObjectClasses: {11}( 1.3.6.1.4.1..2 NAME 'idmStudent'
SUP idmPerson AUXILIARY MAY ( mtr ) )
```

Sorting turns it into:
```
olcObjectClasses: {11}( 1.3.6.1.4.1..2 NAME 'idmStudent'
SUP idmPerson AUXILIARY MAY ( mtr ) )
...
olcObjectClasses: {3}( 1.3.6.1.4.1..1 NAME 'idmPerson'
SUP top AUXILIARY MUST ( uid $ givenName ) )
```

And that then leads to described error.


## Conclusion:

There seems to be no valid reason why the values are sorted.
Attribute values should be taken in *exactly* the order
in which they are entered in `vi`.


## Patch:

This patch ensures that reordering no longer takes place and
fixes the problem in the case shown above.

```
diff --git a/ldapvi/diff.c b/ldapvi/diff.c
index e2787a3..42de566 100644
--- a/ldapvi/diff.c
+++ b/ldapvi/diff.c
@@ -29,8 +29,8 @@ compare_ptr_arrays(GPtrArray *a, GPtrArray *b,
int i = 0;
int j = 0;
 
-   qsort(a->pdata, a->len, sizeof(void *), cmp);
-   qsort(b->pdata, b->len, sizeof(void *), cmp);
+// qsort(a->pdata, a->len, sizeof(void *), cmp);
+// qsort(b->pdata, b->len, sizeof(void *), cmp);
 
while (i < a->len && j < b->len) {
void *ax = g_ptr_array_index(a, i);

```



Bug#820790: ldapvi: sorts entries alphabetically which can break specific modifications where the order of the definitions is important

2016-04-12 Thread Axel Beckert
Package: ldapvi
Version: 1.7-9
Severity: normal
Tags: upstream

Hi,

the following bug report comes from a co-worker of mine who tried to
edit cn=config with ldapvi:

Summary:


ldapvi seems to sort entries alphabetically, which may break specific
modifications where the order of the definitions is important.

Instructions to reproduce the bug:
--

Install slapd on Debian Jessie.

Create `import.ldif` with the following contents:

dn: cn={4}dummy,cn=schema,cn=config
changetype: add
objectClass: olcSchemaConfig
olcObjectClasses: {0}( 7.16.840.1.113730.3.2.0 NAME 'objClass0' DESC 'Dummy 
Object Class 0' )
olcObjectClasses: {1}( 7.16.840.1.113730.3.2.1 NAME 'dummyParent' DESC 
'Dummy Parent' SUP posixAccount AUXILIARY )
olcObjectClasses: {2}( 7.16.840.1.113730.3.2.2 NAME 'objClass2' DESC 'Dummy 
Object Class 2')
olcObjectClasses: {3}( 7.16.840.1.113730.3.2.3 NAME 'objClass3' DESC 'Dummy 
Object Class 3')
olcObjectClasses: {4}( 7.16.840.1.113730.3.2.4 NAME 'objClass4' DESC 'Dummy 
Object Class 4')
olcObjectClasses: {5}( 7.16.840.1.113730.3.2.5 NAME 'objClass5' DESC 'Dummy 
Object Class 5')
olcObjectClasses: {6}( 7.16.840.1.113730.3.2.6 NAME 'objClass6' DESC 'Dummy 
Object Class 6')
olcObjectClasses: {7}( 7.16.840.1.113730.3.2.7 NAME 'objClass7' DESC 'Dummy 
Object Class 7')
olcObjectClasses: {8}( 7.16.840.1.113730.3.2.8 NAME 'objClass8' DESC 'Dummy 
Object Class 8')
olcObjectClasses: {9}( 7.16.840.1.113730.3.2.9 NAME 'objClass9' DESC 'Dummy 
Object Class 9')

then add it to ldap

ldapadd -Y EXTERNAL -H ldapi:/// -f import.ldif

Next use ldapvi to edit the config

ldapvi -Y EXTERNAL -h ldapi:/// -b "cn=config"

and add a 10th Objectclass at the end of the newly added cn={4}dummy
after objClass9

olcObjectClasses: {10}( 7.16.840.1.113730.3.2.10 NAME 'dummyChild' DESC 
'Dummy Child' SUP dummyParent AUXILIARY )

when saving and quitting vi, stdout shows

SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
 12 entries read
add: 0, rename: 0, modify: 1, delete: 0
Action? [yYqQvVebB*rsf+?]

confirming the action with y produces the following error message:

ldap_modify: Other (e.g., implementation specific) error (80)
additional info: olcObjectClasses: ObjectClass not found: "dummyParent"
Error at: cn={4}dummy,cn=schema,cn=config

Abort with q, which saves the ldif to a local file named like
",ldapvi-hostname-x.ldif"

Inspect the file to see that the elements are in alphabetical, instead
of numerical order

version: 1
# to apply these changes using ldapvi, run:
#   ldapvi --ldapmodify -h ldapi:/// ,ldapvi-hostname-x.ldif

dn: cn={4}dummy,cn=schema,cn=config
changetype: modify
replace: olcObjectClasses
olcObjectClasses: {0}( 7.16.840.1.113730.3.2.0 NAME 'objClass0' DESC 'Dummy 
Object Class 0' )
olcObjectClasses: {10}( 7.16.840.1.113730.3.2.10 NAME 'dummyChild' DESC 
'Dummy Child' SUP dummyParent AUXILIARY )
olcObjectClasses: {1}( 7.16.840.1.113730.3.2.1 NAME 'dummyParent' DESC 
'Dummy Parent' SUP posixAccount AUXILIARY )
olcObjectClasses: {2}( 7.16.840.1.113730.3.2.2 NAME 'objClass2' DESC 'Dummy 
Object Class 2')
olcObjectClasses: {3}( 7.16.840.1.113730.3.2.3 NAME 'objClass3' DESC 'Dummy 
Object Class 3')
olcObjectClasses: {4}( 7.16.840.1.113730.3.2.4 NAME 'objClass4' DESC 'Dummy 
Object Class 4')
olcObjectClasses: {5}( 7.16.840.1.113730.3.2.5 NAME 'objClass5' DESC 'Dummy 
Object Class 5')
olcObjectClasses: {6}( 7.16.840.1.113730.3.2.6 NAME 'objClass6' DESC 'Dummy 
Object Class 6')
olcObjectClasses: {7}( 7.16.840.1.113730.3.2.7 NAME 'objClass7' DESC 'Dummy 
Object Class 7')
olcObjectClasses: {8}( 7.16.840.1.113730.3.2.8 NAME 'objClass8' DESC 'Dummy 
Object Class 8')
olcObjectClasses: {9}( 7.16.840.1.113730.3.2.9 NAME 'objClass9' DESC 'Dummy 
Object Class 9')
-

Adding it with ldapadd fails with the same error message

ldapadd -Y EXTERNAL -H ldapi:/// -f ,ldapvi-hostname-x.ldif

as it tries to add the dummyChild before knowing the dummyParent.


Edit it to put the elements into correct order, ie putting the 10th
element at the end

version: 1
# to apply these changes using ldapvi, run:
#   ldapvi --ldapmodify -h ldapi:/// ,ldapvi-hostname-x.ldif

dn: cn={4}dummy,cn=schema,cn=config
changetype: modify
replace: olcObjectClasses
olcObjectClasses: {0}( 7.16.840.1.113730.3.2.0 NAME 'objClass0' DESC 'Dummy 
Object Class 0' )
olcObjectClasses: {1}( 7.16.840.1.113730.3.2.1 NAME 'dummyParent' DESC 
'Dummy Parent' SUP posixAccount AUXILIARY )
olcObjectClasses: {2}( 7.16.840.1.113730.3.2.2 NAME 'objClass2' DESC 'Dummy 
Object Class 2')
olcObjectClasses: {3}( 7.16.840.1.113730.3.2.3 NAME 'objClass3' DESC 'Dummy 
Object Class 3')
olcObjectClasses: {4}( 7.16.840.1.113730.3.2.4 NAME