34 |
|
|
35 |
static int deep_remove_dir (const char *path); |
static int deep_remove_dir (const char *path); |
36 |
|
|
37 |
|
|
38 |
|
|
39 |
/* |
/* |
40 |
* Copies "from" to "to". |
* Copies FROM to TO. Ignores NOEXEC. |
41 |
*/ |
*/ |
42 |
void |
void |
43 |
copy_file (const char *from, const char *to) |
force_copy_file (const char *from, const char *to) |
44 |
{ |
{ |
45 |
struct stat sb; |
struct stat sb; |
46 |
struct utimbuf t; |
struct utimbuf t; |
47 |
int fdin, fdout; |
int fdin, fdout; |
48 |
ssize_t rsize; |
ssize_t rsize; |
49 |
|
|
|
TRACE (TRACE_FUNCTION, "copy(%s,%s)", from, to); |
|
|
|
|
|
if (noexec) |
|
|
return; |
|
|
|
|
50 |
/* If the file to be copied is a link or a device, then just create |
/* If the file to be copied is a link or a device, then just create |
51 |
the new link or device appropriately. */ |
the new link or device appropriately. */ |
52 |
if ((rsize = islink (from)) > 0) |
if ((rsize = islink (from)) > 0) |
116 |
|
|
117 |
|
|
118 |
|
|
119 |
|
/* |
120 |
|
* Copies FROM to TO. Honors NOEXEC. |
121 |
|
*/ |
122 |
|
void |
123 |
|
copy_file (const char *from, const char *to) |
124 |
|
{ |
125 |
|
TRACE (TRACE_FUNCTION, "copy (%s, %s)", from, to); |
126 |
|
if (noexec) return; |
127 |
|
force_copy_file (from, to); |
128 |
|
} |
129 |
|
|
130 |
|
|
131 |
|
|
132 |
/* FIXME-krp: these functions would benefit from caching the char * & |
/* FIXME-krp: these functions would benefit from caching the char * & |
133 |
stat buf. */ |
stat buf. */ |
134 |
|
|
349 |
return 0; |
return 0; |
350 |
} |
} |
351 |
|
|
352 |
|
|
353 |
|
|
354 |
/* |
/* |
355 |
* Change the mode of a file, either adding write permissions, or removing |
* Change the mode of a file, either adding write permissions, or removing |
356 |
* all write permissions. Either change honors the current umask setting. |
* all write permissions. Either change honors the current umask setting. |
358 |
* Don't do anything if PreservePermissions is set to `yes'. This may |
* Don't do anything if PreservePermissions is set to `yes'. This may |
359 |
* have unexpected consequences for some uses of xchmod. |
* have unexpected consequences for some uses of xchmod. |
360 |
*/ |
*/ |
361 |
void |
static void |
362 |
xchmod (const char *fname, int writable) |
ixchmod (const char *fname, bool writable, bool noexec) |
363 |
{ |
{ |
364 |
struct stat sb; |
struct stat sb; |
365 |
mode_t mode, oumask; |
mode_t mode, oumask; |
378 |
oumask = umask (0); |
oumask = umask (0); |
379 |
(void) umask (oumask); |
(void) umask (oumask); |
380 |
if (writable) |
if (writable) |
|
{ |
|
381 |
mode = sb.st_mode | (~oumask |
mode = sb.st_mode | (~oumask |
382 |
& (((sb.st_mode & S_IRUSR) ? S_IWUSR : 0) |
& (((sb.st_mode & S_IRUSR) ? S_IWUSR : 0) |
383 |
| ((sb.st_mode & S_IRGRP) ? S_IWGRP : 0) |
| ((sb.st_mode & S_IRGRP) ? S_IWGRP : 0) |
384 |
| ((sb.st_mode & S_IROTH) ? S_IWOTH : 0))); |
| ((sb.st_mode & S_IROTH) ? S_IWOTH : 0))); |
|
} |
|
385 |
else |
else |
|
{ |
|
386 |
mode = sb.st_mode & ~(S_IWRITE | S_IWGRP | S_IWOTH) & ~oumask; |
mode = sb.st_mode & ~(S_IWRITE | S_IWGRP | S_IWOTH) & ~oumask; |
|
} |
|
387 |
|
|
388 |
TRACE (TRACE_FUNCTION, "chmod(%s,%o)", fname, (unsigned int) mode); |
TRACE (TRACE_FUNCTION, "chmod(%s,%o)", fname, (unsigned int) mode); |
389 |
|
|
394 |
error (0, errno, "cannot change mode of file %s", fname); |
error (0, errno, "cannot change mode of file %s", fname); |
395 |
} |
} |
396 |
|
|
397 |
|
|
398 |
|
|
399 |
|
/* See description for ixchmod. Ignores NOEXEC. */ |
400 |
|
void |
401 |
|
force_xchmod (const char *fname, bool writable) |
402 |
|
{ |
403 |
|
ixchmod (fname, writable, false); |
404 |
|
} |
405 |
|
|
406 |
|
|
407 |
|
|
408 |
|
/* See description for ixchmod. Honors NOEXEC. */ |
409 |
|
void |
410 |
|
xchmod (const char *fname, bool writable) |
411 |
|
{ |
412 |
|
ixchmod (fname, writable, noexec); |
413 |
|
} |
414 |
|
|
415 |
|
|
416 |
|
|
417 |
/* |
/* |
418 |
* Rename a file and die if it fails |
* Rename a file and die if it fails |
419 |
*/ |
*/ |