1 /**************************************************
2 OpengateM - MAC address authentication system
3 module for child process control
5 this module opens the network for the candidate of the user device.
6 (this is used in opengatemchk).
7 a child process opens net, sleeps while, and closes net automatically.
8 independent process is employed to perform a series of processing surely.
10 Copyright (C) 2011 Opengate Project Team
11 Written by Yoshiaki Watanabe
13 This program is free software; you can redistribute it and/or
14 modify it under the terms of the GNU General Public License
15 as published by the Free Software Foundation; either version 2
16 of the License, or (at your option) any later version.
18 This program is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with this program; if not, write to the Free Software
25 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 Email: watanaby@is.saga-u.ac.jp
28 **************************************************/
30 #include "opengatemmng.h"
34 char loadPath[BUFFMAXLN];
36 /**********************************************************/
37 /* start child process that open-net, sleep and close-net */
38 /**********************************************************/
39 int startChildProc(char* macAddress){
46 /* fork child process */
48 err_msg("ERR at %s#%d: fork error",__FILE__,__LINE__);
60 /* detach from server */
61 Close(0);Close(1);Close(2);
62 Pipe(dummyfd); /* connect dummy pipe for stdin and out */
64 /* get ipv4/ipv6 corresponding to the mac from db */
65 GetIpFromMacCheckTable(macAddress, ipv4, ipv6);
68 if(!isNull(ipv4)) rule4=OpenClientGate(ipv4,FALSE,"temp","","");
69 if(!isNull(ipv6)) rule6=OpenClientGate(ipv6,FALSE,"temp","","");
71 /* save pid/ruleNumber to db */
72 SavePidToMacCheckTable(macAddress, getpid(), rule4, rule6);
74 /* at TERM signal is received, call closeExit */
75 signal(SIGTERM, closeExit);
78 sleep(atoi(GetConfValue("OpenTimeout")));
81 if(rule4!=0) CloseClientGate(rule4);
82 if(rule6!=0) CloseClientGate(rule6);
88 /***************************/
90 /***************************/
91 void closeExit(int signo){
94 if(rule4!=0) CloseClientGate(rule4);
95 if(rule6!=0) CloseClientGate(rule6);
99 /*********************************/
100 /* stop child process */
101 /*********************************/
102 int stopChildProc(char* macAddress){
106 /* get pid/ruleNumber from db */
107 GetPidFromMacCheckTable(macAddress, &pid, &rule4, &rule6);
110 if(rule4!=0) CloseClientGate(rule4);
111 if(rule6!=0) CloseClientGate(rule6);
113 /* kill child process */
119 /******************************/
120 /* save the program load path */
121 /******************************/
122 void saveLoadPath(char* argv0){
123 strlcpy(loadPath, argv0, BUFFMAXLN);
126 /***********************************************/
127 /* get the program name extracted from argv[0] */
128 /***********************************************/
129 char* getProgramName(void){
131 pCh = strrchr(loadPath, '/');
132 if(isNull(pCh)) return loadPath;
136 /*********************************************
137 **********************************************/
138 int StartChildProc(char* macAddress){
140 if(debug>1) err_msg("DEBUG:=>startChildProc(%s)",macAddress);
141 ret=startChildProc(macAddress);
142 if(debug>1) err_msg("DEBUG:(%d)<=startChildProc( )",ret);
146 int StopChildProc(char* macAddress){
148 if(debug>1) err_msg("DEBUG:=>stopChildProc(%s)",macAddress);
149 ret=stopChildProc(macAddress);
150 if(debug>1) err_msg("DEBUG:(%d)<=stopChildProc( )",ret);