1 /*
2  *  Copyright conserver.com, 2000
3  *
4  *  Maintainer/Enhancer: Bryan Stansell (bryan@conserver.com)
5  *
6  *  Copyright GNAC, Inc., 1998
7  */
8 
9 /*
10  * Copyright 1992 Purdue Research Foundation, West Lafayette, Indiana
11  * 47907.  All rights reserved.
12  *
13  * Written by Kevin S Braunsdorf, ksb@cc.purdue.edu, purdue!ksb
14  *
15  * This software is not subject to any license of the American Telephone
16  * and Telegraph Company or the Regents of the University of California.
17  *
18  * Permission is granted to anyone to use this software for any purpose on
19  * any computer system, and to alter it and redistribute it freely, subject
20  * to the following restrictions:
21  *
22  * 1. Neither the authors nor Purdue University are responsible for any
23  *    consequences of the use of this software.
24  *
25  * 2. The origin of this software must not be misrepresented, either by
26  *    explicit claim or by omission.  Credit to the authors and Purdue
27  *    University must appear in documentation and sources.
28  *
29  * 3. Altered versions must be plainly marked as such, and must not be
30  *    misrepresented as being the original software.
31  *
32  * 4. This notice may not be removed or altered.
33  */
34 /*
35  * Network console modifications by Robert Olson, olson@mcs.anl.gov.
36  */
37 
38 
39 /* stuff to keep track of a console entry
40  */
41 typedef struct baud {		/* a baud rate table                    */
42     char acrate[8];
43     int irate;
44 } BAUD;
45 
46 typedef struct parity {		/* a parity bits table                  */
47     char *key;
48     int iset;
49     int iclr;
50 } PARITY;
51 
52 typedef enum consType {
53     UNKNOWNTYPE = 0,
54     DEVICE,
55     EXEC,
56     HOST,
57     NOOP,
58     UDS,
59 #if HAVE_FREEIPMI
60     IPMI,
61 #endif
62 } CONSTYPE;
63 
64 #if HAVE_FREEIPMI
65 # define IPMIL_UNKNOWN  (0)
66 # define IPMIL_USER     (IPMICONSOLE_PRIVILEGE_USER+1)
67 # define IPMIL_OPERATOR (IPMICONSOLE_PRIVILEGE_OPERATOR+1)
68 # define IPMIL_ADMIN    (IPMICONSOLE_PRIVILEGE_ADMIN+1)
69 #endif
70 
71 typedef struct names {
72     char *name;
73     struct names *next;
74 } NAMES;
75 
76 typedef struct consentUsers {
77     NAMES *user;
78     short not;
79     struct consentUsers *next;
80 } CONSENTUSERS;
81 
82 /* we calloc() these things, so we're trying to make everything be
83  * "empty" when it's got a zero value
84  */
85 typedef struct consent {	/* console information                  */
86     /*** config file settings ***/
87     char *server;		/* server name                          */
88     CONSTYPE type;		/* console type                         */
89     NAMES *aliases;		/* aliases for server name              */
90     /* type == DEVICE */
91     char *device;		/* device file                          */
92     char *devicesubst;		/* device substitution pattern          */
93     BAUD *baud;			/* the baud on this console port        */
94     PARITY *parity;		/* the parity on this line              */
95     FLAG hupcl;			/* use HUPCL                            */
96     FLAG cstopb;		/* use two stop bits                    */
97     FLAG ixon;			/* XON/XOFF flow control on output      */
98     FLAG ixany;			/* any character to restart output      */
99     FLAG ixoff;			/* XON/XOFF flow control on input       */
100 #if defined(CRTSCTS)
101     FLAG crtscts;		/* use hardware flow control            */
102 #endif
103 #if HAVE_FREEIPMI
104     /* type == IPMI */
105     int ipmiprivlevel;		/* IPMI authentication level            */
106     ipmiconsole_ctx_t ipmictx;	/* IPMI ctx                             */
107     unsigned int ipmiworkaround;	/* IPMI workaround flags                */
108     short ipmiwrkset;		/* workaround flags set in config       */
109     int ipmiciphersuite;	/* IPMI cipher suite                    */
110     char *username;		/* Username to log as                   */
111     char *password;		/* Login Password                       */
112     STRING *ipmikg;		/* IPMI k_g auth key                    */
113 #endif
114     /* type == HOST */
115     char *host;			/* hostname                             */
116     unsigned short netport;	/* final port    | netport = portbase + */
117     unsigned short port;	/* port number   |      portinc * port  */
118     unsigned short portbase;	/* port base                            */
119     unsigned short portinc;	/* port increment                       */
120     FLAG raw;			/* raw or telnet protocol?              */
121     /* type == EXEC */
122     char *exec;			/* exec command                         */
123     char *execsubst;		/* exec substitution pattern            */
124     uid_t execuid;		/* user to run exec as                  */
125     gid_t execgid;		/* group to run exec as                 */
126     /* type == UDS */
127     char *uds;			/* socket file                          */
128     char *udssubst;		/* socket file substitution pattern     */
129     /* global stuff */
130     char *master;		/* master hostname                      */
131     unsigned short breakNum;	/* break type [1-35]                    */
132     char *logfile;		/* logfile                              */
133     off_t logfilemax;		/* size limit for rolling logfile       */
134     char *initcmd;		/* initcmd command                      */
135     char *initsubst;		/* initcmd substitution pattern         */
136     uid_t inituid;		/* user to run initcmd as               */
137     gid_t initgid;		/* group to run initcmd as              */
138     char *motd;			/* motd                                 */
139     time_t idletimeout;		/* idle timeout                         */
140     char *idlestring;		/* string to print when idle            */
141     unsigned short spinmax;	/* initialization spin maximum          */
142     unsigned short spintimer;	/* initialization spin timer            */
143     char *replstring;		/* generic string for replacements      */
144     char *tasklist;		/* list of valid tasks                  */
145     char *breaklist;		/* list of valid break sequences        */
146     /* timestamp stuff */
147     int mark;			/* Mark (chime) interval                */
148     long nextMark;		/* Next mark (chime) time               */
149     FLAG activitylog;		/* log attach/detach/bump               */
150     FLAG breaklog;		/* log breaks sent                      */
151     FLAG tasklog;		/* log tasks invoked                    */
152     /* options */
153     FLAG ondemand;		/* bring up on-demand                   */
154     FLAG reinitoncc;		/* open if down on client connect       */
155     FLAG striphigh;		/* strip high-bit of console data       */
156     FLAG autoreinit;		/* auto-reinitialize if failed          */
157     FLAG unloved;		/* copy "unloved" data to stdout        */
158     FLAG login;			/* allow logins to the console          */
159 
160     /*** runtime settings ***/
161     CONSFILE *fdlog;		/* the local log file                   */
162     CONSFILE *cofile;		/* the port to talk to machine on       */
163     char *execSlave;		/* pseudo-device slave side             */
164     int execSlaveFD;		/* fd of slave side                     */
165     pid_t ipid;			/* pid of virtual command               */
166     pid_t initpid;		/* pid of initcmd command               */
167     CONSFILE *initfile;		/* the command run on init              */
168     pid_t taskpid;		/* pid of task running                  */
169     CONSFILE *taskfile;		/* the output from the task (read-only) */
170     STRING *wbuf;		/* write() buffer                       */
171     int wbufIAC;		/* next IAC location in wbuf            */
172     IOSTATE ioState;		/* state of the socket                  */
173     time_t stateTimer;		/* timer for ioState states             */
174     time_t lastWrite;		/* time of last data sent to console    */
175 #if HAVE_GETTIMEOFDAY
176     struct timeval lastInit;	/* time of last initialization          */
177 #else
178     time_t lastInit;		/* time of last initialization          */
179 #endif
180     unsigned short spincount;	/* initialization spin counter          */
181 
182     /*** state information ***/
183     char acline[132 * 2 + 2];	/* max chars we will call a line        */
184     int iend;			/* length of data stored in acline      */
185     int telnetState;		/* state for telnet negotiations        */
186     FLAG sentDoEcho;		/* have we sent telnet DO ECHO cmd?     */
187     FLAG sentDoSGA;		/* have we sent telnet DO SGA cmd?      */
188     unsigned short autoReUp;	/* is it coming back up automatically?  */
189     FLAG downHard;		/* did it go down unexpectedly?         */
190     unsigned short nolog;	/* don't log output                     */
191     unsigned short fup;		/* we setup this line?                  */
192     unsigned short fronly;	/* we can only read this console        */
193 
194     /*** list management ***/
195     struct client *pCLon;	/* clients on this console              */
196     struct client *pCLwr;	/* client that is writting on console   */
197     CONSENTUSERS *rw;		/* rw users                             */
198     CONSENTUSERS *ro;		/* ro users                             */
199     struct consent *pCEnext;	/* next console entry                   */
200 } CONSENT;
201 
202 typedef struct remote {		/* console at another host              */
203     struct remote *pRCnext;	/* next remote console we know about    */
204     struct remote *pRCuniq;	/* list of uniq remote servers          */
205     char *rserver;		/* remote server name                   */
206     char *rhost;		/* remote host to call to get it        */
207     NAMES *aliases;		/* aliases for remote server name       */
208 } REMOTE;
209 
210 extern PARITY *FindParity(char *);
211 extern BAUD *FindBaud(char *);
212 extern void ConsInit(CONSENT *);
213 extern void ConsDown(CONSENT *, FLAG, FLAG);
214 extern REMOTE *FindUniq(REMOTE *);
215 extern void DestroyRemoteConsole(REMOTE *);
216 extern void StartInit(CONSENT *);
217 extern void StopInit(CONSENT *);
218 extern char *ConsState(CONSENT *);
219 extern void SetupTty(CONSENT *, int);
220