#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include <termios.h>
#include <sys/utsname.h>
#include <sys/param.h>
#include <arpa/telnet.h>
#include <osmocom/vty/vty.h>
#include <osmocom/vty/command.h>
#include <osmocom/vty/buffer.h>
#include <osmocom/core/talloc.h>
#define SYSCONFDIR "/usr/local/etc"
/* our callback, located in telnet_interface.c */
void vty_event(enum event event, int sock, struct vty *vty);
extern struct host host;
/* Vector which store each vty structure. */
static vector vtyvec;
vector Vvty_serv_thread;
char *vty_cwd = NULL;
/* Configure lock. */
static int vty_config;
static int no_password_check = 1;
void *tall_vty_ctx;
static void vty_clear_buf(struct vty *vty)
{
memset(vty->buf, 0, vty->max);
}
/* Allocate new vty struct. */
struct vty *vty_new(void)
{
struct vty *new = talloc_zero(tall_vty_ctx, struct vty);
if (!new)
goto out;
new->obuf = buffer_new(new, 0); /* Use default buffer size. */
if (!new->obuf)
goto out_new;
new->buf = _talloc_zero(new, VTY_BUFSIZ, "vty_new->buf");
if (!new->buf)
goto out_obuf;
new->max = VTY_BUFSIZ;
return new;
out_obuf:
buffer_free(new->obuf);
out_new:
talloc_free(new);
new = NULL;
out:
return new;
}
/* Authentication of vty */
static void vty_auth(struct vty *vty, char *buf)
{
char *passwd = NULL;
enum node_type next_node = 0;
int fail;
char *crypt(const char *, const char *);
switch (vty->node) {
case AUTH_NODE:
#ifdef VTY_CRYPT_PW
if (host.encrypt)
passwd = host.password_encrypt;
else
#endif
passwd = host.password;
if (host.advanced)
next_node = host.enable ? VIEW_NODE : ENABLE_NODE;
else
next_node = VIEW_NODE;
break;
case AUTH_ENABLE_NODE:
#ifdef VTY_CRYPT_PW
if (host.encrypt)
passwd = host.enable_encrypt;
else
#endif
passwd = host.enable;
next_node = ENABLE_NODE;
break;
}
if (passwd) {
#ifdef VTY_CRYPT_PW
if (host.encrypt)
fail = strcmp(crypt(buf, passwd), passwd);
else
#endif
fail = strcmp(buf, passwd);
} else
fail = 1;
if (!fail) {
vty->fail = 0;
vty->node = next_node; /* Success ! */
} else {
vty->fail++;
if (vty->fail >= 3) {
if (vty->node == AUTH_NODE) {
vty_out(vty,
"%% Bad passwords, too many failures!%s",
VTY_NEWLINE);
vty->status = VTY_CLOSE;
} else {
/* AUTH_ENABLE_NODE */
vty->fail = 0;
vty_out(vty,
"%% Bad enable passwords, too many failures!%s",
VTY_NEWLINE);
vty->node = VIEW_NODE;
}
}
}
}
/* Close vty interface. */
void vty_close(struct vty *vty)
{
int i;
if (vt
|