upstream removed this so we don't need to
[debian/amanda] / common-src / bsd-security.c
index 46bdca9ad7ded214a3ed97ebccb6bfa9bab9e15c..ad2929219e93031d2b060aa15cae0391edfadacb 100644 (file)
@@ -39,7 +39,6 @@
 #include "security-util.h"
 #include "sockaddr-util.h"
 #include "stream.h"
-#include "version.h"
 
 #ifndef SO_RCVBUF
 #undef DUMPER_SOCKET_BUFFERING
@@ -74,6 +73,7 @@ const security_driver_t bsd_security_driver = {
     "BSD",
     bsd_connect,
     bsd_accept,
+    sec_get_authenticated_peer_name_hostname,
     bsd_close,
     udpbsd_sendpkt,
     udp_recvpkt,
@@ -124,7 +124,6 @@ bsd_connect(
     void *             datap)
 {
     struct sec_handle *bh;
-    struct servent *se;
     in_port_t port = 0;
     struct timeval sequence_time;
     int sequence;
@@ -133,13 +132,14 @@ bsd_connect(
     struct addrinfo *res, *res_addr;
     char *canonname;
     int result_bind;
+    char *service;
 
     assert(hostname != NULL);
 
     (void)conf_fn;     /* Quiet unused parameter warning */
     (void)datap;        /* Quiet unused parameter warning */
 
-    bh = alloc(SIZEOF(*bh));
+    bh = g_new0(struct sec_handle, 1);
     bh->proto_handle=NULL;
     security_handleinit(&bh->sech, &bsd_security_driver);
 
@@ -270,10 +270,22 @@ bsd_connect(
        bh->udp = &netfd4;
 
     auth_debug(1, _("Resolved hostname=%s\n"), canonname);
-    if ((se = getservbyname(AMANDA_SERVICE_NAME, "udp")) == NULL)
-       port = AMANDA_SERVICE_DEFAULT;
-    else
-       port = (in_port_t)ntohs(se->s_port);
+
+    if (conf_fn) {
+        service = conf_fn("client_port", datap);
+        if (!service || strlen(service) <= 1)
+            service = "amanda";
+    } else {
+        service = "amanda";
+    }
+    port = find_port_for_service(service, "udp");
+    if (port == 0) {
+        security_seterror(&bh->sech, _("%s/udp unknown protocol"), service);
+       (*fn)(arg, &bh->sech, S_ERROR);
+        amfree(canonname);
+       return;
+    }
+
     amanda_gettimeofday(&sequence_time);
     sequence = (int)sequence_time.tv_sec ^ (int)sequence_time.tv_usec;
     handle=alloc(15);
@@ -387,7 +399,7 @@ bsd_stream_server(
 
     assert(bh != NULL);
 
-    bs = alloc(SIZEOF(*bs));
+    bs = g_new0(struct sec_stream, 1);
     security_streaminit(&bs->secstr, &bsd_security_driver);
     bs->socket = stream_server(SU_GET_FAMILY(&bh->udp->peer), &bs->port,
                               (size_t)STREAM_BUFSIZE, (size_t)STREAM_BUFSIZE,
@@ -442,7 +454,7 @@ bsd_stream_client(
 
     assert(bh != NULL);
 
-    bs = alloc(SIZEOF(*bs));
+    bs = g_new0(struct sec_stream, 1);
     security_streaminit(&bs->secstr, &bsd_security_driver);
     bs->fd = stream_client(bh->hostname, (in_port_t)id,
        STREAM_BUFSIZE, STREAM_BUFSIZE, &bs->port, 0);
@@ -529,6 +541,10 @@ bsd_stream_read(
     bs->arg = arg;
 }
 
+/* buffer for bsd_stream_read_sync function */
+static ssize_t  sync_pktlen;
+static void    *sync_pkt;
+
 /*
  * Read a chunk of data to a stream.  Blocks until completion.
  */
@@ -547,11 +563,13 @@ bsd_stream_read_sync(
     if(bs->ev_read != NULL) {
         return -1;
     }
+    sync_pktlen = 0;
+    sync_pkt = NULL;
     bs->ev_read = event_register((event_id_t)bs->fd, EV_READFD,
                        stream_read_sync_callback, bs);
     event_wait(bs->ev_read);
-    *buf = bs->databuf;
-    return (bs->len);
+    *buf = sync_pkt;
+    return (sync_pktlen);
 }
 
 
@@ -579,6 +597,9 @@ stream_read_sync_callback(
     if (n < 0)
         security_stream_seterror(&bs->secstr, "%s", strerror(errno));
     bs->len = n;
+    sync_pktlen = bs->len;
+    sync_pkt = malloc(sync_pktlen);
+    memcpy(sync_pkt, bs->databuf, sync_pktlen);
 }
 
 /*