diff options
Diffstat (limited to 'libtac')
-rw-r--r-- | libtac/include/libtac.h | 2 | ||||
-rw-r--r-- | libtac/lib/connect.c | 13 |
2 files changed, 12 insertions, 3 deletions
diff --git a/libtac/include/libtac.h b/libtac/include/libtac.h index aad4cbf..18f98f6 100644 --- a/libtac/include/libtac.h +++ b/libtac/include/libtac.h @@ -126,7 +126,7 @@ extern int tac_readtimeout_enable; extern int tac_timeout; int tac_connect(struct addrinfo **, char **, int); -int tac_connect_single(struct addrinfo *, const char *); +int tac_connect_single(struct addrinfo *, const char *, struct addrinfo *); char *tac_ntop(const struct sockaddr *); int tac_authen_send(int, const char *, char *, char *, diff --git a/libtac/lib/connect.c b/libtac/lib/connect.c index 1226797..a186220 100644 --- a/libtac/lib/connect.c +++ b/libtac/lib/connect.c @@ -50,7 +50,7 @@ int tac_connect(struct addrinfo **server, char **key, int servers) { TACSYSLOG((LOG_ERR, "%s: no TACACS+ servers defined", __FUNCTION__)) } else { for ( tries = 0; tries < servers; tries++ ) { - if((fd=tac_connect_single(server[tries], key[tries])) >= 0 ) { + if((fd=tac_connect_single(server[tries], key[tries], NULL)) >= 0 ) { /* tac_secret was set in tac_connect_single on success */ break; } @@ -67,7 +67,7 @@ int tac_connect(struct addrinfo **server, char **key, int servers) { * >= 0 : valid fd * < 0 : error status code, see LIBTAC_STATUS_... */ -int tac_connect_single(struct addrinfo *server, const char *key) { +int tac_connect_single(struct addrinfo *server, const char *key, struct addrinfo *srcaddr) { int retval = LIBTAC_STATUS_CONN_ERR; /* default retval */ int fd = -1; int flags, rc; @@ -100,6 +100,15 @@ int tac_connect_single(struct addrinfo *server, const char *key) { return LIBTAC_STATUS_CONN_ERR; } + /* bind if source address got explicity defined */ + if (srcaddr) { + if (bind(fd, srcaddr->ai_addr, srcaddr->ai_addrlen) < 0) { + TACSYSLOG((LOG_ERR, "%s: Failed to bind source address: %s", + __FUNCTION__, strerror(errno))) + return LIBTAC_STATUS_CONN_ERR; + } + } + rc = connect(fd, server->ai_addr, server->ai_addrlen); /* FIX this..for some reason errno = 0 on AIX... */ if((rc == -1) && (errno != EINPROGRESS) && (errno != 0)) { |