Smokes your problems, coughs fresh air.

Category: Technology (Page 18 of 47)

Create a remote repository and branch with bzr

Create a shared remote bzr repository:

bzr init-repo --no-trees sftp://development@server.example.com/srv/bzr/project/
bzr init sftp://development@server.example.com/srv/bzr/project/trunk
bzr co sftp://development@server.example.com/srv/bzr/project/trunk project 

The docs all create a repos in /srv/bzr in which branches are created, but to me, it seems illogical to put all your projects in one repository. So, I create one per project.

Ubuntu Desktop Linux and Acer TravelMate 7513WSMi

My youngest sister has retired her big-ass (17″) Acer TravelMate (model 7513WSMi 7510) with a more modern offering from Sony. That was last year. Now, she thought it’d be a good idea to donate it to our oldest sister. But since the thing has always “run” like a pig with Windows Vista, her girl-geek instincts thought it better if I’d equip the old monster with Ubuntu Linux instead.

AMD 64bit

I’m also considering upgrading my own laptop to 64 bit. (They’ve told me that, really, the 32 bit age is over.) So, the first thing I’m trying to find out (now that I’m getting on the 64 bit train) is if this thing supports 64 bit. I can’t really think of a quick way to find out, so I’m just going to create a 64bit installation CD and see how that works.

Or, I could have just popped open the hood to see the “AMD Turion64x2 Mobile Technology” sticker. 😯

Installation

After changing the boot order, the installation CD (burned from my T61 using “wodim -data ubuntu-10.10-desktop-amd64.iso”) seems to be booting despite the worrying sounds that seem to indicate that the laptop is trying to rip apart and eat the disc.

I’m surprised how good the current installation program looks and that it asks me if I want to “download updates while installing” and “install third-party software”. Nice.

Great idea to ask all the annoying questions (timezone, etc.) during installation instead of after! I’m amused with how much I’m behind the time if I see all the promotional screens for new and improved software which is meant to keep me inspired during the installation process. “OpenOffice.org is fully compatible with Microsoft Office[…]” Am I really that much behind with the times? Nah, I can’t imagine. I must still have some very, very nasty Excel sheet lying around somewhere, gathering dust. If I feed that monster of a thing to OpenOffice, then I’m pretty sure… Yeah, that’s going to be fun. 😈

Post-installation configuration

I had expected to spend at least an hour or two hunting around forums to find solutions for obscure driver-related issues and other nuisances. But no issues popped up. It just worked. Ubuntu is very compatible with the Acer TravelMate 7513WSMi! 😀

So, I spent some of the time saved on setting a user pic and a few other niceties, but I refrained from doing anything fancy, because I’ve figured out a new sister support strategy that I might blog about later. (It involves a four-hour work-week…)

[For my own reference, I started on the first draft of this post on Januari 14.]

Making a shell-script run with setuid root

If you want to run a process with root privileges that you can invoke as a less unprivileged user, you can make the program setuid root. This can be very useful, for example, when you want a PHP or CGI script to call a backup process, or to create a new site or irrevocably delete you whole system. The latter example points to a serious security problem: if anyone can figure out a way to make your program do something you don’t want, you’re screwed, because you just gave them root privileges to wreak maximum havoc. That’s why, normally, scripts (anything executed by an interpreter by the kernel because of a shebang) won’t get elevated privileges when you set their setuid bit.

To understand the setuid bit, let’s first see what happens when I try to cat a file that belongs to root:

su -
# I am now root; fear me
touch no-one-can-touch-me
chmod 600 no-one-can-touch-me
cat no-one-can-touch-me
# cat: Permission denied 

Next, I’ll create a shell script that cats the file:

#!/bin/bash
 
cat no-one-can-touch-me

And make the script setuid root:

su -
chown root:root script.sh
chmod +xs script.sh

If I now execute the script, I still get the permission denied. What I need to make this work is a wrapper program. For that, I refer to Wiebe’s post about the same subject. (Yeah, I know: why bother publishing this if Wiebe already did an excellent job explaining? Well, I just hate to throw away an otherwise fine draft.)

Executing system commands from PHP with SUID executable.

If you want to execute system commands from something like PHP, you need a SUID executable which you can call from your PHP scripts. This is such a script. It could be extended to support parameters for the commands you want to execute, but that would be an enormous security risk, because then anybody can execute any command. If you need something as flexible as that, you need to think about adding some kind of security restrictions, like a list of allowed commands.

