LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 07-24-2008, 09:30 AM   #1
soltanihaji
LQ Newbie
 
Registered: Jul 2008
Posts: 24

Rep: Reputation: 15
Question I found two variables in one source code that have not been defined where


Hi,
I am new in programming in gnome application with C in suse 10.2.

I am developing a source code of firewall that called firestarter version 1.0.0.3.
now in source I saw two variables that their names is FIRESTARTER_RULES_DIR (and ) VERSION but they haven't been defined anywhere. I am confused. I think that maybe them be in header files in C library but FIRESTARTER_RULES_DIR is not seemed be a name in C library.

Please Help me.
for example the below function.in this FIRESTARTER_RULES_DIR haven't been defined any where.



-----------------------------------------------------------------------

#include <config.h>
#include <gnome.h>
#include <sys/stat.h>
#include <stdio.h>
#include <netdb.h>
#include <sys/socket.h>
#include <errno.h>
#include <popt.h>
#include <dirent.h>
#include <sys/types.h>
#include <sys/wait.h>

#include "globals.h"
#include "firestarter.h"
#include "gui.h"
#include "menus.h"
#include "util.h"
#include "logread.h"
#include "wizard.h"
#include "preferences.h"
#include "scriptwriter.h"
#include "dhcp-server.h"
#include "statusview.h"

FirestarterApp Firestarter;

static gint save_session (GnomeClient *client,
gint phase,
GnomeSaveStyle save_style,
gint is_shutdown,
GnomeInteractStyle interact_style,
gint is_fast,
gpointer client_data);

static void session_die (GnomeClient *client,
gpointer client_data);

gboolean firestarter_is_locked (void);

static FirewallStatus firewall_state_prelock;

/* [ stop_firewall ]
* Flushes, zeroes and sets all policies to accept
*/
void
stop_firewall (void)
{
gint retval;
gchar *arg[3] = {"firestarter.sh", "stop", NULL};
gchar *output;
GError *error = NULL;

if (g_spawn_sync (FIRESTARTER_RULES_DIR[/B] "/firestarter",
arg, NULL,
G_SPAWN_STDERR_TO_DEV_NULL,
NULL, NULL,
&output, /* Standard output */
NULL, /* Standard error */
&retval, &error) != TRUE) {
printf ("Error spawning shell process: %s\n", error->message);
}

printf ("%s", output);

if (retval == 0) {
if (!CONSOLE)
status_set_state (STATUS_STOPPED);
} else {
retval = WEXITSTATUS (retval);

if (CONSOLE)
show_error (_("Failed to stop the firewall"));
else
error_dialog (_("Failed to stop the firewall"),
_("Failed to stop the firewall"),
_("There was an undetermined error when trying to stop the firewall."),
Firestarter.window);
}

g_free (output);
}

/* [ start_firewall ]
* Executes the firewall script
*/
void
start_firewall (void)
{
gint retval;
gchar *arg[3] = {"firestarter.sh", "start", NULL};
gchar *output;
GError *error = NULL;

if (g_spawn_sync (FIRESTARTER_RULES_DIR "/firestarter",
arg, NULL,
G_SPAWN_STDERR_TO_DEV_NULL,
NULL, NULL,
&output, /* Standard output */
NULL, /* Standard error */
&retval, &error) != TRUE) {
printf ("Error spawning shell process: %s\n", error->message);
}

printf ("%s", output);

if (retval == 0) {
if (!CONSOLE)
status_set_state (STATUS_RUNNING);
} else {
gchar *message;
retval = WEXITSTATUS (retval);

if (retval == RETURN_EXT_FAILED) {
message = g_strdup_printf (_(
"The device %s is not ready."),
preferences_get_string (PREFS_FW_EXT_IF));
} else if (retval == RETURN_INT_FAILED) {
message = g_strdup_printf (_(
"The device %s is not ready."),
preferences_get_string (PREFS_FW_INT_IF));
} else if (retval == RETURN_NO_IPTABLES) {
message = g_strdup (_("Your kernel does not support iptables."));
} else {
message = g_strdup (_("An unknown error occurred."));
}

message = g_strconcat (message, "\n\n", _(
"Please check your network device settings and make sure your\n"
"Internet connection is active."), NULL);

if (CONSOLE) {
message = g_strconcat (_("Failed to start the firewall\n"),
message, NULL);
show_error (message);
} else {
error_dialog (_("Failed to start the firewall"),
_("Failed to start the firewall"),
message,
Firestarter.window);
status_set_state (STATUS_STOPPED);
}

g_free (message);
}

g_free (output);
}

