version 1.1.1.2, 2013/07/22 08:44:29
|
version 1.1.1.5, 2021/03/17 00:39:23
|
Line 58
|
Line 58
|
static int ConsoleUserHashEqual(struct ghash *g, const void *item1, |
static int ConsoleUserHashEqual(struct ghash *g, const void *item1, |
const void *item2); |
const void *item2); |
static u_int32_t ConsoleUserHash(struct ghash *g, const void *item); |
static u_int32_t ConsoleUserHash(struct ghash *g, const void *item); |
static int ConsoleSetCommand(Context ctx, int ac, char *av[], void *arg); | static int ConsoleSetCommand(Context ctx, int ac, const char *const av[], const void *arg); |
|
|
|
|
/* |
/* |
Line 76
|
Line 76
|
ConsoleSetCommand, NULL, 0, (void *) SET_ENABLE }, |
ConsoleSetCommand, NULL, 0, (void *) SET_ENABLE }, |
{ "disable [opt ...]", "Disable this console option" , |
{ "disable [opt ...]", "Disable this console option" , |
ConsoleSetCommand, NULL, 0, (void *) SET_DISABLE }, |
ConsoleSetCommand, NULL, 0, (void *) SET_DISABLE }, |
{ NULL }, | { NULL, NULL, NULL, NULL, 0, NULL }, |
}; |
}; |
|
|
struct ghash *gUsers; /* allowed users */ |
struct ghash *gUsers; /* allowed users */ |
Line 87
|
Line 87
|
*/ |
*/ |
|
|
static const struct confinfo gConfList[] = { |
static const struct confinfo gConfList[] = { |
|
{ 0, CONSOLE_AUTH, "auth" }, |
|
{ 0, 0, NULL }, |
|
}; |
|
|
|
static const struct confinfo sConfList[] = { |
{ 0, CONSOLE_LOGGING, "logging" }, |
{ 0, CONSOLE_LOGGING, "logging" }, |
{ 0, 0, NULL }, |
{ 0, 0, NULL }, |
}; |
}; |
|
|
struct termios gOrigTermiosAttrs; | static struct termios gOrigTermiosAttrs; |
int gOrigFlags; | static int gOrigFlags; |
|
|
/* |
/* |
* ConsoleInit() |
* ConsoleInit() |
Line 107 ConsoleInit(Console c)
|
Line 112 ConsoleInit(Console c)
|
memset(&gConsole, 0, sizeof(gConsole)); |
memset(&gConsole, 0, sizeof(gConsole)); |
ParseAddr(DEFAULT_CONSOLE_IP, &c->addr, ALLOW_IPV4|ALLOW_IPV6); |
ParseAddr(DEFAULT_CONSOLE_IP, &c->addr, ALLOW_IPV4|ALLOW_IPV6); |
c->port = DEFAULT_CONSOLE_PORT; |
c->port = DEFAULT_CONSOLE_PORT; |
|
Enable(&c->options, CONSOLE_AUTH); |
|
|
SLIST_INIT(&c->sessions); |
SLIST_INIT(&c->sessions); |
|
|
Line 169 ConsoleClose(Console c)
|
Line 175 ConsoleClose(Console c)
|
return 0; |
return 0; |
} |
} |
|
|
|
void |
|
ConsoleCancelCleanup(void *rwlock) NO_THREAD_SAFETY_ANALYSIS |
|
{ |
|
pthread_rwlock_t p = (pthread_rwlock_t)rwlock; |
|
|
|
RWLOCK_UNLOCK(p); |
|
} |
|
|
/* |
/* |
* ConsoleStat() |
* ConsoleStat() |
*/ |
*/ |
|
|
int |
int |
ConsoleStat(Context ctx, int ac, char *av[], void *arg) | ConsoleStat(Context ctx, int ac, const char *const av[], const void *arg) |
| NO_THREAD_SAFETY_ANALYSIS |
{ |
{ |
Console c = &gConsole; |
Console c = &gConsole; |
ConsoleSession s; |
ConsoleSession s; |
ConsoleSession cs = ctx->cs; |
ConsoleSession cs = ctx->cs; |
char addrstr[INET6_ADDRSTRLEN]; |
char addrstr[INET6_ADDRSTRLEN]; |
|
|
|
(void)ac; |
|
(void)av; |
|
(void)arg; |
|
|
Printf("Configuration:\r\n"); |
Printf("Configuration:\r\n"); |
Printf("\tState : %s\r\n", c->fd ? "OPENED" : "CLOSED"); |
Printf("\tState : %s\r\n", c->fd ? "OPENED" : "CLOSED"); |
Printf("\tIP-Address : %s\r\n", u_addrtoa(&c->addr,addrstr,sizeof(addrstr))); |
Printf("\tIP-Address : %s\r\n", u_addrtoa(&c->addr,addrstr,sizeof(addrstr))); |
Printf("\tPort : %d\r\n", c->port); |
Printf("\tPort : %d\r\n", c->port); |
|
|
|
pthread_cleanup_push(ConsoleCancelCleanup, c->lock); |
RWLOCK_RDLOCK(c->lock); |
RWLOCK_RDLOCK(c->lock); |
Printf("Active sessions:\r\n"); |
Printf("Active sessions:\r\n"); |
SLIST_FOREACH(s, &c->sessions, next) { |
SLIST_FOREACH(s, &c->sessions, next) { |
Printf("\tUsername: %s\tFrom: %s\r\n", |
Printf("\tUsername: %s\tFrom: %s\r\n", |
s->user.username, u_addrtoa(&s->peer_addr,addrstr,sizeof(addrstr))); |
s->user.username, u_addrtoa(&s->peer_addr,addrstr,sizeof(addrstr))); |
} |
} |
RWLOCK_UNLOCK(c->lock); | pthread_cleanup_pop(1); |
|
|
|
Printf("Global options:\r\n"); |
|
OptStat(ctx, &c->options, gConfList); |
if (cs) { |
if (cs) { |
Printf("This session options:\r\n"); |
Printf("This session options:\r\n"); |
OptStat(ctx, &cs->options, gConfList); | OptStat(ctx, &cs->options, sConfList); |
} |
} |
return 0; |
return 0; |
} |
} |
Line 217 ConsoleConnect(int type, void *cookie)
|
Line 239 ConsoleConnect(int type, void *cookie)
|
"\xFF\xFD\x01"; /* DO echo */ |
"\xFF\xFD\x01"; /* DO echo */ |
char addrstr[INET6_ADDRSTRLEN]; |
char addrstr[INET6_ADDRSTRLEN]; |
struct sockaddr_storage ss; |
struct sockaddr_storage ss; |
| |
| (void)type; |
Log(LG_CONSOLE, ("CONSOLE: Connect")); |
Log(LG_CONSOLE, ("CONSOLE: Connect")); |
cs = Malloc(MB_CONS, sizeof(*cs)); |
cs = Malloc(MB_CONS, sizeof(*cs)); |
if ((cs->fd = TcpAcceptConnection(c->fd, &ss, FALSE)) < 0) |
if ((cs->fd = TcpAcceptConnection(c->fd, &ss, FALSE)) < 0) |
Line 233 ConsoleConnect(int type, void *cookie)
|
Line 256 ConsoleConnect(int type, void *cookie)
|
cs->write = ConsoleSessionWrite; |
cs->write = ConsoleSessionWrite; |
cs->writev = ConsoleSessionWriteV; |
cs->writev = ConsoleSessionWriteV; |
cs->prompt = ConsoleSessionShowPrompt; |
cs->prompt = ConsoleSessionShowPrompt; |
cs->state = STATE_USERNAME; | if (!Enabled(&c->options, CONSOLE_AUTH)) { |
| cs->state = STATE_AUTHENTIC; |
| strcpy(cs->user.username, "root"); |
| cs->context.priv = 2; |
| } else { |
| cs->state = STATE_USERNAME; |
| } |
cs->context.cs = cs; |
cs->context.cs = cs; |
RWLOCK_WRLOCK(c->lock); |
RWLOCK_WRLOCK(c->lock); |
SLIST_INSERT_HEAD(&c->sessions, cs, next); |
SLIST_INSERT_HEAD(&c->sessions, cs, next); |
Line 369 ConsoleSessionReadEvent(int type, void *cookie)
|
Line 398 ConsoleSessionReadEvent(int type, void *cookie)
|
char *av_copy[MAX_CONSOLE_ARGS]; |
char *av_copy[MAX_CONSOLE_ARGS]; |
char addrstr[INET6_ADDRSTRLEN]; |
char addrstr[INET6_ADDRSTRLEN]; |
|
|
|
(void)type; |
while(1) { |
while(1) { |
if ((n = read(cs->fd, &c, 1)) <= 0) { |
if ((n = read(cs->fd, &c, 1)) <= 0) { |
if (n < 0) { |
if (n < 0) { |
Line 589 success:
|
Line 619 success:
|
cs->context.lnk ? cs->context.lnk->name : |
cs->context.lnk ? cs->context.lnk->name : |
(cs->context.bund? cs->context.bund->name : ""), |
(cs->context.bund? cs->context.bund->name : ""), |
cs->user.username, cs->cmd)); |
cs->user.username, cs->cmd)); |
DoCommand(&cs->context, ac, av, NULL, 0); | DoCommand(&cs->context, ac, (const char *const *)av, NULL, 0); |
} else { |
} else { |
HelpCommand(&cs->context, ac, av, NULL); | HelpCommand(&cs->context, ac, (const char *const *)av, NULL); |
} |
} |
FreeArgs(ac, av_copy); |
FreeArgs(ac, av_copy); |
if (cs->exit) |
if (cs->exit) |
Line 696 StdConsoleSessionWrite(ConsoleSession cs, const char *
|
Line 726 StdConsoleSessionWrite(ConsoleSession cs, const char *
|
static void |
static void |
StdConsoleSessionWriteV(ConsoleSession cs, const char *fmt, va_list vl) |
StdConsoleSessionWriteV(ConsoleSession cs, const char *fmt, va_list vl) |
{ |
{ |
|
(void)cs; |
vprintf(fmt, vl); |
vprintf(fmt, vl); |
fflush(stdout); |
fflush(stdout); |
} |
} |
Line 742 ConsoleSessionShowPrompt(ConsoleSession cs)
|
Line 773 ConsoleSessionShowPrompt(ConsoleSession cs)
|
static u_int32_t |
static u_int32_t |
ConsoleUserHash(struct ghash *g, const void *item) |
ConsoleUserHash(struct ghash *g, const void *item) |
{ |
{ |
ConsoleUser u = (ConsoleUser) item; | const struct console_user *u = (const struct console_user *) item; |
u_char *s = (u_char *) u->username; | const u_char *s = (const u_char *) u->username; |
u_int32_t hash = 0x811c9dc5; |
u_int32_t hash = 0x811c9dc5; |
|
|
|
(void)g; |
while (*s) { |
while (*s) { |
hash += (hash<<1) + (hash<<4) + (hash<<7) + (hash<<8) + (hash<<24); |
hash += (hash<<1) + (hash<<4) + (hash<<7) + (hash<<8) + (hash<<24); |
/* xor the bottom with the current octet */ |
/* xor the bottom with the current octet */ |
Line 762 ConsoleUserHash(struct ghash *g, const void *item)
|
Line 794 ConsoleUserHash(struct ghash *g, const void *item)
|
static int |
static int |
ConsoleUserHashEqual(struct ghash *g, const void *item1, const void *item2) |
ConsoleUserHashEqual(struct ghash *g, const void *item1, const void *item2) |
{ |
{ |
ConsoleUser u1 = (ConsoleUser) item1; | const struct console_user *u1 = (const struct console_user *) item1; |
ConsoleUser u2 = (ConsoleUser) item2; | const struct console_user *u2 = (const struct console_user *) item2; |
|
|
|
(void)g; |
if (u1 && u2) |
if (u1 && u2) |
return (strcmp(u1->username, u2->username) == 0); |
return (strcmp(u1->username, u2->username) == 0); |
else |
else |
Line 776 ConsoleUserHashEqual(struct ghash *g, const void *item
|
Line 809 ConsoleUserHashEqual(struct ghash *g, const void *item
|
*/ |
*/ |
|
|
static int |
static int |
ConsoleSetCommand(Context ctx, int ac, char *av[], void *arg) | ConsoleSetCommand(Context ctx, int ac, const char *const av[], const void *arg) |
{ |
{ |
Console c = &gConsole; |
Console c = &gConsole; |
ConsoleSession cs = ctx->cs; |
ConsoleSession cs = ctx->cs; |
Line 793 ConsoleSetCommand(Context ctx, int ac, char *av[], voi
|
Line 826 ConsoleSetCommand(Context ctx, int ac, char *av[], voi
|
break; |
break; |
|
|
case SET_ENABLE: |
case SET_ENABLE: |
if (cs) | if (cs) { |
EnableCommand(ac, av, &cs->options, gConfList); | if (strcmp(av[0], "auth") != 0) |
| EnableCommand(ac, av, &cs->options, sConfList); |
| } else |
| EnableCommand(ac, av, &c->options, gConfList); |
break; |
break; |
|
|
case SET_DISABLE: |
case SET_DISABLE: |
if (cs) | if (cs) { |
DisableCommand(ac, av, &cs->options, gConfList); | if (strcmp(av[0], "auth") != 0) |
| DisableCommand(ac, av, &cs->options, sConfList); |
| } else |
| DisableCommand(ac, av, &c->options, gConfList); |
break; |
break; |
|
|
case SET_SELF: |
case SET_SELF: |
Line 845 ConsoleShutdown(Console c)
|
Line 884 ConsoleShutdown(Console c)
|
*/ |
*/ |
|
|
int |
int |
UserCommand(Context ctx, int ac, char *av[], void *arg) | UserCommand(Context ctx, int ac, const char *const av[], const void *arg) |
{ |
{ |
ConsoleUser u; |
ConsoleUser u; |
|
|
|
(void)arg; |
|
(void)ctx; |
|
|
if (ac < 2 || ac > 3) |
if (ac < 2 || ac > 3) |
return(-1); |
return(-1); |
|
|
Line 879 UserCommand(Context ctx, int ac, char *av[], void *arg
|
Line 921 UserCommand(Context ctx, int ac, char *av[], void *arg
|
*/ |
*/ |
|
|
int |
int |
UserStat(Context ctx, int ac, char *av[], void *arg) | UserStat(Context ctx, int ac, const char *const av[], const void *arg) |
| NO_THREAD_SAFETY_ANALYSIS |
{ |
{ |
struct ghash_walk walk; |
struct ghash_walk walk; |
ConsoleUser u; |
ConsoleUser u; |
|
|
|
(void)ac; |
|
(void)av; |
|
(void)arg; |
|
|
Printf("Configured users:\r\n"); |
Printf("Configured users:\r\n"); |
|
pthread_cleanup_push(ConsoleCancelCleanup, gUsersLock); |
RWLOCK_RDLOCK(gUsersLock); |
RWLOCK_RDLOCK(gUsersLock); |
ghash_walk_init(gUsers, &walk); |
ghash_walk_init(gUsers, &walk); |
while ((u = ghash_walk_next(gUsers, &walk)) != NULL) { |
while ((u = ghash_walk_next(gUsers, &walk)) != NULL) { |
Printf("\tUsername: %-15s Priv:%s\r\n", u->username, | Printf("\tUsername: %-15s Priv: %s\r\n", u->username, |
((u->priv == 2)?"admin":((u->priv == 1)?"operator":"user"))); |
((u->priv == 2)?"admin":((u->priv == 1)?"operator":"user"))); |
} |
} |
RWLOCK_UNLOCK(gUsersLock); | pthread_cleanup_pop(1); |
|
|
return 0; |
return 0; |
} |
} |