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[] = "Radn";
47 showHelp(int fd, char const *cmd, int res)
49 WRITE_MSG(fd, "Usage: ");
52 " [-Radn] [--] <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 "Please report bugs to " PACKAGE_BUGREPORT "\n");
67 "lsxid " VERSION " -- shows the context which is associated to a file\n"
68 "This program is part of " PACKAGE_STRING "\n\n"
69 "Copyright (C) 2004 Enrico Scholz\n"
70 VERSION_COPYRIGHT_DISCLAIMER);
75 fixupParams(struct Arguments UNUSED * args, int UNUSED argc)
80 getFileContext(char const *name, struct stat const *exp_st)
82 int fd = open(name, O_RDONLY);
91 checkForRace(fd, name, exp_st);
93 res = vc_X_get_filecontext(fd);
95 perror("vc_X_get_filecontext()");
103 handleFile(char const *name, char const *display_name,
104 struct stat const *exp_st)
107 char buf[MAX(sizeof(ctx)*3+1, 20)];
108 bool need_write = true;
110 memset(buf, ' ', sizeof buf);
112 if (S_ISLNK(exp_st->st_mode)) {
113 memcpy(buf, "-------", 7);
114 write(1, buf, sizeof buf);
118 ctx = getFileContext(name, exp_st);
121 memcpy(buf, "!!ERR!!", 7);
122 write(1, buf, sizeof buf);
125 else if (global_args->do_mapping) {
126 char const * vname = vc_getVserverByCtx(ctx, 0,0);
127 if (!vname) buf[0] = '\0';
129 size_t l = strlen(vname);
130 if (l<sizeof(buf)) write(1, buf, sizeof(buf)-l);
140 size_t l = utilvserver_fmt_ulong(buf, ctx);
141 if (l<sizeof(buf)) write(1, buf+l, sizeof(buf)-l);
146 write(1, display_name, strlen(display_name));
149 return ctx!=VC_NOCTX;