aboutsummaryrefslogtreecommitdiff
path: root/rpcapd/daemon.c
diff options
context:
space:
mode:
Diffstat (limited to 'rpcapd/daemon.c')
-rw-r--r--rpcapd/daemon.c70
1 files changed, 36 insertions, 34 deletions
diff --git a/rpcapd/daemon.c b/rpcapd/daemon.c
index 9b0f82851526..87274665805e 100644
--- a/rpcapd/daemon.c
+++ b/rpcapd/daemon.c
@@ -29,9 +29,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifdef HAVE_CONFIG_H
#include <config.h>
-#endif
#include "ftmacros.h"
#include "varattrs.h"
@@ -95,7 +93,7 @@
// Parameters for the service loop.
struct daemon_slpars
{
- SOCKET sockctrl; //!< SOCKET ID of the control connection
+ PCAP_SOCKET sockctrl; //!< PCAP_SOCKET ID of the control connection
SSL *ssl; //!< Optional SSL handler for the controlling sockets
int isactive; //!< Not null if the daemon has to run in active mode
int nullAuthAllowed; //!< '1' if we permit NULL authentication, '0' otherwise
@@ -110,8 +108,8 @@ struct daemon_slpars
// value for a pthread_t on UN*X.
//
struct session {
- SOCKET sockctrl;
- SOCKET sockdata;
+ PCAP_SOCKET sockctrl;
+ PCAP_SOCKET sockdata;
SSL *ctrl_ssl, *data_ssl; // optional SSL handlers for sockctrl and sockdata.
uint8 protocol_version;
pcap_t *fp;
@@ -125,7 +123,7 @@ struct session {
};
// Locally defined functions
-static int daemon_msg_err(SOCKET sockctrl, SSL *, uint32 plen);
+static int daemon_msg_err(PCAP_SOCKET sockctrl, SSL *, uint32 plen);
static int daemon_msg_auth_req(struct daemon_slpars *pars, uint32 plen);
static int daemon_AuthUserPwd(char *username, char *password, char *errbuf);
@@ -142,7 +140,7 @@ static int daemon_msg_endcap_req(uint8 ver, struct daemon_slpars *pars,
static int daemon_msg_updatefilter_req(uint8 ver, struct daemon_slpars *pars,
struct session *session, uint32 plen);
-static int daemon_unpackapplyfilter(SOCKET sockctrl, SSL *, struct session *session, uint32 *plenp, char *errbuf);
+static int daemon_unpackapplyfilter(PCAP_SOCKET sockctrl, SSL *, struct session *session, uint32 *plenp, char *errbuf);
static int daemon_msg_stats_req(uint8 ver, struct daemon_slpars *pars,
struct session *session, uint32 plen, struct pcap_stat *stats,
@@ -159,9 +157,9 @@ static void *daemon_thrdatamain(void *ptr);
static void noop_handler(int sign);
#endif
-static int rpcapd_recv_msg_header(SOCKET sock, SSL *, struct rpcap_header *headerp);
-static int rpcapd_recv(SOCKET sock, SSL *, char *buffer, size_t toread, uint32 *plen, char *errmsgbuf);
-static int rpcapd_discard(SOCKET sock, SSL *, uint32 len);
+static int rpcapd_recv_msg_header(PCAP_SOCKET sock, SSL *, struct rpcap_header *headerp);
+static int rpcapd_recv(PCAP_SOCKET sock, SSL *, char *buffer, size_t toread, uint32 *plen, char *errmsgbuf);
+static int rpcapd_discard(PCAP_SOCKET sock, SSL *, uint32 len);
static void session_close(struct session *);
//
@@ -211,7 +209,7 @@ static int is_url(const char *source);
#endif
int
-daemon_serviceloop(SOCKET sockctrl, int isactive, char *passiveClients,
+daemon_serviceloop(PCAP_SOCKET sockctrl, int isactive, char *passiveClients,
int nullAuthAllowed, int uses_ssl)
{
uint8 first_octet;
@@ -559,7 +557,7 @@ daemon_serviceloop(SOCKET sockctrl, int isactive, char *passiveClients,
plen = header.plen;
//
- // While we're in the authentication pharse, all requests
+ // While we're in the authentication phase, all requests
// must use version 0.
//
if (header.ver != 0)
@@ -1138,7 +1136,7 @@ end:
* This handles the RPCAP_MSG_ERR message.
*/
static int
-daemon_msg_err(SOCKET sockctrl, SSL *ssl, uint32 plen)
+daemon_msg_err(PCAP_SOCKET sockctrl, SSL *ssl, uint32 plen)
{
char errbuf[PCAP_ERRBUF_SIZE];
char remote_errbuf[PCAP_ERRBUF_SIZE];
@@ -1267,7 +1265,7 @@ daemon_msg_auth_req(struct daemon_slpars *pars, uint32 plen)
username = (char *) malloc (usernamelen + 1);
if (username == NULL)
{
- pcap_fmt_errmsg_for_errno(errmsgbuf,
+ pcapint_fmt_errmsg_for_errno(errmsgbuf,
PCAP_ERRBUF_SIZE, errno, "malloc() failed");
goto error;
}
@@ -1288,7 +1286,7 @@ daemon_msg_auth_req(struct daemon_slpars *pars, uint32 plen)
passwd = (char *) malloc (passwdlen + 1);
if (passwd == NULL)
{
- pcap_fmt_errmsg_for_errno(errmsgbuf,
+ pcapint_fmt_errmsg_for_errno(errmsgbuf,
PCAP_ERRBUF_SIZE, errno, "malloc() failed");
free(username);
goto error;
@@ -1451,7 +1449,7 @@ daemon_AuthUserPwd(char *username, char *password, char *errbuf)
{
// Some error other than an authentication error;
// log it.
- pcap_fmt_errmsg_for_win32_err(errmsgbuf,
+ pcapint_fmt_errmsg_for_win32_err(errmsgbuf,
PCAP_ERRBUF_SIZE, error, "LogonUser() failed");
rpcapd_log(LOGPRIO_ERROR, "%s", errmsgbuf);
}
@@ -1463,7 +1461,7 @@ daemon_AuthUserPwd(char *username, char *password, char *errbuf)
if (ImpersonateLoggedOnUser(Token) == 0)
{
snprintf(errbuf, PCAP_ERRBUF_SIZE, "Authentication failed");
- pcap_fmt_errmsg_for_win32_err(errmsgbuf, PCAP_ERRBUF_SIZE,
+ pcapint_fmt_errmsg_for_win32_err(errmsgbuf, PCAP_ERRBUF_SIZE,
GetLastError(), "ImpersonateLoggedOnUser() failed");
rpcapd_log(LOGPRIO_ERROR, "%s", errmsgbuf);
CloseHandle(Token);
@@ -1483,7 +1481,7 @@ daemon_AuthUserPwd(char *username, char *password, char *errbuf)
* we have getspnam(), otherwise we just do traditional
* authentication, which, on some platforms, might work, even
* with shadow passwords, if we're running as root. Traditional
- * authenticaion won't work if we're not running as root, as
+ * authentication won't work if we're not running as root, as
* I think these days all UN*Xes either won't return the password
* at all with getpwnam() or will only do so if you're root.
*
@@ -1532,7 +1530,7 @@ daemon_AuthUserPwd(char *username, char *password, char *errbuf)
//
// The Single UNIX Specification says that if crypt() fails it
- // sets errno, but some implementatons that haven't been run
+ // sets errno, but some implementations that haven't been run
// through the SUS test suite might not do so.
//
errno = 0;
@@ -1562,7 +1560,7 @@ daemon_AuthUserPwd(char *username, char *password, char *errbuf)
if (setuid(user->pw_uid))
{
error = errno;
- pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
+ pcapint_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
error, "setuid");
rpcapd_log(LOGPRIO_ERROR, "setuid() failed: %s",
strerror(error));
@@ -1572,7 +1570,7 @@ daemon_AuthUserPwd(char *username, char *password, char *errbuf)
/* if (setgid(user->pw_gid))
{
error = errno;
- pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
+ pcapint_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
errno, "setgid");
rpcapd_log(LOGPRIO_ERROR, "setgid() failed: %s",
strerror(error));
@@ -1594,7 +1592,7 @@ daemon_AuthUserPwd(char *username, char *password, char *errbuf)
*/
#define CHECK_AND_INCREASE_REPLY_LEN(itemlen) \
if (replylen > UINT32_MAX - (itemlen)) { \
- pcap_strlcpy(errmsgbuf, "Reply length doesn't fit in 32 bits", \
+ pcapint_strlcpy(errmsgbuf, "Reply length doesn't fit in 32 bits", \
sizeof (errmsgbuf)); \
goto error; \
} \
@@ -1648,7 +1646,7 @@ daemon_msg_findallif_req(uint8 ver, struct daemon_slpars *pars, uint32 plen)
if (d->description) {
size_t stringlen = strlen(d->description);
if (stringlen > UINT16_MAX) {
- pcap_strlcpy(errmsgbuf,
+ pcapint_strlcpy(errmsgbuf,
"Description length doesn't fit in 16 bits",
sizeof (errmsgbuf));
goto error;
@@ -1658,7 +1656,7 @@ daemon_msg_findallif_req(uint8 ver, struct daemon_slpars *pars, uint32 plen)
if (d->name) {
size_t stringlen = strlen(d->name);
if (stringlen > UINT16_MAX) {
- pcap_strlcpy(errmsgbuf,
+ pcapint_strlcpy(errmsgbuf,
"Name length doesn't fit in 16 bits",
sizeof (errmsgbuf));
goto error;
@@ -1682,7 +1680,7 @@ daemon_msg_findallif_req(uint8 ver, struct daemon_slpars *pars, uint32 plen)
#endif
CHECK_AND_INCREASE_REPLY_LEN(sizeof(struct rpcap_sockaddr) * 4);
if (naddrs == UINT16_MAX) {
- pcap_strlcpy(errmsgbuf,
+ pcapint_strlcpy(errmsgbuf,
"Number of interfaces doesn't fit in 16 bits",
sizeof (errmsgbuf));
goto error;
@@ -2085,7 +2083,9 @@ daemon_msg_startcap_req(uint8 ver, struct daemon_slpars *pars, uint32 plen,
goto error;
}
- if (sock_initaddress(peerhost, portdata, &hints, &addrinfo, errmsgbuf, PCAP_ERRBUF_SIZE) == -1)
+ addrinfo = sock_initaddress(peerhost, portdata, &hints,
+ errmsgbuf, PCAP_ERRBUF_SIZE);
+ if (addrinfo == NULL)
goto error;
if ((session->sockdata = sock_open(peerhost, addrinfo, SOCKOPEN_CLIENT, 0, errmsgbuf, PCAP_ERRBUF_SIZE)) == INVALID_SOCKET)
@@ -2096,7 +2096,9 @@ daemon_msg_startcap_req(uint8 ver, struct daemon_slpars *pars, uint32 plen,
hints.ai_flags = AI_PASSIVE;
// Make the server socket pick up a free network port for us
- if (sock_initaddress(NULL, NULL, &hints, &addrinfo, errmsgbuf, PCAP_ERRBUF_SIZE) == -1)
+ addrinfo = sock_initaddress(NULL, NULL, &hints, errmsgbuf,
+ PCAP_ERRBUF_SIZE);
+ if (addrinfo == NULL)
goto error;
if ((session->sockdata = sock_open(NULL, addrinfo, SOCKOPEN_SERVER, 1 /* max 1 connection in queue */, errmsgbuf, PCAP_ERRBUF_SIZE)) == INVALID_SOCKET)
@@ -2175,7 +2177,7 @@ daemon_msg_startcap_req(uint8 ver, struct daemon_slpars *pars, uint32 plen,
if (!serveropen_dp)
{
- SOCKET socktemp; // We need another socket, since we're going to accept() a connection
+ PCAP_SOCKET socktemp; // We need another socket, since we're going to accept() a connection
// Connection creation
saddrlen = sizeof(struct sockaddr_storage);
@@ -2227,7 +2229,7 @@ daemon_msg_startcap_req(uint8 ver, struct daemon_slpars *pars, uint32 plen,
(void *) session);
if (ret != 0)
{
- pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
+ pcapint_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
ret, "Error creating the data thread");
goto error;
}
@@ -2329,7 +2331,7 @@ daemon_msg_endcap_req(uint8 ver, struct daemon_slpars *pars,
#define RPCAP_BPF_MAXINSNS 8192
static int
-daemon_unpackapplyfilter(SOCKET sockctrl, SSL *ctrl_ssl, struct session *session, uint32 *plenp, char *errmsgbuf)
+daemon_unpackapplyfilter(PCAP_SOCKET sockctrl, SSL *ctrl_ssl, struct session *session, uint32 *plenp, char *errmsgbuf)
{
int status;
struct rpcap_filter filter;
@@ -2367,7 +2369,7 @@ daemon_unpackapplyfilter(SOCKET sockctrl, SSL *ctrl_ssl, struct session *session
bf_insn = (struct bpf_insn *) malloc (sizeof(struct bpf_insn) * bf_prog.bf_len);
if (bf_insn == NULL)
{
- pcap_fmt_errmsg_for_errno(errmsgbuf, PCAP_ERRBUF_SIZE,
+ pcapint_fmt_errmsg_for_errno(errmsgbuf, PCAP_ERRBUF_SIZE,
errno, "malloc() failed");
return -2;
}
@@ -2908,7 +2910,7 @@ void sleep_secs(int secs)
* Read the header of a message.
*/
static int
-rpcapd_recv_msg_header(SOCKET sock, SSL *ssl, struct rpcap_header *headerp)
+rpcapd_recv_msg_header(PCAP_SOCKET sock, SSL *ssl, struct rpcap_header *headerp)
{
int nread;
char errbuf[PCAP_ERRBUF_SIZE]; // buffer for network errors
@@ -2940,7 +2942,7 @@ rpcapd_recv_msg_header(SOCKET sock, SSL *ssl, struct rpcap_header *headerp)
* error.
*/
static int
-rpcapd_recv(SOCKET sock, SSL *ssl, char *buffer, size_t toread, uint32 *plen, char *errmsgbuf)
+rpcapd_recv(PCAP_SOCKET sock, SSL *ssl, char *buffer, size_t toread, uint32 *plen, char *errmsgbuf)
{
int nread;
char errbuf[PCAP_ERRBUF_SIZE]; // buffer for network errors
@@ -2969,7 +2971,7 @@ rpcapd_recv(SOCKET sock, SSL *ssl, char *buffer, size_t toread, uint32 *plen, ch
* error.
*/
static int
-rpcapd_discard(SOCKET sock, SSL *ssl, uint32 len)
+rpcapd_discard(PCAP_SOCKET sock, SSL *ssl, uint32 len)
{
char errbuf[PCAP_ERRBUF_SIZE + 1]; // keeps the error string, prior to be printed