Mercurial > pkg
comparison previous-work/more_control_and_pkg_man.txt @ 1:d6bef198ae71
add work by Matthias S. Benkmann which is the inspiration for this project.
author | Robert McIntyre <rlm@mit.edu> |
---|---|
date | Tue, 08 Jan 2013 11:45:01 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
0:0b7a589f6e9a | 1:d6bef198ae71 |
---|---|
1 | |
2 AUTHOR: Matthias S. Benkmann <article at winterdrache dot de> | |
3 | |
4 DATE: 2007-10-20 | |
5 | |
6 LICENSE: Creative Commons Attribution-Share Alike 3.0 | |
7 (http://creativecommons.org/licenses/by-sa/3.0/) | |
8 | |
9 SYNOPSIS: More Control and Package Management using Package Users (v1.4) | |
10 | |
11 DESCRIPTION: | |
12 -You want to know which packages your files belong to ? | |
13 -You want to deinstall software that doesn't have make uninstall ? | |
14 -You are bothered by programs installed setuid root behind your back ? | |
15 -You don't like packages quietly overwriting files from other packages ? | |
16 -You don't like package managers like RPM ? | |
17 -YOU WANT TOTAL CONTROL USING ONLY UNIX BUILTINS ? | |
18 | |
19 ATTACHMENTS: | |
20 http://www.linuxfromscratch.org/hints/downloads/attachments/more_control_and_pkg_man/more_control_helpers.tar.bz2 | |
21 | |
22 PREREQUISITES: | |
23 For use with LFS book 6.2: Brain. | |
24 For use with LFS book later than 6.2: Brain (awake, good working condition). | |
25 | |
26 HINT: | |
27 | |
28 ########################################################################### | |
29 Contents | |
30 ########################################################################### | |
31 | |
32 1. Preface | |
33 2. Overview | |
34 | |
35 - PART 1: General Information - | |
36 | |
37 3. Package Users | |
38 3.1 Introduction | |
39 3.2 User Name | |
40 3.3 Groups | |
41 3.4 Home Directory | |
42 4. Common Problems | |
43 4.1 Introduction | |
44 4.2 General Procedure | |
45 4.3 Permission Changes | |
46 4.4 Ownership Changes | |
47 4.5 Write to Non-Install Directory | |
48 4.6 Delete or Overwrite File | |
49 4.7 /sbin/ldconfig | |
50 4.8 What Commands to Run as a Package User | |
51 5. The more_control_helpers Archive | |
52 5.1 Overview | |
53 5.2 The Wrappers | |
54 5.3 add_package_user/install_package | |
55 5.4 forall_direntries_from | |
56 5.5 uninstall_package | |
57 5.6 list_suspicious_files/list_suspicious_files_from | |
58 5.7 list_package | |
59 5.8 grep_all_regular_files_for | |
60 5.9 The etc Directory | |
61 5.10 Temporary Files | |
62 | |
63 - PART 2: LFS Specifics - | |
64 | |
65 6. Pre-Chroot Phase (Chapter 5) | |
66 7. Chroot Phase (Chapter 6) | |
67 7.1 Preparations | |
68 7.2 Walkthrough: Installing linux-libc-headers | |
69 7.3 Known Issues with LFS Packages | |
70 8. Sanity Checks | |
71 8.1 Suspicious Files | |
72 8.2 References to Temporary Files | |
73 | |
74 - APPENDICES - | |
75 | |
76 A. Security Issues | |
77 A.1 NFS | |
78 A.2 Daemons | |
79 B. Package Categories | |
80 C. Acknowledgements and Changelog | |
81 | |
82 | |
83 ########################################################################### | |
84 1. Preface | |
85 ########################################################################### | |
86 | |
87 Let's say I have written a program that you would like to use. To make it | |
88 easier for you I come over to install it for you. Would you give me the root | |
89 account and then leave the room ? No ? Then why do you give it to complete | |
90 strangers who you have never seen in your life, to install software packages | |
91 pulled from some Internet server, that come with no warranty and don't even | |
92 list their contents in the README, although they will happily spread them all | |
93 over your system ? | |
94 | |
95 It is a mystery why Unix admins who wouldn't even trust their employer with | |
96 more than a normal user account carelessly execute complex and incomprehensible | |
97 installation scripts with full root rights. | |
98 | |
99 Users and groups are the basic security principle in a Unix system. They have | |
100 been used successfully for a long time to monitor who has created a file and | |
101 to control who is allowed to delete or change it. But this control has only | |
102 been imposed on the files of ordinary users. What a waste! I suggest to extend | |
103 this control to all system files. | |
104 | |
105 The general idea is to create package users, i.e. user accounts with restricted | |
106 rights, to build and install software packages, rather than doing these tasks | |
107 as root. Not only does this give you more control over what build and install | |
108 scripts may or may not do, it can also serve as a quite useful package | |
109 management system. | |
110 | |
111 | |
112 ############################################################################# | |
113 2. Overview | |
114 ############################################################################# | |
115 | |
116 This hint is divided into 3 parts. The first part contains general information | |
117 about the package user method. This part is the most important part of the | |
118 hint. Read it thoroughly. The second part explains how to apply the package | |
119 user method to the building of an LFS system. | |
120 Finally, part 3 of this hint is the Appendix with information that would not | |
121 fit anywhere else or that is not of general interest. | |
122 | |
123 It is inevitable that part 2 will become outdated with time as the LFS book | |
124 changes and new versions of the software packages used with LFS are released. | |
125 I make no attempt to track these changes. | |
126 When someone reports an issue with a package I will incorporate | |
127 it into the hint, but larger changes that might be required due to changes in | |
128 the LFS build methodology could take a long time to get included. The reason | |
129 for this (aside from lack of time) is that I consider part 2 as bonus material | |
130 that helps people get started but is not essential. Part 1 describes the | |
131 concepts, which are independent of package versions or the LFS book, and you | |
132 will have to rely on this information whenever part 2 fails. Don't forget | |
133 that part 2 only deals with the packages used by the LFS book. For all the | |
134 other packages you install on your system after that even an up-to-date | |
135 part 2 would offer no aid anyway. | |
136 | |
137 The previous paragraph might sound discouraging, and as you read more from the | |
138 hint it is possible that you get the impression that the package user | |
139 method is complicated, causes lots of difficult problems and is overall too | |
140 much trouble for anyone but a real hardcore admin with programming experience. | |
141 But you would be mistaken. | |
142 First of all, many things experienced as installation problems when working | |
143 with the package user system are in fact desirable features. | |
144 If `make install' fails for some package, because it attempts to install a | |
145 file with the same name as a pre-existing file from another package, you | |
146 should not curse the fact that you have to spend additional time to resolve | |
147 this issue. Instead you should be happy that you have been alerted of this | |
148 collision that, had it gone unnoticed, could have messed up your system in | |
149 more or less subtle ways. | |
150 Secondly, the package user system is not an all-or-nothing approach. It | |
151 works on a per-package basis. If a package gives you too much trouble, you | |
152 can always decide to chicken out and finish the installation as root. | |
153 Finally, the more_control_helpers archive provided with this hint contains | |
154 several useful scripts that automate many aspects of software installation | |
155 as a package user and, together with the tips given in this hint, add a lot | |
156 of value to the package user system. | |
157 So do not pass judgement until you have read at least the complete part 1, | |
158 including the description of the more_control_helpers. | |
159 | |
160 | |
161 ---------------------- PART 1: General Information -------------------------- | |
162 | |
163 | |
164 ############################################################################# | |
165 3. Package Users | |
166 ############################################################################# | |
167 | |
168 3.1 Introduction | |
169 ---------------- | |
170 | |
171 The basic idea of this scheme is easily explained. Every package belongs to a | |
172 certain "package user". When you install a package, you build and install | |
173 the package as this package user, causing all files that are installed to be | |
174 owned by the package user. As a consequence all the usual package management | |
175 tasks can be comfortably achieved through the use of standard command line | |
176 utilities. A simple `ls -l <file>' will tell you, for instance, what package | |
177 <file> belongs to and a `find -user ...' command allows you to perform an | |
178 operation on all the files belonging to a certain package, e.g. delete them | |
179 to uninstall the package. | |
180 | |
181 But package management is not all that package users are good for. Because | |
182 package users do not have root-rights, the installation of a package is | |
183 limited in what it can do. One thing that a package user is not allowed to do, | |
184 for example, is to overwrite files from a different package user. Clashes | |
185 between different packages that want to install a binary, library or header | |
186 file of the same name are more common than you might think. With package users | |
187 you never run the risk of package B's installation destroying files from | |
188 package A silently without you noticing. Every attempt of doing this during | |
189 package B's installation will cause a "Permission denied" or | |
190 "Operation not permitted" error so that you have the chance of taking | |
191 appropriate steps. | |
192 Another thing that package users are not allowed to do is install setuid root | |
193 binaries. The decision to make a binary setuid root is also something that a | |
194 prudent admin does not want to leave up to the creator of a software package. | |
195 | |
196 Usually package user accounts have no valid password so that only root can su | |
197 to a package user, which ensures that package users do not open an additional | |
198 way into the system and undermine security. But you *may* set passwords | |
199 anyway to allow a co-admin who you want to be able to install and maintain | |
200 certain software packages to do so without having access to the actual root | |
201 account. This co-admin could for instance install, delete, change additional | |
202 libraries which might be necessary for his workgroup. He would be unable, | |
203 though, to remove or modify libraries which don't belong to him/her, such as | |
204 libc. | |
205 | |
206 | |
207 3.2 User Name | |
208 ------------- | |
209 | |
210 You don't need to drive yourself nuts trying to come up with 8 character | |
211 names for the package users. I always use the name of the package without | |
212 the version number, including dashes and possibly exceeding 8 characters in | |
213 length, e.g. "util-linux", and in the several years that I've been using this | |
214 scheme I have not encountered any problems, nor has anyone else reported | |
215 trouble. The 8-character limit on user names seems to be a thing of the past. | |
216 | |
217 TIP: | |
218 You can use bash's programmable completion feature to save yourself some | |
219 typing when entering commands that take a user name as an argument, such as | |
220 su, finger or pinky. The command | |
221 | |
222 complete -o default -o nospace -A user su finger pinky | |
223 | |
224 tells bash to tab-complete words as user names for the commands su, | |
225 finger and pinky. | |
226 With this in place you can simply type `su linux-li<TAB>' and bash | |
227 will complete this to `su linux-libc-headers' (assuming that you have a | |
228 package user named "linux-libc-headers"). | |
229 "-o default" tells bash that if a suitable user name does not exist, the | |
230 default completion shall be attempted. | |
231 "-o nospace" prevents the addition of a space after the completed word. | |
232 | |
233 This is a very useful command to put into root's .bashrc and .bash_profile. | |
234 | |
235 BTW, at http://freshmeat.net/projects/bashcompletion/ | |
236 you can find a project that offers sophisticated completions for many | |
237 other commands. | |
238 | |
239 Or switch to zsh (http://freshmeat.net/projects/zsh/). It's more powerful | |
240 and less buggy than bash. | |
241 | |
242 | |
243 3.3 Groups | |
244 ---------- | |
245 | |
246 Every package user belongs to at least 2 groups. One of these groups is | |
247 the "install" group, which all package users (and only package users) belong | |
248 to. All directories that packages are allowed to install stuff in belong to | |
249 the install group. This includes directories such as /bin and /usr/bin but | |
250 excludes directories like /root or /. | |
251 The directories owned by the install group are always group-writable. | |
252 This would be enough for the package management aspects, but without further | |
253 preparation this would not give added security or control because every | |
254 package could replace the files from a different package (the change would | |
255 be visible in the output from `ls -l', though). | |
256 For this reason all install directories get the sticky attribute. This | |
257 allows users to create new files and delete or modify their own files in | |
258 the directory, but files from other users can not be modified or removed. | |
259 In the rest of this hint, whenever the term "install directory" is used, it | |
260 refers to a directory that belongs to group install, is group-writable and | |
261 sticky. IOW, to turn <dir> into an install directory you would do | |
262 | |
263 chgrp install <dir> && chmod g+w,o+t <dir> | |
264 | |
265 Although the install group is crucial for the package user system, it is | |
266 implemented as a supplementary group, rather than as the primary group for | |
267 package users. This has at least 2 advantages. | |
268 One advantage is that this makes it easy to get a list of all packages | |
269 installed on the system with the command | |
270 | |
271 grep install /etc/group | |
272 | |
273 A more important point, however, is that the primary group is the | |
274 one that files created by the package user will belong to. So it will be | |
275 printed in the output of `ls -l' and is subject to find's "-group" test. | |
276 This makes it very useful for organizational purposes. | |
277 Following are some suggestions for how to use the primary group. | |
278 | |
279 1. group name = user name | |
280 | |
281 Under this scheme the package user for the bash package would be | |
282 bash:bash. `ls -l /bin/bash' would show something like this | |
283 | |
284 -rwxr-xr-x 1 bash bash 1731859 Feb 30 2005 /bin/bash | |
285 | |
286 An important advantage of this scheme is that the user information is | |
287 not lost when you make a file setuid root, which requires changing | |
288 the file's owner. Because of this advantage, this scheme is the one | |
289 recommended by this hint. However, the hint's instructions will work | |
290 fine if you choose a different scheme. | |
291 | |
292 2. group name = package category | |
293 | |
294 Under this scheme, you would have certain package categories, such as | |
295 games, system, net,... and bash, being a system program, would possibly | |
296 belong to the system group, so that `ls -l /bin/bash' would show something | |
297 like this | |
298 | |
299 -rwxr-xr-x 1 bash system 1731859 Jul 4 1776 /bin/bash | |
300 | |
301 This system is nice, but probably not as useful as #1 above, unless you | |
302 have a real use for this categorization. | |
303 For a possible categorization see Appendix B at the end of this hint. | |
304 | |
305 3. group name = identifier for a real group of people | |
306 | |
307 Under this scheme, the group would correspond to a real group of people in | |
308 meatspace, e.g. the group of admins responsible for the package. | |
309 If you need something like this you'll know best what it looks like and how | |
310 to implement it, so no further discussion of this method will be given here. | |
311 | |
312 | |
313 3.4 Home Directory | |
314 ------------------ | |
315 | |
316 Although it is well possible not to have a valid home directory for package | |
317 users or to have just one home directory shared by all package users, that | |
318 would be a wasted opportunity. Having individual home directories for the | |
319 package users offers a nice way to organize tarballs, patches, build scripts, | |
320 notes and all the other per-package information that you accumulate with time. | |
321 | |
322 I suggest to use the home directory /usr/src/<package> for a package user | |
323 called <package> with the contents detailed below. The more_control_helpers | |
324 archive contains scripts and skeleton files that implement this suggestion. | |
325 | |
326 .bash_profile: | |
327 You will usually want to have the same environment for all package | |
328 users, so it is a good idea to make .bash_profile a symbolic link | |
329 to a file in a central location. The more_control_helpers example | |
330 uses /etc/pkgusr/bash_profile for this purpose. | |
331 | |
332 .bashrc: | |
333 As for .bash_profile a symlink is a good idea for .bashrc. The | |
334 more_control_helpers example uses /etc/pkgusr/bashrc as link target. | |
335 Under normal circumstances package users are not | |
336 (and even can not be) used for logging into the system, so there | |
337 is little reason to distinguish between login and non-login shells | |
338 for package users. Therefore, the example bashrc from | |
339 more_control_helpers simply sources .bash_profile. | |
340 This makes sure that the same environment will be used, regardless | |
341 of whether `su <package>' or `su - <package>' is used to become | |
342 the package user. | |
343 | |
344 .project: | |
345 The contents of this file are printed by the commands | |
346 `finger -l <user>' and 'pinky -l <user>' so .project is a | |
347 good place for putting information about a package. You should | |
348 keep the contents of the .project files for your package users | |
349 up-to-date. | |
350 | |
351 source code: | |
352 The package user's home directory is the perfect place for storing | |
353 a package's source code. This includes tarballs for different | |
354 versions, CVS checkouts, unpacked source trees for building,... | |
355 | |
356 build script(s): | |
357 Package user installations require more careful examination of build | |
358 and install messages than installations done as root, because of | |
359 the package user-specific problems that can occur. Therefore it is | |
360 unwise to simply copy'n'paste installation instructions from the | |
361 LFS book. Build scripts allow you to use sophisticated output | |
362 redirection for logging purposes that is impractical for direct | |
363 entry on the command line. The build script skeleton included in | |
364 the more_control_helpers archive demonstrates this. | |
365 | |
366 | |
367 ############################################################################ | |
368 4. Common Problems | |
369 ############################################################################ | |
370 | |
371 4.1 Introduction | |
372 ---------------- | |
373 | |
374 Software installation is the crux of the package user system. Because | |
375 installation scripts are often written under the assumption that they will be | |
376 executed as root, they sometimes fail when executed by a package user. | |
377 Once this hurdle is passed and a package has been installed, there's usually no | |
378 difference to a root-installation. A few programs insist that certain | |
379 security-sensitive files be owned by root and will not execute otherwise, | |
380 but this is the rare exception. | |
381 This chapter presents some more or less common problems that you will | |
382 encounter when using package user accounts to install software, together with | |
383 guidelines on how to deal with these issues. | |
384 Although I've said it before I will say it again: Many of the problems you | |
385 encounter during a package user installation are desirable features of the | |
386 package user system. You want installation to fail rather than have | |
387 potentially dangerous actions performed behind your back with root rights. | |
388 | |
389 | |
390 4.2 General Procedure | |
391 --------------------- | |
392 | |
393 When an installation fails it is almost always due to a "Permission denied" | |
394 or "Operation not permitted" error while executing a command during | |
395 `make install'. The first thing you have to do is identify the command that | |
396 is causing the problem. Usually you will find this in the make output right | |
397 before the error message. Once you have identified the culprit, you have to | |
398 decide whether the action that is attempted is illegitimate, partially | |
399 legitimate or completely legitimate. Illegitimate commands can simply be | |
400 removed from the Makefile. The other 2 possibilities are more difficult to | |
401 deal with. You either have to change the condition that makes the command fail | |
402 or you have to change or sometimes remove the command and make a note if your | |
403 change suppresses a legitimate action. | |
404 | |
405 After you've made changes to solve a certain problem, you reattempt the | |
406 installation and solve any remaining problems until the installation | |
407 succeeds. Once you've reached that point it is time to perform any remaining | |
408 legitimate actions that you've had to disable, such as make certain binaries | |
409 setuid root. | |
410 | |
411 Note that often Makefiles are generated during the configure step, sometimes | |
412 even later in the build process. If you want to apply changes before the | |
413 configure step you will usually have to edit files called "Makefile.in". | |
414 | |
415 | |
416 4.3 Permission Changes | |
417 ---------------------- | |
418 | |
419 Some unsophisticated build systems that don't use the mkinstalldirs script to | |
420 create installation target directories are very poorly written. Instead of | |
421 testing whether a target directory exists, they simply attempt to create | |
422 it with default permissions. This problem usually manifests as a line such | |
423 as "install -d $(prefix)/bin" in the Makefile. In the common case where | |
424 prefix=/usr this would attempt to create the /usr/bin directory. If the target | |
425 directory already exists, as in this case, install will attempt to change its | |
426 permissions to the default permissions (or those passed on the command line). | |
427 Of course a package user is not allowed to change the permissions of | |
428 /usr/bin and so the command fails with a message like | |
429 "install: cannot change permissions of `/usr/bin': Operation not permitted" | |
430 This is an example of a completely illegitimate command. Just remove it from | |
431 the Makefile and everything's fine. | |
432 | |
433 | |
434 4.4 Ownership Changes | |
435 --------------------- | |
436 | |
437 The most common situation when a package wants to change the ownership of | |
438 files during installation is when it wants to install setuid root binaries. | |
439 A common command to do this would be something like | |
440 "install -c -m 4755 -o root name /usr/bin/name" and the error message would | |
441 look like this: | |
442 "install: cannot change ownership of `name': Operation not permitted" | |
443 The change of ownership is hidden in the "-o root" switch to install, which | |
444 tells it to make the target file owned by root. | |
445 The command is at least partially legitimate, because you probably want the | |
446 binary to be installed. Whether you actually want it to be setuid root is | |
447 a different matter. The fact that a binary is commonly installed as setuid | |
448 root doesn't mean that you should make it so. You'll have to ask yourself if | |
449 normal users absolutely need to execute that binary. If you think they can | |
450 live without it you're better off not making it setuid root, because every | |
451 setuid root binary is a potential security hole. In any case you will | |
452 have to edit the Makefile and remove the offending switch, "-o root" in this | |
453 case, so that the installation can succeed. Note that this will cause the | |
454 binary to be installed setuid <package>, which of course makes no sense at all. | |
455 If you don't intend to make the binary setuid root after the installation, it | |
456 is best to change the "-m 4755" to "-m 755", so that it won't be installed | |
457 setuid at all. | |
458 | |
459 TIP: | |
460 When you make a binary setuid root after the installation, use | |
461 `chown root /usr/bin/name' and not `chown root:root /usr/bin/name'. | |
462 This way you can keep original group of the file (i.e. the group of the | |
463 package user) intact. With the user name = group name scheme recommended for | |
464 package users this makes sure that you can identify the source package of | |
465 the binary even after making it setuid root. | |
466 Note that as a security measure chown resets the setuid bit, | |
467 so you will have to do `chmod u+s /usr/bin/name' after the chown. | |
468 | |
469 | |
470 4.5 Write to Non-Install Directory | |
471 ---------------------------------- | |
472 | |
473 Sometimes packages want to create files or directories in non-install | |
474 directories. 3 situations have to be distinguished in this case. The 1st | |
475 possibility is that the target directory should be an install directory. | |
476 An example of this is /usr/share/aclocal. This directory is not among the | |
477 standard system directories created when building an LFS system. It will be | |
478 created by the first package that has files to install there and will be | |
479 owned by the corresponding package user. The next package that wants to write | |
480 in it will fail to install. The remedy is simple. Just make the directory an | |
481 install directory. You don't even need to be root to do it. The package user | |
482 that owns the directory has the rights to make that change. | |
483 | |
484 The 2nd possible reason for a package wanting to write to a non-install | |
485 directory is that the failing command is only partially legitimate, i.e. you | |
486 do want to have installed whatever it is meant to install, but you want it in | |
487 a different location. For example some packages install binaries that are not | |
488 meant to be called directly. The default location for these binaries is | |
489 sometimes called libexec and with prefix=/usr the package will attempt to | |
490 create /usr/libexec. In cases such as this you often don't have to change | |
491 any Makefiles. There is either a configure switch to change the directory in | |
492 question or it is just a matter of overriding a Makefile variable as in | |
493 `make libexecdir=/usr/lib install'. | |
494 | |
495 The 3rd possible reason for an attempt to write to a non-install directory is | |
496 that the command in question is illegitimate, i.e. you don't want to have | |
497 installed whatever the package wants to install. As usual with illegitimate | |
498 commands you can edit the Makefile and just remove them. In the case of | |
499 a whole directory whose installation you want to suppress it could be too | |
500 much effort to remove all of the offending commands that want to install | |
501 files there. In this case an approach similar to that from the previous | |
502 paragraph can be more effective. Either through configure switches or | |
503 overriding of variables you change the directory in question to something | |
504 like <builddir>/foobar, where <builddir> is the directory in which build | |
505 commands are run (i.e. usually the top of the unpackaged source | |
506 tree). This will cause the package to create the unwanted directory inside | |
507 the build tree, which doesn't cause any permission problems and has the nice | |
508 side effect that it'll be deleted together with the build directory when you | |
509 clean up after the build. | |
510 | |
511 | |
512 4.6 Delete or Overwrite File | |
513 ---------------------------- | |
514 | |
515 In a perfect world one package should not mess with another package's files, | |
516 but in the real world conflicts do happen occasionally. While a normal | |
517 sysadmin installing as root won't notice this until it's too late, an admin | |
518 employing the package user system will have to deal with conflicts right away. | |
519 When a package tries to overwrite or delete a file or directory that is owned | |
520 by another package the attempt will fail. It will fail even inside install | |
521 directories because of the sticky bit. | |
522 Although sometimes difficult to implement, the solution to such a conflict is | |
523 easy to describe. You need to either remove (or rename) the old file or | |
524 directory before installing, or suppress the installation of the new file or | |
525 directory. The installation of individual binaries is sometimes easy to | |
526 prevent. If you find a line such as "PROGRAMS=foo bar fubar barfu" in the | |
527 Makefile and "foo" is the name of the conflicting binary, just try removing | |
528 it from that list. That may be sufficient to prevent it from being installed. | |
529 | |
530 | |
531 4.7 /sbin/ldconfig | |
532 ------------------ | |
533 | |
534 Packages that install libraries sometimes run /sbin/ldconfig as part of their | |
535 installation so that the dynamic libraries are properly registered on the | |
536 system. Because a package user is not allowed to overwrite /etc/ld.so.cache | |
537 ldconfig fails. This failure is commonly ignored in Makefiles, but you should | |
538 take note of it anyway, because you need to run ldconfig as root after | |
539 the installation. Alternatively, the more_control_helpers contain a wrapper | |
540 program that calls /sbin/ldconfig and can be made setuid root. | |
541 | |
542 | |
543 4.8 What Commands to Run as a Package User | |
544 ------------------------------------------ | |
545 | |
546 A common problem that new users of this hint have is to decide which commands | |
547 to run as a package user and which commands to run as root. The general rule | |
548 is that the only commands to run as a package user are those for building, | |
549 installing, removing and modifying the files that belong to *that* package | |
550 user's package. Everything else should be run as root as usual. | |
551 Some things you CAN/SHOULD NOT DO as a package user include | |
552 | |
553 - starting daemons | |
554 - running udevstart | |
555 - stripping /lib/* | |
556 | |
557 | |
558 ############################################################################ | |
559 5. The more_control_helpers Archive | |
560 ############################################################################ | |
561 | |
562 5.1 Overview | |
563 ------------ | |
564 | |
565 The more_control_helpers archive contains files to help you with building and | |
566 maintaining a system that uses the package user method. One thing that the | |
567 more_control_helpers archive contains are some LFS-specific temporary files | |
568 that are only needed for the building of your LFS system and will not remain | |
569 installed in a permanent location. Then there are the previously mentioned | |
570 example files that demonstrate the suggested use of the package user home | |
571 directories discussed earlier. Another group of files contained in the archive | |
572 is a set of scripts that help with package management aspects, such as | |
573 creating new package users and checking which files a particular package has | |
574 installed. Finally the more_control_helpers archive contains wrapper scripts | |
575 for some commands that handle many of the common problems discussed in the | |
576 previous chapter and make package user installations a lot easier. | |
577 | |
578 | |
579 5.2 The Wrappers | |
580 ---------------- | |
581 | |
582 The previous chapter discussed some common problems encountered during | |
583 package user builds and how to solve them. The solution to an installation | |
584 failure usually requires editing of one or more Makefiles. Making such changes | |
585 manually is annoying, even if it happens only occasionally, and whenever you | |
586 reinstall a package you have to make the changes again. Sed scripts and patches | |
587 can help with the latter problem, but they still have to be custom fitted to | |
588 every package that needs them. There is a better solution, though. While there | |
589 exist countless ways to install files, only very few are commonly used by | |
590 packages. The 5 commands mkdir, chgrp, chown, chmod and install are responsible | |
591 for most of the problems that arise during an LFS installation. This | |
592 prompted me to write wrapper scripts for these 5 commands that recognize | |
593 certain problematic patterns and deal with them automatically. | |
594 | |
595 The instructions given in this hint in the LFS-specific part will instruct you | |
596 to install these wrappers in /usr/lib/pkgusr. If you do that and make sure | |
597 that this directory is the first entry in the PATH of every package user, then | |
598 they will save you a lot of time and effort in dealing with recurring issues. | |
599 Note that if you want to choose a directory other than /usr/lib/pkgusr for | |
600 the wrappers, you need to be careful. Some configure scripts ignore certain | |
601 locations. A subdirectory of /etc would not work, for instance, because /etc | |
602 is one of these locations. | |
603 | |
604 It is important that you understand the limitations of the wrapper scripts. | |
605 They can fix some problems without user intervention, such as turning | |
606 newly created directories in /usr/share/locale into install directories. | |
607 But other problems by their very nature require manual intervention. When a | |
608 program tries to install a setuid root binary, for instance, the wrapper | |
609 scripts will suppress the attempt to change ownership of an installed file to | |
610 root. While that allows `make install' to complete without error, it is only | |
611 a partial solution. The wrapper scripts can not (and should not) take away | |
612 your responsibility for deciding whether the program in question should be | |
613 setuid root and to make it so, if necessary. To account for this, the | |
614 wrapper scripts will output warning lines to standard error that start with | |
615 "***" whenever they encounter a situation that needs to be reviewed. | |
616 Following the "***" in the message will be the original command that the | |
617 installation attempted to perform. | |
618 You *must* check these "***" lines, examine the affected files or directories | |
619 and take appropriate action. Because of this it is imperative that you log | |
620 the messages output during a package installation and check these logs | |
621 religiously. The `build' script contained in the more_control_helpers archive | |
622 demonstrates some useful output redirection tricks to be used for this purpose. | |
623 The following 3 examples shall illustrate what kind of things you will have to | |
624 look for: | |
625 | |
626 Example 1: "*** install -c rsh -o root -m 4775 /usr/bin/rsh" | |
627 This message is output by the install wrapper during the installation of | |
628 inetutils. The package wants to install the rsh binary setuid root. The | |
629 install wrapper removes the "-o root" and changes the "-m 4775" to | |
630 "-m 755" before passing the command on to the real install program. | |
631 The important thing here is the "-m 4xxx", because this wants to set the | |
632 setuid bit. Some install scripts throw in a "-o root" for good measure | |
633 when installing an otherwise normal binary. In that case it's enough that | |
634 the install wrapper strips out the "-o root" and you don't have to take | |
635 further action. But when, as in the case of inetutils, the permissions | |
636 indicate an attempt to make a binary setuid or setgid, then you will have to | |
637 investigate. You need to decide if you want rsh to be setuid root and | |
638 if you decide you do, you need to become root and issue commands like this: | |
639 | |
640 chown root /usr/bin/rsh | |
641 chmod u+s /usr/bin/rsh | |
642 | |
643 TIP: | |
644 Be conservative with making binaries setuid. If you're unsure whether you | |
645 will ever use a program (as non-root), you probably don't want it to be | |
646 setuid root. Keep in mind that you can always make the change later when | |
647 you need it. When you apply this reasoning to rsh, for instance, you'll | |
648 probably end up not making it setuid root. | |
649 | |
650 | |
651 Example 2: "*** chgrp tty /usr/bin/write" | |
652 This is output by the chgrp wrapper during the util-linux installation. | |
653 The util-linux package wants to install the write program as setgid tty, | |
654 so that it is allowed to access other users' terminals. The chgrp wrapper | |
655 prevents the changing of the group and the chmod wrapper prevents the | |
656 setting of the setgid bit. You need to decide if you want the | |
657 program to be setgid and if you decide in favor of this, do as root | |
658 | |
659 chgrp tty /usr/bin/write | |
660 chmod g+s /usr/bin/write | |
661 | |
662 | |
663 Example 3: "*** install -d -m 755 /sbin" | |
664 This is also from the util-linux installation. Util-linux, for no good | |
665 reason, tries to recreate the /sbin directory. The install wrapper | |
666 prevents this and you don't have to take any further action. | |
667 | |
668 | |
669 5.3 add_package_user/install_package | |
670 ------------------------------------ | |
671 | |
672 Whenever you install a new package on your system, you first have to create | |
673 a new user account, possibly create a new group and if you follow the advice | |
674 from this hint about making productive use of a package user's home directory, | |
675 you will have to set up that one, too. If you were to do all of this manually, | |
676 it would be a lot of work. The add_package_user and install_package scripts | |
677 in the more_control_helpers archive were written to automate this. | |
678 | |
679 The install_package script is the one you will normally use to prepare for | |
680 installing a new package. It takes 3 parameters: the description of the | |
681 package, the name of the package user account to create and the name of the | |
682 package user's primary group. So if you use the user=group scheme recommended | |
683 by this hint and are as creative with your package descriptions as I am, then | |
684 the command you'll use to prepare for installing package "foo" will be | |
685 | |
686 install_package foo foo foo | |
687 | |
688 This command does 2 things. First it calls the add_package_user script with | |
689 the provided name, group and description plus sensible default values for | |
690 add_package_user's other parameters. Then, after add_package_user has created | |
691 the package user account, install_package automatically uses the su-command | |
692 to switch to the newly created account. If the default .bashrc and | |
693 .bash_profile scripts you use for package users contain the command "cd" as do | |
694 the examples in the more_control_helpers archive, you will be put right into | |
695 your package user's home directory so that you can start installing right away. | |
696 | |
697 TIP: | |
698 The install_package script can be called with a single argument that will | |
699 be used as user name, group name and description. So instead of the above | |
700 command a simple `install_package foo' would have sufficed. | |
701 | |
702 The add_package_user script is responsible for the actual work of creating | |
703 a new package user account. Given a name, a group name and a description, it | |
704 will create a new user account with the provided primary group and the install | |
705 group as supplementary group. The groups will be created if necessary. | |
706 add_package_user takes several arguments that determine the numeric ranges from | |
707 which it will pick the new user's UID and the GIDs for groups it needs to | |
708 create. add_package_user does not only create the package user account. It | |
709 will set up a home directory for it, too. You can either specify the directory | |
710 or go with the default, which is /usr/src/<name>, where <name> is the name | |
711 provided for the new account. If the home directory already exists, its | |
712 ownership and that of any existing contents will be changed to the new user. | |
713 If it doesn't exist, it will be created. | |
714 | |
715 The contents of /etc/pkgusr/skel-package will be copied into the new package | |
716 user's home directory (without overwriting pre-existing files). | |
717 The more_control_helpers archive contains an example of a useful skel-package | |
718 directory. Note that symlinks are copied as symlinks, so skel-package is the | |
719 perfect place to put .bashrc and .bash_profile symlinks to a central location | |
720 that will ensure that all package user accounts have the same environment. | |
721 This is especially useful to make sure that all package users have the | |
722 wrappers directory in their PATH. | |
723 | |
724 | |
725 5.4 forall_direntries_from | |
726 -------------------------- | |
727 | |
728 The forall_direntries_from script is a very useful tool for common package | |
729 management tasks. It can roughly be described as a shortcut for | |
730 "find / -user <name> -or -group <name> <commands>", where <name> is the | |
731 first parameter to forall_direntries_from and <commands> are the remaining | |
732 parameters. However, forall_direntries_from takes care of making sure that | |
733 only relevant filesystems are scanned and shields you from certain unpleasant | |
734 surprises such as "Oops, I forgot that -depth negates -prune and have | |
735 accidentally wiped out my home directory." or "Oops, I forgot to -prune /proc | |
736 and now I'm getting parity errors on my SCSI bus.". | |
737 | |
738 IMPORTANT NOTE: By default the forall_direntries_from script will only scan | |
739 the / filesystem and will not traverse other filesystems. If you have | |
740 relevant directories that need to be scanned on other filesystems, you will | |
741 need to edit the script and add the respective mount point(s) to the | |
742 fs_to_scan list at the beginning of the script. The most likely candidate for | |
743 addition is "/usr". | |
744 | |
745 Application examples: | |
746 | |
747 Example 1: Create a tar.gz archive of all files that belong to <package>, e.g. | |
748 for installing <package> on another machine without having to | |
749 recompile it there. | |
750 | |
751 forall_direntries_from <package> -fprint0 /tmp/files.lst | |
752 tar --null -P -czf /tmp/archive.tar.gz --files-from=/tmp/files.lst | |
753 | |
754 | |
755 Example 2: Print out all setuid root binaries installed by <package>. | |
756 (This only works if you use the user=group scheme.) | |
757 | |
758 forall_direntries_from <package> -perm +u+s -print | |
759 | |
760 | |
761 Example 3: List all binaries in /bin and /usr/bin belonging to "me" (i.e. the | |
762 package user executing the command) in alphabetical order. | |
763 | |
764 forall_direntries_from $(whoami) -path "*/bin/*" -printf "%f\n" | sort | |
765 | |
766 | |
767 Example 4: Uninstall <package>. | |
768 | |
769 See following section about the uninstall_package script. | |
770 | |
771 | |
772 5.5 uninstall_package | |
773 --------------------- | |
774 | |
775 The uninstall_package script is basically a forall_direntries_from | |
776 application example in script form. The command `uninstall_package foo' | |
777 prints out the forall_direntries_from call that you have to use to delete | |
778 all the files of package "foo" (except for those in directories that | |
779 forall_direntries_from is instructed not to scan) together with some | |
780 explanations. So in order to delete the files from package foo, you would | |
781 execute `uninstall_package foo' and then copy'n'paste the command it prints | |
782 to the command line. As a safeguard the forall_direntries_from call has an | |
783 "echo" in front of the "rm" and "rmdir" calls, so if you execute it, the files | |
784 will not actually be deleted unless you remove both instances of "echo". | |
785 It is recommended that you execute the command once with the echos and check | |
786 the output to make sure that only the files you intend to be deleted are in | |
787 the list. After you've confirmed that, you can use the shell's history to | |
788 recall the command, edit out the instances of "echo" and remove the files | |
789 for real. | |
790 | |
791 | |
792 5.6 list_suspicious_files/list_suspicious_files_from | |
793 ---------------------------------------------------- | |
794 | |
795 list_suspicious_files looks for filesystem entries that are out of the ordinary | |
796 in some way and prints a categorized list of them. Things that qualify as | |
797 suspicious include setuid and setgid binaries, world-writable files, symlinks | |
798 that are possibly broken, hard links, install directories with unusual | |
799 permissions and other stuff. You should run this script after you've finished | |
800 your new LFS system and in regular intervals after that. Investigate the | |
801 listing closely. | |
802 | |
803 TIP: | |
804 When you check the list of setuid and setgid files, don't forget to | |
805 look at the actual user or group ownership of the file. It's easy to forget | |
806 that, especially in the setuid case, because we often equate setuid with | |
807 setuid root since setuid is seldom used with other user accounts. | |
808 | |
809 list_suspicious_files_from takes a user or group name or a UID/GID as an | |
810 argument and reports suspicious entries only when they are owned by the given | |
811 user or group. Usually you would not call this script directly but instead | |
812 use list_package (described in the next section), whose output includes that | |
813 from list_suspicious_files_from. | |
814 | |
815 IMPORTANT NOTE: By default the list_suspicious_files script will only scan | |
816 the / filesystem and will not traverse other filesystems. If you have | |
817 relevant directories that need to be scanned on other filesystems, you will | |
818 need to edit the script and add the respective mount point(s) to the | |
819 fs_to_scan list at the beginning of the script. The most likely candidate for | |
820 addition is "/usr". | |
821 | |
822 | |
823 5.7 list_package | |
824 ---------------- | |
825 | |
826 list_package tells you everything about a package's installed files. In | |
827 general you will want to execute something like | |
828 | |
829 list_package $(whoami) >pkg.lst | |
830 | |
831 right after installing a package and you can forget about the chronically | |
832 inaccurate content listings in the (B)LFS book. | |
833 The following (shortened) output for util-linux speaks for itself: | |
834 | |
835 PS1> list_package util-linux | |
836 | |
837 EXECUTABLES (in */bin or */sbin) | |
838 agetty, arch, blockdev, cal, cfdisk, [...] vidmode(->rdev), whereis, write | |
839 | |
840 EXECUTABLES WITH NO MANPAGE (in */bin or */sbin) | |
841 fsck.cramfs, mkfs.cramfs | |
842 | |
843 MANPAGE SUMMARIES OF EXECUTABLES (in */bin or */sbin) | |
844 agetty: alternative Linux getty | |
845 arch: print machine architecture | |
846 blockdev: call block device ioctls from the command line | |
847 cal: displays a calendar | |
848 cfdisk: Curses based disk partition table manipulator for Linux | |
849 chkdupexe: find duplicate executables | |
850 col: filter reverse line feeds from input | |
851 [...] | |
852 swapon: enable/disable devices and files for paging and swapping | |
853 tailf: follow the growth of a log file | |
854 tunelp: set various parameters for the lp device | |
855 ul: do underlining | |
856 umount: unmount file systems | |
857 vidmode: query/set image root device, RAM disk size, or video mode | |
858 whereis: locate the binary, source, and manual page files for a command | |
859 write: send a message to another user | |
860 | |
861 EXTRA MANPAGES | |
862 /usr/share/man/man5/fstab.5 | |
863 /usr/share/man/man5/nfs.5 | |
864 /usr/share/man/man8/sln.8 | |
865 | |
866 EXTRA EXECUTABLES (not in */bin or */sbin) | |
867 /usr/share/misc/getopt/getopt-parse.bash | |
868 /usr/share/misc/getopt/getopt-parse.tcsh | |
869 /usr/share/misc/getopt/getopt-test.bash | |
870 /usr/share/misc/getopt/getopt-test.tcsh | |
871 | |
872 ALL FILES | |
873 /etc/fdprm | |
874 /sbin/agetty | |
875 /sbin/blockdev | |
876 /sbin/cfdisk | |
877 /sbin/ctrlaltdel | |
878 /sbin/elvtune | |
879 /sbin/fdisk | |
880 /sbin/fsck.cramfs | |
881 /sbin/fsck.minix | |
882 /sbin/hwclock | |
883 /sbin/losetup | |
884 /sbin/mkfs | |
885 /sbin/mkfs.bfs | |
886 [...] | |
887 /usr/share/man/man8/rootflags.8 | |
888 /usr/share/man/man8/setfdprm.8 | |
889 /usr/share/man/man8/setsid.8 | |
890 /usr/share/man/man8/sfdisk.8 | |
891 /usr/share/man/man8/sln.8 | |
892 /usr/share/man/man8/swapoff.8 | |
893 /usr/share/man/man8/swapon.8 | |
894 /usr/share/man/man8/tunelp.8 | |
895 /usr/share/man/man8/umount.8 | |
896 /usr/share/man/man8/vidmode.8 | |
897 /usr/share/misc/getopt | |
898 /usr/share/misc/getopt/getopt-parse.bash | |
899 /usr/share/misc/getopt/getopt-parse.tcsh | |
900 /usr/share/misc/getopt/getopt-test.bash | |
901 /usr/share/misc/getopt/getopt-test.tcsh | |
902 | |
903 SETUID FILES | |
904 -rwsr-xr-x "/usr/bin/mount" root:util-linux | |
905 -rwsr-xr-x "/usr/bin/umount" root:util-linux | |
906 | |
907 SETGID FILES | |
908 -rwxr-sr-x "/usr/bin/write" util-linux:tty | |
909 | |
910 FILES WITH UNUSUAL PERMISSIONS | |
911 -rwsr-xr-x "/usr/bin/mount" root:util-linux | |
912 -rwsr-xr-x "/usr/bin/umount" root:util-linux | |
913 -rwxr-sr-x "/usr/bin/write" util-linux:tty | |
914 | |
915 | |
916 Note: list_package works regardless of the prefix you've installed the package | |
917 with, so you can for instance configure with --prefix=/opt/package and | |
918 list_package will work just fine (provided that /opt is on a | |
919 filesystem configured to be scanned by forall_direntries_from and | |
920 list_suspicious_files). | |
921 | |
922 Note: list_package only considers manpages actually owned by the package to | |
923 list. It will not consider manpages installed by another package. This | |
924 means that you may see executables identified as not having a manpage | |
925 although they do have one courtesy of another package | |
926 (usually man-pages). | |
927 | |
928 | |
929 5.8 grep_all_regular_files_for | |
930 ------------------------------ | |
931 | |
932 This script is not really related to the package user system, but because of | |
933 its similarity to the other scripts I've included it anyway. The sole purpose | |
934 of this script is to identify files that store references to the build | |
935 environment, specifically the /tools directory. Such references may point out | |
936 problems, since the /tools directory is supposed to be transient. | |
937 Don't forget that results for unstripped binaries and libraries are not | |
938 reliable, because debugging information often includes references to the | |
939 build environment. These do not cause trouble (unless you're trying to debug | |
940 the objects in question after deleting /tools). | |
941 | |
942 IMPORTANT NOTE: By default the grep_all_regular_files_for script will only scan | |
943 the / filesystem and will not traverse other filesystems. If you have | |
944 relevant directories that need to be scanned on other filesystems, you will | |
945 need to edit the script and add the respective mount point(s) to the | |
946 fs_to_scan list at the beginning of the script. The most likely candidate for | |
947 addition is "/usr". | |
948 | |
949 | |
950 5.9 The etc Directory | |
951 --------------------- | |
952 | |
953 If you follow the instructions provided in the LFS-specific part of this hint, | |
954 the contents of the etc directory will be installed in /etc/pkgusr. The | |
955 directory contains a bashrc and bash_profile for package users that takes | |
956 care of package user specific details such as putting the wrappers directory | |
957 at the beginning of the PATH and calling cd, so that `su <package>' will | |
958 put you right into the package user's home directory. Also contained in the | |
959 etc directory is a skel-package directory as used by | |
960 install_package/add_package_user to populate the home directories of newly | |
961 created package users. | |
962 | |
963 | |
964 5.10 ldconfig.c | |
965 -------------------- | |
966 | |
967 A lot of packages contain libraries. Having to manually call /sbin/ldconfig | |
968 as root after installing these packages can become annoying. It would be | |
969 much easier if one could grant package users permission to use /sbin/ldconfig. | |
970 Making ldconfig setuid root would be a simple and effective solution, but | |
971 there are some pitfalls. First of all it is imperative that ordinary users | |
972 be prohibited from executing ldconfig with elevated privileges. Otherwise | |
973 an ordinary user can overwrite and possibly read arbitrary files on the | |
974 system. This can be prevented by making ldconfig owned by group install and | |
975 removing the o+x bit from the file mode. While this setup is no less secure | |
976 than running `make install' as root, one reason why we're using package users | |
977 is because we don't feel safe doing that. To protect against the (admittedly | |
978 very theoretical) danger of a malicious package user, the more_control_helpers | |
979 provide ldconfig.c. The only thing this program does is to call | |
980 `/sbin/ldconfig -v' with an empty environment. Because it doesn't evaluate | |
981 any user input and doesn't pass any user-provided data to ldconfig, it can | |
982 safely be made setuid root. | |
983 | |
984 | |
985 5.11 Temporary Files | |
986 -------------------- | |
987 | |
988 3 files in the more_control_helpers archive are only used during the | |
989 installation of the base LFS system and are not installed permanently. | |
990 The first of them is the installdirs.lst file that contains a list of | |
991 directories that should be install directories. | |
992 The second file is sbin/useradd, which is a very primitive shell script that | |
993 adds a new entry to /etc/passwd. It allows us to add package users before | |
994 we have installed shadow, which provides a real useradd. | |
995 Finally there is groupadd, which is like useradd, only for /etc/group. | |
996 Both scripts, useradd as well as groupadd, do very little error checking and | |
997 only support the syntax needed by install_package/add_package_user. So don't | |
998 try anything funky with them. | |
999 | |
1000 | |
1001 ------------------------ PART 2: LFS Specifics ------------------------------ | |
1002 | |
1003 | |
1004 ############################################################################# | |
1005 6. Pre-Chroot Phase (Chapter 5) | |
1006 ############################################################################# | |
1007 | |
1008 Build Chapter 5 explained by the LFS book with the following changes: | |
1009 | |
1010 coreutils: | |
1011 After running `make install' for the coreutils | |
1012 package, issue the following command (still from within the coreutils | |
1013 build directory): | |
1014 | |
1015 cp src/su /tools/bin | |
1016 | |
1017 This installs the su binary. Coreutils doesn't install su when working as | |
1018 non-root (which we do in Chapter 5), because su needs to be setuid root for | |
1019 normal operation and a non-root user cannot install setuid root binaries. | |
1020 But for our purposes (i.e. su'ing from root to a package user) a non-setuid | |
1021 su is enough, so we just copy coreutils' su to /tools/bin without making it | |
1022 setuid root. | |
1023 | |
1024 more_control_helpers: | |
1025 When you have reached the end of Chapter 5, before you begin with Chapter 6 | |
1026 you will need to install the helper scripts in the /tools directory so that | |
1027 they are available once you've entered the chroot environment. Use the | |
1028 following commands to install the more_control_helpers in /tools: | |
1029 | |
1030 cd /tools && | |
1031 tar xjf /path/to/more_control_helpers.tar.bz2 && | |
1032 cd more_control_helpers && | |
1033 cp ./sbin/* /tools/bin | |
1034 | |
1035 Note that the target directory is "/tools/bin" in the cp command and | |
1036 *not* "/tools/sbin", although the latter location would be more appropriate. | |
1037 The reason for this is simply that the LFS instructions do not add | |
1038 "/tools/sbin" to the PATH (and neither do the instructions in this hint). | |
1039 | |
1040 | |
1041 ############################################################################# | |
1042 7. Chroot Phase (Chapter 6) | |
1043 ############################################################################# | |
1044 | |
1045 7.1 Preparations | |
1046 ---------------- | |
1047 | |
1048 Enter the chroot environment and follow the instructions from the book up to | |
1049 but *not* including the installation of the first package (which at the time of | |
1050 this writing is linux-libc-headers). Now install the more_control_helpers | |
1051 files in their proper locations on the new LFS system: | |
1052 | |
1053 cp -a /tools/more_control_helpers/etc /etc/pkgusr && | |
1054 chown -R 0:0 /etc/pkgusr && | |
1055 cp -a /tools/more_control_helpers/lib /usr/lib/pkgusr && | |
1056 chown -R 0:0 /usr/lib/pkgusr && | |
1057 cp /tools/more_control_helpers/bin/* /usr/bin && | |
1058 cp /tools/more_control_helpers/sbin/* /usr/sbin && | |
1059 rm /usr/sbin/{useradd,groupadd} | |
1060 | |
1061 Note that the useradd and groupadd scripts are not installed on the new LFS | |
1062 system. These scripts are just temporary workarounds we will use as long as | |
1063 the real useradd and groupadd are not available. Therefore they should only | |
1064 be in /tools/bin. | |
1065 | |
1066 ATTENTION! If you decide to use a different directory than /usr/lib/pkgusr | |
1067 for the wrappers, you have to be careful, because at least the glibc | |
1068 configure script ignores certain directories when looking for programs. The | |
1069 list of ignored directories for glibc includes, among others, everything that | |
1070 starts with "/etc", "/usr/etc" and "/sbin". Wrappers put into a directory that | |
1071 matches any of these patterns would be ineffective. | |
1072 | |
1073 Now it's time to create the install group: | |
1074 | |
1075 groupadd -g 9999 install | |
1076 | |
1077 The GID 9999 has been chosen because the default range used by | |
1078 add_package_user for package user GIDs starts at 10000. Choose whatever number | |
1079 you like. | |
1080 | |
1081 Once the install group has been created you have to turn all the directories | |
1082 that packages will install files in into install directories. To make this | |
1083 easier I have compiled a list of install directories that can be found in | |
1084 the file /tools/more_control_helpers/installdirs.lst. The following command | |
1085 uses this list to assign the necessary directories to the install group. | |
1086 Note that you will get several error messages because of non-existent | |
1087 directories. This is because the list contains some directories not created | |
1088 by LFS. | |
1089 | |
1090 chown 0:9999 $(cat /tools/more_control_helpers/installdirs.lst) | |
1091 | |
1092 To be usable by package users, the directories will have to be group-writable | |
1093 and should be sticky as has been explained in the beginning of this hint. | |
1094 The following command sets the permissions appropriately. | |
1095 You will get the same error messages as for the previous command. | |
1096 | |
1097 chmod ug=rwx,o=rxt $(cat /tools/more_control_helpers/installdirs.lst) | |
1098 | |
1099 | |
1100 7.2 Walkthrough: Installing linux-libc-headers | |
1101 ---------------------------------------------- | |
1102 | |
1103 At this point everything has been set up for creating the first package | |
1104 user. At the time of this writing the first package installed in the LFS | |
1105 book is Linux-Libc-Headers, so this package will serve as an example for how | |
1106 things are done. The command | |
1107 | |
1108 install_package 'Linux Headers' linux-libc-headers linux-libc-headers | |
1109 | |
1110 will create a package user with user and group name linux-libc-headers. | |
1111 If you don't want to use the user=group scheme, change the last argument to | |
1112 the desired group name. The description is arbitrary but needs to meet the | |
1113 requirements for the description field of an /etc/passwd entry. | |
1114 | |
1115 TIP: | |
1116 Remember that you can call install_package with just one argument, if you | |
1117 want user name, group name and description to be the same. | |
1118 | |
1119 The directory /usr/src/linux-libc-headers will be set up as the home directory | |
1120 for the package user, automatically populated with the contents of | |
1121 /etc/pkgusr/skel-package. The install_package command also issues the command | |
1122 `su - linux-libc-headers' to assume the identity of the newly created package | |
1123 user. If you're using the bashrc and bash_profile scripts from the | |
1124 more_control_helpers archive, you will be put straight into the directory | |
1125 /usr/src/linux-libc-headers and your prompt will look like this | |
1126 | |
1127 package linux-libc-headers:/usr/src/linux-libc-headers> | |
1128 | |
1129 to show you that you're working as package user linux-libc-headers and | |
1130 that your current working directory is /usr/src/linux-libc-headers. | |
1131 | |
1132 Use the command | |
1133 | |
1134 echo $PATH | |
1135 | |
1136 to verify that your PATH starts with "/usr/lib/pkgusr", the directory that | |
1137 contains the wrappers, and ends with "/tools/bin". | |
1138 | |
1139 Now everything is prepared for installing the package according to the | |
1140 instructions in the LFS book. Note that at the time of this writing the | |
1141 LFS book tells you to execute a chown command to make sure that the headers | |
1142 are owned by root. This is just because the packager has made a very common | |
1143 mistake when creating the tarball for the headers: He has archived the files | |
1144 with a non-root user/group assignment. When unpacking such a tarball as root, | |
1145 the files end up being owned by some weird user/group combination, which may | |
1146 open a security hole. When you're working as a package user this can not | |
1147 happen and you don't want to chown the headers to root:root, because that | |
1148 would defeat the whole point of installing the headers with a package user. | |
1149 This is one of the small points on which you will have to deviate from the | |
1150 standard LFS instructions when using package users. More package user related | |
1151 issues with the current LFS book can be found in the next section. | |
1152 | |
1153 After you've installed the headers, simply issue the command | |
1154 | |
1155 exit | |
1156 | |
1157 to become root again. Now would be a good time to think about useful | |
1158 customizations for /etc/pkgusr/{bash_profile,bashrc} and/or | |
1159 /etc/pkgusr/skel-package, if you've not already customized them. | |
1160 Once you're satisfied with your setup, install the rest of the packages. | |
1161 The following section will help you with some problems that you will run into. | |
1162 | |
1163 | |
1164 7.3 Known Issues with LFS Packages | |
1165 ---------------------------------- | |
1166 | |
1167 This section has details on the package user related problems you will face | |
1168 when building your LFS system. You should copy the information from this | |
1169 section to the INSTALL NOTES of the relevant .project files for the packages | |
1170 concerned, together with any of your own notes. | |
1171 | |
1172 NOTE: If you're building by an LFS book later than 6.2 it is recommended that | |
1173 you read this complete chapter before you start building any packages. | |
1174 If your LFS version is 6.2 then it's fine to read this section package | |
1175 by package as you progress with your build. | |
1176 | |
1177 | |
1178 linux-libc-headers: | |
1179 At the time of this writing the LFS book tells you to execute a chown | |
1180 command to make sure that the headers are owned by root. This is just | |
1181 because the packager has made a very common mistake when creating the | |
1182 tarball for the headers: He has archived the files with a non-root | |
1183 user/group assignment. When unpacking such a tarball as root, the files | |
1184 end up being owned by some weird user/group combination, which may open | |
1185 a security hole. When you're working as a package user this can not happen | |
1186 and you don't want to chown the headers to root:root, because that would | |
1187 defeat the whole point of installing the headers with a package user. | |
1188 | |
1189 There used to be another packaging error in the linux-libc-headers. | |
1190 Version 2.6.12.0 (current as of this writing) doesn't have it anymore, | |
1191 but older versions used to contain files with permissions set incorrectly. | |
1192 All headers are supposed to be world-readable, but they weren't. More about | |
1193 this later in the glibc notes. | |
1194 | |
1195 | |
1196 man-pages: | |
1197 If the name you use for the man-pages package user is not exactly | |
1198 "man-pages", then you will have to change the variable "manpagesowner" | |
1199 right at the beginning of the wrapper script `install'. | |
1200 | |
1201 Recent versions of man-pages contain POSIX manpages that the package | |
1202 tries to install in /usr/share/man/man{0,1,3}p. There's also a manpage | |
1203 that man-pages wants to install to /usr/share/man/man9. | |
1204 As /usr/share/man is | |
1205 not an install directory and the LFS book does not have instructions to | |
1206 create these directories at the time of this writing, the installation | |
1207 will fail and the respective man-pages will not be installed. | |
1208 Possible remedies: | |
1209 1. Make /usr/share/man an install directory. | |
1210 Consequence: All Packages will be able to create new subdirectories | |
1211 in /usr/share/man. I find this undesirable because there are packages | |
1212 that create directories for manpages in foreign languages that I | |
1213 don't want. YMMV. | |
1214 2. Ignore the problem and live without the POSIX manpages. Unless | |
1215 you are a developer (including script writer) who is interested | |
1216 in writing portable programs/scripts this is a good solution. | |
1217 3. Create the directories /usr/share/man/man{0,1,3}p and man9 as root | |
1218 prior to installing man-pages. You'll have to either chown them | |
1219 to the man-pages package user or make them install directories. | |
1220 This is my preferred solution. | |
1221 | |
1222 | |
1223 glibc: | |
1224 It is kind of unfortunate that the packaging error of libc-linux-headers | |
1225 concerning the permissions doesn't exist in the current version. It | |
1226 provided for a great learning experience. I've kept the following section | |
1227 in the hint for this reason even though it doesn't apply anymore. Please | |
1228 take the time to read it. | |
1229 | |
1230 --------------------- old stuff start ---------------------------------------- | |
1231 Because of the error, the headers in /tools/include | |
1232 are not world-readable. Unfortunately the LFS book (as of this writing) | |
1233 does not correct this in Chapter 5 like it does in Chapter 6. For a | |
1234 standard LFS build this is no problem, because glibc is built as root and | |
1235 root can access everything regardless of permissions. | |
1236 The glibc package user, however, does not have permission to access | |
1237 these headers. This will cause several configure tests to fail, because | |
1238 the respective test programs can not be compiled. | |
1239 The end result is the error message "/lib/cpp fails sanity check", which | |
1240 is completely nonsensical as we don't have a /lib/cpp. | |
1241 | |
1242 This is the perfect opportunity to introduce rule #1 of error diagnostics: | |
1243 | |
1244 NEVER TRUST DIAGNOSTIC MESSAGES ! | |
1245 | |
1246 There are 2 kinds of diagnostic messages: | |
1247 | |
1248 1. Those that are unnecessary, because once you see which component has | |
1249 failed, the source of the problem is obvious. | |
1250 2. Those that grossly misdiagnose the source of the problem and lead | |
1251 you to draw the wrong conclusions. | |
1252 | |
1253 No, there is no other kind. Trust me ;-) | |
1254 In this case, /lib/cpp has nothing to do with the problem. It doesn't | |
1255 exist and that's fine. The message just wants to trick you into doing | |
1256 something stupid such as create a symlink /lib/cpp -> /tools/bin/cpp. | |
1257 But that would be totally wrong. Before you jump to any premature | |
1258 conclusions you should always try to get as much *low-level* information | |
1259 as you can. Diagnostic messages are *high-level* information. They | |
1260 represent a filtered view of the problem, which is usually of little help. | |
1261 Fortunately the message (the complete one, not the part quoted above) also | |
1262 points at the source for the necessary low-level information. In this | |
1263 case that is the file config.log (not to be confused with configure.log, | |
1264 the file created by the build script included in the more_control_helpers | |
1265 archive). | |
1266 config.log is created by all autoconf-created configures (not just that | |
1267 of glibc) and it contains, among other things, the test programs used by | |
1268 configure and messages output while building and running them. Whenever a | |
1269 configure script fails or gives weird results, check config.log. And | |
1270 always remember rule #2 of error diagnostics | |
1271 | |
1272 ALWAYS START AT THE FIRST ERROR | |
1273 | |
1274 This seems pretty obvious, but nevertheless people commonly do the exact | |
1275 opposite. It's just too tempting to start at the point of the final | |
1276 failure and try to work backwards. In this case many people would open | |
1277 config.log and scroll to the point of the failed /lib/cpp sanity check. | |
1278 After all, that's what caused configure to abort and so that's what needs | |
1279 to be fixed, right? WRONG! Someone who takes this approach just sees the | |
1280 error message "/lib/cpp: No such file or directory" and is even more | |
1281 convinced that a missing /lib/cpp symlink (or program) is the problem. | |
1282 | |
1283 The correct way to approach such a problem is to start at the beginning | |
1284 of config.log, to scroll down to first error message and to check if it | |
1285 is an issue that needs to be fixed (error messages in config.log are | |
1286 not always signs for a problem). If the issue needs to be fixed, then | |
1287 it needs to be fixed first, because all later errors could be rooted in | |
1288 this issue (even if, no, *especially* if you don't believe this is the | |
1289 case). | |
1290 If we apply this advice to the problem at hand, we quickly get to the first | |
1291 serious error in config.log: | |
1292 | |
1293 "/tools/include/linux/limits.h: Permission denied" | |
1294 | |
1295 A quick check with ls reveals that indeed the directory with the linux | |
1296 headers is not world-readable, which is obviously wrong. The fix is | |
1297 easy. Just make (as root) the header directories /tools/include/{linux,asm} | |
1298 world-readable with commands similar to those the LFS book presents | |
1299 in Chapter 6 for the installation of linux-libc-headers. | |
1300 Once this change has been made, glibc's configure succeeds. | |
1301 --------------------- old stuff end ----------------------------------------- | |
1302 | |
1303 TIP: | |
1304 Even when configure completes successfully, you should still check the | |
1305 output carefully to see if there is anything odd. E.g. if you're using | |
1306 the wrappers, you should check that configure outputs the line | |
1307 | |
1308 checking for a BSD-compatible install... /usr/lib/pkgusr/install -c | |
1309 | |
1310 If configure detects a different install, such as /tools/bin/install, | |
1311 something is wrong. Maybe there's a typo in the PATH for the package | |
1312 user, or you've put the wrappers into a directory that is ignored by | |
1313 configure. | |
1314 | |
1315 | |
1316 With the wrappers the glibc build and install should work smoothly. | |
1317 The wrapper script for install makes sure that the /usr/share/locale/* | |
1318 directories become install directories so that other programs can install | |
1319 their localized messages. | |
1320 One thing that the wrappers do not take care of, | |
1321 however, is the file /usr/share/info/dir. Because in the current LFS build | |
1322 order glibc is the first package that installs info files, dir is owned by | |
1323 and only writable by glibc. In order to allow other packages to install | |
1324 info pages, execute the following commands as root: | |
1325 | |
1326 chown root:install /usr/share/info/dir && | |
1327 chmod ug=rw,o=r /usr/share/info/dir | |
1328 | |
1329 NOTE: | |
1330 glibc wants to install the program pt_chown as setuid root. If you install | |
1331 as a package user, the program will get installed but not given root | |
1332 privileges (because of the install wrapper). | |
1333 The following info is from the glibc docs: | |
1334 | |
1335 One auxiliary program, `/usr/libexec/pt_chown', is installed setuid | |
1336 `root'. This program is invoked by the `grantpt' function; it sets the | |
1337 permissions on a pseudoterminal so it can be used by the calling | |
1338 process. This means programs like `xterm' and `screen' do not have to | |
1339 be setuid to get a pty. (There may be other reasons why they need | |
1340 privileges.) If you are using a 2.1 or newer Linux kernel with the | |
1341 `devptsfs' or `devfs' filesystems providing pty slaves, you don't need | |
1342 this program; otherwise you do. The source for `pt_chown' is in | |
1343 `login/programs/pt_chown.c'. | |
1344 | |
1345 So unless you're building a system that does not use devpts (which would | |
1346 be quite unusual), this does not need to concern you. | |
1347 | |
1348 TIP: | |
1349 In case you were wondering if you should create /etc/nsswitch.conf and | |
1350 /etc/ld.so.conf as root or glibc, I recommend to assign all files that | |
1351 you manually create or manually edit to the root account. That way you can | |
1352 distinguish between those files that can be regenerated automatically and | |
1353 those that can not. Assigning even automatically generated files to | |
1354 root once you make the first manual edit, ensures that a later | |
1355 reinstallation of a package won't silently do away with your manual tweaks. | |
1356 | |
1357 ldconfig: | |
1358 Now that glibc has installed /sbin/ldconfig you can activate the ldconfig | |
1359 wrapper if you want to. Perform the following steps as root | |
1360 AFTER re-adjusting the toolchain, | |
1361 just before starting with binutils: | |
1362 | |
1363 cd /usr/lib/pkgusr | |
1364 gcc -O2 -W -Wall -o ldconfig ldconfig.c | |
1365 chown root:install ldconfig | |
1366 chmod u=rwxs,g=rxs,o= ldconfig | |
1367 | |
1368 These instructions make the ldconfig wrapper setuid root and setgid install | |
1369 and prevent non-root users not in the install group from executing it. | |
1370 The setuid root is required so that it can replace /etc/ld.so.cache. | |
1371 The setgid install is not strictly required, but without it | |
1372 /etc/ld.so.cache will end up with the group of the last package user that | |
1373 touched it. If you use the user name=group name scheme this will cause the | |
1374 more_control_helpers scripts to believe that /etc/ld.so.cache belongs to | |
1375 the package in question which can be confusing. | |
1376 | |
1377 binutils: | |
1378 Have you make /usr/share/info/dir group-writable as explained above in | |
1379 the glibc notes? If you've missed that part, go back and do it now. | |
1380 The installation of binutils should complete without problems. | |
1381 It does however cause minor conflicts with autoconf (see later). | |
1382 | |
1383 NOTE: | |
1384 At the time of this writing the version of bash used in the LFS book has | |
1385 a bug that causes the list_package script to spit out errors and to list | |
1386 all manpages of binutils (and other packages) as Broken. This bug is | |
1387 already fixed by the bash patch used by the book but the patch is not | |
1388 applied in chapter 5. Since the manpage summary functionality of | |
1389 list_package requires man which is not installed until after bash is | |
1390 rebuilt, this doesn't really matter, because while patching the | |
1391 chapter 5 bash would get rid of the error messages, it wouldn't result | |
1392 in usable manpage summaries. | |
1393 | |
1394 | |
1395 gcc: | |
1396 Because the /usr/lib/libgcc_s.so* symlinks created at the beginning of | |
1397 Chapter 6 is owned by root, gcc's installation cannot remove it. | |
1398 So you will have to remove it as root before `make install'. | |
1399 Alternatively use | |
1400 | |
1401 chown -h gcc: /usr/lib/libgcc* | |
1402 | |
1403 to change ownership of the files in question after creating the gcc | |
1404 package user. Note the -h option which has to be used to change | |
1405 ownership of the symlinks themselves rather than their target files. | |
1406 | |
1407 db: | |
1408 It should be obvious that you don't want to change the ownership of the | |
1409 installed files. | |
1410 | |
1411 | |
1412 coreutils: | |
1413 Because the /bin/cat, /bin/pwd and /bin/stty symlinks are owned by root, | |
1414 coreutils' installation cannot remove them. So you will have to remove | |
1415 them manually before `make install'. Alternatively use the command | |
1416 | |
1417 chown -h coreutils: /bin/{cat,pwd,stty} | |
1418 | |
1419 after creating the coreutils package user. Note the -h switch that makes | |
1420 chown change the ownership of the symlinks themselves rather than their | |
1421 target files. | |
1422 | |
1423 The chapter 6 instructions move the coreutils binaries to /bin, including | |
1424 the mv binary itself. You need to make sure that hashing is turned off | |
1425 for this to work. The LFS book does this by putting `set +h' into the | |
1426 LFS user's .bashrc. If you're following this hint, you're likely using | |
1427 build scripts, so you need to put this command into the build script | |
1428 before the mv commands. | |
1429 | |
1430 NOTE: | |
1431 The man-pages package has already installed manpages for the binaries | |
1432 from coreutils. The install wrapper will prevent coreutils from overwriting | |
1433 those. This is done because the manpages from the man-pages package are | |
1434 of superior quality (although not necessarily uptodate). | |
1435 It also prevents errors during `make install' that | |
1436 would otherwise occur because the coreutils package user cannot overwrite | |
1437 manpages owned by another user. | |
1438 If you don't like the above behaviour and would rather have the original | |
1439 package manpages (because they are uptodate), you can set the variable | |
1440 manpagesowner at the beginning of the install wrapper to a string that | |
1441 doesn't correspond to a package user name (it must not be empty, though!). | |
1442 If you do this, you will have to resolve manpage conflicts in another way. | |
1443 The easiest way to handle this is probably to not install the man-pages | |
1444 package at the beginning of Chapter 6 but at the end, after all the other | |
1445 packages have already installed their manpages. Then you need only deal | |
1446 with the conflicts once, when installing man-pages. | |
1447 | |
1448 | |
1449 ncurses: | |
1450 The installation of ncurses (like that of other packages that include | |
1451 libraries) wants to run /sbin/ldconfig to update /etc/ld.so.cache. | |
1452 This fails because the package user doesn't have permission to replace | |
1453 /etc/ld.so.cache. | |
1454 Making /etc/ld.so.cache group-writable by the install group doesn't help, | |
1455 because the permissions would be reset on the next call to /sbin/ldconfig. | |
1456 This error will usually not abort the installation and you can just | |
1457 run /sbin/ldconfig manually as root afterwards. | |
1458 Alternatively you can use the ldconfig wrapper as described earlier. | |
1459 | |
1460 | |
1461 aclocal directory: | |
1462 At the time of this writing the directory /usr/share/aclocal is | |
1463 created during the bison installation. This directory contains | |
1464 macros for autoconf. Other packages want to install | |
1465 files into this directory, so you should make it writable by the install | |
1466 group and sticky. | |
1467 | |
1468 | |
1469 perl: | |
1470 Before you do `make install', you will have to | |
1471 `chown -h perl: /usr/bin/perl' so that the perl package user is allowed to | |
1472 remove the /usr/bin/perl symlink. | |
1473 | |
1474 If you will install add-on packages for perl as their own package users | |
1475 into /usr/lib/perl5/site_perl, then you will need to turn | |
1476 /usr/lib/perl5/site_perl/ and its subdirectories into | |
1477 install directories. You don't need to do this now as you'll notice it | |
1478 anyway when installing a perl add-on fails. | |
1479 | |
1480 | |
1481 autoconf: | |
1482 The autoconf package wants to install its own copy of standards.info, | |
1483 which fails because binutils has already installed this file. You can | |
1484 either ignore the error or remove the binutils version of standards.info | |
1485 before `make install'. | |
1486 | |
1487 | |
1488 bash: | |
1489 configure: | |
1490 The bash configure script tests for the presence of the special devices | |
1491 /dev/std* and /dev/fd/*. Unfortunately at the time of this writing the | |
1492 test for /dev/fd/* is buggy (the test for /dev/stdin used to be broke, too | |
1493 in bash-2.x, but has been fixed since). It ends up testing read access to | |
1494 standard input, | |
1495 which is the (pseudo)terminal you're building your system in. | |
1496 Unfortunately su doesn't change ownership of the terminal device, so when | |
1497 you're su'd to a package user account, the terminal still belongs to the | |
1498 login user. As the package user doesn't have read access to the device, | |
1499 the tests fail. | |
1500 | |
1501 There is a simple way to get around this. Simply run ./configure like this | |
1502 | |
1503 ./configure .... </dev/null | |
1504 | |
1505 The trick here is to redirect standard input (note, that this is a '<' not | |
1506 a '>' !) to refer to /dev/null. Unlike the terminal device, /dev/null is | |
1507 world-readable and world-writable, so the tests succeed as they should. | |
1508 If you don't like this trick, you can also chown the terminal device in | |
1509 question (see `ls -la /dev/fd/0') to the package user before building | |
1510 bash. | |
1511 | |
1512 make check: | |
1513 When running the test suite as a package user, the test "run-test" will | |
1514 fail with the output like this: | |
1515 | |
1516 33d32 | |
1517 < *** chmod g+s /tmp/test.setgid | |
1518 35c34 | |
1519 < 1 | |
1520 --- | |
1521 > 0 | |
1522 64d62 | |
1523 < *** chmod u+s /tmp/test.setuid | |
1524 66c64 | |
1525 < 1 | |
1526 --- | |
1527 > 0 | |
1528 154c152 | |
1529 < 1 | |
1530 --- | |
1531 > 0 | |
1532 160c158 | |
1533 < 1 | |
1534 --- | |
1535 > 0 | |
1536 | |
1537 The first 2 failures are caused by the chmod wrapper which prevents the | |
1538 test from setting the setuid and setgid bits and outputs the *** warning. | |
1539 The failures are harmless. You can get rid of them by removing the wrappers | |
1540 directory from the PATH before running the tests. | |
1541 | |
1542 The last 2 failures are not specific to package users but will occur | |
1543 whenever you run the tests su'd to another user. The reasons are the same | |
1544 as for the configure problem described earlier. The same solutions apply. | |
1545 Either use chown (if you chowned before configure you're already | |
1546 done, of course) or run make check like this | |
1547 | |
1548 make check </dev/null | |
1549 | |
1550 make install: | |
1551 Before you can `make install' you need to `chown -h bash: /bin/bash' as | |
1552 root so that the bash installation can replace the /bin/bash symlink that | |
1553 you manually created at the beginning of chapter 6. | |
1554 | |
1555 | |
1556 pkgconfig directory: | |
1557 At the time of this writing the directory /usr/lib/pkgconfig is | |
1558 created during the e2fsprogs installation. This directory contains | |
1559 build information used by the pkg-config tool. Other packages want to | |
1560 install files into this directory, so you should make it writable by the | |
1561 install group and sticky. | |
1562 | |
1563 | |
1564 grub: | |
1565 The commands to create and populate /boot/grub have to be executed as | |
1566 root. | |
1567 | |
1568 | |
1569 grep: | |
1570 Before you can `make install' you need to `chown -h grep: /bin/grep' as | |
1571 root so that the grep installation can replace the /bin/grep symlink that | |
1572 you manually created at the beginning of chapter 6. | |
1573 | |
1574 | |
1575 inetutils: | |
1576 This package contains some programs that it wants to be setuid root: | |
1577 rsh, rcp, rlogin and ping | |
1578 The install wrapper prevents these programs from being installed | |
1579 setuid root. You must decide which of these programs you want to be | |
1580 setuid root and manually make them so. Be conservative. Don't make a | |
1581 binary setuid root unless you *know* that ordinary users can't live | |
1582 without it. Every setuid root binary is a potential security hole. | |
1583 | |
1584 | |
1585 iproute2: | |
1586 This package tries to change the permissions of /usr/sbin and some man | |
1587 directories. The install wrappers take care of this. | |
1588 | |
1589 | |
1590 man-db: | |
1591 Even after installing man-db you won't get manpage summaries from | |
1592 list_package, because the way list_package calls man it needs col | |
1593 to work and col is from util-linux. You may however install util-linux | |
1594 right away. The alphabetical sort is the only reason it is at the end | |
1595 of Chapter 6. | |
1596 | |
1597 | |
1598 shadow: | |
1599 By default shadow wants to install non-English manpages. This fails | |
1600 because the /usr/share/man directory is not an install directory and | |
1601 therefore package users are not allowed to create new subdirectories in it. | |
1602 To solve this problem, before you `make install', open the file | |
1603 man/Makefile, find the line | |
1604 | |
1605 SUBDIRS = cs de es fr hu id it ja ko pl pt_BR ru zh_CN zh_TW | |
1606 | |
1607 and remove all the languages that you don't want to install. For those | |
1608 languages that you do want to install, create directories with the | |
1609 respective names in /usr/share/man as root and make them install | |
1610 directories (i.e. group install, group-writable, sticky). | |
1611 | |
1612 There is yet another issue with shadow concerning manpages. The shadow | |
1613 package contains a passwd.5 and a getspnam.3 manpage. | |
1614 Installation of these manpages is | |
1615 automatically suppressed by the install wrapper, because it would | |
1616 overwrite the manpages provided by the man-pages package. As usual | |
1617 the man-pages version is better, so you can simply ignore this issue. | |
1618 | |
1619 shadow wants to install the programs su, chage, chfn, chsh, expiry, | |
1620 gpasswd, newgrp and passwd as setuid root. You will need to decide which | |
1621 of these programs you want to be setuid root and manually make them so. | |
1622 | |
1623 | |
1624 sysklogd: | |
1625 sysklogd's Makefile has /usr/bin/install hardwired as the install | |
1626 program, which circumvents the install wrapper. The wrapper is needed | |
1627 for sysklogd because it tries to make its manpages owned by root | |
1628 (which obviously a package user is not allowed to do). | |
1629 Therefore, install with | |
1630 | |
1631 make INSTALL=install install | |
1632 | |
1633 | |
1634 udev: | |
1635 udev wants to install files into the directory /usr/lib/pkgconfig. If | |
1636 you've followed the instructions given further above you've already made | |
1637 this an install directory. If you haven't, do so now or the udev | |
1638 installation will fail. | |
1639 | |
1640 The LFS instructions for installing udev tell you to execute the command | |
1641 | |
1642 mknod -m0666 /lib/udev/devices/null c 1 3 | |
1643 | |
1644 Because a package user is not allowed to create device nodes, execute this | |
1645 command as root. | |
1646 | |
1647 | |
1648 util-linux: | |
1649 util-linux wants to install write as setgid tty and u/mount as | |
1650 setuid root. The wrappers catch this, so it doesn't cause the install to | |
1651 fail, but as usual you'll have to decide if you want these programs to | |
1652 have special privileges and take manual action as root if you do. | |
1653 | |
1654 | |
1655 ########################################################################## | |
1656 8. Sanity Checks | |
1657 ########################################################################## | |
1658 | |
1659 8.1 Suspicious Files | |
1660 -------------------- | |
1661 | |
1662 You probably ran the `list_package' command for each package and reviewed | |
1663 the results which include the suspicious files owned by that package. But even | |
1664 if you did that it's still a good idea to run the non-package specific | |
1665 `list_suspicious_files' command once your build is complete. There could be | |
1666 something you overlooked the first time, or maybe you created a file as root | |
1667 with the wrong permissions. It doesn't hurt to check again and this will also | |
1668 give you the opportunity to review any setuid/setgid decisions you made with | |
1669 respect to the installed binaries. | |
1670 | |
1671 TIP: | |
1672 When you check the list of setuid and setgid files, don't forget to | |
1673 look at the actual user or group ownership of the file. It's easy to forget | |
1674 that, especially in the setuid case, because we often equate setuid with | |
1675 setuid root since setuid is seldom used with other user accounts. | |
1676 | |
1677 | |
1678 8.2 References to Temporary Files | |
1679 --------------------------------- | |
1680 | |
1681 One big concern when building an LFS system is independence of the new LFS | |
1682 system from the files installed in /tools. The /tools directory is intended | |
1683 to be temporary and it should be possible to delete it after building your | |
1684 LFS system with no adverse side effects. The `grep_all_regular_files_for' | |
1685 script from the more_control_helpers package can help you verify that your | |
1686 new LFS system is indeed clean. The command | |
1687 | |
1688 grep_all_regular_files_for /tools | |
1689 | |
1690 will give you a list of all files that contain the string "/tools". Review the | |
1691 files in the list to make sure that no dependencies on the temporary files in | |
1692 /tools have crept in. But remember that results from binaries and libraries | |
1693 are only meaningful after stripping away the debug information, because | |
1694 debug information necessarily includes references to the build environment. | |
1695 Of course, if you are a developer who will potentially run gdb on system | |
1696 libraries/binaries, your position will be that stripping away debug information | |
1697 is the wrong way to do away with /tools references. The other way to deal with | |
1698 them is to rebuild packages for which /tools references are reported. The new | |
1699 build will not involve any files from /tools and so the new debug information | |
1700 will not refer to /tools. Note that the LFS build instructions for glibc | |
1701 make glibc compile against /tools/glibc-kernheaders. Unless you copy the | |
1702 glibc-kernheaders directory to a location outside of /tools and compile glibc | |
1703 against that copy, you won't get rid of the /tools references in glibc's | |
1704 debug information. | |
1705 No matter what means you choose to deal with the debug information issue, in | |
1706 the end you should have a system where the above command produces only false | |
1707 positives (such as "perlfaq3.1", which includes the URL | |
1708 "http://www.research.att.com/sw/tools/uwin/") and files that legitimately | |
1709 refer to /tools (such as a copy of this hint file). | |
1710 | |
1711 | |
1712 ----------------------------- APPENDICES ---------------------------------- | |
1713 | |
1714 | |
1715 ########################################################################### | |
1716 Appendix A: Security Issues | |
1717 ########################################################################### | |
1718 | |
1719 A.1 NFS | |
1720 ------- | |
1721 | |
1722 If you use the network filesystem NFS, there are some things you need to | |
1723 look out for when using the package user system. A fundamental security | |
1724 problem with NFS is that it blindly trusts the UID and GID of the client. | |
1725 If an attacker can get access to the root account on a system in your network | |
1726 that is allowed to mount NFS shares from your server, or if the attacker can | |
1727 attach his own computer to your network, then this attacker can pretend to be | |
1728 anyone. NFS will happily allow the attacker to work in the NFS exported | |
1729 directory as any user he wants to be. The only exception is the root account. | |
1730 By default NFS exports directories with the root_squash option that maps all | |
1731 incoming requests from uid 0 to anonuid (65534 unless set in /etc/exports) | |
1732 and gid 0 to anongid (65534 unless set in /etc/exports). This protects files | |
1733 owned by root:root. On a normal system this includes most files in /bin, /etc, | |
1734 /lib and most other directories except /home. If you use the package user | |
1735 scheme, however, most of these files are owned by package users. These files | |
1736 are not protected by the root_squash option. In order to make NFS exports | |
1737 secure, you have to add the option "all_squash" to every entry in /etc/exports | |
1738 that exports a directory that contains files owned by package users. Note that | |
1739 all_squash is always a good idea because even systems that don't use package | |
1740 users often have some programs owned by other users or groups, because they | |
1741 need to be setuid or setgid. | |
1742 | |
1743 | |
1744 A.2 Daemons | |
1745 ----------- | |
1746 | |
1747 It is a common practice to run daemons under special user accounts rather | |
1748 than as root as a security measure. If you feel tempted to use a package | |
1749 user account for this purpose, resist the temptation. It would be a very | |
1750 stupid idea. Although they are deliberately less powerful than root, package | |
1751 user accounts are still privileged and need to be considered as equivalent to | |
1752 root as far as security is concerned. Do not do anything with a package user | |
1753 that on a system without package users you would not do with the root account. | |
1754 | |
1755 | |
1756 ########################################################################### | |
1757 Appendix B: Package Categories | |
1758 ########################################################################### | |
1759 | |
1760 Although the user name = group name scheme is recommended by this hint, it is | |
1761 not the only possible one. Another scheme that has some appeal is to define | |
1762 package categories and to use the group for the purpose of categorizing the | |
1763 packages. Following is a suggested set of categories that can serve as a | |
1764 guideline for implementing this scheme. | |
1765 | |
1766 devel: development related stuff, e.g. compilers. This is not restricted to | |
1767 software development. TeX for instance would belong in this group. | |
1768 | |
1769 utils: Most software fits into this category, even somewhat essential software | |
1770 like grep or text editors. | |
1771 | |
1772 net: network related stuff such as an ftp daemon or a web browser. This | |
1773 group overlaps with other groups to a large extent. It should be used | |
1774 in preference of the other groups whenever a package is clearly focused | |
1775 towards Internet, LAN, WWW,... A utility like wget for instance would | |
1776 go in net rather than utils. Exceptions from this rule are the groups | |
1777 docs, addons, games and mmedia. If a package fits into one of those | |
1778 groups, use the respective group instead of net. | |
1779 | |
1780 docs: Documentation related packages, such as a tarball with Linux howtos. | |
1781 Note that software to create documentation such as XML processors should | |
1782 probably go in devel and software to view or post-process documentation | |
1783 such as man or groff should probably go in utils. | |
1784 | |
1785 system: important system software, such as bash. This group should be used | |
1786 only for really essential packages. Most packages you would put in | |
1787 this group are better put in "utils". Vi for instance belongs in | |
1788 utils. | |
1789 It is unlikely that any package not part of basic LFS belongs in the | |
1790 system group. | |
1791 | |
1792 libs: What utils is for executables, libs is for libraries. Libraries that are | |
1793 not strongly related to any of the other categories should go here, such | |
1794 as zlib or libpng. | |
1795 Essential system libraries such as glibc, ncurses or gettext should | |
1796 go in system instead. | |
1797 The libs group is also used for run-time environments such as the | |
1798 Java Virtual Machine, dosemu and wine. Other emulators like MAME for | |
1799 instance should probably go into games instead. | |
1800 | |
1801 games: what do you expect ;-) | |
1802 | |
1803 mmedia: This is the group for audio and video editors, mp3 players etc. | |
1804 | |
1805 apps: Applications such as spreadsheets and word processors (not text editors) | |
1806 but also CAD software and graphics software such as Gimp. | |
1807 The apps group is a bit like utils, but apps are usually more user | |
1808 friendly and more streamlined and feel less nerdish than utils. | |
1809 | |
1810 addons: plugins, filters and similar that are meant to be used in conjunction | |
1811 with another package. | |
1812 | |
1813 x: software that relates to the X Window System in general and does not fit | |
1814 into any of the other categories, such as the X server itself or window | |
1815 managers. | |
1816 Most X software should be put into other more specific groups. | |
1817 A game like xmines would go in games for instance and a text editor for | |
1818 X would go in utils. | |
1819 | |
1820 kde: Software that relates to KDE and does not fit into | |
1821 any other category. This group should be used with care. | |
1822 Do *not* use it for all KDE software. K Office for instance belongs in | |
1823 apps. Konqueror belongs in net. | |
1824 | |
1825 gnome: Software that relates to GNOME and does not fit into | |
1826 any other category. This group should be used with care. | |
1827 Do *not* use it for all GNOME software. Gimp for instance belongs | |
1828 in apps. A GNOME-aware window manager that works with plain X should | |
1829 go in the x group. | |
1830 | |
1831 | |
1832 ########################################################################### | |
1833 Appendix C: Acknowledgements and Changelog | |
1834 ########################################################################### | |
1835 | |
1836 ACKNOWLEDGEMENTS: | |
1837 * Matthias Benkmann for writing the original version of this hint | |
1838 * Tushar Teredesai for suggesting the user=group scheme. | |
1839 * Markus Laire for reporting the 2005-01-01 build bug | |
1840 | |
1841 CHANGELOG: | |
1842 | |
1843 2007-10-20 Matthias Benkmann | |
1844 -relicensed under CC-BY-SA (previously CC-BY-ND). | |
1845 -added name tags to changelog entries in preparation for having the | |
1846 hint continued by different authors. | |
1847 -added workaround to list_package for bug in man-db that causes | |
1848 some manpages to show up as "Weird manpage" in the summary. | |
1849 -chmod wrapper now prevents shadow from installing files setuid | |
1850 shadow. | |
1851 -added a wrapper to solve ldconfig issue. | |
1852 -install_package now works when called with just a single argument. | |
1853 That argument is used for user name, group name and description. | |
1854 -bash_profile of more_control_helpers now has /sbin and /usr/sbin | |
1855 in the PATH to match the PATH used by root when building. | |
1856 -install_package does su - <name> now (i.e. start a login shell). | |
1857 -build script now handles unpacking of tarballs and allows calling | |
1858 the different stages individually. | |
1859 -useradd uses the -s provided shell and no longer hardwires bash. | |
1860 -chapter 6 bash notes now properly address the configure and | |
1861 make check issues. | |
1862 | |
1863 2007-03-21 Matthias Benkmann | |
1864 -changed forall_direntries_from to avoid warning message from find | |
1865 when -depth is used. | |
1866 -added 4.8 What Commands to Run as a Package User | |
1867 | |
1868 2005-12-22 Matthias Benkmann | |
1869 -added advice on how to cope with the moving mv problem to | |
1870 coreutils note. | |
1871 | |
1872 2005-11-13 Matthias Benkmann | |
1873 -fixed list_suspicious_files and list_package to work with | |
1874 recent more POSIX-conforming versions of GNU find | |
1875 -released version 1.2 | |
1876 | |
1877 2005-01-01 Matthias Benkmann | |
1878 -fixed bug in skel-package/build script that caused it to report | |
1879 all steps as successful, even if they failed | |
1880 -released version 1.1 | |
1881 | |
1882 2004-11-01 Matthias Benkmann | |
1883 -capitalized title | |
1884 -released version 1.0 | |
1885 | |
1886 2004-10-14 Matthias Benkmann | |
1887 -started developing the more_control_helpers utilities | |
1888 | |
1889 2004-08-14 Matthias Benkmann | |
1890 -started major rewrite (update for new LFS version, new hint | |
1891 format, textual improvements,...) | |
1892 | |
1893 2002-04-20 Matthias Benkmann | |
1894 -changed LFS VERSION header to be more conservative | |
1895 -added <br> tags to the synopsis for the sake of the hints | |
1896 index | |
1897 -added group mmedia to the list of suggested groups | |
1898 -submitted v0.8 | |
1899 | |
1900 2002-03-16 Matthias Benkmann | |
1901 -added note, that on Linux make doesn't need to be setgid kmem | |
1902 | |
1903 2002-02-18 Matthias Benkmann | |
1904 -added section "Security issues with NFS" | |
1905 -submitted v0.7 | |
1906 | |
1907 2002-01-30 Matthias Benkmann | |
1908 -added Changelog | |
1909 -moved "chown 0.10000 `cat /tmp/installdirs`" command up (before | |
1910 glibc package user is created) | |
1911 -add_package_user: create home directory with "mkdir -p" | |
1912 use $grpfile everywhere instead of /etc/group | |
1913 -improved mammoth sentence in Introduction | |
1914 -added note about possibility to have user name==group name | |
1915 -source bashrc_basic in bashrc_package | |
1916 -minor textual changes |