diff options
author | bug1 <bug1@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2003-05-26 14:07:50 +0000 |
---|---|---|
committer | bug1 <bug1@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2003-05-26 14:07:50 +0000 |
commit | 76f4ab68a56e14747c25e6da830cf73b38bbe1cd (patch) | |
tree | d2e94dac0f1f5da5cb3ecb927b78c4c2a02f4ea6 /libbb | |
parent | 37e0338781ea28f57bed354fe745effb020d16fc (diff) | |
download | busybox-w32-76f4ab68a56e14747c25e6da830cf73b38bbe1cd.tar.gz busybox-w32-76f4ab68a56e14747c25e6da830cf73b38bbe1cd.tar.bz2 busybox-w32-76f4ab68a56e14747c25e6da830cf73b38bbe1cd.zip |
Vodz, last_patch_86
git-svn-id: svn://busybox.net/trunk/busybox@6853 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'libbb')
-rw-r--r-- | libbb/Makefile.in | 2 | ||||
-rw-r--r-- | libbb/concat_subpath_file.c | 36 | ||||
-rw-r--r-- | libbb/copy_file.c | 6 | ||||
-rw-r--r-- | libbb/find_root_device.c | 7 | ||||
-rw-r--r-- | libbb/isdirectory.c | 12 | ||||
-rw-r--r-- | libbb/login.c | 50 | ||||
-rw-r--r-- | libbb/pw_encrypt.c | 5 | ||||
-rw-r--r-- | libbb/recursive_action.c | 6 | ||||
-rw-r--r-- | libbb/remove_file.c | 6 | ||||
-rw-r--r-- | libbb/run_shell.c | 4 | ||||
-rw-r--r-- | libbb/setup_environment.c | 4 | ||||
-rw-r--r-- | libbb/xgetcwd.c | 2 |
12 files changed, 79 insertions, 61 deletions
diff --git a/libbb/Makefile.in b/libbb/Makefile.in index 06daf232c..98b0c66e2 100644 --- a/libbb/Makefile.in +++ b/libbb/Makefile.in | |||
@@ -48,7 +48,7 @@ LIBBB_SRC:= \ | |||
48 | fclose_nonstdin.c fflush_stdout_and_exit.c getopt_ulflags.c \ | 48 | fclose_nonstdin.c fflush_stdout_and_exit.c getopt_ulflags.c \ |
49 | default_error_retval.c wfopen_input.c speed_table.c \ | 49 | default_error_retval.c wfopen_input.c speed_table.c \ |
50 | perror_nomsg_and_die.c perror_nomsg.c skip_whitespace.c \ | 50 | perror_nomsg_and_die.c perror_nomsg.c skip_whitespace.c \ |
51 | warn_ignoring_args.c | 51 | warn_ignoring_args.c concat_subpath_file.c |
52 | 52 | ||
53 | LIBBB_OBJS=$(patsubst %.c,$(LIBBB_DIR)%.o, $(LIBBB_SRC)) | 53 | LIBBB_OBJS=$(patsubst %.c,$(LIBBB_DIR)%.o, $(LIBBB_SRC)) |
54 | 54 | ||
diff --git a/libbb/concat_subpath_file.c b/libbb/concat_subpath_file.c new file mode 100644 index 000000000..6d86f5e8c --- /dev/null +++ b/libbb/concat_subpath_file.c | |||
@@ -0,0 +1,36 @@ | |||
1 | /* vi: set sw=4 ts=4: */ | ||
2 | /* | ||
3 | * Utility routines. | ||
4 | * | ||
5 | * Copyright (C) (C) 2003 Vladimir Oleynik <dzo@simtreas.ru> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, but | ||
13 | * WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | ||
20 | * USA | ||
21 | */ | ||
22 | |||
23 | /* | ||
24 | This function make special for recursive actions with usage | ||
25 | concat_path_file(path, filename) | ||
26 | and skiping "." and ".." directory entries | ||
27 | */ | ||
28 | |||
29 | #include "libbb.h" | ||
30 | |||
31 | extern char *concat_subpath_file(const char *path, const char *f) | ||
32 | { | ||
33 | if(f && *f == '.' && (!f[1] || (f[1] == '.' && !f[2]))) | ||
34 | return NULL; | ||
35 | return concat_path_file(path, f); | ||
36 | } | ||
diff --git a/libbb/copy_file.c b/libbb/copy_file.c index 81c547479..5808ca48c 100644 --- a/libbb/copy_file.c +++ b/libbb/copy_file.c | |||
@@ -105,11 +105,9 @@ int copy_file(const char *source, const char *dest, int flags) | |||
105 | while ((d = readdir(dp)) != NULL) { | 105 | while ((d = readdir(dp)) != NULL) { |
106 | char *new_source, *new_dest; | 106 | char *new_source, *new_dest; |
107 | 107 | ||
108 | if (strcmp(d->d_name, ".") == 0 || | 108 | new_source = concat_subpath_file(source, d->d_name); |
109 | strcmp(d->d_name, "..") == 0) | 109 | if(new_source == NULL) |
110 | continue; | 110 | continue; |
111 | |||
112 | new_source = concat_path_file(source, d->d_name); | ||
113 | new_dest = concat_path_file(dest, d->d_name); | 111 | new_dest = concat_path_file(dest, d->d_name); |
114 | if (copy_file(new_source, new_dest, flags) < 0) | 112 | if (copy_file(new_source, new_dest, flags) < 0) |
115 | status = -1; | 113 | status = -1; |
diff --git a/libbb/find_root_device.c b/libbb/find_root_device.c index 763ac7519..b12d392a2 100644 --- a/libbb/find_root_device.c +++ b/libbb/find_root_device.c | |||
@@ -49,13 +49,10 @@ extern char *find_real_root_device_name(const char* name) | |||
49 | else { | 49 | else { |
50 | while((entry = readdir(dir)) != NULL) { | 50 | while((entry = readdir(dir)) != NULL) { |
51 | 51 | ||
52 | /* Must skip ".." since that is "/", and so we | 52 | fileName = concat_subpath_file("/dev", entry->d_name); |
53 | * would get a false positive on ".." */ | 53 | if(fileName == NULL) |
54 | if (strcmp(entry->d_name, "..") == 0) | ||
55 | continue; | 54 | continue; |
56 | 55 | ||
57 | fileName = concat_path_file("/dev", entry->d_name); | ||
58 | |||
59 | /* Some char devices have the same dev_t as block | 56 | /* Some char devices have the same dev_t as block |
60 | * devices, so make sure this is a block device */ | 57 | * devices, so make sure this is a block device */ |
61 | if (stat(fileName, &statBuf) == 0 && | 58 | if (stat(fileName, &statBuf) == 0 && |
diff --git a/libbb/isdirectory.c b/libbb/isdirectory.c index e8ef2df14..e9b106aa3 100644 --- a/libbb/isdirectory.c +++ b/libbb/isdirectory.c | |||
@@ -20,8 +20,6 @@ | |||
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 | */ | 21 | */ |
22 | 22 | ||
23 | #include <stdio.h> | ||
24 | #include <stdlib.h> | ||
25 | #include <sys/stat.h> | 23 | #include <sys/stat.h> |
26 | #include "libbb.h" | 24 | #include "libbb.h" |
27 | 25 | ||
@@ -32,11 +30,11 @@ | |||
32 | int is_directory(const char *fileName, const int followLinks, struct stat *statBuf) | 30 | int is_directory(const char *fileName, const int followLinks, struct stat *statBuf) |
33 | { | 31 | { |
34 | int status; | 32 | int status; |
35 | int didMalloc = 0; | 33 | struct stat astatBuf; |
36 | 34 | ||
37 | if (statBuf == NULL) { | 35 | if (statBuf == NULL) { |
38 | statBuf = (struct stat *)xmalloc(sizeof(struct stat)); | 36 | /* set from auto stack buffer */ |
39 | ++didMalloc; | 37 | statBuf = &astatBuf; |
40 | } | 38 | } |
41 | 39 | ||
42 | if (followLinks) | 40 | if (followLinks) |
@@ -49,10 +47,6 @@ int is_directory(const char *fileName, const int followLinks, struct stat *statB | |||
49 | } | 47 | } |
50 | else status = TRUE; | 48 | else status = TRUE; |
51 | 49 | ||
52 | if (didMalloc) { | ||
53 | free(statBuf); | ||
54 | statBuf = NULL; | ||
55 | } | ||
56 | return status; | 50 | return status; |
57 | } | 51 | } |
58 | 52 | ||
diff --git a/libbb/login.c b/libbb/login.c index bd8035f41..67636e6b5 100644 --- a/libbb/login.c +++ b/libbb/login.c | |||
@@ -17,26 +17,28 @@ | |||
17 | * along with this program; if not, write to the Free Software | 17 | * along with this program; if not, write to the Free Software |
18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 18 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
19 | * | 19 | * |
20 | * $Id: login.c,v 1.3 2003/05/13 13:28:25 bug1 Exp $ | 20 | * Optimize and correcting OCRNL by Vladimir Oleynik <dzo@simtreas.ru> |
21 | */ | 21 | */ |
22 | 22 | ||
23 | #include <sys/param.h> /* MAXHOSTNAMELEN */ | ||
23 | #include <stdio.h> | 24 | #include <stdio.h> |
24 | #include <unistd.h> | 25 | #include <unistd.h> |
25 | #include "busybox.h" | 26 | #include "libbb.h" |
26 | 27 | ||
27 | #include <sys/utsname.h> | 28 | #include <sys/utsname.h> |
28 | #include <time.h> | 29 | #include <time.h> |
29 | 30 | ||
30 | #define LOGIN " login: " | 31 | #define LOGIN " login: " |
31 | 32 | ||
32 | static char fmtstr_d[] = { "%A, %d %B %Y" }; | 33 | static const char fmtstr_d[] = "%A, %d %B %Y"; |
33 | static char fmtstr_t[] = { "%H:%M:%S" }; | 34 | static const char fmtstr_t[] = "%H:%M:%S"; |
34 | 35 | ||
35 | void print_login_issue(const char *issue_file, const char *tty) | 36 | void print_login_issue(const char *issue_file, const char *tty) |
36 | { | 37 | { |
37 | FILE *fd; | 38 | FILE *fd; |
38 | int c; | 39 | int c; |
39 | char buf[256]; | 40 | char buf[256]; |
41 | const char *outbuf; | ||
40 | time_t t; | 42 | time_t t; |
41 | struct utsname uts; | 43 | struct utsname uts; |
42 | 44 | ||
@@ -47,73 +49,75 @@ void print_login_issue(const char *issue_file, const char *tty) | |||
47 | 49 | ||
48 | if ((fd = fopen(issue_file, "r"))) { | 50 | if ((fd = fopen(issue_file, "r"))) { |
49 | while ((c = fgetc(fd)) != EOF) { | 51 | while ((c = fgetc(fd)) != EOF) { |
52 | outbuf = buf; | ||
53 | buf[0] = c; | ||
54 | if(c == '\n') { | ||
55 | buf[1] = '\r'; | ||
56 | buf[2] = 0; | ||
57 | } else { | ||
58 | buf[1] = 0; | ||
59 | } | ||
50 | if (c == '\\' || c == '%') { | 60 | if (c == '\\' || c == '%') { |
51 | c = fgetc(fd); | 61 | c = fgetc(fd); |
52 | |||
53 | switch (c) { | 62 | switch (c) { |
54 | case 's': | 63 | case 's': |
55 | fputs(uts.sysname, stdout); | 64 | outbuf = uts.sysname; |
56 | break; | 65 | break; |
57 | 66 | ||
58 | case 'n': | 67 | case 'n': |
59 | fputs(uts.nodename, stdout); | 68 | outbuf = uts.nodename; |
60 | break; | 69 | break; |
61 | 70 | ||
62 | case 'r': | 71 | case 'r': |
63 | fputs(uts.release, stdout); | 72 | outbuf = uts.release; |
64 | break; | 73 | break; |
65 | 74 | ||
66 | case 'v': | 75 | case 'v': |
67 | fputs(uts.version, stdout); | 76 | outbuf = uts.version; |
68 | break; | 77 | break; |
69 | 78 | ||
70 | case 'm': | 79 | case 'm': |
71 | fputs(uts.machine, stdout); | 80 | outbuf = uts.machine; |
72 | break; | 81 | break; |
73 | 82 | ||
74 | case 'D': | 83 | case 'D': |
75 | case 'o': | 84 | case 'o': |
76 | getdomainname(buf, sizeof(buf)); | 85 | getdomainname(buf, sizeof(buf)); |
77 | buf[sizeof(buf) - 1] = '\0'; | 86 | buf[sizeof(buf) - 1] = '\0'; |
78 | fputs(buf, stdout); | ||
79 | break; | 87 | break; |
80 | 88 | ||
81 | case 'd': | 89 | case 'd': |
82 | strftime(buf, sizeof(buf), fmtstr_d, localtime(&t)); | 90 | strftime(buf, sizeof(buf), fmtstr_d, localtime(&t)); |
83 | fputs(buf, stdout); | ||
84 | break; | 91 | break; |
85 | 92 | ||
86 | case 't': | 93 | case 't': |
87 | strftime(buf, sizeof(buf), fmtstr_t, localtime(&t)); | 94 | strftime(buf, sizeof(buf), fmtstr_t, localtime(&t)); |
88 | fputs(buf, stdout); | ||
89 | break; | 95 | break; |
90 | 96 | ||
91 | case 'h': | 97 | case 'h': |
92 | gethostname(buf, sizeof(buf)); | 98 | gethostname(buf, sizeof(buf) - 1); |
93 | fputs(buf, stdout); | ||
94 | break; | 99 | break; |
95 | 100 | ||
96 | case 'l': | 101 | case 'l': |
97 | printf("%s", tty); | 102 | outbuf = tty; |
98 | break; | 103 | break; |
99 | 104 | ||
100 | default: | 105 | default: |
101 | putchar(c); | 106 | buf[0] = c; |
102 | } | 107 | } |
103 | } else | ||
104 | putchar(c); | ||
105 | } | 108 | } |
106 | 109 | fputs(outbuf, stdout); | |
107 | puts(""); /* start a new line */ | 110 | } |
108 | fflush(stdout); | ||
109 | 111 | ||
110 | fclose(fd); | 112 | fclose(fd); |
113 | |||
114 | fflush(stdout); | ||
111 | } | 115 | } |
112 | } | 116 | } |
113 | 117 | ||
114 | void print_login_prompt(void) | 118 | void print_login_prompt(void) |
115 | { | 119 | { |
116 | char buf[MAXHOSTNAMELEN]; | 120 | char buf[MAXHOSTNAMELEN+1]; |
117 | 121 | ||
118 | gethostname(buf, MAXHOSTNAMELEN); | 122 | gethostname(buf, MAXHOSTNAMELEN); |
119 | fputs(buf, stdout); | 123 | fputs(buf, stdout); |
diff --git a/libbb/pw_encrypt.c b/libbb/pw_encrypt.c index 0e4eb9f8a..ac79f839f 100644 --- a/libbb/pw_encrypt.c +++ b/libbb/pw_encrypt.c | |||
@@ -39,10 +39,7 @@ extern char *pw_encrypt(const char *clear, const char *salt) | |||
39 | /* if crypt (a nonstandard crypt) returns a string too large, | 39 | /* if crypt (a nonstandard crypt) returns a string too large, |
40 | truncate it so we don't overrun buffers and hope there is | 40 | truncate it so we don't overrun buffers and hope there is |
41 | enough security in what's left */ | 41 | enough security in what's left */ |
42 | if (strlen(cp) > sizeof(cipher)-1) { | 42 | safe_strncpy(cipher, cp, sizeof(cipher)); |
43 | cp[sizeof(cipher)-1] = 0; | ||
44 | } | ||
45 | strcpy(cipher, cp); | ||
46 | return cipher; | 43 | return cipher; |
47 | } | 44 | } |
48 | 45 | ||
diff --git a/libbb/recursive_action.c b/libbb/recursive_action.c index a4a4a7be3..3ea107ca9 100644 --- a/libbb/recursive_action.c +++ b/libbb/recursive_action.c | |||
@@ -103,11 +103,9 @@ int recursive_action(const char *fileName, | |||
103 | while ((next = readdir(dir)) != NULL) { | 103 | while ((next = readdir(dir)) != NULL) { |
104 | char *nextFile; | 104 | char *nextFile; |
105 | 105 | ||
106 | if ((strcmp(next->d_name, "..") == 0) | 106 | nextFile = concat_subpath_file(fileName, next->d_name); |
107 | || (strcmp(next->d_name, ".") == 0)) { | 107 | if(nextFile == NULL) |
108 | continue; | 108 | continue; |
109 | } | ||
110 | nextFile = concat_path_file(fileName, next->d_name); | ||
111 | if (! recursive_action(nextFile, TRUE, followLinks, depthFirst, | 109 | if (! recursive_action(nextFile, TRUE, followLinks, depthFirst, |
112 | fileAction, dirAction, userData)) { | 110 | fileAction, dirAction, userData)) { |
113 | status = FALSE; | 111 | status = FALSE; |
diff --git a/libbb/remove_file.c b/libbb/remove_file.c index 65708a252..8b45c58b8 100644 --- a/libbb/remove_file.c +++ b/libbb/remove_file.c | |||
@@ -79,11 +79,9 @@ extern int remove_file(const char *path, int flags) | |||
79 | while ((d = readdir(dp)) != NULL) { | 79 | while ((d = readdir(dp)) != NULL) { |
80 | char *new_path; | 80 | char *new_path; |
81 | 81 | ||
82 | if (strcmp(d->d_name, ".") == 0 || | 82 | new_path = concat_subpath_file(path, d->d_name); |
83 | strcmp(d->d_name, "..") == 0) | 83 | if(new_path == NULL) |
84 | continue; | 84 | continue; |
85 | |||
86 | new_path = concat_path_file(path, d->d_name); | ||
87 | if (remove_file(new_path, flags) < 0) | 85 | if (remove_file(new_path, flags) < 0) |
88 | status = -1; | 86 | status = -1; |
89 | free(new_path); | 87 | free(new_path); |
diff --git a/libbb/run_shell.c b/libbb/run_shell.c index d154b9852..49e8a76c2 100644 --- a/libbb/run_shell.c +++ b/libbb/run_shell.c | |||
@@ -52,10 +52,7 @@ void run_shell ( const char *shell, int loginshell, const char *command, const c | |||
52 | for ( args = additional_args; args && *args; args++ ) | 52 | for ( args = additional_args; args && *args; args++ ) |
53 | additional_args_cnt++; | 53 | additional_args_cnt++; |
54 | 54 | ||
55 | if ( additional_args ) | ||
56 | args = (const char **) xmalloc (sizeof (char *) * ( 4 + additional_args_cnt )); | 55 | args = (const char **) xmalloc (sizeof (char *) * ( 4 + additional_args_cnt )); |
57 | else | ||
58 | args = (const char **) xmalloc (sizeof (char *) * 4 ); | ||
59 | 56 | ||
60 | args [0] = bb_get_last_path_component ( bb_xstrdup ( shell )); | 57 | args [0] = bb_get_last_path_component ( bb_xstrdup ( shell )); |
61 | 58 | ||
@@ -77,4 +74,3 @@ void run_shell ( const char *shell, int loginshell, const char *command, const c | |||
77 | execv ( shell, (char **) args ); | 74 | execv ( shell, (char **) args ); |
78 | bb_perror_msg_and_die ( "cannot run %s", shell ); | 75 | bb_perror_msg_and_die ( "cannot run %s", shell ); |
79 | } | 76 | } |
80 | |||
diff --git a/libbb/setup_environment.c b/libbb/setup_environment.c index 30d317cea..b18f8967e 100644 --- a/libbb/setup_environment.c +++ b/libbb/setup_environment.c | |||
@@ -45,13 +45,13 @@ | |||
45 | static void xsetenv ( const char *key, const char *value ) | 45 | static void xsetenv ( const char *key, const char *value ) |
46 | { | 46 | { |
47 | if ( setenv ( key, value, 1 )) | 47 | if ( setenv ( key, value, 1 )) |
48 | bb_error_msg_and_die ( "out of memory" ); | 48 | bb_error_msg_and_die (bb_msg_memory_exhausted); |
49 | } | 49 | } |
50 | 50 | ||
51 | void setup_environment ( const char *shell, int loginshell, int changeenv, const struct passwd *pw ) | 51 | void setup_environment ( const char *shell, int loginshell, int changeenv, const struct passwd *pw ) |
52 | { | 52 | { |
53 | if ( loginshell ) { | 53 | if ( loginshell ) { |
54 | char *term; | 54 | const char *term; |
55 | 55 | ||
56 | /* Change the current working directory to be the home directory | 56 | /* Change the current working directory to be the home directory |
57 | * of the user. It is a fatal error for this process to be unable | 57 | * of the user. It is a fatal error for this process to be unable |
diff --git a/libbb/xgetcwd.c b/libbb/xgetcwd.c index 85a5c4125..1fcdba198 100644 --- a/libbb/xgetcwd.c +++ b/libbb/xgetcwd.c | |||
@@ -3,7 +3,7 @@ | |||
3 | * Copyright (C) 1992, 1996 Free Software Foundation, Inc. | 3 | * Copyright (C) 1992, 1996 Free Software Foundation, Inc. |
4 | * Written by David MacKenzie <djm@gnu.ai.mit.edu>. | 4 | * Written by David MacKenzie <djm@gnu.ai.mit.edu>. |
5 | * | 5 | * |
6 | * Special function for busybox written by Vladimir Oleynik <vodz@usa.net> | 6 | * Special function for busybox written by Vladimir Oleynik <dzo@simtreas.ru> |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include <stdlib.h> | 9 | #include <stdlib.h> |