diff options
author | Erik Andersen <andersen@codepoet.org> | 2000-01-29 05:52:40 +0000 |
---|---|---|
committer | Erik Andersen <andersen@codepoet.org> | 2000-01-29 05:52:40 +0000 |
commit | 8e759aa31fa3f0dea6686cb7194398e68ff76696 (patch) | |
tree | bf85d9f769971c50e4c16ebeb4475a1e092c0fed | |
parent | d7a44c76fe22873893b995ab62ce4112fad99c66 (diff) | |
download | busybox-w32-8e759aa31fa3f0dea6686cb7194398e68ff76696.tar.gz busybox-w32-8e759aa31fa3f0dea6686cb7194398e68ff76696.tar.bz2 busybox-w32-8e759aa31fa3f0dea6686cb7194398e68ff76696.zip |
copy fixes to simplify link copying and always do the right thing.
ping could segfault because I'm an idiot, and tried to put a value
in where I hadn't allocated storage. choke.
-Erik
-rw-r--r-- | networking/ping.c | 12 | ||||
-rw-r--r-- | ping.c | 12 | ||||
-rw-r--r-- | utility.c | 18 |
3 files changed, 16 insertions, 26 deletions
diff --git a/networking/ping.c b/networking/ping.c index 2b6e7f5f2..5cadac3e8 100644 --- a/networking/ping.c +++ b/networking/ping.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * $Id: ping.c,v 1.7 2000/01/26 20:06:48 erik Exp $ | 2 | * $Id: ping.c,v 1.8 2000/01/29 05:52:40 erik Exp $ |
3 | * Mini ping implementation for busybox | 3 | * Mini ping implementation for busybox |
4 | * | 4 | * |
5 | * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> | 5 | * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> |
@@ -312,18 +312,14 @@ static void unpack(char *buf, int sz, struct sockaddr_in *from) | |||
312 | 312 | ||
313 | static void ping(char *host) | 313 | static void ping(char *host) |
314 | { | 314 | { |
315 | struct protoent *proto; | 315 | struct protoent *proto=NULL; |
316 | struct hostent *h; | 316 | struct hostent *h; |
317 | char buf[MAXHOSTNAMELEN]; | 317 | char buf[MAXHOSTNAMELEN]; |
318 | char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN]; | 318 | char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN]; |
319 | int sockopt; | 319 | int sockopt; |
320 | 320 | ||
321 | if (!(proto = getprotobyname("icmp"))) { | 321 | proto = getprotobyname("icmp"); |
322 | /* getprotobyname failed, so just silently force | 322 | if ((pingsock = socket(AF_INET, SOCK_RAW, (proto)? proto->p_proto : 1 )) < 0) { /* 1 == ICMP */ |
323 | * proto->p_proto to have the correct value for "icmp" */ | ||
324 | proto->p_proto = 1; | ||
325 | } | ||
326 | if ((pingsock = socket(AF_INET, SOCK_RAW, proto->p_proto)) < 0) { /* 1 == ICMP */ | ||
327 | if (errno == EPERM) { | 323 | if (errno == EPERM) { |
328 | fprintf(stderr, "ping: permission denied. (are you root?)\n"); | 324 | fprintf(stderr, "ping: permission denied. (are you root?)\n"); |
329 | } else { | 325 | } else { |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | * $Id: ping.c,v 1.7 2000/01/26 20:06:48 erik Exp $ | 2 | * $Id: ping.c,v 1.8 2000/01/29 05:52:40 erik Exp $ |
3 | * Mini ping implementation for busybox | 3 | * Mini ping implementation for busybox |
4 | * | 4 | * |
5 | * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> | 5 | * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> |
@@ -312,18 +312,14 @@ static void unpack(char *buf, int sz, struct sockaddr_in *from) | |||
312 | 312 | ||
313 | static void ping(char *host) | 313 | static void ping(char *host) |
314 | { | 314 | { |
315 | struct protoent *proto; | 315 | struct protoent *proto=NULL; |
316 | struct hostent *h; | 316 | struct hostent *h; |
317 | char buf[MAXHOSTNAMELEN]; | 317 | char buf[MAXHOSTNAMELEN]; |
318 | char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN]; | 318 | char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN]; |
319 | int sockopt; | 319 | int sockopt; |
320 | 320 | ||
321 | if (!(proto = getprotobyname("icmp"))) { | 321 | proto = getprotobyname("icmp"); |
322 | /* getprotobyname failed, so just silently force | 322 | if ((pingsock = socket(AF_INET, SOCK_RAW, (proto)? proto->p_proto : 1 )) < 0) { /* 1 == ICMP */ |
323 | * proto->p_proto to have the correct value for "icmp" */ | ||
324 | proto->p_proto = 1; | ||
325 | } | ||
326 | if ((pingsock = socket(AF_INET, SOCK_RAW, proto->p_proto)) < 0) { /* 1 == ICMP */ | ||
327 | if (errno == EPERM) { | 323 | if (errno == EPERM) { |
328 | fprintf(stderr, "ping: permission denied. (are you root?)\n"); | 324 | fprintf(stderr, "ping: permission denied. (are you root?)\n"); |
329 | } else { | 325 | } else { |
@@ -182,6 +182,11 @@ copyFile( const char *srcName, const char *destName, | |||
182 | perror(destName); | 182 | perror(destName); |
183 | return (FALSE); | 183 | return (FALSE); |
184 | } | 184 | } |
185 | #if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1) | ||
186 | if (setModes == TRUE) { | ||
187 | lchown(destName, srcStatBuf.st_uid, srcStatBuf.st_gid); | ||
188 | } | ||
189 | #endif | ||
185 | } else if (S_ISFIFO(srcStatBuf.st_mode)) { | 190 | } else if (S_ISFIFO(srcStatBuf.st_mode)) { |
186 | //fprintf(stderr, "copying fifo %s to %s\n", srcName, destName); | 191 | //fprintf(stderr, "copying fifo %s to %s\n", srcName, destName); |
187 | if (mkfifo(destName, 0644)) { | 192 | if (mkfifo(destName, 0644)) { |
@@ -225,16 +230,9 @@ copyFile( const char *srcName, const char *destName, | |||
225 | } | 230 | } |
226 | 231 | ||
227 | if (setModes == TRUE) { | 232 | if (setModes == TRUE) { |
228 | if (! S_ISLNK(srcStatBuf.st_mode)) { | 233 | /* This is fine, since symlinks never get here */ |
229 | chown(destName, srcStatBuf.st_uid, srcStatBuf.st_gid); | 234 | chown(destName, srcStatBuf.st_uid, srcStatBuf.st_gid); |
230 | /* Never chmod a symlink; it follows the link */ | 235 | chmod(destName, srcStatBuf.st_mode); |
231 | chmod(destName, srcStatBuf.st_mode); | ||
232 | } | ||
233 | #if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1) | ||
234 | else { | ||
235 | lchown(destName, srcStatBuf.st_uid, srcStatBuf.st_gid); | ||
236 | } | ||
237 | #endif | ||
238 | times.actime = srcStatBuf.st_atime; | 236 | times.actime = srcStatBuf.st_atime; |
239 | times.modtime = srcStatBuf.st_mtime; | 237 | times.modtime = srcStatBuf.st_mtime; |
240 | utime(destName, ×); | 238 | utime(destName, ×); |