#include "util.h"
#include "event.h"
#include "packet.h"
-#include "queue.h"
#include "security.h"
#include "security-util.h"
#include "sockaddr-util.h"
#include "stream.h"
-#include "version.h"
/*
* Number of seconds bsdtcp has to start up
"BSDTCP",
bsdtcp_connect,
bsdtcp_accept,
+ sec_get_authenticated_peer_name_hostname,
sec_close,
stream_sendpkt,
stream_recvpkt,
/*
* Local functions
*/
-static int runbsdtcp(struct sec_handle *);
+static int runbsdtcp(struct sec_handle *, in_port_t port);
/*
struct sec_handle *rh;
int result;
char *canonname;
+ char *service;
+ in_port_t port;
assert(fn != NULL);
assert(hostname != NULL);
auth_debug(1, _("bsdtcp: bsdtcp_connect: %s\n"), hostname);
- rh = alloc(sizeof(*rh));
+ rh = g_new0(struct sec_handle, 1);
security_handleinit(&rh->sech, &bsdtcp_security_driver);
rh->hostname = NULL;
rh->rs = NULL;
amfree(rh->hostname);
rh->hostname = stralloc(rh->rs->rc->hostname);
+ 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, "tcp");
+ if (port == 0) {
+ security_seterror(&rh->sech, _("%s/tcp unknown protocol"), service);
+ goto error;
+ }
+
/*
* We need to open a new connection.
*
* XXX need to eventually limit number of outgoing connections here.
*/
if(rh->rc->read == -1) {
- if (runbsdtcp(rh) < 0)
+ if (runbsdtcp(rh, port) < 0)
goto error;
rh->rc->refcnt++;
}
*/
static int
runbsdtcp(
- struct sec_handle * rh)
+ struct sec_handle * rh,
+ in_port_t port)
{
- struct servent * sp;
int server_socket;
in_port_t my_port;
struct tcp_conn * rc = rh->rc;
- if ((sp = getservbyname(AMANDA_SERVICE_NAME, "tcp")) == NULL) {
- error(_("%s/tcp unknown protocol"), "amanda");
- }
-
set_root_privs(1);
server_socket = stream_client_privileged(rc->hostname,
- (in_port_t)(ntohs((in_port_t)sp->s_port)),
+ port,
STREAM_BUFSIZE,
STREAM_BUFSIZE,
&my_port,