void
restart_firewall_if_active (void)
{
if (status_get_state () == STATUS_RUNNING ||
status_get_state () == STATUS_HIT)
start_firewall ();
}

/* [ lock_firewall ]
* Flushes and sets all policies to deny
*/
void
lock_firewall (void)
{
gint retval;
gchar *arg[3] = {"firestarter.sh", "lock", NULL};
gchar *output;
GError *error = NULL;

firewall_state_prelock = status_get_state ();

if (g_spawn_sync (FIRESTARTER_RULES_DIR "/firestarter",
arg, NULL,
G_SPAWN_STDERR_TO_DEV_NULL,
NULL, NULL,
&output, /* Standard output */
NULL, /* Standard error */
&retval, &error) != TRUE) {
printf ("Error spawning shell process: %s\n", error->message);
}

printf ("%s", output);

if (retval == 0) {
if (!CONSOLE)
status_set_state (STATUS_LOCKED);
} else {
retval = WEXITSTATUS (retval);

if (CONSOLE)
show_error (_("Failed to lock the firewall"));
else {
error_dialog (_("Failed to lock the firewall"),
_("Failed to lock the firewall"),
_("There was an undetermined error when trying to lock the firewall."),
Firestarter.window);
}
}

g_free (output);
}

/* [ unlock_firewall ]
* Return the firewall to the state prior to locking
*/
void
unlock_firewall (void)
{
if (firewall_state_prelock == STATUS_RUNNING ||
firewall_state_prelock == STATUS_HIT)
start_firewall ();
else
stop_firewall ();
}

/* [ exit_firestarter ]
* Quit firestater
*/
void
exit_firestarter (void)
{
gtk_main_quit ();
}

/* [ save_session ]
* Saves the current session for later revival
*/
static gint
save_session (GnomeClient *client,
gint phase,
GnomeSaveStyle ave_style,
gint is_shutdown,
GnomeInteractStyle interact_style,
gint is_fast,
gpointer client_data)
{
gchar **argv = g_new0 (gchar*, 4);
guint argc = 1;

argv[0] = client_data;
gnome_client_set_clone_command (client, argc, argv);
gnome_client_set_restart_command (client, argc, argv);

return TRUE;
}

/* [ session_die ]
* Gracefully end the session
*/
static void
session_die (GnomeClient *client, gpointer client_data)
{
exit_firestarter ();
}

static const gchar *
get_lock_file_path (void)
{
static gchar *path = NULL;

if (path == NULL) {
DIR *d;

if ((d = opendir ("/var/lock/subsys")) != NULL) {
closedir (d);
path = g_strdup ("/var/lock/subsys/firestarter");
} else if ((d = opendir ("/var/lock")) != NULL) {
closedir (d);
path = g_strdup ("/var/lock/firestarter");
} else {
perror ("Not able to determine a lock file");
}
}

return path;
}

gboolean
firestarter_is_locked (void)
{
return g_file_test (get_lock_file_path (), G_FILE_TEST_EXISTS);
}

static void
show_help (void)
{
gchar *help = g_strconcat (
_("Firestarter"), " ", VERSION "\n\n",
_(" -s, --start Start the firewall\n"
" -p, --stop Stop the firewall\n"
" --lock Lock the firewall, blocking all traffic\n"
" --generate-scripts Generate firewall scripts from current configuration\n"
" --start-hidden Start Firestarter with the GUI not visible\n"
" -v, --version Prints Firestarter's version number\n"
" -h, --help You're looking at it\n"
), NULL);

fprintf (stderr, "%s", help);
g_free (help);
}

static gboolean
is_root (void)
{
if (getuid () != 0) {
if (CONSOLE)
show_error (_("Insufficient privileges"));
else
error_dialog (_("Insufficient privileges"),
_("Insufficient privileges"),
_("You must have root user privileges to use Firestarter."),
Firestarter.window);

return FALSE;
}

return TRUE;
}

