1 |
root |
1.10 |
#ifndef LIBPTYTTY_H_ /* public libptytty header file */ |
2 |
|
|
#define LIBPTYTTY_H_ |
3 |
root |
1.1 |
|
4 |
root |
1.10 |
#ifdef __cplusplus |
5 |
root |
1.8 |
|
6 |
root |
1.12 |
// C++ API |
7 |
root |
1.8 |
|
8 |
root |
1.18 |
#include <stdlib.h> |
9 |
sf-exg |
1.17 |
#include <exception> |
10 |
|
|
#include <string.h> |
11 |
|
|
|
12 |
|
|
class ptytty_error : public std::exception |
13 |
|
|
{ |
14 |
|
|
private: |
15 |
|
|
char *msg; |
16 |
|
|
|
17 |
|
|
public: |
18 |
|
|
ptytty_error (const char *what_arg) |
19 |
|
|
{ |
20 |
|
|
msg = strdup (what_arg); |
21 |
|
|
} |
22 |
|
|
|
23 |
|
|
~ptytty_error () |
24 |
|
|
{ |
25 |
|
|
free (msg); |
26 |
|
|
} |
27 |
|
|
|
28 |
|
|
const char * |
29 |
|
|
what () const noexcept override |
30 |
|
|
{ |
31 |
|
|
return msg; |
32 |
|
|
} |
33 |
|
|
}; |
34 |
|
|
|
35 |
sf-exg |
1.16 |
struct ptytty |
36 |
|
|
{ |
37 |
root |
1.14 |
int pty; // pty file descriptor; connected to terminal emulator |
38 |
root |
1.10 |
int tty; // tty file descriptor; connected to child |
39 |
root |
1.1 |
|
40 |
root |
1.10 |
virtual ~ptytty () |
41 |
|
|
{ |
42 |
|
|
} |
43 |
root |
1.1 |
|
44 |
root |
1.10 |
virtual bool get () = 0; |
45 |
|
|
virtual void login (int cmd_pid, bool login_shell, const char *hostname) = 0; |
46 |
root |
1.1 |
|
47 |
root |
1.10 |
void close_tty (); |
48 |
|
|
bool make_controlling_tty (); |
49 |
|
|
void set_utf8_mode (bool on); |
50 |
root |
1.1 |
|
51 |
root |
1.13 |
static void sanitise_stdfd (); |
52 |
root |
1.10 |
static void init (); |
53 |
|
|
static ptytty *create (); // create a new pty object |
54 |
root |
1.6 |
|
55 |
root |
1.10 |
static void drop_privileges (); |
56 |
|
|
static void use_helper (); |
57 |
root |
1.4 |
|
58 |
root |
1.10 |
static bool send_fd (int socket, int fd); |
59 |
|
|
static int recv_fd (int socket); |
60 |
root |
1.4 |
|
61 |
root |
1.10 |
protected: |
62 |
root |
1.4 |
|
63 |
root |
1.10 |
ptytty () |
64 |
|
|
: pty(-1), tty(-1) |
65 |
|
|
{ |
66 |
|
|
} |
67 |
|
|
}; |
68 |
root |
1.1 |
|
69 |
root |
1.10 |
#else |
70 |
root |
1.8 |
|
71 |
root |
1.12 |
// C API |
72 |
root |
1.8 |
|
73 |
root |
1.10 |
typedef void *PTYTTY; |
74 |
root |
1.8 |
|
75 |
root |
1.10 |
int ptytty_pty (PTYTTY ptytty); |
76 |
|
|
int ptytty_tty (PTYTTY ptytty); |
77 |
|
|
void ptytty_delete (PTYTTY ptytty); |
78 |
|
|
int ptytty_get (PTYTTY ptytty); |
79 |
root |
1.11 |
void ptytty_login (PTYTTY ptytty, int cmd_pid, int login_shell, const char *hostname); |
80 |
root |
1.8 |
|
81 |
root |
1.10 |
void ptytty_close_tty (PTYTTY ptytty); |
82 |
|
|
int ptytty_make_controlling_tty (PTYTTY ptytty); |
83 |
|
|
void ptytty_set_utf8_mode (PTYTTY ptytty, int on); |
84 |
root |
1.8 |
|
85 |
root |
1.13 |
void ptytty_sanitise_stdfd (); |
86 |
root |
1.10 |
void ptytty_init (); |
87 |
|
|
PTYTTY ptytty_create (); |
88 |
root |
1.8 |
|
89 |
root |
1.10 |
void ptytty_drop_privileges (); |
90 |
|
|
void ptytty_use_helper (); |
91 |
root |
1.1 |
|
92 |
root |
1.10 |
#endif |
93 |
root |
1.9 |
|
94 |
root |
1.10 |
#endif |
95 |
root |
1.9 |
|