Exemple #1
0
void
endhostent(void)
{
	struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res);

	_resp->options &= ~(RES_STAYOPEN | RES_USEVC);
	res_close();
}
Exemple #2
0
void
endhostent(void)
{
#ifndef _REENTRANT
	_res.options &= ~(RES_STAYOPEN | RES_USEVC);
	res_close();
#endif
	_endhtent();
}
Exemple #3
0
void CloseAllFiles( void ) {
/***************************/
    unsigned    i;

    for( i = 0; i < MAX_OPEN_FILES; i++ ) {
        if( openFileList[i] != WRES_NIL_HANDLE ) {
            res_close( openFileList[i] );
        }
    }
}
Exemple #4
0
int
utGetDomainInfo(char **szDefDomain, char **szDefServer)
{
  if (res_init() != 0)
    return 1;
  *szDefDomain = calloc(257, sizeof(char));
  memcpy(*szDefDomain, _res.defdname, 256);
  if (strnlen(*szDefDomain, 256) == 0)
    *szDefDomain[0] = '-';
  *szDefServer = calloc(IFNAMSIZ, sizeof(char));
  memcpy(*szDefServer, inet_ntoa(_res.nsaddr_list[0].sin_addr), IFNAMSIZ-1);
  res_close();
  return 0;
}
Exemple #5
0
// Main
int main ( int argc, char **argv )
{
    // Déclarations variables
    int return_value ;              // Entier recevant les codes de retours des fonctions

    // Initialisation de rand()
    srand ( time ( NULL ) ) ;

    // Initialisation librairie OpenSSL
    OpenSSL_add_all_algorithms () ;
    OPENSSL_config ( NULL ) ;

    // Connexion à la BDD
    mysql_bdd = bdd_start_connection () ;   // On se connecte à la BDD

    // On vérifie la connexion
    if ( mysql_bdd != NULL )
    {
        // On initialise la clé AES
        if ( AES_generate_key() != ERRNO )
        {
            // On initialise la double clé RSA
            if ( generate_RSA_keys() != ERRNO )
            {
                // On vide la BDD par protection
                if ( ( return_value = bdd_do_request ( mysql_bdd, DELETE_ALL, NULL, NULL, NULL ) ) == TRUE )
                {
                    // On initialise le réseau
                    if ( ( return_value = res_activation() ) != ERRNO )
                    {
                        // Un client s'est bel et bien connecté, on lance le thread qui recevra les requêtes
                        if ( ( return_value = pthread_create ( &thread_receive, NULL, fct_thread_res_receive, NULL ) ) == 0 )
                        {
                            // On met en place le egstionnaire de signal sur SIGINT (Ctrl + C)
                            signal ( SIGINT, gestionnaire_signal ) ;

                            // On se place en attente
                            while ( !fermeture ) ;

                            // On kill tous les thread traitement
                            int i ;
                            for ( i = 0; i < NB_MAX_REQ; i++ )
                            {
                                if ( thread_traitement[i] != ZERO )
                                    pthread_cancel ( thread_traitement[i] ) ;
                            }

                            // On kill le thread
                            pthread_cancel ( thread_receive ) ;
                        }
                    }

                    // Finalisation
                    return_value = bdd_do_request ( mysql_bdd, DELETE_ALL, NULL, NULL, NULL ) ;
                    bdd_close_connection ( mysql_bdd ) ;    // On se déconnecte de la BDD
                    res_close() ;                           // On se déconnecte du réseau
                    RSA_free ( bdd_key ) ;                  // On free nos clés RSA & AES
                    free ( exg_key ) ;
                    EVP_cleanup () ;                        // Finalisation OpenSSL
                    printf ( "\nFermeture done \n" ) ;
                    return EXIT_SUCCESS ;
                }
                else
                {
                    EVP_cleanup () ;    // Finalisation OpenSSL
                    return EXIT_FAILURE ;
                }
            }
            else
            {
                EVP_cleanup () ;    // Finalisation OpenSSL
                return EXIT_FAILURE ;
            }
        }
        else
        {
            EVP_cleanup () ;    // Finalisation OpenSSL
            return EXIT_FAILURE ;
        }
    }
    else
    {
        EVP_cleanup () ;    // Finalisation OpenSSL
        return EXIT_FAILURE ;
    }
}
Exemple #6
0
DWORD
LWNetDnsQueryWithBuffer(
    IN PCSTR pszQuestion,
    IN BOOLEAN bReInit,
    IN BOOLEAN bUseTcp,
    OUT PVOID pBuffer,
    IN DWORD dwBufferSize,
    OUT PDWORD pdwResponseSize
    )
{
    DWORD dwError = 0;
    PDNS_RESPONSE_HEADER pHeader = (PDNS_RESPONSE_HEADER)pBuffer;
    int responseSize =  0;
    BOOLEAN bInLock = FALSE;
#if HAVE_DECL_RES_NINIT
    union
    {
        struct __res_state res;
#ifdef __LWI_AIX__
        // struct __res_state was enlarged from 720 in AIX 5.2 to 824 in AIX
        // 5.3. This means calling res_ninit on AIX 5.3 on a structure compiled
        // on AIX 5.2 will result in a buffer overflow. Furthermore, even on
        // AIX 5.3, res_ninit seems to expect 1596 bytes in the structure (1491
        // on AIX 5.2). As a workaround, this padding will ensure enough space
        // is allocated on the stack.
        char buffer[2048];
#endif
    } resLocal = { {0} };
    res_state res = &resLocal.res;
#else
    struct __res_state *res = &_res;
#endif

    LWNET_LOCK_RESOLVER_API(bInLock);

#if HAVE_DECL_RES_NINIT
    if (res_ninit(res) != 0)
#else
    if (res_init() != 0)
#endif
    {
        dwError = ERROR_NOT_FOUND;
        BAIL_ON_LWNET_ERROR(dwError);
    }
    
    if (dwBufferSize < CT_MIN(sizeof(DNS_RESPONSE_HEADER), MAX_DNS_UDP_BUFFER))
    {
        dwError = ERROR_INVALID_PARAMETER;
        BAIL_ON_LWNET_ERROR(dwError);
    }

    // TODO: Add lock on calling resolver due to global options, which may or
    // may not be safe depending on the system.
    if (bUseTcp)
    {
        res->options |= RES_USEVC;
    }
    else
    {
        res->options &= ~(RES_USEVC);
    }

    /* Assertion: pResolverContext != NULL && pResolverContext->bLocked == TRUE */
#if HAVE_DECL_RES_NINIT
    responseSize = res_nquery(res, pszQuestion, ns_c_in, ns_t_srv, (PBYTE) pBuffer, dwBufferSize);
#else
    responseSize = res_query(pszQuestion, ns_c_in, ns_t_srv, (PBYTE) pBuffer, dwBufferSize);
#endif
    if (responseSize < 0)
    {
        LWNET_LOG_VERBOSE("DNS lookup for '%s' failed with errno %d, h_errno = %d", pszQuestion, errno, h_errno);
        dwError = DNS_ERROR_BAD_PACKET;
        BAIL_ON_LWNET_ERROR(dwError);
    }
    if (responseSize < CT_FIELD_OFFSET(DNS_RESPONSE_HEADER, data))
    {
        dwError = DNS_ERROR_BAD_PACKET;
        BAIL_ON_LWNET_ERROR(dwError);
    }
    if (responseSize > dwBufferSize)
    {
        dwError = DNS_ERROR_BAD_PACKET;
        BAIL_ON_LWNET_ERROR(dwError);
    }

    LWNetDnsFixHeaderForEndianness(pHeader);

    if (!LWNetDnsIsValidResponse(pHeader))
    {
        dwError = DNS_ERROR_BAD_PACKET;
        BAIL_ON_LWNET_ERROR(dwError);
    }

error:

#if HAVE_DECL_RES_NINIT
    res_nclose(res);
#else
    /* Indicate that we are done with the resolver, except on HPUX which
       does not implement the res_close function. */
#ifndef __LWI_HP_UX__
    res_close();
#endif
#endif

    LWNET_UNLOCK_RESOLVER_API(bInLock);

    if (dwError)
    {
        responseSize = 0;
    }
    *pdwResponseSize = responseSize;
    return dwError;
}