~ubuntu-branches/ubuntu/maverick/openldap/maverick-proposed

« back to all changes in this revision

Viewing changes to clients/tools/common.c

  • Committer: Bazaar Package Importer
  • Author(s): Mathias Gug
  • Date: 2009-09-07 13:41:10 UTC
  • mto: This revision was merged to the branch mainline in revision 19.
  • Revision ID: james.westby@ubuntu.com-20090907134110-jsdrvn0atu1fex4m
Tags: upstream-2.4.18
ImportĀ upstreamĀ versionĀ 2.4.18

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* common.c - common routines for the ldap client tools */
2
 
/* $OpenLDAP: pkg/ldap/clients/tools/common.c,v 1.78.2.22 2009/05/01 20:00:34 quanah Exp $ */
 
2
/* $OpenLDAP: pkg/ldap/clients/tools/common.c,v 1.78.2.27 2009/08/25 22:58:08 quanah Exp $ */
3
3
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4
4
 *
5
5
 * Copyright 1998-2009 The OpenLDAP Foundation.
120
120
static int      sessionTracking = 0;
121
121
struct berval   stValue;
122
122
#endif /* LDAP_CONTROL_X_SESSION_TRACKING */
 
123
ber_int_t vlvPos;
 
124
ber_int_t vlvCount;
 
125
struct berval *vlvContext;
123
126
 
124
127
LDAPControl     *unknown_ctrls = NULL;
125
128
int             unknown_ctrls_num = 0;
136
139
static int print_ppolicy( LDAP *ld, LDAPControl *ctrl );
137
140
#endif
138
141
static int print_sss( LDAP *ld, LDAPControl *ctrl );
 
142
static int print_vlv( LDAP *ld, LDAPControl *ctrl );
139
143
#ifdef LDAP_CONTROL_X_DEREF
140
144
static int print_deref( LDAP *ld, LDAPControl *ctrl );
141
145
#endif
155
159
        { LDAP_CONTROL_PASSWORDPOLICYRESPONSE,          TOOL_ALL,       print_ppolicy },
156
160
#endif
157
161
        { LDAP_CONTROL_SORTRESPONSE,    TOOL_SEARCH,    print_sss },
 
162
        { LDAP_CONTROL_VLVRESPONSE,             TOOL_SEARCH,    print_vlv },
158
163
#ifdef LDAP_CONTROL_X_DEREF
159
164
        { LDAP_CONTROL_X_DEREF,                         TOOL_SEARCH,    print_deref },
