예제 #1
0
파일: auth.c 프로젝트: Inzaghi2012/3proxy
int ipauth(struct clientparam * param){
	int res;
	unsigned char *username;
	username = param->username;
	param->username = NULL;
	res = checkACL(param);
	param->username = username;
	return res;
}
예제 #2
0
void
Connection::start( QTcpSocket* sock )
{
    Q_ASSERT( m_sock.isNull() );
    Q_ASSERT( sock );
    Q_ASSERT( sock->isValid() );

    m_sock = sock;

    if( m_name.isEmpty() )
    {
        m_name = QString( "peer[%1]" ).arg( m_sock->peerAddress().toString() );
    }

    QTimer::singleShot( 0, this, SLOT( checkACL() ) );
}
예제 #3
0
/*--------------------------------------------------------------------------------------
 * Purpose: Accept the new cli and spawn a new thread for the client 
 *          if more clients are allowed and it passes the ACL check.
 * Input:  the socket used for listening
 * Output: none
 * Kevin Burnett @ November 18, 2008
 * -------------------------------------------------------------------------------------*/
void startLogin( int listenSocket ) {
	// structure to store the client addrress from accept
	struct sockaddr_storage loginaddr;
	socklen_t addrlen = sizeof (loginaddr);
	
	// accept connection
	int loginSocket = accept( listenSocket, (struct sockaddr *) &loginaddr, &addrlen);
	if( loginSocket == -1 ) {
		log_err( "Failed to accept new client" );
		return;
	}

	// convert address into address string and port
	char *addr;
	int port;
	if( getAddressFromSockAddr((struct sockaddr *)&loginaddr, &addr, &port) )
	{
		log_warning( "Unable to get address and port for new connection." );
		return;
	}
#ifdef DEBUG 	
	else
		debug(__FUNCTION__, "connection request from: %s, port: %d ", addr, port);
#endif

	// too many clients, close this one
	if ( LoginSettings.activeConnections == LoginSettings.maxConnections )
	{
		log_warning( "At maximum number of connected clients: connection from %s port %d rejected.", addr, port );
		close(loginSocket);
		free(addr);
		return;
	}

	//check the new client against ACL
	if ( checkACL((struct sockaddr *) &loginaddr, CLI_ACL) == FALSE )
	{
		log_msg("cli connection from %s port %d rejected by access control list",addr, port);
		close(loginSocket);
		free(addr);
		return;
	}
	
	// lock the client list
	if ( pthread_mutex_lock( &(LoginSettings.loginLock) ) )
		log_fatal( "lock login list failed" );

		// create the argument structure for the new client thread
		CliNode * cn = malloc(sizeof (CliNode));
		if(cn==NULL) {
			log_warning("Failed to create cli structure.  Closing connection from %s port %d.", addr, port);
			close(loginSocket);
			free(addr);
			return;
		}
		memset(cn, 0, sizeof(CliNode));
		cn->socket = loginSocket;
		cn->port = port;
		cn->localASNumber = 0;
		cn->id = LoginSettings.nextConnectionId;
		cn->lastAction = time(NULL);
		memcpy(&cn->addr, addr, strlen(addr));

		//increment the number of active clients
		LoginSettings.activeConnections++;
		LoginSettings.nextConnectionId++;

		// update list of cli connections
		cn->next = LoginSettings.firstNode;
		LoginSettings.firstNode = cn;

		// spawn a new thread for this client, detach thread as early as possible to avoid memory leakage
		pthread_t cliThreadID;
		pthread_attr_t cliThreadAttr;
		int error;
		error = pthread_attr_init(&cliThreadAttr);
		error = pthread_attr_setdetachstate(&cliThreadAttr,PTHREAD_CREATE_DETACHED);
		error = pthread_create(&cliThreadID, &cliThreadAttr, &cliThread, cn);
		if (error > 0) {
			log_warning("Failed to create login thread: %s", strerror(error));
		}

		// thread reference
		cn->cliThread = cliThreadID;

	// unlock the client list
	if ( pthread_mutex_unlock( &(LoginSettings.loginLock) ) )
		log_fatal( "unlock login list failed");

#ifdef DEBUG
	debug(__FUNCTION__, "login accepted from: %s, port: %d ", addr, port);
#endif
	free(addr);
}