예제 #1
0
DLLFUNC CMD_FUNC(m_starttls)
{
	if (!MyConnect(sptr) || !IsUnknown(sptr))
		return 0;
#ifndef USE_SSL
	/* sendnotice(sptr, "This server does not support SSL"); */
	/* or numeric 691? */
	/* actually... it's probably best to just act like we don't know this command...? */
	sendto_one(sptr, err_str(ERR_NOTREGISTERED), me.name, "STARTTLS");
	return 0;
#else
	if (iConf.ssl_options & SSLFLAG_NOSTARTTLS)
	{
		sendto_one(sptr, err_str(ERR_NOTREGISTERED), me.name, "STARTTLS");
		return 0;
	}
	if (IsSecure(sptr))
	{
		sendto_one(sptr, err_str(ERR_STARTTLS), me.name, !BadPtr(sptr->name) ? sptr->name : "*", "STARTTLS failed. Already using TLS.");
		return 0;
	}
	dbuf_delete(&sptr->recvQ, 1000000); /* Clear up any remaining plaintext commands */
	sendto_one(sptr, rpl_str(RPL_STARTTLS), me.name, !BadPtr(sptr->name) ? sptr->name : "*");
	send_queued(sptr);

	SetSSLStartTLSHandshake(sptr);
	Debug((DEBUG_DEBUG, "Starting SSL handshake (due to STARTTLS) for %s", sptr->sockhost));
	if ((sptr->ssl = SSL_new(ctx_server)) == NULL)
		goto fail;
	sptr->flags |= FLAGS_SSL;
	SSL_set_fd(sptr->ssl, sptr->fd);
	SSL_set_nonblocking(sptr->ssl);
	if (!ircd_SSL_accept(sptr, sptr->fd)) {
		Debug((DEBUG_DEBUG, "Failed SSL accept handshake in instance 1: %s", sptr->sockhost));
		SSL_set_shutdown(sptr->ssl, SSL_RECEIVED_SHUTDOWN);
		SSL_smart_shutdown(sptr->ssl);
		SSL_free(sptr->ssl);
		goto fail;
	}

	/* HANDSHAKE IN PROGRESS */
	return 0;
fail:
	/* Failure */
	sendto_one(sptr, err_str(ERR_STARTTLS), me.name, !BadPtr(sptr->name) ? sptr->name : "*", "STARTTLS failed");
	sptr->ssl = NULL;
	sptr->flags &= ~FLAGS_SSL;
	SetUnknown(sptr);
	return 0;
#endif
}
예제 #2
0
static int FuncCompileIfElse( FUNC *func )
    {
    FUNC *table[100], *loop, *temp ;
    int i, j, count, unknown ;
    ifelsedir direction ;

    for( loop = func ; loop ; loop = loop->next )
	loop->unknown = 0 ;

/*
 *  First find an if/else tree
 *
 */

    count = 0 ;
    direction = DIR_UNKNOWN ;
    for( loop = func ; loop ; loop = loop->next )
	{
	if( !loop->ignore && ExprLabelEqual(loop->label, iif) )
	    {
	    if( count && (direction == DIR_FORWARD) )
		break ;
	    if( !count )
		direction = DIR_FORWARD ;
	    table[count] = loop ;
	    loop = SetSkip( loop ) ;
	    count++ ;
	    if( direction == DIR_REVERSE )
		break ;					/* final $if */
	    }
	else
	if( !loop->ignore &&
		( ExprLabelEqual( loop->label, ielse ) || ExprLabelEqual( loop->label, ielseif ) ) )
	    {
	    if( !count )
		direction = DIR_REVERSE ;
	    table[count] = loop ;
	    loop = SetSkip( loop ) ;
	    count++ ;
	    if( (direction == DIR_FORWARD) && ExprLabelEqual(loop->label, ielse) )
		break ;					/* final $else */
	    }
	else
	if( count && !ExprLabelEqual(loop->label, imacro) )
	    break ;
	}
    if( !count )
	return 0 ;

    if( count >= 100 )
	IOerror( FuncBomb, "FuncCompileIfElse", "internal table exceeded" ) ;

    if( direction == DIR_UNKNOWN )
	IOerror( FuncBomb, "FuncCompileIfElse", "cannot determine direction" ) ;

/*
 *  Swap ends if tree is reversed
 *
 */

    if( direction == DIR_REVERSE )
	{
	for( i = 0 ; i < count / 2 ; i++ )
	    {
	    temp = table[i] ;
	    table[i] = table[ count - i - 1 ] ;
	    table[ count - i - 1 ] = temp ;
	    }
    if( !ExprLabelEqual( table[0]->label, iif ) )
	IOerror( FuncBomb, "FuncCompileIfElse", "if/else tree has no if" ) ;
    }

/*
 *  Check some syntax
 *
 */

    if( FuncArgCount( table[0] ) != 1 )
	{
	IOerror( FuncBomb, "FuncCompileIfElse",
	    "wrong number of arguments to $if" ) ;
	}
    for( i = 1 ; i < count - 1 ; i++ )
	{
	if( FuncArgCount( table[i] ) != 1 )
	    {
	    IOerror( FuncBomb, "FuncCompileIfElse",
		"wrong number of arguments to $elseif" ) ;
	    }
	if( ExprLabelEqual( table[i]->label, ielse ) )
	    {
	    IOerror( FuncBomb, "FuncCompileIfElse",
		"$else embedded in $if/$else tree" ) ;
	    }
	}
    if( ExprLabelEqual(table[count - 1]->label, ielse) && (FuncArgCount( table[count - 1] ) != 0) )
	IOerror( FuncBomb, "FuncCompileIfElse",
	    "wrong number of arguments to $else" ) ;

/*
 *  Find the true branch
 *
 */

    unknown = 0 ;
    for( i = 0 ; i < count ; i++ )
	{
	if( ExprNonDepend( FuncArg( table[i], 0 ), VAR_SET, 0 ) )
	    {
	    unknown = 1 ;
	    break ;
	    }
	if( ExprLabelEqual( table[i]->label, ielse ) )			/* leftover */
	    break ;
	if( ExprValue( FuncArg( table[i], 0 ) ) )	/* true */
	    break ;
	}

/*
 *  Set the final state
 *
 */

    for( j = 0 ; j < count ; j++ )
	{
	if( unknown )
	    loop = SetUnknown( table[j] ) ;
	else
	    {
	    if( i == j )
		loop = SetTrue( table[j] ) ;
	    else
		loop = SetFalse( table[j] ) ;
	    }
	if( (direction == DIR_REVERSE) && (j == 0) )
	    func = loop ;
	if( (direction == DIR_FORWARD) && (j == count - 1) )
	    func = loop ;
	}

/*
 *  func is now the last FUNC of the tree
 *
 */

    if( func && func->next )
	return !unknown + FuncCompileIfElse( func->next ) ;
    else
	return !unknown ;
    }