polkit-example/ 0000775 0000764 0000764 00000000000 11306554422 013737 5 ustar jreznik jreznik polkit-example/com.redhat.devconf.examples.policy 0000664 0000764 0000764 00000002113 11246762556 022455 0 ustar jreznik jreznik
Red Hat, Inc.
http://www.redhat.com
Cry
Prevents me from crying
no
no
Smile
Allows me to smile
no
yes
Play
I'm not a bad boy mum, I can play
no
auth_admin
polkit-example/Makefile 0000664 0000764 0000764 00000000643 11247224067 015405 0 ustar jreznik jreznik CC = gcc
CFLAGS = -Wall -O2 `pkg-config polkit-gobject-1 --cflags`
LDFLAGS = `pkg-config polkit-gobject-1 --libs`
SOURCES = example.c
OBJECTS = $(SOURCES:.c=.o)
EXEC = example
POLICY = com.redhat.devconf.examples.policy
all: $(SOURCES) $(EXEC)
$(EXEC): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) -o $@
.o:
$(CC) $(CFLAGS) $< -o $@
install-policy:
cp $(POLICY) /usr/share/polkit-1/actions
clean:
rm -rf *o example polkit-example/example.c 0000664 0000764 0000764 00000005324 11247462127 015546 0 ustar jreznik jreznik /*
* This file is part of the Policy Kit 1 DevConf example
*
* Copyright (C) 2009 Jaroslav Reznik
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include
#include
typedef enum {
/* Authorization status is unknown */
Unknown = 0x0,
/* Subject is authorized for the action */
Yes = 0x01,
/* Subject is not authorized for the action */
No = 0x02,
/* Challenge is needed for this action, only when flag is
POLKIT_CHECK_AUTHORIZATION_FLAGS_NONE*/
Challenge = 0x03 } Result;
Result check_authorization(PolkitAuthority *authority, char *action_id)
{
PolkitSubject *subject;
PolkitAuthorizationResult *result;
GError *error = NULL;
subject = polkit_unix_process_new(getpid());
result = polkit_authority_check_authorization_sync(authority,
subject,
action_id,
NULL,
POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION,
NULL,
&error);
if (error) {
g_error_free (error);
return Unknown;
}
if (result)
if (polkit_authorization_result_get_is_challenge(result))
return Challenge;
else
if (polkit_authorization_result_get_is_authorized(result))
return Yes;
else
return No;
return Unknown;
}
int main(int argc, char *argv[])
{
PolkitAuthority *authority;
PolkitSubject *subject;
if (argc < 2)
{
printf("Usage: example actionId\n");
return 1;
}
/* initialize glib */
g_type_init();
/* get Policy Kit 1 Authority object */
authority = polkit_authority_get();
if (!authority)
{
return 1;
}
if (check_authorization(authority, argv[1]) == Yes)
printf("You are authorized to do '%s'.\n", argv[1]);
else
printf("You are NOT authorized to do '%s'.\n", argv[1]);
return 0;
}
polkit-example/README 0000644 0000764 0000764 00000000250 11306554422 014612 0 ustar jreznik jreznik This is quick&short&dirty PolicyKit 1 example
"make"
"make install-policy" as superuser
For any question, feel free to ask me...
Jaroslav Reznik