OSDN Git Service

modified update page. reduced emails.
[opengatem/opengatem.git] / mngsrc / managementdb.c
1 /**************************************************
2 OpengateM - MAC address authentication system 
3
4  module to control management database
5  list of mac addresses
6  list of usage log
7  implemented with MySql 
8
9 Copyright (C) 2011 Opengate Project Team
10 Written by Yoshiaki Watanabe
11
12 This program is free software; you can redistribute it and/or
13 modify it under the terms of the GNU General Public License
14 as published by the Free Software Foundation; either version 2
15 of the License, or (at your option) any later version.
16
17 This program is distributed in the hope that it will be useful,
18 but WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20 GNU General Public License for more details.
21
22 You should have received a copy of the GNU General Public License
23 along with this program; if not, write to the Free Software
24 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
26 Email: watanaby@is.saga-u.ac.jp
27 **************************************************/
28 #include "opengatemmng.h"
29 #include <mysql.h>
30
31 MYSQL mysql;
32
33 /******************************************
34 initialize management db
35 ******************************************/
36 int initMngDb(void){
37
38   /* set parameters */
39   char *server = GetConfValue("MySqlDb/Server");
40   char *user =  GetConfValue("MySqlDb/User");
41   char *password = GetConfValue("MySqlDb/Password");
42   char *database = GetConfValue("MySqlDb/Database");
43   my_bool reconnect;
44
45 /* initialize mysql */
46   mysql_library_init(-1,NULL,NULL);
47   if(mysql_init(&mysql)==NULL){
48      err_msg("ERR at %s#%d: mysql init: %s",__FILE__,__LINE__,
49              mysql_error(&mysql));
50      terminateProg(0);
51   }
52
53   /* Connect to database */
54   if (!mysql_real_connect(&mysql, server,
55                            user, password, database, 0, NULL, 0)) {
56     err_msg("ERR at %s#%d: mysql connect: %s",__FILE__,__LINE__,
57              mysql_error(&mysql));
58     terminateProg(0);
59   }
60
61   /* set auto-reconnect true */
62   reconnect = TRUE;
63   mysql_options(&mysql, MYSQL_OPT_RECONNECT, &reconnect);  
64
65   return TRUE;
66 }
67
68 /******************************************
69 close management db
70 ******************************************/
71 void closeMngDb(void){
72   mysql_close(&mysql);
73   mysql_library_end();
74 }
75
76
77 /******************************************
78  get nic vendor from management db
79 ******************************************/
80 int getNicVendorFromMngDb(char* macAddress, char* vendor, int bufferLength){
81
82   MYSQL_RES *res;
83   MYSQL_ROW row;
84   int found=FALSE;
85   char queryStr[BUFFMAXLN];
86   char macHeader[ADDRMAXLN];
87
88   /* set default values */
89   vendor[0]='?';
90   vendor[1]='\0';
91  
92   /* prepare query string */
93   strlcpy(macHeader, macAddress, ADDRMAXLN);
94   macHeader[8]='\0';
95   snprintf(queryStr, BUFFMAXLN, 
96            "select org from nicvendors where oui='%s'",
97            macHeader);
98
99   /* send SQL query */
100   if (mysql_query(&mysql, queryStr)){
101      err_msg("ERR at %s#%d: mysql query: %s",__FILE__,__LINE__,
102              mysql_error(&mysql));
103      return FALSE;
104   }
105
106   res = mysql_use_result(&mysql);
107   
108   /* output table name */
109   row = mysql_fetch_row(res);
110
111   /* if not found, return false */
112   if(row==NULL)  found=FALSE;
113
114   /* if found */
115   else {
116     strlcpy(vendor, row[0], bufferLength);
117     found=TRUE;
118   }
119
120   mysql_free_result(res);
121   return found;
122 }
123
124 /******************************************
125  The macAddr is already registered
126 ******************************************/
127 int isMacAddrFoundInMngDb(char* macAddr){
128
129   MYSQL_RES *res=NULL;
130   MYSQL_ROW row;
131   char queryStr[BUFFMAXLN];
132   int ret;
133
134   /* prepare query string */
135   snprintf(queryStr, BUFFMAXLN, 
136            "select * from macaddrs "
137            " where macAddress='%s' and status!='D'",
138            macAddr);
139   
140   /* send SQL query */
141   if (mysql_query(&mysql, queryStr)){
142     err_msg("ERR at %s#%d: mysql query: %s",__FILE__,__LINE__,
143             mysql_error(&mysql));
144     return FALSE;
145   }
146   
147   /* store result */
148   res = mysql_store_result(&mysql);
149
150   /* output table name */
151   row = mysql_fetch_row(res);
152   
153   /* if found, return true */
154   if(row!=NULL) ret=TRUE;
155
156   /* if not found, return false */
157   else ret=FALSE;
158
159   mysql_free_result(res);
160   return ret;
161 }
162
163 /******************************************
164  The count of registered mac address for the user
165 ******************************************/
166 int countMacAddrsForUserInMngDb(char* userId, char* extraId){
167
168   MYSQL_RES *res=NULL;
169   MYSQL_ROW row;
170   char queryStr[BUFFMAXLN];
171   char countStr[WORDMAXLN];
172   int count=10000;
173
174   /* prepare query string */
175   snprintf(queryStr, BUFFMAXLN, 
176            "select count(*) from macaddrs "
177            " where userId='%s' and extraId='%s' and status!='D'",
178            userId, extraId);
179
180   /* send SQL query */
181   if (mysql_query(&mysql, queryStr)){
182     err_msg("ERR at %s#%d: mysql query: %s",__FILE__,__LINE__,
183             mysql_error(&mysql));
184     return count;
185   }
186
187   /* store result */
188   res = mysql_store_result(&mysql);
189
190   /* output table name */
191   row = mysql_fetch_row(res);
192
193   /* if found, return values */
194   if(row!=NULL){
195     strlcpy(countStr, row[0], WORDMAXLN);
196     count=atoi(countStr);
197   }
198
199   /* free memory area */
200   mysql_free_result(res);
201
202   return count;
203 }
204
205 /******************************************
206 register mac address to the management db
207 ******************************************/
208 int registMacAddrToMngDb(char* macAddr, char* deviceName, char* userId, char* extraId, char* mailAddr){
209
210   char queryStr[BUFFMAXLN];
211   int count;
212
213    /* if alreay registered (and not deleted yet), return false */
214   if(IsMacAddrFoundInMngDb(macAddr)){
215     SetMessage(ExistentMacAddr);
216     return FALSE;
217   }
218  
219   /* if the user registered device more than limit, return false */
220   count=CountMacAddrsForUserInMngDb(userId,extraId);
221   if(count >= atoi(GetConfValue("MaxDevices"))){
222     SetMessage(DeviceCountOver);
223     return FALSE;
224   }
225  
226   /* prepare query string */
227   snprintf(queryStr, BUFFMAXLN, 
228            "insert into macaddrs "
229            "(macAddress, status, device, userId, extraId, "
230            " entryDate, renewDate, limitDate, mailAddress) "
231            "values ('%s','A','%s', '%s', '%s', "
232            " now(), now(), %s, '%s')",
233            macAddr, deviceName, userId, extraId, 
234            GetConfValue("LimitDate"), mailAddr);
235
236   /* send SQL query */
237   if (mysql_query(&mysql, queryStr)){
238      err_msg("ERR at %s#%d: mysql query: %s",__FILE__,__LINE__,
239              mysql_error(&mysql));
240      return FALSE;
241   }
242
243   return TRUE;
244 }
245
246 /*******************************************
247  get next mac address from management db
248  if end of list, return false
249 *******************************************/
250 int getNextMacAddrFromMngDb(char* userId, char* extraId, char* macAddress, char* deviceName, char* entryDate, char* limitDate, char* status, char* mailAddress){
251
252   static MYSQL_RES *res=NULL;
253   MYSQL_ROW row;
254   char queryStr[BUFFMAXLN];
255
256   /* set default values */
257   macAddress[0]=deviceName[0]=entryDate[0]=limitDate[0]='\0';
258
259   /* if do not get result yet */
260   if(res==NULL){
261
262     /* prepare query string */
263     snprintf(queryStr, BUFFMAXLN, 
264       "select macAddress, device, entryDate, limitDate, status, mailAddress "
265       "from macaddrs where userId='%s' and extraId='%s' and status!='D'",
266       userId, extraId);
267
268     /* send SQL query */
269     if (mysql_query(&mysql, queryStr)){
270       err_msg("ERR at %s#%d: mysql query: %s",__FILE__,__LINE__,
271               mysql_error(&mysql));
272       return FALSE;
273     }
274     
275     /* store result */
276     res = mysql_store_result(&mysql);
277   }
278
279   /* output table name */
280   row = mysql_fetch_row(res);
281
282   /* if found, return values */
283   if(row!=NULL){
284     strlcpy(macAddress, row[0],ADDRMAXLN);
285     strlcpy(deviceName,row[1],WORDMAXLN);
286     strlcpy(entryDate,row[2],WORDMAXLN);
287     strlcpy(limitDate,row[3],WORDMAXLN);
288     strlcpy(status,row[4],WORDMAXLN);
289     strlcpy(mailAddress,row[5],BUFFMAXLN);
290     return TRUE;
291   }
292   /* if not found, free memory area */
293   else{
294     mysql_free_result(res);
295     return FALSE;
296   }
297 }
298
299
300 /******************************************
301  write mac modification log to the management db
302 ******************************************/
303 int putMacModifyLogToMngDb(char* userId, char* extraId, char* macAddr, char modifyType){
304
305   char queryStr[BUFFMAXLN];
306  
307   /* prepare query string */
308   snprintf(queryStr, BUFFMAXLN, 
309            "insert into macmodify "
310            "(userId, extraId, macAddress, modifyType, modifyDate) "
311            "values ('%s', '%s', '%s', '%c', now())",
312            userId, extraId, macAddr, modifyType);
313
314   /* send SQL query */
315   if (mysql_query(&mysql, queryStr)){
316      err_msg("ERR at %s#%d: mysql query: %s",__FILE__,__LINE__,
317              mysql_error(&mysql));
318      return FALSE;
319   }
320
321   return TRUE;
322 }
323
324 /******************************************
325  The count of mac address modification in last 24 hours
326 ******************************************/
327 int countMacModifyPerDayInMngDb(char* userId, char* extraId){
328
329   MYSQL_RES *res=NULL;
330   MYSQL_ROW row;
331   char queryStr[BUFFMAXLN];
332   char countStr[WORDMAXLN];
333   int count=10000;
334
335   /* prepare query string */
336   snprintf(queryStr, BUFFMAXLN, 
337            "select count(*) from macmodify "
338            " where userId='%s' and extraId='%s' and "
339            " modifyDate > adddate(now(), interval -1 day) ",
340            userId, extraId);
341
342   /* send SQL query */
343   if (mysql_query(&mysql, queryStr)){
344     err_msg("ERR at %s#%d: mysql query: %s",__FILE__,__LINE__,
345             mysql_error(&mysql));
346     return count;
347   }
348
349   /* store result */
350   res = mysql_store_result(&mysql);
351
352   /* output table name */
353   row = mysql_fetch_row(res);
354
355   /* if found, return values */
356   if(row!=NULL){
357     strlcpy(countStr, row[0], WORDMAXLN);
358     count=atoi(countStr);
359   }
360
361   /* free memory area */
362   mysql_free_result(res);
363
364   return count;
365 }
366
367 /******************************************
368 delete a mac address registered in the management db
369  do not delete, but set the status flag to 'D'
370 ******************************************/
371 int delMacAddrFromMngDb(char* macAddr){
372
373   char queryStr[BUFFMAXLN];
374
375   /* if the mac data was used, it is preserved for usage log */ 
376   if(IsSessionFoundInMngDb(macAddr)){
377
378     /* prepare query string */
379     /* if session for the mac exists, the row is preserved */
380     /* don't touch device set as status=Inactive */
381     snprintf(queryStr, BUFFMAXLN, 
382              "update macaddrs set status='D',limitDate=now() "
383              " where macAddress='%s' and (status='A' or status='P')", macAddr);
384   }else{
385   
386     /* prepare query string */
387     /* if session does not exist, the row is removed */
388     /* don't touch device set as status=Inactive */
389     snprintf(queryStr, BUFFMAXLN, 
390              "delete from macaddrs "
391              " where macAddress='%s' and (status='A' or status='P')", macAddr);
392   }
393
394   /* send SQL query */
395   if (mysql_query(&mysql, queryStr)){
396     err_msg("ERR at %s#%d: mysql query: %s",__FILE__,__LINE__,
397             mysql_error(&mysql));
398     return FALSE;
399   }
400   return TRUE;
401 }
402
403 /******************************************
404 renew the limit date for a mac address
405  registered in the management db
406 ******************************************/
407 int renewMacAddrInMngDb(char* macAddr){
408
409   char queryStr[BUFFMAXLN];
410
411   /* prepare query string */
412   /* don't touch device set as inactive by admin */
413   snprintf(queryStr, BUFFMAXLN, 
414            "update macaddrs set status='A', renewDate=now(), limitDate=%s "
415            " where (status='A' or status='P') and macAddress='%s'", 
416            GetConfValue("LimitDate"),macAddr);
417
418   /* send SQL query */
419   if (mysql_query(&mysql, queryStr)){
420     err_msg("ERR at %s#%d: mysql query: %s",__FILE__,__LINE__,
421             mysql_error(&mysql));
422     return FALSE;
423   }
424   return TRUE;
425 }
426
427 /******************************************
428 pause the usage of the device for a mac address
429  registered in the management db
430 ******************************************/
431 int pauseMacAddrInMngDb(char* macAddr){
432
433   char queryStr[BUFFMAXLN];
434
435   /* prepare query string */
436   /* don't touch device set as inactive by admin */
437   snprintf(queryStr, BUFFMAXLN, 
438            "update macaddrs set status='P' "
439            " where status='A' and macAddress='%s' and limitDate>now()", 
440            macAddr);
441
442   /* send SQL query */
443   if (mysql_query(&mysql, queryStr)){
444     err_msg("ERR at %s#%d: mysql query: %s",__FILE__,__LINE__,
445             mysql_error(&mysql));
446     return FALSE;
447   }
448   return TRUE;
449 }
450
451 /******************************************
452  is the mac address used in session log
453 ******************************************/
454 int isSessionFoundInMngDb(char* macAddr){
455
456   MYSQL_RES *res=NULL;
457   MYSQL_ROW row;
458   char queryStr[BUFFMAXLN];
459   int ret;
460
461   /* prepare query string */
462   /* get row for addr.entry<session.open<addr.limit */
463   snprintf(queryStr, BUFFMAXLN, 
464            "select * from macaddrs, sessionmd "
465            " where macaddrs.macAddress=sessionmd.macAddress and "
466            " macaddrs.macAddress='%s' and "
467            " entryDate<openTime and openTime<limitDate",
468            macAddr);
469   
470   /* send SQL query */
471   if (mysql_query(&mysql, queryStr)){
472     err_msg("ERR at %s#%d: mysql query: %s",__FILE__,__LINE__,
473             mysql_error(&mysql));
474     return FALSE;
475   }
476   
477   /* store result */
478   res = mysql_store_result(&mysql);
479
480   /* output table name */
481   row = mysql_fetch_row(res);
482   
483   /* if found, return true */
484   if(row!=NULL) ret=TRUE;
485
486   /* if not found, return false */
487   else ret=FALSE;
488
489   mysql_free_result(res);
490   return ret;
491 }
492
493 /*******************************************
494  get next next usage log from management db
495  if end of list, return false
496 *******************************************/
497 int getNextUsageLogFromMngDb(char* userId, char* extraId, char* macAddr, char* deviceName, char* openTime, char* closeTime, char* gatewayName){
498   static MYSQL_RES *res=NULL;
499   MYSQL_ROW row;
500   char queryStr[BUFFMAXLN];
501
502   /* set default values */
503   macAddr[0]=deviceName[0]=openTime[0]=gatewayName[0]='\0';
504
505   /* if do not get result yet */
506   if(res==NULL){
507
508     /* prepare query string */
509     /* get log where addr.entry < session.open < addr.limit */
510     /*  (the same device may be registered by other users in old days) */
511     snprintf(queryStr, BUFFMAXLN, 
512              "select macaddrs.macAddress, device, openTime, closeTime, "
513              " gatewayName "
514              " from macaddrs, sessionmd "
515              " where macaddrs.macAddress=sessionmd.macAddress "
516              " and entryDate < openTime and openTime < limitDate "
517              " and (%s<closeTime or closeTime=0) "
518              " and userId='%s' and extraId='%s'",
519              GetConfValue("ShowLogAfter"), userId, extraId);
520
521     /* send SQL query */
522     if (mysql_query(&mysql, queryStr)){
523       err_msg("ERR at %s#%d: mysql query: %s",__FILE__,__LINE__,
524               mysql_error(&mysql));
525       return FALSE;
526     }
527     
528     /* store result */
529     res = mysql_store_result(&mysql);
530   }
531
532   /* output table name */
533   row = mysql_fetch_row(res);
534
535   /* if found, return values */
536   if(row!=NULL){
537     strlcpy(macAddr, row[0],ADDRMAXLN);
538     strlcpy(deviceName,row[1],WORDMAXLN);
539     strlcpy(openTime,row[2],WORDMAXLN);
540     strlcpy(closeTime,row[3],WORDMAXLN);
541     strlcpy(gatewayName,row[4],WORDMAXLN);
542     return TRUE;
543   }
544   /* if not found, free memory area */
545   else{
546     mysql_free_result(res);
547     return FALSE;
548   }
549 }
550
551
552 /*******************************************
553  get next mail address near limit date
554 from management db 
555 *******************************************/
556 int getNextMailAddressFromMngDb(char* mailAddress, char* limitDate, char* device){
557
558   static MYSQL_RES *res=NULL;
559   MYSQL_ROW row;
560   char queryStr[BUFFMAXLN];
561   char* mailTiming=NULL;
562
563   /* set default values */
564   mailAddress[0]=limitDate[0]='\0';
565
566   /* if do not get result yet */
567   if(res==NULL){
568
569     /* get mail send timing from conf file */
570     mailTiming = GetConfValue("Mail/Timing");
571     if(isNull(mailTiming)) return FALSE;
572
573     /* prepare query string */
574     /* [select mailAddress,limitDate,device from macaddrs 
575         where (  date(now())=date(adddate(limitDate, interval -1 day)) 
576               OR date(now())=date(adddate(limitDate, interval -7 day))  ) 
577              AND (status='A' OR status='P') order by mailAddress,limitDate] */
578     snprintf(queryStr, BUFFMAXLN, 
579              "select mailAddress,limitDate,device from macaddrs "
580              " where (%s) and (status='A' or status='P') "
581              " order by mailAddress,limitDate", mailTiming);
582     /*       mailTiming is a condition string defined in conf file */ 
583
584     /* send SQL query */
585     if (mysql_query(&mysql, queryStr)){
586       err_msg("ERR at %s#%d: mysql query[%s]: %s",__FILE__,__LINE__,queryStr,
587               mysql_error(&mysql));
588       return FALSE;
589     }
590     
591     /* store result */
592     res = mysql_store_result(&mysql);
593   }
594
595   /* output table name */
596   row = mysql_fetch_row(res);
597
598   /* if found, return values */
599   if(row!=NULL){
600     strlcpy(mailAddress, row[0], BUFFMAXLN);
601     strlcpy(limitDate, row[1], WORDMAXLN);
602     strlcpy(device, row[2], WORDMAXLN);
603     return TRUE;
604   }
605   /* if not found, free memory area */
606   else{
607     mysql_free_result(res);
608     return FALSE;
609   }
610 }
611
612 /*******************************************
613  get the date corresponding to ShowLogAfter in conf file
614 *******************************************/
615 int getTimeRangeToShowLog(char* beginTime, char* endTime, int* dateCount){
616
617   static MYSQL_RES *res=NULL;
618   MYSQL_ROW row;
619   char queryStr[BUFFMAXLN];
620   char* showLogAfter;
621   char countStr[WORDMAXLN];
622
623   /* get conf value for beginning day for listing */
624   showLogAfter=GetConfValue("ShowLogAfter");
625   if(isNull(showLogAfter)) return FALSE;
626
627   /* set default values */
628   beginTime[0]='\0';
629   endTime[0]='\0';
630   *dateCount=0;
631
632   /* if do not get result yet */
633   if(res==NULL){
634
635     /* prepare query string */
636     /* select (adddate(now(), interval -1 month)), 
637        now(), 
638        datediff(now(),(adddate(now(), interval -1 month))) + 1; */
639     snprintf(queryStr, BUFFMAXLN, 
640              "select (%s), now(), datediff(now(),(%s)) + 1", 
641              showLogAfter, showLogAfter);
642
643     /* send SQL query */
644     if (mysql_query(&mysql, queryStr)){
645       err_msg("ERR at %s#%d: mysql query[%s]: %s",__FILE__,__LINE__,queryStr,
646               mysql_error(&mysql));
647       return FALSE;
648     }
649     
650     /* store result */
651     res = mysql_store_result(&mysql);
652   }
653
654   /* output table name */
655   row = mysql_fetch_row(res);
656
657   /* if found, return values */
658   if(row!=NULL){
659     strlcpy(beginTime, row[0], WORDMAXLN);
660     strlcpy(endTime, row[1], WORDMAXLN);
661     strlcpy(countStr, row[2], WORDMAXLN);
662     *dateCount=atoi(countStr);
663     return TRUE;
664   }
665   /* if not found, free memory area */
666   else{
667     mysql_free_result(res);
668     return FALSE;
669   }
670 }
671
672 /********************************************
673 rename the device name for indicated mac address
674 ********************************************/
675 int renameDeviceNameInMngDb(char* macAddr, char* nameStr){
676
677   char queryStr[BUFFMAXLN];
678
679   /* prepare query string */
680   snprintf(queryStr, BUFFMAXLN, 
681            "update macaddrs set device='%s' "
682            " where (status='A' or status='P') and macAddress='%s'", 
683            nameStr, macAddr);
684
685   /* send SQL query */
686   if (mysql_query(&mysql, queryStr)){
687     err_msg("ERR at %s#%d: mysql query: %s",__FILE__,__LINE__,
688             mysql_error(&mysql));
689     return FALSE;
690   }
691   return TRUE;
692 }
693
694 /********************************************
695 rename the mail address for indicated mac address
696 ********************************************/
697 int renameMailAddressInMngDb(char* macAddr, char* mailStr){
698
699   char queryStr[BUFFMAXLN];
700
701   /* prepare query string */
702   snprintf(queryStr, BUFFMAXLN, 
703            "update macaddrs set mailAddress='%s' "
704            " where (status='A' or status='P') and macAddress='%s'", 
705            mailStr, macAddr);
706
707   /* send SQL query */
708   if (mysql_query(&mysql, queryStr)){
709     err_msg("ERR at %s#%d: mysql query: %s",__FILE__,__LINE__,
710             mysql_error(&mysql));
711     return FALSE;
712   }
713   return TRUE;
714 }
715
716
717
718 /********************************************
719  routines for debugging output
720 ********************************************/
721
722 int InitMngDb(void){
723   int ret;
724   if(debug>1) err_msg("DEBUG:=>initMngDb()");
725   ret=initMngDb();
726   if(debug>1) err_msg("DEBUG:(%d)<=initMngDb()",ret);
727   return ret;
728 }
729 void CloseMngDb(void){
730   if(debug>1) err_msg("DEBUG:=>closeMngDb()");
731   closeMngDb();
732   if(debug>1) err_msg("DEBUG:<=closeMngDb()");
733 }
734
735 int GetNextMacAddrFromMngDb(char* userId, char* extraId, char* macAddress, char* deviceName, char* entryDate, char* limitDate, char* status, char* mailAddress){
736   int ret;
737   if(debug>1) err_msg("DEBUG:=>getNextMacAddrFromMngDb(%s,%s)",userId,extraId);
738   ret=getNextMacAddrFromMngDb(userId,extraId,macAddress,deviceName,
739                               entryDate,limitDate, status,mailAddress);
740   if(debug>1) err_msg("DEBUG:(%d)<=getNextMacAddrFromMngDb(,,%s,%s,%s,%s,%s,%s)",
741                       ret,macAddress,deviceName,entryDate,limitDate,status,mailAddress);
742   return ret;
743 }
744
745 int RegistMacAddrToMngDb(char* macAddr, char* deviceName, char* userId, char* extraId, char* mailAddress){
746   int ret;
747   if(debug>1) err_msg("DEBUG:=>registMacAddrToMngDb(%s,%s,%s,%s,%s)",
748                       macAddr,deviceName,userId,extraId,mailAddress);
749   ret=registMacAddrToMngDb(macAddr,deviceName,userId,extraId, mailAddress);
750   if(debug>1) err_msg("DEBUG:(%d)<=registMacAddrToMngDb( )",ret);
751   return ret;
752 }
753
754 int IsMacAddrFoundInMngDb(char* macAddr){
755   int ret;
756   if(debug>1) err_msg("DEBUG:=>isMacAddrFoundInMngDb(%s)", macAddr);
757   ret=isMacAddrFoundInMngDb(macAddr);
758   if(debug>1) err_msg("DEBUG:(%d)<=isMacAddrFoundInMngDb( )",ret);
759   return ret;
760 }
761
762 int CountMacAddrsForUserInMngDb(char* userId, char* extraId){
763   int ret;
764   if(debug>1) err_msg("DEBUG:=>countMacAddrsForUserInMngDb(%s,%s)",
765                       userId,extraId);
766   ret=countMacAddrsForUserInMngDb(userId,extraId);
767   if(debug>1) err_msg("DEBUG:(%d)<=countMacAddrsForUserInMngDb( )",ret);
768   return ret;
769 }
770
771 int PutMacModifyLogToMngDb(char* userId, char* extraId, char* macAddr, char modifyType){
772   int ret;
773   if(debug>1) err_msg("DEBUG:=>putMacModifyLogToMngDb(%s,%s,%s,%c)",
774                       userId,extraId,macAddr,modifyType);
775   ret=putMacModifyLogToMngDb(userId,extraId,macAddr,modifyType);
776   if(debug>1) err_msg("DEBUG:(%d)<=putMacModifyLogToMngDb( )",ret);
777   return ret;
778 }
779
780 int GetNicVendorFromMngDb(char* macAddress, char* vendor, int bufferLength){
781   int ret;
782   if(debug>1) err_msg("DEBUG:=>getNicVendorFromMngDb(%s,,%d)",
783                       macAddress, bufferLength);
784   ret=getNicVendorFromMngDb(macAddress, vendor, bufferLength);
785   if(debug>1) err_msg("DEBUG:(%d)<=getNicVendorFromMngDb(%s)",ret, vendor);
786   return ret;
787 }
788
789
790 int CountMacModifyPerDayInMngDb(char* userId, char* extraId){
791   int ret;
792   if(debug>1) err_msg("DEBUG:=>countMacModifyPerDayInMngDb(%s,%s)",
793                       userId,extraId);
794   ret=countMacModifyPerDayInMngDb(userId,extraId);
795   if(debug>1) err_msg("DEBUG:(%d)<=countMacModifyPerDayInMngDb( )",ret);
796   return ret;
797 }
798
799 int DelMacAddrFromMngDb(char* macAddr){
800   int ret;
801   if(debug>1) err_msg("DEBUG:=>delMacAddrFromMngDb(%s)",macAddr);
802   ret=delMacAddrFromMngDb(macAddr);
803   if(debug>1) err_msg("DEBUG:(%d)<=delMacAddrFromMngDb( )",ret);
804   return ret;
805 }
806
807 int RenewMacAddrInMngDb(char* macAddr){
808   int ret;
809   if(debug>1) err_msg("DEBUG:=>renewMacAddrInMngDb(%s)",macAddr);
810   ret=renewMacAddrInMngDb(macAddr);
811   if(debug>1) err_msg("DEBUG:(%d)<=renewMacAddrinMngDb( )",ret);
812   return ret;
813 }
814
815 int PauseMacAddrInMngDb(char* macAddr){
816   int ret;
817   if(debug>1) err_msg("DEBUG:=>pauseMacAddrInMngDb(%s)",macAddr);
818   ret=pauseMacAddrInMngDb(macAddr);
819   if(debug>1) err_msg("DEBUG:(%d)<=pauseMacAddrinMngDb( )",ret);
820   return ret;
821 }
822
823 int IsSessionFoundInMngDb(char* macAddr){
824   int ret;
825   if(debug>1) err_msg("DEBUG:=>isSessionFoundInMngDb(%s)",macAddr);
826   ret=isSessionFoundInMngDb(macAddr);
827   if(debug>1) err_msg("DEBUG:(%d)<=isSessionFoundInMngDb( )",ret);
828   return ret;
829 }
830
831 int GetNextUsageLogFromMngDb(char* userId, char* extraId, char* macAddr, 
832  char* deviceName, char* openTime, char* closeTime, char* gatewayName){
833   int ret;
834   if(debug>1) err_msg("DEBUG:=>getNextUsageLogFromMngDb(%s,%s)",userId,extraId);
835   ret=getNextUsageLogFromMngDb(userId,extraId,macAddr,deviceName,
836                               openTime,closeTime,gatewayName);
837   if(debug>1) err_msg("DEBUG:(%d)<=getNextUsageLogFromMngDb(,,%s,%s,%s,%s,%s)",
838                  ret,macAddr,deviceName,openTime,closeTime,gatewayName);
839   return ret;
840 }
841
842 int GetNextMailAddressFromMngDb(char* mailAddress, char* limitDate, char*device){
843   int ret;
844   if(debug>1) err_msg("DEBUG:=>getnextMailAddressFromMngDb( )");
845   ret=getNextMailAddressFromMngDb(mailAddress, limitDate, device);
846   if(debug>1) err_msg("DEBUG:(%d)<=getNextMailAddressFromMngDb(%s,%s,%s)",
847                       ret,mailAddress,limitDate,device);
848   return ret;
849 }
850
851 int GetTimeRangeToShowLog(char* beginTime, char* endTime, int* dateCount){
852   int ret;
853   if(debug>1) err_msg("DEBUG:=>getTimeRangeToShowLog( )");
854   ret=getTimeRangeToShowLog(beginTime, endTime, dateCount);
855   if(debug>1) err_msg("DEBUG:(%d)<=getTimeRangeToShowLog(%s,%s,%d)",
856                       ret,beginTime,endTime,*dateCount);
857   return ret;
858 }
859
860 int RenameDeviceNameInMngDb(char* macAddr, char* nameStr){
861   int ret;
862   if(debug>1) err_msg("DEBUG:=>renameDevideNameInMngDb(%s,%s)",macAddr,nameStr);
863   ret=renameDeviceNameInMngDb(macAddr, nameStr);
864   if(debug>1) err_msg("DEBUG:(%d)<=renameDeviceNameInMngDb()",ret);
865   return ret;
866 }
867
868 int RenameMailAddressInMngDb(char* macAddr, char* mailStr){
869   int ret;
870   if(debug>1) err_msg("DEBUG:=>renameMailAddressInMngDb(%s,%s)",macAddr,mailStr);
871   ret=renameMailAddressInMngDb(macAddr, mailStr);
872   if(debug>1) err_msg("DEBUG:(%d)<=renameMailAddressInMngDb()",ret);
873   return ret;
874 }