Reformated text.
This commit is contained in:
1 parent
bcb7c68911
commit
787ece6c01
19 files changed
+541
-332
No files matched your search
+82
-44
@@ -1,4 +1,4 @@
|
||||
/* $Id: tinyproxy.c,v 1.18 2001-10-25 17:27:39 rjkaes Exp $
|
||||
/* $Id: tinyproxy.c,v 1.19 2001-11-22 00:31:10 rjkaes Exp $
|
||||
*
|
||||
* The initialise routine. Basically sets up all the initial stuff (logfile,
|
||||
* listening socket, config options, etc.) and then sits there and loops
|
||||
@@ -49,7 +49,8 @@ float load = 0.00;
|
||||
/*
|
||||
* Handle a signal
|
||||
*/
|
||||
void takesig(int sig)
|
||||
void
|
||||
takesig(int sig)
|
||||
{
|
||||
switch (sig) {
|
||||
case SIGHUP:
|
||||
@@ -62,7 +63,8 @@ void takesig(int sig)
|
||||
|
||||
rename_file = safemalloc(strlen(config.logf_name) + 5);
|
||||
if (!rename_file) {
|
||||
fprintf(stderr, "Could not allocate memory in signal handler!\n");
|
||||
fprintf(stderr,
|
||||
"Could not allocate memory in signal handler!\n");
|
||||
exit(EX_OSERR);
|
||||
}
|
||||
|
||||
@@ -73,14 +75,16 @@ void takesig(int sig)
|
||||
|
||||
log_file_des = create_file_safely(config.logf_name);
|
||||
if (log_file_des < 0) {
|
||||
fprintf(stderr, "Could not safely create new log file.\n");
|
||||
fprintf(stderr,
|
||||
"Could not safely create new log file.\n");
|
||||
exit(EX_OSERR);
|
||||
}
|
||||
|
||||
old_fd = config.logf;
|
||||
|
||||
|
||||
if (!(config.logf = fdopen(log_file_des, "w"))) {
|
||||
fprintf(stderr, "Could not create new log file.\n");
|
||||
fprintf(stderr,
|
||||
"Could not create new log file.\n");
|
||||
exit(EX_CANTCREAT);
|
||||
}
|
||||
|
||||
@@ -90,7 +94,6 @@ void takesig(int sig)
|
||||
|
||||
safefree(rename_file);
|
||||
}
|
||||
|
||||
#ifdef FILTER_ENABLE
|
||||
if (config.filter) {
|
||||
filter_destroy();
|
||||
@@ -98,7 +101,8 @@ void takesig(int sig)
|
||||
}
|
||||
log_message(LOG_NOTICE, "Re-reading filter file.");
|
||||
#endif /* FILTER_ENABLE */
|
||||
log_message(LOG_NOTICE, "Finished cleaning memory/connections.");
|
||||
log_message(LOG_NOTICE,
|
||||
"Finished cleaning memory/connections.");
|
||||
break;
|
||||
case SIGTERM:
|
||||
#ifdef FILTER_ENABLE
|
||||
@@ -118,7 +122,8 @@ void takesig(int sig)
|
||||
/*
|
||||
* Display the version information for the user.
|
||||
*/
|
||||
static void display_version(void)
|
||||
static void
|
||||
display_version(void)
|
||||
{
|
||||
printf("%s %s (%s)\n", PACKAGE, VERSION, TARGET_SYSTEM);
|
||||
}
|
||||
@@ -126,7 +131,8 @@ static void display_version(void)
|
||||
/*
|
||||
* Display the copyright and license for this program.
|
||||
*/
|
||||
static void display_license(void)
|
||||
static void
|
||||
display_license(void)
|
||||
{
|
||||
display_version();
|
||||
|
||||
@@ -154,7 +160,8 @@ static void display_license(void)
|
||||
/*
|
||||
* Display usage to the user.
|
||||
*/
|
||||
static void display_usage(void)
|
||||
static void
|
||||
display_usage(void)
|
||||
{
|
||||
printf("Usage: %s [options]\n", PACKAGE);
|
||||
printf("\
|
||||
@@ -165,7 +172,6 @@ Options:\n\
|
||||
-l Display the license.\n\
|
||||
-v Display the version number.\n");
|
||||
|
||||
|
||||
/* Display the modes compiled into tinyproxy */
|
||||
printf("\nFeatures Compiled In:\n");
|
||||
#ifdef XTINYPROXY_ENABLE
|
||||
@@ -183,7 +189,8 @@ Options:\n\
|
||||
#endif /* TUNNEL_SUPPORT */
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
int optch;
|
||||
bool_t godaemon = TRUE;
|
||||
@@ -195,18 +202,18 @@ int main(int argc, char **argv)
|
||||
* Disable the creation of CORE files right up front.
|
||||
*/
|
||||
#ifdef HAVE_SETRLIMIT
|
||||
struct rlimit core_limit = {0, 0};
|
||||
struct rlimit core_limit = { 0, 0 };
|
||||
if (setrlimit(RLIMIT_CORE, &core_limit) < 0) {
|
||||
fprintf(stderr, "%s: Could not set the core limit to zero.\n", argv[0]);
|
||||
fprintf(stderr, "%s: Could not set the core limit to zero.\n",
|
||||
argv[0]);
|
||||
exit(EX_SOFTWARE);
|
||||
}
|
||||
#endif /* HAVE_SETRLIMIT */
|
||||
#endif /* HAVE_SETRLIMIT */
|
||||
|
||||
/*
|
||||
* Process the various options
|
||||
*/
|
||||
while ((optch = getopt(argc, argv, "c:vldh")) !=
|
||||
EOF) {
|
||||
while ((optch = getopt(argc, argv, "c:vldh")) != EOF) {
|
||||
switch (optch) {
|
||||
case 'v':
|
||||
display_version();
|
||||
@@ -220,13 +227,15 @@ int main(int argc, char **argv)
|
||||
case 'c':
|
||||
conf_file = strdup(optarg);
|
||||
if (!conf_file) {
|
||||
fprintf(stderr, "%s: Could not allocate memory.\n", argv[0]);
|
||||
fprintf(stderr,
|
||||
"%s: Could not allocate memory.\n",
|
||||
argv[0]);
|
||||
exit(EX_SOFTWARE);
|
||||
}
|
||||
break;
|
||||
case 'h':
|
||||
default:
|
||||
display_usage();
|
||||
display_usage();
|
||||
exit(EX_OK);
|
||||
}
|
||||
}
|
||||
@@ -236,14 +245,18 @@ int main(int argc, char **argv)
|
||||
*/
|
||||
yyin = fopen(conf_file, "r");
|
||||
if (!yyin) {
|
||||
fprintf(stderr, "%s: Could not open configuration file \"%s\".\n", argv[0], conf_file);
|
||||
fprintf(stderr,
|
||||
"%s: Could not open configuration file \"%s\".\n",
|
||||
argv[0], conf_file);
|
||||
exit(EX_SOFTWARE);
|
||||
}
|
||||
yyparse();
|
||||
|
||||
#if defined(TUNNEL_SUPPORT) && defined(UPSTREAM_SUPPORT)
|
||||
if (config.tunnel_name && config.upstream_name) {
|
||||
fprintf(stderr, "%s: \"Tunnel\" and \"Upstream\" directives can not be both set.\n", argv[0]);
|
||||
fprintf(stderr,
|
||||
"%s: \"Tunnel\" and \"Upstream\" directives can not be both set.\n",
|
||||
argv[0]);
|
||||
exit(EX_SOFTWARE);
|
||||
}
|
||||
#endif
|
||||
@@ -253,19 +266,24 @@ int main(int argc, char **argv)
|
||||
int log_file_fd;
|
||||
|
||||
if (!config.logf_name) {
|
||||
fprintf(stderr, "%s: You MUST set a LogFile in the configuration file.\n", argv[0]);
|
||||
fprintf(stderr,
|
||||
"%s: You MUST set a LogFile in the configuration file.\n",
|
||||
argv[0]);
|
||||
exit(EX_SOFTWARE);
|
||||
}
|
||||
|
||||
log_file_fd = create_file_safely(config.logf_name);
|
||||
if (log_file_fd < 0) {
|
||||
fprintf(stderr, "Could not safely create logfile \"%s\".\n", config.logf_name);
|
||||
fprintf(stderr,
|
||||
"Could not safely create logfile \"%s\".\n",
|
||||
config.logf_name);
|
||||
exit(EX_CANTCREAT);
|
||||
}
|
||||
|
||||
config.logf = fdopen(log_file_fd, "w");
|
||||
if (!config.logf) {
|
||||
fprintf(stderr, "Could not write to log file \"%s\".\n", config.logf_name);
|
||||
fprintf(stderr, "Could not write to log file \"%s\".\n",
|
||||
config.logf_name);
|
||||
exit(EX_CANTCREAT);
|
||||
}
|
||||
} else {
|
||||
@@ -281,18 +299,23 @@ int main(int argc, char **argv)
|
||||
* Set the default values if they were not set in the config file.
|
||||
*/
|
||||
if (config.port == 0) {
|
||||
fprintf(stderr, "%s: You MUST set a Port in the configuration file.\n", argv[0]);
|
||||
fprintf(stderr,
|
||||
"%s: You MUST set a Port in the configuration file.\n",
|
||||
argv[0]);
|
||||
exit(EX_SOFTWARE);
|
||||
}
|
||||
if (!config.stathost) {
|
||||
log_message(LOG_INFO, "Setting stathost to \"%s\".", DEFAULT_STATHOST);
|
||||
log_message(LOG_INFO, "Setting stathost to \"%s\".",
|
||||
DEFAULT_STATHOST);
|
||||
config.stathost = DEFAULT_STATHOST;
|
||||
}
|
||||
if (!config.username) {
|
||||
log_message(LOG_WARNING, "You SHOULD set a UserName in the configuration file. Using current user instead.");
|
||||
log_message(LOG_WARNING,
|
||||
"You SHOULD set a UserName in the configuration file. Using current user instead.");
|
||||
}
|
||||
if (config.idletimeout == 0) {
|
||||
log_message(LOG_INFO, "Setting idle timeout to %u seconds.", MAX_IDLE_TIME);
|
||||
log_message(LOG_INFO, "Setting idle timeout to %u seconds.",
|
||||
MAX_IDLE_TIME);
|
||||
config.idletimeout = MAX_IDLE_TIME;
|
||||
}
|
||||
|
||||
@@ -318,10 +341,10 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) {
|
||||
fprintf(stderr, "%s: Could not set the \"SIGPIPE\" signal.\n", argv[0]);
|
||||
fprintf(stderr, "%s: Could not set the \"SIGPIPE\" signal.\n",
|
||||
argv[0]);
|
||||
exit(EX_OSERR);
|
||||
}
|
||||
|
||||
#ifdef FILTER_ENABLE
|
||||
if (config.filter)
|
||||
filter_init();
|
||||
@@ -331,7 +354,8 @@ int main(int argc, char **argv)
|
||||
* Start listening on the selected port.
|
||||
*/
|
||||
if (thread_listening_sock(config.port) < 0) {
|
||||
fprintf(stderr, "%s: Could not create listening socket.\n", argv[0]);
|
||||
fprintf(stderr, "%s: Could not create listening socket.\n",
|
||||
argv[0]);
|
||||
exit(EX_OSERR);
|
||||
}
|
||||
|
||||
@@ -342,33 +366,45 @@ int main(int argc, char **argv)
|
||||
if (config.group && strlen(config.group) > 0) {
|
||||
thisgroup = getgrnam(config.group);
|
||||
if (!thisgroup) {
|
||||
fprintf(stderr, "%s: Unable to find group \"%s\".\n", argv[0], config.group);
|
||||
fprintf(stderr,
|
||||
"%s: Unable to find group \"%s\".\n",
|
||||
argv[0], config.group);
|
||||
exit(EX_NOUSER);
|
||||
}
|
||||
if (setgid(thisgroup->gr_gid) < 0) {
|
||||
fprintf(stderr, "%s: Unable to change to group \"%s\".\n", argv[0], config.group);
|
||||
fprintf(stderr,
|
||||
"%s: Unable to change to group \"%s\".\n",
|
||||
argv[0], config.group);
|
||||
exit(EX_CANTCREAT);
|
||||
}
|
||||
log_message(LOG_INFO, "Now running as group \"%s\".", config.group);
|
||||
log_message(LOG_INFO, "Now running as group \"%s\".",
|
||||
config.group);
|
||||
}
|
||||
if (config.username && strlen(config.username) > 0) {
|
||||
thisuser = getpwnam(config.username);
|
||||
if (!thisuser) {
|
||||
fprintf(stderr, "%s: Unable to find user \"%s\".", argv[0], config.username);
|
||||
fprintf(stderr,
|
||||
"%s: Unable to find user \"%s\".",
|
||||
argv[0], config.username);
|
||||
exit(EX_NOUSER);
|
||||
}
|
||||
if (setuid(thisuser->pw_uid) < 0) {
|
||||
fprintf(stderr, "%s: Unable to change to user \"%s\".", argv[0], config.username);
|
||||
fprintf(stderr,
|
||||
"%s: Unable to change to user \"%s\".",
|
||||
argv[0], config.username);
|
||||
exit(EX_CANTCREAT);
|
||||
}
|
||||
log_message(LOG_INFO, "Now running as user \"%s\".", config.username);
|
||||
log_message(LOG_INFO, "Now running as user \"%s\".",
|
||||
config.username);
|
||||
}
|
||||
} else {
|
||||
log_message(LOG_WARNING, "Not running as root, so not changing UID/GID.");
|
||||
log_message(LOG_WARNING,
|
||||
"Not running as root, so not changing UID/GID.");
|
||||
}
|
||||
|
||||
if (thread_pool_create() < 0) {
|
||||
fprintf(stderr, "%s: Could not create the pool of threads.", argv[0]);
|
||||
fprintf(stderr, "%s: Could not create the pool of threads.",
|
||||
argv[0]);
|
||||
exit(EX_SOFTWARE);
|
||||
}
|
||||
|
||||
@@ -377,11 +413,13 @@ int main(int argc, char **argv)
|
||||
*/
|
||||
log_message(LOG_INFO, "Setting the various signals.");
|
||||
if (signal(SIGTERM, takesig) == SIG_ERR) {
|
||||
fprintf(stderr, "%s: Could not set the \"SIGTERM\" signal.\n", argv[0]);
|
||||
fprintf(stderr, "%s: Could not set the \"SIGTERM\" signal.\n",
|
||||
argv[0]);
|
||||
exit(EX_OSERR);
|
||||
}
|
||||
if (signal(SIGHUP, takesig) == SIG_ERR) {
|
||||
fprintf(stderr, "%s: Could not set the \"SIGHUP\" signal.\n", argv[0]);
|
||||
fprintf(stderr, "%s: Could not set the \"SIGHUP\" signal.\n",
|
||||
argv[0]);
|
||||
exit(EX_OSERR);
|
||||
}
|
||||
|
||||
@@ -401,10 +439,10 @@ int main(int argc, char **argv)
|
||||
* Remove the PID file.
|
||||
*/
|
||||
if (unlink(config.pidpath) < 0) {
|
||||
log_message(LOG_WARNING, "Could not remove PID file \"%s\": %s.",
|
||||
log_message(LOG_WARNING,
|
||||
"Could not remove PID file \"%s\": %s.",
|
||||
config.pidpath, strerror(errno));
|
||||
}
|
||||
|
||||
#ifdef FILTER_ENABLE
|
||||
if (config.filter)
|
||||
filter_destroy();
|
||||
|
||||
Reference in new issue
Block a user