160
165
#endif
266
271
tool_common_usage( void )
267
272
{
268
273
        static const char *const descriptions[] = {
269
 
N_("  -c         continuous operation mode (do not stop on errors)\n"),
270
274
N_("  -d level   set LDAP debugging level to `level'\n"),
271
275
N_("  -D binddn  bind DN\n"),
272
276
N_("  -e [!]<ext>[=<extparam>] general extensions (! indicates criticality)\n")
297
301
N_("             abandon, cancel, ignore (SIGINT sends abandon/cancel,\n"
298
302
   "             or ignores response; if critical, doesn't wait for SIGINT.\n"
299
303
   "             not really controls)\n")
300
 
N_("  -f file    read operations from `file'\n"),
301
304
N_("  -h host    LDAP server\n"),
302
305
N_("  -H URI     LDAP Uniform Resource Identifier(s)\n"),
303
306
N_("  -I         use SASL Interactive mode\n"),
304
 
N_("  -M         enable Manage DSA IT control (-MM to make critical)\n"),
305
307
N_("  -n         show what would be done but don't actually do it\n"),
306
308
N_("  -N         do not use reverse DNS to canonicalize SASL host name\n"),
307
309
N_("  -O props   SASL security properties\n"),
308
310
N_("  -o <opt>[=<optparam] general options\n"),
309
311
N_("             nettimeout=<timeout> (in seconds, or \"none\" or \"max\")\n"),
310
312
N_("  -p port    port on LDAP server\n"),
311
 
N_("  -P version protocol version (default: 3)\n"),
312
313
N_("  -Q         use SASL Quiet mode\n"),
313
314
N_("  -R realm   SASL realm\n"),
314
315
N_("  -U authcid SASL authentication identity\n"),
1917
1918
        rc = ldap_parse_sortresponse_control( ld, ctrl, &err, &attr );
1918
1919
        if ( rc == LDAP_SUCCESS ) {
1919
1920
                char buf[ BUFSIZ ];
1920
 
                rc = snprintf( buf, sizeof(buf), "(%d) %s %s",
1921
 
                        err, ldap_err2string(err), attr ? attr : "" );
 
1921
                rc = snprintf( buf, sizeof(buf), "(%d) %s%s%s",
 
1922
                        err, ldap_err2string(err), attr ? " " : "", attr ? attr : "" );
1922
1923
 
1923
1924
                tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_VALUE,
1924
1925
                        "sortResult", buf, rc );
1927
1928
        return rc;
1928
1929
}
1929
1930
 
 
1931
static int
 
1932
print_vlv( LDAP *ld, LDAPControl *ctrl )
 
1933
{
 
1934
        int rc;
 
1935
        ber_int_t err;
 
1936
        struct berval bv;
 
1937
 
 
1938
        rc = ldap_parse_vlvresponse_control( ld, ctrl, &vlvPos, &vlvCount,
 
1939
                &vlvContext, &err );
 
1940
        if ( rc == LDAP_SUCCESS ) {
 
1941
                char buf[ BUFSIZ ];
 
1942
 
 
1943
                if ( vlvContext && vlvContext->bv_len > 0 ) {
 
1944
                        bv.bv_len = LUTIL_BASE64_ENCODE_LEN(
 
1945
                                vlvContext->bv_len ) + 1;
 
1946
                        bv.bv_val = ber_memalloc( bv.bv_len + 1 );
 
1947
 
 
1948
                        bv.bv_len = lutil_b64_ntop(
 
1949
                                (unsigned char *) vlvContext->bv_val,
 
1950
                                vlvContext->bv_len,
 
1951
                                bv.bv_val, bv.bv_len );
 
1952
                } else {
 
1953
                        bv.bv_val = "";
 
1954
                        bv.bv_len = 0;
 
1955
                }
 
1956
 
 
1957
                rc = snprintf( buf, sizeof(buf), "pos=%d count=%d context=%s (%d) %s",
 
1958
                        vlvPos, vlvCount, bv.bv_val,
 
1959
                        err, ldap_err2string(err));
 
1960
 
 
1961
                if ( bv.bv_len )
 
1962
                        ber_memfree( bv.bv_val );
 
1963
 
 
1964
                tool_write_ldif( ldif ? LDIF_PUT_COMMENT : LDIF_PUT_VALUE,
 
1965
                        "vlvResult", buf, rc );
 
1966
        }
 
1967
 
 
1968
        return rc;
 
1969
}
 
1970
 
1930
1971
#ifdef LDAP_CONTROL_X_DEREF
1931
1972
static int
1932
1973
print_deref( LDAP *ld, LDAPControl *ctrl )
1971
2012
                        if ( dv->vals != NULL ) {
1972
2013
                                int j;
1973
2014
                                for ( j = 0; dv->vals[ j ].bv_val != NULL; j++ ) {
1974
 
                                        int k;
1975
 
 
1976
 
                                        for ( k = 0; k < dv->vals[ j ].bv_len; k++ ) {
1977
 
                                                if ( !isprint( dv->vals[ j ].bv_val[k] ) ) {
1978
 
                                                        k = -1;
1979
 
                                                        break;
1980
 
                                                }
1981
 
                                        }
 
2015
                                        int k = ldif_is_not_printable( dv->vals[ j ].bv_val, dv->vals[ j ].bv_len );
1982
2016
 
1983
2017
                                        *ptr++ = '<';
1984
2018
                                        ptr = lutil_strcopy( ptr, dv->type );
1985
 
                                        if ( k == -1 ) {
 
2019
                                        if ( k ) {
1986
2020
                                                *ptr++ = ':';
1987
2021
                                        }
1988
2022
                                        *ptr++ = '=';
1989
 
                                        if ( k == -1 ) {
 
2023
                                        if ( k ) {
1990
2024
                                                k = lutil_b64_ntop(
1991
2025
                                                        (unsigned char *) dv->vals[ j ].bv_val,
1992
2026
                                                        dv->vals[ j ].bv_len,
2004
2038
                }
2005
2039
                ptr = lutil_strncopy( ptr, dr->derefVal.bv_val, dr->derefVal.bv_len );
2006
2040
                *ptr++ = '\n';
2007
 
                *ptr++ = '\0';
 
2041
                *ptr = '\0';
2008
2042
                assert( ptr <= buf + len );
2009
2043
 
2010
2044
                tool_write_ldif( LDIF_PUT_COMMENT, NULL, buf, ptr - buf);