Exemple #1
0
static int dsaschema_parse_at(const char *fname, int lineno, char *line, char **argv)
{
	LDAPAttributeType *at;
	int code;
	const char *err;

	at = ldap_str2attributetype(line, &code, &err, LDAP_SCHEMA_ALLOW_ALL);
	if (!at) {
		fprintf(stderr, "%s: line %d: %s before %s\n",
			fname, lineno, ldap_scherr2str(code), err);
		return 1;
	}

	if (at->at_oid == NULL) {
		fprintf(stderr, "%s: line %d: attributeType has no OID\n",
			fname, lineno);
		return 1;
	}

	code = at_add(at, 0, NULL, NULL, &err);
	if (code) {
		fprintf(stderr, "%s: line %d: %s: \"%s\"\n",
			fname, lineno, ldap_scherr2str(code), err);
		return 1;
	}

	ldap_memfree(at);

	return 0;
}
Exemple #2
0
/* the main thread */
void infadd_start(void *v)
{
    AddThread *at = (AddThread *)v;
    PRIntervalTime timer;
    PRUint32 span, i;
    int notBound = 1;
    int ret;

    /* make the blob if necessary */
    if (blobsize > 0) {
        at->blob = (char *)malloc(blobsize);
        if (! at->blob) {
            fprintf(stderr, "T%d: can't allocate blob!\n", at->id);
            return;
        }
        for (i = 0; i < blobsize; i++)
            at->blob[i] = (char)(rand() & 0xff);
    }

    at->alive = 1;
    while (1) {
        timer = PR_IntervalNow();
        
        /* bind if we need to */
        if (notBound) {
            at_bind(at);
            if (noDelay)
                at_enableTCPnodelay(at);
            notBound = 0;
        }

        ret = at_add(at);
        if (LDAP_SUCCESS == ret) {
            span = PR_IntervalToMilliseconds(PR_IntervalNow()-timer);
            /* update data */
            PR_Lock(at->lock);
            at->addCount++;
            at->addTotal++;
            if (at->mintime > span)
                at->mintime = span;
            if (at->maxtime < span)
                at->maxtime = span;
            at->alive = 1;
            at->retry = 0;
            PR_Unlock(at->lock);
        } else if (LDAP_CONNECT_ERROR == ret && at->retry < 10) {
            PR_Lock(at->lock);
            at->retry++;
            PR_Unlock(at->lock);
        } else {
            at_bail(at);
            return;
        }
        
    }
}
int
parse_at(
    const char	*fname,
    int		lineno,
    char	*line,
    char	**argv
)
{
	LDAPAttributeType *at;
	int		code;
	const char	*err;

	at = ldap_str2attributetype( line, &code, &err, LDAP_SCHEMA_ALLOW_ALL );
	if ( !at ) {
		fprintf( stderr, "%s: line %d: %s before %s\n",
			 fname, lineno, ldap_scherr2str(code), err );
		at_usage();
		return 1;
	}

	if ( at->at_oid == NULL ) {
		fprintf( stderr,
			"%s: line %d: attributeType has no OID\n",
			fname, lineno );
		at_usage();
		return 1;
	}

	/* operational attributes should be defined internally */
	if ( at->at_usage ) {
		fprintf( stderr, "%s: line %d: attribute type \"%s\" is operational\n",
			 fname, lineno, at->at_oid );
		return 1;
	}

	code = at_add(at,&err);
	if ( code ) {
		fprintf( stderr, "%s: line %d: %s: \"%s\"\n",
			 fname, lineno, scherr2str(code), err);
		return 1;
	}
	ldap_memfree(at);
	return 0;
}
Exemple #4
0
/* backport register_at() from HEAD, to allow building with OL <= 2.3 */
static int
register_at( char *def, AttributeDescription **rad, int dupok )
{
	LDAPAttributeType *at;
	int code, freeit = 0;
	const char *err;
	AttributeDescription *ad = NULL;

	at = ldap_str2attributetype( def, &code, &err, LDAP_SCHEMA_ALLOW_ALL );
	if ( !at ) {
		Debug( LDAP_DEBUG_ANY,
			"register_at: AttributeType \"%s\": %s, %s\n",
				def, ldap_scherr2str(code), err );
		return code;
	}

	code = at_add( at, 0, NULL, &err );
	if ( code ) {
		if ( code == SLAP_SCHERR_ATTR_DUP && dupok ) {
			freeit = 1;

		} else {
			ldap_attributetype_free( at );
			Debug( LDAP_DEBUG_ANY,
				"register_at: AttributeType \"%s\": %s, %s\n",
				def, scherr2str(code), err );
			return code;
		}
	}
	code = slap_str2ad( at->at_names[0], &ad, &err );
	if ( freeit || code ) {
		ldap_attributetype_free( at );
	} else {
		ldap_memfree( at );
	}
	if ( code ) {
		Debug( LDAP_DEBUG_ANY, "register_at: AttributeType \"%s\": %s\n",
			def, err, 0 );
	}
	if ( rad ) *rad = ad;
	return code;
}
Exemple #5
0
int
parse_at(
	struct config_args_s *c,
	AttributeType	**sat,
	AttributeType	*prev )
{
	LDAPAttributeType *at;
	int		code;
	const char	*err;
	char *line = strchr( c->line, '(' );

	at = ldap_str2attributetype( line, &code, &err, LDAP_SCHEMA_ALLOW_ALL );
	if ( !at ) {
		snprintf( c->cr_msg, sizeof( c->cr_msg ), "%s: %s before %s",
			c->argv[0], ldap_scherr2str(code), err );
		Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
			"%s %s\n", c->log, c->cr_msg );
		at_usage();
		return 1;
	}

	if ( at->at_oid == NULL ) {
		snprintf( c->cr_msg, sizeof( c->cr_msg ), "%s: OID is missing",
			c->argv[0] );
		Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
			"%s %s\n", c->log, c->cr_msg );
		at_usage();
		code = 1;
		goto done;
	}

	/* operational attributes should be defined internally */
	if ( at->at_usage ) {
		snprintf( c->cr_msg, sizeof( c->cr_msg ), "%s: \"%s\" is operational",
			c->argv[0], at->at_oid );
		Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
			"%s %s\n", c->log, c->cr_msg );
		code = 1;
		goto done;
	}

	code = at_add( at, 1, sat, prev, &err);
	if ( code ) {
		snprintf( c->cr_msg, sizeof( c->cr_msg ), "%s: %s: \"%s\"",
			c->argv[0], scherr2str(code), err);
		Debug( LDAP_DEBUG_CONFIG|LDAP_DEBUG_NONE,
			"%s %s\n", c->log, c->cr_msg );
		code = 1;
		goto done;
	}

done:;
	if ( code ) {
		ldap_attributetype_free( at );

	} else {
		ldap_memfree( at );
	}

	return code;
}