136285Sbrian/*-
236285Sbrian * Copyright (c) 1998 Brian Somers <brian@Awfulhak.org>
336285Sbrian * All rights reserved.
436285Sbrian *
536285Sbrian * Redistribution and use in source and binary forms, with or without
636285Sbrian * modification, are permitted provided that the following conditions
736285Sbrian * are met:
836285Sbrian * 1. Redistributions of source code must retain the above copyright
936285Sbrian *    notice, this list of conditions and the following disclaimer.
1036285Sbrian * 2. Redistributions in binary form must reproduce the above copyright
1136285Sbrian *    notice, this list of conditions and the following disclaimer in the
1236285Sbrian *    documentation and/or other materials provided with the distribution.
1336285Sbrian *
1436285Sbrian * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1536285Sbrian * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1636285Sbrian * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1736285Sbrian * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1836285Sbrian * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1936285Sbrian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2036285Sbrian * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2136285Sbrian * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2236285Sbrian * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2336285Sbrian * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2436285Sbrian * SUCH DAMAGE.
2536285Sbrian *
2650479Speter * $FreeBSD$
2736285Sbrian */
2836285Sbrian
2936285Sbrian#define LOCAL_AUTH	0x01
3036285Sbrian#define LOCAL_NO_AUTH	0x02
3136285Sbrian#define LOCAL_DENY	0x03
3236285Sbrian#define LOCAL_CX	0x04	/* OR'd value - require a context */
3336285Sbrian#define LOCAL_CX_OPT	0x08	/* OR'd value - optional context */
3436285Sbrian
3536285Sbrianstruct server;
3636285Sbrianstruct datalink;
3736285Sbrianstruct bundle;
3836285Sbrianstruct cmdargs;
3936285Sbrian
4036285Sbrianstruct prompt {
4158028Sbrian  struct fdescriptor desc;
4236285Sbrian  int fd_in, fd_out;
4336285Sbrian  struct datalink *TermMode;	/* The modem we're talking directly to */
4436285Sbrian  FILE *Term;			/* sits on top of fd_out */
4536285Sbrian  u_char auth;			/* Local Authorized status */
4636285Sbrian  struct server *owner;         /* who created me */
4736285Sbrian  struct bundle *bundle;	/* who I'm controlling */
4836285Sbrian  unsigned nonewline : 1;	/* need a newline before our prompt ? */
4936285Sbrian  unsigned needprompt : 1;	/* Show a prompt at the next UpdateSet() */
5036285Sbrian  unsigned active : 1;		/* Is the prompt active (^Z) */
5137010Sbrian  unsigned readtilde : 1;	/* We've read a ``~'' from fd_in */
5236285Sbrian
5336285Sbrian  struct {
5436285Sbrian    const char *type;		/* Type of connection */
5536285Sbrian    char from[40];		/* Source of connection */
5636285Sbrian  } src;
5736285Sbrian
5836314Sbrian  struct prompt *next;		/* Maintained in log.c */
5936285Sbrian  u_long logmask;		/* Maintained in log.c */
6036285Sbrian
6136285Sbrian  struct termios oldtio;	/* Original tty mode */
6236285Sbrian  struct termios comtio;	/* Command level tty mode */
6336285Sbrian};
6436285Sbrian
6536285Sbrian#define descriptor2prompt(d) \
6636285Sbrian  ((d)->type == PROMPT_DESCRIPTOR ? (struct prompt *)(d) : NULL)
6736285Sbrian
6836285Sbrian#define PROMPT_STD (-1)
6936285Sbrianextern struct prompt *prompt_Create(struct server *, struct bundle *, int);
7036285Sbrianextern void prompt_Destroy(struct prompt *, int);
7136285Sbrianextern void prompt_Required(struct prompt *);
7236285Sbrian#ifdef __GNUC__
7336285Sbrianextern void prompt_Printf(struct prompt *, const char *, ...)
7436285Sbrian                          __attribute__ ((format (printf, 2, 3)));
7536285Sbrian#else
7636285Sbrianextern void prompt_Printf(struct prompt *, const char *, ...);
7736285Sbrian#endif
7879087Skris#ifdef __GNUC__
79102500Sbrianextern void prompt_vPrintf(struct prompt *, const char *, va_list)
8079087Skris			   __attribute__ ((format (printf, 2, 0)));
8179087Skris#else
82102500Sbrianextern void prompt_vPrintf(struct prompt *, const char *, va_list);
8379087Skris#endif
8436285Sbrian#define PROMPT_DONT_WANT_INT 1
8536285Sbrian#define PROMPT_WANT_INT 0
8636285Sbrianextern void prompt_TtyInit(struct prompt *);
8736285Sbrianextern void prompt_TtyCommandMode(struct prompt *);
8836285Sbrianextern void prompt_TtyTermMode(struct prompt *, struct datalink *);
8936285Sbrianextern void prompt_TtyOldMode(struct prompt *);
9036285Sbrianextern pid_t prompt_pgrp(struct prompt *);
9136285Sbrianextern int PasswdCommand(struct cmdargs const *);
9236285Sbrianextern void prompt_Suspend(struct prompt *);
9336285Sbrianextern void prompt_Continue(struct prompt *);
9436285Sbrian#define prompt_IsTermMode(p, dl) ((p)->TermMode == (dl) ? 1 : 0)
9536285Sbrian#define prompt_IsController(p) (!(p) || (p)->owner ? 0 : 1)
9636285Sbrian#define prompt_Required(p) ((p)->needprompt = 1)
97