lintian doesn't like orphan packages with uploaders...
[debian/amanda] / common-src / bsd-security.c
index ad929b3cce40ee4d4616be02919762091fa1a9b1..82348ed98241b0c849658696826267eb0188bc95 100644 (file)
@@ -1,6 +1,7 @@
 /*
  * Amanda, The Advanced Maryland Automatic Network Disk Archiver
  * Copyright (c) 1991-1999 University of Maryland at College Park
+ * Copyright (c) 2007-2012 Zmanda, Inc.  All Rights Reserved.
  * All Rights Reserved.
  *
  * Permission to use, copy, modify, distribute, and sell this software and its
@@ -178,10 +179,8 @@ bsd_connect(
         * Only init the IPv6 socket once
         */
        if (res_addr->ai_addr->sa_family == AF_INET6 && not_init6 == 1) {
-           uid_t euid;
            dgram_zero(&netfd6.dgram);
 
-           euid = geteuid();
            set_root_privs(1);
            result_bind = dgram_bind(&netfd6.dgram,
                                     res_addr->ai_addr->sa_family, &port);
@@ -220,10 +219,8 @@ bsd_connect(
         * Only init the IPv4 socket once
         */
        if (res_addr->ai_addr->sa_family == AF_INET && not_init4 == 1) {
-           uid_t euid;
            dgram_zero(&netfd4.dgram);
 
-           euid = geteuid();
            set_root_privs(1);
            result_bind = dgram_bind(&netfd4.dgram,
                                     res_addr->ai_addr->sa_family, &port);
@@ -605,8 +602,12 @@ stream_read_sync_callback(
         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);
+    if (sync_pktlen > 0) {
+       sync_pkt = malloc(sync_pktlen);
+       memcpy(sync_pkt, bs->databuf, sync_pktlen);
+    } else {
+       sync_pkt = NULL;
+    }
 }
 
 /*
@@ -638,14 +639,12 @@ stream_read_callback(
 
     assert(bs != NULL);
 
-    /*
-     * Remove the event first, in case they reschedule it in the callback.
-     */
-    bsd_stream_read_cancel(bs);
     do {
        n = read(bs->fd, bs->databuf, SIZEOF(bs->databuf));
     } while ((n < 0) && ((errno == EINTR) || (errno == EAGAIN)));
 
+    if (n <= 0)
+       bsd_stream_read_cancel(bs);
     if (n < 0)
        security_stream_seterror(&bs->secstr, "%s", strerror(errno));