From 292f230cddaf923def3ab757f04dfa39747269a8 Mon Sep 17 00:00:00 2001 From: David Zeuthen Date: Mon, 27 Aug 2007 14:06:30 -0400 Subject: [PATCH] also add another missing file --- tools/polkit-config-file-validate.c | 102 ++++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 tools/polkit-config-file-validate.c diff --git a/tools/polkit-config-file-validate.c b/tools/polkit-config-file-validate.c new file mode 100644 index 0000000..743d4ed --- /dev/null +++ b/tools/polkit-config-file-validate.c @@ -0,0 +1,102 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ +/*************************************************************************** + * + * polkit-config-file-validate.c : validate configuration file + * + * Copyright (C) 2007 David Zeuthen, + * + * 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. + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + **************************************************************************/ + +#ifdef HAVE_CONFIG_H +# include +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +static void +usage (int argc, char *argv[]) +{ + fprintf (stderr, + "\n" + "usage : polkit-policy-file-validate [/path/to/config/file] [--version] [--help]\n"); + fprintf (stderr, + "\n" + " --version Show version and exit\n" + " --help Show this information and exit\n" + "\n" + "Validates if given file is a valid PolicyKit configuration file.\n" + "If no file is given, then /etc/PolicyKit/PolicyKit.conf is validated.\n" + "Returns 0 if the file is valid, otherwise a non-zero exit code is returned.\n"); +} + +int +main (int argc, char *argv[]) +{ + int n; + int ret; + char *path; + PolKitConfig *config; + PolKitError *pk_error; + + ret = 1; + + path = NULL; + for (n = 1; n < argc; n++) { + if (strcmp (argv[n], "--help") == 0) { + usage (argc, argv); + ret = 0; + goto out; + } else if (strcmp (argv[n], "--version") == 0) { + printf ("polkit-config-file-validate " PACKAGE_VERSION "\n"); + ret = 0; + goto out; + } else { + if (path != NULL) { + usage (argc, argv); + goto out; + } + path = argv[n]; + } + } + + if (path == NULL) + path = PACKAGE_SYSCONF_DIR "/PolicyKit/PolicyKit.conf"; + + pk_error = NULL; + config = polkit_config_new (path, &pk_error); + if (config == NULL) { + printf ("Configuration file is malformed: %s\n", polkit_error_get_error_message (pk_error)); + polkit_error_free (pk_error); + goto out; + } + + ret = 0; + +out: + return ret; +} -- 2.7.4