After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 310474 - add a 'root' sanity check to gar.conf.mk
add a 'root' sanity check to gar.conf.mk
Status: RESOLVED FIXED
Product: GARNOME
Classification: Deprecated
Component: general
unspecified
Other All
: Normal enhancement
: ---
Assigned To: Karsten Bräckelmann
garnome list
Depends on:
Blocks:
 
 
Reported: 2005-07-15 10:42 UTC by Karsten Bräckelmann
Modified: 2007-10-14 20:34 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
proposed fix (1.56 KB, patch)
2007-10-12 22:19 UTC, Karsten Bräckelmann
committed Details | Review

Description Karsten Bräckelmann 2005-07-15 10:42:46 UTC
gar.conf.mk needs a "root sanity check" added and a BULD_AS_ROOT option.

# export BUILD_AS_ROOT = true

If BUILD_AS_ROOT != true and the building user is 'root', GARNOME should stop
and provide a message to read the README and check the configs in gar.conf.mk.


That way, no dumb user will be able to build as root (by accident, or cause he
just does not care and didn't reda the README at all).

I'm too tired of those clueless folks, who do not know what the are actually
doing. I don't want them to possibly harm their system, end up with a unusable
build (due to default $main_prefix) or help them to fix the mess...
Comment 1 Karsten Bräckelmann 2005-07-15 10:43:59 UTC
Re-assigning to me.
Comment 2 Paul Drain 2005-07-20 02:33:47 UTC
A very good idea.

Although, couldn't this be done with a [if $UID = 0] type of check in the main
gar.mk file, rather than cluttering the install with another option.

In addition, doing a $UID check might actually allow us to run 'useradd' on the
users behalf, if it's true :)

Maybe:

'echo -n 'GARNOME should not be built as root'
'echo -n 'we have created a user called 'build' for you'
'cat README'
Comment 3 Karsten Bräckelmann 2007-10-12 21:12:57 UTC
OK, finally tried implementing this. Turns out it isn't as easy as one would think... Couple notes and discussion:


It's actually irrelevant which one is used, gar.mk or gar.gnome.mk. I do agree however, that we do not need another variable. If, for some really strange reason, a users needs to build as root, he can comment out a single line just as wekk as set a variable. :)

Some code like this would do. Since it is not a target, it will be evaluated when reading in the file, and crap out immediately. Regardless, if a target has been completed before (running as user).

  UID ?= $(shell id -u )

  ifeq (${UID}, 0)
    $(error Cowardly refusing to run with superuser privileges)
  endif

'make' doesn't make it easy to confront the user with a meaningful, unambiguous and eye-cathing error message. Anyway, figured out how to do that, so the error message won't get lost in a bunch of 'make' chatter.


There is one tiny downside to this approach, though. Recursive 'make'.

Placing the root sanity check in gar.mk (or gar.gnome.mk) will be evaluated for each garball. When buidling desktop/ for example (as per the README), this will result in a single test and immediately crapping out for good -- IFF paranoid- is being used.

This is due to how the top-level Makefile and the ones in each meta-garball are calling 'make' recursively for it's contents. Now, the downside when attempting to build desktop/ with a plain 'install' target as root is, that *each* desktop/ garball will stop immedietaly with the exact same error message. Since it is the same with this target and any other general problem, I believe we can live with that.

(However, there is a possible solution: Including a dedicated sanity check file from exactly tree top-level files -- gar.mk, category.mk and Makefile. This just needs to be guarded by an ifndef and defining a variable to prevent including and evaluating this multiple times, similar to C header includes. Probably not worth the effort, though.)


Comments? Thoughts?
Comment 4 Karsten Bräckelmann 2007-10-12 22:19:33 UTC
Created attachment 97149 [details] [review]
proposed fix
Comment 5 Karsten Bräckelmann 2007-10-12 22:26:56 UTC
OK, after some discussion on IRC with Joseph:

Not including the second check in category.mk would result in this error be thrown for each garball in desktop/, when running this:
  make -C desktop/ install

That is, using 'install' instead of 'paranoid-install'. Seems to be quite common. Instead of 80-odd identical errors, this stops immediately after the first one. Also useful to prevent *300* such error messages in the case of a top-level 'make install'...

Downside: To actually build as root, one needs to change 2 files. Not that a big deal, IMHO. However, much nicer. :)


I decided to go with gar.gnome.mk, because it is less cluttered and more GARNOME specific anyway.
Comment 6 Karsten Bräckelmann 2007-10-14 20:34:03 UTC
As per discussion on IRC:  Committed to both stable and trunk.