+ newsup = vals[i].bv_val;
+ i++;
+ }
+ got_all = 1;
+ } else if ( BV_CASEMATCH( vals+i, &BV_DELETECT )) {
+ got_all = delete_entry = 1;
+ } else {
+ fprintf( stderr,
+ _("%s: unknown %s \"%s\" (line %d, entry \"%s\")\n"),
+ prog, BV_CHANGETYPE.bv_val, vals[i].bv_val, linenum+i, dn );
+ rc = LDAP_PARAM_ERROR;
+ goto leave;
+ }
+ i++;
+ } else if ( ldapadd ) { /* missing changetype => add */
+ new_entry = 1;
+ modop = LDAP_MOD_ADD;
+ } else {
+ expect_modop = 1; /* missing changetype => modify */
+ }
+
+ if ( got_all ) {
+ if ( i < lines ) {
+ fprintf( stderr,
+ _("%s: extra lines at end (line %d, entry \"%s\")\n"),
+ prog, linenum+i, dn );
+ rc = LDAP_PARAM_ERROR;
+ goto leave;
+ }
+ goto doit;
+ }
+
+ nmods = lines - i;
+ idn = i;
+
+ if ( new_entry ) {
+ int fv;
+
+ /* Make sure all attributes with multiple values are contiguous */
+ for (; i<lines; i++) {
+ for (j=i+1; j<lines; j++) {
+ if ( BV_CASEMATCH( btype+i, btype+j )) {
+ nmods--;
+ /* out of order, move intervening attributes down */
+ if ( j != i+1 ) {
+ bv = vals[j];
+ fv = freeval[j];
+ for (k=j; k>i; k--) {
+ btype[k] = btype[k-1];
+ vals[k] = vals[k-1];
+ freeval[k] = freeval[k-1];
+ }
+ k++;
+ btype[k] = btype[i];
+ vals[k] = bv;
+ freeval[k] = fv;
+ }
+ i++;
+ }
+ }
+ }
+ /* Allocate space for array of mods, array of pointers to mods,
+ * and array of pointers to values, allowing for NULL terminators
+ * for the pointer arrays...
+ */
+ lm = ber_memalloc( nmods * sizeof(LDAPMod) +
+ (nmods+1) * sizeof(LDAPMod*) +
+ (lines + nmods - idn) * sizeof(struct berval *));
+ pmods = (LDAPMod **)(lm+nmods);
+ bvl = (struct berval **)(pmods+nmods+1);
+
+ j = 0;
+ k = -1;
+ BER_BVZERO(&bv);
+ for (i=idn; i<lines; i++) {
+ if ( BV_CASEMATCH( btype+i, &BV_DN )) {
+ fprintf( stderr, _("%s: attributeDescription \"%s\":"
+ " (possible missing newline"
+ " after line %d, entry \"%s\"?)\n"),
+ prog, btype[i].bv_val, linenum+i - 1, dn );
+ }
+ if ( !BV_CASEMATCH( btype+i, &bv )) {
+ bvl[k++] = NULL;
+ bv = btype[i];
+ lm[j].mod_op = LDAP_MOD_ADD | LDAP_MOD_BVALUES;
+ lm[j].mod_type = bv.bv_val;
+ lm[j].mod_bvalues = bvl+k;
+ pmods[j] = lm+j;
+ j++;