/***************************************************************************
* CVSID: $Id$
*
* hal-is-caller-privileged.c : Determine if a caller is privileged
*
* Copyright (C) 2007 David Zeuthen, <david@fubar.dk>
*
* Licensed under the Academic Free License version 2.1
*
* 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
**************************************************************************/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <getopt.h>
#include <glib.h>
#include <stdlib.h>
#include <libhal.h>
#ifdef HAVE_POLKIT
#include <libpolkit.h>
#endif
/**
* usage:
* @argc: Number of arguments given to program
* @argv: Arguments given to program
*
* Print out program usage.
*/
static void
{
"\n"
"usage : hal-is-caller-privileged --udi <udi> --action <action>\n"
" --caller <caller-name>\n"
" [--help] [--version]\n");
"\n"
" --udi Unique Device Id\n"
" --action PolicyKit action to check for\n"
" --caller The name of the caller\n"
" --version Show version and exit\n"
" --help Show this information and exit\n"
"\n"
"This program determines if a given process on the system bus is\n"
"privileged for a given PolicyKit action for a given device. If an error\n"
"occurs this program exits with a non-zero exit code. Otherwise\n"
"the textual reply will be printed on stdout and this program will\n"
"exit with exit code 0. Note that only the super user (root)\n"
"or other privileged users can use this tool.\n"
"\n");
}
#ifdef HAVE_POLKIT
static void
{
);
exit (1);
}
#endif
/**
* main:
* @argc: Number of arguments given to program
* @argv: Arguments given to program
*
* Returns: Return code
*
* Main entry point
*/
int
{
#ifdef HAVE_POLKIT
#endif
const char *invoked_by_uid;
if (argc <= 1) {
return 1;
}
while (1) {
int c;
int option_index = 0;
const char *opt;
{"version", 0, NULL, 0},
{"help", 0, NULL, 0},
};
if (c == -1)
break;
switch (c) {
case 0:
return 0;
is_version = TRUE;
}
break;
default:
return 1;
break;
}
}
if (is_version) {
return 0;
}
return 1;
}
dbus_error_init (&error);
if (system_bus == NULL) {
printf ("Cannot connect to the system bus\n");
exit (1);
}
#ifdef HAVE_POLKIT
printf ("Cannot get libpolkit context\n");
}
udi,
) {
printf ("cannot lookup privilege\n");
exit (1);
}
if (!allowed_by_privilege) {
printf ("caller don't possess privilege\n");
}
#endif
printf("yes\n");
return 0;
}