File: common.h

package info (click to toggle)
conman 0.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,600 kB
  • sloc: ansic: 11,863; sh: 2,174; exp: 2,132; makefile: 270; perl: 120
file content (218 lines) | stat: -rw-r--r-- 6,726 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
/*****************************************************************************
 *  Written by Chris Dunlap <cdunlap@llnl.gov>.
 *  Copyright (C) 2007-2022 Lawrence Livermore National Security, LLC.
 *  Copyright (C) 2001-2007 The Regents of the University of California.
 *  UCRL-CODE-2002-009.
 *
 *  This file is part of ConMan: The Console Manager.
 *  For details, see <https://dun.github.io/conman/>.
 *
 *  ConMan is free software: you can redistribute it and/or modify it under
 *  the terms of the GNU General Public License as published by the Free
 *  Software Foundation, either version 3 of the License, or (at your option)
 *  any later version.
 *
 *  ConMan is distributed in the hope that it will be useful, but WITHOUT
 *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 *  for more details.
 *
 *  You should have received a copy of the GNU General Public License along
 *  with ConMan.  If not, see <http://www.gnu.org/licenses/>.
 *****************************************************************************/


#ifndef _COMMON_H
#define _COMMON_H

#include <termios.h>
#include "lex.h"
#include "list.h"

#if HAVE_PATHS_H
#  include <paths.h>
#endif /* HAVE_PATHS_H */

#ifndef _PATH_STDPATH
#  define _PATH_STDPATH "/usr/bin:/bin:/usr/sbin:/sbin"
#endif /* !_PATH_STDPATH */

/*  QUOTE(s) converts [s] into a string constant via stringizing.
 *    https://gcc.gnu.org/onlinedocs/cpp/Stringizing.html
 */
#define QUOTE(s)                STRINGIZE(s)
#define STRINGIZE(s)            #s

/*  CONMAN_HOST is the default host name or IP address of the server.
 */
#ifndef CONMAN_HOST
#define CONMAN_HOST             "127.0.0.1"
#endif /* !CONMAN_HOST */

/*  CONMAN_PORT is the default TCP port number of the server.
 */
#ifndef CONMAN_PORT
#define CONMAN_PORT             "7890"
#endif /* !CONMAN_PORT */

/*  Default escape char for the client.
 */
#define DEFAULT_CLIENT_ESCAPE   '&'

/*  Ye old deprecated escape char for the server's configuration file.
 */
#define DEPRECATED_CONF_ESCAPE  '&'
#define DO_CONF_ESCAPE_ERROR    0

/*  Name of daemon for TCP-Wrappers.
 */
#define CONMAN_DAEMON_NAME      "conmand"

/*  Message prefix/suffix defs for info msgs written to clients & logfiles.
 */
#define CONMAN_MSG_PREFIX       "\r\n<ConMan> "
#define CONMAN_MSG_SUFFIX       ".\r\n"

/*  Notes regarding the recommended sizes of various constants:
 *
 *    - OBJ_BUF_SIZE >= LOG_REPLAY_LEN * 2
 *    - OBJ_BUF_SIZE >= MAX_LINE
 *    - MAX_BUF_SIZE >= MAX_LINE
 *    - MAX_SOCK_LINE >= MAX_LINE
 */
#define OBJ_BUF_SIZE            16384
#define LOG_REPLAY_LEN          4096
#define MAX_BUF_SIZE            4096
#define MAX_SOCK_LINE           131072
#define MAX_LINE                1024

/*  Escape codes used to send ctrl info 'tween client & server.
 */
#define ESC_CHAR                0xFF
#define ESC_CHAR_BREAK          'B'
#define ESC_CHAR_CLOSE          '.'
#define ESC_CHAR_DEL            'D'     /* XXX: gnats:100 del char kludge */
#define ESC_CHAR_ECHO           'E'
#define ESC_CHAR_FORCE          'F'
#define ESC_CHAR_HELP           '?'
#define ESC_CHAR_INFO           'I'
#define ESC_CHAR_JOIN           'J'
#define ESC_CHAR_REPLAY         'L'
#define ESC_CHAR_MONITOR        'M'
#define ESC_CHAR_QUIET          'Q'
#define ESC_CHAR_RESET          'R'
#define ESC_CHAR_SUSPEND        'Z'

