diff options
author | Jim Meyering <jim@meyering.net> | 1997-07-06 21:28:04 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 1997-07-06 21:28:04 +0000 |
commit | f3a329069eb8a72a5cbcbffb3999f363ff82c9c2 (patch) | |
tree | 0736b396d2d4ca1025eb4bf50d9f28412aec92fe /lib/modechange.c | |
parent | 244fb561f890a4ba0ee6a45230ea53e41b5b5cdb (diff) | |
download | coreutils-f3a329069eb8a72a5cbcbffb3999f363ff82c9c2.tar.xz |
(mode_create_from_ref): New function.
Diffstat (limited to 'lib/modechange.c')
-rw-r--r-- | lib/modechange.c | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/lib/modechange.c b/lib/modechange.c index f778c3aaf..97f2e63ba 100644 --- a/lib/modechange.c +++ b/lib/modechange.c @@ -1,5 +1,5 @@ /* modechange.c -- file mode manipulation - Copyright (C) 1989, 1990 Free Software Foundation, Inc. + Copyright (C) 1989, 1990, 1997 Free Software Foundation, Inc. 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 @@ -236,6 +236,41 @@ invalid: return MODE_INVALID; } +/* Return a file mode change operation created from the reference REF_FILE + Don't affect special permissions, use umask, affect 'x' if any 'x', for + maximum security + + Return MODE_BAD_REFERENCE if REF_FILE can't be accessed */ + +struct mode_change * +mode_create_from_ref (ref_file) + const char *ref_file; +{ + struct mode_change *change; /* the only change element */ + struct stat ref_stats; + int i; + int umask_value; + + if (stat (ref_file, &ref_stats)) + return MODE_BAD_REFERENCE; + + change = talloc (struct mode_change); + + if (change == NULL) + return MODE_MEMORY_EXHAUSTED; + + umask_value = umask (0); + umask (umask_value); + + change->op = '='; + change->flags = MODE_X_IF_ANY_X; + change->affected = 0777 & ~umask_value; + change->value = ref_stats.st_mode; + change->next = NULL; + + return change; +} + /* Return file mode OLDMODE, adjusted as indicated by the list of change operations CHANGES. If OLDMODE is a directory, the type `X' change affects it even if no execute bits were set in OLDMODE. |