File: ebncheck.c

package info (click to toggle)
ebnetd 1%3A1.0.dfsg.1-4.3
  • links: PTS
  • area: main
  • in suites: buster, jessie, jessie-kfreebsd, stretch, wheezy
  • size: 3,720 kB
  • ctags: 1,649
  • sloc: ansic: 16,691; sh: 9,042; perl: 935; makefile: 282
file content (245 lines) | stat: -rw-r--r-- 5,503 bytes parent folder | download | duplicates (9)
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/*
 * Copyright (c) 1997, 98, 99, 2000, 01  
 *    Motoyuki Kasahara
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 */

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <stdio.h>
#include <sys/types.h>

#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
#include <string.h>
#if !defined(STDC_HEADERS) && defined(HAVE_MEMORY_H)
#include <memory.h>
#endif /* not STDC_HEADERS and HAVE_MEMORY_H */
#else /* not STDC_HEADERS and not HAVE_STRING_H */
#include <strings.h>
#endif /* not STDC_HEADERS and not HAVE_STRING_H */

#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif

#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif

#ifdef HAVE_LIMITS_H
#include <limits.h>
#endif

#ifdef HAVE_LOCALE_H
#include <locale.h>
#endif

#ifndef HAVE_STRCHR
#define strchr index
#define strrchr rindex
#endif /* HAVE_STRCHR */

/*
 * The maximum length of path name.
 */
#ifndef PATH_MAX
#ifdef MAXPATHLEN
#define PATH_MAX        MAXPATHLEN
#else /* not MAXPATHLEN */
#define PATH_MAX        1024
#endif /* not MAXPATHLEN */
#endif /* not PATH_MAX */

#include "fakelog.h"
#include "getopt.h"
#include "hostname.h"
#include "permission.h"
#include "readconf.h"
#include "wildcard.h"

#include "defs.h"

/*
 * Unexported functions.
 */
static void output_help EBNETD_P((void));

/*
 * Command line options.
 */
static const char *short_options = "c:dhv";
static struct option long_options[] = {
    {"configuration-file", required_argument, NULL, 'c'},
    {"debug",              no_argument,       NULL, 'd'},
    {"help",               no_argument,       NULL, 'h'},
    {"verbose",            no_argument,       NULL, 'd'},
    {"version",            no_argument,       NULL, 'v'},
    {NULL, 0, NULL, 0}
};


int
main(argc, argv)
    int argc;
    char *argv[];
{
    EB_Error_Code error_code;
    int ch;

    /*
     * We must output US-ASCII syslog messages.
     */
#ifdef HAVE_SETLOCALE
    setlocale(LC_ALL, "C");
#endif

    /*
     * Set program name and version.
     */
    invoked_name = argv[0];
    program_name = CHECK_PROGRAM_NAME;
    program_version = VERSION;

    /*
     * Initialize EB Library.
     */
    error_code = eb_initialize_library();
    if (error_code != EB_SUCCESS) {
	syslog(LOG_ERR, "%s\n", eb_error_message(error_code));
	exit(1);
    }

    /*
     * Initialize global and static variables.
     */
    server_mode = SERVER_MODE_CHECK;
    initialize_global_variables();

    if (PATH_MAX < strlen(DEFAULT_CONFIGURATION_FILE_NAME)) {
	fprintf(stderr,
	    "%s: internal error, too long DEFAULT_CONFIGURATION_FILE_NAME\n",
	    invoked_name);
	exit(1);
    }
    strcpy(configuration_file_name, DEFAULT_CONFIGURATION_FILE_NAME);

    /*
     * Set fakelog behavior.
     */
    set_fakelog_name(invoked_name);
    set_fakelog_mode(FAKELOG_TO_STDERR);
    set_fakelog_level(LOG_ERR);

    /*
     * Parse command line options.
     */
    for (;;) {
	ch = getopt_long(argc, argv, short_options, long_options, NULL);
	if (ch == -1)
	    break;
	switch (ch) {
	case 'c':
	    /*
	     * Option `-c file'.  Specify a configuration file name.
	     */
	    if (PATH_MAX < strlen(optarg)) {
		fprintf(stderr, "%s: too long configuration file_name\n",
		    invoked_name);
		fflush(stderr);
		exit(1);
	    }
	    strcpy(configuration_file_name, optarg);
	    break;

	case 'd':
	    /*
	     * Option `-d'.  Debug mode.
	     */
	    set_fakelog_level(LOG_DEBUG);
	    break;

	case 'h':
	    /*
	     * Option `-h'.  Help.
	     */
	    output_help();
	    exit(0);

	case 'v':
	    /*
	     * Option `-v'.  Show the version number.
	     */
	    output_version();
	    exit(0);

	default:
	    output_try_help();
	    exit(1);
	}
    }

    /*
     * Check for the number of rest arguments.
     */
    if (0 < argc - optind) {
	fprintf(stderr, "%s: too many arguments\n", invoked_name);
	output_try_help();
	exit(1);
    }

    /*
     * Read the configuration file.
     */
    if (read_configuration(configuration_file_name, configuration_table) < 0) {
	fprintf(stderr, "%s: configuration failure\n", invoked_name);
	fflush(stderr);
	exit(1);
    }

    /*
     * Finalize global and static variables.
     */
    finalize_global_variables();

    /*
     * Finalize EB Library.
     */
    eb_finalize_library();
    
    return 0;
}


/*
 * Output the usage to standard out.
 */
static void
output_help()
{
    printf("Usage: %s [option...]\n", program_name);
    printf("Options:\n");
    printf("  -c FILE  --configuration-file FILE\n");
    printf("                             specify a configuration file\n");
    printf("                             (default: %s)\n",
	DEFAULT_CONFIGURATION_FILE_NAME);
    printf("  -d  --debug  --verbose     degug mode\n");
    printf("  -h  --help                 display this help, then exit\n");
    printf("  -v  --version              display version number, then exit\n");
    printf("\nDefault value used in a configuration file:\n");
    printf("  work-path                  %s\n", DEFAULT_WORK_PATH);
    printf("\nReport bugs to %s.\n", MAILING_ADDRESS);
    fflush(stdout);
}