When writing this, it occurred to me how unnecessary this all is. I will explain below. First, I will describe the old way.

Here is the c source code, as written for our backup script, bsbackup.sh:

// Wrapper for the bsbackup.sh shell script, to be able to run it as root when
// started from a webserver, for example. Set the resulting executable to SUID
// root.
 
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
#include <error.h>
 
int main(int argc, char *argv[], char *envp[])
{
    int set_uid_result;
    int effective_user_id;
    int execute_script_error;
    char* script;
 
    effective_user_id = geteuid();
 
    // Set real and effective user ID
    set_uid_result = setreuid(effective_user_id, effective_user_id);
 
    if (set_uid_result != 0)
    {
        printf("Failed to set user id\n");
        return 1;
    }
 
    script = "/usr/local/sbin/bsbackup.sh";
 
    // This does not return on success.
    execve(script, argv, envp);
    execute_script_error = errno;
 
    // Show a fancy error message.
    error(execute_script_error, execute_script_error, script);
 
    // Shouldn't be necceary, but you never know.
    return 1;
}

To compile:

gcc -o bsbackup bsbackup.c

You can then run this inside PHP:

// The 2>&1 makes all error messages appear on stdout, for easy capturing.
passthru('/usr/local/sbin/bsbackup usb_backup 2>&1');

