#!/usr/bin/ruby =begin Purpose: provide easy way to mangle auth parameters (un/pw) Purpose/HL: painless migration from sendmail to vpopmail Author: Michal Safranek License: GPL v.2 Date: 20050715140500 Usage: printf "%s\0%s\0%s\0" wejnik kocicka Y123456 | \ ./chkpasswd-mangle ./aliases.yaml /var/vpopmail/bin/vchkpw id # aliases.yaml has "username: substitute\n" format (YAML's hash) Requirements: Ruby/1.8.2 ( http://ruby-lang.org/ ) =end require 'yaml' if ARGV.size < 2 # contract breached, throw temp error # we need: config program(s) Kernel.exit(111) end aliases = nil aliases_file = ARGV.shift run = ARGV begin aliases = YAML.load_file(aliases_file) raise "bad config" unless aliases.respond_to?(:[]) rescue # bad config :( Kernel.exit(111) end begin input = IO.for_fd(3, 'r').read.split("\x0", -1) # Any mangling you can imagine can take place here. input[0] = aliases[input[0]] unless aliases[input[0]].nil? # ok, let's proxy it rd, wr = IO.pipe unless fork # child rd.close wr.write(input.join("\x0")) wr.close else # parent wr.close io = IO.for_fd(3, 'r').reopen(rd) exec(*run) end rescue # Exception, thus throw temp error Kernel.exit(111) end