OpenVAS Libraries  9.0.3
nasl-lint.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include "nasl.h"
#include <glib.h>
#include <gio/gio.h>
Include dependency graph for nasl-lint.c:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 Main of the nasl QA linter. More...
 

Detailed Description

Source of the NASL linter of OpenVAS.

Definition in file nasl-lint.c.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Main of the nasl QA linter.

Returns
0 on success

Definition at line 161 of file nasl-lint.c.

References add_nasl_inc_dir(), err, NASL_ALWAYS_SIGNED, NASL_COMMAND_LINE, and NASL_LINT.

162 {
163  int mode = 0;
164  int err = 0;
165  static gboolean debug = FALSE;
166  static gchar *include_dir = NULL;
167  static gchar *nvt_file_list = NULL;
168  static const gchar **nvt_files = NULL;
169  struct arglist *script_infos = g_malloc0 (sizeof (struct arglist));
170  GError *error = NULL;
171  GOptionContext *option_context;
172  static GOptionEntry entries[] = {
173  {"debug", 'd', 0, G_OPTION_ARG_NONE, &debug,
174  "Output debug log messages.", NULL},
175  {"nvt-list", 'l', 0, G_OPTION_ARG_STRING, &nvt_file_list,
176  "Process files from <file>", "<file>"},
177  {"include-dir", 'i', 0, G_OPTION_ARG_STRING, &include_dir,
178  "Search for includes in <dir>", "<dir>"},
179  {G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &nvt_files,
180  "Absolute path to one or more nasl scripts", "NASL_FILE..."},
181  {NULL}
182  };
183 
184  option_context =
185  g_option_context_new ("- standalone NASL linter for OpenVAS");
186  g_option_context_add_main_entries (option_context, entries, NULL);
187  if (!g_option_context_parse (option_context, &argc, &argv, &error))
188  {
189  g_error ("%s\n\n", error->message);
190  }
191  g_option_context_free (option_context);
192 
193 #if !GLIB_CHECK_VERSION(2, 35, 0)
194  g_type_init();
195 #endif
196 
197  mode |= NASL_COMMAND_LINE;
198  /* authenticated mode */
199  mode |= NASL_ALWAYS_SIGNED;
200  /* linter on */
201  mode |= NASL_LINT;
202 
203  /* For relative include */
204  add_nasl_inc_dir ("");
205  /* For absolute include (if given on command line) */
206  if (include_dir != NULL)
207  add_nasl_inc_dir (include_dir);
208 
209  if (debug)
210  g_log_set_handler (NULL,
211  G_LOG_LEVEL_MASK,
212  custom_log_handler,
213  GINT_TO_POINTER (G_LOG_LEVEL_DEBUG|G_LOG_LEVEL_INFO|
214  G_LOG_LEVEL_MESSAGE|
215  G_LOG_LEVEL_WARNING|
216  G_LOG_LEVEL_CRITICAL|
217  G_LOG_LEVEL_ERROR));
218  else
219  g_log_set_handler (NULL,
220  G_LOG_LEVEL_MASK,
221  custom_log_handler,
222  GINT_TO_POINTER (G_LOG_LEVEL_WARNING|
223  G_LOG_LEVEL_CRITICAL|
224  G_LOG_LEVEL_ERROR));
225 
226  /* Process the files from the list */
227  if (nvt_file_list != NULL)
228  err += process_file_list(nvt_file_list, mode, script_infos);
229 
230  /* process the files from the command line */
231  if (nvt_files != NULL)
232  err += process_files(nvt_files, mode, script_infos);
233 
234  g_print ("%d errors found\n", err);
235  return err;
236 }
#define err(x)
#define NASL_COMMAND_LINE
Definition: nasl.h:63
#define NASL_LINT
Definition: nasl.h:64
#define NASL_ALWAYS_SIGNED
Definition: nasl.h:62
int add_nasl_inc_dir(const char *)
Adds the given string as directory for searching for includes.
Here is the call graph for this function: