/*
* 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
"BSD",
bsd_connect,
bsd_accept,
+ sec_get_authenticated_peer_name_hostname,
bsd_close,
udpbsd_sendpkt,
udp_recvpkt,
(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);
* 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);
* 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);
void (*fn)(security_handle_t *, pkt_t *),
void *datap)
{
+ struct stat sbuf;
assert(in >= 0 && out >= 0);
assert(fn != NULL);
netfd4.prefix_packet = &bsd_prefix_packet;
netfd4.driver = &bsd_security_driver;
- udp_addref(&netfd4, &udp_netfd_read_callback);
+ /* check if in is a socket */
+ fstat(in, &sbuf);
+ if (S_ISSOCK(sbuf.st_mode)) {
+ udp_addref(&netfd4, &udp_netfd_read_callback);
+ } else {
+ g_warning("input file descriptor is not a socket; cannot use BSD auth");
+ }
}
/*
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,
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);
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;
+ }
}
/*
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));