| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
#ifdef HAVE_CONFIG_H |
|---|
| 20 |
# include <config.h> |
|---|
| 21 |
#endif |
|---|
| 22 |
|
|---|
| 23 |
#include "fstool.h" |
|---|
| 24 |
#include "util.h" |
|---|
| 25 |
|
|---|
| 26 |
#include "lib/vserver.h" |
|---|
| 27 |
|
|---|
| 28 |
#include <stdio.h> |
|---|
| 29 |
#include <stdlib.h> |
|---|
| 30 |
#include <sys/types.h> |
|---|
| 31 |
#include <sys/stat.h> |
|---|
| 32 |
#include <fcntl.h> |
|---|
| 33 |
|
|---|
| 34 |
struct option const |
|---|
| 35 |
CMDLINE_OPTIONS[] = { |
|---|
| 36 |
{ "help", no_argument, 0, CMD_HELP }, |
|---|
| 37 |
{ "version", no_argument, 0, CMD_VERSION }, |
|---|
| 38 |
{ 0,0,0,0 } |
|---|
| 39 |
}; |
|---|
| 40 |
|
|---|
| 41 |
char const CMDLINE_OPTIONS_SHORT[] = "Rc:xU"; |
|---|
| 42 |
|
|---|
| 43 |
void |
|---|
| 44 |
showHelp(int fd, char const *cmd, int res) |
|---|
| 45 |
{ |
|---|
| 46 |
WRITE_MSG(fd, "Usage: "); |
|---|
| 47 |
WRITE_STR(fd, cmd); |
|---|
| 48 |
WRITE_MSG(fd, |
|---|
| 49 |
" -c <ctx|vserver> [-RxU] [--] <file>+\n\n" |
|---|
| 50 |
" Options:\n" |
|---|
| 51 |
" -R ... recurse through directories\n" |
|---|
| 52 |
" -c ... assign the given context/vserver to the file(s)\n" |
|---|
| 53 |
" -x ... do not cross filesystems\n" |
|---|
| 54 |
" -U ... skip unified files\n\n" |
|---|
| 55 |
"Please report bugs to " PACKAGE_BUGREPORT "\n"); |
|---|
| 56 |
exit(res); |
|---|
| 57 |
} |
|---|
| 58 |
|
|---|
| 59 |
void |
|---|
| 60 |
showVersion() |
|---|
| 61 |
{ |
|---|
| 62 |
WRITE_MSG(1, |
|---|
| 63 |
"chxid " VERSION " -- assigns a context to a file\n" |
|---|
| 64 |
"This program is part of " PACKAGE_STRING "\n\n" |
|---|
| 65 |
"Copyright (C) 2004 Enrico Scholz\n" |
|---|
| 66 |
VERSION_COPYRIGHT_DISCLAIMER); |
|---|
| 67 |
exit(0); |
|---|
| 68 |
} |
|---|
| 69 |
|
|---|
| 70 |
static inline bool |
|---|
| 71 |
isUnified(char const *filename) |
|---|
| 72 |
{ |
|---|
| 73 |
uint_least32_t const V = VC_IATTR_IUNLINK|VC_IATTR_IMMUTABLE; |
|---|
| 74 |
|
|---|
| 75 |
uint_least32_t flags; |
|---|
| 76 |
uint_least32_t mask = V; |
|---|
| 77 |
|
|---|
| 78 |
if (vc_get_iattr(filename, 0, &flags, &mask)==-1 || (mask & V) != V) |
|---|
| 79 |
return false; |
|---|
| 80 |
|
|---|
| 81 |
return (flags & V)==V ? true : false; |
|---|
| 82 |
} |
|---|
| 83 |
|
|---|
| 84 |
bool |
|---|
| 85 |
handleFile(char const *name, char const * display_name) |
|---|
| 86 |
{ |
|---|
| 87 |
if (!global_args->no_unified || !isUnified(name)) { |
|---|
| 88 |
int rc = vc_set_iattr(name, global_args->ctx, 0, VC_IATTR_XID); |
|---|
| 89 |
|
|---|
| 90 |
if (rc==-1) { |
|---|
| 91 |
perror(display_name); |
|---|
| 92 |
return false; |
|---|
| 93 |
} |
|---|
| 94 |
} |
|---|
| 95 |
|
|---|
| 96 |
return true; |
|---|
| 97 |
} |
|---|
| 98 |
|
|---|
| 99 |
void |
|---|
| 100 |
fixupParams(struct Arguments UNUSED *args, int argc) |
|---|
| 101 |
{ |
|---|
| 102 |
if (optind==argc) { |
|---|
| 103 |
WRITE_MSG(2, "No filename given; use '--help' for more information\n"); |
|---|
| 104 |
exit(1); |
|---|
| 105 |
} |
|---|
| 106 |
|
|---|
| 107 |
if (args->ctx_str==0) { |
|---|
| 108 |
WRITE_MSG(2, "No context given; use '--help' for more information\n"); |
|---|
| 109 |
exit(1); |
|---|
| 110 |
} |
|---|
| 111 |
|
|---|
| 112 |
args->ctx = vc_tagopt2tag(args->ctx_str, true, 0); |
|---|
| 113 |
args->do_display_dir = !args->do_recurse; |
|---|
| 114 |
args->do_display_dot = true; |
|---|
| 115 |
} |
|---|