summaryrefslogtreecommitdiff
path: root/Documentation/kdbus/kdbus.endpoint.xml
blob: 6632485f3e844ee819556b2bdcee3c85dc3475f9 (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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
<?xml version='1.0'?> <!--*-nxml-*-->
<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
        "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd">

<refentry id="kdbus.endpoint">

  <refentryinfo>
    <title>kdbus.endpoint</title>
    <productname>kdbus.endpoint</productname>
  </refentryinfo>

  <refmeta>
    <refentrytitle>kdbus.endpoint</refentrytitle>
    <manvolnum>7</manvolnum>
  </refmeta>

  <refnamediv>
    <refname>kdbus.endpoint</refname>
    <refpurpose>kdbus endpoint</refpurpose>
  </refnamediv>

  <refsect1>
    <title>Description</title>

    <para>
      Endpoints are entry points to a bus (see
      <citerefentry>
        <refentrytitle>kdbus.bus</refentrytitle>
        <manvolnum>7</manvolnum>
      </citerefentry>).
      By default, each bus has a default
      endpoint called 'bus'. The bus owner has the ability to create custom
      endpoints with specific names, permissions, and policy databases
      (see below). An endpoint is presented as file underneath the directory
      of the parent bus.
    </para>
    <para>
      To create a custom endpoint, open the default endpoint
      (<literal>bus</literal>) and use the
      <constant>KDBUS_CMD_ENDPOINT_MAKE</constant> ioctl with
      <type>struct kdbus_cmd</type>. Custom endpoints always have a policy
      database that, by default, forbids any operation. You have to explicitly
      install policy entries to allow any operation on this endpoint.
    </para>
    <para>
      Once <constant>KDBUS_CMD_ENDPOINT_MAKE</constant> succeeded, the new
      endpoint will appear in the filesystem
      (<citerefentry>
        <refentrytitle>kdbus.bus</refentrytitle>
        <manvolnum>7</manvolnum>
      </citerefentry>), and the used file descriptor will manage the
      newly created endpoint resource. It cannot be used to manage further
      resources and must be kept open as long as the endpoint is needed. The
      endpoint will be terminated as soon as the file descriptor is closed.
    </para>
    <para>
      Endpoint names may be chosen freely except for one restriction: the name
      must be prefixed with the numeric effective UID of the creator and a dash.
      This is required to avoid namespace clashes between different users. When
      creating an endpoint, the name that is passed in must be properly
      formatted or the kernel will refuse creation of the endpoint. Example:
      <literal>1047-my-endpoint</literal> is an acceptable name for an
      endpoint registered by a user with UID 1047. However,
      <literal>1024-my-endpoint</literal> is not, and neither is
      <literal>my-endpoint</literal>. The UID must be provided in the
      user-namespace of the bus.
    </para>
    <para>
      To create connections to a bus, use <constant>KDBUS_CMD_HELLO</constant>
      on a file descriptor returned by <function>open()</function> on an
      endpoint node. See
      <citerefentry>
        <refentrytitle>kdbus.connection</refentrytitle>
        <manvolnum>7</manvolnum>
      </citerefentry>
      for further details.
    </para>
  </refsect1>

  <refsect1>
    <title>Creating custom endpoints</title>
    <para>
      To create a new endpoint, the
      <constant>KDBUS_CMD_ENDPOINT_MAKE</constant> command is used. Along with
      the endpoint's name, which will be used to expose the endpoint in the
      <citerefentry>
        <refentrytitle>kdbus.fs</refentrytitle>
        <manvolnum>7</manvolnum>
      </citerefentry>,
      the command also optionally takes items to set up the endpoint's
      <citerefentry>
        <refentrytitle>kdbus.policy</refentrytitle>
        <manvolnum>7</manvolnum>
      </citerefentry>.
      <constant>KDBUS_CMD_ENDPOINT_MAKE</constant> takes a
      <type>struct kdbus_cmd</type> argument.
    </para>
    <programlisting>
struct kdbus_cmd {
  __u64 size;
  __u64 flags;
  __u64 return_flags;
  struct kdbus_item items[0];
};
    </programlisting>

    <para>The fields in this struct are described below.</para>

    <variablelist>
      <varlistentry>
        <term><varname>size</varname></term>
        <listitem><para>
          The overall size of the struct, including its items.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>flags</varname></term>
        <listitem><para>The flags for creation.</para>
          <variablelist>
            <varlistentry>
              <term><constant>KDBUS_MAKE_ACCESS_GROUP</constant></term>
              <listitem>
                <para>Make the endpoint file group-accessible.</para>
              </listitem>
            </varlistentry>

            <varlistentry>
              <term><constant>KDBUS_MAKE_ACCESS_WORLD</constant></term>
              <listitem>
                <para>Make the endpoint file world-accessible.</para>
              </listitem>
            </varlistentry>

            <varlistentry>
              <term><constant>KDBUS_FLAG_NEGOTIATE</constant></term>
              <listitem>
                <para>
                  Requests a set of valid flags for this ioctl. When this bit is
                  set, no action is taken; the ioctl will return
                  <errorcode>0</errorcode>, and the <varname>flags</varname>
                  field will have all bits set that are valid for this command.
                  The <constant>KDBUS_FLAG_NEGOTIATE</constant> bit will be
                  cleared by the operation.
                </para>
              </listitem>
            </varlistentry>
          </variablelist>
        </listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>return_flags</varname></term>
        <listitem><para>
          Flags returned by the kernel. Currently unused and always set to
          <constant>0</constant> by the kernel.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>items</varname></term>
        <listitem>
          <para>
            The following items are expected for
            <constant>KDBUS_CMD_ENDPOINT_MAKE</constant>.
          </para>
          <variablelist>
            <varlistentry>
              <term><constant>KDBUS_ITEM_MAKE_NAME</constant></term>
              <listitem>
                <para>Contains a string to identify the endpoint name.</para>
              </listitem>
            </varlistentry>

            <varlistentry>
              <term><constant>KDBUS_ITEM_NAME</constant></term>
              <term><constant>KDBUS_ITEM_POLICY_ACCESS</constant></term>
              <listitem>
                <para>
                  These items are used to set the policy attached to the
                  endpoint. For more details on bus and endpoint policies, see
                  <citerefentry>
                    <refentrytitle>kdbus.policy</refentrytitle>
                    <manvolnum>7</manvolnum>
                  </citerefentry>.
                </para>
              </listitem>
            </varlistentry>
          </variablelist>
          <para>
            Unrecognized items are rejected, and the ioctl will fail with
            <varname>errno</varname> set to <varname>EINVAL</varname>.
          </para>
        </listitem>
      </varlistentry>
    </variablelist>
  </refsect1>

  <refsect1>
    <title>Updating endpoints</title>
    <para>
      To update an existing endpoint, the
      <constant>KDBUS_CMD_ENDPOINT_UPDATE</constant> command is used on the file
      descriptor that was used to create the endpoint, using
      <constant>KDBUS_CMD_ENDPOINT_MAKE</constant>. The only relevant detail of
      the endpoint that can be updated is the policy. When the command is
      employed, the policy of the endpoint is <emphasis>replaced</emphasis>
      atomically with the new set of rules.
      The command takes a <type>struct kdbus_cmd</type> argument.
    </para>
    <programlisting>
struct kdbus_cmd {
  __u64 size;
  __u64 flags;
  __u64 return_flags;
  struct kdbus_item items[0];
};
    </programlisting>

    <para>The fields in this struct are described below.</para>

    <variablelist>
      <varlistentry>
        <term><varname>size</varname></term>
        <listitem><para>
          The overall size of the struct, including its items.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>flags</varname></term>
        <listitem><para>
          Unused for this command.
          <constant>KDBUS_FLAG_NEGOTIATE</constant> is accepted to probe for
          valid flags. If set, the ioctl will return <errorcode>0</errorcode>,
          and the <varname>flags</varname> field is set to
          <constant>0</constant>.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>return_flags</varname></term>
        <listitem><para>
          Flags returned by the kernel. Currently unused and always set to
          <constant>0</constant> by the kernel.
        </para></listitem>
      </varlistentry>

      <varlistentry>
        <term><varname>items</varname></term>
        <listitem>
          <para>
            The following items are expected for
            <constant>KDBUS_CMD_ENDPOINT_UPDATE</constant>.
          </para>
          <variablelist>
            <varlistentry>
              <term><constant>KDBUS_ITEM_NAME</constant></term>
              <term><constant>KDBUS_ITEM_POLICY_ACCESS</constant></term>
              <listitem>
                <para>
                  These items are used to set the policy attached to the
                  endpoint. For more details on bus and endpoint policies, see
                  <citerefentry>
                    <refentrytitle>kdbus.policy</refentrytitle>
                    <manvolnum>7</manvolnum>
                  </citerefentry>.
                  Existing policy is atomically replaced with the new rules
                  provided.
                </para>
              </listitem>
            </varlistentry>

            <varlistentry>
              <term><constant>KDBUS_ITEM_NEGOTIATE</constant></term>
              <listitem><para>
                With this item, programs can <emphasis>probe</emphasis> the
                kernel for known item types. See
                <citerefentry>
                  <refentrytitle>kdbus.item</refentrytitle>
                  <manvolnum>7</manvolnum>
                </citerefentry>
                for more details.
              </para></listitem>
            </varlistentry>
          </variablelist>
          <para>
            Unrecognized items are rejected, and the ioctl will fail with
            <varname>errno</varname> set to <constant>EINVAL</constant>.
          </para>
        </listitem>
      </varlistentry>
    </variablelist>
  </refsect1>

  <refsect1>
    <title>Return value</title>
    <para>
      On success, all mentioned ioctl commands return <errorcode>0</errorcode>;
      on error, <errorcode>-1</errorcode> is returned, and
      <varname>errno</varname> is set to indicate the error.
      If the issued ioctl is illegal for the file descriptor used,
      <varname>errno</varname> will be set to <constant>ENOTTY</constant>.
    </para>

    <refsect2>
      <title>
        <constant>KDBUS_CMD_ENDPOINT_MAKE</constant> may fail with the
        following errors
      </title>

      <variablelist>
        <varlistentry>
          <term><constant>EINVAL</constant></term>
          <listitem><para>
            The flags supplied in the <type>struct kdbus_cmd</type>
            are invalid.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><constant>EINVAL</constant></term>
          <listitem><para>
            Illegal combination of <constant>KDBUS_ITEM_NAME</constant> and
            <constant>KDBUS_ITEM_POLICY_ACCESS</constant> was provided.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><constant>EEXIST</constant></term>
          <listitem><para>
            An endpoint of that name already exists.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><constant>EPERM</constant></term>
          <listitem><para>
            The calling user is not privileged. See
            <citerefentry>
              <refentrytitle>kdbus</refentrytitle>
              <manvolnum>7</manvolnum>
            </citerefentry>
            for information about privileged users.
          </para></listitem>
        </varlistentry>
      </variablelist>
    </refsect2>

    <refsect2>
      <title>
        <constant>KDBUS_CMD_ENDPOINT_UPDATE</constant> may fail with the
        following errors
      </title>

      <variablelist>
        <varlistentry>
          <term><constant>EINVAL</constant></term>
          <listitem><para>
            The flags supplied in <type>struct kdbus_cmd</type>
            are invalid.
          </para></listitem>
        </varlistentry>

        <varlistentry>
          <term><constant>EINVAL</constant></term>
          <listitem><para>
            Illegal combination of <constant>KDBUS_ITEM_NAME</constant> and
            <constant>KDBUS_ITEM_POLICY_ACCESS</constant> was provided.
          </para></listitem>
        </varlistentry>
      </variablelist>
    </refsect2>
  </refsect1>

  <refsect1>
    <title>See Also</title>
    <simplelist type="inline">
      <member>
        <citerefentry>
          <refentrytitle>kdbus</refentrytitle>
          <manvolnum>7</manvolnum>
        </citerefentry>
      </member>
      <member>
        <citerefentry>
          <refentrytitle>kdbus.bus</refentrytitle>
          <manvolnum>7</manvolnum>
        </citerefentry>
      </member>
      <member>
        <citerefentry>
          <refentrytitle>kdbus.endpoint</refentrytitle>
          <manvolnum>7</manvolnum>
        </citerefentry>
      </member>
      <member>
        <citerefentry>
          <refentrytitle>kdbus.fs</refentrytitle>
          <manvolnum>7</manvolnum>
        </citerefentry>
      </member>
      <member>
        <citerefentry>
          <refentrytitle>kdbus.item</refentrytitle>
          <manvolnum>7</manvolnum>
        </citerefentry>
      </member>
      <member>
        <citerefentry>
          <refentrytitle>kdbus.message</refentrytitle>
          <manvolnum>7</manvolnum>
        </citerefentry>
      </member>
      <member>
        <citerefentry>
          <refentrytitle>kdbus.name</refentrytitle>
          <manvolnum>7</manvolnum>
        </citerefentry>
      </member>
      <member>
        <citerefentry>
          <refentrytitle>kdbus.pool</refentrytitle>
           <manvolnum>7</manvolnum>
        </citerefentry>
      </member>
    </simplelist>
  </refsect1>
</refentry>