mirror of
https://github.com/nmap/nmap.git
synced 2026-01-20 13:19:01 +00:00
Whitespace.
indent -kr -i4 -nut -l0 -ss -T size_t *.c with manual adjustments.
This commit is contained in:
@@ -140,7 +140,7 @@ char *b64enc(const unsigned char *data, int len)
|
||||
char *dest;
|
||||
|
||||
/* malloc enough space to do something useful */
|
||||
dest = (char*)safe_malloc(4 * len / 3 + 4);
|
||||
dest = (char *) safe_malloc(4 * len / 3 + 4);
|
||||
|
||||
dest[0] = '\0';
|
||||
|
||||
|
||||
@@ -280,7 +280,7 @@ static int str_cmp_i(const char *a, const char *b)
|
||||
ca = tolower((int) (unsigned char) *a);
|
||||
cb = tolower((int) (unsigned char) *b);
|
||||
if (ca != cb)
|
||||
return ca - cb;
|
||||
return ca - cb;
|
||||
a++;
|
||||
b++;
|
||||
}
|
||||
|
||||
@@ -190,12 +190,12 @@ static void set_ssl_ctx_options(SSL_CTX *ctx)
|
||||
}
|
||||
|
||||
if (o.sslcert != NULL && o.sslkey != NULL) {
|
||||
if (SSL_CTX_use_certificate_file(ctx, o.sslcert, SSL_FILETYPE_PEM) != 1)
|
||||
if (SSL_CTX_use_certificate_file(ctx, o.sslcert, SSL_FILETYPE_PEM) != 1)
|
||||
bye("SSL_CTX_use_certificate_file(): %s.", ERR_error_string(ERR_get_error(), NULL));
|
||||
if (SSL_CTX_use_PrivateKey_file(ctx, o.sslkey, SSL_FILETYPE_PEM) != 1)
|
||||
if (SSL_CTX_use_PrivateKey_file(ctx, o.sslkey, SSL_FILETYPE_PEM) != 1)
|
||||
bye("SSL_CTX_use_Privatekey_file(): %s.", ERR_error_string(ERR_get_error(), NULL));
|
||||
} else {
|
||||
if ((o.sslcert == NULL)!= (o.sslkey == NULL))
|
||||
if ((o.sslcert == NULL) != (o.sslkey == NULL))
|
||||
bye("The --ssl-key and --ssl-cert options must be used together.");
|
||||
}
|
||||
}
|
||||
@@ -458,7 +458,8 @@ bail:
|
||||
return -1;
|
||||
}
|
||||
|
||||
int ncat_connect(void) {
|
||||
int ncat_connect(void)
|
||||
{
|
||||
nsock_pool mypool;
|
||||
int rc;
|
||||
|
||||
@@ -474,7 +475,7 @@ int ncat_connect(void) {
|
||||
nsp_setbroadcast(mypool, 1);
|
||||
|
||||
#ifdef HAVE_OPENSSL
|
||||
set_ssl_ctx_options((SSL_CTX *)nsp_ssl_init(mypool));
|
||||
set_ssl_ctx_options((SSL_CTX *) nsp_ssl_init(mypool));
|
||||
#endif
|
||||
|
||||
if (httpconnect.storage.ss_family == AF_UNSPEC
|
||||
@@ -649,7 +650,7 @@ static void connect_handler(nsock_pool nsp, nsock_event evt, void *data)
|
||||
if (nsi_checkssl(cs.sock_nsi)) {
|
||||
/* Check the domain name. ssl_post_connect_check prints an
|
||||
error message if appropriate. */
|
||||
if (!ssl_post_connect_check((SSL *)nsi_getssl(cs.sock_nsi), o.target))
|
||||
if (!ssl_post_connect_check((SSL *) nsi_getssl(cs.sock_nsi), o.target))
|
||||
bye("Certificate verification error.");
|
||||
}
|
||||
#endif
|
||||
@@ -677,7 +678,7 @@ static void post_connect(nsock_pool nsp, nsock_iod iod)
|
||||
#endif
|
||||
/* Convert Nsock's non-blocking socket to an ordinary blocking one. It's
|
||||
possible for a program to write fast enough that it will get an
|
||||
EAGAIN on write on a non-blocking socket.*/
|
||||
EAGAIN on write on a non-blocking socket. */
|
||||
block_socket(info.fd);
|
||||
netexec(&info, o.cmdexec);
|
||||
}
|
||||
|
||||
@@ -130,7 +130,8 @@ struct options o;
|
||||
struct timeval start_time;
|
||||
|
||||
/* Initializes global options to their default values. */
|
||||
void options_init(void) {
|
||||
void options_init(void)
|
||||
{
|
||||
o.verbose = 0;
|
||||
o.debug = 0;
|
||||
o.target = NULL;
|
||||
@@ -384,7 +385,7 @@ int ncat_delay_timer(int delayval)
|
||||
* Return the open file descriptor. */
|
||||
int ncat_openlog(const char *logfile, int append)
|
||||
{
|
||||
if(append)
|
||||
if (append)
|
||||
return Open(logfile, O_WRONLY | O_CREAT | O_APPEND, 0664);
|
||||
else
|
||||
return Open(logfile, O_WRONLY | O_CREAT | O_TRUNC, 0664);
|
||||
@@ -423,7 +424,7 @@ static int ncat_hexdump(int logfd, const char *data, int len)
|
||||
for (i = 1; i <= len; i++) {
|
||||
if (i % 16 == 1) {
|
||||
/* Hex address output */
|
||||
Snprintf(addrstr, sizeof(addrstr), "%.4x", (u_int)(p - data));
|
||||
Snprintf(addrstr, sizeof(addrstr), "%.4x", (u_int) (p - data));
|
||||
}
|
||||
|
||||
c = *p;
|
||||
|
||||
@@ -197,7 +197,8 @@ extern void set_pseudo_sigchld_handler(void (*handler)(void))
|
||||
/* Run a command and redirect its input and output handles to a pair of
|
||||
anonymous pipes. The process handle and pipe handles are returned in the
|
||||
info struct. Returns the PID of the new process, or -1 on error. */
|
||||
static int run_command_redirected(char *cmdexec, struct subprocess_info *info) {
|
||||
static int run_command_redirected(char *cmdexec, struct subprocess_info *info)
|
||||
{
|
||||
/* Each named pipe we create has to have a unique name. */
|
||||
static int pipe_serial_no = 0;
|
||||
char pipe_name[32];
|
||||
@@ -361,7 +362,8 @@ static int start_subprocess(char *cmdexec, struct subprocess_info *info)
|
||||
called directly to simulate exec. It frees the subprocess_info struct and
|
||||
closes the socket and pipe handles before returning. Returns the exit code
|
||||
of the subprocess. */
|
||||
static DWORD WINAPI subprocess_thread_func(void *data) {
|
||||
static DWORD WINAPI subprocess_thread_func(void *data)
|
||||
{
|
||||
struct subprocess_info *info;
|
||||
char pipe_buffer[BUFSIZ];
|
||||
OVERLAPPED overlap = { 0 };
|
||||
|
||||
@@ -155,7 +155,8 @@ static unsigned int conn_inc = 0;
|
||||
static volatile unsigned int conn_dec = 0;
|
||||
static volatile sig_atomic_t conn_dec_changed;
|
||||
|
||||
static void decrease_conn_count(void) {
|
||||
static void decrease_conn_count(void)
|
||||
{
|
||||
conn_dec_changed = 1;
|
||||
conn_dec++;
|
||||
}
|
||||
@@ -279,7 +280,7 @@ static int ncat_listen_stream(int proto)
|
||||
FD_CLR(i, &master_readfds);
|
||||
FD_CLR(i, &master_writefds);
|
||||
fdi = get_fdinfo(&client_fdlist, i);
|
||||
switch(ssl_handshake(fdi)){
|
||||
switch (ssl_handshake(fdi)) {
|
||||
case NCAT_SSL_HANDSHAKE_COMPLETED:
|
||||
/* Clear from sslpending_fds once ssl is established */
|
||||
FD_CLR(i, &sslpending_fds);
|
||||
@@ -312,9 +313,9 @@ static int ncat_listen_stream(int proto)
|
||||
/* we have a new connection request */
|
||||
handle_connection(i);
|
||||
} else if (i == STDIN_FILENO) {
|
||||
if(o.broker) {
|
||||
if (o.broker) {
|
||||
read_and_broadcast(i);
|
||||
}else {
|
||||
} else {
|
||||
/* Read from stdin and write to all clients. */
|
||||
rc = read_stdin();
|
||||
if (rc == 0 && o.sendonly)
|
||||
@@ -325,9 +326,9 @@ static int ncat_listen_stream(int proto)
|
||||
return 1;
|
||||
}
|
||||
} else if (!o.sendonly) {
|
||||
if(o.broker) {
|
||||
if (o.broker) {
|
||||
read_and_broadcast(i);
|
||||
}else {
|
||||
} else {
|
||||
/* Read from a client and write to stdout. */
|
||||
rc = read_socket(i);
|
||||
if (rc <= 0 && !o.keepopen)
|
||||
@@ -373,7 +374,7 @@ static void handle_connection(int socket_accept)
|
||||
loguser("Connection from %s.\n", inet_socktop(&remoteaddr));
|
||||
}
|
||||
|
||||
if (!o.keepopen && !o.broker) {
|
||||
if (!o.keepopen && !o.broker) {
|
||||
int i;
|
||||
for (i = 0; i < num_listenaddrs; i++) {
|
||||
Close(listen_socket[i]);
|
||||
@@ -406,7 +407,7 @@ static void handle_connection(int socket_accept)
|
||||
|
||||
unblock_socket(s.fd);
|
||||
|
||||
#ifdef HAVE_OPENSSL
|
||||
#ifdef HAVE_OPENSSL
|
||||
if (o.ssl) {
|
||||
/* Add the socket to the necessary descriptor lists. */
|
||||
FD_SET(s.fd, &sslpending_fds);
|
||||
@@ -416,7 +417,7 @@ static void handle_connection(int socket_accept)
|
||||
if (add_fdinfo(&client_fdlist, &s) < 0)
|
||||
bye("add_fdinfo() failed.");
|
||||
} else
|
||||
#endif
|
||||
#endif
|
||||
post_handle_connection(s);
|
||||
}
|
||||
|
||||
@@ -442,11 +443,11 @@ static void post_handle_connection(struct fdinfo sinfo)
|
||||
FD_SET(sinfo.fd, &master_readfds);
|
||||
/* add it to our list of fds for maintaining maxfd */
|
||||
if (add_fdinfo(&client_fdlist, &sinfo) < 0)
|
||||
bye("add_fdinfo() failed.");
|
||||
bye("add_fdinfo() failed.");
|
||||
}
|
||||
FD_SET(sinfo.fd, &master_broadcastfds);
|
||||
if (add_fdinfo(&broadcast_fdlist, &sinfo) < 0)
|
||||
bye("add_fdinfo() failed.");
|
||||
bye("add_fdinfo() failed.");
|
||||
|
||||
if (o.chat)
|
||||
chat_announce_connect(sinfo.fd, &sinfo.remoteaddr);
|
||||
@@ -549,7 +550,7 @@ static int ncat_listen_dgram(int proto)
|
||||
int sockfd[NUM_LISTEN_ADDRS];
|
||||
int i, fdn = -1;
|
||||
int fdmax, nbytes, fds_ready;
|
||||
char buf[DEFAULT_UDP_BUF_LEN] = {0};
|
||||
char buf[DEFAULT_UDP_BUF_LEN] = { 0 };
|
||||
char *tempbuf = NULL;
|
||||
fd_set read_fds;
|
||||
union sockaddr_u remotess;
|
||||
@@ -584,7 +585,7 @@ static int ncat_listen_dgram(int proto)
|
||||
for (i = 0; i < num_listenaddrs; i++) {
|
||||
/* create the UDP listen sockets */
|
||||
sockfd[i] = do_listen(SOCK_DGRAM, proto, &listenaddrs[i]);
|
||||
FD_SET(sockfd[i],&listen_fds);
|
||||
FD_SET(sockfd[i], &listen_fds);
|
||||
add_fd(&listen_fdlist, sockfd[i]);
|
||||
}
|
||||
|
||||
@@ -598,14 +599,14 @@ static int ncat_listen_dgram(int proto)
|
||||
|
||||
/* Rebuild the udp socket which got burnt */
|
||||
sockfd[fdn] = do_listen(SOCK_DGRAM, proto, &listenaddrs[fdn]);
|
||||
FD_SET(sockfd[fdn],&listen_fds);
|
||||
FD_SET(sockfd[fdn], &listen_fds);
|
||||
add_fd(&listen_fdlist, sockfd[fdn]);
|
||||
|
||||
}
|
||||
fdn = -1;
|
||||
socket_n = -1;
|
||||
fd_set fds;
|
||||
FD_ZERO(&fds);
|
||||
fd_set fds;
|
||||
FD_ZERO(&fds);
|
||||
while (1) {
|
||||
/*
|
||||
* We just select to get a list of sockets which we can talk to
|
||||
@@ -624,7 +625,7 @@ static int ncat_listen_dgram(int proto)
|
||||
* really call a function for each ready socket instead of breaking on
|
||||
* the first one.
|
||||
*/
|
||||
for (i = 0; i <= listen_fdlist.fdmax && fds_ready >0; i++) {
|
||||
for (i = 0; i <= listen_fdlist.fdmax && fds_ready > 0; i++) {
|
||||
/* Loop through descriptors until there is something ready */
|
||||
if (!FD_ISSET(i, &fds))
|
||||
continue;
|
||||
@@ -632,7 +633,7 @@ static int ncat_listen_dgram(int proto)
|
||||
/* Check each listening socket */
|
||||
for (j = 0; j < num_listenaddrs; j++) {
|
||||
if (i == sockfd[j]) {
|
||||
if (o.debug >1)
|
||||
if (o.debug > 1)
|
||||
logdebug("Valid descriptor %d \n", i);
|
||||
fdn = j;
|
||||
socket_n = i;
|
||||
|
||||
121
ncat/ncat_main.c
121
ncat/ncat_main.c
@@ -308,7 +308,7 @@ int main(int argc, char *argv[])
|
||||
case 'c':
|
||||
o.cmdexec = optarg;
|
||||
o.shellexec = 1;
|
||||
break;
|
||||
break;
|
||||
case 'e':
|
||||
o.cmdexec = optarg;
|
||||
break;
|
||||
@@ -394,83 +394,54 @@ int main(int argc, char *argv[])
|
||||
if (strcmp(long_options[option_index].name, "version") == 0) {
|
||||
print_banner();
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
else if (strcmp(long_options[option_index].name, "proxy") == 0)
|
||||
{
|
||||
} else if (strcmp(long_options[option_index].name, "proxy") == 0) {
|
||||
if (proxyaddr)
|
||||
bye("You can't specify more than one --proxy.");
|
||||
proxyaddr = Strdup(optarg);
|
||||
}
|
||||
else if (strcmp(long_options[option_index].name, "proxy-type") == 0)
|
||||
{
|
||||
} else if (strcmp(long_options[option_index].name, "proxy-type") == 0) {
|
||||
if (o.proxytype)
|
||||
bye("You can't specify more than one --proxy-type.");
|
||||
bye("You can't specify more than one --proxy-type.");
|
||||
o.proxytype = Strdup(optarg);
|
||||
}
|
||||
else if (strcmp(long_options[option_index].name, "proxy-auth") == 0)
|
||||
{
|
||||
} else if (strcmp(long_options[option_index].name, "proxy-auth") == 0) {
|
||||
if (o.proxy_auth)
|
||||
bye("You can't specify more than one --proxy-auth.");
|
||||
bye("You can't specify more than one --proxy-auth.");
|
||||
o.proxy_auth = Strdup(optarg);
|
||||
}
|
||||
else if (strcmp(long_options[option_index].name, "nsock-engine") == 0)
|
||||
{
|
||||
} else if (strcmp(long_options[option_index].name, "nsock-engine") == 0) {
|
||||
nsock_set_default_engine(optarg);
|
||||
}
|
||||
else if (strcmp(long_options[option_index].name, "broker") == 0)
|
||||
{
|
||||
} else if (strcmp(long_options[option_index].name, "broker") == 0) {
|
||||
o.broker = 1;
|
||||
/* --broker implies --listen. */
|
||||
o.listen = 1;
|
||||
}
|
||||
else if (strcmp(long_options[option_index].name, "chat") == 0
|
||||
|| strcmp(long_options[option_index].name, "talk") == 0)
|
||||
{
|
||||
} else if (strcmp(long_options[option_index].name, "chat") == 0
|
||||
|| strcmp(long_options[option_index].name, "talk") == 0) {
|
||||
/* --talk is an older name for --chat. */
|
||||
o.chat = 1;
|
||||
/* --chat implies --broker. */
|
||||
o.broker = 1;
|
||||
}
|
||||
else if (strcmp(long_options[option_index].name, "allow") == 0)
|
||||
{
|
||||
} else if (strcmp(long_options[option_index].name, "allow") == 0) {
|
||||
o.allow = 1;
|
||||
host_list_add_spec(&allow_host_list, optarg);
|
||||
}
|
||||
else if (strcmp(long_options[option_index].name, "allowfile") == 0)
|
||||
{
|
||||
} else if (strcmp(long_options[option_index].name, "allowfile") == 0) {
|
||||
o.allow = 1;
|
||||
host_list_add_filename(&allow_host_list, optarg);
|
||||
}
|
||||
else if (strcmp(long_options[option_index].name, "deny") == 0)
|
||||
{
|
||||
} else if (strcmp(long_options[option_index].name, "deny") == 0) {
|
||||
host_list_add_spec(&deny_host_list, optarg);
|
||||
}
|
||||
else if (strcmp(long_options[option_index].name, "denyfile") == 0)
|
||||
{
|
||||
} else if (strcmp(long_options[option_index].name, "denyfile") == 0) {
|
||||
host_list_add_filename(&deny_host_list, optarg);
|
||||
}
|
||||
else if (strcmp(long_options[option_index].name, "append-output") == 0)
|
||||
{
|
||||
} else if (strcmp(long_options[option_index].name, "append-output") == 0) {
|
||||
o.append = 1;
|
||||
}
|
||||
#ifdef HAVE_OPENSSL
|
||||
else if (strcmp(long_options[option_index].name, "ssl-cert") == 0)
|
||||
{
|
||||
else if (strcmp(long_options[option_index].name, "ssl-cert") == 0) {
|
||||
o.ssl = 1;
|
||||
o.sslcert = Strdup(optarg);
|
||||
}
|
||||
else if (strcmp(long_options[option_index].name, "ssl-key") == 0)
|
||||
{
|
||||
} else if (strcmp(long_options[option_index].name, "ssl-key") == 0) {
|
||||
o.ssl = 1;
|
||||
o.sslkey = Strdup(optarg);
|
||||
}
|
||||
else if (strcmp(long_options[option_index].name, "ssl-verify") == 0)
|
||||
{
|
||||
} else if (strcmp(long_options[option_index].name, "ssl-verify") == 0) {
|
||||
o.sslverify = 1;
|
||||
o.ssl = 1;
|
||||
}
|
||||
else if (strcmp(long_options[option_index].name, "ssl-trustfile") == 0)
|
||||
{
|
||||
} else if (strcmp(long_options[option_index].name, "ssl-trustfile") == 0) {
|
||||
o.ssl = 1;
|
||||
if (o.ssltrustfile != NULL)
|
||||
bye("The --ssl-trustfile option may be given only once.");
|
||||
@@ -569,34 +540,34 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
if (proxyaddr) {
|
||||
if (!o.proxytype)
|
||||
o.proxytype = Strdup("http");
|
||||
if (!o.proxytype)
|
||||
o.proxytype = Strdup("http");
|
||||
|
||||
if (!strcmp(o.proxytype, "http")) {
|
||||
/* Parse HTTP proxy address and temporarily store it in httpconnect. If
|
||||
* the proxy server is given as an IPv6 address (not hostname), the port
|
||||
* number MUST be specified as well or parsing will break (due to the
|
||||
* colons in the IPv6 address and host:port separator).
|
||||
*/
|
||||
if (!strcmp(o.proxytype, "http")) {
|
||||
/* Parse HTTP proxy address and temporarily store it in httpconnect. If
|
||||
* the proxy server is given as an IPv6 address (not hostname), the port
|
||||
* number MUST be specified as well or parsing will break (due to the
|
||||
* colons in the IPv6 address and host:port separator).
|
||||
*/
|
||||
|
||||
parseproxy(proxyaddr, &httpconnect.storage, DEFAULT_PROXY_PORT);
|
||||
} else if (!strcmp(o.proxytype, "socks4") || !strcmp(o.proxytype, "4")) {
|
||||
/* Parse SOCKS proxy address and temporarily store it in socksconnect */
|
||||
parseproxy(proxyaddr, &httpconnect.storage, DEFAULT_PROXY_PORT);
|
||||
} else if (!strcmp(o.proxytype, "socks4") || !strcmp(o.proxytype, "4")) {
|
||||
/* Parse SOCKS proxy address and temporarily store it in socksconnect */
|
||||
|
||||
parseproxy(proxyaddr, &socksconnect.storage, DEFAULT_SOCKS4_PORT);
|
||||
} else {
|
||||
bye("Invalid proxy type \"%s\".", o.proxytype);
|
||||
}
|
||||
parseproxy(proxyaddr, &socksconnect.storage, DEFAULT_SOCKS4_PORT);
|
||||
} else {
|
||||
bye("Invalid proxy type \"%s\".", o.proxytype);
|
||||
}
|
||||
|
||||
free(o.proxytype);
|
||||
free(proxyaddr);
|
||||
free(o.proxytype);
|
||||
free(proxyaddr);
|
||||
} else {
|
||||
if (o.proxytype) {
|
||||
if (!o.listen)
|
||||
bye("Proxy type (--proxy-type) specified without proxy address (--proxy).");
|
||||
if (strcmp(o.proxytype, "http"))
|
||||
bye("Invalid proxy type \"%s\".", o.proxytype);
|
||||
}
|
||||
if (o.proxytype) {
|
||||
if (!o.listen)
|
||||
bye("Proxy type (--proxy-type) specified without proxy address (--proxy).");
|
||||
if (strcmp(o.proxytype, "http"))
|
||||
bye("Invalid proxy type \"%s\".", o.proxytype);
|
||||
}
|
||||
}
|
||||
|
||||
/* Default port */
|
||||
@@ -723,7 +694,8 @@ connection brokering should work.");
|
||||
}
|
||||
|
||||
/* connect error handling and operations. */
|
||||
static int ncat_connect_mode(void) {
|
||||
static int ncat_connect_mode(void)
|
||||
{
|
||||
/*
|
||||
* allow/deny commands with connect make no sense. If you don't want to
|
||||
* connect to a host, don't try to.
|
||||
@@ -744,7 +716,8 @@ static int ncat_connect_mode(void) {
|
||||
return ncat_connect();
|
||||
}
|
||||
|
||||
static int ncat_listen_mode(void) {
|
||||
static int ncat_listen_mode(void)
|
||||
{
|
||||
/* Can't 'listen' AND 'connect' to a proxy server at the same time. */
|
||||
if (httpconnect.storage.ss_family != AF_UNSPEC || socksconnect.storage.ss_family != AF_UNSPEC)
|
||||
bye("Invalid option combination: --proxy and -l.");
|
||||
@@ -779,7 +752,7 @@ static int ncat_listen_mode(void) {
|
||||
int rc;
|
||||
|
||||
/* No command-line address. Listen on IPv4 or IPv6 or both. */
|
||||
/* Try to bind to IPv6 first; on AIX a bound IPv4 socket blocks an IPv6
|
||||
/* Try to bind to IPv6 first; on AIX a bound IPv4 socket blocks an IPv6
|
||||
socket on the same port, despite IPV6_V6ONLY. */
|
||||
#ifdef HAVE_IPV6
|
||||
if (o.af == AF_INET6 || o.af == AF_UNSPEC) {
|
||||
|
||||
@@ -186,7 +186,7 @@ void netexec(struct fdinfo *info, char *cmdexec)
|
||||
execv(cmdargs[0], cmdargs);
|
||||
}
|
||||
|
||||
/* exec failed.*/
|
||||
/* exec failed. */
|
||||
die("exec");
|
||||
}
|
||||
|
||||
@@ -276,34 +276,41 @@ char **cmdline_split(const char *cmdexec)
|
||||
ptr = cmdexec;
|
||||
while (*ptr) {
|
||||
// Find the start of the token
|
||||
while (('\0' != *ptr) && isspace((int) (unsigned char) *ptr)) ptr++;
|
||||
if ('\0' == *ptr) break;
|
||||
while (('\0' != *ptr) && isspace((int) (unsigned char) *ptr))
|
||||
ptr++;
|
||||
if ('\0' == *ptr)
|
||||
break;
|
||||
max_tokens++;
|
||||
// Find the start of the whitespace again
|
||||
while (('\0' != *ptr) && !isspace((int) (unsigned char) *ptr)) ptr++;
|
||||
while (('\0' != *ptr) && !isspace((int) (unsigned char) *ptr))
|
||||
ptr++;
|
||||
}
|
||||
|
||||
/* The line is not empty so we've got something to deal with */
|
||||
cmd_args = (char**)safe_malloc(sizeof(char*) * (max_tokens + 1));
|
||||
cur_arg = (char*)Calloc(sizeof(char), strlen(cmdexec));
|
||||
cmd_args = (char **) safe_malloc(sizeof(char *) * (max_tokens + 1));
|
||||
cur_arg = (char *) Calloc(sizeof(char), strlen(cmdexec));
|
||||
|
||||
/* Get and copy the tokens */
|
||||
ptr = cmdexec;
|
||||
while (*ptr) {
|
||||
while (('\0' != *ptr) && isspace((int) (unsigned char) *ptr)) ptr++;
|
||||
if ('\0' == *ptr) break;
|
||||
while (('\0' != *ptr) && isspace((int) (unsigned char) *ptr))
|
||||
ptr++;
|
||||
if ('\0' == *ptr)
|
||||
break;
|
||||
|
||||
while (('\0' != *ptr) && !isspace((int) (unsigned char) *ptr)) {
|
||||
if ('\\' == *ptr) {
|
||||
ptr++;
|
||||
if ('\0' == *ptr) break;
|
||||
if ('\0' == *ptr)
|
||||
break;
|
||||
|
||||
cur_arg[ptr_idx] = *ptr;
|
||||
ptr_idx++;
|
||||
ptr++;
|
||||
|
||||
if ('\\' != *(ptr - 1)) {
|
||||
while (('\0' != *ptr) && isspace((int) (unsigned char) *ptr)) ptr++;
|
||||
while (('\0' != *ptr) && isspace((int) (unsigned char) *ptr))
|
||||
ptr++;
|
||||
}
|
||||
} else {
|
||||
cur_arg[ptr_idx] = *ptr;
|
||||
|
||||
@@ -104,7 +104,8 @@
|
||||
/* SIG_CHLD handler */
|
||||
static void proxyreaper(int signo)
|
||||
{
|
||||
while (waitpid(-1, NULL, WNOHANG) > 0);
|
||||
while (waitpid(-1, NULL, WNOHANG) > 0)
|
||||
;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -209,7 +210,7 @@ int ncat_http_server(void)
|
||||
if (o.debug > 1)
|
||||
logdebug("select returned %d fds ready\n", fds_ready);
|
||||
|
||||
for (i = 0; i <= listen_fdlist.fdmax && fds_ready >0; i++) {
|
||||
for (i = 0; i <= listen_fdlist.fdmax && fds_ready > 0; i++) {
|
||||
/* Loop through descriptors until there is something ready */
|
||||
if (!FD_ISSET(i, &read_fds))
|
||||
continue;
|
||||
@@ -231,7 +232,7 @@ int ncat_http_server(void)
|
||||
continue;
|
||||
}
|
||||
if (o.debug > 1)
|
||||
logdebug("forking handler for %d\n", i);
|
||||
logdebug("forking handler for %d\n", i);
|
||||
fork_handler(i, c);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,7 +200,8 @@ SSL *new_ssl(int fd)
|
||||
must be the entire leftmost component, and there must be at least two
|
||||
components following it. len is the length of pattern; pattern may contain
|
||||
null bytes so that len != strlen(pattern). */
|
||||
static int wildcard_match(const char *pattern, const char *hostname, size_t len) {
|
||||
static int wildcard_match(const char *pattern, const char *hostname, size_t len)
|
||||
{
|
||||
if (pattern[0] == '*' && pattern[1] == '.') {
|
||||
/* A wildcard pattern. */
|
||||
const char *p, *h, *dot;
|
||||
@@ -313,7 +314,7 @@ static int cert_match_dnsname(X509 *cert, const char *hostname,
|
||||
if (num_checked != NULL)
|
||||
(*num_checked)++;
|
||||
if (wildcard_match((char *) ASN1_STRING_data(gen_name->d.dNSName), hostname, ASN1_STRING_length(gen_name->d.dNSName)))
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -576,31 +577,31 @@ int ssl_handshake(struct fdinfo *sinfo)
|
||||
int ret = 0;
|
||||
int sslerr = 0;
|
||||
|
||||
if(sinfo == NULL) {
|
||||
if (sinfo == NULL) {
|
||||
if (o.debug)
|
||||
logdebug("ncat_ssl.c: Invoking ssl_handshake() with a NULL parameter "
|
||||
"is a serious bug. Please fix it.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if(!o.ssl)
|
||||
if (!o.ssl)
|
||||
return -1;
|
||||
|
||||
/* Initialize the socket too if it isn't. */
|
||||
if(!sinfo->ssl)
|
||||
if (!sinfo->ssl)
|
||||
sinfo->ssl = new_ssl(sinfo->fd);
|
||||
|
||||
ret = SSL_accept(sinfo->ssl);
|
||||
|
||||
if(ret == 1)
|
||||
if (ret == 1)
|
||||
return NCAT_SSL_HANDSHAKE_COMPLETED;
|
||||
|
||||
sslerr = SSL_get_error(sinfo->ssl, ret);
|
||||
|
||||
if(ret == -1) {
|
||||
if(sslerr == SSL_ERROR_WANT_READ)
|
||||
if (ret == -1) {
|
||||
if (sslerr == SSL_ERROR_WANT_READ)
|
||||
return NCAT_SSL_HANDSHAKE_PENDING_READ;
|
||||
if(sslerr == SSL_ERROR_WANT_WRITE)
|
||||
if (sslerr == SSL_ERROR_WANT_WRITE)
|
||||
return NCAT_SSL_HANDSHAKE_PENDING_WRITE;
|
||||
}
|
||||
|
||||
@@ -613,5 +614,3 @@ int ssl_handshake(struct fdinfo *sinfo)
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@
|
||||
|
||||
void *Calloc(size_t nmemb, size_t size)
|
||||
{
|
||||
void *ret;
|
||||
void *ret;
|
||||
|
||||
/* older libcs don't check for int overflow */
|
||||
smul(nmemb, size);
|
||||
@@ -170,7 +170,7 @@ ssize_t Recv(int s, void *buf, size_t len, int flags)
|
||||
{
|
||||
ssize_t ret;
|
||||
|
||||
ret = recv(s, (char*)buf, len, flags);
|
||||
ret = recv(s, (char *) buf, len, flags);
|
||||
if (ret < 0)
|
||||
die("recv");
|
||||
|
||||
@@ -182,7 +182,7 @@ ssize_t Recvfrom(int s, void *buf, size_t len, int flags,
|
||||
{
|
||||
ssize_t ret;
|
||||
|
||||
ret = recvfrom(s, (char*)buf, len, flags, from, fromlen);
|
||||
ret = recvfrom(s, (char *) buf, len, flags, from, fromlen);
|
||||
if (ret < 0)
|
||||
die("recvfrom");
|
||||
|
||||
@@ -194,7 +194,7 @@ int Setsockopt(int s, int level, int optname, const void *optval,
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = setsockopt(s, level, optname, (const char*)optval, optlen);
|
||||
ret = setsockopt(s, level, optname, (const char *) optval, optlen);
|
||||
if (ret < 0)
|
||||
die("setsockopt");
|
||||
|
||||
@@ -203,7 +203,7 @@ int Setsockopt(int s, int level, int optname, const void *optval,
|
||||
|
||||
sighandler_t Signal(int signum, sighandler_t handler)
|
||||
{
|
||||
sighandler_t ret;
|
||||
sighandler_t ret;
|
||||
|
||||
ret = signal(signum, handler);
|
||||
if (ret == SIG_ERR)
|
||||
@@ -226,7 +226,7 @@ int Socket(int domain, int type, int protocol)
|
||||
|
||||
char *Strdup(const char *s)
|
||||
{
|
||||
char *ret;
|
||||
char *ret;
|
||||
|
||||
ret = strdup(s);
|
||||
if (ret == NULL)
|
||||
|
||||
42
ncat/util.c
42
ncat/util.c
@@ -118,22 +118,22 @@
|
||||
/* safely add 2 size_t */
|
||||
size_t sadd(size_t l, size_t r)
|
||||
{
|
||||
size_t t;
|
||||
size_t t;
|
||||
|
||||
t = l + r;
|
||||
if (t < l)
|
||||
bye("integer overflow %lu + %lu.", (u_long)l, (u_long)r);
|
||||
bye("integer overflow %lu + %lu.", (u_long) l, (u_long) r);
|
||||
return t;
|
||||
}
|
||||
|
||||
/* safely multiply 2 size_t */
|
||||
size_t smul(size_t l, size_t r)
|
||||
{
|
||||
size_t t;
|
||||
size_t t;
|
||||
|
||||
t = l * r;
|
||||
if (l && t / l != r)
|
||||
bye("integer overflow %lu * %lu.", (u_long)l, (u_long)r);
|
||||
bye("integer overflow %lu * %lu.", (u_long) l, (u_long) r);
|
||||
return t;
|
||||
}
|
||||
|
||||
@@ -143,8 +143,8 @@ void windows_init()
|
||||
WORD werd;
|
||||
WSADATA data;
|
||||
|
||||
werd = MAKEWORD( 2, 2 );
|
||||
if ( (WSAStartup(werd, &data)) !=0 )
|
||||
werd = MAKEWORD(2, 2);
|
||||
if ((WSAStartup(werd, &data)) != 0)
|
||||
bye("Failed to start WinSock.");
|
||||
}
|
||||
#endif
|
||||
@@ -217,7 +217,7 @@ int strbuf_append(char **buf, size_t *size, size_t *offset, const char *s, size_
|
||||
|
||||
if (n >= *size - *offset) {
|
||||
*size += n + 1;
|
||||
*buf = (char*) safe_realloc(*buf, *size);
|
||||
*buf = (char *) safe_realloc(*buf, *size);
|
||||
}
|
||||
|
||||
memcpy(*buf + *offset, s, n);
|
||||
@@ -244,7 +244,7 @@ int strbuf_sprintf(char **buf, size_t *size, size_t *offset, const char *fmt, ..
|
||||
|
||||
if (*buf == NULL) {
|
||||
*size = 1;
|
||||
*buf = (char*) safe_malloc(*size);
|
||||
*buf = (char *) safe_malloc(*size);
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
@@ -257,7 +257,7 @@ int strbuf_sprintf(char **buf, size_t *size, size_t *offset, const char *fmt, ..
|
||||
*size += n + 1;
|
||||
else
|
||||
break;
|
||||
*buf = (char*) safe_realloc(*buf, *size);
|
||||
*buf = (char *) safe_realloc(*buf, *size);
|
||||
}
|
||||
*offset += n;
|
||||
|
||||
@@ -334,7 +334,8 @@ int addr_is_local(const union sockaddr_u *su)
|
||||
IPv6 IP address string. Since a static buffer is returned, this is
|
||||
not thread-safe and can only be used once in calls like printf()
|
||||
*/
|
||||
const char *inet_socktop(const union sockaddr_u *su) {
|
||||
const char *inet_socktop(const union sockaddr_u *su)
|
||||
{
|
||||
static char buf[INET6_ADDRSTRLEN + 1];
|
||||
void *addr;
|
||||
|
||||
@@ -449,12 +450,12 @@ int do_connect(int type)
|
||||
}
|
||||
|
||||
if (sock != -1) {
|
||||
if (connect(sock, &targetss.sockaddr, (int) targetsslen)!= -1)
|
||||
return sock;
|
||||
else if (socket_errno()==EINPROGRESS||socket_errno()==EAGAIN)
|
||||
return sock;
|
||||
if (connect(sock, &targetss.sockaddr, (int) targetsslen) != -1)
|
||||
return sock;
|
||||
else if (socket_errno() == EINPROGRESS || socket_errno() == EAGAIN)
|
||||
return sock;
|
||||
}
|
||||
return -1 ;
|
||||
return -1;
|
||||
}
|
||||
|
||||
unsigned char *buildsrcrte(struct in_addr dstaddr, struct in_addr routes[],
|
||||
@@ -574,7 +575,7 @@ int rm_fd(fd_list_t *fdl, int fd)
|
||||
/* find the max descriptor in our list */
|
||||
int get_maxfd(fd_list_t *fdl)
|
||||
{
|
||||
int x = 0, max = -1, nfds = fdl->nfds;
|
||||
int x = 0, max = -1, nfds = fdl->nfds;
|
||||
|
||||
for (x = 0; x < nfds; x++)
|
||||
if (fdl->fds[x].fd > max)
|
||||
@@ -627,7 +628,7 @@ void free_fdlist(fd_list_t *fdl)
|
||||
int fix_line_endings(char *src, int *len, char **dst, int *state)
|
||||
{
|
||||
int fix_count;
|
||||
int i,j;
|
||||
int i, j;
|
||||
int num_bytes = *len;
|
||||
int prev_state = *state;
|
||||
|
||||
@@ -638,17 +639,18 @@ int fix_line_endings(char *src, int *len, char **dst, int *state)
|
||||
/* get count of \n without matching \r */
|
||||
fix_count = 0;
|
||||
for (i = 0; i < num_bytes; i++) {
|
||||
if (src[i] == '\n' && ((i == 0) ? !prev_state : src[i-1] != '\r'))
|
||||
if (src[i] == '\n' && ((i == 0) ? !prev_state : src[i - 1] != '\r'))
|
||||
fix_count++;
|
||||
}
|
||||
if (fix_count <= 0 ) return 0;
|
||||
if (fix_count <= 0)
|
||||
return 0;
|
||||
|
||||
/* now insert matching \r */
|
||||
*dst = (char *) safe_malloc(num_bytes + fix_count);
|
||||
j = 0;
|
||||
|
||||
for (i = 0; i < num_bytes; i++) {
|
||||
if (src[i] == '\n' && ((i == 0) ? !prev_state : src[i-1] != '\r')) {
|
||||
if (src[i] == '\n' && ((i == 0) ? !prev_state : src[i - 1] != '\r')) {
|
||||
memcpy(*dst + j, "\r\n", 2);
|
||||
j += 2;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user