/* [ main ]
* The main function, this is where it all begins and ends
*/
int
main (int argc, char* argv[])
{
GnomeClient *client;
gint i;
gboolean must_run_wizard;
gboolean show_gui = TRUE;

/* Text domain and codeset */
bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
textdomain (GETTEXT_PACKAGE);

/* Parse arguments */
for (i = 0; i < argc; i++) {
const char * arg = argv[i];

if (!strcmp (arg, "-s") || !strcmp(arg, "--start")) {
CONSOLE = TRUE;
gnome_program_init ("firestarter", VERSION, LIBGNOME_MODULE, 1, argv, NULL);
if (is_root ())
start_firewall ();
return 0;
} else if (!strcmp (arg, "-p") || !strcmp(arg, "--stop")) {
CONSOLE = TRUE;
gnome_program_init ("firestarter", VERSION, LIBGNOME_MODULE, 1, argv, NULL);
if (is_root ())
stop_firewall ();
return 0;
} else if (!strcmp(arg, "--lock")) {
CONSOLE = TRUE;
gnome_program_init ("firestarter", VERSION, LIBGNOME_MODULE, 1, argv, NULL);
if (is_root ())
lock_firewall ();
return 0;
} else if (!strcmp(arg, "--generate-scripts")) {
CONSOLE = TRUE;
gnome_program_init ("firestarter", VERSION, LIBGNOME_MODULE, 1, argv, NULL);
if (is_root ())
scriptwriter_output_scripts ();
return 0;
} else if (!strcmp(arg, "--start-hidden")) {
show_gui = FALSE;
} else if (!strcmp (arg, "-v") || !strcmp(arg, "--version")) {
printf ("Firestarter %s\n", VERSION);
return 0;
} else if (!strcmp (arg, "-h") || !strcmp (arg, "--help") || !strcmp(arg, "-help")) {
CONSOLE = TRUE;
gnome_program_init ("firestarter", VERSION, LIBGNOME_MODULE, 1, argv, NULL);
show_help ();
return 0;
}
}

gnome_program_init ("firestarter", VERSION, LIBGNOMEUI_MODULE, argc, argv, NULL);

/* Set up the session managment */
client = gnome_master_client ();
g_signal_connect (G_OBJECT (client), "save_yourself",
G_CALLBACK (save_session), argv[0]);
g_signal_connect (G_OBJECT (client), "die",
G_CALLBACK (session_die), NULL);

/* Check that the user is root */
if (!is_root ())
return 1;

/* Check that a valid gconf schema is installed */
preferences_check_schema();

/* If we're starting Firestarter for the first time or the script is missing, create modal wizard */
must_run_wizard = (preferences_get_bool (PREFS_FIRST_RUN) || !script_exists ());

/* Creating the GUI */
gui_construct ();
/* Attach a timeout that keeps the GUI fw status in sync with userland changes */
status_sync_timeout (NULL); /* Do one immediate refresh */
g_timeout_add (5000, status_sync_timeout, NULL);

/* Initialize the system log file polling function */
open_logfile ((gchar *)get_system_log_path ());

if (preferences_get_bool (PREFS_FIRST_RUN))
policyview_install_default_ruleset ();

/* Run wizard, without the main gui visible */
if (must_run_wizard)
run_wizard ();
else {
/* Test that our scripts are up to date */
if (!scriptwriter_versions_match ()) {
printf (_("Updating firewall to new version...\n"));
scriptwriter_output_scripts ();
printf (_("Firewall update complete\n"));
}

if (preferences_get_bool (PREFS_START_ON_GUI))
start_firewall ();

gui_set_visibility (show_gui);
}

gtk_main ();

return 0;
}
 
Old 07-24-2008, 09:56 AM   #2
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
They are probably in the firestarter.h include file that you have listed.

They are not variables; they are #defines. That means that the C compiler takes the string in the define and replaces it with the defined value wherever it occurs, then compiles it as a constant.

For instance, someplace there is probably a line that goes like this:

#define FIRESTARTER_RULES_DIR /my/default/directory/path

Wherever FIRESTARTER_RULES_DIR occurs in the code, /my/default/directory/path is substituted.

If these defines are not defined anywhere, you can define them yourself, however you choose.
 
Old 07-24-2008, 10:16 AM   #3
soltanihaji
LQ Newbie
 
Registered: Jul 2008
Posts: 24

Original Poster
Rep: Reputation: 15
Thanks for your reply.but I saw all where and it doesn't exist.it is wonderful for me ,this program is running in my system and no error occured.
below is firestarter.h


