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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
/*
* Copyright (C) 2009-2010 Red Hat, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*
* Authors: David Zeuthen <davidz@redhat.com>,
* Andrew Psaltis <ampsaltis@gmail.com>
*/
#include "config.h"
#include "polkitagenthelperprivate.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#ifndef HAVE_CLEARENV
extern char **environ;
int
_polkit_clearenv (void)
{
if (environ != NULL)
environ[0] = NULL;
return 0;
}
#else
int
_polkit_clearenv (void)
{
return clearenv ();
}
#endif
gboolean
send_dbus_message (const char *cookie, const char *user)
{
PolkitAuthority *authority = NULL;
PolkitIdentity *identity = NULL;
GError *error;
gboolean ret;
ret = FALSE;
g_type_init ();
error = NULL;
authority = polkit_authority_get_sync (NULL /* GCancellable* */, &error);
if (authority == NULL)
{
g_printerr ("Error getting authority: %s\n", error->message);
g_error_free (error);
goto out;
}
identity = polkit_unix_user_new_for_name (user, &error);
if (identity == NULL)
{
g_printerr ("Error constructing identity: %s\n", error->message);
g_error_free (error);
goto out;
}
if (!polkit_authority_authentication_agent_response_sync (authority,
cookie,
identity,
NULL,
&error))
{
g_printerr ("polkit-agent-helper-1: error response to PolicyKit daemon: %s\n", error->message);
g_error_free (error);
goto out;
}
ret = TRUE;
out:
if (identity != NULL)
g_object_unref (identity);
if (authority != NULL)
g_object_unref (authority);
return ret;
}
void
flush_and_wait ()
{
fflush (stdout);
fflush (stderr);
fdatasync (fileno(stdout));
fdatasync (fileno(stderr));
usleep (100 * 1000);
}
|