Commit 01b261ee authored by David Zeuthen's avatar David Zeuthen

make polkit-privilege-file-validate accept multiple files

parent 936ca49e
......@@ -8,7 +8,7 @@ polkit-privilege-file-validate \- check access
.SH SYNOPSIS
.PP
.B polkit-privilege-file-validate
[options]
<privilege-files>
.SH DESCRIPTION
......@@ -23,9 +23,6 @@ depending on the distribution.
.SH OPTIONS
The following options are supported:
.TP
.I "--file"
File to validate.
.TP
.I "--help"
Print out usage.
.TP
......@@ -34,8 +31,8 @@ Print the version.
.SH RETURN VALUE
.PP
If the file validates, this program exits with exit code 0. Otherwise
the program exits with a non-zero exit code.
If the given files are all valid, this program exits with exit code
0. Otherwise the program exits with a non-zero exit code.
.SH BUGS
.PP
......
......@@ -130,7 +130,7 @@ main (int argc, char *argv[])
}
if (is_version) {
printf ("pk-can-caller-access-resource " PACKAGE_VERSION "\n");
printf ("polkit-check-caller " PACKAGE_VERSION "\n");
return 0;
}
......@@ -147,9 +147,9 @@ main (int argc, char *argv[])
}
g_error = NULL;
pol_ctx = libpolkit_context_new (&g_error);
if (pol_ctx == NULL) {
fprintf (stderr, "error: libpolkit_context_new: %s\n", g_error->message);
pol_ctx = libpolkit_context_new ();
if (!libpolkit_context_init (pol_ctx, &g_error)) {
fprintf (stderr, "error: libpolkit_context_init: %s\n", g_error->message);
g_error_free (g_error);
return 1;
}
......
......@@ -133,7 +133,7 @@ main (int argc, char *argv[])
}
if (is_version) {
printf ("pk-can-caller-access-resource " PACKAGE_VERSION "\n");
printf ("polkit-check-session " PACKAGE_VERSION "\n");
return 0;
}
......@@ -150,9 +150,9 @@ main (int argc, char *argv[])
}
g_error = NULL;
pol_ctx = libpolkit_context_new (&g_error);
if (pol_ctx == NULL) {
fprintf (stderr, "error: libpolkit_context_new: %s\n", g_error->message);
pol_ctx = libpolkit_context_new ();
if (!libpolkit_context_init (pol_ctx, &g_error)) {
fprintf (stderr, "error: libpolkit_context_init: %s\n", g_error->message);
g_error_free (g_error);
return 1;
}
......
......@@ -42,96 +42,57 @@ usage (int argc, char *argv[])
{
fprintf (stderr,
"\n"
"usage : polkit-privilege-file-validate --file <privilege-file>\n"
"usage : polkit-privilege-file-validate <privilege-files>\n"
" [--version] [--help]\n");
fprintf (stderr,
"\n"
" --file File to validate\n"
" --version Show version and exit\n"
" --help Show this information and exit\n"
"\n"
"Validates a PolicyKit privilege file. Returns 0 if it validates. If\n"
"not, the program exits with a non-zero exit code.\n");
"Validates one or more PolicyKit privilege file. Returns 0 if it validates.\n"
"If not, the program exits with a non-zero exit code.\n");
}
int
main (int argc, char *argv[])
static gboolean
validate_file (const char *file)
{
char *file = NULL;
gboolean is_version = FALSE;
gboolean validated;
PolKitPrivilegeFile *priv_file;
GError *error = NULL;
validated = FALSE;
if (argc <= 1) {
usage (argc, argv);
goto out;
}
while (1) {
int c;
int option_index = 0;
const char *opt;
static struct option long_options[] = {
{"file", 1, NULL, 0},
{"version", 0, NULL, 0},
{"help", 0, NULL, 0},
{NULL, 0, NULL, 0}
};
c = getopt_long (argc, argv, "",
long_options, &option_index);
if (c == -1)
break;
switch (c) {
case 0:
opt = long_options[option_index].name;
if (strcmp (opt, "help") == 0) {
usage (argc, argv);
return 0;
} else if (strcmp (opt, "version") == 0) {
is_version = TRUE;
} else if (strcmp (opt, "file") == 0) {
file = g_strdup (optarg);
}
break;
default:
usage (argc, argv);
goto out;
}
}
if (is_version) {
printf ("pk-privilege-file-validate " PACKAGE_VERSION "\n");
return 0;
}
if (file == NULL) {
usage (argc, argv);
goto out;
}
priv_file = libpolkit_privilege_file_new (file, &error);
if (priv_file == NULL) {
printf ("%s did not validate: %s\n", file, error->message);
g_error_free (error);
goto out;
return FALSE;
}
validated = TRUE;
libpolkit_privilege_file_unref (priv_file);
return TRUE;
}
out:
if (file != NULL)
g_free (file);
int
main (int argc, char *argv[])
{
int n;
if (validated)
return 0;
else
if (argc <= 1) {
usage (argc, argv);
return 1;
}
for (n = 1; n < argc; n++) {
if (strcmp (argv[n], "--help") == 0) {
usage (argc, argv);
return 0;
}
if (strcmp (argv[n], "--version") == 0) {
printf ("polkit-privilege-file-validate " PACKAGE_VERSION "\n");
return 0;
}
if (!validate_file (argv[n])) {
return 1;
}
}
return 0;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment