Esempio n. 1
0
/**
 * Halt TLS threads and close socket
 */
void shutdown_tls()
{
	if (!tls.auth_server_running)
		return;

	log_area_printf(DEBUG_AREA_GW, DEBUG_LEVEL_CRITICAL,
			"tls send failure when sending request");

	close_tls_session();

	/* put auth_server_running to 0 because this is this thread which has
	 * just killed auth_server */
	tls.auth_server_running = 0;
}
Esempio n. 2
0
/**
 * Thread waiting to authentication server (NuAuth) answer.
 * Call auth_packet_to_decision() on new packet.
 */
int authsrv(void *data)
{
	int ret;
	int read_size;
	char cdgram[512];
	char *dgram = cdgram;
	int offset = 0;
	int i = 0;

	log_area_printf(DEBUG_AREA_GW, DEBUG_LEVEL_VERBOSE_DEBUG,
			"[+] In auth server thread");

	if (tls.session) {
		read_size = sizeof(nuv5_nuauth_decision_response_t);
		/* read size of data */
		do {
			if (i>0) {
				log_area_printf(DEBUG_AREA_GW, DEBUG_LEVEL_VERBOSE_DEBUG,
						"Reading header (pass %d)", i);
			}
			ret = ufwissl_read(tls.session, dgram + offset, read_size - offset);
			if (ret < 0) {
				log_area_printf(DEBUG_AREA_GW, DEBUG_LEVEL_WARNING,
						"Unable to read header");
				if (!strcmp("Resource temporarily unavailable",
							ufwissl_get_error(tls.session))) {
					log_area_printf(DEBUG_AREA_GW, DEBUG_LEVEL_WARNING,
							"Resource temporarily unavailable");
					i++;
					continue;
				} else {
					close_tls_session();
					return NU_EXIT_ERROR;
				}
			} else if (ret == 0) {
				log_area_printf(DEBUG_AREA_GW, DEBUG_LEVEL_WARNING,
						"Disconnect during read");
				close_tls_session();
				return NU_EXIT_ERROR;
			} else if (ret != (read_size - offset)) {
				log_area_printf(DEBUG_AREA_GW, DEBUG_LEVEL_WARNING,
						"Under read: %d for %d",
						ret,
						read_size);
				offset += ret;
				i++;
				continue;
			} else {
				offset += ret;
				break;
			}
		} while ((offset != read_size) && i < 3);

		if (i == 3) {
			log_area_printf(DEBUG_AREA_GW, DEBUG_LEVEL_WARNING,
					"Unable to ufwissl_read %d from session", read_size);
			return NU_EXIT_ERROR;
		}

		read_size = ntohs(((nuv5_nuauth_decision_response_t *) dgram)->payload_len);
		if (read_size != 0) {
			log_area_printf(DEBUG_AREA_GW, DEBUG_LEVEL_VERBOSE_DEBUG,
					"going to ufwissl_read: %d", read_size);
			if (read_size + offset > (int) sizeof(cdgram)) {
				log_area_printf(DEBUG_AREA_GW, DEBUG_LEVEL_VERBOSE_DEBUG,
						"too big to read ufwissl_read: %d", read_size);
				close_tls_session();
				return NU_EXIT_ERROR;
			}
			ret = ufwissl_read(tls.session, dgram + offset, read_size);
			if (ret != read_size) {
				log_area_printf(DEBUG_AREA_GW, DEBUG_LEVEL_WARNING,
						"Unable to read data");
				return NU_EXIT_ERROR;
			}
		}
	} else
		ret = 0;
	if (ret == UFWISSL_SOCK_TIMEOUT) {
		return NU_EXIT_ERROR;
	}
	if (ret <= 0) {
		log_area_printf(DEBUG_AREA_GW, DEBUG_LEVEL_VERBOSE_DEBUG,
				"Error during ufwissl_read: %s", ufwissl_get_error(tls.session));
		close_tls_session();
		return NU_EXIT_ERROR;
	} else {
		ret = read_size + offset;
		do {
			read_size = auth_packet_to_decision(dgram, ret);
			ret -= read_size;
			dgram = dgram + read_size;
		} while (ret > 0 && (read_size != -1));
	}

	dgram = cdgram;
	return NU_EXIT_OK;
}