- connection_t *c;
- sockaddr_t sa;
- int fd, len = sizeof(sa);
-cp
- if((fd = accept(sock, &sa.sa, &len)) < 0)
- {
- syslog(LOG_ERR, _("Accepting a new connection failed: %s"), strerror(errno));
- return -1;
- }
-
- sockaddrunmap(&sa);
-
- c = new_connection();
- c->outcipher = myself->connection->outcipher;
- c->outdigest = myself->connection->outdigest;
- c->outmaclength = myself->connection->outmaclength;
- c->outcompression = myself->connection->outcompression;
-
- c->address = sa;
- c->hostname = sockaddr2hostname(&sa);
- c->socket = fd;
- c->last_ping_time = now;
-
- if(debug_lvl >= DEBUG_CONNECTIONS)
- syslog(LOG_NOTICE, _("Connection from %s"), c->hostname);
-
- connection_add(c);
-
- c->allow_request = ID;
- send_id(c);
-cp
- return 0;
+ connection_t *c;
+ sockaddr_t sa;
+ int fd, len = sizeof(sa);
+ int result;
+
+ cp();
+
+ fd = accept(sock, &sa.sa, &len);
+
+ if(fd < 0) {
+ logger(LOG_ERR, _("Accepting a new connection failed: %s"),
+ strerror(errno));
+ return false;
+ }
+
+#ifdef O_NONBLOCK
+ {
+ int flags = fcntl(fd, F_GETFL);
+
+ if(fcntl(fd, F_SETFL, flags | O_NONBLOCK) < 0) {
+ closesocket(fd);
+ logger(LOG_ERR, _("System call `%s' failed: %s"), "fcntl",
+ strerror(errno));
+ return -1;
+ }
+ }
+#endif
+
+ sockaddrunmap(&sa);
+
+ c = new_connection();
+
+ c->address = sa;
+ c->hostname = sockaddr2hostname(&sa);
+ c->socket = fd;
+ c->last_ping_time = now;
+
+ ifdebug(CONNECTIONS) logger(LOG_NOTICE, _("Connection from %s"), c->hostname);
+
+ connection_add(c);
+
+ c->allow_request = ID;
+ gnutls_init(&c->session, GNUTLS_CLIENT);
+ gnutls_set_default_priority(c->session);
+ gnutls_credentials_set(c->session, GNUTLS_CRD_CERTIFICATE, myself->connection->credentials);
+ gnutls_certificate_server_set_request(c->session, GNUTLS_CERT_REQUEST);
+// gnutls_certificate_client_set_select_function(c->session, certselfunc);
+// gnutls_certificate_server_set_select_function(c->session, scertselfunc);
+ gnutls_transport_set_ptr(c->session, c->socket);
+ gnutls_handshake(c->session);
+
+ return true;