aboutsummaryrefslogtreecommitdiffstats
path: root/pseudo.1
blob: 9c65fabb2e6cd55b9ffcc7e44adc4c3190c312de (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
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
.\" 
.\" pseudo(1) man page
.\" 
.\" Copyright (c) 2010 Wind River Systems, Inc.
.\"
.\" This program is free software; you can redistribute it and/or modify
.\" it under the terms of the Lesser GNU General Public License version 2.1 as
.\" published by the Free Software Foundation.
.\"
.\" 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 Lesser GNU General Public License for more details.
.\"
.\" You should have received a copy of the Lesser GNU General Public License
.\" version 2.1 along with this program; if not, write to the Free Software
.\" Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
.TH pseudo 1 "pseudo - pretending to be root"
.SH SYNOPSIS
.B pseudo
.RB [ \-dflv ]
[
.B \-x
.I flags
]
[
.B \-P
.I prefix
]
[
.B \-rR
.I root
]
[
.B \-t
.I timeout
]
.RI [ command ]
.PP
.B pseudo \-h
.PP
.B pseudo
.RB [ \-dflv ]
[
.B \-x
.I flags
]
[
.B \-P
.I prefix
]
.RB [ \-BC ]
.BR \-i\  path
.PP
.B pseudo
.RB [ \-dflv ]
[
.B \-x
.I flags
]
[
.B \-P
.I prefix
]
.RB [ \-BC ]
.BR \-m\  from\  \-M\  to
.PP
.B pseudo
.RB [ \-dflv ]
[
.B \-x
.I flags
]
[
.B \-P
.I prefix
]
.B \-S
.PP
.B pseudo
.RB [ \-dflv ]
[
.B \-x
.I flags
]
[
.B \-P
.I prefix
]
.B \-V
.SH DESCRIPTION
The
.I pseudo
utility provides a virtual root environment, hereafter referred to as the
.IR pseudo\ environment ,
allowing the creation of file system images and packages by users
without root privileges.  The pseudo environment is implemented by pushing
a special library
.RI ( libpseudo.so )
into the
.B LD_PRELOAD
environment variable.  This library intercepts a large number of common
filesystem operations and some user-id related operations, and returns
values that look as though the operations had been performed by a root
user.  This is in turn managed by a daemon program which keeps a list
of virtualized file ownership and permissions; this daemon program itself
is
.IR pseudo .

The
.I pseudo
program itself can also be used as a program launcher.  The launcher
is used to automatically configure a working environment, then execute
processes within that environment.  Alternatively, you can bypass this
by setting up certain environment variables (see the
.B ENVIRONMENT
section below).  The
.I pseudo
client library
.RI ( libpseudo.so )
can then start the server automatically.

The
.I pseudo
command can be invoked in one of several possible modes:

.TP 8
.B \-B
The
.B \-B
option causes
.I pseudo
to scan its database, as with the
.B \-C
option, but instead of reporting mismatches,
.I pseudo
attempts to repair them.  Specifically, device and inode number mismatches
are corrected, and symlink or directory mismatches result in deletion of
database entries.
.TP 8
.B \-C
The
.B \-C
option causes
.I pseudo
to scan its database, comparing against the filesystem, and reporting likely
errors.  This may be unreliable when the server is actively running.
.TP 8
.B \-h
The
.B \-h
option causes
.I pseudo
to print a usage message and exit.
.TP 8
.B \-i
The
.B \-i
option causes
.I pseudo
to attempt to correct device number mismatches by
checking inodes; if
.I path
has the same inode number as recorded in the database, but a different
device number, all instances of the device number recorded in the database
are updated to the device number in the live filesystem for
.IR path .
This is intended to handle the mismatches that can occur when remounting
an NFS filesystem.  The
.B \-i
option implies the
.B \-C
option.  You can also specify the
.B \-B
option to request that the database be rebuilt.
.TP 8
.B \-m
The
.B \-m
and
.B \-M
options cause
.I pseudo
to rename files, replacing the string
.I from
with the string
.I to.
The
.B \-m
option pair implies the
.B \-C
option.  You can also specify the
.B \-B
option to request that the database be rebuilt.
.TP 8
.B \-V
The
.B \-V
option causes
.I pseudo
to print configuration information and exit immediately.
.TP 8
.B \-S
The
.B \-S
option causes
.I pseudo
to try to find an existing server, and if it finds one, instructs that
server to shut down as soon as all clients are detached from it.  Note
that the server will not shut down while clients are connected to it;
in this case,
.I pseudo
will print a list of the remaining client PIDs.
.TP 8
.B \-d
The
.B \-d
option causes pseudo to immediately detach and run in the background
as a daemon.  This is rarely useful except for debugging.
.PP
Finally, invoked without any of these options,
.I pseudo
sets up an emulated root environment, then invokes
.I command
if it was provided, otherwise a shell (using the
.B SHELL
environment variable if it is set, or
.I /bin/sh
otherwise).

The following options modify the behavior of
.IR pseudo :

.TP 8
.BI \-d\  (daemonize)
Run as a daemon;
.I pseudo
detaches from the calling environment and runs as a daemon.  The command
returns successfully if this appears to have succeeded, otherwise it
produces an error message and returns a failure status.

.TP 8
.BI \-f\  (foreground)
Run in the foreground;
.I pseudo
runs as a server, and does not try to start other commands.  This mode
is useful for debugging.

.TP 8
.BI \-l\  (log)
Enable logging.  The
.I pseudo
daemon will log every filesystem transaction in the log database.

.TP 8
.BI \-r\  root
.TP 8
.BI \-R\  root
Set the
.B PSEUDO_CHROOT
environment variable, running as though the program had called
.I chroot(2)
on the specified path.  With
.BR \-r ,
this implies changing the working directory to the specified directory;
with
.BR \-R ,
it does not.

.TP 8
.B \-t timeout
Set the timeout of the
.I pseudo
daemon, in seconds.  The default is currently 30 seconds.  After this
long with no attached clients, the
.I pseudo
daemon shuts down automatically.  The server never shuts down while it
has attached clients.  Note that this does not prevent continued use;
new clients can restart the daemon if they need it.

.TP 8
.BI \-v\  (verbose)
Increase the verbosity of the
.I pseudo
daemon, and the client library for any programs started by this
invocation of
.IR pseudo .
This is equivalent to the numeric form of the
.B PSEUDO_DEBUG
environment variable; multiple
.B \-v
options increase the debugging level.

.TP 8
.BI \-x\  (debug)
Set specific deugging flags (the
.I pseudo
utility's help message lists them). This is equivalent to the string
form of the
.B PSEUDO_DEBUG
environment variable.

.SH EXAMPLES
The two most common usages of
.I pseudo
are using it to run specific commands, and setting up an environment manually
for running various other commands.

For the first case, the usage is reasonably simple:

.sp
$
.I /path/to/pseudo
.br
# 
.I commands which require root privileges

You may have to use the
.BI \-P prefix
option to tell
.I pseudo
where to look for its database and server.  If you specify a full path,
.I pseudo
assumes that
.B PSEUDO_PREFIX
should be the path to the directory containing the
.I pseudo
program, or to the
.I /bin
directory containing the
.I pseudo
program.

The other way to use
.I pseudo
is by setting up an environment.  This is suitable for use in
.I Makefiles
or similar environments, where you want to run a series of commands in
the
.I pseudo
environment, but not to keep invoking the
.I pseudo
command.  To do this, set up the
.BR PSEUDO_PREFIX ,\  LD_PRELOAD ,\ and\ LD_LIBRARY_PATH
environment variables, then run programs normally.  You do not need to
separately invoke the
.I pseudo
daemon; the client library starts it as needed.

If you have moved a directory which
.I pseudo
was tracking, you may be able to get the database reattached using the
.B \-m
option.  A typical usage might be:

.sp
$
.I /path/to/pseudo
.B \-B \-m
.I oldpath
.B \-M
.I newpath
.br

This requests that
.I pseudo
replace the string
.I oldpath
with the string
.I newpath
at the beginnings of filenames, then regenerate the database, correcting any
device/inode numbers.

.SH DIAGNOSTICS
Depending on invocation, diagnostic messages usually go either to standard
error or to the file
.B PSEUDO_PREFIX
.IR /var/pseudo/pseudo.log .
By default,
.I pseudo
daemon messages go into the log file, but messages generated by the client
code go to standard error.  These can be changed using the
.B PSEUDO_DEBUG_FILE
environment variable, documented in
.BR ENVIRONMENT .
At the default logging level, only critical
messages are displayed.  If you have raised the logging level (using the
.I \-v
option or the
.B PSEUDO_DEBUG
environment variable), additional messages are displayed.  Levels higher
than 2 are very unlikely to be useful outside of
.I pseudo
development.

Diagnostic messages seen by default are those which are believed to indicate
either a serious internal flaw in
.I pseudo
or a completely unexpected failure from the underlying operating system.  In
normal use, you should see no diagnostic messages.

.SH ENVIRONMENT
The most significant environment variables for
.I pseudo
are
.B LD_PRELOAD
and
.BR LD_LIBRARY_PATH .
However, these variables have no special meaning to
.IR pseudo ;
rather, they are used in the standard way to manipulate the dynamic linker
into loading the
.I libpseudo
library so that it can intercept calls into the underlying C library.

The following environment variables are used directly by
.IR pseudo :

.TP 8
.B PSEUDO_BINDIR
This directory holds the path to the
.I pseudo
binary; by default, it is the
.I bin
directory under
.B PSEUDO_PREFIX.
.TP 8
.B PSEUDO_CHROOT
This variable holds the current emulated
.I chroot(2)
path.  Paths that are relative to this are treated as though they were
instead relative to the filesystem root.
.TP 8
.B PSEUDO_DEBUG
This variable holds either a numeric "debug level" for
.I pseudo
to run at, or a set of specific debugging flags, generally letters.
Use
.B pseudo -h
to see the available flags. In general, this is useful only for debugging
.I pseudo
itself.
.TP 8
.B PSEUDO_DEBUG_FILE
The name of a file to use for debugging messages from the pseudo client;
the default is to log to standard error.  If the string contains a single
.BR %s ,
that string is replaced with the short program name, and if it contains
a single
.BR %d ,
that string is replaced with the process ID.  Other format specifiers
(other than '%%') are not allowed.  By default, the
.I pseudo
server logs to the file
.I pseudo.log
in the
.I var/pseudo
directory, while clients log to standard error.
.TP 8
.B PSEUDO_DISABLED
If this variable is set to a value that doesn't look like f, F, n, N, s, S, or
a numeric zero, the
.I pseudo
client library does not modify the behavior of called functions, though it
continues to intercept them and block signals while processing them.  This
variable is reevaluated on every call to
.IR fork(2) ,\  clone(2)
or related functions. If the value starts with a lowercase or uppercase
.I s
, the pseudo client disables all server spawning and communications, but still
operates locally. This means that no filesystem mode or permissions changes
are actually recorded or reported, but functions like
.I chown()
will still report success, even though nothing happens. This function is
intended for debugging of issues which are complicated by the server's
involvement.
.TP 8
.B PSEUDO_ALLOW_FSYNC
If this variable is set, pseudo will allow
.I fsync()
and related system calls, even it was configured with the
.I --enable-force-async
option. Otherwise, that option results in all such calls being
discarded silently, even when
.B PSEUDO_DISABLED
is set. The value specified doesn't matter.
.TP 8
.B PSEUDO_ENOSYS_ABORT
If this variable is set, the
.I pseudo
client library calls
.I abort()
rather than setting
.I errno
to
.B ENOSYS
in the event of a call to a missing underlying function.  This variable has
no function outside of debugging
.I pseudo
itself.
.TP 8
.B PSEUDO_LIBDIR
This directory holds the path to the
.I pseudo
shared libraries; by default, it is the
.I lib
directory under
.BR PSEUDO_PREFIX .
(On 64-bit hosts,
.I lib64
is also used.)
.TP 8
.B PSEUDO_LOCALSTATEDIR
This directory holds the
.I pseudo
database files and log files; by default, it is the
.I var/pseudo
directory under
.BR PSEUDO_PREFIX .
.TP 8
.B PSEUDO_NOSYMLINKEXP
By default, when chrooted,
.I pseudo
prepends the chroot directory to
the paths used for absolute symlinks; this behavior ensures that
opening symlinks produces expected results in most cases.  In some
cases you may want to suppress this.  If this variable is unset, or
set to any value other than 0,
.I pseudo
expands symlink paths like this.  If this variable is set to 0,
the behavior is disabled.
.TP 8
.BR PSEUDO_OPTS
This variable holds options to be passed to any new
.I pseudo
servers started.  Typically, when
.I pseudo
is used as a launcher, this will be set automatically; however, you
can also use it to pass options when using
.B LD_PRELOAD
to manually run things in the
.I pseudo
environment.
.TP 8
.B PSEUDO_PASSWD
This variable holds the path to a directory containing password and
group files to use for emulation of various password and group routines.
It should be the path to a directory containing the
.I etc
directory containing files named
.I passwd
and
.IR group .
When
.I pseudo
is emulating a
.I chroot
environment, the chroot directory is used by preference.  The
parallelism between these cases is why this variable points at
the parent directory of
.I etc
rather than the directory containing the files.
.TP 8
.B PSEUDO_PREFIX
If set, the variable
.B PSEUDO_PREFIX
is used to determine the path to use to find the
.I pseudo
server, in
.BR PSEUDO_PREFIX /bin,
and the
.I pseudo
data files, in
.BR PSEUDO_PREFIX /var/pseudo.
This variable is automatically set by the
.I pseudo
program when it is used as a launcher.
.TP 8
.B PSEUDO_TAG
If this variable is set in a client's environment, its value is
communicated to the server at the beginning of each client session,
and recorded in the log database if any logging occurs related to a
specific client.  Note that different clients may have different tags
associated with them; the tag value is per-client, not per-server.
.TP 8
.BR PSEUDO_UIDS ,\  PSEUDO_GIDS
These variables are used internally to pass information about the current
emulated user and group identity from one process to another.
.TP 8
.B PSEUDO_UNLOAD
This variable is reevaluated on every call to
.IR fork(2) ,\ exec(3)
or related functions.  If the variable exists
.RI libpseudo.so
will be removed from
.B LD_PRELOAD
and 
.B PSEUDO_DISABLED 
behavior will also be triggered.  For processes
that simply 
.IR fork(2),
the behavior will be the same as if 
.B PSEUDO_DISABLED
was set.  For new processes, after a call to
.IR exec(3)\ or\ system(3)
pseudo will not be loaded in the new process.
.TP 8
.B SHELL
If set, this will be used when
.I pseudo
is invoked without either a command or one of the options which directs
it to do something other than run a command.  Otherwise,
.I pseudo
defaults to
.I /bin/sh .
.B
.SH BUGS
The
.I pseudo
database is not particularly robust in the face of whole directory trees
being moved, or changes in the underlying device and inode numbers.  It
has a reasonable chance of recovering if only the path or the device numbers
have changed, but it is not particularly designed to address this.  A future
release is expected to have improved resilience in these cases.

The filesystem on which
.I pseudo
keeps its database and files must at a minimum support UNIX domain sockets
and reasonable file locking semantics.  Note that
.I pseudo
relies on
.I flock(2)
locking semantics; a lock has to persist into a child process.  This should
probably eventually be fixed.

The
.I pseudo
client library is probably thread-safe, but has not been adequately tested
or debugged in that context.

Filesystem performance is noticably worse under
.I pseudo
than it is otherwise.  This is probably because nearly every operation
(other than reads and writes) involves at least one round-trip network
communication with the server, and probably some kind of database
activity.

.SH SEE ALSO
fakeroot(1), ld.so(8), pseudolog(1), sqlite3(1)
.SH FURTHER READING
Documentation of the internals of
.I pseudo
may be found in the
.I doc
subdirectory of the pseudo source tree.