X-Git-Url: https://git.gag.com/?a=blobdiff_plain;ds=sidebyside;f=common-src%2Fbsdudp-security.c;h=a4715ff9d9a3dd5b4683f22a9c19203474f72df8;hb=refs%2Ftags%2Fdebian%2F3.3.1-2;hp=d42432080971afd323d53172302daced685e1f3b;hpb=fb2bd066c2f8b34addafe48d62550e3033a59431;p=debian%2Famanda diff --git a/common-src/bsdudp-security.c b/common-src/bsdudp-security.c index d424320..a4715ff 100644 --- a/common-src/bsdudp-security.c +++ b/common-src/bsdudp-security.c @@ -38,7 +38,6 @@ #include "security.h" #include "security-util.h" #include "stream.h" -#include "version.h" #ifndef SO_RCVBUF #undef DUMPER_SOCKET_BUFFERING @@ -64,6 +63,7 @@ const security_driver_t bsdudp_security_driver = { "BSDUDP", bsdudp_connect, bsdudp_accept, + sec_get_authenticated_peer_name_hostname, bsdudp_close, udpbsd_sendpkt, udp_recvpkt, @@ -107,7 +107,6 @@ bsdudp_connect( void * datap) { struct sec_handle *bh; - struct servent *se; in_port_t port; struct timeval sequence_time; int sequence; @@ -116,12 +115,13 @@ bsdudp_connect( char *canonname; struct addrinfo *res = NULL, *res_addr; int result_bind; + char *service; (void)conf_fn; /* Quiet unused parameter warning */ (void)datap; /* Quiet unused parameter warning */ assert(hostname != NULL); - bh = alloc(sizeof(*bh)); + bh = g_new0(struct sec_handle, 1); bh->proto_handle=NULL; bh->rc = NULL; security_handleinit(&bh->sech, &bsdudp_security_driver); @@ -160,10 +160,8 @@ bsdudp_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); @@ -202,10 +200,8 @@ bsdudp_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); @@ -252,10 +248,21 @@ bsdudp_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);