diff options
author | Juan Cespedes <cespedes@debian.org> | 1998-03-10 00:08:41 +0100 |
---|---|---|
committer | Juan Cespedes <cespedes@debian.org> | 1998-03-10 00:08:41 +0100 |
commit | e188705c4f1c5c8e377c2438114a99acaeaf8a3a (patch) | |
tree | c64b320ce52c94d39000a23c989fccd32bef8554 | |
parent | 5e01f654d83a95f2acffa86df57a4c2db9b0cae9 (diff) | |
download | ltrace-e188705c4f1c5c8e377c2438114a99acaeaf8a3a.tar.gz |
Version 0.2.1
* Added -u option (run command as other username)
* Updated manual page a bit
-rw-r--r-- | KK | 79 | ||||
-rw-r--r-- | TODO | 3 | ||||
-rw-r--r-- | debian/changelog | 7 | ||||
-rw-r--r-- | execute_program.c | 58 | ||||
-rw-r--r-- | ltrace.1 | 30 | ||||
-rw-r--r-- | options.c | 6 | ||||
-rw-r--r-- | options.h | 1 |
7 files changed, 94 insertions, 90 deletions
@@ -1,79 +0,0 @@ -atexit(0x40006150) = 0 -__libc_init_first(2, 0xbffffb6e, 0xbffffb7d, 0, 0xbffffb82) = 0x40006150 -atexit(0x0804cc20) = 0 -socket(2, 2, 0, 0x0804a0d5, 0x4000b070) = 5 -socket(4, 2, 0, 2, 2) = -1 -socket(3, 2, 0, 4, 2) = -1 -socket(5, 2, 0, 0x0804a0d5, 0x4000b070) = -1 -strncpy(0xbffff9b4, "eth0", 16) = 0xbffff9b4 -memset(0xbffff828, '\000', 340) = 0xbffff828 -strcpy(0xbffff828, "eth0") = 0xbffff828 -strcpy(0xbffff7e8, "eth0") = 0xbffff7e8 -ioctl(5, 35091, 0xbffff7e8, 0xbffff7e8, 0xbffff9b4) = 0 -strcpy(0xbffff7e8, "eth0") = 0xbffff7e8 -ioctl(5, 35111, 0xbffff7e8, 0xbffff7e8, 0xbffff9b4) = 0 -strcpy(0xbffff7e8, "eth0") = 0xbffff7e8 -ioctl(5, 35101, 0xbffff7e8, 0xbffff7e8, 0xbffff9b4) = 0 -strcpy(0xbffff7e8, "eth0") = 0xbffff7e8 -ioctl(5, 35105, 0xbffff7e8, 0xbffff7e8, 0xbffff9b4) = 0 -strcpy(0xbffff7e8, "eth0") = 0xbffff7e8 -ioctl(5, 35184, 0xbffff7e8, 0xbffff7e8, 0xbffff9b4) = 0 -strcpy(0xbffff7e8, "eth0") = 0xbffff7e8 -ioctl(5, 35184, 0xbffff7e8, 0xbffff7e8, 0xbffff9b4) = 0 -strcpy(0xbffff7e8, "eth0") = 0xbffff7e8 -ioctl(5, 35095, 0xbffff7e8, 0xbffff9b4, 0xbffff828) = 0 -strcpy(0xbffff7e8, "eth0") = 0xbffff7e8 -ioctl(5, 35097, 0xbffff7e8, 0xbffff9b4, 0xbffff828) = 0 -strcpy(0xbffff7e8, "eth0") = 0xbffff7e8 -ioctl(5, 35099, 0xbffff7e8, 0xbffff9b4, 0xbffff828) = 0 -strcpy(0xbffff7e8, "eth0") = 0xbffff7e8 -ioctl(5, 35093, 0xbffff7e8, 0xbffff9b4, 0xbffff828) = 0 -strcpy(0xbffff7e8, "eth0") = 0xbffff7e8 -strcpy(0xbffff7e8, "eth0") = 0xbffff7e8 -fopen(0x0804cfe0, 0x0804cfde, 0xbffff7e8, 0xbffff828, 0xbffff9b4) = 0x0804f828 -fgets("Inter-| Receive "..., 255, 0x0804f828) = 0xbffff6d0 -fgets(" face |packets errs drop fifo fr"..., 255, 0x0804f828) = 0xbffff6d0 -strstr(" face |packets errs drop fifo fr"..., "bytes") = NULL -fgets(" lo: 26 0 0 0 "..., 255, 0x0804f828) = 0xbffff6d0 -strncmp("lo: 26 0 0 0 0 "..., "eth0", 4) = 7 -fgets(" lo:0: 0 0 0 0 "..., 255, 0x0804f828) = 0xbffff6d0 -strncmp("lo:0: 0 0 0 0 0"..., "eth0", 4) = 7 -fgets(" eth0: 0 0 0 0 "..., 255, 0x0804f828) = 0xbffff6d0 -strncmp("eth0: 0 0 0 0 0"..., "eth0", 4) = 0 -strchr(0xbffff6d2, 58, 0xbffff7e8, 0xbffff828, 0xbffff9b4) = 0xbffff6d6 -strchr(0xbffff6d7, 58, 0xbffff7e8, 0xbffff828, 0xbffff9b4) = 0 -strncmp("0 0 0 0 0 0 "..., "No", 2) = -30 -sscanf(0xbffff6dd, 0x0804d02b, 0xbffff924, 0xbffff934, 0xbffff93c) = 11 -fclose(0x0804f828) = 0 -strncmp("eth0", "lo", 2) = -7 -printf("%-8.8s Link encap:%s ") = 31 -sprintf(0x0804f240, 0x0804d740, 0, 80, 78) = 17 -printf("HWaddr %s ") = 26 -printf("\n") = 1 -inet_ntoa(0x010010ac, 0x0804ed64, 0xbffff828, 0x0804ef2c, 1) = 0x0804f828 -strcpy(0x0804f5d4, "172.16.0.1") = 0x0804f5d4 -printf(" %s addr:%s") = 30 -inet_ntoa(0xff0010ac, 0x0804ed64, 0xbffff828, 0x0804ef2c, 1) = 0x0804f828 -strcpy(0x0804f5d4, "172.16.0.255") = 0x0804f5d4 -printf(" Bcast:%s ") = 22 -inet_ntoa(0x00ffffff, 0x0804ed64, 0xbffff828, 0x0804ef2c, 1) = 0x0804f828 -strcpy(0x0804f5d4, "255.255.255.0") = 0x0804f5d4 -printf("Mask:%s\n") = 19 -printf(" ") = 10 -printf("UP ") = 3 -printf("BROADCAST ") = 10 -printf("RUNNING ") = 8 -printf("MULTICAST ") = 10 -printf(" MTU:%d Metric:%d\n") = 20 -printf(" ") = 10 -printf("RX packets:%lu error:%lu dropped"...) = 46 -printf(" ") = 10 -printf("TX packets:%lu error:%lu dropped"...) = 58 -printf(" ") = 10 -printf("Interrupt:%d ") = 12 -printf("Base address:0x%x ") = 19 -printf("\n") = 1 -printf("\n") = 1 -close(5) = 0 -exit(0) -+++ exited (status 0) +++ @@ -1,5 +1,6 @@ * Option -p (trace running process) * Option -f (trace children) +* Option -u (run command as username handling setuid and/or setgid) * SYSCALLS: + execve() <- trace new program * Display different argument types: @@ -9,4 +10,4 @@ * SPARC: + almost all... * netscape: - + Why does it shows so many `breakpointed at:' messages? + + Why does it show so many `breakpointed at:' messages? diff --git a/debian/changelog b/debian/changelog index 340ca18..d405191 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +ltrace (0.2.1) unstable; urgency=low + + * Added -u option (run command as other username) + * Updated manual page a bit + + -- Juan Cespedes <cespedes@debian.org> Tue, 10 Mar 1998 00:08:38 +0100 + ltrace (0.2.0) unstable; urgency=low * First `unstable' release diff --git a/execute_program.c b/execute_program.c index 02d6471..d451f7b 100644 --- a/execute_program.c +++ b/execute_program.c @@ -1,13 +1,19 @@ #include <stdio.h> +#include <sys/types.h> +#include <sys/stat.h> #include <unistd.h> #include <errno.h> #include <string.h> +#include <pwd.h> +#include <grp.h> #include "ltrace.h" #include "options.h" #include "output.h" #include "sysdep.h" +static void change_uid(struct process * proc); + void execute_program(struct process * sp, char **argv) { int pid; @@ -21,6 +27,7 @@ void execute_program(struct process * sp, char **argv) perror("fork"); exit(1); } else if (!pid) { /* child */ + change_uid(sp); trace_me(); execvp(sp->filename, argv); fprintf(stderr, "Can't execute `%s': %s\n", sp->filename, strerror(errno)); @@ -35,3 +42,54 @@ void execute_program(struct process * sp, char **argv) return; } + +static void change_uid(struct process * proc) +{ + uid_t run_uid, run_euid; + gid_t run_gid, run_egid; + + if (opt_u) { + struct passwd *pent; + + if (getuid() != 0 || geteuid() != 0) { + fprintf(stderr, "you must be root to use the -u option\n"); + exit(1); + } + if ((pent = getpwnam(opt_u)) == NULL) { + fprintf(stderr, "cannot find user `%s'\n", opt_u); + exit(1); + } + run_uid = pent->pw_uid; + run_gid = pent->pw_gid; + + if (initgroups(opt_u, run_gid) < 0) { + perror("initgroups"); + exit(1); + } + } else { + run_uid = getuid(); + run_gid = getgid(); + } + if (opt_u || !geteuid()) { + struct stat statbuf; + run_euid = run_uid; + run_egid = run_gid; + + if (!stat(proc->filename, &statbuf)) { + if (statbuf.st_mode & S_ISUID) { + run_euid = statbuf.st_uid; + } + if (statbuf.st_mode & S_ISGID) { + run_euid = statbuf.st_gid; + } + } + if (setregid(run_gid, run_egid) < 0) { + perror("setregid"); + exit(1); + } + if (setreuid(run_uid, run_euid) < 0) { + perror("setreuid"); + exit(1); + } + } +} @@ -6,7 +6,7 @@ ltrace \- A library call tracer .SH SYNOPSIS .B ltrace -.I "[-diLS] [-a column] [-s strsize] [-o filename] command [arg ...]" +.I "[-difLS] [-a column] [-s strsize] [-o filename] [-u username] [-p pid] ... [command [arg ...]]" .SH DESCRIPTION .B ltrace @@ -21,23 +21,18 @@ Its use is very similar to .SH OPTIONS .TP -.I \-a column -Align return values in a secific column (default column 50). .I \-d Increase the debugging level. .TP +.I \-i +Print the instruction pointer at the time of the library call. +.TP .I \-f Trace child processes as they are created by currently traced processes as a result of the fork(2) or clone(2) system calls. The new process is attached as soon as its pid is known. .TP -.I \-i -Print the instruction pointer at the time of the library call. -.TP -.I \-s -Specify the maximum string size to print (the default is 32). -.TP .I \-L DON'T display library calls (use it with the .I \-S @@ -46,10 +41,27 @@ option). .I \-S Display system calls as well as library calls .TP +.I \-a column +Align return values in a secific column (default column 50). +.TP +.I \-s +Specify the maximum string size to print (the default is 32). +.TP .I \-o filename Write the trace output to the file .I filename rather than to stderr. +.TP +.I \-u username +Run command with the userid, groupid and supplementary groups of +.IR username . +This option is only useful when running as root and enables the +correct execution of setuid and/or setgid binaries. +.TP +.I \-p pid +Attach to the process with the process ID +.I pid +and begin tracing. .SH BUGS At the moment, there are too many bugs to list here. @@ -16,6 +16,7 @@ int opt_s = DEFAULT_STRLEN; /* default maximum # of bytes printed in strings */ int opt_S = 0; /* display syscalls */ int opt_L = 1; /* display library calls */ int opt_f = 0; /* trace child processes as they are created */ +char * opt_u = NULL; /* username to run command as */ /* List of pids given to option -p: */ struct opt_p_t * opt_p = NULL; /* attach to process with a given pid */ @@ -23,7 +24,7 @@ struct opt_p_t * opt_p = NULL; /* attach to process with a given pid */ static void usage(void) { fprintf(stderr, "Usage: ltrace [-dfiLS] [-a column] [-s strlen] [-o filename]\n" - " [-p pid] ... [command [arg ...]]\n\n"); + " [-u username] [-p pid] ... [command [arg ...]]\n\n"); } static char * search_for_command(char * filename) @@ -92,6 +93,9 @@ char ** process_options(int argc, char **argv) break; case 'f': opt_f = 1; break; + case 'u': opt_u = argv[1]; + argc--; argv++; + break; case 'p': { struct opt_p_t * tmp = malloc(sizeof(struct opt_p_t)); @@ -8,6 +8,7 @@ extern int opt_s; /* default maximum # of bytes printed in strings */ extern int opt_L; /* display library calls */ extern int opt_S; /* display system calls */ extern int opt_f; /* trace child processes */ +extern char * opt_u; /* username to run command as */ struct opt_p_t { pid_t pid; |