Reformat telnetd.c
This commit is contained in:
@ -38,7 +38,8 @@
|
||||
#include <log_manager.h>
|
||||
#include <modinfo.h>
|
||||
|
||||
MODULE_INFO info = {
|
||||
MODULE_INFO info =
|
||||
{
|
||||
MODULE_API_PROTOCOL,
|
||||
MODULE_GA,
|
||||
GWPROTOCOL_VERSION,
|
||||
@ -81,7 +82,8 @@ static int telnetd_listen(DCB *dcb, char *config);
|
||||
/**
|
||||
* The "module object" for the telnetd protocol module.
|
||||
*/
|
||||
static GWPROTOCOL MyObject = {
|
||||
static GWPROTOCOL MyObject =
|
||||
{
|
||||
telnetd_read_event, /**< Read - EPOLLIN handler */
|
||||
telnetd_write, /**< Write - data from gateway */
|
||||
telnetd_write_event, /**< WriteReady - EPOLLOUT handler */
|
||||
@ -103,8 +105,7 @@ static void telnetd_echo(DCB *dcb, int enable);
|
||||
*
|
||||
* @return version string of the module
|
||||
*/
|
||||
char *
|
||||
version()
|
||||
char* version()
|
||||
{
|
||||
return version_str;
|
||||
}
|
||||
@ -113,8 +114,7 @@ version()
|
||||
* The module initialisation routine, called when the module
|
||||
* is first loaded.
|
||||
*/
|
||||
void
|
||||
ModuleInit()
|
||||
void ModuleInit()
|
||||
{
|
||||
MXS_INFO("Initialise Telnetd Protocol module.");
|
||||
}
|
||||
@ -127,8 +127,7 @@ ModuleInit()
|
||||
*
|
||||
* @return The module object
|
||||
*/
|
||||
GWPROTOCOL *
|
||||
GetModuleObject()
|
||||
GWPROTOCOL* GetModuleObject()
|
||||
{
|
||||
return &MyObject;
|
||||
}
|
||||
@ -139,8 +138,7 @@ GetModuleObject()
|
||||
* @param dcb The descriptor control block
|
||||
* @return
|
||||
*/
|
||||
static int
|
||||
telnetd_read_event(DCB* dcb)
|
||||
static int telnetd_read_event(DCB* dcb)
|
||||
{
|
||||
int n;
|
||||
GWBUF *head = NULL;
|
||||
@ -150,7 +148,6 @@ char *password, *t;
|
||||
|
||||
if ((n = dcb_read(dcb, &head, 0)) != -1)
|
||||
{
|
||||
|
||||
if (head)
|
||||
{
|
||||
unsigned char *ptr = GWBUF_DATA(head);
|
||||
@ -170,7 +167,9 @@ char *password, *t;
|
||||
/* Strip the cr/lf from the username */
|
||||
t = strstr(telnetd->username, "\r\n");
|
||||
if (t)
|
||||
{
|
||||
*t = 0;
|
||||
}
|
||||
telnetd->state = TELNETD_STATE_PASSWD;
|
||||
dcb_printf(dcb, "Password: ");
|
||||
telnetd_echo(dcb, 0);
|
||||
@ -181,7 +180,9 @@ char *password, *t;
|
||||
/* Strip the cr/lf from the username */
|
||||
t = strstr(password, "\r\n");
|
||||
if (t)
|
||||
{
|
||||
*t = 0;
|
||||
}
|
||||
if (admin_verify(telnetd->username, password))
|
||||
{
|
||||
telnetd_echo(dcb, 1);
|
||||
@ -219,8 +220,7 @@ char *password, *t;
|
||||
* @param dcb The descriptor control block
|
||||
* @return
|
||||
*/
|
||||
static int
|
||||
telnetd_write_event(DCB *dcb)
|
||||
static int telnetd_write_event(DCB *dcb)
|
||||
{
|
||||
return dcb_drain_writeq(dcb);
|
||||
}
|
||||
@ -234,8 +234,7 @@ telnetd_write_event(DCB *dcb)
|
||||
* @param dcb Descriptor Control Block for the socket
|
||||
* @param queue Linked list of buffes to write
|
||||
*/
|
||||
static int
|
||||
telnetd_write(DCB *dcb, GWBUF *queue)
|
||||
static int telnetd_write(DCB *dcb, GWBUF *queue)
|
||||
{
|
||||
int rc;
|
||||
rc = dcb_write(dcb, queue);
|
||||
@ -247,8 +246,7 @@ telnetd_write(DCB *dcb, GWBUF *queue)
|
||||
*
|
||||
* @param dcb The descriptor control block
|
||||
*/
|
||||
static int
|
||||
telnetd_error(DCB *dcb)
|
||||
static int telnetd_error(DCB *dcb)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@ -258,8 +256,7 @@ telnetd_error(DCB *dcb)
|
||||
*
|
||||
* @param dcb The descriptor control block
|
||||
*/
|
||||
static int
|
||||
telnetd_hangup(DCB *dcb)
|
||||
static int telnetd_hangup(DCB *dcb)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
@ -271,8 +268,7 @@ telnetd_hangup(DCB *dcb)
|
||||
* @param dcb The descriptor control block
|
||||
* @return The number of new connections created
|
||||
*/
|
||||
static int
|
||||
telnetd_accept(DCB *dcb)
|
||||
static int telnetd_accept(DCB *dcb)
|
||||
{
|
||||
int n_connect = 0;
|
||||
|
||||
@ -287,14 +283,15 @@ int n_connect = 0;
|
||||
so = accept(dcb->fd, (struct sockaddr *)&addr, &addrlen);
|
||||
|
||||
if (so == -1)
|
||||
{
|
||||
return n_connect;
|
||||
}
|
||||
else
|
||||
{
|
||||
atomic_add(&dcb->stats.n_accepts, 1);
|
||||
client_dcb = dcb_alloc(DCB_ROLE_REQUEST_HANDLER);
|
||||
|
||||
if (client_dcb == NULL)
|
||||
|
||||
{
|
||||
close(so);
|
||||
return n_connect;
|
||||
@ -302,8 +299,8 @@ int n_connect = 0;
|
||||
client_dcb->fd = so;
|
||||
client_dcb->remote = strdup(inet_ntoa(addr.sin_addr));
|
||||
memcpy(&client_dcb->func, &MyObject, sizeof(GWPROTOCOL));
|
||||
client_dcb->session =
|
||||
session_alloc(dcb->session->service, client_dcb);
|
||||
client_dcb->session = session_alloc(dcb->session->service, client_dcb);
|
||||
|
||||
if (NULL == client_dcb->session)
|
||||
{
|
||||
dcb_close(client_dcb);
|
||||
@ -339,13 +336,14 @@ int n_connect = 0;
|
||||
* @param dcb The descriptor control block
|
||||
*/
|
||||
|
||||
static int
|
||||
telnetd_close(DCB *dcb)
|
||||
static int telnetd_close(DCB *dcb)
|
||||
{
|
||||
TELNETD *telnetd = dcb->protocol;
|
||||
|
||||
if (telnetd && telnetd->username)
|
||||
{
|
||||
free(telnetd->username);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -356,8 +354,7 @@ TELNETD *telnetd = dcb->protocol;
|
||||
* @param listener The Listener DCB
|
||||
* @param config Configuration (ip:port)
|
||||
*/
|
||||
static int
|
||||
telnetd_listen(DCB *listener, char *config)
|
||||
static int telnetd_listen(DCB *listener, char *config)
|
||||
{
|
||||
struct sockaddr_in addr;
|
||||
int one = 1;
|
||||
@ -367,8 +364,9 @@ int syseno = 0;
|
||||
memcpy(&listener->func, &MyObject, sizeof(GWPROTOCOL));
|
||||
|
||||
if (!parse_bindconfig(config, 4442, &addr))
|
||||
{
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
if ((listener->fd = socket(AF_INET, SOCK_STREAM, 0)) < 0)
|
||||
{
|
||||
@ -378,7 +376,8 @@ int syseno = 0;
|
||||
// socket options
|
||||
syseno = setsockopt(listener->fd, SOL_SOCKET, SO_REUSEADDR, (char *)&one, sizeof(one));
|
||||
|
||||
if(syseno != 0){
|
||||
if (syseno != 0)
|
||||
{
|
||||
char errbuf[STRERROR_BUFLEN];
|
||||
MXS_ERROR("Failed to set socket options. Error %d: %s",
|
||||
errno, strerror_r(errno, errbuf, sizeof(errbuf)));
|
||||
@ -394,9 +393,12 @@ int syseno = 0;
|
||||
|
||||
rc = listen(listener->fd, SOMAXCONN);
|
||||
|
||||
if (rc == 0) {
|
||||
if (rc == 0)
|
||||
{
|
||||
MXS_NOTICE("Listening telnet connections at %s", config);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
int eno = errno;
|
||||
errno = 0;
|
||||
char errbuf[STRERROR_BUFLEN];
|
||||
@ -407,7 +409,6 @@ int syseno = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
if (poll_add_dcb(listener) == -1)
|
||||
{
|
||||
return 0;
|
||||
@ -425,8 +426,7 @@ int syseno = 0;
|
||||
* @param dcb The client DCB
|
||||
* @param cmd The command stream
|
||||
*/
|
||||
static void
|
||||
telnetd_command(DCB *dcb, unsigned char *cmd)
|
||||
static void telnetd_command(DCB *dcb, unsigned char *cmd)
|
||||
{
|
||||
}
|
||||
|
||||
@ -436,14 +436,15 @@ telnetd_command(DCB *dcb, unsigned char *cmd)
|
||||
* @param dcb DCB of the telnet connection
|
||||
* @param enable Enable or disable echo functionality
|
||||
*/
|
||||
static void
|
||||
telnetd_echo(DCB *dcb, int enable)
|
||||
static void telnetd_echo(DCB *dcb, int enable)
|
||||
{
|
||||
GWBUF *gwbuf;
|
||||
char *buf;
|
||||
|
||||
if ((gwbuf = gwbuf_alloc(3)) == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
buf = GWBUF_DATA(gwbuf);
|
||||
buf[0] = TELNET_IAC;
|
||||
buf[1] = enable ? TELNET_WONT : TELNET_WILL;
|
||||
|
Reference in New Issue
Block a user