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
|
/*-
* Copyright (c) 1998-2005 Joao Cabral
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* DHIS(c) Dynamic Host Information System Release 5
*/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#include<time.h>
#include<sys/time.h>
#include<sys/types.h>
#include<netdb.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<netinet/in.h>
#include<sys/socket.h>
#include<arpa/inet.h>
#include<arpa/nameser.h>
#include<resolv.h>
#include<sys/utsname.h>
#include<unistd.h>
#include<signal.h>
#include<sys/signal.h>
#include<sys/wait.h>
#include<syslog.h>
// #include<varargs.h>
#include<gmp.h>
#define BOURNE_SHELL "/bin/sh"
#define DHIS_VERSION 52 /* Current version */
#define DHIS_RELEASE 52 /* Current release */
#define DHIS_R4 40 /* R4 starting version */
#define DHIS_MIN_VERSION 30 /* Minimum required version to run */
#define KA_OFFLINE 300 /* timeout for R3 clients */
#define PARSE_TIMEOUT 60 /* frequency of parse in sec */
#define MIN_NEXT_CHECK 60 /* mim allowed refresh */
#define NEXT_CHECK 120 /* default refresh */
#define MAX_NEXT_CHECK (60*60*6) /* max allowed refresh secs */
#define CHECK_FAILS 3 /* maximum check fails */
#define DHISD_PORT 58800
#define DHISD_PID "/var/run/dhisd.pid"
#define DHISD_DB "/etc/dhis-server/dhis.db"
#define DHISD_LOG "/var/log/dhisd.log"
#define DHISD_SERVICES "/etc/dhis-server/services.db"
#define MAX_HOSTNAME 64
#define MAX_PASS 16
/* R3 messages */
#define R3_ONLINE_REQ 0x00000311
#define R3_OFFLINE_REQ 0x00000312
/* R4 messages */
#define R4_ECHO_REQ 0x00000411
#define R4_ECHO_ACK 0x00000412
#define R4_AUTH_REQ 0x00000421
#define R4_AUTH_DENY 0x00000422
#define R4_AUTH_ACK 0x00000423
#define R4_AUTH_SX 0x00000424
#define R4_AUTH_SY 0x00000425
#define R4_CHECK_REQ 0x00000441
#define R4_CHECK_ACK 0x00000442
#define R4_OFFLINE_REQ 0x00000451
/* R5 messages */
#define ECHO_REQ 0x00000511
#define ECHO_ACK 0x00000512
#define AUTH_REQ 0x00000521
#define AUTH_DENY 0x00000522
#define AUTH_ACK 0x00000523
#define AUTH_SX 0x00000524
#define AUTH_SY 0x00000525
#define R51_AUTH_ACK 0x00000526
#define CHECK_REQ 0x00000541
#define CHECK_ACK 0x00000542
#define OFFLINE_REQ 0x00000551
#define APASS 1
#define AQRC 2
extern int debug;
#define DSYSLOG(d,m) \
do { \
if (debug>=d) \
syslog m; \
} while(0)
|