Monthly Archives: September 2008

Stock FTP with chroot (FreeBSD 7.0)

I was having really weird problems trying to set up a user that would be properly chrooted. Here are some traps/pitfalls.

1) The stock ftpd is not native! It’s merged in from NetBSD (I think). If you look for /usr/share/examples/ftpd/ftpd.conf, you won’t find it.

2) Make sure /home can be executed by anyone. I had everything (“rwx”) disabled for “others”, so that users can’t see who else exists on the system. Well, I had to put the “x” permission back on (in my case, “r” suffices).

3) There might be confusion on what the /etc/ftpXXX files actually do. man ftpchroot says:

The ftpusers file provides user access control for ftpd(8) by defining which users may login.

But if you read further, the file actually defines which users may not login.

Funny thing is, it also says the ftpchroot has the same format; but putting

retard yes

in it caused user retard not to be able to be chrooted upon entering the password. Putting a simple

retard

did the trick.

Advertisements

MLDonkey can’t compile: Tcl/Tk missing

Installing from packages:

ml_togl.c:12:17: error: tcl.h: No such file or directory
ml_togl.c:13:16: error: tk.h: No such file or directory

This happens because some dependencies aren’t in the requirements list:

portinstall tclX tcllib tk

The first two will handle the tcl.h dependency. The second will do tk.h. You should probably make sure tk is the same version as tcl.

Xorg: multiple languages (layouts)

In /etc/X11/xorg.conf:

Section "InputDevice"
Identifier "Keyboard0"
Driver "kbd"
Option "XKbLayout" "us,ru,lt"
Option "XKbOptions" "grp:alt_shift_toggle"
EndSection

Note it’s “us”, not “en”!

A PHP script to resize all images in a directory

This is a crude hack to resize images in a directory. The script is invoked as:

shrink <new_x> <new_y> <file> <file> <file> ...

You’ll need PHP with the GD library. That’s php5-gd on FreeBSD.


#!/usr/local/bin/php
# The output is JPEG, quality 88.

<?php



// Fuction to resize images, originally by D. Weimer.
// Code reformatting done, and '>' changed to '<'.
// http://www.dweimer.net/?page=help&subpage=imageresize
function resize($img,$nx,$ny)
{
    // $x and $y: original image's sizes.
    $x = imagesx($img);
    $y = imagesy($img);

    // Here, $nx and $ny are the minimal desired dimensions.
    if ( ($x/$nx) < ($y/$ny) )
    {
        $ny = round( $y * ($nx/$x) );
    }
    else
    {
        $nx = round( $x * ($ny/$y) );
    }

    $nimg = imagecreatetruecolor($nx,$ny);
    imagecopyresampled($nimg,$img,0,0,0,0,$nx,$ny,$x,$y);
    imagedestroy($img);
    return($nimg);
}



$arguments = $_SERVER['argv'];          // What the user wants to process.
array_shift($arguments);                // 1st element is the path to the script itself.
$newx = array_shift($arguments);        // 2nd is the new desired x dimension.
$newy = array_shift($arguments);        // 3rd is new y.
                                        // all the remaining args are images.

foreach ( $arguments as $arg )          // Go over user's shown items (single or "heaps").
{
    foreach (glob("$arg") as $filename) // Go over every file in a "heap".
    {
        $image = file_get_contents($filename);
        $image = imagecreatefromstring($image);

        $image = resize($image, $newx, $newy);

        imagejpeg( $image, $filename, 88 ); // WARNING!!! Writes JPEG by default!
    }
}


?>

I was too lazy to go searching for something pre-made.

Octave – open-source alternative to MatLAB

There are some links on osalt.com, and Octave even boasts language compatibility.

Will try it out and see how it works. I wonder most whether it has something like MatLAB’s toolboxes.

EDIT: Ah, yes, there are:

…the toolboxes that exist are donated by those interested in them…

(From the FAQ.)

Simple SSH account blocking, FreeBSD

Read the man page! There you’ll find that it’s performed in /etc/ssh/sshd_config by a troup of four directives:

DenyUsers
AllowUsers
DenyGroups
AllowGroups

In that order.

Say you’ve got group users with users jack, off, and jill, and group assholes with jack and jill.

If you want only jill to be able to login, you could specify:

AllowUsers jill

or

AllowUsers jill
AllowGroups assholes

and both of these wouldn’t allow (sic!) jack in!

If you wanted all the users of group assholes to be authorized, you’d put:

AllowUsers *
AllowGroups assholes

in the file. With only the second line, you’d lock everybody out (like I just did with my remote machine… oops!).

After you’re done, restart the server with

sudo /etc/rc.d/sshd restart

/usr/local/src for user’s sources

I use it so that users can store sources out of their home directory. Don’t know how secure it is, considering users’ tendency to leave everything world-writable – it isn’t. Anyway:

cd /usr/local
sudo mkdir src
sudo chown -R root:users src
sudo chmod -R o-rwx src
sudo chmod -R g+w src

urxvt (rxvt-unicode): port installation defaults

cd /usr/ports/x11/rxvt-unicode
sudo make -DWITHOUT_PERL -DWITHOUT_XIM -DWITHOUT_UNICODE3 -DWITHOUT_MENUBAR \
-DWITHOUT_RXVT_SCROLLBAR -DWITHOUT_NEXT_SCROLLBAR -DWITHOUT_XTERM_SCROLLBAR \
-DWITHOUT_PLAIN_SCROLLBAR -DWITH_HALF_SHADOW \
-DWITHOUT_LINESPACE -DWITHOUT_TERMINFO -DWITHOUT_AFTERIMAGE
sudo make install -DWITHOUT_PERL -DWITHOUT_XIM -DWITHOUT_UNICODE3 -DWITHOUT_MENUBAR \
-DWITHOUT_RXVT_SCROLLBAR -DWITHOUT_NEXT_SCROLLBAR -DWITHOUT_XTERM_SCROLLBAR \
-DWITHOUT_PLAIN_SCROLLBAR -DWITH_HALF_SHADOW \
-DWITHOUT_LINESPACE -DWITHOUT_TERMINFO -DWITHOUT_AFTERIMAGE

vim: port installation defaults

Not to forget:

cd /usr/ports/editors/vim
sudo make -D WITHOUT_X11
sudo make install -D WITHOUT_X11

Otherwise, it installs GTK 1.2.

Making a movie from image files using ffmpeg

There’s quite a lot of tutorials on the net, search for the title.

I had an issue, though: the images were taken with a web camera, and some of the images were garbled (wrong header, bad data, etc.). So ffmpeg choked on those silently, and the movie got cut off in the middle.

To find those, use something like

file * | grep

Also, to rename the images from the camera:

#!/bin/sh
#

n=1

for i in 122*; do
    echo $n
    cp $i processed/$n.jpg
    n=`expr $n + 1`
done