As I said, when writing this, it all became very clear to me that it is quite useless. One can also install sudo, run visudo and put this in (assuming your webserver runs as www-data, like on (Debian and Ubuntu):

www-data ALL = NOPASSWD: /usr/local/sbin/bsbackup.sh

Then in PHP, just run this:

passthru('sudo /usr/local/sbin/bsbackup.sh usb_backup 2>&1');

I haven’t tested whether specifying the parameters after the script in the passthru actually works, but I think so. If not, you can just write a wrapper script around the command you’re going to execute.

See what you like best 🙂

Configuring a Power DNS superslave server

Power DNS, as opposed to Bind, has the option to be a superslave. This means that it will initiate any zone transfer from trusted hosts, avoiding the need to configure each zone on both master and slave.

Power DNS has separate back-ends, of which you must choose one. I chose mysql, and I use the generic mysql engine (this is different, and better, than normal MySQL, or something like that…).

First install Power DNS:

aptitute -P install pdns-server pdns-backend-mysql

Then create a database and user:

create database pdns character set utf8;
grant all on pdns.* to 'pdns'@'localhost' identified by 'password';

Then create this schema (found it in the Power DNS docs):

create table domains (
 id    INT auto_increment,
 name    VARCHAR(255) NOT NULL,
 master    VARCHAR(128) DEFAULT NULL,                                                                                                                    
 last_check  INT DEFAULT NULL,                                                                                                                           
 type    VARCHAR(6) NOT NULL,                                                                                                                            
 notified_serial INT DEFAULT NULL,                                                                                                                       
 account         VARCHAR(40) DEFAULT NULL,                                                                                                               
 primary key (id)                                                                                                                                        
)type=InnoDB;                                                                                                                                            
                                                                                                                                                         
CREATE UNIQUE INDEX name_index ON domains(name);                                                                                                         
                                                                                                                                                         
CREATE TABLE records (                                                                                                                                   
  id              INT auto_increment,                                                                                                                    
  domain_id       INT DEFAULT NULL,
  name            VARCHAR(255) DEFAULT NULL,
  type            VARCHAR(6) DEFAULT NULL,
  content         VARCHAR(255) DEFAULT NULL,
  ttl             INT DEFAULT NULL,
  prio            INT DEFAULT NULL,
  change_date     INT DEFAULT NULL,
  primary key(id),
  CONSTRAINT `records_ibfk_1` FOREIGN KEY (`domain_id`) REFERENCES `domains` (`id`) ON DELETE CASCADE
)type=InnoDB;
 
CREATE INDEX rec_name_index ON records(name);
CREATE INDEX nametype_index ON records(name,type);
CREATE INDEX domain_id ON records(domain_id);
 
create table supermasters (
  ip VARCHAR(25) NOT NULL, 
  nameserver VARCHAR(255) NOT NULL, 
  account VARCHAR(40) DEFAULT NULL
);
 
GRANT SELECT ON supermasters TO pdns;
GRANT ALL ON domains TO pdns;
GRANT ALL ON records TO pdns;

Then create /etc/powerdns/pdns.d/pdns-mysql-backend with this in it:

launch=gmysql
gmysql-host=127.0.0.1
gmysql-user=pdns
gmysql-password=password
gmysql-dbname=pdns

Then insert a supermaster:

insert into supermasters values ('1.2.3.4','ns1.example.com','identifiername');

Lastly, don’t forget to enable slave mode in /etc/powerdns/pdns.conf:

slave=yes

Remove appending slash from a path using Sed

Here’s how you can remove the appending slash from a path using sed, the stream editor:

/just/a/path/ | sed -e 's#/$##'
# Output: /just/a/path
 
# And, if there isn't an appending slash, nothing happens:
 /just/another/path | sed -e 's#/$##'
# Output: /just/another/path 

It works quite simple. Sed executes expression (-e) on its standard input. The expression is a substitution using regular expressions. The #-sign is the delimiter. The part (#/) between the first two hash signs is the matching expression and the (empty) part between the second and the third hash sign is the replacement expression. This expression (“s#/$##”) basically says: replace all occurrences of “/” at the end of the line (the dollar sign is the end-of-line anchor) with nothing.

To use this in a script is easy-peasy. Suppose $1 is a system path that may or may not include an appending slash:

#!/bin/bash
 
sanitized_path= "$1" | sed -e 's#/$##'`
 $sanitized_path

This script outputs its first parameter with the appending slash removed.

Roos Roos Loon installation and configuration weirdness

Because Roos Roos Loon has always been an application that stored its data files in the program files directory, special measures had to be taken to make sure the data files are backed up. I wanted them on a network drive. To that end, I always installed the entire program on a network drive.

But I just found out that Loon 2010 had put its data files somewhere in Documents and Settings, even though the program was stored on the network. I guess this was the first version that separated the data and program paths. However, it did so without telling me. The reason it didn’t tell me, might be because of a bug I found in 2011.

For 2010 I just changed a regkey in “currentuser\software\vb and vba\Roos Roos” or something. 2011 I was installing on another machine and I decided to reinstall it to have it nicely from scratch.

And that’s were it started to be weird. Where it asked me where to put the data files the first time I had installed it, it didn’t this time, even when I removed the aforementioned regkey on this computer. It didn’t even want to start after the reinstall anymore, until I pointed it to the 2011 data files I had deleted when removing the program. I would think it would recreate them, as they were empty anyway, but it didn’t.

I think Loon 2011 not asking for the datapath and Loon 2010 not doing it either, may be related. Perhaps if there already is Roos Roos stuff on the machine, it skips that question (being a bug).

Therefore, I suspect that when 2012 is released, it may put its datafiles in the datapath for 2011. I have to watch that.

Ubuntu and SiS 671 VGA chipset driver

The video on my mom’s laptop, A Fujitsu Siemens Esprimo Mobile V5535, had recently gone awry. At the time, the laptop was running Ubuntu 9.04 (I think). Reconfiguring the driver didn’t do much good, so I upgraded the machine to 10.04, hoping that that would fix it. It didn’t.

lspci|grep -i vga
01:00.0 VGA compatible controller: Silicon Integrated Systems [SiS] 771/671 PCIE VGA Display Adapter (rev 10)

I solved the problem by manually installing a replacement driver that I found through a blog post that I found through another blog post that I found through a forum post.

Or something like that. Who cares? The point is that I’m uploading the files I found here so that I don’t have to jump through MegaUpload hoops again (and sit through MedaAnnoying ads):

Installing the binary driver wasn’t too difficult. (I just always cringe when something happens outside of package management.) 🙁

mkdir sis; sis
wget http://blog.bigsmoke.us/uploads/2011/01/xorg-driver-sis671-0.9.1-fixed-build.zip
unzip *zip
sudo cp sis671_drv.* /usr/lib/xorg/modules/drivers
 
#Edit /etc/X11/xorg.conf and set `Driver   "sis671"` on the "Device" Section
[ -z $EDITOR ] && EDITOR=/usr/bin/vim
$EDITOR /etc/x11/xorg.conf

Restarting the X server after that was a bit difficult, since the upgrade to 10.04 also fucked up the console (that damn framebuffer) and because Ctrl-Alt-Backspace is disabled by default. I had to reboot. (Ok, I hate to admit: it’s not that it’s difficult, it’s just wrong.)

Anyway, after the system restart, it worked just fine again. The X log agrees:

(II) SIS: driver for SiS chipsets: SIS5597/5598, SIS530/620,
        SIS6326/AGP/DVD, SIS300/305, SIS630/730, SIS540, SIS315, SIS315H,
        SIS315PRO/E, SIS550, SIS650/M650/651/740, SIS330(Xabre),
        SIS[M]661[F|M]X/[M]741[GX]/[M]760[GX]/[M]761[GX]/662, SIS340,
        [M]670/[M]770[GX], [M]671/[M]771[GX]
(II) SIS: driver for XGI chipsets: Volari Z7 (XG20),
        Volari V3XT/V5/V8/Duo (XG40/XG42)
(II) Primary Device is: PCI 01@00:00:0
(WW) Falling back to old probe method for sis671
(--) Assigning device section with no busID to primary device
(--) Chipset [M]671/[M]771[GX] found
(II) SIS(0): SiS driver (2006/10/17-1, compiled for X.org 1.7.4.0)
(II) SIS(0): Copyright (C) 2001-2005 Thomas Winischhofer  and others
(II) SIS(0): *** See http://www.winischhofer.at/linuxsisvga.shtml
(II) SIS(0): *** for documentation, updates and a Premium Version.
(II) SIS(0): RandR rotation support not available in this version.
(II) SIS(0): Dynamic modelist support not available in this version.
(II) SIS(0): Screen growing support not available in this version.
(II) SIS(0): Advanced Xv video blitter not available in this version.
(II) SIS(0): Advanced MergedFB support not available in this version.
(--) SIS(0): sisfb not found
(--) SIS(0): Relocated I/O registers at 0x9000

Then, to also fix the console:

grep vga16fb /etc/modprobe.d/* || sudo sh -c "echo blacklist vga16fb >> /etc/modprobe.d/blacklist-framebuffer.conf"
 
sudo update-initramfs -u
 
sudo reboot
 
# pray 

I had two other issues that popped up after the upgrade the 10.04. I was inclined to blame the first on the new video driver, but I solved it by disabling “Hardware Acceleration” in the Flash plugin preferences. [source]

Another problem that confused my mother was that the volume control icon had gone. [solution]

How to make a wiki work: PALDAP

The first ever wiki I started was www.paldap.org. PALDAP stands for “PALDAP: A Lazy Directory Administrator’s Pal”. Yes, that’s a recursive acronym. Cute, ainnit? I actually registered the domain because it was the name of a crappy abandonware PHP LDAP administration tool that I wrote in PHP, but decided instead to configure it as a wiki to host some of my assorted experiences with LDAP and OpenLDAP in particular.

I never much bother with LDAP anymore, but the wiki remains because cool URLs don’t change and it doesn’t cost me that much. AdSense income for the wiki is only marginal (€15 in over three years) because the wiki’s content is only marginally useful and the traffic (300 visitors/month) reflects that fact.

[…]

Six days passed since I wrote the last paragraph. It’s a funny thing how writing can mess with your head. I was going to use PALDAP as in introduction to my struggle to make money of my wikis in general. Because the most promising of these wikis are my Hardwood Wikis and not my LDAP wiki, I wasn’t going to linger too much on it. But it’s a week later and some unexpected things happened.

Often, since becoming more familiar with Semantic MediaWiki, I’ve been considering the idea of converting the DokuWiki installation that runs www.paldap.org to a Semantic MediaWiki installation. Yet, nothing ever happened. I no longer work with LDAP professionally and most of the time I just kind of forgot that the site even existed. Until a week ago, when I started writing this post.

So, what happened? How do decisions happen? I have no idea. I’m not a neurologist. (I’m not even a sceintist; Hell, I can’t even spell “scientist”.)

What I have now are rationalizations for my decision but my decision is quite clear: I can’t kill my darling, even though I never really properly cared for it. For the last four years or so I had simply abandoned it on the grounds that it wasn’t costing me much anyway (it’s hosted at NearlyFreeSpeech.Net). Yes, the costs have gone up, but that’s just a rationalization. I could have just gone on and ignore the site’s existence without it ever making much of an impact on my cash flow. (I did some years ago actually promise the site’s most active contributer to never take the site off-line.)

So, if I was being rational, I would have just left the site alone. But, I’m not a rational being. Increasingly less so, in fact. A happy fact, if you ask me.

PALDAP logo

The PALDAP logo designed by Jeroen Dekker

The looks

Anyway, I still haven’t told you what happened last week. I didn’t leave the site alone. I created a development version of the site based on Semantic MediaWiki. It’s fucking kick-ass. It looks awesome thanks to MediaWiki’s new vector skin. But it looks even more awesome thanks to Jeroen Dekker. As we often do, we were hanging out at his place in a lazy haze, being generally unproductive but with random bursts of intelligent conversation and productivity. This day I had been absent-mindedly hacking away on my new MediaWiki darling and I was about to leave and jump on my bicycle when I mentioned that I could use a logo for PALDAP.

It was probably way past one in the morning already, but Jeroen was still in a creative mood from play-practicing with his new lighting set. All I can say about his creativity is that it was late, I hadn’t slept very long the night before (and the night before that and the night before and…) Let’s just say that he besides his excellent gear he didn’t have some very good material to work with. I was feeling ugly and tired. Yet…

Rowan, Januari 7, 2010

Jeroen's creative genius is a compliment to my awesome facial features 🙂

He went into a kind of frenzy on his big-ass touch-screen and being coaxed by me he created the perfect offset for the boring technical subject that is LDAP.

The brains

In the meantime, since last weekend, I’ve been starting to assemble a logical structure of semantic properties (think of LDAP attributes or SQL fields) and templates (sort of like MediaWiki functions) that’ll allow me to capture all the semantics related to the LDAP and the ecology around it.

The booty

I still don’t believe that PALDAP has a huge revenue potential, but hosting costs have increased and if I can get the website to awaken from its winter sleep, maybe it’ll at least start paying for itself again. Not that I really care, honestly. Somehow it’s just masturbatorily satisfying to use the expressiveness of RDF to capture the semantics of LDAP. What I like about it is that the wiki concept (and especially the semantic wiki concept) is a very tight fit for technical documentation. Another thing that I like about working with a wiki about a technical subject is that the wiki has a technical audience. I mean, there’s a reason that the visitors of my Hardwood Investment Wikis click on all those expensive links and that reason is not the technical insight that’ll lead to users clicking the edit button and actually contributing content.

In fact, even with the old DokuWiki version of the site, much of the content was actually created by other users (most by the same user called brontolo). If the community of my Hardwood Wikis worked this well… Let’s just say that I could remain in retirement for a while then.

So, even if this’ll just be an exercise in effective community building/plumbing rather than a way to make advertising income easily, it’ll still be effective as an exercise. I’m going to follow my intuition on this one and see how successful it’ll become and how much time it’ll take.

Fuck, this post sucks, but it sure does help me. Don’t ask me how, but it does. Kinda.

Finding junction files in Windows 7 and exclude them with DeltaCopy

Windows 7 has a sort of hard link, a junction file, which it uses to link the old location “Documents and Settings” to /Users/. Because of all this junctioning, you can’t just copy files with a Cygwin program like Deltacopy, because it will hang in infinite loop and copy a whole lot of things twice.

To identify junction files, run:

dir /AL /s

Here is an example exclude list for deltacopy for a standard windows 7 machine. Path names are specified assuming every user dir is supplied as separate dir to copy (because there are references to root, like ‘/Mijn documenten’:

--delete-excluded --exclude "/Application Data" --exclude "**/Downloads" --exclude "**/AppData/Local/Application Data" --exclude "/Local Settings" --exclude "**/Temporary Internet Files" --exclude "**/Flash Player" --exclude "**/Temp" --exclude "**/VirtualStore" --exclude "NTUSER.DAT*" --exclude "UsrClass.dat*" --exclude "ntuser.dat*" --exclude "parent.lock" --exclude "/Mijn documenten"  --exclude "/Mijn afbeeldingen" --exclude "/Mijn muziek" --exclude "/Mijn video's"

The ‘Mijn Documenten’ and such is a link to other dirs, so it doesn’t skip them. Be sure not to use these statements when running this on Windows XP…

« Older posts Newer posts »

© 2024 BigSmoke

Theme by Anders NorenUp ↑