Back to index

openldap  2.4.31
Defines | Functions | Variables
slapd-common.c File Reference
#include "portable.h"
#include <stdio.h>
#include "ac/stdlib.h"
#include "ac/unistd.h"
#include "ac/string.h"
#include "ac/errno.h"
#include "ldap.h"
#include "ldap_pvt.h"
#include "slapd-common.h"

Go to the source code of this file.

Defines

#define TESTER_CLIENT_FIRST   LDAP_REFERRAL_LIMIT_EXCEEDED /* negative */
#define TESTER_SERVER_LAST   LDAP_OTHER
#define ignore_count   (ignore_base - TESTER_CLIENT_FIRST)
#define UNKNOWN_ERR   (1234567890)

Functions

static int tester_ignore_str2err (const char *err)
int tester_ignore_str2errlist (const char *err)
int tester_ignore_err (int err)
void tester_init (const char *pname, tester_t ptype)
char * tester_uri (char *uri, char *host, int port)
void tester_ldap_error (LDAP *ld, const char *fname, const char *msg)
void tester_perror (const char *fname, const char *msg)
void tester_error (const char *msg)

Variables

pid_t pid
static char progname [BUFSIZ]
tester_t progtype
static int ignore_base [-TESTER_CLIENT_FIRST+TESTER_SERVER_LAST+1]
struct {
const char * name
int err
ignore_str2err []

Define Documentation

Definition at line 48 of file slapd-common.c.

Definition at line 45 of file slapd-common.c.

Definition at line 46 of file slapd-common.c.

#define UNKNOWN_ERR   (1234567890)

Definition at line 128 of file slapd-common.c.


Function Documentation

void tester_error ( const char *  msg)

Definition at line 297 of file slapd-common.c.

{
       fprintf( stderr, "%s: %s\n", progname, msg );
}

Here is the caller graph for this function:

Definition at line 185 of file slapd-common.c.

{
       int rc = 1;

       if ( err && TESTER_CLIENT_FIRST <= err && err <= TESTER_SERVER_LAST ) {
              rc = ignore_count[ err ];
              if ( rc != 0 ) {
                     ignore_count[ err ] = rc + (rc > 0 ? 1 : -1);
              }
       }

       /* SUCCESS is always "ignored" */
       return rc;
}

Here is the caller graph for this function:

static int tester_ignore_str2err ( const char *  err) [static]

Definition at line 131 of file slapd-common.c.

{
       int           i, ignore = 1;

       if ( strcmp( err, "ALL" ) == 0 ) {
              for ( i = 0; ignore_str2err[ i ].name != NULL; i++ ) {
                     ignore_count[ ignore_str2err[ i ].err ] = 1;
              }
              ignore_count[ LDAP_SUCCESS ] = 0;

              return 0;
       }

       if ( err[ 0 ] == '!' ) {
              ignore = 0;
              err++;

       } else if ( err[ 0 ] == '*' ) {
              ignore = -1;
              err++;
       }

       for ( i = 0; ignore_str2err[ i ].name != NULL; i++ ) {
              if ( strcmp( err, ignore_str2err[ i ].name ) == 0 ) {
                     int    err = ignore_str2err[ i ].err;

                     if ( err != LDAP_SUCCESS ) {
                            ignore_count[ err ] = ignore;
                     }

                     return err;
              }
       }

       return UNKNOWN_ERR;
}

Here is the caller graph for this function:

Definition at line 169 of file slapd-common.c.

{
       int    i;
       char   **errs = ldap_str2charray( err, "," );

       for ( i = 0; errs[ i ] != NULL; i++ ) {
              /* TODO: allow <err>:<prog> to ignore <err> only when <prog> */
              (void)tester_ignore_str2err( errs[ i ] );
       }

       ldap_charray_free( errs );

       return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void tester_init ( const char *  pname,
tester_t  ptype 
)

Definition at line 201 of file slapd-common.c.

{
       pid = getpid();
       srand( pid );
       snprintf( progname, sizeof( progname ), "%s PID=%d", pname, pid );
       progtype = ptype;
}

Here is the caller graph for this function:

void tester_ldap_error ( LDAP *  ld,
const char *  fname,
const char *  msg 
)

Definition at line 224 of file slapd-common.c.

{
       int           err;
       char          *text = NULL;
       LDAPControl   **ctrls = NULL;

       ldap_get_option( ld, LDAP_OPT_RESULT_CODE, (void *)&err );
       if ( err != LDAP_SUCCESS ) {
              ldap_get_option( ld, LDAP_OPT_DIAGNOSTIC_MESSAGE, (void *)&text );
       }

       fprintf( stderr, "%s: %s: %s (%d) %s %s\n",
              progname, fname, ldap_err2string( err ), err,
              text == NULL ? "" : text,
              msg ? msg : "" );

       if ( text ) {
              ldap_memfree( text );
              text = NULL;
       }

       ldap_get_option( ld, LDAP_OPT_MATCHED_DN, (void *)&text );
       if ( text != NULL ) {
              if ( text[ 0 ] != '\0' ) {
                     fprintf( stderr, "\tmatched: %s\n", text );
              }
              ldap_memfree( text );
              text = NULL;
       }

       ldap_get_option( ld, LDAP_OPT_SERVER_CONTROLS, (void *)&ctrls );
       if ( ctrls != NULL ) {
              int    i;

              fprintf( stderr, "\tcontrols:\n" );
              for ( i = 0; ctrls[ i ] != NULL; i++ ) {
                     fprintf( stderr, "\t\t%s\n", ctrls[ i ]->ldctl_oid );
              }
              ldap_controls_free( ctrls );
              ctrls = NULL;
       }

       if ( err == LDAP_REFERRAL ) {
              char **refs = NULL;

              ldap_get_option( ld, LDAP_OPT_REFERRAL_URLS, (void *)&refs );

              if ( refs ) {
                     int    i;

                     fprintf( stderr, "\treferral:\n" );
                     for ( i = 0; refs[ i ] != NULL; i++ ) {
                            fprintf( stderr, "\t\t%s\n", refs[ i ] );
                     }

                     ber_memvfree( (void **)refs );
              }
       }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void tester_perror ( const char *  fname,
const char *  msg 
)

Definition at line 285 of file slapd-common.c.

{
       int    save_errno = errno;
       char   buf[ BUFSIZ ];

       fprintf( stderr, "%s: %s: (%d) %s %s\n",
                     progname, fname, save_errno,
                     AC_STRERROR_R( save_errno, buf, sizeof( buf ) ),
                     msg ? msg : "" );
}

Here is the caller graph for this function:

char* tester_uri ( char *  uri,
char *  host,
int  port 
)

Definition at line 210 of file slapd-common.c.

{
       static char   uribuf[ BUFSIZ ];

       if ( uri != NULL ) {
              return uri;
       }

       snprintf( uribuf, sizeof( uribuf ), "ldap://%s:%d", host, port );

       return uribuf;
}

Here is the caller graph for this function:


Variable Documentation

Definition at line 47 of file slapd-common.c.

struct { ... } ignore_str2err[] [static]
pid_t pid

Definition at line 35 of file slapd-common.c.

char progname[BUFSIZ] [static]

Definition at line 38 of file slapd-common.c.

Definition at line 39 of file slapd-common.c.