1 /**************************************************
2 opengate server header file
4 Copyright (C) 1999-2001 Yoshiaki Watanabe
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.
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.
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.
20 Email: watanaby@is.saga-u.ac.jp
21 **************************************************/
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 */
30 #include <fcntl.h> /* for nonblocking */
36 #include <sys/stat.h> /* for S_xxx file mode constants */
37 #include <sys/uio.h> /* for iovec{} and readv/writev */
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>
48 #define SA struct sockaddr
49 #define LISTENQ 1024 /* 2nd argument to listen() */
50 typedef void Sigfunc(int); /* for signal handlers */
55 #include <sys/signal.h>
57 /***** some parameters are overrided by the value in makefile. ****/
59 #define DEBUG 0 /* if 1, dump many message to syslog */
61 #define APPLETMARK "**OpengateAppletHere**" /* applet insert point mark */
62 #define TERMINATEMARK "**TerminateUrlHere**" /* terminate URL insert mark */
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) */
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 */
75 #define LOCKTIMEOUT 10 /* ipfw excusive exec lock timeout (second)*/
77 #define IPFWMIN 10000 /* ipfw rule number minimum */
78 #define IPFWMAX 40000 /* ipfw rule number maximum */
79 #define IPFWINTERVAL 2 /* ipfw rule number interval */
81 /* listen a port between follows */
82 #define PORTMIN 30000 /* minimum port number */
83 #define PORTMAX 60000 /* maximum port number */
85 #define FACILITY LOG_LOCAL1 /* syslog ID */
87 #define DEFAULTPROTO "ftp" /* default authentication protocol */
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 */
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 */
103 /**********prototypes***************************************/
105 int authenticateUser(char *userid, char *password);
106 int AuthenticateUser(char *userid, char *password);
108 int openClientGate(char *clientAddr, char *userid, char *macAddr, char *userProperty);
109 int OpenClientGate(char *clientAddr, char *userid, char *macAddr, char *userProperty);
111 void closeClientGate(void);
112 void CloseClientGate(void);
114 int getPacketCount(void);
115 int GetPacketCount(void);
117 void getClientAddr(char *clientAddr);
118 void GetClientAddr(char *clientAddr);
120 void getUserInfo(char *userid, char *password, int *durationPtr);
121 void GetUserInfo(char *userid, char *password, int *durationPtr);
123 int getUserProperty(char *userid, char *userProperty);
124 int GetUserProperty(char *userid, char *userProperty);
126 void waitClientClose(void);
127 void WaitClientClose(void);
129 void putClientDeny(void);
130 void PutClientDeny(void);
132 void putClientMsg(char *message);
133 void PutClientMsg(char *message);
135 int getListenPort(void);
136 int GetListenPort(void);
138 void putJavaApplet(char *userid, int port, int pid);
139 void PutJavaApplet(char *userid, int port, int pid);
141 int waitAppletConnect(char *userid, char *clientAddr, int duration, char *macAddr);
142 int WaitAppletConnect(char *userid, char *clientAddr, int duration, char *macAddr);
144 ssize_t readln(int fd, void *vptr, size_t maxlen);
145 ssize_t Readln(int fd, void *ptr, size_t maxlen);
147 void Writefmt(int fd, const char *fmt, ...);
155 int getMacAddr(char *clientAddr, char* macAddr);
156 int GetMacAddr(char *clientAddr, char* macAddr);
158 void quitClient(void);
159 void QuitClient(void);
161 int tcp_connect(const char *host, const char *serv);
162 int Tcp_connect(const char *host, const char *serv);
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);
171 char * sock_ntop_host(const struct sockaddr *sa, socklen_t salen);
172 char * Sock_ntop_host(const struct sockaddr *sa, socklen_t salen);
174 int Open(const char *pathname, int oflag, mode_t mode);
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);