summaryrefstree
path: root/usr/share/gtk-doc/html/gio/ch02.html
blob: f751b519c83683f8ad31ebd0965191670db193a8 (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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Writing GIO applications</title>
<meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
<link rel="home" href="index.html" title="GIO Reference Manual">
<link rel="up" href="pt01.html" title="Part I. GIO Overview">
<link rel="prev" href="ch01.html" title="Introduction">
<link rel="next" href="ch03.html" title="Compiling GIO applications">
<meta name="generator" content="GTK-Doc V1.19 (XML mode)">
<link rel="stylesheet" href="style.css" type="text/css">
</head>
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
<table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2"><tr valign="middle">
<td><a accesskey="p" href="ch01.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
<td><a accesskey="u" href="pt01.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
<td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
<th width="100%" align="center">GIO Reference Manual</th>
<td><a accesskey="n" href="ch03.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
</tr></table>
<div class="chapter">
<div class="titlepage"><div><div><h2 class="title">
<a name="id-1.3.3"></a>Writing GIO applications</h2></div></div></div>
<p>
      The information in the GLib <a class="ulink" href="http://developer.gnome.org/glib/stable/glib-programming.html" target="_top">documentation</a> about writing GLib
      applications is generally applicable when writing GIO applications.
    </p>
<div class="simplesect">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="id-1.3.3.3"></a>Threads</h2></div></div></div>
<p>
       GDBus has its own private worker thread, so applications using
       GDBus have at least 3 threads. GIO makes heavy use of the concept
       of a <GTKDOCLINK HREF="g-main-context-push-thread-default">thread-default
       main context</GTKDOCLINK> to execute callbacks of asynchronous
       methods in the same context in which the operation was started.
    </p>
</div>
<div class="simplesect">
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
<a name="id-1.3.3.4"></a>Security</h2></div></div></div>
<p>
When your program needs to carry out some privileged operation (say,
create a new user account), there are various ways in which you can go
about this:
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem"><p>
Implement a daemon that offers the privileged operation. A convenient
way to do this is as a D-Bus system-bus service. The daemon will probably
need ways to check the identity and authorization of the caller before
executing the operation. <a class="ulink" href="http://www.freedesktop.org/software/polkit/docs/latest/polkit.8.html" target="_top">polkit</a> is a framework that allows this.
</p></li>
<li class="listitem"><p>
Use a small helper that is executed with elevated privileges via
pkexec. <a class="ulink" href="http://www.freedesktop.org/software/polkit/docs/latest/pkexec.1.html" target="_top">pkexec</a> is a small program launcher that is part of polkit.
</p></li>
<li class="listitem"><p>
Use a small helper that is executed with elevated privileges by
being suid root.
</p></li>
</ul></div>
<p>
None of these approaches is the clear winner, they all have their
advantages and disadvantages.
</p>
<p>
When writing code that runs with elevated privileges, it is important
to follow some basic rules of secure programming. David Wheeler has an
excellent book on this topic,
<a class="ulink" href="http://www.dwheeler.com/secure-programs/Secure-Programs-HOWTO/index.html" target="_top">Secure Programming for Linux and Unix HOWTO</a>.
</p>
<p>
When using GIO in code that runs with elevated privileges, you have to
be careful. GIO has extension points whose implementations get loaded
from modules (executable code in shared objects), which could allow
an attacker to sneak his own code into your application by tricking it
into loading the code as a module. However, GIO will never load modules
from your home directory except when explictly asked to do so via an
environment variable.
</p>
<p>
In most cases, your helper program should be so small that you don't
need GIO, whose APIs are largely designed to support full-blown desktop
applications. If you can't resist the convenience of these APIs, here
are some steps you should take:
</p>
<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; ">
<li class="listitem"><p>
Clear the environment, e.g. using the <code class="function"><code class="function">clearenv()</code></code>
function.
David Wheeler has a good <a class="ulink" href="http://www.dwheeler.com/secure-programs/Secure-Programs-HOWTO/environment-variables.html" target="_top">explanation</a> for why it is
important to sanitize the environment.
See <a class="xref" href="running-gio-apps.html" title="Running GIO applications"><i>Running GIO applications</i></a>
for a list of all environment variables affecting GIO. In particular,
<code class="envar">PATH</code> (used to locate binaries), <code class="envar">GIO_EXTRA_MODULES</code> (used to locate loadable modules) and <code class="envar">DBUS_{SYSTEM,SESSION}_BUS_ADDRESS</code> (used to locate the D-Bus system and session bus) are important.
</p></li>
<li class="listitem"><p>
Don't use GVfs, by setting <code class="envar">GIO_USE_VFS=local</code> in the environment.
The reason to avoid GVfs in security-sensitive programs is that it uses
many libraries which have not necessarily been audited for security problems.
Gvfs is also heavily distributed and relies on a session bus to be present.
</p></li>
</ul></div>
<p>
</p>
</div>
</div>
<div class="footer">
<hr>
          Generated by GTK-Doc V1.19</div>
</body>
</html>