OSDN Git Service

Initial import.
[opengate/opengate.git] / opengate / opengatesrv / opengatesrv.h
1 /**************************************************
2 opengate server header file
3
4 Copyright (C) 1999-2001 Yoshiaki Watanabe
5
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19
20 Email: watanaby@is.saga-u.ac.jp
21 **************************************************/
22
23 #include        <sys/types.h>   /* basic system data types */
24 #include        <sys/socket.h>  /* basic socket definitions */
25 #include        <sys/time.h>    /* timeval{} for select() */
26 #include        <time.h>                /* timespec{} for pselect() */
27 #include        <netinet/in.h>  /* sockaddr_in{} and other Internet defns */
28 #include        <arpa/inet.h>   /* inet(3) functions */
29 #include        <errno.h>
30 #include        <fcntl.h>               /* for nonblocking */
31 #include        <netdb.h>
32 #include        <signal.h>
33 #include        <stdio.h>
34 #include        <stdlib.h>
35 #include        <string.h>
36 #include        <sys/stat.h>    /* for S_xxx file mode constants */
37 #include        <sys/uio.h>             /* for iovec{} and readv/writev */
38 #include        <unistd.h>
39 #include        <sys/wait.h>
40 #include        <sys/un.h>              /* for Unix domain sockets */
41 # include       <sys/select.h>  /* for convenience */
42 # include       <poll.h>                /* for convenience */
43 # include       <strings.h>             /* for convenience */
44 # include       <sys/ioctl.h>
45 # include       <sys/filio.h>
46 # include       <sys/sockio.h>
47 # include       <pthread.h>
48 #define SA      struct sockaddr
49 #define LISTENQ         1024    /* 2nd argument to listen() */
50 typedef void    Sigfunc(int);   /* for signal handlers */
51
52 #include <syslog.h>
53 #include <ctype.h>
54 #include <stdarg.h>
55 #include <sys/signal.h>
56
57 /***** some parameters are overrided by the value in makefile. ****/
58
59 #define DEBUG 0      /* if 1, dump many message to syslog */
60
61 #define APPLETMARK "**OpengateAppletHere**" /* applet insert point mark */
62 #define TERMINATEMARK "**TerminateUrlHere**" /* terminate URL insert mark */
63
64 #define DURATIONDEFAULT 1200     /* default timeout of java connect (second) */
65 #define DURATIONMAX 10800      /* requested usage time without java */
66                                   /* is limitted by this value(second) */
67
68 #define ACTIVECHECKINTERVAL 600    /* client check interval(second)   */
69 #define COMMWAITTIMEOUT 60        /* communication reply timeout(second) */
70 #define NOREPLYMAX 1               /* permitted count of no reply to hello */
71 #define PACKETLOGDELAY 10          /* wait log writing time(second)   */
72 #define NOPACKETINTERVAL 5400      /* no packet interval (second)     */
73                                    /*    to judge the user has gone   */
74
75 #define LOCKTIMEOUT 10   /* ipfw excusive exec lock timeout (second)*/
76
77 #define IPFWMIN 10000    /* ipfw rule number minimum */
78 #define IPFWMAX 40000    /* ipfw rule number maximum */
79 #define IPFWINTERVAL 2   /* ipfw rule number interval */
80
81                /* listen a port between follows */
82 #define PORTMIN 30000    /* minimum port number */
83 #define PORTMAX 60000    /* maximum port number */
84
85 #define FACILITY LOG_LOCAL1  /* syslog ID */
86
87 #define DEFAULTPROTO  "ftp"    /* default authentication protocol */
88
89 #define ADDRMAXLN 128      /* maximum address string length */
90 #define PASSMAXLN 128      /* maximum password string length */
91 #define USERMAXLN 32       /* maximum userid string length */
92 #define BUFFMAXLN 256      /* maximum buffer string length */
93 #define WORDMAXLN 16       /* maximum word length */
94 #define TRUE 1
95 #define FALSE 0
96 #define DENY   0
97 #define ACCEPT 1
98
99 #define ENABLEMACADDR 1    /* if 0, ignore MAC addr routine */ 
100 #define PAMSERVICENAME "opengate"    /* service name used in PAM */
101 #define RADIUSCONF  "/etc/radius.conf" /* default path to radius.conf */
102
103 /**********prototypes***************************************/
104
105 int authenticateUser(char *userid, char *password);
106 int AuthenticateUser(char *userid, char *password);
107
108 int openClientGate(char *clientAddr, char *userid, char *macAddr, char *userProperty);
109 int OpenClientGate(char *clientAddr, char *userid, char *macAddr, char *userProperty);
110
111 void closeClientGate(void);
112 void CloseClientGate(void);
113
114 int getPacketCount(void);
115 int GetPacketCount(void);
116
117 void getClientAddr(char *clientAddr);
118 void GetClientAddr(char *clientAddr);
119
120 void getUserInfo(char *userid, char *password, int *durationPtr);
121 void GetUserInfo(char *userid, char *password, int *durationPtr);
122
123 int getUserProperty(char *userid, char *userProperty);
124 int GetUserProperty(char *userid, char *userProperty);
125
126 void waitClientClose(void);
127 void WaitClientClose(void);
128
129 void putClientDeny(void);
130 void PutClientDeny(void);
131
132 void putClientMsg(char *message);
133 void PutClientMsg(char *message);
134
135 int getListenPort(void);
136 int GetListenPort(void);
137
138 void putJavaApplet(char *userid, int port, int pid);
139 void PutJavaApplet(char *userid, int port, int pid);
140
141 int waitAppletConnect(char *userid, char *clientAddr, int duration, char *macAddr);
142 int WaitAppletConnect(char *userid, char *clientAddr, int duration, char *macAddr);
143
144 ssize_t readln(int fd, void *vptr, size_t maxlen);
145 ssize_t Readln(int fd, void *ptr, size_t maxlen);
146
147 void Writefmt(int fd, const char *fmt, ...);
148
149 int lock(int fd);
150 int Lock(int fd);
151
152 int unlock(int fd);
153 int Unlock(int fd);
154
155 int getMacAddr(char *clientAddr, char* macAddr);
156 int GetMacAddr(char *clientAddr, char* macAddr);
157
158 void quitClient(void);
159 void QuitClient(void);
160
161 int tcp_connect(const char *host, const char *serv);
162 int Tcp_connect(const char *host, const char *serv);
163
164 void err_ret(const char *fmt, ...);
165 void err_sys(const char *fmt, ...);
166 void err_dump(const char *fmt, ...);
167 void err_msg(const char *fmt, ...);
168 void err_quit(const char *fmt, ...);
169 void errToSyslog(int i);
170
171 char * sock_ntop_host(const struct sockaddr *sa, socklen_t salen);
172 char * Sock_ntop_host(const struct sockaddr *sa, socklen_t salen);
173
174 int Open(const char *pathname, int oflag, mode_t mode);
175 void Close(int fd);
176 pid_t Fork(void);
177 void Pipe(int *fds);
178 void Getpeername(int fd, struct sockaddr *sa, socklen_t *salenptr);
179 int Socket(int family, int type, int protocol);
180 void Listen(int fd, int backlog);
181 Sigfunc * Signal(int signo, Sigfunc *func);
182 void * Malloc(size_t size);
183
184
185