Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

2012-11-08

Bash Script debugging and SELinux


OpenVPN can launch a script client-connect each time a client connect to the VPN.
The script used to work when OpenVPN is launched directly, but not when launched via /etc/init.d/openvpn start ...

A good way to debug is to put this at the beginning of the file:
#!/bin/sh
"client-connect
exec > /tmp/debug.$$ 2>&1; set -x
...

Reading the /tmp/debug.pid will give a first hint: "Permission denied" when trying to launch "/bin/mail" in the script.

I put a ME=$(whoami) in the script but both (working and non-working) returned the same: nobody. So, it leaves only one suspect: SELinux. (I didn't though about SELinux because I didn't see it in the services. But it is there, in the Kernel.)

Quick info about SELinux:
  • sestatus to get information
  • setenforce Permissive will give only warning (it creates less problems than disabling it).
  • /usr/sbin/selinuxenabled && SEL="SELinux ON" to use in scripts.

To be really sure, I did the following:
# ls -Z /etc/init.d/openvpn gives: system_u:object_r:openvpn_initrc_exec_t:s0
# ls -Z myTest               gives: unconfined_u:object_r:openvpn_etc_t:s0

My test script runs "unconfined". If I copy the openvpn script into my folder while preserving the context cp -c ..., I change the content to be the same as my old working script and re-launch. It doesn't work anymore.
Conclusion: the file's context will confine openvpn so that the script it launches will fail to uses /bin/mail.


Solution 1 :
The "hard way" is to try to patch the policy to workaround your case:
$ grep client-connect /var/log/audit/audit.log | audit2allow -M openvpn_cc
This will create two files: a .pp to be run and a .te for your reading pleasure.
install the module: semodule -i openvpn_cc.pp

