summaryrefslogtreecommitdiff
path: root/tools/polkit-config-file-validate.c
blob: d89feb0cb63968cd0e870587be9dd1e5efe4c683 (plain)
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
/* -*- 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, <david@fubar.dk>
 *
 * 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 <config.h>
#endif

#include <stdbool.h>
#include <getopt.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <pwd.h>
#include <grp.h>
#include <unistd.h>
#include <errno.h>

#include <polkit/polkit.h>

static void
usage (int argc, char *argv[])
{
        execlp ("man", "man", "polkit-config-file-validate", NULL);
        fprintf (stderr, "Cannot show man page: %m\n");
        exit (1);
}

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;
}