Commit f8c102f6 authored by Mattia Dongili's avatar Mattia Dongili

Import upstream sources v20070815

Signed-off-by: default avatarMattia Dongili <malattia@linux.it>
parents
tunctl-setgroup
/* Copyright 2002 Jeff Dike
* Licensed under the GPL
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <pwd.h>
#include <net/if.h>
#include <sys/ioctl.h>
#include <linux/if_tun.h>
static void Usage(char *name)
{
fprintf(stderr, "Create: %s [-b] [-u owner] [-t device-name] "
"[-f tun-clone-device]\n", name);
fprintf(stderr, "Delete: %s -d device-name [-f tun-clone-device]\n\n",
name);
fprintf(stderr, "The default tun clone device is /dev/net/tun - some systems"
" use\n/dev/misc/net/tun instead\n\n");
fprintf(stderr, "-b will result in brief output (just the device name)\n");
exit(1);
}
int main(int argc, char **argv)
{
struct ifreq ifr;
struct passwd *pw;
long owner = geteuid();
int tap_fd, opt, delete = 0, brief = 0;
char *tun = "", *file = "/dev/net/tun", *name = argv[0], *end;
while((opt = getopt(argc, argv, "bd:f:t:u:")) > 0){
switch(opt) {
case 'b':
brief = 1;
break;
case 'd':
delete = 1;
tun = optarg;
break;
case 'f':
file = optarg;
break;
case 'u':
pw = getpwnam(optarg);
if(pw != NULL){
owner = pw->pw_uid;
break;
}
owner = strtol(optarg, &end, 0);
if(*end != '\0'){
fprintf(stderr, "'%s' is neither a username nor a numeric uid.\n",
optarg);
Usage(name);
}
break;
case 't':
tun = optarg;
break;
case 'h':
default:
Usage(name);
}
}
argv += optind;
argc -= optind;
if(argc > 0)
Usage(name);
if((tap_fd = open(file, O_RDWR)) < 0){
fprintf(stderr, "Failed to open '%s' : ", file);
perror("");
exit(1);
}
memset(&ifr, 0, sizeof(ifr));
ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
strncpy(ifr.ifr_name, tun, sizeof(ifr.ifr_name) - 1);
if(ioctl(tap_fd, TUNSETIFF, (void *) &ifr) < 0){
perror("TUNSETIFF");
exit(1);
}
if(delete){
if(ioctl(tap_fd, TUNSETPERSIST, 0) < 0){
perror("TUNSETPERSIST");
exit(1);
}
printf("Set '%s' nonpersistent\n", ifr.ifr_name);
}
else {
if(ioctl(tap_fd, TUNSETPERSIST, 1) < 0){
perror("TUNSETPERSIST");
exit(1);
}
if(ioctl(tap_fd, TUNSETOWNER, owner) < 0){
perror("TUNSETPERSIST");
exit(1);
}
if(brief)
printf("%s\n", ifr.ifr_name);
else printf("Set '%s' persistent and owned by uid %ld\n", ifr.ifr_name,
owner);
}
return(0);
}
This diff is collapsed.
/COPYING/1.1/Tue Oct 9 02:22:36 2001//
D/gdbbot////
D/mconsole////
D/moo////
D/net////
D/redhat////
D/rpm////
D/test////
D/transformiix////
D/uml_net////
D/uml_router////
D/umn////
D/port-helper////
D/jailtest////
D/tunctl////
D/umlgdb////
D/watchdog////
D/jail////
D/honeypot////
/Makefile/1.13/Sat Feb 8 04:01:52 2003//
/uml_util.spec.in/1.4/Wed Jan 14 09:56:31 2004//
jdike@cvs.user-mode-linux.sourceforge.net:/cvsroot/user-mode-linux
BB -
shebangs added where needed
fixed the command line handling in honeypot.pl
the jail Makefile installs things now
jail_uml handles user names as well as uids and sets its group
CFLAGS is now settable at the top level
cleanups in uml_mconsole
64-bit fixes, fixing of broken 64-bit COW files, and other
cleanups in uml_moo
bug fix in uml_net's handling of a SLIP interface going down
moved the uml_router directory to uml_switch
cleanups in uml_switch
added a spec file
Me -
BB's tarball contained a tools-$DATE with a tools subdirectory - the
subdirectory had newer stuff, so I started with that.
Cleaned up the honeypot.pl changes
Spurious tab in jail/Makefile
Ignored BB's redeclaration of jailtest main - I prefer correct
declarations even when the arguments aren't used.
Removed uml_util.spec, which is generated
Added a lib directory which contains send_fd()
Added umlfs and umlfs support to uml_mconsole
From dgraves - mconsole int
TUNCTL = $(shell [ -e /usr/include/linux/if_tun.h ] && echo tunctl)
SUBDIRS = lib jail jailtest humfsify mconsole moo port-helper $(TUNCTL) \
uml_net uml_switch watchdog umlfs
UMLVER = $(shell date +%Y%m%d)
TARBALL = uml_utilities_$(UMLVER).tar.bz2
BIN_DIR = /usr/bin
ifeq ($(shell uname -m),x86_64)
LIB_DIR = /usr/lib64/uml
else
LIB_DIR = /usr/lib/uml
endif
CFLAGS = -g -Wall
#CFLAGS = -g -O2 -Wall
export BIN_DIR LIB_DIR CFLAGS
all install:
set -e ; for dir in $(SUBDIRS); do $(MAKE) -C $$dir $@; done
tarball : clean spec
cd .. ; \
mv tools tools-$(UMLVER); \
tar cjf $(TARBALL) tools-$(UMLVER); \
mv tools-$(UMLVER) tools
clean:
rm -rf *~
rm -f uml_util.spec
set -e ; for dir in $(SUBDIRS); do $(MAKE) -C $$dir $@; done
spec:
sed -e 's/__UMLVER__/$(UMLVER)/' < uml_util.spec.in > uml_util.spec
#Give this a task like
#uml-task-info current_task
#it will dump info about it
define uml-task-info
set $tstate = "Unknown"
if $arg0->state == 0
set $tstate = "R"
end
if $arg0->state == 1
set $tstate = "S"
end
if $arg0->state == 2
set $tstate = "D"
end
if $arg0->state == 4
set $tstate = "Z"
end
if $arg0->state == 8
set $tstate = "T"
end
printf "PID(ext): %d(%d)\tState: %s UID(E): %d(%d) \tCmd: %10s @ 0x%x\n", $arg0->pid, $arg0->thread.extern_pid, $tstate, \
$arg0->uid, $arg0->euid, $arg0->comm, $arg0
end
#dump out the info for the files the task has open
define uml-task-files
set $files = $arg0->files
set $max = $files->max_fds
set $i = 0
if $max > 32
set $max = 32
end
while $i < $max
if $files->fd_array[$i] != 0
printf " File fd = %d Name: %s\n", $i, $files->fd_array[$i]->f_dentry.d_iname
end
set $i = $i + 1
end
end
#walk though the task list and print info about them
define uml-tasks
set $current_task = (struct task_struct *)cpu_tasks[0].task
uml-task-info $current_task
set $p = $current_task.next_task
while $p != $current_task
uml-task-info $p
if $uml_task > 1
uml-task-files $p
end
set $p = $p->next_task
end
end
#Vars depend on how much info we dump
#$uml_task = (* ) always dump some info
#$uml_task = (> 0) dump open files
set $uml_task = 0
/gdbbot.pl/1.3/Thu Jul 5 19:18:58 2001//
D
jdike@cvs.user-mode-linux.sourceforge.net:/cvsroot/user-mode-linux
use IO::Pty;
use IPC::Open2;
use Net::IRC;
use POSIX;
use Fcntl;
use strict;
my $irc = new Net::IRC;
my $pty = new IO::Pty;
my $pid;
my $key;
my %trust = ();
my $conn = $irc->newconn(Server => 'irc.openprojects.net',
Port => 6667,
Nick => 'gdbbot',
Ircname => 'Vlad the Debugger',
Username => 'gdb')
or die "gdbbot: Can't connect to IRC server.\n";
sub start_gdb {
my $cmd = shift;
$pid = fork();
!defined($pid) and die "Couldn't fork : $!";
if($pid == 0){
POSIX::setsid() || warn "Couldn't perform setsid $!\n";
my $tty = $pty->slave();
my $name = $tty->ttyname();
# close($pty);
close STDIN; close STDOUT; close STDERR;
open(STDIN,"<&". $tty->fileno()) ||
die "Couldn't reopen ". $name ." for reading, $!";
open(STDOUT,">&". $tty->fileno()) ||
die "Couldn't reopen ". $name ." for writing, $!";
open(STDERR,">&". fileno(STDOUT)) ||
die "Couldn't redirect STDERR, $!";
exec ($cmd);
die "Couldn't exec : $!";
}
else {
fcntl($pty, Fcntl::F_SETFL, Fcntl::O_NONBLOCK);
print "gdb pid is $pid\n";
return $pty;
}
}
sub on_connect {
my $self = shift;
print "Joining \#umldebug...\n";
$self->join("#umldebug");
$key = rand(1<<31);
print "Your secret is $key\n";
my $cmd = "gdb linux";
my $pty = start_gdb($cmd);
$irc->addfh($pty->fileno(), \&gdb_output, "rw");
}
sub on_public {
my ($self, $event) = @_;
my @to = $event->to;
my ($nick, $mynick) = ($event->nick, $self->nick);
my ($arg) = ($event->args);
$arg !~ /^gdbbot/ and return;
$arg =~ s/^gdbbot:\s*//;
if($arg =~ /\^C/){
kill 2, $pid;
}
elsif(defined($key) && ($arg eq $key)){
$self->me("#umldebug", "trusts $nick");
$trust{$nick} = 1;
$key = undef;
}
elsif($trust{$nick} == 1){
if($arg =~ /trust (.*)/){
$trust{$1} = 1;
$self->me("#umldebug", "trusts $1");
}
else {
print $pty "$arg\n";
}
}
else {
$self->me("#umldebug", "doesn't trust $nick");
}
}
sub gdb_output {
while(<$pty>){
$conn->privmsg("#umldebug", "$_");
}
}
sub on_msg {
my ($self, $event) = @_;
my $nick = $event->nick;
$self->privmsg($nick, "Sorry, I don't understand messages yet.");
}
$conn->add_global_handler(376, \&on_connect);
$conn->add_handler('msg', \&on_msg);
$conn->add_handler('public', \&on_public);
$irc->start;
jdike@cvs.user-mode-linux.sourceforge.net:/cvsroot/user-mode-linux
D/CVS////
/hppfs.pm/1.3/Wed Jan 22 20:40:26 2003//
/honeypot.pl/1.6/Thu Jul 31 18:10:52 2003//
/hppfslib.pm/1.4/Thu Jul 31 18:12:39 2003//
jdike@cvs.user-mode-linux.sourceforge.net:/cvsroot/user-mode-linux
#!/usr/bin/perl
#
# Copyright (C) 2002, 2003 Jeff Dike (jdike@karaya.com)
# Licensed under the GPL
#
use hppfs;
use hppfslib;
use strict;
my $dir;
@ARGV and $dir = $ARGV[0] or die "Not enough arguments - pass dir where UML will be running";
# !mkdir $dir and warn "Couldn't create '$dir' : $!";
!mkdir "$dir/proc" and warn "Couldn't create '$dir/proc' : $!";
my $hppfs = hppfs->new($dir);
my $remove_filesystems = remove_lines("hppfs", "hostfs");
# Need to be able to add directories, i.e. driver, bus/pci
# partitions needs work
# slabinfo if UML ever uses the slab cache for anything
$hppfs->add("cmdline" => host_proc("cmdline"),
"cpuinfo" => host_proc("cpuinfo"),
"dma" => host_proc("dma"),
"devices" => remove_lines("ubd"),
"exitcode" => "remove",
"filesystems" => $remove_filesystems,
"interrupts" => host_proc("interrupts"),
"iomem" => host_proc("iomem"),
"ioports" => host_proc("ioports"),
"mounts" => $remove_filesystems,
"pid/mounts" => $remove_filesystems,
"stat" => host_proc("stat"),
"uptime" => host_proc("uptime"),
"version" => host_proc("version"),
dup_proc_dir("bus", $dir) );
$hppfs->handler();
#
# Copyright (C) 2002 Jeff Dike (jdike@karaya.com)
# Licensed under the GPL
#
package hppfs;
use Socket;
use IO::Select;
use strict;
sub new {
my $class = shift;
my $base = shift;
!defined($base) and $base = ".";
my $me = { files => { }, handles => { }, base => $base };
bless($me, $class);
return($me);
}
sub add {
my $me = shift;
while(@_){
my $file = shift;
my $handler = shift;
$me->{files}->{$file} = $handler;
}
}
sub prepare {
my $me = shift;
my $dir = shift;
my $file = shift;
my $full = $me->{base} . "/proc/$dir";
if(! -d $full){
unlink $full;
my $out = `mkdir -p $full 2>&1`;
$? and die "mkdir '$full' failed : $out";
}
my $out = `chmod 755 $full 2>&1`;
$? and die "chmod 755 $full failed : $out";
defined($file) and unlink "$full/$file";
return("$full/$file");
}
sub setup_sock {
my ($me, $file, undef, $mode) = @_;
my $full = $me->prepare($file, $mode);
my $sock = sockaddr_un($full);
!defined($sock) and die "sockaddr_un of '$sock' failed : $!";
!defined(socket(my $fh, AF_UNIX, SOCK_STREAM, 0)) and
die "socket failed : $!";
!defined(bind($fh, $sock)) and die "bind failed : $!";
my $out = `chmod 777 $full 2>&1`;
$? ne 0 and die "'chmod 777 $full' failed : $!";
!defined(listen($fh, 5)) and die "listen failed : $!";
$me->{select}->add(\*$fh);
$me->{handles}->{fileno(\*$fh)} = $file;
}
sub setup_remove {
my ($me, $file) = @_;
my $full = $me->prepare($file);
my $out = `touch $full/remove 2>&1`;
$? != 0 and die "touch $full/remove failed : $out";
}
sub handler {
my $me = shift;
$me->{select} = IO::Select->new();
foreach my $file (keys(%{$me->{files}})){
my $handler = $me->{files}->{$file};
if(ref($handler) eq "ARRAY"){
$me->setup_sock($file, @$handler);
}
elsif($handler eq "remove"){
$me->setup_remove($file);
}
else {
die "Bad handler for '$file'";
}
}
while(1){
my @ready = $me->{select}->can_read();
foreach my $sock (@ready){
my $file = $me->{handles}->{fileno($sock)};
!defined($file) and die "Couldn't map from socket to file";
!accept(CONN, $sock) and die "accept failed : $!";
my ($handler, $mode) = @{$me->{files}->{$file}};
(!defined($handler) || !defined($mode)) and
die "Couldn't map from file to handler";
my $output;
if($mode eq "rw"){
my $input = join("", <CONN>);
$output = $handler->($input);
}
else {
$output = $handler->();
}
print CONN $output;
close CONN;
}
}
}
1;
#
# Copyright (C) 2002, 2003 Jeff Dike (jdike@karaya.com)
# Licensed under the GPL
#
package hppfslib;
use Exporter ();
use vars qw(@ISA @EXPORT);
use strict;
@ISA = qw(Exporter);
@EXPORT = qw(&remove_lines &host &host_proc &dup_proc_dir);
sub remove_lines {
my @remove = @_;
return( [ sub { my $input = shift;
foreach my $str (@remove){
$input =~ s/^.*$str.*\n//mg;
}
return($input) },
"rw" ] );
}
sub host {
my $file = shift;
return( [ sub { return(`cat $file`); },
"r" ] );
}
sub host_proc {
my $file = shift;
return(host("/proc/$file"));
}
sub dup_proc_dir {
my $to = shift;
my $root = shift;
my $new = "$root/proc/$to";
-e $new and `rm -rf $new`;
!mkdir $new and warn "Couldn't create '$new' : $!";
my @dirs = `cd /proc/$to ; find . -type d -print`;
chomp @dirs;
foreach my $dir (@dirs){
$dir eq "." and next;
my $new_dir = "$new/$dir";
!mkdir $new_dir and warn "Couldn't create '$new_dir' : $!";
}
my @files = `cd /proc ; find $to -type f -print`;
chomp @files;
return(map { $_ => host_proc($_) } @files);
}
1;
BIN = humfsify
all:
install:
install -d $(DESTDIR)$(BIN_DIR)
install -o 0755 $(BIN) $(DESTDIR)$(BIN_DIR)
clean:
rm -f *~
This diff is collapsed.
/cell.tar/1.1/Fri Jun 14 01:08:18 2002//
/jail_uml.c/1.2/Mon Jul 22 17:37:43 2002//
/Makefile/1.3/Wed Jan 22 18:23:54 2003//
/tty_log.pl/1.2/Wed Jan 29 18:14:40 2003//
/tty_log.pm/1.3/Thu Jun 12 17:10:50 2003//
/db_out.pm/1.1/Wed Nov 19 10:46:34 2003//
/playlog.pl/1.4/Wed Nov 19 10:47:41 2003//
/tty_out.pm/1.1/Wed Nov 19 10:46:28 2003//
/jailer.pl/1.7/Thu Sep 25 20:43:37 2003//
D
jdike@cvs.user-mode-linux.sourceforge.net:/cvsroot/user-mode-linux
OBJS = jail_uml.o
BIN = jail_uml
CFLAGS ?= -g -Wall
SBIN_DIR ?= /usr/sbin
all : $(BIN)
$(BIN) : $(OBJS)
$(CC) $(CFLAGS) -o $(BIN) $(OBJS)
install : $(BIN)
install -d $(DESTDIR)$(SBIN_DIR)
install -s $(BIN) $(DESTDIR)$(SBIN_DIR)
clean :
rm -rf *~ $(BIN) $(OBJS) cell[0-9]* core* tty_log_cell*
File added