It goes a little further, but still fails and if you look at the policy in the .te file, it is quite complicated.
(I didn't repeat the process audit2allow ... to get further, but I guess that ultimately it would have worked.)


Solution 2:
Create a policy to send mail:

$ vi openvpn_cc.te
policy_module(openvpn_cc, 1.0)
 
require {
        type openvpn_t;
};
 
mta_send_mail(openvpn_t)

Compile: make -f /usr/share/selinux/devel/Makefile openvpn_cc.pp
Install: semodule -i openvpn_cc.pp

Simple and it works.


References:

2009-11-03

Podcatcher

I tried many podcatcher on Linux recently and it is a long journey:
  • gtkpod 0.99.14: just to synchronize iPod. Allow to copy playlist and so on. Old and rough but stable.
  • gPodder 2.0 : podcatcher, manage OPML. This new version is my favorite !
  • Floola 5.3.1 (proprietary) : hard to run, many dependencies. Buggy and cumbersome UI. No OPML. Good iPod integration.
  • BashPodder : command line and minimal GUI. No OPML. simple shell script. Create one folder per day.
  • SongBird 1.4 : Podcast doesn't seem to be on their roadmap. It is sad, because it would make a good web integration with show notes and forums.
  • Exaile 0.2.14 : No OPML. Almost good, but I couldn't synchronize. Uses a hashkey as file name: unreadable. Python/GTK. (There is a new 0.3 version that is a complete rewrite. I still have to check the new version)
  • PenguiTV 4.0 : buggy ; Closely tied to Gnome (Python/Glade). Does OPML. Create one folder per day.
  • PodNova 2.4 : Outdated. a bit hard to run, many dependencies. Python/wxWidgets and a local web server. The integration with the PodNova site is good, you can share, vote and backup your podcast list. But it lacks features and robustness.
  • Media Chest Java
  • myPod (2003) Java but uses ligpod from gtkPod
  • GNUpod Perl pure iPod manager.
  • Amarok more a music collection manager than a podcatcher, but could do the job.
  • As usual there are also many dead projects, not updated for years, but still referenced in a lot of places.

I created an open SpreadSheet for everyone to update : Linux Podcatcher.

There is an Podcatcher Matrix that would be very nice if not outdated and a bit closed !
There is also a Wikipedia entry on aggregators, but it doesn't distinguish between text feeds, Podcast and Video and is a bit outdated and cumbersome.

2009-09-07

Sound and iPod with Awesome Windows Manager

Just a short note about the great Awesome window manager.
There was no sound with some applications. There are 2 programs to know about sound control : alsamixer (command line) and pavucontrol (manage PulseAudio with a simple GTK interface).

For the iPod, I am using RockBox, gtkPod and gpodder. Nothing fancy, but it does the job quickly.

Just have to remember to manually mount the iPod, by adding this in /etc/fstab:
/dev/disk/by-label/IPOD /media/IPOD vfat defaults,umask=000,auto,rw,user 0 0

Also a simple trick to eject the iPod : eject /media/IPOD

2009-08-09

Getting rid of the DisplayManager, Choose your run level

The Display Manager (generally: GDM, KDM, or XDM, Slim ...) is there for historical reason, but it isn't useful unless you need special features.
Now the problem is that Ubuntu restricted the uses of Run Levels ! So you have to tweak the system a little bit if you want to start in text mode.
So lets read:
Add a text-only runlevel to Ubuntu Gutsy and
Boot time RunLevel
Then modify your /etc/event.d/rc-default:
#
# This task guesses what the "default runlevel" should be and starts the
# appropriate script.

start on stopped rcS

script
runlevel --reboot || true

if grep -q -w -- "-s\|single\|S" /proc/cmdline; then
telinit S
elif RL="$(grep -o "[[:blank:]][2345]$" /proc/cmdline || true)"; then
if [ -n "$RL" ]; then
telinit $RL
else
telinit 2
fi
elif [ -r /etc/inittab ]; then
RL="$(sed -n -e "/^id:[0-9]*:initdefault:/{s/^id://;s/:.*//;p}" /etc/inittab || true)"
if [ -n "$RL" ]; then
telinit $RL
else
telinit 2
fi
else
telinit 2
fi
end script


Then knowing that I use Grub 2, the following file has to be modified /etc/grub.d/10_linux (no more menu.lst). Just add the bold part:
...
cat << EOF
menuentry "${OS}, linux ${version}" {
linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro ${GRUB_CMDLINE_LINUX} ${GRUB_CMDLINE_LINUX_DEFAULT}
EOF
if test -n "${initrd}" ; then
cat << EOF
initrd ${rel_dirname}/${initrd}
EOF
fi
cat << EOF
}
EOF

cat << EOF
menuentry "${OS}, linux ${version} (text mode)" {
linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro 3 ${GRUB_CMDLINE_LINUX}
EOF
if test -n "${initrd}" ; then
cat << EOF
initrd ${rel_dirname}/${initrd}
EOF
fi
cat << EOF
}
EOF

cat << EOF
menuentry "${OS}, linux ${version} (single-user mode)" {
linux ${rel_dirname}/${basename} root=${linux_root_device_thisversion} ro single ${GRUB_CMDLINE_LINUX}
EOF
if test -n "${initrd}" ; then
cat << EOF
initrd ${rel_dirname}/${initrd}
EOF
fi
cat << EOF
}
EOF

...

That worked for me, but be careful as it can screw your system !
Now just log in and type: $ startx awesome

2009-07-30

Set up wireless without KDE nor Gnome

One of the first problem faced when going away from KDE, Gnome or XFCE is that you have to set up your wireless connection manually.
If you have 10 minutes, it can be done once and for all: just follow this how to HOWTO: Wireless Security - WPA1, WPA2, LEAP, etc..
Then you can remove the NetworkManager startup script : "sudo update-rc.d -f NetworkManager remove".
Keep in mind to launch a "sudo /etc/init.d/networking restart" in case of problem.

Update: I just found a solution to automatically start Network Monitor Applet (nm-applet) with Awesome Window Manager. But I am quite happy with my current setting, it just connect when it starts.

Java GUI application in Awesome Window Manager

There is a known problem with Java and the non-reparenting Window Managers like for example Awesome.
Java applications which use the XToolkit/XAWT backend may draw gray windows only. The XToolkit/XAWT backend breaks ICCCM-compliance in JDK 5 and 6 because it assumes a reparenting window manager.


There are a number of places where this is described:

To sum up:
  • it doesn't affect version Java 1.4.2 and before.

  • it doesn't affect version Java 1.7 and hopefully after.

  • the best workaround by far, is to set a name to the Window Manager, so it is recognise by Java as a non-reparenting Window Manager. A simple utility allow to set this name. Just add 'wmname LG3D' to your .xinitrc or simply run it.

  • Here are other workarounds left here for reference:

    • launch another X server, like Xephyr

    • set the following environment variable (to use the older Motif back-end instead): AWT_TOOLKIT=MToolkit. But this won't work in the following cases :
      • OpenJDK/IcedTea doesn't include the Motif toolkit.

      • doesn't work for x86_64 Java, for whatever reason.


Lightweight OS : Awesome Window Manager

Some year ago I used to try all kind of Window Managers on Linux and basically loosed a lot of time for nothing. I never though that I would fall back again, but having just 1Go RAM and running JetBrains MPS forced me to consider lighter alternatives than KDE.

First I tried XFCE, but it wasn't enough: too close to Gnome, too traditional. So I tried Fluxbox, didn't like the menu, RatPoison too simple and finally: Awesome. As usual, I found the Wikipedia list very useful.

And so far it is the best Window Manager I ever used.
- Fast, clean and simple, even their Web site is well designed.
- No more loosing time resizing the windows ! At about 98% I just need to have the applications full screen.
- But still it is easy to resize, typically popup window are often too small.
- No waisted screen space : no desktop.
- an unified way to close applications (no more Ctrl-Q, Ctrl-E, Ctrl-X ... one Mod4-Shift-c for all !)
- easy shortcuts
- search through the menu. It is not as good as Spotlight on a Mac or the KDE4 launcher, but I guess it can be configured.

It may sound enough, but there is more:
- highly and simply configurable with a scripting language: LUA. I already known LUA for being used in SciTE a very good code editor.
- it isn't a general purpose Window Manager, it targets my profile. It suits me: a bit cutting edge but not bleeding.

I always though that the "Desktop" was not a good abstraction, unless you have at least three 22' monitors. It becomes often a trash bin and is almost always covered with the application you are working with anyway. That is why I kind of like the KDE4 approach of a desktop that is more than a folder.

2009-07-07

Store Flac, broadcast MP3 : mp3fs and Ampache

Lets say that you keep your music with the best quality while still consuming very little disk space : flac (lossless audio compression).
Now that is fine for PC, but most portable players (iPods) doesn't support flac, but MP3, MP4 and other .
You could duplicate your whole collection in two formats, or transcode as needed, but that would be painful. (Even if some application like Amarok are able to transcode on the fly the music or podcast transfered on an iPod.)
A solution for me is to use mp3fs. Mp3fs takes a directory full of flac and present it as another directory full of ... MP3 ! That is very useful for FTP, NFS or Samba shares.
So your Flac music can now be copied on your ipods easily.

One caveat: unless you have a powerful PC, don't expect to listen directly the mp3: the transcoding take some time. It is fine to copy, but not to stream !

Lastly, I didn't find package for Kubuntu nor Fedora. You just have to compile, which is very simple. The only problem being to get the libraries !
There are some hints for Kubuntu. But for Fedora, the library's names are not exactly the same. After a little "yum search ...", I installed: libid3tag-devel, lame-devel, flac-devel, fuse-devel, libogg-devel.

But still, I don't see the point of having different packages, as if Linux needed to be fragmented !

Ampache is another project that can provide transcoding over the web and essentially much more, but see for yourself.

2009-02-27

My first JavaFX tutorial completed under Linux

I was eager to start using JavaFX, because Linux isn't yet fully supported as a development platform. So I used this tips on how to install Netbeans with JavaFX on Linux. And I have been able to follow this tutorial.
Nothing fancy, but I have a good feeling about JavaFX : the code is clean, powerful and very readable. Not cluttered with legacy stuff.
I hope I will be able to do more with it.

2009-01-22

Java on Linux, So Many Free Choices

Or should we say too many choices ?
This post is essentially to cleanup some bookmarks I tagged "To Read".
There is an article in Fedora Weekly Issue 133 about Java.
I like to have a clean Linux install and having Sun's Java, GCJ, IcedTea and others gives me a bad feeling.
Hopefully the road map toward OpenJDK is clear.

2008-10-03

Java browser plugin on 64 bit Fedora and more

It's been a long time. So just to say that :
- Fedora 10 should be there soon

- There is some hope for a good java plugin on 64-bits browsers. For now just install java-1.6.0-openjdk-plugin. Or better, just yum install java-1.6.0-openjdk-*

- being on a project with a lot of JMS, Tibco RendezVous, Complex Event Processing, Event Driven Architecture and the likes, It is the kind of paradigm change that bring some fun to the job ! So no more HTTP request nor function calls : just send events and hopefully someone else will write the code to react to them. We are so used to HTTP and the firewall censorship that we don't even consider JMS ! But there are plenty of cases where it makes perfect sense to use events and messages : a lot of them !

2008-07-01

Linux Podcast

#! CrunchBang has a nice Linux Podcasts Roundup
And there is a long uncommented list in Monterb.org !
Another commented list in Tux University. (By the way, LearnHub seems to be a nice place !)
Another one from LinuxLink with little comment and logos . Go to Google for the others.

But it will be hard to replace Lug Radio !!

2008-06-25

Storage : S3 vs. Hard Drive

I looked at Amazon S3 service, but it is still expensive, especially if you plan to just "store" files and not often touch them. For example keeping 500GB would cost $90 per month. Compare to a 500GB Hard Drive that cost less than 60€ ! You may count about $10 per month for electric power, depending on your region.

So I planned to use the Open Source Java client : JetS3t, but abandoned it altogether.

Then I have to check for solutions to replicate the files to friends machines. It wouldn't make sense to me to use RAID mirror. Mirror won't protect against thieves or fire !

2008-06-16

Fedora 9 and Java OpenJDK

I upgraded to Fedora 9 some days ago, it went very well. I used the preupgrade GUI tool.
I just have a little mess in the menu, but easily cleaned up.

I am a bit disappointed by OpenJDK Firefox plugin. Basically, it doesn't work, nor WebStart.
So I will switch to the Standard SUN Java back again. Especially as they fixed and enhanced the applets with Java SE 6 Update 10 b25 !

Resources :
  • JavaFAQ is a bit outdated (still cover a large part of FC6 !? )

  • I will have to check this : http://fedorasolved.org/browser-solutions/sun-jdk

  • Mauriat Miranda guides

  • http://dnmouse.webs.com/index.html Quick guides (feature autonine : a GUI that install non-free apps)

  • http://easylife.dulinux.com/ just another GUI that install non-free apps.

  • People hang out on #fedora-java on freenode. There are also people on #classpath

  • Fedora Java Mailing list



I would really like some kind of group about "Java on Fedora", like the Java topic on Debian Wiki

2008-06-10

I tried KDE 4 and I like it

Fedora 9 comes with KDE 4 and it is really great !
Still some details to be fixed but overall I like it much more than Gnome !

Festival de la Cooperative OASIS - 2026

 https://Cooperative-OASIS.org/ Abonnement la revue Passerelle Eco    Papier . Mais les annonces sont dispo:  Revue trimestrielle de l’ Ecov...