bool start_auth( DESCRIPTOR_DATA *d ) { struct sockaddr_in sock; int tlen; struct auth_data *auth; int desc; desc = socket(AF_INET, SOCK_STREAM, 0); if ( desc < 0 && errno == EAGAIN ) { bug( "Can't allocate fd for authorization check on %s.", (int)d->host ); free_string(d->user); d->user = str_dup("(no auth_fd)"); return FALSE; } if ( fcntl(desc, F_SETFL, O_NDELAY) == -1 ) { perror("Nonblock"); close(desc); free_string(d->user); d->user = str_dup("(nonblock)"); return FALSE; } tlen = sizeof(sock); getpeername(d->descriptor, (struct sockaddr *)&sock, &tlen); sock.sin_port = htons(113); sock.sin_family = AF_INET; if ( connect(desc, (struct sockaddr *)&sock, sizeof(sock)) == -1 && errno != EINPROGRESS ) { bug( "Identd denied for %s.", (int)d->host ); close(desc); free_string(d->user); d->user = str_dup("(no verify)"); return FALSE; } if ( errno == ECONNREFUSED ) { close(desc); free_string(d->user); d->user = str_dup("(no identd)"); return FALSE; } for ( auth = first_auth; auth; auth = auth->next ) if ( auth->d == d ) break; if ( !auth ) { GET_FREE(auth, auth_free); auth->d = d; auth->atimes = 70; LINK(auth, first_auth, last_auth, next, prev); } auth->auth_fd = desc; auth->abuf[0] = '\0'; auth->auth_state = AUTH_UNSENT; auth->auth_inc = 0; return TRUE; }
/* Test that the capacity and used size reported by the pool is correct. */ static int capacity_test(void) { pj_pool_t *pool = pj_pool_create(mem, NULL, SIZE, 0, &null_callback); pj_size_t freesize; PJ_LOG(3,("test", "...capacity_test()")); if (!pool) return -200; freesize = GET_FREE(pool); if (pj_pool_alloc(pool, freesize) == NULL) { PJ_LOG(3,("test", "...error: wrong freesize %u reported", freesize)); pj_pool_release(pool); return -210; } pj_pool_release(pool); return 0; }
/* Test function to drain the pool's space. */ static int drain_test(pj_size_t size, pj_size_t increment) { pj_pool_t *pool = pj_pool_create(mem, NULL, size, increment, &null_callback); pj_size_t freesize; void *p; int status = 0; PJ_LOG(3,("test", "...drain_test(%d,%d)", size, increment)); if (!pool) return -10; /* Get free size */ freesize = GET_FREE(pool); if (freesize < 1) { status=-15; goto on_error; } /* Drain the pool until there's nothing left. */ while (freesize > 0) { int size; if (freesize > 255) size = ((pj_rand() & 0x000000FF) + PJ_POOL_ALIGNMENT) & ~(PJ_POOL_ALIGNMENT - 1); else size = freesize; p = pj_pool_alloc(pool, size); if (!p) { status=-20; goto on_error; } freesize -= size; } /* Check that capacity is zero. */ if (GET_FREE(pool) != 0) { PJ_LOG(3,("test", "....error: returned free=%u (expecting 0)", GET_FREE(pool))); status=-30; goto on_error; } /* Try to allocate once more */ p = pj_pool_alloc(pool, 257); if (!p) { status=-40; goto on_error; } /* Check that capacity is NOT zero. */ if (GET_FREE(pool) == 0) { status=-50; goto on_error; } on_error: pj_pool_release(pool); return status; }