/*---[ firestarter.h ]------------------------------------------------
* Copyright (C) 2000 Tomas Junnonen (majix@sci.fi)
*
* 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 of the License, or
* (at your option) any later version.
*
* The main firestarter header file
*--------------------------------------------------------------------*/

#ifndef _FIRESTARTER_MAIN
#define _FIRESTARTER_MAIN

#include <config.h>
#include <gnome.h>

typedef struct _Hit Hit;

struct _Hit
{
gchar *time;
gchar *direction;
gchar *in;
gchar *out;
gchar *port;
gchar *source;
gchar *destination;
gchar *length;
gchar *tos;
gchar *protocol;
gchar *service;
};

gboolean firestarter_is_locked (void);

void stop_firewall (void);
void start_firewall (void);
void restart_firewall_if_active (void);
void lock_firewall (void);
void unlock_firewall (void);
void exit_firestarter (void);

#endif
 
Old 07-24-2008, 07:56 PM   #4
god_is_good478
Member
 
Registered: Jun 2004
Location: Singapore
Distribution: RH9 FC2/3 Mandrake10 Solaris 9
Posts: 31

Rep: Reputation: 15
check your make file if there is one (it might be define in the compilation line)

also it might be in any of these if these are written in house


#include "globals.h"
#include "firestarter.h"
#include "gui.h"
#include "menus.h"
#include "util.h"
#include "logread.h"
#include "wizard.h"
#include "preferences.h"
#include "scriptwriter.h"
#include "dhcp-server.h"
#include "statusview.h"

Last edited by god_is_good478; 07-24-2008 at 07:59 PM.
 
Old 07-24-2008, 08:15 PM   #5
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 678Reputation: 678Reputation: 678Reputation: 678Reputation: 678Reputation: 678
I don't think you are looking at enough of your packages source files. Also important is the README file. It will probably tell you where and how to define the rules directory.

Most packages are managed using autoconf. The variable may be configured in configure.ac by your distro before they compile the package. Running "configure help" you will probably see an option to redefine this macro if you are compiling it yourself.

It is a common practice to test for a macro definition and use it to change which values in a header file are included.

For an example of this look at the "man 7 feature-test-macros" man pages.

There are a number of places where FIRESTARER_RULES_DIR could be defined.
On the command line preceding or trailing the make command:
FIRESTARTER_RULES_DIR=/etc/firestarter/rules make
There is a difference between these two. Read up on using make to learn the difference.

In a configure.ac file. As an argument when running ./configure. Defined in Makefile. In a header file (there are often many).

The configure command produces the Makefile file and may include a +=FIRESTARTER_RULES_DIR=... line in the generated Makefile.
 
Old 07-25-2008, 12:44 AM   #6
soltanihaji
LQ Newbie
 
Registered: Jul 2008
Posts: 24

Original Poster
Rep: Reputation: 15
Thank you jschiwal for your reply.when I run FIRESTARTER_RULES_DIR=/etc/firestarter/rules make
It runs successfully. but I didn't find FIRESTARTER_RULES_DIR in any file.

I searched in Makefile,Makefile.am,Makefile.in,README,config.h,config.in,config.log,configure,configure.in
but I didn't find exactly "FIRESTARTER_RULES_DIR"

I am confused.
 
Old 07-25-2008, 02:11 AM   #7
jiml8
Senior Member
 
Registered: Sep 2003
Posts: 3,171

Rep: Reputation: 116Reputation: 116
grep is your friend.

And if it isn't defined anyplace, then you get to define it. In fact, you have to.
 
Old 07-25-2008, 05:14 PM   #8
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 678Reputation: 678Reputation: 678Reputation: 678Reputation: 678Reputation: 678
I went to the firestarter website. The instructions for Gentoo involve compiling from source:
Code:
[bash]$ ./configure --sysconfdir=/etc
checking for a BSD compatible install... /usr/bin/install -c
...
So forget about FIRESTARTER_RULES_DIR and enter the sysconfdir in the configure stage.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
mod_python: POST and GET variables, and code caching Mike_W Programming 0 03-07-2008 05:26 AM
LXer: Croatian government defined open source policy LXer Syndicated Linux News 0 07-13-2006 04:21 AM
Linux Script which uses user defined variables fieldyweb Linux - Newbie 3 09-26-2005 06:29 PM
apt-get no source defined luqman Red Hat 17 03-03-2005 09:35 AM
user defined variables linuxdev Linux - Newbie 4 02-09-2004 12:43 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:47 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration