File: opener.h

package info (click to toggle)
kppp 4:17.08.3-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • size: 4,176 kB
  • sloc: cpp: 13,825; tcl: 49; sh: 19; xml: 15; makefile: 5
file content (147 lines) | stat: -rw-r--r-- 3,216 bytes parent folder | download | duplicates (4)
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
#ifndef _FILEOPENER_H_
#define _FILEOPENER_H_

#define DEVNULL "/dev/null"

// workaround for bug in glibc on RedHat 5.0 and Debian 2.1
#if defined(__GLIBC__) && (__GLIBC__ == 2 && __GLIBC_MINOR__ == 0 && defined(__linux__))
# define MY_SCM_RIGHTS 1
#else
# define MY_SCM_RIGHTS SCM_RIGHTS
#endif

// ### add by bhughes - FreeBSD defines 'BSD' in sys/param.h
#include <sys/param.h>

#if defined(BSD) || defined(__SVR4)
# define IOV_BASE_CAST (char *)
#else
# define IOV_BASE_CAST (void *)
#endif

const char *pppdPath();

class Opener {

public:
  Opener(int);
  ~Opener();

  enum { OpenDevice = 1,
         OpenLock, RemoveLock,
         OpenResolv,
         OpenSysLog,
         SetSecret, RemoveSecret,
         SetHostname,
         ExecPPPDaemon, KillPPPDaemon,
	 PPPDExitStatus,
         Stop };
  enum Auth { PAP = 1, CHAP };
  enum { MaxPathLen = 30, MaxStrLen = 40, MaxArgs = 100 };

private:
  enum { Original=0x100, New=0x200, Old=0x400 } Version;
  void mainLoop();
  int sendFD(int ttyfd, struct ResponseHeader *response);
  int sendResponse(struct ResponseHeader *response);
  const char *deviceByIndex(int idx);
  bool createAuthFile(Auth method, char *username, char *password);
  bool removeAuthFile(Auth method);
  const char* authFile(Auth method, int version = Original);
  bool execpppd(const char *arguments);
  bool killpppd()const;
  void parseargs(char* buf, char** args);

  int socket;
  int ttyfd;
  char lockfile[MaxPathLen+1];
};


struct RequestHeader {
  int	type;
  int	len;
  //  int   id;     // TODO: Use a transmission id and check whether
                    //       response matches request
};

struct ResponseHeader {
  int	status; /* 0 or errno */
  //  int   id;
};

struct OpenModemRequest {
  struct RequestHeader header;
  int    deviceNum;
};

struct RemoveLockRequest {
  struct RequestHeader header;
};

struct OpenLockRequest {
  struct RequestHeader header;
  int    deviceNum;
  int    flags;
};

struct OpenResolvRequest {
  struct RequestHeader header;
  int    flags;
};

struct OpenLogRequest {
  struct RequestHeader header;
};

struct SetSecretRequest {
  struct RequestHeader header;
  Opener::Auth method;   // PAP or CHAP
  char   username[Opener::MaxStrLen+1];
  char   password[Opener::MaxStrLen+1];
};

struct RemoveSecretRequest {
  struct RequestHeader header;
  Opener::Auth method;   // PAP or CHAP
};

struct SetHostnameRequest {
  struct RequestHeader header;
  char   name[Opener::MaxStrLen+1];
};

struct ExecDaemonRequest {
  struct RequestHeader header;
  char   arguments[MAX_CMDLEN+1];
};

struct KillDaemonRequest {
  struct RequestHeader header;
};

struct PPPDExitStatusRequest {
  struct RequestHeader header;
};

struct StopRequest {
  struct RequestHeader header;
};

union AllRequests {
  struct RequestHeader header;
  struct OpenModemRequest  modem;
  struct OpenLockRequest lock;
  struct RemoveLockRequest unlock;
  struct OpenResolvRequest resolv;
  struct SetSecretRequest secret;
  struct RemoveSecretRequest remove;
  struct SetHostnameRequest host;
  struct OpenLogRequest log;
  struct ExecDaemonRequest daemon;
  struct ExecDaemonRequest kill;
  struct PPPDExitStatusRequest status;
  struct StopRequest stop;
};

#endif