diff options
-rw-r--r-- | Changelog | 7 | ||||
-rw-r--r-- | TODO | 2 | ||||
-rw-r--r-- | applets/busybox.c | 3 | ||||
-rw-r--r-- | busybox.c | 3 | ||||
-rw-r--r-- | busybox.def.h | 1 | ||||
-rw-r--r-- | console-tools/loadkmap.c | 1 | ||||
-rw-r--r-- | coreutils/id.c | 92 | ||||
-rw-r--r-- | coreutils/tail.c | 6 | ||||
-rw-r--r-- | cp_mv.c | 4 | ||||
-rw-r--r-- | id.c | 92 | ||||
-rw-r--r-- | internal.h | 15 | ||||
-rw-r--r-- | loadkmap.c | 1 | ||||
-rw-r--r-- | networking/telnet.c | 21 | ||||
-rw-r--r-- | tail.c | 6 | ||||
-rw-r--r-- | telnet.c | 21 | ||||
-rw-r--r-- | utility.c | 57 |
16 files changed, 286 insertions, 46 deletions
@@ -2,6 +2,7 @@ * added the -v option (inverted search) to grep, updated docs/busybox.pod accordingly. -beppu * Added mktemp, contributed by Daniel Jacobowitz <dan@debian.org> + * Added setkeycodes, for those that have wierd keyboard buttons. * Fix for ping warnings from Sascha Ziemann <szi@aibon.ping.de> * Fixed update segfault * Fixed mknod -- minor number was always 0 @@ -9,6 +10,12 @@ that wanted "tar cf foo.tar foo" (i.e. no "-" before options) I broke creation of tarballs. I reverted the change (so tar needs the "-" for all options). + * Several contributions from Randolph Chung <tausq@debian.org>. + * cp/mv now accepts (and ignores) the -f flag, since it always + does force anyway + * tail can now accept -<num> commands (e.g. -10) for better + compatibility with the standard tail command + * added a simple id implementation; doesn't support supp. groups yet * More doc updates -Erik @@ -4,7 +4,7 @@ or that doing so is even a good idea. It just means that I _might_ get around to it some time. If you have any good ideas, please let me know. * login/sulogin/passwd/getty/etc are part of tinylogin, and so are not - needed or wanted in busybox (or else I'd have to link in libcrypt). + needed or wanted in busybox (or else I'd have to link to libcrypt). * Networking apps are probably going to be split out some time soon into a separate package (named perhaps tiny-netkit?). This currently includes diff --git a/applets/busybox.c b/applets/busybox.c index ca767584a..d8a38ada3 100644 --- a/applets/busybox.c +++ b/applets/busybox.c @@ -134,6 +134,9 @@ static const struct Applet applets[] = { #ifdef BB_HOSTNAME {"hostname", hostname_main, _BB_DIR_BIN}, #endif +#ifdef BB_ID + {"id", id_main, _BB_DIR_USR_BIN}, +#endif #ifdef BB_INIT {"init", init_main, _BB_DIR_SBIN}, #endif @@ -134,6 +134,9 @@ static const struct Applet applets[] = { #ifdef BB_HOSTNAME {"hostname", hostname_main, _BB_DIR_BIN}, #endif +#ifdef BB_ID + {"id", id_main, _BB_DIR_USR_BIN}, +#endif #ifdef BB_INIT {"init", init_main, _BB_DIR_SBIN}, #endif diff --git a/busybox.def.h b/busybox.def.h index c10c1a318..86b8059cb 100644 --- a/busybox.def.h +++ b/busybox.def.h @@ -36,6 +36,7 @@ #define BB_HEAD #define BB_HOSTID #define BB_HOSTNAME +#define BB_ID #define BB_INIT // Don't bother turning BB_INSMOD on. It doesn't work yet. //#define BB_INSMOD diff --git a/console-tools/loadkmap.c b/console-tools/loadkmap.c index 75e52e148..2ac4273db 100644 --- a/console-tools/loadkmap.c +++ b/console-tools/loadkmap.c @@ -51,6 +51,7 @@ int loadkmap_main(int argc, char **argv) } read(0, buff, 7); + printf("buff='%s'\n", buff); if (0 != strncmp(buff, magic, 7)) { fprintf(stderr, "This is not a valid binary keymap.\n"); exit(FALSE); diff --git a/coreutils/id.c b/coreutils/id.c new file mode 100644 index 000000000..8ded0e521 --- /dev/null +++ b/coreutils/id.c @@ -0,0 +1,92 @@ +/* vi: set sw=4 ts=4: */ +/* + * Mini id implementation for busybox + * + * + * Copyright (C) 2000 by Randolph Chung <tausq@debian.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "internal.h" +#include <stdio.h> +#include <unistd.h> +#include <pwd.h> +#include <grp.h> +#include <sys/types.h> + +static const char id_usage[] = + "id [OPTIONS]... [USERNAME]\n\n" + "Print information for USERNAME or the current user\n\n" + "\t-g\tprints only the group ID\n" + "\t-u\tprints only the user ID\n" + "\t-r\tprints the real user ID instead of the effective ID (with -ug)\n\n"; + +extern int id_main(int argc, char **argv) +{ + int no_user = 0, no_group = 0, print_real = 0; + char *cp, *user, *group; + gid_t gid; + + cp = user = group = NULL; + + argc--; argv++; + + while (argc > 0) { + cp = *argv; + if (*cp == '-') { + switch (*++cp) { + case 'u': no_group = 1; break; + case 'g': no_user = 1; break; + case 'r': print_real = 1; break; + default: usage(id_usage); + } + } else { + user = cp; + } + argc--; argv++; + } + + if (no_user && no_group) usage(id_usage); + + if (user == NULL) { + user = xmalloc(9); + group = xmalloc(9); + if (print_real) { + my_getpwuid(user, getuid()); + my_getgrgid(group, getgid()); + } else { + my_getpwuid(user, geteuid()); + my_getgrgid(group, getegid()); + } + } else { + group = xmalloc(9); + gid = my_getpwnamegid(user); + my_getgrgid(group, gid); + } + + if (no_group) printf("%u\n", my_getpwnam(user)); + else if (no_user) printf("%u\n", my_getgrnam(group)); + else + printf("uid=%u(%s) gid=%u(%s)\n", + my_getpwnam(user), user, my_getgrnam(group), group); + + + exit(0); +} + + +/* END CODE */ diff --git a/coreutils/tail.c b/coreutils/tail.c index 315eee188..321c5c4b2 100644 --- a/coreutils/tail.c +++ b/coreutils/tail.c @@ -368,8 +368,10 @@ extern int tail_main(int argc, char **argv) case 'h': usage(tail_usage); default: - fprintf(stderr, "tail: invalid option -- %c\n", opt); - usage(tail_usage); + if ((n_units = atoi(&argv[i][1])) < 1) { + fprintf(stderr, "tail: invalid option -- %c\n", opt); + usage(tail_usage); + } } } else { break; @@ -56,6 +56,7 @@ static const char *cp_mv_usage[] = /* .rodata */ "\t-a\tSame as -dpR\n" "\t-d\tPreserves links\n" "\t-p\tPreserves file attributes if possible\n" + "\t-f\tforce (implied; ignored) - always set\n" "\t-R\tCopies directories recursively\n" #endif , @@ -218,6 +219,9 @@ extern int cp_mv_main(int argc, char **argv) case 'R': recursiveFlag = TRUE; break; + case 'f': + /* for compatibility; busybox cp/mv always does force */ + break; default: usage(cp_mv_usage[is_cp]); } @@ -0,0 +1,92 @@ +/* vi: set sw=4 ts=4: */ +/* + * Mini id implementation for busybox + * + * + * Copyright (C) 2000 by Randolph Chung <tausq@debian.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "internal.h" +#include <stdio.h> +#include <unistd.h> +#include <pwd.h> +#include <grp.h> +#include <sys/types.h> + +static const char id_usage[] = + "id [OPTIONS]... [USERNAME]\n\n" + "Print information for USERNAME or the current user\n\n" + "\t-g\tprints only the group ID\n" + "\t-u\tprints only the user ID\n" + "\t-r\tprints the real user ID instead of the effective ID (with -ug)\n\n"; + +extern int id_main(int argc, char **argv) +{ + int no_user = 0, no_group = 0, print_real = 0; + char *cp, *user, *group; + gid_t gid; + + cp = user = group = NULL; + + argc--; argv++; + + while (argc > 0) { + cp = *argv; + if (*cp == '-') { + switch (*++cp) { + case 'u': no_group = 1; break; + case 'g': no_user = 1; break; + case 'r': print_real = 1; break; + default: usage(id_usage); + } + } else { + user = cp; + } + argc--; argv++; + } + + if (no_user && no_group) usage(id_usage); + + if (user == NULL) { + user = xmalloc(9); + group = xmalloc(9); + if (print_real) { + my_getpwuid(user, getuid()); + my_getgrgid(group, getgid()); + } else { + my_getpwuid(user, geteuid()); + my_getgrgid(group, getegid()); + } + } else { + group = xmalloc(9); + gid = my_getpwnamegid(user); + my_getgrgid(group, gid); + } + + if (no_group) printf("%u\n", my_getpwnam(user)); + else if (no_user) printf("%u\n", my_getgrnam(group)); + else + printf("uid=%u(%s) gid=%u(%s)\n", + my_getpwnam(user), user, my_getgrnam(group), group); + + + exit(0); +} + + +/* END CODE */ diff --git a/internal.h b/internal.h index a81651bec..859bee1c3 100644 --- a/internal.h +++ b/internal.h @@ -129,6 +129,7 @@ extern int halt_main(int argc, char** argv); extern int head_main(int argc, char** argv); extern int hostid_main(int argc, char** argv); extern int hostname_main(int argc, char** argv); +extern int id_main(int argc, char** argv); extern int init_main(int argc, char** argv); extern int insmod_main(int argc, char** argv); extern int kill_main(int argc, char** argv); @@ -233,10 +234,7 @@ extern int createPath (const char *name, int mode); extern int parse_mode( const char* s, mode_t* theMode); extern int get_kernel_revision(void); -extern uid_t my_getpwnam(char *name); -extern gid_t my_getgrnam(char *name); -extern void my_getpwuid(char* name, uid_t uid); -extern void my_getgrgid(char* group, gid_t gid); + extern int get_console_fd(char* tty_name); extern struct mntent *findMountPoint(const char *name, const char *table); extern void write_mtab(char* blockDevice, char* directory, @@ -253,6 +251,15 @@ extern void *xmalloc (size_t size); extern int find_real_root_device_name(char* name); extern char *cstring_lineFromFile(FILE *f); +/* These parse entries in /etc/passwd and /etc/group. This is desirable + * for BusyBox since we want to avoid using the glibc NSS stuff, which + * increases target size and is often not needed embedded systems. */ +extern uid_t my_getpwnam(char *name); +extern gid_t my_getgrnam(char *name); +extern void my_getpwuid(char *name, uid_t uid); +extern void my_getgrgid(char *group, gid_t gid); +extern gid_t my_getpwnamegid(char *name); + #if defined BB_INIT || defined BB_SYSLOGD extern int device_open(char *device, int mode); diff --git a/loadkmap.c b/loadkmap.c index 75e52e148..2ac4273db 100644 --- a/loadkmap.c +++ b/loadkmap.c @@ -51,6 +51,7 @@ int loadkmap_main(int argc, char **argv) } read(0, buff, 7); + printf("buff='%s'\n", buff); if (0 != strncmp(buff, magic, 7)) { fprintf(stderr, "This is not a valid binary keymap.\n"); exit(FALSE); diff --git a/networking/telnet.c b/networking/telnet.c index 076728fb0..8c58521eb 100644 --- a/networking/telnet.c +++ b/networking/telnet.c @@ -1,6 +1,5 @@ -/* vi: set sw=4 ts=4: */ /* - * $Id: telnet.c,v 1.1 2000/02/22 17:17:45 erik Exp $ + * $Id: telnet.c,v 1.2 2000/05/01 19:10:52 erik Exp $ * Mini telnet implementation for busybox * * Copyright (C) 2000 by Randolph Chung <tausq@debian.org> @@ -102,15 +101,15 @@ static inline void telnet_senddont(int s, int c) { SENDCOMMAND(DONT, c); } static void telnet_setoptions(int s) { /* - telnet_senddo(s, TELOPT_SGA); TFLAG_SET(TELOPT_SGA, DO); telnet_sendwill(s, TELOPT_NAWS); TFLAG_SET(TELOPT_NAWS, WILL); telnet_sendwill(s, TELOPT_TSPEED); TFLAG_SET(TELOPT_TSPEED, WILL); - telnet_sendwill(s, TELOPT_LFLOW); TFLAG_SET(TELOPT_LFLOW, WILL); - telnet_sendwill(s, TELOPT_LINEMODE); TFLAG_SET(TELOPT_LINEMODE, WILL); telnet_sendwill(s, TELOPT_NEW_ENVIRON); TFLAG_SET(TELOPT_NEW_ENVIRON, WILL); telnet_senddo(s, TELOPT_STATUS); TFLAG_SET(TELOPT_STATUS, DO); telnet_sendwill(s, TELOPT_TTYPE); TFLAG_SET(TELOPT_TTYPE, WILL); */ + telnet_senddo(s, TELOPT_SGA); TFLAG_SET(TELOPT_SGA, DO); + telnet_sendwill(s, TELOPT_LFLOW); TFLAG_SET(TELOPT_LFLOW, WILL); + telnet_sendwill(s, TELOPT_LINEMODE); TFLAG_SET(TELOPT_LINEMODE, WILL); telnet_senddo(s, TELOPT_BINARY); TFLAG_SET(TELOPT_BINARY, DO); telnet_sendwill(s, TELOPT_BINARY); TFLAG_SET(TELOPT_BINARY, WILL); } @@ -457,16 +456,16 @@ int main(int argc, char **argv) int telnet_main(int argc, char **argv) #endif { - int port = TELNETPORT; + int port = TELNETPORT; argc--; argv++; if (argc < 1) usage(telnet_usage); - if (argc > 1) port = atoi(argv[1]); - telnet_init(); - atexit(telnet_shutdown); + if (argc > 1) port = atoi(argv[1]); + telnet_init(); + atexit(telnet_shutdown); - telnet_start(argv[0], port); - return 0; + telnet_start(argv[0], port); + return 0; } /* @@ -368,8 +368,10 @@ extern int tail_main(int argc, char **argv) case 'h': usage(tail_usage); default: - fprintf(stderr, "tail: invalid option -- %c\n", opt); - usage(tail_usage); + if ((n_units = atoi(&argv[i][1])) < 1) { + fprintf(stderr, "tail: invalid option -- %c\n", opt); + usage(tail_usage); + } } } else { break; @@ -1,6 +1,5 @@ -/* vi: set sw=4 ts=4: */ /* - * $Id: telnet.c,v 1.1 2000/02/22 17:17:45 erik Exp $ + * $Id: telnet.c,v 1.2 2000/05/01 19:10:52 erik Exp $ * Mini telnet implementation for busybox * * Copyright (C) 2000 by Randolph Chung <tausq@debian.org> @@ -102,15 +101,15 @@ static inline void telnet_senddont(int s, int c) { SENDCOMMAND(DONT, c); } static void telnet_setoptions(int s) { /* - telnet_senddo(s, TELOPT_SGA); TFLAG_SET(TELOPT_SGA, DO); telnet_sendwill(s, TELOPT_NAWS); TFLAG_SET(TELOPT_NAWS, WILL); telnet_sendwill(s, TELOPT_TSPEED); TFLAG_SET(TELOPT_TSPEED, WILL); - telnet_sendwill(s, TELOPT_LFLOW); TFLAG_SET(TELOPT_LFLOW, WILL); - telnet_sendwill(s, TELOPT_LINEMODE); TFLAG_SET(TELOPT_LINEMODE, WILL); telnet_sendwill(s, TELOPT_NEW_ENVIRON); TFLAG_SET(TELOPT_NEW_ENVIRON, WILL); telnet_senddo(s, TELOPT_STATUS); TFLAG_SET(TELOPT_STATUS, DO); telnet_sendwill(s, TELOPT_TTYPE); TFLAG_SET(TELOPT_TTYPE, WILL); */ + telnet_senddo(s, TELOPT_SGA); TFLAG_SET(TELOPT_SGA, DO); + telnet_sendwill(s, TELOPT_LFLOW); TFLAG_SET(TELOPT_LFLOW, WILL); + telnet_sendwill(s, TELOPT_LINEMODE); TFLAG_SET(TELOPT_LINEMODE, WILL); telnet_senddo(s, TELOPT_BINARY); TFLAG_SET(TELOPT_BINARY, DO); telnet_sendwill(s, TELOPT_BINARY); TFLAG_SET(TELOPT_BINARY, WILL); } @@ -457,16 +456,16 @@ int main(int argc, char **argv) int telnet_main(int argc, char **argv) #endif { - int port = TELNETPORT; + int port = TELNETPORT; argc--; argv++; if (argc < 1) usage(telnet_usage); - if (argc > 1) port = atoi(argv[1]); - telnet_init(); - atexit(telnet_shutdown); + if (argc > 1) port = atoi(argv[1]); + telnet_init(); + atexit(telnet_shutdown); - telnet_start(argv[0], port); - return 0; + telnet_start(argv[0], port); + return 0; } /* @@ -783,18 +783,27 @@ extern int parse_mode(const char *s, mode_t * theMode) +#if defined BB_CHMOD_CHOWN_CHGRP || defined BB_PS || defined BB_LS || defined BB_TAR || defined BB_ID - -#if defined BB_CHMOD_CHOWN_CHGRP || defined BB_PS || defined BB_LS || defined BB_TAR - -/* Use this to avoid needing the glibc NSS stuff - * This uses storage buf to hold things. - * */ -uid_t my_getid(const char *filename, char *name, uid_t id) +/* This parses entries in /etc/passwd and /etc/group. This is desirable + * for BusyBox, since we want to avoid using the glibc NSS stuff, which + * increases target size and is often not needed or wanted for embedded + * systems. + * + * /etc/passwd entries look like this: + * root:x:0:0:root:/root:/bin/bash + * and /etc/group entries look like this: + * root:x:0: + * + * This uses buf as storage to hold things. + * + */ +uid_t my_getid(const char *filename, char *name, uid_t id, gid_t *gid) { FILE *file; char *rname, *start, *end, buf[128]; - uid_t rid; + id_t rid; + gid_t rgid = 0; file = fopen(filename, "r"); if (file == NULL) { @@ -806,6 +815,7 @@ uid_t my_getid(const char *filename, char *name, uid_t id) if (buf[0] == '#') continue; + /* username/group name */ start = buf; end = strchr(start, ':'); if (end == NULL) @@ -813,24 +823,32 @@ uid_t my_getid(const char *filename, char *name, uid_t id) *end = '\0'; rname = start; + /* password */ start = end + 1; end = strchr(start, ':'); if (end == NULL) continue; + /* uid in passwd, gid in group */ start = end + 1; rid = (uid_t) strtol(start, &end, 10); if (end == start) continue; + /* gid in passwd */ + start = end + 1; + rgid = (gid_t) strtol(start, &end, 10); + if (name) { if (0 == strcmp(rname, name)) { + if (gid) *gid = rgid; fclose(file); return (rid); } } if (id != -1 && id == rid) { strncpy(name, rname, 8); + if (gid) *gid = rgid; fclose(file); return (TRUE); } @@ -839,30 +857,39 @@ uid_t my_getid(const char *filename, char *name, uid_t id) return (-1); } +/* returns a uid given a username */ uid_t my_getpwnam(char *name) { - return my_getid("/etc/passwd", name, -1); + return my_getid("/etc/passwd", name, -1, NULL); } +/* returns a gid given a group name */ gid_t my_getgrnam(char *name) { - return my_getid("/etc/group", name, -1); + return my_getid("/etc/group", name, -1, NULL); } +/* gets a username given a uid */ void my_getpwuid(char *name, uid_t uid) { - my_getid("/etc/passwd", name, uid); + my_getid("/etc/passwd", name, uid, NULL); } +/* gets a groupname given a gid */ void my_getgrgid(char *group, gid_t gid) { - my_getid("/etc/group", group, gid); + my_getid("/etc/group", group, gid, NULL); } +/* gets a gid given a user name */ +gid_t my_getpwnamegid(char *name) +{ + gid_t gid; + my_getid("/etc/passwd", name, -1, &gid); + return gid; +} -#endif /* BB_CHMOD_CHOWN_CHGRP || BB_PS || BB_LS || BB_TAR */ - - +#endif /* BB_CHMOD_CHOWN_CHGRP || BB_PS || BB_LS || BB_TAR || BB_ID */ #if (defined BB_CHVT) || (defined BB_DEALLOCVT) |