How To Prevent A Python Script From Running As Root

At or near the top of your app, before it executes anything sensitive, place the following code:

if os.geteuid()==0:
    print "Cannot run as root!"
    sys.exit(1)

How to do this in PERL: …how-to-prevent-a-perl-script-from-running-as-root…

Did you find this post useful or have questions or comments? Please let me know!

Posted in How Tos, Programming, python | Leave a comment

Read a Changelog From an RPM File

The internet is full of tips on how to read the changelog from an RPM package you have installed.

How do you read the changelog from a .rpm file before you install it?

The answer is amazingly simple:

rpm -q --changelog -p /path/to/file.rpm

Anything you can query from an installed package with rpm -q you can query from a file with -p.

So why is the answer hard so to find? Because the rpm man page describes -p,--package PACKAGE_FILE under select-options, but leaves it out under query-options.

The fact that there is a curly brace where there should be a square bracket tells me the maintainers of this man page don’t actually use it.


select-options
[PACKAGE_NAME] [-a,--all] [-f,--file FILE]
[-g,--group GROUP] {-p,--package PACKAGE_FILE]
[--fileid MD5] [--hdrid SHA1] [--pkgid MD5] [--tid TID]
[--querybynumber HDRNUM] [--triggeredby PACKAGE_NAME]
[--whatprovides CAPABILITY] [--whatrequires CAPABILITY]

query-options
[--changelog] [-c,--configfiles] [-d,--docfiles] [--dump]
[--filesbypkg] [-i,--info] [--last] [-l,--list]
[--provides] [--qf,--queryformat QUERYFMT]
[-R,--requires] [--scripts] [-s,--state]
[--triggers,--triggerscripts]

Did you catch that?

Under select-options {-p,–package PACKAGE_FILE] should read [-p,–package PACKAGE_FILE] and the package flag should be under query-options as well.

You can file the bug report. I have work to do.

Did you find this post useful or have questions or comments? Please let me know!

Posted in How Tos, linux, rpm | Leave a comment

OpenSUSE 11 and SLES 11 Enable Multiple Kernel Support for zypper

By default, when zypper upgrades your kernel, it treats the package like any other package. The old kernel is removed and the new kernel is installed. There are three ways to get your old kernel back (or keep it).

  1. You can re-install it with RPMS. This is involves manually updating your /boot/grub/menu.lst files when you are done.
    In order to boot on your previous kernel
  2. After the upgrade, you can use zypper to install the kernel packages that it removed by throwing various flags on there to force it to ignore conflicts. You still have to go mess with /boot/grub/menu.lst because your old kernel will now be the new default
  3. The best way: Tell zypper to leave your old kernel alone, but install the new kernel as the new default.

Number three is easily done by adding two lines to the /etc/zypp/zypp.conf file before upgrading your kernel.

Add or update these lines in the [main] section of /etc/zypp/zypp.conf

multiversion = provides:multiversion(kernel)
multiversion.kernels = latest,latest-1,running

multiversion defines which packages are allowed to exist with multiple versions of the same package name. Just specifying kernel will allow you to retain all of the available kernel packages. You can restrict which packages by being more specific. For instance: multiversion = kernel-default,kernel-default-base,kernel-source

multiversion.kernels defines package specific retention rules. In this case we defined three to retain:

  1. latest The kernel with the highest version number.
  2. latest-1 The kernel with the next highest version number. This is defined as latest-N where N is the Nth highest version number
  3. running The running kernel version.

If we have three kernels, I would expect to see three after the next update with the oldest of the three falling off the list. If we have two kernels installed, I would expect to see three after the update. If we have one, I would expect two.

The extra, double-cool thing is that the old kernel retain their kdump configurations so you can crash-dump any installed kernel.

Posted in How Tos, linux, OpenSUSE, SLES, zypper | Leave a comment