cmd.c revision 8e6a2a040587479821d1e682a28bcef7e75f19a6
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/*
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * CDDL HEADER START
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo *
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * The contents of this file are subject to the terms of the
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Common Development and Distribution License (the "License").
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * You may not use this file except in compliance with the License.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo *
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * or http://www.opensolaris.org/os/licensing.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * See the License for the specific language governing permissions
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * and limitations under the License.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo *
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * When distributing Covered Code, include this CDDL HEADER in each
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * If applicable, add the following below this CDDL HEADER, with the
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * fields enclosed by brackets "[]" replaced with your own identifying
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * information: Portions Copyright [yyyy] [name of copyright owner]
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo *
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * CDDL HEADER END
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/*
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Use is subject to license terms.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#pragma ident "%Z%%M% %I% %E% SMI"
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/*
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Vntsd handles two types of special commands, one is telnet
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * commands and another is vntsd special commands.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * telnet commands supported are:
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * WILL
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * WONT
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * DO
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * DONT
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * TEL_ECHO
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * SUPRESS
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * LINEMODE
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * BRK
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * AYT
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * HT
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo *
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * Vntsd special commands are:
8e6a2a040587479821d1e682a28bcef7e75f19a6lm * Send break (~#)
8e6a2a040587479821d1e682a28bcef7e75f19a6lm * Exit (~.)
8e6a2a040587479821d1e682a28bcef7e75f19a6lm * Force write access (~w)
8e6a2a040587479821d1e682a28bcef7e75f19a6lm * Console next (~n)
8e6a2a040587479821d1e682a28bcef7e75f19a6lm * Console previous (~p)
8e6a2a040587479821d1e682a28bcef7e75f19a6lm * Help (~?)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#include <stdio.h>
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#include <stdlib.h>
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#include <string.h>
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#include <unistd.h>
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#include <sys/types.h>
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#include <sys/socket.h>
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#include <netinet/in.h>
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#include <thread.h>
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#include <ctype.h>
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#include <sys/termio.h>
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#include <libintl.h>
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#include <syslog.h>
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#include "vntsd.h"
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo#include "chars.h"
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppochar vntsd_eol[] = { CR, LF, 0};
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppotypedef int (*e_func_t)(vntsd_client_t *clientp);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* structure for daemon special cmd */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppotypedef struct {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo char e_char; /* char to match on */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo char *e_help; /* help string */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo e_func_t e_func; /* command */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo} esctable_t;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* genbrk() - send a break to vcc driver */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppostatic int
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppogenbrk(vntsd_client_t *clientp)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo{
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo vntsd_cons_t *consp;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo assert(clientp);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo assert(clientp->cons);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo consp = clientp->cons;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo D1(stderr, "t@%d genbrk fd=%d sockfd %d\n", thr_self(),
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo consp->vcc_fd, clientp->sockfd);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo assert(consp->clientpq != NULL);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (consp->clientpq->handle != clientp) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* reader */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (vntsd_write_line(clientp,
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo gettext(VNTSD_NO_WRITE_ACCESS_MSG)));
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo }
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* writer */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (ioctl(consp->vcc_fd, TCSBRK, NULL)) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (VNTSD_ERR_VCC_IOCTL);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo }
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (VNTSD_STATUS_CONTINUE);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo}
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/*
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * console_forward() - cycle client to the next console
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * in the group queue.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppostatic int
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppoconsole_forward(void)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo{
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (VNTSD_STATUS_MOV_CONS_FORWARD);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo}
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/*
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * console_backward() - cycle client to the previous
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * console in the group queue.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppostatic int
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppoconsole_backward(void)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo{
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (VNTSD_STATUS_MOV_CONS_BACKWARD);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo}
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* acquire_write() - acquire write access to a console. */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppostatic int
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppoacquire_write(vntsd_client_t *clientp)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo{
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo int rv;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo int yes_no = 1;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo vntsd_cons_t *consp;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo assert(clientp);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo consp = clientp->cons;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo assert(consp);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (consp->clientpq->handle == clientp) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* client is a writer */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((rv = vntsd_write_line(clientp,
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo gettext("You have write permission"))) !=
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo VNTSD_SUCCESS) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (rv);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo }
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (VNTSD_STATUS_CONTINUE);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo }
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* message to client */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((rv = vntsd_write_client(clientp, vntsd_eol, VNTSD_EOL_LEN))
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo != VNTSD_SUCCESS) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (rv);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo }
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /*
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * TRANSLATION_NOTE
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * The following string should be formatted to fit on multiple lines
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * assuming a line width of at most 78 characters. There must be no
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * trailing newline.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((rv = vntsd_write_lines(clientp,
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo gettext("Warning: another user currently "
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo "has write permission\nto this console and forcibly removing "
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo "him/her will terminate\nany current write action and all work "
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo "will be lost."))) != VNTSD_SUCCESS) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (rv);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo }
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* get client yes no */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((rv = vntsd_write_client(clientp, vntsd_eol,
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo VNTSD_EOL_LEN)) != VNTSD_SUCCESS) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (rv);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo }
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((rv = vntsd_get_yes_no(clientp,
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo gettext("Would you like to continue?"),
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo &yes_no)) != VNTSD_SUCCESS) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (rv);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo }
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (yes_no == B_FALSE) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* client change mind no need to acquire write access */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (VNTSD_STATUS_CONTINUE);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo }
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (VNTSD_STATUS_ACQUIRE_WRITER);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo}
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* client_exit() - disconnect client from the console. */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppostatic int
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppoclient_exit(void)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo{
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (VNTSD_STATUS_RESELECT_CONS);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo}
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppostatic int daemon_cmd_help(vntsd_client_t *clientp);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* table for daemon commands */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppostatic esctable_t etable[] = {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* send a break to vcc */
8e6a2a040587479821d1e682a28bcef7e75f19a6lm {'#', "Send break", genbrk},
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* exit */
8e6a2a040587479821d1e682a28bcef7e75f19a6lm {'.', "Exit from this console", (e_func_t)client_exit},
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* acquire write access */
8e6a2a040587479821d1e682a28bcef7e75f19a6lm {'w', "Force write access", acquire_write},
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* connect to next console in queue */
8e6a2a040587479821d1e682a28bcef7e75f19a6lm {'n', "Console next", (e_func_t)console_forward},
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* connect to previous console in queue */
8e6a2a040587479821d1e682a28bcef7e75f19a6lm {'p', "Console previous", (e_func_t)console_backward},
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* help must be next to last */
8e6a2a040587479821d1e682a28bcef7e75f19a6lm {'?', "Help", daemon_cmd_help},
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* table terminator */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo {0, 0, 0}
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo};
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppovoid
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppovntsd_init_esctable_msgs(void)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo{
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo esctable_t *p;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo for (p = etable; p->e_char != '\0'; p++) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo p->e_help = gettext(p->e_help);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo }
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo}
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* daemon_cmd_help() - print help. */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppostatic int
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppodaemon_cmd_help(vntsd_client_t *clientp)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo{
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo esctable_t *p;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo int rv;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo char buf[VNTSD_LINE_LEN];
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((rv = vntsd_write_client(clientp, vntsd_eol,
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo VNTSD_EOL_LEN)) != VNTSD_SUCCESS) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (rv);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo }
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /*
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * TRANSLATION_NOTE
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * VNTSD is the name of the VNTS daemon and should not be translated.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((rv = vntsd_write_line(clientp, gettext("VNTSD commands"))) !=
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo VNTSD_SUCCESS) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (rv);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo }
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo for (p = etable; p->e_char; p++) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo (void) snprintf(buf, sizeof (buf),
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo "~%c --%s", p->e_char, p->e_help);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((rv = vntsd_write_line(clientp, buf)) != VNTSD_SUCCESS) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (rv);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo }
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo }
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (VNTSD_STATUS_CONTINUE);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo}
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* exit from daemon command */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppostatic int
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppoexit_daemon_cmd(vntsd_client_t *clientp, int rv)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo{
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo (void) mutex_lock(&clientp->lock);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo clientp->status &= ~VNTSD_CLIENT_DISABLE_DAEMON_CMD;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo (void) mutex_unlock(&clientp->lock);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (rv);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo}
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* vntsd_process_daemon_cmd() - special commands */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppoint
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppovntsd_process_daemon_cmd(vntsd_client_t *clientp, char c)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo{
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo esctable_t *p;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo int rv;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (c != VNTSD_DAEMON_CMD) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* not a daemon command */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (VNTSD_SUCCESS);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo }
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (clientp->status & VNTSD_CLIENT_DISABLE_DAEMON_CMD) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (VNTSD_STATUS_CONTINUE);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo }
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* no reentry to process_daemon_cmd */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo (void) mutex_lock(&clientp->lock);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo clientp->status |= VNTSD_CLIENT_DISABLE_DAEMON_CMD;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo (void) mutex_unlock(&clientp->lock);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo D3(stderr, "t@%d process_daemon_cmd %d %d \n", thr_self(),
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo clientp->cons->vcc_fd, clientp->sockfd);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* read in command */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((rv = vntsd_read_char(clientp, &c)) != VNTSD_SUCCESS) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (exit_daemon_cmd(clientp, rv));
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo }
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo for (p = etable; p->e_char; p++) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (p->e_char == c) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* found match */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo assert(p->e_func);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo rv = (*p->e_func)(clientp);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (exit_daemon_cmd(clientp, rv));
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo }
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo }
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* no match, print out the help */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo p--;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo assert(p->e_char == '?');
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo rv = (*p->e_func)(clientp);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (exit_daemon_cmd(clientp, rv));
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo}
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* vntsd_set_telnet_options() - change telnet client to character mode. */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppoint
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppovntsd_set_telnet_options(int fd)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo{
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* set client telnet options */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo uint8_t buf[] = {IAC, DONT, LINEMODE, IAC, WILL, SUPRESS, IAC, WILL,
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo TEL_ECHO, IAC, DONT, TERM_TYPE, IAC, DONT, TERM_SP,
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo IAC, DONT, STATUS, IAC, DONT, FC, IAC, DONT, TM, IAC, DONT, ENV,
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo IAC, DONT, WIN_SIZE};
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (vntsd_write_fd(fd, (char *)buf, 30));
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo}
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/* vntsd_telnet_cmd() process telnet commands */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppoint
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppovntsd_telnet_cmd(vntsd_client_t *clientp, char c)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo{
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo uint8_t buf[4];
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo char cmd;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo int rv = VNTSD_STATUS_CONTINUE;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo bzero(buf, 4);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((uint8_t)c != IAC) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* not telnet cmd */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (VNTSD_SUCCESS);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo }
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((rv = vntsd_read_char(clientp, &cmd)) != VNTSD_SUCCESS) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (rv);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo }
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((rv = vntsd_read_char(clientp, &c)) != VNTSD_SUCCESS) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (rv);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo }
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo switch ((uint8_t)cmd) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo case WILL:
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo switch ((uint8_t)c) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo case TEL_ECHO:
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo case SUPRESS:
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo case LINEMODE:
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo break;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo default:
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo syslog(LOG_ERR, "not support telnet WILL %x\n", c);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo break;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo }
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo break;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo case WONT:
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo switch ((uint8_t)c) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo case TEL_ECHO:
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo case SUPRESS:
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo case LINEMODE:
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo default:
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo syslog(LOG_ERR, "not support telnet WONT %x\n", c);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo break;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo }
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo break;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo case DO:
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo case DONT:
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo buf[0] = IAC;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo buf[1] = WILL;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo buf[2] = c;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo rv = vntsd_write_client(clientp, (char *)buf, 3);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo break;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo case BRK:
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* send break to vcc */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo rv = genbrk(clientp);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo break;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo case IP:
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo break;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo case AYT:
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo rv = vntsd_write_client(clientp, &c, 1);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo break;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo case HT:
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (VNTSD_STATUS_CONTINUE);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo default:
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo syslog(LOG_ERR, "not support telnet ctrl %x\n", c);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo break;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo }
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (rv == VNTSD_SUCCESS) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (VNTSD_STATUS_CONTINUE);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo } else {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (rv);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo }
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo}
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo/*
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * vntsd_ctrl_cmd() - control keys
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo * read and write suspend are supported.
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppoint
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppovntsd_ctrl_cmd(vntsd_client_t *clientp, char c)
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo{
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo int cmd;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo D3(stderr, "t@%d vntsd_ctrl_cmd%d %d\n", thr_self(),
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo clientp->cons->vcc_fd, clientp->sockfd);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if ((c != START) && (c != STOP)) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* not a supported control command */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (VNTSD_SUCCESS);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo }
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (c == START) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo D3(stderr, "t@%d client restart\n", thr_self());
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* send resume read */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo cmd = 1;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (ioctl(clientp->cons->vcc_fd, TCXONC, &cmd)) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (VNTSD_STATUS_VCC_IO_ERR);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo }
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* send resume write */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo cmd = 3;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (ioctl(clientp->cons->vcc_fd, TCXONC, &cmd)) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (VNTSD_STATUS_VCC_IO_ERR);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo }
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo }
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (c == STOP) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo D3(stderr, "t@%d client suspend\n", thr_self());
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* send suspend read */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo cmd = 0;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (ioctl(clientp->cons->vcc_fd, TCXONC, &cmd)) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (VNTSD_STATUS_VCC_IO_ERR);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo }
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo /* send suspend write */
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo cmd = 2;
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo if (ioctl(clientp->cons->vcc_fd, TCXONC, &cmd)) {
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo perror("ioctl TCXONC");
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (VNTSD_STATUS_VCC_IO_ERR);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo }
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo }
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo return (VNTSD_STATUS_CONTINUE);
1ae0874509b6811fdde1dfd46f0d93fd09867a3fheppo}