]> git.sur5r.net Git - openldap/commitdiff
cleanup controls logging in LDIF mode (-L[L[L]], ITS#6775)
authorPierangelo Masarati <ando@openldap.org>
Tue, 4 Jan 2011 18:20:04 +0000 (18:20 +0000)
committerPierangelo Masarati <ando@openldap.org>
Tue, 4 Jan 2011 18:20:04 +0000 (18:20 +0000)
clients/tools/common.c

index 2177c652d980a32ae548165e03177212ba8e571f..d00f84d163828f7fe5b836367efec5052b961623 100644 (file)
@@ -1953,6 +1953,7 @@ print_prepostread( LDAP *ld, LDAPControl *ctrl, struct berval *what)
                while ( ber_scanf( ber, "{m" /*}*/, &bv ) != LBER_ERROR ) {
                        int             i;
                        BerVarray       vals = NULL;
+                       char            *str = NULL;
 
                        if ( ber_scanf( ber, "[W]", &vals ) == LBER_ERROR ||
                                vals == NULL )
@@ -1960,14 +1961,25 @@ print_prepostread( LDAP *ld, LDAPControl *ctrl, struct berval *what)
                                /* error? */
                                return 1;
                        }
+
+                       if ( ldif ) {
+                               char *ptr;
+
+                               str = malloc( bv.bv_len + STRLENOF(": ") + 1 );
+
+                               ptr = str;
+                               ptr = lutil_strncopy( ptr, bv.bv_val, bv.bv_len );
+                               ptr = lutil_strcopy( ptr, ": " );
+                       }
                
                        for ( i = 0; vals[ i ].bv_val != NULL; i++ ) {
                                tool_write_ldif(
                                        ldif ? LDIF_PUT_COMMENT : LDIF_PUT_VALUE,
-                                       bv.bv_val, vals[ i ].bv_val, vals[ i ].bv_len );
+                                       ldif ? str : bv.bv_val, vals[ i ].bv_val, vals[ i ].bv_len );
                        }
 
                        ber_bvarray_free( vals );
+                       if ( str ) free( str );
                }
        }
 
@@ -2047,7 +2059,8 @@ print_paged_results( LDAP *ld, LDAPControl *ctrl )
                }
 
                tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_VALUE,
-                       "pagedresults", buf, ptr - buf );
+                       ldif ? "pagedresults: " : "pagedresults",
+                       buf, ptr - buf );
        }
 
        return 0;
@@ -2067,7 +2080,7 @@ print_sss( LDAP *ld, LDAPControl *ctrl )
                        err, ldap_err2string(err), attr ? " " : "", attr ? attr : "" );
 
                tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_VALUE,
-                       "sortResult", buf, rc );
+                       ldif ? "sortResult: " : "sortResult", buf, rc );
        }
 
        return rc;
@@ -2107,7 +2120,7 @@ print_vlv( LDAP *ld, LDAPControl *ctrl )
                        ber_memfree( bv.bv_val );
 
                tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_VALUE,
-                       "vlvResult", buf, rc );
+                       ldif ? "vlvResult" : "vlvResult", buf, rc );
        }
 
        return rc;
@@ -2241,13 +2254,17 @@ print_whatfailed( LDAP *ld, LDAPControl *ctrl )
 static int
 print_authzid( LDAP *ld, LDAPControl *ctrl )
 {
-    if (ctrl->ldctl_value.bv_len) {
-           tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_VALUE,
-                   "authzid", ctrl->ldctl_value.bv_val,  ctrl->ldctl_value.bv_len );
+       if ( ctrl->ldctl_value.bv_len ) {
+               tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_VALUE,
+                       ldif ? "authzid: " : "authzid",
+               ctrl->ldctl_value.bv_val, ctrl->ldctl_value.bv_len );
        } else {
-           tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_VALUE,
-                   "authzid", "anonymous",  sizeof("anonymous")-1);
+               tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_VALUE,
+                       ldif ? "authzid: " : "authzid",
+                       "anonymous",  STRLENOF("anonymous") );
        }
+
+       return 0;
 }
 #endif
 
@@ -2281,7 +2298,7 @@ print_ppolicy( LDAP *ld, LDAPControl *ctrl )
                }
 
                tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_VALUE,
-                       "ppolicy", buf, ptr - buf );
+                       ldif ? "ppolicy: " : "ppolicy", buf, ptr - buf );
        }
 
        return rc;