/*  Version string information
 */
#ifndef NDEBUG
#  define FEATURE_DEBUG " DEBUG"
#else
#  define FEATURE_DEBUG ""
#endif /* !NDEBUG */

#if WITH_FREEIPMI
#  define FEATURE_FREEIPMI " FREEIPMI"
#else
#  define FEATURE_FREEIPMI ""
#endif /* WITH_FREEIPMI */

#if WITH_TCP_WRAPPERS
#  define FEATURE_TCP_WRAPPERS " TCP-WRAPPERS"
#else
#  define FEATURE_TCP_WRAPPERS ""
#endif /* WITH_TCP_WRAPPERS */

#define CLIENT_FEATURES \
    (FEATURE_DEBUG)
#define SERVER_FEATURES \
    (FEATURE_DEBUG FEATURE_FREEIPMI FEATURE_TCP_WRAPPERS)

#if ! HAVE_SOCKLEN_T
typedef int socklen_t;                  /* socklen_t is uint32_t in Posix.1g */
#endif /* !HAVE_SOCKLEN_T */


typedef enum cmd_type {                 /* ConMan command (2 bits)           */
    CONMAN_CMD_NONE,
    CONMAN_CMD_CONNECT,
    CONMAN_CMD_MONITOR,
    CONMAN_CMD_QUERY
} cmd_t;

typedef struct request {
    int       sd;                       /* socket descriptor                 */
    char     *user;                     /* login name of client user         */
    char     *tty;                      /* device name of client terminal    */
    char     *fqdn;                     /* queried remote FQDN (or ip) str   */
    char     *host;                     /* short remote hostname (or ip) str */
    char     *ip;                       /* queried remote ip addr string     */
    int       port;                     /* remote port number                */
    List      consoles;                 /* list of consoles affected by cmd  */
    unsigned  command:2;                /* ConMan command to perform (cmd_t) */
    unsigned  enableBroadcast:1;        /* true if b-casting to >1 consoles  */
    unsigned  enableEcho:1;             /* true if echoing standard input    */
    unsigned  enableForce:1;            /* true if forcing console conn      */
    unsigned  enableJoin:1;             /* true if joining console conn      */
    unsigned  enableQuiet:1;            /* true if suppressing info messages */
    unsigned  enableRegex:1;            /* true if regex console matching    */
    unsigned  enableReset:1;            /* true if server supports reset cmd */
} req_t;


enum err_type {
    CONMAN_ERR_NONE,
    CONMAN_ERR_LOCAL,
    CONMAN_ERR_BAD_REQUEST,
    CONMAN_ERR_BAD_REGEX,
    CONMAN_ERR_AUTHENTICATE,
    CONMAN_ERR_NO_CONSOLES,
    CONMAN_ERR_TOO_MANY_CONSOLES,
    CONMAN_ERR_BUSY_CONSOLES
};

enum proto_toks {
/*
 *  Keep enums in sync w/ common.c:proto_strs[].
 */
    CONMAN_TOK_BROADCAST = LEX_TOK_OFFSET,
    CONMAN_TOK_CODE,
    CONMAN_TOK_CONNECT,
    CONMAN_TOK_CONSOLE,
    CONMAN_TOK_ERROR,
    CONMAN_TOK_FORCE,
    CONMAN_TOK_HELLO,
    CONMAN_TOK_JOIN,
    CONMAN_TOK_MESSAGE,
    CONMAN_TOK_MONITOR,
    CONMAN_TOK_OK,
    CONMAN_TOK_OPTION,
    CONMAN_TOK_QUERY,
    CONMAN_TOK_QUIET,
    CONMAN_TOK_REGEX,
    CONMAN_TOK_RESET,
    CONMAN_TOK_TTY,
    CONMAN_TOK_USER
};

extern char *proto_strs[];              /* defined in common.c */

extern const char *conman_license;      /* defined in common.c */


/**************\
**  common.c  **
\**************/

req_t * create_req(void);

void destroy_req(req_t *req);

void get_tty_mode(struct termios *tty, int fd);

void set_tty_mode(struct termios *tty, int fd);

void get_tty_raw(struct termios *tty, int fd);


#endif /* !_COMMON_H */