1 // $Id: vattribute.c,v 1.14 2005/03/24 12:44:17 ensc Exp $ --*- c -*--
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.
24 #include <lib/vserver.h>
30 #define ENSC_WRAPPERS_PREFIX "vattribute: "
31 #define ENSC_WRAPPERS_VSERVER 1
32 #define ENSC_WRAPPERS_UNISTD 1
35 #define CMD_HELP 0x1000
36 #define CMD_VERSION 0x1001
37 #define CMD_XID 0x2000
38 #define CMD_SET 0x2001
39 #define CMD_CCAP 0x2002
40 #define CMD_FLAG 0x2003
41 #define CMD_SECURE 0x2004
42 #define CMD_BCAP 0x2005
44 int wrapper_exit_code = 1;
48 { "help", no_argument, 0, CMD_HELP },
49 { "version", no_argument, 0, CMD_VERSION },
50 { "xid", required_argument, 0, CMD_XID },
51 { "set", no_argument, 0, CMD_SET },
52 { "ccap", required_argument, 0, CMD_CCAP },
53 { "bcap", required_argument, 0, CMD_BCAP },
54 { "flag", required_argument, 0, CMD_FLAG },
55 { "secure", no_argument, 0, CMD_SECURE },
61 struct vc_ctx_flags flags;
62 struct vc_ctx_caps caps;
66 showHelp(int fd, char const *cmd, int res)
68 WRITE_MSG(fd, "Usage:\n ");
71 " --set [--xid <xid>] [--bcap [~!]<cap>] [--ccap [~!]<cap>] [--flag [~!]<flag>] [--secure] -- [<program> <args>*]\n"
73 " --bcap <cap> ... system capability to be added\n"
74 " --cap <cap> ... context capability to be added\n"
76 "Please report bugs to " PACKAGE_BUGREPORT "\n");
85 "vattribute " VERSION " -- sets attributes of vservers\n"
86 "This program is part of " PACKAGE_STRING "\n\n"
87 "Copyright (C) 2004 Enrico Scholz\n"
88 VERSION_COPYRIGHT_DISCLAIMER);
93 parseFlags(char const *str, struct vc_ctx_flags *flags)
95 struct vc_err_listparser err;
98 rc = vc_list2cflag(str,0, &err, flags);
101 WRITE_MSG(2, "Unknown flag '");
102 Vwrite(2, err.ptr, err.len);
104 exit(wrapper_exit_code);
109 parseBCaps(char const *str, struct vc_ctx_caps *caps)
111 struct vc_err_listparser err;
114 rc = vc_list2bcap(str,0, &err, caps);
117 WRITE_MSG(2, "Unknown bcap '");
118 Vwrite(2, err.ptr, err.len);
120 exit(wrapper_exit_code);
125 parseCCaps(char const *str, struct vc_ctx_caps *caps)
127 struct vc_err_listparser err;
130 rc = vc_list2ccap(str,0, &err, caps);
133 WRITE_MSG(2, "Unknown ccap '");
134 Vwrite(2, err.ptr, err.len);
136 exit(wrapper_exit_code);
141 parseSecure(struct vc_ctx_flags UNUSED * flags,
142 struct vc_ctx_caps UNUSED * caps)
144 caps->ccaps = ~vc_get_insecureccaps();
146 caps->bcaps = ~vc_get_insecurebcaps();
149 // TODO: generalize this
150 flags->flagword = VC_VXF_HIDE_NETIF;
151 flags->mask = VC_VXF_HIDE_NETIF;
154 int main(int argc, char *argv[])
156 struct Arguments args = {
158 .flags = { .flagword = 0, .mask = 0 },
159 .caps = { .bcaps = 0, .bmask = 0,.ccaps = 0, .cmask = 0 },
163 int c = getopt_long(argc, argv, "+", CMDLINE_OPTIONS, 0);
167 case CMD_HELP : showHelp(1, argv[0], 0);
168 case CMD_VERSION : showVersion();
169 case CMD_SET : break; // default op currently
170 case CMD_XID : args.xid = Evc_xidopt2xid(optarg,true); break;
171 case CMD_FLAG : parseFlags(optarg, &args.flags); break;
172 case CMD_CCAP : parseCCaps(optarg, &args.caps); break;
173 case CMD_BCAP : parseBCaps(optarg, &args.caps); break;
174 case CMD_SECURE : parseSecure(&args.flags, &args.caps); break;
176 WRITE_MSG(2, "Try '");
177 WRITE_STR(2, argv[0]);
178 WRITE_MSG(2, " --help\" for more information.\n");
184 if (args.xid==VC_NOCTX) args.xid = Evc_get_task_xid(0);
186 if ((args.caps.cmask || args.caps.bmask) &&
187 vc_set_ccaps(args.xid, &args.caps)==-1)
188 perror(ENSC_WRAPPERS_PREFIX "vc_set_ccaps()");
189 else if (args.flags.mask &&
190 vc_set_cflags(args.xid, &args.flags)==-1)
191 perror(ENSC_WRAPPERS_PREFIX "vc_set_flags()");
192 else if (optind<argc)
193 EexecvpD(argv[optind], argv+optind);