3 // Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; version 2 of the License.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 #include <lib/vserver.h>
27 #include <lib/vserver-internal.h>
32 #include <sys/param.h>
33 #include <sys/types.h>
39 { "help", no_argument, 0, CMD_HELP },
40 { "version", no_argument, 0, CMD_VERSION },
44 char const CMDLINE_OPTIONS_SHORT[] = "Radnx";
47 showHelp(int fd, char const *cmd, int res)
49 WRITE_MSG(fd, "Usage: ");
52 " [-Radnx] [--] <file>*\n\n"
54 " -R ... recurse through directories\n"
55 " -a ... display files starting with '.' also\n"
56 " -d ... list directories like other files instead of\n"
57 " listing their content\n"
58 " -n ... do not try to do xid -> vserver-name mapping\n"
59 " -x ... do not cross filesystems\n\n"
60 "Please report bugs to " PACKAGE_BUGREPORT "\n");
68 "lsxid " VERSION " -- shows the context which is associated to a file\n"
69 "This program is part of " PACKAGE_STRING "\n\n"
70 "Copyright (C) 2004 Enrico Scholz\n"
71 VERSION_COPYRIGHT_DISCLAIMER);
76 fixupParams(struct Arguments UNUSED * args, int UNUSED argc)
81 getFileContext(char const *name, struct stat const *exp_st)
83 int fd = open(name, O_RDONLY);
92 checkForRace(fd, name, exp_st);
94 res = vc_X_get_filecontext(fd);
96 perror("vc_X_get_filecontext()");
104 handleFile(char const *name, char const *display_name,
105 struct stat const *exp_st)
108 char buf[MAX(sizeof(ctx)*3+1, 20)];
109 bool need_write = true;
111 memset(buf, ' ', sizeof buf);
113 if (S_ISLNK(exp_st->st_mode)) {
114 memcpy(buf, "-------", 7);
115 write(1, buf, sizeof buf);
119 ctx = getFileContext(name, exp_st);
122 memcpy(buf, "!!ERR!!", 7);
123 write(1, buf, sizeof buf);
126 else if (global_args->do_mapping) {
127 char const * vname = vc_getVserverByCtx(ctx, 0,0);
128 if (!vname) buf[0] = '\0';
130 size_t l = strlen(vname);
131 if (l<sizeof(buf)) write(1, buf, sizeof(buf)-l);
141 size_t l = utilvserver_fmt_ulong(buf, ctx);
142 if (l<sizeof(buf)) write(1, buf+l, sizeof(buf)-l);
147 write(1, display_name, strlen(display_name));
150 return ctx!=VC_NOCTX;